You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Not sure if this is intentional or not but it looks horrifically scary to my C/C++ eyes. The shader below contains variables that use their own components for initialization during their declarations. DXC/SPIR-V seems to have no problem generating code for this - see SPIR-V below. DXC/DXIL generates this error:
error: validation errors
C:\local\Temp\21990660-6187-445f-ac50-5aef4415a2fc.hlsl:9:64: error: Instructions should not read uninitialized value.
note: at '%5 = fadd fast float %1, undef' in block '#0' of function 'main'.
C:\local\Temp\21990660-6187-445f-ac50-5aef4415a2fc.hlsl:9:53: error: Instructions should not read uninitialized value.
note: at '%8 = fadd fast float undef, %6' in block '#0' of function 'main'.
Validation failed.
Interesting case. AFAIK the HLSL spec says nothing about that, but the C++ spec does defines the behaviors, and we can check what Clang/GCC is doing:
int c;
// standard: undefined.// clang: initialized to 0.// g++: undefined.int b = b;
// standard: undefined.// clang: initialized to 0, then `mov b, b`;// g++: warn b is uninitialized, `mov b, b`structV { int x; int y; }
V v = { 0, v.x };
// standard: undefined.// clang: move 0 into v.x, then v.x into v.y.// g++: move 0 into v.x, then v.x into v.ystructV2 {
int x;
int y;
V2(int x, int y) : x(x), y(y) { }
}
V2 v2 = V2(0, v2.x);
// standard: undefined// clang: warning, default init to 0, call V2 constructor with 0 & 0// g++: warning, call constructor with 0 & undefined.
On the SPIR-V side, we do what G++ does: we allow the statement, but we move uninitialized values.
This behavior seems fair to me: you are doing something undefined, we respect that.
Once optimized, the bad values should end-up with an OpUndef.
What could be nice however is to warn if an OpUndef ends up being stored into either a resource, or returned by a shader (as I don't see a case where that's desirable). But correctly detecting those would require a complex static analysis tooling we don't have today.
I suppose I can close this as "working as intended", but feel free to re-open if you disagree.
Description
Not sure if this is intentional or not but it looks horrifically scary to my C/C++ eyes. The shader below contains variables that use their own components for initialization during their declarations. DXC/SPIR-V seems to have no problem generating code for this - see SPIR-V below. DXC/DXIL generates this error:
My quick look at the SPIR-V shows that's initializing the component values before construction the composite variable. I don't know what happens if you run this code but the usage pattern just looks dangerous and possibly a fun way to create hard to find bugs. That said, I saw this in one of the DXC/SPIR-V tests where it looks somewhat intentional: https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/test/CodeGenSPIRV/shader.debug.line.composite.hlsl#L64
Was curious if this is intentional? If it is, why?
Environment
Using DXC on https://shader-playground.timjones.io (Updated from trunk on 2024-04-29)
Shader
SPIR-V
The text was updated successfully, but these errors were encountered: