Skip to content

Commit c0bff66

Browse files
Disable warnings for input global variables (shader-slang#4745)
* Disable warnings for input global variables * Update comment to reflect actual check Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Update comments in uninitialized-globals.slang * Update uninitialized-globals.slang * Refactoring test variable * Typo in test --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
1 parent a266cbf commit c0bff66

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

source/slang/slang-ir-inst-defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ INST_RANGE(BindingQuery, GetRegisterIndex, GetRegisterSpace)
903903
INST(AlwaysFoldIntoUseSiteDecoration, alwaysFold, 0, 0)
904904

905905
INST(GlobalOutputDecoration, output, 0, 0)
906-
INST(GlobalInputDecoration, output, 0, 0)
906+
INST(GlobalInputDecoration, input, 0, 0)
907907
INST(GLSLLocationDecoration, glslLocation, 1, 0)
908908
INST(GLSLOffsetDecoration, glslOffset, 1, 0)
909909
INST(PayloadDecoration, payload, 0, 0)

source/slang/slang-ir-use-uninitialized-values.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ namespace Slang
552552
if (variable->findDecoration<IRSemanticDecoration>())
553553
return;
554554

555+
if (variable->findDecoration<IRGlobalInputDecoration>())
556+
return;
557+
555558
// Check for initialization blocks
556559
for (auto inst : variable->getChildren())
557560
{

tests/diagnostics/uninitialized-globals.slang

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//TEST:SIMPLE(filecheck=CHK): -target spirv
1+
//TEST:SIMPLE(filecheck=CHK): -allow-glsl -target spirv
22

33
// Using groupshared variables
44
groupshared float4 gsConstexpr = float4(1.0f);
5-
groupshared float4 gsUndefined;
5+
groupshared float4 gsUninitialized;
66

77
// OK
88
float use_constexpr_initialized_gs()
@@ -12,8 +12,8 @@ float use_constexpr_initialized_gs()
1212

1313
float use_undefined_gs()
1414
{
15-
//CHK-DAG: warning 41017: use of uninitialized global variable 'gsUndefined'
16-
return gsUndefined.x;
15+
//CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'gsUninitialized'
16+
return gsUninitialized.x;
1717
}
1818

1919
// Using static variables
@@ -35,7 +35,7 @@ void write_to_later()
3535

3636
float use_never_written()
3737
{
38-
//CHK-DAG: warning 41017: use of uninitialized global variable 'writtenNever'
38+
//CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'writtenNever'
3939
return writtenNever;
4040
}
4141

@@ -45,4 +45,35 @@ float use_later_writte()
4545
return writtenLater;
4646
}
4747

48+
// Varying inputs never warn
49+
layout(location = 0) in vec4 data;
50+
51+
vec4 glsl_layout_in_ok()
52+
{
53+
return data;
54+
}
55+
56+
// Layout outputs should still be written to at some point
57+
layout(location = 1) out vec4 x;
58+
59+
vec4 glsl_layout_out_undefined()
60+
{
61+
//CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'x'
62+
return x;
63+
}
64+
65+
layout(location = 2) out vec4 y;
66+
67+
void glsl_layout_out_store(vec4 data)
68+
{
69+
// Written to here...
70+
y = data;
71+
}
72+
73+
vec4 glsl_layout_out_ok()
74+
{
75+
// ...so read here is treated as OK
76+
return y;
77+
}
78+
4879
//CHK-NOT: warning 41017

0 commit comments

Comments
 (0)