Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command encoder released without endEncoding #2077

Closed
kvark opened this issue Oct 15, 2021 · 3 comments
Closed

Command encoder released without endEncoding #2077

kvark opened this issue Oct 15, 2021 · 3 comments
Labels
api: metal Issues with Metal area: correctness We're behaving incorrectly type: bug Something isn't working

Comments

@kvark
Copy link
Member

kvark commented Oct 15, 2021

Description
Still getting these errors from Gecko sometimes.

Repro steps
None

Expected vs observed behavior
No Metal validation error is expected

Extra materials
https://bugzilla.mozilla.org/show_bug.cgi?id=1729648#c5

@kpreid
Copy link
Contributor

kpreid commented Apr 23, 2022

Here's a repro (of at least one way to get this error; I don't know if Gecko is hitting the same case I am, but I'm mentioning this here to hopefully avoid filing duplicate issues):

  1. At wgpu commit 0b61a19
  2. Take wgpu/examples/hello-triangle, perhaps.
  3. Comment out rpass.set_pipeline(&render_pipeline); — i.e. submit a render pass without having specified the pipeline.

The results I get are:

[2022-04-23T22:20:09Z ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 1, Metal)>`
    In a draw command, indexed:false indirect:false
    render pipeline must be set

', wgpu/src/backend/direct.rs:2286:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-[_MTLCommandEncoder dealloc]:131: failed assertion `Command encoder released without endEncoding'
Abort trap: 6

By inserting logging, the assertion appears to occur while Rust is unwinding, unsurprisingly when wgpu_hal::metal::CommandState is dropping its render field of type Option<mtl::RenderCommandEncoder>. Experimentally adding the code

impl Drop for CommandEncoder {
    fn drop(&mut self) {
        if let Some(render) = self.state.render.take() {
            render.end_encoding();
        }
    }
}

to wgpu_hal::metal::CommandEncoder causes the program to finish panicking and exit without the assertion, but I haven't studied the code architecture and certainly can't say this is a correct general fix. (Presumably it at least should treat blit and compute similarly?)

@RayMarch
Copy link

RayMarch commented Jun 3, 2022

i encountered a very similar error today which might be related:

  • i created a render pipeline with a PrimitiveTopology::TriangleStrip and strip_index_format: Some(IndexFormat::Uint32).
  • created a render pass, bound the pipeline
  • bound an index buffer with mismatching index format IndexFormat::Uint16
  • called render_pass.draw_indexed(...)
  • drop the render pass

and i got this MTL error on top of wgpu's validation error

[2022-06-03T21:38:39Z ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `render encoder`
    In a draw command, indexed:true indirect:false
      note: render pipeline = `<RenderPipeline-(0, 1, Metal)>`
    pipeline index format (Uint32) and buffer index format (Uint16) do not match

', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/backend/direct.rs:2273:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
-[_MTLCommandEncoder dealloc]:70: failed assertion `Command encoder released without endEncoding'

@cwfitzgerald cwfitzgerald added api: metal Issues with Metal area: correctness We're behaving incorrectly type: bug Something isn't working labels Jun 4, 2022
Patryk27 pushed a commit to Patryk27/wgpu that referenced this issue Nov 23, 2022
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Dec 5, 2022
@jimblandy
Copy link
Member

We believe this was fixed by #4023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: metal Issues with Metal area: correctness We're behaving incorrectly type: bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

6 participants