Skip to content

Commit

Permalink
fix init image at creation
Browse files Browse the repository at this point in the history
We need to create the cvk_command_image_init with a valid
context. Otherwise we can have a race condition between the
destruction of queue and commands being deleted in the executor
thread.
  • Loading branch information
rjodinchr committed Jan 24, 2025
1 parent a91d6a8 commit 8908894
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ bool cvk_image::init_vulkan_image() {
return false;
}

auto initimage = new cvk_command_image_init(queue, this);
auto initimage = new cvk_command_image_init(queue, this, m_context);
ret = queue->enqueue_command_with_deps(initimage, 0, nullptr,
nullptr);
if (ret != CL_SUCCESS) {
Expand Down
4 changes: 2 additions & 2 deletions src/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ cl_int cvk_command_queue::satisfy_data_dependencies(cvk_command* cmd) {
continue;
}
CVK_ASSERT(mem->is_image_type());
auto initcmd =
new cvk_command_image_init(this, static_cast<cvk_image*>(mem));
auto initcmd = new cvk_command_image_init(
this, static_cast<cvk_image*>(mem), m_context);
_cl_event* initev;
cl_int err = enqueue_command_with_retry(initcmd, &initev);
if (err != CL_SUCCESS) {
Expand Down
19 changes: 13 additions & 6 deletions src/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,14 @@ struct cvk_command_buffer {
#define CLVK_COMMAND_BATCH 0x5000
#define CLVK_COMMAND_IMAGE_INIT 0x5001

struct cvk_command {
struct cvk_command : public refcounted {
cvk_command(cl_command_type type, cvk_command_queue* queue,
cvk_context* ctx)
: m_type(type), m_queue(queue),
m_event(new cvk_event(ctx, this, queue)) {}

cvk_command(cl_command_type type, cvk_command_queue* queue)
: m_type(type), m_queue(queue),
m_event(new cvk_event(m_queue->context(), this, queue)) {}
: cvk_command(type, queue, queue->context()) {}

virtual ~cvk_command() { m_event->release(); }

Expand Down Expand Up @@ -672,8 +675,11 @@ struct cvk_command_fill_buffer final : public cvk_command_buffer_base_region {
};

struct cvk_command_batchable : public cvk_command {
cvk_command_batchable(cl_command_type type, cvk_command_queue* queue,
cvk_context* ctx)
: cvk_command(type, queue, ctx), m_query_pool(VK_NULL_HANDLE) {}
cvk_command_batchable(cl_command_type type, cvk_command_queue* queue)
: cvk_command(type, queue), m_query_pool(VK_NULL_HANDLE) {}
: cvk_command_batchable(type, queue, queue->context()) {}

virtual ~cvk_command_batchable() {
if (m_query_pool != VK_NULL_HANDLE) {
Expand Down Expand Up @@ -1176,8 +1182,9 @@ struct cvk_command_fill_image final : public cvk_command {

struct cvk_command_image_init final : public cvk_command_batchable {

cvk_command_image_init(cvk_command_queue* queue, cvk_image* image)
: cvk_command_batchable(CLVK_COMMAND_IMAGE_INIT, queue),
cvk_command_image_init(cvk_command_queue* queue, cvk_image* image,
cvk_context* ctx)
: cvk_command_batchable(CLVK_COMMAND_IMAGE_INIT, queue, ctx),
m_image(image) {
CVK_ASSERT(!m_image->is_backed_by_buffer_view());
}
Expand Down

0 comments on commit 8908894

Please sign in to comment.