1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-12 22:08:59 +01:00

[d3d11] Introduce D3D11MaxUsedBindings

And use it in ResetCommandListState, in order to avoid redundant state changes.
This commit is contained in:
Philip Rebohle 2022-08-04 17:20:49 +02:00
parent ebbb77518a
commit 18c4ca8e92
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 58 additions and 12 deletions

View File

@ -3776,9 +3776,32 @@ namespace dxvk {
} }
template<typename ContextType>
D3D11MaxUsedBindings D3D11CommonContext<ContextType>::GetMaxUsedBindings() {
D3D11MaxUsedBindings result;
for (uint32_t i = 0; i < result.stages.size(); i++) {
result.stages[i].cbvCount = D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT;
result.stages[i].srvCount = D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT;
result.stages[i].uavCount = 0;
result.stages[i].samplerCount = D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT;
result.stages[i].reserved = 0;
}
result.stages[uint32_t(DxbcProgramType::PixelShader)].uavCount = D3D11_1_UAV_SLOT_COUNT;
result.stages[uint32_t(DxbcProgramType::ComputeShader)].uavCount = D3D11_1_UAV_SLOT_COUNT;
result.vbCount = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT;
result.soCount = D3D11_SO_BUFFER_SLOT_COUNT;
return result;
}
template<typename ContextType> template<typename ContextType>
void D3D11CommonContext<ContextType>::ResetCommandListState() { void D3D11CommonContext<ContextType>::ResetCommandListState() {
EmitCs([] (DxvkContext* ctx) { EmitCs([
cUsedBindings = GetMaxUsedBindings()
] (DxvkContext* ctx) {
// Reset render targets // Reset render targets
ctx->bindRenderTargets(DxvkRenderTargets()); ctx->bindRenderTargets(DxvkRenderTargets());
@ -3825,11 +3848,11 @@ namespace dxvk {
// Unbind index and vertex buffers // Unbind index and vertex buffers
ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32); ctx->bindIndexBuffer(DxvkBufferSlice(), VK_INDEX_TYPE_UINT32);
for (uint32_t i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) for (uint32_t i = 0; i < cUsedBindings.vbCount; i++)
ctx->bindVertexBuffer(i, DxvkBufferSlice(), 0); ctx->bindVertexBuffer(i, DxvkBufferSlice(), 0);
// Unbind transform feedback buffers // Unbind transform feedback buffers
for (uint32_t i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; i++) for (uint32_t i = 0; i < cUsedBindings.soCount; i++)
ctx->bindXfbBuffer(i, DxvkBufferSlice(), DxvkBufferSlice()); ctx->bindXfbBuffer(i, DxvkBufferSlice(), DxvkBufferSlice());
// Unbind per-shader stage resources // Unbind per-shader stage resources
@ -3837,24 +3860,25 @@ namespace dxvk {
auto programType = DxbcProgramType(i); auto programType = DxbcProgramType(i);
auto stage = GetShaderStage(programType); auto stage = GetShaderStage(programType);
ctx->bindShader(stage, nullptr);
// Unbind constant buffers, including the shader's ICB // Unbind constant buffers, including the shader's ICB
auto cbSlotId = computeConstantBufferBinding(programType, 0); auto cbSlotId = computeConstantBufferBinding(programType, 0);
for (uint32_t j = 0; j <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; j++) ctx->bindShader(stage, nullptr);
ctx->bindResourceBuffer(stage, cbSlotId + D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, DxvkBufferSlice());
for (uint32_t j = 0; j < cUsedBindings.stages[i].cbvCount; j++)
ctx->bindResourceBuffer(stage, cbSlotId + j, DxvkBufferSlice()); ctx->bindResourceBuffer(stage, cbSlotId + j, DxvkBufferSlice());
// Unbind shader resource views // Unbind shader resource views
auto srvSlotId = computeSrvBinding(programType, 0); auto srvSlotId = computeSrvBinding(programType, 0);
for (uint32_t j = 0; j < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; j++) for (uint32_t j = 0; j < cUsedBindings.stages[i].srvCount; j++)
ctx->bindResourceView(stage, srvSlotId + j, nullptr, nullptr); ctx->bindResourceView(stage, srvSlotId + j, nullptr, nullptr);
// Unbind texture samplers // Unbind texture samplers
auto samplerSlotId = computeSamplerBinding(programType, 0); auto samplerSlotId = computeSamplerBinding(programType, 0);
for (uint32_t j = 0; j < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; j++) for (uint32_t j = 0; j < cUsedBindings.stages[i].samplerCount; j++)
ctx->bindResourceSampler(stage, samplerSlotId + j, nullptr); ctx->bindResourceSampler(stage, samplerSlotId + j, nullptr);
// Unbind UAVs for supported stages // Unbind UAVs for supported stages
@ -3867,7 +3891,7 @@ namespace dxvk {
auto uavSlotId = computeUavBinding(programType, 0); auto uavSlotId = computeUavBinding(programType, 0);
auto ctrSlotId = computeUavCounterBinding(programType, 0); auto ctrSlotId = computeUavCounterBinding(programType, 0);
for (uint32_t j = 0; j < D3D11_1_UAV_SLOT_COUNT; j++) { for (uint32_t j = 0; j < cUsedBindings.stages[i].uavCount; j++) {
ctx->bindResourceView(stages, uavSlotId, nullptr, nullptr); ctx->bindResourceView(stages, uavSlotId, nullptr, nullptr);
ctx->bindResourceBuffer(stages, ctrSlotId, DxvkBufferSlice()); ctx->bindResourceBuffer(stages, ctrSlotId, DxvkBufferSlice());
} }

View File

@ -906,6 +906,8 @@ namespace dxvk {
UINT NumSamplers, UINT NumSamplers,
ID3D11SamplerState** ppSamplers); ID3D11SamplerState** ppSamplers);
D3D11MaxUsedBindings GetMaxUsedBindings();
void ResetCommandListState(); void ResetCommandListState();
void ResetContextState(); void ResetContextState();

View File

@ -311,4 +311,24 @@ namespace dxvk {
D3D11SamplerBindings samplers; D3D11SamplerBindings samplers;
}; };
/**
* \brief Maximum used binding numbers in a shader stage
*/
struct D3D11MaxUsedStageBindings {
uint32_t cbvCount : 5;
uint32_t srvCount : 9;
uint32_t uavCount : 7;
uint32_t samplerCount : 5;
uint32_t reserved : 6;
};
/**
* \brief Maximum used binding numbers for all context state
*/
struct D3D11MaxUsedBindings {
std::array<D3D11MaxUsedStageBindings, 6> stages;
uint32_t vbCount;
uint32_t soCount;
};
} }