draw_vs_variant.c revision 89d8577fb3036547ef0b47498cc8dc5c77f886e0
17c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell/************************************************************************** 27c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 37c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 47c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * All Rights Reserved. 57c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 67c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 77c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * copy of this software and associated documentation files (the 87c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * "Software"), to deal in the Software without restriction, including 97c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 107c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 117c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to 127c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * the following conditions: 137c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 147c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * The above copyright notice and this permission notice (including the 157c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * next paragraph) shall be included in all copies or substantial portions 167c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * of the Software. 177c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 187c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 197c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 207c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 217c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 227c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 237c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 247c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 257c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 267c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell **************************************************************************/ 277c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 287c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell /* 297c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * Authors: 307c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * Keith Whitwell <keith@tungstengraphics.com> 317c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 327c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 334f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 344f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_math.h" 357c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "draw/draw_context.h" 367c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "draw/draw_private.h" 377c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "draw/draw_vbuf.h" 387c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "draw/draw_vertex.h" 397c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "draw/draw_vs.h" 407c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "translate/translate.h" 417c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell#include "translate/translate_cache.h" 427c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 437c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell/* A first pass at incorporating vertex fetch/emit functionality into 447c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 457c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwellstruct draw_vs_varient_generic { 467c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vs_varient base; 477c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 487c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vertex_shader *shader; 497c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_context *draw; 507c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 517c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell /* Basic plan is to run these two translate functions before/after 527c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * the vertex shader's existing run_linear() routine to simulate 537c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * the inclusion of this functionality into the shader... 547c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 557c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * Next will look at actually including it. 567c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 577c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct translate *fetch; 587c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct translate *emit; 59463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 60463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned temp_vertex_stride; 617c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell}; 627c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 637c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 647c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 657c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 667c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 6721f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwellstatic void vsvg_set_buffer( struct draw_vs_varient *varient, 6821f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell unsigned buffer, 6921f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell const void *ptr, 7021f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell unsigned stride ) 717c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 727c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient; 737c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 747c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch->set_buffer(vsvg->fetch, 757c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell buffer, 767c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell ptr, 777c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell stride); 787c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 797c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 807c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 81584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell/* Mainly for debug at this stage: 82584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell */ 83a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwellstatic void do_rhw_viewport( struct draw_vs_varient_generic *vsvg, 84a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell unsigned count, 85a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell void *output_buffer ) 86584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell{ 87584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell char *ptr = (char *)output_buffer; 8862628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell const float *scale = vsvg->base.vs->draw->viewport.scale; 8962628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell const float *trans = vsvg->base.vs->draw->viewport.translate; 90463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned stride = vsvg->temp_vertex_stride; 91584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell unsigned j; 92584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 932161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell ptr += vsvg->base.vs->position_output * 4 * sizeof(float); 942161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell 95584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell for (j = 0; j < count; j++, ptr += stride) { 96584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell float *data = (float *)ptr; 97584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell float w = 1.0f / data[3]; 98584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 99584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[0] = data[0] * w * scale[0] + trans[0]; 100584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[1] = data[1] * w * scale[1] + trans[1]; 101584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[2] = data[2] * w * scale[2] + trans[2]; 102584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[3] = w; 103584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell } 104584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell} 105a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell 106a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwellstatic void do_viewport( struct draw_vs_varient_generic *vsvg, 107463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned count, 108463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell void *output_buffer ) 109a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell{ 110a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell char *ptr = (char *)output_buffer; 11162628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell const float *scale = vsvg->base.vs->draw->viewport.scale; 11262628c4d3d497cbca73fde869c9069fa90e6453eKeith Whitwell const float *trans = vsvg->base.vs->draw->viewport.translate; 113463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned stride = vsvg->temp_vertex_stride; 114a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell unsigned j; 115a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell 1162161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell ptr += vsvg->base.vs->position_output * 4 * sizeof(float); 1172161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell 118a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell for (j = 0; j < count; j++, ptr += stride) { 119a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell float *data = (float *)ptr; 120a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell 121a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell data[0] = data[0] * scale[0] + trans[0]; 122a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell data[1] = data[1] * scale[1] + trans[1]; 123a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell data[2] = data[2] * scale[2] + trans[2]; 124a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell } 125a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell} 126584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 127584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 1286945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonsecastatic void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient, 1296945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca const unsigned *elts, 1306945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca unsigned count, 1316945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca void *output_buffer) 1327c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 1337c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient; 134463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned temp_vertex_stride = vsvg->temp_vertex_stride; 135463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride ); 136463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 137b98ac1d47257bf7b2661ae7c1a8904b7bc5d623cKeith Whitwell if (0) debug_printf("%s %d \n", __FUNCTION__, count); 1387c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 1397c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell /* Want to do this in small batches for cache locality? 1407c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 1417c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 1427c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch->run_elts( vsvg->fetch, 1437c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell elts, 1447c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell count, 145a47c222803483c208f720e3fb5015050d4d0eaf4Keith Whitwell temp_buffer ); 1467c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 147463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.vs->run_linear( vsvg->base.vs, 148463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 149463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 15089d8577fb3036547ef0b47498cc8dc5c77f886e0Zack Rusin (const float (*)[4])vsvg->base.vs->draw->pt.user.vs_constants, 151463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 152463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride, 153463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride); 154463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 15589d8577fb3036547ef0b47498cc8dc5c77f886e0Zack Rusin /* FIXME: geometry shading? */ 156463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 157463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell if (vsvg->base.key.clip) { 158463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell /* not really handling clipping, just do the rhw so we can 159463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell * see the results... 160463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell */ 161463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_rhw_viewport( vsvg, 162463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 163463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 164463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 165463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell else if (vsvg->base.key.viewport) { 166463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_viewport( vsvg, 167463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 168463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 169463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 170584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 171584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 172463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 173463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, 174463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 175463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride ); 1767c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 177463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 178463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 1, 179463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell &vsvg->draw->rasterizer->point_size, 180463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0); 1817c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 182463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->run( vsvg->emit, 183463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, count, 184463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell output_buffer ); 1857c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 186463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell FREE(temp_buffer); 1877c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 1887c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 1897c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 1906945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonsecastatic void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient, 1916945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca unsigned start, 1926945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca unsigned count, 1936945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca void *output_buffer ) 1947c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 1957c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient; 196463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned temp_vertex_stride = vsvg->temp_vertex_stride; 197463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride ); 1987c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 199463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell if (0) debug_printf("%s %d %d (sz %d, %d)\n", __FUNCTION__, start, count, 200463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.key.output_stride, 201463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride); 202463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 2037c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch->run( vsvg->fetch, 2047c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell start, 2057c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell count, 206463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 207463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 208463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.vs->run_linear( vsvg->base.vs, 209463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 210463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 21189d8577fb3036547ef0b47498cc8dc5c77f886e0Zack Rusin (const float (*)[4])vsvg->base.vs->draw->pt.user.vs_constants, 212463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 213463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride, 214463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride); 215463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 216463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell if (vsvg->base.key.clip) { 217463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell /* not really handling clipping, just do the rhw so we can 218463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell * see the results... 219463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell */ 220463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_rhw_viewport( vsvg, 221463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 222463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 223463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 224463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell else if (vsvg->base.key.viewport) { 225463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_viewport( vsvg, 226463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 227463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 228463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 2297c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 230463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 231463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, 232463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 233463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride ); 234463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 235463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 236463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 1, 237463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell &vsvg->draw->rasterizer->point_size, 238463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0); 239463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 240463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->run( vsvg->emit, 241463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, count, 242463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell output_buffer ); 2437c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 244463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell FREE(temp_buffer); 2457c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 2467c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2477c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2487c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 249889473b3f5a216bd753c357974d6bae29fe3c41dKeith Whitwell 250889473b3f5a216bd753c357974d6bae29fe3c41dKeith Whitwell 2517c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwellstatic void vsvg_destroy( struct draw_vs_varient *varient ) 2527c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 2537c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell FREE(varient); 2547c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 2557c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2567c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2577c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwellstruct draw_vs_varient *draw_vs_varient_generic( struct draw_vertex_shader *vs, 2587c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell const struct draw_vs_varient_key *key ) 2597c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 2607c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell unsigned i; 2617c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct translate_key fetch, emit; 2627c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2637c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vs_varient_generic *vsvg = CALLOC_STRUCT( draw_vs_varient_generic ); 2647c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell if (vsvg == NULL) 2657c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell return NULL; 2667c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2677c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.key = *key; 2687c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.vs = vs; 26921f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell vsvg->base.set_buffer = vsvg_set_buffer; 2707c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.run_elts = vsvg_run_elts; 2717c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.run_linear = vsvg_run_linear; 2727c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.destroy = vsvg_destroy; 2737c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 274b98ac1d47257bf7b2661ae7c1a8904b7bc5d623cKeith Whitwell vsvg->draw = vs->draw; 2757c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 276463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->temp_vertex_stride = MAX2(key->nr_inputs, 277463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.vs->info.num_outputs) * 4 * sizeof(float); 2787c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 279f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell /* Build free-standing fetch and emit functions: 2807c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 281f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell fetch.nr_elements = key->nr_inputs; 282463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell fetch.output_stride = vsvg->temp_vertex_stride; 283f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell for (i = 0; i < key->nr_inputs; i++) { 2847c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].input_format = key->element[i].in.format; 2857c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].input_buffer = key->element[i].in.buffer; 2867c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].input_offset = key->element[i].in.offset; 2877c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 288463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell fetch.element[i].output_offset = i * 4 * sizeof(float); 289463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell assert(fetch.element[i].output_offset < fetch.output_stride); 2907c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell } 2917c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2927c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 293f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell emit.nr_elements = key->nr_outputs; 2947c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell emit.output_stride = key->output_stride; 295f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell for (i = 0; i < key->nr_outputs; i++) { 2967b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell if (key->element[i].out.format != EMIT_1F_PSIZE) 2977b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell { 2987b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 2997b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_buffer = 0; 3007b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_offset = key->element[i].out.vs_output * 4 * sizeof(float); 3017b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_format = draw_translate_vinfo_format(key->element[i].out.format); 3027b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_offset = key->element[i].out.offset; 30363c0970dca9c13ab83ea24f108b41f75f2a290a7Brian Paul assert(emit.element[i].input_offset <= fetch.output_stride); 3047b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell } 3057b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell else { 3067b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_format = PIPE_FORMAT_R32_FLOAT; 3077b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_buffer = 1; 3087b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_offset = 0; 3097b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_format = PIPE_FORMAT_R32_FLOAT; 3107b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_offset = key->element[i].out.offset; 3117b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell } 3127c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell } 3137c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3147c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch = draw_vs_get_fetch( vs->draw, &fetch ); 3157c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->emit = draw_vs_get_emit( vs->draw, &emit ); 3167c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3177c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell return &vsvg->base; 3187c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 3197c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3207c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3217c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3227c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3237c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 324