1/* Copyright © 2023 Intel Corporation 2 * SPDX-License-Identifier: MIT 3 */ 4 5#include "libintel_shaders.h" 6 7void genX(write_3DSTATE_VERTEX_BUFFERS)(global void *dst_ptr, 8 uint32_t buffer_count) 9{ 10 struct GENX(3DSTATE_VERTEX_BUFFERS) v = { 11 GENX(3DSTATE_VERTEX_BUFFERS_header), 12 }; 13 v.DWordLength = 1 + (buffer_count * 4) - 14 GENX(3DSTATE_VERTEX_BUFFERS_length_bias); 15 GENX(3DSTATE_VERTEX_BUFFERS_pack)(dst_ptr, &v); 16} 17 18void genX(write_VERTEX_BUFFER_STATE)(global void *dst_ptr, 19 uint32_t mocs, 20 uint32_t buffer_idx, 21 uint64_t address, 22 uint32_t size, 23 uint32_t stride) 24{ 25 bool buffer_null = address == 0; 26 struct GENX(VERTEX_BUFFER_STATE) v = { 27 .BufferPitch = stride, 28 .NullVertexBuffer = address == 0, 29 .AddressModifyEnable = true, 30 .MOCS = mocs, 31#if GFX_VER >= 12 32 .L3BypassDisable = true, 33#endif 34 .VertexBufferIndex = buffer_idx, 35 .BufferStartingAddress = address, 36 .BufferSize = size, 37 }; 38 GENX(VERTEX_BUFFER_STATE_pack)(dst_ptr, &v); 39} 40 41void genX(write_3DPRIMITIVE)(global void *dst_ptr, 42 bool is_predicated, 43 bool is_indexed, 44 bool uses_tbimr, 45 uint32_t vertex_count_per_instance, 46 uint32_t start_vertex_location, 47 uint32_t instance_count, 48 uint32_t start_instance_location, 49 uint32_t base_vertex_location) 50{ 51 struct GENX(3DPRIMITIVE) v = { 52 GENX(3DPRIMITIVE_header), 53#if GFX_VERx10 >= 125 54 .TBIMREnable = uses_tbimr, 55#endif 56 .PredicateEnable = is_predicated, 57 .VertexAccessType = is_indexed ? RANDOM : SEQUENTIAL, 58 .VertexCountPerInstance = vertex_count_per_instance, 59 .StartVertexLocation = start_vertex_location, 60 .InstanceCount = instance_count, 61 .StartInstanceLocation = start_instance_location, 62 .BaseVertexLocation = base_vertex_location, 63 }; 64 GENX(3DPRIMITIVE_pack)(dst_ptr, &v); 65} 66 67#if GFX_VER >= 11 68void genX(write_3DPRIMITIVE_EXTENDED)(global void *dst_ptr, 69 bool is_predicated, 70 bool is_indexed, 71 bool uses_tbimr, 72 uint32_t vertex_count_per_instance, 73 uint32_t start_vertex_location, 74 uint32_t instance_count, 75 uint32_t start_instance_location, 76 uint32_t base_vertex_location, 77 uint32_t param_base_vertex, 78 uint32_t param_base_instance, 79 uint32_t param_draw_id) 80{ 81 struct GENX(3DPRIMITIVE_EXTENDED) v = { 82 GENX(3DPRIMITIVE_EXTENDED_header), 83#if GFX_VERx10 >= 125 84 .TBIMREnable = uses_tbimr, 85#endif 86 .PredicateEnable = is_predicated, 87 .VertexAccessType = is_indexed ? RANDOM : SEQUENTIAL, 88 .VertexCountPerInstance = vertex_count_per_instance, 89 .StartVertexLocation = start_vertex_location, 90 .InstanceCount = instance_count, 91 .StartInstanceLocation = start_instance_location, 92 .BaseVertexLocation = base_vertex_location, 93 .ExtendedParameter0 = param_base_vertex, 94 .ExtendedParameter1 = param_base_instance, 95 .ExtendedParameter2 = param_draw_id, 96 }; 97 GENX(3DPRIMITIVE_EXTENDED_pack)(dst_ptr, &v); 98} 99#endif 100 101void genX(write_MI_BATCH_BUFFER_START)(global void *dst_ptr, uint64_t addr) 102{ 103 struct GENX(MI_BATCH_BUFFER_START) v = { 104 GENX(MI_BATCH_BUFFER_START_header), 105 .AddressSpaceIndicator = ASI_PPGTT, 106 .BatchBufferStartAddress = addr, 107 }; 108 GENX(MI_BATCH_BUFFER_START_pack)(dst_ptr, &v); 109} 110 111void genX(write_draw)(global uint32_t *dst_ptr, 112 global void *indirect_ptr, 113 global uint32_t *draw_id_ptr, 114 uint32_t draw_id, 115 uint32_t instance_multiplier, 116 bool is_indexed, 117 bool is_predicated, 118 bool uses_tbimr, 119 bool uses_base, 120 bool uses_drawid, 121 uint32_t mocs) 122{ 123#if GFX_VER <= 9 124 if (uses_base || uses_drawid) { 125 uint32_t vertex_buffer_count = 126 (uses_base ? 1 : 0) + (uses_drawid ? 1 : 0); 127 genX(write_3DSTATE_VERTEX_BUFFERS)(dst_ptr, vertex_buffer_count); 128 dst_ptr += 1; /* GENX(3DSTATE_VERTEX_BUFFERS_length); */ 129 if (uses_base) { 130 uint64_t base_addr = (uint64_t)indirect_ptr + (is_indexed ? 12 : 8); 131 genX(write_VERTEX_BUFFER_STATE)(dst_ptr, mocs, 31, base_addr, 8, 0); 132 dst_ptr += GENX(VERTEX_BUFFER_STATE_length); 133 } 134 if (uses_drawid) { 135 *draw_id_ptr = draw_id; 136 genX(write_VERTEX_BUFFER_STATE)(dst_ptr, mocs, 32, 137 (uint64_t)draw_id_ptr, 4, 0); 138 dst_ptr += GENX(VERTEX_BUFFER_STATE_length); 139 } 140 } 141 142 if (is_indexed) { 143 VkDrawIndexedIndirectCommand data = 144 *((global VkDrawIndexedIndirectCommand *)indirect_ptr); 145 146 genX(write_3DPRIMITIVE)(dst_ptr, 147 is_predicated, 148 is_indexed, 149 uses_tbimr, 150 data.indexCount, 151 data.firstIndex, 152 data.instanceCount * instance_multiplier, 153 data.firstInstance, 154 data.vertexOffset); 155 } else { 156 VkDrawIndirectCommand data = 157 *((global VkDrawIndirectCommand *)indirect_ptr); 158 159 genX(write_3DPRIMITIVE)(dst_ptr, 160 is_predicated, 161 is_indexed, 162 uses_tbimr, 163 data.vertexCount, 164 data.firstVertex, 165 data.instanceCount * instance_multiplier, 166 data.firstInstance, 167 0 /* base_vertex_location */); 168 } 169#else 170 if (is_indexed) { 171 VkDrawIndexedIndirectCommand data = 172 *((global VkDrawIndexedIndirectCommand *)indirect_ptr); 173 174 genX(write_3DPRIMITIVE_EXTENDED)(dst_ptr, 175 is_predicated, 176 is_indexed, 177 uses_tbimr, 178 data.indexCount, 179 data.firstIndex, 180 data.instanceCount * instance_multiplier, 181 data.firstInstance, 182 data.vertexOffset, 183 data.vertexOffset, 184 data.firstInstance, 185 draw_id); 186 } else { 187 VkDrawIndirectCommand data = 188 *((global VkDrawIndirectCommand *)indirect_ptr); 189 190 genX(write_3DPRIMITIVE_EXTENDED)(dst_ptr, 191 is_predicated, 192 is_indexed, 193 uses_tbimr, 194 data.vertexCount, 195 data.firstVertex, 196 data.instanceCount * instance_multiplier, 197 data.firstInstance, 198 0 /* base_vertex_location */, 199 data.firstVertex, 200 data.firstInstance, 201 draw_id); 202 } 203#endif 204} 205