2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "pipe/p_format.h"
34 #include "brw_batchbuffer.h"
35 #include "brw_context.h"
36 #include "brw_state.h"
37 #include "brw_defines.h"
38 #include "brw_screen.h"
44 brw_update_texture_surface( struct brw_context
*brw
,
45 struct brw_texture
*tex
,
48 brw
->wm
.surf_bo
[surf
] = brw_search_cache(&brw
->surface_cache
,
50 &tex
->ss
, sizeof tex
->ss
,
54 if (brw
->wm
.surf_bo
[surf
] == NULL
) {
55 brw
->wm
.surf_bo
[surf
] = brw_upload_cache(&brw
->surface_cache
, BRW_SS_SURFACE
,
56 &tex
->ss
, sizeof tex
->ss
,
58 &tex
->ss
, sizeof tex
->ss
,
61 /* Emit relocation to surface contents */
62 brw
->sws
->bo_emit_reloc(brw
->wm
.surf_bo
[surf
],
65 offsetof(struct brw_surface_state
, ss1
),
78 * Sets up a surface state structure to point at the given region.
79 * While it is only used for the front/back buffer currently, it should be
80 * usable for further buffers when doing ARB_draw_buffer support.
83 brw_update_renderbuffer_surface(struct brw_context
*brw
,
84 struct brw_surface
*surface
,
87 struct brw_surf_ss0 blend_ss0
= brw
->curr
.blend
->ss0
;
88 struct brw_surface_state ss
;
90 /* Surfaces are potentially shared between contexts, so can't
91 * scribble the in-place ss0 value in the surface.
93 memcpy(&ss
, &surface
->ss
, sizeof ss
);
95 ss
.ss0
.color_blend
= blend_ss0
.color_blend
;
96 ss
.ss0
.writedisable_blue
= blend_ss0
.writedisable_blue
;
97 ss
.ss0
.writedisable_green
= blend_ss0
.writedisable_green
;
98 ss
.ss0
.writedisable_red
= blend_ss0
.writedisable_red
;
99 ss
.ss0
.writedisable_alpha
= blend_ss0
.writedisable_alpha
;
101 brw
->sws
->bo_unreference(brw
->wm
.surf_bo
[unit
]);
102 brw
->wm
.surf_bo
[unit
] = brw_search_cache(&brw
->surface_cache
,
108 if (brw
->wm
.surf_bo
[unit
] == NULL
) {
110 brw
->wm
.surf_bo
[unit
] = brw_upload_cache(&brw
->surface_cache
,
117 /* XXX: we will only be rendering to this surface:
119 brw
->sws
->bo_emit_reloc(brw
->wm
.surf_bo
[unit
],
120 BRW_USAGE_RENDER_TARGET
,
121 ss
.ss1
.base_addr
- surface
->bo
->offset
[0], /* XXX */
122 offsetof(struct brw_surface_state
, ss1
),
129 * Constructs the binding table for the WM surface state, which maps unit
130 * numbers to surface state objects.
132 static struct brw_winsys_buffer
*
133 brw_wm_get_binding_table(struct brw_context
*brw
)
135 struct brw_winsys_buffer
*bind_bo
;
137 assert(brw
->wm
.nr_surfaces
<= BRW_WM_MAX_SURF
);
139 /* Note there is no key for this search beyond the values in the
142 bind_bo
= brw_search_cache(&brw
->surface_cache
, BRW_SS_SURF_BIND
,
144 brw
->wm
.surf_bo
, brw
->wm
.nr_surfaces
,
147 if (bind_bo
== NULL
) {
148 uint32_t data
[BRW_WM_MAX_SURF
];
149 GLuint data_size
= brw
->wm
.nr_surfaces
* sizeof data
[0];
152 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++)
153 data
[i
] = brw
->wm
.surf_bo
[i
]->offset
[0];
155 bind_bo
= brw_upload_cache( &brw
->surface_cache
, BRW_SS_SURF_BIND
,
157 brw
->wm
.surf_bo
, brw
->wm
.nr_surfaces
,
161 /* Emit binding table relocations to surface state */
162 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++) {
163 brw
->sws
->bo_emit_reloc(bind_bo
,
174 static int prepare_wm_surfaces(struct brw_context
*brw
)
179 /* Unreference old buffers
181 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++) {
182 brw
->sws
->bo_unreference(brw
->wm
.surf_bo
[i
]);
183 brw
->wm
.surf_bo
[i
] = NULL
;
187 /* PIPE_NEW_COLOR_BUFFERS | PIPE_NEW_BLEND
189 * Update surfaces for drawing buffers. Mixes in colormask and
192 * XXX: no color buffer case
194 for (i
= 0; i
< brw
->curr
.fb
.nr_cbufs
; i
++) {
195 brw_update_renderbuffer_surface(brw
,
196 brw_surface(brw
->curr
.fb
.cbufs
[i
]),
202 for (i
= 0; i
< brw
->curr
.num_textures
; i
++) {
203 brw_update_texture_surface(brw
,
204 brw_texture(brw
->curr
.texture
[i
]),
208 /* PIPE_NEW_FRAGMENT_CONSTANTS
211 if (brw
->curr
.fragment_constants
) {
212 brw_update_fragment_constant_surface(brw
,
213 brw
->curr
.fragment_constants
,
218 if (brw
->wm
.nr_surfaces
!= nr_surfaces
) {
219 brw
->wm
.nr_surfaces
= nr_surfaces
;
220 brw
->state
.dirty
.brw
|= BRW_NEW_NR_WM_SURFACES
;
223 brw
->sws
->bo_unreference(brw
->wm
.bind_bo
);
224 brw
->wm
.bind_bo
= brw_wm_get_binding_table(brw
);
229 const struct brw_tracked_state brw_wm_surfaces
= {
231 .mesa
= (PIPE_NEW_COLOR_BUFFERS
|
232 PIPE_NEW_BOUND_TEXTURES
|
233 PIPE_NEW_FRAGMENT_CONSTANTS
|
235 .brw
= (BRW_NEW_CONTEXT
|
236 BRW_NEW_WM_SURFACES
),
239 .prepare
= prepare_wm_surfaces
,