1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 19:54:19 +01:00

[dxvk] Use BindConstantBufferRange for SetConstantBuffers1 if possible

Reduces ref counting overhead in the few games that use this.
This commit is contained in:
Philip Rebohle 2022-07-14 15:10:48 +02:00
parent ce3eae59a9
commit aef2eb14df
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 39 additions and 7 deletions

View File

@ -3291,7 +3291,7 @@ namespace dxvk {
UINT Length) {
EmitCs([
cSlotId = Slot,
cBufferSlice = Length ? pBuffer->GetBufferSlice(16 * Offset, 16 * Length) : DxvkBufferSlice()
cBufferSlice = pBuffer ? pBuffer->GetBufferSlice(16 * Offset, 16 * Length) : DxvkBufferSlice()
] (DxvkContext* ctx) {
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
ctx->bindResourceBuffer(stage, cSlotId, cBufferSlice);
@ -3299,6 +3299,22 @@ namespace dxvk {
}
template<DxbcProgramType ShaderStage>
void D3D11DeviceContext::BindConstantBufferRange(
UINT Slot,
UINT Offset,
UINT Length) {
EmitCs([
cSlotId = Slot,
cOffset = 16 * Offset,
cLength = 16 * Length
] (DxvkContext* ctx) {
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
ctx->bindResourceBufferRange(stage, cSlotId, cOffset, cLength);
});
}
template<DxbcProgramType ShaderStage>
void D3D11DeviceContext::BindSampler(
UINT Slot,
@ -3959,20 +3975,30 @@ namespace dxvk {
constantBound = 0;
}
// Do a full rebind if either the buffer changes, or if either the current or
// the previous number of bound constants were zero, since we're binding a null
// buffer to the backend in that case.
bool needsUpdate = Bindings[StartSlot + i].buffer != newBuffer;
if (needsUpdate)
Bindings[StartSlot + i].buffer = newBuffer;
if (!needsUpdate) {
needsUpdate |= !constantBound;
needsUpdate |= !Bindings[StartSlot + i].constantBound;
}
needsUpdate |= Bindings[StartSlot + i].constantOffset != constantOffset
|| Bindings[StartSlot + i].constantCount != constantCount;
if (needsUpdate) {
Bindings[StartSlot + i].buffer = newBuffer;
Bindings[StartSlot + i].constantOffset = constantOffset;
Bindings[StartSlot + i].constantCount = constantCount;
Bindings[StartSlot + i].constantBound = constantBound;
BindConstantBuffer<ShaderStage>(slotId + i, newBuffer, constantOffset, constantBound);
} else if (Bindings[StartSlot + i].constantOffset != constantOffset
|| Bindings[StartSlot + i].constantCount != constantCount) {
Bindings[StartSlot + i].constantOffset = constantOffset;
Bindings[StartSlot + i].constantCount = constantCount;
Bindings[StartSlot + i].constantBound = constantBound;
BindConstantBufferRange<ShaderStage>(slotId + i, constantOffset, constantBound);
}
}
}

View File

@ -760,6 +760,12 @@ namespace dxvk {
UINT Offset,
UINT Length);
template<DxbcProgramType ShaderStage>
void BindConstantBufferRange(
UINT Slot,
UINT Offset,
UINT Length);
template<DxbcProgramType ShaderStage>
void BindSampler(
UINT Slot,