blob: f35a385f6a96ace3f88144e1d944e06bb743f300 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +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 Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT8:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600227 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600240 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600241 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600260 case VK_INDEX_TYPE_UINT8:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600264 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600268 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600273 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600279 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800380
381 CMD_ASSERT(cmd, 6, 7.5);
382
383 dw1 = GEN7_SF_DW1_STATISTICS |
384 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
385 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
386 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
387 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700388 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800389
390 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
391 int format;
392
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700393 switch (pipeline->db_format) {
Tony Barbour8205d902015-04-16 15:59:00 -0600394 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800395 format = GEN6_ZFORMAT_D16_UNORM;
396 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600397 case VK_FORMAT_D32_SFLOAT:
398 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800399 format = GEN6_ZFORMAT_D32_FLOAT;
400 break;
401 default:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600402 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800403 format = 0;
404 break;
405 }
406
407 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
408 }
409
Tony Barbourfa6cac72015-01-16 14:27:35 -0700410 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800411
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700412 /* Scissor is always enabled */
413 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
414
Tony Barbourfa6cac72015-01-16 14:27:35 -0700415 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800416 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
417 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
418 } else {
419 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
420 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
421 }
422
Chia-I Wu8016a172014-08-29 18:31:32 +0800423 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
424 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
425 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800426 GEN7_SF_DW3_SUBPIXEL_8BITS;
427
428 if (pipeline->use_rs_point_size) {
429 int point_width;
430
431 /* in U8.3 */
432 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
433 point_width = U_CLAMP(point_width, 1, 2047);
434
435 dw3 |= GEN7_SF_DW3_USE_POINT_WIDTH | point_width;
436 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800437
438 body[0] = dw1;
439 body[1] = dw2;
440 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700441 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
442 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
443 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800444}
445
Chia-I Wu8016a172014-08-29 18:31:32 +0800446static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
447{
448 const uint8_t cmd_len = 20;
449 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
450 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800451 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800453 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800454
455 CMD_ASSERT(cmd, 6, 6);
456
457 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800458
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 cmd_batch_pointer(cmd, cmd_len, &dw);
460 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800461 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800462 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800463 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800464}
465
466static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
467{
468 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800469 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800470
471 CMD_ASSERT(cmd, 7, 7.5);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
475 (cmd_len - 2);
476 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800477}
478
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800479static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
480{
481 const uint8_t cmd_len = 4;
482 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
483 (cmd_len - 2);
484 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700485 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800486 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700487 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800488 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800489
490 CMD_ASSERT(cmd, 6, 7.5);
491
492 dw1 = GEN6_CLIP_DW1_STATISTICS;
493 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
494 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
495 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700496 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800497 }
498
499 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800500 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800501 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700502 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
504 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
505 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
506
507 if (pipeline->rasterizerDiscardEnable)
508 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
509 else
510 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
511
512 if (pipeline->depthClipEnable)
513 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
514
515 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
516 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
517 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
518 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
519
520 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
521 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
522 (viewport->viewport_count - 1);
523
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600524 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600525 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600526 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
527 }
528
Chia-I Wu72292b72014-09-09 10:48:33 +0800529 cmd_batch_pointer(cmd, cmd_len, &dw);
530 dw[0] = dw0;
531 dw[1] = dw1;
532 dw[2] = dw2;
533 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800534}
535
Chia-I Wu784d3042014-12-19 14:30:04 +0800536static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600537 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800538 const struct intel_pipeline *pipeline,
539 const struct intel_pipeline_shader *sh)
540{
541 int scratch_space;
542
543 CMD_ASSERT(cmd, 6, 7.5);
544
545 assert(sh->per_thread_scratch_size &&
546 sh->per_thread_scratch_size % 1024 == 0 &&
547 u_is_pow2(sh->per_thread_scratch_size) &&
548 sh->scratch_offset % 1024 == 0);
549 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
550
551 cmd_reserve_reloc(cmd, 1);
552 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
553 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
554}
555
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800556static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
557{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800558 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800559 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600561 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700562 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800563
564 CMD_ASSERT(cmd, 6, 6);
565
566 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
567
568 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
569 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
570
571 dw4 = GEN6_WM_DW4_STATISTICS |
572 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
573 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700574 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800575
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800576 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700577 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
578 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800579
Cody Northrope86574e2015-02-24 14:15:29 -0700580 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700581 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700582
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583 if (fs->uses & INTEL_SHADER_USE_KILL ||
584 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700585 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800586
Cody Northrope238deb2015-01-26 14:41:36 -0700587 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800588 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
589 if (fs->uses & INTEL_SHADER_USE_DEPTH)
590 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
591 if (fs->uses & INTEL_SHADER_USE_W)
592 dw5 |= GEN6_WM_DW5_PS_USE_W;
593
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700594 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700595 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596
597 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700598 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800599 GEN6_WM_DW6_ZW_INTERP_PIXEL |
600 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
601 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
602
Tony Barbourfa6cac72015-01-16 14:27:35 -0700603 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800604 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
605 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
606 } else {
607 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
608 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
609 }
610
Cody Northrope86574e2015-02-24 14:15:29 -0700611 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
612
Chia-I Wu784d3042014-12-19 14:30:04 +0800613 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800614 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800615 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800616 dw[2] = dw2;
617 dw[3] = 0; /* scratch */
618 dw[4] = dw4;
619 dw[5] = dw5;
620 dw[6] = dw6;
621 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700622 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800623
624 if (fs->per_thread_scratch_size)
625 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800626}
627
628static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
629{
630 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800631 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800633 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800634
635 CMD_ASSERT(cmd, 7, 7.5);
636
637 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
638
639 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700640 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641 GEN7_WM_DW1_ZW_INTERP_PIXEL |
642 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
643 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
644
645 if (fs->uses & INTEL_SHADER_USE_KILL ||
646 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700647 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648
Cody Northrope238deb2015-01-26 14:41:36 -0700649 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
650
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651 if (fs->uses & INTEL_SHADER_USE_DEPTH)
652 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
653 if (fs->uses & INTEL_SHADER_USE_W)
654 dw1 |= GEN7_WM_DW1_PS_USE_W;
655
656 dw2 = 0;
657
Tony Barbourfa6cac72015-01-16 14:27:35 -0700658 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
660 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
661 } else {
662 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
663 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
664 }
665
Chia-I Wu72292b72014-09-09 10:48:33 +0800666 cmd_batch_pointer(cmd, cmd_len, &dw);
667 dw[0] = dw0;
668 dw[1] = dw1;
669 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670}
671
672static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
673{
674 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800675 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700677 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600678 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679
680 CMD_ASSERT(cmd, 7, 7.5);
681
682 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
683
684 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
685 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
686
687 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700688 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800689
Cody Northrope86574e2015-02-24 14:15:29 -0700690 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700691 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700692
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800694 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700695 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800696 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800697 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800698 }
699
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800700 if (fs->in_count)
701 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
702
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700703 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
705
706 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
707 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700708 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
709
710 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800711
Chia-I Wu784d3042014-12-19 14:30:04 +0800712 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800713 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800714 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800715 dw[2] = dw2;
716 dw[3] = 0; /* scratch */
717 dw[4] = dw4;
718 dw[5] = dw5;
719 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700720 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800721
722 if (fs->per_thread_scratch_size)
723 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800724}
725
Chia-I Wu8ada4242015-03-02 11:19:33 -0700726static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
727 uint32_t sample_count)
728{
729 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
730 uint32_t dw1, dw2, dw3, *dw;
731
732 CMD_ASSERT(cmd, 6, 7.5);
733
734 switch (sample_count) {
735 case 4:
736 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
737 dw2 = cmd->dev->sample_pattern_4x;
738 dw3 = 0;
739 break;
740 case 8:
741 assert(cmd_gen(cmd) >= INTEL_GEN(7));
742 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
743 dw2 = cmd->dev->sample_pattern_8x[0];
744 dw3 = cmd->dev->sample_pattern_8x[1];
745 break;
746 default:
747 assert(sample_count <= 1);
748 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
749 dw2 = 0;
750 dw3 = 0;
751 break;
752 }
753
754 cmd_batch_pointer(cmd, cmd_len, &dw);
755
756 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
757 dw[1] = dw1;
758 dw[2] = dw2;
759 if (cmd_gen(cmd) >= INTEL_GEN(7))
760 dw[3] = dw3;
761}
762
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800763static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700764 const struct intel_ds_view *view,
765 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766{
767 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800768 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600769 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770
771 CMD_ASSERT(cmd, 6, 7.5);
772
773 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800774 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
775 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800776 dw0 |= (cmd_len - 2);
777
Chia-I Wu72292b72014-09-09 10:48:33 +0800778 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
779 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700780
Chia-I Wu72292b72014-09-09 10:48:33 +0800781 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700782 /* note that we only enable HiZ on Gen7+ */
783 if (!optimal_ds)
784 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
785
Chia-I Wu72292b72014-09-09 10:48:33 +0800786 dw[2] = 0;
787 dw[3] = view->cmd[2];
788 dw[4] = view->cmd[3];
789 dw[5] = view->cmd[4];
790 dw[6] = view->cmd[5];
791
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600792 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800793 cmd_reserve_reloc(cmd, 1);
794 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
795 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600796 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797}
798
799static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700800 const struct intel_ds_view *view,
801 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800802{
803 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600805 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800806
807 CMD_ASSERT(cmd, 6, 7.5);
808
809 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800810 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
811 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800812 dw0 |= (cmd_len - 2);
813
Chia-I Wu72292b72014-09-09 10:48:33 +0800814 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
815 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800816
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700817 if (view->has_stencil) {
818 dw[1] = view->cmd[6];
819
Chia-I Wu72292b72014-09-09 10:48:33 +0800820 cmd_reserve_reloc(cmd, 1);
821 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
822 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700823 } else {
824 dw[1] = 0;
825 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600826 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800827}
828
829static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700830 const struct intel_ds_view *view,
831 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800832{
833 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600835 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836
837 CMD_ASSERT(cmd, 6, 7.5);
838
839 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800840 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
841 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800842 dw0 |= (cmd_len - 2);
843
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
845 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800846
Chia-I Wu73520ac2015-02-19 11:17:45 -0700847 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700848 dw[1] = view->cmd[8];
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 cmd_reserve_reloc(cmd, 1);
851 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
852 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700853 } else {
854 dw[1] = 0;
855 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600856 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800857}
858
Chia-I Wuf8231032014-08-25 10:44:45 +0800859static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
860 uint32_t clear_val)
861{
862 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800864 GEN6_CLEAR_PARAMS_DW0_VALID |
865 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800866 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800867
868 CMD_ASSERT(cmd, 6, 6);
869
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 cmd_batch_pointer(cmd, cmd_len, &dw);
871 dw[0] = dw0;
872 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800873}
874
875static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
876 uint32_t clear_val)
877{
878 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800879 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800880 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800882
883 CMD_ASSERT(cmd, 7, 7.5);
884
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 cmd_batch_pointer(cmd, cmd_len, &dw);
886 dw[0] = dw0;
887 dw[1] = clear_val;
888 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800889}
890
Chia-I Wu302742d2014-08-22 10:28:29 +0800891static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t blend_offset,
893 uint32_t ds_offset,
894 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800895{
896 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800898
899 CMD_ASSERT(cmd, 6, 6);
900
Chia-I Wu426072d2014-08-26 14:31:55 +0800901 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800902 (cmd_len - 2);
903
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 cmd_batch_pointer(cmd, cmd_len, &dw);
905 dw[0] = dw0;
906 dw[1] = blend_offset | 1;
907 dw[2] = ds_offset | 1;
908 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800909}
910
Chia-I Wu1744cca2014-08-22 11:10:17 +0800911static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800912 uint32_t clip_offset,
913 uint32_t sf_offset,
914 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915{
916 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800918
919 CMD_ASSERT(cmd, 6, 6);
920
Chia-I Wu426072d2014-08-26 14:31:55 +0800921 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700922 GEN6_VP_PTR_DW0_CLIP_CHANGED |
923 GEN6_VP_PTR_DW0_SF_CHANGED |
924 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800925 (cmd_len - 2);
926
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 cmd_batch_pointer(cmd, cmd_len, &dw);
928 dw[0] = dw0;
929 dw[1] = clip_offset;
930 dw[2] = sf_offset;
931 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800932}
933
934static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936{
937 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800939
940 CMD_ASSERT(cmd, 6, 6);
941
Chia-I Wu426072d2014-08-26 14:31:55 +0800942 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800943 (cmd_len - 2);
944
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 cmd_batch_pointer(cmd, cmd_len, &dw);
946 dw[0] = dw0;
947 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800948}
949
Chia-I Wu42a56202014-08-23 16:47:48 +0800950static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 uint32_t vs_offset,
952 uint32_t gs_offset,
953 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800954{
955 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800957
958 CMD_ASSERT(cmd, 6, 6);
959
Chia-I Wu426072d2014-08-26 14:31:55 +0800960 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700961 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
962 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
963 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800964 (cmd_len - 2);
965
Chia-I Wu72292b72014-09-09 10:48:33 +0800966 cmd_batch_pointer(cmd, cmd_len, &dw);
967 dw[0] = dw0;
968 dw[1] = vs_offset;
969 dw[2] = gs_offset;
970 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800971}
972
Chia-I Wu257e75e2014-08-29 14:06:35 +0800973static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800974 uint32_t vs_offset,
975 uint32_t gs_offset,
976 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977{
978 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800979 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800980
981 CMD_ASSERT(cmd, 6, 6);
982
983 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700984 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
985 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
986 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800987 (cmd_len - 2);
988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 cmd_batch_pointer(cmd, cmd_len, &dw);
990 dw[0] = dw0;
991 dw[1] = vs_offset;
992 dw[2] = gs_offset;
993 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800994}
995
Chia-I Wu302742d2014-08-22 10:28:29 +0800996static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800997 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800998{
999 const uint8_t cmd_len = 2;
1000 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1001 GEN6_RENDER_SUBTYPE_3D |
1002 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001003 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001004
Chia-I Wu72292b72014-09-09 10:48:33 +08001005 cmd_batch_pointer(cmd, cmd_len, &dw);
1006 dw[0] = dw0;
1007 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001008}
1009
Chia-I Wua6c4f152014-12-02 04:19:58 +08001010static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001011{
Chia-I Wue6073342014-11-30 09:43:42 +08001012 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001013 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1014 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001015
1016 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001017 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001018
Tony Barbourfa6cac72015-01-16 14:27:35 -07001019 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001020}
1021
Chia-I Wu72292b72014-09-09 10:48:33 +08001022static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001023 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001024{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001025 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001026 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001027 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001028 uint32_t dw[3];
1029
1030 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001031 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001032 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001033 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1034 (state->ds_info.stencilReadMask & 0xff) << 8 |
1035 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001037
1038 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001039
1040 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1041 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001042
Chia-I Wu00b51a82014-09-09 12:07:37 +08001043 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001044 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001045}
1046
Chia-I Wu72292b72014-09-09 10:48:33 +08001047static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001048 uint32_t stencil_ref,
1049 const uint32_t blend_color[4])
1050{
Chia-I Wue6073342014-11-30 09:43:42 +08001051 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001052 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001053 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001054
1055 CMD_ASSERT(cmd, 6, 7.5);
1056
Chia-I Wu00b51a82014-09-09 12:07:37 +08001057 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1058 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001059 dw[0] = stencil_ref;
1060 dw[1] = 0;
1061 dw[2] = blend_color[0];
1062 dw[3] = blend_color[1];
1063 dw[4] = blend_color[2];
1064 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001065
Chia-I Wu72292b72014-09-09 10:48:33 +08001066 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001067}
1068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001070{
Chia-I Wu8370b402014-08-29 12:28:37 +08001071 CMD_ASSERT(cmd, 6, 7.5);
1072
Chia-I Wu707a29e2014-08-27 12:51:47 +08001073 if (!cmd->bind.draw_count)
1074 return;
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001077 return;
1078
Chia-I Wu8370b402014-08-29 12:28:37 +08001079 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001080
1081 /*
1082 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1083 *
1084 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1085 * pipe-control with a post-sync op and no write-cache flushes."
1086 *
1087 * The workaround below necessitates this workaround.
1088 */
1089 gen6_PIPE_CONTROL(cmd,
1090 GEN6_PIPE_CONTROL_CS_STALL |
1091 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001093
Chia-I Wud6d079d2014-08-31 13:14:21 +08001094 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1095 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001096}
1097
Chia-I Wu8370b402014-08-29 12:28:37 +08001098static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001099{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001100 CMD_ASSERT(cmd, 6, 7.5);
1101
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001102 if (!cmd->bind.draw_count)
1103 return;
1104
Chia-I Wud6d079d2014-08-31 13:14:21 +08001105 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1106 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001107}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001108
Chia-I Wu8370b402014-08-29 12:28:37 +08001109static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1110{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001111 CMD_ASSERT(cmd, 7, 7.5);
1112
Chia-I Wu8370b402014-08-29 12:28:37 +08001113 if (!cmd->bind.draw_count)
1114 return;
1115
1116 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001117
1118 gen6_PIPE_CONTROL(cmd,
1119 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001120 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001121}
1122
Chia-I Wu8370b402014-08-29 12:28:37 +08001123static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1124{
1125 CMD_ASSERT(cmd, 7, 7.5);
1126
Chia-I Wu8370b402014-08-29 12:28:37 +08001127 /*
1128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1129 *
1130 * "One of the following must also be set (when CS stall is set):
1131 *
1132 * * Render Target Cache Flush Enable ([12] of DW1)
1133 * * Depth Cache Flush Enable ([0] of DW1)
1134 * * Stall at Pixel Scoreboard ([1] of DW1)
1135 * * Depth Stall ([13] of DW1)
1136 * * Post-Sync Operation ([13] of DW1)"
1137 */
1138 gen6_PIPE_CONTROL(cmd,
1139 GEN6_PIPE_CONTROL_CS_STALL |
1140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001141 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001142}
1143
1144static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1145{
1146 CMD_ASSERT(cmd, 7, 7.5);
1147
Chia-I Wu8370b402014-08-29 12:28:37 +08001148 cmd_wa_gen6_pre_depth_stall_write(cmd);
1149
Chia-I Wud6d079d2014-08-31 13:14:21 +08001150 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001151}
1152
1153static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1154{
1155 CMD_ASSERT(cmd, 6, 7.5);
1156
1157 if (!cmd->bind.draw_count)
1158 return;
1159
1160 /*
1161 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1162 *
1163 * "Driver must guarentee that all the caches in the depth pipe are
1164 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1165 * requires driver to send a PIPE_CONTROL with a CS stall along with
1166 * a Depth Flush prior to this command."
1167 *
1168 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1169 *
1170 * "Driver must ierarchi that all the caches in the depth pipe are
1171 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1172 * requires driver to send a PIPE_CONTROL with a CS stall along with
1173 * a Depth Flush prior to this command.
1174 */
1175 gen6_PIPE_CONTROL(cmd,
1176 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1177 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001178 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001179}
1180
1181static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1182{
1183 CMD_ASSERT(cmd, 6, 7.5);
1184
1185 if (!cmd->bind.draw_count)
1186 return;
1187
1188 /*
1189 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1190 *
1191 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1192 * and a post sync operation prior to the group of depth
1193 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1194 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1195 *
1196 * This workaround satifies all the conditions.
1197 */
1198 cmd_wa_gen6_pre_depth_stall_write(cmd);
1199
1200 /*
1201 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1202 *
1203 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1204 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1205 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1206 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1207 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1208 * Depth Flush Bit set, followed by another pipelined depth stall
1209 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1210 * guarantee that the pipeline from WM onwards is already flushed
1211 * (e.g., via a preceding MI_FLUSH)."
1212 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1214 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1215 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001216}
1217
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001218void cmd_batch_state_base_address(struct intel_cmd *cmd)
1219{
1220 const uint8_t cmd_len = 10;
1221 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1222 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001223 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001224 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001225 uint32_t pos;
1226 uint32_t *dw;
1227
1228 CMD_ASSERT(cmd, 6, 7.5);
1229
1230 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1231
1232 dw[0] = dw0;
1233 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001234 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001235 dw[2] = 1;
1236 dw[3] = 1;
1237 dw[4] = 1;
1238 dw[5] = 1;
1239 /* end offsets */
1240 dw[6] = 1;
1241 dw[7] = 1 + 0xfffff000;
1242 dw[8] = 1 + 0xfffff000;
1243 dw[9] = 1;
1244
1245 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001246 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1247 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1248 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1249 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1250 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1251 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001252}
1253
Chia-I Wu7c853562015-02-27 14:35:08 -07001254void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1255{
1256 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1257 const uint8_t cmd_len = 2;
1258 uint32_t offset = 0;
1259 uint32_t *dw;
1260
1261 if (cmd_gen(cmd) <= INTEL_GEN(6))
1262 return;
1263
1264 CMD_ASSERT(cmd, 7, 7.5);
1265
1266 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1267 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1268 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1269 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1270 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1271 offset += size;
1272
1273 dw += 2;
1274 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1275 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1276 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1277
1278 dw += 2;
1279 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1280 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1281 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1282
1283 dw += 2;
1284 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1285 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1286 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1287
1288 dw += 2;
1289 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1290 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1291 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1292
1293 /*
1294 *
1295 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1296 *
1297 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1298 * in the ring after this instruction
1299 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1300 */
1301 cmd_wa_gen7_post_command_cs_stall(cmd);
1302}
1303
Chia-I Wu525c6602014-08-27 10:22:34 +08001304void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1305{
Mike Stroyan552fda42015-01-30 17:21:08 -07001306 if (pipe_control_dw0 == 0)
1307 return;
1308
Chia-I Wu525c6602014-08-27 10:22:34 +08001309 if (!cmd->bind.draw_count)
1310 return;
1311
1312 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1313
Chia-I Wu8370b402014-08-29 12:28:37 +08001314 /*
1315 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1316 *
1317 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1318 * PIPE_CONTROL with any non-zero post-sync-op is required."
1319 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001320 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001321 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001322
Chia-I Wu092279a2014-08-30 19:05:30 +08001323 /*
1324 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1325 *
1326 * "One of the following must also be set (when CS stall is set):
1327 *
1328 * * Render Target Cache Flush Enable ([12] of DW1)
1329 * * Depth Cache Flush Enable ([0] of DW1)
1330 * * Stall at Pixel Scoreboard ([1] of DW1)
1331 * * Depth Stall ([13] of DW1)
1332 * * Post-Sync Operation ([13] of DW1)"
1333 */
1334 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1335 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1336 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1337 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1338 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1339 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1340
Chia-I Wud6d079d2014-08-31 13:14:21 +08001341 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001342}
1343
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001344void cmd_batch_flush_all(struct intel_cmd *cmd)
1345{
1346 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1347 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1348 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1349 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1350 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1351 GEN6_PIPE_CONTROL_CS_STALL);
1352}
1353
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001354void cmd_batch_depth_count(struct intel_cmd *cmd,
1355 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001356 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001357{
1358 cmd_wa_gen6_pre_depth_stall_write(cmd);
1359
1360 gen6_PIPE_CONTROL(cmd,
1361 GEN6_PIPE_CONTROL_DEPTH_STALL |
1362 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001363 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001364}
1365
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001366void cmd_batch_timestamp(struct intel_cmd *cmd,
1367 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001368 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001369{
1370 /* need any WA or stall? */
1371 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1372}
1373
1374void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001375 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001376 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001377 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001378 uint64_t val)
1379{
1380 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001381 gen6_PIPE_CONTROL(cmd,
1382 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1383 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001384}
1385
Chia-I Wu302742d2014-08-22 10:28:29 +08001386static void gen6_cc_states(struct intel_cmd *cmd)
1387{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001388 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1389 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001390 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001391 uint32_t stencil_ref;
1392 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001393
1394 CMD_ASSERT(cmd, 6, 6);
1395
Chia-I Wua6c4f152014-12-02 04:19:58 +08001396 blend_offset = gen6_BLEND_STATE(cmd);
1397
1398 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001399 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001400 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001401 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001402
1403 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001404 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001405 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1406 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001407 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001408 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001409 stencil_ref = 0;
1410 }
1411
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001413
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001415}
1416
Chia-I Wu1744cca2014-08-22 11:10:17 +08001417static void gen6_viewport_states(struct intel_cmd *cmd)
1418{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001419 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001421
1422 if (!viewport)
1423 return;
1424
Tony Barbourfa6cac72015-01-16 14:27:35 -07001425 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001426 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427
1428 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001429 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001430 viewport->cmd);
1431
1432 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001433 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001434 &viewport->cmd[viewport->cmd_clip_pos]);
1435
1436 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001437 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001438 &viewport->cmd[viewport->cmd_cc_pos]);
1439
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001440 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1441 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1442 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001443
1444 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001445 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001446
Chia-I Wub1d450a2014-09-09 13:48:03 +08001447 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001448}
1449
Chia-I Wu302742d2014-08-22 10:28:29 +08001450static void gen7_cc_states(struct intel_cmd *cmd)
1451{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001452 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1453 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001454 uint32_t stencil_ref;
1455 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001456 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001457
1458 CMD_ASSERT(cmd, 7, 7.5);
1459
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001460 if (!blend && !ds)
1461 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001462
Chia-I Wua6c4f152014-12-02 04:19:58 +08001463 offset = gen6_BLEND_STATE(cmd);
1464 gen7_3dstate_pointer(cmd,
1465 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001466
Chia-I Wua6c4f152014-12-02 04:19:58 +08001467 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001468 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001469 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001470 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001471
1472 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001473 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001474 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1475 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001476 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001477 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1478 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001479 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1480 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001481 } else {
1482 stencil_ref = 0;
1483 }
1484
Chia-I Wu72292b72014-09-09 10:48:33 +08001485 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001486 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001487 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001488}
1489
Chia-I Wu1744cca2014-08-22 11:10:17 +08001490static void gen7_viewport_states(struct intel_cmd *cmd)
1491{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001492 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001493 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001494
1495 if (!viewport)
1496 return;
1497
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001498 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001499
Chia-I Wub1d450a2014-09-09 13:48:03 +08001500 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001501 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001502 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001503 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001504 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1505 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506
1507 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001508 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001509 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001510 gen7_3dstate_pointer(cmd,
1511 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001512 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001513
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001514 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1515 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1516 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1517 gen7_3dstate_pointer(cmd,
1518 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1519 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001520}
1521
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001522static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001523 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001524{
1525 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001526 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001527
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001529
1530 dw[0] = GEN6_RENDER_TYPE_RENDER |
1531 GEN6_RENDER_SUBTYPE_3D |
1532 subop | (cmd_len - 2);
1533 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001534 dw[2] = 0;
1535 dw[3] = 0;
1536 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001537}
1538
1539static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001540 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001541{
1542 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001543 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001544
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001546
1547 dw[0] = GEN6_RENDER_TYPE_RENDER |
1548 GEN6_RENDER_SUBTYPE_3D |
1549 subop | (cmd_len - 2);
1550 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001551 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001552 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001553 dw[4] = 0;
1554 dw[5] = 0;
1555 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001556}
1557
Chia-I Wu625105f2014-10-13 15:35:29 +08001558static uint32_t emit_samplers(struct intel_cmd *cmd,
1559 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001560{
Chia-I Wu862c5572015-03-28 15:23:55 +08001561 const struct intel_desc_region *region = cmd->dev->desc_region;
1562 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001563 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1564 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001565 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001566 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001567 uint32_t surface_count;
1568 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001569
1570 CMD_ASSERT(cmd, 6, 7.5);
1571
Chia-I Wu625105f2014-10-13 15:35:29 +08001572 if (!rmap || !rmap->sampler_count)
1573 return 0;
1574
Cody Northrop40316a32014-12-09 19:08:33 -07001575 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001576
Chia-I Wudcb509d2014-12-10 08:53:10 +08001577 /*
1578 * note that we cannot call cmd_state_pointer() here as the following
1579 * cmd_state_pointer() would invalidate the pointer
1580 */
1581 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001582 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001583 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001584
1585 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001586 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587 4 * rmap->sampler_count, &sampler_dw);
1588
Chia-I Wudcb509d2014-12-10 08:53:10 +08001589 cmd_state_update(cmd, border_offset,
1590 border_stride * rmap->sampler_count, &border_dw);
1591
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001592 for (i = 0; i < rmap->sampler_count; i++) {
1593 const struct intel_pipeline_rmap_slot *slot =
1594 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001595 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001596 const struct intel_sampler *sampler;
1597
Chia-I Wuf8385062015-01-04 16:27:24 +08001598 switch (slot->type) {
1599 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001600 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1601 &data->set_offsets[slot->index]);
1602 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001603 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001604 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605 sampler = NULL;
1606 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001607 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001608 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001609 sampler = NULL;
1610 break;
1611 }
1612
1613 if (sampler) {
1614 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1615
1616 sampler_dw[0] = sampler->cmd[0];
1617 sampler_dw[1] = sampler->cmd[1];
1618 sampler_dw[2] = border_offset;
1619 sampler_dw[3] = sampler->cmd[2];
1620 } else {
1621 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1622 sampler_dw[1] = 0;
1623 sampler_dw[2] = 0;
1624 sampler_dw[3] = 0;
1625 }
1626
1627 border_offset += border_stride * 4;
1628 border_dw += border_stride;
1629 sampler_dw += 4;
1630 }
1631
Chia-I Wu625105f2014-10-13 15:35:29 +08001632 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001633}
1634
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001635static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001636 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001637 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001638{
Chia-I Wu862c5572015-03-28 15:23:55 +08001639 const struct intel_desc_region *region = cmd->dev->desc_region;
1640 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001641 const uint32_t sba_offset =
1642 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001643 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001644 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001645
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001646 CMD_ASSERT(cmd, 6, 7.5);
1647
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001648 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001649 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001650 if (!surface_count)
1651 return 0;
1652
Chia-I Wu42a56202014-08-23 16:47:48 +08001653 assert(surface_count <= ARRAY_SIZE(binding_table));
1654
1655 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001656 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001657 struct intel_null_view null_view;
1658 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001659
Chia-I Wuf8385062015-01-04 16:27:24 +08001660 switch (slot->type) {
1661 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001662 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001663 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001664 (slot->index < cmd->bind.fb->rt_count) ?
1665 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001666
Chia-I Wu787a05b2014-12-05 11:02:20 +08001667 if (view) {
1668 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1669 GEN6_ALIGNMENT_SURFACE_STATE,
1670 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001671
Chia-I Wu787a05b2014-12-05 11:02:20 +08001672 cmd_reserve_reloc(cmd, 1);
1673 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1674 view->cmd[1], INTEL_RELOC_WRITE);
1675 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001676 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001677 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001678 }
1679 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001680 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001681 {
Tony Barbour22a30862015-04-22 09:02:32 -06001682 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001683 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001684 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001685 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001686 const struct intel_mem *mem;
1687 bool read_only;
1688 const uint32_t *cmd_data;
1689 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001690
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001691 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001692 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001693
Chia-I Wu862c5572015-03-28 15:23:55 +08001694 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1695 &data->set_offsets[slot->index]);
1696
1697 intel_desc_region_read_surface(region, &desc_offset, stage,
1698 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001699 if (mem) {
1700 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001701 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001702 const uint32_t reloc_flags =
1703 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001704
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001705 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001706 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001707 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001708
1709 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001710 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1711 cmd_data[1] + dynamic_offset, reloc_flags);
1712 } else {
1713 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001714 }
1715 }
1716 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001717 case INTEL_PIPELINE_RMAP_UNUSED:
1718 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001719 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001720 default:
1721 assert(!"unexpected rmap type");
1722 need_null_view = true;
1723 break;
1724 }
1725
1726 if (need_null_view) {
1727 intel_null_view_init(&null_view, cmd->dev);
1728 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1729 GEN6_ALIGNMENT_SURFACE_STATE,
1730 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001731 }
1732
Chia-I Wuf98dd882015-02-10 04:17:47 +08001733 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001734 }
1735
Chia-I Wuf98dd882015-02-10 04:17:47 +08001736 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001737 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001738 surface_count, binding_table) - sba_offset;
1739
1740 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1741 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1742
1743 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001744}
1745
Chia-I Wu1d125092014-10-08 08:49:38 +08001746static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1747{
1748 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001749 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1750 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001751 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001752
1753 CMD_ASSERT(cmd, 6, 7.5);
1754
1755 if (!pipeline->vb_count)
1756 return;
1757
1758 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1759
1760 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1761 dw++;
1762 pos++;
1763
1764 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001765 assert(pipeline->vb[i].strideInBytes <= 2048);
1766
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001767 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001768 pipeline->vb[i].strideInBytes;
1769
Chia-I Wub3686982015-02-27 09:51:16 -07001770 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001771 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1772 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001773 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001774
1775 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001777 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001778 dw[3] = 0;
1779 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001780 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001781 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001782 dw[3] = 1;
1783 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001784 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001785 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001786 dw[3] = 0;
1787 break;
1788 default:
1789 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001790 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001791 dw[3] = 0;
1792 break;
1793 }
1794
Chia-I Wu714df452015-01-01 07:55:04 +08001795 if (cmd->bind.vertex.buf[i]) {
1796 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001797 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001798
1799 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001800 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1801 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001802 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001803 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001804 dw[1] = 0;
1805 dw[2] = 0;
1806 }
1807
1808 dw += 4;
1809 pos += 4;
1810 }
1811}
1812
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001813static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1814{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001815 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1816 const struct intel_pipeline_shader *vs = &pipeline->vs;
1817 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001818 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001819 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001820 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001821 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001822
1823 CMD_ASSERT(cmd, 6, 7.5);
1824
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001825 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001826 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1827 *
1828 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1829 * 128-bit vertex elements to be passed into the payload for each
1830 * vertex."
1831 *
1832 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1833 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001834 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001835 vue_read_len = (vs->in_count + 1) / 2;
1836 if (!vue_read_len)
1837 vue_read_len = 1;
1838
1839 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1840 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1841
1842 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1843 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1844 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001845
1846 dw5 = GEN6_VS_DW5_STATISTICS |
1847 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001848
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001849 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001850 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001851 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001852 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001853
Chia-I Wube0a3d92014-09-02 13:20:59 +08001854 if (pipeline->disable_vs_cache)
1855 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1856
Chia-I Wu784d3042014-12-19 14:30:04 +08001857 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001858 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001859 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001860 dw[2] = dw2;
1861 dw[3] = 0; /* scratch */
1862 dw[4] = dw4;
1863 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001864
1865 if (vs->per_thread_scratch_size)
1866 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001867}
1868
Chia-I Wu625105f2014-10-13 15:35:29 +08001869static void emit_shader_resources(struct intel_cmd *cmd)
1870{
1871 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001872 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001873
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001874 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001875 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001876 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001877 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001878 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001879 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001880 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001881 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001882 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001883 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001884 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001885 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001886 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001887 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001888 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001889
1890 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1891 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1892 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1893 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1894 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1895
1896 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1897 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001898 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1899 binding_tables[0]);
1900 gen7_3dstate_pointer(cmd,
1901 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1902 binding_tables[1]);
1903 gen7_3dstate_pointer(cmd,
1904 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1905 binding_tables[2]);
1906 gen7_3dstate_pointer(cmd,
1907 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1908 binding_tables[3]);
1909 gen7_3dstate_pointer(cmd,
1910 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1911 binding_tables[4]);
1912
1913 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001914 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1915 samplers[0]);
1916 gen7_3dstate_pointer(cmd,
1917 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1918 samplers[1]);
1919 gen7_3dstate_pointer(cmd,
1920 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1921 samplers[2]);
1922 gen7_3dstate_pointer(cmd,
1923 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1924 samplers[3]);
1925 gen7_3dstate_pointer(cmd,
1926 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1927 samplers[4]);
1928 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001929 assert(!binding_tables[1] && !binding_tables[2]);
1930 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1931 binding_tables[0], binding_tables[3], binding_tables[4]);
1932
Chia-I Wu625105f2014-10-13 15:35:29 +08001933 assert(!samplers[1] && !samplers[2]);
1934 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1935 samplers[0], samplers[3], samplers[4]);
1936 }
1937}
1938
Chia-I Wu8ada4242015-03-02 11:19:33 -07001939static void emit_msaa(struct intel_cmd *cmd)
1940{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001941 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001942
Chia-I Wubbc7d912015-02-27 14:59:50 -07001943 if (!cmd->bind.render_pass_changed)
1944 return;
1945
Chia-I Wu8ada4242015-03-02 11:19:33 -07001946 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001947 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001948
1949 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1950 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1951}
1952
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001953static void emit_rt(struct intel_cmd *cmd)
1954{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001955 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07001956
1957 if (!cmd->bind.render_pass_changed)
1958 return;
1959
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001960 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001961 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
1962 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001963}
1964
1965static void emit_ds(struct intel_cmd *cmd)
1966{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001967 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07001968 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001969
Chia-I Wubbc7d912015-02-27 14:59:50 -07001970 if (!cmd->bind.render_pass_changed)
1971 return;
1972
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001973 if (!ds) {
1974 /* all zeros */
1975 static const struct intel_ds_view null_ds;
1976 ds = &null_ds;
1977 }
1978
1979 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001980 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1981 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1982 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001983
1984 if (cmd_gen(cmd) >= INTEL_GEN(7))
1985 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1986 else
1987 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1988}
1989
Chia-I Wua57761b2014-10-14 14:27:44 +08001990static uint32_t emit_shader(struct intel_cmd *cmd,
1991 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001992{
Chia-I Wua57761b2014-10-14 14:27:44 +08001993 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1994 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001995 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001996
Chia-I Wua57761b2014-10-14 14:27:44 +08001997 /* see if the shader is already in the cache */
1998 for (i = 0; i < cache->used; i++) {
1999 if (cache->entries[i].shader == (const void *) shader)
2000 return cache->entries[i].kernel_offset;
2001 }
2002
2003 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2004
2005 /* grow the cache if full */
2006 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002007 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002008 void *entries;
2009
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002010 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002011 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002012 if (entries) {
2013 if (cache->entries) {
2014 memcpy(entries, cache->entries,
2015 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002016 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002017 }
2018
2019 cache->entries = entries;
2020 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002021 }
2022 }
2023
Chia-I Wua57761b2014-10-14 14:27:44 +08002024 /* add the shader to the cache */
2025 if (cache->used < cache->count) {
2026 cache->entries[cache->used].shader = (const void *) shader;
2027 cache->entries[cache->used].kernel_offset = offset;
2028 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002029 }
2030
Chia-I Wua57761b2014-10-14 14:27:44 +08002031 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002032}
2033
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002034static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002035{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002036 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002037
Chia-I Wu8370b402014-08-29 12:28:37 +08002038 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2039 cmd_wa_gen6_pre_depth_stall_write(cmd);
2040 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2041 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2042 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2043 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002044
2045 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002046 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002047 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002048
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002049 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002050 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002051 }
2052 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002053 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002054 }
2055 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002056 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2057 }
2058 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2059 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2060 }
2061 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2062 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002063 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002064
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002065 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2066 gen7_3DSTATE_GS(cmd);
2067 } else {
2068 gen6_3DSTATE_GS(cmd);
2069 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002070
Chia-I Wu8370b402014-08-29 12:28:37 +08002071 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2072 cmd_wa_gen7_post_command_cs_stall(cmd);
2073 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2074 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002075}
2076
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002077static void emit_bounded_states(struct intel_cmd *cmd)
2078{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002079 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002080
2081 emit_graphics_pipeline(cmd);
2082
2083 emit_rt(cmd);
2084 emit_ds(cmd);
2085
2086 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2087 gen7_cc_states(cmd);
2088 gen7_viewport_states(cmd);
2089
2090 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2091 &cmd->bind.pipeline.graphics->vs);
2092 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2093 &cmd->bind.pipeline.graphics->fs);
2094
2095 gen6_3DSTATE_CLIP(cmd);
2096 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002097 gen7_3DSTATE_WM(cmd);
2098 gen7_3DSTATE_PS(cmd);
2099 } else {
2100 gen6_cc_states(cmd);
2101 gen6_viewport_states(cmd);
2102
2103 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2104 &cmd->bind.pipeline.graphics->vs);
2105 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2106 &cmd->bind.pipeline.graphics->fs);
2107
2108 gen6_3DSTATE_CLIP(cmd);
2109 gen6_3DSTATE_SF(cmd);
2110 gen6_3DSTATE_WM(cmd);
2111 }
2112
2113 emit_shader_resources(cmd);
2114
2115 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002116
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002117 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2118 gen6_3DSTATE_VS(cmd);
2119}
2120
Tony Barbourfa6cac72015-01-16 14:27:35 -07002121static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002122 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002123{
2124 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2125 const uint8_t cmd_len = 3;
2126 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002127
2128 CMD_ASSERT(cmd, 6, 7.5);
2129
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002130 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002131 dw[0] = 0;
2132 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002133
2134 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2135 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2136 GEN6_COMPAREFUNCTION_NEVER << 27 |
2137 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2138 } else {
2139 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2140 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2141 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002142 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002143 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002144 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2145 (GEN6_STENCILOP_KEEP) << 25 |
2146 (GEN6_STENCILOP_KEEP) << 22 |
2147 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002148 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2149 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002150 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2151 (GEN6_STENCILOP_KEEP) << 9 |
2152 (GEN6_STENCILOP_KEEP) << 6 |
2153 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002154
Chia-I Wud850a392015-02-19 11:08:25 -07002155 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2156 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2157 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2158 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2159 dw[2] = 0;
2160 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002161
2162 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2163 cmd_align, cmd_len, dw);
2164}
2165
Chia-I Wu6032b892014-10-17 14:47:18 +08002166static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2167{
2168 const struct intel_cmd_meta *meta = cmd->bind.meta;
2169 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2170
2171 CMD_ASSERT(cmd, 6, 7.5);
2172
2173 blend_offset = 0;
2174 ds_offset = 0;
2175 cc_offset = 0;
2176 cc_vp_offset = 0;
2177
Chia-I Wu29e6f502014-11-24 14:27:29 +08002178 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002179 /* BLEND_STATE */
2180 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002181 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002182 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002183 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002184 }
2185
Chia-I Wu29e6f502014-11-24 14:27:29 +08002186 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002187 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002188 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002189 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2190 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002191
Chia-I Wu29e6f502014-11-24 14:27:29 +08002192 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002193 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002194
Chia-I Wu29e6f502014-11-24 14:27:29 +08002195 /* COLOR_CALC_STATE */
2196 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002197 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002198
Chia-I Wu29e6f502014-11-24 14:27:29 +08002199 /* CC_VIEWPORT */
2200 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002201 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002202 dw[0] = u_fui(0.0f);
2203 dw[1] = u_fui(1.0f);
2204 } else {
2205 /* DEPTH_STENCIL_STATE */
2206 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002207 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002208 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2209 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2210 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002211 }
2212
2213 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2214 gen7_3dstate_pointer(cmd,
2215 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2216 blend_offset);
2217 gen7_3dstate_pointer(cmd,
2218 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2219 ds_offset);
2220 gen7_3dstate_pointer(cmd,
2221 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2222
2223 gen7_3dstate_pointer(cmd,
2224 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2225 cc_vp_offset);
2226 } else {
2227 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002228 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002229
2230 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2231 cmd_batch_pointer(cmd, 4, &dw);
2232 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002233 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002234 dw[1] = 0;
2235 dw[2] = 0;
2236 dw[3] = cc_vp_offset;
2237 }
2238}
2239
2240static void gen6_meta_surface_states(struct intel_cmd *cmd)
2241{
2242 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002243 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002244 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002245 const uint32_t sba_offset =
2246 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002247
2248 CMD_ASSERT(cmd, 6, 7.5);
2249
Chia-I Wu29e6f502014-11-24 14:27:29 +08002250 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2251 return;
2252
Chia-I Wu005c47c2014-10-22 13:49:13 +08002253 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002254 if (meta->src.valid) {
2255 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002256 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002257 meta->src.surface_len, meta->src.surface);
2258
2259 cmd_reserve_reloc(cmd, 1);
2260 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2261 cmd_surface_reloc_writer(cmd, offset, 1,
2262 meta->src.reloc_target, meta->src.reloc_offset);
2263 } else {
2264 cmd_surface_reloc(cmd, offset, 1,
2265 (struct intel_bo *) meta->src.reloc_target,
2266 meta->src.reloc_offset, meta->src.reloc_flags);
2267 }
2268
Mike Stroyan9bfad482015-02-10 15:09:23 -07002269 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002270 }
2271 if (meta->dst.valid) {
2272 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002273 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002274 meta->dst.surface_len, meta->dst.surface);
2275
2276 cmd_reserve_reloc(cmd, 1);
2277 cmd_surface_reloc(cmd, offset, 1,
2278 (struct intel_bo *) meta->dst.reloc_target,
2279 meta->dst.reloc_offset, meta->dst.reloc_flags);
2280
Mike Stroyan9bfad482015-02-10 15:09:23 -07002281 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 }
2283
2284 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002285 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002286 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002287 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002288
2289 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2291 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2292 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002293 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002294 } else {
2295 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002297 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002298 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002299 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002300 }
2301}
2302
2303static void gen6_meta_urb(struct intel_cmd *cmd)
2304{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002305 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002306 uint32_t *dw;
2307
2308 CMD_ASSERT(cmd, 6, 6);
2309
2310 /* 3DSTATE_URB */
2311 cmd_batch_pointer(cmd, 3, &dw);
2312 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002313 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 dw[2] = 0;
2315}
2316
2317static void gen7_meta_urb(struct intel_cmd *cmd)
2318{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002319 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2320 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002321 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002322 uint32_t *dw;
2323
2324 CMD_ASSERT(cmd, 7, 7.5);
2325
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2327
Chia-I Wu24aa1022014-11-25 11:53:19 +08002328 switch (cmd_gen(cmd)) {
2329 case INTEL_GEN(7.5):
2330 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2331 break;
2332 case INTEL_GEN(7):
2333 default:
2334 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2335 break;
2336 }
2337
Chia-I Wu6032b892014-10-17 14:47:18 +08002338 /* 3DSTATE_URB_x */
2339 cmd_batch_pointer(cmd, 8, &dw);
2340
2341 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002342 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002343 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002344 dw += 2;
2345
2346 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002347 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 dw += 2;
2349
2350 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002351 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002352 dw += 2;
2353
2354 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002355 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002356 dw += 2;
2357}
2358
2359static void gen6_meta_vf(struct intel_cmd *cmd)
2360{
2361 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002362 uint32_t vb_start, vb_end, vb_stride;
2363 int ve_format, ve_z_source;
2364 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002365 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002366
2367 CMD_ASSERT(cmd, 6, 7.5);
2368
Chia-I Wu29e6f502014-11-24 14:27:29 +08002369 switch (meta->mode) {
2370 case INTEL_CMD_META_VS_POINTS:
2371 cmd_batch_pointer(cmd, 3, &dw);
2372 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002373 dw[1] = GEN6_VE_DW0_VALID;
2374 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2375 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2376 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2377 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002378 return;
2379 break;
2380 case INTEL_CMD_META_FS_RECT:
2381 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002382 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002383
Chia-I Wu29e6f502014-11-24 14:27:29 +08002384 vertices[0][0] = meta->dst.x + meta->width;
2385 vertices[0][1] = meta->dst.y + meta->height;
2386 vertices[1][0] = meta->dst.x;
2387 vertices[1][1] = meta->dst.y + meta->height;
2388 vertices[2][0] = meta->dst.x;
2389 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002390
Chia-I Wu29e6f502014-11-24 14:27:29 +08002391 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2392 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002393
Chia-I Wu29e6f502014-11-24 14:27:29 +08002394 vb_end = vb_start + sizeof(vertices) - 1;
2395 vb_stride = sizeof(vertices[0]);
2396 ve_z_source = GEN6_VFCOMP_STORE_0;
2397 ve_format = GEN6_FORMAT_R32G32_USCALED;
2398 }
2399 break;
2400 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2401 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002402 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002403
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002404 vertices[0][0] = (float) (meta->dst.x + meta->width);
2405 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002406 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002407 vertices[1][0] = (float) meta->dst.x;
2408 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002409 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002410 vertices[2][0] = (float) meta->dst.x;
2411 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002412 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002413
Chia-I Wu29e6f502014-11-24 14:27:29 +08002414 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2415 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002416
Chia-I Wu29e6f502014-11-24 14:27:29 +08002417 vb_end = vb_start + sizeof(vertices) - 1;
2418 vb_stride = sizeof(vertices[0]);
2419 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2420 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2421 }
2422 break;
2423 default:
2424 assert(!"unknown meta mode");
2425 return;
2426 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002427 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002428
2429 /* 3DSTATE_VERTEX_BUFFERS */
2430 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002431
Chia-I Wu6032b892014-10-17 14:47:18 +08002432 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002433 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002434 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002435 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002436
2437 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002438 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2439 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002440
2441 dw[4] = 0;
2442
2443 /* 3DSTATE_VERTEX_ELEMENTS */
2444 cmd_batch_pointer(cmd, 5, &dw);
2445 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002446 dw[1] = GEN6_VE_DW0_VALID;
2447 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2448 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2449 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2450 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2451 dw[3] = GEN6_VE_DW0_VALID |
2452 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2453 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2454 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2455 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2456 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002457}
2458
Chia-I Wu29e6f502014-11-24 14:27:29 +08002459static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002460{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002461 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002462 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002463 uint32_t consts[8];
2464 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002465
2466 CMD_ASSERT(cmd, 6, 7.5);
2467
2468 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002469 case INTEL_DEV_META_VS_FILL_MEM:
2470 consts[0] = meta->dst.x;
2471 consts[1] = meta->clear_val[0];
2472 const_count = 2;
2473 break;
2474 case INTEL_DEV_META_VS_COPY_MEM:
2475 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2476 consts[0] = meta->dst.x;
2477 consts[1] = meta->src.x;
2478 const_count = 2;
2479 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002480 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2481 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2482 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2483 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2484 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2485 consts[0] = meta->src.x;
2486 consts[1] = meta->src.y;
2487 consts[2] = meta->width;
2488 consts[3] = meta->dst.x;
2489 const_count = 4;
2490 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002491 default:
2492 assert(!"unknown meta shader id");
2493 const_count = 0;
2494 break;
2495 }
2496
2497 /* this can be skipped but it makes state dumping prettier */
2498 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2499
2500 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2501}
2502
2503static void gen6_meta_vs(struct intel_cmd *cmd)
2504{
2505 const struct intel_cmd_meta *meta = cmd->bind.meta;
2506 const struct intel_pipeline_shader *sh =
2507 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2508 uint32_t offset, *dw;
2509
2510 CMD_ASSERT(cmd, 6, 7.5);
2511
2512 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002513 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002514
2515 /* 3DSTATE_CONSTANT_VS */
2516 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2517 cmd_batch_pointer(cmd, cmd_len, &dw);
2518 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2520
2521 /* 3DSTATE_VS */
2522 cmd_batch_pointer(cmd, 6, &dw);
2523 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2525
2526 return;
2527 }
2528
2529 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2530
2531 /* 3DSTATE_CONSTANT_VS */
2532 offset = gen6_meta_vs_constants(cmd);
2533 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2534 cmd_batch_pointer(cmd, 7, &dw);
2535 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002536 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002537 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002538 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002539 dw[4] = 0;
2540 dw[5] = 0;
2541 dw[6] = 0;
2542 } else {
2543 cmd_batch_pointer(cmd, 5, &dw);
2544 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002545 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002546 dw[1] = offset;
2547 dw[2] = 0;
2548 dw[3] = 0;
2549 dw[4] = 0;
2550 }
2551
2552 /* 3DSTATE_VS */
2553 offset = emit_shader(cmd, sh);
2554 cmd_batch_pointer(cmd, 6, &dw);
2555 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2556 dw[1] = offset;
2557 dw[2] = GEN6_THREADDISP_SPF |
2558 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2559 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002560 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002561 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2562 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2563
2564 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2565 GEN6_VS_DW5_VS_ENABLE;
2566 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002567 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002569 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002570
2571 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002572}
2573
2574static void gen6_meta_disabled(struct intel_cmd *cmd)
2575{
Chia-I Wu6032b892014-10-17 14:47:18 +08002576 uint32_t *dw;
2577
2578 CMD_ASSERT(cmd, 6, 6);
2579
Chia-I Wu6032b892014-10-17 14:47:18 +08002580 /* 3DSTATE_CONSTANT_GS */
2581 cmd_batch_pointer(cmd, 5, &dw);
2582 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2583 dw[1] = 0;
2584 dw[2] = 0;
2585 dw[3] = 0;
2586 dw[4] = 0;
2587
2588 /* 3DSTATE_GS */
2589 cmd_batch_pointer(cmd, 7, &dw);
2590 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2591 dw[1] = 0;
2592 dw[2] = 0;
2593 dw[3] = 0;
2594 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2595 dw[5] = GEN6_GS_DW5_STATISTICS;
2596 dw[6] = 0;
2597
Chia-I Wu6032b892014-10-17 14:47:18 +08002598 /* 3DSTATE_SF */
2599 cmd_batch_pointer(cmd, 20, &dw);
2600 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2601 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2602 memset(&dw[2], 0, 18 * sizeof(*dw));
2603}
2604
2605static void gen7_meta_disabled(struct intel_cmd *cmd)
2606{
2607 uint32_t *dw;
2608
2609 CMD_ASSERT(cmd, 7, 7.5);
2610
Chia-I Wu6032b892014-10-17 14:47:18 +08002611 /* 3DSTATE_CONSTANT_HS */
2612 cmd_batch_pointer(cmd, 7, &dw);
2613 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2614 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2615
2616 /* 3DSTATE_HS */
2617 cmd_batch_pointer(cmd, 7, &dw);
2618 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2619 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2620
2621 /* 3DSTATE_TE */
2622 cmd_batch_pointer(cmd, 4, &dw);
2623 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2624 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2625
2626 /* 3DSTATE_CONSTANT_DS */
2627 cmd_batch_pointer(cmd, 7, &dw);
2628 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2629 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2630
2631 /* 3DSTATE_DS */
2632 cmd_batch_pointer(cmd, 6, &dw);
2633 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2634 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2635
2636 /* 3DSTATE_CONSTANT_GS */
2637 cmd_batch_pointer(cmd, 7, &dw);
2638 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2639 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2640
2641 /* 3DSTATE_GS */
2642 cmd_batch_pointer(cmd, 7, &dw);
2643 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2644 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2645
2646 /* 3DSTATE_STREAMOUT */
2647 cmd_batch_pointer(cmd, 3, &dw);
2648 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2649 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2650
Chia-I Wu6032b892014-10-17 14:47:18 +08002651 /* 3DSTATE_SF */
2652 cmd_batch_pointer(cmd, 7, &dw);
2653 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2654 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2655
2656 /* 3DSTATE_SBE */
2657 cmd_batch_pointer(cmd, 14, &dw);
2658 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2659 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2660 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002661}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002662
Chia-I Wu29e6f502014-11-24 14:27:29 +08002663static void gen6_meta_clip(struct intel_cmd *cmd)
2664{
2665 const struct intel_cmd_meta *meta = cmd->bind.meta;
2666 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002667
Chia-I Wu29e6f502014-11-24 14:27:29 +08002668 /* 3DSTATE_CLIP */
2669 cmd_batch_pointer(cmd, 4, &dw);
2670 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2671 dw[1] = 0;
2672 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2673 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2674 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2675 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002676 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002677 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002678 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002679}
2680
2681static void gen6_meta_wm(struct intel_cmd *cmd)
2682{
2683 const struct intel_cmd_meta *meta = cmd->bind.meta;
2684 uint32_t *dw;
2685
2686 CMD_ASSERT(cmd, 6, 7.5);
2687
2688 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2689
2690 /* 3DSTATE_MULTISAMPLE */
2691 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2692 cmd_batch_pointer(cmd, 4, &dw);
2693 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2694 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2695 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2696 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2697 dw[2] = 0;
2698 dw[3] = 0;
2699 } else {
2700 cmd_batch_pointer(cmd, 3, &dw);
2701 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2702 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2703 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2704 dw[2] = 0;
2705 }
2706
2707 /* 3DSTATE_SAMPLE_MASK */
2708 cmd_batch_pointer(cmd, 2, &dw);
2709 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2710 dw[1] = (1 << meta->samples) - 1;
2711
2712 /* 3DSTATE_DRAWING_RECTANGLE */
2713 cmd_batch_pointer(cmd, 4, &dw);
2714 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002715 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2716 /* unused */
2717 dw[1] = 0;
2718 dw[2] = 0;
2719 } else {
2720 dw[1] = meta->dst.y << 16 | meta->dst.x;
2721 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2722 (meta->dst.x + meta->width - 1);
2723 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002724 dw[3] = 0;
2725}
2726
2727static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2728{
2729 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002730 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002731 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002732 uint32_t consts[8];
2733 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002734
2735 CMD_ASSERT(cmd, 6, 7.5);
2736
2737 /* underflow is fine here */
2738 offset_x = meta->src.x - meta->dst.x;
2739 offset_y = meta->src.y - meta->dst.y;
2740
2741 switch (meta->shader_id) {
2742 case INTEL_DEV_META_FS_COPY_MEM:
2743 case INTEL_DEV_META_FS_COPY_1D:
2744 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2745 case INTEL_DEV_META_FS_COPY_2D:
2746 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2747 case INTEL_DEV_META_FS_COPY_2D_MS:
2748 consts[0] = offset_x;
2749 consts[1] = offset_y;
2750 consts[2] = meta->src.layer;
2751 consts[3] = meta->src.lod;
2752 const_count = 4;
2753 break;
2754 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2755 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2756 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2757 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2758 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2759 consts[0] = offset_x;
2760 consts[1] = offset_y;
2761 consts[2] = meta->src.layer;
2762 consts[3] = meta->src.lod;
2763 consts[4] = meta->src.x;
2764 consts[5] = meta->width;
2765 const_count = 6;
2766 break;
2767 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2768 consts[0] = offset_x;
2769 consts[1] = offset_y;
2770 consts[2] = meta->width;
2771 const_count = 3;
2772 break;
2773 case INTEL_DEV_META_FS_CLEAR_COLOR:
2774 consts[0] = meta->clear_val[0];
2775 consts[1] = meta->clear_val[1];
2776 consts[2] = meta->clear_val[2];
2777 consts[3] = meta->clear_val[3];
2778 const_count = 4;
2779 break;
2780 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2781 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002782 consts[1] = meta->clear_val[1];
2783 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002784 break;
2785 case INTEL_DEV_META_FS_RESOLVE_2X:
2786 case INTEL_DEV_META_FS_RESOLVE_4X:
2787 case INTEL_DEV_META_FS_RESOLVE_8X:
2788 case INTEL_DEV_META_FS_RESOLVE_16X:
2789 consts[0] = offset_x;
2790 consts[1] = offset_y;
2791 const_count = 2;
2792 break;
2793 default:
2794 assert(!"unknown meta shader id");
2795 const_count = 0;
2796 break;
2797 }
2798
2799 /* this can be skipped but it makes state dumping prettier */
2800 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2801
2802 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2803}
2804
2805static void gen6_meta_ps(struct intel_cmd *cmd)
2806{
2807 const struct intel_cmd_meta *meta = cmd->bind.meta;
2808 const struct intel_pipeline_shader *sh =
2809 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2810 uint32_t offset, *dw;
2811
2812 CMD_ASSERT(cmd, 6, 6);
2813
Chia-I Wu29e6f502014-11-24 14:27:29 +08002814 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2815 /* 3DSTATE_CONSTANT_PS */
2816 cmd_batch_pointer(cmd, 5, &dw);
2817 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2818 dw[1] = 0;
2819 dw[2] = 0;
2820 dw[3] = 0;
2821 dw[4] = 0;
2822
2823 /* 3DSTATE_WM */
2824 cmd_batch_pointer(cmd, 9, &dw);
2825 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2826 dw[1] = 0;
2827 dw[2] = 0;
2828 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002829
2830 switch (meta->ds.op) {
2831 case INTEL_CMD_META_DS_HIZ_CLEAR:
2832 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2833 break;
2834 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2835 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2836 break;
2837 case INTEL_CMD_META_DS_RESOLVE:
2838 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2839 break;
2840 default:
2841 dw[4] = 0;
2842 break;
2843 }
2844
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002845 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002846 dw[6] = 0;
2847 dw[7] = 0;
2848 dw[8] = 0;
2849
Chia-I Wu3adf7212014-10-24 15:34:07 +08002850 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002851 }
2852
Chia-I Wu3adf7212014-10-24 15:34:07 +08002853 /* a normal color write */
2854 assert(meta->dst.valid && !sh->uses);
2855
Chia-I Wu6032b892014-10-17 14:47:18 +08002856 /* 3DSTATE_CONSTANT_PS */
2857 offset = gen6_meta_ps_constants(cmd);
2858 cmd_batch_pointer(cmd, 5, &dw);
2859 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002860 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002861 dw[1] = offset;
2862 dw[2] = 0;
2863 dw[3] = 0;
2864 dw[4] = 0;
2865
2866 /* 3DSTATE_WM */
2867 offset = emit_shader(cmd, sh);
2868 cmd_batch_pointer(cmd, 9, &dw);
2869 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2870 dw[1] = offset;
2871 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2872 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002873 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002874 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002875 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002876 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2877 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002878
Chia-I Wu6032b892014-10-17 14:47:18 +08002879 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002880 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002881 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2882 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2883 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2884 if (meta->samples > 1) {
2885 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2886 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2887 } else {
2888 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2889 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2890 }
2891 dw[7] = 0;
2892 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002893
2894 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002895}
2896
2897static void gen7_meta_ps(struct intel_cmd *cmd)
2898{
2899 const struct intel_cmd_meta *meta = cmd->bind.meta;
2900 const struct intel_pipeline_shader *sh =
2901 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2902 uint32_t offset, *dw;
2903
2904 CMD_ASSERT(cmd, 7, 7.5);
2905
Chia-I Wu29e6f502014-11-24 14:27:29 +08002906 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2907 /* 3DSTATE_WM */
2908 cmd_batch_pointer(cmd, 3, &dw);
2909 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002910
2911 switch (meta->ds.op) {
2912 case INTEL_CMD_META_DS_HIZ_CLEAR:
2913 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2914 break;
2915 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2916 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2917 break;
2918 case INTEL_CMD_META_DS_RESOLVE:
2919 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2920 break;
2921 default:
2922 dw[1] = 0;
2923 break;
2924 }
2925
2926 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002927
2928 /* 3DSTATE_CONSTANT_GS */
2929 cmd_batch_pointer(cmd, 7, &dw);
2930 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2931 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2932
2933 /* 3DSTATE_PS */
2934 cmd_batch_pointer(cmd, 8, &dw);
2935 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2936 dw[1] = 0;
2937 dw[2] = 0;
2938 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002939 /* required to avoid hangs */
2940 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002941 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002942 dw[5] = 0;
2943 dw[6] = 0;
2944 dw[7] = 0;
2945
Chia-I Wu3adf7212014-10-24 15:34:07 +08002946 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002947 }
2948
Chia-I Wu3adf7212014-10-24 15:34:07 +08002949 /* a normal color write */
2950 assert(meta->dst.valid && !sh->uses);
2951
Chia-I Wu6032b892014-10-17 14:47:18 +08002952 /* 3DSTATE_WM */
2953 cmd_batch_pointer(cmd, 3, &dw);
2954 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002955 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002956 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2957 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2958 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2959 dw[2] = 0;
2960
2961 /* 3DSTATE_CONSTANT_PS */
2962 offset = gen6_meta_ps_constants(cmd);
2963 cmd_batch_pointer(cmd, 7, &dw);
2964 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002965 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002966 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002967 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002968 dw[4] = 0;
2969 dw[5] = 0;
2970 dw[6] = 0;
2971
2972 /* 3DSTATE_PS */
2973 offset = emit_shader(cmd, sh);
2974 cmd_batch_pointer(cmd, 8, &dw);
2975 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2976 dw[1] = offset;
2977 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2978 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002979 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002980
2981 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2982 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002983 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002984
2985 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002986 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002987 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002988 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002989 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002990 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002991
2992 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2993 dw[6] = 0;
2994 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002995
2996 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002997}
2998
2999static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3000{
3001 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003002 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003003
3004 CMD_ASSERT(cmd, 6, 7.5);
3005
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003006 if (!ds) {
3007 /* all zeros */
3008 static const struct intel_ds_view null_ds;
3009 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003010 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003011
3012 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003013 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3014 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3015 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003016
3017 if (cmd_gen(cmd) >= INTEL_GEN(7))
3018 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3019 else
3020 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003021}
3022
Chia-I Wu862c5572015-03-28 15:23:55 +08003023static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3024 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003025 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003026{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003027 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003028 if (data->set_offsets)
3029 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003030
Chia-I Wu862c5572015-03-28 15:23:55 +08003031 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003032 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003033 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003034 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003035 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003036 data->set_offset_count = 0;
3037 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003038 }
3039
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003040 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003041 }
3042
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003043 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003044 if (data->dynamic_offsets)
3045 intel_free(cmd, data->dynamic_offsets);
3046
3047 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003048 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003049 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003050 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003051 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003052 data->dynamic_offset_count = 0;
3053 return false;
3054 }
3055
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003056 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003057 }
3058
3059 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003060}
3061
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003062static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3063 const struct intel_pipeline *pipeline)
3064{
3065 cmd->bind.pipeline.graphics = pipeline;
3066
3067 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003068 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003069}
3070
3071static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3072 const struct intel_pipeline *pipeline)
3073{
3074 cmd->bind.pipeline.compute = pipeline;
3075
3076 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003077 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003078}
3079
Chia-I Wu862c5572015-03-28 15:23:55 +08003080static void cmd_copy_dset_data(struct intel_cmd *cmd,
3081 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003082 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003083 uint32_t index,
3084 const struct intel_desc_set *set,
3085 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003086{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003087 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003088
Chia-I Wu862c5572015-03-28 15:23:55 +08003089 assert(index < data->set_offset_count);
3090 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003091
Chia-I Wu862c5572015-03-28 15:23:55 +08003092 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003093 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003094 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003095
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003096 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003097 dynamic_offsets,
3098 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003099 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003100}
3101
Chia-I Wu3b04af52014-11-08 10:48:20 +08003102static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003103 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003104 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003105{
Chia-I Wu714df452015-01-01 07:55:04 +08003106 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003107 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003108 return;
3109 }
3110
Chia-I Wu714df452015-01-01 07:55:04 +08003111 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003112 cmd->bind.vertex.offset[binding] = offset;
3113}
3114
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003116 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003117 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003118{
Chia-I Wu714df452015-01-01 07:55:04 +08003119 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003120 cmd->bind.index.offset = offset;
3121 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003122}
3123
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003125 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003126{
3127 cmd->bind.state.viewport = state;
3128}
3129
3130static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003131 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003132{
3133 cmd->bind.state.raster = state;
3134}
3135
3136static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003137 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003138{
3139 cmd->bind.state.ds = state;
3140}
3141
3142static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003143 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003144{
3145 cmd->bind.state.blend = state;
3146}
3147
Chia-I Wuf98dd882015-02-10 04:17:47 +08003148static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3149{
3150 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3151 struct intel_pipeline_rmap *rmaps[5] = {
3152 pipeline->vs.rmap,
3153 pipeline->tcs.rmap,
3154 pipeline->tes.rmap,
3155 pipeline->gs.rmap,
3156 pipeline->fs.rmap,
3157 };
3158 uint32_t max_write;
3159 int i;
3160
3161 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3162 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3163 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3164
3165 /* pad first */
3166 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3167
3168 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3169 const struct intel_pipeline_rmap *rmap = rmaps[i];
3170 const uint32_t surface_count = (rmap) ?
3171 rmap->rt_count + rmap->texture_resource_count +
3172 rmap->resource_count + rmap->uav_count : 0;
3173
3174 if (surface_count) {
3175 /* SURFACE_STATEs */
3176 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3177
3178 /* BINDING_TABLE_STATE */
3179 max_write += u_align(sizeof(uint32_t) * surface_count,
3180 GEN6_ALIGNMENT_SURFACE_STATE);
3181 }
3182 }
3183
3184 return max_write;
3185}
3186
3187static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3188{
3189 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3190 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3191 uint32_t max_surface_write;
3192
3193 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3194 if (cmd->bind.meta)
3195 max_surface_write = 64 * sizeof(uint32_t);
3196 else
3197 max_surface_write = cmd_get_max_surface_write(cmd);
3198
3199 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3200 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3201 /* SBA expects page-aligned addresses */
3202 writer->sba_offset = writer->used & ~0xfff;
3203
3204 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3205
3206 cmd_batch_state_base_address(cmd);
3207 }
3208}
3209
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003211 uint32_t vertex_start,
3212 uint32_t vertex_count,
3213 uint32_t instance_start,
3214 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003216 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217{
3218 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003219 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003220 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3221
3222 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003223
3224 emit_bounded_states(cmd);
3225
Chia-I Wuf98dd882015-02-10 04:17:47 +08003226 /* sanity check on cmd_get_max_surface_write() */
3227 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3228 surface_writer_used <= cmd_get_max_surface_write(cmd));
3229
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003230 if (indexed) {
3231 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003232 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003233
3234 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3235 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3236 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003237 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003238 cmd->bind.index.offset, cmd->bind.index.type,
3239 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003240 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003241 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003242 cmd->bind.index.offset, cmd->bind.index.type,
3243 p->primitive_restart);
3244 }
3245 } else {
3246 assert(!vertex_base);
3247 }
3248
3249 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3250 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3251 vertex_start, instance_count, instance_start, vertex_base);
3252 } else {
3253 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3254 vertex_start, instance_count, instance_start, vertex_base);
3255 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003256
Chia-I Wu707a29e2014-08-27 12:51:47 +08003257 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003258 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003259 /* need to re-emit all workarounds */
3260 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003261
3262 if (intel_debug & INTEL_DEBUG_NOCACHE)
3263 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003264}
3265
Chia-I Wuc14d1562014-10-17 09:49:22 +08003266void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3267{
Chia-I Wu6032b892014-10-17 14:47:18 +08003268 cmd->bind.meta = meta;
3269
Chia-I Wuf98dd882015-02-10 04:17:47 +08003270 cmd_adjust_state_base_address(cmd);
3271
Chia-I Wu6032b892014-10-17 14:47:18 +08003272 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003273 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003274
3275 gen6_meta_dynamic_states(cmd);
3276 gen6_meta_surface_states(cmd);
3277
3278 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3279 gen7_meta_urb(cmd);
3280 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003281 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003282 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003283 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003284 gen6_meta_wm(cmd);
3285 gen7_meta_ps(cmd);
3286 gen6_meta_depth_buffer(cmd);
3287
3288 cmd_wa_gen7_post_command_cs_stall(cmd);
3289 cmd_wa_gen7_post_command_depth_stall(cmd);
3290
Chia-I Wu29e6f502014-11-24 14:27:29 +08003291 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3292 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003293 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003294 } else {
3295 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3296 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003297 } else {
3298 gen6_meta_urb(cmd);
3299 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003300 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003301 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003302 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003303 gen6_meta_wm(cmd);
3304 gen6_meta_ps(cmd);
3305 gen6_meta_depth_buffer(cmd);
3306
Chia-I Wu29e6f502014-11-24 14:27:29 +08003307 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3308 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003309 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003310 } else {
3311 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3312 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003313 }
3314
3315 cmd->bind.draw_count++;
3316 /* need to re-emit all workarounds */
3317 cmd->bind.wa_flags = 0;
3318
3319 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003320
Chia-I Wubbc7d912015-02-27 14:59:50 -07003321 /* make the normal path believe the render pass has changed */
3322 cmd->bind.render_pass_changed = true;
3323
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003324 if (intel_debug & INTEL_DEBUG_NOCACHE)
3325 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003326}
3327
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003328ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003329 VkCmdBuffer cmdBuffer,
3330 VkPipelineBindPoint pipelineBindPoint,
3331 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003332{
3333 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3334
3335 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003336 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003337 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003338 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003339 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003340 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003341 break;
3342 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003343 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003344 break;
3345 }
3346}
3347
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003348ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003349 VkCmdBuffer cmdBuffer,
3350 VkStateBindPoint stateBindPoint,
3351 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003352{
3353 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3354
3355 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003356 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003357 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003358 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003359 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003360 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003361 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003362 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003363 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003364 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003365 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003366 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003367 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003368 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003369 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003370 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003371 break;
3372 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003373 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003374 break;
3375 }
3376}
3377
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003378ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003379 VkCmdBuffer cmdBuffer,
3380 VkPipelineBindPoint pipelineBindPoint,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003381 uint32_t firstSet,
3382 uint32_t setCount,
3383 const VkDescriptorSet* pDescriptorSets,
3384 uint32_t dynamicOffsetCount,
3385 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003386{
3387 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003388 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003389 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003390 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003391 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003392
3393 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003394 case VK_PIPELINE_BIND_POINT_COMPUTE:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003395 pipeline_layout = cmd->bind.pipeline.compute->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003396 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003397 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003398 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003399 pipeline_layout = cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003400 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003401 break;
3402 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003403 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003404 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003405 break;
3406 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003407
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003408 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003409 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3410
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003411 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003412 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003413 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003414 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003415 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003416 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003417 }
Chia-I Wub2755562014-08-20 13:38:52 +08003418}
3419
Tony Barbour8205d902015-04-16 15:59:00 -06003420
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003421ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3422 VkCmdBuffer cmdBuffer,
3423 uint32_t startBinding,
3424 uint32_t bindingCount,
3425 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003426 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003427{
3428 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003429
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003430 for (uint32_t i = 0; i < bindingCount; i++) {
3431 struct intel_buf *buf = intel_buf(pBuffers[i]);
3432 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3433 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003434}
3435
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003436ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003437 VkCmdBuffer cmdBuffer,
3438 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003439 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003440 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003441{
3442 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003443 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003444
Chia-I Wu714df452015-01-01 07:55:04 +08003445 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003446}
3447
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003448ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003449 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003450 uint32_t firstVertex,
3451 uint32_t vertexCount,
3452 uint32_t firstInstance,
3453 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003454{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003455 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003456
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003457 cmd_draw(cmd, firstVertex, vertexCount,
3458 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003459}
3460
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003461ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003462 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003463 uint32_t firstIndex,
3464 uint32_t indexCount,
3465 int32_t vertexOffset,
3466 uint32_t firstInstance,
3467 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003468{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003469 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003470
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003471 cmd_draw(cmd, firstIndex, indexCount,
3472 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003473}
3474
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003475ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003476 VkCmdBuffer cmdBuffer,
3477 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003478 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003479 uint32_t count,
3480 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003481{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003482 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3483
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003484 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003485}
3486
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003487ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003488 VkCmdBuffer cmdBuffer,
3489 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003490 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003491 uint32_t count,
3492 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003493{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003494 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3495
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003496 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003497}
3498
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003499ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003500 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003501 uint32_t x,
3502 uint32_t y,
3503 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003504{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003505 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3506
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003507 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003508}
3509
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003510ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003511 VkCmdBuffer cmdBuffer,
3512 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003513 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003514{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003515 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3516
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003517 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003518}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003519
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003520ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003521 VkCmdBuffer cmdBuffer,
3522 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003523{
3524 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3525
Mike Stroyan230e6252015-04-17 12:36:38 -06003526 cmd_begin_render_pass(cmd, (struct intel_render_pass *) pRenderPassBegin->renderPass, (struct intel_fb *) pRenderPassBegin->framebuffer);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003527}
3528
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003529ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003530 VkCmdBuffer cmdBuffer,
3531 VkRenderPass renderPass)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003532{
3533 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3534
3535 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3536}