Clean up warnings in r300 code by making some symbols static, adding prototypes
[mesa.git] / src / mesa / drivers / dri / r300 / r300_context.c
index 88a67ce57c0b4df19486e24e4afdd76684367b5f..9100ac2565b7345743023fd9b1f44dc13ec80ed4 100644 (file)
@@ -32,7 +32,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *   Keith Whitwell <keith@tungstengraphics.com>
  *   Nicolai Haehnle <prefect_@gmx.net>
  */
-
 #include "glheader.h"
 #include "api_arrayelt.h"
 #include "context.h"
@@ -41,6 +40,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "matrix.h"
 #include "extensions.h"
 #include "state.h"
+#include "bufferobj.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
@@ -63,7 +63,57 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "utils.h"
 #include "xmlpool.h"           /* for symbolic values of enum-type options */
 
+/* hw_tcl_on derives from future_hw_tcl_on when its safe to change it. */
+int future_hw_tcl_on=0;
+int hw_tcl_on=0;
+
+#if 1
+#define need_GL_ARB_multisample
+#define need_GL_ARB_texture_compression
+#define need_GL_EXT_blend_minmax
+#include "extension_helper.h"
+
+static const struct dri_extension card_extensions[] = {
+  {"GL_ARB_multisample",               GL_ARB_multisample_functions},
+  {"GL_ARB_multitexture",              NULL},
+  {"GL_ARB_texture_border_clamp",      NULL},
+  {"GL_ARB_texture_compression",       GL_ARB_texture_compression_functions},
+/* disable until we support it, fixes a few things in ut2004 */
+/*     {"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",      NULL},
+  {"GL_ARB_vertex_program",            NULL},
+#if USE_ARB_F_P == 1
+  {"GL_ARB_fragment_program",          NULL},
+#endif
+  {"GL_EXT_blend_equation_separate",   NULL},
+  {"GL_EXT_blend_func_separate",       NULL},
+  {"GL_EXT_blend_minmax",              GL_EXT_blend_minmax_functions},
+  {"GL_EXT_blend_subtract",            NULL},
+  {"GL_EXT_secondary_color",           NULL},
+  {"GL_EXT_stencil_wrap",              NULL},
+  {"GL_EXT_texture_edge_clamp",                NULL},
+  {"GL_EXT_texture_env_combine",       NULL},
+  {"GL_EXT_texture_env_dot3",          NULL},
+  {"GL_EXT_texture_filter_anisotropic",        NULL},
+  {"GL_EXT_texture_lod_bias",          NULL},
+  {"GL_EXT_texture_mirror_clamp",      NULL},
+  {"GL_EXT_texture_rectangle",         NULL},
+  {"GL_ATI_texture_env_combine3",      NULL},
+  {"GL_ATI_texture_mirror_once",       NULL},
+  {"GL_MESA_pack_invert",              NULL},
+  {"GL_MESA_ycbcr_texture",            NULL},
+  {"GL_NV_blend_square",               NULL},
+  {"GL_NV_vertex_program",             NULL},
+  {"GL_SGIS_generate_mipmap",          NULL},
+  {NULL,                               NULL}
+};
 
+#else
 /* Extension strings exported by the R300 driver.
  */
 static const char *const card_extensions[] = {
@@ -71,13 +121,18 @@ static const char *const card_extensions[] = {
        "GL_ARB_multitexture",
        "GL_ARB_texture_border_clamp",
        "GL_ARB_texture_compression",
-       "GL_ARB_texture_cube_map",
+/* disable until we support it, fixes a few things in ut2004 */
+/*     "GL_ARB_texture_cube_map", */
        "GL_ARB_texture_env_add",
        "GL_ARB_texture_env_combine",
+       "GL_ARB_texture_env_crossbar",
        "GL_ARB_texture_env_dot3",
        "GL_ARB_texture_mirrored_repeat",
        "GL_ARB_vertex_buffer_object",
        "GL_ARB_vertex_program",
+#if USE_ARB_F_P == 1
+       "GL_ARB_fragment_program",
+#endif
        "GL_EXT_blend_equation_separate",
        "GL_EXT_blend_func_separate",
        "GL_EXT_blend_minmax",
@@ -100,14 +155,15 @@ static const char *const card_extensions[] = {
        "GL_SGIS_generate_mipmap",
        NULL
 };
-
+#endif
 extern struct tnl_pipeline_stage _r300_render_stage;
+extern struct tnl_pipeline_stage _r300_tcl_stage;
 
 static const struct tnl_pipeline_stage *r300_pipeline[] = {
 
        /* Try and go straight to t&l
         */
-//     &_r300_tcl_stage,
+       &_r300_tcl_stage,
 
        /* Catch any t&l fallbacks
         */
@@ -136,6 +192,75 @@ static const struct tnl_pipeline_stage *r300_pipeline[] = {
        0,
 };
 
+static void r300BufferData(GLcontext *ctx, GLenum target, GLsizeiptrARB size,
+               const GLvoid *data, GLenum usage, struct gl_buffer_object *obj)
+{
+       r300ContextPtr rmesa = R300_CONTEXT(ctx);
+       drm_radeon_mem_alloc_t alloc;
+       int offset, ret;
+
+       /* Free previous buffer */
+       if (obj->OnCard) {
+               drm_radeon_mem_free_t memfree;
+               
+               memfree.region = RADEON_MEM_REGION_GART;
+               memfree.region_offset = (char *)obj->Data - (char *)rmesa->radeon.radeonScreen->gartTextures.map;
+
+               ret = drmCommandWrite(rmesa->radeon.radeonScreen->driScreen->fd,
+                                     DRM_RADEON_FREE, &memfree, sizeof(memfree));
+
+               if (ret) {
+                       WARN_ONCE("Failed to free GART memroy!\n");
+               }
+               obj->OnCard = GL_FALSE;
+       }
+       
+       alloc.region = RADEON_MEM_REGION_GART;
+       alloc.alignment = 4;
+       alloc.size = size;
+       alloc.region_offset = &offset;
+
+       ret = drmCommandWriteRead( rmesa->radeon.dri.fd, DRM_RADEON_ALLOC, &alloc, sizeof(alloc));
+       if (ret) {
+               WARN_ONCE("Ran out of GART memory!\n");
+               obj->Data = NULL;
+               _mesa_buffer_data(ctx, target, size, data, usage, obj);
+               return ;
+       }
+       obj->Data = ((char *)rmesa->radeon.radeonScreen->gartTextures.map) + offset;
+       
+       if (data)
+               memcpy(obj->Data, data, size);
+       
+       obj->Size = size;
+       obj->Usage = usage;
+       obj->OnCard = GL_TRUE;
+#if 0
+       fprintf(stderr, "allocated %d bytes at %p, offset=%d\n", size, obj->Data, offset);
+#endif
+}
+
+static void r300DeleteBuffer(GLcontext *ctx, struct gl_buffer_object *obj)
+{
+       r300ContextPtr rmesa = R300_CONTEXT(ctx);
+       
+       if(r300IsGartMemory(rmesa, obj->Data, obj->Size)){
+               drm_radeon_mem_free_t memfree;
+               int ret;
+               
+               memfree.region = RADEON_MEM_REGION_GART;
+               memfree.region_offset = (char *)obj->Data - (char *)rmesa->radeon.radeonScreen->gartTextures.map;
+
+               ret = drmCommandWrite(rmesa->radeon.radeonScreen->driScreen->fd,
+                                     DRM_RADEON_FREE, &memfree, sizeof(memfree));
+
+               if(ret){
+                       WARN_ONCE("Failed to free GART memroy!\n");
+               }
+               obj->Data = NULL;
+       }
+       _mesa_delete_buffer_object(ctx, obj);
+}
 
 /* Create the device specific rendering context.
  */
@@ -173,7 +298,15 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        r300InitIoctlFuncs(&functions);
        r300InitStateFuncs(&functions);
        r300InitTextureFuncs(&functions);
-
+       r300InitShaderFuncs(&functions);
+       
+#if 0 /* Needs various Mesa changes... */
+       if (hw_tcl_on) {
+               functions.BufferData = r300BufferData;
+               functions.DeleteBuffer = r300DeleteBuffer;
+       }
+#endif
+       
        if (!radeonInitContext(&r300->radeon, &functions,
                               glVisual, driContextPriv, sharedContextPrivate)) {
                FREE(r300);
@@ -216,7 +349,8 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
         * texturable memory at once.
         */
 
-       ctx = r300->radeon.glCtx;
+       ctx = r300->radeon.glCtx; 
+       
        ctx->Const.MaxTextureImageUnits = driQueryOptioni(&r300->radeon.optionCache,
                                                     "texture_image_units");
        ctx->Const.MaxTextureCoordUnits = driQueryOptioni(&r300->radeon.optionCache,
@@ -225,17 +359,15 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
                                          ctx->Const.MaxTextureCoordUnits);
        ctx->Const.MaxTextureMaxAnisotropy = 16.0;
 
-       /* No wide points.
-        */
        ctx->Const.MinPointSize = 1.0;
        ctx->Const.MinPointSizeAA = 1.0;
-       ctx->Const.MaxPointSize = 1.0;
-       ctx->Const.MaxPointSizeAA = 1.0;
+       ctx->Const.MaxPointSize = R300_POINTSIZE_MAX;
+       ctx->Const.MaxPointSizeAA = R300_POINTSIZE_MAX;
 
        ctx->Const.MinLineWidth = 1.0;
        ctx->Const.MinLineWidthAA = 1.0;
-       ctx->Const.MaxLineWidth = 1.0;
-       ctx->Const.MaxLineWidthAA = 1.0;
+       ctx->Const.MaxLineWidth = R300_LINESIZE_MAX;
+       ctx->Const.MaxLineWidthAA = R300_LINESIZE_MAX;
 
        /* Initialize the software rasterizer and helper modules.
         */
@@ -243,6 +375,7 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        _ac_CreateContext(ctx);
        _tnl_CreateContext(ctx);
        _swsetup_CreateContext(ctx);
+       _swsetup_Wakeup(ctx);
        _ae_create_context(ctx);
 
        /* Install the customized pipeline:
@@ -261,11 +394,33 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        _tnl_allow_pixel_fog(ctx, GL_FALSE);
        _tnl_allow_vertex_fog(ctx, GL_TRUE);
 
-       driInitExtensions(ctx, card_extensions, GL_TRUE);
+       /* currently bogus data */
+       ctx->Const.MaxVertexProgramInstructions=VSF_MAX_FRAGMENT_LENGTH;
+       ctx->Const.MaxVertexProgramAttribs=16; // r420
+       ctx->Const.MaxVertexProgramTemps=VSF_MAX_FRAGMENT_TEMPS;
+       ctx->Const.MaxVertexProgramLocalParams=256; // r420
+       ctx->Const.MaxVertexProgramEnvParams=256; // r420
+       ctx->Const.MaxVertexProgramAddressRegs=1;
+
+#if USE_ARB_F_P
+       ctx->Const.MaxFragmentProgramTemps = PFS_NUM_TEMP_REGS;
+       ctx->Const.MaxFragmentProgramAttribs = 11; /* copy i915... */
+       ctx->Const.MaxFragmentProgramLocalParams = PFS_NUM_CONST_REGS;
+       ctx->Const.MaxFragmentProgramEnvParams = PFS_NUM_CONST_REGS;
+       ctx->Const.MaxFragmentProgramAluInstructions = PFS_MAX_ALU_INST;
+       ctx->Const.MaxFragmentProgramTexInstructions = PFS_MAX_TEX_INST;
+       ctx->Const.MaxFragmentProgramInstructions = PFS_MAX_ALU_INST+PFS_MAX_TEX_INST;
+       ctx->Const.MaxFragmentProgramTexIndirections = PFS_MAX_TEX_INDIRECT;
+       ctx->Const.MaxFragmentProgramAddressRegs = 0; /* and these are?? */
+       ctx->_MaintainTexEnvProgram = GL_TRUE;
+#endif
 
+       driInitExtensions(ctx, card_extensions, GL_TRUE);
+       
        radeonInitSpanFuncs(ctx);
        r300InitCmdBuf(r300);
        r300InitState(r300);
+
 #if 0
        /* plug in a few more device driver functions */
        /* XXX these should really go right after _mesa_init_driver_functions() */
@@ -275,10 +430,11 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
 
        tcl_mode = driQueryOptioni(&r300->radeon.optionCache, "tcl_mode");
-       if (1 ||
-           driQueryOptionb(&r300->radeon.optionCache, "no_rast")) {
+       if (driQueryOptionb(&r300->radeon.optionCache, "no_rast")) {
                fprintf(stderr, "disabling 3D acceleration\n");
+#if R200_MERGED
                FALLBACK(&r300->radeon, RADEON_FALLBACK_DISABLE, 1);
+#endif
        }
        if (tcl_mode == DRI_CONF_TCL_SW ||
            !(r300->radeon.radeonScreen->chipset & RADEON_CHIPSET_TCL)) {
@@ -300,10 +456,14 @@ void r300DestroyContext(__DRIcontextPrivate * driContextPriv)
        r300ContextPtr r300 = (r300ContextPtr) driContextPriv->driverPrivate;
        radeonContextPtr current = ctx ? RADEON_CONTEXT(ctx) : NULL;
 
+       if (RADEON_DEBUG & DEBUG_DRI) {
+               fprintf(stderr, "Destroying context !\n");
+       }
+
        /* check if we're deleting the currently bound context */
        if (&r300->radeon == current) {
                radeonFlush(r300->radeon.glCtx);
-               _mesa_make_current2(NULL, NULL, NULL);
+               _mesa_make_current(NULL, NULL, NULL);
        }
 
        /* Free r300 context resources */