@@ -533,7 +533,7 @@ impl State {
533
533
#[ derive( Clone , Debug ) ]
534
534
struct StageResources {
535
535
buffers : Vec < Option < ( metal:: Buffer , buffer:: Offset ) > > ,
536
- textures : Vec < Option < native :: ImageRoot > > ,
536
+ textures : Vec < Option < metal :: Texture > > ,
537
537
samplers : Vec < Option < metal:: SamplerState > > ,
538
538
push_constants_buffer_id : Option < u32 > ,
539
539
}
@@ -562,12 +562,12 @@ impl StageResources {
562
562
self . buffers [ slot] = Some ( ( buffer. to_owned ( ) , offset) ) ;
563
563
}
564
564
565
- fn add_textures ( & mut self , start : usize , roots : & [ Option < ( native :: ImageRoot , Layout ) > ] ) {
566
- while self . textures . len ( ) < start + roots . len ( ) {
565
+ fn add_textures ( & mut self , start : usize , textures : & [ Option < ( metal :: Texture , Layout ) > ] ) {
566
+ while self . textures . len ( ) < start + textures . len ( ) {
567
567
self . textures . push ( None )
568
568
}
569
- for ( out, root ) in self . textures [ start..] . iter_mut ( ) . zip ( roots . iter ( ) ) {
570
- * out = root . as_ref ( ) . map ( |& ( ref root , _) | root . clone ( ) ) ;
569
+ for ( out, tex ) in self . textures [ start..] . iter_mut ( ) . zip ( textures . iter ( ) ) {
570
+ * out = tex . as_ref ( ) . map ( |& ( ref t , _) | t . to_owned ( ) ) ;
571
571
}
572
572
}
573
573
@@ -748,22 +748,19 @@ impl CommandSink {
748
748
}
749
749
}
750
750
751
- fn begin_render_pass < ' a , F , I > (
751
+ fn begin_render_pass < ' a , I > (
752
752
& mut self ,
753
753
keep_open : bool ,
754
754
descriptor : & ' a metal:: RenderPassDescriptorRef ,
755
- frames : F ,
756
755
init_commands : I ,
757
756
) where
758
- F : Iterator < Item = ( usize , native:: Frame ) > ,
759
757
I : Iterator < Item = soft:: RenderCommand < & ' a soft:: Own > > ,
760
758
{
761
759
self . stop_encoding ( ) ;
762
760
763
761
match * self {
764
762
CommandSink :: Immediate { ref cmd_buffer, ref mut encoder_state, .. } => {
765
763
let _ap = AutoreleasePool :: new ( ) ;
766
- resolve_frames ( descriptor, frames) ;
767
764
let encoder = cmd_buffer. new_render_command_encoder ( descriptor) ;
768
765
for command in init_commands {
769
766
exec_render ( encoder, command) ;
@@ -778,7 +775,6 @@ impl CommandSink {
778
775
* is_encoding = keep_open;
779
776
passes. push ( soft:: Pass :: Render {
780
777
desc : descriptor. to_owned ( ) ,
781
- frames : frames. collect ( ) ,
782
778
commands : init_commands. map ( soft:: RenderCommand :: own) . collect ( ) ,
783
779
} ) ;
784
780
}
@@ -960,14 +956,6 @@ fn exec_render<'a>(encoder: &metal::RenderCommandEncoderRef, command: soft::Rend
960
956
}
961
957
}
962
958
Cmd :: BindTexture { stage, index, texture } => {
963
- let guard;
964
- let texture = match texture {
965
- Some ( root) => {
966
- guard = root. resolve ( ) ;
967
- Some ( & * guard)
968
- }
969
- None => None ,
970
- } ;
971
959
match stage {
972
960
pso:: Stage :: Vertex =>
973
961
encoder. set_vertex_texture ( index as _ , texture) ,
@@ -1081,12 +1069,12 @@ fn exec_blit<'a>(encoder: &metal::BlitCommandEncoderRef, command: soft::BlitComm
1081
1069
let layers = region. src_subresource . layers . zip ( region. dst_subresource . layers ) ;
1082
1070
for ( src_layer, dst_layer) in layers {
1083
1071
encoder. copy_from_texture (
1084
- & * src. resolve ( ) ,
1072
+ src,
1085
1073
src_layer as _ ,
1086
1074
region. src_subresource . level as _ ,
1087
1075
src_offset,
1088
1076
size,
1089
- & * dst. resolve ( ) ,
1077
+ dst,
1090
1078
dst_layer as _ ,
1091
1079
region. dst_subresource . level as _ ,
1092
1080
dst_offset,
@@ -1107,7 +1095,7 @@ fn exec_blit<'a>(encoder: &metal::BlitCommandEncoderRef, command: soft::BlitComm
1107
1095
row_pitch as NSUInteger ,
1108
1096
slice_pitch as NSUInteger ,
1109
1097
extent,
1110
- & * dst. resolve ( ) ,
1098
+ dst,
1111
1099
layer as NSUInteger ,
1112
1100
r. level as NSUInteger ,
1113
1101
origin,
@@ -1124,7 +1112,7 @@ fn exec_blit<'a>(encoder: &metal::BlitCommandEncoderRef, command: soft::BlitComm
1124
1112
for layer in r. layers . clone ( ) {
1125
1113
let offset = region. buffer_offset + slice_pitch as NSUInteger * ( layer - r. layers . start ) as NSUInteger ;
1126
1114
encoder. copy_from_texture_to_buffer (
1127
- & * src. resolve ( ) ,
1115
+ src,
1128
1116
layer as NSUInteger ,
1129
1117
r. level as NSUInteger ,
1130
1118
origin,
@@ -1150,14 +1138,6 @@ fn exec_compute<'a>(encoder: &metal::ComputeCommandEncoderRef, command: soft::Co
1150
1138
encoder. set_bytes ( index as _ , ( words. len ( ) * WORD_SIZE ) as u64 , words. as_ptr ( ) as _ ) ;
1151
1139
}
1152
1140
Cmd :: BindTexture { index, texture } => {
1153
- let guard;
1154
- let texture = match texture {
1155
- Some ( ref root) => {
1156
- guard = root. resolve ( ) ;
1157
- Some ( & * guard)
1158
- }
1159
- None => None ,
1160
- } ;
1161
1141
encoder. set_texture ( index as _ , texture) ;
1162
1142
}
1163
1143
Cmd :: BindSampler { index, sampler } => {
@@ -1175,28 +1155,11 @@ fn exec_compute<'a>(encoder: &metal::ComputeCommandEncoderRef, command: soft::Co
1175
1155
}
1176
1156
}
1177
1157
1178
- fn resolve_frames < I > ( desc : & metal:: RenderPassDescriptorRef , frames : I )
1179
- where
1180
- I : IntoIterator ,
1181
- I :: Item : Borrow < ( usize , native:: Frame ) > ,
1182
- {
1183
- for f in frames {
1184
- let ( index, ref frame) = * f. borrow ( ) ;
1185
- let swapchain = frame. swapchain . read ( ) . unwrap ( ) ;
1186
- desc
1187
- . color_attachments ( )
1188
- . object_at ( index as _ )
1189
- . unwrap ( )
1190
- . set_texture ( Some ( & swapchain[ frame. index ] ) )
1191
- }
1192
- }
1193
-
1194
1158
fn record_commands ( command_buf : & metal:: CommandBufferRef , passes : & [ soft:: Pass ] ) {
1195
1159
let _ap = AutoreleasePool :: new ( ) ; // for encoder creation
1196
1160
for pass in passes {
1197
1161
match * pass {
1198
- soft:: Pass :: Render { ref desc, ref frames, ref commands } => {
1199
- resolve_frames ( desc, frames) ;
1162
+ soft:: Pass :: Render { ref desc, ref commands } => {
1200
1163
let encoder = command_buf. new_render_command_encoder ( desc) ;
1201
1164
for command in commands {
1202
1165
exec_render ( & encoder, command. as_ref ( ) ) ;
@@ -1618,38 +1581,30 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1618
1581
for subresource_range in subresource_ranges {
1619
1582
let sub = subresource_range. borrow ( ) ;
1620
1583
1621
- let mut frame = None ;
1622
1584
let num_layers = ( sub. layers . end - sub. layers . start ) as u64 ;
1623
1585
let layers = if CLEAR_IMAGE_ARRAY {
1624
1586
0 .. 1
1625
1587
} else {
1626
1588
sub. layers . clone ( )
1627
1589
} ;
1628
1590
let texture = if CLEAR_IMAGE_ARRAY && sub. layers . start > 0 {
1629
- let image_raw = image. root . as_ref ( ) . resolve ( ) ;
1630
1591
// aliasing is necessary for bulk-clearing all layers starting with 0
1631
- let tex = image_raw . new_texture_view_from_slice (
1592
+ let tex = image . raw . new_texture_view_from_slice (
1632
1593
image. mtl_format ,
1633
1594
image. mtl_type ,
1634
1595
NSRange {
1635
1596
location : 0 ,
1636
- length : image_raw . mipmap_level_count ( ) ,
1597
+ length : image . raw . mipmap_level_count ( ) ,
1637
1598
} ,
1638
1599
NSRange {
1639
1600
location : sub. layers . start as _ ,
1640
1601
length : num_layers,
1641
1602
} ,
1642
1603
) ;
1643
1604
retained_textures. push ( tex) ;
1644
- retained_textures. last ( ) . map ( |tex| tex . as_ref ( ) )
1605
+ retained_textures. last ( ) . unwrap ( )
1645
1606
} else {
1646
- match image. root {
1647
- native:: ImageRoot :: Texture ( ref tex) => Some ( tex. as_ref ( ) ) ,
1648
- native:: ImageRoot :: Frame ( ref f) => {
1649
- frame = Some ( ( 0usize , f. clone ( ) ) ) ;
1650
- None
1651
- }
1652
- }
1607
+ & * image. raw
1653
1608
} ;
1654
1609
1655
1610
for layer in layers {
@@ -1669,7 +1624,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1669
1624
. color_attachments ( )
1670
1625
. object_at ( 0 )
1671
1626
. unwrap ( ) ;
1672
- attachment. set_texture ( texture) ;
1627
+ attachment. set_texture ( Some ( texture) ) ;
1673
1628
attachment. set_level ( level as _ ) ;
1674
1629
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1675
1630
if !CLEAR_IMAGE_ARRAY {
@@ -1688,7 +1643,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1688
1643
let attachment = descriptor
1689
1644
. depth_attachment ( )
1690
1645
. unwrap ( ) ;
1691
- attachment. set_texture ( texture) ;
1646
+ attachment. set_texture ( Some ( texture) ) ;
1692
1647
attachment. set_level ( level as _ ) ;
1693
1648
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1694
1649
if !CLEAR_IMAGE_ARRAY {
@@ -1707,7 +1662,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1707
1662
let attachment = descriptor
1708
1663
. stencil_attachment ( )
1709
1664
. unwrap ( ) ;
1710
- attachment. set_texture ( texture) ;
1665
+ attachment. set_texture ( Some ( texture) ) ;
1711
1666
attachment. set_level ( level as _ ) ;
1712
1667
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1713
1668
if !CLEAR_IMAGE_ARRAY {
@@ -1723,7 +1678,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1723
1678
1724
1679
sink. as_mut ( )
1725
1680
. unwrap ( )
1726
- . begin_render_pass ( false , descriptor, frame . clone ( ) . into_iter ( ) , None . into_iter ( ) ) ;
1681
+ . begin_render_pass ( false , descriptor, None . into_iter ( ) ) ;
1727
1682
// no actual pass body - everything is in the attachment clear operations
1728
1683
}
1729
1684
}
@@ -1964,15 +1919,6 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1964
1919
let vertices = & mut self . temp . blit_vertices ;
1965
1920
vertices. clear ( ) ;
1966
1921
1967
- let mut frame = None ;
1968
- let dst_texture = match dst. root {
1969
- native:: ImageRoot :: Texture ( ref tex) => Some ( tex. as_ref ( ) ) ,
1970
- native:: ImageRoot :: Frame ( ref f) => {
1971
- frame = Some ( ( 0usize , f. clone ( ) ) ) ;
1972
- None
1973
- }
1974
- } ;
1975
-
1976
1922
for region in regions {
1977
1923
let r = region. borrow ( ) ;
1978
1924
@@ -2077,7 +2023,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2077
2023
soft:: RenderCommand :: BindTexture {
2078
2024
stage : pso:: Stage :: Fragment ,
2079
2025
index : 0 ,
2080
- texture : Some ( src. root . as_ref ( ) )
2026
+ texture : Some ( & * src. raw )
2081
2027
} ,
2082
2028
] ;
2083
2029
@@ -2132,21 +2078,21 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2132
2078
. color_attachments ( )
2133
2079
. object_at ( 0 )
2134
2080
. unwrap ( ) ;
2135
- attachment. set_texture ( dst_texture ) ;
2081
+ attachment. set_texture ( Some ( & dst . raw ) ) ;
2136
2082
attachment. set_level ( level as _ ) ;
2137
2083
}
2138
2084
if aspects. contains ( Aspects :: DEPTH ) {
2139
2085
let attachment = descriptor
2140
2086
. depth_attachment ( )
2141
2087
. unwrap ( ) ;
2142
- attachment. set_texture ( dst_texture ) ;
2088
+ attachment. set_texture ( Some ( & dst . raw ) ) ;
2143
2089
attachment. set_level ( level as _ ) ;
2144
2090
}
2145
2091
if aspects. contains ( Aspects :: STENCIL ) {
2146
2092
let attachment = descriptor
2147
2093
. stencil_attachment ( )
2148
2094
. unwrap ( ) ;
2149
- attachment. set_texture ( dst_texture ) ;
2095
+ attachment. set_texture ( Some ( & dst . raw ) ) ;
2150
2096
attachment. set_level ( level as _ ) ;
2151
2097
}
2152
2098
@@ -2156,7 +2102,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2156
2102
. chain ( & extra)
2157
2103
. cloned ( ) ;
2158
2104
2159
- inner. sink ( ) . begin_render_pass ( false , descriptor, frame . clone ( ) . into_iter ( ) , commands) ;
2105
+ inner. sink ( ) . begin_render_pass ( false , descriptor, commands) ;
2160
2106
}
2161
2107
}
2162
2108
@@ -2380,14 +2326,10 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2380
2326
} ;
2381
2327
2382
2328
self . state . framebuffer_inner = framebuffer. inner . clone ( ) ;
2383
- let frames = framebuffer. inner . colors
2384
- . iter ( )
2385
- . enumerate ( )
2386
- . filter_map ( |( index, ref cat) | cat. frame . clone ( ) . map ( |f| ( index, f) ) ) ;
2387
2329
let init_commands = self . state . make_render_commands ( full_aspects) ;
2388
2330
inner
2389
2331
. sink ( )
2390
- . begin_render_pass ( true , & descriptor, frames , init_commands) ;
2332
+ . begin_render_pass ( true , & descriptor, init_commands) ;
2391
2333
}
2392
2334
2393
2335
fn next_subpass ( & mut self , _contents : com:: SubpassContents ) {
@@ -2918,18 +2860,18 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2918
2860
} = * self . inner . borrow_mut ( ) ;
2919
2861
2920
2862
let new_src = if src. mtl_format == dst. mtl_format {
2921
- src. root . clone ( )
2863
+ & * src. raw
2922
2864
} else {
2923
2865
assert_eq ! ( src. format_desc. bits, dst. format_desc. bits) ;
2924
- let tex = src. root . as_ref ( ) . resolve ( ) . new_texture_view ( dst. mtl_format ) ;
2925
- retained_textures. push ( tex. clone ( ) ) ;
2926
- native :: ImageRoot :: Texture ( tex )
2866
+ let tex = src. raw . new_texture_view ( dst. mtl_format ) ;
2867
+ retained_textures. push ( tex) ;
2868
+ retained_textures . last ( ) . unwrap ( )
2927
2869
} ;
2928
2870
2929
2871
let commands = regions. into_iter ( ) . map ( |region| {
2930
2872
soft:: BlitCommand :: CopyImage {
2931
- src : new_src. as_ref ( ) ,
2932
- dst : dst. root . as_ref ( ) ,
2873
+ src : new_src,
2874
+ dst : & * dst. raw ,
2933
2875
region : region. borrow ( ) . clone ( ) ,
2934
2876
}
2935
2877
} ) ;
@@ -2952,7 +2894,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2952
2894
let commands = regions. into_iter ( ) . map ( |region| {
2953
2895
soft:: BlitCommand :: CopyBufferToImage {
2954
2896
src : & * src. raw ,
2955
- dst : dst. root . as_ref ( ) ,
2897
+ dst : & * dst. raw ,
2956
2898
dst_desc : dst. format_desc ,
2957
2899
region : region. borrow ( ) . clone ( ) ,
2958
2900
}
@@ -2976,9 +2918,9 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2976
2918
// FIXME: layout
2977
2919
let commands = regions. into_iter ( ) . map ( |region| {
2978
2920
soft:: BlitCommand :: CopyImageToBuffer {
2979
- src : src. root . as_ref ( ) ,
2921
+ src : & * src. raw ,
2980
2922
src_desc : src. format_desc ,
2981
- dst : dst. raw . as_ref ( ) ,
2923
+ dst : & * dst. raw ,
2982
2924
region : region. borrow ( ) . clone ( ) ,
2983
2925
}
2984
2926
} ) ;
0 commit comments