1use alloc::vec::Vec;
2
3use crate::{Features, TextureAspect, TextureSampleType, TextureUsages};
4
5#[cfg(any(feature = "serde", test))]
6use serde::{Deserialize, Serialize};
7
8#[repr(C)]
10#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12#[cfg_attr(any(test, feature = "exhaust"), derive(exhaust::Exhaust))]
13pub enum AstcBlock {
14 B4x4,
16 B5x4,
18 B5x5,
20 B6x5,
22 B6x6,
24 B8x5,
26 B8x6,
28 B8x8,
30 B10x5,
32 B10x6,
34 B10x8,
36 B10x10,
38 B12x10,
40 B12x12,
42}
43
44#[repr(C)]
46#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48#[cfg_attr(any(test, feature = "exhaust"), derive(exhaust::Exhaust))]
49pub enum AstcChannel {
50 Unorm,
54 UnormSrgb,
58 Hdr,
62}
63
64bitflags::bitflags! {
65 #[repr(transparent)]
67 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
68 #[cfg_attr(feature = "serde", serde(transparent))]
69 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
70 pub struct TextureChannel: u16 {
71 const RED = 1 << 0;
73 const GREEN = 1 << 1;
75 const BLUE = 1 << 2;
77 const ALPHA = 1 << 3;
79 const STENCIL = 1 << 4;
81 const DEPTH = 1 << 5;
83 const LUMINANCE = 1 << 6;
85 const CHROMINANCE_BLUE = 1 << 7;
87 const CHROMINANCE_RED = 1 << 8;
89
90 const RG = Self::RED.bits() | Self::GREEN.bits();
92 const RGB = Self::RG.bits() | Self::BLUE.bits();
94 const RGBA = Self::RGB.bits() | Self::ALPHA.bits();
96 const DEPTH_STENCIL = Self::DEPTH.bits() | Self::STENCIL.bits();
98 const LUMINANCE_CHROMINANCE = Self::LUMINANCE.bits() | Self::CHROMINANCE_BLUE.bits() | Self::CHROMINANCE_RED.bits();
100 }
101}
102
103#[repr(C)]
126#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
127#[cfg_attr(any(test, feature = "exhaust"), derive(exhaust::Exhaust))]
128pub enum TextureFormat {
129 R8Unorm,
132 R8Snorm,
134 R8Uint,
136 R8Sint,
138
139 R16Uint,
142 R16Sint,
144 R16Unorm,
148 R16Snorm,
152 R16Float,
154 Rg8Unorm,
156 Rg8Snorm,
158 Rg8Uint,
160 Rg8Sint,
162
163 R32Uint,
166 R32Sint,
168 R32Float,
170 Rg16Uint,
172 Rg16Sint,
174 Rg16Unorm,
178 Rg16Snorm,
182 Rg16Float,
184 Rgba8Unorm,
186 Rgba8UnormSrgb,
188 Rgba8Snorm,
190 Rgba8Uint,
192 Rgba8Sint,
194 Bgra8Unorm,
196 Bgra8UnormSrgb,
198
199 Rgb9e5Ufloat,
202 Rgb10a2Uint,
204 Rgb10a2Unorm,
206 Rg11b10Ufloat,
208
209 R64Uint,
214 Rg32Uint,
216 Rg32Sint,
218 Rg32Float,
220 Rgba16Uint,
222 Rgba16Sint,
224 Rgba16Unorm,
228 Rgba16Snorm,
232 Rgba16Float,
234
235 Rgba32Uint,
238 Rgba32Sint,
240 Rgba32Float,
242
243 Stencil8,
246 Depth16Unorm,
248 Depth24Plus,
250 Depth24PlusStencil8,
252 Depth32Float,
254 Depth32FloatStencil8,
258
259 NV12,
273
274 P010,
290
291 Bc1RgbaUnorm,
300 Bc1RgbaUnormSrgb,
308 Bc2RgbaUnorm,
316 Bc2RgbaUnormSrgb,
324 Bc3RgbaUnorm,
332 Bc3RgbaUnormSrgb,
340 Bc4RUnorm,
348 Bc4RSnorm,
356 Bc5RgUnorm,
364 Bc5RgSnorm,
372 Bc6hRgbUfloat,
379 Bc6hRgbFloat,
386 Bc7RgbaUnorm,
394 Bc7RgbaUnormSrgb,
402 Etc2Rgb8Unorm,
407 Etc2Rgb8UnormSrgb,
412 Etc2Rgb8A1Unorm,
417 Etc2Rgb8A1UnormSrgb,
422 Etc2Rgba8Unorm,
427 Etc2Rgba8UnormSrgb,
432 EacR11Unorm,
437 EacR11Snorm,
442 EacRg11Unorm,
447 EacRg11Snorm,
452 Astc {
460 block: AstcBlock,
462 channel: AstcChannel,
464 },
465}
466
467impl TextureFormat {
470 #[must_use]
479 pub fn aspect_specific_format(&self, aspect: TextureAspect) -> Option<Self> {
480 match (*self, aspect) {
481 (Self::Stencil8, TextureAspect::StencilOnly) => Some(*self),
482 (
483 Self::Depth16Unorm | Self::Depth24Plus | Self::Depth32Float,
484 TextureAspect::DepthOnly,
485 ) => Some(*self),
486 (
487 Self::Depth24PlusStencil8 | Self::Depth32FloatStencil8,
488 TextureAspect::StencilOnly,
489 ) => Some(Self::Stencil8),
490 (Self::Depth24PlusStencil8, TextureAspect::DepthOnly) => Some(Self::Depth24Plus),
491 (Self::Depth32FloatStencil8, TextureAspect::DepthOnly) => Some(Self::Depth32Float),
492 (Self::NV12, TextureAspect::Plane0) => Some(Self::R8Unorm),
493 (Self::NV12, TextureAspect::Plane1) => Some(Self::Rg8Unorm),
494 (Self::P010, TextureAspect::Plane0) => Some(Self::R16Unorm),
495 (Self::P010, TextureAspect::Plane1) => Some(Self::Rg16Unorm),
496 (format, TextureAspect::All) if !format.is_multi_planar_format() => Some(format),
498 _ => None,
499 }
500 }
501
502 #[must_use]
505 pub fn is_depth_stencil_component(&self, combined_format: Self) -> bool {
506 match (combined_format, *self) {
507 (Self::Depth24PlusStencil8, Self::Depth24Plus | Self::Stencil8)
508 | (Self::Depth32FloatStencil8, Self::Depth32Float | Self::Stencil8) => true,
509 _ => false,
510 }
511 }
512
513 #[must_use]
517 pub fn is_depth_stencil_format(&self) -> bool {
518 self.channels().intersects(TextureChannel::DEPTH_STENCIL)
519 }
520
521 #[must_use]
525 pub fn is_combined_depth_stencil_format(&self) -> bool {
526 self.channels().contains(TextureChannel::DEPTH_STENCIL)
527 }
528
529 #[must_use]
531 pub fn is_multi_planar_format(&self) -> bool {
532 self.planes().is_some()
533 }
534
535 #[must_use]
537 pub fn planes(&self) -> Option<u32> {
538 match *self {
539 Self::NV12 => Some(2),
540 Self::P010 => Some(2),
541 _ => None,
542 }
543 }
544
545 #[must_use]
555 pub fn subsampling_factors(&self, plane: Option<u32>) -> (u32, u32) {
556 match *self {
557 Self::NV12 | Self::P010 => match plane {
558 Some(0) => (1, 1),
559 Some(1) => (2, 2),
560 Some(plane) => panic!("plane {plane} is not valid for {self:?}"),
561 None => panic!("the plane must be specified for multi-planar formats"),
562 },
563 _ => (1, 1),
564 }
565 }
566
567 #[must_use]
590 pub fn channels(&self) -> TextureChannel {
591 match self {
592 Self::R8Unorm
593 | Self::R8Snorm
594 | Self::R8Uint
595 | Self::R8Sint
596 | Self::R16Uint
597 | Self::R16Sint
598 | Self::R16Unorm
599 | Self::R16Snorm
600 | Self::R32Uint
601 | Self::R32Sint
602 | Self::R32Float
603 | Self::R16Float
604 | Self::R64Uint
605 | Self::Bc4RUnorm
606 | Self::Bc4RSnorm
607 | Self::EacR11Unorm
608 | Self::EacR11Snorm => TextureChannel::RED,
609
610 Self::Rg8Unorm
611 | Self::Rg8Snorm
612 | Self::Rg8Uint
613 | Self::Rg8Sint
614 | Self::Rg16Uint
615 | Self::Rg16Sint
616 | Self::Rg16Unorm
617 | Self::Rg16Snorm
618 | Self::Rg16Float
619 | Self::Rg32Uint
620 | Self::Rg32Sint
621 | Self::Rg32Float
622 | Self::Bc5RgUnorm
623 | Self::Bc5RgSnorm
624 | Self::EacRg11Unorm
625 | Self::EacRg11Snorm => TextureChannel::RG,
626
627 Self::Rgb9e5Ufloat
628 | Self::Rg11b10Ufloat
629 | Self::Bc6hRgbUfloat
630 | Self::Bc6hRgbFloat
631 | Self::Etc2Rgb8Unorm
632 | Self::Etc2Rgb8UnormSrgb => TextureChannel::RGB,
633
634 Self::Rgba8Unorm
635 | Self::Rgba8UnormSrgb
636 | Self::Rgba8Snorm
637 | Self::Rgba8Uint
638 | Self::Rgba8Sint
639 | Self::Bgra8Unorm
640 | Self::Bgra8UnormSrgb
641 | Self::Rgb10a2Uint
642 | Self::Rgb10a2Unorm
643 | Self::Rgba16Uint
644 | Self::Rgba16Sint
645 | Self::Rgba16Unorm
646 | Self::Rgba16Snorm
647 | Self::Rgba16Float
648 | Self::Rgba32Uint
649 | Self::Rgba32Sint
650 | Self::Rgba32Float
651 | Self::Bc1RgbaUnorm
652 | Self::Bc1RgbaUnormSrgb
653 | Self::Bc2RgbaUnorm
654 | Self::Bc2RgbaUnormSrgb
655 | Self::Bc3RgbaUnorm
656 | Self::Bc3RgbaUnormSrgb
657 | Self::Bc7RgbaUnorm
658 | Self::Bc7RgbaUnormSrgb
659 | Self::Etc2Rgb8A1Unorm
660 | Self::Etc2Rgb8A1UnormSrgb
661 | Self::Etc2Rgba8Unorm
662 | Self::Etc2Rgba8UnormSrgb
663 | Self::Astc { .. } => TextureChannel::RGBA,
664
665 Self::Stencil8 => TextureChannel::STENCIL,
666 Self::Depth16Unorm | Self::Depth24Plus | Self::Depth32Float => TextureChannel::DEPTH,
667
668 Self::Depth24PlusStencil8 | Self::Depth32FloatStencil8 => TextureChannel::DEPTH_STENCIL,
669
670 Self::NV12 | Self::P010 => TextureChannel::LUMINANCE_CHROMINANCE,
671 }
672 }
673
674 #[must_use]
676 pub fn has_color_aspect(&self) -> bool {
677 self.channels().intersects(TextureChannel::RGBA)
678 }
679
680 #[must_use]
682 pub fn has_depth_aspect(&self) -> bool {
683 self.channels().intersects(TextureChannel::DEPTH)
684 }
685
686 #[must_use]
688 pub fn has_stencil_aspect(&self) -> bool {
689 self.channels().intersects(TextureChannel::STENCIL)
690 }
691
692 #[must_use]
698 pub fn size_multiple_requirement(&self) -> (u32, u32) {
699 match *self {
700 Self::NV12 => (2, 2),
701 Self::P010 => (2, 2),
702 _ => self.block_dimensions(),
703 }
704 }
705
706 #[must_use]
710 pub fn block_dimensions(&self) -> (u32, u32) {
711 match *self {
712 Self::R8Unorm
713 | Self::R8Snorm
714 | Self::R8Uint
715 | Self::R8Sint
716 | Self::R16Uint
717 | Self::R16Sint
718 | Self::R16Unorm
719 | Self::R16Snorm
720 | Self::R16Float
721 | Self::Rg8Unorm
722 | Self::Rg8Snorm
723 | Self::Rg8Uint
724 | Self::Rg8Sint
725 | Self::R32Uint
726 | Self::R32Sint
727 | Self::R32Float
728 | Self::Rg16Uint
729 | Self::Rg16Sint
730 | Self::Rg16Unorm
731 | Self::Rg16Snorm
732 | Self::Rg16Float
733 | Self::Rgba8Unorm
734 | Self::Rgba8UnormSrgb
735 | Self::Rgba8Snorm
736 | Self::Rgba8Uint
737 | Self::Rgba8Sint
738 | Self::Bgra8Unorm
739 | Self::Bgra8UnormSrgb
740 | Self::Rgb9e5Ufloat
741 | Self::Rgb10a2Uint
742 | Self::Rgb10a2Unorm
743 | Self::Rg11b10Ufloat
744 | Self::R64Uint
745 | Self::Rg32Uint
746 | Self::Rg32Sint
747 | Self::Rg32Float
748 | Self::Rgba16Uint
749 | Self::Rgba16Sint
750 | Self::Rgba16Unorm
751 | Self::Rgba16Snorm
752 | Self::Rgba16Float
753 | Self::Rgba32Uint
754 | Self::Rgba32Sint
755 | Self::Rgba32Float
756 | Self::Stencil8
757 | Self::Depth16Unorm
758 | Self::Depth24Plus
759 | Self::Depth24PlusStencil8
760 | Self::Depth32Float
761 | Self::Depth32FloatStencil8
762 | Self::NV12
763 | Self::P010 => (1, 1),
764
765 Self::Bc1RgbaUnorm
766 | Self::Bc1RgbaUnormSrgb
767 | Self::Bc2RgbaUnorm
768 | Self::Bc2RgbaUnormSrgb
769 | Self::Bc3RgbaUnorm
770 | Self::Bc3RgbaUnormSrgb
771 | Self::Bc4RUnorm
772 | Self::Bc4RSnorm
773 | Self::Bc5RgUnorm
774 | Self::Bc5RgSnorm
775 | Self::Bc6hRgbUfloat
776 | Self::Bc6hRgbFloat
777 | Self::Bc7RgbaUnorm
778 | Self::Bc7RgbaUnormSrgb => (4, 4),
779
780 Self::Etc2Rgb8Unorm
781 | Self::Etc2Rgb8UnormSrgb
782 | Self::Etc2Rgb8A1Unorm
783 | Self::Etc2Rgb8A1UnormSrgb
784 | Self::Etc2Rgba8Unorm
785 | Self::Etc2Rgba8UnormSrgb
786 | Self::EacR11Unorm
787 | Self::EacR11Snorm
788 | Self::EacRg11Unorm
789 | Self::EacRg11Snorm => (4, 4),
790
791 Self::Astc { block, .. } => match block {
792 AstcBlock::B4x4 => (4, 4),
793 AstcBlock::B5x4 => (5, 4),
794 AstcBlock::B5x5 => (5, 5),
795 AstcBlock::B6x5 => (6, 5),
796 AstcBlock::B6x6 => (6, 6),
797 AstcBlock::B8x5 => (8, 5),
798 AstcBlock::B8x6 => (8, 6),
799 AstcBlock::B8x8 => (8, 8),
800 AstcBlock::B10x5 => (10, 5),
801 AstcBlock::B10x6 => (10, 6),
802 AstcBlock::B10x8 => (10, 8),
803 AstcBlock::B10x10 => (10, 10),
804 AstcBlock::B12x10 => (12, 10),
805 AstcBlock::B12x12 => (12, 12),
806 },
807 }
808 }
809
810 #[must_use]
812 pub fn is_compressed(&self) -> bool {
813 self.block_dimensions() != (1, 1)
814 }
815
816 #[must_use]
818 pub fn is_bcn(&self) -> bool {
819 self.required_features() == Features::TEXTURE_COMPRESSION_BC
820 }
821
822 #[must_use]
824 pub fn is_astc(&self) -> bool {
825 self.required_features() == Features::TEXTURE_COMPRESSION_ASTC
826 || self.required_features() == Features::TEXTURE_COMPRESSION_ASTC_HDR
827 }
828
829 #[must_use]
831 pub fn required_features(&self) -> Features {
832 match *self {
833 Self::R8Unorm
834 | Self::R8Snorm
835 | Self::R8Uint
836 | Self::R8Sint
837 | Self::R16Uint
838 | Self::R16Sint
839 | Self::R16Float
840 | Self::Rg8Unorm
841 | Self::Rg8Snorm
842 | Self::Rg8Uint
843 | Self::Rg8Sint
844 | Self::R32Uint
845 | Self::R32Sint
846 | Self::R32Float
847 | Self::Rg16Uint
848 | Self::Rg16Sint
849 | Self::Rg16Float
850 | Self::Rgba8Unorm
851 | Self::Rgba8UnormSrgb
852 | Self::Rgba8Snorm
853 | Self::Rgba8Uint
854 | Self::Rgba8Sint
855 | Self::Bgra8Unorm
856 | Self::Bgra8UnormSrgb
857 | Self::Rgb9e5Ufloat
858 | Self::Rgb10a2Uint
859 | Self::Rgb10a2Unorm
860 | Self::Rg11b10Ufloat
861 | Self::Rg32Uint
862 | Self::Rg32Sint
863 | Self::Rg32Float
864 | Self::Rgba16Uint
865 | Self::Rgba16Sint
866 | Self::Rgba16Float
867 | Self::Rgba32Uint
868 | Self::Rgba32Sint
869 | Self::Rgba32Float
870 | Self::Stencil8
871 | Self::Depth16Unorm
872 | Self::Depth24Plus
873 | Self::Depth24PlusStencil8
874 | Self::Depth32Float => Features::empty(),
875
876 Self::R64Uint => Features::TEXTURE_INT64_ATOMIC,
877
878 Self::Depth32FloatStencil8 => Features::DEPTH32FLOAT_STENCIL8,
879
880 Self::NV12 => Features::TEXTURE_FORMAT_NV12,
881 Self::P010 => Features::TEXTURE_FORMAT_P010,
882
883 Self::R16Unorm
884 | Self::R16Snorm
885 | Self::Rg16Unorm
886 | Self::Rg16Snorm
887 | Self::Rgba16Unorm
888 | Self::Rgba16Snorm => Features::TEXTURE_FORMAT_16BIT_NORM,
889
890 Self::Bc1RgbaUnorm
891 | Self::Bc1RgbaUnormSrgb
892 | Self::Bc2RgbaUnorm
893 | Self::Bc2RgbaUnormSrgb
894 | Self::Bc3RgbaUnorm
895 | Self::Bc3RgbaUnormSrgb
896 | Self::Bc4RUnorm
897 | Self::Bc4RSnorm
898 | Self::Bc5RgUnorm
899 | Self::Bc5RgSnorm
900 | Self::Bc6hRgbUfloat
901 | Self::Bc6hRgbFloat
902 | Self::Bc7RgbaUnorm
903 | Self::Bc7RgbaUnormSrgb => Features::TEXTURE_COMPRESSION_BC,
904
905 Self::Etc2Rgb8Unorm
906 | Self::Etc2Rgb8UnormSrgb
907 | Self::Etc2Rgb8A1Unorm
908 | Self::Etc2Rgb8A1UnormSrgb
909 | Self::Etc2Rgba8Unorm
910 | Self::Etc2Rgba8UnormSrgb
911 | Self::EacR11Unorm
912 | Self::EacR11Snorm
913 | Self::EacRg11Unorm
914 | Self::EacRg11Snorm => Features::TEXTURE_COMPRESSION_ETC2,
915
916 Self::Astc { channel, .. } => match channel {
917 AstcChannel::Hdr => Features::TEXTURE_COMPRESSION_ASTC_HDR,
918 AstcChannel::Unorm | AstcChannel::UnormSrgb => Features::TEXTURE_COMPRESSION_ASTC,
919 },
920 }
921 }
922
923 #[must_use]
927 pub fn guaranteed_format_features(&self, device_features: Features) -> TextureFormatFeatures {
928 let none = TextureFormatFeatureFlags::empty();
930 let msaa = TextureFormatFeatureFlags::MULTISAMPLE_X4;
931 let msaa_resolve = msaa | TextureFormatFeatureFlags::MULTISAMPLE_RESOLVE;
932
933 let s_ro_wo = TextureFormatFeatureFlags::STORAGE_READ_ONLY
934 | TextureFormatFeatureFlags::STORAGE_WRITE_ONLY;
935 let s_all = s_ro_wo | TextureFormatFeatureFlags::STORAGE_READ_WRITE;
936
937 let basic =
939 TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING;
940 let attachment =
941 basic | TextureUsages::RENDER_ATTACHMENT | TextureUsages::TRANSIENT_ATTACHMENT;
942 let storage = basic | TextureUsages::STORAGE_BINDING;
943 let binding = TextureUsages::TEXTURE_BINDING;
944 let all_flags = attachment | storage | binding;
945 let atomic_64 = if device_features.contains(Features::TEXTURE_ATOMIC) {
946 storage | binding | TextureUsages::STORAGE_ATOMIC
947 } else {
948 storage | binding
949 };
950 let atomic = attachment | atomic_64;
951 let (rg11b10f_f, rg11b10f_u) =
952 if device_features.contains(Features::RG11B10UFLOAT_RENDERABLE) {
953 (msaa_resolve, attachment)
954 } else {
955 (msaa, basic)
956 };
957 let (bgra8unorm_f, bgra8unorm) = if device_features.contains(Features::BGRA8UNORM_STORAGE) {
958 (
959 msaa_resolve | TextureFormatFeatureFlags::STORAGE_WRITE_ONLY,
960 attachment | TextureUsages::STORAGE_BINDING,
961 )
962 } else {
963 (msaa_resolve, attachment)
964 };
965
966 #[rustfmt::skip] let (
968 mut flags,
969 allowed_usages,
970 ) = match *self {
971 Self::R8Unorm => (msaa_resolve, attachment),
972 Self::R8Snorm => ( none, basic),
973 Self::R8Uint => ( msaa, attachment),
974 Self::R8Sint => ( msaa, attachment),
975 Self::R16Uint => ( msaa, attachment),
976 Self::R16Sint => ( msaa, attachment),
977 Self::R16Float => (msaa_resolve, attachment),
978 Self::Rg8Unorm => (msaa_resolve, attachment),
979 Self::Rg8Snorm => ( none, basic),
980 Self::Rg8Uint => ( msaa, attachment),
981 Self::Rg8Sint => ( msaa, attachment),
982 Self::R32Uint => ( s_all, atomic),
983 Self::R32Sint => ( s_all, atomic),
984 Self::R32Float => (msaa | s_all, all_flags),
985 Self::Rg16Uint => ( msaa, attachment),
986 Self::Rg16Sint => ( msaa, attachment),
987 Self::Rg16Float => (msaa_resolve, attachment),
988 Self::Rgba8Unorm => (msaa_resolve | s_ro_wo, all_flags),
989 Self::Rgba8UnormSrgb => (msaa_resolve, attachment),
990 Self::Rgba8Snorm => ( s_ro_wo, storage),
991 Self::Rgba8Uint => ( msaa | s_ro_wo, all_flags),
992 Self::Rgba8Sint => ( msaa | s_ro_wo, all_flags),
993 Self::Bgra8Unorm => (bgra8unorm_f, bgra8unorm),
994 Self::Bgra8UnormSrgb => (msaa_resolve, attachment),
995 Self::Rgb10a2Uint => ( msaa, attachment),
996 Self::Rgb10a2Unorm => (msaa_resolve, attachment),
997 Self::Rg11b10Ufloat => ( rg11b10f_f, rg11b10f_u),
998 Self::R64Uint => ( s_ro_wo, atomic_64),
999 Self::Rg32Uint => ( s_ro_wo, all_flags),
1000 Self::Rg32Sint => ( s_ro_wo, all_flags),
1001 Self::Rg32Float => ( s_ro_wo, all_flags),
1002 Self::Rgba16Uint => ( msaa | s_ro_wo, all_flags),
1003 Self::Rgba16Sint => ( msaa | s_ro_wo, all_flags),
1004 Self::Rgba16Float => (msaa_resolve | s_ro_wo, all_flags),
1005 Self::Rgba32Uint => ( s_ro_wo, all_flags),
1006 Self::Rgba32Sint => ( s_ro_wo, all_flags),
1007 Self::Rgba32Float => ( s_ro_wo, all_flags),
1008
1009 Self::Stencil8 => ( msaa, attachment),
1010 Self::Depth16Unorm => ( msaa, attachment),
1011 Self::Depth24Plus => ( msaa, attachment),
1012 Self::Depth24PlusStencil8 => ( msaa, attachment),
1013 Self::Depth32Float => ( msaa, attachment),
1014 Self::Depth32FloatStencil8 => ( msaa, attachment),
1015
1016 Self::NV12 => ( none, attachment),
1017 Self::P010 => ( none, basic),
1018
1019 Self::R16Unorm => ( msaa | s_ro_wo, storage),
1020 Self::R16Snorm => ( msaa | s_ro_wo, storage),
1021 Self::Rg16Unorm => ( msaa | s_ro_wo, storage),
1022 Self::Rg16Snorm => ( msaa | s_ro_wo, storage),
1023 Self::Rgba16Unorm => ( msaa | s_ro_wo, storage),
1024 Self::Rgba16Snorm => ( msaa | s_ro_wo, storage),
1025
1026 Self::Rgb9e5Ufloat => ( none, basic),
1027
1028 Self::Bc1RgbaUnorm => ( none, basic),
1029 Self::Bc1RgbaUnormSrgb => ( none, basic),
1030 Self::Bc2RgbaUnorm => ( none, basic),
1031 Self::Bc2RgbaUnormSrgb => ( none, basic),
1032 Self::Bc3RgbaUnorm => ( none, basic),
1033 Self::Bc3RgbaUnormSrgb => ( none, basic),
1034 Self::Bc4RUnorm => ( none, basic),
1035 Self::Bc4RSnorm => ( none, basic),
1036 Self::Bc5RgUnorm => ( none, basic),
1037 Self::Bc5RgSnorm => ( none, basic),
1038 Self::Bc6hRgbUfloat => ( none, basic),
1039 Self::Bc6hRgbFloat => ( none, basic),
1040 Self::Bc7RgbaUnorm => ( none, basic),
1041 Self::Bc7RgbaUnormSrgb => ( none, basic),
1042
1043 Self::Etc2Rgb8Unorm => ( none, basic),
1044 Self::Etc2Rgb8UnormSrgb => ( none, basic),
1045 Self::Etc2Rgb8A1Unorm => ( none, basic),
1046 Self::Etc2Rgb8A1UnormSrgb => ( none, basic),
1047 Self::Etc2Rgba8Unorm => ( none, basic),
1048 Self::Etc2Rgba8UnormSrgb => ( none, basic),
1049 Self::EacR11Unorm => ( none, basic),
1050 Self::EacR11Snorm => ( none, basic),
1051 Self::EacRg11Unorm => ( none, basic),
1052 Self::EacRg11Snorm => ( none, basic),
1053
1054 Self::Astc { .. } => ( none, basic),
1055 };
1056
1057 let sample_type1 = self.sample_type(None, Some(device_features));
1059 let is_filterable = sample_type1 == Some(TextureSampleType::Float { filterable: true });
1060
1061 let sample_type2 = self.sample_type(None, None);
1063 let is_blendable = sample_type2 == Some(TextureSampleType::Float { filterable: true })
1064 || device_features.contains(Features::FLOAT32_BLENDABLE)
1065 && matches!(self, Self::R32Float | Self::Rg32Float | Self::Rgba32Float);
1066
1067 flags.set(TextureFormatFeatureFlags::FILTERABLE, is_filterable);
1068 flags.set(TextureFormatFeatureFlags::BLENDABLE, is_blendable);
1069 flags.set(
1070 TextureFormatFeatureFlags::STORAGE_ATOMIC,
1071 allowed_usages.contains(TextureUsages::STORAGE_ATOMIC),
1072 );
1073
1074 TextureFormatFeatures {
1075 allowed_usages,
1076 flags,
1077 }
1078 }
1079
1080 #[must_use]
1085 pub fn sample_type(
1086 &self,
1087 aspect: Option<TextureAspect>,
1088 device_features: Option<Features>,
1089 ) -> Option<TextureSampleType> {
1090 let float = TextureSampleType::Float { filterable: true };
1091 let unfilterable_float = TextureSampleType::Float { filterable: false };
1092 let float32_sample_type = TextureSampleType::Float {
1093 filterable: device_features
1094 .unwrap_or(Features::empty())
1095 .contains(Features::FLOAT32_FILTERABLE),
1096 };
1097 let depth = TextureSampleType::Depth;
1098 let uint = TextureSampleType::Uint;
1099 let sint = TextureSampleType::Sint;
1100
1101 match *self {
1102 Self::R8Unorm
1103 | Self::R8Snorm
1104 | Self::Rg8Unorm
1105 | Self::Rg8Snorm
1106 | Self::Rgba8Unorm
1107 | Self::Rgba8UnormSrgb
1108 | Self::Rgba8Snorm
1109 | Self::Bgra8Unorm
1110 | Self::Bgra8UnormSrgb
1111 | Self::R16Float
1112 | Self::Rg16Float
1113 | Self::Rgba16Float
1114 | Self::Rgb10a2Unorm
1115 | Self::Rg11b10Ufloat => Some(float),
1116
1117 Self::R32Float | Self::Rg32Float | Self::Rgba32Float => Some(float32_sample_type),
1118
1119 Self::R8Uint
1120 | Self::Rg8Uint
1121 | Self::Rgba8Uint
1122 | Self::R16Uint
1123 | Self::Rg16Uint
1124 | Self::Rgba16Uint
1125 | Self::R32Uint
1126 | Self::R64Uint
1127 | Self::Rg32Uint
1128 | Self::Rgba32Uint
1129 | Self::Rgb10a2Uint => Some(uint),
1130
1131 Self::R8Sint
1132 | Self::Rg8Sint
1133 | Self::Rgba8Sint
1134 | Self::R16Sint
1135 | Self::Rg16Sint
1136 | Self::Rgba16Sint
1137 | Self::R32Sint
1138 | Self::Rg32Sint
1139 | Self::Rgba32Sint => Some(sint),
1140
1141 Self::Stencil8 => Some(uint),
1142 Self::Depth16Unorm | Self::Depth24Plus | Self::Depth32Float => Some(depth),
1143 Self::Depth24PlusStencil8 | Self::Depth32FloatStencil8 => match aspect {
1144 Some(TextureAspect::DepthOnly) => Some(depth),
1145 Some(TextureAspect::StencilOnly) => Some(uint),
1146 _ => None,
1147 },
1148
1149 Self::NV12 | Self::P010 => match aspect {
1150 Some(TextureAspect::Plane0) | Some(TextureAspect::Plane1) => {
1151 Some(unfilterable_float)
1152 }
1153 _ => None,
1154 },
1155
1156 Self::R16Unorm
1157 | Self::R16Snorm
1158 | Self::Rg16Unorm
1159 | Self::Rg16Snorm
1160 | Self::Rgba16Unorm
1161 | Self::Rgba16Snorm => Some(float),
1162
1163 Self::Rgb9e5Ufloat => Some(float),
1164
1165 Self::Bc1RgbaUnorm
1166 | Self::Bc1RgbaUnormSrgb
1167 | Self::Bc2RgbaUnorm
1168 | Self::Bc2RgbaUnormSrgb
1169 | Self::Bc3RgbaUnorm
1170 | Self::Bc3RgbaUnormSrgb
1171 | Self::Bc4RUnorm
1172 | Self::Bc4RSnorm
1173 | Self::Bc5RgUnorm
1174 | Self::Bc5RgSnorm
1175 | Self::Bc6hRgbUfloat
1176 | Self::Bc6hRgbFloat
1177 | Self::Bc7RgbaUnorm
1178 | Self::Bc7RgbaUnormSrgb => Some(float),
1179
1180 Self::Etc2Rgb8Unorm
1181 | Self::Etc2Rgb8UnormSrgb
1182 | Self::Etc2Rgb8A1Unorm
1183 | Self::Etc2Rgb8A1UnormSrgb
1184 | Self::Etc2Rgba8Unorm
1185 | Self::Etc2Rgba8UnormSrgb
1186 | Self::EacR11Unorm
1187 | Self::EacR11Snorm
1188 | Self::EacRg11Unorm
1189 | Self::EacRg11Snorm => Some(float),
1190
1191 Self::Astc { .. } => Some(float),
1192 }
1193 }
1194
1195 #[deprecated(since = "0.19.0", note = "Use `block_copy_size` instead.")]
1208 #[must_use]
1209 pub fn block_size(&self, aspect: Option<TextureAspect>) -> Option<u32> {
1210 self.block_copy_size(aspect)
1211 }
1212
1213 #[must_use]
1226 pub fn block_copy_size(&self, aspect: Option<TextureAspect>) -> Option<u32> {
1227 match *self {
1228 Self::R8Unorm | Self::R8Snorm | Self::R8Uint | Self::R8Sint => Some(1),
1229
1230 Self::Rg8Unorm | Self::Rg8Snorm | Self::Rg8Uint | Self::Rg8Sint => Some(2),
1231 Self::R16Unorm | Self::R16Snorm | Self::R16Uint | Self::R16Sint | Self::R16Float => {
1232 Some(2)
1233 }
1234
1235 Self::Rgba8Unorm
1236 | Self::Rgba8UnormSrgb
1237 | Self::Rgba8Snorm
1238 | Self::Rgba8Uint
1239 | Self::Rgba8Sint
1240 | Self::Bgra8Unorm
1241 | Self::Bgra8UnormSrgb => Some(4),
1242 Self::Rg16Unorm
1243 | Self::Rg16Snorm
1244 | Self::Rg16Uint
1245 | Self::Rg16Sint
1246 | Self::Rg16Float => Some(4),
1247 Self::R32Uint | Self::R32Sint | Self::R32Float => Some(4),
1248 Self::Rgb9e5Ufloat | Self::Rgb10a2Uint | Self::Rgb10a2Unorm | Self::Rg11b10Ufloat => {
1249 Some(4)
1250 }
1251
1252 Self::Rgba16Unorm
1253 | Self::Rgba16Snorm
1254 | Self::Rgba16Uint
1255 | Self::Rgba16Sint
1256 | Self::Rgba16Float => Some(8),
1257 Self::R64Uint | Self::Rg32Uint | Self::Rg32Sint | Self::Rg32Float => Some(8),
1258
1259 Self::Rgba32Uint | Self::Rgba32Sint | Self::Rgba32Float => Some(16),
1260
1261 Self::Stencil8 => Some(1),
1262 Self::Depth16Unorm => Some(2),
1263 Self::Depth32Float => Some(4),
1264 Self::Depth24Plus => None,
1265 Self::Depth24PlusStencil8 => match aspect {
1266 Some(TextureAspect::DepthOnly) => None,
1267 Some(TextureAspect::StencilOnly) => Some(1),
1268 _ => None,
1269 },
1270 Self::Depth32FloatStencil8 => match aspect {
1271 Some(TextureAspect::DepthOnly) => Some(4),
1272 Some(TextureAspect::StencilOnly) => Some(1),
1273 _ => None,
1274 },
1275
1276 Self::NV12 => match aspect {
1277 Some(TextureAspect::Plane0) => Some(1),
1278 Some(TextureAspect::Plane1) => Some(2),
1279 _ => None,
1280 },
1281
1282 Self::P010 => match aspect {
1283 Some(TextureAspect::Plane0) => Some(2),
1284 Some(TextureAspect::Plane1) => Some(4),
1285 _ => None,
1286 },
1287
1288 Self::Bc1RgbaUnorm | Self::Bc1RgbaUnormSrgb | Self::Bc4RUnorm | Self::Bc4RSnorm => {
1289 Some(8)
1290 }
1291 Self::Bc2RgbaUnorm
1292 | Self::Bc2RgbaUnormSrgb
1293 | Self::Bc3RgbaUnorm
1294 | Self::Bc3RgbaUnormSrgb
1295 | Self::Bc5RgUnorm
1296 | Self::Bc5RgSnorm
1297 | Self::Bc6hRgbUfloat
1298 | Self::Bc6hRgbFloat
1299 | Self::Bc7RgbaUnorm
1300 | Self::Bc7RgbaUnormSrgb => Some(16),
1301
1302 Self::Etc2Rgb8Unorm
1303 | Self::Etc2Rgb8UnormSrgb
1304 | Self::Etc2Rgb8A1Unorm
1305 | Self::Etc2Rgb8A1UnormSrgb
1306 | Self::EacR11Unorm
1307 | Self::EacR11Snorm => Some(8),
1308 Self::Etc2Rgba8Unorm
1309 | Self::Etc2Rgba8UnormSrgb
1310 | Self::EacRg11Unorm
1311 | Self::EacRg11Snorm => Some(16),
1312
1313 Self::Astc { .. } => Some(16),
1314 }
1315 }
1316
1317 pub const MAX_TARGET_PIXEL_BYTE_COST: u32 = 16;
1319
1320 #[must_use]
1323 pub fn target_pixel_byte_cost(&self) -> Option<u32> {
1324 match *self {
1325 Self::R8Unorm | Self::R8Snorm | Self::R8Uint | Self::R8Sint => Some(1),
1326 Self::Rg8Unorm
1327 | Self::Rg8Snorm
1328 | Self::Rg8Uint
1329 | Self::Rg8Sint
1330 | Self::R16Uint
1331 | Self::R16Sint
1332 | Self::R16Unorm
1333 | Self::R16Snorm
1334 | Self::R16Float => Some(2),
1335 Self::Rgba8Uint
1336 | Self::Rgba8Sint
1337 | Self::Rg16Uint
1338 | Self::Rg16Sint
1339 | Self::Rg16Unorm
1340 | Self::Rg16Snorm
1341 | Self::Rg16Float
1342 | Self::R32Uint
1343 | Self::R32Sint
1344 | Self::R32Float => Some(4),
1345 Self::Rgba8Unorm
1347 | Self::Rgba8UnormSrgb
1348 | Self::Rgba8Snorm
1349 | Self::Bgra8Unorm
1350 | Self::Bgra8UnormSrgb
1351 | Self::Rgba16Uint
1353 | Self::Rgba16Sint
1354 | Self::Rgba16Unorm
1355 | Self::Rgba16Snorm
1356 | Self::Rgba16Float
1357 | Self::R64Uint
1358 | Self::Rg32Uint
1359 | Self::Rg32Sint
1360 | Self::Rg32Float
1361 | Self::Rgb10a2Uint
1362 | Self::Rgb10a2Unorm
1363 | Self::Rg11b10Ufloat => Some(8),
1364 Self::Rgba32Uint | Self::Rgba32Sint | Self::Rgba32Float => Some(16),
1365 Self::Stencil8
1367 | Self::Depth16Unorm
1368 | Self::Depth24Plus
1369 | Self::Depth24PlusStencil8
1370 | Self::Depth32Float
1371 | Self::Depth32FloatStencil8
1372 | Self::NV12
1373 | Self::P010
1374 | Self::Rgb9e5Ufloat
1375 | Self::Bc1RgbaUnorm
1376 | Self::Bc1RgbaUnormSrgb
1377 | Self::Bc2RgbaUnorm
1378 | Self::Bc2RgbaUnormSrgb
1379 | Self::Bc3RgbaUnorm
1380 | Self::Bc3RgbaUnormSrgb
1381 | Self::Bc4RUnorm
1382 | Self::Bc4RSnorm
1383 | Self::Bc5RgUnorm
1384 | Self::Bc5RgSnorm
1385 | Self::Bc6hRgbUfloat
1386 | Self::Bc6hRgbFloat
1387 | Self::Bc7RgbaUnorm
1388 | Self::Bc7RgbaUnormSrgb
1389 | Self::Etc2Rgb8Unorm
1390 | Self::Etc2Rgb8UnormSrgb
1391 | Self::Etc2Rgb8A1Unorm
1392 | Self::Etc2Rgb8A1UnormSrgb
1393 | Self::Etc2Rgba8Unorm
1394 | Self::Etc2Rgba8UnormSrgb
1395 | Self::EacR11Unorm
1396 | Self::EacR11Snorm
1397 | Self::EacRg11Unorm
1398 | Self::EacRg11Snorm
1399 | Self::Astc { .. } => None,
1400 }
1401 }
1402
1403 #[must_use]
1405 pub fn target_component_alignment(&self) -> Option<u32> {
1406 match *self {
1407 Self::R8Unorm
1408 | Self::R8Snorm
1409 | Self::R8Uint
1410 | Self::R8Sint
1411 | Self::Rg8Unorm
1412 | Self::Rg8Snorm
1413 | Self::Rg8Uint
1414 | Self::Rg8Sint
1415 | Self::Rgba8Unorm
1416 | Self::Rgba8UnormSrgb
1417 | Self::Rgba8Snorm
1418 | Self::Rgba8Uint
1419 | Self::Rgba8Sint
1420 | Self::Bgra8Unorm
1421 | Self::Bgra8UnormSrgb => Some(1),
1422 Self::R16Uint
1423 | Self::R16Sint
1424 | Self::R16Unorm
1425 | Self::R16Snorm
1426 | Self::R16Float
1427 | Self::Rg16Uint
1428 | Self::Rg16Sint
1429 | Self::Rg16Unorm
1430 | Self::Rg16Snorm
1431 | Self::Rg16Float
1432 | Self::Rgba16Uint
1433 | Self::Rgba16Sint
1434 | Self::Rgba16Unorm
1435 | Self::Rgba16Snorm
1436 | Self::Rgba16Float => Some(2),
1437 Self::R32Uint
1438 | Self::R32Sint
1439 | Self::R32Float
1440 | Self::R64Uint
1441 | Self::Rg32Uint
1442 | Self::Rg32Sint
1443 | Self::Rg32Float
1444 | Self::Rgba32Uint
1445 | Self::Rgba32Sint
1446 | Self::Rgba32Float
1447 | Self::Rgb10a2Uint
1448 | Self::Rgb10a2Unorm
1449 | Self::Rg11b10Ufloat => Some(4),
1450 Self::Stencil8
1451 | Self::Depth16Unorm
1452 | Self::Depth24Plus
1453 | Self::Depth24PlusStencil8
1454 | Self::Depth32Float
1455 | Self::Depth32FloatStencil8
1456 | Self::NV12
1457 | Self::P010
1458 | Self::Rgb9e5Ufloat
1459 | Self::Bc1RgbaUnorm
1460 | Self::Bc1RgbaUnormSrgb
1461 | Self::Bc2RgbaUnorm
1462 | Self::Bc2RgbaUnormSrgb
1463 | Self::Bc3RgbaUnorm
1464 | Self::Bc3RgbaUnormSrgb
1465 | Self::Bc4RUnorm
1466 | Self::Bc4RSnorm
1467 | Self::Bc5RgUnorm
1468 | Self::Bc5RgSnorm
1469 | Self::Bc6hRgbUfloat
1470 | Self::Bc6hRgbFloat
1471 | Self::Bc7RgbaUnorm
1472 | Self::Bc7RgbaUnormSrgb
1473 | Self::Etc2Rgb8Unorm
1474 | Self::Etc2Rgb8UnormSrgb
1475 | Self::Etc2Rgb8A1Unorm
1476 | Self::Etc2Rgb8A1UnormSrgb
1477 | Self::Etc2Rgba8Unorm
1478 | Self::Etc2Rgba8UnormSrgb
1479 | Self::EacR11Unorm
1480 | Self::EacR11Snorm
1481 | Self::EacRg11Unorm
1482 | Self::EacRg11Snorm
1483 | Self::Astc { .. } => None,
1484 }
1485 }
1486
1487 #[must_use]
1489 pub fn components(&self) -> u8 {
1490 self.components_with_aspect(TextureAspect::All)
1491 }
1492
1493 #[must_use]
1497 pub fn components_with_aspect(&self, aspect: TextureAspect) -> u8 {
1498 match *self {
1499 Self::R8Unorm
1500 | Self::R8Snorm
1501 | Self::R8Uint
1502 | Self::R8Sint
1503 | Self::R16Unorm
1504 | Self::R16Snorm
1505 | Self::R16Uint
1506 | Self::R16Sint
1507 | Self::R16Float
1508 | Self::R32Uint
1509 | Self::R32Sint
1510 | Self::R32Float
1511 | Self::R64Uint => 1,
1512
1513 Self::Rg8Unorm
1514 | Self::Rg8Snorm
1515 | Self::Rg8Uint
1516 | Self::Rg8Sint
1517 | Self::Rg16Unorm
1518 | Self::Rg16Snorm
1519 | Self::Rg16Uint
1520 | Self::Rg16Sint
1521 | Self::Rg16Float
1522 | Self::Rg32Uint
1523 | Self::Rg32Sint
1524 | Self::Rg32Float => 2,
1525
1526 Self::Rgba8Unorm
1527 | Self::Rgba8UnormSrgb
1528 | Self::Rgba8Snorm
1529 | Self::Rgba8Uint
1530 | Self::Rgba8Sint
1531 | Self::Bgra8Unorm
1532 | Self::Bgra8UnormSrgb
1533 | Self::Rgba16Unorm
1534 | Self::Rgba16Snorm
1535 | Self::Rgba16Uint
1536 | Self::Rgba16Sint
1537 | Self::Rgba16Float
1538 | Self::Rgba32Uint
1539 | Self::Rgba32Sint
1540 | Self::Rgba32Float => 4,
1541
1542 Self::Rgb9e5Ufloat | Self::Rg11b10Ufloat => 3,
1543 Self::Rgb10a2Uint | Self::Rgb10a2Unorm => 4,
1544
1545 Self::Stencil8 | Self::Depth16Unorm | Self::Depth24Plus | Self::Depth32Float => 1,
1546
1547 Self::Depth24PlusStencil8 | Self::Depth32FloatStencil8 => match aspect {
1548 TextureAspect::DepthOnly | TextureAspect::StencilOnly => 1,
1549 _ => 2,
1550 },
1551
1552 Self::NV12 | Self::P010 => match aspect {
1553 TextureAspect::Plane0 => 1,
1554 TextureAspect::Plane1 => 2,
1555 _ => 3,
1556 },
1557
1558 Self::Bc4RUnorm | Self::Bc4RSnorm => 1,
1559 Self::Bc5RgUnorm | Self::Bc5RgSnorm => 2,
1560 Self::Bc6hRgbUfloat | Self::Bc6hRgbFloat => 3,
1561 Self::Bc1RgbaUnorm
1562 | Self::Bc1RgbaUnormSrgb
1563 | Self::Bc2RgbaUnorm
1564 | Self::Bc2RgbaUnormSrgb
1565 | Self::Bc3RgbaUnorm
1566 | Self::Bc3RgbaUnormSrgb
1567 | Self::Bc7RgbaUnorm
1568 | Self::Bc7RgbaUnormSrgb => 4,
1569
1570 Self::EacR11Unorm | Self::EacR11Snorm => 1,
1571 Self::EacRg11Unorm | Self::EacRg11Snorm => 2,
1572 Self::Etc2Rgb8Unorm | Self::Etc2Rgb8UnormSrgb => 3,
1573 Self::Etc2Rgb8A1Unorm
1574 | Self::Etc2Rgb8A1UnormSrgb
1575 | Self::Etc2Rgba8Unorm
1576 | Self::Etc2Rgba8UnormSrgb => 4,
1577
1578 Self::Astc { .. } => 4,
1579 }
1580 }
1581
1582 #[must_use]
1589 pub fn remove_srgb_suffix(&self) -> TextureFormat {
1590 match *self {
1591 Self::Rgba8UnormSrgb => Self::Rgba8Unorm,
1592 Self::Bgra8UnormSrgb => Self::Bgra8Unorm,
1593 Self::Bc1RgbaUnormSrgb => Self::Bc1RgbaUnorm,
1594 Self::Bc2RgbaUnormSrgb => Self::Bc2RgbaUnorm,
1595 Self::Bc3RgbaUnormSrgb => Self::Bc3RgbaUnorm,
1596 Self::Bc7RgbaUnormSrgb => Self::Bc7RgbaUnorm,
1597 Self::Etc2Rgb8UnormSrgb => Self::Etc2Rgb8Unorm,
1598 Self::Etc2Rgb8A1UnormSrgb => Self::Etc2Rgb8A1Unorm,
1599 Self::Etc2Rgba8UnormSrgb => Self::Etc2Rgba8Unorm,
1600 Self::Astc {
1601 block,
1602 channel: AstcChannel::UnormSrgb,
1603 } => Self::Astc {
1604 block,
1605 channel: AstcChannel::Unorm,
1606 },
1607 _ => *self,
1608 }
1609 }
1610
1611 #[must_use]
1617 pub fn add_srgb_suffix(&self) -> TextureFormat {
1618 match *self {
1619 Self::Rgba8Unorm => Self::Rgba8UnormSrgb,
1620 Self::Bgra8Unorm => Self::Bgra8UnormSrgb,
1621 Self::Bc1RgbaUnorm => Self::Bc1RgbaUnormSrgb,
1622 Self::Bc2RgbaUnorm => Self::Bc2RgbaUnormSrgb,
1623 Self::Bc3RgbaUnorm => Self::Bc3RgbaUnormSrgb,
1624 Self::Bc7RgbaUnorm => Self::Bc7RgbaUnormSrgb,
1625 Self::Etc2Rgb8Unorm => Self::Etc2Rgb8UnormSrgb,
1626 Self::Etc2Rgb8A1Unorm => Self::Etc2Rgb8A1UnormSrgb,
1627 Self::Etc2Rgba8Unorm => Self::Etc2Rgba8UnormSrgb,
1628 Self::Astc {
1629 block,
1630 channel: AstcChannel::Unorm,
1631 } => Self::Astc {
1632 block,
1633 channel: AstcChannel::UnormSrgb,
1634 },
1635 _ => *self,
1636 }
1637 }
1638
1639 #[must_use]
1646 pub fn has_srgb_suffix(&self) -> bool {
1647 *self != self.remove_srgb_suffix()
1648 }
1649
1650 #[must_use]
1654 pub fn theoretical_memory_footprint(&self, size: crate::Extent3d) -> u64 {
1655 let (block_width, block_height) = self.block_dimensions();
1656
1657 let block_size = self.block_copy_size(None);
1658
1659 let approximate_block_size = match block_size {
1660 Some(size) => size,
1661 None => match self {
1662 Self::Depth16Unorm => 2,
1664 Self::Depth24Plus => 4,
1666 Self::Depth24PlusStencil8 => 4,
1668 Self::Depth32Float => 4,
1670 Self::Depth32FloatStencil8 => 8,
1672 Self::Stencil8 => 1,
1674 Self::NV12 => 3,
1676 Self::P010 => 6,
1678 f => {
1679 unimplemented!("Memory footprint for format {f:?} is not implemented");
1680 }
1681 },
1682 };
1683
1684 let width_blocks = size.width.div_ceil(block_width) as u64;
1685 let height_blocks = size.height.div_ceil(block_height) as u64;
1686
1687 let total_blocks = width_blocks * height_blocks * size.depth_or_array_layers as u64;
1688
1689 total_blocks * approximate_block_size as u64
1690 }
1691}
1692
1693#[cfg(any(feature = "serde", test))]
1694impl<'de> Deserialize<'de> for TextureFormat {
1695 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1696 where
1697 D: serde::Deserializer<'de>,
1698 {
1699 use serde::de::{self, Error, Unexpected};
1700
1701 struct TextureFormatVisitor;
1702
1703 impl de::Visitor<'_> for TextureFormatVisitor {
1704 type Value = TextureFormat;
1705
1706 fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
1707 formatter.write_str("a valid texture format")
1708 }
1709
1710 fn visit_str<E: Error>(self, s: &str) -> Result<Self::Value, E> {
1711 let format = match s {
1712 "r8unorm" => TextureFormat::R8Unorm,
1713 "r8snorm" => TextureFormat::R8Snorm,
1714 "r8uint" => TextureFormat::R8Uint,
1715 "r8sint" => TextureFormat::R8Sint,
1716 "r16uint" => TextureFormat::R16Uint,
1717 "r16sint" => TextureFormat::R16Sint,
1718 "r16unorm" => TextureFormat::R16Unorm,
1719 "r16snorm" => TextureFormat::R16Snorm,
1720 "r16float" => TextureFormat::R16Float,
1721 "rg8unorm" => TextureFormat::Rg8Unorm,
1722 "rg8snorm" => TextureFormat::Rg8Snorm,
1723 "rg8uint" => TextureFormat::Rg8Uint,
1724 "rg8sint" => TextureFormat::Rg8Sint,
1725 "r32uint" => TextureFormat::R32Uint,
1726 "r32sint" => TextureFormat::R32Sint,
1727 "r32float" => TextureFormat::R32Float,
1728 "rg16uint" => TextureFormat::Rg16Uint,
1729 "rg16sint" => TextureFormat::Rg16Sint,
1730 "rg16unorm" => TextureFormat::Rg16Unorm,
1731 "rg16snorm" => TextureFormat::Rg16Snorm,
1732 "rg16float" => TextureFormat::Rg16Float,
1733 "rgba8unorm" => TextureFormat::Rgba8Unorm,
1734 "rgba8unorm-srgb" => TextureFormat::Rgba8UnormSrgb,
1735 "rgba8snorm" => TextureFormat::Rgba8Snorm,
1736 "rgba8uint" => TextureFormat::Rgba8Uint,
1737 "rgba8sint" => TextureFormat::Rgba8Sint,
1738 "bgra8unorm" => TextureFormat::Bgra8Unorm,
1739 "bgra8unorm-srgb" => TextureFormat::Bgra8UnormSrgb,
1740 "rgb10a2uint" => TextureFormat::Rgb10a2Uint,
1741 "rgb10a2unorm" => TextureFormat::Rgb10a2Unorm,
1742 "rg11b10ufloat" => TextureFormat::Rg11b10Ufloat,
1743 "r64uint" => TextureFormat::R64Uint,
1744 "rg32uint" => TextureFormat::Rg32Uint,
1745 "rg32sint" => TextureFormat::Rg32Sint,
1746 "rg32float" => TextureFormat::Rg32Float,
1747 "rgba16uint" => TextureFormat::Rgba16Uint,
1748 "rgba16sint" => TextureFormat::Rgba16Sint,
1749 "rgba16unorm" => TextureFormat::Rgba16Unorm,
1750 "rgba16snorm" => TextureFormat::Rgba16Snorm,
1751 "rgba16float" => TextureFormat::Rgba16Float,
1752 "rgba32uint" => TextureFormat::Rgba32Uint,
1753 "rgba32sint" => TextureFormat::Rgba32Sint,
1754 "rgba32float" => TextureFormat::Rgba32Float,
1755 "stencil8" => TextureFormat::Stencil8,
1756 "depth32float" => TextureFormat::Depth32Float,
1757 "depth32float-stencil8" => TextureFormat::Depth32FloatStencil8,
1758 "depth16unorm" => TextureFormat::Depth16Unorm,
1759 "depth24plus" => TextureFormat::Depth24Plus,
1760 "depth24plus-stencil8" => TextureFormat::Depth24PlusStencil8,
1761 "nv12" => TextureFormat::NV12,
1762 "p010" => TextureFormat::P010,
1763 "rgb9e5ufloat" => TextureFormat::Rgb9e5Ufloat,
1764 "bc1-rgba-unorm" => TextureFormat::Bc1RgbaUnorm,
1765 "bc1-rgba-unorm-srgb" => TextureFormat::Bc1RgbaUnormSrgb,
1766 "bc2-rgba-unorm" => TextureFormat::Bc2RgbaUnorm,
1767 "bc2-rgba-unorm-srgb" => TextureFormat::Bc2RgbaUnormSrgb,
1768 "bc3-rgba-unorm" => TextureFormat::Bc3RgbaUnorm,
1769 "bc3-rgba-unorm-srgb" => TextureFormat::Bc3RgbaUnormSrgb,
1770 "bc4-r-unorm" => TextureFormat::Bc4RUnorm,
1771 "bc4-r-snorm" => TextureFormat::Bc4RSnorm,
1772 "bc5-rg-unorm" => TextureFormat::Bc5RgUnorm,
1773 "bc5-rg-snorm" => TextureFormat::Bc5RgSnorm,
1774 "bc6h-rgb-ufloat" => TextureFormat::Bc6hRgbUfloat,
1775 "bc6h-rgb-float" => TextureFormat::Bc6hRgbFloat,
1776 "bc7-rgba-unorm" => TextureFormat::Bc7RgbaUnorm,
1777 "bc7-rgba-unorm-srgb" => TextureFormat::Bc7RgbaUnormSrgb,
1778 "etc2-rgb8unorm" => TextureFormat::Etc2Rgb8Unorm,
1779 "etc2-rgb8unorm-srgb" => TextureFormat::Etc2Rgb8UnormSrgb,
1780 "etc2-rgb8a1unorm" => TextureFormat::Etc2Rgb8A1Unorm,
1781 "etc2-rgb8a1unorm-srgb" => TextureFormat::Etc2Rgb8A1UnormSrgb,
1782 "etc2-rgba8unorm" => TextureFormat::Etc2Rgba8Unorm,
1783 "etc2-rgba8unorm-srgb" => TextureFormat::Etc2Rgba8UnormSrgb,
1784 "eac-r11unorm" => TextureFormat::EacR11Unorm,
1785 "eac-r11snorm" => TextureFormat::EacR11Snorm,
1786 "eac-rg11unorm" => TextureFormat::EacRg11Unorm,
1787 "eac-rg11snorm" => TextureFormat::EacRg11Snorm,
1788 other => {
1789 if let Some(parts) = other.strip_prefix("astc-") {
1790 let (block, channel) = parts
1791 .split_once('-')
1792 .ok_or_else(|| E::invalid_value(Unexpected::Str(s), &self))?;
1793
1794 let block = match block {
1795 "4x4" => AstcBlock::B4x4,
1796 "5x4" => AstcBlock::B5x4,
1797 "5x5" => AstcBlock::B5x5,
1798 "6x5" => AstcBlock::B6x5,
1799 "6x6" => AstcBlock::B6x6,
1800 "8x5" => AstcBlock::B8x5,
1801 "8x6" => AstcBlock::B8x6,
1802 "8x8" => AstcBlock::B8x8,
1803 "10x5" => AstcBlock::B10x5,
1804 "10x6" => AstcBlock::B10x6,
1805 "10x8" => AstcBlock::B10x8,
1806 "10x10" => AstcBlock::B10x10,
1807 "12x10" => AstcBlock::B12x10,
1808 "12x12" => AstcBlock::B12x12,
1809 _ => return Err(E::invalid_value(Unexpected::Str(s), &self)),
1810 };
1811
1812 let channel = match channel {
1813 "unorm" => AstcChannel::Unorm,
1814 "unorm-srgb" => AstcChannel::UnormSrgb,
1815 "hdr" => AstcChannel::Hdr,
1816 _ => return Err(E::invalid_value(Unexpected::Str(s), &self)),
1817 };
1818
1819 TextureFormat::Astc { block, channel }
1820 } else {
1821 return Err(E::invalid_value(Unexpected::Str(s), &self));
1822 }
1823 }
1824 };
1825
1826 Ok(format)
1827 }
1828 }
1829
1830 deserializer.deserialize_str(TextureFormatVisitor)
1831 }
1832}
1833
1834#[cfg(any(feature = "serde", test))]
1835impl Serialize for TextureFormat {
1836 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1837 where
1838 S: serde::Serializer,
1839 {
1840 let s: alloc::string::String;
1841 let name = match *self {
1842 TextureFormat::R8Unorm => "r8unorm",
1843 TextureFormat::R8Snorm => "r8snorm",
1844 TextureFormat::R8Uint => "r8uint",
1845 TextureFormat::R8Sint => "r8sint",
1846 TextureFormat::R16Uint => "r16uint",
1847 TextureFormat::R16Sint => "r16sint",
1848 TextureFormat::R16Unorm => "r16unorm",
1849 TextureFormat::R16Snorm => "r16snorm",
1850 TextureFormat::R16Float => "r16float",
1851 TextureFormat::Rg8Unorm => "rg8unorm",
1852 TextureFormat::Rg8Snorm => "rg8snorm",
1853 TextureFormat::Rg8Uint => "rg8uint",
1854 TextureFormat::Rg8Sint => "rg8sint",
1855 TextureFormat::R32Uint => "r32uint",
1856 TextureFormat::R32Sint => "r32sint",
1857 TextureFormat::R32Float => "r32float",
1858 TextureFormat::Rg16Uint => "rg16uint",
1859 TextureFormat::Rg16Sint => "rg16sint",
1860 TextureFormat::Rg16Unorm => "rg16unorm",
1861 TextureFormat::Rg16Snorm => "rg16snorm",
1862 TextureFormat::Rg16Float => "rg16float",
1863 TextureFormat::Rgba8Unorm => "rgba8unorm",
1864 TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb",
1865 TextureFormat::Rgba8Snorm => "rgba8snorm",
1866 TextureFormat::Rgba8Uint => "rgba8uint",
1867 TextureFormat::Rgba8Sint => "rgba8sint",
1868 TextureFormat::Bgra8Unorm => "bgra8unorm",
1869 TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb",
1870 TextureFormat::Rgb10a2Uint => "rgb10a2uint",
1871 TextureFormat::Rgb10a2Unorm => "rgb10a2unorm",
1872 TextureFormat::Rg11b10Ufloat => "rg11b10ufloat",
1873 TextureFormat::R64Uint => "r64uint",
1874 TextureFormat::Rg32Uint => "rg32uint",
1875 TextureFormat::Rg32Sint => "rg32sint",
1876 TextureFormat::Rg32Float => "rg32float",
1877 TextureFormat::Rgba16Uint => "rgba16uint",
1878 TextureFormat::Rgba16Sint => "rgba16sint",
1879 TextureFormat::Rgba16Unorm => "rgba16unorm",
1880 TextureFormat::Rgba16Snorm => "rgba16snorm",
1881 TextureFormat::Rgba16Float => "rgba16float",
1882 TextureFormat::Rgba32Uint => "rgba32uint",
1883 TextureFormat::Rgba32Sint => "rgba32sint",
1884 TextureFormat::Rgba32Float => "rgba32float",
1885 TextureFormat::Stencil8 => "stencil8",
1886 TextureFormat::Depth32Float => "depth32float",
1887 TextureFormat::Depth16Unorm => "depth16unorm",
1888 TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8",
1889 TextureFormat::Depth24Plus => "depth24plus",
1890 TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8",
1891 TextureFormat::NV12 => "nv12",
1892 TextureFormat::P010 => "p010",
1893 TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat",
1894 TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm",
1895 TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb",
1896 TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm",
1897 TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb",
1898 TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm",
1899 TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb",
1900 TextureFormat::Bc4RUnorm => "bc4-r-unorm",
1901 TextureFormat::Bc4RSnorm => "bc4-r-snorm",
1902 TextureFormat::Bc5RgUnorm => "bc5-rg-unorm",
1903 TextureFormat::Bc5RgSnorm => "bc5-rg-snorm",
1904 TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat",
1905 TextureFormat::Bc6hRgbFloat => "bc6h-rgb-float",
1906 TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm",
1907 TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb",
1908 TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm",
1909 TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb",
1910 TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm",
1911 TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb",
1912 TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm",
1913 TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb",
1914 TextureFormat::EacR11Unorm => "eac-r11unorm",
1915 TextureFormat::EacR11Snorm => "eac-r11snorm",
1916 TextureFormat::EacRg11Unorm => "eac-rg11unorm",
1917 TextureFormat::EacRg11Snorm => "eac-rg11snorm",
1918 TextureFormat::Astc { block, channel } => {
1919 let block = match block {
1920 AstcBlock::B4x4 => "4x4",
1921 AstcBlock::B5x4 => "5x4",
1922 AstcBlock::B5x5 => "5x5",
1923 AstcBlock::B6x5 => "6x5",
1924 AstcBlock::B6x6 => "6x6",
1925 AstcBlock::B8x5 => "8x5",
1926 AstcBlock::B8x6 => "8x6",
1927 AstcBlock::B8x8 => "8x8",
1928 AstcBlock::B10x5 => "10x5",
1929 AstcBlock::B10x6 => "10x6",
1930 AstcBlock::B10x8 => "10x8",
1931 AstcBlock::B10x10 => "10x10",
1932 AstcBlock::B12x10 => "12x10",
1933 AstcBlock::B12x12 => "12x12",
1934 };
1935
1936 let channel = match channel {
1937 AstcChannel::Unorm => "unorm",
1938 AstcChannel::UnormSrgb => "unorm-srgb",
1939 AstcChannel::Hdr => "hdr",
1940 };
1941
1942 s = alloc::format!("astc-{block}-{channel}");
1943 &s
1944 }
1945 };
1946 serializer.serialize_str(name)
1947 }
1948}
1949
1950bitflags::bitflags! {
1951 #[repr(transparent)]
1953 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1954 #[cfg_attr(feature = "serde", serde(transparent))]
1955 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1956 pub struct TextureFormatFeatureFlags: u32 {
1957 const FILTERABLE = 1 << 0;
1960 const MULTISAMPLE_X2 = 1 << 1;
1962 const MULTISAMPLE_X4 = 1 << 2 ;
1964 const MULTISAMPLE_X8 = 1 << 3 ;
1966 const MULTISAMPLE_X16 = 1 << 4;
1968 const MULTISAMPLE_RESOLVE = 1 << 5;
1971 const STORAGE_READ_ONLY = 1 << 6;
1974 const STORAGE_WRITE_ONLY = 1 << 7;
1977 const STORAGE_READ_WRITE = 1 << 8;
1980 const STORAGE_ATOMIC = 1 << 9;
1983 const BLENDABLE = 1 << 10;
1985 }
1986}
1987
1988impl TextureFormatFeatureFlags {
1989 #[must_use]
1993 pub fn sample_count_supported(&self, count: u32) -> bool {
1994 use TextureFormatFeatureFlags as tfsc;
1995
1996 match count {
1997 1 => true,
1998 2 => self.contains(tfsc::MULTISAMPLE_X2),
1999 4 => self.contains(tfsc::MULTISAMPLE_X4),
2000 8 => self.contains(tfsc::MULTISAMPLE_X8),
2001 16 => self.contains(tfsc::MULTISAMPLE_X16),
2002 _ => false,
2003 }
2004 }
2005
2006 #[must_use]
2008 pub fn supported_sample_counts(&self) -> Vec<u32> {
2009 let all_possible_sample_counts: [u32; 5] = [1, 2, 4, 8, 16];
2010 all_possible_sample_counts
2011 .into_iter()
2012 .filter(|&sc| self.sample_count_supported(sc))
2013 .collect()
2014 }
2015}
2016
2017#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
2021#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2022pub struct TextureFormatFeatures {
2023 pub allowed_usages: TextureUsages,
2025 pub flags: TextureFormatFeatureFlags,
2027}
2028
2029#[cfg(test)]
2030mod tests {
2031 use super::*;
2032 use exhaust::Exhaust;
2033 use hashbrown::HashSet;
2034
2035 #[test]
2036 fn texture_format_serialize() {
2037 use alloc::string::ToString;
2038
2039 assert_eq!(
2040 serde_json::to_string(&TextureFormat::R8Unorm).unwrap(),
2041 "\"r8unorm\"".to_string()
2042 );
2043 assert_eq!(
2044 serde_json::to_string(&TextureFormat::R8Snorm).unwrap(),
2045 "\"r8snorm\"".to_string()
2046 );
2047 assert_eq!(
2048 serde_json::to_string(&TextureFormat::R8Uint).unwrap(),
2049 "\"r8uint\"".to_string()
2050 );
2051 assert_eq!(
2052 serde_json::to_string(&TextureFormat::R8Sint).unwrap(),
2053 "\"r8sint\"".to_string()
2054 );
2055 assert_eq!(
2056 serde_json::to_string(&TextureFormat::R16Uint).unwrap(),
2057 "\"r16uint\"".to_string()
2058 );
2059 assert_eq!(
2060 serde_json::to_string(&TextureFormat::R16Sint).unwrap(),
2061 "\"r16sint\"".to_string()
2062 );
2063 assert_eq!(
2064 serde_json::to_string(&TextureFormat::R16Unorm).unwrap(),
2065 "\"r16unorm\"".to_string()
2066 );
2067 assert_eq!(
2068 serde_json::to_string(&TextureFormat::R16Snorm).unwrap(),
2069 "\"r16snorm\"".to_string()
2070 );
2071 assert_eq!(
2072 serde_json::to_string(&TextureFormat::R16Float).unwrap(),
2073 "\"r16float\"".to_string()
2074 );
2075 assert_eq!(
2076 serde_json::to_string(&TextureFormat::Rg8Unorm).unwrap(),
2077 "\"rg8unorm\"".to_string()
2078 );
2079 assert_eq!(
2080 serde_json::to_string(&TextureFormat::Rg8Snorm).unwrap(),
2081 "\"rg8snorm\"".to_string()
2082 );
2083 assert_eq!(
2084 serde_json::to_string(&TextureFormat::Rg8Uint).unwrap(),
2085 "\"rg8uint\"".to_string()
2086 );
2087 assert_eq!(
2088 serde_json::to_string(&TextureFormat::Rg8Sint).unwrap(),
2089 "\"rg8sint\"".to_string()
2090 );
2091 assert_eq!(
2092 serde_json::to_string(&TextureFormat::R32Uint).unwrap(),
2093 "\"r32uint\"".to_string()
2094 );
2095 assert_eq!(
2096 serde_json::to_string(&TextureFormat::R32Sint).unwrap(),
2097 "\"r32sint\"".to_string()
2098 );
2099 assert_eq!(
2100 serde_json::to_string(&TextureFormat::R32Float).unwrap(),
2101 "\"r32float\"".to_string()
2102 );
2103 assert_eq!(
2104 serde_json::to_string(&TextureFormat::Rg16Uint).unwrap(),
2105 "\"rg16uint\"".to_string()
2106 );
2107 assert_eq!(
2108 serde_json::to_string(&TextureFormat::Rg16Sint).unwrap(),
2109 "\"rg16sint\"".to_string()
2110 );
2111 assert_eq!(
2112 serde_json::to_string(&TextureFormat::Rg16Unorm).unwrap(),
2113 "\"rg16unorm\"".to_string()
2114 );
2115 assert_eq!(
2116 serde_json::to_string(&TextureFormat::Rg16Snorm).unwrap(),
2117 "\"rg16snorm\"".to_string()
2118 );
2119 assert_eq!(
2120 serde_json::to_string(&TextureFormat::Rg16Float).unwrap(),
2121 "\"rg16float\"".to_string()
2122 );
2123 assert_eq!(
2124 serde_json::to_string(&TextureFormat::Rgba8Unorm).unwrap(),
2125 "\"rgba8unorm\"".to_string()
2126 );
2127 assert_eq!(
2128 serde_json::to_string(&TextureFormat::Rgba8UnormSrgb).unwrap(),
2129 "\"rgba8unorm-srgb\"".to_string()
2130 );
2131 assert_eq!(
2132 serde_json::to_string(&TextureFormat::Rgba8Snorm).unwrap(),
2133 "\"rgba8snorm\"".to_string()
2134 );
2135 assert_eq!(
2136 serde_json::to_string(&TextureFormat::Rgba8Uint).unwrap(),
2137 "\"rgba8uint\"".to_string()
2138 );
2139 assert_eq!(
2140 serde_json::to_string(&TextureFormat::Rgba8Sint).unwrap(),
2141 "\"rgba8sint\"".to_string()
2142 );
2143 assert_eq!(
2144 serde_json::to_string(&TextureFormat::Bgra8Unorm).unwrap(),
2145 "\"bgra8unorm\"".to_string()
2146 );
2147 assert_eq!(
2148 serde_json::to_string(&TextureFormat::Bgra8UnormSrgb).unwrap(),
2149 "\"bgra8unorm-srgb\"".to_string()
2150 );
2151 assert_eq!(
2152 serde_json::to_string(&TextureFormat::Rgb10a2Uint).unwrap(),
2153 "\"rgb10a2uint\"".to_string()
2154 );
2155 assert_eq!(
2156 serde_json::to_string(&TextureFormat::Rgb10a2Unorm).unwrap(),
2157 "\"rgb10a2unorm\"".to_string()
2158 );
2159 assert_eq!(
2160 serde_json::to_string(&TextureFormat::Rg11b10Ufloat).unwrap(),
2161 "\"rg11b10ufloat\"".to_string()
2162 );
2163 assert_eq!(
2164 serde_json::to_string(&TextureFormat::R64Uint).unwrap(),
2165 "\"r64uint\"".to_string()
2166 );
2167 assert_eq!(
2168 serde_json::to_string(&TextureFormat::Rg32Uint).unwrap(),
2169 "\"rg32uint\"".to_string()
2170 );
2171 assert_eq!(
2172 serde_json::to_string(&TextureFormat::Rg32Sint).unwrap(),
2173 "\"rg32sint\"".to_string()
2174 );
2175 assert_eq!(
2176 serde_json::to_string(&TextureFormat::Rg32Float).unwrap(),
2177 "\"rg32float\"".to_string()
2178 );
2179 assert_eq!(
2180 serde_json::to_string(&TextureFormat::Rgba16Uint).unwrap(),
2181 "\"rgba16uint\"".to_string()
2182 );
2183 assert_eq!(
2184 serde_json::to_string(&TextureFormat::Rgba16Sint).unwrap(),
2185 "\"rgba16sint\"".to_string()
2186 );
2187 assert_eq!(
2188 serde_json::to_string(&TextureFormat::Rgba16Unorm).unwrap(),
2189 "\"rgba16unorm\"".to_string()
2190 );
2191 assert_eq!(
2192 serde_json::to_string(&TextureFormat::Rgba16Snorm).unwrap(),
2193 "\"rgba16snorm\"".to_string()
2194 );
2195 assert_eq!(
2196 serde_json::to_string(&TextureFormat::Rgba16Float).unwrap(),
2197 "\"rgba16float\"".to_string()
2198 );
2199 assert_eq!(
2200 serde_json::to_string(&TextureFormat::Rgba32Uint).unwrap(),
2201 "\"rgba32uint\"".to_string()
2202 );
2203 assert_eq!(
2204 serde_json::to_string(&TextureFormat::Rgba32Sint).unwrap(),
2205 "\"rgba32sint\"".to_string()
2206 );
2207 assert_eq!(
2208 serde_json::to_string(&TextureFormat::Rgba32Float).unwrap(),
2209 "\"rgba32float\"".to_string()
2210 );
2211 assert_eq!(
2212 serde_json::to_string(&TextureFormat::Stencil8).unwrap(),
2213 "\"stencil8\"".to_string()
2214 );
2215 assert_eq!(
2216 serde_json::to_string(&TextureFormat::Depth32Float).unwrap(),
2217 "\"depth32float\"".to_string()
2218 );
2219 assert_eq!(
2220 serde_json::to_string(&TextureFormat::Depth16Unorm).unwrap(),
2221 "\"depth16unorm\"".to_string()
2222 );
2223 assert_eq!(
2224 serde_json::to_string(&TextureFormat::Depth32FloatStencil8).unwrap(),
2225 "\"depth32float-stencil8\"".to_string()
2226 );
2227 assert_eq!(
2228 serde_json::to_string(&TextureFormat::Depth24Plus).unwrap(),
2229 "\"depth24plus\"".to_string()
2230 );
2231 assert_eq!(
2232 serde_json::to_string(&TextureFormat::Depth24PlusStencil8).unwrap(),
2233 "\"depth24plus-stencil8\"".to_string()
2234 );
2235 assert_eq!(
2236 serde_json::to_string(&TextureFormat::Rgb9e5Ufloat).unwrap(),
2237 "\"rgb9e5ufloat\"".to_string()
2238 );
2239 assert_eq!(
2240 serde_json::to_string(&TextureFormat::Bc1RgbaUnorm).unwrap(),
2241 "\"bc1-rgba-unorm\"".to_string()
2242 );
2243 assert_eq!(
2244 serde_json::to_string(&TextureFormat::Bc1RgbaUnormSrgb).unwrap(),
2245 "\"bc1-rgba-unorm-srgb\"".to_string()
2246 );
2247 assert_eq!(
2248 serde_json::to_string(&TextureFormat::Bc2RgbaUnorm).unwrap(),
2249 "\"bc2-rgba-unorm\"".to_string()
2250 );
2251 assert_eq!(
2252 serde_json::to_string(&TextureFormat::Bc2RgbaUnormSrgb).unwrap(),
2253 "\"bc2-rgba-unorm-srgb\"".to_string()
2254 );
2255 assert_eq!(
2256 serde_json::to_string(&TextureFormat::Bc3RgbaUnorm).unwrap(),
2257 "\"bc3-rgba-unorm\"".to_string()
2258 );
2259 assert_eq!(
2260 serde_json::to_string(&TextureFormat::Bc3RgbaUnormSrgb).unwrap(),
2261 "\"bc3-rgba-unorm-srgb\"".to_string()
2262 );
2263 assert_eq!(
2264 serde_json::to_string(&TextureFormat::Bc4RUnorm).unwrap(),
2265 "\"bc4-r-unorm\"".to_string()
2266 );
2267 assert_eq!(
2268 serde_json::to_string(&TextureFormat::Bc4RSnorm).unwrap(),
2269 "\"bc4-r-snorm\"".to_string()
2270 );
2271 assert_eq!(
2272 serde_json::to_string(&TextureFormat::Bc5RgUnorm).unwrap(),
2273 "\"bc5-rg-unorm\"".to_string()
2274 );
2275 assert_eq!(
2276 serde_json::to_string(&TextureFormat::Bc5RgSnorm).unwrap(),
2277 "\"bc5-rg-snorm\"".to_string()
2278 );
2279 assert_eq!(
2280 serde_json::to_string(&TextureFormat::Bc6hRgbUfloat).unwrap(),
2281 "\"bc6h-rgb-ufloat\"".to_string()
2282 );
2283 assert_eq!(
2284 serde_json::to_string(&TextureFormat::Bc6hRgbFloat).unwrap(),
2285 "\"bc6h-rgb-float\"".to_string()
2286 );
2287 assert_eq!(
2288 serde_json::to_string(&TextureFormat::Bc7RgbaUnorm).unwrap(),
2289 "\"bc7-rgba-unorm\"".to_string()
2290 );
2291 assert_eq!(
2292 serde_json::to_string(&TextureFormat::Bc7RgbaUnormSrgb).unwrap(),
2293 "\"bc7-rgba-unorm-srgb\"".to_string()
2294 );
2295 assert_eq!(
2296 serde_json::to_string(&TextureFormat::Etc2Rgb8Unorm).unwrap(),
2297 "\"etc2-rgb8unorm\"".to_string()
2298 );
2299 assert_eq!(
2300 serde_json::to_string(&TextureFormat::Etc2Rgb8UnormSrgb).unwrap(),
2301 "\"etc2-rgb8unorm-srgb\"".to_string()
2302 );
2303 assert_eq!(
2304 serde_json::to_string(&TextureFormat::Etc2Rgb8A1Unorm).unwrap(),
2305 "\"etc2-rgb8a1unorm\"".to_string()
2306 );
2307 assert_eq!(
2308 serde_json::to_string(&TextureFormat::Etc2Rgb8A1UnormSrgb).unwrap(),
2309 "\"etc2-rgb8a1unorm-srgb\"".to_string()
2310 );
2311 assert_eq!(
2312 serde_json::to_string(&TextureFormat::Etc2Rgba8Unorm).unwrap(),
2313 "\"etc2-rgba8unorm\"".to_string()
2314 );
2315 assert_eq!(
2316 serde_json::to_string(&TextureFormat::Etc2Rgba8UnormSrgb).unwrap(),
2317 "\"etc2-rgba8unorm-srgb\"".to_string()
2318 );
2319 assert_eq!(
2320 serde_json::to_string(&TextureFormat::EacR11Unorm).unwrap(),
2321 "\"eac-r11unorm\"".to_string()
2322 );
2323 assert_eq!(
2324 serde_json::to_string(&TextureFormat::EacR11Snorm).unwrap(),
2325 "\"eac-r11snorm\"".to_string()
2326 );
2327 assert_eq!(
2328 serde_json::to_string(&TextureFormat::EacRg11Unorm).unwrap(),
2329 "\"eac-rg11unorm\"".to_string()
2330 );
2331 assert_eq!(
2332 serde_json::to_string(&TextureFormat::EacRg11Snorm).unwrap(),
2333 "\"eac-rg11snorm\"".to_string()
2334 );
2335 }
2336
2337 #[test]
2338 fn texture_format_deserialize() {
2339 assert_eq!(
2340 serde_json::from_str::<TextureFormat>("\"r8unorm\"").unwrap(),
2341 TextureFormat::R8Unorm
2342 );
2343 assert_eq!(
2344 serde_json::from_str::<TextureFormat>("\"r8snorm\"").unwrap(),
2345 TextureFormat::R8Snorm
2346 );
2347 assert_eq!(
2348 serde_json::from_str::<TextureFormat>("\"r8uint\"").unwrap(),
2349 TextureFormat::R8Uint
2350 );
2351 assert_eq!(
2352 serde_json::from_str::<TextureFormat>("\"r8sint\"").unwrap(),
2353 TextureFormat::R8Sint
2354 );
2355 assert_eq!(
2356 serde_json::from_str::<TextureFormat>("\"r16uint\"").unwrap(),
2357 TextureFormat::R16Uint
2358 );
2359 assert_eq!(
2360 serde_json::from_str::<TextureFormat>("\"r16sint\"").unwrap(),
2361 TextureFormat::R16Sint
2362 );
2363 assert_eq!(
2364 serde_json::from_str::<TextureFormat>("\"r16unorm\"").unwrap(),
2365 TextureFormat::R16Unorm
2366 );
2367 assert_eq!(
2368 serde_json::from_str::<TextureFormat>("\"r16snorm\"").unwrap(),
2369 TextureFormat::R16Snorm
2370 );
2371 assert_eq!(
2372 serde_json::from_str::<TextureFormat>("\"r16float\"").unwrap(),
2373 TextureFormat::R16Float
2374 );
2375 assert_eq!(
2376 serde_json::from_str::<TextureFormat>("\"rg8unorm\"").unwrap(),
2377 TextureFormat::Rg8Unorm
2378 );
2379 assert_eq!(
2380 serde_json::from_str::<TextureFormat>("\"rg8snorm\"").unwrap(),
2381 TextureFormat::Rg8Snorm
2382 );
2383 assert_eq!(
2384 serde_json::from_str::<TextureFormat>("\"rg8uint\"").unwrap(),
2385 TextureFormat::Rg8Uint
2386 );
2387 assert_eq!(
2388 serde_json::from_str::<TextureFormat>("\"rg8sint\"").unwrap(),
2389 TextureFormat::Rg8Sint
2390 );
2391 assert_eq!(
2392 serde_json::from_str::<TextureFormat>("\"r32uint\"").unwrap(),
2393 TextureFormat::R32Uint
2394 );
2395 assert_eq!(
2396 serde_json::from_str::<TextureFormat>("\"r32sint\"").unwrap(),
2397 TextureFormat::R32Sint
2398 );
2399 assert_eq!(
2400 serde_json::from_str::<TextureFormat>("\"r32float\"").unwrap(),
2401 TextureFormat::R32Float
2402 );
2403 assert_eq!(
2404 serde_json::from_str::<TextureFormat>("\"rg16uint\"").unwrap(),
2405 TextureFormat::Rg16Uint
2406 );
2407 assert_eq!(
2408 serde_json::from_str::<TextureFormat>("\"rg16sint\"").unwrap(),
2409 TextureFormat::Rg16Sint
2410 );
2411 assert_eq!(
2412 serde_json::from_str::<TextureFormat>("\"rg16unorm\"").unwrap(),
2413 TextureFormat::Rg16Unorm
2414 );
2415 assert_eq!(
2416 serde_json::from_str::<TextureFormat>("\"rg16snorm\"").unwrap(),
2417 TextureFormat::Rg16Snorm
2418 );
2419 assert_eq!(
2420 serde_json::from_str::<TextureFormat>("\"rg16float\"").unwrap(),
2421 TextureFormat::Rg16Float
2422 );
2423 assert_eq!(
2424 serde_json::from_str::<TextureFormat>("\"rgba8unorm\"").unwrap(),
2425 TextureFormat::Rgba8Unorm
2426 );
2427 assert_eq!(
2428 serde_json::from_str::<TextureFormat>("\"rgba8unorm-srgb\"").unwrap(),
2429 TextureFormat::Rgba8UnormSrgb
2430 );
2431 assert_eq!(
2432 serde_json::from_str::<TextureFormat>("\"rgba8snorm\"").unwrap(),
2433 TextureFormat::Rgba8Snorm
2434 );
2435 assert_eq!(
2436 serde_json::from_str::<TextureFormat>("\"rgba8uint\"").unwrap(),
2437 TextureFormat::Rgba8Uint
2438 );
2439 assert_eq!(
2440 serde_json::from_str::<TextureFormat>("\"rgba8sint\"").unwrap(),
2441 TextureFormat::Rgba8Sint
2442 );
2443 assert_eq!(
2444 serde_json::from_str::<TextureFormat>("\"bgra8unorm\"").unwrap(),
2445 TextureFormat::Bgra8Unorm
2446 );
2447 assert_eq!(
2448 serde_json::from_str::<TextureFormat>("\"bgra8unorm-srgb\"").unwrap(),
2449 TextureFormat::Bgra8UnormSrgb
2450 );
2451 assert_eq!(
2452 serde_json::from_str::<TextureFormat>("\"rgb10a2uint\"").unwrap(),
2453 TextureFormat::Rgb10a2Uint
2454 );
2455 assert_eq!(
2456 serde_json::from_str::<TextureFormat>("\"rgb10a2unorm\"").unwrap(),
2457 TextureFormat::Rgb10a2Unorm
2458 );
2459 assert_eq!(
2460 serde_json::from_str::<TextureFormat>("\"rg11b10ufloat\"").unwrap(),
2461 TextureFormat::Rg11b10Ufloat
2462 );
2463 assert_eq!(
2464 serde_json::from_str::<TextureFormat>("\"r64uint\"").unwrap(),
2465 TextureFormat::R64Uint
2466 );
2467 assert_eq!(
2468 serde_json::from_str::<TextureFormat>("\"rg32uint\"").unwrap(),
2469 TextureFormat::Rg32Uint
2470 );
2471 assert_eq!(
2472 serde_json::from_str::<TextureFormat>("\"rg32sint\"").unwrap(),
2473 TextureFormat::Rg32Sint
2474 );
2475 assert_eq!(
2476 serde_json::from_str::<TextureFormat>("\"rg32float\"").unwrap(),
2477 TextureFormat::Rg32Float
2478 );
2479 assert_eq!(
2480 serde_json::from_str::<TextureFormat>("\"rgba16uint\"").unwrap(),
2481 TextureFormat::Rgba16Uint
2482 );
2483 assert_eq!(
2484 serde_json::from_str::<TextureFormat>("\"rgba16sint\"").unwrap(),
2485 TextureFormat::Rgba16Sint
2486 );
2487 assert_eq!(
2488 serde_json::from_str::<TextureFormat>("\"rgba16unorm\"").unwrap(),
2489 TextureFormat::Rgba16Unorm
2490 );
2491 assert_eq!(
2492 serde_json::from_str::<TextureFormat>("\"rgba16snorm\"").unwrap(),
2493 TextureFormat::Rgba16Snorm
2494 );
2495 assert_eq!(
2496 serde_json::from_str::<TextureFormat>("\"rgba16float\"").unwrap(),
2497 TextureFormat::Rgba16Float
2498 );
2499 assert_eq!(
2500 serde_json::from_str::<TextureFormat>("\"rgba32uint\"").unwrap(),
2501 TextureFormat::Rgba32Uint
2502 );
2503 assert_eq!(
2504 serde_json::from_str::<TextureFormat>("\"rgba32sint\"").unwrap(),
2505 TextureFormat::Rgba32Sint
2506 );
2507 assert_eq!(
2508 serde_json::from_str::<TextureFormat>("\"rgba32float\"").unwrap(),
2509 TextureFormat::Rgba32Float
2510 );
2511 assert_eq!(
2512 serde_json::from_str::<TextureFormat>("\"stencil8\"").unwrap(),
2513 TextureFormat::Stencil8
2514 );
2515 assert_eq!(
2516 serde_json::from_str::<TextureFormat>("\"depth32float\"").unwrap(),
2517 TextureFormat::Depth32Float
2518 );
2519 assert_eq!(
2520 serde_json::from_str::<TextureFormat>("\"depth16unorm\"").unwrap(),
2521 TextureFormat::Depth16Unorm
2522 );
2523 assert_eq!(
2524 serde_json::from_str::<TextureFormat>("\"depth32float-stencil8\"").unwrap(),
2525 TextureFormat::Depth32FloatStencil8
2526 );
2527 assert_eq!(
2528 serde_json::from_str::<TextureFormat>("\"depth24plus\"").unwrap(),
2529 TextureFormat::Depth24Plus
2530 );
2531 assert_eq!(
2532 serde_json::from_str::<TextureFormat>("\"depth24plus-stencil8\"").unwrap(),
2533 TextureFormat::Depth24PlusStencil8
2534 );
2535 assert_eq!(
2536 serde_json::from_str::<TextureFormat>("\"rgb9e5ufloat\"").unwrap(),
2537 TextureFormat::Rgb9e5Ufloat
2538 );
2539 assert_eq!(
2540 serde_json::from_str::<TextureFormat>("\"bc1-rgba-unorm\"").unwrap(),
2541 TextureFormat::Bc1RgbaUnorm
2542 );
2543 assert_eq!(
2544 serde_json::from_str::<TextureFormat>("\"bc1-rgba-unorm-srgb\"").unwrap(),
2545 TextureFormat::Bc1RgbaUnormSrgb
2546 );
2547 assert_eq!(
2548 serde_json::from_str::<TextureFormat>("\"bc2-rgba-unorm\"").unwrap(),
2549 TextureFormat::Bc2RgbaUnorm
2550 );
2551 assert_eq!(
2552 serde_json::from_str::<TextureFormat>("\"bc2-rgba-unorm-srgb\"").unwrap(),
2553 TextureFormat::Bc2RgbaUnormSrgb
2554 );
2555 assert_eq!(
2556 serde_json::from_str::<TextureFormat>("\"bc3-rgba-unorm\"").unwrap(),
2557 TextureFormat::Bc3RgbaUnorm
2558 );
2559 assert_eq!(
2560 serde_json::from_str::<TextureFormat>("\"bc3-rgba-unorm-srgb\"").unwrap(),
2561 TextureFormat::Bc3RgbaUnormSrgb
2562 );
2563 assert_eq!(
2564 serde_json::from_str::<TextureFormat>("\"bc4-r-unorm\"").unwrap(),
2565 TextureFormat::Bc4RUnorm
2566 );
2567 assert_eq!(
2568 serde_json::from_str::<TextureFormat>("\"bc4-r-snorm\"").unwrap(),
2569 TextureFormat::Bc4RSnorm
2570 );
2571 assert_eq!(
2572 serde_json::from_str::<TextureFormat>("\"bc5-rg-unorm\"").unwrap(),
2573 TextureFormat::Bc5RgUnorm
2574 );
2575 assert_eq!(
2576 serde_json::from_str::<TextureFormat>("\"bc5-rg-snorm\"").unwrap(),
2577 TextureFormat::Bc5RgSnorm
2578 );
2579 assert_eq!(
2580 serde_json::from_str::<TextureFormat>("\"bc6h-rgb-ufloat\"").unwrap(),
2581 TextureFormat::Bc6hRgbUfloat
2582 );
2583 assert_eq!(
2584 serde_json::from_str::<TextureFormat>("\"bc6h-rgb-float\"").unwrap(),
2585 TextureFormat::Bc6hRgbFloat
2586 );
2587 assert_eq!(
2588 serde_json::from_str::<TextureFormat>("\"bc7-rgba-unorm\"").unwrap(),
2589 TextureFormat::Bc7RgbaUnorm
2590 );
2591 assert_eq!(
2592 serde_json::from_str::<TextureFormat>("\"bc7-rgba-unorm-srgb\"").unwrap(),
2593 TextureFormat::Bc7RgbaUnormSrgb
2594 );
2595 assert_eq!(
2596 serde_json::from_str::<TextureFormat>("\"etc2-rgb8unorm\"").unwrap(),
2597 TextureFormat::Etc2Rgb8Unorm
2598 );
2599 assert_eq!(
2600 serde_json::from_str::<TextureFormat>("\"etc2-rgb8unorm-srgb\"").unwrap(),
2601 TextureFormat::Etc2Rgb8UnormSrgb
2602 );
2603 assert_eq!(
2604 serde_json::from_str::<TextureFormat>("\"etc2-rgb8a1unorm\"").unwrap(),
2605 TextureFormat::Etc2Rgb8A1Unorm
2606 );
2607 assert_eq!(
2608 serde_json::from_str::<TextureFormat>("\"etc2-rgb8a1unorm-srgb\"").unwrap(),
2609 TextureFormat::Etc2Rgb8A1UnormSrgb
2610 );
2611 assert_eq!(
2612 serde_json::from_str::<TextureFormat>("\"etc2-rgba8unorm\"").unwrap(),
2613 TextureFormat::Etc2Rgba8Unorm
2614 );
2615 assert_eq!(
2616 serde_json::from_str::<TextureFormat>("\"etc2-rgba8unorm-srgb\"").unwrap(),
2617 TextureFormat::Etc2Rgba8UnormSrgb
2618 );
2619 assert_eq!(
2620 serde_json::from_str::<TextureFormat>("\"eac-r11unorm\"").unwrap(),
2621 TextureFormat::EacR11Unorm
2622 );
2623 assert_eq!(
2624 serde_json::from_str::<TextureFormat>("\"eac-r11snorm\"").unwrap(),
2625 TextureFormat::EacR11Snorm
2626 );
2627 assert_eq!(
2628 serde_json::from_str::<TextureFormat>("\"eac-rg11unorm\"").unwrap(),
2629 TextureFormat::EacRg11Unorm
2630 );
2631 assert_eq!(
2632 serde_json::from_str::<TextureFormat>("\"eac-rg11snorm\"").unwrap(),
2633 TextureFormat::EacRg11Snorm
2634 );
2635 }
2636
2637 #[test]
2639 fn is_depth_stencil_format() {
2640 let depth_stencil_formats: HashSet<TextureFormat> = HashSet::from([
2642 TextureFormat::Stencil8,
2643 TextureFormat::Depth16Unorm,
2644 TextureFormat::Depth24Plus,
2645 TextureFormat::Depth24PlusStencil8,
2646 TextureFormat::Depth32Float,
2647 TextureFormat::Depth32FloatStencil8,
2648 ]);
2649
2650 for format in TextureFormat::exhaust() {
2651 if depth_stencil_formats.contains(&format) {
2652 assert!(format.is_depth_stencil_format());
2653 } else {
2654 assert!(!format.is_depth_stencil_format());
2655 }
2656 }
2657 }
2658
2659 #[test]
2661 fn is_combined_depth_stencil_format() {
2662 let valid_formats = [
2664 TextureFormat::Depth24PlusStencil8,
2665 TextureFormat::Depth32FloatStencil8,
2666 ];
2667
2668 for format in TextureFormat::exhaust() {
2669 if valid_formats.contains(&format) {
2670 assert!(format.is_combined_depth_stencil_format());
2671 } else {
2672 assert!(!format.is_combined_depth_stencil_format());
2673 }
2674 }
2675 }
2676
2677 #[test]
2679 fn has_color_aspect() {
2680 let valid_formats: HashSet<TextureFormat> = HashSet::from([
2682 TextureFormat::R8Unorm,
2683 TextureFormat::R8Snorm,
2684 TextureFormat::R8Uint,
2685 TextureFormat::R8Sint,
2686 TextureFormat::R16Uint,
2687 TextureFormat::R16Sint,
2688 TextureFormat::R16Unorm,
2689 TextureFormat::R16Snorm,
2690 TextureFormat::R16Float,
2691 TextureFormat::Rg8Unorm,
2692 TextureFormat::Rg8Snorm,
2693 TextureFormat::Rg8Uint,
2694 TextureFormat::Rg8Sint,
2695 TextureFormat::R32Uint,
2696 TextureFormat::R32Sint,
2697 TextureFormat::R32Float,
2698 TextureFormat::Rg16Uint,
2699 TextureFormat::Rg16Sint,
2700 TextureFormat::Rg16Unorm,
2701 TextureFormat::Rg16Snorm,
2702 TextureFormat::Rg16Float,
2703 TextureFormat::Rgba8Unorm,
2704 TextureFormat::Rgba8UnormSrgb,
2705 TextureFormat::Rgba8Snorm,
2706 TextureFormat::Rgba8Uint,
2707 TextureFormat::Rgba8Sint,
2708 TextureFormat::Bgra8Unorm,
2709 TextureFormat::Bgra8UnormSrgb,
2710 TextureFormat::Rgb9e5Ufloat,
2711 TextureFormat::Rgb10a2Uint,
2712 TextureFormat::Rgb10a2Unorm,
2713 TextureFormat::Rg11b10Ufloat,
2714 TextureFormat::R64Uint,
2715 TextureFormat::Rg32Uint,
2716 TextureFormat::Rg32Sint,
2717 TextureFormat::Rg32Float,
2718 TextureFormat::Rgba16Uint,
2719 TextureFormat::Rgba16Sint,
2720 TextureFormat::Rgba16Unorm,
2721 TextureFormat::Rgba16Snorm,
2722 TextureFormat::Rgba16Float,
2723 TextureFormat::Rgba32Uint,
2724 TextureFormat::Rgba32Sint,
2725 TextureFormat::Rgba32Float,
2726 TextureFormat::Bc1RgbaUnorm,
2727 TextureFormat::Bc1RgbaUnormSrgb,
2728 TextureFormat::Bc2RgbaUnorm,
2729 TextureFormat::Bc2RgbaUnormSrgb,
2730 TextureFormat::Bc3RgbaUnorm,
2731 TextureFormat::Bc3RgbaUnormSrgb,
2732 TextureFormat::Bc4RUnorm,
2733 TextureFormat::Bc4RSnorm,
2734 TextureFormat::Bc5RgUnorm,
2735 TextureFormat::Bc5RgSnorm,
2736 TextureFormat::Bc6hRgbUfloat,
2737 TextureFormat::Bc6hRgbFloat,
2738 TextureFormat::Bc7RgbaUnorm,
2739 TextureFormat::Bc7RgbaUnormSrgb,
2740 TextureFormat::Etc2Rgb8Unorm,
2741 TextureFormat::Etc2Rgb8UnormSrgb,
2742 TextureFormat::Etc2Rgb8A1Unorm,
2743 TextureFormat::Etc2Rgb8A1UnormSrgb,
2744 TextureFormat::Etc2Rgba8Unorm,
2745 TextureFormat::Etc2Rgba8UnormSrgb,
2746 TextureFormat::EacR11Unorm,
2747 TextureFormat::EacR11Snorm,
2748 TextureFormat::EacRg11Unorm,
2749 TextureFormat::EacRg11Snorm,
2750 ]);
2751
2752 for format in TextureFormat::exhaust() {
2753 if let TextureFormat::Astc { .. } = format {
2754 assert!(format.has_color_aspect(), "{:?} failed", format);
2756 } else if valid_formats.contains(&format) {
2757 assert!(format.has_color_aspect(), "{:?} failed", format);
2758 } else {
2759 assert!(!format.has_color_aspect(), "{:?} failed", format);
2760 }
2761 }
2762 }
2763
2764 #[test]
2766 fn has_depth_aspect() {
2767 let valid_formats: HashSet<TextureFormat> = HashSet::from([
2769 TextureFormat::Depth16Unorm,
2770 TextureFormat::Depth24Plus,
2771 TextureFormat::Depth24PlusStencil8,
2772 TextureFormat::Depth32Float,
2773 TextureFormat::Depth32FloatStencil8,
2774 ]);
2775
2776 for format in TextureFormat::exhaust() {
2777 if valid_formats.contains(&format) {
2778 assert!(format.has_depth_aspect());
2779 } else {
2780 assert!(!format.has_depth_aspect());
2781 }
2782 }
2783 }
2784
2785 #[test]
2787 fn has_stencil_aspect() {
2788 let valid_formats: HashSet<TextureFormat> = HashSet::from([
2790 TextureFormat::Stencil8,
2791 TextureFormat::Depth24PlusStencil8,
2792 TextureFormat::Depth32FloatStencil8,
2793 ]);
2794
2795 for format in TextureFormat::exhaust() {
2796 if valid_formats.contains(&format) {
2797 assert!(format.has_stencil_aspect());
2798 } else {
2799 assert!(!format.has_stencil_aspect());
2800 }
2801 }
2802 }
2803}