enable gen running?

This commit is contained in:
2026-10-12 23:00:24 +01:00
parent f799783ee4
commit cb7fdfcea9
8 changed files with 329 additions and 256 deletions
+12 -13
View File
@@ -21,7 +21,6 @@ use bevy_render::{
SlabItemLayout,
},
};
use bevy_shape::BoundingVolume;
use wgpu::{BufferUsages, COPY_BUFFER_ALIGNMENT};
use super::{Aabb, RenderTape, TapeMetadata};
@@ -64,7 +63,7 @@ impl Default for TapeAllocatorSettings {
fn default() -> TapeAllocatorSettings {
TapeAllocatorSettings {
slab_allocator_settings: SlabAllocatorSettings::default(),
extra_buffer_usages: BufferUsages::empty(),
extra_buffer_usages: BufferUsages::empty(),
}
}
}
@@ -93,7 +92,7 @@ impl SlabItem for TapeSlabItem {
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct TapeSlabs {
/// The slab storing the tape's aabb data.
pub aabb_slab_id: TapeSlabId,
pub aabb_slab_id: TapeSlabId,
/// The slab storing the tape's metadata.
pub metadata_slab_id: Option<TapeSlabId>,
}
@@ -109,7 +108,7 @@ pub struct TapeAllocationKey {
/// The ID of the tape asset.
pub tape_id: AssetId<Tape>,
/// The type of data: vertex data, index data
pub class: ElementClass,
pub class: ElementClass,
}
impl TapeAllocationKey {
@@ -275,7 +274,7 @@ impl TapeAllocator {
/// None.
pub fn tape_slabs(&self, tape_id: &AssetId<Tape>) -> Option<TapeSlabs> {
Some(TapeSlabs {
aabb_slab_id: self.tape_id_to_aabb_slab(tape_id).cloned()?,
aabb_slab_id: self.tape_id_to_aabb_slab(tape_id).cloned()?,
metadata_slab_id: self.tape_id_to_metadata_slab(tape_id).cloned(),
})
}
@@ -390,11 +389,11 @@ impl TapeAllocator {
) {
let metadata = {
let aabb = tape.get_aabb(0.0);
let aabb_center = aabb.center().into();
let aabb_half_extents = aabb.half_size().into();
let lowest_corner = aabb.min.into();
let dimensions = (aabb.max - aabb.min).into();
TapeMetadata {
aabb_center,
aabb_half_extents,
lowest_corner,
dimensions,
subdivision_log2: tape.subdivision.ilog2(),
..Default::default()
}
@@ -482,10 +481,10 @@ impl ElementLayout {
/// data.
fn metadata(_tape: &Tape) -> ElementLayout {
ElementLayout {
class: ElementClass::Metadata,
size: size_of::<TapeMetadata>() as u64,
class: ElementClass::Metadata,
size: size_of::<TapeMetadata>() as u64,
elements_per_slot: 1,
buffer_usages: ElementClass::Metadata.buffer_usages(),
buffer_usages: ElementClass::Metadata.buffer_usages(),
}
}
@@ -518,7 +517,7 @@ impl ElementClass {
ElementClass::Metadata => BufferUsages::STORAGE,
ElementClass::Aabb => {
BufferUsages::union(BufferUsages::STORAGE, BufferUsages::BLAS_INPUT)
},
}
}
}
}
+53 -56
View File
@@ -3,8 +3,6 @@
*/
pub mod allocator;
use std::num::NonZeroU32;
use allocator::TapeAllocatorPlugin;
use bevy_app::{App, Plugin};
use bevy_asset::{AssetId, AssetServer, Assets, Handle};
@@ -22,7 +20,7 @@ use bevy_render::{
render_resource::{
BindGroupLayoutDescriptor, BindGroupLayoutEntries, Buffer, CachedComputePipelineId,
ComputePipelineDescriptor, PipelineCache, ShaderType,
binding_types::{storage_buffer_read_only_sized, storage_buffer_sized},
binding_types::{storage_buffer, storage_buffer_read_only},
},
};
use bevy_shader::{Shader, load_shader_library};
@@ -35,6 +33,25 @@ use crate::{
tape::Tape,
};
#[derive(Default, Pod, Zeroable, Clone, Copy, Debug, ShaderType)]
#[repr(C)]
pub struct PackedAabb {
min: Vec3,
max: Vec3,
}
/// Per-tape metadata, stored in [`super::allocator::TapeAllocator`].
/// Currently this is used to decompress vertex.
#[derive(Default, Pod, Zeroable, Clone, Copy, Debug, ShaderType)]
#[repr(C)]
pub struct TapeMetadata {
lowest_corner: Vec3,
pad_a: u32,
dimensions: Vec3,
pad_b: u32,
subdivision_log2: u32,
}
fn get_module(shader: ShaderModuleDescriptorPassthrough) -> Module {
let Some(source) = shader.spirv else {
unreachable!()
@@ -64,32 +81,28 @@ impl Plugin for TapeRenderAssetPlugin {
let enable_gen = include_spirv_raw!("../../shaders_out/enable_gen.orig.spv");
let modules = ReplacementModules {
enable_gen: get_module(enable_gen.clone()),
fuzz: get_module(enable_gen.clone()),
normals: get_module(enable_gen.clone()),
spatial_texture: get_module(enable_gen.clone()),
trace: get_module(enable_gen.clone()),
enable_gen_layout: BindGroupLayoutDescriptor::new(
enable_gen: get_module(enable_gen.clone()),
fuzz: get_module(enable_gen.clone()),
normals: get_module(enable_gen.clone()),
spatial_texture: get_module(enable_gen.clone()),
trace: get_module(enable_gen.clone()),
enable_gen_layout: BindGroupLayoutDescriptor::new(
"Enable Gen Layout",
&BindGroupLayoutEntries::sequential(
ShaderStages::COMPUTE,
(
storage_buffer_sized(false, None).count(NonZeroU32::new(500).unwrap()),
storage_buffer_read_only_sized(false, None)
.count(NonZeroU32::new(500).unwrap()),
storage_buffer_read_only_sized(false, None),
storage_buffer::<PackedAabb>(false),
storage_buffer_read_only::<TapeMetadata>(false),
),
),
),
fuzz_layout: BindGroupLayoutDescriptor::new(
fuzz_layout: BindGroupLayoutDescriptor::new(
"Tape Fuzz Layout",
&BindGroupLayoutEntries::sequential(
ShaderStages::COMPUTE,
(
storage_buffer_sized(false, None).count(NonZeroU32::new(500).unwrap()),
storage_buffer_read_only_sized(false, None)
.count(NonZeroU32::new(500).unwrap()),
storage_buffer_read_only_sized(false, None),
storage_buffer::<PackedAabb>(false),
storage_buffer_read_only::<TapeMetadata>(false),
),
),
),
@@ -98,10 +111,8 @@ impl Plugin for TapeRenderAssetPlugin {
&BindGroupLayoutEntries::sequential(
ShaderStages::COMPUTE,
(
storage_buffer_sized(false, None).count(NonZeroU32::new(500).unwrap()),
storage_buffer_read_only_sized(false, None)
.count(NonZeroU32::new(500).unwrap()),
storage_buffer_read_only_sized(false, None),
storage_buffer::<PackedAabb>(false),
storage_buffer_read_only::<TapeMetadata>(false),
),
),
),
@@ -138,7 +149,7 @@ pub struct TapeMetadataFallbackTape(pub Handle<Tape>);
#[derive(Resource)]
pub struct TapeMetadataFallbackBuffer {
pub slab_id: TapeSlabId,
pub buffer: Buffer,
pub buffer: Buffer,
}
pub fn prepare_tape_metadata_fallback_buffer(
@@ -169,45 +180,31 @@ pub struct Aabb {
#[derive(Resource)]
pub struct ReplacementModules {
pub enable_gen: Module,
pub fuzz: Module,
pub normals: Module,
pub enable_gen: Module,
pub fuzz: Module,
pub normals: Module,
pub spatial_texture: Module,
pub trace: Module,
pub trace: Module,
pub enable_gen_layout: BindGroupLayoutDescriptor,
pub fuzz_layout: BindGroupLayoutDescriptor,
pub enable_gen_layout: BindGroupLayoutDescriptor,
pub fuzz_layout: BindGroupLayoutDescriptor,
pub spatial_texture_layout: BindGroupLayoutDescriptor,
}
/// Per-tape metadata, stored in [`super::allocator::TapeAllocator`].
/// Currently this is used to decompress vertex.
#[derive(Default, Pod, Zeroable, Clone, Copy, Debug, ShaderType)]
#[repr(C)]
pub struct TapeMetadata {
// AABB for decompressing positions.
pub aabb_center: Vec3,
pub pad1: u32,
// AABB for decompressing positions.
pub aabb_half_extents: Vec3,
pub pad2: u32,
pub subdivision_log2: u32,
}
/// The render world representation of a [`Tape`].
#[derive(Debug, Clone)]
pub struct RenderTape {
pub seed: u64,
pub seed: u64,
pub subdivision: u32,
pub enable_gen: Handle<Shader>,
pub fuzz: Handle<Shader>,
pub normals: Handle<Shader>,
pub enable_gen: Handle<Shader>,
pub fuzz: Handle<Shader>,
pub normals: Handle<Shader>,
pub spatial_texture: Handle<Shader>,
pub trace: Handle<Shader>,
pub trace: Handle<Shader>,
pub enable_gen_pipeline: CachedComputePipelineId,
pub fuzz_pipeline: CachedComputePipelineId,
pub enable_gen_pipeline: CachedComputePipelineId,
pub fuzz_pipeline: CachedComputePipelineId,
pub spatial_texture_pipeline: CachedComputePipelineId,
}
@@ -271,8 +268,8 @@ impl RenderAsset for RenderTape {
label: Some(format!("bevy_tape_drive::gen_shader::enable_gen::{key}").into()),
layout: vec![replacement_modules.enable_gen_layout.clone()],
shader: enable_gen.clone(),
immediate_size: 8,
entry_point: Some("enable_gen_entry".into()),
immediate_size: 12,
entry_point: Some("main".into()),
..Default::default()
});
@@ -280,8 +277,8 @@ impl RenderAsset for RenderTape {
label: Some(format!("bevy_tape_drive::gen_shader::fuzz::{key}").into()),
layout: vec![replacement_modules.fuzz_layout.clone()],
shader: fuzz.clone(),
immediate_size: 8,
entry_point: Some("enable_gen_entry".into()),
immediate_size: 12,
entry_point: Some("main".into()),
..Default::default()
});
@@ -290,8 +287,8 @@ impl RenderAsset for RenderTape {
label: Some(format!("bevy_tape_drive::gen_shader::spatial_texture::{key}").into()),
layout: vec![replacement_modules.spatial_texture_layout.clone()],
shader: spatial_texture.clone(),
immediate_size: 8,
entry_point: Some("enable_gen_entry".into()),
immediate_size: 12,
entry_point: Some("main".into()),
..Default::default()
});