--wip-- [skip ci]
This commit is contained in:
+35
-7
@@ -1002,6 +1002,7 @@ impl ApplicationHandler for App {
|
||||
&self.pipeline_cache,
|
||||
&shader_modules,
|
||||
&self.gstate.debug,
|
||||
&self.gstate.csg,
|
||||
);
|
||||
|
||||
let scene = Scene::new(
|
||||
@@ -1878,6 +1879,7 @@ impl App {
|
||||
&self.pipeline_cache,
|
||||
&rcx.shader_modules,
|
||||
&self.gstate.debug,
|
||||
&self.gstate.csg,
|
||||
);
|
||||
|
||||
while csg_pipelines_left > 0 {
|
||||
@@ -2713,6 +2715,7 @@ fn pipeline_recompile(
|
||||
cache: &Arc<PipelineCache>,
|
||||
shader_modules: &Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
||||
debug: &PreviousDebug,
|
||||
csgs: &[Arc<RwLock<CSG>>],
|
||||
) -> (
|
||||
Arc<GraphicsPipeline>,
|
||||
Arc<RayTracingPipeline>,
|
||||
@@ -2805,15 +2808,32 @@ fn pipeline_recompile(
|
||||
.unwrap();
|
||||
|
||||
// Make a list of the shader stages that the pipeline will have.
|
||||
let stages = [
|
||||
&PipelineShaderStageCreateInfo::new(raygen),
|
||||
&PipelineShaderStageCreateInfo::new(miss),
|
||||
&PipelineShaderStageCreateInfo::new(closest_hit),
|
||||
let mut stages = vec![
|
||||
PipelineShaderStageCreateInfo::new(raygen),
|
||||
PipelineShaderStageCreateInfo::new(miss),
|
||||
PipelineShaderStageCreateInfo::new(closest_hit),
|
||||
];
|
||||
|
||||
for csg in csgs {
|
||||
let csg = csg.read().unwrap();
|
||||
let rps = csg.replacement_modules.read().unwrap();
|
||||
let hit = rps["normals.rchit"]
|
||||
.specialize(specs.clone())
|
||||
.unwrap()
|
||||
.single_entry_point()
|
||||
.unwrap();
|
||||
stages.push(PipelineShaderStageCreateInfo::new(hit));
|
||||
let intersection = rps["trace.rint"]
|
||||
.specialize(specs.clone())
|
||||
.unwrap()
|
||||
.single_entry_point()
|
||||
.unwrap();
|
||||
stages.push(PipelineShaderStageCreateInfo::new(intersection));
|
||||
}
|
||||
|
||||
let layout = PipelineLayout::new(
|
||||
device.clone(),
|
||||
PipelineDescriptorSetLayoutCreateInfo::from_stages(stages)
|
||||
PipelineDescriptorSetLayoutCreateInfo::from_stages(stages.iter())
|
||||
.into_pipeline_layout_create_info(device.clone())
|
||||
.unwrap(),
|
||||
)
|
||||
@@ -2822,7 +2842,7 @@ fn pipeline_recompile(
|
||||
// Define the shader groups that will eventually turn into the shader binding
|
||||
// table. The numbers are the indices of the stages in the `stages`
|
||||
// array.
|
||||
let groups = [
|
||||
let mut groups = vec![
|
||||
RayTracingShaderGroupCreateInfo::General { general_shader: 0 },
|
||||
RayTracingShaderGroupCreateInfo::General { general_shader: 1 },
|
||||
RayTracingShaderGroupCreateInfo::TrianglesHit {
|
||||
@@ -2831,12 +2851,20 @@ fn pipeline_recompile(
|
||||
},
|
||||
];
|
||||
|
||||
for i in 0..csgs.len() {
|
||||
groups.push(RayTracingShaderGroupCreateInfo::ProceduralHit {
|
||||
closest_hit_shader: Some((3 + (i * 2)) as u32),
|
||||
any_hit_shader: None,
|
||||
intersection_shader: (4 + (i * 2)) as u32,
|
||||
})
|
||||
}
|
||||
|
||||
RayTracingPipeline::new(
|
||||
device.clone(),
|
||||
Some(cache.clone()),
|
||||
RayTracingPipelineCreateInfo {
|
||||
//flags: PipelineCreateFlags::DISABLE_OPTIMIZATION,
|
||||
stages: stages.into_iter().cloned().collect(),
|
||||
stages: stages.into_iter().collect(),
|
||||
groups: groups.into_iter().collect(),
|
||||
max_pipeline_ray_recursion_depth: 1,
|
||||
//dynamic_state: dynamic_state.clone(),
|
||||
|
||||
+22
-6
@@ -31,7 +31,8 @@ use crate::objects::{CSG, Mesh, OVertex};
|
||||
pub struct Scene {
|
||||
// The bottom-level acceleration structure is required to be kept alive
|
||||
// as we reference it in the top-level acceleration structure.
|
||||
pub _blases: Vec<Arc<AccelerationStructure>>,
|
||||
pub _mesh_blases: Vec<Arc<AccelerationStructure>>,
|
||||
pub _csg_blases: Vec<Arc<AccelerationStructure>>,
|
||||
pub tlas: Arc<AccelerationStructure>,
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ impl Scene {
|
||||
// contains the instances of the bottom-level acceleration structures. In our
|
||||
// shader, we will trace rays against the top-level acceleration
|
||||
// structure.
|
||||
let mut blases: Vec<Arc<AccelerationStructure>> = meshes
|
||||
let mesh_blases: Vec<Arc<AccelerationStructure>> = meshes
|
||||
.iter()
|
||||
.map(|mesh| unsafe {
|
||||
build_acceleration_structure_triangles(
|
||||
@@ -72,7 +73,10 @@ impl Scene {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
blases.extend(csgs.iter().map(|csg| unsafe {
|
||||
|
||||
let csg_blases: Vec<Arc<AccelerationStructure>> = csgs
|
||||
.iter()
|
||||
.map(|csg| unsafe {
|
||||
build_acceleration_structure_boxes(
|
||||
csg,
|
||||
image_index,
|
||||
@@ -80,7 +84,8 @@ impl Scene {
|
||||
device.clone(),
|
||||
&mut builder,
|
||||
)
|
||||
}));
|
||||
})
|
||||
.collect();
|
||||
|
||||
let blas_fence = builder
|
||||
.build()
|
||||
@@ -101,7 +106,7 @@ impl Scene {
|
||||
|
||||
let tlas = unsafe {
|
||||
build_top_level_acceleration_structure(
|
||||
blases
|
||||
mesh_blases
|
||||
.iter()
|
||||
.map(|blas| AccelerationStructureInstance {
|
||||
instance_shader_binding_table_record_offset_and_flags: Packed24_8::new(
|
||||
@@ -111,6 +116,16 @@ impl Scene {
|
||||
acceleration_structure_reference: blas.device_address().into(),
|
||||
..Default::default()
|
||||
})
|
||||
.chain(csg_blases.iter().enumerate().map(|(i, blas)| {
|
||||
AccelerationStructureInstance {
|
||||
instance_shader_binding_table_record_offset_and_flags: Packed24_8::new(
|
||||
(i + 1) as u32,
|
||||
(GeometryInstanceFlags::FORCE_OPAQUE).into(),
|
||||
),
|
||||
acceleration_structure_reference: blas.device_address().into(),
|
||||
..Default::default()
|
||||
}
|
||||
}))
|
||||
.collect(),
|
||||
memory_allocator.clone(),
|
||||
device.clone(),
|
||||
@@ -129,7 +144,8 @@ impl Scene {
|
||||
.unwrap();
|
||||
|
||||
Scene {
|
||||
_blases: blases,
|
||||
_mesh_blases: mesh_blases,
|
||||
_csg_blases: csg_blases,
|
||||
tlas,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user