123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* 223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mesa 3-D graphics library 35e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 44b3835dadf37267ad5fba8ffd675e826d3691f9aBrian Paul * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 55e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * copy of this software and associated documentation files (the "Software"), 823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to deal in the Software without restriction, including without limitation 923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 1123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Software is furnished to do so, subject to the following conditions: 125e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 1323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * The above copyright notice and this permission notice shall be included 1423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * in all copies or substantial portions of the Software. 155e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen * 1623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 193d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 203d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 213d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 223d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * OTHER DEALINGS IN THE SOFTWARE. 23cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 2422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * Authors: 25877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Keith Whitwell <keithw@vmware.com> 2623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 2723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 28c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian Paul#include "main/glheader.h" 29c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian Paul#include "main/context.h" 30c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian Paul#include "main/imports.h" 31c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian Paul#include "main/mtypes.h" 3223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 33cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell#include "t_context.h" 3423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#include "t_pipeline.h" 356f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell#include "t_vp_build.h" 362b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell#include "t_vertex.h" 3723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 38f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid _tnl_install_pipeline( struct gl_context *ctx, 39ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell const struct tnl_pipeline_stage **stages ) 4023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 4123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 4223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLuint i; 4323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 446f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.new_state = ~0; 4523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 46cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell /* Create a writeable copy of each stage. 4723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 48cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) { 496f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 50e197de56cdb86835f1437688a9161cd909792d80Brian Paul memcpy(s, stages[i], sizeof(*s)); 516f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (s->create) 526f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell s->create(ctx, s); 5323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 545e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 556f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.nr_stages = i; 5623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} 5723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 58f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid _tnl_destroy_pipeline( struct gl_context *ctx ) 5923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 6023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 61cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell GLuint i; 625e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 636f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) { 646f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 656f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (s->destroy) 666f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell s->destroy(s); 676f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell } 685e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 69cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell tnl->pipeline.nr_stages = 0; 7023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} 7123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 726f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 736f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 74f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic GLuint check_input_changes( struct gl_context *ctx ) 7523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 7623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 776f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell GLuint i; 786f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 7994b30dc390f1fdd526c080080830016fad3e2ee2Brian Paul for (i = 0; i <= _TNL_LAST_MAT; i++) { 806f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (tnl->vb.AttribPtr[i]->size != tnl->pipeline.last_attrib_size[i] || 816f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->vb.AttribPtr[i]->stride != tnl->pipeline.last_attrib_stride[i]) { 826f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.last_attrib_size[i] = tnl->vb.AttribPtr[i]->size; 836f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.last_attrib_stride[i] = tnl->vb.AttribPtr[i]->stride; 846f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.input_changes |= 1<<i; 8523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 866f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell } 876f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 886f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell return tnl->pipeline.input_changes; 896f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell} 906f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 9123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 92f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic GLuint check_output_changes( struct gl_context *ctx ) 936f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell{ 946f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell#if 0 956f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 966f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 9736b252e94724b2512ea941eff2b3a3abeb80be79Paul Berry for (i = 0; i < VARYING_SLOT_MAX; i++) { 986f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (tnl->vb.ResultPtr[i]->size != tnl->last_result_size[i] || 996f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->vb.ResultPtr[i]->stride != tnl->last_result_stride[i]) { 1006f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->last_result_size[i] = tnl->vb.ResultPtr[i]->size; 1016f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->last_result_stride[i] = tnl->vb.ResultPtr[i]->stride; 1026f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.output_changes |= 1<<i; 10322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes } 10423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 10523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 1066f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (tnl->pipeline.output_changes) 1076f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes ); 1082b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell 1092b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell return tnl->pipeline.output_changes; 1102b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell#else 1112b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell return ~0; 1126f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell#endif 1136f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell} 11423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 115bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner/** 116bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * START/END_FAST_MATH macros: 117bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * 118bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * START_FAST_MATH: Set x86 FPU to faster, 32-bit precision mode (and save 119bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * original mode to a temporary). 120bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * END_FAST_MATH: Restore x86 FPU to original mode. 121bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner */ 122bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#if defined(__GNUC__) && defined(__i386__) 123bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner/* 124bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * Set the x86 FPU control word to guarentee only 32 bits of precision 125bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * are stored in registers. Allowing the FPU to store more introduces 126bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * differences between situations where numbers are pulled out of memory 127bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * vs. situations where the compiler is able to optimize register usage. 128bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * 129bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * In the worst case, we force the compiler to use a memory access to 130bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * truncate the float, by specifying the 'volatile' keyword. 131bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner */ 132bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner/* Hardware default: All exceptions masked, extended double precision, 133bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * round to nearest (IEEE compliant): 134bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner */ 135bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define DEFAULT_X86_FPU 0x037f 136bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner/* All exceptions masked, single precision, round to nearest: 137bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner */ 138bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define FAST_X86_FPU 0x003f 139bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner/* The fldcw instruction will cause any pending FP exceptions to be 140bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * raised prior to entering the block, and we clear any pending 141bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * exceptions before exiting the block. Hence, asm code has free 142bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * reign over the FPU while in the fast math block. 143bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner */ 144bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#if defined(NO_FAST_MATH) 145bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define START_FAST_MATH(x) \ 146bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turnerdo { \ 147bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner static GLuint mask = DEFAULT_X86_FPU; \ 148bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \ 149bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm__ ( "fldcw %0" : : "m" (mask) ); \ 150bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner} while (0) 151bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#else 152bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define START_FAST_MATH(x) \ 153bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turnerdo { \ 154bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner static GLuint mask = FAST_X86_FPU; \ 155bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm__ ( "fnstcw %0" : "=m" (*&(x)) ); \ 156bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm__ ( "fldcw %0" : : "m" (mask) ); \ 157bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner} while (0) 158bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#endif 159bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner/* Restore original FPU mode, and clear any exceptions that may have 160bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner * occurred in the FAST_MATH block. 161bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner */ 162bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define END_FAST_MATH(x) \ 163bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turnerdo { \ 164bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm__ ( "fnclex ; fldcw %0" : : "m" (*&(x)) ); \ 165bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner} while (0) 166bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner 167bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#elif defined(_MSC_VER) && defined(_M_IX86) 168bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define DEFAULT_X86_FPU 0x037f /* See GCC comments above */ 169bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define FAST_X86_FPU 0x003f /* See GCC comments above */ 170bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#if defined(NO_FAST_MATH) 171bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define START_FAST_MATH(x) do {\ 172bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner static GLuint mask = DEFAULT_X86_FPU;\ 173bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm fnstcw word ptr [x]\ 174bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm fldcw word ptr [mask]\ 175bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner} while(0) 176bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#else 177bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define START_FAST_MATH(x) do {\ 178bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner static GLuint mask = FAST_X86_FPU;\ 179bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm fnstcw word ptr [x]\ 180bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm fldcw word ptr [mask]\ 181bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner} while(0) 182bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#endif 183bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define END_FAST_MATH(x) do {\ 184bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm fnclex\ 185bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner __asm fldcw word ptr [x]\ 186bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner} while(0) 187bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner 188bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#else 189bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define START_FAST_MATH(x) x = 0 190bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#define END_FAST_MATH(x) (void)(x) 191bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner#endif 192bb2a897dbc8064ccd38ecbf3f484abc0b900a862Matt Turner 19323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 194f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid _tnl_run_pipeline( struct gl_context *ctx ) 19523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell{ 19623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell TNLcontext *tnl = TNL_CONTEXT(ctx); 197cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell unsigned short __tmp; 1986f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell GLuint i; 19923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 200790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell if (!tnl->vb.Count) 201790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell return; 202790734045b69c47b1525fbf9106a7ca5a8eb7416Keith Whitwell 2036f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell /* Check for changed input sizes or change in stride to/from zero 2046f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell * (ie const or non-const). 205cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 2066f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (check_input_changes( ctx ) || tnl->pipeline.new_state) { 207a328e469d328f8b6fd5afdfc21d576fa1a2c43fcBrian Paul if (ctx->VertexProgram._MaintainTnlProgram) 20881032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwell _tnl_UpdateFixedFunctionProgram( ctx ); 209a661654a33ba38990719ac9f5aea2910a5d5bf77Keith Whitwell 2106f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell for (i = 0; i < tnl->pipeline.nr_stages ; i++) { 2116f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 2126f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (s->validate) 2136f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell s->validate( ctx, s ); 2146f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell } 2156f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell 2166f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.new_state = 0; 2176f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell tnl->pipeline.input_changes = 0; 2182b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell 2192b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell /* Pipeline can only change its output in response to either a 2202b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell * statechange or an input size/stride change. No other changes 2212b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell * are allowed. 2222b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell */ 2232b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell if (check_output_changes( ctx )) 2242b2bd08589099cb480b983835b01cc76a766a3c4Keith Whitwell _tnl_notify_pipeline_output_change( ctx ); 2256f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell } 2265e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 227e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger#ifndef _OPENMP 228e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger /* Don't adjust FPU precision mode in case multiple threads are to be used. 229e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger * This would require that the additional threads also changed the FPU mode 230e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger * which is quite a mess as this had to be done in all parallelized sections; 231e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger * otherwise the master thread and all other threads are running in different 232e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger * modes, producing inconsistent results. 233e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger * Note that all x64 implementations don't define/use START_FAST_MATH, so 234e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger * this is "hack" is only used in i386 mode 235e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger */ 2366f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell START_FAST_MATH(__tmp); 237e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger#endif 23816837e4219e03df36c34f08cee1967b946c44536Keith Whitwell 2396f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell for (i = 0; i < tnl->pipeline.nr_stages ; i++) { 2406f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 2416f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell if (!s->run( ctx, s )) 2426f973f33679e034b7cb63806f1ddfabdbdd70123Keith Whitwell break; 24323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell } 244c6b2a92613a5110dbf387721af8ec505744183b9Keith Whitwell 245e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger#ifndef _OPENMP 246cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell END_FAST_MATH(__tmp); 247e411cd7b0a54d2f9b9f4cda4918aa7742ed5c2a6Andreas Fänger#endif 24823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} 24923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 25023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 2515e3bc0c2a2bcdf59949410f94c9b705fc1281ce8Jouk Jansen 252cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell/* The default pipeline. This is useful for software rasterizers, and 253cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * simple hardware rasterizers. For customization, I don't recommend 254cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * tampering with the internals of these stages in the way that 255cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * drivers did in Mesa 3.4. These stages are basically black boxes, 25622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * and should be left intact. 257cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 25822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * To customize the pipeline, consider: 259cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 260cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * - removing redundant stages (making sure that the software rasterizer 261cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * can cope with this on fallback paths). An example is fog 262cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * coordinate generation, which is not required in the FX driver. 263cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 264cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * - replacing general-purpose machine-independent stages with 265cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * general-purpose machine-specific stages. There is no example of 266cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * this to date, though it must be borne in mind that all subsequent 267cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * stages that reference the output of the new stage must cope with 268cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * any machine-specific data introduced. This may not be easy 269cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * unless there are no such stages (ie the new stage is the last in 270cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * the pipe). 271cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 272cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * - inserting optimized (but specialized) stages ahead of the 273cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * general-purpose fallback implementation. For example, the old 274ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell * fastpath mechanism, which only works when the VB->Elts input is 275cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * available, can be duplicated by placing the fastpath stage at the 276cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * head of this pipeline. Such specialized stages are currently 277cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * constrained to have no outputs (ie. they must either finish the * 278cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * pipeline by returning GL_FALSE from run(), or do nothing). 279cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * 280cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell * Some work can be done to lift some of the restrictions in the final 28122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * case, if it becomes necessary to do so. 282cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell */ 283ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwellconst struct tnl_pipeline_stage *_tnl_default_pipeline[] = { 28422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes &_tnl_vertex_transform_stage, 28522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes &_tnl_normal_transform_stage, 28622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes &_tnl_lighting_stage, 28722144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes &_tnl_texgen_stage, 28822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes &_tnl_texture_transform_stage, 28922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes &_tnl_point_attenuation_stage, 29081032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwell &_tnl_vertex_program_stage, 291e9d1889891ce32ffb3d6425f1e70510ea2c3e24bH. Verbeet &_tnl_fog_coordinate_stage, 292cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell &_tnl_render_stage, 293b97e478fe90f612041e27852eb8c95f45467bde8Keith Whitwell NULL 294cab974cf6c2dbfbf5dd5d291e1aae0f8eeb34290Keith Whitwell}; 29581032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwell 29681032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwellconst struct tnl_pipeline_stage *_tnl_vp_pipeline[] = { 2974b3835dadf37267ad5fba8ffd675e826d3691f9aBrian Paul &_tnl_vertex_program_stage, 29881032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwell &_tnl_render_stage, 29981032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwell NULL 30081032030ff42dd78133d85f7cabab5fb4c9aaf1eKeith Whitwell}; 301