Shader: Switch type<subtype> to type[subtype]

This commit is contained in:
Jérôme Leclercq
2022-01-26 19:24:46 +01:00
parent 29a01e975c
commit e6951d54a5
27 changed files with 506 additions and 510 deletions

View File

@@ -13,7 +13,7 @@ TEST_CASE("structure member access", "[Shader]")
std::string_view nzslSource = R"(
struct innerStruct
{
field: vec3<f32>
field: vec3[f32]
}
struct outerStruct
@@ -23,7 +23,7 @@ struct outerStruct
external
{
[set(0), binding(0)] ubo: uniform<outerStruct>
[set(0), binding(0)] ubo: uniform[outerStruct]
}
)";

View File

@@ -18,7 +18,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -97,7 +97,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -161,7 +161,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]

View File

@@ -37,7 +37,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -73,7 +73,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -97,7 +97,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -118,18 +118,18 @@ const LightCount = 3;
[layout(std140)]
struct Light
{
color: vec4<f32>
color: vec4[f32]
}
[layout(std140)]
struct LightData
{
lights: [Light; LightCount]
lights: array[Light, LightCount]
}
external
{
[set(0), binding(0)] data: uniform<LightData>
[set(0), binding(0)] data: uniform[LightData]
}
[entry(frag)]
@@ -152,7 +152,7 @@ fn main()
[entry(frag)]
fn main()
{
let color: vec4<f32> = (0.000000).xxxx;
let color: vec4[f32] = (0.000000).xxxx;
let i: i32 = 0;
color += data.lights[i].color;
let i: i32 = 2;
@@ -175,18 +175,18 @@ const LightCount = 3;
[layout(std140)]
struct Light
{
color: vec4<f32>
color: vec4[f32]
}
[layout(std140)]
struct LightData
{
lights: [Light; LightCount]
lights: array[Light, LightCount]
}
external
{
[set(0), binding(0)] data: uniform<LightData>
[set(0), binding(0)] data: uniform[LightData]
}
[entry(frag)]
@@ -209,7 +209,7 @@ fn main()
[entry(frag)]
fn main()
{
let color: vec4<f32> = (0.000000).xxxx;
let color: vec4[f32] = (0.000000).xxxx;
let light: Light = data.lights[0];
color += light.color;
let light: Light = data.lights[1];

View File

@@ -18,7 +18,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -250,12 +250,12 @@ OpFunctionEnd)");
std::string_view nzslSource = R"(
struct inputStruct
{
value: [f32; 10]
value: array[f32, 10]
}
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]

View File

@@ -42,13 +42,13 @@ fn main()
[entry(frag)]
fn main()
{
let output = vec4<f32>(8.0, 2.0, -7.0, 0.0) * (7.0 + 5.0) * 2.0 / 4.0;
let output = vec4[f32](8.0, 2.0, -7.0, 0.0) * (7.0 + 5.0) * 2.0 / 4.0;
}
)", R"(
[entry(frag)]
fn main()
{
let output: vec4<f32> = vec4<f32>(48.000000, 12.000000, -42.000000, 0.000000);
let output: vec4[f32] = vec4[f32](48.000000, 12.000000, -42.000000, 0.000000);
)");
}
@@ -149,7 +149,7 @@ fn main()
[entry(frag)]
fn main()
{
let value = vec3<f32>(3.0, 0.0, 1.0).z;
let value = vec3[f32](3.0, 0.0, 1.0).z;
}
)", R"(
[entry(frag)]
@@ -172,7 +172,7 @@ fn main()
[entry(frag)]
fn main()
{
let value: vec4<f32> = vec4<f32>(42.000000, 42.000000, 42.000000, 42.000000);
let value: vec4[f32] = vec4[f32](42.000000, 42.000000, 42.000000, 42.000000);
}
)");
}
@@ -183,13 +183,13 @@ fn main()
[entry(frag)]
fn main()
{
let value = vec4<f32>(3.0, 0.0, 1.0, 2.0).yzwx;
let value = vec4[f32](3.0, 0.0, 1.0, 2.0).yzwx;
}
)", R"(
[entry(frag)]
fn main()
{
let value: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000);
let value: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
}
)");
}
@@ -200,13 +200,13 @@ fn main()
[entry(frag)]
fn main()
{
let value = vec4<f32>(3.0, 0.0, 1.0, 2.0).zzxx;
let value = vec4[f32](3.0, 0.0, 1.0, 2.0).zzxx;
}
)", R"(
[entry(frag)]
fn main()
{
let value: vec4<f32> = vec4<f32>(1.000000, 1.000000, 3.000000, 3.000000);
let value: vec4[f32] = vec4[f32](1.000000, 1.000000, 3.000000, 3.000000);
}
)");
}
@@ -217,13 +217,13 @@ fn main()
[entry(frag)]
fn main()
{
let value = vec4<f32>(0.0, 1.0, 2.0, 3.0).xyz.yz.y.x.xxxx;
let value = vec4[f32](0.0, 1.0, 2.0, 3.0).xyz.yz.y.x.xxxx;
}
)", R"(
[entry(frag)]
fn main()
{
let value: vec4<f32> = vec4<f32>(2.000000, 2.000000, 2.000000, 2.000000);
let value: vec4[f32] = vec4[f32](2.000000, 2.000000, 2.000000, 2.000000);
}
)");
}
@@ -233,12 +233,12 @@ fn main()
ExpectOptimization(R"(
struct inputStruct
{
value: vec4<f32>
value: vec4[f32]
}
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -250,7 +250,7 @@ fn main()
[entry(frag)]
fn main()
{
let value: vec4<f32> = data.value.zzzz;
let value: vec4[f32] = data.value.zzzz;
}
)");
}

View File

@@ -19,7 +19,7 @@ struct inputStruct
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -84,12 +84,12 @@ fn main()
std::string_view nzslSource = R"(
struct inputStruct
{
value: [f32; 10]
value: array[f32, 10]
}
external
{
[set(0), binding(0)] data: uniform<inputStruct>
[set(0), binding(0)] data: uniform[inputStruct]
}
[entry(frag)]
@@ -131,49 +131,49 @@ fn main()
WHEN("removing matrix casts")
{
std::string_view nzslSource = R"(
fn testMat2ToMat2(input: mat2<f32>) -> mat2<f32>
fn testMat2ToMat2(input: mat2[f32]) -> mat2[f32]
{
return mat2<f32>(input);
return mat2[f32](input);
}
fn testMat2ToMat3(input: mat2<f32>) -> mat3<f32>
fn testMat2ToMat3(input: mat2[f32]) -> mat3[f32]
{
return mat3<f32>(input);
return mat3[f32](input);
}
fn testMat2ToMat4(input: mat2<f32>) -> mat4<f32>
fn testMat2ToMat4(input: mat2[f32]) -> mat4[f32]
{
return mat4<f32>(input);
return mat4[f32](input);
}
fn testMat3ToMat2(input: mat3<f32>) -> mat2<f32>
fn testMat3ToMat2(input: mat3[f32]) -> mat2[f32]
{
return mat2<f32>(input);
return mat2[f32](input);
}
fn testMat3ToMat3(input: mat3<f32>) -> mat3<f32>
fn testMat3ToMat3(input: mat3[f32]) -> mat3[f32]
{
return mat3<f32>(input);
return mat3[f32](input);
}
fn testMat3ToMat4(input: mat3<f32>) -> mat4<f32>
fn testMat3ToMat4(input: mat3[f32]) -> mat4[f32]
{
return mat4<f32>(input);
return mat4[f32](input);
}
fn testMat4ToMat2(input: mat4<f32>) -> mat2<f32>
fn testMat4ToMat2(input: mat4[f32]) -> mat2[f32]
{
return mat2<f32>(input);
return mat2[f32](input);
}
fn testMat4ToMat3(input: mat4<f32>) -> mat3<f32>
fn testMat4ToMat3(input: mat4[f32]) -> mat3[f32]
{
return mat3<f32>(input);
return mat3[f32](input);
}
fn testMat4ToMat4(input: mat4<f32>) -> mat4<f32>
fn testMat4ToMat4(input: mat4[f32]) -> mat4[f32]
{
return mat4<f32>(input);
return mat4[f32](input);
}
)";
@@ -185,71 +185,71 @@ fn testMat4ToMat4(input: mat4<f32>) -> mat4<f32>
REQUIRE_NOTHROW(shader = Nz::ShaderAst::Sanitize(*shader, options));
ExpectNZSL(*shader, R"(
fn testMat2ToMat2(input: mat2<f32>) -> mat2<f32>
fn testMat2ToMat2(input: mat2[f32]) -> mat2[f32]
{
return input;
}
fn testMat2ToMat3(input: mat2<f32>) -> mat3<f32>
fn testMat2ToMat3(input: mat2[f32]) -> mat3[f32]
{
let temp: mat3<f32>;
temp[0] = vec3<f32>(input[0], 0.000000);
temp[1] = vec3<f32>(input[1], 0.000000);
temp[2] = vec3<f32>(input[2], 1.000000);
let temp: mat3[f32];
temp[0] = vec3[f32](input[0], 0.000000);
temp[1] = vec3[f32](input[1], 0.000000);
temp[2] = vec3[f32](input[2], 1.000000);
return temp;
}
fn testMat2ToMat4(input: mat2<f32>) -> mat4<f32>
fn testMat2ToMat4(input: mat2[f32]) -> mat4[f32]
{
let temp: mat4<f32>;
temp[0] = vec4<f32>(input[0], 0.000000, 0.000000);
temp[1] = vec4<f32>(input[1], 0.000000, 0.000000);
temp[2] = vec4<f32>(input[2], 1.000000, 0.000000);
temp[3] = vec4<f32>(input[3], 0.000000, 1.000000);
let temp: mat4[f32];
temp[0] = vec4[f32](input[0], 0.000000, 0.000000);
temp[1] = vec4[f32](input[1], 0.000000, 0.000000);
temp[2] = vec4[f32](input[2], 1.000000, 0.000000);
temp[3] = vec4[f32](input[3], 0.000000, 1.000000);
return temp;
}
fn testMat3ToMat2(input: mat3<f32>) -> mat2<f32>
fn testMat3ToMat2(input: mat3[f32]) -> mat2[f32]
{
let temp: mat2<f32>;
let temp: mat2[f32];
temp[0] = input[0].xy;
temp[1] = input[1].xy;
return temp;
}
fn testMat3ToMat3(input: mat3<f32>) -> mat3<f32>
fn testMat3ToMat3(input: mat3[f32]) -> mat3[f32]
{
return input;
}
fn testMat3ToMat4(input: mat3<f32>) -> mat4<f32>
fn testMat3ToMat4(input: mat3[f32]) -> mat4[f32]
{
let temp: mat4<f32>;
temp[0] = vec4<f32>(input[0], 0.000000);
temp[1] = vec4<f32>(input[1], 0.000000);
temp[2] = vec4<f32>(input[2], 0.000000);
temp[3] = vec4<f32>(input[3], 1.000000);
let temp: mat4[f32];
temp[0] = vec4[f32](input[0], 0.000000);
temp[1] = vec4[f32](input[1], 0.000000);
temp[2] = vec4[f32](input[2], 0.000000);
temp[3] = vec4[f32](input[3], 1.000000);
return temp;
}
fn testMat4ToMat2(input: mat4<f32>) -> mat2<f32>
fn testMat4ToMat2(input: mat4[f32]) -> mat2[f32]
{
let temp: mat2<f32>;
let temp: mat2[f32];
temp[0] = input[0].xy;
temp[1] = input[1].xy;
return temp;
}
fn testMat4ToMat3(input: mat4<f32>) -> mat3<f32>
fn testMat4ToMat3(input: mat4[f32]) -> mat3[f32]
{
let temp: mat3<f32>;
let temp: mat3[f32];
temp[0] = input[0].xyz;
temp[1] = input[1].xyz;
temp[2] = input[2].xyz;
return temp;
}
fn testMat4ToMat4(input: mat4<f32>) -> mat4<f32>
fn testMat4ToMat4(input: mat4[f32]) -> mat4[f32]
{
return input;
}

View File

@@ -16,7 +16,7 @@ TEST_CASE("swizzle", "[Shader]")
[entry(frag)]
fn main()
{
let vec = vec4<f32>(0.0, 1.0, 2.0, 3.0);
let vec = vec4[f32](0.0, 1.0, 2.0, 3.0);
let value = vec.xyz;
}
)";
@@ -35,8 +35,8 @@ void main()
[entry(frag)]
fn main()
{
let vec: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000);
let value: vec3<f32> = vec.xyz;
let vec: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
let value: vec3[f32] = vec.xyz;
}
)");
@@ -60,8 +60,8 @@ OpFunctionEnd)");
[entry(frag)]
fn main()
{
let vec = vec4<f32>(0.0, 0.0, 0.0, 0.0);
vec.yzw = vec3<f32>(1.0, 2.0, 3.0);
let vec = vec4[f32](0.0, 0.0, 0.0, 0.0);
vec.yzw = vec3[f32](1.0, 2.0, 3.0);
}
)";
@@ -79,8 +79,8 @@ void main()
[entry(frag)]
fn main()
{
let vec: vec4<f32> = vec4<f32>(0.000000, 0.000000, 0.000000, 0.000000);
vec.yzw = vec3<f32>(1.000000, 2.000000, 3.000000);
let vec: vec4[f32] = vec4[f32](0.000000, 0.000000, 0.000000, 0.000000);
vec.yzw = vec3[f32](1.000000, 2.000000, 3.000000);
}
)");
@@ -127,7 +127,7 @@ void main()
fn main()
{
let value: f32 = 42.000000;
let vec: vec3<f32> = value.xxx;
let vec: vec3[f32] = value.xxx;
}
)");
@@ -171,8 +171,8 @@ void main()
[entry(frag)]
fn main()
{
let vec: vec3<f32> = (max(2.000000, 1.000000)).xxx;
let vec2: vec3<f32> = (min(2.000000, 1.000000)).xxx;
let vec: vec3[f32] = (max(2.000000, 1.000000)).xxx;
let vec2: vec3[f32] = (min(2.000000, 1.000000)).xxx;
}
)");
@@ -200,7 +200,7 @@ OpFunctionEnd)");
[entry(frag)]
fn main()
{
let vec = vec4<f32>(0.0, 1.0, 2.0, 3.0);
let vec = vec4[f32](0.0, 1.0, 2.0, 3.0);
let value = vec.xyz.yz.y.x.xxxx;
}
)";
@@ -219,8 +219,8 @@ void main()
[entry(frag)]
fn main()
{
let vec: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000);
let value: vec4<f32> = vec.xyz.yz.y.x.xxxx;
let vec: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
let value: vec4[f32] = vec.xyz.yz.y.x.xxxx;
}
)");
@@ -247,9 +247,9 @@ OpFunctionEnd)");
[entry(frag)]
fn main()
{
let vec = vec4<f32>(0.0, 1.0, 2.0, 3.0);
let vec = vec4[f32](0.0, 1.0, 2.0, 3.0);
vec.wyxz.bra.ts.x = 0.0;
vec.zyxw.ar.xy.yx = vec2<f32>(1.0, 0.0);
vec.zyxw.ar.xy.yx = vec2[f32](1.0, 0.0);
}
)";
@@ -268,9 +268,9 @@ void main()
[entry(frag)]
fn main()
{
let vec: vec4<f32> = vec4<f32>(0.000000, 1.000000, 2.000000, 3.000000);
let vec: vec4[f32] = vec4[f32](0.000000, 1.000000, 2.000000, 3.000000);
vec.wyxz.zxw.yx.x = 0.000000;
vec.zyxw.wx.xy.yx = vec2<f32>(1.000000, 0.000000);
vec.zyxw.wx.xy.yx = vec2[f32](1.000000, 0.000000);
}
)");