mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-02 04:29:14 +01:00
[d3d11] Clamp and validate bound constant buffer range
SetConstantBuffers will only bind the first 65536 bytes of any buffer passed to it if it is larger. This can be seen even when querying the bound range via GetConstantBuffers1. SetConstantBuffers1 does not have any effect if the bound range is invalid.
This commit is contained in:
parent
81632b91bb
commit
4801fbe098
@ -3497,18 +3497,6 @@ namespace dxvk {
|
||||
|
||||
|
||||
void D3D11DeviceContext::BindConstantBuffer(
|
||||
UINT Slot,
|
||||
D3D11Buffer* pBuffer) {
|
||||
EmitCs([
|
||||
cSlotId = Slot,
|
||||
cBufferSlice = pBuffer ? pBuffer->GetBufferSlice() : DxvkBufferSlice()
|
||||
] (DxvkContext* ctx) {
|
||||
ctx->bindResourceBuffer(cSlotId, cBufferSlice);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::BindConstantBuffer1(
|
||||
UINT Slot,
|
||||
D3D11Buffer* pBuffer,
|
||||
UINT Offset,
|
||||
@ -3628,19 +3616,19 @@ namespace dxvk {
|
||||
for (uint32_t i = 0; i < NumBuffers; i++) {
|
||||
auto newBuffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
||||
|
||||
UINT constantBound = 0;
|
||||
UINT constantCount = 0;
|
||||
|
||||
if (likely(newBuffer != nullptr))
|
||||
constantBound = newBuffer->Desc()->ByteWidth / 16;
|
||||
constantCount = std::min(newBuffer->Desc()->ByteWidth / 16, UINT(D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT));
|
||||
|
||||
if (Bindings[StartSlot + i].buffer != newBuffer
|
||||
|| Bindings[StartSlot + i].constantBound != constantBound) {
|
||||
|| Bindings[StartSlot + i].constantCount != constantCount) {
|
||||
Bindings[StartSlot + i].buffer = newBuffer;
|
||||
Bindings[StartSlot + i].constantOffset = 0;
|
||||
Bindings[StartSlot + i].constantCount = constantBound;
|
||||
Bindings[StartSlot + i].constantBound = constantBound;
|
||||
Bindings[StartSlot + i].constantCount = constantCount;
|
||||
Bindings[StartSlot + i].constantBound = constantCount;
|
||||
|
||||
BindConstantBuffer(slotId + i, newBuffer);
|
||||
BindConstantBuffer(slotId + i, newBuffer, 0, constantCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3664,12 +3652,15 @@ namespace dxvk {
|
||||
UINT constantBound;
|
||||
|
||||
if (likely(newBuffer != nullptr)) {
|
||||
constantBound = newBuffer->Desc()->ByteWidth / 16;
|
||||
constantBound = std::min(newBuffer->Desc()->ByteWidth / 16, UINT(D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT));
|
||||
|
||||
if (likely(pFirstConstant && pNumConstants)) {
|
||||
constantOffset = pFirstConstant[i];
|
||||
constantCount = pNumConstants [i];
|
||||
|
||||
if (unlikely(constantCount > D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT))
|
||||
continue;
|
||||
|
||||
constantBound = (constantOffset + constantCount > constantBound)
|
||||
? constantBound - std::min(constantOffset, constantBound)
|
||||
: constantCount;
|
||||
@ -3696,7 +3687,7 @@ namespace dxvk {
|
||||
Bindings[StartSlot + i].constantCount = constantCount;
|
||||
Bindings[StartSlot + i].constantBound = constantBound;
|
||||
|
||||
BindConstantBuffer1(slotId + i, newBuffer, constantOffset, constantBound);
|
||||
BindConstantBuffer(slotId + i, newBuffer, constantOffset, constantBound);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3937,7 +3928,7 @@ namespace dxvk {
|
||||
uint32_t slotId = computeConstantBufferBinding(Stage, 0);
|
||||
|
||||
for (uint32_t i = 0; i < Bindings.size(); i++) {
|
||||
BindConstantBuffer1(slotId + i, Bindings[i].buffer.ptr(),
|
||||
BindConstantBuffer(slotId + i, Bindings[i].buffer.ptr(),
|
||||
Bindings[i].constantOffset, Bindings[i].constantBound);
|
||||
}
|
||||
}
|
||||
|
@ -763,10 +763,6 @@ namespace dxvk {
|
||||
UINT Offset);
|
||||
|
||||
void BindConstantBuffer(
|
||||
UINT Slot,
|
||||
D3D11Buffer* pBuffer);
|
||||
|
||||
void BindConstantBuffer1(
|
||||
UINT Slot,
|
||||
D3D11Buffer* pBuffer,
|
||||
UINT Offset,
|
||||
|
Loading…
x
Reference in New Issue
Block a user