Skip to content

Commit c353ec0

Browse files
polymonsterGBDixonAlex
authored and
GBDixonAlex
committed
wip setting up shader tables for raytracing pipeline
1 parent 72b1641 commit c353ec0

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/gfx.rs

+11
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,13 @@ pub struct RaytracingPipelineInfo<'stack, D: Device> {
775775
pub pipeline_layout: PipelineLayout,
776776
}
777777

778+
pub struct RaytacingShaderBindingTable<D: Device> {
779+
pub ray_generation: D::ShaderTable,
780+
pub miss: D::ShaderTable,
781+
pub hit_group: D::ShaderTable,
782+
pub callable: D::ShaderTable
783+
}
784+
778785
/// Information to create a pipeline through `Device::create_texture`.
779786
#[derive(Copy, Clone)]
780787
pub struct TextureInfo {
@@ -946,6 +953,9 @@ pub trait ComputePipeline<D: Device>: Send + Sync {}
946953
/// An opaque compute pipeline type..
947954
pub trait RaytracingPipeline<D: Device>: Send + Sync {}
948955

956+
/// An opaque shader table type..
957+
pub trait ShaderTable<D: Device>: Send + Sync {}
958+
949959
/// A pipeline trait for shared functionality between Compute and Render pipelines
950960
pub trait Pipeline {
951961
/// Returns the `PipelineSlotInfo` of which slot to bind a heap to based on the reequested `register` and `descriptor_type`
@@ -1083,6 +1093,7 @@ pub trait Device: 'static + Send + Sync + Sized + Any + Clone {
10831093
type ComputePipeline: ComputePipeline<Self>;
10841094
type RaytracingPipeline: RaytracingPipeline<Self>;
10851095
type CommandSignature: CommandSignature<Self>;
1096+
type ShaderTable: ShaderTable<Self>;
10861097
/// Create a new GPU `Device` from `Device Info`
10871098
fn create(info: &DeviceInfo) -> Self;
10881099
/// Create a new resource `Heap` from `HeapInfo`

src/gfx/d3d12.rs

+50-1
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,13 @@ impl Shader {
16301630
}
16311631
}
16321632

1633+
pub struct ShaderTable {
1634+
}
1635+
1636+
impl super::ShaderTable<Device> for ShaderTable {
1637+
1638+
}
1639+
16331640
impl super::Device for Device {
16341641
type SwapChain = SwapChain;
16351642
type CmdBuf = CmdBuf;
@@ -1644,6 +1651,7 @@ impl super::Device for Device {
16441651
type Heap = Heap;
16451652
type QueryHeap = QueryHeap;
16461653
type CommandSignature = CommandSignature;
1654+
type ShaderTable = ShaderTable;
16471655
fn create(info: &super::DeviceInfo) -> Device {
16481656
unsafe {
16491657
// enable debug layer
@@ -2149,6 +2157,9 @@ impl super::Device for Device {
21492157
Flags: to_d3d12_buffer_usage_flags(info.usage),
21502158
..Default::default()
21512159
},
2160+
D3D12_RESOURCE_STATE_COMMON,
2161+
2162+
/*
21522163
// initial state
21532164
if info.cpu_access.contains(super::CpuAccessFlags::WRITE) {
21542165
D3D12_RESOURCE_STATE_GENERIC_READ
@@ -2159,6 +2170,8 @@ impl super::Device for Device {
21592170
else {
21602171
to_d3d12_resource_state(info.initial_state)
21612172
},
2173+
*/
2174+
21622175
None,
21632176
&mut buf,
21642177
)?;
@@ -3078,9 +3091,45 @@ impl super::Device for Device {
30783091

30793092
unsafe {
30803093
let device5 = self.device.cast::<ID3D12Device5>().expect("hotline_rs::gfx::d3d12: expected ID3D12Device5 availability to create_raytracing_pipeline");
3081-
let state_object = device5.CreateStateObject(
3094+
let state_object : ID3D12StateObject = device5.CreateStateObject(
30823095
&state_object_desc,
30833096
)?;
3097+
3098+
// get shader identifiers
3099+
let props = state_object.cast::<ID3D12StateObjectProperties>().expect("hotline_rs::gfx::d3d12: expected ID3D12StateObjectProperties");
3100+
let ident = props.GetShaderIdentifier(windows_core::PCWSTR(wide_entry_points[0].as_ptr()));
3101+
println!("ident: {:?}", ident);
3102+
3103+
// create a resource ray gen, miss and hitgroup (maybe arrays)
3104+
3105+
// create a table resource
3106+
let mut table_buffer: Option<ID3D12Resource> = None;
3107+
self.device.CreateCommittedResource(
3108+
&D3D12_HEAP_PROPERTIES {
3109+
Type: D3D12_HEAP_TYPE_DEFAULT,
3110+
..Default::default()
3111+
},
3112+
D3D12_HEAP_FLAG_NONE,
3113+
&D3D12_RESOURCE_DESC {
3114+
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
3115+
Alignment: 0, //D3D12_RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT as u64,
3116+
Width: D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES as u64,
3117+
Height: 1,
3118+
DepthOrArraySize: 1,
3119+
MipLevels: 1,
3120+
Format: DXGI_FORMAT_UNKNOWN,
3121+
SampleDesc: DXGI_SAMPLE_DESC {
3122+
Count: 1,
3123+
Quality: 0,
3124+
},
3125+
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
3126+
Flags: D3D12_RESOURCE_FLAG_NONE,
3127+
},
3128+
D3D12_RESOURCE_STATE_COMMON,
3129+
None,
3130+
&mut table_buffer,
3131+
)?;
3132+
30843133
Ok(RaytracingPipeline {
30853134
state_object: state_object
30863135
})

0 commit comments

Comments
 (0)