mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
[naga spv-out] Simplify Writer::get_pointer_id
.
Simplify the definition of `naga:🔙:spv::Writer::get_pointer_id`
by using `get_type_id`'s ability to handle `LocalType::Pointer`.
This means that `get_pointer_id` is no longer fallible, and no longer
needs a type arena. Simplify callers, as well as the
`BlockContext::get_pointer_id` convenience function.
This commit is contained in:
parent
908e8353a8
commit
5c6b00886e
@ -381,7 +381,6 @@ impl<'w> BlockContext<'w> {
|
||||
}
|
||||
};
|
||||
let (id, variable) = self.writer.promote_access_expression_to_variable(
|
||||
&self.ir_module.types,
|
||||
result_type_id,
|
||||
base_id,
|
||||
base_ty,
|
||||
|
@ -226,7 +226,7 @@ impl<'w> BlockContext<'w> {
|
||||
let element_type_id = match self.ir_module.types[global.ty].inner {
|
||||
crate::TypeInner::BindingArray { base, size: _ } => {
|
||||
let class = map_storage_class(global.space);
|
||||
self.get_pointer_id(base, class)?
|
||||
self.get_pointer_id(base, class)
|
||||
}
|
||||
_ => return Err(Error::Validation("array length expression case-5")),
|
||||
};
|
||||
|
@ -667,13 +667,8 @@ impl BlockContext<'_> {
|
||||
.get_constant_scalar(crate::Literal::I32(scope as _))
|
||||
}
|
||||
|
||||
fn get_pointer_id(
|
||||
&mut self,
|
||||
handle: Handle<crate::Type>,
|
||||
class: spirv::StorageClass,
|
||||
) -> Result<Word, Error> {
|
||||
self.writer
|
||||
.get_pointer_id(&self.ir_module.types, handle, class)
|
||||
fn get_pointer_id(&mut self, handle: Handle<crate::Type>, class: spirv::StorageClass) -> Word {
|
||||
self.writer.get_pointer_id(handle, class)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,6 @@ impl Writer {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn promote_access_expression_to_variable(
|
||||
&mut self,
|
||||
ir_types: &UniqueArena<crate::Type>,
|
||||
result_type_id: Word,
|
||||
container_id: Word,
|
||||
container_ty: Handle<crate::Type>,
|
||||
@ -149,8 +148,7 @@ impl Writer {
|
||||
element_ty: Handle<crate::Type>,
|
||||
block: &mut Block,
|
||||
) -> Result<(Word, LocalVariable), Error> {
|
||||
let pointer_type_id =
|
||||
self.get_pointer_id(ir_types, container_ty, spirv::StorageClass::Function)?;
|
||||
let pointer_type_id = self.get_pointer_id(container_ty, spirv::StorageClass::Function);
|
||||
|
||||
let variable = {
|
||||
let id = self.id_gen.next();
|
||||
@ -170,7 +168,7 @@ impl Writer {
|
||||
|
||||
let element_pointer_id = self.id_gen.next();
|
||||
let element_pointer_type_id =
|
||||
self.get_pointer_id(ir_types, element_ty, spirv::StorageClass::Function)?;
|
||||
self.get_pointer_id(element_ty, spirv::StorageClass::Function);
|
||||
block.body.push(Instruction::access_chain(
|
||||
element_pointer_type_id,
|
||||
element_pointer_id,
|
||||
@ -267,27 +265,13 @@ impl Writer {
|
||||
|
||||
pub(super) fn get_pointer_id(
|
||||
&mut self,
|
||||
arena: &UniqueArena<crate::Type>,
|
||||
handle: Handle<crate::Type>,
|
||||
class: spirv::StorageClass,
|
||||
) -> Result<Word, Error> {
|
||||
let ty_id = self.get_type_id(LookupType::Handle(handle));
|
||||
if let crate::TypeInner::Pointer { .. } = arena[handle].inner {
|
||||
return Ok(ty_id);
|
||||
}
|
||||
let lookup_type = LookupType::Local(LocalType::Pointer {
|
||||
) -> Word {
|
||||
self.get_type_id(LookupType::Local(LocalType::Pointer {
|
||||
base: handle,
|
||||
class,
|
||||
});
|
||||
Ok(if let Some(&id) = self.lookup_type.get(&lookup_type) {
|
||||
id
|
||||
} else {
|
||||
let id = self.id_gen.next();
|
||||
let instruction = Instruction::type_pointer(id, class, ty_id);
|
||||
instruction.to_words(&mut self.logical_layout.declarations);
|
||||
self.lookup_type.insert(lookup_type, id);
|
||||
id
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
pub(super) fn get_uint_type_id(&mut self) -> Word {
|
||||
@ -369,11 +353,7 @@ impl Writer {
|
||||
let class = spirv::StorageClass::Input;
|
||||
let handle_ty = ir_module.types[argument.ty].inner.is_handle();
|
||||
let argument_type_id = match handle_ty {
|
||||
true => self.get_pointer_id(
|
||||
&ir_module.types,
|
||||
argument.ty,
|
||||
spirv::StorageClass::UniformConstant,
|
||||
)?,
|
||||
true => self.get_pointer_id(argument.ty, spirv::StorageClass::UniformConstant),
|
||||
false => self.get_type_id(LookupType::Handle(argument.ty)),
|
||||
};
|
||||
|
||||
@ -604,8 +584,7 @@ impl Writer {
|
||||
gv.handle_id = id;
|
||||
} else if global_needs_wrapper(ir_module, var) {
|
||||
let class = map_storage_class(var.space);
|
||||
let pointer_type_id =
|
||||
self.get_pointer_id(&ir_module.types, var.ty, class)?;
|
||||
let pointer_type_id = self.get_pointer_id(var.ty, class);
|
||||
let index_id = self.get_index_constant(0);
|
||||
let id = self.id_gen.next();
|
||||
prelude.body.push(Instruction::access_chain(
|
||||
@ -664,11 +643,9 @@ impl Writer {
|
||||
}
|
||||
|
||||
let init_word = variable.init.map(|constant| context.cached[constant]);
|
||||
let pointer_type_id = context.writer.get_pointer_id(
|
||||
&ir_module.types,
|
||||
variable.ty,
|
||||
spirv::StorageClass::Function,
|
||||
)?;
|
||||
let pointer_type_id = context
|
||||
.writer
|
||||
.get_pointer_id(variable.ty, spirv::StorageClass::Function);
|
||||
let instruction = Instruction::variable(
|
||||
pointer_type_id,
|
||||
id,
|
||||
@ -1468,7 +1445,7 @@ impl Writer {
|
||||
binding: &crate::Binding,
|
||||
) -> Result<Word, Error> {
|
||||
let id = self.id_gen.next();
|
||||
let pointer_type_id = self.get_pointer_id(&ir_module.types, ty, class)?;
|
||||
let pointer_type_id = self.get_pointer_id(ty, class);
|
||||
Instruction::variable(pointer_type_id, id, class, None)
|
||||
.to_words(&mut self.logical_layout.declarations);
|
||||
|
||||
@ -1801,7 +1778,7 @@ impl Writer {
|
||||
if substitute_inner_type_lookup.is_some() {
|
||||
inner_type_id
|
||||
} else {
|
||||
self.get_pointer_id(&ir_module.types, global_variable.ty, class)?
|
||||
self.get_pointer_id(global_variable.ty, class)
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user