Skip to content

Conversation

@beicause
Copy link
Contributor

@beicause beicause commented Dec 11, 2025

Objective

Fixes #22031 (comment). Fixes #15201.
#22031 makes ViewTarget::out_texture_format to return the underlying texture’s format, which causes some issues:

  1. ExtractedWindow::swap_chain_texture_view always uses srgb view. But the underlying swap chain texture in WebGPU can be Bgra8unorm, leading to format mismatch between the render pipeline and the render pass.
  2. We can no longer use srgb view for non-srgb target texture, it will panic due to incompatible pipeline:
    let mut image = Image::new_target_texture(512, 512, TextureFormat::Rgba8Unorm);
    image.texture_view_descriptor = Some(bevy_render::render_resource::TextureViewDescriptor {
        format: Some(TextureFormat::Rgba8UnormSrgb),
        ..Default::default()
    });
    image.texture_descriptor.view_formats = &[TextureFormat::Rgba8UnormSrgb];

Solution

Reverts #22031.
Renames some format to view_format explicitly.
Adds view_format to GpuImage and Image::new_target_texture so we can make render pipeline match render pass texture view.

Testing

Tested render_to_texture and screenshot examples on linux and webgpu.

The rendered Rgba8Unorm texture with or without srgb view in MeshMaterial3d looks the same, but the underlaying data is different:

With srgb view:
屏幕截图_20251212_223355

Without srgb view:
屏幕截图_20251212_223313

@beicause beicause changed the title Alternative fix for non-srgb RenderTarget::Image, reverts #22031 Fix non-srgb RenderTarget::Image, reverts #22031 Dec 11, 2025
@alice-i-cecile alice-i-cecile added this to the 0.18 milestone Dec 12, 2025
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen P-Regression Functionality that used to work but no longer does. Add a test for this! labels Dec 12, 2025
@alice-i-cecile
Copy link
Member

@bonsairobo, can you take a look please?

@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Dec 12, 2025
@beicause beicause force-pushed the revert-22031 branch 2 times, most recently from 3e81d63 to fa0e7b0 Compare December 12, 2025 14:30
@bonsairobo
Copy link
Contributor

Sorry! I didn't realize that webgpu still isn't the default for wasm32 targets, so I must've only tested a WebGL2 build.

I would prefer if the revert happened in its own PR, but idk if there is any precedent for that in Bevy.

I'll review the 2nd commit.

@mockersf
Copy link
Member

Yup, it's nicer for the git history to do revert as stand alone PRs as we squash PRs on merge

Copy link
Contributor

@bonsairobo bonsairobo left a comment

Choose a reason for hiding this comment

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

LGTM

@beicause
Copy link
Contributor Author

Ok, I've opened a PR for reverting.

@beicause beicause changed the title Fix non-srgb RenderTarget::Image, reverts #22031 Fix non-srgb RenderTarget::Image Dec 12, 2025
github-merge-queue bot pushed a commit that referenced this pull request Dec 13, 2025
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-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this! S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

RenderTarget::Image doesn't support Rgba8Unorm and Bgra8Unorm texture formats (non-srgb formats)

4 participants