From e8dda2d5ef7ac030897a74f0d7471415b14c9391 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sun, 28 Jul 2024 18:46:58 +0100 Subject: [PATCH] Properly register TextureBuffer usage + Store Auto ref --- .../EncoderStateManager.cs | 10 ++++++++++ src/Ryujinx.Graphics.Metal/TextureBuffer.cs | 16 ++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 4a7c8a00d5..f515293b86 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -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)) diff --git a/src/Ryujinx.Graphics.Metal/TextureBuffer.cs b/src/Ryujinx.Graphics.Metal/TextureBuffer.cs index 388b77e238..8d23bad98e 100644 --- a/src/Ryujinx.Graphics.Metal/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.Metal/TextureBuffer.cs @@ -15,6 +15,7 @@ namespace Ryujinx.Graphics.Metal private int _size; private int _bufferCount; + private Auto _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 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()