Skip to content

Commit 59cd0e9

Browse files
jimblandyteoxoy
authored andcommitted
[naga] Validate CallResult and AtomicResult population.
Validate that `CallResult` and `AtomicResult` expressions actually have their values provided by `Call` and `Atomic` statements, and not `Emit` statements. Fixes #5740.
1 parent d9c054c commit 59cd0e9

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

naga/src/valid/function.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ pub enum FunctionError {
172172
WorkgroupUniformLoadInvalidPointer(Handle<crate::Expression>),
173173
#[error("Subgroup operation is invalid")]
174174
InvalidSubgroup(#[from] SubgroupError),
175+
#[error("Emit statement should not cover \"result\" expressions like {0:?}")]
176+
EmitResult(Handle<crate::Expression>),
175177
}
176178

177179
bitflags::bitflags! {
@@ -554,7 +556,45 @@ impl super::Validator {
554556
match *statement {
555557
S::Emit(ref range) => {
556558
for handle in range.clone() {
557-
self.emit_expression(handle, context)?;
559+
use crate::Expression as Ex;
560+
match context.expressions[handle] {
561+
Ex::Literal(_)
562+
| Ex::Constant(_)
563+
| Ex::Override(_)
564+
| Ex::ZeroValue(_)
565+
| Ex::Compose { .. }
566+
| Ex::Access { .. }
567+
| Ex::AccessIndex { .. }
568+
| Ex::Splat { .. }
569+
| Ex::Swizzle { .. }
570+
| Ex::FunctionArgument(_)
571+
| Ex::GlobalVariable(_)
572+
| Ex::LocalVariable(_)
573+
| Ex::Load { .. }
574+
| Ex::ImageSample { .. }
575+
| Ex::ImageLoad { .. }
576+
| Ex::ImageQuery { .. }
577+
| Ex::Unary { .. }
578+
| Ex::Binary { .. }
579+
| Ex::Select { .. }
580+
| Ex::Derivative { .. }
581+
| Ex::Relational { .. }
582+
| Ex::Math { .. }
583+
| Ex::As { .. }
584+
| Ex::ArrayLength(_)
585+
| Ex::RayQueryGetIntersection { .. } => {
586+
self.emit_expression(handle, context)?
587+
}
588+
Ex::CallResult(_)
589+
| Ex::AtomicResult { .. }
590+
| Ex::WorkGroupUniformLoadResult { .. }
591+
| Ex::RayQueryProceedResult
592+
| Ex::SubgroupBallotResult
593+
| Ex::SubgroupOperationResult { .. } => {
594+
return Err(FunctionError::EmitResult(handle)
595+
.with_span_handle(handle, context.expressions));
596+
}
597+
}
558598
}
559599
}
560600
S::Block(ref block) => {

0 commit comments

Comments
 (0)