gfx-rs/wgpu-rs

[WebGL] Cannot create INDEX buffer.

Tnze opened this issue · 10 comments

Tnze commented

The code that caused the error

let index: Vec<u32> = vec![0, 1, 2];

let index_buffer = self.device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
    label: Some("Index Buffer"),
    contents: bytemuck::cast_slice(&index),
    usage: wgpu::BufferUsage::INDEX,
});

The error message:

wgpu_webgl_test.js:685 gl backend capability does not allow a buffer with usage TRANSFER_DST | INDEX

I don't understand what TRANSFER_DST is, and I didn't specify it.

Entire example

wgpu-webgl-test.zip

Test steps:

cargo install wasm-pack
npm i serve

wasm-pack build --target web
serve
# then open http://localhost:5000/pkg in browser
Tnze commented

Then I noticed the example texture-arrays create index buffer too. But after my little effort, following this guide, I didn't compile successfully:

> git checkout origin/gecko
> $env:RUSTFLAGS="--cfg=web_sys_unstable_apis"
> cargo build --target wasm32-unknown-unknown --example texture-arrays
    Updating `https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git` index
    Updating git repository `https://github.com/gfx-rs/wgpu`
    Updating git repository `https://github.com/gfx-rs/gfx`
error: failed to select a version for `gfx-backend-gl`.
    ... required by package `wgpu v0.6.0 (C:\Users\Tnze\Documents\Projects\rust\wgpu-rs)`
versions that meet the requirements `*` are: 0.7.0

the package `wgpu` depends on `gfx-backend-gl`, with features: `x11` but `gfx-backend-gl` does not have these features.


failed to select a version for `gfx-backend-gl` which could resolve this conflict

Maybe a new issue is needed. 😅

@Tnze That's weird, I thought that got fixed on latest master. Definitely a new issue is needed.

So this is currently the big issue with the GL backend. There needs to be some fairly major changes to allow they kinds of copying we want to do to actually work. We need to make all cpu side buffers to be actual rust buffers not GL buffers. I'm not sure if that's also a requirement on desktop GL, but it should also make our usage of GL more ideomatic.

This seems to be fixed in the latest master, a new bug appears instead (wgpu-rs cube example):

panicked at 'assertion failed: nb_map.insert(res.name.clone(), (register, slot)).is_none()', /home/daxpedda/.cargo/git/checkouts/gfx-e86e7f3ebdbc4218/cd96e77/src/backend/gl/src/device.rs:466:17

I'm assuming this is unrelated.

@daxpedda You could also try to disable cross feature for WebGL target.

Unfortunately, cube example still doesn't work with WebGL target because of issues on gfx-backend-gl side:

WebGL: INVALID_OPERATION: bindBuffer: buffers bound to non ELEMENT_ARRAY_BUFFER targets can not be bound to ELEMENT_ARRAY_BUFFER target

cube.js:346 panicked at 'Error InvalidOperation executing command: BindIndexBuffer(WebBufferKey(2v1))

We can close this issue in favor of gfx-rs/gfx#3669

kvark commented

Let's keep it for now, and close once the relevant fixes reach wgpu-rs

gfx-rs/gfx#3682 landed, does this mean wgpu-rs is fixed, or does gfx still need to be updated?

I ask because I want to use wgpu in a project that uses index buffers, but not sure if pulling from the last release works, or if I need to use the github repo instead.

kvark commented

This should be included in wgpu-rs master. Please try it out!

Thanks! - is the current master very unstable or would it be worth building off of?

kvark commented

it's slightly changing these days, and is calming down. I don't expect substantial changes at this point, and we are about to publish 0.8.