Skip to content

Commit b7f069e

Browse files
committed
abi layout: minor code cleanups
1 parent 8bdec82 commit b7f069e

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ fn trans_intrinsic_type<'tcx>(
10081008
}
10091009
}
10101010

1011-
/// A struct with multiple fields of the same kind
1012-
/// Used for `#[spirv(vector)]` and `#[spirv(matrix)]`
1011+
/// A struct with multiple fields of the same kind.
1012+
/// Used for `#[spirv(vector)]` and `#[spirv(matrix)]`.
10131013
fn trans_glam_like_struct<'tcx>(
10141014
cx: &CodegenCx<'tcx>,
10151015
span: Span,

tests/difftests/tests/lang/abi/vector_layout/cpu/src/cpu_driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::glam_features::GlamFeatures;
2-
use crate::layout::{LAYOUT_COUNT, LAYOUT_LEN, eval_layouts};
2+
use crate::layout::{LAYOUT_LEN, LAYOUT_RANGE, eval_layouts};
33
use difftest::config::Config;
44

55
pub fn run(glam_feature: GlamFeatures) {
66
glam_feature.assert();
77
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
88
let mut out = vec![0; LAYOUT_LEN];
9-
for gid in 0..LAYOUT_COUNT {
9+
for gid in LAYOUT_RANGE {
1010
eval_layouts(gid as u32, &mut out);
1111
}
1212
config.write_result(&out).unwrap()

tests/difftests/tests/lang/abi/vector_layout/cpu/src/layout.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::mem::offset_of;
2+
use core::ops::Range;
23
use experiments::*;
34
use spirv_std::glam::*;
45

@@ -29,11 +30,12 @@ macro_rules! write_layout {
2930
};
3031
}
3132

32-
/// gid is checked between `0..LAYOUT_COUNT`
33-
pub const LAYOUT_COUNT: usize = 0x60;
33+
/// gid is checked within this range. Note this is a range, so it **must be +1 from the max entry you use**.
34+
/// (Must always start at 0, `InclusiveRange` doesn't work due to constness)
35+
pub const LAYOUT_RANGE: Range<usize> = 0..0x56;
3436
/// at byte offset 0x100 * N starts layout N
3537
pub const LAYOUT_MAX_SIZE: usize = 0x100 / 0x4;
36-
pub const LAYOUT_LEN: usize = LAYOUT_COUNT * LAYOUT_MAX_SIZE;
38+
pub const LAYOUT_LEN: usize = LAYOUT_RANGE.end * LAYOUT_MAX_SIZE;
3739

3840
pub fn eval_layouts(gid: u32, out: &mut [u32]) {
3941
let mut offset = BumpAlloc(gid as usize * LAYOUT_MAX_SIZE);
@@ -120,6 +122,7 @@ pub fn eval_layouts(gid: u32, out: &mut [u32]) {
120122
0x54 => write_layout!(out, offset, BVec4(x, y, z, w)),
121123
0x55 => write_layout!(out, offset, BVec4A()),
122124

125+
// IMPORTANT: when adding new rows, remember to adjust `LAYOUT_COUNT` to be the maximum + 1!
123126
_ => {}
124127
}
125128
}

tests/difftests/tests/lang/abi/vector_layout/cpu/src/shader_driver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::glam_features::GlamFeatures;
2-
use crate::layout::{LAYOUT_COUNT, LAYOUT_LEN};
2+
use crate::layout::{LAYOUT_LEN, LAYOUT_RANGE};
33
use difftest::config::Config;
44
use difftest::scaffold::compute::{BufferConfig, RustComputeShader, WgpuComputeTestMultiBuffer};
55

66
pub fn run(glam_feature: GlamFeatures) {
77
glam_feature.assert();
88
let config = Config::from_path(std::env::args().nth(1).unwrap()).unwrap();
9+
assert_eq!(0, LAYOUT_RANGE.start);
910
let test = WgpuComputeTestMultiBuffer::new(
1011
RustComputeShader::default(),
11-
[LAYOUT_COUNT as u32, 1, 1],
12+
[LAYOUT_RANGE.end as u32, 1, 1],
1213
Vec::from(&[BufferConfig::writeback(LAYOUT_LEN * size_of::<u32>())]),
1314
);
1415
test.run_test(&config).unwrap();

0 commit comments

Comments
 (0)