blob: 2d35e74ffb8b028311bf19634fc54c00d3108609 [file] [log] [blame]
Chia-I Wu09142132014-08-11 15:42:55 +08001/*
2 * XGL
3 *
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_pipeline_delta;
39struct intel_viewport_state;
40struct intel_raster_state;
41struct intel_msaa_state;
42struct intel_blend_state;
43struct intel_ds_state;
Chia-I Wuf8385062015-01-04 16:27:24 +080044struct intel_desc_set;
Chia-I Wuc6025ac2015-02-18 14:59:11 -070045struct intel_render_pass;
Chia-I Wub2755562014-08-20 13:38:52 +080046
Chia-I Wu00b51a82014-09-09 12:07:37 +080047struct intel_cmd_item;
Chia-I Wu958d1b72014-08-21 11:28:11 +080048struct intel_cmd_reloc;
Chia-I Wu6032b892014-10-17 14:47:18 +080049struct intel_cmd_meta;
Chia-I Wu958d1b72014-08-21 11:28:11 +080050
Chia-I Wu8370b402014-08-29 12:28:37 +080051/*
52 * We know what workarounds are needed for intel_pipeline. These are mostly
53 * for intel_pipeline_delta.
54 */
55enum intel_cmd_wa_flags {
56 /*
57 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
58 *
59 * "Before any depth stall flush (including those produced by
60 * non-pipelined state commands), software needs to first send a
61 * PIPE_CONTROL with no bits set except Post-Sync Operation != 0."
62 */
63 INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE = 1 << 0,
64
65 /*
66 * From the Sandy Bridge PRM, volume 2 part 1, page 274:
67 *
68 * "A PIPE_CONTROL command, with only the Stall At Pixel Scoreboard
69 * field set (DW1 Bit 1), must be issued prior to any change to the
70 * value in this field (Maximum Number of Threads in 3DSTATE_WM)"
71 *
72 * From the Ivy Bridge PRM, volume 2 part 1, page 286:
73 *
74 * "If this field (Maximum Number of Threads in 3DSTATE_PS) is changed
75 * between 3DPRIMITIVE commands, a PIPE_CONTROL command with Stall at
76 * Pixel Scoreboard set is required to be issued."
77 */
78 INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL = 1 << 1,
79
80 /*
81 * From the Ivy Bridge PRM, volume 2 part 1, page 106:
82 *
83 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth
84 * stall needs to be sent just prior to any 3DSTATE_VS,
85 * 3DSTATE_URB_VS, 3DSTATE_CONSTANT_VS,
86 * 3DSTATE_BINDING_TABLE_POINTER_VS, 3DSTATE_SAMPLER_STATE_POINTER_VS
87 * command. Only one PIPE_CONTROL needs to be sent before any
88 * combination of VS associated 3DSTATE."
89 */
90 INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE = 1 << 2,
91
92 /*
93 * From the Ivy Bridge PRM, volume 2 part 1, page 258:
94 *
95 * "Due to an HW issue driver needs to send a pipe control with stall
96 * when ever there is state change in depth bias related state"
97 *
98 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
99 *
100 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
101 * in the ring after this instruction
102 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
103 */
104 INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL = 1 << 3,
105
106 /*
107 * From the Ivy Bridge PRM, volume 2 part 1, page 276:
108 *
109 * "The driver must make sure a PIPE_CONTROL with the Depth Stall
110 * Enable bit set after all the following states are programmed:
111 *
112 * - 3DSTATE_PS
113 * - 3DSTATE_VIEWPORT_STATE_POINTERS_CC
114 * - 3DSTATE_CONSTANT_PS
115 * - 3DSTATE_BINDING_TABLE_POINTERS_PS
116 * - 3DSTATE_SAMPLER_STATE_POINTERS_PS
117 * - 3DSTATE_CC_STATE_POINTERS
118 * - 3DSTATE_BLEND_STATE_POINTERS
119 * - 3DSTATE_DEPTH_STENCIL_STATE_POINTERS"
120 */
121 INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL = 1 << 4,
122};
123
Chia-I Wu68f319d2014-09-09 09:43:21 +0800124enum intel_cmd_writer_type {
125 INTEL_CMD_WRITER_BATCH,
Chia-I Wu15cccf72015-02-10 04:07:40 +0800126 INTEL_CMD_WRITER_SURFACE,
Chia-I Wu68f319d2014-09-09 09:43:21 +0800127 INTEL_CMD_WRITER_STATE,
128 INTEL_CMD_WRITER_INSTRUCTION,
129
130 INTEL_CMD_WRITER_COUNT,
131};
132
Chia-I Wua57761b2014-10-14 14:27:44 +0800133struct intel_cmd_shader_cache {
134 struct {
135 const void *shader;
136 uint32_t kernel_offset;
137 } *entries;
138
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600139 uint32_t count;
140 uint32_t used;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600141};
142
Chia-I Wub2755562014-08-20 13:38:52 +0800143/*
144 * States bounded to the command buffer. We want to write states directly to
145 * the command buffer when possible, and reduce this struct.
146 */
147struct intel_cmd_bind {
Chia-I Wu6032b892014-10-17 14:47:18 +0800148 const struct intel_cmd_meta *meta;
149
Chia-I Wua57761b2014-10-14 14:27:44 +0800150 struct intel_cmd_shader_cache shader_cache;
151
Chia-I Wub2755562014-08-20 13:38:52 +0800152 struct {
153 const struct intel_pipeline *graphics;
154 const struct intel_pipeline *compute;
155 const struct intel_pipeline_delta *graphics_delta;
156 const struct intel_pipeline_delta *compute_delta;
Chia-I Wua57761b2014-10-14 14:27:44 +0800157
158 uint32_t vs_offset;
159 uint32_t tcs_offset;
160 uint32_t tes_offset;
161 uint32_t gs_offset;
162 uint32_t fs_offset;
163 uint32_t cs_offset;
Chia-I Wub2755562014-08-20 13:38:52 +0800164 } pipeline;
165
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600166 struct {
Tony Barbourfa6cac72015-01-16 14:27:35 -0700167 const struct intel_dynamic_vp *viewport;
168 const struct intel_dynamic_rs *raster;
169 const struct intel_dynamic_cb *blend;
170 const struct intel_dynamic_ds *ds;
Chia-I Wub2755562014-08-20 13:38:52 +0800171 } state;
172
173 struct {
Chia-I Wuf8385062015-01-04 16:27:24 +0800174 const struct intel_desc_set *graphics;
175 uint32_t *graphics_dynamic_offsets;
176 size_t graphics_dynamic_offset_size;
177 const struct intel_desc_set *compute;
178 uint32_t *compute_dynamic_offsets;
179 size_t compute_dynamic_offset_size;
Chia-I Wub2755562014-08-20 13:38:52 +0800180 } dset;
181
182 struct {
Chia-I Wu714df452015-01-01 07:55:04 +0800183 const struct intel_buf *buf[INTEL_MAX_VERTEX_BINDING_COUNT];
Chia-I Wu24693712014-11-08 11:54:47 +0800184 XGL_GPU_SIZE offset[INTEL_MAX_VERTEX_BINDING_COUNT];
Chia-I Wu3b04af52014-11-08 10:48:20 +0800185 } vertex;
186
187 struct {
Chia-I Wu714df452015-01-01 07:55:04 +0800188 const struct intel_buf *buf;
Chia-I Wub2755562014-08-20 13:38:52 +0800189 XGL_GPU_SIZE offset;
190 XGL_INDEX_TYPE type;
191 } index;
192
Tony Barbourfa6cac72015-01-16 14:27:35 -0700193
Chia-I Wuc6025ac2015-02-18 14:59:11 -0700194 const struct intel_render_pass *render_pass;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800195
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600196 uint32_t draw_count;
Chia-I Wu48c283d2014-08-25 23:13:46 +0800197 uint32_t wa_flags;
Chia-I Wub2755562014-08-20 13:38:52 +0800198};
Chia-I Wu09142132014-08-11 15:42:55 +0800199
Chia-I Wue24c3292014-08-21 14:05:23 +0800200struct intel_cmd_writer {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600201 size_t size;
Chia-I Wue24c3292014-08-21 14:05:23 +0800202 struct intel_bo *bo;
Chia-I Wu0f50ba82014-09-09 10:25:46 +0800203 void *ptr;
Chia-I Wue24c3292014-08-21 14:05:23 +0800204
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600205 size_t used;
Chia-I Wu00b51a82014-09-09 12:07:37 +0800206
Chia-I Wuf98dd882015-02-10 04:17:47 +0800207 uint32_t sba_offset;
208
Chia-I Wu00b51a82014-09-09 12:07:37 +0800209 /* for decoding */
210 struct intel_cmd_item *items;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600211 uint32_t item_alloc;
212 uint32_t item_used;
Chia-I Wue24c3292014-08-21 14:05:23 +0800213};
214
Chia-I Wu730e5362014-08-19 12:15:09 +0800215struct intel_cmd {
216 struct intel_obj obj;
217
218 struct intel_dev *dev;
Chia-I Wu0b784442014-08-25 22:54:16 +0800219 struct intel_bo *scratch_bo;
Chia-I Wu63883292014-08-25 13:50:26 +0800220 int pipeline_select;
Chia-I Wu730e5362014-08-19 12:15:09 +0800221
Chia-I Wu343b1372014-08-20 16:39:20 +0800222 struct intel_cmd_reloc *relocs;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600223 uint32_t reloc_count;
Chia-I Wu343b1372014-08-20 16:39:20 +0800224
Chia-I Wu730e5362014-08-19 12:15:09 +0800225 XGL_FLAGS flags;
226
Chia-I Wu68f319d2014-09-09 09:43:21 +0800227 struct intel_cmd_writer writers[INTEL_CMD_WRITER_COUNT];
Chia-I Wu730e5362014-08-19 12:15:09 +0800228
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600229 uint32_t reloc_used;
Chia-I Wu04966702014-08-20 15:05:03 +0800230 XGL_RESULT result;
Chia-I Wub2755562014-08-20 13:38:52 +0800231
232 struct intel_cmd_bind bind;
Chia-I Wu730e5362014-08-19 12:15:09 +0800233};
234
235static inline struct intel_cmd *intel_cmd(XGL_CMD_BUFFER cmd)
236{
237 return (struct intel_cmd *) cmd;
238}
239
240static inline struct intel_cmd *intel_cmd_from_obj(struct intel_obj *obj)
241{
242 return (struct intel_cmd *) obj;
243}
244
245XGL_RESULT intel_cmd_create(struct intel_dev *dev,
246 const XGL_CMD_BUFFER_CREATE_INFO *info,
247 struct intel_cmd **cmd_ret);
248void intel_cmd_destroy(struct intel_cmd *cmd);
249
Jon Ashburnc04b4dc2015-01-08 18:48:10 -0700250XGL_RESULT intel_cmd_begin(struct intel_cmd *cmd, const XGL_CMD_BUFFER_BEGIN_INFO* pBeginInfo);
Chia-I Wu730e5362014-08-19 12:15:09 +0800251XGL_RESULT intel_cmd_end(struct intel_cmd *cmd);
252
Chia-I Wu465fe212015-02-11 11:27:06 -0700253void intel_cmd_decode(struct intel_cmd *cmd, bool decode_inst_writer);
Chia-I Wu00b51a82014-09-09 12:07:37 +0800254
Chia-I Wue24c3292014-08-21 14:05:23 +0800255static inline struct intel_bo *intel_cmd_get_batch(const struct intel_cmd *cmd,
256 XGL_GPU_SIZE *used)
257{
Chia-I Wu68f319d2014-09-09 09:43:21 +0800258 const struct intel_cmd_writer *writer =
259 &cmd->writers[INTEL_CMD_WRITER_BATCH];
Chia-I Wue24c3292014-08-21 14:05:23 +0800260
261 if (used)
Chia-I Wu72292b72014-09-09 10:48:33 +0800262 *used = writer->used;
Chia-I Wue24c3292014-08-21 14:05:23 +0800263
264 return writer->bo;
265}
266
Chia-I Wu09142132014-08-11 15:42:55 +0800267#endif /* CMD_H */