[dawn] Remove support for 64-bit dynamic offsets Dynamic offsets are 32-bit per the JS and C APIs (originally due to constraints of Vulkan: https://dawn-review.googlesource.com/c/dawn/+/11080/9/src/dawn_native/BindGroupTracker.h). There's no need to allow 64-bit offsets in some backends if the frontend doesn't support it. Bug: none, 363031535 Change-Id: I56f85ad59854886c28047e012c836dfe8bd69daf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/294098 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/BindGroupTracker.h b/src/dawn/native/BindGroupTracker.h index f3f89c4..c04e904 100644 --- a/src/dawn/native/BindGroupTracker.h +++ b/src/dawn/native/BindGroupTracker.h
@@ -42,9 +42,7 @@ // Keeps track of the dirty bind groups so they can be lazily applied when we know the // pipeline state or it changes. -// |DynamicOffset| is a template parameter because offsets in Vulkan are uint32_t but uint64_t -// in other backends. -template <bool CanInheritBindGroups, typename DynamicOffset> +template <bool CanInheritBindGroups> class BindGroupTrackerBase { public: void OnSetBindGroup(BindGroupIndex index, @@ -80,9 +78,9 @@ protected: virtual bool AreLayoutsCompatible() { return mLastAppliedPipelineLayout == mPipelineLayout; } - ityp::span<BindingIndex, DynamicOffset> GetDynamicOffsets(BindGroupIndex index) { - return ityp::span<BindingIndex, DynamicOffset>(mDynamicOffsets[index].offsets.data(), - mDynamicOffsets[index].count); + ityp::span<BindingIndex, uint32_t> GetDynamicOffsets(BindGroupIndex index) { + return ityp::span<BindingIndex, uint32_t>(mDynamicOffsets[index].offsets.data(), + mDynamicOffsets[index].count); } // The Derived class should call this before it applies bind groups. @@ -148,7 +146,7 @@ kMaxDynamicUniformBuffersPerPipelineLayout + kMaxDynamicStorageBuffersPerPipelineLayout; struct BindingDynamicOffsets { - ityp::array<BindingIndex, DynamicOffset, kMaxDynamicOffsetsPerBindGroup> offsets = {}; + ityp::array<BindingIndex, uint32_t, kMaxDynamicOffsetsPerBindGroup> offsets = {}; BindingIndex count = {}; };
diff --git a/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp b/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp index 406ec21..9a8dcbf 100644 --- a/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp +++ b/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp
@@ -114,7 +114,7 @@ BindGroupBase* group, BindingIndex bindingIndex, const BufferBindingInfo& layout, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets) { + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets) { const BindingInfo& bindingInfo = group->GetLayout()->GetBindingInfo(bindingIndex); BufferBinding binding = group->GetBindingAsBufferBinding(bindingIndex); @@ -336,7 +336,7 @@ BindGroupBase* group, BindingIndex bindingIndex, const BufferBindingInfo& layout, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets) { + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets) { const auto& [bindingInfo, binding] = ExtractBufferBindingInfo(group, bindingIndex, layout, dynamicOffsets); @@ -364,7 +364,7 @@ BindGroupBase* group, BindingIndex bindingIndex, const BufferBindingInfo& layout, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets) { + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets) { const auto& [bindingInfo, binding] = ExtractBufferBindingInfo(group, bindingIndex, layout, dynamicOffsets); @@ -462,7 +462,7 @@ constexpr wgpu::ShaderStage kVisibleCompute = wgpu::ShaderStage::Compute & kVisibleStage; BindGroupBase* group = mBindGroups[index]; - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets = GetDynamicOffsets(index); + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets = GetDynamicOffsets(index); const auto& indices = ToBackend(mPipelineLayout)->GetBindingTableIndexMap()[index]; for (BindingIndex bindingIndex : Range(group->GetLayout()->GetBindingCount())) { @@ -762,7 +762,7 @@ for (BindGroupIndex index : uavBindGroups) { BindGroupBase* group = mBindGroups[index]; - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets = GetDynamicOffsets(index); + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets = GetDynamicOffsets(index); const auto& indices = ToBackend(mPipelineLayout)->GetBindingTableIndexMap()[index]; // D3D11 uav slot allocated in reverse order.
diff --git a/src/dawn/native/d3d11/BindGroupTrackerD3D11.h b/src/dawn/native/d3d11/BindGroupTrackerD3D11.h index e5b2002..5b70716 100644 --- a/src/dawn/native/d3d11/BindGroupTrackerD3D11.h +++ b/src/dawn/native/d3d11/BindGroupTrackerD3D11.h
@@ -45,7 +45,7 @@ // - RTVs from the first register (r0) // - UAVs in bind groups // - Pixel Local Storage UAVs -class BindGroupTracker : public BindGroupTrackerBase</*CanInheritBindGroups=*/true, uint64_t> { +class BindGroupTracker : public BindGroupTrackerBase</*CanInheritBindGroups=*/true> { public: explicit BindGroupTracker(const ScopedSwapStateCommandRecordingContext* commandContext); virtual ~BindGroupTracker(); @@ -86,7 +86,7 @@ BindGroupBase* group, BindingIndex bindingIndex, const BufferBindingInfo& layout, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets); + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets); template <typename T> ResultOrError<ComPtr<T>> GetTextureD3DView(BindGroupBase* group, BindingIndex bindingIndex); @@ -104,7 +104,7 @@ BindGroupBase* group, BindingIndex bindingIndex, const BufferBindingInfo& layout, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets); + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets); ResultOrError<ComPtr<ID3D11ShaderResourceView>> GetTextureShaderResourceView( BindGroupBase* group,
diff --git a/src/dawn/native/d3d12/CommandBufferD3D12.cpp b/src/dawn/native/d3d12/CommandBufferD3D12.cpp index 87c35e5..cbe6bf3 100644 --- a/src/dawn/native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn/native/d3d12/CommandBufferD3D12.cpp
@@ -471,7 +471,7 @@ class DescriptorHeapState; template <typename PipelineType> -class BindGroupStateTracker : public BindGroupTrackerBase<false, uint64_t> { +class BindGroupStateTracker : public BindGroupTrackerBase<false> { using Base = BindGroupTrackerBase; public: @@ -672,7 +672,7 @@ const PipelineLayout* pipelineLayout, BindGroupIndex index, BindGroup* group, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets) { + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets) { DAWN_ASSERT(dynamicOffsets.size() == group->GetLayout()->GetDynamicBufferCount()); // Usually, the application won't set the same offsets many times,
diff --git a/src/dawn/native/metal/CommandBufferMTL.mm b/src/dawn/native/metal/CommandBufferMTL.mm index 4c0d3f3..8cd6c61 100644 --- a/src/dawn/native/metal/CommandBufferMTL.mm +++ b/src/dawn/native/metal/CommandBufferMTL.mm
@@ -655,7 +655,7 @@ // pipeline state. // Bind groups may be inherited because bind groups are packed in the buffer / // texture tables in contiguous order. -class BindGroupTracker : public BindGroupTrackerBase<true, uint64_t> { +class BindGroupTracker : public BindGroupTrackerBase<true> { public: BindGroupTracker(StorageBufferLengthTracker* lengthTracker, bool useArgumentBuffers) : BindGroupTrackerBase(), @@ -697,7 +697,7 @@ id<MTLComputeCommandEncoder> compute, BindGroupIndex index, BindGroup* group, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets, + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets, PipelineLayout* pipelineLayout, uint32_t argumentBufferIdx, std::optional<uint32_t> dynamicBufferIdx) { @@ -846,12 +846,6 @@ } if (mUseArgumentBuffers) { - ityp::vector<BindingIndex, uint32_t> dynamicOffsets32; - dynamicOffsets32.reserve(dynamicOffsets.size()); - for (uint64_t offset : dynamicOffsets) { - DAWN_ASSERT(offset <= std::numeric_limits<uint32_t>::max()); - dynamicOffsets32.push_back(uint32_t(offset)); - } const uint32_t dynamicOffsetsCount = uint32_t(dynamicOffsets.size()); if (render) { @@ -865,11 +859,11 @@ if (dynamicOffsetsCount > 0) { DAWN_ASSERT(dynamicBufferIdx.has_value()); - [render setVertexBytes:dynamicOffsets32.data() + [render setVertexBytes:dynamicOffsets.data() length:dynamicOffsetsCount * sizeof(uint32_t) atIndex:dynamicBufferIdx.value()]; - [render setFragmentBytes:dynamicOffsets32.data() + [render setFragmentBytes:dynamicOffsets.data() length:dynamicOffsetsCount * sizeof(uint32_t) atIndex:dynamicBufferIdx.value()]; } @@ -882,7 +876,7 @@ if (dynamicOffsetsCount > 0) { DAWN_ASSERT(dynamicBufferIdx.has_value()); - [compute setBytes:dynamicOffsets32.data() + [compute setBytes:dynamicOffsets.data() length:dynamicOffsetsCount * sizeof(uint32_t) atIndex:dynamicBufferIdx.value()]; }
diff --git a/src/dawn/native/opengl/CommandBufferGL.cpp b/src/dawn/native/opengl/CommandBufferGL.cpp index 4d2cd9c..0624509 100644 --- a/src/dawn/native/opengl/CommandBufferGL.cpp +++ b/src/dawn/native/opengl/CommandBufferGL.cpp
@@ -302,7 +302,7 @@ size_t end; }; -class BindGroupTracker : public BindGroupTrackerBase<false, uint64_t> { +class BindGroupTracker : public BindGroupTrackerBase<false> { public: void OnSetPipeline(RenderPipeline* pipeline) { BindGroupTrackerBase::OnSetPipeline(pipeline); @@ -343,7 +343,7 @@ MaybeError ApplyBindGroup(const OpenGLFunctions& gl, BindGroupIndex groupIndex, BindGroupBase* group, - const ityp::span<BindingIndex, uint64_t>& dynamicOffsets) { + const ityp::span<BindingIndex, uint32_t>& dynamicOffsets) { const auto& indices = ToBackend(mPipelineLayout)->GetBindingIndexInfo()[groupIndex]; for (BindingIndex bindingIndex : Range(group->GetLayout()->GetBindingCount())) { @@ -358,7 +358,7 @@ if (layout.hasDynamicOffset) { // Dynamic buffers are packed at the front of BindingIndices. - offset += dynamicOffsets[bindingIndex]; + offset += uint64_t(dynamicOffsets[bindingIndex]); } GLenum target;
diff --git a/src/dawn/native/vulkan/CommandBufferVk.cpp b/src/dawn/native/vulkan/CommandBufferVk.cpp index 0f47d2a..8a7fee5 100644 --- a/src/dawn/native/vulkan/CommandBufferVk.cpp +++ b/src/dawn/native/vulkan/CommandBufferVk.cpp
@@ -158,7 +158,7 @@ return region; } -class DescriptorSetTracker : public BindGroupTrackerBase<true, uint32_t> { +class DescriptorSetTracker : public BindGroupTrackerBase<true> { public: bool AreLayoutsCompatible() override { return mPipelineLayout == mLastAppliedPipelineLayout &&