st/dri: Don't check for null when user ensures non-null
[mesa.git] / src / gallium / drivers / i965 / brw_cc.c
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
36
37 static enum pipe_error prepare_cc_vp( struct brw_context *brw )
38 {
39 return brw_cache_data( &brw->cache,
40 BRW_CC_VP,
41 &brw->curr.ccv,
42 NULL, 0,
43 &brw->cc.reloc[CC_RELOC_VP].bo );
44 }
45
46 const struct brw_tracked_state brw_cc_vp = {
47 .dirty = {
48 .mesa = PIPE_NEW_VIEWPORT,
49 .brw = BRW_NEW_CONTEXT,
50 .cache = 0
51 },
52 .prepare = prepare_cc_vp
53 };
54
55
56 /* A long-winded way to OR two unsigned integers together:
57 */
58 static INLINE struct brw_cc3
59 combine_cc3( struct brw_cc3 a, struct brw_cc3 b )
60 {
61 union { struct brw_cc3 cc3; unsigned i; } ca, cb;
62 ca.cc3 = a;
63 cb.cc3 = b;
64 ca.i |= cb.i;
65 return ca.cc3;
66 }
67
68 static INLINE struct brw_cc1
69 combine_cc1( struct brw_cc1 a, struct brw_cc1 b )
70 {
71 union { struct brw_cc1 cc1; unsigned i; } ca, cb;
72 ca.cc1 = a;
73 cb.cc1 = b;
74 ca.i |= cb.i;
75 return ca.cc1;
76 }
77
78 static INLINE struct brw_cc2
79 combine_cc2( struct brw_cc2 a, struct brw_cc2 b )
80 {
81 union { struct brw_cc2 cc2; unsigned i; } ca, cb;
82 ca.cc2 = a;
83 cb.cc2 = b;
84 ca.i |= cb.i;
85 return ca.cc2;
86 }
87
88 static int prepare_cc_unit( struct brw_context *brw )
89 {
90 brw->cc.cc.cc0 = brw->curr.zstencil->cc0;
91 brw->cc.cc.cc1 = combine_cc1( brw->curr.zstencil->cc1, brw->curr.cc1_stencil_ref );
92 brw->cc.cc.cc2 = combine_cc2( brw->curr.zstencil->cc2, brw->curr.blend->cc2 );
93 brw->cc.cc.cc3 = combine_cc3( brw->curr.zstencil->cc3, brw->curr.blend->cc3 );
94
95 brw->cc.cc.cc5 = brw->curr.blend->cc5;
96 brw->cc.cc.cc6 = brw->curr.blend->cc6;
97 brw->cc.cc.cc7 = brw->curr.zstencil->cc7;
98
99 return brw_cache_data_sz(&brw->cache, BRW_CC_UNIT,
100 &brw->cc.cc, sizeof(brw->cc.cc),
101 brw->cc.reloc, 1,
102 &brw->cc.state_bo);
103 }
104
105 const struct brw_tracked_state brw_cc_unit = {
106 .dirty = {
107 .mesa = PIPE_NEW_DEPTH_STENCIL_ALPHA | PIPE_NEW_BLEND,
108 .brw = 0,
109 .cache = CACHE_NEW_CC_VP
110 },
111 .prepare = prepare_cc_unit,
112 };
113
114
115 void brw_hw_cc_init( struct brw_context *brw )
116 {
117 make_reloc(&brw->cc.reloc[0],
118 BRW_USAGE_STATE,
119 0,
120 offsetof(struct brw_cc_unit_state, cc4),
121 NULL);
122 }
123
124
125 void brw_hw_cc_cleanup( struct brw_context *brw )
126 {
127 bo_reference(&brw->cc.state_bo, NULL);
128 bo_reference(&brw->cc.reloc[0].bo, NULL);
129 }