Skip to content

Commit

Permalink
Disable warnings for input global variables (shader-slang#4745)
Browse files Browse the repository at this point in the history
* Disable warnings for input global variables

* Update comment to reflect actual check

Co-authored-by: ArielG-NV <[email protected]>

* Update comments in uninitialized-globals.slang

* Update uninitialized-globals.slang

* Refactoring test variable

* Typo in test

---------

Co-authored-by: ArielG-NV <[email protected]>
  • Loading branch information
venkataram-nv and ArielG-NV authored Jul 26, 2024
1 parent a266cbf commit c0bff66
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion source/slang/slang-ir-inst-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ INST_RANGE(BindingQuery, GetRegisterIndex, GetRegisterSpace)
INST(AlwaysFoldIntoUseSiteDecoration, alwaysFold, 0, 0)

INST(GlobalOutputDecoration, output, 0, 0)
INST(GlobalInputDecoration, output, 0, 0)
INST(GlobalInputDecoration, input, 0, 0)
INST(GLSLLocationDecoration, glslLocation, 1, 0)
INST(GLSLOffsetDecoration, glslOffset, 1, 0)
INST(PayloadDecoration, payload, 0, 0)
Expand Down
3 changes: 3 additions & 0 deletions source/slang/slang-ir-use-uninitialized-values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ namespace Slang
if (variable->findDecoration<IRSemanticDecoration>())
return;

if (variable->findDecoration<IRGlobalInputDecoration>())
return;

// Check for initialization blocks
for (auto inst : variable->getChildren())
{
Expand Down
41 changes: 36 additions & 5 deletions tests/diagnostics/uninitialized-globals.slang
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//TEST:SIMPLE(filecheck=CHK): -target spirv
//TEST:SIMPLE(filecheck=CHK): -allow-glsl -target spirv

// Using groupshared variables
groupshared float4 gsConstexpr = float4(1.0f);
groupshared float4 gsUndefined;
groupshared float4 gsUninitialized;

// OK
float use_constexpr_initialized_gs()
Expand All @@ -12,8 +12,8 @@ float use_constexpr_initialized_gs()

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

// Using static variables
Expand All @@ -35,7 +35,7 @@ void write_to_later()

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

Expand All @@ -45,4 +45,35 @@ float use_later_writte()
return writtenLater;
}

// Varying inputs never warn
layout(location = 0) in vec4 data;

vec4 glsl_layout_in_ok()
{
return data;
}

// Layout outputs should still be written to at some point
layout(location = 1) out vec4 x;

vec4 glsl_layout_out_undefined()
{
//CHK-DAG: ([[# @LINE + 1]]): warning 41017: use of uninitialized global variable 'x'
return x;
}

layout(location = 2) out vec4 y;

void glsl_layout_out_store(vec4 data)
{
// Written to here...
y = data;
}

vec4 glsl_layout_out_ok()
{
// ...so read here is treated as OK
return y;
}

//CHK-NOT: warning 41017

0 comments on commit c0bff66

Please sign in to comment.