Merge remote branch 'origin/master' into radeon-rewrite
[mesa.git] / src / mesa / drivers / dri / r300 / r300_context.c
index 5fce8413bbdc829174061262ba05df99974e8f39..6d68309d3f038ba5f89cded1660dfa377db09bbc 100644 (file)
@@ -44,6 +44,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/extensions.h"
 #include "main/state.h"
 #include "main/bufferobj.h"
+#include "main/texobj.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -55,16 +56,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "drivers/common/driverfuncs.h"
 
-#include "radeon_ioctl.h"
-#include "radeon_span.h"
 #include "r300_context.h"
+#include "radeon_context.h"
+#include "radeon_span.h"
 #include "r300_cmdbuf.h"
-#include "r300_mipmap_tree.h"
 #include "r300_state.h"
 #include "r300_ioctl.h"
 #include "r300_tex.h"
 #include "r300_emit.h"
 #include "r300_swtcl.h"
+#include "radeon_bocs_wrapper.h"
 
 
 #include "vblank.h"
@@ -75,19 +76,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 int future_hw_tcl_on = 1;
 int hw_tcl_on = 1;
 
-#define need_GL_EXT_stencil_two_side
-#define need_GL_ARB_multisample
+#define need_GL_VERSION_2_0
 #define need_GL_ARB_point_parameters
-#define need_GL_ARB_texture_compression
-#define need_GL_ARB_vertex_buffer_object
 #define need_GL_ARB_vertex_program
-#define need_GL_EXT_blend_minmax
-//#define need_GL_EXT_fog_coord
-#define need_GL_EXT_multi_draw_arrays
-#define need_GL_EXT_secondary_color
 #define need_GL_EXT_blend_equation_separate
 #define need_GL_EXT_blend_func_separate
+#define need_GL_EXT_blend_minmax
+//#define need_GL_EXT_fog_coord
 #define need_GL_EXT_gpu_program_parameters
+#define need_GL_EXT_secondary_color
+#define need_GL_EXT_stencil_two_side
+#define need_GL_ATI_separate_stencil
 #define need_GL_NV_vertex_program
 #include "extension_helper.h"
 
@@ -95,27 +94,23 @@ const struct dri_extension card_extensions[] = {
   /* *INDENT-OFF* */
   {"GL_ARB_depth_texture",             NULL},
   {"GL_ARB_fragment_program",          NULL},
-  {"GL_ARB_multisample",               GL_ARB_multisample_functions},
   {"GL_ARB_multitexture",              NULL},
   {"GL_ARB_point_parameters",          GL_ARB_point_parameters_functions},
   {"GL_ARB_shadow",                    NULL},
   {"GL_ARB_shadow_ambient",            NULL},
   {"GL_ARB_texture_border_clamp",      NULL},
-  {"GL_ARB_texture_compression",       GL_ARB_texture_compression_functions},
   {"GL_ARB_texture_cube_map",          NULL},
   {"GL_ARB_texture_env_add",           NULL},
   {"GL_ARB_texture_env_combine",       NULL},
   {"GL_ARB_texture_env_crossbar",      NULL},
   {"GL_ARB_texture_env_dot3",          NULL},
   {"GL_ARB_texture_mirrored_repeat",   NULL},
-  {"GL_ARB_vertex_buffer_object",      GL_ARB_vertex_buffer_object_functions},
   {"GL_ARB_vertex_program",            GL_ARB_vertex_program_functions},
   {"GL_EXT_blend_equation_separate",   GL_EXT_blend_equation_separate_functions},
   {"GL_EXT_blend_func_separate",       GL_EXT_blend_func_separate_functions},
   {"GL_EXT_blend_minmax",              GL_EXT_blend_minmax_functions},
   {"GL_EXT_blend_subtract",            NULL},
 //  {"GL_EXT_fog_coord",                       GL_EXT_fog_coord_functions },
-  {"GL_EXT_multi_draw_arrays",         GL_EXT_multi_draw_arrays_functions},
   {"GL_EXT_gpu_program_parameters",     GL_EXT_gpu_program_parameters_functions},
   {"GL_EXT_secondary_color",           GL_EXT_secondary_color_functions},
   {"GL_EXT_shadow_funcs",              NULL},
@@ -128,6 +123,7 @@ const struct dri_extension card_extensions[] = {
   {"GL_EXT_texture_lod_bias",          NULL},
   {"GL_EXT_texture_mirror_clamp",      NULL},
   {"GL_EXT_texture_rectangle",         NULL},
+  {"GL_ATI_separate_stencil",          GL_ATI_separate_stencil_functions},
   {"GL_ATI_texture_env_combine3",      NULL},
   {"GL_ATI_texture_mirror_once",       NULL},
   {"GL_MESA_pack_invert",              NULL},
@@ -140,6 +136,16 @@ const struct dri_extension card_extensions[] = {
   /* *INDENT-ON* */
 };
 
+
+/**
+ * The GL 2.0 functions are needed to make display lists work with
+ * functions added by GL_ATI_separate_stencil.
+ */
+const struct dri_extension gl_20_extension[] = {
+  {"GL_VERSION_2_0",                   GL_VERSION_2_0_functions },
+};
+
+
 extern struct tnl_pipeline_stage _r300_render_stage;
 extern const struct tnl_pipeline_stage _r300_tcl_stage;
 
@@ -187,6 +193,68 @@ static void r300RunPipeline(GLcontext * ctx)
     _mesa_unlock_context_textures(ctx);
 }
 
+static void r300_get_lock(radeonContextPtr rmesa)
+{
+       drm_radeon_sarea_t *sarea = rmesa->sarea;
+
+       if (sarea->ctx_owner != rmesa->dri.hwContext) {
+               sarea->ctx_owner = rmesa->dri.hwContext;
+               if (!rmesa->radeonScreen->kernel_mm)
+                       radeon_bo_legacy_texture_age(rmesa->radeonScreen->bom);
+       }
+}                
+
+static void r300_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmesa)
+{
+    /* please flush pipe do all pending work */
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_SC_SCREENDOOR, 1));
+    radeon_cs_write_dword(cs, 0x0);
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_SC_SCREENDOOR, 1));
+    radeon_cs_write_dword(cs, 0x00FFFFFF);
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_SC_HYPERZ, 1));
+    radeon_cs_write_dword(cs, 0x0);
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_US_CONFIG, 1));
+    radeon_cs_write_dword(cs, 0x0);
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_ZB_CNTL, 1));
+    radeon_cs_write_dword(cs, 0x0);
+    radeon_cs_write_dword(cs, cmdwait(rmesa->radeonScreen, R300_WAIT_3D));
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_RB3D_DSTCACHE_CTLSTAT, 1));
+    radeon_cs_write_dword(cs, R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D);
+    radeon_cs_write_dword(cs, cmdpacket0(rmesa->radeonScreen,
+                                  R300_ZB_ZCACHE_CTLSTAT, 1));
+    radeon_cs_write_dword(cs, R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE);
+    radeon_cs_write_dword(cs, cmdwait(rmesa->radeonScreen,
+                               R300_WAIT_3D | R300_WAIT_3D_CLEAN));
+}
+
+static void r300_vtbl_pre_emit_atoms(radeonContextPtr radeon)
+{
+   BATCH_LOCALS(radeon);
+   cp_wait(radeon, R300_WAIT_3D | R300_WAIT_3D_CLEAN);
+   BEGIN_BATCH_NO_AUTOSTATE(2);
+   OUT_BATCH(cmdpacket0(radeon->radeonScreen, R300_TX_INVALTAGS, 1));
+   OUT_BATCH(R300_TX_FLUSH);
+   END_BATCH();
+   end_3d(radeon);
+}
+
+static void r300_init_vtbl(radeonContextPtr radeon)
+{
+   radeon->vtbl.get_lock = r300_get_lock;
+   radeon->vtbl.update_viewport_offset = r300UpdateViewportOffset;
+   radeon->vtbl.update_draw_buffer = r300UpdateDrawBuffer;
+   radeon->vtbl.emit_cs_header = r300_vtbl_emit_cs_header;
+   radeon->vtbl.swtcl_flush = r300_swtcl_flush;
+   radeon->vtbl.pre_emit_atoms = r300_vtbl_pre_emit_atoms;
+}
+
+
 /* Create the device specific rendering context.
  */
 GLboolean r300CreateContext(const __GLcontextModes * glVisual,
@@ -212,13 +280,14 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        if (!(screen->chip_flags & RADEON_CHIPSET_TCL))
                hw_tcl_on = future_hw_tcl_on = 0;
 
+       r300_init_vtbl(&r300->radeon);
        /* Parse configuration files.
         * Do this here so that initialMaxAnisotropy is set before we create
         * the default textures.
         */
        driParseConfigFiles(&r300->radeon.optionCache, &screen->optionCache,
                            screen->driScreen->myNum, "r300");
-       r300->initialMaxAnisotropy = driQueryOptionf(&r300->radeon.optionCache,
+       r300->radeon.initialMaxAnisotropy = driQueryOptionf(&r300->radeon.optionCache,
                                                     "def_max_anisotropy");
 
        /* Init default driver functions then plug in our R300-specific functions
@@ -238,10 +307,10 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        }
 
        /* Init r300 context data */
-       r300->texture_depth = driQueryOptioni(&r300->radeon.optionCache,
+       r300->radeon.texture_depth = driQueryOptioni(&r300->radeon.optionCache,
                                              "texture_depth");
-       if (r300->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
-               r300->texture_depth = (screen->cpp == 4) ?
+       if (r300->radeon.texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
+               r300->radeon.texture_depth = (screen->cpp == 4) ?
                    DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
 
        /* Set the maximum texture size small enough that we can guarentee that
@@ -282,6 +351,8 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
            ( /*512 */ RADEON_BUFFER_SIZE * 16 * 1024) / (4 * 4);
 #endif
 
+       ctx->Const.MaxDrawBuffers = 1;
+
        /* Initialize the software rasterizer and helper modules.
         */
        _swrast_CreateContext(ctx);
@@ -353,7 +424,7 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
            driQueryOptionb(&r300->radeon.optionCache,
                            "disable_lowimpact_fallback");
 
-       radeonInitSpanFuncs(ctx);
+       radeonInitSpanFuncs( ctx );
        r300InitCmdBuf(r300);
        r300InitState(r300);
        if (!(screen->chip_flags & RADEON_CHIPSET_TCL))
@@ -410,22 +481,22 @@ void r300DestroyContext(__DRIcontextPrivate * driContextPriv)
                _vbo_DestroyContext(r300->radeon.glCtx);
                _swrast_DestroyContext(r300->radeon.glCtx);
 
-               r300FlushCmdBuf(r300, __FUNCTION__);
-               r300DestroyCmdBuf(r300);
+               rcommonFlushCmdBuf(&r300->radeon, __FUNCTION__);
 
                if (radeon->state.scissor.pClipRects) {
                        FREE(radeon->state.scissor.pClipRects);
                        radeon->state.scissor.pClipRects = NULL;
                }
 
+               r300DestroyCmdBuf(r300);
+
                radeonCleanupContext(&r300->radeon);
 
+
                /* the memory manager might be accessed when Mesa frees the shared
                 * state, so don't destroy it earlier
                 */
 
-               /* free the option cache */
-               driDestroyOptionCache(&r300->radeon.optionCache);
 
                FREE(r300);
        }