1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-20 06:52:06 +00:00

Fix trying to reserve size 0 in staging buffer

This commit is contained in:
Isaac Marovitz 2024-07-02 17:49:19 +01:00 committed by Isaac Marovitz
parent 9f0a468f55
commit 8e8dcf0d7f

View file

@ -984,8 +984,18 @@ namespace Ryujinx.Graphics.Metal
return; return;
} }
var vertArgBuffer = _bufferManager.ReserveOrCreate(_pipeline.Cbs, program.ArgumentBufferSizes[setIndex] * sizeof(ulong)); ScopedTemporaryBuffer vertArgBuffer = default;
var fragArgBuffer = _bufferManager.ReserveOrCreate(_pipeline.Cbs, program.FragArgumentBufferSizes[setIndex] * sizeof(ulong)); ScopedTemporaryBuffer fragArgBuffer = default;
if (program.ArgumentBufferSizes[setIndex] > 0)
{
vertArgBuffer = _bufferManager.ReserveOrCreate(_pipeline.Cbs, program.ArgumentBufferSizes[setIndex] * sizeof(ulong));
}
if (program.FragArgumentBufferSizes[setIndex] > 0)
{
fragArgBuffer = _bufferManager.ReserveOrCreate(_pipeline.Cbs, program.FragArgumentBufferSizes[setIndex] * sizeof(ulong));
}
Span<ulong> vertResourceIds = stackalloc ulong[program.ArgumentBufferSizes[setIndex]]; Span<ulong> vertResourceIds = stackalloc ulong[program.ArgumentBufferSizes[setIndex]];
Span<ulong> fragResourceIds = stackalloc ulong[program.FragArgumentBufferSizes[setIndex]]; Span<ulong> fragResourceIds = stackalloc ulong[program.FragArgumentBufferSizes[setIndex]];
@ -1169,15 +1179,20 @@ namespace Ryujinx.Graphics.Metal
} }
} }
if (program.ArgumentBufferSizes[setIndex] > 0)
{
vertArgBuffer.Holder.SetDataUnchecked(vertArgBuffer.Offset, MemoryMarshal.AsBytes(vertResourceIds)); vertArgBuffer.Holder.SetDataUnchecked(vertArgBuffer.Offset, MemoryMarshal.AsBytes(vertResourceIds));
fragArgBuffer.Holder.SetDataUnchecked(fragArgBuffer.Offset, MemoryMarshal.AsBytes(fragResourceIds));
var mtlVertArgBuffer = _bufferManager.GetBuffer(vertArgBuffer.Handle, false).Get(_pipeline.Cbs).Value; var mtlVertArgBuffer = _bufferManager.GetBuffer(vertArgBuffer.Handle, false).Get(_pipeline.Cbs).Value;
var mtlFragArgBuffer = _bufferManager.GetBuffer(fragArgBuffer.Handle, false).Get(_pipeline.Cbs).Value;
renderCommandEncoder.SetVertexBuffer(mtlVertArgBuffer, (uint)vertArgBuffer.Range.Offset, SetIndexToBindingIndex(setIndex)); renderCommandEncoder.SetVertexBuffer(mtlVertArgBuffer, (uint)vertArgBuffer.Range.Offset, SetIndexToBindingIndex(setIndex));
}
if (program.FragArgumentBufferSizes[setIndex] > 0)
{
fragArgBuffer.Holder.SetDataUnchecked(fragArgBuffer.Offset, MemoryMarshal.AsBytes(fragResourceIds));
var mtlFragArgBuffer = _bufferManager.GetBuffer(fragArgBuffer.Handle, false).Get(_pipeline.Cbs).Value;
renderCommandEncoder.SetFragmentBuffer(mtlFragArgBuffer, (uint)fragArgBuffer.Range.Offset, SetIndexToBindingIndex(setIndex)); renderCommandEncoder.SetFragmentBuffer(mtlFragArgBuffer, (uint)fragArgBuffer.Range.Offset, SetIndexToBindingIndex(setIndex));
} }
}
private void UpdateAndBind(MTLComputeCommandEncoder computeCommandEncoder, Program program, int setIndex) private void UpdateAndBind(MTLComputeCommandEncoder computeCommandEncoder, Program program, int setIndex)
{ {
@ -1188,7 +1203,13 @@ namespace Ryujinx.Graphics.Metal
return; return;
} }
var argBuffer = _bufferManager.ReserveOrCreate(_pipeline.Cbs, program.ArgumentBufferSizes[setIndex] * sizeof(ulong)); ScopedTemporaryBuffer argBuffer = default;
if (program.ArgumentBufferSizes[setIndex] > 0)
{
argBuffer = _bufferManager.ReserveOrCreate(_pipeline.Cbs, program.ArgumentBufferSizes[setIndex] * sizeof(ulong));
}
Span<ulong> resourceIds = stackalloc ulong[program.ArgumentBufferSizes[setIndex]]; Span<ulong> resourceIds = stackalloc ulong[program.ArgumentBufferSizes[setIndex]];
var resourceIdIndex = 0; var resourceIdIndex = 0;
@ -1228,7 +1249,7 @@ namespace Ryujinx.Graphics.Metal
mtlBuffer = autoBuffer.Get(_pipeline.Cbs).Value; mtlBuffer = autoBuffer.Get(_pipeline.Cbs).Value;
} }
if (segment.Stages.HasFlag(ResourceStages.Compute)) if ((segment.Stages & ResourceStages.Compute) != 0)
{ {
computeCommandEncoder.UseResource(new MTLResource(mtlBuffer.NativePtr), MTLResourceUsage.Read); computeCommandEncoder.UseResource(new MTLResource(mtlBuffer.NativePtr), MTLResourceUsage.Read);
resourceIds[resourceIdIndex] = mtlBuffer.GpuAddress + (ulong)offset; resourceIds[resourceIdIndex] = mtlBuffer.GpuAddress + (ulong)offset;
@ -1265,7 +1286,7 @@ namespace Ryujinx.Graphics.Metal
mtlBuffer = autoBuffer.Get(_pipeline.Cbs).Value; mtlBuffer = autoBuffer.Get(_pipeline.Cbs).Value;
} }
if (segment.Stages.HasFlag(ResourceStages.Compute)) if ((segment.Stages & ResourceStages.Compute) != 0)
{ {
computeCommandEncoder.UseResource(new MTLResource(mtlBuffer.NativePtr), MTLResourceUsage.Read | MTLResourceUsage.Write); computeCommandEncoder.UseResource(new MTLResource(mtlBuffer.NativePtr), MTLResourceUsage.Read | MTLResourceUsage.Write);
resourceIds[resourceIdIndex] = mtlBuffer.GpuAddress + (ulong)offset; resourceIds[resourceIdIndex] = mtlBuffer.GpuAddress + (ulong)offset;
@ -1323,12 +1344,13 @@ namespace Ryujinx.Graphics.Metal
} }
} }
if (program.ArgumentBufferSizes[setIndex] > 0)
{
argBuffer.Holder.SetDataUnchecked(argBuffer.Offset, MemoryMarshal.AsBytes(resourceIds)); argBuffer.Holder.SetDataUnchecked(argBuffer.Offset, MemoryMarshal.AsBytes(resourceIds));
var mtlArgBuffer = _bufferManager.GetBuffer(argBuffer.Handle, false).Get(_pipeline.Cbs).Value; var mtlArgBuffer = _bufferManager.GetBuffer(argBuffer.Handle, false).Get(_pipeline.Cbs).Value;
computeCommandEncoder.SetBuffer(mtlArgBuffer, (uint)argBuffer.Range.Offset, SetIndexToBindingIndex(setIndex)); computeCommandEncoder.SetBuffer(mtlArgBuffer, (uint)argBuffer.Range.Offset, SetIndexToBindingIndex(setIndex));
} }
}
private uint SetIndexToBindingIndex(int setIndex) private uint SetIndexToBindingIndex(int setIndex)
{ {