Skip to content

Commit 8a1bc9a

Browse files
polymonsterGBDixonAlex
authored and
GBDixonAlex
committed
- fixed false panic issue with wmf play video example, slowly implement shader binding table for raytracing
1 parent c353ec0 commit 8a1bc9a

File tree

4 files changed

+68
-41
lines changed

4 files changed

+68
-41
lines changed

config.jsn

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
tools<windows>: {
44
pmfx: "hotline-data/bin/win32/pmfx/pmfx.exe"
55
texturec: "hotline-data/bin/win32/texturec/texturec.exe"
6-
pmfx_dev: "../pmfx-shader/pmfx.py"
6+
pmfx_dev: "py -3 ../pmfx-shader/pmfx.py"
77
}
88

99
tools_help: {

src/av/wmf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl super::VideoPlayer<d3d12::Device> for VideoPlayer {
155155

156156
// make thread safe
157157
let mt : ID3D11Multithread = device.cast()?;
158-
mt.SetMultithreadProtected(BOOL::from(true)).expect("hotline_rs::wmf::error: call to SetMultithreadProtected failed");
158+
let _ = mt.SetMultithreadProtected(BOOL::from(true));
159159

160160
// setup media engine
161161
let mut reset_token : u32 = 0;

src/gfx/d3d12.rs

+65-38
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@ impl super::Device for Device {
30203020
let mut library_descs = Vec::new();
30213021

30223022
// dxil library shaders
3023-
for (index, shader) in info.shaders.iter().enumerate() {
3023+
for (index, shader) in info.shaders.iter().enumerate().rev() {
30243024
// dxil library
30253025
let dxil_library = D3D12_DXIL_LIBRARY_DESC {
30263026
DXILLibrary: D3D12_SHADER_BYTECODE {
@@ -3032,7 +3032,7 @@ impl super::Device for Device {
30323032
library_descs.push(dxil_library);
30333033
let dxil_library_subobject = D3D12_STATE_SUBOBJECT {
30343034
Type: D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY,
3035-
pDesc: &library_descs[index] as *const _ as *const _,
3035+
pDesc: &library_descs[info.shaders.len() - index - 1] as *const _ as *const _,
30363036
};
30373037
subobjects.push(dxil_library_subobject);
30383038
}
@@ -3048,6 +3048,16 @@ impl super::Device for Device {
30483048
};
30493049
subobjects.push(global_root_signature_subobject);
30503050

3051+
// retuns null if the vec is empty
3052+
let wstr_or_null = |vec: &Vec<u16> | -> windows_core::PCWSTR {
3053+
if vec.is_empty() {
3054+
windows_core::PCWSTR::null()
3055+
}
3056+
else {
3057+
windows_core::PCWSTR(vec.as_ptr())
3058+
}
3059+
};
3060+
30513061
// hitgroup config
30523062
let mut wide_hit_group_strings = Vec::new();
30533063
let mut hit_group_descs = Vec::new();
@@ -3066,12 +3076,10 @@ impl super::Device for Device {
30663076
// create desc
30673077
let hit_group_desc = D3D12_HIT_GROUP_DESC {
30683078
Type: to_d3d12_hit_group_type(&group.geometry),
3069-
HitGroupExport: windows_core::PCWSTR(wide_hit_group_strings[vpos].as_ptr()),
3070-
//AnyHitShaderImport: windows_core::PCWSTR(wide_hit_group_strings[vpos+1].as_ptr()),
3071-
ClosestHitShaderImport: windows_core::PCWSTR(wide_hit_group_strings[vpos+2].as_ptr()),
3072-
//IntersectionShaderImport: windows_core::PCWSTR(wide_hit_group_strings[vpos+3].as_ptr()),
3073-
AnyHitShaderImport: windows_core::PCWSTR::null(),
3074-
IntersectionShaderImport: windows_core::PCWSTR::null(),
3079+
HitGroupExport: wstr_or_null(&wide_hit_group_strings[vpos]),
3080+
AnyHitShaderImport: wstr_or_null(&wide_hit_group_strings[vpos+1]),
3081+
ClosestHitShaderImport: wstr_or_null(&wide_hit_group_strings[vpos+2]),
3082+
IntersectionShaderImport: wstr_or_null(&wide_hit_group_strings[vpos+3]),
30753083
};
30763084
hit_group_descs.push(hit_group_desc);
30773085
let hit_group_subobject = D3D12_STATE_SUBOBJECT {
@@ -3097,38 +3105,57 @@ impl super::Device for Device {
30973105

30983106
// get shader identifiers
30993107
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)
3108+
let raygen_ident = props.GetShaderIdentifier(windows_core::PCWSTR(wide_entry_points[0].as_ptr()));
3109+
let miss_ident = props.GetShaderIdentifier(windows_core::PCWSTR(wide_entry_points[2].as_ptr()));
31043110

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,
3111+
let raygen_identities = vec![raygen_ident];
3112+
let miss_identities = vec![miss_ident];
3113+
3114+
let create_shader_table = |idents : Vec<*mut c_void> | -> Option<ID3D12Resource> {
3115+
// create a table resource
3116+
let mut table_buffer: Option<ID3D12Resource> = None;
3117+
let buffer_size = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES as usize * idents.len();
3118+
self.device.CreateCommittedResource(
3119+
&D3D12_HEAP_PROPERTIES {
3120+
Type: D3D12_HEAP_TYPE_DEFAULT,
3121+
..Default::default()
31243122
},
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-
)?;
3123+
D3D12_HEAP_FLAG_NONE,
3124+
&D3D12_RESOURCE_DESC {
3125+
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
3126+
Alignment: 0,
3127+
Width: buffer_size as u64,
3128+
Height: 1,
3129+
DepthOrArraySize: 1,
3130+
MipLevels: 1,
3131+
Format: DXGI_FORMAT_UNKNOWN,
3132+
SampleDesc: DXGI_SAMPLE_DESC {
3133+
Count: 1,
3134+
Quality: 0,
3135+
},
3136+
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
3137+
Flags: D3D12_RESOURCE_FLAG_NONE,
3138+
},
3139+
D3D12_RESOURCE_STATE_COMMON,
3140+
None,
3141+
&mut table_buffer,
3142+
).expect("hotline_rs::gfx::d3d12: failed to create a shader binding table buffer");
3143+
3144+
//
3145+
if let Some(resource) = table_buffer.as_ref() {
3146+
let range = D3D12_RANGE { Begin: 0, End: 0 };
3147+
let mut map_data = std::ptr::null_mut();
3148+
resource.Map(0, Some(&range), Some(&mut map_data));
3149+
std::ptr::copy_nonoverlapping(idents.as_ptr() as *mut _, map_data, buffer_size);
3150+
resource.Unmap(0, None);
3151+
}
3152+
3153+
table_buffer
3154+
};
3155+
3156+
// create a resource ray gen, miss and hitgroup (maybe arrays)
3157+
create_shader_table(raygen_identities);
3158+
create_shader_table(miss_identities);
31323159

31333160
Ok(RaytracingPipeline {
31343161
state_object: state_object

src/os/win32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub fn string_to_wide(string: String) -> Vec<u16> {
226226
windows::Win32::Globalization::MULTI_BYTE_TO_WIDE_CHAR_FLAGS(0),
227227
null_string.as_bytes(),
228228
Some(vx.as_mut_slice()),
229-
);
229+
) + 1;
230230
let mut v: Vec<u16> = vec![0; n as usize];
231231
MultiByteToWideChar(
232232
windows::Win32::Globalization::CP_UTF8,

0 commit comments

Comments
 (0)