From c0c2bfb2939077732c3198df0fd5023fc9f87ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 1 Dec 2020 09:20:13 +0100 Subject: [PATCH] D3D11: Fix shader module leak in thin3d. Thanks Unknown. --- Common/GPU/D3D11/thin3d_d3d11.cpp | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index 608baeb38b..e961bebf57 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -664,7 +664,28 @@ InputLayout *D3D11DrawContext::CreateInputLayout(const InputLayoutDesc &desc) { return inputLayout; } -class D3D11ShaderModule; +class D3D11ShaderModule : public ShaderModule { +public: + D3D11ShaderModule(const std::string &tag) : tag_(tag) { + } + ~D3D11ShaderModule() { + if (vs) + vs->Release(); + if (ps) + ps->Release(); + if (gs) + gs->Release(); + } + ShaderStage GetStage() const override { return stage; } + + std::vector byteCode_; + ShaderStage stage; + std::string tag_; + + ID3D11VertexShader *vs = nullptr; + ID3D11PixelShader *ps = nullptr; + ID3D11GeometryShader *gs = nullptr; +}; class D3D11Pipeline : public Pipeline { public: @@ -681,6 +702,9 @@ public: il->Release(); if (dynamicUniforms) dynamicUniforms->Release(); + for (D3D11ShaderModule *shaderModule : shaderModules) { + shaderModule->Release(); + } } bool RequiresBuffer() override { return true; @@ -856,29 +880,6 @@ Texture *D3D11DrawContext::CreateTexture(const TextureDesc &desc) { return tex; } -class D3D11ShaderModule : public ShaderModule { -public: - D3D11ShaderModule(const std::string &tag) : tag_(tag) { - } - ~D3D11ShaderModule() { - if (vs) - vs->Release(); - if (ps) - ps->Release(); - if (gs) - gs->Release(); - } - ShaderStage GetStage() const override { return stage; } - - std::vector byteCode_; - ShaderStage stage; - std::string tag_; - - ID3D11VertexShader *vs = nullptr; - ID3D11PixelShader *ps = nullptr; - ID3D11GeometryShader *gs = nullptr; -}; - ShaderModule *D3D11DrawContext::CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t dataSize, const std::string &tag) { if (language != ShaderLanguage::HLSL_D3D11) { ERROR_LOG(G3D, "Unsupported shader language");