misc: chore: Fix object creation in Metal

This commit is contained in:
Evan Husted 2025-01-26 15:26:11 -06:00
parent e859bd5aa2
commit d95f724d17
15 changed files with 28 additions and 28 deletions

View File

@ -302,7 +302,7 @@ namespace Ryujinx.Graphics.Metal
return null; return null;
} }
I8ToI16CacheKey key = new I8ToI16CacheKey(_renderer); I8ToI16CacheKey key = new(_renderer);
if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out BufferHolder holder)) if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out BufferHolder holder))
{ {
@ -325,7 +325,7 @@ namespace Ryujinx.Graphics.Metal
return null; return null;
} }
TopologyConversionCacheKey key = new TopologyConversionCacheKey(_renderer, pattern, indexSize); TopologyConversionCacheKey key = new(_renderer, pattern, indexSize);
if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out BufferHolder holder)) if (!_cachedConvertedBuffers.TryGetValue(offset, size, key, out BufferHolder holder))
{ {

View File

@ -74,7 +74,7 @@ namespace Ryujinx.Graphics.Metal
return BufferHandle.Null; return BufferHandle.Null;
} }
BufferHolder holder = new BufferHolder(_renderer, _pipeline, buffer, size); BufferHolder holder = new(_renderer, _pipeline, buffer, size);
BufferCount++; BufferCount++;

View File

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

View File

@ -25,7 +25,7 @@ namespace Ryujinx.Graphics.Metal
ref StencilUid frontUid = ref descriptor.FrontFace; ref StencilUid frontUid = ref descriptor.FrontFace;
using MTLStencilDescriptor frontFaceStencil = new MTLStencilDescriptor using MTLStencilDescriptor frontFaceStencil = new()
{ {
StencilFailureOperation = frontUid.StencilFailureOperation, StencilFailureOperation = frontUid.StencilFailureOperation,
DepthFailureOperation = frontUid.DepthFailureOperation, DepthFailureOperation = frontUid.DepthFailureOperation,
@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.Metal
ref StencilUid backUid = ref descriptor.BackFace; ref StencilUid backUid = ref descriptor.BackFace;
using MTLStencilDescriptor backFaceStencil = new MTLStencilDescriptor using MTLStencilDescriptor backFaceStencil = new()
{ {
StencilFailureOperation = backUid.StencilFailureOperation, StencilFailureOperation = backUid.StencilFailureOperation,
DepthFailureOperation = backUid.DepthFailureOperation, DepthFailureOperation = backUid.DepthFailureOperation,
@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Metal
WriteMask = backUid.WriteMask WriteMask = backUid.WriteMask
}; };
MTLDepthStencilDescriptor mtlDescriptor = new MTLDepthStencilDescriptor MTLDepthStencilDescriptor mtlDescriptor = new()
{ {
DepthCompareFunction = descriptor.DepthCompareFunction, DepthCompareFunction = descriptor.DepthCompareFunction,
DepthWriteEnabled = descriptor.DepthWriteEnabled DepthWriteEnabled = descriptor.DepthWriteEnabled

View File

@ -165,7 +165,7 @@ namespace Ryujinx.Graphics.Metal
{ {
// Inherit render target related information without causing a render encoder split. // Inherit render target related information without causing a render encoder split.
RenderTargetCopy oldState = new RenderTargetCopy RenderTargetCopy oldState = new()
{ {
Scissors = other.Scissors, Scissors = other.Scissors,
RenderTargets = other.RenderTargets, RenderTargets = other.RenderTargets,

View File

@ -125,7 +125,7 @@ namespace Ryujinx.Graphics.Metal
public readonly MTLRenderCommandEncoder CreateRenderCommandEncoder() public readonly MTLRenderCommandEncoder CreateRenderCommandEncoder()
{ {
// Initialise Pass & State // Initialise Pass & State
using MTLRenderPassDescriptor renderPassDescriptor = new MTLRenderPassDescriptor(); using MTLRenderPassDescriptor renderPassDescriptor = new();
for (int i = 0; i < Constants.MaxColorAttachments; i++) for (int i = 0; i < Constants.MaxColorAttachments; i++)
{ {
@ -185,7 +185,7 @@ namespace Ryujinx.Graphics.Metal
public readonly MTLComputeCommandEncoder CreateComputeCommandEncoder() public readonly MTLComputeCommandEncoder CreateComputeCommandEncoder()
{ {
using MTLComputePassDescriptor descriptor = new MTLComputePassDescriptor(); using MTLComputePassDescriptor descriptor = new();
MTLComputeCommandEncoder computeCommandEncoder = _pipeline.CommandBuffer.ComputeCommandEncoder(descriptor); MTLComputeCommandEncoder computeCommandEncoder = _pipeline.CommandBuffer.ComputeCommandEncoder(descriptor);
return computeCommandEncoder; return computeCommandEncoder;

View File

@ -239,7 +239,7 @@ namespace Ryujinx.Graphics.Metal
buffer.Holder.SetDataUnchecked<float>(buffer.Offset, region); buffer.Holder.SetDataUnchecked<float>(buffer.Offset, region);
_pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]); _pipeline.SetUniformBuffers([new BufferAssignment(0, buffer.Range)]);
Rectangle<float> rect = new Rectangle<float>( Rectangle<float> rect = new(
MathF.Min(dstRegion.X1, dstRegion.X2), MathF.Min(dstRegion.X1, dstRegion.X2),
MathF.Min(dstRegion.Y1, dstRegion.Y2), MathF.Min(dstRegion.Y1, dstRegion.Y2),
MathF.Abs(dstRegion.X2 - dstRegion.X1), MathF.Abs(dstRegion.X2 - dstRegion.X1),
@ -365,7 +365,7 @@ namespace Ryujinx.Graphics.Metal
Span<Viewport> viewports = stackalloc Viewport[16]; Span<Viewport> viewports = stackalloc Viewport[16];
Rectangle<float> rect = new Rectangle<float>( Rectangle<float> rect = new(
MathF.Min(dstRegion.X1, dstRegion.X2), MathF.Min(dstRegion.X1, dstRegion.X2),
MathF.Min(dstRegion.Y1, dstRegion.Y2), MathF.Min(dstRegion.Y1, dstRegion.Y2),
MathF.Abs(dstRegion.X2 - dstRegion.X1), MathF.Abs(dstRegion.X2 - dstRegion.X1),
@ -527,7 +527,7 @@ namespace Ryujinx.Graphics.Metal
Span<Viewport> viewports = stackalloc Viewport[16]; Span<Viewport> viewports = stackalloc Viewport[16];
Rectangle<float> rect = new Rectangle<float>( Rectangle<float> rect = new(
MathF.Min(dstRegion.X1, dstRegion.X2), MathF.Min(dstRegion.X1, dstRegion.X2),
MathF.Min(dstRegion.Y1, dstRegion.Y2), MathF.Min(dstRegion.Y1, dstRegion.Y2),
MathF.Abs(dstRegion.X2 - dstRegion.X1), MathF.Abs(dstRegion.X2 - dstRegion.X1),

View File

@ -253,7 +253,7 @@ namespace Ryujinx.Graphics.Metal
public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved) public ICounterEvent ReportCounter(CounterType type, EventHandler<ulong> resultHandler, float divisor, bool hostReserved)
{ {
// https://developer.apple.com/documentation/metal/gpu_counters_and_counter_sample_buffers/creating_a_counter_sample_buffer_to_store_a_gpu_s_counter_data_during_a_pass?language=objc // https://developer.apple.com/documentation/metal/gpu_counters_and_counter_sample_buffers/creating_a_counter_sample_buffer_to_store_a_gpu_s_counter_data_during_a_pass?language=objc
CounterEvent counterEvent = new CounterEvent(); CounterEvent counterEvent = new();
resultHandler?.Invoke(counterEvent, type == CounterType.SamplesPassed ? (ulong)1 : 0); resultHandler?.Invoke(counterEvent, type == CounterType.SamplesPassed ? (ulong)1 : 0);
return counterEvent; return counterEvent;
} }

View File

@ -149,8 +149,8 @@ namespace Ryujinx.Graphics.Metal
public void Present(CAMetalDrawable drawable, Texture src, Extents2D srcRegion, Extents2D dstRegion, bool isLinear) public void Present(CAMetalDrawable drawable, Texture src, Extents2D srcRegion, Extents2D dstRegion, bool isLinear)
{ {
// TODO: Clean this up // TODO: Clean this up
TextureCreateInfo textureInfo = new TextureCreateInfo((int)drawable.Texture.Width, (int)drawable.Texture.Height, (int)drawable.Texture.Depth, (int)drawable.Texture.MipmapLevelCount, (int)drawable.Texture.SampleCount, 0, 0, 0, Format.B8G8R8A8Unorm, 0, Target.Texture2D, SwizzleComponent.Red, SwizzleComponent.Green, SwizzleComponent.Blue, SwizzleComponent.Alpha); TextureCreateInfo textureInfo = new((int)drawable.Texture.Width, (int)drawable.Texture.Height, (int)drawable.Texture.Depth, (int)drawable.Texture.MipmapLevelCount, (int)drawable.Texture.SampleCount, 0, 0, 0, Format.B8G8R8A8Unorm, 0, Target.Texture2D, SwizzleComponent.Red, SwizzleComponent.Green, SwizzleComponent.Blue, SwizzleComponent.Alpha);
Texture dst = new Texture(_device, _renderer, this, textureInfo, drawable.Texture, 0, 0); Texture dst = new(_device, _renderer, this, textureInfo, drawable.Texture, 0, 0);
_renderer.HelperShader.BlitColor(Cbs, src, dst, srcRegion, dstRegion, isLinear, true); _renderer.HelperShader.BlitColor(Cbs, src, dst, srcRegion, dstRegion, isLinear, true);

View File

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

View File

@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Metal
MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _); MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _);
using MTLSamplerDescriptor descriptor = new MTLSamplerDescriptor using MTLSamplerDescriptor descriptor = new()
{ {
BorderColor = borderColor, BorderColor = borderColor,
MinFilter = minFilter, MinFilter = minFilter,

View File

@ -118,7 +118,7 @@ namespace Ryujinx.Graphics.Metal
private readonly MTLVertexDescriptor BuildVertexDescriptor() private readonly MTLVertexDescriptor BuildVertexDescriptor()
{ {
MTLVertexDescriptor vertexDescriptor = new MTLVertexDescriptor(); MTLVertexDescriptor vertexDescriptor = new();
for (int i = 0; i < VertexAttributeDescriptionsCount; i++) for (int i = 0; i < VertexAttributeDescriptionsCount; i++)
{ {
@ -146,7 +146,7 @@ namespace Ryujinx.Graphics.Metal
private MTLRenderPipelineDescriptor CreateRenderDescriptor(Program program) private MTLRenderPipelineDescriptor CreateRenderDescriptor(Program program)
{ {
MTLRenderPipelineDescriptor renderPipelineDescriptor = new MTLRenderPipelineDescriptor(); MTLRenderPipelineDescriptor renderPipelineDescriptor = new();
for (int i = 0; i < Constants.MaxColorAttachments; i++) for (int i = 0; i < Constants.MaxColorAttachments; i++)
{ {
@ -217,7 +217,7 @@ namespace Ryujinx.Graphics.Metal
using MTLRenderPipelineDescriptor descriptor = CreateRenderDescriptor(program); using MTLRenderPipelineDescriptor descriptor = CreateRenderDescriptor(program);
NSError error = new NSError(IntPtr.Zero); NSError error = new(IntPtr.Zero);
pipelineState = device.NewRenderPipelineState(descriptor, ref error); pipelineState = device.NewRenderPipelineState(descriptor, ref error);
if (error != IntPtr.Zero) if (error != IntPtr.Zero)
{ {
@ -240,7 +240,7 @@ namespace Ryujinx.Graphics.Metal
throw new InvalidOperationException($"Local thread size for compute cannot be 0 in any dimension."); throw new InvalidOperationException($"Local thread size for compute cannot be 0 in any dimension.");
} }
MTLComputePipelineDescriptor descriptor = new MTLComputePipelineDescriptor MTLComputePipelineDescriptor descriptor = new()
{ {
ComputeFunction = program.ComputeFunction, ComputeFunction = program.ComputeFunction,
MaxTotalThreadsPerThreadgroup = maxThreads, MaxTotalThreadsPerThreadgroup = maxThreads,
@ -259,7 +259,7 @@ namespace Ryujinx.Graphics.Metal
using MTLComputePipelineDescriptor descriptor = CreateComputeDescriptor(program); using MTLComputePipelineDescriptor descriptor = CreateComputeDescriptor(program);
NSError error = new NSError(IntPtr.Zero); NSError error = new(IntPtr.Zero);
pipelineState = device.NewComputePipelineState(descriptor, MTLPipelineOption.None, 0, ref error); pipelineState = device.NewComputePipelineState(descriptor, MTLPipelineOption.None, 0, ref error);
if (error != IntPtr.Zero) if (error != IntPtr.Zero)
{ {

View File

@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Metal
{ {
MTLPixelFormat pixelFormat = FormatTable.GetFormat(Info.Format); MTLPixelFormat pixelFormat = FormatTable.GetFormat(Info.Format);
MTLTextureDescriptor descriptor = new MTLTextureDescriptor MTLTextureDescriptor descriptor = new()
{ {
PixelFormat = pixelFormat, PixelFormat = pixelFormat,
Usage = MTLTextureUsage.Unknown, Usage = MTLTextureUsage.Unknown,

View File

@ -33,8 +33,8 @@ namespace Ryujinx.Graphics.Metal
ulong bytesPerRow = (ulong)BitUtils.AlignUp(blockWidth * info.BytesPerPixel, 4); ulong bytesPerRow = (ulong)BitUtils.AlignUp(blockWidth * info.BytesPerPixel, 4);
ulong bytesPerImage = bytesPerRow * (ulong)blockHeight; ulong bytesPerImage = bytesPerRow * (ulong)blockHeight;
MTLOrigin origin = new MTLOrigin { x = (ulong)x, y = (ulong)y, z = is3D ? (ulong)dstLayer : 0 }; MTLOrigin origin = new() { x = (ulong)x, y = (ulong)y, z = is3D ? (ulong)dstLayer : 0 };
MTLSize region = new MTLSize { width = (ulong)width, height = (ulong)height, depth = 1 }; MTLSize region = new() { width = (ulong)width, height = (ulong)height, depth = 1 };
uint layer = is3D ? 0 : (uint)dstLayer; uint layer = is3D ? 0 : (uint)dstLayer;

View File

@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.Metal
if (_requestedWidth != 0 && _requestedHeight != 0) if (_requestedWidth != 0 && _requestedHeight != 0)
{ {
// TODO: This is actually a CGSize, but there is no overload for that, so fill the first two fields of rect with the size. // TODO: This is actually a CGSize, but there is no overload for that, so fill the first two fields of rect with the size.
NSRect rect = new NSRect(_requestedWidth, _requestedHeight, 0, 0); NSRect rect = new(_requestedWidth, _requestedHeight, 0, 0);
ObjectiveC.objc_msgSend(_metalLayer, "setDrawableSize:", rect); ObjectiveC.objc_msgSend(_metalLayer, "setDrawableSize:", rect);
@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.Metal
{ {
ResizeIfNeeded(); ResizeIfNeeded();
CAMetalDrawable drawable = new CAMetalDrawable(ObjectiveC.IntPtr_objc_msgSend(_metalLayer, "nextDrawable")); CAMetalDrawable drawable = new(ObjectiveC.IntPtr_objc_msgSend(_metalLayer, "nextDrawable"));
_width = (int)drawable.Texture.Width; _width = (int)drawable.Texture.Width;
_height = (int)drawable.Texture.Height; _height = (int)drawable.Texture.Height;