[Mesa-dev] [PATCH v2 1/1] clover: Add parameter checks to clCreateBuffer.

Francisco Jerez currojerez at riseup.net
Wed Dec 18 07:27:38 PST 2013


Jan Vesely <jan.vesely at rutgers.edu> writes:

> v2: use fewer if statements and functional tricks instead of single-use method,
>     suggested by Francisco Jerez
>     squash two small patches into one
>
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
> Hi,
>
> this is v2 of the first two patches incorporating Francisco's comments,
> i.e. it's the code from his comments :)
>
> I squashed the two patches into one.
> This patch makes the clCreateBuffer piglit test complain a lot less.
>

I've pushed this patch together with your host_ptr append patch.

Thanks.

>
> regards,
> Jan
>
>  src/gallium/state_trackers/clover/api/memory.cpp | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp
> index 785a509..3320db9 100644
> --- a/src/gallium/state_trackers/clover/api/memory.cpp
> +++ b/src/gallium/state_trackers/clover/api/memory.cpp
> @@ -20,6 +20,7 @@
>  // OTHER DEALINGS IN THE SOFTWARE.
>  //
>  
> +#include "util/u_math.h"
>  #include "api/util.hpp"
>  #include "core/memory.hpp"
>  #include "core/format.hpp"
> @@ -35,7 +36,8 @@ clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size,
>                                         CL_MEM_COPY_HOST_PTR)))
>        throw error(CL_INVALID_HOST_PTR);
>  
> -   if (!size)
> +   if (!size || size > fold(maximum(), 0u,
> +                map(std::mem_fn(&device::max_mem_alloc_size), ctx.devs())))
>        throw error(CL_INVALID_BUFFER_SIZE);
>  
>     if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
> @@ -43,6 +45,14 @@ clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size,
>                   CL_MEM_COPY_HOST_PTR))
>        throw error(CL_INVALID_VALUE);
>  
> +   if (util_bitcount(flags & (CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY |
> +                              CL_MEM_READ_WRITE)) > 1)
> +      throw error(CL_INVALID_VALUE);
> +
> +   if ((flags & CL_MEM_USE_HOST_PTR) &&
> +       (flags & (CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)))
> +      throw error(CL_INVALID_VALUE);
> +
>     ret_error(r_errcode, CL_SUCCESS);
>     return new root_buffer(ctx, flags, size, host_ptr);
>  
> -- 
> 1.8.3.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 229 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131218/74c6892b/attachment.pgp>


More information about the mesa-dev mailing list