Shader: StatementPtr& => const StatementPtr&
This commit is contained in:
parent
1a8599ba29
commit
500ccda85a
|
|
@ -20,15 +20,16 @@ namespace Nz
|
||||||
class NAZARA_GRAPHICS_API UberShader
|
class NAZARA_GRAPHICS_API UberShader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UberShader(ShaderStageType shaderStage, ShaderAst::StatementPtr shaderAst);
|
UberShader(ShaderStageType shaderStage, const ShaderAst::StatementPtr& shaderAst);
|
||||||
~UberShader() = default;
|
~UberShader() = default;
|
||||||
|
|
||||||
UInt64 GetConditionFlagByName(const std::string_view& condition) const;
|
UInt64 GetOptionFlagByName(const std::string& optionName) const;
|
||||||
|
|
||||||
const std::shared_ptr<ShaderModule>& Get(UInt64 combination);
|
const std::shared_ptr<ShaderModule>& Get(UInt64 combination);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<UInt64 /*combination*/, std::shared_ptr<ShaderModule>> m_combinations;
|
std::unordered_map<UInt64 /*combination*/, std::shared_ptr<ShaderModule>> m_combinations;
|
||||||
|
std::unordered_map<std::string, std::size_t> m_optionIndexByName;
|
||||||
ShaderAst::StatementPtr m_shaderAst;
|
ShaderAst::StatementPtr m_shaderAst;
|
||||||
ShaderStageType m_shaderStage;
|
ShaderStageType m_shaderStage;
|
||||||
UInt64 m_combinationMask;
|
UInt64 m_combinationMask;
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,15 @@ namespace Nz::ShaderAst
|
||||||
AstCloner(AstCloner&&) = delete;
|
AstCloner(AstCloner&&) = delete;
|
||||||
~AstCloner() = default;
|
~AstCloner() = default;
|
||||||
|
|
||||||
ExpressionPtr Clone(ExpressionPtr& statement);
|
ExpressionPtr Clone(const ExpressionPtr& statement);
|
||||||
StatementPtr Clone(StatementPtr& statement);
|
StatementPtr Clone(const StatementPtr& statement);
|
||||||
|
|
||||||
AstCloner& operator=(const AstCloner&) = delete;
|
AstCloner& operator=(const AstCloner&) = delete;
|
||||||
AstCloner& operator=(AstCloner&&) = delete;
|
AstCloner& operator=(AstCloner&&) = delete;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline ExpressionPtr CloneExpression(ExpressionPtr& expr);
|
inline ExpressionPtr CloneExpression(const ExpressionPtr& expr);
|
||||||
inline StatementPtr CloneStatement(StatementPtr& statement);
|
inline StatementPtr CloneStatement(const StatementPtr& statement);
|
||||||
|
|
||||||
virtual ExpressionPtr CloneExpression(Expression& expr);
|
virtual ExpressionPtr CloneExpression(Expression& expr);
|
||||||
virtual StatementPtr CloneStatement(Statement& statement);
|
virtual StatementPtr CloneStatement(Statement& statement);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace Nz::ShaderAst
|
namespace Nz::ShaderAst
|
||||||
{
|
{
|
||||||
ExpressionPtr AstCloner::CloneExpression(ExpressionPtr& expr)
|
ExpressionPtr AstCloner::CloneExpression(const ExpressionPtr& expr)
|
||||||
{
|
{
|
||||||
if (!expr)
|
if (!expr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Nz::ShaderAst
|
||||||
return CloneExpression(*expr);
|
return CloneExpression(*expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementPtr AstCloner::CloneStatement(StatementPtr& statement)
|
StatementPtr AstCloner::CloneStatement(const StatementPtr& statement)
|
||||||
{
|
{
|
||||||
if (!statement)
|
if (!statement)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ namespace Nz::ShaderAst
|
||||||
AstOptimizer(AstOptimizer&&) = delete;
|
AstOptimizer(AstOptimizer&&) = delete;
|
||||||
~AstOptimizer() = default;
|
~AstOptimizer() = default;
|
||||||
|
|
||||||
StatementPtr Optimise(StatementPtr& statement);
|
StatementPtr Optimise(const StatementPtr& statement);
|
||||||
StatementPtr Optimise(StatementPtr& statement, UInt64 enabledConditions);
|
StatementPtr Optimise(const StatementPtr& statement, UInt64 enabledConditions);
|
||||||
|
|
||||||
AstOptimizer& operator=(const AstOptimizer&) = delete;
|
AstOptimizer& operator=(const AstOptimizer&) = delete;
|
||||||
AstOptimizer& operator=(AstOptimizer&&) = delete;
|
AstOptimizer& operator=(AstOptimizer&&) = delete;
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ namespace Nz::ShaderAst
|
||||||
SanitizeVisitor(SanitizeVisitor&&) = delete;
|
SanitizeVisitor(SanitizeVisitor&&) = delete;
|
||||||
~SanitizeVisitor() = default;
|
~SanitizeVisitor() = default;
|
||||||
|
|
||||||
inline StatementPtr Sanitize(StatementPtr& statement, std::string* error = nullptr);
|
inline StatementPtr Sanitize(const StatementPtr& statement, std::string* error = nullptr);
|
||||||
StatementPtr Sanitize(StatementPtr& statement, const Options& options, std::string* error = nullptr);
|
StatementPtr Sanitize(const StatementPtr& statement, const Options& options, std::string* error = nullptr);
|
||||||
|
|
||||||
SanitizeVisitor& operator=(const SanitizeVisitor&) = delete;
|
SanitizeVisitor& operator=(const SanitizeVisitor&) = delete;
|
||||||
SanitizeVisitor& operator=(SanitizeVisitor&&) = delete;
|
SanitizeVisitor& operator=(SanitizeVisitor&&) = delete;
|
||||||
|
|
@ -125,8 +125,8 @@ namespace Nz::ShaderAst
|
||||||
Context* m_context;
|
Context* m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline StatementPtr Sanitize(StatementPtr& ast, std::string* error = nullptr);
|
inline StatementPtr Sanitize(const StatementPtr& ast, std::string* error = nullptr);
|
||||||
inline StatementPtr Sanitize(StatementPtr& ast, const SanitizeVisitor::Options& options, std::string* error = nullptr);
|
inline StatementPtr Sanitize(const StatementPtr& ast, const SanitizeVisitor::Options& options, std::string* error = nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Shader/Ast/SanitizeVisitor.inl>
|
#include <Nazara/Shader/Ast/SanitizeVisitor.inl>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Nz::ShaderAst
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline StatementPtr SanitizeVisitor::Sanitize(StatementPtr& statement, std::string* error)
|
inline StatementPtr SanitizeVisitor::Sanitize(const StatementPtr& statement, std::string* error)
|
||||||
{
|
{
|
||||||
return Sanitize(statement, {}, error);
|
return Sanitize(statement, {}, error);
|
||||||
}
|
}
|
||||||
|
|
@ -76,13 +76,13 @@ namespace Nz::ShaderAst
|
||||||
return varIndex;
|
return varIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementPtr Sanitize(StatementPtr& ast, std::string* error)
|
StatementPtr Sanitize(const StatementPtr& ast, std::string* error)
|
||||||
{
|
{
|
||||||
SanitizeVisitor sanitizer;
|
SanitizeVisitor sanitizer;
|
||||||
return sanitizer.Sanitize(ast, error);
|
return sanitizer.Sanitize(ast, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementPtr Sanitize(StatementPtr& ast, const SanitizeVisitor::Options& options, std::string* error)
|
StatementPtr Sanitize(const StatementPtr& ast, const SanitizeVisitor::Options& options, std::string* error)
|
||||||
{
|
{
|
||||||
SanitizeVisitor sanitizer;
|
SanitizeVisitor sanitizer;
|
||||||
return sanitizer.Sanitize(ast, options, error);
|
return sanitizer.Sanitize(ast, options, error);
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,7 @@ namespace Nz
|
||||||
void Visit(ShaderAst::ConditionalStatement& node) override;
|
void Visit(ShaderAst::ConditionalStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareExternalStatement& node) override;
|
void Visit(ShaderAst::DeclareExternalStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareFunctionStatement& node) override;
|
void Visit(ShaderAst::DeclareFunctionStatement& node) override;
|
||||||
|
void Visit(ShaderAst::DeclareOptionStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareStructStatement& node) override;
|
void Visit(ShaderAst::DeclareStructStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareVariableStatement& node) override;
|
void Visit(ShaderAst::DeclareVariableStatement& node) override;
|
||||||
void Visit(ShaderAst::DiscardStatement& node) override;
|
void Visit(ShaderAst::DiscardStatement& node) override;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ namespace Nz
|
||||||
struct States
|
struct States
|
||||||
{
|
{
|
||||||
Nz::UInt64 enabledOptions = 0;
|
Nz::UInt64 enabledOptions = 0;
|
||||||
|
bool sanitized = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ namespace Nz
|
||||||
void Visit(ShaderAst::ConstantExpression& node) override;
|
void Visit(ShaderAst::ConstantExpression& node) override;
|
||||||
void Visit(ShaderAst::DeclareExternalStatement& node) override;
|
void Visit(ShaderAst::DeclareExternalStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareFunctionStatement& node) override;
|
void Visit(ShaderAst::DeclareFunctionStatement& node) override;
|
||||||
|
void Visit(ShaderAst::DeclareOptionStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareStructStatement& node) override;
|
void Visit(ShaderAst::DeclareStructStatement& node) override;
|
||||||
void Visit(ShaderAst::DeclareVariableStatement& node) override;
|
void Visit(ShaderAst::DeclareVariableStatement& node) override;
|
||||||
void Visit(ShaderAst::DiscardStatement& node) override;
|
void Visit(ShaderAst::DiscardStatement& node) override;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace Nz::ShaderAst
|
namespace Nz::ShaderAst
|
||||||
{
|
{
|
||||||
ExpressionPtr AstCloner::Clone(ExpressionPtr& expr)
|
ExpressionPtr AstCloner::Clone(const ExpressionPtr& expr)
|
||||||
{
|
{
|
||||||
expr->Visit(*this);
|
expr->Visit(*this);
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Nz::ShaderAst
|
||||||
return PopExpression();
|
return PopExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementPtr AstCloner::Clone(StatementPtr& statement)
|
StatementPtr AstCloner::Clone(const StatementPtr& statement)
|
||||||
{
|
{
|
||||||
statement->Visit(*this);
|
statement->Visit(*this);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -380,13 +380,13 @@ namespace Nz::ShaderAst
|
||||||
#undef EnableOptimisation
|
#undef EnableOptimisation
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementPtr AstOptimizer::Optimise(StatementPtr& statement)
|
StatementPtr AstOptimizer::Optimise(const StatementPtr& statement)
|
||||||
{
|
{
|
||||||
m_enabledOptions.reset();
|
m_enabledOptions.reset();
|
||||||
return CloneStatement(statement);
|
return CloneStatement(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
StatementPtr AstOptimizer::Optimise(StatementPtr& statement, UInt64 enabledConditions)
|
StatementPtr AstOptimizer::Optimise(const StatementPtr& statement, UInt64 enabledConditions)
|
||||||
{
|
{
|
||||||
m_enabledOptions = enabledConditions;
|
m_enabledOptions = enabledConditions;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Nz::ShaderAst
|
||||||
std::unordered_set<unsigned int> usedBindingIndexes;
|
std::unordered_set<unsigned int> usedBindingIndexes;
|
||||||
};
|
};
|
||||||
|
|
||||||
StatementPtr SanitizeVisitor::Sanitize(StatementPtr& nodePtr, const Options& options, std::string* error)
|
StatementPtr SanitizeVisitor::Sanitize(const StatementPtr& nodePtr, const Options& options, std::string* error)
|
||||||
{
|
{
|
||||||
StatementPtr clone;
|
StatementPtr clone;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue