u_simple_shaders.c revision fa0f48504a32642d688d4b81f62eea54c693b23f
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" 37ea4bf267e4b023b08043f91ac44592fed1736e7fJosé Fonseca#include "util/u_debug.h" 3831970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_defines.h" 39adfbba476db1fc55006efb748656ebb1a481d143Zack Rusin#include "pipe/p_screen.h" 4031970c4633c5000916b0a36022ff761038f5cf5aBrian#include "pipe/p_shader_tokens.h" 4131970c4633c5000916b0a36022ff761038f5cf5aBrian 424f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 4331970c4633c5000916b0a36022ff761038f5cf5aBrian#include "util/u_simple_shaders.h" 4431970c4633c5000916b0a36022ff761038f5cf5aBrian 45c208a2c791fa24c7c5887fc496738cbddbfafc72José Fonseca#include "tgsi/tgsi_build.h" 46c208a2c791fa24c7c5887fc496738cbddbfafc72José Fonseca#include "tgsi/tgsi_dump.h" 47c208a2c791fa24c7c5887fc496738cbddbfafc72José Fonseca#include "tgsi/tgsi_parse.h" 4831970c4633c5000916b0a36022ff761038f5cf5aBrian 4931970c4633c5000916b0a36022ff761038f5cf5aBrian 5031970c4633c5000916b0a36022ff761038f5cf5aBrian 5131970c4633c5000916b0a36022ff761038f5cf5aBrian/** 5231970c4633c5000916b0a36022ff761038f5cf5aBrian * Make simple vertex pass-through shader. 5331970c4633c5000916b0a36022ff761038f5cf5aBrian */ 5431970c4633c5000916b0a36022ff761038f5cf5aBrianvoid * 5531970c4633c5000916b0a36022ff761038f5cf5aBrianutil_make_vertex_passthrough_shader(struct pipe_context *pipe, 5631970c4633c5000916b0a36022ff761038f5cf5aBrian uint num_attribs, 5731970c4633c5000916b0a36022ff761038f5cf5aBrian const uint *semantic_names, 58fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell const uint *semantic_indexes) 59dccbfd8bf0624250a435948029916073d3390191Brian 6031970c4633c5000916b0a36022ff761038f5cf5aBrian{ 61fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell struct pipe_shader_state shader; 62fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell struct tgsi_token tokens[100]; 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 7031970c4633c5000916b0a36022ff761038f5cf5aBrian /* shader header 7131970c4633c5000916b0a36022ff761038f5cf5aBrian */ 7231970c4633c5000916b0a36022ff761038f5cf5aBrian *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); 7331970c4633c5000916b0a36022ff761038f5cf5aBrian 7431970c4633c5000916b0a36022ff761038f5cf5aBrian header = (struct tgsi_header *) &tokens[1]; 7531970c4633c5000916b0a36022ff761038f5cf5aBrian *header = tgsi_build_header(); 7631970c4633c5000916b0a36022ff761038f5cf5aBrian 7731970c4633c5000916b0a36022ff761038f5cf5aBrian processor = (struct tgsi_processor *) &tokens[2]; 7831970c4633c5000916b0a36022ff761038f5cf5aBrian *processor = tgsi_build_processor( procType, header ); 7931970c4633c5000916b0a36022ff761038f5cf5aBrian 8031970c4633c5000916b0a36022ff761038f5cf5aBrian ti = 3; 8131970c4633c5000916b0a36022ff761038f5cf5aBrian 8231970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare inputs */ 8331970c4633c5000916b0a36022ff761038f5cf5aBrian for (i = 0; i < num_attribs; i++) { 8431970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 8531970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_INPUT; 8600cf178d93e5bc36a88a9f8ff444f60c493be14dBrian 8731970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 8800cf178d93e5bc36a88a9f8ff444f60c493be14dBrian decl.Semantic.SemanticName = semantic_names[i]; 8900cf178d93e5bc36a88a9f8ff444f60c493be14dBrian decl.Semantic.SemanticIndex = semantic_indexes[i]; 9000cf178d93e5bc36a88a9f8ff444f60c493be14dBrian 9156fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 9256fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = i; 9331970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 9431970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 9531970c4633c5000916b0a36022ff761038f5cf5aBrian header, 96fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 9731970c4633c5000916b0a36022ff761038f5cf5aBrian } 9831970c4633c5000916b0a36022ff761038f5cf5aBrian 9931970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare outputs */ 10031970c4633c5000916b0a36022ff761038f5cf5aBrian for (i = 0; i < num_attribs; i++) { 10131970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 10231970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_OUTPUT; 10331970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 10431970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticName = semantic_names[i]; 10531970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticIndex = semantic_indexes[i]; 10656fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 10756fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = i; 10831970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 10931970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 11031970c4633c5000916b0a36022ff761038f5cf5aBrian header, 111fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 11231970c4633c5000916b0a36022ff761038f5cf5aBrian } 11331970c4633c5000916b0a36022ff761038f5cf5aBrian 11431970c4633c5000916b0a36022ff761038f5cf5aBrian /* emit MOV instructions */ 11531970c4633c5000916b0a36022ff761038f5cf5aBrian for (i = 0; i < num_attribs; i++) { 11631970c4633c5000916b0a36022ff761038f5cf5aBrian /* MOVE out[i], in[i]; */ 11731970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 11831970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_MOV; 11931970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 1; 12031970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT; 12131970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.Index = i; 12231970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 1; 12331970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT; 12431970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.Index = i; 12531970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 12631970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 12731970c4633c5000916b0a36022ff761038f5cf5aBrian header, 128fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti ); 12931970c4633c5000916b0a36022ff761038f5cf5aBrian } 13031970c4633c5000916b0a36022ff761038f5cf5aBrian 13131970c4633c5000916b0a36022ff761038f5cf5aBrian /* END instruction */ 13231970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 13331970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_END; 13431970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 0; 13531970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 0; 13631970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 13731970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 13831970c4633c5000916b0a36022ff761038f5cf5aBrian header, 139fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti ); 14031970c4633c5000916b0a36022ff761038f5cf5aBrian 14131970c4633c5000916b0a36022ff761038f5cf5aBrian#if 0 /*debug*/ 14231970c4633c5000916b0a36022ff761038f5cf5aBrian tgsi_dump(tokens, 0); 14331970c4633c5000916b0a36022ff761038f5cf5aBrian#endif 14431970c4633c5000916b0a36022ff761038f5cf5aBrian 145fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell shader.tokens = tokens; 146dccbfd8bf0624250a435948029916073d3390191Brian 147fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell return pipe->create_vs_state(pipe, &shader); 14831970c4633c5000916b0a36022ff761038f5cf5aBrian} 14931970c4633c5000916b0a36022ff761038f5cf5aBrian 15031970c4633c5000916b0a36022ff761038f5cf5aBrian 15131970c4633c5000916b0a36022ff761038f5cf5aBrian 15231970c4633c5000916b0a36022ff761038f5cf5aBrian 15331970c4633c5000916b0a36022ff761038f5cf5aBrian/** 15431970c4633c5000916b0a36022ff761038f5cf5aBrian * Make simple fragment texture shader: 15531970c4633c5000916b0a36022ff761038f5cf5aBrian * TEX OUT[0], IN[0], SAMP[0], 2D; 15631970c4633c5000916b0a36022ff761038f5cf5aBrian * END; 15731970c4633c5000916b0a36022ff761038f5cf5aBrian */ 15831970c4633c5000916b0a36022ff761038f5cf5aBrianvoid * 159fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwellutil_make_fragment_tex_shader(struct pipe_context *pipe) 16031970c4633c5000916b0a36022ff761038f5cf5aBrian{ 161fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell struct pipe_shader_state shader; 162fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell struct tgsi_token tokens[100]; 16331970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_header *header; 16431970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_processor *processor; 16531970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_full_declaration decl; 16631970c4633c5000916b0a36022ff761038f5cf5aBrian struct tgsi_full_instruction inst; 16731970c4633c5000916b0a36022ff761038f5cf5aBrian const uint procType = TGSI_PROCESSOR_FRAGMENT; 16831970c4633c5000916b0a36022ff761038f5cf5aBrian uint ti; 16931970c4633c5000916b0a36022ff761038f5cf5aBrian 17031970c4633c5000916b0a36022ff761038f5cf5aBrian /* shader header 17131970c4633c5000916b0a36022ff761038f5cf5aBrian */ 17231970c4633c5000916b0a36022ff761038f5cf5aBrian *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); 17331970c4633c5000916b0a36022ff761038f5cf5aBrian 17431970c4633c5000916b0a36022ff761038f5cf5aBrian header = (struct tgsi_header *) &tokens[1]; 17531970c4633c5000916b0a36022ff761038f5cf5aBrian *header = tgsi_build_header(); 17631970c4633c5000916b0a36022ff761038f5cf5aBrian 17731970c4633c5000916b0a36022ff761038f5cf5aBrian processor = (struct tgsi_processor *) &tokens[2]; 17831970c4633c5000916b0a36022ff761038f5cf5aBrian *processor = tgsi_build_processor( procType, header ); 17931970c4633c5000916b0a36022ff761038f5cf5aBrian 18031970c4633c5000916b0a36022ff761038f5cf5aBrian ti = 3; 18131970c4633c5000916b0a36022ff761038f5cf5aBrian 18231970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare TEX[0] input */ 18331970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 18431970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_INPUT; 18556fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol /* XXX this could be linear... */ 18656fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE; 18731970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 18831970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC; 18931970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticIndex = 0; 19056fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 19156fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = 0; 19231970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 19331970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 19431970c4633c5000916b0a36022ff761038f5cf5aBrian header, 195fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 19631970c4633c5000916b0a36022ff761038f5cf5aBrian 19731970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare color[0] output */ 19831970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 19931970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_OUTPUT; 20031970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.Semantic = 1; 20131970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR; 20231970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Semantic.SemanticIndex = 0; 20356fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 20456fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = 0; 20531970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 20631970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 20731970c4633c5000916b0a36022ff761038f5cf5aBrian header, 208fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 20931970c4633c5000916b0a36022ff761038f5cf5aBrian 21031970c4633c5000916b0a36022ff761038f5cf5aBrian /* declare sampler */ 21131970c4633c5000916b0a36022ff761038f5cf5aBrian decl = tgsi_default_full_declaration(); 21231970c4633c5000916b0a36022ff761038f5cf5aBrian decl.Declaration.File = TGSI_FILE_SAMPLER; 21356fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 21456fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = 0; 21531970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_declaration(&decl, 21631970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 21731970c4633c5000916b0a36022ff761038f5cf5aBrian header, 218fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 21931970c4633c5000916b0a36022ff761038f5cf5aBrian 22031970c4633c5000916b0a36022ff761038f5cf5aBrian /* TEX instruction */ 22131970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 22231970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_TEX; 22331970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 1; 22431970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT; 22531970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullDstRegisters[0].DstRegister.Index = 0; 22631970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 2; 22731970c4633c5000916b0a36022ff761038f5cf5aBrian inst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D; 22831970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT; 22931970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[0].SrcRegister.Index = 0; 23031970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER; 23131970c4633c5000916b0a36022ff761038f5cf5aBrian inst.FullSrcRegisters[1].SrcRegister.Index = 0; 23231970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 23331970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 23431970c4633c5000916b0a36022ff761038f5cf5aBrian header, 235fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti ); 23631970c4633c5000916b0a36022ff761038f5cf5aBrian 23731970c4633c5000916b0a36022ff761038f5cf5aBrian /* END instruction */ 23831970c4633c5000916b0a36022ff761038f5cf5aBrian inst = tgsi_default_full_instruction(); 23931970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.Opcode = TGSI_OPCODE_END; 24031970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumDstRegs = 0; 24131970c4633c5000916b0a36022ff761038f5cf5aBrian inst.Instruction.NumSrcRegs = 0; 24231970c4633c5000916b0a36022ff761038f5cf5aBrian ti += tgsi_build_full_instruction(&inst, 24331970c4633c5000916b0a36022ff761038f5cf5aBrian &tokens[ti], 24431970c4633c5000916b0a36022ff761038f5cf5aBrian header, 245fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti ); 24631970c4633c5000916b0a36022ff761038f5cf5aBrian 24731970c4633c5000916b0a36022ff761038f5cf5aBrian#if 0 /*debug*/ 24831970c4633c5000916b0a36022ff761038f5cf5aBrian tgsi_dump(tokens, 0); 24931970c4633c5000916b0a36022ff761038f5cf5aBrian#endif 25031970c4633c5000916b0a36022ff761038f5cf5aBrian 251fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell shader.tokens = tokens; 252dccbfd8bf0624250a435948029916073d3390191Brian 253fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell return pipe->create_fs_state(pipe, &shader); 25431970c4633c5000916b0a36022ff761038f5cf5aBrian} 25531970c4633c5000916b0a36022ff761038f5cf5aBrian 2566a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2576a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2586a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2596a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2606a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian/** 2616a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian * Make simple fragment color pass-through shader. 2626a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian */ 2636a9a3afcf923ec5c67069cdb1656f52675cd8edeBrianvoid * 264fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwellutil_make_fragment_passthrough_shader(struct pipe_context *pipe) 2656a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian{ 266fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell struct pipe_shader_state shader; 267fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell struct tgsi_token tokens[40]; 2686a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_header *header; 2696a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_processor *processor; 2706a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_full_declaration decl; 2716a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian struct tgsi_full_instruction inst; 2726a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian const uint procType = TGSI_PROCESSOR_FRAGMENT; 273f259ea0347754e0e8c93fd16796fc1db72b03372Keith Whitwell uint ti; 2746a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2756a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* shader header 2766a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian */ 2776a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian *(struct tgsi_version *) &tokens[0] = tgsi_build_version(); 2786a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2796a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header = (struct tgsi_header *) &tokens[1]; 2806a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian *header = tgsi_build_header(); 2816a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2826a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian processor = (struct tgsi_processor *) &tokens[2]; 2836a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian *processor = tgsi_build_processor( procType, header ); 2846a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2856a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti = 3; 2866a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 2876a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* declare input */ 2886a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl = tgsi_default_full_declaration(); 2896a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.File = TGSI_FILE_INPUT; 2906a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.Semantic = 1; 2916a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR; 2926a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticIndex = 0; 29356fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 29456fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = 0; 2956a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_declaration(&decl, 2966a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 2976a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 298fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 2996a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3006a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* declare output */ 3016a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl = tgsi_default_full_declaration(); 3026a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.File = TGSI_FILE_OUTPUT; 3036a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Declaration.Semantic = 1; 3046a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR; 3056a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian decl.Semantic.SemanticIndex = 0; 30656fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.First = 30756fc7690d791819d81ff1c6e6e22d22017c68919Michal Krol decl.DeclarationRange.Last = 0; 3086a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_declaration(&decl, 3096a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3106a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 311fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti); 3126a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3136a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3146a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* MOVE out[0], in[0]; */ 3156a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst = tgsi_default_full_instruction(); 3166a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.Opcode = TGSI_OPCODE_MOV; 3176a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumDstRegs = 1; 3186a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT; 3196a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullDstRegisters[0].DstRegister.Index = 0; 3206a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumSrcRegs = 1; 3216a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT; 3226a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.FullSrcRegisters[0].SrcRegister.Index = 0; 3236a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_instruction(&inst, 3246a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3256a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 326fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti ); 3276a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3286a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian /* END instruction */ 3296a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst = tgsi_default_full_instruction(); 3306a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.Opcode = TGSI_OPCODE_END; 3316a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumDstRegs = 0; 3326a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian inst.Instruction.NumSrcRegs = 0; 3336a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian ti += tgsi_build_full_instruction(&inst, 3346a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian &tokens[ti], 3356a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian header, 336fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell Elements(tokens) - ti ); 3376a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 338fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell assert(ti < Elements(tokens)); 3396a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 3406a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian#if 0 /*debug*/ 3416a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian tgsi_dump(tokens, 0); 3426a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian#endif 3436a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 344fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell shader.tokens = tokens; 345dccbfd8bf0624250a435948029916073d3390191Brian 346fa0f48504a32642d688d4b81f62eea54c693b23fKeith Whitwell return pipe->create_fs_state(pipe, &shader); 3476a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian} 3486a9a3afcf923ec5c67069cdb1656f52675cd8edeBrian 34985b0c171c04c00b4ca9e11a1c79872f5e0cbaf9cJosé Fonseca 350