dawn_native: Add a force_wgsl_step toggle.
This makes SPIRV ingestion always go through a SPIRV->WGSL step first. This will be used to make sure that path works correctly on existing WebGPU SPIRV sites so we're confident the SPIRV->WGSL translation will work when compiled to WASM. Bug: dawn:960 Change-Id: I17efd8c64d9d60ff033ba89b8fff9295e66524ef Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/56080 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
0cb3d480ff
commit
220ff07ffd
|
@ -14,10 +14,9 @@
|
|||
|
||||
tint_root_dir = "//third_party/tint"
|
||||
tint_spirv_tools_dir = "//third_party/vulkan-deps/spirv-tools/src"
|
||||
tint_googletest_dir = "//third_party/googletest"
|
||||
tint_spirv_headers_dir = "//third_party/vulkan-deps/spirv-headers/src"
|
||||
|
||||
tint_build_spv_reader = true
|
||||
tint_build_spv_writer = true
|
||||
tint_build_wgsl_reader = true
|
||||
tint_build_wgsl_writer = false
|
||||
tint_build_wgsl_writer = true
|
||||
|
|
|
@ -1086,6 +1086,30 @@ namespace dawn_native {
|
|||
const ShaderModuleWGSLDescriptor* wgslDesc = nullptr;
|
||||
FindInChain(chainedDescriptor, &wgslDesc);
|
||||
|
||||
// We have a temporary toggle to force the SPIRV ingestion to go through a WGSL
|
||||
// intermediate step. It is done by switching the spirvDesc for a wgslDesc below.
|
||||
ShaderModuleWGSLDescriptor newWgslDesc;
|
||||
std::string newWgslCode;
|
||||
if (spirvDesc && device->IsToggleEnabled(Toggle::ForceWGSLStep)) {
|
||||
std::vector<uint32_t> spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize);
|
||||
tint::Program program;
|
||||
DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages));
|
||||
|
||||
tint::writer::wgsl::Generator generator(&program);
|
||||
if (!generator.Generate()) {
|
||||
std::ostringstream errorStream;
|
||||
errorStream << "Tint WGSL failure:" << std::endl;
|
||||
errorStream << "Generator: " << generator.error() << std::endl;
|
||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||
}
|
||||
|
||||
newWgslCode = generator.result();
|
||||
newWgslDesc.source = newWgslCode.c_str();
|
||||
|
||||
spirvDesc = nullptr;
|
||||
wgslDesc = &newWgslDesc;
|
||||
}
|
||||
|
||||
if (spirvDesc) {
|
||||
if (device->IsToggleEnabled(Toggle::DisallowSpirv)) {
|
||||
return DAWN_VALIDATION_ERROR("SPIR-V is disallowed.");
|
||||
|
|
|
@ -194,7 +194,13 @@ namespace dawn_native {
|
|||
"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"}}
|
||||
"https://crbug.com/dawn/792"}},
|
||||
{Toggle::ForceWGSLStep,
|
||||
{"force_wgsl_step",
|
||||
"When ingesting SPIR-V shaders, force a first conversion to WGSL. This allows "
|
||||
"testing Tint's SPIRV->WGSL translation on real content to be sure that it will "
|
||||
"work when the same translation runs in a WASM module in the page.",
|
||||
"https://crbug.com/dawn/960"}},
|
||||
// Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle.
|
||||
}};
|
||||
} // anonymous namespace
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace dawn_native {
|
|||
EmitHLSLDebugSymbols,
|
||||
DisallowSpirv,
|
||||
DumpTranslatedShaders,
|
||||
ForceWGSLStep,
|
||||
|
||||
EnumCount,
|
||||
InvalidEnum = EnumCount,
|
||||
|
|
Loading…
Reference in New Issue