|
1241 | 1241 | <a href="#1240" id="1240">1240</a> |
1242 | 1242 | <a href="#1241" id="1241">1241</a> |
1243 | 1243 | <a href="#1242" id="1242">1242</a> |
1244 | | -<a href="#1243" id="1243">1243</a></pre></div><pre class="rust"><code><span class="kw">mod </span>allocator; |
| 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> |
| 1268 | +<a href="#1267" id="1267">1267</a> |
| 1269 | +<a href="#1268" id="1268">1268</a></pre></div><pre class="rust"><code><span class="kw">mod </span>allocator; |
1245 | 1270 | <span class="kw">mod </span>bind; |
1246 | 1271 | <span class="kw">mod </span>bundle; |
1247 | 1272 | <span class="kw">mod </span>clear; |
|
1280 | 1305 | <span class="kw">use </span><span class="kw">crate</span>::snatch::SnatchGuard; |
1281 | 1306 |
|
1282 | 1307 | <span class="kw">use </span><span class="kw">crate</span>::init_tracker::BufferInitTrackerAction; |
1283 | | -<span class="kw">use </span><span class="kw">crate</span>::ray_tracing::AsAction; |
| 1308 | +<span class="kw">use </span><span class="kw">crate</span>::ray_tracing::{AsAction, BuildAccelerationStructureError}; |
1284 | 1309 | <span class="kw">use </span><span class="kw">crate</span>::resource::{ |
1285 | 1310 | DestroyedResourceError, Fallible, InvalidResourceError, Labeled, ParentDevice <span class="kw">as _</span>, QuerySet, |
1286 | 1311 | }; |
|
1349 | 1374 | } |
1350 | 1375 |
|
1351 | 1376 | <span class="kw">impl </span>CommandEncoderStatus { |
1352 | | - <span class="doccomment">/// Checks that the encoder is in the [`Self::Recording`] state. |
1353 | | - </span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>record(<span class="kw-2">&mut </span><span class="self">self</span>) -> <span class="prelude-ty">Result</span><RecordingGuard<<span class="lifetime">'_</span>>, EncoderStateError> { |
1354 | | - <span class="kw">match </span><span class="self">self </span>{ |
1355 | | - <span class="self">Self</span>::Recording(<span class="kw">_</span>) => <span class="prelude-val">Ok</span>(RecordingGuard { inner: <span class="self">self </span>}), |
1356 | | - <span class="self">Self</span>::Locked(<span class="kw">_</span>) => <span class="prelude-val">Err</span>(<span class="self">self</span>.invalidate(EncoderStateError::Locked)), |
1357 | | - <span class="self">Self</span>::Finished(<span class="kw">_</span>) => <span class="prelude-val">Err</span>(EncoderStateError::Ended), |
1358 | | - <span class="self">Self</span>::Error(<span class="kw">_</span>) => <span class="prelude-val">Err</span>(EncoderStateError::Invalid), |
1359 | | - <span class="self">Self</span>::Transitioning => <span class="macro">unreachable!</span>(), |
1360 | | - } |
1361 | | - } |
1362 | | - |
1363 | 1377 | <span class="doccomment">/// Record commands using the supplied closure. |
1364 | 1378 | /// |
1365 | 1379 | /// If the encoder is in the [`Self::Recording`] state, calls the closure to |
|
1381 | 1395 | <span class="kw-2">&mut </span><span class="self">self</span>, |
1382 | 1396 | f: F, |
1383 | 1397 | ) -> <span class="prelude-ty">Result</span><(), EncoderStateError> { |
1384 | | - <span class="kw">let </span>err = <span class="kw">match </span><span class="self">self</span>.record() { |
1385 | | - <span class="prelude-val">Ok</span>(guard) => { |
1386 | | - guard.record(f); |
1387 | | - <span class="kw">return </span><span class="prelude-val">Ok</span>(()); |
| 1398 | + <span class="kw">match </span><span class="self">self </span>{ |
| 1399 | + <span class="self">Self</span>::Recording(<span class="kw">_</span>) => { |
| 1400 | + RecordingGuard { inner: <span class="self">self </span>}.record(f); |
| 1401 | + <span class="prelude-val">Ok</span>(()) |
1388 | 1402 | } |
1389 | | - <span class="prelude-val">Err</span>(err) => err, |
1390 | | - }; |
1391 | | - <span class="kw">match </span>err { |
1392 | | - err @ EncoderStateError::Locked => { |
| 1403 | + <span class="self">Self</span>::Locked(<span class="kw">_</span>) => { |
1393 | 1404 | <span class="comment">// Invalidate the encoder and do not record anything, but do not |
1394 | 1405 | // return an immediate validation error. |
1395 | | - </span><span class="self">self</span>.invalidate(err); |
| 1406 | + </span><span class="self">self</span>.invalidate(EncoderStateError::Locked); |
1396 | 1407 | <span class="prelude-val">Ok</span>(()) |
1397 | 1408 | } |
1398 | | - err @ EncoderStateError::Ended => { |
1399 | | - <span class="comment">// Invalidate the encoder, do not record anything, and return an |
1400 | | - // immediate validation error. |
1401 | | - </span><span class="prelude-val">Err</span>(<span class="self">self</span>.invalidate(err)) |
1402 | | - } |
| 1409 | + <span class="comment">// Encoder is ended. Invalidate the encoder, do not record anything, |
| 1410 | + // and return an immediate validation error. |
| 1411 | + </span><span class="self">Self</span>::Finished(<span class="kw">_</span>) => <span class="prelude-val">Err</span>(<span class="self">self</span>.invalidate(EncoderStateError::Ended)), |
1403 | 1412 | <span class="comment">// Encoder is already invalid. Do not record anything, but do not |
1404 | 1413 | // return an immediate validation error. |
1405 | | - </span>EncoderStateError::Invalid => <span class="prelude-val">Ok</span>(()), |
1406 | | - EncoderStateError::Unlocked | EncoderStateError::Submitted => <span class="macro">unreachable!</span>(), |
| 1414 | + </span><span class="self">Self</span>::Error(<span class="kw">_</span>) => <span class="prelude-val">Ok</span>(()), |
| 1415 | + <span class="self">Self</span>::Transitioning => <span class="macro">unreachable!</span>(), |
| 1416 | + } |
| 1417 | + } |
| 1418 | + |
| 1419 | + <span class="doccomment">/// Special version of record used by `command_encoder_as_hal_mut`. This |
| 1420 | + /// differs from the regular version in two ways: |
| 1421 | + /// |
| 1422 | + /// 1. The recording closure is infallible. |
| 1423 | + /// 2. The recording closure takes `Option<&mut CommandBufferMutable>`, and |
| 1424 | + /// in the case that the encoder is not in a valid state for recording, the |
| 1425 | + /// closure is still called, with `None` as its argument. |
| 1426 | + </span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>record_as_hal_mut<T, F: FnOnce(<span class="prelude-ty">Option</span><<span class="kw-2">&mut </span>CommandBufferMutable>) -> T>( |
| 1427 | + <span class="kw-2">&mut </span><span class="self">self</span>, |
| 1428 | + f: F, |
| 1429 | + ) -> T { |
| 1430 | + <span class="kw">match </span><span class="self">self </span>{ |
| 1431 | + <span class="self">Self</span>::Recording(<span class="kw">_</span>) => RecordingGuard { inner: <span class="self">self </span>}.record_as_hal_mut(f), |
| 1432 | + <span class="self">Self</span>::Locked(<span class="kw">_</span>) => { |
| 1433 | + <span class="self">self</span>.invalidate(EncoderStateError::Locked); |
| 1434 | + f(<span class="prelude-val">None</span>) |
| 1435 | + } |
| 1436 | + <span class="self">Self</span>::Finished(<span class="kw">_</span>) => { |
| 1437 | + <span class="self">self</span>.invalidate(EncoderStateError::Ended); |
| 1438 | + f(<span class="prelude-val">None</span>) |
| 1439 | + } |
| 1440 | + <span class="self">Self</span>::Error(<span class="kw">_</span>) => f(<span class="prelude-val">None</span>), |
| 1441 | + <span class="self">Self</span>::Transitioning => <span class="macro">unreachable!</span>(), |
1407 | 1442 | } |
1408 | 1443 | } |
1409 | 1444 |
|
|
1538 | 1573 | } |
1539 | 1574 | } |
1540 | 1575 | } |
| 1576 | + |
| 1577 | + <span class="doccomment">/// Special version of record used by `command_encoder_as_hal_mut`. This |
| 1578 | + /// version takes an infallible recording closure. |
| 1579 | + </span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>record_as_hal_mut<T, F: FnOnce(<span class="prelude-ty">Option</span><<span class="kw-2">&mut </span>CommandBufferMutable>) -> T>( |
| 1580 | + <span class="kw-2">mut </span><span class="self">self</span>, |
| 1581 | + f: F, |
| 1582 | + ) -> T { |
| 1583 | + <span class="kw">let </span>res = f(<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="self">self</span>)); |
| 1584 | + <span class="self">self</span>.mark_successful(); |
| 1585 | + res |
| 1586 | + } |
1541 | 1587 | } |
1542 | 1588 |
|
1543 | 1589 | <span class="kw">impl</span><<span class="lifetime">'a</span>> Drop <span class="kw">for </span>RecordingGuard<<span class="lifetime">'a</span>> { |
|
2142 | 2188 | <span class="attr">#[error(transparent)] |
2143 | 2189 | </span>Clear(<span class="attr">#[from] </span>ClearError), |
2144 | 2190 | <span class="attr">#[error(transparent)] |
| 2191 | + </span>Query(<span class="attr">#[from] </span>QueryError), |
| 2192 | + <span class="attr">#[error(transparent)] |
| 2193 | + </span>BuildAccelerationStructure(<span class="attr">#[from] </span>BuildAccelerationStructureError), |
| 2194 | + <span class="attr">#[error(transparent)] |
2145 | 2195 | </span>TransitionResources(<span class="attr">#[from] </span>TransitionResourcesError), |
2146 | 2196 | <span class="attr">#[error( |
2147 | 2197 | <span class="string">"begin and end indices of pass timestamp writes are both set to {idx}, which is not allowed" |
|
0 commit comments