1 /*
2 * Copyright © 2021 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef PANVK_CMD_BUFFER_H
7 #define PANVK_CMD_BUFFER_H
8
9 #ifndef PAN_ARCH
10 #error "PAN_ARCH must be defined"
11 #endif
12
13 #include <stdint.h>
14
15 #include "vulkan/runtime/vk_command_buffer.h"
16
17 #include "panvk_cmd_desc_state.h"
18 #include "panvk_cmd_dispatch.h"
19 #include "panvk_cmd_draw.h"
20 #include "panvk_cmd_push_constant.h"
21 #include "panvk_descriptor_set.h"
22 #include "panvk_descriptor_set_layout.h"
23 #include "panvk_device.h"
24 #include "panvk_macros.h"
25 #include "panvk_mempool.h"
26 #include "panvk_shader.h"
27
28 #include "pan_jc.h"
29
30 #include "util/list.h"
31
32 #include "genxml/gen_macros.h"
33
34 struct panvk_batch {
35 struct list_head node;
36 struct util_dynarray jobs;
37 struct util_dynarray event_ops;
38 struct pan_jc vtc_jc;
39 struct pan_jc frag_jc;
40 struct {
41 struct panfrost_ptr desc;
42 uint32_t desc_stride;
43 uint32_t bo_count;
44
45 /* One slot per color, two more slots for the depth/stencil buffers. */
46 struct pan_kmod_bo *bos[MAX_RTS + 2];
47 uint32_t layer_count;
48 } fb;
49 struct {
50 struct pan_kmod_bo *src, *dst;
51 } blit;
52 struct panfrost_ptr tls;
53 struct {
54 struct pan_tiler_context ctx;
55 struct panfrost_ptr heap_desc;
56 struct panfrost_ptr ctx_descs;
57 struct mali_tiler_heap_packed heap_templ;
58 struct mali_tiler_context_packed ctx_templ;
59 } tiler;
60 struct pan_tls_info tlsinfo;
61 unsigned wls_total_size;
62 bool issued;
63 };
64
65 enum panvk_cmd_event_op_type {
66 PANVK_EVENT_OP_SET,
67 PANVK_EVENT_OP_RESET,
68 PANVK_EVENT_OP_WAIT,
69 };
70
71 struct panvk_cmd_event_op {
72 enum panvk_cmd_event_op_type type;
73 struct panvk_event *event;
74 };
75
76 struct panvk_cmd_buffer {
77 struct vk_command_buffer vk;
78
79 struct panvk_pool desc_pool;
80 struct panvk_pool varying_pool;
81 struct panvk_pool tls_pool;
82 struct list_head batches;
83 struct list_head push_sets;
84 struct panvk_batch *cur_batch;
85
86 struct {
87 struct panvk_cmd_graphics_state gfx;
88 struct panvk_cmd_compute_state compute;
89 struct panvk_push_constant_state push_constants;
90 } state;
91 };
92
93 VK_DEFINE_HANDLE_CASTS(panvk_cmd_buffer, vk.base, VkCommandBuffer,
94 VK_OBJECT_TYPE_COMMAND_BUFFER)
95
96 #define panvk_cmd_buffer_obj_list_init(cmdbuf, list_name) \
97 list_inithead(&(cmdbuf)->list_name)
98
99 #define panvk_cmd_buffer_obj_list_cleanup(cmdbuf, list_name) \
100 do { \
101 struct panvk_cmd_pool *__pool = \
102 container_of(cmdbuf->vk.pool, struct panvk_cmd_pool, vk); \
103 list_splicetail(&(cmdbuf)->list_name, &__pool->list_name); \
104 } while (0)
105
106 #define panvk_cmd_buffer_obj_list_reset(cmdbuf, list_name) \
107 do { \
108 struct panvk_cmd_pool *__pool = \
109 container_of(cmdbuf->vk.pool, struct panvk_cmd_pool, vk); \
110 list_splicetail(&(cmdbuf)->list_name, &__pool->list_name); \
111 list_inithead(&(cmdbuf)->list_name); \
112 } while (0)
113
114 static inline struct panvk_descriptor_state *
panvk_cmd_get_desc_state(struct panvk_cmd_buffer * cmdbuf,VkPipelineBindPoint bindpoint)115 panvk_cmd_get_desc_state(struct panvk_cmd_buffer *cmdbuf,
116 VkPipelineBindPoint bindpoint)
117 {
118 switch (bindpoint) {
119 case VK_PIPELINE_BIND_POINT_GRAPHICS:
120 return &cmdbuf->state.gfx.desc_state;
121
122 case VK_PIPELINE_BIND_POINT_COMPUTE:
123 return &cmdbuf->state.compute.desc_state;
124
125 default:
126 assert(!"Unsupported bind point");
127 return NULL;
128 }
129 }
130
131 extern const struct vk_command_buffer_ops panvk_per_arch(cmd_buffer_ops);
132
133 struct panvk_batch *
134 panvk_per_arch(cmd_open_batch)(struct panvk_cmd_buffer *cmdbuf);
135
136 void panvk_per_arch(cmd_close_batch)(struct panvk_cmd_buffer *cmdbuf);
137
138 VkResult panvk_per_arch(cmd_alloc_fb_desc)(struct panvk_cmd_buffer *cmdbuf);
139
140 VkResult panvk_per_arch(cmd_alloc_tls_desc)(struct panvk_cmd_buffer *cmdbuf,
141 bool gfx);
142
143 VkResult
144 panvk_per_arch(cmd_prepare_tiler_context)(struct panvk_cmd_buffer *cmdbuf,
145 uint32_t layer_idx);
146
147 void panvk_per_arch(cmd_preload_fb_after_batch_split)(
148 struct panvk_cmd_buffer *cmdbuf);
149
150 void panvk_per_arch(cmd_bind_shaders)(struct vk_command_buffer *vk_cmd,
151 uint32_t stage_count,
152 const gl_shader_stage *stages,
153 struct vk_shader **const shaders);
154
155 #endif
156