VBOs.
authorAapo Tahkola <aet@rasterburn.org>
Wed, 11 May 2005 17:28:13 +0000 (17:28 +0000)
committerAapo Tahkola <aet@rasterburn.org>
Wed, 11 May 2005 17:28:13 +0000 (17:28 +0000)
src/mesa/drivers/dri/r300/r300_context.c
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_ioctl.c
src/mesa/drivers/dri/r300/r300_maos.c
src/mesa/drivers/dri/r300/r300_render.c
src/mesa/drivers/dri/r300/r300_shader.c
src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/r300/r300_texprog.c

index 3d5ec76b1aba70983b1e7dce32c7f066bc361e04..a1dff1177da4f1b8792a6300ce66fdb3c7e1d679 100644 (file)
@@ -140,6 +140,55 @@ static const struct tnl_pipeline_stage *r300_pipeline[] = {
        0,
 };
 
+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;
+
+       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");
+               _mesa_buffer_data(ctx, target, size, data, usage, obj);
+               return ;
+       }
+       obj->Data = ((char *)rmesa->radeon.radeonScreen->gartTextures.map) + offset;
+       memcpy(obj->Data, data, size);
+       obj->Size = size;
+       obj->Usage = usage;
+#if 0
+       fprintf(stderr, "allocated %d bytes at %p, offset=%d\n", size, obj->Data, offset);
+#endif
+}
+
+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.
  */
 GLboolean r300CreateContext(const __GLcontextModes * glVisual,
@@ -177,6 +226,10 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        r300InitStateFuncs(&functions);
        r300InitTextureFuncs(&functions);
        r300InitShaderFuncs(&functions);
+       if(hw_tcl_on){
+               functions.BufferData = r300BufferData;
+               functions.DeleteBuffer = r300DeleteBuffer;
+       }
        
        if (!radeonInitContext(&r300->radeon, &functions,
                               glVisual, driContextPriv, sharedContextPrivate)) {
index fa6dbbf8af1f07f1686563182d75648d8c66a79c..16cf3b9f2c1fff3dc42594898928e49f9ea074d4 100644 (file)
@@ -568,7 +568,7 @@ struct r300_vertex_shader_state {
        
 extern int hw_tcl_on;
 
-#define CURRENT_VERTEX_SHADER(ctx) (ctx->VertexProgram._Enabled ? ctx->VertexProgram.Current : &ctx->_TnlProgram)
+#define CURRENT_VERTEX_SHADER(ctx) (ctx->VertexProgram._Enabled ? ctx->VertexProgram.Current : ctx->_TnlProgram)
 
 //#define TMU_ENABLED(ctx, unit) (hw_tcl_on ? ctx->Texture.Unit[unit]._ReallyEnabled && (OutputsWritten & (1<<(VERT_RESULT_TEX0+(unit)))) : \
 //     (r300->state.render_inputs & (_TNL_BIT_TEX0<<(unit))))
index 7113deb71cc282d9f1620bec483c19e11975644e..56e7b3e2afd94fbf3e1adf2f3cf342736a5b9fd4 100644 (file)
@@ -582,7 +582,7 @@ GLuint r300GartOffsetFromVirtual(r300ContextPtr rmesa, const GLvoid * pointer)
        int offset =
            (char *)pointer - (char *)rmesa->radeon.radeonScreen->gartTextures.map;
 
-       fprintf(stderr, "offset=%08x\n", offset);
+       //fprintf(stderr, "offset=%08x\n", offset);
 
        if (offset < 0 || offset > rmesa->radeon.radeonScreen->gartTextures.size)
                return ~0;
index 5bbd5986d48786e2c7d20322af06d16c3920ed33..938978d68a1ac4755195de59b39a4d0a66bd8b6b 100644 (file)
@@ -173,6 +173,20 @@ static void emit_vector(GLcontext * ctx,
                fprintf(stderr, "%s count %d size %d stride %d\n",
                        __FUNCTION__, count, size, stride);
 
+       if(r300IsGartMemory(rmesa, data, size*stride)){
+               rvb->address = rmesa->radeon.radeonScreen->gartTextures.map;
+               rvb->start = data - rvb->address;
+               rvb->aos_offset = r300GartOffsetFromVirtual(rmesa, data);
+               
+               if(stride == 0)
+                       rvb->aos_stride = 0;
+               else
+                       rvb->aos_stride = stride / 4;
+               
+               rvb->aos_size = size;
+               return;
+       }
+       
        /* Gets triggered when playing with future_hw_tcl_on ...*/
        //assert(!rvb->buf);
 
@@ -188,7 +202,7 @@ static void emit_vector(GLcontext * ctx,
                rvb->aos_stride = size;
                rvb->aos_size   = size;
        }
-
+       
        /* Emit the data
         */
        switch (size) {
@@ -219,6 +233,13 @@ void r300EmitElts(GLcontext * ctx, GLuint *elts, unsigned long n_elts)
        unsigned short int *out;
        int i;
        
+       if(r300IsGartMemory(rmesa, elts, n_elts*sizeof(unsigned short int))){
+               rvb->address = rmesa->radeon.radeonScreen->gartTextures.map;
+               rvb->start = (char *)elts - rvb->address;
+               rvb->aos_offset = rmesa->radeon.radeonScreen->gart_texture_offset + rvb->start;
+               return ;
+       }
+       
        r300AllocDmaRegion(rmesa, rvb, n_elts*sizeof(unsigned short int), 2);
        
        out = (unsigned short int *)(rvb->address + rvb->start);
@@ -242,7 +263,6 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd)
        GLuint aa_vap_reg = 0; /* VAP register assignment */
        GLuint i;
        GLuint inputs = 0;
-       GLuint InputsRead = CURRENT_VERTEX_SHADER(ctx)->InputsRead;
        
 
 #define CONFIGURE_AOS(r, f, v, sz, cn) { \
@@ -272,6 +292,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd)
 }
 
        if (hw_tcl_on) {
+               GLuint InputsRead = CURRENT_VERTEX_SHADER(ctx)->InputsRead;
                struct r300_vertex_program *prog=(struct r300_vertex_program *)CURRENT_VERTEX_SHADER(ctx);
                if (InputsRead & (1<<VERT_ATTRIB_POS)) {
                        inputs |= _TNL_BIT_POS;
index 4a827ace7671ff704acad6bc4c84f1372ff3d99e..ac9d1550264831f51d789718127f8db8a3f49085 100644 (file)
@@ -545,7 +545,7 @@ static GLboolean r300_run_vb_render(GLcontext *ctx,
                fprintf(stderr, "%s\n", __FUNCTION__);
        
 
-       r300ReleaseArrays(ctx);
+       r300ReleaseArrays(ctx);
        r300EmitArrays(ctx, GL_FALSE);
        //dump_inputs(ctx, rmesa->state.render_inputs);
 
@@ -557,6 +557,9 @@ static GLboolean r300_run_vb_render(GLcontext *ctx,
        reg_start(0x4f18,0);
        e32(0x00000003);
        r300EmitState(rmesa);
+       
+       if(hw_tcl_on) /* FIXME */
+               r300FlushCmdBuf(rmesa, __FUNCTION__);
 
        rmesa->state.Elts = VB->Elts;
 
@@ -748,6 +751,8 @@ static GLboolean r300_run_tcl_render(GLcontext *ctx,
    TNLcontext *tnl = TNL_CONTEXT(ctx);
    struct vertex_buffer *VB = &tnl->vb;
    GLuint i;
+   struct r300_vertex_program *vp;
+   
        hw_tcl_on=future_hw_tcl_on;
    
        if (RADEON_DEBUG & DEBUG_PRIMS)
@@ -756,13 +761,16 @@ static GLboolean r300_run_tcl_render(GLcontext *ctx,
                return GL_TRUE;
        if(ctx->VertexProgram._Enabled == GL_FALSE){
                _tnl_UpdateFixedFunctionProgram(ctx);
-               r300ProgramStringNotify(ctx, GL_VERTEX_PROGRAM_ARB, &ctx->_TnlProgram);
-               r300_setup_textures(ctx);
-               r300_setup_rs_unit(ctx);
-
-               r300SetupVertexShader(rmesa);
-               r300SetupPixelShader(rmesa);
        }
+       vp = CURRENT_VERTEX_SHADER(ctx);
+       if(vp->translated == GL_FALSE)
+               translate_vertex_shader(vp);
+               
+       r300_setup_textures(ctx);
+       r300_setup_rs_unit(ctx);
+
+       r300SetupVertexShader(rmesa);
+       r300SetupPixelShader(rmesa);
 
        return r300_run_vb_render(ctx, stage);
 }
index c3c89e0215d3fa18951e3b99ac8f24b28df94947..c1f5914aad180d027aeec29bd98aa160f9cecf67 100644 (file)
@@ -21,11 +21,6 @@ static void r300BindProgram(GLcontext *ctx, GLenum target, struct program *prog)
        }
 }
 
-/* Mesa doesnt seem to have prototype for this */
-struct program *
-_mesa_init_ati_fragment_shader( GLcontext *ctx, struct ati_fragment_shader *prog,
-                           GLenum target, GLuint id);
-
 static struct program *r300NewProgram(GLcontext *ctx, GLenum target, GLuint id)
 {
        struct r300_vertex_program *vp;
@@ -72,8 +67,8 @@ void r300ProgramStringNotify(GLcontext *ctx, GLenum target,
                
        switch(target) {
        case GL_VERTEX_PROGRAM_ARB:
-               vp->translated=GL_FALSE;
-               translate_vertex_shader(vp);
+               /*vp->translated=GL_FALSE;
+               translate_vertex_shader(vp);*/
                //debug_vp(ctx, vp);
        break;
        
index 64b8da1f5c07b0c15effed71873cb807fa056ffb..804e6e666efe15a88260f4903fb93f5284e08a35 100644 (file)
@@ -1371,7 +1371,10 @@ void r300_setup_textures(GLcontext *ctx)
        r300ContextPtr r300 = R300_CONTEXT(ctx);
        int max_texture_unit=-1; /* -1 translates into no setup costs for fields */
        struct gl_texture_unit *texUnit;
-       GLuint OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
+       GLuint OutputsWritten;
+       
+       if(hw_tcl_on)
+               OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
 
        R300_STATECHANGE(r300, txe);
        R300_STATECHANGE(r300, tex.filter);
@@ -1465,7 +1468,10 @@ void r300_setup_rs_unit(GLcontext *ctx)
                0x00,
                0x00
        };
-       GLuint OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
+       GLuint OutputsWritten;
+       
+       if(hw_tcl_on)
+               OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
        
        /* This needs to be rewritten - it is a hack at best */
 
@@ -2126,12 +2132,14 @@ void r300ResetHwState(r300ContextPtr r300)
        r300UpdateTextureState(ctx);
 
 //     r300_setup_routing(ctx, GL_TRUE);
-       r300EmitArrays(ctx, GL_TRUE); /* Just do the routing */
-       r300_setup_textures(ctx);
-       r300_setup_rs_unit(ctx);
+       if(hw_tcl_on == GL_FALSE){
+               r300EmitArrays(ctx, GL_TRUE); /* Just do the routing */
+               r300_setup_textures(ctx);
+               r300_setup_rs_unit(ctx);
 
-       r300SetupVertexShader(r300);
-       r300SetupPixelShader(r300);
+               r300SetupVertexShader(r300);
+               r300SetupPixelShader(r300);
+       }
 
        r300_set_blend_state(ctx);
 
index f90c4bacb886d7115beb7510eced0fd485641e9d..4f92d9094b7e4db5f0d171b42d43d226e55039e6 100644 (file)
@@ -223,7 +223,10 @@ void r300GenerateTextureFragmentShader(r300ContextPtr r300)
        struct r300_pixel_shader_program *p = &ps->program;
        GLcontext *ctx = r300->radeon.glCtx;
        int i, tc_reg;
-       GLuint OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
+       GLuint OutputsWritten;
+       
+       if(hw_tcl_on)
+               OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
 
        p->tex.length = 0;
        p->alu.length = 0;