Fallback to software render if there is no miptree for an image
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common_context.h
index d32e5af5441785bb1f8104a604e12f0a51ec5c66..5156c5d0d0a8bcf5db3e2c9ded72205ef407b82f 100644 (file)
@@ -8,11 +8,13 @@
 #include "tnl/t_context.h"
 #include "main/colormac.h"
 
+#include "radeon_debug.h"
 #include "radeon_screen.h"
 #include "radeon_drm.h"
 #include "dri_util.h"
 #include "tnl/t_vertex.h"
 
+#include "dri_metaops.h"
 struct radeon_context;
 
 #include "radeon_bocs_wrapper.h"
@@ -83,8 +85,6 @@ struct radeon_renderbuffer
        unsigned int cpp;
        /* unsigned int offset; */
        unsigned int pitch;
-       unsigned int width;
-       unsigned int height;
 
        uint32_t draw_offset; /* FBO */
        /* boo Xorg 6.8.2 compat */
@@ -92,7 +92,7 @@ struct radeon_renderbuffer
 
        GLuint pf_pending;  /**< sequence number of pending flip */
        GLuint vbl_pending;   /**< vblank sequence number of pending flip */
-       __DRIdrawablePrivate *dPriv;
+       __DRIdrawable *dPriv;
 };
 
 struct radeon_framebuffer
@@ -117,17 +117,17 @@ struct radeon_framebuffer
 
 };
 
+
 struct radeon_colorbuffer_state {
        GLuint clear;
        int roundEnable;
-       struct radeon_renderbuffer *rrb;
+       struct gl_renderbuffer *rb;
        uint32_t draw_offset; /* offset into color renderbuffer - FBOs */
 };
 
 struct radeon_depthbuffer_state {
        GLuint clear;
-       struct radeon_renderbuffer *rrb;
+       struct gl_renderbuffer *rb;
 };
 
 struct radeon_scissor_state {
@@ -143,10 +143,6 @@ struct radeon_stencilbuffer_state {
        GLuint clear;           /* rb3d_stencilrefmask value */
 };
 
-struct radeon_stipple_state {
-       GLuint mask[32];
-};
-
 struct radeon_state_atom {
        struct radeon_state_atom *next, *prev;
        const char *name;       /* for debug */
@@ -164,6 +160,7 @@ struct radeon_hw_state {
        /* Head of the linked list of state atoms. */
        struct radeon_state_atom atomlist;
        int max_state_size;     /* Number of bytes necessary for a full state emit. */
+       int max_post_flush_size; /* Number of bytes necessary for post flushing emits */
        GLboolean is_dirty, all_dirty;
 };
 
@@ -211,6 +208,10 @@ struct radeon_tex_obj {
         * and so on.
         */
        GLboolean validated;
+       /* Minimum LOD to be used during rendering */
+       unsigned minLod;
+       /* Miximum LOD to be used during rendering */
+       unsigned maxLod;
 
        GLuint override_offset;
        GLboolean image_override; /* Image overridden by GLX_EXT_tfp */
@@ -227,6 +228,24 @@ struct radeon_tex_obj {
 
         GLuint pp_txfilter_1;  /*  r300 */
 
+       /* r700 texture states */
+       GLuint SQ_TEX_RESOURCE0;
+       GLuint SQ_TEX_RESOURCE1;
+       GLuint SQ_TEX_RESOURCE2;
+       GLuint SQ_TEX_RESOURCE3;
+       GLuint SQ_TEX_RESOURCE4;
+       GLuint SQ_TEX_RESOURCE5;
+       GLuint SQ_TEX_RESOURCE6;
+
+       GLuint SQ_TEX_SAMPLER0;
+       GLuint SQ_TEX_SAMPLER1;
+       GLuint SQ_TEX_SAMPLER2;
+
+       GLuint TD_PS_SAMPLER0_BORDER_RED;
+       GLuint TD_PS_SAMPLER0_BORDER_GREEN;
+       GLuint TD_PS_SAMPLER0_BORDER_BLUE;
+       GLuint TD_PS_SAMPLER0_BORDER_ALPHA;
+
        GLboolean border_fallback;
 
 
@@ -237,6 +256,17 @@ static INLINE radeonTexObj* radeon_tex_obj(struct gl_texture_object *texObj)
        return (radeonTexObj*)texObj;
 }
 
+/* occlusion query */
+struct radeon_query_object {
+       struct gl_query_object Base;
+       struct radeon_bo *bo;
+       int curr_offset;
+       GLboolean emitted_begin;
+
+       /* Double linked list of not flushed query objects */
+       struct radeon_query_object *prev, *next;
+};
+
 /* Need refcounting on dma buffers:
  */
 struct radeon_dma_buffer {
@@ -252,14 +282,25 @@ struct radeon_aos {
        int count; /** Number of vertices */
 };
 
+#define DMA_BO_FREE_TIME 100
+
+struct radeon_dma_bo {
+  struct radeon_dma_bo *next, *prev;
+  struct radeon_bo *bo;
+  int expire_counter;
+};
+
 struct radeon_dma {
         /* Active dma region.  Allocations for vertices and retained
          * regions come from here.  Also used for emitting random vertices,
          * these may be flushed by calling flush_current();
          */
-        struct radeon_bo *current; /** Buffer that DMA memory is allocated from */
-        int current_used; /** Number of bytes allocated and forgotten about */
-        int current_vertexptr; /** End of active vertex region */
+       struct radeon_dma_bo free;
+       struct radeon_dma_bo wait;
+       struct radeon_dma_bo reserved;
+        size_t current_used; /** Number of bytes allocated and forgotten about */
+        size_t current_vertexptr; /** End of active vertex region */
+        size_t minimum_size;
 
         /**
          * If current_vertexptr != current_used then flush must be non-zero.
@@ -267,12 +308,6 @@ struct radeon_dma {
          * performed.
          */
         void (*flush) (GLcontext *);
-
-        /* Number of "in-flight" DMA buffers, i.e. the number of buffers
-         * for which a DISCARD command is currently queued in the command buffer
-.
-         */
-        GLuint nr_released_bufs;
 };
 
 /* radeon_swtcl.c
@@ -292,6 +327,8 @@ struct radeon_swtcl_info {
        struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
        GLuint vertex_attr_count;
 
+       GLuint emit_prediction;
+        struct radeon_bo *bo;
 };
 
 #define RADEON_MAX_AOS_ARRAYS          16
@@ -304,7 +341,8 @@ struct radeon_tcl_info {
 
 struct radeon_ioctl {
        GLuint vertex_offset;
-        struct radeon_bo *bo;
+       GLuint vertex_max;
+       struct radeon_bo *bo;
        GLuint vertex_size;
 };
 
@@ -343,42 +381,16 @@ struct radeon_store {
 };
 
 struct radeon_dri_mirror {
-       __DRIcontextPrivate *context;   /* DRI context */
-       __DRIscreenPrivate *screen;     /* DRI screen */
-
-   /**
-    * DRI drawable bound to this context for drawing.
-    */
-       __DRIdrawablePrivate *drawable;
-
-   /**
-    * DRI drawable bound to this context for reading.
-    */
-       __DRIdrawablePrivate *readable;
+       __DRIcontext *context;  /* DRI context */
+       __DRIscreen *screen;    /* DRI screen */
 
        drm_context_t hwContext;
        drm_hw_lock_t *hwLock;
+       int hwLockCount;
        int fd;
        int drmMinor;
 };
 
-#define DEBUG_TEXTURE  0x001
-#define DEBUG_STATE    0x002
-#define DEBUG_IOCTL    0x004
-#define DEBUG_PRIMS    0x008
-#define DEBUG_VERTS    0x010
-#define DEBUG_FALLBACKS        0x020
-#define DEBUG_VFMT     0x040
-#define DEBUG_CODEGEN  0x080
-#define DEBUG_VERBOSE  0x100
-#define DEBUG_DRI       0x200
-#define DEBUG_DMA       0x400
-#define DEBUG_SANITY    0x800
-#define DEBUG_SYNC      0x1000
-#define DEBUG_PIXEL     0x2000
-#define DEBUG_MEMORY    0x4000
-
-
 typedef void (*radeon_tri_func) (radeonContextPtr,
                                 radeonVertex *,
                                 radeonVertex *, radeonVertex *);
@@ -388,15 +400,12 @@ typedef void (*radeon_line_func) (radeonContextPtr,
 
 typedef void (*radeon_point_func) (radeonContextPtr, radeonVertex *);
 
-#define RADEON_MAX_BOS 24
+#define RADEON_MAX_BOS 32
 struct radeon_state {
        struct radeon_colorbuffer_state color;
        struct radeon_depthbuffer_state depth;
        struct radeon_scissor_state scissor;
        struct radeon_stencilbuffer_state stencil;
-
-       struct radeon_cs_space_check bos[RADEON_MAX_BOS];
-       int validated_bo_count;
 };
 
 /**
@@ -416,11 +425,14 @@ struct radeon_cmdbuf {
 struct radeon_context {
    GLcontext *glCtx;
    radeonScreenPtr radeonScreen;       /* Screen private DRI data */
-  
+
    /* Texture object bookkeeping
     */
    int                   texture_depth;
    float                 initialMaxAnisotropy;
+   uint32_t              texture_row_align;
+   uint32_t              texture_rect_row_align;
+   uint32_t              texture_compressed_row_align;
 
   struct radeon_dma dma;
   struct radeon_hw_state hw;
@@ -435,7 +447,6 @@ struct radeon_context {
    GLuint numClipRects;        /* Cliprects for the draw buffer */
    drm_clip_rect_t *pClipRects;
    unsigned int lastStamp;
-   GLboolean lost_context;
    drm_radeon_sarea_t *sarea;  /* Private SAREA data */
 
    /* Mirrors of some DRI state */
@@ -457,24 +468,44 @@ struct radeon_context {
    driOptionCache optionCache;
 
    struct radeon_cmdbuf cmdbuf;
-       
+
+   struct radeon_debug debug;
+
   drm_clip_rect_t fboRect;
   GLboolean constant_cliprect; /* use for FBO or DRI2 rendering */
   GLboolean front_cliprects;
 
-  struct {
-      struct gl_fragment_program *bitmap_fp;
-      struct gl_vertex_program *passthrough_vp;
+   /**
+    * Set if rendering has occured to the drawable's front buffer.
+    *
+    * This is used in the DRI2 case to detect that glFlush should also copy
+    * the contents of the fake front buffer to the real front buffer.
+    */
+   GLboolean front_buffer_dirty;
+
+   /**
+    * Track whether front-buffer rendering is currently enabled
+    *
+    * A separate flag is used to track this in order to support MRT more
+    * easily.
+    */
+   GLboolean is_front_buffer_rendering;
+
+   /**
+    * Track whether front-buffer is the current read target.
+    *
+    * This is closely associated with is_front_buffer_rendering, but may
+    * be set separately.  The DRI2 fake front buffer must be referenced
+    * either way.
+    */
+   GLboolean is_front_buffer_reading;
 
-      struct gl_fragment_program *saved_fp;
-      GLboolean saved_fp_enable;
-      struct gl_vertex_program *saved_vp;
-      GLboolean saved_vp_enable;
+   struct dri_metaops meta;
 
-      GLint saved_vp_x, saved_vp_y;
-      GLsizei saved_vp_width, saved_vp_height;
-      GLenum saved_matrix_mode;
-   } meta;
+   struct {
+       struct radeon_query_object *current;
+       struct radeon_state_atom queryobj;
+   } query;
 
    struct {
           void (*get_lock)(radeonContextPtr radeon);
@@ -485,11 +516,45 @@ struct radeon_context {
           void (*pre_emit_state)(radeonContextPtr rmesa);
           void (*fallback)(GLcontext *ctx, GLuint bit, GLboolean mode);
           void (*free_context)(GLcontext *ctx);
+          void (*emit_query_finish)(radeonContextPtr radeon);
+          void (*update_scissor)(GLcontext *ctx);
+          unsigned (*check_blit)(gl_format mesa_format);
+          unsigned (*blit)(GLcontext *ctx,
+                        struct radeon_bo *src_bo,
+                        intptr_t src_offset,
+                        gl_format src_mesaformat,
+                        unsigned src_pitch,
+                        unsigned src_width,
+                        unsigned src_height,
+                        unsigned src_x_offset,
+                        unsigned src_y_offset,
+                        struct radeon_bo *dst_bo,
+                        intptr_t dst_offset,
+                        gl_format dst_mesaformat,
+                        unsigned dst_pitch,
+                        unsigned dst_width,
+                        unsigned dst_height,
+                        unsigned dst_x_offset,
+                        unsigned dst_y_offset,
+                        unsigned reg_width,
+                        unsigned reg_height,
+                        unsigned flip_y);
+          unsigned (*is_format_renderable)(gl_format mesa_format);
    } vtbl;
 };
 
 #define RADEON_CONTEXT(glctx) ((radeonContextPtr)(ctx->DriverCtx))
 
+static inline __DRIdrawable* radeon_get_drawable(radeonContextPtr radeon)
+{
+       return radeon->dri.context->driDrawablePriv;
+}
+
+static inline __DRIdrawable* radeon_get_readable(radeonContextPtr radeon)
+{
+       return radeon->dri.context->driReadablePriv;
+}
+
 /**
  * This function takes a float and packs it into a uint32_t
  */
@@ -538,26 +603,16 @@ static INLINE uint32_t radeonPackFloat24(float f)
 GLboolean radeonInitContext(radeonContextPtr radeon,
                            struct dd_function_table* functions,
                            const __GLcontextModes * glVisual,
-                           __DRIcontextPrivate * driContextPriv,
+                           __DRIcontext * driContextPriv,
                            void *sharedContextPrivate);
 
 void radeonCleanupContext(radeonContextPtr radeon);
-GLboolean radeonUnbindContext(__DRIcontextPrivate * driContextPriv);
-void radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable);
-GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
-                           __DRIdrawablePrivate * driDrawPriv,
-                           __DRIdrawablePrivate * driReadPriv);
-extern void radeonDestroyContext(__DRIcontextPrivate * driContextPriv);
-
-/* ================================================================
- * Debugging:
- */
-#define DO_DEBUG               1
-
-#if DO_DEBUG
-extern int RADEON_DEBUG;
-#else
-#define RADEON_DEBUG           0
-#endif
+GLboolean radeonUnbindContext(__DRIcontext * driContextPriv);
+void radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
+                                GLboolean front_only);
+GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
+                           __DRIdrawable * driDrawPriv,
+                           __DRIdrawable * driReadPriv);
+extern void radeonDestroyContext(__DRIcontext * driContextPriv);
 
 #endif