From 91fd9d97a29963f5765820913344a6bcd8156acd Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Thu, 11 May 2023 00:19:49 +0000 Subject: [PATCH] d3d11: fix and enable some BufferZeroInitTests & Compute tests Bug: dawn:1755 Bug: dawn:1798 Bug: dawn:1721 Change-Id: I7e5d4964bd248b4429cb393168b0e7dbe119c08c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132001 Reviewed-by: Austin Eng Kokoro: Kokoro Commit-Queue: Peng Huang --- .../native/d3d11/BindGroupTrackerD3D11.cpp | 27 ++++++++++++++++--- src/dawn/native/d3d11/PipelineLayoutD3D11.cpp | 3 +-- src/dawn/native/d3d11/TextureD3D11.cpp | 3 +++ .../tests/end2end/BufferZeroInitTests.cpp | 9 ------- .../ComputeLayoutMemoryBufferTests.cpp | 8 ------ .../ComputeStorageBufferBarrierTests.cpp | 10 ++----- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp b/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp index 8fd2d60b95..a33897ced5 100644 --- a/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp +++ b/src/dawn/native/d3d11/BindGroupTrackerD3D11.cpp @@ -246,7 +246,20 @@ MaybeError BindGroupTracker::ApplyBindGroup(BindGroupIndex index) { } case BindingInfoType::StorageTexture: { - return DAWN_UNIMPLEMENTED_ERROR("Storage textures are not supported"); + ASSERT(bindingInfo.storageTexture.access == wgpu::StorageTextureAccess::WriteOnly); + ComPtr d3d11UAV; + TextureView* view = ToBackend(group->GetBindingAsTextureView(bindingIndex)); + DAWN_TRY_ASSIGN(d3d11UAV, view->CreateD3D11UnorderedAccessView()); + if (bindingInfo.visibility & wgpu::ShaderStage::Fragment) { + deviceContext1->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, bindingSlot, + 1, d3d11UAV.GetAddressOf(), nullptr); + } + if (bindingInfo.visibility & wgpu::ShaderStage::Compute) { + deviceContext1->CSSetUnorderedAccessViews(bindingSlot, 1, + d3d11UAV.GetAddressOf(), nullptr); + } + break; } case BindingInfoType::ExternalTexture: { @@ -350,8 +363,16 @@ void BindGroupTracker::UnApplyBindGroup(BindGroupIndex index) { } case BindingInfoType::StorageTexture: { - // TODO(dawn:1798): Support storage textures. - UNREACHABLE(); + ASSERT(bindingInfo.storageTexture.access == wgpu::StorageTextureAccess::WriteOnly); + ID3D11UnorderedAccessView* nullUAV = nullptr; + if (bindingInfo.visibility & wgpu::ShaderStage::Fragment) { + deviceContext1->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL, nullptr, nullptr, bindingSlot, + 1, &nullUAV, nullptr); + } + if (bindingInfo.visibility & wgpu::ShaderStage::Compute) { + deviceContext1->CSSetUnorderedAccessViews(bindingSlot, 1, &nullUAV, nullptr); + } break; } diff --git a/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp b/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp index 268a2f0ee9..7b9b7906f2 100644 --- a/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp +++ b/src/dawn/native/d3d11/PipelineLayoutD3D11.cpp @@ -34,7 +34,6 @@ MaybeError PipelineLayout::Initialize() { unsigned int samplerIndex = 0; unsigned int shaderResourceViewIndex = 0; unsigned int unorderedAccessViewIndex = 0; - unsigned int storageTextureIndex = 0; for (BindGroupIndex group : IterateBitSet(GetBindGroupLayoutsMask())) { const BindGroupLayoutBase* bgl = GetBindGroupLayout(group); @@ -70,7 +69,7 @@ MaybeError PipelineLayout::Initialize() { break; case BindingInfoType::StorageTexture: - mIndexInfo[group][bindingIndex] = storageTextureIndex++; + mIndexInfo[group][bindingIndex] = unorderedAccessViewIndex++; break; } } diff --git a/src/dawn/native/d3d11/TextureD3D11.cpp b/src/dawn/native/d3d11/TextureD3D11.cpp index ff76f6f710..8d7daa1648 100644 --- a/src/dawn/native/d3d11/TextureD3D11.cpp +++ b/src/dawn/native/d3d11/TextureD3D11.cpp @@ -877,6 +877,9 @@ ResultOrError> TextureView::CreateD3D11Unorder uavDesc.Texture1D.MipSlice = GetBaseMipLevel(); break; case wgpu::TextureViewDimension::e2D: + uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; + uavDesc.Texture2D.MipSlice = GetBaseMipLevel(); + break; case wgpu::TextureViewDimension::e2DArray: uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY; uavDesc.Texture2DArray.FirstArraySlice = GetBaseArrayLayer(); diff --git a/src/dawn/tests/end2end/BufferZeroInitTests.cpp b/src/dawn/tests/end2end/BufferZeroInitTests.cpp index 05982faf18..ee5997a3c1 100644 --- a/src/dawn/tests/end2end/BufferZeroInitTests.cpp +++ b/src/dawn/tests/end2end/BufferZeroInitTests.cpp @@ -169,9 +169,6 @@ class BufferZeroInitTest : public DawnTest { uint64_t bufferOffset, uint64_t boundBufferSize, const std::vector& expectedBufferData) { - // TODO(dawn:1755): Buffer usage can't be both uniform and other accelerated usages with - // D3D11. - DAWN_SUPPRESS_TEST_IF(IsD3D11()); wgpu::ComputePipelineDescriptor pipelineDescriptor; pipelineDescriptor.layout = nullptr; pipelineDescriptor.compute.module = module; @@ -427,9 +424,6 @@ class BufferZeroInitTest : public DawnTest { } void TestBufferZeroInitAsIndirectBufferForDispatchIndirect(uint64_t indirectBufferOffset) { - // TODO(dawn:1798): Support storage textures. - DAWN_SUPPRESS_TEST_IF(IsD3D11()); - constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; constexpr wgpu::Color kClearColorGreen = {0.f, 1.f, 0.f, 1.f}; @@ -1145,9 +1139,6 @@ TEST_P(BufferZeroInitTest, PaddingInitialized) { DAWN_SUPPRESS_TEST_IF(IsANGLE()); // TODO(crbug.com/dawn/1084) DAWN_SUPPRESS_TEST_IF(IsLinux() && IsVulkan() && IsNvidia()); // TODO(crbug.com/dawn/1214) - // TODO(dawn:1755): Buffer usage can't be both uniform and other accelerated usages with D3D11. - DAWN_SUPPRESS_TEST_IF(IsD3D11()); - constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm; // A small sub-4-byte format means a single vertex can fit entirely within the padded buffer, // touching some of the padding. Test a small format, as well as larger formats. diff --git a/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp b/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp index 815e2076ef..ae15fee9f9 100644 --- a/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp +++ b/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp @@ -530,10 +530,6 @@ TEST_P(ComputeLayoutMemoryBufferTests, StructMember) { const bool isUniform = GetParam().mAddressSpace == AddressSpace::Uniform; - // D3D11 doesn't support storage buffer with uniform address space - // TODO(dawn:1792): figure how to support it on D3D11 - DAWN_SUPPRESS_TEST_IF(IsD3D11() && isUniform); - // Sentinel value markers codes used to check that the start and end of // structures are correctly aligned. Each of these codes are distinct and // are not likely to be confused with data. @@ -705,10 +701,6 @@ TEST_P(ComputeLayoutMemoryBufferTests, NonStructMember) { const bool isUniform = GetParam().mAddressSpace == AddressSpace::Uniform; - // D3D11 doesn't support storage buffer with uniform address space - // TODO(dawn:1792): figure how to support it on D3D11 - DAWN_SUPPRESS_TEST_IF(IsD3D11() && isUniform); - auto params = GetParam(); Field& field = params.mField; diff --git a/src/dawn/tests/end2end/ComputeStorageBufferBarrierTests.cpp b/src/dawn/tests/end2end/ComputeStorageBufferBarrierTests.cpp index c9634a371f..e2319d7a90 100644 --- a/src/dawn/tests/end2end/ComputeStorageBufferBarrierTests.cpp +++ b/src/dawn/tests/end2end/ComputeStorageBufferBarrierTests.cpp @@ -202,9 +202,6 @@ TEST_P(ComputeStorageBufferBarrierTests, StorageAndReadonlyStoragePingPongInOneP // Test that Storage to Uniform buffer transitions work and synchronize correctly // by ping-ponging between Storage/Uniform usage in sequential compute passes. TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) { - // TODO(dawn:1721): D3D11 buffer cannot be uniform and storage at the same time. - DAWN_SUPPRESS_TEST_IF(IsD3D11()); - std::vector data(kNumValues, 0); std::vector expectedA(kNumValues, 0x1234 * kIterations); std::vector expectedB(kNumValues, 0x1234 * (kIterations - 1)); @@ -273,9 +270,6 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPong) { // Test that Storage to Uniform buffer transitions work and synchronize correctly // by ping-ponging between Storage/Uniform usage in one compute pass. TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPongInOnePass) { - // TODO(dawn:1721): D3D11 buffer cannot be uniform and storage at the same time. - DAWN_SUPPRESS_TEST_IF(IsD3D11()); - std::vector data(kNumValues, 0); std::vector expectedA(kNumValues, 0x1234 * kIterations); std::vector expectedB(kNumValues, 0x1234 * (kIterations - 1)); @@ -326,9 +320,9 @@ TEST_P(ComputeStorageBufferBarrierTests, UniformToStorageAddPingPongInOnePass) { wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); wgpu::ComputePassEncoder pass = encoder.BeginComputePass(); - for (uint32_t i = 0, b = 0; i < kIterations; ++i, b = 1 - b) { + for (uint32_t i = 0; i < kIterations; ++i) { pass.SetPipeline(pipeline); - pass.SetBindGroup(0, bindGroups[b]); + pass.SetBindGroup(0, bindGroups[i % 2]); pass.DispatchWorkgroups(kNumValues / 4); } pass.End();