Shader: Fix parsing of unary/dot/indices/and/or

This commit is contained in:
Jérôme Leclercq
2022-03-21 23:11:28 +01:00
parent 4fa3de519c
commit a54f70fd24
4 changed files with 173 additions and 93 deletions

View File

@@ -88,6 +88,97 @@ OpStore
OpBranch
OpLabel
OpReturn
OpFunctionEnd)");
}
WHEN("using a more complex branch")
{
std::string_view nzslSource = R"(
[nzsl_version("1.0")]
module;
struct inputStruct
{
value: f32
}
external
{
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
fn main()
{
let value: f32;
if (data.value > 42.0 || data.value <= 50.0 && data.value < 0.0)
value = 1.0;
else
value = 0.0;
}
)";
Nz::ShaderAst::ModulePtr shaderModule = Nz::ShaderLang::Parse(nzslSource);
shaderModule = SanitizeModule(*shaderModule);
ExpectGLSL(*shaderModule, R"(
void main()
{
float value;
if ((data.value > (42.000000)) || ((data.value <= (50.000000)) && (data.value < (0.000000))))
{
value = 1.000000;
}
else
{
value = 0.000000;
}
}
)");
ExpectNZSL(*shaderModule, R"(
[entry(frag)]
fn main()
{
let value: f32;
if ((data.value > (42.000000)) || ((data.value <= (50.000000)) && (data.value < (0.000000))))
{
value = 1.000000;
}
else
{
value = 0.000000;
}
}
)");
ExpectSPIRV(*shaderModule, R"(
OpFunction
OpLabel
OpVariable
OpAccessChain
OpLoad
OpFOrdGreaterThanEqual
OpAccessChain
OpLoad
OpFOrdLessThanEqual
OpAccessChain
OpLoad
OpFOrdLessThan
OpLogicalAnd
OpLogicalOr
OpSelectionMerge
OpBranchConditional
OpLabel
OpStore
OpBranch
OpLabel
OpStore
OpBranch
OpLabel
OpReturn
OpFunctionEnd)");
}