@@ -3020,7 +3020,7 @@ impl super::Device for Device {
3020
3020
let mut library_descs = Vec :: new ( ) ;
3021
3021
3022
3022
// dxil library shaders
3023
- for ( index, shader) in info. shaders . iter ( ) . enumerate ( ) {
3023
+ for ( index, shader) in info. shaders . iter ( ) . enumerate ( ) . rev ( ) {
3024
3024
// dxil library
3025
3025
let dxil_library = D3D12_DXIL_LIBRARY_DESC {
3026
3026
DXILLibrary : D3D12_SHADER_BYTECODE {
@@ -3032,7 +3032,7 @@ impl super::Device for Device {
3032
3032
library_descs. push ( dxil_library) ;
3033
3033
let dxil_library_subobject = D3D12_STATE_SUBOBJECT {
3034
3034
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 _ ,
3036
3036
} ;
3037
3037
subobjects. push ( dxil_library_subobject) ;
3038
3038
}
@@ -3048,6 +3048,16 @@ impl super::Device for Device {
3048
3048
} ;
3049
3049
subobjects. push ( global_root_signature_subobject) ;
3050
3050
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
+
3051
3061
// hitgroup config
3052
3062
let mut wide_hit_group_strings = Vec :: new ( ) ;
3053
3063
let mut hit_group_descs = Vec :: new ( ) ;
@@ -3066,12 +3076,10 @@ impl super::Device for Device {
3066
3076
// create desc
3067
3077
let hit_group_desc = D3D12_HIT_GROUP_DESC {
3068
3078
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 ] ) ,
3075
3083
} ;
3076
3084
hit_group_descs. push ( hit_group_desc) ;
3077
3085
let hit_group_subobject = D3D12_STATE_SUBOBJECT {
@@ -3097,38 +3105,57 @@ impl super::Device for Device {
3097
3105
3098
3106
// get shader identifiers
3099
3107
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 ( ) ) ) ;
3104
3110
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 ( )
3124
3122
} ,
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) ;
3132
3159
3133
3160
Ok ( RaytracingPipeline {
3134
3161
state_object : state_object
0 commit comments