From 0b4f1b6d6fddc006b8cfefa54dc948d79d998237 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 1 Oct 2018 16:53:32 +0200 Subject: [PATCH] [d3d11] Implement DiscardView and DiscardResource for images --- src/d3d11/d3d11_context.cpp | 36 +++++++++++++++++++++++++++++++++--- src/d3d11/d3d11_context.h | 4 ++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 4a602557..50b4615a 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -72,13 +72,31 @@ namespace dxvk { if (resType == D3D11_RESOURCE_DIMENSION_BUFFER) DiscardBuffer(static_cast(pResource)); + else if (resType != D3D11_RESOURCE_DIMENSION_UNKNOWN) + DiscardTexture(GetCommonTexture(pResource)); } void STDMETHODCALLTYPE D3D11DeviceContext::DiscardView(ID3D11View* pResourceView) { - // Ignore. We don't do Discard for images or image - // subresources, and for buffers we could only really - // do this if the view covers the entire buffer. + // ID3D11View has no methods to query the exact type of + // the view, so we'll have to check each possible class + auto dsv = dynamic_cast(pResourceView); + auto rtv = dynamic_cast(pResourceView); + auto uav = dynamic_cast(pResourceView); + + Rc view; + if (dsv) view = dsv->GetImageView(); + if (rtv) view = rtv->GetImageView(); + if (uav) view = uav->GetImageView(); + + if (view != nullptr) { + EmitCs([cView = std::move(view)] + (DxvkContext* ctx) { + ctx->discardImage( + cView->image(), + cView->subresources()); + }); + } } @@ -2907,6 +2925,18 @@ namespace dxvk { } + void D3D11DeviceContext::DiscardTexture( + D3D11CommonTexture* pTexture) { + EmitCs([cImage = pTexture->GetImage()] (DxvkContext* ctx) { + VkImageSubresourceRange subresources = { + cImage->formatInfo()->aspectMask, + 0, cImage->info().mipLevels, + 0, cImage->info().numLayers }; + ctx->discardImage(cImage, subresources); + }); + } + + void D3D11DeviceContext::SetConstantBuffers( DxbcProgramType ShaderStage, D3D11ConstantBufferBindings& Bindings, diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 4eca33ee..2d2f11a5 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -7,6 +7,7 @@ #include "d3d11_annotation.h" #include "d3d11_context_state.h" #include "d3d11_device_child.h" +#include "d3d11_texture.h" namespace dxvk { @@ -707,6 +708,9 @@ namespace dxvk { void DiscardBuffer( D3D11Buffer* pBuffer); + void DiscardTexture( + D3D11CommonTexture* pTexture); + void SetConstantBuffers( DxbcProgramType ShaderStage, D3D11ConstantBufferBindings& Bindings,