Skip to content

Commit 999358e

Browse files
committed
tiling wrap up
1 parent acfc2dd commit 999358e

21 files changed

+372
-347
lines changed

Cargo.lock

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ async-channel = "1.8"
2020
bytemuck = { version = "1.19.0", features = ["derive"] }
2121
cfg_aliases = "0.2"
2222
clap = { version = "4.5.23", features = ["derive"] }
23-
craballoc = { path = "../crabslab/crates/craballoc" } #, version = "0.2.1" }
24-
crabslab = { path = "../crabslab/crates/crabslab", default-features = false } #version = "0.6.5", default-features = false }
23+
craballoc = { version = "0.2.2" }
24+
crabslab = { version = "0.6.5", default-features = false }
2525
plotters = "0.3.7"
2626
ctor = "0.2.2"
2727
dagga = "0.2.1"

crates/renderling/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ gltf = ["dep:gltf", "dep:serde_json"]
2828
test_i8_i16_extraction = []
2929
ui = ["dep:glyph_brush", "dep:loading-bytes", "dep:lyon"]
3030
wasm = ["wgpu/fragile-send-sync-non-atomic-wasm"]
31-
test-sync = []
3231
debug-slab = []
32+
light-tiling-stats = []
3333

3434
[build-dependencies]
3535
cfg_aliases.workspace = true
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

crates/renderling/src/atlas/cpu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ mod test {
10151015
let (projection, view) = crate::camera::default_ortho2d(w as f32, h as f32);
10161016
let _camera = stage.new_camera(Camera::new(projection, view));
10171017
let texels = AtlasImage::from_path("../../img/happy_mac.png").unwrap();
1018-
let entries = stage.set_images(std::iter::repeat(texels).take(3)).unwrap();
1018+
let entries = stage.set_images(std::iter::repeat_n(texels, 3)).unwrap();
10191019
let clamp_tex = &entries[0];
10201020
let repeat_tex = &entries[1];
10211021
repeat_tex.modify(|t| {

crates/renderling/src/light.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ pub struct LightTilingDescriptor {
855855
/// Size of the [`Stage`]'s depth texture.
856856
pub depth_texture_size: UVec2,
857857
/// Configurable tile size.
858-
pub tile_size: UVec2,
858+
pub tile_size: u32,
859859
/// Array pointing to the lighting "tiles".
860860
pub tiles_array: Array<LightTile>,
861861
/// Minimum illuminance.
@@ -868,7 +868,7 @@ impl Default for LightTilingDescriptor {
868868
fn default() -> Self {
869869
Self {
870870
depth_texture_size: Default::default(),
871-
tile_size: UVec2::splat(16),
871+
tile_size: 16,
872872
tiles_array: Default::default(),
873873
minimum_illuminance_lux: 0.1,
874874
}
@@ -878,7 +878,7 @@ impl Default for LightTilingDescriptor {
878878
impl LightTilingDescriptor {
879879
/// Returns the dimensions of the grid of tiles.
880880
pub fn tile_grid_size(&self) -> UVec2 {
881-
let dims_f32 = self.depth_texture_size.as_vec2() / self.tile_size.as_vec2();
881+
let dims_f32 = self.depth_texture_size.as_vec2() / self.tile_size as f32;
882882
dims_f32.ceil().as_uvec2()
883883
}
884884

@@ -908,7 +908,7 @@ pub fn dequantize_depth_u32_to_f32(depth: u32) -> f32 {
908908
/// invocation of the light list computation.
909909
struct NextLightIndex {
910910
current_step: usize,
911-
tile_size: UVec2,
911+
tile_size: u32,
912912
lights: Array<Id<Light>>,
913913
global_id: UVec3,
914914
}
@@ -930,7 +930,7 @@ impl Iterator for NextLightIndex {
930930
impl NextLightIndex {
931931
pub fn new(
932932
global_id: UVec3,
933-
tile_size: UVec2,
933+
tile_size: u32,
934934
analytical_lights_array: Array<Id<Light>>,
935935
) -> Self {
936936
Self {
@@ -945,8 +945,8 @@ impl NextLightIndex {
945945
// Determine the xy coord of this invocation within the _tile_
946946
let frag_tile_xy = self.global_id.xy() % self.tile_size;
947947
// Determine the index of this invocation within the _tile_
948-
let offset = frag_tile_xy.y * self.tile_size.x + frag_tile_xy.x;
949-
let stride = (self.tile_size.x * self.tile_size.y) as usize;
948+
let offset = frag_tile_xy.y * self.tile_size + frag_tile_xy.x;
949+
let stride = (self.tile_size * self.tile_size) as usize;
950950
self.current_step * stride + offset as usize
951951
}
952952
}
@@ -1335,34 +1335,28 @@ mod test {
13351335
let lights_array = Array::new(0, 1);
13361336
// When there's only one light we only need one invocation to check that one light
13371337
// (per tile)
1338-
let mut next_light =
1339-
NextLightIndex::new(UVec3::new(0, 0, 0), UVec2::splat(16), lights_array);
1338+
let mut next_light = NextLightIndex::new(UVec3::new(0, 0, 0), 16, lights_array);
13401339
assert_eq!(Some(0u32.into()), next_light.next());
13411340
assert_eq!(None, next_light.next());
13421341
// The next invocation won't check anything
1343-
let mut next_light =
1344-
NextLightIndex::new(UVec3::new(1, 0, 0), UVec2::splat(16), lights_array);
1342+
let mut next_light = NextLightIndex::new(UVec3::new(1, 0, 0), 16, lights_array);
13451343
assert_eq!(None, next_light.next());
13461344
// Neither will the next row
1347-
let mut next_light =
1348-
NextLightIndex::new(UVec3::new(0, 1, 0), UVec2::splat(16), lights_array);
1345+
let mut next_light = NextLightIndex::new(UVec3::new(0, 1, 0), 16, lights_array);
13491346
assert_eq!(None, next_light.next());
13501347
}
13511348
{
13521349
let lights_array = Array::new(0, 2);
13531350
// When there's two lights we need two invocations
1354-
let mut next_light =
1355-
NextLightIndex::new(UVec3::new(0, 0, 0), UVec2::splat(16), lights_array);
1351+
let mut next_light = NextLightIndex::new(UVec3::new(0, 0, 0), 16, lights_array);
13561352
assert_eq!(Some(0u32.into()), next_light.next());
13571353
assert_eq!(None, next_light.next());
13581354
// The next invocation checks the second light
1359-
let mut next_light =
1360-
NextLightIndex::new(UVec3::new(1, 0, 0), UVec2::splat(16), lights_array);
1355+
let mut next_light = NextLightIndex::new(UVec3::new(1, 0, 0), 16, lights_array);
13611356
assert_eq!(Some(1u32.into()), next_light.next());
13621357
assert_eq!(None, next_light.next());
13631358
// The next one doesn't check anything
1364-
let mut next_light =
1365-
NextLightIndex::new(UVec3::new(2, 0, 0), UVec2::splat(16), lights_array);
1359+
let mut next_light = NextLightIndex::new(UVec3::new(2, 0, 0), 16, lights_array);
13661360
assert_eq!(None, next_light.next());
13671361
}
13681362
{
@@ -1371,8 +1365,7 @@ mod test {
13711365
let mut checked_lights = vec![];
13721366
for y in 0..16 {
13731367
for x in 0..16 {
1374-
let mut next_light =
1375-
NextLightIndex::new(UVec3::new(x, y, 0), UVec2::splat(16), lights_array);
1368+
let mut next_light = NextLightIndex::new(UVec3::new(x, y, 0), 16, lights_array);
13761369
let next_index = next_light.next_index();
13771370
let checked_light = next_light.next().unwrap();
13781371
assert_eq!(next_index, checked_light.index());

0 commit comments

Comments
 (0)