~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/intel/vulkan/genX_state.c

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2015 Intel Corporation
3
 
 *
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:
10
 
 *
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
13
 
 * Software.
14
 
 *
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
21
 
 * IN THE SOFTWARE.
22
 
 */
23
 
 
24
 
#include <assert.h>
25
 
#include <stdbool.h>
26
 
#include <string.h>
27
 
#include <unistd.h>
28
 
#include <fcntl.h>
29
 
 
30
 
#include "anv_private.h"
31
 
 
32
 
#include "common/intel_aux_map.h"
33
 
#include "common/intel_sample_positions.h"
34
 
#include "common/intel_pixel_hash.h"
35
 
#include "genxml/gen_macros.h"
36
 
#include "genxml/genX_pack.h"
37
 
 
38
 
#include "vk_util.h"
39
 
 
40
 
static void
41
 
genX(emit_slice_hashing_state)(struct anv_device *device,
42
 
                               struct anv_batch *batch)
43
 
{
44
 
#if GFX_VER == 11
45
 
   /* Gfx11 hardware has two pixel pipes at most. */
46
 
   for (unsigned i = 2; i < ARRAY_SIZE(device->info.ppipe_subslices); i++)
47
 
      assert(device->info.ppipe_subslices[i] == 0);
48
 
 
49
 
   if (device->info.ppipe_subslices[0] == device->info.ppipe_subslices[1])
50
 
     return;
51
 
 
52
 
   if (!device->slice_hash.alloc_size) {
53
 
      unsigned size = GENX(SLICE_HASH_TABLE_length) * 4;
54
 
      device->slice_hash =
55
 
         anv_state_pool_alloc(&device->dynamic_state_pool, size, 64);
56
 
 
57
 
      const bool flip = device->info.ppipe_subslices[0] <
58
 
                     device->info.ppipe_subslices[1];
59
 
      struct GENX(SLICE_HASH_TABLE) table;
60
 
      intel_compute_pixel_hash_table_3way(16, 16, 3, 3, flip, table.Entry[0]);
61
 
 
62
 
      GENX(SLICE_HASH_TABLE_pack)(NULL, device->slice_hash.map, &table);
63
 
   }
64
 
 
65
 
   anv_batch_emit(batch, GENX(3DSTATE_SLICE_TABLE_STATE_POINTERS), ptr) {
66
 
      ptr.SliceHashStatePointerValid = true;
67
 
      ptr.SliceHashTableStatePointer = device->slice_hash.offset;
68
 
   }
69
 
 
70
 
   anv_batch_emit(batch, GENX(3DSTATE_3D_MODE), mode) {
71
 
      mode.SliceHashingTableEnable = true;
72
 
   }
73
 
#elif GFX_VERx10 == 120
74
 
   /* For each n calculate ppipes_of[n], equal to the number of pixel pipes
75
 
    * present with n active dual subslices.
76
 
    */
77
 
   unsigned ppipes_of[3] = {};
78
 
 
79
 
   for (unsigned n = 0; n < ARRAY_SIZE(ppipes_of); n++) {
80
 
      for (unsigned p = 0; p < 3; p++)
81
 
         ppipes_of[n] += (device->info.ppipe_subslices[p] == n);
82
 
   }
83
 
 
84
 
   /* Gfx12 has three pixel pipes. */
85
 
   for (unsigned p = 3; p < ARRAY_SIZE(device->info.ppipe_subslices); p++)
86
 
      assert(device->info.ppipe_subslices[p] == 0);
87
 
 
88
 
   if (ppipes_of[2] == 3 || ppipes_of[0] == 2) {
89
 
      /* All three pixel pipes have the maximum number of active dual
90
 
       * subslices, or there is only one active pixel pipe: Nothing to do.
91
 
       */
92
 
      return;
93
 
   }
94
 
 
95
 
   anv_batch_emit(batch, GENX(3DSTATE_SUBSLICE_HASH_TABLE), p) {
96
 
      p.SliceHashControl[0] = TABLE_0;
97
 
 
98
 
      if (ppipes_of[2] == 2 && ppipes_of[0] == 1)
99
 
         intel_compute_pixel_hash_table_3way(8, 16, 2, 2, 0, p.TwoWayTableEntry[0]);
100
 
      else if (ppipes_of[2] == 1 && ppipes_of[1] == 1 && ppipes_of[0] == 1)
101
 
         intel_compute_pixel_hash_table_3way(8, 16, 3, 3, 0, p.TwoWayTableEntry[0]);
102
 
 
103
 
      if (ppipes_of[2] == 2 && ppipes_of[1] == 1)
104
 
         intel_compute_pixel_hash_table_3way(8, 16, 5, 4, 0, p.ThreeWayTableEntry[0]);
105
 
      else if (ppipes_of[2] == 2 && ppipes_of[0] == 1)
106
 
         intel_compute_pixel_hash_table_3way(8, 16, 2, 2, 0, p.ThreeWayTableEntry[0]);
107
 
      else if (ppipes_of[2] == 1 && ppipes_of[1] == 1 && ppipes_of[0] == 1)
108
 
         intel_compute_pixel_hash_table_3way(8, 16, 3, 3, 0, p.ThreeWayTableEntry[0]);
109
 
      else
110
 
         unreachable("Illegal fusing.");
111
 
   }
112
 
 
113
 
   anv_batch_emit(batch, GENX(3DSTATE_3D_MODE), p) {
114
 
      p.SubsliceHashingTableEnable = true;
115
 
      p.SubsliceHashingTableEnableMask = true;
116
 
   }
117
 
#elif GFX_VERx10 == 125
118
 
   uint32_t ppipe_mask = 0;
119
 
   for (unsigned p = 0; p < ARRAY_SIZE(device->info.ppipe_subslices); p++) {
120
 
      if (device->info.ppipe_subslices[p])
121
 
         ppipe_mask |= (1u << p);
122
 
   }
123
 
   assert(ppipe_mask);
124
 
 
125
 
   if (!device->slice_hash.alloc_size) {
126
 
      unsigned size = GENX(SLICE_HASH_TABLE_length) * 4;
127
 
      device->slice_hash =
128
 
         anv_state_pool_alloc(&device->dynamic_state_pool, size, 64);
129
 
 
130
 
      struct GENX(SLICE_HASH_TABLE) table;
131
 
 
132
 
      /* Note that the hardware expects an array with 7 tables, each
133
 
       * table is intended to specify the pixel pipe hashing behavior
134
 
       * for every possible slice count between 2 and 8, however that
135
 
       * doesn't actually work, among other reasons due to hardware
136
 
       * bugs that will cause the GPU to erroneously access the table
137
 
       * at the wrong index in some cases, so in practice all 7 tables
138
 
       * need to be initialized to the same value.
139
 
       */
140
 
      for (unsigned i = 0; i < 7; i++)
141
 
         intel_compute_pixel_hash_table_nway(16, 16, ppipe_mask, table.Entry[i][0]);
142
 
 
143
 
      GENX(SLICE_HASH_TABLE_pack)(NULL, device->slice_hash.map, &table);
144
 
   }
145
 
 
146
 
   anv_batch_emit(batch, GENX(3DSTATE_SLICE_TABLE_STATE_POINTERS), ptr) {
147
 
      ptr.SliceHashStatePointerValid = true;
148
 
      ptr.SliceHashTableStatePointer = device->slice_hash.offset;
149
 
   }
150
 
 
151
 
   anv_batch_emit(batch, GENX(3DSTATE_3D_MODE), mode) {
152
 
      mode.SliceHashingTableEnable = true;
153
 
      mode.SliceHashingTableEnableMask = true;
154
 
      mode.CrossSliceHashingMode = (util_bitcount(ppipe_mask) > 1 ?
155
 
                                    hashing32x32 : NormalMode);
156
 
      mode.CrossSliceHashingModeMask = -1;
157
 
   }
158
 
#endif
159
 
}
160
 
 
161
 
static VkResult
162
 
init_render_queue_state(struct anv_queue *queue)
163
 
{
164
 
   struct anv_device *device = queue->device;
165
 
   uint32_t cmds[128];
166
 
   struct anv_batch batch = {
167
 
      .start = cmds,
168
 
      .next = cmds,
169
 
      .end = (void *) cmds + sizeof(cmds),
170
 
   };
171
 
 
172
 
   anv_batch_emit(&batch, GENX(PIPELINE_SELECT), ps) {
173
 
#if GFX_VER >= 9
174
 
      ps.MaskBits = GFX_VER >= 12 ? 0x13 : 3;
175
 
      ps.MediaSamplerDOPClockGateEnable = GFX_VER >= 12;
176
 
#endif
177
 
      ps.PipelineSelection = _3D;
178
 
   }
179
 
 
180
 
#if GFX_VER == 9
181
 
   anv_batch_write_reg(&batch, GENX(CACHE_MODE_1), cm1) {
182
 
      cm1.FloatBlendOptimizationEnable = true;
183
 
      cm1.FloatBlendOptimizationEnableMask = true;
184
 
      cm1.MSCRAWHazardAvoidanceBit = true;
185
 
      cm1.MSCRAWHazardAvoidanceBitMask = true;
186
 
      cm1.PartialResolveDisableInVC = true;
187
 
      cm1.PartialResolveDisableInVCMask = true;
188
 
   }
189
 
#endif
190
 
 
191
 
#if GFX_VERx10 >= 125
192
 
   /* GEN:BUG:1607854226:
193
 
    *
194
 
    *  Non-pipelined state has issues with not applying in MEDIA/GPGPU mode.
195
 
    *  Fortunately, we always start the context off in 3D mode.
196
 
    */
197
 
   uint32_t mocs = device->isl_dev.mocs.internal;
198
 
   anv_batch_emit(&batch, GENX(STATE_BASE_ADDRESS), sba) {
199
 
      sba.GeneralStateBaseAddress = (struct anv_address) { NULL, 0 };
200
 
      sba.GeneralStateBufferSize  = 0xfffff;
201
 
      sba.GeneralStateMOCS = mocs;
202
 
      sba.GeneralStateBaseAddressModifyEnable = true;
203
 
      sba.GeneralStateBufferSizeModifyEnable = true;
204
 
 
205
 
      sba.StatelessDataPortAccessMOCS = mocs;
206
 
 
207
 
      sba.SurfaceStateBaseAddress =
208
 
         (struct anv_address) { .offset = SURFACE_STATE_POOL_MIN_ADDRESS };
209
 
      sba.SurfaceStateMOCS = mocs;
210
 
      sba.SurfaceStateBaseAddressModifyEnable = true;
211
 
 
212
 
      sba.DynamicStateBaseAddress =
213
 
         (struct anv_address) { .offset = DYNAMIC_STATE_POOL_MIN_ADDRESS };
214
 
      sba.DynamicStateBufferSize = DYNAMIC_STATE_POOL_SIZE / 4096;
215
 
      sba.DynamicStateMOCS = mocs;
216
 
      sba.DynamicStateBaseAddressModifyEnable = true;
217
 
      sba.DynamicStateBufferSizeModifyEnable = true;
218
 
 
219
 
      sba.IndirectObjectBaseAddress = (struct anv_address) { NULL, 0 };
220
 
      sba.IndirectObjectBufferSize = 0xfffff;
221
 
      sba.IndirectObjectMOCS = mocs;
222
 
      sba.IndirectObjectBaseAddressModifyEnable = true;
223
 
      sba.IndirectObjectBufferSizeModifyEnable = true;
224
 
 
225
 
      sba.InstructionBaseAddress =
226
 
         (struct anv_address) { .offset = INSTRUCTION_STATE_POOL_MIN_ADDRESS };
227
 
      sba.InstructionBufferSize = INSTRUCTION_STATE_POOL_SIZE / 4096;
228
 
      sba.InstructionMOCS = mocs;
229
 
      sba.InstructionBaseAddressModifyEnable = true;
230
 
      sba.InstructionBuffersizeModifyEnable = true;
231
 
 
232
 
      sba.BindlessSurfaceStateBaseAddress =
233
 
         (struct anv_address) { .offset = SURFACE_STATE_POOL_MIN_ADDRESS };
234
 
      sba.BindlessSurfaceStateSize = (1 << 20) - 1;
235
 
      sba.BindlessSurfaceStateMOCS = mocs;
236
 
      sba.BindlessSurfaceStateBaseAddressModifyEnable = true;
237
 
 
238
 
      sba.BindlessSamplerStateBaseAddress = (struct anv_address) { NULL, 0 };
239
 
      sba.BindlessSamplerStateMOCS = mocs;
240
 
      sba.BindlessSamplerStateBaseAddressModifyEnable = true;
241
 
      sba.BindlessSamplerStateBufferSize = 0;
242
 
   }
243
 
#endif
244
 
 
245
 
   anv_batch_emit(&batch, GENX(3DSTATE_AA_LINE_PARAMETERS), aa);
246
 
 
247
 
   anv_batch_emit(&batch, GENX(3DSTATE_DRAWING_RECTANGLE), rect) {
248
 
      rect.ClippedDrawingRectangleYMin = 0;
249
 
      rect.ClippedDrawingRectangleXMin = 0;
250
 
      rect.ClippedDrawingRectangleYMax = UINT16_MAX;
251
 
      rect.ClippedDrawingRectangleXMax = UINT16_MAX;
252
 
      rect.DrawingRectangleOriginY = 0;
253
 
      rect.DrawingRectangleOriginX = 0;
254
 
   }
255
 
 
256
 
#if GFX_VER >= 8
257
 
   anv_batch_emit(&batch, GENX(3DSTATE_WM_CHROMAKEY), ck);
258
 
 
259
 
   genX(emit_sample_pattern)(&batch, NULL);
260
 
 
261
 
   /* The BDW+ docs describe how to use the 3DSTATE_WM_HZ_OP instruction in the
262
 
    * section titled, "Optimized Depth Buffer Clear and/or Stencil Buffer
263
 
    * Clear." It mentions that the packet overrides GPU state for the clear
264
 
    * operation and needs to be reset to 0s to clear the overrides. Depending
265
 
    * on the kernel, we may not get a context with the state for this packet
266
 
    * zeroed. Do it ourselves just in case. We've observed this to prevent a
267
 
    * number of GPU hangs on ICL.
268
 
    */
269
 
   anv_batch_emit(&batch, GENX(3DSTATE_WM_HZ_OP), hzp);
270
 
#endif
271
 
 
272
 
#if GFX_VER == 11
273
 
   /* The default behavior of bit 5 "Headerless Message for Pre-emptable
274
 
    * Contexts" in SAMPLER MODE register is set to 0, which means
275
 
    * headerless sampler messages are not allowed for pre-emptable
276
 
    * contexts. Set the bit 5 to 1 to allow them.
277
 
    */
278
 
   anv_batch_write_reg(&batch, GENX(SAMPLER_MODE), sm) {
279
 
      sm.HeaderlessMessageforPreemptableContexts = true;
280
 
      sm.HeaderlessMessageforPreemptableContextsMask = true;
281
 
   }
282
 
 
283
 
   /* Bit 1 "Enabled Texel Offset Precision Fix" must be set in
284
 
    * HALF_SLICE_CHICKEN7 register.
285
 
    */
286
 
   anv_batch_write_reg(&batch, GENX(HALF_SLICE_CHICKEN7), hsc7) {
287
 
      hsc7.EnabledTexelOffsetPrecisionFix = true;
288
 
      hsc7.EnabledTexelOffsetPrecisionFixMask = true;
289
 
   }
290
 
 
291
 
   anv_batch_write_reg(&batch, GENX(TCCNTLREG), tcc) {
292
 
      tcc.L3DataPartialWriteMergingEnable = true;
293
 
      tcc.ColorZPartialWriteMergingEnable = true;
294
 
      tcc.URBPartialWriteMergingEnable = true;
295
 
      tcc.TCDisable = true;
296
 
   }
297
 
#endif
298
 
   genX(emit_slice_hashing_state)(device, &batch);
299
 
 
300
 
#if GFX_VER >= 11
301
 
   /* hardware specification recommends disabling repacking for
302
 
    * the compatibility with decompression mechanism in display controller.
303
 
    */
304
 
   if (device->info.disable_ccs_repack) {
305
 
      anv_batch_write_reg(&batch, GENX(CACHE_MODE_0), cm0) {
306
 
         cm0.DisableRepackingforCompression = true;
307
 
         cm0.DisableRepackingforCompressionMask = true;
308
 
      }
309
 
   }
310
 
 
311
 
   /* an unknown issue is causing vs push constants to become
312
 
    * corrupted during object-level preemption. For now, restrict
313
 
    * to command buffer level preemption to avoid rendering
314
 
    * corruption.
315
 
    */
316
 
   anv_batch_write_reg(&batch, GENX(CS_CHICKEN1), cc1) {
317
 
      cc1.ReplayMode = MidcmdbufferPreemption;
318
 
      cc1.ReplayModeMask = true;
319
 
 
320
 
#if GFX_VERx10 == 120
321
 
      cc1.DisablePreemptionandHighPriorityPausingdueto3DPRIMITIVECommand = true;
322
 
      cc1.DisablePreemptionandHighPriorityPausingdueto3DPRIMITIVECommandMask = true;
323
 
#endif
324
 
   }
325
 
 
326
 
#if GFX_VERx10 < 125
327
 
#define AA_LINE_QUALITY_REG GENX(3D_CHICKEN3)
328
 
#else
329
 
#define AA_LINE_QUALITY_REG GENX(CHICKEN_RASTER_1)
330
 
#endif
331
 
 
332
 
   /* Enable the new line drawing algorithm that produces higher quality
333
 
    * lines.
334
 
    */
335
 
   anv_batch_write_reg(&batch, AA_LINE_QUALITY_REG, c3) {
336
 
      c3.AALineQualityFix = true;
337
 
      c3.AALineQualityFixMask = true;
338
 
   }
339
 
#endif
340
 
 
341
 
#if GFX_VER == 12
342
 
   if (device->info.has_aux_map) {
343
 
      uint64_t aux_base_addr = intel_aux_map_get_base(device->aux_map_ctx);
344
 
      assert(aux_base_addr % (32 * 1024) == 0);
345
 
      anv_batch_emit(&batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
346
 
         lri.RegisterOffset = GENX(GFX_AUX_TABLE_BASE_ADDR_num);
347
 
         lri.DataDWord = aux_base_addr & 0xffffffff;
348
 
      }
349
 
      anv_batch_emit(&batch, GENX(MI_LOAD_REGISTER_IMM), lri) {
350
 
         lri.RegisterOffset = GENX(GFX_AUX_TABLE_BASE_ADDR_num) + 4;
351
 
         lri.DataDWord = aux_base_addr >> 32;
352
 
      }
353
 
   }
354
 
#endif
355
 
 
356
 
   /* Set the "CONSTANT_BUFFER Address Offset Disable" bit, so
357
 
    * 3DSTATE_CONSTANT_XS buffer 0 is an absolute address.
358
 
    *
359
 
    * This is only safe on kernels with context isolation support.
360
 
    */
361
 
   if (GFX_VER >= 8 && device->physical->has_context_isolation) {
362
 
#if GFX_VER >= 9
363
 
      anv_batch_write_reg(&batch, GENX(CS_DEBUG_MODE2), csdm2) {
364
 
         csdm2.CONSTANT_BUFFERAddressOffsetDisable = true;
365
 
         csdm2.CONSTANT_BUFFERAddressOffsetDisableMask = true;
366
 
      }
367
 
#elif GFX_VER == 8
368
 
      anv_batch_write_reg(&batch, GENX(INSTPM), instpm) {
369
 
         instpm.CONSTANT_BUFFERAddressOffsetDisable = true;
370
 
         instpm.CONSTANT_BUFFERAddressOffsetDisableMask = true;
371
 
      }
372
 
#endif
373
 
   }
374
 
 
375
 
#if GFX_VER >= 11
376
 
   /* Starting with GFX version 11, SLM is no longer part of the L3$ config
377
 
    * so it never changes throughout the lifetime of the VkDevice.
378
 
    */
379
 
   const struct intel_l3_config *cfg = intel_get_default_l3_config(&device->info);
380
 
   genX(emit_l3_config)(&batch, device, cfg);
381
 
   device->l3_config = cfg;
382
 
#endif
383
 
 
384
 
   anv_batch_emit(&batch, GENX(MI_BATCH_BUFFER_END), bbe);
385
 
 
386
 
   assert(batch.next <= batch.end);
387
 
 
388
 
   return anv_queue_submit_simple_batch(queue, &batch);
389
 
}
390
 
 
391
 
void
392
 
genX(init_physical_device_state)(ASSERTED struct anv_physical_device *device)
393
 
{
394
 
   assert(device->info.verx10 == GFX_VERx10);
395
 
}
396
 
 
397
 
VkResult
398
 
genX(init_device_state)(struct anv_device *device)
399
 
{
400
 
   VkResult res;
401
 
 
402
 
   device->slice_hash = (struct anv_state) { 0 };
403
 
   for (uint32_t i = 0; i < device->queue_count; i++) {
404
 
      struct anv_queue *queue = &device->queues[i];
405
 
      switch (queue->family->engine_class) {
406
 
      case I915_ENGINE_CLASS_RENDER:
407
 
         res = init_render_queue_state(queue);
408
 
         break;
409
 
      default:
410
 
         res = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
411
 
         break;
412
 
      }
413
 
      if (res != VK_SUCCESS)
414
 
         return res;
415
 
   }
416
 
 
417
 
   return res;
418
 
}
419
 
 
420
 
#if GFX_VERx10 >= 125
421
 
#define maybe_for_each_shading_rate_op(name) \
422
 
   for (VkFragmentShadingRateCombinerOpKHR name = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR; \
423
 
        name <= VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR; \
424
 
        name++)
425
 
#elif GFX_VER >= 12
426
 
#define maybe_for_each_shading_rate_op(name)
427
 
#endif
428
 
 
429
 
/* Rather than reemitting the CPS_STATE structure everything those changes and
430
 
 * for as many viewports as needed, we can just prepare all possible cases and
431
 
 * just pick the right offset from the prepacked states when needed.
432
 
 */
433
 
void
434
 
genX(init_cps_device_state)(struct anv_device *device)
435
 
{
436
 
#if GFX_VER >= 12
437
 
   void *cps_state_ptr = device->cps_states.map;
438
 
 
439
 
   /* Disabled CPS mode */
440
 
   for (uint32_t __v = 0; __v < MAX_VIEWPORTS; __v++) {
441
 
      struct GENX(CPS_STATE) cps_state = {
442
 
         .CoarsePixelShadingMode = CPS_MODE_CONSTANT,
443
 
         .MinCPSizeX = 1,
444
 
         .MinCPSizeY = 1,
445
 
#if GFX_VERx10 >= 125
446
 
         .Combiner0OpcodeforCPsize = PASSTHROUGH,
447
 
         .Combiner1OpcodeforCPsize = PASSTHROUGH,
448
 
#endif /* GFX_VERx10 >= 125 */
449
 
 
450
 
      };
451
 
 
452
 
      GENX(CPS_STATE_pack)(NULL, cps_state_ptr, &cps_state);
453
 
      cps_state_ptr += GENX(CPS_STATE_length) * 4;
454
 
   }
455
 
 
456
 
   maybe_for_each_shading_rate_op(op0) {
457
 
      maybe_for_each_shading_rate_op(op1) {
458
 
         for (uint32_t x = 1; x <= 4; x *= 2) {
459
 
            for (uint32_t y = 1; y <= 4; y *= 2) {
460
 
               struct GENX(CPS_STATE) cps_state = {
461
 
                  .CoarsePixelShadingMode = CPS_MODE_CONSTANT,
462
 
                  .MinCPSizeX = x,
463
 
                  .MinCPSizeY = y,
464
 
               };
465
 
 
466
 
#if GFX_VERx10 >= 125
467
 
               static const uint32_t combiner_ops[] = {
468
 
                  [VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR]    = PASSTHROUGH,
469
 
                  [VK_FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_KHR] = OVERRIDE,
470
 
                  [VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_KHR]     = HIGH_QUALITY,
471
 
                  [VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_KHR]     = LOW_QUALITY,
472
 
                  [VK_FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_KHR]     = RELATIVE,
473
 
               };
474
 
 
475
 
               cps_state.Combiner0OpcodeforCPsize = combiner_ops[op0];
476
 
               cps_state.Combiner1OpcodeforCPsize = combiner_ops[op1];
477
 
#endif /* GFX_VERx10 >= 125 */
478
 
 
479
 
               for (uint32_t __v = 0; __v < MAX_VIEWPORTS; __v++) {
480
 
                  GENX(CPS_STATE_pack)(NULL, cps_state_ptr, &cps_state);
481
 
                  cps_state_ptr += GENX(CPS_STATE_length) * 4;
482
 
               }
483
 
            }
484
 
         }
485
 
      }
486
 
   }
487
 
#endif /* GFX_VER >= 12 */
488
 
}
489
 
 
490
 
#if GFX_VER >= 12
491
 
static uint32_t
492
 
get_cps_state_offset(struct anv_device *device, bool cps_enabled,
493
 
                     const struct anv_dynamic_state *d)
494
 
{
495
 
   if (!cps_enabled)
496
 
      return device->cps_states.offset;
497
 
 
498
 
   uint32_t offset;
499
 
   static const uint32_t size_index[] = {
500
 
      [1] = 0,
501
 
      [2] = 1,
502
 
      [4] = 2,
503
 
   };
504
 
 
505
 
#if GFX_VERx10 >= 125
506
 
   offset =
507
 
      1 + /* skip disabled */
508
 
      d->fragment_shading_rate.ops[0] * 5 * 3 * 3 +
509
 
      d->fragment_shading_rate.ops[1] * 3 * 3 +
510
 
      size_index[d->fragment_shading_rate.rate.width] * 3 +
511
 
      size_index[d->fragment_shading_rate.rate.height];
512
 
#else
513
 
   offset =
514
 
      1 + /* skip disabled */
515
 
      size_index[d->fragment_shading_rate.rate.width] * 3 +
516
 
      size_index[d->fragment_shading_rate.rate.height];
517
 
#endif
518
 
 
519
 
   offset *= MAX_VIEWPORTS * GENX(CPS_STATE_length) * 4;
520
 
 
521
 
   return device->cps_states.offset + offset;
522
 
}
523
 
#endif /* GFX_VER >= 12 */
524
 
 
525
 
void
526
 
genX(emit_l3_config)(struct anv_batch *batch,
527
 
                     const struct anv_device *device,
528
 
                     const struct intel_l3_config *cfg)
529
 
{
530
 
   UNUSED const struct intel_device_info *devinfo = &device->info;
531
 
 
532
 
#if GFX_VER >= 8
533
 
 
534
 
#if GFX_VER >= 12
535
 
#define L3_ALLOCATION_REG GENX(L3ALLOC)
536
 
#define L3_ALLOCATION_REG_num GENX(L3ALLOC_num)
537
 
#else
538
 
#define L3_ALLOCATION_REG GENX(L3CNTLREG)
539
 
#define L3_ALLOCATION_REG_num GENX(L3CNTLREG_num)
540
 
#endif
541
 
 
542
 
   anv_batch_write_reg(batch, L3_ALLOCATION_REG, l3cr) {
543
 
      if (cfg == NULL) {
544
 
#if GFX_VER >= 12
545
 
         l3cr.L3FullWayAllocationEnable = true;
546
 
#else
547
 
         unreachable("Invalid L3$ config");
548
 
#endif
549
 
      } else {
550
 
#if GFX_VER < 11
551
 
         l3cr.SLMEnable = cfg->n[INTEL_L3P_SLM];
552
 
#endif
553
 
#if GFX_VER == 11
554
 
         /* Wa_1406697149: Bit 9 "Error Detection Behavior Control" must be
555
 
          * set in L3CNTLREG register. The default setting of the bit is not
556
 
          * the desirable behavior.
557
 
          */
558
 
         l3cr.ErrorDetectionBehaviorControl = true;
559
 
         l3cr.UseFullWays = true;
560
 
#endif /* GFX_VER == 11 */
561
 
         assert(cfg->n[INTEL_L3P_IS] == 0);
562
 
         assert(cfg->n[INTEL_L3P_C] == 0);
563
 
         assert(cfg->n[INTEL_L3P_T] == 0);
564
 
         l3cr.URBAllocation = cfg->n[INTEL_L3P_URB];
565
 
         l3cr.ROAllocation = cfg->n[INTEL_L3P_RO];
566
 
         l3cr.DCAllocation = cfg->n[INTEL_L3P_DC];
567
 
         l3cr.AllAllocation = cfg->n[INTEL_L3P_ALL];
568
 
      }
569
 
   }
570
 
 
571
 
#else /* GFX_VER < 8 */
572
 
 
573
 
   const bool has_dc = cfg->n[INTEL_L3P_DC] || cfg->n[INTEL_L3P_ALL];
574
 
   const bool has_is = cfg->n[INTEL_L3P_IS] || cfg->n[INTEL_L3P_RO] ||
575
 
                       cfg->n[INTEL_L3P_ALL];
576
 
   const bool has_c = cfg->n[INTEL_L3P_C] || cfg->n[INTEL_L3P_RO] ||
577
 
                      cfg->n[INTEL_L3P_ALL];
578
 
   const bool has_t = cfg->n[INTEL_L3P_T] || cfg->n[INTEL_L3P_RO] ||
579
 
                      cfg->n[INTEL_L3P_ALL];
580
 
 
581
 
   assert(!cfg->n[INTEL_L3P_ALL]);
582
 
 
583
 
   /* When enabled SLM only uses a portion of the L3 on half of the banks,
584
 
    * the matching space on the remaining banks has to be allocated to a
585
 
    * client (URB for all validated configurations) set to the
586
 
    * lower-bandwidth 2-bank address hashing mode.
587
 
    */
588
 
   const bool urb_low_bw = cfg->n[INTEL_L3P_SLM] && devinfo->platform != INTEL_PLATFORM_BYT;
589
 
   assert(!urb_low_bw || cfg->n[INTEL_L3P_URB] == cfg->n[INTEL_L3P_SLM]);
590
 
 
591
 
   /* Minimum number of ways that can be allocated to the URB. */
592
 
   const unsigned n0_urb = devinfo->platform == INTEL_PLATFORM_BYT ? 32 : 0;
593
 
   assert(cfg->n[INTEL_L3P_URB] >= n0_urb);
594
 
 
595
 
   anv_batch_write_reg(batch, GENX(L3SQCREG1), l3sqc) {
596
 
      l3sqc.ConvertDC_UC = !has_dc;
597
 
      l3sqc.ConvertIS_UC = !has_is;
598
 
      l3sqc.ConvertC_UC = !has_c;
599
 
      l3sqc.ConvertT_UC = !has_t;
600
 
#if GFX_VERx10 == 75
601
 
      l3sqc.L3SQGeneralPriorityCreditInitialization = SQGPCI_DEFAULT;
602
 
#else
603
 
      l3sqc.L3SQGeneralPriorityCreditInitialization =
604
 
         devinfo->platform == INTEL_PLATFORM_BYT ? BYT_SQGPCI_DEFAULT : SQGPCI_DEFAULT;
605
 
#endif
606
 
      l3sqc.L3SQHighPriorityCreditInitialization = SQHPCI_DEFAULT;
607
 
   }
608
 
 
609
 
   anv_batch_write_reg(batch, GENX(L3CNTLREG2), l3cr2) {
610
 
      l3cr2.SLMEnable = cfg->n[INTEL_L3P_SLM];
611
 
      l3cr2.URBLowBandwidth = urb_low_bw;
612
 
      l3cr2.URBAllocation = cfg->n[INTEL_L3P_URB] - n0_urb;
613
 
#if !GFX_VERx10 == 75
614
 
      l3cr2.ALLAllocation = cfg->n[INTEL_L3P_ALL];
615
 
#endif
616
 
      l3cr2.ROAllocation = cfg->n[INTEL_L3P_RO];
617
 
      l3cr2.DCAllocation = cfg->n[INTEL_L3P_DC];
618
 
   }
619
 
 
620
 
   anv_batch_write_reg(batch, GENX(L3CNTLREG3), l3cr3) {
621
 
      l3cr3.ISAllocation = cfg->n[INTEL_L3P_IS];
622
 
      l3cr3.ISLowBandwidth = 0;
623
 
      l3cr3.CAllocation = cfg->n[INTEL_L3P_C];
624
 
      l3cr3.CLowBandwidth = 0;
625
 
      l3cr3.TAllocation = cfg->n[INTEL_L3P_T];
626
 
      l3cr3.TLowBandwidth = 0;
627
 
   }
628
 
 
629
 
#if GFX_VERx10 == 75
630
 
   if (device->physical->cmd_parser_version >= 4) {
631
 
      /* Enable L3 atomics on HSW if we have a DC partition, otherwise keep
632
 
       * them disabled to avoid crashing the system hard.
633
 
       */
634
 
      anv_batch_write_reg(batch, GENX(SCRATCH1), s1) {
635
 
         s1.L3AtomicDisable = !has_dc;
636
 
      }
637
 
      anv_batch_write_reg(batch, GENX(CHICKEN3), c3) {
638
 
         c3.L3AtomicDisableMask = true;
639
 
         c3.L3AtomicDisable = !has_dc;
640
 
      }
641
 
   }
642
 
#endif /* GFX_VERx10 == 75 */
643
 
 
644
 
#endif /* GFX_VER < 8 */
645
 
}
646
 
 
647
 
void
648
 
genX(emit_multisample)(struct anv_batch *batch, uint32_t samples,
649
 
                       const struct intel_sample_position *positions)
650
 
{
651
 
   anv_batch_emit(batch, GENX(3DSTATE_MULTISAMPLE), ms) {
652
 
      ms.NumberofMultisamples       = __builtin_ffs(samples) - 1;
653
 
 
654
 
      ms.PixelLocation              = CENTER;
655
 
#if GFX_VER >= 8
656
 
      /* The PRM says that this bit is valid only for DX9:
657
 
       *
658
 
       *    SW can choose to set this bit only for DX9 API. DX10/OGL API's
659
 
       *    should not have any effect by setting or not setting this bit.
660
 
       */
661
 
      ms.PixelPositionOffsetEnable  = false;
662
 
#else
663
 
      switch (samples) {
664
 
      case 1:
665
 
         INTEL_SAMPLE_POS_1X_ARRAY(ms.Sample, positions);
666
 
         break;
667
 
      case 2:
668
 
         INTEL_SAMPLE_POS_2X_ARRAY(ms.Sample, positions);
669
 
         break;
670
 
      case 4:
671
 
         INTEL_SAMPLE_POS_4X_ARRAY(ms.Sample, positions);
672
 
         break;
673
 
      case 8:
674
 
         INTEL_SAMPLE_POS_8X_ARRAY(ms.Sample, positions);
675
 
         break;
676
 
      default:
677
 
            break;
678
 
      }
679
 
#endif
680
 
   }
681
 
}
682
 
 
683
 
#if GFX_VER >= 8
684
 
void
685
 
genX(emit_sample_pattern)(struct anv_batch *batch,
686
 
                          const struct anv_dynamic_state *d)
687
 
{
688
 
   /* See the Vulkan 1.0 spec Table 24.1 "Standard sample locations" and
689
 
    * VkPhysicalDeviceFeatures::standardSampleLocations.
690
 
    */
691
 
   anv_batch_emit(batch, GENX(3DSTATE_SAMPLE_PATTERN), sp) {
692
 
      /* The Skylake PRM Vol. 2a "3DSTATE_SAMPLE_PATTERN" says:
693
 
       *
694
 
       *    "When programming the sample offsets (for NUMSAMPLES_4 or _8
695
 
       *    and MSRASTMODE_xxx_PATTERN), the order of the samples 0 to 3
696
 
       *    (or 7 for 8X, or 15 for 16X) must have monotonically increasing
697
 
       *    distance from the pixel center. This is required to get the
698
 
       *    correct centroid computation in the device."
699
 
       *
700
 
       * However, the Vulkan spec seems to require that the the samples occur
701
 
       * in the order provided through the API. The standard sample patterns
702
 
       * have the above property that they have monotonically increasing
703
 
       * distances from the center but client-provided ones do not. As long as
704
 
       * this only affects centroid calculations as the docs say, we should be
705
 
       * ok because OpenGL and Vulkan only require that the centroid be some
706
 
       * lit sample and that it's the same for all samples in a pixel; they
707
 
       * have no requirement that it be the one closest to center.
708
 
       */
709
 
      if (d) {
710
 
         INTEL_SAMPLE_POS_1X_ARRAY(sp._1xSample,  d->sample_locations.locations_1);
711
 
         INTEL_SAMPLE_POS_2X_ARRAY(sp._2xSample,  d->sample_locations.locations_2);
712
 
         INTEL_SAMPLE_POS_4X_ARRAY(sp._4xSample,  d->sample_locations.locations_4);
713
 
         INTEL_SAMPLE_POS_8X_ARRAY(sp._8xSample,  d->sample_locations.locations_8);
714
 
#if GFX_VER >= 9
715
 
         INTEL_SAMPLE_POS_16X_ARRAY(sp._16xSample, d->sample_locations.locations_16);
716
 
#endif
717
 
      } else {
718
 
         INTEL_SAMPLE_POS_1X(sp._1xSample);
719
 
         INTEL_SAMPLE_POS_2X(sp._2xSample);
720
 
         INTEL_SAMPLE_POS_4X(sp._4xSample);
721
 
         INTEL_SAMPLE_POS_8X(sp._8xSample);
722
 
#if GFX_VER >= 9
723
 
         INTEL_SAMPLE_POS_16X(sp._16xSample);
724
 
#endif
725
 
      }
726
 
   }
727
 
}
728
 
#endif
729
 
 
730
 
#if GFX_VER >= 11
731
 
void
732
 
genX(emit_shading_rate)(struct anv_batch *batch,
733
 
                        const struct anv_graphics_pipeline *pipeline,
734
 
                        struct anv_dynamic_state *dynamic_state)
735
 
{
736
 
   const struct brw_wm_prog_data *wm_prog_data = get_wm_prog_data(pipeline);
737
 
   const bool cps_enable = wm_prog_data && wm_prog_data->per_coarse_pixel_dispatch;
738
 
 
739
 
#if GFX_VER == 11
740
 
   anv_batch_emit(batch, GENX(3DSTATE_CPS), cps) {
741
 
      cps.CoarsePixelShadingMode = cps_enable ? CPS_MODE_CONSTANT : CPS_MODE_NONE;
742
 
      if (cps_enable) {
743
 
         cps.MinCPSizeX = dynamic_state->fragment_shading_rate.rate.width;
744
 
         cps.MinCPSizeY = dynamic_state->fragment_shading_rate.rate.height;
745
 
      }
746
 
   }
747
 
#elif GFX_VER >= 12
748
 
   /* TODO: we can optimize this flush in the following cases:
749
 
    *
750
 
    *    In the case where the last geometry shader emits a value that is not
751
 
    *    constant, we can avoid this stall because we can synchronize the
752
 
    *    pixel shader internally with
753
 
    *    3DSTATE_PS::EnablePSDependencyOnCPsizeChange.
754
 
    *
755
 
    *    If we know that the previous pipeline and the current one are using
756
 
    *    the same fragment shading rate.
757
 
    */
758
 
   anv_batch_emit(batch, GENX(PIPE_CONTROL), pc) {
759
 
#if GFX_VERx10 >= 125
760
 
      pc.PSSStallSyncEnable = true;
761
 
#else
762
 
      pc.PSDSyncEnable = true;
763
 
#endif
764
 
   }
765
 
 
766
 
   anv_batch_emit(batch, GENX(3DSTATE_CPS_POINTERS), cps) {
767
 
      struct anv_device *device = pipeline->base.device;
768
 
 
769
 
      cps.CoarsePixelShadingStateArrayPointer =
770
 
         get_cps_state_offset(device, cps_enable, dynamic_state);
771
 
   }
772
 
#endif
773
 
}
774
 
#endif /* GFX_VER >= 11 */
775
 
 
776
 
static uint32_t
777
 
vk_to_intel_tex_filter(VkFilter filter, bool anisotropyEnable)
778
 
{
779
 
   switch (filter) {
780
 
   default:
781
 
      assert(!"Invalid filter");
782
 
   case VK_FILTER_NEAREST:
783
 
      return anisotropyEnable ? MAPFILTER_ANISOTROPIC : MAPFILTER_NEAREST;
784
 
   case VK_FILTER_LINEAR:
785
 
      return anisotropyEnable ? MAPFILTER_ANISOTROPIC : MAPFILTER_LINEAR;
786
 
   }
787
 
}
788
 
 
789
 
static uint32_t
790
 
vk_to_intel_max_anisotropy(float ratio)
791
 
{
792
 
   return (anv_clamp_f(ratio, 2, 16) - 2) / 2;
793
 
}
794
 
 
795
 
static const uint32_t vk_to_intel_mipmap_mode[] = {
796
 
   [VK_SAMPLER_MIPMAP_MODE_NEAREST]          = MIPFILTER_NEAREST,
797
 
   [VK_SAMPLER_MIPMAP_MODE_LINEAR]           = MIPFILTER_LINEAR
798
 
};
799
 
 
800
 
static const uint32_t vk_to_intel_tex_address[] = {
801
 
   [VK_SAMPLER_ADDRESS_MODE_REPEAT]          = TCM_WRAP,
802
 
   [VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT] = TCM_MIRROR,
803
 
   [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE]   = TCM_CLAMP,
804
 
   [VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE] = TCM_MIRROR_ONCE,
805
 
   [VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER] = TCM_CLAMP_BORDER,
806
 
};
807
 
 
808
 
/* Vulkan specifies the result of shadow comparisons as:
809
 
 *     1     if   ref <op> texel,
810
 
 *     0     otherwise.
811
 
 *
812
 
 * The hardware does:
813
 
 *     0     if texel <op> ref,
814
 
 *     1     otherwise.
815
 
 *
816
 
 * So, these look a bit strange because there's both a negation
817
 
 * and swapping of the arguments involved.
818
 
 */
819
 
static const uint32_t vk_to_intel_shadow_compare_op[] = {
820
 
   [VK_COMPARE_OP_NEVER]                        = PREFILTEROP_ALWAYS,
821
 
   [VK_COMPARE_OP_LESS]                         = PREFILTEROP_LEQUAL,
822
 
   [VK_COMPARE_OP_EQUAL]                        = PREFILTEROP_NOTEQUAL,
823
 
   [VK_COMPARE_OP_LESS_OR_EQUAL]                = PREFILTEROP_LESS,
824
 
   [VK_COMPARE_OP_GREATER]                      = PREFILTEROP_GEQUAL,
825
 
   [VK_COMPARE_OP_NOT_EQUAL]                    = PREFILTEROP_EQUAL,
826
 
   [VK_COMPARE_OP_GREATER_OR_EQUAL]             = PREFILTEROP_GREATER,
827
 
   [VK_COMPARE_OP_ALWAYS]                       = PREFILTEROP_NEVER,
828
 
};
829
 
 
830
 
#if GFX_VER >= 9
831
 
static const uint32_t vk_to_intel_sampler_reduction_mode[] = {
832
 
   [VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT] = STD_FILTER,
833
 
   [VK_SAMPLER_REDUCTION_MODE_MIN_EXT]              = MINIMUM,
834
 
   [VK_SAMPLER_REDUCTION_MODE_MAX_EXT]              = MAXIMUM,
835
 
};
836
 
#endif
837
 
 
838
 
VkResult genX(CreateSampler)(
839
 
    VkDevice                                    _device,
840
 
    const VkSamplerCreateInfo*                  pCreateInfo,
841
 
    const VkAllocationCallbacks*                pAllocator,
842
 
    VkSampler*                                  pSampler)
843
 
{
844
 
   ANV_FROM_HANDLE(anv_device, device, _device);
845
 
   struct anv_sampler *sampler;
846
 
 
847
 
   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
848
 
 
849
 
   sampler = vk_object_zalloc(&device->vk, pAllocator, sizeof(*sampler),
850
 
                              VK_OBJECT_TYPE_SAMPLER);
851
 
   if (!sampler)
852
 
      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
853
 
 
854
 
   sampler->n_planes = 1;
855
 
 
856
 
   uint32_t border_color_stride = GFX_VERx10 == 75 ? 512 : 64;
857
 
   uint32_t border_color_offset;
858
 
   ASSERTED bool has_custom_color = false;
859
 
   if (pCreateInfo->borderColor <= VK_BORDER_COLOR_INT_OPAQUE_WHITE) {
860
 
      border_color_offset = device->border_colors.offset +
861
 
                            pCreateInfo->borderColor *
862
 
                            border_color_stride;
863
 
   } else {
864
 
      assert(GFX_VER >= 8);
865
 
      sampler->custom_border_color =
866
 
         anv_state_reserved_pool_alloc(&device->custom_border_colors);
867
 
      border_color_offset = sampler->custom_border_color.offset;
868
 
   }
869
 
 
870
 
#if GFX_VER >= 9
871
 
   unsigned sampler_reduction_mode = STD_FILTER;
872
 
   bool enable_sampler_reduction = false;
873
 
#endif
874
 
 
875
 
   vk_foreach_struct(ext, pCreateInfo->pNext) {
876
 
      switch (ext->sType) {
877
 
      case VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO: {
878
 
         VkSamplerYcbcrConversionInfo *pSamplerConversion =
879
 
            (VkSamplerYcbcrConversionInfo *) ext;
880
 
         ANV_FROM_HANDLE(anv_ycbcr_conversion, conversion,
881
 
                         pSamplerConversion->conversion);
882
 
 
883
 
         /* Ignore conversion for non-YUV formats. This fulfills a requirement
884
 
          * for clients that want to utilize same code path for images with
885
 
          * external formats (VK_FORMAT_UNDEFINED) and "regular" RGBA images
886
 
          * where format is known.
887
 
          */
888
 
         if (conversion == NULL || !conversion->format->can_ycbcr)
889
 
            break;
890
 
 
891
 
         sampler->n_planes = conversion->format->n_planes;
892
 
         sampler->conversion = conversion;
893
 
         break;
894
 
      }
895
 
#if GFX_VER >= 9
896
 
      case VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO: {
897
 
         VkSamplerReductionModeCreateInfo *sampler_reduction =
898
 
            (VkSamplerReductionModeCreateInfo *) ext;
899
 
         sampler_reduction_mode =
900
 
            vk_to_intel_sampler_reduction_mode[sampler_reduction->reductionMode];
901
 
         enable_sampler_reduction = true;
902
 
         break;
903
 
      }
904
 
#endif
905
 
      case VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT: {
906
 
         VkSamplerCustomBorderColorCreateInfoEXT *custom_border_color =
907
 
            (VkSamplerCustomBorderColorCreateInfoEXT *) ext;
908
 
         if (sampler->custom_border_color.map == NULL)
909
 
            break;
910
 
 
911
 
         union isl_color_value color = { .u32 = {
912
 
            custom_border_color->customBorderColor.uint32[0],
913
 
            custom_border_color->customBorderColor.uint32[1],
914
 
            custom_border_color->customBorderColor.uint32[2],
915
 
            custom_border_color->customBorderColor.uint32[3],
916
 
         } };
917
 
 
918
 
         const struct anv_format *format_desc =
919
 
            custom_border_color->format != VK_FORMAT_UNDEFINED ?
920
 
            anv_get_format(custom_border_color->format) : NULL;
921
 
 
922
 
         /* For formats with a swizzle, it does not carry over to the sampler
923
 
          * for border colors, so we need to do the swizzle ourselves here.
924
 
          */
925
 
         if (format_desc && format_desc->n_planes == 1 &&
926
 
             !isl_swizzle_is_identity(format_desc->planes[0].swizzle)) {
927
 
            const struct anv_format_plane *fmt_plane = &format_desc->planes[0];
928
 
 
929
 
            assert(!isl_format_has_int_channel(fmt_plane->isl_format));
930
 
            color = isl_color_value_swizzle(color, fmt_plane->swizzle, true);
931
 
         }
932
 
 
933
 
         memcpy(sampler->custom_border_color.map, color.u32, sizeof(color));
934
 
         has_custom_color = true;
935
 
         break;
936
 
      }
937
 
      default:
938
 
         anv_debug_ignored_stype(ext->sType);
939
 
         break;
940
 
      }
941
 
   }
942
 
 
943
 
   assert((sampler->custom_border_color.map == NULL) || has_custom_color);
944
 
 
945
 
   if (device->physical->has_bindless_samplers) {
946
 
      /* If we have bindless, allocate enough samplers.  We allocate 32 bytes
947
 
       * for each sampler instead of 16 bytes because we want all bindless
948
 
       * samplers to be 32-byte aligned so we don't have to use indirect
949
 
       * sampler messages on them.
950
 
       */
951
 
      sampler->bindless_state =
952
 
         anv_state_pool_alloc(&device->dynamic_state_pool,
953
 
                              sampler->n_planes * 32, 32);
954
 
   }
955
 
 
956
 
   for (unsigned p = 0; p < sampler->n_planes; p++) {
957
 
      const bool plane_has_chroma =
958
 
         sampler->conversion && sampler->conversion->format->planes[p].has_chroma;
959
 
      const VkFilter min_filter =
960
 
         plane_has_chroma ? sampler->conversion->chroma_filter : pCreateInfo->minFilter;
961
 
      const VkFilter mag_filter =
962
 
         plane_has_chroma ? sampler->conversion->chroma_filter : pCreateInfo->magFilter;
963
 
      const bool enable_min_filter_addr_rounding = min_filter != VK_FILTER_NEAREST;
964
 
      const bool enable_mag_filter_addr_rounding = mag_filter != VK_FILTER_NEAREST;
965
 
      /* From Broadwell PRM, SAMPLER_STATE:
966
 
       *   "Mip Mode Filter must be set to MIPFILTER_NONE for Planar YUV surfaces."
967
 
       */
968
 
      const bool isl_format_is_planar_yuv = sampler->conversion &&
969
 
         isl_format_is_yuv(sampler->conversion->format->planes[0].isl_format) &&
970
 
         isl_format_is_planar(sampler->conversion->format->planes[0].isl_format);
971
 
 
972
 
      const uint32_t mip_filter_mode =
973
 
         isl_format_is_planar_yuv ?
974
 
         MIPFILTER_NONE : vk_to_intel_mipmap_mode[pCreateInfo->mipmapMode];
975
 
 
976
 
      struct GENX(SAMPLER_STATE) sampler_state = {
977
 
         .SamplerDisable = false,
978
 
         .TextureBorderColorMode = DX10OGL,
979
 
 
980
 
#if GFX_VER >= 11
981
 
         .CPSLODCompensationEnable = true,
982
 
#endif
983
 
 
984
 
#if GFX_VER >= 8
985
 
         .LODPreClampMode = CLAMP_MODE_OGL,
986
 
#else
987
 
         .LODPreClampEnable = CLAMP_ENABLE_OGL,
988
 
#endif
989
 
 
990
 
#if GFX_VER == 8
991
 
         .BaseMipLevel = 0.0,
992
 
#endif
993
 
         .MipModeFilter = mip_filter_mode,
994
 
         .MagModeFilter = vk_to_intel_tex_filter(mag_filter, pCreateInfo->anisotropyEnable),
995
 
         .MinModeFilter = vk_to_intel_tex_filter(min_filter, pCreateInfo->anisotropyEnable),
996
 
         .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16, 15.996),
997
 
         .AnisotropicAlgorithm =
998
 
            pCreateInfo->anisotropyEnable ? EWAApproximation : LEGACY,
999
 
         .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14),
1000
 
         .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14),
1001
 
         .ChromaKeyEnable = 0,
1002
 
         .ChromaKeyIndex = 0,
1003
 
         .ChromaKeyMode = 0,
1004
 
         .ShadowFunction =
1005
 
            vk_to_intel_shadow_compare_op[pCreateInfo->compareEnable ?
1006
 
                                        pCreateInfo->compareOp : VK_COMPARE_OP_NEVER],
1007
 
         .CubeSurfaceControlMode = OVERRIDE,
1008
 
 
1009
 
         .BorderColorPointer = border_color_offset,
1010
 
 
1011
 
#if GFX_VER >= 8
1012
 
         .LODClampMagnificationMode = MIPNONE,
1013
 
#endif
1014
 
 
1015
 
         .MaximumAnisotropy = vk_to_intel_max_anisotropy(pCreateInfo->maxAnisotropy),
1016
 
         .RAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
1017
 
         .RAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
1018
 
         .VAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
1019
 
         .VAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
1020
 
         .UAddressMinFilterRoundingEnable = enable_min_filter_addr_rounding,
1021
 
         .UAddressMagFilterRoundingEnable = enable_mag_filter_addr_rounding,
1022
 
         .TrilinearFilterQuality = 0,
1023
 
         .NonnormalizedCoordinateEnable = pCreateInfo->unnormalizedCoordinates,
1024
 
         .TCXAddressControlMode = vk_to_intel_tex_address[pCreateInfo->addressModeU],
1025
 
         .TCYAddressControlMode = vk_to_intel_tex_address[pCreateInfo->addressModeV],
1026
 
         .TCZAddressControlMode = vk_to_intel_tex_address[pCreateInfo->addressModeW],
1027
 
 
1028
 
#if GFX_VER >= 9
1029
 
         .ReductionType = sampler_reduction_mode,
1030
 
         .ReductionTypeEnable = enable_sampler_reduction,
1031
 
#endif
1032
 
      };
1033
 
 
1034
 
      GENX(SAMPLER_STATE_pack)(NULL, sampler->state[p], &sampler_state);
1035
 
 
1036
 
      if (sampler->bindless_state.map) {
1037
 
         memcpy(sampler->bindless_state.map + p * 32,
1038
 
                sampler->state[p], GENX(SAMPLER_STATE_length) * 4);
1039
 
      }
1040
 
   }
1041
 
 
1042
 
   *pSampler = anv_sampler_to_handle(sampler);
1043
 
 
1044
 
   return VK_SUCCESS;
1045
 
}