[glsl-in] Always use uint for array size (#1448)

This commit is contained in:
João Capucho
2021-10-05 18:05:47 +01:00
committed by GitHub
parent 71a75d727d
commit da00bf2be6
5 changed files with 17 additions and 6 deletions

View File

@@ -24,7 +24,18 @@ impl<'source> ParsingContext<'source> {
return Ok(Some((ArraySize::Dynamic, meta)));
}
let (constant, _) = self.parse_constant_expression(parser)?;
let (value, span) = self.parse_uint_constant(parser)?;
let constant = parser.module.constants.fetch_or_append(
crate::Constant {
name: None,
specialization: None,
inner: crate::ConstantInner::Scalar {
width: 4,
value: crate::ScalarValue::Uint(value as u64),
},
},
span,
);
let end_meta = self.expect(parser, TokenValue::RightBracket)?.meta;
meta.subsume(end_meta);
Ok(Some((ArraySize::Constant(constant), meta)))

View File

@@ -23,8 +23,8 @@ struct CameraPosition {
struct Lights {
AmbientColor: vec4<f32>;
NumLights: vec4<u32>;
PointLights: [[stride(48)]] array<PointLight,10>;
DirectionalLights: [[stride(32)]] array<DirectionalLight,1>;
PointLights: [[stride(48)]] array<PointLight,10u>;
DirectionalLights: [[stride(32)]] array<DirectionalLight,1u>;
};
[[block]]

View File

@@ -1,6 +1,6 @@
[[block]]
struct Data {
vecs: [[stride(16)]] array<vec4<f32>,42>;
vecs: [[stride(16)]] array<vec4<f32>,42u>;
};
[[group(1), binding(0)]]

View File

@@ -181,7 +181,7 @@ fn testStructConstructor() {
}
fn testArrayConstructor() {
var tree1: array<f32,1> = array<f32,1>(0.0);
var tree1: array<f32,1u> = array<f32,1u>(0.0);
}

View File

@@ -1,7 +1,7 @@
var<private> i: u32;
fn main1() {
var local: array<f32,2> = array<f32,2>(1.0, 2.0);
var local: array<f32,2u> = array<f32,2u>(1.0, 2.0);
let e2: u32 = i;
}