summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-10-10 09:44:54 -0600
committerBrian <brian.paul@tungstengraphics.com>2007-10-10 09:44:54 -0600
commit44200421e8e15e603464e4a3e9d10f46787fc737 (patch)
tree8b2dd82fe494a88a59838b6ee71803212945f3ca /src
parent013ce15595df19005996046ed4f9f42771299d14 (diff)
Merge tgsi_mesa_compile_fp_program() and tgsi_mesa_compile_vp_program() into tgsi_translate_mesa_program().
Diffstat (limited to 'src')
-rw-r--r--src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c288
-rw-r--r--src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h19
-rw-r--r--src/mesa/state_tracker/st_program.c56
3 files changed, 45 insertions, 318 deletions
diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
index 1bf3be40dd..8975b4fd57 100644
--- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
+++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
@@ -39,10 +39,10 @@ map_register_file(
/**
* Map mesa register file index to TGSI index.
* Take special care when processing input and output indices.
- * \param processor either TGSI_PROCESSOR_FRAGMENT or TGSI_PROCESSOR_VERTEX
* \param file one of TGSI_FILE_x
* \param index the mesa register file index
- * \param usage_bitmask ???
+ * \param inputMapping maps Mesa input indexes to TGSI input indexes
+ * \param outputMapping maps Mesa output indexes to TGSI output indexes
*/
static GLuint
map_register_file_index(
@@ -443,6 +443,9 @@ compile_instruction(
}
}
+/**
+ * \param usage_mask bitfield of TGSI_WRITEMASK_{XYZW} tokens
+ */
static struct tgsi_full_declaration
make_input_decl(
GLuint index,
@@ -450,7 +453,7 @@ make_input_decl(
GLuint usage_mask,
GLboolean semantic_info,
GLuint semantic_name,
- GLuint semantic_index )
+ GLbitfield semantic_index )
{
struct tgsi_full_declaration decl;
@@ -473,12 +476,15 @@ make_input_decl(
return decl;
}
+/**
+ * \param usage_mask bitfield of TGSI_WRITEMASK_{XYZW} tokens
+ */
static struct tgsi_full_declaration
make_output_decl(
GLuint index,
GLuint semantic_name,
GLuint semantic_index,
- GLuint usage_mask )
+ GLbitfield usage_mask )
{
struct tgsi_full_declaration decl;
@@ -567,10 +573,9 @@ find_temporaries(const struct gl_program *program,
* \param maxTokens size of the tokens array
*
*/
-#if 0
-static GLboolean
-tgsi_translate_program(
- uint procType,
+GLboolean
+tgsi_translate_mesa_program(
+ uint procType,
const struct gl_program *program,
GLuint numInputs,
const GLuint inputMapping[],
@@ -736,271 +741,4 @@ tgsi_translate_program(
return GL_TRUE;
}
-#endif
-
-
-
-/**
- * Convert Mesa fragment program to TGSI format.
- * \param inputMapping maps Mesa fragment program inputs to TGSI generic
- * input indexes
- * \param inputSemantic the TGSI_SEMANTIC flag for each input
- * \param interpMode the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
- * \param outputMapping maps Mesa fragment program outputs to TGSI
- * generic outputs
- *
- */
-GLboolean
-tgsi_mesa_compile_fp_program(
- const struct gl_fragment_program *program,
- GLuint numInputs,
- const GLuint inputMapping[],
- const ubyte inputSemanticName[],
- const ubyte inputSemanticIndex[],
- const GLuint interpMode[],
- GLuint numOutputs,
- const GLuint outputMapping[],
- const ubyte outputSemanticName[],
- const ubyte outputSemanticIndex[],
- struct tgsi_token *tokens,
- GLuint maxTokens )
-{
- GLuint i;
- GLuint ti; /* token index */
- struct tgsi_header *header;
- struct tgsi_processor *processor;
- struct tgsi_full_instruction fullinst;
- GLuint preamble_size = 0;
-
- *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
-
- header = (struct tgsi_header *) &tokens[1];
- *header = tgsi_build_header();
-
- processor = (struct tgsi_processor *) &tokens[2];
- *processor = tgsi_build_processor( TGSI_PROCESSOR_FRAGMENT, header );
-
- ti = 3;
-
- for (i = 0; i < numInputs; i++) {
- struct tgsi_full_declaration fulldecl;
- switch (inputSemanticName[i]) {
- case TGSI_SEMANTIC_POSITION:
- /* Fragment XY pos */
- fulldecl = make_input_decl(i,
- TGSI_INTERPOLATE_CONSTANT,
- TGSI_WRITEMASK_XY,
- GL_TRUE, TGSI_SEMANTIC_POSITION, 0 );
- ti += tgsi_build_full_declaration(
- &fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- /* Fragment ZW pos */
- fulldecl = make_input_decl(i,
- TGSI_INTERPOLATE_LINEAR,
- TGSI_WRITEMASK_ZW,
- GL_TRUE, TGSI_SEMANTIC_POSITION, 0 );
- ti += tgsi_build_full_declaration(
- &fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- break;
- default:
- fulldecl = make_input_decl(i,
- interpMode[i],
- TGSI_WRITEMASK_XYZW,
- GL_TRUE, inputSemanticName[i],
- inputSemanticIndex[i]);
- ti += tgsi_build_full_declaration(&fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- break;
- }
- }
-
-
- /*
- * Declare output attributes.
- */
- for (i = 0; i < numOutputs; i++) {
- struct tgsi_full_declaration fulldecl;
- switch (outputSemanticName[i]) {
- case TGSI_SEMANTIC_POSITION:
- fulldecl = make_output_decl(i,
- TGSI_SEMANTIC_POSITION, 0, /* Z / Depth */
- TGSI_WRITEMASK_Z );
- ti += tgsi_build_full_declaration(
- &fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- break;
- case TGSI_SEMANTIC_COLOR:
- fulldecl = make_output_decl(i,
- TGSI_SEMANTIC_COLOR, 0,
- TGSI_WRITEMASK_XYZW );
- ti += tgsi_build_full_declaration(
- &fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- break;
- default:
- abort();
- }
- }
-
- {
- GLuint tempsUsed[MAX_PROGRAM_TEMPS];
- uint numTemps = find_temporaries(&program->Base, tempsUsed);
- for (i = 0; i < numTemps; i++) {
- struct tgsi_full_declaration fulldecl;
- fulldecl = make_temp_decl(tempsUsed[i]);
- ti += tgsi_build_full_declaration(
- &fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- }
- }
-
- /*
- * Copy fragment z if the shader does not write it.
- */
-#if 0
- if( !(program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) ) {
- fullinst = tgsi_default_full_instruction();
-
- fullinst.Instruction.Opcode = TGSI_OPCODE_MOV;
- fullinst.Instruction.NumDstRegs = 1;
- fullinst.Instruction.NumSrcRegs = 1;
-
- fulldst = &fullinst.FullDstRegisters[0];
- fulldst->DstRegister.File = TGSI_FILE_OUTPUT;
- fulldst->DstRegister.Index = 0;
- fulldst->DstRegister.WriteMask = TGSI_WRITEMASK_Z;
-
- fullsrc = &fullinst.FullSrcRegisters[0];
- fullsrc->SrcRegister.File = TGSI_FILE_INPUT;
- fullsrc->SrcRegister.Index = 0;
-
- ti += tgsi_build_full_instruction(
- &fullinst,
- &tokens[ti],
- header,
- maxTokens - ti );
- preamble_size++;
- }
-#endif
-
- for( i = 0; i < program->Base.NumInstructions; i++ ) {
- compile_instruction(
- &program->Base.Instructions[i],
- &fullinst,
- inputMapping,
- outputMapping,
- preamble_size,
- TGSI_PROCESSOR_FRAGMENT );
-
- ti += tgsi_build_full_instruction(
- &fullinst,
- &tokens[ti],
- header,
- maxTokens - ti );
- }
-
- return GL_TRUE;
-}
-
-GLboolean
-tgsi_mesa_compile_vp_program(
- const struct gl_vertex_program *program,
- GLuint numInputs,
- const GLuint inputMapping[],
- const ubyte inputSemanticName[],
- const ubyte inputSemanticIndex[],
- GLuint numOutputs,
- const GLuint outputMapping[],
- const ubyte outputSemanticName[],
- const ubyte outputSemanticIndex[],
- struct tgsi_token *tokens,
- GLuint maxTokens)
-{
- GLuint i, ti;
- struct tgsi_header *header;
- struct tgsi_processor *processor;
- struct tgsi_full_instruction fullinst;
-
- *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
-
- header = (struct tgsi_header *) &tokens[1];
- *header = tgsi_build_header();
-
- processor = (struct tgsi_processor *) &tokens[2];
- *processor = tgsi_build_processor( TGSI_PROCESSOR_VERTEX, header );
-
- ti = 3;
-
- /* input decls */
- for (i = 0; i < numInputs; i++) {
- struct tgsi_full_declaration fulldecl;
- fulldecl = make_input_decl(i,
- TGSI_INTERPOLATE_ATTRIB,
- TGSI_WRITEMASK_XYZW,
- GL_FALSE, inputSemanticName[i],
- inputSemanticIndex[i]);
- ti += tgsi_build_full_declaration(&fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- }
-
- /* output decls */
- for (i = 0; i < numOutputs; i++) {
- struct tgsi_full_declaration fulldecl;
- fulldecl = make_output_decl(i,
- outputSemanticName[i],
- outputSemanticIndex[i],
- TGSI_WRITEMASK_XYZW );
- ti += tgsi_build_full_declaration(&fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- }
-
- {
- GLuint tempsUsed[MAX_PROGRAM_TEMPS];
- uint numTemps = find_temporaries(&program->Base, tempsUsed);
- for (i = 0; i < numTemps; i++) {
- struct tgsi_full_declaration fulldecl;
- fulldecl = make_temp_decl(tempsUsed[i]);
- ti += tgsi_build_full_declaration(
- &fulldecl,
- &tokens[ti],
- header,
- maxTokens - ti );
- }
- }
-
- for( i = 0; i < program->Base.NumInstructions; i++ ) {
- compile_instruction(
- &program->Base.Instructions[i],
- &fullinst,
- inputMapping,
- outputMapping,
- 0,
- TGSI_PROCESSOR_VERTEX );
-
- ti += tgsi_build_full_instruction(
- &fullinst,
- &tokens[ti],
- header,
- maxTokens - ti );
- }
-
- return GL_TRUE;
-}
diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h
index 29e8053369..13372d75fd 100644
--- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h
+++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h
@@ -8,8 +8,9 @@ extern "C" {
struct tgsi_token;
GLboolean
-tgsi_mesa_compile_fp_program(
- const struct gl_fragment_program *program,
+tgsi_translate_mesa_program(
+ uint procType,
+ const struct gl_program *program,
GLuint numInputs,
const GLuint inputMapping[],
const ubyte inputSemanticName[],
@@ -22,20 +23,6 @@ tgsi_mesa_compile_fp_program(
struct tgsi_token *tokens,
GLuint maxTokens );
-GLboolean
-tgsi_mesa_compile_vp_program(
- const struct gl_vertex_program *program,
- GLuint numInputs,
- const GLuint inputMapping[],
- const ubyte inputSemanticName[],
- const ubyte inputSemanticIndex[],
- GLuint numOutputs,
- const GLuint outputMapping[],
- const ubyte outputSemanticName[],
- const ubyte outputSemanticIndex[],
- struct tgsi_token *tokens,
- GLuint maxTokens );
-
#if defined __cplusplus
} // extern "C"
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 1c5af7b75f..5b6fa70dff 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -233,19 +233,21 @@ st_translate_vertex_program(struct st_context *st,
/* XXX: fix static allocation of tokens:
*/
- tgsi_mesa_compile_vp_program( &stvp->Base,
- /* inputs */
- vs.num_inputs,
- stvp->input_to_index,
- vs.input_semantic_name,
- vs.input_semantic_index,
- /* outputs */
- vs.num_outputs,
- outputMapping,
- vs.output_semantic_name,
+ tgsi_translate_mesa_program( TGSI_PROCESSOR_VERTEX,
+ &stvp->Base.Base,
+ /* inputs */
+ vs.num_inputs,
+ stvp->input_to_index,
+ vs.input_semantic_name,
+ vs.input_semantic_index,
+ NULL,
+ /* outputs */
+ vs.num_outputs,
+ outputMapping,
+ vs.output_semantic_name,
vs.output_semantic_index,
- /* tokenized result */
- tokensOut, maxTokens);
+ /* tokenized result */
+ tokensOut, maxTokens);
vs.tokens = tokensOut;
cso = st_cached_vs_state(st, &vs);
@@ -386,21 +388,21 @@ st_translate_fragment_program(struct st_context *st,
/* XXX: fix static allocation of tokens:
*/
- tgsi_mesa_compile_fp_program( &stfp->Base,
- /* inputs */
- fs.num_inputs,
- inputMapping,
- fs.input_semantic_name,
- fs.input_semantic_index,
- interpMode,
- /* outputs */
- fs.num_outputs,
- outputMapping,
- fs.output_semantic_name,
- fs.output_semantic_index,
- /* tokenized result */
- tokensOut, maxTokens);
-
+ tgsi_translate_mesa_program( TGSI_PROCESSOR_FRAGMENT,
+ &stfp->Base.Base,
+ /* inputs */
+ fs.num_inputs,
+ inputMapping,
+ fs.input_semantic_name,
+ fs.input_semantic_index,
+ interpMode,
+ /* outputs */
+ fs.num_outputs,
+ outputMapping,
+ fs.output_semantic_name,
+ fs.output_semantic_index,
+ /* tokenized result */
+ tokensOut, maxTokens);
fs.tokens = tokensOut;