return ngg_gs_vertex_ptr(ctx, vertexidx);
}
+static LLVMValueRef
+ngg_gs_get_emit_output_ptr(struct radv_shader_context *ctx, LLVMValueRef vertexptr,
+ unsigned out_idx)
+{
+ LLVMValueRef gep_idx[3] = {
+ ctx->ac.i32_0, /* implied C-style array */
+ ctx->ac.i32_0, /* first struct entry */
+ LLVMConstInt(ctx->ac.i32, out_idx, false),
+ };
+ return LLVMBuildGEP(ctx->ac.builder, vertexptr, gep_idx, 3, "");
+}
+
+static LLVMValueRef
+ngg_gs_get_emit_primflag_ptr(struct radv_shader_context *ctx, LLVMValueRef vertexptr,
+ unsigned stream)
+{
+ LLVMValueRef gep_idx[3] = {
+ ctx->ac.i32_0, /* implied C-style array */
+ ctx->ac.i32_1, /* second struct entry */
+ LLVMConstInt(ctx->ac.i32, stream, false),
+ };
+ return LLVMBuildGEP(ctx->ac.builder, vertexptr, gep_idx, 3, "");
+}
+
static struct radv_stream_output *
radv_get_stream_output_by_loc(struct radv_streamout_info *so, unsigned location)
{
LLVMBuildStore(builder, tmp, ctx->gs_next_vertex[stream]);
tmp = ngg_gs_emit_vertex_ptr(ctx, gsthread, vertexidx);
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implied C-style array */
- ctx->ac.i32_1, /* second entry of struct */
- LLVMConstInt(ctx->ac.i32, stream, false),
- };
- tmp = LLVMBuildGEP(builder, tmp, gep_idx, 3, "");
- LLVMBuildStore(builder, i8_0, tmp);
+ LLVMBuildStore(builder, i8_0,
+ ngg_gs_get_emit_primflag_ptr(ctx, tmp, stream));
ac_build_endloop(&ctx->ac, 5100);
}
if (!ctx->args->shader_info->gs.num_stream_output_components[stream])
continue;
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implicit C-style array */
- ctx->ac.i32_1, /* second value of struct */
- LLVMConstInt(ctx->ac.i32, stream, false),
- };
- tmp = LLVMBuildGEP(builder, vertexptr, gep_idx, 3, "");
- tmp = LLVMBuildLoad(builder, tmp, "");
+ tmp = LLVMBuildLoad(builder,
+ ngg_gs_get_emit_primflag_ptr(ctx, vertexptr, stream), "");
tmp = LLVMBuildTrunc(builder, tmp, ctx->ac.i1, "");
tmp2 = LLVMBuildICmp(builder, LLVMIntULT, tid, num_emit_threads, "");
nggso.prim_enable[stream] = LLVMBuildAnd(builder, tmp, tmp2, "");
/* Load primitive liveness */
tmp = ngg_gs_vertex_ptr(ctx, primidx);
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implicit C-style array */
- ctx->ac.i32_1, /* second value of struct */
- ctx->ac.i32_0, /* stream 0 */
- };
- tmp = LLVMBuildGEP(builder, tmp, gep_idx, 3, "");
- tmp = LLVMBuildLoad(builder, tmp, "");
+ tmp = LLVMBuildLoad(builder,
+ ngg_gs_get_emit_primflag_ptr(ctx, tmp, 0), "");
const LLVMValueRef primlive =
LLVMBuildTrunc(builder, tmp, ctx->ac.i1, "");
ac_build_ifcc(&ctx->ac, vertlive, 5130);
{
tmp = ngg_gs_vertex_ptr(ctx, vertlive_scan.result_exclusive);
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implicit C-style array */
- ctx->ac.i32_1, /* second value of struct */
- ctx->ac.i32_1, /* stream 1 */
- };
- tmp = LLVMBuildGEP(builder, tmp, gep_idx, 3, "");
tmp2 = LLVMBuildTrunc(builder, tid, ctx->ac.i8, "");
- LLVMBuildStore(builder, tmp2, tmp);
+ LLVMBuildStore(builder, tmp2,
+ ngg_gs_get_emit_primflag_ptr(ctx, tmp, 1));
}
ac_build_endif(&ctx->ac, 5130);
prim.num_vertices = verts_per_prim;
tmp = ngg_gs_vertex_ptr(ctx, tid);
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implicit C-style array */
- ctx->ac.i32_1, /* second value of struct */
- ctx->ac.i32_0, /* primflag */
- };
- tmp = LLVMBuildGEP(builder, tmp, gep_idx, 3, "");
- flags = LLVMBuildLoad(builder, tmp, "");
+ flags = LLVMBuildLoad(builder,
+ ngg_gs_get_emit_primflag_ptr(ctx, tmp, 0), "");
prim.isnull = LLVMBuildNot(builder, LLVMBuildTrunc(builder, flags, ctx->ac.i1, ""), "");
for (unsigned i = 0; i < verts_per_prim; ++i) {
outinfo->pos_exports = 0;
tmp = ngg_gs_vertex_ptr(ctx, tid);
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implicit C-style array */
- ctx->ac.i32_1, /* second value of struct */
- ctx->ac.i32_1, /* stream 1: source data index */
- };
- tmp = LLVMBuildGEP(builder, tmp, gep_idx, 3, "");
- tmp = LLVMBuildLoad(builder, tmp, "");
+ tmp = LLVMBuildLoad(builder,
+ ngg_gs_get_emit_primflag_ptr(ctx, tmp, 1), "");
tmp = LLVMBuildZExt(builder, tmp, ctx->ac.i32, "");
const LLVMValueRef vertexptr = ngg_gs_vertex_ptr(ctx, tmp);
unsigned out_idx = 0;
- gep_idx[1] = ctx->ac.i32_0;
for (unsigned i = 0; i < AC_LLVM_MAX_OUTPUTS; ++i) {
unsigned output_usage_mask =
ctx->args->shader_info->gs.output_usage_mask[i];
if (!(output_usage_mask & (1 << j)))
continue;
- gep_idx[2] = LLVMConstInt(ctx->ac.i32, out_idx, false);
- tmp = LLVMBuildGEP(builder, vertexptr, gep_idx, 3, "");
+ tmp = ngg_gs_get_emit_output_ptr(ctx, vertexptr, out_idx);
tmp = LLVMBuildLoad(builder, tmp, "");
LLVMTypeRef type = LLVMGetAllocatedType(ctx->abi.outputs[ac_llvm_reg_index_soa(i, j)]);
LLVMValueRef out_val = LLVMBuildLoad(ctx->ac.builder,
out_ptr[j], "");
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implied C-style array */
- ctx->ac.i32_0, /* first entry of struct */
- LLVMConstInt(ctx->ac.i32, out_idx, false),
- };
- LLVMValueRef ptr = LLVMBuildGEP(builder, vertexptr, gep_idx, 3, "");
-
out_val = ac_to_integer(&ctx->ac, out_val);
out_val = LLVMBuildZExtOrBitCast(ctx->ac.builder, out_val, ctx->ac.i32, "");
- LLVMBuildStore(builder, out_val, ptr);
+ LLVMBuildStore(builder, out_val,
+ ngg_gs_get_emit_output_ptr(ctx, vertexptr, out_idx));
}
}
assert(out_idx * 4 <= ctx->args->shader_info->gs.gsvs_vertex_size);
tmp = LLVMBuildAdd(builder, curverts, ctx->ac.i32_1, "");
LLVMBuildStore(builder, tmp, ctx->gs_curprim_verts[stream]);
- LLVMValueRef gep_idx[3] = {
- ctx->ac.i32_0, /* implied C-style array */
- ctx->ac.i32_1, /* second struct entry */
- LLVMConstInt(ctx->ac.i32, stream, false),
- };
- const LLVMValueRef primflagptr =
- LLVMBuildGEP(builder, vertexptr, gep_idx, 3, "");
-
/* The per-vertex primitive flag encoding:
* bit 0: whether this vertex finishes a primitive
* bit 1: whether the primitive is odd (if we are emitting triangle strips)
LLVMBuildShl(builder,
LLVMBuildZExt(builder, is_odd, ctx->ac.i8, ""),
ctx->ac.i8_1, ""), "");
- LLVMBuildStore(builder, tmp, primflagptr);
+ LLVMBuildStore(builder, tmp,
+ ngg_gs_get_emit_primflag_ptr(ctx, vertexptr, stream));
tmp = LLVMBuildLoad(builder, ctx->gs_generated_prims[stream], "");
tmp = LLVMBuildAdd(builder, tmp, LLVMBuildZExt(builder, iscompleteprim, ctx->ac.i32, ""), "");