From 7907100b9cffe326dce458d7c5febdd47fc0926e Mon Sep 17 00:00:00 2001 From: flyinghead Date: Wed, 25 Sep 2024 21:57:15 +0200 Subject: [PATCH] dx11: wrong texture returned to libretro in some cases If a render to texture happens before presenting the current frame, another texture will be bound to shader slot #0 and will be returned to the libretro frontend. Issue #1616 and #1619 --- core/rend/dx11/dx11_renderer.h | 2 ++ core/rend/dx11/dx11context_lr.cpp | 8 +++++++- core/rend/dx11/dx11context_lr.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/rend/dx11/dx11_renderer.h b/core/rend/dx11/dx11_renderer.h index 6304cb652..a206ca409 100644 --- a/core/rend/dx11/dx11_renderer.h +++ b/core/rend/dx11/dx11_renderer.h @@ -46,6 +46,8 @@ struct DX11Renderer : public Renderer frameRendered = false; #ifndef LIBRETRO imguiDriver->setFrameRendered(); +#else + theDX11Context.present(); #endif return true; } diff --git a/core/rend/dx11/dx11context_lr.cpp b/core/rend/dx11/dx11context_lr.cpp index feedec653..f2358b2fd 100644 --- a/core/rend/dx11/dx11context_lr.cpp +++ b/core/rend/dx11/dx11context_lr.cpp @@ -132,6 +132,8 @@ ComPtr& DX11Context::getRenderTarget(int width, int heig void DX11Context::presentFrame(ComPtr& textureView, int width, int height) { + ID3D11ShaderResourceView *nullSRView = nullptr; + pDeviceContext->PSSetShaderResources(0, 1, &nullSRView); ComPtr renderTarget = getRenderTarget(width, height); pDeviceContext->OMSetRenderTargets(1, &renderTarget.get(), nullptr); @@ -160,7 +162,11 @@ void DX11Context::presentFrame(ComPtr& textureView, in ID3D11RenderTargetView *nullView = nullptr; pDeviceContext->OMSetRenderTargets(1, &nullView, nullptr); - pDeviceContext->PSSetShaderResources(0, 1, &this->textureView.get()); +} + +void DX11Context::present() +{ + pDeviceContext->PSSetShaderResources(0, 1, &textureView.get()); } #endif diff --git a/core/rend/dx11/dx11context_lr.h b/core/rend/dx11/dx11context_lr.h index 3a043a019..72d9e8156 100644 --- a/core/rend/dx11/dx11context_lr.h +++ b/core/rend/dx11/dx11context_lr.h @@ -35,6 +35,7 @@ class DX11Context : public GraphicsContext public: bool init(ID3D11Device *device, ID3D11DeviceContext *deviceContext, pD3DCompile D3DCompile, D3D_FEATURE_LEVEL featureLevel); void term() override; + void present(); const ComPtr& getDevice() const { return pDevice; } const ComPtr& getDeviceContext() const { return pDeviceContext; } @@ -88,6 +89,7 @@ private: int renderTargetHeight = 0; BlendStates blendStates; std::unique_ptr quad; + ComPtr rasterizerState; D3D_FEATURE_LEVEL featureLevel{}; bool supportedTexFormats[5] {}; // indexed by TextureType enum