u_simple_shaders.c File Reference

Simple vertex/fragment shader generators. More...

Include dependency graph for u_simple_shaders.c:

Go to the source code of this file.

Functions

void * util_make_vertex_passthrough_shader (struct pipe_context *pipe, uint num_attribs, const uint *semantic_names, const uint *semantic_indexes, struct pipe_shader_state *shader)
 Make simple vertex pass-through shader.
void * util_make_fragment_tex_shader (struct pipe_context *pipe, struct pipe_shader_state *shader)
 Make simple fragment texture shader: TEX OUT[0], IN[0], SAMP[0], 2D; END;.
void * util_make_fragment_passthrough_shader (struct pipe_context *pipe, struct pipe_shader_state *shader)
 Make simple fragment color pass-through shader.
void util_free_shader (struct pipe_shader_state *shader)


Detailed Description

Simple vertex/fragment shader generators.

Author:
Brian Paul

Definition in file u_simple_shaders.c.


Function Documentation

void util_free_shader ( struct pipe_shader_state shader  ) 

Definition at line 364 of file u_simple_shaders.c.

References FREE, and pipe_shader_state::tokens.

00365 {
00366    FREE((struct tgsi_token *)shader->tokens);
00367    shader->tokens = NULL;
00368 }

void* util_make_fragment_passthrough_shader ( struct pipe_context pipe,
struct pipe_shader_state shader 
)

Make simple fragment color pass-through shader.

Definition at line 273 of file u_simple_shaders.c.

References assert, pipe_context::create_fs_state, tgsi_full_declaration::Declaration, tgsi_full_declaration::DeclarationRange, tgsi_full_dst_register::DstRegister, tgsi_src_register::File, tgsi_dst_register::File, tgsi_declaration::File, tgsi_declaration_range::First, tgsi_full_instruction::FullDstRegisters, tgsi_full_instruction::FullSrcRegisters, tgsi_src_register::Index, tgsi_dst_register::Index, tgsi_full_instruction::Instruction, tgsi_declaration_range::Last, MALLOC, tgsi_instruction::NumDstRegs, tgsi_instruction::NumSrcRegs, tgsi_instruction::Opcode, tgsi_full_declaration::Semantic, tgsi_declaration::Semantic, tgsi_declaration_semantic::SemanticIndex, tgsi_declaration_semantic::SemanticName, tgsi_full_src_register::SrcRegister, tgsi_build_full_declaration(), tgsi_build_full_instruction(), tgsi_build_header(), tgsi_build_processor(), tgsi_build_version(), tgsi_default_full_declaration(), tgsi_default_full_instruction(), tgsi_dump(), TGSI_FILE_INPUT, TGSI_FILE_OUTPUT, TGSI_OPCODE_END, TGSI_OPCODE_MOV, TGSI_PROCESSOR_FRAGMENT, TGSI_SEMANTIC_COLOR, and pipe_shader_state::tokens.

00275 {
00276    uint maxTokens = 40;
00277    struct tgsi_token *tokens;
00278    struct tgsi_header *header;
00279    struct tgsi_processor *processor;
00280    struct tgsi_full_declaration decl;
00281    struct tgsi_full_instruction inst;
00282    const uint procType = TGSI_PROCESSOR_FRAGMENT;
00283    uint ti;
00284 
00285    tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
00286 
00287    /* shader header
00288     */
00289    *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
00290 
00291    header = (struct tgsi_header *) &tokens[1];
00292    *header = tgsi_build_header();
00293 
00294    processor = (struct tgsi_processor *) &tokens[2];
00295    *processor = tgsi_build_processor( procType, header );
00296 
00297    ti = 3;
00298 
00299    /* declare input */
00300    decl = tgsi_default_full_declaration();
00301    decl.Declaration.File = TGSI_FILE_INPUT;
00302    decl.Declaration.Semantic = 1;
00303    decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
00304    decl.Semantic.SemanticIndex = 0;
00305    decl.DeclarationRange.First = 
00306       decl.DeclarationRange.Last = 0;
00307    ti += tgsi_build_full_declaration(&decl,
00308                                      &tokens[ti],
00309                                      header,
00310                                      maxTokens - ti);
00311 
00312    /* declare output */
00313    decl = tgsi_default_full_declaration();
00314    decl.Declaration.File = TGSI_FILE_OUTPUT;
00315    decl.Declaration.Semantic = 1;
00316    decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
00317    decl.Semantic.SemanticIndex = 0;
00318    decl.DeclarationRange.First = 
00319       decl.DeclarationRange.Last = 0;
00320    ti += tgsi_build_full_declaration(&decl,
00321                                      &tokens[ti],
00322                                      header,
00323                                      maxTokens - ti);
00324 
00325 
00326    /* MOVE out[0], in[0]; */
00327    inst = tgsi_default_full_instruction();
00328    inst.Instruction.Opcode = TGSI_OPCODE_MOV;
00329    inst.Instruction.NumDstRegs = 1;
00330    inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
00331    inst.FullDstRegisters[0].DstRegister.Index = 0;
00332    inst.Instruction.NumSrcRegs = 1;
00333    inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
00334    inst.FullSrcRegisters[0].SrcRegister.Index = 0;
00335    ti += tgsi_build_full_instruction(&inst,
00336                                      &tokens[ti],
00337                                      header,
00338                                      maxTokens - ti );
00339 
00340    /* END instruction */
00341    inst = tgsi_default_full_instruction();
00342    inst.Instruction.Opcode = TGSI_OPCODE_END;
00343    inst.Instruction.NumDstRegs = 0;
00344    inst.Instruction.NumSrcRegs = 0;
00345    ti += tgsi_build_full_instruction(&inst,
00346                                      &tokens[ti],
00347                                      header,
00348                                      maxTokens - ti );
00349 
00350    assert(ti < maxTokens);
00351 
00352 #if 0 /*debug*/
00353    tgsi_dump(tokens, 0);
00354 #endif
00355 
00356    shader->tokens = tokens;
00357    /*shader->num_tokens = ti;*/
00358 
00359    return pipe->create_fs_state(pipe, shader);
00360 }

void* util_make_fragment_tex_shader ( struct pipe_context pipe,
struct pipe_shader_state shader 
)

Make simple fragment texture shader: TEX OUT[0], IN[0], SAMP[0], 2D; END;.

Definition at line 164 of file u_simple_shaders.c.

References pipe_context::create_fs_state, tgsi_full_declaration::Declaration, tgsi_full_declaration::DeclarationRange, tgsi_full_dst_register::DstRegister, tgsi_src_register::File, tgsi_dst_register::File, tgsi_declaration::File, tgsi_declaration_range::First, tgsi_full_instruction::FullDstRegisters, tgsi_full_instruction::FullSrcRegisters, tgsi_src_register::Index, tgsi_dst_register::Index, tgsi_full_instruction::Instruction, tgsi_full_instruction::InstructionExtTexture, tgsi_declaration::Interpolate, tgsi_declaration_range::Last, MALLOC, tgsi_instruction::NumDstRegs, tgsi_instruction::NumSrcRegs, tgsi_instruction::Opcode, tgsi_full_declaration::Semantic, tgsi_declaration::Semantic, tgsi_declaration_semantic::SemanticIndex, tgsi_declaration_semantic::SemanticName, tgsi_full_src_register::SrcRegister, tgsi_instruction_ext_texture::Texture, tgsi_build_full_declaration(), tgsi_build_full_instruction(), tgsi_build_header(), tgsi_build_processor(), tgsi_build_version(), tgsi_default_full_declaration(), tgsi_default_full_instruction(), tgsi_dump(), TGSI_FILE_INPUT, TGSI_FILE_OUTPUT, TGSI_FILE_SAMPLER, TGSI_INTERPOLATE_PERSPECTIVE, TGSI_OPCODE_END, TGSI_OPCODE_TEX, TGSI_PROCESSOR_FRAGMENT, TGSI_SEMANTIC_COLOR, TGSI_SEMANTIC_GENERIC, TGSI_TEXTURE_2D, and pipe_shader_state::tokens.

00166 {
00167    uint maxTokens = 100;
00168    struct tgsi_token *tokens;
00169    struct tgsi_header *header;
00170    struct tgsi_processor *processor;
00171    struct tgsi_full_declaration decl;
00172    struct tgsi_full_instruction inst;
00173    const uint procType = TGSI_PROCESSOR_FRAGMENT;
00174    uint ti;
00175 
00176    tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
00177 
00178    /* shader header
00179     */
00180    *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
00181 
00182    header = (struct tgsi_header *) &tokens[1];
00183    *header = tgsi_build_header();
00184 
00185    processor = (struct tgsi_processor *) &tokens[2];
00186    *processor = tgsi_build_processor( procType, header );
00187 
00188    ti = 3;
00189 
00190    /* declare TEX[0] input */
00191    decl = tgsi_default_full_declaration();
00192    decl.Declaration.File = TGSI_FILE_INPUT;
00193    /* XXX this could be linear... */
00194    decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
00195    decl.Declaration.Semantic = 1;
00196    decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC;
00197    decl.Semantic.SemanticIndex = 0;
00198    decl.DeclarationRange.First = 
00199    decl.DeclarationRange.Last = 0;
00200    ti += tgsi_build_full_declaration(&decl,
00201                                      &tokens[ti],
00202                                      header,
00203                                      maxTokens - ti);
00204 
00205    /* declare color[0] output */
00206    decl = tgsi_default_full_declaration();
00207    decl.Declaration.File = TGSI_FILE_OUTPUT;
00208    decl.Declaration.Semantic = 1;
00209    decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
00210    decl.Semantic.SemanticIndex = 0;
00211    decl.DeclarationRange.First = 
00212    decl.DeclarationRange.Last = 0;
00213    ti += tgsi_build_full_declaration(&decl,
00214                                      &tokens[ti],
00215                                      header,
00216                                      maxTokens - ti);
00217 
00218    /* declare sampler */
00219    decl = tgsi_default_full_declaration();
00220    decl.Declaration.File = TGSI_FILE_SAMPLER;
00221    decl.DeclarationRange.First = 
00222    decl.DeclarationRange.Last = 0;
00223    ti += tgsi_build_full_declaration(&decl,
00224                                      &tokens[ti],
00225                                      header,
00226                                      maxTokens - ti);
00227 
00228    /* TEX instruction */
00229    inst = tgsi_default_full_instruction();
00230    inst.Instruction.Opcode = TGSI_OPCODE_TEX;
00231    inst.Instruction.NumDstRegs = 1;
00232    inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
00233    inst.FullDstRegisters[0].DstRegister.Index = 0;
00234    inst.Instruction.NumSrcRegs = 2;
00235    inst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D;
00236    inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
00237    inst.FullSrcRegisters[0].SrcRegister.Index = 0;
00238    inst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER;
00239    inst.FullSrcRegisters[1].SrcRegister.Index = 0;
00240    ti += tgsi_build_full_instruction(&inst,
00241                                      &tokens[ti],
00242                                      header,
00243                                      maxTokens - ti );
00244 
00245    /* END instruction */
00246    inst = tgsi_default_full_instruction();
00247    inst.Instruction.Opcode = TGSI_OPCODE_END;
00248    inst.Instruction.NumDstRegs = 0;
00249    inst.Instruction.NumSrcRegs = 0;
00250    ti += tgsi_build_full_instruction(&inst,
00251                                      &tokens[ti],
00252                                      header,
00253                                      maxTokens - ti );
00254 
00255 #if 0 /*debug*/
00256    tgsi_dump(tokens, 0);
00257 #endif
00258 
00259    shader->tokens = tokens;
00260    /*shader->num_tokens = ti;*/
00261 
00262    return pipe->create_fs_state(pipe, shader);
00263 }

void* util_make_vertex_passthrough_shader ( struct pipe_context pipe,
uint  num_attribs,
const uint semantic_names,
const uint semantic_indexes,
struct pipe_shader_state shader 
)

Make simple vertex pass-through shader.

Definition at line 56 of file u_simple_shaders.c.

References pipe_context::create_vs_state, tgsi_full_declaration::Declaration, tgsi_full_declaration::DeclarationRange, tgsi_full_dst_register::DstRegister, tgsi_src_register::File, tgsi_dst_register::File, tgsi_declaration::File, tgsi_declaration_range::First, tgsi_full_instruction::FullDstRegisters, tgsi_full_instruction::FullSrcRegisters, tgsi_src_register::Index, tgsi_dst_register::Index, tgsi_full_instruction::Instruction, tgsi_declaration_range::Last, MALLOC, tgsi_instruction::NumDstRegs, tgsi_instruction::NumSrcRegs, tgsi_instruction::Opcode, tgsi_full_declaration::Semantic, tgsi_declaration::Semantic, tgsi_declaration_semantic::SemanticIndex, tgsi_declaration_semantic::SemanticName, tgsi_full_src_register::SrcRegister, tgsi_build_full_declaration(), tgsi_build_full_instruction(), tgsi_build_header(), tgsi_build_processor(), tgsi_build_version(), tgsi_default_full_declaration(), tgsi_default_full_instruction(), tgsi_dump(), TGSI_FILE_INPUT, TGSI_FILE_OUTPUT, TGSI_OPCODE_END, TGSI_OPCODE_MOV, TGSI_PROCESSOR_VERTEX, and pipe_shader_state::tokens.

00062 {
00063    uint maxTokens = 100;
00064    struct tgsi_token *tokens;
00065    struct tgsi_header *header;
00066    struct tgsi_processor *processor;
00067    struct tgsi_full_declaration decl;
00068    struct tgsi_full_instruction inst;
00069    const uint procType = TGSI_PROCESSOR_VERTEX;
00070    uint ti, i;
00071 
00072    tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
00073 
00074    /* shader header
00075     */
00076    *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
00077 
00078    header = (struct tgsi_header *) &tokens[1];
00079    *header = tgsi_build_header();
00080 
00081    processor = (struct tgsi_processor *) &tokens[2];
00082    *processor = tgsi_build_processor( procType, header );
00083 
00084    ti = 3;
00085 
00086    /* declare inputs */
00087    for (i = 0; i < num_attribs; i++) {
00088       decl = tgsi_default_full_declaration();
00089       decl.Declaration.File = TGSI_FILE_INPUT;
00090 
00091       decl.Declaration.Semantic = 1;
00092       decl.Semantic.SemanticName = semantic_names[i];
00093       decl.Semantic.SemanticIndex = semantic_indexes[i];
00094 
00095       decl.DeclarationRange.First = 
00096       decl.DeclarationRange.Last = i;
00097       ti += tgsi_build_full_declaration(&decl,
00098                                         &tokens[ti],
00099                                         header,
00100                                         maxTokens - ti);
00101    }
00102 
00103    /* declare outputs */
00104    for (i = 0; i < num_attribs; i++) {
00105       decl = tgsi_default_full_declaration();
00106       decl.Declaration.File = TGSI_FILE_OUTPUT;
00107       decl.Declaration.Semantic = 1;
00108       decl.Semantic.SemanticName = semantic_names[i];
00109       decl.Semantic.SemanticIndex = semantic_indexes[i];
00110       decl.DeclarationRange.First = 
00111          decl.DeclarationRange.Last = i;
00112       ti += tgsi_build_full_declaration(&decl,
00113                                         &tokens[ti],
00114                                         header,
00115                                         maxTokens - ti);
00116    }
00117 
00118    /* emit MOV instructions */
00119    for (i = 0; i < num_attribs; i++) {
00120       /* MOVE out[i], in[i]; */
00121       inst = tgsi_default_full_instruction();
00122       inst.Instruction.Opcode = TGSI_OPCODE_MOV;
00123       inst.Instruction.NumDstRegs = 1;
00124       inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
00125       inst.FullDstRegisters[0].DstRegister.Index = i;
00126       inst.Instruction.NumSrcRegs = 1;
00127       inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
00128       inst.FullSrcRegisters[0].SrcRegister.Index = i;
00129       ti += tgsi_build_full_instruction(&inst,
00130                                         &tokens[ti],
00131                                         header,
00132                                         maxTokens - ti );
00133    }
00134 
00135    /* END instruction */
00136    inst = tgsi_default_full_instruction();
00137    inst.Instruction.Opcode = TGSI_OPCODE_END;
00138    inst.Instruction.NumDstRegs = 0;
00139    inst.Instruction.NumSrcRegs = 0;
00140    ti += tgsi_build_full_instruction(&inst,
00141                                      &tokens[ti],
00142                                      header,
00143                                      maxTokens - ti );
00144 
00145 #if 0 /*debug*/
00146    tgsi_dump(tokens, 0);
00147 #endif
00148 
00149    shader->tokens = tokens;
00150    /*shader->num_tokens = ti;*/
00151 
00152    return pipe->create_vs_state(pipe, shader);
00153 }


Generated on Tue Sep 29 06:25:29 2009 for Gallium3D by  doxygen 1.5.4