Skip to content

Commit 1d1f953

Browse files
committed
Deploying to master from @ a420e453c3d9c93dfb1a8526bf11c000d895c916 🚀
1 parent 5eb73d6 commit 1d1f953

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

‎doc/src/wgpu/util/belt.rs.html

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@
179179
<span id="171">171</span>
180180
<span id="172">172</span>
181181
<span id="173">173</span>
182+
<span id="174">174</span>
183+
<span id="175">175</span>
184+
<span id="176">176</span>
185+
<span id="177">177</span>
186+
<span id="178">178</span>
187+
<span id="179">179</span>
188+
<span id="180">180</span>
189+
<span id="181">181</span>
190+
<span id="182">182</span>
191+
<span id="183">183</span>
182192
</pre><pre class="rust"><code><span class="kw">use</span> <span class="kw">crate</span>::{
183193
<span class="ident">util::align_to</span>, <span class="ident">Buffer</span>, <span class="ident">BufferAddress</span>, <span class="ident">BufferDescriptor</span>, <span class="ident">BufferSize</span>, <span class="ident">BufferUsages</span>,
184194
<span class="ident">BufferViewMut</span>, <span class="ident">CommandEncoder</span>, <span class="ident">Device</span>, <span class="ident">MapMode</span>,
@@ -269,23 +279,27 @@
269279
.<span class="ident">position</span>(<span class="op">|</span><span class="ident">chunk</span><span class="op">|</span> <span class="ident">chunk</span>.<span class="ident">offset</span> <span class="op">+</span> <span class="ident">size</span>.<span class="ident">get</span>() <span class="op">&lt;</span><span class="op">=</span> <span class="ident">chunk</span>.<span class="ident">size</span>)
270280
{
271281
<span class="self">self</span>.<span class="ident">active_chunks</span>.<span class="ident">swap_remove</span>(<span class="ident">index</span>)
272-
} <span class="kw">else</span> <span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">index</span>) <span class="op">=</span> <span class="self">self</span>
273-
.<span class="ident">free_chunks</span>
274-
.<span class="ident">iter</span>()
275-
.<span class="ident">position</span>(<span class="op">|</span><span class="ident">chunk</span><span class="op">|</span> <span class="ident">size</span>.<span class="ident">get</span>() <span class="op">&lt;</span><span class="op">=</span> <span class="ident">chunk</span>.<span class="ident">size</span>)
276-
{
277-
<span class="self">self</span>.<span class="ident">free_chunks</span>.<span class="ident">swap_remove</span>(<span class="ident">index</span>)
278282
} <span class="kw">else</span> {
279-
<span class="kw">let</span> <span class="ident">size</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">chunk_size</span>.<span class="ident">max</span>(<span class="ident">size</span>.<span class="ident">get</span>());
280-
<span class="ident">Chunk</span> {
281-
<span class="ident">buffer</span>: <span class="ident">Arc::new</span>(<span class="ident">device</span>.<span class="ident">create_buffer</span>(<span class="kw-2">&amp;</span><span class="ident">BufferDescriptor</span> {
282-
<span class="ident">label</span>: <span class="prelude-val">Some</span>(<span class="string">&quot;(wgpu internal) StagingBelt staging buffer&quot;</span>),
283+
<span class="self">self</span>.<span class="ident">receive_chunks</span>(); <span class="comment">// ensure self.free_chunks is up to date</span>
284+
285+
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">index</span>) <span class="op">=</span> <span class="self">self</span>
286+
.<span class="ident">free_chunks</span>
287+
.<span class="ident">iter</span>()
288+
.<span class="ident">position</span>(<span class="op">|</span><span class="ident">chunk</span><span class="op">|</span> <span class="ident">size</span>.<span class="ident">get</span>() <span class="op">&lt;</span><span class="op">=</span> <span class="ident">chunk</span>.<span class="ident">size</span>)
289+
{
290+
<span class="self">self</span>.<span class="ident">free_chunks</span>.<span class="ident">swap_remove</span>(<span class="ident">index</span>)
291+
} <span class="kw">else</span> {
292+
<span class="kw">let</span> <span class="ident">size</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">chunk_size</span>.<span class="ident">max</span>(<span class="ident">size</span>.<span class="ident">get</span>());
293+
<span class="ident">Chunk</span> {
294+
<span class="ident">buffer</span>: <span class="ident">Arc::new</span>(<span class="ident">device</span>.<span class="ident">create_buffer</span>(<span class="kw-2">&amp;</span><span class="ident">BufferDescriptor</span> {
295+
<span class="ident">label</span>: <span class="prelude-val">Some</span>(<span class="string">&quot;(wgpu internal) StagingBelt staging buffer&quot;</span>),
296+
<span class="ident">size</span>,
297+
<span class="ident">usage</span>: <span class="ident">BufferUsages::MAP_WRITE</span> <span class="op">|</span> <span class="ident">BufferUsages::COPY_SRC</span>,
298+
<span class="ident">mapped_at_creation</span>: <span class="bool-val">true</span>,
299+
})),
283300
<span class="ident">size</span>,
284-
<span class="ident">usage</span>: <span class="ident">BufferUsages::MAP_WRITE</span> <span class="op">|</span> <span class="ident">BufferUsages::COPY_SRC</span>,
285-
<span class="ident">mapped_at_creation</span>: <span class="bool-val">true</span>,
286-
})),
287-
<span class="ident">size</span>,
288-
<span class="ident">offset</span>: <span class="number">0</span>,
301+
<span class="ident">offset</span>: <span class="number">0</span>,
302+
}
289303
}
290304
};
291305

@@ -323,10 +337,7 @@
323337
<span class="doccomment">/// [`StagingBelt::write_buffer()`] are submitted. Additional calls are harmless.</span>
324338
<span class="doccomment">/// Not calling this as soon as possible may result in increased buffer memory usage.</span>
325339
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">recall</span>(<span class="kw-2">&amp;mut</span> <span class="self">self</span>) {
326-
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Ok</span>(<span class="kw-2">mut</span> <span class="ident">chunk</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">receiver</span>.<span class="ident">try_recv</span>() {
327-
<span class="ident">chunk</span>.<span class="ident">offset</span> <span class="op">=</span> <span class="number">0</span>;
328-
<span class="self">self</span>.<span class="ident">free_chunks</span>.<span class="ident">push</span>(<span class="ident">chunk</span>);
329-
}
340+
<span class="self">self</span>.<span class="ident">receive_chunks</span>();
330341

331342
<span class="kw">let</span> <span class="ident">sender</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">sender</span>;
332343
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="self">self</span>.<span class="ident">closed_chunks</span>.<span class="ident">drain</span>(..) {
@@ -340,6 +351,15 @@
340351
});
341352
}
342353
}
354+
355+
<span class="doccomment">/// Move all chunks that the GPU is done with (and are now mapped again)</span>
356+
<span class="doccomment">/// from `self.receiver` to `self.free_chunks`.</span>
357+
<span class="kw">fn</span> <span class="ident">receive_chunks</span>(<span class="kw-2">&amp;mut</span> <span class="self">self</span>) {
358+
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Ok</span>(<span class="kw-2">mut</span> <span class="ident">chunk</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">receiver</span>.<span class="ident">try_recv</span>() {
359+
<span class="ident">chunk</span>.<span class="ident">offset</span> <span class="op">=</span> <span class="number">0</span>;
360+
<span class="self">self</span>.<span class="ident">free_chunks</span>.<span class="ident">push</span>(<span class="ident">chunk</span>);
361+
}
362+
}
343363
}
344364

345365
<span class="kw">impl</span> <span class="ident">fmt::Debug</span> <span class="kw">for</span> <span class="ident">StagingBelt</span> {

0 commit comments

Comments
 (0)