--wip-- [skip ci]
This commit is contained in:
+35
-7
@@ -1002,6 +1002,7 @@ impl ApplicationHandler for App {
|
|||||||
&self.pipeline_cache,
|
&self.pipeline_cache,
|
||||||
&shader_modules,
|
&shader_modules,
|
||||||
&self.gstate.debug,
|
&self.gstate.debug,
|
||||||
|
&self.gstate.csg,
|
||||||
);
|
);
|
||||||
|
|
||||||
let scene = Scene::new(
|
let scene = Scene::new(
|
||||||
@@ -1878,6 +1879,7 @@ impl App {
|
|||||||
&self.pipeline_cache,
|
&self.pipeline_cache,
|
||||||
&rcx.shader_modules,
|
&rcx.shader_modules,
|
||||||
&self.gstate.debug,
|
&self.gstate.debug,
|
||||||
|
&self.gstate.csg,
|
||||||
);
|
);
|
||||||
|
|
||||||
while csg_pipelines_left > 0 {
|
while csg_pipelines_left > 0 {
|
||||||
@@ -2713,6 +2715,7 @@ fn pipeline_recompile(
|
|||||||
cache: &Arc<PipelineCache>,
|
cache: &Arc<PipelineCache>,
|
||||||
shader_modules: &Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
shader_modules: &Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
|
||||||
debug: &PreviousDebug,
|
debug: &PreviousDebug,
|
||||||
|
csgs: &[Arc<RwLock<CSG>>],
|
||||||
) -> (
|
) -> (
|
||||||
Arc<GraphicsPipeline>,
|
Arc<GraphicsPipeline>,
|
||||||
Arc<RayTracingPipeline>,
|
Arc<RayTracingPipeline>,
|
||||||
@@ -2805,15 +2808,32 @@ fn pipeline_recompile(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Make a list of the shader stages that the pipeline will have.
|
// Make a list of the shader stages that the pipeline will have.
|
||||||
let stages = [
|
let mut stages = vec![
|
||||||
&PipelineShaderStageCreateInfo::new(raygen),
|
PipelineShaderStageCreateInfo::new(raygen),
|
||||||
&PipelineShaderStageCreateInfo::new(miss),
|
PipelineShaderStageCreateInfo::new(miss),
|
||||||
&PipelineShaderStageCreateInfo::new(closest_hit),
|
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(
|
let layout = PipelineLayout::new(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
PipelineDescriptorSetLayoutCreateInfo::from_stages(stages)
|
PipelineDescriptorSetLayoutCreateInfo::from_stages(stages.iter())
|
||||||
.into_pipeline_layout_create_info(device.clone())
|
.into_pipeline_layout_create_info(device.clone())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
@@ -2822,7 +2842,7 @@ fn pipeline_recompile(
|
|||||||
// Define the shader groups that will eventually turn into the shader binding
|
// Define the shader groups that will eventually turn into the shader binding
|
||||||
// table. The numbers are the indices of the stages in the `stages`
|
// table. The numbers are the indices of the stages in the `stages`
|
||||||
// array.
|
// array.
|
||||||
let groups = [
|
let mut groups = vec![
|
||||||
RayTracingShaderGroupCreateInfo::General { general_shader: 0 },
|
RayTracingShaderGroupCreateInfo::General { general_shader: 0 },
|
||||||
RayTracingShaderGroupCreateInfo::General { general_shader: 1 },
|
RayTracingShaderGroupCreateInfo::General { general_shader: 1 },
|
||||||
RayTracingShaderGroupCreateInfo::TrianglesHit {
|
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(
|
RayTracingPipeline::new(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
Some(cache.clone()),
|
Some(cache.clone()),
|
||||||
RayTracingPipelineCreateInfo {
|
RayTracingPipelineCreateInfo {
|
||||||
//flags: PipelineCreateFlags::DISABLE_OPTIMIZATION,
|
//flags: PipelineCreateFlags::DISABLE_OPTIMIZATION,
|
||||||
stages: stages.into_iter().cloned().collect(),
|
stages: stages.into_iter().collect(),
|
||||||
groups: groups.into_iter().collect(),
|
groups: groups.into_iter().collect(),
|
||||||
max_pipeline_ray_recursion_depth: 1,
|
max_pipeline_ray_recursion_depth: 1,
|
||||||
//dynamic_state: dynamic_state.clone(),
|
//dynamic_state: dynamic_state.clone(),
|
||||||
|
|||||||
+30
-14
@@ -31,8 +31,9 @@ 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
|
||||||
// as we reference it in the top-level acceleration structure.
|
// as we reference it in the top-level acceleration structure.
|
||||||
pub _blases: Vec<Arc<AccelerationStructure>>,
|
pub _mesh_blases: Vec<Arc<AccelerationStructure>>,
|
||||||
pub tlas: Arc<AccelerationStructure>,
|
pub _csg_blases: Vec<Arc<AccelerationStructure>>,
|
||||||
|
pub tlas: Arc<AccelerationStructure>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
@@ -61,7 +62,7 @@ impl Scene {
|
|||||||
// contains the instances of the bottom-level acceleration structures. In our
|
// contains the instances of the bottom-level acceleration structures. In our
|
||||||
// shader, we will trace rays against the top-level acceleration
|
// shader, we will trace rays against the top-level acceleration
|
||||||
// structure.
|
// structure.
|
||||||
let mut blases: Vec<Arc<AccelerationStructure>> = meshes
|
let mesh_blases: Vec<Arc<AccelerationStructure>> = meshes
|
||||||
.iter()
|
.iter()
|
||||||
.map(|mesh| unsafe {
|
.map(|mesh| unsafe {
|
||||||
build_acceleration_structure_triangles(
|
build_acceleration_structure_triangles(
|
||||||
@@ -72,15 +73,19 @@ impl Scene {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
blases.extend(csgs.iter().map(|csg| unsafe {
|
|
||||||
build_acceleration_structure_boxes(
|
let csg_blases: Vec<Arc<AccelerationStructure>> = csgs
|
||||||
csg,
|
.iter()
|
||||||
image_index,
|
.map(|csg| unsafe {
|
||||||
memory_allocator.clone(),
|
build_acceleration_structure_boxes(
|
||||||
device.clone(),
|
csg,
|
||||||
&mut builder,
|
image_index,
|
||||||
)
|
memory_allocator.clone(),
|
||||||
}));
|
device.clone(),
|
||||||
|
&mut builder,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let blas_fence = builder
|
let blas_fence = builder
|
||||||
.build()
|
.build()
|
||||||
@@ -101,7 +106,7 @@ impl Scene {
|
|||||||
|
|
||||||
let tlas = unsafe {
|
let tlas = unsafe {
|
||||||
build_top_level_acceleration_structure(
|
build_top_level_acceleration_structure(
|
||||||
blases
|
mesh_blases
|
||||||
.iter()
|
.iter()
|
||||||
.map(|blas| AccelerationStructureInstance {
|
.map(|blas| AccelerationStructureInstance {
|
||||||
instance_shader_binding_table_record_offset_and_flags: Packed24_8::new(
|
instance_shader_binding_table_record_offset_and_flags: Packed24_8::new(
|
||||||
@@ -111,6 +116,16 @@ impl Scene {
|
|||||||
acceleration_structure_reference: blas.device_address().into(),
|
acceleration_structure_reference: blas.device_address().into(),
|
||||||
..Default::default()
|
..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(),
|
.collect(),
|
||||||
memory_allocator.clone(),
|
memory_allocator.clone(),
|
||||||
device.clone(),
|
device.clone(),
|
||||||
@@ -129,7 +144,8 @@ impl Scene {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Scene {
|
Scene {
|
||||||
_blases: blases,
|
_mesh_blases: mesh_blases,
|
||||||
|
_csg_blases: csg_blases,
|
||||||
tlas,
|
tlas,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user