|
1052 | 1052 | <a href="#1051" id="1051">1051</a>
|
1053 | 1053 | <a href="#1052" id="1052">1052</a>
|
1054 | 1054 | <a href="#1053" id="1053">1053</a>
|
1055 |
| -<a href="#1054" id="1054">1054</a></pre></div><pre class="rust"><code><span class="kw">use crate</span>::{ |
| 1055 | +<a href="#1054" id="1054">1054</a> |
| 1056 | +<a href="#1055" id="1055">1055</a> |
| 1057 | +<a href="#1056" id="1056">1056</a> |
| 1058 | +<a href="#1057" id="1057">1057</a> |
| 1059 | +<a href="#1058" id="1058">1058</a> |
| 1060 | +<a href="#1059" id="1059">1059</a> |
| 1061 | +<a href="#1060" id="1060">1060</a> |
| 1062 | +<a href="#1061" id="1061">1061</a> |
| 1063 | +<a href="#1062" id="1062">1062</a> |
| 1064 | +<a href="#1063" id="1063">1063</a> |
| 1065 | +<a href="#1064" id="1064">1064</a> |
| 1066 | +<a href="#1065" id="1065">1065</a> |
| 1067 | +<a href="#1066" id="1066">1066</a> |
| 1068 | +<a href="#1067" id="1067">1067</a> |
| 1069 | +<a href="#1068" id="1068">1068</a> |
| 1070 | +<a href="#1069" id="1069">1069</a> |
| 1071 | +<a href="#1070" id="1070">1070</a> |
| 1072 | +<a href="#1071" id="1071">1071</a></pre></div><pre class="rust"><code><span class="kw">use crate</span>::{ |
1056 | 1073 | device::{
|
1057 | 1074 | bgl, Device, DeviceError, MissingDownlevelFlags, MissingFeatures, SHADER_STAGE_COUNT,
|
1058 | 1075 | },
|
|
1493 | 1510 | <span class="doccomment">/// Bindable resource and the slot to bind it to.
|
1494 | 1511 | </span><span class="attr">#[derive(Clone, Debug)]
|
1495 | 1512 | #[cfg_attr(feature = <span class="string">"serde"</span>, derive(Serialize, Deserialize))]
|
1496 |
| -</span><span class="kw">pub struct </span>BindGroupEntry<<span class="lifetime">'a</span>> { |
| 1513 | +</span><span class="kw">pub struct </span>BindGroupEntry<<span class="lifetime">'a</span>, B = BufferId, S = SamplerId, TV = TextureViewId, TLAS = TlasId> |
| 1514 | +<span class="kw">where |
| 1515 | + </span>[BufferBinding<B>]: ToOwned, |
| 1516 | + [S]: ToOwned, |
| 1517 | + [TV]: ToOwned, |
| 1518 | + <[BufferBinding<B>] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1519 | + <[S] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1520 | + <[TV] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1521 | +{ |
1497 | 1522 | <span class="doccomment">/// Slot for which binding provides resource. Corresponds to an entry of the same
|
1498 | 1523 | /// binding index in the [`BindGroupLayoutDescriptor`].
|
1499 | 1524 | </span><span class="kw">pub </span>binding: u32,
|
1500 |
| - <span class="doccomment">/// Resource to attach to the binding |
1501 |
| - </span><span class="kw">pub </span>resource: BindingResource<<span class="lifetime">'a</span>>, |
| 1525 | + <span class="attr">#[cfg_attr( |
| 1526 | + feature = <span class="string">"serde"</span>, |
| 1527 | + serde(bound(deserialize = <span class="string">"BindingResource<'a, B, S, TV, TLAS>: Deserialize<'de>"</span>)) |
| 1528 | + )] |
| 1529 | + </span><span class="doccomment">/// Resource to attach to the binding |
| 1530 | + </span><span class="kw">pub </span>resource: BindingResource<<span class="lifetime">'a</span>, B, S, TV, TLAS>, |
1502 | 1531 | }
|
1503 | 1532 |
|
1504 |
| -<span class="doccomment">/// Bindable resource and the slot to bind it to. |
1505 |
| -</span><span class="attr">#[derive(Clone, Debug)] |
1506 |
| -</span><span class="kw">pub struct </span>ResolvedBindGroupEntry<<span class="lifetime">'a</span>> { |
1507 |
| - <span class="doccomment">/// Slot for which binding provides resource. Corresponds to an entry of the same |
1508 |
| - /// binding index in the [`BindGroupLayoutDescriptor`]. |
1509 |
| - </span><span class="kw">pub </span>binding: u32, |
1510 |
| - <span class="doccomment">/// Resource to attach to the binding |
1511 |
| - </span><span class="kw">pub </span>resource: ResolvedBindingResource<<span class="lifetime">'a</span>>, |
1512 |
| -} |
| 1533 | +<span class="kw">pub type </span>ResolvedBindGroupEntry<<span class="lifetime">'a</span>> = |
| 1534 | + BindGroupEntry<<span class="lifetime">'a</span>, Arc<Buffer>, Arc<Sampler>, Arc<TextureView>, Arc<Tlas>>; |
1513 | 1535 |
|
1514 | 1536 | <span class="doccomment">/// Describes a group of bindings and the resources to be bound.
|
1515 | 1537 | </span><span class="attr">#[derive(Clone, Debug)]
|
1516 | 1538 | #[cfg_attr(feature = <span class="string">"serde"</span>, derive(Serialize, Deserialize))]
|
1517 |
| -</span><span class="kw">pub struct </span>BindGroupDescriptor<<span class="lifetime">'a</span>> { |
| 1539 | +</span><span class="kw">pub struct </span>BindGroupDescriptor< |
| 1540 | + <span class="lifetime">'a</span>, |
| 1541 | + BGL = BindGroupLayoutId, |
| 1542 | + B = BufferId, |
| 1543 | + S = SamplerId, |
| 1544 | + TV = TextureViewId, |
| 1545 | + TLAS = TlasId, |
| 1546 | +> <span class="kw">where |
| 1547 | + </span>[BufferBinding<B>]: ToOwned, |
| 1548 | + [S]: ToOwned, |
| 1549 | + [TV]: ToOwned, |
| 1550 | + <[BufferBinding<B>] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1551 | + <[S] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1552 | + <[TV] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1553 | + [BindGroupEntry<<span class="lifetime">'a</span>, B, S, TV, TLAS>]: ToOwned, |
| 1554 | + <[BindGroupEntry<<span class="lifetime">'a</span>, B, S, TV, TLAS>] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1555 | +{ |
1518 | 1556 | <span class="doccomment">/// Debug label of the bind group.
|
1519 | 1557 | ///
|
1520 | 1558 | /// This will show up in graphics debuggers for easy identification.
|
1521 | 1559 | </span><span class="kw">pub </span>label: Label<<span class="lifetime">'a</span>>,
|
1522 | 1560 | <span class="doccomment">/// The [`BindGroupLayout`] that corresponds to this bind group.
|
1523 |
| - </span><span class="kw">pub </span>layout: BindGroupLayoutId, |
1524 |
| - <span class="doccomment">/// The resources to bind to this bind group. |
1525 |
| - </span><span class="kw">pub </span>entries: Cow<<span class="lifetime">'a</span>, [BindGroupEntry<<span class="lifetime">'a</span>>]>, |
| 1561 | + </span><span class="kw">pub </span>layout: BGL, |
| 1562 | + <span class="attr">#[cfg_attr( |
| 1563 | + feature = <span class="string">"serde"</span>, |
| 1564 | + serde(bound( |
| 1565 | + deserialize = <span class="string">"<[BindGroupEntry<'a, B, S, TV, TLAS>] as ToOwned>::Owned: Deserialize<'de>" |
| 1566 | + </span>)) |
| 1567 | + )] |
| 1568 | + </span><span class="doccomment">/// The resources to bind to this bind group. |
| 1569 | + </span><span class="kw">pub </span>entries: Cow<<span class="lifetime">'a</span>, [BindGroupEntry<<span class="lifetime">'a</span>, B, S, TV, TLAS>]>, |
1526 | 1570 | }
|
1527 | 1571 |
|
1528 |
| -<span class="doccomment">/// Describes a group of bindings and the resources to be bound. |
1529 |
| -</span><span class="attr">#[derive(Clone, Debug)] |
1530 |
| -</span><span class="kw">pub struct </span>ResolvedBindGroupDescriptor<<span class="lifetime">'a</span>> { |
1531 |
| - <span class="doccomment">/// Debug label of the bind group. |
1532 |
| - /// |
1533 |
| - /// This will show up in graphics debuggers for easy identification. |
1534 |
| - </span><span class="kw">pub </span>label: Label<<span class="lifetime">'a</span>>, |
1535 |
| - <span class="doccomment">/// The [`BindGroupLayout`] that corresponds to this bind group. |
1536 |
| - </span><span class="kw">pub </span>layout: Arc<BindGroupLayout>, |
1537 |
| - <span class="doccomment">/// The resources to bind to this bind group. |
1538 |
| - </span><span class="kw">pub </span>entries: Cow<<span class="lifetime">'a</span>, [ResolvedBindGroupEntry<<span class="lifetime">'a</span>>]>, |
1539 |
| -} |
| 1572 | +<span class="kw">pub type </span>ResolvedBindGroupDescriptor<<span class="lifetime">'a</span>> = BindGroupDescriptor< |
| 1573 | + <span class="lifetime">'a</span>, |
| 1574 | + Arc<BindGroupLayout>, |
| 1575 | + Arc<Buffer>, |
| 1576 | + Arc<Sampler>, |
| 1577 | + Arc<TextureView>, |
| 1578 | + Arc<Tlas>, |
| 1579 | +>; |
1540 | 1580 |
|
1541 | 1581 | <span class="doccomment">/// Describes a [`BindGroupLayout`].
|
1542 | 1582 | </span><span class="attr">#[derive(Clone, Debug)]
|
|
1695 | 1735 | /// A `PipelineLayoutDescriptor` can be used to create a pipeline layout.
|
1696 | 1736 | </span><span class="attr">#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
1697 | 1737 | #[cfg_attr(feature = <span class="string">"serde"</span>, derive(Serialize, Deserialize))]
|
1698 |
| -</span><span class="kw">pub struct </span>PipelineLayoutDescriptor<<span class="lifetime">'a</span>> { |
| 1738 | +#[cfg_attr(feature = <span class="string">"serde"</span>, serde(bound = <span class="string">"BGL: Serialize"</span>))] |
| 1739 | +</span><span class="kw">pub struct </span>PipelineLayoutDescriptor<<span class="lifetime">'a</span>, BGL = BindGroupLayoutId> |
| 1740 | +<span class="kw">where |
| 1741 | + </span>[BGL]: ToOwned, |
| 1742 | + <[BGL] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1743 | +{ |
1699 | 1744 | <span class="doccomment">/// Debug label of the pipeline layout.
|
1700 | 1745 | ///
|
1701 | 1746 | /// This will show up in graphics debuggers for easy identification.
|
1702 | 1747 | </span><span class="kw">pub </span>label: Label<<span class="lifetime">'a</span>>,
|
1703 | 1748 | <span class="doccomment">/// Bind groups that this pipeline uses. The first entry will provide all the bindings for
|
1704 | 1749 | /// "set = 0", second entry will provide all the bindings for "set = 1" etc.
|
1705 |
| - </span><span class="kw">pub </span>bind_group_layouts: Cow<<span class="lifetime">'a</span>, [BindGroupLayoutId]>, |
| 1750 | + </span><span class="attr">#[cfg_attr( |
| 1751 | + feature = <span class="string">"serde"</span>, |
| 1752 | + serde(bound(deserialize = <span class="string">"<[BGL] as ToOwned>::Owned: Deserialize<'de>"</span>)) |
| 1753 | + )] |
| 1754 | + </span><span class="kw">pub </span>bind_group_layouts: Cow<<span class="lifetime">'a</span>, [BGL]>, |
1706 | 1755 | <span class="doccomment">/// Set of push constant ranges this pipeline uses. Each shader stage that
|
1707 | 1756 | /// uses push constants must define the range in push constant memory that
|
1708 | 1757 | /// corresponds to its single `layout(push_constant)` uniform block.
|
|
1713 | 1762 | </span><span class="kw">pub </span>push_constant_ranges: Cow<<span class="lifetime">'a</span>, [wgt::PushConstantRange]>,
|
1714 | 1763 | }
|
1715 | 1764 |
|
1716 |
| -<span class="doccomment">/// Describes a pipeline layout. |
1717 |
| -/// |
1718 |
| -/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout. |
1719 |
| -</span><span class="attr">#[derive(Debug)] |
1720 |
| -</span><span class="kw">pub struct </span>ResolvedPipelineLayoutDescriptor<<span class="lifetime">'a</span>> { |
1721 |
| - <span class="doccomment">/// Debug label of the pipeline layout. |
1722 |
| - /// |
1723 |
| - /// This will show up in graphics debuggers for easy identification. |
1724 |
| - </span><span class="kw">pub </span>label: Label<<span class="lifetime">'a</span>>, |
1725 |
| - <span class="doccomment">/// Bind groups that this pipeline uses. The first entry will provide all the bindings for |
1726 |
| - /// "set = 0", second entry will provide all the bindings for "set = 1" etc. |
1727 |
| - </span><span class="kw">pub </span>bind_group_layouts: Cow<<span class="lifetime">'a</span>, [Arc<BindGroupLayout>]>, |
1728 |
| - <span class="doccomment">/// Set of push constant ranges this pipeline uses. Each shader stage that |
1729 |
| - /// uses push constants must define the range in push constant memory that |
1730 |
| - /// corresponds to its single `layout(push_constant)` uniform block. |
1731 |
| - /// |
1732 |
| - /// If this array is non-empty, the |
1733 |
| - /// [`Features::PUSH_CONSTANTS`](wgt::Features::PUSH_CONSTANTS) feature must |
1734 |
| - /// be enabled. |
1735 |
| - </span><span class="kw">pub </span>push_constant_ranges: Cow<<span class="lifetime">'a</span>, [wgt::PushConstantRange]>, |
1736 |
| -} |
| 1765 | +<span class="kw">pub type </span>ResolvedPipelineLayoutDescriptor<<span class="lifetime">'a</span>> = PipelineLayoutDescriptor<<span class="lifetime">'a</span>, Arc<BindGroupLayout>>; |
1737 | 1766 |
|
1738 | 1767 | <span class="attr">#[derive(Debug)]
|
1739 | 1768 | </span><span class="kw">pub struct </span>PipelineLayout {
|
|
1855 | 1884 | <span class="attr">#[repr(C)]
|
1856 | 1885 | #[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
1857 | 1886 | #[cfg_attr(feature = <span class="string">"serde"</span>, derive(Serialize, Deserialize))]
|
1858 |
| -</span><span class="kw">pub struct </span>BufferBinding { |
1859 |
| - <span class="kw">pub </span>buffer_id: BufferId, |
| 1887 | +</span><span class="kw">pub struct </span>BufferBinding<B = BufferId> { |
| 1888 | + <span class="kw">pub </span>buffer: B, |
1860 | 1889 | <span class="kw">pub </span>offset: wgt::BufferAddress,
|
1861 | 1890 | <span class="kw">pub </span>size: <span class="prelude-ty">Option</span><wgt::BufferSize>,
|
1862 | 1891 | }
|
1863 | 1892 |
|
1864 |
| -<span class="attr">#[derive(Clone, Debug)] |
1865 |
| -</span><span class="kw">pub struct </span>ResolvedBufferBinding { |
1866 |
| - <span class="kw">pub </span>buffer: Arc<Buffer>, |
1867 |
| - <span class="kw">pub </span>offset: wgt::BufferAddress, |
1868 |
| - <span class="kw">pub </span>size: <span class="prelude-ty">Option</span><wgt::BufferSize>, |
1869 |
| -} |
| 1893 | +<span class="kw">pub type </span>ResolvedBufferBinding = BufferBinding<Arc<Buffer>>; |
1870 | 1894 |
|
1871 | 1895 | <span class="comment">// Note: Duplicated in `wgpu-rs` as `BindingResource`
|
1872 | 1896 | // They're different enough that it doesn't make sense to share a common type
|
1873 | 1897 | </span><span class="attr">#[derive(Debug, Clone)]
|
1874 | 1898 | #[cfg_attr(feature = <span class="string">"serde"</span>, derive(serde::Serialize, serde::Deserialize))]
|
1875 |
| -</span><span class="kw">pub enum </span>BindingResource<<span class="lifetime">'a</span>> { |
1876 |
| - Buffer(BufferBinding), |
1877 |
| - BufferArray(Cow<<span class="lifetime">'a</span>, [BufferBinding]>), |
1878 |
| - Sampler(SamplerId), |
1879 |
| - SamplerArray(Cow<<span class="lifetime">'a</span>, [SamplerId]>), |
1880 |
| - TextureView(TextureViewId), |
1881 |
| - TextureViewArray(Cow<<span class="lifetime">'a</span>, [TextureViewId]>), |
1882 |
| - AccelerationStructure(TlasId), |
| 1899 | +</span><span class="kw">pub enum </span>BindingResource<<span class="lifetime">'a</span>, B = BufferId, S = SamplerId, TV = TextureViewId, TLAS = TlasId> |
| 1900 | +<span class="kw">where |
| 1901 | + </span>[BufferBinding<B>]: ToOwned, |
| 1902 | + [S]: ToOwned, |
| 1903 | + [TV]: ToOwned, |
| 1904 | + <[BufferBinding<B>] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1905 | + <[S] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1906 | + <[TV] <span class="kw">as </span>ToOwned>::Owned: std::fmt::Debug, |
| 1907 | +{ |
| 1908 | + Buffer(BufferBinding<B>), |
| 1909 | + <span class="attr">#[cfg_attr( |
| 1910 | + feature = <span class="string">"serde"</span>, |
| 1911 | + serde(bound(deserialize = <span class="string">"<[BufferBinding<B>] as ToOwned>::Owned: Deserialize<'de>"</span>)) |
| 1912 | + )] |
| 1913 | + </span>BufferArray(Cow<<span class="lifetime">'a</span>, [BufferBinding<B>]>), |
| 1914 | + Sampler(S), |
| 1915 | + <span class="attr">#[cfg_attr( |
| 1916 | + feature = <span class="string">"serde"</span>, |
| 1917 | + serde(bound(deserialize = <span class="string">"<[S] as ToOwned>::Owned: Deserialize<'de>"</span>)) |
| 1918 | + )] |
| 1919 | + </span>SamplerArray(Cow<<span class="lifetime">'a</span>, [S]>), |
| 1920 | + TextureView(TV), |
| 1921 | + <span class="attr">#[cfg_attr( |
| 1922 | + feature = <span class="string">"serde"</span>, |
| 1923 | + serde(bound(deserialize = <span class="string">"<[TV] as ToOwned>::Owned: Deserialize<'de>"</span>)) |
| 1924 | + )] |
| 1925 | + </span>TextureViewArray(Cow<<span class="lifetime">'a</span>, [TV]>), |
| 1926 | + AccelerationStructure(TLAS), |
1883 | 1927 | }
|
1884 | 1928 |
|
1885 |
| -<span class="comment">// Note: Duplicated in `wgpu-rs` as `BindingResource` |
1886 |
| -// They're different enough that it doesn't make sense to share a common type |
1887 |
| -</span><span class="attr">#[derive(Debug, Clone)] |
1888 |
| -</span><span class="kw">pub enum </span>ResolvedBindingResource<<span class="lifetime">'a</span>> { |
1889 |
| - Buffer(ResolvedBufferBinding), |
1890 |
| - BufferArray(Cow<<span class="lifetime">'a</span>, [ResolvedBufferBinding]>), |
1891 |
| - Sampler(Arc<Sampler>), |
1892 |
| - SamplerArray(Cow<<span class="lifetime">'a</span>, [Arc<Sampler>]>), |
1893 |
| - TextureView(Arc<TextureView>), |
1894 |
| - TextureViewArray(Cow<<span class="lifetime">'a</span>, [Arc<TextureView>]>), |
1895 |
| - AccelerationStructure(Arc<Tlas>), |
1896 |
| -} |
| 1929 | +<span class="kw">pub type </span>ResolvedBindingResource<<span class="lifetime">'a</span>> = |
| 1930 | + BindingResource<<span class="lifetime">'a</span>, Arc<Buffer>, Arc<Sampler>, Arc<TextureView>, Arc<Tlas>>; |
1897 | 1931 |
|
1898 | 1932 | <span class="attr">#[derive(Clone, Debug, Error)]
|
1899 | 1933 | #[non_exhaustive]
|
|
0 commit comments