panfrost/midgard: Use unsigned blend patch offset
[mesa.git] / src / gallium / drivers / panfrost / pan_resource.c
index 8901aeee09b1c537da316fc5bfd39ff529a810fc..4acbae25d4a1fe6ef38205ba34727b32d85671cf 100644 (file)
@@ -70,7 +70,7 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
         pipe_reference_init(&prsc->reference, 1);
         prsc->screen = pscreen;
 
-       rsc->bo = panfrost_drm_import_bo(screen, whandle);
+       rsc->bo = panfrost_drm_import_bo(screen, whandle->handle);
        rsc->slices[0].stride = whandle->stride;
        rsc->slices[0].initialized = true;
 
@@ -120,10 +120,16 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen,
                         handle->handle = args.fd;
 
                         return TRUE;
-                } else
-                       return panfrost_drm_export_bo(screen, rsrc->bo->gem_handle,
-                                                      rsrc->slices[0].stride,
-                                                      handle);
+                } else {
+                        int fd = panfrost_drm_export_bo(screen, rsrc->bo);
+
+                        if (fd < 0)
+                                return FALSE;
+
+                        handle->handle = fd;
+                        handle->stride = rsrc->slices[0].stride;
+                        return TRUE;
+               }
        }
 
        return FALSE;
@@ -223,8 +229,8 @@ panfrost_compute_checksum_sizes(
                 unsigned width,
                 unsigned height)
 {
-        unsigned aligned_width = ALIGN(width, CHECKSUM_TILE_WIDTH);
-        unsigned aligned_height = ALIGN(height, CHECKSUM_TILE_HEIGHT);
+        unsigned aligned_width = ALIGN_POT(width, CHECKSUM_TILE_WIDTH);
+        unsigned aligned_height = ALIGN_POT(height, CHECKSUM_TILE_HEIGHT);
 
         unsigned tile_count_x = aligned_width / CHECKSUM_TILE_WIDTH;
         unsigned tile_count_y = aligned_height / CHECKSUM_TILE_HEIGHT;
@@ -276,8 +282,8 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
                 unsigned effective_depth = depth;
 
                 if (should_align) {
-                        effective_width = ALIGN(effective_width, 16);
-                        effective_height = ALIGN(effective_height, 16);
+                        effective_width = ALIGN_POT(effective_width, 16);
+                        effective_height = ALIGN_POT(effective_height, 16);
 
                         /* We don't need to align depth */
                 }
@@ -289,7 +295,7 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
 
                 /* ..but cache-line align it for performance */
                 if (can_align_stride && pres->layout == PAN_LINEAR)
-                        stride = ALIGN(stride, 64);
+                        stride = ALIGN_POT(stride, 64);
 
                 slice->stride = stride;
 
@@ -331,14 +337,14 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
         if (res->target != PIPE_TEXTURE_3D) {
                 /* Arrays and cubemaps have the entire miptree duplicated */
 
-                pres->cubemap_stride = ALIGN(offset, 64);
-                *bo_size = ALIGN(pres->cubemap_stride * res->array_size, 4096);
+                pres->cubemap_stride = ALIGN_POT(offset, 64);
+                *bo_size = ALIGN_POT(pres->cubemap_stride * res->array_size, 4096);
         } else {
                 /* 3D strides across the 2D layers */
                 assert(res->array_size == 1);
 
                 pres->cubemap_stride = size_2d;
-                *bo_size = ALIGN(offset, 4096);
+                *bo_size = ALIGN_POT(offset, 4096);
         }
 }
 
@@ -385,18 +391,7 @@ panfrost_resource_create_bo(struct panfrost_screen *screen, struct panfrost_reso
         size_t bo_size;
 
         panfrost_setup_slices(pres, &bo_size);
-
-        struct panfrost_memory mem;
-        struct panfrost_bo *bo = rzalloc(screen, struct panfrost_bo);
-
-        pipe_reference_init(&bo->reference, 1);
-        panfrost_drm_allocate_slab(screen, &mem, bo_size / 4096, true, 0, 0, 0);
-
-        bo->cpu = mem.cpu;
-        bo->gpu = mem.gpu;
-        bo->gem_handle = mem.gem_handle;
-       bo->size = bo_size;
-       pres->bo = bo;
+        pres->bo = panfrost_drm_create_bo(screen, bo_size, 0);
 }
 
 static struct pipe_resource *
@@ -436,20 +431,6 @@ panfrost_resource_create(struct pipe_screen *screen,
         return (struct pipe_resource *)so;
 }
 
-static void
-panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *bo)
-{
-        struct panfrost_memory mem = {
-                .cpu = bo->cpu,
-                .gpu = bo->gpu,
-                .size = bo->size,
-                .gem_handle = bo->gem_handle,
-        };
-
-        panfrost_drm_free_slab(screen, &mem);
-        ralloc_free(bo);
-}
-
 void
 panfrost_bo_reference(struct panfrost_bo *bo)
 {
@@ -461,9 +442,8 @@ panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
 {
         /* When the reference count goes to zero, we need to cleanup */
 
-        if (pipe_reference(&bo->reference, NULL)) {
-                panfrost_destroy_bo(pan_screen(screen), bo);
-        }
+        if (pipe_reference(&bo->reference, NULL))
+                panfrost_drm_release_bo(pan_screen(screen), bo);
 }
 
 static void