From b93925c3061301f4a771a04579cfbbec5e78f993 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sun, 15 Mar 2026 15:31:01 +0100 Subject: [PATCH] fix: inconsistencies on t5 technique compilation --- src/Common/Game/T5/T5_Assets.h | 6 +++-- .../Game/T5/Techset/TechsetConstantsT5.h | 16 ++++++++++--- src/ObjCommon/Techset/CommonTechnique.h | 1 + .../Techset/CommonShaderArgCreator.cpp | 24 ++++++++++++++++--- .../Material/MaterialConstantZoneStateT5.cpp | 18 ++++++++++++++ .../Techset/CommonTechniqueDumper.cpp | 13 +++++----- 6 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/Common/Game/T5/T5_Assets.h b/src/Common/Game/T5/T5_Assets.h index 1e42c95b..077a82ef 100644 --- a/src/Common/Game/T5/T5_Assets.h +++ b/src/Common/Game/T5/T5_Assets.h @@ -1533,8 +1533,10 @@ namespace T5 // - Any polygon offset that is not GFXS1_POLYGON_OFFSET_0 TECHNIQUE_FLAG_80 = 0x80, - TECHNIQUE_FLAG_100 = 0x100, - TECHNIQUE_FLAG_200 = 0x200, + // Uses marksHitNormal + MTL_TECHFLAG_USES_MARKS_HIT_NORMAL = 0x100, + // Uses __characterCharredAmount or destructibleParms. Not sure how those two relate? + MTL_TECHFLAG_200 = 0x200, }; struct MaterialPass diff --git a/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h b/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h index 8ea418de..a382caeb 100644 --- a/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h +++ b/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h @@ -315,6 +315,7 @@ namespace T5 .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, .techFlags = MTL_TECHFLAG_USES_LIGHT_SPOT_FACTORS, + .techFlagShaderType = techset::CommonTechniqueShaderType::PIXEL, }, { .value = CONST_SRC_CODE_LIGHT_ATTENUATION, @@ -730,6 +731,7 @@ namespace T5 .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, .techFlags = MTL_TECHFLAG_USES_GRASS, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_GRASS_FORCE0, @@ -737,6 +739,7 @@ namespace T5 .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, .techFlags = MTL_TECHFLAG_USES_GRASS, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_GRASS_FORCE1, @@ -744,6 +747,7 @@ namespace T5 .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, .techFlags = MTL_TECHFLAG_USES_GRASS, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_GRASS_WIND_FORCE0, @@ -751,6 +755,7 @@ namespace T5 .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, .techFlags = MTL_TECHFLAG_USES_GRASS, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_MOTIONBLUR_DIRECTION_AND_MAGNITUDE, @@ -841,7 +846,8 @@ namespace T5 .accessor = "destructibleParms", .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, - .techFlags = TECHNIQUE_FLAG_200, + .techFlags = MTL_TECHFLAG_200, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_CLOUD_WORLD_AREA, @@ -866,7 +872,8 @@ namespace T5 .accessor = "__characterCharredAmount", .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, - .techFlags = TECHNIQUE_FLAG_200, + .techFlags = MTL_TECHFLAG_200, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_TREECANOPY_PARMS, @@ -879,6 +886,8 @@ namespace T5 .accessor = "marksHitNormal", .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_PRIM, + .techFlags = MTL_TECHFLAG_USES_MARKS_HIT_NORMAL, + .techFlagShaderType = techset::CommonTechniqueShaderType::VERTEX, }, { .value = CONST_SRC_CODE_POSTFX_CONTROL0, @@ -1587,7 +1596,7 @@ namespace T5 .value = TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY, .accessor = "lightmapSamplerPrimary", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, - .customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_SECONDARY, + .customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_PRIMARY, }, { .value = TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY, @@ -1709,6 +1718,7 @@ namespace T5 .value = TEXTURE_SRC_CODE_REFLECTION_PROBE, .accessor = "reflectionProbeSampler", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + .customSamplerIndex = CUSTOM_SAMPLER_REFLECTION_PROBE, }, { .value = TEXTURE_SRC_CODE_FEATHER_FLOAT_Z, diff --git a/src/ObjCommon/Techset/CommonTechnique.h b/src/ObjCommon/Techset/CommonTechnique.h index 8e54aa40..3f2153a5 100644 --- a/src/ObjCommon/Techset/CommonTechnique.h +++ b/src/ObjCommon/Techset/CommonTechnique.h @@ -79,6 +79,7 @@ namespace techset std::uint8_t arrayCount; CommonCodeSourceUpdateFrequency updateFrequency; std::optional techFlags; + std::optional techFlagShaderType; std::optional transposedMatrix; }; diff --git a/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp b/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp index adcbc615..87ae4f3e 100644 --- a/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp +++ b/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp @@ -277,7 +277,7 @@ namespace } m_args.emplace_back(argumentType, commonDestination, techset::CommonShaderArgValue{.code_const_source = value}); - if (maybeInfo->techFlags) + if (maybeInfo->techFlags && (!maybeInfo->techFlagShaderType || *maybeInfo->techFlagShaderType == m_shader_type)) m_tech_flags |= *maybeInfo->techFlags; return NoResult{}; @@ -515,7 +515,7 @@ namespace return std::move(result); } - if (constInfo->techFlags) + if (constInfo->techFlags && (!constInfo->techFlagShaderType || *constInfo->techFlagShaderType == m_shader_type)) m_tech_flags |= *constInfo->techFlags; return NoResult{}; @@ -825,6 +825,15 @@ namespace result::Expected AutoCreateConstantArg(const d3d11::ConstantBufferVariable& variable, const size_t bufferIndex) { + if (!IsArgumentTypeSupported( + techset::CommonShaderArgumentType{.m_shader_type = m_shader_type, .m_value_type = techset::CommonShaderValueType::CODE_CONST})) + { + con::warn("Shader {} uses unsupported argument type \"{} constant\". This may cause unstable behaviour.", + m_shader_name, + ShaderTypeName(m_shader_type)); + return NoResult{}; + } + const auto maybeCodeConst = m_common_code_source_infos.GetCodeConstSourceForAccessor(variable.m_name); if (!maybeCodeConst) { @@ -862,7 +871,7 @@ namespace return std::move(result); } - if (constInfo->techFlags) + if (constInfo->techFlags && (!constInfo->techFlagShaderType || *constInfo->techFlagShaderType == m_shader_type)) m_tech_flags |= *constInfo->techFlags; return NoResult{}; @@ -870,6 +879,15 @@ namespace result::Expected AutoCreateSamplerArg(const d3d11::BoundResource& textureResource, const unsigned samplerBindPoint) { + if (!IsArgumentTypeSupported( + techset::CommonShaderArgumentType{.m_shader_type = m_shader_type, .m_value_type = techset::CommonShaderValueType::CODE_SAMPLER})) + { + con::warn("Shader {} uses unsupported argument type \"{} sampler\". This may cause unstable behaviour.", + m_shader_name, + ShaderTypeName(m_shader_type)); + return NoResult{}; + } + const auto maybeCodeSampler = m_common_code_source_infos.GetCodeSamplerSourceForAccessor(textureResource.m_name); if (!maybeCodeSampler) return result::Unexpected(std::format("Missing assignment to shader texture {}", textureResource.m_name)); diff --git a/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp b/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp index 3293c570..37fe8827 100644 --- a/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp +++ b/src/ObjWriting/Game/T5/Material/MaterialConstantZoneStateT5.cpp @@ -33,6 +33,7 @@ namespace "DarkenPower", "Detail_Amount", "Detail_Normal_Tile", + "Diffuse_MapSampler", "Diffuse_Normal_Height_Facing", "Dimensions", "DispersionAmount", @@ -44,6 +45,7 @@ namespace "EdgeMinDist", "EdgeSize", "Edge_Color_Multiplier", + "Edge_Intensity", "Emissive_Amount", "EnemiesColor", "Exposure", @@ -143,6 +145,7 @@ namespace "NormalHeightMultiplier", "Normal_Detail_Height", "Normal_Detail_Scale", + "Normal_MapSampler", "Normal_Map_Size_Scale", "Normal_Variance_Scale", "NumFrames", @@ -157,6 +160,7 @@ namespace "Player_Lookup_Scale", "PositiveColor", "Power", + "PreviewCompID", "PulseColor", "PulseInterval", "PulseTime", @@ -165,6 +169,7 @@ namespace "Radius", "ReflectionAmount", "Reflection_Amount", + "Reflection_Amt", "Reflection_Blur", "Reticle_Alt_Color", "Reticle_Color", @@ -177,6 +182,7 @@ namespace "ScanlineSpeed", "ScatterAmount", "ScatterSize", + "Scatter_Intensity", "SceneNoise", "SparkleBrightness", "SparkleDensity", @@ -189,6 +195,7 @@ namespace "SpecularAmount", "SpecularColor", "Specular_Amount", + "Specular_Color", "Specular_Decay_Threshold", "Speed", "StaticAmount", @@ -202,6 +209,7 @@ namespace "TearLookupSpeed", "TearMultiplier", "TearPower", + "Temporal_Sharpness", "Thickness", "TickMarkColorAndHarshness", "Tint", @@ -221,6 +229,9 @@ namespace "WaterScale2", "WaterSpeed1", "WaterSpeed2", + "Wetness_Color", + "Wetness_Color_Gloss_Bias", + "Wetness_Specular_Swatch_Scale", "Zoom", "alphaDissolveParms", "alphaRevealParms", @@ -230,6 +241,11 @@ namespace "alphaRevealParms4", "clipSpaceLookupOffset", "clipSpaceLookupScale", + "cloakTextureControl0", + "cloakTextureControl1", + "clothcharrColorMapScale", + "clothcharrEmberColorAndBrightness", + "clothcharrMaskMapScale", "cloudsFeather", "cloudsHeights", "cloudsUVMad1", @@ -333,6 +349,7 @@ namespace "CompassMap", "Detail_Map", "Diffuse", + "DiffuseBurnt2", "Diffuse_Map", "DpadTexture", "FontTextutre", @@ -374,6 +391,7 @@ namespace "Static", "StaticMap", "Static_Noise_Map", + "Stretch_Map", "SunShadowSamplerState", "SunShadowState", "Surface_Normal_Map", diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp index 0be6f401..2c6c9ffc 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp @@ -231,6 +231,7 @@ namespace static_cast(arg.m_type.m_value_type)); return; } + const auto buffer = std::ranges::find_if(shaderInfo.m_constant_buffers, [&boundResource](const d3d11::ConstantBuffer& constantBuffer) { @@ -409,15 +410,15 @@ namespace Indent(); std::string materialPropertyName; - if (m_constant_zone_state.GetConstantName(arg.m_value.name_hash, materialPropertyName) - || m_constant_zone_state.GetTextureDefName(arg.m_value.name_hash, materialPropertyName)) - { - m_stream << std::format("{} = material.{};\n", codeDestAccessor, materialPropertyName); - } - else if (m_constant_zone_state.HashString(codeDestAccessor) == arg.m_value.name_hash) + if (m_constant_zone_state.HashString(codeDestAccessor) == arg.m_value.name_hash) { m_stream << std::format("{} = material.{};\n", codeDestAccessor, codeDestAccessor); } + else if (m_constant_zone_state.GetConstantName(arg.m_value.name_hash, materialPropertyName) + || m_constant_zone_state.GetTextureDefName(arg.m_value.name_hash, materialPropertyName)) + { + m_stream << std::format("{} = material.{};\n", codeDestAccessor, materialPropertyName); + } else { m_stream << std::format("{} = material.#0x{:x};\n", codeDestAccessor, arg.m_value.name_hash);