MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / acquire

Method acquire

native/shared/src/renderer/transient.rs:175–212  ·  view source on GitHub ↗

Acquire a transient matching `desc`. Returns either a freed slot from the reuse pool or allocates a new one via `device`. The returned handle is valid until `release()` or the next resize.

(&mut self, device: &wgpu::Device, desc: TransientDesc)

Source from the content-addressed store, hash-verified

173 /// The returned handle is valid until `release()` or the next
174 /// resize.
175 pub fn acquire(&mut self, device: &wgpu::Device, desc: TransientDesc) -> TransientId {
176 let target_extent = desc.size.extent(self.swap_size.0, self.swap_size.1);
177
178 // Look for an existing free slot with identical desc + extent.
179 for slot in self.slots.iter_mut() {
180 if !slot.in_use
181 && slot.desc == desc
182 && slot.extent == target_extent
183 {
184 slot.in_use = true;
185 return TransientId(slot.id);
186 }
187 }
188
189 // Nothing matched — allocate a new slot.
190 let texture = device.create_texture(&wgpu::TextureDescriptor {
191 label: Some("transient"),
192 size: wgpu::Extent3d {
193 width: target_extent.0,
194 height: target_extent.1,
195 depth_or_array_layers: 1,
196 },
197 mip_level_count: desc.mips,
198 sample_count: desc.samples,
199 dimension: wgpu::TextureDimension::D2,
200 format: desc.format,
201 usage: desc.usage,
202 view_formats: &[],
203 });
204 let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
205 let id = self.next_id;
206 self.next_id += 1;
207 // Ids are stable — surviving slots keep theirs across resizes
208 // (which can drop swapchain-relative slots and shrink the Vec),
209 // so handle lookups stay valid even when the slot index shifts.
210 self.slots.push(Slot { id, desc, extent: target_extent, texture, view, in_use: true });
211 TransientId(id)
212 }
213
214 /// Mark a transient as no longer in use. The slot returns to the
215 /// reuse pool and can be handed back to a subsequent `acquire`

Calls 4

TransientIdClass · 0.85
extentMethod · 0.80
iter_mutMethod · 0.80
pushMethod · 0.45