mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2024-12-26 18:43:04 +00:00
Patch some leaks and only perform copies on valid textures (#37)
This commit is contained in:
parent
01f41b8b0e
commit
fff3a4f8f8
6 changed files with 29 additions and 13 deletions
|
@ -149,7 +149,7 @@ class CommandBufferEncoder
|
||||||
{
|
{
|
||||||
EndCurrentPass();
|
EndCurrentPass();
|
||||||
|
|
||||||
var descriptor = new MTLBlitPassDescriptor();
|
using var descriptor = new MTLBlitPassDescriptor();
|
||||||
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
|
var blitCommandEncoder = _commandBuffer.BlitCommandEncoder(descriptor);
|
||||||
|
|
||||||
CurrentEncoder = blitCommandEncoder;
|
CurrentEncoder = blitCommandEncoder;
|
||||||
|
|
|
@ -176,15 +176,12 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public readonly MTLComputeCommandEncoder CreateComputeCommandEncoder()
|
public readonly MTLComputeCommandEncoder CreateComputeCommandEncoder()
|
||||||
{
|
{
|
||||||
var descriptor = new MTLComputePassDescriptor();
|
using var descriptor = new MTLComputePassDescriptor();
|
||||||
var computeCommandEncoder = _pipeline.CommandBuffer.ComputeCommandEncoder(descriptor);
|
var computeCommandEncoder = _pipeline.CommandBuffer.ComputeCommandEncoder(descriptor);
|
||||||
|
|
||||||
// Mark all state as dirty to ensure it is set on the encoder
|
// Mark all state as dirty to ensure it is set on the encoder
|
||||||
SignalDirty(DirtyFlags.ComputeAll);
|
SignalDirty(DirtyFlags.ComputeAll);
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
descriptor.Dispose();
|
|
||||||
|
|
||||||
return computeCommandEncoder;
|
return computeCommandEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
ShaderSource shader = _shaders[i];
|
ShaderSource shader = _shaders[i];
|
||||||
|
|
||||||
var compileOptions = new MTLCompileOptions
|
using var compileOptions = new MTLCompileOptions
|
||||||
{
|
{
|
||||||
PreserveInvariance = true,
|
PreserveInvariance = true,
|
||||||
LanguageVersion = MTLLanguageVersion.Version31,
|
LanguageVersion = MTLLanguageVersion.Version31,
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _);
|
MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _);
|
||||||
|
|
||||||
var samplerState = device.NewSamplerState(new MTLSamplerDescriptor
|
using var descriptor = new MTLSamplerDescriptor
|
||||||
{
|
{
|
||||||
BorderColor = borderColor,
|
BorderColor = borderColor,
|
||||||
MinFilter = minFilter,
|
MinFilter = minFilter,
|
||||||
|
@ -31,7 +31,9 @@ namespace Ryujinx.Graphics.Metal
|
||||||
TAddressMode = info.AddressV.Convert(),
|
TAddressMode = info.AddressV.Convert(),
|
||||||
RAddressMode = info.AddressP.Convert(),
|
RAddressMode = info.AddressP.Convert(),
|
||||||
SupportArgumentBuffers = true
|
SupportArgumentBuffers = true
|
||||||
});
|
};
|
||||||
|
|
||||||
|
var samplerState = device.NewSamplerState(descriptor);
|
||||||
|
|
||||||
_mtlSamplerState = samplerState;
|
_mtlSamplerState = samplerState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,11 @@ namespace Ryujinx.Graphics.Metal
|
||||||
TextureBase src = this;
|
TextureBase src = this;
|
||||||
TextureBase dst = (TextureBase)destination;
|
TextureBase dst = (TextureBase)destination;
|
||||||
|
|
||||||
|
if (!Valid || !dst.Valid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var srcImage = GetHandle();
|
var srcImage = GetHandle();
|
||||||
var dstImage = dst.GetHandle();
|
var dstImage = dst.GetHandle();
|
||||||
|
|
||||||
|
@ -203,6 +208,11 @@ namespace Ryujinx.Graphics.Metal
|
||||||
TextureBase src = this;
|
TextureBase src = this;
|
||||||
TextureBase dst = (TextureBase)destination;
|
TextureBase dst = (TextureBase)destination;
|
||||||
|
|
||||||
|
if (!Valid || !dst.Valid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var srcImage = GetHandle();
|
var srcImage = GetHandle();
|
||||||
var dstImage = dst.GetHandle();
|
var dstImage = dst.GetHandle();
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,16 @@ using Ryujinx.Graphics.GAL;
|
||||||
using SharpMetal.Metal;
|
using SharpMetal.Metal;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Metal
|
namespace Ryujinx.Graphics.Metal
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("macos")]
|
[SupportedOSPlatform("macos")]
|
||||||
abstract class TextureBase : IDisposable
|
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 Pipeline Pipeline;
|
||||||
protected readonly MTLDevice Device;
|
protected readonly MTLDevice Device;
|
||||||
|
@ -35,7 +38,7 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public MTLTexture GetHandle()
|
public MTLTexture GetHandle()
|
||||||
{
|
{
|
||||||
if (_disposed)
|
if (_isValid == 0)
|
||||||
{
|
{
|
||||||
return new MTLTexture(IntPtr.Zero);
|
return new MTLTexture(IntPtr.Zero);
|
||||||
}
|
}
|
||||||
|
@ -50,11 +53,15 @@ namespace Ryujinx.Graphics.Metal
|
||||||
|
|
||||||
public void Dispose()
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue