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/texformat.h"
35 #include "main/texstore.h"
36 #include "shader/prog_parameter.h"
38 #include "intel_mipmap_tree.h"
39 #include "intel_batchbuffer.h"
40 #include "intel_tex.h"
41 #include "intel_fbo.h"
43 #include "brw_context.h"
44 #include "brw_state.h"
45 #include "brw_defines.h"
48 static GLuint
translate_tex_target( GLenum target
)
52 return BRW_SURFACE_1D
;
54 case GL_TEXTURE_RECTANGLE_NV
:
55 return BRW_SURFACE_2D
;
58 return BRW_SURFACE_2D
;
61 return BRW_SURFACE_3D
;
63 case GL_TEXTURE_CUBE_MAP
:
64 return BRW_SURFACE_CUBE
;
73 static GLuint
translate_tex_format( GLuint mesa_format
, GLenum internal_format
,
76 switch( mesa_format
) {
78 return BRW_SURFACEFORMAT_L8_UNORM
;
81 return BRW_SURFACEFORMAT_I8_UNORM
;
84 return BRW_SURFACEFORMAT_A8_UNORM
;
86 case MESA_FORMAT_AL88
:
87 return BRW_SURFACEFORMAT_L8A8_UNORM
;
89 case MESA_FORMAT_RGB888
:
90 assert(0); /* not supported for sampling */
91 return BRW_SURFACEFORMAT_R8G8B8_UNORM
;
93 case MESA_FORMAT_ARGB8888
:
94 if (internal_format
== GL_RGB
)
95 return BRW_SURFACEFORMAT_B8G8R8X8_UNORM
;
97 return BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
99 case MESA_FORMAT_RGBA8888_REV
:
100 if (internal_format
== GL_RGB
)
101 return BRW_SURFACEFORMAT_R8G8B8X8_UNORM
;
103 return BRW_SURFACEFORMAT_R8G8B8A8_UNORM
;
105 case MESA_FORMAT_RGB565
:
106 return BRW_SURFACEFORMAT_B5G6R5_UNORM
;
108 case MESA_FORMAT_ARGB1555
:
109 return BRW_SURFACEFORMAT_B5G5R5A1_UNORM
;
111 case MESA_FORMAT_ARGB4444
:
112 return BRW_SURFACEFORMAT_B4G4R4A4_UNORM
;
114 case MESA_FORMAT_YCBCR_REV
:
115 return BRW_SURFACEFORMAT_YCRCB_NORMAL
;
117 case MESA_FORMAT_YCBCR
:
118 return BRW_SURFACEFORMAT_YCRCB_SWAPUVY
;
120 case MESA_FORMAT_RGB_FXT1
:
121 case MESA_FORMAT_RGBA_FXT1
:
122 return BRW_SURFACEFORMAT_FXT1
;
124 case MESA_FORMAT_Z16
:
125 if (depth_mode
== GL_INTENSITY
)
126 return BRW_SURFACEFORMAT_I16_UNORM
;
127 else if (depth_mode
== GL_ALPHA
)
128 return BRW_SURFACEFORMAT_A16_UNORM
;
130 return BRW_SURFACEFORMAT_L16_UNORM
;
132 case MESA_FORMAT_RGB_DXT1
:
133 return BRW_SURFACEFORMAT_DXT1_RGB
;
135 case MESA_FORMAT_RGBA_DXT1
:
136 return BRW_SURFACEFORMAT_BC1_UNORM
;
138 case MESA_FORMAT_RGBA_DXT3
:
139 return BRW_SURFACEFORMAT_BC2_UNORM
;
141 case MESA_FORMAT_RGBA_DXT5
:
142 return BRW_SURFACEFORMAT_BC3_UNORM
;
144 case MESA_FORMAT_SARGB8
:
145 return BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB
;
147 case MESA_FORMAT_SLA8
:
148 return BRW_SURFACEFORMAT_L8A8_UNORM_SRGB
;
150 case MESA_FORMAT_SL8
:
151 return BRW_SURFACEFORMAT_L8_UNORM_SRGB
;
153 case MESA_FORMAT_SRGB_DXT1
:
154 return BRW_SURFACEFORMAT_BC1_UNORM_SRGB
;
156 case MESA_FORMAT_S8_Z24
:
157 /* XXX: these different surface formats don't seem to
158 * make any difference for shadow sampler/compares.
160 if (depth_mode
== GL_INTENSITY
)
161 return BRW_SURFACEFORMAT_I24X8_UNORM
;
162 else if (depth_mode
== GL_ALPHA
)
163 return BRW_SURFACEFORMAT_A24X8_UNORM
;
165 return BRW_SURFACEFORMAT_L24X8_UNORM
;
167 case MESA_FORMAT_DUDV8
:
168 return BRW_SURFACEFORMAT_R8G8_SNORM
;
170 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
171 return BRW_SURFACEFORMAT_R8G8B8A8_SNORM
;
181 * Use same key for WM and VS surfaces.
183 struct brw_surface_key
{
184 GLenum target
, depthmode
;
186 GLint format
, internal_format
;
187 GLint first_level
, last_level
;
188 GLint width
, height
, depth
;
196 brw_set_surface_tiling(struct brw_surface_state
*surf
, uint32_t tiling
)
199 case I915_TILING_NONE
:
200 surf
->ss3
.tiled_surface
= 0;
201 surf
->ss3
.tile_walk
= 0;
204 surf
->ss3
.tiled_surface
= 1;
205 surf
->ss3
.tile_walk
= BRW_TILEWALK_XMAJOR
;
208 surf
->ss3
.tiled_surface
= 1;
209 surf
->ss3
.tile_walk
= BRW_TILEWALK_YMAJOR
;
215 brw_create_texture_surface( struct brw_context
*brw
,
216 struct brw_surface_key
*key
)
218 struct brw_surface_state surf
;
221 memset(&surf
, 0, sizeof(surf
));
223 surf
.ss0
.mipmap_layout_mode
= BRW_SURFACE_MIPMAPLAYOUT_BELOW
;
224 surf
.ss0
.surface_type
= translate_tex_target(key
->target
);
226 surf
.ss0
.surface_format
= translate_tex_format(key
->format
,
227 key
->internal_format
,
231 switch (key
->depth
) {
233 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
237 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B8G8R8X8_UNORM
;
240 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_B5G6R5_UNORM
;
245 /* This is ok for all textures with channel width 8bit or less:
247 /* surf.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
249 surf
.ss1
.base_addr
= key
->bo
->offset
; /* reloc */
251 surf
.ss1
.base_addr
= key
->offset
;
253 surf
.ss2
.mip_count
= key
->last_level
- key
->first_level
;
254 surf
.ss2
.width
= key
->width
- 1;
255 surf
.ss2
.height
= key
->height
- 1;
256 brw_set_surface_tiling(&surf
, key
->tiling
);
257 surf
.ss3
.pitch
= (key
->pitch
* key
->cpp
) - 1;
258 surf
.ss3
.depth
= key
->depth
- 1;
260 surf
.ss4
.min_lod
= 0;
262 if (key
->target
== GL_TEXTURE_CUBE_MAP
) {
263 surf
.ss0
.cube_pos_x
= 1;
264 surf
.ss0
.cube_pos_y
= 1;
265 surf
.ss0
.cube_pos_z
= 1;
266 surf
.ss0
.cube_neg_x
= 1;
267 surf
.ss0
.cube_neg_y
= 1;
268 surf
.ss0
.cube_neg_z
= 1;
271 bo
= brw_upload_cache(&brw
->surface_cache
, BRW_SS_SURFACE
,
273 &key
->bo
, key
->bo
? 1 : 0,
278 /* Emit relocation to surface contents */
279 dri_bo_emit_reloc(bo
,
280 I915_GEM_DOMAIN_SAMPLER
, 0,
282 offsetof(struct brw_surface_state
, ss1
),
289 brw_update_texture_surface( GLcontext
*ctx
, GLuint unit
)
291 struct brw_context
*brw
= brw_context(ctx
);
292 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[unit
]._Current
;
293 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
294 struct gl_texture_image
*firstImage
= tObj
->Image
[0][intelObj
->firstLevel
];
295 struct brw_surface_key key
;
296 const GLuint surf
= SURF_INDEX_TEXTURE(unit
);
298 memset(&key
, 0, sizeof(key
));
300 if (intelObj
->imageOverride
) {
301 key
.pitch
= intelObj
->pitchOverride
/ intelObj
->mt
->cpp
;
302 key
.depth
= intelObj
->depthOverride
;
304 key
.offset
= intelObj
->textureOffset
;
306 key
.format
= firstImage
->TexFormat
->MesaFormat
;
307 key
.internal_format
= firstImage
->InternalFormat
;
308 key
.pitch
= intelObj
->mt
->pitch
;
309 key
.depth
= firstImage
->Depth
;
310 key
.bo
= intelObj
->mt
->region
->buffer
;
314 key
.target
= tObj
->Target
;
315 key
.depthmode
= tObj
->DepthMode
;
316 key
.first_level
= intelObj
->firstLevel
;
317 key
.last_level
= intelObj
->lastLevel
;
318 key
.width
= firstImage
->Width
;
319 key
.height
= firstImage
->Height
;
320 key
.cpp
= intelObj
->mt
->cpp
;
321 key
.tiling
= intelObj
->mt
->region
->tiling
;
323 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
324 brw
->wm
.surf_bo
[surf
] = brw_search_cache(&brw
->surface_cache
,
327 &key
.bo
, key
.bo
? 1 : 0,
329 if (brw
->wm
.surf_bo
[surf
] == NULL
) {
330 brw
->wm
.surf_bo
[surf
] = brw_create_texture_surface(brw
, &key
);
337 * Create the constant buffer surface. Vertex/fragment shader constants will be
338 * read from this buffer with Data Port Read instructions/messages.
341 brw_create_constant_surface( struct brw_context
*brw
,
342 struct brw_surface_key
*key
)
344 const GLint w
= key
->width
- 1;
345 struct brw_surface_state surf
;
348 memset(&surf
, 0, sizeof(surf
));
350 surf
.ss0
.mipmap_layout_mode
= BRW_SURFACE_MIPMAPLAYOUT_BELOW
;
351 surf
.ss0
.surface_type
= BRW_SURFACE_BUFFER
;
352 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
;
356 surf
.ss1
.base_addr
= key
->bo
->offset
; /* reloc */
358 surf
.ss1
.base_addr
= key
->offset
;
360 surf
.ss2
.width
= w
& 0x7f; /* bits 6:0 of size or width */
361 surf
.ss2
.height
= (w
>> 7) & 0x1fff; /* bits 19:7 of size or width */
362 surf
.ss3
.depth
= (w
>> 20) & 0x7f; /* bits 26:20 of size or width */
363 surf
.ss3
.pitch
= (key
->pitch
* key
->cpp
) - 1; /* ignored?? */
364 brw_set_surface_tiling(&surf
, key
->tiling
); /* tiling now allowed */
366 bo
= brw_upload_cache(&brw
->surface_cache
, BRW_SS_SURFACE
,
368 &key
->bo
, key
->bo
? 1 : 0,
373 /* Emit relocation to surface contents */
374 dri_bo_emit_reloc(bo
,
375 I915_GEM_DOMAIN_SAMPLER
, 0,
377 offsetof(struct brw_surface_state
, ss1
),
386 * Update the surface state for a WM constant buffer.
387 * The constant buffer will be (re)allocated here if needed.
390 brw_update_wm_constant_surface( GLcontext
*ctx
,
392 dri_bo
*const_buffer
,
393 const struct gl_program_parameter_list
*params
)
395 struct brw_context
*brw
= brw_context(ctx
);
396 struct brw_surface_key key
;
397 struct intel_context
*intel
= &brw
->intel
;
398 const int size
= params
->NumParameters
* 4 * sizeof(GLfloat
);
400 /* free old const buffer if too small */
401 if (const_buffer
&& const_buffer
->size
< size
) {
402 dri_bo_unreference(const_buffer
);
406 /* alloc new buffer if needed */
409 drm_intel_bo_alloc(intel
->bufmgr
, "fp_const_buffer", size
, 64);
412 memset(&key
, 0, sizeof(key
));
414 key
.format
= MESA_FORMAT_RGBA_FLOAT32
;
415 key
.internal_format
= GL_RGBA
;
416 key
.bo
= const_buffer
;
417 key
.depthmode
= GL_NONE
;
418 key
.pitch
= params
->NumParameters
;
419 key
.width
= params
->NumParameters
;
425 printf("%s:\n", __FUNCTION__);
426 printf(" width %d height %d depth %d cpp %d pitch %d\n",
427 key.width, key.height, key.depth, key.cpp, key.pitch);
430 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
431 brw
->wm
.surf_bo
[surf
] = brw_search_cache(&brw
->surface_cache
,
434 &key
.bo
, key
.bo
? 1 : 0,
436 if (brw
->wm
.surf_bo
[surf
] == NULL
) {
437 brw
->wm
.surf_bo
[surf
] = brw_create_constant_surface(brw
, &key
);
445 * Update the surface state for a VS constant buffer.
446 * The constant buffer will be (re)allocated here if needed.
449 brw_update_vs_constant_surface( GLcontext
*ctx
,
451 dri_bo
*const_buffer
,
452 const struct gl_program_parameter_list
*params
)
454 struct brw_context
*brw
= brw_context(ctx
);
455 struct brw_surface_key key
;
456 struct intel_context
*intel
= &brw
->intel
;
457 const int size
= params
->NumParameters
* 4 * sizeof(GLfloat
);
461 /* We always create a new VS constant buffer so that several can be
462 * in flight at a time. Free the old one first...
464 dri_bo_unreference(const_buffer
);
466 /* alloc new buffer */
468 drm_intel_bo_alloc(intel
->bufmgr
, "vp_const_buffer", size
, 64);
470 memset(&key
, 0, sizeof(key
));
472 key
.format
= MESA_FORMAT_RGBA_FLOAT32
;
473 key
.internal_format
= GL_RGBA
;
474 key
.bo
= const_buffer
;
475 key
.depthmode
= GL_NONE
;
476 key
.pitch
= params
->NumParameters
;
477 key
.width
= params
->NumParameters
;
483 printf("%s:\n", __FUNCTION__);
484 printf(" width %d height %d depth %d cpp %d pitch %d\n",
485 key.width, key.height, key.depth, key.cpp, key.pitch);
488 dri_bo_unreference(brw
->vs
.surf_bo
[surf
]);
489 brw
->vs
.surf_bo
[surf
] = brw_search_cache(&brw
->surface_cache
,
492 &key
.bo
, key
.bo
? 1 : 0,
494 if (brw
->vs
.surf_bo
[surf
] == NULL
) {
495 brw
->vs
.surf_bo
[surf
] = brw_create_constant_surface(brw
, &key
);
503 * Sets up a surface state structure to point at the given region.
504 * While it is only used for the front/back buffer currently, it should be
505 * usable for further buffers when doing ARB_draw_buffer support.
508 brw_update_renderbuffer_surface(struct brw_context
*brw
,
509 struct gl_renderbuffer
*rb
,
510 unsigned int unit
, GLboolean cached
)
512 GLcontext
*ctx
= &brw
->intel
.ctx
;
513 dri_bo
*region_bo
= NULL
;
514 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
515 struct intel_region
*region
= irb
? irb
->region
: NULL
;
517 unsigned int surface_type
;
518 unsigned int surface_format
;
519 unsigned int width
, height
, pitch
, cpp
;
520 GLubyte color_mask
[4];
521 GLboolean color_blend
;
523 uint32_t draw_offset
;
526 memset(&key
, 0, sizeof(key
));
528 if (region
!= NULL
) {
529 region_bo
= region
->buffer
;
531 key
.surface_type
= BRW_SURFACE_2D
;
532 switch (irb
->texformat
->MesaFormat
) {
533 case MESA_FORMAT_ARGB8888
:
534 key
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
536 case MESA_FORMAT_RGB565
:
537 key
.surface_format
= BRW_SURFACEFORMAT_B5G6R5_UNORM
;
539 case MESA_FORMAT_ARGB1555
:
540 key
.surface_format
= BRW_SURFACEFORMAT_B5G5R5A1_UNORM
;
542 case MESA_FORMAT_ARGB4444
:
543 key
.surface_format
= BRW_SURFACEFORMAT_B4G4R4A4_UNORM
;
546 _mesa_problem(ctx
, "Bad renderbuffer format: %d\n",
547 irb
->texformat
->MesaFormat
);
549 key
.tiling
= region
->tiling
;
550 key
.width
= region
->width
;
551 key
.height
= region
->height
;
552 key
.pitch
= region
->pitch
;
553 key
.cpp
= region
->cpp
;
554 key
.draw_offset
= region
->draw_offset
; /* cur 3d or cube face offset */
556 key
.surface_type
= BRW_SURFACE_NULL
;
557 key
.surface_format
= BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
564 memcpy(key
.color_mask
, ctx
->Color
.ColorMask
,
565 sizeof(key
.color_mask
));
566 key
.color_blend
= (!ctx
->Color
._LogicOpEnabled
&&
567 ctx
->Color
.BlendEnabled
);
569 dri_bo_unreference(brw
->wm
.surf_bo
[unit
]);
570 brw
->wm
.surf_bo
[unit
] = NULL
;
572 brw
->wm
.surf_bo
[unit
] = brw_search_cache(&brw
->surface_cache
,
578 if (brw
->wm
.surf_bo
[unit
] == NULL
) {
579 struct brw_surface_state surf
;
581 memset(&surf
, 0, sizeof(surf
));
583 surf
.ss0
.surface_format
= key
.surface_format
;
584 surf
.ss0
.surface_type
= key
.surface_type
;
585 surf
.ss1
.base_addr
= key
.draw_offset
;
586 if (region_bo
!= NULL
)
587 surf
.ss1
.base_addr
+= region_bo
->offset
; /* reloc */
589 surf
.ss2
.width
= key
.width
- 1;
590 surf
.ss2
.height
= key
.height
- 1;
591 brw_set_surface_tiling(&surf
, key
.tiling
);
592 surf
.ss3
.pitch
= (key
.pitch
* key
.cpp
) - 1;
595 surf
.ss0
.color_blend
= key
.color_blend
;
596 surf
.ss0
.writedisable_red
= !key
.color_mask
[0];
597 surf
.ss0
.writedisable_green
= !key
.color_mask
[1];
598 surf
.ss0
.writedisable_blue
= !key
.color_mask
[2];
599 surf
.ss0
.writedisable_alpha
= !key
.color_mask
[3];
601 /* Key size will never match key size for textures, so we're safe. */
602 brw
->wm
.surf_bo
[unit
] = brw_upload_cache(&brw
->surface_cache
,
608 if (region_bo
!= NULL
) {
609 /* We might sample from it, and we might render to it, so flag
610 * them both. We might be able to figure out from other state
611 * a more restrictive relocation to emit.
613 drm_intel_bo_emit_reloc(brw
->wm
.surf_bo
[unit
],
614 offsetof(struct brw_surface_state
, ss1
),
617 I915_GEM_DOMAIN_RENDER
,
618 I915_GEM_DOMAIN_RENDER
);
625 * Constructs the binding table for the WM surface state, which maps unit
626 * numbers to surface state objects.
629 brw_wm_get_binding_table(struct brw_context
*brw
)
633 assert(brw
->wm
.nr_surfaces
<= BRW_WM_MAX_SURF
);
635 bind_bo
= brw_search_cache(&brw
->surface_cache
, BRW_SS_SURF_BIND
,
637 brw
->wm
.surf_bo
, brw
->wm
.nr_surfaces
,
640 if (bind_bo
== NULL
) {
641 GLuint data_size
= brw
->wm
.nr_surfaces
* sizeof(GLuint
);
642 uint32_t *data
= malloc(data_size
);
645 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++)
646 if (brw
->wm
.surf_bo
[i
])
647 data
[i
] = brw
->wm
.surf_bo
[i
]->offset
;
651 bind_bo
= brw_upload_cache( &brw
->surface_cache
, BRW_SS_SURF_BIND
,
653 brw
->wm
.surf_bo
, brw
->wm
.nr_surfaces
,
657 /* Emit binding table relocations to surface state */
658 for (i
= 0; i
< BRW_WM_MAX_SURF
; i
++) {
659 if (brw
->wm
.surf_bo
[i
] != NULL
) {
660 dri_bo_emit_reloc(bind_bo
,
661 I915_GEM_DOMAIN_INSTRUCTION
, 0,
674 static void prepare_wm_surfaces(struct brw_context
*brw
)
676 GLcontext
*ctx
= &brw
->intel
.ctx
;
677 struct intel_context
*intel
= &brw
->intel
;
682 /* Update surfaces for drawing buffers */
683 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
>= 1) {
684 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
685 brw_update_renderbuffer_surface(brw
,
686 ctx
->DrawBuffer
->_ColorDrawBuffers
[i
],
691 brw_update_renderbuffer_surface(brw
, NULL
, 0, GL_TRUE
);
694 old_nr_surfaces
= brw
->wm
.nr_surfaces
;
695 brw
->wm
.nr_surfaces
= MAX_DRAW_BUFFERS
;
697 /* Update surface / buffer for fragment shader constant buffer */
699 const GLuint surf
= SURF_INDEX_FRAG_CONST_BUFFER
;
700 struct brw_fragment_program
*fp
=
701 (struct brw_fragment_program
*) brw
->fragment_program
;
703 brw_update_wm_constant_surface(ctx
, surf
, fp
->const_buffer
,
704 fp
->program
.Base
.Parameters
);
706 brw
->wm
.nr_surfaces
= surf
+ 1;
709 /* Update surfaces for textures */
710 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
711 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
712 const GLuint surf
= SURF_INDEX_TEXTURE(i
);
714 /* _NEW_TEXTURE, BRW_NEW_TEXDATA */
715 if (texUnit
->_ReallyEnabled
) {
716 if (texUnit
->_Current
== intel
->frame_buffer_texobj
) {
717 /* render to texture */
718 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
719 brw
->wm
.surf_bo
[surf
] = brw
->wm
.surf_bo
[0];
720 dri_bo_reference(brw
->wm
.surf_bo
[surf
]);
721 brw
->wm
.nr_surfaces
= surf
+ 1;
723 /* regular texture */
724 brw_update_texture_surface(ctx
, i
);
725 brw
->wm
.nr_surfaces
= surf
+ 1;
728 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
729 brw
->wm
.surf_bo
[surf
] = NULL
;
733 dri_bo_unreference(brw
->wm
.bind_bo
);
734 brw
->wm
.bind_bo
= brw_wm_get_binding_table(brw
);
736 if (brw
->wm
.nr_surfaces
!= old_nr_surfaces
)
737 brw
->state
.dirty
.brw
|= BRW_NEW_NR_WM_SURFACES
;
742 * Constructs the binding table for the VS surface state.
745 brw_vs_get_binding_table(struct brw_context
*brw
)
749 assert(brw
->vs
.nr_surfaces
<= BRW_VS_MAX_SURF
);
751 bind_bo
= brw_search_cache(&brw
->surface_cache
, BRW_SS_SURF_BIND
,
753 brw
->vs
.surf_bo
, brw
->vs
.nr_surfaces
,
756 if (bind_bo
== NULL
) {
757 GLuint data_size
= brw
->vs
.nr_surfaces
* sizeof(GLuint
);
758 uint32_t *data
= malloc(data_size
);
761 for (i
= 0; i
< brw
->vs
.nr_surfaces
; i
++)
762 if (brw
->vs
.surf_bo
[i
])
763 data
[i
] = brw
->vs
.surf_bo
[i
]->offset
;
767 bind_bo
= brw_upload_cache( &brw
->surface_cache
, BRW_SS_SURF_BIND
,
769 brw
->vs
.surf_bo
, brw
->vs
.nr_surfaces
,
773 /* Emit binding table relocations to surface state */
774 for (i
= 0; i
< BRW_VS_MAX_SURF
; i
++) {
775 if (brw
->vs
.surf_bo
[i
] != NULL
) {
776 dri_bo_emit_reloc(bind_bo
,
777 I915_GEM_DOMAIN_INSTRUCTION
, 0,
792 * Vertex shader surfaces (constant buffer).
794 static void prepare_vs_surfaces(struct brw_context
*brw
)
796 GLcontext
*ctx
= &brw
->intel
.ctx
;
798 /* Update surface / buffer for vertex shader constant buffer */
800 const GLuint surf
= SURF_INDEX_VERT_CONST_BUFFER
;
801 struct brw_vertex_program
*vp
=
802 (struct brw_vertex_program
*) brw
->vertex_program
;
804 brw_update_vs_constant_surface(ctx
, surf
, vp
->const_buffer
,
805 vp
->program
.Base
.Parameters
);
807 brw
->vs
.nr_surfaces
= 1;
810 dri_bo_unreference(brw
->vs
.bind_bo
);
811 brw
->vs
.bind_bo
= brw_vs_get_binding_table(brw
);
814 brw
->state
.dirty
.brw
|= BRW_NEW_NR_VS_SURFACES
;
819 prepare_surfaces(struct brw_context
*brw
)
821 prepare_wm_surfaces(brw
);
822 prepare_vs_surfaces(brw
);
826 const struct brw_tracked_state brw_wm_surfaces
= {
828 .mesa
= (_NEW_COLOR
|
832 _NEW_PROGRAM_CONSTANTS
),
833 .brw
= (BRW_NEW_CONTEXT
),
836 .prepare
= prepare_surfaces
,