ilo: improve readability of ilo_image
[mesa.git] / src / gallium / drivers / ilo / core / ilo_state_3d_top.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2014 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 "genhw/genhw.h"
29 #include "util/u_dual_blend.h"
30 #include "util/u_framebuffer.h"
31 #include "util/u_half.h"
32 #include "util/u_resource.h"
33
34 #include "ilo_format.h"
35 #include "ilo_state_3d.h"
36 #include "../ilo_resource.h"
37 #include "../ilo_shader.h"
38
39 static void
40 ve_init_cso(const struct ilo_dev *dev,
41 const struct pipe_vertex_element *state,
42 unsigned vb_index,
43 struct ilo_ve_cso *cso)
44 {
45 int comp[4] = {
46 GEN6_VFCOMP_STORE_SRC,
47 GEN6_VFCOMP_STORE_SRC,
48 GEN6_VFCOMP_STORE_SRC,
49 GEN6_VFCOMP_STORE_SRC,
50 };
51 int format;
52
53 ILO_DEV_ASSERT(dev, 6, 8);
54
55 switch (util_format_get_nr_components(state->src_format)) {
56 case 1: comp[1] = GEN6_VFCOMP_STORE_0;
57 case 2: comp[2] = GEN6_VFCOMP_STORE_0;
58 case 3: comp[3] = (util_format_is_pure_integer(state->src_format)) ?
59 GEN6_VFCOMP_STORE_1_INT :
60 GEN6_VFCOMP_STORE_1_FP;
61 }
62
63 format = ilo_format_translate_vertex(dev, state->src_format);
64
65 STATIC_ASSERT(Elements(cso->payload) >= 2);
66 cso->payload[0] =
67 vb_index << GEN6_VE_DW0_VB_INDEX__SHIFT |
68 GEN6_VE_DW0_VALID |
69 format << GEN6_VE_DW0_FORMAT__SHIFT |
70 state->src_offset << GEN6_VE_DW0_VB_OFFSET__SHIFT;
71
72 cso->payload[1] =
73 comp[0] << GEN6_VE_DW1_COMP0__SHIFT |
74 comp[1] << GEN6_VE_DW1_COMP1__SHIFT |
75 comp[2] << GEN6_VE_DW1_COMP2__SHIFT |
76 comp[3] << GEN6_VE_DW1_COMP3__SHIFT;
77 }
78
79 void
80 ilo_gpe_init_ve(const struct ilo_dev *dev,
81 unsigned num_states,
82 const struct pipe_vertex_element *states,
83 struct ilo_ve_state *ve)
84 {
85 unsigned i;
86
87 ILO_DEV_ASSERT(dev, 6, 8);
88
89 ve->count = num_states;
90 ve->vb_count = 0;
91
92 for (i = 0; i < num_states; i++) {
93 const unsigned pipe_idx = states[i].vertex_buffer_index;
94 const unsigned instance_divisor = states[i].instance_divisor;
95 unsigned hw_idx;
96
97 /*
98 * map the pipe vb to the hardware vb, which has a fixed instance
99 * divisor
100 */
101 for (hw_idx = 0; hw_idx < ve->vb_count; hw_idx++) {
102 if (ve->vb_mapping[hw_idx] == pipe_idx &&
103 ve->instance_divisors[hw_idx] == instance_divisor)
104 break;
105 }
106
107 /* create one if there is no matching hardware vb */
108 if (hw_idx >= ve->vb_count) {
109 hw_idx = ve->vb_count++;
110
111 ve->vb_mapping[hw_idx] = pipe_idx;
112 ve->instance_divisors[hw_idx] = instance_divisor;
113 }
114
115 ve_init_cso(dev, &states[i], hw_idx, &ve->cso[i]);
116 }
117 }
118
119 void
120 ilo_gpe_set_ve_edgeflag(const struct ilo_dev *dev,
121 struct ilo_ve_cso *cso)
122 {
123 int format;
124
125 ILO_DEV_ASSERT(dev, 6, 8);
126
127 /*
128 * From the Sandy Bridge PRM, volume 2 part 1, page 94:
129 *
130 * "- This bit (Edge Flag Enable) must only be ENABLED on the last
131 * valid VERTEX_ELEMENT structure.
132 *
133 * - When set, Component 0 Control must be set to VFCOMP_STORE_SRC,
134 * and Component 1-3 Control must be set to VFCOMP_NOSTORE.
135 *
136 * - The Source Element Format must be set to the UINT format.
137 *
138 * - [DevSNB]: Edge Flags are not supported for QUADLIST
139 * primitives. Software may elect to convert QUADLIST primitives
140 * to some set of corresponding edge-flag-supported primitive
141 * types (e.g., POLYGONs) prior to submission to the 3D pipeline."
142 */
143 cso->payload[0] |= GEN6_VE_DW0_EDGE_FLAG_ENABLE;
144
145 /*
146 * Edge flags have format GEN6_FORMAT_R8_USCALED when defined via
147 * glEdgeFlagPointer(), and format GEN6_FORMAT_R32_FLOAT when defined
148 * via glEdgeFlag(), as can be seen in vbo_attrib_tmp.h.
149 *
150 * Since all the hardware cares about is whether the flags are zero or not,
151 * we can treat them as the corresponding _UINT formats.
152 */
153 format = GEN_EXTRACT(cso->payload[0], GEN6_VE_DW0_FORMAT);
154 cso->payload[0] &= ~GEN6_VE_DW0_FORMAT__MASK;
155
156 switch (format) {
157 case GEN6_FORMAT_R32_FLOAT:
158 format = GEN6_FORMAT_R32_UINT;
159 break;
160 case GEN6_FORMAT_R8_USCALED:
161 format = GEN6_FORMAT_R8_UINT;
162 break;
163 default:
164 break;
165 }
166
167 cso->payload[0] |= GEN_SHIFT32(format, GEN6_VE_DW0_FORMAT);
168
169 cso->payload[1] =
170 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
171 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
172 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
173 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
174 }
175
176 void
177 ilo_gpe_init_ve_nosrc(const struct ilo_dev *dev,
178 int comp0, int comp1, int comp2, int comp3,
179 struct ilo_ve_cso *cso)
180 {
181 ILO_DEV_ASSERT(dev, 6, 8);
182
183 STATIC_ASSERT(Elements(cso->payload) >= 2);
184
185 assert(comp0 != GEN6_VFCOMP_STORE_SRC &&
186 comp1 != GEN6_VFCOMP_STORE_SRC &&
187 comp2 != GEN6_VFCOMP_STORE_SRC &&
188 comp3 != GEN6_VFCOMP_STORE_SRC);
189
190 cso->payload[0] = GEN6_VE_DW0_VALID;
191 cso->payload[1] =
192 comp0 << GEN6_VE_DW1_COMP0__SHIFT |
193 comp1 << GEN6_VE_DW1_COMP1__SHIFT |
194 comp2 << GEN6_VE_DW1_COMP2__SHIFT |
195 comp3 << GEN6_VE_DW1_COMP3__SHIFT;
196 }
197
198 void
199 ilo_gpe_init_vs_cso(const struct ilo_dev *dev,
200 const struct ilo_shader_state *vs,
201 struct ilo_shader_cso *cso)
202 {
203 int start_grf, vue_read_len, sampler_count, max_threads;
204 uint32_t dw2, dw4, dw5;
205
206 ILO_DEV_ASSERT(dev, 6, 8);
207
208 start_grf = ilo_shader_get_kernel_param(vs, ILO_KERNEL_URB_DATA_START_REG);
209 vue_read_len = ilo_shader_get_kernel_param(vs, ILO_KERNEL_INPUT_COUNT);
210 sampler_count = ilo_shader_get_kernel_param(vs, ILO_KERNEL_SAMPLER_COUNT);
211
212 /*
213 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
214 *
215 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
216 * 128-bit vertex elements to be passed into the payload for each
217 * vertex."
218 *
219 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
220 * data to be read and passed to the thread."
221 */
222 vue_read_len = (vue_read_len + 1) / 2;
223 if (!vue_read_len)
224 vue_read_len = 1;
225
226 max_threads = dev->thread_count;
227 if (ilo_dev_gen(dev) == ILO_GEN(7.5) && dev->gt == 2)
228 max_threads *= 2;
229
230 dw2 = (true) ? 0 : GEN6_THREADDISP_FP_MODE_ALT;
231 dw2 |= ((sampler_count + 3) / 4) << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT;
232
233 dw4 = start_grf << GEN6_VS_DW4_URB_GRF_START__SHIFT |
234 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
235 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
236
237 dw5 = GEN6_VS_DW5_STATISTICS |
238 GEN6_VS_DW5_VS_ENABLE;
239
240 if (ilo_dev_gen(dev) >= ILO_GEN(7.5))
241 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
242 else
243 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
244
245 STATIC_ASSERT(Elements(cso->payload) >= 3);
246 cso->payload[0] = dw2;
247 cso->payload[1] = dw4;
248 cso->payload[2] = dw5;
249 }
250
251 static void
252 gs_init_cso_gen6(const struct ilo_dev *dev,
253 const struct ilo_shader_state *gs,
254 struct ilo_shader_cso *cso)
255 {
256 int start_grf, vue_read_len, max_threads;
257 uint32_t dw2, dw4, dw5, dw6;
258
259 ILO_DEV_ASSERT(dev, 6, 6);
260
261 if (ilo_shader_get_type(gs) == PIPE_SHADER_GEOMETRY) {
262 start_grf = ilo_shader_get_kernel_param(gs,
263 ILO_KERNEL_URB_DATA_START_REG);
264
265 vue_read_len = ilo_shader_get_kernel_param(gs, ILO_KERNEL_INPUT_COUNT);
266 }
267 else {
268 start_grf = ilo_shader_get_kernel_param(gs,
269 ILO_KERNEL_VS_GEN6_SO_START_REG);
270
271 vue_read_len = ilo_shader_get_kernel_param(gs, ILO_KERNEL_OUTPUT_COUNT);
272 }
273
274 /*
275 * From the Sandy Bridge PRM, volume 2 part 1, page 153:
276 *
277 * "Specifies the amount of URB data read and passed in the thread
278 * payload for each Vertex URB entry, in 256-bit register increments.
279 *
280 * It is UNDEFINED to set this field (Vertex URB Entry Read Length) to
281 * 0 indicating no Vertex URB data to be read and passed to the
282 * thread."
283 */
284 vue_read_len = (vue_read_len + 1) / 2;
285 if (!vue_read_len)
286 vue_read_len = 1;
287
288 /*
289 * From the Sandy Bridge PRM, volume 2 part 1, page 154:
290 *
291 * "Maximum Number of Threads valid range is [0,27] when Rendering
292 * Enabled bit is set."
293 *
294 * From the Sandy Bridge PRM, volume 2 part 1, page 173:
295 *
296 * "Programming Note: If the GS stage is enabled, software must always
297 * allocate at least one GS URB Entry. This is true even if the GS
298 * thread never needs to output vertices to the pipeline, e.g., when
299 * only performing stream output. This is an artifact of the need to
300 * pass the GS thread an initial destination URB handle."
301 *
302 * As such, we always enable rendering, and limit the number of threads.
303 */
304 if (dev->gt == 2) {
305 /* maximum is 60, but limited to 28 */
306 max_threads = 28;
307 }
308 else {
309 /* maximum is 24, but limited to 21 (see brwCreateContext()) */
310 max_threads = 21;
311 }
312
313 dw2 = GEN6_THREADDISP_SPF;
314
315 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
316 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
317 start_grf << GEN6_GS_DW4_URB_GRF_START__SHIFT;
318
319 dw5 = (max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
320 GEN6_GS_DW5_STATISTICS |
321 GEN6_GS_DW5_SO_STATISTICS |
322 GEN6_GS_DW5_RENDER_ENABLE;
323
324 /*
325 * we cannot make use of GEN6_GS_REORDER because it will reorder
326 * triangle strips according to D3D rules (triangle 2N+1 uses vertices
327 * (2N+1, 2N+3, 2N+2)), instead of GL rules (triangle 2N+1 uses vertices
328 * (2N+2, 2N+1, 2N+3)).
329 */
330 dw6 = GEN6_GS_DW6_GS_ENABLE;
331
332 if (ilo_shader_get_kernel_param(gs, ILO_KERNEL_GS_DISCARD_ADJACENCY))
333 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
334
335 if (ilo_shader_get_kernel_param(gs, ILO_KERNEL_VS_GEN6_SO)) {
336 const uint32_t svbi_post_inc =
337 ilo_shader_get_kernel_param(gs, ILO_KERNEL_GS_GEN6_SVBI_POST_INC);
338
339 dw6 |= GEN6_GS_DW6_SVBI_PAYLOAD_ENABLE;
340 if (svbi_post_inc) {
341 dw6 |= GEN6_GS_DW6_SVBI_POST_INC_ENABLE |
342 svbi_post_inc << GEN6_GS_DW6_SVBI_POST_INC_VAL__SHIFT;
343 }
344 }
345
346 STATIC_ASSERT(Elements(cso->payload) >= 4);
347 cso->payload[0] = dw2;
348 cso->payload[1] = dw4;
349 cso->payload[2] = dw5;
350 cso->payload[3] = dw6;
351 }
352
353 static void
354 gs_init_cso_gen7(const struct ilo_dev *dev,
355 const struct ilo_shader_state *gs,
356 struct ilo_shader_cso *cso)
357 {
358 int start_grf, vue_read_len, sampler_count, max_threads;
359 uint32_t dw2, dw4, dw5;
360
361 ILO_DEV_ASSERT(dev, 7, 7.5);
362
363 start_grf = ilo_shader_get_kernel_param(gs, ILO_KERNEL_URB_DATA_START_REG);
364 vue_read_len = ilo_shader_get_kernel_param(gs, ILO_KERNEL_INPUT_COUNT);
365 sampler_count = ilo_shader_get_kernel_param(gs, ILO_KERNEL_SAMPLER_COUNT);
366
367 /* in pairs */
368 vue_read_len = (vue_read_len + 1) / 2;
369
370 switch (ilo_dev_gen(dev)) {
371 case ILO_GEN(7.5):
372 max_threads = (dev->gt >= 2) ? 256 : 70;
373 break;
374 case ILO_GEN(7):
375 max_threads = (dev->gt == 2) ? 128 : 36;
376 break;
377 default:
378 max_threads = 1;
379 break;
380 }
381
382 dw2 = (true) ? 0 : GEN6_THREADDISP_FP_MODE_ALT;
383 dw2 |= ((sampler_count + 3) / 4) << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT;
384
385 dw4 = vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
386 GEN7_GS_DW4_INCLUDE_VERTEX_HANDLES |
387 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
388 start_grf << GEN7_GS_DW4_URB_GRF_START__SHIFT;
389
390 dw5 = (max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT |
391 GEN7_GS_DW5_STATISTICS |
392 GEN7_GS_DW5_GS_ENABLE;
393
394 STATIC_ASSERT(Elements(cso->payload) >= 3);
395 cso->payload[0] = dw2;
396 cso->payload[1] = dw4;
397 cso->payload[2] = dw5;
398 }
399
400 void
401 ilo_gpe_init_gs_cso(const struct ilo_dev *dev,
402 const struct ilo_shader_state *gs,
403 struct ilo_shader_cso *cso)
404 {
405 if (ilo_dev_gen(dev) >= ILO_GEN(7))
406 gs_init_cso_gen7(dev, gs, cso);
407 else
408 gs_init_cso_gen6(dev, gs, cso);
409 }
410
411 static void
412 view_init_null_gen6(const struct ilo_dev *dev,
413 unsigned width, unsigned height,
414 unsigned depth, unsigned level,
415 struct ilo_view_surface *surf)
416 {
417 uint32_t *dw;
418
419 ILO_DEV_ASSERT(dev, 6, 6);
420
421 assert(width >= 1 && height >= 1 && depth >= 1);
422
423 /*
424 * From the Sandy Bridge PRM, volume 4 part 1, page 71:
425 *
426 * "A null surface will be used in instances where an actual surface is
427 * not bound. When a write message is generated to a null surface, no
428 * actual surface is written to. When a read message (including any
429 * sampling engine message) is generated to a null surface, the result
430 * is all zeros. Note that a null surface type is allowed to be used
431 * with all messages, even if it is not specificially indicated as
432 * supported. All of the remaining fields in surface state are ignored
433 * for null surfaces, with the following exceptions:
434 *
435 * * [DevSNB+]: Width, Height, Depth, and LOD fields must match the
436 * depth buffer's corresponding state for all render target
437 * surfaces, including null.
438 * * Surface Format must be R8G8B8A8_UNORM."
439 *
440 * From the Sandy Bridge PRM, volume 4 part 1, page 82:
441 *
442 * "If Surface Type is SURFTYPE_NULL, this field (Tiled Surface) must be
443 * true"
444 */
445
446 STATIC_ASSERT(Elements(surf->payload) >= 6);
447 dw = surf->payload;
448
449 dw[0] = GEN6_SURFTYPE_NULL << GEN6_SURFACE_DW0_TYPE__SHIFT |
450 GEN6_FORMAT_B8G8R8A8_UNORM << GEN6_SURFACE_DW0_FORMAT__SHIFT;
451
452 dw[1] = 0;
453
454 dw[2] = (height - 1) << GEN6_SURFACE_DW2_HEIGHT__SHIFT |
455 (width - 1) << GEN6_SURFACE_DW2_WIDTH__SHIFT |
456 level << GEN6_SURFACE_DW2_MIP_COUNT_LOD__SHIFT;
457
458 dw[3] = (depth - 1) << GEN6_SURFACE_DW3_DEPTH__SHIFT |
459 GEN6_TILING_X;
460
461 dw[4] = 0;
462 dw[5] = 0;
463 }
464
465 static void
466 view_init_for_buffer_gen6(const struct ilo_dev *dev,
467 const struct ilo_buffer *buf,
468 unsigned offset, unsigned size,
469 unsigned struct_size,
470 enum pipe_format elem_format,
471 bool is_rt, bool render_cache_rw,
472 struct ilo_view_surface *surf)
473 {
474 const int elem_size = util_format_get_blocksize(elem_format);
475 int width, height, depth, pitch;
476 int surface_format, num_entries;
477 uint32_t *dw;
478
479 ILO_DEV_ASSERT(dev, 6, 6);
480
481 /*
482 * For SURFTYPE_BUFFER, a SURFACE_STATE specifies an element of a
483 * structure in a buffer.
484 */
485
486 surface_format = ilo_format_translate_color(dev, elem_format);
487
488 num_entries = size / struct_size;
489 /* see if there is enough space to fit another element */
490 if (size % struct_size >= elem_size)
491 num_entries++;
492
493 /*
494 * From the Sandy Bridge PRM, volume 4 part 1, page 76:
495 *
496 * "For SURFTYPE_BUFFER render targets, this field (Surface Base
497 * Address) specifies the base address of first element of the
498 * surface. The surface is interpreted as a simple array of that
499 * single element type. The address must be naturally-aligned to the
500 * element size (e.g., a buffer containing R32G32B32A32_FLOAT elements
501 * must be 16-byte aligned).
502 *
503 * For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
504 * the base address of the first element of the surface, computed in
505 * software by adding the surface base address to the byte offset of
506 * the element in the buffer."
507 */
508 if (is_rt)
509 assert(offset % elem_size == 0);
510
511 /*
512 * From the Sandy Bridge PRM, volume 4 part 1, page 77:
513 *
514 * "For buffer surfaces, the number of entries in the buffer ranges
515 * from 1 to 2^27."
516 */
517 assert(num_entries >= 1 && num_entries <= 1 << 27);
518
519 /*
520 * From the Sandy Bridge PRM, volume 4 part 1, page 81:
521 *
522 * "For surfaces of type SURFTYPE_BUFFER, this field (Surface Pitch)
523 * indicates the size of the structure."
524 */
525 pitch = struct_size;
526
527 pitch--;
528 num_entries--;
529 /* bits [6:0] */
530 width = (num_entries & 0x0000007f);
531 /* bits [19:7] */
532 height = (num_entries & 0x000fff80) >> 7;
533 /* bits [26:20] */
534 depth = (num_entries & 0x07f00000) >> 20;
535
536 STATIC_ASSERT(Elements(surf->payload) >= 6);
537 dw = surf->payload;
538
539 dw[0] = GEN6_SURFTYPE_BUFFER << GEN6_SURFACE_DW0_TYPE__SHIFT |
540 surface_format << GEN6_SURFACE_DW0_FORMAT__SHIFT;
541 if (render_cache_rw)
542 dw[0] |= GEN6_SURFACE_DW0_RENDER_CACHE_RW;
543
544 dw[1] = offset;
545
546 dw[2] = height << GEN6_SURFACE_DW2_HEIGHT__SHIFT |
547 width << GEN6_SURFACE_DW2_WIDTH__SHIFT;
548
549 dw[3] = depth << GEN6_SURFACE_DW3_DEPTH__SHIFT |
550 pitch << GEN6_SURFACE_DW3_PITCH__SHIFT;
551
552 dw[4] = 0;
553 dw[5] = 0;
554 }
555
556 static void
557 view_init_for_texture_gen6(const struct ilo_dev *dev,
558 const struct ilo_texture *tex,
559 enum pipe_format format,
560 unsigned first_level,
561 unsigned num_levels,
562 unsigned first_layer,
563 unsigned num_layers,
564 bool is_rt,
565 struct ilo_view_surface *surf)
566 {
567 int surface_type, surface_format;
568 int width, height, depth, pitch, lod;
569 uint32_t *dw;
570
571 ILO_DEV_ASSERT(dev, 6, 6);
572
573 surface_type = ilo_gpe_gen6_translate_texture(tex->base.target);
574 assert(surface_type != GEN6_SURFTYPE_BUFFER);
575
576 if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT && tex->separate_s8)
577 format = PIPE_FORMAT_Z32_FLOAT;
578
579 if (is_rt)
580 surface_format = ilo_format_translate_render(dev, format);
581 else
582 surface_format = ilo_format_translate_texture(dev, format);
583 assert(surface_format >= 0);
584
585 width = tex->image.width0;
586 height = tex->image.height0;
587 depth = (tex->base.target == PIPE_TEXTURE_3D) ?
588 tex->base.depth0 : num_layers;
589 pitch = tex->image.bo_stride;
590
591 if (surface_type == GEN6_SURFTYPE_CUBE) {
592 /*
593 * From the Sandy Bridge PRM, volume 4 part 1, page 81:
594 *
595 * "For SURFTYPE_CUBE: [DevSNB+]: for Sampling Engine Surfaces, the
596 * range of this field (Depth) is [0,84], indicating the number of
597 * cube array elements (equal to the number of underlying 2D array
598 * elements divided by 6). For other surfaces, this field must be
599 * zero."
600 *
601 * When is_rt is true, we treat the texture as a 2D one to avoid the
602 * restriction.
603 */
604 if (is_rt) {
605 surface_type = GEN6_SURFTYPE_2D;
606 }
607 else {
608 assert(num_layers % 6 == 0);
609 depth = num_layers / 6;
610 }
611 }
612
613 /* sanity check the size */
614 assert(width >= 1 && height >= 1 && depth >= 1 && pitch >= 1);
615 switch (surface_type) {
616 case GEN6_SURFTYPE_1D:
617 assert(width <= 8192 && height == 1 && depth <= 512);
618 assert(first_layer < 512 && num_layers <= 512);
619 break;
620 case GEN6_SURFTYPE_2D:
621 assert(width <= 8192 && height <= 8192 && depth <= 512);
622 assert(first_layer < 512 && num_layers <= 512);
623 break;
624 case GEN6_SURFTYPE_3D:
625 assert(width <= 2048 && height <= 2048 && depth <= 2048);
626 assert(first_layer < 2048 && num_layers <= 512);
627 if (!is_rt)
628 assert(first_layer == 0);
629 break;
630 case GEN6_SURFTYPE_CUBE:
631 assert(width <= 8192 && height <= 8192 && depth <= 85);
632 assert(width == height);
633 assert(first_layer < 512 && num_layers <= 512);
634 if (is_rt)
635 assert(first_layer == 0);
636 break;
637 default:
638 assert(!"unexpected surface type");
639 break;
640 }
641
642 /* non-full array spacing is supported only on GEN7+ */
643 assert(tex->image.walk != ILO_IMAGE_WALK_LOD);
644 /* non-interleaved samples are supported only on GEN7+ */
645 if (tex->base.nr_samples > 1)
646 assert(tex->image.interleaved_samples);
647
648 if (is_rt) {
649 assert(num_levels == 1);
650 lod = first_level;
651 }
652 else {
653 lod = num_levels - 1;
654 }
655
656 /*
657 * From the Sandy Bridge PRM, volume 4 part 1, page 76:
658 *
659 * "Linear render target surface base addresses must be element-size
660 * aligned, for non-YUV surface formats, or a multiple of 2
661 * element-sizes for YUV surface formats. Other linear surfaces have
662 * no alignment requirements (byte alignment is sufficient.)"
663 *
664 * From the Sandy Bridge PRM, volume 4 part 1, page 81:
665 *
666 * "For linear render target surfaces, the pitch must be a multiple
667 * of the element size for non-YUV surface formats. Pitch must be a
668 * multiple of 2 * element size for YUV surface formats."
669 *
670 * From the Sandy Bridge PRM, volume 4 part 1, page 86:
671 *
672 * "For linear surfaces, this field (X Offset) must be zero"
673 */
674 if (tex->image.tiling == GEN6_TILING_NONE) {
675 if (is_rt) {
676 const int elem_size = util_format_get_blocksize(format);
677 assert(pitch % elem_size == 0);
678 }
679 }
680
681 STATIC_ASSERT(Elements(surf->payload) >= 6);
682 dw = surf->payload;
683
684 dw[0] = surface_type << GEN6_SURFACE_DW0_TYPE__SHIFT |
685 surface_format << GEN6_SURFACE_DW0_FORMAT__SHIFT |
686 GEN6_SURFACE_DW0_MIPLAYOUT_BELOW;
687
688 if (surface_type == GEN6_SURFTYPE_CUBE && !is_rt) {
689 dw[0] |= 1 << 9 |
690 GEN6_SURFACE_DW0_CUBE_FACE_ENABLES__MASK;
691 }
692
693 if (is_rt)
694 dw[0] |= GEN6_SURFACE_DW0_RENDER_CACHE_RW;
695
696 dw[1] = 0;
697
698 dw[2] = (height - 1) << GEN6_SURFACE_DW2_HEIGHT__SHIFT |
699 (width - 1) << GEN6_SURFACE_DW2_WIDTH__SHIFT |
700 lod << GEN6_SURFACE_DW2_MIP_COUNT_LOD__SHIFT;
701
702 assert(tex->image.tiling != GEN8_TILING_W);
703 dw[3] = (depth - 1) << GEN6_SURFACE_DW3_DEPTH__SHIFT |
704 (pitch - 1) << GEN6_SURFACE_DW3_PITCH__SHIFT |
705 tex->image.tiling;
706
707 dw[4] = first_level << GEN6_SURFACE_DW4_MIN_LOD__SHIFT |
708 first_layer << 17 |
709 (num_layers - 1) << 8 |
710 ((tex->base.nr_samples > 1) ? GEN6_SURFACE_DW4_MULTISAMPLECOUNT_4 :
711 GEN6_SURFACE_DW4_MULTISAMPLECOUNT_1);
712
713 dw[5] = 0;
714
715 assert(tex->image.align_j == 2 || tex->image.align_j == 4);
716 if (tex->image.align_j == 4)
717 dw[5] |= GEN6_SURFACE_DW5_VALIGN_4;
718 }
719
720 static void
721 view_init_null_gen7(const struct ilo_dev *dev,
722 unsigned width, unsigned height,
723 unsigned depth, unsigned level,
724 struct ilo_view_surface *surf)
725 {
726 uint32_t *dw;
727
728 ILO_DEV_ASSERT(dev, 7, 8);
729
730 assert(width >= 1 && height >= 1 && depth >= 1);
731
732 /*
733 * From the Ivy Bridge PRM, volume 4 part 1, page 62:
734 *
735 * "A null surface is used in instances where an actual surface is not
736 * bound. When a write message is generated to a null surface, no
737 * actual surface is written to. When a read message (including any
738 * sampling engine message) is generated to a null surface, the result
739 * is all zeros. Note that a null surface type is allowed to be used
740 * with all messages, even if it is not specificially indicated as
741 * supported. All of the remaining fields in surface state are ignored
742 * for null surfaces, with the following exceptions:
743 *
744 * * Width, Height, Depth, LOD, and Render Target View Extent fields
745 * must match the depth buffer's corresponding state for all render
746 * target surfaces, including null.
747 * * All sampling engine and data port messages support null surfaces
748 * with the above behavior, even if not mentioned as specifically
749 * supported, except for the following:
750 * * Data Port Media Block Read/Write messages.
751 * * The Surface Type of a surface used as a render target (accessed
752 * via the Data Port's Render Target Write message) must be the same
753 * as the Surface Type of all other render targets and of the depth
754 * buffer (defined in 3DSTATE_DEPTH_BUFFER), unless either the depth
755 * buffer or render targets are SURFTYPE_NULL."
756 *
757 * From the Ivy Bridge PRM, volume 4 part 1, page 65:
758 *
759 * "If Surface Type is SURFTYPE_NULL, this field (Tiled Surface) must be
760 * true"
761 */
762
763 STATIC_ASSERT(Elements(surf->payload) >= 13);
764 dw = surf->payload;
765
766 dw[0] = GEN6_SURFTYPE_NULL << GEN7_SURFACE_DW0_TYPE__SHIFT |
767 GEN6_FORMAT_B8G8R8A8_UNORM << GEN7_SURFACE_DW0_FORMAT__SHIFT;
768
769 if (ilo_dev_gen(dev) >= ILO_GEN(8))
770 dw[0] |= GEN6_TILING_X << GEN8_SURFACE_DW0_TILING__SHIFT;
771 else
772 dw[0] |= GEN6_TILING_X << GEN7_SURFACE_DW0_TILING__SHIFT;
773
774 dw[1] = 0;
775
776 dw[2] = GEN_SHIFT32(height - 1, GEN7_SURFACE_DW2_HEIGHT) |
777 GEN_SHIFT32(width - 1, GEN7_SURFACE_DW2_WIDTH);
778
779 dw[3] = GEN_SHIFT32(depth - 1, GEN7_SURFACE_DW3_DEPTH);
780
781 dw[4] = 0;
782 dw[5] = level;
783
784 dw[6] = 0;
785 dw[7] = 0;
786
787 if (ilo_dev_gen(dev) >= ILO_GEN(8))
788 memset(&dw[8], 0, sizeof(*dw) * (13 - 8));
789 }
790
791 static void
792 view_init_for_buffer_gen7(const struct ilo_dev *dev,
793 const struct ilo_buffer *buf,
794 unsigned offset, unsigned size,
795 unsigned struct_size,
796 enum pipe_format elem_format,
797 bool is_rt, bool render_cache_rw,
798 struct ilo_view_surface *surf)
799 {
800 const bool typed = (elem_format != PIPE_FORMAT_NONE);
801 const bool structured = (!typed && struct_size > 1);
802 const int elem_size = (typed) ?
803 util_format_get_blocksize(elem_format) : 1;
804 int width, height, depth, pitch;
805 int surface_type, surface_format, num_entries;
806 uint32_t *dw;
807
808 ILO_DEV_ASSERT(dev, 7, 8);
809
810 surface_type = (structured) ? GEN7_SURFTYPE_STRBUF : GEN6_SURFTYPE_BUFFER;
811
812 surface_format = (typed) ?
813 ilo_format_translate_color(dev, elem_format) : GEN6_FORMAT_RAW;
814
815 num_entries = size / struct_size;
816 /* see if there is enough space to fit another element */
817 if (size % struct_size >= elem_size && !structured)
818 num_entries++;
819
820 /*
821 * From the Ivy Bridge PRM, volume 4 part 1, page 67:
822 *
823 * "For SURFTYPE_BUFFER render targets, this field (Surface Base
824 * Address) specifies the base address of first element of the
825 * surface. The surface is interpreted as a simple array of that
826 * single element type. The address must be naturally-aligned to the
827 * element size (e.g., a buffer containing R32G32B32A32_FLOAT elements
828 * must be 16-byte aligned)
829 *
830 * For SURFTYPE_BUFFER non-rendertarget surfaces, this field specifies
831 * the base address of the first element of the surface, computed in
832 * software by adding the surface base address to the byte offset of
833 * the element in the buffer."
834 */
835 if (is_rt)
836 assert(offset % elem_size == 0);
837
838 /*
839 * From the Ivy Bridge PRM, volume 4 part 1, page 68:
840 *
841 * "For typed buffer and structured buffer surfaces, the number of
842 * entries in the buffer ranges from 1 to 2^27. For raw buffer
843 * surfaces, the number of entries in the buffer is the number of
844 * bytes which can range from 1 to 2^30."
845 */
846 assert(num_entries >= 1 &&
847 num_entries <= 1 << ((typed || structured) ? 27 : 30));
848
849 /*
850 * From the Ivy Bridge PRM, volume 4 part 1, page 69:
851 *
852 * "For SURFTYPE_BUFFER: The low two bits of this field (Width) must be
853 * 11 if the Surface Format is RAW (the size of the buffer must be a
854 * multiple of 4 bytes)."
855 *
856 * From the Ivy Bridge PRM, volume 4 part 1, page 70:
857 *
858 * "For surfaces of type SURFTYPE_BUFFER and SURFTYPE_STRBUF, this
859 * field (Surface Pitch) indicates the size of the structure."
860 *
861 * "For linear surfaces with Surface Type of SURFTYPE_STRBUF, the pitch
862 * must be a multiple of 4 bytes."
863 */
864 if (structured)
865 assert(struct_size % 4 == 0);
866 else if (!typed)
867 assert(num_entries % 4 == 0);
868
869 pitch = struct_size;
870
871 pitch--;
872 num_entries--;
873 /* bits [6:0] */
874 width = (num_entries & 0x0000007f);
875 /* bits [20:7] */
876 height = (num_entries & 0x001fff80) >> 7;
877 /* bits [30:21] */
878 depth = (num_entries & 0x7fe00000) >> 21;
879 /* limit to [26:21] */
880 if (typed || structured)
881 depth &= 0x3f;
882
883 STATIC_ASSERT(Elements(surf->payload) >= 13);
884 dw = surf->payload;
885
886 dw[0] = surface_type << GEN7_SURFACE_DW0_TYPE__SHIFT |
887 surface_format << GEN7_SURFACE_DW0_FORMAT__SHIFT;
888 if (render_cache_rw)
889 dw[0] |= GEN7_SURFACE_DW0_RENDER_CACHE_RW;
890
891 if (ilo_dev_gen(dev) >= ILO_GEN(8)) {
892 dw[8] = offset;
893 memset(&dw[9], 0, sizeof(*dw) * (13 - 9));
894 } else {
895 dw[1] = offset;
896 }
897
898 dw[2] = GEN_SHIFT32(height, GEN7_SURFACE_DW2_HEIGHT) |
899 GEN_SHIFT32(width, GEN7_SURFACE_DW2_WIDTH);
900
901 dw[3] = GEN_SHIFT32(depth, GEN7_SURFACE_DW3_DEPTH) |
902 pitch;
903
904 dw[4] = 0;
905 dw[5] = 0;
906
907 dw[6] = 0;
908 dw[7] = 0;
909
910 if (ilo_dev_gen(dev) >= ILO_GEN(7.5)) {
911 dw[7] |= GEN_SHIFT32(GEN75_SCS_RED, GEN75_SURFACE_DW7_SCS_R) |
912 GEN_SHIFT32(GEN75_SCS_GREEN, GEN75_SURFACE_DW7_SCS_G) |
913 GEN_SHIFT32(GEN75_SCS_BLUE, GEN75_SURFACE_DW7_SCS_B) |
914 GEN_SHIFT32(GEN75_SCS_ALPHA, GEN75_SURFACE_DW7_SCS_A);
915 }
916 }
917
918 static void
919 view_init_for_texture_gen7(const struct ilo_dev *dev,
920 const struct ilo_texture *tex,
921 enum pipe_format format,
922 unsigned first_level,
923 unsigned num_levels,
924 unsigned first_layer,
925 unsigned num_layers,
926 bool is_rt,
927 struct ilo_view_surface *surf)
928 {
929 int surface_type, surface_format;
930 int width, height, depth, pitch, lod;
931 uint32_t *dw;
932
933 ILO_DEV_ASSERT(dev, 7, 8);
934
935 surface_type = ilo_gpe_gen6_translate_texture(tex->base.target);
936 assert(surface_type != GEN6_SURFTYPE_BUFFER);
937
938 if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT && tex->separate_s8)
939 format = PIPE_FORMAT_Z32_FLOAT;
940
941 if (is_rt)
942 surface_format = ilo_format_translate_render(dev, format);
943 else
944 surface_format = ilo_format_translate_texture(dev, format);
945 assert(surface_format >= 0);
946
947 width = tex->image.width0;
948 height = tex->image.height0;
949 depth = (tex->base.target == PIPE_TEXTURE_3D) ?
950 tex->base.depth0 : num_layers;
951 pitch = tex->image.bo_stride;
952
953 if (surface_type == GEN6_SURFTYPE_CUBE) {
954 /*
955 * From the Ivy Bridge PRM, volume 4 part 1, page 70:
956 *
957 * "For SURFTYPE_CUBE:For Sampling Engine Surfaces, the range of
958 * this field is [0,340], indicating the number of cube array
959 * elements (equal to the number of underlying 2D array elements
960 * divided by 6). For other surfaces, this field must be zero."
961 *
962 * When is_rt is true, we treat the texture as a 2D one to avoid the
963 * restriction.
964 */
965 if (is_rt) {
966 surface_type = GEN6_SURFTYPE_2D;
967 }
968 else {
969 assert(num_layers % 6 == 0);
970 depth = num_layers / 6;
971 }
972 }
973
974 /* sanity check the size */
975 assert(width >= 1 && height >= 1 && depth >= 1 && pitch >= 1);
976 assert(first_layer < 2048 && num_layers <= 2048);
977 switch (surface_type) {
978 case GEN6_SURFTYPE_1D:
979 assert(width <= 16384 && height == 1 && depth <= 2048);
980 break;
981 case GEN6_SURFTYPE_2D:
982 assert(width <= 16384 && height <= 16384 && depth <= 2048);
983 break;
984 case GEN6_SURFTYPE_3D:
985 assert(width <= 2048 && height <= 2048 && depth <= 2048);
986 if (!is_rt)
987 assert(first_layer == 0);
988 break;
989 case GEN6_SURFTYPE_CUBE:
990 assert(width <= 16384 && height <= 16384 && depth <= 86);
991 assert(width == height);
992 if (is_rt)
993 assert(first_layer == 0);
994 break;
995 default:
996 assert(!"unexpected surface type");
997 break;
998 }
999
1000 if (is_rt) {
1001 assert(num_levels == 1);
1002 lod = first_level;
1003 }
1004 else {
1005 lod = num_levels - 1;
1006 }
1007
1008 /*
1009 * From the Ivy Bridge PRM, volume 4 part 1, page 68:
1010 *
1011 * "The Base Address for linear render target surfaces and surfaces
1012 * accessed with the typed surface read/write data port messages must
1013 * be element-size aligned, for non-YUV surface formats, or a multiple
1014 * of 2 element-sizes for YUV surface formats. Other linear surfaces
1015 * have no alignment requirements (byte alignment is sufficient)."
1016 *
1017 * From the Ivy Bridge PRM, volume 4 part 1, page 70:
1018 *
1019 * "For linear render target surfaces and surfaces accessed with the
1020 * typed data port messages, the pitch must be a multiple of the
1021 * element size for non-YUV surface formats. Pitch must be a multiple
1022 * of 2 * element size for YUV surface formats. For linear surfaces
1023 * with Surface Type of SURFTYPE_STRBUF, the pitch must be a multiple
1024 * of 4 bytes.For other linear surfaces, the pitch can be any multiple
1025 * of bytes."
1026 *
1027 * From the Ivy Bridge PRM, volume 4 part 1, page 74:
1028 *
1029 * "For linear surfaces, this field (X Offset) must be zero."
1030 */
1031 if (tex->image.tiling == GEN6_TILING_NONE) {
1032 if (is_rt) {
1033 const int elem_size = util_format_get_blocksize(format);
1034 assert(pitch % elem_size == 0);
1035 }
1036 }
1037
1038 STATIC_ASSERT(Elements(surf->payload) >= 13);
1039 dw = surf->payload;
1040
1041 dw[0] = surface_type << GEN7_SURFACE_DW0_TYPE__SHIFT |
1042 surface_format << GEN7_SURFACE_DW0_FORMAT__SHIFT;
1043
1044 /*
1045 * From the Ivy Bridge PRM, volume 4 part 1, page 63:
1046 *
1047 * "If this field (Surface Array) is enabled, the Surface Type must be
1048 * SURFTYPE_1D, SURFTYPE_2D, or SURFTYPE_CUBE. If this field is
1049 * disabled and Surface Type is SURFTYPE_1D, SURFTYPE_2D, or
1050 * SURFTYPE_CUBE, the Depth field must be set to zero."
1051 *
1052 * For non-3D sampler surfaces, resinfo (the sampler message) always
1053 * returns zero for the number of layers when this field is not set.
1054 */
1055 if (surface_type != GEN6_SURFTYPE_3D) {
1056 if (util_resource_is_array_texture(&tex->base))
1057 dw[0] |= GEN7_SURFACE_DW0_IS_ARRAY;
1058 else
1059 assert(depth == 1);
1060 }
1061
1062 if (ilo_dev_gen(dev) >= ILO_GEN(8)) {
1063 switch (tex->image.align_j) {
1064 case 4:
1065 dw[0] |= GEN7_SURFACE_DW0_VALIGN_4;
1066 break;
1067 case 8:
1068 dw[0] |= GEN8_SURFACE_DW0_VALIGN_8;
1069 break;
1070 case 16:
1071 dw[0] |= GEN8_SURFACE_DW0_VALIGN_16;
1072 break;
1073 default:
1074 assert(!"unsupported valign");
1075 break;
1076 }
1077
1078 switch (tex->image.align_i) {
1079 case 4:
1080 dw[0] |= GEN8_SURFACE_DW0_HALIGN_4;
1081 break;
1082 case 8:
1083 dw[0] |= GEN8_SURFACE_DW0_HALIGN_8;
1084 break;
1085 case 16:
1086 dw[0] |= GEN8_SURFACE_DW0_HALIGN_16;
1087 break;
1088 default:
1089 assert(!"unsupported halign");
1090 break;
1091 }
1092
1093 dw[0] |= tex->image.tiling << GEN8_SURFACE_DW0_TILING__SHIFT;
1094 } else {
1095 assert(tex->image.align_i == 4 || tex->image.align_i == 8);
1096 assert(tex->image.align_j == 2 || tex->image.align_j == 4);
1097
1098 if (tex->image.align_j == 4)
1099 dw[0] |= GEN7_SURFACE_DW0_VALIGN_4;
1100
1101 if (tex->image.align_i == 8)
1102 dw[0] |= GEN7_SURFACE_DW0_HALIGN_8;
1103
1104 assert(tex->image.tiling != GEN8_TILING_W);
1105 dw[0] |= tex->image.tiling << GEN7_SURFACE_DW0_TILING__SHIFT;
1106
1107 if (tex->image.walk == ILO_IMAGE_WALK_LOD)
1108 dw[0] |= GEN7_SURFACE_DW0_ARYSPC_LOD0;
1109 else
1110 dw[0] |= GEN7_SURFACE_DW0_ARYSPC_FULL;
1111 }
1112
1113 if (is_rt)
1114 dw[0] |= GEN7_SURFACE_DW0_RENDER_CACHE_RW;
1115
1116 if (surface_type == GEN6_SURFTYPE_CUBE && !is_rt)
1117 dw[0] |= GEN7_SURFACE_DW0_CUBE_FACE_ENABLES__MASK;
1118
1119 if (ilo_dev_gen(dev) >= ILO_GEN(8)) {
1120 assert(tex->image.walk_layer_height % 4 == 0);
1121 dw[1] = tex->image.walk_layer_height / 4;
1122 } else {
1123 dw[1] = 0;
1124 }
1125
1126 dw[2] = GEN_SHIFT32(height - 1, GEN7_SURFACE_DW2_HEIGHT) |
1127 GEN_SHIFT32(width - 1, GEN7_SURFACE_DW2_WIDTH);
1128
1129 dw[3] = GEN_SHIFT32(depth - 1, GEN7_SURFACE_DW3_DEPTH) |
1130 (pitch - 1);
1131
1132 dw[4] = first_layer << 18 |
1133 (num_layers - 1) << 7;
1134
1135 /*
1136 * MSFMT_MSS means the samples are not interleaved and MSFMT_DEPTH_STENCIL
1137 * means the samples are interleaved. The layouts are the same when the
1138 * number of samples is 1.
1139 */
1140 if (tex->image.interleaved_samples && tex->base.nr_samples > 1) {
1141 assert(!is_rt);
1142 dw[4] |= GEN7_SURFACE_DW4_MSFMT_DEPTH_STENCIL;
1143 }
1144 else {
1145 dw[4] |= GEN7_SURFACE_DW4_MSFMT_MSS;
1146 }
1147
1148 switch (tex->base.nr_samples) {
1149 case 0:
1150 case 1:
1151 default:
1152 dw[4] |= GEN7_SURFACE_DW4_MULTISAMPLECOUNT_1;
1153 break;
1154 case 2:
1155 dw[4] |= GEN8_SURFACE_DW4_MULTISAMPLECOUNT_2;
1156 break;
1157 case 4:
1158 dw[4] |= GEN7_SURFACE_DW4_MULTISAMPLECOUNT_4;
1159 break;
1160 case 8:
1161 dw[4] |= GEN7_SURFACE_DW4_MULTISAMPLECOUNT_8;
1162 break;
1163 case 16:
1164 dw[4] |= GEN8_SURFACE_DW4_MULTISAMPLECOUNT_16;
1165 break;
1166 }
1167
1168 dw[5] = GEN_SHIFT32(first_level, GEN7_SURFACE_DW5_MIN_LOD) |
1169 lod;
1170
1171 dw[6] = 0;
1172 dw[7] = 0;
1173
1174 if (ilo_dev_gen(dev) >= ILO_GEN(7.5)) {
1175 dw[7] |= GEN_SHIFT32(GEN75_SCS_RED, GEN75_SURFACE_DW7_SCS_R) |
1176 GEN_SHIFT32(GEN75_SCS_GREEN, GEN75_SURFACE_DW7_SCS_G) |
1177 GEN_SHIFT32(GEN75_SCS_BLUE, GEN75_SURFACE_DW7_SCS_B) |
1178 GEN_SHIFT32(GEN75_SCS_ALPHA, GEN75_SURFACE_DW7_SCS_A);
1179 }
1180
1181 if (ilo_dev_gen(dev) >= ILO_GEN(8))
1182 memset(&dw[8], 0, sizeof(*dw) * (13 - 8));
1183 }
1184
1185 void
1186 ilo_gpe_init_view_surface_null(const struct ilo_dev *dev,
1187 unsigned width, unsigned height,
1188 unsigned depth, unsigned level,
1189 struct ilo_view_surface *surf)
1190 {
1191 if (ilo_dev_gen(dev) >= ILO_GEN(7)) {
1192 view_init_null_gen7(dev,
1193 width, height, depth, level, surf);
1194 } else {
1195 view_init_null_gen6(dev,
1196 width, height, depth, level, surf);
1197 }
1198
1199 surf->bo = NULL;
1200 surf->scanout = false;
1201 }
1202
1203 void
1204 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev *dev,
1205 const struct ilo_buffer *buf,
1206 unsigned offset, unsigned size,
1207 unsigned struct_size,
1208 enum pipe_format elem_format,
1209 bool is_rt, bool render_cache_rw,
1210 struct ilo_view_surface *surf)
1211 {
1212 if (ilo_dev_gen(dev) >= ILO_GEN(7)) {
1213 view_init_for_buffer_gen7(dev, buf, offset, size,
1214 struct_size, elem_format, is_rt, render_cache_rw, surf);
1215 } else {
1216 view_init_for_buffer_gen6(dev, buf, offset, size,
1217 struct_size, elem_format, is_rt, render_cache_rw, surf);
1218 }
1219
1220 /* do not increment reference count */
1221 surf->bo = buf->bo;
1222 surf->scanout = false;
1223 }
1224
1225 void
1226 ilo_gpe_init_view_surface_for_texture(const struct ilo_dev *dev,
1227 const struct ilo_texture *tex,
1228 enum pipe_format format,
1229 unsigned first_level,
1230 unsigned num_levels,
1231 unsigned first_layer,
1232 unsigned num_layers,
1233 bool is_rt,
1234 struct ilo_view_surface *surf)
1235 {
1236 if (ilo_dev_gen(dev) >= ILO_GEN(7)) {
1237 view_init_for_texture_gen7(dev, tex, format,
1238 first_level, num_levels, first_layer, num_layers,
1239 is_rt, surf);
1240 } else {
1241 view_init_for_texture_gen6(dev, tex, format,
1242 first_level, num_levels, first_layer, num_layers,
1243 is_rt, surf);
1244 }
1245
1246 /* do not increment reference count */
1247 surf->bo = tex->image.bo;
1248
1249 /* assume imported RTs are scanouts */
1250 surf->scanout = ((tex->base.bind & PIPE_BIND_SCANOUT) ||
1251 (tex->imported && (tex->base.bind & PIPE_BIND_RENDER_TARGET)));
1252 }
1253
1254 static void
1255 sampler_init_border_color_gen6(const struct ilo_dev *dev,
1256 const union pipe_color_union *color,
1257 uint32_t *dw, int num_dwords)
1258 {
1259 float rgba[4] = {
1260 color->f[0], color->f[1], color->f[2], color->f[3],
1261 };
1262
1263 ILO_DEV_ASSERT(dev, 6, 6);
1264
1265 assert(num_dwords >= 12);
1266
1267 /*
1268 * This state is not documented in the Sandy Bridge PRM, but in the
1269 * Ironlake PRM. SNORM8 seems to be in DW11 instead of DW1.
1270 */
1271
1272 /* IEEE_FP */
1273 dw[1] = fui(rgba[0]);
1274 dw[2] = fui(rgba[1]);
1275 dw[3] = fui(rgba[2]);
1276 dw[4] = fui(rgba[3]);
1277
1278 /* FLOAT_16 */
1279 dw[5] = util_float_to_half(rgba[0]) |
1280 util_float_to_half(rgba[1]) << 16;
1281 dw[6] = util_float_to_half(rgba[2]) |
1282 util_float_to_half(rgba[3]) << 16;
1283
1284 /* clamp to [-1.0f, 1.0f] */
1285 rgba[0] = CLAMP(rgba[0], -1.0f, 1.0f);
1286 rgba[1] = CLAMP(rgba[1], -1.0f, 1.0f);
1287 rgba[2] = CLAMP(rgba[2], -1.0f, 1.0f);
1288 rgba[3] = CLAMP(rgba[3], -1.0f, 1.0f);
1289
1290 /* SNORM16 */
1291 dw[9] = (int16_t) util_iround(rgba[0] * 32767.0f) |
1292 (int16_t) util_iround(rgba[1] * 32767.0f) << 16;
1293 dw[10] = (int16_t) util_iround(rgba[2] * 32767.0f) |
1294 (int16_t) util_iround(rgba[3] * 32767.0f) << 16;
1295
1296 /* SNORM8 */
1297 dw[11] = (int8_t) util_iround(rgba[0] * 127.0f) |
1298 (int8_t) util_iround(rgba[1] * 127.0f) << 8 |
1299 (int8_t) util_iround(rgba[2] * 127.0f) << 16 |
1300 (int8_t) util_iround(rgba[3] * 127.0f) << 24;
1301
1302 /* clamp to [0.0f, 1.0f] */
1303 rgba[0] = CLAMP(rgba[0], 0.0f, 1.0f);
1304 rgba[1] = CLAMP(rgba[1], 0.0f, 1.0f);
1305 rgba[2] = CLAMP(rgba[2], 0.0f, 1.0f);
1306 rgba[3] = CLAMP(rgba[3], 0.0f, 1.0f);
1307
1308 /* UNORM8 */
1309 dw[0] = (uint8_t) util_iround(rgba[0] * 255.0f) |
1310 (uint8_t) util_iround(rgba[1] * 255.0f) << 8 |
1311 (uint8_t) util_iround(rgba[2] * 255.0f) << 16 |
1312 (uint8_t) util_iround(rgba[3] * 255.0f) << 24;
1313
1314 /* UNORM16 */
1315 dw[7] = (uint16_t) util_iround(rgba[0] * 65535.0f) |
1316 (uint16_t) util_iround(rgba[1] * 65535.0f) << 16;
1317 dw[8] = (uint16_t) util_iround(rgba[2] * 65535.0f) |
1318 (uint16_t) util_iround(rgba[3] * 65535.0f) << 16;
1319 }
1320
1321 /**
1322 * Translate a pipe texture mipfilter to the matching hardware mipfilter.
1323 */
1324 static int
1325 gen6_translate_tex_mipfilter(unsigned filter)
1326 {
1327 switch (filter) {
1328 case PIPE_TEX_MIPFILTER_NEAREST: return GEN6_MIPFILTER_NEAREST;
1329 case PIPE_TEX_MIPFILTER_LINEAR: return GEN6_MIPFILTER_LINEAR;
1330 case PIPE_TEX_MIPFILTER_NONE: return GEN6_MIPFILTER_NONE;
1331 default:
1332 assert(!"unknown mipfilter");
1333 return GEN6_MIPFILTER_NONE;
1334 }
1335 }
1336
1337 /**
1338 * Translate a pipe texture filter to the matching hardware mapfilter.
1339 */
1340 static int
1341 gen6_translate_tex_filter(unsigned filter)
1342 {
1343 switch (filter) {
1344 case PIPE_TEX_FILTER_NEAREST: return GEN6_MAPFILTER_NEAREST;
1345 case PIPE_TEX_FILTER_LINEAR: return GEN6_MAPFILTER_LINEAR;
1346 default:
1347 assert(!"unknown sampler filter");
1348 return GEN6_MAPFILTER_NEAREST;
1349 }
1350 }
1351
1352 /**
1353 * Translate a pipe texture coordinate wrapping mode to the matching hardware
1354 * wrapping mode.
1355 */
1356 static int
1357 gen6_translate_tex_wrap(unsigned wrap)
1358 {
1359 switch (wrap) {
1360 case PIPE_TEX_WRAP_CLAMP: return GEN8_TEXCOORDMODE_HALF_BORDER;
1361 case PIPE_TEX_WRAP_REPEAT: return GEN6_TEXCOORDMODE_WRAP;
1362 case PIPE_TEX_WRAP_CLAMP_TO_EDGE: return GEN6_TEXCOORDMODE_CLAMP;
1363 case PIPE_TEX_WRAP_CLAMP_TO_BORDER: return GEN6_TEXCOORDMODE_CLAMP_BORDER;
1364 case PIPE_TEX_WRAP_MIRROR_REPEAT: return GEN6_TEXCOORDMODE_MIRROR;
1365 case PIPE_TEX_WRAP_MIRROR_CLAMP:
1366 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
1367 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
1368 default:
1369 assert(!"unknown sampler wrap mode");
1370 return GEN6_TEXCOORDMODE_WRAP;
1371 }
1372 }
1373
1374 /**
1375 * Translate a pipe shadow compare function to the matching hardware shadow
1376 * function.
1377 */
1378 static int
1379 gen6_translate_shadow_func(unsigned func)
1380 {
1381 /*
1382 * For PIPE_FUNC_x, the reference value is on the left-hand side of the
1383 * comparison, and 1.0 is returned when the comparison is true.
1384 *
1385 * For GEN6_COMPAREFUNCTION_x, the reference value is on the right-hand side of
1386 * the comparison, and 0.0 is returned when the comparison is true.
1387 */
1388 switch (func) {
1389 case PIPE_FUNC_NEVER: return GEN6_COMPAREFUNCTION_ALWAYS;
1390 case PIPE_FUNC_LESS: return GEN6_COMPAREFUNCTION_LEQUAL;
1391 case PIPE_FUNC_EQUAL: return GEN6_COMPAREFUNCTION_NOTEQUAL;
1392 case PIPE_FUNC_LEQUAL: return GEN6_COMPAREFUNCTION_LESS;
1393 case PIPE_FUNC_GREATER: return GEN6_COMPAREFUNCTION_GEQUAL;
1394 case PIPE_FUNC_NOTEQUAL: return GEN6_COMPAREFUNCTION_EQUAL;
1395 case PIPE_FUNC_GEQUAL: return GEN6_COMPAREFUNCTION_GREATER;
1396 case PIPE_FUNC_ALWAYS: return GEN6_COMPAREFUNCTION_NEVER;
1397 default:
1398 assert(!"unknown shadow compare function");
1399 return GEN6_COMPAREFUNCTION_NEVER;
1400 }
1401 }
1402
1403 void
1404 ilo_gpe_init_sampler_cso(const struct ilo_dev *dev,
1405 const struct pipe_sampler_state *state,
1406 struct ilo_sampler_cso *sampler)
1407 {
1408 int mip_filter, min_filter, mag_filter, max_aniso;
1409 int lod_bias, max_lod, min_lod;
1410 int wrap_s, wrap_t, wrap_r, wrap_cube;
1411 uint32_t dw0, dw1, dw3;
1412
1413 ILO_DEV_ASSERT(dev, 6, 8);
1414
1415 memset(sampler, 0, sizeof(*sampler));
1416
1417 mip_filter = gen6_translate_tex_mipfilter(state->min_mip_filter);
1418 min_filter = gen6_translate_tex_filter(state->min_img_filter);
1419 mag_filter = gen6_translate_tex_filter(state->mag_img_filter);
1420
1421 sampler->anisotropic = state->max_anisotropy;
1422
1423 if (state->max_anisotropy >= 2 && state->max_anisotropy <= 16)
1424 max_aniso = state->max_anisotropy / 2 - 1;
1425 else if (state->max_anisotropy > 16)
1426 max_aniso = GEN6_ANISORATIO_16;
1427 else
1428 max_aniso = GEN6_ANISORATIO_2;
1429
1430 /*
1431 *
1432 * Here is how the hardware calculate per-pixel LOD, from my reading of the
1433 * PRMs:
1434 *
1435 * 1) LOD is set to log2(ratio of texels to pixels) if not specified in
1436 * other ways. The number of texels is measured using level
1437 * SurfMinLod.
1438 * 2) Bias is added to LOD.
1439 * 3) LOD is clamped to [MinLod, MaxLod], and the clamped value is
1440 * compared with Base to determine whether magnification or
1441 * minification is needed. (if preclamp is disabled, LOD is compared
1442 * with Base before clamping)
1443 * 4) If magnification is needed, or no mipmapping is requested, LOD is
1444 * set to floor(MinLod).
1445 * 5) LOD is clamped to [0, MIPCnt], and SurfMinLod is added to LOD.
1446 *
1447 * With Gallium interface, Base is always zero and
1448 * pipe_sampler_view::u.tex.first_level specifies SurfMinLod.
1449 */
1450 if (ilo_dev_gen(dev) >= ILO_GEN(7)) {
1451 const float scale = 256.0f;
1452
1453 /* [-16.0, 16.0) in S4.8 */
1454 lod_bias = (int)
1455 (CLAMP(state->lod_bias, -16.0f, 15.9f) * scale);
1456 lod_bias &= 0x1fff;
1457
1458 /* [0.0, 14.0] in U4.8 */
1459 max_lod = (int) (CLAMP(state->max_lod, 0.0f, 14.0f) * scale);
1460 min_lod = (int) (CLAMP(state->min_lod, 0.0f, 14.0f) * scale);
1461 }
1462 else {
1463 const float scale = 64.0f;
1464
1465 /* [-16.0, 16.0) in S4.6 */
1466 lod_bias = (int)
1467 (CLAMP(state->lod_bias, -16.0f, 15.9f) * scale);
1468 lod_bias &= 0x7ff;
1469
1470 /* [0.0, 13.0] in U4.6 */
1471 max_lod = (int) (CLAMP(state->max_lod, 0.0f, 13.0f) * scale);
1472 min_lod = (int) (CLAMP(state->min_lod, 0.0f, 13.0f) * scale);
1473 }
1474
1475 /*
1476 * We want LOD to be clamped to determine magnification/minification, and
1477 * get set to zero when it is magnification or when mipmapping is disabled.
1478 * The hardware would set LOD to floor(MinLod) and that is a problem when
1479 * MinLod is greater than or equal to 1.0f.
1480 *
1481 * With Base being zero, it is always minification when MinLod is non-zero.
1482 * To achieve our goal, we just need to set MinLod to zero and set
1483 * MagFilter to MinFilter when mipmapping is disabled.
1484 */
1485 if (state->min_mip_filter == PIPE_TEX_MIPFILTER_NONE && min_lod) {
1486 min_lod = 0;
1487 mag_filter = min_filter;
1488 }
1489
1490 /* determine wrap s/t/r */
1491 wrap_s = gen6_translate_tex_wrap(state->wrap_s);
1492 wrap_t = gen6_translate_tex_wrap(state->wrap_t);
1493 wrap_r = gen6_translate_tex_wrap(state->wrap_r);
1494 if (ilo_dev_gen(dev) < ILO_GEN(8)) {
1495 /*
1496 * For nearest filtering, PIPE_TEX_WRAP_CLAMP means
1497 * PIPE_TEX_WRAP_CLAMP_TO_EDGE; for linear filtering,
1498 * PIPE_TEX_WRAP_CLAMP means PIPE_TEX_WRAP_CLAMP_TO_BORDER while
1499 * additionally clamping the texture coordinates to [0.0, 1.0].
1500 *
1501 * PIPE_TEX_WRAP_CLAMP is not supported natively until Gen8. The
1502 * clamping has to be taken care of in the shaders. There are two
1503 * filters here, but let the minification one has a say.
1504 */
1505 const bool clamp_is_to_edge =
1506 (state->min_img_filter == PIPE_TEX_FILTER_NEAREST);
1507
1508 if (clamp_is_to_edge) {
1509 if (wrap_s == GEN8_TEXCOORDMODE_HALF_BORDER)
1510 wrap_s = GEN6_TEXCOORDMODE_CLAMP;
1511 if (wrap_t == GEN8_TEXCOORDMODE_HALF_BORDER)
1512 wrap_t = GEN6_TEXCOORDMODE_CLAMP;
1513 if (wrap_r == GEN8_TEXCOORDMODE_HALF_BORDER)
1514 wrap_r = GEN6_TEXCOORDMODE_CLAMP;
1515 } else {
1516 if (wrap_s == GEN8_TEXCOORDMODE_HALF_BORDER) {
1517 wrap_s = GEN6_TEXCOORDMODE_CLAMP_BORDER;
1518 sampler->saturate_s = true;
1519 }
1520 if (wrap_t == GEN8_TEXCOORDMODE_HALF_BORDER) {
1521 wrap_t = GEN6_TEXCOORDMODE_CLAMP_BORDER;
1522 sampler->saturate_t = true;
1523 }
1524 if (wrap_r == GEN8_TEXCOORDMODE_HALF_BORDER) {
1525 wrap_r = GEN6_TEXCOORDMODE_CLAMP_BORDER;
1526 sampler->saturate_r = true;
1527 }
1528 }
1529 }
1530
1531 /*
1532 * From the Sandy Bridge PRM, volume 4 part 1, page 107:
1533 *
1534 * "When using cube map texture coordinates, only TEXCOORDMODE_CLAMP
1535 * and TEXCOORDMODE_CUBE settings are valid, and each TC component
1536 * must have the same Address Control mode."
1537 *
1538 * From the Ivy Bridge PRM, volume 4 part 1, page 96:
1539 *
1540 * "This field (Cube Surface Control Mode) must be set to
1541 * CUBECTRLMODE_PROGRAMMED"
1542 *
1543 * Therefore, we cannot use "Cube Surface Control Mode" for semless cube
1544 * map filtering.
1545 */
1546 if (state->seamless_cube_map &&
1547 (state->min_img_filter != PIPE_TEX_FILTER_NEAREST ||
1548 state->mag_img_filter != PIPE_TEX_FILTER_NEAREST)) {
1549 wrap_cube = GEN6_TEXCOORDMODE_CUBE;
1550 }
1551 else {
1552 wrap_cube = GEN6_TEXCOORDMODE_CLAMP;
1553 }
1554
1555 if (!state->normalized_coords) {
1556 /*
1557 * From the Ivy Bridge PRM, volume 4 part 1, page 98:
1558 *
1559 * "The following state must be set as indicated if this field
1560 * (Non-normalized Coordinate Enable) is enabled:
1561 *
1562 * - TCX/Y/Z Address Control Mode must be TEXCOORDMODE_CLAMP,
1563 * TEXCOORDMODE_HALF_BORDER, or TEXCOORDMODE_CLAMP_BORDER.
1564 * - Surface Type must be SURFTYPE_2D or SURFTYPE_3D.
1565 * - Mag Mode Filter must be MAPFILTER_NEAREST or
1566 * MAPFILTER_LINEAR.
1567 * - Min Mode Filter must be MAPFILTER_NEAREST or
1568 * MAPFILTER_LINEAR.
1569 * - Mip Mode Filter must be MIPFILTER_NONE.
1570 * - Min LOD must be 0.
1571 * - Max LOD must be 0.
1572 * - MIP Count must be 0.
1573 * - Surface Min LOD must be 0.
1574 * - Texture LOD Bias must be 0."
1575 */
1576 assert(wrap_s == GEN6_TEXCOORDMODE_CLAMP ||
1577 wrap_s == GEN6_TEXCOORDMODE_CLAMP_BORDER);
1578 assert(wrap_t == GEN6_TEXCOORDMODE_CLAMP ||
1579 wrap_t == GEN6_TEXCOORDMODE_CLAMP_BORDER);
1580 assert(wrap_r == GEN6_TEXCOORDMODE_CLAMP ||
1581 wrap_r == GEN6_TEXCOORDMODE_CLAMP_BORDER);
1582
1583 assert(mag_filter == GEN6_MAPFILTER_NEAREST ||
1584 mag_filter == GEN6_MAPFILTER_LINEAR);
1585 assert(min_filter == GEN6_MAPFILTER_NEAREST ||
1586 min_filter == GEN6_MAPFILTER_LINEAR);
1587
1588 /* work around a bug in util_blitter */
1589 mip_filter = GEN6_MIPFILTER_NONE;
1590
1591 assert(mip_filter == GEN6_MIPFILTER_NONE);
1592 }
1593
1594 if (ilo_dev_gen(dev) >= ILO_GEN(7)) {
1595 dw0 = 1 << 28 |
1596 mip_filter << 20 |
1597 lod_bias << 1;
1598
1599 sampler->dw_filter = mag_filter << 17 |
1600 min_filter << 14;
1601
1602 sampler->dw_filter_aniso = GEN6_MAPFILTER_ANISOTROPIC << 17 |
1603 GEN6_MAPFILTER_ANISOTROPIC << 14 |
1604 1;
1605
1606 dw1 = min_lod << 20 |
1607 max_lod << 8;
1608
1609 if (state->compare_mode != PIPE_TEX_COMPARE_NONE)
1610 dw1 |= gen6_translate_shadow_func(state->compare_func) << 1;
1611
1612 dw3 = max_aniso << 19;
1613
1614 /* round the coordinates for linear filtering */
1615 if (min_filter != GEN6_MAPFILTER_NEAREST) {
1616 dw3 |= (GEN6_SAMPLER_DW3_U_MIN_ROUND |
1617 GEN6_SAMPLER_DW3_V_MIN_ROUND |
1618 GEN6_SAMPLER_DW3_R_MIN_ROUND);
1619 }
1620 if (mag_filter != GEN6_MAPFILTER_NEAREST) {
1621 dw3 |= (GEN6_SAMPLER_DW3_U_MAG_ROUND |
1622 GEN6_SAMPLER_DW3_V_MAG_ROUND |
1623 GEN6_SAMPLER_DW3_R_MAG_ROUND);
1624 }
1625
1626 if (!state->normalized_coords)
1627 dw3 |= 1 << 10;
1628
1629 sampler->dw_wrap = wrap_s << 6 |
1630 wrap_t << 3 |
1631 wrap_r;
1632
1633 /*
1634 * As noted in the classic i965 driver, the HW may still reference
1635 * wrap_t and wrap_r for 1D textures. We need to set them to a safe
1636 * mode
1637 */
1638 sampler->dw_wrap_1d = wrap_s << 6 |
1639 GEN6_TEXCOORDMODE_WRAP << 3 |
1640 GEN6_TEXCOORDMODE_WRAP;
1641
1642 sampler->dw_wrap_cube = wrap_cube << 6 |
1643 wrap_cube << 3 |
1644 wrap_cube;
1645
1646 STATIC_ASSERT(Elements(sampler->payload) >= 7);
1647
1648 sampler->payload[0] = dw0;
1649 sampler->payload[1] = dw1;
1650 sampler->payload[2] = dw3;
1651
1652 memcpy(&sampler->payload[3],
1653 state->border_color.ui, sizeof(state->border_color.ui));
1654 }
1655 else {
1656 dw0 = 1 << 28 |
1657 mip_filter << 20 |
1658 lod_bias << 3;
1659
1660 if (state->compare_mode != PIPE_TEX_COMPARE_NONE)
1661 dw0 |= gen6_translate_shadow_func(state->compare_func);
1662
1663 sampler->dw_filter = (min_filter != mag_filter) << 27 |
1664 mag_filter << 17 |
1665 min_filter << 14;
1666
1667 sampler->dw_filter_aniso = GEN6_MAPFILTER_ANISOTROPIC << 17 |
1668 GEN6_MAPFILTER_ANISOTROPIC << 14;
1669
1670 dw1 = min_lod << 22 |
1671 max_lod << 12;
1672
1673 sampler->dw_wrap = wrap_s << 6 |
1674 wrap_t << 3 |
1675 wrap_r;
1676
1677 sampler->dw_wrap_1d = wrap_s << 6 |
1678 GEN6_TEXCOORDMODE_WRAP << 3 |
1679 GEN6_TEXCOORDMODE_WRAP;
1680
1681 sampler->dw_wrap_cube = wrap_cube << 6 |
1682 wrap_cube << 3 |
1683 wrap_cube;
1684
1685 dw3 = max_aniso << 19;
1686
1687 /* round the coordinates for linear filtering */
1688 if (min_filter != GEN6_MAPFILTER_NEAREST) {
1689 dw3 |= (GEN6_SAMPLER_DW3_U_MIN_ROUND |
1690 GEN6_SAMPLER_DW3_V_MIN_ROUND |
1691 GEN6_SAMPLER_DW3_R_MIN_ROUND);
1692 }
1693 if (mag_filter != GEN6_MAPFILTER_NEAREST) {
1694 dw3 |= (GEN6_SAMPLER_DW3_U_MAG_ROUND |
1695 GEN6_SAMPLER_DW3_V_MAG_ROUND |
1696 GEN6_SAMPLER_DW3_R_MAG_ROUND);
1697 }
1698
1699 if (!state->normalized_coords)
1700 dw3 |= 1;
1701
1702 STATIC_ASSERT(Elements(sampler->payload) >= 15);
1703
1704 sampler->payload[0] = dw0;
1705 sampler->payload[1] = dw1;
1706 sampler->payload[2] = dw3;
1707
1708 sampler_init_border_color_gen6(dev,
1709 &state->border_color, &sampler->payload[3], 12);
1710 }
1711 }