@@ -547,7 +547,7 @@ impl State {
547
547
#[ derive( Clone , Debug ) ]
548
548
struct StageResources {
549
549
buffers : Vec < Option < ( metal:: Buffer , buffer:: Offset ) > > ,
550
- textures : Vec < Option < native :: ImageRoot > > ,
550
+ textures : Vec < Option < metal :: Texture > > ,
551
551
samplers : Vec < Option < metal:: SamplerState > > ,
552
552
push_constants_buffer_id : Option < u32 > ,
553
553
}
@@ -576,12 +576,12 @@ impl StageResources {
576
576
self . buffers [ slot] = Some ( ( buffer. to_owned ( ) , offset) ) ;
577
577
}
578
578
579
- fn add_textures ( & mut self , start : usize , roots : & [ Option < ( native :: ImageRoot , Layout ) > ] ) {
580
- while self . textures . len ( ) < start + roots . len ( ) {
579
+ fn add_textures ( & mut self , start : usize , textures : & [ Option < ( metal :: Texture , Layout ) > ] ) {
580
+ while self . textures . len ( ) < start + textures . len ( ) {
581
581
self . textures . push ( None )
582
582
}
583
- for ( out, root ) in self . textures [ start..] . iter_mut ( ) . zip ( roots . iter ( ) ) {
584
- * out = root . as_ref ( ) . map ( |& ( ref root , _) | root . clone ( ) ) ;
583
+ for ( out, tex ) in self . textures [ start..] . iter_mut ( ) . zip ( textures . iter ( ) ) {
584
+ * out = tex . as_ref ( ) . map ( |& ( ref t , _) | t . to_owned ( ) ) ;
585
585
}
586
586
}
587
587
@@ -762,22 +762,19 @@ impl CommandSink {
762
762
}
763
763
}
764
764
765
- fn begin_render_pass < ' a , F , I > (
765
+ fn begin_render_pass < ' a , I > (
766
766
& mut self ,
767
767
keep_open : bool ,
768
768
descriptor : & ' a metal:: RenderPassDescriptorRef ,
769
- frames : F ,
770
769
init_commands : I ,
771
770
) where
772
- F : Iterator < Item = ( usize , native:: Frame ) > ,
773
771
I : Iterator < Item = soft:: RenderCommand < & ' a soft:: Own > > ,
774
772
{
775
773
self . stop_encoding ( ) ;
776
774
777
775
match * self {
778
776
CommandSink :: Immediate { ref cmd_buffer, ref mut encoder_state, .. } => {
779
777
let _ap = AutoreleasePool :: new ( ) ;
780
- resolve_frames ( descriptor, frames) ;
781
778
let encoder = cmd_buffer. new_render_command_encoder ( descriptor) ;
782
779
for command in init_commands {
783
780
exec_render ( encoder, command) ;
@@ -792,7 +789,6 @@ impl CommandSink {
792
789
* is_encoding = keep_open;
793
790
passes. push ( soft:: Pass :: Render {
794
791
desc : descriptor. to_owned ( ) ,
795
- frames : frames. collect ( ) ,
796
792
commands : init_commands. map ( soft:: RenderCommand :: own) . collect ( ) ,
797
793
} ) ;
798
794
}
@@ -974,14 +970,6 @@ fn exec_render<'a>(encoder: &metal::RenderCommandEncoderRef, command: soft::Rend
974
970
}
975
971
}
976
972
Cmd :: BindTexture { stage, index, texture } => {
977
- let guard;
978
- let texture = match texture {
979
- Some ( root) => {
980
- guard = root. resolve ( ) ;
981
- Some ( & * guard)
982
- }
983
- None => None ,
984
- } ;
985
973
match stage {
986
974
pso:: Stage :: Vertex =>
987
975
encoder. set_vertex_texture ( index as _ , texture) ,
@@ -1095,12 +1083,12 @@ fn exec_blit<'a>(encoder: &metal::BlitCommandEncoderRef, command: soft::BlitComm
1095
1083
let layers = region. src_subresource . layers . zip ( region. dst_subresource . layers ) ;
1096
1084
for ( src_layer, dst_layer) in layers {
1097
1085
encoder. copy_from_texture (
1098
- & * src. resolve ( ) ,
1086
+ src,
1099
1087
src_layer as _ ,
1100
1088
region. src_subresource . level as _ ,
1101
1089
src_offset,
1102
1090
size,
1103
- & * dst. resolve ( ) ,
1091
+ dst,
1104
1092
dst_layer as _ ,
1105
1093
region. dst_subresource . level as _ ,
1106
1094
dst_offset,
@@ -1121,7 +1109,7 @@ fn exec_blit<'a>(encoder: &metal::BlitCommandEncoderRef, command: soft::BlitComm
1121
1109
row_pitch as NSUInteger ,
1122
1110
slice_pitch as NSUInteger ,
1123
1111
extent,
1124
- & * dst. resolve ( ) ,
1112
+ dst,
1125
1113
layer as NSUInteger ,
1126
1114
r. level as NSUInteger ,
1127
1115
origin,
@@ -1138,7 +1126,7 @@ fn exec_blit<'a>(encoder: &metal::BlitCommandEncoderRef, command: soft::BlitComm
1138
1126
for layer in r. layers . clone ( ) {
1139
1127
let offset = region. buffer_offset + slice_pitch as NSUInteger * ( layer - r. layers . start ) as NSUInteger ;
1140
1128
encoder. copy_from_texture_to_buffer (
1141
- & * src. resolve ( ) ,
1129
+ src,
1142
1130
layer as NSUInteger ,
1143
1131
r. level as NSUInteger ,
1144
1132
origin,
@@ -1164,14 +1152,6 @@ fn exec_compute<'a>(encoder: &metal::ComputeCommandEncoderRef, command: soft::Co
1164
1152
encoder. set_bytes ( index as _ , words. len ( ) as u64 * 4 , words. as_ptr ( ) as _ ) ;
1165
1153
}
1166
1154
Cmd :: BindTexture { index, texture } => {
1167
- let guard;
1168
- let texture = match texture {
1169
- Some ( ref root) => {
1170
- guard = root. resolve ( ) ;
1171
- Some ( & * guard)
1172
- }
1173
- None => None ,
1174
- } ;
1175
1155
encoder. set_texture ( index as _ , texture) ;
1176
1156
}
1177
1157
Cmd :: BindSampler { index, sampler } => {
@@ -1189,28 +1169,11 @@ fn exec_compute<'a>(encoder: &metal::ComputeCommandEncoderRef, command: soft::Co
1189
1169
}
1190
1170
}
1191
1171
1192
- fn resolve_frames < I > ( desc : & metal:: RenderPassDescriptorRef , frames : I )
1193
- where
1194
- I : IntoIterator ,
1195
- I :: Item : Borrow < ( usize , native:: Frame ) > ,
1196
- {
1197
- for f in frames {
1198
- let ( index, ref frame) = * f. borrow ( ) ;
1199
- let swapchain = frame. swapchain . read ( ) . unwrap ( ) ;
1200
- desc
1201
- . color_attachments ( )
1202
- . object_at ( index as _ )
1203
- . unwrap ( )
1204
- . set_texture ( Some ( & swapchain[ frame. index ] ) )
1205
- }
1206
- }
1207
-
1208
1172
fn record_commands ( command_buf : & metal:: CommandBufferRef , passes : & [ soft:: Pass ] ) {
1209
1173
let _ap = AutoreleasePool :: new ( ) ; // for encoder creation
1210
1174
for pass in passes {
1211
1175
match * pass {
1212
- soft:: Pass :: Render { ref desc, ref frames, ref commands } => {
1213
- resolve_frames ( desc, frames) ;
1176
+ soft:: Pass :: Render { ref desc, ref commands } => {
1214
1177
let encoder = command_buf. new_render_command_encoder ( desc) ;
1215
1178
for command in commands {
1216
1179
exec_render ( & encoder, command. as_ref ( ) ) ;
@@ -1632,38 +1595,30 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1632
1595
for subresource_range in subresource_ranges {
1633
1596
let sub = subresource_range. borrow ( ) ;
1634
1597
1635
- let mut frame = None ;
1636
1598
let num_layers = ( sub. layers . end - sub. layers . start ) as u64 ;
1637
1599
let layers = if CLEAR_IMAGE_ARRAY {
1638
1600
0 .. 1
1639
1601
} else {
1640
1602
sub. layers . clone ( )
1641
1603
} ;
1642
1604
let texture = if CLEAR_IMAGE_ARRAY && sub. layers . start > 0 {
1643
- let image_raw = image. root . as_ref ( ) . resolve ( ) ;
1644
1605
// aliasing is necessary for bulk-clearing all layers starting with 0
1645
- let tex = image_raw . new_texture_view_from_slice (
1606
+ let tex = image . raw . new_texture_view_from_slice (
1646
1607
image. mtl_format ,
1647
1608
image. mtl_type ,
1648
1609
NSRange {
1649
1610
location : 0 ,
1650
- length : image_raw . mipmap_level_count ( ) ,
1611
+ length : image . raw . mipmap_level_count ( ) ,
1651
1612
} ,
1652
1613
NSRange {
1653
1614
location : sub. layers . start as _ ,
1654
1615
length : num_layers,
1655
1616
} ,
1656
1617
) ;
1657
1618
retained_textures. push ( tex) ;
1658
- retained_textures. last ( ) . map ( |tex| tex . as_ref ( ) )
1619
+ retained_textures. last ( ) . unwrap ( )
1659
1620
} else {
1660
- match image. root {
1661
- native:: ImageRoot :: Texture ( ref tex) => Some ( tex. as_ref ( ) ) ,
1662
- native:: ImageRoot :: Frame ( ref f) => {
1663
- frame = Some ( ( 0usize , f. clone ( ) ) ) ;
1664
- None
1665
- }
1666
- }
1621
+ & * image. raw
1667
1622
} ;
1668
1623
1669
1624
for layer in layers {
@@ -1683,7 +1638,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1683
1638
. color_attachments ( )
1684
1639
. object_at ( 0 )
1685
1640
. unwrap ( ) ;
1686
- attachment. set_texture ( texture) ;
1641
+ attachment. set_texture ( Some ( texture) ) ;
1687
1642
attachment. set_level ( level as _ ) ;
1688
1643
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1689
1644
if !CLEAR_IMAGE_ARRAY {
@@ -1702,7 +1657,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1702
1657
let attachment = descriptor
1703
1658
. depth_attachment ( )
1704
1659
. unwrap ( ) ;
1705
- attachment. set_texture ( texture) ;
1660
+ attachment. set_texture ( Some ( texture) ) ;
1706
1661
attachment. set_level ( level as _ ) ;
1707
1662
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1708
1663
if !CLEAR_IMAGE_ARRAY {
@@ -1721,7 +1676,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1721
1676
let attachment = descriptor
1722
1677
. stencil_attachment ( )
1723
1678
. unwrap ( ) ;
1724
- attachment. set_texture ( texture) ;
1679
+ attachment. set_texture ( Some ( texture) ) ;
1725
1680
attachment. set_level ( level as _ ) ;
1726
1681
attachment. set_store_action ( metal:: MTLStoreAction :: Store ) ;
1727
1682
if !CLEAR_IMAGE_ARRAY {
@@ -1737,7 +1692,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1737
1692
1738
1693
sink. as_mut ( )
1739
1694
. unwrap ( )
1740
- . begin_render_pass ( false , descriptor, frame . clone ( ) . into_iter ( ) , None . into_iter ( ) ) ;
1695
+ . begin_render_pass ( false , descriptor, None . into_iter ( ) ) ;
1741
1696
// no actual pass body - everything is in the attachment clear operations
1742
1697
}
1743
1698
}
@@ -1977,15 +1932,6 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
1977
1932
let vertices = & mut self . temp . blit_vertices ;
1978
1933
vertices. clear ( ) ;
1979
1934
1980
- let mut frame = None ;
1981
- let dst_texture = match dst. root {
1982
- native:: ImageRoot :: Texture ( ref tex) => Some ( tex. as_ref ( ) ) ,
1983
- native:: ImageRoot :: Frame ( ref f) => {
1984
- frame = Some ( ( 0usize , f. clone ( ) ) ) ;
1985
- None
1986
- }
1987
- } ;
1988
-
1989
1935
for region in regions {
1990
1936
let r = region. borrow ( ) ;
1991
1937
@@ -2090,7 +2036,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2090
2036
soft:: RenderCommand :: BindTexture {
2091
2037
stage : pso:: Stage :: Fragment ,
2092
2038
index : 0 ,
2093
- texture : Some ( src. root . as_ref ( ) )
2039
+ texture : Some ( & * src. raw )
2094
2040
} ,
2095
2041
] ;
2096
2042
@@ -2145,21 +2091,21 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2145
2091
. color_attachments ( )
2146
2092
. object_at ( 0 )
2147
2093
. unwrap ( ) ;
2148
- attachment. set_texture ( dst_texture ) ;
2094
+ attachment. set_texture ( Some ( & dst . raw ) ) ;
2149
2095
attachment. set_level ( level as _ ) ;
2150
2096
}
2151
2097
if aspects. contains ( Aspects :: DEPTH ) {
2152
2098
let attachment = descriptor
2153
2099
. depth_attachment ( )
2154
2100
. unwrap ( ) ;
2155
- attachment. set_texture ( dst_texture ) ;
2101
+ attachment. set_texture ( Some ( & dst . raw ) ) ;
2156
2102
attachment. set_level ( level as _ ) ;
2157
2103
}
2158
2104
if aspects. contains ( Aspects :: STENCIL ) {
2159
2105
let attachment = descriptor
2160
2106
. stencil_attachment ( )
2161
2107
. unwrap ( ) ;
2162
- attachment. set_texture ( dst_texture ) ;
2108
+ attachment. set_texture ( Some ( & dst . raw ) ) ;
2163
2109
attachment. set_level ( level as _ ) ;
2164
2110
}
2165
2111
@@ -2169,7 +2115,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2169
2115
. chain ( & extra)
2170
2116
. cloned ( ) ;
2171
2117
2172
- inner. sink ( ) . begin_render_pass ( false , descriptor, frame . clone ( ) . into_iter ( ) , commands) ;
2118
+ inner. sink ( ) . begin_render_pass ( false , descriptor, commands) ;
2173
2119
}
2174
2120
}
2175
2121
@@ -2393,14 +2339,10 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2393
2339
} ;
2394
2340
2395
2341
self . state . framebuffer_inner = framebuffer. inner . clone ( ) ;
2396
- let frames = framebuffer. inner . colors
2397
- . iter ( )
2398
- . enumerate ( )
2399
- . filter_map ( |( index, ref cat) | cat. frame . clone ( ) . map ( |f| ( index, f) ) ) ;
2400
2342
let init_commands = self . state . make_render_commands ( full_aspects) ;
2401
2343
inner
2402
2344
. sink ( )
2403
- . begin_render_pass ( true , & descriptor, frames , init_commands) ;
2345
+ . begin_render_pass ( true , & descriptor, init_commands) ;
2404
2346
}
2405
2347
2406
2348
fn next_subpass ( & mut self , _contents : com:: SubpassContents ) {
@@ -2933,18 +2875,18 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2933
2875
} = * self . inner . borrow_mut ( ) ;
2934
2876
2935
2877
let new_src = if src. mtl_format == dst. mtl_format {
2936
- src. root . clone ( )
2878
+ & * src. raw
2937
2879
} else {
2938
2880
assert_eq ! ( src. format_desc. bits, dst. format_desc. bits) ;
2939
- let tex = src. root . as_ref ( ) . resolve ( ) . new_texture_view ( dst. mtl_format ) ;
2940
- retained_textures. push ( tex. clone ( ) ) ;
2941
- native :: ImageRoot :: Texture ( tex )
2881
+ let tex = src. raw . new_texture_view ( dst. mtl_format ) ;
2882
+ retained_textures. push ( tex) ;
2883
+ retained_textures . last ( ) . unwrap ( )
2942
2884
} ;
2943
2885
2944
2886
let commands = regions. into_iter ( ) . map ( |region| {
2945
2887
soft:: BlitCommand :: CopyImage {
2946
- src : new_src. as_ref ( ) ,
2947
- dst : dst. root . as_ref ( ) ,
2888
+ src : new_src,
2889
+ dst : & * dst. raw ,
2948
2890
region : region. borrow ( ) . clone ( ) ,
2949
2891
}
2950
2892
} ) ;
@@ -2967,7 +2909,7 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2967
2909
let commands = regions. into_iter ( ) . map ( |region| {
2968
2910
soft:: BlitCommand :: CopyBufferToImage {
2969
2911
src : & * src. raw ,
2970
- dst : dst. root . as_ref ( ) ,
2912
+ dst : & * dst. raw ,
2971
2913
dst_desc : dst. format_desc ,
2972
2914
region : region. borrow ( ) . clone ( ) ,
2973
2915
}
@@ -2991,9 +2933,9 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
2991
2933
// FIXME: layout
2992
2934
let commands = regions. into_iter ( ) . map ( |region| {
2993
2935
soft:: BlitCommand :: CopyImageToBuffer {
2994
- src : src. root . as_ref ( ) ,
2936
+ src : & * src. raw ,
2995
2937
src_desc : src. format_desc ,
2996
- dst : dst. raw . as_ref ( ) ,
2938
+ dst : & * dst. raw ,
2997
2939
region : region. borrow ( ) . clone ( ) ,
2998
2940
}
2999
2941
} ) ;
0 commit comments