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_screen.h"
42 static enum pipe_error
43 brw_update_texture_surface( struct brw_context
*brw
,
44 struct brw_texture
*tex
,
45 struct brw_winsys_buffer
**bo_out
)
47 struct brw_winsys_reloc reloc
[1];
50 /* Emit relocation to surface contents */
54 offsetof(struct brw_surface_state
, ss1
),
57 if (brw_search_cache(&brw
->surface_cache
,
59 &tex
->ss
, sizeof tex
->ss
,
60 reloc
, Elements(reloc
),
65 ret
= brw_upload_cache(&brw
->surface_cache
, BRW_SS_SURFACE
,
66 &tex
->ss
, sizeof tex
->ss
,
67 reloc
, Elements(reloc
),
68 &tex
->ss
, sizeof tex
->ss
,
85 * Sets up a surface state structure to point at the given region.
86 * While it is only used for the front/back buffer currently, it should be
87 * usable for further buffers when doing ARB_draw_buffer support.
89 static enum pipe_error
90 brw_update_render_surface(struct brw_context
*brw
,
91 struct brw_surface
*surface
,
92 struct brw_winsys_buffer
**bo_out
)
94 struct brw_surf_ss0 blend_ss0
= brw
->curr
.blend
->ss0
;
95 struct brw_surface_state ss
;
96 struct brw_winsys_reloc reloc
[1];
99 /* XXX: we will only be rendering to this surface:
101 make_reloc(&reloc
[0],
102 BRW_USAGE_RENDER_TARGET
,
104 offsetof(struct brw_surface_state
, ss1
),
107 /* Surfaces are potentially shared between contexts, so can't
108 * scribble the in-place ss0 value in the surface.
110 memcpy(&ss
, &surface
->ss
, sizeof ss
);
112 ss
.ss0
.color_blend
= blend_ss0
.color_blend
;
113 ss
.ss0
.writedisable_blue
= blend_ss0
.writedisable_blue
;
114 ss
.ss0
.writedisable_green
= blend_ss0
.writedisable_green
;
115 ss
.ss0
.writedisable_red
= blend_ss0
.writedisable_red
;
116 ss
.ss0
.writedisable_alpha
= blend_ss0
.writedisable_alpha
;
118 if (brw_search_cache(&brw
->surface_cache
,
121 reloc
, Elements(reloc
),
126 ret
= brw_upload_cache(&brw
->surface_cache
,
129 reloc
, Elements(reloc
),
141 * Constructs the binding table for the WM surface state, which maps unit
142 * numbers to surface state objects.
144 static enum pipe_error
145 brw_wm_get_binding_table(struct brw_context
*brw
,
146 struct brw_winsys_buffer
**bo_out
)
149 struct brw_winsys_reloc reloc
[BRW_WM_MAX_SURF
];
150 uint32_t data
[BRW_WM_MAX_SURF
];
151 GLuint nr_relocs
= 0;
152 GLuint data_size
= brw
->wm
.nr_surfaces
* sizeof data
[0];
155 assert(brw
->wm
.nr_surfaces
<= BRW_WM_MAX_SURF
);
156 assert(brw
->wm
.nr_surfaces
> 0);
158 /* Emit binding table relocations to surface state
160 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++) {
161 if (brw
->wm
.surf_bo
[i
]) {
162 make_reloc(&reloc
[nr_relocs
++],
170 /* Note there is no key for this search beyond the values in the
173 if (brw_search_cache(&brw
->surface_cache
, BRW_SS_SURF_BIND
,
180 /* Upload zero data, will all be overwitten with relocation
183 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++)
186 ret
= brw_upload_cache( &brw
->surface_cache
, BRW_SS_SURF_BIND
,
198 static enum pipe_error
prepare_wm_surfaces(struct brw_context
*brw
)
204 /* PIPE_NEW_COLOR_BUFFERS | PIPE_NEW_BLEND
206 * Update surfaces for drawing buffers. Mixes in colormask and
209 * XXX: no color buffer case
211 for (i
= 0; i
< brw
->curr
.fb
.nr_cbufs
; i
++) {
212 ret
= brw_update_render_surface(brw
,
213 brw_surface(brw
->curr
.fb
.cbufs
[i
]),
214 &brw
->wm
.surf_bo
[BTI_COLOR_BUF(i
)]);
218 nr_surfaces
= BTI_COLOR_BUF(i
) + 1;
223 /* PIPE_NEW_FRAGMENT_CONSTANTS
226 if (brw
->curr
.fragment_constants
) {
227 ret
= brw_update_fragment_constant_surface(
229 brw
->curr
.fragment_constants
,
230 &brw
->wm
.surf_bo
[BTI_FRAGMENT_CONSTANTS
]);
235 nr_surfaces
= BTI_FRAGMENT_CONSTANTS
+ 1;
238 bo_reference(&brw
->wm
.surf_bo
[SURF_FRAG_CONSTANTS
], NULL
);
245 for (i
= 0; i
< brw
->curr
.num_fragment_sampler_views
; i
++) {
246 ret
= brw_update_texture_surface(brw
,
247 brw_texture(brw
->curr
.fragment_sampler_views
[i
]->texture
),
248 &brw
->wm
.surf_bo
[BTI_TEXTURE(i
)]);
252 nr_surfaces
= BTI_TEXTURE(i
) + 1;
255 /* Clear any inactive entries:
257 for (i
= brw
->curr
.fb
.nr_cbufs
; i
< BRW_MAX_DRAW_BUFFERS
; i
++)
258 bo_reference(&brw
->wm
.surf_bo
[BTI_COLOR_BUF(i
)], NULL
);
260 if (!brw
->curr
.fragment_constants
)
261 bo_reference(&brw
->wm
.surf_bo
[BTI_FRAGMENT_CONSTANTS
], NULL
);
263 /* XXX: no pipe_max_textures define?? */
264 for (i
= brw
->curr
.num_fragment_sampler_views
; i
< PIPE_MAX_SAMPLERS
; i
++)
265 bo_reference(&brw
->wm
.surf_bo
[BTI_TEXTURE(i
)], NULL
);
267 if (brw
->wm
.nr_surfaces
!= nr_surfaces
) {
268 brw
->wm
.nr_surfaces
= nr_surfaces
;
269 brw
->state
.dirty
.brw
|= BRW_NEW_NR_WM_SURFACES
;
272 ret
= brw_wm_get_binding_table(brw
, &brw
->wm
.bind_bo
);
279 const struct brw_tracked_state brw_wm_surfaces
= {
281 .mesa
= (PIPE_NEW_COLOR_BUFFERS
|
282 PIPE_NEW_BOUND_TEXTURES
|
283 PIPE_NEW_FRAGMENT_CONSTANTS
|
285 .brw
= (BRW_NEW_CONTEXT
|
286 BRW_NEW_WM_SURFACES
),
289 .prepare
= prepare_wm_surfaces
,