From 0cc233e3dc36b569eabdfada6e42000185f00ac3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 16 Sep 2019 19:37:04 -0400 Subject: [PATCH] ac: add ac_build_image_get_sample_count from radeonsi Reviewed-by: Samuel Pitoiset --- src/amd/common/ac_llvm_build.c | 19 +++++++++++++++ src/amd/common/ac_llvm_build.h | 2 ++ .../drivers/radeonsi/si_shader_tgsi_mem.c | 24 ++++++------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index 44092a39487..cda2daab6f5 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -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]) { diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h index 8d85ae62fc7..013bf00041a 100644 --- a/src/amd/common/ac_llvm_build.h +++ b/src/amd/common/ac_llvm_build.h @@ -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, diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c index f1d9d64a240..709ada50ea0 100644 --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c @@ -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) -- 2.30.2