iris_blorp.c 13.4 KB
Newer Older
Kenneth Graunke's avatar
Kenneth Graunke committed
1
2
3
4
5
6
/*
 * Copyright © 2018 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
7
8
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
Kenneth Graunke's avatar
Kenneth Graunke committed
10
 *
11
12
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
Kenneth Graunke's avatar
Kenneth Graunke committed
13
 *
14
15
16
17
18
19
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
Kenneth Graunke's avatar
Kenneth Graunke committed
21
 */
Kenneth Graunke's avatar
Kenneth Graunke committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/**
 * @file iris_blorp.c
 *
 * ============================= GENXML CODE =============================
 *              [This file is compiled once per generation.]
 * =======================================================================
 *
 * GenX specific code for working with BLORP (blitting, resolves, clears
 * on the 3D engine).  This provides the driver-specific hooks needed to
 * implement the BLORP API.
 *
 * See iris_blit.c, iris_clear.c, and so on.
 */

Kenneth Graunke's avatar
Kenneth Graunke committed
37
38
39
40
41
42
#include <assert.h>

#include "iris_batch.h"
#include "iris_resource.h"
#include "iris_context.h"

Kenneth Graunke's avatar
Kenneth Graunke committed
43
#include "util/u_upload_mgr.h"
Kenneth Graunke's avatar
Kenneth Graunke committed
44
#include "intel/common/gen_l3_config.h"
Kenneth Graunke's avatar
Kenneth Graunke committed
45

Kenneth Graunke's avatar
Kenneth Graunke committed
46
47
48
49
50
51
52
53
#include "blorp/blorp_genX_exec.h"

static uint32_t *
stream_state(struct iris_batch *batch,
             struct u_upload_mgr *uploader,
             unsigned size,
             unsigned alignment,
             uint32_t *out_offset,
Kenneth Graunke's avatar
Kenneth Graunke committed
54
             struct iris_bo **out_bo)
Kenneth Graunke's avatar
Kenneth Graunke committed
55
56
57
58
59
60
{
   struct pipe_resource *res = NULL;
   void *ptr = NULL;

   u_upload_alloc(uploader, 0, size, alignment, out_offset, &res, &ptr);

Kenneth Graunke's avatar
Kenneth Graunke committed
61
   struct iris_bo *bo = iris_resource_bo(res);
62
   iris_use_pinned_bo(batch, bo, false, IRIS_DOMAIN_NONE);
Kenneth Graunke's avatar
Kenneth Graunke committed
63

64
65
66
   iris_record_state_size(batch->state_sizes,
                          bo->gtt_offset + *out_offset, size);

Kenneth Graunke's avatar
Kenneth Graunke committed
67
68
69
70
71
72
73
74
   /* If the caller has asked for a BO, we leave them the responsibility of
    * adding bo->gtt_offset (say, by handing an address to genxml).  If not,
    * we assume they want the offset from a base address.
    */
   if (out_bo)
      *out_bo = bo;
   else
      *out_offset += iris_bo_offset_from_base_address(bo);
Kenneth Graunke's avatar
Kenneth Graunke committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88

   pipe_resource_reference(&res, NULL);

   return ptr;
}

static void *
blorp_emit_dwords(struct blorp_batch *blorp_batch, unsigned n)
{
   struct iris_batch *batch = blorp_batch->driver_batch;
   return iris_get_command_space(batch, n * sizeof(uint32_t));
}

static uint64_t
89
90
combine_and_pin_address(struct blorp_batch *blorp_batch,
                        struct blorp_address addr)
Kenneth Graunke's avatar
Kenneth Graunke committed
91
92
93
94
{
   struct iris_batch *batch = blorp_batch->driver_batch;
   struct iris_bo *bo = addr.buffer;

95
96
   iris_use_pinned_bo(batch, bo, addr.reloc_flags & RELOC_WRITE,
                      IRIS_DOMAIN_NONE);
Kenneth Graunke's avatar
Kenneth Graunke committed
97

98
99
100
101
102
103
104
105
106
   /* Assume this is a general address, not relative to a base. */
   return bo->gtt_offset + addr.offset;
}

static uint64_t
blorp_emit_reloc(struct blorp_batch *blorp_batch, UNUSED void *location,
                 struct blorp_address addr, uint32_t delta)
{
   return combine_and_pin_address(blorp_batch, addr) + delta;
Kenneth Graunke's avatar
Kenneth Graunke committed
107
108
109
110
111
112
}

static void
blorp_surface_reloc(struct blorp_batch *blorp_batch, uint32_t ss_offset,
                    struct blorp_address addr, uint32_t delta)
{
113
114
115
116
117
118
119
120
   /* Let blorp_get_surface_address do the pinning. */
}

static uint64_t
blorp_get_surface_address(struct blorp_batch *blorp_batch,
                          struct blorp_address addr)
{
   return combine_and_pin_address(blorp_batch, addr);
Kenneth Graunke's avatar
Kenneth Graunke committed
121
122
123
124
125
}

UNUSED static struct blorp_address
blorp_get_surface_base_address(UNUSED struct blorp_batch *blorp_batch)
{
126
   return (struct blorp_address) { .offset = IRIS_MEMZONE_BINDER_START };
Kenneth Graunke's avatar
Kenneth Graunke committed
127
128
129
130
131
132
133
134
135
136
137
138
}

static void *
blorp_alloc_dynamic_state(struct blorp_batch *blorp_batch,
                          uint32_t size,
                          uint32_t alignment,
                          uint32_t *offset)
{
   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
   struct iris_batch *batch = blorp_batch->driver_batch;

   return stream_state(batch, ice->state.dynamic_uploader,
Kenneth Graunke's avatar
Kenneth Graunke committed
139
                       size, alignment, offset, NULL);
Kenneth Graunke's avatar
Kenneth Graunke committed
140
141
142
143
144
145
146
147
148
149
150
151
}

static void
blorp_alloc_binding_table(struct blorp_batch *blorp_batch,
                          unsigned num_entries,
                          unsigned state_size,
                          unsigned state_alignment,
                          uint32_t *bt_offset,
                          uint32_t *surface_offsets,
                          void **surface_maps)
{
   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
152
   struct iris_binder *binder = &ice->state.binder;
Kenneth Graunke's avatar
Kenneth Graunke committed
153
154
   struct iris_batch *batch = blorp_batch->driver_batch;

155
156
   *bt_offset = iris_binder_reserve(ice, num_entries * sizeof(uint32_t));
   uint32_t *bt_map = binder->map + *bt_offset;
Kenneth Graunke's avatar
Kenneth Graunke committed
157
158
159
160

   for (unsigned i = 0; i < num_entries; i++) {
      surface_maps[i] = stream_state(batch, ice->state.surface_uploader,
                                     state_size, state_alignment,
Kenneth Graunke's avatar
Kenneth Graunke committed
161
                                     &surface_offsets[i], NULL);
162
      bt_map[i] = surface_offsets[i] - (uint32_t) binder->bo->gtt_offset;
Kenneth Graunke's avatar
Kenneth Graunke committed
163
   }
164

165
   iris_use_pinned_bo(batch, binder->bo, false, IRIS_DOMAIN_NONE);
166

167
   batch->screen->vtbl.update_surface_base_address(batch, binder);
Kenneth Graunke's avatar
Kenneth Graunke committed
168
169
170
171
172
173
174
175
176
177
178
179
180
}

static void *
blorp_alloc_vertex_buffer(struct blorp_batch *blorp_batch,
                          uint32_t size,
                          struct blorp_address *addr)
{
   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
   struct iris_batch *batch = blorp_batch->driver_batch;
   struct iris_bo *bo;
   uint32_t offset;

   void *map = stream_state(batch, ice->ctx.stream_uploader, size, 64,
Kenneth Graunke's avatar
Kenneth Graunke committed
181
                            &offset, &bo);
Kenneth Graunke's avatar
Kenneth Graunke committed
182
183
184
185

   *addr = (struct blorp_address) {
      .buffer = bo,
      .offset = offset,
186
187
      .mocs = iris_mocs(bo, &batch->screen->isl_dev,
                        ISL_SURF_USAGE_VERTEX_BUFFER_BIT),
Kenneth Graunke's avatar
Kenneth Graunke committed
188
189
190
191
192
   };

   return map;
}

193
/**
194
195
 * See iris_upload_render_state's IRIS_DIRTY_VERTEX_BUFFERS handling for
 * a comment about why these VF invalidations are needed.
196
197
 */
static void
198
blorp_vf_invalidate_for_vb_48b_transitions(struct blorp_batch *blorp_batch,
199
                                           const struct blorp_address *addrs,
200
                                           UNUSED uint32_t *sizes,
201
202
                                           unsigned num_vbs)
{
203
#if GEN_GEN < 11
204
205
206
207
208
209
   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
   struct iris_batch *batch = blorp_batch->driver_batch;
   bool need_invalidate = false;

   for (unsigned i = 0; i < num_vbs; i++) {
      struct iris_bo *bo = addrs[i].buffer;
210
      uint16_t high_bits = bo->gtt_offset >> 32u;
211

212
      if (high_bits != ice->state.last_vbo_high_bits[i]) {
213
214
215
216
217
218
         need_invalidate = true;
         ice->state.last_vbo_high_bits[i] = high_bits;
      }
   }

   if (need_invalidate) {
219
220
221
222
      iris_emit_pipe_control_flush(batch,
                                   "workaround: VF cache 32-bit key [blorp]",
                                   PIPE_CONTROL_VF_CACHE_INVALIDATE |
                                   PIPE_CONTROL_CS_STALL);
223
   }
224
#endif
225
226
}

Kenneth Graunke's avatar
Kenneth Graunke committed
227
static struct blorp_address
228
blorp_get_workaround_address(struct blorp_batch *blorp_batch)
Kenneth Graunke's avatar
Kenneth Graunke committed
229
230
231
{
   struct iris_batch *batch = blorp_batch->driver_batch;

232
233
234
235
   return (struct blorp_address) {
      .buffer = batch->screen->workaround_address.bo,
      .offset = batch->screen->workaround_address.offset,
   };
Kenneth Graunke's avatar
Kenneth Graunke committed
236
237
238
239
240
241
242
243
244
245
246
247
}

static void
blorp_flush_range(UNUSED struct blorp_batch *blorp_batch,
                  UNUSED void *start,
                  UNUSED size_t size)
{
   /* All allocated states come from the batch which we will flush before we
    * submit it.  There's nothing for us to do here.
    */
}

248
249
static const struct gen_l3_config *
blorp_get_l3_config(struct blorp_batch *blorp_batch)
Kenneth Graunke's avatar
Kenneth Graunke committed
250
{
Kenneth Graunke's avatar
Kenneth Graunke committed
251
   struct iris_batch *batch = blorp_batch->driver_batch;
252
   return batch->screen->l3_config_3d;
Kenneth Graunke's avatar
Kenneth Graunke committed
253
254
255
256
257
258
259
260
261
}

static void
iris_blorp_exec(struct blorp_batch *blorp_batch,
                const struct blorp_params *params)
{
   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
   struct iris_batch *batch = blorp_batch->driver_batch;

262
263
264
265
266
267
268
269
270
271
#if GEN_GEN >= 11
   /* The PIPE_CONTROL command description says:
    *
    *    "Whenever a Binding Table Index (BTI) used by a Render Target Message
    *     points to a different RENDER_SURFACE_STATE, SW must issue a Render
    *     Target Cache Flush by enabling this bit. When render target flush
    *     is set due to new association of BTI, PS Scoreboard Stall bit must
    *     be set in this packet."
    */
   iris_emit_pipe_control_flush(batch,
272
                                "workaround: RT BTI change [blorp]",
273
274
275
276
                                PIPE_CONTROL_RENDER_TARGET_FLUSH |
                                PIPE_CONTROL_STALL_AT_SCOREBOARD);
#endif

277
278
279
280
281
   /* Flush the render cache in cases where the same surface is reinterpreted
    * with a differernt format, which blorp does for stencil and depth data
    * among other things.  Invalidation of sampler caches and flushing of any
    * caches which had previously written the source surfaces should already
    * have been handled by the caller.
Kenneth Graunke's avatar
Kenneth Graunke committed
282
283
284
285
286
287
288
289
290
    */
   if (params->dst.enabled) {
      iris_cache_flush_for_render(batch, params->dst.addr.buffer,
                                  params->dst.view.format,
                                  params->dst.aux_usage);
   }

   iris_require_command_space(batch, 1400);

291
292
293
294
#if GEN_GEN == 8
   genX(update_pma_fix)(ice, batch, false);
#endif

295
296
297
298
299
300
   const unsigned scale = params->fast_clear_op ? UINT_MAX : 1;
   if (ice->state.current_hash_scale != scale) {
      genX(emit_hashing_mode)(ice, batch, params->x1 - params->x0,
                              params->y1 - params->y0, scale);
   }

301
#if GEN_GEN >= 12
302
   genX(invalidate_aux_map_state)(batch);
303
304
#endif

305
306
   iris_handle_always_flush_cache(batch);

Kenneth Graunke's avatar
Kenneth Graunke committed
307
308
   blorp_exec(blorp_batch, params);

309
310
   iris_handle_always_flush_cache(batch);

Kenneth Graunke's avatar
Kenneth Graunke committed
311
312
313
   /* We've smashed all state compared to what the normal 3D pipeline
    * rendering tracks for GL.
    */
314
315

   uint64_t skip_bits = (IRIS_DIRTY_POLYGON_STIPPLE |
316
317
                         IRIS_DIRTY_SO_BUFFERS |
                         IRIS_DIRTY_SO_DECL_LIST |
318
319
320
321
                         IRIS_DIRTY_LINE_STIPPLE |
                         IRIS_ALL_DIRTY_FOR_COMPUTE |
                         IRIS_DIRTY_SCISSOR_RECT |
                         IRIS_DIRTY_VF |
322
323
324
325
326
327
328
329
330
331
332
                         IRIS_DIRTY_SF_CL_VIEWPORT);
   uint64_t skip_stage_bits = (IRIS_ALL_STAGE_DIRTY_FOR_COMPUTE |
                               IRIS_STAGE_DIRTY_UNCOMPILED_VS |
                               IRIS_STAGE_DIRTY_UNCOMPILED_TCS |
                               IRIS_STAGE_DIRTY_UNCOMPILED_TES |
                               IRIS_STAGE_DIRTY_UNCOMPILED_GS |
                               IRIS_STAGE_DIRTY_UNCOMPILED_FS |
                               IRIS_STAGE_DIRTY_SAMPLER_STATES_VS |
                               IRIS_STAGE_DIRTY_SAMPLER_STATES_TCS |
                               IRIS_STAGE_DIRTY_SAMPLER_STATES_TES |
                               IRIS_STAGE_DIRTY_SAMPLER_STATES_GS);
333

334
335
   if (!ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL]) {
      /* BLORP disabled tessellation, that's fine for the next draw */
336
337
338
339
340
341
      skip_stage_bits |= IRIS_STAGE_DIRTY_TCS |
                         IRIS_STAGE_DIRTY_TES |
                         IRIS_STAGE_DIRTY_CONSTANTS_TCS |
                         IRIS_STAGE_DIRTY_CONSTANTS_TES |
                         IRIS_STAGE_DIRTY_BINDINGS_TCS |
                         IRIS_STAGE_DIRTY_BINDINGS_TES;
342
343
344
345
   }

   if (!ice->shaders.uncompiled[MESA_SHADER_GEOMETRY]) {
      /* BLORP disabled geometry shaders, that's fine for the next draw */
346
347
348
      skip_stage_bits |= IRIS_STAGE_DIRTY_GS |
                         IRIS_STAGE_DIRTY_CONSTANTS_GS |
                         IRIS_STAGE_DIRTY_BINDINGS_GS;
349
350
   }

351
352
353
354
355
356
357
358
359
360
   /* we can skip flagging IRIS_DIRTY_DEPTH_BUFFER, if
    * BLORP_BATCH_NO_EMIT_DEPTH_STENCIL is set.
    */
   if (blorp_batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL)
      skip_bits |= IRIS_DIRTY_DEPTH_BUFFER;

   if (!params->wm_prog_data)
      skip_bits |= IRIS_DIRTY_BLEND_STATE | IRIS_DIRTY_PS_BLEND;

   ice->state.dirty |= ~skip_bits;
361
   ice->state.stage_dirty |= ~skip_stage_bits;
Kenneth Graunke's avatar
Kenneth Graunke committed
362

363
364
365
366
367
368
369
370
371
372
373
374
   if (params->src.enabled)
      iris_bo_bump_seqno(params->src.addr.buffer, batch->next_seqno,
                         IRIS_DOMAIN_OTHER_READ);
   if (params->dst.enabled)
      iris_bo_bump_seqno(params->dst.addr.buffer, batch->next_seqno,
                         IRIS_DOMAIN_RENDER_WRITE);
   if (params->depth.enabled)
      iris_bo_bump_seqno(params->depth.addr.buffer, batch->next_seqno,
                         IRIS_DOMAIN_DEPTH_WRITE);
   if (params->stencil.enabled)
      iris_bo_bump_seqno(params->stencil.addr.buffer, batch->next_seqno,
                         IRIS_DOMAIN_DEPTH_WRITE);
Kenneth Graunke's avatar
Kenneth Graunke committed
375
376
377
378
379
}

void
genX(init_blorp)(struct iris_context *ice)
{
380
381
382
383
   struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;

   blorp_init(&ice->blorp, ice, &screen->isl_dev);
   ice->blorp.compiler = screen->compiler;
Kenneth Graunke's avatar
Kenneth Graunke committed
384
385
386
   ice->blorp.lookup_shader = iris_blorp_lookup_shader;
   ice->blorp.upload_shader = iris_blorp_upload_shader;
   ice->blorp.exec = iris_blorp_exec;
Kenneth Graunke's avatar
Kenneth Graunke committed
387
}