Compare commits
No commits in common. "00c67d5bdf2a203916c1ed82fc213f83524f146a" and "29dbdf9f94bc959740a04b7b334ef245ad055844" have entirely different histories.
00c67d5bdf
...
29dbdf9f94
|
|
@ -1,9 +0,0 @@
|
|||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "clang"
|
||||
rustflags = [
|
||||
"-Clink-arg=-fuse-ld=mold",
|
||||
|
||||
# Nightly
|
||||
"-Zshare-generics=y",
|
||||
"-Zthreads=0",
|
||||
]
|
||||
35
Cargo.toml
35
Cargo.toml
|
|
@ -3,9 +3,6 @@ name = "vidya"
|
|||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[patch.crates-io]
|
||||
bevy = {path = "../bevy"}
|
||||
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
|
||||
|
|
@ -71,22 +68,22 @@ raw-window-handle = "0.6"
|
|||
egui = "0.32"
|
||||
egui_winit_platform = "0.27"
|
||||
|
||||
bevy = { version = "0.20.0-dev" }
|
||||
bevy_app = { version = "0.20.0-dev" }
|
||||
bevy_asset = { version = "0.20.0-dev" }
|
||||
bevy_derive = { version = "0.20.0-dev" }
|
||||
bevy_ecs = { version = "0.20.0-dev" }
|
||||
bevy_hierarchy = { version = "0.20.0-dev" }
|
||||
bevy_log = { version = "0.20.0-dev" }
|
||||
bevy_math = { version = "0.20.0-dev" }
|
||||
bevy_platform = { version = "0.20.0-dev" }
|
||||
bevy_reflect = { version = "0.20.0-dev" }
|
||||
bevy_tasks = { version = "0.20.0-dev" }
|
||||
bevy_time = { version = "0.20.0-dev" }
|
||||
bevy_transform = { version = "0.20.0-dev" }
|
||||
bevy_utils = { version = "0.20.0-dev" }
|
||||
bevy_window = { version = "0.20.0-dev" }
|
||||
bevy_winit = { version = "0.20.0-dev" }
|
||||
bevy = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_app = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_asset = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_derive = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_ecs = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy", features = ["multi_threaded", "trace"]}
|
||||
bevy_hierarchy = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_log = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_math = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_platform = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_reflect = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_tasks = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_time = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_transform = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_utils = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_window = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
bevy_winit = { version = "0.19.0-dev", git = "https://github.com/bevyengine/bevy" }
|
||||
|
||||
[[example]]
|
||||
name = "bevy_integration"
|
||||
|
|
|
|||
|
|
@ -49,8 +49,6 @@ cosmic-text = "0.12.1"
|
|||
sys-locale = "0.3.2"
|
||||
guillotiere = "0.6.2"
|
||||
|
||||
ash-formats = { git = "https://github.com/janis-bhm/ash-formats", branch = "main" }
|
||||
|
||||
[dev-dependencies]
|
||||
tracing-test = "0.2.5"
|
||||
image = "0.25.5"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use crate::{
|
|||
|
||||
use super::Device;
|
||||
use ash::vk::{self, Handle};
|
||||
use ash_formats::FormatExt;
|
||||
use gpu_allocator::vulkan::{AllocationCreateDesc, AllocationScheme};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
|
|
@ -515,7 +514,8 @@ 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 || image.format.format_class() == view_format.format_class()
|
||||
image.format == view_format
|
||||
|| FormatClass::from(image.format) == FormatClass::from(view_format)
|
||||
} else {
|
||||
image.format == view_format
|
||||
}
|
||||
|
|
@ -1045,3 +1045,583 @@ 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 FormatClass {
|
||||
pub fn block_size(self) -> u32 {
|
||||
use FormatClass::*;
|
||||
|
||||
match self {
|
||||
S8 | Bits8 | Alpha8 => 1,
|
||||
D16 | Bits16 => 2,
|
||||
Bits24 | D24 | D16S8 => 3,
|
||||
Bits32 | D24S8 => 4,
|
||||
D32S8 => 5,
|
||||
Bits48 => 6,
|
||||
Bits64 | D32 => 8,
|
||||
Bits96 => 12,
|
||||
Bits128 => 16,
|
||||
Bits192 => 24,
|
||||
Bits256 => 32,
|
||||
|
||||
Bc1Rgb | Bc1Rgba => 8,
|
||||
Bc2 | Bc3 | Bc6h | Bc7 => 16,
|
||||
Bc4 => 8,
|
||||
Bc5 => 16,
|
||||
|
||||
Etc2Rgb | Etc2Rgba | EacR => 8,
|
||||
Etc2EacRgba | EacRg => 16,
|
||||
|
||||
Astc4x4 | Astc5x4 | Astc5x5 | Astc6x5 | Astc6x6 | Astc8x5 | Astc8x6 | Astc8x8
|
||||
| Astc10x5 | Astc10x6 | Astc10x8 | Astc10x10 | Astc12x10 | Astc12x12 => 16,
|
||||
|
||||
YuvG8B8G8R8_422 | YuvB8G8R8G8_422 => 2,
|
||||
|
||||
YuvG8B8R8Triplane420
|
||||
| YuvG8B8R8Biplane420
|
||||
| YuvG10X6B10X6R10X6Triplane420
|
||||
| YuvG10X6B10X6R10X6Biplane420
|
||||
| YuvG12X4B12X4R12X4Triplane420
|
||||
| YuvG12X4B12X4R12X4Biplane420
|
||||
| YuvG16B16R16Triplane420
|
||||
| YuvG16B16R16Biplane420 => 1,
|
||||
YuvG8B8R8Triplane422 => todo!(),
|
||||
YuvG8B8R8Biplane422 => todo!(),
|
||||
YuvG8B8R8Triplane444 => todo!(),
|
||||
YuvG10X6B10X6R10X6Triplane422 => todo!(),
|
||||
YuvG10X6B10X6R10X6Biplane422 => todo!(),
|
||||
YuvG10X6B10X6R10X6Triplane444 => todo!(),
|
||||
YuvG12X4B12X4R12X4Triplane422 => todo!(),
|
||||
YuvG12X4B12X4R12X4Biplane422 => todo!(),
|
||||
YuvG12X4B12X4R12X4Triplane444 => todo!(),
|
||||
YuvG16B16R16Triplane422 => todo!(),
|
||||
YuvG16B16R16Biplane422 => todo!(),
|
||||
YuvG16B16R16Triplane444 => todo!(),
|
||||
YuvG8B8R8Biplane444 => todo!(),
|
||||
YuvG10X6B10X6R10X6Biplane444 => todo!(),
|
||||
YuvG12X4B12X4R12X4Biplane444 => todo!(),
|
||||
YuvG16B16R16Biplane444 => todo!(),
|
||||
Bits64R10G10B10A10 => todo!(),
|
||||
Bits64G10B10G10R10_422 => todo!(),
|
||||
Bits64B10G10R10G10_422 => todo!(),
|
||||
Bits64R12G12B12A12 => todo!(),
|
||||
Bits64G12B12G12R12_422 => todo!(),
|
||||
Bits64B12G12R12G12_422 => todo!(),
|
||||
Bits64G16B16G16R16_422 => todo!(),
|
||||
Bits64B16G16R16G16_422 => todo!(),
|
||||
Bits64R14G14B14A14 => todo!(),
|
||||
Pvrtc1_2bpp => todo!(),
|
||||
Pvrtc1_4bpp => todo!(),
|
||||
Pvrtc2_2bpp => todo!(),
|
||||
Pvrtc2_4bpp => todo!(),
|
||||
Astc3x3x3 => todo!(),
|
||||
Astc4x3x3 => todo!(),
|
||||
Astc4x4x3 => todo!(),
|
||||
Astc4x4x4 => todo!(),
|
||||
Astc5x4x4 => todo!(),
|
||||
Astc5x5x4 => todo!(),
|
||||
Astc5x5x5 => todo!(),
|
||||
Astc6x5x5 => todo!(),
|
||||
Astc6x6x5 => todo!(),
|
||||
Astc6x6x6 => todo!(),
|
||||
YuvG14X2B14X2R14X2Biplane420 => todo!(),
|
||||
YuvG14X2B14X2R14X2Biplane422 => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@
|
|||
//! recorded sequentially, in the order they were inserted into a command
|
||||
//! buffer. During command insertion
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::{
|
||||
device::DeviceOwned,
|
||||
render_graph::recorder::{CommandRecorder, SideEffectMap},
|
||||
|
|
@ -23,7 +21,6 @@ use super::resources::*;
|
|||
|
||||
pub struct ImportResource<T: Resource> {
|
||||
pub resource: T,
|
||||
pub range: Option<Subresource>,
|
||||
pub access: vk::AccessFlags2,
|
||||
pub stage: vk::PipelineStageFlags2,
|
||||
pub layout: Option<vk::ImageLayout>,
|
||||
|
|
@ -31,9 +28,12 @@ pub struct ImportResource<T: Resource> {
|
|||
|
||||
impl<T: Resource> Command for ImportResource<T> {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
let range = self.range.unwrap_or_else(|| self.resource.full_range());
|
||||
map.with(self.stage, self.access, self.layout)
|
||||
.insert_range(self.resource.id(), range);
|
||||
self.resource
|
||||
.side_effect(map.reborrow().into_side_effect_map2(
|
||||
self.stage,
|
||||
self.access,
|
||||
self.layout,
|
||||
));
|
||||
}
|
||||
|
||||
fn apply(self, _recorder: &mut CommandRecorder) {
|
||||
|
|
@ -55,16 +55,16 @@ impl<T: AsRef<[BufferRows]>> BufferImageBufferCopyRegion for T {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait ImageCopyRegion<T: IntoImageSubresourceRange> {
|
||||
fn regions(&self) -> &[TextureRegion<T>];
|
||||
pub trait ImageCopyRegion {
|
||||
fn regions(&self) -> &[TextureRegion];
|
||||
}
|
||||
impl<T: IntoImageSubresourceRange> ImageCopyRegion<T> for TextureRegion<T> {
|
||||
fn regions(&self) -> &[TextureRegion<T>] {
|
||||
impl ImageCopyRegion for TextureRegion {
|
||||
fn regions(&self) -> &[TextureRegion] {
|
||||
core::slice::from_ref(self)
|
||||
}
|
||||
}
|
||||
impl<U: IntoImageSubresourceRange, T: AsRef<[TextureRegion<U>]>> ImageCopyRegion<U> for T {
|
||||
fn regions(&self) -> &[TextureRegion<U>] {
|
||||
impl<T: AsRef<[TextureRegion]>> ImageCopyRegion for T {
|
||||
fn regions(&self) -> &[TextureRegion] {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
|
@ -90,91 +90,59 @@ pub struct CopyBuffers<T: BufferCopyRegion> {
|
|||
pub dst_region: T,
|
||||
}
|
||||
|
||||
pub struct CopyTextures<T: ImageCopyRegion<R>, R: IntoImageSubresourceRange> {
|
||||
pub struct CopyTextures<T: ImageCopyRegion> {
|
||||
pub src: Texture,
|
||||
pub src_region: T,
|
||||
pub dst: Texture,
|
||||
pub dst_region: T,
|
||||
_pd: PhantomData<R>,
|
||||
}
|
||||
|
||||
pub struct CopyBufferToTexture<
|
||||
T: BufferImageBufferCopyRegion,
|
||||
U: ImageCopyRegion<R>,
|
||||
R: IntoImageSubresourceLayers,
|
||||
> {
|
||||
pub struct CopyBufferToTexture<T: BufferImageBufferCopyRegion, U: ImageCopyRegion> {
|
||||
pub src: Buffer,
|
||||
pub src_region: T,
|
||||
pub dst: Texture,
|
||||
pub dst_region: U,
|
||||
_pd: PhantomData<R>,
|
||||
}
|
||||
|
||||
pub struct CopyTextureToBuffer<
|
||||
T: ImageCopyRegion<R>,
|
||||
U: BufferImageBufferCopyRegion,
|
||||
R: IntoImageSubresourceLayers,
|
||||
> {
|
||||
pub struct CopyTextureToBuffer<T: ImageCopyRegion, U: BufferImageBufferCopyRegion> {
|
||||
pub src: Texture,
|
||||
pub src_region: T,
|
||||
pub dst: Buffer,
|
||||
pub dst_region: U,
|
||||
_pd: PhantomData<R>,
|
||||
}
|
||||
|
||||
impl<T, U, R> Command for CopyBufferToTexture<T, U, R>
|
||||
fn copy_side_effects_inner<T, U>(src: &T, dst: &U, mut map: SideEffectMap)
|
||||
where
|
||||
T: BufferImageBufferCopyRegion,
|
||||
U: ImageCopyRegion<R>,
|
||||
R: IntoImageSubresourceLayers,
|
||||
T: Resource,
|
||||
U: Resource,
|
||||
{
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
let block_size = self.dst.format().block_size() as u64;
|
||||
let texels_per_block = self.dst.format().texels_per_block() as u64;
|
||||
|
||||
let src_id = self.src.id();
|
||||
let dst_id = self.dst.id();
|
||||
|
||||
for (src_region, dst_region) in self
|
||||
.src_region
|
||||
.regions()
|
||||
.iter()
|
||||
.zip(self.dst_region.regions())
|
||||
{
|
||||
let texel_count = if src_region.row_size != 0 {
|
||||
let texel_count = src_region.row_size as u64 * src_region.row_count as u64;
|
||||
debug_assert!(
|
||||
texel_count % texels_per_block == 0,
|
||||
"Buffer copy region must be a multiple of the block size"
|
||||
);
|
||||
texel_count
|
||||
} else {
|
||||
dst_region.extent.width as u64
|
||||
* dst_region.extent.height as u64
|
||||
* dst_region.extent.depth as u64
|
||||
};
|
||||
|
||||
let byte_size = texel_count.div_ceil(texels_per_block) * block_size;
|
||||
|
||||
map.with(
|
||||
src.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_READ,
|
||||
Some(vk::ImageLayout::TRANSFER_SRC_OPTIMAL),
|
||||
)
|
||||
.insert_range(
|
||||
src_id,
|
||||
BufferRange {
|
||||
offset: src_region.offset,
|
||||
size: byte_size,
|
||||
},
|
||||
);
|
||||
|
||||
map.with(
|
||||
));
|
||||
dst.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
Some(vk::ImageLayout::TRANSFER_DST_OPTIMAL),
|
||||
)
|
||||
.insert_range(dst_id, dst_region.range.into_range());
|
||||
));
|
||||
}
|
||||
|
||||
impl<T, U> Command for CopyBufferToTexture<T, U>
|
||||
where
|
||||
T: BufferImageBufferCopyRegion,
|
||||
U: ImageCopyRegion,
|
||||
{
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
let src_map = map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_READ,
|
||||
Some(vk::ImageLayout::TRANSFER_SRC_OPTIMAL),
|
||||
);
|
||||
|
||||
let src_id = self.src.id();
|
||||
for region in self.src_region.regions() {
|
||||
src_map.insert_range(src_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,14 +162,20 @@ where
|
|||
.buffer_image_height(src_region.row_count)
|
||||
.image_offset(dst_region.offset)
|
||||
.image_extent(dst_region.extent)
|
||||
.image_subresource(dst_region.range.into_layers())
|
||||
.image_subresource(
|
||||
vk::ImageSubresourceLayers::default()
|
||||
.aspect_mask(dst_region.range.aspect)
|
||||
.mip_level(dst_region.range.mip_level)
|
||||
.base_array_layer(dst_region.range.array_layers.start())
|
||||
.layer_count(dst_region.range.array_layers.len()),
|
||||
)
|
||||
})
|
||||
.collect::<Box<[_]>>();
|
||||
|
||||
let info = vk::CopyBufferToImageInfo2::default()
|
||||
.src_buffer(recorder.get_buffer_handle(self.src.id()))
|
||||
.dst_image(recorder.get_image_handle(self.dst.id()))
|
||||
.dst_image_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL)
|
||||
.dst_image_layout(recorder.get_image_layout(self.dst.id()))
|
||||
.regions(®ions);
|
||||
|
||||
unsafe {
|
||||
|
|
@ -210,337 +184,48 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, U, R> Command for CopyTextureToBuffer<T, U, R>
|
||||
where
|
||||
T: ImageCopyRegion<R>,
|
||||
U: BufferImageBufferCopyRegion,
|
||||
R: IntoImageSubresourceLayers,
|
||||
{
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
let block_size = self.src.format().block_size() as u64;
|
||||
let texels_per_block = self.src.format().texels_per_block() as u64;
|
||||
|
||||
let src_id = self.src.id();
|
||||
let dst_id = self.dst.id();
|
||||
|
||||
for (src_region, dst_region) in self
|
||||
.src_region
|
||||
.regions()
|
||||
.iter()
|
||||
.zip(self.dst_region.regions())
|
||||
{
|
||||
let texel_count = if dst_region.row_size != 0 {
|
||||
let texel_count = dst_region.row_size as u64 * dst_region.row_count as u64;
|
||||
debug_assert!(
|
||||
texel_count % texels_per_block == 0,
|
||||
"Buffer copy region must be a multiple of the block size"
|
||||
);
|
||||
texel_count
|
||||
} else {
|
||||
src_region.extent.width as u64
|
||||
* src_region.extent.height as u64
|
||||
* src_region.extent.depth as u64
|
||||
};
|
||||
|
||||
let byte_size = texel_count.div_ceil(texels_per_block) * block_size;
|
||||
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_READ,
|
||||
Some(vk::ImageLayout::TRANSFER_SRC_OPTIMAL),
|
||||
)
|
||||
.insert_range(dst_id, src_region.range.into_range());
|
||||
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
Some(vk::ImageLayout::TRANSFER_DST_OPTIMAL),
|
||||
)
|
||||
.insert_range(
|
||||
src_id,
|
||||
BufferRange {
|
||||
offset: dst_region.offset,
|
||||
size: byte_size,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(self, recorder: &mut CommandRecorder) {
|
||||
let cmd = recorder.cmd_buffer();
|
||||
let dev = &cmd.device().raw;
|
||||
|
||||
let regions = self
|
||||
.src_region
|
||||
.regions()
|
||||
.iter()
|
||||
.zip(self.dst_region.regions())
|
||||
.map(|(src_region, dst_region)| {
|
||||
vk::BufferImageCopy2::default()
|
||||
.buffer_offset(dst_region.offset)
|
||||
.buffer_row_length(dst_region.row_size)
|
||||
.buffer_image_height(dst_region.row_count)
|
||||
.image_offset(src_region.offset)
|
||||
.image_extent(src_region.extent)
|
||||
.image_subresource(src_region.range.into_layers())
|
||||
})
|
||||
.collect::<Box<[_]>>();
|
||||
|
||||
let info = vk::CopyImageToBufferInfo2::default()
|
||||
.dst_buffer(recorder.get_buffer_handle(self.src.id()))
|
||||
.src_image(recorder.get_image_handle(self.dst.id()))
|
||||
.src_image_layout(vk::ImageLayout::TRANSFER_SRC_OPTIMAL)
|
||||
.regions(®ions);
|
||||
|
||||
unsafe {
|
||||
dev.cmd_copy_image_to_buffer2(cmd.raw(), &info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Command for CopyBuffers<T>
|
||||
where
|
||||
T: BufferCopyRegion,
|
||||
{
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
for region in self.src_region.regions() {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_READ,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.src.id(), *region);
|
||||
}
|
||||
|
||||
for region in self.dst_region.regions() {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.dst.id(), *region);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(self, recorder: &mut CommandRecorder) {
|
||||
let cmd = recorder.cmd_buffer();
|
||||
let dev = &cmd.device().raw;
|
||||
|
||||
let regions = self
|
||||
.src_region
|
||||
.regions()
|
||||
.iter()
|
||||
.zip(self.dst_region.regions())
|
||||
.map(|(src_region, dst_region)| {
|
||||
vk::BufferCopy2::default()
|
||||
.src_offset(src_region.offset)
|
||||
.dst_offset(dst_region.offset)
|
||||
.size(src_region.size)
|
||||
})
|
||||
.collect::<Box<[_]>>();
|
||||
|
||||
let info = vk::CopyBufferInfo2::default()
|
||||
.dst_buffer(recorder.get_buffer_handle(self.dst.id()))
|
||||
.src_buffer(recorder.get_buffer_handle(self.src.id()))
|
||||
.regions(®ions);
|
||||
|
||||
unsafe {
|
||||
dev.cmd_copy_buffer2(cmd.raw(), &info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R> Command for CopyTextures<T, R>
|
||||
where
|
||||
T: ImageCopyRegion<R>,
|
||||
R: IntoImageSubresourceLayers,
|
||||
{
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
for region in self.src_region.regions() {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_READ,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.src.id(), region.range.into_range());
|
||||
}
|
||||
|
||||
for region in self.dst_region.regions() {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COPY,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.dst.id(), region.range.into_range());
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(self, recorder: &mut CommandRecorder) {
|
||||
let cmd = recorder.cmd_buffer();
|
||||
let dev = &cmd.device().raw;
|
||||
|
||||
let regions = self
|
||||
.src_region
|
||||
.regions()
|
||||
.iter()
|
||||
.zip(self.dst_region.regions())
|
||||
.map(|(src_region, dst_region)| {
|
||||
vk::ImageCopy2::default()
|
||||
.src_offset(src_region.offset)
|
||||
.src_subresource(src_region.range.into_layers())
|
||||
.dst_offset(dst_region.offset)
|
||||
.dst_subresource(dst_region.range.into_layers())
|
||||
.extent(src_region.extent)
|
||||
})
|
||||
.collect::<Box<[_]>>();
|
||||
|
||||
let info = vk::CopyImageInfo2::default()
|
||||
.src_image(recorder.get_image_handle(self.src.id()))
|
||||
.src_image_layout(vk::ImageLayout::TRANSFER_SRC_OPTIMAL)
|
||||
.dst_image(recorder.get_image_handle(self.dst.id()))
|
||||
.dst_image_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL)
|
||||
.regions(®ions);
|
||||
|
||||
unsafe {
|
||||
dev.cmd_copy_image2(cmd.raw(), &info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ClearTexture<R: IntoImageSubresourceRange> {
|
||||
pub dst: Texture,
|
||||
pub dst_region: TextureRegion<R>,
|
||||
pub struct ClearTexture {
|
||||
pub dst: Write<TextureRegion>,
|
||||
pub clear_value: [f32; 4],
|
||||
}
|
||||
|
||||
impl<R: IntoImageSubresourceRange> Command for ClearTexture<R> {
|
||||
impl Command for ClearTexture {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::CLEAR,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
Some(vk::ImageLayout::TRANSFER_DST_OPTIMAL),
|
||||
)
|
||||
.insert_range(self.dst.id(), self.dst_region.range.into_range());
|
||||
}
|
||||
|
||||
fn apply(self, recorder: &mut CommandRecorder) {
|
||||
let cmd = recorder.cmd_buffer();
|
||||
let dev = &cmd.device().raw;
|
||||
|
||||
let values = vk::ClearColorValue {
|
||||
float32: self.clear_value,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
dev.cmd_clear_color_image(
|
||||
cmd.raw(),
|
||||
recorder.get_image_handle(self.dst.id()),
|
||||
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
|
||||
&values,
|
||||
&[self.dst_region.range.into_range()],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UpdateBuffer {
|
||||
pub dst: Buffer,
|
||||
pub dst_region: BufferRange,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl Command for UpdateBuffer {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
map.with(
|
||||
self.dst.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::TRANSFER,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.dst.id(), self.dst_region);
|
||||
Some(vk::ImageLayout::TRANSFER_DST_OPTIMAL),
|
||||
));
|
||||
}
|
||||
|
||||
fn apply(self, _recorder: &mut CommandRecorder) {}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RenderAttachment {
|
||||
pub texture: Texture,
|
||||
pub region: vk::ImageSubresourceRange,
|
||||
pub layout: vk::ImageLayout,
|
||||
pub load_op: vk::AttachmentLoadOp,
|
||||
pub store_op: vk::AttachmentStoreOp,
|
||||
pub struct UpdateBuffer {
|
||||
pub dst: Write<BufferSlice>,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl RenderAttachment {
|
||||
pub fn side_effect(&self, mut map: SideEffectMap, load: bool) {
|
||||
for attachment in &self.color_attachments {
|
||||
// The dependencies declared here need to be barrier'd before and
|
||||
// after the render pass: the spec says pipelineBarrier inside of a
|
||||
// render pass instance referencing framebuffer-local stages must
|
||||
// contain only framebuffer-local stages.
|
||||
impl Command for UpdateBuffer {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
self.dst.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::TRANSFER,
|
||||
vk::AccessFlags2::TRANSFER_WRITE,
|
||||
None,
|
||||
));
|
||||
}
|
||||
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::COLOR_ATTACHMENT_OUTPUT,
|
||||
if attachment.load_op == vk::AttachmentLoadOp::LOAD {
|
||||
vk::AccessFlags2::COLOR_ATTACHMENT_READ
|
||||
} else {
|
||||
vk::AccessFlags2::empty()
|
||||
},
|
||||
Some(attachment.layout),
|
||||
)
|
||||
.insert_range(attachment.texture.id(), attachment.region);
|
||||
}
|
||||
if let Some(depth) = &self.depth_attachment {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::EARLY_FRAGMENT_TESTS,
|
||||
if depth.load_op == vk::AttachmentLoadOp::LOAD {
|
||||
vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ
|
||||
} else {
|
||||
vk::AccessFlags2::empty()
|
||||
},
|
||||
Some(depth.layout),
|
||||
)
|
||||
.insert_range(depth.texture.id(), depth.region);
|
||||
}
|
||||
if let Some(stencil) = &self.stencil_attachment {
|
||||
map.with(
|
||||
vk::PipelineStageFlags2::EARLY_FRAGMENT_TESTS,
|
||||
if stencil.load_op == vk::AttachmentLoadOp::LOAD {
|
||||
vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ
|
||||
} else {
|
||||
vk::AccessFlags2::empty()
|
||||
},
|
||||
Some(stencil.layout),
|
||||
)
|
||||
.insert_range(stencil.texture.id(), stencil.region);
|
||||
}
|
||||
}
|
||||
fn apply(self, _recorder: &mut CommandRecorder) {}
|
||||
}
|
||||
|
||||
pub struct BeginRendering {
|
||||
pub color_attachments: Vec<RenderAttachment>,
|
||||
pub depth_attachment: Option<RenderAttachment>,
|
||||
pub stencil_attachment: Option<RenderAttachment>,
|
||||
pub color_attachments: Vec<TextureRegion>,
|
||||
pub depth_attachment: Option<TextureRegion>,
|
||||
pub stencil_attachment: Option<TextureRegion>,
|
||||
pub area: (u32, u32),
|
||||
pub layers: u32,
|
||||
}
|
||||
|
||||
pub struct EndRendering {
|
||||
pub color_attachments: Vec<RenderAttachment>,
|
||||
pub depth_attachment: Option<RenderAttachment>,
|
||||
pub stencil_attachment: Option<RenderAttachment>,
|
||||
}
|
||||
|
||||
impl BeginRendering {
|
||||
fn end_rendering(&self) -> EndRendering {
|
||||
EndRendering {
|
||||
color_attachments: self.color_attachments.clone(),
|
||||
depth_attachment: self.depth_attachment.clone(),
|
||||
stencil_attachment: self.stencil_attachment.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Command for BeginRendering {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
for attachment in &self.color_attachments {
|
||||
|
|
@ -549,49 +234,37 @@ impl Command for BeginRendering {
|
|||
// pass instance referencing framebuffer-local stages must contain
|
||||
// only framebuffer-local stages.
|
||||
|
||||
map.with(
|
||||
// TODO: consider loadop and storeop?
|
||||
attachment.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::COLOR_ATTACHMENT_OUTPUT,
|
||||
if attachment.load_op == vk::AttachmentLoadOp::LOAD {
|
||||
vk::AccessFlags2::COLOR_ATTACHMENT_READ
|
||||
} else {
|
||||
vk::AccessFlags2::empty()
|
||||
},
|
||||
Some(attachment.layout),
|
||||
)
|
||||
.insert_range(attachment.texture.id(), attachment.region);
|
||||
vk::AccessFlags2::COLOR_ATTACHMENT_READ,
|
||||
Some(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL),
|
||||
));
|
||||
}
|
||||
if let Some(depth) = &self.depth_attachment {
|
||||
map.with(
|
||||
depth.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::EARLY_FRAGMENT_TESTS,
|
||||
if depth.load_op == vk::AttachmentLoadOp::LOAD {
|
||||
vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ
|
||||
} else {
|
||||
vk::AccessFlags2::empty()
|
||||
},
|
||||
Some(depth.layout),
|
||||
)
|
||||
.insert_range(depth.texture.id(), depth.region);
|
||||
vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ,
|
||||
Some(vk::ImageLayout::DEPTH_ATTACHMENT_OPTIMAL),
|
||||
));
|
||||
}
|
||||
if let Some(stencil) = &self.stencil_attachment {
|
||||
map.with(
|
||||
stencil.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::EARLY_FRAGMENT_TESTS,
|
||||
if stencil.load_op == vk::AttachmentLoadOp::LOAD {
|
||||
vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ
|
||||
} else {
|
||||
vk::AccessFlags2::empty()
|
||||
},
|
||||
Some(stencil.layout),
|
||||
)
|
||||
.insert_range(stencil.texture.id(), stencil.region);
|
||||
vk::AccessFlags2::DEPTH_STENCIL_ATTACHMENT_READ,
|
||||
Some(vk::ImageLayout::STENCIL_ATTACHMENT_OPTIMAL),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(self, _recorder: &mut CommandRecorder) {}
|
||||
}
|
||||
|
||||
pub struct EndRendering;
|
||||
|
||||
impl Command for EndRendering {
|
||||
fn side_effects(&self, _map: SideEffectMap) {
|
||||
// TODO: need the beginrendering struct to declare the store-op dependencies.
|
||||
// No resource access, but ends the render pass
|
||||
}
|
||||
|
||||
fn apply(self, _recorder: &mut CommandRecorder) {}
|
||||
|
|
@ -622,12 +295,11 @@ pub struct BindVertexBuffers {
|
|||
impl Command for BindVertexBuffers {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
for buffer in &self.buffers {
|
||||
map.with(
|
||||
buffer.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::VERTEX_ATTRIBUTE_INPUT,
|
||||
vk::AccessFlags2::VERTEX_ATTRIBUTE_READ,
|
||||
None,
|
||||
)
|
||||
.insert_range(buffer.id(), buffer.range);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -657,12 +329,11 @@ pub struct BindIndexBuffer(pub BufferSlice, pub IndexFormat);
|
|||
|
||||
impl Command for BindIndexBuffer {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
map.with(
|
||||
self.0.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::INDEX_INPUT,
|
||||
vk::AccessFlags2::INDEX_READ,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.0.id(), self.0.range);
|
||||
));
|
||||
}
|
||||
|
||||
fn apply(self, recorder: &mut CommandRecorder) {
|
||||
|
|
@ -807,11 +478,27 @@ pub enum IndexFormat {
|
|||
|
||||
pub struct Draw<T: IsDrawData> {
|
||||
pub data: T,
|
||||
pub vertex_buffers: Vec<BufferSlice>,
|
||||
pub index_buffer: Option<(BufferSlice, IndexFormat)>,
|
||||
}
|
||||
|
||||
impl<T: IsDrawData> Command for Draw<T> {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
self.data.side_effects(map.reborrow());
|
||||
for vertex_buffer in &self.vertex_buffers {
|
||||
vertex_buffer.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::VERTEX_ATTRIBUTE_INPUT,
|
||||
vk::AccessFlags2::VERTEX_ATTRIBUTE_READ,
|
||||
None,
|
||||
));
|
||||
}
|
||||
if let Some((index_buffer, _)) = &self.index_buffer {
|
||||
index_buffer.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::INDEX_INPUT,
|
||||
vk::AccessFlags2::INDEX_READ,
|
||||
None,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn apply(self, _recorder: &mut CommandRecorder) {}
|
||||
|
|
@ -840,35 +527,35 @@ mod sealed {
|
|||
pub trait OutsideRenderPass {}
|
||||
}
|
||||
use ash::vk;
|
||||
use ash_formats::FormatExt;
|
||||
pub(super) use sealed::*;
|
||||
|
||||
impl IsDrawData for DrawData {}
|
||||
impl IsDrawData for DrawIndexedData {}
|
||||
impl IsDrawData for DrawIndirectData {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
map.with(
|
||||
self.indirect_buffer
|
||||
.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::DRAW_INDIRECT,
|
||||
vk::AccessFlags2::INDIRECT_COMMAND_READ,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.indirect_buffer.id(), self.indirect_buffer.range);
|
||||
));
|
||||
}
|
||||
}
|
||||
impl IsDrawData for DrawIndexedIndirectData {
|
||||
fn side_effects(&self, mut map: SideEffectMap) {
|
||||
map.with(
|
||||
self.indirect_buffer
|
||||
.side_effect(map.reborrow().into_side_effect_map2(
|
||||
vk::PipelineStageFlags2::DRAW_INDIRECT,
|
||||
vk::AccessFlags2::INDIRECT_COMMAND_READ,
|
||||
None,
|
||||
)
|
||||
.insert_range(self.indirect_buffer.id(), self.indirect_buffer.range);
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
impl OutsideRenderPass for BeginRendering {}
|
||||
impl InsideRenderPass for EndRendering {}
|
||||
impl<T: IntoImageSubresourceRange> OutsideRenderPass for ClearTexture<T> {}
|
||||
impl<T: Resource, U: Resource> OutsideRenderPass for Copy<T, U> {}
|
||||
impl OutsideRenderPass for ClearTexture {}
|
||||
impl OutsideRenderPass for UpdateBuffer {}
|
||||
|
||||
impl InsideRenderPass for BindPipeline {}
|
||||
|
|
|
|||
|
|
@ -80,11 +80,7 @@ impl<'r> GraphBuilder<'r> {
|
|||
|
||||
mod api_demo {
|
||||
|
||||
use crate::{
|
||||
EguiState,
|
||||
pipeline::Pipeline,
|
||||
render_graph::{commands, resources::TextureRegion},
|
||||
};
|
||||
use crate::{EguiState, pipeline::Pipeline, render_graph::commands};
|
||||
|
||||
use super::*;
|
||||
use ash::vk::{self, BufferUsageFlags};
|
||||
|
|
@ -184,86 +180,84 @@ mod api_demo {
|
|||
);
|
||||
|
||||
let mut cmd = builder.make_command_list();
|
||||
// cmd.push(commands::Copy {
|
||||
// src: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(staging.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: 0,
|
||||
// size: vertex_size as u64,
|
||||
// },
|
||||
// },
|
||||
// dst: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(vertex_buffer.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: 0,
|
||||
// size: vertex_size as u64,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
cmd.push(commands::Copy {
|
||||
src: resources::BufferSlice {
|
||||
buffer: resources::Buffer(staging.id),
|
||||
range: resources::BufferRange {
|
||||
offset: 0,
|
||||
size: vertex_size as u64,
|
||||
},
|
||||
},
|
||||
dst: resources::BufferSlice {
|
||||
buffer: resources::Buffer(vertex_buffer.id),
|
||||
range: resources::BufferRange {
|
||||
offset: 0,
|
||||
size: vertex_size as u64,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// cmd.push(commands::Copy {
|
||||
// src: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(staging.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: vertex_size as u64,
|
||||
// size: (vertex_size + index_size) as u64,
|
||||
// },
|
||||
// },
|
||||
// dst: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(index_buffer.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: 0,
|
||||
// size: index_size as u64,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
cmd.push(commands::Copy {
|
||||
src: resources::BufferSlice {
|
||||
buffer: resources::Buffer(staging.id),
|
||||
range: resources::BufferRange {
|
||||
offset: vertex_size as u64,
|
||||
size: (vertex_size + index_size) as u64,
|
||||
},
|
||||
},
|
||||
dst: resources::BufferSlice {
|
||||
buffer: resources::Buffer(index_buffer.id),
|
||||
range: resources::BufferRange {
|
||||
offset: 0,
|
||||
size: index_size as u64,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// cmd.push(commands::Copy {
|
||||
// src: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(staging.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: (vertex_size + index_size) as u64,
|
||||
// size: draw_calls_size as u64,
|
||||
// },
|
||||
// },
|
||||
// dst: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(indirect_buffer.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: 0,
|
||||
// size: draw_calls_size as u64,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
cmd.push(commands::Copy {
|
||||
src: resources::BufferSlice {
|
||||
buffer: resources::Buffer(staging.id),
|
||||
range: resources::BufferRange {
|
||||
offset: (vertex_size + index_size) as u64,
|
||||
size: draw_calls_size as u64,
|
||||
},
|
||||
},
|
||||
dst: resources::BufferSlice {
|
||||
buffer: resources::Buffer(indirect_buffer.id),
|
||||
range: resources::BufferRange {
|
||||
offset: 0,
|
||||
size: draw_calls_size as u64,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// cmd.push(commands::Copy {
|
||||
// src: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(staging.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: (vertex_size + index_size + draw_calls_size) as u64,
|
||||
// size: textures_indices_size as u64,
|
||||
// },
|
||||
// },
|
||||
// dst: resources::BufferSlice {
|
||||
// buffer: resources::Buffer(texture_indices.id),
|
||||
// range: resources::BufferRange {
|
||||
// offset: 0,
|
||||
// size: textures_indices_size as u64,
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
cmd.push(commands::Copy {
|
||||
src: resources::BufferSlice {
|
||||
buffer: resources::Buffer(staging.id),
|
||||
range: resources::BufferRange {
|
||||
offset: (vertex_size + index_size + draw_calls_size) as u64,
|
||||
size: textures_indices_size as u64,
|
||||
},
|
||||
},
|
||||
dst: resources::BufferSlice {
|
||||
buffer: resources::Buffer(texture_indices.id),
|
||||
range: resources::BufferRange {
|
||||
offset: 0,
|
||||
size: textures_indices_size as u64,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let mut pass_cmd = cmd.begin_rendering(
|
||||
vec![commands::RenderAttachment {
|
||||
vec![resources::TextureRegion {
|
||||
texture: resources::Texture(render_target),
|
||||
region: vk::ImageSubresourceRange::default()
|
||||
.aspect_mask(vk::ImageAspectFlags::COLOR)
|
||||
.base_mip_level(0)
|
||||
.level_count(1)
|
||||
.base_array_layer(0)
|
||||
.layer_count(1),
|
||||
layout: vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
|
||||
load_op: vk::AttachmentLoadOp::LOAD,
|
||||
store_op: vk::AttachmentStoreOp::STORE,
|
||||
range: resources::TextureRange {
|
||||
aspect: vk::ImageAspectFlags::COLOR,
|
||||
mip_levels: (0..).into(),
|
||||
array_layers: (0..).into(),
|
||||
origin: (0, 0, 0),
|
||||
extent: (extent.0, extent.1, 1),
|
||||
},
|
||||
}],
|
||||
None,
|
||||
None,
|
||||
|
|
@ -307,17 +301,20 @@ mod api_demo {
|
|||
&[extent.0 as f32, extent.1 as f32].map(f32::to_bits),
|
||||
),
|
||||
});
|
||||
pass_cmd.push(commands::BindVertexBuffers {
|
||||
buffers: vec![resources::BufferSlice {
|
||||
pass_cmd.push(commands::Draw {
|
||||
data: commands::DrawIndexedIndirectData {
|
||||
indirect_buffer: resources::Buffer(indirect_buffer.id).full_slice(),
|
||||
count: draw_calls.len() as u32,
|
||||
stride: size_of::<DrawCall>() as u32,
|
||||
},
|
||||
vertex_buffers: vec![resources::BufferSlice {
|
||||
buffer: resources::Buffer(vertex_buffer.id),
|
||||
range: resources::BufferRange {
|
||||
offset: 0,
|
||||
size: vertex_size as u64,
|
||||
},
|
||||
}],
|
||||
first_binding: 0,
|
||||
});
|
||||
pass_cmd.push(commands::BindIndexBuffer(
|
||||
index_buffer: Some((
|
||||
resources::BufferSlice {
|
||||
buffer: resources::Buffer(index_buffer.id),
|
||||
range: resources::BufferRange {
|
||||
|
|
@ -326,13 +323,7 @@ mod api_demo {
|
|||
},
|
||||
},
|
||||
commands::IndexFormat::Uint32,
|
||||
));
|
||||
pass_cmd.push(commands::Draw {
|
||||
data: commands::DrawIndexedIndirectData {
|
||||
indirect_buffer: resources::Buffer(indirect_buffer.id).full_slice(),
|
||||
count: draw_calls.len() as u32,
|
||||
stride: size_of::<DrawCall>() as u32,
|
||||
},
|
||||
)),
|
||||
});
|
||||
|
||||
pass_cmd.finalise();
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ use crate::{
|
|||
commands::CommandBuffer,
|
||||
images::ImageDesc,
|
||||
render_graph::{
|
||||
commands::{Command, InsideRenderPass, OutsideRenderPass, RenderAttachment},
|
||||
resources::{ResourceId, Subresource, SubresourceScope, SubresourceScopeInner},
|
||||
commands::{Command, InsideRenderPass, OutsideRenderPass},
|
||||
resources::{
|
||||
ResourceId, Subresource, SubresourceScope, SubresourceScopeInner, TextureRegion,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -81,12 +83,6 @@ impl<T> VecOrSingle<T> {
|
|||
VecOrSingle::Single(item) => core::slice::from_ref::<T>(item).iter(),
|
||||
}
|
||||
}
|
||||
fn iter_mut(&mut self) -> core::slice::IterMut<'_, T> {
|
||||
match self {
|
||||
VecOrSingle::Vec(items) => items.as_mut_slice().iter_mut(),
|
||||
VecOrSingle::Single(item) => core::slice::from_mut::<T>(item).iter_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -98,35 +94,13 @@ struct SideEffects {
|
|||
pub struct SideEffectMap<'a>(&'a mut SideEffects, u32);
|
||||
|
||||
impl<'a> SideEffectMap<'a> {
|
||||
pub fn insert(&mut self, id: ResourceId, new_scope: SubresourceScope) {
|
||||
pub fn insert(&mut self, id: ResourceId, scope: SubresourceScope) {
|
||||
self.0.resources.insert(id);
|
||||
|
||||
'inserted: {
|
||||
'outer: for ((_rid, _cid), scopes) in self.0.map.range_mut((id, 0)..=(id, self.1)).rev()
|
||||
{
|
||||
for scope in scopes.iter_mut().rev() {
|
||||
if scope.try_merge(&new_scope) {
|
||||
// if we can fold this scope with a previous one, we can
|
||||
// stop iterating, as the barrier already exists if
|
||||
// needed
|
||||
break 'inserted;
|
||||
} else if scope.conflicts(&new_scope) {
|
||||
// if this scope conflicts with a previous one, we need
|
||||
// to insert a barrier before the current command index;
|
||||
// we can stop iterating, as we can no longer fold into
|
||||
// any scopes before this conflict
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we couldn't fold this scope with any previous one, add it as a new entry
|
||||
self.0
|
||||
.map
|
||||
.entry((id, self.1))
|
||||
.and_modify(|entry| entry.push(new_scope))
|
||||
.or_insert_with(|| new_scope.into());
|
||||
}
|
||||
.and_modify(|entry| entry.push(scope))
|
||||
.or_insert_with(|| scope.into());
|
||||
}
|
||||
|
||||
pub fn reborrow(&mut self) -> SideEffectMap<'_> {
|
||||
|
|
@ -147,16 +121,6 @@ impl<'a> SideEffectMap<'a> {
|
|||
required_layout,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with(
|
||||
&mut self,
|
||||
stage_flags: vk::PipelineStageFlags2,
|
||||
access_flags: vk::AccessFlags2,
|
||||
required_layout: Option<vk::ImageLayout>,
|
||||
) -> SideEffectMap2<'_> {
|
||||
self.reborrow()
|
||||
.into_side_effect_map2(stage_flags, access_flags, required_layout)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SideEffectMap2<'a> {
|
||||
|
|
@ -245,9 +209,9 @@ impl<'cmd> CommandList<'cmd> {
|
|||
|
||||
pub fn begin_rendering(
|
||||
&mut self,
|
||||
color_attachments: Vec<RenderAttachment>,
|
||||
depth_attachment: Option<RenderAttachment>,
|
||||
stencil_attachment: Option<RenderAttachment>,
|
||||
color_attachments: Vec<TextureRegion>,
|
||||
depth_attachment: Option<TextureRegion>,
|
||||
stencil_attachment: Option<TextureRegion>,
|
||||
area: (u32, u32),
|
||||
layers: u32,
|
||||
) -> RenderPass<'cmd, '_> {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,10 @@ use crate::{images::MipRange, render_graph::recorder::SideEffectMap2};
|
|||
|
||||
pub trait Resource: Sized {
|
||||
fn id(&self) -> ResourceId;
|
||||
fn full_range(&self) -> Subresource;
|
||||
fn side_effect(&self, map: SideEffectMap2);
|
||||
}
|
||||
|
||||
mod sealed {
|
||||
use ash::vk;
|
||||
|
||||
pub trait Texture {
|
||||
fn format(&self) -> vk::Format {
|
||||
todo!()
|
||||
|
|
@ -23,32 +21,11 @@ mod sealed {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub use sealed::{Buffer as AsBuffer, Texture as AsTexture};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Subresource {
|
||||
Buffer(BufferRange),
|
||||
Texture(vk::ImageSubresourceRange),
|
||||
}
|
||||
|
||||
impl Subresource {
|
||||
pub fn full_buffer() -> Self {
|
||||
Self::Buffer(BufferRange {
|
||||
offset: 0,
|
||||
size: vk::WHOLE_SIZE,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn full_texture(format: vk::Format) -> Self {
|
||||
use ash_formats::FormatExt;
|
||||
Self::Texture(vk::ImageSubresourceRange {
|
||||
aspect_mask: format.aspect_flags(),
|
||||
base_mip_level: 0,
|
||||
level_count: vk::REMAINING_MIP_LEVELS,
|
||||
base_array_layer: 0,
|
||||
layer_count: vk::REMAINING_ARRAY_LAYERS,
|
||||
})
|
||||
}
|
||||
Texture(TextureRange),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
@ -64,7 +41,7 @@ pub enum SubresourceScopeInner {
|
|||
subresource: BufferRange,
|
||||
},
|
||||
Texture {
|
||||
subresource: vk::ImageSubresourceRange,
|
||||
subresource: TextureRange,
|
||||
layout: vk::ImageLayout,
|
||||
},
|
||||
}
|
||||
|
|
@ -114,18 +91,18 @@ impl SubresourceScope {
|
|||
// think), however: if a previous access requires a less general
|
||||
// barrier, then is it better to split?
|
||||
|
||||
let overlaps = lhs.aspect_mask.intersects(rhs.aspect_mask)
|
||||
&& lhs.mip_levels().intersects(rhs.mip_levels())
|
||||
&& lhs.layers().intersects(rhs.layers());
|
||||
let overlaps = lhs.aspect.intersects(rhs.aspect)
|
||||
&& lhs.mip_levels.intersects(rhs.mip_levels)
|
||||
&& lhs.array_layers.intersects(rhs.array_layers);
|
||||
|
||||
// non-overlapping sub-resources shouldn't be merged.
|
||||
if !overlaps {
|
||||
return false;
|
||||
}
|
||||
|
||||
let lhs_contains_rhs = lhs.aspect_mask.contains(rhs.aspect_mask)
|
||||
&& lhs.mip_levels().contains(rhs.mip_levels())
|
||||
&& lhs.layers().contains(rhs.layers());
|
||||
let lhs_contains_rhs = lhs.aspect.contains(rhs.aspect)
|
||||
&& lhs.mip_levels.contains(rhs.mip_levels)
|
||||
&& lhs.array_layers.contains(rhs.array_layers);
|
||||
|
||||
// other is not a subresource of self, so we can't merge them.
|
||||
if !lhs_contains_rhs {
|
||||
|
|
@ -166,9 +143,9 @@ impl SubresourceScope {
|
|||
) => {
|
||||
// image subresource ranges overlap if they share mip levels and
|
||||
// array layers with the same aspects.
|
||||
let overlaps = lhs.aspect_mask.intersects(rhs.aspect_mask)
|
||||
&& lhs.mip_levels().intersects(rhs.mip_levels())
|
||||
&& lhs.layers().intersects(rhs.layers());
|
||||
let overlaps = lhs.aspect.intersects(rhs.aspect)
|
||||
&& lhs.mip_levels.intersects(rhs.mip_levels)
|
||||
&& lhs.array_layers.intersects(rhs.array_layers);
|
||||
|
||||
if !overlaps {
|
||||
return false;
|
||||
|
|
@ -194,6 +171,8 @@ mod impls {
|
|||
use super::*;
|
||||
|
||||
impl sealed::Texture for Texture {}
|
||||
impl sealed::Texture for TextureRegion {}
|
||||
impl sealed::Texture for TextureView {}
|
||||
|
||||
impl sealed::Buffer for Buffer {}
|
||||
impl sealed::Buffer for BufferSlice {}
|
||||
|
|
@ -203,25 +182,130 @@ mod impls {
|
|||
self.0
|
||||
}
|
||||
|
||||
fn full_range(&self) -> Subresource {
|
||||
Subresource::full_buffer()
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
map.insert_range(self.id(), BufferRange::full());
|
||||
}
|
||||
}
|
||||
|
||||
impl Resource for BufferSlice {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.buffer.id()
|
||||
}
|
||||
|
||||
fn full_range(&self) -> Subresource {
|
||||
self.buffer.full_range()
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
map.insert_range(self.id(), self.range);
|
||||
}
|
||||
}
|
||||
impl Resource for BufferSlices {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.buffer.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
for range in &self.ranges {
|
||||
map.insert_range(self.id(), *range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: the rows are not in bytes, so this is plain wrong. A BufferRowSlice needs to be generic over Buffer/BufferSlice, or commands taking a BufferRowSlice need to take the row parameters separately.
|
||||
impl Resource for BufferRowSlice {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.buffer.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
map.insert_range(
|
||||
self.id(),
|
||||
BufferRange {
|
||||
offset: self.row.offset,
|
||||
size: vk::WHOLE_SIZE,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
impl Resource for BufferRowSlices {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.buffer.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
for row in &self.rows {
|
||||
map.insert_range(
|
||||
self.id(),
|
||||
BufferRange {
|
||||
offset: row.offset,
|
||||
size: vk::WHOLE_SIZE,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Resource for Texture {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.0
|
||||
}
|
||||
fn full_range(&self) -> Subresource {
|
||||
Subresource::full_texture(vk::Format::UNDEFINED)
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
map.insert_range(self.id(), TextureRange::full());
|
||||
}
|
||||
}
|
||||
impl Resource for TextureRegion {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.texture.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
map.insert_range(self.id(), self.range);
|
||||
}
|
||||
}
|
||||
impl Resource for TextureRegions {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.texture.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
for range in &self.ranges {
|
||||
map.insert_range(self.id(), range.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Resource for TextureView {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.texture.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, mut map: SideEffectMap2) {
|
||||
map.insert_range(self.id(), self.range);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Resource> Resource for Read<T> {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.0.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, map: SideEffectMap2) {
|
||||
self.0.side_effect(map);
|
||||
}
|
||||
}
|
||||
impl<T: Resource> Resource for Write<T> {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.0.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, map: SideEffectMap2) {
|
||||
self.0.side_effect(map);
|
||||
}
|
||||
}
|
||||
impl<T: Resource> Resource for ReadWrite<T> {
|
||||
fn id(&self) -> ResourceId {
|
||||
self.0.id()
|
||||
}
|
||||
|
||||
fn side_effect(&self, map: SideEffectMap2) {
|
||||
self.0.side_effect(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -268,12 +352,6 @@ impl BufferRange {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BufferRange> for Subresource {
|
||||
fn from(value: BufferRange) -> Self {
|
||||
Subresource::Buffer(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct BufferRows {
|
||||
pub offset: u64,
|
||||
|
|
@ -281,105 +359,67 @@ pub struct BufferRows {
|
|||
pub row_size: u32,
|
||||
}
|
||||
|
||||
pub trait IntoImageSubresourceLayers {
|
||||
fn into_layers(&self) -> vk::ImageSubresourceLayers;
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct TextureRange {
|
||||
pub aspect: vk::ImageAspectFlags,
|
||||
pub mip_levels: MipRange,
|
||||
pub array_layers: MipRange,
|
||||
}
|
||||
|
||||
pub trait IntoImageSubresourceRange {
|
||||
fn into_range(&self) -> vk::ImageSubresourceRange;
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct TextureLayers {
|
||||
pub aspect: vk::ImageAspectFlags,
|
||||
pub mip_level: u32,
|
||||
pub array_layers: MipRange,
|
||||
}
|
||||
|
||||
impl IntoImageSubresourceLayers for vk::ImageSubresource {
|
||||
fn into_layers(&self) -> vk::ImageSubresourceLayers {
|
||||
impl From<TextureLayers> for vk::ImageSubresourceLayers {
|
||||
fn from(value: TextureLayers) -> Self {
|
||||
vk::ImageSubresourceLayers {
|
||||
aspect_mask: self.aspect_mask,
|
||||
mip_level: self.mip_level,
|
||||
base_array_layer: self.array_layer,
|
||||
layer_count: 1,
|
||||
aspect_mask: value.aspect,
|
||||
mip_level: value.mip_level,
|
||||
base_array_layer: value.array_layers.start,
|
||||
layer_count: value.array_layers.end - value.array_layers.start,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoImageSubresourceRange for T
|
||||
where
|
||||
T: IntoImageSubresourceLayers,
|
||||
{
|
||||
fn into_range(&self) -> vk::ImageSubresourceRange {
|
||||
self.into_layers().into_range()
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoImageSubresourceRange for vk::ImageSubresourceLayers {
|
||||
fn into_range(&self) -> vk::ImageSubresourceRange {
|
||||
impl From<TextureRange> for vk::ImageSubresourceRange {
|
||||
fn from(value: TextureRange) -> Self {
|
||||
vk::ImageSubresourceRange {
|
||||
aspect_mask: self.aspect_mask,
|
||||
base_mip_level: self.mip_level,
|
||||
level_count: 1,
|
||||
base_array_layer: self.base_array_layer,
|
||||
layer_count: self.layer_count,
|
||||
aspect_mask: value.aspect,
|
||||
base_mip_level: value.mip_levels.start,
|
||||
level_count: value.mip_levels.end - value.mip_levels.start,
|
||||
base_array_layer: value.array_layers.start,
|
||||
layer_count: value.array_layers.end - value.array_layers.start,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoImageSubresourceRange for vk::ImageSubresourceRange {
|
||||
fn into_range(&self) -> vk::ImageSubresourceRange {
|
||||
*self
|
||||
impl From<TextureLayers> for TextureRange {
|
||||
fn from(value: TextureLayers) -> Self {
|
||||
Self {
|
||||
aspect: value.aspect,
|
||||
mip_levels: MipRange::single(value.mip_level),
|
||||
array_layers: value.array_layers,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ImageSubresourceExt {
|
||||
fn aspects(self) -> vk::ImageAspectFlags;
|
||||
fn layers(self) -> MipRange;
|
||||
fn mip_levels(self) -> MipRange;
|
||||
}
|
||||
|
||||
impl ImageSubresourceExt for vk::ImageSubresourceLayers {
|
||||
fn aspects(self) -> vk::ImageAspectFlags {
|
||||
self.aspect_mask
|
||||
}
|
||||
fn layers(self) -> MipRange {
|
||||
MipRange::new(
|
||||
self.base_array_layer,
|
||||
self.base_array_layer + self.layer_count,
|
||||
)
|
||||
}
|
||||
|
||||
fn mip_levels(self) -> MipRange {
|
||||
MipRange::single(self.mip_level)
|
||||
impl From<TextureLayers> for Subresource {
|
||||
fn from(value: TextureLayers) -> Self {
|
||||
Subresource::Texture(TextureRange {
|
||||
aspect: value.aspect,
|
||||
mip_levels: MipRange::single(value.mip_level),
|
||||
array_layers: value.array_layers,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageSubresourceExt for vk::ImageSubresourceRange {
|
||||
fn aspects(self) -> vk::ImageAspectFlags {
|
||||
self.aspect_mask
|
||||
}
|
||||
fn layers(self) -> MipRange {
|
||||
MipRange::new(
|
||||
self.base_array_layer,
|
||||
self.base_array_layer + self.layer_count,
|
||||
)
|
||||
}
|
||||
|
||||
fn mip_levels(self) -> MipRange {
|
||||
MipRange::new(self.base_mip_level, self.base_mip_level + self.level_count)
|
||||
}
|
||||
}
|
||||
|
||||
impl ImageSubresourceExt for vk::ImageSubresource {
|
||||
fn aspects(self) -> vk::ImageAspectFlags {
|
||||
self.aspect_mask
|
||||
}
|
||||
fn layers(self) -> MipRange {
|
||||
MipRange::single(self.mip_level)
|
||||
}
|
||||
|
||||
fn mip_levels(self) -> MipRange {
|
||||
MipRange::single(self.array_layer)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<vk::ImageSubresourceRange> for Subresource {
|
||||
fn from(value: vk::ImageSubresourceRange) -> Self {
|
||||
impl From<TextureRange> for Subresource {
|
||||
fn from(value: TextureRange) -> Self {
|
||||
Subresource::Texture(value)
|
||||
}
|
||||
}
|
||||
|
|
@ -393,6 +433,17 @@ impl From<(BufferRange, vk::ImageLayout)> for ResourceRange {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<(TextureRange, vk::ImageLayout)> for ResourceRange {
|
||||
fn from((value, layout): (TextureRange, vk::ImageLayout)) -> Self {
|
||||
ResourceRange::Texture {
|
||||
aspect: value.aspect,
|
||||
mip_level: value.mip_levels,
|
||||
array_layers: value.array_layers,
|
||||
layout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BufferRange> for ResourceRange {
|
||||
fn from(value: BufferRange) -> Self {
|
||||
ResourceRange::Buffer {
|
||||
|
|
@ -402,6 +453,18 @@ impl From<BufferRange> for ResourceRange {
|
|||
}
|
||||
}
|
||||
|
||||
impl TextureRange {
|
||||
pub fn full() -> Self {
|
||||
Self {
|
||||
aspect: vk::ImageAspectFlags::COLOR
|
||||
| vk::ImageAspectFlags::DEPTH
|
||||
| vk::ImageAspectFlags::STENCIL,
|
||||
mip_levels: MipRange::default(),
|
||||
array_layers: MipRange::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Buffer(pub ResourceId);
|
||||
|
||||
impl Buffer {
|
||||
|
|
@ -416,7 +479,6 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Texture(pub ResourceId);
|
||||
|
||||
pub struct BufferSlice {
|
||||
|
|
@ -439,12 +501,19 @@ pub struct BufferRowSlices {
|
|||
pub rows: Vec<BufferRows>,
|
||||
}
|
||||
|
||||
pub struct TextureRegion<T: IntoImageSubresourceRange = vk::ImageSubresourceRange> {
|
||||
pub range: T,
|
||||
pub struct TextureRegion {
|
||||
pub range: TextureLayers,
|
||||
pub offset: vk::Offset3D,
|
||||
pub extent: vk::Extent3D,
|
||||
}
|
||||
|
||||
pub struct TextureView {
|
||||
pub texture: Texture,
|
||||
pub format: vk::Format,
|
||||
pub mapping: vk::ComponentMapping,
|
||||
pub range: TextureRange,
|
||||
}
|
||||
|
||||
pub struct Read<T>(pub T);
|
||||
pub struct Write<T>(pub T);
|
||||
pub struct ReadWrite<T>(pub T);
|
||||
|
|
|
|||
Loading…
Reference in a new issue