Skip to content

Commit

Permalink
[naga wgsl-in] Add additional test cases regarding abstract-typed con…
Browse files Browse the repository at this point in the history
…stants
  • Loading branch information
jamienicol committed Feb 5, 2025
1 parent d185e05 commit 8563e3a
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 20 deletions.
28 changes: 28 additions & 0 deletions naga/tests/in/abstract-types-function-calls.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,53 @@ fn func_au(a: array<u32, 2>) {}

fn func_f_i(a: f32, b: i32) {}

const const_af = 0;
const const_ai = 0;
const const_vec_af = vec2(0.0);
const const_vec_ai = vec2(0);
const const_mat_af = mat2x2(vec2(0.0), vec2(0.0));
const const_arr_af = array(0.0, 0.0);
const const_arr_ai = array(0, 0);

fn main() {
func_f(0.0);
func_f(0);
func_i(0);
func_u(0);

func_f(const_af);
func_f(const_ai);
func_i(const_ai);
func_u(const_ai);

func_vf(vec2(0.0));
func_vf(vec2(0));
func_vi(vec2(0));
func_vu(vec2(0));

func_vf(const_vec_af);
func_vf(const_vec_ai);
func_vi(const_vec_ai);
func_vu(const_vec_ai);

func_mf(mat2x2(vec2(0.0), vec2(0.0)));
func_mf(mat2x2(vec2(0), vec2(0)));

func_mf(const_mat_af);

func_af(array(0.0, 0.0));
func_af(array(0, 0));
func_ai(array(0, 0));
func_au(array(0, 0));

func_af(const_arr_af);
func_af(const_arr_ai);
func_ai(const_arr_ai);
func_au(const_arr_ai);

func_f_i(0.0, 0);
func_f_i(0, 0);

func_f_i(const_af, const_ai);
func_f_i(const_ai, const_ai);
}
10 changes: 10 additions & 0 deletions naga/tests/in/abstract-types-return.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ fn return_vec2f32_ai() -> vec2<f32> {
fn return_arrf32_ai() -> array<f32, 4> {
return array(1, 1, 1, 1);
}

const one = 1;
fn return_const_f32_const_ai() -> f32 {
return one;
}

fn return_vec2f32_const_ai() -> vec2<f32> {
const vec_one = vec2(1);
return vec_one;
}
7 changes: 6 additions & 1 deletion naga/tests/in/const_assert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ const y = 2;
const_assert x < y; // valid at module-scope.
const_assert(y != 0); // parentheses are optional.

// Ensure abstract-typed consts can be compared to different concrete types
const_assert x == 1i;
const_assert x > 0u;
const_assert x < 2.0f;

fn foo() {
const z = x + y - 2;
const_assert z > 0; // valid in functions.
const_assert(z > 0);
}
}
8 changes: 8 additions & 0 deletions naga/tests/out/glsl/abstract-types-return.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ float[4] return_arrf32_ai() {
return float[4](1.0, 1.0, 1.0, 1.0);
}

float return_const_f32_const_ai() {
return 1.0;
}

vec2 return_vec2f32_const_ai() {
return vec2(1.0);
}

void main() {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions naga/tests/out/hlsl/abstract-types-return.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ ret_return_arrf32_ai return_arrf32_ai()
return Constructarray4_float_(1.0, 1.0, 1.0, 1.0);
}

float return_const_f32_const_ai()
{
return 1.0;
}

float2 return_vec2f32_const_ai()
{
return (1.0).xx;
}

[numthreads(1, 1, 1)]
void main()
{
Expand Down
15 changes: 15 additions & 0 deletions naga/tests/out/msl/abstract-types-function-calls.msl
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,31 @@ void main_(
func_f(0.0);
func_i(0);
func_u(0u);
func_f(0.0);
func_f(0.0);
func_i(0);
func_u(0u);
func_vf(metal::float2(0.0));
func_vf(metal::float2(0.0));
func_vi(metal::int2(0));
func_vu(metal::uint2(0u));
func_vf(metal::float2(0.0));
func_vf(metal::float2(0.0));
func_vi(metal::int2(0));
func_vu(metal::uint2(0u));
func_mf(metal::float2x2(metal::float2(0.0), metal::float2(0.0)));
func_mf(metal::float2x2(metal::float2(0.0), metal::float2(0.0)));
func_mf(metal::float2x2(metal::float2(0.0), metal::float2(0.0)));
func_af(type_7 {0.0, 0.0});
func_af(type_7 {0.0, 0.0});
func_ai(type_8 {0, 0});
func_au(type_9 {0u, 0u});
func_af(type_7 {0.0, 0.0});
func_af(type_7 {0.0, 0.0});
func_ai(type_8 {0, 0});
func_au(type_9 {0u, 0u});
func_f_i(0.0, 0);
func_f_i(0.0, 0);
func_f_i(0.0, 0);
func_f_i(0.0, 0);
return;
Expand Down
10 changes: 10 additions & 0 deletions naga/tests/out/msl/abstract-types-return.msl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ type_4 return_arrf32_ai(
return type_4 {1.0, 1.0, 1.0, 1.0};
}

float return_const_f32_const_ai(
) {
return 1.0;
}

metal::float2 return_vec2f32_const_ai(
) {
return metal::float2(1.0);
}

kernel void main_(
) {
return;
Expand Down
41 changes: 28 additions & 13 deletions naga/tests/out/spv/abstract-types-function-calls.spvasm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 100
; Bound: 115
OpCapability Shader
OpCapability Linkage
%1 = OpExtInstImport "GLSL.std.450"
Expand Down Expand Up @@ -129,17 +129,32 @@ OpBranch %83
%85 = OpFunctionCall %2 %16 %73
%86 = OpFunctionCall %2 %21 %74
%87 = OpFunctionCall %2 %26 %75
%88 = OpFunctionCall %2 %31 %76
%89 = OpFunctionCall %2 %31 %76
%90 = OpFunctionCall %2 %36 %77
%91 = OpFunctionCall %2 %41 %78
%92 = OpFunctionCall %2 %46 %79
%93 = OpFunctionCall %2 %46 %79
%94 = OpFunctionCall %2 %51 %80
%95 = OpFunctionCall %2 %51 %80
%96 = OpFunctionCall %2 %56 %81
%97 = OpFunctionCall %2 %61 %82
%98 = OpFunctionCall %2 %67 %73 %74
%99 = OpFunctionCall %2 %67 %73 %74
%88 = OpFunctionCall %2 %16 %73
%89 = OpFunctionCall %2 %16 %73
%90 = OpFunctionCall %2 %21 %74
%91 = OpFunctionCall %2 %26 %75
%92 = OpFunctionCall %2 %31 %76
%93 = OpFunctionCall %2 %31 %76
%94 = OpFunctionCall %2 %36 %77
%95 = OpFunctionCall %2 %41 %78
%96 = OpFunctionCall %2 %31 %76
%97 = OpFunctionCall %2 %31 %76
%98 = OpFunctionCall %2 %36 %77
%99 = OpFunctionCall %2 %41 %78
%100 = OpFunctionCall %2 %46 %79
%101 = OpFunctionCall %2 %46 %79
%102 = OpFunctionCall %2 %46 %79
%103 = OpFunctionCall %2 %51 %80
%104 = OpFunctionCall %2 %51 %80
%105 = OpFunctionCall %2 %56 %81
%106 = OpFunctionCall %2 %61 %82
%107 = OpFunctionCall %2 %51 %80
%108 = OpFunctionCall %2 %51 %80
%109 = OpFunctionCall %2 %56 %81
%110 = OpFunctionCall %2 %61 %82
%111 = OpFunctionCall %2 %67 %73 %74
%112 = OpFunctionCall %2 %67 %73 %74
%113 = OpFunctionCall %2 %67 %73 %74
%114 = OpFunctionCall %2 %67 %73 %74
OpReturn
OpFunctionEnd
24 changes: 18 additions & 6 deletions naga/tests/out/spv/abstract-types-return.spvasm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 41
; Bound: 47
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %38 "main"
OpExecutionMode %38 LocalSize 1 1 1
OpEntryPoint GLCompute %44 "main"
OpExecutionMode %44 LocalSize 1 1 1
OpDecorate %7 ArrayStride 4
%2 = OpTypeVoid
%3 = OpTypeInt 32 1
Expand All @@ -25,7 +25,7 @@ OpDecorate %7 ArrayStride 4
%30 = OpConstantComposite %6 %22 %22
%34 = OpTypeFunction %7
%35 = OpConstantComposite %7 %22 %22 %22 %22
%39 = OpTypeFunction %2
%45 = OpTypeFunction %2
%10 = OpFunction %3 None %11
%9 = OpLabel
OpBranch %13
Expand Down Expand Up @@ -62,9 +62,21 @@ OpBranch %36
%36 = OpLabel
OpReturnValue %35
OpFunctionEnd
%38 = OpFunction %2 None %39
%38 = OpFunction %5 None %21
%37 = OpLabel
OpBranch %40
OpBranch %39
%39 = OpLabel
OpReturnValue %22
OpFunctionEnd
%41 = OpFunction %6 None %29
%40 = OpLabel
OpBranch %42
%42 = OpLabel
OpReturnValue %30
OpFunctionEnd
%44 = OpFunction %2 None %45
%43 = OpLabel
OpBranch %46
%46 = OpLabel
OpReturn
OpFunctionEnd
15 changes: 15 additions & 0 deletions naga/tests/out/wgsl/abstract-types-function-calls.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,31 @@ fn main() {
func_f(0f);
func_i(0i);
func_u(0u);
func_f(0f);
func_f(0f);
func_i(0i);
func_u(0u);
func_vf(vec2(0f));
func_vf(vec2(0f));
func_vi(vec2(0i));
func_vu(vec2(0u));
func_vf(vec2(0f));
func_vf(vec2(0f));
func_vi(vec2(0i));
func_vu(vec2(0u));
func_mf(mat2x2<f32>(vec2(0f), vec2(0f)));
func_mf(mat2x2<f32>(vec2(0f), vec2(0f)));
func_mf(mat2x2<f32>(vec2(0f), vec2(0f)));
func_af(array<f32, 2>(0f, 0f));
func_af(array<f32, 2>(0f, 0f));
func_ai(array<i32, 2>(0i, 0i));
func_au(array<u32, 2>(0u, 0u));
func_af(array<f32, 2>(0f, 0f));
func_af(array<f32, 2>(0f, 0f));
func_ai(array<i32, 2>(0i, 0i));
func_au(array<u32, 2>(0u, 0u));
func_f_i(0f, 0i);
func_f_i(0f, 0i);
func_f_i(0f, 0i);
func_f_i(0f, 0i);
return;
Expand Down
8 changes: 8 additions & 0 deletions naga/tests/out/wgsl/abstract-types-return.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ fn return_arrf32_ai() -> array<f32, 4> {
return array<f32, 4>(1f, 1f, 1f, 1f);
}

fn return_const_f32_const_ai() -> f32 {
return 1f;
}

fn return_vec2f32_const_ai() -> vec2<f32> {
return vec2(1f);
}

@compute @workgroup_size(1, 1, 1)
fn main() {
return;
Expand Down

0 comments on commit 8563e3a

Please sign in to comment.