2 * Copyright © 2022 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #ifndef GENX_CMD_DRAW_HELPERS_H
25 #define GENX_CMD_DRAW_HELPERS_H
30 #include "anv_private.h"
34 emit_vertex_bo(struct anv_cmd_buffer *cmd_buffer,
35 struct anv_address addr,
36 uint32_t size, uint32_t index)
38 uint32_t *p = anv_batch_emitn(&cmd_buffer->batch, 5,
39 GENX(3DSTATE_VERTEX_BUFFERS));
41 GENX(VERTEX_BUFFER_STATE_pack)(&cmd_buffer->batch, p + 1,
42 &(struct GENX(VERTEX_BUFFER_STATE)) {
43 .VertexBufferIndex = index,
44 .AddressModifyEnable = true,
46 .MOCS = anv_mocs(cmd_buffer->device, addr.bo,
47 ISL_SURF_USAGE_VERTEX_BUFFER_BIT),
48 .NullVertexBuffer = size == 0,
50 .L3BypassDisable = true,
52 .BufferStartingAddress = addr,
57 genX(cmd_buffer_set_binding_for_gfx8_vb_flush)(cmd_buffer,
63 emit_base_vertex_instance_bo(struct anv_cmd_buffer *cmd_buffer,
64 struct anv_address addr)
66 emit_vertex_bo(cmd_buffer, addr, addr.bo ? 8 : 0, ANV_SVGS_VB_INDEX);
70 emit_base_vertex_instance(struct anv_cmd_buffer *cmd_buffer,
71 uint32_t base_vertex, uint32_t base_instance)
73 if (base_vertex == 0 && base_instance == 0) {
74 emit_base_vertex_instance_bo(cmd_buffer, ANV_NULL_ADDRESS);
78 struct anv_state id_state =
79 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, 8, 4);
81 ((uint32_t *)id_state.map)[0] = base_vertex;
82 ((uint32_t *)id_state.map)[1] = base_instance;
84 struct anv_address addr =
85 anv_state_pool_state_address(&cmd_buffer->device->dynamic_state_pool,
88 emit_base_vertex_instance_bo(cmd_buffer, addr);
92 emit_draw_index(struct anv_cmd_buffer *cmd_buffer, uint32_t draw_index)
94 struct anv_state state =
95 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, 4, 4);
97 ((uint32_t *)state.map)[0] = draw_index;
99 struct anv_address addr =
100 anv_state_pool_state_address(&cmd_buffer->device->dynamic_state_pool,
103 emit_vertex_bo(cmd_buffer, addr, 4, ANV_DRAWID_VB_INDEX);
105 #endif /* GFX_VER <= 11 */
108 update_dirty_vbs_for_gfx8_vb_flush(struct anv_cmd_buffer *cmd_buffer,
109 uint32_t access_type)
112 struct anv_graphics_pipeline *pipeline = cmd_buffer->state.gfx.pipeline;
113 const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);
115 uint64_t vb_used = pipeline->vb_used;
116 if (vs_prog_data->uses_firstvertex ||
117 vs_prog_data->uses_baseinstance)
118 vb_used |= 1ull << ANV_SVGS_VB_INDEX;
119 if (vs_prog_data->uses_drawid)
120 vb_used |= 1ull << ANV_DRAWID_VB_INDEX;
122 genX(cmd_buffer_update_dirty_vbs_for_gfx8_vb_flush)(cmd_buffer,
123 access_type == RANDOM,
129 ALWAYS_INLINE static void
130 cmd_buffer_emit_vertex_constants_and_flush(struct anv_cmd_buffer *cmd_buffer,
131 const struct brw_vs_prog_data *vs_prog_data,
132 uint32_t base_vertex,
133 uint32_t base_instance,
137 bool emitted = false;
138 if (vs_prog_data->uses_firstvertex ||
139 vs_prog_data->uses_baseinstance) {
140 emit_base_vertex_instance(cmd_buffer, base_vertex, base_instance);
143 if (vs_prog_data->uses_drawid) {
144 emit_draw_index(cmd_buffer, draw_id);
147 /* Emitting draw index or vertex index BOs may result in needing
148 * additional VF cache flushes.
150 if (emitted || force_flush)
151 genX(cmd_buffer_apply_pipe_flushes)(cmd_buffer);
155 #endif /* GENX_CMD_DRAW_HELPERS_H */