0
\$\begingroup\$

Here 's the thing. I developed a graphic project using SharpDx. Every time I actived the graphic diagnostic and debuged some hlsl code in my shaders, It always showed me the disassembling code rather than source file code. I want to know why and how to get the source code in the graphic debugger.

For Example, this is the source code in my hlsl file light.hlsl:

cbuffer CameraConstant : register(b0)
{
    matrix World;
    matrix View;
    matrix Projection;
};

struct VS_IN
{
    float4 position : POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
};

struct PS_IN
{
    float4 position : SV_POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
};

PS_IN LightVertexShader(VS_IN input)
{
    PS_IN output = (PS_IN)0;

    input.position.w = 1.0f;

    output.position = mul(input.position, World);
    output.position = mul(output.position, View);
    output.position = mul(output.position, Projection);

    output.tex = input.tex;

    output.normal = mul(input.normal, (float3x3)World);
    output.normal = normalize(output.normal);

    return output;
};

Texture2D shaderTexture : register(t0);
SamplerState SampleType : register(s0);

cbuffer LightConstant : register(b0)
{
    float4 AmbientColor;
    float4 DiffuseColor;
    float3 LightDirection;
};

float4 LightPixelShader(PS_IN input) : SV_TARGET
{
    float4 textureColor;
    float4 color;
    textureColor = shaderTexture.Sample(SampleType, input.tex);
    color = AmbientColor;

    float3 lightDir;
    lightDir = -LightDirection;

    float lightIntensity;
    lightIntensity = saturate(dot(input.normal, lightDir));

    if (lightIntensity > 0.0f)
    {
        color += (DiffuseColor * lightIntensity);
    }

    color = saturate(color);
    color = color * textureColor;

    return color;
};

And Here is the code when I'm debugging the vertex shader in graphic diagnostics, which is the disassembling code related to the code in light.hlsl, such as:

 // 
 // generated by microsoft (r) hlsl shader compiler 10.1 
 // 
 // 
 // buffer definitions: 
 // 
 // cbuffer cameraconstant 
 // { 
 // 
 //   float4x4 world;                    // offset:    0 size:    64 
 //   float4x4 view;                     // offset:   64 size:    64 
 //   float4x4 projection;               // offset:  128 size:    64 
 // 
 // } 
 // 
 // 
 // resource bindings: 
 // 
 // name                                 type  format         dim      hlsl bind  count 
 // ------------------------------ ---------- ------- ----------- -------------- ------ 
 // cameraconstant                    cbuffer      na          na            cb0      1 
 // 
 // 
 // 
 // input signature: 
 // 
 // name                 index   mask register sysvalue  format   used 
 // -------------------- ----- ------ -------- -------- ------- ------ 
 // position                 0   xyzw        0     none   float   xyz 
 // texcoord                 0   xy          1     none   float   xy 
 // normal                   0   xyz         2     none   float   xyz 
 // 
 // 
 // output signature: 
 // 
 // name                 index   mask register sysvalue  format   used 
 // -------------------- ----- ------ -------- -------- ------- ------ 
 // sv_position              0   xyzw        0      pos   float   xyzw 
 // texcoord                 0   xy          1     none   float   xy 
 // normal                   0   xyz         2     none   float   xyz 
 // 
 0x00000000: vs_5_0 
 0x00000008: dcl_globalflags refactoringallowed 
 0x0000000c: dcl_constantbuffer cb0[12], immediateindexed 
 0x0000001c: dcl_input v0.xyz 
 0x00000028: dcl_input v1.xy 
 0x00000034: dcl_input v2.xyz 
 0x00000040: dcl_output_siv o0.xyzw, position 
 0x00000050: dcl_output o1.xy 
 0x0000005c: dcl_output o2.xyz 
 0x00000068: dcl_temps 2 
--- 无源文件 -----------------------------------------------------------------------
<unknown>:
00000000  mov r0.xyz, v0.xyzx  
00000001  mov r0.w, l(1.000000)  
00000002  dp4 r1.x, r0.xyzw, cb0[0].xyzw  
00000003  dp4 r1.y, r0.xyzw, cb0[1].xyzw  
00000004  dp4 r1.z, r0.xyzw, cb0[2].xyzw  
00000005  dp4 r1.w, r0.xyzw, cb0[3].xyzw  
00000006  dp4 r0.x, r1.xyzw, cb0[4].xyzw  
00000007  dp4 r0.y, r1.xyzw, cb0[5].xyzw  
00000008  dp4 r0.z, r1.xyzw, cb0[6].xyzw  
00000009  dp4 r0.w, r1.xyzw, cb0[7].xyzw  
0000000A  dp4 o0.x, r0.xyzw, cb0[8].xyzw  
0000000B  dp4 o0.y, r0.xyzw, cb0[9].xyzw  
0000000C  dp4 o0.z, r0.xyzw, cb0[10].xyzw  
0000000D  dp4 o0.w, r0.xyzw, cb0[11].xyzw  
0000000E  mov o1.xy, v1.xyxx  
0000000F  dp3 r0.x, v2.xyzx, cb0[0].xyzx  
00000010  dp3 r0.y, v2.xyzx, cb0[1].xyzx  
00000011  dp3 r0.z, v2.xyzx, cb0[2].xyzx  
00000012  dp3 r0.w, r0.xyzx, r0.xyzx  
00000013  rsq r0.w, r0.w  
00000014  mul o2.xyz, r0.wwww, r0.xyzx  
00000015  ret  
 // approximately 22 instruction slots used 
\$\endgroup\$
  • \$\begingroup\$ Please post code as text, not as images. This makes it searchable, more accessible, and eases copy-snd-pasting if users want to talk about a particular snippet in an answer. \$\endgroup\$ – DMGregory Mar 8 '18 at 11:32
  • \$\begingroup\$ Right, I add the code in my question, I hope this will help. \$\endgroup\$ – tedyage Mar 9 '18 at 2:11
  • \$\begingroup\$ There is a third party plugin for Visual Studio called HLSL Tools that can be found on the marketplace. If I remember correctly it is free and offers things like intellisense, debugging, highlighting, jump to function, etc for HLSL. Maybe that will help? \$\endgroup\$ – user121635 Oct 29 '18 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.