diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 9090119ef0..7774c61bf5 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -1047,6 +1047,17 @@ namespace dawn_native { return tintProgram != nullptr || spirv.size() > 0; } + // TintSource is a PIMPL container for a tint::Source::File, which needs to be kept alive for as + // long as tint diagnostics are inspected. + class TintSource { + public: + template + TintSource(ARGS&&... args) : file(std::forward(args)...) { + } + + tint::Source::File file; + }; + MaybeError ValidateShaderModuleDescriptor(DeviceBase* device, const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { @@ -1088,13 +1099,14 @@ namespace dawn_native { const auto* wgslDesc = static_cast(chainedDescriptor); - tint::Source::File file("", wgslDesc->source); + auto tintSource = std::make_unique("", wgslDesc->source); tint::Program program; - DAWN_TRY_ASSIGN(program, ParseWGSL(&file, outMessages)); + DAWN_TRY_ASSIGN(program, ParseWGSL(&tintSource->file, outMessages)); if (device->IsToggleEnabled(Toggle::UseTintGenerator)) { parseResult->tintProgram = std::make_unique(std::move(program)); + parseResult->tintSource = std::move(tintSource); } else { tint::transform::Manager transformManager; transformManager.append( diff --git a/src/dawn_native/ShaderModule.h b/src/dawn_native/ShaderModule.h index 2e8c3af949..ab3a271558 100644 --- a/src/dawn_native/ShaderModule.h +++ b/src/dawn_native/ShaderModule.h @@ -55,6 +55,9 @@ namespace dawn_native { using EntryPointMetadataTable = std::unordered_map>; + // Source for a tint program + class TintSource; + struct ShaderModuleParseResult { ShaderModuleParseResult(); ~ShaderModuleParseResult(); @@ -64,6 +67,7 @@ namespace dawn_native { bool HasParsedShader() const; std::unique_ptr tintProgram; + std::unique_ptr tintSource; std::vector spirv; std::unique_ptr compilationMessages; };