tiletrees?
This commit is contained in:
@@ -104,6 +104,7 @@ impl RaytracingSceneBindings {
|
|||||||
&mut self.instances.aabb_buffers.dirty,
|
&mut self.instances.aabb_buffers.dirty,
|
||||||
&mut self.instances.tape_metadata_buffers.dirty,
|
&mut self.instances.tape_metadata_buffers.dirty,
|
||||||
&mut self.instances.spatial_textures.dirty,
|
&mut self.instances.spatial_textures.dirty,
|
||||||
|
&mut self.instances.tiletrees.dirty,
|
||||||
&mut self.assets.textures.dirty,
|
&mut self.assets.textures.dirty,
|
||||||
] {
|
] {
|
||||||
invalid |= core::mem::replace(dirty, false);
|
invalid |= core::mem::replace(dirty, false);
|
||||||
@@ -173,6 +174,19 @@ impl RaytracingSceneBindings {
|
|||||||
spatial_textures.push(fallback_texture.d3.texture_view.deref());
|
spatial_textures.push(fallback_texture.d3.texture_view.deref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut tiletrees: Vec<_> = self
|
||||||
|
.instances
|
||||||
|
.tiletrees
|
||||||
|
.iter()
|
||||||
|
.map(|texture| match texture {
|
||||||
|
Some(view) => view.deref(),
|
||||||
|
None => fallback_texture.d3.texture_view.deref(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
if tiletrees.is_empty() {
|
||||||
|
tiletrees.push(fallback_texture.d3.texture_view.deref());
|
||||||
|
}
|
||||||
|
|
||||||
let (mut textures, mut samplers): (Vec<_>, Vec<_>) = self
|
let (mut textures, mut samplers): (Vec<_>, Vec<_>) = self
|
||||||
.assets
|
.assets
|
||||||
.textures
|
.textures
|
||||||
@@ -215,6 +229,8 @@ impl RaytracingSceneBindings {
|
|||||||
tape_metadata_buffers.as_slice(),
|
tape_metadata_buffers.as_slice(),
|
||||||
spatial_textures.as_slice(),
|
spatial_textures.as_slice(),
|
||||||
&self.spatial_texture_sampler,
|
&self.spatial_texture_sampler,
|
||||||
|
tiletrees.as_slice(),
|
||||||
|
&self.tiletree_sampler,
|
||||||
textures.as_slice(),
|
textures.as_slice(),
|
||||||
samplers.as_slice(),
|
samplers.as_slice(),
|
||||||
self.assets.materials.binding().unwrap(),
|
self.assets.materials.binding().unwrap(),
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ use super::{
|
|||||||
pub const MAX_MESH_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap();
|
pub const MAX_MESH_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap();
|
||||||
pub const MAX_TAPE_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap();
|
pub const MAX_TAPE_SLAB_COUNT: NonZeroU32 = NonZeroU32::new(500).unwrap();
|
||||||
pub const MAX_SPATIAL_TEXTURE_COUNT: NonZeroU32 = NonZeroU32::new(5000).unwrap();
|
pub const MAX_SPATIAL_TEXTURE_COUNT: NonZeroU32 = NonZeroU32::new(5000).unwrap();
|
||||||
|
pub const MAX_TILETREE_COUNT: NonZeroU32 = NonZeroU32::new(5000).unwrap();
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
|
#[derive(Clone, Copy, Default, PartialEq, Pod, Zeroable)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -51,8 +52,8 @@ pub struct GpuInstanceGeometryIds {
|
|||||||
pub struct GpuInstanceTapeIds {
|
pub struct GpuInstanceTapeIds {
|
||||||
aabb_buffer_id: u32,
|
aabb_buffer_id: u32,
|
||||||
aabb_buffer_offset: u32,
|
aabb_buffer_offset: u32,
|
||||||
aabb_count: u32,
|
|
||||||
spatial_texture_id: u32,
|
spatial_texture_id: u32,
|
||||||
|
tiletree_id: u32,
|
||||||
metadata_buffer_id: u32,
|
metadata_buffer_id: u32,
|
||||||
metadata_buffer_offset: u32,
|
metadata_buffer_offset: u32,
|
||||||
}
|
}
|
||||||
@@ -103,7 +104,7 @@ pub enum BlasKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MeshBuffers = (BufferId, BufferId);
|
type MeshBuffers = (BufferId, BufferId);
|
||||||
type TapeBuffers = (BufferId, BufferId, TextureId);
|
type TapeBuffers = (BufferId, BufferId, TextureId, TextureId);
|
||||||
|
|
||||||
pub enum Buffers {
|
pub enum Buffers {
|
||||||
Mesh(MeshBuffers),
|
Mesh(MeshBuffers),
|
||||||
@@ -264,6 +265,7 @@ pub struct InstanceState {
|
|||||||
pub aabb_buffers: RetainedBindingArray<BufferId, Buffer>,
|
pub aabb_buffers: RetainedBindingArray<BufferId, Buffer>,
|
||||||
pub tape_metadata_buffers: RetainedBindingArray<BufferId, Buffer>,
|
pub tape_metadata_buffers: RetainedBindingArray<BufferId, Buffer>,
|
||||||
pub spatial_textures: RetainedBindingArray<TextureId, TextureView>,
|
pub spatial_textures: RetainedBindingArray<TextureId, TextureView>,
|
||||||
|
pub tiletrees: RetainedBindingArray<TextureId, TextureView>,
|
||||||
pub transforms: AtomicSparseBufferVec<GpuTransform>,
|
pub transforms: AtomicSparseBufferVec<GpuTransform>,
|
||||||
pub previous_frame_transforms: AtomicSparseBufferVec<GpuTransform>,
|
pub previous_frame_transforms: AtomicSparseBufferVec<GpuTransform>,
|
||||||
pub geometry_ids: AtomicSparseBufferVec<GpuInstanceGeometryIds>,
|
pub geometry_ids: AtomicSparseBufferVec<GpuInstanceGeometryIds>,
|
||||||
@@ -290,6 +292,7 @@ impl InstanceState {
|
|||||||
aabb_buffers: RetainedBindingArray::new(),
|
aabb_buffers: RetainedBindingArray::new(),
|
||||||
tape_metadata_buffers: RetainedBindingArray::new(),
|
tape_metadata_buffers: RetainedBindingArray::new(),
|
||||||
spatial_textures: RetainedBindingArray::new(),
|
spatial_textures: RetainedBindingArray::new(),
|
||||||
|
tiletrees: RetainedBindingArray::new(),
|
||||||
transforms: storage_buffer("solari_transforms"),
|
transforms: storage_buffer("solari_transforms"),
|
||||||
previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"),
|
previous_frame_transforms: storage_buffer("solari_previous_frame_transforms"),
|
||||||
geometry_ids: storage_buffer("solari_geometry_ids"),
|
geometry_ids: storage_buffer("solari_geometry_ids"),
|
||||||
@@ -404,11 +407,13 @@ impl InstanceState {
|
|||||||
self.vertex_buffers.release(&vertex_key);
|
self.vertex_buffers.release(&vertex_key);
|
||||||
self.index_buffers.release(&index_key);
|
self.index_buffers.release(&index_key);
|
||||||
}
|
}
|
||||||
for (aabb_key, metadata_key, spatial_key) in core::mem::take(&mut self.retired_tape_buffers)
|
for (aabb_key, metadata_key, spatial_key, tiletree_key) in
|
||||||
|
core::mem::take(&mut self.retired_tape_buffers)
|
||||||
{
|
{
|
||||||
self.aabb_buffers.release(&aabb_key);
|
self.aabb_buffers.release(&aabb_key);
|
||||||
self.tape_metadata_buffers.release(&metadata_key);
|
self.tape_metadata_buffers.release(&metadata_key);
|
||||||
self.spatial_textures.release(&spatial_key);
|
self.spatial_textures.release(&spatial_key);
|
||||||
|
self.tiletrees.release(&tiletree_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,12 +709,14 @@ impl InstanceState {
|
|||||||
Some(aabb_slice),
|
Some(aabb_slice),
|
||||||
Some(metadata_slice),
|
Some(metadata_slice),
|
||||||
Some(spatial_texture),
|
Some(spatial_texture),
|
||||||
|
Some(tiletree),
|
||||||
Some(material_slot),
|
Some(material_slot),
|
||||||
Some(blas_address),
|
Some(blas_address),
|
||||||
) = (
|
) = (
|
||||||
inputs.tape_allocator.tape_aabb_slice(&instance.tape),
|
inputs.tape_allocator.tape_aabb_slice(&instance.tape),
|
||||||
inputs.tape_allocator.tape_metadata_slice(&instance.tape),
|
inputs.tape_allocator.tape_metadata_slice(&instance.tape),
|
||||||
inputs.tape_allocator.tape_spatial_texture(&instance.tape),
|
inputs.tape_allocator.tape_spatial_texture(&instance.tape),
|
||||||
|
inputs.tape_allocator.tape_tiletree(&instance.tape),
|
||||||
material_slot,
|
material_slot,
|
||||||
blas_address,
|
blas_address,
|
||||||
)
|
)
|
||||||
@@ -760,6 +767,18 @@ impl InstanceState {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tiletree_key = tiletree.0.id();
|
||||||
|
let tiletree_capacity = MAX_TILETREE_COUNT.get();
|
||||||
|
if !self.tiletrees.has_room(&tiletree_key, spatial_capacity) {
|
||||||
|
once!(warn!(
|
||||||
|
"Solari scene needs more than {} tiletrees. Instances past that limit will not \
|
||||||
|
be rendered.",
|
||||||
|
MAX_TILETREE_COUNT.get()
|
||||||
|
));
|
||||||
|
self.deactivate_tape_instance(lights, entity, instance);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let previous_buffers = instance.buffers.take();
|
let previous_buffers = instance.buffers.take();
|
||||||
let aabb_buffer_id = self
|
let aabb_buffer_id = self
|
||||||
.aabb_buffers
|
.aabb_buffers
|
||||||
@@ -776,18 +795,26 @@ impl InstanceState {
|
|||||||
.acquire(spatial_texture_key, spatial_capacity, || {
|
.acquire(spatial_texture_key, spatial_capacity, || {
|
||||||
spatial_texture.1.clone()
|
spatial_texture.1.clone()
|
||||||
})
|
})
|
||||||
.expect("spatial vslab binding array had room but handed out no slot");
|
.expect("spatial texture binding array had room but handed out no slot");
|
||||||
instance.buffers = Some((aabb_buffer_key, metadata_buffer_key, spatial_texture_key));
|
let tiletree_id = self
|
||||||
|
.tiletrees
|
||||||
|
.acquire(tiletree_key, tiletree_capacity, || tiletree.1.clone())
|
||||||
|
.expect("tiletree binding array had room but handed out no slot");
|
||||||
|
instance.buffers = Some((
|
||||||
|
aabb_buffer_key,
|
||||||
|
metadata_buffer_key,
|
||||||
|
spatial_texture_key,
|
||||||
|
tiletree_key,
|
||||||
|
));
|
||||||
self.release_tape_buffers(previous_buffers);
|
self.release_tape_buffers(previous_buffers);
|
||||||
|
|
||||||
let aabb_count = (aabb_slice.range.len()) as u32;
|
|
||||||
self.tape_ids.grow_and_set(
|
self.tape_ids.grow_and_set(
|
||||||
slot,
|
slot,
|
||||||
GpuInstanceTapeIds {
|
GpuInstanceTapeIds {
|
||||||
aabb_buffer_id,
|
aabb_buffer_id,
|
||||||
aabb_buffer_offset: aabb_slice.range.start,
|
aabb_buffer_offset: aabb_slice.range.start,
|
||||||
aabb_count,
|
|
||||||
spatial_texture_id,
|
spatial_texture_id,
|
||||||
|
tiletree_id,
|
||||||
metadata_buffer_id,
|
metadata_buffer_id,
|
||||||
metadata_buffer_offset: metadata_slice.range.start,
|
metadata_buffer_offset: metadata_slice.range.start,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ use super::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::scene::{
|
use crate::scene::{
|
||||||
binder::instances::{MAX_SPATIAL_TEXTURE_COUNT, MAX_TAPE_SLAB_COUNT},
|
binder::instances::{MAX_SPATIAL_TEXTURE_COUNT, MAX_TAPE_SLAB_COUNT, MAX_TILETREE_COUNT},
|
||||||
extract::{
|
extract::{
|
||||||
ExtractedRaytracingDirectionalLight, ExtractedRaytracingPointLight,
|
ExtractedRaytracingDirectionalLight, ExtractedRaytracingPointLight,
|
||||||
ExtractedRaytracingRectLight, ExtractedRaytracingSpotLight,
|
ExtractedRaytracingRectLight, ExtractedRaytracingSpotLight,
|
||||||
@@ -78,6 +78,7 @@ pub struct RaytracingSceneBindings {
|
|||||||
tlas: TlasState,
|
tlas: TlasState,
|
||||||
bind_groups: BindGroupCacheState,
|
bind_groups: BindGroupCacheState,
|
||||||
spatial_texture_sampler: Sampler,
|
spatial_texture_sampler: Sampler,
|
||||||
|
tiletree_sampler: Sampler,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RaytracingSceneBindings {
|
impl RaytracingSceneBindings {
|
||||||
@@ -105,6 +106,9 @@ impl FromWorld for RaytracingSceneBindings {
|
|||||||
texture_3d(TextureSampleType::Float { filterable: true })
|
texture_3d(TextureSampleType::Float { filterable: true })
|
||||||
.count(MAX_SPATIAL_TEXTURE_COUNT),
|
.count(MAX_SPATIAL_TEXTURE_COUNT),
|
||||||
sampler(SamplerBindingType::Filtering),
|
sampler(SamplerBindingType::Filtering),
|
||||||
|
texture_3d(TextureSampleType::Float { filterable: true })
|
||||||
|
.count(MAX_TILETREE_COUNT),
|
||||||
|
sampler(SamplerBindingType::Filtering),
|
||||||
texture_2d(TextureSampleType::Float { filterable: true })
|
texture_2d(TextureSampleType::Float { filterable: true })
|
||||||
.count(MAX_TEXTURE_COUNT),
|
.count(MAX_TEXTURE_COUNT),
|
||||||
sampler(SamplerBindingType::Filtering).count(MAX_TEXTURE_COUNT),
|
sampler(SamplerBindingType::Filtering).count(MAX_TEXTURE_COUNT),
|
||||||
@@ -155,6 +159,17 @@ impl FromWorld for RaytracingSceneBindings {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let tiletree_sampler = render_device.create_sampler(&SamplerDescriptor {
|
||||||
|
label: Some("tape_drive_tiletree_sampler"),
|
||||||
|
address_mode_u: AddressMode::ClampToEdge,
|
||||||
|
address_mode_v: AddressMode::ClampToEdge,
|
||||||
|
address_mode_w: AddressMode::ClampToEdge,
|
||||||
|
mag_filter: FilterMode::Linear,
|
||||||
|
min_filter: FilterMode::Linear,
|
||||||
|
mipmap_filter: MipmapFilterMode::Linear,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
bind_group: None,
|
bind_group: None,
|
||||||
bind_group_layout,
|
bind_group_layout,
|
||||||
@@ -166,6 +181,7 @@ impl FromWorld for RaytracingSceneBindings {
|
|||||||
tlas: TlasState::new(render_device),
|
tlas: TlasState::new(render_device),
|
||||||
bind_groups: BindGroupCacheState::new(render_device),
|
bind_groups: BindGroupCacheState::new(render_device),
|
||||||
spatial_texture_sampler,
|
spatial_texture_sampler,
|
||||||
|
tiletree_sampler,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ struct InstanceGeometryIds {
|
|||||||
struct InstanceTapeIds {
|
struct InstanceTapeIds {
|
||||||
aabb_buffer_id: u32,
|
aabb_buffer_id: u32,
|
||||||
aabb_buffer_offset: u32,
|
aabb_buffer_offset: u32,
|
||||||
aabb_count: u32,
|
|
||||||
spatial_texture_id: u32,
|
spatial_texture_id: u32,
|
||||||
|
tiletree_id: u32,
|
||||||
metadata_buffer_id: u32,
|
metadata_buffer_id: u32,
|
||||||
metadata_buffer_offset: u32,
|
metadata_buffer_offset: u32,
|
||||||
}
|
}
|
||||||
@@ -149,26 +149,28 @@ const LIGHT_NOT_PRESENT_THIS_FRAME = 0xFFFFFFFFu;
|
|||||||
@group(0) @binding(2) var<storage> aabb_buffers: binding_array<AabbBuffer>;
|
@group(0) @binding(2) var<storage> aabb_buffers: binding_array<AabbBuffer>;
|
||||||
@group(0) @binding(3) var<storage> tape_metadata_buffers: binding_array<TapeMetadataBuffer>;
|
@group(0) @binding(3) var<storage> tape_metadata_buffers: binding_array<TapeMetadataBuffer>;
|
||||||
|
|
||||||
@group(0) @binding(6) var textures: binding_array<texture_2d<f32>>;
|
@group(0) @binding(6) var tiletrees: binding_array<texture_3d<f32>>;
|
||||||
@group(0) @binding(7) var samplers: binding_array<sampler>;
|
@group(0) @binding(7) var tiletree_sampler: sampler;
|
||||||
@group(0) @binding(8) var<storage> materials: array<Material>;
|
@group(0) @binding(8) var textures: binding_array<texture_2d<f32>>;
|
||||||
@group(0) @binding(9) var tlas: acceleration_structure;
|
@group(0) @binding(9) var samplers: binding_array<sampler>;
|
||||||
@group(0) @binding(10) var previous_frame_tlas: acceleration_structure;
|
@group(0) @binding(10) var<storage> materials: array<Material>;
|
||||||
@group(0) @binding(11) var<storage> transforms: array<mat3x4<f32>>;
|
@group(0) @binding(11) var tlas: acceleration_structure;
|
||||||
@group(0) @binding(12) var<storage> previous_frame_transforms: array<mat3x4<f32>>;
|
@group(0) @binding(12) var previous_frame_tlas: acceleration_structure;
|
||||||
@group(0) @binding(13) var<storage> geometry_ids: array<InstanceGeometryIds>;
|
@group(0) @binding(13) var<storage> transforms: array<mat3x4<f32>>;
|
||||||
@group(0) @binding(14) var<storage> tape_ids: array<InstanceTapeIds>;
|
@group(0) @binding(14) var<storage> previous_frame_transforms: array<mat3x4<f32>>;
|
||||||
@group(0) @binding(15) var<storage> material_ids: array<u32>;
|
@group(0) @binding(15) var<storage> geometry_ids: array<InstanceGeometryIds>;
|
||||||
@group(0) @binding(16) var brdf_dfg_lut: texture_2d<f32>;
|
@group(0) @binding(16) var<storage> tape_ids: array<InstanceTapeIds>;
|
||||||
@group(0) @binding(17) var brdf_dfg_lut_sampler: sampler;
|
@group(0) @binding(17) var<storage> material_ids: array<u32>;
|
||||||
@group(0) @binding(18) var<storage> light_sources: array<LightSource>;
|
@group(0) @binding(18) var brdf_dfg_lut: texture_2d<f32>;
|
||||||
@group(0) @binding(19) var<storage> directional_lights: array<DirectionalLight>;
|
@group(0) @binding(19) var brdf_dfg_lut_sampler: sampler;
|
||||||
@group(0) @binding(20) var<storage> point_lights: array<PointLight>;
|
@group(0) @binding(20) var<storage> light_sources: array<LightSource>;
|
||||||
@group(0) @binding(21) var<storage> rect_lights: array<RectLight>;
|
@group(0) @binding(21) var<storage> directional_lights: array<DirectionalLight>;
|
||||||
@group(0) @binding(22) var environment_map: texture_cube<f32>;
|
@group(0) @binding(22) var<storage> point_lights: array<PointLight>;
|
||||||
@group(0) @binding(23) var environment_map_sampler: sampler;
|
@group(0) @binding(23) var<storage> rect_lights: array<RectLight>;
|
||||||
@group(0) @binding(24) var<storage> environment_map_light: EnvironmentMapLight;
|
@group(0) @binding(24) var environment_map: texture_cube<f32>;
|
||||||
@group(0) @binding(25) var<storage> previous_frame_light_id_translations: array<u32>;
|
@group(0) @binding(25) var environment_map_sampler: sampler;
|
||||||
|
@group(0) @binding(26) var<storage> environment_map_light: EnvironmentMapLight;
|
||||||
|
@group(0) @binding(27) var<storage> previous_frame_light_id_translations: array<u32>;
|
||||||
|
|
||||||
const RAY_T_MIN = 0.001f;
|
const RAY_T_MIN = 0.001f;
|
||||||
const RAY_T_MAX = 100000.0f;
|
const RAY_T_MAX = 100000.0f;
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ pub fn compile_raytracing_blas(
|
|||||||
|
|
||||||
const FLAG_FILL_ENABLE_GEN: u32 = 1 << 0;
|
const FLAG_FILL_ENABLE_GEN: u32 = 1 << 0;
|
||||||
const FLAG_FILL_SPATIAL_TEXTURE: u32 = 1 << 1;
|
const FLAG_FILL_SPATIAL_TEXTURE: u32 = 1 << 1;
|
||||||
|
const FLAG_FILL_TILETREE: u32 = 1 << 1;
|
||||||
|
|
||||||
let tape_info = tapes
|
let tape_info = tapes
|
||||||
.iter()
|
.iter()
|
||||||
@@ -269,6 +270,7 @@ pub fn compile_raytracing_blas(
|
|||||||
let aabbs_slice = tape_allocator.tape_aabb_slice(&asset_id).unwrap();
|
let aabbs_slice = tape_allocator.tape_aabb_slice(&asset_id).unwrap();
|
||||||
let metadata_slice = tape_allocator.tape_metadata_slice(&asset_id).unwrap();
|
let metadata_slice = tape_allocator.tape_metadata_slice(&asset_id).unwrap();
|
||||||
let spatial_texture = tape_allocator.tape_spatial_texture(&asset_id).unwrap();
|
let spatial_texture = tape_allocator.tape_spatial_texture(&asset_id).unwrap();
|
||||||
|
let tiletree = tape_allocator.tape_tiletree(&asset_id).unwrap();
|
||||||
|
|
||||||
let blas_size = BlasAABBGeometrySizeDescriptor {
|
let blas_size = BlasAABBGeometrySizeDescriptor {
|
||||||
primitive_count: aabbs_slice.range.len() as u32,
|
primitive_count: aabbs_slice.range.len() as u32,
|
||||||
@@ -281,6 +283,7 @@ pub fn compile_raytracing_blas(
|
|||||||
aabbs_slice,
|
aabbs_slice,
|
||||||
metadata_slice,
|
metadata_slice,
|
||||||
spatial_texture,
|
spatial_texture,
|
||||||
|
tiletree,
|
||||||
blas_size,
|
blas_size,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -291,7 +294,7 @@ pub fn compile_raytracing_blas(
|
|||||||
let build_entries = tape_info
|
let build_entries = tape_info
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(
|
.filter_map(
|
||||||
|(key, tape, aabbs_slice, metadata_slice, spatial_texture, blas_size)| {
|
|(key, tape, aabbs_slice, metadata_slice, spatial_texture, tiletree, blas_size)| {
|
||||||
let pipeline = pipeline_cache.get_compute_pipeline(tape.enable_gen_pipeline)?;
|
let pipeline = pipeline_cache.get_compute_pipeline(tape.enable_gen_pipeline)?;
|
||||||
|
|
||||||
let bind_group = render_device.create_bind_group(
|
let bind_group = render_device.create_bind_group(
|
||||||
@@ -301,6 +304,7 @@ pub fn compile_raytracing_blas(
|
|||||||
aabbs_slice.buffer.as_entire_buffer_binding(),
|
aabbs_slice.buffer.as_entire_buffer_binding(),
|
||||||
metadata_slice.buffer.as_entire_buffer_binding(),
|
metadata_slice.buffer.as_entire_buffer_binding(),
|
||||||
&spatial_texture.1,
|
&spatial_texture.1,
|
||||||
|
&tiletree.1,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -314,16 +318,16 @@ pub fn compile_raytracing_blas(
|
|||||||
compute_pass.set_bind_group(0, &bind_group, &[]);
|
compute_pass.set_bind_group(0, &bind_group, &[]);
|
||||||
compute_pass.set_immediates(0, bytemuck::bytes_of(&pc));
|
compute_pass.set_immediates(0, bytemuck::bytes_of(&pc));
|
||||||
compute_pass.dispatch_workgroups(
|
compute_pass.dispatch_workgroups(
|
||||||
tape.subdivision / 8,
|
tape.subdivision / 4,
|
||||||
tape.subdivision / 8,
|
tape.subdivision / 4,
|
||||||
tape.subdivision / 8,
|
tape.subdivision / 4,
|
||||||
);
|
);
|
||||||
pc.flags = FLAG_FILL_SPATIAL_TEXTURE;
|
pc.flags = FLAG_FILL_SPATIAL_TEXTURE;
|
||||||
compute_pass.set_immediates(0, bytemuck::bytes_of(&pc));
|
compute_pass.set_immediates(0, bytemuck::bytes_of(&pc));
|
||||||
compute_pass.dispatch_workgroups(
|
compute_pass.dispatch_workgroups(
|
||||||
tape.subdivision,
|
tape.subdivision * 2,
|
||||||
tape.subdivision,
|
tape.subdivision * 2,
|
||||||
tape.subdivision,
|
tape.subdivision * 2,
|
||||||
);
|
);
|
||||||
|
|
||||||
updated_blases.push(key.tape);
|
updated_blases.push(key.tape);
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ pub struct TapeAllocator {
|
|||||||
#[deref]
|
#[deref]
|
||||||
slab_allocator: SlabAllocator<TapeSlabItem>,
|
slab_allocator: SlabAllocator<TapeSlabItem>,
|
||||||
spatial_texture_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
spatial_texture_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||||
|
tiletree_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tunable parameters that customize the behavior of the allocator.
|
/// Tunable parameters that customize the behavior of the allocator.
|
||||||
@@ -201,6 +202,7 @@ impl FromWorld for TapeAllocator {
|
|||||||
Self {
|
Self {
|
||||||
slab_allocator,
|
slab_allocator,
|
||||||
spatial_texture_allocator: HashMap::new(),
|
spatial_texture_allocator: HashMap::new(),
|
||||||
|
tiletree_allocator: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -282,6 +284,13 @@ impl TapeAllocator {
|
|||||||
self.spatial_texture_allocator.get(tape_id)
|
self.spatial_texture_allocator.get(tape_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the spatial texture for the tape with the given ID.
|
||||||
|
///
|
||||||
|
/// If the tape wasn't allocated, returns None.
|
||||||
|
pub fn tape_tiletree(&self, tape_id: &AssetId<Tape>) -> Option<&(Texture, TextureView)> {
|
||||||
|
self.tiletree_allocator.get(tape_id)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the IDs of the vertex buffer and index buffer respectively for
|
/// Returns the IDs of the vertex buffer and index buffer respectively for
|
||||||
/// the tape with the given ID.
|
/// the tape with the given ID.
|
||||||
///
|
///
|
||||||
@@ -376,14 +385,15 @@ impl TapeAllocator {
|
|||||||
tape_allocator_settings,
|
tape_allocator_settings,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Allocate spatial texture.
|
||||||
let texture = render_device.create_texture(&TextureDescriptor {
|
let texture = render_device.create_texture(&TextureDescriptor {
|
||||||
label: Some(&format!("Tape {} spatial texture", tape_id)),
|
label: Some(&format!("Tape {} spatial texture", tape_id)),
|
||||||
format: TextureFormat::R32Float,
|
format: TextureFormat::R16Float,
|
||||||
dimension: TextureDimension::D3,
|
dimension: TextureDimension::D3,
|
||||||
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
view_formats: &[TextureFormat::R32Float],
|
view_formats: &[TextureFormat::R16Float],
|
||||||
size: Extent3d {
|
size: Extent3d {
|
||||||
width: tape.subdivision * 8,
|
width: tape.subdivision * 8,
|
||||||
height: tape.subdivision * 8,
|
height: tape.subdivision * 8,
|
||||||
@@ -394,10 +404,31 @@ impl TapeAllocator {
|
|||||||
label: Some(&format!("Tape {} spatial texture view", tape_id)),
|
label: Some(&format!("Tape {} spatial texture view", tape_id)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Allocate spatial texture.
|
|
||||||
self.spatial_texture_allocator
|
self.spatial_texture_allocator
|
||||||
.insert(*tape_id, (texture, texture_view));
|
.insert(*tape_id, (texture, texture_view));
|
||||||
|
|
||||||
|
// Allocate worst-case tiletree
|
||||||
|
let texture = render_device.create_texture(&TextureDescriptor {
|
||||||
|
label: Some(&format!("Tape {} tiletree", tape_id)),
|
||||||
|
format: TextureFormat::Rgb10a2Unorm,
|
||||||
|
dimension: TextureDimension::D3,
|
||||||
|
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||||
|
mip_level_count: 1,
|
||||||
|
sample_count: 1,
|
||||||
|
view_formats: &[TextureFormat::Rgb10a2Unorm],
|
||||||
|
size: Extent3d {
|
||||||
|
width: tape.subdivision * 128,
|
||||||
|
height: tape.subdivision * 128,
|
||||||
|
depth_or_array_layers: tape.subdivision * 6,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
let texture_view = texture.create_view(&TextureViewDescriptor {
|
||||||
|
label: Some(&format!("Tape {} tiletree view", tape_id)),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
|
self.tiletree_allocator
|
||||||
|
.insert(*tape_id, (texture, texture_view));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform growth.
|
// Perform growth.
|
||||||
@@ -490,6 +521,7 @@ impl TapeAllocator {
|
|||||||
deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Metadata));
|
deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Metadata));
|
||||||
deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Aabb));
|
deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Aabb));
|
||||||
self.spatial_texture_allocator.remove(tape_id);
|
self.spatial_texture_allocator.remove(tape_id);
|
||||||
|
self.tiletree_allocator.remove(tape_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
deallocation_stage.commit();
|
deallocation_stage.commit();
|
||||||
|
|||||||
@@ -20,13 +20,16 @@ struct PushConstants {
|
|||||||
|
|
||||||
const FLAG_FILL_ENABLE_GEN = 1 << 0;
|
const FLAG_FILL_ENABLE_GEN = 1 << 0;
|
||||||
const FLAG_FILL_SPATIAL_TEXTURE = 1 << 1;
|
const FLAG_FILL_SPATIAL_TEXTURE = 1 << 1;
|
||||||
|
const FLAG_FILL_TILETREE = 1 << 2;
|
||||||
|
|
||||||
@group(0) @binding(0)
|
@group(0) @binding(0)
|
||||||
var<storage, read_write> aabb_buffer: AabbBuffer;
|
var<storage, read_write> aabb_buffer: AabbBuffer;
|
||||||
@group(0) @binding(1)
|
@group(0) @binding(1)
|
||||||
var<storage> tape_metadata_buffer: TapeMetadataBuffer;
|
var<storage> tape_metadata_buffer: TapeMetadataBuffer;
|
||||||
@group(0) @binding(2)
|
@group(0) @binding(2)
|
||||||
var spatial_texture: texture_storage_3d<r32float, write>;
|
var spatial_texture: texture_storage_3d<r16float, write>;
|
||||||
|
@group(0) @binding(3)
|
||||||
|
var tiletree: texture_storage_3d<rgb10a2unorm, write>;
|
||||||
|
|
||||||
var<immediate> push_constants: PushConstants;
|
var<immediate> push_constants: PushConstants;
|
||||||
|
|
||||||
@@ -34,7 +37,7 @@ struct ComputeInput {
|
|||||||
@builtin(global_invocation_id) global_invocation_id: vec3u
|
@builtin(global_invocation_id) global_invocation_id: vec3u
|
||||||
}
|
}
|
||||||
|
|
||||||
@compute @workgroup_size(8, 8, 8)
|
@compute @workgroup_size(4, 4, 4)
|
||||||
fn main(compute_input: ComputeInput) {
|
fn main(compute_input: ComputeInput) {
|
||||||
var metadata = tape_metadata_buffer.metadata[push_constants.metadata_buffer_offset];
|
var metadata = tape_metadata_buffer.metadata[push_constants.metadata_buffer_offset];
|
||||||
|
|
||||||
@@ -78,4 +81,8 @@ fn main(compute_input: ComputeInput) {
|
|||||||
|
|
||||||
textureStore(spatial_texture, compute_input.global_invocation_id, vec4(point, 0., 0., 0.));
|
textureStore(spatial_texture, compute_input.global_invocation_id, vec4(point, 0., 0., 0.));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (push_constants.flags & FLAG_FILL_TILETREE) > 0 {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,11 @@ impl Plugin for TapeRenderAssetPlugin {
|
|||||||
storage_buffer::<PackedAabb>(false),
|
storage_buffer::<PackedAabb>(false),
|
||||||
storage_buffer_read_only::<TapeMetadata>(false),
|
storage_buffer_read_only::<TapeMetadata>(false),
|
||||||
texture_storage_3d(
|
texture_storage_3d(
|
||||||
TextureFormat::R32Float,
|
TextureFormat::R16Float,
|
||||||
|
StorageTextureAccess::WriteOnly,
|
||||||
|
),
|
||||||
|
texture_storage_3d(
|
||||||
|
TextureFormat::Rgb10a2Unorm,
|
||||||
StorageTextureAccess::WriteOnly,
|
StorageTextureAccess::WriteOnly,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user