Skip to content

Commit

Permalink
[naga spv-in] OpImageWrite allows input other than Vector4. (#6630)
Browse files Browse the repository at this point in the history
* fix(naga-spv-in): Image write value type is invalid.

* fix(naga-spv-in): input vector 4 may case error

* fix(naga-spv-in): Incorrect swizzle pattern for vector size 3.
  • Loading branch information
ReinaS-64892 authored Jan 24, 2025
1 parent 0fc0b35 commit 5386d38
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion naga/src/front/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,51 @@ impl<I: Iterator<Item = u32>> super::Frontend<I> {

let value_lexp = self.lookup_expression.lookup(value_id)?;
let value = self.get_expr_handle(value_id, value_lexp, ctx, emitter, block, body_idx);
let value_type = self.lookup_type.lookup(value_lexp.type_id)?.handle;

// In hlsl etc, the write value may not be the vector 4.
let expanded_value = match ctx.module.types[value_type].inner {
crate::TypeInner::Scalar(_) => Some(crate::Expression::Splat {
value,
size: crate::VectorSize::Quad,
}),
crate::TypeInner::Vector { size, .. } => match size {
crate::VectorSize::Bi => Some(crate::Expression::Swizzle {
size: crate::VectorSize::Quad,
vector: value,
pattern: [
crate::SwizzleComponent::X,
crate::SwizzleComponent::Y,
crate::SwizzleComponent::Y,
crate::SwizzleComponent::Y,
],
}),
crate::VectorSize::Tri => Some(crate::Expression::Swizzle {
size: crate::VectorSize::Quad,
vector: value,
pattern: [
crate::SwizzleComponent::X,
crate::SwizzleComponent::Y,
crate::SwizzleComponent::Z,
crate::SwizzleComponent::Z,
],
}),
crate::VectorSize::Quad => None,
},
_ => return Err(Error::InvalidVectorType(value_type)),
};

let value_patched = if let Some(s) = expanded_value {
ctx.expressions.append(s, crate::Span::default())
} else {
value
};

Ok(crate::Statement::ImageStore {
image: image_lexp.handle,
coordinate,
array_index,
value,
value: value_patched,
})
}

Expand Down

0 comments on commit 5386d38

Please sign in to comment.