1use webgpu_traits::{ComputePass, ComputePassId, RenderPass, RenderPassId};
6use wgpu_core::id::markers::{
7 Adapter, BindGroup, BindGroupLayout, Buffer, CommandBuffer, CommandEncoder, ComputePipeline,
8 Device, ExternalTexture, PipelineLayout, QuerySet, Queue, RenderBundle, RenderPipeline,
9 Sampler, ShaderModule, Texture, TextureView,
10};
11use wgpu_core::id::{
12 AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
13 ComputePipelineId, DeviceId, ExternalTextureId, PipelineLayoutId, QuerySetId, QueueId,
14 RenderBundleId, RenderPipelineId, SamplerId, 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 command_buffers: IdentityManager<CommandBuffer>,
31 textures: IdentityManager<Texture>,
32 texture_views: IdentityManager<TextureView>,
33 samplers: IdentityManager<Sampler>,
34 render_pipelines: IdentityManager<RenderPipeline>,
35 render_bundles: IdentityManager<RenderBundle>,
36 compute_passes: IdentityManager<ComputePass>,
37 render_passes: IdentityManager<RenderPass>,
38 query_sets: IdentityManager<QuerySet>,
39 external_textures: IdentityManager<ExternalTexture>,
40}
41
42impl Default for IdentityHub {
43 fn default() -> Self {
44 IdentityHub {
45 adapters: IdentityManager::new(),
46 devices: IdentityManager::new(),
47 queues: IdentityManager::new(),
48 buffers: IdentityManager::new(),
49 bind_groups: IdentityManager::new(),
50 bind_group_layouts: IdentityManager::new(),
51 compute_pipelines: IdentityManager::new(),
52 pipeline_layouts: IdentityManager::new(),
53 shader_modules: IdentityManager::new(),
54 command_encoders: IdentityManager::new(),
55 command_buffers: IdentityManager::new(),
56 textures: IdentityManager::new(),
57 texture_views: IdentityManager::new(),
58 samplers: IdentityManager::new(),
59 render_pipelines: IdentityManager::new(),
60 render_bundles: IdentityManager::new(),
61 compute_passes: IdentityManager::new(),
62 render_passes: IdentityManager::new(),
63 query_sets: IdentityManager::new(),
64 external_textures: IdentityManager::new(),
65 }
66 }
67}
68
69impl IdentityHub {
70 pub(crate) fn create_device_id(&self) -> DeviceId {
71 self.devices.process()
72 }
73
74 pub(crate) fn free_device_id(&self, id: DeviceId) {
75 self.devices.free(id);
76 }
77
78 pub(crate) fn create_queue_id(&self) -> QueueId {
79 self.queues.process()
80 }
81
82 pub(crate) fn free_queue_id(&self, id: QueueId) {
83 self.queues.free(id);
84 }
85
86 pub(crate) fn create_adapter_id(&self) -> AdapterId {
87 self.adapters.process()
88 }
89
90 pub(crate) fn free_adapter_id(&self, id: AdapterId) {
91 self.adapters.free(id);
92 }
93
94 pub(crate) fn create_buffer_id(&self) -> BufferId {
95 self.buffers.process()
96 }
97
98 pub(crate) fn free_buffer_id(&self, id: BufferId) {
99 self.buffers.free(id);
100 }
101
102 pub(crate) fn create_bind_group_id(&self) -> BindGroupId {
103 self.bind_groups.process()
104 }
105
106 pub(crate) fn free_bind_group_id(&self, id: BindGroupId) {
107 self.bind_groups.free(id);
108 }
109
110 pub(crate) fn create_bind_group_layout_id(&self) -> BindGroupLayoutId {
111 self.bind_group_layouts.process()
112 }
113
114 pub(crate) fn free_bind_group_layout_id(&self, id: BindGroupLayoutId) {
115 self.bind_group_layouts.free(id);
116 }
117
118 pub(crate) fn create_compute_pipeline_id(&self) -> ComputePipelineId {
119 self.compute_pipelines.process()
120 }
121
122 pub(crate) fn free_compute_pipeline_id(&self, id: ComputePipelineId) {
123 self.compute_pipelines.free(id);
124 }
125
126 pub(crate) fn create_pipeline_layout_id(&self) -> PipelineLayoutId {
127 self.pipeline_layouts.process()
128 }
129
130 pub(crate) fn free_pipeline_layout_id(&self, id: PipelineLayoutId) {
131 self.pipeline_layouts.free(id);
132 }
133
134 pub(crate) fn create_shader_module_id(&self) -> ShaderModuleId {
135 self.shader_modules.process()
136 }
137
138 pub(crate) fn free_shader_module_id(&self, id: ShaderModuleId) {
139 self.shader_modules.free(id);
140 }
141
142 pub(crate) fn create_command_encoder_id(&self) -> CommandEncoderId {
143 self.command_encoders.process()
144 }
145
146 pub(crate) fn free_command_encoder_id(&self, id: CommandEncoderId) {
147 self.command_encoders.free(id);
148 }
149
150 pub(crate) fn create_command_buffer_id(&self) -> CommandBufferId {
151 self.command_buffers.process()
152 }
153
154 pub(crate) fn free_command_buffer_id(&self, id: CommandBufferId) {
155 self.command_buffers.free(id);
156 }
157
158 pub(crate) fn create_sampler_id(&self) -> SamplerId {
159 self.samplers.process()
160 }
161
162 pub(crate) fn free_sampler_id(&self, id: SamplerId) {
163 self.samplers.free(id);
164 }
165
166 pub(crate) fn create_render_pipeline_id(&self) -> RenderPipelineId {
167 self.render_pipelines.process()
168 }
169
170 pub(crate) fn free_render_pipeline_id(&self, id: RenderPipelineId) {
171 self.render_pipelines.free(id);
172 }
173
174 pub(crate) fn create_texture_id(&self) -> TextureId {
175 self.textures.process()
176 }
177
178 pub(crate) fn free_texture_id(&self, id: TextureId) {
179 self.textures.free(id);
180 }
181
182 pub(crate) fn create_texture_view_id(&self) -> TextureViewId {
183 self.texture_views.process()
184 }
185
186 pub(crate) fn free_texture_view_id(&self, id: TextureViewId) {
187 self.texture_views.free(id);
188 }
189
190 pub(crate) fn create_render_bundle_id(&self) -> RenderBundleId {
191 self.render_bundles.process()
192 }
193
194 pub(crate) fn free_render_bundle_id(&self, id: RenderBundleId) {
195 self.render_bundles.free(id);
196 }
197
198 pub(crate) fn create_compute_pass_id(&self) -> ComputePassId {
199 self.compute_passes.process()
200 }
201
202 pub(crate) fn free_compute_pass_id(&self, id: ComputePassId) {
203 self.compute_passes.free(id);
204 }
205
206 pub(crate) fn create_render_pass_id(&self) -> RenderPassId {
207 self.render_passes.process()
208 }
209
210 pub(crate) fn free_render_pass_id(&self, id: RenderPassId) {
211 self.render_passes.free(id);
212 }
213
214 pub(crate) fn create_query_set_id(&self) -> QuerySetId {
215 self.query_sets.process()
216 }
217
218 pub(crate) fn free_query_set_id(&self, id: QuerySetId) {
219 self.query_sets.free(id);
220 }
221
222 pub(crate) fn create_external_texture_id(&self) -> ExternalTextureId {
223 self.external_textures.process()
224 }
225
226 pub(crate) fn free_external_texture_id(&self, id: ExternalTextureId) {
227 self.external_textures.free(id);
228 }
229}