From d4703e9534854c3d2e27e6c6ab0f01696716a876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 10 May 2023 20:51:52 +0200 Subject: [PATCH 1/5] Decoded position format is always the same --- GPU/Common/VertexDecoderCommon.cpp | 14 +++++--------- GPU/Common/VertexDecoderCommon.h | 6 +++--- GPU/D3D11/DrawEngineD3D11.cpp | 2 +- GPU/Directx9/DrawEngineDX9.cpp | 2 +- GPU/GLES/DrawEngineGLES.cpp | 2 +- GPU/Vulkan/PipelineManagerVulkan.cpp | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/GPU/Common/VertexDecoderCommon.cpp b/GPU/Common/VertexDecoderCommon.cpp index ec1af7c80e7d..cc8b6452e2b1 100644 --- a/GPU/Common/VertexDecoderCommon.cpp +++ b/GPU/Common/VertexDecoderCommon.cpp @@ -60,7 +60,7 @@ int TranslateNumBones(int bones) { return bones; } -int DecFmtSize(u8 fmt) { +static int DecFmtSize(u8 fmt) { switch (fmt) { case DEC_NONE: return 0; case DEC_FLOAT_1: return 4; @@ -83,7 +83,7 @@ int DecFmtSize(u8 fmt) { } void DecVtxFormat::ComputeID() { - id = w0fmt | (w1fmt << 4) | (uvfmt << 8) | (c0fmt << 12) | (c1fmt << 16) | (nrmfmt << 20) | (posfmt << 24); + id = w0fmt | (w1fmt << 4) | (uvfmt << 8) | (c0fmt << 12) | (c1fmt << 16) | (nrmfmt << 20); } void DecVtxFormat::InitializeFromID(uint32_t id) { @@ -94,7 +94,6 @@ void DecVtxFormat::InitializeFromID(uint32_t id) { c0fmt = ((id >> 12) & 0xF); c1fmt = ((id >> 16) & 0xF); nrmfmt = ((id >> 20) & 0xF); - posfmt = ((id >> 24) & 0xF); w0off = 0; w1off = w0off + DecFmtSize(w0fmt); uvoff = w1off + DecFmtSize(w1fmt); @@ -102,7 +101,7 @@ void DecVtxFormat::InitializeFromID(uint32_t id) { c1off = c0off + DecFmtSize(c0fmt); nrmoff = c1off + DecFmtSize(c1fmt); posoff = nrmoff + DecFmtSize(nrmfmt); - stride = posoff + DecFmtSize(posfmt); + stride = posoff + DecFmtSize(PosFmt()); } void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound) { @@ -1248,20 +1247,18 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options, if (posalign[pos] > biggest) biggest = posalign[pos]; + // We don't set posfmt because it's always DEC_FLOAT_3. if (throughmode) { steps_[numSteps_++] = posstep_through[pos]; - decFmt.posfmt = DEC_FLOAT_3; } else { if (skinInDecode) { steps_[numSteps_++] = morphcount == 1 ? posstep_skin[pos] : posstep_morph_skin[pos]; - decFmt.posfmt = DEC_FLOAT_3; } else { steps_[numSteps_++] = morphcount == 1 ? posstep[pos] : posstep_morph[pos]; - decFmt.posfmt = DEC_FLOAT_3; } } decFmt.posoff = decOff; - decOff += DecFmtSize(decFmt.posfmt); + decOff += DecFmtSize(DecVtxFormat::PosFmt()); } decFmt.stride = options.alignOutputToWord ? align(decOff, 4) : decOff; @@ -1279,7 +1276,6 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options, ERROR_LOG_REPORT(G3D, "Vertices without position found: (%08x) %s", fmt_, temp); } - _assert_msg_(decFmt.posfmt == DEC_FLOAT_3, "Reader only supports float pos"); _assert_msg_(decFmt.uvfmt == DEC_FLOAT_2 || decFmt.uvfmt == DEC_NONE, "Reader only supports float UV"); // Attempt to JIT as well. But only do that if the main CPU JIT is enabled, in order to aid diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index 5e13332f707c..3a0de590bd83 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -67,8 +67,6 @@ enum { DEC_U16_4, }; -int DecFmtSize(u8 fmt); - struct DecVtxFormat { u8 w0fmt; u8 w0off; // first 4 weights u8 w1fmt; u8 w1off; // second 4 weights @@ -76,12 +74,14 @@ struct DecVtxFormat { u8 c0fmt; u8 c0off; // First color u8 c1fmt; u8 c1off; u8 nrmfmt; u8 nrmoff; - u8 posfmt; u8 posoff; + u8 posoff; // Output position format is always DEC_FLOAT_3. u8 stride; uint32_t id; void ComputeID(); void InitializeFromID(uint32_t id); + + static u8 PosFmt() { return DEC_FLOAT_3; } }; void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound); diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index 0deb056ef45b..1172e0ce292f 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -243,7 +243,7 @@ ID3D11InputLayout *DrawEngineD3D11::SetupDecFmtForDraw(D3D11VertexShader *vshade // POSITION // Always - VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, "POSITION", 0); + VertexAttribSetup(VertexElement, DecVtxFormat::PosFmt(), decFmt.posoff, "POSITION", 0); VertexElement++; // Create declaration diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index 276fde10a3dc..72f19884721b 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -206,7 +206,7 @@ IDirect3DVertexDeclaration9 *DrawEngineDX9::SetupDecFmtForDraw(const DecVtxForma // POSITION // Always - VertexAttribSetup(VertexElement, decFmt.posfmt, decFmt.posoff, D3DDECLUSAGE_POSITION, 0); + VertexAttribSetup(VertexElement, DecVtxFormat::PosFmt(), decFmt.posoff, D3DDECLUSAGE_POSITION, 0); VertexElement++; // End diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index 9949d0c37bb7..f48a9d80b332 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -218,7 +218,7 @@ GLRInputLayout *DrawEngineGLES::SetupDecFmtForDraw(const DecVtxFormat &decFmt) { VertexAttribSetup(ATTR_COLOR0, decFmt.c0fmt, decFmt.stride, decFmt.c0off, entries); VertexAttribSetup(ATTR_COLOR1, decFmt.c1fmt, decFmt.stride, decFmt.c1off, entries); VertexAttribSetup(ATTR_NORMAL, decFmt.nrmfmt, decFmt.stride, decFmt.nrmoff, entries); - VertexAttribSetup(ATTR_POSITION, decFmt.posfmt, decFmt.stride, decFmt.posoff, entries); + VertexAttribSetup(ATTR_POSITION, DecVtxFormat::PosFmt(), decFmt.stride, decFmt.posoff, entries); inputLayout = render_->CreateInputLayout(entries); inputLayoutMap_.Insert(key, inputLayout); diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index 05803e30286e..75d280590398 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -134,7 +134,7 @@ static int SetupVertexAttribs(VkVertexInputAttributeDescription attrs[], const D VertexAttribSetup(&attrs[count++], decFmt.nrmfmt, decFmt.nrmoff, PspAttributeLocation::NORMAL); } // Position is always there. - VertexAttribSetup(&attrs[count++], decFmt.posfmt, decFmt.posoff, PspAttributeLocation::POSITION); + VertexAttribSetup(&attrs[count++], DecVtxFormat::PosFmt(), decFmt.posoff, PspAttributeLocation::POSITION); return count; } From 64ee5675b85d8d831016ad9e7986bd6f9c6240f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 6 Oct 2023 09:41:31 +0200 Subject: [PATCH 2/5] Minor unrelated cleanup --- Core/MIPS/MIPSVFPUUtils.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Core/MIPS/MIPSVFPUUtils.cpp b/Core/MIPS/MIPSVFPUUtils.cpp index 2ba4efaa097b..d8196999ebfe 100644 --- a/Core/MIPS/MIPSVFPUUtils.cpp +++ b/Core/MIPS/MIPSVFPUUtils.cpp @@ -33,9 +33,6 @@ #pragma warning(disable: 4146) #endif -#define V(i) (currentMIPS->v[voffset[i]]) -#define VI(i) (currentMIPS->vi[voffset[i]]) - union float2int { uint32_t i; float f; @@ -164,12 +161,11 @@ void GetMatrixRows(int matrixReg, MatrixSize msize, u8 vecs[4]) { } } - void ReadVector(float *rd, VectorSize size, int reg) { int row; int length; switch (size) { - case V_Single: rd[0] = V(reg); return; // transpose = 0; row=(reg>>5)&3; length = 1; break; + case V_Single: rd[0] = currentMIPS->v[voffset[reg]]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; case V_Pair: row=(reg>>5)&2; length = 2; break; case V_Triple: row=(reg>>6)&1; length = 3; break; case V_Quad: row=(reg>>5)&2; length = 4; break; @@ -195,7 +191,7 @@ void WriteVector(const float *rd, VectorSize size, int reg) { int length; switch (size) { - case V_Single: if (!currentMIPS->VfpuWriteMask(0)) V(reg) = rd[0]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; + case V_Single: if (!currentMIPS->VfpuWriteMask(0)) currentMIPS->v[voffset[reg]] = rd[0]; return; // transpose = 0; row=(reg>>5)&3; length = 1; break; case V_Pair: row=(reg>>5)&2; length = 2; break; case V_Triple: row=(reg>>6)&1; length = 3; break; case V_Quad: row=(reg>>5)&2; length = 4; break; From 10ccbfd68c3dc8ca5c874708868eb069f77928e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 6 Oct 2023 12:24:59 +0200 Subject: [PATCH 3/5] Unify the clearing of variables after a draw call --- GPU/Common/DrawEngineCommon.h | 22 ++++++++++++++++++++++ GPU/D3D11/DrawEngineD3D11.cpp | 21 +-------------------- GPU/Directx9/DrawEngineDX9.cpp | 23 +---------------------- GPU/GLES/DrawEngineGLES.cpp | 24 +----------------------- GPU/Vulkan/DrawEngineVulkan.cpp | 19 +------------------ 5 files changed, 26 insertions(+), 83 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 3e9228bbfd8c..c2c781c6b329 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -195,6 +195,28 @@ class DrawEngineCommon { } } + inline void ResetAfterDrawInline() { + gpuStats.numFlushes++; + gpuStats.numDrawCalls += numDrawInds_; + gpuStats.numVertexDecodes += numDrawVerts_; + gpuStats.numVertsSubmitted += vertexCountInDrawCalls_; + + indexGen.Reset(); + decodedVerts_ = 0; + numDrawVerts_ = 0; + numDrawInds_ = 0; + vertexCountInDrawCalls_ = 0; + decodeIndsCounter_ = 0; + decodeVertsCounter_ = 0; + gstate_c.vertexFullAlpha = true; + + // Now seems as good a time as any to reset the min/max coords, which we may examine later. + gstate_c.vertBounds.minU = 512; + gstate_c.vertBounds.minV = 512; + gstate_c.vertBounds.maxU = 0; + gstate_c.vertBounds.maxV = 0; + } + uint32_t ComputeDrawcallsHash() const; bool useHWTransform_ = false; diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index 1172e0ce292f..f04385bb6fdc 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -725,27 +725,8 @@ void DrawEngineD3D11::DoFlush() { decOptions_.applySkinInDecode = g_Config.bSoftwareSkinning; } - gpuStats.numFlushes++; - gpuStats.numDrawCalls += numDrawInds_; - gpuStats.numVertexDecodes += numDrawVerts_; - gpuStats.numVertsSubmitted += vertexCountInDrawCalls_; - - indexGen.Reset(); - decodedVerts_ = 0; - numDrawVerts_ = 0; - numDrawInds_ = 0; - vertexCountInDrawCalls_ = 0; - decodeVertsCounter_ = 0; - decodeIndsCounter_ = 0; - gstate_c.vertexFullAlpha = true; + ResetAfterDrawInline(); framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason); - - // Now seems as good a time as any to reset the min/max coords, which we may examine later. - gstate_c.vertBounds.minU = 512; - gstate_c.vertBounds.minV = 512; - gstate_c.vertBounds.maxU = 0; - gstate_c.vertBounds.maxV = 0; - GPUDebug::NotifyDraw(); } diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index 72f19884721b..283ccd375ed3 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -666,29 +666,8 @@ void DrawEngineDX9::DoFlush() { decOptions_.applySkinInDecode = g_Config.bSoftwareSkinning; } - gpuStats.numFlushes++; - gpuStats.numDrawCalls += numDrawInds_; - gpuStats.numVertexDecodes += numDrawVerts_; - gpuStats.numVertsSubmitted += vertexCountInDrawCalls_; - - // TODO: The below should be shared. - - indexGen.Reset(); - decodedVerts_ = 0; - numDrawVerts_ = 0; - numDrawInds_ = 0; - vertexCountInDrawCalls_ = 0; - decodeVertsCounter_ = 0; - decodeIndsCounter_ = 0; - gstate_c.vertexFullAlpha = true; + ResetAfterDrawInline(); framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason); - - // Now seems as good a time as any to reset the min/max coords, which we may examine later. - gstate_c.vertBounds.minU = 512; - gstate_c.vertBounds.minV = 512; - gstate_c.vertBounds.maxU = 0; - gstate_c.vertBounds.maxV = 0; - GPUDebug::NotifyDraw(); } diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index f48a9d80b332..7aefa970bca2 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -473,30 +473,8 @@ void DrawEngineGLES::DoFlush() { } bail: - gpuStats.numFlushes++; - gpuStats.numDrawCalls += numDrawInds_; - gpuStats.numVertexDecodes += numDrawVerts_; - gpuStats.numVertsSubmitted += vertexCountInDrawCalls_; - - // TODO: When the next flush has the same vertex format, we can continue with the same offset in the vertex buffer, - // and start indexing from a higher value. This is very friendly to OpenGL (where we can't rely on baseindex if we - // wanted to avoid rebinding the vertex input every time). - indexGen.Reset(); - decodedVerts_ = 0; - numDrawVerts_ = 0; - numDrawInds_ = 0; - vertexCountInDrawCalls_ = 0; - decodeVertsCounter_ = 0; - decodeIndsCounter_ = 0; - gstate_c.vertexFullAlpha = true; + ResetAfterDrawInline(); framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason); - - // Now seems as good a time as any to reset the min/max coords, which we may examine later. - gstate_c.vertBounds.minU = 512; - gstate_c.vertBounds.minV = 512; - gstate_c.vertBounds.maxU = 0; - gstate_c.vertBounds.maxV = 0; - GPUDebug::NotifyDraw(); } diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index ed83c7f20756..1f9a1f26dc6a 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -1014,27 +1014,10 @@ void DrawEngineVulkan::DoFlush() { decOptions_.applySkinInDecode = g_Config.bSoftwareSkinning; } - gpuStats.numFlushes++; - gpuStats.numDrawCalls += numDrawInds_; - gpuStats.numVertexDecodes += numDrawVerts_; - gpuStats.numVertsSubmitted += vertexCountInDrawCalls_; + ResetAfterDrawInline(); - indexGen.Reset(); - decodedVerts_ = 0; - numDrawVerts_ = 0; - numDrawInds_ = 0; - vertexCountInDrawCalls_ = 0; - decodeIndsCounter_ = 0; - decodeVertsCounter_ = 0; - gstate_c.vertexFullAlpha = true; framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason); - // Now seems as good a time as any to reset the min/max coords, which we may examine later. - gstate_c.vertBounds.minU = 512; - gstate_c.vertBounds.minV = 512; - gstate_c.vertBounds.maxU = 0; - gstate_c.vertBounds.maxV = 0; - GPUDebug::NotifyDraw(); } From 42164b37d6196875acceb549171b1e9c7158e406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 22 Aug 2023 17:10:25 +0200 Subject: [PATCH 4/5] Gradle: Fix some deprecation warnings --- android/build.gradle | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c2e08dc091d5..1acfad56d264 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -45,10 +45,9 @@ android { } } - compileSdkVersion 33 + compileSdk 33 ndkVersion "21.4.7075529" - defaultConfig { applicationId 'org.ppsspp.ppsspp' if (androidGitVersion.name() != "unknown" && androidGitVersion.code() >= 14000000) { @@ -63,8 +62,8 @@ android { new File("versionname.txt").write(androidGitVersion.name()) new File("versioncode.txt").write(androidGitVersion.code().toString()) - minSdkVersion 9 - targetSdkVersion 33 + minSdk 9 + targetSdk 33 if (project.hasProperty("ANDROID_VERSION_CODE") && project.hasProperty("ANDROID_VERSION_NAME")) { versionCode ANDROID_VERSION_CODE versionName ANDROID_VERSION_NAME From 5711259b868250fbf3a5b9113df217b66a9c0d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 6 Oct 2023 15:40:13 +0200 Subject: [PATCH 5/5] Declare the back depth buffer as "transient". Allows allocating no memory for it on tiled GPUs. We can't do the same for other depth buffers as we often need to preserve them between passes. --- Common/GPU/Vulkan/VulkanQueueRunner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index e6bb324f76c7..1ce5f05ea559 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -173,7 +173,7 @@ bool VulkanQueueRunner::InitDepthStencilBuffer(VkCommandBuffer cmd) { image_info.queueFamilyIndexCount = 0; image_info.pQueueFamilyIndices = nullptr; image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; image_info.flags = 0; depth_.format = depth_format;