Skip to content

Commit

Permalink
Merge pull request #530 from opticfluorine/vk-uniform-barrier
Browse files Browse the repository at this point in the history
Add UniformRead to Vulkan memory barriers for uniform buffers
  • Loading branch information
smoogipoo committed Mar 30, 2024
2 parents 8ef576a + c0135af commit 02d2b64
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Veldrid/Vk/VkCommandList.cs
Expand Up @@ -755,10 +755,14 @@ private protected override void UpdateBufferCore(DeviceBuffer buffer, uint buffe

vkCmdCopyBuffer(_cb, srcVkBuffer.DeviceBuffer, dstVkBuffer.DeviceBuffer, 1, ref region);

bool needToProtectUniform = destination.Usage.HasFlag(BufferUsage.UniformBuffer);

VkMemoryBarrier barrier;
barrier.sType = VkStructureType.MemoryBarrier;
barrier.srcAccessMask = VkAccessFlags.TransferWrite;
barrier.dstAccessMask = VkAccessFlags.VertexAttributeRead;
barrier.dstAccessMask = needToProtectUniform
? VkAccessFlags.VertexAttributeRead | VkAccessFlags.UniformRead
: VkAccessFlags.VertexAttributeRead;
barrier.pNext = null;
vkCmdPipelineBarrier(
_cb,
Expand Down Expand Up @@ -966,7 +970,7 @@ private protected override void UpdateBufferCore(DeviceBuffer buffer, uint buffe
VkImageAspectFlags aspect = (srcVkTexture.Usage & TextureUsage.DepthStencil) != 0
? VkImageAspectFlags.Depth
: VkImageAspectFlags.Color;

Util.GetMipDimensions(dstVkTexture, dstMipLevel, out uint mipWidth, out uint mipHeight, out uint mipDepth);
uint blockSize = FormatHelpers.IsCompressedFormat(srcVkTexture.Format) ? 4u : 1u;
uint bufferRowLength = Math.Max(mipWidth, blockSize);
Expand Down

0 comments on commit 02d2b64

Please sign in to comment.