Skip to content

Commit

Permalink
[naga] Add tests for automatic conversions in assignments.
Browse files Browse the repository at this point in the history
Add tests for automatic conversions of the right-hand sides of
assignment expressions.
  • Loading branch information
jimblandy committed Dec 25, 2024
1 parent 32d0299 commit 4c1b402
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 1 deletion.
73 changes: 73 additions & 0 deletions naga/tests/in/abstract-types-var.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,53 @@ fn all_constant_arguments() {
var iafpaiaf = array(1, 2.0);
var iafpafai = array(1.0, 2);
var iafpafaf = array(1.0, 2.0);

// Assignments to all of the above.
xvipaiai = vec2(42, 43);
xvupaiai = vec2(44, 45);
xvfpaiai = vec2(46, 47);

xvupuai = vec2(42u, 43);
xvupaiu = vec2(42, 43u);

xvuuai = vec2<u32>(42u, 43);
xvuaiu = vec2<u32>(42, 43u);

xmfpaiaiaiai = mat2x2(1, 2, 3, 4);
xmfpafaiaiai = mat2x2(1.0, 2, 3, 4);
xmfpaiafaiai = mat2x2(1, 2.0, 3, 4);
xmfpaiaiafai = mat2x2(1, 2, 3.0, 4);
xmfpaiaiaiaf = mat2x2(1, 2, 3, 4.0);

xmfp_faiaiai = mat2x2(1.0f, 2, 3, 4);
xmfpai_faiai = mat2x2(1, 2.0f, 3, 4);
xmfpaiai_fai = mat2x2(1, 2, 3.0f, 4);
xmfpaiaiai_f = mat2x2(1, 2, 3, 4.0f);

xvispai = vec2(1);
xvfspaf = vec2(1.0);
xvis_ai = vec2<i32>(1);
xvus_ai = vec2<u32>(1);
xvfs_ai = vec2<f32>(1);
xvfs_af = vec2<f32>(1.0);

xafafaf = array<f32, 2>(1.0, 2.0);
xaf_faf = array<f32, 2>(1.0f, 2.0);
xafaf_f = array<f32, 2>(1.0, 2.0f);
xafaiai = array<f32, 2>(1, 2);
xai_iai = array<i32, 2>(1i, 2);
xaiai_i = array<i32, 2>(1, 2i);

xaipaiai = array(1, 2);
xafpaiai = array(1, 2);
xafpaiaf = array(1, 2.0);
xafpafai = array(1.0, 2);
xafpafaf = array(1.0, 2.0);

iaipaiai = array(1, 2);
iafpaiaf = array(1, 2.0);
iafpafai = array(1.0, 2);
iafpafaf = array(1.0, 2.0);
}

fn mixed_constant_and_runtime_arguments() {
Expand Down Expand Up @@ -135,4 +182,30 @@ fn mixed_constant_and_runtime_arguments() {
var xafpai_f: array<f32, 2> = array(1, f);
var xaip_iai: array<i32, 2> = array(i, 2);
var xaipai_i: array<i32, 2> = array(1, i);

// Assignments to all of the above.
xvupuai = vec2(u, 43);
xvupaiu = vec2(42, u);

xvuuai = vec2<u32>(u, 43);
xvuaiu = vec2<u32>(42, u);

xmfp_faiaiai = mat2x2(f, 2, 3, 4);
xmfpai_faiai = mat2x2(1, f, 3, 4);
xmfpaiai_fai = mat2x2(1, 2, f, 4);
xmfpaiaiai_f = mat2x2(1, 2, 3, f);

xaf_faf = array<f32, 2>(f, 2.0);
xafaf_f = array<f32, 2>(1.0, f);
xaf_fai = array<f32, 2>(f, 2);
xafai_f = array<f32, 2>(1, f);
xai_iai = array<i32, 2>(i, 2);
xaiai_i = array<i32, 2>(1, i);

xafp_faf = array(f, 2.0);
xafpaf_f = array(1.0, f);
xafp_fai = array(f, 2);
xafpai_f = array(1, f);
xaip_iai = array(i, 2);
xaipai_i = array(1, i);
}
78 changes: 78 additions & 0 deletions naga/tests/out/msl/abstract-types-var.msl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,44 @@ void all_constant_arguments(
type_7 iafpaiaf = type_7 {1.0, 2.0};
type_7 iafpafai = type_7 {1.0, 2.0};
type_7 iafpafaf = type_7 {1.0, 2.0};
xvipaiai = metal::int2(42, 43);
xvupaiai = metal::uint2(44u, 45u);
xvfpaiai = metal::float2(46.0, 47.0);
xvupuai = metal::uint2(42u, 43u);
xvupaiu = metal::uint2(42u, 43u);
xvuuai = metal::uint2(42u, 43u);
xvuaiu = metal::uint2(42u, 43u);
xmfpaiaiaiai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpafaiaiai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpaiafaiai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpaiaiafai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpaiaiaiaf = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfp_faiaiai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpai_faiai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpaiai_fai = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xmfpaiaiai_f = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, 4.0));
xvispai = metal::int2(1);
xvfspaf = metal::float2(1.0);
xvis_ai = metal::int2(1);
xvus_ai = metal::uint2(1u);
xvfs_ai = metal::float2(1.0);
xvfs_af = metal::float2(1.0);
xafafaf = type_7 {1.0, 2.0};
xaf_faf = type_7 {1.0, 2.0};
xafaf_f = type_7 {1.0, 2.0};
xafaiai = type_7 {1.0, 2.0};
xai_iai = type_8 {1, 2};
xaiai_i = type_8 {1, 2};
xaipaiai = type_8 {1, 2};
xafpaiai = type_7 {1.0, 2.0};
xafpaiaf = type_7 {1.0, 2.0};
xafpafai = type_7 {1.0, 2.0};
xafpafaf = type_7 {1.0, 2.0};
iaipaiai = type_8 {1, 2};
iafpaiaf = type_7 {1.0, 2.0};
iafpafai = type_7 {1.0, 2.0};
iafpafaf = type_7 {1.0, 2.0};
return;
}

void mixed_constant_and_runtime_arguments(
Expand Down Expand Up @@ -117,5 +155,45 @@ void mixed_constant_and_runtime_arguments(
xaip_iai = type_8 {_e91, 2};
int _e95 = i;
xaipai_i = type_8 {1, _e95};
uint _e99 = u;
xvupuai_1 = metal::uint2(_e99, 43u);
uint _e102 = u;
xvupaiu_1 = metal::uint2(42u, _e102);
uint _e105 = u;
xvuuai_1 = metal::uint2(_e105, 43u);
uint _e108 = u;
xvuaiu_1 = metal::uint2(42u, _e108);
float _e111 = f;
xmfp_faiaiai_1 = metal::float2x2(metal::float2(_e111, 2.0), metal::float2(3.0, 4.0));
float _e118 = f;
xmfpai_faiai_1 = metal::float2x2(metal::float2(1.0, _e118), metal::float2(3.0, 4.0));
float _e125 = f;
xmfpaiai_fai_1 = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(_e125, 4.0));
float _e132 = f;
xmfpaiaiai_f_1 = metal::float2x2(metal::float2(1.0, 2.0), metal::float2(3.0, _e132));
float _e139 = f;
xaf_faf_1 = type_7 {_e139, 2.0};
float _e142 = f;
xafaf_f_1 = type_7 {1.0, _e142};
float _e145 = f;
xaf_fai = type_7 {_e145, 2.0};
float _e148 = f;
xafai_f = type_7 {1.0, _e148};
int _e151 = i;
xai_iai_1 = type_8 {_e151, 2};
int _e154 = i;
xaiai_i_1 = type_8 {1, _e154};
float _e157 = f;
xafp_faf = type_7 {_e157, 2.0};
float _e160 = f;
xafpaf_f = type_7 {1.0, _e160};
float _e163 = f;
xafp_fai = type_7 {_e163, 2.0};
float _e166 = f;
xafpai_f = type_7 {1.0, _e166};
int _e169 = i;
xaip_iai = type_8 {_e169, 2};
int _e172 = i;
xaipai_i = type_8 {1, _e172};
return;
}
103 changes: 102 additions & 1 deletion naga/tests/out/spv/abstract-types-var.spvasm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 225
; Bound: 269
OpCapability Shader
OpCapability Linkage
%1 = OpExtInstImport "GLSL.std.450"
Expand Down Expand Up @@ -162,6 +162,43 @@ OpDecorate %12 ArrayStride 4
%89 = OpVariable %90 Function %21
OpBranch %128
%128 = OpLabel
OpStore %85 %15
OpStore %87 %18
OpStore %89 %21
OpStore %91 %24
OpStore %92 %24
OpStore %93 %24
OpStore %94 %24
OpStore %95 %31
OpStore %97 %31
OpStore %98 %31
OpStore %99 %31
OpStore %100 %31
OpStore %101 %31
OpStore %102 %31
OpStore %103 %31
OpStore %104 %31
OpStore %105 %33
OpStore %106 %34
OpStore %107 %33
OpStore %108 %36
OpStore %109 %34
OpStore %110 %34
OpStore %111 %37
OpStore %113 %37
OpStore %114 %37
OpStore %115 %37
OpStore %116 %39
OpStore %118 %39
OpStore %119 %39
OpStore %120 %37
OpStore %121 %37
OpStore %122 %37
OpStore %123 %37
OpStore %124 %39
OpStore %125 %37
OpStore %126 %37
OpStore %127 %37
OpReturn
OpFunctionEnd
%130 = OpFunction %2 None %84
Expand Down Expand Up @@ -255,5 +292,69 @@ OpStore %176 %222
%223 = OpLoad %3 %134
%224 = OpCompositeConstruct %12 %32 %223
OpStore %178 %224
%225 = OpLoad %5 %131
%226 = OpCompositeConstruct %6 %225 %23
OpStore %140 %226
%227 = OpLoad %5 %131
%228 = OpCompositeConstruct %6 %22 %227
OpStore %142 %228
%229 = OpLoad %5 %131
%230 = OpCompositeConstruct %6 %229 %23
OpStore %144 %230
%231 = OpLoad %5 %131
%232 = OpCompositeConstruct %6 %22 %231
OpStore %146 %232
%233 = OpLoad %7 %137
%234 = OpCompositeConstruct %8 %233 %26
%235 = OpCompositeConstruct %9 %234 %30
OpStore %148 %235
%236 = OpLoad %7 %137
%237 = OpCompositeConstruct %8 %25 %236
%238 = OpCompositeConstruct %9 %237 %30
OpStore %150 %238
%239 = OpLoad %7 %137
%240 = OpCompositeConstruct %8 %239 %29
%241 = OpCompositeConstruct %9 %27 %240
OpStore %152 %241
%242 = OpLoad %7 %137
%243 = OpCompositeConstruct %8 %28 %242
%244 = OpCompositeConstruct %9 %27 %243
OpStore %154 %244
%245 = OpLoad %7 %137
%246 = OpCompositeConstruct %10 %245 %26
OpStore %156 %246
%247 = OpLoad %7 %137
%248 = OpCompositeConstruct %10 %25 %247
OpStore %158 %248
%249 = OpLoad %7 %137
%250 = OpCompositeConstruct %10 %249 %26
OpStore %160 %250
%251 = OpLoad %7 %137
%252 = OpCompositeConstruct %10 %25 %251
OpStore %162 %252
%253 = OpLoad %3 %134
%254 = OpCompositeConstruct %12 %253 %38
OpStore %164 %254
%255 = OpLoad %3 %134
%256 = OpCompositeConstruct %12 %32 %255
OpStore %166 %256
%257 = OpLoad %7 %137
%258 = OpCompositeConstruct %10 %257 %26
OpStore %168 %258
%259 = OpLoad %7 %137
%260 = OpCompositeConstruct %10 %25 %259
OpStore %170 %260
%261 = OpLoad %7 %137
%262 = OpCompositeConstruct %10 %261 %26
OpStore %172 %262
%263 = OpLoad %7 %137
%264 = OpCompositeConstruct %10 %25 %263
OpStore %174 %264
%265 = OpLoad %3 %134
%266 = OpCompositeConstruct %12 %265 %38
OpStore %176 %266
%267 = OpLoad %3 %134
%268 = OpCompositeConstruct %12 %32 %267
OpStore %178 %268
OpReturn
OpFunctionEnd
78 changes: 78 additions & 0 deletions naga/tests/out/wgsl/abstract-types-var.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,44 @@ fn all_constant_arguments() {
var iafpafai: array<f32, 2> = array<f32, 2>(1f, 2f);
var iafpafaf: array<f32, 2> = array<f32, 2>(1f, 2f);

xvipaiai = vec2<i32>(42i, 43i);
xvupaiai = vec2<u32>(44u, 45u);
xvfpaiai = vec2<f32>(46f, 47f);
xvupuai = vec2<u32>(42u, 43u);
xvupaiu = vec2<u32>(42u, 43u);
xvuuai = vec2<u32>(42u, 43u);
xvuaiu = vec2<u32>(42u, 43u);
xmfpaiaiaiai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpafaiaiai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpaiafaiai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpaiaiafai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpaiaiaiaf = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfp_faiaiai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpai_faiai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpaiai_fai = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xmfpaiaiai_f = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, 4f));
xvispai = vec2(1i);
xvfspaf = vec2(1f);
xvis_ai = vec2(1i);
xvus_ai = vec2(1u);
xvfs_ai = vec2(1f);
xvfs_af = vec2(1f);
xafafaf = array<f32, 2>(1f, 2f);
xaf_faf = array<f32, 2>(1f, 2f);
xafaf_f = array<f32, 2>(1f, 2f);
xafaiai = array<f32, 2>(1f, 2f);
xai_iai = array<i32, 2>(1i, 2i);
xaiai_i = array<i32, 2>(1i, 2i);
xaipaiai = array<i32, 2>(1i, 2i);
xafpaiai = array<f32, 2>(1f, 2f);
xafpaiaf = array<f32, 2>(1f, 2f);
xafpafai = array<f32, 2>(1f, 2f);
xafpafaf = array<f32, 2>(1f, 2f);
iaipaiai = array<i32, 2>(1i, 2i);
iafpaiaf = array<f32, 2>(1f, 2f);
iafpafai = array<f32, 2>(1f, 2f);
iafpafaf = array<f32, 2>(1f, 2f);
return;
}

fn mixed_constant_and_runtime_arguments() {
Expand Down Expand Up @@ -141,6 +179,46 @@ fn mixed_constant_and_runtime_arguments() {
xaip_iai = array<i32, 2>(_e91, 2i);
let _e95 = i;
xaipai_i = array<i32, 2>(1i, _e95);
let _e99 = u;
xvupuai_1 = vec2<u32>(_e99, 43u);
let _e102 = u;
xvupaiu_1 = vec2<u32>(42u, _e102);
let _e105 = u;
xvuuai_1 = vec2<u32>(_e105, 43u);
let _e108 = u;
xvuaiu_1 = vec2<u32>(42u, _e108);
let _e111 = f;
xmfp_faiaiai_1 = mat2x2<f32>(vec2<f32>(_e111, 2f), vec2<f32>(3f, 4f));
let _e118 = f;
xmfpai_faiai_1 = mat2x2<f32>(vec2<f32>(1f, _e118), vec2<f32>(3f, 4f));
let _e125 = f;
xmfpaiai_fai_1 = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(_e125, 4f));
let _e132 = f;
xmfpaiaiai_f_1 = mat2x2<f32>(vec2<f32>(1f, 2f), vec2<f32>(3f, _e132));
let _e139 = f;
xaf_faf_1 = array<f32, 2>(_e139, 2f);
let _e142 = f;
xafaf_f_1 = array<f32, 2>(1f, _e142);
let _e145 = f;
xaf_fai = array<f32, 2>(_e145, 2f);
let _e148 = f;
xafai_f = array<f32, 2>(1f, _e148);
let _e151 = i;
xai_iai_1 = array<i32, 2>(_e151, 2i);
let _e154 = i;
xaiai_i_1 = array<i32, 2>(1i, _e154);
let _e157 = f;
xafp_faf = array<f32, 2>(_e157, 2f);
let _e160 = f;
xafpaf_f = array<f32, 2>(1f, _e160);
let _e163 = f;
xafp_fai = array<f32, 2>(_e163, 2f);
let _e166 = f;
xafpai_f = array<f32, 2>(1f, _e166);
let _e169 = i;
xaip_iai = array<i32, 2>(_e169, 2i);
let _e172 = i;
xaipai_i = array<i32, 2>(1i, _e172);
return;
}

0 comments on commit 4c1b402

Please sign in to comment.