ursus_core/render/resource/
desc.rs1use crate::render::gfx::descriptor::ImageUsage;
2use crate::render::gfx::types::Format;
3use ash::vk;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub struct ResourceHandle(pub(crate) u32);
7
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub enum ResourceExtent {
10 Absolute(u32, u32),
11 ScaleInternal(f32),
12 ScaleOutput(f32),
13}
14
15impl ResourceExtent {
16 pub fn resolve(&self, internal: (u32, u32), output: (u32, u32)) -> (u32, u32) {
17 let scale = |(w, h): (u32, u32), s: f32| {
18 (((w as f32 * s).round() as u32).max(1), ((h as f32 * s).round() as u32).max(1))
19 };
20
21 match *self {
22 Self::Absolute(w, h) => (w, h),
23 Self::ScaleInternal(s) => scale(internal, s),
24 Self::ScaleOutput(s) => scale(output, s),
25 }
26 }
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum ResourceKind {
31 Color,
32 Depth,
33}
34
35impl ResourceKind {
36 pub fn aspect_mask(self) -> vk::ImageAspectFlags {
37 match self {
38 Self::Color => vk::ImageAspectFlags::COLOR,
39 Self::Depth => vk::ImageAspectFlags::DEPTH,
40 }
41 }
42}
43
44#[derive(Debug, Clone)]
45pub struct ResourceDesc {
46 pub name: String,
47 pub format: Format,
48 pub extent: ResourceExtent,
49 pub kind: ResourceKind,
50 pub usage: ImageUsage,
51}
52
53impl ResourceDesc {
54 pub fn color(name: impl Into<String>, format: Format, extent: ResourceExtent) -> Self {
55 Self {
56 name: name.into(),
57 format,
58 extent,
59 kind: ResourceKind::Color,
60 usage: ImageUsage::COLOR_ATTACHMENT | ImageUsage::SAMPLED,
61 }
62 }
63
64 pub fn depth(name: impl Into<String>, format: Format, extent: ResourceExtent) -> Self {
65 Self {
66 name: name.into(),
67 format,
68 extent,
69 kind: ResourceKind::Depth,
70 usage: ImageUsage::DEPTH_ATTACHMENT | ImageUsage::SAMPLED,
71 }
72 }
73
74 pub fn with_usage(mut self, flags: ImageUsage) -> Self {
75 self.usage |= flags;
76 self
77 }
78}
79
80pub struct ExternalImageDesc {
81 pub name: String,
82 pub format: vk::Format,
83 pub kind: ResourceKind,
84 pub initial_layout: vk::ImageLayout,
85 pub final_layout: vk::ImageLayout,
86}