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>
33 #include "main/mtypes.h"
34 #include "main/texstore.h"
35 #include "program/prog_parameter.h"
37 #include "intel_mipmap_tree.h"
38 #include "intel_batchbuffer.h"
39 #include "intel_tex.h"
40 #include "intel_fbo.h"
42 #include "brw_context.h"
43 #include "brw_state.h"
44 #include "brw_defines.h"
47 static GLuint
translate_tex_target( GLenum target
)
51 return BRW_SURFACE_1D
;
53 case GL_TEXTURE_RECTANGLE_NV
:
54 return BRW_SURFACE_2D
;
57 return BRW_SURFACE_2D
;
60 return BRW_SURFACE_3D
;
62 case GL_TEXTURE_CUBE_MAP
:
63 return BRW_SURFACE_CUBE
;
71 static uint32_t brw_format_for_mesa_format
[MESA_FORMAT_COUNT
] =
73 [MESA_FORMAT_L8
] = BRW_SURFACEFORMAT_L8_UNORM
,
74 [MESA_FORMAT_I8
] = BRW_SURFACEFORMAT_I8_UNORM
,
75 [MESA_FORMAT_A8
] = BRW_SURFACEFORMAT_A8_UNORM
,
76 [MESA_FORMAT_AL88
] = BRW_SURFACEFORMAT_L8A8_UNORM
,
77 [MESA_FORMAT_AL1616
] = BRW_SURFACEFORMAT_L16A16_UNORM
,
78 [MESA_FORMAT_R8
] = BRW_SURFACEFORMAT_R8_UNORM
,
79 [MESA_FORMAT_R16
] = BRW_SURFACEFORMAT_R16_UNORM
,
80 [MESA_FORMAT_RG88
] = BRW_SURFACEFORMAT_R8G8_UNORM
,
81 [MESA_FORMAT_RG1616
] = BRW_SURFACEFORMAT_R16G16_UNORM
,
82 [MESA_FORMAT_ARGB8888
] = BRW_SURFACEFORMAT_B8G8R8A8_UNORM
,
83 [MESA_FORMAT_XRGB8888
] = BRW_SURFACEFORMAT_B8G8R8X8_UNORM
,
84 [MESA_FORMAT_RGB565
] = BRW_SURFACEFORMAT_B5G6R5_UNORM
,
85 [MESA_FORMAT_ARGB1555
] = BRW_SURFACEFORMAT_B5G5R5A1_UNORM
,
86 [MESA_FORMAT_ARGB4444
] = BRW_SURFACEFORMAT_B4G4R4A4_UNORM
,
87 [MESA_FORMAT_YCBCR_REV
] = BRW_SURFACEFORMAT_YCRCB_NORMAL
,
88 [MESA_FORMAT_YCBCR
] = BRW_SURFACEFORMAT_YCRCB_SWAPUVY
,
89 [MESA_FORMAT_RGB_FXT1
] = BRW_SURFACEFORMAT_FXT1
,
90 [MESA_FORMAT_RGBA_FXT1
] = BRW_SURFACEFORMAT_FXT1
,
91 [MESA_FORMAT_RGB_DXT1
] = BRW_SURFACEFORMAT_DXT1_RGB
,
92 [MESA_FORMAT_RGBA_DXT1
] = BRW_SURFACEFORMAT_BC1_UNORM
,
93 [MESA_FORMAT_RGBA_DXT3
] = BRW_SURFACEFORMAT_BC2_UNORM
,
94 [MESA_FORMAT_RGBA_DXT5
] = BRW_SURFACEFORMAT_BC3_UNORM
,
95 [MESA_FORMAT_SRGB_DXT1
] = BRW_SURFACEFORMAT_DXT1_RGB_SRGB
,
96 [MESA_FORMAT_SRGBA_DXT1
] = BRW_SURFACEFORMAT_BC1_UNORM_SRGB
,
97 [MESA_FORMAT_SRGBA_DXT3
] = BRW_SURFACEFORMAT_BC2_UNORM_SRGB
,
98 [MESA_FORMAT_SRGBA_DXT5
] = BRW_SURFACEFORMAT_BC3_UNORM_SRGB
,
99 [MESA_FORMAT_SARGB8
] = BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB
,
100 [MESA_FORMAT_SLA8
] = BRW_SURFACEFORMAT_L8A8_UNORM_SRGB
,
101 [MESA_FORMAT_SL8
] = BRW_SURFACEFORMAT_L8_UNORM_SRGB
,
102 [MESA_FORMAT_DUDV8
] = BRW_SURFACEFORMAT_R8G8_SNORM
,
103 [MESA_FORMAT_SIGNED_RGBA8888_REV
] = BRW_SURFACEFORMAT_R8G8B8A8_SNORM
,
107 brw_render_target_supported(gl_format format
)
109 if (format
== MESA_FORMAT_S8_Z24
||
110 format
== MESA_FORMAT_X8_Z24
||
111 format
== MESA_FORMAT_Z16
) {
115 /* Not exactly true, as some of those formats are not renderable.
116 * But at least we know how to translate them.
118 return brw_format_for_mesa_format
[format
] != 0;
121 static GLuint
translate_tex_format( gl_format mesa_format
,
122 GLenum internal_format
,
126 switch( mesa_format
) {
128 case MESA_FORMAT_Z16
:
129 if (depth_mode
== GL_INTENSITY
)
130 return BRW_SURFACEFORMAT_I16_UNORM
;
131 else if (depth_mode
== GL_ALPHA
)
132 return BRW_SURFACEFORMAT_A16_UNORM
;
133 else if (depth_mode
== GL_RED
)
134 return BRW_SURFACEFORMAT_R16_UNORM
;
136 return BRW_SURFACEFORMAT_L16_UNORM
;
138 case MESA_FORMAT_S8_Z24
:
139 /* XXX: these different surface formats don't seem to
140 * make any difference for shadow sampler/compares.
142 if (depth_mode
== GL_INTENSITY
)
143 return BRW_SURFACEFORMAT_I24X8_UNORM
;
144 else if (depth_mode
== GL_ALPHA
)
145 return BRW_SURFACEFORMAT_A24X8_UNORM
;
146 else if (depth_mode
== GL_RED
)
147 return BRW_SURFACEFORMAT_R24_UNORM_X8_TYPELESS
;
149 return BRW_SURFACEFORMAT_L24X8_UNORM
;
151 case MESA_FORMAT_SARGB8
:
152 case MESA_FORMAT_SLA8
:
153 case MESA_FORMAT_SL8
:
154 if (srgb_decode
== GL_DECODE_EXT
)
155 return brw_format_for_mesa_format
[mesa_format
];
156 else if (srgb_decode
== GL_SKIP_DECODE_EXT
)
157 return brw_format_for_mesa_format
[_mesa_get_srgb_format_linear(mesa_format
)];
159 assert(brw_format_for_mesa_format
[mesa_format
] != 0);
160 return brw_format_for_mesa_format
[mesa_format
];
165 brw_set_surface_tiling(struct brw_surface_state
*surf
, uint32_t tiling
)
168 case I915_TILING_NONE
:
169 surf
->ss3
.tiled_surface
= 0;
170 surf
->ss3
.tile_walk
= 0;
173 surf
->ss3
.tiled_surface
= 1;
174 surf
->ss3
.tile_walk
= BRW_TILEWALK_XMAJOR
;
177 surf
->ss3
.tiled_surface
= 1;
178 surf
->ss3
.tile_walk
= BRW_TILEWALK_YMAJOR
;
184 brw_update_texture_surface( struct gl_context
*ctx
, GLuint unit
)
186 struct brw_context
*brw
= brw_context(ctx
);
187 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[unit
]._Current
;
188 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
189 struct gl_texture_image
*firstImage
= tObj
->Image
[0][tObj
->BaseLevel
];
190 const GLuint surf_index
= SURF_INDEX_TEXTURE(unit
);
191 struct brw_surface_state surf
;
194 memset(&surf
, 0, sizeof(surf
));
196 surf
.ss0
.mipmap_layout_mode
= BRW_SURFACE_MIPMAPLAYOUT_BELOW
;
197 surf
.ss0
.surface_type
= translate_tex_target(tObj
->Target
);
198 surf
.ss0
.surface_format
= translate_tex_format(firstImage
->TexFormat
,
199 firstImage
->InternalFormat
,
200 tObj
->DepthMode
, tObj
->sRGBDecode
);
202 /* This is ok for all textures with channel width 8bit or less:
204 /* surf.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
205 surf
.ss1
.base_addr
= intelObj
->mt
->region
->buffer
->offset
; /* reloc */
207 surf
.ss2
.mip_count
= intelObj
->_MaxLevel
- tObj
->BaseLevel
;
208 surf
.ss2
.width
= firstImage
->Width
- 1;
209 surf
.ss2
.height
= firstImage
->Height
- 1;
210 brw_set_surface_tiling(&surf
, intelObj
->mt
->region
->tiling
);
211 surf
.ss3
.pitch
= (intelObj
->mt
->region
->pitch
* intelObj
->mt
->cpp
) - 1;
212 surf
.ss3
.depth
= firstImage
->Depth
- 1;
214 surf
.ss4
.min_lod
= 0;
216 if (tObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
217 surf
.ss0
.cube_pos_x
= 1;
218 surf
.ss0
.cube_pos_y
= 1;
219 surf
.ss0
.cube_pos_z
= 1;
220 surf
.ss0
.cube_neg_x
= 1;
221 surf
.ss0
.cube_neg_y
= 1;
222 surf
.ss0
.cube_neg_z
= 1;
225 map
= brw_state_batch(brw
, sizeof(surf
), 32,
226 &brw
->wm
.surf_bo
[surf_index
],
227 &brw
->wm
.surf_offset
[surf_index
]);
228 memcpy(map
, &surf
, sizeof(surf
));
230 /* Emit relocation to surface contents */
231 drm_intel_bo_emit_reloc(brw
->wm
.surf_bo
[surf_index
],
232 brw
->wm
.surf_offset
[surf_index
] +
233 offsetof(struct brw_surface_state
, ss1
),
234 intelObj
->mt
->region
->buffer
, 0,
235 I915_GEM_DOMAIN_SAMPLER
, 0);
239 * Create the constant buffer surface. Vertex/fragment shader constants will be
240 * read from this buffer with Data Port Read instructions/messages.
243 brw_create_constant_surface(struct brw_context
*brw
,
246 drm_intel_bo
**out_bo
,
247 uint32_t *out_offset
)
249 struct intel_context
*intel
= &brw
->intel
;
250 const GLint w
= width
- 1;
251 struct brw_surface_state surf
;
254 memset(&surf
, 0, sizeof(surf
));
256 surf
.ss0
.mipmap_layout_mode
= BRW_SURFACE_MIPMAPLAYOUT_BELOW
;
257 surf
.ss0
.surface_type
= BRW_SURFACE_BUFFER
;
258 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
;
261 surf
.ss0
.render_cache_read_write
= 1;
264 surf
.ss1
.base_addr
= bo
->offset
; /* reloc */
266 surf
.ss2
.width
= w
& 0x7f; /* bits 6:0 of size or width */
267 surf
.ss2
.height
= (w
>> 7) & 0x1fff; /* bits 19:7 of size or width */
268 surf
.ss3
.depth
= (w
>> 20) & 0x7f; /* bits 26:20 of size or width */
269 surf
.ss3
.pitch
= (width
* 16) - 1; /* ignored?? */
270 brw_set_surface_tiling(&surf
, I915_TILING_NONE
); /* tiling now allowed */
272 map
= brw_state_batch(brw
, sizeof(surf
), 32, out_bo
, out_offset
);
273 memcpy(map
, &surf
, sizeof(surf
));
275 /* Emit relocation to surface contents. Section 5.1.1 of the gen4
276 * bspec ("Data Cache") says that the data cache does not exist as
277 * a separate cache and is just the sampler cache.
279 drm_intel_bo_emit_reloc(*out_bo
, (*out_offset
+
280 offsetof(struct brw_surface_state
, ss1
)),
282 I915_GEM_DOMAIN_SAMPLER
, 0);
285 /* Creates a new WM constant buffer reflecting the current fragment program's
286 * constants, if needed by the fragment program.
288 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
292 prepare_wm_constants(struct brw_context
*brw
)
294 struct gl_context
*ctx
= &brw
->intel
.ctx
;
295 struct intel_context
*intel
= &brw
->intel
;
296 struct brw_fragment_program
*fp
=
297 (struct brw_fragment_program
*) brw
->fragment_program
;
298 const int size
= brw
->wm
.prog_data
->nr_pull_params
* sizeof(float);
302 _mesa_load_state_parameters(ctx
, fp
->program
.Base
.Parameters
);
304 /* BRW_NEW_FRAGMENT_PROGRAM */
305 if (brw
->wm
.prog_data
->nr_pull_params
== 0) {
306 if (brw
->wm
.const_bo
) {
307 drm_intel_bo_unreference(brw
->wm
.const_bo
);
308 brw
->wm
.const_bo
= NULL
;
309 brw
->state
.dirty
.brw
|= BRW_NEW_WM_CONSTBUF
;
314 drm_intel_bo_unreference(brw
->wm
.const_bo
);
315 brw
->wm
.const_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "WM const bo",
318 /* _NEW_PROGRAM_CONSTANTS */
319 drm_intel_gem_bo_map_gtt(brw
->wm
.const_bo
);
320 constants
= brw
->wm
.const_bo
->virtual;
321 for (i
= 0; i
< brw
->wm
.prog_data
->nr_pull_params
; i
++) {
322 constants
[i
] = convert_param(brw
->wm
.prog_data
->pull_param_convert
[i
],
323 *brw
->wm
.prog_data
->pull_param
[i
]);
325 drm_intel_gem_bo_unmap_gtt(brw
->wm
.const_bo
);
327 brw
->state
.dirty
.brw
|= BRW_NEW_WM_CONSTBUF
;
330 const struct brw_tracked_state brw_wm_constants
= {
332 .mesa
= (_NEW_PROGRAM_CONSTANTS
),
333 .brw
= (BRW_NEW_FRAGMENT_PROGRAM
),
336 .prepare
= prepare_wm_constants
,
340 * Updates surface / buffer for fragment shader constant buffer, if
343 * This consumes the state updates for the constant buffer, and produces
344 * BRW_NEW_WM_SURFACES to get picked up by brw_prepare_wm_surfaces for
345 * inclusion in the binding table.
347 static void upload_wm_constant_surface(struct brw_context
*brw
)
349 GLuint surf
= SURF_INDEX_FRAG_CONST_BUFFER
;
350 struct brw_fragment_program
*fp
=
351 (struct brw_fragment_program
*) brw
->fragment_program
;
352 const struct gl_program_parameter_list
*params
=
353 fp
->program
.Base
.Parameters
;
355 /* If there's no constant buffer, then no surface BO is needed to point at
358 if (brw
->wm
.const_bo
== 0) {
359 if (brw
->wm
.surf_bo
[surf
] != NULL
) {
360 drm_intel_bo_unreference(brw
->wm
.surf_bo
[surf
]);
361 brw
->wm
.surf_bo
[surf
] = NULL
;
362 brw
->state
.dirty
.brw
|= BRW_NEW_WM_SURFACES
;
367 brw_create_constant_surface(brw
, brw
->wm
.const_bo
, params
->NumParameters
,
368 &brw
->wm
.surf_bo
[surf
],
369 &brw
->wm
.surf_offset
[surf
]);
370 brw
->state
.dirty
.brw
|= BRW_NEW_WM_SURFACES
;
373 const struct brw_tracked_state brw_wm_constant_surface
= {
376 .brw
= (BRW_NEW_WM_CONSTBUF
|
380 .emit
= upload_wm_constant_surface
,
384 brw_update_null_renderbuffer_surface(struct brw_context
*brw
, unsigned int unit
)
386 struct intel_context
*intel
= &brw
->intel
;
387 struct brw_surface_state surf
;
390 memset(&surf
, 0, sizeof(surf
));
392 surf
.ss0
.surface_type
= BRW_SURFACE_NULL
;
393 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
394 surf
.ss1
.base_addr
= 0;
398 brw_set_surface_tiling(&surf
, I915_TILING_NONE
);
401 if (intel
->gen
< 6) {
403 surf
.ss0
.color_blend
= 0;
404 surf
.ss0
.writedisable_red
= 1;
405 surf
.ss0
.writedisable_green
= 1;
406 surf
.ss0
.writedisable_blue
= 1;
407 surf
.ss0
.writedisable_alpha
= 1;
410 map
= brw_state_batch(brw
, sizeof(surf
), 32,
411 &brw
->wm
.surf_bo
[unit
],
412 &brw
->wm
.surf_offset
[unit
]);
413 memcpy(map
, &surf
, sizeof(surf
));
417 * Sets up a surface state structure to point at the given region.
418 * While it is only used for the front/back buffer currently, it should be
419 * usable for further buffers when doing ARB_draw_buffer support.
422 brw_update_renderbuffer_surface(struct brw_context
*brw
,
423 struct gl_renderbuffer
*rb
,
426 struct intel_context
*intel
= &brw
->intel
;
427 struct gl_context
*ctx
= &intel
->ctx
;
428 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
429 struct intel_region
*region
= irb
->region
;
430 struct brw_surface_state surf
;
433 memset(&surf
, 0, sizeof(surf
));
435 switch (irb
->Base
.Format
) {
436 case MESA_FORMAT_XRGB8888
:
437 /* XRGB is handled as ARGB because the chips in this family
438 * cannot render to XRGB targets. This means that we have to
439 * mask writes to alpha (ala glColorMask) and reconfigure the
440 * alpha blending hardware to use GL_ONE (or GL_ZERO) for
441 * cases where GL_DST_ALPHA (or GL_ONE_MINUS_DST_ALPHA) is
444 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
446 case MESA_FORMAT_SARGB8
:
447 /* without GL_EXT_framebuffer_sRGB we shouldn't bind sRGB
448 surfaces to the blend/update as sRGB */
449 if (ctx
->Color
.sRGBEnabled
)
450 surf
.ss0
.surface_format
= brw_format_for_mesa_format
[irb
->Base
.Format
];
452 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
455 surf
.ss0
.surface_format
= brw_format_for_mesa_format
[irb
->Base
.Format
];
456 assert(surf
.ss0
.surface_format
!= 0);
459 surf
.ss0
.surface_type
= BRW_SURFACE_2D
;
460 if (region
->tiling
== I915_TILING_NONE
) {
461 surf
.ss1
.base_addr
= (region
->draw_x
+
462 region
->draw_y
* region
->pitch
) * region
->cpp
;
464 uint32_t tile_base
, tile_x
, tile_y
;
465 uint32_t pitch
= region
->pitch
* region
->cpp
;
467 if (region
->tiling
== I915_TILING_X
) {
468 tile_x
= region
->draw_x
% (512 / region
->cpp
);
469 tile_y
= region
->draw_y
% 8;
470 tile_base
= ((region
->draw_y
/ 8) * (8 * pitch
));
471 tile_base
+= (region
->draw_x
- tile_x
) / (512 / region
->cpp
) * 4096;
474 tile_x
= region
->draw_x
% (128 / region
->cpp
);
475 tile_y
= region
->draw_y
% 32;
476 tile_base
= ((region
->draw_y
/ 32) * (32 * pitch
));
477 tile_base
+= (region
->draw_x
- tile_x
) / (128 / region
->cpp
) * 4096;
479 assert(brw
->has_surface_tile_offset
|| (tile_x
== 0 && tile_y
== 0));
480 assert(tile_x
% 4 == 0);
481 assert(tile_y
% 2 == 0);
482 /* Note that the low bits of these fields are missing, so
483 * there's the possibility of getting in trouble.
485 surf
.ss1
.base_addr
= tile_base
;
486 surf
.ss5
.x_offset
= tile_x
/ 4;
487 surf
.ss5
.y_offset
= tile_y
/ 2;
489 surf
.ss1
.base_addr
+= region
->buffer
->offset
; /* reloc */
491 surf
.ss2
.width
= rb
->Width
- 1;
492 surf
.ss2
.height
= rb
->Height
- 1;
493 brw_set_surface_tiling(&surf
, region
->tiling
);
494 surf
.ss3
.pitch
= (region
->pitch
* region
->cpp
) - 1;
496 if (intel
->gen
< 6) {
498 surf
.ss0
.color_blend
= (!ctx
->Color
._LogicOpEnabled
&&
499 (ctx
->Color
.BlendEnabled
& (1 << unit
)));
500 surf
.ss0
.writedisable_red
= !ctx
->Color
.ColorMask
[unit
][0];
501 surf
.ss0
.writedisable_green
= !ctx
->Color
.ColorMask
[unit
][1];
502 surf
.ss0
.writedisable_blue
= !ctx
->Color
.ColorMask
[unit
][2];
503 /* As mentioned above, disable writes to the alpha component when the
504 * renderbuffer is XRGB.
506 if (ctx
->DrawBuffer
->Visual
.alphaBits
== 0)
507 surf
.ss0
.writedisable_alpha
= 1;
509 surf
.ss0
.writedisable_alpha
= !ctx
->Color
.ColorMask
[unit
][3];
512 map
= brw_state_batch(brw
, sizeof(surf
), 32,
513 &brw
->wm
.surf_bo
[unit
],
514 &brw
->wm
.surf_offset
[unit
]);
515 memcpy(map
, &surf
, sizeof(surf
));
517 drm_intel_bo_emit_reloc(brw
->wm
.surf_bo
[unit
],
518 brw
->wm
.surf_offset
[unit
] +
519 offsetof(struct brw_surface_state
, ss1
),
521 surf
.ss1
.base_addr
- region
->buffer
->offset
,
522 I915_GEM_DOMAIN_RENDER
,
523 I915_GEM_DOMAIN_RENDER
);
527 prepare_wm_surfaces(struct brw_context
*brw
)
529 struct gl_context
*ctx
= &brw
->intel
.ctx
;
533 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
>= 1) {
534 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
535 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
536 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
537 struct intel_region
*region
= irb
? irb
->region
: NULL
;
539 brw_add_validated_bo(brw
, region
->buffer
);
540 nr_surfaces
= SURF_INDEX_DRAW(i
) + 1;
544 if (brw
->wm
.const_bo
) {
545 brw_add_validated_bo(brw
, brw
->wm
.const_bo
);
546 nr_surfaces
= SURF_INDEX_FRAG_CONST_BUFFER
+ 1;
549 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
550 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
551 struct gl_texture_object
*tObj
= texUnit
->_Current
;
552 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
554 if (texUnit
->_ReallyEnabled
) {
555 brw_add_validated_bo(brw
, intelObj
->mt
->region
->buffer
);
556 nr_surfaces
= SURF_INDEX_TEXTURE(i
) + 1;
560 /* Have to update this in our prepare, since the unit's prepare
563 if (brw
->wm
.nr_surfaces
!= nr_surfaces
) {
564 brw
->wm
.nr_surfaces
= nr_surfaces
;
565 brw
->state
.dirty
.brw
|= BRW_NEW_NR_WM_SURFACES
;
570 * Constructs the set of surface state objects pointed to by the
574 upload_wm_surfaces(struct brw_context
*brw
)
576 struct gl_context
*ctx
= &brw
->intel
.ctx
;
579 /* _NEW_BUFFERS | _NEW_COLOR */
580 /* Update surfaces for drawing buffers */
581 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
>= 1) {
582 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
583 if (intel_renderbuffer(ctx
->DrawBuffer
->_ColorDrawBuffers
[i
])) {
584 brw_update_renderbuffer_surface(brw
,
585 ctx
->DrawBuffer
->_ColorDrawBuffers
[i
],
588 brw_update_null_renderbuffer_surface(brw
, i
);
592 brw_update_null_renderbuffer_surface(brw
, 0);
595 /* Update surfaces for textures */
596 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
597 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
598 const GLuint surf
= SURF_INDEX_TEXTURE(i
);
601 if (texUnit
->_ReallyEnabled
) {
602 brw_update_texture_surface(ctx
, i
);
604 drm_intel_bo_unreference(brw
->wm
.surf_bo
[surf
]);
605 brw
->wm
.surf_bo
[surf
] = NULL
;
609 brw
->state
.dirty
.brw
|= BRW_NEW_WM_SURFACES
;
612 const struct brw_tracked_state brw_wm_surfaces
= {
614 .mesa
= (_NEW_COLOR
|
617 .brw
= (BRW_NEW_BATCH
),
620 .prepare
= prepare_wm_surfaces
,
621 .emit
= upload_wm_surfaces
,
625 * Constructs the binding table for the WM surface state, which maps unit
626 * numbers to surface state objects.
629 brw_wm_upload_binding_table(struct brw_context
*brw
)
634 /* Might want to calculate nr_surfaces first, to avoid taking up so much
635 * space for the binding table.
637 bind
= brw_state_batch(brw
, sizeof(uint32_t) * BRW_WM_MAX_SURF
,
638 32, &brw
->wm
.bind_bo
, &brw
->wm
.bind_bo_offset
);
640 for (i
= 0; i
< BRW_WM_MAX_SURF
; i
++) {
641 /* BRW_NEW_WM_SURFACES */
642 bind
[i
] = brw
->wm
.surf_offset
[i
];
643 if (brw
->wm
.surf_bo
[i
]) {
644 bind
[i
] = brw
->wm
.surf_offset
[i
];
650 brw
->state
.dirty
.brw
|= BRW_NEW_BINDING_TABLE
;
653 const struct brw_tracked_state brw_wm_binding_table
= {
656 .brw
= (BRW_NEW_BATCH
|
657 BRW_NEW_WM_SURFACES
),
660 .emit
= brw_wm_upload_binding_table
,