search

Home  >  Q&A  >  body text

c++ - 如何调试HLSL编写的shader?

D3D11初学者,最近在尝试实现一些光照模型。可是有个问题就是.fx文件里面的HLSL代码不知道该如何去调试,我能定位到某个值出了问题,我想打印看一下值是什么,但是却没有办法,断点什么的也没用,求指点。

PHP中文网PHP中文网2804 days ago484

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:27:45

    https://msdn.microsoft.com/zh-cn/library/hh873197.aspx There are instructions on this, but... I don’t know how to use it either

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:27:45

    Do you use the D3DCompileFromFile function to compile your hlsl source code? The hlsl bytecode generated by this function does not contain compilation information by default, so it cannot be debugged in VS (can only be debugged by disassembly) .

    Function prototype:

    HRESULT  D3DXCompileShaderFromFile(
      __in   LPCSTR pSrcFile,
      __in   const D3DXMACRO *pDefines,
      __in   LPD3DXINCLUDE pInclude,
      __in   LPCSTR pFunctionName,
      __in   LPCSTR pProfile,
      __in   DWORD Flags,
      __out  LPD3DXBUFFER *ppShader,
      __out  LPD3DXBUFFER *ppErrorMsgs,
      __out  LPD3DXCONSTANTTABLE *ppConstantTable
    );
    

    Set the fourth parameter from the last to: D3DXSHADER_DEBUG or D3D10_SHADER_DEBUG depending on your sdk

        // Compile the vertex shader code.
        result = D3DCompileFromFile(
                                    vsFilename, 
                                    NULL, 
                                    NULL, 
                                    "TextureVertexShader", 
                                    "vs_5_0", 
                                    D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_DEBUG ,
                                     0,
                                    &vertexShaderBuffer, 
                                    &errorMessage);

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:27:45

    For VS2015, go to Debugging->Graphics->Start graphics debugging and then you can debug the program like debugging C++ code

    reply
    0
  • Cancelreply