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

Introduce a new helper function,
`naga::back::spv::Writer::get_resolution_pointer_id`. Use it in
`BlockContext::write_expression_pointer`.
This commit is contained in:
Jim Blandy committed 2024-10-11 08:27:15 -07:00
1 parent 0f17ad6455
commit 436ffba77a
2 files changed
+21 -8

No files matched your search

+3 -8
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)
}
}
};
+18
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())