diff options
author | Nicolai Hähnle <[email protected]> | 2018-02-16 14:21:56 +0100 |
---|---|---|
committer | Nicolai Hähnle <[email protected]> | 2018-04-20 09:23:40 +0200 |
commit | f931583828f0ca9a3b135da0f2cda6a36ebbc877 (patch) | |
tree | 58c3637389e3708db99acaa2819976e582223a68 /src/amd/common | |
parent | 9cb52d470a0db8b733bb344168308a6e7766626d (diff) |
amd/common: pass new enum ac_image_dim to ac_build_image_opcode
This is in preparation for the new, dimension-aware LLVM image
intrinsics.
Acked-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/amd/common')
-rw-r--r-- | src/amd/common/ac_llvm_build.c | 10 | ||||
-rw-r--r-- | src/amd/common/ac_llvm_build.h | 13 | ||||
-rw-r--r-- | src/amd/common/ac_nir_to_llvm.c | 54 |
3 files changed, 66 insertions, 11 deletions
diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index 9a00bb11140..77b07989430 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -1456,6 +1456,12 @@ LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, bool sample = a->opcode == ac_image_sample || a->opcode == ac_image_gather4 || a->opcode == ac_image_get_lod; + bool da = a->dim == ac_image_cube || + a->dim == ac_image_1darray || + a->dim == ac_image_2darray || + a->dim == ac_image_2darraymsaa; + if (a->opcode == ac_image_get_lod) + da = false; if (sample) args[num_args++] = ac_to_float(ctx, a->addr); @@ -1471,7 +1477,7 @@ LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, args[num_args++] = ctx->i1false; /* glc */ args[num_args++] = ctx->i1false; /* slc */ args[num_args++] = ctx->i1false; /* lwe */ - args[num_args++] = LLVMConstInt(ctx->i1, a->da, 0); + args[num_args++] = LLVMConstInt(ctx->i1, da, 0); switch (a->opcode) { case ac_image_sample: @@ -2473,7 +2479,7 @@ void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask, fmask_load.opcode = ac_image_load; fmask_load.resource = fmask; fmask_load.dmask = 0xf; - fmask_load.da = is_array_tex; + fmask_load.dim = is_array_tex ? ac_image_2darray : ac_image_2d; LLVMValueRef fmask_addr[4]; memcpy(fmask_addr, addr, sizeof(fmask_addr[0]) * 3); diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h index c583240e14b..328eddc9a77 100644 --- a/src/amd/common/ac_llvm_build.h +++ b/src/amd/common/ac_llvm_build.h @@ -317,8 +317,20 @@ enum ac_image_opcode { ac_image_get_resinfo, }; +enum ac_image_dim { + ac_image_1d, + ac_image_2d, + ac_image_3d, + ac_image_cube, // includes cube arrays + ac_image_1darray, + ac_image_2darray, + ac_image_2dmsaa, + ac_image_2darraymsaa, +}; + struct ac_image_args { enum ac_image_opcode opcode; + enum ac_image_dim dim; bool level_zero; bool bias; bool lod; @@ -331,7 +343,6 @@ struct ac_image_args { LLVMValueRef addr; unsigned dmask; bool unorm; - bool da; }; LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index 6b519f78e0f..de3754d72be 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -76,6 +76,45 @@ build_store_values_extended(struct ac_llvm_context *ac, } } +static enum ac_image_dim +get_ac_sampler_dim(const struct ac_llvm_context *ctx, enum glsl_sampler_dim dim, + bool is_array) +{ + switch (dim) { + case GLSL_SAMPLER_DIM_1D: + if (ctx->chip_class >= GFX9) + return is_array ? ac_image_2darray : ac_image_2d; + return is_array ? ac_image_1darray : ac_image_1d; + case GLSL_SAMPLER_DIM_2D: + case GLSL_SAMPLER_DIM_RECT: + case GLSL_SAMPLER_DIM_SUBPASS: + case GLSL_SAMPLER_DIM_EXTERNAL: + return is_array ? ac_image_2darray : ac_image_2d; + case GLSL_SAMPLER_DIM_3D: + return ac_image_3d; + case GLSL_SAMPLER_DIM_CUBE: + return ac_image_cube; + case GLSL_SAMPLER_DIM_MS: + case GLSL_SAMPLER_DIM_SUBPASS_MS: + return is_array ? ac_image_2darraymsaa : ac_image_2dmsaa; + default: + unreachable("bad sampler dim"); + } +} + +static enum ac_image_dim +get_ac_image_dim(const struct ac_llvm_context *ctx, enum glsl_sampler_dim sdim, + bool is_array) +{ + enum ac_image_dim dim = get_ac_sampler_dim(ctx, sdim, is_array); + + if (dim == ac_image_cube || + (ctx->chip_class <= VI && dim == ac_image_3d)) + dim = ac_image_2darray; + + return dim; +} + static LLVMTypeRef get_def_type(struct ac_nir_context *ctx, const nir_ssa_def *def) { @@ -1124,7 +1163,7 @@ static LLVMValueRef lower_gather4_integer(struct ac_llvm_context *ctx, { struct ac_image_args txq_args = { 0 }; - txq_args.da = instr->is_array || instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE; + txq_args.dim = get_ac_sampler_dim(ctx, instr->sampler_dim, instr->is_array); txq_args.opcode = ac_image_get_resinfo; txq_args.dmask = 0xf; txq_args.addr = ctx->i32_0; @@ -2055,7 +2094,7 @@ static LLVMValueRef adjust_sample_index_using_fmask(struct ac_llvm_context *ctx, struct ac_image_args args = {0}; args.opcode = ac_image_load; - args.da = coord_z ? true : false; + args.dim = coord_z ? ac_image_2darray : ac_image_2d; args.resource = fmask_desc_ptr; args.dmask = 0xf; args.addr = ac_build_gather_values(ctx, fmask_load_address, coord_z ? 4 : 2); @@ -2402,7 +2441,8 @@ static LLVMValueRef visit_image_samples(struct ac_nir_context *ctx, const struct glsl_type *type = glsl_without_array(var->type); struct ac_image_args args = { 0 }; - args.da = glsl_is_array_image(type); + args.dim = get_ac_sampler_dim(&ctx->ac, glsl_get_sampler_dim(type), + glsl_sampler_type_is_array(type)); args.dmask = 0xf; args.resource = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE, NULL, true, false); @@ -2426,7 +2466,8 @@ static LLVMValueRef visit_image_size(struct ac_nir_context *ctx, struct ac_image_args args = { 0 }; - args.da = glsl_is_array_image(type); + args.dim = get_ac_image_dim(&ctx->ac, glsl_get_sampler_dim(type), + glsl_sampler_type_is_array(type)); args.dmask = 0xf; args.resource = get_sampler_desc(ctx, instr->variables[0], AC_DESC_IMAGE, NULL, true, false); args.opcode = ac_image_get_resinfo; @@ -3185,10 +3226,7 @@ static void set_tex_fetch_args(struct ac_llvm_context *ctx, unsigned dmask) { unsigned is_rect = 0; - bool da = instr->is_array || instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE; - if (op == nir_texop_lod) - da = false; /* Pad to power of two vector */ while (count < util_next_power_of_two(count)) param[count++] = LLVMGetUndef(ctx->i32); @@ -3208,7 +3246,7 @@ static void set_tex_fetch_args(struct ac_llvm_context *ctx, args->dmask = dmask; args->unorm = is_rect; - args->da = da; + args->dim = get_ac_sampler_dim(&ctx->ac, instr->sampler_dim, instr->is_array); } /* Disable anisotropic filtering if BASE_LEVEL == LAST_LEVEL. |