From 6d539cc5e0867a13eca795a431af8c2069b91432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 28 Dec 2024 23:44:49 +0100 Subject: [PATCH] More fixes --- GPU/Common/DepthRaster.h | 6 ++- GPU/Common/DrawEngineCommon.cpp | 67 ++++++++++++++++++--------------- GPU/Common/DrawEngineCommon.h | 1 - GPU/GPU.h | 6 ++- GPU/GPUCommon.cpp | 7 +++- GPU/GPUCommonHW.cpp | 5 ++- 6 files changed, 53 insertions(+), 39 deletions(-) diff --git a/GPU/Common/DepthRaster.h b/GPU/Common/DepthRaster.h index 189748bb47..104ccec36f 100644 --- a/GPU/Common/DepthRaster.h +++ b/GPU/Common/DepthRaster.h @@ -15,7 +15,7 @@ struct DepthScreenVertex { #endif // We only need to support these three modes. -enum class ZCompareMode { +enum class ZCompareMode : u8 { Greater, // Most common Less, // Less common Always, // Mostly used for clears @@ -29,10 +29,12 @@ struct DepthScissor { }; struct DepthDraw { + u32 depthAddr; + u16 depthStride; + u8 cullMode; GEPrimitiveType prim; ZCompareMode compareMode; bool cullEnabled; - int cullMode; DepthScissor scissor; int vertexOffset; int indexOffset; diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 3544b2a225..357736b9b2 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -39,7 +39,7 @@ enum { TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex), - DEPTH_TRANSFORMED_SIZE = VERTEX_BUFFER_MAX * 4, + DEPTH_TRANSFORMED_SIZE = VERTEX_BUFFER_MAX * 4 * sizeof(float), DEPTH_SCREENVERTS_COMPONENT_COUNT = VERTEX_BUFFER_MAX, DEPTH_SCREENVERTS_COMPONENT_SIZE = DEPTH_SCREENVERTS_COMPONENT_COUNT * sizeof(int) + 384, DEPTH_SCREENVERTS_SIZE = DEPTH_SCREENVERTS_COMPONENT_SIZE * 3, @@ -67,6 +67,9 @@ DrawEngineCommon::DrawEngineCommon() : decoderMap_(32) { case DepthRasterMode::OFF: useDepthRaster_ = false; } + if (useDepthRaster_) { + depthDraws_.reserve(256); + } } DrawEngineCommon::~DrawEngineCommon() { @@ -983,6 +986,8 @@ bool DrawEngineCommon::CalculateDepthDraw(DepthDraw *draw, GEPrimitiveType prim, return false; } + draw->depthAddr = gstate.getDepthBufRawAddress() | 0x04000000; + draw->depthStride = gstate.DepthBufStride(); draw->vertexOffset = depthVertexCount_; draw->indexOffset = depthIndexCount_; draw->vertexCount = vertexCount; @@ -1015,7 +1020,7 @@ void DrawEngineCommon::DepthRasterTransform(GEPrimitiveType prim, VertexDecoder return; } - TimeCollector collectStat(&gpuStats.msRasterizingDepth, coreCollectDebugStats); + TimeCollector collectStat(&gpuStats.msPrepareDepth, coreCollectDebugStats); // Decode. int numDecoded = 0; @@ -1035,9 +1040,11 @@ void DrawEngineCommon::DepthRasterTransform(GEPrimitiveType prim, VertexDecoder // Commit depthIndexCount_ += vertexCount; - depthVertexCount_ += numDec; + depthVertexCount_ += numDecoded; depthDraws_.push_back(draw); + + // FlushQueuedDepth(); } void DrawEngineCommon::DepthRasterPredecoded(GEPrimitiveType prim, const void *inVerts, int numDecoded, VertexDecoder *dec, int vertexCount) { @@ -1050,7 +1057,7 @@ void DrawEngineCommon::DepthRasterPredecoded(GEPrimitiveType prim, const void *i return; } - TimeCollector collectStat(&gpuStats.msRasterizingDepth, coreCollectDebugStats); + TimeCollector collectStat(&gpuStats.msPrepareDepth, coreCollectDebugStats); _dbg_assert_(prim != GE_PRIM_TRIANGLE_STRIP && prim != GE_PRIM_TRIANGLE_FAN); @@ -1073,11 +1080,36 @@ void DrawEngineCommon::DepthRasterPredecoded(GEPrimitiveType prim, const void *i depthVertexCount_ += numDecoded; depthDraws_.push_back(draw); + + // FlushQueuedDepth(); } void DrawEngineCommon::FlushQueuedDepth() { + TimeCollector collectStat(&gpuStats.msRasterizeDepth, coreCollectDebugStats); + for (const auto &draw : depthDraws_) { - ExecuteDepthDraw(draw); + int *tx = depthScreenVerts_; + int *ty = depthScreenVerts_ + DEPTH_SCREENVERTS_COMPONENT_COUNT; + float *tz = (float *)(depthScreenVerts_ + DEPTH_SCREENVERTS_COMPONENT_COUNT * 2); + + int outVertCount = 0; + + const float *vertices = depthTransformed_ + 4 * draw.vertexOffset; + const uint16_t *indices = depthIndices_ + draw.indexOffset; + + switch (draw.prim) { + case GE_PRIM_RECTANGLES: + outVertCount = DepthRasterClipIndexedRectangles(tx, ty, tz, vertices, indices, draw); + break; + case GE_PRIM_TRIANGLES: + outVertCount = DepthRasterClipIndexedTriangles(tx, ty, tz, vertices, indices, draw); + break; + default: + _dbg_assert_(false); + break; + } + // TODO: Could potentially split into tasks here! + DepthRasterScreenVerts((uint16_t *)Memory::GetPointerWrite(draw.depthAddr), draw.depthStride, tx, ty, tz, outVertCount, draw); } // Reset queue @@ -1085,28 +1117,3 @@ void DrawEngineCommon::FlushQueuedDepth() { depthVertexCount_ = 0; depthDraws_.clear(); } - -void DrawEngineCommon::ExecuteDepthDraw(const DepthDraw &draw) { - int *tx = depthScreenVerts_; - int *ty = depthScreenVerts_ + DEPTH_SCREENVERTS_COMPONENT_COUNT; - float *tz = (float *)(depthScreenVerts_ + DEPTH_SCREENVERTS_COMPONENT_COUNT * 2); - - int outVertCount = 0; - - const float *vertices = depthTransformed_ + 4 * draw.vertexOffset; - const uint16_t *indices = depthIndices_ + draw.indexOffset; - - switch (draw.prim) { - case GE_PRIM_RECTANGLES: - outVertCount = DepthRasterClipIndexedRectangles(tx, ty, tz, vertices, indices, draw); - break; - case GE_PRIM_TRIANGLES: - outVertCount = DepthRasterClipIndexedTriangles(tx, ty, tz, vertices, indices, draw); - break; - default: - _dbg_assert_(false); - break; - } - DepthRasterScreenVerts((uint16_t *)Memory::GetPointerWrite(gstate.getDepthBufRawAddress() | 0x04000000), gstate.DepthBufStride(), - tx, ty, tz, outVertCount, draw); -} diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index e25d3662a2..8b56f3cd65 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -179,7 +179,6 @@ protected: void DepthRasterTransform(GEPrimitiveType prim, VertexDecoder *dec, uint32_t vertTypeID, int vertexCount); void DepthRasterPredecoded(GEPrimitiveType prim, const void *inVerts, int numDecoded, VertexDecoder *dec, int vertexCount); - void ExecuteDepthDraw(const DepthDraw &draw); bool CalculateDepthDraw(DepthDraw *draw, GEPrimitiveType prim, int vertexCount); static inline int IndexSize(u32 vtype) { diff --git a/GPU/GPU.h b/GPU/GPU.h index ce5443084c..5b1d937c04 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -108,7 +108,8 @@ struct GPUStatistics { numCachedReplacedTextures = 0; numClutTextures = 0; msProcessingDisplayLists = 0; - msRasterizingDepth = 0.0f; + msPrepareDepth = 0.0f; + msRasterizeDepth = 0.0f; numDepthRasterPrims = 0; numDepthRasterBackface = 0; numDepthRasterNoPixels = 0; @@ -153,7 +154,8 @@ struct GPUStatistics { int numCachedReplacedTextures; int numClutTextures; double msProcessingDisplayLists; - double msRasterizingDepth; + double msPrepareDepth; + double msRasterizeDepth; int vertexGPUCycles; int otherGPUCycles; int numDepthRasterPrims; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 25635b8148..1f507a3867 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -987,8 +987,10 @@ void GPUCommon::Execute_Ret(u32 op, u32 diff) { } void GPUCommon::Execute_End(u32 op, u32 diff) { - if (flushOnParams_) + if (flushOnParams_) { + drawEngineCommon_->FlushQueuedDepth(); Flush(); + } const u32 prev = Memory::ReadUnchecked_U32(currentList->pc - 4); UpdatePC(currentList->pc, currentList->pc); @@ -1380,8 +1382,9 @@ void GPUCommon::FastLoadBoneMatrix(u32 target) { } if (!g_Config.bSoftwareSkinning) { - if (flushOnParams_) + if (flushOnParams_) { Flush(); + } gstate_c.Dirty(uniformsToDirty); } else { gstate_c.deferredVertTypeDirty |= uniformsToDirty; diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index 03df3acfba..a8aae188d1 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -1801,7 +1801,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 back, %d zcull\n%s", + "Z-rast: %0.2f/%0.2f ms, %d prim, %d nopix, %d small, %d back, %d zcull\n%s", gpuStats.msProcessingDisplayLists * 1000.0f, gpuStats.numDrawSyncs, gpuStats.numListSyncs, @@ -1838,7 +1838,8 @@ size_t GPUCommonHW::FormatGPUStatsCommon(char *buffer, size_t size) { gpuStats.numCopiesForSelfTex, gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles, vertexAverageCycles, - gpuStats.msRasterizingDepth * 1000.0, + gpuStats.msPrepareDepth * 1000.0, + gpuStats.msRasterizeDepth * 1000.0, gpuStats.numDepthRasterPrims, gpuStats.numDepthRasterNoPixels, gpuStats.numDepthRasterTooSmall,