Use more headers in AsBindGroup docs (#17586)

# Objective

- Linking to a specific AsBindGroup attribute is hard because it doesn't
use any headers and all the docs is in a giant block

## Solution

- Make each attribute it's own sub-header so they can be easily linked

---

## Showcase

Here's what the rustdoc output looks like with this change


![image](https://github.com/user-attachments/assets/4987b03c-c75d-4a5f-89b7-0c356b61706a)

## Notes

I kept the bullet point so the text is still indented like before. Not
sure if we should keep that or not
This commit is contained in:
IceSentry 2025-02-02 10:18:39 -05:00 committed by GitHub
parent 416100a253
commit 9c5ce33e1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -142,17 +142,19 @@ impl Deref for BindGroup {
/// ///
/// The following field-level attributes are supported: /// The following field-level attributes are supported:
/// ///
/// * `uniform(BINDING_INDEX)` /// ## `uniform(BINDING_INDEX)`
/// * The field will be converted to a shader-compatible type using the [`ShaderType`] trait, written to a [`Buffer`], and bound as a uniform.
/// [`ShaderType`] is implemented for most math types already, such as [`f32`], [`Vec4`](bevy_math::Vec4), and
/// [`LinearRgba`](bevy_color::LinearRgba). It can also be derived for custom structs.
/// ///
/// * `texture(BINDING_INDEX, arguments)` /// * The field will be converted to a shader-compatible type using the [`ShaderType`] trait, written to a [`Buffer`], and bound as a uniform.
/// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Texture`](crate::render_resource::Texture) /// [`ShaderType`] is implemented for most math types already, such as [`f32`], [`Vec4`](bevy_math::Vec4), and
/// GPU resource, which will be bound as a texture in shaders. The field will be assumed to implement [`Into<Option<Handle<Image>>>`]. In practice, /// [`LinearRgba`](bevy_color::LinearRgba). It can also be derived for custom structs.
/// most fields should be a [`Handle<Image>`](bevy_asset::Handle) or [`Option<Handle<Image>>`]. If the value of an [`Option<Handle<Image>>`] is ///
/// [`None`], the [`crate::texture::FallbackImage`] resource will be used instead. This attribute can be used in conjunction with a `sampler` binding attribute /// ## `texture(BINDING_INDEX, arguments)`
/// (with a different binding index) if a binding of the sampler for the [`Image`](bevy_image::Image) is also required. ///
/// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Texture`](crate::render_resource::Texture)
/// GPU resource, which will be bound as a texture in shaders. The field will be assumed to implement [`Into<Option<Handle<Image>>>`]. In practice,
/// most fields should be a [`Handle<Image>`](bevy_asset::Handle) or [`Option<Handle<Image>>`]. If the value of an [`Option<Handle<Image>>`] is
/// [`None`], the [`crate::texture::FallbackImage`] resource will be used instead. This attribute can be used in conjunction with a `sampler` binding attribute
/// (with a different binding index) if a binding of the sampler for the [`Image`](bevy_image::Image) is also required.
/// ///
/// | Arguments | Values | Default | /// | Arguments | Values | Default |
/// |-----------------------|-------------------------------------------------------------------------|----------------------| /// |-----------------------|-------------------------------------------------------------------------|----------------------|
@ -162,11 +164,12 @@ impl Deref for BindGroup {
/// | `multisampled` = ... | `true`, `false` | `false` | /// | `multisampled` = ... | `true`, `false` | `false` |
/// | `visibility(...)` | `all`, `none`, or a list-combination of `vertex`, `fragment`, `compute` | `vertex`, `fragment` | /// | `visibility(...)` | `all`, `none`, or a list-combination of `vertex`, `fragment`, `compute` | `vertex`, `fragment` |
/// ///
/// * `storage_texture(BINDING_INDEX, arguments)` /// ## `storage_texture(BINDING_INDEX, arguments)`
/// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Texture`](crate::render_resource::Texture) ///
/// GPU resource, which will be bound as a storage texture in shaders. The field will be assumed to implement [`Into<Option<Handle<Image>>>`]. In practice, /// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Texture`](crate::render_resource::Texture)
/// most fields should be a [`Handle<Image>`](bevy_asset::Handle) or [`Option<Handle<Image>>`]. If the value of an [`Option<Handle<Image>>`] is /// GPU resource, which will be bound as a storage texture in shaders. The field will be assumed to implement [`Into<Option<Handle<Image>>>`]. In practice,
/// [`None`], the [`crate::texture::FallbackImage`] resource will be used instead. /// most fields should be a [`Handle<Image>`](bevy_asset::Handle) or [`Option<Handle<Image>>`]. If the value of an [`Option<Handle<Image>>`] is
/// [`None`], the [`crate::texture::FallbackImage`] resource will be used instead.
/// ///
/// | Arguments | Values | Default | /// | Arguments | Values | Default |
/// |------------------------|--------------------------------------------------------------------------------------------|---------------| /// |------------------------|--------------------------------------------------------------------------------------------|---------------|
@ -175,22 +178,24 @@ impl Deref for BindGroup {
/// | `access` = ... | any member of [`StorageTextureAccess`](crate::render_resource::StorageTextureAccess) | `ReadWrite` | /// | `access` = ... | any member of [`StorageTextureAccess`](crate::render_resource::StorageTextureAccess) | `ReadWrite` |
/// | `visibility(...)` | `all`, `none`, or a list-combination of `vertex`, `fragment`, `compute` | `compute` | /// | `visibility(...)` | `all`, `none`, or a list-combination of `vertex`, `fragment`, `compute` | `compute` |
/// ///
/// * `sampler(BINDING_INDEX, arguments)` /// ## `sampler(BINDING_INDEX, arguments)`
/// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Sampler`] GPU ///
/// resource, which will be bound as a sampler in shaders. The field will be assumed to implement [`Into<Option<Handle<Image>>>`]. In practice, /// * This field's [`Handle<Image>`](bevy_asset::Handle) will be used to look up the matching [`Sampler`] GPU
/// most fields should be a [`Handle<Image>`](bevy_asset::Handle) or [`Option<Handle<Image>>`]. If the value of an [`Option<Handle<Image>>`] is /// resource, which will be bound as a sampler in shaders. The field will be assumed to implement [`Into<Option<Handle<Image>>>`]. In practice,
/// [`None`], the [`crate::texture::FallbackImage`] resource will be used instead. This attribute can be used in conjunction with a `texture` binding attribute /// most fields should be a [`Handle<Image>`](bevy_asset::Handle) or [`Option<Handle<Image>>`]. If the value of an [`Option<Handle<Image>>`] is
/// (with a different binding index) if a binding of the texture for the [`Image`](bevy_image::Image) is also required. /// [`None`], the [`crate::texture::FallbackImage`] resource will be used instead. This attribute can be used in conjunction with a `texture` binding attribute
/// (with a different binding index) if a binding of the texture for the [`Image`](bevy_image::Image) is also required.
/// ///
/// | Arguments | Values | Default | /// | Arguments | Values | Default |
/// |------------------------|-------------------------------------------------------------------------|------------------------| /// |------------------------|-------------------------------------------------------------------------|------------------------|
/// | `sampler_type` = "..." | `"filtering"`, `"non_filtering"`, `"comparison"`. | `"filtering"` | /// | `sampler_type` = "..." | `"filtering"`, `"non_filtering"`, `"comparison"`. | `"filtering"` |
/// | `visibility(...)` | `all`, `none`, or a list-combination of `vertex`, `fragment`, `compute` | `vertex`, `fragment` | /// | `visibility(...)` | `all`, `none`, or a list-combination of `vertex`, `fragment`, `compute` | `vertex`, `fragment` |
/// * `storage(BINDING_INDEX, arguments)` ///
/// * The field's [`Handle<Storage>`](bevy_asset::Handle) will be used to look up the matching [`Buffer`] GPU resource, which /// ## `storage(BINDING_INDEX, arguments)`
/// will be bound as a storage buffer in shaders. If the `storage` attribute is used, the field is expected a raw ///
/// buffer, and the buffer will be bound as a storage buffer in shaders. /// * The field's [`Handle<Storage>`](bevy_asset::Handle) will be used to look up the matching [`Buffer`] GPU resource, which
/// * It supports an optional `read_only` parameter. Defaults to false if not present. /// will be bound as a storage buffer in shaders. If the `storage` attribute is used, the field is expected a raw
/// buffer, and the buffer will be bound as a storage buffer in shaders.
/// ///
/// | Arguments | Values | Default | /// | Arguments | Values | Default |
/// |------------------------|-------------------------------------------------------------------------|----------------------| /// |------------------------|-------------------------------------------------------------------------|----------------------|
@ -253,41 +258,46 @@ impl Deref for BindGroup {
/// ``` /// ```
/// ///
/// Some less common scenarios will require "struct-level" attributes. These are the currently supported struct-level attributes: /// Some less common scenarios will require "struct-level" attributes. These are the currently supported struct-level attributes:
/// * `uniform(BINDING_INDEX, ConvertedShaderType)` /// ## `uniform(BINDING_INDEX, ConvertedShaderType)`
/// * This also creates a [`Buffer`] using [`ShaderType`] and binds it as a uniform, much ///
/// like the field-level `uniform` attribute. The difference is that the entire [`AsBindGroup`] value is converted to `ConvertedShaderType`, /// * This also creates a [`Buffer`] using [`ShaderType`] and binds it as a uniform, much
/// which must implement [`ShaderType`], instead of a specific field implementing [`ShaderType`]. This is useful if more complicated conversion /// like the field-level `uniform` attribute. The difference is that the entire [`AsBindGroup`] value is converted to `ConvertedShaderType`,
/// logic is required. The conversion is done using the [`AsBindGroupShaderType<ConvertedShaderType>`] trait, which is automatically implemented /// which must implement [`ShaderType`], instead of a specific field implementing [`ShaderType`]. This is useful if more complicated conversion
/// if `&Self` implements [`Into<ConvertedShaderType>`]. Only use [`AsBindGroupShaderType`] if access to resources like [`RenderAssets<GpuImage>`] is /// logic is required. The conversion is done using the [`AsBindGroupShaderType<ConvertedShaderType>`] trait, which is automatically implemented
/// required. /// if `&Self` implements [`Into<ConvertedShaderType>`]. Only use [`AsBindGroupShaderType`] if access to resources like [`RenderAssets<GpuImage>`] is
/// * `bind_group_data(DataType)` /// required.
/// * The [`AsBindGroup`] type will be converted to some `DataType` using [`Into<DataType>`] and stored ///
/// as [`AsBindGroup::Data`] as part of the [`AsBindGroup::as_bind_group`] call. This is useful if data needs to be stored alongside /// ## `bind_group_data(DataType)`
/// the generated bind group, such as a unique identifier for a material's bind group. The most common use case for this attribute ///
/// is "shader pipeline specialization". See [`SpecializedRenderPipeline`](crate::render_resource::SpecializedRenderPipeline). /// * The [`AsBindGroup`] type will be converted to some `DataType` using [`Into<DataType>`] and stored
/// * `bindless(COUNT)` /// as [`AsBindGroup::Data`] as part of the [`AsBindGroup::as_bind_group`] call. This is useful if data needs to be stored alongside
/// * This switch enables *bindless resources*, which changes the way Bevy /// the generated bind group, such as a unique identifier for a material's bind group. The most common use case for this attribute
/// supplies resources (uniforms, textures, and samplers) to the shader. /// is "shader pipeline specialization". See [`SpecializedRenderPipeline`](crate::render_resource::SpecializedRenderPipeline).
/// When bindless resources are enabled, and the current platform supports ///
/// them, instead of presenting a single instance of a resource to your /// ## `bindless(COUNT)`
/// shader Bevy will instead present a *binding array* of `COUNT` elements. ///
/// In your shader, the index of the element of each binding array /// * This switch enables *bindless resources*, which changes the way Bevy
/// corresponding to the mesh currently being drawn can be retrieved with /// supplies resources (uniforms, textures, and samplers) to the shader.
/// `mesh[in.instance_index].material_and_lightmap_bind_group_slot & /// When bindless resources are enabled, and the current platform supports
/// 0xffffu`. /// them, instead of presenting a single instance of a resource to your
/// * Bindless uniforms don't exist, so in bindless mode all uniforms and /// shader Bevy will instead present a *binding array* of `COUNT` elements.
/// uniform buffers are automatically replaced with read-only storage /// In your shader, the index of the element of each binding array
/// buffers. /// corresponding to the mesh currently being drawn can be retrieved with
/// * The purpose of bindless mode is to improve performance by reducing /// `mesh[in.instance_index].material_and_lightmap_bind_group_slot &
/// state changes. By grouping resources together into binding arrays, Bevy /// 0xffffu`.
/// doesn't have to modify GPU state as often, decreasing API and driver /// * Bindless uniforms don't exist, so in bindless mode all uniforms and
/// overhead. /// uniform buffers are automatically replaced with read-only storage
/// * If bindless mode is enabled, the `BINDLESS` definition will be /// buffers.
/// available. Because not all platforms support bindless resources, you /// * The purpose of bindless mode is to improve performance by reducing
/// should check for the presence of this definition via `#ifdef` and fall /// state changes. By grouping resources together into binding arrays, Bevy
/// back to standard bindings if it isn't present. /// doesn't have to modify GPU state as often, decreasing API and driver
/// * See the `shaders/shader_material_bindless` example for an example of /// overhead.
/// how to use bindless mode. /// * If bindless mode is enabled, the `BINDLESS` definition will be
/// available. Because not all platforms support bindless resources, you
/// should check for the presence of this definition via `#ifdef` and fall
/// back to standard bindings if it isn't present.
/// * See the `shaders/shader_material_bindless` example for an example of
/// how to use bindless mode.
/// ///
/// The previous `CoolMaterial` example illustrating "combining multiple field-level uniform attributes with the same binding index" can /// The previous `CoolMaterial` example illustrating "combining multiple field-level uniform attributes with the same binding index" can
/// also be equivalently represented with a single struct-level uniform attribute: /// also be equivalently represented with a single struct-level uniform attribute: