util: convert u_simple_shaders to use tgsi_ureg

Much nicer now.
This commit is contained in:
Keith Whitwell 2009-08-13 12:46:32 +01:00
parent 8a7d1e7b76
commit 002c76cfef
1 changed files with 49 additions and 247 deletions

View File

@ -42,9 +42,7 @@
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_simple_shaders.h" #include "util/u_simple_shaders.h"
#include "tgsi/tgsi_build.h" #include "tgsi/tgsi_ureg.h"
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_parse.h"
@ -58,93 +56,31 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
const uint *semantic_indexes) const uint *semantic_indexes)
{ {
struct pipe_shader_state shader; struct ureg_program *ureg;
struct tgsi_token tokens[100]; uint i;
struct tgsi_header *header;
struct tgsi_processor *processor;
struct tgsi_full_declaration decl;
struct tgsi_full_instruction inst;
const uint procType = TGSI_PROCESSOR_VERTEX;
uint ti, i;
/* shader header ureg = ureg_create( pipe, TGSI_PROCESSOR_VERTEX );
*/ if (ureg == NULL)
*(struct tgsi_version *) &tokens[0] = tgsi_build_version(); return NULL;
header = (struct tgsi_header *) &tokens[1];
*header = tgsi_build_header();
processor = (struct tgsi_processor *) &tokens[2];
*processor = tgsi_build_processor( procType, header );
ti = 3;
/* declare inputs */
for (i = 0; i < num_attribs; i++) { for (i = 0; i < num_attribs; i++) {
decl = tgsi_default_full_declaration(); struct ureg_src src;
decl.Declaration.File = TGSI_FILE_INPUT; struct ureg_dst dst;
decl.Declaration.Semantic = 1; src = ureg_DECL_vs_input( ureg,
decl.Semantic.SemanticName = semantic_names[i]; semantic_names[i],
decl.Semantic.SemanticIndex = semantic_indexes[i]; semantic_indexes[i]);
decl.DeclarationRange.First = dst = ureg_DECL_output( ureg,
decl.DeclarationRange.Last = i; semantic_names[i],
ti += tgsi_build_full_declaration(&decl, semantic_indexes[i]);
&tokens[ti],
header, ureg_MOV( ureg, dst, src );
Elements(tokens) - ti);
} }
/* declare outputs */ ureg_END( ureg );
for (i = 0; i < num_attribs; i++) {
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_OUTPUT;
decl.Declaration.Semantic = 1;
decl.Semantic.SemanticName = semantic_names[i];
decl.Semantic.SemanticIndex = semantic_indexes[i];
decl.DeclarationRange.First =
decl.DeclarationRange.Last = i;
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
Elements(tokens) - ti);
}
/* emit MOV instructions */ return ureg_create_shader_and_destroy( ureg );
for (i = 0; i < num_attribs; i++) {
/* MOVE out[i], in[i]; */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_MOV;
inst.Instruction.NumDstRegs = 1;
inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
inst.FullDstRegisters[0].DstRegister.Index = i;
inst.Instruction.NumSrcRegs = 1;
inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
inst.FullSrcRegisters[0].SrcRegister.Index = i;
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
Elements(tokens) - ti );
}
/* END instruction */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_END;
inst.Instruction.NumDstRegs = 0;
inst.Instruction.NumSrcRegs = 0;
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
Elements(tokens) - ti );
#if 0 /*debug*/
tgsi_dump(tokens, 0);
#endif
shader.tokens = tokens;
return pipe->create_vs_state(pipe, &shader);
} }
@ -158,99 +94,29 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
void * void *
util_make_fragment_tex_shader(struct pipe_context *pipe) util_make_fragment_tex_shader(struct pipe_context *pipe)
{ {
struct pipe_shader_state shader; struct ureg_program *ureg;
struct tgsi_token tokens[100]; struct ureg_src sampler;
struct tgsi_header *header; struct ureg_src tex;
struct tgsi_processor *processor; struct ureg_dst out;
struct tgsi_full_declaration decl;
struct tgsi_full_instruction inst;
const uint procType = TGSI_PROCESSOR_FRAGMENT;
uint ti;
/* shader header ureg = ureg_create( pipe, TGSI_PROCESSOR_FRAGMENT );
*/ if (ureg == NULL)
*(struct tgsi_version *) &tokens[0] = tgsi_build_version(); return NULL;
sampler = ureg_DECL_sampler( ureg );
header = (struct tgsi_header *) &tokens[1]; tex = ureg_DECL_fs_input( ureg,
*header = tgsi_build_header(); TGSI_SEMANTIC_GENERIC, 0,
TGSI_INTERPOLATE_PERSPECTIVE );
processor = (struct tgsi_processor *) &tokens[2]; out = ureg_DECL_output( ureg,
*processor = tgsi_build_processor( procType, header ); TGSI_SEMANTIC_COLOR,
0 );
ti = 3; ureg_TEX( ureg, out, TGSI_TEXTURE_2D, tex, sampler );
ureg_END( ureg );
/* declare TEX[0] input */ return ureg_create_shader_and_destroy( ureg );
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_INPUT;
/* XXX this could be linear... */
decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
decl.Declaration.Semantic = 1;
decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC;
decl.Semantic.SemanticIndex = 0;
decl.DeclarationRange.First =
decl.DeclarationRange.Last = 0;
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
Elements(tokens) - ti);
/* declare color[0] output */
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_OUTPUT;
decl.Declaration.Semantic = 1;
decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
decl.Semantic.SemanticIndex = 0;
decl.DeclarationRange.First =
decl.DeclarationRange.Last = 0;
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
Elements(tokens) - ti);
/* declare sampler */
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_SAMPLER;
decl.DeclarationRange.First =
decl.DeclarationRange.Last = 0;
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
Elements(tokens) - ti);
/* TEX instruction */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_TEX;
inst.Instruction.NumDstRegs = 1;
inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
inst.FullDstRegisters[0].DstRegister.Index = 0;
inst.Instruction.NumSrcRegs = 2;
inst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D;
inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
inst.FullSrcRegisters[0].SrcRegister.Index = 0;
inst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER;
inst.FullSrcRegisters[1].SrcRegister.Index = 0;
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
Elements(tokens) - ti );
/* END instruction */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_END;
inst.Instruction.NumDstRegs = 0;
inst.Instruction.NumSrcRegs = 0;
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
Elements(tokens) - ti );
#if 0 /*debug*/
tgsi_dump(tokens, 0);
#endif
shader.tokens = tokens;
return pipe->create_fs_state(pipe, &shader);
} }
@ -263,87 +129,23 @@ util_make_fragment_tex_shader(struct pipe_context *pipe)
void * void *
util_make_fragment_passthrough_shader(struct pipe_context *pipe) util_make_fragment_passthrough_shader(struct pipe_context *pipe)
{ {
struct pipe_shader_state shader; struct ureg_program *ureg;
struct tgsi_token tokens[40]; struct ureg_src src;
struct tgsi_header *header; struct ureg_dst dst;
struct tgsi_processor *processor;
struct tgsi_full_declaration decl;
struct tgsi_full_instruction inst;
const uint procType = TGSI_PROCESSOR_FRAGMENT;
uint ti;
/* shader header ureg = ureg_create( pipe, TGSI_PROCESSOR_FRAGMENT );
*/ if (ureg == NULL)
*(struct tgsi_version *) &tokens[0] = tgsi_build_version(); return NULL;
header = (struct tgsi_header *) &tokens[1]; src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0,
*header = tgsi_build_header(); TGSI_INTERPOLATE_PERSPECTIVE );
processor = (struct tgsi_processor *) &tokens[2]; dst = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 );
*processor = tgsi_build_processor( procType, header );
ti = 3; ureg_MOV( ureg, dst, src );
ureg_END( ureg );
/* declare input */ return ureg_create_shader_and_destroy( ureg );
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_INPUT;
decl.Declaration.Semantic = 1;
decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
decl.Semantic.SemanticIndex = 0;
decl.DeclarationRange.First =
decl.DeclarationRange.Last = 0;
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
Elements(tokens) - ti);
/* declare output */
decl = tgsi_default_full_declaration();
decl.Declaration.File = TGSI_FILE_OUTPUT;
decl.Declaration.Semantic = 1;
decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
decl.Semantic.SemanticIndex = 0;
decl.DeclarationRange.First =
decl.DeclarationRange.Last = 0;
ti += tgsi_build_full_declaration(&decl,
&tokens[ti],
header,
Elements(tokens) - ti);
/* MOVE out[0], in[0]; */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_MOV;
inst.Instruction.NumDstRegs = 1;
inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
inst.FullDstRegisters[0].DstRegister.Index = 0;
inst.Instruction.NumSrcRegs = 1;
inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
inst.FullSrcRegisters[0].SrcRegister.Index = 0;
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
Elements(tokens) - ti );
/* END instruction */
inst = tgsi_default_full_instruction();
inst.Instruction.Opcode = TGSI_OPCODE_END;
inst.Instruction.NumDstRegs = 0;
inst.Instruction.NumSrcRegs = 0;
ti += tgsi_build_full_instruction(&inst,
&tokens[ti],
header,
Elements(tokens) - ti );
assert(ti < Elements(tokens));
#if 0 /*debug*/
tgsi_dump(tokens, 0);
#endif
shader.tokens = tokens;
return pipe->create_fs_state(pipe, &shader);
} }