summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker/st_cb_rasterpos.c
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-09-25 14:29:11 -0600
committerBrian <brian.paul@tungstengraphics.com>2007-09-25 14:29:11 -0600
commit40c543eb71368c646259afb87d5c76551f6b45b7 (patch)
tree1e0c89610cc347607580fb4044e08bb0a060739e /src/mesa/state_tracker/st_cb_rasterpos.c
parentf9ed2fdaace0d4d7f091a4423a8638945e920b0d (diff)
Translate mesa vertex/fragment programs to TGSI programs at same time to do proper linking.
Previously, programs were translated independently during validation. The problem is the translation to TGSI format, which packs shader input/outputs into continuous slots, depends on which vertex program is being paired with which fragment shader. Now, we look at the outputs of the vertex program in conjunction with the inputs of the fragment shader to be sure the attributes match up correctly. The new 'linked_program_pair' class keeps track of the associations between vertex and fragment shaders. It's also the place where the TGSI tokens are kept since they're no longer per-program state but per-linkage. Still a few loose ends, like implementing some kind of hash/lookup table for linked_program_pairs.
Diffstat (limited to 'src/mesa/state_tracker/st_cb_rasterpos.c')
-rw-r--r--src/mesa/state_tracker/st_cb_rasterpos.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index 2311bddc65..661d155e6d 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -53,9 +53,9 @@ static void
setup_vertex_attribs(GLcontext *ctx)
{
struct pipe_context *pipe = ctx->st->pipe;
-#if 0
- const uint inputAttrs = ctx->st->state.vs->inputs_read;
- uint attr;
+ const struct cso_vertex_shader *vs = ctx->st->state.vs;
+ const struct st_vertex_program *stvp = ctx->st->vp;
+ uint slot;
/* all attributes come from the default attribute buffer */
{
@@ -67,20 +67,16 @@ setup_vertex_attribs(GLcontext *ctx)
pipe->set_vertex_buffer(pipe, 0, &vbuffer);
}
- for (attr = 0; attr < 16; attr++) {
+ for (slot = 0; slot < vs->state.num_inputs; slot++) {
struct pipe_vertex_element velement;
+ const GLuint attr = stvp->index_to_input[slot];
- if (inputAttrs & (1 << attr)) {
- velement.src_offset = attr * 4 * sizeof(GLfloat);
- velement.vertex_buffer_index = 0;
- velement.dst_offset = 0;
- velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
- pipe->set_vertex_element(pipe, attr, &velement);
- }
+ velement.src_offset = attr * 4 * sizeof(GLfloat);
+ velement.vertex_buffer_index = 0;
+ velement.dst_offset = 0;
+ velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+ pipe->set_vertex_element(pipe, slot, &velement);
}
-#else
- assert(0);
-#endif
}
@@ -98,12 +94,11 @@ setup_feedback(GLcontext *ctx)
feedback.discard = 1;
feedback.num_attribs = 0;
+ /* feedback all results from vertex shader */
for (i = 0; i < vs->num_outputs; i++) {
- if (1/***(1 << i) & outputAttrs***/) {
- feedback.attrib[feedback.num_attribs] = i;
- feedback.size[feedback.num_attribs] = 4;
- feedback.num_attribs++;
- }
+ feedback.attrib[feedback.num_attribs] = i;
+ feedback.size[feedback.num_attribs] = 4;
+ feedback.num_attribs++;
}
pipe->set_feedback_state(pipe, &feedback);
@@ -261,13 +256,11 @@ update_rasterpos(GLcontext *ctx,
static void
st_RasterPos(GLcontext *ctx, const GLfloat v[4])
{
- struct pipe_context *pipe = ctx->st->pipe;
+ const struct st_context *st = ctx->st;
+ struct pipe_context *pipe = st->pipe;
float *buf_map;
struct pipe_feedback_buffer fb_buf;
- /** XXX TEMPORARILY DISABLE */
- return;
-
st_validate_state(ctx->st);
/* setup vertex buffers */
@@ -277,7 +270,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
* Load the default attribute buffer with current attribs.
*/
{
- struct pipe_buffer_handle *buf = ctx->st->default_attrib_buffer;
+ struct pipe_buffer_handle *buf = st->default_attrib_buffer;
const unsigned size = sizeof(ctx->Current.Attrib);
const void *data = ctx->Current.Attrib;
/* colors, texcoords, etc */
@@ -313,17 +306,16 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
PIPE_BUFFER_FLAG_READ);
/* extract values and update rasterpos state */
-#if 0 /* XXX update */
{
- const uint outputAttrs = ctx->st->state.vs->outputs_written;
+ const GLuint *outputMapping = st->vertex_result_to_slot;
const float *pos, *color0, *color1, *tex0;
float *buf = buf_map;
- assert(outputAttrs & (1 << TGSI_ATTRIB_POS));
+ assert(outputMapping[VERT_RESULT_HPOS] != ~0);
pos = buf;
buf += 4;
- if (outputAttrs & (1 << TGSI_ATTRIB_COLOR0)) {
+ if (outputMapping[VERT_RESULT_COL0] != ~0) {
color0 = buf;
buf += 4;
}
@@ -331,7 +323,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
color0 = ctx->Current.Attrib[VERT_ATTRIB_COLOR0];
}
- if (outputAttrs & (1 << TGSI_ATTRIB_COLOR1)) {
+ if (outputMapping[VERT_RESULT_COL1] != ~0) {
color1 = buf;
buf += 4;
}
@@ -339,16 +331,23 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
color1 = ctx->Current.Attrib[VERT_ATTRIB_COLOR1];
}
+ if (outputMapping[VERT_RESULT_TEX0] != ~0) {
+ tex0 = buf;
+ buf += 4;
+ }
+ else {
+ tex0 = ctx->Current.Attrib[VERT_ATTRIB_TEX0];
+ }
+
update_rasterpos(ctx, pos, color0, color1, tex0);
}
-#endif
/* free vertex feedback buffer */
pipe->winsys->buffer_unmap(pipe->winsys, fb_buf.buffer);
pipe->winsys->buffer_reference(pipe->winsys, &fb_buf.buffer, NULL);
/* restore pipe state */
- pipe->set_feedback_state(pipe, &ctx->st->state.feedback);
+ pipe->set_feedback_state(pipe, &st->state.feedback);
}