Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the uniformity analysis trust the handle validation pass. #2200

Merged
merged 1 commit into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions src/valid/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Figures out the following properties:
- expression reference counts
!*/

use super::{CallError, ExpressionError, FunctionError, ModuleInfo, ShaderStages, ValidationFlags};
use super::{ExpressionError, FunctionError, ModuleInfo, ShaderStages, ValidationFlags};
use crate::span::{AddSpan as _, WithSpan};
use crate::{
arena::{Arena, Handle},
Expand Down Expand Up @@ -308,10 +308,7 @@ impl FunctionInfo {
handle: Handle<crate::Expression>,
global_use: GlobalUse,
) -> NonUniformResult {
//Note: if the expression doesn't exist, this function
// will return `None`, but the later validation of
// expressions should detect this and error properly.
let info = self.expressions.get_mut(handle.index())?;
let info = &mut self.expressions[handle.index()];
info.ref_count += 1;
// mark the used global as read
if let Some(global) = info.assignable_global {
Expand All @@ -335,8 +332,7 @@ impl FunctionInfo {
handle: Handle<crate::Expression>,
assignable_global: &mut Option<Handle<crate::GlobalVariable>>,
) -> NonUniformResult {
//Note: similarly to `add_ref_impl`, this ignores invalid expressions.
let info = self.expressions.get_mut(handle.index())?;
let info = &mut self.expressions[handle.index()];
info.ref_count += 1;
// propagate the assignable global up the chain, till it either hits
// a value-type expression, or the assignment statement.
Expand Down Expand Up @@ -689,13 +685,7 @@ impl FunctionInfo {
non_uniform_result: self.add_ref(expr),
requirements: UniformityRequirements::empty(),
},
E::CallResult(function) => {
let info = other_functions
.get(function.index())
.ok_or(ExpressionError::CallToUndeclaredFunction(function))?;
jimblandy marked this conversation as resolved.
Show resolved Hide resolved

info.uniformity.clone()
}
E::CallResult(function) => other_functions[function.index()].uniformity.clone(),
E::AtomicResult { .. } => Uniformity {
non_uniform_result: Some(handle),
requirements: UniformityRequirements::empty(),
Expand Down Expand Up @@ -736,15 +726,12 @@ impl FunctionInfo {
use crate::Statement as S;

let mut combined_uniformity = FunctionUniformity::new();
for (statement, &span) in statements.span_iter() {
for statement in statements {
let uniformity = match *statement {
S::Emit(ref range) => {
let mut requirements = UniformityRequirements::empty();
for expr in range.clone() {
let req = match self.expressions.get(expr.index()) {
Some(expr) => expr.uniformity.requirements,
None => UniformityRequirements::empty(),
};
let req = self.expressions[expr.index()].uniformity.requirements;
#[cfg(feature = "validate")]
if self
.flags
Expand Down Expand Up @@ -889,13 +876,7 @@ impl FunctionInfo {
for &argument in arguments {
let _ = self.add_ref(argument);
}
let info = other_functions.get(function.index()).ok_or(
FunctionError::InvalidCall {
function,
error: CallError::ForwardDeclaredFunction,
}
.with_span_static(span, "forward call"),
)?;
let info = &other_functions[function.index()];
//Note: the result is validated by the Validator, not here
self.process_call(info, arguments, expression_arena)?
}
Expand Down
2 changes: 0 additions & 2 deletions src/valid/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub enum ExpressionError {
ExpectedGlobalVariable,
#[error("Not a global variable or a function argument")]
ExpectedGlobalOrArgument,
#[error("Calling an undeclared function {0:?}")]
CallToUndeclaredFunction(Handle<crate::Function>),
#[error("Needs to be an binding array instead of {0:?}")]
ExpectedBindingArrayType(Handle<crate::Type>),
#[error("Needs to be an image instead of {0:?}")]
Expand Down
2 changes: 0 additions & 2 deletions src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use bit_set::BitSet;
#[derive(Clone, Debug, thiserror::Error)]
#[cfg_attr(test, derive(PartialEq))]
pub enum CallError {
#[error("The callee is declared after the caller")]
ForwardDeclaredFunction,
#[error("Argument {index} expression is invalid")]
Argument {
index: usize,
Expand Down