gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

[GL] Currently bound framebuffer is not valid for glDrawArrays operation #3587

Closed Gordon-F closed 3 years ago

Gordon-F commented 3 years ago

Short info header:

Find some regressions after merged https://github.com/gfx-rs/gfx/pull/3571:

Tested with hello-triangle wgpu example.

  1. thread unnamed panicked at 'called Option::unwrap() on a None value', /Users/indish/Dev/RustProjects/gfx/src/backend/gl/src/command.rs:527:64
    let attachment_indices = subpass
            .color_attachments
            .iter()
            .map(|&index| state.attachments[index].color_index.unwrap())
            .collect();

After some hacks works fine:

let attachment_indices = subpass
            .color_attachments
            .iter()
            .map(|&index| state.attachments[index].color_index)
            .filter_map(|e| e)
            .collect();
  1. Currently bound framebuffer is not valid for glDrawArrays operation
2021-01-14 18:53:23.181 13658-13715/rust.example.hello_triangle E/gfx_backend_gl: [API/Error] ID 95 : Error:glDrawArrays::currently bound framebuffer is not valid for this operation
2021-01-14 18:53:23.184 13658-13714/rust.example.hello_triangle I/RustStdoutStderr: thread '<unnamed>' panicked at 'Error InvalidFramebufferOperation executing command: Draw { primitive: 4, vertices: 0..3, instances: 0..1 }', /Users/indish/Dev/RustProjects/gfx/src/backend/gl/src/queue.rs:1066:13
2021-01-14 18:53:23.184 13658-13714/rust.example.hello_triangle I/RustStdoutStderr: stack backtrace:

Full OpenGL ES Trace.

Vulkan works fine.

kvark commented 3 years ago

Thank you for filing! What's the use case that hits this assertion? The color_index is assigned by the following code:

        for info in attachment_infos {
            let view = info.image_view.clone();
            let aspects = view.aspects();
            let color_index = if aspects.contains(Aspects::COLOR) {
                colors.push(view);
                Some(colors.len() as u8 - 1)
            } else {
                depth_stencil = Some(view);
                None
            };
            attachments.push(AttachmentInfo {
                color_index,
                clear_value: info.clear_value,
            })
        }

So for each attachment that has a color, color_index should be Some, and in the affected loop we are iterating through color_attachments. So something seems off. Please provide more info about this test case.

Gordon-F commented 3 years ago

@kvark I tested this case with wgpu hello-triangle with wgpu from this branch.

But now i tested gfx-rs quad example and got same error:

EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, egl_color_buffer_format *, EGLBoolean) returns 0x3000
AdapterInfo { name: "Mali-T830", vendor: 5045, device: 0, device_type: IntegratedGpu }
Memory types: [MemoryType { properties: CPU_VISIBLE | CPU_CACHED, heap_index: 1 }, MemoryType { properties: CPU_VISIBLE, heap_index: 1 }, MemoryType { properties: DEVICE_LOCAL, heap_index: 0 }, MemoryType { properties: DEVICE_LOCAL, heap_index: 0 }]
formats: Some([Rgba8Srgb, Bgra8Srgb])
SwapchainConfig { present_mode: FIFO, composite_alpha_mode: OPAQUE, format: Rgba8Srgb, extent: Extent2D { width: 1024, height: 768 }, image_count: 2, image_layers: 1, image_usage: COLOR_ATTACHMENT }
[src/backend/gl/src/device.rs:869] &subpass = SubpassDesc {
    colors: [
        (
            0,
            ColorAttachmentOptimal,
        ),
    ],
    depth_stencil: None,
    inputs: [],
    resolves: [],
    preserves: [],
}
[src/backend/gl/src/device.rs:875] &color_attachments = [
    0,
]
[src/backend/gl/src/device.rs:875] &depth_stencil = None
[src/backend/gl/src/command.rs:522] &state.attachments = [
    AttachmentInfo {
        color_index: None,
        clear_value: ClearValue {
            color: [
                1061997773,
                1061997773,
                1065353216,
            ],
            depth_stencil: ClearDepthStencil {
                depth: 0.8,
                stencil: 1061997773,
            },
        },
    },
]
[src/backend/gl/src/command.rs:523] &subpass.color_attachments = [
    0,
]
I/RustStdoutStderr: thread '<unnamed>' panicked at 'Error InvalidFramebufferOperation executing command: Draw { primitive: 4, vertices: 0..6, instances: 0..1 }', src/backend/gl/src/queue.rs:1066:13
I/RustStdoutStderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
W/libEGL: EGLNativeWindowType 0x72f97a6010 disconnect failed
I/RustStdoutStderr: DROPPED!
kvark commented 3 years ago

I'm not able to debug at this very moment due to #3588 Could you step into begin_render_pass to see why color_index isn't getting set properly?

Gordon-F commented 3 years ago

Because aspects is empty?

[src/backend/gl/src/command.rs:819] &info = RenderAttachmentInfo {
    image_view: Renderbuffer {
        raw: 1,
        aspects: (empty),
    },
    clear_value: ClearValue {
        color: [
           1061997773,
           1061997773,
           1065353216,
       ],
       depth_stencil: ClearDepthStencil {
           depth: 0.8,
           stencil: 1061997773,
       },
   },
}