diff options
author | Francisco Jerez <[email protected]> | 2013-07-21 01:14:54 +0200 |
---|---|---|
committer | Francisco Jerez <[email protected]> | 2013-07-22 23:09:34 +0200 |
commit | df530829f757a8968389427eb26f45a0d46623fa (patch) | |
tree | 2d4a27391420df49508c980a3c168c18d02e3cdc | |
parent | f64c0ca692d3e8c78dd9ae1f015f58f1dfc1c760 (diff) |
clover: Respect kernel argument alignment restrictions.
Cc: [email protected]
Reviewed-by: Tom Stellard <[email protected]>
-rw-r--r-- | src/gallium/state_trackers/clover/core/kernel.cpp | 16 | ||||
-rw-r--r-- | src/gallium/state_trackers/clover/llvm/invocation.cpp | 5 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp index 7023f291fe2..93d54107baf 100644 --- a/src/gallium/state_trackers/clover/core/kernel.cpp +++ b/src/gallium/state_trackers/clover/core/kernel.cpp @@ -22,6 +22,7 @@ #include "core/kernel.hpp" #include "core/resource.hpp" +#include "util/u_math.h" #include "pipe/p_context.h" using namespace clover; @@ -197,6 +198,15 @@ namespace { std::reverse(v.begin(), v.end()); } + /// + /// Pad buffer \a v to the next multiple of \a n. + /// + template<typename T> + void + align(T &v, size_t n) { + v.resize(util_align_npot(v.size(), n)); + } + bool msb(const std::vector<uint8_t> &s) { if (PIPE_ENDIAN_NATIVE == PIPE_ENDIAN_LITTLE) @@ -278,6 +288,7 @@ _cl_kernel::scalar_argument::bind(exec_context &ctx, extend(w, marg.ext_type, marg.target_size); byteswap(w, ctx.q->dev.endianness()); + align(ctx.input, marg.target_align); insert(ctx.input, w); } @@ -300,6 +311,7 @@ _cl_kernel::global_argument::set(size_t size, const void *value) { void _cl_kernel::global_argument::bind(exec_context &ctx, const clover::module::argument &marg) { + align(ctx.input, marg.target_align); ctx.g_handles.push_back(allocate(ctx.input, marg.target_size)); ctx.g_buffers.push_back(obj->resource(ctx.q).pipe); } @@ -329,6 +341,7 @@ _cl_kernel::local_argument::bind(exec_context &ctx, extend(v, module::argument::zero_ext, marg.target_size); byteswap(v, ctx.q->dev.endianness()); + align(ctx.input, marg.target_align); insert(ctx.input, v); ctx.mem_local += __storage; @@ -357,6 +370,7 @@ _cl_kernel::constant_argument::bind(exec_context &ctx, extend(v, module::argument::zero_ext, marg.target_size); byteswap(v, ctx.q->dev.endianness()); + align(ctx.input, marg.target_align); insert(ctx.input, v); st = obj->resource(ctx.q).bind_surface(*ctx.q, false); @@ -387,6 +401,7 @@ _cl_kernel::image_rd_argument::bind(exec_context &ctx, extend(v, module::argument::zero_ext, marg.target_size); byteswap(v, ctx.q->dev.endianness()); + align(ctx.input, marg.target_align); insert(ctx.input, v); st = obj->resource(ctx.q).bind_sampler_view(*ctx.q); @@ -417,6 +432,7 @@ _cl_kernel::image_wr_argument::bind(exec_context &ctx, extend(v, module::argument::zero_ext, marg.target_size); byteswap(v, ctx.q->dev.endianness()); + align(ctx.input, marg.target_align); insert(ctx.input, v); st = obj->resource(ctx.q).bind_surface(*ctx.q, true); diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp index a50cf37dfcb..2c6c1d46882 100644 --- a/src/gallium/state_trackers/clover/llvm/invocation.cpp +++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp @@ -317,6 +317,7 @@ namespace { TD.getSmallestLegalIntType(mod->getContext(), arg_size * 8) : arg_type; unsigned target_size = TD.getTypeStoreSize(target_type); + unsigned target_align = TD.getABITypeAlignment(target_type); if (llvm::isa<llvm::PointerType>(arg_type) && arg.hasByValAttr()) { arg_type = @@ -332,7 +333,7 @@ namespace { default: args.push_back( module::argument(module::argument::global, arg_size, - target_size, 0, + target_size, target_align, module::argument::zero_ext)); break; } @@ -347,7 +348,7 @@ namespace { args.push_back( module::argument(module::argument::scalar, arg_size, - target_size, 0, ext_type)); + target_size, target_align, ext_type)); } } |