17c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell/************************************************************************** 27c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2007 VMware, Inc. 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. 21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE 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: 30877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Keith Whitwell <keithw@vmware.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 427c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell/* A first pass at incorporating vertex fetch/emit functionality into 437c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 44b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstruct draw_vs_variant_generic { 45b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul struct draw_vs_variant base; 467c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 477c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_vertex_shader *shader; 487c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct draw_context *draw; 497c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 507c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell /* Basic plan is to run these two translate functions before/after 517c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * the vertex shader's existing run_linear() routine to simulate 527c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * the inclusion of this functionality into the shader... 537c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * 547c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell * Next will look at actually including it. 557c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 567c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct translate *fetch; 577c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct translate *emit; 58463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 59463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned temp_vertex_stride; 607c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell}; 617c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 627c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 637c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 647c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 657c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 66b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstatic void vsvg_set_buffer( struct draw_vs_variant *variant, 6721f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell unsigned buffer, 6821f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell const void *ptr, 692a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca unsigned stride, 702a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca unsigned max_index ) 717c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 72b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant; 737c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 747c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch->set_buffer(vsvg->fetch, 757c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell buffer, 767c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell ptr, 772a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca stride, 782a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca max_index ); 797c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 807c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 817756aae815a26c533948081c2c319c20bcf5962cZack Rusinstatic const struct pipe_viewport_state * 827756aae815a26c533948081c2c319c20bcf5962cZack Rusinfind_viewport(struct draw_context *draw, 837756aae815a26c533948081c2c319c20bcf5962cZack Rusin char *buffer, 847756aae815a26c533948081c2c319c20bcf5962cZack Rusin unsigned vertex_idx, 857756aae815a26c533948081c2c319c20bcf5962cZack Rusin unsigned stride) 867756aae815a26c533948081c2c319c20bcf5962cZack Rusin{ 877756aae815a26c533948081c2c319c20bcf5962cZack Rusin int viewport_index_output = 887756aae815a26c533948081c2c319c20bcf5962cZack Rusin draw_current_shader_viewport_index_output(draw); 897756aae815a26c533948081c2c319c20bcf5962cZack Rusin char *ptr = buffer + vertex_idx * stride; 907756aae815a26c533948081c2c319c20bcf5962cZack Rusin unsigned *data = (unsigned *)ptr; 917756aae815a26c533948081c2c319c20bcf5962cZack Rusin int viewport_index = 927756aae815a26c533948081c2c319c20bcf5962cZack Rusin draw_current_shader_uses_viewport_index(draw) ? 937756aae815a26c533948081c2c319c20bcf5962cZack Rusin data[viewport_index_output * 4] : 0; 94d7d676252d2ae1fd6d3dd76d4e205251ad7c6152Zack Rusin 95d7d676252d2ae1fd6d3dd76d4e205251ad7c6152Zack Rusin viewport_index = draw_clamp_viewport_idx(viewport_index); 967756aae815a26c533948081c2c319c20bcf5962cZack Rusin 977756aae815a26c533948081c2c319c20bcf5962cZack Rusin return &draw->viewports[viewport_index]; 987756aae815a26c533948081c2c319c20bcf5962cZack Rusin} 997756aae815a26c533948081c2c319c20bcf5962cZack Rusin 1007c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 101584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell/* Mainly for debug at this stage: 102584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell */ 103b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstatic void do_rhw_viewport( struct draw_vs_variant_generic *vsvg, 104a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell unsigned count, 105a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell void *output_buffer ) 106584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell{ 107584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell char *ptr = (char *)output_buffer; 108463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned stride = vsvg->temp_vertex_stride; 109584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell unsigned j; 110584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 1112161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell ptr += vsvg->base.vs->position_output * 4 * sizeof(float); 1122161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell 113584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell for (j = 0; j < count; j++, ptr += stride) { 1147756aae815a26c533948081c2c319c20bcf5962cZack Rusin const struct pipe_viewport_state *viewport = 1157756aae815a26c533948081c2c319c20bcf5962cZack Rusin find_viewport(vsvg->base.vs->draw, (char*)output_buffer, 1167756aae815a26c533948081c2c319c20bcf5962cZack Rusin j, stride); 1177756aae815a26c533948081c2c319c20bcf5962cZack Rusin const float *scale = viewport->scale; 1187756aae815a26c533948081c2c319c20bcf5962cZack Rusin const float *trans = viewport->translate; 119584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell float *data = (float *)ptr; 120584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell float w = 1.0f / data[3]; 121584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 122584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[0] = data[0] * w * scale[0] + trans[0]; 123584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[1] = data[1] * w * scale[1] + trans[1]; 124584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[2] = data[2] * w * scale[2] + trans[2]; 125584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell data[3] = w; 126584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell } 127584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell} 128a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell 129b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstatic void do_viewport( struct draw_vs_variant_generic *vsvg, 130463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned count, 131463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell void *output_buffer ) 132a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell{ 133a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell char *ptr = (char *)output_buffer; 134463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned stride = vsvg->temp_vertex_stride; 135a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell unsigned j; 136a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell 1372161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell ptr += vsvg->base.vs->position_output * 4 * sizeof(float); 1382161b0fafcdc16703162dd489d2ec1e7114cce4cKeith Whitwell 139a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell for (j = 0; j < count; j++, ptr += stride) { 1407756aae815a26c533948081c2c319c20bcf5962cZack Rusin const struct pipe_viewport_state *viewport = 1417756aae815a26c533948081c2c319c20bcf5962cZack Rusin find_viewport(vsvg->base.vs->draw, (char*)output_buffer, 1427756aae815a26c533948081c2c319c20bcf5962cZack Rusin j, stride); 1437756aae815a26c533948081c2c319c20bcf5962cZack Rusin const float *scale = viewport->scale; 1447756aae815a26c533948081c2c319c20bcf5962cZack Rusin const float *trans = viewport->translate; 145a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell float *data = (float *)ptr; 146a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell 147a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell data[0] = data[0] * scale[0] + trans[0]; 148a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell data[1] = data[1] * scale[1] + trans[1]; 149a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell data[2] = data[2] * scale[2] + trans[2]; 150a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell } 151a08c574bfcf72c7f7ffbeb35c10347b491ef87fbKeith Whitwell} 152584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 153584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 154b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstatic void PIPE_CDECL vsvg_run_elts( struct draw_vs_variant *variant, 1556945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca const unsigned *elts, 1566945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca unsigned count, 1576945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca void *output_buffer) 1587c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 159b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant; 160463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned temp_vertex_stride = vsvg->temp_vertex_stride; 161463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride ); 162463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 163b98ac1d47257bf7b2661ae7c1a8904b7bc5d623cKeith Whitwell if (0) debug_printf("%s %d \n", __FUNCTION__, count); 1647c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 1657c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell /* Want to do this in small batches for cache locality? 1667c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 1677c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 1687c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch->run_elts( vsvg->fetch, 1697c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell elts, 1707c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell count, 1711c2e5c223da28cdffe156b6b430fcdf638909021Zack Rusin vsvg->draw->start_instance, 1725007e39f76c897b8f3aa4acf6086c8b7ac30bdefMichal Krol vsvg->draw->instance_id, 173a47c222803483c208f720e3fb5015050d4d0eaf4Keith Whitwell temp_buffer ); 1747c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 175463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.vs->run_linear( vsvg->base.vs, 176463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 177463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 178ba2cc3b8e6ad161181b67fd2575c6bc768584d23Brian Paul vsvg->base.vs->draw->pt.user.vs_constants, 179ba2cc3b8e6ad161181b67fd2575c6bc768584d23Brian Paul vsvg->base.vs->draw->pt.user.vs_constants_size, 180463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 181463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride, 182463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride); 183463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 18489d8577fb3036547ef0b47498cc8dc5c77f886e0Zack Rusin /* FIXME: geometry shading? */ 185463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 186463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell if (vsvg->base.key.clip) { 187463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell /* not really handling clipping, just do the rhw so we can 188463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell * see the results... 189463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell */ 190463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_rhw_viewport( vsvg, 191463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 192463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 193463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 194463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell else if (vsvg->base.key.viewport) { 195463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_viewport( vsvg, 196463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 197463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 198463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 199584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 200584a3dcf8e4042cc1a5d48d83ea63d0a3c9706c1Keith Whitwell 201463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 202463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, 203463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 2042a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca temp_vertex_stride, 2052a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0 ); 2067c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 207463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 208463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 1, 209463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell &vsvg->draw->rasterizer->point_size, 2102a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca 0, 2112a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0 ); 2127c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 213463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->run( vsvg->emit, 214463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, count, 2151c2e5c223da28cdffe156b6b430fcdf638909021Zack Rusin vsvg->draw->start_instance, 2167ca0ce38340144794267609646048b3820d594abMichal Krol vsvg->draw->instance_id, 217463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell output_buffer ); 2187c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 219463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell FREE(temp_buffer); 2207c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 2217c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2227c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 223b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstatic void PIPE_CDECL vsvg_run_linear( struct draw_vs_variant *variant, 2246945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca unsigned start, 2256945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca unsigned count, 2266945bcb89370501e0a218bc656e68e30e4dadcdaJosé Fonseca void *output_buffer ) 2277c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 228b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant; 229463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell unsigned temp_vertex_stride = vsvg->temp_vertex_stride; 230463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride ); 2317c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 232463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell if (0) debug_printf("%s %d %d (sz %d, %d)\n", __FUNCTION__, start, count, 233463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.key.output_stride, 234463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride); 235463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 2367c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch->run( vsvg->fetch, 2377c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell start, 2387c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell count, 2391c2e5c223da28cdffe156b6b430fcdf638909021Zack Rusin vsvg->draw->start_instance, 2407ca0ce38340144794267609646048b3820d594abMichal Krol vsvg->draw->instance_id, 241463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 242463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 243463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->base.vs->run_linear( vsvg->base.vs, 244463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 245463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 246ba2cc3b8e6ad161181b67fd2575c6bc768584d23Brian Paul vsvg->base.vs->draw->pt.user.vs_constants, 247ba2cc3b8e6ad161181b67fd2575c6bc768584d23Brian Paul vsvg->base.vs->draw->pt.user.vs_constants_size, 248463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 249463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride, 250463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_vertex_stride); 251463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 252463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell if (vsvg->base.key.clip) { 253463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell /* not really handling clipping, just do the rhw so we can 254463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell * see the results... 255463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell */ 256463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_rhw_viewport( vsvg, 257463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 258463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 259463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 260463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell else if (vsvg->base.key.viewport) { 261463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell do_viewport( vsvg, 262463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell count, 263463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer ); 264463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell } 2657c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 266463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 267463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, 268463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell temp_buffer, 2692a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca temp_vertex_stride, 2702a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0 ); 271463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 272463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->set_buffer( vsvg->emit, 273463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 1, 274463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell &vsvg->draw->rasterizer->point_size, 2752a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca 0, 2762a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0 ); 277463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 278463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->emit->run( vsvg->emit, 279463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell 0, count, 2801c2e5c223da28cdffe156b6b430fcdf638909021Zack Rusin vsvg->draw->start_instance, 2817ca0ce38340144794267609646048b3820d594abMichal Krol vsvg->draw->instance_id, 282463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell output_buffer ); 2837c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 284463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell FREE(temp_buffer); 2857c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 2867c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2877c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2887c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 289889473b3f5a216bd753c357974d6bae29fe3c41dKeith Whitwell 290889473b3f5a216bd753c357974d6bae29fe3c41dKeith Whitwell 291b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstatic void vsvg_destroy( struct draw_vs_variant *variant ) 2927c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 293b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul FREE(variant); 2947c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 2957c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 2967c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 297b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paulstruct draw_vs_variant * 298b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Pauldraw_vs_create_variant_generic( struct draw_vertex_shader *vs, 299b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul const struct draw_vs_variant_key *key ) 3007c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell{ 3017c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell unsigned i; 3027c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell struct translate_key fetch, emit; 3037c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 304b7e150605d402224cdd8fa3d186924bdee3c6c49Brian Paul struct draw_vs_variant_generic *vsvg = CALLOC_STRUCT( draw_vs_variant_generic ); 305150c289f6067cb1ba4572f9124948a94ef94c839Edward O'Callaghan if (!vsvg) 3067c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell return NULL; 3077c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3087c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.key = *key; 3097c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.vs = vs; 31021f98ad30aaeab5085d12278830f485e61b47cc1Keith Whitwell vsvg->base.set_buffer = vsvg_set_buffer; 3117c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.run_elts = vsvg_run_elts; 3127c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.run_linear = vsvg_run_linear; 3137c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->base.destroy = vsvg_destroy; 3147c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 315b98ac1d47257bf7b2661ae7c1a8904b7bc5d623cKeith Whitwell vsvg->draw = vs->draw; 3167c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 317463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell vsvg->temp_vertex_stride = MAX2(key->nr_inputs, 31805487ef88ded5fea0b1de7bc08d44846648d1ce2Zack Rusin draw_total_vs_outputs(vs->draw)) * 4 * sizeof(float); 3197c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 320f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell /* Build free-standing fetch and emit functions: 3217c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell */ 322f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell fetch.nr_elements = key->nr_inputs; 323463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell fetch.output_stride = vsvg->temp_vertex_stride; 324f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell for (i = 0; i < key->nr_inputs; i++) { 325543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol fetch.element[i].type = TRANSLATE_ELEMENT_NORMAL; 3267c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].input_format = key->element[i].in.format; 3277c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].input_buffer = key->element[i].in.buffer; 3287c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].input_offset = key->element[i].in.offset; 3297ca0ce38340144794267609646048b3820d594abMichal Krol fetch.element[i].instance_divisor = 0; 3307c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell fetch.element[i].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 331463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell fetch.element[i].output_offset = i * 4 * sizeof(float); 332463a47bf59398e850d5a6537da1186d855bd2919Keith Whitwell assert(fetch.element[i].output_offset < fetch.output_stride); 3337c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell } 3347c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3357c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 336f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell emit.nr_elements = key->nr_outputs; 3377c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell emit.output_stride = key->output_stride; 338f8762ba5234fd1b44e11e76bb5f58d2305c90572Keith Whitwell for (i = 0; i < key->nr_outputs; i++) { 3397b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell if (key->element[i].out.format != EMIT_1F_PSIZE) 3407b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell { 341543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol emit.element[i].type = TRANSLATE_ELEMENT_NORMAL; 3427b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 3437b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_buffer = 0; 3447b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_offset = key->element[i].out.vs_output * 4 * sizeof(float); 3457ca0ce38340144794267609646048b3820d594abMichal Krol emit.element[i].instance_divisor = 0; 3467b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_format = draw_translate_vinfo_format(key->element[i].out.format); 3477b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_offset = key->element[i].out.offset; 34863c0970dca9c13ab83ea24f108b41f75f2a290a7Brian Paul assert(emit.element[i].input_offset <= fetch.output_stride); 3497b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell } 3507b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell else { 351543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol emit.element[i].type = TRANSLATE_ELEMENT_NORMAL; 3527b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_format = PIPE_FORMAT_R32_FLOAT; 3537b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_buffer = 1; 3547b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].input_offset = 0; 3557ca0ce38340144794267609646048b3820d594abMichal Krol emit.element[i].instance_divisor = 0; 3567b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_format = PIPE_FORMAT_R32_FLOAT; 3577b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell emit.element[i].output_offset = key->element[i].out.offset; 3587b85ea19de09d4e7e077ca147528e90e52683690Keith Whitwell } 3597c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell } 3607c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3617c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->fetch = draw_vs_get_fetch( vs->draw, &fetch ); 3627c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell vsvg->emit = draw_vs_get_emit( vs->draw, &emit ); 3637c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3647c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell return &vsvg->base; 3657c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell} 3667c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3677c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3687c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3697c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 3707c99d7fe60e7bb0b7cf103a851aeef4614278ca6Keith Whitwell 371