Skip to content

Commit

Permalink
fix(naga-spv-in): Image write value type is invalid.
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinaS-64892 committed Jan 20, 2025
1 parent 87b3ca2 commit 7e14590
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion naga/src/front/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,64 @@ 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);

// In hlsl etc, the write value may not be the vector 4.
let swizzled_value = match ctx.type_arena[image_ty].inner {
crate::TypeInner::Image {
dim: _,
arrayed: _,
class: crate::ImageClass::Storage { format, access: _ },
} => match format {
crate::StorageFormat::Rg8Unorm
| crate::StorageFormat::Rg8Snorm
| crate::StorageFormat::Rg8Uint
| crate::StorageFormat::Rg8Sint
| crate::StorageFormat::Rg16Uint
| crate::StorageFormat::Rg16Sint
| crate::StorageFormat::Rg16Float
| crate::StorageFormat::Rg32Uint
| crate::StorageFormat::Rg32Sint
| crate::StorageFormat::Rg32Float => Some(crate::Expression::Swizzle {
size: crate::VectorSize::Quad,
vector: value,
pattern: [
crate::SwizzleComponent::X,
crate::SwizzleComponent::Y,
crate::SwizzleComponent::Y,
crate::SwizzleComponent::Y,
],
}),

crate::StorageFormat::R8Unorm
| crate::StorageFormat::R8Snorm
| crate::StorageFormat::R8Uint
| crate::StorageFormat::R8Sint
| crate::StorageFormat::R16Uint
| crate::StorageFormat::R16Sint
| crate::StorageFormat::R16Float
| crate::StorageFormat::R32Uint
| crate::StorageFormat::R32Sint
| crate::StorageFormat::R32Float
| crate::StorageFormat::R16Unorm
| crate::StorageFormat::R16Snorm => Some(crate::Expression::Splat {
value,
size: crate::VectorSize::Quad,
}),
_ => None,
},
_ => None,
};

let value_patched = if let Some(s) = swizzled_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 7e14590

Please sign in to comment.