r300-gallium, radeon-gallium: Begin migration to DRI2 state tracker, part 1.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 4 Mar 2009 05:14:33 +0000 (21:14 -0800)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 4 Mar 2009 06:16:24 +0000 (22:16 -0800)
s/migration/migrane/ , actually. Anyway, this has working glxinfo...

14 files changed:
src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_screen.h
src/gallium/drivers/r300/r300_winsys.h
src/gallium/winsys/drm/radeon/Makefile
src/gallium/winsys/drm/radeon/radeon_buffer.c
src/gallium/winsys/drm/radeon/radeon_buffer.h
src/gallium/winsys/drm/radeon/radeon_drm.c
src/gallium/winsys/drm/radeon/radeon_drm.h
src/gallium/winsys/drm/radeon/radeon_r300.c
src/gallium/winsys/drm/radeon/radeon_r300.h
src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c
src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h

index a9811501435d20ffbf2f65f34c4925959984566b..653d919ef1d54435fdc6ff14233378f6640b86d4 100644 (file)
@@ -103,7 +103,6 @@ static void r300_destroy_context(struct pipe_context* context) {
 }
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
-                                         struct pipe_winsys* winsys,
                                          struct r300_winsys* r300_winsys)
 {
     struct r300_context* r300 = CALLOC_STRUCT(r300_context);
@@ -111,9 +110,11 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     if (!r300)
         return NULL;
 
+    /* XXX this could be refactored now? */
     r300->winsys = r300_winsys;
-    r300->context.winsys = winsys;
-    r300->context.screen = r300_create_screen(winsys, r300_winsys);
+
+    r300->context.winsys = (struct pipe_winsys*)r300_winsys;
+    r300->context.screen = r300_screen(screen);
 
     r300->context.destroy = r300_destroy_context;
 
index 5247901be5b0cdbf651e53a153ebfd20eca91dcc..2be9e2eb33375495f43b1889aab4ed7dd16eabdb 100644 (file)
@@ -268,7 +268,6 @@ void r300_init_surface_functions(struct r300_context* r300);
  * We'll just step out in that case... */
 #ifndef R300_WINSYS_H
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
-                                         struct pipe_winsys* winsys,
                                          struct r300_winsys* r300_winsys);
 #endif
 
index 2fcd50481283ac505405f225859849bc7bab808b..e97334463a3f366d4851fb9709577fbdd4cf6069 100644 (file)
@@ -337,8 +337,7 @@ static void r300_destroy_screen(struct pipe_screen* pscreen)
     FREE(r300screen);
 }
 
-struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys,
-                                       struct r300_winsys* r300_winsys)
+struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys)
 {
     struct r300_screen* r300screen = CALLOC_STRUCT(r300_screen);
     struct r300_capabilities* caps = CALLOC_STRUCT(r300_capabilities);
@@ -352,7 +351,7 @@ struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys,
     r300_parse_chipset(caps);
 
     r300screen->caps = caps;
-    r300screen->screen.winsys = winsys;
+    r300screen->screen.winsys = (struct pipe_winsys*)r300_winsys;
     r300screen->screen.destroy = r300_destroy_screen;
     r300screen->screen.get_name = r300_get_name;
     r300screen->screen.get_vendor = r300_get_vendor;
index 6c845144cb3a53b09870ab8943a23b4c43b5e969..3f52dbc3beaebf1ac381cda80205a2ab4e34b93a 100644 (file)
@@ -61,7 +61,6 @@ r300_transfer(struct pipe_transfer* transfer)
 }
 
 /* Creates a new r300 screen. */
-struct pipe_screen* r300_create_screen(struct pipe_winsys* winsys,
-                                       struct r300_winsys* r300_winsys);
+struct pipe_screen* r300_create_screen(struct r300_winsys* r300_winsys);
 
 #endif /* R300_SCREEN_H */
index 5a3a2128927f681434772b5ebadd5fa324d9921c..b7341c4f3ad416b4b0d80a8ec69feb4ea9d4b761 100644 (file)
@@ -33,10 +33,16 @@ extern "C" {
 
 #include "pipe/p_defines.h"
 #include "pipe/p_state.h"
+#include "pipe/internal/p_winsys_screen.h"
 
 struct radeon_cs;
 
 struct r300_winsys {
+    /* Parent class */
+    struct pipe_winsys base;
+
+    /* Opaque Radeon-specific winsys object. */
+    void* radeon_winsys;
 
     /* PCI ID */
     uint32_t pci_id;
@@ -47,10 +53,6 @@ struct r300_winsys {
     /* CS object. This is very much like Intel's batchbuffer.
      * Fill it full of dwords and relocs and then submit.
      * Repeat as needed. */
-    /* Note: Unlike Mesa's version of this, we don't keep a copy of the CSM
-     * that was used to create this CS. Is this a good idea? */
-    /* Note: The pipe driver doesn't know how to use this. This is purely
-     * for the winsys. */
     struct radeon_cs* cs;
 
     /* Check to see if there's room for commands. */
@@ -84,7 +86,6 @@ struct r300_winsys {
 };
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
-                                         struct pipe_winsys* winsys,
                                          struct r300_winsys* r300_winsys);
 
 #ifdef __cplusplus
index 784686ffb6808a1b98e64529327ff38233eee1db..8721f2cb5d47aac7805c13de48da036ddfc37ebd 100644 (file)
@@ -7,15 +7,14 @@ LIBNAME = radeon_dri.so
 MINIGLX_SOURCES =
 
 PIPE_DRIVERS = \
+       $(TOP)/src/gallium/state_trackers/dri2/libdri2drm.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
        $(TOP)/src/gallium/drivers/r300/libr300.a
 
 DRIVER_SOURCES = \
        radeon_buffer.c \
-       radeon_context.c \
        radeon_drm.c \
        radeon_r300.c \
-       radeon_screen.c \
        radeon_winsys_softpipe.c
 
 C_SOURCES = \
index 918d2f98e2a01528906a814054aa639d2ef2a632..79b8f777ca833ba8d8363b76a630a6718d7c3d68 100644 (file)
@@ -1,5 +1,6 @@
 /* 
  * Copyright © 2008 Jérôme Glisse
+ *             2009 Corbin Simpson
  * All Rights Reserved.
  * 
  * Permission is hereby granted, free of charge, to any person obtaining
 /*
  * Authors:
  *      Jérôme Glisse <glisse@freedesktop.org>
+ *      Corbin Simpson <MostAwesomeDude@gmail.com>
  */
 #include <stdio.h>
-#include "dri_util.h"
+
 #include "state_tracker/st_public.h"
+
+#include "util/u_memory.h"
+
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
 #include "radeon_buffer.h"
 #include "radeon_bo.h"
 #include "radeon_drm.h"
 
+
 static const char *radeon_get_name(struct pipe_winsys *ws)
 {
-    return "RADEON/DRI2";
+    return "Radeon/GEM+KMS";
 }
 
 static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws,
-                                             unsigned alignment,
-                                             unsigned usage,
-                                             unsigned size)
+                                                unsigned alignment,
+                                                unsigned usage,
+                                                unsigned size)
 {
-    struct radeon_pipe_winsys *radeon_ws = (struct radeon_pipe_winsys *)ws;
+    struct radeon_winsys *radeon_ws = (struct radeon_winsys *)ws;
     struct radeon_pipe_buffer *radeon_buffer;
     uint32_t domain;
 
-    radeon_buffer = calloc(1, sizeof(*radeon_buffer));
+    radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
     if (radeon_buffer == NULL) {
         return NULL;
     }
+
     radeon_buffer->base.refcount = 1;
     radeon_buffer->base.alignment = alignment;
     radeon_buffer->base.usage = usage;
@@ -69,21 +76,21 @@ static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws,
     if (usage & PIPE_BUFFER_USAGE_VERTEX) {
         domain |= RADEON_GEM_DOMAIN_GTT;
     }
-
     if (usage & PIPE_BUFFER_USAGE_INDEX) {
         domain |= RADEON_GEM_DOMAIN_GTT;
     }
-    radeon_buffer->bo = radeon_bo_open(radeon_ws->radeon_screen->bom, 0,
-                                    size, alignment, domain, 0);
+
+    radeon_buffer->bo = radeon_bo_open(radeon_ws->bom, 0, size, alignment,
+                                       domain, 0);
     if (radeon_buffer->bo == NULL) {
-        free(radeon_buffer);
+        FREE(radeon_buffer);
     }
     return &radeon_buffer->base;
 }
 
 static struct pipe_buffer *radeon_buffer_user_create(struct pipe_winsys *ws,
-                                                  void *ptr,
-                                                  unsigned bytes)
+                                                     void *ptr,
+                                                     unsigned bytes)
 {
     struct radeon_pipe_buffer *radeon_buffer;
 
@@ -106,21 +113,20 @@ static void radeon_buffer_del(struct pipe_winsys *ws, struct pipe_buffer *buffer
 }
 
 static void *radeon_buffer_map(struct pipe_winsys *ws,
-                            struct pipe_buffer *buffer,
-                            unsigned flags)
+                               struct pipe_buffer *buffer,
+                               unsigned flags)
 {
     struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer;
     int write = 0;
 
     if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) {
-       /* Remove this when radeon_bo_map supports DONTBLOCK 
-        */
+       /* XXX Remove this when radeon_bo_map supports DONTBLOCK */
        return NULL;
     }
-
     if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) {
         write = 1;
     }
+
     if (radeon_bo_map(radeon_buffer->bo, write))
         return NULL;
     return radeon_buffer->bo->ptr;
@@ -134,59 +140,58 @@ static void radeon_buffer_unmap(struct pipe_winsys *ws, struct pipe_buffer *buff
 }
 
 static void radeon_fence_reference(struct pipe_winsys *ws,
-                                struct pipe_fence_handle **ptr,
-                                struct pipe_fence_handle *pfence)
+                                   struct pipe_fence_handle **ptr,
+                                   struct pipe_fence_handle *pfence)
 {
 }
 
 static int radeon_fence_signalled(struct pipe_winsys *ws,
-                               struct pipe_fence_handle *pfence,
-                               unsigned flag)
+                                  struct pipe_fence_handle *pfence,
+                                  unsigned flag)
 {
     return 1;
 }
 
 static int radeon_fence_finish(struct pipe_winsys *ws,
-                            struct pipe_fence_handle *pfence,
-                            unsigned flag)
+                               struct pipe_fence_handle *pfence,
+                               unsigned flag)
 {
     return 0;
 }
 
 static void radeon_flush_frontbuffer(struct pipe_winsys *pipe_winsys,
-                                  struct pipe_surface *pipe_surface,
-                                  void *context_private)
+                                     struct pipe_surface *pipe_surface,
+                                     void *context_private)
 {
     /* TODO: call dri2CopyRegion */
 }
 
-struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen)
+struct pipe_winsys *radeon_pipe_winsys()
 {
-    struct radeon_pipe_winsys *radeon_ws;
+    struct pipe_winsys *radeon_ws;
 
-    radeon_ws = calloc(1, sizeof(struct radeon_pipe_winsys));
+    radeon_ws = CALLOC_STRUCT(pipe_winsys);
     if (radeon_ws == NULL) {
         return NULL;
     }
-    radeon_ws->radeon_screen = radeon_screen;
 
-    radeon_ws->winsys.flush_frontbuffer = radeon_flush_frontbuffer;
+    radeon_ws->flush_frontbuffer = radeon_flush_frontbuffer;
 
-    radeon_ws->winsys.buffer_create = radeon_buffer_create;
-    radeon_ws->winsys.buffer_destroy = radeon_buffer_del;
-    radeon_ws->winsys.user_buffer_create = radeon_buffer_user_create;
-    radeon_ws->winsys.buffer_map = radeon_buffer_map;
-    radeon_ws->winsys.buffer_unmap = radeon_buffer_unmap;
+    radeon_ws->buffer_create = radeon_buffer_create;
+    radeon_ws->buffer_destroy = radeon_buffer_del;
+    radeon_ws->user_buffer_create = radeon_buffer_user_create;
+    radeon_ws->buffer_map = radeon_buffer_map;
+    radeon_ws->buffer_unmap = radeon_buffer_unmap;
 
-    radeon_ws->winsys.fence_reference = radeon_fence_reference;
-    radeon_ws->winsys.fence_signalled = radeon_fence_signalled;
-    radeon_ws->winsys.fence_finish = radeon_fence_finish;
+    radeon_ws->fence_reference = radeon_fence_reference;
+    radeon_ws->fence_signalled = radeon_fence_signalled;
+    radeon_ws->fence_finish = radeon_fence_finish;
 
-    radeon_ws->winsys.get_name = radeon_get_name;
+    radeon_ws->get_name = radeon_get_name;
 
-    return &radeon_ws->winsys;
+    return radeon_ws;
 }
-
+#if 0
 static struct pipe_buffer *radeon_buffer_from_handle(struct radeon_screen *radeon_screen,
                                                   uint32_t handle)
 {
@@ -243,3 +248,4 @@ struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_co
                                       PIPE_BUFFER_USAGE_GPU_WRITE);
     return ps;
 }
+#endif
\ No newline at end of file
index c626c20229bebb00294f697b4674344044898300..e062308f440cb7bfd535748724425f5e7a0634da 100644 (file)
@@ -40,12 +40,15 @@ struct radeon_pipe_buffer {
     struct radeon_bo    *bo;
 };
 
-struct radeon_pipe_winsys {
-    struct pipe_winsys      winsys;
-    struct radeon_screen       *radeon_screen;
+struct radeon_winsys {
+    /* Parent class. */
+    struct pipe_winsys base;
+
+    /* Radeon BO manager. This corresponds to void* radeon_winsys in r300_winsys. */
+    struct radeon_bo_manager* bom;
 };
 
-struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen);
+struct pipe_winsys *radeon_pipe_winsys();
 struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_context,
                                              uint32_t handle,
                                              enum pipe_format format,
index 839b0bf0bd4b3bc3fcc61489a1f3cf468c7bf7cb..9cd178f944aab464ccd97cf3e8011f41c6df60db 100644 (file)
  * Authors:
  *      Corbin Simpson <MostAwesomeDude@gmail.com>
  */
+
 #include "radeon_drm.h"
+
+/* Create a pipe_screen. */
+struct pipe_screen* radeon_create_screen(int drmFB, int pciID)
+{
+    struct radeon_context* radeon = CALLOC_STRUCT(radeon_context);
+    struct pipe_winsys* winsys = radeon_pipe_winsys(radeon);
+
+    if (getenv("RADEON_SOFTPIPE")) {
+        return softpipe_create_screen(winsys);
+    } else {
+        struct r300_winsys* r300 = radeon_create_r300_winsys(drmFB, winsys);
+        FREE(winsys);
+        return r300_create_screen(r300);
+    }
+}
+
+/* Create a pipe_context. */
+struct pipe_context* radeon_create_context(struct pipe_screen* screen)
+{
+    if (getenv("RADEON_SOFTPIPE")) {
+        return radeon_create_softpipe(screen->winsys);
+    } else {
+        return r300_create_context(screen, screen->winsys);
+    }
+}
+
+boolean radeon_buffer_from_texture(struct pipe_texture* texture,
+                                   struct pipe_buffer** buffer,
+                                   unsigned* stride)
+{
+}
+
+/* Create a buffer from a handle. */
+/* XXX what's up with name? */
+struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen,
+                                              const char* name,
+                                              unsigned handle)
+{
+    struct radeon_bo_manager* bom = ((struct radeon_winsys*)screen->winsys)->bom;
+    struct radeon_pipe_buffer* radeon_buffer;
+    struct radeon_bo* bo = NULL;
+
+    bo = radeon_bo_open(bom, handle, 0, 0, 0, 0);
+    if (bo == NULL) {
+        return NULL;
+    }
+
+    radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
+    if (radeon_buffer == NULL) {
+        radeon_bo_unref(bo);
+        return NULL;
+    }
+
+    radeon_buffer->base.refcount = 1;
+    radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
+    radeon_buffer->bo = bo;
+    return &radeon_buffer->base;
+}
+
+boolean radeon_handle_from_buffer(struct pipe_screen* screen,
+                                  struct pipe_buffer* buffer,
+                                  unsigned* handle)
+{
+}
+
+boolean radeon_global_handle_from_buffer(struct pipe_screen* screen,
+                                         struct pipe_buffer* buffer,
+                                         unsigned* handle)
+{
+}
+
+struct drm_api drm_api_hooks = {
+    .create_screen = radeon_create_screen,
+    .create_context = radeon_create_context,
+    .buffer_from_texture = radeon_buffer_from_texture,
+    .buffer_from_handle = radeon_buffer_from_handle,
+    .handle_from_buffer = radeon_handle_from_buffer,
+    .global_handle_from_buffer = radeon_global_handle_from_buffer,
+};
\ No newline at end of file
index 8ccbc81895908472518fa2eef46e9e6350f58fc2..e434106cb5b0c551d76dc7363d40e62b9a136c93 100644 (file)
 #ifndef RADEON_DRM_H
 #define RADEON_DRM_H
 
+#include "pipe/p_screen.h"
+
+#include "util/u_memory.h"
+
 #include "state_tracker/drm_api.h"
 
+#include "radeon_buffer.h"
+#include "radeon_context.h"
+#include "radeon_r300.h"
+#include "radeon_screen.h"
+#include "radeon_winsys_softpipe.h"
+
+struct pipe_screen* radeon_create_screen(int drmFB, int pciID);
+
+struct pipe_context* radeon_create_context(struct pipe_screen* screen);
+
+boolean radeon_buffer_from_texture(struct pipe_texture* texture,
+                                   struct pipe_buffer** buffer,
+                                   unsigned* stride);
+
+struct pipe_buffer* radeon_buffer_from_handle(struct pipe_screen* screen,
+                                              const char* name,
+                                              unsigned handle);
+
+boolean radeon_handle_from_buffer(struct pipe_screen* screen,
+                                  struct pipe_buffer* buffer,
+                                  unsigned* handle);
+
+boolean radeon_global_handle_from_buffer(struct pipe_screen* screen,
+                                         struct pipe_buffer* buffer,
+                                         unsigned* handle);
+
 #endif
index 8fe2375e34de77e3b85eb724d408927421d1f829..e9b96b1ee93d856be476fc1af9e855e181300f4b 100644 (file)
@@ -75,14 +75,16 @@ static void do_ioctls(struct r300_winsys* winsys, int fd)
 
 }
 
-struct r300_winsys* radeon_create_r300_winsys(int fd)
+struct r300_winsys* radeon_create_r300_winsys(int fd, struct pipe_winsys* old_winsys)
 {
-    struct r300_winsys* winsys = calloc(1, sizeof(struct r300_winsys));
+    struct r300_winsys* winsys = CALLOC_STRUCT(r300_winsys);
 
     do_ioctls(winsys, fd);
 
+    struct radeon_bo_manager* bom = radeon_bo_manager_gem_ctor(fd);
     struct radeon_cs_manager* csm = radeon_cs_manager_gem_ctor(fd);
 
+    winsys->radeon_winsys = bom;
     winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4);
 
     winsys->check_cs = radeon_r300_check_cs;
@@ -92,5 +94,7 @@ struct r300_winsys* radeon_create_r300_winsys(int fd)
     winsys->end_cs = radeon_cs_end;
     winsys->flush_cs = radeon_r300_flush_cs;
 
+    winsys->base = *old_winsys;
+
     return winsys;
 }
index 8ed95a3a9b15e8091e0216e01669d810ab9c66bc..432b7b18331c2fab53538344b61d2b08c9d03e1f 100644 (file)
@@ -31,4 +31,4 @@
 
 #include "radeon_buffer.h"
 
-struct r300_winsys* radeon_create_r300_winsys(int fd);
+struct r300_winsys* radeon_create_r300_winsys(int fd, struct pipe_winsys* old_winsys);
index 8402e1fa5a83f940f5103869055eec359b9b5eea..75e975f5e28ec0e0b4370de8a5dfff27a48e2339 100644 (file)
@@ -29,7 +29,6 @@
  * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
  */
 #include <stdio.h>
-#include "imports.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_format.h"
 #include "softpipe/sp_winsys.h"
@@ -57,21 +56,19 @@ static boolean radeon_is_format_supported(struct softpipe_winsys *sws, uint form
     return FALSE;
 }
 
-struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context)
+struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys)
 {
     struct radeon_softpipe_winsys *radeon_sp_ws;
     struct pipe_screen *pipe_screen;
 
-    pipe_screen = softpipe_create_screen(radeon_context->pipe_winsys);
+    pipe_screen = softpipe_create_screen(winsys);
 
     radeon_sp_ws = CALLOC_STRUCT(radeon_softpipe_winsys);
     if (radeon_sp_ws == NULL) {
         return NULL;
     }
-    radeon_context->pipe_screen = pipe_screen;
-    radeon_sp_ws->radeon_context = radeon_context;
     radeon_sp_ws->sp_winsys.is_format_supported = radeon_is_format_supported;
     return softpipe_create(pipe_screen,
-                           radeon_context->pipe_winsys,
+                           winsys,
                            &radeon_sp_ws->sp_winsys);
 }
index 519eab769c80e6e11872afe7bb9edd7d9f85022e..093693eddfa8e9c6dcbc6d33d4d7d9fd9809f0e6 100644 (file)
@@ -32,6 +32,6 @@
 
 #include "radeon_context.h"
 
-struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context);
+struct pipe_context *radeon_create_softpipe(struct pipe_winsys* winsys);
 
 #endif