18e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell/**************************************************************************
28e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell *
38e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
48e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * All Rights Reserved.
58e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell *
68e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
78e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * copy of this software and associated documentation files (the
88e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * "Software"), to deal in the Software without restriction, including
98e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
108e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
118e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * permit persons to whom the Software is furnished to do so, subject to
128e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * the following conditions:
138e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell *
148e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * The above copyright notice and this permission notice (including the
158e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * next paragraph) shall be included in all copies or substantial portions
168e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * of the Software.
178e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell *
188e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
198e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
208e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
218e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
228e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
238e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
248e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
258e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell *
268e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell **************************************************************************/
278e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell
288e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell/* Authors:  Keith Whitwell <keith@tungstengraphics.com>
298e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell */
30b859cdf6f191b4d8b56537c8dc30082a7e2d94b3Michel Dänzer
316393cda6766b707ef01e925d378239a66d143ae0Keith Whitwell#include "sp_context.h"
326393cda6766b707ef01e925d378239a66d143ae0Keith Whitwell#include "sp_state.h"
337e8396399824108d62dc3e02b2af0422e98aab8eBrian#include "sp_tile_cache.h"
348e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell
355c845b911596e72a9fdbc566ee06b1d7dc8afb7cMichal Krol#include "draw/draw_context.h"
365c845b911596e72a9fdbc566ee06b1d7dc8afb7cMichal Krol
37f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol#include "util/u_format.h"
3828486880ca3ec39419ccee0cb1a3bedc9ef7117cJosé Fonseca#include "util/u_inlines.h"
39f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol
408e4a95a93d15a6707a29454cd47e10b08314cda2Keith Whitwell
417e8396399824108d62dc3e02b2af0422e98aab8eBrian/**
421119852d0272c5ae43b09024b61f6e53c356ee65Brian * XXX this might get moved someday
437e8396399824108d62dc3e02b2af0422e98aab8eBrian * Set the framebuffer surface info: color buffers, zbuffer, stencil buffer.
44c76efb96b405e43e3261d1dc9e8812fdb2cfbac8Michel Dänzer * Here, we flush the old surfaces and update the tile cache to point to the new
457e8396399824108d62dc3e02b2af0422e98aab8eBrian * surfaces.
461119852d0272c5ae43b09024b61f6e53c356ee65Brian */
4773f96c51052bf5233191d852ef463462306bf1d5Brianvoid
4873f96c51052bf5233191d852ef463462306bf1d5Briansoftpipe_set_framebuffer_state(struct pipe_context *pipe,
4973f96c51052bf5233191d852ef463462306bf1d5Brian                               const struct pipe_framebuffer_state *fb)
501119852d0272c5ae43b09024b61f6e53c356ee65Brian{
517e8396399824108d62dc3e02b2af0422e98aab8eBrian   struct softpipe_context *sp = softpipe_context(pipe);
527e8396399824108d62dc3e02b2af0422e98aab8eBrian   uint i;
537e8396399824108d62dc3e02b2af0422e98aab8eBrian
547a15642f411613df51474d5c2ab85456b5ca41ceJosé Fonseca   draw_flush(sp->draw);
557a15642f411613df51474d5c2ab85456b5ca41ceJosé Fonseca
567e8396399824108d62dc3e02b2af0422e98aab8eBrian   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
577e8396399824108d62dc3e02b2af0422e98aab8eBrian      /* check if changing cbuf */
587e8396399824108d62dc3e02b2af0422e98aab8eBrian      if (sp->framebuffer.cbufs[i] != fb->cbufs[i]) {
597e8396399824108d62dc3e02b2af0422e98aab8eBrian         /* flush old */
60aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell         sp_flush_tile_cache(sp->cbuf_cache[i]);
61c76efb96b405e43e3261d1dc9e8812fdb2cfbac8Michel Dänzer
627e8396399824108d62dc3e02b2af0422e98aab8eBrian         /* assign new */
63a77226071f6814a53358a5d6caff685889d0e4ecYounes Manton         pipe_surface_reference(&sp->framebuffer.cbufs[i], fb->cbufs[i]);
647e8396399824108d62dc3e02b2af0422e98aab8eBrian
657e8396399824108d62dc3e02b2af0422e98aab8eBrian         /* update cache */
66c76efb96b405e43e3261d1dc9e8812fdb2cfbac8Michel Dänzer         sp_tile_cache_set_surface(sp->cbuf_cache[i], fb->cbufs[i]);
677e8396399824108d62dc3e02b2af0422e98aab8eBrian      }
687e8396399824108d62dc3e02b2af0422e98aab8eBrian   }
697e8396399824108d62dc3e02b2af0422e98aab8eBrian
702299f21f8da816fc4588492965e7dac422da1a96Zack Rusin   sp->framebuffer.nr_cbufs = fb->nr_cbufs;
717e8396399824108d62dc3e02b2af0422e98aab8eBrian
727e8396399824108d62dc3e02b2af0422e98aab8eBrian   /* zbuf changing? */
738de2331e432e2ea6f978acb6c80666da99c6c4a1Brian   if (sp->framebuffer.zsbuf != fb->zsbuf) {
747e8396399824108d62dc3e02b2af0422e98aab8eBrian      /* flush old */
75aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell      sp_flush_tile_cache(sp->zsbuf_cache);
76c76efb96b405e43e3261d1dc9e8812fdb2cfbac8Michel Dänzer
777e8396399824108d62dc3e02b2af0422e98aab8eBrian      /* assign new */
78a77226071f6814a53358a5d6caff685889d0e4ecYounes Manton      pipe_surface_reference(&sp->framebuffer.zsbuf, fb->zsbuf);
797e8396399824108d62dc3e02b2af0422e98aab8eBrian
807e8396399824108d62dc3e02b2af0422e98aab8eBrian      /* update cache */
818de2331e432e2ea6f978acb6c80666da99c6c4a1Brian      sp_tile_cache_set_surface(sp->zsbuf_cache, fb->zsbuf);
821119852d0272c5ae43b09024b61f6e53c356ee65Brian
83ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell      /* Tell draw module how deep the Z/depth buffer is */
84d0bc5293d6e1e9c34fa822b7c2928932ed22462cBrian Paul      if (sp->framebuffer.zsbuf) {
85ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         int depth_bits;
86ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         double mrd;
87f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol         depth_bits = util_format_get_component_bits(sp->framebuffer.zsbuf->format,
88f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol                                                     UTIL_FORMAT_COLORSPACE_ZS,
89f5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79Michal Krol                                                     0);
90ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         if (depth_bits > 16) {
91ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell            mrd = 0.0000001;
92ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         }
93ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         else {
94ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell            mrd = 0.00002;
95ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         }
96ade8984f5023b05412f2467add4a59d14af53185Keith Whitwell         draw_set_mrd(sp->draw, mrd);
97d0bc5293d6e1e9c34fa822b7c2928932ed22462cBrian Paul      }
98d0bc5293d6e1e9c34fa822b7c2928932ed22462cBrian Paul   }
99d0bc5293d6e1e9c34fa822b7c2928932ed22462cBrian Paul
10009f67990abd4bb9b79349be2fca9a6ae850b6f5fBrian   sp->framebuffer.width = fb->width;
10109f67990abd4bb9b79349be2fca9a6ae850b6f5fBrian   sp->framebuffer.height = fb->height;
10209f67990abd4bb9b79349be2fca9a6ae850b6f5fBrian
1037e8396399824108d62dc3e02b2af0422e98aab8eBrian   sp->dirty |= SP_NEW_FRAMEBUFFER;
1041119852d0272c5ae43b09024b61f6e53c356ee65Brian}
105