Shader: Rework Swizzle and add support for swizzle store in SPIRV
This commit is contained in:
@@ -128,14 +128,6 @@ namespace Nz
|
||||
UInt32, //< ui32
|
||||
};
|
||||
|
||||
enum class SwizzleComponent
|
||||
{
|
||||
First,
|
||||
Second,
|
||||
Third,
|
||||
Fourth
|
||||
};
|
||||
|
||||
enum class UnaryType
|
||||
{
|
||||
LogicalNot, //< !v
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Nz::ShaderAst
|
||||
NodeType GetType() const override;
|
||||
void Visit(AstExpressionVisitor& visitor) override;
|
||||
|
||||
std::array<SwizzleComponent, 4> components;
|
||||
std::array<UInt32, 4> components;
|
||||
std::size_t componentCount;
|
||||
ExpressionPtr expression;
|
||||
};
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Nz::ShaderBuilder
|
||||
|
||||
struct Swizzle
|
||||
{
|
||||
inline std::unique_ptr<ShaderAst::SwizzleExpression> operator()(ShaderAst::ExpressionPtr expression, std::vector<ShaderAst::SwizzleComponent> swizzleComponents) const;
|
||||
inline std::unique_ptr<ShaderAst::SwizzleExpression> operator()(ShaderAst::ExpressionPtr expression, std::vector<UInt32> swizzleComponents) const;
|
||||
};
|
||||
|
||||
struct Unary
|
||||
|
||||
@@ -277,7 +277,7 @@ namespace Nz::ShaderBuilder
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
inline std::unique_ptr<ShaderAst::SwizzleExpression> Impl::Swizzle::operator()(ShaderAst::ExpressionPtr expression, std::vector<ShaderAst::SwizzleComponent> swizzleComponents) const
|
||||
inline std::unique_ptr<ShaderAst::SwizzleExpression> Impl::Swizzle::operator()(ShaderAst::ExpressionPtr expression, std::vector<UInt32> swizzleComponents) const
|
||||
{
|
||||
auto swizzleNode = std::make_unique<ShaderAst::SwizzleExpression>();
|
||||
swizzleNode->expression = std::move(expression);
|
||||
@@ -285,7 +285,10 @@ namespace Nz::ShaderBuilder
|
||||
assert(swizzleComponents.size() <= swizzleNode->components.size());
|
||||
swizzleNode->componentCount = swizzleComponents.size();
|
||||
for (std::size_t i = 0; i < swizzleNode->componentCount; ++i)
|
||||
{
|
||||
assert(swizzleComponents[i] >= 0 && swizzleComponents[i] <= 4);
|
||||
swizzleNode->components[i] = swizzleComponents[i];
|
||||
}
|
||||
|
||||
return swizzleNode;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Shader/Config.hpp>
|
||||
#include <Nazara/Shader/SpirvData.hpp>
|
||||
#include <Nazara/Shader/Ast/AstExpressionVisitorExcept.hpp>
|
||||
#include <Nazara/Shader/Ast/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -37,21 +38,23 @@ namespace Nz
|
||||
SpirvExpressionStore& operator=(SpirvExpressionStore&&) = delete;
|
||||
|
||||
private:
|
||||
struct LocalVar
|
||||
{
|
||||
std::string varName;
|
||||
};
|
||||
|
||||
struct Pointer
|
||||
{
|
||||
SpirvStorageClass storage;
|
||||
UInt32 pointerId;
|
||||
};
|
||||
|
||||
struct SwizzledPointer : Pointer
|
||||
{
|
||||
ShaderAst::VectorType swizzledType;
|
||||
std::array<UInt32, 4> swizzleIndices;
|
||||
std::size_t componentCount;
|
||||
};
|
||||
|
||||
SpirvAstVisitor& m_visitor;
|
||||
SpirvBlock& m_block;
|
||||
SpirvWriter& m_writer;
|
||||
std::variant<std::monostate, LocalVar, Pointer> m_value;
|
||||
std::variant<std::monostate, Pointer, SwizzledPointer> m_value;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user