From 94c2c2d44c7bbfbccad14d6230c3ca09800426ad Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 19 Apr 2022 00:31:17 +0000 Subject: [PATCH] [tint] Remove current_function_ usage from ValidateLocationAttribute. The ValidateLocationAttribute function needs to know the stage of the current function so, pass that in instead of accessing current_function_ directly. Bug: tint:1313 Change-Id: Ifa0ac912f5e78f14b6512fd74ae951545abd9b22 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87140 Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Dan Sinclair --- src/tint/resolver/resolver.h | 1 + src/tint/resolver/resolver_validation.cc | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tint/resolver/resolver.h b/src/tint/resolver/resolver.h index ff879b08ce..76f1e86a76 100644 --- a/src/tint/resolver/resolver.h +++ b/src/tint/resolver/resolver.h @@ -271,6 +271,7 @@ class Resolver { bool ValidateLocationAttribute(const ast::LocationAttribute* location, const sem::Type* type, std::unordered_set& locations, + ast::PipelineStage stage, const Source& source, const bool is_input = false); bool ValidateLoopStatement(const sem::LoopStatement* stmt); diff --git a/src/tint/resolver/resolver_validation.cc b/src/tint/resolver/resolver_validation.cc index 708a4fab94..e12d2e8397 100644 --- a/src/tint/resolver/resolver_validation.cc +++ b/src/tint/resolver/resolver_validation.cc @@ -1002,7 +1002,11 @@ bool Resolver::ValidateEntryPoint(const sem::Function* func) { pipeline_io_attribute = attr; bool is_input = param_or_ret == ParamOrRetType::kParameter; - if (!ValidateLocationAttribute(location, ty, locations, source, + + auto stage = current_function_ + ? current_function_->Declaration()->PipelineStage() + : ast::PipelineStage::kNone; + if (!ValidateLocationAttribute(location, ty, locations, stage, source, is_input)) { return false; } @@ -2099,8 +2103,11 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { invariant_attribute = invariant; } else if (auto* location = attr->As()) { has_location = true; + auto stage = current_function_ + ? current_function_->Declaration()->PipelineStage() + : ast::PipelineStage::kNone; if (!ValidateLocationAttribute(location, member->Type(), locations, - member->Declaration()->source)) { + stage, member->Declaration()->source)) { return false; } } else if (auto* builtin = attr->As()) { @@ -2146,11 +2153,11 @@ bool Resolver::ValidateLocationAttribute( const ast::LocationAttribute* location, const sem::Type* type, std::unordered_set& locations, + ast::PipelineStage stage, const Source& source, const bool is_input) { std::string inputs_or_output = is_input ? "inputs" : "output"; - if (current_function_ && current_function_->Declaration()->PipelineStage() == - ast::PipelineStage::kCompute) { + if (stage == ast::PipelineStage::kCompute) { AddError("attribute is not valid for compute shader " + inputs_or_output, location->source); return false;