1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[d3d11] Change how resourece binding treats null resources

This commit is contained in:
Philip Rebohle 2022-08-07 15:33:39 +02:00
parent 897e7816f0
commit 35dde3e1b9
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -3193,7 +3193,7 @@ namespace dxvk {
D3D11Buffer* pBuffer, D3D11Buffer* pBuffer,
UINT Offset, UINT Offset,
UINT Stride) { UINT Stride) {
if (likely(pBuffer != nullptr)) { if (pBuffer) {
EmitCs([ EmitCs([
cSlotId = Slot, cSlotId = Slot,
cBufferSlice = pBuffer->GetBufferSlice(Offset), cBufferSlice = pBuffer->GetBufferSlice(Offset),
@ -3222,14 +3222,22 @@ namespace dxvk {
? VK_INDEX_TYPE_UINT16 ? VK_INDEX_TYPE_UINT16
: VK_INDEX_TYPE_UINT32; : VK_INDEX_TYPE_UINT32;
EmitCs([ if (pBuffer) {
cBufferSlice = pBuffer != nullptr ? pBuffer->GetBufferSlice(Offset) : DxvkBufferSlice(), EmitCs([
cIndexType = indexType cBufferSlice = pBuffer->GetBufferSlice(Offset),
] (DxvkContext* ctx) mutable { cIndexType = indexType
ctx->bindIndexBuffer( ] (DxvkContext* ctx) mutable {
Forwarder::move(cBufferSlice), ctx->bindIndexBuffer(
cIndexType); Forwarder::move(cBufferSlice),
}); cIndexType);
});
} else {
EmitCs([
cIndexType = indexType
] (DxvkContext* ctx) {
ctx->bindIndexBuffer(DxvkBufferSlice(), cIndexType);
});
}
} }
@ -3238,32 +3246,34 @@ namespace dxvk {
UINT Slot, UINT Slot,
D3D11Buffer* pBuffer, D3D11Buffer* pBuffer,
UINT Offset) { UINT Offset) {
DxvkBufferSlice bufferSlice; if (pBuffer) {
DxvkBufferSlice counterSlice; EmitCs([
cSlotId = Slot,
cOffset = Offset,
cBufferSlice = pBuffer->GetBufferSlice(),
cCounterSlice = pBuffer->GetSOCounter()
] (DxvkContext* ctx) mutable {
if (cCounterSlice.defined() && cOffset != ~0u) {
ctx->updateBuffer(
cCounterSlice.buffer(),
cCounterSlice.offset(),
sizeof(cOffset),
&cOffset);
}
if (pBuffer != nullptr) { ctx->bindXfbBuffer(cSlotId,
bufferSlice = pBuffer->GetBufferSlice(); Forwarder::move(cBufferSlice),
counterSlice = pBuffer->GetSOCounter(); Forwarder::move(cCounterSlice));
});
} else {
EmitCs([
cSlotId = Slot
] (DxvkContext* ctx) {
ctx->bindXfbBuffer(cSlotId,
DxvkBufferSlice(),
DxvkBufferSlice());
});
} }
EmitCs([
cSlotId = Slot,
cOffset = Offset,
cBufferSlice = bufferSlice,
cCounterSlice = counterSlice
] (DxvkContext* ctx) mutable {
if (cCounterSlice.defined() && cOffset != ~0u) {
ctx->updateBuffer(
cCounterSlice.buffer(),
cCounterSlice.offset(),
sizeof(cOffset),
&cOffset);
}
ctx->bindXfbBuffer(cSlotId,
Forwarder::move(cBufferSlice),
Forwarder::move(cCounterSlice));
});
} }
@ -3274,14 +3284,23 @@ namespace dxvk {
D3D11Buffer* pBuffer, D3D11Buffer* pBuffer,
UINT Offset, UINT Offset,
UINT Length) { UINT Length) {
EmitCs([ if (pBuffer) {
cSlotId = Slot, EmitCs([
cBufferSlice = pBuffer ? pBuffer->GetBufferSlice(16 * Offset, 16 * Length) : DxvkBufferSlice() cSlotId = Slot,
] (DxvkContext* ctx) mutable { cBufferSlice = pBuffer->GetBufferSlice(16 * Offset, 16 * Length)
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); ] (DxvkContext* ctx) mutable {
ctx->bindResourceBuffer(stage, cSlotId, VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
Forwarder::move(cBufferSlice)); ctx->bindResourceBuffer(stage, cSlotId,
}); Forwarder::move(cBufferSlice));
});
} else {
EmitCs([
cSlotId = Slot
] (DxvkContext* ctx) {
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
ctx->bindResourceBuffer(stage, cSlotId, DxvkBufferSlice());
});
}
} }
@ -3307,14 +3326,23 @@ namespace dxvk {
void D3D11CommonContext<ContextType>::BindSampler( void D3D11CommonContext<ContextType>::BindSampler(
UINT Slot, UINT Slot,
D3D11SamplerState* pSampler) { D3D11SamplerState* pSampler) {
EmitCs([ if (pSampler) {
cSlotId = Slot, EmitCs([
cSampler = pSampler != nullptr ? pSampler->GetDXVKSampler() : nullptr cSlotId = Slot,
] (DxvkContext* ctx) mutable { cSampler = pSampler->GetDXVKSampler()
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); ] (DxvkContext* ctx) mutable {
ctx->bindResourceSampler(stage, cSlotId, VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
Forwarder::move(cSampler)); ctx->bindResourceSampler(stage, cSlotId,
}); Forwarder::move(cSampler));
});
} else {
EmitCs([
cSlotId = Slot
] (DxvkContext* ctx) {
VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
ctx->bindResourceSampler(stage, cSlotId, nullptr);
});
}
} }
@ -4297,17 +4325,8 @@ namespace dxvk {
constantBound = 0; constantBound = 0;
} }
// Do a full rebind if either the buffer changes, or if either the current or // Do a full rebind if either the buffer changes
// the previous number of bound constants were zero, since we're binding a null if (bindings.buffers[StartSlot + i].buffer != newBuffer) {
// buffer to the backend in that case.
bool needsUpdate = bindings.buffers[StartSlot + i].buffer != newBuffer;
if (!needsUpdate) {
needsUpdate |= !constantBound;
needsUpdate |= !bindings.buffers[StartSlot + i].constantBound;
}
if (needsUpdate) {
bindings.buffers[StartSlot + i].buffer = newBuffer; bindings.buffers[StartSlot + i].buffer = newBuffer;
bindings.buffers[StartSlot + i].constantOffset = constantOffset; bindings.buffers[StartSlot + i].constantOffset = constantOffset;
bindings.buffers[StartSlot + i].constantCount = constantCount; bindings.buffers[StartSlot + i].constantCount = constantCount;