@@ -217,20 +217,32 @@ impl super::DeviceShared {
217
217
. iter ( )
218
218
. map ( |at| self . private_caps . map_texture_format ( at. view_format ) )
219
219
. collect :: < ArrayVec < _ , { super :: MAX_TOTAL_ATTACHMENTS } > > ( ) ;
220
+ let vk_view_formats_list = e
221
+ . key ( )
222
+ . attachments
223
+ . iter ( )
224
+ . map ( |at| at. raw_view_formats . clone ( ) )
225
+ . collect :: < ArrayVec < _ , { super :: MAX_TOTAL_ATTACHMENTS } > > ( ) ;
226
+
220
227
let vk_image_infos = e
221
228
. key ( )
222
229
. attachments
223
230
. iter ( )
224
231
. enumerate ( )
225
232
. map ( |( i, at) | {
226
- vk:: FramebufferAttachmentImageInfo :: builder ( )
233
+ let mut info = vk:: FramebufferAttachmentImageInfo :: builder ( )
227
234
. usage ( conv:: map_texture_usage ( at. view_usage ) )
228
235
. flags ( at. raw_image_flags )
229
236
. width ( e. key ( ) . extent . width )
230
237
. height ( e. key ( ) . extent . height )
231
- . layer_count ( e. key ( ) . extent . depth_or_array_layers )
232
- . view_formats ( & vk_view_formats[ i..i + 1 ] )
233
- . build ( )
238
+ . layer_count ( e. key ( ) . extent . depth_or_array_layers ) ;
239
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkRenderPassBeginInfo.html#VUID-VkRenderPassBeginInfo-framebuffer-03214
240
+ if vk_view_formats_list[ i] . is_empty ( ) {
241
+ info = info. view_formats ( & vk_view_formats[ i..i + 1 ] ) ;
242
+ } else {
243
+ info = info. view_formats ( & vk_view_formats_list[ i] ) ;
244
+ } ;
245
+ info. build ( )
234
246
} )
235
247
. collect :: < ArrayVec < _ , { super :: MAX_TOTAL_ATTACHMENTS } > > ( ) ;
236
248
@@ -550,6 +562,7 @@ impl super::Device {
550
562
let original_format = self . shared . private_caps . map_texture_format ( config. format ) ;
551
563
let mut raw_flags = vk:: SwapchainCreateFlagsKHR :: empty ( ) ;
552
564
let mut raw_view_formats: Vec < vk:: Format > = vec ! [ ] ;
565
+ let mut wgt_view_formats = vec ! [ ] ;
553
566
if !config. view_formats . is_empty ( ) {
554
567
raw_flags |= vk:: SwapchainCreateFlagsKHR :: MUTABLE_FORMAT ;
555
568
raw_view_formats = config
@@ -558,6 +571,9 @@ impl super::Device {
558
571
. map ( |f| self . shared . private_caps . map_texture_format ( * f) )
559
572
. collect ( ) ;
560
573
raw_view_formats. push ( original_format) ;
574
+
575
+ wgt_view_formats = config. view_formats . clone ( ) ;
576
+ wgt_view_formats. push ( config. format ) ;
561
577
}
562
578
563
579
let mut info = vk:: SwapchainCreateInfoKHR :: builder ( )
@@ -617,11 +633,13 @@ impl super::Device {
617
633
618
634
Ok ( super :: Swapchain {
619
635
raw,
636
+ raw_flags,
620
637
functor,
621
638
device : Arc :: clone ( & self . shared ) ,
622
639
fence,
623
640
images,
624
641
config : config. clone ( ) ,
642
+ view_formats : wgt_view_formats,
625
643
} )
626
644
}
627
645
@@ -630,11 +648,26 @@ impl super::Device {
630
648
/// - `vk_image` must be created respecting `desc`
631
649
/// - If `drop_guard` is `Some`, the application must manually destroy the image handle. This
632
650
/// can be done inside the `Drop` impl of `drop_guard`.
651
+ /// - If the `ImageCreateFlags` does not contain `MUTABLE_FORMAT`, the `view_formats` of `desc` must be empty.
633
652
pub unsafe fn texture_from_raw (
634
653
vk_image : vk:: Image ,
635
654
desc : & crate :: TextureDescriptor ,
636
655
drop_guard : Option < crate :: DropGuard > ,
637
656
) -> super :: Texture {
657
+ let mut raw_flags = vk:: ImageCreateFlags :: empty ( ) ;
658
+ let mut view_formats = vec ! [ ] ;
659
+ for tf in desc. view_formats . iter ( ) {
660
+ if * tf == desc. format {
661
+ continue ;
662
+ }
663
+ view_formats. push ( * tf) ;
664
+ }
665
+ if !view_formats. is_empty ( ) {
666
+ raw_flags |=
667
+ vk:: ImageCreateFlags :: MUTABLE_FORMAT | vk:: ImageCreateFlags :: EXTENDED_USAGE ;
668
+ view_formats. push ( desc. format )
669
+ }
670
+
638
671
super :: Texture {
639
672
raw : vk_image,
640
673
drop_guard,
@@ -644,6 +677,7 @@ impl super::Device {
644
677
format_info : desc. format . describe ( ) ,
645
678
raw_flags : vk:: ImageCreateFlags :: empty ( ) ,
646
679
copy_size : desc. copy_extent ( ) ,
680
+ view_formats,
647
681
}
648
682
}
649
683
@@ -908,20 +942,24 @@ impl crate::Device<super::Api> for super::Device {
908
942
}
909
943
910
944
let original_format = self . shared . private_caps . map_texture_format ( desc. format ) ;
911
- let mut hal_view_formats: Vec < vk:: Format > = vec ! [ ] ;
945
+ let mut vk_view_formats = vec ! [ ] ;
946
+ let mut wgt_view_formats = vec ! [ ] ;
912
947
if !desc. view_formats . is_empty ( ) {
913
948
raw_flags |= vk:: ImageCreateFlags :: MUTABLE_FORMAT ;
949
+ wgt_view_formats = desc. view_formats . clone ( ) ;
950
+ wgt_view_formats. push ( desc. format ) ;
951
+
914
952
if self . shared_instance ( ) . driver_api_version >= vk:: API_VERSION_1_2
915
953
|| self
916
954
. enabled_device_extensions ( )
917
955
. contains ( & vk:: KhrImageFormatListFn :: name ( ) )
918
956
{
919
- hal_view_formats = desc
957
+ vk_view_formats = desc
920
958
. view_formats
921
959
. iter ( )
922
960
. map ( |f| self . shared . private_caps . map_texture_format ( * f) )
923
961
. collect ( ) ;
924
- hal_view_formats . push ( original_format)
962
+ vk_view_formats . push ( original_format)
925
963
}
926
964
}
927
965
@@ -939,8 +977,8 @@ impl crate::Device<super::Api> for super::Device {
939
977
. initial_layout ( vk:: ImageLayout :: UNDEFINED ) ;
940
978
941
979
let mut format_list_info = vk:: ImageFormatListCreateInfo :: builder ( ) ;
942
- if !hal_view_formats . is_empty ( ) {
943
- format_list_info = format_list_info. view_formats ( & hal_view_formats ) ;
980
+ if !vk_view_formats . is_empty ( ) {
981
+ format_list_info = format_list_info. view_formats ( & vk_view_formats ) ;
944
982
vk_info = vk_info. push_next ( & mut format_list_info) ;
945
983
}
946
984
@@ -981,6 +1019,7 @@ impl crate::Device<super::Api> for super::Device {
981
1019
format_info : desc. format . describe ( ) ,
982
1020
raw_flags,
983
1021
copy_size,
1022
+ view_formats : wgt_view_formats,
984
1023
} )
985
1024
}
986
1025
unsafe fn destroy_texture ( & self , texture : super :: Texture ) {
@@ -1036,6 +1075,11 @@ impl crate::Device<super::Api> for super::Device {
1036
1075
raw_image_flags : texture. raw_flags ,
1037
1076
view_usage,
1038
1077
view_format : desc. format ,
1078
+ raw_view_formats : texture
1079
+ . view_formats
1080
+ . iter ( )
1081
+ . map ( |tf| self . shared . private_caps . map_texture_format ( * tf) )
1082
+ . collect ( ) ,
1039
1083
} ;
1040
1084
1041
1085
Ok ( super :: TextureView {
0 commit comments