From fbfd418e20ceb505f041aa6114ac99ea6c93a0c5 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sat, 7 Mar 2026 10:32:53 +0000 Subject: [PATCH] feat: add templated technique compiler for IW4 --- src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp | 3 + .../Techset/TechniqueCompiler.cpp.template | 61 ++++++++++++++++++- .../Techset/TechniqueCompiler.h.template | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp index 79a9723a..88457744 100644 --- a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp +++ b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp @@ -1,6 +1,7 @@ #include "ObjCompilerIW4.h" #include "Game/IW4/IW4.h" +#include "Game/IW4/Techset/TechniqueCompilerIW4.h" #include "Game/IW4/Techset/TechsetCompilerIW4.h" #include "Game/IW4/Techset/VertexDeclCompilerIW4.h" #include "Image/ImageIwdPostProcessor.h" @@ -21,6 +22,8 @@ namespace #endif collection.AddAssetCreator(techset::CreateVertexDeclCompilerIW4(memory)); collection.AddAssetCreator(techset::CreateTechsetCompilerIW4(memory, searchPath)); + + collection.AddSubAssetCreator(techset::CreateTechniqueCompilerIW4(memory, zone, searchPath)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, diff --git a/src/ObjCompiling/Techset/TechniqueCompiler.cpp.template b/src/ObjCompiling/Techset/TechniqueCompiler.cpp.template index 4fff5f44..0bd9b10d 100644 --- a/src/ObjCompiling/Techset/TechniqueCompiler.cpp.template +++ b/src/ObjCompiling/Techset/TechniqueCompiler.cpp.template @@ -1,4 +1,4 @@ -#options GAME(T6) +#options GAME(IW4, T6) #filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".cpp" @@ -8,14 +8,21 @@ #if GAME == "IW3" #define FEATURE_IW3 +#define IS_DX9 #elif GAME == "IW4" #define FEATURE_IW4 +#define IS_DX9 #elif GAME == "IW5" #define FEATURE_IW5 +#define IS_DX9 #elif GAME == "T5" #define FEATURE_T5 +#define IS_DX9 +#define SHADERS_ARE_SUBASSETS #elif GAME == "T6" #define FEATURE_T6 +#define IS_DX11 +#define SHADERS_ARE_SUBASSETS #endif // This file was templated. @@ -131,6 +138,9 @@ namespace arg.type = static_cast(ConvertArgumentType(commonArg.m_type)); +#if defined(IS_DX9) + arg.dest = static_cast(commonArg.m_destination.dx9.m_destination_register); +#else arg.size = static_cast(commonArg.m_destination.dx11.m_size); arg.buffer = static_cast(commonArg.m_destination.dx11.m_buffer); @@ -146,6 +156,7 @@ namespace arg.location.samplerIndex = static_cast(commonArg.m_destination.dx11.m_location.sampler_index); } +#endif ConvertArgumentValue(arg.u, commonArg, memory, context); } @@ -161,7 +172,11 @@ namespace } const std::string declName(nameStream.str()); +#if defined(SHADERS_ARE_SUBASSETS) auto* vertexDeclAsset = context.LoadSubAsset(declName); +#else + auto* vertexDeclAsset = context.LoadDependency(declName); +#endif assert(vertexDeclAsset); pass.vertexDecl = vertexDeclAsset ? vertexDeclAsset->Asset() : nullptr; } @@ -172,14 +187,22 @@ namespace if (!commonPass.m_vertex_shader.m_name.empty()) { +#if defined(SHADERS_ARE_SUBASSETS) auto* vertexShaderAsset = context.LoadSubAsset(commonPass.m_vertex_shader.m_name); +#else + auto* vertexShaderAsset = context.LoadDependency(commonPass.m_vertex_shader.m_name); +#endif assert(vertexShaderAsset); pass.vertexShader = vertexShaderAsset ? vertexShaderAsset->Asset() : nullptr; } if (!commonPass.m_pixel_shader.m_name.empty()) { +#if defined(SHADERS_ARE_SUBASSETS) auto* pixelShaderAsset = context.LoadSubAsset(commonPass.m_pixel_shader.m_name); +#else + auto* pixelShaderAsset = context.LoadDependency(commonPass.m_pixel_shader.m_name); +#endif assert(pixelShaderAsset); pass.pixelShader = pixelShaderAsset ? pixelShaderAsset->Asset() : nullptr; } @@ -205,6 +228,9 @@ namespace void UpdateTechniqueFlags(MaterialTechnique& technique, const techset::CommonTechnique& commonTechnique) { +#if defined(FEATURE_IW4) + // TODO +#elif defined(FEATURE_T6) std::string lowerTechniqueName(commonTechnique.m_name); utils::MakeStringLowerCase(lowerTechniqueName); @@ -215,9 +241,14 @@ namespace { technique.flags |= TECHNIQUE_FLAG_4; } +#endif if (AnyDeclHasOptionalSource(technique)) +#if defined(FEATURE_IW4) + technique.flags |= TECHNIQUE_FLAG_20; +#elif defined(FEATURE_T6) technique.flags |= TECHNIQUE_FLAG_8; +#endif } MaterialTechnique* ConvertTechnique(const techset::CommonTechnique& commonTechnique, AssetCreationContext& context, MemoryManager& memory) @@ -241,6 +272,7 @@ namespace return technique; } +#if defined(FEATURE_T6) void ApplyTechFlagsFromMaterial(const Material& material, const Zone& zone) { if (!material.techniqueSet || !material.techniqueSet->name || !material.stateBitsTable) @@ -266,6 +298,7 @@ namespace technique->flags |= TECHNIQUE_FLAG_80; } } +#endif class SHADER_LOADER_CLASS_NAME final : public techset::ITechniqueShaderLoader { @@ -277,7 +310,11 @@ namespace std::optional LoadVertexShader(const std::string& name) override { +#if defined(SHADERS_ARE_SUBASSETS) auto* shaderAsset = m_context.LoadSubAsset(name); +#else + auto* shaderAsset = m_context.ForceLoadDependency(name); +#endif if (!shaderAsset) return std::nullopt; @@ -288,13 +325,22 @@ namespace return techset::CommonTechniqueShaderBin{ .m_shader_bin = shader->prog.loadDef.program, +#if defined(IS_DX9) + .m_shader_bin_size = + static_cast(shader->prog.loadDef.programSize) * sizeof(std::remove_pointer_t), +#else .m_shader_bin_size = shader->prog.loadDef.programSize, +#endif }; } std::optional LoadPixelShader(const std::string& name) override { +#if defined(SHADERS_ARE_SUBASSETS) auto* shaderAsset = m_context.LoadSubAsset(name); +#else + auto* shaderAsset = m_context.ForceLoadDependency(name); +#endif if (!shaderAsset) return std::nullopt; @@ -305,7 +351,12 @@ namespace return techset::CommonTechniqueShaderBin{ .m_shader_bin = shader->prog.loadDef.program, +#if defined(IS_DX9) + .m_shader_bin_size = + static_cast(shader->prog.loadDef.programSize) * sizeof(std::remove_pointer_t), +#else .m_shader_bin_size = shader->prog.loadDef.programSize, +#endif }; } @@ -327,7 +378,11 @@ namespace { bool failure = false; SHADER_LOADER_CLASS_NAME shaderLoader(context); +#if defined(IS_DX9) + const auto commonShaderArgCreator = techset::CommonShaderArgCreator::CreateDx9(shaderLoader, context, commonCodeSourceInfos); +#else const auto commonShaderArgCreator = techset::CommonShaderArgCreator::CreateDx11(shaderLoader, context, commonCodeSourceInfos); +#endif const auto commonTechnique = techset::LoadCommonTechnique(subAssetName, commonCodeSourceInfos, commonRoutingInfos, *commonShaderArgCreator, m_search_path, failure); @@ -343,6 +398,9 @@ namespace void FinalizeZone(AssetCreationContext& context) override { +#if defined(FEATURE_IW4) + // TODO +#elif defined(FEATURE_T6) const auto materials = m_zone.m_pools.PoolAssets(); for (auto* materialAsset : materials) { @@ -358,6 +416,7 @@ namespace ApplyPrecompiledIndex(technique.passArray[passIndex]); } } +#endif } private: diff --git a/src/ObjCompiling/Techset/TechniqueCompiler.h.template b/src/ObjCompiling/Techset/TechniqueCompiler.h.template index a1310e61..f858775d 100644 --- a/src/ObjCompiling/Techset/TechniqueCompiler.h.template +++ b/src/ObjCompiling/Techset/TechniqueCompiler.h.template @@ -1,4 +1,4 @@ -#options GAME(T6) +#options GAME(IW4, T6) #filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".h"