i915g: Compute 3DSTATE_BUF_INFO flags at surface create time.
authorEmma Anholt <emma@anholt.net>
Sun, 20 Jun 2021 15:52:25 +0000 (08:52 -0700)
committerEmma Anholt <emma@anholt.net>
Tue, 22 Jun 2021 18:06:37 +0000 (11:06 -0700)
No need to compute them at state emit.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11512>

src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i915/i915_state_static.c
src/gallium/drivers/i915/i915_surface.c

index 65e24fb..65de266 100644 (file)
@@ -213,6 +213,7 @@ struct i915_sampler_state {
 
 struct i915_surface {
    struct pipe_surface templ;
+   uint32_t buf_info; /* _3DSTATE_BUF_INFO_CMD flags */
 };
 
 struct i915_velems_state {
index 1d8e211..3f6923c 100644 (file)
@@ -75,25 +75,6 @@ static unsigned translate_depth_format(enum pipe_format zformat)
    }
 }
 
-static inline uint32_t
-buf_3d_tiling_bits(enum i915_winsys_buffer_tile tiling)
-{
-   uint32_t tiling_bits = 0;
-
-   switch (tiling) {
-   case I915_TILE_Y:
-      tiling_bits |= BUF_3D_TILE_WALK_Y;
-      FALLTHROUGH;
-   case I915_TILE_X:
-      tiling_bits |= BUF_3D_TILED_SURFACE;
-      FALLTHROUGH;
-   case I915_TILE_NONE:
-      break;
-   }
-
-   return tiling_bits;
-}
-
 static void update_framebuffer(struct i915_context *i915)
 {
    struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
@@ -103,13 +84,12 @@ static void update_framebuffer(struct i915_context *i915)
    uint32_t draw_offset, draw_size;
 
    if (cbuf_surface) {
+      struct i915_surface *surf = i915_surface(cbuf_surface);
       struct i915_texture *tex = i915_texture(cbuf_surface->texture);
       assert(tex);
 
       i915->current.cbuf_bo = tex->buffer;
-      i915->current.cbuf_flags = BUF_3D_ID_COLOR_BACK |
-                                 BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
-                                 buf_3d_tiling_bits(tex->tiling);
+      i915->current.cbuf_flags = surf->buf_info;
 
       layer = cbuf_surface->u.tex.first_layer;
 
@@ -124,6 +104,7 @@ static void update_framebuffer(struct i915_context *i915)
    /* What happens if no zbuf??
     */
    if (depth_surface) {
+      struct i915_surface *surf = i915_surface(depth_surface);
       struct i915_texture *tex = i915_texture(depth_surface->texture);
       unsigned offset = i915_texture_offset(tex, depth_surface->u.tex.level,
                                             depth_surface->u.tex.first_layer);
@@ -132,9 +113,7 @@ static void update_framebuffer(struct i915_context *i915)
          debug_printf("Depth offset is %d\n",offset);
 
       i915->current.depth_bo = tex->buffer;
-      i915->current.depth_flags = BUF_3D_ID_DEPTH |
-                                  BUF_3D_PITCH(tex->stride) |  /* pitch in bytes */
-                                  buf_3d_tiling_bits(tex->tiling);
+      i915->current.depth_flags = surf->buf_info;
    } else
       i915->current.depth_bo = NULL;
    i915->static_dirty |= I915_DST_BUF_DEPTH;
index 095e978..3c717bc 100644 (file)
@@ -357,6 +357,7 @@ i915_create_surface_custom(struct pipe_context *ctx,
                            unsigned width0,
                            unsigned height0)
 {
+   struct i915_texture *tex = i915_texture(pt);
    struct i915_surface *surf;
 
    assert(surf_tmpl->u.tex.first_layer == surf_tmpl->u.tex.last_layer);
@@ -380,6 +381,25 @@ i915_create_surface_custom(struct pipe_context *ctx,
    ps->u.tex.last_layer = surf_tmpl->u.tex.last_layer;
    ps->context = ctx;
 
+   if (util_format_is_depth_or_stencil(ps->format)) {
+      surf->buf_info = BUF_3D_ID_DEPTH;
+   } else {
+      surf->buf_info = BUF_3D_ID_COLOR_BACK;
+   }
+
+   surf->buf_info |= BUF_3D_PITCH(tex->stride); /* pitch in bytes */
+
+   switch (tex->tiling) {
+   case I915_TILE_Y:
+      surf->buf_info |= BUF_3D_TILED_SURFACE | BUF_3D_TILE_WALK_Y;
+      break;
+   case I915_TILE_X:
+      surf->buf_info |= BUF_3D_TILED_SURFACE;
+      break;
+   case I915_TILE_NONE:
+      break;
+   }
+
    return ps;
 }