gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.73k stars 934 forks source link

DXC compile error with Bevy + Hanabi #5659

Open martinhiller opened 6 months ago

martinhiller commented 6 months ago

Description Running a minimal Bevy app with the Hanabi particle system and the DXC shader compiler results in a DXC compile error during startup. Switching to the Vulkan backend or using the FXC compiler for DX12 fixes the issue.

Repro steps

  1. Set up a simple Cargo project with the following file contents:

Cargo.toml

[package]
name = "wgpu-dxc-error"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.13.2"
bevy_hanabi = "0.10.0"

src\main.rs

use bevy::{
    prelude::*,
    render::{
        settings::{Backends, RenderCreation, WgpuSettings},
        RenderPlugin,
    },
};
use bevy_hanabi::prelude::*;

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins.set(RenderPlugin {
                render_creation: RenderCreation::Automatic(WgpuSettings {
                    backends: Some(Backends::DX12),
                    ..default()
                }),
                ..default()
            }),
            HanabiPlugin,
        ))
        .run();
}
  1. Download the most recent version of DXC: dxc_2024_03_29.zip
  2. Place the corresponding dxcompiler.dll and dxil.dll files in your project folder.
  3. Run cargo run.

Alternatively for step 1, check out this repository.

Expected vs observed behavior

Expected behavior: An empty window opens up and stays open. Observed behavior: An empty window opens up and closes immediately.

Extra materials

The following logs are produced:

2024-05-04T09:56:22.757478Z  INFO bevy_winit::system: Creating new window "App" (0v1)
2024-05-04T09:56:22.840661Z  INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 6600", vendor: 4098, device: 29695, device_type: DiscreteGpu, driver: "", driver_info: "", backend: Dx12 }
2024-05-04T09:56:23.162342Z  INFO bevy_hanabi::plugin: Initializing Hanabi for GPU adapter AMD Radeon RX 6600
2024-05-04T09:56:23.208752Z ERROR log: Naga generated shader for "main" at Compute:
struct NagaConstants {
    int first_vertex;
    int first_instance;
    uint other;
};
ConstantBuffer<NagaConstants> _NagaConstants: register(b1);

struct SimParamsX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X {
    float delta_time;
    float time;
    uint num_effects;
    uint render_stride;
    uint dispatch_stride;
};

struct ForceFieldSourceX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X {
    float3 position;
    float max_radius;
    float min_radius;
    float mass;
    float force_exponent;
    float conform_to_sphere;
};

struct SpawnerX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X {
    row_major float3x4 transform;
    row_major float3x4 inverse_transform;
    int spawn;
    uint seed;
    int count;
    uint effect_index;
    ForceFieldSourceX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X force_field[16];
    uint padding[4];
};

static const uint DI_OFFSET_XX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 0u;
static const uint DI_OFFSET_PONGX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 3u;
static const uint RI_OFFSET_INSTANCE_COUNTX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 1u;
static const uint RI_OFFSET_ALIVE_COUNTX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 5u;
static const uint RI_OFFSET_DEAD_COUNTX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 6u;
static const uint RI_OFFSET_MAX_SPAWNX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 7u;
static const uint RI_OFFSET_PINGX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 8u;
static const uint RI_OFFSET_MAX_UPDATEX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X = 9u;

RWByteAddressBuffer render_indirect_buffer : register(u0);
RWByteAddressBuffer dispatch_indirect_buffer : register(u1);
ByteAddressBuffer spawner_buffer : register(t0);
cbuffer sim_params : register(b0) { SimParamsX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X sim_params; }

uint NagaBufferLength(ByteAddressBuffer buffer)
{
    uint ret;
    buffer.GetDimensions(ret);
    return ret;
}

[numthreads(64, 1, 1)]
void main(uint3 global_invocation_id : SV_DispatchThreadID)
{
    uint index = global_invocation_id.x;
    uint _expr4 = sim_params.num_effects;
    if ((index >= _expr4)) {
        return;
    }
    if ((index >= ((NagaBufferLength(spawner_buffer) - 0) / 640))) {
        return;
    }
    uint effect_index = asuint(spawner_buffer.Load(108+index*640+0));
    uint _expr17 = sim_params.render_stride;
    uint ri_base = ((_expr17 * effect_index) / 4u);
    uint _expr23 = sim_params.dispatch_stride;
    uint di_base = ((_expr23 * effect_index) / 4u);
    uint alive_count = asuint(render_indirect_buffer.Load((ri_base + RI_OFFSET_ALIVE_COUNTX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4));
    dispatch_indirect_buffer.Store((di_base + DI_OFFSET_XX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4, asuint(((alive_count + 63u) >> 6u)));
    render_indirect_buffer.Store((ri_base + RI_OFFSET_MAX_UPDATEX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4, asuint(alive_count));
    uint dead_count = asuint(render_indirect_buffer.Load((ri_base + RI_OFFSET_DEAD_COUNTX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4));
    render_indirect_buffer.Store((ri_base + RI_OFFSET_MAX_SPAWNX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4, asuint(dead_count));
    render_indirect_buffer.Store((ri_base + RI_OFFSET_INSTANCE_COUNTX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4, asuint(0u));
    uint ping = asuint(render_indirect_buffer.Load((ri_base + RI_OFFSET_PINGX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4));
    uint pong = (1u - ping);
    render_indirect_buffer.Store((ri_base + RI_OFFSET_PINGX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4, asuint(pong));
    dispatch_indirect_buffer.Store((di_base + DI_OFFSET_PONGX_naga_oil_mod_XMJSXM6K7NBQW4YLCNE5DU5TGPBPWG33NNVXW4X)*4, asuint(pong));
    return;
}

2024-05-04T09:56:23.210839Z ERROR log: Shader translation error for stage ShaderStages(COMPUTE): DXC compile error: "warning: no output provided for debug - embedding PDB in shader container.  Use -Qembed_debug to silence this warning.\nerror: error reading 'hanabi:vfx_indirect_shader'\n\0"
2024-05-04T09:56:23.210935Z ERROR log: Please report it to https://github.com/gfx-rs/wgpu
2024-05-04T09:56:23.211044Z ERROR log: Handling wgpu errors as fatal by default
thread 'main' panicked at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\backend\wgpu_core.rs:3006:5:
wgpu error: Validation Error

Caused by:
    In Device::create_compute_pipeline
      note: label = `hanabi:compute_pipeline:dispatch_indirect`
    Internal error: DXC compile error: "warning: no output provided for debug - embedding PDB in shader container.  Use -Qembed_debug to silence this warning.\nerror: error reading 'hanabi:vfx_indirect_shader'\n\0"

stack backtrace:
   0:     0x7ff67b224ee2 - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\sys_common\backtrace.rs:44
   1:     0x7ff67b23fccd - core::fmt::rt::Argument::fmt
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\fmt\rt.rs:142
   2:     0x7ff67b23fccd - core::fmt::write
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\fmt\mod.rs:1120
   3:     0x7ff67b2210c1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\io\mod.rs:1846
   4:     0x7ff67b224d0a - std::sys_common::backtrace::_print
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\sys_common\backtrace.rs:47
   5:     0x7ff67b224d0a - std::sys_common::backtrace::print
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\sys_common\backtrace.rs:34
   6:     0x7ff67b226eb9 - std::panicking::default_hook::closure$1
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:272
   7:     0x7ff67b226b75 - std::panicking::default_hook
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:292
   8:     0x7ff67b2273d4 - std::panicking::rust_panic_with_hook
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:781
   9:     0x7ff67b2272a9 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:659
  10:     0x7ff67b225589 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\sys_common\backtrace.rs:171
  11:     0x7ff67b226f76 - std::panicking::begin_panic_handler
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:647
  12:     0x7ff67b255d07 - core::panicking::panic_fmt
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\panicking.rs:72
  13:     0x7ff679b3fdfc - wgpu::backend::wgpu_core::default_error_handler
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\backend\wgpu_core.rs:3006
  14:     0x7ff679932d2d - core::ops::function::Fn::call<void (*)(enum2$<wgpu::Error>),tuple$<enum2$<wgpu::Error> > >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\ops\function.rs:79
  15:     0x7ff679ac7292 - alloc::boxed::impl$49::call<tuple$<enum2$<wgpu::Error> >,dyn$<wgpu::UncapturedErrorHandler<assoc$<Output,tuple$<> > > >,alloc::alloc::Global>
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\alloc\src\boxed.rs:2029
  16:     0x7ff679b3fb86 - wgpu::backend::wgpu_core::ErrorSinkRaw::handle_error
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\backend\wgpu_core.rs:2992
  17:     0x7ff679b1d4d4 - wgpu::backend::wgpu_core::ContextWgpuCore::handle_error<enum2$<wgpu_core::pipeline::CreateComputePipelineError> >
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\backend\wgpu_core.rs:262
  18:     0x7ff679b2f8a5 - wgpu::backend::wgpu_core::impl$7::device_create_compute_pipeline
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\backend\wgpu_core.rs:1201
  19:     0x7ff679b42b72 - wgpu::context::impl$5::device_create_compute_pipeline<wgpu::backend::wgpu_core::ContextWgpuCore>
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\context.rs:2275
  20:     0x7ff679928f5b - wgpu::Device::create_compute_pipeline
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.4\src\lib.rs:2494
  21:     0x7ff6777e1b1f - bevy_render::renderer::render_device::RenderDevice::create_compute_pipeline
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_render-0.13.2\src\renderer\render_device.rs:140
  22:     0x7ff6777ed2bf - bevy_hanabi::render::impl$7::from_world
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_hanabi-0.10.0\src\render\mod.rs:476
  23:     0x7ff6774eb2d3 - bevy_ecs::world::World::init_resource<bevy_hanabi::render::DispatchIndirectPipeline>
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_ecs-0.13.2\src\world\mod.rs:1065
  24:     0x7ff6777cd3f3 - bevy_app::app::App::init_resource<bevy_hanabi::render::DispatchIndirectPipeline>
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_app-0.13.2\src\app.rs:596
  25:     0x7ff6776137e5 - bevy_hanabi::plugin::impl$1::finish
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_hanabi-0.10.0\src\plugin.rs:169
  26:     0x7ff67aee2529 - bevy_app::app::App::finish
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_app-0.13.2\src\app.rs:334
  27:     0x7ff6779f737c - bevy_winit::winit_runner
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_winit-0.13.2\src\lib.rs:258
  28:     0x7ff677a25934 - core::ops::function::FnOnce::call_once<void (*)(bevy_app::app::App),tuple$<bevy_app::app::App> >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\ops\function.rs:250
  29:     0x7ff677a24473 - core::ops::function::FnOnce::call_once<void (*)(bevy_app::app::App),tuple$<bevy_app::app::App> >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\ops\function.rs:250
  30:     0x7ff67aee173d - alloc::boxed::impl$47::call_once<tuple$<bevy_app::app::App>,dyn$<core::ops::function::FnOnce<tuple$<bevy_app::app::App>,assoc$<Output,tuple$<> > >,core::marker::Send>,alloc::alloc::Global>
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\alloc\src\boxed.rs:2015
  31:     0x7ff67aee232a - bevy_app::app::App::run
                               at C:\Users\{USERDIR}\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_app-0.13.2\src\app.rs:308
  32:     0x7ff6774b1f23 - wgpu_dxc_error::main
                               at C:\Users\{USERDIR}\wgpu-dxc-error\src\main.rs:11
  33:     0x7ff6774b26db - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\ops\function.rs:250
  34:     0x7ff6774b148e - core::hint::black_box
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\hint.rs:334
  35:     0x7ff6774b148e - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\std\src\sys_common\backtrace.rs:155
  36:     0x7ff6774b1061 - std::rt::lang_start::closure$0<tuple$<> >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\std\src\rt.rs:166
  37:     0x7ff67b21bf32 - std::rt::lang_start_internal::closure$2
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\rt.rs:148
  38:     0x7ff67b21bf32 - std::panicking::try::do_call
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:554
  39:     0x7ff67b21bf32 - std::panicking::try
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:518
  40:     0x7ff67b21bf32 - std::panic::catch_unwind
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panic.rs:142
  41:     0x7ff67b21bf32 - std::rt::lang_start_internal
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\rt.rs:148
  42:     0x7ff6774b103a - std::rt::lang_start<tuple$<> >
                               at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\std\src\rt.rs:165
  43:     0x7ff6774b1ff9 - main
  44:     0x7ff67b253eac - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  45:     0x7ff67b253eac - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  46:     0x7fff0dbe257d - BaseThreadInitThunk
  47:     0x7fff0ebaaa48 - RtlUserThreadStart
error: process didn't exit successfully: `target\debug\wgpu-dxc-error.exe` (exit code: 101)

It almost appears as if the shader module label hanabi:vfx_indirect_shader defined here is interpreted as a file path in DXC here?

Platform WGPU: 0.19.4 OS: Windows 11 23H2 (22631.3447) GPU: AMD Radeon RX 6600 (driver version 24.4.1)

teoxoy commented 6 months ago

Could you try using InstanceFlags::DISCARD_HAL_LABELS to see if this avoids the issue?

martinhiller commented 6 months ago

Absolutely spot on. Everything works fine with InstanceFlags::DISCARD_HAL_LABELS. Thank you already for this insight!