From: Marek Olšák <marek.ol...@amd.com> --- src/amd/common/ac_llvm_build.c | 37 ++++++++++++++++++++++++ src/amd/common/ac_llvm_build.h | 2 ++ src/amd/common/ac_nir_to_llvm.c | 41 ++------------------------ src/gallium/drivers/radeonsi/si_shader.c | 49 ++++---------------------------- 4 files changed, 47 insertions(+), 82 deletions(-)
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index a0b74a5..114cb0c 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -107,20 +107,57 @@ ac_emit_llvm_intrinsic(struct ac_llvm_context *ctx, const char *name, if (!set_callsite_attrs) ac_add_func_attributes(ctx->context, function, attrib_mask); } call = LLVMBuildCall(ctx->builder, function, params, param_count, ""); if (set_callsite_attrs) ac_add_func_attributes(ctx->context, call, attrib_mask); return call; } +/** + * Given the i32 or vNi32 \p type, generate the textual name (e.g. for use with + * intrinsic names). + */ +void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize) +{ + LLVMTypeRef elem_type = type; + + assert(bufsize >= 8); + + if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) { + int ret = snprintf(buf, bufsize, "v%u", + LLVMGetVectorSize(type)); + if (ret < 0) { + char *type_name = LLVMPrintTypeToString(type); + fprintf(stderr, "Error building type name for: %s\n", + type_name); + return; + } + elem_type = LLVMGetElementType(type); + buf += ret; + bufsize -= ret; + } + switch (LLVMGetTypeKind(elem_type)) { + default: break; + case LLVMIntegerTypeKind: + snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type)); + break; + case LLVMFloatTypeKind: + snprintf(buf, bufsize, "f32"); + break; + case LLVMDoubleTypeKind: + snprintf(buf, bufsize, "f64"); + break; + } +} + LLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values, unsigned value_count, unsigned value_stride, bool load) { LLVMBuilderRef builder = ctx->builder; LLVMValueRef vec = NULL; unsigned i; diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h index 57bfdbd..46da79e 100644 --- a/src/amd/common/ac_llvm_build.h +++ b/src/amd/common/ac_llvm_build.h @@ -55,20 +55,22 @@ struct ac_llvm_context { }; void ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context); LLVMValueRef ac_emit_llvm_intrinsic(struct ac_llvm_context *ctx, const char *name, LLVMTypeRef return_type, LLVMValueRef *params, unsigned param_count, unsigned attrib_mask); +void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize); + LLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values, unsigned value_count, unsigned value_stride, bool load); LLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values, unsigned value_count); diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index b6d9292..30d48aa 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -2371,75 +2371,40 @@ static int image_type_to_components_count(enum glsl_sampler_dim dim, bool array) return 2; case GLSL_SAMPLER_DIM_SUBPASS_MS: return 3; default: break; } return 0; } -static void build_type_name_for_intr( - LLVMTypeRef type, - char *buf, unsigned bufsize) -{ - LLVMTypeRef elem_type = type; - - assert(bufsize >= 8); - - if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) { - int ret = snprintf(buf, bufsize, "v%u", - LLVMGetVectorSize(type)); - if (ret < 0) { - char *type_name = LLVMPrintTypeToString(type); - fprintf(stderr, "Error building type name for: %s\n", - type_name); - return; - } - elem_type = LLVMGetElementType(type); - buf += ret; - bufsize -= ret; - } - switch (LLVMGetTypeKind(elem_type)) { - default: break; - case LLVMIntegerTypeKind: - snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type)); - break; - case LLVMFloatTypeKind: - snprintf(buf, bufsize, "f32"); - break; - case LLVMDoubleTypeKind: - snprintf(buf, bufsize, "f64"); - break; - } -} - static void get_image_intr_name(const char *base_name, LLVMTypeRef data_type, LLVMTypeRef coords_type, LLVMTypeRef rsrc_type, char *out_name, unsigned out_len) { char coords_type_name[8]; - build_type_name_for_intr(coords_type, coords_type_name, + ac_build_type_name_for_intr(coords_type, coords_type_name, sizeof(coords_type_name)); if (HAVE_LLVM <= 0x0309) { snprintf(out_name, out_len, "%s.%s", base_name, coords_type_name); } else { char data_type_name[8]; char rsrc_type_name[8]; - build_type_name_for_intr(data_type, data_type_name, + ac_build_type_name_for_intr(data_type, data_type_name, sizeof(data_type_name)); - build_type_name_for_intr(rsrc_type, rsrc_type_name, + ac_build_type_name_for_intr(rsrc_type, rsrc_type_name, sizeof(rsrc_type_name)); snprintf(out_name, out_len, "%s.%s.%s.%s", base_name, data_type_name, coords_type_name, rsrc_type_name); } } /* 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 diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 8fae876..21efaa4 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -3130,59 +3130,20 @@ static LLVMValueRef get_buffer_size( lp_build_const_int32(gallivm, 16), ""); stride = LLVMBuildAnd(builder, stride, lp_build_const_int32(gallivm, 0x3FFF), ""); size = LLVMBuildUDiv(builder, size, stride, ""); } return size; } -/** - * Given the i32 or vNi32 \p type, generate the textual name (e.g. for use with - * intrinsic names). - */ -static void build_type_name_for_intr( - LLVMTypeRef type, - char *buf, unsigned bufsize) -{ - LLVMTypeRef elem_type = type; - - assert(bufsize >= 8); - - if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) { - int ret = snprintf(buf, bufsize, "v%u", - LLVMGetVectorSize(type)); - if (ret < 0) { - char *type_name = LLVMPrintTypeToString(type); - fprintf(stderr, "Error building type name for: %s\n", - type_name); - return; - } - elem_type = LLVMGetElementType(type); - buf += ret; - bufsize -= ret; - } - switch (LLVMGetTypeKind(elem_type)) { - default: break; - case LLVMIntegerTypeKind: - snprintf(buf, bufsize, "i%d", LLVMGetIntTypeWidth(elem_type)); - break; - case LLVMFloatTypeKind: - snprintf(buf, bufsize, "f32"); - break; - case LLVMDoubleTypeKind: - snprintf(buf, bufsize, "f64"); - break; - } -} - static void build_tex_intrinsic(const struct lp_build_tgsi_action *action, struct lp_build_tgsi_context *bld_base, struct lp_build_emit_data *emit_data); /* Prevent optimizations (at least of memory accesses) across the current * point in the program by emitting empty inline assembly that is marked as * having side effects. */ #if 0 /* unused currently */ static void emit_optimization_barrier(struct si_shader_context *ctx) @@ -3596,32 +3557,32 @@ static void load_emit_memory( } static void get_image_intr_name(const char *base_name, LLVMTypeRef data_type, LLVMTypeRef coords_type, LLVMTypeRef rsrc_type, char *out_name, unsigned out_len) { char coords_type_name[8]; - build_type_name_for_intr(coords_type, coords_type_name, + ac_build_type_name_for_intr(coords_type, coords_type_name, sizeof(coords_type_name)); if (HAVE_LLVM <= 0x0309) { snprintf(out_name, out_len, "%s.%s", base_name, coords_type_name); } else { char data_type_name[8]; char rsrc_type_name[8]; - build_type_name_for_intr(data_type, data_type_name, + ac_build_type_name_for_intr(data_type, data_type_name, sizeof(data_type_name)); - build_type_name_for_intr(rsrc_type, rsrc_type_name, + ac_build_type_name_for_intr(rsrc_type, rsrc_type_name, sizeof(rsrc_type_name)); snprintf(out_name, out_len, "%s.%s.%s.%s", base_name, data_type_name, coords_type_name, rsrc_type_name); } } static void load_emit( const struct lp_build_tgsi_action *action, struct lp_build_tgsi_context *bld_base, struct lp_build_emit_data *emit_data) @@ -4023,21 +3984,21 @@ static void atomic_emit( "llvm.amdgcn.buffer.atomic.%s", action->intr_name); } else { LLVMValueRef coords; char coords_type[8]; if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS) coords = emit_data->args[2]; else coords = emit_data->args[1]; - build_type_name_for_intr(LLVMTypeOf(coords), coords_type, sizeof(coords_type)); + ac_build_type_name_for_intr(LLVMTypeOf(coords), coords_type, sizeof(coords_type)); snprintf(intrinsic_name, sizeof(intrinsic_name), "llvm.amdgcn.image.atomic.%s.%s", action->intr_name, coords_type); } tmp = lp_build_intrinsic( builder, intrinsic_name, bld_base->uint_bld.elem_type, emit_data->args, emit_data->arg_count, 0); emit_data->output[emit_data->chan] = LLVMBuildBitCast(builder, tmp, bld_base->base.elem_type, ""); @@ -4807,21 +4768,21 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action, case TGSI_OPCODE_TG4: name = "llvm.SI.gather4"; infix = ".lz"; break; default: assert(0); return; } /* Add the type and suffixes .c, .o if needed. */ - build_type_name_for_intr(LLVMTypeOf(emit_data->args[0]), type, sizeof(type)); + ac_build_type_name_for_intr(LLVMTypeOf(emit_data->args[0]), type, sizeof(type)); sprintf(intr_name, "%s%s%s%s.%s", name, is_shadow ? ".c" : "", infix, has_offset ? ".o" : "", type); /* The hardware needs special lowering for Gather4 with integer formats. */ if (opcode == TGSI_OPCODE_TG4) { struct tgsi_shader_info *info = &ctx->shader->selector->info; /* This will also work with non-constant indexing because of how * glsl_to_tgsi works and we intent to preserve that behavior. */ -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev