diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index ebbd089bb..74cd3d576 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -63,7 +63,7 @@ namespace dxvk { // this->IASetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, nullptr, nullptr, nullptr); // this->IASetIndexBuffer(nullptr, DXGI_FORMAT_UNKNOWN, 0); -// this->VSSetShader(nullptr, nullptr, 0); + this->VSSetShader(nullptr, nullptr, 0); // this->VSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, nullptr); // this->VSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr); // this->VSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr); @@ -83,7 +83,7 @@ namespace dxvk { // this->GSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr); // this->GSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr); -// this->PSSetShader(nullptr, nullptr, 0); + this->PSSetShader(nullptr, nullptr, 0); // this->PSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, nullptr); // this->PSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, nullptr); // this->PSSetSamplers (0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, nullptr); @@ -553,7 +553,17 @@ namespace dxvk { ID3D11VertexShader* pVertexShader, ID3D11ClassInstance* const* ppClassInstances, UINT NumClassInstances) { - Logger::err("D3D11DeviceContext::VSSetShader: Not implemented"); + auto shader = static_cast(pVertexShader); + + if (NumClassInstances != 0) + Logger::err("D3D11DeviceContext::VSSetShader: Class instances not supported"); + + if (m_state.vs.shader != shader) { + m_state.vs.shader = shader; + + m_context->bindShader(VK_SHADER_STAGE_VERTEX_BIT, + shader != nullptr ? shader->GetShader() : nullptr); + } } @@ -809,7 +819,17 @@ namespace dxvk { ID3D11PixelShader* pPixelShader, ID3D11ClassInstance* const* ppClassInstances, UINT NumClassInstances) { - Logger::err("D3D11DeviceContext::PSSetShader: Not implemented"); + auto shader = static_cast(pPixelShader); + + if (NumClassInstances != 0) + Logger::err("D3D11DeviceContext::VSSetShader: Class instances not supported"); + + if (m_state.ps.shader != shader) { + m_state.ps.shader = shader; + + m_context->bindShader(VK_SHADER_STAGE_FRAGMENT_BIT, + shader != nullptr ? shader->GetShader() : nullptr); + } } diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 5be273e16..779438a90 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -638,7 +638,7 @@ namespace dxvk { try { *pShaderModule = D3D11ShaderModule( - pShaderBytecode, BytecodeLength); + this, pShaderBytecode, BytecodeLength); return S_OK; } catch (const DxvkError& e) { Logger::err(e.message()); diff --git a/src/d3d11/d3d11_shader.cpp b/src/d3d11/d3d11_shader.cpp index e28a94caf..69d6d045e 100644 --- a/src/d3d11/d3d11_shader.cpp +++ b/src/d3d11/d3d11_shader.cpp @@ -1,3 +1,4 @@ +#include "d3d11_device.h" #include "d3d11_shader.h" namespace dxvk { @@ -23,17 +24,20 @@ namespace dxvk { D3D11ShaderModule::D3D11ShaderModule( - const void* pShaderBytecode, - size_t BytecodeLength) { + D3D11Device* pDevice, + const void* pShaderBytecode, + size_t BytecodeLength) { DxbcReader reader( reinterpret_cast(pShaderBytecode), BytecodeLength); DxbcModule module(reader); - m_code = module.compile(); + + SpirvCodeBuffer spirvCode = module.compile(); // TODO pre-process shader bindings + std::vector resourceSlots; // If requested by the user, dump both the raw DXBC // shader and the compiled SPIR-V module to a file. @@ -47,9 +51,15 @@ namespace dxvk { reader.store(std::ofstream(str::format(baseName, ".dxbc"), std::ios_base::binary | std::ios_base::trunc)); - m_code.store(std::ofstream(str::format(baseName, ".spv"), + spirvCode.store(std::ofstream(str::format(baseName, ".spv"), std::ios_base::binary | std::ios_base::trunc)); } + + m_shader = pDevice->GetDXVKDevice()->createShader( + module.version().shaderStage(), + resourceSlots.size(), + resourceSlots.data(), + spirvCode); } diff --git a/src/d3d11/d3d11_shader.h b/src/d3d11/d3d11_shader.h index bfda2bcd2..6a87ef13a 100644 --- a/src/d3d11/d3d11_shader.h +++ b/src/d3d11/d3d11_shader.h @@ -23,14 +23,18 @@ namespace dxvk { D3D11ShaderModule(); D3D11ShaderModule( - const void* pShaderBytecode, - size_t BytecodeLength); + D3D11Device* pDevice, + const void* pShaderBytecode, + size_t BytecodeLength); ~D3D11ShaderModule(); + Rc GetShader() const { + return m_shader; + } + private: - - SpirvCodeBuffer m_code; + Rc m_shader; Sha1Hash ComputeShaderHash( const void* pShaderBytecode, @@ -73,8 +77,8 @@ namespace dxvk { *ppDevice = ref(m_device); } - const D3D11ShaderModule& GetShaderModule() const { - return m_module; + Rc GetShader() const { + return m_module.GetShader(); } private: