i965g: wip on removing GL stuff, trying to get a few files compiling
[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 #include "brw_defines.h"
36
37 static void prepare_cc_vp( struct brw_context *brw )
38 {
39 struct brw_cc_viewport ccv;
40
41 memset(&ccv, 0, sizeof(ccv));
42
43 /* _NEW_VIEWPORT */
44 ccv.min_depth = ctx->Viewport.Near;
45 ccv.max_depth = ctx->Viewport.Far;
46
47 brw->sws->bo_unreference(brw->cc.vp_bo);
48 brw->cc.vp_bo = brw_cache_data( &brw->cache, BRW_CC_VP, &ccv, NULL, 0 );
49 }
50
51 const struct brw_tracked_state brw_cc_vp = {
52 .dirty = {
53 .mesa = PIPE_NEW_VIEWPORT,
54 .brw = BRW_NEW_CONTEXT,
55 .cache = 0
56 },
57 .prepare = prepare_cc_vp
58 };
59
60 struct brw_cc_unit_key {
61 struct pipe_depth_stencil_alpha_state dsa;
62 struct pipe_blend_state blend; /* no color mask */
63 };
64
65 static void
66 cc_unit_populate_key(struct brw_context *brw, struct brw_cc_unit_key *key)
67 {
68 memset(key, 0, sizeof(*key));
69
70 key->dsa = brw->dsa;
71 key->blend = brw->blend;
72
73 /* Clear non-respected values:
74 */
75 key->blend.colormask = 0xf;
76 }
77
78 /**
79 * Creates the state cache entry for the given CC unit key.
80 */
81 static struct brw_winsys_buffer *
82 cc_unit_create_from_key(struct brw_context *brw, struct brw_cc_unit_key *key)
83 {
84 struct brw_cc_unit_state cc;
85 struct brw_winsys_buffer *bo;
86
87 memset(&cc, 0, sizeof(cc));
88
89 cc.cc0 = brw->dsa.cc0;
90 cc.cc1 = brw->dsa.cc1;
91 cc.cc2 = brw->dsa.cc2;
92 cc.cc3 = brw->dsa.cc3 | brw->blend.cc3;
93
94 /* CACHE_NEW_CC_VP */
95 cc.cc4.cc_viewport_state_offset = brw->cc.vp_bo->offset >> 5; /* reloc */
96
97 cc.cc5 = brw->blend.cc5 | brw->debug.cc5;
98
99
100 bo = brw_upload_cache(&brw->cache, BRW_CC_UNIT,
101 key, sizeof(*key),
102 &brw->cc.vp_bo, 1,
103 &cc, sizeof(cc),
104 NULL, NULL);
105
106 /* Emit CC viewport relocation */
107 dri_bo_emit_reloc(bo,
108 I915_GEM_DOMAIN_INSTRUCTION,
109 0,
110 0,
111 offsetof(struct brw_cc_unit_state, cc4),
112 brw->cc.vp_bo);
113
114 return bo;
115 }
116
117 static void prepare_cc_unit( struct brw_context *brw )
118 {
119 struct brw_cc_unit_key key;
120
121 cc_unit_populate_key(brw, &key);
122
123 brw->sws->bo_unreference(brw->cc.state_bo);
124 brw->cc.state_bo = brw_search_cache(&brw->cache, BRW_CC_UNIT,
125 &key, sizeof(key),
126 &brw->cc.vp_bo, 1,
127 NULL);
128
129 if (brw->cc.state_bo == NULL)
130 brw->cc.state_bo = cc_unit_create_from_key(brw, &key);
131 }
132
133 const struct brw_tracked_state brw_cc_unit = {
134 .dirty = {
135 .mesa = PIPE_NEW_DEPTH_STENCIL_ALPHA | PIPE_NEW_BLEND,
136 .brw = 0,
137 .cache = CACHE_NEW_CC_VP
138 },
139 .prepare = prepare_cc_unit,
140 };
141
142
143