gallivm/draw: add support for draw_id system value.
authorDave Airlie <airlied@redhat.com>
Wed, 11 Dec 2019 03:02:34 +0000 (13:02 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 12 Dec 2019 00:16:19 +0000 (10:16 +1000)
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_llvm.h
src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_pt.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c
src/gallium/auxiliary/gallivm/lp_bld_nir.c
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c

index 4a3bada06e087d33c2871589b476b0a5fc6e04e3..2c78e4709d9f1b2074b33f050038af6305937f1d 100644 (file)
@@ -1622,7 +1622,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
    struct gallivm_state *gallivm = variant->gallivm;
    LLVMContextRef context = gallivm->context;
    LLVMTypeRef int32_type = LLVMInt32TypeInContext(context);
-   LLVMTypeRef arg_types[11];
+   LLVMTypeRef arg_types[12];
    unsigned num_arg_types = ARRAY_SIZE(arg_types);
    LLVMTypeRef func_type;
    LLVMValueRef context_ptr;
@@ -1689,6 +1689,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
    arg_types[i++] = int32_type;                          /* vertex_id_offset */
    arg_types[i++] = int32_type;                          /* start_instance */
    arg_types[i++] = LLVMPointerType(int32_type, 0);      /* fetch_elts  */
+   arg_types[i++] = int32_type;                          /* draw_id */
 
    func_type = LLVMFunctionType(LLVMInt8TypeInContext(context),
                                 arg_types, num_arg_types, 0);
@@ -1723,6 +1724,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
    vertex_id_offset          = LLVMGetParam(variant_func, 8);
    system_values.base_instance = LLVMGetParam(variant_func, 9);
    fetch_elts                = LLVMGetParam(variant_func, 10);
+   system_values.draw_id     = LLVMGetParam(variant_func, 11);
 
    lp_build_name(context_ptr, "context");
    lp_build_name(io_ptr, "io");
@@ -1735,6 +1737,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
    lp_build_name(vertex_id_offset, "vertex_id_offset");
    lp_build_name(system_values.base_instance, "start_instance");
    lp_build_name(fetch_elts, "fetch_elts");
+   lp_build_name(system_values.draw_id, "draw_id");
 
    /*
     * Function body
index 914f783fd000209b9715a103528ce9548d9d0ec1..6edc89b63bacc9d9810f4d48a3f4e01553816cdf 100644 (file)
@@ -328,7 +328,8 @@ typedef boolean
                       unsigned instance_id,
                       unsigned vertex_id_offset,
                       unsigned start_instance,
-                      const unsigned *fetch_elts);
+                      const unsigned *fetch_elts,
+                      unsigned draw_id);
 
 
 typedef int
index 86e90c76f888d6bcb7474d8e6299d13bc3aff9eb..0fd0caab31b11eec799b4455ca15b59b139eebd0 100644 (file)
@@ -196,6 +196,7 @@ struct draw_context
          int eltBias;         
          unsigned min_index;
          unsigned max_index;
+         unsigned drawid;
          
          /** vertex arrays */
          struct draw_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
index f69189763109b6b97581f37eb6965e05f5696212..24ac054272650d84dc1cc4bdea0761c507ff9767 100644 (file)
@@ -485,6 +485,7 @@ draw_vbo(struct draw_context *draw,
    draw->pt.user.min_index = info->min_index;
    draw->pt.user.max_index = info->max_index;
    draw->pt.user.eltSize = info->index_size ? draw->pt.user.eltSizeIB : 0;
+   draw->pt.user.drawid = info->drawid;
 
    if (0)
       debug_printf("draw_vbo(mode=%u start=%u count=%u):\n",
index 0eeaf780af053ce356b819b0ef7dcf693f399a9d..c19eda2ede4dd3e55f39b8e867b09f22e8371386 100644 (file)
@@ -429,7 +429,7 @@ llvm_pipeline_generic(struct draw_pt_middle_end *middle,
                                              draw->instance_id,
                                              vid_base,
                                              draw->start_instance,
-                                             elts);
+                                             elts, draw->pt.user.drawid);
 
    /* Finished with fetch and vs:
     */
index 547161ba7fe3de2ff7c5e7f9fb91f0ff4450eb70..e5fe9eec6eb2a0be6c7b1a899bf69b4a3c622815 100644 (file)
@@ -1167,6 +1167,7 @@ static void visit_intrinsic(struct lp_build_nir_context *bld_base,
    case nir_intrinsic_load_num_work_groups:
    case nir_intrinsic_load_invocation_id:
    case nir_intrinsic_load_front_face:
+   case nir_intrinsic_load_draw_id:
       bld_base->sysval_intrin(bld_base, instr, result);
       break;
    case nir_intrinsic_discard_if:
index a95af23ae0d3229b27d25565fb0ccb70fc014728..b0c034645f3fe3ed64949fb054fae92c27a65012 100644 (file)
@@ -949,6 +949,9 @@ static void emit_sysval_intrin(struct lp_build_nir_context *bld_base,
    case nir_intrinsic_load_front_face:
       result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.front_facing);
       break;
+   case nir_intrinsic_load_draw_id:
+      result[0] = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.draw_id);
+      break;
    default:
       break;
    }
index d82044f770ff61185bfa1d739e661eedc1fac5ad..5019c1dd8f6e3ec2f6599602b06a496a947a6d8b 100644 (file)
@@ -171,6 +171,7 @@ struct lp_bld_tgsi_system_values {
    LLVMValueRef prim_id;
    LLVMValueRef basevertex;
    LLVMValueRef invocation_id;
+   LLVMValueRef draw_id;
    LLVMValueRef thread_id;
    LLVMValueRef block_id;
    LLVMValueRef grid_size;
index a4606a67615fa7bc7036b733c5dd862f60daf01e..5d18cfba4acfa46ec20a4d2f6b7a23330fed3ec4 100644 (file)
@@ -1345,6 +1345,11 @@ emit_fetch_system_value(
       res = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.front_facing);
       break;
 
+   case TGSI_SEMANTIC_DRAWID:
+      res = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->system_values.draw_id);
+      atype = TGSI_TYPE_UNSIGNED;
+      break;
+
    default:
       assert(!"unexpected semantic in emit_fetch_system_value");
       res = bld_base->base.zero;