Fallback to software render if there is no miptree for an image
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common_context.h
index c9be104578ed47e98d0c7c6c6bf8abb226ded848..5156c5d0d0a8bcf5db3e2c9ded72205ef407b82f 100644 (file)
@@ -8,11 +8,17 @@
 #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"
+
 /* This union is used to avoid warnings/miscompilation
    with float to uint32_t casts due to strict-aliasing */
 typedef union { GLfloat f; uint32_t ui32; } float_ui32_type;
@@ -39,6 +45,8 @@ typedef struct radeon_context *radeonContextPtr;
 #define RADEON_FALLBACK_BLEND_FUNC     0x0020
 #define RADEON_FALLBACK_DISABLE        0x0040
 #define RADEON_FALLBACK_BORDER_MODE    0x0080
+#define RADEON_FALLBACK_DEPTH_BUFFER   0x0100
+#define RADEON_FALLBACK_STENCIL_BUFFER  0x0200
 
 #define R200_FALLBACK_TEXTURE           0x01
 #define R200_FALLBACK_DRAW_BUFFER       0x02
@@ -68,6 +76,8 @@ typedef struct radeon_context *radeonContextPtr;
 #include "tnl_dd/t_dd_vertex.h"
 #undef TAG
 
+#define RADEON_RB_CLASS 0xdeadbeef
+
 struct radeon_renderbuffer
 {
        struct gl_renderbuffer base;
@@ -75,25 +85,49 @@ 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 */
        int has_surface;
 
-       __DRIdrawablePrivate *dPriv;
+       GLuint pf_pending;  /**< sequence number of pending flip */
+       GLuint vbl_pending;   /**< vblank sequence number of pending flip */
+       __DRIdrawable *dPriv;
 };
 
+struct radeon_framebuffer
+{
+       struct gl_framebuffer base;
+
+       struct radeon_renderbuffer *color_rb[2];
+
+       GLuint vbl_waited;
+
+       /* buffer swap */
+       int64_t swap_ust;
+       int64_t swap_missed_ust;
+
+       GLuint swap_count;
+       GLuint swap_missed_count;
+
+       /* Drawable page flipping state */
+       GLboolean pf_active;
+       GLint pf_current_page;
+       GLint pf_num_pages;
+
+};
+
+
 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;
-       GLfloat scale;
-       struct radeon_renderbuffer *rrb;
+       struct gl_renderbuffer *rb;
 };
 
 struct radeon_scissor_state {
@@ -106,14 +140,9 @@ struct radeon_scissor_state {
 };
 
 struct radeon_stencilbuffer_state {
-       GLboolean hwBuffer;
        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 */
@@ -131,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;
 };
 
@@ -170,7 +200,6 @@ typedef struct radeon_tex_obj radeonTexObj, *radeonTexObjPtr;
 /* Texture object in locally shared texture space.
  */
 struct radeon_tex_obj {
-  //   driTextureObject base;
        struct gl_texture_object base;
        struct _radeon_mipmap_tree *mt;
 
@@ -179,32 +208,19 @@ 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 */
        GLuint tile_bits;       /* hw texture tile bits used on this texture */
         struct radeon_bo *bo;
 
-       GLuint bufAddr;         /* Offset to start of locally
-                                  shared texture block */
-
-       GLuint dirty_state;     /* Flags (1 per texunit) for
-                                  whether or not this texobj
-                                  has dirty hardware state
-                                  (pp_*) that needs to be
-                                  brought into the
-                                  texunit. */
-
-       drm_radeon_tex_image_t image[6][RADEON_MAX_TEXTURE_LEVELS];
-       /* Six, for the cube faces */
-
-
-
        GLuint pp_txfilter;     /* hardware register values */
        GLuint pp_txformat;
-        GLuint pp_txformat_x;
-       GLuint pp_txoffset;     /* Image location in texmem.
-                                  All cube faces follow. */
+       GLuint pp_txformat_x;
        GLuint pp_txsize;       /* npot only */
        GLuint pp_txpitch;      /* npot only */
        GLuint pp_border_color;
@@ -212,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;
 
 
@@ -222,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 {
@@ -237,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.
@@ -252,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
@@ -277,11 +327,22 @@ 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
+struct radeon_tcl_info {
+       struct radeon_aos aos[RADEON_MAX_AOS_ARRAYS];
+       GLuint aos_count;
+       struct radeon_bo *elt_dma_bo; /** Buffer object that contains element indices */
+       int elt_dma_offset; /** Offset into this buffer object, in bytes */
 };
 
 struct radeon_ioctl {
        GLuint vertex_offset;
-        struct radeon_bo *bo;
+       GLuint vertex_max;
+       struct radeon_bo *bo;
        GLuint vertex_size;
 };
 
@@ -320,43 +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 *);
@@ -366,6 +400,7 @@ typedef void (*radeon_line_func) (radeonContextPtr,
 
 typedef void (*radeon_point_func) (radeonContextPtr, radeonVertex *);
 
+#define RADEON_MAX_BOS 32
 struct radeon_state {
        struct radeon_colorbuffer_state color;
        struct radeon_depthbuffer_state depth;
@@ -390,14 +425,14 @@ struct radeon_cmdbuf {
 struct radeon_context {
    GLcontext *glCtx;
    radeonScreenPtr radeonScreen;       /* Screen private DRI data */
-  
+
    /* Texture object bookkeeping
     */
-   unsigned              nr_heaps;
-   driTexHeap          * texture_heaps[ RADEON_NR_TEX_HEAPS ];
-   driTextureObject      swapped;
    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;
@@ -408,14 +443,10 @@ struct radeon_context {
    GLuint NewGLState;
    DECLARE_RENDERINPUTS(tnl_index_bitset);     /* index of bits for last tnl_install_attrs */
 
-   /* Page flipping */
-   GLuint doPageFlip;
-
    /* Drawable, cliprect and scissor information */
    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 */
@@ -427,36 +458,103 @@ struct radeon_context {
    GLuint irqsEmitted;
    drm_radeon_irq_wait_t iw;
 
-   /* buffer swap */
-   int64_t swap_ust;
-   int64_t swap_missed_ust;
-
-   GLuint swap_count;
-   GLuint swap_missed_count;
-
    /* Derived state - for r300 only */
    struct radeon_state state;
 
    struct radeon_swtcl_info swtcl;
+   struct radeon_tcl_info tcl;
    /* Configuration cache
     */
    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;
+
+   /**
+    * 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 dri_metaops meta;
+
+   struct {
+       struct radeon_query_object *current;
+       struct radeon_state_atom queryobj;
+   } query;
+
    struct {
           void (*get_lock)(radeonContextPtr radeon);
           void (*update_viewport_offset)(GLcontext *ctx);
-          void (*update_draw_buffer)(GLcontext *ctx);
           void (*emit_cs_header)(struct radeon_cs *cs, radeonContextPtr rmesa);
           void (*swtcl_flush)(GLcontext *ctx, uint32_t offset);
           void (*pre_emit_atoms)(radeonContextPtr rmesa);
           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
  */
@@ -505,25 +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);
-
-/* ================================================================
- * 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