Skip to content

Commit 0a2ba5c

Browse files
committed
Deploying to master from @ gfx-rs/wgpu@dc924bc 🚀
1 parent cb79088 commit 0a2ba5c

File tree

446 files changed

+1968
-1405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

446 files changed

+1968
-1405
lines changed

doc/search-index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/search.desc/wgpu/wgpu-desc-1-.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/search.desc/wgpu_core/wgpu_core-desc-0-.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/search.desc/wgpu_hal/wgpu_hal-desc-0-.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/api/device.rs.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@
778778
<a href="#777" id="777">777</a>
779779
<a href="#778" id="778">778</a>
780780
<a href="#779" id="779">779</a>
781-
<a href="#780" id="780">780</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{boxed::Box, string::String, sync::Arc, vec};
781+
<a href="#780" id="780">780</a>
782+
<a href="#781" id="781">781</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{boxed::Box, string::String, sync::Arc, vec};
782783
<span class="attr">#[cfg(wgpu_core)]
783784
</span><span class="kw">use </span>core::ops::Deref;
784785
<span class="kw">use </span>core::{error, fmt, future::Future};
@@ -1104,6 +1105,7 @@
11041105
/// - `hal_buffer` must be created from this device internal handle
11051106
/// - `hal_buffer` must be created respecting `desc`
11061107
/// - `hal_buffer` must be initialized
1108+
/// - `hal_buffer` must not have zero size
11071109
</span><span class="attr">#[cfg(wgpu_core)]
11081110
#[must_use]
11091111
</span><span class="kw">pub unsafe fn </span>create_buffer_from_hal&lt;A: wgc::hal_api::HalApi&gt;(

doc/src/wgpu/backend/wgpu_core.rs.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,7 +3643,13 @@
36433643
<a href="#3642" id="3642">3642</a>
36443644
<a href="#3643" id="3643">3643</a>
36453645
<a href="#3644" id="3644">3644</a>
3646-
<a href="#3645" id="3645">3645</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{
3646+
<a href="#3645" id="3645">3645</a>
3647+
<a href="#3646" id="3646">3646</a>
3648+
<a href="#3647" id="3647">3647</a>
3649+
<a href="#3648" id="3648">3648</a>
3650+
<a href="#3649" id="3649">3649</a>
3651+
<a href="#3650" id="3650">3650</a>
3652+
<a href="#3651" id="3651">3651</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{
36473653
borrow::Cow::{<span class="self">self</span>, Borrowed},
36483654
boxed::Box,
36493655
format,
@@ -3811,7 +3817,13 @@
38113817
}
38123818
}
38133819

3814-
<span class="kw">pub unsafe fn </span>create_buffer_from_hal&lt;A: wgc::hal_api::HalApi&gt;(
3820+
<span class="doccomment">/// # Safety
3821+
///
3822+
/// - `hal_buffer` must be created from `device`.
3823+
/// - `hal_buffer` must be created respecting `desc`
3824+
/// - `hal_buffer` must be initialized
3825+
/// - `hal_buffer` must not have zero size.
3826+
</span><span class="kw">pub unsafe fn </span>create_buffer_from_hal&lt;A: wgc::hal_api::HalApi&gt;(
38153827
<span class="kw-2">&amp;</span><span class="self">self</span>,
38163828
hal_buffer: A::Buffer,
38173829
device: <span class="kw-2">&amp;</span>CoreDevice,

doc/src/wgpu_core/binding_model.rs.html

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,34 @@
12371237
<a href="#1236" id="1236">1236</a>
12381238
<a href="#1237" id="1237">1237</a>
12391239
<a href="#1238" id="1238">1238</a>
1240-
<a href="#1239" id="1239">1239</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{
1240+
<a href="#1239" id="1239">1239</a>
1241+
<a href="#1240" id="1240">1240</a>
1242+
<a href="#1241" id="1241">1241</a>
1243+
<a href="#1242" id="1242">1242</a>
1244+
<a href="#1243" id="1243">1243</a>
1245+
<a href="#1244" id="1244">1244</a>
1246+
<a href="#1245" id="1245">1245</a>
1247+
<a href="#1246" id="1246">1246</a>
1248+
<a href="#1247" id="1247">1247</a>
1249+
<a href="#1248" id="1248">1248</a>
1250+
<a href="#1249" id="1249">1249</a>
1251+
<a href="#1250" id="1250">1250</a>
1252+
<a href="#1251" id="1251">1251</a>
1253+
<a href="#1252" id="1252">1252</a>
1254+
<a href="#1253" id="1253">1253</a>
1255+
<a href="#1254" id="1254">1254</a>
1256+
<a href="#1255" id="1255">1255</a>
1257+
<a href="#1256" id="1256">1256</a>
1258+
<a href="#1257" id="1257">1257</a>
1259+
<a href="#1258" id="1258">1258</a>
1260+
<a href="#1259" id="1259">1259</a>
1261+
<a href="#1260" id="1260">1260</a>
1262+
<a href="#1261" id="1261">1261</a>
1263+
<a href="#1262" id="1262">1262</a>
1264+
<a href="#1263" id="1263">1263</a>
1265+
<a href="#1264" id="1264">1264</a>
1266+
<a href="#1265" id="1265">1265</a>
1267+
<a href="#1266" id="1266">1266</a></pre></div><pre class="rust"><code><span class="kw">use </span>alloc::{
12411268
borrow::{Cow, ToOwned},
12421269
boxed::Box,
12431270
string::String,
@@ -1334,15 +1361,48 @@
13341361
}
13351362
}
13361363

1337-
<span class="comment">//TODO: refactor this to move out `enum BindingError`.
1364+
<span class="attr">#[derive(Clone, Debug, Error)]
1365+
#[non_exhaustive]
1366+
</span><span class="kw">pub enum </span>BindingError {
1367+
<span class="attr">#[error(transparent)]
1368+
</span>DestroyedResource(<span class="attr">#[from] </span>DestroyedResourceError),
1369+
<span class="attr">#[error(<span class="string">"Buffer {buffer}: Binding with size {binding_size} at offset {offset} would overflow buffer size of {buffer_size}"</span>)]
1370+
</span>BindingRangeTooLarge {
1371+
buffer: ResourceErrorIdent,
1372+
offset: wgt::BufferAddress,
1373+
binding_size: u64,
1374+
buffer_size: u64,
1375+
},
1376+
<span class="attr">#[error(<span class="string">"Buffer {buffer}: Binding offset {offset} is greater than buffer size {buffer_size}"</span>)]
1377+
</span>BindingOffsetTooLarge {
1378+
buffer: ResourceErrorIdent,
1379+
offset: wgt::BufferAddress,
1380+
buffer_size: u64,
1381+
},
1382+
}
13381383

1384+
<span class="kw">impl </span>WebGpuError <span class="kw">for </span>BindingError {
1385+
<span class="kw">fn </span>webgpu_error_type(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; ErrorType {
1386+
<span class="kw">match </span><span class="self">self </span>{
1387+
<span class="self">Self</span>::DestroyedResource(e) =&gt; e.webgpu_error_type(),
1388+
<span class="self">Self</span>::BindingRangeTooLarge { .. } | <span class="self">Self</span>::BindingOffsetTooLarge { .. } =&gt; {
1389+
ErrorType::Validation
1390+
}
1391+
}
1392+
}
1393+
}
1394+
1395+
<span class="comment">// TODO: there may be additional variants here that can be extracted into
1396+
// `BindingError`.
13391397
</span><span class="attr">#[derive(Clone, Debug, Error)]
13401398
#[non_exhaustive]
13411399
</span><span class="kw">pub enum </span>CreateBindGroupError {
13421400
<span class="attr">#[error(transparent)]
13431401
</span>Device(<span class="attr">#[from] </span>DeviceError),
13441402
<span class="attr">#[error(transparent)]
13451403
</span>DestroyedResource(<span class="attr">#[from] </span>DestroyedResourceError),
1404+
<span class="attr">#[error(transparent)]
1405+
</span>BindingError(<span class="attr">#[from] </span>BindingError),
13461406
<span class="attr">#[error(
13471407
<span class="string">"Binding count declared with at most {expected} items, but {actual} items were provided"
13481408
</span>)]
@@ -1353,12 +1413,6 @@
13531413
</span>BindingArrayLengthMismatch { actual: usize, expected: usize },
13541414
<span class="attr">#[error(<span class="string">"Array binding provided zero elements"</span>)]
13551415
</span>BindingArrayZeroLength,
1356-
<span class="attr">#[error(<span class="string">"The bound range {range:?} of {buffer} overflows its size ({size})"</span>)]
1357-
</span>BindingRangeTooLarge {
1358-
buffer: ResourceErrorIdent,
1359-
range: Range&lt;wgt::BufferAddress&gt;,
1360-
size: u64,
1361-
},
13621416
<span class="attr">#[error(<span class="string">"Binding size {actual} of {buffer} is less than minimum {min}"</span>)]
13631417
</span>BindingSizeTooSmall {
13641418
buffer: ResourceErrorIdent,
@@ -1473,14 +1527,14 @@
14731527
<span class="kw">let </span>e: <span class="kw-2">&amp;</span><span class="kw">dyn </span>WebGpuError = <span class="kw">match </span><span class="self">self </span>{
14741528
<span class="self">Self</span>::Device(e) =&gt; e,
14751529
<span class="self">Self</span>::DestroyedResource(e) =&gt; e,
1530+
<span class="self">Self</span>::BindingError(e) =&gt; e,
14761531
<span class="self">Self</span>::MissingBufferUsage(e) =&gt; e,
14771532
<span class="self">Self</span>::MissingTextureUsage(e) =&gt; e,
14781533
<span class="self">Self</span>::ResourceUsageCompatibility(e) =&gt; e,
14791534
<span class="self">Self</span>::InvalidResource(e) =&gt; e,
14801535
<span class="self">Self</span>::BindingArrayPartialLengthMismatch { .. }
14811536
| <span class="self">Self</span>::BindingArrayLengthMismatch { .. }
14821537
| <span class="self">Self</span>::BindingArrayZeroLength
1483-
| <span class="self">Self</span>::BindingRangeTooLarge { .. }
14841538
| <span class="self">Self</span>::BindingSizeTooSmall { .. }
14851539
| <span class="self">Self</span>::BindingsNumMismatch { .. }
14861540
| <span class="self">Self</span>::BindingZeroSize(<span class="kw">_</span>)

doc/src/wgpu_core/command/bundle.rs.html

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,26 @@
17621762
<a href="#1761" id="1761">1761</a>
17631763
<a href="#1762" id="1762">1762</a>
17641764
<a href="#1763" id="1763">1763</a>
1765-
<a href="#1764" id="1764">1764</a></pre></div><pre class="rust"><code><span class="doccomment">/*! Render Bundles
1765+
<a href="#1764" id="1764">1764</a>
1766+
<a href="#1765" id="1765">1765</a>
1767+
<a href="#1766" id="1766">1766</a>
1768+
<a href="#1767" id="1767">1767</a>
1769+
<a href="#1768" id="1768">1768</a>
1770+
<a href="#1769" id="1769">1769</a>
1771+
<a href="#1770" id="1770">1770</a>
1772+
<a href="#1771" id="1771">1771</a>
1773+
<a href="#1772" id="1772">1772</a>
1774+
<a href="#1773" id="1773">1773</a>
1775+
<a href="#1774" id="1774">1774</a>
1776+
<a href="#1775" id="1775">1775</a>
1777+
<a href="#1776" id="1776">1776</a>
1778+
<a href="#1777" id="1777">1777</a>
1779+
<a href="#1778" id="1778">1778</a>
1780+
<a href="#1779" id="1779">1779</a>
1781+
<a href="#1780" id="1780">1780</a>
1782+
<a href="#1781" id="1781">1781</a>
1783+
<a href="#1782" id="1782">1782</a>
1784+
<a href="#1783" id="1783">1783</a></pre></div><pre class="rust"><code><span class="doccomment">/*! Render Bundles
17661785

17671786
A render bundle is a prerecorded sequence of commands that can be replayed on a
17681787
command encoder with a single call. A single bundle can replayed any number of
@@ -1857,6 +1876,7 @@
18571876
<span class="kw">use </span>arrayvec::ArrayVec;
18581877
<span class="kw">use </span>thiserror::Error;
18591878

1879+
<span class="kw">use </span>wgpu_hal::ShouldBeNonZeroExt;
18601880
<span class="kw">use </span>wgt::error::{ErrorType, WebGpuError};
18611881

18621882
<span class="kw">use crate</span>::{
@@ -2366,7 +2386,8 @@
23662386
<span class="prelude-val">Ok</span>(())
23672387
}
23682388

2369-
<span class="kw">fn </span>set_index_buffer(
2389+
<span class="comment">// This function is duplicative of `render::set_index_buffer`.
2390+
</span><span class="kw">fn </span>set_index_buffer(
23702391
state: <span class="kw-2">&amp;mut </span>State,
23712392
buffer_guard: <span class="kw-2">&amp;</span><span class="kw">crate</span>::storage::Storage&lt;Fallible&lt;Buffer&gt;&gt;,
23722393
buffer_id: id::Id&lt;id::markers::Buffer&gt;,
@@ -2384,22 +2405,21 @@
23842405
buffer.same_device(<span class="kw-2">&amp;</span>state.device)<span class="question-mark">?</span>;
23852406
buffer.check_usage(wgt::BufferUsages::INDEX)<span class="question-mark">?</span>;
23862407

2387-
<span class="kw">let </span>end = <span class="kw">match </span>size {
2388-
<span class="prelude-val">Some</span>(s) =&gt; offset + s.get(),
2389-
<span class="prelude-val">None </span>=&gt; buffer.size,
2390-
};
2408+
<span class="kw">let </span>end = offset + buffer.resolve_binding_size(offset, size)<span class="question-mark">?</span>;
2409+
23912410
state
23922411
.buffer_memory_init_actions
23932412
.extend(buffer.initialization_status.read().create_action(
23942413
<span class="kw-2">&amp;</span>buffer,
2395-
offset..end,
2414+
offset..end.get(),
23962415
MemoryInitKind::NeedsInitializedMemory,
23972416
));
2398-
state.set_index_buffer(buffer, index_format, offset..end);
2417+
state.set_index_buffer(buffer, index_format, offset..end.get());
23992418
<span class="prelude-val">Ok</span>(())
24002419
}
24012420

2402-
<span class="kw">fn </span>set_vertex_buffer(
2421+
<span class="comment">// This function is duplicative of `render::set_vertex_buffer`.
2422+
</span><span class="kw">fn </span>set_vertex_buffer(
24032423
state: <span class="kw-2">&amp;mut </span>State,
24042424
buffer_guard: <span class="kw-2">&amp;</span><span class="kw">crate</span>::storage::Storage&lt;Fallible&lt;Buffer&gt;&gt;,
24052425
slot: u32,
@@ -2426,18 +2446,16 @@
24262446
buffer.same_device(<span class="kw-2">&amp;</span>state.device)<span class="question-mark">?</span>;
24272447
buffer.check_usage(wgt::BufferUsages::VERTEX)<span class="question-mark">?</span>;
24282448

2429-
<span class="kw">let </span>end = <span class="kw">match </span>size {
2430-
<span class="prelude-val">Some</span>(s) =&gt; offset + s.get(),
2431-
<span class="prelude-val">None </span>=&gt; buffer.size,
2432-
};
2449+
<span class="kw">let </span>end = offset + buffer.resolve_binding_size(offset, size)<span class="question-mark">?</span>;
2450+
24332451
state
24342452
.buffer_memory_init_actions
24352453
.extend(buffer.initialization_status.read().create_action(
24362454
<span class="kw-2">&amp;</span>buffer,
2437-
offset..end,
2455+
offset..end.get(),
24382456
MemoryInitKind::NeedsInitializedMemory,
24392457
));
2440-
state.vertex[slot <span class="kw">as </span>usize] = <span class="prelude-val">Some</span>(VertexState::new(buffer, offset..end));
2458+
state.vertex[slot <span class="kw">as </span>usize] = <span class="prelude-val">Some</span>(VertexState::new(buffer, offset..end.get()));
24412459
<span class="prelude-val">Ok</span>(())
24422460
}
24432461

@@ -2729,11 +2747,9 @@
27292747
size,
27302748
} =&gt; {
27312749
<span class="kw">let </span>buffer = buffer.try_raw(snatch_guard)<span class="question-mark">?</span>;
2732-
<span class="kw">let </span>bb = hal::BufferBinding {
2733-
buffer,
2734-
offset: <span class="kw-2">*</span>offset,
2735-
size: <span class="kw-2">*</span>size,
2736-
};
2750+
<span class="comment">// SAFETY: The binding size was checked against the buffer size
2751+
// in `set_index_buffer` and again in `IndexState::flush`.
2752+
</span><span class="kw">let </span>bb = hal::BufferBinding::new_unchecked(buffer, <span class="kw-2">*</span>offset, <span class="kw-2">*</span>size);
27372753
<span class="kw">unsafe </span>{ raw.set_index_buffer(bb, <span class="kw-2">*</span>index_format) };
27382754
}
27392755
Cmd::SetVertexBuffer {
@@ -2743,11 +2759,9 @@
27432759
size,
27442760
} =&gt; {
27452761
<span class="kw">let </span>buffer = buffer.try_raw(snatch_guard)<span class="question-mark">?</span>;
2746-
<span class="kw">let </span>bb = hal::BufferBinding {
2747-
buffer,
2748-
offset: <span class="kw-2">*</span>offset,
2749-
size: <span class="kw-2">*</span>size,
2750-
};
2762+
<span class="comment">// SAFETY: The binding size was checked against the buffer size
2763+
// in `set_vertex_buffer` and again in `VertexState::flush`.
2764+
</span><span class="kw">let </span>bb = hal::BufferBinding::new_unchecked(buffer, <span class="kw-2">*</span>offset, <span class="kw-2">*</span>size);
27512765
<span class="kw">unsafe </span>{ raw.set_vertex_buffer(<span class="kw-2">*</span>slot, bb) };
27522766
}
27532767
Cmd::SetPushConstant {
@@ -2895,6 +2909,9 @@
28952909
/// [`RenderBundleEncoder::finish`] records the currently set index buffer here,
28962910
/// and calls [`State::flush_index`] before any indexed draw command to produce
28972911
/// a `SetIndexBuffer` command if one is necessary.
2912+
///
2913+
/// Binding ranges must be validated against the size of the buffer before
2914+
/// being stored in `IndexState`.
28982915
</span><span class="attr">#[derive(Debug)]
28992916
</span><span class="kw">struct </span>IndexState {
29002917
buffer: Arc&lt;Buffer&gt;,
@@ -2916,13 +2933,21 @@
29162933
<span class="doccomment">/// Generate a `SetIndexBuffer` command to prepare for an indexed draw
29172934
/// command, if needed.
29182935
</span><span class="kw">fn </span>flush(<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="prelude-ty">Option</span>&lt;ArcRenderCommand&gt; {
2936+
<span class="comment">// This was all checked before, but let's check again just in case.
2937+
</span><span class="kw">let </span>binding_size = <span class="self">self
2938+
</span>.range
2939+
.end
2940+
.checked_sub(<span class="self">self</span>.range.start)
2941+
.filter(|<span class="kw">_</span>| <span class="self">self</span>.range.end &lt;= <span class="self">self</span>.buffer.size)
2942+
.expect(<span class="string">"index range must be contained in buffer"</span>);
2943+
29192944
<span class="kw">if </span><span class="self">self</span>.is_dirty {
29202945
<span class="self">self</span>.is_dirty = <span class="bool-val">false</span>;
29212946
<span class="prelude-val">Some</span>(ArcRenderCommand::SetIndexBuffer {
29222947
buffer: <span class="self">self</span>.buffer.clone(),
29232948
index_format: <span class="self">self</span>.format,
29242949
offset: <span class="self">self</span>.range.start,
2925-
size: wgt::BufferSize::new(<span class="self">self</span>.range.end - <span class="self">self</span>.range.start),
2950+
size: NonZeroU64::new(binding_size),
29262951
})
29272952
} <span class="kw">else </span>{
29282953
<span class="prelude-val">None
@@ -2938,6 +2963,9 @@
29382963
/// calls this type's [`flush`] method just before any draw command to
29392964
/// produce a `SetVertexBuffer` commands if one is necessary.
29402965
///
2966+
/// Binding ranges must be validated against the size of the buffer before
2967+
/// being stored in `VertexState`.
2968+
///
29412969
/// [`flush`]: IndexState::flush
29422970
</span><span class="attr">#[derive(Debug)]
29432971
</span><span class="kw">struct </span>VertexState {
@@ -2947,7 +2975,10 @@
29472975
}
29482976

29492977
<span class="kw">impl </span>VertexState {
2950-
<span class="kw">fn </span>new(buffer: Arc&lt;Buffer&gt;, range: Range&lt;wgt::BufferAddress&gt;) -&gt; <span class="self">Self </span>{
2978+
<span class="doccomment">/// Create a new `VertexState`.
2979+
///
2980+
/// The `range` must be contained within `buffer`.
2981+
</span><span class="kw">fn </span>new(buffer: Arc&lt;Buffer&gt;, range: Range&lt;wgt::BufferAddress&gt;) -&gt; <span class="self">Self </span>{
29512982
<span class="self">Self </span>{
29522983
buffer,
29532984
range,
@@ -2959,13 +2990,20 @@
29592990
///
29602991
/// `slot` is the index of the vertex buffer slot that `self` tracks.
29612992
</span><span class="kw">fn </span>flush(<span class="kw-2">&amp;mut </span><span class="self">self</span>, slot: u32) -&gt; <span class="prelude-ty">Option</span>&lt;ArcRenderCommand&gt; {
2993+
<span class="kw">let </span>binding_size = <span class="self">self
2994+
</span>.range
2995+
.end
2996+
.checked_sub(<span class="self">self</span>.range.start)
2997+
.filter(|<span class="kw">_</span>| <span class="self">self</span>.range.end &lt;= <span class="self">self</span>.buffer.size)
2998+
.expect(<span class="string">"vertex range must be contained in buffer"</span>);
2999+
29623000
<span class="kw">if </span><span class="self">self</span>.is_dirty {
29633001
<span class="self">self</span>.is_dirty = <span class="bool-val">false</span>;
29643002
<span class="prelude-val">Some</span>(ArcRenderCommand::SetVertexBuffer {
29653003
slot,
29663004
buffer: <span class="self">self</span>.buffer.clone(),
29673005
offset: <span class="self">self</span>.range.start,
2968-
size: wgt::BufferSize::new(<span class="self">self</span>.range.end - <span class="self">self</span>.range.start),
3006+
size: NonZeroU64::new(binding_size),
29693007
})
29703008
} <span class="kw">else </span>{
29713009
<span class="prelude-val">None

0 commit comments

Comments
 (0)