vulkano-rs / vulkano

Safe and rich Rust wrapper around the Vulkan API
Apache License 2.0
4.48k stars 433 forks source link

PersistentDescriptorSet pool size assertion fails #2102

Closed trevex closed 1 year ago

trevex commented 1 year ago

Template

If you dont understand something just leave it. If you can provide more detailed information than the template allows for, please ignore the template and present all of your findings.

Issue

I recently started using vulkano and am currently testing and playing around with it. Unfortunately I ran into an asserting failing when creating a PersistentDescriptorSet and I fail to understand why. The code is very similar to the immutable_image example. Basically the first descriptor set I am trying to create fails:

    let layout = pipeline.layout().set_layouts().get(0).unwrap();
    let textures_set = PersistentDescriptorSet::new( //  << PANICS HERE
        ctx.descriptor_set_allocator(),
        layout.clone(),
        [WriteDescriptorSet::image_view_sampler_array(
            0,
            0,
            [(texture, sampler)],
        )],
    )
    .unwrap();

    let layout = pipeline.layout().set_layouts().get(1).unwrap();
    let vertex_buffer_set = PersistentDescriptorSet::new(
        ctx.descriptor_set_allocator(),
        layout.clone(),
        [WriteDescriptorSet::buffer(0, vertex_buffer.clone())],
    )
    .unwrap();

Interestingly if I swap the two code blocks above, it will still panic creating the texture_set. So it seems to heavily to be related to how I create it, but I do not recognize something wrong with it. Just for context the shader definitions for them from vertex shader and fragment shader respectively:

    layout(set = 1, binding = 0) readonly buffer Vertices { ChunkVertex vertices[]; };
    layout(set = 0, binding = 0) uniform sampler2D textures[]; // bindless using GL_EXT_nonuniform_qualifier

The failed assertion with stacktrace looks as follows:

thread 'main' panicked at 'assertion failed: !pool_sizes.is_empty()', /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/pool.rs:71:9
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: vulkano::descriptor_set::pool::DescriptorPool::new
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/pool.rs:71:9
   4: vulkano::descriptor_set::allocator::FixedPool::new
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/allocator.rs:260:21
   5: vulkano::descriptor_set::allocator::FixedEntry::new
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/allocator.rs:225:19
   6: <vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator as vulkano::descriptor_set::allocator::DescriptorSetAllocator>::allocate::{{closure}}
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/allocator.rs:178:17
   7: vulkano::descriptor_set::allocator::sorted_map::SortedMap<K,V>::get_or_try_insert
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/allocator.rs:505:52
   8: <vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator as vulkano::descriptor_set::allocator::DescriptorSetAllocator>::allocate
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/allocator.rs:176:21
   9: <alloc::sync::Arc<vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator> as vulkano::descriptor_set::allocator::DescriptorSetAllocator>::allocate
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/allocator.rs:200:9
  10: vulkano::descriptor_set::persistent::PersistentDescriptorSet::new_variable
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/persistent.rs:93:21
  11: vulkano::descriptor_set::persistent::PersistentDescriptorSet::new
             at /home/nik/.cargo/registry/src/github.com-1ecc6299db9ec823/vulkano-0.32.0/src/descriptor_set/persistent.rs:58:9
  12: mondu::main
             at ./src/main.rs:197:24
  13: core::ops::function::FnOnce::call_once
             at /build/rustc-1.64.0-src/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Any help is appreciated. I assume I am doing something stupid or unintended, but am not able to find the issue.

trevex commented 1 year ago

I reproduced the issue using the image example here: https://github.com/trevex/vulkano/blob/reproduce-descriptor-set-issue/examples/src/bin/image/main.rs

However I stumbled upon the runtime descriptor array feature that was required and an now looking into the provided example. I expect the issue above to resolve itself after studying https://github.com/trevex/vulkano/blob/reproduce-descriptor-set-issue/examples/src/bin/runtime_array/main.rs.

Closing for now.

trevex commented 1 year ago

Leveraging the runtime array features indeed fixes the issue.