diff options
author | Jan Vesely <jan.vesely@rutgers.edu> | 2013-12-17 11:19:09 -0500 |
---|---|---|
committer | Francisco Jerez <currojerez@riseup.net> | 2013-12-18 16:18:15 +0100 |
commit | 21f82188ce389a2543c894dd6d88fbebb25cc796 (patch) | |
tree | a6fc243bed9ec7fd6b51175a1e75aaf814e4e1d7 /src/gallium | |
parent | 78fcc31d4a8179ca24a8008a1ad1ca6bdb668fdd (diff) | |
download | external_mesa3d-21f82188ce389a2543c894dd6d88fbebb25cc796.zip external_mesa3d-21f82188ce389a2543c894dd6d88fbebb25cc796.tar.gz external_mesa3d-21f82188ce389a2543c894dd6d88fbebb25cc796.tar.bz2 |
clover: Add parameter checks to clCreateBuffer.
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@rutgers.edu>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/state_trackers/clover/api/memory.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/gallium/state_trackers/clover/api/memory.cpp b/src/gallium/state_trackers/clover/api/memory.cpp index 785a509..b8b3692 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,10 @@ 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 +47,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); |