From: Aapo Tahkola Date: Wed, 11 May 2005 17:28:13 +0000 (+0000) Subject: VBOs. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4e68f4c1faa67c072fefe040271edf2c3a334eb7;p=mesa.git VBOs. --- diff --git a/src/mesa/drivers/dri/r300/r300_context.c b/src/mesa/drivers/dri/r300/r300_context.c index 3d5ec76b1ab..a1dff1177da 100644 --- a/src/mesa/drivers/dri/r300/r300_context.c +++ b/src/mesa/drivers/dri/r300/r300_context.c @@ -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)) { diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h index fa6dbbf8af1..16cf3b9f2c1 100644 --- a/src/mesa/drivers/dri/r300/r300_context.h +++ b/src/mesa/drivers/dri/r300/r300_context.h @@ -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)))) diff --git a/src/mesa/drivers/dri/r300/r300_ioctl.c b/src/mesa/drivers/dri/r300/r300_ioctl.c index 7113deb71cc..56e7b3e2afd 100644 --- a/src/mesa/drivers/dri/r300/r300_ioctl.c +++ b/src/mesa/drivers/dri/r300/r300_ioctl.c @@ -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; diff --git a/src/mesa/drivers/dri/r300/r300_maos.c b/src/mesa/drivers/dri/r300/r300_maos.c index 5bbd5986d48..938978d68a1 100644 --- a/src/mesa/drivers/dri/r300/r300_maos.c +++ b/src/mesa/drivers/dri/r300/r300_maos.c @@ -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<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); } diff --git a/src/mesa/drivers/dri/r300/r300_shader.c b/src/mesa/drivers/dri/r300/r300_shader.c index c3c89e0215d..c1f5914aad1 100644 --- a/src/mesa/drivers/dri/r300/r300_shader.c +++ b/src/mesa/drivers/dri/r300/r300_shader.c @@ -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; diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 64b8da1f5c0..804e6e666ef 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -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); diff --git a/src/mesa/drivers/dri/r300/r300_texprog.c b/src/mesa/drivers/dri/r300/r300_texprog.c index f90c4bacb88..4f92d9094b7 100644 --- a/src/mesa/drivers/dri/r300/r300_texprog.c +++ b/src/mesa/drivers/dri/r300/r300_texprog.c @@ -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;