Shader: Add full support for scalar swizzle

This commit is contained in:
Jérôme Leclercq
2021-12-25 19:13:08 +01:00
parent ec3da7e3f5
commit f98ea6b0ca
5 changed files with 309 additions and 200 deletions

View File

@@ -33,6 +33,8 @@ namespace Nz::ShaderAst
SanitizeVisitor& operator=(const SanitizeVisitor&) = delete;
SanitizeVisitor& operator=(SanitizeVisitor&&) = delete;
static UInt32 ToSwizzleIndex(char c);
struct Options
{
std::unordered_set<std::string> reservedIdentifiers;
@@ -40,6 +42,7 @@ namespace Nz::ShaderAst
bool makeVariableNameUnique = false;
bool removeCompoundAssignments = false;
bool removeOptionDeclaration = true;
bool removeScalarSwizzling = false;
};
private:
@@ -86,6 +89,8 @@ namespace Nz::ShaderAst
void PushScope();
void PopScope();
ExpressionPtr CacheResult(ExpressionPtr expression);
template<typename T> const T& ComputeAttributeValue(AttributeValue<T>& attribute);
ConstantValue ComputeConstantValue(Expression& expr);
template<typename T> std::unique_ptr<T> Optimize(T& node);
@@ -112,7 +117,12 @@ namespace Nz::ShaderAst
void Validate(AccessIndexExpression& node);
void Validate(CallFunctionExpression& node, const DeclareFunctionStatement* referenceDeclaration);
void Validate(CastExpression& node);
void Validate(DeclareVariableStatement& node);
void Validate(IntrinsicExpression& node);
void Validate(SwizzleExpression& node);
void Validate(UnaryExpression& node);
void Validate(VariableExpression& node);
ExpressionType ValidateBinaryOp(BinaryType op, const ExpressionPtr& leftExpr, const ExpressionPtr& rightExpr);
struct FunctionData