? depend ? of ? r300_CopyTexSubImage2D.patch ? r300_foo.patch ? server Index: Makefile =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/Makefile,v retrieving revision 1.23 diff -u -r1.23 Makefile --- Makefile 6 Apr 2006 16:48:36 -0000 1.23 +++ Makefile 29 Aug 2006 14:57:15 -0000 @@ -43,6 +43,7 @@ r300_fragprog.c \ r300_shader.c \ r300_maos.c \ + r300_meta.c \ $(EGL_SOURCES) # \ Index: r300_cmdbuf.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_cmdbuf.c,v retrieving revision 1.57 diff -u -r1.57 r300_cmdbuf.c --- r300_cmdbuf.c 27 Jul 2006 22:51:14 -0000 1.57 +++ r300_cmdbuf.c 29 Aug 2006 14:57:16 -0000 @@ -93,6 +93,27 @@ cmd.nbox = r300->radeon.numClipRects; cmd.boxes = (drm_clip_rect_t *)r300->radeon.pClipRects; } + //cmd.boxes = NULL; +#if 0 + drm_clip_rect_t all_rect; + all_rect.x1 = 0; //rand()%100; + all_rect.y1 = 0; //rand()%100; + all_rect.x2 = 252; //rand()%250; //127; + all_rect.y2 = 255; //rand()%100; //127; + + cmd.boxes = &all_rect; + cmd.nbox = 1; +#endif +#if 0 + fprintf(stderr, "flush:\n"); + for (i = 0; i < cmd.nbox; i++) + fprintf(stderr, "box %d: x1 %d, y1 %d, x2 %d, y2 %d\n", i, + cmd.boxes[i].x1, + cmd.boxes[i].y1, + cmd.boxes[i].x2, + cmd.boxes[i].y2); + fflush(stderr); +#endif ret = drmCommandWrite(r300->radeon.dri.fd, DRM_RADEON_CMDBUF, &cmd, sizeof(cmd)); Index: r300_context.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_context.c,v retrieving revision 1.58 diff -u -r1.58 r300_context.c --- r300_context.c 15 Aug 2006 16:48:06 -0000 1.58 +++ r300_context.c 29 Aug 2006 14:57:17 -0000 @@ -60,6 +60,7 @@ #include "r300_ioctl.h" #include "r300_tex.h" #include "r300_maos.h" +#include "r300_meta.h" #ifdef USER_BUFFERS #include "radeon_mm.h" @@ -370,6 +371,9 @@ } TCL_FALLBACK(r300->radeon.glCtx, RADEON_TCL_FALLBACK_TCL_DISABLE, 1); } +#ifdef R300_META + r300_meta_init(ctx); +#endif return GL_TRUE; } @@ -470,6 +474,9 @@ assert(r300); /* should never be null */ if (r300) { +#ifdef R300_META + r300_meta_uninit(ctx); +#endif GLboolean release_texture_heaps; release_texture_heaps = (r300->radeon.glCtx->Shared->RefCount == 1); Index: r300_context.h =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_context.h,v retrieving revision 1.102 diff -u -r1.102 r300_context.h --- r300_context.h 22 Aug 2006 21:54:50 -0000 1.102 +++ r300_context.h 29 Aug 2006 14:57:18 -0000 @@ -58,6 +58,7 @@ //#define OPTIMIZE_ELTS #define CB_DPATH +#define R300_META struct r300_context; typedef struct r300_context r300ContextRec; @@ -199,6 +200,9 @@ GLboolean border_fallback; GLuint tile_bits; /* hw texture tile bits used on this texture */ +#ifdef R300_META + int fake; +#endif }; struct r300_texture_env_state { @@ -588,7 +592,8 @@ extern int hw_tcl_on; -#define CURRENT_VERTEX_SHADER(ctx) (ctx->VertexProgram._Current) +//#define CURRENT_VERTEX_SHADER(ctx) (ctx->VertexProgram._Current) +#define CURRENT_VERTEX_SHADER(ctx) (R300_CONTEXT(ctx)->selected_vp) /* Should but doesnt work */ //#define CURRENT_VERTEX_SHADER(ctx) (R300_CONTEXT(ctx)->curr_vp) @@ -603,12 +608,18 @@ /* r300_vertex_shader_state and r300_vertex_program should probably be merged together someday. * Keeping them them seperate for now should ensure fixed pipeline keeps functioning properly. */ +struct r300_vertex_program_key { + GLuint InputsRead; + GLuint OutputsWritten; + GLuint passthrough; +}; + struct r300_vertex_program { - struct gl_vertex_program mesa_program; /* Must be first */ + struct r300_vertex_program *next; + struct r300_vertex_program_key key; int translated; struct r300_vertex_shader_fragment program; - struct r300_vertex_shader_fragment params; int pos_end; int num_temporaries; /* Number of temp vars used by program */ @@ -619,6 +630,12 @@ int use_ref_count; }; +struct r300_vertex_program_cont { + struct gl_vertex_program mesa_program; /* Must be first */ + struct r300_vertex_shader_fragment params; + struct r300_vertex_program *progs; +}; + #define PFS_MAX_ALU_INST 64 #define PFS_MAX_TEX_INST 64 #define PFS_MAX_TEX_INDIRECT 4 @@ -793,6 +810,7 @@ struct r300_cmdbuf cmdbuf; struct r300_state state; struct gl_vertex_program *curr_vp; + struct r300_vertex_program *selected_vp; /* Vertex buffers */ @@ -820,6 +838,7 @@ GLboolean texmicrotile; GLboolean span_dlocking; + GLboolean passthrough_vps; }; struct r300_buffer_object { @@ -849,9 +868,9 @@ extern int r300_get_num_verts(r300ContextPtr rmesa, int num_verts, int prim); -void r300_translate_vertex_shader(struct r300_vertex_program *vp); +extern void r300_select_vertex_shader(r300ContextPtr r300); extern void r300InitShaderFuncs(struct dd_function_table *functions); -extern int r300VertexProgUpdateParams(GLcontext *ctx, struct r300_vertex_program *vp, float *dst); +extern int r300VertexProgUpdateParams(GLcontext *ctx, struct r300_vertex_program_cont *vp, float *dst); extern int r300Fallback(GLcontext *ctx); extern void radeon_vb_to_rvb(r300ContextPtr rmesa, struct radeon_vertex_buffer *rvb, struct vertex_buffer *vb); Index: r300_maos.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_maos.c,v retrieving revision 1.38 diff -u -r1.38 r300_maos.c --- r300_maos.c 22 Aug 2006 22:27:32 -0000 1.38 +++ r300_maos.c 29 Aug 2006 14:57:18 -0000 @@ -407,8 +407,8 @@ if (hw_tcl_on) { struct r300_vertex_program *prog=(struct r300_vertex_program *)CURRENT_VERTEX_SHADER(ctx); inputs = prog->inputs; - InputsRead = CURRENT_VERTEX_SHADER(ctx)->Base.InputsRead; - OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; + InputsRead = CURRENT_VERTEX_SHADER(ctx)->key.InputsRead; + OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->key.OutputsWritten; } else { DECLARE_RENDERINPUTS(inputs_bitset); inputs = r300->state.sw_tcl_inputs; Index: r300_meta.c =================================================================== RCS file: r300_meta.c diff -N r300_meta.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ r300_meta.c 29 Aug 2006 14:57:19 -0000 @@ -0,0 +1,422 @@ +#include "glheader.h" +#include "state.h" +#include "imports.h" +#include "enums.h" +#include "macros.h" +#include "context.h" +#include "dd.h" +#include "simple_list.h" + +#include "hash.h" +#include "dispatch.h" +#include "bufferobj.h" +#include "vtxfmt.h" +#include "api_validate.h" +#include "state.h" + +#include "framebuffer.h" +#include "renderbuffer.h" +#include "teximage.h" +#include "drirenderbuffer.h" + +#include "r300_context.h" +#include "r300_state.h" +#include "r300_meta.h" + + +static GLcontext *r300_meta_ctx; + +static struct gl_buffer_object *obj; +static struct gl_texture_object *tex_obj; +static struct gl_framebuffer *fb_obj; + +void r300_meta_init(GLcontext *ctx) +{ + float verts[] = { -100.0, -100.0, 0.0, 1.0, + 100.0, -100.0, 0.0, 1.0, + 100.0, 100.0, 0.0, 1.0, + -100.0, 100.0, 0.0, 1.0, + + 1.0, 0.0, 0.0, 0.0, + 1.0, 0.0, 0.0, 0.0, + 1.0, 0.0, 0.0, 0.0, + 1.0, 0.0, 0.0, 0.0, + + 1.0, 0.0, + 1.0, 0.0, + 1.0, 0.0, + 1.0, 0.0 }; + r300TexObjPtr t; + driRenderbuffer *rb; + struct gl_texture_image *ti; + + r300ContextPtr r300 = R300_CONTEXT(ctx); + + fprintf(stderr, "init!\n"); + + r300_meta_ctx = _mesa_malloc(sizeof(GLcontext)); + _mesa_memcpy(r300_meta_ctx, ctx, sizeof(GLcontext)); + + obj = ctx->Driver.NewBufferObject(ctx, 65536, GL_ARRAY_BUFFER_ARB); + + ctx->Driver.BufferData(ctx, 65536, (4 + 4) * 4 * sizeof(float), verts, GL_STATIC_DRAW_ARB, obj); + + fb_obj = _mesa_new_framebuffer(ctx, 21733); + fb_obj->_ColorDrawBufferMask[0] = BUFFER_BIT_FRONT_LEFT; + + rb = driNewRenderbuffer(GL_RGBA, NULL, 4, 0, 1, r300->radeon.dri.drawable); + rb->Base.Name = 21734; + _mesa_add_renderbuffer(fb_obj, BUFFER_FRONT_LEFT, &rb->Base); + + tex_obj = ctx->Driver.NewTextureObject(ctx, 21732, GL_TEXTURE_2D); + ti = _mesa_new_texture_image(ctx); + + _mesa_init_teximage_fields(ctx, GL_TEXTURE_2D, ti, 1, 1, 1, 0, GL_RGBA8); + + _mesa_set_tex_image(tex_obj, GL_TEXTURE_2D, 0, ti); + + t = (r300TexObjPtr) tex_obj->DriverData; + t->fake = GL_TRUE; + fprintf(stderr, "tobj at %p\n", t); + + + fprintf(stderr, "new ctx %p old %p\n", r300_meta_ctx, ctx); + fprintf(stderr, "new obj allocated!\n"); + + r300_meta_ctx->Array.ArrayObj->Vertex.Size = 4; + r300_meta_ctx->Array.ArrayObj->Vertex.Type = GL_FLOAT; + r300_meta_ctx->Array.ArrayObj->Vertex.StrideB = 4 * sizeof(float); + r300_meta_ctx->Array.ArrayObj->Vertex.Ptr = NULL; + r300_meta_ctx->Array.ArrayObj->Vertex.Enabled = GL_TRUE; /* FIXME */ + r300_meta_ctx->Array.ArrayObj->Vertex.BufferObj = obj; + + r300_meta_ctx->Array.ArrayObj->Color.Size = 4; + r300_meta_ctx->Array.ArrayObj->Color.Type = GL_FLOAT; + r300_meta_ctx->Array.ArrayObj->Color.StrideB = 4 * sizeof(float); + r300_meta_ctx->Array.ArrayObj->Color.Ptr = NULL + 4 * 4 * sizeof(float); + r300_meta_ctx->Array.ArrayObj->Color.Enabled = GL_TRUE; /* FIXME */ + r300_meta_ctx->Array.ArrayObj->Color.BufferObj = obj; + + r300_meta_ctx->Array.ArrayObj->TexCoord[0].Size = 2; + r300_meta_ctx->Array.ArrayObj->TexCoord[0].Type = GL_FLOAT; + r300_meta_ctx->Array.ArrayObj->TexCoord[0].StrideB = 2 * sizeof(float); + r300_meta_ctx->Array.ArrayObj->TexCoord[0].Ptr = NULL + 8 * 4 * sizeof(float); + r300_meta_ctx->Array.ArrayObj->TexCoord[0].Enabled = GL_TRUE; /* FIXME */ + r300_meta_ctx->Array.ArrayObj->TexCoord[0].BufferObj = obj; + + r300_meta_ctx->Depth.Test = GL_TRUE; + r300_meta_ctx->Depth.Mask = GL_TRUE; + r300_meta_ctx->Depth.Func = GL_ALWAYS; +} + +void r300_meta_uninit(GLcontext *ctx) +{ + ctx->Driver.DeleteBuffer(ctx, obj); + ctx->Driver.DeleteTexture(ctx, tex_obj); +} + +static void update_state(GLcontext *ctx) +{ + r300ContextPtr r300 = R300_CONTEXT(ctx); + __DRIdrawablePrivate *dPriv = r300->radeon.dri.drawable; + + ctx->Driver.Enable(ctx, GL_DEPTH_TEST, ctx->Depth.Test); + ctx->Driver.DepthMask(ctx, ctx->Depth.Mask); + ctx->Driver.DepthFunc(ctx, ctx->Depth.Func); + + //ctx->Point._Size = dPriv->w > dPriv->h ? dPriv->w : dPriv->h; + //ctx->Driver.PointSize(ctx, ctx->Point._Size); + + ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled); + ctx->Driver.Fogfv( ctx, GL_FOG_MODE, NULL ); + ctx->Driver.Fogfv( ctx, GL_FOG_DENSITY, &ctx->Fog.Density ); + ctx->Driver.Fogfv( ctx, GL_FOG_START, &ctx->Fog.Start ); + ctx->Driver.Fogfv( ctx, GL_FOG_END, &ctx->Fog.End ); + ctx->Driver.Fogfv( ctx, GL_FOG_COLOR, ctx->Fog.Color ); + ctx->Driver.Fogfv( ctx, GL_FOG_COORDINATE_SOURCE_EXT, NULL ); + + r300ResetHwState(r300); + +} +void r300_set_drb(r300ContextPtr r300, driRenderbuffer *drb); + +static void r300_meta_set_state(GLcontext *ctx, struct gl_framebuffer *dest_fb, int state) +{ + r300ContextPtr r300 = R300_CONTEXT(ctx); + __DRIdrawablePrivate *dPriv = r300->radeon.dri.drawable; + + if (state == GL_TRUE) { + struct gl_framebuffer *fb; + + r300_meta_ctx->DrawBuffer = dest_fb; //fb_obj; //ctx->DrawBuffer; + assert(r300_meta_ctx->DrawBuffer); + fb = r300_meta_ctx->DrawBuffer; + + r300_meta_ctx->WinSysDrawBuffer = ctx->WinSysDrawBuffer; + + assert(_glapi_Context == ctx); + _glapi_Context = r300_meta_ctx; + assert(r300->radeon.glCtx == ctx); + r300->radeon.glCtx = r300_meta_ctx; + + update_state(r300_meta_ctx); + + //fprintf(stderr, "x %d, y %d, w %d, h %d\n", dPriv->x, dPriv->y, dPriv->w, dPriv->h); + +#if 0 + R300_STATECHANGE(r300, vpt); + r300->hw.vpt.cmd[R300_VPT_XSCALE] = r300PackFloat32(dPriv->w); //r300PackFloat32(100.5); + r300->hw.vpt.cmd[R300_VPT_XOFFSET] = r300PackFloat32(dPriv->x); + r300->hw.vpt.cmd[R300_VPT_YSCALE] = r300PackFloat32(dPriv->h); //r300PackFloat32(0.5); + r300->hw.vpt.cmd[R300_VPT_YOFFSET] = r300PackFloat32(dPriv->y); + r300->hw.vpt.cmd[R300_VPT_ZSCALE] = r300PackFloat32(/*0.5*/1.0); + r300->hw.vpt.cmd[R300_VPT_ZOFFSET] = r300PackFloat32(/*0.5*/0.0); + //fprintf(stderr, "vpt set!\n"); + + R300_STATECHANGE(r300, unk221C); + r300->hw.unk221C.cmd[1] = R300_221C_CLEAR; +#else + R300_STATECHANGE(r300, vpt); + r300->hw.vpt.cmd[R300_VPT_XSCALE] = r300PackFloat32(1.0); + r300->hw.vpt.cmd[R300_VPT_XOFFSET] = r300PackFloat32(/*dPriv->x*/0); + r300->hw.vpt.cmd[R300_VPT_YSCALE] = r300PackFloat32(1.0); + r300->hw.vpt.cmd[R300_VPT_YOFFSET] = r300PackFloat32(/*dPriv->y*/0); + r300->hw.vpt.cmd[R300_VPT_ZSCALE] = r300PackFloat32(1.0); + r300->hw.vpt.cmd[R300_VPT_ZOFFSET] = r300PackFloat32(0.0); + //fprintf(stderr, "vpt set!\n"); + + R300_STATECHANGE(r300, unk221C); + r300->hw.unk221C.cmd[1] = R300_221C_CLEAR; +#endif + + r300_meta_ctx->NewState |= _NEW_ALL; + + r300->passthrough_vps = GL_TRUE; + } else { + r300->passthrough_vps = GL_FALSE; + r300->radeon.glCtx = ctx; + _glapi_Context = ctx; + + update_state(ctx); + ctx->NewState |= _NEW_ALL; + _math_matrix_viewport(&ctx->Viewport._WindowMap, + ctx->Viewport.X, ctx->Viewport.Y, + ctx->Viewport.Width, ctx->Viewport.Height, + ctx->Viewport.Near, ctx->Viewport.Far, + ctx->DrawBuffer->_DepthMaxF); + r300UpdateWindow(ctx); + } +} + +void r300_meta_bitblt(GLcontext *ctx, + struct gl_framebuffer *dest_fb, GLbitfield dest_mask, struct r300_rect *dest_rect, + struct gl_framebuffer *src_fb, GLbitfield src_mask, struct r300_rect *src_rect) +{ + r300ContextPtr r300 = R300_CONTEXT(ctx); + float *verts; + int i; + r300TexObjPtr t, prev_t; + __DRIdrawablePrivate *dPriv = r300->radeon.dri.drawable; + + driRenderbuffer *src_drb; + + for (i = BUFFER_FRONT_LEFT; i < BUFFER_FRONT_RIGHT; i++) + if (src_mask & (1 << i)) + break; + + src_drb = src_fb->Attachment[i].Renderbuffer; + + int dest_max_y = (dest_rect->y1 > dest_rect->y2) ? dest_rect->y1 : dest_rect->y2; + int src_pitch = src_drb->flippedPitch; + + verts = ctx->Driver.MapBuffer(ctx, 65536, GL_WRITE_ONLY, obj); + for (i = 0; i <= 4 * 4; i += 4) { +#ifdef POINTS + static float run = 0; + verts[i + 0] = /*0.5;*/ /*run++*/-0.4; //dPriv->w / 2.0; //0; //(rand()%10)-5; + verts[i + 1] = 0.5; //dPriv->h / 2.0; //0; //(rand()%10)-5; +#endif + verts[i + 2] = ctx->Depth.Clear; + } + verts[0 + 0] = dest_rect->x1; + verts[0 + 1] = dest_rect->y1; + + verts[4 + 0] = dest_rect->x2; + verts[4 + 1] = dest_rect->y1; + + verts[8 + 0] = dest_rect->x2; + verts[8 + 1] = dest_rect->y2; + + verts[12 + 0] = dest_rect->x1; + verts[12 + 1] = dest_rect->y2; + + verts = verts + 4 * 4; + + for (i = 0; i <= 4 * 4; i += 4) { + verts[i + 0] = 1.0; /* g */ + verts[i + 1] = 1.0; /* b */ + verts[i + 2] = 1.0; + verts[i + 3] = 1.0; /* r */ + } + + verts = verts + 4 * 4; +#if 0 + verts[0 + 0] = 0.0; + verts[0 + 1] = 0.0; + + verts[2 + 0] = 1.0; + verts[2 + 1] = 0.0; + + verts[4 + 0] = 1.0; + verts[4 + 1] = 1.0; + + verts[6 + 0] = 0.0; + verts[6 + 1] = 1.0; +#else + verts[0 + 0] = src_rect->x1 / (float)src_pitch; + verts[0 + 1] = src_rect->y1 / (float)dest_max_y; + + verts[2 + 0] = src_rect->x2 / (float)src_pitch; + verts[2 + 1] = src_rect->y1 / (float)dest_max_y; + + verts[4 + 0] = src_rect->x2 / (float)src_pitch; + verts[4 + 1] = src_rect->y2 / (float)dest_max_y; + + verts[6 + 0] = src_rect->x1 / (float)src_pitch; + verts[6 + 1] = src_rect->y2 / (float)dest_max_y; +#endif + + ctx->Driver.UnmapBuffer(ctx, 65536, obj); + +#if 1 + r300_meta_ctx->Texture.Unit[0].Enabled = TEXTURE_2D_BIT; + r300_meta_ctx->Texture.Unit[0]._Current = tex_obj; + r300_meta_ctx->Texture.Unit[0].Current2D = tex_obj; + + t = (r300TexObjPtr) tex_obj->DriverData; +#if 1 + int src_offset; + + src_offset = src_drb->flippedOffset + r300->radeon.radeonScreen->fbLocation; + //fprintf(stderr, "src offset %x, pitch %d\n", src_offset, src_drb->flippedPitch); + //fprintf(stderr, "src fb width %d, height %d\n", src_fb->Width, src_fb->Height); + + t->format = R300_EASY_TX_FORMAT(ONE, X, Y, Z, W8Z8Y8X8); + //t->format = R300_EASY_TX_FORMAT(X, Y, Z, /*W*/ONE, W8Z8Y8X8); + //t->format = 0x5300c;//R300_EASY_TX_FORMAT(W, Z, Y, X, W8Z8Y8X8); + //t->format = R300_EASY_TX_FORMAT(Y, Z, ZERO, X, W8Z8Y8X8); + + /* abgr */ + + //t->format = R300_EASY_TX_FORMAT(ONE, ZERO, ZERO, ONE, W8Z8Y8X8); + + t->offset = src_offset | R300_TXO_MACRO_TILE; + t->size = ((src_pitch - 1) << R300_TX_WIDTHMASK_SHIFT) | + ((dest_max_y/*src_fb->Height*/ - 1) << R300_TX_HEIGHTMASK_SHIFT) | + (0 << R300_TX_MAX_MIP_LEVEL_SHIFT) + /*| R300_TX_SIZE_TXPITCH_EN*/; + t->filter = 0xa12; + //t->format = 0x5300c; + t->pitch = 0x0; + t->pitch_reg = (src_pitch-1)*4; +#else + t->filter = 0xa12; + //t->unknown1 = 0x20100000; + t->size = 0x1f83f; + t->format = 0x5300c; + t->pitch = 0x0; + t->offset = 0xc3804000; +#endif + prev_t = r300->state.texture.unit[0].texobj; + r300->state.texture.unit[0].texobj = t; +#endif + + //dest_fb->_ColorDrawBufferMask[0] = BUFFER_BIT_FRONT_LEFT; + + GLbitfield prev_mask = dest_fb->_ColorDrawBufferMask[0]; + dest_fb->_ColorDrawBufferMask[0] = dest_mask; + + /*int prev_scissor = r300->radeon.state.scissor.enabled; + int prev_n_cliprect = r300->radeon.numClipRects; + + */ + + //ctx->Driver.Enable(ctx, GL_FOG, ctx->Fog.Enabled); + //ctx->Driver.Flush(ctx); + r300Flush(ctx); + + r300_meta_set_state(ctx, dest_fb, GL_TRUE); + //fprintf(stderr, "2d start!\n"); +#if 0 + drm_clip_rect_t *prev_cliprect = r300->radeon.pClipRects; + int prev_n_cliprect = r300->radeon.numClipRects; + drm_clip_rect_t cliprect[20]; // = &r300->radeon.pClipRects[0]; + cliprect[0].x1 = dest_rect->x1; + cliprect[0].y1 = dest_rect->y1; + cliprect[0].x2 = dest_rect->x2; + if (cliprect[0].x2 > 252) + cliprect[0].x2 = 252; + cliprect[0].y2 = dest_rect->y2; + r300->radeon.pClipRects = cliprect; + r300->radeon.state.scissor.enabled = 0; + r300->radeon.numClipRects = 1; +#endif + +#if 0 + if (r300->radeon.state.scissor.enabled) + fprintf(stderr, "scissor enabled!\n"); + + if (r300->radeon.numClipRects != 1) { + + for (i = 0; i < r300->radeon.numClipRects; i++) { + fprintf(stderr, "x1 %d, y1 %d, x2 %d, y2 %d\n", + r300->radeon.pClipRects[i].x1, + r300->radeon.pClipRects[i].y1, + r300->radeon.pClipRects[i].x2, + r300->radeon.pClipRects[i].y2); + + } + + fprintf(stderr, "unknown num of cliprects %d\n", r300->radeon.numClipRects); + + } else { + if (dest_rect->x1 != r300->radeon.pClipRects[0].x1) + fprintf(stderr, "x1 doesnt match\n"); + if (dest_rect->y1 != r300->radeon.pClipRects[0].y1) + fprintf(stderr, "y1 doesnt match\n"); + if (dest_rect->x2 != r300->radeon.pClipRects[0].x2) + fprintf(stderr, "x2 doesnt match\n"); + if (dest_rect->y2 != r300->radeon.pClipRects[0].y2) + fprintf(stderr, "y2 doesnt match\n"); + } +#endif + CALL_DrawArrays(GET_DISPATCH(), (GL_QUADS, 0, 4)); + r300Flush(ctx); + //fprintf(stderr, "2d end!\n"); +#if 0 + r300->radeon.pClipRects = prev_cliprect; + r300->radeon.numClipRects = prev_n_cliprect; +#endif + + //ctx->Driver.Flush(ctx); + //r300->radeon.pClipRects = NULL; + + dest_fb->_ColorDrawBufferMask[0] = prev_mask; +/*radeonContextPtr radeon = RADEON_CONTEXT(ctx); + + if (radeon->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT) + radeonSetCliprects(radeon, GL_BACK_LEFT); + else + radeonSetCliprects(radeon, GL_FRONT_LEFT); + radeonEnable(ctx, GL_SCISSOR_TEST, ctx->Scissor.Enabled);*/ + + //radeonUpdateScissor( ctx ); + r300_meta_set_state(ctx, NULL, GL_FALSE); +#if 1 + r300->state.texture.unit[0].texobj = prev_t; + r300_meta_ctx->Texture.Unit[0].Enabled = ctx->Texture.Unit[0]._ReallyEnabled = 0; + + ctx->Texture.Unit[0]._Current = prev_t; +#endif +} + Index: r300_meta.h =================================================================== RCS file: r300_meta.h diff -N r300_meta.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ r300_meta.h 29 Aug 2006 14:57:19 -0000 @@ -0,0 +1,15 @@ +#ifndef __R300_META_H__ +#define __R300_META_H__ + +struct r300_rect { + int x1, y1, x2, y2; +}; + +void r300_2d_3d_init(GLcontext *ctx); +void r300_2d_3d_copy(GLcontext *ctx, int flags, int buffer); +void r300_2d_3d_uninit(GLcontext *ctx); +void r300_2d_3d_bitblt(GLcontext *ctx, + struct gl_framebuffer *dest_fb, GLbitfield dest_mask, struct r300_rect *dest_rect, + struct gl_framebuffer *src_fb, GLbitfield src_mask, struct r300_rect *src_rect); + +#endif Index: r300_shader.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_shader.c,v retrieving revision 1.18 diff -u -r1.18 r300_shader.c --- r300_shader.c 20 Jul 2006 16:49:57 -0000 1.18 +++ r300_shader.c 29 Aug 2006 14:57:19 -0000 @@ -12,13 +12,13 @@ { r300ContextPtr rmesa = R300_CONTEXT(ctx); - struct r300_vertex_program *vp=(void *)prog; + struct r300_vertex_program_cont *vp=(void *)prog; switch(target){ case GL_VERTEX_PROGRAM_ARB: - rmesa->curr_vp = (struct gl_vertex_program *)vp; - vp->ref_count++; + //rmesa->curr_vp = (struct gl_vertex_program *)vp; + //vp->ref_count++; #if 0 if((vp->ref_count % 1500) == 0) { fprintf(stderr, "id %p, ref_count %d\n", vp, vp->ref_count); @@ -37,13 +37,13 @@ static struct gl_program * r300NewProgram(GLcontext *ctx, GLenum target, GLuint id) { - struct r300_vertex_program *vp; + struct r300_vertex_program_cont *vp; struct r300_fragment_program *fp; switch(target){ case GL_VERTEX_STATE_PROGRAM_NV: case GL_VERTEX_PROGRAM_ARB: - vp=CALLOC_STRUCT(r300_vertex_program); + vp=CALLOC_STRUCT(r300_vertex_program_cont); return _mesa_init_vertex_program(ctx, &vp->mesa_program, target, id); case GL_FRAGMENT_PROGRAM_ARB: fp=CALLOC_STRUCT(r300_fragment_program); @@ -77,13 +77,15 @@ static void r300ProgramStringNotify(GLcontext *ctx, GLenum target, struct gl_program *prog) { - struct r300_vertex_program *vp=(void *)prog; + struct r300_vertex_program_cont *vp=(void *)prog; struct r300_fragment_program *fp = (struct r300_fragment_program *) prog; switch(target) { case GL_VERTEX_PROGRAM_ARB: - vp->translated = GL_FALSE; - memset(&vp->translated, 0, sizeof(struct r300_vertex_program) - sizeof(struct gl_vertex_program)); + vp->progs = NULL; + /*vp->translated = GL_FALSE; + memset(&vp->translated, 0, sizeof(struct r300_vertex_program) - sizeof(struct + gl_vertex_program));*/ /*r300_translate_vertex_shader(vp);*/ break; case GL_FRAGMENT_PROGRAM_ARB: Index: r300_state.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_state.c,v retrieving revision 1.164 diff -u -r1.164 r300_state.c --- r300_state.c 26 Aug 2006 16:24:04 -0000 1.164 +++ r300_state.c 29 Aug 2006 14:57:22 -0000 @@ -993,6 +993,40 @@ * Tell the card where to render (offset, pitch). * Effected by glDrawBuffer, etc */ +void r300_set_drb(r300ContextPtr r300, driRenderbuffer *drb) +{ + assert(drb); + assert(drb->flippedPitch); + + R300_STATECHANGE( r300, cb ); + + //fprintf(stderr, "target rb at %p\n", drb); + + r300->hw.cb.cmd[R300_CB_OFFSET] = drb->flippedOffset + //r300->radeon.state.color.drawOffset + + r300->radeon.radeonScreen->fbLocation; + r300->hw.cb.cmd[R300_CB_PITCH] = drb->flippedPitch;//r300->radeon.state.color.drawPitch; + //fprintf(stderr, "pitch %d\n", drb->flippedPitch); + if (drb->flippedPitch == 1280) { + if (r300->radeon.radeonScreen->cpp == 4) + r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_FORMAT_ARGB8888; + else + r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_FORMAT_RGB565; + } else { + r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_FORMAT_ARGB8888;//R300_COLOR_FORMAT_ARGB8888; + } + + if (/*r300->radeon.sarea->tiling_enabled*/drb->flippedPitch == 1280) + r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_TILE_ENABLE; + + //r300->hw.cb.cmd[R300_CB_OFFSET] = 0xc0000000; + //fprintf(stderr, "dst offset %x\n", r300->hw.cb.cmd[R300_CB_OFFSET]); + //fprintf(stderr, "dst pitch %x\n", r300->hw.cb.cmd[R300_CB_PITCH]); +} + +/** + * Tell the card where to render (offset, pitch). + * Effected by glDrawBuffer, etc + */ void r300UpdateDrawBuffer(GLcontext *ctx) { @@ -1000,24 +1034,26 @@ r300ContextPtr r300 = rmesa; struct gl_framebuffer *fb = ctx->DrawBuffer; driRenderbuffer *drb; + //fprintf(stderr, "target fb at %p\n", fb); - if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) { + if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT) {//fprintf(stderr, "front\n"); /* draw to front */ - drb = (driRenderbuffer *) fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; + r300_set_drb(r300, fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + //drb = (driRenderbuffer *) fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; } - else if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT) { + else if (fb->_ColorDrawBufferMask[0] == BUFFER_BIT_BACK_LEFT) {//fprintf(stderr, "back\n"); /* draw to back */ - drb = (driRenderbuffer *) fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer; + r300_set_drb(r300, fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); + //drb = (driRenderbuffer *) fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer; } else { /* drawing to multiple buffers, or none */ return; } - assert(drb); + /*assert(drb); assert(drb->flippedPitch); - R300_STATECHANGE( rmesa, cb ); r300->hw.cb.cmd[R300_CB_OFFSET] = drb->flippedOffset + //r300->radeon.state.color.drawOffset + @@ -1030,7 +1066,7 @@ r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_FORMAT_RGB565; if (r300->radeon.sarea->tiling_enabled) - r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_TILE_ENABLE; + r300->hw.cb.cmd[R300_CB_PITCH] |= R300_COLOR_TILE_ENABLE;*/ #if 0 R200_STATECHANGE( rmesa, ctx ); @@ -1287,7 +1323,7 @@ int i; if(hw_tcl_on) - OutputsWritten.vp_outputs = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; + OutputsWritten.vp_outputs = CURRENT_VERTEX_SHADER(ctx)->key.OutputsWritten; else RENDERINPUTS_COPY( OutputsWritten.index_bitset, r300->state.render_inputs_bitset ); @@ -1612,7 +1648,7 @@ ((drm_r300_cmd_header_t*)rmesa->hw.vpp.cmd)->vpu.count = 0; R300_STATECHANGE(rmesa, vpp); - param_count = r300VertexProgUpdateParams(ctx, prog, (float *)&rmesa->hw.vpp.cmd[R300_VPP_PARAM_0]); + param_count = r300VertexProgUpdateParams(ctx, (struct r300_vertex_program_cont *)ctx->VertexProgram._Current/*prog*/, (float *)&rmesa->hw.vpp.cmd[R300_VPP_PARAM_0]); bump_vpu_count(rmesa->hw.vpp.cmd, param_count); param_count /= 4; @@ -1657,7 +1693,7 @@ ctx = rmesa->radeon.glCtx; - if (rmesa->NewGLState && hw_tcl_on) { + if (/*rmesa->NewGLState && */hw_tcl_on) { rmesa->NewGLState = 0; for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) { @@ -1671,9 +1707,10 @@ TNL_CONTEXT(ctx)->vb.AttribPtr[i] = rmesa->temp_attrib[i]; } + r300_select_vertex_shader(rmesa); vp = (struct r300_vertex_program *)CURRENT_VERTEX_SHADER(ctx); - if (vp->translated == GL_FALSE) - r300_translate_vertex_shader(vp); + /*if (vp->translated == GL_FALSE) + r300_translate_vertex_shader(vp);*/ if (vp->translated == GL_FALSE) { fprintf(stderr, "Failing back to sw-tcl\n"); hw_tcl_on = future_hw_tcl_on = 0; Index: r300_tex.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_tex.c,v retrieving revision 1.23 diff -u -r1.23 r300_tex.c --- r300_tex.c 29 Mar 2006 15:21:01 -0000 1.23 +++ r300_tex.c 29 Aug 2006 14:57:23 -0000 @@ -1109,6 +1109,64 @@ return obj; } +#include "framebuffer.h" +#include "renderbuffer.h" +#include "teximage.h" +#include "drirenderbuffer.h" + + +#include "r300_context.h" +#include "r300_state.h" +#include "r300_meta.h" + +static void r300CopyTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height ) +{ + r300ContextPtr rmesa = R300_CONTEXT(ctx); + radeonContextPtr radeon; + radeon = (radeonContextPtr) rmesa; + struct gl_texture_unit *unit; + struct gl_texture_image *ti; + struct gl_texture_object *to; + r300TexObjPtr t; + + unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; + to = unit->Current2D; + t = to->DriverData; + if (t == NULL) + return; + + struct gl_framebuffer *fb; + struct gl_framebuffer *dest_fb; + driRenderbuffer *rb; + + dest_fb = _mesa_new_framebuffer(radeon->glCtx, 65529); + dest_fb->_ColorDrawBufferMask[0] = BUFFER_BIT_FRONT_LEFT; + + rb = driNewRenderbuffer(GL_RGBA, NULL, 4, 0, 1, radeon->dri.drawable); + rb->Base.Name = 21734; + + rb->flippedOffset = t->offset - radeon->radeonScreen->fbLocation; + rb->flippedPitch = 256; + + _mesa_add_renderbuffer(dest_fb, BUFFER_FRONT_LEFT, &rb->Base); + + struct r300_rect dest_rect, src_rect; + + src_rect.x1 = xoffset; + src_rect.y1 = yoffset; + src_rect.x2 = xoffset + width; + src_rect.y2 = yoffset + height; + + dest_rect.x1 = x; + dest_rect.y1 = y; + dest_rect.x2 = x + width; + dest_rect.y2 = y + height; + + r300_meta_bitblt(ctx, dest_fb, BUFFER_BIT_FRONT_LEFT, &dest_rect, ctx->DrawBuffer, BUFFER_BIT_BACK_LEFT, &src_rect); +} void r300InitTextureFuncs(struct dd_function_table *functions) { @@ -1130,6 +1188,9 @@ #else functions->TexSubImage3D = _mesa_store_texsubimage3d; #endif +#if 1 + functions->CopyTexSubImage2D = r300CopyTexSubImage2D; +#endif functions->NewTextureObject = r300NewTextureObject; functions->BindTexture = r300BindTexture; functions->DeleteTexture = r300DeleteTexture; Index: r300_texstate.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_texstate.c,v retrieving revision 1.47 diff -u -r1.47 r300_texstate.c --- r300_texstate.c 6 Jun 2006 18:37:45 -0000 1.47 +++ r300_texstate.c 29 Aug 2006 14:57:23 -0000 @@ -547,6 +547,10 @@ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; struct gl_texture_object *tObj = texUnit->_Current; r300TexObjPtr t = (r300TexObjPtr) tObj->DriverData; +#ifdef R300_META + if (t->fake) + return GL_TRUE; +#endif /* Fallback if there's a texture border */ if (tObj->Image[0][tObj->BaseLevel]->Border > 0) Index: r300_vertexprog.c =================================================================== RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_vertexprog.c,v retrieving revision 1.62 diff -u -r1.62 r300_vertexprog.c --- r300_vertexprog.c 28 Aug 2006 19:42:41 -0000 1.62 +++ r300_vertexprog.c 29 Aug 2006 14:57:25 -0000 @@ -95,7 +95,7 @@ }; #undef OPN -int r300VertexProgUpdateParams(GLcontext *ctx, struct r300_vertex_program *vp, float *dst) +int r300VertexProgUpdateParams(GLcontext *ctx, struct r300_vertex_program_cont *vp, float *dst) { int pi; struct gl_vertex_program *mesa_vp = &vp->mesa_program; @@ -384,10 +384,8 @@ u_temp_i=VSF_MAX_FRAGMENT_TEMPS-1; \ } while (0) -void r300_translate_vertex_shader(struct r300_vertex_program *vp) +static void r300_translate_vertex_shader(struct r300_vertex_program *vp, struct prog_instruction *vpi) { - struct gl_vertex_program *mesa_vp= &vp->mesa_program; - struct prog_instruction *vpi; int i, cur_reg=0; VERTEX_SHADER_INSTRUCTION *o_inst; unsigned long operands; @@ -399,131 +397,9 @@ int u_temp_i=VSF_MAX_FRAGMENT_TEMPS-1; struct prog_src_register src[3]; - if (mesa_vp->Base.NumInstructions == 0) - return; - - if (getenv("R300_VP_SAFETY")) { - WARN_ONCE("R300_VP_SAFETY enabled.\n"); - - vpi = malloc((mesa_vp->Base.NumInstructions + VSF_MAX_FRAGMENT_TEMPS) * sizeof(struct prog_instruction)); - memset(vpi, 0, VSF_MAX_FRAGMENT_TEMPS * sizeof(struct prog_instruction)); - - for (i=0; i < VSF_MAX_FRAGMENT_TEMPS; i++) { - vpi[i].Opcode = OPCODE_MOV; - vpi[i].StringPos = 0; - vpi[i].Data = 0; - - vpi[i].DstReg.File = PROGRAM_TEMPORARY; - vpi[i].DstReg.Index = i; - vpi[i].DstReg.WriteMask = WRITEMASK_XYZW; - vpi[i].DstReg.CondMask = COND_TR; - - vpi[i].SrcReg[0].File = PROGRAM_STATE_VAR; - vpi[i].SrcReg[0].Index = 0; - vpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE); - } - - memcpy(&vpi[i], mesa_vp->Base.Instructions, mesa_vp->Base.NumInstructions * sizeof(struct prog_instruction)); - - free(mesa_vp->Base.Instructions); - - mesa_vp->Base.Instructions = vpi; - - mesa_vp->Base.NumInstructions += VSF_MAX_FRAGMENT_TEMPS; - vpi = &mesa_vp->Base.Instructions[mesa_vp->Base.NumInstructions-1]; - - assert(vpi->Opcode == OPCODE_END); - } - - if (mesa_vp->IsPositionInvariant) { - struct gl_program_parameter_list *paramList; - GLint tokens[6] = { STATE_MATRIX, STATE_MVP, 0, 0, 0, STATE_MATRIX }; - -#ifdef PREFER_DP4 - tokens[5] = STATE_MATRIX; -#else - tokens[5] = STATE_MATRIX_TRANSPOSE; -#endif - paramList = mesa_vp->Base.Parameters; - - vpi = malloc((mesa_vp->Base.NumInstructions + 4) * sizeof(struct prog_instruction)); - memset(vpi, 0, 4 * sizeof(struct prog_instruction)); - - for (i=0; i < 4; i++) { - GLint idx; - tokens[3] = tokens[4] = i; - idx = _mesa_add_state_reference(paramList, tokens); -#ifdef PREFER_DP4 - vpi[i].Opcode = OPCODE_DP4; - vpi[i].StringPos = 0; - vpi[i].Data = 0; - - vpi[i].DstReg.File = PROGRAM_OUTPUT; - vpi[i].DstReg.Index = VERT_RESULT_HPOS; - vpi[i].DstReg.WriteMask = 1 << i; - vpi[i].DstReg.CondMask = COND_TR; - - vpi[i].SrcReg[0].File = PROGRAM_STATE_VAR; - vpi[i].SrcReg[0].Index = idx; - vpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W); - - vpi[i].SrcReg[1].File = PROGRAM_INPUT; - vpi[i].SrcReg[1].Index = VERT_ATTRIB_POS; - vpi[i].SrcReg[1].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W); -#else - if (i == 0) - vpi[i].Opcode = OPCODE_MUL; - else - vpi[i].Opcode = OPCODE_MAD; - - vpi[i].StringPos = 0; - vpi[i].Data = 0; - - if (i == 3) - vpi[i].DstReg.File = PROGRAM_OUTPUT; - else - vpi[i].DstReg.File = PROGRAM_TEMPORARY; - vpi[i].DstReg.Index = 0; - vpi[i].DstReg.WriteMask = 0xf; - vpi[i].DstReg.CondMask = COND_TR; - - vpi[i].SrcReg[0].File = PROGRAM_STATE_VAR; - vpi[i].SrcReg[0].Index = idx; - vpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W); - - vpi[i].SrcReg[1].File = PROGRAM_INPUT; - vpi[i].SrcReg[1].Index = VERT_ATTRIB_POS; - vpi[i].SrcReg[1].Swizzle = MAKE_SWIZZLE4(i, i, i, i); - - if (i > 0) { - vpi[i].SrcReg[2].File = PROGRAM_TEMPORARY; - vpi[i].SrcReg[2].Index = 0; - vpi[i].SrcReg[2].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W); - } -#endif - } - - memcpy(&vpi[i], mesa_vp->Base.Instructions, mesa_vp->Base.NumInstructions * sizeof(struct prog_instruction)); - - free(mesa_vp->Base.Instructions); - - mesa_vp->Base.Instructions = vpi; - - mesa_vp->Base.NumInstructions += 4; - vpi = &mesa_vp->Base.Instructions[mesa_vp->Base.NumInstructions-1]; - - assert(vpi->Opcode == OPCODE_END); - - mesa_vp->Base.InputsRead |= (1 << VERT_ATTRIB_POS); - mesa_vp->Base.OutputsWritten |= (1 << VERT_RESULT_HPOS); - - //fprintf(stderr, "IsPositionInvariant is set!\n"); - //_mesa_print_program(&mesa_vp->Base); - } - vp->pos_end=0; /* Not supported yet */ vp->program.length=0; - vp->num_temporaries=mesa_vp->Base.NumTemporaries; + vp->num_temporaries=0; //mesa_vp->Base.NumTemporaries; for(i=0; i < VERT_ATTRIB_MAX; i++) vp->inputs[i] = -1; @@ -531,41 +407,41 @@ for(i=0; i < VERT_RESULT_MAX; i++) vp->outputs[i] = -1; - assert(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_HPOS)); + assert(vp->key.OutputsWritten & (1 << VERT_RESULT_HPOS)); /* Assign outputs */ - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_HPOS)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_HPOS)) vp->outputs[VERT_RESULT_HPOS] = cur_reg++; - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_PSIZ)) vp->outputs[VERT_RESULT_PSIZ] = cur_reg++; - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_COL0)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_COL0)) vp->outputs[VERT_RESULT_COL0] = cur_reg++; - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_COL1)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_COL1)) vp->outputs[VERT_RESULT_COL1] = cur_reg++; #if 0 /* Not supported yet */ - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_BFC0)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_BFC0)) vp->outputs[VERT_RESULT_BFC0] = cur_reg++; - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_BFC1)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_BFC1)) vp->outputs[VERT_RESULT_BFC1] = cur_reg++; - if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_FOGC)) + if(vp->key.OutputsWritten & (1 << VERT_RESULT_FOGC)) vp->outputs[VERT_RESULT_FOGC] = cur_reg++; #endif for(i=VERT_RESULT_TEX0; i <= VERT_RESULT_TEX7; i++) - if(mesa_vp->Base.OutputsWritten & (1 << i)) + if(vp->key.OutputsWritten & (1 << i)) vp->outputs[i] = cur_reg++; vp->translated = GL_TRUE; vp->native = GL_TRUE; o_inst=vp->program.body.i; - for(vpi=mesa_vp->Base.Instructions; vpi->Opcode != OPCODE_END; vpi++, o_inst++){ + for(; vpi->Opcode != OPCODE_END; vpi++, o_inst++){ FREE_TEMPS(); operands=op_operands(vpi->Opcode); @@ -987,3 +863,153 @@ #endif } +static GLuint passthrough(struct r300_vertex_program_key *wanted_key, + struct r300_vertex_program_key *curr_key, + struct prog_instruction *oi, struct prog_instruction *ip, GLint n_instr) +{ + GLint i; + + n_instr = 0; + assert(ip == NULL && n_instr == 0); + + for (i = 0; i < VERT_RESULT_MAX; i++) + if (wanted_key->passthrough & wanted_key->OutputsWritten & (1 << i)) { + curr_key->OutputsWritten |= 1 << i; + n_instr ++; + } + n_instr ++; + + memset(oi, 0, n_instr * sizeof(struct prog_instruction)); + n_instr = 0; + + for (i = 0; i < VERT_RESULT_MAX; i++) + if (wanted_key->passthrough & wanted_key->OutputsWritten & (1 << i)) { + oi[n_instr].Opcode = OPCODE_MOV; + oi[n_instr].StringPos = 0; + oi[n_instr].Data = 0; + + oi[n_instr].DstReg.File = PROGRAM_OUTPUT; + oi[n_instr].DstReg.Index = i; + oi[n_instr].DstReg.WriteMask = WRITEMASK_XYZW; + oi[n_instr].DstReg.CondMask = COND_TR; + + oi[n_instr].SrcReg[0].File = PROGRAM_INPUT; + switch (i) { + case VERT_RESULT_HPOS: + oi[n_instr].SrcReg[0].Index = VERT_ATTRIB_POS; + break; + + case VERT_RESULT_COL0: + oi[n_instr].SrcReg[0].Index = VERT_ATTRIB_COLOR0; + break; + + case VERT_RESULT_COL1: + oi[n_instr].SrcReg[0].Index = VERT_ATTRIB_COLOR1; + break; + + default: + if (i >= VERT_RESULT_TEX0 && i <= VERT_RESULT_TEX7) { + oi[n_instr].SrcReg[0].Index = VERT_ATTRIB_TEX0 + i - VERT_RESULT_TEX0; + } else { + WARN_ONCE("Unknown result\n"); + } + break; + } + + oi[n_instr].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W); + + n_instr ++; + curr_key->OutputsWritten |= 1 << i; + } + + oi[n_instr].Opcode = OPCODE_END; + n_instr++; + + curr_key->passthrough |= wanted_key->passthrough; + return n_instr; +} + +static struct r300_vertex_program *build_program(struct r300_vertex_program_key *wanted_key, + struct r300_vertex_program_key *curr_key, + struct prog_instruction *vpi) +{ + struct r300_vertex_program *vp; + struct prog_instruction temp[256]; + struct prog_instruction *temp_i; + GLint n_instr = 0; + + vp = _mesa_calloc(sizeof(*vp)); + _mesa_memcpy(&vp->key, wanted_key, sizeof(vp->key)); + + for (temp_i = vpi; temp_i->Opcode != OPCODE_END; temp_i++) + n_instr++; + + assert(n_instr); + + if (wanted_key->passthrough) { + n_instr = passthrough(wanted_key, curr_key, temp, NULL, 0); + assert(n_instr); + r300_translate_vertex_shader(vp, &temp); + return vp; + } + + assert(n_instr); + + r300_translate_vertex_shader(vp, /*&temp*/vpi); + + return vp; +} + +void r300_select_vertex_shader(r300ContextPtr r300) +{ + GLcontext *ctx = ctx = r300->radeon.glCtx; + GLuint InputsRead; + struct r300_vertex_program_key curr_key, wanted_key = { 0 }; + GLint i; + struct r300_vertex_program_cont *vpc; + struct r300_vertex_program *vp; + + vpc = (struct r300_vertex_program_cont *)ctx->VertexProgram._Current; + InputsRead = ctx->FragmentProgram._Current->Base.InputsRead; + + wanted_key.OutputsWritten |= 1 << VERT_RESULT_HPOS; + + if (InputsRead & FRAG_BIT_COL0) + wanted_key.OutputsWritten |= 1 << VERT_RESULT_COL0; + + if ((InputsRead & FRAG_BIT_COL1) /*|| + (InputsRead & FRAG_BIT_FOGC)*/) + wanted_key.OutputsWritten |= 1 << VERT_RESULT_COL1; + + for (i = 0; i < ctx->Const.MaxTextureUnits; i++) + if (InputsRead & (FRAG_BIT_TEX0 << i)) + wanted_key.OutputsWritten |= 1 << (VERT_RESULT_TEX0 + i); + + wanted_key.InputsRead = vpc->mesa_program.Base.InputsRead; + //wanted_key.OutputsWritten = vpc->mesa_program.Base.OutputsWritten; + + if (r300->passthrough_vps) + wanted_key.passthrough |= ~0; + + for (vp = vpc->progs; vp; vp = vp->next) + if (_mesa_memcmp(&vp->key, &wanted_key, sizeof(wanted_key)) == 0) { + r300->selected_vp = vp; + return ; + } + + curr_key.InputsRead = vpc->mesa_program.Base.InputsRead; + curr_key.OutputsWritten = vpc->mesa_program.Base.OutputsWritten; + curr_key.passthrough = 0; + + //_mesa_print_program(&vpc->mesa_program.Base); + + vp = build_program(&wanted_key, &curr_key, vpc->mesa_program.Base.Instructions); + vp->next = vpc->progs; + vpc->progs = vp; + + r300->selected_vp = vp; +} + + + +