mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Cast gl_VertexIndex to SInt (#332)
* [glsl-in] Cast gl_VertexIndex to SInt * [glsl-in] Use conversion cast (gl_VertexIndex) - Also cast gl_InstanceIndex * [glsl-in] Simplify global var lookup * [glsl-in] Fix missing comma
This commit is contained in:
@@ -9,7 +9,12 @@ use super::token::TokenMetadata;
|
||||
|
||||
impl Program {
|
||||
pub fn lookup_variable(&mut self, name: &str) -> Result<Option<Handle<Expression>>, ErrorKind> {
|
||||
let mut expression: Option<Handle<Expression>> = None;
|
||||
if let Some(local_var) = self.context.lookup_local_var(name) {
|
||||
return Ok(Some(local_var));
|
||||
}
|
||||
if let Some(global_var) = self.context.lookup_global_var_exps.get(name) {
|
||||
return Ok(Some(*global_var));
|
||||
}
|
||||
match name {
|
||||
"gl_Position" => {
|
||||
#[cfg(feature = "glsl-validate")]
|
||||
@@ -19,29 +24,26 @@ impl Program {
|
||||
return Err(ErrorKind::VariableNotAvailable(name.into()));
|
||||
}
|
||||
};
|
||||
let h = self
|
||||
.module
|
||||
.global_variables
|
||||
.fetch_or_append(GlobalVariable {
|
||||
name: Some(name.into()),
|
||||
class: if self.shader_stage == ShaderStage::Vertex {
|
||||
StorageClass::Output
|
||||
} else {
|
||||
StorageClass::Input
|
||||
let h = self.module.global_variables.append(GlobalVariable {
|
||||
name: Some(name.into()),
|
||||
class: if self.shader_stage == ShaderStage::Vertex {
|
||||
StorageClass::Output
|
||||
} else {
|
||||
StorageClass::Input
|
||||
},
|
||||
binding: Some(Binding::BuiltIn(BuiltIn::Position)),
|
||||
ty: self.module.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: VectorSize::Quad,
|
||||
kind: ScalarKind::Float,
|
||||
width: 4,
|
||||
},
|
||||
binding: Some(Binding::BuiltIn(BuiltIn::Position)),
|
||||
ty: self.module.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Vector {
|
||||
size: VectorSize::Quad,
|
||||
kind: ScalarKind::Float,
|
||||
width: 4,
|
||||
},
|
||||
}),
|
||||
init: None,
|
||||
interpolation: None,
|
||||
storage_access: StorageAccess::empty(),
|
||||
});
|
||||
}),
|
||||
init: None,
|
||||
interpolation: None,
|
||||
storage_access: StorageAccess::empty(),
|
||||
});
|
||||
self.lookup_global_variables.insert(name.into(), h);
|
||||
let exp = self
|
||||
.context
|
||||
@@ -49,7 +51,7 @@ impl Program {
|
||||
.append(Expression::GlobalVariable(h));
|
||||
self.context.lookup_global_var_exps.insert(name.into(), exp);
|
||||
|
||||
expression = Some(exp);
|
||||
Ok(Some(exp))
|
||||
}
|
||||
"gl_VertexIndex" => {
|
||||
#[cfg(feature = "glsl-validate")]
|
||||
@@ -59,32 +61,36 @@ impl Program {
|
||||
return Err(ErrorKind::VariableNotAvailable(name.into()));
|
||||
}
|
||||
};
|
||||
let h = self
|
||||
.module
|
||||
.global_variables
|
||||
.fetch_or_append(GlobalVariable {
|
||||
name: Some(name.into()),
|
||||
class: StorageClass::Input,
|
||||
binding: Some(Binding::BuiltIn(BuiltIn::VertexIndex)),
|
||||
ty: self.module.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Scalar {
|
||||
kind: ScalarKind::Uint,
|
||||
width: 4,
|
||||
},
|
||||
}),
|
||||
init: None,
|
||||
interpolation: None,
|
||||
storage_access: StorageAccess::empty(),
|
||||
});
|
||||
let h = self.module.global_variables.append(GlobalVariable {
|
||||
name: Some(name.into()),
|
||||
class: StorageClass::Input,
|
||||
binding: Some(Binding::BuiltIn(BuiltIn::VertexIndex)),
|
||||
ty: self.module.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Scalar {
|
||||
kind: ScalarKind::Uint,
|
||||
width: 4,
|
||||
},
|
||||
}),
|
||||
init: None,
|
||||
interpolation: None,
|
||||
storage_access: StorageAccess::empty(),
|
||||
});
|
||||
self.lookup_global_variables.insert(name.into(), h);
|
||||
let exp = self
|
||||
let mut expr = self
|
||||
.context
|
||||
.expressions
|
||||
.append(Expression::GlobalVariable(h));
|
||||
self.context.lookup_global_var_exps.insert(name.into(), exp);
|
||||
expr = self.context.expressions.append(Expression::As {
|
||||
expr,
|
||||
kind: ScalarKind::Sint,
|
||||
convert: true,
|
||||
});
|
||||
self.context
|
||||
.lookup_global_var_exps
|
||||
.insert(name.into(), expr);
|
||||
|
||||
expression = Some(exp);
|
||||
Ok(Some(expr))
|
||||
}
|
||||
"gl_InstanceIndex" => {
|
||||
#[cfg(feature = "glsl-validate")]
|
||||
@@ -94,44 +100,38 @@ impl Program {
|
||||
return Err(ErrorKind::VariableNotAvailable(name.into()));
|
||||
}
|
||||
};
|
||||
let h = self
|
||||
.module
|
||||
.global_variables
|
||||
.fetch_or_append(GlobalVariable {
|
||||
name: Some(name.into()),
|
||||
class: StorageClass::Input,
|
||||
binding: Some(Binding::BuiltIn(BuiltIn::InstanceIndex)),
|
||||
ty: self.module.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Scalar {
|
||||
kind: ScalarKind::Uint,
|
||||
width: 4,
|
||||
},
|
||||
}),
|
||||
init: None,
|
||||
interpolation: None,
|
||||
storage_access: StorageAccess::empty(),
|
||||
});
|
||||
let h = self.module.global_variables.append(GlobalVariable {
|
||||
name: Some(name.into()),
|
||||
class: StorageClass::Input,
|
||||
binding: Some(Binding::BuiltIn(BuiltIn::InstanceIndex)),
|
||||
ty: self.module.types.fetch_or_append(Type {
|
||||
name: None,
|
||||
inner: TypeInner::Scalar {
|
||||
kind: ScalarKind::Uint,
|
||||
width: 4,
|
||||
},
|
||||
}),
|
||||
init: None,
|
||||
interpolation: None,
|
||||
storage_access: StorageAccess::empty(),
|
||||
});
|
||||
self.lookup_global_variables.insert(name.into(), h);
|
||||
let exp = self
|
||||
let mut expr = self
|
||||
.context
|
||||
.expressions
|
||||
.append(Expression::GlobalVariable(h));
|
||||
self.context.lookup_global_var_exps.insert(name.into(), exp);
|
||||
expr = self.context.expressions.append(Expression::As {
|
||||
expr,
|
||||
kind: ScalarKind::Sint,
|
||||
convert: true,
|
||||
});
|
||||
self.context
|
||||
.lookup_global_var_exps
|
||||
.insert(name.into(), expr);
|
||||
|
||||
expression = Some(exp);
|
||||
Ok(Some(expr))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if let Some(expression) = expression {
|
||||
Ok(Some(expression))
|
||||
} else if let Some(local_var) = self.context.lookup_local_var(name) {
|
||||
Ok(Some(local_var))
|
||||
} else if let Some(global_var) = self.context.lookup_global_var_exps.get(name) {
|
||||
Ok(Some(*global_var))
|
||||
} else {
|
||||
Ok(None)
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user