Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[naga spv-in] OpImageWrite allows input other than Vector4. #6630

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion naga/src/front/spv/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,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