Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind group layout entries #10224

Merged
merged 24 commits into from
Nov 28, 2023

Conversation

IceSentry
Copy link
Contributor

@IceSentry IceSentry commented Oct 22, 2023

Objective

Solution

  • Same api as Bind group entries #9694 but adapted for BindGroupLayoutEntry
  • Use the same ShaderStages visibilty for all entries by default
  • Add BindingType helper function that mirror the wgsl equivalent and that make writing layouts much simpler.

Before:

let layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
    label: Some("post_process_bind_group_layout"),
    entries: &[
        BindGroupLayoutEntry {
            binding: 0,
            visibility: ShaderStages::FRAGMENT,
            ty: BindingType::Texture {
                sample_type: TextureSampleType::Float { filterable: true },
                view_dimension: TextureViewDimension::D2,
                multisampled: false,
            },
            count: None,
        },
        BindGroupLayoutEntry {
            binding: 1,
            visibility: ShaderStages::FRAGMENT,
            ty: BindingType::Sampler(SamplerBindingType::Filtering),
            count: None,
        },
        BindGroupLayoutEntry {
            binding: 2,
            visibility: ShaderStages::FRAGMENT,
            ty: BindingType::Buffer {
                ty: bevy::render::render_resource::BufferBindingType::Uniform,
                has_dynamic_offset: false,
                min_binding_size: Some(PostProcessSettings::min_size()),
            },
            count: None,
        },
    ],
});

After:

let layout = render_device.create_bind_group_layout(
    "post_process_bind_group_layout"),
    &BindGroupLayoutEntries::sequential(
        ShaderStages::FRAGMENT,
        (
            texture_2d_f32(),
            sampler(SamplerBindingType::Filtering),
            uniform_buffer(false, Some(PostProcessSettings::min_size())),
        ),
    ),
);

Here's a more extreme example in bevy_solari: JMS55@86dab7f


Changelog

  • Added BindGroupLayoutEntries and all BindingType helper functions.

Migration Guide

RenderDevice::create_bind_group_layout() doesn't take a BindGroupLayoutDescriptor anymore. You need to provide the parameters separately

// 0.12
let layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
    label: Some("post_process_bind_group_layout"),
    entries: &[
        BindGroupLayoutEntry {
			// ...
        },
    ],
});

// 0.13
let layout = render_device.create_bind_group_layout(
	"post_process_bind_group_layout",
    &[
        BindGroupLayoutEntry {
			// ...
        },
    ],
);

TODO

  • implement a Dynamic variant
  • update the RenderDevice::create_bind_group_layout() api to match the one from RenderDevice::creat_bind_group()
  • docs

@IceSentry IceSentry force-pushed the bind-group-layout-entries branch from 4945418 to 5369d6b Compare October 22, 2023 00:30
@IceSentry IceSentry added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Oct 22, 2023
@JMS55 JMS55 added this to the 0.13 milestone Oct 23, 2023
@IceSentry IceSentry force-pushed the bind-group-layout-entries branch from 5369d6b to 30f4278 Compare November 5, 2023 06:35
@IceSentry IceSentry added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Nov 8, 2023
@IceSentry IceSentry force-pushed the bind-group-layout-entries branch from 4d132f1 to fabb71b Compare November 8, 2023 06:01
@IceSentry IceSentry marked this pull request as ready for review November 8, 2023 06:01
Copy link
Contributor

@JMS55 JMS55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typos: *_mutlisampled -> *_multisampled

Otherwise lgtm, so pre-emptivley leaving my approval.

@IceSentry IceSentry force-pushed the bind-group-layout-entries branch from 1b9708f to cf09ecd Compare November 22, 2023 21:11
@IceSentry
Copy link
Contributor Author

Fixed the typo + fixed ci + rebased

@IceSentry
Copy link
Contributor Author

We might want to wait after 0.12.1 to merge this

Copy link
Contributor

@robtfm robtfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

the tradeoff in what to make explicit functions for, vs arguments to a generic fn is a bit tricky. i definitely think you've done the right thing by making generic functions and more specific variants as well. if anything i'd say we could go even further (sampler_filtering(), texture_storage_2d_readonly() etc), but that's definitely subjective/stylistic and i would understand if others disagree.

@IceSentry IceSentry force-pushed the bind-group-layout-entries branch from 600db4c to 009cf1e Compare November 23, 2023 03:17
@IceSentry IceSentry added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Nov 26, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Nov 28, 2023
Merged via the queue into bevyengine:main with commit 6d0c11a Nov 28, 2023
@IceSentry IceSentry deleted the bind-group-layout-entries branch January 10, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants