From e882a7f8ba70006a83b708edce95d684528ceb03 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 31 Aug 2022 15:15:57 +0200 Subject: [PATCH] [d3d11] Implement extended shader interface --- src/d3d11/d3d11_shader.cpp | 56 ++++++++++++++++++++++++++++++++++++++ src/d3d11/d3d11_shader.h | 47 +++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 4 deletions(-) diff --git a/src/d3d11/d3d11_shader.cpp b/src/d3d11/d3d11_shader.cpp index 085ad13f2..c153c8397 100644 --- a/src/d3d11/d3d11_shader.cpp +++ b/src/d3d11/d3d11_shader.cpp @@ -125,4 +125,60 @@ namespace dxvk { return S_OK; } + + D3D11ExtShader::D3D11ExtShader( + ID3D11DeviceChild* pParent, + D3D11CommonShader* pShader) + : m_parent(pParent), m_shader(pShader) { + + } + + + D3D11ExtShader::~D3D11ExtShader() { + + } + + + ULONG STDMETHODCALLTYPE D3D11ExtShader::AddRef() { + return m_parent->AddRef(); + } + + + ULONG STDMETHODCALLTYPE D3D11ExtShader::Release() { + return m_parent->Release(); + } + + + HRESULT STDMETHODCALLTYPE D3D11ExtShader::QueryInterface( + REFIID riid, + void** ppvObject) { + return m_parent->QueryInterface(riid, ppvObject); + } + + + HRESULT STDMETHODCALLTYPE D3D11ExtShader::GetSpirvCode( + SIZE_T* pCodeSize, + void* pCode) { + auto shader = m_shader->GetShader(); + auto code = shader->getRawCode(); + + HRESULT hr = S_OK; + + if (pCode) { + size_t size = code.size(); + + if (size > *pCodeSize) { + size = *pCodeSize; + hr = S_FALSE; + } + + std::memcpy(pCode, code.data(), size); + *pCodeSize = size; + return hr; + } else { + *pCodeSize = code.size(); + return hr; + } + } + } diff --git a/src/d3d11/d3d11_shader.h b/src/d3d11/d3d11_shader.h index 4ef2e4b90..fe499bc14 100644 --- a/src/d3d11/d3d11_shader.h +++ b/src/d3d11/d3d11_shader.h @@ -59,8 +59,41 @@ namespace dxvk { Rc m_buffer; }; - - + + + /** + * \brief Extended shader interface + */ + class D3D11ExtShader : public ID3D11VkExtShader { + + public: + + D3D11ExtShader( + ID3D11DeviceChild* pParent, + D3D11CommonShader* pShader); + + ~D3D11ExtShader(); + + ULONG STDMETHODCALLTYPE AddRef(); + + ULONG STDMETHODCALLTYPE Release(); + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void** ppvObject); + + HRESULT STDMETHODCALLTYPE GetSpirvCode( + SIZE_T* pCodeSize, + void* pCode); + + private: + + ID3D11DeviceChild* m_parent; + D3D11CommonShader* m_shader; + + }; + + /** * \brief Common shader interface * @@ -75,7 +108,7 @@ namespace dxvk { D3D11Shader(D3D11Device* device, const D3D11CommonShader& shader) : D3D11DeviceChild(device), - m_shader(shader), m_d3d10(this) { } + m_shader(shader), m_d3d10(this), m_shaderExt(this, &m_shader) { } ~D3D11Shader() { } @@ -95,7 +128,12 @@ namespace dxvk { *ppvObject = ref(&m_d3d10); return S_OK; } - + + if (riid == __uuidof(ID3D11VkExtShader)) { + *ppvObject = ref(&m_shaderExt); + return S_OK; + } + Logger::warn("D3D11Shader::QueryInterface: Unknown interface query"); return E_NOINTERFACE; } @@ -112,6 +150,7 @@ namespace dxvk { D3D11CommonShader m_shader; D3D10ShaderClass m_d3d10; + D3D11ExtShader m_shaderExt; };