DX9: Improved shader debug info output.

This commit is contained in:
bkaradzic 2013-08-09 21:32:23 -07:00
parent f1f5e3fa32
commit 8f026846ff
2 changed files with 53 additions and 25 deletions

Binary file not shown.

View file

@ -278,7 +278,7 @@ int32_t writef(bx::WriterI* _writer, const char* _format, ...)
len = bx::vsnprintf(out, len, _format, argList); len = bx::vsnprintf(out, len, _format, argList);
} }
len = _writer->write(out, len); len = bx::write(_writer, out, len);
va_end(argList); va_end(argList);
@ -493,13 +493,13 @@ void printCode(const char* _code)
fprintf(stderr, "---\n"); fprintf(stderr, "---\n");
} }
void writeFile(const char* _filePath, void* _data, uint32_t _size) void writeFile(const char* _filePath, const void* _data, int32_t _size)
{ {
FILE* file = fopen(_filePath, "wb"); bx::CrtFileWriter out;
if (NULL != file) if (0 == out.open(_filePath) )
{ {
fwrite(_data, 1, _size, file); out.write(_data, _size);
fclose(file); out.close();
} }
} }
@ -533,7 +533,7 @@ bool compileGLSLShader(bx::CommandLine& _cmdLine, const std::string& _code, bx::
writef(_writer, "#version %s\n\n", profile); writef(_writer, "#version %s\n\n", profile);
} }
_writer->write(optimizedShader, (int32_t)strlen(optimizedShader) ); bx::write(_writer, optimizedShader, (int32_t)strlen(optimizedShader) );
uint8_t nul = 0; uint8_t nul = 0;
bx::write(_writer, nul); bx::write(_writer, nul);
@ -552,14 +552,16 @@ bool compileHLSLShaderDx9(bx::CommandLine& _cmdLine, const std::string& _code, b
return false; return false;
} }
bool debug = _cmdLine.hasArg('\0', "debug");
uint32_t flags = 0; uint32_t flags = 0;
flags |= _cmdLine.hasArg('\0', "debug") ? D3DXSHADER_DEBUG : 0; flags |= debug ? D3DXSHADER_DEBUG : 0;
flags |= _cmdLine.hasArg('\0', "avoid-flow-control") ? D3DXSHADER_AVOID_FLOW_CONTROL : 0; flags |= _cmdLine.hasArg('\0', "avoid-flow-control") ? D3DXSHADER_AVOID_FLOW_CONTROL : 0;
flags |= _cmdLine.hasArg('\0', "no-preshader") ? D3DXSHADER_NO_PRESHADER : 0; flags |= _cmdLine.hasArg('\0', "no-preshader") ? D3DXSHADER_NO_PRESHADER : 0;
flags |= _cmdLine.hasArg('\0', "partial-precision") ? D3DXSHADER_PARTIALPRECISION : 0; flags |= _cmdLine.hasArg('\0', "partial-precision") ? D3DXSHADER_PARTIALPRECISION : 0;
flags |= _cmdLine.hasArg('\0', "prefer-flow-control") ? D3DXSHADER_PREFER_FLOW_CONTROL : 0; flags |= _cmdLine.hasArg('\0', "prefer-flow-control") ? D3DXSHADER_PREFER_FLOW_CONTROL : 0;
flags |= _cmdLine.hasArg('\0', "backwards-compatibility") ? D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY : 0; flags |= _cmdLine.hasArg('\0', "backwards-compatibility") ? D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY : 0;
bool werror = _cmdLine.hasArg('\0', "Werror"); bool werror = _cmdLine.hasArg('\0', "Werror");
uint32_t optimization = 3; uint32_t optimization = 3;
@ -580,17 +582,43 @@ bool compileHLSLShaderDx9(bx::CommandLine& _cmdLine, const std::string& _code, b
LPD3DXBUFFER errorMsg; LPD3DXBUFFER errorMsg;
LPD3DXCONSTANTTABLE constantTable; LPD3DXCONSTANTTABLE constantTable;
HRESULT hr = D3DXCompileShader(_code.c_str() HRESULT hr;
, (uint32_t)_code.size()
, NULL // Output preprocessed shader so that HLSL can be debugged via GPA
, NULL // or PIX. Compiling through memory won't embed preprocessed shader
, "main" // file path.
, profile if (debug)
, flags {
, &code std::string ofp = _cmdLine.findOption('o');
, &errorMsg ofp += ".hlsl";
, &constantTable writeFile(ofp.c_str(), _code.c_str(), (int32_t)_code.size() );
);
hr = D3DXCompileShaderFromFileA(ofp.c_str()
, NULL
, NULL
, "main"
, profile
, flags
, &code
, &errorMsg
, &constantTable
);
}
else
{
hr = D3DXCompileShader(_code.c_str()
, (uint32_t)_code.size()
, NULL
, NULL
, "main"
, profile
, flags
, &code
, &errorMsg
, &constantTable
);
}
if (FAILED(hr) if (FAILED(hr)
|| (werror && NULL != errorMsg) ) || (werror && NULL != errorMsg) )
{ {
@ -655,7 +683,7 @@ bool compileHLSLShaderDx9(bx::CommandLine& _cmdLine, const std::string& _code, b
const Uniform& un = *it; const Uniform& un = *it;
uint8_t nameSize = (uint8_t)un.name.size(); uint8_t nameSize = (uint8_t)un.name.size();
bx::write(_writer, nameSize); bx::write(_writer, nameSize);
_writer->write(un.name.c_str(), nameSize); bx::write(_writer, un.name.c_str(), nameSize);
uint8_t type = un.type|fragmentBit; uint8_t type = un.type|fragmentBit;
bx::write(_writer, type); bx::write(_writer, type);
bx::write(_writer, un.num); bx::write(_writer, un.num);
@ -673,7 +701,7 @@ bool compileHLSLShaderDx9(bx::CommandLine& _cmdLine, const std::string& _code, b
uint16_t shaderSize = (uint16_t)code->GetBufferSize(); uint16_t shaderSize = (uint16_t)code->GetBufferSize();
bx::write(_writer, shaderSize); bx::write(_writer, shaderSize);
_writer->write(code->GetBufferPointer(), shaderSize); bx::write(_writer, code->GetBufferPointer(), shaderSize);
uint8_t nul = 0; uint8_t nul = 0;
bx::write(_writer, nul); bx::write(_writer, nul);
@ -831,7 +859,7 @@ bool compileHLSLShaderDx11(bx::CommandLine& _cmdLine, const std::string& _code,
} }
} }
_writer->write(attrMask, sizeof(attrMask) ); bx::write(_writer, attrMask, sizeof(attrMask) );
BX_TRACE("Output:"); BX_TRACE("Output:");
for (uint32_t ii = 0; ii < desc.OutputParameters; ++ii) for (uint32_t ii = 0; ii < desc.OutputParameters; ++ii)
@ -930,7 +958,7 @@ bool compileHLSLShaderDx11(bx::CommandLine& _cmdLine, const std::string& _code,
const Uniform& un = *it; const Uniform& un = *it;
uint8_t nameSize = (uint8_t)un.name.size(); uint8_t nameSize = (uint8_t)un.name.size();
bx::write(_writer, nameSize); bx::write(_writer, nameSize);
_writer->write(un.name.c_str(), nameSize); bx::write(_writer, un.name.c_str(), nameSize);
uint8_t type = un.type|fragmentBit; uint8_t type = un.type|fragmentBit;
bx::write(_writer, type); bx::write(_writer, type);
bx::write(_writer, un.num); bx::write(_writer, un.num);
@ -948,7 +976,7 @@ bool compileHLSLShaderDx11(bx::CommandLine& _cmdLine, const std::string& _code,
uint16_t shaderSize = (uint16_t)code->GetBufferSize(); uint16_t shaderSize = (uint16_t)code->GetBufferSize();
bx::write(_writer, shaderSize); bx::write(_writer, shaderSize);
_writer->write(code->GetBufferPointer(), shaderSize); bx::write(_writer, code->GetBufferPointer(), shaderSize);
uint8_t nul = 0; uint8_t nul = 0;
bx::write(_writer, nul); bx::write(_writer, nul);