Skip to content

Commit

Permalink
[dxvk,d3d11] Fix draw buffer tracking for DrawAuto
Browse files Browse the repository at this point in the history
Not like anybody uses this feature, but we need to both check for
hazards and make sure the SO counter actually gets tracked. Use
the existing draw buffer mechanism for this.
  • Loading branch information
doitsujin committed Feb 16, 2025
1 parent 7765b32 commit 3754e64
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/d3d11/d3d11_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,22 @@ namespace dxvk {
if (!ctrBuf.defined())
return;

EmitCs([=] (DxvkContext* ctx) {
ctx->drawIndirectXfb(ctrBuf,
// We bind the SO counter as an indirect count buffer,
// so reset any tracking we may have been doing here.
m_state.id.reset();

EmitCs([=] (DxvkContext* ctx) mutable {
ctx->bindDrawBuffers(DxvkBufferSlice(),
Forwarder::move(ctrBuf));

ctx->drawIndirectXfb(0u,
vtxBuf.buffer()->getXfbVertexStride(),
vtxBuf.offset());

// Reset draw buffer right away so we don't
// keep the SO counter alive indefinitely
ctx->bindDrawBuffers(DxvkBufferSlice(),
DxvkBufferSlice());
});
}

Expand Down
16 changes: 9 additions & 7 deletions src/dxvk/dxvk_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,17 +1052,19 @@ namespace dxvk {


void DxvkContext::drawIndirectXfb(
const DxvkBufferSlice& counterBuffer,
VkDeviceSize counterOffset,
uint32_t counterDivisor,
uint32_t counterBias) {
if (this->commitGraphicsState<false, false>()) {
auto physSlice = counterBuffer.getSliceHandle();
if (this->commitGraphicsState<false, true>()) {
auto physSlice = m_state.id.cntBuffer.getSliceHandle();

m_cmd->cmdDrawIndirectVertexCount(1, 0,
physSlice.handle,
physSlice.offset,
counterBias,
counterDivisor);
physSlice.handle, physSlice.offset + counterOffset,
counterBias, counterDivisor);

// The count will generally be written from streamout
if (likely(m_state.id.cntBuffer.buffer()->hasGfxStores()))
accessDrawCountBuffer(counterOffset);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/dxvk/dxvk_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,14 @@ namespace dxvk {
uint32_t stride);

/**
* \brief Transform feddback draw call
* \param [in] counterBuffer Xfb counter buffer
* \brief Transform feedback draw call
*
* \param [in] counterOffset Draw count offset
* \param [in] counterDivisor Vertex stride
* \param [in] counterBias Counter bias
*/
void drawIndirectXfb(
const DxvkBufferSlice& counterBuffer,
VkDeviceSize counterOffset,
uint32_t counterDivisor,
uint32_t counterBias);

Expand Down

0 comments on commit 3754e64

Please sign in to comment.