@@ -550,7 +550,9 @@ pub extern "C" fn wgpu_device_create_texture(
550
550
551
551
pub fn texture_create_view (
552
552
texture_id : TextureId ,
553
- desc : & resource:: TextureViewDescriptor ,
553
+ format : resource:: TextureFormat ,
554
+ view_kind : hal:: image:: ViewKind ,
555
+ range : hal:: image:: SubresourceRange ,
554
556
) -> resource:: TextureView < back:: Backend > {
555
557
let texture_guard = HUB . textures . read ( ) ;
556
558
let texture = & texture_guard[ texture_id] ;
@@ -561,14 +563,10 @@ pub fn texture_create_view(
561
563
[ texture. device_id . value ] . raw
562
564
. create_image_view (
563
565
& texture. raw ,
564
- conv :: map_texture_view_dimension ( desc . dimension ) ,
565
- conv:: map_texture_format ( desc . format ) ,
566
+ view_kind ,
567
+ conv:: map_texture_format ( format) ,
566
568
hal:: format:: Swizzle :: NO ,
567
- hal:: image:: SubresourceRange {
568
- aspects : conv:: map_texture_aspect_flags ( desc. aspect ) ,
569
- levels : desc. base_mip_level as u8 .. ( desc. base_mip_level + desc. level_count ) as u8 ,
570
- layers : desc. base_array_layer as u16 .. ( desc. base_array_layer + desc. array_count ) as u16 ,
571
- } ,
569
+ range,
572
570
)
573
571
. unwrap ( )
574
572
} ;
@@ -610,61 +608,43 @@ pub extern "C" fn wgpu_texture_create_view(
610
608
texture_id : TextureId ,
611
609
desc : & resource:: TextureViewDescriptor ,
612
610
) -> TextureViewId {
613
- let view = texture_create_view ( texture_id, desc) ;
614
- let texture_id = view. texture_id . value ;
611
+ let view = texture_create_view (
612
+ texture_id,
613
+ desc. format ,
614
+ conv:: map_texture_view_dimension ( desc. dimension ) ,
615
+ hal:: image:: SubresourceRange {
616
+ aspects : conv:: map_texture_aspect_flags ( desc. aspect ) ,
617
+ levels : desc. base_mip_level as u8 .. ( desc. base_mip_level + desc. level_count ) as u8 ,
618
+ layers : desc. base_array_layer as u16 .. ( desc. base_array_layer + desc. array_count ) as u16 ,
619
+ } ,
620
+ ) ;
615
621
let ref_count = view. life_guard . ref_count . clone ( ) ;
616
622
let id = HUB . texture_views . register_local ( view) ;
617
623
device_track_view ( texture_id, id, ref_count) ;
618
624
id
619
625
}
620
626
621
- pub fn texture_create_default_view (
622
- texture_id : TextureId
623
- ) -> resource:: TextureView < back:: Backend > {
624
- let texture_guard = HUB . textures . read ( ) ;
625
- let texture = & texture_guard[ texture_id] ;
626
-
627
- let view_kind = match texture. kind {
628
- hal:: image:: Kind :: D1 ( _, 1 ) => hal:: image:: ViewKind :: D1 ,
629
- hal:: image:: Kind :: D1 ( ..) => hal:: image:: ViewKind :: D1Array ,
630
- hal:: image:: Kind :: D2 ( _, _, 1 , _) => hal:: image:: ViewKind :: D2 ,
631
- hal:: image:: Kind :: D2 ( ..) => hal:: image:: ViewKind :: D2Array ,
632
- hal:: image:: Kind :: D3 ( ..) => hal:: image:: ViewKind :: D3 ,
633
- } ;
634
-
635
- let raw = unsafe {
636
- HUB . devices
637
- . read ( )
638
- [ texture. device_id . value ] . raw
639
- . create_image_view (
640
- & texture. raw ,
641
- view_kind,
642
- conv:: map_texture_format ( texture. format ) ,
643
- hal:: format:: Swizzle :: NO ,
644
- texture. full_range . clone ( ) ,
645
- )
646
- . unwrap ( )
647
- } ;
648
-
649
- resource:: TextureView {
650
- raw,
651
- texture_id : Stored {
652
- value : texture_id,
653
- ref_count : texture. life_guard . ref_count . clone ( ) ,
654
- } ,
655
- format : texture. format ,
656
- extent : texture. kind . extent ( ) ,
657
- samples : texture. kind . num_samples ( ) ,
658
- is_owned_by_swap_chain : false ,
659
- life_guard : LifeGuard :: new ( ) ,
660
- }
661
- }
662
-
663
627
#[ cfg( feature = "local" ) ]
664
628
#[ no_mangle]
665
629
pub extern "C" fn wgpu_texture_create_default_view ( texture_id : TextureId ) -> TextureViewId {
666
- let view = texture_create_default_view ( texture_id) ;
667
- let texture_id = view. texture_id . value ;
630
+ let ( format, view_kind, range) = {
631
+ let texture_guard = HUB . textures . read ( ) ;
632
+ let texture = & texture_guard[ texture_id] ;
633
+ let view_kind = match texture. kind {
634
+ hal:: image:: Kind :: D1 ( _, 1 ) => hal:: image:: ViewKind :: D1 ,
635
+ hal:: image:: Kind :: D1 ( ..) => hal:: image:: ViewKind :: D1Array ,
636
+ hal:: image:: Kind :: D2 ( _, _, 1 , _) => hal:: image:: ViewKind :: D2 ,
637
+ hal:: image:: Kind :: D2 ( ..) => hal:: image:: ViewKind :: D2Array ,
638
+ hal:: image:: Kind :: D3 ( ..) => hal:: image:: ViewKind :: D3 ,
639
+ } ;
640
+ ( texture. format , view_kind, texture. full_range . clone ( ) )
641
+ } ;
642
+ let view = texture_create_view (
643
+ texture_id,
644
+ format,
645
+ view_kind,
646
+ range,
647
+ ) ;
668
648
let ref_count = view. life_guard . ref_count . clone ( ) ;
669
649
let id = HUB . texture_views . register_local ( view) ;
670
650
device_track_view ( texture_id, id, ref_count) ;
0 commit comments