1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2018 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
12bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
21bf215546Sopenharmony_ci */
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ci/**
24bf215546Sopenharmony_ci * @file iris_blorp.c
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci * ============================= GENXML CODE =============================
27bf215546Sopenharmony_ci *              [This file is compiled once per generation.]
28bf215546Sopenharmony_ci * =======================================================================
29bf215546Sopenharmony_ci *
30bf215546Sopenharmony_ci * GenX specific code for working with BLORP (blitting, resolves, clears
31bf215546Sopenharmony_ci * on the 3D engine).  This provides the driver-specific hooks needed to
32bf215546Sopenharmony_ci * implement the BLORP API.
33bf215546Sopenharmony_ci *
34bf215546Sopenharmony_ci * See iris_blit.c, iris_clear.c, and so on.
35bf215546Sopenharmony_ci */
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include <assert.h>
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "iris_batch.h"
40bf215546Sopenharmony_ci#include "iris_resource.h"
41bf215546Sopenharmony_ci#include "iris_context.h"
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci#include "util/u_upload_mgr.h"
44bf215546Sopenharmony_ci#include "intel/common/intel_l3_config.h"
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci#include "blorp/blorp_genX_exec.h"
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_cistatic uint32_t *
49bf215546Sopenharmony_cistream_state(struct iris_batch *batch,
50bf215546Sopenharmony_ci             struct u_upload_mgr *uploader,
51bf215546Sopenharmony_ci             unsigned size,
52bf215546Sopenharmony_ci             unsigned alignment,
53bf215546Sopenharmony_ci             uint32_t *out_offset,
54bf215546Sopenharmony_ci             struct iris_bo **out_bo)
55bf215546Sopenharmony_ci{
56bf215546Sopenharmony_ci   struct pipe_resource *res = NULL;
57bf215546Sopenharmony_ci   void *ptr = NULL;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   u_upload_alloc(uploader, 0, size, alignment, out_offset, &res, &ptr);
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   struct iris_bo *bo = iris_resource_bo(res);
62bf215546Sopenharmony_ci   iris_use_pinned_bo(batch, bo, false, IRIS_DOMAIN_NONE);
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   iris_record_state_size(batch->state_sizes,
65bf215546Sopenharmony_ci                          bo->address + *out_offset, size);
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   /* If the caller has asked for a BO, we leave them the responsibility of
68bf215546Sopenharmony_ci    * adding bo->address (say, by handing an address to genxml).  If not,
69bf215546Sopenharmony_ci    * we assume they want the offset from a base address.
70bf215546Sopenharmony_ci    */
71bf215546Sopenharmony_ci   if (out_bo)
72bf215546Sopenharmony_ci      *out_bo = bo;
73bf215546Sopenharmony_ci   else
74bf215546Sopenharmony_ci      *out_offset += iris_bo_offset_from_base_address(bo);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   pipe_resource_reference(&res, NULL);
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   return ptr;
79bf215546Sopenharmony_ci}
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_cistatic void *
82bf215546Sopenharmony_ciblorp_emit_dwords(struct blorp_batch *blorp_batch, unsigned n)
83bf215546Sopenharmony_ci{
84bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
85bf215546Sopenharmony_ci   return iris_get_command_space(batch, n * sizeof(uint32_t));
86bf215546Sopenharmony_ci}
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_cistatic uint64_t
89bf215546Sopenharmony_cicombine_and_pin_address(struct blorp_batch *blorp_batch,
90bf215546Sopenharmony_ci                        struct blorp_address addr)
91bf215546Sopenharmony_ci{
92bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
93bf215546Sopenharmony_ci   struct iris_bo *bo = addr.buffer;
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   iris_use_pinned_bo(batch, bo, addr.reloc_flags & RELOC_WRITE,
96bf215546Sopenharmony_ci                      IRIS_DOMAIN_NONE);
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci   /* Assume this is a general address, not relative to a base. */
99bf215546Sopenharmony_ci   return bo->address + addr.offset;
100bf215546Sopenharmony_ci}
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_cistatic uint64_t
103bf215546Sopenharmony_ciblorp_emit_reloc(struct blorp_batch *blorp_batch, UNUSED void *location,
104bf215546Sopenharmony_ci                 struct blorp_address addr, uint32_t delta)
105bf215546Sopenharmony_ci{
106bf215546Sopenharmony_ci   return combine_and_pin_address(blorp_batch, addr) + delta;
107bf215546Sopenharmony_ci}
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_cistatic void
110bf215546Sopenharmony_ciblorp_surface_reloc(struct blorp_batch *blorp_batch, uint32_t ss_offset,
111bf215546Sopenharmony_ci                    struct blorp_address addr, uint32_t delta)
112bf215546Sopenharmony_ci{
113bf215546Sopenharmony_ci   /* Let blorp_get_surface_address do the pinning. */
114bf215546Sopenharmony_ci}
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_cistatic uint64_t
117bf215546Sopenharmony_ciblorp_get_surface_address(struct blorp_batch *blorp_batch,
118bf215546Sopenharmony_ci                          struct blorp_address addr)
119bf215546Sopenharmony_ci{
120bf215546Sopenharmony_ci   return combine_and_pin_address(blorp_batch, addr);
121bf215546Sopenharmony_ci}
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ciUNUSED static struct blorp_address
124bf215546Sopenharmony_ciblorp_get_surface_base_address(UNUSED struct blorp_batch *blorp_batch)
125bf215546Sopenharmony_ci{
126bf215546Sopenharmony_ci   return (struct blorp_address) { .offset = IRIS_MEMZONE_BINDER_START };
127bf215546Sopenharmony_ci}
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_cistatic void *
130bf215546Sopenharmony_ciblorp_alloc_dynamic_state(struct blorp_batch *blorp_batch,
131bf215546Sopenharmony_ci                          uint32_t size,
132bf215546Sopenharmony_ci                          uint32_t alignment,
133bf215546Sopenharmony_ci                          uint32_t *offset)
134bf215546Sopenharmony_ci{
135bf215546Sopenharmony_ci   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
136bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci   return stream_state(batch, ice->state.dynamic_uploader,
139bf215546Sopenharmony_ci                       size, alignment, offset, NULL);
140bf215546Sopenharmony_ci}
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ciUNUSED static void *
143bf215546Sopenharmony_ciblorp_alloc_general_state(struct blorp_batch *blorp_batch,
144bf215546Sopenharmony_ci                          uint32_t size,
145bf215546Sopenharmony_ci                          uint32_t alignment,
146bf215546Sopenharmony_ci                          uint32_t *offset)
147bf215546Sopenharmony_ci{
148bf215546Sopenharmony_ci   /* Use dynamic state range for general state on iris. */
149bf215546Sopenharmony_ci   return blorp_alloc_dynamic_state(blorp_batch, size, alignment, offset);
150bf215546Sopenharmony_ci}
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_cistatic void
153bf215546Sopenharmony_ciblorp_alloc_binding_table(struct blorp_batch *blorp_batch,
154bf215546Sopenharmony_ci                          unsigned num_entries,
155bf215546Sopenharmony_ci                          unsigned state_size,
156bf215546Sopenharmony_ci                          unsigned state_alignment,
157bf215546Sopenharmony_ci                          uint32_t *out_bt_offset,
158bf215546Sopenharmony_ci                          uint32_t *surface_offsets,
159bf215546Sopenharmony_ci                          void **surface_maps)
160bf215546Sopenharmony_ci{
161bf215546Sopenharmony_ci   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
162bf215546Sopenharmony_ci   struct iris_binder *binder = &ice->state.binder;
163bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   unsigned bt_offset =
166bf215546Sopenharmony_ci      iris_binder_reserve(ice, num_entries * sizeof(uint32_t));
167bf215546Sopenharmony_ci   uint32_t *bt_map = binder->map + bt_offset;
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci   uint32_t surf_base_offset = GFX_VER < 11 ? binder->bo->address : 0;
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci   *out_bt_offset = bt_offset;
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   for (unsigned i = 0; i < num_entries; i++) {
174bf215546Sopenharmony_ci      surface_maps[i] = stream_state(batch, ice->state.surface_uploader,
175bf215546Sopenharmony_ci                                     state_size, state_alignment,
176bf215546Sopenharmony_ci                                     &surface_offsets[i], NULL);
177bf215546Sopenharmony_ci      bt_map[i] = surface_offsets[i] - surf_base_offset;
178bf215546Sopenharmony_ci   }
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci   iris_use_pinned_bo(batch, binder->bo, false, IRIS_DOMAIN_NONE);
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci   batch->screen->vtbl.update_binder_address(batch, binder);
183bf215546Sopenharmony_ci}
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_cistatic uint32_t
186bf215546Sopenharmony_ciblorp_binding_table_offset_to_pointer(struct blorp_batch *batch,
187bf215546Sopenharmony_ci                                      uint32_t offset)
188bf215546Sopenharmony_ci{
189bf215546Sopenharmony_ci   /* See IRIS_BT_OFFSET_SHIFT in iris_state.c */
190bf215546Sopenharmony_ci   return offset >> ((GFX_VER >= 11 && GFX_VERx10 < 125) ? 3 : 0);
191bf215546Sopenharmony_ci}
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_cistatic void *
194bf215546Sopenharmony_ciblorp_alloc_vertex_buffer(struct blorp_batch *blorp_batch,
195bf215546Sopenharmony_ci                          uint32_t size,
196bf215546Sopenharmony_ci                          struct blorp_address *addr)
197bf215546Sopenharmony_ci{
198bf215546Sopenharmony_ci   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
199bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
200bf215546Sopenharmony_ci   struct iris_bo *bo;
201bf215546Sopenharmony_ci   uint32_t offset;
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci   void *map = stream_state(batch, ice->ctx.const_uploader, size, 64,
204bf215546Sopenharmony_ci                            &offset, &bo);
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci   *addr = (struct blorp_address) {
207bf215546Sopenharmony_ci      .buffer = bo,
208bf215546Sopenharmony_ci      .offset = offset,
209bf215546Sopenharmony_ci      .mocs = iris_mocs(bo, &batch->screen->isl_dev,
210bf215546Sopenharmony_ci                        ISL_SURF_USAGE_VERTEX_BUFFER_BIT),
211bf215546Sopenharmony_ci      .local_hint = iris_bo_likely_local(bo),
212bf215546Sopenharmony_ci   };
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci   return map;
215bf215546Sopenharmony_ci}
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci/**
218bf215546Sopenharmony_ci * See iris_upload_render_state's IRIS_DIRTY_VERTEX_BUFFERS handling for
219bf215546Sopenharmony_ci * a comment about why these VF invalidations are needed.
220bf215546Sopenharmony_ci */
221bf215546Sopenharmony_cistatic void
222bf215546Sopenharmony_ciblorp_vf_invalidate_for_vb_48b_transitions(struct blorp_batch *blorp_batch,
223bf215546Sopenharmony_ci                                           const struct blorp_address *addrs,
224bf215546Sopenharmony_ci                                           UNUSED uint32_t *sizes,
225bf215546Sopenharmony_ci                                           unsigned num_vbs)
226bf215546Sopenharmony_ci{
227bf215546Sopenharmony_ci#if GFX_VER < 11
228bf215546Sopenharmony_ci   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
229bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
230bf215546Sopenharmony_ci   bool need_invalidate = false;
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci   for (unsigned i = 0; i < num_vbs; i++) {
233bf215546Sopenharmony_ci      struct iris_bo *bo = addrs[i].buffer;
234bf215546Sopenharmony_ci      uint16_t high_bits = bo->address >> 32u;
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci      if (high_bits != ice->state.last_vbo_high_bits[i]) {
237bf215546Sopenharmony_ci         need_invalidate = true;
238bf215546Sopenharmony_ci         ice->state.last_vbo_high_bits[i] = high_bits;
239bf215546Sopenharmony_ci      }
240bf215546Sopenharmony_ci   }
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ci   if (need_invalidate) {
243bf215546Sopenharmony_ci      iris_emit_pipe_control_flush(batch,
244bf215546Sopenharmony_ci                                   "workaround: VF cache 32-bit key [blorp]",
245bf215546Sopenharmony_ci                                   PIPE_CONTROL_VF_CACHE_INVALIDATE |
246bf215546Sopenharmony_ci                                   PIPE_CONTROL_CS_STALL);
247bf215546Sopenharmony_ci   }
248bf215546Sopenharmony_ci#endif
249bf215546Sopenharmony_ci}
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_cistatic struct blorp_address
252bf215546Sopenharmony_ciblorp_get_workaround_address(struct blorp_batch *blorp_batch)
253bf215546Sopenharmony_ci{
254bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_ci   return (struct blorp_address) {
257bf215546Sopenharmony_ci      .buffer = batch->screen->workaround_address.bo,
258bf215546Sopenharmony_ci      .offset = batch->screen->workaround_address.offset,
259bf215546Sopenharmony_ci      .local_hint =
260bf215546Sopenharmony_ci         iris_bo_likely_local(batch->screen->workaround_address.bo),
261bf215546Sopenharmony_ci   };
262bf215546Sopenharmony_ci}
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_cistatic void
265bf215546Sopenharmony_ciblorp_flush_range(UNUSED struct blorp_batch *blorp_batch,
266bf215546Sopenharmony_ci                  UNUSED void *start,
267bf215546Sopenharmony_ci                  UNUSED size_t size)
268bf215546Sopenharmony_ci{
269bf215546Sopenharmony_ci   /* All allocated states come from the batch which we will flush before we
270bf215546Sopenharmony_ci    * submit it.  There's nothing for us to do here.
271bf215546Sopenharmony_ci    */
272bf215546Sopenharmony_ci}
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_cistatic const struct intel_l3_config *
275bf215546Sopenharmony_ciblorp_get_l3_config(struct blorp_batch *blorp_batch)
276bf215546Sopenharmony_ci{
277bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
278bf215546Sopenharmony_ci   return batch->screen->l3_config_3d;
279bf215546Sopenharmony_ci}
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_cistatic void
282bf215546Sopenharmony_ciiris_blorp_exec_render(struct blorp_batch *blorp_batch,
283bf215546Sopenharmony_ci                       const struct blorp_params *params)
284bf215546Sopenharmony_ci{
285bf215546Sopenharmony_ci   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
286bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
287bf215546Sopenharmony_ci
288bf215546Sopenharmony_ci#if GFX_VER >= 11
289bf215546Sopenharmony_ci   /* The PIPE_CONTROL command description says:
290bf215546Sopenharmony_ci    *
291bf215546Sopenharmony_ci    *    "Whenever a Binding Table Index (BTI) used by a Render Target Message
292bf215546Sopenharmony_ci    *     points to a different RENDER_SURFACE_STATE, SW must issue a Render
293bf215546Sopenharmony_ci    *     Target Cache Flush by enabling this bit. When render target flush
294bf215546Sopenharmony_ci    *     is set due to new association of BTI, PS Scoreboard Stall bit must
295bf215546Sopenharmony_ci    *     be set in this packet."
296bf215546Sopenharmony_ci    */
297bf215546Sopenharmony_ci   iris_emit_pipe_control_flush(batch,
298bf215546Sopenharmony_ci                                "workaround: RT BTI change [blorp]",
299bf215546Sopenharmony_ci                                PIPE_CONTROL_RENDER_TARGET_FLUSH |
300bf215546Sopenharmony_ci                                PIPE_CONTROL_STALL_AT_SCOREBOARD);
301bf215546Sopenharmony_ci#endif
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci   if (params->depth.enabled &&
304bf215546Sopenharmony_ci       !(blorp_batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL))
305bf215546Sopenharmony_ci      genX(emit_depth_state_workarounds)(ice, batch, &params->depth.surf);
306bf215546Sopenharmony_ci
307bf215546Sopenharmony_ci   /* Flush the render cache in cases where the same surface is used with
308bf215546Sopenharmony_ci    * different aux modes, which can lead to GPU hangs.  Invalidation of
309bf215546Sopenharmony_ci    * sampler caches and flushing of any caches which had previously written
310bf215546Sopenharmony_ci    * the source surfaces should already have been handled by the caller.
311bf215546Sopenharmony_ci    */
312bf215546Sopenharmony_ci   if (params->dst.enabled) {
313bf215546Sopenharmony_ci      iris_cache_flush_for_render(batch, params->dst.addr.buffer,
314bf215546Sopenharmony_ci                                  params->dst.aux_usage);
315bf215546Sopenharmony_ci   }
316bf215546Sopenharmony_ci
317bf215546Sopenharmony_ci   iris_require_command_space(batch, 1400);
318bf215546Sopenharmony_ci
319bf215546Sopenharmony_ci#if GFX_VER == 8
320bf215546Sopenharmony_ci   genX(update_pma_fix)(ice, batch, false);
321bf215546Sopenharmony_ci#endif
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_ci   const unsigned scale = params->fast_clear_op ? UINT_MAX : 1;
324bf215546Sopenharmony_ci   if (ice->state.current_hash_scale != scale) {
325bf215546Sopenharmony_ci      genX(emit_hashing_mode)(ice, batch, params->x1 - params->x0,
326bf215546Sopenharmony_ci                              params->y1 - params->y0, scale);
327bf215546Sopenharmony_ci   }
328bf215546Sopenharmony_ci
329bf215546Sopenharmony_ci#if GFX_VERx10 == 125
330bf215546Sopenharmony_ci   iris_use_pinned_bo(batch, iris_resource_bo(ice->state.pixel_hashing_tables),
331bf215546Sopenharmony_ci                      false, IRIS_DOMAIN_NONE);
332bf215546Sopenharmony_ci#else
333bf215546Sopenharmony_ci   assert(!ice->state.pixel_hashing_tables);
334bf215546Sopenharmony_ci#endif
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci#if GFX_VER >= 12
337bf215546Sopenharmony_ci   genX(invalidate_aux_map_state)(batch);
338bf215546Sopenharmony_ci#endif
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_ci   iris_handle_always_flush_cache(batch);
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci   blorp_exec(blorp_batch, params);
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   iris_handle_always_flush_cache(batch);
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   /* We've smashed all state compared to what the normal 3D pipeline
347bf215546Sopenharmony_ci    * rendering tracks for GL.
348bf215546Sopenharmony_ci    */
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci   uint64_t skip_bits = (IRIS_DIRTY_POLYGON_STIPPLE |
351bf215546Sopenharmony_ci                         IRIS_DIRTY_SO_BUFFERS |
352bf215546Sopenharmony_ci                         IRIS_DIRTY_SO_DECL_LIST |
353bf215546Sopenharmony_ci                         IRIS_DIRTY_LINE_STIPPLE |
354bf215546Sopenharmony_ci                         IRIS_ALL_DIRTY_FOR_COMPUTE |
355bf215546Sopenharmony_ci                         IRIS_DIRTY_SCISSOR_RECT |
356bf215546Sopenharmony_ci                         IRIS_DIRTY_VF);
357bf215546Sopenharmony_ci   /* Wa_14016820455
358bf215546Sopenharmony_ci    * On Gfx 12.5 platforms, the SF_CL_VIEWPORT pointer can be invalidated
359bf215546Sopenharmony_ci    * likely by a read cache invalidation when clipping is disabled, so we
360bf215546Sopenharmony_ci    * don't skip its dirty bit here, in order to reprogram it.
361bf215546Sopenharmony_ci    */
362bf215546Sopenharmony_ci   if (GFX_VERx10 != 125)
363bf215546Sopenharmony_ci      skip_bits |= IRIS_DIRTY_SF_CL_VIEWPORT;
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci   uint64_t skip_stage_bits = (IRIS_ALL_STAGE_DIRTY_FOR_COMPUTE |
366bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_UNCOMPILED_VS |
367bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_UNCOMPILED_TCS |
368bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_UNCOMPILED_TES |
369bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_UNCOMPILED_GS |
370bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_UNCOMPILED_FS |
371bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_SAMPLER_STATES_VS |
372bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_SAMPLER_STATES_TCS |
373bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_SAMPLER_STATES_TES |
374bf215546Sopenharmony_ci                               IRIS_STAGE_DIRTY_SAMPLER_STATES_GS);
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ci   if (!ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL]) {
377bf215546Sopenharmony_ci      /* BLORP disabled tessellation, that's fine for the next draw */
378bf215546Sopenharmony_ci      skip_stage_bits |= IRIS_STAGE_DIRTY_TCS |
379bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_TES |
380bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_CONSTANTS_TCS |
381bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_CONSTANTS_TES |
382bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_BINDINGS_TCS |
383bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_BINDINGS_TES;
384bf215546Sopenharmony_ci   }
385bf215546Sopenharmony_ci
386bf215546Sopenharmony_ci   if (!ice->shaders.uncompiled[MESA_SHADER_GEOMETRY]) {
387bf215546Sopenharmony_ci      /* BLORP disabled geometry shaders, that's fine for the next draw */
388bf215546Sopenharmony_ci      skip_stage_bits |= IRIS_STAGE_DIRTY_GS |
389bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_CONSTANTS_GS |
390bf215546Sopenharmony_ci                         IRIS_STAGE_DIRTY_BINDINGS_GS;
391bf215546Sopenharmony_ci   }
392bf215546Sopenharmony_ci
393bf215546Sopenharmony_ci   /* we can skip flagging IRIS_DIRTY_DEPTH_BUFFER, if
394bf215546Sopenharmony_ci    * BLORP_BATCH_NO_EMIT_DEPTH_STENCIL is set.
395bf215546Sopenharmony_ci    */
396bf215546Sopenharmony_ci   if (blorp_batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL)
397bf215546Sopenharmony_ci      skip_bits |= IRIS_DIRTY_DEPTH_BUFFER;
398bf215546Sopenharmony_ci
399bf215546Sopenharmony_ci   if (!params->wm_prog_data)
400bf215546Sopenharmony_ci      skip_bits |= IRIS_DIRTY_BLEND_STATE | IRIS_DIRTY_PS_BLEND;
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci   ice->state.dirty |= ~skip_bits;
403bf215546Sopenharmony_ci   ice->state.stage_dirty |= ~skip_stage_bits;
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci   for (int i = 0; i < ARRAY_SIZE(ice->shaders.urb.size); i++)
406bf215546Sopenharmony_ci      ice->shaders.urb.size[i] = 0;
407bf215546Sopenharmony_ci
408bf215546Sopenharmony_ci   if (params->src.enabled)
409bf215546Sopenharmony_ci      iris_bo_bump_seqno(params->src.addr.buffer, batch->next_seqno,
410bf215546Sopenharmony_ci                         IRIS_DOMAIN_SAMPLER_READ);
411bf215546Sopenharmony_ci   if (params->dst.enabled)
412bf215546Sopenharmony_ci      iris_bo_bump_seqno(params->dst.addr.buffer, batch->next_seqno,
413bf215546Sopenharmony_ci                         IRIS_DOMAIN_RENDER_WRITE);
414bf215546Sopenharmony_ci   if (params->depth.enabled)
415bf215546Sopenharmony_ci      iris_bo_bump_seqno(params->depth.addr.buffer, batch->next_seqno,
416bf215546Sopenharmony_ci                         IRIS_DOMAIN_DEPTH_WRITE);
417bf215546Sopenharmony_ci   if (params->stencil.enabled)
418bf215546Sopenharmony_ci      iris_bo_bump_seqno(params->stencil.addr.buffer, batch->next_seqno,
419bf215546Sopenharmony_ci                         IRIS_DOMAIN_DEPTH_WRITE);
420bf215546Sopenharmony_ci}
421bf215546Sopenharmony_ci
422bf215546Sopenharmony_cistatic void
423bf215546Sopenharmony_ciiris_blorp_exec_blitter(struct blorp_batch *blorp_batch,
424bf215546Sopenharmony_ci                        const struct blorp_params *params)
425bf215546Sopenharmony_ci{
426bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
427bf215546Sopenharmony_ci
428bf215546Sopenharmony_ci   /* Around the length of a XY_BLOCK_COPY_BLT and MI_FLUSH_DW */
429bf215546Sopenharmony_ci   iris_require_command_space(batch, 108);
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   iris_handle_always_flush_cache(batch);
432bf215546Sopenharmony_ci
433bf215546Sopenharmony_ci   blorp_exec(blorp_batch, params);
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_ci   iris_handle_always_flush_cache(batch);
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_ci   if (params->src.enabled) {
438bf215546Sopenharmony_ci      iris_bo_bump_seqno(params->src.addr.buffer, batch->next_seqno,
439bf215546Sopenharmony_ci                         IRIS_DOMAIN_OTHER_READ);
440bf215546Sopenharmony_ci   }
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_ci   iris_bo_bump_seqno(params->dst.addr.buffer, batch->next_seqno,
443bf215546Sopenharmony_ci                      IRIS_DOMAIN_OTHER_WRITE);
444bf215546Sopenharmony_ci}
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_cistatic void
447bf215546Sopenharmony_ciiris_blorp_exec(struct blorp_batch *blorp_batch,
448bf215546Sopenharmony_ci                const struct blorp_params *params)
449bf215546Sopenharmony_ci{
450bf215546Sopenharmony_ci   if (blorp_batch->flags & BLORP_BATCH_USE_BLITTER)
451bf215546Sopenharmony_ci      iris_blorp_exec_blitter(blorp_batch, params);
452bf215546Sopenharmony_ci   else
453bf215546Sopenharmony_ci      iris_blorp_exec_render(blorp_batch, params);
454bf215546Sopenharmony_ci}
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_cistatic void
457bf215546Sopenharmony_ciblorp_measure_start(struct blorp_batch *blorp_batch,
458bf215546Sopenharmony_ci                    const struct blorp_params *params)
459bf215546Sopenharmony_ci{
460bf215546Sopenharmony_ci   struct iris_context *ice = blorp_batch->blorp->driver_ctx;
461bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci   trace_intel_begin_blorp(&batch->trace);
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   if (batch->measure == NULL)
466bf215546Sopenharmony_ci      return;
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_ci   iris_measure_snapshot(ice, batch, params->snapshot_type, NULL, NULL, NULL);
469bf215546Sopenharmony_ci}
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_ci
472bf215546Sopenharmony_cistatic void
473bf215546Sopenharmony_ciblorp_measure_end(struct blorp_batch *blorp_batch,
474bf215546Sopenharmony_ci                    const struct blorp_params *params)
475bf215546Sopenharmony_ci{
476bf215546Sopenharmony_ci   struct iris_batch *batch = blorp_batch->driver_batch;
477bf215546Sopenharmony_ci
478bf215546Sopenharmony_ci   trace_intel_end_blorp(&batch->trace,
479bf215546Sopenharmony_ci                         params->x1 - params->x0,
480bf215546Sopenharmony_ci                         params->y1 - params->y0,
481bf215546Sopenharmony_ci                         params->hiz_op,
482bf215546Sopenharmony_ci                         params->fast_clear_op,
483bf215546Sopenharmony_ci                         params->shader_type,
484bf215546Sopenharmony_ci                         params->shader_pipeline);
485bf215546Sopenharmony_ci}
486bf215546Sopenharmony_ci
487bf215546Sopenharmony_civoid
488bf215546Sopenharmony_cigenX(init_blorp)(struct iris_context *ice)
489bf215546Sopenharmony_ci{
490bf215546Sopenharmony_ci   struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
491bf215546Sopenharmony_ci
492bf215546Sopenharmony_ci   blorp_init(&ice->blorp, ice, &screen->isl_dev, NULL);
493bf215546Sopenharmony_ci   ice->blorp.compiler = screen->compiler;
494bf215546Sopenharmony_ci   ice->blorp.lookup_shader = iris_blorp_lookup_shader;
495bf215546Sopenharmony_ci   ice->blorp.upload_shader = iris_blorp_upload_shader;
496bf215546Sopenharmony_ci   ice->blorp.exec = iris_blorp_exec;
497bf215546Sopenharmony_ci}
498