From e92d839e4b504213184e91788a925e902d2c61df Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Tue, 26 Nov 2024 23:02:16 +0300 Subject: [PATCH] Account for ConstTexCoord. --- .../MirageCore/RenderData/hhShaderListData.h | 2 +- .../MirageCore/RenderData/hhTexsetData.h | 24 +++++++++ .../MirageCore/RenderData/hhTextureData.h | 17 ++++++ UnleashedRecomp/api/SWA.h | 2 + UnleashedRecomp/gpu/video.cpp | 54 +++++++++++++++++-- 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTexsetData.h create mode 100644 UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTextureData.h diff --git a/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhShaderListData.h b/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhShaderListData.h index 6b94128d..3731fff8 100644 --- a/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhShaderListData.h +++ b/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhShaderListData.h @@ -27,7 +27,7 @@ namespace Hedgehog::Mirage public: hh::map> m_VertexShaderPermutations; hh::map, boost::shared_ptr> m_PixelShaders; - uint32_t m_SubPermutations; + be m_SubPermutations; }; SWA_ASSERT_OFFSETOF(CPixelShaderPermutationData, m_VertexShaderPermutations, 0x0); diff --git a/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTexsetData.h b/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTexsetData.h new file mode 100644 index 00000000..627bf04d --- /dev/null +++ b/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTexsetData.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include +#include + +namespace Hedgehog::Mirage +{ + class CTextureData; + + class CTexsetData : public Database::CDatabaseData + { + public: + hh::vector> m_TextureList; + hh::vector m_TextureNameList; + bool m_ConstTexCoord; + }; + + SWA_ASSERT_OFFSETOF(CTexsetData, m_TextureList, 0xC); + SWA_ASSERT_OFFSETOF(CTexsetData, m_TextureNameList, 0x1C); + SWA_ASSERT_OFFSETOF(CTexsetData, m_ConstTexCoord, 0x2C); + SWA_ASSERT_SIZEOF(CTexsetData, 0x30); +} diff --git a/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTextureData.h b/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTextureData.h new file mode 100644 index 00000000..cf8abbee --- /dev/null +++ b/UnleashedRecomp/api/Hedgehog/MirageCore/RenderData/hhTextureData.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace Hedgehog::Mirage +{ + class CTextureData : public Database::CDatabaseData + { + public: + SWA_INSERT_PADDING(0x8); + uint8_t m_TexcoordIndex; + SWA_INSERT_PADDING(0x1B); + }; + + SWA_ASSERT_OFFSETOF(CTextureData, m_TexcoordIndex, 0x14); + SWA_ASSERT_SIZEOF(CTextureData, 0x30); +} diff --git a/UnleashedRecomp/api/SWA.h b/UnleashedRecomp/api/SWA.h index 48434de9..c1691418 100644 --- a/UnleashedRecomp/api/SWA.h +++ b/UnleashedRecomp/api/SWA.h @@ -37,6 +37,8 @@ #include "Hedgehog/MirageCore/RenderData/hhPixelShaderData.h" #include "Hedgehog/MirageCore/RenderData/hhShaderListData.h" #include "Hedgehog/MirageCore/RenderData/hhTerrainModelData.h" +#include "Hedgehog/MirageCore/RenderData/hhTexsetData.h" +#include "Hedgehog/MirageCore/RenderData/hhTextureData.h" #include "Hedgehog/MirageCore/RenderData/hhVertexShaderCodeData.h" #include "Hedgehog/MirageCore/RenderData/hhVertexShaderData.h" #include "Hedgehog/MirageCore/Renderable/hhRenderable.h" diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 23b275ef..63ca9ae8 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -4340,6 +4340,20 @@ static void CompileMeshPipeline(Hedgehog::Mirage::CMeshData* mesh, MeshLayer lay auto& material = mesh->m_spMaterial; auto& shaderList = material->m_spShaderListData; + bool constTexCoord = true; + if (material->m_spTexsetData.get() != nullptr) + { + for (size_t i = 1; i < material->m_spTexsetData->m_TextureList.size(); i++) + { + if (material->m_spTexsetData->m_TextureList[i]->m_TexcoordIndex != + material->m_spTexsetData->m_TextureList[0]->m_TexcoordIndex) + { + constTexCoord = false; + break; + } + } + } + // Shadow pipeline. if (layer == MeshLayer::Opaque || layer == MeshLayer::PunchThrough) { @@ -4380,19 +4394,32 @@ static void CompileMeshPipeline(Hedgehog::Mirage::CMeshData* mesh, MeshLayer lay if (defaultFindResult == shaderList->m_PixelShaderPermutations.end()) return; + uint32_t pixelShaderSubPermutationsToCompile = 0; + if (constTexCoord) pixelShaderSubPermutationsToCompile |= 0x1; + if (args.noGI) pixelShaderSubPermutationsToCompile |= 0x2; + + if ((defaultFindResult->second.m_SubPermutations.get() & (1 << pixelShaderSubPermutationsToCompile)) == 0) + pixelShaderSubPermutationsToCompile &= ~0x1; + guest_stack_var noneSymbol(reinterpret_cast(g_memory.Translate(0x8200D938))); auto noneFindResult = defaultFindResult->second.m_VertexShaderPermutations.find(*noneSymbol); if (noneFindResult == defaultFindResult->second.m_VertexShaderPermutations.end()) return; + uint32_t vertexShaderSubPermutationsToCompile = 0; + if (constTexCoord) vertexShaderSubPermutationsToCompile |= 0x1; + + if ((noneFindResult->second->m_SubPermutations.get() & (1 << vertexShaderSubPermutationsToCompile)) == 0) + vertexShaderSubPermutationsToCompile &= ~0x1; + for (auto& [pixelShaderSubPermutations, pixelShader] : defaultFindResult->second.m_PixelShaders) { - if (pixelShader.get() == nullptr || (pixelShaderSubPermutations & 0x2) != (args.noGI ? 0x2 : 0x0)) + if (pixelShader.get() == nullptr || (pixelShaderSubPermutations & 0x3) != pixelShaderSubPermutationsToCompile) continue; for (auto& [vertexShaderSubPermutations, vertexShader] : noneFindResult->second->m_VertexShaders) { - if (vertexShader.get() == nullptr) + if (vertexShader.get() == nullptr || (vertexShaderSubPermutations & 0x1) != vertexShaderSubPermutationsToCompile) continue; PipelineState pipelineState{}; @@ -4583,7 +4610,28 @@ void GetModelDataMidAsmHook(PPCRegister& r1, PPCRegister& r31) static bool CheckMadeAll(Hedgehog::Mirage::CMeshData* meshData) { - return meshData->IsMadeOne() && (meshData->m_spMaterial.get() == nullptr || meshData->m_spMaterial->IsMadeOne()); + if (!meshData->IsMadeOne()) + return false; + + if (meshData->m_spMaterial.get() != nullptr) + { + if (!meshData->m_spMaterial->IsMadeOne()) + return false; + + if (meshData->m_spMaterial->m_spTexsetData.get() != nullptr) + { + if (!meshData->m_spMaterial->m_spTexsetData->IsMadeOne()) + return false; + + for (auto& texture : meshData->m_spMaterial->m_spTexsetData->m_TextureList) + { + if (!texture->IsMadeOne()) + return false; + } + } + } + + return true; } template