diff --git a/include/dxc/Support/SPIRVOptions.h b/include/dxc/Support/SPIRVOptions.h index 538962944..1e1c9169c 100644 --- a/include/dxc/Support/SPIRVOptions.h +++ b/include/dxc/Support/SPIRVOptions.h @@ -92,8 +92,9 @@ struct SpirvCodeGenOptions { bool printAll; // Dump SPIR-V module before each pass and after the last one. - // String representation of all command line options. + // String representation of all command line options and input file. std::string clOptions; + std::string inputFile; }; } // namespace spirv diff --git a/tools/clang/lib/SPIRV/SpirvEmitter.cpp b/tools/clang/lib/SPIRV/SpirvEmitter.cpp index 95a11136e..83df6f6ef 100644 --- a/tools/clang/lib/SPIRV/SpirvEmitter.cpp +++ b/tools/clang/lib/SPIRV/SpirvEmitter.cpp @@ -649,9 +649,10 @@ SpirvEmitter::SpirvEmitter(CompilerInstance &ci) // Emit OpModuleProcessed to indicate the command line options that were // used to generate this module. - if (!spirvOptions.clOptions.empty()) { + if (!spirvOptions.inputFile.empty() || !spirvOptions.clOptions.empty()) { // Using this format: "dxc-cl-option: XXXXXX" - std::string clOptionStr = "dxc-cl-option:" + spirvOptions.clOptions; + std::string clOptionStr = + "dxc-cl-option: " + spirvOptions.inputFile + spirvOptions.clOptions; spvBuilder.addModuleProcessed(clOptionStr); } } @@ -1306,14 +1307,11 @@ void SpirvEmitter::doFunctionDecl(const FunctionDecl *decl) { return; // Generate DebugEntryPoint if function definition if (spirvOptions.debugInfoVulkan && debugFunction) { - std::string commitHash = clang::getGitCommitHash(); - std::string clOptionStr; - if (!spirvOptions.clOptions.empty()) - clOptionStr = spirvOptions.clOptions; auto *cu = dyn_cast(outer_scope); assert(cu && "expected DebugCompilationUnit"); - spvBuilder.createDebugEntryPoint(debugFunction, cu, commitHash, - clOptionStr); + spvBuilder.createDebugEntryPoint(debugFunction, cu, + clang::getGitCommitHash(), + spirvOptions.clOptions); } } } diff --git a/tools/clang/test/CodeGenSPIRV/shader.debug.function.hlsl b/tools/clang/test/CodeGenSPIRV/shader.debug.function.hlsl index 6412f9f83..5093065cd 100644 --- a/tools/clang/test/CodeGenSPIRV/shader.debug.function.hlsl +++ b/tools/clang/test/CodeGenSPIRV/shader.debug.function.hlsl @@ -6,6 +6,7 @@ // CHECK: [[fooName:%\d+]] = OpString "foo" // CHECK: [[emptyStr:%\d+]] = OpString "" // CHECK: [[mainName:%\d+]] = OpString "main" +// CHECK: [[clOpts:%\d+]] = OpString " -E main -T ps_6_0 -spirv -fcgl -Vd -fspv-debug=vulkan -Qembed_debug" // CHECK: [[int:%\d+]] = OpExtInst %void [[set]] DebugTypeBasic {{%\d+}} %uint_32 %uint_4 %uint_0 // CHECK: [[float:%\d+]] = OpExtInst %void [[set]] DebugTypeBasic {{%\d+}} %uint_32 %uint_3 %uint_0 @@ -16,12 +17,12 @@ // Check DebugFunction instructions // -// CHECK: {{%\d+}} = OpExtInst %void [[set]] DebugFunction [[fooName]] [[fooFnType]] [[source]] %uint_34 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_35 +// CHECK: {{%\d+}} = OpExtInst %void [[set]] DebugFunction [[fooName]] [[fooFnType]] [[source]] %uint_35 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_36 // CHECK: [[float4:%\d+]] = OpExtInst %void [[set]] DebugTypeVector [[float]] %uint_4 // CHECK: [[mainFnType:%\d+]] = OpExtInst %void [[set]] DebugTypeFunction %uint_3 [[float4]] [[float4]] -// CHECK: [[mainDbgFn:%\d+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] [[mainFnType]] [[source]] %uint_39 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_40 -// CHECK: [[mainDbgEp:%\d+]] = OpExtInst %void [[set]] DebugEntryPoint [[mainDbgFn]] [[compilationUnit]] {{%\d+}} {{%\d+}} +// CHECK: [[mainDbgFn:%\d+]] = OpExtInst %void [[set]] DebugFunction [[mainName]] [[mainFnType]] [[source]] %uint_40 %uint_1 [[compilationUnit]] [[emptyStr]] %uint_3 %uint_41 +// CHECK: [[mainDbgEp:%\d+]] = OpExtInst %void [[set]] DebugEntryPoint [[mainDbgFn]] [[compilationUnit]] {{%\d+}} [[clOpts]] // Check DebugFunctionDefintion is in main // diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index 8f3ed0b27..460496996 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -1019,10 +1019,16 @@ public: opts.SpirvOptions.codeGenHighLevel = opts.CodeGenHighLevel; opts.SpirvOptions.defaultRowMajor = opts.DefaultRowMajor; opts.SpirvOptions.disableValidation = opts.DisableValidation; - // Store a string representation of command line options. - if (opts.DebugInfo) - for (auto opt : mainArgs.getArrayRef()) - opts.SpirvOptions.clOptions += " " + std::string(opt); + // Save a string representation of command line options and + // input file name. + if (opts.DebugInfo) { + opts.SpirvOptions.inputFile = opts.InputFile; + for (auto opt : mainArgs.getArrayRef()) { + if (opts.InputFile.compare(opt) != 0) { + opts.SpirvOptions.clOptions += " " + std::string(opt); + } + } + } compiler.getCodeGenOpts().SpirvOptions = opts.SpirvOptions; clang::EmitSpirvAction action;