Make storage buffer length UBO size a multiple of 16 bytes

Conditional on whether TINT_EXPECTS_UBOS_TO_BE_MULTIPLE_OF_16 is
defined, which it will be in a future Tint CL.

Bug: tint:984
Change-Id: I191cd59fe6947c9113a8fad7dbfbf79903969b27
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/57960
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Antonio Maiorano 2021-07-14 15:33:31 +00:00 committed by Dawn LUCI CQ
parent 954e8abe48
commit 58016bfb31
1 changed files with 15 additions and 1 deletions

View File

@ -30,6 +30,8 @@
#include "dawn_native/metal/TextureMTL.h" #include "dawn_native/metal/TextureMTL.h"
#include "dawn_native/metal/UtilsMetal.h" #include "dawn_native/metal/UtilsMetal.h"
#include <tint/tint.h>
namespace dawn_native { namespace metal { namespace dawn_native { namespace metal {
namespace { namespace {
@ -272,7 +274,7 @@ namespace dawn_native { namespace metal {
// The lengths of buffers are stored as 32bit integers because that is the width the // The lengths of buffers are stored as 32bit integers because that is the width the
// MSL code generated by SPIRV-Cross expects. // MSL code generated by SPIRV-Cross expects.
PerStage<std::array<uint32_t, kGenericMetalBufferSlots>> data; PerStage<std::array<uint32_t, ((kGenericMetalBufferSlots / 4) + 1) * 4>> data;
void Apply(id<MTLRenderCommandEncoder> render, void Apply(id<MTLRenderCommandEncoder> render,
RenderPipeline* pipeline, RenderPipeline* pipeline,
@ -292,6 +294,10 @@ namespace dawn_native { namespace metal {
bufferCount += pipeline->GetVertexBufferCount(); bufferCount += pipeline->GetVertexBufferCount();
} }
#ifdef TINT_EXPECTS_UBOS_TO_BE_MULTIPLE_OF_16
bufferCount = Align(bufferCount, 4);
ASSERT(bufferCount <= data[SingleShaderStage::Vertex].size());
#endif
[render setVertexBytes:data[SingleShaderStage::Vertex].data() [render setVertexBytes:data[SingleShaderStage::Vertex].data()
length:sizeof(uint32_t) * bufferCount length:sizeof(uint32_t) * bufferCount
atIndex:kBufferLengthBufferSlot]; atIndex:kBufferLengthBufferSlot];
@ -300,6 +306,10 @@ namespace dawn_native { namespace metal {
if (stagesToApply & wgpu::ShaderStage::Fragment) { if (stagesToApply & wgpu::ShaderStage::Fragment) {
uint32_t bufferCount = ToBackend(pipeline->GetLayout()) uint32_t bufferCount = ToBackend(pipeline->GetLayout())
->GetBufferBindingCount(SingleShaderStage::Fragment); ->GetBufferBindingCount(SingleShaderStage::Fragment);
#ifdef TINT_EXPECTS_UBOS_TO_BE_MULTIPLE_OF_16
bufferCount = Align(bufferCount, 4);
ASSERT(bufferCount <= data[SingleShaderStage::Fragment].size());
#endif
[render setFragmentBytes:data[SingleShaderStage::Fragment].data() [render setFragmentBytes:data[SingleShaderStage::Fragment].data()
length:sizeof(uint32_t) * bufferCount length:sizeof(uint32_t) * bufferCount
atIndex:kBufferLengthBufferSlot]; atIndex:kBufferLengthBufferSlot];
@ -320,6 +330,10 @@ namespace dawn_native { namespace metal {
uint32_t bufferCount = ToBackend(pipeline->GetLayout()) uint32_t bufferCount = ToBackend(pipeline->GetLayout())
->GetBufferBindingCount(SingleShaderStage::Compute); ->GetBufferBindingCount(SingleShaderStage::Compute);
#ifdef TINT_EXPECTS_UBOS_TO_BE_MULTIPLE_OF_16
bufferCount = Align(bufferCount, 4);
ASSERT(bufferCount <= data[SingleShaderStage::Compute].size());
#endif
[compute setBytes:data[SingleShaderStage::Compute].data() [compute setBytes:data[SingleShaderStage::Compute].data()
length:sizeof(uint32_t) * bufferCount length:sizeof(uint32_t) * bufferCount
atIndex:kBufferLengthBufferSlot]; atIndex:kBufferLengthBufferSlot];