mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
clover: handle memory object properties properly.
This adds proper support for the buffer/image property APIs. Fixes: CL CTS api buffer_properties_queries v1.1: use a helper for properties parsing. Reviewed-by: Karol Herbst <kherbst@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7642>
This commit is contained in:
parent
6fd20a0281
commit
0272b6b1ba
5 changed files with 109 additions and 35 deletions
|
|
@ -170,8 +170,8 @@ namespace clover {
|
|||
NULL, // clSetDefaultDeviceCommandQueue
|
||||
NULL, // clSetProgramReleaseCallback
|
||||
NULL, // clSetProgramSpecializationConstant
|
||||
NULL, // clCreateBufferWithProperties
|
||||
NULL, // clCreateImageWithProperties
|
||||
clCreateBufferWithProperties,
|
||||
clCreateImageWithProperties,
|
||||
clSetContextDestructorCallback
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,13 +82,33 @@ namespace {
|
|||
return d_flags | (d_flags & dev_access_flags ? 0 : CL_MEM_READ_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<cl_mem_properties>
|
||||
fill_properties(const cl_mem_properties *d_properties) {
|
||||
std::vector<cl_mem_properties> properties;
|
||||
if (d_properties) {
|
||||
while (*d_properties) {
|
||||
if (*d_properties != 0)
|
||||
throw error(CL_INVALID_PROPERTY);
|
||||
|
||||
properties.push_back(*d_properties);
|
||||
d_properties++;
|
||||
};
|
||||
properties.push_back(0);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
||||
CLOVER_API cl_mem
|
||||
clCreateBuffer(cl_context d_ctx, cl_mem_flags d_flags, size_t size,
|
||||
void *host_ptr, cl_int *r_errcode) try {
|
||||
const cl_mem_flags flags = validate_flags(NULL, d_flags, false);
|
||||
clCreateBufferWithProperties(cl_context d_ctx,
|
||||
const cl_mem_properties *d_properties,
|
||||
cl_mem_flags d_flags, size_t size,
|
||||
void *host_ptr, cl_int *r_errcode) try {
|
||||
|
||||
auto &ctx = obj(d_ctx);
|
||||
const cl_mem_flags flags = validate_flags(NULL, d_flags, false);
|
||||
std::vector<cl_mem_properties> properties = fill_properties(d_properties);
|
||||
|
||||
if (bool(host_ptr) != bool(flags & (CL_MEM_USE_HOST_PTR |
|
||||
CL_MEM_COPY_HOST_PTR)))
|
||||
|
|
@ -101,13 +121,20 @@ clCreateBuffer(cl_context d_ctx, cl_mem_flags d_flags, size_t size,
|
|||
throw error(CL_INVALID_BUFFER_SIZE);
|
||||
|
||||
ret_error(r_errcode, CL_SUCCESS);
|
||||
return new root_buffer(ctx, flags, size, host_ptr);
|
||||
|
||||
return new root_buffer(ctx, properties, flags, size, host_ptr);
|
||||
} catch (error &e) {
|
||||
ret_error(r_errcode, e);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CLOVER_API cl_mem
|
||||
clCreateBuffer(cl_context d_ctx, cl_mem_flags d_flags, size_t size,
|
||||
void *host_ptr, cl_int *r_errcode) {
|
||||
return clCreateBufferWithProperties(d_ctx, NULL, d_flags, size,
|
||||
host_ptr, r_errcode);
|
||||
}
|
||||
|
||||
CLOVER_API cl_mem
|
||||
clCreateSubBuffer(cl_mem d_mem, cl_mem_flags d_flags,
|
||||
cl_buffer_create_type op,
|
||||
|
|
@ -139,10 +166,12 @@ clCreateSubBuffer(cl_mem d_mem, cl_mem_flags d_flags,
|
|||
}
|
||||
|
||||
CLOVER_API cl_mem
|
||||
clCreateImage(cl_context d_ctx, cl_mem_flags d_flags,
|
||||
const cl_image_format *format,
|
||||
const cl_image_desc *desc,
|
||||
void *host_ptr, cl_int *r_errcode) try {
|
||||
clCreateImageWithProperties(cl_context d_ctx,
|
||||
const cl_mem_properties *d_properties,
|
||||
cl_mem_flags d_flags,
|
||||
const cl_image_format *format,
|
||||
const cl_image_desc *desc,
|
||||
void *host_ptr, cl_int *r_errcode) try {
|
||||
auto &ctx = obj(d_ctx);
|
||||
|
||||
if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))
|
||||
|
|
@ -178,6 +207,7 @@ clCreateImage(cl_context d_ctx, cl_mem_flags d_flags,
|
|||
if (!supported_formats(ctx, desc->image_type).count(*format))
|
||||
throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
|
||||
|
||||
std::vector<cl_mem_properties> properties = fill_properties(d_properties);
|
||||
ret_error(r_errcode, CL_SUCCESS);
|
||||
|
||||
const size_t row_pitch = desc->image_row_pitch ? desc->image_row_pitch :
|
||||
|
|
@ -195,7 +225,7 @@ clCreateImage(cl_context d_ctx, cl_mem_flags d_flags,
|
|||
}, ctx.devices()))
|
||||
throw error(CL_INVALID_IMAGE_SIZE);
|
||||
|
||||
return new image2d(ctx, flags, format,
|
||||
return new image2d(ctx, properties, flags, format,
|
||||
desc->image_width, desc->image_height,
|
||||
row_pitch, host_ptr);
|
||||
|
||||
|
|
@ -214,7 +244,7 @@ clCreateImage(cl_context d_ctx, cl_mem_flags d_flags,
|
|||
const size_t slice_pitch = desc->image_slice_pitch ?
|
||||
desc->image_slice_pitch : row_pitch * desc->image_height;
|
||||
|
||||
return new image3d(ctx, flags, format,
|
||||
return new image3d(ctx, properties, flags, format,
|
||||
desc->image_width, desc->image_height,
|
||||
desc->image_depth, row_pitch,
|
||||
slice_pitch, host_ptr);
|
||||
|
|
@ -236,6 +266,16 @@ clCreateImage(cl_context d_ctx, cl_mem_flags d_flags,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CLOVER_API cl_mem
|
||||
clCreateImage(cl_context d_ctx,
|
||||
cl_mem_flags d_flags,
|
||||
const cl_image_format *format,
|
||||
const cl_image_desc *desc,
|
||||
void *host_ptr, cl_int *r_errcode) {
|
||||
return clCreateImageWithProperties(d_ctx, NULL, d_flags, format, desc, host_ptr, r_errcode);
|
||||
}
|
||||
|
||||
|
||||
CLOVER_API cl_mem
|
||||
clCreateImage2D(cl_context d_ctx, cl_mem_flags d_flags,
|
||||
const cl_image_format *format,
|
||||
|
|
@ -244,7 +284,7 @@ clCreateImage2D(cl_context d_ctx, cl_mem_flags d_flags,
|
|||
const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0,
|
||||
row_pitch, 0, 0, 0, NULL };
|
||||
|
||||
return clCreateImage(d_ctx, d_flags, format, &desc, host_ptr, r_errcode);
|
||||
return clCreateImageWithProperties(d_ctx, NULL, d_flags, format, &desc, host_ptr, r_errcode);
|
||||
}
|
||||
|
||||
CLOVER_API cl_mem
|
||||
|
|
@ -256,7 +296,7 @@ clCreateImage3D(cl_context d_ctx, cl_mem_flags d_flags,
|
|||
const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0,
|
||||
row_pitch, slice_pitch, 0, 0, NULL };
|
||||
|
||||
return clCreateImage(d_ctx, d_flags, format, &desc, host_ptr, r_errcode);
|
||||
return clCreateImageWithProperties(d_ctx, NULL, d_flags, format, &desc, host_ptr, r_errcode);
|
||||
}
|
||||
|
||||
CLOVER_API cl_int
|
||||
|
|
@ -340,6 +380,9 @@ clGetMemObjectInfo(cl_mem d_mem, cl_mem_info param,
|
|||
buf.as_scalar<cl_bool>() = mem.host_ptr() && system_svm;
|
||||
break;
|
||||
}
|
||||
case CL_MEM_PROPERTIES:
|
||||
buf.as_vector<cl_mem_properties>() = mem.properties();
|
||||
break;
|
||||
default:
|
||||
throw error(CL_INVALID_VALUE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ kernel::kernel(clover::program &prog, const std::string &name,
|
|||
continue;
|
||||
|
||||
auto mconst = find(f, m.secs);
|
||||
auto rb = std::make_unique<root_buffer>(prog.context(),
|
||||
auto rb = std::make_unique<root_buffer>(prog.context(), std::vector<cl_mem_properties>(),
|
||||
CL_MEM_COPY_HOST_PTR | CL_MEM_READ_ONLY,
|
||||
mconst.size, mconst.data.data());
|
||||
_constant_buffers.emplace(&dev, std::move(rb));
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@
|
|||
|
||||
using namespace clover;
|
||||
|
||||
memory_obj::memory_obj(clover::context &ctx, cl_mem_flags flags,
|
||||
memory_obj::memory_obj(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
size_t size, void *host_ptr) :
|
||||
context(ctx), _flags(flags),
|
||||
context(ctx), _properties(properties), _flags(flags),
|
||||
_size(size), _host_ptr(host_ptr) {
|
||||
if (flags & CL_MEM_COPY_HOST_PTR)
|
||||
data.append((char *)host_ptr, size);
|
||||
|
|
@ -51,6 +53,11 @@ memory_obj::destroy_notify(std::function<void ()> f) {
|
|||
_destroy_notify.push(f);
|
||||
}
|
||||
|
||||
std::vector<cl_mem_properties>
|
||||
memory_obj::properties() const {
|
||||
return _properties;
|
||||
}
|
||||
|
||||
cl_mem_flags
|
||||
memory_obj::flags() const {
|
||||
return _flags;
|
||||
|
|
@ -66,9 +73,11 @@ memory_obj::host_ptr() const {
|
|||
return _host_ptr;
|
||||
}
|
||||
|
||||
buffer::buffer(clover::context &ctx, cl_mem_flags flags,
|
||||
buffer::buffer(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
size_t size, void *host_ptr) :
|
||||
memory_obj(ctx, flags, size, host_ptr) {
|
||||
memory_obj(ctx, properties, flags, size, host_ptr) {
|
||||
}
|
||||
|
||||
cl_mem_object_type
|
||||
|
|
@ -76,9 +85,11 @@ buffer::type() const {
|
|||
return CL_MEM_OBJECT_BUFFER;
|
||||
}
|
||||
|
||||
root_buffer::root_buffer(clover::context &ctx, cl_mem_flags flags,
|
||||
root_buffer::root_buffer(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
size_t size, void *host_ptr) :
|
||||
buffer(ctx, flags, size, host_ptr) {
|
||||
buffer(ctx, properties, flags, size, host_ptr) {
|
||||
}
|
||||
|
||||
resource &
|
||||
|
|
@ -119,7 +130,7 @@ root_buffer::resource_out(command_queue &q) {
|
|||
|
||||
sub_buffer::sub_buffer(root_buffer &parent, cl_mem_flags flags,
|
||||
size_t offset, size_t size) :
|
||||
buffer(parent.context(), flags, size,
|
||||
buffer(parent.context(), std::vector<cl_mem_properties>(), flags, size,
|
||||
(char *)parent.host_ptr() + offset),
|
||||
parent(parent), _offset(offset) {
|
||||
}
|
||||
|
|
@ -152,12 +163,14 @@ sub_buffer::offset() const {
|
|||
return _offset;
|
||||
}
|
||||
|
||||
image::image(clover::context &ctx, cl_mem_flags flags,
|
||||
image::image(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
const cl_image_format *format,
|
||||
size_t width, size_t height, size_t depth,
|
||||
size_t row_pitch, size_t slice_pitch, size_t size,
|
||||
void *host_ptr) :
|
||||
memory_obj(ctx, flags, size, host_ptr),
|
||||
memory_obj(ctx, properties, flags, size, host_ptr),
|
||||
_format(*format), _width(width), _height(height), _depth(depth),
|
||||
_row_pitch(row_pitch), _slice_pitch(slice_pitch) {
|
||||
}
|
||||
|
|
@ -230,11 +243,13 @@ image::slice_pitch() const {
|
|||
return _slice_pitch;
|
||||
}
|
||||
|
||||
image2d::image2d(clover::context &ctx, cl_mem_flags flags,
|
||||
image2d::image2d(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
const cl_image_format *format, size_t width,
|
||||
size_t height, size_t row_pitch,
|
||||
void *host_ptr) :
|
||||
image(ctx, flags, format, width, height, 1,
|
||||
image(ctx, properties, flags, format, width, height, 1,
|
||||
row_pitch, 0, height * row_pitch, host_ptr) {
|
||||
}
|
||||
|
||||
|
|
@ -243,12 +258,14 @@ image2d::type() const {
|
|||
return CL_MEM_OBJECT_IMAGE2D;
|
||||
}
|
||||
|
||||
image3d::image3d(clover::context &ctx, cl_mem_flags flags,
|
||||
image3d::image3d(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
const cl_image_format *format,
|
||||
size_t width, size_t height, size_t depth,
|
||||
size_t row_pitch, size_t slice_pitch,
|
||||
void *host_ptr) :
|
||||
image(ctx, flags, format, width, height, depth,
|
||||
image(ctx, properties, flags, format, width, height, depth,
|
||||
row_pitch, slice_pitch, depth * slice_pitch,
|
||||
host_ptr) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@
|
|||
namespace clover {
|
||||
class memory_obj : public ref_counter, public _cl_mem {
|
||||
protected:
|
||||
memory_obj(clover::context &ctx, cl_mem_flags flags,
|
||||
memory_obj(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
size_t size, void *host_ptr);
|
||||
|
||||
memory_obj(const memory_obj &obj) = delete;
|
||||
|
|
@ -56,6 +58,7 @@ namespace clover {
|
|||
virtual void resource_out(command_queue &q) = 0;
|
||||
|
||||
void destroy_notify(std::function<void ()> f);
|
||||
std::vector<cl_mem_properties> properties() const;
|
||||
cl_mem_flags flags() const;
|
||||
size_t size() const;
|
||||
void *host_ptr() const;
|
||||
|
|
@ -63,6 +66,7 @@ namespace clover {
|
|||
const intrusive_ref<clover::context> context;
|
||||
|
||||
private:
|
||||
std::vector<cl_mem_properties> _properties;
|
||||
cl_mem_flags _flags;
|
||||
size_t _size;
|
||||
void *_host_ptr;
|
||||
|
|
@ -74,7 +78,9 @@ namespace clover {
|
|||
|
||||
class buffer : public memory_obj {
|
||||
protected:
|
||||
buffer(clover::context &ctx, cl_mem_flags flags,
|
||||
buffer(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
size_t size, void *host_ptr);
|
||||
|
||||
public:
|
||||
|
|
@ -83,7 +89,9 @@ namespace clover {
|
|||
|
||||
class root_buffer : public buffer {
|
||||
public:
|
||||
root_buffer(clover::context &ctx, cl_mem_flags flags,
|
||||
root_buffer(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
size_t size, void *host_ptr);
|
||||
|
||||
virtual clover::resource &
|
||||
|
|
@ -124,7 +132,9 @@ namespace clover {
|
|||
|
||||
class image : public memory_obj {
|
||||
protected:
|
||||
image(clover::context &ctx, cl_mem_flags flags,
|
||||
image(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
const cl_image_format *format,
|
||||
size_t width, size_t height, size_t depth,
|
||||
size_t row_pitch, size_t slice_pitch, size_t size,
|
||||
|
|
@ -161,7 +171,9 @@ namespace clover {
|
|||
|
||||
class image2d : public image {
|
||||
public:
|
||||
image2d(clover::context &ctx, cl_mem_flags flags,
|
||||
image2d(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
const cl_image_format *format, size_t width,
|
||||
size_t height, size_t row_pitch,
|
||||
void *host_ptr);
|
||||
|
|
@ -171,7 +183,9 @@ namespace clover {
|
|||
|
||||
class image3d : public image {
|
||||
public:
|
||||
image3d(clover::context &ctx, cl_mem_flags flags,
|
||||
image3d(clover::context &ctx,
|
||||
std::vector<cl_mem_properties> properties,
|
||||
cl_mem_flags flags,
|
||||
const cl_image_format *format,
|
||||
size_t width, size_t height, size_t depth,
|
||||
size_t row_pitch, size_t slice_pitch,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue