Skip to content

[SPIR-V] Shader failes to compile when activating debug infos #4911

Closed

Description

@Clothoid1

The following reproducer does not compile, leading to the error message:

fatal error : generated SPIR-V is invalid: ID '52[%52]' has not been defined
1>  %51 = OpExtInst %void %1 DebugTypeFunction %uint_3 %52 %48 %49
1>
1>note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Reproducer:

StructuredBuffer<uint16_t> myIntersectionMaskBuffer_BitCompressed : register(t0);

class CompressedIntersectionBits
{
	uint16_t myCompressedData;

	static CompressedIntersectionBits read_const(StructuredBuffer<uint16_t> aIntersectionMaskBuffer_BitCompressed_in, const uint aRayIndex_in)
	{
		CompressedIntersectionBits aCompressedIntersectionBits;
		aCompressedIntersectionBits.myCompressedData = aIntersectionMaskBuffer_BitCompressed_in[aRayIndex_in];
		return aCompressedIntersectionBits;
	}
};

class CompressedIntersectionBits_Test
{
	static CompressedIntersectionBits read_const(StructuredBuffer<uint16_t> aIntersectionMaskBuffer_BitCompressed_in, const uint aRayIndex_in)
	{
		CompressedIntersectionBits aCompressedIntersectionBits;
		aCompressedIntersectionBits.myCompressedData = aIntersectionMaskBuffer_BitCompressed_in[aRayIndex_in];
		return aCompressedIntersectionBits;
	}
};

void runKernel(const uint aIndexX_in, const uint aIndexY_in)
{
	uint aRayIndex = aIndexY_in * 512 + aIndexX_in;

	CompressedIntersectionBits aCompressedIntersectionBits = CompressedIntersectionBits::read_const(myIntersectionMaskBuffer_BitCompressed, aRayIndex);
	//CompressedIntersectionBits aCompressedIntersectionBits = CompressedIntersectionBits_Test::read_const(myIntersectionMaskBuffer_BitCompressed, aRayIndex);
}

[numthreads(8, 8, 1)]
void main(uint3 GlobalInvocationID : SV_DispatchThreadID, uint3 LocalInvocationID : SV_GroupThreadID)
{
	runKernel(GlobalInvocationID[0], GlobalInvocationID[1]);
}

Command Line used:
dxc.exe -spirv -T cs_6_7 -fvk-use-scalar-layout -enable-16bit-types -fspv-target-env=vulkan1.3 -fspv-debug=vulkan-with-source -E main

dxc version used:
dxcompiler.dll: 1.7 - 1.7.0.3774 (2168dcb4f)

Operating System used:
Windows 10

When removing the option
-fspv-debug=vulkan-with-source
the file compiles without a problem.

The issue also vanishes, when calling

CompressedIntersectionBits_Test::read_const(myIntersectionMaskBuffer_BitCompressed, aRayIndex);

instead of

CompressedIntersectionBits::read_const(myIntersectionMaskBuffer_BitCompressed, aRayIndex);

Activity

  1. added
    bug
    on Jan 5, 2023
  2. changed the title [-]Shader failes to compile when activating debug infos[/-] [+][SPIR-V] Shader failes to compile when activating debug infos[/+] on Jan 5, 2023
  3. Keenuts commented on Jan 5, 2023

    @Keenuts
    Collaborator

    Hi! Thanks for complete the report!

    Was able to reproduce at head with:

    class MyClass
    {
    	static MyClass my_func()
    	{
    		MyClass tmp;
    		return tmp;
    	}
    };
    
    [numthreads(1, 1, 1)]
    void main(uint3 GlobalInvocationID : SV_DispatchThreadID)
    {
      const uint index = GlobalInvocationID[0];
    	MyClass::my_func();
    }
    ./build/bin/dxc -spirv -T cs_6_7 -fspv-debug=vulkan-with-source -E main repro.hlsl
    

    The issue seems to be linked to the optimizer, and the compact-ids pass, IDs gets rearranged, and the ID ends up being used before being defined:

    10747 %26 = OpExtInst %void %1 DebugLexicalBlock %12 %uint_4 %uint_2 %22
    10748 %28 = OpExtInst %void %1 DebugLocalVariable %27 %19 %12 %uint_5 %uint_11 %26 %uint_4
    10853 %24 = OpExtInst %void %1 DebugTypeFunction %uint_3 %26
    [...]
    10855 %26 = OpExtInst %void %1 DebugTypeComposite %8 %uint_0 %19 %uint_1 %uint_7 %20 %8 %uint_0 %uint_3 %27
  4. Keenuts commented on Jan 5, 2023

    @Keenuts
    Collaborator

    Not a compact-ids pass issue, the initial code also contains other debug instructions with IDs defined later on. Also, from other generated spv, the use-before-declaration seems to be OK. Looking into it.

  5. added
    spirv
    on Jan 17, 2023
  6. webez commented on Mar 6, 2023

    @webez

    Hi.
    I could reproduce the same bug with this code

    class ClassA {
      void FuncA()   {
          this.FuncB();
      }
      
        void FuncB()   {
      }
    };
    
    void main() {
        ClassA var;
        var.FuncA();
    }
    
  7. Keenuts commented on May 22, 2023

    @Keenuts
    Collaborator

    Hello! Sorry haven't had much time for DXC.
    Seems like this issue is related to KhronosGroup/SPIRV-Tools#5229 but this is not enough to fix it.
    Seems like there is also a fix to do in the debug instruction ordering code.

  8. Clothoid1 commented on Jul 18, 2023

    @Clothoid1
    Author

    I just tested this issue with latest DXC compiler.
    I can now no longer reproduce this issue.
    Instead i only get the warning:
    warning : Member functions will not be linked to their class in the debug information. See KhronosGroup/SPIRV-Registry#203

    Theoretically this issue could now be closed.
    Or should it be kept open until also the warning is solved?

  9. Clothoid1 commented on Jul 18, 2023

    @Clothoid1
    Author

    When activating debug infos now all of our shaders compile - with the exception of our raytracing shaders.
    But it seems to me that this remaining issue was already reported:
    #5113

  10. Keenuts commented on Jul 18, 2023

    @Keenuts
    Collaborator

    Hello! So yes, thanks, for now, the issue is "resolved" as "it doesn't crash".
    We can close this, but we now need to change the SPIR-V spec to solve this long-term.
    (This will take longer, as we need to define the spec, and figure out how to propagate it, maybe wait a spirv release?)

    For the second issue, seems unrelated to this (as in it's a different error/crash).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugspirv

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions