Skip to content

Commit

Permalink
Simplify alignment passing for now
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Jan 24, 2024
1 parent 1b17ecc commit f2b895f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Vulkan/BufferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ public BufferHandle CreateWithHandle(
return Unsafe.As<ulong, BufferHandle>(ref handle64);
}

public ScopedTemporaryBuffer ReserveOrCreate(VulkanRenderer gd, CommandBufferScoped cbs, int size, out BufferHolder holder, int alignment = -1)
public ScopedTemporaryBuffer ReserveOrCreate(VulkanRenderer gd, CommandBufferScoped cbs, int size, out BufferHolder holder)
{
StagingBufferReserved? result = StagingBuffer.TryReserveData(cbs, size, alignment);
StagingBufferReserved? result = StagingBuffer.TryReserveData(cbs, size);

if (result.HasValue)
{
Expand All @@ -284,9 +284,9 @@ public ScopedTemporaryBuffer ReserveOrCreate(VulkanRenderer gd, CommandBufferSco
}
}

public ScopedTemporaryBuffer ReserveOrCreate(VulkanRenderer gd, CommandBufferScoped cbs, int size, int alignment = -1)
public ScopedTemporaryBuffer ReserveOrCreate(VulkanRenderer gd, CommandBufferScoped cbs, int size)
{
return ReserveOrCreate(gd, cbs, size, out _, alignment);
return ReserveOrCreate(gd, cbs, size, out _);
}

public unsafe MemoryRequirements GetHostImportedUsageRequirements(VulkanRenderer gd)
Expand Down
21 changes: 14 additions & 7 deletions src/Ryujinx.Graphics.Vulkan/StagingBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,15 @@ private int GetContiguousFreeSize(int alignment)
/// </summary>
/// <param name="cbs">Command buffer to reserve the data on</param>
/// <param name="size">The minimum size the reserved data requires</param>
/// <param name="alignment">The required alignment for the buffer offset. -1 uses the most permissive alignment</param>
/// <param name="alignment">The required alignment for the buffer offset</param>
/// <returns>The reserved range of the staging buffer</returns>
public unsafe StagingBufferReserved? TryReserveData(CommandBufferScoped cbs, int size, int alignment = -1)
public unsafe StagingBufferReserved? TryReserveData(CommandBufferScoped cbs, int size, int alignment)
{
if (size > BufferSize)
{
return null;
}

if (alignment == -1)
{
alignment = _resourceAlignment;
}

// Temporary reserved data cannot be fragmented.

if (GetContiguousFreeSize(alignment) < size)
Expand All @@ -233,6 +228,18 @@ private int GetContiguousFreeSize(int alignment)
return ReserveDataImpl(cbs, size, alignment);
}

/// <summary>
/// Reserve a range on the staging buffer for the current command buffer and upload data to it.
/// Uses the most permissive byte alignment.
/// </summary>
/// <param name="cbs">Command buffer to reserve the data on</param>
/// <param name="size">The minimum size the reserved data requires</param>
/// <returns>The reserved range of the staging buffer</returns>
public unsafe StagingBufferReserved? TryReserveData(CommandBufferScoped cbs, int size)
{
return TryReserveData(cbs, size, _resourceAlignment);
}

private bool WaitFreeCompleted(CommandBufferPool cbp)
{
if (_pendingCopies.TryPeek(out var pc))
Expand Down

0 comments on commit f2b895f

Please sign in to comment.