From aa93b48cd3c9cac3fa238e5eb682f1aa3078943e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 2 Jan 2025 13:46:01 +0100 Subject: [PATCH] Move the depth raster code around a bit in DrawEngineCommon for easier changes --- Common/GPU/Vulkan/VulkanRenderManager.cpp | 1 + GPU/Common/DrawEngineCommon.cpp | 122 +++++++++++----------- GPU/Common/DrawEngineCommon.h | 31 ++++-- 3 files changed, 84 insertions(+), 70 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 0735319977..94a44398e2 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -28,6 +28,7 @@ using namespace PPSSPP_VK; // renderPass is an example of the "compatibility class" or RenderPassType type. bool VKRGraphicsPipeline::Create(VulkanContext *vulkan, VkRenderPass compatibleRenderPass, RenderPassType rpType, VkSampleCountFlagBits sampleCount, double scheduleTime, int countToCompile) { + _dbg_assert_(desc); // Good torture test to test the shutdown-while-precompiling-shaders issue on PC where it's normally // hard to catch because shaders compile so fast. // sleep_ms(200); diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 3faf79c1e8..b7bc4eb811 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -1001,6 +1001,66 @@ bool DrawEngineCommon::CalculateDepthDraw(DepthDraw *draw, GEPrimitiveType prim, return true; } +void DrawEngineCommon::EnqueueDepthDraw(const DepthDraw &draw) { + if (depthDraws_.empty()) { + rasterTimeStart_ = time_now_d(); + } + + depthDraws_.push_back(draw); +} + +// TODO: Possibly split this in stages, to avoid switching back and forth between clipping and drawing. +void DrawEngineCommon::ProcessDepthDraw(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; + + DepthScissor tileScissor = draw.scissor.Tile(0, 1); + + const bool collectStats = coreCollectDebugStats; + const bool lowQ = g_Config.iDepthRasterMode == (int)DepthRasterMode::LOW_QUALITY; + + { + TimeCollector collectStat(&gpuStats.msCullDepth, collectStats); + switch (draw.prim) { + case GE_PRIM_RECTANGLES: + outVertCount = DepthRasterClipIndexedRectangles(tx, ty, tz, vertices, indices, draw, tileScissor); + break; + case GE_PRIM_TRIANGLES: + outVertCount = DepthRasterClipIndexedTriangles(tx, ty, tz, vertices, indices, draw, tileScissor); + break; + default: + _dbg_assert_(false); + break; + } + } + { + TimeCollector collectStat(&gpuStats.msRasterizeDepth, collectStats); + DepthRasterScreenVerts((uint16_t *)Memory::GetPointerWrite(draw.depthAddr), draw.depthStride, tx, ty, tz, outVertCount, draw, tileScissor, lowQ); + } +} + +void DrawEngineCommon::FlushQueuedDepth() { + if (rasterTimeStart_ != 0.0) { + gpuStats.msRasterTimeAvailable += time_now_d() - rasterTimeStart_; + rasterTimeStart_ = 0.0; + } + + for (const auto &draw : depthDraws_) { + ProcessDepthDraw(draw); + } + + // Reset queue + depthIndexCount_ = 0; + depthVertexCount_ = 0; + depthDraws_.clear(); +} + void DrawEngineCommon::DepthRasterTransform(GEPrimitiveType prim, VertexDecoder *dec, uint32_t vertTypeID, int vertexCount) { if (!gstate.isModeClear() && (!gstate.isDepthTestEnabled() || !gstate.isDepthWriteEnabled())) { return; @@ -1042,13 +1102,7 @@ void DrawEngineCommon::DepthRasterTransform(GEPrimitiveType prim, VertexDecoder depthIndexCount_ += vertexCount; depthVertexCount_ += numDecoded; - if (depthDraws_.empty()) { - rasterTimeStart_ = time_now_d(); - } - - depthDraws_.push_back(draw); - - // FlushQueuedDepth(); + EnqueueDepthDraw(draw); } void DrawEngineCommon::DepthRasterPredecoded(GEPrimitiveType prim, const void *inVerts, int numDecoded, VertexDecoder *dec, int vertexCount) { @@ -1083,57 +1137,5 @@ void DrawEngineCommon::DepthRasterPredecoded(GEPrimitiveType prim, const void *i depthIndexCount_ += vertexCount; depthVertexCount_ += numDecoded; - depthDraws_.push_back(draw); - - if (depthDraws_.empty()) { - rasterTimeStart_ = time_now_d(); - } - // FlushQueuedDepth(); -} - -void DrawEngineCommon::FlushQueuedDepth() { - if (rasterTimeStart_ != 0.0) { - gpuStats.msRasterTimeAvailable += time_now_d() - rasterTimeStart_; - rasterTimeStart_ = 0.0; - } - - const bool collectStats = coreCollectDebugStats; - const bool lowQ = g_Config.iDepthRasterMode == (int)DepthRasterMode::LOW_QUALITY; - - for (const auto &draw : depthDraws_) { - 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; - - DepthScissor tileScissor = draw.scissor.Tile(0, 1); - - { - TimeCollector collectStat(&gpuStats.msCullDepth, collectStats); - switch (draw.prim) { - case GE_PRIM_RECTANGLES: - outVertCount = DepthRasterClipIndexedRectangles(tx, ty, tz, vertices, indices, draw, tileScissor); - break; - case GE_PRIM_TRIANGLES: - outVertCount = DepthRasterClipIndexedTriangles(tx, ty, tz, vertices, indices, draw, tileScissor); - break; - default: - _dbg_assert_(false); - break; - } - } - { - TimeCollector collectStat(&gpuStats.msRasterizeDepth, collectStats); - DepthRasterScreenVerts((uint16_t *)Memory::GetPointerWrite(draw.depthAddr), draw.depthStride, tx, ty, tz, outVertCount, draw, tileScissor, lowQ); - } - } - - // Reset queue - depthIndexCount_ = 0; - depthVertexCount_ = 0; - depthDraws_.clear(); + EnqueueDepthDraw(draw); } diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index e927a82e9a..9dc7bf42ad 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -80,7 +80,7 @@ public: virtual void BeginFrame(); void SetGPUCommon(GPUCommon *gpuCommon) { - gpuCommon_ = gpuCommon; + gpuCommon = gpuCommon; } virtual void DeviceLost() = 0; @@ -164,8 +164,6 @@ public: return decoded_ + 12 * 65536; } - void FlushQueuedDepth(); - protected: virtual bool UpdateUseHWTessellation(bool enabled) const { return enabled; } void UpdatePlanes(); @@ -177,10 +175,6 @@ protected: void ApplyFramebufferRead(FBOTexState *fboTexState); - void DepthRasterTransform(GEPrimitiveType prim, VertexDecoder *dec, uint32_t vertTypeID, int vertexCount); - void DepthRasterPredecoded(GEPrimitiveType prim, const void *inVerts, int numDecoded, VertexDecoder *dec, int vertexCount); - bool CalculateDepthDraw(DepthDraw *draw, GEPrimitiveType prim, int vertexCount); - static inline int IndexSize(u32 vtype) { const u32 indexType = (vtype & GE_VTYPE_IDX_MASK); if (indexType == GE_VTYPE_IDX_16BIT) { @@ -346,19 +340,36 @@ protected: ComputedPipelineState pipelineState_; // Hardware tessellation - TessellationDataTransfer *tessDataTransfer; + TessellationDataTransfer *tessDataTransfer = nullptr; + + GPUCommon *gpuCommon_; // Culling +private: Plane8 planes_; Vec2f minOffset_; Vec2f maxOffset_; bool offsetOutsideEdge_; - GPUCommon *gpuCommon_; + // Software depth raster. TODO: Extract? +public: + // Public interface + void FlushQueuedDepth(); + +protected: + // Interface used by the backends. + void DepthRasterTransform(GEPrimitiveType prim, VertexDecoder *dec, uint32_t vertTypeID, int vertexCount); + void DepthRasterPredecoded(GEPrimitiveType prim, const void *inVerts, int numDecoded, VertexDecoder *dec, int vertexCount); - // Software depth raster bool useDepthRaster_ = false; +private: + // Internal implementation details. + + inline void EnqueueDepthDraw(const DepthDraw &draw); + inline void ProcessDepthDraw(const DepthDraw &draw); + bool CalculateDepthDraw(DepthDraw *draw, GEPrimitiveType prim, int vertexCount); + float *depthTransformed_ = nullptr; int *depthScreenVerts_ = nullptr; uint16_t *depthIndices_ = nullptr;