Skip to content

Commit dd74cac

Browse files
committed
Deploying to master from @ 75519839be7977617396ec1a70f7ac2a023b0e9d 🚀
1 parent 9c65116 commit dd74cac

File tree

8 files changed

+108
-43
lines changed

8 files changed

+108
-43
lines changed

‎doc/search-index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,27 @@
158158
<span id="150">150</span>
159159
<span id="151">151</span>
160160
<span id="152">152</span>
161+
<span id="153">153</span>
162+
<span id="154">154</span>
163+
<span id="155">155</span>
164+
<span id="156">156</span>
165+
<span id="157">157</span>
166+
<span id="158">158</span>
167+
<span id="159">159</span>
168+
<span id="160">160</span>
169+
<span id="161">161</span>
170+
<span id="162">162</span>
171+
<span id="163">163</span>
172+
<span id="164">164</span>
173+
<span id="165">165</span>
174+
<span id="166">166</span>
175+
<span id="167">167</span>
176+
<span id="168">168</span>
177+
<span id="169">169</span>
178+
<span id="170">170</span>
179+
<span id="171">171</span>
180+
<span id="172">172</span>
181+
<span id="173">173</span>
161182
</pre><pre class="rust"><code><span class="kw">use</span> <span class="kw">crate</span>::{
162183
<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>,
163184
<span class="ident">BufferViewMut</span>, <span class="ident">CommandEncoder</span>, <span class="ident">Device</span>, <span class="ident">MapMode</span>,
@@ -171,37 +192,47 @@
171192
<span class="ident">offset</span>: <span class="ident">BufferAddress</span>,
172193
}
173194

174-
<span class="doccomment">/// Staging belt is a machine that uploads data.</span>
195+
<span class="doccomment">/// Efficiently performs many buffer writes by sharing and reusing temporary buffers.</span>
175196
<span class="doccomment">///</span>
176197
<span class="doccomment">/// Internally it uses a ring-buffer of staging buffers that are sub-allocated.</span>
177-
<span class="doccomment">/// It has an advantage over [`Queue::write_buffer`] in a way that it returns a mutable slice,</span>
198+
<span class="doccomment">/// It has an advantage over [`Queue::write_buffer()`] in a way that it returns a mutable slice,</span>
178199
<span class="doccomment">/// which you can fill to avoid an extra data copy.</span>
179200
<span class="doccomment">///</span>
180201
<span class="doccomment">/// Using a staging belt is slightly complicated, and generally goes as follows:</span>
181-
<span class="doccomment">/// - Write to buffers that need writing to using [`StagingBelt::write_buffer`].</span>
182-
<span class="doccomment">/// - Call `finish`.</span>
183-
<span class="doccomment">/// - Submit all command encoders used with `StagingBelt::write_buffer`.</span>
184-
<span class="doccomment">/// - Call `recall`</span>
202+
<span class="doccomment">/// 1. Write to buffers that need writing to using [`StagingBelt::write_buffer()`].</span>
203+
<span class="doccomment">/// 2. Call [`StagingBelt::finish()`].</span>
204+
<span class="doccomment">/// 3. Submit all command encoders that were used in step 1.</span>
205+
<span class="doccomment">/// 4. Call [`StagingBelt::recall()`].</span>
185206
<span class="doccomment">///</span>
186-
<span class="doccomment">/// [`Queue::write_buffer`]: crate::Queue::write_buffer</span>
207+
<span class="doccomment">/// [`Queue::write_buffer()`]: crate::Queue::write_buffer</span>
187208
<span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">StagingBelt</span> {
188209
<span class="ident">chunk_size</span>: <span class="ident">BufferAddress</span>,
189-
<span class="doccomment">/// Chunks that we are actively using for pending transfers at this moment.</span>
210+
<span class="doccomment">/// Chunks into which we are accumulating data to be transferred.</span>
190211
<span class="ident">active_chunks</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">Chunk</span><span class="op">&gt;</span>,
191-
<span class="doccomment">/// Chunks that have scheduled transfers already.</span>
212+
<span class="doccomment">/// Chunks that have scheduled transfers already; they are unmapped and some</span>
213+
<span class="doccomment">/// command encoder has one or more `copy_buffer_to_buffer` commands with them</span>
214+
<span class="doccomment">/// as source.</span>
192215
<span class="ident">closed_chunks</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">Chunk</span><span class="op">&gt;</span>,
193-
<span class="doccomment">/// Chunks that are back from the GPU and ready to be used.</span>
216+
<span class="doccomment">/// Chunks that are back from the GPU and ready to be mapped for write and put</span>
217+
<span class="doccomment">/// into `active_chunks`.</span>
194218
<span class="ident">free_chunks</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">Chunk</span><span class="op">&gt;</span>,
219+
<span class="doccomment">/// When closed chunks are mapped again, the map callback sends them here.</span>
195220
<span class="ident">sender</span>: <span class="ident">mpsc::Sender</span><span class="op">&lt;</span><span class="ident">Chunk</span><span class="op">&gt;</span>,
221+
<span class="doccomment">/// Free chunks are received here to be put on `self.free_chunks`.</span>
196222
<span class="ident">receiver</span>: <span class="ident">mpsc::Receiver</span><span class="op">&lt;</span><span class="ident">Chunk</span><span class="op">&gt;</span>,
197223
}
198224

199225
<span class="kw">impl</span> <span class="ident">StagingBelt</span> {
200226
<span class="doccomment">/// Create a new staging belt.</span>
201227
<span class="doccomment">///</span>
202-
<span class="doccomment">/// The `chunk_size` is the unit of internal buffer allocation.</span>
203-
<span class="doccomment">/// It&#39;s better when it&#39;s big, but ideally still 1-4 times less than</span>
204-
<span class="doccomment">/// the total amount of data uploaded per submission.</span>
228+
<span class="doccomment">/// The `chunk_size` is the unit of internal buffer allocation; writes will be</span>
229+
<span class="doccomment">/// sub-allocated within each chunk. Therefore, for optimal use of memory, the</span>
230+
<span class="doccomment">/// chunk size should be:</span>
231+
<span class="doccomment">///</span>
232+
<span class="doccomment">/// * larger than the largest single [`StagingBelt::write_buffer()`] operation;</span>
233+
<span class="doccomment">/// * 1-4 times less than the total amount of data uploaded per submission</span>
234+
<span class="doccomment">/// (per [`StagingBelt::finish()`]); and</span>
235+
<span class="doccomment">/// * bigger is better, within these bounds.</span>
205236
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">chunk_size</span>: <span class="ident">BufferAddress</span>) -&gt; <span class="self">Self</span> {
206237
<span class="kw">let</span> (<span class="ident">sender</span>, <span class="ident">receiver</span>) <span class="op">=</span> <span class="ident">mpsc::channel</span>();
207238
<span class="ident">StagingBelt</span> {
@@ -218,7 +249,12 @@
218249
<span class="doccomment">/// at the specified offset.</span>
219250
<span class="doccomment">///</span>
220251
<span class="doccomment">/// The upload will be placed into the provided command encoder. This encoder</span>
221-
<span class="doccomment">/// must be submitted after `finish` is called and before `recall` is called.</span>
252+
<span class="doccomment">/// must be submitted after [`StagingBelt::finish()`] is called and before</span>
253+
<span class="doccomment">/// [`StagingBelt::recall()`] is called.</span>
254+
<span class="doccomment">///</span>
255+
<span class="doccomment">/// If the `size` is greater than the size of any free internal buffer, a new buffer</span>
256+
<span class="doccomment">/// will be allocated for it. Therefore, the `chunk_size` passed to [`StagingBelt::new()`]</span>
257+
<span class="doccomment">/// should ideally be larger than every such size.</span>
222258
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">write_buffer</span>(
223259
<span class="kw-2">&amp;mut</span> <span class="self">self</span>,
224260
<span class="ident">encoder</span>: <span class="kw-2">&amp;mut</span> <span class="ident">CommandEncoder</span>,
@@ -268,8 +304,12 @@
268304

269305
<span class="doccomment">/// Prepare currently mapped buffers for use in a submission.</span>
270306
<span class="doccomment">///</span>
271-
<span class="doccomment">/// At this point, all the partially used staging buffers are closed until</span>
272-
<span class="doccomment">/// the GPU is done copying the data from them.</span>
307+
<span class="doccomment">/// This must be called before the command encoder(s) provided to</span>
308+
<span class="doccomment">/// [`StagingBelt::write_buffer()`] are submitted.</span>
309+
<span class="doccomment">///</span>
310+
<span class="doccomment">/// At this point, all the partially used staging buffers are closed (cannot be used for</span>
311+
<span class="doccomment">/// further writes) until after [`StagingBelt::recall()`] is called *and* the GPU is done</span>
312+
<span class="doccomment">/// copying the data from them.</span>
273313
<span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">finish</span>(<span class="kw-2">&amp;mut</span> <span class="self">self</span>) {
274314
<span class="kw">for</span> <span class="ident">chunk</span> <span class="kw">in</span> <span class="self">self</span>.<span class="ident">active_chunks</span>.<span class="ident">drain</span>(..) {
275315
<span class="ident">chunk</span>.<span class="ident">buffer</span>.<span class="ident">unmap</span>();
@@ -279,7 +319,9 @@
279319

280320
<span class="doccomment">/// Recall all of the closed buffers back to be reused.</span>
281321
<span class="doccomment">///</span>
282-
<span class="doccomment">/// This has to be called after the command encoders written to `write_buffer` are submitted!</span>
322+
<span class="doccomment">/// This must only be called after the command encoder(s) provided to</span>
323+
<span class="doccomment">/// [`StagingBelt::write_buffer()`] are submitted. Additional calls are harmless.</span>
324+
<span class="doccomment">/// Not calling this as soon as possible may result in increased buffer memory usage.</span>
283325
<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>) {
284326
<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>() {
285327
<span class="ident">chunk</span>.<span class="ident">offset</span> <span class="op">=</span> <span class="number">0</span>;

‎doc/src/wgpu_hal/gles/mod.rs.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,10 @@
769769
<span id="763">763</span>
770770
<span id="764">764</span>
771771
<span id="765">765</span>
772+
<span id="766">766</span>
773+
<span id="767">767</span>
774+
<span id="768">768</span>
775+
<span id="769">769</span>
772776
</pre><pre class="rust"><code><span class="doccomment">/*!
773777
# OpenGL ES3 API (aka GLES3).
774778

@@ -840,10 +844,14 @@
840844
<span class="kw">mod</span> <span class="ident">queue</span>;
841845

842846
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">any</span>(<span class="ident">not</span>(<span class="ident">target_arch</span> <span class="op">=</span> <span class="string">&quot;wasm32&quot;</span>), <span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;emscripten&quot;</span>))]</span>
843-
<span class="kw">use</span> <span class="ident"><span class="self">self</span>::egl</span>::{<span class="ident">AdapterContext</span>, <span class="ident">Instance</span>, <span class="ident">Surface</span>};
847+
<span class="kw">pub</span> <span class="kw">use</span> <span class="ident"><span class="self">self</span>::egl</span>::{<span class="ident">AdapterContext</span>, <span class="ident">AdapterContextLock</span>};
848+
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">any</span>(<span class="ident">not</span>(<span class="ident">target_arch</span> <span class="op">=</span> <span class="string">&quot;wasm32&quot;</span>), <span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;emscripten&quot;</span>))]</span>
849+
<span class="kw">use</span> <span class="ident"><span class="self">self</span>::egl</span>::{<span class="ident">Instance</span>, <span class="ident">Surface</span>};
844850

845851
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">all</span>(<span class="ident">target_arch</span> <span class="op">=</span> <span class="string">&quot;wasm32&quot;</span>, <span class="ident">not</span>(<span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;emscripten&quot;</span>)))]</span>
846-
<span class="kw">use</span> <span class="ident"><span class="self">self</span>::web</span>::{<span class="ident">AdapterContext</span>, <span class="ident">Instance</span>, <span class="ident">Surface</span>};
852+
<span class="kw">pub</span> <span class="kw">use</span> <span class="ident"><span class="self">self</span>::web::AdapterContext</span>;
853+
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">all</span>(<span class="ident">target_arch</span> <span class="op">=</span> <span class="string">&quot;wasm32&quot;</span>, <span class="ident">not</span>(<span class="ident">feature</span> <span class="op">=</span> <span class="string">&quot;emscripten&quot;</span>)))]</span>
854+
<span class="kw">use</span> <span class="ident"><span class="self">self</span>::web</span>::{<span class="ident">Instance</span>, <span class="ident">Surface</span>};
847855

848856
<span class="kw">use</span> <span class="ident">arrayvec::ArrayVec</span>;
849857

‎doc/wgpu/util/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1 class="fqn"><span class="in-band">Module <a href="../index.html">wgpu</a>::<
1414
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DownloadBuffer.html" title="wgpu::util::DownloadBuffer struct">DownloadBuffer</a></div><div class="item-right docblock-short"><p>CPU accessible buffer used to download data back from the GPU.</p>
1515
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawIndexedIndirect.html" title="wgpu::util::DrawIndexedIndirect struct">DrawIndexedIndirect</a></div><div class="item-right docblock-short"><p>The structure expected in <code>indirect_buffer</code> for <a href="trait.RenderEncoder.html#tymethod.draw_indexed_indirect"><code>RenderEncoder::draw_indexed_indirect</code></a>.</p>
1616
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DrawIndirect.html" title="wgpu::util::DrawIndirect struct">DrawIndirect</a></div><div class="item-right docblock-short"><p>The structure expected in <code>indirect_buffer</code> for <a href="trait.RenderEncoder.html#tymethod.draw_indirect"><code>RenderEncoder::draw_indirect</code></a>.</p>
17-
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.StagingBelt.html" title="wgpu::util::StagingBelt struct">StagingBelt</a></div><div class="item-right docblock-short"><p>Staging belt is a machine that uploads data.</p>
17+
</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.StagingBelt.html" title="wgpu::util::StagingBelt struct">StagingBelt</a></div><div class="item-right docblock-short"><p>Efficiently performs many buffer writes by sharing and reusing temporary buffers.</p>
1818
</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2>
1919
<div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.DeviceExt.html" title="wgpu::util::DeviceExt trait">DeviceExt</a></div><div class="item-right docblock-short"><p>Utility methods not meant to be in the main API.</p>
2020
</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.RenderEncoder.html" title="wgpu::util::RenderEncoder trait">RenderEncoder</a></div><div class="item-right docblock-short"><p>Methods shared by <a href="../struct.RenderPass.html" title="RenderPass"><code>RenderPass</code></a> and <a href="../struct.RenderBundleEncoder.html" title="RenderBundleEncoder"><code>RenderBundleEncoder</code></a>.</p>

‎doc/wgpu/util/sidebar-items.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)