Skip to content

Commit 1a6ddf7

Browse files
author
GBDixonAlex
committed
- add create_tlas_with_heap function
1 parent 58884b1 commit 1a6ddf7

File tree

5 files changed

+39
-33
lines changed

5 files changed

+39
-33
lines changed

plugins/ecs_examples/src/raytraced_shadows.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ pub fn setup_raytraced_shadows_scene(
193193
tlas: None
194194
}
195195
);
196-
197-
//
198196

199197
Ok(())
200198
}
@@ -225,10 +223,12 @@ pub fn setup_raytraced_shadows_tlas(
225223
blas: &blas.blas
226224
}
227225
);
228-
let tlas = device.create_raytracing_tlas(&gfx::RaytracingTLASInfo {
226+
let tlas = device.create_raytracing_tlas_with_heap(&gfx::RaytracingTLASInfo {
229227
instances: &instances,
230-
build_flags: gfx::AccelerationStructureBuildFlags::PREFER_FAST_TRACE
231-
})?;
228+
build_flags: gfx::AccelerationStructureBuildFlags::PREFER_FAST_TRACE,
229+
},
230+
&mut pmfx.shader_heap
231+
)?;
232232

233233
t.tlas = Some(tlas);
234234
}
@@ -253,7 +253,7 @@ pub fn animate_lights (
253253
}
254254

255255
// TODO_RT
256-
// create tlas with heap?
256+
257257
// update tlas
258258
// mesh vertex count
259259
// fix: Ignoring InitialState D3D12_RESOURCE_STATE_COPY_DEST. Buffers are effectively created in state D3D12_RESOURCE_STATE_COMMON.
@@ -276,12 +276,10 @@ pub fn render_meshes_raytraced(
276276
if let Ok(camera) = camera {
277277
for t in &tlas_query {
278278
if let Some(tlas) = &t.tlas {
279-
280279
// set pipeline
281280
let raytracing_pipeline = pmfx.get_raytracing_pipeline(&pass.pass_pipline)?;
282281
pass.cmd_buf.set_raytracing_pipeline(&raytracing_pipeline.pipeline);
283282

284-
285283
let slot = raytracing_pipeline.pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants);
286284
if let Some(slot) = slot {
287285
// camera constants
@@ -300,7 +298,7 @@ pub fn render_meshes_raytraced(
300298
// bind tlas on t1 (device heap)
301299
let srv0 = tlas.get_srv_index().expect("expect tlas to have an srv");
302300
if let Some(t0) = raytracing_pipeline.pipeline.get_pipeline_slot(69, 0, gfx::DescriptorType::ShaderResource) {
303-
pass.cmd_buf.set_binding(&raytracing_pipeline.pipeline, device.get_shader_heap(), t0.index, srv0);
301+
pass.cmd_buf.set_binding(&raytracing_pipeline.pipeline, &pmfx.shader_heap, t0.index, srv0);
304302
}
305303

306304
// dispatch

src/gfx.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,12 @@ pub trait Device: 'static + Send + Sync + Sized + Any + Clone {
12601260
&mut self,
12611261
info: &RaytracingBLASInfo<Self>
12621262
) -> Result<Self::RaytracingBLAS, Error>;
1263-
/*
12641263
/// Create a top level acceleration structure from array of `RaytracingInstanceInfo` with specificed heap
12651264
fn create_raytracing_tlas_with_heap(
12661265
&mut self,
12671266
info: &RaytracingTLASInfo<Self>,
12681267
heap: &mut Self::Heap
12691268
) -> Result<Self::RaytracingTLAS, Error>;
1270-
*/
12711269
/// Create a top level acceleration structure from array of `RaytracingInstanceInfo`
12721270
fn create_raytracing_tlas(
12731271
&mut self,

src/gfx/d3d12.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -3434,11 +3434,11 @@ impl super::Device for Device {
34343434
}
34353435
}
34363436

3437-
fn create_raytracing_tlas(
3437+
fn create_raytracing_tlas_with_heap(
34383438
&mut self,
3439-
info: &RaytracingTLASInfo<Self>
3439+
info: &RaytracingTLASInfo<Self>,
3440+
heap: &mut Heap
34403441
) -> result::Result<RaytracingTLAS, super::Error> {
3441-
34423442
// pack 24: 8 bits
34433443
let pack_24_8 = |a, b| {
34443444
(a & 0x00ffffff) | ((b & 0x000000ff) << 24)
@@ -3458,15 +3458,17 @@ impl super::Device for Device {
34583458

34593459
// create upload buffer for instance descs
34603460
let stride = std::mem::size_of::<D3D12_RAYTRACING_INSTANCE_DESC>();
3461-
let instance_buffer = self.create_buffer(&BufferInfo {
3461+
let instance_buffer = self.create_buffer_with_heap(&BufferInfo {
34623462
usage: super::BufferUsage::UPLOAD,
34633463
cpu_access: super::CpuAccessFlags::NONE,
34643464
format: super::Format::Unknown,
34653465
stride: std::mem::size_of::<D3D12_RAYTRACING_INSTANCE_DESC>(),
34663466
num_elements: num_instances,
34673467
initial_state: super::ResourceState::GenericRead
3468-
}, Some(instance_descs.as_slice()))
3469-
.expect(format!("hotline_rs::gfx::d3d12: failed to create a scratch buffer for raytracing blas of size {}", stride * num_instances).as_str());
3468+
},
3469+
Some(instance_descs.as_slice()),
3470+
heap
3471+
).expect(format!("hotline_rs::gfx::d3d12: failed to create a scratch buffer for raytracing blas of size {}", stride * num_instances).as_str());
34703472

34713473
// create acceleration structure inputs
34723474
let inputs = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_INPUTS {
@@ -3489,25 +3491,31 @@ impl super::Device for Device {
34893491
};
34903492

34913493
// UAV scratch buffer
3492-
let scratch_buffer = self.create_buffer::<u8>(&BufferInfo {
3494+
let scratch_buffer = self.create_buffer_with_heap::<u8>(&BufferInfo {
34933495
usage: super::BufferUsage::UNORDERED_ACCESS | super::BufferUsage::BUFFER_ONLY,
34943496
cpu_access: super::CpuAccessFlags::NONE,
34953497
format: super::Format::Unknown,
34963498
stride: prebuild_info.ScratchDataSizeInBytes as usize,
34973499
num_elements: 1,
34983500
initial_state: super::ResourceState::UnorderedAccess
3499-
}, None)
3501+
},
3502+
None,
3503+
heap
3504+
)
35003505
.expect(format!("hotline_rs::gfx::d3d12: failed to create a scratch buffer for raytracing tlas of size {}", prebuild_info.ScratchDataSizeInBytes).as_str());
35013506

35023507
// UAV buffer the tlas
3503-
let tlas_buffer = self.create_buffer::<u8>(&BufferInfo {
3508+
let tlas_buffer = self.create_buffer_with_heap::<u8>(&BufferInfo {
35043509
usage: super::BufferUsage::UNORDERED_ACCESS | super::BufferUsage::ACCELERATION_STRUCTURE,
35053510
cpu_access: super::CpuAccessFlags::NONE,
35063511
format: super::Format::Unknown,
35073512
stride: prebuild_info.ResultDataMaxSizeInBytes as usize,
35083513
num_elements: 1,
35093514
initial_state: super::ResourceState::AccelerationStructure
3510-
}, None).expect(format!("hotline_rs::gfx::d3d12: failed to create a tlas of size {}", prebuild_info.ScratchDataSizeInBytes).as_str());
3515+
},
3516+
None,
3517+
heap
3518+
).expect(format!("hotline_rs::gfx::d3d12: failed to create a tlas of size {}", prebuild_info.ScratchDataSizeInBytes).as_str());
35113519

35123520
// create tlas desc
35133521
let tlas_desc = D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC {
@@ -3535,6 +3543,16 @@ impl super::Device for Device {
35353543
})
35363544
}
35373545

3546+
fn create_raytracing_tlas(
3547+
&mut self,
3548+
info: &RaytracingTLASInfo<Self>
3549+
) -> result::Result<RaytracingTLAS, super::Error> {
3550+
let mut heap = std::mem::take(&mut self.shader_heap).unwrap();
3551+
let result = self.create_raytracing_tlas_with_heap(info, &mut heap);
3552+
self.shader_heap = Some(heap);
3553+
result
3554+
}
3555+
35383556
fn create_indirect_render_command<T: Sized>(
35393557
&mut self,
35403558
arguments: Vec<super::IndirectArgument>,

src/plugin.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,11 @@ impl reloader::ReloadResponder for PluginReloadResponder {
9898
.output()
9999
.expect("hotline::hot_lib:: hot lib failed to build!")
100100
}
101-
else {
102-
/*
103-
let hotline_path = super::get_data_path("../..");
104-
let pmbuild = super::get_data_path("../../hotline-data/pmbuild.cmd");
105-
std::process::Command::new(pmbuild)
106-
.current_dir(hotline_path)
107-
.arg("win32-debug")
108-
.arg("-plugins")
109-
.output()
110-
.expect("hotline::hot_lib:: hot pmfx failed to compile!")
111-
*/
112-
101+
else {
113102
Command::new("cargo")
114103
.current_dir(&self.path)
115104
.arg("build")
105+
.env("CARGO_TERM_COLOR", "always")
116106
.arg("-p")
117107
.arg(&self.name)
118108
.output()

todo.txt

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
// build
4545

4646
// DONE:
47+
// x create tlas with heap?
48+
// x raytraced triangle
4749
// x test shader compilation with mac changes
4850
// x update pmbuild
4951
// x omni shadow map

0 commit comments

Comments
 (0)