use ash-formats
This commit is contained in:
parent
6e9da846bb
commit
0e19b8d99b
|
|
@ -39,6 +39,7 @@ bitflags = "2.6"
|
|||
thread_local = "1.1.8"
|
||||
|
||||
ash = "0.38.0"
|
||||
ash-formats = { git = "https://github.com/janis-bhm/ash-formats.git", version = "0.1.0" }
|
||||
ash-window = "0.13.0"
|
||||
# vk-mem = "0.5.0"
|
||||
gpu-allocator = { git = "https://github.com/janis-bhm/gpu-allocator", branch = "main" }
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ anyhow = { workspace = true }
|
|||
tracing = { workspace = true }
|
||||
|
||||
ash = { workspace = true }
|
||||
ash-formats = { workspace = true }
|
||||
ash-window = { workspace = true }
|
||||
# vk-mem = { workspace = true }
|
||||
gpu-allocator = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ use crate::{
|
|||
images::{Image, QueueOwnership},
|
||||
pipeline::{Pipeline, PipelineLayout},
|
||||
sync::{self, FenceFuture},
|
||||
util::{self, FormatExt, MutexExt},
|
||||
util::{self, MutexExt},
|
||||
};
|
||||
|
||||
use super::{Device, queue::Queue};
|
||||
use ash::{prelude::*, vk};
|
||||
use ash_formats::FormatHelpers as _;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -475,17 +476,7 @@ pub mod traits {
|
|||
subresources: &[vk::ImageSubresourceRange],
|
||||
) {
|
||||
// assert_eq!(self.state(), CommandBufferState::Recording);
|
||||
let clear_colors = match format.get_component_kind() {
|
||||
crate::util::FormatComponentKind::Float => vk::ClearColorValue {
|
||||
float32: color.into_f32(),
|
||||
},
|
||||
crate::util::FormatComponentKind::UInt => vk::ClearColorValue {
|
||||
uint32: color.into_u32(),
|
||||
},
|
||||
crate::util::FormatComponentKind::SInt => vk::ClearColorValue {
|
||||
int32: color.into_i32(),
|
||||
},
|
||||
};
|
||||
let clear_colors = format.clear_value(color.into_f32());
|
||||
|
||||
unsafe {
|
||||
self.device().dev().cmd_clear_color_image(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use std::{
|
|||
};
|
||||
|
||||
use ash::vk;
|
||||
use ash_formats::FormatHelpers as _;
|
||||
use gpu_allocator::MemoryLocation;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
|
|
@ -133,7 +134,7 @@ pub fn egui_pre_pass(
|
|||
dev.clone(),
|
||||
BufferDesc {
|
||||
name: Some("egui-prepass-staging-buffer".into()),
|
||||
size: (extent.0 * extent.1 * 4) as u64, // RGBA8
|
||||
size: vk::Format::R8G8B8A8_UNORM.layer_size([extent.0, extent.1, 1]),
|
||||
usage: vk::BufferUsageFlags::TRANSFER_SRC,
|
||||
queue_families: device::QueueFlags::empty(),
|
||||
mem_location: MemoryLocation::CpuToGpu,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use crate::{
|
|||
|
||||
use super::Device;
|
||||
use ash::vk::{self, Handle};
|
||||
use ash_formats::FormatExt;
|
||||
use gpu_allocator::vulkan::{AllocationCreateDesc, AllocationScheme};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
|
|
@ -510,8 +511,7 @@ fn validate_image_view_format(image: &ImageDesc, view_format: vk::Format) -> boo
|
|||
let mutable = image.flags.contains(vk::ImageCreateFlags::MUTABLE_FORMAT);
|
||||
|
||||
if mutable {
|
||||
image.format == view_format
|
||||
|| FormatClass::from(image.format) == FormatClass::from(view_format)
|
||||
image.format == view_format || image.format.format_class() == view_format.format_class()
|
||||
} else {
|
||||
image.format == view_format
|
||||
}
|
||||
|
|
@ -957,501 +957,3 @@ pub const SUBRESOURCERANGE_COLOR_ALL: vk::ImageSubresourceRange = vk::ImageSubre
|
|||
base_array_layer: 0,
|
||||
layer_count: vk::REMAINING_ARRAY_LAYERS,
|
||||
};
|
||||
|
||||
// copilot generated from spec:
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum FormatClass {
|
||||
Bits8,
|
||||
Bits16,
|
||||
Alpha8,
|
||||
Bits24,
|
||||
Bits32,
|
||||
Bits48,
|
||||
Bits64,
|
||||
Bits96,
|
||||
Bits128,
|
||||
Bits192,
|
||||
Bits256,
|
||||
|
||||
D16,
|
||||
D24,
|
||||
D32,
|
||||
S8,
|
||||
D16S8,
|
||||
D24S8,
|
||||
D32S8,
|
||||
|
||||
Bc1Rgb,
|
||||
Bc1Rgba,
|
||||
Bc2,
|
||||
Bc3,
|
||||
Bc4,
|
||||
Bc5,
|
||||
Bc6h,
|
||||
Bc7,
|
||||
|
||||
Etc2Rgb,
|
||||
Etc2Rgba,
|
||||
Etc2EacRgba,
|
||||
EacR,
|
||||
EacRg,
|
||||
|
||||
Astc4x4,
|
||||
Astc5x4,
|
||||
Astc5x5,
|
||||
Astc6x5,
|
||||
Astc6x6,
|
||||
Astc8x5,
|
||||
Astc8x6,
|
||||
Astc8x8,
|
||||
Astc10x5,
|
||||
Astc10x6,
|
||||
Astc10x8,
|
||||
Astc10x10,
|
||||
Astc12x10,
|
||||
Astc12x12,
|
||||
|
||||
YuvG8B8G8R8_422,
|
||||
YuvB8G8R8G8_422,
|
||||
|
||||
YuvG8B8R8Triplane420,
|
||||
YuvG8B8R8Biplane420,
|
||||
YuvG8B8R8Triplane422,
|
||||
YuvG8B8R8Biplane422,
|
||||
YuvG8B8R8Triplane444,
|
||||
YuvG10X6B10X6R10X6Triplane420,
|
||||
YuvG10X6B10X6R10X6Biplane420,
|
||||
YuvG10X6B10X6R10X6Triplane422,
|
||||
YuvG10X6B10X6R10X6Biplane422,
|
||||
YuvG10X6B10X6R10X6Triplane444,
|
||||
YuvG12X4B12X4R12X4Triplane420,
|
||||
YuvG12X4B12X4R12X4Biplane420,
|
||||
YuvG12X4B12X4R12X4Triplane422,
|
||||
YuvG12X4B12X4R12X4Biplane422,
|
||||
YuvG12X4B12X4R12X4Triplane444,
|
||||
YuvG16B16R16Triplane420,
|
||||
YuvG16B16R16Biplane420,
|
||||
YuvG16B16R16Triplane422,
|
||||
YuvG16B16R16Biplane422,
|
||||
YuvG16B16R16Triplane444,
|
||||
|
||||
YuvG8B8R8Biplane444,
|
||||
YuvG10X6B10X6R10X6Biplane444,
|
||||
YuvG12X4B12X4R12X4Biplane444,
|
||||
YuvG16B16R16Biplane444,
|
||||
|
||||
Bits64R10G10B10A10,
|
||||
Bits64G10B10G10R10_422,
|
||||
Bits64B10G10R10G10_422,
|
||||
Bits64R12G12B12A12,
|
||||
Bits64G12B12G12R12_422,
|
||||
Bits64B12G12R12G12_422,
|
||||
Bits64G16B16G16R16_422,
|
||||
Bits64B16G16R16G16_422,
|
||||
Bits64R14G14B14A14,
|
||||
|
||||
Pvrtc1_2bpp,
|
||||
Pvrtc1_4bpp,
|
||||
Pvrtc2_2bpp,
|
||||
Pvrtc2_4bpp,
|
||||
|
||||
Astc3x3x3,
|
||||
Astc4x3x3,
|
||||
Astc4x4x3,
|
||||
Astc4x4x4,
|
||||
Astc5x4x4,
|
||||
Astc5x5x4,
|
||||
Astc5x5x5,
|
||||
Astc6x5x5,
|
||||
Astc6x6x5,
|
||||
Astc6x6x6,
|
||||
|
||||
YuvG14X2B14X2R14X2Biplane420,
|
||||
YuvG14X2B14X2R14X2Biplane422,
|
||||
}
|
||||
|
||||
impl From<vk::Format> for FormatClass {
|
||||
fn from(format: vk::Format) -> Self {
|
||||
use vk::Format as F;
|
||||
match format {
|
||||
// 8-bit
|
||||
F::R4G4_UNORM_PACK8
|
||||
| F::R8_UNORM
|
||||
| F::R8_SNORM
|
||||
| F::R8_USCALED
|
||||
| F::R8_SSCALED
|
||||
// | F::R8_BOOL_ARM
|
||||
// | F::R8_SFLOAT_FPENCODING_FLOAT8E4M3_ARM
|
||||
// | F::R8_SFLOAT_FPENCODING_FLOAT8E5M2_ARM
|
||||
| F::R8_UINT
|
||||
| F::R8_SINT
|
||||
| F::R8_SRGB => FormatClass::Bits8,
|
||||
|
||||
// 16-bit
|
||||
F::A1B5G5R5_UNORM_PACK16_KHR
|
||||
| F::R10X6_UNORM_PACK16
|
||||
| F::R12X4_UNORM_PACK16
|
||||
| F::A4R4G4B4_UNORM_PACK16
|
||||
| F::A4B4G4R4_UNORM_PACK16
|
||||
// | F::R10X6_UINT_PACK16_ARM
|
||||
// | F::R12X4_UINT_PACK16_ARM
|
||||
// | F::R14X2_UINT_PACK16_ARM
|
||||
// | F::R14X2_UNORM_PACK16_ARM
|
||||
// | F::R16_SFLOAT_FPENCODING_BFLOAT16_ARM
|
||||
| F::R4G4B4A4_UNORM_PACK16
|
||||
| F::B4G4R4A4_UNORM_PACK16
|
||||
| F::R5G6B5_UNORM_PACK16
|
||||
| F::B5G6R5_UNORM_PACK16
|
||||
| F::R5G5B5A1_UNORM_PACK16
|
||||
| F::B5G5R5A1_UNORM_PACK16
|
||||
| F::A1R5G5B5_UNORM_PACK16
|
||||
| F::R8G8_UNORM
|
||||
| F::R8G8_SNORM
|
||||
| F::R8G8_USCALED
|
||||
| F::R8G8_SSCALED
|
||||
| F::R8G8_UINT
|
||||
| F::R8G8_SINT
|
||||
| F::R8G8_SRGB
|
||||
| F::R16_UNORM
|
||||
| F::R16_SNORM
|
||||
| F::R16_USCALED
|
||||
| F::R16_SSCALED
|
||||
| F::R16_UINT
|
||||
| F::R16_SINT
|
||||
| F::R16_SFLOAT => FormatClass::Bits16,
|
||||
|
||||
// 8-bit alpha
|
||||
F::A8_UNORM_KHR => FormatClass::Alpha8,
|
||||
|
||||
// 24-bit
|
||||
F::R8G8B8_UNORM
|
||||
| F::R8G8B8_SNORM
|
||||
| F::R8G8B8_USCALED
|
||||
| F::R8G8B8_SSCALED
|
||||
| F::R8G8B8_UINT
|
||||
| F::R8G8B8_SINT
|
||||
| F::R8G8B8_SRGB
|
||||
| F::B8G8R8_UNORM
|
||||
| F::B8G8R8_SNORM
|
||||
| F::B8G8R8_USCALED
|
||||
| F::B8G8R8_SSCALED
|
||||
| F::B8G8R8_UINT
|
||||
| F::B8G8R8_SINT
|
||||
| F::B8G8R8_SRGB => FormatClass::Bits24,
|
||||
|
||||
// 32-bit
|
||||
F::R10X6G10X6_UNORM_2PACK16
|
||||
| F::R12X4G12X4_UNORM_2PACK16
|
||||
// | F::R16G16_SFIXED5_NV
|
||||
// | F::R10X6G10X6_UINT_2PACK16_ARM
|
||||
// | F::R12X4G12X4_UINT_2PACK16_ARM
|
||||
// | F::R14X2G14X2_UINT_2PACK16_ARM
|
||||
// | F::R14X2G14X2_UNORM_2PACK16_ARM
|
||||
| F::R8G8B8A8_UNORM
|
||||
| F::R8G8B8A8_SNORM
|
||||
| F::R8G8B8A8_USCALED
|
||||
| F::R8G8B8A8_SSCALED
|
||||
| F::R8G8B8A8_UINT
|
||||
| F::R8G8B8A8_SINT
|
||||
| F::R8G8B8A8_SRGB
|
||||
| F::B8G8R8A8_UNORM
|
||||
| F::B8G8R8A8_SNORM
|
||||
| F::B8G8R8A8_USCALED
|
||||
| F::B8G8R8A8_SSCALED
|
||||
| F::B8G8R8A8_UINT
|
||||
| F::B8G8R8A8_SINT
|
||||
| F::B8G8R8A8_SRGB
|
||||
| F::A8B8G8R8_UNORM_PACK32
|
||||
| F::A8B8G8R8_SNORM_PACK32
|
||||
| F::A8B8G8R8_USCALED_PACK32
|
||||
| F::A8B8G8R8_SSCALED_PACK32
|
||||
| F::A8B8G8R8_UINT_PACK32
|
||||
| F::A8B8G8R8_SINT_PACK32
|
||||
| F::A8B8G8R8_SRGB_PACK32
|
||||
| F::A2R10G10B10_UNORM_PACK32
|
||||
| F::A2R10G10B10_SNORM_PACK32
|
||||
| F::A2R10G10B10_USCALED_PACK32
|
||||
| F::A2R10G10B10_SSCALED_PACK32
|
||||
| F::A2R10G10B10_UINT_PACK32
|
||||
| F::A2R10G10B10_SINT_PACK32
|
||||
| F::A2B10G10R10_UNORM_PACK32
|
||||
| F::A2B10G10R10_SNORM_PACK32
|
||||
| F::A2B10G10R10_USCALED_PACK32
|
||||
| F::A2B10G10R10_SSCALED_PACK32
|
||||
| F::A2B10G10R10_UINT_PACK32
|
||||
| F::A2B10G10R10_SINT_PACK32
|
||||
| F::R16G16_UNORM
|
||||
| F::R16G16_SNORM
|
||||
| F::R16G16_USCALED
|
||||
| F::R16G16_SSCALED
|
||||
| F::R16G16_UINT
|
||||
| F::R16G16_SINT
|
||||
| F::R16G16_SFLOAT
|
||||
| F::R32_UINT
|
||||
| F::R32_SINT
|
||||
| F::R32_SFLOAT
|
||||
| F::B10G11R11_UFLOAT_PACK32
|
||||
| F::E5B9G9R9_UFLOAT_PACK32 => FormatClass::Bits32,
|
||||
|
||||
// 48-bit
|
||||
F::R16G16B16_UNORM
|
||||
| F::R16G16B16_SNORM
|
||||
| F::R16G16B16_USCALED
|
||||
| F::R16G16B16_SSCALED
|
||||
| F::R16G16B16_UINT
|
||||
| F::R16G16B16_SINT
|
||||
| F::R16G16B16_SFLOAT => FormatClass::Bits48,
|
||||
|
||||
// 64-bit
|
||||
F::R16G16B16A16_UNORM
|
||||
| F::R16G16B16A16_SNORM
|
||||
| F::R16G16B16A16_USCALED
|
||||
| F::R16G16B16A16_SSCALED
|
||||
| F::R16G16B16A16_UINT
|
||||
| F::R16G16B16A16_SINT
|
||||
| F::R16G16B16A16_SFLOAT
|
||||
| F::R32G32_UINT
|
||||
| F::R32G32_SINT
|
||||
| F::R32G32_SFLOAT
|
||||
| F::R64_UINT
|
||||
| F::R64_SINT
|
||||
| F::R64_SFLOAT => FormatClass::Bits64,
|
||||
|
||||
// 96-bit
|
||||
F::R32G32B32_UINT | F::R32G32B32_SINT | F::R32G32B32_SFLOAT => FormatClass::Bits96,
|
||||
|
||||
// 128-bit
|
||||
F::R32G32B32A32_UINT
|
||||
| F::R32G32B32A32_SINT
|
||||
| F::R32G32B32A32_SFLOAT
|
||||
| F::R64G64_UINT
|
||||
| F::R64G64_SINT
|
||||
| F::R64G64_SFLOAT => FormatClass::Bits128,
|
||||
|
||||
// 192-bit
|
||||
F::R64G64B64_UINT | F::R64G64B64_SINT | F::R64G64B64_SFLOAT => FormatClass::Bits192,
|
||||
|
||||
// 256-bit
|
||||
F::R64G64B64A64_UINT | F::R64G64B64A64_SINT | F::R64G64B64A64_SFLOAT => {
|
||||
FormatClass::Bits256
|
||||
}
|
||||
|
||||
// Depth / Stencil
|
||||
F::D16_UNORM => FormatClass::D16,
|
||||
F::X8_D24_UNORM_PACK32 => FormatClass::D24,
|
||||
F::D32_SFLOAT => FormatClass::D32,
|
||||
F::S8_UINT => FormatClass::S8,
|
||||
F::D16_UNORM_S8_UINT => FormatClass::D16S8,
|
||||
F::D24_UNORM_S8_UINT => FormatClass::D24S8,
|
||||
F::D32_SFLOAT_S8_UINT => FormatClass::D32S8,
|
||||
|
||||
// BCn
|
||||
F::BC1_RGB_UNORM_BLOCK | F::BC1_RGB_SRGB_BLOCK => FormatClass::Bc1Rgb,
|
||||
F::BC1_RGBA_UNORM_BLOCK | F::BC1_RGBA_SRGB_BLOCK => FormatClass::Bc1Rgba,
|
||||
F::BC2_UNORM_BLOCK | F::BC2_SRGB_BLOCK => FormatClass::Bc2,
|
||||
F::BC3_UNORM_BLOCK | F::BC3_SRGB_BLOCK => FormatClass::Bc3,
|
||||
F::BC4_UNORM_BLOCK | F::BC4_SNORM_BLOCK => FormatClass::Bc4,
|
||||
F::BC5_UNORM_BLOCK | F::BC5_SNORM_BLOCK => FormatClass::Bc5,
|
||||
F::BC6H_UFLOAT_BLOCK | F::BC6H_SFLOAT_BLOCK => FormatClass::Bc6h,
|
||||
F::BC7_UNORM_BLOCK | F::BC7_SRGB_BLOCK => FormatClass::Bc7,
|
||||
|
||||
// ETC2 / EAC
|
||||
F::ETC2_R8G8B8_UNORM_BLOCK | F::ETC2_R8G8B8_SRGB_BLOCK => FormatClass::Etc2Rgb,
|
||||
F::ETC2_R8G8B8A1_UNORM_BLOCK | F::ETC2_R8G8B8A1_SRGB_BLOCK => FormatClass::Etc2Rgba,
|
||||
F::ETC2_R8G8B8A8_UNORM_BLOCK | F::ETC2_R8G8B8A8_SRGB_BLOCK => FormatClass::Etc2EacRgba,
|
||||
F::EAC_R11_UNORM_BLOCK | F::EAC_R11_SNORM_BLOCK => FormatClass::EacR,
|
||||
F::EAC_R11G11_UNORM_BLOCK | F::EAC_R11G11_SNORM_BLOCK => FormatClass::EacRg,
|
||||
|
||||
// ASTC 2D
|
||||
F::ASTC_4X4_SFLOAT_BLOCK | F::ASTC_4X4_UNORM_BLOCK | F::ASTC_4X4_SRGB_BLOCK => {
|
||||
FormatClass::Astc4x4
|
||||
}
|
||||
F::ASTC_5X4_SFLOAT_BLOCK | F::ASTC_5X4_UNORM_BLOCK | F::ASTC_5X4_SRGB_BLOCK => {
|
||||
FormatClass::Astc5x4
|
||||
}
|
||||
F::ASTC_5X5_SFLOAT_BLOCK | F::ASTC_5X5_UNORM_BLOCK | F::ASTC_5X5_SRGB_BLOCK => {
|
||||
FormatClass::Astc5x5
|
||||
}
|
||||
F::ASTC_6X5_SFLOAT_BLOCK | F::ASTC_6X5_UNORM_BLOCK | F::ASTC_6X5_SRGB_BLOCK => {
|
||||
FormatClass::Astc6x5
|
||||
}
|
||||
F::ASTC_6X6_SFLOAT_BLOCK | F::ASTC_6X6_UNORM_BLOCK | F::ASTC_6X6_SRGB_BLOCK => {
|
||||
FormatClass::Astc6x6
|
||||
}
|
||||
F::ASTC_8X5_SFLOAT_BLOCK | F::ASTC_8X5_UNORM_BLOCK | F::ASTC_8X5_SRGB_BLOCK => {
|
||||
FormatClass::Astc8x5
|
||||
}
|
||||
F::ASTC_8X6_SFLOAT_BLOCK | F::ASTC_8X6_UNORM_BLOCK | F::ASTC_8X6_SRGB_BLOCK => {
|
||||
FormatClass::Astc8x6
|
||||
}
|
||||
F::ASTC_8X8_SFLOAT_BLOCK | F::ASTC_8X8_UNORM_BLOCK | F::ASTC_8X8_SRGB_BLOCK => {
|
||||
FormatClass::Astc8x8
|
||||
}
|
||||
F::ASTC_10X5_SFLOAT_BLOCK | F::ASTC_10X5_UNORM_BLOCK | F::ASTC_10X5_SRGB_BLOCK => {
|
||||
FormatClass::Astc10x5
|
||||
}
|
||||
F::ASTC_10X6_SFLOAT_BLOCK | F::ASTC_10X6_UNORM_BLOCK | F::ASTC_10X6_SRGB_BLOCK => {
|
||||
FormatClass::Astc10x6
|
||||
}
|
||||
F::ASTC_10X8_SFLOAT_BLOCK | F::ASTC_10X8_UNORM_BLOCK | F::ASTC_10X8_SRGB_BLOCK => {
|
||||
FormatClass::Astc10x8
|
||||
}
|
||||
F::ASTC_10X10_SFLOAT_BLOCK | F::ASTC_10X10_UNORM_BLOCK | F::ASTC_10X10_SRGB_BLOCK => {
|
||||
FormatClass::Astc10x10
|
||||
}
|
||||
F::ASTC_12X10_SFLOAT_BLOCK | F::ASTC_12X10_UNORM_BLOCK | F::ASTC_12X10_SRGB_BLOCK => {
|
||||
FormatClass::Astc12x10
|
||||
}
|
||||
F::ASTC_12X12_SFLOAT_BLOCK | F::ASTC_12X12_UNORM_BLOCK | F::ASTC_12X12_SRGB_BLOCK => {
|
||||
FormatClass::Astc12x12
|
||||
}
|
||||
|
||||
// Packed/YCbCr-ish (as listed)
|
||||
F::G8B8G8R8_422_UNORM => FormatClass::YuvG8B8G8R8_422,
|
||||
F::B8G8R8G8_422_UNORM => FormatClass::YuvB8G8R8G8_422,
|
||||
|
||||
F::G8_B8_R8_3PLANE_420_UNORM => FormatClass::YuvG8B8R8Triplane420,
|
||||
F::G8_B8R8_2PLANE_420_UNORM => FormatClass::YuvG8B8R8Biplane420,
|
||||
F::G8_B8_R8_3PLANE_422_UNORM => FormatClass::YuvG8B8R8Triplane422,
|
||||
F::G8_B8R8_2PLANE_422_UNORM => FormatClass::YuvG8B8R8Biplane422,
|
||||
F::G8_B8_R8_3PLANE_444_UNORM => FormatClass::YuvG8B8R8Triplane444,
|
||||
|
||||
F::G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG10X6B10X6R10X6Triplane420
|
||||
}
|
||||
F::G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG10X6B10X6R10X6Biplane420
|
||||
}
|
||||
F::G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG10X6B10X6R10X6Triplane422
|
||||
}
|
||||
F::G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG10X6B10X6R10X6Biplane422
|
||||
}
|
||||
F::G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG10X6B10X6R10X6Triplane444
|
||||
}
|
||||
|
||||
F::G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG12X4B12X4R12X4Triplane420
|
||||
}
|
||||
F::G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG12X4B12X4R12X4Biplane420
|
||||
}
|
||||
F::G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG12X4B12X4R12X4Triplane422
|
||||
}
|
||||
F::G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG12X4B12X4R12X4Biplane422
|
||||
}
|
||||
F::G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG12X4B12X4R12X4Triplane444
|
||||
}
|
||||
|
||||
F::G16_B16_R16_3PLANE_420_UNORM => FormatClass::YuvG16B16R16Triplane420,
|
||||
F::G16_B16R16_2PLANE_420_UNORM => FormatClass::YuvG16B16R16Biplane420,
|
||||
F::G16_B16_R16_3PLANE_422_UNORM => FormatClass::YuvG16B16R16Triplane422,
|
||||
F::G16_B16R16_2PLANE_422_UNORM => FormatClass::YuvG16B16R16Biplane422,
|
||||
F::G16_B16_R16_3PLANE_444_UNORM => FormatClass::YuvG16B16R16Triplane444,
|
||||
|
||||
// 2-plane 444 (additional section)
|
||||
F::G8_B8R8_2PLANE_444_UNORM => FormatClass::YuvG8B8R8Biplane444,
|
||||
F::G10X6_B10X6R10X6_2PLANE_444_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG10X6B10X6R10X6Biplane444
|
||||
}
|
||||
F::G12X4_B12X4R12X4_2PLANE_444_UNORM_3PACK16 => {
|
||||
FormatClass::YuvG12X4B12X4R12X4Biplane444
|
||||
}
|
||||
F::G16_B16R16_2PLANE_444_UNORM => FormatClass::YuvG16B16R16Biplane444,
|
||||
|
||||
// 64-bit special grouped headings from the markdown
|
||||
F::R10X6G10X6B10X6A10X6_UNORM_4PACK16 /* | F::R10X6G10X6B10X6A10X6_UINT_4PACK16_ARM */
|
||||
=> {
|
||||
FormatClass::Bits64R10G10B10A10
|
||||
}
|
||||
F::G10X6B10X6G10X6R10X6_422_UNORM_4PACK16 => FormatClass::Bits64G10B10G10R10_422,
|
||||
F::B10X6G10X6R10X6G10X6_422_UNORM_4PACK16 => FormatClass::Bits64B10G10R10G10_422,
|
||||
F::R12X4G12X4B12X4A12X4_UNORM_4PACK16 /*| F::R12X4G12X4B12X4A12X4_UINT_4PACK16_ARM */
|
||||
=> {
|
||||
FormatClass::Bits64R12G12B12A12
|
||||
}
|
||||
F::G12X4B12X4G12X4R12X4_422_UNORM_4PACK16 => FormatClass::Bits64G12B12G12R12_422,
|
||||
F::B12X4G12X4R12X4G12X4_422_UNORM_4PACK16 => FormatClass::Bits64B12G12R12G12_422,
|
||||
F::G16B16G16R16_422_UNORM => FormatClass::Bits64G16B16G16R16_422,
|
||||
F::B16G16R16G16_422_UNORM => FormatClass::Bits64B16G16R16G16_422,
|
||||
|
||||
// F::R14X2G14X2B14X2A14X2_UINT_4PACK16_ARM
|
||||
// | F::R14X2G14X2B14X2A14X2_UNORM_4PACK16_ARM => FormatClass::Bits64_R14G14B14A14,
|
||||
|
||||
// PVRTC
|
||||
F::PVRTC1_2BPP_UNORM_BLOCK_IMG | F::PVRTC1_2BPP_SRGB_BLOCK_IMG => {
|
||||
FormatClass::Pvrtc1_2bpp
|
||||
}
|
||||
F::PVRTC1_4BPP_UNORM_BLOCK_IMG | F::PVRTC1_4BPP_SRGB_BLOCK_IMG => {
|
||||
FormatClass::Pvrtc1_4bpp
|
||||
}
|
||||
F::PVRTC2_2BPP_UNORM_BLOCK_IMG | F::PVRTC2_2BPP_SRGB_BLOCK_IMG => {
|
||||
FormatClass::Pvrtc2_2bpp
|
||||
}
|
||||
F::PVRTC2_4BPP_UNORM_BLOCK_IMG | F::PVRTC2_4BPP_SRGB_BLOCK_IMG => {
|
||||
FormatClass::Pvrtc2_4bpp
|
||||
}
|
||||
|
||||
// ASTC 3D (EXT)
|
||||
// F::ASTC_3X3X3_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_3X3X3_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_3X3X3_SFLOAT_BLOCK_EXT => FormatClass::Astc3x3x3,
|
||||
// F::ASTC_4X3X3_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_4X3X3_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_4X3X3_SFLOAT_BLOCK_EXT => FormatClass::Astc4x3x3,
|
||||
// F::ASTC_4X4X3_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_4X4X3_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_4X4X3_SFLOAT_BLOCK_EXT => FormatClass::Astc4x4x3,
|
||||
// F::ASTC_4X4X4_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_4X4X4_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_4X4X4_SFLOAT_BLOCK_EXT => FormatClass::Astc4x4x4,
|
||||
// F::ASTC_5X4X4_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_5X4X4_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_5X4X4_SFLOAT_BLOCK_EXT => FormatClass::Astc5x4x4,
|
||||
// F::ASTC_5X5X4_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_5X5X4_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_5X5X4_SFLOAT_BLOCK_EXT => FormatClass::Astc5x5x4,
|
||||
// F::ASTC_5X5X5_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_5X5X5_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_5X5X5_SFLOAT_BLOCK_EXT => FormatClass::Astc5x5x5,
|
||||
// F::ASTC_6X5X5_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_6X5X5_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_6X5X5_SFLOAT_BLOCK_EXT => FormatClass::Astc6x5x5,
|
||||
// F::ASTC_6X6X5_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_6X6X5_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_6X6X5_SFLOAT_BLOCK_EXT => FormatClass::Astc6x6x5,
|
||||
// F::ASTC_6X6X6_UNORM_BLOCK_EXT
|
||||
// | F::ASTC_6X6X6_SRGB_BLOCK_EXT
|
||||
// | F::ASTC_6X6X6_SFLOAT_BLOCK_EXT => FormatClass::Astc6x6x6,
|
||||
|
||||
// // 14-bit 2-plane
|
||||
// F::G14X2_B14X2R14X2_2PLANE_420_UNORM_3PACK16_ARM => {
|
||||
// FormatClass::YuvG14X2_B14X2R14X2_2Plane_420
|
||||
// }
|
||||
// F::G14X2_B14X2R14X2_2PLANE_422_UNORM_3PACK16_ARM => {
|
||||
// FormatClass::YuvG14X2_B14X2R14X2_2Plane_422
|
||||
// }
|
||||
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn format_to_aspect_mask(format: vk::Format) -> vk::ImageAspectFlags {
|
||||
use vk::Format as F;
|
||||
match format {
|
||||
F::D16_UNORM | F::X8_D24_UNORM_PACK32 | F::D32_SFLOAT => vk::ImageAspectFlags::DEPTH,
|
||||
F::D16_UNORM_S8_UINT | F::D24_UNORM_S8_UINT | F::D32_SFLOAT_S8_UINT => {
|
||||
vk::ImageAspectFlags::DEPTH | vk::ImageAspectFlags::STENCIL
|
||||
}
|
||||
F::S8_UINT => vk::ImageAspectFlags::STENCIL,
|
||||
_ => vk::ImageAspectFlags::COLOR,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
map_try_insert,
|
||||
core_io,
|
||||
core_io_borrowed_buf,
|
||||
debug_closure_helpers,
|
||||
slice_partition_dedup
|
||||
)]
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use crate::{
|
|||
util::{self, Rgba, WithLifetime},
|
||||
};
|
||||
use ash::vk;
|
||||
use ash_formats::FormatExt;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[repr(transparent)]
|
||||
|
|
@ -1267,7 +1268,7 @@ pub fn image_barrier(
|
|||
.old_layout(before_access.layout)
|
||||
.new_layout(after_access.layout)
|
||||
.subresource_range(vk::ImageSubresourceRange {
|
||||
aspect_mask: util::image_aspect_from_format(format),
|
||||
aspect_mask: format.aspect_flags(),
|
||||
..images::SUBRESOURCERANGE_ALL
|
||||
})
|
||||
.src_queue_family_index(
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ use std::{
|
|||
sync::{Arc, Weak},
|
||||
};
|
||||
|
||||
use ash::vk::Extent2D;
|
||||
use ash::vk::{self, Extent2D};
|
||||
use ash_formats::FormatHelpers as _;
|
||||
use cosmic_text::{CacheKey, FontSystem, PhysicalGlyph, SwashCache};
|
||||
use glam::IVec2;
|
||||
use guillotiere::size2;
|
||||
|
|
@ -189,7 +190,7 @@ impl std::fmt::Debug for FontAtlas {
|
|||
|
||||
impl FontAtlas {
|
||||
fn new(size: u32) -> Self {
|
||||
let num_bytes = size * size * 4;
|
||||
let num_bytes = vk::Format::R8G8B8A8_UNORM.layer_size([size, size, 1]);
|
||||
Self {
|
||||
image: Arc::new(Image(parking_lot::RwLock::new(ImageInner {
|
||||
image: vec![0; num_bytes as usize],
|
||||
|
|
@ -234,7 +235,7 @@ impl FontAtlas {
|
|||
let y = y + line_y;
|
||||
let image_offset = 4 * y as u32 * image.width() + 4 * x as u32;
|
||||
let glyph_offset = 4 * line_y * width;
|
||||
let len = 4 * width as usize;
|
||||
let len = vk::Format::R8G8B8A8_UNORM.row_pitch(width as u32) as usize;
|
||||
let dst = &mut image.bytes_mut()[image_offset as usize..][..len];
|
||||
let src = &data[glyph_offset as usize..][..len];
|
||||
dst.copy_from_slice(src);
|
||||
|
|
|
|||
|
|
@ -199,229 +199,6 @@ impl<'a, T: 'a> MutexExt<'a, T> for parking_lot::Mutex<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait FormatExt {
|
||||
fn get_component_kind(&self) -> FormatComponentKind;
|
||||
fn is_f32(&self) -> bool;
|
||||
fn is_u32(&self) -> bool;
|
||||
fn is_i32(&self) -> bool;
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum FormatComponentKind {
|
||||
Float,
|
||||
UInt,
|
||||
SInt,
|
||||
}
|
||||
|
||||
fn format_to_primitive(format: vk::Format) -> FormatComponentKind {
|
||||
use FormatComponentKind::*;
|
||||
match format {
|
||||
vk::Format::BC6H_SFLOAT_BLOCK => Float,
|
||||
vk::Format::D32_SFLOAT => Float,
|
||||
vk::Format::R16G16B16A16_SFLOAT => Float,
|
||||
vk::Format::R16G16B16_SFLOAT => Float,
|
||||
vk::Format::R16G16_SFLOAT => Float,
|
||||
vk::Format::R16_SFLOAT => Float,
|
||||
vk::Format::R32G32B32A32_SFLOAT => Float,
|
||||
vk::Format::R32G32B32_SFLOAT => Float,
|
||||
vk::Format::R32G32_SFLOAT => Float,
|
||||
vk::Format::R32_SFLOAT => Float,
|
||||
vk::Format::R64G64B64A64_SFLOAT => Float,
|
||||
vk::Format::R64G64B64_SFLOAT => Float,
|
||||
vk::Format::R64G64_SFLOAT => Float,
|
||||
vk::Format::R64_SFLOAT => Float,
|
||||
vk::Format::D32_SFLOAT_S8_UINT => Float,
|
||||
vk::Format::A2B10G10R10_SINT_PACK32 => SInt,
|
||||
vk::Format::A2R10G10B10_SINT_PACK32 => SInt,
|
||||
vk::Format::A8B8G8R8_SINT_PACK32 => SInt,
|
||||
vk::Format::B8G8R8A8_SINT => SInt,
|
||||
vk::Format::B8G8R8_SINT => SInt,
|
||||
vk::Format::R16G16B16A16_SINT => SInt,
|
||||
vk::Format::R16G16B16_SINT => SInt,
|
||||
vk::Format::R16G16_SINT => SInt,
|
||||
vk::Format::R16_SINT => SInt,
|
||||
vk::Format::R32G32B32A32_SINT => SInt,
|
||||
vk::Format::R32G32B32_SINT => SInt,
|
||||
vk::Format::R32G32_SINT => SInt,
|
||||
vk::Format::R32_SINT => SInt,
|
||||
vk::Format::R64G64B64A64_SINT => SInt,
|
||||
vk::Format::R64G64B64_SINT => SInt,
|
||||
vk::Format::R64G64_SINT => SInt,
|
||||
vk::Format::R64_SINT => SInt,
|
||||
vk::Format::R8G8B8A8_SINT => SInt,
|
||||
vk::Format::R8G8B8_SINT => SInt,
|
||||
vk::Format::R8G8_SINT => SInt,
|
||||
vk::Format::R8_SINT => SInt,
|
||||
vk::Format::A2B10G10R10_SNORM_PACK32 => Float,
|
||||
vk::Format::A2R10G10B10_SNORM_PACK32 => Float,
|
||||
vk::Format::A8B8G8R8_SNORM_PACK32 => Float,
|
||||
vk::Format::B8G8R8A8_SNORM => Float,
|
||||
vk::Format::B8G8R8_SNORM => Float,
|
||||
vk::Format::BC4_SNORM_BLOCK => Float,
|
||||
vk::Format::BC5_SNORM_BLOCK => Float,
|
||||
vk::Format::EAC_R11G11_SNORM_BLOCK => Float,
|
||||
vk::Format::EAC_R11_SNORM_BLOCK => Float,
|
||||
vk::Format::R16G16B16A16_SNORM => Float,
|
||||
vk::Format::R16G16B16_SNORM => Float,
|
||||
vk::Format::R16G16_SNORM => Float,
|
||||
vk::Format::R16_SNORM => Float,
|
||||
vk::Format::R8G8B8A8_SNORM => Float,
|
||||
vk::Format::R8G8B8_SNORM => Float,
|
||||
vk::Format::R8G8_SNORM => Float,
|
||||
vk::Format::R8_SNORM => Float,
|
||||
vk::Format::A8B8G8R8_SRGB_PACK32 => Float,
|
||||
vk::Format::ASTC_10X10_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_10X5_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_10X6_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_10X8_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_12X10_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_12X12_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_4X4_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_5X4_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_5X5_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_6X5_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_6X6_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_8X5_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_8X6_SRGB_BLOCK => Float,
|
||||
vk::Format::ASTC_8X8_SRGB_BLOCK => Float,
|
||||
vk::Format::B8G8R8A8_SRGB => Float,
|
||||
vk::Format::B8G8R8_SRGB => Float,
|
||||
vk::Format::BC1_RGBA_SRGB_BLOCK => Float,
|
||||
vk::Format::BC1_RGB_SRGB_BLOCK => Float,
|
||||
vk::Format::BC2_SRGB_BLOCK => Float,
|
||||
vk::Format::BC3_SRGB_BLOCK => Float,
|
||||
vk::Format::BC7_SRGB_BLOCK => Float,
|
||||
vk::Format::ETC2_R8G8B8A1_SRGB_BLOCK => Float,
|
||||
vk::Format::ETC2_R8G8B8A8_SRGB_BLOCK => Float,
|
||||
vk::Format::ETC2_R8G8B8_SRGB_BLOCK => Float,
|
||||
vk::Format::R8G8B8A8_SRGB => Float,
|
||||
vk::Format::R8G8B8_SRGB => Float,
|
||||
vk::Format::R8G8_SRGB => Float,
|
||||
vk::Format::R8_SRGB => Float,
|
||||
vk::Format::A2B10G10R10_SSCALED_PACK32 => Float,
|
||||
vk::Format::A2R10G10B10_SSCALED_PACK32 => Float,
|
||||
vk::Format::A8B8G8R8_SSCALED_PACK32 => Float,
|
||||
vk::Format::B8G8R8A8_SSCALED => Float,
|
||||
vk::Format::B8G8R8_SSCALED => Float,
|
||||
vk::Format::R16G16B16A16_SSCALED => Float,
|
||||
vk::Format::R16G16B16_SSCALED => Float,
|
||||
vk::Format::R16G16_SSCALED => Float,
|
||||
vk::Format::R16_SSCALED => Float,
|
||||
vk::Format::R8G8B8A8_SSCALED => Float,
|
||||
vk::Format::R8G8B8_SSCALED => Float,
|
||||
vk::Format::R8G8_SSCALED => Float,
|
||||
vk::Format::R8_SSCALED => Float,
|
||||
vk::Format::B10G11R11_UFLOAT_PACK32 => Float,
|
||||
vk::Format::BC6H_UFLOAT_BLOCK => Float,
|
||||
vk::Format::E5B9G9R9_UFLOAT_PACK32 => Float,
|
||||
vk::Format::A2B10G10R10_UINT_PACK32 => UInt,
|
||||
vk::Format::A2R10G10B10_UINT_PACK32 => UInt,
|
||||
vk::Format::A8B8G8R8_UINT_PACK32 => UInt,
|
||||
vk::Format::B8G8R8A8_UINT => UInt,
|
||||
vk::Format::B8G8R8_UINT => UInt,
|
||||
vk::Format::R16G16B16A16_UINT => UInt,
|
||||
vk::Format::R16G16B16_UINT => UInt,
|
||||
vk::Format::R16G16_UINT => UInt,
|
||||
vk::Format::R16_UINT => UInt,
|
||||
vk::Format::R32G32B32A32_UINT => UInt,
|
||||
vk::Format::R32G32B32_UINT => UInt,
|
||||
vk::Format::R32G32_UINT => UInt,
|
||||
vk::Format::R32_UINT => UInt,
|
||||
vk::Format::R64G64B64A64_UINT => UInt,
|
||||
vk::Format::R64G64B64_UINT => UInt,
|
||||
vk::Format::R64G64_UINT => UInt,
|
||||
vk::Format::R64_UINT => UInt,
|
||||
vk::Format::R8G8B8A8_UINT => UInt,
|
||||
vk::Format::R8G8B8_UINT => UInt,
|
||||
vk::Format::R8G8_UINT => UInt,
|
||||
vk::Format::R8_UINT => UInt,
|
||||
vk::Format::S8_UINT => UInt,
|
||||
vk::Format::A1R5G5B5_UNORM_PACK16 => Float,
|
||||
vk::Format::A2B10G10R10_UNORM_PACK32 => Float,
|
||||
vk::Format::A2R10G10B10_UNORM_PACK32 => Float,
|
||||
vk::Format::A8B8G8R8_UNORM_PACK32 => Float,
|
||||
vk::Format::ASTC_10X10_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_10X5_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_10X6_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_10X8_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_12X10_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_12X12_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_4X4_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_5X4_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_5X5_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_6X5_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_6X6_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_8X5_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_8X6_UNORM_BLOCK => Float,
|
||||
vk::Format::ASTC_8X8_UNORM_BLOCK => Float,
|
||||
vk::Format::B4G4R4A4_UNORM_PACK16 => Float,
|
||||
vk::Format::B5G5R5A1_UNORM_PACK16 => Float,
|
||||
vk::Format::B5G6R5_UNORM_PACK16 => Float,
|
||||
vk::Format::B8G8R8A8_UNORM => Float,
|
||||
vk::Format::B8G8R8_UNORM => Float,
|
||||
vk::Format::BC1_RGBA_UNORM_BLOCK => Float,
|
||||
vk::Format::BC1_RGB_UNORM_BLOCK => Float,
|
||||
vk::Format::BC2_UNORM_BLOCK => Float,
|
||||
vk::Format::BC3_UNORM_BLOCK => Float,
|
||||
vk::Format::BC4_UNORM_BLOCK => Float,
|
||||
vk::Format::BC5_UNORM_BLOCK => Float,
|
||||
vk::Format::BC7_UNORM_BLOCK => Float,
|
||||
vk::Format::D16_UNORM => Float,
|
||||
vk::Format::D16_UNORM_S8_UINT => Float,
|
||||
vk::Format::D24_UNORM_S8_UINT => Float,
|
||||
vk::Format::EAC_R11G11_UNORM_BLOCK => Float,
|
||||
vk::Format::EAC_R11_UNORM_BLOCK => Float,
|
||||
vk::Format::ETC2_R8G8B8A1_UNORM_BLOCK => Float,
|
||||
vk::Format::ETC2_R8G8B8A8_UNORM_BLOCK => Float,
|
||||
vk::Format::ETC2_R8G8B8_UNORM_BLOCK => Float,
|
||||
vk::Format::R16G16B16A16_UNORM => Float,
|
||||
vk::Format::R16G16B16_UNORM => Float,
|
||||
vk::Format::R16G16_UNORM => Float,
|
||||
vk::Format::R16_UNORM => Float,
|
||||
vk::Format::R4G4B4A4_UNORM_PACK16 => Float,
|
||||
vk::Format::R4G4_UNORM_PACK8 => Float,
|
||||
vk::Format::R5G5B5A1_UNORM_PACK16 => Float,
|
||||
vk::Format::R5G6B5_UNORM_PACK16 => Float,
|
||||
vk::Format::R8G8B8A8_UNORM => Float,
|
||||
vk::Format::R8G8B8_UNORM => Float,
|
||||
vk::Format::R8G8_UNORM => Float,
|
||||
vk::Format::R8_UNORM => Float,
|
||||
vk::Format::X8_D24_UNORM_PACK32 => Float,
|
||||
vk::Format::A2B10G10R10_USCALED_PACK32 => Float,
|
||||
vk::Format::A2R10G10B10_USCALED_PACK32 => Float,
|
||||
vk::Format::A8B8G8R8_USCALED_PACK32 => Float,
|
||||
vk::Format::B8G8R8A8_USCALED => Float,
|
||||
vk::Format::B8G8R8_USCALED => Float,
|
||||
vk::Format::R16G16B16A16_USCALED => Float,
|
||||
vk::Format::R16G16B16_USCALED => Float,
|
||||
vk::Format::R16G16_USCALED => Float,
|
||||
vk::Format::R16_USCALED => Float,
|
||||
vk::Format::R8G8B8A8_USCALED => Float,
|
||||
vk::Format::R8G8B8_USCALED => Float,
|
||||
vk::Format::R8G8_USCALED => Float,
|
||||
vk::Format::R8_USCALED => Float,
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
impl FormatExt for vk::Format {
|
||||
fn get_component_kind(&self) -> FormatComponentKind {
|
||||
format_to_primitive(*self)
|
||||
}
|
||||
fn is_f32(&self) -> bool {
|
||||
format_to_primitive(*self) == FormatComponentKind::Float
|
||||
}
|
||||
|
||||
fn is_u32(&self) -> bool {
|
||||
format_to_primitive(*self) == FormatComponentKind::UInt
|
||||
}
|
||||
|
||||
fn is_i32(&self) -> bool {
|
||||
format_to_primitive(*self) == FormatComponentKind::SInt
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub struct Rect2D {
|
||||
top_left: glam::IVec2,
|
||||
|
|
@ -618,21 +395,6 @@ impl Rgba {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn image_aspect_from_format(format: vk::Format) -> vk::ImageAspectFlags {
|
||||
use vk::{Format, ImageAspectFlags};
|
||||
match format {
|
||||
Format::D32_SFLOAT | Format::X8_D24_UNORM_PACK32 | Format::D16_UNORM => {
|
||||
ImageAspectFlags::DEPTH
|
||||
}
|
||||
Format::S8_UINT => ImageAspectFlags::STENCIL,
|
||||
Format::D32_SFLOAT_S8_UINT | Format::D16_UNORM_S8_UINT | Format::D24_UNORM_S8_UINT => {
|
||||
ImageAspectFlags::DEPTH | ImageAspectFlags::STENCIL
|
||||
}
|
||||
_ => ImageAspectFlags::COLOR,
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct WithLifetime<'a, T>(T, std::marker::PhantomData<&'a ()>);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ash-formats = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
|
@ -26,4 +27,4 @@ renderer = {path = "../renderer"}
|
|||
|
||||
[dev-dependencies]
|
||||
tracing-test = "0.2.5"
|
||||
image = "0.25.5"
|
||||
image = "0.25.5"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![feature(debug_closure_helpers)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use ash_formats::FormatHelpers as _;
|
||||
use bevy_asset::{Asset, AssetLoader};
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_reflect::TypePath;
|
||||
|
|
@ -241,7 +242,7 @@ impl std::fmt::Debug for FontAtlas {
|
|||
|
||||
impl FontAtlas {
|
||||
fn new(size: u32) -> Self {
|
||||
let num_bytes = size * size * 4;
|
||||
let num_bytes = renderer::ash::vk::Format::R8G8B8A8_UNORM.layer_size([size, size, 1]);
|
||||
Self {
|
||||
image: Arc::new(Image(parking_lot::RwLock::new(ImageInner {
|
||||
image: vec![0; num_bytes as usize],
|
||||
|
|
@ -289,7 +290,7 @@ impl FontAtlas {
|
|||
let y = y + line_y;
|
||||
let image_offset = 4 * y as u32 * image.width() + 4 * x as u32;
|
||||
let glyph_offset = 4 * line_y * width;
|
||||
let len = 4 * width as usize;
|
||||
let len = renderer::ash::vk::Format::R8G8B8A8_UNORM.row_pitch(width as u32) as usize;
|
||||
let dst = &mut image.bytes_mut()[image_offset as usize..][..len];
|
||||
let src = &data[glyph_offset as usize..][..len];
|
||||
dst.copy_from_slice(src);
|
||||
|
|
|
|||
Loading…
Reference in a new issue