From b755ebdc8e447afdd02d82f108bf5247b0b8b4f9 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Wed, 29 Nov 2023 20:24:47 -0800 Subject: [PATCH 1/2] Fixing poly overcount in logging in Metal renderer plRenderTriListFunc was taking the index count and not the triangle count --- .../Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp index 59aebe384a..4789609990 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp @@ -156,7 +156,7 @@ bool plRenderTriListFunc::RenderPrims() const size_t lightSize = offsetof(plMetalLights, lampSources) + (sizeof(plMetalShaderLightSource) * lights->count); fDevice->CurrentRenderCommandEncoder()->setVertexBytes(lights, sizeof(plMetalLights), VertexShaderArgumentLights); - fDevice->CurrentRenderCommandEncoder()->drawIndexedPrimitives(MTL::PrimitiveTypeTriangle, fNumTris, MTL::IndexTypeUInt16, fDevice->fCurrentIndexBuffer, (sizeof(uint16_t) * fIStart)); + fDevice->CurrentRenderCommandEncoder()->drawIndexedPrimitives(MTL::PrimitiveTypeTriangle, fNumTris * 3, MTL::IndexTypeUInt16, fDevice->fCurrentIndexBuffer, (sizeof(uint16_t) * fIStart)); } plMetalPipeline::plMetalPipeline(hsWindowHndl display, hsWindowHndl window, const hsG3DDeviceModeRecord* devMode) : pl3DPipeline(devMode), @@ -1183,7 +1183,7 @@ void plMetalPipeline::IRenderBufferSpan(const plIcicle& span, hsGDeviceRef* vb, /* Index Buffer stuff and drawing */ - plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength); + plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength/3); plProfile_EndTiming(RenderBuff); @@ -1478,7 +1478,7 @@ void plMetalPipeline::IRenderAuxSpan(const plSpan& span, const plAuxSpan* aux) fState.fCurrentVertexBuffer = vRef->GetBuffer(); fDevice.fCurrentIndexBuffer = iRef->GetBuffer(); - plRenderTriListFunc render(&fDevice, 0, aux->fVStartIdx, aux->fVLength, aux->fIStartIdx, aux->fILength); + plRenderTriListFunc render(&fDevice, 0, aux->fVStartIdx, aux->fVLength, aux->fIStartIdx, aux->fILength/3); for (int32_t pass = 0; pass < mRef->GetNumPasses(); pass++) { IHandleMaterialPass(material, pass, &span, vRef); @@ -3707,7 +3707,7 @@ void plMetalPipeline::IRenderShadowCasterSpan(plShadowSlave* slave, plDrawableSp uint32_t iStart = span.fIPackedIdx; uint32_t iLength = span.fILength; - plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength); + plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength/3); static hsMatrix44 emptyMatrix; hsMatrix44 m = emptyMatrix; From 60020306e3a38fd391436a095afc668d4d3b15d4 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Thu, 30 Nov 2023 16:41:36 -0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Adam Johnson --- .../Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp index 4789609990..4ca1e2bca6 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp @@ -1183,7 +1183,7 @@ void plMetalPipeline::IRenderBufferSpan(const plIcicle& span, hsGDeviceRef* vb, /* Index Buffer stuff and drawing */ - plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength/3); + plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength / 3); plProfile_EndTiming(RenderBuff); @@ -1478,7 +1478,7 @@ void plMetalPipeline::IRenderAuxSpan(const plSpan& span, const plAuxSpan* aux) fState.fCurrentVertexBuffer = vRef->GetBuffer(); fDevice.fCurrentIndexBuffer = iRef->GetBuffer(); - plRenderTriListFunc render(&fDevice, 0, aux->fVStartIdx, aux->fVLength, aux->fIStartIdx, aux->fILength/3); + plRenderTriListFunc render(&fDevice, 0, aux->fVStartIdx, aux->fVLength, aux->fIStartIdx, aux->fILength / 3); for (int32_t pass = 0; pass < mRef->GetNumPasses(); pass++) { IHandleMaterialPass(material, pass, &span, vRef); @@ -3707,7 +3707,7 @@ void plMetalPipeline::IRenderShadowCasterSpan(plShadowSlave* slave, plDrawableSp uint32_t iStart = span.fIPackedIdx; uint32_t iLength = span.fILength; - plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength/3); + plRenderTriListFunc render(&fDevice, 0, vStart, vLength, iStart, iLength / 3); static hsMatrix44 emptyMatrix; hsMatrix44 m = emptyMatrix;