Skip to content

Commit

Permalink
Add test for using local const in types
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
  • Loading branch information
sagudev committed Feb 18, 2025
1 parent a2713b9 commit 6e1d427
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 130 deletions.
6 changes: 6 additions & 0 deletions naga/tests/in/const-exprs.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn main() {
splat_of_constant();
compose_of_constant();
compose_of_splat();
test_local_const();
}

// Swizzle the value of nested Compose expressions.
Expand Down Expand Up @@ -94,3 +95,8 @@ fn compose_vector_zero_val_binop() {
var b = vec3(vec2i(), 0) + vec3(0, 1, 2);
var c = vec3(vec2i(), 2) + vec3(1, vec2i());
}

fn test_local_const() {
const local_const = 2;
var arr: array<f32, local_const>;
}
6 changes: 6 additions & 0 deletions naga/tests/out/glsl/const-exprs.main.Compute.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ void compose_of_splat() {
return;
}

void test_local_const() {
float arr[2] = float[2](0.0, 0.0);
return;
}

uint map_texture_kind(int texture_kind) {
switch(texture_kind) {
case 0: {
Expand Down Expand Up @@ -101,6 +106,7 @@ void main() {
splat_of_constant();
compose_of_constant();
compose_of_splat();
test_local_const();
return;
}

8 changes: 8 additions & 0 deletions naga/tests/out/hlsl/const-exprs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ void compose_of_splat()
return;
}

void test_local_const()
{
float arr[2] = (float[2])0;

return;
}

uint map_texture_kind(int texture_kind)
{
switch(texture_kind) {
Expand Down Expand Up @@ -112,5 +119,6 @@ void main()
splat_of_constant();
compose_of_constant();
compose_of_splat();
test_local_const();
return;
}
10 changes: 10 additions & 0 deletions naga/tests/out/msl/const-exprs.msl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

using metal::uint;

struct type_5 {
float inner[2];
};
constant uint TWO = 2u;
constant int THREE = 3;
constant int FOUR = 4;
Expand Down Expand Up @@ -74,6 +77,12 @@ void compose_of_splat(
return;
}

void test_local_const(
) {
type_5 arr = {};
return;
}

uint map_texture_kind(
int texture_kind
) {
Expand Down Expand Up @@ -110,5 +119,6 @@ kernel void main_(
splat_of_constant();
compose_of_constant();
compose_of_splat();
test_local_const();
return;
}
272 changes: 142 additions & 130 deletions naga/tests/out/spv/const-exprs.spvasm
Original file line number Diff line number Diff line change
@@ -1,166 +1,178 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 120
; Bound: 128
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %111 "main"
OpExecutionMode %111 LocalSize 2 3 1
OpEntryPoint GLCompute %118 "main"
OpExecutionMode %118 LocalSize 2 3 1
OpDecorate %8 ArrayStride 4
%2 = OpTypeVoid
%3 = OpTypeInt 32 0
%4 = OpTypeInt 32 1
%5 = OpTypeVector %4 4
%6 = OpTypeFloat 32
%7 = OpTypeVector %6 4
%8 = OpTypeVector %6 2
%10 = OpTypeBool
%9 = OpTypeVector %10 2
%11 = OpTypeVector %4 3
%12 = OpConstant %3 2
%13 = OpConstant %4 3
%14 = OpConstant %4 4
%15 = OpConstant %4 8
%16 = OpConstant %6 3.141
%17 = OpConstant %6 6.282
%18 = OpConstant %6 0.44444445
%19 = OpConstant %6 0.0
%20 = OpConstantComposite %7 %18 %19 %19 %19
%21 = OpConstant %4 0
%22 = OpConstant %4 1
%23 = OpConstant %4 2
%24 = OpConstant %6 4.0
%25 = OpConstant %6 5.0
%26 = OpConstantComposite %8 %24 %25
%27 = OpConstantTrue %10
%28 = OpConstantFalse %10
%29 = OpConstantComposite %9 %27 %28
%32 = OpTypeFunction %2
%33 = OpConstantComposite %5 %14 %13 %23 %22
%35 = OpTypePointer Function %5
%40 = OpTypePointer Function %4
%44 = OpConstant %4 6
%49 = OpConstant %4 30
%50 = OpConstant %4 70
%53 = OpConstantNull %4
%55 = OpConstantNull %4
%58 = OpConstantNull %5
%69 = OpConstant %4 -4
%70 = OpConstantComposite %5 %69 %69 %69 %69
%79 = OpConstant %6 1.0
%80 = OpConstant %6 2.0
%81 = OpConstantComposite %7 %80 %79 %79 %79
%83 = OpTypePointer Function %7
%88 = OpTypeFunction %3 %4
%89 = OpConstant %3 10
%90 = OpConstant %3 20
%91 = OpConstant %3 30
%92 = OpConstant %3 0
%99 = OpConstantNull %3
%102 = OpConstantComposite %11 %22 %22 %22
%103 = OpConstantComposite %11 %21 %22 %23
%104 = OpConstantComposite %11 %22 %21 %23
%106 = OpTypePointer Function %11
%31 = OpFunction %2 None %32
%30 = OpLabel
%34 = OpVariable %35 Function %33
OpBranch %36
%36 = OpLabel
OpReturn
OpFunctionEnd
%38 = OpFunction %2 None %32
%9 = OpConstant %3 2
%8 = OpTypeArray %6 %9
%10 = OpTypeVector %6 2
%12 = OpTypeBool
%11 = OpTypeVector %12 2
%13 = OpTypeVector %4 3
%14 = OpConstant %4 3
%15 = OpConstant %4 4
%16 = OpConstant %4 8
%17 = OpConstant %6 3.141
%18 = OpConstant %6 6.282
%19 = OpConstant %6 0.44444445
%20 = OpConstant %6 0.0
%21 = OpConstantComposite %7 %19 %20 %20 %20
%22 = OpConstant %4 0
%23 = OpConstant %4 1
%24 = OpConstant %4 2
%25 = OpConstant %6 4.0
%26 = OpConstant %6 5.0
%27 = OpConstantComposite %10 %25 %26
%28 = OpConstantTrue %12
%29 = OpConstantFalse %12
%30 = OpConstantComposite %11 %28 %29
%33 = OpTypeFunction %2
%34 = OpConstantComposite %5 %15 %14 %24 %23
%36 = OpTypePointer Function %5
%41 = OpTypePointer Function %4
%45 = OpConstant %4 6
%50 = OpConstant %4 30
%51 = OpConstant %4 70
%54 = OpConstantNull %4
%56 = OpConstantNull %4
%59 = OpConstantNull %5
%70 = OpConstant %4 -4
%71 = OpConstantComposite %5 %70 %70 %70 %70
%80 = OpConstant %6 1.0
%81 = OpConstant %6 2.0
%82 = OpConstantComposite %7 %81 %80 %80 %80
%84 = OpTypePointer Function %7
%89 = OpTypePointer Function %8
%90 = OpConstantNull %8
%95 = OpTypeFunction %3 %4
%96 = OpConstant %3 10
%97 = OpConstant %3 20
%98 = OpConstant %3 30
%99 = OpConstant %3 0
%106 = OpConstantNull %3
%109 = OpConstantComposite %13 %23 %23 %23
%110 = OpConstantComposite %13 %22 %23 %24
%111 = OpConstantComposite %13 %23 %22 %24
%113 = OpTypePointer Function %13
%32 = OpFunction %2 None %33
%31 = OpLabel
%35 = OpVariable %36 Function %34
OpBranch %37
%37 = OpLabel
%39 = OpVariable %40 Function %23
OpBranch %41
%41 = OpLabel
OpReturn
OpFunctionEnd
%43 = OpFunction %2 None %32
%39 = OpFunction %2 None %33
%38 = OpLabel
%40 = OpVariable %41 Function %24
OpBranch %42
%42 = OpLabel
%45 = OpVariable %40 Function %44
OpBranch %46
%46 = OpLabel
OpReturn
OpFunctionEnd
%48 = OpFunction %2 None %32
%44 = OpFunction %2 None %33
%43 = OpLabel
%46 = OpVariable %41 Function %45
OpBranch %47
%47 = OpLabel
%57 = OpVariable %35 Function %58
%52 = OpVariable %40 Function %53
%56 = OpVariable %40 Function %50
%51 = OpVariable %40 Function %49
%54 = OpVariable %40 Function %55
OpBranch %59
%59 = OpLabel
%60 = OpLoad %4 %51
OpStore %52 %60
%61 = OpLoad %4 %52
OpStore %54 %61
%62 = OpLoad %4 %51
%63 = OpLoad %4 %52
%64 = OpLoad %4 %54
%65 = OpLoad %4 %56
%66 = OpCompositeConstruct %5 %62 %63 %64 %65
OpStore %57 %66
OpReturn
OpFunctionEnd
%68 = OpFunction %2 None %32
%67 = OpLabel
%71 = OpVariable %35 Function %70
OpBranch %72
%72 = OpLabel
%49 = OpFunction %2 None %33
%48 = OpLabel
%58 = OpVariable %36 Function %59
%53 = OpVariable %41 Function %54
%57 = OpVariable %41 Function %51
%52 = OpVariable %41 Function %50
%55 = OpVariable %41 Function %56
OpBranch %60
%60 = OpLabel
%61 = OpLoad %4 %52
OpStore %53 %61
%62 = OpLoad %4 %53
OpStore %55 %62
%63 = OpLoad %4 %52
%64 = OpLoad %4 %53
%65 = OpLoad %4 %55
%66 = OpLoad %4 %57
%67 = OpCompositeConstruct %5 %63 %64 %65 %66
OpStore %58 %67
OpReturn
OpFunctionEnd
%74 = OpFunction %2 None %32
%69 = OpFunction %2 None %33
%68 = OpLabel
%72 = OpVariable %36 Function %71
OpBranch %73
%73 = OpLabel
%75 = OpVariable %35 Function %70
OpBranch %76
%76 = OpLabel
OpReturn
OpFunctionEnd
%78 = OpFunction %2 None %32
%75 = OpFunction %2 None %33
%74 = OpLabel
%76 = OpVariable %36 Function %71
OpBranch %77
%77 = OpLabel
%82 = OpVariable %83 Function %81
OpBranch %84
%84 = OpLabel
OpReturn
OpFunctionEnd
%87 = OpFunction %3 None %88
%86 = OpFunctionParameter %4
%79 = OpFunction %2 None %33
%78 = OpLabel
%83 = OpVariable %84 Function %82
OpBranch %85
%85 = OpLabel
OpBranch %93
%93 = OpLabel
OpSelectionMerge %94 None
OpSwitch %86 %98 0 %95 1 %96 2 %97
%95 = OpLabel
OpReturnValue %89
%96 = OpLabel
OpReturnValue %90
%97 = OpLabel
OpReturnValue %91
%98 = OpLabel
OpReturnValue %92
%94 = OpLabel
OpReturnValue %99
OpReturn
OpFunctionEnd
%87 = OpFunction %2 None %33
%86 = OpLabel
%88 = OpVariable %89 Function %90
OpBranch %91
%91 = OpLabel
OpReturn
OpFunctionEnd
%101 = OpFunction %2 None %32
%94 = OpFunction %3 None %95
%93 = OpFunctionParameter %4
%92 = OpLabel
OpBranch %100
%100 = OpLabel
%105 = OpVariable %106 Function %102
%107 = OpVariable %106 Function %103
%108 = OpVariable %106 Function %104
OpBranch %109
%109 = OpLabel
OpSelectionMerge %101 None
OpSwitch %93 %105 0 %102 1 %103 2 %104
%102 = OpLabel
OpReturnValue %96
%103 = OpLabel
OpReturnValue %97
%104 = OpLabel
OpReturnValue %98
%105 = OpLabel
OpReturnValue %99
%101 = OpLabel
OpReturnValue %106
OpFunctionEnd
%108 = OpFunction %2 None %33
%107 = OpLabel
%112 = OpVariable %113 Function %109
%114 = OpVariable %113 Function %110
%115 = OpVariable %113 Function %111
OpBranch %116
%116 = OpLabel
OpReturn
OpFunctionEnd
%111 = OpFunction %2 None %32
%110 = OpLabel
OpBranch %112
%112 = OpLabel
%113 = OpFunctionCall %2 %31
%114 = OpFunctionCall %2 %38
%115 = OpFunctionCall %2 %43
%116 = OpFunctionCall %2 %48
%117 = OpFunctionCall %2 %68
%118 = OpFunctionCall %2 %74
%119 = OpFunctionCall %2 %78
%118 = OpFunction %2 None %33
%117 = OpLabel
OpBranch %119
%119 = OpLabel
%120 = OpFunctionCall %2 %32
%121 = OpFunctionCall %2 %39
%122 = OpFunctionCall %2 %44
%123 = OpFunctionCall %2 %49
%124 = OpFunctionCall %2 %69
%125 = OpFunctionCall %2 %75
%126 = OpFunctionCall %2 %79
%127 = OpFunctionCall %2 %87
OpReturn
OpFunctionEnd
Loading

0 comments on commit 6e1d427

Please sign in to comment.