gfx-rs/wgpu-rs

Mip-maps level 1 and above for every layer of a cube texture are stored on layers 4 and 5 only

Closed this issue · 8 comments

I tried various methods (the code from mip-map example too), but when I render the cube texture as skybox, every mip-map beyond level 0 is drawn on layers 4 and 5 (+/-Z faces) of the cube.

This is how I generate mip-maps for every layer:

for layer in 0..6 {
    /* update uniform buffers */
    for mip in 0..max_mip_level {
        let texture_view_desc = wgpu::TextureViewDescriptor {
            label: Some("cubemap_face"),
            format: Some(wgpu::TextureFormat::Rgba16Float),
            dimension: Some(wgpu::TextureViewDimension::D2),
            aspect: wgpu::TextureAspect::All,
            base_mip_level: mip,
            level_count: std::num::NonZeroU32::new(1),
            base_array_layer: layer,
            array_layer_count: None,
        };
        let view = texture.create_view(&texture_view_desc);

        {
            let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
                color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
                    attachment: &view,
                    resolve_target: None,
                    ops: wgpu::Operations {
                        load: wgpu::LoadOp::Clear(wgpu::Color {
                            r: 0.0,
                            g: 0.0,
                            b: 0.0,
                            a: 1.0,
                        }),
                        store: true,
                    },
                }],
                depth_stencil_attachment: None,
            });
            /* rendering stuff */
        }
    }
}

And this is how I sample it in the shader:

layout(set = 0, binding = 0) uniform textureCube t_Cubemap;
layout(set = 0, binding = 1) uniform sampler s_Cubemap;
  
void main()
{
    vec3 env_color = textureLod(samplerCube(t_Cubemap, s_Cubemap), v_local_pos, 1.2).rgb;

    /* gamma correction */

    f_color = vec4(env_color, 1.0);
}
kvark commented

Thank you for filing! Issues like this should be trivially addressable once we can reproduce.
Do you have a repro case?
What platform are you running on?
You could also record an API trace and attach a ZIP here, see https://github.com/gfx-rs/wgpu/wiki/Debugging-wgpu-Applications#tracing-infrastructure

I tested it on Windows 10 with Vulkan backend

Here is the API trace (hope I did it right):
trace.zip

How else can I help with reproduction?

kvark commented

Oh, the last thing we'll need to know is what version of wgpu-rs you were using, exactly.

I'm using version 0.6.0

kvark commented

Looks like we are missing a bit of validation here. Metal complains:

_mtlValidateArgumentsForTextureViewOnDevice:1595: failed assertion `Texture Creation
newSliceRange.length(6) must equal (1) for textureType (MTLTextureType2D).'

Your array_layer_count should be Some(1) to fix this one. I'll hack it in the trace, we'll see if there is more to this.

kvark commented

Works fine on Metal after I patch that. Going to add the validation momentarily...

Your array_layer_count should be Some(1) to fix this one. I'll hack it in the trace, we'll see if there is more to this.

Yeah this was the problem.
Thank you

kvark commented

PR is coming, going to close this given the resolution now