mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Add support for all texture types
This commit is contained in:
committed by
Dzmitry Malyshau
parent
2b475ecc96
commit
7bced3f4e8
@@ -189,7 +189,21 @@ impl Program<'_> {
|
||||
}
|
||||
FunctionCallKind::Function(name) => {
|
||||
match name.as_str() {
|
||||
"sampler2D" => {
|
||||
"sampler1D"
|
||||
| "sampler1DArray"
|
||||
| "sampler2D"
|
||||
| "sampler2DArray"
|
||||
| "sampler2DMS"
|
||||
| "sampler2DMSArray"
|
||||
| "sampler3D"
|
||||
| "samplerCube"
|
||||
| "samplerCubeArray"
|
||||
| "sampler1DShadow"
|
||||
| "sampler1DArrayShadow"
|
||||
| "sampler2DShadow"
|
||||
| "sampler2DArrayShadow"
|
||||
| "samplerCubeShadow"
|
||||
| "samplerCubeArrayShadow" => {
|
||||
if args.len() != 2 {
|
||||
return Err(ErrorKind::wrong_function_args(name, 2, args.len(), meta));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{ScalarKind, Type, TypeInner, VectorSize};
|
||||
use crate::{ImageClass, ImageDimension, ScalarKind, Type, TypeInner, VectorSize};
|
||||
|
||||
pub fn parse_type(type_name: &str) -> Option<Type> {
|
||||
match type_name {
|
||||
@@ -37,21 +37,12 @@ pub fn parse_type(type_name: &str) -> Option<Type> {
|
||||
width: 4,
|
||||
},
|
||||
}),
|
||||
"texture2D" => Some(Type {
|
||||
"sampler" | "samplerShadow" => Some(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Image {
|
||||
dim: crate::ImageDimension::D2,
|
||||
arrayed: false,
|
||||
class: crate::ImageClass::Sampled {
|
||||
kind: ScalarKind::Float,
|
||||
multi: false,
|
||||
},
|
||||
inner: TypeInner::Sampler {
|
||||
comparison: type_name == "samplerShadow",
|
||||
},
|
||||
}),
|
||||
"sampler" => Some(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Sampler { comparison: false },
|
||||
}),
|
||||
word => {
|
||||
fn kind_width_parse(ty: &str) -> Option<(ScalarKind, u8)> {
|
||||
Some(match ty {
|
||||
@@ -114,7 +105,56 @@ pub fn parse_type(type_name: &str) -> Option<Type> {
|
||||
})
|
||||
};
|
||||
|
||||
vec_parse(word).or_else(|| mat_parse(word))
|
||||
let texture_parse = |word: &str| {
|
||||
let mut iter = word.split("texture");
|
||||
|
||||
let texture_kind = |ty| {
|
||||
Some(match ty {
|
||||
"" => ScalarKind::Float,
|
||||
"i" => ScalarKind::Sint,
|
||||
"u" => ScalarKind::Uint,
|
||||
_ => return None,
|
||||
})
|
||||
};
|
||||
|
||||
let kind = iter.next()?;
|
||||
let size = iter.next()?;
|
||||
let kind = texture_kind(kind)?;
|
||||
|
||||
let sampled = |multi| ImageClass::Sampled { kind, multi };
|
||||
|
||||
let (dim, arrayed, class) = match size {
|
||||
"1D" => (ImageDimension::D1, false, sampled(false)),
|
||||
"1DArray" => (ImageDimension::D1, false, sampled(false)),
|
||||
"2D" => (ImageDimension::D2, false, sampled(false)),
|
||||
"2DArray" => (ImageDimension::D2, false, sampled(false)),
|
||||
"2DMS" => (ImageDimension::D2, true, sampled(true)),
|
||||
"2DMSArray" => (ImageDimension::D2, true, sampled(true)),
|
||||
"3D" => (ImageDimension::D3, false, sampled(false)),
|
||||
"Cube" => (ImageDimension::Cube, false, sampled(false)),
|
||||
"CubeArray" => (ImageDimension::D2, false, sampled(false)),
|
||||
"1DShadow" => (ImageDimension::D1, false, ImageClass::Depth),
|
||||
"1DArrayShadow" => (ImageDimension::D1, true, ImageClass::Depth),
|
||||
"2DShadow" => (ImageDimension::D2, false, ImageClass::Depth),
|
||||
"2DArrayShadow" => (ImageDimension::D2, true, ImageClass::Depth),
|
||||
"CubeShadow" => (ImageDimension::Cube, false, ImageClass::Depth),
|
||||
"CubeArrayShadow" => (ImageDimension::Cube, true, ImageClass::Depth),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Image {
|
||||
dim,
|
||||
arrayed,
|
||||
class,
|
||||
},
|
||||
})
|
||||
};
|
||||
|
||||
vec_parse(word)
|
||||
.or_else(|| mat_parse(word))
|
||||
.or_else(|| texture_parse(word))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user