bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.59k stars 1.92k forks source link

setViewMode sequential mode seems to be broken #3299

Closed npnp closed 1 month ago

npnp commented 1 month ago

Describe the bug

When bgfx::setViewMode is called with bgfx::ViewMode::Sequential, the order of views should be in the order in witch bgfx::submit calls where issued, however it seems that the views are always sorted by their ID:

To Reproduce

  1. Modify the drawing loop section in the 01-cubes example to draw each cube in separate view:

            // Submit 11x11 cubes.
            //for (uint32_t yy = 0; yy < 11; ++yy)
            //{
            //bgfx::ViewId order[] = { 0,1,2,3,4,5,6,7,8,9,10 };
            bgfx::ViewId order[] =   { 0,8,6,3,10,5,2,7,1,9,4 };
            int depth = 0;
                for (uint32_t xx = 0; xx < 11; ++xx)
                {
                    //bgfx::touch(order[xx]);
                    float yy = 5;
                    float mtx[16];
                    bx::mtxRotateXY(mtx, time + xx*0.21f, time + yy*0.37f);
                    mtx[12] = -15.0f + float(xx)*3.0f;
                    mtx[13] = -15.0f + float(yy)*3.0f;
                    mtx[14] = 0.0f;
    
                    // Set model matrix for rendering.
                    bgfx::setTransform(mtx);
    
                    // Set vertex and index buffer.
                    bgfx::setVertexBuffer(0, m_vbh);
                    bgfx::setIndexBuffer(ibh);
    
                    // Set render states.
                    bgfx::setState(state);
    
                    // Submit primitive for rendering to view 0.
                    bgfx::setViewMode(order[xx], bgfx::ViewMode::Sequential);
                    bgfx::submit(order[xx], m_program);//, depth++);
                }
            //}
  2. Open the file in RenderDoc

  3. Capture a frame and observe the view order: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10:

Capture

Expected behavior The order should be the same as order of submit calls, so: 0,8,6,3,10,5,2,7,1,9,4

If the order is set explictly using setViewOrder, then the behavior is as expected:

Capture1

Additional context

PC Windows 10 Nvidia 3060 DirectX 11 & Vulkan renderers

bkaradzic commented 1 month ago

You didn't understood that correctly... bgfx::ViewMode sets order of draw calls within the view, not view order. To set view order use bgfx::setViewOrder https://bkaradzic.github.io/bgfx/bgfx.html#_CPPv4N4bgfx12setViewOrderE6ViewId8uint16_tPK6ViewId

There is example of usage here: https://github.com/bkaradzic/bgfx/blob/00fa5ad179f5aa13c1e44d0bcbccdc535aba2d00/examples/09-hdr/hdr.cpp#L450-L463

npnp commented 1 month ago

Oh yeah that makes sense, sorry for the noise!