Skip to content

Commit

Permalink
Error if the uniformity requirements for a barrier aren't met
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab authored and jimblandy committed Jan 10, 2023
1 parent 5b4e946 commit e6e94d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/valid/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,25 @@ impl FunctionInfo {
ExitFlags::empty()
},
},
S::Barrier(_) => FunctionUniformity {
result: Uniformity {
non_uniform_result: None,
requirements: UniformityRequirements::WORK_GROUP_BARRIER,
},
exit: ExitFlags::empty(),
},
S::Barrier(_) => {
#[cfg(feature = "validate")]
if self
.flags
.contains(super::ValidationFlags::CONTROL_FLOW_UNIFORMITY)
{
if let Some(cause) = disruptor {
return Err(FunctionError::NonUniformBarrier(cause)
.with_span_static(span, "Barrier creation"));
}
}
FunctionUniformity {
result: Uniformity {
non_uniform_result: None,
requirements: UniformityRequirements::WORK_GROUP_BARRIER,
},
exit: ExitFlags::empty(),
}
}
S::Block(ref b) => {
self.process_block(b, other_functions, disruptor, expression_arena)?
}
Expand Down Expand Up @@ -1154,7 +1166,7 @@ fn uniform_control_flow() {
assert_eq!(info[derivative_expr].ref_count, 1);
assert_eq!(info[non_uniform_global], GlobalUse::READ);

let stmt_emit3 = S::Emit(emit_range_globals);
let stmt_emit3 = S::Emit(emit_range_globals.clone());
let stmt_return_non_uniform = S::Return {
value: Some(non_uniform_global_expr),
};
Expand Down Expand Up @@ -1201,4 +1213,25 @@ fn uniform_control_flow() {
}),
);
assert_eq!(info[non_uniform_global], GlobalUse::READ | GlobalUse::WRITE);

let stmt_emit5 = S::Emit(emit_range_globals.clone());
let stmt_if_non_uniform = S::If {
condition: non_uniform_global_expr,
accept: vec![S::Barrier(crate::Barrier::empty())].into(),
reject: crate::Block::new(),
};
assert_eq!(
info.process_block(
&vec![stmt_emit5, stmt_if_non_uniform].into(),
&[],
None,
&expressions
),
Err(
FunctionError::NonUniformBarrier(UniformityDisruptor::Expression(
non_uniform_global_expr
))
.with_span()
),
);
}
2 changes: 2 additions & 0 deletions src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ pub enum FunctionError {
Handle<crate::Expression>,
UniformityDisruptor,
),
#[error("Required uniformity of barrier is not fulfilled because of {0:?}")]
NonUniformBarrier(UniformityDisruptor),
#[error("Functions that are not entry points cannot have `@location` or `@builtin` attributes on their arguments: \"{name}\" has attributes")]
PipelineInputRegularFunction { name: String },
#[error("Functions that are not entry points cannot have `@location` or `@builtin` attributes on their return value types")]
Expand Down

0 comments on commit e6e94d6

Please sign in to comment.