diff --git a/shaders/out/voxel.spv b/shaders/out/voxel.spv index 0bc44fe..a938871 100644 Binary files a/shaders/out/voxel.spv and b/shaders/out/voxel.spv differ diff --git a/shaders/voxel.slang b/shaders/voxel.slang index 78a080d..e81a363 100644 --- a/shaders/voxel.slang +++ b/shaders/voxel.slang @@ -155,7 +155,7 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_ Hit h; Span s; - bool hit = tracer.trace(stacks[stack_index], h, r, s); + bool hit = tracer.trace(stack_index, h, r, s); ToroidalStructureTableTracer.Cursor cursor = table_tracer.begin(r, s); Cell cell; diff --git a/shaders/voxel_cache.slang b/shaders/voxel_cache.slang index 2bf786d..6f13d94 100644 --- a/shaders/voxel_cache.slang +++ b/shaders/voxel_cache.slang @@ -134,6 +134,9 @@ public interface IVoxelHit public bool shouldHit(VoxelCacheParameters parameters, uint32_t node_index, uint32_t child_index); } +static const uint32_t WG_COUNT = 256; +groupshared uint32_t stack[5 * WG_COUNT]; + public struct VoxelCacheTracer> : IVoxelCache { typedef VoxelTraceStack GroupSharedData; @@ -144,7 +147,7 @@ public struct VoxelCacheTracer> : IVoxelCache public H voxel_hit; public VoxelCacheParameters parameters; - public bool trace(uint32_t root, inout VoxelTraceStack stack, Ray r, L lod, float offset_t, out Hit v) + public bool trace(uint32_t root, uint32_t thread_id, Ray r, L lod, float offset_t, out Hit v) { // Ray mirroring r.origin += float3(1.); @@ -174,7 +177,7 @@ public struct VoxelCacheTracer> : IVoxelCache { this.parameters.usage_buffer[current_node_index] = this.frame_timestamp; } - stack.stack[10 - scale_exp / 2] = current_node_index; + stack[thread_id + WG_COUNT * (10 - scale_exp / 2)] = current_node_index; [loop] for (uint32_t iter = 0; iter < 500; iter++) @@ -186,7 +189,7 @@ public struct VoxelCacheTracer> : IVoxelCache { scale_exp -= 2; current_node_index = current_node.pointer(); - stack.stack[10 - scale_exp / 2] = current_node_index; + stack[thread_id + WG_COUNT * (10 - scale_exp / 2)] = current_node_index; child_index = get_children_index(pos, scale_exp) ^ child_mirror; current_node = this.parameters.structure_pool[current_node_index].pointers[child_index]; // Write usage @@ -254,7 +257,7 @@ public struct VoxelCacheTracer> : IVoxelCache } scale_exp = 23 - common_depth; - current_node_index = stack.stack[10 - scale_exp / 2]; + current_node_index = stack[thread_id + WG_COUNT * (10 - scale_exp / 2)]; } v.hit = false; diff --git a/shaders/voxel_tracing.slang b/shaders/voxel_tracing.slang index d65dcbb..fb3a9d3 100644 --- a/shaders/voxel_tracing.slang +++ b/shaders/voxel_tracing.slang @@ -57,8 +57,7 @@ public interface IVoxelCache { // The voxel cache tracer needs to store a small stack. // Keeping it in registers is wastefull thus using groupshared memory is the best option - associatedtype GroupSharedData; - public bool trace(uint32_t root, inout GroupSharedData data, Ray r, L lod, float offset_t, out Hit v); + public bool trace(uint32_t root, uint32_t thread_id, Ray r, L lod, float offset_t, out Hit v); } public struct Tracer @@ -68,7 +67,7 @@ public struct Tracer public C cache; public L lod; - public bool trace(inout C.GroupSharedData gsData, out Hit h, Ray r, Span s) + public bool trace(uint32_t thread_id, out Hit h, Ray r, Span s) { /* loop: next cell -> cache.trace -> early out */ S.Cursor cursor = this.structure.begin(r, s); @@ -81,7 +80,7 @@ public struct Tracer while (this.structure.next(cursor, cell)) { - if (cache.trace(cell.cache_pointer, gsData, cell.local_ray, lod, cell.t, h)) + if (cache.trace(cell.cache_pointer, thread_id, cell.local_ray, lod, cell.t, h)) { return true; }