diff --git a/src/gallium/frontends/clover/api/queue.cpp b/src/gallium/frontends/clover/api/queue.cpp index 65b271b216f..39de311b34f 100644 --- a/src/gallium/frontends/clover/api/queue.cpp +++ b/src/gallium/frontends/clover/api/queue.cpp @@ -91,7 +91,11 @@ clGetCommandQueueInfo(cl_command_queue d_q, cl_command_queue_info param, break; case CL_QUEUE_PROPERTIES: - buf.as_scalar() = q.properties(); + buf.as_scalar() = q.props(); + break; + + case CL_QUEUE_PROPERTIES_ARRAY: + buf.as_vector() = q.properties(); break; default: @@ -114,22 +118,29 @@ clFlush(cl_command_queue d_q) try { } CLOVER_API cl_command_queue -clCreateCommandQueueWithProperties(cl_context context, cl_device_id device, - const cl_queue_properties *properties, - cl_int *errcode_ret) try { - cl_command_queue_properties props = 0; - if (properties) { - for (auto idx = 0; properties[idx]; idx += 2) { - if (properties[idx] == CL_QUEUE_PROPERTIES) - props |= properties[idx + 1]; - else - throw error(CL_INVALID_VALUE); - } - } +clCreateCommandQueueWithProperties(cl_context d_ctx, cl_device_id d_dev, + const cl_queue_properties *d_properties, + cl_int *r_errcode) try { + auto &ctx = obj(d_ctx); + auto &dev = obj(d_dev); - return clCreateCommandQueue(context, device, props, errcode_ret); + if (!count(dev, ctx.devices())) + throw error(CL_INVALID_DEVICE); + + ret_error(r_errcode, CL_SUCCESS); + std::vector properties; + + if (d_properties) { + int idx = -1; + /* these come in pairs, bail if the first is 0 */ + do { + idx++; + properties.push_back(d_properties[idx]); + } while (d_properties[idx & ~1]); + } + return new command_queue(ctx, dev, properties); } catch (error &e) { - ret_error(errcode_ret, e); + ret_error(r_errcode, e); return NULL; } diff --git a/src/gallium/frontends/clover/core/queue.cpp b/src/gallium/frontends/clover/core/queue.cpp index c7d08a8c6d2..b5e36e57f4a 100644 --- a/src/gallium/frontends/clover/core/queue.cpp +++ b/src/gallium/frontends/clover/core/queue.cpp @@ -44,7 +44,33 @@ namespace { command_queue::command_queue(clover::context &ctx, clover::device &dev, cl_command_queue_properties props) : - context(ctx), device(dev), props(props) { + context(ctx), device(dev), _props(props) { + pipe = dev.pipe->context_create(dev.pipe, NULL, PIPE_CONTEXT_COMPUTE_ONLY); + if (!pipe) + throw error(CL_INVALID_DEVICE); + + if (ctx.notify) { + struct pipe_debug_callback cb; + memset(&cb, 0, sizeof(cb)); + cb.debug_message = &debug_notify_callback; + cb.data = this; + if (pipe->set_debug_callback) + pipe->set_debug_callback(pipe, &cb); + } +} +command_queue::command_queue(clover::context &ctx, clover::device &dev, + std::vector properties) : + context(ctx), device(dev), _properties(properties) { + + for(std::vector::size_type i = 0; i != properties.size(); i += 2) { + if (properties[i] == 0) + break; + if (properties[i] == CL_QUEUE_PROPERTIES) + _props |= properties[i + 1]; + else if (properties[i] != CL_QUEUE_SIZE) + throw error(CL_INVALID_VALUE); + } + pipe = dev.pipe->context_create(dev.pipe, NULL, PIPE_CONTEXT_COMPUTE_ONLY); if (!pipe) throw error(CL_INVALID_DEVICE); @@ -88,13 +114,18 @@ command_queue::flush_unlocked() { } cl_command_queue_properties +command_queue::props() const { + return _props; +} + +std::vector command_queue::properties() const { - return props; + return _properties; } bool command_queue::profiling_enabled() const { - return props & CL_QUEUE_PROFILING_ENABLE; + return _props & CL_QUEUE_PROFILING_ENABLE; } void diff --git a/src/gallium/frontends/clover/core/queue.hpp b/src/gallium/frontends/clover/core/queue.hpp index 27f2c9b7aeb..579bba8f7a5 100644 --- a/src/gallium/frontends/clover/core/queue.hpp +++ b/src/gallium/frontends/clover/core/queue.hpp @@ -38,6 +38,8 @@ namespace clover { class command_queue : public ref_counter, public _cl_command_queue { public: + command_queue(clover::context &ctx, clover::device &dev, + std::vector properties); command_queue(clover::context &ctx, clover::device &dev, cl_command_queue_properties props); ~command_queue(); @@ -48,7 +50,9 @@ namespace clover { void flush(); - cl_command_queue_properties properties() const; + cl_command_queue_properties props() const; + + std::vector properties() const; bool profiling_enabled() const; const intrusive_ref context; @@ -70,7 +74,8 @@ namespace clover { // Use this instead of flush() if `queued_events_mutex` is acquired. void flush_unlocked(); - cl_command_queue_properties props; + std::vector _properties; + cl_command_queue_properties _props; pipe_context *pipe; std::mutex queued_events_mutex; std::deque> queued_events;