zink: Fix MSVC RTC in zink_get_framebuffer_imageless()
authorCharles Baker <charles@juicelabs.co>
Fri, 21 Jan 2022 07:41:54 +0000 (20:41 +1300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 8 Feb 2022 14:43:00 +0000 (14:43 +0000)
The bit fields in zink_framebuffer_state cause a false positive with
MSVC's run-time checks enabled.  setting state.num_attachments in
zink_get_framebuffer_imageless().  Writing some bits of num_attachments
involves reading bits from layers and samples that haven't been
initialized.

Fixed by assigning to num_attachments earlier in the function.  Not
quite sure why that makes a difference but at a guess there's a
heuristic that considers assignment close to declaration as
initialization.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14566>

src/gallium/drivers/zink/zink_framebuffer.c

index 192450d..eddb9fe 100644 (file)
@@ -143,6 +143,8 @@ zink_get_framebuffer_imageless(struct zink_context *ctx)
    assert(zink_screen(ctx->base.screen)->info.have_KHR_imageless_framebuffer);
 
    struct zink_framebuffer_state state;
+   state.num_attachments = ctx->fb_state.nr_cbufs;
+
    const unsigned cresolve_offset = ctx->fb_state.nr_cbufs + !!ctx->fb_state.zsbuf;
    unsigned num_resolves = 0;
    for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) {
@@ -160,7 +162,6 @@ zink_get_framebuffer_imageless(struct zink_context *ctx)
       }
    }
 
-   state.num_attachments = ctx->fb_state.nr_cbufs;
    const unsigned zsresolve_offset = cresolve_offset + num_resolves;
    if (ctx->fb_state.zsbuf) {
       struct pipe_surface *psurf = ctx->fb_state.zsbuf;