Skip to content

Commit

Permalink
Fixed rendering bug caused by discard.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomspilman committed Sep 18, 2024
1 parent 3489e6e commit 92c945f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions native/monogame/vulkan/MGG_Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3353,8 +3353,45 @@ void MGG_Buffer_SetData(MGG_GraphicsDevice* device, MGG_Buffer*& buffer, mgint o
// copying over data still in use. See NX.

if (discard)
{
auto last = buffer;

buffer = MGVK_BufferDiscard(device, buffer);

// Fix any active mapping of the buffer that
// was just discarded for another.

switch (buffer->type)
{
case MGBufferType::Constant:
for (int i=0; i < (int)MGShaderStage::Count; i++)
{
if (device->uniforms[i] == last)
{
device->uniforms[i] = buffer;
device->uniformsDirty |= 1 << (int)i;
}
}
break;

case MGBufferType::Vertex:
for (int i = 0; i < 8; i++)
{
if (device->vertexBuffers[i] == last)
{
device->vertexBuffers[i] = buffer;
device->vertexBuffersDirty |= 1 << i;
}
}
break;

case MGBufferType::Index:
if (device->indexBuffer == last)
device->indexBuffer = buffer;
break;
}
}

// Do the copy and flush.
MGVK_BufferCopyAndFlush(device, buffer, offset, data, length);
}
Expand Down

0 comments on commit 92c945f

Please sign in to comment.