diff options
author | Thomas White <taw@bitwiz.org.uk> | 2009-10-16 10:41:46 +0200 |
---|---|---|
committer | Martin Jansa <Martin.Jansa@gmail.com> | 2010-02-18 15:39:26 +0100 |
commit | 03aea2f5130b0392e37d7dfbb2d02e8e9c56fdd5 (patch) | |
tree | 29b182a650ecb7d295641455fa32ead88b13c30d /src | |
parent | 443678151543b7d28e5c7a6d19481b795a4e78fa (diff) |
Ready for vertex submission to hardware
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/drivers/dri/glamo/glamo_context.h | 22 | ||||
-rw-r--r-- | src/mesa/drivers/dri/glamo/glamo_regs.h | 30 | ||||
-rw-r--r-- | src/mesa/drivers/dri/glamo/glamo_render.c | 54 | ||||
-rw-r--r-- | src/mesa/drivers/dri/glamo/glamo_tris.c | 146 |
4 files changed, 194 insertions, 58 deletions
diff --git a/src/mesa/drivers/dri/glamo/glamo_context.h b/src/mesa/drivers/dri/glamo/glamo_context.h index d02041d205..376e0a4b67 100644 --- a/src/mesa/drivers/dri/glamo/glamo_context.h +++ b/src/mesa/drivers/dri/glamo/glamo_context.h @@ -25,10 +25,14 @@ #ifndef __GLAMO_CONTEXT_H #define __GLAMO_CONTEXT_H + #include "dri_util.h" #include "utils.h" +#include "tnl/t_vertex.h" + #include "glamo_screen.h" + typedef struct glamo_context glamoContext; typedef struct glamo_context *glamoContextPtr; @@ -56,21 +60,28 @@ struct glamo_context { /* Information about the current primitive */ struct { GLuint id; - uint32_t primitive; /**< Current hardware primitive type */ - void (*flush) (struct glamo_context *); + uint32_t primitive; /* Current hardware primitive type */ struct glamo_bo *vb_bo; uint8_t *vb; - unsigned int start_offset; /**< Byte offset of start */ - unsigned int current_offset; /**< Byte offset of next vertex */ - unsigned int count; /**< Number of vertices */ + unsigned int start_offset; /* Byte offset of start */ + unsigned int current_offset; /* Byte offset of next vertex */ + unsigned int count; /* Number of vertices */ } prim; + /* Current vertex format and attributes */ + int vertex_size; + struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX]; + uint16_t col_clear; }; #define GLAMO_CONTEXT(ctx) ((glamoContextPtr)(ctx->DriverCtx)) +#define TAG(x) glamo##x +#include "tnl_dd/t_dd_vertex.h" +#undef TAG + extern GLboolean glamoCreateContext(const __GLcontextModes *glVis, __DRIcontext *driContextPriv, void *sharedContextPrivate); @@ -87,4 +98,5 @@ extern void glamo_update_renderbuffers(__DRIcontext *context, | (((g) & 0xfc) << 3) \ | (((b) & 0xf8) >> 3)) + #endif /* __GLAMO_CONTEXT_H */ diff --git a/src/mesa/drivers/dri/glamo/glamo_regs.h b/src/mesa/drivers/dri/glamo/glamo_regs.h index ff5c754b20..d996c1636f 100644 --- a/src/mesa/drivers/dri/glamo/glamo_regs.h +++ b/src/mesa/drivers/dri/glamo/glamo_regs.h @@ -131,4 +131,34 @@ enum glamo_register_2d { GLAMO_REG_2D_ID3 = REG_2D(0x48), }; + +/* No offset this time */ +#define REG_3D(x) (x) + +enum glamo_register_3d +{ + /* Fire the engine */ + G3D_FIRE = REG_3D(0x2058), + + /* Streams of vertex/colour/normal/texcoord data */ + G3D_ACTIVE_STREAMS = REG_3D(0x1f00), + G3D_LAST_STREAM__VCOLFMT = REG_3D(0x2030), + G3D_STREAM_MODE_0 = REG_3D(0x1f10), + G3D_STREAM_BASE_0 = REG_3D(0x1f14), + G3D_STREAM_MODE_1 = REG_3D(0x1f18), + G3D_STREAM_BASE_1 = REG_3D(0x1f1c), + G3D_STREAM_MODE_2 = REG_3D(0x1f20), + G3D_STREAM_BASE_2 = REG_3D(0x1f24), + G3D_STREAM_MODE_3 = REG_3D(0x1f28), + G3D_STREAM_BASE_3 = REG_3D(0x1f2c), + G3D_STREAM_MODE_4 = REG_3D(0x1f30), + G3D_STREAM_BASE_4 = REG_3D(0x1f34), + G3D_STREAM_MODE_5 = REG_3D(0x1f38), + G3D_STREAM_BASE_5 = REG_3D(0x1f3c), + G3D_STREAM_MODE_6 = REG_3D(0x1f40), + G3D_STREAM_BASE_6 = REG_3D(0x1f44), + G3D_STREAM_MODE_7 = REG_3D(0x1f48), + G3D_STREAM_BASE_7 = REG_3D(0x1f4c), +} + #endif /* _GLAMO_REGS_H */ diff --git a/src/mesa/drivers/dri/glamo/glamo_render.c b/src/mesa/drivers/dri/glamo/glamo_render.c index 3e7aec2dc5..7908359705 100644 --- a/src/mesa/drivers/dri/glamo/glamo_render.c +++ b/src/mesa/drivers/dri/glamo/glamo_render.c @@ -73,41 +73,58 @@ * VRAM buffers. Use strip/fan hardware primitives where possible. * Try to simulate missing primitives with indexed vertices. */ -#define HAVE_POINTS 0 +#define HAVE_POINTS 1 #define HAVE_LINES 1 -#define HAVE_LINE_STRIPS 1 +#define HAVE_LINE_STRIPS 0 #define HAVE_TRIANGLES 1 -#define HAVE_TRI_STRIPS 1 -#define HAVE_TRI_STRIP_1 0 /* Has it, template can't use it yet */ -#define HAVE_TRI_FANS 1 -#define HAVE_POLYGONS 1 +#define HAVE_TRI_STRIPS 0 +#define HAVE_TRI_STRIP_1 0 +#define HAVE_TRI_FANS 0 +#define HAVE_POLYGONS 0 #define HAVE_QUADS 0 #define HAVE_QUAD_STRIPS 0 #define HAVE_ELTS 0 -static inline GLuint glamoGetVBMax(struct glamo_context *glamo) +static void glamoFlushPrim(struct glamo_context *gCtx) { - return GLAMO_VB_SIZE / (4 * 4); + printf("glamoFlushPrim: %i vertices, %i %i\n", gCtx->prim.count, + gCtx->prim.start_offset, gCtx->prim.current_offset); + + if ( gCtx->prim.vb_bo == NULL ) return; + + gCtx->prim.start_offset = gCtx->prim.current_offset; + + glamo_bo_subdata(gCtx->prim.vb_bo, 0, gCtx->prim.start_offset, + gCtx->prim.vb); + + /* Dispatch to the hardware */ + + /* Please use a new BO for the next buffer */ + gCtx->prim.vb_bo = NULL; } -static inline GLuint glamoGetCurrentMax(struct glamo_context *glamo) + +static inline GLuint glamoGetVBMax(struct glamo_context *gCtx) +{ + return GLAMO_VB_SIZE / gCtx->vertex_size; +} + + +static inline GLuint glamoGetCurrentMax(struct glamo_context *gCtx) { /* How many more vertices can be accommodated? * Each vertex takes up 4x 32-bit fixed point values */ - return (GLAMO_VB_SIZE - glamo->prim.current_offset) / (4 * 4); + return (GLAMO_VB_SIZE - gCtx->prim.current_offset) / gCtx->vertex_size; } + #define LOCAL_VARS \ struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); #define INIT(prim) -#define FLUSH() \ - do { \ - if ((gCtx)->prim.flush) \ - (gCtx)->prim.flush(gCtx); \ - } while (0) +#define FLUSH() glamoFlushPrim(gCtx) #define GET_SUBSEQUENT_VB_MAX_VERTS() glamoGetVBMax(gCtx) #define GET_CURRENT_VB_MAX_VERTS() glamoGetCurrentMax(gCtx) @@ -134,6 +151,8 @@ static GLboolean glamoRunRender(GLcontext *ctx, struct vertex_buffer *VB = &tnl->vb; GLuint i; + printf("glamoRunRender\n"); + /* Don't handle clipping */ if ( !glamo_validate_render(ctx, VB) ) { return GL_TRUE; /* Failed */ @@ -144,6 +163,7 @@ static GLboolean glamoRunRender(GLcontext *ctx, tnl->Driver.Render.Start(ctx); for ( i=0; i<VB->PrimitiveCount; i++ ) { + GLuint prim = _tnl_translate_prim(&VB->Primitive[i]); GLuint start = VB->Primitive[i].start; GLuint length = VB->Primitive[i].count; @@ -152,13 +172,11 @@ static GLboolean glamoRunRender(GLcontext *ctx, glamo_render_tab_verts[prim & PRIM_MODE_MASK](ctx, start, start + length, prim); + } tnl->Driver.Render.Finish(ctx); - if ((gCtx)->prim.flush) - (gCtx)->prim.flush(gCtx); - return GL_FALSE; /* Ok */ } diff --git a/src/mesa/drivers/dri/glamo/glamo_tris.c b/src/mesa/drivers/dri/glamo/glamo_tris.c index 22c70004b4..6c6b5a6729 100644 --- a/src/mesa/drivers/dri/glamo/glamo_tris.c +++ b/src/mesa/drivers/dri/glamo/glamo_tris.c @@ -49,6 +49,10 @@ */ +#include <glamo_bo.h> +#include <glamo_bo_gem.h> +#include <glamo_drm.h> + #include "main/mtypes.h" #include "swrast/swrast.h" #include "tnl/t_context.h" @@ -69,14 +73,19 @@ static void glamoRunPipeline(GLcontext *ctx) } -/* Unused */ static void glamoRenderStart(GLcontext *ctx) { - printf("glamoRenderStart\n"); + struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); + + /* Decide which attributes will be used */ + gCtx->vertex_attrs[0].attrib = _TNL_ATTRIB_POS; + gCtx->vertex_attrs[0].format = EMIT_4F; + + gCtx->vertex_size = _tnl_install_attrs(ctx, gCtx->vertex_attrs, 1, + NULL, 0); } -/* Unused */ static void glamoRenderFinish(GLcontext *ctx) { printf("glamoRenderFinish\n"); @@ -93,40 +102,100 @@ uint32_t *glamoGetPrimSpace(struct glamo_context *gCtx, unsigned int count) { uint32_t *addr; -#if 0 - if (intel->intelScreen->no_vbo) { - return intel_extend_inline(intel, count * intel->vertex_size); - } - - /* Check for space in the existing VB */ - if (intel->prim.vb_bo == NULL || - (intel->prim.current_offset + - count * intel->vertex_size * 4) > INTEL_VB_SIZE || - (intel->prim.count + count) >= (1 << 16)) { - /* Flush existing prim if any */ - INTEL_FIREVERTICES(intel); - - intel_finish_vb(intel); - - /* Start a new VB */ - if (intel->prim.vb == NULL) - intel->prim.vb = malloc(INTEL_VB_SIZE); - intel->prim.vb_bo = dri_bo_alloc(intel->bufmgr, "vb", - INTEL_VB_SIZE, 4); - intel->prim.start_offset = 0; - intel->prim.current_offset = 0; - } - - intel->prim.flush = intel_flush_prim; - - addr = (uint32_t *)(intel->prim.vb + intel->prim.current_offset); - intel->prim.current_offset += intel->vertex_size * 4 * count; - intel->prim.count += count; -#endif - - return addr; + printf("glamoGetPrimSpace\n"); + + /* Check for space in the existing VB */ + if (gCtx->prim.vb_bo == NULL || (gCtx->prim.current_offset + + count * gCtx->vertex_size) > GLAMO_VB_SIZE) { + + /* Not enough space, or no VB existing. Start a new one... */ + if (gCtx->prim.vb == NULL) { + printf("Allocated %i bytes\n", GLAMO_VB_SIZE); + gCtx->prim.vb = malloc(GLAMO_VB_SIZE); + } + gCtx->prim.vb_bo = glamo_bo_open(gCtx->glamoScreen->bom, 0, + GLAMO_VB_SIZE, 4, + GLAMO_GEM_DOMAIN_VRAM, 0); + gCtx->prim.start_offset = 0; + gCtx->prim.current_offset = 0; + } + + addr = (uint32_t *)(gCtx->prim.vb + gCtx->prim.current_offset); + gCtx->prim.current_offset += gCtx->vertex_size * count; + gCtx->prim.count += count; + + return addr; } + +#define COPY_DWORDS( j, vb, vertsize, v ) \ +do { \ + for ( j = 0 ; j < vertsize ; j++ ) { \ + vb[j] = ((GLuint *)v)[j]; \ + } \ + vb += vertsize; \ +} while (0) + + +static void glamo_draw_triangle(struct glamo_context *gCtx, + glamoVertexPtr v0, glamoVertexPtr v1, + glamoVertexPtr v2) +{ + GLuint *vb = glamoGetPrimSpace(gCtx, 3); + int j; + + COPY_DWORDS(j, vb, gCtx->vertex_size, v0); + COPY_DWORDS(j, vb, gCtx->vertex_size, v1); + COPY_DWORDS(j, vb, gCtx->vertex_size, v2); +} + + +static void glamo_draw_line(struct glamo_context *gCtx, + glamoVertexPtr v0, glamoVertexPtr v1) +{ + GLuint *vb = glamoGetPrimSpace(gCtx, 2); + int j; + + COPY_DWORDS(j, vb, gCtx->vertex_size, v0); + COPY_DWORDS(j, vb, gCtx->vertex_size, v1); +} + + +static void glamo_draw_point(struct glamo_context *gCtx, glamoVertexPtr v0) +{ + GLuint *vb = glamoGetPrimSpace(gCtx, 2); + int j; + + COPY_DWORDS(j, vb, gCtx->vertex_size, v0); +} + + +#define TRI( a, b, c ) \ +do { \ + glamo_draw_triangle(gCtx, a, b, c ); \ +} while (0) + + +#define QUAD( a, b, c, d ) \ +printf("Drawing a quad\n"); \ +do { \ + glamo_draw_triangle(gCtx, a, b, d); \ + glamo_draw_triangle(gCtx, b, c, d); \ +} while (0) + + +#define LINE(v0, v1) \ +do { \ + glamo_draw_line(gCtx, v0, v1); \ +} while (0) + + +#define POINT(v0) \ +do { \ + glamo_draw_point(gCtx, v0); \ +} while (0) + + #define IND (0) #define TAG(x) x #include "tnl_dd/t_dd_tritmp.h" @@ -216,6 +285,7 @@ static void init_rast_tab() void glamoInitTriFuncs(GLcontext *ctx) { TNLcontext *tnl = TNL_CONTEXT(ctx); + struct glamo_context *gCtx = GLAMO_CONTEXT(ctx); static int firsttime = 1; if (firsttime) { @@ -223,6 +293,12 @@ void glamoInitTriFuncs(GLcontext *ctx) firsttime = 0; } + gCtx->prim.start_offset = 0; + gCtx->prim.current_offset = 0; + gCtx->prim.vb_bo = NULL; + gCtx->prim.vb = NULL; + gCtx->prim.count = 0; + tnl->Driver.RunPipeline = glamoRunPipeline; tnl->Driver.Render.Start = glamoRenderStart; tnl->Driver.Render.Finish = glamoRenderFinish; |