--wip-- [skip ci]
This commit is contained in:
@@ -213,6 +213,7 @@ struct App {
|
|||||||
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
|
command_buffer_allocator: Arc<dyn CommandBufferAllocator>,
|
||||||
uniform_buffer_allocator: Arc<Mutex<SubbufferAllocator>>,
|
uniform_buffer_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||||
block_enable_allocator: Arc<Mutex<SubbufferAllocator>>,
|
block_enable_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||||
|
aabb_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||||
host_visible_allocator: Arc<Mutex<SubbufferAllocator>>,
|
host_visible_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||||
compute_visible_allocator: Arc<Mutex<SubbufferAllocator>>,
|
compute_visible_allocator: Arc<Mutex<SubbufferAllocator>>,
|
||||||
pipeline_cache: Arc<PipelineCache>,
|
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(
|
let host_visible_allocator = Arc::new(Mutex::new(SubbufferAllocator::new(
|
||||||
memory_allocator.clone(),
|
memory_allocator.clone(),
|
||||||
SubbufferAllocatorCreateInfo {
|
SubbufferAllocatorCreateInfo {
|
||||||
@@ -750,6 +761,7 @@ impl App {
|
|||||||
compute_visible_allocator,
|
compute_visible_allocator,
|
||||||
host_visible_allocator,
|
host_visible_allocator,
|
||||||
block_enable_allocator,
|
block_enable_allocator,
|
||||||
|
aabb_allocator,
|
||||||
pipeline_cache,
|
pipeline_cache,
|
||||||
csg_count: gstate.csg.len(),
|
csg_count: gstate.csg.len(),
|
||||||
draw_gui: true,
|
draw_gui: true,
|
||||||
@@ -1276,6 +1288,7 @@ impl ApplicationHandler for App {
|
|||||||
rcx.shader_modules.clone(),
|
rcx.shader_modules.clone(),
|
||||||
self.previous_debug,
|
self.previous_debug,
|
||||||
self.block_enable_allocator.clone(),
|
self.block_enable_allocator.clone(),
|
||||||
|
self.aabb_allocator.clone(),
|
||||||
self.host_visible_allocator.clone(),
|
self.host_visible_allocator.clone(),
|
||||||
self.descriptor_set_allocator.clone(),
|
self.descriptor_set_allocator.clone(),
|
||||||
rcx.swapchain.image_count(),
|
rcx.swapchain.image_count(),
|
||||||
@@ -2023,6 +2036,7 @@ impl App {
|
|||||||
rcx.shader_modules.clone(),
|
rcx.shader_modules.clone(),
|
||||||
self.previous_debug,
|
self.previous_debug,
|
||||||
self.block_enable_allocator.clone(),
|
self.block_enable_allocator.clone(),
|
||||||
|
self.aabb_allocator.clone(),
|
||||||
self.host_visible_allocator.clone(),
|
self.host_visible_allocator.clone(),
|
||||||
self.descriptor_set_allocator.clone(),
|
self.descriptor_set_allocator.clone(),
|
||||||
rcx.swapchain.image_count(),
|
rcx.swapchain.image_count(),
|
||||||
@@ -2256,6 +2270,7 @@ impl App {
|
|||||||
rcx.shader_modules.clone(),
|
rcx.shader_modules.clone(),
|
||||||
self.previous_debug,
|
self.previous_debug,
|
||||||
self.block_enable_allocator.clone(),
|
self.block_enable_allocator.clone(),
|
||||||
|
self.aabb_allocator.clone(),
|
||||||
self.host_visible_allocator.clone(),
|
self.host_visible_allocator.clone(),
|
||||||
self.descriptor_set_allocator.clone(),
|
self.descriptor_set_allocator.clone(),
|
||||||
rcx.swapchain.image_count(),
|
rcx.swapchain.image_count(),
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ pub(crate) struct CSG {
|
|||||||
pub(crate) trace_descriptor_set: Vec<Arc<DescriptorSet>>,
|
pub(crate) trace_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||||
pub(crate) normals_descriptor_set: Vec<Arc<DescriptorSet>>,
|
pub(crate) normals_descriptor_set: Vec<Arc<DescriptorSet>>,
|
||||||
pub(crate) enable_gen_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(
|
pub(crate) fn load_obj(
|
||||||
|
|||||||
+33
-5
@@ -6,10 +6,10 @@ use vulkano::{
|
|||||||
AccelerationStructure, AccelerationStructureBuildGeometryInfo,
|
AccelerationStructure, AccelerationStructureBuildGeometryInfo,
|
||||||
AccelerationStructureBuildRangeInfo, AccelerationStructureBuildType,
|
AccelerationStructureBuildRangeInfo, AccelerationStructureBuildType,
|
||||||
AccelerationStructureCreateInfo, AccelerationStructureGeometries,
|
AccelerationStructureCreateInfo, AccelerationStructureGeometries,
|
||||||
AccelerationStructureGeometryInstancesData, AccelerationStructureGeometryInstancesDataType,
|
AccelerationStructureGeometryAabbsData, AccelerationStructureGeometryInstancesData,
|
||||||
AccelerationStructureGeometryTrianglesData, AccelerationStructureInstance,
|
AccelerationStructureGeometryInstancesDataType, AccelerationStructureGeometryTrianglesData,
|
||||||
AccelerationStructureType, BuildAccelerationStructureFlags, BuildAccelerationStructureMode,
|
AccelerationStructureInstance, AccelerationStructureType, BuildAccelerationStructureFlags,
|
||||||
GeometryInstanceFlags,
|
BuildAccelerationStructureMode, GeometryInstanceFlags,
|
||||||
},
|
},
|
||||||
buffer::{Buffer, BufferCreateInfo, BufferUsage, IndexBuffer, Subbuffer},
|
buffer::{Buffer, BufferCreateInfo, BufferUsage, IndexBuffer, Subbuffer},
|
||||||
command_buffer::{
|
command_buffer::{
|
||||||
@@ -22,7 +22,7 @@ use vulkano::{
|
|||||||
sync::GpuFuture,
|
sync::GpuFuture,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::objects::{Mesh, OVertex};
|
use crate::objects::{CSG, Mesh, OVertex};
|
||||||
|
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
// The bottom-level acceleration structure is required to be kept alive
|
// 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(
|
unsafe fn build_top_level_acceleration_structure(
|
||||||
as_instances: Vec<AccelerationStructureInstance>,
|
as_instances: Vec<AccelerationStructureInstance>,
|
||||||
allocator: Arc<dyn MemoryAllocator>,
|
allocator: Arc<dyn MemoryAllocator>,
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ pub enum WorkItem {
|
|||||||
PreviousDebug,
|
PreviousDebug,
|
||||||
Arc<Mutex<SubbufferAllocator>>,
|
Arc<Mutex<SubbufferAllocator>>,
|
||||||
Arc<Mutex<SubbufferAllocator>>,
|
Arc<Mutex<SubbufferAllocator>>,
|
||||||
|
Arc<Mutex<SubbufferAllocator>>,
|
||||||
Arc<dyn DescriptorSetAllocator>,
|
Arc<dyn DescriptorSetAllocator>,
|
||||||
u32,
|
u32,
|
||||||
u32,
|
u32,
|
||||||
@@ -113,6 +114,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
|||||||
modules,
|
modules,
|
||||||
debug,
|
debug,
|
||||||
block_enable_allocator,
|
block_enable_allocator,
|
||||||
|
aabb_allocator,
|
||||||
host_visible_allocator,
|
host_visible_allocator,
|
||||||
descriptor_set_allocator,
|
descriptor_set_allocator,
|
||||||
frames,
|
frames,
|
||||||
@@ -164,6 +166,20 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
|||||||
})
|
})
|
||||||
.collect();
|
.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_layout = trace_pipeline.layout().set_layouts()[1].clone();
|
||||||
let trace_descriptor_set = (0..frames)
|
let trace_descriptor_set = (0..frames)
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
@@ -202,10 +218,10 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
|||||||
DescriptorSet::new(
|
DescriptorSet::new(
|
||||||
descriptor_set_allocator.clone(),
|
descriptor_set_allocator.clone(),
|
||||||
enable_gen_layout.clone(),
|
enable_gen_layout.clone(),
|
||||||
[WriteDescriptorSet::buffer(
|
[
|
||||||
0,
|
WriteDescriptorSet::buffer(0, enable_buffer[f as usize].clone()),
|
||||||
enable_buffer[f as usize].clone(),
|
WriteDescriptorSet::buffer(1, aabb_buffer[f as usize].clone()),
|
||||||
)],
|
],
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -230,6 +246,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
|
|||||||
enable_gen_pipeline,
|
enable_gen_pipeline,
|
||||||
subdivision,
|
subdivision,
|
||||||
enable_buffer,
|
enable_buffer,
|
||||||
|
aabb_buffer,
|
||||||
enable_buffer_host_visible,
|
enable_buffer_host_visible,
|
||||||
trace_descriptor_set,
|
trace_descriptor_set,
|
||||||
normals_descriptor_set,
|
normals_descriptor_set,
|
||||||
|
|||||||
Reference in New Issue
Block a user