@@ -37,7 +37,7 @@ const WORD_SIZE: usize = 4;
37
37
const WORD_ALIGNMENT : u64 = WORD_SIZE as _ ;
38
38
/// Enable an optimization to have multi-layered render passed
39
39
/// with clear operations set up to implement our `clear_image`
40
- /// Note: currently doesn 't work, needs a repro case for Apple
40
+ /// Note: multi-target clears don 't appear to work properly on Intel GPUs
41
41
const CLEAR_IMAGE_ARRAY : bool = false && cfg ! ( target_os = "macos" ) ;
42
42
/// Number of frames to average when reporting the performance counters.
43
43
const COUNTERS_REPORT_WINDOW : usize = 0 ;
@@ -867,30 +867,30 @@ impl CommandSink {
867
867
}
868
868
869
869
/// Switch the active encoder to render by starting a render pass.
870
- fn switch_render < ' a > (
871
- & ' a mut self ,
872
- descriptor : & ' a metal:: RenderPassDescriptorRef ,
873
- ) -> PreRender < ' a > {
870
+ fn switch_render (
871
+ & mut self ,
872
+ descriptor : metal:: RenderPassDescriptor ,
873
+ ) -> PreRender {
874
874
//assert!(AutoReleasePool::is_active());
875
875
self . stop_encoding ( ) ;
876
876
877
877
match * self {
878
878
CommandSink :: Immediate { ref cmd_buffer, ref mut encoder_state, ref mut num_passes, .. } => {
879
879
* num_passes += 1 ;
880
- let encoder = cmd_buffer. new_render_command_encoder ( descriptor) ;
880
+ let encoder = cmd_buffer. new_render_command_encoder ( & descriptor) ;
881
881
* encoder_state = EncoderState :: Render ( encoder. to_owned ( ) ) ;
882
882
PreRender :: Immediate ( encoder)
883
883
}
884
884
CommandSink :: Deferred { ref mut is_encoding, ref mut journal } => {
885
- let pass = soft:: Pass :: Render ( descriptor. to_owned ( ) ) ;
885
+ let pass = soft:: Pass :: Render ( descriptor) ;
886
886
* is_encoding = true ;
887
887
journal. passes . push ( ( pass, journal. render_commands . len ( ) .. 0 ) ) ;
888
888
PreRender :: Deferred ( & mut journal. resources , & mut journal. render_commands )
889
889
}
890
890
#[ cfg( feature = "dispatch" ) ]
891
891
CommandSink :: Remote { ref mut pass, ref capacity, .. } => {
892
892
let mut list = Vec :: with_capacity ( capacity. render ) ;
893
- * pass = Some ( EncodePass :: Render ( list, descriptor. to_owned ( ) ) ) ;
893
+ * pass = Some ( EncodePass :: Render ( list, descriptor) ) ;
894
894
match * pass {
895
895
Some ( EncodePass :: Render ( ref mut list, _) ) => PreRender :: Deferred ( list) ,
896
896
_ => unreachable ! ( )
@@ -902,7 +902,7 @@ impl CommandSink {
902
902
fn quick_render < ' a , I > (
903
903
& mut self ,
904
904
label : & str ,
905
- descriptor : & ' a metal:: RenderPassDescriptorRef ,
905
+ descriptor : metal:: RenderPassDescriptor ,
906
906
commands : I ,
907
907
)
908
908
where
@@ -2125,8 +2125,6 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2125
2125
let raw = image. like . as_texture ( ) ;
2126
2126
for subresource_range in subresource_ranges {
2127
2127
let sub = subresource_range. borrow ( ) ;
2128
- let descriptor = metal:: RenderPassDescriptor :: new ( ) ;
2129
-
2130
2128
let num_layers = ( sub. layers . end - sub. layers . start ) as u64 ;
2131
2129
let layers = if CLEAR_IMAGE_ARRAY {
2132
2130
0 .. 1
@@ -2153,66 +2151,9 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2153
2151
raw
2154
2152
} ;
2155
2153
2156
- let color_attachment = if image. format_desc . aspects . contains ( Aspects :: COLOR ) {
2157
- let attachment = descriptor
2158
- . color_attachments ( )
2159
- . object_at ( 0 )
2160
- . unwrap ( ) ;
2161
- attachment. set_texture ( Some ( texture) ) ;
2162
- attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
2163
- if sub. aspects . contains ( Aspects :: COLOR ) {
2164
- attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
2165
- attachment. set_clear_color ( clear_color. clone ( ) ) ;
2166
- Some ( attachment)
2167
- } else {
2168
- attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
2169
- None
2170
- }
2171
- } else {
2172
- assert ! ( !sub. aspects. contains( Aspects :: COLOR ) ) ;
2173
- None
2174
- } ;
2175
-
2176
- let depth_attachment = if image. format_desc . aspects . contains ( Aspects :: DEPTH ) {
2177
- let attachment = descriptor
2178
- . depth_attachment ( )
2179
- . unwrap ( ) ;
2180
- attachment. set_texture ( Some ( texture) ) ;
2181
- attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
2182
- if sub. aspects . contains ( Aspects :: DEPTH ) {
2183
- attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
2184
- attachment. set_clear_depth ( depth_stencil. depth as _ ) ;
2185
- Some ( attachment)
2186
- } else {
2187
- attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
2188
- None
2189
- }
2190
- } else {
2191
- assert ! ( !sub. aspects. contains( Aspects :: DEPTH ) ) ;
2192
- None
2193
- } ;
2194
-
2195
- let stencil_attachment = if image. format_desc . aspects . contains ( Aspects :: STENCIL ) {
2196
- let attachment = descriptor
2197
- . stencil_attachment ( )
2198
- . unwrap ( ) ;
2199
- attachment. set_texture ( Some ( texture) ) ;
2200
- attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
2201
- if sub. aspects . contains ( Aspects :: STENCIL ) {
2202
- attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
2203
- attachment. set_clear_stencil ( depth_stencil. stencil ) ;
2204
- Some ( attachment)
2205
- } else {
2206
- attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
2207
- None
2208
- }
2209
- } else {
2210
- assert ! ( !sub. aspects. contains( Aspects :: STENCIL ) ) ;
2211
- None
2212
- } ;
2213
-
2214
2154
for layer in layers {
2215
2155
for level in sub. levels . clone ( ) {
2156
+ let descriptor = metal:: RenderPassDescriptor :: new ( ) . to_owned ( ) ;
2216
2157
if base_extent. depth > 1 {
2217
2158
assert_eq ! ( sub. layers. end, 1 ) ;
2218
2159
let depth = base_extent. at_level ( level) . depth as u64 ;
@@ -2221,24 +2162,66 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2221
2162
descriptor. set_render_target_array_length ( num_layers) ;
2222
2163
} ;
2223
2164
2224
- if let Some ( attachment) = color_attachment {
2165
+ if image. format_desc . aspects . contains ( Aspects :: COLOR ) {
2166
+ let attachment = descriptor
2167
+ . color_attachments ( )
2168
+ . object_at ( 0 )
2169
+ . unwrap ( ) ;
2170
+ attachment. set_texture ( Some ( texture) ) ;
2225
2171
attachment. set_level ( level as _ ) ;
2226
2172
if !CLEAR_IMAGE_ARRAY {
2227
2173
attachment. set_slice ( layer as _ ) ;
2228
2174
}
2229
- }
2230
- if let Some ( attachment) = depth_attachment {
2175
+ attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
2176
+ if sub. aspects . contains ( Aspects :: COLOR ) {
2177
+ attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
2178
+ attachment. set_clear_color ( clear_color. clone ( ) ) ;
2179
+ } else {
2180
+ attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
2181
+ }
2182
+ } else {
2183
+ assert ! ( !sub. aspects. contains( Aspects :: COLOR ) ) ;
2184
+ } ;
2185
+
2186
+ if image. format_desc . aspects . contains ( Aspects :: DEPTH ) {
2187
+ let attachment = descriptor
2188
+ . depth_attachment ( )
2189
+ . unwrap ( ) ;
2190
+ attachment. set_texture ( Some ( texture) ) ;
2231
2191
attachment. set_level ( level as _ ) ;
2232
2192
if !CLEAR_IMAGE_ARRAY {
2233
2193
attachment. set_slice ( layer as _ ) ;
2234
2194
}
2235
- }
2236
- if let Some ( attachment) = stencil_attachment {
2195
+ attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
2196
+ if sub. aspects . contains ( Aspects :: DEPTH ) {
2197
+ attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
2198
+ attachment. set_clear_depth ( depth_stencil. depth as _ ) ;
2199
+ } else {
2200
+ attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
2201
+ }
2202
+ } else {
2203
+ assert ! ( !sub. aspects. contains( Aspects :: DEPTH ) ) ;
2204
+ } ;
2205
+
2206
+ if image. format_desc . aspects . contains ( Aspects :: STENCIL ) {
2207
+ let attachment = descriptor
2208
+ . stencil_attachment ( )
2209
+ . unwrap ( ) ;
2210
+ attachment. set_texture ( Some ( texture) ) ;
2237
2211
attachment. set_level ( level as _ ) ;
2238
2212
if !CLEAR_IMAGE_ARRAY {
2239
2213
attachment. set_slice ( layer as _ ) ;
2240
2214
}
2241
- }
2215
+ attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
2216
+ if sub. aspects . contains ( Aspects :: STENCIL ) {
2217
+ attachment. set_load_action ( metal:: MTLLoadAction :: Clear ) ;
2218
+ attachment. set_clear_stencil ( depth_stencil. stencil ) ;
2219
+ } else {
2220
+ attachment. set_load_action ( metal:: MTLLoadAction :: Load ) ;
2221
+ }
2222
+ } else {
2223
+ assert ! ( !sub. aspects. contains( Aspects :: STENCIL ) ) ;
2224
+ } ;
2242
2225
2243
2226
sink. as_mut ( )
2244
2227
. unwrap ( )
@@ -2607,32 +2590,38 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2607
2590
} ;
2608
2591
2609
2592
autoreleasepool ( || {
2610
- let descriptor = metal:: RenderPassDescriptor :: new ( ) ;
2611
2593
let dst_new = match dst_cubish {
2612
2594
Some ( ref tex) => tex. as_ref ( ) ,
2613
2595
None => dst. like . as_texture ( ) ,
2614
2596
} ;
2615
- if src. format_desc . aspects . contains ( Aspects :: COLOR ) {
2616
- descriptor
2617
- . color_attachments ( )
2618
- . object_at ( 0 )
2619
- . unwrap ( )
2620
- . set_texture ( Some ( dst_new) ) ;
2621
- }
2622
- if src. format_desc . aspects . contains ( Aspects :: DEPTH ) {
2623
- descriptor
2624
- . depth_attachment ( )
2625
- . unwrap ( )
2626
- . set_texture ( Some ( dst_new) ) ;
2627
- }
2628
- if src. format_desc . aspects . contains ( Aspects :: STENCIL ) {
2629
- descriptor
2630
- . stencil_attachment ( )
2631
- . unwrap ( )
2632
- . set_texture ( Some ( dst_new) ) ;
2633
- }
2634
2597
2635
2598
for ( ( aspects, level) , list) in vertices. drain ( ) {
2599
+ let descriptor = metal:: RenderPassDescriptor :: new ( ) . to_owned ( ) ;
2600
+ descriptor. set_render_target_array_length ( dst_layers as _ ) ;
2601
+
2602
+ if aspects. contains ( Aspects :: COLOR ) {
2603
+ let att = descriptor
2604
+ . color_attachments ( )
2605
+ . object_at ( 0 )
2606
+ . unwrap ( ) ;
2607
+ att. set_texture ( Some ( dst_new) ) ;
2608
+ att. set_level ( level as _ ) ;
2609
+ }
2610
+ if aspects. contains ( Aspects :: DEPTH ) {
2611
+ let att = descriptor
2612
+ . depth_attachment ( )
2613
+ . unwrap ( ) ;
2614
+ att. set_texture ( Some ( dst_new) ) ;
2615
+ att. set_level ( level as _ ) ;
2616
+ }
2617
+ if aspects. contains ( Aspects :: STENCIL ) {
2618
+ let att = descriptor
2619
+ . stencil_attachment ( )
2620
+ . unwrap ( ) ;
2621
+ att. set_texture ( Some ( dst_new) ) ;
2622
+ att. set_level ( level as _ ) ;
2623
+ }
2624
+
2636
2625
let ext = dst. kind . extent ( ) . at_level ( level) ;
2637
2626
//Note: flipping Y coordinate of the destination here
2638
2627
let rect = pso:: Rect {
@@ -2667,27 +2656,6 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2667
2656
} ,
2668
2657
] ;
2669
2658
2670
- descriptor. set_render_target_array_length ( dst_layers as _ ) ;
2671
- if aspects. contains ( Aspects :: COLOR ) {
2672
- descriptor
2673
- . color_attachments ( )
2674
- . object_at ( 0 )
2675
- . unwrap ( )
2676
- . set_level ( level as _ ) ;
2677
- }
2678
- if aspects. contains ( Aspects :: DEPTH ) {
2679
- descriptor
2680
- . depth_attachment ( )
2681
- . unwrap ( )
2682
- . set_level ( level as _ ) ;
2683
- }
2684
- if aspects. contains ( Aspects :: STENCIL ) {
2685
- descriptor
2686
- . stencil_attachment ( )
2687
- . unwrap ( )
2688
- . set_level ( level as _ ) ;
2689
- }
2690
-
2691
2659
let commands = prelude
2692
2660
. iter ( )
2693
2661
. chain ( & com_ds)
@@ -2697,7 +2665,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2697
2665
sink
2698
2666
. as_mut ( )
2699
2667
. unwrap ( )
2700
- . quick_render ( "blit_image" , & descriptor, commands) ;
2668
+ . quick_render ( "blit_image" , descriptor, commands) ;
2701
2669
}
2702
2670
} ) ;
2703
2671
@@ -3004,7 +2972,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
3004
2972
self . inner
3005
2973
. borrow_mut ( )
3006
2974
. sink ( )
3007
- . switch_render ( & sin. descriptor )
2975
+ . switch_render ( sin. descriptor )
3008
2976
. issue_many ( init_commands) ;
3009
2977
}
3010
2978
0 commit comments