mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[spv-out] Use bit flags in LocalImageType, instead of bools.
This commit is contained in:
committed by
Dzmitry Malyshau
parent
b226c5108a
commit
b35e40ec59
@@ -224,20 +224,21 @@ impl super::Instruction {
|
||||
id: Word,
|
||||
sampled_type_id: Word,
|
||||
dim: spirv::Dim,
|
||||
depth: bool,
|
||||
arrayed: bool,
|
||||
multisampled: bool,
|
||||
sampled: bool,
|
||||
flags: super::ImageTypeFlags,
|
||||
image_format: spirv::ImageFormat,
|
||||
) -> Self {
|
||||
let mut instruction = Self::new(Op::TypeImage);
|
||||
instruction.set_result(id);
|
||||
instruction.add_operand(sampled_type_id);
|
||||
instruction.add_operand(dim as u32);
|
||||
instruction.add_operand(depth as u32);
|
||||
instruction.add_operand(arrayed as u32);
|
||||
instruction.add_operand(multisampled as u32);
|
||||
instruction.add_operand(if sampled { 1 } else { 2 });
|
||||
instruction.add_operand(flags.contains(super::ImageTypeFlags::DEPTH) as u32);
|
||||
instruction.add_operand(flags.contains(super::ImageTypeFlags::ARRAYED) as u32);
|
||||
instruction.add_operand(flags.contains(super::ImageTypeFlags::MULTISAMPLED) as u32);
|
||||
instruction.add_operand(if flags.contains(super::ImageTypeFlags::SAMPLED) {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
});
|
||||
instruction.add_operand(image_format as u32);
|
||||
instruction
|
||||
}
|
||||
|
||||
@@ -174,43 +174,49 @@ fn map_dim(dim: crate::ImageDimension) -> spirv::Dim {
|
||||
struct LocalImageType {
|
||||
sampled_type: crate::ScalarKind,
|
||||
dim: spirv::Dim,
|
||||
depth: bool,
|
||||
arrayed: bool,
|
||||
multisampled: bool,
|
||||
sampled: bool,
|
||||
flags: ImageTypeFlags,
|
||||
image_format: spirv::ImageFormat,
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// Flags corresponding to the boolean(-ish) parameters to OpTypeImage.
|
||||
pub struct ImageTypeFlags: u8 {
|
||||
const DEPTH = 0x1;
|
||||
const ARRAYED = 0x2;
|
||||
const MULTISAMPLED = 0x4;
|
||||
const SAMPLED = 0x8;
|
||||
}
|
||||
}
|
||||
|
||||
impl LocalImageType {
|
||||
/// Construct a `LocalImageType` from the fields of a `TypeInner::Image`.
|
||||
fn from_inner(dim: crate::ImageDimension, arrayed: bool, class: crate::ImageClass) -> Self {
|
||||
let make_flags = |multi: bool, other: ImageTypeFlags| -> ImageTypeFlags {
|
||||
let mut flags = other;
|
||||
flags.set(ImageTypeFlags::ARRAYED, arrayed);
|
||||
flags.set(ImageTypeFlags::MULTISAMPLED, multi);
|
||||
flags
|
||||
};
|
||||
|
||||
let dim = map_dim(dim);
|
||||
|
||||
match class {
|
||||
crate::ImageClass::Sampled { kind, multi } => LocalImageType {
|
||||
sampled_type: kind,
|
||||
dim,
|
||||
depth: false,
|
||||
arrayed,
|
||||
multisampled: multi,
|
||||
sampled: true,
|
||||
flags: make_flags(multi, ImageTypeFlags::SAMPLED),
|
||||
image_format: spirv::ImageFormat::Unknown,
|
||||
},
|
||||
crate::ImageClass::Depth { multi } => LocalImageType {
|
||||
sampled_type: crate::ScalarKind::Float,
|
||||
dim,
|
||||
depth: true,
|
||||
arrayed,
|
||||
multisampled: multi,
|
||||
sampled: true,
|
||||
flags: make_flags(multi, ImageTypeFlags::DEPTH | ImageTypeFlags::SAMPLED),
|
||||
image_format: spirv::ImageFormat::Unknown,
|
||||
},
|
||||
crate::ImageClass::Storage { format, access: _ } => LocalImageType {
|
||||
sampled_type: crate::ScalarKind::from(format),
|
||||
dim,
|
||||
depth: false,
|
||||
arrayed,
|
||||
multisampled: false,
|
||||
sampled: false,
|
||||
flags: make_flags(false, ImageTypeFlags::empty()),
|
||||
image_format: format.into(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -687,16 +687,7 @@ impl Writer {
|
||||
pointer_class: None,
|
||||
};
|
||||
let type_id = self.get_type_id(LookupType::Local(local_type));
|
||||
Instruction::type_image(
|
||||
id,
|
||||
type_id,
|
||||
image.dim,
|
||||
image.depth,
|
||||
image.arrayed,
|
||||
image.multisampled,
|
||||
image.sampled,
|
||||
image.image_format,
|
||||
)
|
||||
Instruction::type_image(id, type_id, image.dim, image.flags, image.image_format)
|
||||
}
|
||||
LocalType::Sampler => Instruction::type_sampler(id),
|
||||
LocalType::SampledImage { image_type_id } => {
|
||||
|
||||
Reference in New Issue
Block a user