From 86329e286b23a23d284d213e904869fbfc8a53c1 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 1 Aug 2022 19:56:24 +0000 Subject: [PATCH] tint/cmd: Dump disassembly with --verbose Change-Id: I2701117b6c253b632091a59fc1a63d97526d5ce2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97500 Auto-Submit: Ben Clayton Reviewed-by: Antonio Maiorano Kokoro: Kokoro Commit-Queue: Ben Clayton --- src/tint/cmd/main.cc | 4 ++++ src/tint/val/hlsl.cc | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/tint/cmd/main.cc b/src/tint/cmd/main.cc index 0c2bcdf89e..c38e6f9699 100644 --- a/src/tint/cmd/main.cc +++ b/src/tint/cmd/main.cc @@ -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; } } } diff --git a/src/tint/val/hlsl.cc b/src/tint/val/hlsl.cc index 18bded6fec..f1cfb05d4f 100644 --- a/src/tint/val/hlsl.cc +++ b/src/tint/val/hlsl.cc @@ -114,13 +114,21 @@ Result HlslUsingFXC(const std::string& fxc_path, return result; } - pD3DCompile d3dCompile = reinterpret_cast( + auto* d3dCompile = reinterpret_cast( reinterpret_cast(GetProcAddress(fxcLib, "D3DCompile"))); + auto* d3dDisassemble = reinterpret_cast( + reinterpret_cast(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,21 +155,30 @@ Result HlslUsingFXC(const std::string& fxc_path, ComPtr compiledShader; ComPtr errors; - HRESULT cr = d3dCompile(source.c_str(), // pSrcData - source.length(), // SrcDataSize - nullptr, // pSourceName - nullptr, // pDefines - nullptr, // pInclude - ep.first.c_str(), // pEntrypoint - profile, // pTarget - compileFlags, // Flags1 - 0, // Flags2 - &compiledShader, // ppCode - &errors); // ppErrorMsgs - if (FAILED(cr)) { + HRESULT res = d3dCompile(source.c_str(), // pSrcData + source.length(), // SrcDataSize + nullptr, // pSourceName + nullptr, // pDefines + nullptr, // pInclude + ep.first.c_str(), // pEntrypoint + profile, // pTarget + compileFlags, // Flags1 + 0, // Flags2 + &compiledShader, // ppCode + &errors); // ppErrorMsgs + if (FAILED(res)) { result.output = static_cast(errors->GetBufferPointer()); result.failed = true; return result; + } else { + ComPtr disassembly; + res = d3dDisassemble(compiledShader->GetBufferPointer(), + compiledShader->GetBufferSize(), 0, "", &disassembly); + if (FAILED(res)) { + result.output = "failed to disassemble shader"; + } else { + result.output = static_cast(disassembly->GetBufferPointer()); + } } }