mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-12 22:08:59 +01:00
[d3d11] Refactor shader resource state
This commit is contained in:
parent
33e169e85f
commit
1b4cb66dc3
@ -1361,9 +1361,7 @@ namespace dxvk {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
SetShaderResources<DxbcProgramType::VertexShader>(
|
||||
m_state.vs.shaderResources,
|
||||
StartSlot, NumViews,
|
||||
ppShaderResourceViews);
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
|
||||
@ -1431,7 +1429,7 @@ namespace dxvk {
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
GetShaderResources(m_state.vs.shaderResources,
|
||||
GetShaderResources<DxbcProgramType::VertexShader>(
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
@ -1503,9 +1501,7 @@ namespace dxvk {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
SetShaderResources<DxbcProgramType::HullShader>(
|
||||
m_state.hs.shaderResources,
|
||||
StartSlot, NumViews,
|
||||
ppShaderResourceViews);
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
|
||||
@ -1573,7 +1569,7 @@ namespace dxvk {
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
GetShaderResources(m_state.hs.shaderResources,
|
||||
GetShaderResources<DxbcProgramType::HullShader>(
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
@ -1645,9 +1641,7 @@ namespace dxvk {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
SetShaderResources<DxbcProgramType::DomainShader>(
|
||||
m_state.ds.shaderResources,
|
||||
StartSlot, NumViews,
|
||||
ppShaderResourceViews);
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
|
||||
@ -1715,7 +1709,7 @@ namespace dxvk {
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
GetShaderResources(m_state.ds.shaderResources,
|
||||
GetShaderResources<DxbcProgramType::DomainShader>(
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
@ -1787,9 +1781,7 @@ namespace dxvk {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
SetShaderResources<DxbcProgramType::GeometryShader>(
|
||||
m_state.gs.shaderResources,
|
||||
StartSlot, NumViews,
|
||||
ppShaderResourceViews);
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
|
||||
@ -1857,7 +1849,7 @@ namespace dxvk {
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
GetShaderResources(m_state.gs.shaderResources,
|
||||
GetShaderResources<DxbcProgramType::GeometryShader>(
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
@ -1929,9 +1921,7 @@ namespace dxvk {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
SetShaderResources<DxbcProgramType::PixelShader>(
|
||||
m_state.ps.shaderResources,
|
||||
StartSlot, NumViews,
|
||||
ppShaderResourceViews);
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
|
||||
@ -1999,7 +1989,7 @@ namespace dxvk {
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
GetShaderResources(m_state.ps.shaderResources,
|
||||
GetShaderResources<DxbcProgramType::PixelShader>(
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
@ -2071,9 +2061,7 @@ namespace dxvk {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
SetShaderResources<DxbcProgramType::ComputeShader>(
|
||||
m_state.cs.shaderResources,
|
||||
StartSlot, NumViews,
|
||||
ppShaderResourceViews);
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
|
||||
@ -2198,7 +2186,7 @@ namespace dxvk {
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
D3D10DeviceLock lock = LockContext();
|
||||
|
||||
GetShaderResources(m_state.cs.shaderResources,
|
||||
GetShaderResources<DxbcProgramType::ComputeShader>(
|
||||
StartSlot, NumViews, ppShaderResourceViews);
|
||||
}
|
||||
|
||||
@ -3769,14 +3757,16 @@ namespace dxvk {
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType ShaderStage>
|
||||
void D3D11CommonContext<ContextType>::GetShaderResources(
|
||||
const D3D11ShaderResourceBindings& Bindings,
|
||||
UINT StartSlot,
|
||||
UINT NumViews,
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
||||
const auto& bindings = m_state.srv[ShaderStage];
|
||||
|
||||
for (uint32_t i = 0; i < NumViews; i++) {
|
||||
ppShaderResourceViews[i] = StartSlot + i < Bindings.views.size()
|
||||
? Bindings.views[StartSlot + i].ref()
|
||||
ppShaderResourceViews[i] = StartSlot + i < bindings.views.size()
|
||||
? bindings.views[StartSlot + i].ref()
|
||||
: nullptr;
|
||||
}
|
||||
}
|
||||
@ -3914,6 +3904,7 @@ namespace dxvk {
|
||||
|
||||
// Reset resource bindings
|
||||
m_state.cbv.reset();
|
||||
m_state.srv.reset();
|
||||
|
||||
// Default samplers
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
|
||||
@ -3925,23 +3916,6 @@ namespace dxvk {
|
||||
m_state.cs.samplers[i] = nullptr;
|
||||
}
|
||||
|
||||
// Default shader resources
|
||||
for (uint32_t i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
||||
m_state.vs.shaderResources.views[i] = nullptr;
|
||||
m_state.hs.shaderResources.views[i] = nullptr;
|
||||
m_state.ds.shaderResources.views[i] = nullptr;
|
||||
m_state.gs.shaderResources.views[i] = nullptr;
|
||||
m_state.ps.shaderResources.views[i] = nullptr;
|
||||
m_state.cs.shaderResources.views[i] = nullptr;
|
||||
}
|
||||
|
||||
m_state.vs.shaderResources.hazardous.clear();
|
||||
m_state.hs.shaderResources.hazardous.clear();
|
||||
m_state.ds.shaderResources.hazardous.clear();
|
||||
m_state.gs.shaderResources.hazardous.clear();
|
||||
m_state.ps.shaderResources.hazardous.clear();
|
||||
m_state.cs.shaderResources.hazardous.clear();
|
||||
|
||||
// Default UAVs
|
||||
for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) {
|
||||
m_state.ps.unorderedAccessViews[i] = nullptr;
|
||||
@ -4016,29 +3990,30 @@ namespace dxvk {
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType ShaderStage, typename T>
|
||||
void D3D11CommonContext<ContextType>::ResolveSrvHazards(
|
||||
T* pView,
|
||||
D3D11ShaderResourceBindings& Bindings) {
|
||||
T* pView) {
|
||||
auto& bindings = m_state.srv[ShaderStage];
|
||||
|
||||
uint32_t slotId = computeSrvBinding(ShaderStage, 0);
|
||||
int32_t srvId = Bindings.hazardous.findNext(0);
|
||||
int32_t srvId = bindings.hazardous.findNext(0);
|
||||
|
||||
while (srvId >= 0) {
|
||||
auto srv = Bindings.views[srvId].ptr();
|
||||
auto srv = bindings.views[srvId].ptr();
|
||||
|
||||
if (likely(srv && srv->TestHazards())) {
|
||||
bool hazard = CheckViewOverlap(pView, srv);
|
||||
|
||||
if (unlikely(hazard)) {
|
||||
Bindings.views[srvId] = nullptr;
|
||||
Bindings.hazardous.clr(srvId);
|
||||
bindings.views[srvId] = nullptr;
|
||||
bindings.hazardous.clr(srvId);
|
||||
|
||||
BindShaderResource<ShaderStage>(slotId + srvId, nullptr);
|
||||
}
|
||||
} else {
|
||||
// Avoid further redundant iterations
|
||||
Bindings.hazardous.clr(srvId);
|
||||
bindings.hazardous.clr(srvId);
|
||||
}
|
||||
|
||||
srvId = Bindings.hazardous.findNext(srvId + 1);
|
||||
srvId = bindings.hazardous.findNext(srvId + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4048,7 +4023,7 @@ namespace dxvk {
|
||||
void D3D11CommonContext<ContextType>::ResolveCsSrvHazards(
|
||||
T* pView) {
|
||||
if (!pView) return;
|
||||
ResolveSrvHazards<DxbcProgramType::ComputeShader> (pView, m_state.cs.shaderResources);
|
||||
ResolveSrvHazards<DxbcProgramType::ComputeShader>(pView);
|
||||
}
|
||||
|
||||
|
||||
@ -4057,11 +4032,11 @@ namespace dxvk {
|
||||
void D3D11CommonContext<ContextType>::ResolveOmSrvHazards(
|
||||
T* pView) {
|
||||
if (!pView) return;
|
||||
ResolveSrvHazards<DxbcProgramType::VertexShader> (pView, m_state.vs.shaderResources);
|
||||
ResolveSrvHazards<DxbcProgramType::HullShader> (pView, m_state.hs.shaderResources);
|
||||
ResolveSrvHazards<DxbcProgramType::DomainShader> (pView, m_state.ds.shaderResources);
|
||||
ResolveSrvHazards<DxbcProgramType::GeometryShader> (pView, m_state.gs.shaderResources);
|
||||
ResolveSrvHazards<DxbcProgramType::PixelShader> (pView, m_state.ps.shaderResources);
|
||||
ResolveSrvHazards<DxbcProgramType::VertexShader>(pView);
|
||||
ResolveSrvHazards<DxbcProgramType::HullShader>(pView);
|
||||
ResolveSrvHazards<DxbcProgramType::DomainShader>(pView);
|
||||
ResolveSrvHazards<DxbcProgramType::GeometryShader>(pView);
|
||||
ResolveSrvHazards<DxbcProgramType::PixelShader>(pView);
|
||||
}
|
||||
|
||||
|
||||
@ -4164,12 +4139,12 @@ namespace dxvk {
|
||||
RestoreSamplers<DxbcProgramType::PixelShader> (m_state.ps.samplers);
|
||||
RestoreSamplers<DxbcProgramType::ComputeShader> (m_state.cs.samplers);
|
||||
|
||||
RestoreShaderResources<DxbcProgramType::VertexShader> (m_state.vs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::HullShader> (m_state.hs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::DomainShader> (m_state.ds.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::GeometryShader> (m_state.gs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::PixelShader> (m_state.ps.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::ComputeShader> (m_state.cs.shaderResources);
|
||||
RestoreShaderResources<DxbcProgramType::VertexShader>();
|
||||
RestoreShaderResources<DxbcProgramType::HullShader>();
|
||||
RestoreShaderResources<DxbcProgramType::DomainShader>();
|
||||
RestoreShaderResources<DxbcProgramType::GeometryShader>();
|
||||
RestoreShaderResources<DxbcProgramType::PixelShader>();
|
||||
RestoreShaderResources<DxbcProgramType::ComputeShader>();
|
||||
|
||||
RestoreUnorderedAccessViews<DxbcProgramType::PixelShader> (m_state.ps.unorderedAccessViews);
|
||||
RestoreUnorderedAccessViews<DxbcProgramType::ComputeShader> (m_state.cs.unorderedAccessViews);
|
||||
@ -4202,12 +4177,12 @@ namespace dxvk {
|
||||
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType Stage>
|
||||
void D3D11CommonContext<ContextType>::RestoreShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings) {
|
||||
void D3D11CommonContext<ContextType>::RestoreShaderResources() {
|
||||
const auto& bindings = m_state.srv[Stage];
|
||||
uint32_t slotId = computeSrvBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.views.size(); i++)
|
||||
BindShaderResource<Stage>(slotId + i, Bindings.views[i].ptr());
|
||||
for (uint32_t i = 0; i < bindings.views.size(); i++)
|
||||
BindShaderResource<Stage>(slotId + i, bindings.views[i].ptr());
|
||||
}
|
||||
|
||||
|
||||
@ -4332,16 +4307,16 @@ namespace dxvk {
|
||||
template<typename ContextType>
|
||||
template<DxbcProgramType ShaderStage>
|
||||
void D3D11CommonContext<ContextType>::SetShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings,
|
||||
UINT StartSlot,
|
||||
UINT NumResources,
|
||||
ID3D11ShaderResourceView* const* ppResources) {
|
||||
auto& bindings = m_state.srv[ShaderStage];
|
||||
uint32_t slotId = computeSrvBinding(ShaderStage, StartSlot);
|
||||
|
||||
for (uint32_t i = 0; i < NumResources; i++) {
|
||||
auto resView = static_cast<D3D11ShaderResourceView*>(ppResources[i]);
|
||||
|
||||
if (Bindings.views[StartSlot + i] != resView) {
|
||||
if (bindings.views[StartSlot + i] != resView) {
|
||||
if (unlikely(resView && resView->TestHazards())) {
|
||||
if (TestSrvHazards<ShaderStage>(resView))
|
||||
resView = nullptr;
|
||||
@ -4349,10 +4324,10 @@ namespace dxvk {
|
||||
// Only set if necessary, but don't reset it on every
|
||||
// bind as this would be more expensive than a few
|
||||
// redundant checks in OMSetRenderTargets and friends.
|
||||
Bindings.hazardous.set(StartSlot + i, resView);
|
||||
bindings.hazardous.set(StartSlot + i, resView);
|
||||
}
|
||||
|
||||
Bindings.views[StartSlot + i] = resView;
|
||||
bindings.views[StartSlot + i] = resView;
|
||||
BindShaderResource<ShaderStage>(slotId + i, resView);
|
||||
}
|
||||
}
|
||||
|
@ -894,8 +894,8 @@ namespace dxvk {
|
||||
UINT* pFirstConstant,
|
||||
UINT* pNumConstants);
|
||||
|
||||
template<DxbcProgramType ShaderStage>
|
||||
void GetShaderResources(
|
||||
const D3D11ShaderResourceBindings& Bindings,
|
||||
UINT StartSlot,
|
||||
UINT NumViews,
|
||||
ID3D11ShaderResourceView** ppShaderResourceViews);
|
||||
@ -914,8 +914,7 @@ namespace dxvk {
|
||||
|
||||
template<DxbcProgramType ShaderStage, typename T>
|
||||
void ResolveSrvHazards(
|
||||
T* pView,
|
||||
D3D11ShaderResourceBindings& Bindings);
|
||||
T* pView);
|
||||
|
||||
template<typename T>
|
||||
void ResolveCsSrvHazards(
|
||||
@ -941,8 +940,7 @@ namespace dxvk {
|
||||
D3D11SamplerBindings& Bindings);
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings);
|
||||
void RestoreShaderResources();
|
||||
|
||||
template<DxbcProgramType Stage>
|
||||
void RestoreUnorderedAccessViews(
|
||||
@ -964,7 +962,6 @@ namespace dxvk {
|
||||
|
||||
template<DxbcProgramType ShaderStage>
|
||||
void SetShaderResources(
|
||||
D3D11ShaderResourceBindings& Bindings,
|
||||
UINT StartSlot,
|
||||
UINT NumResources,
|
||||
ID3D11ShaderResourceView* const* ppResources);
|
||||
|
@ -68,16 +68,30 @@ namespace dxvk {
|
||||
|
||||
using D3D11CbvBindings = D3D11ShaderStageState<D3D11ShaderStageCbvBinding>;
|
||||
|
||||
/**
|
||||
* \brief Shader resource bindings
|
||||
*
|
||||
* Stores bound shader resource views, as well as a bit
|
||||
* set of views that are potentially hazardous.
|
||||
*/
|
||||
struct D3D11ShaderStageSrvBinding {
|
||||
std::array<Com<D3D11ShaderResourceView>, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> views = { };
|
||||
DxvkBindingSet<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> hazardous = { };
|
||||
|
||||
void reset() {
|
||||
for (uint32_t i = 0; i < views.size(); i++)
|
||||
views[i] = nullptr;
|
||||
|
||||
hazardous.clear();
|
||||
}
|
||||
};
|
||||
|
||||
using D3D11SrvBindings = D3D11ShaderStageState<D3D11ShaderStageSrvBinding>;
|
||||
|
||||
using D3D11SamplerBindings = std::array<
|
||||
D3D11SamplerState*, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>;
|
||||
|
||||
|
||||
struct D3D11ShaderResourceBindings {
|
||||
std::array<Com<D3D11ShaderResourceView>, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> views = { };
|
||||
DxvkBindingSet<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> hazardous = { };
|
||||
};
|
||||
|
||||
|
||||
using D3D11UnorderedAccessBindings = std::array<
|
||||
Com<D3D11UnorderedAccessView>, D3D11_1_UAV_SLOT_COUNT>;
|
||||
|
||||
@ -85,35 +99,30 @@ namespace dxvk {
|
||||
struct D3D11ContextStateVS {
|
||||
Com<D3D11VertexShader> shader = nullptr;
|
||||
D3D11SamplerBindings samplers = { };
|
||||
D3D11ShaderResourceBindings shaderResources = { };
|
||||
};
|
||||
|
||||
|
||||
struct D3D11ContextStateHS {
|
||||
Com<D3D11HullShader> shader = nullptr;
|
||||
D3D11SamplerBindings samplers = { };
|
||||
D3D11ShaderResourceBindings shaderResources = { };
|
||||
};
|
||||
|
||||
|
||||
struct D3D11ContextStateDS {
|
||||
Com<D3D11DomainShader> shader = nullptr;
|
||||
D3D11SamplerBindings samplers = { };
|
||||
D3D11ShaderResourceBindings shaderResources = { };
|
||||
};
|
||||
|
||||
|
||||
struct D3D11ContextStateGS {
|
||||
Com<D3D11GeometryShader> shader = nullptr;
|
||||
D3D11SamplerBindings samplers = { };
|
||||
D3D11ShaderResourceBindings shaderResources = { };
|
||||
};
|
||||
|
||||
|
||||
struct D3D11ContextStatePS {
|
||||
Com<D3D11PixelShader> shader = nullptr;
|
||||
D3D11SamplerBindings samplers = { };
|
||||
D3D11ShaderResourceBindings shaderResources = { };
|
||||
D3D11UnorderedAccessBindings unorderedAccessViews = { };
|
||||
};
|
||||
|
||||
@ -121,7 +130,6 @@ namespace dxvk {
|
||||
struct D3D11ContextStateCS {
|
||||
Com<D3D11ComputeShader> shader = nullptr;
|
||||
D3D11SamplerBindings samplers = { };
|
||||
D3D11ShaderResourceBindings shaderResources = { };
|
||||
D3D11UnorderedAccessBindings unorderedAccessViews = { };
|
||||
|
||||
DxvkBindingSet<D3D11_1_UAV_SLOT_COUNT> uavMask = { };
|
||||
@ -222,6 +230,7 @@ namespace dxvk {
|
||||
D3D11ContextStatePR pr;
|
||||
|
||||
D3D11CbvBindings cbv;
|
||||
D3D11SrvBindings srv;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user