From b6e73aa50a27c78fb285f044b852bc8a03e0bf5b Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Wed, 10 May 2023 01:44:26 +0000 Subject: [PATCH] d3d11: support multisampled rendering and enable related tests Bug: dawn:1804 Bug: dawn:1705 Change-Id: Ic90a42dab7149af261af790ca393d8a595e3ec4c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132021 Kokoro: Kokoro Commit-Queue: Peng Huang Reviewed-by: Austin Eng --- src/dawn/native/d3d11/CommandBufferD3D11.cpp | 37 ++++++++++++++++++- .../end2end/CreatePipelineAsyncTests.cpp | 1 + .../end2end/MultisampledRenderingTests.cpp | 2 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/dawn/native/d3d11/CommandBufferD3D11.cpp b/src/dawn/native/d3d11/CommandBufferD3D11.cpp index 4db4f9bc7c..48aee390cf 100644 --- a/src/dawn/native/d3d11/CommandBufferD3D11.cpp +++ b/src/dawn/native/d3d11/CommandBufferD3D11.cpp @@ -627,7 +627,42 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass, switch (type) { case Command::EndRenderPass: { mCommands.NextCommand(); - // TODO(dawn:1705): resolve MSAA + ID3D11DeviceContext* d3d11DeviceContext = commandContext->GetD3D11DeviceContext(); + d3d11DeviceContext->OMSetRenderTargets(0, nullptr, nullptr); + + if (renderPass->attachmentState->GetSampleCount() <= 1) { + return {}; + } + + // Resolve multisampled textures. + for (ColorAttachmentIndex i : + IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) { + const auto& attachment = renderPass->colorAttachments[i]; + if (!attachment.resolveTarget.Get()) { + continue; + } + + if (attachment.storeOp != wgpu::StoreOp::Store) { + continue; + } + + ASSERT(attachment.view->GetAspects() == Aspect::Color); + ASSERT(attachment.resolveTarget->GetAspects() == Aspect::Color); + + Texture* resolveTexture = ToBackend(attachment.resolveTarget->GetTexture()); + Texture* colorTexture = ToBackend(attachment.view->GetTexture()); + uint32_t dstSubresource = resolveTexture->GetSubresourceIndex( + attachment.resolveTarget->GetBaseMipLevel(), + attachment.resolveTarget->GetBaseArrayLayer(), Aspect::Color); + uint32_t srcSubresource = colorTexture->GetSubresourceIndex( + attachment.view->GetBaseMipLevel(), attachment.view->GetBaseArrayLayer(), + Aspect::Color); + d3d11DeviceContext->ResolveSubresource( + resolveTexture->GetD3D11Resource(), dstSubresource, + colorTexture->GetD3D11Resource(), srcSubresource, + resolveTexture->GetD3D11Format()); + } + return {}; } diff --git a/src/dawn/tests/end2end/CreatePipelineAsyncTests.cpp b/src/dawn/tests/end2end/CreatePipelineAsyncTests.cpp index 627d3b28d4..5d945be8a2 100644 --- a/src/dawn/tests/end2end/CreatePipelineAsyncTests.cpp +++ b/src/dawn/tests/end2end/CreatePipelineAsyncTests.cpp @@ -955,6 +955,7 @@ TEST_P(CreatePipelineAsyncTest, CreateRenderPipelineAsyncWithBlendState) { } DAWN_INSTANTIATE_TEST(CreatePipelineAsyncTest, + D3D11Backend(), D3D12Backend(), MetalBackend(), OpenGLBackend(), diff --git a/src/dawn/tests/end2end/MultisampledRenderingTests.cpp b/src/dawn/tests/end2end/MultisampledRenderingTests.cpp index 50a50f1abb..72d95c3f99 100644 --- a/src/dawn/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/dawn/tests/end2end/MultisampledRenderingTests.cpp @@ -1189,6 +1189,7 @@ TEST_P(MultisampledRenderingWithTransientAttachmentTest, ResolveTransientAttachm } DAWN_INSTANTIATE_TEST(MultisampledRenderingTest, + D3D11Backend(), D3D12Backend(), D3D12Backend({}, {"use_d3d12_resource_heap_tier2"}), D3D12Backend({}, {"use_d3d12_render_pass"}), @@ -1203,6 +1204,7 @@ DAWN_INSTANTIATE_TEST(MultisampledRenderingTest, "emulate_store_and_msaa_resolve"})); DAWN_INSTANTIATE_TEST(MultisampledRenderingWithTransientAttachmentTest, + D3D11Backend(), D3D12Backend(), D3D12Backend({}, {"use_d3d12_resource_heap_tier2"}), D3D12Backend({}, {"use_d3d12_render_pass"}),