iris: Unreference some more things on state module teardown
[mesa.git] / src / gallium / drivers / iris / iris_resource.c
index 6ab4614fb0ebecc9d64a7c7105e634c321290e1b..ca8832c5b345d0afd1eda6686f845849ad819f89 100644 (file)
@@ -459,14 +459,13 @@ iris_resource_from_handle(struct pipe_screen *pscreen,
 
    uint64_t modifier = whandle->modifier;
    if (modifier == DRM_FORMAT_MOD_INVALID) {
-         modifier = tiling_to_modifier(res->bo->tiling_mode);
+      modifier = tiling_to_modifier(res->bo->tiling_mode);
    }
    const struct isl_drm_modifier_info *mod_info =
       isl_drm_modifier_get_info(modifier);
    assert(mod_info);
 
-   // XXX: usage...
-   isl_surf_usage_flags_t isl_usage = ISL_SURF_USAGE_DISPLAY_BIT;
+   isl_surf_usage_flags_t isl_usage = pipe_bind_to_isl_usage(templ->bind);
 
    const struct iris_format_info fmt =
       iris_format_for_usage(devinfo, templ->format, isl_usage);
@@ -581,11 +580,11 @@ s8_offset(uint32_t stride, uint32_t x, uint32_t y, bool swizzled)
    if (swizzled) {
       /* adjust for bit6 swizzling */
       if (((byte_x / 8) % 2) == 1) {
-        if (((byte_y / 8) % 2) == 0) {
-           u += 64;
-        } else {
-           u -= 64;
-        }
+         if (((byte_y / 8) % 2) == 0) {
+            u += 64;
+         } else {
+            u -= 64;
+         }
       }
    }
 
@@ -770,11 +769,7 @@ iris_map_tiled_memcpy(struct iris_transfer *map)
          unsigned x1, x2, y1, y2;
          tile_extents(surf, &box, xfer->level, &x1, &x2, &y1, &y2);
 
-         /* When transferring cubes, box.depth is counted in cubes, but
-          * box.z is counted in faces.  We want to transfer only the
-          * specified face, but for all array elements.  So, use 's'
-          * (the zero-based slice count) rather than box.z.
-          */
+         /* Use 's' rather than 'box.z' to rebase the first slice to 0. */
          void *ptr = map->ptr + s * xfer->layer_stride;
 
          isl_memcpy_tiled_to_linear(x1, x2, y1, y2, ptr, src, xfer->stride,
@@ -829,6 +824,12 @@ iris_transfer_map(struct pipe_context *ctx,
    struct iris_resource *res = (struct iris_resource *)resource;
    struct isl_surf *surf = &res->surf;
 
+    /* If we can discard the whole resource, we can also discard the
+     * subrange being accessed.
+     */
+    if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE)
+       usage |= PIPE_TRANSFER_DISCARD_RANGE;
+
    if (surf->tiling != ISL_TILING_LINEAR &&
        (usage & PIPE_TRANSFER_MAP_DIRECTLY))
       return NULL;
@@ -846,9 +847,6 @@ iris_transfer_map(struct pipe_context *ctx,
    struct iris_transfer *map = slab_alloc(&ice->transfer_pool);
    struct pipe_transfer *xfer = &map->base;
 
-   // PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
-   // PIPE_TRANSFER_DISCARD_RANGE
-
    if (!map)
       return NULL;
 
@@ -935,6 +933,13 @@ iris_flush_and_dirty_for_history(struct iris_context *ice,
       return;
 
    unsigned flush = PIPE_CONTROL_CS_STALL;
+
+   /* We've likely used the rendering engine (i.e. BLORP) to write to this
+    * surface.  Flush the render cache so the data actually lands.
+    */
+   if (batch->name != IRIS_BATCH_COMPUTE)
+      flush |= PIPE_CONTROL_RENDER_TARGET_FLUSH;
+
    uint64_t dirty = 0ull;
 
    if (res->bind_history & PIPE_BIND_CONSTANT_BUFFER) {