Shader: Fix SpirV generation for Swizzle expressions
+ fix OpSampledImage
This commit is contained in:
parent
bfb93bc925
commit
eb67990b7b
|
|
@ -727,16 +727,17 @@ namespace Nz
|
||||||
|
|
||||||
void SpirvAstVisitor::Visit(ShaderAst::SwizzleExpression& node)
|
void SpirvAstVisitor::Visit(ShaderAst::SwizzleExpression& node)
|
||||||
{
|
{
|
||||||
const ShaderAst::ExpressionType& targetExprType = GetExpressionType(node);
|
|
||||||
assert(IsPrimitiveType(targetExprType));
|
|
||||||
|
|
||||||
ShaderAst::PrimitiveType targetType = std::get<ShaderAst::PrimitiveType>(targetExprType);
|
|
||||||
|
|
||||||
UInt32 exprResultId = EvaluateExpression(node.expression);
|
UInt32 exprResultId = EvaluateExpression(node.expression);
|
||||||
UInt32 resultId = m_writer.AllocateResultId();
|
UInt32 resultId = m_writer.AllocateResultId();
|
||||||
|
|
||||||
|
const ShaderAst::ExpressionType& targetExprType = GetExpressionType(node);
|
||||||
|
|
||||||
if (node.componentCount > 1)
|
if (node.componentCount > 1)
|
||||||
{
|
{
|
||||||
|
assert(IsVectorType(targetExprType));
|
||||||
|
|
||||||
|
const ShaderAst::VectorType& targetType = std::get<ShaderAst::VectorType>(targetExprType);
|
||||||
|
|
||||||
// Swizzling is implemented via SpirvOp::OpVectorShuffle using the same vector twice as operands
|
// Swizzling is implemented via SpirvOp::OpVectorShuffle using the same vector twice as operands
|
||||||
m_currentBlock->AppendVariadic(SpirvOp::OpVectorShuffle, [&](const auto& appender)
|
m_currentBlock->AppendVariadic(SpirvOp::OpVectorShuffle, [&](const auto& appender)
|
||||||
{
|
{
|
||||||
|
|
@ -751,6 +752,10 @@ namespace Nz
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
assert(IsPrimitiveType(targetExprType));
|
||||||
|
|
||||||
|
ShaderAst::PrimitiveType targetType = std::get<ShaderAst::PrimitiveType>(targetExprType);
|
||||||
|
|
||||||
// Extract a single component from the vector
|
// Extract a single component from the vector
|
||||||
assert(node.componentCount == 1);
|
assert(node.componentCount == 1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -546,7 +546,7 @@ namespace Nz
|
||||||
auto imageType = Image{
|
auto imageType = Image{
|
||||||
{}, //< qualifier
|
{}, //< qualifier
|
||||||
{}, //< depth
|
{}, //< depth
|
||||||
{}, //< sampled
|
true, //< sampled
|
||||||
SpirvDim::Dim2D, //< dim
|
SpirvDim::Dim2D, //< dim
|
||||||
SpirvImageFormat::Unknown, //< format
|
SpirvImageFormat::Unknown, //< format
|
||||||
BuildType(ShaderAst::PrimitiveType::Float32), //< sampledType
|
BuildType(ShaderAst::PrimitiveType::Float32), //< sampledType
|
||||||
|
|
@ -791,9 +791,9 @@ namespace Nz
|
||||||
|
|
||||||
UInt32 sampled;
|
UInt32 sampled;
|
||||||
if (arg.sampled.has_value())
|
if (arg.sampled.has_value())
|
||||||
sampled = (*arg.sampled) ? 1 : 0;
|
sampled = (*arg.sampled) ? 1 : 2; //< Yes/No
|
||||||
else
|
else
|
||||||
sampled = 2;
|
sampled = 0; //< Dunno
|
||||||
|
|
||||||
constants.AppendVariadic(SpirvOp::OpTypeImage, [&](const auto& appender)
|
constants.AppendVariadic(SpirvOp::OpTypeImage, [&](const auto& appender)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue