[Mesa-dev] [PATCH 3/3] clover: Add checks for image support to the image functions
Francisco Jerez
currojerez at riseup.net
Fri Jul 25 03:30:27 PDT 2014
Tom Stellard <thomas.stellard at amd.com> writes:
> Most image functions are required to return a CL_INVALID_OPERATION
> error when used on devices without image support.
> ---
> src/gallium/state_trackers/clover/api/memory.cpp | 6 ++++++
> src/gallium/state_trackers/clover/api/sampler.cpp | 3 +++
> src/gallium/state_trackers/clover/api/transfer.cpp | 17 +++++++++++++++++
> src/gallium/state_trackers/clover/core/context.cpp | 9 +++++++++
> src/gallium/state_trackers/clover/core/context.hpp | 2 ++
> 5 files changed, 37 insertions(+)
>
> diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp
> index d26b1c6..77f8b96 100644
> --- a/src/gallium/state_trackers/clover/api/memory.cpp
> +++ b/src/gallium/state_trackers/clover/api/memory.cpp
> @@ -106,6 +106,9 @@ clCreateImage2D(cl_context d_ctx, cl_mem_flags flags,
> void *host_ptr, cl_int *r_errcode) try {
> auto &ctx = obj(d_ctx);
>
> + if (!ctx.image_support())
> + throw error(CL_INVALID_OPERATION);
> +
Just use:
| if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))
| throw error(CL_INVALID_OPERATION);
> if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
> CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR |
> CL_MEM_COPY_HOST_PTR))
> @@ -141,6 +144,9 @@ clCreateImage3D(cl_context d_ctx, cl_mem_flags flags,
> void *host_ptr, cl_int *r_errcode) try {
> auto &ctx = obj(d_ctx);
>
> + if (!ctx.image_support())
> + throw error(CL_INVALID_OPERATION);
> +
Same here.
> if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
> CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR |
> CL_MEM_COPY_HOST_PTR))
> diff --git a/src/gallium/state_trackers/clover/api/sampler.cpp b/src/gallium/state_trackers/clover/api/sampler.cpp
> index 403892b..7f2e04d 100644
> --- a/src/gallium/state_trackers/clover/api/sampler.cpp
> +++ b/src/gallium/state_trackers/clover/api/sampler.cpp
> @@ -31,6 +31,9 @@ clCreateSampler(cl_context d_ctx, cl_bool norm_mode,
> cl_int *r_errcode) try {
> auto &ctx = obj(d_ctx);
>
> + if (!ctx.image_support())
> + throw error(CL_INVALID_OPERATION);
> +
And here.
> ret_error(r_errcode, CL_SUCCESS);
> return new sampler(ctx, norm_mode, addr_mode, filter_mode);
>
> diff --git a/src/gallium/state_trackers/clover/api/transfer.cpp b/src/gallium/state_trackers/clover/api/transfer.cpp
> index 404ceb0..da12d2b 100644
> --- a/src/gallium/state_trackers/clover/api/transfer.cpp
> +++ b/src/gallium/state_trackers/clover/api/transfer.cpp
> @@ -457,6 +457,8 @@ clEnqueueReadImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
> auto src_origin = vector(p_origin);
> auto src_pitch = pitch(region, {{ img.pixel_size(),
> img.row_pitch(), img.slice_pitch() }});
> + if (!q.device().image_support())
> + throw error(CL_INVALID_OPERATION);
>
Move this into 'validate_object(command_queue &, image &, ...)' so you
don't have to repeat the same check in every image transfer function.
> validate_common(q, deps);
> validate_object(q, ptr, {}, dst_pitch, region);
> @@ -491,6 +493,9 @@ clEnqueueWriteImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
> auto src_pitch = pitch(region, {{ img.pixel_size(),
> row_pitch, slice_pitch }});
>
> + if (!q.device().image_support())
> + throw error(CL_INVALID_OPERATION);
> +
> validate_common(q, deps);
> validate_object(q, img, dst_origin, region);
> validate_object(q, ptr, {}, src_pitch, region);
> @@ -522,6 +527,9 @@ clEnqueueCopyImage(cl_command_queue d_q, cl_mem d_src_mem, cl_mem d_dst_mem,
> auto dst_origin = vector(p_dst_origin);
> auto src_origin = vector(p_src_origin);
>
> + if (!q.device().image_support())
> + throw error(CL_INVALID_OPERATION);
> +
> validate_common(q, deps);
> validate_object(q, dst_img, dst_origin, region);
> validate_object(q, src_img, src_origin, region);
> @@ -559,6 +567,9 @@ clEnqueueCopyImageToBuffer(cl_command_queue d_q,
> src_img.row_pitch(),
> src_img.slice_pitch() }});
>
> + if (!q.device().image_support())
> + throw error(CL_INVALID_OPERATION);
> +
> validate_common(q, deps);
> validate_object(q, dst_mem, dst_origin, dst_pitch, region);
> validate_object(q, src_img, src_origin, region);
> @@ -595,6 +606,9 @@ clEnqueueCopyBufferToImage(cl_command_queue d_q,
> vector_t src_origin = { src_offset };
> auto src_pitch = pitch(region, {{ dst_img.pixel_size() }});
>
> + if (!q.device().image_support())
> + throw error(CL_INVALID_OPERATION);
> +
> validate_common(q, deps);
> validate_object(q, dst_img, dst_origin, region);
> validate_object(q, src_mem, src_origin, src_pitch, region);
> @@ -651,6 +665,9 @@ clEnqueueMapImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
> auto region = vector(p_region);
> auto origin = vector(p_origin);
>
> + if (!q.device().image_support())
> + throw error(CL_INVALID_OPERATION);
> +
> validate_common(q, deps);
> validate_object(q, img, origin, region);
>
> diff --git a/src/gallium/state_trackers/clover/core/context.cpp b/src/gallium/state_trackers/clover/core/context.cpp
> index bf4df39..722c97d 100644
> --- a/src/gallium/state_trackers/clover/core/context.cpp
> +++ b/src/gallium/state_trackers/clover/core/context.cpp
> @@ -48,3 +48,12 @@ context::device_range
> context::devices() const {
> return map(evals(), devs);
> }
> +
> +bool
> +context::image_support() const {
> + for (const device &dev : devs) {
> + if (dev.image_support())
> + return true;
> + }
> + return false;
> +}
> diff --git a/src/gallium/state_trackers/clover/core/context.hpp b/src/gallium/state_trackers/clover/core/context.hpp
> index 0ec4ff4..d3c095f 100644
> --- a/src/gallium/state_trackers/clover/core/context.hpp
> +++ b/src/gallium/state_trackers/clover/core/context.hpp
> @@ -53,6 +53,8 @@ namespace clover {
> device_range
> devices() const;
>
> + bool image_support() const;
> +
> private:
> property_list props;
> const std::vector<intrusive_ref<device>> devs;
> --
> 1.8.1.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 212 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140725/0c035a80/attachment.sig>
More information about the mesa-dev
mailing list