Vectors cannot be used as array indexes, however, single-component swizzles (such as vec.x) can be used.
This suggests that single-component swizzles should actually be scalars and not vectors of dimx = 1.
It is worth noting that the use of swizzles on scalars should still be allowed.
-- v4: vkd3d-shader/hlsl: Make single-component swizzles retrieve a scalar. tests: Add tests for assignments to self with swizzles. tests: Test swizzles on scalar values. tests: Test using single-component swizzles as indexes. tests: Combine all the swizzle tests in a single file.
From: Francisco Casas fcasas@codeweavers.com
--- Makefile.am | 9 +-- tests/swizzle-0.shader_test | 15 ----- tests/swizzle-1.shader_test | 11 ---- tests/swizzle-2.shader_test | 11 ---- tests/swizzle-3.shader_test | 14 ----- tests/swizzle-4.shader_test | 13 ----- tests/swizzle-5.shader_test | 10 ---- tests/swizzle-6.shader_test | 12 ---- tests/swizzle-7.shader_test | 11 ---- tests/swizzles.shader_test | 111 ++++++++++++++++++++++++++++++++++++ 10 files changed, 112 insertions(+), 105 deletions(-) delete mode 100644 tests/swizzle-0.shader_test delete mode 100644 tests/swizzle-1.shader_test delete mode 100644 tests/swizzle-2.shader_test delete mode 100644 tests/swizzle-3.shader_test delete mode 100644 tests/swizzle-4.shader_test delete mode 100644 tests/swizzle-5.shader_test delete mode 100644 tests/swizzle-6.shader_test delete mode 100644 tests/swizzle-7.shader_test create mode 100644 tests/swizzles.shader_test
diff --git a/Makefile.am b/Makefile.am index b237b4af..0b4c2a55 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,15 +135,8 @@ vkd3d_shader_tests = \ tests/shader-interstage-interface.shader_test \ tests/sqrt.shader_test \ tests/step.shader_test \ - tests/swizzle-0.shader_test \ - tests/swizzle-1.shader_test \ - tests/swizzle-2.shader_test \ - tests/swizzle-3.shader_test \ - tests/swizzle-4.shader_test \ - tests/swizzle-5.shader_test \ - tests/swizzle-6.shader_test \ - tests/swizzle-7.shader_test \ tests/swizzle-constant-prop.shader_test \ + tests/swizzles.shader_test \ tests/texture-load.shader_test \ tests/texture-load-offset.shader_test \ tests/texture-load-typed.shader_test \ diff --git a/tests/swizzle-0.shader_test b/tests/swizzle-0.shader_test deleted file mode 100644 index 9be141cf..00000000 --- a/tests/swizzle-0.shader_test +++ /dev/null @@ -1,15 +0,0 @@ -[pixel shader] -uniform float4 color; - -float4 main() : sv_target -{ - float4 ret = color; - ret.gb = ret.ra; - ret.ra = float2(0.0101, 0.0404); - return ret; -} - -[test] -uniform 0 float4 0.0303 0.08 0.07 0.0202 -draw quad -probe all rgba (0.0101, 0.0303, 0.0202, 0.0404) diff --git a/tests/swizzle-1.shader_test b/tests/swizzle-1.shader_test deleted file mode 100644 index 40cdc010..00000000 --- a/tests/swizzle-1.shader_test +++ /dev/null @@ -1,11 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret = float4(0.1, 0.2, 0.3, 0.4); - ret.wyz.yx = float2(0.5, 0.6).yx; - return ret; -} - -[test] -draw quad -probe all rgba (0.1, 0.6, 0.3, 0.5) diff --git a/tests/swizzle-2.shader_test b/tests/swizzle-2.shader_test deleted file mode 100644 index b07134c6..00000000 --- a/tests/swizzle-2.shader_test +++ /dev/null @@ -1,11 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret; - ret.zwyx = float4(0.1, 0.2, 0.3, 0.4); - return ret; -} - -[test] -draw quad -probe all rgba (0.4, 0.3, 0.1, 0.2) diff --git a/tests/swizzle-3.shader_test b/tests/swizzle-3.shader_test deleted file mode 100644 index 1ecf5a5c..00000000 --- a/tests/swizzle-3.shader_test +++ /dev/null @@ -1,14 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret; - ret.yw.y = 0.1; - ret.xzy.yz.y.x = 0.2; - ret.yzwx.yzwx.wz.y = 0.3; - ret.zxy.xyz.zxy.xy.y = 0.4; - return ret; -} - -[test] -draw quad -probe all rgba (0.3, 0.2, 0.4, 0.1) diff --git a/tests/swizzle-4.shader_test b/tests/swizzle-4.shader_test deleted file mode 100644 index c09fa515..00000000 --- a/tests/swizzle-4.shader_test +++ /dev/null @@ -1,13 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret; - ret.yxz.yx = float2(0.1, 0.2); - ret.w.x = 0.3; - ret.wzyx.zyx.yx.x = 0.4; - return ret; -} - -[test] -draw quad -probe all rgba (0.1, 0.2, 0.4, 0.3) diff --git a/tests/swizzle-5.shader_test b/tests/swizzle-5.shader_test deleted file mode 100644 index 5a3ee1db..00000000 --- a/tests/swizzle-5.shader_test +++ /dev/null @@ -1,10 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret = float4(0.1, 0.2, 0.3, 0.4).ywxz.zyyz; - return ret; -} - -[test] -draw quad -probe all rgba (0.1, 0.4, 0.4, 0.1) diff --git a/tests/swizzle-6.shader_test b/tests/swizzle-6.shader_test deleted file mode 100644 index 04251c65..00000000 --- a/tests/swizzle-6.shader_test +++ /dev/null @@ -1,12 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret = float4(0.1, 0.2, 0.3, 0.4); - ret.yxwz = ret; - ret = ret.wyzx; - return ret; -} - -[test] -draw quad -probe all rgba (0.3, 0.1, 0.4, 0.2) diff --git a/tests/swizzle-7.shader_test b/tests/swizzle-7.shader_test deleted file mode 100644 index 15a4cd07..00000000 --- a/tests/swizzle-7.shader_test +++ /dev/null @@ -1,11 +0,0 @@ -[pixel shader] -float4 main() : SV_target -{ - float4 ret; - ret.xyzw.xyzw = float4(0.1, 0.2, 0.3, 0.4); - return ret; -} - -[test] -draw quad -probe all rgba (0.1, 0.2, 0.3, 0.4) diff --git a/tests/swizzles.shader_test b/tests/swizzles.shader_test new file mode 100644 index 00000000..caf8377e --- /dev/null +++ b/tests/swizzles.shader_test @@ -0,0 +1,111 @@ +[pixel shader] +uniform float4 color; + +float4 main() : sv_target +{ + float4 ret = color; + ret.gb = ret.ra; + ret.ra = float2(0.0101, 0.0404); + return ret; +} + +[test] +uniform 0 float4 0.0303 0.08 0.07 0.0202 +draw quad +probe all rgba (0.0101, 0.0303, 0.0202, 0.0404) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret = float4(0.1, 0.2, 0.3, 0.4); + ret.wyz.yx = float2(0.5, 0.6).yx; + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.6, 0.3, 0.5) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.zwyx = float4(0.1, 0.2, 0.3, 0.4); + return ret; +} + +[test] +draw quad +probe all rgba (0.4, 0.3, 0.1, 0.2) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.yw.y = 0.1; + ret.xzy.yz.y.x = 0.2; + ret.yzwx.yzwx.wz.y = 0.3; + ret.zxy.xyz.zxy.xy.y = 0.4; + return ret; +} + +[test] +draw quad +probe all rgba (0.3, 0.2, 0.4, 0.1) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.yxz.yx = float2(0.1, 0.2); + ret.w.x = 0.3; + ret.wzyx.zyx.yx.x = 0.4; + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.2, 0.4, 0.3) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret = float4(0.1, 0.2, 0.3, 0.4).ywxz.zyyz; + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.4, 0.4, 0.1) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret = float4(0.1, 0.2, 0.3, 0.4); + ret.yxwz = ret; + ret = ret.wyzx; + return ret; +} + +[test] +draw quad +probe all rgba (0.3, 0.1, 0.4, 0.2) + + +[pixel shader] +float4 main() : SV_target +{ + float4 ret; + ret.xyzw.xyzw = float4(0.1, 0.2, 0.3, 0.4); + return ret; +} + +[test] +draw quad +probe all rgba (0.1, 0.2, 0.3, 0.4)
From: Francisco Casas fcasas@codeweavers.com
Vectors cannot be used as array indexes, however, single-component swizzles (such as vec.x) can be used.
This suggests that single-component swizzles should actually be scalars and not vectors of dimx = 1.
It is worth noting that the use of single-component swizzles on scalars should still be allowed. --- tests/hlsl-vector-indexing.shader_test | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/tests/hlsl-vector-indexing.shader_test b/tests/hlsl-vector-indexing.shader_test index f2d20c44..a7e671b8 100644 --- a/tests/hlsl-vector-indexing.shader_test +++ b/tests/hlsl-vector-indexing.shader_test @@ -25,3 +25,27 @@ float4 main() : SV_TARGET uniform 0 float4 1.0 2.0 3.0 4.0 draw quad probe all rgba (1.0, 2.0, 2.0, 3.0) + + +[pixel shader fail] +float4 main() : SV_TARGET +{ + float4 vec = {0, 1, 2, 3}; + int1 idx = {3}; + + return vec[idx]; +} + + +[pixel shader todo] +float4 main() : SV_TARGET +{ + float4 vec = {0, 1, 2, 3}; + int2 idx = {1, 2}; + + return vec[idx.y]; +} + +[test] +todo draw quad +todo probe all rgba (2.0, 2.0, 2.0, 2.0)
This merge request was approved by Alexandre Julliard.
From: Francisco Casas fcasas@codeweavers.com
--- tests/swizzles.shader_test | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/tests/swizzles.shader_test b/tests/swizzles.shader_test index caf8377e..4bc8bc87 100644 --- a/tests/swizzles.shader_test +++ b/tests/swizzles.shader_test @@ -109,3 +109,29 @@ float4 main() : SV_target [test] draw quad probe all rgba (0.1, 0.2, 0.3, 0.4) + + +[pixel shader] +float4 main() : sv_target +{ + float f = 20; + + return f.x.x; +} + +[test] +draw quad +probe all rgba (20.0, 20.0, 20.0, 20.0) + + +[pixel shader] +float4 main() : sv_target +{ + float f = 3; + + return float4(1, 2, f.x.xx); +} + +[test] +draw quad +probe all rgba (1.0, 2.0, 3.0, 3.0)
From: Francisco Casas fcasas@codeweavers.com
--- tests/swizzles.shader_test | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
diff --git a/tests/swizzles.shader_test b/tests/swizzles.shader_test index 4bc8bc87..c3d3343f 100644 --- a/tests/swizzles.shader_test +++ b/tests/swizzles.shader_test @@ -135,3 +135,36 @@ float4 main() : sv_target [test] draw quad probe all rgba (1.0, 2.0, 3.0, 3.0) + + +[pixel shader] +uniform float4 color; + +float4 main() : sv_target +{ + float4 ret = color; + ret.xyzw = ret.xyzw; // Assignment to self. + return ret; +} + +[test] +uniform 0 float4 1.0 2.0 3.0 4.0 +draw quad +probe all rgba (1.0, 2.0, 3.0, 4.0) + + +[pixel shader] +uniform float4 color; + +float4 main() : sv_target +{ + float4 ret = color; + ret.xyzw = ret.wxyz; // Assignment to self, shifted. + ret.xy = ret.yx; + return ret; +} + +[test] +uniform 0 float4 1.0 2.0 3.0 4.0 +draw quad +probe all rgba (1.0, 4.0, 2.0, 3.0)
From: Francisco Casas fcasas@codeweavers.com
--- libs/vkd3d-shader/hlsl.c | 8 ++++++-- tests/hlsl-storage-qualifiers.shader_test | 6 +++--- tests/hlsl-vector-indexing.shader_test | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c index 01172efd..256e466a 100644 --- a/libs/vkd3d-shader/hlsl.c +++ b/libs/vkd3d-shader/hlsl.c @@ -1164,11 +1164,15 @@ struct hlsl_ir_swizzle *hlsl_new_swizzle(struct hlsl_ctx *ctx, DWORD s, unsigned struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc) { struct hlsl_ir_swizzle *swizzle; + struct hlsl_type *type;
if (!(swizzle = hlsl_alloc(ctx, sizeof(*swizzle)))) return NULL; - init_node(&swizzle->node, HLSL_IR_SWIZZLE, - hlsl_get_vector_type(ctx, val->data_type->base_type, components), loc); + if (components == 1) + type = hlsl_get_scalar_type(ctx, val->data_type->base_type); + else + type = hlsl_get_vector_type(ctx, val->data_type->base_type, components); + init_node(&swizzle->node, HLSL_IR_SWIZZLE, type, loc); hlsl_src_from_node(&swizzle->val, val); swizzle->swizzle = s; return swizzle; diff --git a/tests/hlsl-storage-qualifiers.shader_test b/tests/hlsl-storage-qualifiers.shader_test index 4d17c0d7..59066c5f 100644 --- a/tests/hlsl-storage-qualifiers.shader_test +++ b/tests/hlsl-storage-qualifiers.shader_test @@ -1,4 +1,4 @@ -[pixel shader todo] +[pixel shader] void sub2(in uniform float4 i, out float4 o) { o = i; @@ -17,5 +17,5 @@ void main(in uniform float4 a, uniform float4 b, out float4 o : sv_target) [test] uniform 0 float4 0.1 0.0 0.0 0.0 uniform 4 float4 0.2 0.0 0.0 0.0 -todo draw quad -probe all rgba (0.1, 0.2, 0.3, 0.4) +draw quad +todo probe all rgba (0.1, 0.2, 0.3, 0.4) diff --git a/tests/hlsl-vector-indexing.shader_test b/tests/hlsl-vector-indexing.shader_test index a7e671b8..1542d358 100644 --- a/tests/hlsl-vector-indexing.shader_test +++ b/tests/hlsl-vector-indexing.shader_test @@ -37,7 +37,7 @@ float4 main() : SV_TARGET }
-[pixel shader todo] +[pixel shader] float4 main() : SV_TARGET { float4 vec = {0, 1, 2, 3}; @@ -47,5 +47,5 @@ float4 main() : SV_TARGET }
[test] -todo draw quad -todo probe all rgba (2.0, 2.0, 2.0, 2.0) +draw quad +probe all rgba (2.0, 2.0, 2.0, 2.0)