script/dom/webgpu/
identityhub.rs1use webgpu_traits::{ComputePass, ComputePassId, RenderPass, RenderPassId};
6use wgpu_core::id::markers::{
7 Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device,
8 PipelineLayout, Queue, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture,
9 TextureView,
10};
11use wgpu_core::id::{
12 AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
13 DeviceId, PipelineLayoutId, QueueId, RenderBundleId, RenderPipelineId, SamplerId,
14 ShaderModuleId, TextureId, TextureViewId,
15};
16use wgpu_core::identity::IdentityManager;
17
18#[derive(Debug)]
19pub(crate) struct IdentityHub {
20 adapters: IdentityManager<Adapter>,
21 devices: IdentityManager<Device>,
22 queues: IdentityManager<Queue>,
23 buffers: IdentityManager<Buffer>,
24 bind_groups: IdentityManager<BindGroup>,
25 bind_group_layouts: IdentityManager<BindGroupLayout>,
26 compute_pipelines: IdentityManager<ComputePipeline>,
27 pipeline_layouts: IdentityManager<PipelineLayout>,
28 shader_modules: IdentityManager<ShaderModule>,
29 command_encoders: IdentityManager<CommandEncoder>,
30 textures: IdentityManager<Texture>,
31 texture_views: IdentityManager<TextureView>,
32 samplers: IdentityManager<Sampler>,
33 render_pipelines: IdentityManager<RenderPipeline>,
34 render_bundles: IdentityManager<RenderBundle>,
35 compute_passes: IdentityManager<ComputePass>,
36 render_passes: IdentityManager<RenderPass>,
37}
38
39impl Default for IdentityHub {
40 fn default() -> Self {
41 IdentityHub {
42 adapters: IdentityManager::new(),
43 devices: IdentityManager::new(),
44 queues: IdentityManager::new(),
45 buffers: IdentityManager::new(),
46 bind_groups: IdentityManager::new(),
47 bind_group_layouts: IdentityManager::new(),
48 compute_pipelines: IdentityManager::new(),
49 pipeline_layouts: IdentityManager::new(),
50 shader_modules: IdentityManager::new(),
51 command_encoders: IdentityManager::new(),
52 textures: IdentityManager::new(),
53 texture_views: IdentityManager::new(),
54 samplers: IdentityManager::new(),
55 render_pipelines: IdentityManager::new(),
56 render_bundles: IdentityManager::new(),
57 compute_passes: IdentityManager::new(),
58 render_passes: IdentityManager::new(),
59 }
60 }
61}
62
63impl IdentityHub {
64 pub(crate) fn create_device_id(&self) -> DeviceId {
65 self.devices.process()
66 }
67
68 pub(crate) fn free_device_id(&self, id: DeviceId) {
69 self.devices.free(id);
70 }
71
72 pub(crate) fn create_queue_id(&self) -> QueueId {
73 self.queues.process()
74 }
75
76 pub(crate) fn free_queue_id(&self, id: QueueId) {
77 self.queues.free(id);
78 }
79
80 pub(crate) fn create_adapter_id(&self) -> AdapterId {
81 self.adapters.process()
82 }
83
84 pub(crate) fn free_adapter_id(&self, id: AdapterId) {
85 self.adapters.free(id);
86 }
87
88 pub(crate) fn create_buffer_id(&self) -> BufferId {
89 self.buffers.process()
90 }
91
92 pub(crate) fn free_buffer_id(&self, id: BufferId) {
93 self.buffers.free(id);
94 }
95
96 pub(crate) fn create_bind_group_id(&self) -> BindGroupId {
97 self.bind_groups.process()
98 }
99
100 pub(crate) fn free_bind_group_id(&self, id: BindGroupId) {
101 self.bind_groups.free(id);
102 }
103
104 pub(crate) fn create_bind_group_layout_id(&self) -> BindGroupLayoutId {
105 self.bind_group_layouts.process()
106 }
107
108 pub(crate) fn free_bind_group_layout_id(&self, id: BindGroupLayoutId) {
109 self.bind_group_layouts.free(id);
110 }
111
112 pub(crate) fn create_compute_pipeline_id(&self) -> ComputePipelineId {
113 self.compute_pipelines.process()
114 }
115
116 pub(crate) fn free_compute_pipeline_id(&self, id: ComputePipelineId) {
117 self.compute_pipelines.free(id);
118 }
119
120 pub(crate) fn create_pipeline_layout_id(&self) -> PipelineLayoutId {
121 self.pipeline_layouts.process()
122 }
123
124 pub(crate) fn free_pipeline_layout_id(&self, id: PipelineLayoutId) {
125 self.pipeline_layouts.free(id);
126 }
127
128 pub(crate) fn create_shader_module_id(&self) -> ShaderModuleId {
129 self.shader_modules.process()
130 }
131
132 pub(crate) fn free_shader_module_id(&self, id: ShaderModuleId) {
133 self.shader_modules.free(id);
134 }
135
136 pub(crate) fn create_command_encoder_id(&self) -> CommandEncoderId {
137 self.command_encoders.process()
138 }
139
140 pub(crate) fn free_command_buffer_id(&self, id: CommandEncoderId) {
141 self.command_encoders.free(id);
142 }
143
144 pub(crate) fn create_sampler_id(&self) -> SamplerId {
145 self.samplers.process()
146 }
147
148 pub(crate) fn free_sampler_id(&self, id: SamplerId) {
149 self.samplers.free(id);
150 }
151
152 pub(crate) fn create_render_pipeline_id(&self) -> RenderPipelineId {
153 self.render_pipelines.process()
154 }
155
156 pub(crate) fn free_render_pipeline_id(&self, id: RenderPipelineId) {
157 self.render_pipelines.free(id);
158 }
159
160 pub(crate) fn create_texture_id(&self) -> TextureId {
161 self.textures.process()
162 }
163
164 pub(crate) fn free_texture_id(&self, id: TextureId) {
165 self.textures.free(id);
166 }
167
168 pub(crate) fn create_texture_view_id(&self) -> TextureViewId {
169 self.texture_views.process()
170 }
171
172 pub(crate) fn free_texture_view_id(&self, id: TextureViewId) {
173 self.texture_views.free(id);
174 }
175
176 pub(crate) fn create_render_bundle_id(&self) -> RenderBundleId {
177 self.render_bundles.process()
178 }
179
180 pub(crate) fn free_render_bundle_id(&self, id: RenderBundleId) {
181 self.render_bundles.free(id);
182 }
183
184 pub(crate) fn create_compute_pass_id(&self) -> ComputePassId {
185 self.compute_passes.process()
186 }
187
188 pub(crate) fn free_compute_pass_id(&self, id: ComputePassId) {
189 self.compute_passes.free(id);
190 }
191
192 pub(crate) fn create_render_pass_id(&self) -> RenderPassId {
193 self.render_passes.process()
194 }
195
196 pub(crate) fn free_render_pass_id(&self, id: RenderPassId) {
197 self.render_passes.free(id);
198 }
199}