Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) Intel Corp. 2006. All Rights Reserved. |
| 3 | Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to |
| 4 | develop this 3D driver. |
| 5 | |
| 6 | Permission is hereby granted, free of charge, to any person obtaining |
| 7 | a copy of this software and associated documentation files (the |
| 8 | "Software"), to deal in the Software without restriction, including |
| 9 | without limitation the rights to use, copy, modify, merge, publish, |
| 10 | distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | permit persons to whom the Software is furnished to do so, subject to |
| 12 | the following conditions: |
| 13 | |
| 14 | The above copyright notice and this permission notice (including the |
| 15 | next paragraph) shall be included in all copies or substantial |
| 16 | portions of the Software. |
| 17 | |
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | |
| 26 | **********************************************************************/ |
| 27 | /* |
| 28 | * Authors: |
| 29 | * Keith Whitwell <keith@tungstengraphics.com> |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | #include "brw_context.h" |
| 34 | #include "brw_state.h" |
| 35 | #include "brw_defines.h" |
| 36 | #include "brw_util.h" |
Brian Paul | ecadb51 | 2008-09-18 15:17:05 -0600 | [diff] [blame] | 37 | #include "main/macros.h" |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 38 | |
Dave Airlie | f75843a | 2008-08-24 17:59:10 +1000 | [diff] [blame] | 39 | static void prepare_cc_vp( struct brw_context *brw ) |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 40 | { |
Eric Anholt | 0310aaf | 2009-08-26 11:04:13 -0700 | [diff] [blame] | 41 | GLcontext *ctx = &brw->intel.ctx; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 42 | struct brw_cc_viewport ccv; |
| 43 | |
| 44 | memset(&ccv, 0, sizeof(ccv)); |
| 45 | |
Eric Anholt | 92e7c6a | 2009-10-28 16:36:35 -0700 | [diff] [blame] | 46 | /* _NEW_TRANSOFORM */ |
| 47 | if (ctx->Transform.DepthClamp) { |
| 48 | /* _NEW_VIEWPORT */ |
| 49 | ccv.min_depth = MIN2(ctx->Viewport.Near, ctx->Viewport.Far); |
| 50 | ccv.max_depth = MAX2(ctx->Viewport.Near, ctx->Viewport.Far); |
| 51 | } else { |
| 52 | ccv.min_depth = 0.0; |
| 53 | ccv.max_depth = 1.0; |
| 54 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 55 | |
Eric Anholt | 38bad76 | 2007-12-14 11:02:48 -0800 | [diff] [blame] | 56 | dri_bo_unreference(brw->cc.vp_bo); |
Eric Anholt | 8395da2 | 2009-11-05 10:25:34 -0800 | [diff] [blame] | 57 | brw->cc.vp_bo = brw_cache_data(&brw->cache, BRW_CC_VP, &ccv, sizeof(ccv), |
| 58 | NULL, 0); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | const struct brw_tracked_state brw_cc_vp = { |
| 62 | .dirty = { |
Eric Anholt | 92e7c6a | 2009-10-28 16:36:35 -0700 | [diff] [blame] | 63 | .mesa = _NEW_VIEWPORT | _NEW_TRANSFORM, |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 64 | .brw = BRW_NEW_CONTEXT, |
| 65 | .cache = 0 |
| 66 | }, |
Dave Airlie | f75843a | 2008-08-24 17:59:10 +1000 | [diff] [blame] | 67 | .prepare = prepare_cc_vp |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 70 | struct brw_cc_unit_key { |
| 71 | GLboolean stencil, stencil_two_side, color_blend, alpha_enabled; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 72 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 73 | GLenum stencil_func[2], stencil_fail_op[2]; |
| 74 | GLenum stencil_pass_depth_fail_op[2], stencil_pass_depth_pass_op[2]; |
| 75 | GLubyte stencil_ref[2], stencil_write_mask[2], stencil_test_mask[2]; |
| 76 | GLenum logic_op; |
| 77 | |
| 78 | GLenum blend_eq_rgb, blend_eq_a; |
| 79 | GLenum blend_src_rgb, blend_src_a; |
| 80 | GLenum blend_dst_rgb, blend_dst_a; |
| 81 | |
| 82 | GLenum alpha_func; |
Eric Anholt | 93ec89e | 2008-01-16 10:46:35 -0800 | [diff] [blame] | 83 | GLclampf alpha_ref; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 84 | |
| 85 | GLboolean dither; |
| 86 | |
Eric Anholt | 6a5e86b | 2008-01-16 10:50:28 -0800 | [diff] [blame] | 87 | GLboolean depth_test, depth_write; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 88 | GLenum depth_func; |
| 89 | }; |
| 90 | |
Ian Romanick | eadd9b8 | 2009-12-08 21:13:05 -0800 | [diff] [blame] | 91 | /** |
| 92 | * Modify blend function to force destination alpha to 1.0 |
| 93 | * |
| 94 | * If \c function specifies a blend function that uses destination alpha, |
| 95 | * replace it with a function that hard-wires destination alpha to 1.0. This |
| 96 | * is used when rendering to xRGB targets. |
| 97 | */ |
| 98 | static GLenum |
| 99 | fix_xRGB_alpha(GLenum function) |
| 100 | { |
| 101 | switch (function) { |
| 102 | case GL_DST_ALPHA: |
| 103 | return GL_ONE; |
| 104 | |
| 105 | case GL_ONE_MINUS_DST_ALPHA: |
| 106 | case GL_SRC_ALPHA_SATURATE: |
| 107 | return GL_ZERO; |
| 108 | } |
| 109 | |
| 110 | return function; |
| 111 | } |
| 112 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 113 | static void |
| 114 | cc_unit_populate_key(struct brw_context *brw, struct brw_cc_unit_key *key) |
| 115 | { |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 116 | GLcontext *ctx = &brw->intel.ctx; |
| 117 | const unsigned back = ctx->Stencil._BackFace; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 118 | |
| 119 | memset(key, 0, sizeof(*key)); |
| 120 | |
Brian Paul | 91e61f4 | 2009-03-02 11:47:52 -0700 | [diff] [blame] | 121 | key->stencil = ctx->Stencil._Enabled; |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 122 | key->stencil_two_side = ctx->Stencil._TestTwoSide; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 123 | |
| 124 | if (key->stencil) { |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 125 | key->stencil_func[0] = ctx->Stencil.Function[0]; |
| 126 | key->stencil_fail_op[0] = ctx->Stencil.FailFunc[0]; |
| 127 | key->stencil_pass_depth_fail_op[0] = ctx->Stencil.ZFailFunc[0]; |
| 128 | key->stencil_pass_depth_pass_op[0] = ctx->Stencil.ZPassFunc[0]; |
| 129 | key->stencil_ref[0] = ctx->Stencil.Ref[0]; |
| 130 | key->stencil_write_mask[0] = ctx->Stencil.WriteMask[0]; |
| 131 | key->stencil_test_mask[0] = ctx->Stencil.ValueMask[0]; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 132 | } |
| 133 | if (key->stencil_two_side) { |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 134 | key->stencil_func[1] = ctx->Stencil.Function[back]; |
| 135 | key->stencil_fail_op[1] = ctx->Stencil.FailFunc[back]; |
| 136 | key->stencil_pass_depth_fail_op[1] = ctx->Stencil.ZFailFunc[back]; |
| 137 | key->stencil_pass_depth_pass_op[1] = ctx->Stencil.ZPassFunc[back]; |
| 138 | key->stencil_ref[1] = ctx->Stencil.Ref[back]; |
| 139 | key->stencil_write_mask[1] = ctx->Stencil.WriteMask[back]; |
| 140 | key->stencil_test_mask[1] = ctx->Stencil.ValueMask[back]; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 143 | if (ctx->Color._LogicOpEnabled) |
| 144 | key->logic_op = ctx->Color.LogicOp; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 145 | else |
| 146 | key->logic_op = GL_COPY; |
| 147 | |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 148 | key->color_blend = ctx->Color.BlendEnabled; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 149 | if (key->color_blend) { |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 150 | key->blend_eq_rgb = ctx->Color.BlendEquationRGB; |
| 151 | key->blend_eq_a = ctx->Color.BlendEquationA; |
| 152 | key->blend_src_rgb = ctx->Color.BlendSrcRGB; |
| 153 | key->blend_dst_rgb = ctx->Color.BlendDstRGB; |
| 154 | key->blend_src_a = ctx->Color.BlendSrcA; |
| 155 | key->blend_dst_a = ctx->Color.BlendDstA; |
Ian Romanick | eadd9b8 | 2009-12-08 21:13:05 -0800 | [diff] [blame] | 156 | |
| 157 | /* If the renderbuffer is XRGB, we have to frob the blend function to |
| 158 | * force the destination alpha to 1.0. This means replacing GL_DST_ALPHA |
Ian Romanick | b90f7f3 | 2009-12-14 16:16:26 -0800 | [diff] [blame] | 159 | * with GL_ONE and GL_ONE_MINUS_DST_ALPHA with GL_ZERO. |
Ian Romanick | eadd9b8 | 2009-12-08 21:13:05 -0800 | [diff] [blame] | 160 | */ |
Ian Romanick | b90f7f3 | 2009-12-14 16:16:26 -0800 | [diff] [blame] | 161 | if (ctx->DrawBuffer->Visual.alphaBits == 0) { |
Ian Romanick | eadd9b8 | 2009-12-08 21:13:05 -0800 | [diff] [blame] | 162 | key->blend_src_rgb = fix_xRGB_alpha(key->blend_src_rgb); |
| 163 | key->blend_src_a = fix_xRGB_alpha(key->blend_src_a); |
| 164 | key->blend_dst_rgb = fix_xRGB_alpha(key->blend_dst_rgb); |
| 165 | key->blend_dst_a = fix_xRGB_alpha(key->blend_dst_a); |
| 166 | } |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 169 | key->alpha_enabled = ctx->Color.AlphaEnabled; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 170 | if (key->alpha_enabled) { |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 171 | key->alpha_func = ctx->Color.AlphaFunc; |
| 172 | key->alpha_ref = ctx->Color.AlphaRef; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 175 | key->dither = ctx->Color.DitherFlag; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 176 | |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 177 | key->depth_test = ctx->Depth.Test; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 178 | if (key->depth_test) { |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 179 | key->depth_func = ctx->Depth.Func; |
| 180 | key->depth_write = ctx->Depth.Mask; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Creates the state cache entry for the given CC unit key. |
| 186 | */ |
| 187 | static dri_bo * |
| 188 | cc_unit_create_from_key(struct brw_context *brw, struct brw_cc_unit_key *key) |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 189 | { |
| 190 | struct brw_cc_unit_state cc; |
Eric Anholt | 8abffad | 2008-01-02 16:55:21 -0800 | [diff] [blame] | 191 | dri_bo *bo; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 192 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 193 | memset(&cc, 0, sizeof(cc)); |
| 194 | |
| 195 | /* _NEW_STENCIL */ |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 196 | if (key->stencil) { |
| 197 | cc.cc0.stencil_enable = 1; |
| 198 | cc.cc0.stencil_func = |
| 199 | intel_translate_compare_func(key->stencil_func[0]); |
| 200 | cc.cc0.stencil_fail_op = |
| 201 | intel_translate_stencil_op(key->stencil_fail_op[0]); |
| 202 | cc.cc0.stencil_pass_depth_fail_op = |
| 203 | intel_translate_stencil_op(key->stencil_pass_depth_fail_op[0]); |
| 204 | cc.cc0.stencil_pass_depth_pass_op = |
| 205 | intel_translate_stencil_op(key->stencil_pass_depth_pass_op[0]); |
| 206 | cc.cc1.stencil_ref = key->stencil_ref[0]; |
| 207 | cc.cc1.stencil_write_mask = key->stencil_write_mask[0]; |
| 208 | cc.cc1.stencil_test_mask = key->stencil_test_mask[0]; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 209 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 210 | if (key->stencil_two_side) { |
| 211 | cc.cc0.bf_stencil_enable = 1; |
| 212 | cc.cc0.bf_stencil_func = |
| 213 | intel_translate_compare_func(key->stencil_func[1]); |
| 214 | cc.cc0.bf_stencil_fail_op = |
| 215 | intel_translate_stencil_op(key->stencil_fail_op[1]); |
| 216 | cc.cc0.bf_stencil_pass_depth_fail_op = |
| 217 | intel_translate_stencil_op(key->stencil_pass_depth_fail_op[1]); |
| 218 | cc.cc0.bf_stencil_pass_depth_pass_op = |
| 219 | intel_translate_stencil_op(key->stencil_pass_depth_pass_op[1]); |
| 220 | cc.cc1.bf_stencil_ref = key->stencil_ref[1]; |
| 221 | cc.cc2.bf_stencil_write_mask = key->stencil_write_mask[1]; |
| 222 | cc.cc2.bf_stencil_test_mask = key->stencil_test_mask[1]; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* Not really sure about this: |
| 226 | */ |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 227 | if (key->stencil_write_mask[0] || |
| 228 | (key->stencil_two_side && key->stencil_write_mask[1])) |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 229 | cc.cc0.stencil_write_enable = 1; |
| 230 | } |
| 231 | |
| 232 | /* _NEW_COLOR */ |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 233 | if (key->logic_op != GL_COPY) { |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 234 | cc.cc2.logicop_enable = 1; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 235 | cc.cc5.logicop_func = intel_translate_logic_op(key->logic_op); |
| 236 | } else if (key->color_blend) { |
| 237 | GLenum eqRGB = key->blend_eq_rgb; |
| 238 | GLenum eqA = key->blend_eq_a; |
| 239 | GLenum srcRGB = key->blend_src_rgb; |
| 240 | GLenum dstRGB = key->blend_dst_rgb; |
| 241 | GLenum srcA = key->blend_src_a; |
| 242 | GLenum dstA = key->blend_dst_a; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 243 | |
| 244 | if (eqRGB == GL_MIN || eqRGB == GL_MAX) { |
| 245 | srcRGB = dstRGB = GL_ONE; |
| 246 | } |
| 247 | |
| 248 | if (eqA == GL_MIN || eqA == GL_MAX) { |
| 249 | srcA = dstA = GL_ONE; |
| 250 | } |
| 251 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 252 | cc.cc6.dest_blend_factor = brw_translate_blend_factor(dstRGB); |
| 253 | cc.cc6.src_blend_factor = brw_translate_blend_factor(srcRGB); |
| 254 | cc.cc6.blend_function = brw_translate_blend_equation(eqRGB); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 255 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 256 | cc.cc5.ia_dest_blend_factor = brw_translate_blend_factor(dstA); |
| 257 | cc.cc5.ia_src_blend_factor = brw_translate_blend_factor(srcA); |
| 258 | cc.cc5.ia_blend_function = brw_translate_blend_equation(eqA); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 259 | |
| 260 | cc.cc3.blend_enable = 1; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 261 | cc.cc3.ia_blend_enable = (srcA != srcRGB || |
| 262 | dstA != dstRGB || |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 263 | eqA != eqRGB); |
| 264 | } |
| 265 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 266 | if (key->alpha_enabled) { |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 267 | cc.cc3.alpha_test = 1; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 268 | cc.cc3.alpha_test_func = intel_translate_compare_func(key->alpha_func); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 269 | cc.cc3.alpha_test_format = BRW_ALPHATEST_FORMAT_UNORM8; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 270 | |
| 271 | UNCLAMPED_FLOAT_TO_UBYTE(cc.cc7.alpha_ref.ub[0], key->alpha_ref); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 274 | if (key->dither) { |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 275 | cc.cc5.dither_enable = 1; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 276 | cc.cc6.y_dither_offset = 0; |
| 277 | cc.cc6.x_dither_offset = 0; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* _NEW_DEPTH */ |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 281 | if (key->depth_test) { |
| 282 | cc.cc2.depth_test = 1; |
| 283 | cc.cc2.depth_test_function = intel_translate_compare_func(key->depth_func); |
Eric Anholt | 6a5e86b | 2008-01-16 10:50:28 -0800 | [diff] [blame] | 284 | cc.cc2.depth_write_enable = key->depth_write; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 285 | } |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 286 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 287 | /* CACHE_NEW_CC_VP */ |
Eric Anholt | 38bad76 | 2007-12-14 11:02:48 -0800 | [diff] [blame] | 288 | cc.cc4.cc_viewport_state_offset = brw->cc.vp_bo->offset >> 5; /* reloc */ |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 289 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 290 | if (INTEL_DEBUG & DEBUG_STATS) |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 291 | cc.cc5.statistics_enable = 1; |
| 292 | |
Eric Anholt | 8abffad | 2008-01-02 16:55:21 -0800 | [diff] [blame] | 293 | bo = brw_upload_cache(&brw->cache, BRW_CC_UNIT, |
| 294 | key, sizeof(*key), |
| 295 | &brw->cc.vp_bo, 1, |
| 296 | &cc, sizeof(cc), |
| 297 | NULL, NULL); |
| 298 | |
| 299 | /* Emit CC viewport relocation */ |
Eric Anholt | 3628185 | 2008-09-06 03:09:43 +0100 | [diff] [blame] | 300 | dri_bo_emit_reloc(bo, |
| 301 | I915_GEM_DOMAIN_INSTRUCTION, |
| 302 | 0, |
| 303 | 0, |
| 304 | offsetof(struct brw_cc_unit_state, cc4), |
| 305 | brw->cc.vp_bo); |
Eric Anholt | 8abffad | 2008-01-02 16:55:21 -0800 | [diff] [blame] | 306 | |
| 307 | return bo; |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Dave Airlie | f75843a | 2008-08-24 17:59:10 +1000 | [diff] [blame] | 310 | static void prepare_cc_unit( struct brw_context *brw ) |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 311 | { |
| 312 | struct brw_cc_unit_key key; |
| 313 | |
| 314 | cc_unit_populate_key(brw, &key); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 315 | |
Eric Anholt | 38bad76 | 2007-12-14 11:02:48 -0800 | [diff] [blame] | 316 | dri_bo_unreference(brw->cc.state_bo); |
Eric Anholt | b35811e | 2008-01-02 13:20:00 -0800 | [diff] [blame] | 317 | brw->cc.state_bo = brw_search_cache(&brw->cache, BRW_CC_UNIT, |
| 318 | &key, sizeof(key), |
| 319 | &brw->cc.vp_bo, 1, |
| 320 | NULL); |
| 321 | |
| 322 | if (brw->cc.state_bo == NULL) |
| 323 | brw->cc.state_bo = cc_unit_create_from_key(brw, &key); |
Eric Anholt | 38bad76 | 2007-12-14 11:02:48 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 326 | const struct brw_tracked_state brw_cc_unit = { |
| 327 | .dirty = { |
| 328 | .mesa = _NEW_STENCIL | _NEW_COLOR | _NEW_DEPTH, |
| 329 | .brw = 0, |
| 330 | .cache = CACHE_NEW_CC_VP |
| 331 | }, |
Dave Airlie | 008653a | 2008-04-17 17:17:23 +1000 | [diff] [blame] | 332 | .prepare = prepare_cc_unit, |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | |
| 336 | |