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.87k stars 1.93k forks source link

Vulkan Backend - incorrect mipmap generation for cubemap frame buffers. #3236

Open volcoma opened 8 months ago

volcoma commented 8 months ago

Hi, i've found a bug with the implementation of the mipmap generation in

void TextureVK::resolve function.

Currently it only generates mipmap for one of the faces of the cubemap as seen here. This works fine for dx11 and opengl backends I have a frame buffer which is filled properly

for(int i = 0; i < 6; ++i)
{
gfx::frame_buffer::ptr output ...  per face

gfx::blit(pass.id,
             cubemap_fbo->get_texture()->native_handle(),
             0,
             0,
             0,
             uint16_t(face),
             output->get_texture()->native_handle());
} 

after that i use a pass to resolve the texture so it can force generate the mipmaps

            gfx::render_pass pass("cubemap_generate_mips");
            pass.bind(cubemap_fbo.get());
            pass.touch();

Screenshot 2024-01-01 154044

if i change the function a bit

            auto numLayers = _numLayers;
            if(m_type == VK_IMAGE_VIEW_TYPE_CUBE || VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
            {
                numLayers = 6;
            }

and use numLayers instead of _numLayers it fixes it.

Screenshot 2024-01-01 154001

I am not sure if it is the same for both VK_IMAGE_VIEW_TYPE_CUBE and VK_IMAGE_VIEW_TYPE_CUBE_ARRAY but i think it is. Could not find much info about it.

bkaradzic commented 8 months ago

cc @pezcode

pezcode commented 8 months ago

The easiest fix would be to use the existing m_numSides, that would also work for layered cube maps, i.e. 6*N

volcoma commented 4 months ago

Hi. Any idea when this fix would hit master? Seemed like a trivial fix, but like 5 months passed.

bkaradzic commented 4 months ago

@volcoma You can test fix, and send PR.