From 07f73577af29d68a245283be65b12aca244c0690 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Sun, 13 Mar 2011 13:08:32 +0100 Subject: [PATCH] nvc0: support edge flags --- src/gallium/drivers/nvc0/nvc0_context.h | 3 + src/gallium/drivers/nvc0/nvc0_program.c | 8 +++ src/gallium/drivers/nvc0/nvc0_push.c | 89 +++++++++++++++++++++---- src/gallium/drivers/nvc0/nvc0_vbo.c | 2 +- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/src/gallium/drivers/nvc0/nvc0_context.h b/src/gallium/drivers/nvc0/nvc0_context.h index aac358e142b..102997e4fcb 100644 --- a/src/gallium/drivers/nvc0/nvc0_context.h +++ b/src/gallium/drivers/nvc0/nvc0_context.h @@ -136,6 +136,9 @@ struct nvc0_context { struct draw_context *draw; }; +#define NVC0_USING_EDGEFLAG(ctx) \ + ((ctx)->vertprog->vp.edgeflag < PIPE_MAX_ATTRIBS) + static INLINE struct nvc0_context * nvc0_context(struct pipe_context *pipe) { diff --git a/src/gallium/drivers/nvc0/nvc0_program.c b/src/gallium/drivers/nvc0/nvc0_program.c index 9895f2141b7..3c59213176e 100644 --- a/src/gallium/drivers/nvc0/nvc0_program.c +++ b/src/gallium/drivers/nvc0/nvc0_program.c @@ -202,6 +202,8 @@ nvc0_varying_location(unsigned sn, unsigned si) return 0x40; case TGSI_SEMANTIC_FACE: return 0x3fc; + case TGSI_SEMANTIC_EDGEFLAG: /* doesn't exist, set value like for an sreg */ + return 0xf00; /* case TGSI_SEMANTIC_CLIP_DISTANCE: return 0x2c0 + (si * 4); @@ -290,6 +292,8 @@ prog_decl(struct nvc0_translation_info *ti, ti->output_loc[i][c] = si * 4 + c; } } else { + if (sn == TGSI_SEMANTIC_EDGEFLAG) + ti->edgeflag_out = i; for (c = 0; c < 4; ++c) ti->output_loc[i][c] = nvc0_varying_location(sn, si) + c * 4; /* for TFB_VARYING_LOCS: */ @@ -427,6 +431,8 @@ nvc0_vp_gp_gen_header(struct nvc0_program *vp, struct nvc0_translation_info *ti) for (i = 0; i <= ti->scan.file_max[TGSI_FILE_OUTPUT]; ++i) { a = (ti->output_loc[i][0] - 0x40) / 4; + if (ti->output_loc[i][0] >= 0xf00) + continue; for (c = 0; c < 4; ++c, ++a) { if (!ti->output_access[i][c]) continue; @@ -670,6 +676,8 @@ nvc0_program_translate(struct nvc0_program *prog) ti->edgeflag_out = PIPE_MAX_SHADER_OUTPUTS; + prog->vp.edgeflag = PIPE_MAX_ATTRIBS; + if (prog->type == PIPE_SHADER_VERTEX && prog->vp.num_ucps) ti->append_ucp = TRUE; diff --git a/src/gallium/drivers/nvc0/nvc0_push.c b/src/gallium/drivers/nvc0/nvc0_push.c index 68544c90d29..2e9f4c10928 100644 --- a/src/gallium/drivers/nvc0/nvc0_push.c +++ b/src/gallium/drivers/nvc0/nvc0_push.c @@ -15,9 +15,6 @@ struct push_context { void *idxbuf; - float edgeflag; - int edgeflag_attr; - uint32_t vertex_words; uint32_t packet_vertex_limit; @@ -27,8 +24,56 @@ struct push_context { uint32_t prim; uint32_t restart_index; uint32_t instance_id; + + struct { + int buffer; + float value; + uint8_t *data; + unsigned offset; + unsigned stride; + } edgeflag; }; +static void +init_push_context(struct nvc0_context *nvc0, struct push_context *ctx) +{ + struct pipe_vertex_element *ve; + + ctx->chan = nvc0->screen->base.channel; + ctx->translate = nvc0->vertex->translate; + + ctx->edgeflag.value = 0.5f; + + if (NVC0_USING_EDGEFLAG(nvc0)) { + ve = &nvc0->vertex->element[nvc0->vertprog->vp.edgeflag].pipe; + + ctx->edgeflag.buffer = ve->vertex_buffer_index; + ctx->edgeflag.offset = ve->src_offset; + + ctx->packet_vertex_limit = 1; + } else { + ctx->edgeflag.buffer = -1; + ctx->edgeflag.offset = 0; + ctx->edgeflag.stride = 0; + ctx->edgeflag.data = NULL; + + ctx->packet_vertex_limit = nvc0->vertex->vtx_per_packet_max; + } + + ctx->vertex_words = nvc0->vertex->vtx_size; +} + +static INLINE void +set_edgeflag(struct push_context *ctx, unsigned vtx_id) +{ + float f = *(float *)(ctx->edgeflag.data + vtx_id * ctx->edgeflag.stride); + + if (ctx->edgeflag.value != f) { + ctx->edgeflag.value = f; + IMMED_RING(ctx->chan, RING_3D(EDGEFLAG_ENABLE), f ? 1 : 0); + } +} + static INLINE unsigned prim_restart_search_i08(uint8_t *elts, unsigned push, uint8_t index) { @@ -62,7 +107,7 @@ prim_restart_search_i32(uint32_t *elts, unsigned push, uint32_t index) static void emit_vertices_i08(struct push_context *ctx, unsigned start, unsigned count) { - uint8_t *elts = (uint8_t *)ctx->idxbuf + start; + uint8_t *restrict elts = (uint8_t *)ctx->idxbuf + start; while (count) { unsigned push = MIN2(count, ctx->packet_vertex_limit); @@ -72,6 +117,9 @@ emit_vertices_i08(struct push_context *ctx, unsigned start, unsigned count) if (ctx->primitive_restart) nr = prim_restart_search_i08(elts, push, ctx->restart_index); + if (unlikely(ctx->edgeflag.buffer >= 0) && nr) + set_edgeflag(ctx, elts[0]); + size = ctx->vertex_words * nr; BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size); @@ -97,7 +145,7 @@ emit_vertices_i08(struct push_context *ctx, unsigned start, unsigned count) static void emit_vertices_i16(struct push_context *ctx, unsigned start, unsigned count) { - uint16_t *elts = (uint16_t *)ctx->idxbuf + start; + uint16_t *restrict elts = (uint16_t *)ctx->idxbuf + start; while (count) { unsigned push = MIN2(count, ctx->packet_vertex_limit); @@ -107,6 +155,9 @@ emit_vertices_i16(struct push_context *ctx, unsigned start, unsigned count) if (ctx->primitive_restart) nr = prim_restart_search_i16(elts, push, ctx->restart_index); + if (unlikely(ctx->edgeflag.buffer >= 0) && nr) + set_edgeflag(ctx, elts[0]); + size = ctx->vertex_words * nr; BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size); @@ -132,7 +183,7 @@ emit_vertices_i16(struct push_context *ctx, unsigned start, unsigned count) static void emit_vertices_i32(struct push_context *ctx, unsigned start, unsigned count) { - uint32_t *elts = (uint32_t *)ctx->idxbuf + start; + uint32_t *restrict elts = (uint32_t *)ctx->idxbuf + start; while (count) { unsigned push = MIN2(count, ctx->packet_vertex_limit); @@ -142,6 +193,9 @@ emit_vertices_i32(struct push_context *ctx, unsigned start, unsigned count) if (ctx->primitive_restart) nr = prim_restart_search_i32(elts, push, ctx->restart_index); + if (unlikely(ctx->edgeflag.buffer >= 0) && nr) + set_edgeflag(ctx, elts[0]); + size = ctx->vertex_words * nr; BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size); @@ -171,6 +225,9 @@ emit_vertices_seq(struct push_context *ctx, unsigned start, unsigned count) unsigned push = MIN2(count, ctx->packet_vertex_limit); unsigned size = ctx->vertex_words * push; + if (unlikely(ctx->edgeflag.buffer >= 0)) + set_edgeflag(ctx, start); + BEGIN_RING_NI(ctx->chan, RING_3D(VERTEX_DATA), size); ctx->translate->run(ctx->translate, start, push, ctx->instance_id, @@ -219,10 +276,7 @@ nvc0_push_vbo(struct nvc0_context *nvc0, const struct pipe_draw_info *info) unsigned inst = info->instance_count; boolean apply_bias = info->indexed && info->index_bias; - ctx.chan = nvc0->screen->base.channel; - ctx.translate = nvc0->vertex->translate; - ctx.packet_vertex_limit = nvc0->vertex->vtx_per_packet_max; - ctx.vertex_words = nvc0->vertex->vtx_size; + init_push_context(nvc0, &ctx); for (i = 0; i < nvc0->num_vtxbufs; ++i) { uint8_t *data; @@ -236,12 +290,18 @@ nvc0_push_vbo(struct nvc0_context *nvc0, const struct pipe_draw_info *info) data += info->index_bias * vb->stride; ctx.translate->set_buffer(ctx.translate, i, data, vb->stride, ~0); + + if (unlikely(i == ctx.edgeflag.buffer)) { + ctx.edgeflag.data = data + ctx.edgeflag.offset; + ctx.edgeflag.stride = vb->stride; + } } if (info->indexed) { - ctx.idxbuf = nouveau_resource_map_offset(&nvc0->base, - nv04_resource(nvc0->idxbuf.buffer), - nvc0->idxbuf.offset, NOUVEAU_BO_RD); + ctx.idxbuf = + nouveau_resource_map_offset(&nvc0->base, + nv04_resource(nvc0->idxbuf.buffer), + nvc0->idxbuf.offset, NOUVEAU_BO_RD); if (!ctx.idxbuf) return; index_size = nvc0->idxbuf.index_size; @@ -283,6 +343,9 @@ nvc0_push_vbo(struct nvc0_context *nvc0, const struct pipe_draw_info *info) ctx.prim |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT; } + if (unlikely(ctx.edgeflag.value == 0.0f)) + IMMED_RING(ctx.chan, RING_3D(EDGEFLAG_ENABLE), 1); + if (info->indexed) nouveau_resource_unmap(nv04_resource(nvc0->idxbuf.buffer)); diff --git a/src/gallium/drivers/nvc0/nvc0_vbo.c b/src/gallium/drivers/nvc0/nvc0_vbo.c index e7e7ce7dc22..3698043029c 100644 --- a/src/gallium/drivers/nvc0/nvc0_vbo.c +++ b/src/gallium/drivers/nvc0/nvc0_vbo.c @@ -265,7 +265,7 @@ nvc0_vertex_arrays_validate(struct nvc0_context *nvc0) struct nvc0_vertex_element *ve; unsigned i; - if (unlikely(vertex->need_conversion)) { + if (unlikely(vertex->need_conversion || NVC0_USING_EDGEFLAG(nvc0))) { nvc0->vbo_fifo = ~0; nvc0->vbo_user = 0; } else { -- 2.30.2