From bda33e7851133b805786213424112d0f577dd0f5 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Fri, 23 Jan 2026 21:55:27 +0000 Subject: [PATCH] wip --- src/Common/Game/IW3/GameIW3.cpp | 7 +- src/Common/Game/IW3/IW3.h | 1 + src/Common/Game/IW4/GameIW4.cpp | 6 +- src/Common/Game/IW5/GameIW5.cpp | 6 +- src/Common/Game/T5/GameT5.cpp | 7 +- src/Common/Game/T5/T5.h | 3 +- src/Common/Game/T5/T5_Assets.h | 4 + src/Common/Game/T6/GameT6.cpp | 7 +- src/Common/Game/T6/T6.h | 6 +- src/Common/Game/T6/T6_Assets.h | 56 ++-- src/Common/Techset/StateMap/StateMapLayout.h | 1 + .../Game/T5/Techset/TechsetConstantsT5.h | 25 ++ .../Game/T6/Techset/TechsetConstantsT6.h | 35 +++ src/ObjCommon/Techset/CommonTechnique.cpp | 199 +++++++++++++- src/ObjCommon/Techset/CommonTechnique.h | 160 +++++++++--- .../Techset/CommonVertexDeclCreator.cpp | 67 +++++ .../Techset/CommonVertexDeclCreator.h | 11 + .../Game/IW4/Material/CompilerMaterialIW4.cpp | 10 +- .../Game/IW4/Techset/CompilerTechsetIW4.cpp | 21 +- src/ObjCompiling/Game/T6/ObjCompilerT6.cpp | 5 + .../Game/T6/Techset/TechniqueCompilerT6.cpp | 223 ++++++++++++++++ .../Game/T6/Techset/TechniqueCompilerT6.h | 12 + .../Game/T6/Techset/TechsetCompilerT6.cpp | 13 + .../Game/T6/Techset/VertexDeclCompilerT6.cpp | 57 ++++ .../Game/T6/Techset/VertexDeclCompilerT6.h | 11 + .../Techset/CommonShaderArgCreator.cpp | 164 ++++++++++++ .../Techset/CommonShaderArgCreator.h | 61 +++++ .../Techset/CommonTechniqueLoader.cpp | 46 ++++ .../Techset/CommonTechniqueLoader.h | 10 +- .../Techset/CommonTechsetCache.cpp | 18 -- src/ObjCompiling/Techset/CommonTechsetCache.h | 21 -- .../Techset/CommonTechsetLoader.cpp | 1 - .../Sequence/TechniqueNoScopeSequences.cpp | 6 +- .../Sequence/TechniquePassScopeSequences.cpp | 72 +++-- .../TechniqueShaderScopeSequences.cpp | 195 +++++++++----- .../Techset/Parsing/TechniqueFileParser.cpp | 36 ++- .../Techset/Parsing/TechniqueFileParser.h | 12 +- .../Parsing/TechniqueFileParserState.cpp | 24 +- .../Parsing/TechniqueFileParserState.h | 22 +- .../StateMapFromTechniqueExtractor.cpp | 68 ----- .../StateMap/StateMapFromTechniqueExtractor.h | 40 --- .../Techset/StateMap/StateMapReader.h | 5 +- .../{ => StateMap}/TechniqueStateMapCache.cpp | 0 .../{ => StateMap}/TechniqueStateMapCache.h | 7 +- .../Techset/TechniqueDefinitionAcceptor.cpp | 116 -------- .../Techset/TechniqueDefinitionAcceptor.h | 100 ------- .../Techset/TechniqueFileReader.cpp | 39 --- .../Techset/TechniqueFileReader.h | 24 -- src/ObjLoading/Asset/AssetCreationContext.cpp | 6 +- .../Game/T6/Techset/PixelShaderLoaderT6.cpp | 0 .../Game/T6/Techset/PixelShaderLoaderT6.h | 0 .../Game/T6/Techset/VertexShaderLoaderT6.cpp | 0 .../Game/T6/Techset/VertexShaderLoaderT6.h | 0 .../Game/T5/Techset/TechsetDumperT5.cpp | 201 +++++--------- .../Game/T6/Techset/TechsetDumperT6.cpp | 247 +++++++----------- .../Techset/CommonTechniqueDumper.cpp | 16 +- .../Techset/CommonTechniqueDumper.h | 1 + 57 files changed, 1564 insertions(+), 947 deletions(-) create mode 100644 src/ObjCommon/Techset/CommonVertexDeclCreator.cpp create mode 100644 src/ObjCommon/Techset/CommonVertexDeclCreator.h create mode 100644 src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp create mode 100644 src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h create mode 100644 src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.cpp create mode 100644 src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.h create mode 100644 src/ObjCompiling/Techset/CommonShaderArgCreator.cpp create mode 100644 src/ObjCompiling/Techset/CommonShaderArgCreator.h delete mode 100644 src/ObjCompiling/Techset/CommonTechsetCache.cpp delete mode 100644 src/ObjCompiling/Techset/CommonTechsetCache.h delete mode 100644 src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.cpp delete mode 100644 src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.h rename src/ObjCompiling/Techset/{ => StateMap}/TechniqueStateMapCache.cpp (100%) rename src/ObjCompiling/Techset/{ => StateMap}/TechniqueStateMapCache.h (69%) delete mode 100644 src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.cpp delete mode 100644 src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.h delete mode 100644 src/ObjCompiling/Techset/TechniqueFileReader.cpp delete mode 100644 src/ObjCompiling/Techset/TechniqueFileReader.h create mode 100644 src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp create mode 100644 src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h create mode 100644 src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp create mode 100644 src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h diff --git a/src/Common/Game/IW3/GameIW3.cpp b/src/Common/Game/IW3/GameIW3.cpp index 31007508..b14dda08 100644 --- a/src/Common/Game/IW3/GameIW3.cpp +++ b/src/Common/Game/IW3/GameIW3.cpp @@ -8,18 +8,21 @@ using namespace IW3; namespace { - constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{ + constexpr const char* ASSET_TYPE_NAMES[]{ "xmodelpieces", "physpreset", "xanim", "xmodel", "material", "techniqueset", "image", "sound", "soundcurve", "loadedsound", "clipmap_unused", "clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents", "gfxworld", "lightdef", "uimap", "font", "menulist", "menu", "localize", "weapon", "snddriverglobals", "fx", "impactfx", "aitype", "mptype", "character", "xmodelalias", "rawfile", "stringtable", }; + static_assert(std::extent_v == ASSET_TYPE_COUNT); - constexpr const char* SUB_ASSET_TYPE_NAMES[SUB_ASSET_TYPE_COUNT]{ + constexpr const char* SUB_ASSET_TYPE_NAMES[]{ "technique", + "vertexdecl", "vertexshader", "pixelshader", }; + static_assert(std::extent_v == SUB_ASSET_TYPE_COUNT); } // namespace namespace IW3 diff --git a/src/Common/Game/IW3/IW3.h b/src/Common/Game/IW3/IW3.h index ee7d6856..bfc5c489 100644 --- a/src/Common/Game/IW3/IW3.h +++ b/src/Common/Game/IW3/IW3.h @@ -53,6 +53,7 @@ namespace IW3 enum SubAssetType { SUB_ASSET_TYPE_TECHNIQUE, + SUB_ASSET_TYPE_VERTEX_DECL, SUB_ASSET_TYPE_VERTEX_SHADER, SUB_ASSET_TYPE_PIXEL_SHADER, diff --git a/src/Common/Game/IW4/GameIW4.cpp b/src/Common/Game/IW4/GameIW4.cpp index a3ca8860..88a05a2e 100644 --- a/src/Common/Game/IW4/GameIW4.cpp +++ b/src/Common/Game/IW4/GameIW4.cpp @@ -8,7 +8,7 @@ using namespace IW4; namespace { - constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{ + constexpr const char* ASSET_TYPE_NAMES[]{ "physpreset", "physcollmap", "xanim", "xmodelsurfs", "xmodel", "material", "pixelshader", "vertexshader", "vertexdecl", "techniqueset", "image", "sound", "soundcurve", "loadedsound", "clipmap_unused", @@ -19,10 +19,12 @@ namespace "xmodelalias", "rawfile", "stringtable", "leaderboard", "structureddatadef", "tracer", "vehicle", "addonmapents", }; + static_assert(std::extent_v == ASSET_TYPE_COUNT); - constexpr const char* SUB_ASSET_TYPE_NAMES[SUB_ASSET_TYPE_COUNT]{ + constexpr const char* SUB_ASSET_TYPE_NAMES[]{ "technique", }; + static_assert(std::extent_v == SUB_ASSET_TYPE_COUNT); } // namespace namespace IW4 diff --git a/src/Common/Game/IW5/GameIW5.cpp b/src/Common/Game/IW5/GameIW5.cpp index f7dafcea..2a02dbb1 100644 --- a/src/Common/Game/IW5/GameIW5.cpp +++ b/src/Common/Game/IW5/GameIW5.cpp @@ -8,7 +8,7 @@ using namespace IW5; namespace { - constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{ + constexpr const char* ASSET_TYPE_NAMES[]{ "physpreset", "physcollmap", "xanim", @@ -56,10 +56,12 @@ namespace "vehicle", "addonmapents", }; + static_assert(std::extent_v == ASSET_TYPE_COUNT); - constexpr const char* SUB_ASSET_TYPE_NAMES[SUB_ASSET_TYPE_COUNT]{ + constexpr const char* SUB_ASSET_TYPE_NAMES[]{ "technique", }; + static_assert(std::extent_v == SUB_ASSET_TYPE_COUNT); } // namespace namespace IW5 diff --git a/src/Common/Game/T5/GameT5.cpp b/src/Common/Game/T5/GameT5.cpp index d72c81bf..c54e40a4 100644 --- a/src/Common/Game/T5/GameT5.cpp +++ b/src/Common/Game/T5/GameT5.cpp @@ -8,7 +8,7 @@ using namespace T5; namespace { - constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{ + constexpr const char* ASSET_TYPE_NAMES[]{ "xmodelpieces", "physpreset", "physconstraints", "destructibledef", "xanim", "xmodel", "material", "techniqueset", "image", "soundbank", "soundpatch", "clipmap_unused", "clipmap", "comworld", "gameworldsp", "gameworldmp", "mapents", "gfxworld", "gfxlightdef", "uimap", "font", @@ -17,12 +17,15 @@ namespace "xmodelalias", "rawfile", "stringtable", "packindex", "xglobals", "ddl", "glasses", "emblemset", }; + static_assert(std::extent_v == ASSET_TYPE_COUNT); - constexpr const char* SUB_ASSET_TYPE_NAMES[SUB_ASSET_TYPE_COUNT]{ + constexpr const char* SUB_ASSET_TYPE_NAMES[]{ "technique", + "vertexdecl", "vertexshader", "pixelshader", }; + static_assert(std::extent_v == SUB_ASSET_TYPE_COUNT); } // namespace namespace T5 diff --git a/src/Common/Game/T5/T5.h b/src/Common/Game/T5/T5.h index 89ebd8e7..962a87ad 100644 --- a/src/Common/Game/T5/T5.h +++ b/src/Common/Game/T5/T5.h @@ -62,7 +62,8 @@ namespace T5 enum SubAssetType { - SUB_ASSET_TYPE_TECHNIQUE = ASSET_TYPE_COUNT, + SUB_ASSET_TYPE_TECHNIQUE, + SUB_ASSET_TYPE_VERTEX_DECL, SUB_ASSET_TYPE_VERTEX_SHADER, SUB_ASSET_TYPE_PIXEL_SHADER, diff --git a/src/Common/Game/T5/T5_Assets.h b/src/Common/Game/T5/T5_Assets.h index 2d29e9c1..229bd0e0 100644 --- a/src/Common/Game/T5/T5_Assets.h +++ b/src/Common/Game/T5/T5_Assets.h @@ -1465,11 +1465,15 @@ namespace T5 MTL_ARG_MATERIAL_VERTEX_CONST = 0x0, MTL_ARG_LITERAL_VERTEX_CONST = 0x1, MTL_ARG_MATERIAL_PIXEL_SAMPLER = 0x2, + MTL_ARG_CODE_PRIM_BEGIN = 0x3, + MTL_ARG_CODE_VERTEX_CONST = 0x3, MTL_ARG_CODE_PIXEL_SAMPLER = 0x4, MTL_ARG_CODE_PIXEL_CONST = 0x5, + MTL_ARG_CODE_PRIM_END = 0x6, + MTL_ARG_MATERIAL_PIXEL_CONST = 0x6, MTL_ARG_LITERAL_PIXEL_CONST = 0x7, diff --git a/src/Common/Game/T6/GameT6.cpp b/src/Common/Game/T6/GameT6.cpp index 8ef710f9..1a4b6435 100644 --- a/src/Common/Game/T6/GameT6.cpp +++ b/src/Common/Game/T6/GameT6.cpp @@ -8,7 +8,7 @@ using namespace T6; namespace { - constexpr const char* ASSET_TYPE_NAMES[ASSET_TYPE_COUNT]{ + constexpr const char* ASSET_TYPE_NAMES[]{ "xmodelpieces", "physpreset", "physconstraints", @@ -70,12 +70,15 @@ namespace "footstepfxtable", "zbarrier", }; + static_assert(std::extent_v == ASSET_TYPE_COUNT); - constexpr const char* SUB_ASSET_TYPE_NAMES[SUB_ASSET_TYPE_COUNT]{ + constexpr const char* SUB_ASSET_TYPE_NAMES[]{ "technique", + "vertexdecl", "vertexshader", "pixelshader", }; + static_assert(std::extent_v == SUB_ASSET_TYPE_COUNT); } // namespace namespace T6 diff --git a/src/Common/Game/T6/T6.h b/src/Common/Game/T6/T6.h index f3b052f1..47bd2ad7 100644 --- a/src/Common/Game/T6/T6.h +++ b/src/Common/Game/T6/T6.h @@ -83,6 +83,7 @@ namespace T6 enum SubAssetType { SUB_ASSET_TYPE_TECHNIQUE, + SUB_ASSET_TYPE_VERTEX_DECL, SUB_ASSET_TYPE_VERTEX_SHADER, SUB_ASSET_TYPE_PIXEL_SHADER, @@ -288,8 +289,9 @@ namespace T6 using AssetZBarrier = Asset; using SubAssetTechnique = SubAsset; - using SubAssetVertexShader = SubAsset; - using SubAssetPixelShader = SubAsset; + using SubAssetVertexDecl = SubAsset; + using SubAssetVertexShader = SubAsset; + using SubAssetPixelShader = SubAsset; } // namespace T6 DEFINE_ASSET_NAME_ACCESSOR(T6::AssetPhysPreset, name); diff --git a/src/Common/Game/T6/T6_Assets.h b/src/Common/Game/T6/T6_Assets.h index 07838f09..e85f5761 100644 --- a/src/Common/Game/T6/T6_Assets.h +++ b/src/Common/Game/T6/T6_Assets.h @@ -3001,6 +3001,15 @@ namespace T6 VERTEX_SHADER_MODEL_UNLIT, }; + enum CustomSamplers + { + CUSTOM_SAMPLER_REFLECTION_PROBE = 0, + CUSTOM_SAMPLER_LIGHTMAP_PRIMARY, + CUSTOM_SAMPLER_LIGHTMAP_SECONDARY, + + CUSTOM_SAMPLER_COUNT + }; + enum MaterialType : unsigned char { MTL_TYPE_DEFAULT = 0x0, @@ -3035,6 +3044,20 @@ namespace T6 MaterialShaderArgument* args; }; + enum TechniqueFlags + { + TECHNIQUE_FLAG_1 = 0x1, + TECHNIQUE_FLAG_2 = 0x2, + TECHNIQUE_FLAG_4 = 0x4, + TECHNIQUE_FLAG_8 = 0x8, + TECHNIQUE_FLAG_10 = 0x10, + TECHNIQUE_FLAG_20 = 0x20, + TECHNIQUE_FLAG_40 = 0x40, + TECHNIQUE_FLAG_80 = 0x80, + TECHNIQUE_FLAG_100 = 0x100, + TECHNIQUE_FLAG_200 = 0x200, + }; + struct MaterialTechnique { const char* name; @@ -3043,14 +3066,6 @@ namespace T6 MaterialPass passArray[1]; }; - /* struct __cppobj ID3D11View : ID3D11DeviceChild - { - };*/ - - /* struct __cppobj ID3D11ShaderResourceView : ID3D11View - { - };*/ - struct type_align32(4) GfxImageLoadDef { char levelCount; @@ -3719,14 +3734,6 @@ namespace T6 GfxImage* secondary; }; - /* struct __cppobj ID3D11Resource : ID3D11DeviceChild - { - };*/ - - /* struct __cppobj ID3D11Buffer : ID3D11Resource - { - };*/ - struct type_align(4) GfxLightGridEntry { uint16_t colorsIndex; @@ -5793,8 +5800,8 @@ namespace T6 struct MaterialStreamRouting { - char source; - char dest; + unsigned char source; + unsigned char dest; }; struct MaterialVertexStreamRouting @@ -5805,7 +5812,7 @@ namespace T6 struct MaterialVertexDeclaration { - char streamCount; + unsigned char streamCount; bool hasOptionalSource; bool isLoaded; MaterialVertexStreamRouting routing; @@ -6177,14 +6184,19 @@ namespace T6 MTL_ARG_MATERIAL_VERTEX_CONST = 0x0, MTL_ARG_LITERAL_VERTEX_CONST = 0x1, MTL_ARG_MATERIAL_PIXEL_SAMPLER = 0x2, + MTL_ARG_CODE_PRIM_BEGIN = 0x3, + MTL_ARG_CODE_VERTEX_CONST = 0x3, MTL_ARG_CODE_PIXEL_SAMPLER = 0x4, MTL_ARG_CODE_PIXEL_CONST = 0x5, + MTL_ARG_CODE_PRIM_END = 0x6, + MTL_ARG_MATERIAL_PIXEL_CONST = 0x6, MTL_ARG_LITERAL_PIXEL_CONST = 0x7, - MLT_ARG_COUNT = 0x8, + + MLT_ARG_COUNT, }; struct MaterialShaderArgument @@ -6895,10 +6907,6 @@ namespace T6 vec3_t halfLengths; }; - /* struct __cppobj ID3D11InputLayout : ID3D11DeviceChild - { - };*/ - struct GfxLightRegionAxis { vec3_t dir; diff --git a/src/Common/Techset/StateMap/StateMapLayout.h b/src/Common/Techset/StateMap/StateMapLayout.h index 9bcb6166..811f80de 100644 --- a/src/Common/Techset/StateMap/StateMapLayout.h +++ b/src/Common/Techset/StateMap/StateMapLayout.h @@ -1,4 +1,5 @@ #pragma once + #include #include #include diff --git a/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h b/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h index ecb0e7ec..e64d4733 100644 --- a/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h +++ b/src/ObjCommon/Game/T5/Techset/TechsetConstantsT5.h @@ -277,6 +277,11 @@ namespace T5 }; static_assert(std::extent_v == STREAM_DST_COUNT); + static inline techset::CommonStreamRoutingInfos commonRoutingInfos(streamRoutingSources, + std::extent_v, + streamRoutingDestinations, + std::extent_v); + static techset::CommonCodeConstSourceInfo commonCodeConstSources[]{ { .value = CONST_SRC_CODE_LIGHT_POSITION, @@ -1734,6 +1739,26 @@ namespace T5 }, }; + // See MaterialShaderArgumentType + static inline techset::CommonShaderArgumentType commonArgumentTypes[]{ + {.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_SAMPLER}, + {.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::CODE_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_SAMPLER }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST }, + }; + static_assert(std::extent_v == MLT_ARG_COUNT); + + static inline techset::CommonCodeSourceInfos commonCodeSourceInfos(commonCodeConstSources, + std::extent_v, + commonCodeSamplerSources, + std::extent_v, + commonArgumentTypes, + std::extent_v); + inline MaterialTypeInfo g_materialTypeInfo[]{ {"", "" }, {"m/", "m_" }, diff --git a/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h index 73569967..d8c46bce 100644 --- a/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h +++ b/src/ObjCommon/Game/T6/Techset/TechsetConstantsT6.h @@ -190,6 +190,11 @@ namespace T6 }; static_assert(std::extent_v == STREAM_DST_COUNT); + static inline techset::CommonStreamRoutingInfos commonRoutingInfos(streamRoutingSources, + std::extent_v, + streamRoutingDestinations, + std::extent_v); + static inline techset::CommonCodeConstSourceInfo commonCodeConstSources[]{ { .value = CONST_SRC_CODE_LIGHT_POSITION, @@ -214,6 +219,7 @@ namespace T6 .accessor = "lightSpotFactors", .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + .techFlags = TECHNIQUE_FLAG_10, }, { .value = CONST_SRC_CODE_LIGHT_ATTENUATION, @@ -544,6 +550,7 @@ namespace T6 .accessor = "particleCloudVelWorld", .arrayCount = 0, .updateFrequency = techset::CommonCodeSourceUpdateFrequency::PER_OBJECT, + .techFlags = TECHNIQUE_FLAG_100, }, { .value = CONST_SRC_CODE_DEPTH_FROM_CLIP, @@ -1538,11 +1545,13 @@ namespace T6 .value = TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY, .accessor = "lightmapSamplerPrimary", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + .customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_PRIMARY, }, { .value = TEXTURE_SRC_CODE_LIGHTMAP_SECONDARY, .accessor = "lightmapSamplerSecondary", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + .customSamplerIndex = CUSTOM_SAMPLER_LIGHTMAP_SECONDARY, }, { .value = TEXTURE_SRC_CODE_SHADOWMAP_SUN, @@ -1563,11 +1572,13 @@ namespace T6 .value = TEXTURE_SRC_CODE_RESOLVED_POST_SUN, .accessor = "resolvedPostSun", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + .techFlags = TECHNIQUE_FLAG_1, }, { .value = TEXTURE_SRC_CODE_RESOLVED_SCENE, .accessor = "resolvedScene", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + .techFlags = TECHNIQUE_FLAG_2, }, { .value = TEXTURE_SRC_CODE_POST_EFFECT_SRC, @@ -1608,16 +1619,19 @@ namespace T6 .value = TEXTURE_SRC_CODE_FLOATZ, .accessor = "floatZSampler", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + .techFlags = TECHNIQUE_FLAG_40, }, { .value = TEXTURE_SRC_CODE_PROCESSED_FLOATZ, .accessor = "processedFloatZSampler", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + .techFlags = TECHNIQUE_FLAG_40, }, { .value = TEXTURE_SRC_CODE_RAW_FLOATZ, .accessor = "rawFloatZSampler", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::RARELY, + .techFlags = TECHNIQUE_FLAG_40, }, { .value = TEXTURE_SRC_CODE_STENCIL, @@ -1648,6 +1662,7 @@ namespace T6 .value = TEXTURE_SRC_CODE_REFLECTION_PROBE, .accessor = "reflectionProbeSampler", .updateFrequency = techset::CommonCodeSourceUpdateFrequency::CUSTOM, + .customSamplerIndex = CUSTOM_SAMPLER_REFLECTION_PROBE, }, { .value = TEXTURE_SRC_CODE_FEATHER_FLOAT_Z, @@ -1791,6 +1806,26 @@ namespace T6 }, }; + // See MaterialShaderArgumentType + static inline techset::CommonShaderArgumentType commonArgumentTypes[]{ + {.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_SAMPLER}, + {.m_shader_type = techset::CommonTechniqueShaderType::VERTEX, .m_value_type = techset::CommonShaderValueType::CODE_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_SAMPLER }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::CODE_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::MATERIAL_CONST }, + {.m_shader_type = techset::CommonTechniqueShaderType::PIXEL, .m_value_type = techset::CommonShaderValueType::LITERAL_CONST }, + }; + static_assert(std::extent_v == MLT_ARG_COUNT); + + static inline techset::CommonCodeSourceInfos commonCodeSourceInfos(commonCodeConstSources, + std::extent_v, + commonCodeSamplerSources, + std::extent_v, + commonArgumentTypes, + std::extent_v); + static inline MaterialTypeInfo g_materialTypeInfo[]{ {"", "" }, {"m/", "m_" }, diff --git a/src/ObjCommon/Techset/CommonTechnique.cpp b/src/ObjCommon/Techset/CommonTechnique.cpp index a28b2a9c..0362df59 100644 --- a/src/ObjCommon/Techset/CommonTechnique.cpp +++ b/src/ObjCommon/Techset/CommonTechnique.cpp @@ -1,15 +1,19 @@ #include "CommonTechnique.h" #include +#include namespace techset { CommonCodeSourceInfos::CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos, const size_t codeConstCount, const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos, - const size_t codeSamplerCount) + const size_t codeSamplerCount, + const CommonShaderArgumentType* argumentTypes, + const size_t argumentTypeCount) : m_code_const_source_infos(codeConstCount), - m_code_sampler_source_infos(codeSamplerCount) + m_code_sampler_source_infos(codeSamplerCount), + m_argument_types(argumentTypeCount) { std::copy(codeConstSourceInfos, &codeConstSourceInfos[codeConstCount], m_code_const_source_infos.data()); std::ranges::sort(m_code_const_source_infos, @@ -24,6 +28,18 @@ namespace techset { return a.value < b.value; }); + + std::copy(argumentTypes, &argumentTypes[argumentTypeCount], m_argument_types.data()); + + for (const auto& codeConstInfo : m_code_const_source_infos) + { + m_code_const_lookup.emplace(codeConstInfo.accessor, codeConstInfo.value); + } + + for (const auto& codeSamplerInfo : m_code_sampler_source_infos) + { + m_code_sampler_lookup.emplace(codeSamplerInfo.accessor, codeSamplerInfo.value); + } } std::optional CommonCodeSourceInfos::GetInfoForCodeConstSource(const CommonCodeConstSource codeConstSource) const @@ -55,6 +71,33 @@ namespace techset return std::nullopt; } + std::optional CommonCodeSourceInfos::GetCodeConstSourceForAccessor(const std::string& accessor) const + { + const auto foundEntry = m_code_const_lookup.find(accessor); + if (foundEntry == m_code_const_lookup.end()) + return std::nullopt; + + return foundEntry->second; + } + + std::optional CommonCodeSourceInfos::GetCodeSamplerSourceForAccessor(const std::string& accessor) const + { + const auto foundEntry = m_code_sampler_lookup.find(accessor); + if (foundEntry == m_code_sampler_lookup.end()) + return std::nullopt; + + return foundEntry->second; + } + + std::optional CommonCodeSourceInfos::GetArgumentTypeNumericValue(const CommonShaderArgumentType& argumentType) const + { + const auto foundValue = std::ranges::find(m_argument_types, argumentType); + if (foundValue == m_argument_types.end()) + return std::nullopt; + + return static_cast(foundValue - m_argument_types.begin()); + } + CommonStreamRoutingInfos::CommonStreamRoutingInfos(const CommonStreamRoutingSourceInfo* sourceInfos, const size_t sourceCount, const CommonStreamRoutingDestinationInfo* destinationNames, @@ -64,6 +107,18 @@ namespace techset { std::copy(sourceInfos, &sourceInfos[sourceCount], m_sources.data()); std::copy(destinationNames, &destinationNames[destinationCount], m_destinations.data()); + + for (size_t i = 0; i < sourceCount; i++) + { + m_source_name_lookup[sourceInfos[i].name] = static_cast(i); + m_source_abbreviation_lookup[sourceInfos[i].abbreviation] = static_cast(i); + } + + for (size_t i = 0; i < destinationCount; i++) + { + m_destination_name_lookup[destinationNames[i].name] = static_cast(i); + m_destination_abbreviation_lookup[destinationNames[i].abbreviation] = static_cast(i); + } } const char* CommonStreamRoutingInfos::GetSourceName(const CommonStreamSource source) const @@ -105,4 +160,144 @@ namespace techset return m_destinations[destination].abbreviation; } + + std::optional CommonStreamRoutingInfos::GetSourceByName(const std::string& name) const + { + const auto foundSource = m_source_name_lookup.find(name); + if (foundSource != m_source_name_lookup.end()) + return foundSource->second; + + return std::nullopt; + } + + std::optional CommonStreamRoutingInfos::GetSourceByAbbreviation(const std::string& abbreviation) const + { + const auto foundSource = m_source_abbreviation_lookup.find(abbreviation); + if (foundSource != m_source_abbreviation_lookup.end()) + return foundSource->second; + + return std::nullopt; + } + + std::optional CommonStreamRoutingInfos::GetDestinationByName(const std::string& name) const + { + const auto foundDestination = m_destination_name_lookup.find(name); + if (foundDestination != m_destination_name_lookup.end()) + return foundDestination->second; + + return std::nullopt; + } + + std::optional CommonStreamRoutingInfos::GetDestinationByAbbreviation(const std::string& abbreviation) const + { + const auto foundDestination = m_destination_abbreviation_lookup.find(abbreviation); + if (foundDestination != m_destination_abbreviation_lookup.end()) + return foundDestination->second; + + return std::nullopt; + } + + CommonShaderArg::CommonShaderArg(const CommonShaderArgumentType type, const CommonShaderArgDestination& destination, const CommonShaderArgValue& value) + : m_type(type), + m_destination(destination), + m_value(value) + { + } + + CommonCodeSourceUpdateFrequency CommonShaderArg::GetFrequency(const CommonCodeSourceInfos& infos) const + { + switch (m_type.m_value_type) + { + case CommonShaderValueType::CODE_CONST: + { + const auto info = infos.GetInfoForCodeConstSource(m_value.code_const_source); + assert(info); + return info->updateFrequency; + } + + case CommonShaderValueType::CODE_SAMPLER: + { + const auto info = infos.GetInfoForCodeSamplerSource(m_value.code_sampler_source); + assert(info); + return info->updateFrequency; + } + + case CommonShaderValueType::MATERIAL_CONST: + case CommonShaderValueType::LITERAL_CONST: + case CommonShaderValueType::MATERIAL_SAMPLER: + return CommonCodeSourceUpdateFrequency::RARELY; + + default: + assert(false); + return CommonCodeSourceUpdateFrequency::RARELY; + } + } + + CommonStreamRouting::CommonStreamRouting(const CommonStreamSource source, const CommonStreamDestination destination) + : m_source(source), + m_destination(destination) + { + } + + CommonVertexDeclaration::CommonVertexDeclaration(std::vector routing) + : m_routing(std::move(routing)) + { + } + + void CommonVertexDeclaration::SortRoutingEntries() + { + std::ranges::sort(m_routing, + [](const CommonStreamRouting& r1, const CommonStreamRouting& r2) + { + return r1.m_source < r2.m_source; + }); + } + + CommonTechniqueShader::CommonTechniqueShader() + : m_type(CommonTechniqueShaderType::VERTEX) + { + } + + CommonTechniqueShader::CommonTechniqueShader(const CommonTechniqueShaderType type, std::string name) + : m_type(type), + m_name(std::move(name)) + { + } + + CommonPass::CommonPass(const uint32_t samplerFlags, + std::string stateMap, + CommonTechniqueShader vertexShader, + CommonTechniqueShader pixelShader, + CommonVertexDeclaration vertexDeclaration) + : m_sampler_flags(samplerFlags), + m_state_map(std::move(stateMap)), + m_vertex_shader(std::move(vertexShader)), + m_pixel_shader(std::move(pixelShader)), + m_vertex_declaration(std::move(vertexDeclaration)) + { + } + + CommonPass::FrequencyCounts_t CommonPass::GetFrequencyCounts(const CommonCodeSourceInfos& infos) const + { + FrequencyCounts_t result; + for (auto& count : result) + count = 0; + + for (auto& arg : m_args) + result[std::to_underlying(arg.GetFrequency(infos))]++; + + return result; + } + + CommonTechnique::CommonTechnique(std::string name) + : m_name(std::move(name)), + m_flags(0) + { + } + + CommonTechnique::CommonTechnique(std::string name, const uint64_t flags) + : m_name(std::move(name)), + m_flags(flags) + { + } } // namespace techset diff --git a/src/ObjCommon/Techset/CommonTechnique.h b/src/ObjCommon/Techset/CommonTechnique.h index 37dcfe3f..70ed62ef 100644 --- a/src/ObjCommon/Techset/CommonTechnique.h +++ b/src/ObjCommon/Techset/CommonTechnique.h @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace techset @@ -27,12 +28,35 @@ namespace techset const char* abbreviation; }; + enum class CommonTechniqueShaderType : std::uint8_t + { + VERTEX, + PIXEL + }; + + enum class CommonShaderValueType : std::uint8_t + { + // Value is set to a float4 value in the pass + LITERAL_CONST, + // Value is set to a float4 value in the material + MATERIAL_CONST, + // Value is set to a float4 value calculated in code + CODE_CONST, + // Value is set to a sampler from the material + MATERIAL_SAMPLER, + // Value is set to a sampler generated in code + CODE_SAMPLER + }; + enum class CommonCodeSourceUpdateFrequency : std::uint8_t { PER_PRIM, PER_OBJECT, RARELY, CUSTOM, + IGNORE, + + COUNT }; struct CommonCodeConstSourceInfo @@ -41,6 +65,7 @@ namespace techset const char* accessor; std::uint8_t arrayCount; CommonCodeSourceUpdateFrequency updateFrequency; + std::optional techFlags; }; struct CommonCodeSamplerSourceInfo @@ -48,6 +73,24 @@ namespace techset CommonCodeSamplerSource value; const char* accessor; CommonCodeSourceUpdateFrequency updateFrequency; + std::optional techFlags; + std::optional customSamplerIndex; + }; + + struct CommonShaderArgumentType + { + friend bool operator==(const CommonShaderArgumentType& lhs, const CommonShaderArgumentType& rhs) + { + return lhs.m_shader_type == rhs.m_shader_type && lhs.m_value_type == rhs.m_value_type; + } + + friend bool operator!=(const CommonShaderArgumentType& lhs, const CommonShaderArgumentType& rhs) + { + return !(lhs == rhs); + } + + CommonTechniqueShaderType m_shader_type; + CommonShaderValueType m_value_type; }; class CommonCodeSourceInfos @@ -56,14 +99,26 @@ namespace techset CommonCodeSourceInfos(const CommonCodeConstSourceInfo* codeConstSourceInfos, size_t codeConstCount, const CommonCodeSamplerSourceInfo* codeSamplerSourceInfos, - size_t codeSamplerCount); + size_t codeSamplerCount, + const CommonShaderArgumentType* argumentTypes, + size_t argumentTypeCount); [[nodiscard]] std::optional GetInfoForCodeConstSource(CommonCodeConstSource codeConstSource) const; [[nodiscard]] std::optional GetInfoForCodeSamplerSource(CommonCodeSamplerSource codeSamplerSource) const; + [[nodiscard]] std::optional GetCodeConstSourceForAccessor(const std::string& accessor) const; + [[nodiscard]] std::optional GetCodeSamplerSourceForAccessor(const std::string& accessor) const; + + [[nodiscard]] std::optional GetArgumentTypeNumericValue(const CommonShaderArgumentType& argumentType) const; + private: std::vector m_code_const_source_infos; std::vector m_code_sampler_source_infos; + + std::unordered_map m_code_const_lookup; + std::unordered_map m_code_sampler_lookup; + + std::vector m_argument_types; }; class CommonStreamRoutingInfos @@ -79,10 +134,18 @@ namespace techset [[nodiscard]] bool IsSourceOptional(CommonStreamSource source) const; [[nodiscard]] const char* GetDestinationName(CommonStreamDestination destination) const; [[nodiscard]] const char* GetDestinationAbbreviation(CommonStreamDestination destination) const; + [[nodiscard]] std::optional GetSourceByName(const std::string& name) const; + [[nodiscard]] std::optional GetSourceByAbbreviation(const std::string& abbreviation) const; + [[nodiscard]] std::optional GetDestinationByName(const std::string& name) const; + [[nodiscard]] std::optional GetDestinationByAbbreviation(const std::string& abbreviation) const; private: std::vector m_sources; std::vector m_destinations; + std::unordered_map m_source_name_lookup; + std::unordered_map m_destination_name_lookup; + std::unordered_map m_source_abbreviation_lookup; + std::unordered_map m_destination_abbreviation_lookup; }; union CommonShaderArgValue @@ -115,31 +178,26 @@ namespace techset CommonShaderArgDestinationDx11 dx11; }; - enum class CommonShaderArgType : std::uint8_t - { - // Value is set to a float4 value in the pass - LITERAL_CONST, - // Value is set to a float4 value in the material - MATERIAL_CONST, - // Value is set to a float4 value calculated in code - CODE_CONST, - // Value is set to a sampler from the material - MATERIAL_SAMPLER, - // Value is set to a sampler generated in code - CODE_SAMPLER - }; - class CommonShaderArg { public: - CommonShaderArgType m_type; + CommonShaderArg() = default; + CommonShaderArg(CommonShaderArgumentType type, const CommonShaderArgDestination& destination, const CommonShaderArgValue& value); + + [[nodiscard]] CommonCodeSourceUpdateFrequency GetFrequency(const CommonCodeSourceInfos& infos) const; + + CommonShaderArgumentType m_type; CommonShaderArgDestination m_destination; CommonShaderArgValue m_value; + std::optional m_bin; }; class CommonStreamRouting { public: + CommonStreamRouting() = default; + CommonStreamRouting(CommonStreamSource source, CommonStreamDestination destination); + CommonStreamSource m_source; CommonStreamDestination m_destination; }; @@ -147,39 +205,69 @@ namespace techset class CommonVertexDeclaration { public: + CommonVertexDeclaration() = default; + explicit CommonVertexDeclaration(std::vector routing); + + void SortRoutingEntries(); + std::vector m_routing; }; + class CommonTechniqueShaderBin + { + public: + const void* m_shader_bin; + size_t m_shader_bin_size; + }; + class CommonTechniqueShader { public: + CommonTechniqueShader(); + CommonTechniqueShader(CommonTechniqueShaderType type, std::string name); + + CommonTechniqueShaderType m_type; std::string m_name; - const void* m_shader_bin; - size_t m_shader_bin_size; + std::optional m_bin; + }; + + class CommonPass + { + public: + using FrequencyCounts_t = std::array; + + CommonPass() = default; + CommonPass(uint32_t samplerFlags, + std::string stateMap, + CommonTechniqueShader vertexShader, + CommonTechniqueShader pixelShader, + CommonVertexDeclaration vertexDeclaration); + + [[nodiscard]] FrequencyCounts_t GetFrequencyCounts(const CommonCodeSourceInfos& infos) const; + + uint32_t m_sampler_flags; + std::string m_state_map; + CommonTechniqueShader m_vertex_shader; + CommonTechniqueShader m_pixel_shader; + CommonVertexDeclaration m_vertex_declaration; std::vector m_args; }; + class CommonTechnique + { + public: + CommonTechnique() = default; + explicit CommonTechnique(std::string name); + CommonTechnique(std::string name, uint64_t flags); + + std::string m_name; + uint64_t m_flags; + std::vector m_passes; + }; + enum class DxVersion : std::uint8_t { DX9, DX11 }; - - class CommonPass - { - public: - uint32_t m_sampler_flags; - DxVersion m_dx_version; - CommonTechniqueShader m_vertex_shader; - CommonTechniqueShader m_pixel_shader; - CommonVertexDeclaration m_vertex_declaration; - }; - - class CommonTechnique - { - public: - std::string m_name; - uint64_t m_flags; - std::vector m_passes; - }; } // namespace techset diff --git a/src/ObjCommon/Techset/CommonVertexDeclCreator.cpp b/src/ObjCommon/Techset/CommonVertexDeclCreator.cpp new file mode 100644 index 00000000..a27aec5d --- /dev/null +++ b/src/ObjCommon/Techset/CommonVertexDeclCreator.cpp @@ -0,0 +1,67 @@ +#include "CommonVertexDeclCreator.h" + +#include "Utils/Logging/Log.h" + +#include + +namespace +{ + bool NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset) + { + if (offset >= assetName.size()) + return false; + + if (offset + 1 < assetName.size() && isdigit(assetName[offset + 1])) + { + abbreviation = std::string(assetName, offset, 2); + offset += 2; + } + else + { + abbreviation = std::string(assetName, offset, 1); + offset += 1; + } + + return true; + } +} // namespace + +namespace techset +{ + std::optional CreateVertexDeclFromName(const std::string& name, const CommonStreamRoutingInfos& routingInfos) + { + CommonVertexDeclaration result; + size_t currentOffset = 0u; + + std::string sourceAbbreviation; + while (NextAbbreviation(name, sourceAbbreviation, currentOffset)) + { + std::string destinationAbbreviation; + if (!NextAbbreviation(name, destinationAbbreviation, currentOffset)) + { + con::error("Failed to detect vertex decl destination abbreviation: {}", name); + return std::nullopt; + } + + const auto maybeSource = routingInfos.GetSourceByAbbreviation(sourceAbbreviation); + if (!maybeSource) + { + con::error("Unknown vertex decl source abbreviation: {}", sourceAbbreviation); + return std::nullopt; + } + + const auto maybeDestination = routingInfos.GetDestinationByAbbreviation(sourceAbbreviation); + if (!maybeDestination) + { + con::error("Unknown vertex decl destination abbreviation: {}", destinationAbbreviation); + return std::nullopt; + } + + result.m_routing.emplace_back(*maybeSource, *maybeDestination); + } + + result.SortRoutingEntries(); + + return result; + } +} // namespace techset diff --git a/src/ObjCommon/Techset/CommonVertexDeclCreator.h b/src/ObjCommon/Techset/CommonVertexDeclCreator.h new file mode 100644 index 00000000..9566999e --- /dev/null +++ b/src/ObjCommon/Techset/CommonVertexDeclCreator.h @@ -0,0 +1,11 @@ +#pragma once + +#include "CommonTechnique.h" + +#include +#include + +namespace techset +{ + std::optional CreateVertexDeclFromName(const std::string& name, const CommonStreamRoutingInfos& routingInfos); +} diff --git a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp index 0f3fdecd..d2e20bc0 100644 --- a/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Material/CompilerMaterialIW4.cpp @@ -9,11 +9,8 @@ #include "Gdt/AbstractGdtEntryReader.h" #include "Gdt/IGdtQueryable.h" #include "Pool/GlobalAssetPool.h" -#include "Techset/CommonTechsetCache.h" -#include "Techset/StateMap/StateMapFromTechniqueExtractor.h" #include "Techset/StateMap/StateMapHandler.h" -#include "Techset/TechniqueFileReader.h" -#include "Techset/TechniqueStateMapCache.h" +#include "Techset/StateMap/TechniqueStateMapCache.h" #include "Techset/TechsetCommon.h" #include "Utils/Logging/Log.h" @@ -28,6 +25,7 @@ using namespace IW4; namespace { + /* class SkipMaterialException final : public std::exception { }; @@ -1328,6 +1326,7 @@ namespace std::unique_ptr m_techset_creator; }; + */ class MaterialLoader final : public AssetCreator { @@ -1341,6 +1340,8 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { + return AssetCreationResult::NoAction(); + /* const auto* entry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_MATERIAL, assetName); if (!entry) return AssetCreationResult::NoAction(); @@ -1367,6 +1368,7 @@ namespace } return AssetCreationResult::Failure(); + */ } private: diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp index 158b9984..161fa2e9 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp @@ -6,11 +6,9 @@ #include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Shader/D3D9ShaderAnalyser.h" #include "Shader/ShaderCommon.h" -#include "Techset/CommonTechsetCache.h" #include "Techset/CommonTechsetLoader.h" #include "Techset/StateMap/StateMapReader.h" -#include "Techset/TechniqueFileReader.h" -#include "Techset/TechniqueStateMapCache.h" +#include "Techset/StateMap/TechniqueStateMapCache.h" #include "Techset/TechsetCommon.h" #include "Utils/Alignment.h" #include "Utils/Logging/Log.h" @@ -32,6 +30,7 @@ using namespace std::string_literals; namespace { + /* class LoadedTechnique { public: @@ -407,7 +406,7 @@ namespace if (arg1.m_arg.type == MTL_ARG_MATERIAL_VERTEX_CONST || arg1.m_arg.type == MTL_ARG_MATERIAL_PIXEL_CONST || arg1.m_arg.type == MTL_ARG_MATERIAL_PIXEL_SAMPLER) - return arg1.m_arg.u.codeSampler < arg2.m_arg.u.codeSampler; + return arg1.m_arg.u.nameHash < arg2.m_arg.u.nameHash; return arg1.m_arg.dest < arg2.m_arg.dest; }); @@ -1263,7 +1262,7 @@ namespace TechniqueZoneLoadingState& m_zone_state; techset::ICreatorIW4* m_techset_creator; }; - + */ class TechsetLoader final : public techset::ICreatorIW4 { public: @@ -1275,15 +1274,18 @@ namespace AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { + return AssetCreationResult::NoAction(); + /* bool failure = false; const auto* techsetDefinition = LoadTechsetDefinition(assetName, context, failure); if (!techsetDefinition) return failure ? AssetCreationResult::Failure() : AssetCreationResult::NoAction(); return CreateTechsetFromDefinition(assetName, *techsetDefinition, context); + */ } - private: + /* AssetCreationResult CreateTechsetFromDefinition(const std::string& assetName, const CommonTechset& definition, AssetCreationContext& context) { auto* techset = m_memory.Alloc(); @@ -1311,9 +1313,11 @@ namespace return AssetCreationResult::Success(context.AddAsset(std::move(registration))); } + */ CommonTechset* LoadTechsetDefinition(const std::string& assetName, AssetCreationContext& context, bool& failure) override { + /* failure = false; auto& definitionCache = context.GetZoneAssetCreationState(); auto* cachedTechsetDefinition = definitionCache.GetCachedTechsetDefinition(assetName); @@ -1334,10 +1338,13 @@ namespace definitionCache.AddCommonTechsetToCache(assetName, std::move(techsetDefinition)); return techsetDefinitionPtr; + */ + return nullptr; } const state_map::StateMapDefinition* LoadStateMapDefinition(const std::string& stateMapName, AssetCreationContext& context) override { + /* auto& stateMapCache = context.GetZoneAssetCreationState(); auto* cachedStateMap = stateMapCache.GetCachedStateMap(stateMapName); if (cachedStateMap) @@ -1358,6 +1365,8 @@ namespace stateMapCache.AddStateMapToCache(std::move(stateMapDefinition)); return stateMapDefinitionPtr; + */ + return nullptr; } private: diff --git a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp index d9681a32..7a825ec8 100644 --- a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp @@ -4,7 +4,9 @@ #include "Image/ImageIPakPostProcessor.h" #include "Image/ImageIwdPostProcessor.h" #include "KeyValuePairs/KeyValuePairsCompilerT6.h" +#include "Techset/TechniqueCompilerT6.h" #include "Techset/TechsetCompilerT6.h" +#include "Techset/VertexDeclCompilerT6.h" #include @@ -22,6 +24,9 @@ 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::CreateVertexDeclCompilerT6(memory)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, diff --git a/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp new file mode 100644 index 00000000..7489d1e0 --- /dev/null +++ b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.cpp @@ -0,0 +1,223 @@ +#include "TechniqueCompilerT6.h" + +#include "Game/T6/T6.h" +#include "Game/T6/Techset/TechsetConstantsT6.h" +#include "Techset/CommonShaderArgCreator.h" +#include "Techset/CommonTechniqueLoader.h" +#include "Utils/StringUtils.h" + +#include +#include + +using namespace T6; + +namespace +{ + void UpdateTechniqueFlags(MaterialTechnique& technique, const techset::CommonTechnique& commonTechnique) + { + std::string lowerTechniqueName(commonTechnique.m_name); + utils::MakeStringLowerCase(lowerTechniqueName); + + // Not a particularly cool way to do this but... + // the game actually does this :shrug: + if (lowerTechniqueName == "zprepass" || lowerTechniqueName.starts_with("pimp_technique_zprepass_") + || lowerTechniqueName.starts_with("pimp_technique_layer_zprepass_") || lowerTechniqueName.starts_with("pimp_technique_buildshadowmap_")) + { + technique.flags |= TECHNIQUE_FLAG_4; + } + } + + void ConvertMaterialArgs(MaterialPass& pass, const techset::CommonPass& commonPass, MemoryManager& memory) + { + pass.args = memory.Alloc(commonPass.m_args.size()); + + size_t perObjArgCount = 0u; + size_t perPrimArgCount = 0u; + size_t stableArgCount = 0u; + size_t argIndex = 0u; + + const auto frequencyCount = commonPass.GetFrequencyCounts(commonCodeSourceInfos); + + for (const auto& arg : commonPass.m_args) + { + UpdateTechniqueFlagsForArgument(technique.flags, arg); + switch (arg.m_update_frequency) + { + case MTL_UPDATE_PER_PRIM: + perPrimArgCount++; + break; + case MTL_UPDATE_PER_OBJECT: + perObjArgCount++; + break; + case MTL_UPDATE_RARELY: + stableArgCount++; + break; + case MTL_UPDATE_CUSTOM: + { + assert(arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER); + if (arg.m_arg.type == MTL_ARG_CODE_PIXEL_SAMPLER) + { + const auto customSampler = std::ranges::find(g_customSamplerSrc, arg.m_arg.u.codeSampler); + assert(customSampler != std::end(g_customSamplerSrc)); + if (customSampler != std::end(g_customSamplerSrc)) + { + const auto customSamplerIndex = customSampler - std::begin(g_customSamplerSrc); + out.customSamplerFlags |= 1 << customSamplerIndex; + } + } + } + continue; + default: + assert(false); + continue; + } + + out.args[argIndex++] = arg.m_arg; + } + + pass.perObjArgCount = static_cast(frequencyCount[std::to_underlying(techset::CommonCodeSourceUpdateFrequency::PER_OBJECT)]); + pass.perPrimArgCount = static_cast(frequencyCount[std::to_underlying(techset::CommonCodeSourceUpdateFrequency::PER_PRIM)]); + pass.stableArgCount = static_cast(frequencyCount[std::to_underlying(techset::CommonCodeSourceUpdateFrequency::RARELY)]); + } + + void ConvertVertexDecl(MaterialPass& pass, const techset::CommonVertexDeclaration& commonDecl, AssetCreationContext& context) + { + std::ostringstream nameStream; + for (const auto& entry : commonDecl.m_routing) + { + nameStream << commonRoutingInfos.GetSourceAbbreviation(entry.m_source); + nameStream << commonRoutingInfos.GetDestinationAbbreviation(entry.m_destination); + } + + const std::string declName(nameStream.str()); + auto* vertexDeclAsset = context.LoadSubAsset(declName); + assert(vertexDeclAsset); + pass.vertexDecl = vertexDeclAsset ? vertexDeclAsset->Asset() : nullptr; + } + + void ConvertMaterialPass(MaterialPass& pass, const techset::CommonPass& commonPass, AssetCreationContext& context, MemoryManager& memory) + { + ConvertVertexDecl(pass, commonPass.m_vertex_declaration, context); + + if (!commonPass.m_vertex_shader.m_name.empty()) + { + auto* vertexShaderAsset = context.LoadSubAsset(commonPass.m_vertex_shader.m_name); + assert(vertexShaderAsset); + pass.vertexShader = vertexShaderAsset ? vertexShaderAsset->Asset() : nullptr; + } + + if (!commonPass.m_pixel_shader.m_name.empty()) + { + auto* pixelShaderAsset = context.LoadSubAsset(commonPass.m_pixel_shader.m_name); + assert(pixelShaderAsset); + pass.pixelShader = pixelShaderAsset ? pixelShaderAsset->Asset() : nullptr; + } + } + + MaterialTechnique* ConvertTechnique(const techset::CommonTechnique& commonTechnique, AssetCreationContext& context, MemoryManager& memory) + { + const auto additionalPassCount = std::max(commonTechnique.m_passes.size(), 1u) - 1u; + auto* technique = static_cast(memory.AllocRaw(sizeof(MaterialTechnique) + additionalPassCount * sizeof(MaterialPass))); + + const auto passCount = static_cast(commonTechnique.m_passes.size()); + + technique->name = memory.Dup(commonTechnique.m_name.c_str()); + + // Take common flags and apply further logic + technique->flags = static_cast(commonTechnique.m_flags); + UpdateTechniqueFlags(*technique, commonTechnique); + + technique->passCount = passCount; + + for (auto passIndex = 0u; passIndex < passCount; passIndex++) + ConvertMaterialPass(technique->passArray[passIndex], commonTechnique.m_passes[passIndex], context, memory); + + return technique; + } + + class TechniqueShaderLoaderT6 final : public techset::ITechniqueShaderLoader + { + public: + explicit TechniqueShaderLoaderT6(AssetCreationContext& context) + : m_context(context) + { + } + + std::optional LoadVertexShader(const std::string& name) override + { + auto* shaderAsset = m_context.LoadSubAsset(name); + if (!shaderAsset) + return std::nullopt; + + const auto* shader = shaderAsset->Asset(); + assert(shader->prog.loadDef.program && shader->prog.loadDef.programSize > 0); + if (!shader->prog.loadDef.program || shader->prog.loadDef.programSize == 0) + return std::nullopt; + + return techset::CommonTechniqueShaderBin{ + .m_shader_bin = shader->prog.loadDef.program, + .m_shader_bin_size = shader->prog.loadDef.programSize, + }; + } + + std::optional LoadPixelShader(const std::string& name) override + { + auto* shaderAsset = m_context.LoadSubAsset(name); + if (!shaderAsset) + return std::nullopt; + + const auto* shader = shaderAsset->Asset(); + assert(shader->prog.loadDef.program && shader->prog.loadDef.programSize > 0); + if (!shader->prog.loadDef.program || shader->prog.loadDef.programSize == 0) + return std::nullopt; + + return techset::CommonTechniqueShaderBin{ + .m_shader_bin = shader->prog.loadDef.program, + .m_shader_bin_size = shader->prog.loadDef.programSize, + }; + } + + private: + AssetCreationContext& m_context; + }; + + class TechniqueCompilerT6 final : public SubAssetCreator + { + public: + TechniqueCompilerT6(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult CreateSubAsset(const std::string& subAssetName, AssetCreationContext& context) override + { + bool failure = false; + TechniqueShaderLoaderT6 shaderLoader(context); + const auto commonShaderArgCreator = techset::CommonShaderArgCreator::CreateDx11(shaderLoader, context); + + const auto commonTechnique = + techset::LoadCommonTechnique(subAssetName, commonCodeSourceInfos, commonRoutingInfos, *commonShaderArgCreator, m_search_path, failure); + + if (!commonTechnique) + return failure ? AssetCreationResult::Failure() : AssetCreationResult::NoAction(); + + auto* convertedTechnique = ConvertTechnique(*commonTechnique, context, m_memory); + assert(convertedTechnique); + + return AssetCreationResult::Success(context.AddSubAsset(AssetRegistration(subAssetName, convertedTechnique))); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +namespace techset +{ + std::unique_ptr CreateTechniqueCompilerT6(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace techset diff --git a/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h new file mode 100644 index 00000000..c859d4d0 --- /dev/null +++ b/src/ObjCompiling/Game/T6/Techset/TechniqueCompilerT6.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +namespace techset +{ + std::unique_ptr CreateTechniqueCompilerT6(MemoryManager& memory, ISearchPath& searchPath); +} diff --git a/src/ObjCompiling/Game/T6/Techset/TechsetCompilerT6.cpp b/src/ObjCompiling/Game/T6/Techset/TechsetCompilerT6.cpp index 9a672a30..3a98bea3 100644 --- a/src/ObjCompiling/Game/T6/Techset/TechsetCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/Techset/TechsetCompilerT6.cpp @@ -70,6 +70,19 @@ namespace auto* techset = ConvertTechniqueSet(*commonTechset, m_memory); + for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v; techniqueIndex++) + { + const auto& techniqueName = commonTechset->m_technique_names[techniqueIndex]; + if (techniqueName.empty()) + continue; + + auto* technique = context.LoadSubAsset(techniqueName); + if (!technique) + return AssetCreationResult::Failure(); + + techset->techniques[techniqueIndex] = technique->Asset(); + } + return AssetCreationResult::Success(context.AddAsset(AssetRegistration(assetName, techset))); } diff --git a/src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.cpp b/src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.cpp new file mode 100644 index 00000000..74a5aa50 --- /dev/null +++ b/src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.cpp @@ -0,0 +1,57 @@ +#include "VertexDeclCompilerT6.h" + +#include "Game/T6/T6.h" +#include "Game/T6/Techset/TechsetConstantsT6.h" +#include "Techset/CommonVertexDeclCreator.h" +#include "Utils/Logging/Log.h" + +using namespace T6; + +namespace +{ + class VertexDeclCompilerT6 final : public SubAssetCreator + { + public: + explicit VertexDeclCompilerT6(MemoryManager& memory) + : m_memory(memory) + { + } + + AssetCreationResult CreateSubAsset(const std::string& subAssetName, AssetCreationContext& context) override + { + const auto commonVertexDecl = techset::CreateVertexDeclFromName(subAssetName, commonRoutingInfos); + if (!commonVertexDecl) + return AssetCreationResult::Failure(); + + if (commonVertexDecl->m_routing.size() > std::extent_v) + { + con::error("Vertex declaration can only have up to {} routing entries", std::extent_v); + return AssetCreationResult::Failure(); + } + + auto* vertexDecl = m_memory.Alloc(); + + for (const auto& commonRoutingEntry : commonVertexDecl->m_routing) + { + vertexDecl->routing.data[vertexDecl->streamCount].source = commonRoutingEntry.m_source; + vertexDecl->routing.data[vertexDecl->streamCount].dest = commonRoutingEntry.m_destination; + vertexDecl->hasOptionalSource = vertexDecl->hasOptionalSource || commonRoutingEntry.m_source >= STREAM_SRC_OPTIONAL_BEGIN; + + vertexDecl->streamCount++; + } + + return AssetCreationResult::Success(context.AddSubAsset(AssetRegistration(subAssetName, vertexDecl))); + } + + private: + MemoryManager& m_memory; + }; +} // namespace + +namespace techset +{ + std::unique_ptr CreateVertexDeclCompilerT6(MemoryManager& memory) + { + return std::make_unique(memory); + } +} // namespace techset diff --git a/src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.h b/src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.h new file mode 100644 index 00000000..b06f43de --- /dev/null +++ b/src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Asset/IAssetCreator.h" +#include "Utils/MemoryManager.h" + +#include + +namespace techset +{ + std::unique_ptr CreateVertexDeclCompilerT6(MemoryManager& memory); +} diff --git a/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp b/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp new file mode 100644 index 00000000..aaaa4d06 --- /dev/null +++ b/src/ObjCompiling/Techset/CommonShaderArgCreator.cpp @@ -0,0 +1,164 @@ +#include "CommonShaderArgCreator.h" + +#include +#include + +namespace +{ + class BaseCommonShaderArgCreator : public techset::CommonShaderArgCreator + { + public: + explicit BaseCommonShaderArgCreator(techset::ITechniqueShaderLoader& shaderLoader, techset::CommonCodeSourceInfos& commonCodeSourceInfos) + : m_shader_loader(shaderLoader), + m_common_code_source_infos(commonCodeSourceInfos), + m_shader_type(techset::CommonTechniqueShaderType::VERTEX), + m_bin{} + { + } + + result::Expected EnterShader(const techset::CommonTechniqueShaderType shaderType, const std::string& name) override + { + m_shader_type = shaderType; + + std::optional maybeShader; + if (shaderType == techset::CommonTechniqueShaderType::VERTEX) + { + maybeShader = m_shader_loader.LoadVertexShader(name); + } + else if (shaderType == techset::CommonTechniqueShaderType::PIXEL) + { + maybeShader = m_shader_loader.LoadPixelShader(name); + } + + if (!maybeShader) + return result::Unexpected("Failed to load shader"); + + m_bin = *maybeShader; + + return NoResult{}; + } + + void LeaveShader() override + { + m_bin = {}; + } + + result::Expected AcceptShaderConstantArgument(const techset::CommonShaderArgCreatorDestination& destination, + techset::CommonCodeConstSource codeConstSource) override + { + return result::Unexpected("Not implemented"); + } + + result::Expected AcceptShaderSamplerArgument(const techset::CommonShaderArgCreatorDestination& destination, + techset::CommonCodeSamplerSource codeSamplerSource) override + { + return result::Unexpected("Not implemented"); + } + + result::Expected AcceptShaderLiteralArgument(const techset::CommonShaderArgCreatorDestination& destination, + const std::array& literalValue) override + { + return result::Unexpected("Not implemented"); + } + + result::Expected AcceptShaderMaterialArgument(const techset::CommonShaderArgCreatorDestination& destination, + unsigned nameHash) override + { + return result::Unexpected("Not implemented"); + } + + result::Expected AcceptShaderMaterialArgument(const techset::CommonShaderArgCreatorDestination& destination, + const std::string& nameValue) override + { + return result::Unexpected("Not implemented"); + } + + result::Expected, std::string> FinalizeArgs() override + { + // TODO: Auto create remaining args + + std::ranges::sort(m_args, + [this](const techset::CommonShaderArg& arg0, const techset::CommonShaderArg& arg1) -> bool + { + const auto updateFreq0 = arg0.GetFrequency(m_common_code_source_infos); + const auto updateFreq1 = arg1.GetFrequency(m_common_code_source_infos); + if (updateFreq0 != updateFreq1) + return updateFreq0 < updateFreq1; + + const auto typeNumeric0 = m_common_code_source_infos.GetArgumentTypeNumericValue(arg0.m_type); + const auto typeNumeric1 = m_common_code_source_infos.GetArgumentTypeNumericValue(arg1.m_type); + assert(typeNumeric0); + assert(typeNumeric1); + if (*typeNumeric0 != *typeNumeric1) + return *typeNumeric0 < *typeNumeric1; + + if (arg0.m_type.m_value_type == techset::CommonShaderValueType::MATERIAL_CONST + || arg0.m_type.m_value_type == techset::CommonShaderValueType::MATERIAL_SAMPLER) + { + return arg0.m_value.name_hash < arg1.m_value.name_hash; + } + + return CompareArgumentDestinations(arg0.m_destination, arg1.m_destination); + }); + + return m_args; + } + + protected: + [[nodiscard]] virtual size_t CompareArgumentDestinations(const techset::CommonShaderArgDestination& dest0, + const techset::CommonShaderArgDestination& dest1) const = 0; + + techset::ITechniqueShaderLoader& m_shader_loader; + techset::CommonCodeSourceInfos& m_common_code_source_infos; + + techset::CommonTechniqueShaderType m_shader_type; + techset::CommonTechniqueShaderBin m_bin; + + std::vector m_args; + }; + + class CommonShaderArgCreatorDx11 final : public BaseCommonShaderArgCreator + { + public: + explicit CommonShaderArgCreatorDx11(techset::ITechniqueShaderLoader& shaderLoader, techset::CommonCodeSourceInfos& commonCodeSourceInfos) + : BaseCommonShaderArgCreator(shaderLoader, commonCodeSourceInfos) + { + } + + protected: + [[nodiscard]] size_t CompareArgumentDestinations(const techset::CommonShaderArgDestination& dest0, + const techset::CommonShaderArgDestination& dest1) const override + { + if (dest0.dx11.m_buffer != dest1.dx11.m_buffer) + return dest0.dx11.m_buffer < dest1.dx11.m_buffer; + + return dest0.dx11.m_location < dest1.dx11.m_location; + } + }; +} // namespace + +namespace techset +{ + CommonShaderArgCreatorDestination::CommonShaderArgCreatorDestination(std::string argumentName) + : m_argument_name(std::move(argumentName)) + { + } + + CommonShaderArgCreatorDestination::CommonShaderArgCreatorDestination(std::string argumentName, const unsigned argumentIndex) + : m_argument_name(std::move(argumentName)), + m_argument_index(argumentIndex) + { + } + + std::unique_ptr CommonShaderArgCreator::CreateDx9(ITechniqueShaderLoader& shaderLoader, AssetCreationContext& context) + { + // TODO + return nullptr; + } + + std::unique_ptr + CommonShaderArgCreator::CreateDx11(ITechniqueShaderLoader& shaderLoader, AssetCreationContext& context, CommonCodeSourceInfos& commonCodeSourceInfos) + { + return std::make_unique(shaderLoader, commonCodeSourceInfos); + } +} // namespace techset diff --git a/src/ObjCompiling/Techset/CommonShaderArgCreator.h b/src/ObjCompiling/Techset/CommonShaderArgCreator.h new file mode 100644 index 00000000..2a24cade --- /dev/null +++ b/src/ObjCompiling/Techset/CommonShaderArgCreator.h @@ -0,0 +1,61 @@ +#pragma once + +#include "Asset/AssetCreationContext.h" +#include "Techset/CommonTechnique.h" +#include "Utils/Result.h" + +#include +#include +#include +#include + +namespace techset +{ + class ITechniqueShaderLoader + { + public: + ITechniqueShaderLoader() = default; + virtual ~ITechniqueShaderLoader() = default; + + virtual std::optional LoadVertexShader(const std::string& name) = 0; + virtual std::optional LoadPixelShader(const std::string& name) = 0; + }; + + class CommonShaderArgCreatorDestination + { + public: + std::string m_argument_name; + std::optional m_argument_index; + + CommonShaderArgCreatorDestination() = default; + explicit CommonShaderArgCreatorDestination(std::string argumentName); + CommonShaderArgCreatorDestination(std::string argumentName, unsigned argumentIndex); + }; + + class CommonShaderArgCreator + { + public: + CommonShaderArgCreator() = default; + virtual ~CommonShaderArgCreator() = default; + + virtual result::Expected EnterShader(CommonTechniqueShaderType shaderType, const std::string& name) = 0; + virtual void LeaveShader() = 0; + + virtual result::Expected AcceptShaderConstantArgument(const CommonShaderArgCreatorDestination& destination, + CommonCodeConstSource codeConstSource) = 0; + virtual result::Expected AcceptShaderSamplerArgument(const CommonShaderArgCreatorDestination& destination, + CommonCodeSamplerSource codeSamplerSource) = 0; + virtual result::Expected AcceptShaderLiteralArgument(const CommonShaderArgCreatorDestination& destination, + const std::array& literalValue) = 0; + virtual result::Expected AcceptShaderMaterialArgument(const CommonShaderArgCreatorDestination& destination, + unsigned nameHash) = 0; + virtual result::Expected AcceptShaderMaterialArgument(const CommonShaderArgCreatorDestination& destination, + const std::string& nameValue) = 0; + + virtual result::Expected, std::string> FinalizeArgs() = 0; + + static std::unique_ptr CreateDx9(ITechniqueShaderLoader& shaderLoader, AssetCreationContext& context); + static std::unique_ptr + CreateDx11(ITechniqueShaderLoader& shaderLoader, AssetCreationContext& context, CommonCodeSourceInfos& commonCodeSourceInfos); + }; +} // namespace techset diff --git a/src/ObjCompiling/Techset/CommonTechniqueLoader.cpp b/src/ObjCompiling/Techset/CommonTechniqueLoader.cpp index 4def5bcc..6dd21eac 100644 --- a/src/ObjCompiling/Techset/CommonTechniqueLoader.cpp +++ b/src/ObjCompiling/Techset/CommonTechniqueLoader.cpp @@ -1 +1,47 @@ #include "CommonTechniqueLoader.h" + +#include "Parsing/Impl/CommentRemovingStreamProxy.h" +#include "Parsing/Impl/ParserSingleInputStream.h" +#include "Parsing/Simple/SimpleLexer.h" +#include "Parsing/TechniqueFileParser.h" +#include "Techset/TechsetCommon.h" +#include "Utils/Logging/Log.h" + +namespace techset +{ + std::unique_ptr LoadCommonTechnique(const std::string& techniqueName, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + CommonShaderArgCreator& commonShaderArgCreator, + ISearchPath& searchPath, + bool& failure) + { + failure = false; + + const auto fileName = GetFileNameForTechniqueName(techniqueName); + const auto techniqueFile = searchPath.Open(fileName); + if (!techniqueFile.IsOpen()) + return nullptr; + + SimpleLexer::Config lexerConfig; + lexerConfig.m_emit_new_line_tokens = false; + lexerConfig.m_read_strings = true; + lexerConfig.m_string_escape_sequences = false; + lexerConfig.m_read_integer_numbers = true; + lexerConfig.m_read_floating_point_numbers = true; + + const auto baseStream = std::make_unique(*techniqueFile.m_stream, fileName); + const auto commentProxy = std::make_unique(baseStream.get()); + const auto lexer = std::make_unique(commentProxy.get(), std::move(lexerConfig)); + + const auto parser = std::make_unique(*lexer, techniqueName, codeSourceInfos, routingInfos, commonShaderArgCreator); + + const auto success = parser->Parse(); + if (success) + return parser->GetParsingResult(); + + failure = true; + con::error("Parsing technique file \"{}\" failed!", fileName); + return nullptr; + } +} // namespace techset diff --git a/src/ObjCompiling/Techset/CommonTechniqueLoader.h b/src/ObjCompiling/Techset/CommonTechniqueLoader.h index 70722720..77772ed3 100644 --- a/src/ObjCompiling/Techset/CommonTechniqueLoader.h +++ b/src/ObjCompiling/Techset/CommonTechniqueLoader.h @@ -1,12 +1,18 @@ #pragma once #include "Asset/AssetCreationContext.h" +#include "CommonShaderArgCreator.h" #include "Techset/CommonTechnique.h" #include +#include namespace techset { - std::unique_ptr - LoadCommonTechnique(const AssetCreationContext& context, const CommonCodeSourceInfos& codeSourceInfos, const CommonStreamRoutingInfos& routingInfos); + std::unique_ptr LoadCommonTechnique(const std::string& techniqueName, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + CommonShaderArgCreator& commonShaderArgCreator, + ISearchPath& searchPath, + bool& failure); } // namespace techset diff --git a/src/ObjCompiling/Techset/CommonTechsetCache.cpp b/src/ObjCompiling/Techset/CommonTechsetCache.cpp deleted file mode 100644 index aa089e7b..00000000 --- a/src/ObjCompiling/Techset/CommonTechsetCache.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "CommonTechsetCache.h" - -using namespace techset; - -CommonTechset* CommonTechsetCache::GetCachedTechsetDefinition(const std::string& techsetName) const -{ - const auto foundTechset = m_cache.find(techsetName); - - if (foundTechset != m_cache.end()) - return foundTechset->second.get(); - - return nullptr; -} - -void CommonTechsetCache::AddCommonTechsetToCache(std::string name, std::unique_ptr definition) -{ - m_cache.emplace(std::make_pair(std::move(name), std::move(definition))); -} diff --git a/src/ObjCompiling/Techset/CommonTechsetCache.h b/src/ObjCompiling/Techset/CommonTechsetCache.h deleted file mode 100644 index dea2a1d2..00000000 --- a/src/ObjCompiling/Techset/CommonTechsetCache.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "Asset/IZoneAssetCreationState.h" -#include "Techset/CommonTechset.h" - -#include -#include -#include - -namespace techset -{ - class CommonTechsetCache final : public IZoneAssetCreationState - { - public: - [[nodiscard]] CommonTechset* GetCachedTechsetDefinition(const std::string& techsetName) const; - void AddCommonTechsetToCache(std::string name, std::unique_ptr definition); - - private: - std::unordered_map> m_cache; - }; -} // namespace techset diff --git a/src/ObjCompiling/Techset/CommonTechsetLoader.cpp b/src/ObjCompiling/Techset/CommonTechsetLoader.cpp index 407f8f80..faa78f90 100644 --- a/src/ObjCompiling/Techset/CommonTechsetLoader.cpp +++ b/src/ObjCompiling/Techset/CommonTechsetLoader.cpp @@ -9,7 +9,6 @@ #include "Utils/Logging/Log.h" #include -#include #include #include diff --git a/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueNoScopeSequences.cpp b/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueNoScopeSequences.cpp index f94e1a71..baad556e 100644 --- a/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueNoScopeSequences.cpp +++ b/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueNoScopeSequences.cpp @@ -23,10 +23,8 @@ namespace techset protected: void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - assert(state->m_in_pass == false); - state->m_in_pass = true; - - state->m_acceptor->AcceptNextPass(); + assert(!state->m_current_pass); + state->m_current_pass = CommonPass(); } }; } // namespace techset diff --git a/src/ObjCompiling/Techset/Parsing/Sequence/TechniquePassScopeSequences.cpp b/src/ObjCompiling/Techset/Parsing/Sequence/TechniquePassScopeSequences.cpp index fca643b8..7b9b60a9 100644 --- a/src/ObjCompiling/Techset/Parsing/Sequence/TechniquePassScopeSequences.cpp +++ b/src/ObjCompiling/Techset/Parsing/Sequence/TechniquePassScopeSequences.cpp @@ -26,20 +26,18 @@ namespace techset protected: void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - assert(state->m_in_pass == true); + assert(state->m_current_pass); + assert(state->m_technique); - std::string errorMessage; - if (!state->m_acceptor->AcceptEndPass(errorMessage)) - throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), errorMessage); - - state->m_in_pass = false; + state->m_current_pass->m_vertex_declaration.SortRoutingEntries(); + state->m_technique->m_passes.emplace_back(std::move(*state->m_current_pass)); + state->m_current_pass = std::nullopt; } }; class SequenceStateMap final : public TechniqueParser::sequence_t { - static constexpr auto CAPTURE_START = 1; - static constexpr auto CAPTURE_STATE_MAP_NAME = 2; + static constexpr auto CAPTURE_STATE_MAP_NAME = 1; public: SequenceStateMap() @@ -47,7 +45,7 @@ namespace techset const SimpleMatcherFactory create(this); AddMatchers({ - create.Keyword("stateMap").Capture(CAPTURE_START), + create.Keyword("stateMap"), create.String().Capture(CAPTURE_STATE_MAP_NAME), create.Char(';'), }); @@ -56,13 +54,9 @@ namespace techset protected: void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - const auto& firstToken = result.NextCapture(CAPTURE_START); + assert(state->m_current_pass); - std::string errorMessage; - const auto acceptorResult = state->m_acceptor->AcceptStateMap(result.NextCapture(CAPTURE_STATE_MAP_NAME).StringValue(), errorMessage); - - if (!acceptorResult) - throw ParsingException(firstToken.GetPos(), std::move(errorMessage)); + state->m_current_pass->m_state_map = result.NextCapture(CAPTURE_STATE_MAP_NAME).StringValue(); } }; @@ -71,7 +65,7 @@ namespace techset static constexpr auto TAG_VERTEX_SHADER = 1; static constexpr auto TAG_PIXEL_SHADER = 2; - static constexpr auto CAPTURE_START = 1; + static constexpr auto CAPTURE_FIRST_TOKEN = 1; static constexpr auto CAPTURE_VERSION = 2; static constexpr auto CAPTURE_VERSION_MAJOR = 3; static constexpr auto CAPTURE_VERSION_MINOR = 4; @@ -88,7 +82,7 @@ namespace techset create.Keyword("vertexShader").Tag(TAG_VERTEX_SHADER), create.Keyword("pixelShader").Tag(TAG_PIXEL_SHADER), }) - .Capture(CAPTURE_START), + .Capture(CAPTURE_FIRST_TOKEN), create.Or({ create.And({ create.Integer().Capture(CAPTURE_VERSION_MAJOR), @@ -106,31 +100,23 @@ namespace techset protected: void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - const auto& firstToken = result.NextCapture(CAPTURE_START); - // Don't care about shader version since it's stated in the shader bin anyway const auto& shaderNameToken = result.NextCapture(CAPTURE_SHADER_NAME); - bool acceptorResult; - std::string errorMessage; const auto shaderTag = result.NextTag(); assert(shaderTag == TAG_VERTEX_SHADER || shaderTag == TAG_PIXEL_SHADER); + if (shaderTag == TAG_VERTEX_SHADER) - { - acceptorResult = state->m_acceptor->AcceptVertexShader(shaderNameToken.StringValue(), errorMessage); - state->m_current_shader = ShaderSelector::VERTEX_SHADER; - } + state->m_current_shader_type = CommonTechniqueShaderType::VERTEX; else - { - acceptorResult = state->m_acceptor->AcceptPixelShader(shaderNameToken.StringValue(), errorMessage); - state->m_current_shader = ShaderSelector::PIXEL_SHADER; - } + state->m_current_shader_type = CommonTechniqueShaderType::PIXEL; - state->m_in_shader = true; + state->m_current_shader = CommonTechniqueShader(state->m_current_shader_type, shaderNameToken.StringValue()); - if (!acceptorResult) - throw ParsingException(firstToken.GetPos(), std::move(errorMessage)); + auto enterResult = state->m_shader_arg_creator.EnterShader(state->m_current_shader->m_type, state->m_current_shader->m_name); + if (!enterResult.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), enterResult.error()); } }; @@ -191,13 +177,23 @@ namespace techset protected: void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - const auto& firstToken = result.NextCapture(CAPTURE_FIRST_TOKEN); - const std::string destinationString = CreateRoutingString(result, CAPTURE_STREAM_DESTINATION_NAME, CAPTURE_STREAM_DESTINATION_INDEX); - const std::string sourceString = CreateRoutingString(result, CAPTURE_STREAM_SOURCE_NAME, CAPTURE_STREAM_SOURCE_INDEX); + assert(state->m_current_pass); - std::string errorMessage; - if (!state->m_acceptor->AcceptVertexStreamRouting(destinationString, sourceString, errorMessage)) - throw ParsingException(firstToken.GetPos(), std::move(errorMessage)); + const auto& firstToken = result.NextCapture(CAPTURE_FIRST_TOKEN); + + const std::string destinationString = CreateRoutingString(result, CAPTURE_STREAM_DESTINATION_NAME, CAPTURE_STREAM_DESTINATION_INDEX); + const auto maybeDestination = state->m_routing_infos.GetDestinationByName(destinationString); + + if (!maybeDestination.has_value()) + throw ParsingException(firstToken.GetPos(), "Unknown routing destination"); + + const std::string sourceString = CreateRoutingString(result, CAPTURE_STREAM_SOURCE_NAME, CAPTURE_STREAM_SOURCE_INDEX); + const auto maybeSource = state->m_routing_infos.GetSourceByName(sourceString); + + if (!maybeSource.has_value()) + throw ParsingException(firstToken.GetPos(), "Unknown routing source"); + + state->m_current_pass->m_vertex_declaration.m_routing.emplace_back(*maybeSource, *maybeDestination); } }; } // namespace techset diff --git a/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueShaderScopeSequences.cpp b/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueShaderScopeSequences.cpp index 5811a145..40b9e73e 100644 --- a/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueShaderScopeSequences.cpp +++ b/src/ObjCompiling/Techset/Parsing/Sequence/TechniqueShaderScopeSequences.cpp @@ -1,6 +1,7 @@ #include "TechniqueShaderScopeSequences.h" #include "Parsing/Simple/Matcher/SimpleMatcherFactory.h" +#include "Techset/CommonShaderArgCreator.h" #include @@ -10,21 +11,35 @@ namespace techset { class SequenceEndShader final : public TechniqueParser::sequence_t { + static constexpr auto CAPTURE_FIRST_TOKEN = 1; + public: SequenceEndShader() { const SimpleMatcherFactory create(this); AddMatchers({ - create.Char('}'), + create.Char('}').Capture(CAPTURE_FIRST_TOKEN), }); } protected: void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - assert(state->m_in_shader == true); - state->m_in_shader = false; + assert(state->m_current_pass); + assert(state->m_current_shader); + + if (state->m_current_shader_type == CommonTechniqueShaderType::VERTEX) + state->m_current_pass->m_vertex_shader = std::move(*state->m_current_shader); + else + state->m_current_pass->m_pixel_shader = std::move(*state->m_current_shader); + + state->m_current_shader = std::nullopt; + auto finalizationResult = state->m_shader_arg_creator.FinalizeArgs(); + if (!finalizationResult.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), finalizationResult.error()); + + state->m_shader_arg_creator.LeaveShader(); } }; @@ -134,40 +149,120 @@ namespace techset }); } - static void ProcessCodeArgument(const TechniqueParserState* state, SequenceResult& result, ShaderArgument arg, const bool isSampler) + protected: + void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override { - std::vector accessors; - while (result.HasNextCapture(CAPTURE_CODE_ACCESSOR)) - accessors.emplace_back(result.NextCapture(CAPTURE_CODE_ACCESSOR).IdentifierValue()); + assert(state->m_current_shader); - ShaderArgumentCodeSource source; - if (result.HasNextCapture(CAPTURE_CODE_INDEX)) + const auto& shaderArgumentNameToken = result.NextCapture(CAPTURE_SHADER_ARGUMENT); + + CommonShaderArgCreatorDestination destination; + if (result.HasNextCapture(CAPTURE_SHADER_INDEX)) { - const auto& codeIndexToken = result.NextCapture(CAPTURE_CODE_INDEX); - if (codeIndexToken.IntegerValue() < 0) - throw ParsingException(codeIndexToken.GetPos(), "Index cannot be negative"); - source = ShaderArgumentCodeSource(std::move(accessors), static_cast(codeIndexToken.IntegerValue())); + const auto& shaderArgumentIndexToken = result.NextCapture(CAPTURE_SHADER_INDEX); + if (shaderArgumentIndexToken.IntegerValue() < 0) + throw ParsingException(shaderArgumentIndexToken.GetPos(), "Index cannot be negative"); + const auto index = static_cast(shaderArgumentIndexToken.IntegerValue()); + destination = CommonShaderArgCreatorDestination(shaderArgumentNameToken.IdentifierValue(), index); } else - source = ShaderArgumentCodeSource(std::move(accessors)); + destination = CommonShaderArgCreatorDestination(shaderArgumentNameToken.IdentifierValue()); - std::string errorMessage; - if (!isSampler) + const auto typeTag = result.NextTag(); + assert(typeTag == TAG_CONSTANT || typeTag == TAG_SAMPLER || typeTag == TAG_LITERAL || typeTag == TAG_MATERIAL); + + if (typeTag == TAG_CONSTANT || typeTag == TAG_SAMPLER) { - if (!state->m_acceptor->AcceptShaderConstantArgument(state->m_current_shader, std::move(arg), std::move(source), errorMessage)) - throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(errorMessage)); + ProcessCodeArgument(state, result, destination, typeTag == TAG_SAMPLER); + } + else if (typeTag == TAG_LITERAL) + { + ProcessLiteralArgument(state, result, destination); } else { - if (!state->m_acceptor->AcceptShaderSamplerArgument(state->m_current_shader, std::move(arg), std::move(source), errorMessage)) - throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(errorMessage)); + ProcessMaterialArgument(state, result, destination); } } - static void ProcessLiteralArgument(const TechniqueParserState* state, SequenceResult& result, ShaderArgument arg) + private: + static void ProcessCodeArgument(const TechniqueParserState* state, + SequenceResult& result, + const CommonShaderArgCreatorDestination& destination, + const bool isSampler) { - float value[4]; - for (float& i : value) + const auto accessor = GetAccessorValue(result); + + CommonShaderArgValue argValue; + if (isSampler) + { + const auto maybeSamplerSource = state->m_code_source_infos.GetCodeSamplerSourceForAccessor(accessor); + if (!maybeSamplerSource.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Unknown code sampler"); + + argValue.code_const_source = *maybeSamplerSource; + } + else + { + const auto maybeConstSource = state->m_code_source_infos.GetCodeSamplerSourceForAccessor(accessor); + if (!maybeConstSource.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Unknown code constant"); + + argValue.code_const_source = *maybeConstSource; + } + + if (result.HasNextCapture(CAPTURE_CODE_INDEX)) + { + if (isSampler) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Code sampler is not an array"); + + const auto& codeIndexToken = result.NextCapture(CAPTURE_CODE_INDEX); + const auto indexIntValue = codeIndexToken.IntegerValue(); + if (indexIntValue < 0) + throw ParsingException(codeIndexToken.GetPos(), "Index cannot be negative"); + + const auto indexValue = static_cast(indexIntValue); + + size_t codeArraySize = state->m_code_source_infos.GetInfoForCodeConstSource(argValue.code_const_source)->arrayCount; + + if (codeArraySize == 0) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), "Code constant is not an array"); + if (codeArraySize <= indexValue) + { + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), + std::format("Array overflow: Code array has size {}", codeArraySize)); + } + + argValue.code_const_source += static_cast(indexValue); + } + + result::Expected shaderCreatorResult(NoResult{}); + if (isSampler) + shaderCreatorResult = state->m_shader_arg_creator.AcceptShaderSamplerArgument(destination, argValue.code_sampler_source); + else + shaderCreatorResult = state->m_shader_arg_creator.AcceptShaderConstantArgument(destination, argValue.code_const_source); + + if (!shaderCreatorResult.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(shaderCreatorResult.error())); + } + + static std::string GetAccessorValue(SequenceResult& result) + { + std::ostringstream accessorStream; + + accessorStream << result.NextCapture(CAPTURE_CODE_ACCESSOR).IdentifierValue(); + while (result.HasNextCapture(CAPTURE_CODE_ACCESSOR)) + accessorStream << '.' << result.NextCapture(CAPTURE_CODE_ACCESSOR).IdentifierValue(); + + return accessorStream.str(); + } + + static void ProcessLiteralArgument(const TechniqueParserState* state, + SequenceResult& result, + const CommonShaderArgCreatorDestination& destination) + { + std::array argValue; + for (float& i : argValue) { const auto& literalValueToken = result.NextCapture(CAPTURE_LITERAL_VALUE); @@ -177,56 +272,30 @@ namespace techset i = static_cast(literalValueToken.IntegerValue()); } - const ShaderArgumentLiteralSource source(value); - std::string errorMessage; - if (!state->m_acceptor->AcceptShaderLiteralArgument(state->m_current_shader, std::move(arg), source, errorMessage)) - throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(errorMessage)); + auto shaderCreatorResult = state->m_shader_arg_creator.AcceptShaderLiteralArgument(destination, argValue); + + if (!shaderCreatorResult.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(shaderCreatorResult.error())); } - static void ProcessMaterialArgument(const TechniqueParserState* state, SequenceResult& result, ShaderArgument arg) + static void ProcessMaterialArgument(const TechniqueParserState* state, + SequenceResult& result, + const CommonShaderArgCreatorDestination& destination) { - std::string errorMessage; + result::Expected shaderCreatorResult(NoResult{}); if (result.HasNextCapture(CAPTURE_MATERIAL_HASH)) { - ShaderArgumentMaterialSource source(static_cast(result.NextCapture(CAPTURE_MATERIAL_HASH).IntegerValue())); - if (!state->m_acceptor->AcceptShaderMaterialArgument(state->m_current_shader, std::move(arg), std::move(source), errorMessage)) - throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(errorMessage)); + shaderCreatorResult = state->m_shader_arg_creator.AcceptShaderMaterialArgument( + destination, static_cast(result.NextCapture(CAPTURE_MATERIAL_HASH).IntegerValue())); } else { - ShaderArgumentMaterialSource source(result.NextCapture(CAPTURE_MATERIAL_NAME).IdentifierValue()); - if (!state->m_acceptor->AcceptShaderMaterialArgument(state->m_current_shader, std::move(arg), std::move(source), errorMessage)) - throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(errorMessage)); + const auto stringValue = result.NextCapture(CAPTURE_MATERIAL_NAME).IdentifierValue(); + shaderCreatorResult = state->m_shader_arg_creator.AcceptShaderMaterialArgument(destination, stringValue); } - } - protected: - void ProcessMatch(TechniqueParserState* state, SequenceResult& result) const override - { - assert(state->m_in_shader == true); - - const auto& shaderArgumentNameToken = result.NextCapture(CAPTURE_SHADER_ARGUMENT); - - ShaderArgument arg; - if (result.HasNextCapture(CAPTURE_SHADER_INDEX)) - { - const auto& shaderArgumentIndexToken = result.NextCapture(CAPTURE_SHADER_INDEX); - if (shaderArgumentIndexToken.IntegerValue() < 0) - throw ParsingException(shaderArgumentIndexToken.GetPos(), "Index cannot be negative"); - const auto index = static_cast(shaderArgumentIndexToken.IntegerValue()); - arg = ShaderArgument(shaderArgumentNameToken.IdentifierValue(), index); - } - else - arg = ShaderArgument(shaderArgumentNameToken.IdentifierValue()); - - const auto typeTag = result.NextTag(); - assert(typeTag == TAG_CONSTANT || typeTag == TAG_SAMPLER || typeTag == TAG_LITERAL || typeTag == TAG_MATERIAL); - if (typeTag == TAG_CONSTANT || typeTag == TAG_SAMPLER) - ProcessCodeArgument(state, result, std::move(arg), typeTag == TAG_SAMPLER); - else if (typeTag == TAG_LITERAL) - ProcessLiteralArgument(state, result, std::move(arg)); - else - ProcessMaterialArgument(state, result, std::move(arg)); + if (!shaderCreatorResult.has_value()) + throw ParsingException(result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(shaderCreatorResult.error())); } }; } // namespace techset diff --git a/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.cpp b/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.cpp index 1032d6ed..9159ad3e 100644 --- a/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.cpp +++ b/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.cpp @@ -4,20 +4,30 @@ #include "Sequence/TechniquePassScopeSequences.h" #include "Sequence/TechniqueShaderScopeSequences.h" -using namespace techset; - -TechniqueParser::TechniqueParser(SimpleLexer* lexer, ITechniqueDefinitionAcceptor* acceptor) - : AbstractParser(lexer, std::make_unique(acceptor)) +namespace techset { -} + TechniqueParser::TechniqueParser(SimpleLexer& lexer, + std::string techniqueName, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + CommonShaderArgCreator& shaderArgCreator) + : AbstractParser(&lexer, std::make_unique(std::move(techniqueName), codeSourceInfos, routingInfos, shaderArgCreator)) + { + } -const std::vector& TechniqueParser::GetTestsForState() -{ - if (m_state->m_in_shader) - return TechniqueShaderScopeSequences::GetSequences(); + std::unique_ptr TechniqueParser::GetParsingResult() const + { + return std::move(m_state->m_technique); + } - if (m_state->m_in_pass) - return TechniquePassScopeSequences::GetSequences(); + const std::vector& TechniqueParser::GetTestsForState() + { + if (m_state->m_current_shader.has_value()) + return TechniqueShaderScopeSequences::GetSequences(); - return TechniqueNoScopeSequences::GetSequences(); -} + if (m_state->m_current_pass.has_value()) + return TechniquePassScopeSequences::GetSequences(); + + return TechniqueNoScopeSequences::GetSequences(); + } +} // namespace techset diff --git a/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.h b/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.h index 8944f573..b0232bd0 100644 --- a/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.h +++ b/src/ObjCompiling/Techset/Parsing/TechniqueFileParser.h @@ -4,15 +4,21 @@ #include "Parsing/Simple/SimpleLexer.h" #include "Parsing/Simple/SimpleParserValue.h" #include "TechniqueFileParserState.h" +#include "Techset/CommonTechnique.h" namespace techset { class TechniqueParser final : public AbstractParser { + public: + TechniqueParser(SimpleLexer& lexer, + std::string techniqueName, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + CommonShaderArgCreator& shaderArgCreator); + [[nodiscard]] std::unique_ptr GetParsingResult() const; + protected: const std::vector& GetTestsForState() override; - - public: - TechniqueParser(SimpleLexer* lexer, ITechniqueDefinitionAcceptor* acceptor); }; } // namespace techset diff --git a/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.cpp b/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.cpp index 97cdfa52..d0a42cf9 100644 --- a/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.cpp +++ b/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.cpp @@ -1,14 +1,16 @@ #include "TechniqueFileParserState.h" -#include - -using namespace techset; - -TechniqueParserState::TechniqueParserState(ITechniqueDefinitionAcceptor* acceptor) - : m_acceptor(acceptor), - m_in_pass(false), - m_in_shader(false), - m_current_shader(ShaderSelector::VERTEX_SHADER) +namespace techset { - assert(acceptor); -} + TechniqueParserState::TechniqueParserState(std::string techniqueName, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + CommonShaderArgCreator& shaderArgCreator) + : m_technique(std::make_unique(std::move(techniqueName))), + m_code_source_infos(codeSourceInfos), + m_routing_infos(routingInfos), + m_shader_arg_creator(shaderArgCreator), + m_current_shader_type(CommonTechniqueShaderType::VERTEX) + { + } +} // namespace techset diff --git a/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.h b/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.h index b97b143c..2e3d775c 100644 --- a/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.h +++ b/src/ObjCompiling/Techset/Parsing/TechniqueFileParserState.h @@ -1,18 +1,28 @@ #pragma once -#include "Techset/TechniqueDefinitionAcceptor.h" +#include "Techset/CommonShaderArgCreator.h" +#include "Techset/CommonTechnique.h" + +#include namespace techset { class TechniqueParserState { public: - explicit TechniqueParserState(ITechniqueDefinitionAcceptor* acceptor); + TechniqueParserState(std::string techniqueName, + const CommonCodeSourceInfos& codeSourceInfos, + const CommonStreamRoutingInfos& routingInfos, + CommonShaderArgCreator& shaderArgCreator); - ITechniqueDefinitionAcceptor* const m_acceptor; + std::unique_ptr m_technique; - bool m_in_pass; - bool m_in_shader; - ShaderSelector m_current_shader; + const CommonCodeSourceInfos& m_code_source_infos; + const CommonStreamRoutingInfos& m_routing_infos; + CommonShaderArgCreator& m_shader_arg_creator; + + std::optional m_current_pass; + std::optional m_current_shader; + CommonTechniqueShaderType m_current_shader_type; }; } // namespace techset diff --git a/src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.cpp b/src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.cpp deleted file mode 100644 index 473d08c2..00000000 --- a/src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "StateMapFromTechniqueExtractor.h" - -using namespace state_map; - -std::string StateMapFromTechniqueExtractor::RetrieveStateMap() -{ - return std::move(m_state_map); -} - -void StateMapFromTechniqueExtractor::AcceptNextPass() {} - -bool StateMapFromTechniqueExtractor::AcceptEndPass(std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptStateMap(const std::string& stateMapName, std::string& errorMessage) -{ - m_state_map = stateMapName; - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptVertexShader(const std::string& vertexShaderName, std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptPixelShader(const std::string& pixelShaderName, std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptShaderConstantArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentCodeSource source, - std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptShaderSamplerArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentCodeSource source, - std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptShaderLiteralArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentLiteralSource source, - std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptShaderMaterialArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentMaterialSource source, - std::string& errorMessage) -{ - return true; -} - -bool StateMapFromTechniqueExtractor::AcceptVertexStreamRouting(const std::string& destination, const std::string& source, std::string& errorMessage) -{ - return true; -} diff --git a/src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.h b/src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.h deleted file mode 100644 index 48f70d9d..00000000 --- a/src/ObjCompiling/Techset/StateMap/StateMapFromTechniqueExtractor.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "Techset/TechniqueDefinitionAcceptor.h" - -#include - -namespace state_map -{ - class StateMapFromTechniqueExtractor final : public techset::ITechniqueDefinitionAcceptor - { - public: - std::string RetrieveStateMap(); - - void AcceptNextPass() override; - bool AcceptEndPass(std::string& errorMessage) override; - bool AcceptStateMap(const std::string& stateMapName, std::string& errorMessage) override; - bool AcceptVertexShader(const std::string& vertexShaderName, std::string& errorMessage) override; - bool AcceptPixelShader(const std::string& pixelShaderName, std::string& errorMessage) override; - bool AcceptShaderConstantArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentCodeSource source, - std::string& errorMessage) override; - bool AcceptShaderSamplerArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentCodeSource source, - std::string& errorMessage) override; - bool AcceptShaderLiteralArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentLiteralSource source, - std::string& errorMessage) override; - bool AcceptShaderMaterialArgument(techset::ShaderSelector shader, - techset::ShaderArgument shaderArgument, - techset::ShaderArgumentMaterialSource source, - std::string& errorMessage) override; - bool AcceptVertexStreamRouting(const std::string& destination, const std::string& source, std::string& errorMessage) override; - - private: - std::string m_state_map; - }; -} // namespace state_map diff --git a/src/ObjCompiling/Techset/StateMap/StateMapReader.h b/src/ObjCompiling/Techset/StateMap/StateMapReader.h index f3c53161..c1bda74f 100644 --- a/src/ObjCompiling/Techset/StateMap/StateMapReader.h +++ b/src/ObjCompiling/Techset/StateMap/StateMapReader.h @@ -4,7 +4,6 @@ #include "Parsing/StateMapParserState.h" #include "StateMapDefinition.h" #include "Techset/StateMap/StateMapLayout.h" -#include "Utils/ClassUtils.h" #include #include @@ -22,7 +21,7 @@ namespace state_map public: StateMapReader(std::istream& stream, std::string fileName, std::string stateMapName, const StateMapLayout& layout); - _NODISCARD bool IsValidEndState(const StateMapParserState* state) const; - _NODISCARD std::unique_ptr ReadStateMapDefinition() const; + [[nodiscard]] bool IsValidEndState(const StateMapParserState* state) const; + [[nodiscard]] std::unique_ptr ReadStateMapDefinition() const; }; } // namespace state_map diff --git a/src/ObjCompiling/Techset/TechniqueStateMapCache.cpp b/src/ObjCompiling/Techset/StateMap/TechniqueStateMapCache.cpp similarity index 100% rename from src/ObjCompiling/Techset/TechniqueStateMapCache.cpp rename to src/ObjCompiling/Techset/StateMap/TechniqueStateMapCache.cpp diff --git a/src/ObjCompiling/Techset/TechniqueStateMapCache.h b/src/ObjCompiling/Techset/StateMap/TechniqueStateMapCache.h similarity index 69% rename from src/ObjCompiling/Techset/TechniqueStateMapCache.h rename to src/ObjCompiling/Techset/StateMap/TechniqueStateMapCache.h index aaf8b245..be1d8af8 100644 --- a/src/ObjCompiling/Techset/TechniqueStateMapCache.h +++ b/src/ObjCompiling/Techset/StateMap/TechniqueStateMapCache.h @@ -1,8 +1,7 @@ #pragma once #include "Asset/IZoneAssetCreationState.h" -#include "StateMap/StateMapDefinition.h" -#include "Utils/ClassUtils.h" +#include "Techset/StateMap/StateMapDefinition.h" #include #include @@ -13,10 +12,10 @@ namespace techset class TechniqueStateMapCache final : public IZoneAssetCreationState { public: - _NODISCARD const state_map::StateMapDefinition* GetCachedStateMap(const std::string& name) const; + [[nodiscard]] const state_map::StateMapDefinition* GetCachedStateMap(const std::string& name) const; void AddStateMapToCache(std::unique_ptr stateMap); - _NODISCARD const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const; + [[nodiscard]] const state_map::StateMapDefinition* GetStateMapForTechnique(const std::string& techniqueName) const; void SetTechniqueUsesStateMap(std::string techniqueName, const state_map::StateMapDefinition* stateMap); private: diff --git a/src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.cpp b/src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.cpp deleted file mode 100644 index c576a9d3..00000000 --- a/src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "TechniqueDefinitionAcceptor.h" - -using namespace techset; - -ShaderArgument::ShaderArgument() - : m_argument_index_specified(false), - m_argument_index(0u) -{ -} - -ShaderArgument::ShaderArgument(std::string argumentName) - : m_argument_name(std::move(argumentName)), - m_argument_index_specified(false), - m_argument_index(0u) -{ -} - -ShaderArgument::ShaderArgument(std::string argumentName, const unsigned argumentIndex) - : m_argument_name(std::move(argumentName)), - m_argument_index_specified(true), - m_argument_index(argumentIndex) -{ -} - -ShaderArgumentCodeSource::ShaderArgumentCodeSource() - : m_index_accessor_specified(false), - m_index_accessor(0u) -{ -} - -ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector accessors) - : m_accessors(std::move(accessors)), - m_index_accessor_specified(false), - m_index_accessor(0u) -{ -} - -ShaderArgumentCodeSource::ShaderArgumentCodeSource(std::vector accessors, const unsigned indexAccessor) - : m_accessors(std::move(accessors)), - m_index_accessor_specified(true), - m_index_accessor(indexAccessor) -{ -} - -ShaderArgumentLiteralSource::ShaderArgumentLiteralSource() - : m_value{} -{ -} - -ShaderArgumentLiteralSource::ShaderArgumentLiteralSource(const float v0, const float v1, const float v2, const float v3) - : m_value{v0, v1, v2, v3} -{ -} - -ShaderArgumentLiteralSource::ShaderArgumentLiteralSource(float value[4]) - : m_value{value[0], value[1], value[2], value[3]} -{ -} - -namespace techset -{ - bool operator<(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs) - { - if (lhs.m_value[0] < rhs.m_value[0]) - return true; - if (lhs.m_value[0] > rhs.m_value[0]) - return false; - if (lhs.m_value[1] < rhs.m_value[1]) - return true; - if (lhs.m_value[1] > rhs.m_value[1]) - return false; - if (lhs.m_value[2] < rhs.m_value[2]) - return true; - if (lhs.m_value[2] > rhs.m_value[2]) - return false; - if (lhs.m_value[3] < rhs.m_value[3]) - return true; - if (lhs.m_value[3] > rhs.m_value[3]) - return false; - return false; - } - - bool operator<=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs) - { - return !(rhs < lhs); - } - - bool operator>(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs) - { - return rhs < lhs; - } - - bool operator>=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs) - { - return !(lhs < rhs); - } -} // namespace techset - -ShaderArgumentMaterialSource::ShaderArgumentMaterialSource() - : m_is_hash(false), - m_hash(0u) -{ -} - -ShaderArgumentMaterialSource::ShaderArgumentMaterialSource(const unsigned hash) - : m_is_hash(true), - m_hash(hash) -{ -} - -ShaderArgumentMaterialSource::ShaderArgumentMaterialSource(std::string name) - : m_is_hash(false), - m_hash(0u), - m_name(std::move(name)) -{ -} diff --git a/src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.h b/src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.h deleted file mode 100644 index 353c52cb..00000000 --- a/src/ObjCompiling/Techset/TechniqueDefinitionAcceptor.h +++ /dev/null @@ -1,100 +0,0 @@ -#pragma once - -#include -#include - -namespace techset -{ - enum class ShaderSelector - { - VERTEX_SHADER, - PIXEL_SHADER - }; - - class ShaderArgument - { - public: - std::string m_argument_name; - bool m_argument_index_specified; - unsigned m_argument_index; - - ShaderArgument(); - explicit ShaderArgument(std::string argumentName); - ShaderArgument(std::string argumentName, unsigned argumentIndex); - }; - - class ShaderArgumentCodeSource - { - public: - std::vector m_accessors; - bool m_index_accessor_specified; - unsigned m_index_accessor; - - ShaderArgumentCodeSource(); - explicit ShaderArgumentCodeSource(std::vector accessors); - ShaderArgumentCodeSource(std::vector accessors, unsigned indexAccessor); - }; - - class ShaderArgumentLiteralSource - { - public: - float m_value[4]; - - ShaderArgumentLiteralSource(); - ShaderArgumentLiteralSource(float v0, float v1, float v2, float v3); - explicit ShaderArgumentLiteralSource(float value[4]); - - friend bool operator<(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs); - friend bool operator<=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs); - friend bool operator>(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs); - friend bool operator>=(const ShaderArgumentLiteralSource& lhs, const ShaderArgumentLiteralSource& rhs); - }; - - class ShaderArgumentMaterialSource - { - public: - ShaderArgumentMaterialSource(); - explicit ShaderArgumentMaterialSource(unsigned hash); - explicit ShaderArgumentMaterialSource(std::string name); - - bool m_is_hash; - unsigned m_hash; - std::string m_name; - }; - - class ITechniqueDefinitionAcceptor - { - protected: - ITechniqueDefinitionAcceptor() = default; - - public: - virtual ~ITechniqueDefinitionAcceptor() = default; - ITechniqueDefinitionAcceptor(const ITechniqueDefinitionAcceptor& other) = default; - ITechniqueDefinitionAcceptor(ITechniqueDefinitionAcceptor&& other) noexcept = default; - ITechniqueDefinitionAcceptor& operator=(const ITechniqueDefinitionAcceptor& other) = default; - ITechniqueDefinitionAcceptor& operator=(ITechniqueDefinitionAcceptor&& other) noexcept = default; - - virtual void AcceptNextPass() = 0; - virtual bool AcceptEndPass(std::string& errorMessage) = 0; - - virtual bool AcceptStateMap(const std::string& stateMapName, std::string& errorMessage) = 0; - - virtual bool AcceptVertexShader(const std::string& vertexShaderName, std::string& errorMessage) = 0; - virtual bool AcceptPixelShader(const std::string& pixelShaderName, std::string& errorMessage) = 0; - - virtual bool - AcceptShaderConstantArgument(ShaderSelector shader, ShaderArgument shaderArgument, ShaderArgumentCodeSource source, std::string& errorMessage) = 0; - virtual bool - AcceptShaderSamplerArgument(ShaderSelector shader, ShaderArgument shaderArgument, ShaderArgumentCodeSource source, std::string& errorMessage) = 0; - virtual bool AcceptShaderLiteralArgument(ShaderSelector shader, - ShaderArgument shaderArgument, - ShaderArgumentLiteralSource source, - std::string& errorMessage) = 0; - virtual bool AcceptShaderMaterialArgument(ShaderSelector shader, - ShaderArgument shaderArgument, - ShaderArgumentMaterialSource source, - std::string& errorMessage) = 0; - - virtual bool AcceptVertexStreamRouting(const std::string& destination, const std::string& source, std::string& errorMessage) = 0; - }; -} // namespace techset diff --git a/src/ObjCompiling/Techset/TechniqueFileReader.cpp b/src/ObjCompiling/Techset/TechniqueFileReader.cpp deleted file mode 100644 index 884b9b32..00000000 --- a/src/ObjCompiling/Techset/TechniqueFileReader.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "TechniqueFileReader.h" - -#include "Parsing/Impl/CommentRemovingStreamProxy.h" -#include "Parsing/Impl/ParserSingleInputStream.h" -#include "Parsing/Simple/SimpleLexer.h" -#include "Techset/Parsing/TechniqueFileParser.h" -#include "Utils/Logging/Log.h" - -#include - -using namespace techset; - -TechniqueFileReader::TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor) - : m_file_name(std::move(fileName)), - m_acceptor(acceptor) -{ - m_base_stream = std::make_unique(stream, m_file_name); - m_comment_proxy = std::make_unique(m_base_stream.get()); -} - -bool TechniqueFileReader::ReadTechniqueDefinition() const -{ - SimpleLexer::Config lexerConfig; - lexerConfig.m_emit_new_line_tokens = false; - lexerConfig.m_read_strings = true; - lexerConfig.m_string_escape_sequences = false; - lexerConfig.m_read_integer_numbers = true; - lexerConfig.m_read_floating_point_numbers = true; - const auto lexer = std::make_unique(m_comment_proxy.get(), std::move(lexerConfig)); - - const auto parser = std::make_unique(lexer.get(), m_acceptor); - - const auto success = parser->Parse(); - if (success) - return true; - - con::error("Parsing technique file \"{}\" failed!", m_file_name); - return false; -} diff --git a/src/ObjCompiling/Techset/TechniqueFileReader.h b/src/ObjCompiling/Techset/TechniqueFileReader.h deleted file mode 100644 index 9f72828e..00000000 --- a/src/ObjCompiling/Techset/TechniqueFileReader.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "Parsing/IParserLineStream.h" -#include "TechniqueDefinitionAcceptor.h" - -#include -#include - -namespace techset -{ - class TechniqueFileReader - { - public: - TechniqueFileReader(std::istream& stream, std::string fileName, ITechniqueDefinitionAcceptor* acceptor); - - [[nodiscard]] bool ReadTechniqueDefinition() const; - - private: - std::string m_file_name; - ITechniqueDefinitionAcceptor* m_acceptor; - std::unique_ptr m_base_stream; - std::unique_ptr m_comment_proxy; - }; -} // namespace techset diff --git a/src/ObjLoading/Asset/AssetCreationContext.cpp b/src/ObjLoading/Asset/AssetCreationContext.cpp index f547d3e0..e18b2262 100644 --- a/src/ObjLoading/Asset/AssetCreationContext.cpp +++ b/src/ObjLoading/Asset/AssetCreationContext.cpp @@ -67,11 +67,15 @@ AssetCreationContext::AssetCreationContext(Zone& zone, const AssetCreatorCollect : ZoneAssetCreationStateContainer(zone), m_zone(zone), m_forced_asset_pools(std::make_unique(zone, zone.m_priority)), - m_sub_asset_pools(IGame::GetGameById(zone.m_game_id)->GetSubAssetTypeCount()), m_creators(creators), m_ignored_asset_lookup(ignoredAssetLookup), m_forced_load_depth(0u) { + const auto subAssetTypeCount = IGame::GetGameById(zone.m_game_id)->GetSubAssetTypeCount(); + m_sub_asset_pools.resize(subAssetTypeCount); + + for (asset_type_t subAssetType = 0; subAssetType < subAssetTypeCount; subAssetType++) + m_sub_asset_pools[subAssetType] = std::make_unique(); } XAssetInfoGeneric* AssetCreationContext::AddAssetGeneric(GenericAssetRegistration registration) const diff --git a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h new file mode 100644 index 00000000..e69de29b diff --git a/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp b/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h b/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h new file mode 100644 index 00000000..e69de29b diff --git a/src/ObjWriting/Game/T5/Techset/TechsetDumperT5.cpp b/src/ObjWriting/Game/T5/Techset/TechsetDumperT5.cpp index a68a8206..1f7c3460 100644 --- a/src/ObjWriting/Game/T5/Techset/TechsetDumperT5.cpp +++ b/src/ObjWriting/Game/T5/Techset/TechsetDumperT5.cpp @@ -67,106 +67,79 @@ namespace for (auto streamIndex = 0u; streamIndex < streamCount; streamIndex++) { const auto& routing = vertexDecl->routing.data[streamIndex]; - commonRouting.emplace_back(techset::CommonStreamRouting{ - .m_source = static_cast(routing.source), - .m_destination = static_cast(routing.dest), - }); + commonRouting.emplace_back(static_cast(routing.source), + static_cast(routing.dest)); } } - return techset::CommonVertexDeclaration{ - .m_routing = std::move(commonRouting), - }; + return techset::CommonVertexDeclaration(std::move(commonRouting)); } techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg) { + const techset::CommonShaderArgDestination destination{.dx9 = {.m_destination_register = arg.dest}}; + switch (arg.type) { case MTL_ARG_CODE_VERTEX_CONST: case MTL_ARG_CODE_PIXEL_CONST: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::CODE_CONST, - .m_destination = {.dx9 = - { - .m_destination_register = arg.dest, - }}, - .m_value = { - .code_const_source = static_cast(arg.u.codeConst.index), - } + { + const techset::CommonShaderArgValue value{ + .code_const_source = static_cast(arg.u.codeConst.index), }; + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } + case MTL_ARG_MATERIAL_VERTEX_CONST: case MTL_ARG_MATERIAL_PIXEL_CONST: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::MATERIAL_CONST, - .m_destination = {.dx9 = - { - .m_destination_register = arg.dest, - }}, - .m_value = { - .name_hash = arg.u.nameHash, - } + { + const techset::CommonShaderArgValue value{ + .name_hash = arg.u.nameHash, }; + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } + case MTL_ARG_CODE_PIXEL_SAMPLER: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::CODE_SAMPLER, - .m_destination = {.dx9 = - { - .m_destination_register = arg.dest, - }}, - .m_value = { - .code_sampler_source = static_cast(arg.u.codeSampler), - } + { + const techset::CommonShaderArgValue value{ + .code_sampler_source = static_cast(arg.u.codeSampler), }; + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } + case MTL_ARG_MATERIAL_PIXEL_SAMPLER: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::MATERIAL_SAMPLER, - .m_destination = {.dx9 = - { - .m_destination_register = arg.dest, - }}, - .m_value = { - .name_hash = arg.u.nameHash, - } + { + const techset::CommonShaderArgValue value{ + .name_hash = arg.u.nameHash, }; + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } + default: case MTL_ARG_LITERAL_VERTEX_CONST: case MTL_ARG_LITERAL_PIXEL_CONST: + { + techset::CommonShaderArgValue value{}; if (arg.u.literalConst) { - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::LITERAL_CONST, - .m_destination = {.dx9 = - { - .m_destination_register = arg.dest, - }}, - .m_value = { - .literal_value = - { - (*arg.u.literalConst)[0], - (*arg.u.literalConst)[1], - (*arg.u.literalConst)[2], - (*arg.u.literalConst)[3], - }, } + value.literal_value = { + (*arg.u.literalConst)[0], + (*arg.u.literalConst)[1], + (*arg.u.literalConst)[2], + (*arg.u.literalConst)[3], }; } - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::LITERAL_CONST, - .m_destination = {.dx9 = - { - .m_destination_register = arg.dest, - }}, - .m_value = {}, - }; + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } } } - techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialVertexShader* vertexShader) + techset::CommonTechniqueShader ConvertToCommonShader(const MaterialVertexShader* vertexShader) { techset::CommonTechniqueShader result{}; if (!vertexShader) @@ -177,34 +150,16 @@ namespace if (vertexShader->prog.loadDef.program) { - result.m_shader_bin = vertexShader->prog.loadDef.program; - result.m_shader_bin_size = vertexShader->prog.loadDef.programSize * sizeof(uint32_t); - } - - if (pass.args) - { - const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount; - for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++) - { - const auto& arg = pass.args[argIndex]; - - switch (arg.type) - { - case MTL_ARG_CODE_VERTEX_CONST: - case MTL_ARG_MATERIAL_VERTEX_CONST: - case MTL_ARG_LITERAL_VERTEX_CONST: - result.m_args.emplace_back(ConvertToCommonArg(arg)); - break; - default: - break; - } - } + result.m_bin = techset::CommonTechniqueShaderBin{ + .m_shader_bin = vertexShader->prog.loadDef.program, + .m_shader_bin_size = vertexShader->prog.loadDef.programSize * sizeof(uint32_t), + }; } return result; } - techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialPixelShader* pixelShader) + techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPixelShader* pixelShader) { techset::CommonTechniqueShader result{}; if (!pixelShader) @@ -215,30 +170,10 @@ namespace if (pixelShader->prog.loadDef.program) { - result.m_shader_bin = pixelShader->prog.loadDef.program; - result.m_shader_bin_size = pixelShader->prog.loadDef.programSize * sizeof(uint32_t); - } - - if (pass.args) - { - const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount; - for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++) - { - const auto& arg = pass.args[argIndex]; - - switch (arg.type) - { - case MTL_ARG_CODE_PIXEL_CONST: - case MTL_ARG_CODE_PIXEL_SAMPLER: - case MTL_ARG_MATERIAL_PIXEL_CONST: - case MTL_ARG_MATERIAL_PIXEL_SAMPLER: - case MTL_ARG_LITERAL_PIXEL_CONST: - result.m_args.emplace_back(ConvertToCommonArg(arg)); - break; - default: - break; - } - } + result.m_bin = techset::CommonTechniqueShaderBin{ + .m_shader_bin = pixelShader->prog.loadDef.program, + .m_shader_bin_size = pixelShader->prog.loadDef.programSize * sizeof(uint32_t), + }; } return result; @@ -246,37 +181,34 @@ namespace techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) { - std::vector passes; + techset::CommonTechnique commonTechnique(technique.name ? technique.name : std::string(), technique.flags); for (auto passIndex = 0u; passIndex < technique.passCount; passIndex++) { const auto& pass = technique.passArray[passIndex]; + techset::CommonPass commonPass(pass.customSamplerFlags, + // No clue what the actual state map was + "passthrough", + ConvertToCommonShader(pass.vertexShader), + ConvertToCommonShader(pass.pixelShader), + ConvertToCommonVertexDeclaration(pass.vertexDecl)); - passes.emplace_back(techset::CommonPass{ - .m_sampler_flags = pass.customSamplerFlags, - .m_dx_version = techset::DxVersion::DX9, - .m_vertex_shader = ConvertToCommonShader(pass, pass.vertexShader), - .m_pixel_shader = ConvertToCommonShader(pass, pass.pixelShader), - .m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl), - }); + if (pass.args) + { + const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount; + commonPass.m_args.reserve(totalArgCount); + for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++) + commonPass.m_args.emplace_back(ConvertToCommonArg(pass.args[argIndex])); + } + + commonTechnique.m_passes.emplace_back(std::move(commonPass)); } - return techset::CommonTechnique{ - .m_name = technique.name ? technique.name : std::string(), - .m_flags = technique.flags, - .m_passes = std::move(passes), - }; + return commonTechnique; } void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset) { - static techset::CommonCodeSourceInfos codeSourceInfos(commonCodeConstSources, - std::extent_v, - commonCodeSamplerSources, - std::extent_v); - static techset::CommonStreamRoutingInfos routingInfos( - streamRoutingSources, std::extent_v, streamRoutingDestinations, std::extent_v); - auto* techniqueState = context.GetZoneAssetDumperState(); const auto* materialConstantState = context.GetZoneAssetDumperState(); for (const auto* technique : techset.techniques) @@ -285,7 +217,8 @@ namespace { const auto commonTechnique = ConvertToCommonTechnique(*technique); - techset::DumpCommonTechnique(context, commonTechnique, codeSourceInfos, routingInfos, *materialConstantState); + techset::DumpCommonTechnique( + context, commonTechnique, techset::DxVersion::DX9, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState); } } } diff --git a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp index 699dd34d..9293c006 100644 --- a/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp +++ b/src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp @@ -8,8 +8,6 @@ #include "Techset/ShaderDumpingZoneState.h" #include "Techset/TechniqueDumpingZoneState.h" -#include - using namespace T6; namespace @@ -66,16 +64,12 @@ namespace for (auto streamIndex = 0u; streamIndex < streamCount; streamIndex++) { const auto& routing = vertexDecl->routing.data[streamIndex]; - commonRouting.emplace_back(techset::CommonStreamRouting{ - .m_source = static_cast(routing.source), - .m_destination = static_cast(routing.dest), - }); + commonRouting.emplace_back(static_cast(routing.source), + static_cast(routing.dest)); } } - return techset::CommonVertexDeclaration{ - .m_routing = std::move(commonRouting), - }; + return techset::CommonVertexDeclaration(std::move(commonRouting)); } techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg) @@ -84,100 +78,99 @@ namespace { case MTL_ARG_CODE_VERTEX_CONST: case MTL_ARG_CODE_PIXEL_CONST: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::CODE_CONST, - .m_destination = {.dx11 = - { - .m_location = arg.location.offset, - .m_size = arg.size, - .m_buffer = arg.buffer, - }}, - .m_value = { - .code_const_source = static_cast(arg.u.codeConst.index), - } + { + const techset::CommonShaderArgValue value{ + .code_const_source = static_cast(arg.u.codeConst.index), }; + const techset::CommonShaderArgDestination destination = { + .dx11 = { + .m_location = arg.location.offset, + .m_size = arg.size, + .m_buffer = arg.buffer, + } + }; + + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } case MTL_ARG_MATERIAL_VERTEX_CONST: case MTL_ARG_MATERIAL_PIXEL_CONST: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::MATERIAL_CONST, - .m_destination = {.dx11 = - { - .m_location = arg.location.offset, - .m_size = arg.size, - .m_buffer = arg.buffer, - }}, - .m_value = { - .name_hash = arg.u.nameHash, - } + { + const techset::CommonShaderArgValue value{ + .name_hash = arg.u.nameHash, }; + const techset::CommonShaderArgDestination destination = { + .dx11 = { + .m_location = arg.location.offset, + .m_size = arg.size, + .m_buffer = arg.buffer, + } + }; + + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } case MTL_ARG_CODE_PIXEL_SAMPLER: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::CODE_SAMPLER, - .m_destination = {.dx11 = - { - .m_location = arg.location.samplerIndex, - .m_size = arg.size, - .m_buffer = arg.buffer, - }}, - .m_value = { - .code_sampler_source = static_cast(arg.u.codeSampler), - } + { + const techset::CommonShaderArgValue value{ + .code_sampler_source = static_cast(arg.u.codeSampler), + }; + const techset::CommonShaderArgDestination destination = { + .dx11 = { + .m_location = arg.location.samplerIndex, + .m_size = arg.size, + .m_buffer = arg.buffer, + } }; + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } + case MTL_ARG_MATERIAL_PIXEL_SAMPLER: - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::MATERIAL_SAMPLER, - .m_destination = {.dx11 = - { - .m_location = arg.location.samplerIndex, - .m_size = arg.size, - .m_buffer = arg.buffer, - }}, - .m_value = { - .name_hash = arg.u.nameHash, - } + { + const techset::CommonShaderArgValue value{ + .name_hash = arg.u.nameHash, }; + const techset::CommonShaderArgDestination destination = { + .dx11 = { + .m_location = arg.location.samplerIndex, + .m_size = arg.size, + .m_buffer = arg.buffer, + } + }; + + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } default: case MTL_ARG_LITERAL_VERTEX_CONST: case MTL_ARG_LITERAL_PIXEL_CONST: + { + techset::CommonShaderArgValue value{}; if (arg.u.literalConst) { - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::LITERAL_CONST, - .m_destination = {.dx11 = - { - .m_location = arg.location.offset, - .m_size = arg.size, - .m_buffer = arg.buffer, - }}, - .m_value = { - .literal_value = - { - (*arg.u.literalConst)[0], - (*arg.u.literalConst)[1], - (*arg.u.literalConst)[2], - (*arg.u.literalConst)[3], - }, } + value.literal_value = { + (*arg.u.literalConst)[0], + (*arg.u.literalConst)[1], + (*arg.u.literalConst)[2], + (*arg.u.literalConst)[3], }; } - return techset::CommonShaderArg{ - .m_type = techset::CommonShaderArgType::LITERAL_CONST, - .m_destination = {.dx11 = - { - .m_location = arg.location.offset, - .m_size = arg.size, - .m_buffer = arg.buffer, - }}, - .m_value = {}, + const techset::CommonShaderArgDestination destination = { + .dx11 = { + .m_location = arg.location.offset, + .m_size = arg.size, + .m_buffer = arg.buffer, + } }; + + return techset::CommonShaderArg(commonArgumentTypes[arg.type], destination, value); + } } } - techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialVertexShader* vertexShader) + techset::CommonTechniqueShader ConvertToCommonShader(const MaterialVertexShader* vertexShader) { techset::CommonTechniqueShader result{}; if (!vertexShader) @@ -188,34 +181,16 @@ namespace if (vertexShader->prog.loadDef.program) { - result.m_shader_bin = vertexShader->prog.loadDef.program; - result.m_shader_bin_size = vertexShader->prog.loadDef.programSize; - } - - if (pass.args) - { - const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount; - for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++) - { - const auto& arg = pass.args[argIndex]; - - switch (arg.type) - { - case MTL_ARG_CODE_VERTEX_CONST: - case MTL_ARG_MATERIAL_VERTEX_CONST: - case MTL_ARG_LITERAL_VERTEX_CONST: - result.m_args.emplace_back(ConvertToCommonArg(arg)); - break; - default: - break; - } - } + result.m_bin = techset::CommonTechniqueShaderBin{ + .m_shader_bin = vertexShader->prog.loadDef.program, + .m_shader_bin_size = vertexShader->prog.loadDef.programSize, + }; } return result; } - techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPass& pass, const MaterialPixelShader* pixelShader) + techset::CommonTechniqueShader ConvertToCommonShader(const MaterialPixelShader* pixelShader) { techset::CommonTechniqueShader result{}; if (!pixelShader) @@ -226,30 +201,10 @@ namespace if (pixelShader->prog.loadDef.program) { - result.m_shader_bin = pixelShader->prog.loadDef.program; - result.m_shader_bin_size = pixelShader->prog.loadDef.programSize; - } - - if (pass.args) - { - const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount; - for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++) - { - const auto& arg = pass.args[argIndex]; - - switch (arg.type) - { - case MTL_ARG_CODE_PIXEL_CONST: - case MTL_ARG_CODE_PIXEL_SAMPLER: - case MTL_ARG_MATERIAL_PIXEL_CONST: - case MTL_ARG_MATERIAL_PIXEL_SAMPLER: - case MTL_ARG_LITERAL_PIXEL_CONST: - result.m_args.emplace_back(ConvertToCommonArg(arg)); - break; - default: - break; - } - } + result.m_bin = techset::CommonTechniqueShaderBin{ + .m_shader_bin = pixelShader->prog.loadDef.program, + .m_shader_bin_size = pixelShader->prog.loadDef.programSize, + }; } return result; @@ -257,37 +212,34 @@ namespace techset::CommonTechnique ConvertToCommonTechnique(const MaterialTechnique& technique) { - std::vector passes; + techset::CommonTechnique commonTechnique(technique.name ? technique.name : std::string(), technique.flags); for (auto passIndex = 0u; passIndex < technique.passCount; passIndex++) { const auto& pass = technique.passArray[passIndex]; + techset::CommonPass commonPass(pass.customSamplerFlags, + // No clue what the actual state map was + "passthrough", + ConvertToCommonShader(pass.vertexShader), + ConvertToCommonShader(pass.pixelShader), + ConvertToCommonVertexDeclaration(pass.vertexDecl)); - passes.emplace_back(techset::CommonPass{ - .m_sampler_flags = pass.customSamplerFlags, - .m_dx_version = techset::DxVersion::DX11, - .m_vertex_shader = ConvertToCommonShader(pass, pass.vertexShader), - .m_pixel_shader = ConvertToCommonShader(pass, pass.pixelShader), - .m_vertex_declaration = ConvertToCommonVertexDeclaration(pass.vertexDecl), - }); + if (pass.args) + { + const size_t totalArgCount = pass.perPrimArgCount + pass.perObjArgCount + pass.stableArgCount; + commonPass.m_args.reserve(totalArgCount); + for (auto argIndex = 0uz; argIndex < totalArgCount; argIndex++) + commonPass.m_args.emplace_back(ConvertToCommonArg(pass.args[argIndex])); + } + + commonTechnique.m_passes.emplace_back(std::move(commonPass)); } - return techset::CommonTechnique{ - .m_name = technique.name ? technique.name : std::string(), - .m_flags = technique.flags, - .m_passes = std::move(passes), - }; + return commonTechnique; } void DumpTechniques(AssetDumpingContext& context, const MaterialTechniqueSet& techset) { - static techset::CommonCodeSourceInfos codeSourceInfos(commonCodeConstSources, - std::extent_v, - commonCodeSamplerSources, - std::extent_v); - static techset::CommonStreamRoutingInfos routingInfos( - streamRoutingSources, std::extent_v, streamRoutingDestinations, std::extent_v); - auto* techniqueState = context.GetZoneAssetDumperState(); const auto* materialConstantState = context.GetZoneAssetDumperState(); for (const auto* technique : techset.techniques) @@ -296,7 +248,8 @@ namespace { const auto commonTechnique = ConvertToCommonTechnique(*technique); - techset::DumpCommonTechnique(context, commonTechnique, codeSourceInfos, routingInfos, *materialConstantState); + techset::DumpCommonTechnique( + context, commonTechnique, techset::DxVersion::DX11, commonCodeSourceInfos, commonRoutingInfos, *materialConstantState); } } } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp index d50942ab..24e7fbcd 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.cpp +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.cpp @@ -23,10 +23,12 @@ namespace { public: TechniqueFileWriter(std::ostream& stream, + const DxVersion dxVersion, const CommonCodeSourceInfos& codeSourceInfos, const CommonStreamRoutingInfos& routingInfos, const AbstractMaterialConstantZoneState& constantZoneState) : AbstractTextDumper(stream), + m_dx_version(dxVersion), m_code_source_infos(codeSourceInfos), m_routing_infos(routingInfos), m_constant_zone_state(constantZoneState) @@ -73,8 +75,8 @@ namespace #endif DumpStateMap(); - DumpShader(technique, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, pass.m_dx_version); - DumpShader(technique, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, pass.m_dx_version); + DumpShader(technique, pass.m_vertex_shader, TechniqueShaderType::VERTEX_SHADER, m_dx_version); + DumpShader(technique, pass.m_pixel_shader, TechniqueShaderType::PIXEL_SHADER, m_dx_version); DumpVertexDecl(pass.m_vertex_declaration); DecIndent(); @@ -91,7 +93,7 @@ namespace void DumpShader(const CommonTechnique& technique, const CommonTechniqueShader& shader, const TechniqueShaderType shaderType, const DxVersion dxVersion) { - if (!shader.m_shader_bin) + if (!shader.m_bin || !shader.m_bin->m_shader_bin) { if (!shader.m_name.empty()) { @@ -105,7 +107,7 @@ namespace unsigned versionMajor, versionMinor; if (dxVersion == DxVersion::DX9) { - const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); + const auto shaderInfo = d3d9::ShaderAnalyser::GetShaderInfo(shader.m_bin->m_shader_bin, shader.m_bin->m_shader_bin_size); assert(shaderInfo); if (!shaderInfo) return; @@ -121,7 +123,7 @@ namespace else { assert(dxVersion == DxVersion::DX11); - const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_shader_bin, shader.m_shader_bin_size); + const auto shaderInfo = d3d11::ShaderAnalyser::GetShaderInfo(shader.m_bin->m_shader_bin, shader.m_bin->m_shader_bin_size); assert(shaderInfo); if (!shaderInfo) return; @@ -385,6 +387,7 @@ namespace } } + DxVersion m_dx_version; const CommonCodeSourceInfos& m_code_source_infos; const CommonStreamRoutingInfos& m_routing_infos; const AbstractMaterialConstantZoneState& m_constant_zone_state; @@ -395,6 +398,7 @@ namespace techset { void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique, + const DxVersion dxVersion, const CommonCodeSourceInfos& codeSourceInfos, const CommonStreamRoutingInfos& routingInfos, const AbstractMaterialConstantZoneState& constantZoneState) @@ -402,7 +406,7 @@ namespace techset const auto techniqueFile = context.OpenAssetFile(GetFileNameForTechniqueName(technique.m_name)); if (techniqueFile) { - TechniqueFileWriter writer(*techniqueFile, codeSourceInfos, routingInfos, constantZoneState); + TechniqueFileWriter writer(*techniqueFile, dxVersion, codeSourceInfos, routingInfos, constantZoneState); writer.DumpTechnique(technique); } } diff --git a/src/ObjWriting/Techset/CommonTechniqueDumper.h b/src/ObjWriting/Techset/CommonTechniqueDumper.h index 4a3dc943..f2a6a4bd 100644 --- a/src/ObjWriting/Techset/CommonTechniqueDumper.h +++ b/src/ObjWriting/Techset/CommonTechniqueDumper.h @@ -8,6 +8,7 @@ namespace techset { void DumpCommonTechnique(const AssetDumpingContext& context, const CommonTechnique& technique, + DxVersion dxVersion, const CommonCodeSourceInfos& codeSourceInfos, const CommonStreamRoutingInfos& routingInfos, const AbstractMaterialConstantZoneState& constantZoneState);