u_simple_shaders.c revision dccbfd8bf0624250a435948029916073d3390191
131970c4633c5000916b0a36022ff761038f5cf5aBrian/**************************************************************************
231970c4633c5000916b0a36022ff761038f5cf5aBrian *
331970c4633c5000916b0a36022ff761038f5cf5aBrian * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
431970c4633c5000916b0a36022ff761038f5cf5aBrian * All Rights Reserved.
531970c4633c5000916b0a36022ff761038f5cf5aBrian *
631970c4633c5000916b0a36022ff761038f5cf5aBrian * Permission is hereby granted, free of charge, to any person obtaining a
731970c4633c5000916b0a36022ff761038f5cf5aBrian * copy of this software and associated documentation files (the
831970c4633c5000916b0a36022ff761038f5cf5aBrian * "Software"), to deal in the Software without restriction, including
931970c4633c5000916b0a36022ff761038f5cf5aBrian * without limitation the rights to use, copy, modify, merge, publish,
1031970c4633c5000916b0a36022ff761038f5cf5aBrian * distribute, sub license, and/or sell copies of the Software, and to
1131970c4633c5000916b0a36022ff761038f5cf5aBrian * permit persons to whom the Software is furnished to do so, subject to
1231970c4633c5000916b0a36022ff761038f5cf5aBrian * the following conditions:
1331970c4633c5000916b0a36022ff761038f5cf5aBrian *
1431970c4633c5000916b0a36022ff761038f5cf5aBrian * The above copyright notice and this permission notice (including the
1531970c4633c5000916b0a36022ff761038f5cf5aBrian * next paragraph) shall be included in all copies or substantial portions
1631970c4633c5000916b0a36022ff761038f5cf5aBrian * of the Software.
1731970c4633c5000916b0a36022ff761038f5cf5aBrian *
1831970c4633c5000916b0a36022ff761038f5cf5aBrian * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1931970c4633c5000916b0a36022ff761038f5cf5aBrian * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2031970c4633c5000916b0a36022ff761038f5cf5aBrian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2131970c4633c5000916b0a36022ff761038f5cf5aBrian * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
2231970c4633c5000916b0a36022ff761038f5cf5aBrian * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2331970c4633c5000916b0a36022ff761038f5cf5aBrian * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2431970c4633c5000916b0a36022ff761038f5cf5aBrian * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2531970c4633c5000916b0a36022ff761038f5cf5aBrian *
2631970c4633c5000916b0a36022ff761038f5cf5aBrian **************************************************************************/
2731970c4633c5000916b0a36022ff761038f5cf5aBrian
2831970c4633c5000916b0a36022ff761038f5cf5aBrian/**
2931970c4633c5000916b0a36022ff761038f5cf5aBrian * @file
3031970c4633c5000916b0a36022ff761038f5cf5aBrian * Simple vertex/fragment shader generators.
3131970c4633c5000916b0a36022ff761038f5cf5aBrian *
3231970c4633c5000916b0a36022ff761038f5cf5aBrian * @author Brian Paul
3331970c4633c5000916b0a36022ff761038f5cf5aBrian */
3431970c4633c5000916b0a36022ff761038f5cf5aBrian
3531970c4633c5000916b0a36022ff761038f5cf5aBrian
3631970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_context.h"
3731970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_debug.h"
3831970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_defines.h"
3931970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_inlines.h"
4031970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_util.h"
4131970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_winsys.h"
4231970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_shader_tokens.h"
4331970c4633c5000916b0a36022ff761038f5cf5aBrian
4431970c4633c5000916b0a36022ff761038f5cf5aBrian#include "util/u_simple_shaders.h"
4531970c4633c5000916b0a36022ff761038f5cf5aBrian
4631970c4633c5000916b0a36022ff761038f5cf5aBrian#include "tgsi/util/tgsi_build.h"
4731970c4633c5000916b0a36022ff761038f5cf5aBrian#include "tgsi/util/tgsi_dump.h"
4831970c4633c5000916b0a36022ff761038f5cf5aBrian#include "tgsi/util/tgsi_parse.h"
4931970c4633c5000916b0a36022ff761038f5cf5aBrian
5031970c4633c5000916b0a36022ff761038f5cf5aBrian
5131970c4633c5000916b0a36022ff761038f5cf5aBrian
5231970c4633c5000916b0a36022ff761038f5cf5aBrian/**
5331970c4633c5000916b0a36022ff761038f5cf5aBrian * Make simple vertex pass-through shader.
5431970c4633c5000916b0a36022ff761038f5cf5aBrian */
5531970c4633c5000916b0a36022ff761038f5cf5aBrianvoid *
5631970c4633c5000916b0a36022ff761038f5cf5aBrianutil_make_vertex_passthrough_shader(struct pipe_context *pipe,
5731970c4633c5000916b0a36022ff761038f5cf5aBrian                                    uint num_attribs,
5831970c4633c5000916b0a36022ff761038f5cf5aBrian                                    const uint *semantic_names,
59dccbfd8bf0624250a435948029916073d3390191Brian                                    const uint *semantic_indexes,
60dccbfd8bf0624250a435948029916073d3390191Brian                                    struct pipe_shader_state *shader)
61dccbfd8bf0624250a435948029916073d3390191Brian
6231970c4633c5000916b0a36022ff761038f5cf5aBrian{
6331970c4633c5000916b0a36022ff761038f5cf5aBrian   uint maxTokens = 100;
6431970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_token *tokens;
6531970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_header *header;
6631970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_processor *processor;
6731970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_full_declaration decl;
6831970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_full_instruction inst;
6931970c4633c5000916b0a36022ff761038f5cf5aBrian   const uint procType = TGSI_PROCESSOR_VERTEX;
7031970c4633c5000916b0a36022ff761038f5cf5aBrian   uint ti, i;
7131970c4633c5000916b0a36022ff761038f5cf5aBrian
72482f4995253a0c295dc02e34e58a138ac8822c54Michal Krol   tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
7331970c4633c5000916b0a36022ff761038f5cf5aBrian
7431970c4633c5000916b0a36022ff761038f5cf5aBrian   /* shader header
7531970c4633c5000916b0a36022ff761038f5cf5aBrian    */
7631970c4633c5000916b0a36022ff761038f5cf5aBrian   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
7731970c4633c5000916b0a36022ff761038f5cf5aBrian
7831970c4633c5000916b0a36022ff761038f5cf5aBrian   header = (struct tgsi_header *) &tokens[1];
7931970c4633c5000916b0a36022ff761038f5cf5aBrian   *header = tgsi_build_header();
8031970c4633c5000916b0a36022ff761038f5cf5aBrian
8131970c4633c5000916b0a36022ff761038f5cf5aBrian   processor = (struct tgsi_processor *) &tokens[2];
8231970c4633c5000916b0a36022ff761038f5cf5aBrian   *processor = tgsi_build_processor( procType, header );
8331970c4633c5000916b0a36022ff761038f5cf5aBrian
8431970c4633c5000916b0a36022ff761038f5cf5aBrian   ti = 3;
8531970c4633c5000916b0a36022ff761038f5cf5aBrian
8631970c4633c5000916b0a36022ff761038f5cf5aBrian   /* declare inputs */
8731970c4633c5000916b0a36022ff761038f5cf5aBrian   for (i = 0; i < num_attribs; i++) {
8831970c4633c5000916b0a36022ff761038f5cf5aBrian      decl = tgsi_default_full_declaration();
8931970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.Declaration.File = TGSI_FILE_INPUT;
9000cf178d93e5bc36a88a9f8ff444f60c493be14dBrian
9131970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.Declaration.Semantic = 1;
9200cf178d93e5bc36a88a9f8ff444f60c493be14dBrian      decl.Semantic.SemanticName = semantic_names[i];
9300cf178d93e5bc36a88a9f8ff444f60c493be14dBrian      decl.Semantic.SemanticIndex = semantic_indexes[i];
9400cf178d93e5bc36a88a9f8ff444f60c493be14dBrian
9531970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.u.DeclarationRange.First =
9600cf178d93e5bc36a88a9f8ff444f60c493be14dBrian      decl.u.DeclarationRange.Last = i;
9731970c4633c5000916b0a36022ff761038f5cf5aBrian      ti += tgsi_build_full_declaration(&decl,
9831970c4633c5000916b0a36022ff761038f5cf5aBrian                                        &tokens[ti],
9931970c4633c5000916b0a36022ff761038f5cf5aBrian                                        header,
10031970c4633c5000916b0a36022ff761038f5cf5aBrian                                        maxTokens - ti);
10131970c4633c5000916b0a36022ff761038f5cf5aBrian   }
10231970c4633c5000916b0a36022ff761038f5cf5aBrian
10331970c4633c5000916b0a36022ff761038f5cf5aBrian   /* declare outputs */
10431970c4633c5000916b0a36022ff761038f5cf5aBrian   for (i = 0; i < num_attribs; i++) {
10531970c4633c5000916b0a36022ff761038f5cf5aBrian      decl = tgsi_default_full_declaration();
10631970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.Declaration.File = TGSI_FILE_OUTPUT;
10731970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.Declaration.Semantic = 1;
10831970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.Semantic.SemanticName = semantic_names[i];
10931970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.Semantic.SemanticIndex = semantic_indexes[i];
11031970c4633c5000916b0a36022ff761038f5cf5aBrian      decl.u.DeclarationRange.First =
11100cf178d93e5bc36a88a9f8ff444f60c493be14dBrian         decl.u.DeclarationRange.Last = i;
11231970c4633c5000916b0a36022ff761038f5cf5aBrian      ti += tgsi_build_full_declaration(&decl,
11331970c4633c5000916b0a36022ff761038f5cf5aBrian                                        &tokens[ti],
11431970c4633c5000916b0a36022ff761038f5cf5aBrian                                        header,
11531970c4633c5000916b0a36022ff761038f5cf5aBrian                                        maxTokens - ti);
11631970c4633c5000916b0a36022ff761038f5cf5aBrian   }
11731970c4633c5000916b0a36022ff761038f5cf5aBrian
11831970c4633c5000916b0a36022ff761038f5cf5aBrian   /* emit MOV instructions */
11931970c4633c5000916b0a36022ff761038f5cf5aBrian   for (i = 0; i < num_attribs; i++) {
12031970c4633c5000916b0a36022ff761038f5cf5aBrian      /* MOVE out[i], in[i]; */
12131970c4633c5000916b0a36022ff761038f5cf5aBrian      inst = tgsi_default_full_instruction();
12231970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.Instruction.Opcode = TGSI_OPCODE_MOV;
12331970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.Instruction.NumDstRegs = 1;
12431970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
12531970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.FullDstRegisters[0].DstRegister.Index = i;
12631970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.Instruction.NumSrcRegs = 1;
12731970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
12831970c4633c5000916b0a36022ff761038f5cf5aBrian      inst.FullSrcRegisters[0].SrcRegister.Index = i;
12931970c4633c5000916b0a36022ff761038f5cf5aBrian      ti += tgsi_build_full_instruction(&inst,
13031970c4633c5000916b0a36022ff761038f5cf5aBrian                                        &tokens[ti],
13131970c4633c5000916b0a36022ff761038f5cf5aBrian                                        header,
13231970c4633c5000916b0a36022ff761038f5cf5aBrian                                        maxTokens - ti );
13331970c4633c5000916b0a36022ff761038f5cf5aBrian   }
13431970c4633c5000916b0a36022ff761038f5cf5aBrian
13531970c4633c5000916b0a36022ff761038f5cf5aBrian   /* END instruction */
13631970c4633c5000916b0a36022ff761038f5cf5aBrian   inst = tgsi_default_full_instruction();
13731970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.Opcode = TGSI_OPCODE_END;
13831970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.NumDstRegs = 0;
13931970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.NumSrcRegs = 0;
14031970c4633c5000916b0a36022ff761038f5cf5aBrian   ti += tgsi_build_full_instruction(&inst,
14131970c4633c5000916b0a36022ff761038f5cf5aBrian                                     &tokens[ti],
14231970c4633c5000916b0a36022ff761038f5cf5aBrian                                     header,
14331970c4633c5000916b0a36022ff761038f5cf5aBrian                                     maxTokens - ti );
14431970c4633c5000916b0a36022ff761038f5cf5aBrian
14531970c4633c5000916b0a36022ff761038f5cf5aBrian#if 0 /*debug*/
14631970c4633c5000916b0a36022ff761038f5cf5aBrian   tgsi_dump(tokens, 0);
14731970c4633c5000916b0a36022ff761038f5cf5aBrian#endif
14831970c4633c5000916b0a36022ff761038f5cf5aBrian
149dccbfd8bf0624250a435948029916073d3390191Brian   shader->tokens = tokens;
150dccbfd8bf0624250a435948029916073d3390191Brian   /*shader->num_tokens = ti;*/
151dccbfd8bf0624250a435948029916073d3390191Brian
152dccbfd8bf0624250a435948029916073d3390191Brian   return pipe->create_vs_state(pipe, shader);
15331970c4633c5000916b0a36022ff761038f5cf5aBrian}
15431970c4633c5000916b0a36022ff761038f5cf5aBrian
15531970c4633c5000916b0a36022ff761038f5cf5aBrian
15631970c4633c5000916b0a36022ff761038f5cf5aBrian
15731970c4633c5000916b0a36022ff761038f5cf5aBrian
15831970c4633c5000916b0a36022ff761038f5cf5aBrian/**
15931970c4633c5000916b0a36022ff761038f5cf5aBrian * Make simple fragment texture shader:
16031970c4633c5000916b0a36022ff761038f5cf5aBrian *  TEX OUT[0], IN[0], SAMP[0], 2D;
16131970c4633c5000916b0a36022ff761038f5cf5aBrian *  END;
16231970c4633c5000916b0a36022ff761038f5cf5aBrian */
16331970c4633c5000916b0a36022ff761038f5cf5aBrianvoid *
164dccbfd8bf0624250a435948029916073d3390191Brianutil_make_fragment_tex_shader(struct pipe_context *pipe,
165dccbfd8bf0624250a435948029916073d3390191Brian                              struct pipe_shader_state *shader)
16631970c4633c5000916b0a36022ff761038f5cf5aBrian{
16731970c4633c5000916b0a36022ff761038f5cf5aBrian   uint maxTokens = 100;
16831970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_token *tokens;
16931970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_header *header;
17031970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_processor *processor;
17131970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_full_declaration decl;
17231970c4633c5000916b0a36022ff761038f5cf5aBrian   struct tgsi_full_instruction inst;
17331970c4633c5000916b0a36022ff761038f5cf5aBrian   const uint procType = TGSI_PROCESSOR_FRAGMENT;
17431970c4633c5000916b0a36022ff761038f5cf5aBrian   uint ti;
17531970c4633c5000916b0a36022ff761038f5cf5aBrian
176482f4995253a0c295dc02e34e58a138ac8822c54Michal Krol   tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
17731970c4633c5000916b0a36022ff761038f5cf5aBrian
17831970c4633c5000916b0a36022ff761038f5cf5aBrian   /* shader header
17931970c4633c5000916b0a36022ff761038f5cf5aBrian    */
18031970c4633c5000916b0a36022ff761038f5cf5aBrian   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
18131970c4633c5000916b0a36022ff761038f5cf5aBrian
18231970c4633c5000916b0a36022ff761038f5cf5aBrian   header = (struct tgsi_header *) &tokens[1];
18331970c4633c5000916b0a36022ff761038f5cf5aBrian   *header = tgsi_build_header();
18431970c4633c5000916b0a36022ff761038f5cf5aBrian
18531970c4633c5000916b0a36022ff761038f5cf5aBrian   processor = (struct tgsi_processor *) &tokens[2];
18631970c4633c5000916b0a36022ff761038f5cf5aBrian   *processor = tgsi_build_processor( procType, header );
18731970c4633c5000916b0a36022ff761038f5cf5aBrian
18831970c4633c5000916b0a36022ff761038f5cf5aBrian   ti = 3;
18931970c4633c5000916b0a36022ff761038f5cf5aBrian
19031970c4633c5000916b0a36022ff761038f5cf5aBrian   /* declare TEX[0] input */
19131970c4633c5000916b0a36022ff761038f5cf5aBrian   decl = tgsi_default_full_declaration();
19231970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Declaration.File = TGSI_FILE_INPUT;
19331970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Declaration.Semantic = 1;
19431970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC;
19531970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Semantic.SemanticIndex = 0;
19631970c4633c5000916b0a36022ff761038f5cf5aBrian   /* XXX this could be linear... */
19731970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Declaration.Interpolate = 1;
19831970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Interpolation.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
19931970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.u.DeclarationRange.First =
20031970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.u.DeclarationRange.Last = 0;
20131970c4633c5000916b0a36022ff761038f5cf5aBrian   ti += tgsi_build_full_declaration(&decl,
20231970c4633c5000916b0a36022ff761038f5cf5aBrian                                     &tokens[ti],
20331970c4633c5000916b0a36022ff761038f5cf5aBrian                                     header,
20431970c4633c5000916b0a36022ff761038f5cf5aBrian                                     maxTokens - ti);
20531970c4633c5000916b0a36022ff761038f5cf5aBrian
20631970c4633c5000916b0a36022ff761038f5cf5aBrian   /* declare color[0] output */
20731970c4633c5000916b0a36022ff761038f5cf5aBrian   decl = tgsi_default_full_declaration();
20831970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Declaration.File = TGSI_FILE_OUTPUT;
20931970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Declaration.Semantic = 1;
21031970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
21131970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Semantic.SemanticIndex = 0;
21231970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.u.DeclarationRange.First =
21331970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.u.DeclarationRange.Last = 0;
21431970c4633c5000916b0a36022ff761038f5cf5aBrian   ti += tgsi_build_full_declaration(&decl,
21531970c4633c5000916b0a36022ff761038f5cf5aBrian                                     &tokens[ti],
21631970c4633c5000916b0a36022ff761038f5cf5aBrian                                     header,
21731970c4633c5000916b0a36022ff761038f5cf5aBrian                                     maxTokens - ti);
21831970c4633c5000916b0a36022ff761038f5cf5aBrian
21931970c4633c5000916b0a36022ff761038f5cf5aBrian   /* declare sampler */
22031970c4633c5000916b0a36022ff761038f5cf5aBrian   decl = tgsi_default_full_declaration();
22131970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.Declaration.File = TGSI_FILE_SAMPLER;
22231970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.u.DeclarationRange.First =
22331970c4633c5000916b0a36022ff761038f5cf5aBrian   decl.u.DeclarationRange.Last = 0;
22431970c4633c5000916b0a36022ff761038f5cf5aBrian   ti += tgsi_build_full_declaration(&decl,
22531970c4633c5000916b0a36022ff761038f5cf5aBrian                                     &tokens[ti],
22631970c4633c5000916b0a36022ff761038f5cf5aBrian                                     header,
22731970c4633c5000916b0a36022ff761038f5cf5aBrian                                     maxTokens - ti);
22831970c4633c5000916b0a36022ff761038f5cf5aBrian
22931970c4633c5000916b0a36022ff761038f5cf5aBrian   /* TEX instruction */
23031970c4633c5000916b0a36022ff761038f5cf5aBrian   inst = tgsi_default_full_instruction();
23131970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.Opcode = TGSI_OPCODE_TEX;
23231970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.NumDstRegs = 1;
23331970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
23431970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.FullDstRegisters[0].DstRegister.Index = 0;
23531970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.NumSrcRegs = 2;
23631970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D;
23731970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
23831970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.FullSrcRegisters[0].SrcRegister.Index = 0;
23931970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER;
24031970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.FullSrcRegisters[1].SrcRegister.Index = 0;
24131970c4633c5000916b0a36022ff761038f5cf5aBrian   ti += tgsi_build_full_instruction(&inst,
24231970c4633c5000916b0a36022ff761038f5cf5aBrian                                     &tokens[ti],
24331970c4633c5000916b0a36022ff761038f5cf5aBrian                                     header,
24431970c4633c5000916b0a36022ff761038f5cf5aBrian                                     maxTokens - ti );
24531970c4633c5000916b0a36022ff761038f5cf5aBrian
24631970c4633c5000916b0a36022ff761038f5cf5aBrian   /* END instruction */
24731970c4633c5000916b0a36022ff761038f5cf5aBrian   inst = tgsi_default_full_instruction();
24831970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.Opcode = TGSI_OPCODE_END;
24931970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.NumDstRegs = 0;
25031970c4633c5000916b0a36022ff761038f5cf5aBrian   inst.Instruction.NumSrcRegs = 0;
25131970c4633c5000916b0a36022ff761038f5cf5aBrian   ti += tgsi_build_full_instruction(&inst,
25231970c4633c5000916b0a36022ff761038f5cf5aBrian                                     &tokens[ti],
25331970c4633c5000916b0a36022ff761038f5cf5aBrian                                     header,
25431970c4633c5000916b0a36022ff761038f5cf5aBrian                                     maxTokens - ti );
25531970c4633c5000916b0a36022ff761038f5cf5aBrian
25631970c4633c5000916b0a36022ff761038f5cf5aBrian#if 0 /*debug*/
25731970c4633c5000916b0a36022ff761038f5cf5aBrian   tgsi_dump(tokens, 0);
25831970c4633c5000916b0a36022ff761038f5cf5aBrian#endif
25931970c4633c5000916b0a36022ff761038f5cf5aBrian
260dccbfd8bf0624250a435948029916073d3390191Brian   shader->tokens = tokens;
261dccbfd8bf0624250a435948029916073d3390191Brian   /*shader->num_tokens = ti;*/
262dccbfd8bf0624250a435948029916073d3390191Brian
263dccbfd8bf0624250a435948029916073d3390191Brian   return pipe->create_fs_state(pipe, shader);
26431970c4633c5000916b0a36022ff761038f5cf5aBrian}
26531970c4633c5000916b0a36022ff761038f5cf5aBrian
2666a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2676a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2686a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2696a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2706a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian/**
2716a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian * Make simple fragment color pass-through shader.
2726a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian */
2736a9a3afcf923ec5c67069cdb1656f52675cd8edeBrianvoid *
274dccbfd8bf0624250a435948029916073d3390191Brianutil_make_fragment_passthrough_shader(struct pipe_context *pipe,
275dccbfd8bf0624250a435948029916073d3390191Brian                                      struct pipe_shader_state *shader)
2766a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian{
2776a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   uint maxTokens = 40;
2786a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   struct tgsi_token *tokens;
2796a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   struct tgsi_header *header;
2806a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   struct tgsi_processor *processor;
2816a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   struct tgsi_full_declaration decl;
2826a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   struct tgsi_full_instruction inst;
2836a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   const uint procType = TGSI_PROCESSOR_FRAGMENT;
284f259ea0347754e0e8c93fd16796fc1db72b03372Keith Whitwell   uint ti;
2856a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
286400b12b4ceda32cc35b60d0484dfd333f1749b8eMichal Krol   tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0]));
2876a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2886a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   /* shader header
2896a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian    */
2906a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
2916a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2926a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   header = (struct tgsi_header *) &tokens[1];
2936a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   *header = tgsi_build_header();
2946a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2956a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   processor = (struct tgsi_processor *) &tokens[2];
2966a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   *processor = tgsi_build_processor( procType, header );
2976a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
2986a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   ti = 3;
2996a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3006a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   /* declare input */
3016a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl = tgsi_default_full_declaration();
3026a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Declaration.File = TGSI_FILE_INPUT;
3036a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Declaration.Semantic = 1;
3046a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
3056a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Semantic.SemanticIndex = 0;
3066a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.u.DeclarationRange.First =
3076a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian      decl.u.DeclarationRange.Last = 0;
3086a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   ti += tgsi_build_full_declaration(&decl,
3096a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     &tokens[ti],
3106a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     header,
3116a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     maxTokens - ti);
3126a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3136a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   /* declare output */
3146a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl = tgsi_default_full_declaration();
3156a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Declaration.File = TGSI_FILE_OUTPUT;
3166a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Declaration.Semantic = 1;
3176a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
3186a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.Semantic.SemanticIndex = 0;
3196a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   decl.u.DeclarationRange.First =
3206a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian      decl.u.DeclarationRange.Last = 0;
3216a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   ti += tgsi_build_full_declaration(&decl,
3226a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     &tokens[ti],
3236a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     header,
3246a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     maxTokens - ti);
3256a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3266a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3276a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   /* MOVE out[0], in[0]; */
3286a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst = tgsi_default_full_instruction();
3296a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.Instruction.Opcode = TGSI_OPCODE_MOV;
3306a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.Instruction.NumDstRegs = 1;
3316a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
3326a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.FullDstRegisters[0].DstRegister.Index = 0;
3336a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.Instruction.NumSrcRegs = 1;
3346a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
3356a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.FullSrcRegisters[0].SrcRegister.Index = 0;
3366a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   ti += tgsi_build_full_instruction(&inst,
3376a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     &tokens[ti],
3386a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     header,
3396a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     maxTokens - ti );
3406a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3416a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   /* END instruction */
3426a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst = tgsi_default_full_instruction();
3436a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.Instruction.Opcode = TGSI_OPCODE_END;
3446a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.Instruction.NumDstRegs = 0;
3456a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   inst.Instruction.NumSrcRegs = 0;
3466a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   ti += tgsi_build_full_instruction(&inst,
3476a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     &tokens[ti],
3486a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     header,
3496a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian                                     maxTokens - ti );
3506a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3516a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   assert(ti < maxTokens);
3526a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
3536a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian#if 0 /*debug*/
3546a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian   tgsi_dump(tokens, 0);
3556a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian#endif
3566a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
357dccbfd8bf0624250a435948029916073d3390191Brian   shader->tokens = tokens;
358dccbfd8bf0624250a435948029916073d3390191Brian   /*shader->num_tokens = ti;*/
359dccbfd8bf0624250a435948029916073d3390191Brian
360dccbfd8bf0624250a435948029916073d3390191Brian   return pipe->create_fs_state(pipe, shader);
3616a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian}
3626a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian
363