From 3fee20dfecfc7fbcc3a013d1faf70e69f7324616 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 3 Aug 2018 11:10:40 +0200 Subject: [PATCH] [d3d11] Implement DiscardResource for buffers We don't suppor this for images, and we don't support DiscardView yet. Buffers can be invalidated, which may in some cases be beneficial in order to avoid synchronization on the GPU. --- src/d3d11/d3d11_context.cpp | 33 +++++++++++++++++++++++---------- src/d3d11/d3d11_context.h | 3 +++ src/d3d11/d3d11_device.cpp | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 8dc5fcc0c..6c70ef4e3 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -61,20 +61,24 @@ namespace dxvk { return E_NOINTERFACE; } - void STDMETHODCALLTYPE D3D11DeviceContext::DiscardResource(ID3D11Resource * pResource) { - static bool s_errorShown = false; - - if (!std::exchange(s_errorShown, true)) - Logger::err("D3D11DeviceContext::DiscardResource: Not implemented"); + + void STDMETHODCALLTYPE D3D11DeviceContext::DiscardResource(ID3D11Resource* pResource) { + D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN; + pResource->GetType(&resType); + + // We don't support the Discard API for images + if (resType == D3D11_RESOURCE_DIMENSION_BUFFER) + DiscardBuffer(reinterpret_cast(pResource)); } - void STDMETHODCALLTYPE D3D11DeviceContext::DiscardView(ID3D11View * pResourceView) { - static bool s_errorShown = false; - - if (!std::exchange(s_errorShown, true)) - Logger::err("D3D11DeviceContext::DiscardView: Not implemented"); + + 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. } + void STDMETHODCALLTYPE D3D11DeviceContext::DiscardView1( ID3D11View* pResourceView, const D3D11_RECT* pRects, @@ -2711,6 +2715,15 @@ namespace dxvk { } + void D3D11DeviceContext::DiscardBuffer( + D3D11Buffer* pBuffer) { + EmitCs([cBuffer = pBuffer->GetBuffer()] (DxvkContext* ctx) { + ctx->invalidateBuffer(cBuffer, + cBuffer->allocPhysicalSlice()); + }); + } + + void D3D11DeviceContext::SetConstantBuffers( DxbcProgramType ShaderStage, D3D11ConstantBufferBindings& Bindings, diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 2a920a840..844a1d7c9 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -703,6 +703,9 @@ namespace dxvk { UINT CtrSlot, D3D11UnorderedAccessView* pUav); + void DiscardBuffer( + D3D11Buffer* pBuffer); + void SetConstantBuffers( DxbcProgramType ShaderStage, D3D11ConstantBufferBindings& Bindings, diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 6541fa3de..91f0652cd 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -1603,7 +1603,7 @@ namespace dxvk { auto info = static_cast(pFeatureSupportData); info->OutputMergerLogicOp = features.core.features.logicOp; info->UAVOnlyRenderingForcedSampleCount = FALSE; - info->DiscardAPIsSeenByDriver = FALSE; + info->DiscardAPIsSeenByDriver = TRUE; info->FlagsForUpdateAndCopySeenByDriver = FALSE; info->ClearView = FALSE; info->CopyWithOverlap = FALSE;