Properly register TextureBuffer usage + Store Auto ref

This commit is contained in:
Isaac Marovitz 2024-07-28 18:46:58 +01:00
parent 479ea9f8e8
commit 3429ee2318
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
2 changed files with 16 additions and 10 deletions

View File

@ -1133,6 +1133,11 @@ namespace Ryujinx.Graphics.Metal
continue;
}
if (storage is TextureBuffer textureBuffer)
{
textureBuffer.RebuildStorage(false);
}
var mtlTexture = storage.GetHandle();
MTLRenderStages renderStages = 0;
@ -1345,6 +1350,11 @@ namespace Ryujinx.Graphics.Metal
continue;
}
if (storage is TextureBuffer textureBuffer)
{
textureBuffer.RebuildStorage(false);
}
var mtlTexture = storage.GetHandle();
if (segment.Stages.HasFlag(ResourceStages.Compute))

View File

@ -15,6 +15,7 @@ namespace Ryujinx.Graphics.Metal
private int _size;
private int _bufferCount;
private Auto<DisposableBuffer> _buffer;
public TextureBuffer(MTLDevice device, MetalRenderer renderer, Pipeline pipeline, TextureCreateInfo info) : base(device, renderer, pipeline, info)
{
@ -32,25 +33,20 @@ namespace Ryujinx.Graphics.Metal
MtlFormat = pixelFormat;
}
private void RebuildStorage()
public void RebuildStorage(bool write)
{
// Find the parent buffer, and try to build a texture from it.
// TODO: texture uses should register read/write usage on the assigned buffer.
Auto<DisposableBuffer> bufferAuto = Renderer.BufferManager.GetBuffer(_bufferHandle, false);
if (MtlTexture.NativePtr != 0)
if (MtlTexture != IntPtr.Zero)
{
MtlTexture.Dispose();
}
if (bufferAuto == null)
if (_buffer == null)
{
MtlTexture = default;
}
else
{
DisposableBuffer buffer = bufferAuto.Get(Pipeline.Cbs, _offset, _size);
DisposableBuffer buffer = _buffer.Get(Pipeline.Cbs, _offset, _size, write);
_descriptor.Width = (uint)(_size / Info.BytesPerPixel);
MtlTexture = buffer.Value.NewTexture(_descriptor, (ulong)_offset, (ulong)_size);
@ -123,7 +119,7 @@ namespace Ryujinx.Graphics.Metal
_size = buffer.Size;
_bufferCount = Renderer.BufferManager.BufferCount;
RebuildStorage();
_buffer = Renderer.BufferManager.GetBuffer(_bufferHandle, false);
}
public override void Release()