r600g: remove an unused parameter from r600_bo_destroy
[mesa.git] / src / gallium / winsys / r600 / drm / r600_bo.c
index 9498f3a82eaf4685de82e15adf3762b5c3cf2194..123f718e664ce02fb82669dfc4a0670f24cb0390 100644 (file)
  * Authors:
  *      Dave Airlie
  */
-#include <pipe/p_compiler.h>
-#include <pipe/p_screen.h>
-#include <pipebuffer/pb_bufmgr.h>
 #include "r600_priv.h"
+#include "r600d.h"
+#include "state_tracker/drm_driver.h"
+#include "radeon_drm.h"
 
 struct r600_bo *r600_bo(struct radeon *radeon,
-                                 unsigned size, unsigned alignment, unsigned usage)
+                       unsigned size, unsigned alignment,
+                       unsigned binding, unsigned usage)
 {
-       struct r600_bo *ws_bo = calloc(1, sizeof(struct r600_bo));
-       struct pb_desc desc;
-       struct pb_manager *man;
-
-       desc.alignment = alignment;
-       desc.usage = usage;
-       ws_bo->size = size;
-
-       if (usage & (PIPE_BIND_CONSTANT_BUFFER | PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER))
-               man = radeon->cman;
-       else
-               man = radeon->kman;
-
-       ws_bo->pb = man->create_buffer(man, size, &desc);
-       if (ws_bo->pb == NULL) {
-               free(ws_bo);
+       struct r600_bo *bo;
+       struct pb_buffer *pb;
+       uint32_t initial_domain, domains;
+         
+       /* Staging resources particpate in transfers and blits only
+        * and are used for uploads and downloads from regular
+        * resources.  We generate them internally for some transfers.
+        */
+       if (usage == PIPE_USAGE_STAGING) {
+               domains = RADEON_GEM_DOMAIN_GTT;
+               initial_domain = RADEON_GEM_DOMAIN_GTT;
+       } else {
+               domains = RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM;
+
+               switch(usage) {
+               case PIPE_USAGE_DYNAMIC:
+               case PIPE_USAGE_STREAM:
+               case PIPE_USAGE_STAGING:
+                       initial_domain = RADEON_GEM_DOMAIN_GTT;
+                       break;
+               case PIPE_USAGE_DEFAULT:
+               case PIPE_USAGE_STATIC:
+               case PIPE_USAGE_IMMUTABLE:
+               default:
+                       initial_domain = RADEON_GEM_DOMAIN_VRAM;
+                       break;
+               }
+       }
+
+       pb = radeon->ws->buffer_create(radeon->ws, size, alignment, binding, initial_domain);
+       if (!pb) {
                return NULL;
        }
 
-       pipe_reference_init(&ws_bo->reference, 1);
-       return ws_bo;
+       bo = calloc(1, sizeof(struct r600_bo));
+       bo->domains = domains;
+       bo->buf = pb;
+       bo->cs_buf = radeon->ws->buffer_get_cs_handle(pb);
+
+       pipe_reference_init(&bo->reference, 1);
+       return bo;
 }
 
-struct r600_bo *r600_bo_handle(struct radeon *radeon,
-                                        unsigned handle)
+struct r600_bo *r600_bo_handle(struct radeon *radeon, struct winsys_handle *whandle,
+                              unsigned *stride, unsigned *array_mode)
 {
-       struct r600_bo *ws_bo = calloc(1, sizeof(struct r600_bo));
-       struct radeon_bo *bo;
+       struct pb_buffer *pb;
+       struct r600_bo *bo = calloc(1, sizeof(struct r600_bo));
 
-       ws_bo->pb = radeon_bo_pb_create_buffer_from_handle(radeon->kman, handle);
-       if (!ws_bo->pb) {
-               free(ws_bo);
+       pb = bo->buf = radeon->ws->buffer_from_handle(radeon->ws, whandle, stride, NULL);
+       if (!pb) {
+               free(bo);
                return NULL;
        }
-       bo = radeon_bo_pb_get_bo(ws_bo->pb);
-       ws_bo->size = bo->size;
-       pipe_reference_init(&ws_bo->reference, 1);
-       return ws_bo;
-}
 
-void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx)
-{
-       return pb_map(bo->pb, usage, ctx);
-}
+       pipe_reference_init(&bo->reference, 1);
+       bo->domains = RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM;
+       bo->cs_buf = radeon->ws->buffer_get_cs_handle(pb);
 
-void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo)
-{
-       pb_unmap(bo->pb);
+       if (stride)
+               *stride = whandle->stride;
+
+       if (array_mode) {
+               enum radeon_bo_layout micro, macro;
+
+               radeon->ws->buffer_get_tiling(bo->buf, &micro, &macro);
+
+               if (macro == RADEON_LAYOUT_TILED)
+                       *array_mode = V_0280A0_ARRAY_2D_TILED_THIN1;
+               else if (micro == RADEON_LAYOUT_TILED)
+                       *array_mode = V_0280A0_ARRAY_1D_TILED_THIN1;
+               else
+                       *array_mode = 0;
+       }
+       return bo;
 }
 
-static void r600_bo_destroy(struct radeon *radeon, struct r600_bo *bo)
+void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, struct radeon_winsys_cs *cs, unsigned usage)
 {
-       if (bo->pb)
-               pb_reference(&bo->pb, NULL);
-       free(bo);
+       return radeon->ws->buffer_map(bo->buf, cs, usage);
 }
 
-void r600_bo_reference(struct radeon *radeon, struct r600_bo **dst,
-                           struct r600_bo *src)
+void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo)
 {
-       struct r600_bo *old = *dst;
-               
-       if (pipe_reference(&(*dst)->reference, &src->reference)) {
-               r600_bo_destroy(radeon, old);
-       }
-       *dst = src;
+       radeon->ws->buffer_unmap(bo->buf);
 }
 
-unsigned r600_bo_get_handle(struct r600_bo *pb_bo)
+void r600_bo_destroy(struct r600_bo *bo)
 {
-       struct radeon_bo *bo;
-
-       bo = radeon_bo_pb_get_bo(pb_bo->pb);
-       if (!bo)
-               return 0;
-
-       return bo->handle;
+       pb_reference(&bo->buf, NULL);
+       free(bo);
 }
 
-unsigned r600_bo_get_size(struct r600_bo *pb_bo)
+boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *bo,
+                                 unsigned stride, struct winsys_handle *whandle)
 {
-       struct radeon_bo *bo;
-
-       bo = radeon_bo_pb_get_bo(pb_bo->pb);
-       if (!bo)
-               return 0;
-
-       return bo->size;
+       return radeon->ws->buffer_get_handle(bo->buf, stride, whandle);
 }