~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/gallium/drivers/radeonsi/si_cp_reg_shadowing.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 2020 Advanced Micro Devices, Inc.
3
 
 * All Rights Reserved.
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 
 * copy of this software and associated documentation files (the "Software"),
7
 
 * to deal in the Software without restriction, including without limitation
8
 
 * on the rights to use, copy, modify, merge, publish, distribute, sub
9
 
 * license, and/or sell copies of the Software, and to permit persons to whom
10
 
 * the Software is furnished to do so, subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice (including the next
13
 
 * paragraph) shall be included in all copies or substantial portions of the
14
 
 * Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19
 
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20
 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 
 */
24
 
 
25
 
#include "si_build_pm4.h"
26
 
#include "ac_debug.h"
27
 
#include "ac_shadowed_regs.h"
28
 
#include "util/u_memory.h"
29
 
 
30
 
static void si_build_load_reg(struct si_screen *sscreen, struct si_pm4_state *pm4,
31
 
                              enum ac_reg_range_type type,
32
 
                              struct si_resource *shadow_regs)
33
 
{
34
 
   uint64_t gpu_address = shadow_regs->gpu_address;
35
 
   unsigned packet, num_ranges, offset;
36
 
   const struct ac_reg_range *ranges;
37
 
 
38
 
   ac_get_reg_ranges(sscreen->info.chip_class, sscreen->info.family,
39
 
                     type, &num_ranges, &ranges);
40
 
 
41
 
   switch (type) {
42
 
   case SI_REG_RANGE_UCONFIG:
43
 
      gpu_address += SI_SHADOWED_UCONFIG_REG_OFFSET;
44
 
      offset = CIK_UCONFIG_REG_OFFSET;
45
 
      packet = PKT3_LOAD_UCONFIG_REG;
46
 
      break;
47
 
   case SI_REG_RANGE_CONTEXT:
48
 
      gpu_address += SI_SHADOWED_CONTEXT_REG_OFFSET;
49
 
      offset = SI_CONTEXT_REG_OFFSET;
50
 
      packet = PKT3_LOAD_CONTEXT_REG;
51
 
      break;
52
 
   default:
53
 
      gpu_address += SI_SHADOWED_SH_REG_OFFSET;
54
 
      offset = SI_SH_REG_OFFSET;
55
 
      packet = PKT3_LOAD_SH_REG;
56
 
      break;
57
 
   }
58
 
 
59
 
   si_pm4_cmd_add(pm4, PKT3(packet, 1 + num_ranges * 2, 0));
60
 
   si_pm4_cmd_add(pm4, gpu_address);
61
 
   si_pm4_cmd_add(pm4, gpu_address >> 32);
62
 
   for (unsigned i = 0; i < num_ranges; i++) {
63
 
      si_pm4_cmd_add(pm4, (ranges[i].offset - offset) / 4);
64
 
      si_pm4_cmd_add(pm4, ranges[i].size / 4);
65
 
   }
66
 
}
67
 
 
68
 
static struct si_pm4_state *
69
 
si_create_shadowing_ib_preamble(struct si_context *sctx)
70
 
{
71
 
   struct si_shadow_preamble {
72
 
      struct si_pm4_state pm4;
73
 
      uint32_t more_pm4[150]; /* Add more space because the command buffer is large. */
74
 
   };
75
 
   struct si_pm4_state *pm4 = (struct si_pm4_state *)CALLOC_STRUCT(si_shadow_preamble);
76
 
 
77
 
   /* Add all the space that we allocated. */
78
 
   pm4->max_dw = sizeof(struct si_shadow_preamble) - offsetof(struct si_shadow_preamble, pm4.pm4);
79
 
 
80
 
   if (sctx->screen->dpbb_allowed) {
81
 
      si_pm4_cmd_add(pm4, PKT3(PKT3_EVENT_WRITE, 0, 0));
82
 
      si_pm4_cmd_add(pm4, EVENT_TYPE(V_028A90_BREAK_BATCH) | EVENT_INDEX(0));
83
 
   }
84
 
 
85
 
   /* Wait for idle, because we'll update VGT ring pointers. */
86
 
   si_pm4_cmd_add(pm4, PKT3(PKT3_EVENT_WRITE, 0, 0));
87
 
   si_pm4_cmd_add(pm4, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH) | EVENT_INDEX(4));
88
 
 
89
 
   /* VGT_FLUSH is required even if VGT is idle. It resets VGT pointers. */
90
 
   si_pm4_cmd_add(pm4, PKT3(PKT3_EVENT_WRITE, 0, 0));
91
 
   si_pm4_cmd_add(pm4, EVENT_TYPE(V_028A90_VGT_FLUSH) | EVENT_INDEX(0));
92
 
 
93
 
   if (sctx->chip_class >= GFX10) {
94
 
      unsigned gcr_cntl = S_586_GL2_INV(1) | S_586_GL2_WB(1) |
95
 
                          S_586_GLM_INV(1) | S_586_GLM_WB(1) |
96
 
                          S_586_GL1_INV(1) | S_586_GLV_INV(1) |
97
 
                          S_586_GLK_INV(1) | S_586_GLI_INV(V_586_GLI_ALL);
98
 
 
99
 
      si_pm4_cmd_add(pm4, PKT3(PKT3_ACQUIRE_MEM, 6, 0));
100
 
      si_pm4_cmd_add(pm4, 0);           /* CP_COHER_CNTL */
101
 
      si_pm4_cmd_add(pm4, 0xffffffff);  /* CP_COHER_SIZE */
102
 
      si_pm4_cmd_add(pm4, 0xffffff);    /* CP_COHER_SIZE_HI */
103
 
      si_pm4_cmd_add(pm4, 0);           /* CP_COHER_BASE */
104
 
      si_pm4_cmd_add(pm4, 0);           /* CP_COHER_BASE_HI */
105
 
      si_pm4_cmd_add(pm4, 0x0000000A);  /* POLL_INTERVAL */
106
 
      si_pm4_cmd_add(pm4, gcr_cntl);    /* GCR_CNTL */
107
 
   } else if (sctx->chip_class == GFX9) {
108
 
      unsigned cp_coher_cntl = S_0301F0_SH_ICACHE_ACTION_ENA(1) |
109
 
                               S_0301F0_SH_KCACHE_ACTION_ENA(1) |
110
 
                               S_0301F0_TC_ACTION_ENA(1) |
111
 
                               S_0301F0_TCL1_ACTION_ENA(1) |
112
 
                               S_0301F0_TC_WB_ACTION_ENA(1);
113
 
 
114
 
      si_pm4_cmd_add(pm4, PKT3(PKT3_ACQUIRE_MEM, 5, 0));
115
 
      si_pm4_cmd_add(pm4, cp_coher_cntl); /* CP_COHER_CNTL */
116
 
      si_pm4_cmd_add(pm4, 0xffffffff);    /* CP_COHER_SIZE */
117
 
      si_pm4_cmd_add(pm4, 0xffffff);      /* CP_COHER_SIZE_HI */
118
 
      si_pm4_cmd_add(pm4, 0);             /* CP_COHER_BASE */
119
 
      si_pm4_cmd_add(pm4, 0);             /* CP_COHER_BASE_HI */
120
 
      si_pm4_cmd_add(pm4, 0x0000000A);    /* POLL_INTERVAL */
121
 
   } else {
122
 
      unreachable("invalid chip");
123
 
   }
124
 
 
125
 
   si_pm4_cmd_add(pm4, PKT3(PKT3_PFP_SYNC_ME, 0, 0));
126
 
   si_pm4_cmd_add(pm4, 0);
127
 
 
128
 
   si_pm4_cmd_add(pm4, PKT3(PKT3_CONTEXT_CONTROL, 1, 0));
129
 
   si_pm4_cmd_add(pm4,
130
 
                  CC0_UPDATE_LOAD_ENABLES(1) |
131
 
                  CC0_LOAD_PER_CONTEXT_STATE(1) |
132
 
                  CC0_LOAD_CS_SH_REGS(1) |
133
 
                  CC0_LOAD_GFX_SH_REGS(1) |
134
 
                  CC0_LOAD_GLOBAL_UCONFIG(1));
135
 
   si_pm4_cmd_add(pm4,
136
 
                  CC1_UPDATE_SHADOW_ENABLES(1) |
137
 
                  CC1_SHADOW_PER_CONTEXT_STATE(1) |
138
 
                  CC1_SHADOW_CS_SH_REGS(1) |
139
 
                  CC1_SHADOW_GFX_SH_REGS(1) |
140
 
                  CC1_SHADOW_GLOBAL_UCONFIG(1));
141
 
 
142
 
   for (unsigned i = 0; i < SI_NUM_SHADOWED_REG_RANGES; i++)
143
 
      si_build_load_reg(sctx->screen, pm4, i, sctx->shadowed_regs);
144
 
 
145
 
   return pm4;
146
 
}
147
 
 
148
 
static void si_set_context_reg_array(struct radeon_cmdbuf *cs, unsigned reg, unsigned num,
149
 
                                     const uint32_t *values)
150
 
{
151
 
   radeon_begin(cs);
152
 
   radeon_set_context_reg_seq(reg, num);
153
 
   radeon_emit_array(values, num);
154
 
   radeon_end();
155
 
}
156
 
 
157
 
void si_init_cp_reg_shadowing(struct si_context *sctx)
158
 
{
159
 
   if (sctx->screen->info.mid_command_buffer_preemption_enabled ||
160
 
       sctx->screen->debug_flags & DBG(SHADOW_REGS)) {
161
 
      sctx->shadowed_regs =
162
 
            si_aligned_buffer_create(sctx->b.screen,
163
 
                                     PIPE_RESOURCE_FLAG_UNMAPPABLE | SI_RESOURCE_FLAG_DRIVER_INTERNAL,
164
 
                                     PIPE_USAGE_DEFAULT,
165
 
                                     SI_SHADOWED_REG_BUFFER_SIZE,
166
 
                                     4096);
167
 
      if (!sctx->shadowed_regs)
168
 
         fprintf(stderr, "radeonsi: cannot create a shadowed_regs buffer\n");
169
 
   }
170
 
 
171
 
   si_init_cs_preamble_state(sctx, sctx->shadowed_regs != NULL);
172
 
 
173
 
   if (sctx->shadowed_regs) {
174
 
      /* We need to clear the shadowed reg buffer. */
175
 
      si_cp_dma_clear_buffer(sctx, &sctx->gfx_cs, &sctx->shadowed_regs->b.b,
176
 
                             0, sctx->shadowed_regs->bo_size, 0, SI_OP_SYNC_AFTER,
177
 
                             SI_COHERENCY_CP, L2_BYPASS);
178
 
 
179
 
      /* Create the shadowing preamble. */
180
 
      struct si_pm4_state *shadowing_preamble =
181
 
            si_create_shadowing_ib_preamble(sctx);
182
 
 
183
 
      /* Initialize shadowed registers as follows. */
184
 
      radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, sctx->shadowed_regs,
185
 
                                RADEON_USAGE_READWRITE | RADEON_PRIO_DESCRIPTORS);
186
 
      si_pm4_emit(sctx, shadowing_preamble);
187
 
      ac_emulate_clear_state(&sctx->screen->info, &sctx->gfx_cs, si_set_context_reg_array);
188
 
      si_pm4_emit(sctx, sctx->cs_preamble_state);
189
 
 
190
 
      /* The register values are shadowed, so we won't need to set them again. */
191
 
      si_pm4_free_state(sctx, sctx->cs_preamble_state, ~0);
192
 
      sctx->cs_preamble_state = NULL;
193
 
 
194
 
      si_set_tracked_regs_to_clear_state(sctx);
195
 
 
196
 
      /* Setup preemption. The shadowing preamble will be executed as a preamble IB,
197
 
       * which will load register values from memory on a context switch.
198
 
       */
199
 
      sctx->ws->cs_setup_preemption(&sctx->gfx_cs, shadowing_preamble->pm4,
200
 
                                    shadowing_preamble->ndw);
201
 
      si_pm4_free_state(sctx, shadowing_preamble, ~0);
202
 
   }
203
 
}