[Mesa-dev] [PATCH v2 31/73] ac/nir: pass ac_llvm_context to some helper functions
Nicolai Hähnle
nhaehnle at gmail.com
Wed Jul 5 10:48:15 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/amd/common/ac_nir_to_llvm.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 727c248..5463e44 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -987,32 +987,32 @@ static void setup_types(struct nir_to_llvm_context *ctx)
static int get_llvm_num_components(LLVMValueRef value)
{
LLVMTypeRef type = LLVMTypeOf(value);
unsigned num_components = LLVMGetTypeKind(type) == LLVMVectorTypeKind
? LLVMGetVectorSize(type)
: 1;
return num_components;
}
-static LLVMValueRef llvm_extract_elem(struct nir_to_llvm_context *ctx,
+static LLVMValueRef llvm_extract_elem(struct ac_llvm_context *ac,
LLVMValueRef value,
int index)
{
int count = get_llvm_num_components(value);
assert(index < count);
if (count == 1)
return value;
- return LLVMBuildExtractElement(ctx->builder, value,
- LLVMConstInt(ctx->i32, index, false), "");
+ return LLVMBuildExtractElement(ac->builder, value,
+ LLVMConstInt(ac->i32, index, false), "");
}
static LLVMValueRef trim_vector(struct nir_to_llvm_context *ctx,
LLVMValueRef value, unsigned count)
{
unsigned num_components = get_llvm_num_components(value);
if (count == num_components)
return value;
LLVMValueRef masks[] = {
@@ -1021,37 +1021,37 @@ static LLVMValueRef trim_vector(struct nir_to_llvm_context *ctx,
if (count == 1)
return LLVMBuildExtractElement(ctx->builder, value, masks[0],
"");
LLVMValueRef swizzle = LLVMConstVector(masks, count);
return LLVMBuildShuffleVector(ctx->builder, value, value, swizzle, "");
}
static void
-build_store_values_extended(struct nir_to_llvm_context *ctx,
+build_store_values_extended(struct ac_llvm_context *ac,
LLVMValueRef *values,
unsigned value_count,
unsigned value_stride,
LLVMValueRef vec)
{
- LLVMBuilderRef builder = ctx->builder;
+ LLVMBuilderRef builder = ac->builder;
unsigned i;
if (value_count == 1) {
LLVMBuildStore(builder, vec, values[0]);
return;
}
for (i = 0; i < value_count; i++) {
LLVMValueRef ptr = values[i * value_stride];
- LLVMValueRef index = LLVMConstInt(ctx->i32, i, false);
+ LLVMValueRef index = LLVMConstInt(ac->i32, i, false);
LLVMValueRef value = LLVMBuildExtractElement(builder, vec, index, "");
LLVMBuildStore(builder, value, ptr);
}
}
static LLVMTypeRef get_def_type(struct ac_nir_context *ctx,
const nir_ssa_def *def)
{
LLVMTypeRef type = LLVMIntTypeInContext(ctx->ac.context, def->bit_size);
if (def->num_components > 1) {
@@ -2347,23 +2347,23 @@ static void visit_store_ssbo(struct nir_to_llvm_context *ctx,
static LLVMValueRef visit_atomic_ssbo(struct nir_to_llvm_context *ctx,
const nir_intrinsic_instr *instr)
{
const char *name;
LLVMValueRef params[6];
int arg_count = 0;
if (ctx->stage == MESA_SHADER_FRAGMENT)
ctx->shader_info->fs.writes_memory = true;
if (instr->intrinsic == nir_intrinsic_ssbo_atomic_comp_swap) {
- params[arg_count++] = llvm_extract_elem(ctx, get_src(ctx->nir, instr->src[3]), 0);
+ params[arg_count++] = llvm_extract_elem(&ctx->ac, get_src(ctx->nir, instr->src[3]), 0);
}
- params[arg_count++] = llvm_extract_elem(ctx, get_src(ctx->nir, instr->src[2]), 0);
+ params[arg_count++] = llvm_extract_elem(&ctx->ac, get_src(ctx->nir, instr->src[2]), 0);
params[arg_count++] = get_src(ctx->nir, instr->src[0]);
params[arg_count++] = LLVMConstInt(ctx->i32, 0, false); /* vindex */
params[arg_count++] = get_src(ctx->nir, instr->src[1]); /* voffset */
params[arg_count++] = ctx->i1false; /* slc */
switch (instr->intrinsic) {
case nir_intrinsic_ssbo_atomic_add:
name = "llvm.amdgcn.buffer.atomic.add";
break;
case nir_intrinsic_ssbo_atomic_imin:
@@ -2821,21 +2821,21 @@ store_tcs_output(struct nir_to_llvm_context *ctx,
dw_addr = get_dw_address(ctx, dw_addr, param, const_index, is_compact, vertex_index, stride,
indir_index);
buf_addr = get_tcs_tes_buffer_address_params(ctx, param, const_index, is_compact,
vertex_index, indir_index);
unsigned base = is_compact ? const_index : 0;
for (unsigned chan = 0; chan < 8; chan++) {
bool is_tess_factor = false;
if (!(writemask & (1 << chan)))
continue;
- LLVMValueRef value = llvm_extract_elem(ctx, src, chan);
+ LLVMValueRef value = llvm_extract_elem(&ctx->ac, src, chan);
lds_store(ctx, dw_addr, value);
if (instr->variables[0]->var->data.location == VARYING_SLOT_TESS_LEVEL_INNER ||
instr->variables[0]->var->data.location == VARYING_SLOT_TESS_LEVEL_OUTER)
is_tess_factor = true;
if (!is_tess_factor && writemask != 0xF)
ac_build_buffer_store_dword(&ctx->ac, ctx->hs_ring_tess_offchip, value, 1,
buf_addr, ctx->oc_lds,
@@ -3065,64 +3065,64 @@ visit_store_var(struct nir_to_llvm_context *ctx,
if (ctx->stage == MESA_SHADER_TESS_CTRL) {
store_tcs_output(ctx, instr, src, writemask);
return;
}
for (unsigned chan = 0; chan < 8; chan++) {
int stride = 4;
if (!(writemask & (1 << chan)))
continue;
- value = llvm_extract_elem(ctx, src, chan);
+ value = llvm_extract_elem(&ctx->ac, src, chan);
if (instr->variables[0]->var->data.compact)
stride = 1;
if (indir_index) {
unsigned count = glsl_count_attribute_slots(
instr->variables[0]->var->type, false);
count -= chan / 4;
LLVMValueRef tmp_vec = ac_build_gather_values_extended(
&ctx->ac, ctx->nir->outputs + idx + chan, count,
stride, true);
if (get_llvm_num_components(tmp_vec) > 1) {
tmp_vec = LLVMBuildInsertElement(ctx->builder, tmp_vec,
value, indir_index, "");
} else
tmp_vec = value;
- build_store_values_extended(ctx, ctx->nir->outputs + idx + chan,
+ build_store_values_extended(&ctx->ac, ctx->nir->outputs + idx + chan,
count, stride, tmp_vec);
} else {
temp_ptr = ctx->nir->outputs[idx + chan + const_index * stride];
LLVMBuildStore(ctx->builder, value, temp_ptr);
}
}
break;
case nir_var_local:
for (unsigned chan = 0; chan < 8; chan++) {
if (!(writemask & (1 << chan)))
continue;
- value = llvm_extract_elem(ctx, src, chan);
+ value = llvm_extract_elem(&ctx->ac, src, chan);
if (indir_index) {
unsigned count = glsl_count_attribute_slots(
instr->variables[0]->var->type, false);
count -= chan / 4;
LLVMValueRef tmp_vec = ac_build_gather_values_extended(
&ctx->ac, ctx->nir->locals + idx + chan, count,
4, true);
tmp_vec = LLVMBuildInsertElement(ctx->builder, tmp_vec,
value, indir_index, "");
- build_store_values_extended(ctx, ctx->nir->locals + idx + chan,
+ build_store_values_extended(&ctx->ac, ctx->nir->locals + idx + chan,
count, 4, tmp_vec);
} else {
temp_ptr = ctx->nir->locals[idx + chan + const_index * 4];
LLVMBuildStore(ctx->builder, value, temp_ptr);
}
}
break;
case nir_var_shared: {
LLVMValueRef ptr = get_shared_memory_ptr(ctx, idx, ctx->i32);
@@ -3132,21 +3132,21 @@ visit_store_var(struct nir_to_llvm_context *ctx,
for (unsigned chan = 0; chan < 8; chan++) {
if (!(writemask & (1 << chan)))
continue;
LLVMValueRef index = LLVMConstInt(ctx->i32, chan, false);
LLVMValueRef derived_ptr;
if (indir_index)
index = LLVMBuildAdd(ctx->builder, index, indir_index, "");
- value = llvm_extract_elem(ctx, src, chan);
+ value = llvm_extract_elem(&ctx->ac, src, chan);
derived_ptr = LLVMBuildGEP(ctx->builder, ptr, &index, 1, "");
LLVMBuildStore(ctx->builder,
to_integer(&ctx->ac, value), derived_ptr);
}
break;
}
default:
break;
}
}
@@ -3262,21 +3262,21 @@ static LLVMValueRef get_image_coords(struct nir_to_llvm_context *ctx,
if(instr->variables[0]->deref.child)
type = instr->variables[0]->deref.child->type;
LLVMValueRef src0 = get_src(ctx->nir, instr->src[0]);
LLVMValueRef coords[4];
LLVMValueRef masks[] = {
LLVMConstInt(ctx->i32, 0, false), LLVMConstInt(ctx->i32, 1, false),
LLVMConstInt(ctx->i32, 2, false), LLVMConstInt(ctx->i32, 3, false),
};
LLVMValueRef res;
- LLVMValueRef sample_index = llvm_extract_elem(ctx, get_src(ctx->nir, instr->src[1]), 0);
+ LLVMValueRef sample_index = llvm_extract_elem(&ctx->ac, get_src(ctx->nir, instr->src[1]), 0);
int count;
enum glsl_sampler_dim dim = glsl_get_sampler_dim(type);
bool add_frag_pos = (dim == GLSL_SAMPLER_DIM_SUBPASS ||
dim == GLSL_SAMPLER_DIM_SUBPASS_MS);
bool is_ms = (dim == GLSL_SAMPLER_DIM_MS ||
dim == GLSL_SAMPLER_DIM_SUBPASS_MS);
count = image_type_to_components_count(dim,
glsl_sampler_type_is_array(type));
@@ -4378,70 +4378,70 @@ static void visit_tex(struct nir_to_llvm_context *ctx, nir_tex_instr *instr)
samples = LLVMBuildShl(ctx->builder, ctx->i32one,
samples, "");
samples = LLVMBuildSelect(ctx->builder, is_msaa, samples,
ctx->i32one, "");
result = samples;
goto write_result;
}
if (coord)
for (chan = 0; chan < instr->coord_components; chan++)
- coords[chan] = llvm_extract_elem(ctx, coord, chan);
+ coords[chan] = llvm_extract_elem(&ctx->ac, coord, chan);
if (offsets && instr->op != nir_texop_txf) {
LLVMValueRef offset[3], pack;
for (chan = 0; chan < 3; ++chan)
offset[chan] = ctx->i32zero;
args.offset = true;
for (chan = 0; chan < get_llvm_num_components(offsets); chan++) {
- offset[chan] = llvm_extract_elem(ctx, offsets, chan);
+ offset[chan] = llvm_extract_elem(&ctx->ac, offsets, chan);
offset[chan] = LLVMBuildAnd(ctx->builder, offset[chan],
LLVMConstInt(ctx->i32, 0x3f, false), "");
if (chan)
offset[chan] = LLVMBuildShl(ctx->builder, offset[chan],
LLVMConstInt(ctx->i32, chan * 8, false), "");
}
pack = LLVMBuildOr(ctx->builder, offset[0], offset[1], "");
pack = LLVMBuildOr(ctx->builder, pack, offset[2], "");
address[count++] = pack;
}
/* pack LOD bias value */
if (instr->op == nir_texop_txb && bias) {
address[count++] = bias;
}
/* Pack depth comparison value */
if (instr->is_shadow && comparator) {
- address[count++] = llvm_extract_elem(ctx, comparator, 0);
+ address[count++] = llvm_extract_elem(&ctx->ac, comparator, 0);
}
/* pack derivatives */
if (ddx || ddy) {
switch (instr->sampler_dim) {
case GLSL_SAMPLER_DIM_3D:
case GLSL_SAMPLER_DIM_CUBE:
num_deriv_comp = 3;
break;
case GLSL_SAMPLER_DIM_2D:
default:
num_deriv_comp = 2;
break;
case GLSL_SAMPLER_DIM_1D:
num_deriv_comp = 1;
break;
}
for (unsigned i = 0; i < num_deriv_comp; i++) {
- derivs[i] = to_float(&ctx->ac, llvm_extract_elem(ctx, ddx, i));
- derivs[num_deriv_comp + i] = to_float(&ctx->ac, llvm_extract_elem(ctx, ddy, i));
+ derivs[i] = to_float(&ctx->ac, llvm_extract_elem(&ctx->ac, ddx, i));
+ derivs[num_deriv_comp + i] = to_float(&ctx->ac, llvm_extract_elem(&ctx->ac, ddy, i));
}
}
if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE && coord) {
if (instr->is_array && instr->op != nir_texop_lod)
coords[3] = apply_round_slice(ctx, coords[3]);
for (chan = 0; chan < instr->coord_components; chan++)
coords[chan] = to_float(&ctx->ac, coords[chan]);
if (instr->coord_components == 3)
coords[3] = LLVMGetUndef(ctx->f32);
--
2.9.3
More information about the mesa-dev
mailing list