| 1 |
|
| 2 |
. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef KK_CMD_BUFFER_H |
| 9 |
#define KK_CMD_BUFFER_H 1 |
| 10 |
|
| 11 |
#include "kk_private.h" |
| 12 |
|
| 13 |
#include "kk_descriptor_set.h" |
| 14 |
#include "kk_image.h" |
| 15 |
#include "kk_nir_lower_vbo.h" |
| 16 |
#include "kk_shader.h" |
| 17 |
|
| 18 |
#include "kosmickrisp/bridge/mtl_types.h" |
| 19 |
|
| 20 |
#include "kosmickrisp/libkk/kk_query.h" |
| 21 |
|
| 22 |
#include "util/u_dynarray.h" |
| 23 |
|
| 24 |
#include "vk_command_buffer.h" |
| 25 |
|
| 26 |
#include <stdio.h> |
| 27 |
|
| 28 |
struct kk_query_pool; |
| 29 |
|
| 30 |
struct kk_root_descriptor_table { |
| 31 |
struct kk_bo *root_buffer; |
| 32 |
|
| 33 |
union { |
| 34 |
struct { |
| 35 |
|
| 36 |
uint32_t buffer_strides[KK_MAX_VBUFS]; |
| 37 |
uint64_t attrib_base[KK_MAX_ATTRIBS]; |
| 38 |
uint32_t attrib_clamps[KK_MAX_ATTRIBS]; |
| 39 |
float blend_constant[4]; |
| 40 |
uint32_t draw_id; |
| 41 |
} draw; |
| 42 |
struct { |
| 43 |
uint32_t base_group[3]; |
| 44 |
} cs; |
| 45 |
}; |
| 46 |
|
| 47 |
|
| 48 |
uint8_t push[KK_MAX_PUSH_SIZE]; |
| 49 |
|
| 50 |
|
| 51 |
uint64_t sets[KK_MAX_SETS]; |
| 52 |
|
| 53 |
|
| 54 |
struct kk_buffer_address dynamic_buffers[KK_MAX_DYNAMIC_BUFFERS]; |
| 55 |
|
| 56 |
|
| 57 |
uint8_t set_dynamic_buffer_start[KK_MAX_SETS]; |
| 58 |
}; |
| 59 |
|
| 60 |
struct kk_descriptor_state { |
| 61 |
bool root_dirty; |
| 62 |
struct kk_root_descriptor_table root; |
| 63 |
|
| 64 |
uint32_t set_sizes[KK_MAX_SETS]; |
| 65 |
struct kk_descriptor_set *sets[KK_MAX_SETS]; |
| 66 |
|
| 67 |
uint32_t push_dirty; |
| 68 |
struct kk_push_descriptor_set *push[KK_MAX_SETS]; |
| 69 |
}; |
| 70 |
|
| 71 |
struct kk_attachment { |
| 72 |
VkFormat vk_format; |
| 73 |
struct kk_image_view *iview; |
| 74 |
|
| 75 |
VkResolveModeFlagBits resolve_mode; |
| 76 |
struct kk_image_view *resolve_iview; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
VkAttachmentStoreOp store_op; |
| 81 |
}; |
| 82 |
|
| 83 |
struct kk_rendering_state { |
| 84 |
VkRenderingFlagBits flags; |
| 85 |
|
| 86 |
VkRect2D area; |
| 87 |
uint32_t layer_count; |
| 88 |
uint32_t view_mask; |
| 89 |
uint32_t samples; |
| 90 |
|
| 91 |
uint32_t color_att_count; |
| 92 |
struct kk_attachment color_att[KK_MAX_RTS]; |
| 93 |
struct kk_attachment depth_att; |
| 94 |
struct kk_attachment stencil_att; |
| 95 |
struct kk_attachment fsr_att; |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
enum kk_dirty { |
| 102 |
KK_DIRTY_VB = BITFIELD_BIT(0), |
| 103 |
KK_DIRTY_OCCLUSION = BITFIELD_BIT(1), |
| 104 |
}; |
| 105 |
|
| 106 |
struct kk_graphics_state { |
| 107 |
struct kk_rendering_state render; |
| 108 |
struct kk_descriptor_state descriptors; |
| 109 |
|
| 110 |
mtl_depth_stencil_state *depth_stencil_state; |
| 111 |
mtl_render_pass_descriptor *render_pass_descriptor; |
| 112 |
bool is_depth_stencil_dynamic; |
| 113 |
bool is_cull_front_and_back; |
| 114 |
bool need_to_start_render_pass; |
| 115 |
|
| 116 |
enum kk_dirty dirty; |
| 117 |
uint32_t sample_count; |
| 118 |
|
| 119 |
struct { |
| 120 |
enum mtl_visibility_result_mode mode; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
uint16_t index; |
| 126 |
} occlusion; |
| 127 |
|
| 128 |
|
| 129 |
struct { |
| 130 |
mtl_buffer *handle; |
| 131 |
uint32_t size; |
| 132 |
uint32_t offset; |
| 133 |
uint32_t restart; |
| 134 |
uint8_t bytes_per_index; |
| 135 |
} index; |
| 136 |
|
| 137 |
|
| 138 |
struct { |
| 139 |
struct kk_addr_range addr_range[KK_MAX_VBUFS]; |
| 140 |
mtl_buffer *handles[KK_MAX_VBUFS]; |
| 141 |
|
| 142 |
|
| 143 |
uint32_t max_vertices; |
| 144 |
} vb; |
| 145 |
|
| 146 |
|
| 147 |
struct vk_vertex_input_state _dynamic_vi; |
| 148 |
struct vk_sample_locations_state _dynamic_sl; |
| 149 |
}; |
| 150 |
|
| 151 |
struct kk_compute_state { |
| 152 |
struct kk_descriptor_state descriptors; |
| 153 |
}; |
| 154 |
|
| 155 |
struct kk_encoder; |
| 156 |
|
| 157 |
struct kk_cmd_buffer { |
| 158 |
struct vk_command_buffer vk; |
| 159 |
|
| 160 |
struct kk_encoder *encoder; |
| 161 |
void *drawable; |
| 162 |
|
| 163 |
struct { |
| 164 |
struct kk_graphics_state gfx; |
| 165 |
struct kk_compute_state cs; |
| 166 |
struct kk_shader *shaders[MESA_SHADER_STAGES]; |
| 167 |
|
| 168 |
uint32_t dirty_shaders; |
| 169 |
} state; |
| 170 |
|
| 171 |
|
| 172 |
struct util_dynarray large_bos; |
| 173 |
}; |
| 174 |
|
| 175 |
VK_DEFINE_HANDLE_CASTS(kk_cmd_buffer, vk.base, VkCommandBuffer, |
| 176 |
VK_OBJECT_TYPE_COMMAND_BUFFER) |
| 177 |
|
| 178 |
extern const struct vk_command_buffer_ops kk_cmd_buffer_ops; |
| 179 |
|
| 180 |
static inline struct kk_device * |
| 181 |
kk_cmd_buffer_device(struct kk_cmd_buffer *cmd) |
| 182 |
{ |
| 183 |
return (struct kk_device *)cmd->vk.base.device; |
| 184 |
} |
| 185 |
|
| 186 |
static inline struct kk_cmd_pool * |
| 187 |
kk_cmd_buffer_pool(struct kk_cmd_buffer *cmd) |
| 188 |
{ |
| 189 |
return (struct kk_cmd_pool *)cmd->vk.pool; |
| 190 |
} |
| 191 |
|
| 192 |
static inline struct kk_descriptor_state * |
| 193 |
kk_get_descriptors_state(struct kk_cmd_buffer *cmd, |
| 194 |
VkPipelineBindPoint bind_point) |
| 195 |
{ |
| 196 |
switch (bind_point) { |
| 197 |
case VK_PIPELINE_BIND_POINT_GRAPHICS: |
| 198 |
return &cmd->state.gfx.descriptors; |
| 199 |
case VK_PIPELINE_BIND_POINT_COMPUTE: |
| 200 |
return &cmd->state.cs.descriptors; |
| 201 |
default: |
| 202 |
UNREACHABLE("Unhandled bind point"); |
| 203 |
} |
| 204 |
}; |
| 205 |
|
| 206 |
void kk_cmd_release_resources(struct kk_device *dev, struct kk_cmd_buffer *cmd); |
| 207 |
|
| 208 |
static void |
| 209 |
kk_cmd_buffer_dirty_all_gfx(struct kk_cmd_buffer *cmd) |
| 210 |
{ |
| 211 |
|
| 212 |
vk_dynamic_graphics_state_dirty_all(&cmd->vk.dynamic_graphics_state); |
| 213 |
cmd->state.dirty_shaders = ~0u; |
| 214 |
cmd->state.gfx.dirty = ~0u; |
| 215 |
cmd->state.gfx.descriptors.root_dirty = true; |
| 216 |
} |
| 217 |
|
| 218 |
void kk_cmd_release_dynamic_ds_state(struct kk_cmd_buffer *cmd); |
| 219 |
|
| 220 |
mtl_depth_stencil_state * |
| 221 |
kk_compile_depth_stencil_state(struct kk_device *device, |
| 222 |
const struct vk_depth_stencil_state *ds, |
| 223 |
bool has_depth, bool has_stencil); |
| 224 |
|
| 225 |
void kk_meta_resolve_rendering(struct kk_cmd_buffer *cmd, |
| 226 |
const VkRenderingInfo *pRenderingInfo); |
| 227 |
|
| 228 |
void kk_cmd_buffer_write_descriptor_buffer(struct kk_cmd_buffer *cmd, |
| 229 |
struct kk_descriptor_state *desc, |
| 230 |
size_t size, size_t offset); |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
struct kk_bo *kk_cmd_allocate_buffer(struct kk_cmd_buffer *cmd, size_t size_B, |
| 235 |
size_t alignment_B); |
| 236 |
|
| 237 |
struct kk_pool { |
| 238 |
mtl_buffer *handle; |
| 239 |
uint64_t gpu; |
| 240 |
void *cpu; |
| 241 |
}; |
| 242 |
struct kk_pool kk_pool_upload(struct kk_cmd_buffer *cmd, void *data, |
| 243 |
size_t size_B, size_t alignment_B); |
| 244 |
|
| 245 |
uint64_t kk_upload_descriptor_root(struct kk_cmd_buffer *cmd, |
| 246 |
VkPipelineBindPoint bind_point); |
| 247 |
|
| 248 |
void kk_cmd_buffer_flush_push_descriptors(struct kk_cmd_buffer *cmd, |
| 249 |
struct kk_descriptor_state *desc); |
| 250 |
|
| 251 |
void kk_dispatch_precomp(struct kk_cmd_buffer *cmd, struct mtl_size grid, |
| 252 |
bool pre_gfx, enum libkk_program idx, void *data, |
| 253 |
size_t data_size); |
| 254 |
|
| 255 |
#define MESA_DISPATCH_PRECOMP kk_dispatch_precomp |
| 256 |
|
| 257 |
void kk_cmd_write(struct kk_cmd_buffer *cmd, struct libkk_imm_write write); |
| 258 |
|
| 259 |
#endif |