diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index b80308e4b..8f7a0641c 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -762,7 +762,11 @@ namespace dxvk { UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { - Logger::err("D3D11DeviceContext::VSSetSamplers: Not implemented"); + this->BindSamplers( + DxbcProgramType::VertexShader, + &m_state.vs.samplers, + StartSlot, NumSamplers, + ppSamplers); } @@ -1032,7 +1036,11 @@ namespace dxvk { UINT StartSlot, UINT NumSamplers, ID3D11SamplerState* const* ppSamplers) { - Logger::err("D3D11DeviceContext::PSSetSamplers: Not implemented"); + this->BindSamplers( + DxbcProgramType::PixelShader, + &m_state.ps.samplers, + StartSlot, NumSamplers, + ppSamplers); } @@ -1390,6 +1398,7 @@ namespace dxvk { if (pBindings->at(StartSlot + i) != buffer) { pBindings->at(StartSlot + i) = buffer; + // Figure out which part of the buffer to bind DxvkBufferBinding bindingInfo; if (buffer != nullptr) { @@ -1398,12 +1407,13 @@ namespace dxvk { 0, VK_WHOLE_SIZE); } - VkPipelineBindPoint bindPoint + // Bind buffer to the DXVK resource slot + const VkPipelineBindPoint bindPoint = ShaderStage == DxbcProgramType::ComputeShader ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS; - uint32_t slotId = computeResourceSlotId( + const uint32_t slotId = computeResourceSlotId( ShaderStage, DxbcBindingType::ConstantBuffer, StartSlot + i); @@ -1414,6 +1424,44 @@ namespace dxvk { } + void D3D11DeviceContext::BindSamplers( + DxbcProgramType ShaderStage, + D3D11SamplerBindings* pBindings, + UINT StartSlot, + UINT NumSamplers, + ID3D11SamplerState* const* ppSamplers) { + for (uint32_t i = 0; i < NumSamplers; i++) { + D3D11SamplerState* sampler = nullptr; + + if (ppSamplers != nullptr) + sampler = static_cast(ppSamplers[i]); + + if (pBindings->at(StartSlot + i) != sampler) { + pBindings->at(StartSlot + i) = sampler; + + // Retrieve the DXVK sampler object + Rc samplerInfo = nullptr; + + if (sampler != nullptr) + samplerInfo = sampler->GetDXVKSampler(); + + // Bind sampler to the DXVK resource slot + const VkPipelineBindPoint bindPoint + = ShaderStage == DxbcProgramType::ComputeShader + ? VK_PIPELINE_BIND_POINT_COMPUTE + : VK_PIPELINE_BIND_POINT_GRAPHICS; + + const uint32_t slotId = computeResourceSlotId( + ShaderStage, DxbcBindingType::ImageSampler, + StartSlot + i); + + m_context->bindResourceSampler( + bindPoint, slotId, samplerInfo); + } + } + } + + void D3D11DeviceContext::ApplyViewportState() { // We cannot set less than one viewport in Vulkan, and // rendering with no active viewport is illegal anyway. diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 1672821b9..6a8f8a10a 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -561,6 +561,13 @@ namespace dxvk { UINT NumBuffers, ID3D11Buffer* const* ppConstantBuffers); + void BindSamplers( + DxbcProgramType ShaderStage, + D3D11SamplerBindings* pBindings, + UINT StartSlot, + UINT NumSamplers, + ID3D11SamplerState* const* ppSamplers); + void ApplyViewportState(); void SetupIAStateObjects(); diff --git a/src/d3d11/d3d11_context_state.h b/src/d3d11/d3d11_context_state.h index 57b426fc8..26cb81d4e 100644 --- a/src/d3d11/d3d11_context_state.h +++ b/src/d3d11/d3d11_context_state.h @@ -4,6 +4,7 @@ #include "d3d11_buffer.h" #include "d3d11_input_layout.h" +#include "d3d11_sampler.h" #include "d3d11_shader.h" #include "d3d11_state.h" #include "d3d11_view.h" @@ -13,39 +14,50 @@ namespace dxvk { using D3D11ConstantBufferBindings = std::array< Com, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>; + + using D3D11SamplerBindings = std::array< + Com, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>; + + struct D3D11ContextStateVS { Com shader; D3D11ConstantBufferBindings constantBuffers; + D3D11SamplerBindings samplers; }; struct D3D11ContextStateHS { Com shader; D3D11ConstantBufferBindings constantBuffers; + D3D11SamplerBindings samplers; }; struct D3D11ContextStateDS { Com shader; D3D11ConstantBufferBindings constantBuffers; + D3D11SamplerBindings samplers; }; struct D3D11ContextStateGS { Com shader; D3D11ConstantBufferBindings constantBuffers; + D3D11SamplerBindings samplers; }; struct D3D11ContextStatePS { Com shader; D3D11ConstantBufferBindings constantBuffers; + D3D11SamplerBindings samplers; }; struct D3D11ContextStateCS { - Com shader; + Com shader; D3D11ConstantBufferBindings constantBuffers; + D3D11SamplerBindings samplers; };