diff --git a/src/dawn_native/Toggles.cpp b/src/dawn_native/Toggles.cpp index efc1540b4f..81cec28982 100644 --- a/src/dawn_native/Toggles.cpp +++ b/src/dawn_native/Toggles.cpp @@ -189,6 +189,12 @@ namespace dawn_native { "This is useful to prevent a Chromium renderer process from successfully sending" "SPIR-V code to be compiled in the GPU process.", "https://crbug.com/1214923"}}, + {Toggle::DumpTranslatedShaders, + {"dump_translated_shaders", + "Dump generated shaders for debug propose, dumped shaders will be log via " + "EmitLog, thus printed in Chrome console or consumed by user-defined callback " + "function.", + "https://crbug.com/dawn/792"}} // Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle. }}; } // anonymous namespace diff --git a/src/dawn_native/Toggles.h b/src/dawn_native/Toggles.h index f9dc6c0018..639ebb44e7 100644 --- a/src/dawn_native/Toggles.h +++ b/src/dawn_native/Toggles.h @@ -53,6 +53,7 @@ namespace dawn_native { UseTempBufferInSmallFormatTextureToTextureCopyFromGreaterToLessMipLevel, EmitHLSLDebugSymbols, DisallowSpirv, + DumpTranslatedShaders, EnumCount, InvalidEnum = EnumCount, diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp index 2b7f3e947a..ed4727d2c3 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp @@ -393,6 +393,12 @@ namespace dawn_native { namespace d3d12 { entryPointName = "main"; } + if (device->IsToggleEnabled(Toggle::DumpTranslatedShaders)) { + std::ostringstream dumpedMsg; + dumpedMsg << "/* Dumped generated HLSL */" << std::endl << hlslSource; + GetDevice()->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str()); + } + // Use HLSL source as the input for the key since it does need to know about the pipeline // layout. The pipeline layout is only required if we key from WGSL: two different pipeline // layouts could be used to produce different shader blobs and the wrong shader blob could