DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] Non semantic shader information issue (-fspv-debug=vulkan-with-source)

Open Goshido opened this issue 1 year ago • 7 comments

Description I'm using Vulkan + HLSL workflow. After editing shader in RenderDoc and press compile there is a compilation error:

Running "D:/Development/VulkanSDK/1.3.290.0/Bin/dxc.exe" -T ps_6_0 -E PS -spirv -fspv-target-env=vulkan1.1 -Fo C:/Users/Goshido/AppData/Local/Temp/shader_output C:/Users/Goshido/AppData/Local/Temp/shader_input
error: missing entry point definition


Process crashed with code -2147467259.
Output file is 0 bytes

I also noticed that SPIR-V blobs produced by DXC v1.8.2407.10013 a2a220bc616ca28848ec0af77ad33a09f92fa43a showed exactly the same compilation flag information in RenderDoc:

-T {hlsl_stage2}_6_0 -E {entry_point} -spirv -fspv-target-env={vulkan_ver}  -E PS -T ps_6_8 -HV 2021 -spirv 
-fvk-use-dx-layout -fspv-reduce-load-size -fspv-target-env=vulkan1.1 -enable-16bit-types -WX -I tools\editor\hlsl
-I tools\editor\include -I app\src\main\hlsl -I app\src\main\cpp\include\pbr -Od -fspv-debug=vulkan-with-source
-Fo tools\editor\editor-assets\shaders\blit.ps.spv -Qembed_debug

Now SPIR-V blobs compiled by recent DXC v1.8.2407.10091 75ff50caa046a054747ae15b5c1910a4c8aa1917 shows less information:

-T {hlsl_stage2}_6_0 -E {entry_point} -spirv -fspv-target-env={vulkan_ver}

Steps to Reproduce

  1. Take the following shader code:

blit_program.ps:

#include "blit_program.inc"
#include "color_space.ps"
#include "srgb_program.inc"


// 1.0H / 2.4H
#define INVERSE_GAMMA           4.16667e-1F

[[vk::constant_id ( CONST_INVERSE_GAMMA )]]
float const                     g_inverseGamma = INVERSE_GAMMA;

[[vk::binding ( BIND_IMAGE, SET_BLIT )]]
Texture2D<float32_t4>           g_image:        register ( t0 );

[[vk::binding ( BIND_SAMPLER, SET_BLIT )]]
SamplerState                    g_sampler:      register ( s0 );

struct InputData
{
    [[vk::location ( ATT_SLOT_UV )]]
    noperspective float32_t2    _uv:            UV;
};

//----------------------------------------------------------------------------------------------------------------------

float32_t4 PS ( in InputData inputData ): SV_Target0
{
    float16_t3 const color = (float16_t3)g_image.SampleLevel ( g_sampler, inputData._uv, 0.0F ).xyz;
    return float32_t4 ( LinearToSRGB ( color, (float16_t)g_inverseGamma ), 1.0F );
}

color_space.ps:

#ifndef COLOR_SPACE_PS
#define COLOR_SPACE_PS


float32_t3 LinearToSRGB ( in float16_t3 ldr, in float16_t inverseGamma )
{
    // See https://entropymine.com/imageworsener/srgbformula/
    float16_t3 const a = ldr * 12.92H;
    float16_t3 const b = 1.055H * pow ( ldr, inverseGamma ) - 0.055H;
    return (float32_t3)lerp ( a, b, (float16_t3)( ldr > 3.1308e-3H ) );
}


#endif // COLOR_SPACE_PS

blit_program.inc:

#ifndef BLIT_PROGRAM_INC
#define BLIT_PROGRAM_INC


#define ATT_SLOT_UV     0

#define SET_BLIT        0
#define BIND_IMAGE      0
#define BIND_SAMPLER    1


#endif // BLIT_PROGRAM_INC

srgb_program.inc:

#ifndef SRGB_PROGRAM_INC
#define SRGB_PROGRAM_INC


#define CONST_INVERSE_GAMMA     0


#endif // SRGB_PROGRAM_INC
  1. Compile it with the following flags:
dxc.exe                                                     ^
    -HV 2021                                                ^
    -spirv                                                  ^
    -fvk-use-dx-layout                                      ^
    -fspv-reduce-load-size                                  ^
    -fspv-target-env=vulkan1.1                              ^
    -enable-16bit-types                                     ^
    -WX                                                     ^
    -I tools\editor\hlsl                                    ^
    -I tools\editor\include                                 ^
    -I app\src\main\hlsl                                    ^
    -I app\src\main\cpp\include\pbr                         ^
    -Od                                                     ^
    -fspv-debug=vulkan-with-source                          ^
    -E PS                                                   ^
    -T ps_6_8                                               ^
    -Fo tools\editor\editor-assets\shaders\blit.ps.spv      ^
    tools\editor\hlsl\blit.ps
  1. Use this program and made capture.
  2. Try to edit program blit_program.ps by multiplying color variable by 0.5H.
...

float32_t4 PS ( in InputData inputData ): SV_Target0
{
    float16_t3 const color = (float16_t3)g_image.SampleLevel ( g_sampler, inputData._uv, 0.0F ).xyz;
    return float32_t4 ( LinearToSRGB ( color * 0.5H, (float16_t)g_inverseGamma ), 1.0F ); <--------------------------
}
  1. Press apply changes.

Actual Behavior Compilation fails:

Running "D:/Development/VulkanSDK/1.3.290.0/Bin/dxc.exe" -T ps_6_0 -E PS -spirv
-fspv-target-env=vulkan1.1 -Fo C:/Users/Goshido/AppData/Local/Temp/shader_output
C:/Users/Goshido/AppData/Local/Temp/shader_input
error: missing entry point definition


Process crashed with code -2147467259.
Output file is 0 bytes

Expected: Compilation success.

Would you kindly help?

Environment

  • git submodule update --init has been invoked before build
  • hctbuild build parameters: -official -rel -x64 -vs2022 -speak-up -no-dxilconv -spirv
  • Visual Studio 2022 Community components were up to date.
  • Windows 11 Pro (23H2, Build 22631.4169)
  • dxc.exe v1.8.2407.10091 executable, commit SHA-1 75ff50caa046a054747ae15b5c1910a4c8aa1917
  • RenderDoc v1.35

Additional information

Here is blobs from old and new DXC: SPIR-V blobs.zip.

The video with problem:

https://github.com/user-attachments/assets/f0ef8f84-19f0-4230-9219-11175e0bf62c

Initially I created issue for RenderDoc: #3448. Issue has been closed because it's not RenderDoc issue in the first place.

Goshido avatar Sep 29 '24 10:09 Goshido

The main difference between the "good" version and the "bad" version is that the "bad" version now includes the DebugSource for two files that were not included before. I personally do not see any problems with the debug instructions.

It could be that there is a new code pattern that renderdoc is not use to. Without know the details on where renderdoc is failing, I cannot know how the source should be changed. I've asked someone else who know more about the debug instructions to look at it.

s-perron avatar Oct 02 '24 17:10 s-perron

Roger. I gonna notify @baldurk . Maybe he could help to resolve the issue.

Goshido avatar Oct 02 '24 17:10 Goshido

I diffed the blobs and aside from noise with SSA values the problem shows up immediately for me. Yes there are new DebugSource and associated instructions, but the blob under DXC 1.8.2407.10091 75ff50 is missing DebugFunctionDefinition which is present in the blob under DXC 1.8.2407.10013 a2a220bc6.

Without this instruction the information in DebugEntry which refers to the DebugFunction can be tied to the actual OpFunction/OpEntryPoint so the command line is missing.

The debuginfo spec explicitly calls out that this is necessary for entry points:

DebugEntryPoint ... Entry Point is the <id> of the DebugFunction corresponding to the OpFunction referenced in the OpEntryPoint. This function must also have a DebugFunctionDefinition in the first basic block of that OpFunction.

baldurk avatar Oct 02 '24 17:10 baldurk

FYI: @SteveUrquhart

s-perron avatar Oct 02 '24 18:10 s-perron

This is a regression caused by https://github.com/microsoft/DirectXShaderCompiler/pull/6758.

DXC generates two function based on the entry point in the HLSL. One is src_<name>. This is the actual code from the HLSL, but it is not the entry point from the spir-v perspective. DXC will wrap this function inside another one call <name>, which is the real entry point. Its purpose is to connect the SPIR-V interface with the HLSL interface. For example, in HLSL inputs are parameters to the function, but in SPIR-V they are global variables.

Before that commit, we correctly generated the DebugFunctionDefinition in the wrapper. After that commit, the DebugFunctionDefinition is generated in src_<name>. Then src_<name> gets inlined, and when the function is deleted, the debug information for it is deleted. That is how we end up with no DebugFunctionDefinition.

As @baldurk pointed out, the spec mandates that DebugFunctionDefinition must be in the real entry point. I think we need to revert #6758. I'll talk to @SteveUrquhart about that.

s-perron avatar Oct 04 '24 17:10 s-perron

A fix should be coming soon.

s-perron avatar Oct 08 '24 18:10 s-perron

This is fixed by https://github.com/microsoft/DirectXShaderCompiler/pull/6966, sorry for the regression.

SteveUrquhart avatar Oct 14 '24 19:10 SteveUrquhart

I tested the latest DXC version 1.8.2407.10115, 9b9442cd86c242aa0c030be3beea0fb1d0df7a1f. The issue with missing shader editing feature is gone. Thx! 👍

The issue could be closed.

Goshido avatar Nov 20 '24 06:11 Goshido