mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[spv] force treating the built-in scalar types as unsigned
This commit is contained in:
committed by
Dzmitry Malyshau
parent
6c1f4ac590
commit
66d994566c
@@ -2367,11 +2367,40 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
crate::StorageAccess::empty()
|
||||
};
|
||||
|
||||
let ty = match binding {
|
||||
// SPIR-V only cares about some of the built-in types being integer.
|
||||
// Naga requires them to be strictly unsigned, so we have to patch it.
|
||||
Some(crate::Binding::BuiltIn(built_in)) => {
|
||||
let scalar_kind = module.types[lookup_type.handle].inner.scalar_kind();
|
||||
let needs_uint = match built_in {
|
||||
crate::BuiltIn::BaseInstance
|
||||
| crate::BuiltIn::BaseVertex
|
||||
| crate::BuiltIn::InstanceIndex
|
||||
| crate::BuiltIn::SampleIndex
|
||||
| crate::BuiltIn::VertexIndex => true,
|
||||
_ => false,
|
||||
};
|
||||
if needs_uint && scalar_kind == Some(crate::ScalarKind::Sint) {
|
||||
log::warn!("Treating {:?} as unsigned", built_in);
|
||||
module.types.fetch_or_append(crate::Type {
|
||||
name: None,
|
||||
inner: crate::TypeInner::Scalar {
|
||||
kind: crate::ScalarKind::Uint,
|
||||
width: 4,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
lookup_type.handle
|
||||
}
|
||||
}
|
||||
_ => lookup_type.handle,
|
||||
};
|
||||
|
||||
let var = crate::GlobalVariable {
|
||||
name: dec.name,
|
||||
class,
|
||||
binding,
|
||||
ty: lookup_type.handle,
|
||||
ty,
|
||||
init,
|
||||
interpolation: dec.interpolation,
|
||||
storage_access,
|
||||
|
||||
BIN
test-data/spv/quad.vert.spv
Normal file
BIN
test-data/spv/quad.vert.spv
Normal file
Binary file not shown.
@@ -173,7 +173,7 @@ fn convert_boids() {
|
||||
|
||||
#[cfg(feature = "spv-in")]
|
||||
#[test]
|
||||
fn convert_cube() {
|
||||
fn convert_cube_spv() {
|
||||
let mut validator = naga::proc::Validator::new();
|
||||
let vs = load_spv("cube.vert.spv");
|
||||
validator.validate(&vs).unwrap();
|
||||
@@ -232,6 +232,25 @@ fn convert_cube() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "spv-in")]
|
||||
#[test]
|
||||
fn convert_quad_spv() {
|
||||
let mut validator = naga::proc::Validator::new();
|
||||
// check that integer `gl_VertexIndex` is treated as unsigned
|
||||
let vs = load_spv("quad.vert.spv");
|
||||
validator.validate(&vs).unwrap();
|
||||
#[cfg(feature = "msl-out")]
|
||||
{
|
||||
use naga::back::msl;
|
||||
let options = msl::Options {
|
||||
lang_version: (1, 0),
|
||||
spirv_cross_compatibility: false,
|
||||
binding_map: msl::BindingMap::default(),
|
||||
};
|
||||
msl::write_string(&vs, &options).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "glsl-in")]
|
||||
#[test]
|
||||
#[ignore]
|
||||
|
||||
Reference in New Issue
Block a user