llvmpipe: fix crash when doing FB fetch + gl_FragDepth write in one shader
authorPavel Asyutchenko <sventeam@yandex.ru>
Thu, 2 Sep 2021 18:11:04 +0000 (21:11 +0300)
committerMarge Bot <eric+marge@anholt.net>
Tue, 5 Oct 2021 20:45:38 +0000 (20:45 +0000)
Reproducible by piglit test from this MR:
https://gitlab.freedesktop.org/mesa/piglit/-/merge_requests/576

Signed-off-by: Pavel Asyutchenko <sventeam@yandex.ru>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12705>

src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/drivers/llvmpipe/lp_state_fs.c

index 9b72a9e..b771b7c 100644 (file)
@@ -473,7 +473,7 @@ static void emit_load_var(struct lp_build_nir_context *bld_base,
       break;
    case nir_var_shader_out:
       if (bld->fs_iface && bld->fs_iface->fb_fetch) {
-         bld->fs_iface->fb_fetch(bld->fs_iface, &bld_base->base, var->data.driver_location, result);
+         bld->fs_iface->fb_fetch(bld->fs_iface, &bld_base->base, var->data.location, result);
          return;
       }
       for (unsigned i = 0; i < num_components; i++) {
index d2053c3..b3b7baa 100644 (file)
@@ -258,7 +258,7 @@ struct lp_build_fs_iface {
 
    void (*fb_fetch)(const struct lp_build_fs_iface *iface,
                     struct lp_build_context *bld,
-                    unsigned cbuf,
+                    int location,
                     LLVMValueRef result[4]);
 };
 
index 197c60f..c77f0f3 100644 (file)
@@ -452,10 +452,13 @@ static LLVMValueRef fs_interp(const struct lp_build_fs_iface *iface,
 }
 
 static void fs_fb_fetch(const struct lp_build_fs_iface *iface,
-                                struct lp_build_context *bld,
-                                unsigned cbuf,
-                                LLVMValueRef result[4])
+                        struct lp_build_context *bld,
+                        int location,
+                        LLVMValueRef result[4])
 {
+   assert(location >= FRAG_RESULT_DATA0 && location <= FRAG_RESULT_DATA7);
+   const int cbuf = location - FRAG_RESULT_DATA0;
+
    struct lp_build_fs_llvm_iface *fs_iface = (struct lp_build_fs_llvm_iface *)iface;
    struct gallivm_state *gallivm = bld->gallivm;
    LLVMBuilderRef builder = gallivm->builder;