lp_setup.c revision 5ce0380a0f585b9e1fb616b749f7fd18a8afada1
1946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca/************************************************************************** 2946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 3946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * All Rights Reserved. 5946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 6946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * Permission is hereby granted, free of charge, to any person obtaining a 7946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * copy of this software and associated documentation files (the 8946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * "Software"), to deal in the Software without restriction, including 9946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * without limitation the rights to use, copy, modify, merge, publish, 10946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * distribute, sub license, and/or sell copies of the Software, and to 11946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * permit persons to whom the Software is furnished to do so, subject to 12946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * the following conditions: 13946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 14946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * The above copyright notice and this permission notice (including the 15946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * next paragraph) shall be included in all copies or substantial portions 16946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * of the Software. 17946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 18946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 26946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca **************************************************************************/ 27946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 28946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca/** 29931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell * Tiling engine. 30946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 31931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell * Builds per-tile display lists and executes them on calls to 32931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell * lp_setup_flush(). 33946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca */ 34946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 35d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca#include "pipe/p_defines.h" 36d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca#include "pipe/p_inlines.h" 37946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "util/u_memory.h" 38253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell#include "util/u_pack_color.h" 397f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell#include "util/u_surface.h" 40663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell#include "lp_scene.h" 41663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell#include "lp_scene_queue.h" 42d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca#include "lp_buffer.h" 43d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca#include "lp_texture.h" 445ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell#include "lp_debug.h" 455ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell#include "lp_fence.h" 465ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell#include "lp_rast.h" 47d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca#include "lp_setup_context.h" 48253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 495ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell#include "draw/draw_context.h" 505ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell#include "draw/draw_vbuf.h" 515ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 52402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 53d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul/** XXX temporary value, temporary here */ 54663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell#define MAX_SCENES 2 55d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 56d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 575ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwellstatic void set_scene_state( struct setup_context *, unsigned ); 58946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 59946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 60663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwellstruct lp_scene * 61663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwelllp_setup_get_current_scene(struct setup_context *setup) 6222b07b8be4c2939b00e10f17fa91e68682808594Brian Paul{ 63663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell if (!setup->scene) { 643bee8c2e7c17893f91f6b62e2db090ef495dca9dBrian Paul /* wait for a free/empty bin */ 65663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell setup->scene = lp_scene_dequeue(setup->empty_scenes); 66663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell if(0)lp_scene_reset( setup->scene ); /* XXX temporary? */ 673bee8c2e7c17893f91f6b62e2db090ef495dca9dBrian Paul 687f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell lp_scene_set_framebuffer_size(setup->scene, 697f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell setup->fb.width, 707f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell setup->fb.height); 713bee8c2e7c17893f91f6b62e2db090ef495dca9dBrian Paul } 72663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell return setup->scene; 7322b07b8be4c2939b00e10f17fa91e68682808594Brian Paul} 7422b07b8be4c2939b00e10f17fa91e68682808594Brian Paul 75253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 76253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellstatic void 77253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellfirst_triangle( struct setup_context *setup, 78253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float (*v0)[4], 79253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float (*v1)[4], 80253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float (*v2)[4]) 81253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell{ 825ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_ACTIVE ); 83253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell lp_setup_choose_triangle( setup ); 84253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->triangle( setup, v0, v1, v2 ); 85253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell} 86253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 87253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellstatic void 88253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellfirst_line( struct setup_context *setup, 89253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float (*v0)[4], 90253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float (*v1)[4]) 91253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell{ 925ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_ACTIVE ); 93253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell lp_setup_choose_line( setup ); 94253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->line( setup, v0, v1 ); 95253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell} 96253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 97253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellstatic void 98253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellfirst_point( struct setup_context *setup, 99253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float (*v0)[4]) 100253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell{ 1015ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_ACTIVE ); 102253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell lp_setup_choose_point( setup ); 103253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->point( setup, v0 ); 104253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell} 105253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 106931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellstatic void reset_context( struct setup_context *setup ) 107931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell{ 108a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 109402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 110301c1494b27ad92ff1237909f9c98c1660be8fc1José Fonseca /* Reset derived state */ 1112e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->constants.stored_size = 0; 1122e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->constants.stored_data = NULL; 113301c1494b27ad92ff1237909f9c98c1660be8fc1José Fonseca setup->fs.stored = NULL; 114f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca setup->dirty = ~0; 1152e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 1163bee8c2e7c17893f91f6b62e2db090ef495dca9dBrian Paul /* no current bin */ 117663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell setup->scene = NULL; 1180718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell 1190718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell /* Reset some state: 1200718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell */ 1210718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell setup->clear.flags = 0; 122253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 123253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell /* Have an explicit "start-binning" call and get rid of this 124253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell * pointer twiddling? 125253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell */ 126253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->line = first_line; 127253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->point = first_point; 128253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->triangle = first_triangle; 129931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell} 130931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 131931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 132663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell/** Rasterize all scene's bins */ 133931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellstatic void 134663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwelllp_setup_rasterize_scene( struct setup_context *setup, 135314d3cd751448f9ae36126937b3bbf0330542da3Keith Whitwell boolean write_depth ) 136e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell{ 137663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_setup_get_current_scene(setup); 13822b07b8be4c2939b00e10f17fa91e68682808594Brian Paul 139663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_rasterize_scene(setup->rast, 1407f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell scene, 1417f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell &setup->fb, 1427f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell write_depth); 143e0e2008f1dcd73a59a184e0ef4c1dd77ac2a1cbfKeith Whitwell 1441caa26202c3bcc41ea5829b646128088e14d5dfdKeith Whitwell reset_context( setup ); 1453094fc200920f9d5eb62136d3b25896229fb0dbfBrian Paul 146a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s done \n", __FUNCTION__); 147e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell} 148e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell 149931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 150931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 151931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellstatic void 152931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellbegin_binning( struct setup_context *setup ) 153e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell{ 154663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_setup_get_current_scene(setup); 15522b07b8be4c2939b00e10f17fa91e68682808594Brian Paul 156a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 157402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 1587f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell if (setup->fb.cbufs[0]) { 1590718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell if (setup->clear.flags & PIPE_CLEAR_COLOR) 160663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 1618a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_clear_color, 1628a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul setup->clear.color ); 163931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell else 164663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 1658a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_load_color, 1668a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_arg_null() ); 167931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell } 168931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 1697f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell if (setup->fb.zsbuf) { 1700718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell if (setup->clear.flags & PIPE_CLEAR_DEPTHSTENCIL) 171663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 1728a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_clear_zstencil, 1738a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul setup->clear.zstencil ); 174931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell else 175663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 1768a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_load_zstencil, 1778a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_arg_null() ); 178931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell } 1793094fc200920f9d5eb62136d3b25896229fb0dbfBrian Paul 180a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s done\n", __FUNCTION__); 181e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell} 182e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell 183e529170c11d3cb5812aabeff0a6ee2d7a2ea66f2Keith Whitwell 184931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell/* This basically bins and then flushes any outstanding full-screen 185931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell * clears. 186931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell * 187931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell * TODO: fast path for fullscreen clears and no triangles. 188946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca */ 189931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellstatic void 190931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellexecute_clears( struct setup_context *setup ) 191946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 192a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 193402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 194931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell begin_binning( setup ); 195663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_setup_rasterize_scene( setup, TRUE ); 196946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 197946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 198931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 199931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellstatic void 2005ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwellset_scene_state( struct setup_context *setup, 201931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell unsigned new_state ) 202931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell{ 203931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell unsigned old_state = setup->state; 204931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 205931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell if (old_state == new_state) 206931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell return; 207931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 208a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s old %d new %d\n", __FUNCTION__, old_state, new_state); 209402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 210931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell switch (new_state) { 211931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell case SETUP_ACTIVE: 212402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell begin_binning( setup ); 213931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell break; 214931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 215931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell case SETUP_CLEARED: 216931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell if (old_state == SETUP_ACTIVE) { 217931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell assert(0); 218931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell return; 219931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell } 220931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell break; 221931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 222931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell case SETUP_FLUSHED: 2230718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell if (old_state == SETUP_CLEARED) 224931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell execute_clears( setup ); 225931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell else 226663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_setup_rasterize_scene( setup, TRUE ); 227931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell break; 228931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell } 229931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 230931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell setup->state = new_state; 231931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell} 232931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 233931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 234946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonsecavoid 235931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwelllp_setup_flush( struct setup_context *setup, 236931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell unsigned flags ) 237946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 238a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 239402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 2405ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_FLUSHED ); 241946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 242946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 243946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 244931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellvoid 245931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwelllp_setup_bind_framebuffer( struct setup_context *setup, 2469fca3e065b9ab5ef1389a76934bc24ed2b287a76Brian Paul const struct pipe_framebuffer_state *fb ) 247946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 248663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_setup_get_current_scene(setup); 2498a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul 250a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 251402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 2525ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_FLUSHED ); 253931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 2547f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell util_copy_framebuffer_state(&setup->fb, fb); 2558a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul 2567f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell lp_scene_set_framebuffer_size(scene, setup->fb.width, setup->fb.height); 257931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell} 258931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 259b1659b9213f3eeee440590dfe379f0d193948307Brian Paul 260931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellvoid 261931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwelllp_setup_clear( struct setup_context *setup, 262253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const float *color, 263253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell double depth, 264253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell unsigned stencil, 265931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell unsigned flags ) 266931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell{ 267663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_setup_get_current_scene(setup); 268659609e0ae27071a601794935c85547e315dedebJosé Fonseca unsigned i; 269659609e0ae27071a601794935c85547e315dedebJosé Fonseca 270a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s state %d\n", __FUNCTION__, setup->state); 271402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 272402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 2734cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell if (flags & PIPE_CLEAR_COLOR) { 274659609e0ae27071a601794935c85547e315dedebJosé Fonseca for (i = 0; i < 4; ++i) 275659609e0ae27071a601794935c85547e315dedebJosé Fonseca setup->clear.color.clear_color[i] = float_to_ubyte(color[i]); 2764cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell } 2774cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell 2784cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell if (flags & PIPE_CLEAR_DEPTHSTENCIL) { 2794cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell setup->clear.zstencil.clear_zstencil = 2807f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell util_pack_z_stencil(setup->fb.zsbuf->format, 2814cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell depth, 2824cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell stencil); 2834cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell } 2844cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell 285931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell if (setup->state == SETUP_ACTIVE) { 286663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell /* Add the clear to existing scene. In the unusual case where 2879a6567f1ed88727545f747e8670b713f17627c94Brian Paul * both color and depth-stencil are being cleared when there's 2889a6567f1ed88727545f747e8670b713f17627c94Brian Paul * already been some rendering, we could discard the currently 2899a6567f1ed88727545f747e8670b713f17627c94Brian Paul * binned scene and start again, but I don't see that as being 2909a6567f1ed88727545f747e8670b713f17627c94Brian Paul * a common usage. 291253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell */ 2924cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell if (flags & PIPE_CLEAR_COLOR) 293663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 2948a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_clear_color, 2958a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul setup->clear.color ); 296253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell 2974cdd10cb4b60d85f6c231a26739f7d5e264a05e5Keith Whitwell if (setup->clear.flags & PIPE_CLEAR_DEPTHSTENCIL) 298663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 2998a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul lp_rast_clear_zstencil, 3008a23105fa016ec4368f407ca64e7763f110da4e5Brian Paul setup->clear.zstencil ); 301946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca } 302946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca else { 303253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell /* Put ourselves into the 'pre-clear' state, specifically to try 304253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell * and accumulate multiple clears to color and depth_stencil 305253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell * buffers which the app or state-tracker might issue 306253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell * separately. 307253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell */ 3085ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_CLEARED ); 3090718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell 310931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell setup->clear.flags |= flags; 311946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca } 312931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell} 313931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 314931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 3156cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul/** 3166cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul * Emit a fence. 3176cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul */ 3186cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paulstruct pipe_fence_handle * 3196cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paullp_setup_fence( struct setup_context *setup ) 3206cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul{ 321663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_setup_get_current_scene(setup); 322663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell const unsigned rank = lp_scene_get_num_bins( scene ); /* xxx */ 3236cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul struct lp_fence *fence = lp_fence_create(rank); 3246cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul 3256cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul LP_DBG(DEBUG_SETUP, "%s rank %u\n", __FUNCTION__, rank); 3266cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul 3275ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell set_scene_state( setup, SETUP_ACTIVE ); 3286cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul 3296cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul /* insert the fence into all command bins */ 330663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_everywhere( scene, 331663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_rast_fence, 332663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_rast_arg_fence(fence) ); 3336cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul 3346cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul return (struct pipe_fence_handle *) fence; 3356cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul} 3366cbb1219a3f6b83ee4d24aecb61f5b5943e3cac3Brian Paul 337415b271b5100d64579690111bc8eb549866865a7Keith Whitwell 338415b271b5100d64579690111bc8eb549866865a7Keith Whitwellvoid 339e215f94f15fd20919cc0ed500dc2efde4f076516Keith Whitwelllp_setup_set_triangle_state( struct setup_context *setup, 340e215f94f15fd20919cc0ed500dc2efde4f076516Keith Whitwell unsigned cull_mode, 341e215f94f15fd20919cc0ed500dc2efde4f076516Keith Whitwell boolean ccw_is_frontface) 342415b271b5100d64579690111bc8eb549866865a7Keith Whitwell{ 343a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 344402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 345415b271b5100d64579690111bc8eb549866865a7Keith Whitwell setup->ccw_is_frontface = ccw_is_frontface; 346415b271b5100d64579690111bc8eb549866865a7Keith Whitwell setup->cullmode = cull_mode; 347415b271b5100d64579690111bc8eb549866865a7Keith Whitwell setup->triangle = first_triangle; 348415b271b5100d64579690111bc8eb549866865a7Keith Whitwell} 349415b271b5100d64579690111bc8eb549866865a7Keith Whitwell 350415b271b5100d64579690111bc8eb549866865a7Keith Whitwell 351415b271b5100d64579690111bc8eb549866865a7Keith Whitwell 352931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellvoid 353931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwelllp_setup_set_fs_inputs( struct setup_context *setup, 354253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell const struct lp_shader_input *input, 355931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell unsigned nr ) 356931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell{ 357a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s %p %u\n", __FUNCTION__, (void *) input, nr); 358402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 359253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell memcpy( setup->fs.input, input, nr * sizeof input[0] ); 360253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwell setup->fs.nr_inputs = nr; 361931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell} 36289498d01531cd515c769e570bf799c39fbafc8fbKeith Whitwell 3630718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwellvoid 3645ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwelllp_setup_set_fs_function( struct setup_context *setup, 3655ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell lp_jit_frag_func jit_function ) 3660718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell{ 3675ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) jit_function); 368d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca /* FIXME: reference count */ 369d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 3705ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell setup->fs.current.jit_function = jit_function; 3710e042bed49c51fef38b02b7cc05efa504f2f703dBrian Paul setup->dirty |= LP_SETUP_NEW_FS; 3720718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell} 3730718c7700533a965d7cd06b4f67b82bbae6e66a1Keith Whitwell 374d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecavoid 375d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecalp_setup_set_fs_constants(struct setup_context *setup, 376d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca struct pipe_buffer *buffer) 377d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca{ 378a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffer); 379402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 3802e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca pipe_buffer_reference(&setup->constants.current, buffer); 381931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 3822e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->dirty |= LP_SETUP_NEW_CONSTANTS; 383d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca} 384d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 385d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 386d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecavoid 387d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecalp_setup_set_alpha_ref_value( struct setup_context *setup, 388d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca float alpha_ref_value ) 389d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca{ 390a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s %f\n", __FUNCTION__, alpha_ref_value); 391402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 39285999695829823e459e11822b4846ed1db5c055dJosé Fonseca if(setup->fs.current.jit_context.alpha_ref_value != alpha_ref_value) { 39385999695829823e459e11822b4846ed1db5c055dJosé Fonseca setup->fs.current.jit_context.alpha_ref_value = alpha_ref_value; 3942e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->dirty |= LP_SETUP_NEW_FS; 395d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca } 396d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca} 397d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 398d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecavoid 399d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecalp_setup_set_blend_color( struct setup_context *setup, 400d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca const struct pipe_blend_color *blend_color ) 401d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca{ 402a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 403402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 404f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca assert(blend_color); 405d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 406f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca if(memcmp(&setup->blend_color.current, blend_color, sizeof *blend_color) != 0) { 407f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca memcpy(&setup->blend_color.current, blend_color, sizeof *blend_color); 408f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca setup->dirty |= LP_SETUP_NEW_BLEND_COLOR; 409d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca } 410d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca} 411d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 4125ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 4135ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwellvoid 4145ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwelllp_setup_set_flatshade_first( struct setup_context *setup, 4155ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell boolean flatshade_first ) 4165ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell{ 4175ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell setup->flatshade_first = flatshade_first; 4185ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell} 4195ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 4205ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 4215ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwellvoid 4225ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwelllp_setup_set_vertex_info( struct setup_context *setup, 4235ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell struct vertex_info *vertex_info ) 4245ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell{ 4255ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell /* XXX: just silently holding onto the pointer: 4265ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell */ 4275ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell setup->vertex_info = vertex_info; 4285ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell} 4295ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 4305ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 431d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecavoid 432d904ed88c1d957f662497343de7dc3e9fa743e47José Fonsecalp_setup_set_sampler_textures( struct setup_context *setup, 433d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca unsigned num, struct pipe_texture **texture) 434d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca{ 435d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca struct pipe_texture *dummy; 436d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca unsigned i; 437d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 438a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 439402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 440402c189af7e95be99ba2e5fd71a71987ffd73c2fKeith Whitwell 441d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca assert(num <= PIPE_MAX_SAMPLERS); 442d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 443d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { 444d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca struct pipe_texture *tex = i < num ? texture[i] : NULL; 445d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 446d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca /* FIXME: hold on to the reference */ 447d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca dummy = NULL; 448d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca pipe_texture_reference(&dummy, tex); 449d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 450d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca if(tex) { 451d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex); 45285999695829823e459e11822b4846ed1db5c055dJosé Fonseca struct lp_jit_texture *jit_tex; 45385999695829823e459e11822b4846ed1db5c055dJosé Fonseca jit_tex = &setup->fs.current.jit_context.textures[i]; 454d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca jit_tex->width = tex->width[0]; 455d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca jit_tex->height = tex->height[0]; 456d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca jit_tex->stride = lp_tex->stride[0]; 457d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca if(!lp_tex->dt) 458d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca jit_tex->data = lp_tex->data; 459d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca else 460d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca /* FIXME: map the rendertarget */ 461d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca assert(0); 462d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca } 463d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca } 464d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 4652e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->dirty |= LP_SETUP_NEW_FS; 466d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca} 467d904ed88c1d957f662497343de7dc3e9fa743e47José Fonseca 468c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonsecaboolean 469c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonsecalp_setup_is_texture_referenced( struct setup_context *setup, 470c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca const struct pipe_texture *texture ) 471c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca{ 472c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca /* FIXME */ 473c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca return PIPE_UNREFERENCED; 474c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca} 475c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca 476c0e3e35b03e6cbed3768cb56e298b6119eafe1efJosé Fonseca 4775ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwellvoid 4785ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwelllp_setup_update_state( struct setup_context *setup ) 479608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca{ 480663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_setup_get_current_scene(setup); 48122b07b8be4c2939b00e10f17fa91e68682808594Brian Paul 482a08d6302168341001003da32d42cfcff2311fa04Brian Paul LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); 483608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca 48485999695829823e459e11822b4846ed1db5c055dJosé Fonseca assert(setup->fs.current.jit_function); 48585999695829823e459e11822b4846ed1db5c055dJosé Fonseca 486f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca if(setup->dirty & LP_SETUP_NEW_BLEND_COLOR) { 487f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca uint8_t *stored; 488f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca unsigned i, j; 489f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca 490663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell stored = lp_scene_alloc_aligned(scene, 4 * 16, 16); 491f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca 4929c1debe208d07b57e88c65bae186bb339de7dee7Brian Paul /* smear each blend color component across 16 ubyte elements */ 493f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca for (i = 0; i < 4; ++i) { 494f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca uint8_t c = float_to_ubyte(setup->blend_color.current.color[i]); 495f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca for (j = 0; j < 16; ++j) 4964e058f6c4803be5d9d676338d6aee2775b88b87cBrian Paul stored[i*16 + j] = c; 497f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca } 498f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca 499f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca setup->blend_color.stored = stored; 500f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca 501f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca setup->fs.current.jit_context.blend_color = setup->blend_color.stored; 502f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca setup->dirty |= LP_SETUP_NEW_FS; 503f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca } 504f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca 505f2be08ae0e20b3da8ff684ffeb94412cc6a5a5a1José Fonseca 5062e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca if(setup->dirty & LP_SETUP_NEW_CONSTANTS) { 5072e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca struct pipe_buffer *buffer = setup->constants.current; 5082e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 5092e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca if(buffer) { 5102e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca unsigned current_size = buffer->size; 5112e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca const void *current_data = llvmpipe_buffer(buffer)->data; 5122e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 5132e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca /* TODO: copy only the actually used constants? */ 5142e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 5152e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca if(setup->constants.stored_size != current_size || 5162e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca !setup->constants.stored_data || 5172e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca memcmp(setup->constants.stored_data, 5182e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca current_data, 5192e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca current_size) != 0) { 5202e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca void *stored; 5212e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 522663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell stored = lp_scene_alloc(scene, current_size); 5232e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca if(stored) { 5242e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca memcpy(stored, 5252e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca current_data, 5262e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca current_size); 5272e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->constants.stored_size = current_size; 5282e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->constants.stored_data = stored; 5292e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca } 5302e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca } 5312e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca } 5322e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca else { 5332e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->constants.stored_size = 0; 5342e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->constants.stored_data = NULL; 5352e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca } 5362e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 5372e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->fs.current.jit_context.constants = setup->constants.stored_data; 5382e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->dirty |= LP_SETUP_NEW_FS; 5392e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca } 5402e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 5412e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 5422e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca if(setup->dirty & LP_SETUP_NEW_FS) { 54385999695829823e459e11822b4846ed1db5c055dJosé Fonseca if(!setup->fs.stored || 54485999695829823e459e11822b4846ed1db5c055dJosé Fonseca memcmp(setup->fs.stored, 54585999695829823e459e11822b4846ed1db5c055dJosé Fonseca &setup->fs.current, 54685999695829823e459e11822b4846ed1db5c055dJosé Fonseca sizeof setup->fs.current) != 0) { 547663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell /* The fs state that's been stored in the scene is different from 548e2f46344560f8f1193b311ad41883011e67eea00Brian Paul * the new, current state. So allocate a new lp_rast_state object 549e2f46344560f8f1193b311ad41883011e67eea00Brian Paul * and append it to the bin's setup data buffer. 550e2f46344560f8f1193b311ad41883011e67eea00Brian Paul */ 551e2f46344560f8f1193b311ad41883011e67eea00Brian Paul struct lp_rast_state *stored = 552663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell (struct lp_rast_state *) lp_scene_alloc(scene, sizeof *stored); 55385999695829823e459e11822b4846ed1db5c055dJosé Fonseca if(stored) { 55485999695829823e459e11822b4846ed1db5c055dJosé Fonseca memcpy(stored, 55585999695829823e459e11822b4846ed1db5c055dJosé Fonseca &setup->fs.current, 55685999695829823e459e11822b4846ed1db5c055dJosé Fonseca sizeof setup->fs.current); 55785999695829823e459e11822b4846ed1db5c055dJosé Fonseca setup->fs.stored = stored; 558e2f46344560f8f1193b311ad41883011e67eea00Brian Paul 559e2f46344560f8f1193b311ad41883011e67eea00Brian Paul /* put the state-set command into all bins */ 560663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_bin_state_command( scene, 561663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_rast_set_state, 562663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_rast_arg_state(setup->fs.stored) ); 563608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca } 564608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca } 565608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca } 566608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca 5672e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca setup->dirty = 0; 5682e3580d994e2caf6d81763803c8525a7ed42b8fdJosé Fonseca 56985999695829823e459e11822b4846ed1db5c055dJosé Fonseca assert(setup->fs.stored); 570608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca} 571608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca 572608c22272327d3b554c7665b60f6322716e5fd9dJosé Fonseca 573946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 574946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 575253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellvoid 576253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwelllp_setup_destroy( struct setup_context *setup ) 577946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 578415b271b5100d64579690111bc8eb549866865a7Keith Whitwell reset_context( setup ); 579415b271b5100d64579690111bc8eb549866865a7Keith Whitwell 580301c1494b27ad92ff1237909f9c98c1660be8fc1José Fonseca pipe_buffer_reference(&setup->constants.current, NULL); 581301c1494b27ad92ff1237909f9c98c1660be8fc1José Fonseca 582663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell /* free the scenes in the 'empty' queue */ 583663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell while (lp_scene_queue_count(setup->empty_scenes) > 0) { 584663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_scene_dequeue(setup->empty_scenes); 585663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell if (!scene) 586d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul break; 587663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_destroy(scene); 588d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul } 589d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 590931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell lp_rast_destroy( setup->rast ); 59122b07b8be4c2939b00e10f17fa91e68682808594Brian Paul 59289498d01531cd515c769e570bf799c39fbafc8fbKeith Whitwell FREE( setup ); 593946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 594946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 595946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 596946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca/** 5975ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell * Create a new primitive tiling engine. Plug it into the backend of 5985ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell * the draw module. Currently also creates a rasterizer to use with 5995ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell * it. 600946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca */ 601253dfed93918bd87c4a55047a9d569ede545f8beKeith Whitwellstruct setup_context * 6025ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwelllp_setup_create( struct pipe_screen *screen, 6035ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell struct draw_context *draw ) 604946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 605d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul unsigned i; 60689498d01531cd515c769e570bf799c39fbafc8fbKeith Whitwell struct setup_context *setup = CALLOC_STRUCT(setup_context); 607946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 608d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul if (!setup) 609d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul return NULL; 610d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 6115ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell lp_setup_init_vbuf(setup); 6125ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 613663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell setup->empty_scenes = lp_scene_queue_create(); 614663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell if (!setup->empty_scenes) 615d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul goto fail; 616d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 617663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell setup->rast = lp_rast_create( screen, setup->empty_scenes ); 618931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell if (!setup->rast) 619931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell goto fail; 620931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 6215ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell setup->vbuf = draw_vbuf_stage(draw, &setup->base); 6225ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell if (!setup->vbuf) 6235ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell goto fail; 6245ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 6255ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell draw_set_rasterize_stage(draw, setup->vbuf); 6265ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell draw_set_render(draw, &setup->base); 6275ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 628663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell /* create some empty scenes */ 629663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell for (i = 0; i < MAX_SCENES; i++) { 630663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell struct lp_scene *scene = lp_scene_create(); 631663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_enqueue(setup->empty_scenes, scene); 632d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul } 633d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 634163a31952c903034c8a70213b344e1b2ef287270Keith Whitwell setup->triangle = first_triangle; 635163a31952c903034c8a70213b344e1b2ef287270Keith Whitwell setup->line = first_line; 636163a31952c903034c8a70213b344e1b2ef287270Keith Whitwell setup->point = first_point; 637163a31952c903034c8a70213b344e1b2ef287270Keith Whitwell 638301c1494b27ad92ff1237909f9c98c1660be8fc1José Fonseca setup->dirty = ~0; 639301c1494b27ad92ff1237909f9c98c1660be8fc1José Fonseca 640946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca return setup; 641931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell 642931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwellfail: 6435ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell if (setup->rast) 6445ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell lp_rast_destroy( setup->rast ); 6455ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 6465ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell if (setup->vbuf) 6475ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell ; 6485ce0380a0f585b9e1fb616b749f7fd18a8afada1Keith Whitwell 649663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell if (setup->empty_scenes) 650663750d5564a225b4720f7ee8bea93ffb309fc88Keith Whitwell lp_scene_queue_destroy(setup->empty_scenes); 651d7dbc666367438ee9efe748505907b36bba6b66aBrian Paul 652931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell FREE(setup); 653931210424bc46b2c13919f0ac3e0ef781eff207eKeith Whitwell return NULL; 654946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 655946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 656