Fix crashes during rasterization fallback by avoiding _tnl_need_projected_coords
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_screen.c
index e51b72911bbab55fce14e5abc8efcc78e9d78c25..edc924436687949167d9e6745543845fbb8e26b4 100644 (file)
@@ -38,15 +38,20 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "glheader.h"
 #include "imports.h"
+#include "mtypes.h"
+#include "framebuffer.h"
+#include "renderbuffer.h"
 
 #define STANDALONE_MMIO
 #include "radeon_context.h"
 #include "radeon_screen.h"
 #include "radeon_macros.h"
+#include "radeon_span.h"
 
 #include "utils.h"
 #include "context.h"
 #include "vblank.h"
+#include "drirenderbuffer.h"
 
 #include "GL/internal/dri_interface.h"
 
@@ -70,12 +75,13 @@ DRI_CONF_BEGIN
         DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
         DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
         DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
+        DRI_CONF_TEXTURE_LEVEL_HACK(false)
     DRI_CONF_SECTION_END
     DRI_CONF_SECTION_DEBUG
         DRI_CONF_NO_RAST(false)
     DRI_CONF_SECTION_END
 DRI_CONF_END;
-static const GLuint __driNConfigOptions = 12;
+static const GLuint __driNConfigOptions = 13;
 
 #if 1
 /* Including xf86PciInfo.h introduces a bunch of errors...
@@ -88,6 +94,9 @@ static const GLuint __driNConfigOptions = 12;
 #define PCI_CHIP_RADEON_QY     0x5159
 #define PCI_CHIP_RADEON_QZ     0x515A
 
+#define PCI_CHIP_RN50_515E     0x515E
+#define PCI_CHIP_RN50_5969     0x5969
+
 #define PCI_CHIP_RADEON_LW     0x4C57 /* mobility 7 - has tcl */
 #define PCI_CHIP_RADEON_LX     0x4C58 /* mobility FireGL 7800 m7 */
 
@@ -322,6 +331,8 @@ radeonScreenPtr radeonCreateScreen( __DRIscreenPrivate *sPriv )
       screen->chipset |= RADEON_CHIPSET_TCL;
    case PCI_CHIP_RADEON_QY:
    case PCI_CHIP_RADEON_QZ:
+   case PCI_CHIP_RN50_515E:
+   case PCI_CHIP_RN50_5969:
    case PCI_CHIP_RADEON_LY:
    case PCI_CHIP_RADEON_LZ:
    case PCI_CHIP_RS100_4136: /* IGPs don't have TCL */
@@ -355,6 +366,10 @@ radeonScreenPtr radeonCreateScreen( __DRIscreenPrivate *sPriv )
    screen->depthOffset = dri_priv->depthOffset;
    screen->depthPitch  = dri_priv->depthPitch;
 
+   /* Check if ddx has set up a surface reg to cover depth buffer */
+   screen->depthHasSurface = ((sPriv->ddxMajor > 4) &&
+      (screen->chipset & RADEON_CHIPSET_TCL));
+
    screen->texOffset[RADEON_LOCAL_TEX_HEAP] = dri_priv->textureOffset
                                       + screen->fbLocation;
    screen->texSize[RADEON_LOCAL_TEX_HEAP] = dri_priv->textureSize;
@@ -441,10 +456,8 @@ radeonInitDriver( __DRIscreenPrivate *sPriv )
 }
 
 
-
 /**
- * Create and initialize the Mesa and driver specific pixmap buffer
- * data.
+ * Create the Mesa framebuffer and renderbuffers for a given window/drawable.
  *
  * \todo This function (and its interface) will need to be updated to support
  * pbuffers.
@@ -455,6 +468,8 @@ radeonCreateBuffer( __DRIscreenPrivate *driScrnPriv,
                     const __GLcontextModes *mesaVis,
                     GLboolean isPixmap )
 {
+   radeonScreenPtr screen = (radeonScreenPtr) driScrnPriv->private;
+
    if (isPixmap) {
       return GL_FALSE; /* not implemented */
    }
@@ -464,12 +479,64 @@ radeonCreateBuffer( __DRIscreenPrivate *driScrnPriv,
       const GLboolean swAccum = mesaVis->accumRedBits > 0;
       const GLboolean swStencil = mesaVis->stencilBits > 0 &&
          mesaVis->depthBits != 24;
+#if 0
       driDrawPriv->driverPrivate = (void *)
          _mesa_create_framebuffer( mesaVis,
                                    swDepth,
                                    swStencil,
                                    swAccum,
                                    swAlpha );
+#else
+      struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
+
+      {
+         driRenderbuffer *frontRb
+            = driNewRenderbuffer(GL_RGBA, screen->cpp,
+                                 screen->frontOffset, screen->frontPitch);
+         radeonSetSpanFunctions(frontRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
+      }
+
+      if (mesaVis->doubleBufferMode) {
+         driRenderbuffer *backRb
+            = driNewRenderbuffer(GL_RGBA, screen->cpp,
+                                 screen->backOffset, screen->backPitch);
+         radeonSetSpanFunctions(backRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
+      }
+
+      if (mesaVis->depthBits == 16) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch);
+         radeonSetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+      else if (mesaVis->depthBits == 24) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch);
+         radeonSetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+
+      if (mesaVis->stencilBits > 0 && !swStencil) {
+         driRenderbuffer *stencilRb
+            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch);
+         radeonSetSpanFunctions(stencilRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
+      }
+
+      _mesa_add_soft_renderbuffers(fb,
+                                   GL_FALSE, /* color */
+                                   swDepth,
+                                   swStencil,
+                                   swAccum,
+                                   swAlpha,
+                                   GL_FALSE /* aux */);
+      driDrawPriv->driverPrivate = (void *) fb;
+#endif
       return (driDrawPriv->driverPrivate != NULL);
    }
 }
@@ -538,11 +605,11 @@ void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc
 
 {
    __DRIscreenPrivate *psp;
-   static const __DRIversion ddx_expected = { 4, 0, 0 };
+   static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 1, 3, 0 };
 
-   if ( ! driCheckDriDdxDrmVersions2( "Radeon",
+   if ( ! driCheckDriDdxDrmVersions3( "Radeon",
                                      dri_version, & dri_expected,
                                      ddx_version, & ddx_expected,
                                      drm_version, & drm_expected ) ) {