tint/cmd: Dump disassembly with --verbose

Change-Id: I2701117b6c253b632091a59fc1a63d97526d5ce2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97500
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-08-01 19:56:24 +00:00 committed by Dawn LUCI CQ
parent 92f2cb79b5
commit 86329e286b
2 changed files with 34 additions and 13 deletions

View File

@ -868,9 +868,13 @@ bool GenerateHlsl(const tint::Program* program, const Options& options) {
if (options.verbose) {
if (fxc_found && !fxc_res.failed) {
std::cout << "Passed FXC validation" << std::endl;
std::cout << fxc_res.output;
std::cout << std::endl;
}
if (dxc_found && !dxc_res.failed) {
std::cout << "Passed DXC validation" << std::endl;
std::cout << dxc_res.output;
std::cout << std::endl;
}
}
}

View File

@ -114,13 +114,21 @@ Result HlslUsingFXC(const std::string& fxc_path,
return result;
}
pD3DCompile d3dCompile = reinterpret_cast<pD3DCompile>(
auto* d3dCompile = reinterpret_cast<pD3DCompile>(
reinterpret_cast<void*>(GetProcAddress(fxcLib, "D3DCompile")));
auto* d3dDisassemble = reinterpret_cast<pD3DDisassemble>(
reinterpret_cast<void*>(GetProcAddress(fxcLib, "D3DDisassemble")));
if (d3dCompile == nullptr) {
result.output = "Couldn't load D3DCompile from FXC";
result.failed = true;
return result;
}
if (d3dDisassemble == nullptr) {
result.output = "Couldn't load D3DDisassemble from FXC";
result.failed = true;
return result;
}
for (auto ep : entry_points) {
const char* profile = "";
@ -147,7 +155,7 @@ Result HlslUsingFXC(const std::string& fxc_path,
ComPtr<ID3DBlob> compiledShader;
ComPtr<ID3DBlob> errors;
HRESULT cr = d3dCompile(source.c_str(), // pSrcData
HRESULT res = d3dCompile(source.c_str(), // pSrcData
source.length(), // SrcDataSize
nullptr, // pSourceName
nullptr, // pDefines
@ -158,10 +166,19 @@ Result HlslUsingFXC(const std::string& fxc_path,
0, // Flags2
&compiledShader, // ppCode
&errors); // ppErrorMsgs
if (FAILED(cr)) {
if (FAILED(res)) {
result.output = static_cast<char*>(errors->GetBufferPointer());
result.failed = true;
return result;
} else {
ComPtr<ID3DBlob> disassembly;
res = d3dDisassemble(compiledShader->GetBufferPointer(),
compiledShader->GetBufferSize(), 0, "", &disassembly);
if (FAILED(res)) {
result.output = "failed to disassemble shader";
} else {
result.output = static_cast<char*>(disassembly->GetBufferPointer());
}
}
}