mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 14:31:08 +01:00
Allow struct members without an origin
This commit is contained in:
1 parent
b5d99e133b
commit
bd9efe5915
4 files changed
+25
-13
No files matched your search
@@ -930,6 +930,7 @@ impl<W: Write> Writer<W> {
|
||||
let base_name = module.types[member.ty].name.or_index(member.ty);
|
||||
write!(self.out, "\t{} {}", base_name, name)?;
|
||||
match member.origin {
|
||||
crate::MemberOrigin::Empty => {}
|
||||
crate::MemberOrigin::BuiltIn(built_in) => {
|
||||
ResolvedBinding::BuiltIn(built_in)
|
||||
.try_fmt_decorated(&mut self.out, "")?;
|
||||
@@ -1105,6 +1106,7 @@ impl<W: Write> Writer<W> {
|
||||
let name = member.name.or_index(MemberIndex(index));
|
||||
let ty_name = module.types[member.ty].name.or_index(member.ty);
|
||||
match member.origin {
|
||||
crate::MemberOrigin::Empty => {}
|
||||
crate::MemberOrigin::BuiltIn(built_in) => {
|
||||
write!(self.out, "\t{} {}", ty_name, name)?;
|
||||
ResolvedBinding::BuiltIn(built_in)
|
||||
|
||||
@@ -83,9 +83,9 @@ pub fn map_width(word: spirv::Word) -> Result<crate::Bytes, Error> {
|
||||
.map_err(|_| Error::InvalidTypeWidth(word))
|
||||
}
|
||||
|
||||
pub fn map_builtin(word: spirv::Word) -> Result<Option<crate::BuiltIn>, Error> {
|
||||
pub fn map_builtin(word: spirv::Word) -> Result<crate::BuiltIn, Error> {
|
||||
use spirv::BuiltIn as Bi;
|
||||
Ok(Some(match spirv::BuiltIn::from_u32(word) {
|
||||
Ok(match spirv::BuiltIn::from_u32(word) {
|
||||
Some(Bi::BaseInstance) => crate::BuiltIn::BaseInstance,
|
||||
Some(Bi::BaseVertex) => crate::BuiltIn::BaseVertex,
|
||||
Some(Bi::ClipDistance) => crate::BuiltIn::ClipDistance,
|
||||
@@ -103,10 +103,6 @@ pub fn map_builtin(word: spirv::Word) -> Result<Option<crate::BuiltIn>, Error> {
|
||||
Some(Bi::LocalInvocationId) => crate::BuiltIn::LocalInvocationId,
|
||||
Some(Bi::LocalInvocationIndex) => crate::BuiltIn::LocalInvocationIndex,
|
||||
Some(Bi::WorkgroupId) => crate::BuiltIn::WorkGroupId,
|
||||
Some(Bi::WorkgroupSize) => {
|
||||
log::warn!("gl_WorkgroupSize builtin is not supported");
|
||||
return Ok(None);
|
||||
}
|
||||
_ => return Err(Error::UnsupportedBuiltIn(word)),
|
||||
}))
|
||||
})
|
||||
}
|
||||
+18
-6
@@ -147,6 +147,13 @@ struct Decoration {
|
||||
}
|
||||
|
||||
impl Decoration {
|
||||
fn debug_name(&self) -> &str {
|
||||
match self.name {
|
||||
Some(ref name) => name.as_str(),
|
||||
None => "?",
|
||||
}
|
||||
}
|
||||
|
||||
fn get_binding(&self) -> Option<crate::Binding> {
|
||||
//TODO: validate this better
|
||||
match *self {
|
||||
@@ -197,7 +204,7 @@ impl Decoration {
|
||||
offset: Some(offset),
|
||||
..
|
||||
} => Ok(crate::MemberOrigin::Offset(offset)),
|
||||
_ => Err(Error::MissingDecoration(spirv::Decoration::Offset)),
|
||||
_ => Ok(crate::MemberOrigin::Empty),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,12 +360,15 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
) -> Result<(), Error> {
|
||||
let raw = self.next()?;
|
||||
let dec_typed = spirv::Decoration::from_u32(raw).ok_or(Error::InvalidDecoration(raw))?;
|
||||
log::trace!("\t\t{:?}", dec_typed);
|
||||
log::trace!("\t\t{}: {:?}", dec.debug_name(), dec_typed);
|
||||
match dec_typed {
|
||||
spirv::Decoration::BuiltIn => {
|
||||
inst.expect(base_words + 2)?;
|
||||
let raw = self.next()?;
|
||||
dec.built_in = map_builtin(raw)?;
|
||||
match map_builtin(raw) {
|
||||
Ok(built_in) => dec.built_in = Some(built_in),
|
||||
Err(_e) => log::warn!("Unsupported builtin {}", raw),
|
||||
};
|
||||
}
|
||||
spirv::Decoration::Location => {
|
||||
inst.expect(base_words + 2)?;
|
||||
@@ -1573,6 +1583,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
if left != 0 {
|
||||
return Err(Error::InvalidOperand);
|
||||
}
|
||||
|
||||
self.future_member_decor
|
||||
.entry((id, member))
|
||||
.or_default()
|
||||
@@ -1595,6 +1606,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
inst.expect_at_least(4)?;
|
||||
let id = self.next()?;
|
||||
let member = self.next()?;
|
||||
|
||||
let mut dec = self
|
||||
.future_member_decor
|
||||
.remove(&(id, member))
|
||||
@@ -1870,8 +1882,8 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
self.switch(ModuleState::Type, inst.op)?;
|
||||
inst.expect_at_least(2)?;
|
||||
let id = self.next()?;
|
||||
let decor = self.future_decor.remove(&id);
|
||||
if let Some(ref decor) = decor {
|
||||
let parent_decor = self.future_decor.remove(&id);
|
||||
if let Some(ref decor) = parent_decor {
|
||||
if decor.block.is_some() {
|
||||
// do nothing
|
||||
}
|
||||
@@ -1897,7 +1909,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
id,
|
||||
LookupType {
|
||||
handle: module.types.append(crate::Type {
|
||||
name: decor.and_then(|dec| dec.name),
|
||||
name: parent_decor.and_then(|dec| dec.name),
|
||||
inner,
|
||||
}),
|
||||
base_id: None,
|
||||
|
||||
@@ -147,6 +147,8 @@ pub enum ArraySize {
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
|
||||
pub enum MemberOrigin {
|
||||
/// Member is local to the shader.
|
||||
Empty,
|
||||
/// Built-in shader variable.
|
||||
BuiltIn(BuiltIn),
|
||||
/// Offset within the struct.
|
||||
|
||||
Reference in new issue
Block a user