f6cc6e927105589777cd0205a406debc91fb3d36
[mesa.git] / src / gallium / drivers / ilo / ilo_gpe_gen7.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "util/u_resource.h"
29 #include "brw_defines.h"
30 #include "intel_reg.h"
31
32 #include "ilo_format.h"
33 #include "ilo_resource.h"
34 #include "ilo_shader.h"
35 #include "ilo_gpe_gen7.h"
36
37 void
38 ilo_gpe_init_gs_cso_gen7(const struct ilo_dev_info *dev,
39 const struct ilo_shader_state *gs,
40 struct ilo_shader_cso *cso)
41 {
42 int start_grf, vue_read_len, max_threads;
43 uint32_t dw2, dw4, dw5;
44
45 ILO_GPE_VALID_GEN(dev, 7, 7);
46
47 start_grf = ilo_shader_get_kernel_param(gs, ILO_KERNEL_URB_DATA_START_REG);
48 vue_read_len = ilo_shader_get_kernel_param(gs, ILO_KERNEL_INPUT_COUNT);
49
50 /* in pairs */
51 vue_read_len = (vue_read_len + 1) / 2;
52
53 switch (dev->gen) {
54 case ILO_GEN(7):
55 max_threads = (dev->gt == 2) ? 128 : 36;
56 break;
57 default:
58 max_threads = 1;
59 break;
60 }
61
62 dw2 = (true) ? 0 : GEN6_GS_FLOATING_POINT_MODE_ALT;
63
64 dw4 = vue_read_len << GEN6_GS_URB_READ_LENGTH_SHIFT |
65 GEN7_GS_INCLUDE_VERTEX_HANDLES |
66 0 << GEN6_GS_URB_ENTRY_READ_OFFSET_SHIFT |
67 start_grf << GEN6_GS_DISPATCH_START_GRF_SHIFT;
68
69 dw5 = (max_threads - 1) << GEN6_GS_MAX_THREADS_SHIFT |
70 GEN6_GS_STATISTICS_ENABLE |
71 GEN6_GS_ENABLE;
72
73 STATIC_ASSERT(Elements(cso->payload) >= 3);
74 cso->payload[0] = dw2;
75 cso->payload[1] = dw4;
76 cso->payload[2] = dw5;
77 }
78
79 void
80 ilo_gpe_init_rasterizer_wm_gen7(const struct ilo_dev_info *dev,
81 const struct pipe_rasterizer_state *state,
82 struct ilo_rasterizer_wm *wm)
83 {
84 uint32_t dw1, dw2;
85
86 ILO_GPE_VALID_GEN(dev, 7, 7);
87
88 dw1 = GEN7_WM_POSITION_ZW_PIXEL |
89 GEN7_WM_LINE_AA_WIDTH_2_0 |
90 GEN7_WM_MSRAST_OFF_PIXEL;
91
92 /* same value as in 3DSTATE_SF */
93 if (state->line_smooth)
94 dw1 |= GEN7_WM_LINE_END_CAP_AA_WIDTH_1_0;
95
96 if (state->poly_stipple_enable)
97 dw1 |= GEN7_WM_POLYGON_STIPPLE_ENABLE;
98 if (state->line_stipple_enable)
99 dw1 |= GEN7_WM_LINE_STIPPLE_ENABLE;
100
101 if (state->bottom_edge_rule)
102 dw1 |= GEN7_WM_POINT_RASTRULE_UPPER_RIGHT;
103
104 dw2 = GEN7_WM_MSDISPMODE_PERSAMPLE;
105
106 /*
107 * assertion that makes sure
108 *
109 * dw1 |= wm->dw_msaa_rast;
110 * dw2 |= wm->dw_msaa_disp;
111 *
112 * is valid
113 */
114 STATIC_ASSERT(GEN7_WM_MSRAST_OFF_PIXEL == 0 &&
115 GEN7_WM_MSDISPMODE_PERSAMPLE == 0);
116
117 wm->dw_msaa_rast =
118 (state->multisample) ? GEN7_WM_MSRAST_ON_PATTERN : 0;
119 wm->dw_msaa_disp = GEN7_WM_MSDISPMODE_PERPIXEL;
120
121 STATIC_ASSERT(Elements(wm->payload) >= 2);
122 wm->payload[0] = dw1;
123 wm->payload[1] = dw2;
124 }
125
126 void
127 ilo_gpe_init_fs_cso_gen7(const struct ilo_dev_info *dev,
128 const struct ilo_shader_state *fs,
129 struct ilo_shader_cso *cso)
130 {
131 int start_grf, max_threads;
132 uint32_t dw2, dw4, dw5;
133 uint32_t wm_interps, wm_dw1;
134
135 ILO_GPE_VALID_GEN(dev, 7, 7);
136
137 start_grf = ilo_shader_get_kernel_param(fs, ILO_KERNEL_URB_DATA_START_REG);
138 /* see brwCreateContext() */
139 max_threads = (dev->gt == 2) ? 172 : 48;
140
141 dw2 = (true) ? 0 : GEN7_PS_FLOATING_POINT_MODE_ALT;
142
143 dw4 = (max_threads - 1) << IVB_PS_MAX_THREADS_SHIFT |
144 GEN7_PS_POSOFFSET_NONE;
145
146 if (false)
147 dw4 |= GEN7_PS_PUSH_CONSTANT_ENABLE;
148
149 if (ilo_shader_get_kernel_param(fs, ILO_KERNEL_INPUT_COUNT))
150 dw4 |= GEN7_PS_ATTRIBUTE_ENABLE;
151
152 assert(!ilo_shader_get_kernel_param(fs, ILO_KERNEL_FS_DISPATCH_16_OFFSET));
153 dw4 |= GEN7_PS_8_DISPATCH_ENABLE;
154
155 dw5 = start_grf << GEN7_PS_DISPATCH_START_GRF_SHIFT_0 |
156 0 << GEN7_PS_DISPATCH_START_GRF_SHIFT_1 |
157 0 << GEN7_PS_DISPATCH_START_GRF_SHIFT_2;
158
159 /* FS affects 3DSTATE_WM too */
160 wm_dw1 = 0;
161
162 /*
163 * TODO set this bit only when
164 *
165 * a) fs writes colors and color is not masked, or
166 * b) fs writes depth, or
167 * c) fs or cc kills
168 */
169 wm_dw1 |= GEN7_WM_DISPATCH_ENABLE;
170
171 /*
172 * From the Ivy Bridge PRM, volume 2 part 1, page 278:
173 *
174 * "This bit (Pixel Shader Kill Pixel), if ENABLED, indicates that
175 * the PS kernel or color calculator has the ability to kill
176 * (discard) pixels or samples, other than due to depth or stencil
177 * testing. This bit is required to be ENABLED in the following
178 * situations:
179 *
180 * - The API pixel shader program contains "killpix" or "discard"
181 * instructions, or other code in the pixel shader kernel that
182 * can cause the final pixel mask to differ from the pixel mask
183 * received on dispatch.
184 *
185 * - A sampler with chroma key enabled with kill pixel mode is used
186 * by the pixel shader.
187 *
188 * - Any render target has Alpha Test Enable or AlphaToCoverage
189 * Enable enabled.
190 *
191 * - The pixel shader kernel generates and outputs oMask.
192 *
193 * Note: As ClipDistance clipping is fully supported in hardware
194 * and therefore not via PS instructions, there should be no need
195 * to ENABLE this bit due to ClipDistance clipping."
196 */
197 if (ilo_shader_get_kernel_param(fs, ILO_KERNEL_FS_USE_KILL))
198 wm_dw1 |= GEN7_WM_KILL_ENABLE;
199
200 if (ilo_shader_get_kernel_param(fs, ILO_KERNEL_FS_OUTPUT_Z))
201 wm_dw1 |= GEN7_WM_PSCDEPTH_ON;
202
203 if (ilo_shader_get_kernel_param(fs, ILO_KERNEL_FS_INPUT_Z))
204 wm_dw1 |= GEN7_WM_USES_SOURCE_DEPTH;
205
206 if (ilo_shader_get_kernel_param(fs, ILO_KERNEL_FS_INPUT_W))
207 wm_dw1 |= GEN7_WM_USES_SOURCE_W;
208
209 wm_interps = ilo_shader_get_kernel_param(fs,
210 ILO_KERNEL_FS_BARYCENTRIC_INTERPOLATIONS);
211
212 wm_dw1 |= wm_interps << GEN7_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT;
213
214 STATIC_ASSERT(Elements(cso->payload) >= 4);
215 cso->payload[0] = dw2;
216 cso->payload[1] = dw4;
217 cso->payload[2] = dw5;
218 cso->payload[3] = wm_dw1;
219 }
220
221 void
222 ilo_gpe_init_view_surface_null_gen7(const struct ilo_dev_info *dev,
223 unsigned width, unsigned height,
224 unsigned depth, unsigned level,
225 struct ilo_view_surface *surf)
226 {
227 uint32_t *dw;
228
229 ILO_GPE_VALID_GEN(dev, 7, 7);
230
231 /*
232 * From the Ivy Bridge PRM, volume 4 part 1, page 62:
233 *
234 * "A null surface is used in instances where an actual surface is not
235 * bound. When a write message is generated to a null surface, no
236 * actual surface is written to. When a read message (including any
237 * sampling engine message) is generated to a null surface, the result
238 * is all zeros. Note that a null surface type is allowed to be used
239 * with all messages, even if it is not specificially indicated as
240 * supported. All of the remaining fields in surface state are ignored
241 * for null surfaces, with the following exceptions:
242 *
243 * * Width, Height, Depth, LOD, and Render Target View Extent fields
244 * must match the depth buffer's corresponding state for all render
245 * target surfaces, including null.
246 * * All sampling engine and data port messages support null surfaces
247 * with the above behavior, even if not mentioned as specifically
248 * supported, except for the following:
249 * * Data Port Media Block Read/Write messages.
250 * * The Surface Type of a surface used as a render target (accessed
251 * via the Data Port's Render Target Write message) must be the same
252 * as the Surface Type of all other render targets and of the depth
253 * buffer (defined in 3DSTATE_DEPTH_BUFFER), unless either the depth
254 * buffer or render targets are SURFTYPE_NULL."
255 *
256 * From the Ivy Bridge PRM, volume 4 part 1, page 65:
257 *
258 * "If Surface Type is SURFTYPE_NULL, this field (Tiled Surface) must be
259 * true"
260 */
261
262 STATIC_ASSERT(Elements(surf->payload) >= 8);
263 dw = surf->payload;
264
265 dw[0] = BRW_SURFACE_NULL << BRW_SURFACE_TYPE_SHIFT |
266 BRW_SURFACEFORMAT_B8G8R8A8_UNORM << BRW_SURFACE_FORMAT_SHIFT |
267 BRW_SURFACE_TILED << 13;
268
269 dw[1] = 0;
270
271 dw[2] = SET_FIELD(height - 1, GEN7_SURFACE_HEIGHT) |
272 SET_FIELD(width - 1, GEN7_SURFACE_WIDTH);
273
274 dw[3] = SET_FIELD(depth - 1, BRW_SURFACE_DEPTH);
275
276 dw[4] = 0;
277 dw[5] = level;
278
279 dw[6] = 0;
280 dw[7] = 0;
281
282 surf->bo = NULL;
283 }
284
285 void
286 ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info *dev,
287 const struct ilo_buffer *buf,
288 unsigned offset, unsigned size,
289 unsigned struct_size,
290 enum pipe_format elem_format,
291 bool is_rt, bool render_cache_rw,
292 struct ilo_view_surface *surf)
293 {
294 const bool typed = (elem_format != PIPE_FORMAT_NONE);
295 const bool structured = (!typed && struct_size > 1);
296 const int elem_size = (typed) ?
297 util_format_get_blocksize(elem_format) : 1;
298 int width, height, depth, pitch;
299 int surface_type, surface_format, num_entries;
300 uint32_t *dw;
301
302 ILO_GPE_VALID_GEN(dev, 7, 7);
303
304 surface_type = (structured) ? 5 : BRW_SURFACE_BUFFER;
305
306 surface_format = (typed) ?
307 ilo_translate_color_format(elem_format) : BRW_SURFACEFORMAT_RAW;
308
309 num_entries = size / struct_size;
310 /* see if there is enough space to fit another element */
311 if (size % struct_size >= elem_size && !structured)
312 num_entries++;
313
314 /*
315 * From the Ivy Bridge PRM, volume 4 part 1, page 67:
316 *
317 * "For SURFTYPE_BUFFER render targets, this field (Surface Base
318 * Address) specifies the base address of first element of the
319 * surface. The surface is interpreted as a simple array of that
320 * single element type. The address must be naturally-aligned to the
321 * element size (e.g., a buffer containing R32G32B32A32_FLOAT elements
322 * must be 16-byte aligned)
323 *
324 * For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
325 * the base address of the first element of the surface, computed in
326 * software by adding the surface base address to the byte offset of
327 * the element in the buffer."
328 */
329 if (is_rt)
330 assert(offset % elem_size == 0);
331
332 /*
333 * From the Ivy Bridge PRM, volume 4 part 1, page 68:
334 *
335 * "For typed buffer and structured buffer surfaces, the number of
336 * entries in the buffer ranges from 1 to 2^27. For raw buffer
337 * surfaces, the number of entries in the buffer is the number of
338 * bytes which can range from 1 to 2^30."
339 */
340 assert(num_entries >= 1 &&
341 num_entries <= 1 << ((typed || structured) ? 27 : 30));
342
343 /*
344 * From the Ivy Bridge PRM, volume 4 part 1, page 69:
345 *
346 * "For SURFTYPE_BUFFER: The low two bits of this field (Width) must be
347 * 11 if the Surface Format is RAW (the size of the buffer must be a
348 * multiple of 4 bytes)."
349 *
350 * From the Ivy Bridge PRM, volume 4 part 1, page 70:
351 *
352 * "For surfaces of type SURFTYPE_BUFFER and SURFTYPE_STRBUF, this
353 * field (Surface Pitch) indicates the size of the structure."
354 *
355 * "For linear surfaces with Surface Type of SURFTYPE_STRBUF, the pitch
356 * must be a multiple of 4 bytes."
357 */
358 if (structured)
359 assert(struct_size % 4 == 0);
360 else if (!typed)
361 assert(num_entries % 4 == 0);
362
363 pitch = struct_size;
364
365 pitch--;
366 num_entries--;
367 /* bits [6:0] */
368 width = (num_entries & 0x0000007f);
369 /* bits [20:7] */
370 height = (num_entries & 0x001fff80) >> 7;
371 /* bits [30:21] */
372 depth = (num_entries & 0x7fe00000) >> 21;
373 /* limit to [26:21] */
374 if (typed || structured)
375 depth &= 0x3f;
376
377 STATIC_ASSERT(Elements(surf->payload) >= 8);
378 dw = surf->payload;
379
380 dw[0] = surface_type << BRW_SURFACE_TYPE_SHIFT |
381 surface_format << BRW_SURFACE_FORMAT_SHIFT;
382 if (render_cache_rw)
383 dw[0] |= BRW_SURFACE_RC_READ_WRITE;
384
385 dw[1] = offset;
386
387 dw[2] = SET_FIELD(height, GEN7_SURFACE_HEIGHT) |
388 SET_FIELD(width, GEN7_SURFACE_WIDTH);
389
390 dw[3] = SET_FIELD(depth, BRW_SURFACE_DEPTH) |
391 pitch;
392
393 dw[4] = 0;
394 dw[5] = 0;
395
396 dw[6] = 0;
397 dw[7] = 0;
398
399 /* do not increment reference count */
400 surf->bo = buf->bo;
401 }
402
403 void
404 ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info *dev,
405 const struct ilo_texture *tex,
406 enum pipe_format format,
407 unsigned first_level,
408 unsigned num_levels,
409 unsigned first_layer,
410 unsigned num_layers,
411 bool is_rt, bool render_cache_rw,
412 struct ilo_view_surface *surf)
413 {
414 int surface_type, surface_format;
415 int width, height, depth, pitch, lod;
416 unsigned layer_offset, x_offset, y_offset;
417 uint32_t *dw;
418
419 ILO_GPE_VALID_GEN(dev, 7, 7);
420
421 surface_type = ilo_gpe_gen6_translate_texture(tex->base.target);
422 assert(surface_type != BRW_SURFACE_BUFFER);
423
424 if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT && tex->separate_s8)
425 format = PIPE_FORMAT_Z32_FLOAT;
426
427 if (is_rt)
428 surface_format = ilo_translate_render_format(format);
429 else
430 surface_format = ilo_translate_texture_format(format);
431 assert(surface_format >= 0);
432
433 width = tex->base.width0;
434 height = tex->base.height0;
435 depth = (tex->base.target == PIPE_TEXTURE_3D) ?
436 tex->base.depth0 : num_layers;
437 pitch = tex->bo_stride;
438
439 if (surface_type == BRW_SURFACE_CUBE) {
440 /*
441 * From the Ivy Bridge PRM, volume 4 part 1, page 70:
442 *
443 * "For SURFTYPE_CUBE:For Sampling Engine Surfaces, the range of
444 * this field is [0,340], indicating the number of cube array
445 * elements (equal to the number of underlying 2D array elements
446 * divided by 6). For other surfaces, this field must be zero."
447 *
448 * When is_rt is true, we treat the texture as a 2D one to avoid the
449 * restriction.
450 */
451 if (is_rt) {
452 surface_type = BRW_SURFACE_2D;
453 }
454 else {
455 assert(num_layers % 6 == 0);
456 depth = num_layers / 6;
457 }
458 }
459
460 /* sanity check the size */
461 assert(width >= 1 && height >= 1 && depth >= 1 && pitch >= 1);
462 assert(first_layer < 2048 && num_layers <= 2048);
463 switch (surface_type) {
464 case BRW_SURFACE_1D:
465 assert(width <= 16384 && height == 1 && depth <= 2048);
466 break;
467 case BRW_SURFACE_2D:
468 assert(width <= 16384 && height <= 16384 && depth <= 2048);
469 break;
470 case BRW_SURFACE_3D:
471 assert(width <= 2048 && height <= 2048 && depth <= 2048);
472 if (!is_rt)
473 assert(first_layer == 0);
474 break;
475 case BRW_SURFACE_CUBE:
476 assert(width <= 16384 && height <= 16384 && depth <= 86);
477 assert(width == height);
478 if (is_rt)
479 assert(first_layer == 0);
480 break;
481 default:
482 assert(!"unexpected surface type");
483 break;
484 }
485
486 if (is_rt) {
487 /*
488 * Compute the offset to the layer manually.
489 *
490 * For rendering, the hardware requires LOD to be the same for all
491 * render targets and the depth buffer. We need to compute the offset
492 * to the layer manually and always set LOD to 0.
493 */
494 if (true) {
495 /* we lose the capability for layered rendering */
496 assert(num_layers == 1);
497
498 layer_offset = ilo_texture_get_slice_offset(tex,
499 first_level, first_layer, &x_offset, &y_offset);
500
501 assert(x_offset % 4 == 0);
502 assert(y_offset % 2 == 0);
503 x_offset /= 4;
504 y_offset /= 2;
505
506 /* derive the size for the LOD */
507 width = u_minify(width, first_level);
508 height = u_minify(height, first_level);
509 if (surface_type == BRW_SURFACE_3D)
510 depth = u_minify(depth, first_level);
511 else
512 depth = 1;
513
514 first_level = 0;
515 first_layer = 0;
516 lod = 0;
517 }
518 else {
519 layer_offset = 0;
520 x_offset = 0;
521 y_offset = 0;
522 }
523
524 assert(num_levels == 1);
525 lod = first_level;
526 }
527 else {
528 layer_offset = 0;
529 x_offset = 0;
530 y_offset = 0;
531
532 lod = num_levels - 1;
533 }
534
535 /*
536 * From the Ivy Bridge PRM, volume 4 part 1, page 68:
537 *
538 * "The Base Address for linear render target surfaces and surfaces
539 * accessed with the typed surface read/write data port messages must
540 * be element-size aligned, for non-YUV surface formats, or a multiple
541 * of 2 element-sizes for YUV surface formats. Other linear surfaces
542 * have no alignment requirements (byte alignment is sufficient)."
543 *
544 * From the Ivy Bridge PRM, volume 4 part 1, page 70:
545 *
546 * "For linear render target surfaces and surfaces accessed with the
547 * typed data port messages, the pitch must be a multiple of the
548 * element size for non-YUV surface formats. Pitch must be a multiple
549 * of 2 * element size for YUV surface formats. For linear surfaces
550 * with Surface Type of SURFTYPE_STRBUF, the pitch must be a multiple
551 * of 4 bytes.For other linear surfaces, the pitch can be any multiple
552 * of bytes."
553 *
554 * From the Ivy Bridge PRM, volume 4 part 1, page 74:
555 *
556 * "For linear surfaces, this field (X Offset) must be zero."
557 */
558 if (tex->tiling == INTEL_TILING_NONE) {
559 if (is_rt) {
560 const int elem_size = util_format_get_blocksize(format);
561 assert(layer_offset % elem_size == 0);
562 assert(pitch % elem_size == 0);
563 }
564
565 assert(!x_offset);
566 }
567
568 STATIC_ASSERT(Elements(surf->payload) >= 8);
569 dw = surf->payload;
570
571 dw[0] = surface_type << BRW_SURFACE_TYPE_SHIFT |
572 surface_format << BRW_SURFACE_FORMAT_SHIFT |
573 ilo_gpe_gen6_translate_winsys_tiling(tex->tiling) << 13;
574
575 /*
576 * From the Ivy Bridge PRM, volume 4 part 1, page 63:
577 *
578 * "If this field (Surface Array) is enabled, the Surface Type must be
579 * SURFTYPE_1D, SURFTYPE_2D, or SURFTYPE_CUBE. If this field is
580 * disabled and Surface Type is SURFTYPE_1D, SURFTYPE_2D, or
581 * SURFTYPE_CUBE, the Depth field must be set to zero."
582 *
583 * For non-3D sampler surfaces, resinfo (the sampler message) always
584 * returns zero for the number of layers when this field is not set.
585 */
586 if (surface_type != BRW_SURFACE_3D) {
587 if (util_resource_is_array_texture(&tex->base))
588 dw[0] |= GEN7_SURFACE_IS_ARRAY;
589 else
590 assert(depth == 1);
591 }
592
593 if (tex->valign_4)
594 dw[0] |= GEN7_SURFACE_VALIGN_4;
595
596 if (tex->halign_8)
597 dw[0] |= GEN7_SURFACE_HALIGN_8;
598
599 if (tex->array_spacing_full)
600 dw[0] |= GEN7_SURFACE_ARYSPC_FULL;
601 else
602 dw[0] |= GEN7_SURFACE_ARYSPC_LOD0;
603
604 if (render_cache_rw)
605 dw[0] |= BRW_SURFACE_RC_READ_WRITE;
606
607 if (surface_type == BRW_SURFACE_CUBE && !is_rt)
608 dw[0] |= BRW_SURFACE_CUBEFACE_ENABLES;
609
610 dw[1] = layer_offset;
611
612 dw[2] = SET_FIELD(height - 1, GEN7_SURFACE_HEIGHT) |
613 SET_FIELD(width - 1, GEN7_SURFACE_WIDTH);
614
615 dw[3] = SET_FIELD(depth - 1, BRW_SURFACE_DEPTH) |
616 (pitch - 1);
617
618 dw[4] = first_layer << 18 |
619 (num_layers - 1) << 7;
620
621 /*
622 * MSFMT_MSS means the samples are not interleaved and MSFMT_DEPTH_STENCIL
623 * means the samples are interleaved. The layouts are the same when the
624 * number of samples is 1.
625 */
626 if (tex->interleaved && tex->base.nr_samples > 1) {
627 assert(!is_rt);
628 dw[4] |= GEN7_SURFACE_MSFMT_DEPTH_STENCIL;
629 }
630 else {
631 dw[4] |= GEN7_SURFACE_MSFMT_MSS;
632 }
633
634 if (tex->base.nr_samples > 4)
635 dw[4] |= GEN7_SURFACE_MULTISAMPLECOUNT_8;
636 else if (tex->base.nr_samples > 2)
637 dw[4] |= GEN7_SURFACE_MULTISAMPLECOUNT_4;
638 else
639 dw[4] |= GEN7_SURFACE_MULTISAMPLECOUNT_1;
640
641 dw[5] = x_offset << BRW_SURFACE_X_OFFSET_SHIFT |
642 y_offset << BRW_SURFACE_Y_OFFSET_SHIFT |
643 SET_FIELD(first_level, GEN7_SURFACE_MIN_LOD) |
644 lod;
645
646 dw[6] = 0;
647 dw[7] = 0;
648
649 /* do not increment reference count */
650 surf->bo = tex->bo;
651 }
652
653 int
654 ilo_gpe_gen7_estimate_command_size(const struct ilo_dev_info *dev,
655 enum ilo_gpe_gen7_command cmd,
656 int arg)
657 {
658 static const struct {
659 int header;
660 int body;
661 } gen7_command_size_table[ILO_GPE_GEN7_COMMAND_COUNT] = {
662 [ILO_GPE_GEN7_STATE_BASE_ADDRESS] = { 0, 10 },
663 [ILO_GPE_GEN7_STATE_SIP] = { 0, 2 },
664 [ILO_GPE_GEN7_3DSTATE_VF_STATISTICS] = { 0, 1 },
665 [ILO_GPE_GEN7_PIPELINE_SELECT] = { 0, 1 },
666 [ILO_GPE_GEN7_MEDIA_VFE_STATE] = { 0, 8 },
667 [ILO_GPE_GEN7_MEDIA_CURBE_LOAD] = { 0, 4 },
668 [ILO_GPE_GEN7_MEDIA_INTERFACE_DESCRIPTOR_LOAD] = { 0, 4 },
669 [ILO_GPE_GEN7_MEDIA_STATE_FLUSH] = { 0, 2 },
670 [ILO_GPE_GEN7_GPGPU_WALKER] = { 0, 11 },
671 [ILO_GPE_GEN7_3DSTATE_CLEAR_PARAMS] = { 0, 3 },
672 [ILO_GPE_GEN7_3DSTATE_DEPTH_BUFFER] = { 0, 7 },
673 [ILO_GPE_GEN7_3DSTATE_STENCIL_BUFFER] = { 0, 3 },
674 [ILO_GPE_GEN7_3DSTATE_HIER_DEPTH_BUFFER] = { 0, 3 },
675 [ILO_GPE_GEN7_3DSTATE_VERTEX_BUFFERS] = { 1, 4 },
676 [ILO_GPE_GEN7_3DSTATE_VERTEX_ELEMENTS] = { 1, 2 },
677 [ILO_GPE_GEN7_3DSTATE_INDEX_BUFFER] = { 0, 3 },
678 [ILO_GPE_GEN7_3DSTATE_CC_STATE_POINTERS] = { 0, 2 },
679 [ILO_GPE_GEN7_3DSTATE_SCISSOR_STATE_POINTERS] = { 0, 2 },
680 [ILO_GPE_GEN7_3DSTATE_VS] = { 0, 6 },
681 [ILO_GPE_GEN7_3DSTATE_GS] = { 0, 7 },
682 [ILO_GPE_GEN7_3DSTATE_CLIP] = { 0, 4 },
683 [ILO_GPE_GEN7_3DSTATE_SF] = { 0, 7 },
684 [ILO_GPE_GEN7_3DSTATE_WM] = { 0, 3 },
685 [ILO_GPE_GEN7_3DSTATE_CONSTANT_VS] = { 0, 7 },
686 [ILO_GPE_GEN7_3DSTATE_CONSTANT_GS] = { 0, 7 },
687 [ILO_GPE_GEN7_3DSTATE_CONSTANT_PS] = { 0, 7 },
688 [ILO_GPE_GEN7_3DSTATE_SAMPLE_MASK] = { 0, 2 },
689 [ILO_GPE_GEN7_3DSTATE_CONSTANT_HS] = { 0, 7 },
690 [ILO_GPE_GEN7_3DSTATE_CONSTANT_DS] = { 0, 7 },
691 [ILO_GPE_GEN7_3DSTATE_HS] = { 0, 7 },
692 [ILO_GPE_GEN7_3DSTATE_TE] = { 0, 4 },
693 [ILO_GPE_GEN7_3DSTATE_DS] = { 0, 6 },
694 [ILO_GPE_GEN7_3DSTATE_STREAMOUT] = { 0, 3 },
695 [ILO_GPE_GEN7_3DSTATE_SBE] = { 0, 14 },
696 [ILO_GPE_GEN7_3DSTATE_PS] = { 0, 8 },
697 [ILO_GPE_GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP] = { 0, 2 },
698 [ILO_GPE_GEN7_3DSTATE_VIEWPORT_STATE_POINTERS_CC] = { 0, 2 },
699 [ILO_GPE_GEN7_3DSTATE_BLEND_STATE_POINTERS] = { 0, 2 },
700 [ILO_GPE_GEN7_3DSTATE_DEPTH_STENCIL_STATE_POINTERS] = { 0, 2 },
701 [ILO_GPE_GEN7_3DSTATE_BINDING_TABLE_POINTERS_VS] = { 0, 2 },
702 [ILO_GPE_GEN7_3DSTATE_BINDING_TABLE_POINTERS_HS] = { 0, 2 },
703 [ILO_GPE_GEN7_3DSTATE_BINDING_TABLE_POINTERS_DS] = { 0, 2 },
704 [ILO_GPE_GEN7_3DSTATE_BINDING_TABLE_POINTERS_GS] = { 0, 2 },
705 [ILO_GPE_GEN7_3DSTATE_BINDING_TABLE_POINTERS_PS] = { 0, 2 },
706 [ILO_GPE_GEN7_3DSTATE_SAMPLER_STATE_POINTERS_VS] = { 0, 2 },
707 [ILO_GPE_GEN7_3DSTATE_SAMPLER_STATE_POINTERS_HS] = { 0, 2 },
708 [ILO_GPE_GEN7_3DSTATE_SAMPLER_STATE_POINTERS_DS] = { 0, 2 },
709 [ILO_GPE_GEN7_3DSTATE_SAMPLER_STATE_POINTERS_GS] = { 0, 2 },
710 [ILO_GPE_GEN7_3DSTATE_SAMPLER_STATE_POINTERS_PS] = { 0, 2 },
711 [ILO_GPE_GEN7_3DSTATE_URB_VS] = { 0, 2 },
712 [ILO_GPE_GEN7_3DSTATE_URB_HS] = { 0, 2 },
713 [ILO_GPE_GEN7_3DSTATE_URB_DS] = { 0, 2 },
714 [ILO_GPE_GEN7_3DSTATE_URB_GS] = { 0, 2 },
715 [ILO_GPE_GEN7_3DSTATE_DRAWING_RECTANGLE] = { 0, 4 },
716 [ILO_GPE_GEN7_3DSTATE_POLY_STIPPLE_OFFSET] = { 0, 2 },
717 [ILO_GPE_GEN7_3DSTATE_POLY_STIPPLE_PATTERN] = { 0, 33, },
718 [ILO_GPE_GEN7_3DSTATE_LINE_STIPPLE] = { 0, 3 },
719 [ILO_GPE_GEN7_3DSTATE_AA_LINE_PARAMETERS] = { 0, 3 },
720 [ILO_GPE_GEN7_3DSTATE_MULTISAMPLE] = { 0, 4 },
721 [ILO_GPE_GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_VS] = { 0, 2 },
722 [ILO_GPE_GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_HS] = { 0, 2 },
723 [ILO_GPE_GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_DS] = { 0, 2 },
724 [ILO_GPE_GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_GS] = { 0, 2 },
725 [ILO_GPE_GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS] = { 0, 2 },
726 [ILO_GPE_GEN7_3DSTATE_SO_DECL_LIST] = { 3, 2 },
727 [ILO_GPE_GEN7_3DSTATE_SO_BUFFER] = { 0, 4 },
728 [ILO_GPE_GEN7_PIPE_CONTROL] = { 0, 5 },
729 [ILO_GPE_GEN7_3DPRIMITIVE] = { 0, 7 },
730 };
731 const int header = gen7_command_size_table[cmd].header;
732 const int body = gen7_command_size_table[cmd].body;
733 const int count = arg;
734
735 ILO_GPE_VALID_GEN(dev, 7, 7);
736 assert(cmd < ILO_GPE_GEN7_COMMAND_COUNT);
737
738 return (likely(count)) ? header + body * count : 0;
739 }
740
741 int
742 ilo_gpe_gen7_estimate_state_size(const struct ilo_dev_info *dev,
743 enum ilo_gpe_gen7_state state,
744 int arg)
745 {
746 static const struct {
747 int alignment;
748 int body;
749 bool is_array;
750 } gen7_state_size_table[ILO_GPE_GEN7_STATE_COUNT] = {
751 [ILO_GPE_GEN7_INTERFACE_DESCRIPTOR_DATA] = { 8, 8, true },
752 [ILO_GPE_GEN7_SF_CLIP_VIEWPORT] = { 16, 16, true },
753 [ILO_GPE_GEN7_CC_VIEWPORT] = { 8, 2, true },
754 [ILO_GPE_GEN7_COLOR_CALC_STATE] = { 16, 6, false },
755 [ILO_GPE_GEN7_BLEND_STATE] = { 16, 2, true },
756 [ILO_GPE_GEN7_DEPTH_STENCIL_STATE] = { 16, 3, false },
757 [ILO_GPE_GEN7_SCISSOR_RECT] = { 8, 2, true },
758 [ILO_GPE_GEN7_BINDING_TABLE_STATE] = { 8, 1, true },
759 [ILO_GPE_GEN7_SURFACE_STATE] = { 8, 8, false },
760 [ILO_GPE_GEN7_SAMPLER_STATE] = { 8, 4, true },
761 [ILO_GPE_GEN7_SAMPLER_BORDER_COLOR_STATE] = { 8, 4, false },
762 [ILO_GPE_GEN7_PUSH_CONSTANT_BUFFER] = { 8, 1, true },
763 };
764 const int alignment = gen7_state_size_table[state].alignment;
765 const int body = gen7_state_size_table[state].body;
766 const bool is_array = gen7_state_size_table[state].is_array;
767 const int count = arg;
768 int estimate;
769
770 ILO_GPE_VALID_GEN(dev, 7, 7);
771 assert(state < ILO_GPE_GEN7_STATE_COUNT);
772
773 if (likely(count)) {
774 if (is_array) {
775 estimate = (alignment - 1) + body * count;
776 }
777 else {
778 estimate = (alignment - 1) + body;
779 /* all states are aligned */
780 if (count > 1)
781 estimate += util_align_npot(body, alignment) * (count - 1);
782 }
783 }
784 else {
785 estimate = 0;
786 }
787
788 return estimate;
789 }