From 8b10ee3937cf8007ed31a38b3f620491188280ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 28 Dec 2024 16:11:56 +0100 Subject: [PATCH] Depth Z: Add a stat for Z-culling, correctly distinguish the small/backface stats --- GPU/Common/DepthRaster.cpp | 9 +++++++-- GPU/GPU.h | 2 ++ GPU/GPUCommonHW.cpp | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/GPU/Common/DepthRaster.cpp b/GPU/Common/DepthRaster.cpp index cdc6159030..9dc24f35a4 100644 --- a/GPU/Common/DepthRaster.cpp +++ b/GPU/Common/DepthRaster.cpp @@ -149,11 +149,11 @@ TriangleResult DepthRasterTriangle(uint16_t *depthBuf, int stride, int x1, int y // TODO: Cull really small triangles here - we can increase the threshold a bit probably. int triArea = (v1y - v2y) * v0x + (v2x - v1x) * v0y + (v1x * v2y - v2x * v1y); - if (triArea <= 0) { + if (triArea < 0) { return TriangleResult::Backface; } if (triArea < MIN_TRI_AREA) { - return TriangleResult::TooSmall; + return TriangleResult::TooSmall; // Or zero area. } float oneOverTriArea = 1.0f / (float)triArea; @@ -344,6 +344,7 @@ int DepthRasterClipIndexedTriangles(int *tx, int *ty, float *tz, const float *tr static const float zerovec[4] = {}; int collected = 0; + int planeCulled = 0; const float *verts[12]; // four triangles at a time! for (int i = 0; i < count; i += 3) { // Collect valid triangles into buffer. @@ -356,6 +357,8 @@ int DepthRasterClipIndexedTriangles(int *tx, int *ty, float *tz, const float *tr verts[collected + 1] = v1; verts[collected + 2] = v2; collected += 3; + } else { + planeCulled++; } if (i >= count - 3 && collected != 12) { @@ -433,6 +436,8 @@ int DepthRasterClipIndexedTriangles(int *tx, int *ty, float *tz, const float *tr outCount += 12; } } + + gpuStats.numDepthRasterZCulled += planeCulled; return outCount; } diff --git a/GPU/GPU.h b/GPU/GPU.h index 9b98e86344..ce5443084c 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -113,6 +113,7 @@ struct GPUStatistics { numDepthRasterBackface = 0; numDepthRasterNoPixels = 0; numDepthRasterTooSmall = 0; + numDepthRasterZCulled = 0; vertexGPUCycles = 0; otherGPUCycles = 0; } @@ -159,6 +160,7 @@ struct GPUStatistics { int numDepthRasterBackface; int numDepthRasterNoPixels; int numDepthRasterTooSmall; + int numDepthRasterZCulled; // Flip count. Doesn't really belong here. int numFlips; }; diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index 552a38179c..a734a32e45 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -1776,7 +1776,7 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) { "replacer: tracks %d references, %d unique textures\n" "Cpy: depth %d, color %d, reint %d, blend %d, self %d\n" "GPU cycles: %d (%0.1f per vertex)\n" - "Depth raster: %0.2f ms, %d prim, %d nopix, %d small, %d backface\n%s", + "Depth raster: %0.2f ms, %d prim, %d nopix, %d small, %d back, %d zcull\n%s", gpuStats.msProcessingDisplayLists * 1000.0f, gpuStats.numDrawSyncs, gpuStats.numListSyncs, @@ -1818,6 +1818,7 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) { gpuStats.numDepthRasterNoPixels, gpuStats.numDepthRasterTooSmall, gpuStats.numDepthRasterBackface, + gpuStats.numDepthRasterZCulled, debugRecording_ ? "(debug-recording)" : "" ); }