Files
phy/wgpu/util/trait.RenderEncoder.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

106 lines
21 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Methods shared by `RenderPass` and `RenderBundleEncoder`."><title>RenderEncoder in wgpu::util - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="wgpu" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../wgpu/index.html"><img src="https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../wgpu/index.html"><img src="https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png" alt="logo"></a><h2><a href="../../wgpu/index.html">wgpu</a><span class="version">23.0.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Render<wbr>Encoder</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.draw" title="draw">draw</a></li><li><a href="#tymethod.draw_indexed" title="draw_indexed">draw_indexed</a></li><li><a href="#tymethod.draw_indexed_indirect" title="draw_indexed_indirect">draw_indexed_indirect</a></li><li><a href="#tymethod.draw_indirect" title="draw_indirect">draw_indirect</a></li><li><a href="#tymethod.set_bind_group" title="set_bind_group">set_bind_group</a></li><li><a href="#tymethod.set_index_buffer" title="set_index_buffer">set_index_buffer</a></li><li><a href="#tymethod.set_pipeline" title="set_pipeline">set_pipeline</a></li><li><a href="#tymethod.set_push_constants" title="set_push_constants">set_push_constants</a></li><li><a href="#tymethod.set_vertex_buffer" title="set_vertex_buffer">set_vertex_buffer</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In wgpu::<wbr>util</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">wgpu</a>::<wbr><a href="index.html">util</a></span><h1>Trait <span class="trait">RenderEncoder</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/wgpu/util/encoder.rs.html#8-105">Source</a> </span></div><pre class="rust item-decl"><code>pub trait RenderEncoder&lt;'a&gt; {
// Required methods
fn <a href="#tymethod.set_bind_group" class="fn">set_bind_group</a>(
&amp;mut self,
index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
bind_group: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;'a <a class="struct" href="../struct.BindGroup.html" title="struct wgpu::BindGroup">BindGroup</a>&gt;,
offsets: &amp;[<a class="type" href="../type.DynamicOffset.html" title="type wgpu::DynamicOffset">DynamicOffset</a>],
);
<span class="item-spacer"></span> fn <a href="#tymethod.set_pipeline" class="fn">set_pipeline</a>(&amp;mut self, pipeline: &amp;'a <a class="struct" href="../struct.RenderPipeline.html" title="struct wgpu::RenderPipeline">RenderPipeline</a>);
<span class="item-spacer"></span> fn <a href="#tymethod.set_index_buffer" class="fn">set_index_buffer</a>(
&amp;mut self,
buffer_slice: <a class="struct" href="../struct.BufferSlice.html" title="struct wgpu::BufferSlice">BufferSlice</a>&lt;'a&gt;,
index_format: <a class="enum" href="../enum.IndexFormat.html" title="enum wgpu::IndexFormat">IndexFormat</a>,
);
<span class="item-spacer"></span> fn <a href="#tymethod.set_vertex_buffer" class="fn">set_vertex_buffer</a>(&amp;mut self, slot: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, buffer_slice: <a class="struct" href="../struct.BufferSlice.html" title="struct wgpu::BufferSlice">BufferSlice</a>&lt;'a&gt;);
<span class="item-spacer"></span> fn <a href="#tymethod.draw" class="fn">draw</a>(&amp;mut self, vertices: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;, instances: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;);
<span class="item-spacer"></span> fn <a href="#tymethod.draw_indexed" class="fn">draw_indexed</a>(
&amp;mut self,
indices: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;,
base_vertex: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.i32.html">i32</a>,
instances: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;,
);
<span class="item-spacer"></span> fn <a href="#tymethod.draw_indirect" class="fn">draw_indirect</a>(
&amp;mut self,
indirect_buffer: &amp;'a <a class="struct" href="../struct.Buffer.html" title="struct wgpu::Buffer">Buffer</a>,
indirect_offset: <a class="type" href="../type.BufferAddress.html" title="type wgpu::BufferAddress">BufferAddress</a>,
);
<span class="item-spacer"></span> fn <a href="#tymethod.draw_indexed_indirect" class="fn">draw_indexed_indirect</a>(
&amp;mut self,
indirect_buffer: &amp;'a <a class="struct" href="../struct.Buffer.html" title="struct wgpu::Buffer">Buffer</a>,
indirect_offset: <a class="type" href="../type.BufferAddress.html" title="type wgpu::BufferAddress">BufferAddress</a>,
);
<span class="item-spacer"></span> fn <a href="#tymethod.set_push_constants" class="fn">set_push_constants</a>(
&amp;mut self,
stages: <a class="struct" href="../struct.ShaderStages.html" title="struct wgpu::ShaderStages">ShaderStages</a>,
offset: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
data: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>],
);
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Methods shared by <a href="../struct.RenderPass.html" title="struct wgpu::RenderPass"><code>RenderPass</code></a> and <a href="../struct.RenderBundleEncoder.html" title="struct wgpu::RenderBundleEncoder"><code>RenderBundleEncoder</code></a>.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.set_bind_group" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#13-18">Source</a><h4 class="code-header">fn <a href="#tymethod.set_bind_group" class="fn">set_bind_group</a>(
&amp;mut self,
index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
bind_group: <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;'a <a class="struct" href="../struct.BindGroup.html" title="struct wgpu::BindGroup">BindGroup</a>&gt;,
offsets: &amp;[<a class="type" href="../type.DynamicOffset.html" title="type wgpu::DynamicOffset">DynamicOffset</a>],
)</h4></section></summary><div class="docblock"><p>Sets the active bind group for a given bind group index. The bind group layout
in the active pipeline when any <code>draw()</code> function is called must match the layout of this bind group.</p>
<p>If the bind group have dynamic offsets, provide them in order of their declaration.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.set_pipeline" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#23">Source</a><h4 class="code-header">fn <a href="#tymethod.set_pipeline" class="fn">set_pipeline</a>(&amp;mut self, pipeline: &amp;'a <a class="struct" href="../struct.RenderPipeline.html" title="struct wgpu::RenderPipeline">RenderPipeline</a>)</h4></section></summary><div class="docblock"><p>Sets the active render pipeline.</p>
<p>Subsequent draw calls will exhibit the behavior defined by <code>pipeline</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.set_index_buffer" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#29">Source</a><h4 class="code-header">fn <a href="#tymethod.set_index_buffer" class="fn">set_index_buffer</a>(
&amp;mut self,
buffer_slice: <a class="struct" href="../struct.BufferSlice.html" title="struct wgpu::BufferSlice">BufferSlice</a>&lt;'a&gt;,
index_format: <a class="enum" href="../enum.IndexFormat.html" title="enum wgpu::IndexFormat">IndexFormat</a>,
)</h4></section></summary><div class="docblock"><p>Sets the active index buffer.</p>
<p>Subsequent calls to <a href="trait.RenderEncoder.html#tymethod.draw_indexed" title="method wgpu::util::RenderEncoder::draw_indexed"><code>draw_indexed</code></a> on this <a href="trait.RenderEncoder.html" title="trait wgpu::util::RenderEncoder"><code>RenderEncoder</code></a> will
use <code>buffer</code> as the source index buffer.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.set_vertex_buffer" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#41">Source</a><h4 class="code-header">fn <a href="#tymethod.set_vertex_buffer" class="fn">set_vertex_buffer</a>(&amp;mut self, slot: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, buffer_slice: <a class="struct" href="../struct.BufferSlice.html" title="struct wgpu::BufferSlice">BufferSlice</a>&lt;'a&gt;)</h4></section></summary><div class="docblock"><p>Assign a vertex buffer to a slot.</p>
<p>Subsequent calls to <a href="trait.RenderEncoder.html#tymethod.draw" title="method wgpu::util::RenderEncoder::draw"><code>draw</code></a> and <a href="trait.RenderEncoder.html#tymethod.draw_indexed" title="method wgpu::util::RenderEncoder::draw_indexed"><code>draw_indexed</code></a> on this
<a href="trait.RenderEncoder.html" title="trait wgpu::util::RenderEncoder"><code>RenderEncoder</code></a> will use <code>buffer</code> as one of the source vertex buffers.</p>
<p>The <code>slot</code> refers to the index of the matching descriptor in
<a href="../struct.VertexState.html#structfield.buffers" title="field wgpu::VertexState::buffers">VertexState::buffers</a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.draw" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#46">Source</a><h4 class="code-header">fn <a href="#tymethod.draw" class="fn">draw</a>(&amp;mut self, vertices: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;, instances: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;)</h4></section></summary><div class="docblock"><p>Draws primitives from the active vertex buffer(s).</p>
<p>The active vertex buffers can be set with <a href="trait.RenderEncoder.html#tymethod.set_vertex_buffer" title="method wgpu::util::RenderEncoder::set_vertex_buffer"><code>RenderEncoder::set_vertex_buffer</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.draw_indexed" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#52">Source</a><h4 class="code-header">fn <a href="#tymethod.draw_indexed" class="fn">draw_indexed</a>(
&amp;mut self,
indices: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;,
base_vertex: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.i32.html">i32</a>,
instances: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/ops/range/struct.Range.html" title="struct core::ops::range::Range">Range</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>&gt;,
)</h4></section></summary><div class="docblock"><p>Draws indexed primitives using the active index buffer and the active vertex buffers.</p>
<p>The active index buffer can be set with <a href="trait.RenderEncoder.html#tymethod.set_index_buffer" title="method wgpu::util::RenderEncoder::set_index_buffer"><code>RenderEncoder::set_index_buffer</code></a>, while the active
vertex buffers can be set with <a href="trait.RenderEncoder.html#tymethod.set_vertex_buffer" title="method wgpu::util::RenderEncoder::set_vertex_buffer"><code>RenderEncoder::set_vertex_buffer</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.draw_indirect" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#59">Source</a><h4 class="code-header">fn <a href="#tymethod.draw_indirect" class="fn">draw_indirect</a>(
&amp;mut self,
indirect_buffer: &amp;'a <a class="struct" href="../struct.Buffer.html" title="struct wgpu::Buffer">Buffer</a>,
indirect_offset: <a class="type" href="../type.BufferAddress.html" title="type wgpu::BufferAddress">BufferAddress</a>,
)</h4></section></summary><div class="docblock"><p>Draws primitives from the active vertex buffer(s) based on the contents of the <code>indirect_buffer</code>.</p>
<p>The active vertex buffers can be set with <a href="trait.RenderEncoder.html#tymethod.set_vertex_buffer" title="method wgpu::util::RenderEncoder::set_vertex_buffer"><code>RenderEncoder::set_vertex_buffer</code></a>.</p>
<p>The structure expected in <code>indirect_buffer</code> must conform to <a href="struct.DrawIndirectArgs.html" title="struct wgpu::util::DrawIndirectArgs"><code>DrawIndirectArgs</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.draw_indexed_indirect" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#68-72">Source</a><h4 class="code-header">fn <a href="#tymethod.draw_indexed_indirect" class="fn">draw_indexed_indirect</a>(
&amp;mut self,
indirect_buffer: &amp;'a <a class="struct" href="../struct.Buffer.html" title="struct wgpu::Buffer">Buffer</a>,
indirect_offset: <a class="type" href="../type.BufferAddress.html" title="type wgpu::BufferAddress">BufferAddress</a>,
)</h4></section></summary><div class="docblock"><p>Draws indexed primitives using the active index buffer and the active vertex buffers,
based on the contents of the <code>indirect_buffer</code>.</p>
<p>The active index buffer can be set with <a href="trait.RenderEncoder.html#tymethod.set_index_buffer" title="method wgpu::util::RenderEncoder::set_index_buffer"><code>RenderEncoder::set_index_buffer</code></a>, while the active
vertex buffers can be set with <a href="trait.RenderEncoder.html#tymethod.set_vertex_buffer" title="method wgpu::util::RenderEncoder::set_vertex_buffer"><code>RenderEncoder::set_vertex_buffer</code></a>.</p>
<p>The structure expected in <code>indirect_buffer</code> must conform to <a href="struct.DrawIndexedIndirectArgs.html" title="struct wgpu::util::DrawIndexedIndirectArgs"><code>DrawIndexedIndirectArgs</code></a>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.set_push_constants" class="method"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#104">Source</a><h4 class="code-header">fn <a href="#tymethod.set_push_constants" class="fn">set_push_constants</a>(&amp;mut self, stages: <a class="struct" href="../struct.ShaderStages.html" title="struct wgpu::ShaderStages">ShaderStages</a>, offset: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, data: &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>])</h4></section></summary><div class="docblock"><p><a href="../struct.Features.html#associatedconstant.PUSH_CONSTANTS" title="associated constant wgpu::Features::PUSH_CONSTANTS"><code>wgt::Features::PUSH_CONSTANTS</code></a> must be enabled on the device in order to call this function.</p>
<p>Set push constant data.</p>
<p>Offset is measured in bytes, but must be a multiple of <a href="../constant.PUSH_CONSTANT_ALIGNMENT.html" title="constant wgpu::PUSH_CONSTANT_ALIGNMENT"><code>wgt::PUSH_CONSTANT_ALIGNMENT</code></a>.</p>
<p>Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32.
For example, with an offset of 4 and an array of <code>[u32; 3]</code>, that will write to the range
of 4..16.</p>
<p>For each byte in the range of push constant data written, the union of the stages of all push constant
ranges that covers that byte must be exactly <code>stages</code>. Theres no good way of explaining this simply,
so here are some examples:</p>
<div class="example-wrap"><pre class="language-text"><code>For the given ranges:
- 0..4 Vertex
- 4..8 Fragment</code></pre></div>
<p>You would need to upload this in two set_push_constants calls. First for the <code>Vertex</code> range, second for the <code>Fragment</code> range.</p>
<div class="example-wrap"><pre class="language-text"><code>For the given ranges:
- 0..8 Vertex
- 4..12 Fragment</code></pre></div>
<p>You would need to upload this in three set_push_constants calls. First for the <code>Vertex</code> only range 0..4, second
for the <code>Vertex | Fragment</code> range 4..8, third for the <code>Fragment</code> range 8..12.</p>
</div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-RenderEncoder%3C'a%3E-for-RenderBundleEncoder%3C'a%3E" class="impl"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#163-217">Source</a><a href="#impl-RenderEncoder%3C'a%3E-for-RenderBundleEncoder%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.RenderEncoder.html" title="trait wgpu::util::RenderEncoder">RenderEncoder</a>&lt;'a&gt; for <a class="struct" href="../struct.RenderBundleEncoder.html" title="struct wgpu::RenderBundleEncoder">RenderBundleEncoder</a>&lt;'a&gt;</h3></section><section id="impl-RenderEncoder%3C'a%3E-for-RenderPass%3C'a%3E" class="impl"><a class="src rightside" href="../../src/wgpu/util/encoder.rs.html#107-161">Source</a><a href="#impl-RenderEncoder%3C'a%3E-for-RenderPass%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="trait.RenderEncoder.html" title="trait wgpu::util::RenderEncoder">RenderEncoder</a>&lt;'a&gt; for <a class="struct" href="../struct.RenderPass.html" title="struct wgpu::RenderPass">RenderPass</a>&lt;'a&gt;</h3></section></div><script src="../../trait.impl/wgpu/util/encoder/trait.RenderEncoder.js" async></script></section></div></main></body></html>