Sprite rendering on dx12 seems broken since bevy 0.20.0

Open
#26,509 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start by reproducing the provided TextureAtlas example on DirectX 12 with Bevy 0.20.0 or 0.20.1, then compare it with Vulkan and Bevy 0.19.1. Trace sprite atlas rendering through the relevant rendering code and tests, focusing on differences that could explain missing sprites or incorrect placement on DirectX 12. Done means the provided example renders all digits in their expected positions on DirectX 12.

Written by the indexing model from the issue text.

Description

C-Bug S-Needs-Triage

Bevy version and features

  • bevy 0.20.0, with default features

Relevant system information

`AdapterInfo { name: "NVIDIA GeForce RTX 5060 Ti", vendor: 4318, device: 11524, device_type: DiscreteGpu, device_pci_bus_id: "0000:01:00.0", driver: "32.0.16.2114", driver_info: "", backend: Dx12, subgroup_min_size: 32, subgroup_max_size: 32, transient_saves_memory: Some(false), limit_bucket: None }`

What you did

  • Prepare a sprite sheet that contains digit from 0 to 9, and create sprites for each digit using TextureAtlas.
  • Run program with specify $env:WGPU_BACKEND="vulkan" or $env:WGPU_BACKEND="dx12".

What went wrong

In bevy 0.19.1:
Sprites rendered correctly (like Figure 1) on both vulkan and dx12.

In bevy 0.20.0 (and 0.20.1):
On vulkan, all digit are rendered correctly (like Figure 1).
On dx12, some digit are not rendered, and some digit are rendered on unexpected place (like Figure 2).

Code to reproduce this problem:

use bevy::{prelude::*, window::WindowResolution};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                resolution: WindowResolution::new(300, 200),
                ..default()
            }),
            ..default()
        }))
        .add_systems(Startup, startup)
        .run();
}

fn startup(
    asset_server: Res<AssetServer>,
    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
    mut commands: Commands,
) {
    let mut layout = TextureAtlasLayout::new_empty(UVec2::new(140, 14));
    let indexes = (0..10)
        .map(|o| layout.add_texture(URect::new(14 * o, 0, 14 * (o + 1), 14)))
        .collect::<Vec<_>>();
    let image = asset_server.load::<Image>("test.png");
    let layout = texture_atlas_layouts.add(layout);

    commands.spawn(Camera2d);
    for (offset, index) in indexes.into_iter().enumerate() {
        commands.spawn((
            Sprite {
                image: image.clone(),
                texture_atlas: Some(TextureAtlas {
                    layout: layout.clone(),
                    index: index,
                }),
                ..default()
            },
            Transform {
                translation: Vec3::new(14.0 * offset as f32, 0.0, 0.0),
                ..default()
            },
        ));
    }
}

Additional information

Figure 1:
figure1
Figure 2:
figure2
Sprite sheet:
test

Dominant language
Rust
Stars
49.8k
Forks
5.1k
Avg merge
3d 4h
Merged PRs (30d)
136

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bevyengine/bevy

All issues in bevyengine/bevy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.