From fe58d808717267975575104d329038793c384da9 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Thu, 18 May 2023 14:26:24 +0000 Subject: [PATCH] d3d11: fix and enable ReadOnlyDepthStencilAttachmentTests Bug: dawn:1705 Bug: dawn:1727 Change-Id: I28f20d2be10753f6a7e7bd727fa80d050cfb8694 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133360 Kokoro: Kokoro Auto-Submit: Peng Huang Reviewed-by: Austin Eng Reviewed-by: Corentin Wallez Commit-Queue: Austin Eng --- src/dawn/native/d3d11/CommandBufferD3D11.cpp | 5 +++-- src/dawn/native/d3d11/TextureD3D11.cpp | 20 ++++++++----------- src/dawn/native/d3d11/TextureD3D11.h | 2 -- .../ReadOnlyDepthStencilAttachmentTests.cpp | 13 ++++++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/dawn/native/d3d11/CommandBufferD3D11.cpp b/src/dawn/native/d3d11/CommandBufferD3D11.cpp index d5a3d09d06..82e87cf22f 100644 --- a/src/dawn/native/d3d11/CommandBufferD3D11.cpp +++ b/src/dawn/native/d3d11/CommandBufferD3D11.cpp @@ -440,7 +440,8 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass, TextureView* depthStencilTextureView = ToBackend(renderPass->depthStencilAttachment.view.Get()); DAWN_TRY_ASSIGN(d3d11DepthStencilView, - depthStencilTextureView->CreateD3D11DepthStencilView(false, false)); + depthStencilTextureView->CreateD3D11DepthStencilView( + attachmentInfo->depthReadOnly, attachmentInfo->stencilReadOnly)); UINT clearFlags = 0; if (attachmentFormat.HasDepth() && renderPass->depthStencilAttachment.depthLoadOp == wgpu::LoadOp::Clear) { @@ -658,7 +659,7 @@ MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass, d3d11DeviceContext->ResolveSubresource( resolveTexture->GetD3D11Resource(), dstSubresource, colorTexture->GetD3D11Resource(), srcSubresource, - resolveTexture->GetD3D11Format()); + d3d::DXGITextureFormat(attachment.resolveTarget->GetFormat().format)); } return {}; diff --git a/src/dawn/native/d3d11/TextureD3D11.cpp b/src/dawn/native/d3d11/TextureD3D11.cpp index 8d7daa1648..86942da360 100644 --- a/src/dawn/native/d3d11/TextureD3D11.cpp +++ b/src/dawn/native/d3d11/TextureD3D11.cpp @@ -183,7 +183,11 @@ T Texture::GetD3D11TextureDesc() const { } desc.MipLevels = static_cast(GetNumMipLevels()); - desc.Format = GetD3D11Format(); + // To sample from a depth or stencil texture, we need to create a typeless texture. + bool needsTypelessFormat = + GetFormat().HasDepthOrStencil() && (GetUsage() & wgpu::TextureUsage::TextureBinding); + desc.Format = needsTypelessFormat ? d3d::DXGITypelessTextureFormat(GetFormat().format) + : d3d::DXGITextureFormat(GetFormat().format); desc.Usage = mIsStaging ? D3D11_USAGE_STAGING : D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11TextureBindFlags(GetInternalUsage(), GetFormat()); constexpr UINT kCPUReadWriteFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; @@ -281,10 +285,6 @@ void Texture::DestroyImpl() { mD3d11Resource = nullptr; } -DXGI_FORMAT Texture::GetD3D11Format() const { - return d3d::DXGITextureFormat(GetFormat().format); -} - ID3D11Resource* Texture::GetD3D11Resource() const { return mD3d11Resource.Get(); } @@ -333,7 +333,7 @@ D3D11_DEPTH_STENCIL_VIEW_DESC Texture::GetDSVDescriptor(const SubresourceRange& bool stencilReadOnly) const { D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = GetD3D11Format(); + dsvDesc.Format = d3d::DXGITextureFormat(GetFormat().format); dsvDesc.Flags = 0; if (depthReadOnly && range.aspects & Aspect::Depth) { dsvDesc.Flags |= D3D11_DSV_READ_ONLY_DEPTH; @@ -699,14 +699,10 @@ Ref TextureView::Create(TextureBase* texture, TextureView::~TextureView() = default; -DXGI_FORMAT TextureView::GetD3D11Format() const { - return d3d::DXGITextureFormat(GetFormat().format); -} - ResultOrError> TextureView::CreateD3D11ShaderResourceView() const { Device* device = ToBackend(GetDevice()); D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - srvDesc.Format = GetD3D11Format(); + srvDesc.Format = d3d::DXGITextureFormat(GetFormat().format); const Format& textureFormat = GetTexture()->GetFormat(); // TODO(dawn:1705): share below code with D3D12? @@ -868,7 +864,7 @@ ResultOrError> TextureView::CreateD3D11DepthStenc ResultOrError> TextureView::CreateD3D11UnorderedAccessView() const { D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc; - uavDesc.Format = GetD3D11Format(); + uavDesc.Format = d3d::DXGITextureFormat(GetFormat().format); ASSERT(!GetTexture()->IsMultisampledTexture()); switch (GetDimension()) { diff --git a/src/dawn/native/d3d11/TextureD3D11.h b/src/dawn/native/d3d11/TextureD3D11.h index ecf08c44d1..b78084baae 100644 --- a/src/dawn/native/d3d11/TextureD3D11.h +++ b/src/dawn/native/d3d11/TextureD3D11.h @@ -53,7 +53,6 @@ class Texture final : public d3d::Texture { std::vector> waitFences, bool isSwapChainTexture, bool isInitialized); - DXGI_FORMAT GetD3D11Format() const; ID3D11Resource* GetD3D11Resource() const; D3D11_RENDER_TARGET_VIEW_DESC GetRTVDescriptor(const Format& format, @@ -128,7 +127,6 @@ class TextureView final : public TextureViewBase { public: static Ref Create(TextureBase* texture, const TextureViewDescriptor* descriptor); - DXGI_FORMAT GetD3D11Format() const; ResultOrError> CreateD3D11ShaderResourceView() const; ResultOrError> CreateD3D11RenderTargetView() const; ResultOrError> CreateD3D11DepthStencilView( diff --git a/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp b/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp index df747233fd..53410ae27b 100644 --- a/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp +++ b/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp @@ -297,6 +297,9 @@ class ReadOnlyStencilAttachmentTests : public ReadOnlyDepthStencilAttachmentTest }; TEST_P(ReadOnlyStencilAttachmentTests, SampleFromAttachment) { + // TODO(dawn:1827): sampling from stencil attachment fails on D3D11. + DAWN_SUPPRESS_TEST_IF(IsD3D11()); + wgpu::Texture colorTexture = CreateTexture(wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::CopySrc); @@ -345,13 +348,15 @@ TEST_P(ReadOnlyStencilAttachmentTests, NotSampleFromAttachment) { } DAWN_INSTANTIATE_TEST_P(ReadOnlyDepthAttachmentTests, - {D3D12Backend(), D3D12Backend({}, {"use_d3d12_render_pass"}), - MetalBackend(), VulkanBackend()}, + {D3D11Backend(), D3D12Backend(), + D3D12Backend({}, {"use_d3d12_render_pass"}), MetalBackend(), + VulkanBackend()}, std::vector(utils::kDepthFormats.begin(), utils::kDepthFormats.end())); DAWN_INSTANTIATE_TEST_P(ReadOnlyStencilAttachmentTests, - {D3D12Backend(), D3D12Backend({}, {"use_d3d12_render_pass"}), - MetalBackend(), VulkanBackend()}, + {D3D11Backend(), D3D12Backend(), + D3D12Backend({}, {"use_d3d12_render_pass"}), MetalBackend(), + VulkanBackend()}, std::vector(utils::kStencilFormats.begin(), utils::kStencilFormats.end()));