diff --git a/include/Nazara/Graphics.hpp b/include/Nazara/Graphics.hpp index 08c7e86e7..8241fa52f 100644 --- a/include/Nazara/Graphics.hpp +++ b/include/Nazara/Graphics.hpp @@ -95,7 +95,6 @@ #include #include #include -#include #include #include #include diff --git a/include/Nazara/Graphics/MaterialPass.hpp b/include/Nazara/Graphics/MaterialPass.hpp index 77b00489c..d02442769 100644 --- a/include/Nazara/Graphics/MaterialPass.hpp +++ b/include/Nazara/Graphics/MaterialPass.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,7 @@ namespace Nz { MaterialPassFlags flags; RenderStates states; - std::unordered_map options; + std::unordered_map options; std::vector> shaders; }; } diff --git a/include/Nazara/Graphics/ShaderReflection.hpp b/include/Nazara/Graphics/ShaderReflection.hpp index fa057a4be..ccbb4b14c 100644 --- a/include/Nazara/Graphics/ShaderReflection.hpp +++ b/include/Nazara/Graphics/ShaderReflection.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -82,7 +83,7 @@ namespace Nz struct OptionData { nzsl::Ast::ExpressionType type; - UInt32 hash; + nzsl::Ast::OptionHash hash; }; struct StructMemberData diff --git a/include/Nazara/Graphics/UberShader.hpp b/include/Nazara/Graphics/UberShader.hpp index 91f5de5c3..669beacd9 100644 --- a/include/Nazara/Graphics/UberShader.hpp +++ b/include/Nazara/Graphics/UberShader.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ namespace Nz struct Option { - UInt32 hash; + nzsl::Ast::OptionHash hash; }; NazaraSignal(OnShaderUpdated, UberShader* /*uberShader*/); diff --git a/src/Nazara/Graphics/Graphics.cpp b/src/Nazara/Graphics/Graphics.cpp index 7d8074ea0..b66d4a573 100644 --- a/src/Nazara/Graphics/Graphics.cpp +++ b/src/Nazara/Graphics/Graphics.cpp @@ -256,6 +256,8 @@ namespace Nz void Graphics::BuildDefaultMaterials() { + using namespace nzsl::Ast::Literals; + std::size_t depthPassIndex = m_materialPassRegistry.GetPassIndex("DepthPass"); std::size_t shadowPassIndex = m_materialPassRegistry.GetPassIndex("ShadowPass"); std::size_t distanceShadowPassIndex = m_materialPassRegistry.GetPassIndex("DistanceShadowPass"); @@ -274,17 +276,17 @@ namespace Nz settings.AddPass(forwardPassIndex, forwardPass); MaterialPass depthPass = forwardPass; - depthPass.options[CRC32("DepthPass")] = true; + depthPass.options["DepthPass"_opt] = true; settings.AddPass(depthPassIndex, depthPass); MaterialPass shadowPass = depthPass; - shadowPass.options[CRC32("ShadowPass")] = true; + shadowPass.options["ShadowPass"_opt] = true; shadowPass.states.frontFace = FrontFace::Clockwise; shadowPass.states.depthClamp = enabledFeatures.depthClamping; settings.AddPass(shadowPassIndex, shadowPass); MaterialPass distanceShadowPass = shadowPass; - distanceShadowPass.options[CRC32("DistanceDepth")] = true; + distanceShadowPass.options["DistanceDepth"_opt] = true; settings.AddPass(distanceShadowPassIndex, distanceShadowPass); m_defaultMaterials.materials[MaterialType::Basic].material = std::make_shared(std::move(settings), "BasicMaterial"); @@ -302,17 +304,17 @@ namespace Nz settings.AddPass(forwardPassIndex, forwardPass); MaterialPass depthPass = forwardPass; - depthPass.options[CRC32("DepthPass")] = true; + depthPass.options["DepthPass"_opt] = true; settings.AddPass(depthPassIndex, depthPass); MaterialPass shadowPass = depthPass; - shadowPass.options[CRC32("ShadowPass")] = true; + shadowPass.options["ShadowPass"_opt] = true; shadowPass.states.frontFace = FrontFace::Clockwise; shadowPass.states.depthClamp = enabledFeatures.depthClamping; settings.AddPass(shadowPassIndex, shadowPass); MaterialPass distanceShadowPass = shadowPass; - distanceShadowPass.options[CRC32("DistanceDepth")] = true; + distanceShadowPass.options["DistanceDepth"_opt] = true; settings.AddPass(distanceShadowPassIndex, distanceShadowPass); m_defaultMaterials.materials[MaterialType::PhysicallyBased].material = std::make_shared(std::move(settings), "PhysicallyBasedMaterial"); @@ -330,17 +332,17 @@ namespace Nz settings.AddPass(forwardPassIndex, forwardPass); MaterialPass depthPass = forwardPass; - depthPass.options[CRC32("DepthPass")] = true; + depthPass.options["DepthPass"_opt] = true; settings.AddPass(depthPassIndex, depthPass); MaterialPass shadowPass = depthPass; - shadowPass.options[CRC32("ShadowPass")] = true; + shadowPass.options["ShadowPass"_opt] = true; shadowPass.states.frontFace = FrontFace::Clockwise; shadowPass.states.depthClamp = enabledFeatures.depthClamping; settings.AddPass(shadowPassIndex, shadowPass); MaterialPass distanceShadowPass = shadowPass; - distanceShadowPass.options[CRC32("DistanceDepth")] = true; + distanceShadowPass.options["DistanceDepth"_opt] = true; settings.AddPass(distanceShadowPassIndex, distanceShadowPass); m_defaultMaterials.materials[MaterialType::Phong].material = std::make_shared(std::move(settings), "PhongMaterial"); diff --git a/src/Nazara/Graphics/Material.cpp b/src/Nazara/Graphics/Material.cpp index f082a185b..d83c162b5 100644 --- a/src/Nazara/Graphics/Material.cpp +++ b/src/Nazara/Graphics/Material.cpp @@ -26,6 +26,8 @@ namespace Nz Material::Material(MaterialSettings settings, const nzsl::Ast::ModulePtr& referenceModule) : m_settings(std::move(settings)) { + using namespace nzsl::Ast::Literals; + NazaraAssert(referenceModule, "invalid module"); Graphics* graphics = Graphics::Instance(); @@ -36,9 +38,9 @@ namespace Nz options.forceAutoBindingResolve = true; options.partialSanitization = true; options.moduleResolver = graphics->GetShaderModuleResolver(); - options.optionValues[CRC32("MaxLightCount")] = SafeCast(PredefinedLightData::MaxLightCount); - options.optionValues[CRC32("MaxLightCascadeCount")] = SafeCast(PredefinedDirectionalLightData::MaxLightCascadeCount); - options.optionValues[CRC32("MaxJointCount")] = SafeCast(PredefinedSkeletalData::MaxMatricesCount); + options.optionValues["MaxLightCount"_opt] = SafeCast(PredefinedLightData::MaxLightCount); + options.optionValues["MaxLightCascadeCount"_opt] = SafeCast(PredefinedDirectionalLightData::MaxLightCascadeCount); + options.optionValues["MaxJointCount"_opt] = SafeCast(PredefinedSkeletalData::MaxMatricesCount); nzsl::Ast::ModulePtr sanitizedModule = nzsl::Ast::Sanitize(*referenceModule, options); @@ -123,6 +125,8 @@ namespace Nz { uberShader->UpdateConfigCallback([=](UberShader::Config& config, const std::vector& vertexBuffers) { + using namespace nzsl::Ast::Literals; + if (vertexBuffers.empty()) return; @@ -135,35 +139,35 @@ namespace Nz switch (component.component) { case VertexComponent::Color: - config.optionValues[CRC32("VertexColorLoc")] = locationIndex; + config.optionValues["VertexColorLoc"_opt] = locationIndex; break; case VertexComponent::Normal: - config.optionValues[CRC32("VertexNormalLoc")] = locationIndex; + config.optionValues["VertexNormalLoc"_opt] = locationIndex; break; case VertexComponent::Position: - config.optionValues[CRC32("VertexPositionLoc")] = locationIndex; + config.optionValues["VertexPositionLoc"_opt] = locationIndex; break; case VertexComponent::SizeSinCos: - config.optionValues[CRC32("VertexSizeRotLocation")] = locationIndex; + config.optionValues["VertexSizeRotLocation"_opt] = locationIndex; break; case VertexComponent::Tangent: - config.optionValues[CRC32("VertexTangentLoc")] = locationIndex; + config.optionValues["VertexTangentLoc"_opt] = locationIndex; break; case VertexComponent::TexCoord: - config.optionValues[CRC32("VertexUvLoc")] = locationIndex; + config.optionValues["VertexUvLoc"_opt] = locationIndex; break; case VertexComponent::JointIndices: - config.optionValues[CRC32("VertexJointIndicesLoc")] = locationIndex; + config.optionValues["VertexJointIndicesLoc"_opt] = locationIndex; break; case VertexComponent::JointWeights: - config.optionValues[CRC32("VertexJointWeightsLoc")] = locationIndex; + config.optionValues["VertexJointWeightsLoc"_opt] = locationIndex; break; case VertexComponent::Unused: diff --git a/src/Nazara/Graphics/ShaderReflection.cpp b/src/Nazara/Graphics/ShaderReflection.cpp index 1ed196d08..d9d6540fb 100644 --- a/src/Nazara/Graphics/ShaderReflection.cpp +++ b/src/Nazara/Graphics/ShaderReflection.cpp @@ -157,7 +157,7 @@ namespace Nz throw std::runtime_error("option " + node.optName + " condition must be resolved"); OptionData& optionData = m_options[node.optName]; - optionData.hash = CRC32(node.optName); + optionData.hash = nzsl::Ast::HashOption(node.optName); optionData.type = node.optType.GetResultingValue(); } diff --git a/src/Nazara/Graphics/UberShader.cpp b/src/Nazara/Graphics/UberShader.cpp index 2b0ce2fbc..8fc32cc38 100644 --- a/src/Nazara/Graphics/UberShader.cpp +++ b/src/Nazara/Graphics/UberShader.cpp @@ -137,7 +137,7 @@ namespace Nz //TODO: Check optionType optionByName[option.optName] = Option{ - CRC32(option.optName) + nzsl::Ast::HashOption(option.optName) }; }; diff --git a/tests/RenderTest/main.cpp b/tests/RenderTest/main.cpp index 8728dba62..dee8f85fc 100644 --- a/tests/RenderTest/main.cpp +++ b/tests/RenderTest/main.cpp @@ -113,7 +113,7 @@ int main() } nzsl::ShaderWriter::States states; - states.optionValues[Nz::CRC32("red")] = false; //< Try enabling this! + states.optionValues[nzsl::Ast::HashOption("red")] = false; //< Try enabling this! states.optimize = true; auto fragVertShader = device->InstantiateShaderModule(nzsl::ShaderStageType::Fragment | nzsl::ShaderStageType::Vertex, *shaderModule, states); diff --git a/xmake.lua b/xmake.lua index 87f57ecaa..80f211acc 100644 --- a/xmake.lua +++ b/xmake.lua @@ -305,7 +305,7 @@ if has_config("platform") then end if has_config("renderer") then - add_requires("nzsl", { debug = is_mode("debug"), configs = { with_symbols = not is_mode("release"), shared = not is_plat("wasm", "android") and not has_config("static") } }) + add_requires("nzsl >=2023.12.17+1", { debug = is_mode("debug"), configs = { with_symbols = not is_mode("release"), shared = not is_plat("wasm", "android") and not has_config("static") } }) local function is_cross_compiling() if os.host() == "windows" then