mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-04 07:24:15 +01:00
[d3d11] Implement fast path for binding full constant buffers
Saves a few CPU cycles in the most common case where we don't have to perform any sort of range check.
This commit is contained in:
parent
8f580efa25
commit
61adaa941d
@ -1657,8 +1657,7 @@ namespace dxvk {
|
|||||||
DxbcProgramType::VertexShader,
|
DxbcProgramType::VertexShader,
|
||||||
m_state.vs.constantBuffers,
|
m_state.vs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers,
|
ppConstantBuffers);
|
||||||
nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1670,7 +1669,7 @@ namespace dxvk {
|
|||||||
const UINT* pNumConstants) {
|
const UINT* pNumConstants) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetConstantBuffers(
|
SetConstantBuffers1(
|
||||||
DxbcProgramType::VertexShader,
|
DxbcProgramType::VertexShader,
|
||||||
m_state.vs.constantBuffers,
|
m_state.vs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
@ -1820,8 +1819,7 @@ namespace dxvk {
|
|||||||
DxbcProgramType::HullShader,
|
DxbcProgramType::HullShader,
|
||||||
m_state.hs.constantBuffers,
|
m_state.hs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers,
|
ppConstantBuffers);
|
||||||
nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1833,7 +1831,7 @@ namespace dxvk {
|
|||||||
const UINT* pNumConstants) {
|
const UINT* pNumConstants) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetConstantBuffers(
|
SetConstantBuffers1(
|
||||||
DxbcProgramType::HullShader,
|
DxbcProgramType::HullShader,
|
||||||
m_state.hs.constantBuffers,
|
m_state.hs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
@ -1969,8 +1967,7 @@ namespace dxvk {
|
|||||||
DxbcProgramType::DomainShader,
|
DxbcProgramType::DomainShader,
|
||||||
m_state.ds.constantBuffers,
|
m_state.ds.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers,
|
ppConstantBuffers);
|
||||||
nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1982,7 +1979,7 @@ namespace dxvk {
|
|||||||
const UINT* pNumConstants) {
|
const UINT* pNumConstants) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetConstantBuffers(
|
SetConstantBuffers1(
|
||||||
DxbcProgramType::DomainShader,
|
DxbcProgramType::DomainShader,
|
||||||
m_state.ds.constantBuffers,
|
m_state.ds.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
@ -2104,8 +2101,7 @@ namespace dxvk {
|
|||||||
DxbcProgramType::GeometryShader,
|
DxbcProgramType::GeometryShader,
|
||||||
m_state.gs.constantBuffers,
|
m_state.gs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers,
|
ppConstantBuffers);
|
||||||
nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2117,7 +2113,7 @@ namespace dxvk {
|
|||||||
const UINT* pNumConstants) {
|
const UINT* pNumConstants) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetConstantBuffers(
|
SetConstantBuffers1(
|
||||||
DxbcProgramType::GeometryShader,
|
DxbcProgramType::GeometryShader,
|
||||||
m_state.gs.constantBuffers,
|
m_state.gs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
@ -2253,8 +2249,7 @@ namespace dxvk {
|
|||||||
DxbcProgramType::PixelShader,
|
DxbcProgramType::PixelShader,
|
||||||
m_state.ps.constantBuffers,
|
m_state.ps.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers,
|
ppConstantBuffers);
|
||||||
nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2266,7 +2261,7 @@ namespace dxvk {
|
|||||||
const UINT* pNumConstants) {
|
const UINT* pNumConstants) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetConstantBuffers(
|
SetConstantBuffers1(
|
||||||
DxbcProgramType::PixelShader,
|
DxbcProgramType::PixelShader,
|
||||||
m_state.ps.constantBuffers,
|
m_state.ps.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
@ -2402,8 +2397,7 @@ namespace dxvk {
|
|||||||
DxbcProgramType::ComputeShader,
|
DxbcProgramType::ComputeShader,
|
||||||
m_state.cs.constantBuffers,
|
m_state.cs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
ppConstantBuffers,
|
ppConstantBuffers);
|
||||||
nullptr, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2415,7 +2409,7 @@ namespace dxvk {
|
|||||||
const UINT* pNumConstants) {
|
const UINT* pNumConstants) {
|
||||||
D3D10DeviceLock lock = LockContext();
|
D3D10DeviceLock lock = LockContext();
|
||||||
|
|
||||||
SetConstantBuffers(
|
SetConstantBuffers1(
|
||||||
DxbcProgramType::ComputeShader,
|
DxbcProgramType::ComputeShader,
|
||||||
m_state.cs.constantBuffers,
|
m_state.cs.constantBuffers,
|
||||||
StartSlot, NumBuffers,
|
StartSlot, NumBuffers,
|
||||||
@ -3357,6 +3351,36 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
void D3D11DeviceContext::SetConstantBuffers(
|
void D3D11DeviceContext::SetConstantBuffers(
|
||||||
|
DxbcProgramType ShaderStage,
|
||||||
|
D3D11ConstantBufferBindings& Bindings,
|
||||||
|
UINT StartSlot,
|
||||||
|
UINT NumBuffers,
|
||||||
|
ID3D11Buffer* const* ppConstantBuffers) {
|
||||||
|
const uint32_t slotId = computeResourceSlotId(
|
||||||
|
ShaderStage, DxbcBindingType::ConstantBuffer,
|
||||||
|
StartSlot);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
||||||
|
auto newBuffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
||||||
|
|
||||||
|
UINT constantBound = newBuffer
|
||||||
|
? newBuffer->Desc()->ByteWidth / 16
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
if (Bindings[StartSlot + i].buffer != newBuffer
|
||||||
|
|| Bindings[StartSlot + i].constantBound != constantBound) {
|
||||||
|
Bindings[StartSlot + i].buffer = newBuffer;
|
||||||
|
Bindings[StartSlot + i].constantOffset = 0;
|
||||||
|
Bindings[StartSlot + i].constantCount = constantBound;
|
||||||
|
Bindings[StartSlot + i].constantBound = constantBound;
|
||||||
|
|
||||||
|
BindConstantBuffer(slotId + i, &Bindings[StartSlot + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void D3D11DeviceContext::SetConstantBuffers1(
|
||||||
DxbcProgramType ShaderStage,
|
DxbcProgramType ShaderStage,
|
||||||
D3D11ConstantBufferBindings& Bindings,
|
D3D11ConstantBufferBindings& Bindings,
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
@ -3378,7 +3402,7 @@ namespace dxvk {
|
|||||||
if (likely(newBuffer != nullptr)) {
|
if (likely(newBuffer != nullptr)) {
|
||||||
constantBound = newBuffer->Desc()->ByteWidth / 16;
|
constantBound = newBuffer->Desc()->ByteWidth / 16;
|
||||||
|
|
||||||
if (pFirstConstant && pNumConstants) {
|
if (likely(pFirstConstant && pNumConstants)) {
|
||||||
constantOffset = pFirstConstant[i];
|
constantOffset = pFirstConstant[i];
|
||||||
constantCount = pNumConstants [i];
|
constantCount = pNumConstants [i];
|
||||||
|
|
||||||
|
@ -735,6 +735,13 @@ namespace dxvk {
|
|||||||
ID3D11Buffer* pBuffer);
|
ID3D11Buffer* pBuffer);
|
||||||
|
|
||||||
void SetConstantBuffers(
|
void SetConstantBuffers(
|
||||||
|
DxbcProgramType ShaderStage,
|
||||||
|
D3D11ConstantBufferBindings& Bindings,
|
||||||
|
UINT StartSlot,
|
||||||
|
UINT NumBuffers,
|
||||||
|
ID3D11Buffer* const* ppConstantBuffers);
|
||||||
|
|
||||||
|
void SetConstantBuffers1(
|
||||||
DxbcProgramType ShaderStage,
|
DxbcProgramType ShaderStage,
|
||||||
D3D11ConstantBufferBindings& Bindings,
|
D3D11ConstantBufferBindings& Bindings,
|
||||||
UINT StartSlot,
|
UINT StartSlot,
|
||||||
|
Loading…
Reference in New Issue
Block a user