blob: 9d83eb78492db58cf46d6fa120be48eb883487cd [file] [log] [blame]
Chia-I Wu09142132014-08-11 15:42:55 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wu09142132014-08-11 15:42:55 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wu09142132014-08-11 15:42:55 +080027 */
28
29#ifndef CMD_H
30#define CMD_H
31
32#include "intel.h"
33#include "obj.h"
Chia-I Wub2755562014-08-20 13:38:52 +080034#include "view.h"
35
36struct intel_pipeline;
Chia-I Wuf2b6d722014-09-02 08:52:27 +080037struct intel_pipeline_shader;
Chia-I Wub2755562014-08-20 13:38:52 +080038struct intel_viewport_state;
39struct intel_raster_state;
40struct intel_msaa_state;
41struct intel_blend_state;
42struct intel_ds_state;
Chia-I Wuf8385062015-01-04 16:27:24 +080043struct intel_desc_set;
Chia-I Wuc6025ac2015-02-18 14:59:11 -070044struct intel_render_pass;
Chia-I Wub2755562014-08-20 13:38:52 +080045
Chia-I Wu00b51a82014-09-09 12:07:37 +080046struct intel_cmd_item;
Chia-I Wu958d1b72014-08-21 11:28:11 +080047struct intel_cmd_reloc;
Chia-I Wu6032b892014-10-17 14:47:18 +080048struct intel_cmd_meta;
Chia-I Wu958d1b72014-08-21 11:28:11 +080049
Chia-I Wu8370b402014-08-29 12:28:37 +080050/*
51 * We know what workarounds are needed for intel_pipeline. These are mostly
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -060052 * for pipeline derivatives.
Chia-I Wu8370b402014-08-29 12:28:37 +080053 */
54enum intel_cmd_wa_flags {
55 /*
56 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
57 *
58 * "Before any depth stall flush (including those produced by
59 * non-pipelined state commands), software needs to first send a
60 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
61 */
62 INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE = 1 << 0,
63
64 /*
65 * From the Sandy Bridge PRM, volume 2 part 1, page 274:
66 *
67 * "A PIPE_CONTROL command, with only the Stall At Pixel Scoreboard
68 * field set (DW1 Bit 1), must be issued prior to any change to the
69 * value in this field (Maximum Number of Threads in 3DSTATE_WM)"
70 *
71 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
72 *
73 * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
74 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
75 * Pixel Scoreboard set is required to be issued."
76 */
77 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL = 1 << 1,
78
79 /*
80 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
81 *
82 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
83 * stall needs to be sent just prior to any 3DSTATE_VS,
84 * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS,
85 * 3DSTATE_BINDING_TABLE_POINTER_VS, 3DSTATE_SAMPLER_STATE_POINTER_VS
86 * command. Only one PIPE_CONTROL needs to be sent before any
87 * combination of VS associated 3DSTATE."
88 */
89 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE = 1 << 2,
90
91 /*
92 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
93 *
94 * "Due to an HW issue driver needs to send a pipe control with stall
95 * when ever there is state change in depth bias related state"
Chia-I Wu8370b402014-08-29 12:28:37 +080096 */
97 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL = 1 << 3,
98
99 /*
100 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
101 *
102 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
103 * Enable bit set after all the following states are programmed:
104 *
105 * - 3DSTATE_PS
106 * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
107 * - 3DSTATE_CONSTANT_PS
108 * - 3DSTATE_BINDING_TABLE_POINTERS_PS
109 * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
110 * - 3DSTATE_CC_STATE_POINTERS
111 * - 3DSTATE_BLEND_STATE_POINTERS
112 * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
113 */
114 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL = 1 << 4,
115};
116
Chia-I Wu68f319d2014-09-09 09:43:21 +0800117enum intel_cmd_writer_type {
118 INTEL_CMD_WRITER_BATCH,
Chia-I Wu15cccf72015-02-10 04:07:40 +0800119 INTEL_CMD_WRITER_SURFACE,
Chia-I Wu68f319d2014-09-09 09:43:21 +0800120 INTEL_CMD_WRITER_STATE,
121 INTEL_CMD_WRITER_INSTRUCTION,
122
123 INTEL_CMD_WRITER_COUNT,
124};
125
Chia-I Wua57761b2014-10-14 14:27:44 +0800126struct intel_cmd_shader_cache {
127 struct {
128 const void *shader;
129 uint32_t kernel_offset;
130 } *entries;
131
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600132 uint32_t count;
133 uint32_t used;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600134};
135
Chia-I Wu862c5572015-03-28 15:23:55 +0800136struct intel_cmd_dset_data {
137 struct intel_desc_offset *set_offsets;
138 uint32_t set_offset_count;
139
140 uint32_t *dynamic_offsets;
141 uint32_t dynamic_offset_count;
142};
143
Chia-I Wub2755562014-08-20 13:38:52 +0800144/*
145 * States bounded to the command buffer. We want to write states directly to
146 * the command buffer when possible, and reduce this struct.
147 */
148struct intel_cmd_bind {
Chia-I Wu6032b892014-10-17 14:47:18 +0800149 const struct intel_cmd_meta *meta;
150
Chia-I Wua57761b2014-10-14 14:27:44 +0800151 struct intel_cmd_shader_cache shader_cache;
152
Chia-I Wub2755562014-08-20 13:38:52 +0800153 struct {
154 const struct intel_pipeline *graphics;
155 const struct intel_pipeline *compute;
Chia-I Wua57761b2014-10-14 14:27:44 +0800156
157 uint32_t vs_offset;
158 uint32_t tcs_offset;
159 uint32_t tes_offset;
160 uint32_t gs_offset;
161 uint32_t fs_offset;
162 uint32_t cs_offset;
Chia-I Wub2755562014-08-20 13:38:52 +0800163 } pipeline;
164
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600165 struct {
Tony Barbourde4124d2015-07-03 10:33:54 -0600166 const struct intel_dynamic_viewport *viewport;
Cody Northropf5bd2252015-08-17 11:10:49 -0600167 const struct intel_dynamic_raster_line *raster_line;
168 const struct intel_dynamic_raster_depth_bias *raster_depth_bias;
Tony Barbourde4124d2015-07-03 10:33:54 -0600169 const struct intel_dynamic_color_blend *blend;
Cody Northrop2605cb02015-08-18 15:21:16 -0600170 const struct intel_dynamic_depth *depth;
171 const struct intel_dynamic_stencil *stencil;
Chia-I Wub2755562014-08-20 13:38:52 +0800172 } state;
173
174 struct {
Chia-I Wu862c5572015-03-28 15:23:55 +0800175 struct intel_cmd_dset_data graphics_data;
Chia-I Wu862c5572015-03-28 15:23:55 +0800176 struct intel_cmd_dset_data compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +0800177 } dset;
178
179 struct {
Chia-I Wu714df452015-01-01 07:55:04 +0800180 const struct intel_buf *buf[INTEL_MAX_VERTEX_BINDING_COUNT];
Tony Barbour8205d902015-04-16 15:59:00 -0600181 VkDeviceSize offset[INTEL_MAX_VERTEX_BINDING_COUNT];
Chia-I Wu3b04af52014-11-08 10:48:20 +0800182 } vertex;
183
184 struct {
Chia-I Wu714df452015-01-01 07:55:04 +0800185 const struct intel_buf *buf;
Tony Barbour8205d902015-04-16 15:59:00 -0600186 VkDeviceSize offset;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187 VkIndexType type;
Chia-I Wub2755562014-08-20 13:38:52 +0800188 } index;
189
Tony Barbourfa6cac72015-01-16 14:27:35 -0700190
Chia-I Wubbc7d912015-02-27 14:59:50 -0700191 bool render_pass_changed;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600192 const struct intel_render_pass *render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800193 const struct intel_render_pass_subpass *render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600194 const struct intel_fb *fb;
Chia-I Wu513ae5b2015-07-01 19:04:59 +0800195 VkRenderPassContents render_pass_contents;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800196
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600197 uint32_t draw_count;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800198 uint32_t wa_flags;
Chia-I Wub2755562014-08-20 13:38:52 +0800199};
Chia-I Wu09142132014-08-11 15:42:55 +0800200
Chia-I Wue24c3292014-08-21 14:05:23 +0800201struct intel_cmd_writer {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600202 size_t size;
Chia-I Wue24c3292014-08-21 14:05:23 +0800203 struct intel_bo *bo;
Chia-I Wu0f50ba82014-09-09 10:25:46 +0800204 void *ptr;
Chia-I Wue24c3292014-08-21 14:05:23 +0800205
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600206 size_t used;
Chia-I Wu00b51a82014-09-09 12:07:37 +0800207
Chia-I Wuf98dd882015-02-10 04:17:47 +0800208 uint32_t sba_offset;
209
Chia-I Wu00b51a82014-09-09 12:07:37 +0800210 /* for decoding */
211 struct intel_cmd_item *items;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600212 uint32_t item_alloc;
213 uint32_t item_used;
Chia-I Wue24c3292014-08-21 14:05:23 +0800214};
215
Cody Northropf02f9f82015-07-09 18:08:05 -0600216struct intel_cmd_pool {
217 struct intel_obj obj;
218 struct intel_dev *dev;
219
220 uint32_t queue_family_index;
221 uint32_t create_flags;
222};
223
224static inline struct intel_cmd_pool *intel_cmd_pool(VkCmdPool pool)
225{
226 return *(struct intel_cmd_pool **) &pool;
227}
228
229static inline struct intel_cmd_pool *intel_cmd_pool_from_base(struct intel_base *base)
230{
231 return (struct intel_cmd_pool *) base;
232}
233
234static inline struct intel_cmd_pool *intel_cmd_pool_from_obj(struct intel_obj *obj)
235{
236 return (struct intel_cmd_pool *) &obj->base;
237}
238
239VkResult intel_cmd_pool_create(struct intel_dev *dev,
240 const VkCmdPoolCreateInfo *info,
241 struct intel_cmd_pool **cmd_pool_ret);
242void intel_cmd_pool_destroy(struct intel_cmd_pool *pool);
243
Chia-I Wu730e5362014-08-19 12:15:09 +0800244struct intel_cmd {
245 struct intel_obj obj;
246
247 struct intel_dev *dev;
Chia-I Wu0b784442014-08-25 22:54:16 +0800248 struct intel_bo *scratch_bo;
Chia-I Wu513ae5b2015-07-01 19:04:59 +0800249 bool primary;
Chia-I Wu63883292014-08-25 13:50:26 +0800250 int pipeline_select;
Chia-I Wu730e5362014-08-19 12:15:09 +0800251
Chia-I Wu343b1372014-08-20 16:39:20 +0800252 struct intel_cmd_reloc *relocs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600253 uint32_t reloc_count;
Chia-I Wu343b1372014-08-20 16:39:20 +0800254
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600255 VkFlags flags;
Chia-I Wu730e5362014-08-19 12:15:09 +0800256
Chia-I Wu68f319d2014-09-09 09:43:21 +0800257 struct intel_cmd_writer writers[INTEL_CMD_WRITER_COUNT];
Chia-I Wu730e5362014-08-19 12:15:09 +0800258
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600259 uint32_t reloc_used;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600260 VkResult result;
Chia-I Wub2755562014-08-20 13:38:52 +0800261
262 struct intel_cmd_bind bind;
Chia-I Wu730e5362014-08-19 12:15:09 +0800263};
264
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600265static inline struct intel_cmd *intel_cmd(VkCmdBuffer cmd)
Chia-I Wu730e5362014-08-19 12:15:09 +0800266{
267 return (struct intel_cmd *) cmd;
268}
269
270static inline struct intel_cmd *intel_cmd_from_obj(struct intel_obj *obj)
271{
272 return (struct intel_cmd *) obj;
273}
274
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600275VkResult intel_cmd_create(struct intel_dev *dev,
276 const VkCmdBufferCreateInfo *info,
Chia-I Wu730e5362014-08-19 12:15:09 +0800277 struct intel_cmd **cmd_ret);
278void intel_cmd_destroy(struct intel_cmd *cmd);
279
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600280VkResult intel_cmd_begin(struct intel_cmd *cmd, const VkCmdBufferBeginInfo* pBeginInfo);
281VkResult intel_cmd_end(struct intel_cmd *cmd);
Chia-I Wu730e5362014-08-19 12:15:09 +0800282
Chia-I Wu465fe212015-02-11 11:27:06 -0700283void intel_cmd_decode(struct intel_cmd *cmd, bool decode_inst_writer);
Chia-I Wu00b51a82014-09-09 12:07:37 +0800284
Chia-I Wue24c3292014-08-21 14:05:23 +0800285static inline struct intel_bo *intel_cmd_get_batch(const struct intel_cmd *cmd,
Tony Barbour8205d902015-04-16 15:59:00 -0600286 VkDeviceSize *used)
Chia-I Wue24c3292014-08-21 14:05:23 +0800287{
Chia-I Wu68f319d2014-09-09 09:43:21 +0800288 const struct intel_cmd_writer *writer =
289 &cmd->writers[INTEL_CMD_WRITER_BATCH];
Chia-I Wue24c3292014-08-21 14:05:23 +0800290
291 if (used)
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 *used = writer->used;
Chia-I Wue24c3292014-08-21 14:05:23 +0800293
294 return writer->bo;
295}
296
Chia-I Wu09142132014-08-11 15:42:55 +0800297#endif /* CMD_H */