ac: add ac_build_image_get_sample_count from radeonsi
authorMarek Olšák <marek.olsak@amd.com>
Mon, 16 Sep 2019 23:37:04 +0000 (19:37 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 30 Sep 2019 18:21:42 +0000 (14:21 -0400)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c

index 44092a394878b52d0e858c5de7fb07d65e7f09f3..cda2daab6f51be2c63ce34c0cdc83c4028460a28 100644 (file)
@@ -2492,6 +2492,25 @@ LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
        return result;
 }
 
+LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx,
+                                            LLVMValueRef rsrc)
+{
+       LLVMValueRef samples;
+
+       /* Read the samples from the descriptor directly.
+        * Hardware doesn't have any instruction for this.
+        */
+       samples = LLVMBuildExtractElement(ctx->builder, rsrc,
+                                         LLVMConstInt(ctx->i32, 3, 0), "");
+       samples = LLVMBuildLShr(ctx->builder, samples,
+                               LLVMConstInt(ctx->i32, 16, 0), "");
+       samples = LLVMBuildAnd(ctx->builder, samples,
+                              LLVMConstInt(ctx->i32, 0xf, 0), "");
+       samples = LLVMBuildShl(ctx->builder, ctx->i32_1,
+                              samples, "");
+       return samples;
+}
+
 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
                                    LLVMValueRef args[2])
 {
index 8d85ae62fc79d1a2d2ccc24541db4622a3f0481c..013bf00041ac5876db24c1624b09f57abbfd1010 100644 (file)
@@ -552,6 +552,8 @@ struct ac_image_args {
 
 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
                                   struct ac_image_args *a);
+LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx,
+                                            LLVMValueRef rsrc);
 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
                                    LLVMValueRef args[2]);
 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx,
index f1d9d64a2406c92db872ff4beb634de37d4a0950..709ada50ea0e76563ace4b53165a19a4cb7e10b7 100644 (file)
@@ -1685,23 +1685,13 @@ static void si_llvm_emit_txqs(
        struct lp_build_emit_data *emit_data)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMValueRef res, samples;
-       LLVMValueRef res_ptr, samp_ptr, fmask_ptr = NULL;
-
-       tex_fetch_ptrs(bld_base, emit_data, &res_ptr, &samp_ptr, &fmask_ptr);
-
-       /* Read the samples from the descriptor directly. */
-       res = LLVMBuildBitCast(ctx->ac.builder, res_ptr, ctx->v8i32, "");
-       samples = LLVMBuildExtractElement(ctx->ac.builder, res,
-                                         LLVMConstInt(ctx->i32, 3, 0), "");
-       samples = LLVMBuildLShr(ctx->ac.builder, samples,
-                               LLVMConstInt(ctx->i32, 16, 0), "");
-       samples = LLVMBuildAnd(ctx->ac.builder, samples,
-                              LLVMConstInt(ctx->i32, 0xf, 0), "");
-       samples = LLVMBuildShl(ctx->ac.builder, ctx->i32_1,
-                              samples, "");
-
-       emit_data->output[emit_data->chan] = samples;
+       LLVMValueRef rsrc;
+
+       tex_fetch_ptrs(bld_base, emit_data, &rsrc, NULL, NULL);
+
+       rsrc = LLVMBuildBitCast(ctx->ac.builder, rsrc, ctx->v8i32, "");
+       emit_data->output[emit_data->chan] =
+               ac_build_image_get_sample_count(&ctx->ac, rsrc);
 }
 
 static LLVMValueRef si_llvm_emit_fbfetch(struct si_shader_context *ctx)