From 7ab9adc17cf914170975323f8a8d3ad4b86b47eb Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sun, 1 Mar 2026 13:31:24 +0100 Subject: [PATCH] chore: handle flag 80 on t6 techniques --- src/ObjCompiling/Game/T6/ObjCompilerT6.cpp | 2 +- .../Game/T6/Techset/TechniqueCompilerT6.cpp | 38 +++++++++++++++++-- .../Game/T6/Techset/TechniqueCompilerT6.h | 2 +- .../Asset/AssetCreatorCollection.cpp | 2 + .../Techset/CommonTechniqueDumper.cpp | 9 ++++- src/ZoneCommon/Pool/AssetPool.h | 4 +- .../T6/Techset/TechniqueCompilerT6Test.cpp | 2 +- 7 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp index 7a825ec8..34e0cbb1 100644 --- a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp @@ -25,7 +25,7 @@ namespace collection.AddAssetCreator(key_value_pairs::CreateCompilerT6(memory, zone, zoneDefinition.m_zone_definition, zoneStates)); collection.AddAssetCreator(techset::CreateCompilerT6(memory, searchPath)); - collection.AddSubAssetCreator(techset::CreateTechniqueCompilerT6(memory, searchPath)); + collection.AddSubAssetCreator(techset::CreateTechniqueCompilerT6(memory, zone, searchPath)); collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerT6(memory)); } diff --git a/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp index d33d6cb1..08e285f3 100644 --- a/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp @@ -207,6 +207,27 @@ namespace return technique; } + void ApplyTechFlagsFromMaterial(const Material& material) + { + if (!material.techniqueSet || material.stateBitsTable) + return; + + for (auto techType = 0u; techType < TECHNIQUE_COUNT; techType++) + { + auto* technique = material.techniqueSet->techniques[techType]; + const auto stateBitsEntry = material.stateBitsEntry[techType]; + + if (!technique || stateBitsEntry < 0 || static_cast(stateBitsEntry) >= material.stateBitsCount) + continue; + + const auto& stateBits = material.stateBitsTable[static_cast(stateBitsEntry)].loadBits; + const bool shouldSetFlag80 = stateBits.structured.depthTestDisabled == 0 || stateBits.structured.depthWrite > 0 + || stateBits.structured.depthTest > 0 || stateBits.structured.polygonOffset > 0; + if (shouldSetFlag80) + technique->flags |= TECHNIQUE_FLAG_80; + } + } + class TechniqueShaderLoaderT6 final : public techset::ITechniqueShaderLoader { public: @@ -256,8 +277,9 @@ namespace class TechniqueCompilerT6 final : public SubAssetCreator { public: - TechniqueCompilerT6(MemoryManager& memory, ISearchPath& searchPath) + TechniqueCompilerT6(MemoryManager& memory, Zone& zone, ISearchPath& searchPath) : m_memory(memory), + m_zone(zone), m_search_path(searchPath) { } @@ -280,16 +302,26 @@ namespace return AssetCreationResult::Success(context.AddSubAsset(AssetRegistration(subAssetName, convertedTechnique))); } + void FinalizeZone(AssetCreationContext& context) override + { + const auto materials = m_zone.m_pools.PoolAssets(); + for (auto* materialAsset : materials) + { + ApplyTechFlagsFromMaterial(*materialAsset->Asset()); + } + } + private: MemoryManager& m_memory; + Zone& m_zone; ISearchPath& m_search_path; }; } // namespace namespace techset { - std::unique_ptr CreateTechniqueCompilerT6(MemoryManager& memory, ISearchPath& searchPath) + std::unique_ptr CreateTechniqueCompilerT6(MemoryManager& memory, Zone& zone, ISearchPath& searchPath) { - return std::make_unique(memory, searchPath); + return std::make_unique(memory, zone, searchPath); } } // namespace techset diff --git a/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h index c859d4d0..869acca8 100644 --- a/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h +++ b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h @@ -8,5 +8,5 @@ namespace techset { - std::unique_ptr CreateTechniqueCompilerT6(MemoryManager& memory, ISearchPath& searchPath); + std::unique_ptr CreateTechniqueCompilerT6(MemoryManager& memory, Zone& zone, ISearchPath& searchPath); } diff --git a/src/ObjLoading/Asset/AssetCreatorCollection.cpp b/src/ObjLoading/Asset/AssetCreatorCollection.cpp index 13282c69..3edaabaa 100644 --- a/src/ObjLoading/Asset/AssetCreatorCollection.cpp +++ b/src/ObjLoading/Asset/AssetCreatorCollection.cpp @@ -111,6 +111,8 @@ AssetCreationResult AssetCreatorCollection::CreateDefaultAsset(const asset_type_ void AssetCreatorCollection::FinalizeZone(AssetCreationContext& context) const { + for (const auto& creator : m_sub_asset_creators) + creator->FinalizeZone(context); for (const auto& creator : m_asset_creators) creator->FinalizeZone(context); for (const auto& postProcessor : m_asset_post_processors) diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp index d5c64043..8afb185c 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp @@ -317,11 +317,12 @@ namespace if (arg.m_type.m_value_type == CommonShaderValueType::CODE_CONST) { auto constSourceInfo = m_code_source_infos.GetInfoForCodeConstSource(arg.m_value.code_const_source.m_index); + const auto isMatrix = constSourceInfo && constSourceInfo->transposedMatrix.has_value(); if (isTransposed) { - assert(constSourceInfo); - if (constSourceInfo && constSourceInfo->transposedMatrix) + assert(isMatrix); + if (isMatrix) constSourceInfo = m_code_source_infos.GetInfoForCodeConstSource(*constSourceInfo->transposedMatrix); } @@ -333,6 +334,10 @@ namespace else codeAccessor = std::format("{}[{}]", constSourceInfo->accessor, arg.m_value.code_const_source.m_index - constSourceInfo->value); + // Assert that the value uses 4 rows when matrix and 1 otherwise. + // If this is untrue, there must be more code handling the selected rows + assert((isMatrix && arg.m_value.code_const_source.m_row_count == 4) || arg.m_value.code_const_source.m_row_count == 1); + if (codeDestAccessor != codeAccessor) { Indent(); diff --git a/src/ZoneCommon/Pool/AssetPool.h b/src/ZoneCommon/Pool/AssetPool.h index 55f25cd0..27cc7266 100644 --- a/src/ZoneCommon/Pool/AssetPool.h +++ b/src/ZoneCommon/Pool/AssetPool.h @@ -102,12 +102,12 @@ public: { } - AssetPoolIterator begin() + AssetPoolIterator begin() const { return AssetPoolIterator(m_asset_pool.begin()); } - AssetPoolIterator end() + AssetPoolIterator end() const { return AssetPoolIterator(m_asset_pool.end()); } diff --git a/test/ObjCompilingTests/Game/T6/Techset/TechniqueCompilerT6Test.cpp b/test/ObjCompilingTests/Game/T6/Techset/TechniqueCompilerT6Test.cpp index 3ddd149d..43b0c4aa 100644 --- a/test/ObjCompilingTests/Game/T6/Techset/TechniqueCompilerT6Test.cpp +++ b/test/ObjCompilingTests/Game/T6/Techset/TechniqueCompilerT6Test.cpp @@ -69,7 +69,7 @@ TEST_CASE("TechniqueCompilerT6", "[t6][techset][compiler]") creatorCollection.AddSubAssetCreator(techset::CreateVertexShaderLoaderT6(memory, searchPath)); creatorCollection.AddSubAssetCreator(techset::CreatePixelShaderLoaderT6(memory, searchPath)); - auto loader = techset::CreateTechniqueCompilerT6(memory, searchPath); + auto loader = techset::CreateTechniqueCompilerT6(memory, zone, searchPath); SECTION("Can compile simple technique") {