--wip-- [skip ci]
This commit is contained in:
@@ -213,6 +213,7 @@ struct App {
|
||||
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
|
||||
uniform_buffer_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||
block_enable_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||
aabb_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||
host_visible_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||
compute_visible_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||
pipeline_cache: Arc<PipelineCache>,
|
||||
@@ -587,6 +588,16 @@ impl App {
|
||||
},
|
||||
)));
|
||||
|
||||
let aabb_allocator = Arc::new(Mutex::new(SubbufferAllocator::new(
|
||||
memory_allocator.clone(),
|
||||
SubbufferAllocatorCreateInfo {
|
||||
buffer_usage: BufferUsage::STORAGE_BUFFER
|
||||
| BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY,
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE,
|
||||
..Default::default()
|
||||
},
|
||||
)));
|
||||
|
||||
let host_visible_allocator = Arc::new(Mutex::new(SubbufferAllocator::new(
|
||||
memory_allocator.clone(),
|
||||
SubbufferAllocatorCreateInfo {
|
||||
@@ -750,6 +761,7 @@ impl App {
|
||||
compute_visible_allocator,
|
||||
host_visible_allocator,
|
||||
block_enable_allocator,
|
||||
aabb_allocator,
|
||||
pipeline_cache,
|
||||
csg_count: gstate.csg.len(),
|
||||
draw_gui: true,
|
||||
@@ -1276,6 +1288,7 @@ impl ApplicationHandler for App {
|
||||
rcx.shader_modules.clone(),
|
||||
self.previous_debug,
|
||||
self.block_enable_allocator.clone(),
|
||||
self.aabb_allocator.clone(),
|
||||
self.host_visible_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
rcx.swapchain.image_count(),
|
||||
@@ -2023,6 +2036,7 @@ impl App {
|
||||
rcx.shader_modules.clone(),
|
||||
self.previous_debug,
|
||||
self.block_enable_allocator.clone(),
|
||||
self.aabb_allocator.clone(),
|
||||
self.host_visible_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
rcx.swapchain.image_count(),
|
||||
@@ -2256,6 +2270,7 @@ impl App {
|
||||
rcx.shader_modules.clone(),
|
||||
self.previous_debug,
|
||||
self.block_enable_allocator.clone(),
|
||||
self.aabb_allocator.clone(),
|
||||
self.host_visible_allocator.clone(),
|
||||
self.descriptor_set_allocator.clone(),
|
||||
rcx.swapchain.image_count(),
|
||||
|
||||
@@ -63,6 +63,7 @@ pub(crate) struct CSG {
|
||||
pub(crate) trace_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||
pub(crate) normals_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||
pub(crate) enable_gen_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||
pub(crate) aabb_buffer: Vec<Subbuffer<[u8]>>,
|
||||
}
|
||||
|
||||
pub(crate) fn load_obj(
|
||||
|
||||
+33
-5
@@ -6,10 +6,10 @@ use vulkano::{
|
||||
AccelerationStructure, AccelerationStructureBuildGeometryInfo,
|
||||
AccelerationStructureBuildRangeInfo, AccelerationStructureBuildType,
|
||||
AccelerationStructureCreateInfo, AccelerationStructureGeometries,
|
||||
AccelerationStructureGeometryInstancesData, AccelerationStructureGeometryInstancesDataType,
|
||||
AccelerationStructureGeometryTrianglesData, AccelerationStructureInstance,
|
||||
AccelerationStructureType, BuildAccelerationStructureFlags, BuildAccelerationStructureMode,
|
||||
GeometryInstanceFlags,
|
||||
AccelerationStructureGeometryAabbsData, AccelerationStructureGeometryInstancesData,
|
||||
AccelerationStructureGeometryInstancesDataType, AccelerationStructureGeometryTrianglesData,
|
||||
AccelerationStructureInstance, AccelerationStructureType, BuildAccelerationStructureFlags,
|
||||
BuildAccelerationStructureMode, GeometryInstanceFlags,
|
||||
},
|
||||
buffer::{Buffer, BufferCreateInfo, BufferUsage, IndexBuffer, Subbuffer},
|
||||
command_buffer::{
|
||||
@@ -22,7 +22,7 @@ use vulkano::{
|
||||
sync::GpuFuture,
|
||||
};
|
||||
|
||||
use crate::objects::{Mesh, OVertex};
|
||||
use crate::objects::{CSG, Mesh, OVertex};
|
||||
|
||||
pub struct Scene {
|
||||
// The bottom-level acceleration structure is required to be kept alive
|
||||
@@ -244,6 +244,34 @@ unsafe fn build_acceleration_structure_triangles(
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn build_acceleration_structure_boxes(
|
||||
csg: &CSG,
|
||||
index: usize,
|
||||
memory_allocator: Arc<dyn MemoryAllocator>,
|
||||
device: Arc<Device>,
|
||||
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
) -> Arc<AccelerationStructure> {
|
||||
let primitive_count = (csg.subdivision * csg.subdivision * csg.subdivision) as u32;
|
||||
let as_geometry_aabb_data = AccelerationStructureGeometryAabbsData {
|
||||
stride: 4 * 6, // six floats
|
||||
data: Some(csg.aabb_buffer[index].clone()),
|
||||
..AccelerationStructureGeometryAabbsData::default()
|
||||
};
|
||||
|
||||
let geometries = AccelerationStructureGeometries::Aabbs(vec![as_geometry_aabb_data]);
|
||||
|
||||
unsafe {
|
||||
build_acceleration_structure_common(
|
||||
geometries,
|
||||
primitive_count,
|
||||
AccelerationStructureType::BottomLevel,
|
||||
memory_allocator,
|
||||
device,
|
||||
builder,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn build_top_level_acceleration_structure(
|
||||
as_instances: Vec<AccelerationStructureInstance>,
|
||||
allocator: Arc<dyn MemoryAllocator>,
|
||||
|
||||
@@ -63,6 +63,7 @@ pub enum WorkItem {
|
||||
PreviousDebug,
|
||||
Arc<Mutex<SubbufferAllocator>>,
|
||||
Arc<Mutex<SubbufferAllocator>>,
|
||||
Arc<Mutex<SubbufferAllocator>>,
|
||||
Arc<dyn DescriptorSetAllocator>,
|
||||
u32,
|
||||
u32,
|
||||
@@ -113,6 +114,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
modules,
|
||||
debug,
|
||||
block_enable_allocator,
|
||||
aabb_allocator,
|
||||
host_visible_allocator,
|
||||
descriptor_set_allocator,
|
||||
frames,
|
||||
@@ -164,6 +166,20 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
})
|
||||
.collect();
|
||||
|
||||
let aabb_buffer: Vec<Subbuffer<[u8]>> = (0..frames)
|
||||
.map(|_| {
|
||||
aabb_allocator
|
||||
.lock()
|
||||
.unwrap()
|
||||
.allocate_slice(
|
||||
((MAXIMUM_SUBDIVISION * MAXIMUM_SUBDIVISION * MAXIMUM_SUBDIVISION)
|
||||
* 4
|
||||
* 6) as u64,
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let trace_layout = trace_pipeline.layout().set_layouts()[1].clone();
|
||||
let trace_descriptor_set = (0..frames)
|
||||
.map(|f| {
|
||||
@@ -202,10 +218,10 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
enable_gen_layout.clone(),
|
||||
[WriteDescriptorSet::buffer(
|
||||
0,
|
||||
enable_buffer[f as usize].clone(),
|
||||
)],
|
||||
[
|
||||
WriteDescriptorSet::buffer(0, enable_buffer[f as usize].clone()),
|
||||
WriteDescriptorSet::buffer(1, aabb_buffer[f as usize].clone()),
|
||||
],
|
||||
[],
|
||||
)
|
||||
.unwrap()
|
||||
@@ -230,6 +246,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
||||
enable_gen_pipeline,
|
||||
subdivision,
|
||||
enable_buffer,
|
||||
aabb_buffer,
|
||||
enable_buffer_host_visible,
|
||||
trace_descriptor_set,
|
||||
normals_descriptor_set,
|
||||
|
||||
Reference in New Issue
Block a user