| 1 |
/* |
| 2 |
* Copyright © 2024 Collabora Ltd. |
| 3 |
* Copyright © 2024 Arm Ltd. |
| 4 |
* |
| 5 |
* Derived from tu_cmd_buffer.c which is: |
| 6 |
* Copyright © 2016 Red Hat. |
| 7 |
* Copyright © 2016 Bas Nieuwenhuizen |
| 8 |
* Copyright © 2015 Intel Corporation |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: MIT |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <stdint.h> |
| 14 |
#include "genxml/gen_macros.h" |
| 15 |
|
| 16 |
#include "drm-uapi/panthor_drm.h" |
| 17 |
|
| 18 |
#include "panvk_buffer.h" |
| 19 |
#include "panvk_cmd_alloc.h" |
| 20 |
#include "panvk_cmd_buffer.h" |
| 21 |
#include "panvk_cmd_desc_state.h" |
| 22 |
#include "panvk_cmd_draw.h" |
| 23 |
#include "panvk_cmd_frame_shaders.h" |
| 24 |
#include "panvk_cmd_meta.h" |
| 25 |
#include "panvk_cmd_precomp.h" |
| 26 |
#include "panvk_cmd_ts.h" |
| 27 |
#include "panvk_device.h" |
| 28 |
#include "panvk_entrypoints.h" |
| 29 |
#include "panvk_image.h" |
| 30 |
#include "panvk_image_view.h" |
| 31 |
#include "panvk_instance.h" |
| 32 |
#include "panvk_instr.h" |
| 33 |
#include "panvk_priv_bo.h" |
| 34 |
#include "panvk_query_pool.h" |
| 35 |
#include "panvk_shader.h" |
| 36 |
#include "panvk_tracepoints.h" |
| 37 |
|
| 38 |
#include "pan_desc.h" |
| 39 |
#include "pan_earlyzs.h" |
| 40 |
#include "pan_encoder.h" |
| 41 |
#include "pan_format.h" |
| 42 |
#include "pan_jc.h" |
| 43 |
#include "pan_props.h" |
| 44 |
#include "pan_samples.h" |
| 45 |
#include "pan_shader.h" |
| 46 |
|
| 47 |
#include "util/bitscan.h" |
| 48 |
#include "vk_format.h" |
| 49 |
#include "vk_meta.h" |
| 50 |
#include "vk_pipeline_layout.h" |
| 51 |
#include "vk_render_pass.h" |
| 52 |
#include "poly/geometry.h" |
| 53 |
|
| 54 |
static enum cs_reg_perm |
| 55 |
provoking_vertex_fn_reg_perm_cb(struct cs_builder *b, unsigned reg) |
| 56 |
{ |
| 57 |
return CS_REG_RW; |
| 58 |
} |
| 59 |
|
| 60 |
#define PROVOKING_VERTEX_FN_MAX_SIZE 512 |
| 61 |
|
| 62 |
static size_t |
| 63 |
generate_fn_set_fbds_provoking_vertex(struct panvk_device *dev, |
| 64 |
struct cs_buffer fn_mem, bool has_zs_ext, |
| 65 |
uint32_t rt_count, |
| 66 |
uint32_t *dump_region_size) |
| 67 |
{ |
| 68 |
const struct drm_panthor_csif_info *csif_info = |
| 69 |
panthor_kmod_get_csif_props(dev->kmod.dev); |
| 70 |
|
| 71 |
struct cs_builder b; |
| 72 |
struct cs_builder_conf conf = { |
| 73 |
.nr_registers = csif_info->cs_reg_count, |
| 74 |
.nr_kernel_registers = MAX2(csif_info->unpreserved_cs_reg_count, 4), |
| 75 |
.reg_perm = provoking_vertex_fn_reg_perm_cb, |
| 76 |
.ls_sb_slot = SB_ID(LS), |
| 77 |
}; |
| 78 |
cs_builder_init(&b, &conf, fn_mem); |
| 79 |
|
| 80 |
struct cs_function function; |
| 81 |
struct cs_function_ctx function_ctx = { |
| 82 |
.ctx_reg = cs_subqueue_ctx_reg(&b), |
| 83 |
.dump_addr_offset = |
| 84 |
offsetof(struct panvk_cs_subqueue_context, reg_dump_addr), |
| 85 |
}; |
| 86 |
|
| 87 |
cs_function_def(&b, &function, function_ctx) { |
| 88 |
uint32_t fbd_sz = get_fbd_size(has_zs_ext, rt_count); |
| 89 |
|
| 90 |
/* argument passed in by the caller */ |
| 91 |
struct cs_index fbd_count = cs_scratch_reg32(&b, 0); |
| 92 |
|
| 93 |
/* normal scratch regs */ |
| 94 |
struct cs_index scratch_reg = cs_scratch_reg32(&b, 1); |
| 95 |
struct cs_index fbd_addr = cs_scratch_reg64(&b, 2); |
| 96 |
|
| 97 |
cs_add64(&b, fbd_addr, cs_sr_reg64(&b, FRAGMENT, FBD_POINTER), 0); |
| 98 |
|
| 99 |
cs_while(&b, MALI_CS_CONDITION_GREATER, fbd_count) { |
| 100 |
/* provoking_vertex flag is bit 14 of word 11 */ |
| 101 |
unsigned offset = 11 * 4; |
| 102 |
cs_load32_to(&b, scratch_reg, fbd_addr, offset); |
| 103 |
cs_flush_loads(&b); |
| 104 |
cs_add32(&b, scratch_reg, scratch_reg, -(1 << 14)); |
| 105 |
cs_store32(&b, scratch_reg, fbd_addr, offset); |
| 106 |
cs_flush_stores(&b); |
| 107 |
|
| 108 |
cs_add32(&b, fbd_count, fbd_count, -1); |
| 109 |
cs_add64(&b, fbd_addr, fbd_addr, fbd_sz); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
assert(cs_is_valid(&b)); |
| 114 |
cs_end(&b); |
| 115 |
cs_builder_fini(&b); |
| 116 |
|
| 117 |
*dump_region_size = function.dump_size; |
| 118 |
|
| 119 |
return function.length * sizeof(uint64_t); |
| 120 |
} |
| 121 |
|
| 122 |
static uint32_t |
| 123 |
get_fn_set_fbds_provoking_vertex_idx(bool has_zs_ext, uint32_t rt_count) |
| 124 |
{ |
| 125 |
assert(rt_count >= 1 && rt_count <= MAX_RTS); |
| 126 |
uint32_t idx = has_zs_ext * MAX_RTS + (rt_count - 1); |
| 127 |
assert(idx < 2 * MAX_RTS); |
| 128 |
return idx; |
| 129 |
} |
| 130 |
|
| 131 |
static uint32_t |
| 132 |
calc_fn_set_fbds_provoking_vertex_idx(struct panvk_cmd_buffer *cmdbuf) |
| 133 |
{ |
| 134 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 135 |
const bool has_zs_ext = pan_fb_has_zs(fb); |
| 136 |
|
| 137 |
return get_fn_set_fbds_provoking_vertex_idx(has_zs_ext, fb->rt_count); |
| 138 |
} |
| 139 |
|
| 140 |
VkResult |
| 141 |
panvk_per_arch(device_draw_context_init)(struct panvk_device *dev) |
| 142 |
{ |
| 143 |
dev->draw_ctx = vk_zalloc(&dev->vk.alloc, |
| 144 |
sizeof(struct panvk_device_draw_context), |
| 145 |
_Alignof(struct panvk_device_draw_context), |
| 146 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 147 |
if (dev->draw_ctx == NULL) |
| 148 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 149 |
|
| 150 |
const uint32_t fns_bo_size = PROVOKING_VERTEX_FN_MAX_SIZE * 2 * MAX_RTS; |
| 151 |
VkResult result = panvk_priv_bo_create( |
| 152 |
dev, fns_bo_size, |
| 153 |
panvk_device_adjust_bo_flags(dev, PAN_KMOD_BO_FLAG_WB_MMAP), |
| 154 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE, &dev->draw_ctx->fns_bo); |
| 155 |
if (result != VK_SUCCESS) |
| 156 |
goto free_draw_ctx; |
| 157 |
|
| 158 |
for (uint32_t has_zs_ext = 0; has_zs_ext <= 1; has_zs_ext++) { |
| 159 |
for (uint32_t rt_count = 1; rt_count <= MAX_RTS; rt_count++) { |
| 160 |
uint32_t idx = |
| 161 |
get_fn_set_fbds_provoking_vertex_idx(has_zs_ext, rt_count); |
| 162 |
/* Check that we have calculated a fn_stride if we need it to offset |
| 163 |
* addresses. */ |
| 164 |
assert(idx == 0 || |
| 165 |
dev->draw_ctx->fn_set_fbds_provoking_vertex_stride != 0); |
| 166 |
size_t offset = |
| 167 |
idx * dev->draw_ctx->fn_set_fbds_provoking_vertex_stride; |
| 168 |
|
| 169 |
struct cs_buffer fn_mem = { |
| 170 |
.cpu = dev->draw_ctx->fns_bo->addr.host + offset, |
| 171 |
.gpu = dev->draw_ctx->fns_bo->addr.dev + offset, |
| 172 |
.capacity = PROVOKING_VERTEX_FN_MAX_SIZE / sizeof(uint64_t), |
| 173 |
}; |
| 174 |
|
| 175 |
uint32_t dump_region_size; |
| 176 |
size_t fn_length = |
| 177 |
generate_fn_set_fbds_provoking_vertex(dev, fn_mem, has_zs_ext, |
| 178 |
rt_count, &dump_region_size); |
| 179 |
|
| 180 |
/* All functions must have the same length */ |
| 181 |
assert(idx == 0 || |
| 182 |
fn_length == dev->draw_ctx->fn_set_fbds_provoking_vertex_stride); |
| 183 |
dev->draw_ctx->fn_set_fbds_provoking_vertex_stride = fn_length; |
| 184 |
dev->dump_region_size[PANVK_SUBQUEUE_VERTEX_TILER] = |
| 185 |
MAX2(dev->dump_region_size[PANVK_SUBQUEUE_VERTEX_TILER], |
| 186 |
dump_region_size); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
panvk_priv_bo_flush(dev->draw_ctx->fns_bo, 0, fns_bo_size); |
| 191 |
|
| 192 |
return VK_SUCCESS; |
| 193 |
|
| 194 |
free_draw_ctx: |
| 195 |
vk_free(&dev->vk.alloc, dev->draw_ctx); |
| 196 |
return result; |
| 197 |
} |
| 198 |
|
| 199 |
void |
| 200 |
panvk_per_arch(device_draw_context_cleanup)(struct panvk_device *dev) |
| 201 |
{ |
| 202 |
panvk_priv_bo_unref(dev->draw_ctx->fns_bo); |
| 203 |
vk_free(&dev->vk.alloc, dev->draw_ctx); |
| 204 |
} |
| 205 |
|
| 206 |
static void |
| 207 |
emit_vs_attrib(struct panvk_cmd_buffer *cmdbuf, |
| 208 |
uint32_t attrib_idx, uint32_t vb_desc_offset, |
| 209 |
struct mali_attribute_packed *desc) |
| 210 |
{ |
| 211 |
const struct vk_dynamic_graphics_state *dyns = |
| 212 |
&cmdbuf->vk.dynamic_graphics_state; |
| 213 |
const struct vk_vertex_input_state *vi = dyns->vi; |
| 214 |
const struct vk_vertex_attribute_state *attrib_info = |
| 215 |
&vi->attributes[attrib_idx]; |
| 216 |
const struct vk_vertex_binding_state *buf_info = |
| 217 |
&vi->bindings[attrib_info->binding]; |
| 218 |
const uint32_t stride = dyns->vi_binding_strides[attrib_info->binding]; |
| 219 |
bool per_instance = buf_info->input_rate == VK_VERTEX_INPUT_RATE_INSTANCE; |
| 220 |
enum pipe_format f = vk_format_to_pipe_format(attrib_info->format); |
| 221 |
unsigned buf_idx = vb_desc_offset + attrib_info->binding; |
| 222 |
|
| 223 |
pan_pack(desc, ATTRIBUTE, cfg) { |
| 224 |
cfg.offset = attrib_info->offset; |
| 225 |
|
| 226 |
if (per_instance) |
| 227 |
cfg.offset += cmdbuf->state.gfx.sysvals.vs.base_instance * stride; |
| 228 |
|
| 229 |
cfg.format = GENX(pan_format_from_pipe_format)(f)->hw; |
| 230 |
cfg.table = 0; |
| 231 |
cfg.buffer_index = buf_idx; |
| 232 |
cfg.stride = stride; |
| 233 |
if (!per_instance) { |
| 234 |
/* Per-vertex */ |
| 235 |
cfg.attribute_type = MALI_ATTRIBUTE_TYPE_1D; |
| 236 |
cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_VERTEX; |
| 237 |
cfg.offset_enable = true; |
| 238 |
} else if (buf_info->divisor == 1) { |
| 239 |
cfg.attribute_type = MALI_ATTRIBUTE_TYPE_1D; |
| 240 |
cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_INSTANCE; |
| 241 |
} else if (buf_info->divisor == 0) { |
| 242 |
cfg.attribute_type = MALI_ATTRIBUTE_TYPE_1D; |
| 243 |
/* HW doesn't support a zero divisor, but we can achieve the same by |
| 244 |
* not using a divisor and setting the stride to zero */ |
| 245 |
cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_INSTANCE; |
| 246 |
cfg.stride = 0; |
| 247 |
} else if (util_is_power_of_two_or_zero(buf_info->divisor)) { |
| 248 |
/* Per-instance, POT divisor */ |
| 249 |
cfg.attribute_type = MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR; |
| 250 |
cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_INSTANCE; |
| 251 |
cfg.divisor_r = __builtin_ctz(buf_info->divisor); |
| 252 |
} else { |
| 253 |
/* Per-instance, NPOT divisor */ |
| 254 |
cfg.attribute_type = MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR; |
| 255 |
cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_INSTANCE; |
| 256 |
cfg.divisor_d = pan_compute_npot_divisor( |
| 257 |
buf_info->divisor, &cfg.divisor_r, &cfg.divisor_e); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
static bool |
| 263 |
vs_driver_set_is_dirty(struct panvk_cmd_buffer *cmdbuf) |
| 264 |
{ |
| 265 |
return dyn_gfx_state_dirty(cmdbuf, VI) || |
| 266 |
dyn_gfx_state_dirty(cmdbuf, VI_BINDINGS_VALID) || |
| 267 |
dyn_gfx_state_dirty(cmdbuf, VI_BINDING_STRIDES) || |
| 268 |
gfx_state_dirty(cmdbuf, VB) || gfx_state_dirty(cmdbuf, VS) || |
| 269 |
gfx_state_dirty(cmdbuf, DESC_STATE); |
| 270 |
} |
| 271 |
|
| 272 |
static VkResult |
| 273 |
prepare_vs_driver_set(struct panvk_cmd_buffer *cmdbuf, |
| 274 |
const struct panvk_draw_info *draw) |
| 275 |
{ |
| 276 |
if (!vs_driver_set_is_dirty(cmdbuf)) |
| 277 |
return VK_SUCCESS; |
| 278 |
|
| 279 |
struct panvk_shader_desc_state *vs_desc_state = &cmdbuf->state.gfx.vs.desc; |
| 280 |
const struct panvk_shader_variant *vs = |
| 281 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 282 |
const struct vk_dynamic_graphics_state *dyns = |
| 283 |
&cmdbuf->vk.dynamic_graphics_state; |
| 284 |
const struct vk_vertex_input_state *vi = dyns->vi; |
| 285 |
uint32_t vb_count = 0; |
| 286 |
|
| 287 |
cmdbuf->state.gfx.vi.attribs_changing_on_base_instance = 0; |
| 288 |
u_foreach_bit(i, vi->attributes_valid) { |
| 289 |
const struct vk_vertex_binding_state *binding = |
| 290 |
&vi->bindings[vi->attributes[i].binding]; |
| 291 |
const uint32_t stride = |
| 292 |
dyns->vi_binding_strides[vi->attributes[i].binding]; |
| 293 |
|
| 294 |
if (binding->input_rate == VK_VERTEX_INPUT_RATE_INSTANCE && stride != 0) { |
| 295 |
cmdbuf->state.gfx.vi.attribs_changing_on_base_instance |= |
| 296 |
BITFIELD_BIT(i); |
| 297 |
} |
| 298 |
|
| 299 |
vb_count = MAX2(vi->attributes[i].binding + 1, vb_count); |
| 300 |
} |
| 301 |
|
| 302 |
uint32_t vb_offset = vs->desc_info.dyn_bufs.count + MAX_VS_ATTRIBS + 1; |
| 303 |
uint32_t desc_count = vb_offset + vb_count; |
| 304 |
uint32_t repeat_count = 1; |
| 305 |
|
| 306 |
if (draw->indirect.draw_count > 1 && |
| 307 |
cmdbuf->state.gfx.vi.attribs_changing_on_base_instance != 0) |
| 308 |
repeat_count = draw->indirect.draw_count; |
| 309 |
|
| 310 |
const struct panvk_descriptor_state *desc_state = |
| 311 |
&cmdbuf->state.gfx.desc_state; |
| 312 |
struct pan_ptr driver_set = panvk_cmd_alloc_dev_mem( |
| 313 |
cmdbuf, desc, repeat_count * desc_count * PANVK_DESCRIPTOR_SIZE, |
| 314 |
PANVK_DESCRIPTOR_SIZE); |
| 315 |
struct panvk_opaque_desc *descs = driver_set.cpu; |
| 316 |
|
| 317 |
if (!driver_set.gpu) |
| 318 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 319 |
|
| 320 |
for (uint32_t r = 0; r < repeat_count; r++) { |
| 321 |
for (uint32_t i = 0; i < MAX_VS_ATTRIBS; i++) { |
| 322 |
if (vi->attributes_valid & BITFIELD_BIT(i)) { |
| 323 |
emit_vs_attrib(cmdbuf, i, vb_offset, |
| 324 |
(struct mali_attribute_packed *)(&descs[i])); |
| 325 |
} else { |
| 326 |
/* Write a NullDescriptor and rely on OOB behavior */ |
| 327 |
pan_cast_and_pack(&descs[i], NULL_DESCRIPTOR, cfg) |
| 328 |
; |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
/* Dummy sampler always comes right after the vertex attribs. */ |
| 333 |
pan_cast_and_pack(&descs[MAX_VS_ATTRIBS], SAMPLER, cfg) { |
| 334 |
cfg.clamp_integer_array_indices = false; |
| 335 |
} |
| 336 |
|
| 337 |
panvk_per_arch(cmd_fill_dyn_bufs)( |
| 338 |
desc_state, vs, |
| 339 |
(struct mali_buffer_packed *)(&descs[MAX_VS_ATTRIBS + 1])); |
| 340 |
|
| 341 |
for (uint32_t i = 0; i < vb_count; i++) { |
| 342 |
const struct panvk_attrib_buf *vb = &cmdbuf->state.gfx.vb.bufs[i]; |
| 343 |
const bool nulldesc = (vb->address == 0 && vb->size == 0); |
| 344 |
|
| 345 |
if ((vi->bindings_valid & BITFIELD_BIT(i)) && !nulldesc) { |
| 346 |
pan_cast_and_pack(&descs[vb_offset + i], BUFFER, cfg) { |
| 347 |
cfg.address = vb->address; |
| 348 |
cfg.size = vb->size; |
| 349 |
} |
| 350 |
} else { |
| 351 |
/* Write a NullDescriptor and rely on OOB behavior */ |
| 352 |
pan_cast_and_pack(&descs[vb_offset + i], NULL_DESCRIPTOR, cfg) |
| 353 |
; |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
descs += desc_count; |
| 358 |
} |
| 359 |
|
| 360 |
vs_desc_state->driver_set.dev_addr = driver_set.gpu; |
| 361 |
vs_desc_state->driver_set.size = desc_count * PANVK_DESCRIPTOR_SIZE; |
| 362 |
gfx_state_set_dirty(cmdbuf, DESC_STATE); |
| 363 |
return VK_SUCCESS; |
| 364 |
} |
| 365 |
|
| 366 |
static void |
| 367 |
emit_varying_descs(const struct panvk_cmd_buffer *cmdbuf, |
| 368 |
struct mali_attribute_packed *descs) |
| 369 |
{ |
| 370 |
const struct panvk_shader_variant *vs = |
| 371 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 372 |
const struct panvk_shader_variant *fs = |
| 373 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 374 |
|
| 375 |
const struct pan_varying_layout *vs_layout = &vs->info.varyings.formats; |
| 376 |
const struct pan_varying_layout *fs_format = &fs->info.varyings.formats; |
| 377 |
pan_varying_layout_require_layout(vs_layout); |
| 378 |
pan_varying_layout_require_format(fs_format); |
| 379 |
|
| 380 |
for (uint32_t i = 0; i < fs_format->count; i++) { |
| 381 |
const struct pan_varying_slot *fs_slot = |
| 382 |
pan_varying_layout_slot_at(fs_format, i); |
| 383 |
|
| 384 |
/* Skip empty slots and special varyings. */ |
| 385 |
if (!fs_slot || fs_slot->section != PAN_VARYING_SECTION_GENERIC) |
| 386 |
continue; |
| 387 |
|
| 388 |
unsigned offset = 0; |
| 389 |
enum pipe_format format = PIPE_FORMAT_NONE; |
| 390 |
|
| 391 |
const struct pan_varying_slot *vs_slot = |
| 392 |
pan_varying_layout_find_slot(vs_layout, fs_slot->location); |
| 393 |
if (vs_slot) { |
| 394 |
nir_alu_type base_type = nir_alu_type_get_base_type(fs_slot->alu_type); |
| 395 |
nir_alu_type bit_size = nir_alu_type_get_type_size(vs_slot->alu_type); |
| 396 |
|
| 397 |
offset = vs_slot->offset; |
| 398 |
format = pan_varying_format(base_type | bit_size, vs_slot->ncomps); |
| 399 |
} |
| 400 |
|
| 401 |
pan_pack(&descs[i], ATTRIBUTE, cfg) { |
| 402 |
cfg.attribute_type = MALI_ATTRIBUTE_TYPE_VERTEX_PACKET; |
| 403 |
cfg.offset_enable = false; |
| 404 |
cfg.format = GENX(pan_format_from_pipe_format)(format)->hw; |
| 405 |
cfg.table = 61; |
| 406 |
cfg.frequency = MALI_ATTRIBUTE_FREQUENCY_VERTEX; |
| 407 |
cfg.offset = 1024 + offset; |
| 408 |
/* On v12+, the hardware-controlled buffer is at index 1 for varyings */ |
| 409 |
cfg.buffer_index = PAN_ARCH >= 12 ? 1 : 0; |
| 410 |
cfg.attribute_stride = vs_layout->generic_size_B; |
| 411 |
cfg.packet_stride = vs_layout->generic_size_B + 16; |
| 412 |
} |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
static VkResult |
| 417 |
prepare_fs_driver_set(struct panvk_cmd_buffer *cmdbuf) |
| 418 |
{ |
| 419 |
struct panvk_shader_desc_state *fs_desc_state = &cmdbuf->state.gfx.fs.desc; |
| 420 |
const struct panvk_shader_variant *fs = |
| 421 |
panvk_shader_only_variant(cmdbuf->state.gfx.fs.shader); |
| 422 |
const struct panvk_descriptor_state *desc_state = |
| 423 |
&cmdbuf->state.gfx.desc_state; |
| 424 |
/* If the shader is using LD_VAR_BUF[_IMM], we do not have to set up |
| 425 |
* Attribute Descriptors for varying loads. */ |
| 426 |
const uint32_t desc_count = |
| 427 |
fs->desc_info.fs_varying_attr_desc_count + |
| 428 |
fs->desc_info.dyn_bufs.count + 1; |
| 429 |
struct pan_ptr driver_set = panvk_cmd_alloc_dev_mem( |
| 430 |
cmdbuf, desc, desc_count * PANVK_DESCRIPTOR_SIZE, PANVK_DESCRIPTOR_SIZE); |
| 431 |
struct panvk_opaque_desc *descs = driver_set.cpu; |
| 432 |
|
| 433 |
if (desc_count && !driver_set.gpu) |
| 434 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 435 |
|
| 436 |
if (fs->desc_info.fs_varying_attr_desc_count > 0) |
| 437 |
emit_varying_descs(cmdbuf, (struct mali_attribute_packed *)(&descs[0])); |
| 438 |
|
| 439 |
/* Dummy sampler always comes right after the varyings. */ |
| 440 |
const uint32_t sampler_idx = fs->desc_info.fs_varying_attr_desc_count; |
| 441 |
pan_cast_and_pack(&descs[sampler_idx], SAMPLER, cfg) { |
| 442 |
cfg.clamp_integer_array_indices = false; |
| 443 |
} |
| 444 |
|
| 445 |
panvk_per_arch(cmd_fill_dyn_bufs)( |
| 446 |
desc_state, fs, |
| 447 |
(struct mali_buffer_packed *)(&descs[sampler_idx + 1])); |
| 448 |
|
| 449 |
fs_desc_state->driver_set.dev_addr = driver_set.gpu; |
| 450 |
fs_desc_state->driver_set.size = desc_count * PANVK_DESCRIPTOR_SIZE; |
| 451 |
gfx_state_set_dirty(cmdbuf, DESC_STATE); |
| 452 |
return VK_SUCCESS; |
| 453 |
} |
| 454 |
|
| 455 |
static bool |
| 456 |
has_depth_att(struct panvk_cmd_buffer *cmdbuf) |
| 457 |
{ |
| 458 |
return (cmdbuf->state.gfx.render.bound_attachments & |
| 459 |
MESA_VK_RP_ATTACHMENT_DEPTH_BIT) != 0; |
| 460 |
} |
| 461 |
|
| 462 |
static bool |
| 463 |
has_stencil_att(struct panvk_cmd_buffer *cmdbuf) |
| 464 |
{ |
| 465 |
return (cmdbuf->state.gfx.render.bound_attachments & |
| 466 |
MESA_VK_RP_ATTACHMENT_STENCIL_BIT) != 0; |
| 467 |
} |
| 468 |
|
| 469 |
static bool |
| 470 |
writes_depth(struct panvk_cmd_buffer *cmdbuf) |
| 471 |
{ |
| 472 |
const struct vk_depth_stencil_state *ds = |
| 473 |
&cmdbuf->vk.dynamic_graphics_state.ds; |
| 474 |
|
| 475 |
return has_depth_att(cmdbuf) && ds->depth.test_enable && |
| 476 |
ds->depth.write_enable && ds->depth.compare_op != VK_COMPARE_OP_NEVER; |
| 477 |
} |
| 478 |
|
| 479 |
static bool |
| 480 |
writes_stencil(struct panvk_cmd_buffer *cmdbuf) |
| 481 |
{ |
| 482 |
const struct vk_depth_stencil_state *ds = |
| 483 |
&cmdbuf->vk.dynamic_graphics_state.ds; |
| 484 |
|
| 485 |
return has_stencil_att(cmdbuf) && ds->stencil.test_enable && |
| 486 |
((ds->stencil.front.write_mask && |
| 487 |
(ds->stencil.front.op.fail != VK_STENCIL_OP_KEEP || |
| 488 |
ds->stencil.front.op.pass != VK_STENCIL_OP_KEEP || |
| 489 |
ds->stencil.front.op.depth_fail != VK_STENCIL_OP_KEEP)) || |
| 490 |
(ds->stencil.back.write_mask && |
| 491 |
(ds->stencil.back.op.fail != VK_STENCIL_OP_KEEP || |
| 492 |
ds->stencil.back.op.pass != VK_STENCIL_OP_KEEP || |
| 493 |
ds->stencil.back.op.depth_fail != VK_STENCIL_OP_KEEP))); |
| 494 |
} |
| 495 |
|
| 496 |
static bool |
| 497 |
ds_test_always_passes(struct panvk_cmd_buffer *cmdbuf) |
| 498 |
{ |
| 499 |
const struct vk_depth_stencil_state *ds = |
| 500 |
&cmdbuf->vk.dynamic_graphics_state.ds; |
| 501 |
|
| 502 |
if (!has_depth_att(cmdbuf)) |
| 503 |
return true; |
| 504 |
|
| 505 |
if (ds->depth.test_enable && ds->depth.compare_op != VK_COMPARE_OP_ALWAYS) |
| 506 |
return false; |
| 507 |
|
| 508 |
if (ds->stencil.test_enable && |
| 509 |
(ds->stencil.front.op.compare != VK_COMPARE_OP_ALWAYS || |
| 510 |
ds->stencil.back.op.compare != VK_COMPARE_OP_ALWAYS)) |
| 511 |
return false; |
| 512 |
|
| 513 |
return true; |
| 514 |
} |
| 515 |
|
| 516 |
static inline enum mali_func |
| 517 |
translate_compare_func(VkCompareOp comp) |
| 518 |
{ |
| 519 |
STATIC_ASSERT(VK_COMPARE_OP_NEVER == (VkCompareOp)MALI_FUNC_NEVER); |
| 520 |
STATIC_ASSERT(VK_COMPARE_OP_LESS == (VkCompareOp)MALI_FUNC_LESS); |
| 521 |
STATIC_ASSERT(VK_COMPARE_OP_EQUAL == (VkCompareOp)MALI_FUNC_EQUAL); |
| 522 |
STATIC_ASSERT(VK_COMPARE_OP_LESS_OR_EQUAL == (VkCompareOp)MALI_FUNC_LEQUAL); |
| 523 |
STATIC_ASSERT(VK_COMPARE_OP_GREATER == (VkCompareOp)MALI_FUNC_GREATER); |
| 524 |
STATIC_ASSERT(VK_COMPARE_OP_NOT_EQUAL == (VkCompareOp)MALI_FUNC_NOT_EQUAL); |
| 525 |
STATIC_ASSERT(VK_COMPARE_OP_GREATER_OR_EQUAL == |
| 526 |
(VkCompareOp)MALI_FUNC_GEQUAL); |
| 527 |
STATIC_ASSERT(VK_COMPARE_OP_ALWAYS == (VkCompareOp)MALI_FUNC_ALWAYS); |
| 528 |
|
| 529 |
return (enum mali_func)comp; |
| 530 |
} |
| 531 |
|
| 532 |
static enum mali_stencil_op |
| 533 |
translate_stencil_op(VkStencilOp in) |
| 534 |
{ |
| 535 |
switch (in) { |
| 536 |
case VK_STENCIL_OP_KEEP: |
| 537 |
return MALI_STENCIL_OP_KEEP; |
| 538 |
case VK_STENCIL_OP_ZERO: |
| 539 |
return MALI_STENCIL_OP_ZERO; |
| 540 |
case VK_STENCIL_OP_REPLACE: |
| 541 |
return MALI_STENCIL_OP_REPLACE; |
| 542 |
case VK_STENCIL_OP_INCREMENT_AND_CLAMP: |
| 543 |
return MALI_STENCIL_OP_INCR_SAT; |
| 544 |
case VK_STENCIL_OP_DECREMENT_AND_CLAMP: |
| 545 |
return MALI_STENCIL_OP_DECR_SAT; |
| 546 |
case VK_STENCIL_OP_INCREMENT_AND_WRAP: |
| 547 |
return MALI_STENCIL_OP_INCR_WRAP; |
| 548 |
case VK_STENCIL_OP_DECREMENT_AND_WRAP: |
| 549 |
return MALI_STENCIL_OP_DECR_WRAP; |
| 550 |
case VK_STENCIL_OP_INVERT: |
| 551 |
return MALI_STENCIL_OP_INVERT; |
| 552 |
default: |
| 553 |
UNREACHABLE("Invalid stencil op"); |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
static enum mali_draw_mode |
| 558 |
translate_prim_topology(VkPrimitiveTopology in) |
| 559 |
{ |
| 560 |
/* Test VK_PRIMITIVE_TOPOLOGY_META_RECT_LIST_MESA separately, as it's not |
| 561 |
* part of the VkPrimitiveTopology enum. |
| 562 |
*/ |
| 563 |
if (in == VK_PRIMITIVE_TOPOLOGY_META_RECT_LIST_MESA) |
| 564 |
return MALI_DRAW_MODE_TRIANGLES; |
| 565 |
|
| 566 |
switch (in) { |
| 567 |
case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: |
| 568 |
return MALI_DRAW_MODE_POINTS; |
| 569 |
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: |
| 570 |
return MALI_DRAW_MODE_LINES; |
| 571 |
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: |
| 572 |
return MALI_DRAW_MODE_LINE_STRIP; |
| 573 |
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: |
| 574 |
return MALI_DRAW_MODE_TRIANGLES; |
| 575 |
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: |
| 576 |
return MALI_DRAW_MODE_TRIANGLE_STRIP; |
| 577 |
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: |
| 578 |
return MALI_DRAW_MODE_TRIANGLE_FAN; |
| 579 |
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: |
| 580 |
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: |
| 581 |
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: |
| 582 |
case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: |
| 583 |
case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: |
| 584 |
default: |
| 585 |
UNREACHABLE("Invalid primitive type"); |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
static VkResult |
| 590 |
update_tls(struct panvk_cmd_buffer *cmdbuf) |
| 591 |
{ |
| 592 |
struct panvk_tls_state *state = &cmdbuf->state.tls; |
| 593 |
const struct panvk_shader_variant *vs = |
| 594 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 595 |
const struct panvk_shader_variant *fs = |
| 596 |
panvk_shader_only_variant(cmdbuf->state.gfx.fs.shader); |
| 597 |
struct cs_builder *b = |
| 598 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 599 |
|
| 600 |
if (!cmdbuf->state.gfx.tsd) { |
| 601 |
if (!state->desc.gpu) { |
| 602 |
state->desc = panvk_cmd_alloc_desc(cmdbuf, LOCAL_STORAGE); |
| 603 |
if (!state->desc.gpu) |
| 604 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 605 |
} |
| 606 |
|
| 607 |
cmdbuf->state.gfx.tsd = state->desc.gpu; |
| 608 |
|
| 609 |
cs_update_vt_ctx(b) { |
| 610 |
#if PAN_ARCH >= 12 |
| 611 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VERTEX_TSD), |
| 612 |
state->desc.gpu); |
| 613 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, FRAGMENT_TSD), |
| 614 |
state->desc.gpu); |
| 615 |
#else |
| 616 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, TSD_0), state->desc.gpu); |
| 617 |
#endif |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
state->info.tls.size = |
| 622 |
MAX3(vs->info.tls_size, fs ? fs->info.tls_size : 0, state->info.tls.size); |
| 623 |
return VK_SUCCESS; |
| 624 |
} |
| 625 |
|
| 626 |
static enum mali_index_type |
| 627 |
index_size_to_index_type(uint32_t size) |
| 628 |
{ |
| 629 |
switch (size) { |
| 630 |
case 0: |
| 631 |
return MALI_INDEX_TYPE_NONE; |
| 632 |
case 1: |
| 633 |
return MALI_INDEX_TYPE_UINT8; |
| 634 |
case 2: |
| 635 |
return MALI_INDEX_TYPE_UINT16; |
| 636 |
case 4: |
| 637 |
return MALI_INDEX_TYPE_UINT32; |
| 638 |
default: |
| 639 |
assert(!"Invalid index size"); |
| 640 |
return MALI_INDEX_TYPE_NONE; |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
static VkResult |
| 645 |
prepare_blend(struct panvk_cmd_buffer *cmdbuf) |
| 646 |
{ |
| 647 |
bool dirty = dyn_gfx_state_dirty(cmdbuf, MS_ALPHA_TO_ONE_ENABLE) || |
| 648 |
dyn_gfx_state_dirty(cmdbuf, CB_LOGIC_OP_ENABLE) || |
| 649 |
dyn_gfx_state_dirty(cmdbuf, CB_LOGIC_OP) || |
| 650 |
dyn_gfx_state_dirty(cmdbuf, CB_ATTACHMENT_COUNT) || |
| 651 |
dyn_gfx_state_dirty(cmdbuf, CB_COLOR_WRITE_ENABLES) || |
| 652 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_ENABLES) || |
| 653 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_EQUATIONS) || |
| 654 |
dyn_gfx_state_dirty(cmdbuf, CB_WRITE_MASKS) || |
| 655 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_CONSTANTS) || |
| 656 |
dyn_gfx_state_dirty(cmdbuf, COLOR_ATTACHMENT_MAP) || |
| 657 |
fs_user_dirty(cmdbuf) || gfx_state_dirty(cmdbuf, RENDER_STATE); |
| 658 |
|
| 659 |
if (!dirty) |
| 660 |
return VK_SUCCESS; |
| 661 |
|
| 662 |
const struct panvk_shader_variant *fs = |
| 663 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 664 |
uint32_t bd_count = cmdbuf->state.gfx.render.fb.layout.rt_count; |
| 665 |
struct cs_builder *b = |
| 666 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 667 |
struct pan_ptr ptr = panvk_cmd_alloc_desc_array(cmdbuf, bd_count, BLEND); |
| 668 |
struct mali_blend_packed *bds = ptr.cpu; |
| 669 |
|
| 670 |
if (bd_count && !ptr.gpu) |
| 671 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 672 |
|
| 673 |
if (fs) { |
| 674 |
panvk_per_arch(blend_emit_descs)(cmdbuf, bds); |
| 675 |
} else { |
| 676 |
for (unsigned i = 0; i < bd_count; i++) { |
| 677 |
pan_pack(&bds[i], BLEND, cfg) { |
| 678 |
cfg.enable = false; |
| 679 |
cfg.internal.mode = MALI_BLEND_MODE_OFF; |
| 680 |
} |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
cs_update_vt_ctx(b) |
| 685 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, BLEND_DESC), ptr.gpu | bd_count); |
| 686 |
|
| 687 |
return VK_SUCCESS; |
| 688 |
} |
| 689 |
|
| 690 |
#if PAN_ARCH >= 12 |
| 691 |
static void |
| 692 |
prepare_vp(struct panvk_cmd_buffer *cmdbuf) |
| 693 |
{ |
| 694 |
struct cs_builder *b = |
| 695 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 696 |
const VkViewport *viewport = |
| 697 |
&cmdbuf->vk.dynamic_graphics_state.vp.viewports[0]; |
| 698 |
const VkRect2D *scissor = &cmdbuf->vk.dynamic_graphics_state.vp.scissors[0]; |
| 699 |
|
| 700 |
/* XXX: Switch scissor_array_enable to true and use array based variant |
| 701 |
* for future proofness */ |
| 702 |
|
| 703 |
if (dyn_gfx_state_dirty(cmdbuf, VP_SCISSORS)) { |
| 704 |
struct mali_scissor_packed scissor_box; |
| 705 |
pan_pack(&scissor_box, SCISSOR, cfg) { |
| 706 |
assert(scissor->offset.x >= 0 && scissor->offset.y >= 0); |
| 707 |
|
| 708 |
int minx = scissor->offset.x; |
| 709 |
int miny = scissor->offset.y; |
| 710 |
int maxx = scissor->offset.x + scissor->extent.width; |
| 711 |
int maxy = scissor->offset.y + scissor->extent.height; |
| 712 |
|
| 713 |
/* Make sure we don't end up with a max < min when width/height is 0 */ |
| 714 |
maxx = maxx > minx ? maxx - 1 : maxx; |
| 715 |
maxy = maxy > miny ? maxy - 1 : maxy; |
| 716 |
|
| 717 |
/* Clamp scissor to valid range */ |
| 718 |
cfg.scissor_minimum_x = CLAMP(minx, 0, UINT16_MAX); |
| 719 |
cfg.scissor_minimum_y = CLAMP(miny, 0, UINT16_MAX); |
| 720 |
cfg.scissor_maximum_x = CLAMP(maxx, 0, UINT16_MAX); |
| 721 |
cfg.scissor_maximum_y = CLAMP(maxy, 0, UINT16_MAX); |
| 722 |
} |
| 723 |
|
| 724 |
struct mali_scissor_packed *scissor_box_ptr = &scissor_box; |
| 725 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, SCISSOR_BOX), |
| 726 |
*((uint64_t *)scissor_box_ptr)); |
| 727 |
} |
| 728 |
|
| 729 |
if (dyn_gfx_state_dirty(cmdbuf, VP_VIEWPORTS) || |
| 730 |
dyn_gfx_state_dirty(cmdbuf, VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE) || |
| 731 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLIP_ENABLE) || |
| 732 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLAMP_ENABLE) || |
| 733 |
dyn_gfx_state_dirty(cmdbuf, VP_DEPTH_CLAMP_RANGE)) { |
| 734 |
struct mali_viewport_packed mali_viewport; |
| 735 |
pan_pack(&mali_viewport, VIEWPORT, cfg) { |
| 736 |
/* The spec says "width must be greater than 0.0" */ |
| 737 |
assert(viewport->width >= 0); |
| 738 |
int minx = (int)viewport->x; |
| 739 |
int maxx = (int)(viewport->x + viewport->width); |
| 740 |
|
| 741 |
/* Viewport height can be negative */ |
| 742 |
int miny = |
| 743 |
MIN2((int)viewport->y, (int)(viewport->y + viewport->height)); |
| 744 |
int maxy = |
| 745 |
MAX2((int)viewport->y, (int)(viewport->y + viewport->height)); |
| 746 |
|
| 747 |
/* Make sure we don't end up with a max < min when width/height is 0 */ |
| 748 |
maxx = maxx > minx ? maxx - 1 : maxx; |
| 749 |
maxy = maxy > miny ? maxy - 1 : maxy; |
| 750 |
|
| 751 |
/* Clamp viewport to valid range */ |
| 752 |
cfg.min_x = CLAMP(minx, 0, UINT16_MAX); |
| 753 |
cfg.min_y = CLAMP(miny, 0, UINT16_MAX); |
| 754 |
cfg.max_x = CLAMP(maxx, 0, UINT16_MAX); |
| 755 |
cfg.max_y = CLAMP(maxy, 0, UINT16_MAX); |
| 756 |
|
| 757 |
float z_min, z_max; |
| 758 |
panvk_depth_range(&cmdbuf->state.gfx, |
| 759 |
&cmdbuf->vk.dynamic_graphics_state.vp, |
| 760 |
&z_min, &z_max); |
| 761 |
cfg.min_depth = z_min; |
| 762 |
cfg.max_depth = z_max; |
| 763 |
} |
| 764 |
|
| 765 |
uint64_t *mali_viewport_ptr = (uint64_t *)&mali_viewport; |
| 766 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VIEWPORT_HIGH), |
| 767 |
mali_viewport_ptr[0]); |
| 768 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VIEWPORT_LOW), |
| 769 |
mali_viewport_ptr[1]); |
| 770 |
} |
| 771 |
} |
| 772 |
#else |
| 773 |
static void |
| 774 |
prepare_vp(struct panvk_cmd_buffer *cmdbuf) |
| 775 |
{ |
| 776 |
struct cs_builder *b = |
| 777 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 778 |
const VkViewport *viewport = |
| 779 |
&cmdbuf->vk.dynamic_graphics_state.vp.viewports[0]; |
| 780 |
const VkRect2D *scissor = &cmdbuf->vk.dynamic_graphics_state.vp.scissors[0]; |
| 781 |
|
| 782 |
if (dyn_gfx_state_dirty(cmdbuf, VP_VIEWPORTS) || |
| 783 |
dyn_gfx_state_dirty(cmdbuf, VP_SCISSORS)) { |
| 784 |
struct mali_scissor_packed scissor_box; |
| 785 |
pan_pack(&scissor_box, SCISSOR, cfg) { |
| 786 |
|
| 787 |
/* The spec says "width must be greater than 0.0" */ |
| 788 |
assert(viewport->width >= 0); |
| 789 |
int minx = (int)viewport->x; |
| 790 |
int maxx = (int)(viewport->x + viewport->width); |
| 791 |
|
| 792 |
/* Viewport height can be negative */ |
| 793 |
int miny = |
| 794 |
MIN2((int)viewport->y, (int)(viewport->y + viewport->height)); |
| 795 |
int maxy = |
| 796 |
MAX2((int)viewport->y, (int)(viewport->y + viewport->height)); |
| 797 |
|
| 798 |
assert(scissor->offset.x >= 0 && scissor->offset.y >= 0); |
| 799 |
minx = MAX2(scissor->offset.x, minx); |
| 800 |
miny = MAX2(scissor->offset.y, miny); |
| 801 |
maxx = MIN2(scissor->offset.x + scissor->extent.width, maxx); |
| 802 |
maxy = MIN2(scissor->offset.y + scissor->extent.height, maxy); |
| 803 |
|
| 804 |
/* Make sure we don't end up with a max < min when width/height is 0 */ |
| 805 |
maxx = maxx > minx ? maxx - 1 : maxx; |
| 806 |
maxy = maxy > miny ? maxy - 1 : maxy; |
| 807 |
|
| 808 |
/* Clamp viewport scissor to valid range */ |
| 809 |
cfg.scissor_minimum_x = CLAMP(minx, 0, UINT16_MAX); |
| 810 |
cfg.scissor_minimum_y = CLAMP(miny, 0, UINT16_MAX); |
| 811 |
cfg.scissor_maximum_x = CLAMP(maxx, 0, UINT16_MAX); |
| 812 |
cfg.scissor_maximum_y = CLAMP(maxy, 0, UINT16_MAX); |
| 813 |
} |
| 814 |
|
| 815 |
struct mali_scissor_packed *scissor_box_ptr = &scissor_box; |
| 816 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, SCISSOR_BOX), |
| 817 |
*((uint64_t *)scissor_box_ptr)); |
| 818 |
} |
| 819 |
|
| 820 |
if (dyn_gfx_state_dirty(cmdbuf, VP_VIEWPORTS) || |
| 821 |
dyn_gfx_state_dirty(cmdbuf, VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE) || |
| 822 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLIP_ENABLE) || |
| 823 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLAMP_ENABLE) || |
| 824 |
dyn_gfx_state_dirty(cmdbuf, VP_DEPTH_CLAMP_RANGE)) { |
| 825 |
float z_min, z_max; |
| 826 |
panvk_depth_range(&cmdbuf->state.gfx, |
| 827 |
&cmdbuf->vk.dynamic_graphics_state.vp, &z_min, &z_max); |
| 828 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, LOW_DEPTH_CLAMP), fui(z_min)); |
| 829 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, HIGH_DEPTH_CLAMP), fui(z_max)); |
| 830 |
} |
| 831 |
} |
| 832 |
#endif |
| 833 |
|
| 834 |
#if PAN_ARCH >= 12 |
| 835 |
static inline uint64_t |
| 836 |
get_vs_all_spd(const struct panvk_cmd_buffer *cmdbuf) |
| 837 |
{ |
| 838 |
const struct panvk_shader_variant *vs = |
| 839 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 840 |
assert(vs); |
| 841 |
const struct vk_input_assembly_state *ia = |
| 842 |
&cmdbuf->vk.dynamic_graphics_state.ia; |
| 843 |
return ia->primitive_topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST |
| 844 |
? panvk_priv_mem_dev_addr(vs->spds.all_points) |
| 845 |
: panvk_priv_mem_dev_addr(vs->spds.all_triangles); |
| 846 |
} |
| 847 |
#else |
| 848 |
static inline uint64_t |
| 849 |
get_vs_pos_spd(const struct panvk_cmd_buffer *cmdbuf) |
| 850 |
{ |
| 851 |
const struct panvk_shader_variant *vs = |
| 852 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 853 |
assert(vs); |
| 854 |
const struct vk_input_assembly_state *ia = |
| 855 |
&cmdbuf->vk.dynamic_graphics_state.ia; |
| 856 |
return ia->primitive_topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST |
| 857 |
? panvk_priv_mem_dev_addr(vs->spds.pos_points) |
| 858 |
: panvk_priv_mem_dev_addr(vs->spds.pos_triangles); |
| 859 |
} |
| 860 |
#endif |
| 861 |
|
| 862 |
static void |
| 863 |
prepare_tiler_primitive_size(struct panvk_cmd_buffer *cmdbuf) |
| 864 |
{ |
| 865 |
struct cs_builder *b = |
| 866 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 867 |
const struct vk_input_assembly_state *ia = |
| 868 |
&cmdbuf->vk.dynamic_graphics_state.ia; |
| 869 |
float primitive_size; |
| 870 |
|
| 871 |
if (!dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_TOPOLOGY) && |
| 872 |
!dyn_gfx_state_dirty(cmdbuf, RS_LINE_WIDTH) && |
| 873 |
!gfx_state_dirty(cmdbuf, VS)) |
| 874 |
return; |
| 875 |
|
| 876 |
switch (ia->primitive_topology) { |
| 877 |
/* From the Vulkan spec 1.3.293: |
| 878 |
* |
| 879 |
* "If maintenance5 is enabled and a value is not written to a variable |
| 880 |
* decorated with PointSize, a value of 1.0 is used as the size of |
| 881 |
* points." |
| 882 |
* |
| 883 |
* If no point size is written, ensure that the size is always 1.0f. |
| 884 |
* On v13+, the point size default to 1.0f. |
| 885 |
*/ |
| 886 |
#if PAN_ARCH < 13 |
| 887 |
case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: { |
| 888 |
const struct panvk_shader_variant *vs = |
| 889 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 890 |
|
| 891 |
if (vs->info.vs.writes_point_size) |
| 892 |
return; |
| 893 |
|
| 894 |
primitive_size = 1.0f; |
| 895 |
break; |
| 896 |
} |
| 897 |
#endif |
| 898 |
case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: |
| 899 |
case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: |
| 900 |
primitive_size = cmdbuf->vk.dynamic_graphics_state.rs.line.width; |
| 901 |
break; |
| 902 |
default: |
| 903 |
return; |
| 904 |
} |
| 905 |
|
| 906 |
#if PAN_ARCH >= 13 |
| 907 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, LINE_WIDTH), |
| 908 |
fui(primitive_size)); |
| 909 |
#else |
| 910 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, PRIMITIVE_SIZE), |
| 911 |
fui(primitive_size)); |
| 912 |
#endif |
| 913 |
} |
| 914 |
|
| 915 |
static uint32_t |
| 916 |
calc_enabled_layer_count(struct panvk_cmd_buffer *cmdbuf) |
| 917 |
{ |
| 918 |
return cmdbuf->state.gfx.render.view_mask ? |
| 919 |
util_bitcount(cmdbuf->state.gfx.render.view_mask) : |
| 920 |
cmdbuf->state.gfx.render.layer_count; |
| 921 |
} |
| 922 |
|
| 923 |
static uint32_t |
| 924 |
calc_fbd_size(struct panvk_cmd_buffer *cmdbuf) |
| 925 |
{ |
| 926 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 927 |
const bool has_zs_ext = pan_fb_has_zs(fb); |
| 928 |
|
| 929 |
return get_fbd_size(has_zs_ext, fb->rt_count); |
| 930 |
} |
| 931 |
|
| 932 |
static uint32_t |
| 933 |
calc_render_descs_size(struct panvk_cmd_buffer *cmdbuf) |
| 934 |
{ |
| 935 |
uint32_t fbd_count = calc_enabled_layer_count(cmdbuf); |
| 936 |
uint32_t td_count = DIV_ROUND_UP(cmdbuf->state.gfx.render.layer_count, |
| 937 |
MAX_LAYERS_PER_TILER_DESC); |
| 938 |
|
| 939 |
return (calc_fbd_size(cmdbuf) * fbd_count) + |
| 940 |
(td_count * pan_size(TILER_CONTEXT)); |
| 941 |
} |
| 942 |
|
| 943 |
static void |
| 944 |
cs_render_desc_ringbuf_reserve(struct cs_builder *b, uint32_t size) |
| 945 |
{ |
| 946 |
/* Make sure we don't allocate more than the ringbuf size. */ |
| 947 |
assert(size <= RENDER_DESC_RINGBUF_SIZE); |
| 948 |
|
| 949 |
/* Make sure the allocation is 64-byte aligned. */ |
| 950 |
assert(util_is_aligned(size, 64)); |
| 951 |
|
| 952 |
struct cs_index ringbuf_sync = cs_scratch_reg64(b, 0); |
| 953 |
struct cs_index sz_reg = cs_scratch_reg32(b, 2); |
| 954 |
|
| 955 |
cs_load64_to( |
| 956 |
b, ringbuf_sync, cs_subqueue_ctx_reg(b), |
| 957 |
offsetof(struct panvk_cs_subqueue_context, render.desc_ringbuf.syncobj)); |
| 958 |
|
| 959 |
/* Wait for the other end to release memory. */ |
| 960 |
cs_move32_to(b, sz_reg, size - 1); |
| 961 |
cs_sync32_wait(b, false, MALI_CS_CONDITION_GREATER, sz_reg, ringbuf_sync); |
| 962 |
|
| 963 |
/* Decrement the syncobj to reflect the fact we're reserving memory. */ |
| 964 |
cs_move32_to(b, sz_reg, -size); |
| 965 |
cs_sync32_add(b, false, MALI_CS_SYNC_SCOPE_CSG, sz_reg, ringbuf_sync, |
| 966 |
cs_now()); |
| 967 |
} |
| 968 |
|
| 969 |
static void |
| 970 |
cs_render_desc_ringbuf_move_ptr(struct cs_builder *b, uint32_t size, |
| 971 |
bool wrap_around) |
| 972 |
{ |
| 973 |
struct cs_index scratch_reg = cs_scratch_reg32(b, 0); |
| 974 |
struct cs_index ptr_lo = cs_scratch_reg32(b, 2); |
| 975 |
struct cs_index pos = cs_scratch_reg32(b, 4); |
| 976 |
|
| 977 |
cs_load_to( |
| 978 |
b, cs_scratch_reg_tuple(b, 2, 3), cs_subqueue_ctx_reg(b), |
| 979 |
BITFIELD_MASK(3), |
| 980 |
offsetof(struct panvk_cs_subqueue_context, render.desc_ringbuf.ptr)); |
| 981 |
|
| 982 |
/* Update the relative position and absolute address. */ |
| 983 |
cs_add32(b, ptr_lo, ptr_lo, size); |
| 984 |
cs_add32(b, pos, pos, size); |
| 985 |
|
| 986 |
/* Wrap-around. */ |
| 987 |
if (likely(wrap_around)) { |
| 988 |
cs_add32(b, scratch_reg, pos, -RENDER_DESC_RINGBUF_SIZE); |
| 989 |
|
| 990 |
cs_if(b, MALI_CS_CONDITION_GEQUAL, scratch_reg) { |
| 991 |
cs_add32(b, ptr_lo, ptr_lo, -RENDER_DESC_RINGBUF_SIZE); |
| 992 |
cs_add32(b, pos, pos, -RENDER_DESC_RINGBUF_SIZE); |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
cs_store( |
| 997 |
b, cs_scratch_reg_tuple(b, 2, 3), cs_subqueue_ctx_reg(b), |
| 998 |
BITFIELD_MASK(3), |
| 999 |
offsetof(struct panvk_cs_subqueue_context, render.desc_ringbuf.ptr)); |
| 1000 |
cs_flush_stores(b); |
| 1001 |
} |
| 1002 |
|
| 1003 |
static bool get_first_provoking_vertex(struct panvk_cmd_buffer *cmdbuf); |
| 1004 |
|
| 1005 |
static VkResult |
| 1006 |
get_tiler_desc(struct panvk_cmd_buffer *cmdbuf) |
| 1007 |
{ |
| 1008 |
assert(cmdbuf->state.gfx.render.invalidate_inherited_ctx || |
| 1009 |
!inherits_render_ctx(cmdbuf)); |
| 1010 |
|
| 1011 |
if (cmdbuf->state.gfx.render.tiler) |
| 1012 |
return VK_SUCCESS; |
| 1013 |
|
| 1014 |
struct cs_builder *b = |
| 1015 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1016 |
struct panvk_physical_device *phys_dev = |
| 1017 |
to_panvk_physical_device(cmdbuf->vk.base.device->physical); |
| 1018 |
const bool tracing_enabled = PANVK_DEBUG(TRACE); |
| 1019 |
struct pan_tiler_features tiler_features = |
| 1020 |
pan_query_tiler_features(&phys_dev->kmod.dev->props); |
| 1021 |
bool simul_use = |
| 1022 |
cmdbuf->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 1023 |
struct pan_ptr tiler_desc = {0}; |
| 1024 |
struct mali_tiler_context_packed tiler_tmpl; |
| 1025 |
uint32_t td_count = DIV_ROUND_UP(cmdbuf->state.gfx.render.layer_count, |
| 1026 |
MAX_LAYERS_PER_TILER_DESC); |
| 1027 |
|
| 1028 |
if (!simul_use) { |
| 1029 |
tiler_desc = panvk_cmd_alloc_desc_array(cmdbuf, td_count, TILER_CONTEXT); |
| 1030 |
if (!tiler_desc.gpu) |
| 1031 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 1032 |
} |
| 1033 |
|
| 1034 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 1035 |
|
| 1036 |
/* At this point, we should know sample count and the tile size should have |
| 1037 |
* been calculated */ |
| 1038 |
assert(fb->sample_count > 0 && fb->tile_size_px > 0); |
| 1039 |
|
| 1040 |
pan_pack(&tiler_tmpl, TILER_CONTEXT, cfg) { |
| 1041 |
ASSERTED unsigned max_levels = tiler_features.max_levels; |
| 1042 |
assert(max_levels >= 2); |
| 1043 |
|
| 1044 |
/* The tiler chunk start with a header of 64 bytes */ |
| 1045 |
cfg.hierarchy_mask = panvk_select_tiler_hierarchy_mask( |
| 1046 |
phys_dev, &cmdbuf->state.gfx, phys_dev->csf.tiler.chunk_size - 64); |
| 1047 |
cfg.fb_width = fb->width_px; |
| 1048 |
cfg.fb_height = fb->height_px; |
| 1049 |
|
| 1050 |
#if PAN_ARCH >= 12 |
| 1051 |
cfg.effective_tile_size = fb->tile_size_px; |
| 1052 |
#endif |
| 1053 |
|
| 1054 |
cfg.sample_pattern = pan_sample_pattern(fb->sample_count); |
| 1055 |
|
| 1056 |
cfg.first_provoking_vertex = get_first_provoking_vertex(cmdbuf); |
| 1057 |
|
| 1058 |
/* This will be overloaded. */ |
| 1059 |
cfg.layer_count = 1; |
| 1060 |
cfg.layer_offset = 0; |
| 1061 |
} |
| 1062 |
|
| 1063 |
/* When simul_use=true, the tiler descriptors are allocated from the |
| 1064 |
* descriptor ringbuf. We set state.gfx.render.tiler to a non-NULL |
| 1065 |
* value to satisfy the is_tiler_desc_allocated() tests, but we want |
| 1066 |
* it to point to a faulty address so that we can easily detect if it's |
| 1067 |
* used in the command stream/framebuffer descriptors. */ |
| 1068 |
cmdbuf->state.gfx.render.tiler = |
| 1069 |
simul_use ? 0xdeadbeefdeadbeefull : tiler_desc.gpu; |
| 1070 |
|
| 1071 |
struct cs_index tiler_ctx_addr = cs_sr_reg64(b, IDVS, TILER_CTX); |
| 1072 |
|
| 1073 |
if (simul_use) { |
| 1074 |
uint32_t descs_sz = calc_render_descs_size(cmdbuf); |
| 1075 |
|
| 1076 |
cs_render_desc_ringbuf_reserve(b, descs_sz); |
| 1077 |
|
| 1078 |
/* Reserve ringbuf mem. */ |
| 1079 |
cs_update_vt_ctx(b) { |
| 1080 |
cs_load64_to(b, tiler_ctx_addr, cs_subqueue_ctx_reg(b), |
| 1081 |
offsetof(struct panvk_cs_subqueue_context, |
| 1082 |
render.desc_ringbuf.ptr)); |
| 1083 |
} |
| 1084 |
|
| 1085 |
cs_render_desc_ringbuf_move_ptr(b, descs_sz, !tracing_enabled); |
| 1086 |
} else { |
| 1087 |
cs_update_vt_ctx(b) { |
| 1088 |
cs_move64_to(b, tiler_ctx_addr, tiler_desc.gpu); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
|
| 1092 |
/* Reset the polygon list. */ |
| 1093 |
cs_move64_to(b, cs_scratch_reg64(b, 0), 0); |
| 1094 |
|
| 1095 |
/* Lay out words 2, 3 and 5, so they can be stored along the other updates. |
| 1096 |
* Word 4 contains layer information and will be updated in the loop. */ |
| 1097 |
cs_move64_to(b, cs_scratch_reg64(b, 2), |
| 1098 |
tiler_tmpl.opaque[2] | (uint64_t)tiler_tmpl.opaque[3] << 32); |
| 1099 |
cs_move32_to(b, cs_scratch_reg32(b, 5), tiler_tmpl.opaque[5]); |
| 1100 |
|
| 1101 |
/* Load the tiler_heap and geom_buf from the context. */ |
| 1102 |
cs_load_to(b, cs_scratch_reg_tuple(b, 6, 4), cs_subqueue_ctx_reg(b), |
| 1103 |
BITFIELD_MASK(4), |
| 1104 |
offsetof(struct panvk_cs_subqueue_context, render.tiler_heap)); |
| 1105 |
|
| 1106 |
/* If we don't know what provoking vertex mode the application wants yet, |
| 1107 |
* leave space to patch it later */ |
| 1108 |
if (cmdbuf->state.gfx.render.first_provoking_vertex == U_TRISTATE_UNSET) { |
| 1109 |
cs_maybe(b, &cmdbuf->state.gfx.render.maybe_set_tds_provoking_vertex) |
| 1110 |
/* provoking_vertex flag is bit 18 of word 2 */ |
| 1111 |
cs_add32(b, cs_scratch_reg32(b, 2), cs_scratch_reg32(b, 2), |
| 1112 |
-(1 << 18)); |
| 1113 |
} |
| 1114 |
|
| 1115 |
/* Fill extra fields with zeroes so we can reset the completed |
| 1116 |
* top/bottom and private states. */ |
| 1117 |
cs_move64_to(b, cs_scratch_reg64(b, 10), 0); |
| 1118 |
cs_move64_to(b, cs_scratch_reg64(b, 12), 0); |
| 1119 |
cs_move64_to(b, cs_scratch_reg64(b, 14), 0); |
| 1120 |
|
| 1121 |
/* Take care of the tiler desc with layer_offset=0 outside of the loop. */ |
| 1122 |
cs_move32_to(b, cs_scratch_reg32(b, 4), |
| 1123 |
MIN2(cmdbuf->state.gfx.render.layer_count - 1, |
| 1124 |
MAX_LAYERS_PER_TILER_DESC - 1)); |
| 1125 |
|
| 1126 |
/* Replace words 0:13 and 24:31. */ |
| 1127 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1128 |
BITFIELD_MASK(16), 0); |
| 1129 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1130 |
BITFIELD_RANGE(0, 2) | BITFIELD_RANGE(10, 6), 64); |
| 1131 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1132 |
BITFIELD_RANGE(0, 2) | BITFIELD_RANGE(10, 6), 96); |
| 1133 |
|
| 1134 |
uint32_t remaining_layers = |
| 1135 |
td_count > 1 |
| 1136 |
? cmdbuf->state.gfx.render.layer_count % MAX_LAYERS_PER_TILER_DESC |
| 1137 |
: 0; |
| 1138 |
uint32_t full_td_count = |
| 1139 |
cmdbuf->state.gfx.render.layer_count / MAX_LAYERS_PER_TILER_DESC; |
| 1140 |
|
| 1141 |
if (remaining_layers) { |
| 1142 |
int32_t layer_offset = |
| 1143 |
-(cmdbuf->state.gfx.render.layer_count - remaining_layers) & |
| 1144 |
BITFIELD_MASK(9); |
| 1145 |
|
| 1146 |
/* If the last tiler descriptor is not full, we emit it outside of the |
| 1147 |
* loop to pass the right layer count. All this would be a lot simpler |
| 1148 |
* if we had OR/AND instructions, but here we are. */ |
| 1149 |
cs_update_vt_ctx(b) |
| 1150 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 1151 |
pan_size(TILER_CONTEXT) * full_td_count); |
| 1152 |
cs_move32_to(b, cs_scratch_reg32(b, 4), |
| 1153 |
(layer_offset << 8) | (remaining_layers - 1)); |
| 1154 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1155 |
BITFIELD_MASK(16), 0); |
| 1156 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1157 |
BITFIELD_RANGE(0, 2) | BITFIELD_RANGE(10, 6), 64); |
| 1158 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1159 |
BITFIELD_RANGE(0, 2) | BITFIELD_RANGE(10, 6), 96); |
| 1160 |
|
| 1161 |
cs_update_vt_ctx(b) |
| 1162 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 1163 |
-pan_size(TILER_CONTEXT)); |
| 1164 |
} else if (full_td_count > 1) { |
| 1165 |
cs_update_vt_ctx(b) |
| 1166 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 1167 |
pan_size(TILER_CONTEXT) * (full_td_count - 1)); |
| 1168 |
} |
| 1169 |
|
| 1170 |
if (full_td_count > 1) { |
| 1171 |
struct cs_index counter_reg = cs_scratch_reg32(b, 17); |
| 1172 |
uint32_t layer_offset = |
| 1173 |
(-MAX_LAYERS_PER_TILER_DESC * (full_td_count - 1)) & BITFIELD_MASK(9); |
| 1174 |
|
| 1175 |
cs_move32_to(b, counter_reg, full_td_count - 1); |
| 1176 |
cs_move32_to(b, cs_scratch_reg32(b, 4), |
| 1177 |
(layer_offset << 8) | (MAX_LAYERS_PER_TILER_DESC - 1)); |
| 1178 |
|
| 1179 |
/* We iterate the remaining full tiler descriptors in reverse order, so we |
| 1180 |
* can start from the smallest layer offset, and increment it by |
| 1181 |
* MAX_LAYERS_PER_TILER_DESC << 8 at each iteration. Again, the split is |
| 1182 |
* mostly due to the lack of AND instructions, and the fact layer_offset |
| 1183 |
* is a 9-bit signed integer inside a 32-bit word, which ADD32 can't deal |
| 1184 |
* with unless the number we add is positive. |
| 1185 |
*/ |
| 1186 |
cs_while(b, MALI_CS_CONDITION_GREATER, counter_reg) { |
| 1187 |
/* Replace words 0:13 and 24:31. */ |
| 1188 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1189 |
BITFIELD_MASK(16), 0); |
| 1190 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1191 |
BITFIELD_RANGE(0, 2) | BITFIELD_RANGE(10, 6), 64); |
| 1192 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), tiler_ctx_addr, |
| 1193 |
BITFIELD_RANGE(0, 2) | BITFIELD_RANGE(10, 6), 96); |
| 1194 |
|
| 1195 |
cs_add32(b, cs_scratch_reg32(b, 4), cs_scratch_reg32(b, 4), |
| 1196 |
MAX_LAYERS_PER_TILER_DESC << 8); |
| 1197 |
|
| 1198 |
cs_add32(b, counter_reg, counter_reg, -1); |
| 1199 |
cs_update_vt_ctx(b) |
| 1200 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 1201 |
-pan_size(TILER_CONTEXT)); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
/* Flush all stores to tiler_ctx_addr. */ |
| 1206 |
cs_flush_stores(b); |
| 1207 |
|
| 1208 |
cs_next_iter_sb(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER, |
| 1209 |
cs_scratch_reg_tuple(b, 0, 2)); |
| 1210 |
|
| 1211 |
cs_vt_start(b, cs_now()); |
| 1212 |
return VK_SUCCESS; |
| 1213 |
} |
| 1214 |
|
| 1215 |
static struct pan_tiler_context |
| 1216 |
get_tiler_context(struct panvk_cmd_buffer *cmdbuf, uint32_t layer) |
| 1217 |
{ |
| 1218 |
struct pan_tiler_context tiler_ctx = { |
| 1219 |
.valhall.layer_offset = layer - (layer % MAX_LAYERS_PER_TILER_DESC), |
| 1220 |
}; |
| 1221 |
|
| 1222 |
if (!(cmdbuf->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) && |
| 1223 |
(cmdbuf->state.gfx.render.tiler != 0)) { |
| 1224 |
uint32_t td_idx = layer / MAX_LAYERS_PER_TILER_DESC; |
| 1225 |
|
| 1226 |
tiler_ctx.valhall.desc = |
| 1227 |
cmdbuf->state.gfx.render.tiler + (td_idx * pan_size(TILER_CONTEXT)); |
| 1228 |
} |
| 1229 |
|
| 1230 |
return tiler_ctx; |
| 1231 |
} |
| 1232 |
|
| 1233 |
static VkResult |
| 1234 |
get_fb_descs(struct panvk_cmd_buffer *cmdbuf) |
| 1235 |
{ |
| 1236 |
assert(cmdbuf->state.gfx.render.invalidate_inherited_ctx || |
| 1237 |
!inherits_render_ctx(cmdbuf)); |
| 1238 |
|
| 1239 |
if (cmdbuf->state.gfx.render.fbds.gpu || |
| 1240 |
!cmdbuf->state.gfx.render.layer_count) |
| 1241 |
return VK_SUCCESS; |
| 1242 |
|
| 1243 |
uint32_t view_mask_temp = cmdbuf->state.gfx.render.view_mask; |
| 1244 |
uint32_t enabled_layer_count = calc_enabled_layer_count(cmdbuf); |
| 1245 |
uint32_t fbd_sz = calc_fbd_size(cmdbuf); |
| 1246 |
uint32_t fbds_sz = enabled_layer_count * fbd_sz; |
| 1247 |
|
| 1248 |
cmdbuf->state.gfx.render.fbds = panvk_cmd_alloc_dev_mem( |
| 1249 |
cmdbuf, desc, fbds_sz, pan_alignment(FRAMEBUFFER)); |
| 1250 |
if (!cmdbuf->state.gfx.render.fbds.gpu) |
| 1251 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 1252 |
|
| 1253 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 1254 |
struct panvk_rendering_state *render = &cmdbuf->state.gfx.render; |
| 1255 |
|
| 1256 |
/* At this point, we should know sample count and the tile size should have |
| 1257 |
* been calculated */ |
| 1258 |
assert(render->fb.layout.sample_count > 0); |
| 1259 |
assert(render->fb.layout.tile_size_px > 0); |
| 1260 |
const uint8_t sample_count = render->fb.layout.sample_count; |
| 1261 |
|
| 1262 |
bool simul_use = |
| 1263 |
cmdbuf->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 1264 |
|
| 1265 |
/* The only bit we patch in FBDs is the tiler pointer. If tiler is not |
| 1266 |
* involved (clear job) or if the update can happen in place (not |
| 1267 |
* simultaneous use of the command buffer), we can avoid the |
| 1268 |
* copy. |
| 1269 |
* |
| 1270 |
* According to VUID-VkSubmitInfo2KHR-commandBuffer-06192 and |
| 1271 |
* VUID-VkSubmitInfo2KHR-commandBuffer-06010, suspend/resume operations |
| 1272 |
* can't cross the vkQueueSubmit2() boundary, so no need to dynamically |
| 1273 |
* allocate descriptors in that case: |
| 1274 |
* " |
| 1275 |
* If any commandBuffer member of an element of pCommandBufferInfos |
| 1276 |
* contains any suspended render pass instances, they must be resumed by a |
| 1277 |
* render pass instance later in submission order within |
| 1278 |
* pCommandBufferInfos. |
| 1279 |
* |
| 1280 |
* If any commandBuffer member of an element of pCommandBufferInfos |
| 1281 |
* contains any resumed render pass instances, they must be suspended by a |
| 1282 |
* render pass instance earlier in submission order within |
| 1283 |
* pCommandBufferInfos. |
| 1284 |
* " |
| 1285 |
*/ |
| 1286 |
bool copy_fbds = simul_use && cmdbuf->state.gfx.render.tiler; |
| 1287 |
struct pan_ptr fbds = cmdbuf->state.gfx.render.fbds; |
| 1288 |
uint32_t fbd_flags = 0; |
| 1289 |
|
| 1290 |
/* We prepare all FB descriptors upfront. For multiview, only create FBDs |
| 1291 |
* for enabled views. */ |
| 1292 |
bool multiview = cmdbuf->state.gfx.render.view_mask; |
| 1293 |
|
| 1294 |
struct pan_tiler_context tiler_ctx; |
| 1295 |
struct pan_fb_desc_info fbd_info = { |
| 1296 |
.fb = &render->fb.layout, |
| 1297 |
.load = &render->fb.load, |
| 1298 |
.store = &render->fb.store, |
| 1299 |
.sample_pos_array_pointer = dev->sample_positions->addr.dev + |
| 1300 |
pan_sample_positions_offset(pan_sample_pattern(sample_count)), |
| 1301 |
.provoking_vertex_first = get_first_provoking_vertex(cmdbuf), |
| 1302 |
.allow_hsr_prepass = PAN_ARCH >= 13 && PANVK_DEBUG(HSR_PREPASS), |
| 1303 |
.tiler_ctx = &tiler_ctx, |
| 1304 |
}; |
| 1305 |
|
| 1306 |
VkResult result = panvk_per_arch(cmd_get_frame_shaders)( |
| 1307 |
cmdbuf, fbd_info.fb, fbd_info.load, &render->fb.resolve, |
| 1308 |
&fbd_info.frame_shaders); |
| 1309 |
if (result != VK_SUCCESS) |
| 1310 |
return result; |
| 1311 |
|
| 1312 |
for (uint32_t i = 0; i < enabled_layer_count; i++) { |
| 1313 |
uint32_t layer_idx = multiview ? u_bit_scan(&view_mask_temp) : i; |
| 1314 |
|
| 1315 |
fbd_info.layer = layer_idx; |
| 1316 |
tiler_ctx = get_tiler_context(cmdbuf, layer_idx); |
| 1317 |
|
| 1318 |
uint32_t new_fbd_flags = |
| 1319 |
GENX(pan_emit_fb_desc)(&fbd_info, fbds.cpu + fbd_sz * i); |
| 1320 |
|
| 1321 |
/* Make sure all FBDs have the same flags. */ |
| 1322 |
assert(i == 0 || new_fbd_flags == fbd_flags); |
| 1323 |
fbd_flags = new_fbd_flags; |
| 1324 |
} |
| 1325 |
|
| 1326 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_FRAGMENT); |
| 1327 |
for (uint32_t ir_pass = 0; ir_pass < PANVK_IR_PASS_COUNT; ir_pass++) { |
| 1328 |
struct pan_ptr ir_fbds = panvk_cmd_alloc_dev_mem( |
| 1329 |
cmdbuf, desc, fbds_sz, pan_alignment(FRAMEBUFFER)); |
| 1330 |
|
| 1331 |
if (!ir_fbds.gpu) |
| 1332 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 1333 |
|
| 1334 |
uint32_t ir_view_mask_temp = cmdbuf->state.gfx.render.view_mask; |
| 1335 |
|
| 1336 |
for (uint32_t i = 0; i < enabled_layer_count; i++) { |
| 1337 |
uint32_t layer_idx = multiview ? u_bit_scan(&ir_view_mask_temp) : i; |
| 1338 |
void *ir_fbd = (void *)((uint8_t *)ir_fbds.cpu + (i * fbd_sz)); |
| 1339 |
|
| 1340 |
fbd_info.layer = layer_idx; |
| 1341 |
tiler_ctx = get_tiler_context(cmdbuf, layer_idx); |
| 1342 |
fbd_info.load = ir_pass == PANVK_IR_FIRST_PASS |
| 1343 |
? &render->fb.load |
| 1344 |
: &render->fb.spill.load; |
| 1345 |
fbd_info.store = ir_pass == PANVK_IR_LAST_PASS |
| 1346 |
? &render->fb.store |
| 1347 |
: &render->fb.spill.store; |
| 1348 |
|
| 1349 |
VkResult result = panvk_per_arch(cmd_get_frame_shaders)( |
| 1350 |
cmdbuf, fbd_info.fb, fbd_info.load, |
| 1351 |
ir_pass == PANVK_IR_LAST_PASS ? &render->fb.resolve : NULL, |
| 1352 |
&fbd_info.frame_shaders); |
| 1353 |
if (result != VK_SUCCESS) |
| 1354 |
return result; |
| 1355 |
|
| 1356 |
ASSERTED uint32_t new_fbd_flags = |
| 1357 |
GENX(pan_emit_fb_desc)(&fbd_info, ir_fbd); |
| 1358 |
|
| 1359 |
/* Make sure all FBDs have the same flags. */ |
| 1360 |
assert(new_fbd_flags == fbd_flags); |
| 1361 |
} |
| 1362 |
|
| 1363 |
static_assert(ARRAY_SIZE(cmdbuf->state.gfx.render.ir.fbds) == PANVK_IR_PASS_COUNT, |
| 1364 |
"ir.fbds array size must match PANVK_IR_PASS_COUNT"); |
| 1365 |
cmdbuf->state.gfx.render.ir.fbds[ir_pass] = ir_fbds.gpu; |
| 1366 |
} |
| 1367 |
|
| 1368 |
/* Wait for IR info push to complete */ |
| 1369 |
cs_wait_slot(b, SB_ID(LS)); |
| 1370 |
|
| 1371 |
bool unset_provoking_vertex = |
| 1372 |
cmdbuf->state.gfx.render.first_provoking_vertex == U_TRISTATE_UNSET; |
| 1373 |
|
| 1374 |
if (copy_fbds) { |
| 1375 |
struct cs_index cur_tiler = cs_reg64(b, 38); |
| 1376 |
struct cs_index dst_fbd_ptr = cs_sr_reg64(b, FRAGMENT, FBD_POINTER); |
| 1377 |
struct cs_index fbd_idx = cs_reg32(b, 47); |
| 1378 |
struct cs_index src_fbd_ptr = cs_reg64(b, 48); |
| 1379 |
struct cs_index remaining_layers_in_td = cs_reg32(b, 50); |
| 1380 |
uint32_t td_count = DIV_ROUND_UP(cmdbuf->state.gfx.render.layer_count, |
| 1381 |
MAX_LAYERS_PER_TILER_DESC); |
| 1382 |
|
| 1383 |
cs_update_frag_ctx(b) { |
| 1384 |
cs_load64_to(b, cur_tiler, cs_subqueue_ctx_reg(b), |
| 1385 |
offsetof(struct panvk_cs_subqueue_context, |
| 1386 |
render.desc_ringbuf.ptr)); |
| 1387 |
cs_add64(b, dst_fbd_ptr, cur_tiler, |
| 1388 |
pan_size(TILER_CONTEXT) * td_count); |
| 1389 |
} |
| 1390 |
|
| 1391 |
cs_move64_to(b, src_fbd_ptr, fbds.gpu); |
| 1392 |
|
| 1393 |
/* Copy FBDs for layer regular pass */ |
| 1394 |
cs_move32_to(b, remaining_layers_in_td, MAX_LAYERS_PER_TILER_DESC); |
| 1395 |
cs_move32_to(b, fbd_idx, enabled_layer_count); |
| 1396 |
cs_while(b, MALI_CS_CONDITION_GREATER, fbd_idx) { |
| 1397 |
cs_add32(b, fbd_idx, fbd_idx, -1); |
| 1398 |
|
| 1399 |
/* Our loop is copying 64-bytes at a time, so make sure the |
| 1400 |
* framebuffer size is aligned on 64-bytes. */ |
| 1401 |
assert(fbd_sz == ALIGN_POT(fbd_sz, 64)); |
| 1402 |
|
| 1403 |
for (uint32_t fbd_off = 0; fbd_off < fbd_sz; fbd_off += 64) { |
| 1404 |
if (fbd_off == 0) { |
| 1405 |
cs_load_to(b, cs_scratch_reg_tuple(b, 0, 14), src_fbd_ptr, |
| 1406 |
BITFIELD_MASK(14), fbd_off); |
| 1407 |
cs_add64(b, cs_scratch_reg64(b, 14), cur_tiler, 0); |
| 1408 |
|
| 1409 |
/* If we don't know what provoking vertex mode the |
| 1410 |
* application wants yet, leave space to patch it later. */ |
| 1411 |
if (unset_provoking_vertex) { |
| 1412 |
/* Provoking_vertex flag is bit 14 of word 11 */ |
| 1413 |
struct cs_index word = cs_scratch_reg32(b, 11); |
| 1414 |
cs_maybe( |
| 1415 |
b, |
| 1416 |
&cmdbuf->state.gfx.render.maybe_set_fbds_provoking_vertex) |
| 1417 |
cs_add32(b, word, word, -(1 << 14)); |
| 1418 |
} |
| 1419 |
} else { |
| 1420 |
cs_load_to(b, cs_scratch_reg_tuple(b, 0, 16), src_fbd_ptr, |
| 1421 |
BITFIELD_MASK(16), fbd_off); |
| 1422 |
} |
| 1423 |
cs_store(b, cs_scratch_reg_tuple(b, 0, 16), dst_fbd_ptr, |
| 1424 |
BITFIELD_MASK(16), fbd_off); |
| 1425 |
} |
| 1426 |
|
| 1427 |
/* Finish stores to pass_dst_fbd_ptr. */ |
| 1428 |
cs_flush_stores(b); |
| 1429 |
|
| 1430 |
cs_add64(b, src_fbd_ptr, src_fbd_ptr, fbd_sz); |
| 1431 |
cs_update_frag_ctx(b) |
| 1432 |
cs_add64(b, dst_fbd_ptr, dst_fbd_ptr, fbd_sz); |
| 1433 |
|
| 1434 |
cs_add32(b, remaining_layers_in_td, remaining_layers_in_td, -1); |
| 1435 |
cs_if(b, MALI_CS_CONDITION_LEQUAL, remaining_layers_in_td) { |
| 1436 |
cs_update_frag_ctx(b) |
| 1437 |
cs_add64(b, cur_tiler, cur_tiler, pan_size(TILER_CONTEXT)); |
| 1438 |
cs_move32_to(b, remaining_layers_in_td, |
| 1439 |
MAX_LAYERS_PER_TILER_DESC); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
cs_update_frag_ctx(b) { |
| 1444 |
uint32_t full_td_count = |
| 1445 |
cmdbuf->state.gfx.render.layer_count / MAX_LAYERS_PER_TILER_DESC; |
| 1446 |
|
| 1447 |
/* If the last tiler descriptor is not full, cur_tiler points to the |
| 1448 |
* last tiler descriptor, not the FBD that follows. */ |
| 1449 |
if (full_td_count < td_count) |
| 1450 |
cs_add64(b, dst_fbd_ptr, cur_tiler, |
| 1451 |
fbd_flags + pan_size(TILER_CONTEXT)); |
| 1452 |
else |
| 1453 |
cs_add64(b, dst_fbd_ptr, cur_tiler, fbd_flags); |
| 1454 |
|
| 1455 |
cs_add64(b, cur_tiler, cur_tiler, |
| 1456 |
-(full_td_count * pan_size(TILER_CONTEXT))); |
| 1457 |
} |
| 1458 |
} else { |
| 1459 |
cs_update_frag_ctx(b) { |
| 1460 |
cs_move64_to(b, cs_sr_reg64(b, FRAGMENT, FBD_POINTER), |
| 1461 |
fbds.gpu | fbd_flags); |
| 1462 |
cs_move64_to(b, cs_reg64(b, 38), cmdbuf->state.gfx.render.tiler); |
| 1463 |
} |
| 1464 |
|
| 1465 |
/* If we don't know what provoking vertex mode the application wants yet, |
| 1466 |
* leave space to patch it later */ |
| 1467 |
if (cmdbuf->state.gfx.render.first_provoking_vertex == U_TRISTATE_UNSET) { |
| 1468 |
uint32_t fbd_count = calc_enabled_layer_count(cmdbuf); |
| 1469 |
/* passed to fn_set_fbds_provoking_vertex */ |
| 1470 |
struct cs_index fbd_count_reg = cs_scratch_reg32(b, 0); |
| 1471 |
cs_move32_to(b, fbd_count_reg, fbd_count); |
| 1472 |
|
| 1473 |
struct cs_index length_reg = cs_scratch_reg32(b, 1); |
| 1474 |
struct cs_index addr_reg = cs_scratch_reg64(b, 2); |
| 1475 |
uint32_t fn_idx = calc_fn_set_fbds_provoking_vertex_idx(cmdbuf); |
| 1476 |
uint32_t fn_stride = |
| 1477 |
dev->draw_ctx->fn_set_fbds_provoking_vertex_stride; |
| 1478 |
uint32_t fn_addr = |
| 1479 |
dev->draw_ctx->fns_bo->addr.dev + fn_idx * fn_stride; |
| 1480 |
cs_move64_to(b, addr_reg, fn_addr); |
| 1481 |
cs_move32_to(b, length_reg, fn_stride); |
| 1482 |
|
| 1483 |
cs_maybe(b, &cmdbuf->state.gfx.render.maybe_set_fbds_provoking_vertex) |
| 1484 |
cs_call(b, addr_reg, length_reg); |
| 1485 |
} |
| 1486 |
} |
| 1487 |
|
| 1488 |
return VK_SUCCESS; |
| 1489 |
} |
| 1490 |
|
| 1491 |
static bool |
| 1492 |
get_first_provoking_vertex(struct panvk_cmd_buffer *cmdbuf) |
| 1493 |
{ |
| 1494 |
switch (cmdbuf->state.gfx.render.first_provoking_vertex) { |
| 1495 |
case U_TRISTATE_NO: |
| 1496 |
return false; |
| 1497 |
case U_TRISTATE_YES: |
| 1498 |
return true; |
| 1499 |
/* If we don't know the provoking vertex mode yet, guess that it will |
| 1500 |
* be PROVOKING_VERTEX_MODE_FIRST. This is the vulkan default, and so |
| 1501 |
* likely to be right more often. */ |
| 1502 |
case U_TRISTATE_UNSET: |
| 1503 |
return true; |
| 1504 |
default: |
| 1505 |
UNREACHABLE("Invalid u_tristate"); |
| 1506 |
} |
| 1507 |
} |
| 1508 |
|
| 1509 |
static void |
| 1510 |
set_provoking_vertex_mode(struct panvk_cmd_buffer *cmdbuf, |
| 1511 |
enum u_tristate first_provoking_vertex) |
| 1512 |
{ |
| 1513 |
struct panvk_cmd_graphics_state *state = &cmdbuf->state.gfx; |
| 1514 |
|
| 1515 |
if (first_provoking_vertex != U_TRISTATE_UNSET) { |
| 1516 |
/* If this is not the first draw, first_provoking_vertex should match |
| 1517 |
* the one from the previous draws. Unfortunately, we can't check it |
| 1518 |
* when the render pass is inherited. */ |
| 1519 |
assert(state->render.first_provoking_vertex == U_TRISTATE_UNSET || |
| 1520 |
state->render.first_provoking_vertex == first_provoking_vertex); |
| 1521 |
state->render.first_provoking_vertex = first_provoking_vertex; |
| 1522 |
} |
| 1523 |
|
| 1524 |
/* If the application uses PROVOKING_VERTEX_MODE_LAST after we previously |
| 1525 |
* emitted FBDs/TDs with the wrong mode set, patch the CS to flip the |
| 1526 |
* provoking vertex mode bits. */ |
| 1527 |
if (state->render.first_provoking_vertex == U_TRISTATE_NO && |
| 1528 |
state->render.maybe_set_tds_provoking_vertex) |
| 1529 |
{ |
| 1530 |
struct cs_builder *b = |
| 1531 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1532 |
cs_patch_maybe(b, state->render.maybe_set_tds_provoking_vertex); |
| 1533 |
state->render.maybe_set_tds_provoking_vertex = NULL; |
| 1534 |
} |
| 1535 |
if (state->render.first_provoking_vertex == U_TRISTATE_NO && |
| 1536 |
state->render.maybe_set_fbds_provoking_vertex) { |
| 1537 |
struct cs_builder *b = |
| 1538 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_FRAGMENT); |
| 1539 |
cs_patch_maybe(b, state->render.maybe_set_fbds_provoking_vertex); |
| 1540 |
state->render.maybe_set_fbds_provoking_vertex = NULL; |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
static VkResult |
| 1545 |
get_render_ctx(struct panvk_cmd_buffer *cmdbuf) |
| 1546 |
{ |
| 1547 |
panvk_per_arch(cmd_select_tile_size)(cmdbuf); |
| 1548 |
|
| 1549 |
VkResult result = get_tiler_desc(cmdbuf); |
| 1550 |
if (result != VK_SUCCESS) |
| 1551 |
return result; |
| 1552 |
|
| 1553 |
return get_fb_descs(cmdbuf); |
| 1554 |
} |
| 1555 |
|
| 1556 |
static VkResult |
| 1557 |
prepare_vs(struct panvk_cmd_buffer *cmdbuf, const struct panvk_draw_info *draw) |
| 1558 |
{ |
| 1559 |
struct panvk_descriptor_state *desc_state = &cmdbuf->state.gfx.desc_state; |
| 1560 |
struct panvk_shader_desc_state *vs_desc_state = &cmdbuf->state.gfx.vs.desc; |
| 1561 |
const struct panvk_shader_variant *vs = |
| 1562 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 1563 |
struct cs_builder *b = |
| 1564 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1565 |
bool upd_res_table = false; |
| 1566 |
|
| 1567 |
VkResult result = prepare_vs_driver_set(cmdbuf, draw); |
| 1568 |
if (result != VK_SUCCESS) |
| 1569 |
return result; |
| 1570 |
|
| 1571 |
if (gfx_state_dirty(cmdbuf, VS) || gfx_state_dirty(cmdbuf, DESC_STATE) || |
| 1572 |
vs_driver_set_is_dirty(cmdbuf)) { |
| 1573 |
uint32_t repeat_count = 1; |
| 1574 |
|
| 1575 |
if (draw->indirect.draw_count > 1 && |
| 1576 |
cmdbuf->state.gfx.vi.attribs_changing_on_base_instance != 0) |
| 1577 |
repeat_count = draw->indirect.draw_count; |
| 1578 |
|
| 1579 |
result = panvk_per_arch(cmd_prepare_shader_res_table)( |
| 1580 |
cmdbuf, desc_state, vs, vs_desc_state, repeat_count); |
| 1581 |
if (result != VK_SUCCESS) |
| 1582 |
return result; |
| 1583 |
|
| 1584 |
upd_res_table = true; |
| 1585 |
} |
| 1586 |
|
| 1587 |
cs_update_vt_ctx(b) { |
| 1588 |
if (upd_res_table) |
| 1589 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VERTEX_SRT), |
| 1590 |
vs_desc_state->res_table); |
| 1591 |
|
| 1592 |
#if PAN_ARCH >= 12 |
| 1593 |
if (gfx_state_dirty(cmdbuf, VS) || |
| 1594 |
dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_TOPOLOGY)) |
| 1595 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VERTEX_SPD), get_vs_all_spd(cmdbuf)); |
| 1596 |
#else |
| 1597 |
if (gfx_state_dirty(cmdbuf, VS) || |
| 1598 |
dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_TOPOLOGY)) |
| 1599 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VERTEX_POS_SPD), |
| 1600 |
get_vs_pos_spd(cmdbuf)); |
| 1601 |
|
| 1602 |
if (gfx_state_dirty(cmdbuf, VS)) |
| 1603 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VERTEX_VARY_SPD), |
| 1604 |
panvk_priv_mem_dev_addr(vs->spds.var)); |
| 1605 |
#endif |
| 1606 |
} |
| 1607 |
|
| 1608 |
return VK_SUCCESS; |
| 1609 |
} |
| 1610 |
|
| 1611 |
static VkResult |
| 1612 |
prepare_fs(struct panvk_cmd_buffer *cmdbuf) |
| 1613 |
{ |
| 1614 |
const struct panvk_shader_variant *fs = |
| 1615 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 1616 |
struct panvk_shader_desc_state *fs_desc_state = &cmdbuf->state.gfx.fs.desc; |
| 1617 |
struct panvk_descriptor_state *desc_state = &cmdbuf->state.gfx.desc_state; |
| 1618 |
struct cs_builder *b = |
| 1619 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1620 |
|
| 1621 |
if (fs && |
| 1622 |
(gfx_state_dirty(cmdbuf, VS) || |
| 1623 |
gfx_state_dirty(cmdbuf, FS) || |
| 1624 |
gfx_state_dirty(cmdbuf, DESC_STATE))) { |
| 1625 |
VkResult result = prepare_fs_driver_set(cmdbuf); |
| 1626 |
if (result != VK_SUCCESS) |
| 1627 |
return result; |
| 1628 |
|
| 1629 |
result = panvk_per_arch(cmd_prepare_shader_res_table)( |
| 1630 |
cmdbuf, desc_state, fs, fs_desc_state, 1); |
| 1631 |
if (result != VK_SUCCESS) |
| 1632 |
return result; |
| 1633 |
} |
| 1634 |
|
| 1635 |
cs_update_vt_ctx(b) { |
| 1636 |
if (fs_user_dirty(cmdbuf) || gfx_state_dirty(cmdbuf, DESC_STATE)) |
| 1637 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, FRAGMENT_SRT), |
| 1638 |
fs ? fs_desc_state->res_table : 0); |
| 1639 |
if (fs_user_dirty(cmdbuf)) |
| 1640 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, FRAGMENT_SPD), |
| 1641 |
fs ? panvk_priv_mem_dev_addr(fs->spd) : 0); |
| 1642 |
} |
| 1643 |
|
| 1644 |
return VK_SUCCESS; |
| 1645 |
} |
| 1646 |
|
| 1647 |
static VkResult |
| 1648 |
prepare_push_uniforms(struct panvk_cmd_buffer *cmdbuf, |
| 1649 |
const struct panvk_draw_info *draw) |
| 1650 |
{ |
| 1651 |
struct cs_builder *b = |
| 1652 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1653 |
const struct panvk_shader_variant *vs = |
| 1654 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 1655 |
const struct panvk_shader_variant *fs = |
| 1656 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 1657 |
VkResult result; |
| 1658 |
|
| 1659 |
if (gfx_state_dirty(cmdbuf, VS_PUSH_UNIFORMS)) { |
| 1660 |
uint32_t repeat_count = 1; |
| 1661 |
|
| 1662 |
if (draw->indirect.draw_count > 1 && |
| 1663 |
(shader_uses_sysval(vs, graphics, vs.first_vertex) || |
| 1664 |
shader_uses_sysval(vs, graphics, vs.base_instance))) |
| 1665 |
repeat_count = draw->indirect.draw_count; |
| 1666 |
|
| 1667 |
result = |
| 1668 |
panvk_per_arch(cmd_prepare_push_uniforms)(cmdbuf, vs, repeat_count); |
| 1669 |
if (result != VK_SUCCESS) |
| 1670 |
return result; |
| 1671 |
|
| 1672 |
cs_update_vt_ctx(b) { |
| 1673 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, VERTEX_FAU), |
| 1674 |
cmdbuf->state.gfx.vs.push_uniforms | |
| 1675 |
((uint64_t)vs->fau.total_count << 56)); |
| 1676 |
} |
| 1677 |
} |
| 1678 |
|
| 1679 |
if (fs_user_dirty(cmdbuf) || gfx_state_dirty(cmdbuf, FS_PUSH_UNIFORMS)) { |
| 1680 |
uint64_t fau_ptr = 0; |
| 1681 |
|
| 1682 |
if (fs) { |
| 1683 |
result = panvk_per_arch(cmd_prepare_push_uniforms)(cmdbuf, fs, 1); |
| 1684 |
if (result != VK_SUCCESS) |
| 1685 |
return result; |
| 1686 |
|
| 1687 |
fau_ptr = cmdbuf->state.gfx.fs.push_uniforms | |
| 1688 |
((uint64_t)fs->fau.total_count << 56); |
| 1689 |
} |
| 1690 |
|
| 1691 |
cs_update_vt_ctx(b) |
| 1692 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, FRAGMENT_FAU), fau_ptr); |
| 1693 |
} |
| 1694 |
|
| 1695 |
return VK_SUCCESS; |
| 1696 |
} |
| 1697 |
|
| 1698 |
static VkResult |
| 1699 |
prepare_ds(struct panvk_cmd_buffer *cmdbuf, struct pan_earlyzs_state earlyzs) |
| 1700 |
{ |
| 1701 |
bool dirty = dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_TEST_ENABLE) || |
| 1702 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_WRITE_ENABLE) || |
| 1703 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_COMPARE_OP) || |
| 1704 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_TEST_ENABLE) || |
| 1705 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_OP) || |
| 1706 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_COMPARE_MASK) || |
| 1707 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_WRITE_MASK) || |
| 1708 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_REFERENCE) || |
| 1709 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLAMP_ENABLE) || |
| 1710 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLIP_ENABLE) || |
| 1711 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_BIAS_ENABLE) || |
| 1712 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_BIAS_FACTORS) || |
| 1713 |
dyn_gfx_state_dirty(cmdbuf, MS_ALPHA_TO_COVERAGE_ENABLE) || |
| 1714 |
dyn_gfx_state_dirty(cmdbuf, INPUT_ATTACHMENT_MAP) || |
| 1715 |
fs_user_dirty(cmdbuf) || gfx_state_dirty(cmdbuf, OQ); |
| 1716 |
|
| 1717 |
if (!dirty) |
| 1718 |
return VK_SUCCESS; |
| 1719 |
|
| 1720 |
struct cs_builder *b = |
| 1721 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1722 |
const struct vk_dynamic_graphics_state *dyns = |
| 1723 |
&cmdbuf->vk.dynamic_graphics_state; |
| 1724 |
const struct vk_depth_stencil_state *ds = &dyns->ds; |
| 1725 |
const struct vk_rasterization_state *rs = &dyns->rs; |
| 1726 |
bool test_s = has_stencil_att(cmdbuf) && ds->stencil.test_enable; |
| 1727 |
bool test_z = has_depth_att(cmdbuf) && ds->depth.test_enable; |
| 1728 |
const struct panvk_shader_variant *fs = |
| 1729 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 1730 |
|
| 1731 |
struct pan_ptr zsd = panvk_cmd_alloc_desc(cmdbuf, DEPTH_STENCIL); |
| 1732 |
if (!zsd.gpu) |
| 1733 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 1734 |
|
| 1735 |
pan_cast_and_pack(zsd.cpu, DEPTH_STENCIL, cfg) { |
| 1736 |
cfg.stencil_test_enable = test_s; |
| 1737 |
if (test_s) { |
| 1738 |
cfg.front_compare_function = |
| 1739 |
translate_compare_func(ds->stencil.front.op.compare); |
| 1740 |
cfg.front_stencil_fail = |
| 1741 |
translate_stencil_op(ds->stencil.front.op.fail); |
| 1742 |
cfg.front_depth_fail = |
| 1743 |
translate_stencil_op(ds->stencil.front.op.depth_fail); |
| 1744 |
cfg.front_depth_pass = translate_stencil_op(ds->stencil.front.op.pass); |
| 1745 |
cfg.back_compare_function = |
| 1746 |
translate_compare_func(ds->stencil.back.op.compare); |
| 1747 |
cfg.back_stencil_fail = translate_stencil_op(ds->stencil.back.op.fail); |
| 1748 |
cfg.back_depth_fail = |
| 1749 |
translate_stencil_op(ds->stencil.back.op.depth_fail); |
| 1750 |
cfg.back_depth_pass = translate_stencil_op(ds->stencil.back.op.pass); |
| 1751 |
} |
| 1752 |
|
| 1753 |
cfg.stencil_from_shader = fs ? fs->info.fs.writes_stencil : 0; |
| 1754 |
cfg.front_write_mask = ds->stencil.front.write_mask; |
| 1755 |
cfg.back_write_mask = ds->stencil.back.write_mask; |
| 1756 |
cfg.front_value_mask = ds->stencil.front.compare_mask; |
| 1757 |
cfg.back_value_mask = ds->stencil.back.compare_mask; |
| 1758 |
cfg.front_reference_value = ds->stencil.front.reference; |
| 1759 |
cfg.back_reference_value = ds->stencil.back.reference; |
| 1760 |
|
| 1761 |
cfg.depth_cull_enable = vk_rasterization_state_depth_clip_enable(rs); |
| 1762 |
if (rs->depth_clamp_enable) |
| 1763 |
cfg.depth_clamp_mode = MALI_DEPTH_CLAMP_MODE_BOUNDS; |
| 1764 |
|
| 1765 |
if (fs) { |
| 1766 |
#if PAN_ARCH == 10 |
| 1767 |
cfg.shader_read_only_z_s = earlyzs.shader_readonly_zs; |
| 1768 |
#elif PAN_ARCH == 11 |
| 1769 |
cfg.separated_dependency_tracking = true; |
| 1770 |
#endif |
| 1771 |
cfg.depth_source = pan_depth_source(&fs->info); |
| 1772 |
} |
| 1773 |
|
| 1774 |
cfg.depth_write_enable = test_z && ds->depth.write_enable; |
| 1775 |
cfg.depth_bias_enable = rs->depth_bias.enable; |
| 1776 |
cfg.depth_function = test_z ? translate_compare_func(ds->depth.compare_op) |
| 1777 |
: MALI_FUNC_ALWAYS; |
| 1778 |
cfg.depth_units = rs->depth_bias.constant_factor; |
| 1779 |
cfg.depth_factor = rs->depth_bias.slope_factor; |
| 1780 |
cfg.depth_bias_clamp = rs->depth_bias.clamp; |
| 1781 |
} |
| 1782 |
|
| 1783 |
cs_update_vt_ctx(b) |
| 1784 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, ZSD), zsd.gpu); |
| 1785 |
|
| 1786 |
return VK_SUCCESS; |
| 1787 |
} |
| 1788 |
|
| 1789 |
static VkResult |
| 1790 |
wrap_prev_oq(struct panvk_cmd_buffer *cmdbuf) |
| 1791 |
{ |
| 1792 |
uint64_t last_syncobj = cmdbuf->state.gfx.render.oq.last; |
| 1793 |
|
| 1794 |
if (!last_syncobj) |
| 1795 |
return VK_SUCCESS; |
| 1796 |
|
| 1797 |
/* We need to signal n_views consecutive queries for multiview. */ |
| 1798 |
const uint32_t n_views = |
| 1799 |
MAX2(1, util_bitcount(cmdbuf->state.gfx.render.view_mask)); |
| 1800 |
|
| 1801 |
for (uint32_t view_idx = 0; view_idx < n_views; ++view_idx) { |
| 1802 |
struct pan_ptr new_oq_node = panvk_cmd_alloc_dev_mem( |
| 1803 |
cmdbuf, desc, sizeof(struct panvk_cs_occlusion_query), 8); |
| 1804 |
|
| 1805 |
|
| 1806 |
if (!new_oq_node.gpu) |
| 1807 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 1808 |
|
| 1809 |
cmdbuf->state.gfx.render.oq.chain = new_oq_node.gpu; |
| 1810 |
|
| 1811 |
struct panvk_cs_occlusion_query *oq = new_oq_node.cpu; |
| 1812 |
|
| 1813 |
*oq = (struct panvk_cs_occlusion_query){ |
| 1814 |
.node = {.next = 0}, |
| 1815 |
.syncobj = last_syncobj + view_idx * sizeof(struct panvk_query_available_obj), |
| 1816 |
}; |
| 1817 |
|
| 1818 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_FRAGMENT); |
| 1819 |
struct cs_index new_node_ptr = cs_scratch_reg64(b, 0); |
| 1820 |
cs_move64_to(b, new_node_ptr, new_oq_node.gpu); |
| 1821 |
cs_single_link_list_add_tail( |
| 1822 |
b, cs_subqueue_ctx_reg(b), |
| 1823 |
offsetof(struct panvk_cs_subqueue_context, render.oq_chain), new_node_ptr, |
| 1824 |
offsetof(struct panvk_cs_occlusion_query, node), |
| 1825 |
cs_scratch_reg_tuple(b, 10, 4)); |
| 1826 |
} |
| 1827 |
|
| 1828 |
return VK_SUCCESS; |
| 1829 |
} |
| 1830 |
|
| 1831 |
static VkResult |
| 1832 |
prepare_oq(struct panvk_cmd_buffer *cmdbuf) |
| 1833 |
{ |
| 1834 |
if (!gfx_state_dirty(cmdbuf, OQ) || |
| 1835 |
cmdbuf->state.gfx.occlusion_query.mode == MALI_OCCLUSION_MODE_DISABLED || |
| 1836 |
cmdbuf->state.gfx.occlusion_query.syncobj == |
| 1837 |
cmdbuf->state.gfx.render.oq.last) |
| 1838 |
return VK_SUCCESS; |
| 1839 |
|
| 1840 |
VkResult result = wrap_prev_oq(cmdbuf); |
| 1841 |
if (result) |
| 1842 |
return result; |
| 1843 |
|
| 1844 |
struct cs_builder *b = |
| 1845 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1846 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, OQ), |
| 1847 |
cmdbuf->state.gfx.occlusion_query.ptr); |
| 1848 |
|
| 1849 |
cmdbuf->state.gfx.render.oq.last = |
| 1850 |
cmdbuf->state.gfx.occlusion_query.syncobj; |
| 1851 |
return VK_SUCCESS; |
| 1852 |
} |
| 1853 |
|
| 1854 |
static void |
| 1855 |
prepare_dcd(struct panvk_cmd_buffer *cmdbuf, |
| 1856 |
struct pan_earlyzs_state *earlyzs) |
| 1857 |
{ |
| 1858 |
struct cs_builder *b = |
| 1859 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 1860 |
const struct panvk_shader_variant *fs = |
| 1861 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 1862 |
bool dcd2_dirty = |
| 1863 |
fs_user_dirty(cmdbuf) || |
| 1864 |
dyn_gfx_state_dirty(cmdbuf, INPUT_ATTACHMENT_MAP) || |
| 1865 |
dyn_gfx_state_dirty(cmdbuf, COLOR_ATTACHMENT_MAP); |
| 1866 |
#if PAN_ARCH >= 13 |
| 1867 |
dcd2_dirty |= dyn_gfx_state_dirty(cmdbuf, MS_ALPHA_TO_COVERAGE_ENABLE) || |
| 1868 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_TEST_ENABLE) || |
| 1869 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_WRITE_ENABLE) || |
| 1870 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_COMPARE_OP) || |
| 1871 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_TEST_ENABLE) || |
| 1872 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_OP) || |
| 1873 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_WRITE_MASK) || |
| 1874 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_ENABLES) || |
| 1875 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_EQUATIONS) || |
| 1876 |
dyn_gfx_state_dirty(cmdbuf, CB_WRITE_MASKS); |
| 1877 |
#endif |
| 1878 |
bool dcd0_dirty = |
| 1879 |
dyn_gfx_state_dirty(cmdbuf, RS_RASTERIZER_DISCARD_ENABLE) || |
| 1880 |
dyn_gfx_state_dirty(cmdbuf, RS_CULL_MODE) || |
| 1881 |
dyn_gfx_state_dirty(cmdbuf, RS_LINE_MODE) || |
| 1882 |
dyn_gfx_state_dirty(cmdbuf, RS_FRONT_FACE) || |
| 1883 |
dyn_gfx_state_dirty(cmdbuf, MS_RASTERIZATION_SAMPLES) || |
| 1884 |
dyn_gfx_state_dirty(cmdbuf, MS_SAMPLE_MASK) || |
| 1885 |
dyn_gfx_state_dirty(cmdbuf, MS_ALPHA_TO_COVERAGE_ENABLE) || |
| 1886 |
dyn_gfx_state_dirty(cmdbuf, MS_ALPHA_TO_ONE_ENABLE) || |
| 1887 |
/* writes_depth() uses vk_depth_stencil_state */ |
| 1888 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_TEST_ENABLE) || |
| 1889 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_WRITE_ENABLE) || |
| 1890 |
dyn_gfx_state_dirty(cmdbuf, DS_DEPTH_COMPARE_OP) || |
| 1891 |
/* writes_stencil() uses vk_depth_stencil_state */ |
| 1892 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_TEST_ENABLE) || |
| 1893 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_OP) || |
| 1894 |
dyn_gfx_state_dirty(cmdbuf, DS_STENCIL_WRITE_MASK) || |
| 1895 |
/* fpk enablement depends on vk_color_blend_attachment_state */ |
| 1896 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_ENABLES) || |
| 1897 |
dyn_gfx_state_dirty(cmdbuf, CB_BLEND_EQUATIONS) || |
| 1898 |
dyn_gfx_state_dirty(cmdbuf, CB_WRITE_MASKS) || |
| 1899 |
/* line mode needs primitive topology */ |
| 1900 |
dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_TOPOLOGY) || |
| 1901 |
dyn_gfx_state_dirty(cmdbuf, INPUT_ATTACHMENT_MAP) || |
| 1902 |
fs_user_dirty(cmdbuf) || gfx_state_dirty(cmdbuf, RENDER_STATE) || |
| 1903 |
gfx_state_dirty(cmdbuf, OQ) || dcd2_dirty; |
| 1904 |
bool dcd1_dirty = dyn_gfx_state_dirty(cmdbuf, MS_RASTERIZATION_SAMPLES) || |
| 1905 |
dyn_gfx_state_dirty(cmdbuf, MS_SAMPLE_MASK) || |
| 1906 |
/* line mode needs primitive topology */ |
| 1907 |
dyn_gfx_state_dirty(cmdbuf, RS_LINE_MODE) || |
| 1908 |
dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_TOPOLOGY) || |
| 1909 |
dyn_gfx_state_dirty(cmdbuf, COLOR_ATTACHMENT_MAP) || |
| 1910 |
fs_user_dirty(cmdbuf) || |
| 1911 |
gfx_state_dirty(cmdbuf, RENDER_STATE); |
| 1912 |
|
| 1913 |
const struct vk_dynamic_graphics_state *dyns = |
| 1914 |
&cmdbuf->vk.dynamic_graphics_state; |
| 1915 |
const struct vk_rasterization_state *rs = |
| 1916 |
&cmdbuf->vk.dynamic_graphics_state.rs; |
| 1917 |
const struct vk_input_assembly_state *ia = |
| 1918 |
&cmdbuf->vk.dynamic_graphics_state.ia; |
| 1919 |
|
| 1920 |
bool alpha_to_coverage = dyns->ms.alpha_to_coverage_enable; |
| 1921 |
bool writes_z = writes_depth(cmdbuf); |
| 1922 |
bool writes_s = writes_stencil(cmdbuf); |
| 1923 |
bool shader_modifies_coverage = false; |
| 1924 |
uint8_t rt_mask = cmdbuf->state.gfx.render.bound_attachments & |
| 1925 |
MESA_VK_RP_ATTACHMENT_ANY_COLOR_BITS; |
| 1926 |
uint8_t rt_written = 0, rt_read = 0; |
| 1927 |
|
| 1928 |
if (fs) { |
| 1929 |
rt_written = color_attachment_written_mask(fs, &dyns->cal); |
| 1930 |
rt_read = color_attachment_read_mask(fs, &dyns->ial, rt_mask); |
| 1931 |
shader_modifies_coverage = fs->info.fs.writes_coverage || |
| 1932 |
fs->info.fs.can_discard || alpha_to_coverage; |
| 1933 |
} |
| 1934 |
|
| 1935 |
bool msaa = dyns->ms.rasterization_samples > 1; |
| 1936 |
if ((ia->primitive_topology == VK_PRIMITIVE_TOPOLOGY_LINE_LIST || |
| 1937 |
ia->primitive_topology == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP) && |
| 1938 |
rs->line.mode == VK_LINE_RASTERIZATION_MODE_BRESENHAM) { |
| 1939 |
/* we need to disable MSAA when rendering bresenham lines. |
| 1940 |
* |
| 1941 |
* From the Vulkan spec: |
| 1942 |
* "When Bresenham lines are being rasterized, sample locations may |
| 1943 |
* all be treated as being at the pixel center (this may affect |
| 1944 |
* attribute and depth interpolation)."" |
| 1945 |
*/ |
| 1946 |
msaa = false; |
| 1947 |
} |
| 1948 |
|
| 1949 |
if (dcd0_dirty) { |
| 1950 |
struct mali_dcd_flags_0_packed dcd0; |
| 1951 |
pan_pack(&dcd0, DCD_FLAGS_0, cfg) { |
| 1952 |
if (fs) { |
| 1953 |
enum pan_earlyzs_zs_tilebuf_read zs_read = |
| 1954 |
PAN_EARLYZS_ZS_TILEBUF_NOT_READ; |
| 1955 |
|
| 1956 |
if (z_attachment_read(fs, &dyns->ial) || |
| 1957 |
s_attachment_read(fs, &dyns->ial)) { |
| 1958 |
if (writes_z || writes_s || PAN_ARCH != 10) |
| 1959 |
zs_read = PAN_EARLYZS_ZS_TILEBUF_READ_NO_OPT; |
| 1960 |
else |
| 1961 |
zs_read = PAN_EARLYZS_ZS_TILEBUF_READ_OPT; |
| 1962 |
} |
| 1963 |
|
| 1964 |
cfg.allow_forward_pixel_to_kill = |
| 1965 |
fs->info.fs.can_fpk && !(rt_mask & ~rt_written) && |
| 1966 |
!(rt_read & rt_written) && !alpha_to_coverage && |
| 1967 |
!cmdbuf->state.gfx.cb.info.any_dest_read; |
| 1968 |
|
| 1969 |
cfg.allow_forward_pixel_to_be_killed = !fs->info.writes_global; |
| 1970 |
|
| 1971 |
bool writes_zs = writes_z || writes_s; |
| 1972 |
bool zs_always_passes = ds_test_always_passes(cmdbuf); |
| 1973 |
bool oq = cmdbuf->state.gfx.occlusion_query.mode != |
| 1974 |
MALI_OCCLUSION_MODE_DISABLED; |
| 1975 |
|
| 1976 |
*earlyzs = |
| 1977 |
pan_earlyzs_get(fs->fs.earlyzs_lut, writes_zs || oq, |
| 1978 |
alpha_to_coverage, zs_always_passes, zs_read); |
| 1979 |
|
| 1980 |
cfg.pixel_kill_operation = (enum mali_pixel_kill)earlyzs->kill; |
| 1981 |
cfg.zs_update_operation = (enum mali_pixel_kill)earlyzs->update; |
| 1982 |
|
| 1983 |
/* Use per-sample shading if required by API. Also use it when a |
| 1984 |
* blend shader is used with multisampling, as this is handled by a |
| 1985 |
* single ST_TILE in the blend shader with the current sample ID, |
| 1986 |
* requiring per-sample shading. |
| 1987 |
*/ |
| 1988 |
cfg.evaluate_per_sample = |
| 1989 |
(fs->info.fs.sample_shading || |
| 1990 |
cmdbuf->state.gfx.cb.info.needs_shader) && |
| 1991 |
(dyns->ms.rasterization_samples > 1); |
| 1992 |
|
| 1993 |
cfg.shader_modifies_coverage = shader_modifies_coverage; |
| 1994 |
} else { |
| 1995 |
cfg.allow_forward_pixel_to_kill = true; |
| 1996 |
cfg.allow_forward_pixel_to_be_killed = true; |
| 1997 |
cfg.pixel_kill_operation = MALI_PIXEL_KILL_FORCE_EARLY; |
| 1998 |
cfg.zs_update_operation = MALI_PIXEL_KILL_FORCE_EARLY; |
| 1999 |
cfg.overdraw_alpha0 = true; |
| 2000 |
cfg.overdraw_alpha1 = true; |
| 2001 |
} |
| 2002 |
|
| 2003 |
if (rs->line.mode == VK_LINE_RASTERIZATION_MODE_BRESENHAM) |
| 2004 |
cfg.aligned_line_ends = true; |
| 2005 |
|
| 2006 |
cfg.front_face_ccw = rs->front_face == VK_FRONT_FACE_COUNTER_CLOCKWISE; |
| 2007 |
cfg.cull_front_face = (rs->cull_mode & VK_CULL_MODE_FRONT_BIT) != 0; |
| 2008 |
cfg.cull_back_face = (rs->cull_mode & VK_CULL_MODE_BACK_BIT) != 0; |
| 2009 |
|
| 2010 |
cfg.multisample_enable = msaa; |
| 2011 |
cfg.occlusion_query = cmdbuf->state.gfx.occlusion_query.mode; |
| 2012 |
cfg.alpha_to_coverage = alpha_to_coverage; |
| 2013 |
} |
| 2014 |
|
| 2015 |
cs_update_vt_ctx(b) |
| 2016 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, DCD0), dcd0.opaque[0]); |
| 2017 |
} |
| 2018 |
|
| 2019 |
if (dcd1_dirty) { |
| 2020 |
struct mali_dcd_flags_1_packed dcd1; |
| 2021 |
pan_pack(&dcd1, DCD_FLAGS_1, cfg) { |
| 2022 |
cfg.sample_mask = msaa ? dyns->ms.sample_mask : UINT16_MAX; |
| 2023 |
cfg.render_target_mask = rt_written; |
| 2024 |
} |
| 2025 |
|
| 2026 |
cs_update_vt_ctx(b) |
| 2027 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, DCD1), dcd1.opaque[0]); |
| 2028 |
} |
| 2029 |
|
| 2030 |
if (dcd2_dirty) { |
| 2031 |
struct mali_dcd_flags_2_packed dcd2; |
| 2032 |
pan_pack(&dcd2, DCD_FLAGS_2, cfg) { |
| 2033 |
cfg.read_mask = rt_read; |
| 2034 |
cfg.write_mask = rt_written; |
| 2035 |
#if PAN_ARCH >= 11 |
| 2036 |
if (fs) { |
| 2037 |
cfg.no_shader_depth_read = !z_attachment_read(fs, &dyns->ial); |
| 2038 |
cfg.no_shader_stencil_read = !s_attachment_read(fs, &dyns->ial); |
| 2039 |
} |
| 2040 |
#endif |
| 2041 |
#if PAN_ARCH >= 13 |
| 2042 |
if (fs) { |
| 2043 |
/* HSR can cull */ |
| 2044 |
cfg.hsr_can_cull = !fs->info.fs.hsr.ld_tile && rt_written && |
| 2045 |
!(rt_read & rt_written) && |
| 2046 |
!cmdbuf->state.gfx.cb.info.any_dest_read; |
| 2047 |
|
| 2048 |
|
| 2049 |
/* HSR can_be_culled |
| 2050 |
* - FUTURE: We could allow write-only side effects. |
| 2051 |
* - FUTURE: we could allow any LD_TILE that's not used in CLPER or |
| 2052 |
* tex_lod operations. */ |
| 2053 |
assert(dcd0_dirty && "earlyzs was never filled"); |
| 2054 |
bool late_zs = earlyzs->update == MALI_PIXEL_KILL_FORCE_LATE; |
| 2055 |
cfg.hsr_can_be_culled = |
| 2056 |
!fs->info.fs.sidefx && |
| 2057 |
!fs->info.fs.hsr.wait_or_tile_access_before_atest_zsemit && |
| 2058 |
!fs->info.fs.hsr.rasterizer_coverage_read && |
| 2059 |
!fs->info.fs.hsr.ld_tile && |
| 2060 |
!fs->info.fs.hsr.centroid_interpolation && |
| 2061 |
(!shader_modifies_coverage || !cfg.z_write_or_stencil || |
| 2062 |
late_zs); |
| 2063 |
|
| 2064 |
/* Late HSR update */ |
| 2065 |
cfg.hsr_update_operation = shader_modifies_coverage || late_zs |
| 2066 |
? MALI_HSR_UPDATE_LATE |
| 2067 |
: MALI_HSR_UPDATE_EARLY; |
| 2068 |
|
| 2069 |
/* Since we do not allow side effects for HSR, we can always have |
| 2070 |
* the HSR kill op follow HSR update. */ |
| 2071 |
cfg.hsr_prepass_kill_operation = |
| 2072 |
MALI_HSR_PREPASS_KILL_FOLLOW_HSR_UPDATE; |
| 2073 |
|
| 2074 |
/* Whether prepass must run varyings. */ |
| 2075 |
cfg.enable_varying_shading_in_pre_pass = |
| 2076 |
fs->info.fs.hsr.varying_before_atest_zsemit && |
| 2077 |
(cfg.hsr_update_operation == MALI_HSR_UPDATE_LATE || |
| 2078 |
cfg.hsr_prepass_kill_operation == MALI_HSR_PREPASS_KILL_LATE || |
| 2079 |
earlyzs->update == MALI_PIXEL_KILL_FORCE_LATE || |
| 2080 |
earlyzs->kill == MALI_PIXEL_KILL_FORCE_LATE); |
| 2081 |
|
| 2082 |
/* Whether depth is written or stencil is used */ |
| 2083 |
const struct vk_depth_stencil_state *ds = |
| 2084 |
&cmdbuf->vk.dynamic_graphics_state.ds; |
| 2085 |
cfg.z_write_or_stencil = |
| 2086 |
writes_z || (has_stencil_att(cmdbuf) && ds->stencil.test_enable); |
| 2087 |
} else { |
| 2088 |
cfg.hsr_can_cull = false; |
| 2089 |
cfg.hsr_can_be_culled = false; |
| 2090 |
cfg.z_write_or_stencil = false; |
| 2091 |
cfg.enable_varying_shading_in_pre_pass = false; |
| 2092 |
cfg.hsr_update_operation = MALI_HSR_UPDATE_EARLY; |
| 2093 |
cfg.hsr_prepass_kill_operation = |
| 2094 |
MALI_HSR_PREPASS_KILL_FOLLOW_HSR_UPDATE; |
| 2095 |
} |
| 2096 |
#endif |
| 2097 |
} |
| 2098 |
|
| 2099 |
cs_update_vt_ctx(b) |
| 2100 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, DCD2), dcd2.opaque[0]); |
| 2101 |
} |
| 2102 |
} |
| 2103 |
|
| 2104 |
static void |
| 2105 |
prepare_index_buffer(struct panvk_cmd_buffer *cmdbuf) |
| 2106 |
{ |
| 2107 |
struct cs_builder *b = |
| 2108 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 2109 |
|
| 2110 |
if (gfx_state_dirty(cmdbuf, IB)) { |
| 2111 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, INDEX_BUFFER_SIZE), |
| 2112 |
cmdbuf->state.gfx.ib.size); |
| 2113 |
|
| 2114 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, INDEX_BUFFER), |
| 2115 |
cmdbuf->state.gfx.ib.dev_addr); |
| 2116 |
} |
| 2117 |
} |
| 2118 |
|
| 2119 |
static void |
| 2120 |
set_tiler_idvs_flags(struct cs_builder *b, struct panvk_cmd_buffer *cmdbuf, |
| 2121 |
struct panvk_draw_info *draw) |
| 2122 |
{ |
| 2123 |
const struct panvk_shader_variant *vs = |
| 2124 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 2125 |
const struct panvk_shader_variant *fs = |
| 2126 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 2127 |
const struct vk_dynamic_graphics_state *dyns = |
| 2128 |
&cmdbuf->vk.dynamic_graphics_state; |
| 2129 |
const struct vk_input_assembly_state *ia = &dyns->ia; |
| 2130 |
const struct vk_rasterization_state *rs = &dyns->rs; |
| 2131 |
struct mali_primitive_flags_packed tiler_idvs_flags; |
| 2132 |
|
| 2133 |
/* When drawing non-point primitives, we use the no_psiz variant which has |
| 2134 |
* point size writes patched out */ |
| 2135 |
bool writes_point_size = |
| 2136 |
vs->info.vs.writes_point_size && |
| 2137 |
ia->primitive_topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST; |
| 2138 |
bool writes_layer = vs->info.outputs_written & VARYING_BIT_LAYER; |
| 2139 |
bool extended_fifo = writes_point_size || vs->info.vs.needs_extended_fifo; |
| 2140 |
bool writes_prim_id = vs->info.outputs_written & VARYING_BIT_PRIMITIVE_ID; |
| 2141 |
bool fs_reads_prim_id = fs ? fs->info.fs.reads_primitive_id : false; |
| 2142 |
|
| 2143 |
bool dirty = gfx_state_dirty(cmdbuf, VS) || fs_user_dirty(cmdbuf) || |
| 2144 |
dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_RESTART_ENABLE) || |
| 2145 |
dyn_gfx_state_dirty(cmdbuf, IA_PRIMITIVE_TOPOLOGY) || |
| 2146 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLAMP_ENABLE) || |
| 2147 |
dyn_gfx_state_dirty(cmdbuf, RS_DEPTH_CLIP_ENABLE); |
| 2148 |
|
| 2149 |
if (dirty) { |
| 2150 |
pan_pack(&tiler_idvs_flags, PRIMITIVE_FLAGS, cfg) { |
| 2151 |
cfg.draw_mode = translate_prim_topology(ia->primitive_topology); |
| 2152 |
cfg.primitive_index_enable = fs_reads_prim_id; |
| 2153 |
cfg.primitive_index_override = writes_prim_id && fs_reads_prim_id; |
| 2154 |
|
| 2155 |
#if PAN_ARCH < 13 |
| 2156 |
cfg.point_size_array_format = writes_point_size |
| 2157 |
? MALI_POINT_SIZE_ARRAY_FORMAT_FP16 |
| 2158 |
: MALI_POINT_SIZE_ARRAY_FORMAT_NONE; |
| 2159 |
#endif |
| 2160 |
|
| 2161 |
cfg.layer_index_enable = writes_layer; |
| 2162 |
|
| 2163 |
cfg.position_fifo_format = extended_fifo |
| 2164 |
? MALI_FIFO_FORMAT_EXTENDED |
| 2165 |
: MALI_FIFO_FORMAT_BASIC; |
| 2166 |
|
| 2167 |
cfg.low_depth_cull = cfg.high_depth_cull = |
| 2168 |
vk_rasterization_state_depth_clip_enable(rs); |
| 2169 |
|
| 2170 |
cfg.secondary_shader = vs->info.vs.secondary_enable && fs != NULL; |
| 2171 |
cfg.primitive_restart = ia->primitive_restart_enable; |
| 2172 |
cfg.view_mask = cmdbuf->state.gfx.render.view_mask; |
| 2173 |
} |
| 2174 |
|
| 2175 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, TILER_FLAGS), tiler_idvs_flags.opaque[0]); |
| 2176 |
#if PAN_ARCH >= 11 |
| 2177 |
struct mali_primitive_flags_2_packed tiler_flags_2; |
| 2178 |
pan_pack(&tiler_flags_2, PRIMITIVE_FLAGS_2, cfg) { |
| 2179 |
} |
| 2180 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, TILER_FLAGS2), |
| 2181 |
tiler_flags_2.opaque[0]); |
| 2182 |
#endif |
| 2183 |
} |
| 2184 |
} |
| 2185 |
|
| 2186 |
static struct mali_primitive_flags_packed |
| 2187 |
get_tiler_flags_override(struct panvk_draw_info *draw) |
| 2188 |
{ |
| 2189 |
struct mali_primitive_flags_packed flags_override; |
| 2190 |
/* Pack with nodefaults so only explicitly set override fields affect the |
| 2191 |
* previously set register values */ |
| 2192 |
pan_pack_nodefaults(&flags_override, PRIMITIVE_FLAGS, cfg) { |
| 2193 |
cfg.index_type = index_size_to_index_type(draw->index.size); |
| 2194 |
}; |
| 2195 |
|
| 2196 |
return flags_override; |
| 2197 |
} |
| 2198 |
|
| 2199 |
static VkResult |
| 2200 |
prepare_draw(struct panvk_cmd_buffer *cmdbuf, struct panvk_draw_info *draw) |
| 2201 |
{ |
| 2202 |
const struct panvk_shader_variant *vs = |
| 2203 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 2204 |
const struct panvk_shader_variant *fs = |
| 2205 |
panvk_shader_only_variant(get_fs(cmdbuf)); |
| 2206 |
struct panvk_descriptor_state *desc_state = &cmdbuf->state.gfx.desc_state; |
| 2207 |
ASSERTED bool idvs = vs->info.vs.idvs; |
| 2208 |
VkResult result; |
| 2209 |
|
| 2210 |
assert(vs); |
| 2211 |
|
| 2212 |
/* FIXME: support non-IDVS. */ |
| 2213 |
assert(idvs); |
| 2214 |
|
| 2215 |
if (cmdbuf->state.gfx.vk_meta) { |
| 2216 |
/* vk_meta doesn't care about the provoking vertex mode, we should use |
| 2217 |
* the same mode that the application uses. */ |
| 2218 |
set_provoking_vertex_mode(cmdbuf, U_TRISTATE_UNSET); |
| 2219 |
} else { |
| 2220 |
enum u_tristate first_provoking_vertex = u_tristate_make( |
| 2221 |
cmdbuf->vk.dynamic_graphics_state.rs.provoking_vertex == |
| 2222 |
VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT); |
| 2223 |
set_provoking_vertex_mode(cmdbuf, first_provoking_vertex); |
| 2224 |
} |
| 2225 |
|
| 2226 |
result = update_tls(cmdbuf); |
| 2227 |
if (result != VK_SUCCESS) |
| 2228 |
return result; |
| 2229 |
|
| 2230 |
if (!cmdbuf->vk.dynamic_graphics_state.rs.rasterizer_discard_enable) { |
| 2231 |
ASSERTED const struct pan_fb_layout *fb = |
| 2232 |
&cmdbuf->state.gfx.render.fb.layout; |
| 2233 |
uint32_t *nr_samples = &cmdbuf->state.gfx.render.fb.nr_samples; |
| 2234 |
uint32_t rasterization_samples = |
| 2235 |
cmdbuf->vk.dynamic_graphics_state.ms.rasterization_samples; |
| 2236 |
|
| 2237 |
/* If there's no attachment, we patch nr_samples to match |
| 2238 |
* rasterization_samples, otherwise, we make sure those two numbers match. |
| 2239 |
*/ |
| 2240 |
if (!cmdbuf->state.gfx.render.bound_attachments) { |
| 2241 |
assert(rasterization_samples > 0); |
| 2242 |
*nr_samples = rasterization_samples; |
| 2243 |
} else { |
| 2244 |
assert(rasterization_samples == *nr_samples); |
| 2245 |
} |
| 2246 |
|
| 2247 |
/* In case we already emitted tiler/framebuffer descriptors, we ensure |
| 2248 |
* that the sample count didn't change |
| 2249 |
* XXX: This currently can happen in case we resume a render pass with no |
| 2250 |
* attachements and without any draw as the FBD is emitted when suspending. |
| 2251 |
*/ |
| 2252 |
assert(fb->sample_count == 0 || |
| 2253 |
fb->sample_count == cmdbuf->state.gfx.render.fb.nr_samples); |
| 2254 |
} |
| 2255 |
|
| 2256 |
if (!inherits_render_ctx(cmdbuf)) { |
| 2257 |
result = get_render_ctx(cmdbuf); |
| 2258 |
if (result != VK_SUCCESS) |
| 2259 |
return result; |
| 2260 |
} |
| 2261 |
|
| 2262 |
struct cs_builder *b = |
| 2263 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 2264 |
|
| 2265 |
uint32_t used_set_mask = |
| 2266 |
vs->desc_info.used_set_mask | (fs ? fs->desc_info.used_set_mask : 0); |
| 2267 |
|
| 2268 |
if (gfx_state_dirty(cmdbuf, DESC_STATE) || gfx_state_dirty(cmdbuf, VS) || |
| 2269 |
gfx_state_dirty(cmdbuf, FS)) { |
| 2270 |
result = panvk_per_arch(cmd_prepare_push_descs)(cmdbuf, desc_state, |
| 2271 |
used_set_mask); |
| 2272 |
if (result != VK_SUCCESS) |
| 2273 |
return result; |
| 2274 |
} |
| 2275 |
|
| 2276 |
result = prepare_blend(cmdbuf); |
| 2277 |
if (result != VK_SUCCESS) |
| 2278 |
return result; |
| 2279 |
|
| 2280 |
/* Changes to base_instance will modify the offset of per-instance |
| 2281 |
* attributes, so we manually invalidate the VI state to trigger a |
| 2282 |
* new attribute table generation in that case. */ |
| 2283 |
if ((draw->instance.base != cmdbuf->state.gfx.sysvals.vs.base_instance || |
| 2284 |
draw->indirect.buffer_dev_addr) && |
| 2285 |
cmdbuf->state.gfx.vi.attribs_changing_on_base_instance != 0) |
| 2286 |
BITSET_SET(cmdbuf->vk.dynamic_graphics_state.dirty, MESA_VK_DYNAMIC_VI); |
| 2287 |
|
| 2288 |
panvk_per_arch(cmd_prepare_draw_sysvals)(cmdbuf, draw); |
| 2289 |
|
| 2290 |
result = prepare_push_uniforms(cmdbuf, draw); |
| 2291 |
if (result != VK_SUCCESS) |
| 2292 |
return result; |
| 2293 |
|
| 2294 |
result = prepare_vs(cmdbuf, draw); |
| 2295 |
if (result != VK_SUCCESS) |
| 2296 |
return result; |
| 2297 |
|
| 2298 |
result = prepare_fs(cmdbuf); |
| 2299 |
if (result != VK_SUCCESS) |
| 2300 |
return result; |
| 2301 |
|
| 2302 |
cs_update_vt_ctx(b) { |
| 2303 |
prepare_index_buffer(cmdbuf); |
| 2304 |
|
| 2305 |
set_tiler_idvs_flags(b, cmdbuf, draw); |
| 2306 |
|
| 2307 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, VARY_SIZE), |
| 2308 |
vs->info.varyings.formats.generic_size_B); |
| 2309 |
|
| 2310 |
struct pan_earlyzs_state earlyzs = {0}; |
| 2311 |
|
| 2312 |
prepare_dcd(cmdbuf, &earlyzs); |
| 2313 |
|
| 2314 |
result = prepare_ds(cmdbuf, earlyzs); |
| 2315 |
if (result != VK_SUCCESS) |
| 2316 |
return result; |
| 2317 |
|
| 2318 |
result = prepare_oq(cmdbuf); |
| 2319 |
if (result != VK_SUCCESS) |
| 2320 |
return result; |
| 2321 |
|
| 2322 |
prepare_vp(cmdbuf); |
| 2323 |
prepare_tiler_primitive_size(cmdbuf); |
| 2324 |
} |
| 2325 |
|
| 2326 |
clear_dirty_after_draw(cmdbuf); |
| 2327 |
return VK_SUCCESS; |
| 2328 |
} |
| 2329 |
|
| 2330 |
static void |
| 2331 |
update_prims_generated_query(struct panvk_cmd_buffer *cmdbuf, |
| 2332 |
struct panvk_draw_info *draw) |
| 2333 |
{ |
| 2334 |
struct cs_builder *b = |
| 2335 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_COMPUTE); |
| 2336 |
struct vk_input_assembly_state *ia = &cmdbuf->vk.dynamic_graphics_state.ia; |
| 2337 |
struct panvk_prims_generated_query_state *state = |
| 2338 |
&cmdbuf->state.gfx.prims_generated_query; |
| 2339 |
|
| 2340 |
if (!state->ptr) |
| 2341 |
return; |
| 2342 |
|
| 2343 |
assert(!draw->index.size || !ia->primitive_restart_enable); |
| 2344 |
|
| 2345 |
enum mesa_prim prim = vk_topology_to_mesa(ia->primitive_topology); |
| 2346 |
uint32_t view_count = cmdbuf->state.gfx.render.view_mask ? |
| 2347 |
util_bitcount(cmdbuf->state.gfx.render.view_mask) : 1; |
| 2348 |
|
| 2349 |
if (draw->index.size && ia->primitive_restart_enable) { |
| 2350 |
struct panvk_precomp_ctx precomp_ctx = panvk_per_arch(precomp_cs)(cmdbuf); |
| 2351 |
|
| 2352 |
struct panlib_update_prims_generated_query_restart_args args = { |
| 2353 |
.prims_generated = state->ptr, |
| 2354 |
.index_buffer = cmdbuf->state.gfx.ib.dev_addr, |
| 2355 |
.index_buffer_size_el = cmdbuf->state.gfx.ib.size / draw->index.size, |
| 2356 |
.cmd_stride = draw->indirect.stride, |
| 2357 |
.cmd = draw->indirect.buffer_dev_addr, |
| 2358 |
.view_count = view_count, |
| 2359 |
}; |
| 2360 |
|
| 2361 |
struct panlib_precomp_grid grid; |
| 2362 |
if (draw->indirect.count_buffer_dev_addr) { |
| 2363 |
struct cs_index addr = cs_scratch_reg64(b, 0); |
| 2364 |
struct cs_index max_draw_count = cs_scratch_reg32(b, 2); |
| 2365 |
|
| 2366 |
cs_update_compute_ctx(b) { |
| 2367 |
cs_move64_to(b, addr, draw->indirect.count_buffer_dev_addr); |
| 2368 |
cs_load32_to(b, cs_sr_reg32(b, COMPUTE, JOB_SIZE_X), addr, 0); |
| 2369 |
|
| 2370 |
cs_move32_to(b, cs_sr_reg32(b, COMPUTE, JOB_SIZE_Y), 1); |
| 2371 |
cs_move32_to(b, cs_sr_reg32(b, COMPUTE, JOB_SIZE_Z), 1); |
| 2372 |
|
| 2373 |
cs_move32_to(b, max_draw_count, draw->indirect.draw_count); |
| 2374 |
cs_umin32(b, cs_sr_reg32(b, COMPUTE, JOB_SIZE_X), |
| 2375 |
cs_sr_reg32(b, COMPUTE, JOB_SIZE_X), max_draw_count); |
| 2376 |
} |
| 2377 |
|
| 2378 |
grid = panlib_dynamic_csf(); |
| 2379 |
} else { |
| 2380 |
grid = panlib_1d(draw->indirect.draw_count); |
| 2381 |
} |
| 2382 |
|
| 2383 |
/* We need to WAIT in order to avoid overlapping the (non-atomic) direct |
| 2384 |
* draw counter updates with indirect draws. TODO: we could avoid that |
| 2385 |
* by having separate direct/indirect counters and adding them on read */ |
| 2386 |
panlib_update_prims_generated_query_restart_struct( |
| 2387 |
&precomp_ctx, grid, PANLIB_BARRIER_CSF_WAIT, args, |
| 2388 |
poly_compact_prim(prim), util_logbase2(draw->index.size)); |
| 2389 |
} else if (draw->indirect.buffer_dev_addr) { |
| 2390 |
struct panvk_precomp_ctx precomp_ctx = panvk_per_arch(precomp_cs)(cmdbuf); |
| 2391 |
|
| 2392 |
struct panlib_update_prims_generated_query_indirect_args args = { |
| 2393 |
.prims_generated = state->ptr, |
| 2394 |
.draw_count_buffer = draw->indirect.count_buffer_dev_addr, |
| 2395 |
.max_draw_count = draw->indirect.draw_count, |
| 2396 |
.cmd_stride = draw->indirect.stride, |
| 2397 |
.cmd = draw->indirect.buffer_dev_addr, |
| 2398 |
.view_count = view_count, |
| 2399 |
}; |
| 2400 |
|
| 2401 |
/* We need to WAIT in order to avoid overlapping the (non-atomic) direct |
| 2402 |
* draw counter updates with indirect draws. TODO: we could avoid that |
| 2403 |
* by having separate direct/indirect counters and adding them on read */ |
| 2404 |
panlib_update_prims_generated_query_indirect_struct( |
| 2405 |
&precomp_ctx, panlib_1d(1), PANLIB_BARRIER_CSF_WAIT, args, |
| 2406 |
poly_compact_prim(prim)); |
| 2407 |
} else { |
| 2408 |
uint32_t prims_per_instance = |
| 2409 |
u_decomposed_prims_for_vertices(prim, draw->vertex.count); |
| 2410 |
uint32_t prims_generated = |
| 2411 |
prims_per_instance * draw->instance.count * view_count; |
| 2412 |
|
| 2413 |
struct cs_index addr = cs_scratch_reg64(b, 0); |
| 2414 |
struct cs_index value = cs_scratch_reg32(b, 2); |
| 2415 |
|
| 2416 |
cs_move64_to(b, addr, state->ptr); |
| 2417 |
cs_load32_to(b, value, addr, 0); |
| 2418 |
cs_add32(b, value, value, prims_generated); |
| 2419 |
cs_store32(b, value, addr, 0); |
| 2420 |
} |
| 2421 |
} |
| 2422 |
|
| 2423 |
static void |
| 2424 |
panvk_cmd_draw(struct panvk_cmd_buffer *cmdbuf, struct panvk_draw_info *draw) |
| 2425 |
{ |
| 2426 |
const struct cs_tracing_ctx *tracing_ctx = |
| 2427 |
&cmdbuf->state.cs[PANVK_SUBQUEUE_VERTEX_TILER].tracing; |
| 2428 |
const struct panvk_shader_variant *vs = |
| 2429 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 2430 |
struct cs_builder *b = |
| 2431 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 2432 |
VkResult result; |
| 2433 |
|
| 2434 |
/* If there's no vertex shader, we can skip the draw. */ |
| 2435 |
if (!panvk_priv_mem_check_alloc(vs->spd)) |
| 2436 |
return; |
| 2437 |
|
| 2438 |
/* Needs to be done before get_fs() is called because it depends on |
| 2439 |
* fs.required being initialized. */ |
| 2440 |
cmdbuf->state.gfx.fs.required = |
| 2441 |
fs_required(&cmdbuf->state.gfx, &cmdbuf->vk.dynamic_graphics_state); |
| 2442 |
|
| 2443 |
result = prepare_draw(cmdbuf, draw); |
| 2444 |
if (result != VK_SUCCESS) |
| 2445 |
return; |
| 2446 |
|
| 2447 |
update_prims_generated_query(cmdbuf, draw); |
| 2448 |
|
| 2449 |
cs_update_vt_ctx(b) { |
| 2450 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, GLOBAL_ATTRIBUTE_OFFSET), 0); |
| 2451 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, INDEX_COUNT), draw->vertex.count); |
| 2452 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, INSTANCE_COUNT), |
| 2453 |
draw->instance.count); |
| 2454 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, INDEX_OFFSET), draw->index.offset); |
| 2455 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, VERTEX_OFFSET), draw->vertex.base); |
| 2456 |
/* NIR expects zero-based instance ID, but even if it did have an |
| 2457 |
* intrinsic to load the absolute instance ID, we'd want to keep it |
| 2458 |
* zero-based to work around Mali's limitation on non-zero firstInstance |
| 2459 |
* when a instance divisor is used. |
| 2460 |
*/ |
| 2461 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, INSTANCE_OFFSET), 0); |
| 2462 |
} |
| 2463 |
|
| 2464 |
struct mali_primitive_flags_packed flags_override = |
| 2465 |
get_tiler_flags_override(draw); |
| 2466 |
|
| 2467 |
uint32_t idvs_count = DIV_ROUND_UP(cmdbuf->state.gfx.render.layer_count, |
| 2468 |
MAX_LAYERS_PER_TILER_DESC); |
| 2469 |
|
| 2470 |
panvk_cond_render(cmdbuf, b) |
| 2471 |
{ |
| 2472 |
if (idvs_count > 1) { |
| 2473 |
struct cs_index counter_reg = cs_scratch_reg32(b, 17); |
| 2474 |
struct cs_index tiler_ctx_addr = cs_sr_reg64(b, IDVS, TILER_CTX); |
| 2475 |
|
| 2476 |
cs_move32_to(b, counter_reg, idvs_count); |
| 2477 |
|
| 2478 |
cs_while(b, MALI_CS_CONDITION_GREATER, counter_reg) { |
| 2479 |
#if PAN_ARCH >= 12 |
| 2480 |
cs_trace_run_idvs2(b, tracing_ctx, cs_scratch_reg_tuple(b, 0, 4), |
| 2481 |
flags_override.opaque[0], true, cs_undef(), |
| 2482 |
MALI_IDVS_SHADING_MODE_EARLY); |
| 2483 |
#else |
| 2484 |
cs_trace_run_idvs(b, tracing_ctx, cs_scratch_reg_tuple(b, 0, 4), |
| 2485 |
flags_override.opaque[0], true, |
| 2486 |
cs_shader_res_sel(0, 0, 1, 0), |
| 2487 |
cs_shader_res_sel(2, 2, 2, 0), cs_undef()); |
| 2488 |
#endif |
| 2489 |
|
| 2490 |
cs_add32(b, counter_reg, counter_reg, -1); |
| 2491 |
cs_update_vt_ctx(b) { |
| 2492 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 2493 |
pan_size(TILER_CONTEXT)); |
| 2494 |
} |
| 2495 |
} |
| 2496 |
|
| 2497 |
cs_update_vt_ctx(b) { |
| 2498 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 2499 |
-(idvs_count * pan_size(TILER_CONTEXT))); |
| 2500 |
} |
| 2501 |
} else { |
| 2502 |
#if PAN_ARCH >= 12 |
| 2503 |
cs_trace_run_idvs2(b, tracing_ctx, cs_scratch_reg_tuple(b, 0, 4), |
| 2504 |
flags_override.opaque[0], true, cs_undef(), |
| 2505 |
MALI_IDVS_SHADING_MODE_EARLY); |
| 2506 |
#else |
| 2507 |
cs_trace_run_idvs(b, tracing_ctx, cs_scratch_reg_tuple(b, 0, 4), |
| 2508 |
flags_override.opaque[0], true, |
| 2509 |
cs_shader_res_sel(0, 0, 1, 0), |
| 2510 |
cs_shader_res_sel(2, 2, 2, 0), cs_undef()); |
| 2511 |
#endif |
| 2512 |
} |
| 2513 |
} |
| 2514 |
} |
| 2515 |
|
| 2516 |
VkResult |
| 2517 |
panvk_per_arch(cmd_prepare_exec_cmd_for_draws)( |
| 2518 |
struct panvk_cmd_buffer *primary, |
| 2519 |
struct panvk_cmd_buffer *secondary) |
| 2520 |
{ |
| 2521 |
if (!(secondary->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) |
| 2522 |
return VK_SUCCESS; |
| 2523 |
|
| 2524 |
if (!inherits_render_ctx(primary)) { |
| 2525 |
enum u_tristate first_provoking_vertex = |
| 2526 |
secondary->state.gfx.render.first_provoking_vertex; |
| 2527 |
set_provoking_vertex_mode(primary, first_provoking_vertex); |
| 2528 |
VkResult result = get_render_ctx(primary); |
| 2529 |
if (result != VK_SUCCESS) |
| 2530 |
return result; |
| 2531 |
} |
| 2532 |
|
| 2533 |
return prepare_oq(primary); |
| 2534 |
} |
| 2535 |
|
| 2536 |
VKAPI_ATTR void VKAPI_CALL |
| 2537 |
panvk_per_arch(CmdDraw)(VkCommandBuffer commandBuffer, uint32_t vertexCount, |
| 2538 |
uint32_t instanceCount, uint32_t firstVertex, |
| 2539 |
uint32_t firstInstance) |
| 2540 |
{ |
| 2541 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 2542 |
|
| 2543 |
if (instanceCount == 0 || vertexCount == 0) |
| 2544 |
return; |
| 2545 |
|
| 2546 |
/* gl_BaseVertexARB is a signed integer, and it should expose the value of |
| 2547 |
* firstVertex in a non-indexed draw. */ |
| 2548 |
assert(firstVertex < INT32_MAX); |
| 2549 |
|
| 2550 |
/* gl_BaseInstance is a signed integer, and it should expose the value of |
| 2551 |
* firstInstnace. */ |
| 2552 |
assert(firstInstance < INT32_MAX); |
| 2553 |
|
| 2554 |
struct panvk_draw_info draw = { |
| 2555 |
.vertex.base = firstVertex, |
| 2556 |
.vertex.count = vertexCount, |
| 2557 |
.instance.base = firstInstance, |
| 2558 |
.instance.count = instanceCount, |
| 2559 |
}; |
| 2560 |
|
| 2561 |
panvk_cmd_draw(cmdbuf, &draw); |
| 2562 |
} |
| 2563 |
|
| 2564 |
VKAPI_ATTR void VKAPI_CALL |
| 2565 |
panvk_per_arch(CmdDrawIndexed)(VkCommandBuffer commandBuffer, |
| 2566 |
uint32_t indexCount, uint32_t instanceCount, |
| 2567 |
uint32_t firstIndex, int32_t vertexOffset, |
| 2568 |
uint32_t firstInstance) |
| 2569 |
{ |
| 2570 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 2571 |
|
| 2572 |
if (instanceCount == 0 || indexCount == 0) |
| 2573 |
return; |
| 2574 |
|
| 2575 |
/* gl_BaseInstance is a signed integer, and it should expose the value of |
| 2576 |
* firstInstnace. */ |
| 2577 |
assert(firstInstance < INT32_MAX); |
| 2578 |
|
| 2579 |
struct panvk_draw_info draw = { |
| 2580 |
.index.size = cmdbuf->state.gfx.ib.index_size, |
| 2581 |
.index.offset = firstIndex, |
| 2582 |
.vertex.base = vertexOffset, |
| 2583 |
.vertex.count = indexCount, |
| 2584 |
.instance.count = instanceCount, |
| 2585 |
.instance.base = firstInstance, |
| 2586 |
}; |
| 2587 |
|
| 2588 |
panvk_cmd_draw(cmdbuf, &draw); |
| 2589 |
} |
| 2590 |
|
| 2591 |
static void |
| 2592 |
panvk_cmd_draw_indirect(struct panvk_cmd_buffer *cmdbuf, |
| 2593 |
struct panvk_draw_info *draw) |
| 2594 |
{ |
| 2595 |
const struct cs_tracing_ctx *tracing_ctx = |
| 2596 |
&cmdbuf->state.cs[PANVK_SUBQUEUE_VERTEX_TILER].tracing; |
| 2597 |
const struct panvk_shader_variant *vs = |
| 2598 |
panvk_shader_hw_variant(cmdbuf->state.gfx.vs.shader); |
| 2599 |
struct cs_builder *b = |
| 2600 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 2601 |
VkResult result; |
| 2602 |
|
| 2603 |
/* If there's no vertex shader, we can skip the draw. */ |
| 2604 |
if (!panvk_priv_mem_check_alloc(vs->spd)) |
| 2605 |
return; |
| 2606 |
|
| 2607 |
/* Needs to be done before get_fs() is called because it depends on |
| 2608 |
* fs.required being initialized. */ |
| 2609 |
cmdbuf->state.gfx.fs.required = |
| 2610 |
fs_required(&cmdbuf->state.gfx, &cmdbuf->vk.dynamic_graphics_state); |
| 2611 |
|
| 2612 |
/* Layered indirect draw (VK_EXT_shader_viewport_index_layer) needs |
| 2613 |
* additional changes. We allow layer_count == 0 because that happens |
| 2614 |
* when mixing dynamic rendering and secondary command buffers. Once |
| 2615 |
* we decide to support layared+indirect, we'll need to pass the |
| 2616 |
* layer_count info through the tiler descriptor, for instance by |
| 2617 |
* re-using one of the word that's flagged 'ignored' in the descriptor |
| 2618 |
* (word 14:23). |
| 2619 |
* |
| 2620 |
* Multiview is limited to 8 layers, and so will always fit in one TD. |
| 2621 |
* Therefore layered rendering is allowed with multiview. */ |
| 2622 |
assert(cmdbuf->state.gfx.render.layer_count <= 1 || |
| 2623 |
cmdbuf->state.gfx.render.view_mask); |
| 2624 |
|
| 2625 |
/* Force a new push uniform block to be allocated */ |
| 2626 |
gfx_state_set_dirty(cmdbuf, VS_PUSH_UNIFORMS); |
| 2627 |
|
| 2628 |
result = prepare_draw(cmdbuf, draw); |
| 2629 |
if (result != VK_SUCCESS) |
| 2630 |
return; |
| 2631 |
|
| 2632 |
update_prims_generated_query(cmdbuf, draw); |
| 2633 |
|
| 2634 |
struct panvk_shader_desc_state *vs_desc_state = |
| 2635 |
&cmdbuf->state.gfx.vs.desc; |
| 2636 |
const struct vk_dynamic_graphics_state *dyns = |
| 2637 |
&cmdbuf->vk.dynamic_graphics_state; |
| 2638 |
const struct vk_vertex_input_state *vi = dyns->vi; |
| 2639 |
|
| 2640 |
struct mali_primitive_flags_packed flags_override = |
| 2641 |
get_tiler_flags_override(draw); |
| 2642 |
|
| 2643 |
uint32_t patch_attribs = |
| 2644 |
cmdbuf->state.gfx.vi.attribs_changing_on_base_instance; |
| 2645 |
uint32_t vs_res_table_size = |
| 2646 |
panvk_shader_res_table_count(&cmdbuf->state.gfx.vs.desc) * |
| 2647 |
pan_size(RESOURCE); |
| 2648 |
bool patch_faus = shader_uses_sysval(vs, graphics, vs.first_vertex) || |
| 2649 |
shader_uses_sysval(vs, graphics, vs.base_instance); |
| 2650 |
struct cs_index draw_params_addr = cs_scratch_reg64(b, 0); |
| 2651 |
struct cs_index vs_drv_set = cs_scratch_reg64(b, 2); |
| 2652 |
struct cs_index attrib_offset = cs_scratch_reg32(b, 4); |
| 2653 |
struct cs_index multiplicand = cs_scratch_reg32(b, 5); |
| 2654 |
struct cs_index draw_count = cs_scratch_reg32(b, 6); |
| 2655 |
struct cs_index max_draw_count = cs_scratch_reg32(b, 7); |
| 2656 |
struct cs_index draw_id = cs_scratch_reg32(b, 7); |
| 2657 |
struct cs_index vs_fau_addr = cs_scratch_reg64(b, 8); |
| 2658 |
struct cs_index tracing_scratch_regs = cs_scratch_reg_tuple(b, 10, 4); |
| 2659 |
uint32_t vs_fau_count = vs->fau.total_count; |
| 2660 |
|
| 2661 |
if (draw->indirect.count_buffer_dev_addr) { |
| 2662 |
cs_move32_to(b, max_draw_count, draw->indirect.draw_count); |
| 2663 |
cs_move64_to(b, draw_params_addr, draw->indirect.count_buffer_dev_addr); |
| 2664 |
cs_load32_to(b, draw_count, draw_params_addr, 0); |
| 2665 |
cs_umin32(b, draw_count, draw_count, max_draw_count); |
| 2666 |
} else { |
| 2667 |
cs_move32_to(b, draw_count, draw->indirect.draw_count); |
| 2668 |
} |
| 2669 |
|
| 2670 |
if (patch_faus) |
| 2671 |
cs_move64_to(b, vs_fau_addr, cmdbuf->state.gfx.vs.push_uniforms); |
| 2672 |
|
| 2673 |
if (patch_attribs != 0) |
| 2674 |
cs_move64_to(b, vs_drv_set, vs_desc_state->driver_set.dev_addr); |
| 2675 |
|
| 2676 |
cs_move64_to(b, draw_params_addr, draw->indirect.buffer_dev_addr); |
| 2677 |
cs_move32_to(b, draw_id, 0); |
| 2678 |
|
| 2679 |
panvk_cond_render(cmdbuf, b) |
| 2680 |
cs_while(b, MALI_CS_CONDITION_GREATER, draw_count) |
| 2681 |
{ |
| 2682 |
cs_update_vt_ctx(b) { |
| 2683 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, GLOBAL_ATTRIBUTE_OFFSET), 0); |
| 2684 |
/* Load SR33-37 from indirect buffer. */ |
| 2685 |
unsigned reg_mask = draw->index.size ? 0b11111 : 0b11011; |
| 2686 |
cs_load_to(b, cs_sr_reg_tuple(b, IDVS, INDEX_COUNT, 5), |
| 2687 |
draw_params_addr, reg_mask, 0); |
| 2688 |
} |
| 2689 |
|
| 2690 |
if (patch_faus) { |
| 2691 |
if (shader_uses_sysval(vs, graphics, vs.first_vertex)) { |
| 2692 |
cs_store32(b, cs_sr_reg32(b, IDVS, VERTEX_OFFSET), vs_fau_addr, |
| 2693 |
shader_remapped_sysval_offset( |
| 2694 |
vs, sysval_offset(graphics, vs.first_vertex))); |
| 2695 |
} |
| 2696 |
|
| 2697 |
if (shader_uses_sysval(vs, graphics, vs.base_instance)) { |
| 2698 |
cs_store32(b, cs_sr_reg32(b, IDVS, INSTANCE_OFFSET), vs_fau_addr, |
| 2699 |
shader_remapped_sysval_offset( |
| 2700 |
vs, sysval_offset(graphics, vs.base_instance))); |
| 2701 |
} |
| 2702 |
} |
| 2703 |
|
| 2704 |
if (patch_attribs != 0) { |
| 2705 |
/* If firstInstance=0, skip the offset adjustment. */ |
| 2706 |
cs_if(b, MALI_CS_CONDITION_NEQUAL, |
| 2707 |
cs_sr_reg32(b, IDVS, INSTANCE_OFFSET)) { |
| 2708 |
u_foreach_bit(i, patch_attribs) { |
| 2709 |
const struct vk_vertex_attribute_state *attrib_info = |
| 2710 |
&vi->attributes[i]; |
| 2711 |
const uint32_t stride = |
| 2712 |
dyns->vi_binding_strides[attrib_info->binding]; |
| 2713 |
|
| 2714 |
cs_load32_to(b, attrib_offset, vs_drv_set, |
| 2715 |
pan_size(ATTRIBUTE) * i + (2 * sizeof(uint32_t))); |
| 2716 |
|
| 2717 |
/* Emulated immediate multiply: we walk the bits in |
| 2718 |
* base_instance, and accumulate (stride << bit_pos) if the bit |
| 2719 |
* is present. This is sub-optimal, but it's simple :-). */ |
| 2720 |
cs_move_reg32(b, multiplicand, |
| 2721 |
cs_sr_reg32(b, IDVS, INSTANCE_OFFSET)); |
| 2722 |
|
| 2723 |
/* Flush the loads here so that we don't get automatic flushes |
| 2724 |
* over and over again due to the divergent nature of the if/else |
| 2725 |
* in the loop below. */ |
| 2726 |
cs_flush_loads(b); |
| 2727 |
for (uint32_t i = 31; i > 0; i--) { |
| 2728 |
uint32_t add = stride << i; |
| 2729 |
|
| 2730 |
/* bit31 is the sign bit, so we don't need to subtract to |
| 2731 |
* check the presence of the bit. */ |
| 2732 |
if (i < 31) |
| 2733 |
cs_add32(b, multiplicand, multiplicand, -(1 << i)); |
| 2734 |
|
| 2735 |
if (add) { |
| 2736 |
cs_if(b, MALI_CS_CONDITION_LESS, multiplicand) |
| 2737 |
cs_add32(b, multiplicand, multiplicand, 1 << i); |
| 2738 |
cs_else(b) |
| 2739 |
cs_add32(b, attrib_offset, attrib_offset, add); |
| 2740 |
} else { |
| 2741 |
cs_if(b, MALI_CS_CONDITION_LESS, multiplicand) |
| 2742 |
cs_add32(b, multiplicand, multiplicand, 1 << i); |
| 2743 |
} |
| 2744 |
} |
| 2745 |
|
| 2746 |
cs_if(b, MALI_CS_CONDITION_NEQUAL, multiplicand) |
| 2747 |
cs_add32(b, attrib_offset, attrib_offset, stride); |
| 2748 |
|
| 2749 |
cs_store32(b, attrib_offset, vs_drv_set, |
| 2750 |
pan_size(ATTRIBUTE) * i + (2 * sizeof(uint32_t))); |
| 2751 |
cs_flush_stores(b); |
| 2752 |
} |
| 2753 |
} |
| 2754 |
} |
| 2755 |
|
| 2756 |
/* NIR expects zero-based instance ID, but even if it did have an |
| 2757 |
* intrinsic to load the absolute instance ID, we'd want to keep it |
| 2758 |
* zero-based to work around Mali's limitation on non-zero firstInstance |
| 2759 |
* when a instance divisor is used. |
| 2760 |
*/ |
| 2761 |
cs_update_vt_ctx(b) |
| 2762 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, INSTANCE_OFFSET), 0); |
| 2763 |
|
| 2764 |
#if PAN_ARCH >= 12 |
| 2765 |
cs_trace_run_idvs2(b, tracing_ctx, tracing_scratch_regs, |
| 2766 |
flags_override.opaque[0], true, draw_id, |
| 2767 |
MALI_IDVS_SHADING_MODE_EARLY); |
| 2768 |
#else |
| 2769 |
cs_trace_run_idvs( |
| 2770 |
b, tracing_ctx, tracing_scratch_regs, flags_override.opaque[0], true, |
| 2771 |
cs_shader_res_sel(0, 0, 1, 0), cs_shader_res_sel(2, 2, 2, 0), draw_id); |
| 2772 |
#endif |
| 2773 |
|
| 2774 |
cs_add32(b, draw_count, draw_count, -1); |
| 2775 |
cs_add32(b, draw_id, draw_id, 1); |
| 2776 |
cs_add64(b, draw_params_addr, draw_params_addr, |
| 2777 |
draw->indirect.stride); |
| 2778 |
|
| 2779 |
if (patch_faus) { |
| 2780 |
cs_add64(b, vs_fau_addr, vs_fau_addr, vs_fau_count * sizeof(uint64_t)); |
| 2781 |
cs_update_vt_ctx(b) { |
| 2782 |
cs_add64(b, cs_sr_reg64(b, IDVS, VERTEX_FAU), |
| 2783 |
cs_sr_reg64(b, IDVS, VERTEX_FAU), |
| 2784 |
vs_fau_count * sizeof(uint64_t)); |
| 2785 |
} |
| 2786 |
|
| 2787 |
} |
| 2788 |
|
| 2789 |
if (patch_attribs != 0) { |
| 2790 |
cs_add64(b, vs_drv_set, vs_drv_set, |
| 2791 |
vs_desc_state->driver_set.size); |
| 2792 |
cs_update_vt_ctx(b) { |
| 2793 |
cs_add64(b, cs_sr_reg64(b, IDVS, VERTEX_SRT), |
| 2794 |
cs_sr_reg64(b, IDVS, VERTEX_SRT), vs_res_table_size); |
| 2795 |
} |
| 2796 |
} |
| 2797 |
} |
| 2798 |
} |
| 2799 |
|
| 2800 |
VKAPI_ATTR void VKAPI_CALL |
| 2801 |
panvk_per_arch(CmdDrawIndirect)(VkCommandBuffer commandBuffer, VkBuffer _buffer, |
| 2802 |
VkDeviceSize offset, uint32_t drawCount, |
| 2803 |
uint32_t stride) |
| 2804 |
{ |
| 2805 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 2806 |
VK_FROM_HANDLE(panvk_buffer, buffer, _buffer); |
| 2807 |
|
| 2808 |
if (drawCount == 0) |
| 2809 |
return; |
| 2810 |
|
| 2811 |
struct panvk_draw_info draw = { |
| 2812 |
.indirect.buffer_dev_addr = panvk_buffer_gpu_ptr(buffer, offset), |
| 2813 |
.indirect.draw_count = drawCount, |
| 2814 |
.indirect.stride = stride, |
| 2815 |
}; |
| 2816 |
|
| 2817 |
panvk_cmd_draw_indirect(cmdbuf, &draw); |
| 2818 |
} |
| 2819 |
|
| 2820 |
VKAPI_ATTR void VKAPI_CALL |
| 2821 |
panvk_per_arch(CmdDrawIndexedIndirect)(VkCommandBuffer commandBuffer, |
| 2822 |
VkBuffer _buffer, VkDeviceSize offset, |
| 2823 |
uint32_t drawCount, uint32_t stride) |
| 2824 |
{ |
| 2825 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 2826 |
VK_FROM_HANDLE(panvk_buffer, buffer, _buffer); |
| 2827 |
|
| 2828 |
if (drawCount == 0) |
| 2829 |
return; |
| 2830 |
|
| 2831 |
struct panvk_draw_info draw = { |
| 2832 |
.index.size = cmdbuf->state.gfx.ib.index_size, |
| 2833 |
.indirect.buffer_dev_addr = panvk_buffer_gpu_ptr(buffer, offset), |
| 2834 |
.indirect.draw_count = drawCount, |
| 2835 |
.indirect.stride = stride, |
| 2836 |
}; |
| 2837 |
|
| 2838 |
panvk_cmd_draw_indirect(cmdbuf, &draw); |
| 2839 |
} |
| 2840 |
|
| 2841 |
VKAPI_ATTR void VKAPI_CALL |
| 2842 |
panvk_per_arch(CmdDrawIndirectCount)(VkCommandBuffer commandBuffer, |
| 2843 |
VkBuffer _buffer, |
| 2844 |
VkDeviceSize offset, |
| 2845 |
VkBuffer countBuffer, |
| 2846 |
VkDeviceSize countBufferOffset, |
| 2847 |
uint32_t maxDrawCount, |
| 2848 |
uint32_t stride) |
| 2849 |
{ |
| 2850 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 2851 |
VK_FROM_HANDLE(panvk_buffer, buffer, _buffer); |
| 2852 |
VK_FROM_HANDLE(panvk_buffer, count_buffer, countBuffer); |
| 2853 |
|
| 2854 |
if (maxDrawCount == 0) |
| 2855 |
return; |
| 2856 |
|
| 2857 |
struct panvk_draw_info draw = { |
| 2858 |
.indirect.buffer_dev_addr = panvk_buffer_gpu_ptr(buffer, offset), |
| 2859 |
.indirect.count_buffer_dev_addr = |
| 2860 |
panvk_buffer_gpu_ptr(count_buffer, countBufferOffset), |
| 2861 |
.indirect.draw_count = maxDrawCount, |
| 2862 |
.indirect.stride = stride, |
| 2863 |
}; |
| 2864 |
|
| 2865 |
panvk_cmd_draw_indirect(cmdbuf, &draw); |
| 2866 |
} |
| 2867 |
|
| 2868 |
VKAPI_ATTR void VKAPI_CALL |
| 2869 |
panvk_per_arch(CmdDrawIndexedIndirectCount)(VkCommandBuffer commandBuffer, |
| 2870 |
VkBuffer _buffer, |
| 2871 |
VkDeviceSize offset, |
| 2872 |
VkBuffer countBuffer, |
| 2873 |
VkDeviceSize countBufferOffset, |
| 2874 |
uint32_t maxDrawCount, |
| 2875 |
uint32_t stride) |
| 2876 |
{ |
| 2877 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 2878 |
VK_FROM_HANDLE(panvk_buffer, buffer, _buffer); |
| 2879 |
VK_FROM_HANDLE(panvk_buffer, count_buffer, countBuffer); |
| 2880 |
|
| 2881 |
if (maxDrawCount == 0) |
| 2882 |
return; |
| 2883 |
|
| 2884 |
struct panvk_draw_info draw = { |
| 2885 |
.index.size = cmdbuf->state.gfx.ib.index_size, |
| 2886 |
.indirect.buffer_dev_addr = panvk_buffer_gpu_ptr(buffer, offset), |
| 2887 |
.indirect.count_buffer_dev_addr = |
| 2888 |
panvk_buffer_gpu_ptr(count_buffer, countBufferOffset), |
| 2889 |
.indirect.draw_count = maxDrawCount, |
| 2890 |
.indirect.stride = stride, |
| 2891 |
}; |
| 2892 |
|
| 2893 |
panvk_cmd_draw_indirect(cmdbuf, &draw); |
| 2894 |
} |
| 2895 |
|
| 2896 |
void |
| 2897 |
panvk_per_arch(cmd_inherit_render_state)( |
| 2898 |
struct panvk_cmd_buffer *cmdbuf, |
| 2899 |
const VkCommandBufferBeginInfo *pBeginInfo) |
| 2900 |
{ |
| 2901 |
if (cmdbuf->vk.level != VK_COMMAND_BUFFER_LEVEL_SECONDARY || |
| 2902 |
!(pBeginInfo->flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) |
| 2903 |
return; |
| 2904 |
|
| 2905 |
assert(pBeginInfo->pInheritanceInfo); |
| 2906 |
char gcbiar_data[VK_GCBIARR_DATA_SIZE(MAX_RTS)]; |
| 2907 |
const VkRenderingInfo *resume_info = |
| 2908 |
vk_get_command_buffer_inheritance_as_rendering_resume(cmdbuf->vk.level, |
| 2909 |
pBeginInfo, |
| 2910 |
gcbiar_data); |
| 2911 |
if (resume_info) { |
| 2912 |
panvk_per_arch(cmd_init_render_state)(cmdbuf, resume_info); |
| 2913 |
return; |
| 2914 |
} |
| 2915 |
|
| 2916 |
const VkCommandBufferInheritanceRenderingInfo *inheritance_info = |
| 2917 |
vk_get_command_buffer_inheritance_rendering_info(cmdbuf->vk.level, |
| 2918 |
pBeginInfo); |
| 2919 |
assert(inheritance_info); |
| 2920 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 2921 |
struct panvk_physical_device *phys_dev = |
| 2922 |
to_panvk_physical_device(dev->vk.physical); |
| 2923 |
struct panvk_rendering_state *render = &cmdbuf->state.gfx.render; |
| 2924 |
|
| 2925 |
render->first_provoking_vertex = U_TRISTATE_UNSET; |
| 2926 |
render->maybe_set_tds_provoking_vertex = NULL; |
| 2927 |
render->maybe_set_fbds_provoking_vertex = NULL; |
| 2928 |
render->suspended = false; |
| 2929 |
render->flags = inheritance_info->flags; |
| 2930 |
|
| 2931 |
gfx_state_set_dirty(cmdbuf, RENDER_STATE); |
| 2932 |
memset(&render->color_attachments, 0, sizeof(render->color_attachments)); |
| 2933 |
memset(&render->z_attachment, 0, sizeof(render->z_attachment)); |
| 2934 |
memset(&render->s_attachment, 0, sizeof(render->s_attachment)); |
| 2935 |
cmdbuf->state.gfx.render.bound_attachments = 0; |
| 2936 |
|
| 2937 |
render->view_mask = inheritance_info->viewMask; |
| 2938 |
render->layer_count = inheritance_info->viewMask ? |
| 2939 |
util_last_bit(inheritance_info->viewMask) : 0; |
| 2940 |
|
| 2941 |
/* If a draw was performed, the inherited sample count should match our current sample count */ |
| 2942 |
const uint32_t sample_count = inheritance_info->rasterizationSamples; |
| 2943 |
assert(render->fb.layout.sample_count == 0 || |
| 2944 |
render->fb.layout.sample_count == sample_count); |
| 2945 |
render->fb.layout = (struct pan_fb_layout) { |
| 2946 |
.sample_count = sample_count, |
| 2947 |
.rt_count = MAX2(inheritance_info->colorAttachmentCount, 1), |
| 2948 |
|
| 2949 |
.tile_size_px = render->fb.layout.tile_size_px, |
| 2950 |
.tile_rt_alloc_B = render->fb.layout.tile_rt_alloc_B, |
| 2951 |
.tile_rt_budget_B = |
| 2952 |
pan_query_optimal_tib_size(PAN_ARCH, phys_dev->model), |
| 2953 |
.tile_z_budget_B = |
| 2954 |
pan_query_optimal_z_tib_size(PAN_ARCH, phys_dev->model), |
| 2955 |
}; |
| 2956 |
render->fb.nr_samples = sample_count; |
| 2957 |
|
| 2958 |
assert(inheritance_info->colorAttachmentCount <= PAN_MAX_RTS); |
| 2959 |
|
| 2960 |
for (uint32_t i = 0; i < inheritance_info->colorAttachmentCount; i++) { |
| 2961 |
render->bound_attachments |= MESA_VK_RP_ATTACHMENT_COLOR_BIT(i); |
| 2962 |
render->color_attachments.fmts[i] = |
| 2963 |
inheritance_info->pColorAttachmentFormats[i]; |
| 2964 |
render->color_attachments.samples[i] = |
| 2965 |
inheritance_info->rasterizationSamples; |
| 2966 |
render->fb.layout.rt_formats[i] = |
| 2967 |
vk_format_to_pipe_format(inheritance_info->pColorAttachmentFormats[i]); |
| 2968 |
} |
| 2969 |
|
| 2970 |
if (inheritance_info->depthAttachmentFormat) { |
| 2971 |
render->bound_attachments |= MESA_VK_RP_ATTACHMENT_DEPTH_BIT; |
| 2972 |
render->z_attachment.fmt = inheritance_info->depthAttachmentFormat; |
| 2973 |
render->fb.layout.z_format = |
| 2974 |
vk_format_to_pipe_format(inheritance_info->depthAttachmentFormat); |
| 2975 |
} |
| 2976 |
|
| 2977 |
if (inheritance_info->stencilAttachmentFormat) { |
| 2978 |
render->bound_attachments |= MESA_VK_RP_ATTACHMENT_STENCIL_BIT; |
| 2979 |
render->s_attachment.fmt = inheritance_info->stencilAttachmentFormat; |
| 2980 |
render->fb.layout.s_format = |
| 2981 |
vk_format_to_pipe_format(inheritance_info->stencilAttachmentFormat); |
| 2982 |
} |
| 2983 |
|
| 2984 |
const VkRenderingAttachmentLocationInfoKHR att_loc_info_default = { |
| 2985 |
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_LOCATION_INFO_KHR, |
| 2986 |
.colorAttachmentCount = inheritance_info->colorAttachmentCount, |
| 2987 |
}; |
| 2988 |
const VkRenderingAttachmentLocationInfoKHR *att_loc_info = |
| 2989 |
vk_get_command_buffer_rendering_attachment_location_info( |
| 2990 |
cmdbuf->vk.level, pBeginInfo); |
| 2991 |
if (att_loc_info == NULL) |
| 2992 |
att_loc_info = &att_loc_info_default; |
| 2993 |
|
| 2994 |
vk_cmd_set_rendering_attachment_locations(&cmdbuf->vk, att_loc_info); |
| 2995 |
} |
| 2996 |
|
| 2997 |
VKAPI_ATTR void VKAPI_CALL |
| 2998 |
panvk_per_arch(CmdBeginRendering)(VkCommandBuffer commandBuffer, |
| 2999 |
const VkRenderingInfo *pRenderingInfo) |
| 3000 |
{ |
| 3001 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 3002 |
ASSERTED struct panvk_cmd_graphics_state *state = &cmdbuf->state.gfx; |
| 3003 |
bool resuming = pRenderingInfo->flags & VK_RENDERING_RESUMING_BIT; |
| 3004 |
|
| 3005 |
panvk_per_arch(cmd_init_render_state)(cmdbuf, pRenderingInfo); |
| 3006 |
|
| 3007 |
/* If we're not resuming, the FBD should be NULL. */ |
| 3008 |
assert(!state->render.fbds.gpu || resuming); |
| 3009 |
|
| 3010 |
panvk_per_arch(panvk_instr_begin_work)(PANVK_SUBQUEUE_VERTEX_TILER, cmdbuf, |
| 3011 |
PANVK_INSTR_WORK_TYPE_RENDER); |
| 3012 |
panvk_per_arch(panvk_instr_begin_work)(PANVK_SUBQUEUE_FRAGMENT, cmdbuf, |
| 3013 |
PANVK_INSTR_WORK_TYPE_RENDER); |
| 3014 |
} |
| 3015 |
|
| 3016 |
static void |
| 3017 |
set_run_fullscreen_tiler_flags(struct cs_builder *b, uint32_t view_mask) |
| 3018 |
{ |
| 3019 |
struct mali_primitive_flags_packed tiler_flags; |
| 3020 |
pan_pack(&tiler_flags, PRIMITIVE_FLAGS, cfg) { |
| 3021 |
cfg.draw_mode = MALI_DRAW_MODE_TRIANGLES; |
| 3022 |
cfg.position_fifo_format = MALI_FIFO_FORMAT_BASIC; |
| 3023 |
cfg.view_mask = view_mask; |
| 3024 |
} |
| 3025 |
|
| 3026 |
cs_update_vt_ctx(b) |
| 3027 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, TILER_FLAGS), tiler_flags.opaque[0]); |
| 3028 |
} |
| 3029 |
|
| 3030 |
static void |
| 3031 |
cmd_run_fullscreen(struct panvk_cmd_buffer *cmdbuf, |
| 3032 |
uint64_t dcd, bool ignore_scissor) |
| 3033 |
{ |
| 3034 |
const struct cs_tracing_ctx *tracing_ctx = |
| 3035 |
&cmdbuf->state.cs[PANVK_SUBQUEUE_VERTEX_TILER].tracing; |
| 3036 |
struct cs_builder *b = |
| 3037 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 3038 |
|
| 3039 |
if (!inherits_render_ctx(cmdbuf)) { |
| 3040 |
VkResult result = get_render_ctx(cmdbuf); |
| 3041 |
if (result != VK_SUCCESS) |
| 3042 |
return; |
| 3043 |
} |
| 3044 |
|
| 3045 |
struct cs_index draw_ptr = cs_scratch_reg64(b, 0); |
| 3046 |
struct cs_index tf_tmp = cs_scratch_reg32(b, 2); |
| 3047 |
#if PAN_ARCH >= 11 |
| 3048 |
struct cs_index tf2_tmp = cs_scratch_reg32(b, 3); |
| 3049 |
#endif |
| 3050 |
#if PAN_ARCH >= 13 |
| 3051 |
struct cs_index dcd0_tmp = cs_scratch_reg32(b, 4); |
| 3052 |
struct cs_index dcd1_tmp = cs_scratch_reg32(b, 5); |
| 3053 |
struct cs_index dcd2_tmp = cs_scratch_reg32(b, 6); |
| 3054 |
#endif |
| 3055 |
struct cs_index scissor_tmp = cs_scratch_reg64(b, 8); |
| 3056 |
struct cs_index counter = cs_scratch_reg32(b, 10); |
| 3057 |
struct cs_index trace_regs = cs_scratch_reg_tuple(b, 12, 4); |
| 3058 |
|
| 3059 |
cs_move64_to(b, draw_ptr, dcd); |
| 3060 |
|
| 3061 |
/* We need to set our own tiler flags so save them off */ |
| 3062 |
cs_move_reg32(b, tf_tmp, cs_sr_reg32(b, IDVS, TILER_FLAGS)); |
| 3063 |
|
| 3064 |
#if PAN_ARCH >= 11 |
| 3065 |
cs_move_reg32(b, tf2_tmp, cs_sr_reg32(b, IDVS, TILER_FLAGS2)); |
| 3066 |
cs_update_vt_ctx(b) { |
| 3067 |
struct mali_primitive_flags_2_packed tiler_flags_2; |
| 3068 |
pan_pack(&tiler_flags_2, PRIMITIVE_FLAGS_2, cfg) { |
| 3069 |
} |
| 3070 |
cs_move32_to(b, cs_sr_reg32(b, IDVS, TILER_FLAGS2), |
| 3071 |
tiler_flags_2.opaque[0]); |
| 3072 |
} |
| 3073 |
#endif |
| 3074 |
|
| 3075 |
/* Starting with v13, the DCD flag registers have to match the flag fields |
| 3076 |
* in the DrawCallDescriptor we provide in memory so we have to save them |
| 3077 |
* off. |
| 3078 |
*/ |
| 3079 |
#if PAN_ARCH >= 13 |
| 3080 |
cs_move_reg32(b, dcd0_tmp, cs_sr_reg32(b, IDVS, DCD0)); |
| 3081 |
cs_move_reg32(b, dcd1_tmp, cs_sr_reg32(b, IDVS, DCD1)); |
| 3082 |
cs_move_reg32(b, dcd2_tmp, cs_sr_reg32(b, IDVS, DCD2)); |
| 3083 |
|
| 3084 |
cs_update_vt_ctx(b) { |
| 3085 |
cs_load32_to(b, cs_sr_reg32(b, IDVS, DCD0), draw_ptr, 0); |
| 3086 |
cs_load32_to(b, cs_sr_reg32(b, IDVS, DCD1), draw_ptr, 1 * 4); |
| 3087 |
cs_load32_to(b, cs_sr_reg32(b, IDVS, DCD2), draw_ptr, 5 * 4); |
| 3088 |
} |
| 3089 |
#endif |
| 3090 |
|
| 3091 |
/* RUN_FULLSCREEN respects scissors but for some things like barrier draws, |
| 3092 |
* we want to ignore the scissor so we have to save off the old one and use |
| 3093 |
* a default. |
| 3094 |
*/ |
| 3095 |
if (ignore_scissor) { |
| 3096 |
struct mali_scissor_packed scissor; |
| 3097 |
pan_pack(&scissor, SCISSOR, cfg) { |
| 3098 |
cfg.scissor_minimum_x = 0; |
| 3099 |
cfg.scissor_minimum_y = 0; |
| 3100 |
cfg.scissor_maximum_x = UINT16_MAX; |
| 3101 |
cfg.scissor_maximum_y = UINT16_MAX; |
| 3102 |
} |
| 3103 |
|
| 3104 |
cs_move_reg64(b, scissor_tmp, cs_sr_reg64(b, IDVS, SCISSOR_BOX)); |
| 3105 |
|
| 3106 |
cs_update_vt_ctx(b) { |
| 3107 |
cs_move64_to(b, cs_sr_reg64(b, IDVS, SCISSOR_BOX), |
| 3108 |
scissor.opaque[0] | (uint64_t)scissor.opaque[1] << 32); |
| 3109 |
} |
| 3110 |
} |
| 3111 |
|
| 3112 |
uint32_t layer_count = cmdbuf->state.gfx.render.layer_count; |
| 3113 |
uint32_t view_mask = cmdbuf->state.gfx.render.view_mask; |
| 3114 |
uint32_t tiler_count = DIV_ROUND_UP(layer_count, MAX_LAYERS_PER_TILER_DESC); |
| 3115 |
if (tiler_count > 1) { |
| 3116 |
struct cs_index tiler_ctx_addr = cs_sr_reg64(b, IDVS, TILER_CTX); |
| 3117 |
|
| 3118 |
/* Multiview always fits inside a single tiler context */ |
| 3119 |
assert(view_mask == 0); |
| 3120 |
|
| 3121 |
/* Start off with a full view mask */ |
| 3122 |
set_run_fullscreen_tiler_flags(b, |
| 3123 |
BITFIELD_MASK(MAX_LAYERS_PER_TILER_DESC)); |
| 3124 |
|
| 3125 |
cs_move32_to(b, counter, tiler_count); |
| 3126 |
cs_while(b, MALI_CS_CONDITION_GREATER, counter) { |
| 3127 |
cs_add32(b, counter, counter, -1); |
| 3128 |
cs_if(b, MALI_CS_CONDITION_EQUAL, counter) { |
| 3129 |
set_run_fullscreen_tiler_flags(b, |
| 3130 |
BITFIELD_MASK(layer_count % MAX_LAYERS_PER_TILER_DESC)); |
| 3131 |
} |
| 3132 |
|
| 3133 |
cs_trace_run_fullscreen(b, tracing_ctx, trace_regs, 0, draw_ptr); |
| 3134 |
|
| 3135 |
cs_update_vt_ctx(b) { |
| 3136 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 3137 |
pan_size(TILER_CONTEXT)); |
| 3138 |
} |
| 3139 |
} |
| 3140 |
|
| 3141 |
cs_update_vt_ctx(b) { |
| 3142 |
cs_add64(b, tiler_ctx_addr, tiler_ctx_addr, |
| 3143 |
-(tiler_count * pan_size(TILER_CONTEXT))); |
| 3144 |
} |
| 3145 |
} else { |
| 3146 |
set_run_fullscreen_tiler_flags(b, |
| 3147 |
view_mask ? view_mask : BITFIELD_MASK(layer_count)); |
| 3148 |
|
| 3149 |
cs_trace_run_fullscreen(b, tracing_ctx, trace_regs, 0, draw_ptr); |
| 3150 |
} |
| 3151 |
|
| 3152 |
cs_update_vt_ctx(b) { |
| 3153 |
cs_move_reg32(b, cs_sr_reg32(b, IDVS, TILER_FLAGS), tf_tmp); |
| 3154 |
#if PAN_ARCH >= 11 |
| 3155 |
cs_move_reg32(b, cs_sr_reg32(b, IDVS, TILER_FLAGS2), tf2_tmp); |
| 3156 |
#endif |
| 3157 |
#if PAN_ARCH >= 13 |
| 3158 |
cs_move_reg32(b, cs_sr_reg32(b, IDVS, DCD0), dcd0_tmp); |
| 3159 |
cs_move_reg32(b, cs_sr_reg32(b, IDVS, DCD1), dcd1_tmp); |
| 3160 |
cs_move_reg32(b, cs_sr_reg32(b, IDVS, DCD2), dcd2_tmp); |
| 3161 |
#endif |
| 3162 |
if (ignore_scissor) |
| 3163 |
cs_move_reg64(b, cs_sr_reg64(b, IDVS, SCISSOR_BOX), scissor_tmp); |
| 3164 |
} |
| 3165 |
} |
| 3166 |
|
| 3167 |
void |
| 3168 |
panvk_per_arch(cmd_fb_barrier)(struct panvk_cmd_buffer *cmdbuf) |
| 3169 |
{ |
| 3170 |
struct pan_ptr zsd = panvk_cmd_alloc_desc(cmdbuf, DEPTH_STENCIL); |
| 3171 |
if (!zsd.gpu) |
| 3172 |
return; |
| 3173 |
|
| 3174 |
pan_cast_and_pack(zsd.cpu, DEPTH_STENCIL, cfg) { |
| 3175 |
cfg.stencil_test_enable = false; |
| 3176 |
cfg.depth_write_enable = false; |
| 3177 |
cfg.depth_function = MALI_FUNC_ALWAYS; |
| 3178 |
}; |
| 3179 |
|
| 3180 |
struct pan_ptr dcd = panvk_cmd_alloc_desc(cmdbuf, DRAW); |
| 3181 |
if (!dcd.gpu) |
| 3182 |
return; |
| 3183 |
|
| 3184 |
pan_cast_and_pack(dcd.cpu, DRAW, cfg) { |
| 3185 |
cfg.flags_0.allow_forward_pixel_to_kill = false; |
| 3186 |
cfg.flags_0.allow_forward_pixel_to_be_killed = false; |
| 3187 |
cfg.flags_0.primitive_barrier = true; |
| 3188 |
cfg.flags_0.occlusion_query = MALI_OCCLUSION_MODE_DISABLED; |
| 3189 |
|
| 3190 |
cfg.flags_2.read_mask = 0; |
| 3191 |
cfg.flags_2.write_mask = 0; |
| 3192 |
#if PAN_ARCH >= 11 |
| 3193 |
cfg.flags_2.no_shader_depth_read = true; |
| 3194 |
cfg.flags_2.no_shader_stencil_read = true; |
| 3195 |
#endif |
| 3196 |
|
| 3197 |
cfg.depth_stencil = zsd.gpu; |
| 3198 |
}; |
| 3199 |
|
| 3200 |
cmd_run_fullscreen(cmdbuf, dcd.gpu, true); |
| 3201 |
} |
| 3202 |
|
| 3203 |
static void |
| 3204 |
flush_tiling(struct panvk_cmd_buffer *cmdbuf) |
| 3205 |
{ |
| 3206 |
struct cs_builder *b = |
| 3207 |
panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER); |
| 3208 |
|
| 3209 |
if (!cmdbuf->state.gfx.render.tiler && !inherits_render_ctx(cmdbuf)) |
| 3210 |
return; |
| 3211 |
|
| 3212 |
/* Flush the tiling operations and signal the internal sync object. */ |
| 3213 |
cs_finish_tiling(b); |
| 3214 |
|
| 3215 |
/* We're relying on PANVK_SUBQUEUE_VERTEX_TILER being the first queue to |
| 3216 |
* skip an ADD operation on the syncobjs pointer. */ |
| 3217 |
STATIC_ASSERT(PANVK_SUBQUEUE_VERTEX_TILER == 0); |
| 3218 |
|
| 3219 |
#if PAN_ARCH >= 11 |
| 3220 |
struct cs_index sync_addr = cs_scratch_reg64(b, 0); |
| 3221 |
struct cs_index add_val = cs_scratch_reg64(b, 2); |
| 3222 |
|
| 3223 |
cs_load64_to(b, sync_addr, cs_subqueue_ctx_reg(b), |
| 3224 |
offsetof(struct panvk_cs_subqueue_context, syncobjs)); |
| 3225 |
|
| 3226 |
cs_move64_to(b, add_val, 1); |
| 3227 |
cs_vt_end(b, cs_defer_indirect()); |
| 3228 |
panvk_instr_sync64_add(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER, true, |
| 3229 |
MALI_CS_SYNC_SCOPE_CSG, add_val, sync_addr, |
| 3230 |
cs_defer_indirect()); |
| 3231 |
#else |
| 3232 |
struct cs_index sync_addr = cs_scratch_reg64(b, 0); |
| 3233 |
struct cs_index iter_sb = cs_scratch_reg32(b, 2); |
| 3234 |
struct cs_index cmp_scratch = cs_scratch_reg32(b, 3); |
| 3235 |
struct cs_index add_val = cs_scratch_reg64(b, 4); |
| 3236 |
|
| 3237 |
cs_load_to(b, cs_scratch_reg_tuple(b, 0, 3), cs_subqueue_ctx_reg(b), |
| 3238 |
BITFIELD_MASK(3), |
| 3239 |
offsetof(struct panvk_cs_subqueue_context, syncobjs)); |
| 3240 |
|
| 3241 |
cs_move64_to(b, add_val, 1); |
| 3242 |
|
| 3243 |
cs_match_iter_sb(b, x, iter_sb, cmp_scratch) { |
| 3244 |
cs_vt_end(b, cs_defer(SB_WAIT_ITER(x), SB_ID(DEFERRED_SYNC))); |
| 3245 |
panvk_instr_sync64_add(cmdbuf, PANVK_SUBQUEUE_VERTEX_TILER, true, |
| 3246 |
MALI_CS_SYNC_SCOPE_CSG, add_val, sync_addr, |
| 3247 |
cs_defer(SB_WAIT_ITER(x), SB_ID(DEFERRED_SYNC))); |
| 3248 |
} |
| 3249 |
#endif |
| 3250 |
|
| 3251 |
/* Update the vertex seqno. */ |
| 3252 |
++cmdbuf->state.cs[PANVK_SUBQUEUE_VERTEX_TILER].relative_sync_point; |
| 3253 |
} |
| 3254 |
|
| 3255 |
static void |
| 3256 |
wait_finish_tiling(struct panvk_cmd_buffer *cmdbuf) |
| 3257 |
{ |
| 3258 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_FRAGMENT); |
| 3259 |
struct cs_index vt_sync_addr = cs_scratch_reg64(b, 0); |
| 3260 |
struct cs_index vt_sync_point = cs_scratch_reg64(b, 2); |
| 3261 |
uint64_t rel_vt_sync_point = |
| 3262 |
cmdbuf->state.cs[PANVK_SUBQUEUE_VERTEX_TILER].relative_sync_point; |
| 3263 |
|
| 3264 |
cs_load64_to(b, vt_sync_addr, cs_subqueue_ctx_reg(b), |
| 3265 |
offsetof(struct panvk_cs_subqueue_context, syncobjs)); |
| 3266 |
|
| 3267 |
cs_add64(b, vt_sync_point, |
| 3268 |
cs_progress_seqno_reg(b, PANVK_SUBQUEUE_VERTEX_TILER), |
| 3269 |
rel_vt_sync_point); |
| 3270 |
|
| 3271 |
panvk_instr_sync64_wait(cmdbuf, PANVK_SUBQUEUE_FRAGMENT, false, |
| 3272 |
MALI_CS_CONDITION_GREATER, vt_sync_point, |
| 3273 |
vt_sync_addr); |
| 3274 |
} |
| 3275 |
|
| 3276 |
static uint32_t |
| 3277 |
calc_tiler_oom_handler_idx(struct panvk_cmd_buffer *cmdbuf) |
| 3278 |
{ |
| 3279 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 3280 |
const bool has_zs_ext = pan_fb_has_zs(fb); |
| 3281 |
|
| 3282 |
return get_tiler_oom_handler_idx(has_zs_ext, fb->rt_count); |
| 3283 |
} |
| 3284 |
|
| 3285 |
static void |
| 3286 |
setup_tiler_oom_ctx(struct panvk_cmd_buffer *cmdbuf) |
| 3287 |
{ |
| 3288 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_FRAGMENT); |
| 3289 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 3290 |
const bool has_zs_ext = pan_fb_has_zs(fb); |
| 3291 |
struct mali_framebuffer_pointer_packed fb_tag; |
| 3292 |
|
| 3293 |
uint32_t layer_count = cmdbuf->state.gfx.render.layer_count; |
| 3294 |
uint32_t td_count = DIV_ROUND_UP(layer_count, MAX_LAYERS_PER_TILER_DESC); |
| 3295 |
|
| 3296 |
pan_pack(&fb_tag, FRAMEBUFFER_POINTER, cfg) { |
| 3297 |
cfg.zs_crc_extension_present = has_zs_ext; |
| 3298 |
cfg.render_target_count = fb->rt_count; |
| 3299 |
} |
| 3300 |
|
| 3301 |
struct cs_index counter = cs_scratch_reg32(b, 1); |
| 3302 |
cs_move32_to(b, counter, 0); |
| 3303 |
cs_store32(b, counter, cs_subqueue_ctx_reg(b), |
| 3304 |
TILER_OOM_CTX_FIELD_OFFSET(counter)); |
| 3305 |
|
| 3306 |
struct cs_index fbd_ptr_reg = cs_scratch_reg64(b, 6); |
| 3307 |
cs_add64(b, fbd_ptr_reg, cs_sr_reg64(b, FRAGMENT, FBD_POINTER), |
| 3308 |
-(int32_t)fb_tag.opaque[0]); |
| 3309 |
cs_store64(b, fbd_ptr_reg, cs_subqueue_ctx_reg(b), |
| 3310 |
TILER_OOM_CTX_FIELD_OFFSET(layer_fbd_ptr)); |
| 3311 |
|
| 3312 |
for (uint32_t ir_pass = 0; ir_pass < PANVK_IR_PASS_COUNT; ir_pass++) { |
| 3313 |
const uint32_t ir_descs_offset = |
| 3314 |
TILER_OOM_CTX_FIELD_OFFSET(ir_descs) + (sizeof(uint64_t) * ir_pass); |
| 3315 |
struct cs_index ir_fbds_reg = cs_scratch_reg64(b, 2); |
| 3316 |
|
| 3317 |
cs_move64_to(b, ir_fbds_reg, cmdbuf->state.gfx.render.ir.fbds[ir_pass]); |
| 3318 |
cs_store64(b, ir_fbds_reg, cs_subqueue_ctx_reg(b), ir_descs_offset); |
| 3319 |
} |
| 3320 |
|
| 3321 |
struct cs_index td_count_reg = cs_scratch_reg32(b, 4); |
| 3322 |
cs_move32_to(b, td_count_reg, td_count); |
| 3323 |
cs_store32(b, td_count_reg, cs_subqueue_ctx_reg(b), |
| 3324 |
TILER_OOM_CTX_FIELD_OFFSET(td_count)); |
| 3325 |
|
| 3326 |
struct cs_index layer_count_index = cs_scratch_reg32(b, 5); |
| 3327 |
cs_move32_to(b, layer_count_index, layer_count); |
| 3328 |
cs_store32(b, layer_count_index, cs_subqueue_ctx_reg(b), |
| 3329 |
TILER_OOM_CTX_FIELD_OFFSET(layer_count)); |
| 3330 |
|
| 3331 |
cs_flush_stores(b); |
| 3332 |
} |
| 3333 |
|
| 3334 |
static uint32_t |
| 3335 |
pack_32_2x16(uint16_t lo, uint16_t hi) |
| 3336 |
{ |
| 3337 |
return (((uint32_t)hi) << 16) | (uint32_t)lo; |
| 3338 |
} |
| 3339 |
|
| 3340 |
static VkResult |
| 3341 |
issue_fragment_jobs(struct panvk_cmd_buffer *cmdbuf) |
| 3342 |
{ |
| 3343 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 3344 |
const struct cs_tracing_ctx *tracing_ctx = |
| 3345 |
&cmdbuf->state.cs[PANVK_SUBQUEUE_FRAGMENT].tracing; |
| 3346 |
const struct pan_fb_layout *fb = &cmdbuf->state.gfx.render.fb.layout; |
| 3347 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, PANVK_SUBQUEUE_FRAGMENT); |
| 3348 |
bool has_oq_chain = cmdbuf->state.gfx.render.oq.chain != 0; |
| 3349 |
|
| 3350 |
/* Now initialize the fragment bits. */ |
| 3351 |
cs_update_frag_ctx(b) { |
| 3352 |
cs_move32_to(b, cs_sr_reg32(b, FRAGMENT, BBOX_MIN), |
| 3353 |
pack_32_2x16(fb->tiling_area_px.min_x, |
| 3354 |
fb->tiling_area_px.min_y)); |
| 3355 |
cs_move32_to(b, cs_sr_reg32(b, FRAGMENT, BBOX_MAX), |
| 3356 |
pack_32_2x16(fb->tiling_area_px.max_x, |
| 3357 |
fb->tiling_area_px.max_y)); |
| 3358 |
} |
| 3359 |
|
| 3360 |
bool simul_use = |
| 3361 |
cmdbuf->flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; |
| 3362 |
|
| 3363 |
/* The only bit we patch in FBDs is the tiler pointer. If tiler is not |
| 3364 |
* involved (clear job) or if the update can happen in place (not |
| 3365 |
* simultaneous use of the command buffer), we can avoid the |
| 3366 |
* copy. */ |
| 3367 |
bool needs_tiling = |
| 3368 |
cmdbuf->state.gfx.render.tiler || inherits_render_ctx(cmdbuf); |
| 3369 |
|
| 3370 |
/* If the command buffer can run in parallel on different queues, we need |
| 3371 |
* to make sure each instance has its own descriptors, unless tiling is |
| 3372 |
* not needed (AKA RUN_FRAGMENT used for clears), because then the FBD |
| 3373 |
* descriptors are constant (no need to patch them at runtime). */ |
| 3374 |
bool free_render_descs = simul_use && needs_tiling; |
| 3375 |
uint32_t fbd_sz = calc_fbd_size(cmdbuf); |
| 3376 |
uint32_t td_count = 0; |
| 3377 |
if (needs_tiling) { |
| 3378 |
td_count = DIV_ROUND_UP(cmdbuf->state.gfx.render.layer_count, |
| 3379 |
MAX_LAYERS_PER_TILER_DESC); |
| 3380 |
} |
| 3381 |
|
| 3382 |
/* Update the Tiler OOM context */ |
| 3383 |
setup_tiler_oom_ctx(cmdbuf); |
| 3384 |
|
| 3385 |
/* Enable the oom handler before waiting for the vertex/tiler work. |
| 3386 |
* At this point, the tiler oom context has been set up with the correct |
| 3387 |
* state for this renderpass, so it's safe to enable. */ |
| 3388 |
struct cs_index addr_reg = cs_scratch_reg64(b, 0); |
| 3389 |
struct cs_index length_reg = cs_scratch_reg32(b, 2); |
| 3390 |
uint32_t handler_idx = calc_tiler_oom_handler_idx(cmdbuf); |
| 3391 |
uint64_t handler_addr = dev->tiler_oom.handlers_bo->addr.dev + |
| 3392 |
handler_idx * dev->tiler_oom.handler_stride; |
| 3393 |
cs_move64_to(b, addr_reg, handler_addr); |
| 3394 |
cs_move32_to(b, length_reg, dev->tiler_oom.handler_stride); |
| 3395 |
cs_set_exception_handler(b, MALI_CS_EXCEPTION_TYPE_TILER_OOM, addr_reg, |
| 3396 |
length_reg); |
| 3397 |
|
| 3398 |
/* Wait for the tiling to be done before submitting the fragment job. */ |
| 3399 |
wait_finish_tiling(cmdbuf); |
| 3400 |
|
| 3401 |
/* Disable the oom handler once the vertex/tiler work has finished. |
| 3402 |
* We need to disable the handler at this point as the vertex/tiler subqueue |
| 3403 |
* might continue on to the next renderpass and hit an out-of-memory |
| 3404 |
* exception prior to the fragment subqueue setting up the tiler oom context |
| 3405 |
* for the next renderpass. |
| 3406 |
* By disabling the handler here, any exception will be left pending until a |
| 3407 |
* new hander is registered, at which point the correct state has been set |
| 3408 |
* up. */ |
| 3409 |
cs_move64_to(b, addr_reg, 0); |
| 3410 |
cs_move32_to(b, length_reg, 0); |
| 3411 |
cs_set_exception_handler(b, MALI_CS_EXCEPTION_TYPE_TILER_OOM, addr_reg, |
| 3412 |
length_reg); |
| 3413 |
|
| 3414 |
/* Applications tend to forget to describe subpass dependencies, especially |
| 3415 |
* when it comes to write -> read dependencies on attachments. The |
| 3416 |
* proprietary driver forces "others" invalidation as a workaround, and this |
| 3417 |
* invalidation even became implicit (done as part of the RUN_FRAGMENT) on |
| 3418 |
* v13+. We don't do that in panvk, but we provide a debug flag to help |
| 3419 |
* identify those issues. */ |
| 3420 |
if (PANVK_DEBUG(IMPLICIT_OTHERS_INV)) { |
| 3421 |
cs_flush_caches(b, MALI_CS_FLUSH_MODE_NONE, MALI_CS_FLUSH_MODE_NONE, |
| 3422 |
MALI_CS_OTHER_FLUSH_MODE_INVALIDATE, length_reg, |
| 3423 |
cs_defer(0x0, SB_ID(IMM_FLUSH))); |
| 3424 |
cs_wait_slot(b, SB_ID(IMM_FLUSH)); |
| 3425 |
} |
| 3426 |
|
| 3427 |
if (cmdbuf->state.gfx.render.layer_count <= 1) { |
| 3428 |
cs_trace_run_fragment(b, tracing_ctx, cs_scratch_reg_tuple(b, 0, 4), |
| 3429 |
false, MALI_TILE_RENDER_ORDER_Z_ORDER); |
| 3430 |
} else { |
| 3431 |
struct cs_index run_fragment_regs = cs_scratch_reg_tuple(b, 0, 4); |
| 3432 |
struct cs_index remaining_layers = cs_scratch_reg32(b, 4); |
| 3433 |
|
| 3434 |
cs_move32_to(b, remaining_layers, calc_enabled_layer_count(cmdbuf)); |
| 3435 |
cs_while(b, MALI_CS_CONDITION_GREATER, remaining_layers) { |
| 3436 |
cs_add32(b, remaining_layers, remaining_layers, -1); |
| 3437 |
|
| 3438 |
cs_trace_run_fragment(b, tracing_ctx, run_fragment_regs, false, |
| 3439 |
MALI_TILE_RENDER_ORDER_Z_ORDER); |
| 3440 |
|
| 3441 |
cs_update_frag_ctx(b) |
| 3442 |
cs_add64(b, cs_sr_reg64(b, FRAGMENT, FBD_POINTER), |
| 3443 |
cs_sr_reg64(b, FRAGMENT, FBD_POINTER), fbd_sz); |
| 3444 |
} |
| 3445 |
} |
| 3446 |
|
| 3447 |
struct cs_index sync_addr = cs_scratch_reg64(b, 0); |
| 3448 |
struct cs_index sb_update_scratch_regs = cs_scratch_reg_tuple(b, 2, 2); |
| 3449 |
struct cs_index add_val = cs_scratch_reg64(b, 4); |
| 3450 |
struct cs_index add_val_lo = cs_scratch_reg32(b, 4); |
| 3451 |
struct cs_index ringbuf_sync_addr = cs_scratch_reg64(b, 6); |
| 3452 |
struct cs_index release_sz = cs_scratch_reg32(b, 8); |
| 3453 |
|
| 3454 |
struct cs_index completed = cs_scratch_reg_tuple(b, 10, 4); |
| 3455 |
struct cs_index completed_top = cs_scratch_reg64(b, 10); |
| 3456 |
struct cs_index completed_bottom = cs_scratch_reg64(b, 12); |
| 3457 |
struct cs_index cur_tiler = cs_reg64(b, 38); |
| 3458 |
struct cs_index tiler_count = cs_reg32(b, 47); |
| 3459 |
struct cs_index oq_chain = cs_scratch_reg64(b, 10); |
| 3460 |
struct cs_index oq_chain_lo = cs_scratch_reg32(b, 10); |
| 3461 |
struct cs_index oq_syncobj = cs_scratch_reg64(b, 12); |
| 3462 |
|
| 3463 |
cs_move64_to(b, add_val, 1); |
| 3464 |
|
| 3465 |
if (free_render_descs) { |
| 3466 |
cs_move32_to(b, release_sz, calc_render_descs_size(cmdbuf)); |
| 3467 |
cs_load64_to(b, ringbuf_sync_addr, cs_subqueue_ctx_reg(b), |
| 3468 |
offsetof(struct panvk_cs_subqueue_context, |
| 3469 |
render.desc_ringbuf.syncobj)); |
| 3470 |
} |
| 3471 |
|
| 3472 |
cs_move32_to(b, tiler_count, td_count); |
| 3473 |
|
| 3474 |
cs_load64_to(b, sync_addr, cs_subqueue_ctx_reg(b), |
| 3475 |
offsetof(struct panvk_cs_subqueue_context, syncobjs)); |
| 3476 |
cs_add64(b, sync_addr, sync_addr, |
| 3477 |
PANVK_SUBQUEUE_FRAGMENT * sizeof(struct panvk_cs_sync64)); |
| 3478 |
|
| 3479 |
cs_iter_sb_update(cmdbuf, PANVK_SUBQUEUE_FRAGMENT, sb_update_scratch_regs, |
| 3480 |
sb_upd_ctx) { |
| 3481 |
/* We wait on the current iter, but we signal the next one, so that |
| 3482 |
* the next FINISH_FRAGMENT can't start until this one is done (required |
| 3483 |
* to guarantee that used heap chunks won't be released prematurely). |
| 3484 |
* No need to wait for sb_upd_ctx.next_sb, this is taken care of in |
| 3485 |
* the cs_iter_sb_update() preamble. |
| 3486 |
*/ |
| 3487 |
#if PAN_ARCH >= 11 |
| 3488 |
const struct cs_async_op async = cs_defer_indirect(); |
| 3489 |
|
| 3490 |
cs_set_state(b, MALI_CS_SET_STATE_TYPE_SB_SEL_DEFERRED, |
| 3491 |
sb_upd_ctx.regs.next_sb); |
| 3492 |
#else |
| 3493 |
struct cs_async_op async = |
| 3494 |
cs_defer(SB_WAIT_ITER(sb_upd_ctx.cur_sb), SB_ITER(sb_upd_ctx.next_sb)); |
| 3495 |
#endif |
| 3496 |
|
| 3497 |
if (td_count == 1) { |
| 3498 |
cs_load_to(b, completed, cur_tiler, BITFIELD_MASK(4), 40); |
| 3499 |
cs_finish_fragment(b, true, completed_top, completed_bottom, async); |
| 3500 |
} else if (td_count > 1) { |
| 3501 |
cs_while(b, MALI_CS_CONDITION_GREATER, tiler_count) { |
| 3502 |
cs_load_to(b, completed, cur_tiler, BITFIELD_MASK(4), 40); |
| 3503 |
cs_finish_fragment(b, false, completed_top, completed_bottom, |
| 3504 |
async); |
| 3505 |
cs_update_frag_ctx(b) |
| 3506 |
cs_add64(b, cur_tiler, cur_tiler, pan_size(TILER_CONTEXT)); |
| 3507 |
cs_add32(b, tiler_count, tiler_count, -1); |
| 3508 |
} |
| 3509 |
cs_frag_end(b, async); |
| 3510 |
} |
| 3511 |
|
| 3512 |
#if PAN_ARCH >= 11 |
| 3513 |
cs_set_state_imm32(b, MALI_CS_SET_STATE_TYPE_SB_SEL_DEFERRED, |
| 3514 |
SB_ID(DEFERRED_SYNC)); |
| 3515 |
#else |
| 3516 |
async = cs_defer(SB_WAIT_ITER(sb_upd_ctx.cur_sb), SB_ID(DEFERRED_SYNC)); |
| 3517 |
#endif |
| 3518 |
|
| 3519 |
if (free_render_descs) { |
| 3520 |
cs_sync32_add(b, true, MALI_CS_SYNC_SCOPE_CSG, release_sz, |
| 3521 |
ringbuf_sync_addr, async); |
| 3522 |
} |
| 3523 |
|
| 3524 |
if (has_oq_chain) { |
| 3525 |
struct cs_index flush_id = oq_chain_lo; |
| 3526 |
cs_move32_to(b, flush_id, 0); |
| 3527 |
|
| 3528 |
#if PAN_ARCH >= 11 |
| 3529 |
/* FLUSH_CACHE2 is part of the deferred group so we need to |
| 3530 |
* temporarily set DEFERRED_FLUSH here to use the right scoreboard in |
| 3531 |
* indirect mode */ |
| 3532 |
cs_set_state_imm32(b, MALI_CS_SET_STATE_TYPE_SB_SEL_DEFERRED, |
| 3533 |
SB_ID(DEFERRED_FLUSH)); |
| 3534 |
#else |
| 3535 |
async = cs_defer(SB_WAIT_ITER(sb_upd_ctx.cur_sb), SB_ID(DEFERRED_FLUSH)); |
| 3536 |
#endif |
| 3537 |
cs_flush_caches(b, MALI_CS_FLUSH_MODE_CLEAN, MALI_CS_FLUSH_MODE_CLEAN, |
| 3538 |
MALI_CS_OTHER_FLUSH_MODE_NONE, flush_id, async); |
| 3539 |
#if PAN_ARCH >= 11 |
| 3540 |
cs_set_state_imm32(b, MALI_CS_SET_STATE_TYPE_SB_SEL_DEFERRED, |
| 3541 |
SB_ID(DEFERRED_SYNC)); |
| 3542 |
#else |
| 3543 |
async = cs_defer(SB_WAIT_ITER(sb_upd_ctx.cur_sb), SB_ID(DEFERRED_SYNC)); |
| 3544 |
#endif |
| 3545 |
|
| 3546 |
cs_load64_to(b, oq_chain, cs_subqueue_ctx_reg(b), |
| 3547 |
offsetof(struct panvk_cs_subqueue_context, render.oq_chain)); |
| 3548 |
|
| 3549 |
/* For WAR dependency on subqueue_context.render.oq_chain. */ |
| 3550 |
cs_flush_loads(b); |
| 3551 |
|
| 3552 |
/* We use oq_syncobj as a placeholder to reset the oq_chain. */ |
| 3553 |
cs_move64_to(b, oq_syncobj, 0); |
| 3554 |
cs_store64(b, oq_syncobj, cs_subqueue_ctx_reg(b), |
| 3555 |
offsetof(struct panvk_cs_subqueue_context, render.oq_chain)); |
| 3556 |
|
| 3557 |
cs_single_link_list_for_each_from(b, oq_chain, |
| 3558 |
struct panvk_cs_occlusion_query, node) { |
| 3559 |
cs_load64_to(b, oq_syncobj, oq_chain, |
| 3560 |
offsetof(struct panvk_cs_occlusion_query, syncobj)); |
| 3561 |
cs_sync32_set(b, true, MALI_CS_SYNC_SCOPE_CSG, add_val_lo, oq_syncobj, |
| 3562 |
cs_defer(SB_MASK(DEFERRED_FLUSH), SB_ID(DEFERRED_SYNC))); |
| 3563 |
} |
| 3564 |
} |
| 3565 |
|
| 3566 |
panvk_instr_sync64_add(cmdbuf, PANVK_SUBQUEUE_FRAGMENT, true, |
| 3567 |
MALI_CS_SYNC_SCOPE_CSG, add_val, sync_addr, async); |
| 3568 |
} |
| 3569 |
|
| 3570 |
/* Update the ring buffer position. */ |
| 3571 |
if (free_render_descs) { |
| 3572 |
cs_render_desc_ringbuf_move_ptr(b, calc_render_descs_size(cmdbuf), |
| 3573 |
!tracing_ctx->enabled); |
| 3574 |
} |
| 3575 |
|
| 3576 |
/* Update the frag seqno. */ |
| 3577 |
++cmdbuf->state.cs[PANVK_SUBQUEUE_FRAGMENT].relative_sync_point; |
| 3578 |
|
| 3579 |
|
| 3580 |
return VK_SUCCESS; |
| 3581 |
} |
| 3582 |
|
| 3583 |
static void |
| 3584 |
handle_deferred_queries(struct panvk_cmd_buffer *cmdbuf) |
| 3585 |
{ |
| 3586 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 3587 |
|
| 3588 |
for (uint32_t sq = 0; sq < PANVK_SUBQUEUE_COUNT; ++sq) { |
| 3589 |
struct cs_builder *b = panvk_get_cs_builder(cmdbuf, sq); |
| 3590 |
struct cs_index current = cs_scratch_reg64(b, 0); |
| 3591 |
struct cs_index reports = cs_scratch_reg64(b, 2); |
| 3592 |
struct cs_index next = cs_scratch_reg64(b, 4); |
| 3593 |
int offset = sizeof(uint64_t) * sq; |
| 3594 |
|
| 3595 |
cs_load64_to( |
| 3596 |
b, current, cs_subqueue_ctx_reg(b), |
| 3597 |
offsetof(struct panvk_cs_subqueue_context, render.ts_chain.head)); |
| 3598 |
|
| 3599 |
cs_while(b, MALI_CS_CONDITION_NEQUAL, current) { |
| 3600 |
|
| 3601 |
cs_load64_to(b, reports, current, |
| 3602 |
offsetof(struct panvk_cs_timestamp_query, reports)); |
| 3603 |
|
| 3604 |
cs_if(b, MALI_CS_CONDITION_NEQUAL, reports) |
| 3605 |
cs_store_state(b, reports, offset, MALI_CS_STATE_TIMESTAMP, |
| 3606 |
cs_defer(dev->csf.sb.all_iters_mask, SB_ID(LS))); |
| 3607 |
|
| 3608 |
cs_load64_to(b, next, current, |
| 3609 |
offsetof(struct panvk_cs_timestamp_query, node.next)); |
| 3610 |
|
| 3611 |
if (sq == PANVK_QUERY_TS_INFO_SUBQUEUE) { |
| 3612 |
/* WAR on panvk_cs_timestamp_query::next. */ |
| 3613 |
cs_flush_loads(b); |
| 3614 |
struct cs_index tmp = cs_scratch_reg64(b, 6); |
| 3615 |
cs_move64_to(b, tmp, 0); |
| 3616 |
cs_store64(b, tmp, current, |
| 3617 |
offsetof(struct panvk_cs_timestamp_query, node.next)); |
| 3618 |
|
| 3619 |
cs_single_link_list_add_tail( |
| 3620 |
b, cs_subqueue_ctx_reg(b), |
| 3621 |
offsetof(struct panvk_cs_subqueue_context, render.ts_done_chain), |
| 3622 |
current, offsetof(struct panvk_cs_timestamp_query, node), |
| 3623 |
cs_scratch_reg_tuple(b, 10, 4)); |
| 3624 |
} |
| 3625 |
|
| 3626 |
cs_add64(b, current, next, 0); |
| 3627 |
} |
| 3628 |
|
| 3629 |
cs_move64_to(b, current, 0); |
| 3630 |
cs_store64( |
| 3631 |
b, current, cs_subqueue_ctx_reg(b), |
| 3632 |
offsetof(struct panvk_cs_subqueue_context, render.ts_chain.head)); |
| 3633 |
cs_flush_stores(b); |
| 3634 |
} |
| 3635 |
} |
| 3636 |
|
| 3637 |
VKAPI_ATTR void VKAPI_CALL |
| 3638 |
panvk_per_arch(CmdEndRendering)(VkCommandBuffer commandBuffer) |
| 3639 |
{ |
| 3640 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 3641 |
bool suspending = cmdbuf->state.gfx.render.flags & VK_RENDERING_SUSPENDING_BIT; |
| 3642 |
VkResult result; |
| 3643 |
|
| 3644 |
if (!suspending) { |
| 3645 |
/* If no draw was performed, we should ensure sample count is valid and that we emit tile size */ |
| 3646 |
panvk_per_arch(cmd_select_tile_size)(cmdbuf); |
| 3647 |
|
| 3648 |
const struct pan_fb_load *fb_load = &cmdbuf->state.gfx.render.fb.load; |
| 3649 |
bool clear = fb_load->z.in_bounds_load == PAN_FB_LOAD_CLEAR || |
| 3650 |
fb_load->s.in_bounds_load == PAN_FB_LOAD_CLEAR; |
| 3651 |
for (unsigned rt = 0; rt < PAN_MAX_RTS; rt++) { |
| 3652 |
if (fb_load->rts[rt].in_bounds_load == PAN_FB_LOAD_CLEAR) |
| 3653 |
clear = true; |
| 3654 |
} |
| 3655 |
|
| 3656 |
if (clear && !inherits_render_ctx(cmdbuf)) { |
| 3657 |
result = get_fb_descs(cmdbuf); |
| 3658 |
if (result != VK_SUCCESS) |
| 3659 |
return; |
| 3660 |
} |
| 3661 |
|
| 3662 |
/* Flush the last occlusion query before ending the render pass if |
| 3663 |
* this query has ended while we were inside the render pass. */ |
| 3664 |
if (cmdbuf->state.gfx.render.oq.last != |
| 3665 |
cmdbuf->state.gfx.occlusion_query.syncobj) { |
| 3666 |
result = wrap_prev_oq(cmdbuf); |
| 3667 |
if (result != VK_SUCCESS) |
| 3668 |
return; |
| 3669 |
} |
| 3670 |
|
| 3671 |
if (cmdbuf->state.gfx.render.fbds.gpu || inherits_render_ctx(cmdbuf)) { |
| 3672 |
flush_tiling(cmdbuf); |
| 3673 |
issue_fragment_jobs(cmdbuf); |
| 3674 |
|
| 3675 |
handle_deferred_queries(cmdbuf); |
| 3676 |
} |
| 3677 |
} else if (!inherits_render_ctx(cmdbuf)) { |
| 3678 |
/* If we're suspending the render pass and we didn't inherit the render |
| 3679 |
* context, we need to emit it now, so it's available when the render pass |
| 3680 |
* is resumed. */ |
| 3681 |
VkResult result = get_render_ctx(cmdbuf); |
| 3682 |
if (result != VK_SUCCESS) |
| 3683 |
return; |
| 3684 |
} |
| 3685 |
|
| 3686 |
memset(&cmdbuf->state.gfx.render.fbds, 0, |
| 3687 |
sizeof(cmdbuf->state.gfx.render.fbds)); |
| 3688 |
memset(&cmdbuf->state.gfx.render.oq, 0, sizeof(cmdbuf->state.gfx.render.oq)); |
| 3689 |
cmdbuf->state.gfx.render.tiler = 0; |
| 3690 |
|
| 3691 |
/* If we're finished with this render pass, make sure we reset the flags |
| 3692 |
* so any barrier encountered after EndRendering() doesn't try to flush |
| 3693 |
* draws. */ |
| 3694 |
cmdbuf->state.gfx.render.flags = 0; |
| 3695 |
cmdbuf->state.gfx.render.suspended = suspending; |
| 3696 |
|
| 3697 |
/* If we're not suspending, we need to resolve attachments. */ |
| 3698 |
if (!suspending) |
| 3699 |
panvk_per_arch(cmd_meta_resolve_attachments)(cmdbuf); |
| 3700 |
|
| 3701 |
struct panvk_instr_end_args instr_info = { |
| 3702 |
.render = { |
| 3703 |
.flags = cmdbuf->state.gfx.render.flags, |
| 3704 |
.fb = &cmdbuf->state.gfx.render.fb.layout, |
| 3705 |
}}; |
| 3706 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 3707 |
panvk_per_arch(panvk_instr_end_work_async)( |
| 3708 |
PANVK_SUBQUEUE_VERTEX_TILER, cmdbuf, PANVK_INSTR_WORK_TYPE_RENDER, |
| 3709 |
&instr_info, cs_defer(dev->csf.sb.all_iters_mask, 0)); |
| 3710 |
panvk_per_arch(panvk_instr_end_work_async)( |
| 3711 |
PANVK_SUBQUEUE_FRAGMENT, cmdbuf, PANVK_INSTR_WORK_TYPE_RENDER, |
| 3712 |
&instr_info, cs_defer(dev->csf.sb.all_iters_mask, 0)); |
| 3713 |
} |