lumen_engine_gpu/
resource.rs1use crate::{BufferId, NodeKey, SamplerId, Size, TextureDomain, TextureId};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub struct TextureDesc {
5 pub domain: TextureDomain,
6 pub format: wgpu::TextureFormat,
7 pub usage: wgpu::TextureUsages,
8}
9
10impl TextureDesc {
11 pub fn render_target(size: Size, format: wgpu::TextureFormat) -> Self {
12 Self {
13 domain: TextureDomain::full_frame(size),
14 format,
15 usage: wgpu::TextureUsages::RENDER_ATTACHMENT
16 | wgpu::TextureUsages::TEXTURE_BINDING
17 | wgpu::TextureUsages::COPY_SRC,
18 }
19 }
20
21 pub fn sampled(size: Size, format: wgpu::TextureFormat) -> Self {
22 Self {
23 domain: TextureDomain::full_frame(size),
24 format,
25 usage: wgpu::TextureUsages::TEXTURE_BINDING
26 | wgpu::TextureUsages::COPY_DST
27 | wgpu::TextureUsages::COPY_SRC,
28 }
29 }
30
31 pub fn storage(size: Size, format: wgpu::TextureFormat) -> Self {
32 Self {
33 domain: TextureDomain::full_frame(size),
34 format,
35 usage: wgpu::TextureUsages::STORAGE_BINDING
36 | wgpu::TextureUsages::TEXTURE_BINDING
37 | wgpu::TextureUsages::COPY_DST
38 | wgpu::TextureUsages::COPY_SRC,
39 }
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44pub struct BufferDesc {
45 pub size: u64,
46 pub usage: wgpu::BufferUsages,
47}
48
49impl BufferDesc {
50 pub fn uniform(size: u64) -> Self {
51 Self {
52 size,
53 usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
54 }
55 }
56
57 pub fn storage(size: u64) -> Self {
58 Self {
59 size,
60 usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
61 }
62 }
63
64 pub fn vertex(size: u64) -> Self {
65 Self {
66 size,
67 usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
68 }
69 }
70
71 pub fn index(size: u64) -> Self {
72 Self {
73 size,
74 usage: wgpu::BufferUsages::INDEX | wgpu::BufferUsages::COPY_DST,
75 }
76 }
77
78 pub fn indirect(size: u64) -> Self {
79 Self {
80 size,
81 usage: wgpu::BufferUsages::INDIRECT | wgpu::BufferUsages::COPY_DST,
82 }
83 }
84}
85
86#[derive(Debug, Clone)]
87pub struct TextureResource {
88 pub id: TextureId,
89 pub label: Option<String>,
90 pub desc: TextureDesc,
91 pub owner: Option<NodeKey>,
92}
93
94#[derive(Debug, Clone)]
95pub struct BufferResource {
96 pub id: BufferId,
97 pub label: Option<String>,
98 pub desc: BufferDesc,
99 pub owner: Option<NodeKey>,
100}
101
102#[derive(Debug, Clone)]
103pub struct SamplerResource {
104 pub id: SamplerId,
105 pub label: Option<String>,
106 pub desc: wgpu::SamplerDescriptor<'static>,
107}