From 77bf637b059f036628a7ebb621aa75983112594b Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sat, 4 Jan 2025 14:17:58 -0500 Subject: [PATCH] Vertex Attribute Fixes --- core/rend/metal/metal_buffer.h | 8 ++++---- core/rend/metal/metal_pipeline.h | 22 +++++++++++++++++++++- core/rend/metal/metal_renderer.cpp | 3 ++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/rend/metal/metal_buffer.h b/core/rend/metal/metal_buffer.h index 567d55c792..72ffe33888 100644 --- a/core/rend/metal/metal_buffer.h +++ b/core/rend/metal/metal_buffer.h @@ -71,16 +71,16 @@ class BufferPacker BufferPacker(); u64 addUniform(const void *p, size_t size) { - return add(p, size, 16); + return add(p, size); } u64 addStorage(const void *p, size_t size) { - return add(p, size, 16); + return add(p, size); } - u64 add(const void *p, size_t size, u32 alignment = 4) + u64 add(const void *p, size_t size) { - u32 padding = align(offset, std::max(4u, alignment)); + u32 padding = align(offset, 16); if (padding != 0) { chunks.push_back(nullptr); diff --git a/core/rend/metal/metal_pipeline.h b/core/rend/metal/metal_pipeline.h index b033ec07c5..53fe7ea8d2 100644 --- a/core/rend/metal/metal_pipeline.h +++ b/core/rend/metal/metal_pipeline.h @@ -130,28 +130,48 @@ class MetalPipelineManager auto pos = vertexDesc->attributes()->object(0); // pos pos->setFormat(MTL::VertexFormatFloat3); pos->setOffset(offsetof(Vertex, x)); + pos->setBufferIndex(30); if (full) { auto col = vertexDesc->attributes()->object(1); // base color col->setFormat(MTL::VertexFormatUChar4Normalized); col->setOffset(offsetof(Vertex, col)); + col->setBufferIndex(30); auto spc = vertexDesc->attributes()->object(2); // offset color spc->setFormat(MTL::VertexFormatUChar4Normalized); spc->setOffset(offsetof(Vertex, spc)); + spc->setBufferIndex(30); auto u = vertexDesc->attributes()->object(3); // tex coord u->setFormat(MTL::VertexFormatFloat2); u->setOffset(offsetof(Vertex, u)); + u->setBufferIndex(30); + + auto col1 = vertexDesc->attributes()->object(4); + col1->setFormat(MTL::VertexFormatUChar4Normalized); + col1->setOffset(offsetof(Vertex, col1)); + col1->setBufferIndex(30); + + auto spc1 = vertexDesc->attributes()->object(4); + spc1->setFormat(MTL::VertexFormatUChar4Normalized); + spc1->setOffset(offsetof(Vertex, spc1)); + spc1->setBufferIndex(30); + + auto u1 = vertexDesc->attributes()->object(3); // tex coord + u1->setFormat(MTL::VertexFormatFloat2); + u1->setOffset(offsetof(Vertex, u1)); + u1->setBufferIndex(30); if (naomi2) { auto nx = vertexDesc->attributes()->object(4); // naomi2 normal nx->setFormat(MTL::VertexFormatFloat3); nx->setOffset(offsetof(Vertex, nx)); + nx->setBufferIndex(30); } } - auto layout = vertexDesc->layouts()->object(0); + auto layout = vertexDesc->layouts()->object(30); layout->setStride(sizeof(Vertex)); layout->setStepRate(1); layout->setStepFunction(MTL::VertexStepFunctionPerVertex); diff --git a/core/rend/metal/metal_renderer.cpp b/core/rend/metal/metal_renderer.cpp index 3864a6ac04..f51115c7bb 100644 --- a/core/rend/metal/metal_renderer.cpp +++ b/core/rend/metal/metal_renderer.cpp @@ -474,12 +474,13 @@ bool MetalRenderer::Draw(const MetalTexture *fogTexture, const MetalTexture *pal } // Upload vertex and index buffers - VertexShaderUniforms vtxUniforms; + VertexShaderUniforms vtxUniforms {}; vtxUniforms.ndcMat = matrices.GetNormalMatrix(); UploadMainBuffer(vtxUniforms, fragUniforms); renderEncoder->setVertexBuffer(curMainBuffer, offsets.vertexUniformOffset, 0); + renderEncoder->setVertexBuffer(curMainBuffer, 0, 30); renderEncoder->setFragmentBuffer(curMainBuffer, offsets.fragmentUniformOffset, 0); RenderPass previous_pass {};