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

[d3d11] Use resource cookies for draw buffer tracking

Avoids keeping draw buffers alive when the app stops using indirect
draws. Unlikely to have caused issues in practice, but draw buffers
are not part of the API state to begin with.
This commit is contained in:
Philip Rebohle 2025-02-16 14:03:12 +01:00
parent eaa2c9f513
commit acfe3cb0e3
3 changed files with 22 additions and 13 deletions

View File

@ -4644,10 +4644,6 @@ namespace dxvk {
ApplyRasterizerSampleCount();
ApplyViewportState();
BindDrawBuffers(
m_state.id.argBuffer.ptr(),
m_state.id.cntBuffer.ptr());
BindIndexBuffer(
m_state.ia.indexBuffer.buffer.ptr(),
m_state.ia.indexBuffer.offset,
@ -4686,6 +4682,11 @@ namespace dxvk {
RestoreSamplers<DxbcProgramType::GeometryShader>();
RestoreSamplers<DxbcProgramType::PixelShader>();
RestoreSamplers<DxbcProgramType::ComputeShader>();
// Draw buffer bindings aren't persistent at the API level, and
// we can't meaningfully track them. Just reset this state here
// and reapply on the next indirect draw.
SetDrawBuffers(nullptr, nullptr);
}
@ -5012,10 +5013,13 @@ namespace dxvk {
auto argBuffer = static_cast<D3D11Buffer*>(pBufferForArgs);
auto cntBuffer = static_cast<D3D11Buffer*>(pBufferForCount);
if (m_state.id.argBuffer != argBuffer
|| m_state.id.cntBuffer != cntBuffer) {
m_state.id.argBuffer = argBuffer;
m_state.id.cntBuffer = cntBuffer;
auto argBufferCookie = argBuffer ? argBuffer->GetCookie() : 0u;
auto cntBufferCookie = cntBuffer ? cntBuffer->GetCookie() : 0u;
if (m_state.id.argBufferCookie != argBufferCookie
|| m_state.id.cntBufferCookie != cntBufferCookie) {
m_state.id.argBufferCookie = argBufferCookie;
m_state.id.cntBufferCookie = cntBufferCookie;
BindDrawBuffers(argBuffer, cntBuffer);
}

View File

@ -865,6 +865,11 @@ namespace dxvk {
Rc<DxvkLatencyTracker> LatencyTracker) {
D3D10DeviceLock lock = LockContext();
// Don't keep draw buffers alive indefinitely. This cannot be
// done in ExecuteFlush because command recording itself might
// flush, so no state changes are allowed to happen there.
SetDrawBuffers(nullptr, nullptr);
EmitCs<false>([
cTracker = std::move(LatencyTracker)
] (DxvkContext* ctx) {

View File

@ -232,12 +232,12 @@ namespace dxvk {
* argument and draw count buffer.
*/
struct D3D11ContextStateID {
Com<D3D11Buffer, false> argBuffer = nullptr;
Com<D3D11Buffer, false> cntBuffer = nullptr;
uint64_t argBufferCookie = 0u;
uint64_t cntBufferCookie = 0u;
void reset() {
argBuffer = nullptr;
cntBuffer = nullptr;
argBufferCookie = 0u;
cntBufferCookie = 0u;
}
};