diff --git a/src/gallium/frontends/clover/core/kernel.cpp b/src/gallium/frontends/clover/core/kernel.cpp index 36a81ee04e1..16be95e5906 100644 --- a/src/gallium/frontends/clover/core/kernel.cpp +++ b/src/gallium/frontends/clover/core/kernel.cpp @@ -523,11 +523,12 @@ kernel::local_argument::set(size_t size, const void *value) { void kernel::local_argument::bind(exec_context &ctx, const module::argument &marg) { + ctx.mem_local = ::align(ctx.mem_local, marg.target_align); auto v = bytes(ctx.mem_local); extend(v, module::argument::zero_ext, marg.target_size); byteswap(v, ctx.q->device().endianness()); - align(ctx.input, marg.target_align); + align(ctx.input, ctx.q->device().address_bits() / 8); insert(ctx.input, v); ctx.mem_local += _storage; diff --git a/src/gallium/frontends/clover/core/module.hpp b/src/gallium/frontends/clover/core/module.hpp index 9825ea259b9..d7c669d1b7b 100644 --- a/src/gallium/frontends/clover/core/module.hpp +++ b/src/gallium/frontends/clover/core/module.hpp @@ -125,7 +125,9 @@ namespace clover { type type; size_t size; size_t target_size; - size_t target_align; + size_t target_align; // For arguments of type local, this represents + // the alignment requirement for the pointed + // type and for the pointer itself. ext_type ext_type; semantic semantic; arg_info info; diff --git a/src/gallium/frontends/clover/llvm/codegen/common.cpp b/src/gallium/frontends/clover/llvm/codegen/common.cpp index 1c3e822aac8..2ed46794def 100644 --- a/src/gallium/frontends/clover/llvm/codegen/common.cpp +++ b/src/gallium/frontends/clover/llvm/codegen/common.cpp @@ -213,8 +213,11 @@ namespace { const auto offset = static_cast(clang::LangAS::opencl_local); if (address_space == map[offset]) { + const auto pointee_type = cast< + ::llvm::PointerType>(actual_type)->getElementType(); args.emplace_back(module::argument::local, arg_api_size, - target_size, target_align, + target_size, + dl.getABITypeAlignment(pointee_type), module::argument::zero_ext); } else { // XXX: Correctly handle constant address space. There is no diff --git a/src/gallium/frontends/clover/spirv/invocation.cpp b/src/gallium/frontends/clover/spirv/invocation.cpp index ec425e2c7d6..cec265d87ed 100644 --- a/src/gallium/frontends/clover/spirv/invocation.cpp +++ b/src/gallium/frontends/clover/spirv/invocation.cpp @@ -350,10 +350,16 @@ namespace { if (opcode == SpvOpTypePointer) pointer_types[id] = get(inst, 3); + module::size_t alignment; + if (storage_class == SpvStorageClassWorkgroup) + alignment = opcode == SpvOpTypePointer ? types[pointer_types[id]].target_align : 0; + else + alignment = pointer_byte_size; + types[id] = { convert_storage_class(storage_class, err), sizeof(cl_mem), static_cast(pointer_byte_size), - static_cast(pointer_byte_size), + alignment, module::argument::zero_ext }; types[id].info.address_qualifier = convert_storage_class_to_cl(storage_class); break;