ilo: get rid of GPE tables completely
[mesa.git] / src / gallium / drivers / ilo / ilo_transfer.c
index 4d6e3262a99698cece698140506f6459de0d355c..9f68d4ad9761b8f0f44ecafe1e0f33e8dc73077c 100644 (file)
 #include "ilo_cp.h"
 #include "ilo_context.h"
 #include "ilo_resource.h"
+#include "ilo_state.h"
 #include "ilo_transfer.h"
 
-enum ilo_transfer_map_method {
-   /* map() / map_gtt() / map_unsynchronized() */
-   ILO_TRANSFER_MAP_CPU,
-   ILO_TRANSFER_MAP_GTT,
-   ILO_TRANSFER_MAP_UNSYNC,
-
-   /* use staging system buffer */
-   ILO_TRANSFER_MAP_SW_CONVERT,
-   ILO_TRANSFER_MAP_SW_ZS,
-};
-
-struct ilo_transfer {
-   struct pipe_transfer base;
-
-   enum ilo_transfer_map_method method;
-   void *ptr;
-
-   void *staging_sys;
-};
-
-static inline struct ilo_transfer *
-ilo_transfer(struct pipe_transfer *transfer)
-{
-   return (struct ilo_transfer *) transfer;
-}
-
 static bool
 is_bo_busy(struct ilo_context *ilo, struct intel_bo *bo, bool *need_flush)
 {
-   const bool referenced = ilo->cp->bo->references(ilo->cp->bo, bo);
+   const bool referenced = intel_bo_references(ilo->cp->bo, bo);
 
    if (need_flush)
       *need_flush = referenced;
@@ -71,14 +46,6 @@ is_bo_busy(struct ilo_context *ilo, struct intel_bo *bo, bool *need_flush)
    if (referenced)
       return true;
 
-   /*
-    * XXX With hardware context support, the bo may be needed by GPU
-    * without being referenced by ilo->cp->bo.  We have to flush
-    * unconditionally, and that is bad.
-    */
-   if (ilo->cp->render_ctx)
-      ilo_cp_flush(ilo->cp);
-
    return intel_bo_is_busy(bo);
 }
 
@@ -90,13 +57,13 @@ map_bo_for_transfer(struct ilo_context *ilo, struct intel_bo *bo,
 
    switch (xfer->method) {
    case ILO_TRANSFER_MAP_CPU:
-      err = bo->map(bo, (xfer->base.usage & PIPE_TRANSFER_WRITE));
+      err = intel_bo_map(bo, (xfer->base.usage & PIPE_TRANSFER_WRITE));
       break;
    case ILO_TRANSFER_MAP_GTT:
-      err = bo->map_gtt(bo);
+      err = intel_bo_map_gtt(bo);
       break;
    case ILO_TRANSFER_MAP_UNSYNC:
-      err = bo->map_unsynchronized(bo);
+      err = intel_bo_map_unsynchronized(bo);
       break;
    default:
       assert(!"unknown mapping method");
@@ -169,8 +136,10 @@ choose_transfer_method(struct ilo_context *ilo, struct ilo_transfer *xfer)
       else if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
          /* discard old bo and allocate a new one for mapping */
          if ((tex && ilo_texture_alloc_bo(tex)) ||
-             (buf && ilo_buffer_alloc_bo(buf)))
+             (buf && ilo_buffer_alloc_bo(buf))) {
+            ilo_mark_states_with_resource_dirty(ilo, res);
             will_stall = false;
+         }
       }
       else if (usage & PIPE_TRANSFER_FLUSH_EXPLICIT) {
          /*
@@ -438,7 +407,7 @@ tex_staging_sys_zs_read(struct ilo_context *ilo,
 {
    const bool swizzle = ilo->dev->has_address_swizzling;
    const struct pipe_box *box = &xfer->base.box;
-   const uint8_t *src = tex->bo->get_virtual(tex->bo);
+   const uint8_t *src = intel_bo_get_virtual(tex->bo);
    tex_tile_offset_func tile_offset;
    unsigned tiles_per_row;
    int slice;
@@ -449,7 +418,7 @@ tex_staging_sys_zs_read(struct ilo_context *ilo,
 
    if (tex->separate_s8) {
       struct ilo_texture *s8_tex = tex->separate_s8;
-      const uint8_t *s8_src = s8_tex->bo->get_virtual(s8_tex->bo);
+      const uint8_t *s8_src = intel_bo_get_virtual(s8_tex->bo);
       tex_tile_offset_func s8_tile_offset;
       unsigned s8_tiles_per_row;
       int dst_cpp, dst_s8_pos, src_cpp_used;
@@ -549,7 +518,7 @@ tex_staging_sys_zs_write(struct ilo_context *ilo,
 {
    const bool swizzle = ilo->dev->has_address_swizzling;
    const struct pipe_box *box = &xfer->base.box;
-   uint8_t *dst = tex->bo->get_virtual(tex->bo);
+   uint8_t *dst = intel_bo_get_virtual(tex->bo);
    tex_tile_offset_func tile_offset;
    unsigned tiles_per_row;
    int slice;
@@ -560,7 +529,7 @@ tex_staging_sys_zs_write(struct ilo_context *ilo,
 
    if (tex->separate_s8) {
       struct ilo_texture *s8_tex = tex->separate_s8;
-      uint8_t *s8_dst = s8_tex->bo->get_virtual(s8_tex->bo);
+      uint8_t *s8_dst = intel_bo_get_virtual(s8_tex->bo);
       tex_tile_offset_func s8_tile_offset;
       unsigned s8_tiles_per_row;
       int src_cpp, src_s8_pos, dst_cpp_used;
@@ -663,7 +632,7 @@ tex_staging_sys_convert_write(struct ilo_context *ilo,
    void *dst;
    int slice;
 
-   dst = tex->bo->get_virtual(tex->bo);
+   dst = intel_bo_get_virtual(tex->bo);
    dst += tex_get_box_offset(tex, xfer->base.level, box);
 
    /* slice stride is not always available */
@@ -710,16 +679,16 @@ tex_staging_sys_map_bo(const struct ilo_context *ilo,
    int err;
 
    if (prefer_cpu && (tex->tiling == INTEL_TILING_NONE || !linear_view))
-      err = tex->bo->map(tex->bo, !for_read_back);
+      err = intel_bo_map(tex->bo, !for_read_back);
    else
-      err = tex->bo->map_gtt(tex->bo);
+      err = intel_bo_map_gtt(tex->bo);
 
    if (!tex->separate_s8)
       return !err;
 
-   err = tex->separate_s8->bo->map(tex->separate_s8->bo, !for_read_back);
+   err = intel_bo_map(tex->separate_s8->bo, !for_read_back);
    if (err)
-      tex->bo->unmap(tex->bo);
+      intel_bo_unmap(tex->bo);
 
    return !err;
 }
@@ -729,9 +698,9 @@ tex_staging_sys_unmap_bo(const struct ilo_context *ilo,
                          const struct ilo_texture *tex)
 {
    if (tex->separate_s8)
-      tex->separate_s8->bo->unmap(tex->separate_s8->bo);
+      intel_bo_unmap(tex->separate_s8->bo);
 
-   tex->bo->unmap(tex->bo);
+   intel_bo_unmap(tex->bo);
 }
 
 static void
@@ -833,7 +802,7 @@ tex_direct_unmap(struct ilo_context *ilo,
                  struct ilo_texture *tex,
                  struct ilo_transfer *xfer)
 {
-   tex->bo->unmap(tex->bo);
+   intel_bo_unmap(tex->bo);
 }
 
 static bool
@@ -853,7 +822,7 @@ tex_direct_map(struct ilo_context *ilo,
    else
       xfer->base.layer_stride = 0;
 
-   xfer->ptr = tex->bo->get_virtual(tex->bo);
+   xfer->ptr = intel_bo_get_virtual(tex->bo);
    xfer->ptr += tex_get_box_offset(tex, xfer->base.level, &xfer->base.box);
 
    return true;
@@ -928,7 +897,7 @@ buf_map(struct ilo_context *ilo, struct ilo_transfer *xfer)
    xfer->base.stride = 0;
    xfer->base.layer_stride = 0;
 
-   xfer->ptr = buf->bo->get_virtual(buf->bo);
+   xfer->ptr = intel_bo_get_virtual(buf->bo);
    xfer->ptr += xfer->base.box.x;
 
    return true;
@@ -939,7 +908,7 @@ buf_unmap(struct ilo_context *ilo, struct ilo_transfer *xfer)
 {
    struct ilo_buffer *buf = ilo_buffer(xfer->base.resource);
 
-   buf->bo->unmap(buf->bo);
+   intel_bo_unmap(buf->bo);
 }
 
 static void
@@ -954,8 +923,10 @@ buf_pwrite(struct ilo_context *ilo, struct ilo_buffer *buf,
 
       if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
          /* old data not needed so discard the old bo to avoid stalling */
-         if (ilo_buffer_alloc_bo(buf))
+         if (ilo_buffer_alloc_bo(buf)) {
+            ilo_mark_states_with_resource_dirty(ilo, &buf->base);
             will_stall = false;
+         }
       }
       else {
          /*
@@ -970,7 +941,7 @@ buf_pwrite(struct ilo_context *ilo, struct ilo_buffer *buf,
          ilo_cp_flush(ilo->cp);
    }
 
-   buf->bo->pwrite(buf->bo, offset, size, data);
+   intel_bo_pwrite(buf->bo, offset, size, data);
 }
 
 static void
@@ -993,7 +964,8 @@ ilo_transfer_unmap(struct pipe_context *pipe,
       tex_unmap(ilo, xfer);
 
    pipe_resource_reference(&xfer->base.resource, NULL);
-   FREE(xfer);
+
+   util_slab_free(&ilo->transfer_mempool, xfer);
 }
 
 static void *
@@ -1008,7 +980,7 @@ ilo_transfer_map(struct pipe_context *pipe,
    struct ilo_transfer *xfer;
    bool success;
 
-   xfer = MALLOC_STRUCT(ilo_transfer);
+   xfer = util_slab_alloc(&ilo->transfer_mempool);
    if (!xfer) {
       *transfer = NULL;
       return NULL;