1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-18 16:02:01 +00:00

Patch some leaks and only perform copies on valid textures (#37)

This commit is contained in:
riperiperi 2024-08-05 22:58:37 +01:00 committed by Isaac Marovitz
parent 01f41b8b0e
commit fff3a4f8f8
6 changed files with 29 additions and 13 deletions

View file

@ -149,7 +149,7 @@ class CommandBufferEncoder
{
EndCurrentPass();
var descriptor = new MTLBlitPassDescriptor();
using var descriptor = new MTLBlitPassDescriptor();
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
CurrentEncoder = blitCommandEncoder;

View file

@ -176,15 +176,12 @@ namespace Ryujinx.Graphics.Metal
public readonly MTLComputeCommandEncoder CreateComputeCommandEncoder()
{
var descriptor = new MTLComputePassDescriptor();
using var descriptor = new MTLComputePassDescriptor();
var computeCommandEncoder = _pipeline.CommandBuffer.ComputeCommandEncoder(descriptor);
// Mark all state as dirty to ensure it is set on the encoder
SignalDirty(DirtyFlags.ComputeAll);
// Cleanup
descriptor.Dispose();
return computeCommandEncoder;
}

View file

@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Metal
{
ShaderSource shader = _shaders[i];
var compileOptions = new MTLCompileOptions
using var compileOptions = new MTLCompileOptions
{
PreserveInvariance = true,
LanguageVersion = MTLLanguageVersion.Version31,

View file

@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.Metal
MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _);
var samplerState = device.NewSamplerState(new MTLSamplerDescriptor
using var descriptor = new MTLSamplerDescriptor
{
BorderColor = borderColor,
MinFilter = minFilter,
@ -31,7 +31,9 @@ namespace Ryujinx.Graphics.Metal
TAddressMode = info.AddressV.Convert(),
RAddressMode = info.AddressP.Convert(),
SupportArgumentBuffers = true
});
};
var samplerState = device.NewSamplerState(descriptor);
_mtlSamplerState = samplerState;
}

View file

@ -151,6 +151,11 @@ namespace Ryujinx.Graphics.Metal
TextureBase src = this;
TextureBase dst = (TextureBase)destination;
if (!Valid || !dst.Valid)
{
return;
}
var srcImage = GetHandle();
var dstImage = dst.GetHandle();
@ -203,6 +208,11 @@ namespace Ryujinx.Graphics.Metal
TextureBase src = this;
TextureBase dst = (TextureBase)destination;
if (!Valid || !dst.Valid)
{
return;
}
var srcImage = GetHandle();
var dstImage = dst.GetHandle();

View file

@ -2,13 +2,16 @@ using Ryujinx.Graphics.GAL;
using SharpMetal.Metal;
using System;
using System.Runtime.Versioning;
using System.Threading;
namespace Ryujinx.Graphics.Metal
{
[SupportedOSPlatform("macos")]
abstract class TextureBase : IDisposable
{
private bool _disposed;
private int _isValid = 1;
public bool Valid => Volatile.Read(ref _isValid) != 0;
protected readonly Pipeline Pipeline;
protected readonly MTLDevice Device;
@ -35,7 +38,7 @@ namespace Ryujinx.Graphics.Metal
public MTLTexture GetHandle()
{
if (_disposed)
if (_isValid == 0)
{
return new MTLTexture(IntPtr.Zero);
}
@ -50,11 +53,15 @@ namespace Ryujinx.Graphics.Metal
public void Dispose()
{
if (MtlTexture != IntPtr.Zero)
bool wasValid = Interlocked.Exchange(ref _isValid, 0) != 0;
if (wasValid)
{
MtlTexture.Dispose();
if (MtlTexture != IntPtr.Zero)
{
MtlTexture.Dispose();
}
}
_disposed = true;
}
}
}