amd/common: Fix stores to derefs with unknown variable.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 23 Jan 2019 21:50:33 +0000 (22:50 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 6 Feb 2019 21:35:54 +0000 (22:35 +0100)
Fixes: a2b5cc3c399 "radv: enable variable pointers"
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_nir_to_llvm.c

index 6ba0ee74f11c4865debf08a79c4ae2786a230a21..3a830591a24fb9fc11265b3864e0ad8555d6461d 100644 (file)
@@ -2006,18 +2006,23 @@ static void
 visit_store_var(struct ac_nir_context *ctx,
                nir_intrinsic_instr *instr)
 {
-        nir_variable *var = nir_deref_instr_get_variable(nir_instr_as_deref(instr->src[0].ssa->parent_instr));
+       nir_deref_instr *deref = nir_instr_as_deref(instr->src[0].ssa->parent_instr);
+       nir_variable *var = nir_deref_instr_get_variable(deref);
 
        LLVMValueRef temp_ptr, value;
-       int idx = var->data.driver_location;
-       unsigned comp = var->data.location_frac;
+       int idx = 0;
+       unsigned comp = 0;
        LLVMValueRef src = ac_to_float(&ctx->ac, get_src(ctx, instr->src[1]));
        int writemask = instr->const_index[0];
        LLVMValueRef indir_index;
        unsigned const_index;
 
-       get_deref_offset(ctx, nir_instr_as_deref(instr->src[0].ssa->parent_instr), false,
-                        NULL, NULL, &const_index, &indir_index);
+       if (var) {
+               get_deref_offset(ctx, deref, false,
+                                NULL, NULL, &const_index, &indir_index);
+               idx = var->data.driver_location;
+               comp = var->data.location_frac;
+       }
 
        if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src)) == 64) {
 
@@ -2030,7 +2035,7 @@ visit_store_var(struct ac_nir_context *ctx,
 
        writemask = writemask << comp;
 
-       switch (var->data.mode) {
+       switch (deref->mode) {
        case nir_var_shader_out:
 
                if (ctx->stage == MESA_SHADER_TESS_CTRL) {
@@ -2039,8 +2044,8 @@ visit_store_var(struct ac_nir_context *ctx,
                        unsigned const_index = 0;
                        const bool is_patch = var->data.patch;
 
-                       get_deref_offset(ctx, nir_instr_as_deref(instr->src[0].ssa->parent_instr),
-                                        false, NULL, is_patch ? NULL : &vertex_index,
+                       get_deref_offset(ctx, deref, false, NULL,
+                                        is_patch ? NULL : &vertex_index,
                                         &const_index, &indir_index);
 
                        ctx->abi->store_tcs_outputs(ctx->abi, var,