Merge branch 'gallium-drm-driver-drescriptor'
authorJakob Bornecrantz <jakob@vmware.com>
Mon, 28 Jun 2010 18:59:09 +0000 (20:59 +0200)
committerJakob Bornecrantz <jakob@vmware.com>
Mon, 28 Jun 2010 19:14:45 +0000 (21:14 +0200)
Conflicts:
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_x11.c
src/gallium/state_trackers/egl/x11/native_x11.h
src/gallium/state_trackers/xorg/xorg_driver.c
src/gallium/winsys/radeon/drm/radeon_drm.c

18 files changed:
1  2 
configure.ac
src/gallium/drivers/galahad/Makefile
src/gallium/drivers/galahad/SConscript
src/gallium/drivers/i915/i915_screen.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_winsys.h
src/gallium/state_trackers/egl/kms/native_kms.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_x11.c
src/gallium/state_trackers/egl/x11/native_x11.h
src/gallium/state_trackers/xorg/xorg_driver.c
src/gallium/state_trackers/xorg/xorg_tracker.h
src/gallium/targets/dri-radeong/Makefile
src/gallium/targets/egl-radeon/Makefile
src/gallium/targets/xorg-radeon/Makefile
src/gallium/winsys/r600/drm/r600_drm.c
src/gallium/winsys/radeon/drm/radeon_r300.c

diff --combined configure.ac
index 5cfdd45eca052859de87bce43d3e6c2f864d4f69,4a676d4abdb0d9b2bb0d0072536f1380b83e99b0..09921176625c0678ce341592d8f9d2d08ec82341
@@@ -469,12 -469,12 +469,12 @@@ dn
  dnl this variable will be prepended to SRC_DIRS and is not exported
  CORE_DIRS="mapi/glapi glsl mesa"
  
 -SRC_DIRS="glew"
 +SRC_DIRS=""
  GLU_DIRS="sgi"
  GALLIUM_DIRS="auxiliary drivers state_trackers"
  GALLIUM_TARGET_DIRS=""
  GALLIUM_WINSYS_DIRS="sw"
 -GALLIUM_DRIVERS_DIRS="softpipe failover trace rbug identity"
 +GALLIUM_DRIVERS_DIRS="softpipe failover galahad trace rbug identity"
  GALLIUM_STATE_TRACKERS_DIRS=""
  
  case "$mesa_driver" in
@@@ -486,7 -486,7 +486,7 @@@ xlib
  dri)
      SRC_DIRS="$SRC_DIRS glx"
      DRIVER_DIRS="dri"
-     GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri sw/drm"
+     GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/dri"
      ;;
  osmesa)
      DRIVER_DIRS="osmesa"
@@@ -860,7 -860,7 +860,7 @@@ AC_SUBST([DRI_LIB_DEPS]
  
  case $DRI_DIRS in
  *i915*|*i965*)
 -    PKG_CHECK_MODULES([INTEL], [libdrm_intel >= 2.4.19])
 +    PKG_CHECK_MODULES([INTEL], [libdrm_intel >= 2.4.21])
      ;;
  esac
  
@@@ -891,7 -891,7 +891,7 @@@ els
  fi
  AC_ARG_ENABLE([gl-osmesa],
      [AS_HELP_STRING([--enable-gl-osmesa],
 -        [enable OSMesa on libGL @<:@default=enabled for xlib driver@:>@])],
 +        [enable OSMesa with libGL @<:@default=enabled for xlib driver@:>@])],
      [gl_osmesa="$enableval"],
      [gl_osmesa="$default_gl_osmesa"])
  if test "x$gl_osmesa" = xyes; then
@@@ -926,8 -926,8 +926,8 @@@ x16|x32
  esac
  AC_SUBST([OSMESA_LIB])
  
 -case "$mesa_driver" in
 -osmesa)
 +case "$DRIVER_DIRS" in
 +*osmesa*)
      # only link libraries with osmesa if shared
      if test "$enable_static" = no; then
          OSMESA_LIB_DEPS="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
      OSMESA_MESA_DEPS=""
      OSMESA_PC_LIB_PRIV="-lm -lpthread $SELINUX_LIBS $DLOPEN_LIBS"
      ;;
 -*)
 -    # Link OSMesa to libGL otherwise
 -    OSMESA_LIB_DEPS=""
 -    # only link libraries with osmesa if shared
 -    if test "$enable_static" = no; then
 -        OSMESA_MESA_DEPS='-l$(GL_LIB)'
 -    else
 -        OSMESA_MESA_DEPS=""
 -    fi
 -    OSMESA_PC_REQ="gl"
 -    ;;
  esac
 -OSMESA_PC_LIB_PRIV="$OSMESA_PC_LIB_PRIV"
  AC_SUBST([OSMESA_LIB_DEPS])
  AC_SUBST([OSMESA_MESA_DEPS])
  AC_SUBST([OSMESA_PC_REQ])
@@@ -1301,22 -1313,18 +1301,22 @@@ if test "x$HAVE_ST_XORG" = xyes; the
          HAVE_XEXTPROTO_71="no")
  fi
  
 +AC_ARG_WITH([egl-platforms],
 +    [AS_HELP_STRING([--with-egl-platforms@<:@=DIRS...@:>@],
 +        [comma delimited native platforms libEGL supports, e.g.
 +        "x11,kms" @<:@default=auto@:>@])],
 +    [with_egl_platforms="$withval"],
 +    [with_egl_platforms=yes])
  AC_ARG_WITH([egl-displays],
      [AS_HELP_STRING([--with-egl-displays@<:@=DIRS...@:>@],
 -        [comma delimited native displays libEGL supports, e.g.
 -        "x11,kms" @<:@default=auto@:>@])],
 -    [with_egl_displays="$withval"],
 -    [with_egl_displays=yes])
 +        [DEPRECATED.  Use --with-egl-platforms instead])],
 +    [with_egl_platforms="$withval"])
  
 -EGL_DISPLAYS=""
 -case "$with_egl_displays" in
 +EGL_PLATFORMS=""
 +case "$with_egl_platforms" in
  yes)
      if test "x$enable_egl" = xyes && test "x$mesa_driver" != xosmesa; then
 -        EGL_DISPLAYS="x11"
 +        EGL_PLATFORMS="x11"
      fi
      ;;
  *)
          AC_MSG_ERROR([cannot build egl state tracker without EGL library])
      fi
      # verify the requested driver directories exist
 -    egl_displays=`IFS=', '; echo $with_egl_displays`
 -    for dpy in $egl_displays; do
 -        test -d "$srcdir/src/gallium/state_trackers/egl/$dpy" || \
 -            AC_MSG_ERROR([EGL display '$dpy' does't exist])
 +    egl_platforms=`IFS=', '; echo $with_egl_platforms`
 +    for plat in $egl_platforms; do
 +        test -d "$srcdir/src/gallium/state_trackers/egl/$plat" || \
 +            AC_MSG_ERROR([EGL platform '$plat' does't exist])
 +        if test "$plat" = "fbdev"; then
 +                GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/fbdev"
 +        fi
      done
 -    EGL_DISPLAYS="$egl_displays"
 +    EGL_PLATFORMS="$egl_platforms"
      ;;
  esac
 -AC_SUBST([EGL_DISPLAYS])
 +AC_SUBST([EGL_PLATFORMS])
  
  AC_ARG_WITH([egl-driver-dir],
      [AS_HELP_STRING([--with-egl-driver-dir=DIR],
@@@ -1430,35 -1435,20 +1430,35 @@@ elif test "x$enable_gallium_svga" = xau
  fi
  
  dnl
 -dnl Gallium Intel configuration
 +dnl Gallium i915 configuration
  dnl
 -AC_ARG_ENABLE([gallium-intel],
 -    [AS_HELP_STRING([--enable-gallium-intel],
 -        [build gallium intel @<:@default=disabled@:>@])],
 -    [enable_gallium_intel="$enableval"],
 -    [enable_gallium_intel=auto])
 -if test "x$enable_gallium_intel" = xyes; then
 +AC_ARG_ENABLE([gallium-i915],
 +    [AS_HELP_STRING([--enable-gallium-i915],
 +        [build gallium i915 @<:@default=disabled@:>@])],
 +    [enable_gallium_i915="$enableval"],
 +    [enable_gallium_i915=auto])
 +if test "x$enable_gallium_i915" = xyes; then
      GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
 -    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
 -    gallium_check_st "i915/drm i965/drm" "dri-i915 dri-i965" "egl-i915 egl-i965" "xorg-i915 xorg-i965"
 -elif test "x$enable_gallium_intel" = xauto; then
 +    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915"
 +    gallium_check_st "i915/drm" "dri-i915" "egl-i915" "xorg-i915"
 +elif test "x$enable_gallium_i915" = xauto; then
      GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/sw"
 -    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965"
 +    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915"
 +fi
 +
 +dnl
 +dnl Gallium i965 configuration
 +dnl
 +AC_ARG_ENABLE([gallium-i965],
 +    [AS_HELP_STRING([--enable-gallium-i965],
 +        [build gallium i965 @<:@default=disabled@:>@])],
 +    [enable_gallium_i965="$enableval"],
 +    [enable_gallium_i965=auto])
 +if test "x$enable_gallium_i965" = xyes; then
 +    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965"
 +    gallium_check_st "i965/drm" "dri-i965" "egl-i965" "xorg-i965"
 +elif test "x$enable_gallium_i965" = xauto; then
 +    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i965"
  fi
  
  dnl
@@@ -1598,7 -1588,7 +1598,7 @@@ echo "        Shared libs:     $enable_
  echo "        Static libs:     $enable_static"
  if test "$enable_egl" = yes; then
      echo "        EGL:             $EGL_DRIVERS_DIRS"
 -    echo "        EGL displays:    $EGL_DISPLAYS"
 +    echo "        EGL platforms:   $EGL_PLATFORMS"
  else
      echo "        EGL:             no"
  fi
index 67d087456626256e8f9af911225e02ecf9c23173,0000000000000000000000000000000000000000..e9c4f7e28c81167896980503b66ab0fb8e7d4390
mode 100644,000000..100644
--- /dev/null
@@@ -1,12 -1,0 +1,11 @@@
-       glhd_screen.c \
-       glhd_drm.c
 +TOP = ../../../..
 +include $(TOP)/configs/current
 +
 +LIBNAME = galahad
 +
 +C_SOURCES = \
 +      glhd_objects.c \
 +      glhd_context.c \
++      glhd_screen.c
 +
 +include ../../Makefile.template
index fc668facaf563d7fe01cfbd1832ca95598b24181,0000000000000000000000000000000000000000..ca6213cfff14af209f802f8759b65dac4430284f
mode 100644,000000..100644
--- /dev/null
@@@ -1,14 -1,0 +1,13 @@@
-               'glhd_drm.c',
 +Import('*')
 +
 +env = env.Clone()
 +
 +identity = env.ConvenienceLibrary(
 +      target = 'identity',
 +      source = [
 +              'glhd_context.c',
 +              'glhd_objects.c',
 +              'glhd_screen.c',
 +      ])
 +
 +Export('identity')
index 255538ebaa4a7936f646fca616f62b070e363e73,bb0b85d74c719bdaacc1cc0711866f4d8f18e17e..77345d5f7117fe3d369984245188bdd71aab3767
  #include "util/u_string.h"
  
  #include "i915_reg.h"
 +#include "i915_debug.h"
  #include "i915_context.h"
  #include "i915_screen.h"
  #include "i915_surface.h"
  #include "i915_resource.h"
  #include "i915_winsys.h"
+ #include "i915_public.h"
  
  
  /*
@@@ -331,7 -331,5 +332,7 @@@ i915_screen_create(struct i915_winsys *
     i915_init_screen_resource_functions(is);
     i915_init_screen_surface_functions(is);
  
 +   i915_debug_init(is);
 +
     return &is->base;
  }
index d3d36a782c5652aabec3c1228bcc47c22693e4fe,fd522b84e1a2017c985c2632586f6b472a348cab..5bba55906c3a7df9f0396f7d0c9d21d8b2258906
@@@ -30,6 -30,7 +30,7 @@@
  #include "r300_screen_buffer.h"
  #include "r300_state_inlines.h"
  #include "r300_winsys.h"
+ #include "r300_public.h"
  
  /* Return the identifier behind whom the brave coders responsible for this
   * amalgamation of code, sweat, and duct tape, routinely obscure their names.
@@@ -269,24 -270,15 +270,24 @@@ static boolean r300_is_format_supported
                              format == PIPE_FORMAT_R16G16B16_FLOAT ||
                              format == PIPE_FORMAT_R16G16B16A16_FLOAT;
  
 -    if (target >= PIPE_MAX_TEXTURE_TYPES) {
 -        fprintf(stderr, "r300: Implementation error: Received bogus texture "
 -            "target %d in %s\n", target, __FUNCTION__);
 -        return FALSE;
 +    switch (sample_count) {
 +        case 0:
 +        case 1:
 +            break;
 +        case 2:
 +        case 3:
 +        case 4:
 +        case 6:
 +            if (usage != PIPE_BIND_RENDER_TARGET ||
 +                !util_format_is_rgba8_variant(
 +                    util_format_description(format))) {
 +                return FALSE;
 +            }
 +            break;
 +        default:
 +            return FALSE;
      }
  
 -   if (sample_count > 1)
 -      return FALSE;
 -
      /* Check sampler format support. */
      if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
          /* Z24 cannot be sampled from on non-r5xx. */
          retval |= PIPE_BIND_VERTEX_BUFFER;
      }
  
 +    /* Transfers are always supported. */
 +    if (usage & PIPE_BIND_TRANSFER_READ)
 +        retval |= PIPE_BIND_TRANSFER_READ;
 +    if (usage & PIPE_BIND_TRANSFER_WRITE)
 +        retval |= PIPE_BIND_TRANSFER_WRITE;
 +
      return retval == usage;
  }
  
@@@ -381,7 -367,7 +382,7 @@@ static int r300_fence_finish(struct pip
      return 0; /* 0 == success */
  }
  
- struct pipe_screen* r300_create_screen(struct r300_winsys_screen *rws)
+ struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws)
  {
      struct r300_screen *r300screen = CALLOC_STRUCT(r300_screen);
  
index ddb66000561314e4f65e7c03fcdfcffeb021fd52,5a013e2a25a28a1ce79ce6c9d0895a495071d425..6206570fca473ecf417a28b1c2374ddb52040f49
   * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
   * USE OR OTHER DEALINGS IN THE SOFTWARE. */
  
 -#include "pipe/p_screen.h"
 -
 -#include "util/u_format.h"
 -#include "util/u_format_s3tc.h"
 -#include "util/u_math.h"
 -#include "util/u_memory.h"
 +/* Always include headers in the reverse order!! ~ M. */
 +#include "r300_texture.h"
  
  #include "r300_context.h"
  #include "r300_reg.h"
 -#include "r300_texture.h"
  #include "r300_transfer.h"
  #include "r300_screen.h"
  #include "r300_winsys.h"
  
 -#define TILE_WIDTH 0
 -#define TILE_HEIGHT 1
 +#include "util/u_format.h"
 +#include "util/u_format_s3tc.h"
 +#include "util/u_math.h"
 +#include "util/u_memory.h"
 +
 +#include "pipe/p_screen.h"
- #include "state_tracker/drm_api.h"
 -static const unsigned microblock_table[5][3][2] = {
 -    /*linear  tiled   square-tiled */
 -    {{32, 1}, {8, 4}, {0, 0}}, /*   8 bits per pixel */
 -    {{16, 1}, {8, 2}, {4, 4}}, /*  16 bits per pixel */
 -    {{ 8, 1}, {4, 2}, {0, 0}}, /*  32 bits per pixel */
 -    {{ 4, 1}, {0, 0}, {2, 2}}, /*  64 bits per pixel */
 -    {{ 2, 1}, {0, 0}, {0, 0}}  /* 128 bits per pixel */
++/* XXX NO! just no! */
++#include "state_tracker/drm_driver.h"
 +
 +enum r300_dim {
 +    DIM_WIDTH  = 0,
 +    DIM_HEIGHT = 1
  };
  
  unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format,
@@@ -592,21 -596,21 +594,21 @@@ static void r300_texture_setup_fb_state
      /* Set framebuffer state. */
      if (util_format_is_depth_or_stencil(tex->b.b.format)) {
          for (i = 0; i <= tex->b.b.last_level; i++) {
 -            tex->fb_state.depthpitch[i] =
 +            tex->fb_state.pitch[i] =
                  tex->hwpitch[i] |
                  R300_DEPTHMACROTILE(tex->mip_macrotile[i]) |
                  R300_DEPTHMICROTILE(tex->microtile);
          }
 -        tex->fb_state.zb_format = r300_translate_zsformat(tex->b.b.format);
 +        tex->fb_state.format = r300_translate_zsformat(tex->b.b.format);
      } else {
          for (i = 0; i <= tex->b.b.last_level; i++) {
 -            tex->fb_state.colorpitch[i] =
 +            tex->fb_state.pitch[i] =
                  tex->hwpitch[i] |
                  r300_translate_colorformat(tex->b.b.format) |
                  R300_COLOR_TILE(tex->mip_macrotile[i]) |
                  R300_COLOR_MICROTILE(tex->microtile);
          }
 -        tex->fb_state.us_out_fmt = r300_translate_out_fmt(tex->b.b.format);
 +        tex->fb_state.format = r300_translate_out_fmt(tex->b.b.format);
      }
  }
  
@@@ -616,10 -620,8 +618,10 @@@ void r300_texture_reinterpret_format(st
  {
      struct r300_screen *r300screen = r300_screen(screen);
  
 -    SCREEN_DBG(r300screen, DBG_TEX, "r300: texture_reinterpret_format: %s -> %s\n",
 -               util_format_short_name(tex->format), util_format_short_name(new_format));
 +    SCREEN_DBG(r300screen, DBG_TEX,
 +        "r300: texture_reinterpret_format: %s -> %s\n",
 +        util_format_short_name(tex->format),
 +        util_format_short_name(new_format));
  
      tex->format = new_format;
  
@@@ -646,65 -648,36 +648,65 @@@ unsigned r300_texture_get_offset(struc
      }
  }
  
 -/**
 - * Return the width (dim==TILE_WIDTH) or height (dim==TILE_HEIGHT) of one tile
 - * of the given texture.
 - */
 -static unsigned r300_texture_get_tile_size(struct r300_texture* tex,
 -                                           int dim, boolean macrotile)
 +/* Returns the number of pixels that the texture should be aligned to
 + * in the given dimension. */
 +static unsigned r300_get_pixel_alignment(struct r300_texture *tex,
 +                                         enum r300_buffer_tiling macrotile,
 +                                         enum r300_dim dim)
  {
 -    unsigned pixsize, tile_size;
 -
 -    pixsize = util_format_get_blocksize(tex->b.b.format);
 -    tile_size = microblock_table[util_logbase2(pixsize)][tex->microtile][dim];
 -
 -    if (macrotile) {
 -        tile_size *= 8;
 +    static const unsigned table[2][5][3][2] =
 +    {
 +        {
 +    /* Macro: linear    linear    linear
 +       Micro: linear    tiled  square-tiled */
 +            {{ 32, 1}, { 8,  4}, { 0,  0}}, /*   8 bits per pixel */
 +            {{ 16, 1}, { 8,  2}, { 4,  4}}, /*  16 bits per pixel */
 +            {{  8, 1}, { 4,  2}, { 0,  0}}, /*  32 bits per pixel */
 +            {{  4, 1}, { 0,  0}, { 2,  2}}, /*  64 bits per pixel */
 +            {{  2, 1}, { 0,  0}, { 0,  0}}  /* 128 bits per pixel */
 +        },
 +        {
 +    /* Macro: tiled     tiled     tiled
 +       Micro: linear    tiled  square-tiled */
 +            {{256, 8}, {64, 32}, { 0,  0}}, /*   8 bits per pixel */
 +            {{128, 8}, {64, 16}, {32, 32}}, /*  16 bits per pixel */
 +            {{ 64, 8}, {32, 16}, { 0,  0}}, /*  32 bits per pixel */
 +            {{ 32, 8}, { 0,  0}, {16, 16}}, /*  64 bits per pixel */
 +            {{ 16, 8}, { 0,  0}, { 0,  0}}  /* 128 bits per pixel */
 +        }
 +    };
 +    static const unsigned aa_block[2] = {4, 8};
 +    unsigned res = 0;
 +    unsigned pixsize = util_format_get_blocksize(tex->b.b.format);
 +
 +    assert(macrotile <= R300_BUFFER_TILED);
 +    assert(tex->microtile <= R300_BUFFER_SQUARETILED);
 +    assert(pixsize <= 16);
 +    assert(dim <= DIM_HEIGHT);
 +
 +    if (tex->b.b.nr_samples > 1) {
 +        /* Multisampled textures have their own alignment scheme. */
 +        if (pixsize == 4)
 +            res = aa_block[dim];
 +    } else {
 +        /* Standard alignment. */
 +        res = table[macrotile][util_logbase2(pixsize)][tex->microtile][dim];
      }
  
 -    assert(tile_size);
 -    return tile_size;
 +    assert(res);
 +    return res;
  }
  
  /* Return true if macrotiling should be enabled on the miplevel. */
  static boolean r300_texture_macro_switch(struct r300_texture *tex,
                                           unsigned level,
                                           boolean rv350_mode,
 -                                         int dim)
 +                                         enum r300_dim dim)
  {
      unsigned tile, texdim;
  
 -    tile = r300_texture_get_tile_size(tex, dim, TRUE);
 -    if (dim == TILE_WIDTH) {
 +    tile = r300_get_pixel_alignment(tex, R300_BUFFER_TILED, dim);
 +    if (dim == DIM_WIDTH) {
          texdim = u_minify(tex->b.b.width0, level);
      } else {
          texdim = u_minify(tex->b.b.height0, level);
@@@ -740,8 -713,8 +742,8 @@@ unsigned r300_texture_get_stride(struc
      width = u_minify(tex->b.b.width0, level);
  
      if (util_format_is_plain(tex->b.b.format)) {
 -        tile_width = r300_texture_get_tile_size(tex, TILE_WIDTH,
 -                                                tex->mip_macrotile[level]);
 +        tile_width = r300_get_pixel_alignment(tex, tex->mip_macrotile[level],
 +                                              DIM_WIDTH);
          width = align(width, tile_width);
  
          stride = util_format_get_stride(tex->b.b.format, width);
@@@ -770,8 -743,8 +772,8 @@@ static unsigned r300_texture_get_nblock
      height = u_minify(tex->b.b.height0, level);
  
      if (util_format_is_plain(tex->b.b.format)) {
 -        tile_height = r300_texture_get_tile_size(tex, TILE_HEIGHT,
 -                                                 tex->mip_macrotile[level]);
 +        tile_height = r300_get_pixel_alignment(tex, tex->mip_macrotile[level],
 +                                               DIM_HEIGHT);
          height = align(height, tile_height);
  
          /* This is needed for the kernel checker, unfortunately. */
@@@ -811,26 -784,21 +813,26 @@@ static void r300_setup_miptree(struct r
      unsigned stride, size, layer_size, nblocksy, i;
      boolean rv350_mode = screen->caps.is_rv350;
  
 -    SCREEN_DBG(screen, DBG_TEXALLOC, "r300: Making miptree for texture, format %s\n",
 -               util_format_short_name(base->format));
 +    SCREEN_DBG(screen, DBG_TEXALLOC,
 +        "r300: Making miptree for texture, format %s\n",
 +        util_format_short_name(base->format));
  
      for (i = 0; i <= base->last_level; i++) {
          /* Let's see if this miplevel can be macrotiled. */
          tex->mip_macrotile[i] =
              (tex->macrotile == R300_BUFFER_TILED &&
 -             r300_texture_macro_switch(tex, i, rv350_mode, TILE_WIDTH) &&
 -             r300_texture_macro_switch(tex, i, rv350_mode, TILE_HEIGHT)) ?
 +             r300_texture_macro_switch(tex, i, rv350_mode, DIM_WIDTH) &&
 +             r300_texture_macro_switch(tex, i, rv350_mode, DIM_HEIGHT)) ?
               R300_BUFFER_TILED : R300_BUFFER_LINEAR;
  
          stride = r300_texture_get_stride(screen, tex, i);
          nblocksy = r300_texture_get_nblocksy(tex, i);
          layer_size = stride * nblocksy;
  
 +        if (base->nr_samples) {
 +            layer_size *= base->nr_samples;
 +        }
 +
          if (base->target == PIPE_TEXTURE_CUBE)
              size = layer_size * 6;
          else
@@@ -896,8 -864,8 +898,8 @@@ static void r300_setup_tiling(struct pi
      }
  
      /* Set macrotiling. */
 -    if (r300_texture_macro_switch(tex, 0, rv350_mode, TILE_WIDTH) &&
 -        r300_texture_macro_switch(tex, 0, rv350_mode, TILE_HEIGHT)) {
 +    if (r300_texture_macro_switch(tex, 0, rv350_mode, DIM_WIDTH) &&
 +        r300_texture_macro_switch(tex, 0, rv350_mode, DIM_HEIGHT)) {
          tex->macrotile = R300_BUFFER_TILED;
      }
  }
@@@ -931,14 -899,17 +933,14 @@@ static boolean r300_texture_get_handle(
  {
      struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys;
      struct r300_texture* tex = (struct r300_texture*)texture;
 -    unsigned stride;
  
      if (!tex) {
          return FALSE;
      }
  
 -    stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
 -
 -    rws->buffer_get_handle(rws, tex->buffer, stride, whandle);
 +    whandle->stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
  
 -    return TRUE;
 +    return rws->buffer_get_handle(rws, tex->buffer, whandle);
  }
  
  struct u_resource_vtbl r300_texture_vtbl = 
@@@ -995,12 -966,11 +997,12 @@@ struct pipe_resource* r300_texture_crea
  
      SCREEN_DBG(rscreen, DBG_TEX,
                 "r300: texture_create: Macro: %s, Micro: %s, Pitch: %i, "
 -               "Dim: %ix%ix%i, LastLevel: %i, Format: %s\n",
 +               "Dim: %ix%ix%i, LastLevel: %i, Size: %i, Format: %s\n",
                 tex->macrotile ? "YES" : " NO",
                 tex->microtile ? "YES" : " NO",
                 tex->hwpitch[0],
                 base->width0, base->height0, base->depth0, base->last_level,
 +               tex->size,
                 util_format_short_name(base->format));
  
      tex->domain = base->flags & R300_RESOURCE_FLAG_TRANSFER ? R300_DOMAIN_GTT :
      tex->buffer = rws->buffer_create(rws, 2048, base->bind, tex->domain,
                                       tex->size);
  
 +    if (!tex->buffer) {
 +      FREE(tex);
 +      return NULL;
 +    }
 +
      rws->buffer_set_tiling(rws, tex->buffer,
              tex->pitch[0] * util_format_get_blocksize(tex->b.b.format),
              tex->microtile,
              tex->macrotile);
  
 -    if (!tex->buffer) {
 -        FREE(tex);
 -        return NULL;
 -    }
 -
      return (struct pipe_resource*)tex;
  }
  
@@@ -1032,27 -1002,26 +1034,27 @@@ struct pipe_surface* r300_get_tex_surfa
                                          unsigned flags)
  {
      struct r300_texture* tex = r300_texture(texture);
 -    struct pipe_surface* surface = CALLOC_STRUCT(pipe_surface);
 -    unsigned offset;
 -
 -    offset = r300_texture_get_offset(tex, level, zslice, face);
 +    struct r300_surface* surface = CALLOC_STRUCT(r300_surface);
  
      if (surface) {
 -        pipe_reference_init(&surface->reference, 1);
 -        pipe_resource_reference(&surface->texture, texture);
 -        surface->format = texture->format;
 -        surface->width = u_minify(texture->width0, level);
 -        surface->height = u_minify(texture->height0, level);
 -        surface->offset = offset;
 -        surface->usage = flags;
 -        surface->zslice = zslice;
 -        surface->texture = texture;
 -        surface->face = face;
 -        surface->level = level;
 +        pipe_reference_init(&surface->base.reference, 1);
 +        pipe_resource_reference(&surface->base.texture, texture);
 +        surface->base.format = texture->format;
 +        surface->base.width = u_minify(texture->width0, level);
 +        surface->base.height = u_minify(texture->height0, level);
 +        surface->base.usage = flags;
 +        surface->base.zslice = zslice;
 +        surface->base.face = face;
 +        surface->base.level = level;
 +
 +        surface->buffer = tex->buffer;
 +        surface->domain = tex->domain;
 +        surface->offset = r300_texture_get_offset(tex, level, zslice, face);
 +        surface->pitch = tex->fb_state.pitch[level];
 +        surface->format = tex->fb_state.format;
      }
  
 -    return surface;
 +    return &surface->base;
  }
  
  /* Not required to implement u_resource_vtbl, consider moving to another file:
@@@ -1072,6 -1041,7 +1074,6 @@@ r300_texture_from_handle(struct pipe_sc
      struct r300_screen* rscreen = r300_screen(screen);
      struct r300_winsys_buffer *buffer;
      struct r300_texture* tex;
 -    unsigned stride;
      boolean override_zb_flags;
  
      /* Support only 2D textures without mipmaps */
          return NULL;
      }
  
 -    buffer = rws->buffer_from_handle(rws, screen, whandle, &stride);
++    /* XXX make the winsys return the stride_override, see i915_resource_texture.c:830 */
 +    buffer = rws->buffer_from_handle(rws, whandle->handle);
      if (!buffer) {
          return NULL;
      }
      tex->b.b.screen = screen;
      tex->domain = R300_DOMAIN_VRAM;
  
 -    tex->stride_override = stride;
 +    tex->stride_override = whandle->stride;
  
      /* one ref already taken */
      tex->buffer = buffer;
                 "Pitch: % 4i, Dim: %ix%i, Format: %s\n",
                 tex->macrotile ? "YES" : " NO",
                 tex->microtile ? "YES" : " NO",
 -               stride / util_format_get_blocksize(base->format),
 +               whandle->stride / util_format_get_blocksize(base->format),
                 base->width0, base->height0,
                 util_format_short_name(base->format));
  
index 77c1c13ef9ae55419828033e2e60e2c492c53763,8a8888d48133658539c66d5e20a27249b82f172c..3b5e9eec602033c9c26ec8cdcb4ca18faf37c1f9
@@@ -47,6 -47,13 +47,6 @@@ enum r300_reference_domain { /* bitfiel
      R300_REF_HW = 2
  };
  
 -struct r300_cs_info {
 -    /* In DWORDs. */
 -    unsigned used;
 -    unsigned free;
 -    unsigned capacity;
 -};
 -
  struct r300_winsys_screen {
      void (*destroy)(struct r300_winsys_screen *ws);
      
       * Returns TRUE if a flush is required. */
      boolean (*validate)(struct r300_winsys_screen* winsys);
  
 -    /* Return current CS info. */
 -    void (*get_cs_info)(struct r300_winsys_screen *winsys,
 -                        struct r300_cs_info *info);
 +    /* Return the number of free dwords in CS. */
 +    unsigned (*get_cs_free_dwords)(struct r300_winsys_screen *winsys);
  
 -    /* Start a command emit. */
 -    void (*begin_cs)(struct r300_winsys_screen* winsys,
 -                     int size,
 -                     const char* file,
 -                     const char* function,
 -                     int line);
 +    /* Return the pointer to the first free dword in CS and assume a pipe
 +     * driver wants to fill "count" dwords. */
 +    uint32_t *(*get_cs_pointer)(struct r300_winsys_screen *winsys,
 +                                unsigned count);
  
      /* Write a dword to the command buffer. */
      void (*write_cs_dword)(struct r300_winsys_screen* winsys, uint32_t dword);
                             enum r300_buffer_domain wd,
                             uint32_t flags);
  
 -    /* Finish a command emit. */
 -    void (*end_cs)(struct r300_winsys_screen* winsys,
 -                   const char* file,
 -                   const char* function,
 -                   int line);
 -
      /* Flush the CS. */
      void (*flush_cs)(struct r300_winsys_screen* winsys);
  
                          enum r300_value_id vid);
  
      struct r300_winsys_buffer *(*buffer_from_handle)(struct r300_winsys_screen *winsys,
 -                                                   struct pipe_screen *screen,
 -                                                   struct winsys_handle *whandle,
 -                                                   unsigned *stride);
 +                                                     unsigned handle);
 +
      boolean (*buffer_get_handle)(struct r300_winsys_screen *winsys,
                                 struct r300_winsys_buffer *buffer,
 -                               unsigned stride,
                                 struct winsys_handle *whandle);
  
      boolean (*is_buffer_referenced)(struct r300_winsys_screen *winsys,
  struct r300_winsys_screen *
  r300_winsys_screen(struct pipe_screen *screen);
  
- /* Creates a new r300 screen. */
- struct pipe_screen* r300_create_screen(struct r300_winsys_screen *rws);
  #endif /* R300_WINSYS_H */
index f90b8714c99a48744e723802945a7a0a34d3052f,8f667f1ec139e9471dd7e177e8c9a130827f8b74..09a08f32b3cd89fe3c990623b0f0e70e54e0dc41
@@@ -33,6 -33,7 +33,7 @@@
  #include "egllog.h"
  
  #include "native_kms.h"
+ #include "state_tracker/drm_driver.h"
  
  static boolean
  kms_surface_validate(struct native_surface *nsurf, uint attachment_mask,
@@@ -657,8 -658,6 +658,6 @@@ kms_display_destroy(struct native_displ
     if (kdpy->fd >= 0)
        drmClose(kdpy->fd);
  
-    if (kdpy->api && kdpy->api->destroy)
-       kdpy->api->destroy(kdpy->api);
     FREE(kdpy);
  }
  
@@@ -674,7 -673,7 +673,7 @@@ kms_display_init_screen(struct native_d
     fd = kdpy->fd;
     if (fd >= 0) {
        drmVersionPtr version = drmGetVersion(fd);
-       if (!version || strcmp(version->name, kdpy->api->driver_name)) {
+       if (!version || strcmp(version->name, driver_descriptor.driver_name)) {
           if (version) {
              _eglLog(_EGL_WARNING, "unknown driver name %s", version->name);
              drmFreeVersion(version);
        drmFreeVersion(version);
     }
     else {
-       fd = drmOpen(kdpy->api->driver_name, NULL);
+       fd = drmOpen(driver_descriptor.driver_name, NULL);
     }
  
     if (fd < 0) {
     }
  #endif
  
-    kdpy->base.screen = kdpy->api->create_screen(kdpy->api, fd);
+    kdpy->base.screen = driver_descriptor.create_screen(fd);
     if (!kdpy->base.screen) {
        _eglLog(_EGL_WARNING, "failed to create DRM screen");
        drmClose(fd);
@@@ -724,8 -723,7 +723,7 @@@ static struct native_display_modeset km
  };
  
  static struct native_display *
- kms_create_display(int fd, struct native_event_handler *event_handler,
-                    struct drm_api *api)
+ kms_create_display(int fd, struct native_event_handler *event_handler)
  {
     struct kms_display *kdpy;
  
        return NULL;
  
     kdpy->event_handler = event_handler;
-    kdpy->api = api;
-    if (!kdpy->api) {
-       _eglLog(_EGL_WARNING, "failed to create DRM API");
-       FREE(kdpy);
-       return NULL;
-    }
     kdpy->fd = fd;
     if (!kms_display_init_screen(&kdpy->base)) {
        kms_display_destroy(&kdpy->base);
  }
  
  struct native_probe *
 -native_create_probe(EGLNativeDisplayType dpy)
 +native_create_probe(void *dpy)
  {
     return NULL;
  }
@@@ -790,40 -780,26 +780,25 @@@ native_get_probe_result(struct native_p
     return NATIVE_PROBE_UNKNOWN;
  }
  
- /* the api is destroyed with the native display */
- static struct drm_api *drm_api;
  const char *
  native_get_name(void)
  {
     static char kms_name[32];
  
-    if (!drm_api)
-       drm_api = drm_api_create();
  
-    if (drm_api)
-       util_snprintf(kms_name, sizeof(kms_name), "KMS/%s", drm_api->name);
-    else
-       util_snprintf(kms_name, sizeof(kms_name), "KMS");
+    util_snprintf(kms_name, sizeof(kms_name), "KMS/%s", driver_descriptor.name);
  
     return kms_name;
  }
  
  struct native_display *
 -native_create_display(EGLNativeDisplayType dpy,
 -                      struct native_event_handler *event_handler)
 +native_create_display(void *dpy, struct native_event_handler *event_handler)
  {
     struct native_display *ndpy = NULL;
     int fd;
  
-    if (!drm_api)
-       drm_api = drm_api_create();
-    if (drm_api) {
-       /* well, this makes fd 0 being ignored */
-       fd = (dpy != EGL_DEFAULT_DISPLAY) ?
-          (int) pointer_to_intptr((void *) dpy) : -1;
-       ndpy = kms_create_display(fd, event_handler, drm_api);
-    }
+    fd = (dpy != EGL_DEFAULT_DISPLAY) ? (int) pointer_to_intptr((void *) dpy) : -1;
+    ndpy = kms_create_display(fd, event_handler);
  
     return ndpy;
  }
index e90c33b824d383a7fb848de4c529afa127219897,0ce7c0be64b358661a652572c18b44104076b941..7464354fe6151410460d8934e15d2325bce0c5ae
@@@ -32,7 -32,7 +32,7 @@@
  #include "pipe/p_screen.h"
  #include "pipe/p_context.h"
  #include "pipe/p_state.h"
- #include "state_tracker/drm_api.h"
+ #include "state_tracker/drm_driver.h"
  #include "egllog.h"
  
  #include "native_x11.h"
@@@ -50,7 -50,6 +50,6 @@@ struct dri2_display 
  
     struct native_event_handler *event_handler;
  
-    struct drm_api *api;
     struct x11_screen *xscr;
     int xscr_number;
     const char *dri_driver;
@@@ -662,8 -661,6 +661,6 @@@ dri2_display_destroy(struct native_disp
        x11_screen_destroy(dri2dpy->xscr);
     if (dri2dpy->own_dpy)
        XCloseDisplay(dri2dpy->dpy);
-    if (dri2dpy->api && dri2dpy->api->destroy)
-       dri2dpy->api->destroy(dri2dpy->api);
     FREE(dri2dpy);
  }
  
@@@ -695,7 -692,7 +692,7 @@@ static boolea
  dri2_display_init_screen(struct native_display *ndpy)
  {
     struct dri2_display *dri2dpy = dri2_display(ndpy);
-    const char *driver = dri2dpy->api->name;
+    const char *driver = driver_descriptor.name;
     int fd;
  
     if (!x11_screen_support(dri2dpy->xscr, X11_SCREEN_EXTENSION_DRI2) ||
     if (!dri2dpy->dri_driver || !driver ||
         strcmp(dri2dpy->dri_driver, driver) != 0) {
        _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s",
-             dri2dpy->dri_driver, dri2dpy->api->name);
+             dri2dpy->dri_driver, driver);
        return FALSE;
     }
  
     if (fd < 0)
        return FALSE;
  
-    dri2dpy->base.screen = dri2dpy->api->create_screen(dri2dpy->api, fd);
+    dri2dpy->base.screen = driver_descriptor.create_screen(fd);
     if (!dri2dpy->base.screen) {
        _eglLog(_EGL_WARNING, "failed to create DRM screen");
        return FALSE;
@@@ -741,9 -738,8 +738,8 @@@ dri2_display_hash_table_compare(void *k
  }
  
  struct native_display *
 -x11_create_dri2_display(EGLNativeDisplayType dpy,
 +x11_create_dri2_display(Display *dpy,
-                         struct native_event_handler *event_handler,
-                         struct drm_api *api)
+                         struct native_event_handler *event_handler)
  {
     struct dri2_display *dri2dpy;
  
        return NULL;
  
     dri2dpy->event_handler = event_handler;
-    dri2dpy->api = api;
  
     dri2dpy->dpy = dpy;
     if (!dri2dpy->dpy) {
index bfa12b26a77487d922a6e1ac42df244558f387d6,5d71778410b5c5d778db0ea378d3d519517e2e1c..6f1e5998732c547a72fc93c9b435f34535406fdf
  #include "util/u_debug.h"
  #include "util/u_memory.h"
  #include "util/u_string.h"
- #include "state_tracker/drm_api.h"
  #include "egllog.h"
  
  #include "native_x11.h"
  #include "x11_screen.h"
  
- #define X11_PROBE_MAGIC 0x11980BE /* "X11PROBE" */
+ #include "state_tracker/drm_driver.h"
  
- static struct drm_api *api;
+ #define X11_PROBE_MAGIC 0x11980BE /* "X11PROBE" */
  
  static void
  x11_probe_destroy(struct native_probe *nprobe)
@@@ -46,7 -45,7 +45,7 @@@
  }
  
  struct native_probe *
 -native_create_probe(EGLNativeDisplayType dpy)
 +native_create_probe(void *dpy)
  {
     struct native_probe *nprobe;
     struct x11_screen *xscr;
@@@ -96,15 -95,12 +95,12 @@@ native_get_probe_result(struct native_p
     if (!nprobe || nprobe->magic != X11_PROBE_MAGIC)
        return NATIVE_PROBE_UNKNOWN;
  
-    if (!api)
-       api = drm_api_create();
     /* this is a software driver */
-    if (!api)
+    if (!driver_descriptor.create_screen)
        return NATIVE_PROBE_SUPPORTED;
  
     /* the display does not support DRI2 or the driver mismatches */
-    if (!nprobe->data || strcmp(api->name, (const char *) nprobe->data) != 0)
+    if (!nprobe->data || strcmp(driver_descriptor.name, (const char *) nprobe->data) != 0)
        return NATIVE_PROBE_FALLBACK;
  
     return NATIVE_PROBE_EXACT;
@@@ -115,36 -111,31 +111,30 @@@ native_get_name(void
  {
     static char x11_name[32];
  
-    if (!api)
-       api = drm_api_create();
-    if (api)
-       util_snprintf(x11_name, sizeof(x11_name), "X11/%s", api->name);
-    else
-       util_snprintf(x11_name, sizeof(x11_name), "X11");
+    util_snprintf(x11_name, sizeof(x11_name), "X11/%s", driver_descriptor.name);
  
     return x11_name;
  }
  
  struct native_display *
 -native_create_display(EGLNativeDisplayType dpy,
 -                      struct native_event_handler *event_handler)
 +native_create_display(void *dpy, struct native_event_handler *event_handler)
  {
     struct native_display *ndpy = NULL;
     boolean force_sw;
  
-    if (!api)
-       api = drm_api_create();
     force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE);
-    if (api && !force_sw) {
-       ndpy = x11_create_dri2_display((Display *) dpy, event_handler, api);
+    if (!driver_descriptor.create_screen)
+       force_sw = TRUE;
+    if (!force_sw) {
 -      ndpy = x11_create_dri2_display(dpy, event_handler);
++      ndpy = x11_create_dri2_display((Display *) dpy, event_handler);
     }
  
     if (!ndpy) {
        EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING;
  
        _eglLog(level, "use software fallback");
 -      ndpy = x11_create_ximage_display(dpy, event_handler);
 +      ndpy = x11_create_ximage_display((Display *) dpy, event_handler);
     }
  
     return ndpy;
index f1fea7f3de43557609d4cba6603706321c49a6f1,e16da935c0b85bcf4a7c56a0f68a14d25d665238..a1c32c3455a4a370ece7245424edcbea31dc352d
  #ifndef _NATIVE_X11_H_
  #define _NATIVE_X11_H_
  
- #include "state_tracker/drm_api.h"
  #include "common/native.h"
  
  struct native_display *
 -x11_create_ximage_display(EGLNativeDisplayType dpy,
 +x11_create_ximage_display(Display *dpy,
                            struct native_event_handler *event_handler);
  
  struct native_display *
 -x11_create_dri2_display(EGLNativeDisplayType dpy,
 +x11_create_dri2_display(Display *dpy,
-                         struct native_event_handler *event_handler,
-                         struct drm_api *api);
+                         struct native_event_handler *event_handler);
  
  #endif /* _NATIVE_X11_H_ */
index a7e57634aec0aa9b6fcede624817a0f3c63578f3,9357cd5763fcc89e83f701ba77b5a7406397ccbd..c69d75e22e85f94aa19d4b6db82d4b5e07e90b0b
@@@ -51,6 -51,7 +51,7 @@@
  
  #include <pciaccess.h>
  
+ #include "state_tracker/drm_driver.h"
  #include "pipe/p_context.h"
  #include "xorg_tracker.h"
  #include "xorg_winsys.h"
@@@ -80,8 -81,7 +81,8 @@@ typedef enu
      OPTION_2D_ACCEL,
      OPTION_DEBUG_FALLBACK,
      OPTION_THROTTLE_SWAP,
 -    OPTION_THROTTLE_DIRTY
 +    OPTION_THROTTLE_DIRTY,
 +    OPTION_3D_ACCEL
  } drv_option_enums;
  
  static const OptionInfoRec drv_options[] = {
@@@ -90,7 -90,6 +91,7 @@@
      {OPTION_DEBUG_FALLBACK, "DebugFallback", OPTV_BOOLEAN, {0}, FALSE},
      {OPTION_THROTTLE_SWAP, "SwapThrottling", OPTV_BOOLEAN, {0}, FALSE},
      {OPTION_THROTTLE_DIRTY, "DirtyThrottling", OPTV_BOOLEAN, {0}, FALSE},
 +    {OPTION_3D_ACCEL, "3DAccel", OPTV_BOOLEAN, {0}, FALSE},
      {-1, NULL, OPTV_NONE, {0}, FALSE}
  };
  
@@@ -269,18 -268,12 +270,12 @@@ drv_init_drm(ScrnInfoPtr pScrn
            );
  
  
-       ms->api = drm_api_create();
-       ms->fd = drmOpen(ms->api ? ms->api->driver_name : NULL, BusID);
+       ms->fd = drmOpen(driver_descriptor.driver_name, BusID);
        xfree(BusID);
  
        if (ms->fd >= 0)
            return TRUE;
  
-       if (ms->api && ms->api->destroy)
-           ms->api->destroy(ms->api);
-       ms->api = NULL;
        return FALSE;
      }
  
@@@ -292,10 -285,6 +287,6 @@@ drv_close_drm(ScrnInfoPtr pScrn
  {
      modesettingPtr ms = modesettingPTR(pScrn);
  
-     if (ms->api && ms->api->destroy)
-       ms->api->destroy(ms->api);
-     ms->api = NULL;
      drmClose(ms->fd);
      ms->fd = -1;
  
@@@ -316,18 -305,10 +307,11 @@@ drv_init_resource_management(ScrnInfoPt
      if (ms->screen || ms->kms)
        return TRUE;
  
-     if (ms->api) {
-       ms->screen = ms->no3D ? NULL :
-           ms->api->create_screen(ms->api, ms->fd);
-       if (ms->screen)
-           return TRUE;
-       if (ms->api->destroy)
-           ms->api->destroy(ms->api);
 -    ms->screen = driver_descriptor.create_screen(ms->fd);
++    if (!ms->no3D)
++      ms->screen = driver_descriptor.create_screen(ms->fd);
  
-       ms->api = NULL;
-     }
+     if (ms->screen)
+       return TRUE;
  
  #ifdef HAVE_LIBKMS
      if (!kms_create(ms->fd, &ms->kms))
@@@ -433,7 -414,6 +417,6 @@@ drv_pre_init(ScrnInfoPtr pScrn, int fla
      }
  
      ms->fd = -1;
-     ms->api = NULL;
      if (!drv_init_drm(pScrn))
        return FALSE;
  
@@@ -649,21 -629,12 +632,21 @@@ drv_screen_init(int scrnIndex, ScreenPt
      CustomizerPtr cust = ms->cust;
      MessageType from_st;
      MessageType from_dt;
 +    MessageType from_3D;
 +    Bool use3D;
  
      if (!drv_init_drm(pScrn)) {
        FatalError("Could not init DRM");
        return FALSE;
      }
  
 +    use3D = cust ? !cust->no_3d : TRUE;
 +    from_3D = xf86GetOptValBool(ms->Options, OPTION_3D_ACCEL,
 +                              &use3D) ?
 +      X_CONFIG : X_PROBED;
 +
 +    ms->no3D = !use3D;
 +
      if (!drv_init_resource_management(pScrn)) {
        FatalError("Could not init resource management (!pipe_screen && !libkms)");
        return FALSE;
      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Fallback debugging is %s\n",
               ms->debug_fallback ? "enabled" : "disabled");
  #ifdef DRI2
 -    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "3D Acceleration is %s\n",
 +    xf86DrvMsg(pScrn->scrnIndex, from_3D, "3D Acceleration is %s\n",
               ms->screen ? "enabled" : "disabled");
  #else
      xf86DrvMsg(pScrn->scrnIndex, X_INFO, "3D Acceleration is disabled\n");
index df56ad1b155464c608f37df70674fe954a235f90,cc2d379af15fca6a1d1f275e3ed21c81be9f59b4..a5178ef43a4e357c618df30ad14b03ad6798e9b9
@@@ -49,7 -49,6 +49,6 @@@
  #include "pipe/p_screen.h"
  #include "util/u_inlines.h"
  #include "util/u_debug.h"
- #include "state_tracker/drm_api.h"
  
  #define DRV_ERROR(msg)        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
  
@@@ -76,7 -75,6 +75,7 @@@ typedef struct _CustomizerRe
  {
      Bool dirty_throttling;
      Bool swap_throttling;
 +    Bool no_3d;
      Bool (*winsys_screen_init)(struct _CustomizerRec *cust, int fd);
      Bool (*winsys_screen_close)(struct _CustomizerRec *cust);
      Bool (*winsys_enter_vt)(struct _CustomizerRec *cust);
@@@ -105,7 -103,6 +104,7 @@@ typedef struct _modesettingRe
      Bool swapThrottling;
      Bool dirtyThrottling;
      CloseScreenProcPtr CloseScreen;
 +    Bool no3D;
  
      /* Broken-out options. */
      OptionInfoPtr Options;
      struct kms_bo *root_bo;
  
      /* gallium */
-     struct drm_api *api;
      struct pipe_screen *screen;
      struct pipe_context *ctx;
      boolean d_depth_bits_last;
index 8ba1972ffa44daf695860b96aaa8848680565eb0,28647540b0a2afa783cb7f55de499d6b2d1583cc..a0ee9f1d18a1057b8ac1158045e712fe9f778510
@@@ -7,15 -7,18 +7,19 @@@ PIPE_DRIVERS = 
        $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \
        $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
 +      $(TOP)/src/gallium/drivers/galahad/libgalahad.a \
        $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/rbug/librbug.a \
        $(TOP)/src/gallium/drivers/r300/libr300.a
  
  C_SOURCES = \
+       target.c \
        $(COMMON_GALLIUM_SOURCES) \
        $(DRIVER_SOURCES)
  
+ DRIVER_DEFINES = \
+       -DGALLIUM_RBUG -DGALLIUM_TRACE
  include ../Makefile.dri
  
  DRI_LIB_DEPS += -ldrm_radeon
index 64c20afc2beaa8d7a9c52b84c47ac1ae3d3cc3a7,2adc027b8f05a20e6e6a129defb21ce5bdd974b3..79426836db4216abdfe3b8adb27d13c591a4ce3a
@@@ -2,12 -2,14 +2,15 @@@ TOP = ../../../.
  include $(TOP)/configs/current
  
  EGL_DRIVER_NAME = radeon
- EGL_DRIVER_SOURCES = dummy.c
+ EGL_DRIVER_SOURCES = target.c
  EGL_DRIVER_LIBS = -ldrm_radeon
  
+ EGL_DRIVER_DEFINES = \
+       -DGALLIUM_RBUG -DGALLIUM_TRACE
  EGL_DRIVER_PIPES = \
        $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \
 +      $(TOP)/src/gallium/drivers/galahad/libgalahad.a \
        $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/rbug/librbug.a \
        $(TOP)/src/gallium/drivers/r300/libr300.a
index 6cbc61e7aecf47aa505e88cd1d87cc15c533792f,ba7caea155c309f8a142c6fef41610fbcba50969..caf2ac98b9413c440bc0b4f6f8872e45d5f1d332
@@@ -4,20 -4,20 +4,21 @@@ include $(TOP)/configs/curren
  LIBNAME = radeon_drv.so
  
  C_SOURCES = \
+       radeon_target.c \
        radeon_xorg.c
  
  DRIVER_DEFINES = \
-       -DHAVE_CONFIG_H
+       -DHAVE_CONFIG_H -DGALLIUM_RBUG -DGALLIUM_TRACE
  
  DRIVER_LINKS = \
          $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \
          $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \
          $(TOP)/src/gallium/drivers/r300/libr300.a \
 +              $(TOP)/src/gallium/drivers/galahad/libgalahad.a \
          $(TOP)/src/gallium/drivers/trace/libtrace.a \
          $(TOP)/src/gallium/drivers/rbug/librbug.a \
          $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
          $(GALLIUM_AUXILIARIES) \
 -      $(shell pkg-config --libs libdrm libdrm_intel)
 +      $(shell pkg-config --libs libdrm libdrm_radeon)
  
  include ../Makefile.xorg
index 803049d58c99d7a3a1fb88547a02d7ea591a7338,469f1446d051af86e87c5694fea4df301bb72c5d..3d87a994c150a4bc0453faf281605d0e552e4fa3
   *      Joakim Sindholt <opensource@zhasha.com>
   */
  #include <sys/ioctl.h>
- #include "trace/tr_drm.h"
  #include "util/u_inlines.h"
  #include "util/u_debug.h"
- #include "state_tracker/drm_api.h"
  #include "radeon_priv.h"
  #include "r600_screen.h"
  #include "r600_texture.h"
+ #include "r600_public.h"
+ #include "r600_drm_public.h"
+ #include "state_tracker/drm_driver.h"
  
- static struct pipe_screen *r600_drm_create_screen(struct drm_api* api, int drmfd)
+ struct radeon *r600_drm_winsys_create(int drmfd)
  {
-       struct radeon *rw = radeon_new(drmfd, 0);
-       if (rw == NULL)
-               return NULL;
-       return radeon_create_screen(rw);
+       return radeon_new(drmfd, 0);
  }
  
  boolean r600_buffer_get_handle(struct radeon *rw,
                               struct winsys_handle *whandle)
  {
        struct drm_gem_flink flink;
 -      struct r600_buffer* rbuffer;
 -      int r;
 +      struct r600_buffer* rbuffer = (struct r600_buffer*)buf;
  
 -      rbuffer = (struct r600_buffer*)buf;
 -      if (!rbuffer->flink) {
 -              flink.handle = rbuffer->bo->handle;
 -              r = ioctl(rw->fd, DRM_IOCTL_GEM_FLINK, &flink);
 -              if (r) {
 -                      return FALSE;
 +      if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
 +              if (!rbuffer->flink) {
 +                      flink.handle = rbuffer->bo->handle;
 +
 +                      if (ioctl(rw->fd, DRM_IOCTL_GEM_FLINK, &flink)) {
 +                              return FALSE;
 +                      }
 +
 +                      rbuffer->flink = flink.name;
                }
 -              rbuffer->flink = flink.name;
 +              whandle->handle = rbuffer->flink;
 +      } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
 +              whandle->handle = rbuffer->bo->handle;
        }
 -      whandle->handle = rbuffer->flink;
        return TRUE;
  }
- static void r600_drm_api_destroy(struct drm_api *api)
- {
-       return;
- }
- struct drm_api drm_api_hooks = {
-       .name = "r600",
-       .driver_name = "r600",
-       .create_screen = r600_drm_create_screen,
-       .destroy = r600_drm_api_destroy,
- };
- struct drm_api* drm_api_create()
- {
- #ifdef DEBUG
-       return trace_drm_create(&drm_api_hooks);
- #else
-       return &drm_api_hooks;
- #endif
- }
index d2d317dc209e1bbd0bd0e2993fbf4fc85c4ce210,a9b36578ef8aef9de9e448707bc12cbf1fda341d..cb26447606d503019ea7cc309f8d3473f6ccd86c
@@@ -25,7 -25,7 +25,7 @@@
  
  #include "radeon_bo_gem.h"
  #include "radeon_cs_gem.h"
- #include "state_tracker/drm_api.h"
+ #include "state_tracker/drm_driver.h"
  
  static struct r300_winsys_buffer *
  radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws,
@@@ -136,21 -136,29 +136,21 @@@ static boolean radeon_r300_winsys_is_bu
  }
  
  static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws,
 -                                                                      struct pipe_screen *screen,
 -                                                                      struct winsys_handle *whandle,
 -                                                                      unsigned *stride)
 +                                                                        unsigned handle)
  {
      struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws);
      struct pb_buffer *_buf;
  
 -    _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle);
 -    *stride = whandle->stride;
 +    _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, handle);
      return radeon_libdrm_winsys_buffer(_buf);
  }
  
  static boolean radeon_r300_winsys_buffer_get_handle(struct r300_winsys_screen *rws,
                                                    struct r300_winsys_buffer *buffer,
 -                                                  unsigned stride,
 -                                                  struct winsys_handle *whandle)
 +                                                    struct winsys_handle *whandle)
  {
      struct pb_buffer *_buf = radeon_pb_buffer(buffer);
 -    boolean ret;
 -    ret = radeon_drm_bufmgr_get_handle(_buf, whandle);
 -    if (ret)
 -      whandle->stride = stride;
 -    return ret;
 +    return radeon_drm_bufmgr_get_handle(_buf, whandle);
  }
  
  static void radeon_set_flush_cb(struct r300_winsys_screen *rws,
@@@ -184,23 -192,25 +184,23 @@@ static boolean radeon_validate(struct r
      return TRUE;
  }
  
 -static void radeon_get_cs_info(struct r300_winsys_screen *rws,
 -                               struct r300_cs_info *info)
 +static unsigned radeon_get_cs_free_dwords(struct r300_winsys_screen *rws)
  {
      struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws);
      struct radeon_cs *cs = ws->cs;
  
 -    info->capacity = cs->ndw;
 -    info->used = cs->cdw;
 -    info->free = cs->ndw - cs->cdw;
 +    return cs->ndw - cs->cdw;
  }
  
 -static void radeon_begin_cs(struct r300_winsys_screen *rws,
 -                            int size,
 -                            const char* file,
 -                            const char* function,
 -                            int line)
 +static uint32_t *radeon_get_cs_pointer(struct r300_winsys_screen *rws,
 +                                       unsigned count)
  {
      struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws);
 -    radeon_cs_begin(ws->cs, size, file, function, line);
 +    struct radeon_cs *cs = ws->cs;
 +    uint32_t *ptr = cs->packets + cs->cdw;
 +
 +    cs->cdw += count;
 +    return ptr;
  }
  
  static void radeon_write_cs_dword(struct r300_winsys_screen *rws,
@@@ -233,6 -243,15 +233,6 @@@ static void radeon_reset_bos(struct r30
      radeon_cs_space_reset_bos(ws->cs);
  }
  
 -static void radeon_end_cs(struct r300_winsys_screen *rws,
 -                          const char* file,
 -                          const char* function,
 -                          int line)
 -{
 -    struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws);
 -    radeon_cs_end(ws->cs, file, function, line);
 -}
 -
  static void radeon_flush_cs(struct r300_winsys_screen *rws)
  {
      struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws);
@@@ -326,11 -345,12 +326,11 @@@ radeon_setup_winsys(int fd, struct rade
      ws->base.add_buffer = radeon_add_buffer;
      ws->base.validate = radeon_validate;
      ws->base.destroy = radeon_winsys_destroy;
 -    ws->base.get_cs_info = radeon_get_cs_info;
 -    ws->base.begin_cs = radeon_begin_cs;
 +    ws->base.get_cs_free_dwords = radeon_get_cs_free_dwords;
 +    ws->base.get_cs_pointer = radeon_get_cs_pointer;
      ws->base.write_cs_dword = radeon_write_cs_dword;
      ws->base.write_cs_table = radeon_write_cs_table;
      ws->base.write_cs_reloc = radeon_write_cs_reloc;
 -    ws->base.end_cs = radeon_end_cs;
      ws->base.flush_cs = radeon_flush_cs;
      ws->base.reset_bos = radeon_reset_bos;
      ws->base.set_flush_cb = radeon_set_flush_cb;