aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-10-09 14:55:22 -0600
committerBrian <[email protected]>2007-10-09 14:55:22 -0600
commitbc139a19b00f8686caa8db7c56af2087f26e369a (patch)
tree4e598ff84144599ad115ed9abdaf8b21cc2f33b0 /src/mesa
parent342bc50c3d8765ea4ab50aa7d77df5c86c478c61 (diff)
Pack fragment program outputs to be consistant with vertex programs.
Previously, output[0] was always Z and output[1] was color. Now output[0] will be color if Z is not written. In shade_quad() use the semantic info to determine which quantity is in which output slot.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/pipe/p_state.h1
-rwxr-xr-xsrc/mesa/pipe/softpipe/sp_quad_fs.c23
-rw-r--r--src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c31
-rw-r--r--src/mesa/state_tracker/st_program.c20
4 files changed, 24 insertions, 51 deletions
diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h
index 64c5f13f232..99ec574124c 100644
--- a/src/mesa/pipe/p_state.h
+++ b/src/mesa/pipe/p_state.h
@@ -152,7 +152,6 @@ struct pipe_shader_state {
ubyte num_inputs;
ubyte num_outputs;
- uint outputs_written; /**< bitmask */
ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */
ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */
diff --git a/src/mesa/pipe/softpipe/sp_quad_fs.c b/src/mesa/pipe/softpipe/sp_quad_fs.c
index 2b0c4366bd9..b6005c6a699 100755
--- a/src/mesa/pipe/softpipe/sp_quad_fs.c
+++ b/src/mesa/pipe/softpipe/sp_quad_fs.c
@@ -78,6 +78,7 @@ shade_quad(
const float fx = (float) quad->x0;
const float fy = (float) quad->y0;
struct tgsi_exec_machine *machine = &qss->machine;
+ uint colorOut;
/* Consts does not require 16 byte alignment. */
machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT];
@@ -109,28 +110,32 @@ shade_quad(
quad->mask &= tgsi_exec_machine_run( machine );
}
- /* store result color (always in output[1]) */
- memcpy(
- quad->outputs.color,
- &machine->Outputs[1].xyzw[0].f[0],
- sizeof( quad->outputs.color ) );
-
- /* Z */
- if (qss->stage.softpipe->fs->outputs_written & 0x1) {
+ if (qss->stage.softpipe->fs->output_semantic_name[0] == TGSI_SEMANTIC_POSITION) {
/* output[0] is new Z */
uint i;
for (i = 0; i < 4; i++) {
quad->outputs.depth[i] = machine->Outputs[0].xyzw[2].f[i];
}
+ colorOut = 1;
}
else {
- /* pass input Z to output Z */
+ /* pass input Z (which was interpolated by the executor) to output Z */
uint i;
for (i = 0; i < 4; i++) {
quad->outputs.depth[i] = machine->Inputs[0].xyzw[2].f[i];
}
+ colorOut = 0;
}
+ /* store result color */
+ /* XXX need to handle multiple color outputs someday */
+ assert(qss->stage.softpipe->fs->output_semantic_name[colorOut]
+ == TGSI_SEMANTIC_COLOR);
+ memcpy(
+ quad->outputs.color,
+ &machine->Outputs[colorOut].xyzw[0].f[0],
+ sizeof( quad->outputs.color ) );
+
/* shader may cull fragments */
if( quad->mask ) {
qs->next->run( qs->next, quad );
diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
index 88de85994a9..5a1ec3553e3 100644
--- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
+++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
@@ -46,47 +46,22 @@ map_register_file(
*/
static GLuint
map_register_file_index(
- GLuint processor,
GLuint file,
GLuint index,
const GLuint inputMapping[],
const GLuint outputMapping[])
{
- GLuint mapped_index;
-
- assert(processor == TGSI_PROCESSOR_FRAGMENT
- || processor == TGSI_PROCESSOR_VERTEX);
-
switch( file ) {
case TGSI_FILE_INPUT:
/* inputs are mapped according to the user-defined map */
return inputMapping[index];
case TGSI_FILE_OUTPUT:
- if( processor == TGSI_PROCESSOR_FRAGMENT ) {
- /* fragment program outputs are hard-coded:
- * depth result -> index 0
- * color results -> index 1, 2, ...
- */
- if( index == FRAG_RESULT_DEPR ) {
- mapped_index = 0; /**TGSI_ATTRIB_POS;**/
- }
- else {
- assert( index == FRAG_RESULT_COLR );
- mapped_index = 1; /**TGSI_ATTRIB_COLOR0;**/
- }
- }
- else {
- /* vertex outputs are mapped according to the user-defined map */
- mapped_index = outputMapping[index];
- }
- break;
+ return outputMapping[index];
default:
- mapped_index = index;
+ return index;
}
-
- return mapped_index;
}
/*
@@ -166,7 +141,6 @@ compile_instruction(
fulldst = &fullinst->FullDstRegisters[0];
fulldst->DstRegister.File = map_register_file( inst->DstReg.File );
fulldst->DstRegister.Index = map_register_file_index(
- processor,
fulldst->DstRegister.File,
inst->DstReg.Index,
inputMapping,
@@ -180,7 +154,6 @@ compile_instruction(
fullsrc = &fullinst->FullSrcRegisters[i];
fullsrc->SrcRegister.File = map_register_file( inst->SrcReg[i].File );
fullsrc->SrcRegister.Index = map_register_file_index(
- processor,
fullsrc->SrcRegister.File,
inst->SrcReg[i].Index,
inputMapping,
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 86aaaad6bb3..0b14830353c 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -160,8 +160,6 @@ st_translate_vertex_program(struct st_context *st,
defaultOutputMapping[attr] = slot;
}
- vs.outputs_written |= (1 << slot);
-
/*
printf("Output %u -> slot %u\n", attr, slot);
*/
@@ -346,35 +344,33 @@ st_translate_fragment_program(struct st_context *st,
}
/*
- * Semantics for outputs
+ * Semantics and mapping for outputs
*/
{
uint numColors = 0;
GLbitfield outputsWritten = stfp->Base.Base.OutputsWritten;
- /* output[0] is always Z, but may not really be written */
- fs.output_semantic_name[fs.num_outputs] = TGSI_SEMANTIC_POSITION;
- fs.output_semantic_index[fs.num_outputs] = 0;
- outputMapping[FRAG_RESULT_DEPR] = fs.num_outputs;
- fs.num_outputs++;
-
+ /* if z is written, emit that first */
if (outputsWritten & (1 << FRAG_RESULT_DEPR)) {
- fs.outputs_written |= 0x1;
+ fs.output_semantic_name[fs.num_outputs] = TGSI_SEMANTIC_POSITION;
+ fs.output_semantic_index[fs.num_outputs] = 0;
+ outputMapping[FRAG_RESULT_DEPR] = fs.num_outputs;
+ fs.num_outputs++;
outputsWritten &= ~(1 << FRAG_RESULT_DEPR);
}
- /* color outputs begin at output [1] */
+ /* handle remaning outputs (color) */
for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
if (outputsWritten & (1 << attr)) {
switch (attr) {
case FRAG_RESULT_DEPR:
+ /* handled above */
assert(0);
break;
case FRAG_RESULT_COLR:
fs.output_semantic_name[fs.num_outputs] = TGSI_SEMANTIC_COLOR;
fs.output_semantic_index[fs.num_outputs] = numColors;
outputMapping[attr] = fs.num_outputs;
- fs.outputs_written |= (0x2 << numColors);
numColors++;
break;
default: