gfx-rs / wgpu

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

Sometimes cannot create compute pipeline #6129

Open GopherJ opened 3 weeks ago

GopherJ commented 3 weeks ago

Description wgpu sometimes unable to do validator and hence fails to create compute pipeline

thread 'webgpu::stage::tests::webgpu_rpo_from_medium_sized_rows' panicked at src/webgpu/stage.rs:237:17:
assertion `left == right` failed
  left: [8635338869442206704, 11671305615285950885, 15253023094703789604, 7398108415970215319]
 right: [2242391899857912644, 12689382052053305418, 235236990017815546, 5046143039268215739]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test webgpu::stage::tests::webgpu_rpo_from_medium_sized_rows ... FAILED
thread 'webgpu::stage::tests::webgpu_rpo_from_single_row' panicked at src/webgpu/stage.rs:237:17:
assertion `left == right` failed
  left: [0, 0, 0, 0]
 right: [2242391899857912644, 12689382052053305418, 235236990017815546, 5046143039268215739]
test webgpu::stage::tests::webgpu_rpo_from_single_row ... FAILED
thread 'webgpu::stage::tests::webgpu_rpx_from_large_sized_rows' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:3411:5:
wgpu error: Validation Error

Caused by:
  In Device::create_compute_pipeline
    Internal error: new_compute_pipeline_state: "Compilation failed"

test webgpu::stage::tests::webgpu_rpx_from_large_sized_rows ... FAILED
thread 'webgpu::stage::tests::webgpu_rpx_from_medium_sized_rows' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:3411:5:
wgpu error: Validation Error

Caused by:
  In Device::create_compute_pipeline
    Internal error: new_compute_pipeline_state: "Compilation failed"

test webgpu::stage::tests::webgpu_rpx_from_medium_sized_rows ... FAILED
thread 'webgpu::stage::tests::webgpu_rpx_from_single_row' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-22.1.0/src/backend/wgpu_core.rs:3411:5:
wgpu error: Validation Error

Caused by:
test webgpu::stage::tests::webgpu_rpx_from_single_row ... FAILED
  In Device::create_compute_pipeline

    Internal error: new_compute_pipeline_state: "Compilation failed"

Repro steps

  1. https://github.com/GopherJ/webgpu-shaders
  2. run ci test, in this public repo it didn't fail to create compute pipeline yet, but the same code exists in another repo and it failed

Expected vs observed behavior don't fail to do validation

Extra materials Screenshots to help explain your problem. Validation logs can be attached in case there are warnings and errors. Zip-compressed API traces and GPU captures can also land here.

Platform Information about your OS, version of wgpu, your tech stack, etc.

GopherJ commented 3 weeks ago

wgpu seems to be behaving very differently with different runs of CI using macos-latest

jimblandy commented 2 weeks ago

@GopherJ Is this a duplicate of #6110?

GopherJ commented 2 weeks ago

yes lol, sorry

GopherJ commented 2 weeks ago

before closing, actually this on throws an error, are they the same? I'm not 100% sure yet because that one is just too slow

dtzxporter commented 1 week ago

Your code has undefined behavior:

            let result =
                unsafe { core::slice::from_raw_parts(data.as_ptr() as *mut [BaseElement; 4], n) };

            // With the current interface, we have to make sure all mapped views are
            // dropped before we unmap the buffer.
            drop(data);
            staging_buffer.unmap(); // Unmaps buffer from memory

You're dropping the mapped buffer, which you haven't converted to a Vec<> yet, so data.as_ptr() becomes invalid, leading to invalid memory being accessed. Convert result to a Vec<> before dropping/unmapping the buffer.