diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 176186df3e..65a2178bf0 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -274,7 +274,9 @@ namespace dawn_native { namespace metal { // The lengths of buffers are stored as 32bit integers because that is the width the // MSL code generated by SPIRV-Cross expects. - PerStage> data; + // UBOs require we align the max buffer count to 4 elements (16 bytes). + static constexpr size_t MaxBufferCount = ((kGenericMetalBufferSlots + 3) / 4) * 4; + PerStage> data; void Apply(id render, RenderPipeline* pipeline, @@ -294,10 +296,9 @@ namespace dawn_native { namespace metal { 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() length:sizeof(uint32_t) * bufferCount atIndex:kBufferLengthBufferSlot]; @@ -306,10 +307,9 @@ namespace dawn_native { namespace metal { if (stagesToApply & wgpu::ShaderStage::Fragment) { uint32_t bufferCount = ToBackend(pipeline->GetLayout()) ->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() length:sizeof(uint32_t) * bufferCount atIndex:kBufferLengthBufferSlot]; @@ -330,10 +330,9 @@ namespace dawn_native { namespace metal { uint32_t bufferCount = ToBackend(pipeline->GetLayout()) ->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() length:sizeof(uint32_t) * bufferCount atIndex:kBufferLengthBufferSlot];