| 1 | /* |
| 2 | * Copyright © 2016 Rob Clark <[email protected]> |
| 3 | * Copyright © 2018 Google, Inc. |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Authors: |
| 7 | * Rob Clark <[email protected]> |
| 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | #include "pipe/p_state.h" |
| 13 | #include "util/format/u_format.h" |
| 14 | #include "util/u_inlines.h" |
| 15 | #include "util/u_memory.h" |
| 16 | #include "util/u_string.h" |
| 17 | |
| 18 | #include "freedreno_draw.h" |
| 19 | #include "freedreno_resource.h" |
| 20 | #include "freedreno_state.h" |
| 21 | #include "freedreno_tracepoints.h" |
| 22 | |
| 23 | #include "fd6_barrier.h" |
| 24 | #include "fd6_blitter.h" |
| 25 | #include "fd6_context.h" |
| 26 | #include "fd6_draw.h" |
| 27 | #include "fd6_emit.h" |
| 28 | #include "fd6_gmem.h" |
| 29 | #include "fd6_pack.h" |
| 30 | #include "fd6_program.h" |
| 31 | #include "fd6_resource.h" |
| 32 | #include "fd6_zsa.h" |
| 33 | |
| 34 | template <chip CHIP> |
| 35 | static void |
| 36 | emit_mrt(fd_crb &crb, struct pipe_framebuffer_state *pfb, |
| 37 | const struct fd_gmem_stateobj *gmem) |
| 38 | { |
| 39 | unsigned srgb_cntl = 0; |
| 40 | unsigned i; |
| 41 | |
| 42 | /* Note, GLES 3.2 says "If the fragment’s layer number is negative, or |
| 43 | * greater than or equal to the minimum number of layers of any attachment, |
| 44 | * the effects of the fragment on the framebuffer contents are undefined." |
| 45 | */ |
| 46 | unsigned max_layer_index = 0; |
| 47 | enum a6xx_format mrt0_format = FMT6_NONE; |
| 48 | |
| 49 | for (i = 0; i < pfb->nr_cbufs; i++) { |
| 50 | enum a3xx_color_swap swap = WZYX; |
| 51 | bool sint = false, uint = false; |
| 52 | struct fd_resource *rsc = NULL; |
| 53 | ASSERTED struct fdl_slice *slice = NULL; |
| 54 | uint32_t stride = 0; |
| 55 | uint32_t array_stride = 0; |
| 56 | uint32_t offset; |
| 57 | |
| 58 | if (!pfb->cbufs[i].texture) |
| 59 | continue; |
| 60 | |
| 61 | struct pipe_surface *psurf = &pfb->cbufs[i]; |
| 62 | enum pipe_format pformat = psurf->format; |
| 63 | rsc = fd_resource(psurf->texture); |
| 64 | |
| 65 | uint32_t base = gmem ? gmem->cbuf_base[i] : 0; |
| 66 | slice = fd_resource_slice(rsc, psurf->level); |
| 67 | enum a6xx_tile_mode tile_mode = (enum a6xx_tile_mode) |
| 68 | fd_resource_tile_mode(psurf->texture, psurf->level); |
| 69 | enum a6xx_format format = fd6_color_format(pformat, tile_mode); |
| 70 | sint = util_format_is_pure_sint(pformat); |
| 71 | uint = util_format_is_pure_uint(pformat); |
| 72 | |
| 73 | if (util_format_is_srgb(pformat)) |
| 74 | srgb_cntl |= (1 << i); |
| 75 | |
| 76 | offset = |
| 77 | fd_resource_offset(rsc, psurf->level, psurf->first_layer); |
| 78 | |
| 79 | stride = fd_resource_pitch(rsc, psurf->level); |
| 80 | array_stride = fd_resource_layer_stride(rsc, psurf->level); |
| 81 | swap = fd6_color_swap(pformat, (enum a6xx_tile_mode)rsc->layout.tile_mode, false); |
| 82 | |
| 83 | max_layer_index = psurf->last_layer - psurf->first_layer; |
| 84 | |
| 85 | assert((offset + slice->size0) <= fd_bo_size(rsc->bo)); |
| 86 | |
| 87 | /* Batch with no draws? */ |
| 88 | crb.attach_bo(rsc->bo); |
| 89 | |
| 90 | crb.add(RB_MRT_BUF_INFO(CHIP, i, |
| 91 | .color_format = format, |
| 92 | .color_tile_mode = tile_mode, |
| 93 | .color_swap = swap, |
| 94 | .losslesscompen = fd_resource_ubwc_enabled(rsc, psurf->level), |
| 95 | )); |
| 96 | |
| 97 | crb.add(A6XX_RB_MRT_PITCH(i, stride)); |
| 98 | crb.add(A6XX_RB_MRT_ARRAY_PITCH(i, array_stride)); |
| 99 | crb.add(A6XX_RB_MRT_BASE(i, .bo = rsc->bo, .bo_offset = offset)); |
| 100 | crb.add(A6XX_RB_MRT_BASE_GMEM(i, base)); |
| 101 | |
| 102 | crb.add(A6XX_SP_PS_MRT_REG(i, |
| 103 | .color_format = format, |
| 104 | .color_sint = sint, |
| 105 | .color_uint = uint |
| 106 | )); |
| 107 | |
| 108 | crb.add(A6XX_RB_COLOR_FLAG_BUFFER_ADDR(i, |
| 109 | .bo = rsc->bo, |
| 110 | .bo_offset = fd_resource_ubwc_offset(rsc, psurf->level, psurf->first_layer), |
| 111 | )); |
| 112 | crb.add(A6XX_RB_COLOR_FLAG_BUFFER_PITCH(i, |
| 113 | .pitch = fdl_ubwc_pitch(&rsc->layout, psurf->level), |
| 114 | .array_pitch = rsc->layout.ubwc_layer_size >> 2, |
| 115 | )); |
| 116 | |
| 117 | if (i == 0) |
| 118 | mrt0_format = format; |
| 119 | } |
| 120 | if (pfb->zsbuf.texture) |
| 121 | max_layer_index = pfb->zsbuf.last_layer - pfb->zsbuf.first_layer; |
| 122 | |
| 123 | crb.add(GRAS_LRZ_MRT_BUFFER_INFO_0(CHIP, .color_format = mrt0_format)); |
| 124 | crb.add(A6XX_RB_SRGB_CNTL(.dword = srgb_cntl)); |
| 125 | crb.add(A6XX_SP_SRGB_CNTL(.dword = srgb_cntl)); |
| 126 | |
| 127 | crb.add(GRAS_CL_ARRAY_SIZE(CHIP, max_layer_index)); |
| 128 | } |
| 129 | |
| 130 | template <chip CHIP> |
| 131 | static void |
| 132 | emit_zs(fd_crb &crb, struct pipe_surface *zsbuf, const struct fd_gmem_stateobj *gmem) |
| 133 | { |
| 134 | if (zsbuf->texture) { |
| 135 | struct fd_resource *rsc = fd_resource(zsbuf->texture); |
| 136 | struct fd_resource *stencil = rsc->stencil; |
| 137 | uint32_t stride = fd_resource_pitch(rsc, zsbuf->level); |
| 138 | uint32_t array_stride = fd_resource_layer_stride(rsc, zsbuf->level); |
| 139 | uint32_t base = gmem ? gmem->zsbuf_base[0] : 0; |
| 140 | uint32_t offset = |
| 141 | fd_resource_offset(rsc, zsbuf->level, zsbuf->first_layer); |
| 142 | |
| 143 | /* We could have a depth buffer, but no draws with depth write/test |
| 144 | * enabled, in which case it wouldn't have been part of the batch |
| 145 | * resource tracking |
| 146 | */ |
| 147 | crb.attach_bo(rsc->bo); |
| 148 | |
| 149 | if (zsbuf->format == PIPE_FORMAT_S8_UINT) { |
| 150 | /* S8 is implemented as Z32_S8 minus the Z32 plane: */ |
| 151 | enum a6xx_depth_format fmt = DEPTH6_32; |
| 152 | |
| 153 | crb.add(RB_DEPTH_BUFFER_INFO(CHIP, |
| 154 | .depth_format = fmt, |
| 155 | .tilemode = TILE6_3, |
| 156 | .losslesscompen = fd_resource_ubwc_enabled(rsc, zsbuf->level), |
| 157 | )); |
| 158 | crb.add(A6XX_RB_DEPTH_BUFFER_PITCH()); |
| 159 | crb.add(A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH()); |
| 160 | crb.add(A6XX_RB_DEPTH_BUFFER_BASE()); |
| 161 | crb.add(A6XX_RB_DEPTH_GMEM_BASE(base)); |
| 162 | crb.add(GRAS_SU_DEPTH_BUFFER_INFO(CHIP, .depth_format = fmt)); |
| 163 | |
| 164 | stencil = rsc; |
| 165 | } else { |
| 166 | enum a6xx_depth_format fmt = fd6_pipe2depth(zsbuf->format); |
| 167 | |
| 168 | crb.add(RB_DEPTH_BUFFER_INFO(CHIP, |
| 169 | .depth_format = fmt, |
| 170 | .tilemode = TILE6_3, |
| 171 | .losslesscompen = fd_resource_ubwc_enabled(rsc, zsbuf->level), |
| 172 | )); |
| 173 | crb.add(A6XX_RB_DEPTH_BUFFER_PITCH(stride)); |
| 174 | crb.add(A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH(array_stride)); |
| 175 | crb.add(A6XX_RB_DEPTH_BUFFER_BASE(.bo = rsc->bo, .bo_offset = offset)); |
| 176 | crb.add(A6XX_RB_DEPTH_GMEM_BASE(base)); |
| 177 | crb.add(GRAS_SU_DEPTH_BUFFER_INFO(CHIP, .depth_format = fmt)); |
| 178 | |
| 179 | crb.add(A6XX_RB_DEPTH_FLAG_BUFFER_BASE( |
| 180 | .bo = rsc->bo, |
| 181 | .bo_offset = fd_resource_ubwc_offset(rsc, zsbuf->level, zsbuf->first_layer), |
| 182 | )); |
| 183 | crb.add(A6XX_RB_DEPTH_FLAG_BUFFER_PITCH( |
| 184 | .pitch = fdl_ubwc_pitch(&rsc->layout, zsbuf->level), |
| 185 | .array_pitch = rsc->layout.ubwc_layer_size >> 2, |
| 186 | )); |
| 187 | } |
| 188 | |
| 189 | if (stencil) { |
| 190 | stride = fd_resource_pitch(stencil, zsbuf->level); |
| 191 | array_stride = fd_resource_layer_stride(stencil, zsbuf->level); |
| 192 | uint32_t base = gmem ? gmem->zsbuf_base[1] : 0; |
| 193 | uint32_t offset = |
| 194 | fd_resource_offset(stencil, zsbuf->level, zsbuf->first_layer); |
| 195 | |
| 196 | crb.attach_bo(stencil->bo); |
| 197 | |
| 198 | crb.add(RB_STENCIL_BUFFER_INFO(CHIP, |
| 199 | .separate_stencil = true, |
| 200 | .tilemode = TILE6_3, |
| 201 | )); |
| 202 | crb.add(A6XX_RB_STENCIL_BUFFER_PITCH(stride)); |
| 203 | crb.add(A6XX_RB_STENCIL_BUFFER_ARRAY_PITCH(array_stride)); |
| 204 | crb.add(A6XX_RB_STENCIL_BUFFER_BASE(.bo = stencil->bo, .bo_offset = offset)); |
| 205 | crb.add(A6XX_RB_STENCIL_GMEM_BASE(base)); |
| 206 | } else { |
| 207 | crb.add(RB_STENCIL_BUFFER_INFO(CHIP, 0)); |
| 208 | } |
| 209 | } else { |
| 210 | crb.add(RB_DEPTH_BUFFER_INFO(CHIP, |
| 211 | .depth_format = DEPTH6_NONE, |
| 212 | )); |
| 213 | crb.add(A6XX_RB_DEPTH_BUFFER_PITCH()); |
| 214 | crb.add(A6XX_RB_DEPTH_BUFFER_ARRAY_PITCH()); |
| 215 | crb.add(A6XX_RB_DEPTH_BUFFER_BASE()); |
| 216 | crb.add(A6XX_RB_DEPTH_GMEM_BASE()); |
| 217 | crb.add(GRAS_SU_DEPTH_BUFFER_INFO(CHIP, .depth_format = DEPTH6_NONE)); |
| 218 | crb.add(RB_STENCIL_BUFFER_INFO(CHIP, 0)); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | template <chip CHIP> |
| 223 | static inline bool |
| 224 | lrzfc_enabled(struct fd_resource *zsbuf) |
| 225 | { |
| 226 | if ((CHIP < A7XX) || FD_DBG(NOLRZFC) || !zsbuf) |
| 227 | return false; |
| 228 | return zsbuf->lrz_layout.lrz_fc_size > 0; |
| 229 | } |
| 230 | |
| 231 | template <chip CHIP> |
| 232 | static void |
| 233 | emit_lrz(fd_cs &cs, struct fd_batch *batch, struct fd_batch_subpass *subpass) |
| 234 | { |
| 235 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 236 | |
| 237 | if (!subpass->lrz) { |
| 238 | fd_crb crb(cs, 9); |
| 239 | |
| 240 | crb.add(GRAS_LRZ_BUFFER_BASE(CHIP)); |
| 241 | crb.add(GRAS_LRZ_BUFFER_PITCH(CHIP)); |
| 242 | crb.add(A6XX_GRAS_LRZ_VIEW_INFO()); |
| 243 | crb.add(A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE()); |
| 244 | |
| 245 | if (CHIP >= A7XX) { |
| 246 | crb.add(GRAS_LRZ_DEPTH_BUFFER_INFO(CHIP)); |
| 247 | crb.add(GRAS_LRZ_CNTL2(CHIP)); |
| 248 | } |
| 249 | |
| 250 | if (CHIP >= A8XX) { |
| 251 | crb.add(GRAS_LRZ_BUFFER_SLICE_PITCH(CHIP)); |
| 252 | } |
| 253 | |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | /* When swapping LRZ buffers we need to flush LRZ cache.. |
| 258 | * we possibly don't need this during the binning pass, it |
| 259 | * appears that the corruption happens on the read-side, ie. |
| 260 | * we change the LRZ buffer after a sub-pass, but get a |
| 261 | * cache-hit on stale data from the previous LRZ buffer. |
| 262 | */ |
| 263 | fd6_event_write<CHIP>(batch->ctx, cs, FD_LRZ_FLUSH); |
| 264 | |
| 265 | fd_crb crb(cs, 9); |
| 266 | |
| 267 | struct fd_resource *zsbuf = fd_resource(pfb->zsbuf.texture); |
| 268 | |
| 269 | crb.attach_bo(subpass->lrz); |
| 270 | |
| 271 | crb.add(GRAS_LRZ_BUFFER_BASE(CHIP, .bo = subpass->lrz)); |
| 272 | crb.add(GRAS_LRZ_BUFFER_PITCH(CHIP, |
| 273 | .pitch = zsbuf->lrz_layout.lrz_pitch * sizeof(uint16_t), |
| 274 | .array_pitch = zsbuf->lrz_layout.lrz_layer_size, |
| 275 | )); |
| 276 | crb.add(A6XX_GRAS_LRZ_VIEW_INFO( |
| 277 | .base_layer = pfb->zsbuf.first_layer, |
| 278 | .layer_count = pfb->zsbuf.last_layer - pfb->zsbuf.first_layer + 1, |
| 279 | .base_mip_level = pfb->zsbuf.level, |
| 280 | )); |
| 281 | crb.add(A6XX_GRAS_LRZ_FAST_CLEAR_BUFFER_BASE( |
| 282 | .bo = zsbuf->lrz_layout.lrz_fc_size ? subpass->lrz : NULL, |
| 283 | .bo_offset = zsbuf->lrz_layout.lrz_fc_offset |
| 284 | )); |
| 285 | |
| 286 | if (CHIP >= A7XX) { |
| 287 | crb.add(GRAS_LRZ_DEPTH_BUFFER_INFO(CHIP, |
| 288 | .depth_format = fd6_pipe2depth(pfb->zsbuf.format), |
| 289 | )); |
| 290 | crb.add(GRAS_LRZ_CNTL2(CHIP, |
| 291 | .disable_on_wrong_dir = false, |
| 292 | .fc_enable = lrzfc_enabled<CHIP>(zsbuf), |
| 293 | )); |
| 294 | } |
| 295 | |
| 296 | if (CHIP >= A8XX) { |
| 297 | crb.add(GRAS_LRZ_BUFFER_SLICE_PITCH(CHIP, |
| 298 | zsbuf->lrz_layout.lrz_slice_pitch |
| 299 | )); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /* Emit any needed lrz clears to the prologue cmds |
| 304 | */ |
| 305 | template <chip CHIP> |
| 306 | static void |
| 307 | emit_lrz_clears(struct fd_batch *batch) |
| 308 | { |
| 309 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 310 | struct fd_context *ctx = batch->ctx; |
| 311 | unsigned count = 0; |
| 312 | |
| 313 | if (!pfb->zsbuf.texture) |
| 314 | return; |
| 315 | |
| 316 | struct fd_resource *zsbuf = fd_resource(pfb->zsbuf.texture); |
| 317 | |
| 318 | foreach_subpass (subpass, batch) { |
| 319 | /* The lrz buffer isn't explicitly tracked by the batch resource |
| 320 | * tracking (tracking the zsbuf is sufficient), but it still needs |
| 321 | * to be attached to the ring |
| 322 | */ |
| 323 | if (subpass->lrz) |
| 324 | fd_ringbuffer_attach_bo(batch->gmem, subpass->lrz); |
| 325 | |
| 326 | if (!(subpass->fast_cleared & FD_BUFFER_LRZ)) |
| 327 | continue; |
| 328 | |
| 329 | subpass->fast_cleared &= ~FD_BUFFER_LRZ; |
| 330 | |
| 331 | fd_cs cs(fd_batch_get_prologue(batch)); |
| 332 | |
| 333 | /* prep before first clear: */ |
| 334 | if (count == 0) { |
| 335 | fd6_emit_gmem_cache_cntl<CHIP>(cs, ctx->screen, false); |
| 336 | fd6_set_render_mode<CHIP>(cs, {RM6_BLIT2DSCALE}); |
| 337 | fd6_emit_flushes<CHIP>(ctx, cs, FD6_FLUSH_CACHE); |
| 338 | fd6_set_rb_dbg_eco_mode<CHIP>(ctx, cs, true); |
| 339 | } |
| 340 | |
| 341 | if (lrzfc_enabled<CHIP>(zsbuf)) { |
| 342 | emit_lrz<CHIP>(cs, batch, subpass); |
| 343 | fd_pkt4(cs, 1) |
| 344 | .add(GRAS_LRZ_DEPTH_CLEAR(CHIP, subpass->clear_depth)); |
| 345 | fd6_event_write<CHIP>(ctx, cs, FD_LRZ_CLEAR); |
| 346 | } else { |
| 347 | fd6_clear_lrz<CHIP>(cs, zsbuf, subpass->lrz, subpass->clear_depth); |
| 348 | } |
| 349 | |
| 350 | count++; |
| 351 | } |
| 352 | |
| 353 | /* cleanup after last clear: */ |
| 354 | if (count > 0) { |
| 355 | fd_cs cs(fd_batch_get_prologue(batch)); |
| 356 | |
| 357 | fd6_set_rb_dbg_eco_mode<CHIP>(ctx, cs, false); |
| 358 | |
| 359 | /* Clearing writes via CCU color in the PS stage, and LRZ is read via |
| 360 | * UCHE in the earlier GRAS stage. |
| 361 | * |
| 362 | * Note tu also asks for WFI but maybe that is only needed if |
| 363 | * has_ccu_flush_bug (and it is added by fd6_emit_flushes() already |
| 364 | * in that case) |
| 365 | */ |
| 366 | fd6_emit_flushes<CHIP>(batch->ctx, cs, |
| 367 | FD6_FLUSH_CCU_COLOR | |
| 368 | FD6_INVALIDATE_CACHE); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | static bool |
| 373 | use_hw_binning(struct fd_batch *batch) |
| 374 | { |
| 375 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 376 | |
| 377 | if ((gmem->maxpw * gmem->maxph) > 32) |
| 378 | return false; |
| 379 | |
| 380 | return fd_binning_enabled && ((gmem->nbins_x * gmem->nbins_y) >= 2) && |
| 381 | (batch->num_draws > 0); |
| 382 | } |
| 383 | |
| 384 | template <chip CHIP> |
| 385 | static void |
| 386 | patch_fb_read_gmem(struct fd_batch *batch) |
| 387 | { |
| 388 | struct fd_screen *screen = batch->ctx->screen; |
| 389 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 390 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 391 | |
| 392 | unsigned num_patches = fd_patch_num_elements(&batch->fb_read_patches); |
| 393 | if (!num_patches) |
| 394 | return; |
| 395 | |
| 396 | for (unsigned i = 0; i < num_patches; i++) { |
| 397 | struct fd_cs_patch *patch = |
| 398 | fd_patch_element(&batch->fb_read_patches, i); |
| 399 | int buf = patch->val; |
| 400 | struct pipe_surface *psurf = &pfb->cbufs[buf]; |
| 401 | struct pipe_resource *prsc = psurf->texture; |
| 402 | struct fd_resource *rsc = fd_resource(prsc); |
| 403 | enum pipe_format format = psurf->format; |
| 404 | |
| 405 | uint8_t swiz[4]; |
| 406 | fdl6_format_swiz(psurf->format, false, swiz); |
| 407 | |
| 408 | /* always TILE6_2 mode in GMEM, which also means no swap: */ |
| 409 | if (CHIP <= A7XX) { |
| 410 | uint64_t base = screen->gmem_base + gmem->cbuf_base[buf]; |
| 411 | uint32_t descriptor[FDL6_TEX_CONST_DWORDS] = { |
| 412 | A6XX_TEX_MEMOBJ_0_FMT(fd6_texture_format( |
| 413 | format, (enum a6xx_tile_mode)rsc->layout.tile_mode, false)) | |
| 414 | A6XX_TEX_MEMOBJ_0_SAMPLES(fd_msaa_samples(prsc->nr_samples)) | |
| 415 | A6XX_TEX_MEMOBJ_0_SWAP(WZYX) | |
| 416 | A6XX_TEX_MEMOBJ_0_TILE_MODE(TILE6_2) | |
| 417 | COND(util_format_is_srgb(format), A6XX_TEX_MEMOBJ_0_SRGB) | |
| 418 | A6XX_TEX_MEMOBJ_0_SWIZ_X(fdl6_swiz(swiz[0])) | |
| 419 | A6XX_TEX_MEMOBJ_0_SWIZ_Y(fdl6_swiz(swiz[1])) | |
| 420 | A6XX_TEX_MEMOBJ_0_SWIZ_Z(fdl6_swiz(swiz[2])) | |
| 421 | A6XX_TEX_MEMOBJ_0_SWIZ_W(fdl6_swiz(swiz[3])), |
| 422 | |
| 423 | A6XX_TEX_MEMOBJ_1_WIDTH(pfb->width) | |
| 424 | A6XX_TEX_MEMOBJ_1_HEIGHT(pfb->height), |
| 425 | |
| 426 | A6XX_TEX_MEMOBJ_2_PITCH(gmem->bin_w * gmem->cbuf_cpp[buf]) | |
| 427 | A6XX_TEX_MEMOBJ_2_TYPE(A6XX_TEX_2D), |
| 428 | |
| 429 | A6XX_TEX_MEMOBJ_3_ARRAY_PITCH(rsc->layout.layer_size), |
| 430 | A6XX_TEX_MEMOBJ_4_BASE_LO(base), |
| 431 | |
| 432 | A6XX_TEX_MEMOBJ_5_BASE_HI(base >> 32) | |
| 433 | A6XX_TEX_MEMOBJ_5_DEPTH(prsc->array_size) |
| 434 | }; |
| 435 | |
| 436 | memcpy(patch->cs, descriptor, FDL6_TEX_CONST_DWORDS * 4); |
| 437 | } else if (CHIP >= A8XX) { |
| 438 | /* base address is simply GMEM location when using GMEM tiling: */ |
| 439 | uint64_t base = gmem->cbuf_base[buf]; |
| 440 | uint32_t descriptor[FDL6_TEX_CONST_DWORDS] = { |
| 441 | A8XX_TEX_MEMOBJ_0_BASE_LO(base), |
| 442 | |
| 443 | A8XX_TEX_MEMOBJ_1_BASE_HI(base >> 32) | |
| 444 | A8XX_TEX_MEMOBJ_1_TYPE(A6XX_TEX_2D) | |
| 445 | A8XX_TEX_MEMOBJ_1_DEPTH(prsc->array_size), |
| 446 | |
| 447 | A8XX_TEX_MEMOBJ_2_WIDTH(pfb->width) | |
| 448 | A8XX_TEX_MEMOBJ_2_HEIGHT(pfb->height) | |
| 449 | A8XX_TEX_MEMOBJ_2_SAMPLES(fd_msaa_samples(prsc->nr_samples)), |
| 450 | |
| 451 | A8XX_TEX_MEMOBJ_3_FMT(fd6_texture_format( |
| 452 | format, (enum a6xx_tile_mode)rsc->layout.tile_mode, false)) | |
| 453 | A8XX_TEX_MEMOBJ_3_SWAP(WZYX) | |
| 454 | A8XX_TEX_MEMOBJ_3_SWIZ_X(fdl8_swiz(swiz[0])) | |
| 455 | A8XX_TEX_MEMOBJ_3_SWIZ_Y(fdl8_swiz(swiz[1])) | |
| 456 | A8XX_TEX_MEMOBJ_3_SWIZ_Z(fdl8_swiz(swiz[2])) | |
| 457 | A8XX_TEX_MEMOBJ_3_SWIZ_W(fdl8_swiz(swiz[3])), |
| 458 | |
| 459 | A8XX_TEX_MEMOBJ_4_TILE_MODE(TILE6_2) | |
| 460 | COND(util_format_is_srgb(format), A8XX_TEX_MEMOBJ_4_SRGB), |
| 461 | |
| 462 | 0, |
| 463 | |
| 464 | A8XX_TEX_MEMOBJ_6_TEX_LINE_OFFSET(gmem->bin_w * gmem->cbuf_cpp[buf] * 8) | /* in bits */ |
| 465 | A8XX_TEX_MEMOBJ_6_MIN_LINE_OFFSET(0), |
| 466 | |
| 467 | A8XX_TEX_MEMOBJ_7_ARRAY_SLICE_OFFSET(rsc->layout.layer_size), |
| 468 | }; |
| 469 | |
| 470 | memcpy(patch->cs, descriptor, FDL6_TEX_CONST_DWORDS * 4); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | util_dynarray_clear(&batch->fb_read_patches); |
| 475 | } |
| 476 | |
| 477 | template <chip CHIP> |
| 478 | static void |
| 479 | patch_fb_read_sysmem(struct fd_batch *batch) |
| 480 | { |
| 481 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 482 | |
| 483 | unsigned num_patches = |
| 484 | fd_patch_num_elements(&batch->fb_read_patches); |
| 485 | if (!num_patches) |
| 486 | return; |
| 487 | for (unsigned i = 0; i < num_patches; i++) { |
| 488 | struct fd_cs_patch *patch = |
| 489 | fd_patch_element(&batch->fb_read_patches, i); |
| 490 | int buf = patch->val; |
| 491 | |
| 492 | struct pipe_surface *psurf = &pfb->cbufs[buf]; |
| 493 | if (!psurf->texture) |
| 494 | return; |
| 495 | |
| 496 | struct pipe_resource *prsc = psurf->texture; |
| 497 | struct fd_resource *rsc = fd_resource(prsc); |
| 498 | |
| 499 | struct fdl_view_args args = { |
| 500 | .iova = fd_bo_get_iova(rsc->bo), |
| 501 | |
| 502 | .base_miplevel = psurf->level, |
| 503 | .level_count = 1, |
| 504 | |
| 505 | .base_array_layer = psurf->first_layer, |
| 506 | .layer_count = psurf->last_layer - psurf->first_layer + 1, |
| 507 | |
| 508 | .swiz = {PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z, |
| 509 | PIPE_SWIZZLE_W}, |
| 510 | .format = psurf->format, |
| 511 | |
| 512 | .type = FDL_VIEW_TYPE_2D, |
| 513 | .chroma_offsets = {FDL_CHROMA_LOCATION_COSITED_EVEN, |
| 514 | FDL_CHROMA_LOCATION_COSITED_EVEN}, |
| 515 | }; |
| 516 | const struct fdl_layout *layouts[3] = {&rsc->layout, NULL, NULL}; |
| 517 | struct fdl6_view view; |
| 518 | fdl6_view_init<CHIP>(&view, layouts, &args, |
| 519 | batch->ctx->screen->info->props.has_z24uint_s8uint); |
| 520 | memcpy(patch->cs, view.descriptor, FDL6_TEX_CONST_DWORDS * 4); |
| 521 | } |
| 522 | |
| 523 | util_dynarray_clear(&batch->fb_read_patches); |
| 524 | } |
| 525 | |
| 526 | template <chip CHIP> |
| 527 | static void |
| 528 | update_render_cntl(fd_cs &cs, struct fd_screen *screen, |
| 529 | struct pipe_framebuffer_state *pfb, |
| 530 | bool binning) |
| 531 | { |
| 532 | if (CHIP >= A7XX) { |
| 533 | with_crb (cs, 2) { |
| 534 | crb.add(RB_RENDER_CNTL(CHIP, |
| 535 | .fs_disable = binning, |
| 536 | .raster_mode = TYPE_TILED, |
| 537 | .raster_direction = LR_TB |
| 538 | )); |
| 539 | crb.add(GRAS_SU_RENDER_CNTL(CHIP, |
| 540 | .fs_disable = binning, |
| 541 | )); |
| 542 | } |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | bool depth_ubwc_enable = false; |
| 547 | uint32_t mrts_ubwc_enable = 0; |
| 548 | int i; |
| 549 | |
| 550 | if (pfb->zsbuf.texture) { |
| 551 | struct fd_resource *rsc = fd_resource(pfb->zsbuf.texture); |
| 552 | depth_ubwc_enable = |
| 553 | fd_resource_ubwc_enabled(rsc, pfb->zsbuf.level); |
| 554 | } |
| 555 | |
| 556 | for (i = 0; i < pfb->nr_cbufs; i++) { |
| 557 | if (!pfb->cbufs[i].texture) |
| 558 | continue; |
| 559 | |
| 560 | struct pipe_surface *psurf = &pfb->cbufs[i]; |
| 561 | struct fd_resource *rsc = fd_resource(psurf->texture); |
| 562 | |
| 563 | if (fd_resource_ubwc_enabled(rsc, psurf->level)) |
| 564 | mrts_ubwc_enable |= 1 << i; |
| 565 | } |
| 566 | |
| 567 | struct fd_reg_pair rb_render_cntl = RB_RENDER_CNTL( |
| 568 | CHIP, |
| 569 | .ccusinglecachelinesize = 2, |
| 570 | .fs_disable = binning, |
| 571 | .flag_depth = depth_ubwc_enable, |
| 572 | .flag_mrts = mrts_ubwc_enable, |
| 573 | ); |
| 574 | |
| 575 | if (screen->info->props.has_cp_reg_write) { |
| 576 | fd_pkt7(cs, CP_REG_WRITE, 3) |
| 577 | .add(CP_REG_WRITE_0(TRACK_RENDER_CNTL)) |
| 578 | .add(CP_REG_WRITE_1(rb_render_cntl.reg)) |
| 579 | .add(CP_REG_WRITE_2(rb_render_cntl.value)); |
| 580 | } else { |
| 581 | fd_pkt4(cs, 1) |
| 582 | .add(rb_render_cntl); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | template <chip CHIP> |
| 587 | static void |
| 588 | update_vsc_pipe(fd_cs &cs, struct fd_batch *batch) |
| 589 | { |
| 590 | struct fd_context *ctx = batch->ctx; |
| 591 | struct fd6_context *fd6_ctx = fd6_context(ctx); |
| 592 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 593 | unsigned max_vsc_pipes = batch->ctx->screen->info->num_vsc_pipes; |
| 594 | int i; |
| 595 | |
| 596 | if (batch->draw_strm_bits / 8 > fd6_ctx->vsc_draw_strm_pitch) { |
| 597 | if (fd6_ctx->vsc_draw_strm) |
| 598 | fd_bo_del(fd6_ctx->vsc_draw_strm); |
| 599 | fd6_ctx->vsc_draw_strm = NULL; |
| 600 | /* Note: probably only need to align to 0x40, but aligning stronger |
| 601 | * reduces the odds that we will have to realloc again on the next |
| 602 | * frame: |
| 603 | */ |
| 604 | fd6_ctx->vsc_draw_strm_pitch = align(batch->draw_strm_bits / 8, 0x4000); |
| 605 | mesa_logd("pre-resize VSC_DRAW_STRM_PITCH to: 0x%x", |
| 606 | fd6_ctx->vsc_draw_strm_pitch); |
| 607 | } |
| 608 | |
| 609 | if (batch->prim_strm_bits / 8 > fd6_ctx->vsc_prim_strm_pitch) { |
| 610 | if (fd6_ctx->vsc_prim_strm) |
| 611 | fd_bo_del(fd6_ctx->vsc_prim_strm); |
| 612 | fd6_ctx->vsc_prim_strm = NULL; |
| 613 | fd6_ctx->vsc_prim_strm_pitch = align(batch->prim_strm_bits / 8, 0x4000); |
| 614 | mesa_logd("pre-resize VSC_PRIM_STRM_PITCH to: 0x%x", |
| 615 | fd6_ctx->vsc_prim_strm_pitch); |
| 616 | } |
| 617 | |
| 618 | if (!fd6_ctx->vsc_draw_strm) { |
| 619 | /* We also use four bytes per vsc pipe at the end of the draw |
| 620 | * stream buffer for VSC_PIPE_DATA_DRAW_SIZE written back by hw |
| 621 | * (see VSC_SIZE_BASE) |
| 622 | */ |
| 623 | unsigned sz = (max_vsc_pipes * fd6_ctx->vsc_draw_strm_pitch) + |
| 624 | (max_vsc_pipes * 4); |
| 625 | fd6_ctx->vsc_draw_strm = |
| 626 | fd_bo_new(ctx->screen->dev, sz, FD_BO_NOMAP, "vsc_draw_strm"); |
| 627 | } |
| 628 | |
| 629 | if (!fd6_ctx->vsc_prim_strm) { |
| 630 | unsigned sz = max_vsc_pipes * fd6_ctx->vsc_prim_strm_pitch; |
| 631 | fd6_ctx->vsc_prim_strm = |
| 632 | fd_bo_new(ctx->screen->dev, sz, FD_BO_NOMAP, "vsc_prim_strm"); |
| 633 | } |
| 634 | |
| 635 | cs.attach_bo(fd6_ctx->vsc_draw_strm); |
| 636 | cs.attach_bo(fd6_ctx->vsc_prim_strm); |
| 637 | |
| 638 | fd_ncrb<CHIP> ncrb(cs, 12 + max_vsc_pipes); |
| 639 | |
| 640 | ncrb.add(VSC_BIN_SIZE(CHIP, .binw = gmem->bin_w, .binh = gmem->bin_h)); |
| 641 | ncrb.add(A6XX_VSC_SIZE_BASE( |
| 642 | .bo = fd6_ctx->vsc_draw_strm, |
| 643 | .bo_offset = max_vsc_pipes * fd6_ctx->vsc_draw_strm_pitch |
| 644 | )); |
| 645 | |
| 646 | ncrb.add(A6XX_VSC_EXPANDED_BIN_CNTL(.nx = gmem->nbins_x, .ny = gmem->nbins_y)); |
| 647 | |
| 648 | for (i = 0; i < max_vsc_pipes; i++) { |
| 649 | const struct fd_vsc_pipe *pipe = &gmem->vsc_pipe[i]; |
| 650 | ncrb.add(A6XX_VSC_PIPE_CONFIG_REG(i, |
| 651 | .x = pipe->x, .y = pipe->y, |
| 652 | .w = pipe->w, .h = pipe->h)); |
| 653 | } |
| 654 | |
| 655 | ncrb.add(A6XX_VSC_PIPE_DATA_PRIM_BASE(.bo = fd6_ctx->vsc_prim_strm)); |
| 656 | ncrb.add(A6XX_VSC_PIPE_DATA_PRIM_STRIDE(.dword = fd6_ctx->vsc_prim_strm_pitch)); |
| 657 | ncrb.add(A6XX_VSC_PIPE_DATA_PRIM_LENGTH(.dword = fd6_ctx->vsc_prim_strm_pitch - 64)); |
| 658 | |
| 659 | ncrb.add(A6XX_VSC_PIPE_DATA_DRAW_BASE(.bo = fd6_ctx->vsc_draw_strm)); |
| 660 | ncrb.add(A6XX_VSC_PIPE_DATA_DRAW_STRIDE(.dword = fd6_ctx->vsc_draw_strm_pitch)); |
| 661 | ncrb.add(A6XX_VSC_PIPE_DATA_DRAW_LENGTH(.dword = fd6_ctx->vsc_draw_strm_pitch - 64)); |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * If overflow is detected, either 0x1 (VSC_DRAW_STRM overflow) or 0x3 |
| 666 | * (VSC_PRIM_STRM overflow) plus the size of the overflowed buffer is |
| 667 | * written to control->vsc_overflow. This allows the CPU to |
| 668 | * detect which buffer overflowed (and, since the current size is |
| 669 | * encoded as well, this protects against already-submitted but |
| 670 | * not executed batches from fooling the CPU into increasing the |
| 671 | * size again unnecessarily). |
| 672 | */ |
| 673 | static void |
| 674 | emit_vsc_overflow_test(struct fd_batch *batch) |
| 675 | { |
| 676 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 677 | struct fd6_context *fd6_ctx = fd6_context(batch->ctx); |
| 678 | fd_cs cs(batch->gmem); |
| 679 | |
| 680 | assert((fd6_ctx->vsc_draw_strm_pitch & 0x3) == 0); |
| 681 | assert((fd6_ctx->vsc_prim_strm_pitch & 0x3) == 0); |
| 682 | |
| 683 | /* Check for overflow, write vsc_scratch if detected: */ |
| 684 | for (int i = 0; i < gmem->num_vsc_pipes; i++) { |
| 685 | fd_pkt7(cs, CP_COND_WRITE5, 8) |
| 686 | .add(CP_COND_WRITE5_0( |
| 687 | .function = WRITE_GE, |
| 688 | .write_memory = true, |
| 689 | )) |
| 690 | .add(CP_COND_WRITE5_POLL_ADDR( |
| 691 | .qword = REG_A6XX_VSC_PIPE_DATA_DRAW_SIZE(i), |
| 692 | )) |
| 693 | .add(CP_COND_WRITE5_3( |
| 694 | .ref = fd6_ctx->vsc_draw_strm_pitch - 64, |
| 695 | )) |
| 696 | .add(CP_COND_WRITE5_4(.mask = ~0)) |
| 697 | .add(CP_COND_WRITE5_WRITE_ADDR(control_ptr(fd6_ctx, vsc_overflow))) |
| 698 | .add(CP_COND_WRITE5_7(.write_data = 1 + fd6_ctx->vsc_draw_strm_pitch)); |
| 699 | |
| 700 | fd_pkt7(cs, CP_COND_WRITE5, 8) |
| 701 | .add(CP_COND_WRITE5_0( |
| 702 | .function = WRITE_GE, |
| 703 | .write_memory = true, |
| 704 | )) |
| 705 | .add(CP_COND_WRITE5_POLL_ADDR( |
| 706 | .qword = REG_A6XX_VSC_PIPE_DATA_PRIM_SIZE(i), |
| 707 | )) |
| 708 | .add(CP_COND_WRITE5_3( |
| 709 | .ref = fd6_ctx->vsc_prim_strm_pitch - 64, |
| 710 | )) |
| 711 | .add(CP_COND_WRITE5_4(.mask = ~0)) |
| 712 | .add(CP_COND_WRITE5_WRITE_ADDR(control_ptr(fd6_ctx, vsc_overflow))) |
| 713 | .add(CP_COND_WRITE5_7(.write_data = 1 + fd6_ctx->vsc_prim_strm_pitch)); |
| 714 | } |
| 715 | |
| 716 | fd_pkt7(cs, CP_WAIT_MEM_WRITES, 0); |
| 717 | } |
| 718 | |
| 719 | static void |
| 720 | check_vsc_overflow(struct fd_context *ctx) |
| 721 | { |
| 722 | struct fd6_context *fd6_ctx = fd6_context(ctx); |
| 723 | struct fd6_control *control = |
| 724 | (struct fd6_control *)fd_bo_map(fd6_ctx->control_mem); |
| 725 | uint32_t vsc_overflow = control->vsc_overflow; |
| 726 | |
| 727 | if (!vsc_overflow) |
| 728 | return; |
| 729 | |
| 730 | /* clear overflow flag: */ |
| 731 | control->vsc_overflow = 0; |
| 732 | |
| 733 | unsigned buffer = vsc_overflow & 0x3; |
| 734 | unsigned size = vsc_overflow & ~0x3; |
| 735 | |
| 736 | if (buffer == 0x1) { |
| 737 | /* VSC_DRAW_STRM overflow: */ |
| 738 | |
| 739 | if (size < fd6_ctx->vsc_draw_strm_pitch) { |
| 740 | /* we've already increased the size, this overflow is |
| 741 | * from a batch submitted before resize, but executed |
| 742 | * after |
| 743 | */ |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | fd_bo_del(fd6_ctx->vsc_draw_strm); |
| 748 | fd6_ctx->vsc_draw_strm = NULL; |
| 749 | fd6_ctx->vsc_draw_strm_pitch *= 2; |
| 750 | |
| 751 | mesa_logd("resized VSC_PIPE_DATA_DRAW_STRIDE to: 0x%x", |
| 752 | fd6_ctx->vsc_draw_strm_pitch); |
| 753 | |
| 754 | } else if (buffer == 0x3) { |
| 755 | /* VSC_PRIM_STRM overflow: */ |
| 756 | |
| 757 | if (size < fd6_ctx->vsc_prim_strm_pitch) { |
| 758 | /* we've already increased the size */ |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | fd_bo_del(fd6_ctx->vsc_prim_strm); |
| 763 | fd6_ctx->vsc_prim_strm = NULL; |
| 764 | fd6_ctx->vsc_prim_strm_pitch *= 2; |
| 765 | |
| 766 | mesa_logd("resized VSC_PIPE_DATA_PRIM_STRIDE to: 0x%x", |
| 767 | fd6_ctx->vsc_prim_strm_pitch); |
| 768 | |
| 769 | } else { |
| 770 | /* NOTE: it's possible, for example, for overflow to corrupt the |
| 771 | * control page. I mostly just see this hit if I set initial VSC |
| 772 | * buffer size extremely small. Things still seem to recover, |
| 773 | * but maybe we should pre-emptively realloc vsc_data/vsc_data2 |
| 774 | * and hope for different memory placement? |
| 775 | */ |
| 776 | mesa_loge("invalid vsc_overflow value: 0x%08x", vsc_overflow); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | template <chip CHIP> |
| 781 | static void |
| 782 | emit_common_init(fd_cs &cs, struct fd_batch *batch) |
| 783 | { |
| 784 | struct fd_context *ctx = batch->ctx; |
| 785 | struct fd_autotune *at = &batch->ctx->autotune; |
| 786 | struct fd_batch_result *result = batch->autotune_result; |
| 787 | |
| 788 | if (!result) |
| 789 | return; |
| 790 | |
| 791 | cs.attach_bo(at->results_mem); |
| 792 | |
| 793 | fd_pkt4(cs, 1) |
| 794 | .add(A6XX_RB_SAMPLE_COUNTER_CNTL(.copy = true)); |
| 795 | |
| 796 | if (!ctx->screen->info->props.has_event_write_sample_count) { |
| 797 | fd_pkt4(cs, 2) |
| 798 | .add(A6XX_RB_SAMPLE_COUNTER_BASE( |
| 799 | results_ptr(at, result[result->idx].samples_start) |
| 800 | )); |
| 801 | |
| 802 | fd6_event_write<CHIP>(ctx, cs, FD_ZPASS_DONE); |
| 803 | |
| 804 | /* Copied from blob's cmdstream, not sure why it is done. */ |
| 805 | if (CHIP == A7XX) { |
| 806 | fd6_event_write<CHIP>(ctx, cs, FD_CCU_CLEAN_DEPTH); |
| 807 | } |
| 808 | } else { |
| 809 | fd_pkt7(cs, CP_EVENT_WRITE7, 3) |
| 810 | .add(CP_EVENT_WRITE7_0( |
| 811 | .event = ZPASS_DONE, |
| 812 | .write_sample_count = true, |
| 813 | )) |
| 814 | .add(EV_DST_RAM_CP_EVENT_WRITE7_1( |
| 815 | results_ptr(at, result[result->idx].samples_start) |
| 816 | )); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | template <chip CHIP> |
| 821 | static void |
| 822 | emit_common_fini(fd_cs &cs, struct fd_batch *batch) |
| 823 | { |
| 824 | struct fd_context *ctx = batch->ctx; |
| 825 | struct fd_autotune *at = &batch->ctx->autotune; |
| 826 | struct fd_batch_result *result = batch->autotune_result; |
| 827 | |
| 828 | fd6_emit_flushes<CHIP>(batch->ctx, cs, batch->barrier); |
| 829 | |
| 830 | if (!result) |
| 831 | return; |
| 832 | |
| 833 | cs.attach_bo(at->results_mem); |
| 834 | |
| 835 | if (!ctx->screen->info->props.has_event_write_sample_count) { |
| 836 | with_crb (cs, 3) { |
| 837 | crb.add(A6XX_RB_SAMPLE_COUNTER_CNTL(.copy = true)); |
| 838 | crb.add(A6XX_RB_SAMPLE_COUNTER_BASE( |
| 839 | results_ptr(at, result[result->idx].samples_end) |
| 840 | )); |
| 841 | } |
| 842 | |
| 843 | fd6_event_write<CHIP>(batch->ctx, cs, FD_ZPASS_DONE); |
| 844 | } else { |
| 845 | fd_pkt4(cs, 1) |
| 846 | .add(A6XX_RB_SAMPLE_COUNTER_CNTL(.copy = true)); |
| 847 | |
| 848 | fd_pkt7(cs, CP_EVENT_WRITE7, 3) |
| 849 | .add(CP_EVENT_WRITE7_0( |
| 850 | .event = ZPASS_DONE, |
| 851 | .write_sample_count = true, |
| 852 | .sample_count_end_offset = true, |
| 853 | .write_accum_sample_count_diff = true, |
| 854 | )) |
| 855 | .add(EV_DST_RAM_CP_EVENT_WRITE7_1( |
| 856 | results_ptr(at, result[result->idx].samples_start) |
| 857 | )); |
| 858 | } |
| 859 | |
| 860 | fd6_fence_write<CHIP>(cs, result->fence, results_ptr(at, fence)); |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * Emit conditional CP_INDIRECT_BRANCH based on VSC_CHANNEL_VISIBILITY[p], |
| 865 | * ie. the IB is skipped for tiles that have no visible geometry. |
| 866 | * |
| 867 | * If we aren't using binning pass, this just emits a normal IB. |
| 868 | */ |
| 869 | template <chip CHIP> |
| 870 | static void |
| 871 | emit_conditional_ib(fd_cs &cs, struct fd_batch *batch, const struct fd_tile *tile, |
| 872 | struct fd_ringbuffer *target) |
| 873 | { |
| 874 | /* If we have fast clear, that won't count in the VSC state, so it |
| 875 | * forces an unconditional IB (because we know there is something |
| 876 | * to do for this tile) |
| 877 | */ |
| 878 | if (batch->cleared || !use_hw_binning(batch)) { |
| 879 | fd6_emit_ib<CHIP>(cs, target); |
| 880 | return; |
| 881 | } |
| 882 | |
| 883 | if (target->cur == target->start) |
| 884 | return; |
| 885 | |
| 886 | unsigned count = fd_ringbuffer_cmd_count(target); |
| 887 | |
| 888 | BEGIN_RING(cs, 5 + 4 * count); /* ensure conditional doesn't get split */ |
| 889 | |
| 890 | fd_pkt7(cs, CP_REG_TEST, 1) |
| 891 | .add(A6XX_CP_REG_TEST_0( |
| 892 | .reg = REG_A6XX_VSC_CHANNEL_VISIBILITY(tile->p), |
| 893 | .bit = tile->n, |
| 894 | .skip_wait_for_me = true, |
| 895 | )); |
| 896 | |
| 897 | fd_pkt7(cs, CP_COND_REG_EXEC, 2) |
| 898 | .add(CP_COND_REG_EXEC_0_MODE(PRED_TEST)) |
| 899 | .add(PRED_TEST_CP_COND_REG_EXEC_1_DWORDS(4 * count)); |
| 900 | |
| 901 | for (unsigned i = 0; i < count; i++) { |
| 902 | uint32_t dwords; |
| 903 | |
| 904 | fd_pkt7(cs, CP_INDIRECT_BUFFER, 3) |
| 905 | .add(target, i, &dwords) |
| 906 | .add(A5XX_CP_INDIRECT_BUFFER_2(.ib_size = dwords)); |
| 907 | |
| 908 | assert(dwords > 0); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | template <chip CHIP> |
| 913 | static void |
| 914 | set_scissor(fd_cs &cs, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2) |
| 915 | { |
| 916 | fd_pkt4(cs, 2) |
| 917 | .add(GRAS_SC_WINDOW_SCISSOR_TL(CHIP, .x = x1, .y = y1)) |
| 918 | .add(GRAS_SC_WINDOW_SCISSOR_BR(CHIP, .x = x2, .y = y2)); |
| 919 | |
| 920 | fd_pkt4(cs, 2) |
| 921 | .add(GRAS_A2D_SCISSOR_TL(CHIP, .x = x1, .y = y1)) |
| 922 | .add(GRAS_A2D_SCISSOR_BR(CHIP, .x = x2, .y = y2)); |
| 923 | } |
| 924 | |
| 925 | template <chip CHIP> |
| 926 | static void |
| 927 | set_tessfactor_bo(fd_cs &cs, struct fd_batch *batch) |
| 928 | { |
| 929 | /* This happens after all drawing has been emitted to the draw CS, so we know |
| 930 | * whether we need the tess BO pointers. |
| 931 | */ |
| 932 | if (!batch->tessellation) |
| 933 | return; |
| 934 | |
| 935 | struct fd_screen *screen = batch->ctx->screen; |
| 936 | |
| 937 | assert(screen->tess_bo); |
| 938 | cs.attach_bo(screen->tess_bo); |
| 939 | |
| 940 | fd_pkt4(cs, 2) |
| 941 | .add(PC_TESS_BASE(CHIP, screen->tess_bo)); |
| 942 | |
| 943 | /* Updating PC_TESS_BASE could race with the next draw which uses it. */ |
| 944 | fd_pkt7(cs, CP_WAIT_FOR_IDLE, 0); |
| 945 | } |
| 946 | |
| 947 | struct bin_size_params { |
| 948 | enum a6xx_render_mode render_mode; |
| 949 | bool force_lrz_write_dis; |
| 950 | enum a6xx_buffers_location buffers_location; |
| 951 | enum a6xx_lrz_feedback_mask lrz_feedback_zmode_mask; |
| 952 | }; |
| 953 | |
| 954 | /* nregs: 17 */ |
| 955 | template <chip CHIP> |
| 956 | static void |
| 957 | set_bin_size(fd_crb &crb, const struct fd_gmem_stateobj *gmem, struct bin_size_params p) |
| 958 | { |
| 959 | unsigned w = gmem ? gmem->bin_w : 0; |
| 960 | unsigned h = gmem ? gmem->bin_h : 0; |
| 961 | |
| 962 | crb.add(GRAS_SC_BIN_CNTL(CHIP, |
| 963 | .binw = w, .binh = h, |
| 964 | .render_mode = p.render_mode, |
| 965 | .force_lrz_write_dis = p.force_lrz_write_dis, |
| 966 | .buffers_location = p.buffers_location, |
| 967 | .lrz_feedback_zmode_mask = p.lrz_feedback_zmode_mask, |
| 968 | .force_bi_dir_lrz_disable = true, |
| 969 | )); |
| 970 | crb.add(RB_CNTL( |
| 971 | CHIP, |
| 972 | .binw = w, .binh = h, |
| 973 | .render_mode = p.render_mode, |
| 974 | .force_lrz_write_dis = p.force_lrz_write_dis, |
| 975 | .buffers_location = p.buffers_location, |
| 976 | .lrz_feedback_zmode_mask = p.lrz_feedback_zmode_mask, |
| 977 | )); |
| 978 | crb.add(A6XX_VFD_RENDER_MODE(p.render_mode)); |
| 979 | |
| 980 | if (CHIP >= A8XX) { |
| 981 | crb.add(TPL1_BIN_SIZE(CHIP, .binw = w, .binh = h)); |
| 982 | crb.add(TPL1_A2D_BIN_SIZE(CHIP, .binw = w, .binh = h)); |
| 983 | crb.add(SP_BIN_SIZE(CHIP, .binw = w, .binh = h)); |
| 984 | |
| 985 | for (int i = 0; i < 8; i++) { |
| 986 | crb.add(RB_MRT_GMEM_DIMENSION_REG(CHIP, i, |
| 987 | .width = COND(gmem && gmem->cbuf_cpp[i], w), |
| 988 | .height = COND(gmem && gmem->cbuf_cpp[i], h), |
| 989 | )); |
| 990 | } |
| 991 | crb.add(RB_DEPTH_GMEM_DIMENSION(CHIP, |
| 992 | .width = COND(gmem && gmem->zsbuf_cpp[0], w), |
| 993 | .height = COND(gmem && gmem->zsbuf_cpp[0], h), |
| 994 | )); |
| 995 | crb.add(RB_STENCIL_GMEM_DIMENSION(CHIP, |
| 996 | .width = COND(gmem && (gmem->zsbuf_cpp[0] || gmem->zsbuf_cpp[1]), w), |
| 997 | .height = COND(gmem && (gmem->zsbuf_cpp[0] || gmem->zsbuf_cpp[1]), h), |
| 998 | )); |
| 999 | } |
| 1000 | |
| 1001 | /* no flag for RB_RESOLVE_CNTL_3... */ |
| 1002 | crb.add(RB_RESOLVE_CNTL_3(CHIP, .binw = w, .binh = h)); |
| 1003 | } |
| 1004 | |
| 1005 | template <chip CHIP> |
| 1006 | static void |
| 1007 | emit_binning_pass(fd_cs &cs, struct fd_batch *batch) assert_dt |
| 1008 | { |
| 1009 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 1010 | |
| 1011 | assert(!batch->tessellation); |
| 1012 | |
| 1013 | set_scissor<CHIP>(cs, 0, 0, gmem->width - 1, gmem->height - 1); |
| 1014 | |
| 1015 | fd6_set_render_mode<CHIP>(cs, {RM6_BIN_VISIBILITY}); |
| 1016 | |
| 1017 | fd_pkt7(cs, CP_SET_VISIBILITY_OVERRIDE, 1) |
| 1018 | .add(0x1); |
| 1019 | |
| 1020 | fd_pkt7(cs, CP_SET_MODE, 1) |
| 1021 | .add(0x1); |
| 1022 | |
| 1023 | fd_pkt7(cs, CP_WAIT_FOR_IDLE, 0); |
| 1024 | |
| 1025 | fd_pkt4(cs, 1) |
| 1026 | .add(A6XX_VFD_RENDER_MODE(.render_mode = BINNING_PASS)); |
| 1027 | |
| 1028 | update_vsc_pipe<CHIP>(cs, batch); |
| 1029 | |
| 1030 | fd6_event_write<CHIP>(batch->ctx, cs, FD_VSC_BINNING_START); |
| 1031 | |
| 1032 | fd_crb(cs, 2) |
| 1033 | .add(A6XX_RB_WINDOW_OFFSET(.x = 0, .y = 0)) |
| 1034 | .add(A6XX_TPL1_WINDOW_OFFSET(.x = 0, .y = 0)); |
| 1035 | |
| 1036 | /* emit IB to binning drawcmds: */ |
| 1037 | trace_start_binning_ib(&batch->trace, cs); |
| 1038 | foreach_subpass (subpass, batch) { |
| 1039 | emit_lrz<CHIP>(cs, batch, subpass); |
| 1040 | fd6_emit_ib<CHIP>(cs, subpass->draw); |
| 1041 | } |
| 1042 | trace_end_binning_ib(&batch->trace, cs); |
| 1043 | |
| 1044 | fd_pkt7(cs, CP_SET_DRAW_STATE, 3) |
| 1045 | .add(CP_SET_DRAW_STATE__0(0, .disable_all_groups = true)) |
| 1046 | .add(CP_SET_DRAW_STATE__ADDR(0)); |
| 1047 | |
| 1048 | fd6_event_write<CHIP>(batch->ctx, cs, FD_VSC_BINNING_END); |
| 1049 | |
| 1050 | /* This flush is probably required because the VSC, which produces the |
| 1051 | * visibility stream, is a client of UCHE, whereas the CP needs to read |
| 1052 | * the visibility stream (without caching) to do draw skipping. The |
| 1053 | * WFI+WAIT_FOR_ME combination guarantees that the binning commands |
| 1054 | * submitted are finished before reading the VSC regs (in |
| 1055 | * emit_vsc_overflow_test) or the VSC_DATA buffer directly (implicitly |
| 1056 | * as part of draws). |
| 1057 | */ |
| 1058 | fd6_emit_flushes<CHIP>(batch->ctx, cs, |
| 1059 | FD6_FLUSH_CACHE | |
| 1060 | FD6_WAIT_FOR_IDLE | |
| 1061 | FD6_WAIT_FOR_ME); |
| 1062 | |
| 1063 | trace_start_vsc_overflow_test(&batch->trace, cs); |
| 1064 | emit_vsc_overflow_test(batch); |
| 1065 | trace_end_vsc_overflow_test(&batch->trace, cs); |
| 1066 | |
| 1067 | fd_pkt7(cs, CP_SET_VISIBILITY_OVERRIDE, 1) |
| 1068 | .add(0x0); |
| 1069 | |
| 1070 | fd_pkt7(cs, CP_SET_MODE, 1) |
| 1071 | .add(0x0); |
| 1072 | |
| 1073 | if (CHIP >= A7XX) { |
| 1074 | fd6_set_render_mode<CHIP>(cs, {RM7_BIN_VISIBILITY_END}); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | /* nregs: 7 */ |
| 1079 | template <chip CHIP> |
| 1080 | static void |
| 1081 | emit_msaa(fd_crb &crb, unsigned nr) |
| 1082 | { |
| 1083 | enum a3xx_msaa_samples samples = fd_msaa_samples(nr); |
| 1084 | |
| 1085 | crb.add(A6XX_TPL1_RAS_MSAA_CNTL(.samples = samples)); |
| 1086 | crb.add(A6XX_TPL1_DEST_MSAA_CNTL( |
| 1087 | .samples = samples, |
| 1088 | .msaa_disable = (samples == MSAA_ONE), |
| 1089 | )); |
| 1090 | |
| 1091 | crb.add(GRAS_SC_RAS_MSAA_CNTL(CHIP, .samples = samples)); |
| 1092 | crb.add(GRAS_SC_DEST_MSAA_CNTL(CHIP, |
| 1093 | .samples = samples, |
| 1094 | .msaa_disable = (samples == MSAA_ONE), |
| 1095 | )); |
| 1096 | |
| 1097 | crb.add(A6XX_RB_RAS_MSAA_CNTL(.samples = samples)); |
| 1098 | crb.add(A6XX_RB_DEST_MSAA_CNTL( |
| 1099 | .samples = samples, |
| 1100 | .msaa_disable = (samples == MSAA_ONE), |
| 1101 | )); |
| 1102 | |
| 1103 | crb.add(A6XX_RB_RESOLVE_GMEM_BUFFER_INFO(.samples = samples)); |
| 1104 | } |
| 1105 | |
| 1106 | template <chip CHIP> |
| 1107 | static void prepare_tile_setup(struct fd_batch *batch); |
| 1108 | template <chip CHIP> |
| 1109 | static void prepare_tile_fini(struct fd_batch *batch); |
| 1110 | |
| 1111 | template <chip CHIP> |
| 1112 | static void |
| 1113 | fd7_emit_static_binning_regs(fd_cs &cs, bool gmem) |
| 1114 | { |
| 1115 | bool full_in_gmem = false; /* gen8 TODO */ |
| 1116 | bool sysmem = !gmem; |
| 1117 | fd_ncrb<CHIP> ncrb(cs, 4); |
| 1118 | |
| 1119 | assert(CHIP >= A7XX); |
| 1120 | |
| 1121 | ncrb.add(RB_BUFFER_CNTL(CHIP, |
| 1122 | .z_sysmem = sysmem, |
| 1123 | .s_sysmem = sysmem, |
| 1124 | .rt0_sysmem = sysmem, |
| 1125 | .rt1_sysmem = sysmem, |
| 1126 | .rt2_sysmem = sysmem, |
| 1127 | .rt3_sysmem = sysmem, |
| 1128 | .rt4_sysmem = sysmem, |
| 1129 | .rt5_sysmem = sysmem, |
| 1130 | .rt6_sysmem = sysmem, |
| 1131 | .rt7_sysmem = sysmem, |
| 1132 | .z_full_in_gmem = full_in_gmem, |
| 1133 | .s_full_in_gmem = full_in_gmem, |
| 1134 | .rt0_full_in_gmem = full_in_gmem, |
| 1135 | .rt1_full_in_gmem = full_in_gmem, |
| 1136 | .rt2_full_in_gmem = full_in_gmem, |
| 1137 | .rt3_full_in_gmem = full_in_gmem, |
| 1138 | .rt4_full_in_gmem = full_in_gmem, |
| 1139 | .rt5_full_in_gmem = full_in_gmem, |
| 1140 | .rt6_full_in_gmem = full_in_gmem, |
| 1141 | .rt7_full_in_gmem = full_in_gmem, |
| 1142 | )); |
| 1143 | ncrb.add(GRAS_LRZ_CB_CNTL(CHIP, 0x0)); |
| 1144 | ncrb.add(GRAS_MODE_CNTL(CHIP, 0x2)); |
| 1145 | ncrb.add(RB_CLEAR_TARGET(CHIP, |
| 1146 | .clear_mode = gmem ? CLEAR_MODE_GMEM : CLEAR_MODE_SYSMEM, |
| 1147 | )); |
| 1148 | } |
| 1149 | |
| 1150 | template <chip CHIP> |
| 1151 | struct fd_ringbuffer * |
| 1152 | fd6_build_preemption_preamble(struct fd_context *ctx, bool gmem) |
| 1153 | { |
| 1154 | struct fd_screen *screen = ctx->screen; |
| 1155 | |
| 1156 | fd_cs cs(ctx->pipe, 0x1000); |
| 1157 | |
| 1158 | fd6_emit_static_regs<CHIP>(cs, ctx); |
| 1159 | fd6_emit_gmem_cache_cntl<CHIP>(cs, screen, gmem); |
| 1160 | |
| 1161 | if (CHIP >= A7XX) { |
| 1162 | fd7_emit_static_binning_regs<CHIP>(cs, gmem); |
| 1163 | } |
| 1164 | |
| 1165 | /* TODO use CP_MEM_TO_SCRATCH_MEM on a7xx. The VSC scratch mem should be |
| 1166 | * automatically saved, unlike GPU registers, so we wouldn't have to |
| 1167 | * manually restore this state. |
| 1168 | */ |
| 1169 | fd_pkt7(cs, CP_MEM_TO_REG, 3) |
| 1170 | .add(CP_MEM_TO_REG_0( |
| 1171 | .reg = REG_A6XX_VSC_CHANNEL_VISIBILITY(0), |
| 1172 | .cnt = 32, |
| 1173 | )) |
| 1174 | .add(A5XX_CP_MEM_TO_REG_SRC( |
| 1175 | control_ptr(fd6_context(ctx), vsc_state), |
| 1176 | )); |
| 1177 | |
| 1178 | return cs; |
| 1179 | } |
| 1180 | FD_GENX(fd6_build_preemption_preamble); |
| 1181 | |
| 1182 | static void |
| 1183 | emit_preamble(struct fd_context *ctx, fd_cs &cs, bool gmem) |
| 1184 | { |
| 1185 | struct fd6_context *fd6_ctx = fd6_context(ctx); |
| 1186 | struct fd_ringbuffer *preamble = gmem ? fd6_ctx->gmem_preamble : fd6_ctx->sysmem_preamble; |
| 1187 | uint32_t dwords; |
| 1188 | |
| 1189 | fd_pkt7(cs, CP_SET_AMBLE, 3) |
| 1190 | .add(preamble, 0, &dwords) |
| 1191 | .add(CP_SET_AMBLE_2(.dwords = dwords, .type = BIN_PREAMBLE_AMBLE_TYPE)); |
| 1192 | |
| 1193 | fd_pkt7(cs, CP_SET_AMBLE, 3) |
| 1194 | .add(CP_SET_AMBLE_ADDR()) |
| 1195 | .add(CP_SET_AMBLE_2(.type = PREAMBLE_AMBLE_TYPE)); |
| 1196 | |
| 1197 | fd_pkt7(cs, CP_SET_AMBLE, 3) |
| 1198 | .add(CP_SET_AMBLE_ADDR()) |
| 1199 | .add(CP_SET_AMBLE_2(.type = POSTAMBLE_AMBLE_TYPE)); |
| 1200 | } |
| 1201 | |
| 1202 | /* before first tile */ |
| 1203 | template <chip CHIP> |
| 1204 | static void |
| 1205 | fd6_emit_tile_init(struct fd_batch *batch) assert_dt |
| 1206 | { |
| 1207 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 1208 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 1209 | struct fd_screen *screen = batch->ctx->screen; |
| 1210 | fd_cs cs(batch->gmem); |
| 1211 | |
| 1212 | emit_lrz_clears<CHIP>(batch); |
| 1213 | |
| 1214 | fd6_emit_restore<CHIP>(cs, batch); |
| 1215 | emit_preamble(batch->ctx, cs, true); |
| 1216 | |
| 1217 | fd6_event_write<CHIP>(batch->ctx, cs, FD_LRZ_FLUSH); |
| 1218 | |
| 1219 | if (batch->prologue) { |
| 1220 | trace_start_prologue(&batch->trace, cs); |
| 1221 | fd6_emit_ib<CHIP>(cs, batch->prologue); |
| 1222 | trace_end_prologue(&batch->trace, cs); |
| 1223 | } |
| 1224 | |
| 1225 | fd6_cache_inv<CHIP>(batch->ctx, cs); |
| 1226 | |
| 1227 | prepare_tile_setup<CHIP>(batch); |
| 1228 | prepare_tile_fini<CHIP>(batch); |
| 1229 | |
| 1230 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_GLOBAL, 1) |
| 1231 | .add(0x0); |
| 1232 | |
| 1233 | /* blob controls "local" in IB2, but I think that is not required */ |
| 1234 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_LOCAL, 1) |
| 1235 | .add(0x1); |
| 1236 | |
| 1237 | fd6_emit_gmem_cache_cntl<CHIP>(cs, screen, true); |
| 1238 | |
| 1239 | with_crb (cs, 150) { |
| 1240 | emit_zs<CHIP>(crb, &pfb->zsbuf, batch->gmem_state); |
| 1241 | emit_mrt<CHIP>(crb, pfb, batch->gmem_state); |
| 1242 | emit_msaa<CHIP>(crb, pfb->samples); |
| 1243 | } |
| 1244 | |
| 1245 | patch_fb_read_gmem<CHIP>(batch); |
| 1246 | |
| 1247 | if (CHIP >= A7XX) { |
| 1248 | fd7_emit_static_binning_regs<CHIP>(cs, true); |
| 1249 | } |
| 1250 | |
| 1251 | if (use_hw_binning(batch)) { |
| 1252 | /* enable stream-out during binning pass: */ |
| 1253 | with_crb (cs, 18) { |
| 1254 | crb.add(VPC_SO_OVERRIDE(CHIP, false)); |
| 1255 | |
| 1256 | set_bin_size<CHIP>(crb, gmem, { |
| 1257 | .render_mode = BINNING_PASS, |
| 1258 | .buffers_location = BUFFERS_IN_GMEM, |
| 1259 | .lrz_feedback_zmode_mask = LRZ_FEEDBACK_NONE, |
| 1260 | }); |
| 1261 | } |
| 1262 | |
| 1263 | update_render_cntl<CHIP>(cs, screen, pfb, true); |
| 1264 | emit_binning_pass<CHIP>(cs, batch); |
| 1265 | |
| 1266 | with_crb (cs, 18) { |
| 1267 | /* and disable stream-out for draw pass: */ |
| 1268 | crb.add(VPC_SO_OVERRIDE(CHIP, true)); |
| 1269 | |
| 1270 | /* |
| 1271 | * NOTE: even if we detect VSC overflow and disable use of |
| 1272 | * visibility stream in draw pass, it is still safe to execute |
| 1273 | * the reset of these cmds: |
| 1274 | */ |
| 1275 | |
| 1276 | set_bin_size<CHIP>(crb, gmem, { |
| 1277 | .render_mode = RENDERING_PASS, |
| 1278 | .force_lrz_write_dis = !screen->info->props.has_lrz_feedback, |
| 1279 | .buffers_location = BUFFERS_IN_GMEM, |
| 1280 | .lrz_feedback_zmode_mask = screen->info->props.has_lrz_feedback |
| 1281 | ? LRZ_FEEDBACK_EARLY_Z_LATE_Z |
| 1282 | : LRZ_FEEDBACK_NONE, |
| 1283 | }); |
| 1284 | } |
| 1285 | |
| 1286 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_GLOBAL, 1) |
| 1287 | .add(0x1); |
| 1288 | |
| 1289 | /* Upload state regs to memory to be restored on skipsaverestore |
| 1290 | * preemption. |
| 1291 | */ |
| 1292 | fd_pkt7(cs, CP_REG_TO_MEM, 3) |
| 1293 | .add(CP_REG_TO_MEM_0( |
| 1294 | .reg = REG_A6XX_VSC_CHANNEL_VISIBILITY(0), |
| 1295 | .cnt = 32, |
| 1296 | )) |
| 1297 | .add(A5XX_CP_REG_TO_MEM_DEST( |
| 1298 | control_ptr(fd6_context(batch->ctx), vsc_state) |
| 1299 | )); |
| 1300 | } else { |
| 1301 | with_crb (cs, 18) { |
| 1302 | /* no binning pass, so enable stream-out for draw pass: */ |
| 1303 | crb.add(VPC_SO_OVERRIDE(CHIP, false)); |
| 1304 | |
| 1305 | set_bin_size<CHIP>(crb, gmem, { |
| 1306 | .render_mode = RENDERING_PASS, |
| 1307 | .force_lrz_write_dis = !screen->info->props.has_lrz_feedback, |
| 1308 | .buffers_location = BUFFERS_IN_GMEM, |
| 1309 | .lrz_feedback_zmode_mask = |
| 1310 | screen->info->props.has_lrz_feedback |
| 1311 | ? LRZ_FEEDBACK_EARLY_Z_OR_EARLY_Z_LATE_Z |
| 1312 | : LRZ_FEEDBACK_NONE, |
| 1313 | }); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | update_render_cntl<CHIP>(cs, screen, pfb, false); |
| 1318 | |
| 1319 | emit_common_init<CHIP>(cs, batch); |
| 1320 | } |
| 1321 | |
| 1322 | /* nregs: 5 */ |
| 1323 | template <chip CHIP> |
| 1324 | static void |
| 1325 | set_window_offset(fd_crb &crb, uint32_t x1, uint32_t y1) |
| 1326 | { |
| 1327 | crb.add(A6XX_RB_WINDOW_OFFSET(.x = x1, .y = y1)); |
| 1328 | crb.add(A6XX_RB_RESOLVE_WINDOW_OFFSET(.x = x1, .y = y1)); |
| 1329 | crb.add(SP_WINDOW_OFFSET(CHIP, .x = x1, .y = y1)); |
| 1330 | crb.add(A6XX_TPL1_WINDOW_OFFSET(.x = x1, .y = y1)); |
| 1331 | if (CHIP >= A8XX) |
| 1332 | crb.add(TPL1_A2D_WINDOW_OFFSET(CHIP, .x = x1, .y = y1)); |
| 1333 | } |
| 1334 | |
| 1335 | /* before mem2gmem */ |
| 1336 | template <chip CHIP> |
| 1337 | static void |
| 1338 | fd6_emit_tile_prep(struct fd_batch *batch, const struct fd_tile *tile) |
| 1339 | { |
| 1340 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 1341 | struct fd_screen *screen = batch->ctx->screen; |
| 1342 | struct fd_context *ctx = batch->ctx; |
| 1343 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 1344 | struct fd6_context *fd6_ctx = fd6_context(ctx); |
| 1345 | fd_cs cs(batch->gmem); |
| 1346 | |
| 1347 | fd6_set_render_mode<CHIP>(cs, {.mode = RM6_BIN_RENDER_START, .uses_gmem = true}); |
| 1348 | |
| 1349 | uint32_t x1 = tile->xoff; |
| 1350 | uint32_t y1 = tile->yoff; |
| 1351 | uint32_t x2 = tile->xoff + tile->bin_w - 1; |
| 1352 | uint32_t y2 = tile->yoff + tile->bin_h - 1; |
| 1353 | |
| 1354 | set_scissor<CHIP>(cs, x1, y1, x2, y2); |
| 1355 | set_tessfactor_bo<CHIP>(cs, batch); |
| 1356 | |
| 1357 | with_crb (cs, 150) { |
| 1358 | emit_zs<CHIP>(crb, &pfb->zsbuf, batch->gmem_state); |
| 1359 | emit_mrt<CHIP>(crb, pfb, batch->gmem_state); |
| 1360 | emit_msaa<CHIP>(crb, pfb->samples); |
| 1361 | } |
| 1362 | |
| 1363 | if (use_hw_binning(batch)) { |
| 1364 | const struct fd_vsc_pipe *pipe = &gmem->vsc_pipe[tile->p]; |
| 1365 | unsigned num_vsc_pipes = screen->info->num_vsc_pipes; |
| 1366 | |
| 1367 | fd_pkt7(cs, CP_WAIT_FOR_ME, 0); |
| 1368 | |
| 1369 | fd_pkt7(cs, CP_SET_MODE, 1) |
| 1370 | .add(0x0); |
| 1371 | |
| 1372 | fd_pkt7(cs, CP_SET_BIN_DATA5, 7) |
| 1373 | /* A702 also sets BIT(0) but that hangchecks */ |
| 1374 | .add(CP_SET_BIN_DATA5_0( |
| 1375 | .vsc_size = pipe->w * pipe->h, |
| 1376 | .vsc_n = tile->n, |
| 1377 | )) |
| 1378 | .add(NO_ABS_MASK_CP_SET_BIN_DATA5_BIN_DATA_ADDR( |
| 1379 | .bo = fd6_ctx->vsc_draw_strm, |
| 1380 | .bo_offset = tile->p * fd6_ctx->vsc_draw_strm_pitch, |
| 1381 | )) |
| 1382 | .add(NO_ABS_MASK_CP_SET_BIN_DATA5_BIN_SIZE_ADDR( |
| 1383 | .bo = fd6_ctx->vsc_draw_strm, /* VSC_PIPE_DATA_DRAW_BASE + (p * 4) */ |
| 1384 | .bo_offset = (tile->p * 4) + (num_vsc_pipes * fd6_ctx->vsc_draw_strm_pitch), |
| 1385 | )) |
| 1386 | .add(NO_ABS_MASK_CP_SET_BIN_DATA5_BIN_PRIM_STRM( |
| 1387 | .bo = fd6_ctx->vsc_prim_strm, |
| 1388 | .bo_offset = tile->p * fd6_ctx->vsc_prim_strm_pitch, |
| 1389 | )); |
| 1390 | |
| 1391 | fd_pkt7(cs, CP_SET_VISIBILITY_OVERRIDE, 1) |
| 1392 | .add(0x0); |
| 1393 | |
| 1394 | with_crb (cs, 18) { |
| 1395 | crb.add(VPC_SO_OVERRIDE(CHIP, true)); |
| 1396 | |
| 1397 | /* |
| 1398 | * NOTE: even if we detect VSC overflow and disable use of |
| 1399 | * visibility stream in draw pass, it is still safe to execute |
| 1400 | * the reset of these cmds: |
| 1401 | */ |
| 1402 | |
| 1403 | set_bin_size<CHIP>(crb, gmem, { |
| 1404 | .render_mode = RENDERING_PASS, |
| 1405 | .force_lrz_write_dis = !screen->info->props.has_lrz_feedback, |
| 1406 | .buffers_location = BUFFERS_IN_GMEM, |
| 1407 | .lrz_feedback_zmode_mask = screen->info->props.has_lrz_feedback |
| 1408 | ? LRZ_FEEDBACK_EARLY_Z_LATE_Z |
| 1409 | : LRZ_FEEDBACK_NONE, |
| 1410 | }); |
| 1411 | } |
| 1412 | |
| 1413 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_GLOBAL, 1) |
| 1414 | .add(0x1); |
| 1415 | } else { |
| 1416 | fd_pkt7(cs, CP_SET_VISIBILITY_OVERRIDE, 1) |
| 1417 | .add(0x1); |
| 1418 | |
| 1419 | /* no binning pass, so enable stream-out for draw pass:: */ |
| 1420 | fd_pkt4(cs, 1) |
| 1421 | .add(VPC_SO_OVERRIDE(CHIP, false)); |
| 1422 | } |
| 1423 | |
| 1424 | with_crb (cs, 22) { |
| 1425 | set_window_offset<CHIP>(crb, x1, y1); |
| 1426 | |
| 1427 | set_bin_size<CHIP>(crb, gmem, { |
| 1428 | .render_mode = RENDERING_PASS, |
| 1429 | .force_lrz_write_dis = !screen->info->props.has_lrz_feedback, |
| 1430 | .buffers_location = BUFFERS_IN_GMEM, |
| 1431 | .lrz_feedback_zmode_mask = screen->info->props.has_lrz_feedback |
| 1432 | ? LRZ_FEEDBACK_EARLY_Z_LATE_Z |
| 1433 | : LRZ_FEEDBACK_NONE, |
| 1434 | }); |
| 1435 | } |
| 1436 | |
| 1437 | fd_pkt7(cs, CP_SET_MODE, 1) |
| 1438 | .add(0x0); |
| 1439 | } |
| 1440 | |
| 1441 | static void |
| 1442 | set_blit_scissor(struct fd_batch *batch, fd_cs &cs) |
| 1443 | { |
| 1444 | const struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 1445 | |
| 1446 | struct pipe_scissor_state blit_scissor; |
| 1447 | |
| 1448 | blit_scissor.minx = 0; |
| 1449 | blit_scissor.miny = 0; |
| 1450 | blit_scissor.maxx = MAX2(1, align(pfb->width, 16)); |
| 1451 | blit_scissor.maxy = MAX2(1, align(pfb->height, 4)); |
| 1452 | |
| 1453 | fd_pkt4(cs, 2) |
| 1454 | .add(A6XX_RB_RESOLVE_CNTL_1(.x = blit_scissor.minx, .y = blit_scissor.miny)) |
| 1455 | .add(A6XX_RB_RESOLVE_CNTL_2(.x = blit_scissor.maxx - 1, .y = blit_scissor.maxy - 1)); |
| 1456 | } |
| 1457 | |
| 1458 | /* nregs: 10 */ |
| 1459 | template <chip CHIP> |
| 1460 | static void |
| 1461 | emit_blit(struct fd_batch *batch, fd_crb &crb, uint32_t base, |
| 1462 | struct pipe_surface *psurf, bool stencil) |
| 1463 | { |
| 1464 | struct fd_resource *rsc = fd_resource(psurf->texture); |
| 1465 | enum pipe_format pfmt = psurf->format; |
| 1466 | uint32_t offset; |
| 1467 | bool ubwc_enabled; |
| 1468 | |
| 1469 | assert(psurf->first_layer == psurf->last_layer); |
| 1470 | |
| 1471 | /* separate stencil case: */ |
| 1472 | if (stencil) { |
| 1473 | rsc = rsc->stencil; |
| 1474 | pfmt = rsc->b.b.format; |
| 1475 | } |
| 1476 | |
| 1477 | offset = |
| 1478 | fd_resource_offset(rsc, psurf->level, psurf->first_layer); |
| 1479 | ubwc_enabled = fd_resource_ubwc_enabled(rsc, psurf->level); |
| 1480 | |
| 1481 | assert(psurf->first_layer == psurf->last_layer); |
| 1482 | |
| 1483 | enum a6xx_tile_mode tile_mode = (enum a6xx_tile_mode) |
| 1484 | fd_resource_tile_mode(&rsc->b.b, psurf->level); |
| 1485 | enum a6xx_format format = fd6_color_format(pfmt, tile_mode); |
| 1486 | uint32_t stride = fd_resource_pitch(rsc, psurf->level); |
| 1487 | uint32_t array_stride = fd_resource_layer_stride(rsc, psurf->level); |
| 1488 | enum a3xx_color_swap swap = |
| 1489 | fd6_color_swap(pfmt, (enum a6xx_tile_mode)rsc->layout.tile_mode, |
| 1490 | false); |
| 1491 | enum a3xx_msaa_samples samples = fd_msaa_samples(rsc->b.b.nr_samples); |
| 1492 | |
| 1493 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_INFO( |
| 1494 | .tile_mode = tile_mode, |
| 1495 | .flags = ubwc_enabled, |
| 1496 | .samples = samples, |
| 1497 | .color_swap = swap, |
| 1498 | .color_format = format, |
| 1499 | )); |
| 1500 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_BASE(.bo = rsc->bo, .bo_offset = offset)); |
| 1501 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_PITCH(stride)); |
| 1502 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_ARRAY_PITCH(array_stride)); |
| 1503 | |
| 1504 | crb.add(A6XX_RB_RESOLVE_GMEM_BUFFER_BASE(.dword = base)); |
| 1505 | |
| 1506 | if (ubwc_enabled) { |
| 1507 | crb.add(A6XX_RB_RESOLVE_SYSTEM_FLAG_BUFFER_BASE( |
| 1508 | .bo = rsc->bo, |
| 1509 | .bo_offset = fd_resource_ubwc_offset(rsc, psurf->level, psurf->first_layer), |
| 1510 | )); |
| 1511 | crb.add(A6XX_RB_RESOLVE_SYSTEM_FLAG_BUFFER_PITCH( |
| 1512 | .pitch = fdl_ubwc_pitch(&rsc->layout, psurf->level), |
| 1513 | .array_pitch = rsc->layout.ubwc_layer_size >> 2, |
| 1514 | )); |
| 1515 | } |
| 1516 | |
| 1517 | if (CHIP >= A7XX) |
| 1518 | crb.add(RB_CLEAR_TARGET(CHIP, .clear_mode = CLEAR_MODE_GMEM)); |
| 1519 | } |
| 1520 | |
| 1521 | template <chip CHIP> |
| 1522 | static void |
| 1523 | emit_restore_blit(struct fd_batch *batch, fd_cs &cs, uint32_t base, |
| 1524 | struct pipe_surface *psurf, unsigned buffer) |
| 1525 | { |
| 1526 | bool stencil = (buffer == FD_BUFFER_STENCIL); |
| 1527 | |
| 1528 | with_crb (cs, 11) { |
| 1529 | crb.add(A6XX_RB_RESOLVE_OPERATION( |
| 1530 | .type = BLIT_EVENT_LOAD, |
| 1531 | .sample_0 = util_format_is_pure_integer(psurf->format), |
| 1532 | .depth = (buffer == FD_BUFFER_DEPTH), |
| 1533 | )); |
| 1534 | |
| 1535 | emit_blit<CHIP>(batch, crb, base, psurf, stencil); |
| 1536 | } |
| 1537 | |
| 1538 | fd6_event_write<CHIP>(batch->ctx, cs, FD_CCU_RESOLVE); |
| 1539 | } |
| 1540 | |
| 1541 | template <chip CHIP> |
| 1542 | static void |
| 1543 | emit_subpass_clears(struct fd_batch *batch, fd_cs &cs, struct fd_batch_subpass *subpass) |
| 1544 | { |
| 1545 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 1546 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 1547 | enum a3xx_msaa_samples samples = fd_msaa_samples(pfb->samples); |
| 1548 | |
| 1549 | uint32_t buffers = subpass->fast_cleared; |
| 1550 | |
| 1551 | if (buffers & PIPE_CLEAR_COLOR) { |
| 1552 | |
| 1553 | for (int i = 0; i < pfb->nr_cbufs; i++) { |
| 1554 | union pipe_color_union *color = &subpass->clear_color[i]; |
| 1555 | union util_color uc = {0}; |
| 1556 | |
| 1557 | if (!pfb->cbufs[i].texture) |
| 1558 | continue; |
| 1559 | |
| 1560 | if (!(buffers & (PIPE_CLEAR_COLOR0 << i))) |
| 1561 | continue; |
| 1562 | |
| 1563 | enum pipe_format pfmt = pfb->cbufs[i].format; |
| 1564 | |
| 1565 | // XXX I think RB_CLEAR_COLOR_DWn wants to take into account SWAP?? |
| 1566 | union pipe_color_union swapped; |
| 1567 | switch (fd6_color_swap(pfmt, TILE6_LINEAR, false)) { |
| 1568 | case WZYX: |
| 1569 | swapped.ui[0] = color->ui[0]; |
| 1570 | swapped.ui[1] = color->ui[1]; |
| 1571 | swapped.ui[2] = color->ui[2]; |
| 1572 | swapped.ui[3] = color->ui[3]; |
| 1573 | break; |
| 1574 | case WXYZ: |
| 1575 | swapped.ui[2] = color->ui[0]; |
| 1576 | swapped.ui[1] = color->ui[1]; |
| 1577 | swapped.ui[0] = color->ui[2]; |
| 1578 | swapped.ui[3] = color->ui[3]; |
| 1579 | break; |
| 1580 | case ZYXW: |
| 1581 | swapped.ui[3] = color->ui[0]; |
| 1582 | swapped.ui[0] = color->ui[1]; |
| 1583 | swapped.ui[1] = color->ui[2]; |
| 1584 | swapped.ui[2] = color->ui[3]; |
| 1585 | break; |
| 1586 | case XYZW: |
| 1587 | swapped.ui[3] = color->ui[0]; |
| 1588 | swapped.ui[2] = color->ui[1]; |
| 1589 | swapped.ui[1] = color->ui[2]; |
| 1590 | swapped.ui[0] = color->ui[3]; |
| 1591 | break; |
| 1592 | } |
| 1593 | |
| 1594 | util_pack_color_union(pfmt, &uc, &swapped); |
| 1595 | |
| 1596 | with_crb (cs, 9) { |
| 1597 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_INFO( |
| 1598 | .tile_mode = TILE6_LINEAR, |
| 1599 | .samples = samples, |
| 1600 | .color_format = fd6_color_format(pfmt, TILE6_LINEAR), |
| 1601 | )); |
| 1602 | |
| 1603 | crb.add(A6XX_RB_RESOLVE_OPERATION( |
| 1604 | .type = BLIT_EVENT_CLEAR, |
| 1605 | .clear_mask = 0xf, |
| 1606 | )); |
| 1607 | |
| 1608 | crb.add(A6XX_RB_RESOLVE_GMEM_BUFFER_BASE(gmem->cbuf_base[i])); |
| 1609 | crb.add(A6XX_RB_RESOLVE_CNTL_0()); |
| 1610 | |
| 1611 | crb.add(A6XX_RB_RESOLVE_CLEAR_COLOR_DW0(uc.ui[0])); |
| 1612 | crb.add(A6XX_RB_RESOLVE_CLEAR_COLOR_DW1(uc.ui[1])); |
| 1613 | crb.add(A6XX_RB_RESOLVE_CLEAR_COLOR_DW2(uc.ui[2])); |
| 1614 | crb.add(A6XX_RB_RESOLVE_CLEAR_COLOR_DW3(uc.ui[3])); |
| 1615 | |
| 1616 | if (CHIP >= A7XX) |
| 1617 | crb.add(RB_CLEAR_TARGET(CHIP, .clear_mode = CLEAR_MODE_GMEM)); |
| 1618 | } |
| 1619 | |
| 1620 | fd6_event_write<CHIP>(batch->ctx, cs, FD_CCU_RESOLVE); |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | const bool has_depth = !!pfb->zsbuf.texture; |
| 1625 | const bool has_separate_stencil = |
| 1626 | has_depth && fd_resource(pfb->zsbuf.texture)->stencil; |
| 1627 | |
| 1628 | /* First clear depth or combined depth/stencil. */ |
| 1629 | if ((has_depth && (buffers & PIPE_CLEAR_DEPTH)) || |
| 1630 | (!has_separate_stencil && (buffers & PIPE_CLEAR_STENCIL))) { |
| 1631 | enum pipe_format pfmt = pfb->zsbuf.format; |
| 1632 | uint32_t clear_value; |
| 1633 | uint32_t mask = 0; |
| 1634 | |
| 1635 | if (has_separate_stencil) { |
| 1636 | pfmt = util_format_get_depth_only(pfb->zsbuf.format); |
| 1637 | clear_value = util_pack_z(pfmt, subpass->clear_depth); |
| 1638 | } else { |
| 1639 | pfmt = pfb->zsbuf.format; |
| 1640 | clear_value = |
| 1641 | util_pack_z_stencil(pfmt, subpass->clear_depth, subpass->clear_stencil); |
| 1642 | } |
| 1643 | |
| 1644 | if (buffers & PIPE_CLEAR_DEPTH) |
| 1645 | mask |= 0x1; |
| 1646 | |
| 1647 | if (!has_separate_stencil && (buffers & PIPE_CLEAR_STENCIL)) |
| 1648 | mask |= 0x2; |
| 1649 | |
| 1650 | with_crb (cs, 6) { |
| 1651 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_INFO( |
| 1652 | .tile_mode = TILE6_LINEAR, |
| 1653 | .samples = samples, |
| 1654 | .color_format = fd6_color_format(pfmt, TILE6_LINEAR), |
| 1655 | )); |
| 1656 | |
| 1657 | crb.add(A6XX_RB_RESOLVE_OPERATION( |
| 1658 | .type = BLIT_EVENT_CLEAR, |
| 1659 | .depth = true, |
| 1660 | .clear_mask = mask, |
| 1661 | )); |
| 1662 | |
| 1663 | crb.add(A6XX_RB_RESOLVE_GMEM_BUFFER_BASE(gmem->zsbuf_base[0])); |
| 1664 | crb.add(A6XX_RB_RESOLVE_CNTL_0()); |
| 1665 | |
| 1666 | crb.add(A6XX_RB_RESOLVE_CLEAR_COLOR_DW0(clear_value)); |
| 1667 | |
| 1668 | if (CHIP >= A7XX) |
| 1669 | crb.add(RB_CLEAR_TARGET(CHIP, .clear_mode = CLEAR_MODE_GMEM)); |
| 1670 | } |
| 1671 | |
| 1672 | fd6_event_write<CHIP>(batch->ctx, cs, FD_CCU_RESOLVE); |
| 1673 | } |
| 1674 | |
| 1675 | /* Then clear the separate stencil buffer in case of 32 bit depth |
| 1676 | * formats with separate stencil. */ |
| 1677 | if (has_separate_stencil && (buffers & PIPE_CLEAR_STENCIL)) { |
| 1678 | with_crb (cs, 6) { |
| 1679 | crb.add(A6XX_RB_RESOLVE_SYSTEM_BUFFER_INFO( |
| 1680 | .tile_mode = TILE6_LINEAR, |
| 1681 | .samples = samples, |
| 1682 | .color_format = FMT6_8_UINT, |
| 1683 | )); |
| 1684 | |
| 1685 | crb.add(A6XX_RB_RESOLVE_OPERATION( |
| 1686 | .type = BLIT_EVENT_CLEAR, |
| 1687 | .depth = true, |
| 1688 | .clear_mask = 0x1, |
| 1689 | )); |
| 1690 | |
| 1691 | crb.add(A6XX_RB_RESOLVE_GMEM_BUFFER_BASE(gmem->zsbuf_base[1])); |
| 1692 | crb.add(A6XX_RB_RESOLVE_CNTL_0()); |
| 1693 | |
| 1694 | crb.add(A6XX_RB_RESOLVE_CLEAR_COLOR_DW0(subpass->clear_stencil & 0xff)); |
| 1695 | |
| 1696 | if (CHIP >= A7XX) |
| 1697 | crb.add(RB_CLEAR_TARGET(CHIP, .clear_mode = CLEAR_MODE_GMEM)); |
| 1698 | } |
| 1699 | |
| 1700 | fd6_event_write<CHIP>(batch->ctx, cs, FD_CCU_RESOLVE); |
| 1701 | } |
| 1702 | } |
| 1703 | |
| 1704 | /* |
| 1705 | * transfer from system memory to gmem |
| 1706 | */ |
| 1707 | template <chip CHIP> |
| 1708 | static void |
| 1709 | emit_restore_blits(struct fd_batch *batch, fd_cs &cs) |
| 1710 | { |
| 1711 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 1712 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 1713 | |
| 1714 | if (batch->restore & FD_BUFFER_COLOR) { |
| 1715 | unsigned i; |
| 1716 | for (i = 0; i < pfb->nr_cbufs; i++) { |
| 1717 | if (!pfb->cbufs[i].texture) |
| 1718 | continue; |
| 1719 | if (!(batch->restore & (PIPE_CLEAR_COLOR0 << i))) |
| 1720 | continue; |
| 1721 | emit_restore_blit<CHIP>(batch, cs, gmem->cbuf_base[i], &pfb->cbufs[i], |
| 1722 | FD_BUFFER_COLOR); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | if (batch->restore & (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL)) { |
| 1727 | struct fd_resource *rsc = fd_resource(pfb->zsbuf.texture); |
| 1728 | |
| 1729 | if (!rsc->stencil || (batch->restore & FD_BUFFER_DEPTH)) { |
| 1730 | emit_restore_blit<CHIP>(batch, cs, gmem->zsbuf_base[0], &pfb->zsbuf, |
| 1731 | FD_BUFFER_DEPTH); |
| 1732 | } |
| 1733 | if (rsc->stencil && (batch->restore & FD_BUFFER_STENCIL)) { |
| 1734 | emit_restore_blit<CHIP>(batch, cs, gmem->zsbuf_base[1], &pfb->zsbuf, |
| 1735 | FD_BUFFER_STENCIL); |
| 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | template <chip CHIP> |
| 1741 | static void |
| 1742 | prepare_tile_setup(struct fd_batch *batch) |
| 1743 | { |
| 1744 | if (batch->restore) { |
| 1745 | batch->tile_loads = |
| 1746 | fd_submit_new_ringbuffer(batch->submit, 0x1000, FD_RINGBUFFER_STREAMING); |
| 1747 | |
| 1748 | fd_cs cs(batch->tile_loads); |
| 1749 | |
| 1750 | set_blit_scissor(batch, cs); |
| 1751 | emit_restore_blits<CHIP>(batch, cs); |
| 1752 | } |
| 1753 | |
| 1754 | foreach_subpass (subpass, batch) { |
| 1755 | if (!subpass->fast_cleared) |
| 1756 | continue; |
| 1757 | |
| 1758 | subpass->subpass_clears = |
| 1759 | fd_submit_new_ringbuffer(batch->submit, 0x1000, FD_RINGBUFFER_STREAMING); |
| 1760 | |
| 1761 | fd_cs cs(subpass->subpass_clears); |
| 1762 | |
| 1763 | set_blit_scissor(batch, cs); |
| 1764 | emit_subpass_clears<CHIP>(batch, cs, subpass); |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | /* |
| 1769 | * transfer from system memory to gmem |
| 1770 | */ |
| 1771 | static void |
| 1772 | fd6_emit_tile_mem2gmem(struct fd_batch *batch, const struct fd_tile *tile) |
| 1773 | { |
| 1774 | } |
| 1775 | |
| 1776 | /* before IB to rendering cmds: */ |
| 1777 | template <chip CHIP> |
| 1778 | static void |
| 1779 | fd6_emit_tile_renderprep(struct fd_batch *batch, const struct fd_tile *tile) |
| 1780 | { |
| 1781 | if (batch->tile_loads) { |
| 1782 | fd_cs cs(batch->gmem); |
| 1783 | trace_start_tile_loads(&batch->trace, cs, batch->restore); |
| 1784 | emit_conditional_ib<CHIP>(cs, batch, tile, batch->tile_loads); |
| 1785 | trace_end_tile_loads(&batch->trace, cs); |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | static bool |
| 1790 | blit_can_resolve(enum pipe_format format) |
| 1791 | { |
| 1792 | const struct util_format_description *desc = util_format_description(format); |
| 1793 | |
| 1794 | /* blit event can only do resolve for simple cases: |
| 1795 | * averaging samples as unsigned integers or choosing only one sample |
| 1796 | */ |
| 1797 | if (util_format_is_snorm(format) || util_format_is_srgb(format)) |
| 1798 | return false; |
| 1799 | |
| 1800 | /* can't do formats with larger channel sizes |
| 1801 | * note: this includes all float formats |
| 1802 | * note2: single channel integer formats seem OK |
| 1803 | */ |
| 1804 | if (desc->channel[0].size > 10) |
| 1805 | return false; |
| 1806 | |
| 1807 | switch (format) { |
| 1808 | /* for unknown reasons blit event can't msaa resolve these formats when tiled |
| 1809 | * likely related to these formats having different layout from other cpp=2 |
| 1810 | * formats |
| 1811 | */ |
| 1812 | case PIPE_FORMAT_R8G8_UNORM: |
| 1813 | case PIPE_FORMAT_R8G8_UINT: |
| 1814 | case PIPE_FORMAT_R8G8_SINT: |
| 1815 | case PIPE_FORMAT_R8G8_SRGB: |
| 1816 | /* TODO: this one should be able to work? */ |
| 1817 | case PIPE_FORMAT_Z24_UNORM_S8_UINT: |
| 1818 | return false; |
| 1819 | default: |
| 1820 | break; |
| 1821 | } |
| 1822 | |
| 1823 | return true; |
| 1824 | } |
| 1825 | |
| 1826 | static bool |
| 1827 | needs_resolve(struct pipe_surface *psurf) |
| 1828 | { |
| 1829 | return psurf->nr_samples && |
| 1830 | (psurf->nr_samples != psurf->texture->nr_samples); |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * Returns the UNKNOWN_8C01 value for handling partial depth/stencil |
| 1835 | * clear/stores to Z24S8. |
| 1836 | */ |
| 1837 | static uint32_t |
| 1838 | fd6_unknown_8c01(enum pipe_format format, unsigned buffers) |
| 1839 | { |
| 1840 | buffers &= FD_BUFFER_DEPTH | FD_BUFFER_STENCIL; |
| 1841 | if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT) { |
| 1842 | if (buffers == FD_BUFFER_DEPTH) |
| 1843 | return 0x08000041; |
| 1844 | else if (buffers == FD_BUFFER_STENCIL) |
| 1845 | return 0x00084001; |
| 1846 | } |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
| 1850 | template <chip CHIP> |
| 1851 | static void |
| 1852 | emit_resolve_blit(struct fd_batch *batch, fd_cs &cs, |
| 1853 | uint32_t base, struct pipe_surface *psurf, |
| 1854 | unsigned buffer) assert_dt |
| 1855 | { |
| 1856 | uint32_t info = 0; |
| 1857 | bool stencil = false; |
| 1858 | |
| 1859 | if (!fd_resource(psurf->texture)->valid) |
| 1860 | return; |
| 1861 | |
| 1862 | /* if we need to resolve, but cannot with BLIT event, we instead need |
| 1863 | * to generate per-tile CP_BLIT (r2d) commands: |
| 1864 | * |
| 1865 | * The separate-stencil is a special case, we might need to use CP_BLIT |
| 1866 | * for depth, but we can still resolve stencil with a BLIT event |
| 1867 | */ |
| 1868 | if (needs_resolve(psurf) && !blit_can_resolve(psurf->format) && |
| 1869 | (buffer != FD_BUFFER_STENCIL)) { |
| 1870 | /* We could potentially use fd6_unknown_8c01() to handle partial z/s |
| 1871 | * resolve to packed z/s, but we would need a corresponding ability in the |
| 1872 | * !resolve case below, so batch_draw_tracking_for_dirty_bits() has us |
| 1873 | * just do a restore of the other channel for partial packed z/s writes. |
| 1874 | */ |
| 1875 | fd6_resolve_tile<CHIP>(batch, cs, base, psurf, 0); |
| 1876 | return; |
| 1877 | } |
| 1878 | |
| 1879 | switch (buffer) { |
| 1880 | case FD_BUFFER_COLOR: |
| 1881 | info = A6XX_RB_RESOLVE_OPERATION_TYPE(BLIT_EVENT_STORE); |
| 1882 | break; |
| 1883 | case FD_BUFFER_STENCIL: |
| 1884 | info = A6XX_RB_RESOLVE_OPERATION_TYPE(BLIT_EVENT_STORE_AND_CLEAR); |
| 1885 | stencil = true; |
| 1886 | break; |
| 1887 | case FD_BUFFER_DEPTH: |
| 1888 | info = A6XX_RB_RESOLVE_OPERATION_TYPE(BLIT_EVENT_STORE) | A6XX_RB_RESOLVE_OPERATION_DEPTH; |
| 1889 | break; |
| 1890 | } |
| 1891 | |
| 1892 | if (util_format_is_pure_integer(psurf->format) || |
| 1893 | util_format_is_depth_or_stencil(psurf->format)) |
| 1894 | info |= A6XX_RB_RESOLVE_OPERATION_SAMPLE_0; |
| 1895 | |
| 1896 | with_crb (cs, 11) { |
| 1897 | crb.add(A6XX_RB_RESOLVE_OPERATION(.dword = info)); |
| 1898 | emit_blit<CHIP>(batch, crb, base, psurf, stencil); |
| 1899 | } |
| 1900 | |
| 1901 | fd6_event_write<CHIP>(batch->ctx, cs, FD_CCU_RESOLVE); |
| 1902 | } |
| 1903 | |
| 1904 | /* |
| 1905 | * transfer from gmem to system memory (ie. normal RAM) |
| 1906 | */ |
| 1907 | |
| 1908 | template <chip CHIP> |
| 1909 | static void |
| 1910 | prepare_tile_fini(struct fd_batch *batch) |
| 1911 | assert_dt |
| 1912 | { |
| 1913 | const struct fd_gmem_stateobj *gmem = batch->gmem_state; |
| 1914 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 1915 | |
| 1916 | batch->tile_store = |
| 1917 | fd_submit_new_ringbuffer(batch->submit, 0x1000, FD_RINGBUFFER_STREAMING); |
| 1918 | |
| 1919 | fd_cs cs(batch->tile_store); |
| 1920 | |
| 1921 | set_blit_scissor(batch, cs); |
| 1922 | |
| 1923 | if (batch->resolve & (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL)) { |
| 1924 | struct fd_resource *rsc = fd_resource(pfb->zsbuf.texture); |
| 1925 | |
| 1926 | if (!rsc->stencil || (batch->resolve & FD_BUFFER_DEPTH)) { |
| 1927 | emit_resolve_blit<CHIP>(batch, cs, gmem->zsbuf_base[0], |
| 1928 | &pfb->zsbuf, FD_BUFFER_DEPTH); |
| 1929 | } |
| 1930 | if (rsc->stencil && (batch->resolve & FD_BUFFER_STENCIL)) { |
| 1931 | emit_resolve_blit<CHIP>(batch, cs, gmem->zsbuf_base[1], |
| 1932 | &pfb->zsbuf, FD_BUFFER_STENCIL); |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | if (batch->resolve & FD_BUFFER_COLOR) { |
| 1937 | unsigned i; |
| 1938 | for (i = 0; i < pfb->nr_cbufs; i++) { |
| 1939 | if (!pfb->cbufs[i].texture) |
| 1940 | continue; |
| 1941 | if (!(batch->resolve & (PIPE_CLEAR_COLOR0 << i))) |
| 1942 | continue; |
| 1943 | emit_resolve_blit<CHIP>(batch, cs, gmem->cbuf_base[i], |
| 1944 | &pfb->cbufs[i], FD_BUFFER_COLOR); |
| 1945 | } |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | template <chip CHIP> |
| 1950 | static void |
| 1951 | fd6_emit_tile(struct fd_batch *batch, const struct fd_tile *tile) |
| 1952 | { |
| 1953 | fd_cs cs(batch->gmem); |
| 1954 | |
| 1955 | foreach_subpass (subpass, batch) { |
| 1956 | if (subpass->subpass_clears) { |
| 1957 | trace_start_clears(&batch->trace, cs, subpass->fast_cleared); |
| 1958 | emit_conditional_ib<CHIP>(cs, batch, tile, subpass->subpass_clears); |
| 1959 | trace_end_clears(&batch->trace, cs); |
| 1960 | } |
| 1961 | |
| 1962 | emit_lrz<CHIP>(cs, batch, subpass); |
| 1963 | |
| 1964 | fd6_emit_ib<CHIP>(cs, subpass->draw); |
| 1965 | } |
| 1966 | |
| 1967 | if (batch->tile_epilogue) |
| 1968 | fd6_emit_ib<CHIP>(cs, batch->tile_epilogue); |
| 1969 | } |
| 1970 | |
| 1971 | template <chip CHIP> |
| 1972 | static void |
| 1973 | fd6_emit_tile_gmem2mem(struct fd_batch *batch, const struct fd_tile *tile) |
| 1974 | { |
| 1975 | fd_cs cs(batch->gmem); |
| 1976 | |
| 1977 | if (use_hw_binning(batch)) { |
| 1978 | fd6_set_render_mode<CHIP>(cs, {.mode = RM6_BIN_END_OF_DRAWS, .uses_gmem = true}); |
| 1979 | } |
| 1980 | |
| 1981 | fd_pkt7(cs, CP_SET_DRAW_STATE, 3) |
| 1982 | .add(CP_SET_DRAW_STATE__0(0, .disable_all_groups = true)) |
| 1983 | .add(CP_SET_DRAW_STATE__ADDR(0)); |
| 1984 | |
| 1985 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_LOCAL, 1) |
| 1986 | .add(0x0); |
| 1987 | |
| 1988 | fd6_set_render_mode<CHIP>(cs, {.mode = RM6_BIN_RESOLVE, .uses_gmem = true}); |
| 1989 | |
| 1990 | if (batch->tile_store) { |
| 1991 | trace_start_tile_stores(&batch->trace, cs, batch->resolve); |
| 1992 | emit_conditional_ib<CHIP>(cs, batch, tile, batch->tile_store); |
| 1993 | trace_end_tile_stores(&batch->trace, cs); |
| 1994 | } |
| 1995 | |
| 1996 | fd6_set_render_mode<CHIP>(cs, {.mode = RM6_BIN_RENDER_END}); |
| 1997 | } |
| 1998 | |
| 1999 | template <chip CHIP> |
| 2000 | static void |
| 2001 | fd6_emit_tile_fini(struct fd_batch *batch) |
| 2002 | { |
| 2003 | fd_cs cs(batch->gmem); |
| 2004 | |
| 2005 | emit_common_fini<CHIP>(cs, batch); |
| 2006 | |
| 2007 | if (batch->epilogue) |
| 2008 | fd6_emit_ib<CHIP>(cs, batch->epilogue); |
| 2009 | |
| 2010 | fd_pkt4(cs, 1) |
| 2011 | .add(GRAS_LRZ_CNTL(CHIP, .enable = true)); |
| 2012 | |
| 2013 | fd6_event_write<CHIP>(batch->ctx, cs, FD_LRZ_FLUSH); |
| 2014 | fd6_event_write<CHIP>(batch->ctx, cs, FD_CCU_CLEAN_BLIT_CACHE); |
| 2015 | |
| 2016 | if (use_hw_binning(batch)) { |
| 2017 | check_vsc_overflow(batch->ctx); |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | template <chip CHIP> |
| 2022 | static void |
| 2023 | emit_sysmem_clears(fd_cs &cs, struct fd_batch *batch, struct fd_batch_subpass *subpass) |
| 2024 | assert_dt |
| 2025 | { |
| 2026 | struct fd_context *ctx = batch->ctx; |
| 2027 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 2028 | |
| 2029 | uint32_t buffers = subpass->fast_cleared; |
| 2030 | |
| 2031 | assert(buffers); |
| 2032 | |
| 2033 | struct pipe_box box2d; |
| 2034 | u_box_2d(0, 0, pfb->width, pfb->height, &box2d); |
| 2035 | |
| 2036 | trace_start_clears(&batch->trace, cs, buffers); |
| 2037 | |
| 2038 | fd6_set_render_mode<CHIP>(cs, {RM6_BLIT2DSCALE}); |
| 2039 | |
| 2040 | if (buffers & PIPE_CLEAR_COLOR) { |
| 2041 | for (int i = 0; i < pfb->nr_cbufs; i++) { |
| 2042 | union pipe_color_union color = subpass->clear_color[i]; |
| 2043 | |
| 2044 | if (!pfb->cbufs[i].texture) |
| 2045 | continue; |
| 2046 | |
| 2047 | if (!(buffers & (PIPE_CLEAR_COLOR0 << i))) |
| 2048 | continue; |
| 2049 | |
| 2050 | fd6_clear_surface<CHIP>(ctx, cs, &pfb->cbufs[i], &box2d, &color, 0); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | if (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) { |
| 2055 | union pipe_color_union value = {}; |
| 2056 | |
| 2057 | const bool has_depth = !!pfb->zsbuf.texture; |
| 2058 | struct pipe_resource *separate_stencil = |
| 2059 | has_depth && fd_resource(pfb->zsbuf.texture)->stencil |
| 2060 | ? &fd_resource(pfb->zsbuf.texture)->stencil->b.b |
| 2061 | : NULL; |
| 2062 | |
| 2063 | if ((buffers & PIPE_CLEAR_DEPTH) || (!separate_stencil && (buffers & PIPE_CLEAR_STENCIL))) { |
| 2064 | value.f[0] = subpass->clear_depth; |
| 2065 | value.ui[1] = subpass->clear_stencil; |
| 2066 | fd6_clear_surface<CHIP>(ctx, cs, &pfb->zsbuf, &box2d, |
| 2067 | &value, fd6_unknown_8c01(pfb->zsbuf.format, buffers)); |
| 2068 | } |
| 2069 | |
| 2070 | if (separate_stencil && (buffers & PIPE_CLEAR_STENCIL)) { |
| 2071 | value.ui[0] = subpass->clear_stencil; |
| 2072 | |
| 2073 | struct pipe_surface stencil_surf = pfb->zsbuf; |
| 2074 | stencil_surf.format = PIPE_FORMAT_S8_UINT; |
| 2075 | stencil_surf.texture = separate_stencil; |
| 2076 | |
| 2077 | fd6_clear_surface<CHIP>(ctx, cs, &stencil_surf, &box2d, &value, 0); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | fd6_emit_flushes<CHIP>(ctx, cs, FD6_FLUSH_CCU_COLOR | FD6_INVALIDATE_CCU_COLOR); |
| 2082 | |
| 2083 | trace_end_clears(&batch->trace, cs); |
| 2084 | } |
| 2085 | |
| 2086 | template <chip CHIP> |
| 2087 | static void |
| 2088 | fd6_emit_sysmem_prep(struct fd_batch *batch) assert_dt |
| 2089 | { |
| 2090 | fd_cs cs(batch->gmem); |
| 2091 | |
| 2092 | emit_lrz_clears<CHIP>(batch); |
| 2093 | |
| 2094 | fd6_emit_restore<CHIP>(cs, batch); |
| 2095 | emit_preamble(batch->ctx, cs, true); |
| 2096 | fd6_event_write<CHIP>(batch->ctx, cs, FD_LRZ_FLUSH); |
| 2097 | |
| 2098 | if (batch->prologue) { |
| 2099 | if (!batch->nondraw) { |
| 2100 | trace_start_prologue(&batch->trace, cs); |
| 2101 | } |
| 2102 | fd6_emit_ib<CHIP>(cs, batch->prologue); |
| 2103 | if (!batch->nondraw) { |
| 2104 | trace_end_prologue(&batch->trace, cs); |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | /* remaining setup below here does not apply to blit/compute: */ |
| 2109 | if (batch->nondraw) |
| 2110 | return; |
| 2111 | |
| 2112 | fd6_set_render_mode<CHIP>(cs, {RM6_DIRECT_RENDER}); |
| 2113 | |
| 2114 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 2115 | |
| 2116 | if (pfb->width > 0 && pfb->height > 0) |
| 2117 | set_scissor<CHIP>(cs, 0, 0, pfb->width - 1, pfb->height - 1); |
| 2118 | else |
| 2119 | set_scissor<CHIP>(cs, 0, 0, 0, 0); |
| 2120 | set_blit_scissor(batch, cs); |
| 2121 | |
| 2122 | set_tessfactor_bo<CHIP>(cs, batch); |
| 2123 | |
| 2124 | if (CHIP >= A7XX) { |
| 2125 | /* Non-context regs: */ |
| 2126 | fd_pkt4(cs, 1) |
| 2127 | .add(GRAS_MODE_CNTL(CHIP, 0x2)); |
| 2128 | } |
| 2129 | |
| 2130 | with_crb (cs, 25) { |
| 2131 | set_window_offset<CHIP>(crb, 0, 0); |
| 2132 | |
| 2133 | set_bin_size<CHIP>(crb, NULL, { |
| 2134 | .render_mode = RENDERING_PASS, |
| 2135 | .buffers_location = BUFFERS_IN_SYSMEM, |
| 2136 | .lrz_feedback_zmode_mask = batch->ctx->screen->info->props.has_lrz_feedback |
| 2137 | ? LRZ_FEEDBACK_EARLY_Z_LATE_Z |
| 2138 | : LRZ_FEEDBACK_NONE, |
| 2139 | }); |
| 2140 | |
| 2141 | if (CHIP >= A7XX) { |
| 2142 | crb.add(RB_BUFFER_CNTL(CHIP, |
| 2143 | .z_sysmem = true, |
| 2144 | .s_sysmem = true, |
| 2145 | .rt0_sysmem = true, |
| 2146 | .rt1_sysmem = true, |
| 2147 | .rt2_sysmem = true, |
| 2148 | .rt3_sysmem = true, |
| 2149 | .rt4_sysmem = true, |
| 2150 | .rt5_sysmem = true, |
| 2151 | .rt6_sysmem = true, |
| 2152 | .rt7_sysmem = true, |
| 2153 | )); |
| 2154 | crb.add(GRAS_LRZ_CB_CNTL(CHIP, 0x0)); |
| 2155 | } |
| 2156 | |
| 2157 | /* enable stream-out, with sysmem there is only one pass: */ |
| 2158 | crb.add(VPC_SO_OVERRIDE(CHIP, false)); |
| 2159 | } |
| 2160 | |
| 2161 | fd6_set_render_mode<CHIP>(cs, {RM6_DIRECT_RENDER}); |
| 2162 | |
| 2163 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_GLOBAL, 1) |
| 2164 | .add(0x0); |
| 2165 | |
| 2166 | /* blob controls "local" in IB2, but I think that is not required */ |
| 2167 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_LOCAL, 1) |
| 2168 | .add(0x1); |
| 2169 | |
| 2170 | fd_pkt7(cs, CP_SET_VISIBILITY_OVERRIDE, 1) |
| 2171 | .add(0x1); |
| 2172 | |
| 2173 | with_crb (cs, 150) { |
| 2174 | emit_zs<CHIP>(crb, &pfb->zsbuf, NULL); |
| 2175 | emit_mrt<CHIP>(crb, pfb, NULL); |
| 2176 | emit_msaa<CHIP>(crb, pfb->samples); |
| 2177 | } |
| 2178 | |
| 2179 | emit_common_init<CHIP>(cs, batch); |
| 2180 | |
| 2181 | patch_fb_read_sysmem<CHIP>(batch); |
| 2182 | } |
| 2183 | |
| 2184 | template <chip CHIP> |
| 2185 | static void |
| 2186 | fd6_emit_sysmem(struct fd_batch *batch) |
| 2187 | assert_dt |
| 2188 | { |
| 2189 | struct fd_screen *screen = batch->ctx->screen; |
| 2190 | fd_cs cs(batch->gmem); |
| 2191 | |
| 2192 | fd6_emit_gmem_cache_cntl<CHIP>(cs, screen, false); |
| 2193 | |
| 2194 | if (CHIP >= A7XX) { |
| 2195 | fd7_emit_static_binning_regs<CHIP>(cs, false); |
| 2196 | } |
| 2197 | |
| 2198 | foreach_subpass (subpass, batch) { |
| 2199 | if (subpass->fast_cleared) { |
| 2200 | unsigned flushes = FD6_INVALIDATE_CCHE | FD6_WAIT_FOR_IDLE; |
| 2201 | if (subpass->fast_cleared & FD_BUFFER_COLOR) |
| 2202 | flushes |= FD6_INVALIDATE_CCU_COLOR; |
| 2203 | if (subpass->fast_cleared & (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL)) |
| 2204 | flushes |= FD6_INVALIDATE_CCU_DEPTH; |
| 2205 | |
| 2206 | fd6_emit_flushes<CHIP>(batch->ctx, cs, flushes); |
| 2207 | emit_sysmem_clears<CHIP>(cs, batch, subpass); |
| 2208 | fd6_emit_flushes<CHIP>(batch->ctx, cs, flushes); |
| 2209 | fd6_set_render_mode<CHIP>(cs, {RM6_DIRECT_RENDER}); |
| 2210 | } |
| 2211 | |
| 2212 | struct pipe_framebuffer_state *pfb = &batch->framebuffer; |
| 2213 | update_render_cntl<CHIP>(cs, screen, pfb, false); |
| 2214 | |
| 2215 | emit_lrz<CHIP>(cs, batch, subpass); |
| 2216 | |
| 2217 | fd6_emit_ib<CHIP>(cs, subpass->draw); |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | template <chip CHIP> |
| 2222 | static void |
| 2223 | fd6_emit_sysmem_fini(struct fd_batch *batch) assert_dt |
| 2224 | { |
| 2225 | fd_cs cs(batch->gmem); |
| 2226 | |
| 2227 | batch->barrier |= FD6_FLUSH_CCU_COLOR | |
| 2228 | FD6_INVALIDATE_CCU_COLOR | |
| 2229 | FD6_INVALIDATE_CCHE | |
| 2230 | FD6_FLUSH_CACHE | |
| 2231 | FD6_WAIT_FOR_IDLE; |
| 2232 | |
| 2233 | if (!batch->nondraw) |
| 2234 | batch->barrier |= FD6_FLUSH_CCU_DEPTH | FD6_INVALIDATE_CCU_DEPTH; |
| 2235 | |
| 2236 | emit_common_fini<CHIP>(cs, batch); |
| 2237 | |
| 2238 | if (batch->tile_epilogue) |
| 2239 | fd6_emit_ib<CHIP>(cs, batch->tile_epilogue); |
| 2240 | |
| 2241 | if (batch->epilogue) |
| 2242 | fd6_emit_ib<CHIP>(cs, batch->epilogue); |
| 2243 | |
| 2244 | fd_pkt7(cs, CP_SKIP_IB2_ENABLE_GLOBAL, 1) |
| 2245 | .add(0x0); |
| 2246 | |
| 2247 | if (!batch->nondraw) |
| 2248 | fd6_event_write<CHIP>(batch->ctx, cs, FD_LRZ_FLUSH); |
| 2249 | } |
| 2250 | |
| 2251 | template <chip CHIP> |
| 2252 | void |
| 2253 | fd6_gmem_init(struct pipe_context *pctx) |
| 2254 | disable_thread_safety_analysis |
| 2255 | { |
| 2256 | struct fd_context *ctx = fd_context(pctx); |
| 2257 | |
| 2258 | ctx->emit_tile_init = fd6_emit_tile_init<CHIP>; |
| 2259 | ctx->emit_tile_prep = fd6_emit_tile_prep<CHIP>; |
| 2260 | ctx->emit_tile_mem2gmem = fd6_emit_tile_mem2gmem; |
| 2261 | ctx->emit_tile_renderprep = fd6_emit_tile_renderprep<CHIP>; |
| 2262 | ctx->emit_tile = fd6_emit_tile<CHIP>; |
| 2263 | ctx->emit_tile_gmem2mem = fd6_emit_tile_gmem2mem<CHIP>; |
| 2264 | ctx->emit_tile_fini = fd6_emit_tile_fini<CHIP>; |
| 2265 | ctx->emit_sysmem_prep = fd6_emit_sysmem_prep<CHIP>; |
| 2266 | ctx->emit_sysmem = fd6_emit_sysmem<CHIP>; |
| 2267 | ctx->emit_sysmem_fini = fd6_emit_sysmem_fini<CHIP>; |
| 2268 | } |
| 2269 | FD_GENX(fd6_gmem_init); |