iris: some draw info, vbs, sample mask
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 10 Jan 2018 08:19:29 +0000 (00:19 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Feb 2019 18:26:04 +0000 (10:26 -0800)
src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_draw.c
src/gallium/drivers/iris/iris_state.c

index 1af18e4bf3035693dfef93d59ad96bec68fc5158..7e8d358e39d934d490e660548639e2fe5eb2a357 100644 (file)
@@ -50,6 +50,8 @@ enum iris_dirty {
    IRIS_DIRTY_LINE_STIPPLE             = (1ull << 11),
    IRIS_DIRTY_VERTEX_ELEMENTS          = (1ull << 12),
    IRIS_DIRTY_MULTISAMPLE              = (1ull << 13),
+   IRIS_DIRTY_VERTEX_BUFFERS           = (1ull << 14),
+   IRIS_DIRTY_SAMPLE_MASK              = (1ull << 15),
 };
 
 struct iris_depth_stencil_alpha_state;
@@ -63,10 +65,12 @@ struct iris_context {
       uint64_t dirty;
       unsigned num_viewports; // XXX: can viewports + scissors be different?
       unsigned num_scissors;
+      unsigned sample_mask;
       struct iris_blend_state *cso_blend;
       struct iris_rasterizer_state *cso_rast;
       struct iris_depth_stencil_alpha_state *cso_zsa;
       struct iris_vertex_element_state *cso_vertex_elements;
+      struct iris_vertex_buffer_state *cso_vertex_buffers;
       struct iris_viewport_state *cso_vp;
       struct iris_depth_state *cso_depth;
       struct pipe_blend_color blend_color;
@@ -92,7 +96,9 @@ iris_create_context(struct pipe_screen *screen, void *priv, unsigned flags);
 void iris_init_program_functions(struct pipe_context *ctx);
 void iris_init_state_functions(struct pipe_context *ctx);
 
-void iris_upload_render_state(struct iris_context *ice, struct iris_batch *batch);
+void iris_upload_render_state(struct iris_context *ice,
+                              struct iris_batch *batch,
+                              struct pipe_draw_info *draw);
 void iris_destroy_state(struct iris_context *ice);
 
 #endif
index 748e2e6cc00d61ce0968511961659158dc0afb26..58b0187500ec928a0200e9bcb9ef826a0f5d5688 100644 (file)
@@ -66,7 +66,7 @@ iris_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 {
    struct iris_context *ice = (struct iris_context *) ctx;
 
-   iris_upload_render_state(ice);
+   iris_upload_render_state(ice, draw);
 
 #if 0
    l3 configuration
index 79eaa699670cee1741cdbd0be7068149e4cdbbe3..f161598292f2b9b637c2b448d04cfa7a7e957c28 100644 (file)
@@ -155,6 +155,32 @@ UNUSED static void pipe_asserts()
 #undef PIPE_ASSERT
 }
 
+static unsigned
+translate_prim_type(enum pipe_prim_type prim, uint8_t verts_per_patch)
+{
+   assert(prim == PIPE_PRIM_PATCHES || verts_per_patch == 0);
+
+   static const unsigned map[] = {
+      [PIPE_PRIM_POINTS]                   = _3DPRIM_POINTLIST,
+      [PIPE_PRIM_LINES]                    = _3DPRIM_LINELIST,
+      [PIPE_PRIM_LINE_LOOP]                = _3DPRIM_LINELOOP,
+      [PIPE_PRIM_LINE_STRIP]               = _3DPRIM_LINESTRIP,
+      [PIPE_PRIM_TRIANGLES]                = _3DPRIM_TRILIST,
+      [PIPE_PRIM_TRIANGLE_STRIP]           = _3DPRIM_TRISTRIP,
+      [PIPE_PRIM_TRIANGLE_FAN]             = _3DPRIM_TRIFAN,
+      [PIPE_PRIM_QUADS]                    = _3DPRIM_QUADLIST,
+      [PIPE_PRIM_QUAD_STRIP]               = _3DPRIM_QUADSTRIP,
+      [PIPE_PRIM_POLYGON]                  = _3DPRIM_POLYGON,
+      [PIPE_PRIM_LINES_ADJACENCY]          = _3DPRIM_LINELIST_ADJ,
+      [PIPE_PRIM_LINE_STRIP_ADJACENCY]     = _3DPRIM_LINESTRIP_ADJ,
+      [PIPE_PRIM_TRIANGLES_ADJACENCY]      = _3DPRIM_TRILIST_ADJ,
+      [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY] = _3DPRIM_TRISTRIP_ADJ,
+      [PIPE_PRIM_PATCHES]                  = _3DPRIM_PATCHLIST_1 - 1,
+   };
+
+   return map[prim] + verts_per_patch;
+}
+
 static unsigned
 translate_compare_func(enum pipe_compare_func pipe_func)
 {
@@ -827,8 +853,12 @@ iris_set_polygon_stipple(struct pipe_context *ctx,
 }
 
 static void
-iris_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
+iris_set_sample_mask(struct pipe_context *ctx, unsigned sample_mask)
 {
+   struct iris_context *ice = (struct iris_context *) ctx;
+
+   ice->state.sample_mask = sample_mask;
+   ice->state.dirty |= IRIS_DIRTY_SAMPLE_MASK;
 }
 
 static void
@@ -1072,6 +1102,7 @@ iris_set_vertex_buffers(struct pipe_context *ctx,
                         unsigned start_slot, unsigned count,
                         const struct pipe_vertex_buffer *buffers)
 {
+   struct iris_context *ice = (struct iris_context *) ctx;
    struct iris_vertex_buffer_state *cso =
       malloc(sizeof(struct iris_vertex_buffer_state));
 
@@ -1105,7 +1136,7 @@ iris_set_vertex_buffers(struct pipe_context *ctx,
       vb_pack_dest += GENX(VERTEX_BUFFER_STATE_length);
    }
 
-   /* XXX: actually do something with this! */
+   ice->state.dirty |= IRIS_DIRTY_VERTEX_BUFFERS;
 }
 
 struct iris_vertex_element_state {
@@ -1205,7 +1236,9 @@ iris_set_stream_output_targets(struct pipe_context *ctx,
 }
 
 void
-iris_upload_render_state(struct iris_context *ice, struct iris_batch *batch)
+iris_upload_render_state(struct iris_context *ice,
+                         struct iris_batch *batch,
+                         struct pipe_draw_info *draw)
 {
    const uint64_t dirty = ice->state.dirty;
 
@@ -1295,6 +1328,13 @@ iris_upload_render_state(struct iris_context *ice, struct iris_batch *batch)
       }
    }
 
+   if (dirty & IRIS_DIRTY_VERTEX_BUFFERS) {
+      struct iris_vertex_buffer_state *cso = ice->state.cso_vertex_buffers;
+      // XXX: address!!!
+      iris_batch_emit(batch, cso->vertex_buffers,
+                      sizeof(uint32_t) * cso->length);
+   }
+
    if (dirty & IRIS_DIRTY_VERTEX_ELEMENTS) {
       struct iris_vertex_element_state *cso = ice->state.cso_vertex_elements;
       iris_batch_emit(batch, cso->vertex_elements, sizeof(uint32_t) *
@@ -1317,6 +1357,58 @@ iris_upload_render_state(struct iris_context *ice, struct iris_batch *batch)
       }
    }
 
+   if (dirty & IRIS_DIRTY_SAMPLE_MASK) {
+      iris_emit_cmd(batch, GENX(3DSTATE_SAMPLE_MASK), ms) {
+         ms.SampleMask = ice->state.sample_mask;
+      }
+   }
+
+   if (1) {
+      iris_emit_cmd(batch, GENX(3DSTATE_VF_TOPOLOGY), topo) {
+         topo.PrimitiveTopologyType =
+            translate_prim_type(draw->mode, draw->vertices_per_patch);
+      }
+   }
+
+   if (1) {
+      iris_emit_cmd(batch, GENX(3DSTATE_VF), vf) {
+         vf.IndexedDrawCutIndexEnable = draw->primitive_restart;
+         vf.CutIndex = draw->restart_index;
+      }
+   }
+
+   // draw->index_size > 0
+   if (1) {
+      struct iris_resource *res = (struct iris_resource *)draw->index.resource;
+
+      assert(!draw->has_user_indices);
+
+      iris_emit_cmd(batch, GENX(3DSTATE_INDEX_BUFFER), ib) {
+         ib.IndexFormat = draw->index_size;
+         ib.MOCS = MOCS_WB;
+         ib.BufferSize = res->bo->size;
+         // XXX: gah, addresses :(  need two different combine address funcs
+         // ib.BufferStartingAddress = res->bo;
+      }
+
+      assert(!draw->indirect); // XXX: indirect support
+
+      iris_emit_cmd(batch, GENX(3DPRIMITIVE), prim) {
+         prim.StartInstanceLocation = draw->start_instance;
+         prim.InstanceCount = draw->instance_count;
+
+         // XXX: this is probably bonkers.
+         prim.StartVertexLocation = draw->start;
+
+         if (draw->index_size) {
+            prim.BaseVertexLocation += draw->index_bias;
+         } else {
+            prim.StartVertexLocation += draw->index_bias;
+         }
+
+         //prim.BaseVertexLocation = ...;
+      }
+   }
 #if 0
    l3 configuration
 
@@ -1370,21 +1462,6 @@ iris_upload_render_state(struct iris_context *ice, struct iris_batch *batch)
    3DSTATE_STENCIL_BUFFER
    3DSTATE_CLEAR_PARAMS
      -> iris_framebuffer_state?
-
-   3DSTATE_VF_TOPOLOGY
-     -> pipe_draw_info (prim_mode)
-   3DSTATE_VF
-     -> pipe_draw_info (restart_index, primitive_restart)
-
-   3DSTATE_INDEX_BUFFER
-     -> pipe_draw_info (index)
-   3DSTATE_VERTEX_BUFFERS
-     -> pipe_vertex_buffer (set_vertex_buffer hook)
-   3DSTATE_VF_COMPONENT_PACKING
-     -> TODO ???
-
-   3DPRIMITIVE
-     -> pipe_draw_info
 #endif
 }