Dump translated HLSL shaders if the toggle enabled

Add a toggle named "dump_translated_shaders", and when this toggle
is enabled, translated HLSL shaders will be dumped and log via
Device::EmitLog in the kInfo logging level.

BUG: dawn:792
Change-Id: Ia5ccc96019c32b43aa315f080f80a26919b441e3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/53580
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Zhaoming Jiang 2021-06-08 10:03:44 +00:00 committed by Dawn LUCI CQ
parent 0f9ea803cc
commit e557296b08
3 changed files with 13 additions and 0 deletions

View File

@ -189,6 +189,12 @@ namespace dawn_native {
"This is useful to prevent a Chromium renderer process from successfully sending" "This is useful to prevent a Chromium renderer process from successfully sending"
"SPIR-V code to be compiled in the GPU process.", "SPIR-V code to be compiled in the GPU process.",
"https://crbug.com/1214923"}}, "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. // Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle.
}}; }};
} // anonymous namespace } // anonymous namespace

View File

@ -53,6 +53,7 @@ namespace dawn_native {
UseTempBufferInSmallFormatTextureToTextureCopyFromGreaterToLessMipLevel, UseTempBufferInSmallFormatTextureToTextureCopyFromGreaterToLessMipLevel,
EmitHLSLDebugSymbols, EmitHLSLDebugSymbols,
DisallowSpirv, DisallowSpirv,
DumpTranslatedShaders,
EnumCount, EnumCount,
InvalidEnum = EnumCount, InvalidEnum = EnumCount,

View File

@ -393,6 +393,12 @@ namespace dawn_native { namespace d3d12 {
entryPointName = "main"; 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 // 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 // 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 // layouts could be used to produce different shader blobs and the wrong shader blob could