1946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca/************************************************************************** 2946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * 3877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * Copyright 2007 VMware, Inc. 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. 21877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca * IN NO EVENT SHALL VMWARE 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 28877128505431adaf817dc8069172ebe4a1cdf5d8José Fonseca/* Authors: Keith Whitwell <keithw@vmware.com> 29946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca */ 30946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 316d810e5a7b082b9769a4ede4661536ae0e070dd2Brian Paul#include "pipe/p_state.h" 3228486880ca3ec39419ccee0cb1a3bedc9ef7117cJosé Fonseca#include "util/u_inlines.h" 331fc5a318a64b10567ed6990eb04b2dc3ecb2b347Brian Paul#include "util/u_framebuffer.h" 346d810e5a7b082b9769a4ede4661536ae0e070dd2Brian Paul#include "util/u_surface.h" 35946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "lp_context.h" 36bc50336b6ab40b6f4df7dbe19abe8b1d89938472Brian Paul#include "lp_scene.h" 37946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "lp_state.h" 38c1013f5d404880046f304de706d4216b08bd3011Keith Whitwell#include "lp_setup.h" 39946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 40946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca#include "draw/draw_context.h" 41946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 42f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol#include "util/u_format.h" 43f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol 44946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 45946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca/** 46946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer. 47946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca */ 48946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonsecavoid 49946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonsecallvmpipe_set_framebuffer_state(struct pipe_context *pipe, 50946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca const struct pipe_framebuffer_state *fb) 51946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca{ 52946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca struct llvmpipe_context *lp = llvmpipe_context(pipe); 53946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 54544882eb58253a4538ccc90ae091abed353416b4Brian Paul boolean changed = !util_framebuffer_state_equal(&lp->framebuffer, fb); 55dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger unsigned i; 56946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 574a72ec49f671015cd556ca2efbe5327f8e02fb28Brian Paul assert(fb->width <= LP_MAX_WIDTH); 584a72ec49f671015cd556ca2efbe5327f8e02fb28Brian Paul assert(fb->height <= LP_MAX_HEIGHT); 59bc50336b6ab40b6f4df7dbe19abe8b1d89938472Brian Paul 606d810e5a7b082b9769a4ede4661536ae0e070dd2Brian Paul if (changed) { 61f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure /* 62f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure * If no depth buffer is bound, send the utility function the default 63f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure * format for no bound depth (PIPE_FORMAT_NONE). 64f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure */ 65f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure enum pipe_format depth_format = fb->zsbuf ? 66f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure fb->zsbuf->format : PIPE_FORMAT_NONE; 67f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure const struct util_format_description *depth_desc = 68f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure util_format_description(depth_format); 69f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure 70dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger if (lp->framebuffer.zsbuf && lp->framebuffer.zsbuf->context != pipe) { 71dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger debug_printf("Illegal setting of fb state with zsbuf created in " 72dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger "another context\n"); 73dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger } 74dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger for (i = 0; i < fb->nr_cbufs; i++) { 75dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger if (lp->framebuffer.cbufs[i] && 76dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger lp->framebuffer.cbufs[i]->context != pipe) { 77dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger debug_printf("Illegal setting of fb state with cbuf %d created in " 78dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger "another context\n", i); 79dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger } 80dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger } 81dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger 826d810e5a7b082b9769a4ede4661536ae0e070dd2Brian Paul util_copy_framebuffer_state(&lp->framebuffer, fb); 83946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 845f00819cb382bdb70c29e2db3c6ff22a879bf10fKeith Whitwell if (LP_PERF & PERF_NO_DEPTH) { 85dc8b9bd0aae1b1bae89edda517ffe5c83b759552Roland Scheidegger pipe_surface_reference(&lp->framebuffer.zsbuf, NULL); 865f00819cb382bdb70c29e2db3c6ff22a879bf10fKeith Whitwell } 875f00819cb382bdb70c29e2db3c6ff22a879bf10fKeith Whitwell 88f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure /* 89f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure * Calculate the floating point depth sense and Minimum Resolvable Depth 90f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure * value for the llvmpipe module. This is separate from the draw module. 91be0b67a1436eb2b899f9874725b2a68eb26f9f3fMatthew McClure */ 92f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure lp->floating_point_depth = 93f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure (util_get_depth_format_type(depth_desc) == UTIL_FORMAT_TYPE_FLOAT); 94f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure 95f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure lp->mrd = util_get_depth_format_mrd(depth_desc); 96be0b67a1436eb2b899f9874725b2a68eb26f9f3fMatthew McClure 97f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure /* Tell the draw module how deep the Z/depth buffer is. */ 98f9e2c24326869542c9b43220f63dd9841c6de38fMatthew McClure draw_set_zs_format(lp->draw, depth_format); 99946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 1007f2ba80025e4b534db72427a206e6a542fc2f520Keith Whitwell lp_setup_bind_framebuffer( lp->setup, &lp->framebuffer ); 101946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca 1026b65685def525a8023ee936e82e53af2bc4e38b2Keith Whitwell lp->dirty |= LP_NEW_FRAMEBUFFER; 1036b65685def525a8023ee936e82e53af2bc4e38b2Keith Whitwell } 104946f432a08112148d743eb9faf6b27bb8cc7fa76José Fonseca} 105