2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 #include "main/mtypes.h"
24 #include "main/blend.h"
25 #include "main/samplerobj.h"
26 #include "main/texformat.h"
27 #include "program/prog_parameter.h"
29 #include "intel_mipmap_tree.h"
30 #include "intel_batchbuffer.h"
31 #include "intel_tex.h"
32 #include "intel_fbo.h"
33 #include "intel_buffer_objects.h"
35 #include "brw_context.h"
36 #include "brw_state.h"
37 #include "brw_defines.h"
41 * Convert an swizzle enumeration (i.e. SWIZZLE_X) to one of the Gen7.5+
42 * "Shader Channel Select" enumerations (i.e. HSW_SCS_RED)
45 swizzle_to_scs(GLenum swizzle
)
62 assert(!"Should not get here: invalid swizzle mode");
67 gen7_surface_tiling_mode(uint32_t tiling
)
71 return GEN7_SURFACE_TILING_X
;
73 return GEN7_SURFACE_TILING_Y
;
75 return GEN7_SURFACE_TILING_NONE
;
81 gen7_surface_msaa_bits(unsigned num_samples
, enum intel_msaa_layout layout
)
86 ss4
|= GEN7_SURFACE_MULTISAMPLECOUNT_8
;
87 else if (num_samples
> 1)
88 ss4
|= GEN7_SURFACE_MULTISAMPLECOUNT_4
;
90 ss4
|= GEN7_SURFACE_MULTISAMPLECOUNT_1
;
92 if (layout
== INTEL_MSAA_LAYOUT_IMS
)
93 ss4
|= GEN7_SURFACE_MSFMT_DEPTH_STENCIL
;
95 ss4
|= GEN7_SURFACE_MSFMT_MSS
;
102 gen7_set_surface_mcs_info(struct brw_context
*brw
,
104 uint32_t surf_offset
,
105 const struct intel_mipmap_tree
*mcs_mt
,
106 bool is_render_target
)
108 /* From the Ivy Bridge PRM, Vol4 Part1 p76, "MCS Base Address":
110 * "The MCS surface must be stored as Tile Y."
112 assert(mcs_mt
->region
->tiling
== I915_TILING_Y
);
114 /* Compute the pitch in units of tiles. To do this we need to divide the
115 * pitch in bytes by 128, since a single Y-tile is 128 bytes wide.
117 unsigned pitch_tiles
= mcs_mt
->region
->pitch
/ 128;
119 /* The upper 20 bits of surface state DWORD 6 are the upper 20 bits of the
120 * GPU address of the MCS buffer; the lower 12 bits contain other control
121 * information. Since buffer addresses are always on 4k boundaries (and
122 * thus have their lower 12 bits zero), we can use an ordinary reloc to do
123 * the necessary address translation.
125 assert ((mcs_mt
->region
->bo
->offset
& 0xfff) == 0);
127 surf
[6] = GEN7_SURFACE_MCS_ENABLE
|
128 SET_FIELD(pitch_tiles
- 1, GEN7_SURFACE_MCS_PITCH
) |
129 mcs_mt
->region
->bo
->offset
;
131 drm_intel_bo_emit_reloc(brw
->intel
.batch
.bo
,
135 is_render_target
? I915_GEM_DOMAIN_RENDER
136 : I915_GEM_DOMAIN_SAMPLER
,
137 is_render_target
? I915_GEM_DOMAIN_RENDER
: 0);
142 gen7_check_surface_setup(uint32_t *surf
, bool is_render_target
)
144 unsigned num_multisamples
= surf
[4] & INTEL_MASK(5, 3);
145 unsigned multisampled_surface_storage_format
= surf
[4] & (1 << 6);
146 unsigned surface_array_spacing
= surf
[0] & (1 << 10);
147 bool is_multisampled
= num_multisamples
!= GEN7_SURFACE_MULTISAMPLECOUNT_1
;
149 (void) surface_array_spacing
;
151 /* From the Graphics BSpec: vol5c Shared Functions [SNB+] > State >
152 * SURFACE_STATE > SURFACE_STATE for most messages [DevIVB]: Surface Array
155 * If Multisampled Surface Storage Format is MSFMT_MSS and Number of
156 * Multisamples is not MULTISAMPLECOUNT_1, this field must be set to
159 if (multisampled_surface_storage_format
== GEN7_SURFACE_MSFMT_MSS
161 assert(surface_array_spacing
== GEN7_SURFACE_ARYSPC_LOD0
);
163 /* From the Graphics BSpec: vol5c Shared Functions [SNB+] > State >
164 * SURFACE_STATE > SURFACE_STATE for most messages [DevIVB]: Multisampled
165 * Surface Storage Format:
167 * All multisampled render target surfaces must have this field set to
172 * This field is ignored if Number of Multisamples is MULTISAMPLECOUNT_1.
174 if (is_render_target
&& is_multisampled
) {
175 assert(multisampled_surface_storage_format
== GEN7_SURFACE_MSFMT_MSS
);
178 /* From the Graphics BSpec: vol5c Shared Functions [SNB+] > State >
179 * SURFACE_STATE > SURFACE_STATE for most messages [DevIVB]: Multisampled
180 * Surface Storage Format:
182 * If the surface’s Number of Multisamples is MULTISAMPLECOUNT_8, Width
183 * is >= 8192 (meaning the actual surface width is >= 8193 pixels), this
184 * field must be set to MSFMT_MSS.
186 uint32_t width
= GET_FIELD(surf
[2], GEN7_SURFACE_WIDTH
) + 1;
187 if (num_multisamples
== GEN7_SURFACE_MULTISAMPLECOUNT_8
&& width
>= 8193) {
188 assert(multisampled_surface_storage_format
== GEN7_SURFACE_MSFMT_MSS
);
191 /* From the Graphics BSpec: vol5c Shared Functions [SNB+] > State >
192 * SURFACE_STATE > SURFACE_STATE for most messages [DevIVB]: Multisampled
193 * Surface Storage Format:
195 * If the surface’s Number of Multisamples is MULTISAMPLECOUNT_8,
196 * ((Depth+1) * (Height+1)) is > 4,194,304, OR if the surface’s Number of
197 * Multisamples is MULTISAMPLECOUNT_4, ((Depth+1) * (Height+1)) is >
198 * 8,388,608, this field must be set to MSFMT_DEPTH_STENCIL.This field
199 * must be set to MSFMT_DEPTH_STENCIL if Surface Format is one of the
200 * following: I24X8_UNORM, L24X8_UNORM, A24X8_UNORM, or
201 * R24_UNORM_X8_TYPELESS.
205 * This field is ignored if Number of Multisamples is MULTISAMPLECOUNT_1.
207 uint32_t depth
= GET_FIELD(surf
[3], BRW_SURFACE_DEPTH
) + 1;
208 uint32_t height
= GET_FIELD(surf
[2], GEN7_SURFACE_HEIGHT
) + 1;
209 if (num_multisamples
== GEN7_SURFACE_MULTISAMPLECOUNT_8
&&
210 depth
* height
> 4194304) {
211 assert(multisampled_surface_storage_format
==
212 GEN7_SURFACE_MSFMT_DEPTH_STENCIL
);
214 if (num_multisamples
== GEN7_SURFACE_MULTISAMPLECOUNT_4
&&
215 depth
* height
> 8388608) {
216 assert(multisampled_surface_storage_format
==
217 GEN7_SURFACE_MSFMT_DEPTH_STENCIL
);
219 if (is_multisampled
) {
220 switch (GET_FIELD(surf
[0], BRW_SURFACE_FORMAT
)) {
221 case BRW_SURFACEFORMAT_I24X8_UNORM
:
222 case BRW_SURFACEFORMAT_L24X8_UNORM
:
223 case BRW_SURFACEFORMAT_A24X8_UNORM
:
224 case BRW_SURFACEFORMAT_R24_UNORM_X8_TYPELESS
:
225 assert(multisampled_surface_storage_format
==
226 GEN7_SURFACE_MSFMT_DEPTH_STENCIL
);
233 gen7_update_buffer_texture_surface(struct gl_context
*ctx
,
235 uint32_t *binding_table
,
238 struct brw_context
*brw
= brw_context(ctx
);
239 struct intel_context
*intel
= &brw
->intel
;
240 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[unit
]._Current
;
241 struct intel_buffer_object
*intel_obj
=
242 intel_buffer_object(tObj
->BufferObject
);
243 drm_intel_bo
*bo
= intel_obj
? intel_obj
->buffer
: NULL
;
244 gl_format format
= tObj
->_BufferObjectFormat
;
246 uint32_t *surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
,
247 8 * 4, 32, &binding_table
[surf_index
]);
248 memset(surf
, 0, 8 * 4);
250 uint32_t surface_format
= brw_format_for_mesa_format(format
);
251 if (surface_format
== 0 && format
!= MESA_FORMAT_RGBA_FLOAT32
) {
252 _mesa_problem(NULL
, "bad format %s for texture buffer\n",
253 _mesa_get_format_name(format
));
256 surf
[0] = BRW_SURFACE_BUFFER
<< BRW_SURFACE_TYPE_SHIFT
|
257 surface_format
<< BRW_SURFACE_FORMAT_SHIFT
|
258 BRW_SURFACE_RC_READ_WRITE
;
261 surf
[1] = bo
->offset
; /* reloc */
263 /* Emit relocation to surface contents. Section 5.1.1 of the gen4
264 * bspec ("Data Cache") says that the data cache does not exist as
265 * a separate cache and is just the sampler cache.
267 drm_intel_bo_emit_reloc(intel
->batch
.bo
,
268 binding_table
[surf_index
] + 4,
270 I915_GEM_DOMAIN_SAMPLER
, 0);
272 int texel_size
= _mesa_get_format_bytes(format
);
273 int w
= intel_obj
->Base
.Size
/ texel_size
;
275 /* note that these differ from GEN6 */
276 surf
[2] = SET_FIELD(w
& 0x7f, GEN7_SURFACE_WIDTH
) | /* bits 6:0 of size */
277 SET_FIELD((w
>> 7) & 0x3fff, GEN7_SURFACE_HEIGHT
); /* 20:7 */
278 surf
[3] = SET_FIELD((w
>> 21) & 0x3f, BRW_SURFACE_DEPTH
) | /* bits 26:21 */
282 gen7_check_surface_setup(surf
, false /* is_render_target */);
286 gen7_update_texture_surface(struct gl_context
*ctx
,
288 uint32_t *binding_table
,
291 struct brw_context
*brw
= brw_context(ctx
);
292 struct intel_context
*intel
= &brw
->intel
;
293 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[unit
]._Current
;
294 struct intel_texture_object
*intelObj
= intel_texture_object(tObj
);
295 struct intel_mipmap_tree
*mt
= intelObj
->mt
;
296 struct gl_texture_image
*firstImage
= tObj
->Image
[0][tObj
->BaseLevel
];
297 struct gl_sampler_object
*sampler
= _mesa_get_samplerobj(ctx
, unit
);
298 int width
, height
, depth
;
299 uint32_t tile_x
, tile_y
;
301 if (tObj
->Target
== GL_TEXTURE_BUFFER
) {
302 gen7_update_buffer_texture_surface(ctx
, unit
, binding_table
, surf_index
);
306 intel_miptree_get_dimensions_for_image(firstImage
, &width
, &height
, &depth
);
308 uint32_t *surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
,
309 8 * 4, 32, &binding_table
[surf_index
]);
310 memset(surf
, 0, 8 * 4);
312 uint32_t tex_format
= translate_tex_format(intel
,
314 firstImage
->InternalFormat
,
316 sampler
->sRGBDecode
);
318 surf
[0] = translate_tex_target(tObj
->Target
) << BRW_SURFACE_TYPE_SHIFT
|
319 tex_format
<< BRW_SURFACE_FORMAT_SHIFT
|
320 gen7_surface_tiling_mode(mt
->region
->tiling
) |
321 BRW_SURFACE_CUBEFACE_ENABLES
;
323 if (mt
->align_h
== 4)
324 surf
[0] |= GEN7_SURFACE_VALIGN_4
;
325 if (mt
->align_w
== 8)
326 surf
[0] |= GEN7_SURFACE_HALIGN_8
;
328 if (depth
> 1 && tObj
->Target
!= GL_TEXTURE_3D
)
329 surf
[0] |= GEN7_SURFACE_IS_ARRAY
;
331 if (mt
->array_spacing_lod0
)
332 surf
[0] |= GEN7_SURFACE_ARYSPC_LOD0
;
334 surf
[1] = mt
->region
->bo
->offset
+ mt
->offset
; /* reloc */
335 surf
[1] += intel_miptree_get_tile_offsets(intelObj
->mt
, firstImage
->Level
, 0,
338 surf
[2] = SET_FIELD(width
- 1, GEN7_SURFACE_WIDTH
) |
339 SET_FIELD(height
- 1, GEN7_SURFACE_HEIGHT
);
340 surf
[3] = SET_FIELD(depth
- 1, BRW_SURFACE_DEPTH
) |
341 ((intelObj
->mt
->region
->pitch
) - 1);
343 surf
[4] = gen7_surface_msaa_bits(mt
->num_samples
, mt
->msaa_layout
);
345 assert(brw
->has_surface_tile_offset
|| (tile_x
== 0 && tile_y
== 0));
346 /* Note that the low bits of these fields are missing, so
347 * there's the possibility of getting in trouble.
349 surf
[5] = ((tile_x
/ 4) << BRW_SURFACE_X_OFFSET_SHIFT
|
350 (tile_y
/ 2) << BRW_SURFACE_Y_OFFSET_SHIFT
|
352 (intelObj
->_MaxLevel
- tObj
->BaseLevel
));
354 if (intel
->is_haswell
) {
355 /* Handling GL_ALPHA as a surface format override breaks 1.30+ style
356 * texturing functions that return a float, as our code generation always
357 * selects the .x channel (which would always be 0).
359 const bool alpha_depth
= tObj
->DepthMode
== GL_ALPHA
&&
360 (firstImage
->_BaseFormat
== GL_DEPTH_COMPONENT
||
361 firstImage
->_BaseFormat
== GL_DEPTH_STENCIL
);
363 const int swizzle
= unlikely(alpha_depth
)
364 ? SWIZZLE_XYZW
: brw_get_texture_swizzle(ctx
, tObj
);
367 SET_FIELD(swizzle_to_scs(GET_SWZ(swizzle
, 0)), GEN7_SURFACE_SCS_R
) |
368 SET_FIELD(swizzle_to_scs(GET_SWZ(swizzle
, 1)), GEN7_SURFACE_SCS_G
) |
369 SET_FIELD(swizzle_to_scs(GET_SWZ(swizzle
, 2)), GEN7_SURFACE_SCS_B
) |
370 SET_FIELD(swizzle_to_scs(GET_SWZ(swizzle
, 3)), GEN7_SURFACE_SCS_A
);
373 /* Emit relocation to surface contents */
374 drm_intel_bo_emit_reloc(brw
->intel
.batch
.bo
,
375 binding_table
[surf_index
] + 4,
376 intelObj
->mt
->region
->bo
,
377 surf
[1] - intelObj
->mt
->region
->bo
->offset
,
378 I915_GEM_DOMAIN_SAMPLER
, 0);
380 gen7_check_surface_setup(surf
, false /* is_render_target */);
384 * Create the constant buffer surface. Vertex/fragment shader constants will
385 * be read from this buffer with Data Port Read instructions/messages.
388 gen7_create_constant_surface(struct brw_context
*brw
,
392 uint32_t *out_offset
,
395 struct intel_context
*intel
= &brw
->intel
;
396 uint32_t stride
= dword_pitch
? 4 : 16;
397 uint32_t elements
= ALIGN(size
, stride
) / stride
;
398 const GLint w
= elements
- 1;
400 uint32_t *surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
,
401 8 * 4, 32, out_offset
);
402 memset(surf
, 0, 8 * 4);
404 surf
[0] = BRW_SURFACE_BUFFER
<< BRW_SURFACE_TYPE_SHIFT
|
405 BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
<< BRW_SURFACE_FORMAT_SHIFT
|
406 BRW_SURFACE_RC_READ_WRITE
;
409 surf
[1] = bo
->offset
+ offset
; /* reloc */
411 /* note that these differ from GEN6 */
412 surf
[2] = SET_FIELD(w
& 0x7f, GEN7_SURFACE_WIDTH
) |
413 SET_FIELD((w
>> 7) & 0x3fff, GEN7_SURFACE_HEIGHT
);
414 surf
[3] = SET_FIELD((w
>> 21) & 0x3f, BRW_SURFACE_DEPTH
) |
417 if (intel
->is_haswell
) {
418 surf
[7] = SET_FIELD(HSW_SCS_RED
, GEN7_SURFACE_SCS_R
) |
419 SET_FIELD(HSW_SCS_GREEN
, GEN7_SURFACE_SCS_G
) |
420 SET_FIELD(HSW_SCS_BLUE
, GEN7_SURFACE_SCS_B
) |
421 SET_FIELD(HSW_SCS_ALPHA
, GEN7_SURFACE_SCS_A
);
424 /* Emit relocation to surface contents. Section 5.1.1 of the gen4
425 * bspec ("Data Cache") says that the data cache does not exist as
426 * a separate cache and is just the sampler cache.
428 drm_intel_bo_emit_reloc(intel
->batch
.bo
,
431 I915_GEM_DOMAIN_SAMPLER
, 0);
433 gen7_check_surface_setup(surf
, false /* is_render_target */);
437 * Create a surface for shader time.
440 gen7_create_shader_time_surface(struct brw_context
*brw
, uint32_t *out_offset
)
442 struct intel_context
*intel
= &brw
->intel
;
443 const int w
= brw
->shader_time
.bo
->size
- 1;
445 uint32_t *surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
,
446 8 * 4, 32, out_offset
);
447 memset(surf
, 0, 8 * 4);
449 surf
[0] = BRW_SURFACE_BUFFER
<< BRW_SURFACE_TYPE_SHIFT
|
450 BRW_SURFACEFORMAT_RAW
<< BRW_SURFACE_FORMAT_SHIFT
|
451 BRW_SURFACE_RC_READ_WRITE
;
453 surf
[1] = brw
->shader_time
.bo
->offset
; /* reloc */
455 /* note that these differ from GEN6 */
456 surf
[2] = SET_FIELD(w
& 0x7f, GEN7_SURFACE_WIDTH
) |
457 SET_FIELD((w
>> 7) & 0x3fff, GEN7_SURFACE_HEIGHT
);
458 surf
[3] = SET_FIELD((w
>> 21) & 0x3f, BRW_SURFACE_DEPTH
);
460 /* Unlike texture or renderbuffer surfaces, we only do untyped operations
461 * on the shader_time surface, so there's no need to set HSW channel
465 /* Emit relocation to surface contents. Section 5.1.1 of the gen4
466 * bspec ("Data Cache") says that the data cache does not exist as
467 * a separate cache and is just the sampler cache.
469 drm_intel_bo_emit_reloc(intel
->batch
.bo
,
471 brw
->shader_time
.bo
, 0,
472 I915_GEM_DOMAIN_SAMPLER
, 0);
474 gen7_check_surface_setup(surf
, false /* is_render_target */);
478 gen7_update_null_renderbuffer_surface(struct brw_context
*brw
, unsigned unit
)
480 /* From the Ivy bridge PRM, Vol4 Part1 p62 (Surface Type: Programming
483 * A null surface is used in instances where an actual surface is not
484 * bound. When a write message is generated to a null surface, no
485 * actual surface is written to. When a read message (including any
486 * sampling engine message) is generated to a null surface, the result
487 * is all zeros. Note that a null surface type is allowed to be used
488 * with all messages, even if it is not specificially indicated as
489 * supported. All of the remaining fields in surface state are ignored
490 * for null surfaces, with the following exceptions: Width, Height,
491 * Depth, LOD, and Render Target View Extent fields must match the
492 * depth buffer’s corresponding state for all render target surfaces,
495 struct intel_context
*intel
= &brw
->intel
;
496 struct gl_context
*ctx
= &intel
->ctx
;
499 const struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
501 uint32_t *surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
,
502 8 * 4, 32, &brw
->wm
.surf_offset
[unit
]);
503 memset(surf
, 0, 8 * 4);
505 /* From the Ivybridge PRM, Volume 4, Part 1, page 65,
506 * Tiled Surface: Programming Notes:
507 * "If Surface Type is SURFTYPE_NULL, this field must be TRUE."
509 surf
[0] = BRW_SURFACE_NULL
<< BRW_SURFACE_TYPE_SHIFT
|
510 BRW_SURFACEFORMAT_B8G8R8A8_UNORM
<< BRW_SURFACE_FORMAT_SHIFT
|
511 GEN7_SURFACE_TILING_Y
;
513 surf
[2] = SET_FIELD(fb
->Width
- 1, GEN7_SURFACE_WIDTH
) |
514 SET_FIELD(fb
->Height
- 1, GEN7_SURFACE_HEIGHT
);
516 gen7_check_surface_setup(surf
, true /* is_render_target */);
520 * Sets up a surface state structure to point at the given region.
521 * While it is only used for the front/back buffer currently, it should be
522 * usable for further buffers when doing ARB_draw_buffer support.
525 gen7_update_renderbuffer_surface(struct brw_context
*brw
,
526 struct gl_renderbuffer
*rb
,
530 struct intel_context
*intel
= &brw
->intel
;
531 struct gl_context
*ctx
= &intel
->ctx
;
532 struct intel_renderbuffer
*irb
= intel_renderbuffer(rb
);
533 struct intel_region
*region
= irb
->mt
->region
;
536 gl_format rb_format
= _mesa_get_render_format(ctx
, intel_rb_format(irb
));
538 bool is_array
= false;
539 int depth
= MAX2(rb
->Depth
, 1);
540 int min_array_element
;
541 GLenum gl_target
= rb
->TexImage
?
542 rb
->TexImage
->TexObject
->Target
: GL_TEXTURE_2D
;
544 uint32_t *surf
= brw_state_batch(brw
, AUB_TRACE_SURFACE_STATE
,
545 8 * 4, 32, &brw
->wm
.surf_offset
[unit
]);
546 memset(surf
, 0, 8 * 4);
548 intel_miptree_used_for_rendering(irb
->mt
);
550 /* Render targets can't use IMS layout */
551 assert(irb
->mt
->msaa_layout
!= INTEL_MSAA_LAYOUT_IMS
);
553 assert(brw_render_target_supported(intel
, rb
));
554 format
= brw
->render_target_format
[rb_format
];
555 if (unlikely(!brw
->format_supported_as_render_target
[rb_format
])) {
556 _mesa_problem(ctx
, "%s: renderbuffer format %s unsupported\n",
557 __FUNCTION__
, _mesa_get_format_name(rb_format
));
561 case GL_TEXTURE_CUBE_MAP_ARRAY
:
562 case GL_TEXTURE_CUBE_MAP
:
563 surftype
= BRW_SURFACE_2D
;
568 surftype
= translate_tex_target(gl_target
);
569 is_array
= _mesa_tex_target_is_array(gl_target
);
574 min_array_element
= 0;
575 } else if (irb
->mt
->num_samples
> 1) {
576 min_array_element
= irb
->mt_layer
/ irb
->mt
->num_samples
;
578 min_array_element
= irb
->mt_layer
;
581 surf
[0] = surftype
<< BRW_SURFACE_TYPE_SHIFT
|
582 format
<< BRW_SURFACE_FORMAT_SHIFT
|
583 (irb
->mt
->array_spacing_lod0
? GEN7_SURFACE_ARYSPC_LOD0
584 : GEN7_SURFACE_ARYSPC_FULL
) |
585 gen7_surface_tiling_mode(region
->tiling
);
587 if (irb
->mt
->align_h
== 4)
588 surf
[0] |= GEN7_SURFACE_VALIGN_4
;
589 if (irb
->mt
->align_w
== 8)
590 surf
[0] |= GEN7_SURFACE_HALIGN_8
;
593 surf
[0] |= GEN7_SURFACE_IS_ARRAY
;
596 surf
[1] = region
->bo
->offset
;
598 assert(brw
->has_surface_tile_offset
);
600 surf
[5] = irb
->mt_level
;
602 surf
[2] = SET_FIELD(irb
->mt
->logical_width0
- 1, GEN7_SURFACE_WIDTH
) |
603 SET_FIELD(irb
->mt
->logical_height0
- 1, GEN7_SURFACE_HEIGHT
);
605 surf
[3] = ((depth
- 1) << BRW_SURFACE_DEPTH_SHIFT
) |
608 surf
[4] = gen7_surface_msaa_bits(irb
->mt
->num_samples
, irb
->mt
->msaa_layout
) |
609 min_array_element
<< GEN7_SURFACE_MIN_ARRAY_ELEMENT_SHIFT
|
610 (depth
- 1) << GEN7_SURFACE_RENDER_TARGET_VIEW_EXTENT_SHIFT
;
612 if (irb
->mt
->mcs_mt
) {
613 gen7_set_surface_mcs_info(brw
, surf
, brw
->wm
.surf_offset
[unit
],
614 irb
->mt
->mcs_mt
, true /* is RT */);
617 if (intel
->is_haswell
) {
618 surf
[7] = SET_FIELD(HSW_SCS_RED
, GEN7_SURFACE_SCS_R
) |
619 SET_FIELD(HSW_SCS_GREEN
, GEN7_SURFACE_SCS_G
) |
620 SET_FIELD(HSW_SCS_BLUE
, GEN7_SURFACE_SCS_B
) |
621 SET_FIELD(HSW_SCS_ALPHA
, GEN7_SURFACE_SCS_A
);
624 drm_intel_bo_emit_reloc(brw
->intel
.batch
.bo
,
625 brw
->wm
.surf_offset
[unit
] + 4,
627 surf
[1] - region
->bo
->offset
,
628 I915_GEM_DOMAIN_RENDER
,
629 I915_GEM_DOMAIN_RENDER
);
631 gen7_check_surface_setup(surf
, true /* is_render_target */);
635 gen7_init_vtable_surface_functions(struct brw_context
*brw
)
637 struct intel_context
*intel
= &brw
->intel
;
639 intel
->vtbl
.update_texture_surface
= gen7_update_texture_surface
;
640 intel
->vtbl
.update_renderbuffer_surface
= gen7_update_renderbuffer_surface
;
641 intel
->vtbl
.update_null_renderbuffer_surface
=
642 gen7_update_null_renderbuffer_surface
;
643 intel
->vtbl
.create_constant_surface
= gen7_create_constant_surface
;