tiletree work queue system works
This commit is contained in:
@@ -350,9 +350,9 @@ pub fn compile_raytracing_blas(
|
||||
compute_pass.set_pipeline(tiletree_pipeline);
|
||||
compute_pass.set_bind_group(0, &tiletree_bind_group, &[]);
|
||||
compute_pass.dispatch_workgroups(
|
||||
(tape.subdivision / 4) * 128,
|
||||
(tape.subdivision / 4) * 128,
|
||||
(tape.subdivision / 4) * 6,
|
||||
tape.subdivision,
|
||||
tape.subdivision,
|
||||
tape.subdivision,
|
||||
);
|
||||
|
||||
updated_blases.push(key.tape);
|
||||
|
||||
@@ -417,9 +417,9 @@ impl TapeAllocator {
|
||||
sample_count: 1,
|
||||
view_formats: &[TextureFormat::Rgb10a2Unorm],
|
||||
size: Extent3d {
|
||||
width: tape.subdivision * 128,
|
||||
height: tape.subdivision * 128,
|
||||
depth_or_array_layers: tape.subdivision * 6,
|
||||
width: tape.subdivision * 4 * 2 * 2,
|
||||
height: tape.subdivision * 4 * 2 * 2,
|
||||
depth_or_array_layers: tape.subdivision * 4 * 2 * 2,
|
||||
},
|
||||
});
|
||||
let texture_view = texture.create_view(&TextureViewDescriptor {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import package::render::aabb::PackedAabb;
|
||||
import package::render::metadata_types::TapeMetadata;
|
||||
import package::render::implicit::{interval_scene, scene, gradient_scene};
|
||||
import package::render::util::{NAN, encode_internal_pos, internal_to_external_pos};
|
||||
import package::render::util::{NAN, decode_internal_pos, encode_internal_pos, internal_to_external_pos};
|
||||
import package::render::spatial_implicit::{SPATIAL_SCENE_OFFSET, INVERSE_SPATIAL_SCENE_SCALE};
|
||||
|
||||
enable wgpu_binding_array;
|
||||
@@ -26,39 +26,182 @@ var spatial_texture: texture_3d<f32>;
|
||||
@group(0) @binding(3)
|
||||
var tiletree: texture_storage_3d<rgb10a2unorm, write>;
|
||||
|
||||
const SOLVE_ARRAY_LEN: u32 = 16*16*16;
|
||||
|
||||
const INFINITE_LOOP_LIMIT: i32 = 512;
|
||||
const SUBDIVIDE_LOOPS: i32 = 2;
|
||||
|
||||
var<workgroup> to_solve: array<u32, SOLVE_ARRAY_LEN/2>;
|
||||
var<workgroup> low_head: atomic<u32>;
|
||||
var<workgroup> high_head: atomic<u32>;
|
||||
|
||||
var<immediate> push_constants: PushConstants;
|
||||
|
||||
struct ComputeInput {
|
||||
@builtin(workgroup_id) workgroup_id: vec3u,
|
||||
@builtin(local_invocation_id) local_invocaion_id: vec3u,
|
||||
@builtin(global_invocation_id) global_invocation_id: vec3u
|
||||
@builtin(local_invocation_id) local_invocation_id: vec3u,
|
||||
}
|
||||
|
||||
fn in_aabb(metadata: TapeMetadata, internal_pos: vec3f) -> bool {
|
||||
let low_corner = internal_to_external_pos(internal_pos + vec3(0.0), metadata);
|
||||
let high_corner = internal_to_external_pos(internal_pos + vec3(1.0), metadata);
|
||||
|
||||
let interval = interval_scene(
|
||||
vec4(low_corner, metadata.time),
|
||||
vec4(high_corner, metadata.time),
|
||||
);
|
||||
|
||||
return (interval.x < 0) && (interval.y > 0);
|
||||
}
|
||||
|
||||
fn get_solve_array(index: u32) -> u32 {
|
||||
if (index % 2 == 0) {
|
||||
return to_solve[index / 2] & 0x0000FFFFu;
|
||||
} else {
|
||||
return to_solve[index / 2] >> 16u;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_solve_array_pair(index: u32, value_low: u32, value_high: u32) {
|
||||
to_solve[index / 2] = (value_low & 0x0000FFFFu) | (value_high << 16u);
|
||||
}
|
||||
|
||||
fn create_work_item_pair(increasing: bool, subdivision_log2: u32, uinternal_pos: vec3u) {
|
||||
var index: u32;
|
||||
if (increasing) {
|
||||
index = atomicAdd(&low_head, 2);
|
||||
} else {
|
||||
index = atomicSub(&high_head, 2);
|
||||
}
|
||||
var pos = encode_internal_pos(uinternal_pos, subdivision_log2);
|
||||
set_solve_array_pair(index, pos, pos + 1);
|
||||
}
|
||||
|
||||
fn create_work_items_batch(increasing: bool, subdivision_log2: u32, uinternal_pos_local: vec3u) {
|
||||
var index: u32;
|
||||
var direction: i32;
|
||||
if (increasing) {
|
||||
index = atomicAdd(&low_head, 8);
|
||||
direction = 1;
|
||||
} else {
|
||||
index = atomicSub(&high_head, 8);
|
||||
direction = -1;
|
||||
}
|
||||
set_solve_array_pair(u32(i32(index) + (0 * direction)),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(0,0,0), subdivision_log2),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(1,0,0), subdivision_log2)
|
||||
);
|
||||
set_solve_array_pair(u32(i32(index) + (2 * direction)),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(0,1,0), subdivision_log2),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(1,1,0), subdivision_log2)
|
||||
);
|
||||
set_solve_array_pair(u32(i32(index) + (4 * direction)),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(0,0,1), subdivision_log2),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(1,0,1), subdivision_log2)
|
||||
);
|
||||
set_solve_array_pair(u32(i32(index) + (6 * direction)),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(0,1,1), subdivision_log2),
|
||||
encode_internal_pos(uinternal_pos_local + vec3(1,1,1), subdivision_log2)
|
||||
);
|
||||
}
|
||||
|
||||
fn get_work_item(increasing: bool) -> u32 {
|
||||
var index: u32;
|
||||
if (increasing) {
|
||||
index = atomicAdd(&high_head, 1) + 1;
|
||||
} else {
|
||||
index = atomicSub(&low_head, 1) - 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
fn reset_stack(increasing: bool) {
|
||||
if (increasing) {
|
||||
atomicStore(&low_head, 0);
|
||||
} else {
|
||||
atomicStore(&high_head, SOLVE_ARRAY_LEN - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// subgroupElect is not implemented in naga
|
||||
fn subgroup_elect() -> bool {
|
||||
let index = subgroupExclusiveAdd(1);
|
||||
return subgroupBroadcastFirst(index) == index;
|
||||
}
|
||||
|
||||
@compute @workgroup_size(4, 4, 4)
|
||||
fn main(compute_input: ComputeInput) {
|
||||
var metadata = tape_metadata_buffer.metadata[push_constants.metadata_buffer_offset];
|
||||
|
||||
let uinternal_pos = compute_input.global_invocation_id;
|
||||
let internal_pos = vec3f(uinternal_pos);
|
||||
|
||||
// subgroupElect is not implemented in naga
|
||||
//let index = subgroupExclusiveAdd(1);
|
||||
//let elect = subgroupBroadcastFirst(index) == index;
|
||||
|
||||
var exit = 0;
|
||||
//if elect {
|
||||
let base_index = encode_internal_pos(uinternal_pos / vec3u(128, 128, 6), metadata.subdivision_log2);
|
||||
if subgroup_elect() {
|
||||
let base_index = encode_internal_pos(compute_input.workgroup_id, metadata.subdivision_log2);
|
||||
let aabb = &aabb_buffer.aabbs[push_constants.aabb_buffer_offset + base_index];
|
||||
if bitcast<u32>(aabb.min_x) == 0xFFC00000u {
|
||||
exit = 1;
|
||||
}
|
||||
//}
|
||||
//exit = subgroupBroadcastFirst(exit);
|
||||
}
|
||||
exit = subgroupBroadcastFirst(exit);
|
||||
if exit == 1 {
|
||||
return;
|
||||
}
|
||||
|
||||
let position = internal_to_external_pos(internal_pos / vec3(128.0, 128.0, 6.0), metadata);
|
||||
metadata.subdivision_log2 += 2;
|
||||
|
||||
var rolling_subdivision = 2u;
|
||||
var global_offset = compute_input.workgroup_id * vec3(4, 4, 4);
|
||||
|
||||
var increasing = false;
|
||||
|
||||
if (subgroup_elect()) {
|
||||
reset_stack(increasing);
|
||||
}
|
||||
workgroupBarrier();
|
||||
|
||||
if (compute_input.local_invocation_id.x % 2 == 0) {
|
||||
create_work_item_pair(increasing, rolling_subdivision, compute_input.local_invocation_id);
|
||||
}
|
||||
|
||||
increasing = !increasing;
|
||||
|
||||
for (var i = 0; i < SUBDIVIDE_LOOPS; i++) {
|
||||
workgroupBarrier();
|
||||
if (subgroup_elect()) {
|
||||
reset_stack(increasing);
|
||||
}
|
||||
workgroupBarrier();
|
||||
|
||||
for (var infini = 0; infini < INFINITE_LOOP_LIMIT; infini++) {
|
||||
let item = get_work_item(increasing);
|
||||
if (item >= SOLVE_ARRAY_LEN) {
|
||||
break;
|
||||
}
|
||||
let solve_item = get_solve_array(item);
|
||||
let uinternal_pos_local = decode_internal_pos(solve_item, rolling_subdivision);
|
||||
let uinternal_pos_global = uinternal_pos_local + global_offset;
|
||||
let aabb = in_aabb(metadata, vec3f(uinternal_pos_global));
|
||||
if (aabb) {
|
||||
create_work_items_batch(increasing, rolling_subdivision + 1, uinternal_pos_local * 2);
|
||||
}
|
||||
}
|
||||
|
||||
metadata.subdivision_log2 += 1;
|
||||
rolling_subdivision += 1;
|
||||
global_offset *= 2;
|
||||
increasing = !increasing;
|
||||
}
|
||||
|
||||
workgroupBarrier();
|
||||
|
||||
for (var infini = 0; infini < INFINITE_LOOP_LIMIT; infini++) {
|
||||
let item = get_work_item(increasing);
|
||||
if (item >= SOLVE_ARRAY_LEN) {
|
||||
break;
|
||||
}
|
||||
let solve_item = get_solve_array(item);
|
||||
let uinternal_pos_local = decode_internal_pos(solve_item, rolling_subdivision);
|
||||
let uinternal_pos_global = uinternal_pos_local + global_offset;
|
||||
let position = internal_to_external_pos(vec3f(uinternal_pos_global), metadata);
|
||||
//let grad = gradient_scene(vec4(position, metadata.time));
|
||||
|
||||
const EPSILON = 0.001;
|
||||
@@ -70,5 +213,6 @@ fn main(compute_input: ComputeInput) {
|
||||
);
|
||||
let grad = normalize(n - (scene(vec4(position, metadata.time))));
|
||||
|
||||
textureStore(tiletree, uinternal_pos, vec4(grad * 0.5 + 0.5, 0.0));
|
||||
textureStore(tiletree, uinternal_pos_global, vec4(grad * 0.5 + 0.5, 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user