Wgpu-rs: RODS: assertion failed: `(left == right)` extending a state that is already a transition

Created on 10 Jun 2020  路  8Comments  路  Source: gfx-rs/wgpu-rs

Howdy! I am trying to use RODS by reading from a depth buffer as a depth attachment, and a texture in a shader. I am not however writing to it as a depth attachment:

  • In my Pipeline, I said depth_write_enabled: false under the depth_stencil_state:
    rust depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: false, depth_compare: wgpu::CompareFunction::Less, stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE, stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE, stencil_read_mask: 0, stencil_write_mask: 0, }),
  • In the render pass, I said:
    rust depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { attachment: &self.draw_depth_buffer, depth_load_op: wgpu::LoadOp::Load, depth_store_op: wgpu::StoreOp::Store, clear_depth: 1.0, depth_read_only: true, stencil_load_op: wgpu::LoadOp::Clear, stencil_store_op: wgpu::StoreOp::Store, clear_stencil: 0, stencil_read_only: false, }),


The backtrace

C:/Users/Patrik/.cargo/bin/cargo.exe run --color=always --example water
   Compiling wgpu v0.5.0 (C:\Projects\wgpu-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 5.14s
     Running `target\debug\examples\water.exe`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(ATTACHMENT_WRITE)`,
 right: `None`: extending a state that is already a transition', C:\Users\Patrik\.cargo\git\checkouts\wgpu-53e70f8674b08dd4\eaf8f4a\wgpu-core\src\track\texture.rs:203:37
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.46\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print_fmt
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\sys_common\backtrace.rs:78
   2: std::sys_common::backtrace::_print::{{impl}}::fmt
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\sys_common\backtrace.rs:59
   3: core::fmt::write
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libcore\fmt\mod.rs:1076
   4: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\io\mod.rs:1537
   5: std::sys_common::backtrace::_print
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\sys_common\backtrace.rs:62
   6: std::sys_common::backtrace::print
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\sys_common\backtrace.rs:49
   7: std::panicking::default_hook::{{closure}}
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:198
   8: std::panicking::default_hook
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:218
   9: std::panicking::rust_panic_with_hook
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:486
  10: std::panicking::begin_panic_handler
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:388
  11: std::panicking::begin_panic_fmt
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:342
  12: wgpu_core::track::texture::{{impl}}::merge
             at C:\Users\Patrik\.cargo\git\checkouts\wgpu-53e70f8674b08dd4\eaf8f4a\wgpu-core\src\track\texture.rs:203
  13: wgpu_core::track::ResourceTracker<wgpu_core::track::texture::TextureState>::merge_extend<wgpu_core::track::texture::TextureState>
             at C:\Users\Patrik\.cargo\git\checkouts\wgpu-53e70f8674b08dd4\eaf8f4a\wgpu-core\src\track\mod.rs:341
  14: wgpu_core::track::TrackerSet::merge_extend
             at C:\Users\Patrik\.cargo\git\checkouts\wgpu-53e70f8674b08dd4\eaf8f4a\wgpu-core\src\track\mod.rs:489
  15: wgpu_core::hub::Global<wgpu_core::hub::IdentityManagerFactory>::command_encoder_run_render_pass<wgpu_core::hub::IdentityManagerFactory,gfx_backend_vulkan::Backend>
             at C:\Users\Patrik\.cargo\git\checkouts\wgpu-53e70f8674b08dd4\eaf8f4a\wgpu-core\src\command\render.rs:935
  16: wgpu::backend::direct::{{impl}}::encoder_end_render_pass
             at .\src\backend\direct.rs:857
  17: wgpu::{{impl}}::drop
             at .\src\lib.rs:1550
  18: core::ptr::drop_in_place<wgpu::RenderPass>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libcore\ptr\mod.rs:184
  19: water::{{impl}}::render
             at .\examples\water\main.rs:632
  20: water::framework::run_async::{{closure}}::{{closure}}<water::Example>
             at .\examples\framework.rs:176
  21: winit::platform_impl::platform::event_loop::{{impl}}::run_return::{{closure}}<(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop.rs:200
  22: alloc::boxed::{{impl}}::call_mut<(winit::event::Event<()>, mut winit::event_loop::ControlFlow*),FnMut<(winit::event::Event<()>, mut winit::event_loop::ControlFlow*)>>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\liballoc\boxed.rs:1064
  23: winit::platform_impl::platform::event_loop::runner::{{impl}}::call_event_handler::{{closure}}<()>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop\runner.rs:239
  24: std::panic::{{impl}}::call_once<(),closure-0>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panic.rs:318
  25: std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure-0>,()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panicking.rs:297
  26: winit::platform_impl::platform::window::TASKBAR_LIST::__getit
  27: std::panicking::try<(),std::panic::AssertUnwindSafe<closure-0>>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panicking.rs:274
  28: std::panic::catch_unwind<std::panic::AssertUnwindSafe<closure-0>,()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panic.rs:394
  29: winit::platform_impl::platform::event_loop::runner::EventLoopRunner<()>::catch_unwind<(),(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop\runner.rs:150
  30: winit::platform_impl::platform::event_loop::runner::EventLoopRunner<()>::call_event_handler<()>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop\runner.rs:233
  31: winit::platform_impl::platform::event_loop::runner::EventLoopRunner<()>::send_event<()>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop\runner.rs:208
  32: winit::platform_impl::platform::event_loop::SubclassInput<()>::send_event<()>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop.rs:90
  33: winit::platform_impl::platform::event_loop::public_window_callback::{{closure}}<()>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop.rs:819
  34: core::ops::function::FnOnce::call_once<closure-0,()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libcore\ops\function.rs:232
  35: std::panic::{{impl}}::call_once<isize,closure-0>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panic.rs:318
  36: std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure-0>,isize>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panicking.rs:297
  37: std::panicking::try::do_catch<std::panic::AssertUnwindSafe<closure-0>,isize>
  38: std::panicking::try<isize,std::panic::AssertUnwindSafe<closure-0>>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panicking.rs:274
  39: std::panic::catch_unwind<std::panic::AssertUnwindSafe<closure-0>,isize>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\panic.rs:394
  40: winit::platform_impl::platform::event_loop::runner::EventLoopRunner<()>::catch_unwind<(),isize,closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop\runner.rs:150
  41: winit::platform_impl::platform::event_loop::public_window_callback<()>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop.rs:1893
  42: DefSubclassProc
  43: DefSubclassProc
  44: CallWindowProcW
  45: CallWindowProcW
  46: glPushClientAttrib
  47: CallWindowProcW
  48: DispatchMessageW
  49: IsWindowVisible
  50: KiUserCallbackDispatcher
  51: NtUserDispatchMessage
  52: DispatchMessageW
  53: winit::platform_impl::platform::event_loop::EventLoop<()>::run_return<(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop.rs:215
  54: winit::platform_impl::platform::event_loop::EventLoop<()>::run<(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\platform_impl\windows\event_loop.rs:185
  55: winit::event_loop::EventLoop<()>::run<(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.22.2\src\event_loop.rs:149
  56: water::framework::run_async::{{closure}}<water::Example>
             at .\examples\framework.rs:112
  57: core::future::from_generator::{{impl}}::poll<generator-0>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libcore\future\mod.rs:73
  58: futures_executor::local_pool::block_on::{{closure}}<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-executor-0.3.5\src\local_pool.rs:317
  59: futures_executor::local_pool::run_executor::{{closure}}<(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-executor-0.3.5\src\local_pool.rs:87
  60: std::thread::local::LocalKey<alloc::sync::Arc<futures_executor::local_pool::ThreadNotify>>::try_with<alloc::sync::Arc<futures_executor::local_pool::ThreadNotify>,closure-0,()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\thread\local.rs:263
  61: std::thread::local::LocalKey<alloc::sync::Arc<futures_executor::local_pool::ThreadNotify>>::with<alloc::sync::Arc<futures_executor::local_pool::ThreadNotify>,closure-0,()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\thread\local.rs:239
  62: futures_executor::local_pool::run_executor<(),closure-0>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-executor-0.3.5\src\local_pool.rs:83
  63: futures_executor::local_pool::block_on<core::future::from_generator::GenFuture<generator-0>>
             at C:\Users\Patrik\.cargo\registry\src\github.com-1ecc6299db9ec823\futures-executor-0.3.5\src\local_pool.rs:317
  64: water::framework::run<water::Example>
             at .\examples\framework.rs:198
  65: water::main
             at .\examples\water\main.rs:639
  66: std::rt::lang_start::{{closure}}<()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\rt.rs:67
  67: std::rt::lang_start_internal::{{closure}}
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\rt.rs:52
  68: std::panicking::try::do_call
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:297
  69: std::panicking::try
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panicking.rs:274
  70: std::panic::catch_unwind
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\panic.rs:394
  71: std::rt::lang_start_internal
             at /rustc/4bd32c98047a809ba5fd1fac2aa044638e5f2105\/src\libstd\rt.rs:51
  72: std::rt::lang_start<()>
             at C:\Users\Patrik\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src\libstd\rt.rs:67
  73: main
  74: invoke_main
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  75: __scrt_common_main_seh
             at d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  76: BaseThreadInitThunk
  77: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[2020-06-09T23:29:36Z ERROR gfx_memory::heaps] Heaps still have 11 types live on drop
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(15872) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(65536) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(329728) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(3145728) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(256) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(2048) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(16384) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::general] Memory leak: SizeEntry(131072) is still used
[2020-06-09T23:29:36Z ERROR gfx_memory::allocator::linear] Not all allocation from LinearAllocator was freed
[2020-06-09T23:29:36Z ERROR gfx_descriptor::allocator] DescriptorAllocator is dropped
error: process didn't exit successfully: `target\debug\examples\water.exe` (exit code: 101)

And the error occurs at the end of a RenderPass block, presumably during the Drop impl for it.

If you need more information, please tell me.

Thanks, Patrik

bug

Most helpful comment

No worries! Working around that turned out to be fairly straightforward, and now I'm able reproduce the issue thanks to your example. Working on it...

By saying that's not how LoadOp::Clear is intended for read-only depth, do you mean to say that I am never allowed to render to the buffer, at all?

I'm just saying that "Clear" is a mutation, which comes in conflict with RODS, which is supposed to be immutable for the scope of the pass. I'll add proper checks to guard against that.

All 8 comments

I'm just linking gfx-rs/wgpu#685 for reference, since it was the PR which tried to implement RODS.

Could you make something for me to reproduce? I did test RODS when landing this on a simple example, so something minor must be off. Could be in these lines:

                        let new_use = if is_depth_stencil_read_only(at, view.range.aspects) {
                            is_ds_read_only = true;
                            TextureUse::ATTACHMENT_READ
                        } else {
                            TextureUse::ATTACHMENT_WRITE
                        };

The error basically says that your depth-stencil attachment is already considered to be writable by the pass.

Sure, here's a repo where I uploaded a copy of this repository with a stripped down version of the example. Run it with cargo run --example water, and the files are in ./examples/water/*.

https://github.com/OptimisticPeach/MRE_RODS_bug/tree/master

@OptimisticPeach I can't run that because it fails for multiple unrelated reasons:

  • shader translation on Metal doesn't like a local variable terrain_depth colliding with the global uniform
  • vertex buffers are all messed up:
        let water_vertex_size = mem::size_of::<f32>();
        let terrain_vertex_size = mem::size_of::<f32>();

        let water_vertices = vec![0.0f32];

        let terrain_vertices = vec![0.0f32];

Another thing that is wrong is the use of LoadOp::Clear for the read-only depth. It needs to be Load. In the future wgpu versions, we'll make this distinct at the type level.

I'm so sorry! It was not my intention to break the code; I just kept removing things to make it a smaller reproduction example. I've uploaded a completely new version to the repo which contains the entire example. I've also fixed the name issue in the shader.

By saying that's not how LoadOp::Clear is intended for read-only depth, do you mean to say that I am _never_ allowed to render to the buffer, at all? Because my intention was to render to it in one pass, and only read from it in another pass.

In any case, I'm really sorry for any lost time, and inconvenience.

Thanks,
Patrik

No worries! Working around that turned out to be fairly straightforward, and now I'm able reproduce the issue thanks to your example. Working on it...

By saying that's not how LoadOp::Clear is intended for read-only depth, do you mean to say that I am never allowed to render to the buffer, at all?

I'm just saying that "Clear" is a mutation, which comes in conflict with RODS, which is supposed to be immutable for the scope of the pass. I'll add proper checks to guard against that.

Fix is coming in https://github.com/gfx-rs/wgpu/pull/712, just need a review and to check the validation messages on Linux.

Fixed in #370 update. Note that the RODS API is likely to change one more time in the near future, but your example code should be unblocked now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

branpk picture branpk  路  3Comments

OptimisticPeach picture OptimisticPeach  路  3Comments

lordnoriyuki picture lordnoriyuki  路  4Comments

imjasonmiller picture imjasonmiller  路  3Comments

Lokathor picture Lokathor  路  3Comments