Skip to content

Commit

Permalink
Vertex Attribute Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jan 4, 2025
1 parent 1a68c76 commit 77bf637
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
8 changes: 4 additions & 4 deletions core/rend/metal/metal_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion core/rend/metal/metal_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion core/rend/metal/metal_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down

0 comments on commit 77bf637

Please sign in to comment.