ShaderModule: Refactor ParseWGSL() to take a File*
The tint::ast::Module holds a diagnostic list (tint::diag::List) which references the source tint::Source::File. If you try to enable any of the more pretty diagnostic printing functionality, and attempt to print these after ParseWGSL() has returned, you'll then dereference a pointer to the now stack unwound `tint::Source::File`. Promote the file up one callstack level to fix this. Bug: none. Only exposed when using pretty printing. Change-Id: I9432dd9d668fd1d92efa228bb5ed31278fd3ddfc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37280 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
2bd95f1cf4
commit
4c5ab90452
|
@ -173,12 +173,11 @@ namespace dawn_native {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DAWN_ENABLE_WGSL
|
#ifdef DAWN_ENABLE_WGSL
|
||||||
ResultOrError<tint::ast::Module> ParseWGSL(const char* wgsl) {
|
ResultOrError<tint::ast::Module> ParseWGSL(const tint::Source::File* file) {
|
||||||
std::ostringstream errorStream;
|
std::ostringstream errorStream;
|
||||||
errorStream << "Tint WGSL reader failure:" << std::endl;
|
errorStream << "Tint WGSL reader failure:" << std::endl;
|
||||||
|
|
||||||
tint::Source::File file("", wgsl);
|
tint::reader::wgsl::Parser parser(file);
|
||||||
tint::reader::wgsl::Parser parser(&file);
|
|
||||||
if (!parser.Parse()) {
|
if (!parser.Parse()) {
|
||||||
errorStream << "Parser: " << parser.error() << std::endl;
|
errorStream << "Parser: " << parser.error() << std::endl;
|
||||||
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
return DAWN_VALIDATION_ERROR(errorStream.str().c_str());
|
||||||
|
@ -827,16 +826,18 @@ namespace dawn_native {
|
||||||
const auto* wgslDesc =
|
const auto* wgslDesc =
|
||||||
static_cast<const ShaderModuleWGSLDescriptor*>(chainedDescriptor);
|
static_cast<const ShaderModuleWGSLDescriptor*>(chainedDescriptor);
|
||||||
|
|
||||||
|
tint::Source::File file("", wgslDesc->source);
|
||||||
|
|
||||||
if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
if (device->IsToggleEnabled(Toggle::UseTintGenerator)) {
|
||||||
tint::ast::Module module;
|
tint::ast::Module module;
|
||||||
DAWN_TRY_ASSIGN(module, ParseWGSL(wgslDesc->source));
|
DAWN_TRY_ASSIGN(module, ParseWGSL(&file));
|
||||||
if (device->IsValidationEnabled()) {
|
if (device->IsValidationEnabled()) {
|
||||||
DAWN_TRY(ValidateModule(&module));
|
DAWN_TRY(ValidateModule(&module));
|
||||||
}
|
}
|
||||||
parseResult.tintModule = std::make_unique<tint::ast::Module>(std::move(module));
|
parseResult.tintModule = std::make_unique<tint::ast::Module>(std::move(module));
|
||||||
} else {
|
} else {
|
||||||
tint::ast::Module module;
|
tint::ast::Module module;
|
||||||
DAWN_TRY_ASSIGN(module, ParseWGSL(wgslDesc->source));
|
DAWN_TRY_ASSIGN(module, ParseWGSL(&file));
|
||||||
|
|
||||||
{
|
{
|
||||||
tint::transform::Manager transformManager;
|
tint::transform::Manager transformManager;
|
||||||
|
|
Loading…
Reference in New Issue