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 <noreply+kokoro@google.com>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Peng Huang 2023-05-18 14:26:24 +00:00 committed by Dawn LUCI CQ
parent 92151b238b
commit fe58d80871
4 changed files with 20 additions and 20 deletions

View File

@ -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 {};

View File

@ -183,7 +183,11 @@ T Texture::GetD3D11TextureDesc() const {
}
desc.MipLevels = static_cast<UINT16>(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> TextureView::Create(TextureBase* texture,
TextureView::~TextureView() = default;
DXGI_FORMAT TextureView::GetD3D11Format() const {
return d3d::DXGITextureFormat(GetFormat().format);
}
ResultOrError<ComPtr<ID3D11ShaderResourceView>> 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<ComPtr<ID3D11DepthStencilView>> TextureView::CreateD3D11DepthStenc
ResultOrError<ComPtr<ID3D11UnorderedAccessView>> TextureView::CreateD3D11UnorderedAccessView()
const {
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
uavDesc.Format = GetD3D11Format();
uavDesc.Format = d3d::DXGITextureFormat(GetFormat().format);
ASSERT(!GetTexture()->IsMultisampledTexture());
switch (GetDimension()) {

View File

@ -53,7 +53,6 @@ class Texture final : public d3d::Texture {
std::vector<Ref<d3d::Fence>> 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<TextureView> Create(TextureBase* texture, const TextureViewDescriptor* descriptor);
DXGI_FORMAT GetD3D11Format() const;
ResultOrError<ComPtr<ID3D11ShaderResourceView>> CreateD3D11ShaderResourceView() const;
ResultOrError<ComPtr<ID3D11RenderTargetView>> CreateD3D11RenderTargetView() const;
ResultOrError<ComPtr<ID3D11DepthStencilView>> CreateD3D11DepthStencilView(

View File

@ -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<wgpu::TextureFormat>(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<wgpu::TextureFormat>(utils::kStencilFormats.begin(),
utils::kStencilFormats.end()));