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
->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
->cache
, BRW_SS_SURFACE
,
326 &key
.bo
, key
.bo
? 1 : 0,
328 if (brw
->wm
.surf_bo
[surf
] == NULL
) {
329 brw
->wm
.surf_bo
[surf
] = brw_create_texture_surface(brw
, &key
);
336 * Create the constant buffer surface. Vertex/fragment shader constants will be
337 * read from this buffer with Data Port Read instructions/messages.
340 brw_create_constant_surface( struct brw_context
*brw
,
341 struct brw_surface_key
*key
)
343 const GLint w
= key
->width
- 1;
344 struct brw_surface_state surf
;
347 memset(&surf
, 0, sizeof(surf
));
349 surf
.ss0
.mipmap_layout_mode
= BRW_SURFACE_MIPMAPLAYOUT_BELOW
;
350 surf
.ss0
.surface_type
= BRW_SURFACE_BUFFER
;
351 surf
.ss0
.surface_format
= BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
;
355 surf
.ss1
.base_addr
= key
->bo
->offset
; /* reloc */
357 surf
.ss1
.base_addr
= key
->offset
;
359 surf
.ss2
.width
= w
& 0x7f; /* bits 6:0 of size or width */
360 surf
.ss2
.height
= (w
>> 7) & 0x1fff; /* bits 19:7 of size or width */
361 surf
.ss3
.depth
= (w
>> 20) & 0x7f; /* bits 26:20 of size or width */
362 surf
.ss3
.pitch
= (key
->pitch
* key
->cpp
) - 1; /* ignored?? */
363 brw_set_surface_tiling(&surf
, key
->tiling
); /* tiling now allowed */
365 bo
= brw_upload_cache(&brw
->cache
, BRW_SS_SURFACE
,
367 &key
->bo
, key
->bo
? 1 : 0,
372 /* Emit relocation to surface contents */
373 dri_bo_emit_reloc(bo
,
374 I915_GEM_DOMAIN_SAMPLER
, 0,
376 offsetof(struct brw_surface_state
, ss1
),
385 * Update the surface state for a WM constant buffer.
386 * The constant buffer will be (re)allocated here if needed.
389 brw_update_wm_constant_surface( GLcontext
*ctx
,
391 dri_bo
*const_buffer
,
392 const struct gl_program_parameter_list
*params
)
394 struct brw_context
*brw
= brw_context(ctx
);
395 struct brw_surface_key key
;
396 struct intel_context
*intel
= &brw
->intel
;
397 const int size
= params
->NumParameters
* 4 * sizeof(GLfloat
);
399 /* free old const buffer if too small */
400 if (const_buffer
&& const_buffer
->size
< size
) {
401 dri_bo_unreference(const_buffer
);
405 /* alloc new buffer if needed */
408 drm_intel_bo_alloc(intel
->bufmgr
, "fp_const_buffer", size
, 64);
411 memset(&key
, 0, sizeof(key
));
413 key
.format
= MESA_FORMAT_RGBA_FLOAT32
;
414 key
.internal_format
= GL_RGBA
;
415 key
.bo
= const_buffer
;
416 key
.depthmode
= GL_NONE
;
417 key
.pitch
= params
->NumParameters
;
418 key
.width
= params
->NumParameters
;
424 printf("%s:\n", __FUNCTION__);
425 printf(" width %d height %d depth %d cpp %d pitch %d\n",
426 key.width, key.height, key.depth, key.cpp, key.pitch);
429 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
430 brw
->wm
.surf_bo
[surf
] = brw_search_cache(&brw
->cache
, BRW_SS_SURFACE
,
432 &key
.bo
, key
.bo
? 1 : 0,
434 if (brw
->wm
.surf_bo
[surf
] == NULL
) {
435 brw
->wm
.surf_bo
[surf
] = brw_create_constant_surface(brw
, &key
);
443 * Update the surface state for a VS constant buffer.
444 * The constant buffer will be (re)allocated here if needed.
447 brw_update_vs_constant_surface( GLcontext
*ctx
,
449 dri_bo
*const_buffer
,
450 const struct gl_program_parameter_list
*params
)
452 struct brw_context
*brw
= brw_context(ctx
);
453 struct brw_surface_key key
;
454 struct intel_context
*intel
= &brw
->intel
;
455 const int size
= params
->NumParameters
* 4 * sizeof(GLfloat
);
459 /* free old const buffer if too small */
460 if (const_buffer
&& const_buffer
->size
< size
) {
461 dri_bo_unreference(const_buffer
);
465 /* alloc new buffer if needed */
468 drm_intel_bo_alloc(intel
->bufmgr
, "vp_const_buffer", size
, 64);
471 memset(&key
, 0, sizeof(key
));
473 key
.format
= MESA_FORMAT_RGBA_FLOAT32
;
474 key
.internal_format
= GL_RGBA
;
475 key
.bo
= const_buffer
;
476 key
.depthmode
= GL_NONE
;
477 key
.pitch
= params
->NumParameters
;
478 key
.width
= params
->NumParameters
;
484 printf("%s:\n", __FUNCTION__);
485 printf(" width %d height %d depth %d cpp %d pitch %d\n",
486 key.width, key.height, key.depth, key.cpp, key.pitch);
489 dri_bo_unreference(brw
->vs
.surf_bo
[surf
]);
490 brw
->vs
.surf_bo
[surf
] = brw_search_cache(&brw
->cache
, BRW_SS_SURFACE
,
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
->cache
, BRW_SS_SURFACE
,
577 if (brw
->wm
.surf_bo
[unit
] == NULL
) {
578 struct brw_surface_state surf
;
580 memset(&surf
, 0, sizeof(surf
));
582 surf
.ss0
.surface_format
= key
.surface_format
;
583 surf
.ss0
.surface_type
= key
.surface_type
;
584 surf
.ss1
.base_addr
= key
.draw_offset
;
585 if (region_bo
!= NULL
)
586 surf
.ss1
.base_addr
+= region_bo
->offset
; /* reloc */
588 surf
.ss2
.width
= key
.width
- 1;
589 surf
.ss2
.height
= key
.height
- 1;
590 brw_set_surface_tiling(&surf
, key
.tiling
);
591 surf
.ss3
.pitch
= (key
.pitch
* key
.cpp
) - 1;
594 surf
.ss0
.color_blend
= key
.color_blend
;
595 surf
.ss0
.writedisable_red
= !key
.color_mask
[0];
596 surf
.ss0
.writedisable_green
= !key
.color_mask
[1];
597 surf
.ss0
.writedisable_blue
= !key
.color_mask
[2];
598 surf
.ss0
.writedisable_alpha
= !key
.color_mask
[3];
600 /* Key size will never match key size for textures, so we're safe. */
601 brw
->wm
.surf_bo
[unit
] = brw_upload_cache(&brw
->cache
, BRW_SS_SURFACE
,
606 if (region_bo
!= NULL
) {
607 /* We might sample from it, and we might render to it, so flag
608 * them both. We might be able to figure out from other state
609 * a more restrictive relocation to emit.
611 drm_intel_bo_emit_reloc(brw
->wm
.surf_bo
[unit
],
612 offsetof(struct brw_surface_state
, ss1
),
615 I915_GEM_DOMAIN_RENDER
,
616 I915_GEM_DOMAIN_RENDER
);
623 * Constructs the binding table for the WM surface state, which maps unit
624 * numbers to surface state objects.
627 brw_wm_get_binding_table(struct brw_context
*brw
)
631 assert(brw
->wm
.nr_surfaces
<= BRW_WM_MAX_SURF
);
633 bind_bo
= brw_search_cache(&brw
->cache
, BRW_SS_SURF_BIND
,
635 brw
->wm
.surf_bo
, brw
->wm
.nr_surfaces
,
638 if (bind_bo
== NULL
) {
639 GLuint data_size
= brw
->wm
.nr_surfaces
* sizeof(GLuint
);
640 uint32_t *data
= malloc(data_size
);
643 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++)
644 if (brw
->wm
.surf_bo
[i
])
645 data
[i
] = brw
->wm
.surf_bo
[i
]->offset
;
649 bind_bo
= brw_upload_cache( &brw
->cache
, BRW_SS_SURF_BIND
,
651 brw
->wm
.surf_bo
, brw
->wm
.nr_surfaces
,
655 /* Emit binding table relocations to surface state */
656 for (i
= 0; i
< BRW_WM_MAX_SURF
; i
++) {
657 if (brw
->wm
.surf_bo
[i
] != NULL
) {
658 dri_bo_emit_reloc(bind_bo
,
659 I915_GEM_DOMAIN_INSTRUCTION
, 0,
672 static void prepare_wm_surfaces(struct brw_context
*brw
)
674 GLcontext
*ctx
= &brw
->intel
.ctx
;
675 struct intel_context
*intel
= &brw
->intel
;
680 /* Update surfaces for drawing buffers */
681 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
>= 1) {
682 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
683 brw_update_renderbuffer_surface(brw
,
684 ctx
->DrawBuffer
->_ColorDrawBuffers
[i
],
689 brw_update_renderbuffer_surface(brw
, NULL
, 0, GL_TRUE
);
692 old_nr_surfaces
= brw
->wm
.nr_surfaces
;
693 brw
->wm
.nr_surfaces
= MAX_DRAW_BUFFERS
;
695 /* Update surface / buffer for fragment shader constant buffer */
697 const GLuint surf
= SURF_INDEX_FRAG_CONST_BUFFER
;
698 struct brw_fragment_program
*fp
=
699 (struct brw_fragment_program
*) brw
->fragment_program
;
701 brw_update_wm_constant_surface(ctx
, surf
, fp
->const_buffer
,
702 fp
->program
.Base
.Parameters
);
704 brw
->wm
.nr_surfaces
= surf
+ 1;
707 /* Update surfaces for textures */
708 for (i
= 0; i
< BRW_MAX_TEX_UNIT
; i
++) {
709 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[i
];
710 const GLuint surf
= SURF_INDEX_TEXTURE(i
);
712 /* _NEW_TEXTURE, BRW_NEW_TEXDATA */
713 if (texUnit
->_ReallyEnabled
) {
714 if (texUnit
->_Current
== intel
->frame_buffer_texobj
) {
715 /* render to texture */
716 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
717 brw
->wm
.surf_bo
[surf
] = brw
->wm
.surf_bo
[0];
718 dri_bo_reference(brw
->wm
.surf_bo
[surf
]);
719 brw
->wm
.nr_surfaces
= surf
+ 1;
721 /* regular texture */
722 brw_update_texture_surface(ctx
, i
);
723 brw
->wm
.nr_surfaces
= surf
+ 1;
726 dri_bo_unreference(brw
->wm
.surf_bo
[surf
]);
727 brw
->wm
.surf_bo
[surf
] = NULL
;
731 dri_bo_unreference(brw
->wm
.bind_bo
);
732 brw
->wm
.bind_bo
= brw_wm_get_binding_table(brw
);
734 if (brw
->wm
.nr_surfaces
!= old_nr_surfaces
)
735 brw
->state
.dirty
.brw
|= BRW_NEW_NR_WM_SURFACES
;
740 * Constructs the binding table for the VS surface state.
743 brw_vs_get_binding_table(struct brw_context
*brw
)
747 assert(brw
->vs
.nr_surfaces
<= BRW_VS_MAX_SURF
);
749 bind_bo
= brw_search_cache(&brw
->cache
, BRW_SS_SURF_BIND
,
751 brw
->vs
.surf_bo
, brw
->vs
.nr_surfaces
,
754 if (bind_bo
== NULL
) {
755 GLuint data_size
= brw
->vs
.nr_surfaces
* sizeof(GLuint
);
756 uint32_t *data
= malloc(data_size
);
759 for (i
= 0; i
< brw
->vs
.nr_surfaces
; i
++)
760 if (brw
->vs
.surf_bo
[i
])
761 data
[i
] = brw
->vs
.surf_bo
[i
]->offset
;
765 bind_bo
= brw_upload_cache( &brw
->cache
, BRW_SS_SURF_BIND
,
767 brw
->vs
.surf_bo
, brw
->vs
.nr_surfaces
,
771 /* Emit binding table relocations to surface state */
772 for (i
= 0; i
< BRW_VS_MAX_SURF
; i
++) {
773 if (brw
->vs
.surf_bo
[i
] != NULL
) {
774 dri_bo_emit_reloc(bind_bo
,
775 I915_GEM_DOMAIN_INSTRUCTION
, 0,
790 * Vertex shader surfaces. Just constant buffer for now. Could add vertex
791 * shader textures in the future.
793 static void prepare_vs_surfaces(struct brw_context
*brw
)
795 GLcontext
*ctx
= &brw
->intel
.ctx
;
797 /* Update surface / buffer for vertex shader constant buffer */
799 const GLuint surf
= SURF_INDEX_VERT_CONST_BUFFER
;
800 struct brw_vertex_program
*vp
=
801 (struct brw_vertex_program
*) brw
->vertex_program
;
803 brw_update_vs_constant_surface(ctx
, surf
, vp
->const_buffer
,
804 vp
->program
.Base
.Parameters
);
806 brw
->vs
.nr_surfaces
= 1;
809 dri_bo_unreference(brw
->vs
.bind_bo
);
810 brw
->vs
.bind_bo
= brw_vs_get_binding_table(brw
);
813 brw
->state
.dirty
.brw
|= BRW_NEW_NR_VS_SURFACES
;
818 prepare_surfaces(struct brw_context
*brw
)
820 prepare_wm_surfaces(brw
);
821 prepare_vs_surfaces(brw
);
825 const struct brw_tracked_state brw_wm_surfaces
= {
827 .mesa
= _NEW_COLOR
| _NEW_TEXTURE
| _NEW_BUFFERS
| _NEW_PROGRAM
,
828 .brw
= BRW_NEW_CONTEXT
,
831 .prepare
= prepare_surfaces
,