radv: fix fmask ptr issue
authorDave Airlie <airlied@redhat.com>
Wed, 19 Oct 2016 02:27:04 +0000 (12:27 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 19 Oct 2016 03:16:25 +0000 (13:16 +1000)
We were using the wrong descriptor in the fmask picking code.

src/amd/common/ac_nir_to_llvm.c

index 4b5f043d3af027460fbc1a68dadb704ce4abdfe4..ad32e15ba122c1fa7bf2c0832850d739158488f0 100644 (file)
@@ -3092,7 +3092,8 @@ static void tex_fetch_ptrs(struct nir_to_llvm_context *ctx,
                else
                        *samp_ptr = get_sampler_desc(ctx, instr->texture, DESC_SAMPLER);
        }
-       if (fmask_ptr && !instr->sampler && instr->op == nir_texop_txf_ms)
+       if (fmask_ptr && !instr->sampler && (instr->op == nir_texop_txf_ms ||
+                                            instr->op == nir_texop_samples_identical))
                *fmask_ptr = get_sampler_desc(ctx, instr->texture, DESC_FMASK);
 }
 
@@ -3405,14 +3406,27 @@ static void visit_tex(struct nir_to_llvm_context *ctx, nir_tex_instr *instr)
                txf_address[3] = ctx->i32zero;
 
                set_tex_fetch_args(ctx, &txf_info, instr, nir_texop_txf,
-                                  res_ptr, samp_ptr,
+                                  fmask_ptr, NULL,
                                   txf_address, txf_count, 0xf);
 
                result = build_tex_intrinsic(ctx, instr, &txf_info);
                goto write_result;
        }
 
-       /* TODO sample FMASK magic */
+       /* Adjust the sample index according to FMASK.
+        *
+        * For uncompressed MSAA surfaces, FMASK should return 0x76543210,
+        * which is the identity mapping. Each nibble says which physical sample
+        * should be fetched to get that sample.
+        *
+        * For example, 0x11111100 means there are only 2 samples stored and
+        * the second sample covers 3/4 of the pixel. When reading samples 0
+        * and 1, return physical sample 0 (determined by the first two 0s
+        * in FMASK), otherwise return physical sample 1.
+        *
+        * The sample index should be adjusted as follows:
+        *   sample_index = (fmask >> (sample_index * 4)) & 0xF;
+        */
        if (instr->sampler_dim == GLSL_SAMPLER_DIM_MS) {
                LLVMValueRef txf_address[4];
                struct ac_tex_info txf_info = { 0 };
@@ -3424,7 +3438,7 @@ static void visit_tex(struct nir_to_llvm_context *ctx, nir_tex_instr *instr)
                txf_address[3] = ctx->i32zero;
 
                set_tex_fetch_args(ctx, &txf_info, instr, nir_texop_txf,
-                                  res_ptr, samp_ptr,
+                                  fmask_ptr, NULL,
                                   txf_address, txf_count, 0xf);
 
                result = build_tex_intrinsic(ctx, instr, &txf_info);