diff options
Diffstat (limited to 'lib/mesa/src/gallium/state_trackers/clover/api/memory.cpp')
-rw-r--r-- | lib/mesa/src/gallium/state_trackers/clover/api/memory.cpp | 213 |
1 files changed, 85 insertions, 128 deletions
diff --git a/lib/mesa/src/gallium/state_trackers/clover/api/memory.cpp b/lib/mesa/src/gallium/state_trackers/clover/api/memory.cpp index df4b9baa1..1efb95b5c 100644 --- a/lib/mesa/src/gallium/state_trackers/clover/api/memory.cpp +++ b/lib/mesa/src/gallium/state_trackers/clover/api/memory.cpp @@ -28,58 +28,37 @@ using namespace clover; namespace { - cl_mem_flags - validate_flags(cl_mem d_parent, cl_mem_flags d_flags) { - const cl_mem_flags dev_access_flags = - CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY; - const cl_mem_flags host_ptr_flags = - CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR; - const cl_mem_flags host_access_flags = - CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS; - const cl_mem_flags valid_flags = - dev_access_flags | host_access_flags | (d_parent ? 0 : host_ptr_flags); - - if ((d_flags & ~valid_flags) || - util_bitcount(d_flags & dev_access_flags) > 1 || - util_bitcount(d_flags & host_access_flags) > 1) + const cl_mem_flags dev_access_flags = + CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY; + const cl_mem_flags host_ptr_flags = + CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR; + const cl_mem_flags host_access_flags = + CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS; + const cl_mem_flags all_mem_flags = + dev_access_flags | host_ptr_flags | host_access_flags; + + void + validate_flags(cl_mem_flags flags, cl_mem_flags valid) { + if ((flags & ~valid) || + util_bitcount(flags & dev_access_flags) > 1 || + util_bitcount(flags & host_access_flags) > 1) throw error(CL_INVALID_VALUE); - if ((d_flags & CL_MEM_USE_HOST_PTR) && - (d_flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))) + if ((flags & CL_MEM_USE_HOST_PTR) && + (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))) throw error(CL_INVALID_VALUE); - - if (d_parent) { - const auto &parent = obj(d_parent); - const cl_mem_flags flags = (d_flags | - (d_flags & dev_access_flags ? 0 : - parent.flags() & dev_access_flags) | - (d_flags & host_access_flags ? 0 : - parent.flags() & host_access_flags) | - (parent.flags() & host_ptr_flags)); - - if (~flags & parent.flags() & (dev_access_flags & ~CL_MEM_READ_WRITE)) - throw error(CL_INVALID_VALUE); - - // Check if new host access flags cause a mismatch between - // host-read/write-only. - if (!(flags & CL_MEM_HOST_NO_ACCESS) && - (~flags & parent.flags() & host_access_flags)) - throw error(CL_INVALID_VALUE); - - return flags; - - } else { - return d_flags | (d_flags & dev_access_flags ? 0 : CL_MEM_READ_WRITE); - } } } 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); + const cl_mem_flags flags = d_flags | + (d_flags & dev_access_flags ? 0 : CL_MEM_READ_WRITE); auto &ctx = obj(d_ctx); + validate_flags(d_flags, all_mem_flags); + if (bool(host_ptr) != bool(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) throw error(CL_INVALID_HOST_PTR); @@ -103,7 +82,16 @@ clCreateSubBuffer(cl_mem d_mem, cl_mem_flags d_flags, cl_buffer_create_type op, const void *op_info, cl_int *r_errcode) try { auto &parent = obj<root_buffer>(d_mem); - const cl_mem_flags flags = validate_flags(d_mem, d_flags); + const cl_mem_flags flags = d_flags | + (d_flags & dev_access_flags ? 0 : parent.flags() & dev_access_flags) | + (d_flags & host_access_flags ? 0 : parent.flags() & host_access_flags) | + (parent.flags() & host_ptr_flags); + + validate_flags(d_flags, dev_access_flags | host_access_flags); + + if (~flags & parent.flags() & + ((dev_access_flags & ~CL_MEM_READ_WRITE) | host_access_flags)) + throw error(CL_INVALID_VALUE); if (op == CL_BUFFER_CREATE_TYPE_REGION) { auto reg = reinterpret_cast<const cl_buffer_region *>(op_info); @@ -129,90 +117,35 @@ 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 { +clCreateImage2D(cl_context d_ctx, cl_mem_flags d_flags, + const cl_image_format *format, + size_t width, size_t height, size_t row_pitch, + void *host_ptr, cl_int *r_errcode) try { + const cl_mem_flags flags = d_flags | + (d_flags & dev_access_flags ? 0 : CL_MEM_READ_WRITE); auto &ctx = obj(d_ctx); + validate_flags(d_flags, all_mem_flags); + if (!any_of(std::mem_fn(&device::image_support), ctx.devices())) throw error(CL_INVALID_OPERATION); if (!format) throw error(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR); - if (!desc) - throw error(CL_INVALID_IMAGE_DESCRIPTOR); - - if (desc->image_array_size == 0 && - (desc->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || - desc->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)) - throw error(CL_INVALID_IMAGE_DESCRIPTOR); - - if (!host_ptr && - (desc->image_row_pitch || desc->image_slice_pitch)) - throw error(CL_INVALID_IMAGE_DESCRIPTOR); - - if (desc->num_mip_levels || desc->num_samples) - throw error(CL_INVALID_IMAGE_DESCRIPTOR); - - if (bool(desc->buffer) != (desc->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER)) - throw error(CL_INVALID_IMAGE_DESCRIPTOR); + if (width < 1 || height < 1) + throw error(CL_INVALID_IMAGE_SIZE); - if (bool(host_ptr) != bool(d_flags & (CL_MEM_USE_HOST_PTR | - CL_MEM_COPY_HOST_PTR))) + if (bool(host_ptr) != bool(flags & (CL_MEM_USE_HOST_PTR | + CL_MEM_COPY_HOST_PTR))) throw error(CL_INVALID_HOST_PTR); - const cl_mem_flags flags = validate_flags(desc->buffer, d_flags); - - if (!supported_formats(ctx, desc->image_type).count(*format)) + if (!supported_formats(ctx, CL_MEM_OBJECT_IMAGE2D).count(*format)) throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); ret_error(r_errcode, CL_SUCCESS); - - switch (desc->image_type) { - case CL_MEM_OBJECT_IMAGE2D: - if (!desc->image_width || !desc->image_height) - throw error(CL_INVALID_IMAGE_SIZE); - - if (all_of([=](const device &dev) { - const size_t max = 1 << dev.max_image_levels_2d(); - return (desc->image_width > max || - desc->image_height > max); - }, ctx.devices())) - throw error(CL_INVALID_IMAGE_SIZE); - - return new image2d(ctx, flags, format, - desc->image_width, desc->image_height, - desc->image_row_pitch, host_ptr); - - case CL_MEM_OBJECT_IMAGE3D: - if (!desc->image_width || !desc->image_height || !desc->image_depth) - throw error(CL_INVALID_IMAGE_SIZE); - - if (all_of([=](const device &dev) { - const size_t max = 1 << dev.max_image_levels_3d(); - return (desc->image_width > max || - desc->image_height > max || - desc->image_depth > max); - }, ctx.devices())) - throw error(CL_INVALID_IMAGE_SIZE); - - return new image3d(ctx, flags, format, - desc->image_width, desc->image_height, - desc->image_depth, desc->image_row_pitch, - desc->image_slice_pitch, host_ptr); - - case CL_MEM_OBJECT_IMAGE1D: - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - case CL_MEM_OBJECT_IMAGE1D_BUFFER: - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - // XXX - Not implemented. - throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); - - default: - throw error(CL_INVALID_IMAGE_DESCRIPTOR); - } + return new image2d(ctx, flags, format, width, height, + row_pitch, host_ptr); } catch (error &e) { ret_error(r_errcode, e); @@ -220,26 +153,40 @@ clCreateImage(cl_context d_ctx, cl_mem_flags d_flags, } CLOVER_API cl_mem -clCreateImage2D(cl_context d_ctx, cl_mem_flags d_flags, - const cl_image_format *format, - size_t width, size_t height, size_t row_pitch, - void *host_ptr, cl_int *r_errcode) { - 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); -} - -CLOVER_API cl_mem clCreateImage3D(cl_context d_ctx, cl_mem_flags d_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, cl_int *r_errcode) { - const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, - row_pitch, slice_pitch, 0, 0, NULL }; + void *host_ptr, cl_int *r_errcode) try { + const cl_mem_flags flags = d_flags | + (d_flags & dev_access_flags ? 0 : CL_MEM_READ_WRITE); + auto &ctx = obj(d_ctx); + + validate_flags(d_flags, all_mem_flags); + + if (!any_of(std::mem_fn(&device::image_support), ctx.devices())) + throw error(CL_INVALID_OPERATION); + + if (!format) + throw error(CL_INVALID_IMAGE_FORMAT_DESCRIPTOR); + + if (width < 1 || height < 1 || depth < 2) + throw error(CL_INVALID_IMAGE_SIZE); + + if (bool(host_ptr) != bool(flags & (CL_MEM_USE_HOST_PTR | + CL_MEM_COPY_HOST_PTR))) + throw error(CL_INVALID_HOST_PTR); - return clCreateImage(d_ctx, d_flags, format, &desc, host_ptr, r_errcode); + if (!supported_formats(ctx, CL_MEM_OBJECT_IMAGE3D).count(*format)) + throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED); + + ret_error(r_errcode, CL_SUCCESS); + return new image3d(ctx, flags, format, width, height, depth, + row_pitch, slice_pitch, host_ptr); + +} catch (error &e) { + ret_error(r_errcode, e); + return NULL; } CLOVER_API cl_int @@ -249,7 +196,7 @@ clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags, auto &ctx = obj(d_ctx); auto formats = supported_formats(ctx, type); - validate_flags(NULL, flags); + validate_flags(flags, all_mem_flags); if (r_buf && !r_count) throw error(CL_INVALID_VALUE); @@ -405,6 +352,16 @@ clSetMemObjectDestructorCallback(cl_mem d_mem, return e.get(); } +CLOVER_API cl_mem +clCreateImage(cl_context d_ctx, cl_mem_flags flags, + const cl_image_format *format, + const cl_image_desc *image_desc, + void *host_ptr, cl_int *r_errcode) { + CLOVER_NOT_SUPPORTED_UNTIL("1.2"); + ret_error(r_errcode, CL_INVALID_OPERATION); + return NULL; +} + CLOVER_API cl_int clEnqueueFillBuffer(cl_command_queue command_queue, cl_mem buffer, const void *pattern, size_t pattern_size, |