mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 17:44:09 +01:00
refactor(naga): Create TypeInner::is_external_image helper
This commit is contained in:
1 parent
0caefd83a2
commit
0ce78c5d0c
5 files changed
+21
-59
No files matched your search
@@ -1037,14 +1037,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// External textures are handled entirely differently, so defer entirely to that method.
|
||||
// We do so prior to calling resolve_resource_binding() below, as we even need to resolve
|
||||
// their bindings separately.
|
||||
let is_external_texture = matches!(
|
||||
*handle_ty,
|
||||
TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
}
|
||||
);
|
||||
if is_external_texture {
|
||||
if handle_ty.is_external_image() {
|
||||
return self.write_global_external_texture(module, handle, global);
|
||||
}
|
||||
|
||||
@@ -1935,11 +1928,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
) -> BackendResult {
|
||||
// External texture arguments must be expanded into separate
|
||||
// arguments for each plane and the params buffer.
|
||||
if let TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
} = module.types[arg.ty].inner
|
||||
{
|
||||
if module.types[arg.ty].inner.is_external_image() {
|
||||
return self.write_function_external_texture_argument(module, handle, index);
|
||||
}
|
||||
|
||||
@@ -4147,11 +4136,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// also know that external textures can only ever be used as an argument to another
|
||||
// function. Therefore we can simply emit each of the expanded arguments in a
|
||||
// consecutive comma-separated list.
|
||||
if let TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
} = *ty
|
||||
{
|
||||
if ty.is_external_image() {
|
||||
let plane_names = [0, 1, 2].map(|i| {
|
||||
&self.names[&func_ctx
|
||||
.external_texture_argument_key(pos, ExternalTextureNameKey::Plane(i))]
|
||||
@@ -4347,11 +4332,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// will have been expanded to separate consecutive arguments for each
|
||||
// plane and the parameters buffer. Therefore we can simply emit each of
|
||||
// the expanded global variables in a consecutive comma-separated list.
|
||||
if let TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
} = *ty
|
||||
{
|
||||
if ty.is_external_image() {
|
||||
let plane_names = [0, 1, 2].map(|i| {
|
||||
&self.names[&NameKey::ExternalTextureGlobalVariable(
|
||||
handle,
|
||||
|
||||
@@ -1232,11 +1232,7 @@ impl<W: Write> Writer<W> {
|
||||
kind: crate::ScalarKind,
|
||||
context: &ExpressionContext,
|
||||
) -> BackendResult {
|
||||
if let crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
} = *context.resolve_type(image)
|
||||
{
|
||||
if context.resolve_type(image).is_external_image() {
|
||||
write!(self.out, "{IMAGE_SIZE_EXTERNAL_FUNCTION}(")?;
|
||||
self.put_expression(image, context, true)?;
|
||||
write!(self.out, ")")?;
|
||||
@@ -1500,11 +1496,7 @@ impl<W: Write> Writer<W> {
|
||||
mut address: TexelAddress,
|
||||
context: &ExpressionContext,
|
||||
) -> BackendResult {
|
||||
if let crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
} = *context.resolve_type(image)
|
||||
{
|
||||
if context.resolve_type(image).is_external_image() {
|
||||
write!(self.out, "{IMAGE_LOAD_EXTERNAL_FUNCTION}(")?;
|
||||
self.put_expression(image, context, true)?;
|
||||
write!(self.out, ", ")?;
|
||||
@@ -8174,11 +8166,7 @@ template <typename A>
|
||||
)?;
|
||||
self.put_inline_sampler_properties(back::Level(2), sampler, options)?;
|
||||
writeln!(self.out, "{});", back::INDENT)?;
|
||||
} else if let crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
} = module.types[var.ty].inner
|
||||
{
|
||||
} else if module.types[var.ty].inner.is_external_image() {
|
||||
// Wrap the individual arguments for each external texture global
|
||||
// in a struct which can be easily passed around.
|
||||
let wrapper_name = &self.names[&NameKey::GlobalVariable(handle)];
|
||||
|
||||
+2
-14
@@ -323,13 +323,7 @@ impl Namer {
|
||||
let name = self.call_or(&arg.name, "param");
|
||||
output.insert(NameKey::FunctionArgument(fun_handle, index as u32), name);
|
||||
|
||||
if matches!(
|
||||
module.types[arg.ty].inner,
|
||||
crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
}
|
||||
) {
|
||||
if module.types[arg.ty].inner.is_external_image() {
|
||||
let base = arg.name.as_deref().unwrap_or("param");
|
||||
for &(suffix, ext_key) in ExternalTextureNameKey::ALL {
|
||||
let name = self.call(&format!("{base}_{suffix}"));
|
||||
@@ -354,13 +348,7 @@ impl Namer {
|
||||
let name = self.call_or(&var.name, "global");
|
||||
output.insert(NameKey::GlobalVariable(handle), name);
|
||||
|
||||
if matches!(
|
||||
module.types[var.ty].inner,
|
||||
crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
}
|
||||
) {
|
||||
if module.types[var.ty].inner.is_external_image() {
|
||||
let base = var.name.as_deref().unwrap_or("global");
|
||||
for &(suffix, ext_key) in ExternalTextureNameKey::ALL {
|
||||
let name = self.call(&format!("{base}_{suffix}"));
|
||||
|
||||
@@ -508,6 +508,17 @@ impl crate::TypeInner {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true if `self` is an external texture.
|
||||
pub const fn is_external_image(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Determine whether `self` automatically converts to `goal`.
|
||||
///
|
||||
/// If Naga IR's automatic conversions will convert `self` to
|
||||
|
||||
@@ -970,13 +970,7 @@ impl super::Validator {
|
||||
_ => return Err(TypeError::BindingArrayBaseTypeNotStruct(base)),
|
||||
};
|
||||
}
|
||||
if matches!(
|
||||
gctx.types[base].inner,
|
||||
crate::TypeInner::Image {
|
||||
class: crate::ImageClass::External,
|
||||
..
|
||||
}
|
||||
) {
|
||||
if gctx.types[base].inner.is_external_image() {
|
||||
// Binding arrays of external textures are not yet supported.
|
||||
// See <https://github.com/gfx-rs/wgpu/issues/8027>. Note that
|
||||
// `validate_global_var` relies on this error being raised here.
|
||||
|
||||
Reference in new issue
Block a user