mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-01 19:29:16 +01:00
[d3d11] Refactor sampler state
This commit is contained in:
parent
1b4cb66dc3
commit
8383423fbe
@ -1373,9 +1373,7 @@ namespace dxvk {
|
|||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetSamplers<DxbcProgramType::VertexShader>(
|
SetSamplers<DxbcProgramType::VertexShader>(
|
||||||
m_state.vs.samplers,
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
StartSlot, NumSamplers,
|
|
||||||
ppSamplers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1441,7 +1439,7 @@ namespace dxvk {
|
|||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
GetSamplers(m_state.vs.samplers,
|
GetSamplers<DxbcProgramType::VertexShader>(
|
||||||
StartSlot, NumSamplers, ppSamplers);
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1513,9 +1511,7 @@ namespace dxvk {
|
|||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetSamplers<DxbcProgramType::HullShader>(
|
SetSamplers<DxbcProgramType::HullShader>(
|
||||||
m_state.hs.samplers,
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
StartSlot, NumSamplers,
|
|
||||||
ppSamplers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1581,7 +1577,7 @@ namespace dxvk {
|
|||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
GetSamplers(m_state.hs.samplers,
|
GetSamplers<DxbcProgramType::HullShader>(
|
||||||
StartSlot, NumSamplers, ppSamplers);
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1653,9 +1649,7 @@ namespace dxvk {
|
|||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetSamplers<DxbcProgramType::DomainShader>(
|
SetSamplers<DxbcProgramType::DomainShader>(
|
||||||
m_state.ds.samplers,
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
StartSlot, NumSamplers,
|
|
||||||
ppSamplers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1721,7 +1715,7 @@ namespace dxvk {
|
|||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
GetSamplers(m_state.ds.samplers,
|
GetSamplers<DxbcProgramType::DomainShader>(
|
||||||
StartSlot, NumSamplers, ppSamplers);
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1793,9 +1787,7 @@ namespace dxvk {
|
|||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetSamplers<DxbcProgramType::GeometryShader>(
|
SetSamplers<DxbcProgramType::GeometryShader>(
|
||||||
m_state.gs.samplers,
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
StartSlot, NumSamplers,
|
|
||||||
ppSamplers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1861,7 +1853,7 @@ namespace dxvk {
|
|||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
GetSamplers(m_state.gs.samplers,
|
GetSamplers<DxbcProgramType::GeometryShader>(
|
||||||
StartSlot, NumSamplers, ppSamplers);
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1933,9 +1925,7 @@ namespace dxvk {
|
|||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetSamplers<DxbcProgramType::PixelShader>(
|
SetSamplers<DxbcProgramType::PixelShader>(
|
||||||
m_state.ps.samplers,
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
StartSlot, NumSamplers,
|
|
||||||
ppSamplers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2001,7 +1991,7 @@ namespace dxvk {
|
|||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
GetSamplers(m_state.ps.samplers,
|
GetSamplers<DxbcProgramType::PixelShader>(
|
||||||
StartSlot, NumSamplers, ppSamplers);
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2073,9 +2063,7 @@ namespace dxvk {
|
|||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetSamplers<DxbcProgramType::ComputeShader>(
|
SetSamplers<DxbcProgramType::ComputeShader>(
|
||||||
m_state.cs.samplers,
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
StartSlot, NumSamplers,
|
|
||||||
ppSamplers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2198,7 +2186,7 @@ namespace dxvk {
|
|||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
GetSamplers(m_state.cs.samplers,
|
GetSamplers<DxbcProgramType::ComputeShader>(
|
||||||
StartSlot, NumSamplers, ppSamplers);
|
StartSlot, NumSamplers, ppSamplers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3773,14 +3761,16 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
template<typename ContextType>
|
template<typename ContextType>
|
||||||
|
template<DxbcProgramType ShaderStage>
|
||||||
void D3D11CommonContext<ContextType>::GetSamplers(
|
void D3D11CommonContext<ContextType>::GetSamplers(
|
||||||
const D3D11SamplerBindings& Bindings,
|
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
UINT NumSamplers,
|
UINT NumSamplers,
|
||||||
ID3D11SamplerState** ppSamplers) {
|
ID3D11SamplerState** ppSamplers) {
|
||||||
|
const auto& bindings = m_state.samplers[ShaderStage];
|
||||||
|
|
||||||
for (uint32_t i = 0; i < NumSamplers; i++) {
|
for (uint32_t i = 0; i < NumSamplers; i++) {
|
||||||
ppSamplers[i] = StartSlot + i < Bindings.size()
|
ppSamplers[i] = StartSlot + i < bindings.samplers.size()
|
||||||
? ref(Bindings[StartSlot + i])
|
? ref(bindings.samplers[StartSlot + i])
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3905,16 +3895,7 @@ namespace dxvk {
|
|||||||
// Reset resource bindings
|
// Reset resource bindings
|
||||||
m_state.cbv.reset();
|
m_state.cbv.reset();
|
||||||
m_state.srv.reset();
|
m_state.srv.reset();
|
||||||
|
m_state.samplers.reset();
|
||||||
// Default samplers
|
|
||||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
|
|
||||||
m_state.vs.samplers[i] = nullptr;
|
|
||||||
m_state.hs.samplers[i] = nullptr;
|
|
||||||
m_state.ds.samplers[i] = nullptr;
|
|
||||||
m_state.gs.samplers[i] = nullptr;
|
|
||||||
m_state.ps.samplers[i] = nullptr;
|
|
||||||
m_state.cs.samplers[i] = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default UAVs
|
// Default UAVs
|
||||||
for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) {
|
for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) {
|
||||||
@ -4132,13 +4113,6 @@ namespace dxvk {
|
|||||||
RestoreConstantBuffers<DxbcProgramType::PixelShader>();
|
RestoreConstantBuffers<DxbcProgramType::PixelShader>();
|
||||||
RestoreConstantBuffers<DxbcProgramType::ComputeShader>();
|
RestoreConstantBuffers<DxbcProgramType::ComputeShader>();
|
||||||
|
|
||||||
RestoreSamplers<DxbcProgramType::VertexShader> (m_state.vs.samplers);
|
|
||||||
RestoreSamplers<DxbcProgramType::HullShader> (m_state.hs.samplers);
|
|
||||||
RestoreSamplers<DxbcProgramType::DomainShader> (m_state.ds.samplers);
|
|
||||||
RestoreSamplers<DxbcProgramType::GeometryShader>(m_state.gs.samplers);
|
|
||||||
RestoreSamplers<DxbcProgramType::PixelShader> (m_state.ps.samplers);
|
|
||||||
RestoreSamplers<DxbcProgramType::ComputeShader> (m_state.cs.samplers);
|
|
||||||
|
|
||||||
RestoreShaderResources<DxbcProgramType::VertexShader>();
|
RestoreShaderResources<DxbcProgramType::VertexShader>();
|
||||||
RestoreShaderResources<DxbcProgramType::HullShader>();
|
RestoreShaderResources<DxbcProgramType::HullShader>();
|
||||||
RestoreShaderResources<DxbcProgramType::DomainShader>();
|
RestoreShaderResources<DxbcProgramType::DomainShader>();
|
||||||
@ -4148,6 +4122,13 @@ namespace dxvk {
|
|||||||
|
|
||||||
RestoreUnorderedAccessViews<DxbcProgramType::PixelShader> (m_state.ps.unorderedAccessViews);
|
RestoreUnorderedAccessViews<DxbcProgramType::PixelShader> (m_state.ps.unorderedAccessViews);
|
||||||
RestoreUnorderedAccessViews<DxbcProgramType::ComputeShader> (m_state.cs.unorderedAccessViews);
|
RestoreUnorderedAccessViews<DxbcProgramType::ComputeShader> (m_state.cs.unorderedAccessViews);
|
||||||
|
|
||||||
|
RestoreSamplers<DxbcProgramType::VertexShader>();
|
||||||
|
RestoreSamplers<DxbcProgramType::HullShader>();
|
||||||
|
RestoreSamplers<DxbcProgramType::DomainShader>();
|
||||||
|
RestoreSamplers<DxbcProgramType::GeometryShader>();
|
||||||
|
RestoreSamplers<DxbcProgramType::PixelShader>();
|
||||||
|
RestoreSamplers<DxbcProgramType::ComputeShader>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4166,12 +4147,12 @@ namespace dxvk {
|
|||||||
|
|
||||||
template<typename ContextType>
|
template<typename ContextType>
|
||||||
template<DxbcProgramType Stage>
|
template<DxbcProgramType Stage>
|
||||||
void D3D11CommonContext<ContextType>::RestoreSamplers(
|
void D3D11CommonContext<ContextType>::RestoreSamplers() {
|
||||||
D3D11SamplerBindings& Bindings) {
|
const auto& bindings = m_state.samplers[Stage];
|
||||||
uint32_t slotId = computeSamplerBinding(Stage, 0);
|
uint32_t slotId = computeSamplerBinding(Stage, 0);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < Bindings.size(); i++)
|
for (uint32_t i = 0; i < bindings.samplers.size(); i++)
|
||||||
BindSampler<Stage>(slotId + i, Bindings[i]);
|
BindSampler<Stage>(slotId + i, bindings.samplers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4337,17 +4318,17 @@ namespace dxvk {
|
|||||||
template<typename ContextType>
|
template<typename ContextType>
|
||||||
template<DxbcProgramType ShaderStage>
|
template<DxbcProgramType ShaderStage>
|
||||||
void D3D11CommonContext<ContextType>::SetSamplers(
|
void D3D11CommonContext<ContextType>::SetSamplers(
|
||||||
D3D11SamplerBindings& Bindings,
|
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
UINT NumSamplers,
|
UINT NumSamplers,
|
||||||
ID3D11SamplerState* const* ppSamplers) {
|
ID3D11SamplerState* const* ppSamplers) {
|
||||||
|
auto& bindings = m_state.samplers[ShaderStage];
|
||||||
uint32_t slotId = computeSamplerBinding(ShaderStage, StartSlot);
|
uint32_t slotId = computeSamplerBinding(ShaderStage, StartSlot);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < NumSamplers; i++) {
|
for (uint32_t i = 0; i < NumSamplers; i++) {
|
||||||
auto sampler = static_cast<D3D11SamplerState*>(ppSamplers[i]);
|
auto sampler = static_cast<D3D11SamplerState*>(ppSamplers[i]);
|
||||||
|
|
||||||
if (Bindings[StartSlot + i] != sampler) {
|
if (bindings.samplers[StartSlot + i] != sampler) {
|
||||||
Bindings[StartSlot + i] = sampler;
|
bindings.samplers[StartSlot + i] = sampler;
|
||||||
BindSampler<ShaderStage>(slotId + i, sampler);
|
BindSampler<ShaderStage>(slotId + i, sampler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -900,8 +900,8 @@ namespace dxvk {
|
|||||||
UINT NumViews,
|
UINT NumViews,
|
||||||
ID3D11ShaderResourceView** ppShaderResourceViews);
|
ID3D11ShaderResourceView** ppShaderResourceViews);
|
||||||
|
|
||||||
|
template<DxbcProgramType ShaderStage>
|
||||||
void GetSamplers(
|
void GetSamplers(
|
||||||
const D3D11SamplerBindings& Bindings,
|
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
UINT NumSamplers,
|
UINT NumSamplers,
|
||||||
ID3D11SamplerState** ppSamplers);
|
ID3D11SamplerState** ppSamplers);
|
||||||
@ -936,8 +936,7 @@ namespace dxvk {
|
|||||||
void RestoreConstantBuffers();
|
void RestoreConstantBuffers();
|
||||||
|
|
||||||
template<DxbcProgramType Stage>
|
template<DxbcProgramType Stage>
|
||||||
void RestoreSamplers(
|
void RestoreSamplers();
|
||||||
D3D11SamplerBindings& Bindings);
|
|
||||||
|
|
||||||
template<DxbcProgramType Stage>
|
template<DxbcProgramType Stage>
|
||||||
void RestoreShaderResources();
|
void RestoreShaderResources();
|
||||||
@ -968,7 +967,6 @@ namespace dxvk {
|
|||||||
|
|
||||||
template<DxbcProgramType ShaderStage>
|
template<DxbcProgramType ShaderStage>
|
||||||
void SetSamplers(
|
void SetSamplers(
|
||||||
D3D11SamplerBindings& Bindings,
|
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
UINT NumSamplers,
|
UINT NumSamplers,
|
||||||
ID3D11SamplerState* const* ppSamplers);
|
ID3D11SamplerState* const* ppSamplers);
|
||||||
|
@ -87,10 +87,22 @@ namespace dxvk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
using D3D11SrvBindings = D3D11ShaderStageState<D3D11ShaderStageSrvBinding>;
|
using D3D11SrvBindings = D3D11ShaderStageState<D3D11ShaderStageSrvBinding>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Sampler bindings
|
||||||
|
*
|
||||||
|
* Stores bound samplers.
|
||||||
|
*/
|
||||||
|
struct D3D11ShaderStageSamplerBinding {
|
||||||
|
std::array<D3D11SamplerState*, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT> samplers = { };
|
||||||
|
|
||||||
|
void reset() {
|
||||||
|
for (uint32_t i = 0; i < samplers.size(); i++)
|
||||||
|
samplers[i] = nullptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
using D3D11SamplerBindings = std::array<
|
using D3D11SamplerBindings = D3D11ShaderStageState<D3D11ShaderStageSamplerBinding>;
|
||||||
D3D11SamplerState*, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>;
|
|
||||||
|
|
||||||
|
|
||||||
using D3D11UnorderedAccessBindings = std::array<
|
using D3D11UnorderedAccessBindings = std::array<
|
||||||
Com<D3D11UnorderedAccessView>, D3D11_1_UAV_SLOT_COUNT>;
|
Com<D3D11UnorderedAccessView>, D3D11_1_UAV_SLOT_COUNT>;
|
||||||
@ -98,38 +110,32 @@ namespace dxvk {
|
|||||||
|
|
||||||
struct D3D11ContextStateVS {
|
struct D3D11ContextStateVS {
|
||||||
Com<D3D11VertexShader> shader = nullptr;
|
Com<D3D11VertexShader> shader = nullptr;
|
||||||
D3D11SamplerBindings samplers = { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct D3D11ContextStateHS {
|
struct D3D11ContextStateHS {
|
||||||
Com<D3D11HullShader> shader = nullptr;
|
Com<D3D11HullShader> shader = nullptr;
|
||||||
D3D11SamplerBindings samplers = { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct D3D11ContextStateDS {
|
struct D3D11ContextStateDS {
|
||||||
Com<D3D11DomainShader> shader = nullptr;
|
Com<D3D11DomainShader> shader = nullptr;
|
||||||
D3D11SamplerBindings samplers = { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct D3D11ContextStateGS {
|
struct D3D11ContextStateGS {
|
||||||
Com<D3D11GeometryShader> shader = nullptr;
|
Com<D3D11GeometryShader> shader = nullptr;
|
||||||
D3D11SamplerBindings samplers = { };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct D3D11ContextStatePS {
|
struct D3D11ContextStatePS {
|
||||||
Com<D3D11PixelShader> shader = nullptr;
|
Com<D3D11PixelShader> shader = nullptr;
|
||||||
D3D11SamplerBindings samplers = { };
|
|
||||||
D3D11UnorderedAccessBindings unorderedAccessViews = { };
|
D3D11UnorderedAccessBindings unorderedAccessViews = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct D3D11ContextStateCS {
|
struct D3D11ContextStateCS {
|
||||||
Com<D3D11ComputeShader> shader = nullptr;
|
Com<D3D11ComputeShader> shader = nullptr;
|
||||||
D3D11SamplerBindings samplers = { };
|
|
||||||
D3D11UnorderedAccessBindings unorderedAccessViews = { };
|
D3D11UnorderedAccessBindings unorderedAccessViews = { };
|
||||||
|
|
||||||
DxvkBindingSet<D3D11_1_UAV_SLOT_COUNT> uavMask = { };
|
DxvkBindingSet<D3D11_1_UAV_SLOT_COUNT> uavMask = { };
|
||||||
@ -231,6 +237,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
D3D11CbvBindings cbv;
|
D3D11CbvBindings cbv;
|
||||||
D3D11SrvBindings srv;
|
D3D11SrvBindings srv;
|
||||||
|
D3D11SamplerBindings samplers;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user