Skip to content

Commit

Permalink
[naga] Validate CallResult and AtomicResult population.
Browse files Browse the repository at this point in the history
Validate that `CallResult` and `AtomicResult` expressions actually
have their values provided by `Call` and `Atomic` statements, and not
`Emit` statements.

Fixes #5740.
  • Loading branch information
jimblandy authored and teoxoy committed May 28, 2024
1 parent d9c054c commit 59cd0e9
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion naga/src/valid/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ pub enum FunctionError {
WorkgroupUniformLoadInvalidPointer(Handle<crate::Expression>),
#[error("Subgroup operation is invalid")]
InvalidSubgroup(#[from] SubgroupError),
#[error("Emit statement should not cover \"result\" expressions like {0:?}")]
EmitResult(Handle<crate::Expression>),
}

bitflags::bitflags! {
Expand Down Expand Up @@ -554,7 +556,45 @@ impl super::Validator {
match *statement {
S::Emit(ref range) => {
for handle in range.clone() {
self.emit_expression(handle, context)?;
use crate::Expression as Ex;
match context.expressions[handle] {
Ex::Literal(_)
| Ex::Constant(_)
| Ex::Override(_)
| Ex::ZeroValue(_)
| Ex::Compose { .. }
| Ex::Access { .. }
| Ex::AccessIndex { .. }
| Ex::Splat { .. }
| Ex::Swizzle { .. }
| Ex::FunctionArgument(_)
| Ex::GlobalVariable(_)
| Ex::LocalVariable(_)
| Ex::Load { .. }
| Ex::ImageSample { .. }
| Ex::ImageLoad { .. }
| Ex::ImageQuery { .. }
| Ex::Unary { .. }
| Ex::Binary { .. }
| Ex::Select { .. }
| Ex::Derivative { .. }
| Ex::Relational { .. }
| Ex::Math { .. }
| Ex::As { .. }
| Ex::ArrayLength(_)
| Ex::RayQueryGetIntersection { .. } => {
self.emit_expression(handle, context)?
}
Ex::CallResult(_)
| Ex::AtomicResult { .. }
| Ex::WorkGroupUniformLoadResult { .. }
| Ex::RayQueryProceedResult
| Ex::SubgroupBallotResult
| Ex::SubgroupOperationResult { .. } => {
return Err(FunctionError::EmitResult(handle)
.with_span_handle(handle, context.expressions));
}
}
}
}
S::Block(ref block) => {
Expand Down

0 comments on commit 59cd0e9

Please sign in to comment.