u_simple_shaders.c revision 00cf178d93e5bc36a88a9f8ff444f60c493be14d
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, 5931970c4633c5000916b0a36022ff761038f5cf5aBrian const uint *semantic_indexes) 6031970c4633c5000916b0a36022ff761038f5cf5aBrian{ 6131970c4633c5000916b0a36022ff761038f5cf5aBrian uint maxTokens = 100; 6231970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_token *tokens; 6331970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_header *header; 6431970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_processor *processor; 6531970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_full_declaration decl; 6631970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_full_instruction inst; 6731970c4633c5000916b0a36022ff761038f5cf5aBrian const uint procType = TGSI_PROCESSOR_VERTEX; 6831970c4633c5000916b0a36022ff761038f5cf5aBrian uint ti, i; 6931970c4633c5000916b0a36022ff761038f5cf5aBrian struct pipe_shader_state shader; 7031970c4633c5000916b0a36022ff761038f5cf5aBrian 71482f4995253a0c295dc02e34e58a138ac8822c54Michal Krol tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0])); 7231970c4633c5000916b0a36022ff761038f5cf5aBrian 7331970c4633c5000916b0a36022ff761038f5cf5aBrian /* shader header 7431970c4633c5000916b0a36022ff761038f5cf5aBrian */ 7531970c4633c5000916b0a36022ff761038f5cf5aBrian *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); 7631970c4633c5000916b0a36022ff761038f5cf5aBrian 7731970c4633c5000916b0a36022ff761038f5cf5aBrian header = (struct tgsi_header *) &tokens[1]; 7831970c4633c5000916b0a36022ff761038f5cf5aBrian *header = tgsi_build_header(); 7931970c4633c5000916b0a36022ff761038f5cf5aBrian 8031970c4633c5000916b0a36022ff761038f5cf5aBrian processor = (struct tgsi_processor *) &tokens[2]; 8131970c4633c5000916b0a36022ff761038f5cf5aBrian *processor = tgsi_build_processor( procType, header ); 8231970c4633c5000916b0a36022ff761038f5cf5aBrian 8331970c4633c5000916b0a36022ff761038f5cf5aBrian ti = 3; 8431970c4633c5000916b0a36022ff761038f5cf5aBrian 8531970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare inputs */ 8631970c4633c5000916b0a36022ff761038f5cf5aBrian for (i = 0; i < num_attribs; i++) { 8731970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 8831970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_INPUT; 8900cf178d93e5bc36a88a9f8ff444f60c493be14dBrian 9031970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 9100cf178d93e5bc36a88a9f8ff444f60c493be14dBrian decl.Semantic.SemanticName = semantic_names[i]; 9200cf178d93e5bc36a88a9f8ff444f60c493be14dBrian decl.Semantic.SemanticIndex = semantic_indexes[i]; 9300cf178d93e5bc36a88a9f8ff444f60c493be14dBrian 9431970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.First = 9500cf178d93e5bc36a88a9f8ff444f60c493be14dBrian decl.u.DeclarationRange.Last = i; 9631970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 9731970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 9831970c4633c5000916b0a36022ff761038f5cf5aBrian header, 9931970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti); 10031970c4633c5000916b0a36022ff761038f5cf5aBrian } 10131970c4633c5000916b0a36022ff761038f5cf5aBrian 10231970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare outputs */ 10331970c4633c5000916b0a36022ff761038f5cf5aBrian for (i = 0; i < num_attribs; i++) { 10431970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 10531970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_OUTPUT; 10631970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 10731970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticName = semantic_names[i]; 10831970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticIndex = semantic_indexes[i]; 10931970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.First = 11000cf178d93e5bc36a88a9f8ff444f60c493be14dBrian decl.u.DeclarationRange.Last = i; 11131970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 11231970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 11331970c4633c5000916b0a36022ff761038f5cf5aBrian header, 11431970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti); 11531970c4633c5000916b0a36022ff761038f5cf5aBrian } 11631970c4633c5000916b0a36022ff761038f5cf5aBrian 11731970c4633c5000916b0a36022ff761038f5cf5aBrian /* emit MOV instructions */ 11831970c4633c5000916b0a36022ff761038f5cf5aBrian for (i = 0; i < num_attribs; i++) { 11931970c4633c5000916b0a36022ff761038f5cf5aBrian /* MOVE out[i], in[i]; */ 12031970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 12131970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_MOV; 12231970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 1; 12331970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT; 12431970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.Index = i; 12531970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 1; 12631970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT; 12731970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.Index = i; 12831970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 12931970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 13031970c4633c5000916b0a36022ff761038f5cf5aBrian header, 13131970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti ); 13231970c4633c5000916b0a36022ff761038f5cf5aBrian } 13331970c4633c5000916b0a36022ff761038f5cf5aBrian 13431970c4633c5000916b0a36022ff761038f5cf5aBrian /* END instruction */ 13531970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 13631970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_END; 13731970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 0; 13831970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 0; 13931970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 14031970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 14131970c4633c5000916b0a36022ff761038f5cf5aBrian header, 14231970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti ); 14331970c4633c5000916b0a36022ff761038f5cf5aBrian 14431970c4633c5000916b0a36022ff761038f5cf5aBrian#if 0 /*debug*/ 14531970c4633c5000916b0a36022ff761038f5cf5aBrian tgsi_dump(tokens, 0); 14631970c4633c5000916b0a36022ff761038f5cf5aBrian#endif 14731970c4633c5000916b0a36022ff761038f5cf5aBrian 14831970c4633c5000916b0a36022ff761038f5cf5aBrian shader.tokens = tokens; 14931970c4633c5000916b0a36022ff761038f5cf5aBrian return pipe->create_vs_state(pipe, &shader); 15031970c4633c5000916b0a36022ff761038f5cf5aBrian} 15131970c4633c5000916b0a36022ff761038f5cf5aBrian 15231970c4633c5000916b0a36022ff761038f5cf5aBrian 15331970c4633c5000916b0a36022ff761038f5cf5aBrian 15431970c4633c5000916b0a36022ff761038f5cf5aBrian 15531970c4633c5000916b0a36022ff761038f5cf5aBrian/** 15631970c4633c5000916b0a36022ff761038f5cf5aBrian * Make simple fragment texture shader: 15731970c4633c5000916b0a36022ff761038f5cf5aBrian * TEX OUT[0], IN[0], SAMP[0], 2D; 15831970c4633c5000916b0a36022ff761038f5cf5aBrian * END; 15931970c4633c5000916b0a36022ff761038f5cf5aBrian */ 16031970c4633c5000916b0a36022ff761038f5cf5aBrianvoid * 16131970c4633c5000916b0a36022ff761038f5cf5aBrianutil_make_fragment_tex_shader(struct pipe_context *pipe) 16231970c4633c5000916b0a36022ff761038f5cf5aBrian{ 16331970c4633c5000916b0a36022ff761038f5cf5aBrian uint maxTokens = 100; 16431970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_token *tokens; 16531970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_header *header; 16631970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_processor *processor; 16731970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_full_declaration decl; 16831970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_full_instruction inst; 16931970c4633c5000916b0a36022ff761038f5cf5aBrian const uint procType = TGSI_PROCESSOR_FRAGMENT; 17031970c4633c5000916b0a36022ff761038f5cf5aBrian uint ti; 17131970c4633c5000916b0a36022ff761038f5cf5aBrian struct pipe_shader_state shader; 17231970c4633c5000916b0a36022ff761038f5cf5aBrian 173482f4995253a0c295dc02e34e58a138ac8822c54Michal Krol tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0])); 17431970c4633c5000916b0a36022ff761038f5cf5aBrian 17531970c4633c5000916b0a36022ff761038f5cf5aBrian /* shader header 17631970c4633c5000916b0a36022ff761038f5cf5aBrian */ 17731970c4633c5000916b0a36022ff761038f5cf5aBrian *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); 17831970c4633c5000916b0a36022ff761038f5cf5aBrian 17931970c4633c5000916b0a36022ff761038f5cf5aBrian header = (struct tgsi_header *) &tokens[1]; 18031970c4633c5000916b0a36022ff761038f5cf5aBrian *header = tgsi_build_header(); 18131970c4633c5000916b0a36022ff761038f5cf5aBrian 18231970c4633c5000916b0a36022ff761038f5cf5aBrian processor = (struct tgsi_processor *) &tokens[2]; 18331970c4633c5000916b0a36022ff761038f5cf5aBrian *processor = tgsi_build_processor( procType, header ); 18431970c4633c5000916b0a36022ff761038f5cf5aBrian 18531970c4633c5000916b0a36022ff761038f5cf5aBrian ti = 3; 18631970c4633c5000916b0a36022ff761038f5cf5aBrian 18731970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare TEX[0] input */ 18831970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 18931970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_INPUT; 19031970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 19131970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC; 19231970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticIndex = 0; 19331970c4633c5000916b0a36022ff761038f5cf5aBrian /* XXX this could be linear... */ 19431970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Interpolate = 1; 19531970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Interpolation.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE; 19631970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.First = 19731970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.Last = 0; 19831970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 19931970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 20031970c4633c5000916b0a36022ff761038f5cf5aBrian header, 20131970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti); 20231970c4633c5000916b0a36022ff761038f5cf5aBrian 20331970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare color[0] output */ 20431970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 20531970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_OUTPUT; 20631970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 20731970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR; 20831970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticIndex = 0; 20931970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.First = 21031970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.Last = 0; 21131970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 21231970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 21331970c4633c5000916b0a36022ff761038f5cf5aBrian header, 21431970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti); 21531970c4633c5000916b0a36022ff761038f5cf5aBrian 21631970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare sampler */ 21731970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 21831970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_SAMPLER; 21931970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.First = 22031970c4633c5000916b0a36022ff761038f5cf5aBrian decl.u.DeclarationRange.Last = 0; 22131970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 22231970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 22331970c4633c5000916b0a36022ff761038f5cf5aBrian header, 22431970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti); 22531970c4633c5000916b0a36022ff761038f5cf5aBrian 22631970c4633c5000916b0a36022ff761038f5cf5aBrian /* TEX instruction */ 22731970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 22831970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_TEX; 22931970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 1; 23031970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT; 23131970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.Index = 0; 23231970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 2; 23331970c4633c5000916b0a36022ff761038f5cf5aBrian inst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D; 23431970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT; 23531970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.Index = 0; 23631970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER; 23731970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[1].SrcRegister.Index = 0; 23831970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 23931970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 24031970c4633c5000916b0a36022ff761038f5cf5aBrian header, 24131970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti ); 24231970c4633c5000916b0a36022ff761038f5cf5aBrian 24331970c4633c5000916b0a36022ff761038f5cf5aBrian /* END instruction */ 24431970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 24531970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_END; 24631970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 0; 24731970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 0; 24831970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 24931970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 25031970c4633c5000916b0a36022ff761038f5cf5aBrian header, 25131970c4633c5000916b0a36022ff761038f5cf5aBrian maxTokens - ti ); 25231970c4633c5000916b0a36022ff761038f5cf5aBrian 25331970c4633c5000916b0a36022ff761038f5cf5aBrian#if 0 /*debug*/ 25431970c4633c5000916b0a36022ff761038f5cf5aBrian tgsi_dump(tokens, 0); 25531970c4633c5000916b0a36022ff761038f5cf5aBrian#endif 25631970c4633c5000916b0a36022ff761038f5cf5aBrian 25731970c4633c5000916b0a36022ff761038f5cf5aBrian shader.tokens = tokens; 25831970c4633c5000916b0a36022ff761038f5cf5aBrian return pipe->create_fs_state(pipe, &shader); 25931970c4633c5000916b0a36022ff761038f5cf5aBrian} 26031970c4633c5000916b0a36022ff761038f5cf5aBrian 2616a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2626a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2636a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2646a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2656a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian/** 2666a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian * Make simple fragment color pass-through shader. 2676a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian */ 2686a9a3afcf923ec5c67069cdb1656f52675cd8edeBrianvoid * 2696a9a3afcf923ec5c67069cdb1656f52675cd8edeBrianutil_make_fragment_passthrough_shader(struct pipe_context *pipe) 2706a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian{ 2716a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian uint maxTokens = 40; 2726a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_token *tokens; 2736a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_header *header; 2746a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_processor *processor; 2756a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_full_declaration decl; 2766a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_full_instruction inst; 2776a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian const uint procType = TGSI_PROCESSOR_FRAGMENT; 278f259ea0347754e0e8c93fd16796fc1db72b03372Keith Whitwell uint ti; 2796a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct pipe_shader_state shader; 2806a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 281400b12b4ceda32cc35b60d0484dfd333f1749b8eMichal Krol tokens = (struct tgsi_token *) MALLOC(maxTokens * sizeof(tokens[0])); 2826a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2836a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* shader header 2846a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian */ 2856a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); 2866a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2876a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header = (struct tgsi_header *) &tokens[1]; 2886a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian *header = tgsi_build_header(); 2896a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2906a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian processor = (struct tgsi_processor *) &tokens[2]; 2916a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian *processor = tgsi_build_processor( procType, header ); 2926a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2936a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti = 3; 2946a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2956a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* declare input */ 2966a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl = tgsi_default_full_declaration(); 2976a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.File = TGSI_FILE_INPUT; 2986a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.Semantic = 1; 2996a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR; 3006a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticIndex = 0; 3016a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.u.DeclarationRange.First = 3026a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.u.DeclarationRange.Last = 0; 3036a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_declaration(&decl, 3046a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3056a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 3066a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian maxTokens - ti); 3076a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3086a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* declare output */ 3096a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl = tgsi_default_full_declaration(); 3106a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.File = TGSI_FILE_OUTPUT; 3116a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.Semantic = 1; 3126a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR; 3136a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticIndex = 0; 3146a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.u.DeclarationRange.First = 3156a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.u.DeclarationRange.Last = 0; 3166a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_declaration(&decl, 3176a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3186a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 3196a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian maxTokens - ti); 3206a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3216a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3226a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* MOVE out[0], in[0]; */ 3236a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst = tgsi_default_full_instruction(); 3246a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.Opcode = TGSI_OPCODE_MOV; 3256a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumDstRegs = 1; 3266a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT; 3276a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullDstRegisters[0].DstRegister.Index = 0; 3286a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumSrcRegs = 1; 3296a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT; 3306a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullSrcRegisters[0].SrcRegister.Index = 0; 3316a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_instruction(&inst, 3326a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3336a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 3346a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian maxTokens - ti ); 3356a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3366a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* END instruction */ 3376a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst = tgsi_default_full_instruction(); 3386a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.Opcode = TGSI_OPCODE_END; 3396a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumDstRegs = 0; 3406a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumSrcRegs = 0; 3416a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_instruction(&inst, 3426a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3436a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 3446a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian maxTokens - ti ); 3456a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3466a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian assert(ti < maxTokens); 3476a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3486a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian#if 0 /*debug*/ 3496a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian tgsi_dump(tokens, 0); 3506a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian#endif 3516a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3526a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian shader.tokens = tokens; 3536a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian return pipe->create_fs_state(pipe, &shader); 3546a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian} 3556a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 356