[naga spv-out] Introduce Writer::get_resolution_pointer_id.

Introduce a new helper function,
`naga:🔙:spv::Writer::get_resolution_pointer_id`. Use it in
`BlockContext::write_expression_pointer`.
This commit is contained in:
Jim Blandy 2024-10-10 12:51:57 -07:00
parent 0f17ad6455
commit 436ffba77a
2 changed files with 21 additions and 8 deletions

View File

@ -1721,14 +1721,9 @@ impl<'w> BlockContext<'w> {
let resolution = &self.fun_info[expr_handle].ty;
match type_adjustment {
AccessTypeAdjustment::None => self.writer.get_expression_type_id(resolution),
AccessTypeAdjustment::IntroducePointer(class) => match *resolution {
TypeResolution::Handle(handle) => self.writer.get_pointer_id(handle, class),
TypeResolution::Value(_) => {
unreachable!(
"IntroducePointer should only be used with images and samplers"
);
}
},
AccessTypeAdjustment::IntroducePointer(class) => {
self.writer.get_resolution_pointer_id(resolution, class)
}
}
};

View File

@ -274,6 +274,24 @@ impl Writer {
}))
}
/// Return a SPIR-V type for a pointer to `resolution`.
///
/// The given `resolution` must be one that we can represent
/// either as a `LocalType::Pointer` or `LocalType::LocalPointer`.
pub(super) fn get_resolution_pointer_id(
&mut self,
resolution: &TypeResolution,
class: spirv::StorageClass,
) -> Word {
match *resolution {
TypeResolution::Handle(handle) => self.get_pointer_id(handle, class),
TypeResolution::Value(ref inner) => {
let base = NumericType::from_inner(inner).unwrap();
self.get_type_id(LookupType::Local(LocalType::LocalPointer { base, class }))
}
}
}
pub(super) fn get_uint_type_id(&mut self) -> Word {
let local_type = LocalType::Numeric(NumericType::Scalar(crate::Scalar::U32));
self.get_type_id(local_type.into())