tiletrees?
This commit is contained in:
@@ -49,6 +49,7 @@ pub struct TapeAllocator {
|
||||
#[deref]
|
||||
slab_allocator: SlabAllocator<TapeSlabItem>,
|
||||
spatial_texture_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||
tiletree_allocator: HashMap<AssetId<Tape>, (Texture, TextureView)>,
|
||||
}
|
||||
|
||||
/// Tunable parameters that customize the behavior of the allocator.
|
||||
@@ -201,6 +202,7 @@ impl FromWorld for TapeAllocator {
|
||||
Self {
|
||||
slab_allocator,
|
||||
spatial_texture_allocator: HashMap::new(),
|
||||
tiletree_allocator: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,6 +284,13 @@ impl TapeAllocator {
|
||||
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
|
||||
/// the tape with the given ID.
|
||||
///
|
||||
@@ -376,14 +385,15 @@ impl TapeAllocator {
|
||||
tape_allocator_settings,
|
||||
);
|
||||
|
||||
// Allocate spatial texture.
|
||||
let texture = render_device.create_texture(&TextureDescriptor {
|
||||
label: Some(&format!("Tape {} spatial texture", tape_id)),
|
||||
format: TextureFormat::R32Float,
|
||||
format: TextureFormat::R16Float,
|
||||
dimension: TextureDimension::D3,
|
||||
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
view_formats: &[TextureFormat::R32Float],
|
||||
view_formats: &[TextureFormat::R16Float],
|
||||
size: Extent3d {
|
||||
width: tape.subdivision * 8,
|
||||
height: tape.subdivision * 8,
|
||||
@@ -394,10 +404,31 @@ impl TapeAllocator {
|
||||
label: Some(&format!("Tape {} spatial texture view", tape_id)),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// Allocate spatial texture.
|
||||
self.spatial_texture_allocator
|
||||
.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.
|
||||
@@ -490,6 +521,7 @@ impl TapeAllocator {
|
||||
deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Metadata));
|
||||
deallocation_stage.free(&TapeAllocationKey::new(*tape_id, ElementClass::Aabb));
|
||||
self.spatial_texture_allocator.remove(tape_id);
|
||||
self.tiletree_allocator.remove(tape_id);
|
||||
}
|
||||
|
||||
deallocation_stage.commit();
|
||||
|
||||
@@ -20,13 +20,16 @@ struct PushConstants {
|
||||
|
||||
const FLAG_FILL_ENABLE_GEN = 1 << 0;
|
||||
const FLAG_FILL_SPATIAL_TEXTURE = 1 << 1;
|
||||
const FLAG_FILL_TILETREE = 1 << 2;
|
||||
|
||||
@group(0) @binding(0)
|
||||
var<storage, read_write> aabb_buffer: AabbBuffer;
|
||||
@group(0) @binding(1)
|
||||
var<storage> tape_metadata_buffer: TapeMetadataBuffer;
|
||||
@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;
|
||||
|
||||
@@ -34,7 +37,7 @@ struct ComputeInput {
|
||||
@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) {
|
||||
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.));
|
||||
}
|
||||
|
||||
if (push_constants.flags & FLAG_FILL_TILETREE) > 0 {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,11 @@ impl Plugin for TapeRenderAssetPlugin {
|
||||
storage_buffer::<PackedAabb>(false),
|
||||
storage_buffer_read_only::<TapeMetadata>(false),
|
||||
texture_storage_3d(
|
||||
TextureFormat::R32Float,
|
||||
TextureFormat::R16Float,
|
||||
StorageTextureAccess::WriteOnly,
|
||||
),
|
||||
texture_storage_3d(
|
||||
TextureFormat::Rgb10a2Unorm,
|
||||
StorageTextureAccess::WriteOnly,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user