Shader: Add constant cast optimization
This commit is contained in:
@@ -31,13 +31,18 @@ namespace Nz::ShaderAst
|
||||
|
||||
protected:
|
||||
ExpressionPtr Clone(BinaryExpression& node) override;
|
||||
ExpressionPtr Clone(CastExpression& node) override;
|
||||
ExpressionPtr Clone(ConditionalExpression& node) override;
|
||||
ExpressionPtr Clone(UnaryExpression& node) override;
|
||||
StatementPtr Clone(BranchStatement& node) override;
|
||||
StatementPtr Clone(ConditionalStatement& node) override;
|
||||
|
||||
template<BinaryType Type> ExpressionPtr PropagateConstant(std::unique_ptr<ConstantExpression>&& lhs, std::unique_ptr<ConstantExpression>&& rhs);
|
||||
template<UnaryType Type> ExpressionPtr PropagateConstant(std::unique_ptr<ConstantExpression>&& operand);
|
||||
template<BinaryType Type> ExpressionPtr PropagateBinaryConstant(std::unique_ptr<ConstantExpression>&& lhs, std::unique_ptr<ConstantExpression>&& rhs);
|
||||
template<typename TargetType> ExpressionPtr PropagateSingleValueCast(std::unique_ptr<ConstantExpression>&& operand);
|
||||
template<UnaryType Type> ExpressionPtr PropagateUnaryConstant(std::unique_ptr<ConstantExpression>&& operand);
|
||||
template<typename TargetType> ExpressionPtr PropagateVec2Cast(TargetType v1, TargetType v2);
|
||||
template<typename TargetType> ExpressionPtr PropagateVec3Cast(TargetType v1, TargetType v2, TargetType v3);
|
||||
template<typename TargetType> ExpressionPtr PropagateVec4Cast(TargetType v1, TargetType v2, TargetType v3, TargetType v4);
|
||||
|
||||
private:
|
||||
std::optional<UInt64> m_enabledOptions;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/Ast/ExpressionType.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz::ShaderAst
|
||||
@@ -27,6 +29,8 @@ namespace Nz::ShaderAst
|
||||
Vector3i32,
|
||||
Vector4i32
|
||||
>;
|
||||
|
||||
NAZARA_SHADER_API ExpressionType GetExpressionType(const ConstantValue& constant);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <Nazara/Shader/Ast/Attribute.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
@@ -126,8 +126,6 @@ namespace Nz::ShaderAst
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
ExpressionType GetExpressionType() const;
|
||||
|
||||
ShaderAst::ConstantValue value;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Shader/Ast/Nodes.hpp>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
@@ -39,6 +40,7 @@ namespace Nz::ShaderBuilder
|
||||
|
||||
struct Cast
|
||||
{
|
||||
inline std::unique_ptr<ShaderAst::CastExpression> operator()(ShaderAst::ExpressionType targetType, std::array<ShaderAst::ExpressionPtr, 4> expressions) const;
|
||||
inline std::unique_ptr<ShaderAst::CastExpression> operator()(ShaderAst::ExpressionType targetType, std::vector<ShaderAst::ExpressionPtr> expressions) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -58,6 +58,15 @@ namespace Nz::ShaderBuilder
|
||||
return branchNode;
|
||||
}
|
||||
|
||||
inline std::unique_ptr<ShaderAst::CastExpression> Impl::Cast::operator()(ShaderAst::ExpressionType targetType, std::array<ShaderAst::ExpressionPtr, 4> expressions) const
|
||||
{
|
||||
auto castNode = std::make_unique<ShaderAst::CastExpression>();
|
||||
castNode->expressions = std::move(expressions);
|
||||
castNode->targetType = std::move(targetType);
|
||||
|
||||
return castNode;
|
||||
}
|
||||
|
||||
inline std::unique_ptr<ShaderAst::CastExpression> Impl::Cast::operator()(ShaderAst::ExpressionType targetType, std::vector<ShaderAst::ExpressionPtr> expressions) const
|
||||
{
|
||||
auto castNode = std::make_unique<ShaderAst::CastExpression>();
|
||||
|
||||
Reference in New Issue
Block a user