mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-11-24 18:20:12 +01:00
Dont be stupid
This commit is contained in:
parent
c58cc76b39
commit
7f41e7dbd4
@ -26,6 +26,7 @@ namespace Ryujinx.Graphics.Metal
|
||||
private MTLCommandEncoder _currentEncoder;
|
||||
|
||||
private RenderEncoderState _renderEncoderState;
|
||||
private MTLVertexDescriptor _vertexDescriptor = new();
|
||||
|
||||
private MTLBuffer _indexBuffer;
|
||||
private MTLIndexType _indexType;
|
||||
@ -117,7 +118,7 @@ namespace Ryujinx.Graphics.Metal
|
||||
|
||||
var descriptor = new MTLRenderPassDescriptor();
|
||||
var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor);
|
||||
_renderEncoderState.SetEncoderState(renderCommandEncoder);
|
||||
_renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor);
|
||||
|
||||
_currentEncoder = renderCommandEncoder;
|
||||
return renderCommandEncoder;
|
||||
@ -160,7 +161,7 @@ namespace Ryujinx.Graphics.Metal
|
||||
descriptor.ColorAttachments.Object(0).ClearColor = _clearColor;
|
||||
|
||||
var renderCommandEncoder = _commandBuffer.RenderCommandEncoder(descriptor);
|
||||
_renderEncoderState.SetEncoderState(renderCommandEncoder);
|
||||
_renderEncoderState.SetEncoderState(renderCommandEncoder, _vertexDescriptor);
|
||||
|
||||
var sampler = _device.NewSamplerState(new MTLSamplerDescriptor
|
||||
{
|
||||
@ -526,12 +527,28 @@ namespace Ryujinx.Graphics.Metal
|
||||
|
||||
public void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
|
||||
{
|
||||
_renderEncoderState.UpdateVertexAttributes(vertexAttribs);
|
||||
for (int i = 0; i < vertexAttribs.Length; i++)
|
||||
{
|
||||
if (!vertexAttribs[i].IsZero)
|
||||
{
|
||||
// TODO: Format should not be hardcoded
|
||||
var attrib = _vertexDescriptor.Attributes.Object((ulong)i);
|
||||
attrib.Format = MTLVertexFormat.Float4;
|
||||
attrib.BufferIndex = (ulong)vertexAttribs[i].BufferIndex;
|
||||
attrib.Offset = (ulong)vertexAttribs[i].Offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
||||
{
|
||||
_renderEncoderState.UpdateVertexBuffers(vertexBuffers);
|
||||
for (int i = 0; i < vertexBuffers.Length; i++)
|
||||
{
|
||||
if (vertexBuffers[i].Stride != 0)
|
||||
{
|
||||
_vertexDescriptor.Layouts.Object((ulong)i).Stride = (ulong)vertexBuffers[i].Stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void SetViewports(ReadOnlySpan<Viewport> viewports)
|
||||
|
@ -21,8 +21,6 @@ namespace Ryujinx.Graphics.Metal
|
||||
private MTLStencilDescriptor _backFaceStencil = null;
|
||||
private MTLStencilDescriptor _frontFaceStencil = null;
|
||||
|
||||
private MTLVertexDescriptor _vertexDescriptor = new();
|
||||
|
||||
public PrimitiveTopology Topology = PrimitiveTopology.Triangles;
|
||||
public MTLCullMode CullMode = MTLCullMode.None;
|
||||
public MTLWinding Winding = MTLWinding.Clockwise;
|
||||
@ -34,11 +32,11 @@ namespace Ryujinx.Graphics.Metal
|
||||
_device = device;
|
||||
}
|
||||
|
||||
public readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder)
|
||||
public readonly void SetEncoderState(MTLRenderCommandEncoder renderCommandEncoder, MTLVertexDescriptor vertexDescriptor)
|
||||
{
|
||||
var renderPipelineDescriptor = new MTLRenderPipelineDescriptor
|
||||
{
|
||||
VertexDescriptor = _vertexDescriptor
|
||||
VertexDescriptor = vertexDescriptor
|
||||
};
|
||||
|
||||
if (_vertexFunction != null)
|
||||
@ -51,12 +49,13 @@ namespace Ryujinx.Graphics.Metal
|
||||
renderPipelineDescriptor.VertexFunction = _fragmentFunction;
|
||||
}
|
||||
|
||||
renderPipelineDescriptor.ColorAttachments.Object(0).SetBlendingEnabled(true);
|
||||
renderPipelineDescriptor.ColorAttachments.Object(0).PixelFormat = MTLPixelFormat.BGRA8Unorm;
|
||||
renderPipelineDescriptor.ColorAttachments.Object(0).SourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha;
|
||||
renderPipelineDescriptor.ColorAttachments.Object(0).DestinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
|
||||
renderPipelineDescriptor.ColorAttachments.Object(0).SourceRGBBlendFactor = MTLBlendFactor.SourceAlpha;
|
||||
renderPipelineDescriptor.ColorAttachments.Object(0).DestinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
|
||||
var attachment = renderPipelineDescriptor.ColorAttachments.Object(0);
|
||||
attachment.SetBlendingEnabled(true);
|
||||
attachment.PixelFormat = MTLPixelFormat.BGRA8Unorm;
|
||||
attachment.SourceAlphaBlendFactor = MTLBlendFactor.SourceAlpha;
|
||||
attachment.DestinationAlphaBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
|
||||
attachment.SourceRGBBlendFactor = MTLBlendFactor.SourceAlpha;
|
||||
attachment.DestinationRGBBlendFactor = MTLBlendFactor.OneMinusSourceAlpha;
|
||||
|
||||
var error = new NSError(IntPtr.Zero);
|
||||
var pipelineState = _device.NewRenderPipelineState(renderPipelineDescriptor, ref error);
|
||||
@ -102,30 +101,5 @@ namespace Ryujinx.Graphics.Metal
|
||||
FrontFaceStencil = _frontFaceStencil
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateVertexAttributes(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
|
||||
{
|
||||
for (int i = 0; i < vertexAttribs.Length; i++)
|
||||
{
|
||||
if (!vertexAttribs[i].IsZero)
|
||||
{
|
||||
// TODO: Format should not be hardcoded
|
||||
_vertexDescriptor.Attributes.Object((ulong)i).Format = MTLVertexFormat.Float4;
|
||||
_vertexDescriptor.Attributes.Object((ulong)i).BufferIndex = (ulong)vertexAttribs[i].BufferIndex;
|
||||
_vertexDescriptor.Attributes.Object((ulong)i).Offset = (ulong)vertexAttribs[i].Offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
|
||||
{
|
||||
for (int i = 0; i < vertexBuffers.Length; i++)
|
||||
{
|
||||
if (vertexBuffers[i].Stride != 0)
|
||||
{
|
||||
_vertexDescriptor.Layouts.Object((ulong)i).Stride = (ulong)vertexBuffers[i].Stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user