@@ -5,6 +5,7 @@ use alloc::{
55 sync:: Arc ,
66 vec:: Vec ,
77} ;
8+ use arrayvec:: ArrayVec ;
89use core:: { ffi, num:: NonZeroU32 , ptr, time:: Duration } ;
910use std:: time:: Instant ;
1011
@@ -983,7 +984,7 @@ impl crate::Device for super::Device {
983984 let mut ranges = Vec :: with_capacity ( total_non_dynamic_entries) ;
984985
985986 let mut bind_group_infos =
986- arrayvec :: ArrayVec :: < super :: BindGroupInfo , { crate :: MAX_BIND_GROUPS } > :: default ( ) ;
987+ ArrayVec :: < super :: BindGroupInfo , { crate :: MAX_BIND_GROUPS } > :: default ( ) ;
987988 for ( index, bgl) in desc. bind_group_layouts . iter ( ) . enumerate ( ) {
988989 let mut info = super :: BindGroupInfo {
989990 tables : super :: TableTypes :: empty ( ) ,
@@ -1952,6 +1953,22 @@ impl crate::Device for super::Device {
19521953 } ;
19531954 let flags = Direct3D12 :: D3D12_PIPELINE_STATE_FLAG_NONE ;
19541955
1956+ let mut view_instancing =
1957+ core:: pin:: pin!( ArrayVec :: <Direct3D12 :: D3D12_VIEW_INSTANCE_LOCATION , 32 >:: new( ) ) ;
1958+ if let Some ( mask) = desc. multiview_mask {
1959+ let mask = mask. get ( ) ;
1960+ // This array is just what _could_ be rendered to. We actually apply the mask at
1961+ // renderpass creation time. The `view_index` passed to the shader depends on the
1962+ // view's index in this array, so if we include every view in this array, `view_index`
1963+ // actually the texture array layer, like in vulkan.
1964+ for i in 0 ..32 - mask. leading_zeros ( ) {
1965+ view_instancing. push ( Direct3D12 :: D3D12_VIEW_INSTANCE_LOCATION {
1966+ ViewportArrayIndex : 0 ,
1967+ RenderTargetArrayIndex : i,
1968+ } ) ;
1969+ }
1970+ }
1971+
19551972 let mut stream_desc = RenderPipelineStateStreamDesc {
19561973 // Shared by vertex and mesh pipelines
19571974 root_signature : desc. layout . shared . signature . as_ref ( ) ,
@@ -1970,6 +1987,16 @@ impl crate::Device for super::Device {
19701987 node_mask : 0 ,
19711988 cached_pso,
19721989 flags,
1990+ view_instancing : if !view_instancing. is_empty ( ) {
1991+ Some ( Direct3D12 :: D3D12_VIEW_INSTANCING_DESC {
1992+ ViewInstanceCount : view_instancing. len ( ) as u32 ,
1993+ pViewInstanceLocations : view_instancing. as_ptr ( ) ,
1994+ // This lets us hide/mask certain values later, at renderpass creation time.
1995+ Flags : Direct3D12 :: D3D12_VIEW_INSTANCING_FLAG_ENABLE_VIEW_INSTANCE_MASKING ,
1996+ } )
1997+ } else {
1998+ None
1999+ } ,
19732000
19742001 // Optional data that depends on the pipeline type (vertex vs mesh).
19752002 vertex_shader : Default :: default ( ) ,
0 commit comments