Debian Codegraph @

src/kosmickrisp/vulkan/kk_encoder.h

raw symbols SCIP
1 /*
2 * Copyright 2025 LunarG, Inc.
3 * Copyright 2025 Google LLC
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef KK_ENCODER_H
8 #define KK_ENCODER_H 1
9
10 #include "kosmickrisp/bridge/mtl_types.h"
11
12 #include "util/u_dynarray.h"
13
14 #include "vulkan/vulkan.h"
15
16 struct kk_queue;
17 struct kk_cmd_buffer;
18
19 enum kk_encoder_type {
20 KK_ENC_NONE = 0,
21 KK_ENC_RENDER = BITFIELD_BIT(0),
22 KK_ENC_COMPUTE = BITFIELD_BIT(1),
23 KK_ENC_BLIT = BITFIELD_BIT(2),
24 KK_ENC_ALL = (KK_ENC_RENDER | KK_ENC_COMPUTE | KK_ENC_BLIT),
25 KK_ENC_COUNT = 3u,
26 };
27
28 struct kk_encoder_internal {
29 mtl_command_buffer *cmd_buffer;
30 mtl_command_encoder *encoder;
31
32 /* Used to know if we need to make heaps resident again */
33 uint32_t user_heap_hash;
34
35 /* Need to track last used to we can converge at submission */
36 enum kk_encoder_type last_used;
37
38 /* Used to synchronize between passes inside the same command buffer */
39 struct util_dynarray fences;
40 /* Tracks if we need to wait on the last fence present in fences at the start
41 * of the pass */
42 bool wait_fence;
43 };
44
45 struct kk_copy_query_pool_results_info {
46 uint64_t availability;
47 uint64_t results;
48 uint64_t indices;
49 uint64_t dst_addr;
50 uint64_t dst_stride;
51 uint32_t first_query;
52 VkQueryResultFlagBits flags;
53 uint16_t reports_per_query;
54 uint32_t query_count;
55 };
56
57 struct kk_encoder {
58 mtl_device *dev;
59 struct kk_encoder_internal main;
60 /* Compute only for pre gfx required work */
61 struct kk_encoder_internal pre_gfx;
62
63 /* Used to synchronize between main and pre_gfx encoders */
64 mtl_event *event;
65 uint64_t event_value;
66 /* Track what values pre_gfx must wait/signal before starting the encoding */
67 uint64_t wait_value_pre_gfx;
68 uint64_t signal_value_pre_gfx;
69 uint64_t last_signaled_value_pre_gfx;
70
71 /* uint64_t pairs with first being the address, second being the value to
72 * write */
73 struct util_dynarray imm_writes;
74 /* Array of kk_copy_quer_pool_results_info structs */
75 struct util_dynarray copy_query_pool_result_infos;
76 };
77
78 /* Allocates encoder and initialises/creates all resources required to start
79 * recording commands into the multiple encoders */
80 VkResult kk_encoder_init(mtl_device *device, struct kk_queue *queue,
81 struct kk_encoder **encoder);
82
83 /* Submits all command buffers and releases encoder memory. Requires all command
84 * buffers in the encoder to be linked to the last one used so the post
85 * execution callback is called once all are done */
86 void kk_encoder_submit(struct kk_encoder *encoder);
87
88 mtl_render_encoder *
89 kk_encoder_start_render(struct kk_cmd_buffer *cmd,
90 mtl_render_pass_descriptor *descriptor,
91 uint32_t view_mask);
92
93 /* Ends encoding on all command buffers */
94 void kk_encoder_end(struct kk_cmd_buffer *cmd);
95
96 /* Creates a fence and signals it inside the encoder, then ends encoding */
97 void kk_encoder_signal_fence_and_end(struct kk_cmd_buffer *cmd);
98
99 mtl_render_encoder *kk_render_encoder(struct kk_cmd_buffer *cmd);
100
101 mtl_compute_encoder *kk_compute_encoder(struct kk_cmd_buffer *cmd);
102
103 mtl_blit_encoder *kk_blit_encoder(struct kk_cmd_buffer *cmd);
104
105 mtl_compute_encoder *kk_encoder_pre_gfx_encoder(struct kk_cmd_buffer *cmd);
106
107 void upload_queue_writes(struct kk_cmd_buffer *cmd);
108
109 #endif /* KK_ENCODER_H */