Skip to content

Use embedded_asset to load PBR shaders #19137

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

Merged
merged 2 commits into from
May 16, 2025

Conversation

atlv24
Copy link
Contributor

@atlv24 atlv24 commented May 9, 2025

Objective

  • Get in-engine shader hot reloading working

Solution

  • Adopt Use embedded_asset to load shaders #12009
  • Cut back on everything possible to land an MVP: we only hot-reload PBR in deferred shading mode. This is to minimize the diff and avoid merge hell. The rest shall come in followups.

Testing

  • cargo run --example pbr --features="embedded_watcher" and edit some pbr shader code

@atlv24 atlv24 force-pushed the shader-hot-reload branch from c2c886a to 9572536 Compare May 9, 2025 05:17
@tychedelia tychedelia added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 9, 2025
Copy link
Contributor

@andriyDev andriyDev left a comment

Choose a reason for hiding this comment

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

Thank you so much for making this happen! I'm so excited to clean out these weak handles!

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

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

Please ensure that this does not break our Wasm builds when compiling on Windows, see #14246
Hopefully that rustc bug was fixed in the year since :D
Edit: it was not ._.
Also relevant to test: #14718 and #10575

@atlv24 atlv24 force-pushed the shader-hot-reload branch from 9572536 to 6995c4a Compare May 9, 2025 07:44
@atlv24
Copy link
Contributor Author

atlv24 commented May 12, 2025

Waiting for #19139

@atlv24 atlv24 added the S-Blocked This cannot move forward until something else changes label May 12, 2025
@atlv24 atlv24 requested a review from andriyDev May 12, 2025 08:11
macro_rules! load_embedded_asset {
(@get: $path: literal, $provider: expr) => {{
let path = $crate::embedded_path!($path);
let path = $crate::AssetPath::from_path_buf(path).with_source("embedded");
Copy link
Contributor

@superdump superdump May 12, 2025

Choose a reason for hiding this comment

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

I wonder if we want to name the AssetPaths given they have a label field for that.

@@ -1345,7 +1345,7 @@ impl From<&StandardMaterial> for StandardMaterialKey {

impl Material for StandardMaterial {
fn fragment_shader() -> ShaderRef {
PBR_SHADER_HANDLE.into()
shader_ref(bevy_asset::embedded_path!("render/pbr.wgsl"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like possibly a not so discoverable pattern? I wonder if we should have a clearly-named macro for this particularly and likely common usage?

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

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

Mostly looks good to me. Just left a few comments. If someone wants to merge before I get back to this, I am not opposed.

@janhohenheim janhohenheim removed the S-Blocked This cannot move forward until something else changes label May 12, 2025
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

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

I'm not going to block on the two remaining comments I had.

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

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

From my limited understanding, this also looks correct :)

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 12, 2025
@@ -140,7 +207,7 @@ impl EmbeddedAssetRegistry {
#[macro_export]
macro_rules! embedded_path {
($path_str: expr) => {{
embedded_path!("src", $path_str)
$crate::embedded_path!("src", $path_str)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this meant to fix use bevy_asset::embedded_path as [something else]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

im not sure why it doesn't work without this.

@atlv24 atlv24 force-pushed the shader-hot-reload branch from 6995c4a to 1679b3e Compare May 15, 2025 21:08
@superdump superdump added this pull request to the merge queue May 16, 2025
Merged via the queue into bevyengine:main with commit 1395152 May 16, 2025
32 checks passed
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-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants