shitty radix

This commit is contained in:
2026-09-28 23:01:31 +02:00
parent e673c6dc0d
commit 3124978e3f
15 changed files with 1403 additions and 314 deletions
+41 -15
View File
@@ -1,7 +1,7 @@
use std::num::NonZero;
use bytemuck::Zeroable;
use wgpu::{BindGroup, BindGroupLayout, Buffer, BufferUsages, CommandEncoder, ComputePipeline, Device, Queue, ShaderStages};
use wgpu::{BindGroup, BindGroupLayout, Buffer, BufferUsages, CommandEncoder, ComputePipeline, Device, Queue, ShaderStages, util::DeviceExt};
use crate::voxel_cache::{data::{CacheNodeRequest, CacheResponse, ColorPoolElement, LocationPoolElement, StructurePoolElement}, producer_interface::CacheProducerInterface, request_buffer::RequestBuffer, structure_table::StructureTable, usage_buffer::UsageBuffer};
@@ -21,6 +21,7 @@ pub struct VoxelCache<const N: usize>
queue: Queue,
structure_pool: Buffer,
location_pool: Buffer,
depth_pool: Buffer,
attributes_pools: Vec<Buffer>,
pub structure_table: StructureTable,
@@ -84,6 +85,12 @@ where
mapped_at_creation: false,
});
let depth_pool = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
label: Some("Depth pool"),
contents: bytemuck::cast_slice(&vec![0xFFFFFFFFu32; cache_size]),
usage: BufferUsages::STORAGE,
});
// Create attribttues
let attributes_pools =
attributes.iter().enumerate()
@@ -227,18 +234,18 @@ where
},
count: None,
},
// Sorted requests
// Depth pool
wgpu::BindGroupLayoutEntry {
binding: 3,
visibility: ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: true },
ty: wgpu::BufferBindingType::Storage { read_only: false },
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
},
// LRU List
// Sorted requests
wgpu::BindGroupLayoutEntry {
binding: 4,
visibility: ShaderStages::COMPUTE,
@@ -249,10 +256,21 @@ where
},
count: None,
},
// Usage buffer
// LRU List
wgpu::BindGroupLayoutEntry {
binding: 5,
visibility: ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
},
// Usage buffer
wgpu::BindGroupLayoutEntry {
binding: 6,
visibility: ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: false },
has_dynamic_offset: false,
@@ -262,7 +280,7 @@ where
},
// pools request count
wgpu::BindGroupLayoutEntry {
binding: 6,
binding: 7,
visibility: ShaderStages::COMPUTE,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Storage { read_only: true },
@@ -296,24 +314,29 @@ where
binding: 2,
resource: location_pool.as_entire_binding(),
},
// Sorted requests
// Depth pool
wgpu::BindGroupEntry {
binding: 3,
resource: depth_pool.as_entire_binding(),
},
// Sorted requests
wgpu::BindGroupEntry {
binding: 4,
resource: request_buffer.index_buffer().as_entire_binding(),
},
// LRU list
wgpu::BindGroupEntry {
binding: 4,
binding: 5,
resource: usage_buffer.sort_buffer().as_entire_binding(),
},
// Usage buffer
wgpu::BindGroupEntry {
binding: 5,
binding: 6,
resource: usage_buffer.usage_buffer().as_entire_binding(),
},
// Pools request count
wgpu::BindGroupEntry {
binding: 6,
binding: 7,
resource: request_buffer.request_count_buffer().as_entire_binding(),
},
],
@@ -397,10 +420,11 @@ where
@group(0) @binding(0) var<storage, read_write> structure_pool: array<StructurePoolElement>;
@group(0) @binding(1) var<storage, read_write> attributes_pools: binding_array<AttributeArray, {attribute_count}>;
@group(0) @binding(2) var<storage, read_write> location_pool: array<LocationPoolElement>;
@group(0) @binding(3) var<storage, read> sorted_requests: array<u32>;
@group(0) @binding(4) var<storage, read> lru_list: array<u32>;
@group(0) @binding(5) var<storage, read_write> usage_buffer: array<u32>;
@group(0) @binding(6) var<storage, read> pools_request_count: u32;
@group(0) @binding(3) var<storage, read_write> depth_pool: array<u32>;
@group(0) @binding(4) var<storage, read> sorted_requests: array<u32>;
@group(0) @binding(5) var<storage, read> lru_list: array<u32>;
@group(0) @binding(6) var<storage, read_write> usage_buffer: array<u32>;
@group(0) @binding(7) var<storage, read> pools_request_count: u32;
@group(1) @binding(0) var<storage, read_write> structure_table_pointers: array<u32>;
@group(1) @binding(1) var<storage, read_write> structure_table_sorted_requests: array<u32>;
@@ -661,9 +685,11 @@ where
if(requests_wb[index].child_index == 0xFFFFFFFF)
{{
structure_table_pointers[requests_wb[index].node_index] = new_pointer;
depth_pool[overwritten_element] = 0;
}}else if usage_buffer[requests_wb[index].node_index] != parameters.frame_timestamp + 1
{{
structure_pool[requests_wb[index].node_index].pointers[requests_wb[index].child_index] = new_pointer;
depth_pool[overwritten_element] = depth_pool[requests_wb[index].node_index] + 1;
}}
}}
@@ -765,6 +791,7 @@ where
device,
structure_pool,
attributes_pools,
depth_pool,
location_pool,
request_buffer,
usage_buffer,
@@ -868,7 +895,6 @@ where
// Sort requests, reset request buffers to count requests
self.usage_buffer.sort_usage(encoder);
self.request_buffer.sort_requests(encoder);
self.structure_table
.request_buffer_mut()
.sort_requests(encoder);