Shader: Fix SpirV generation for Swizzle expressions

+ fix OpSampledImage
This commit is contained in:
Jérôme Leclercq 2021-05-05 12:04:09 +02:00
parent bfb93bc925
commit eb67990b7b
2 changed files with 13 additions and 8 deletions

View File

@ -727,16 +727,17 @@ namespace Nz
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 resultId = m_writer.AllocateResultId();
const ShaderAst::ExpressionType& targetExprType = GetExpressionType(node);
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
m_currentBlock->AppendVariadic(SpirvOp::OpVectorShuffle, [&](const auto& appender)
{
@ -751,6 +752,10 @@ namespace Nz
}
else
{
assert(IsPrimitiveType(targetExprType));
ShaderAst::PrimitiveType targetType = std::get<ShaderAst::PrimitiveType>(targetExprType);
// Extract a single component from the vector
assert(node.componentCount == 1);

View File

@ -546,7 +546,7 @@ namespace Nz
auto imageType = Image{
{}, //< qualifier
{}, //< depth
{}, //< sampled
true, //< sampled
SpirvDim::Dim2D, //< dim
SpirvImageFormat::Unknown, //< format
BuildType(ShaderAst::PrimitiveType::Float32), //< sampledType
@ -791,9 +791,9 @@ namespace Nz
UInt32 sampled;
if (arg.sampled.has_value())
sampled = (*arg.sampled) ? 1 : 0;
sampled = (*arg.sampled) ? 1 : 2; //< Yes/No
else
sampled = 2;
sampled = 0; //< Dunno
constants.AppendVariadic(SpirvOp::OpTypeImage, [&](const auto& appender)
{