blob: 01dc658ebb8b8c9e0206c44ee1a226f74c8f934a [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 |
500 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700501 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800502 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
503 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
504 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
505
Chia-I Wub6386202015-03-24 11:13:06 +0800506 if (pipeline->depth_zero_to_one)
507 dw2 |= GEN6_CLIP_DW2_APIMODE_D3D;
508 else
509 dw2 |= GEN6_CLIP_DW2_APIMODE_OGL;
510
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 if (pipeline->rasterizerDiscardEnable)
512 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
513 else
514 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
515
516 if (pipeline->depthClipEnable)
517 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
518
519 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
520 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
521 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
522 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
523
524 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
525 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
526 (viewport->viewport_count - 1);
527
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600528 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600529 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600530 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
531 }
532
Chia-I Wu72292b72014-09-09 10:48:33 +0800533 cmd_batch_pointer(cmd, cmd_len, &dw);
534 dw[0] = dw0;
535 dw[1] = dw1;
536 dw[2] = dw2;
537 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800538}
539
Chia-I Wu784d3042014-12-19 14:30:04 +0800540static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600541 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800542 const struct intel_pipeline *pipeline,
543 const struct intel_pipeline_shader *sh)
544{
545 int scratch_space;
546
547 CMD_ASSERT(cmd, 6, 7.5);
548
549 assert(sh->per_thread_scratch_size &&
550 sh->per_thread_scratch_size % 1024 == 0 &&
551 u_is_pow2(sh->per_thread_scratch_size) &&
552 sh->scratch_offset % 1024 == 0);
553 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
554
555 cmd_reserve_reloc(cmd, 1);
556 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
557 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
558}
559
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
561{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800562 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800563 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800564 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600565 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700566 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800567
568 CMD_ASSERT(cmd, 6, 6);
569
570 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
571
572 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
573 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
574
575 dw4 = GEN6_WM_DW4_STATISTICS |
576 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
577 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700578 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800579
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800580 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700581 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
582 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583
Cody Northrope86574e2015-02-24 14:15:29 -0700584 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700585 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700586
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800587 if (fs->uses & INTEL_SHADER_USE_KILL ||
588 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700589 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800590
Cody Northrope238deb2015-01-26 14:41:36 -0700591 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800592 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
593 if (fs->uses & INTEL_SHADER_USE_DEPTH)
594 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
595 if (fs->uses & INTEL_SHADER_USE_W)
596 dw5 |= GEN6_WM_DW5_PS_USE_W;
597
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700598 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700599 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800600
601 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700602 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603 GEN6_WM_DW6_ZW_INTERP_PIXEL |
604 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
605 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
606
Tony Barbourfa6cac72015-01-16 14:27:35 -0700607 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800608 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
609 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
610 } else {
611 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
612 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
613 }
614
Cody Northrope86574e2015-02-24 14:15:29 -0700615 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
616
Chia-I Wu784d3042014-12-19 14:30:04 +0800617 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800618 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800619 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[2] = dw2;
621 dw[3] = 0; /* scratch */
622 dw[4] = dw4;
623 dw[5] = dw5;
624 dw[6] = dw6;
625 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700626 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800627
628 if (fs->per_thread_scratch_size)
629 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630}
631
632static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
633{
634 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800635 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800636 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800637 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638
639 CMD_ASSERT(cmd, 7, 7.5);
640
641 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
642
643 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700644 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645 GEN7_WM_DW1_ZW_INTERP_PIXEL |
646 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
647 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
648
649 if (fs->uses & INTEL_SHADER_USE_KILL ||
650 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700651 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800652
Cody Northrope238deb2015-01-26 14:41:36 -0700653 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_DEPTH)
656 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
657 if (fs->uses & INTEL_SHADER_USE_W)
658 dw1 |= GEN7_WM_DW1_PS_USE_W;
659
660 dw2 = 0;
661
Tony Barbourfa6cac72015-01-16 14:27:35 -0700662 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
664 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
665 } else {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
668 }
669
Chia-I Wu72292b72014-09-09 10:48:33 +0800670 cmd_batch_pointer(cmd, cmd_len, &dw);
671 dw[0] = dw0;
672 dw[1] = dw1;
673 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674}
675
676static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
677{
678 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800679 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800680 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700681 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600682 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683
684 CMD_ASSERT(cmd, 7, 7.5);
685
686 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
687
688 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
689 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
690
691 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700692 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693
Cody Northrope86574e2015-02-24 14:15:29 -0700694 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700695 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700696
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800698 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700699 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800700 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800701 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800702 }
703
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 if (fs->in_count)
705 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
706
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700707 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800708 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
709
710 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
711 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700712 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
713
714 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715
Chia-I Wu784d3042014-12-19 14:30:04 +0800716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800718 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800719 dw[2] = dw2;
720 dw[3] = 0; /* scratch */
721 dw[4] = dw4;
722 dw[5] = dw5;
723 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700724 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800725
726 if (fs->per_thread_scratch_size)
727 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800728}
729
Chia-I Wu8ada4242015-03-02 11:19:33 -0700730static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
731 uint32_t sample_count)
732{
733 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
734 uint32_t dw1, dw2, dw3, *dw;
735
736 CMD_ASSERT(cmd, 6, 7.5);
737
738 switch (sample_count) {
739 case 4:
740 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
741 dw2 = cmd->dev->sample_pattern_4x;
742 dw3 = 0;
743 break;
744 case 8:
745 assert(cmd_gen(cmd) >= INTEL_GEN(7));
746 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
747 dw2 = cmd->dev->sample_pattern_8x[0];
748 dw3 = cmd->dev->sample_pattern_8x[1];
749 break;
750 default:
751 assert(sample_count <= 1);
752 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
753 dw2 = 0;
754 dw3 = 0;
755 break;
756 }
757
758 cmd_batch_pointer(cmd, cmd_len, &dw);
759
760 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
761 dw[1] = dw1;
762 dw[2] = dw2;
763 if (cmd_gen(cmd) >= INTEL_GEN(7))
764 dw[3] = dw3;
765}
766
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700768 const struct intel_ds_view *view,
769 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770{
771 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800772 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600773 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800774
775 CMD_ASSERT(cmd, 6, 7.5);
776
777 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800778 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
779 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800780 dw0 |= (cmd_len - 2);
781
Chia-I Wu72292b72014-09-09 10:48:33 +0800782 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
783 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700784
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700786 /* note that we only enable HiZ on Gen7+ */
787 if (!optimal_ds)
788 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
789
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 dw[2] = 0;
791 dw[3] = view->cmd[2];
792 dw[4] = view->cmd[3];
793 dw[5] = view->cmd[4];
794 dw[6] = view->cmd[5];
795
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600796 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800797 cmd_reserve_reloc(cmd, 1);
798 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
799 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600800 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800801}
802
803static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700804 const struct intel_ds_view *view,
805 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800806{
807 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800808 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600809 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810
811 CMD_ASSERT(cmd, 6, 7.5);
812
813 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800814 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
815 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800816 dw0 |= (cmd_len - 2);
817
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
819 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800820
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700821 if (view->has_stencil) {
822 dw[1] = view->cmd[6];
823
Chia-I Wu72292b72014-09-09 10:48:33 +0800824 cmd_reserve_reloc(cmd, 1);
825 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
826 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700827 } else {
828 dw[1] = 0;
829 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600830 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800831}
832
833static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700834 const struct intel_ds_view *view,
835 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836{
837 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800838 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600839 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800840
841 CMD_ASSERT(cmd, 6, 7.5);
842
843 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800844 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
845 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800846 dw0 |= (cmd_len - 2);
847
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
849 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800850
Chia-I Wu73520ac2015-02-19 11:17:45 -0700851 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700852 dw[1] = view->cmd[8];
853
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 cmd_reserve_reloc(cmd, 1);
855 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
856 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700857 } else {
858 dw[1] = 0;
859 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600860 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800861}
862
Chia-I Wuf8231032014-08-25 10:44:45 +0800863static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
864 uint32_t clear_val)
865{
866 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800867 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800868 GEN6_CLEAR_PARAMS_DW0_VALID |
869 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 cmd_batch_pointer(cmd, cmd_len, &dw);
875 dw[0] = dw0;
876 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800877}
878
879static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
880 uint32_t clear_val)
881{
882 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800883 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800884 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800886
887 CMD_ASSERT(cmd, 7, 7.5);
888
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 cmd_batch_pointer(cmd, cmd_len, &dw);
890 dw[0] = dw0;
891 dw[1] = clear_val;
892 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800893}
894
Chia-I Wu302742d2014-08-22 10:28:29 +0800895static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t blend_offset,
897 uint32_t ds_offset,
898 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800899{
900 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800902
903 CMD_ASSERT(cmd, 6, 6);
904
Chia-I Wu426072d2014-08-26 14:31:55 +0800905 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800906 (cmd_len - 2);
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_batch_pointer(cmd, cmd_len, &dw);
909 dw[0] = dw0;
910 dw[1] = blend_offset | 1;
911 dw[2] = ds_offset | 1;
912 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800913}
914
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t clip_offset,
917 uint32_t sf_offset,
918 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800919{
920 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800921 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922
923 CMD_ASSERT(cmd, 6, 6);
924
Chia-I Wu426072d2014-08-26 14:31:55 +0800925 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700926 GEN6_VP_PTR_DW0_CLIP_CHANGED |
927 GEN6_VP_PTR_DW0_SF_CHANGED |
928 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800929 (cmd_len - 2);
930
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 cmd_batch_pointer(cmd, cmd_len, &dw);
932 dw[0] = dw0;
933 dw[1] = clip_offset;
934 dw[2] = sf_offset;
935 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936}
937
938static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800940{
941 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800943
944 CMD_ASSERT(cmd, 6, 6);
945
Chia-I Wu426072d2014-08-26 14:31:55 +0800946 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800947 (cmd_len - 2);
948
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 cmd_batch_pointer(cmd, cmd_len, &dw);
950 dw[0] = dw0;
951 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800952}
953
Chia-I Wu42a56202014-08-23 16:47:48 +0800954static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t vs_offset,
956 uint32_t gs_offset,
957 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800958{
959 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800960 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800961
962 CMD_ASSERT(cmd, 6, 6);
963
Chia-I Wu426072d2014-08-26 14:31:55 +0800964 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700965 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
966 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
967 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800968 (cmd_len - 2);
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 cmd_batch_pointer(cmd, cmd_len, &dw);
971 dw[0] = dw0;
972 dw[1] = vs_offset;
973 dw[2] = gs_offset;
974 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800975}
976
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800978 uint32_t vs_offset,
979 uint32_t gs_offset,
980 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800981{
982 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800984
985 CMD_ASSERT(cmd, 6, 6);
986
987 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700988 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
989 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
990 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800991 (cmd_len - 2);
992
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 cmd_batch_pointer(cmd, cmd_len, &dw);
994 dw[0] = dw0;
995 dw[1] = vs_offset;
996 dw[2] = gs_offset;
997 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800998}
999
Chia-I Wu302742d2014-08-22 10:28:29 +08001000static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001002{
1003 const uint8_t cmd_len = 2;
1004 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1005 GEN6_RENDER_SUBTYPE_3D |
1006 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001008
Chia-I Wu72292b72014-09-09 10:48:33 +08001009 cmd_batch_pointer(cmd, cmd_len, &dw);
1010 dw[0] = dw0;
1011 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wua6c4f152014-12-02 04:19:58 +08001014static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001015{
Chia-I Wue6073342014-11-30 09:43:42 +08001016 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001017 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1018 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001019
1020 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001021 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001022
Tony Barbourfa6cac72015-01-16 14:27:35 -07001023 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001024}
1025
Chia-I Wu72292b72014-09-09 10:48:33 +08001026static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001027 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001028{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001029 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001030 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001031 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001032 uint32_t dw[3];
1033
1034 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001035 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001037 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1038 (state->ds_info.stencilReadMask & 0xff) << 8 |
1039 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001040 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001041
1042 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001043
1044 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1045 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001046
Chia-I Wu00b51a82014-09-09 12:07:37 +08001047 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001048 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001049}
1050
Chia-I Wu72292b72014-09-09 10:48:33 +08001051static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001052 uint32_t stencil_ref,
1053 const uint32_t blend_color[4])
1054{
Chia-I Wue6073342014-11-30 09:43:42 +08001055 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001056 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001057 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001058
1059 CMD_ASSERT(cmd, 6, 7.5);
1060
Chia-I Wu00b51a82014-09-09 12:07:37 +08001061 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1062 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001063 dw[0] = stencil_ref;
1064 dw[1] = 0;
1065 dw[2] = blend_color[0];
1066 dw[3] = blend_color[1];
1067 dw[4] = blend_color[2];
1068 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001069
Chia-I Wu72292b72014-09-09 10:48:33 +08001070 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001071}
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001074{
Chia-I Wu8370b402014-08-29 12:28:37 +08001075 CMD_ASSERT(cmd, 6, 7.5);
1076
Chia-I Wu707a29e2014-08-27 12:51:47 +08001077 if (!cmd->bind.draw_count)
1078 return;
1079
Chia-I Wu8370b402014-08-29 12:28:37 +08001080 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001081 return;
1082
Chia-I Wu8370b402014-08-29 12:28:37 +08001083 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001084
1085 /*
1086 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1087 *
1088 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1089 * pipe-control with a post-sync op and no write-cache flushes."
1090 *
1091 * The workaround below necessitates this workaround.
1092 */
1093 gen6_PIPE_CONTROL(cmd,
1094 GEN6_PIPE_CONTROL_CS_STALL |
1095 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001096 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001097
Chia-I Wud6d079d2014-08-31 13:14:21 +08001098 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1099 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001100}
1101
Chia-I Wu8370b402014-08-29 12:28:37 +08001102static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001103{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001104 CMD_ASSERT(cmd, 6, 7.5);
1105
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001106 if (!cmd->bind.draw_count)
1107 return;
1108
Chia-I Wud6d079d2014-08-31 13:14:21 +08001109 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1110 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001111}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001112
Chia-I Wu8370b402014-08-29 12:28:37 +08001113static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1114{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001115 CMD_ASSERT(cmd, 7, 7.5);
1116
Chia-I Wu8370b402014-08-29 12:28:37 +08001117 if (!cmd->bind.draw_count)
1118 return;
1119
1120 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001121
1122 gen6_PIPE_CONTROL(cmd,
1123 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001124 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001125}
1126
Chia-I Wu8370b402014-08-29 12:28:37 +08001127static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1128{
1129 CMD_ASSERT(cmd, 7, 7.5);
1130
Chia-I Wu8370b402014-08-29 12:28:37 +08001131 /*
1132 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1133 *
1134 * "One of the following must also be set (when CS stall is set):
1135 *
1136 * * Render Target Cache Flush Enable ([12] of DW1)
1137 * * Depth Cache Flush Enable ([0] of DW1)
1138 * * Stall at Pixel Scoreboard ([1] of DW1)
1139 * * Depth Stall ([13] of DW1)
1140 * * Post-Sync Operation ([13] of DW1)"
1141 */
1142 gen6_PIPE_CONTROL(cmd,
1143 GEN6_PIPE_CONTROL_CS_STALL |
1144 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001145 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001146}
1147
1148static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1149{
1150 CMD_ASSERT(cmd, 7, 7.5);
1151
Chia-I Wu8370b402014-08-29 12:28:37 +08001152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
Chia-I Wud6d079d2014-08-31 13:14:21 +08001154 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
1156
1157static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1158{
1159 CMD_ASSERT(cmd, 6, 7.5);
1160
1161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 /*
1165 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1166 *
1167 * "Driver must guarentee that all the caches in the depth pipe are
1168 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1169 * requires driver to send a PIPE_CONTROL with a CS stall along with
1170 * a Depth Flush prior to this command."
1171 *
1172 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1173 *
1174 * "Driver must ierarchi that all the caches in the depth pipe are
1175 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1176 * requires driver to send a PIPE_CONTROL with a CS stall along with
1177 * a Depth Flush prior to this command.
1178 */
1179 gen6_PIPE_CONTROL(cmd,
1180 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1181 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001182 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001183}
1184
1185static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1186{
1187 CMD_ASSERT(cmd, 6, 7.5);
1188
1189 if (!cmd->bind.draw_count)
1190 return;
1191
1192 /*
1193 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1194 *
1195 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1196 * and a post sync operation prior to the group of depth
1197 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1198 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1199 *
1200 * This workaround satifies all the conditions.
1201 */
1202 cmd_wa_gen6_pre_depth_stall_write(cmd);
1203
1204 /*
1205 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1206 *
1207 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1208 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1209 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1210 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1211 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1212 * Depth Flush Bit set, followed by another pipelined depth stall
1213 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1214 * guarantee that the pipeline from WM onwards is already flushed
1215 * (e.g., via a preceding MI_FLUSH)."
1216 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1218 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1219 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001220}
1221
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001222void cmd_batch_state_base_address(struct intel_cmd *cmd)
1223{
1224 const uint8_t cmd_len = 10;
1225 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1226 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001227 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001228 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001229 uint32_t pos;
1230 uint32_t *dw;
1231
1232 CMD_ASSERT(cmd, 6, 7.5);
1233
1234 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1235
1236 dw[0] = dw0;
1237 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001238 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001239 dw[2] = 1;
1240 dw[3] = 1;
1241 dw[4] = 1;
1242 dw[5] = 1;
1243 /* end offsets */
1244 dw[6] = 1;
1245 dw[7] = 1 + 0xfffff000;
1246 dw[8] = 1 + 0xfffff000;
1247 dw[9] = 1;
1248
1249 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001250 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1251 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1252 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1253 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1254 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1255 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001256}
1257
Chia-I Wu7c853562015-02-27 14:35:08 -07001258void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1259{
1260 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1261 const uint8_t cmd_len = 2;
1262 uint32_t offset = 0;
1263 uint32_t *dw;
1264
1265 if (cmd_gen(cmd) <= INTEL_GEN(6))
1266 return;
1267
1268 CMD_ASSERT(cmd, 7, 7.5);
1269
1270 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1271 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1272 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1273 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1274 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1275 offset += size;
1276
1277 dw += 2;
1278 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1279 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1280 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1281
1282 dw += 2;
1283 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1284 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1285 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1286
1287 dw += 2;
1288 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1289 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1290 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1291
1292 dw += 2;
1293 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1294 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1295 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1296
1297 /*
1298 *
1299 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1300 *
1301 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1302 * in the ring after this instruction
1303 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1304 */
1305 cmd_wa_gen7_post_command_cs_stall(cmd);
1306}
1307
Chia-I Wu525c6602014-08-27 10:22:34 +08001308void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1309{
Mike Stroyan552fda42015-01-30 17:21:08 -07001310 if (pipe_control_dw0 == 0)
1311 return;
1312
Chia-I Wu525c6602014-08-27 10:22:34 +08001313 if (!cmd->bind.draw_count)
1314 return;
1315
1316 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1317
Chia-I Wu8370b402014-08-29 12:28:37 +08001318 /*
1319 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1320 *
1321 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1322 * PIPE_CONTROL with any non-zero post-sync-op is required."
1323 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001324 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001325 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001326
Chia-I Wu092279a2014-08-30 19:05:30 +08001327 /*
1328 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1329 *
1330 * "One of the following must also be set (when CS stall is set):
1331 *
1332 * * Render Target Cache Flush Enable ([12] of DW1)
1333 * * Depth Cache Flush Enable ([0] of DW1)
1334 * * Stall at Pixel Scoreboard ([1] of DW1)
1335 * * Depth Stall ([13] of DW1)
1336 * * Post-Sync Operation ([13] of DW1)"
1337 */
1338 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1339 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1340 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1341 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1342 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1343 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1344
Chia-I Wud6d079d2014-08-31 13:14:21 +08001345 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001346}
1347
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001348void cmd_batch_flush_all(struct intel_cmd *cmd)
1349{
1350 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1351 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1352 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1353 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1354 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1355 GEN6_PIPE_CONTROL_CS_STALL);
1356}
1357
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001358void cmd_batch_depth_count(struct intel_cmd *cmd,
1359 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001360 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001361{
1362 cmd_wa_gen6_pre_depth_stall_write(cmd);
1363
1364 gen6_PIPE_CONTROL(cmd,
1365 GEN6_PIPE_CONTROL_DEPTH_STALL |
1366 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001367 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001368}
1369
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001370void cmd_batch_timestamp(struct intel_cmd *cmd,
1371 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001372 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001373{
1374 /* need any WA or stall? */
1375 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1376}
1377
1378void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001379 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001380 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001381 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001382 uint64_t val)
1383{
1384 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001385 gen6_PIPE_CONTROL(cmd,
1386 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1387 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001388}
1389
Chia-I Wu302742d2014-08-22 10:28:29 +08001390static void gen6_cc_states(struct intel_cmd *cmd)
1391{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001392 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1393 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001395 uint32_t stencil_ref;
1396 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001397
1398 CMD_ASSERT(cmd, 6, 6);
1399
Chia-I Wua6c4f152014-12-02 04:19:58 +08001400 blend_offset = gen6_BLEND_STATE(cmd);
1401
1402 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001403 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001404 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001405 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001406
1407 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001408 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001409 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1410 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001411 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001413 stencil_ref = 0;
1414 }
1415
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001417
Chia-I Wu72292b72014-09-09 10:48:33 +08001418 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001419}
1420
Chia-I Wu1744cca2014-08-22 11:10:17 +08001421static void gen6_viewport_states(struct intel_cmd *cmd)
1422{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001423 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001425
1426 if (!viewport)
1427 return;
1428
Tony Barbourfa6cac72015-01-16 14:27:35 -07001429 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001430 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001431
1432 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001433 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001434 viewport->cmd);
1435
1436 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001437 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001438 &viewport->cmd[viewport->cmd_clip_pos]);
1439
1440 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001441 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001442 &viewport->cmd[viewport->cmd_cc_pos]);
1443
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001444 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1445 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1446 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001447
1448 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001449 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001450
Chia-I Wub1d450a2014-09-09 13:48:03 +08001451 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001452}
1453
Chia-I Wu302742d2014-08-22 10:28:29 +08001454static void gen7_cc_states(struct intel_cmd *cmd)
1455{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001456 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1457 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001458 uint32_t stencil_ref;
1459 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001460 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001461
1462 CMD_ASSERT(cmd, 7, 7.5);
1463
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001464 if (!blend && !ds)
1465 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001466
Chia-I Wua6c4f152014-12-02 04:19:58 +08001467 offset = gen6_BLEND_STATE(cmd);
1468 gen7_3dstate_pointer(cmd,
1469 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001470
Chia-I Wua6c4f152014-12-02 04:19:58 +08001471 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001472 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001473 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001474 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001475
1476 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001477 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001478 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1479 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001480 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001481 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1482 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001483 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1484 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001485 } else {
1486 stencil_ref = 0;
1487 }
1488
Chia-I Wu72292b72014-09-09 10:48:33 +08001489 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001490 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001491 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001492}
1493
Chia-I Wu1744cca2014-08-22 11:10:17 +08001494static void gen7_viewport_states(struct intel_cmd *cmd)
1495{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001496 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001497 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001498
1499 if (!viewport)
1500 return;
1501
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001502 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001503
Chia-I Wub1d450a2014-09-09 13:48:03 +08001504 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001505 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001507 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001508 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1509 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001510
1511 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001512 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001513 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001514 gen7_3dstate_pointer(cmd,
1515 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001516 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001517
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001518 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1519 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1520 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1521 gen7_3dstate_pointer(cmd,
1522 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1523 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001524}
1525
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001526static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001527 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001528{
1529 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001530 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001531
Chia-I Wu72292b72014-09-09 10:48:33 +08001532 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001533
1534 dw[0] = GEN6_RENDER_TYPE_RENDER |
1535 GEN6_RENDER_SUBTYPE_3D |
1536 subop | (cmd_len - 2);
1537 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001538 dw[2] = 0;
1539 dw[3] = 0;
1540 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001541}
1542
1543static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001544 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001545{
1546 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001547 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001548
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001550
1551 dw[0] = GEN6_RENDER_TYPE_RENDER |
1552 GEN6_RENDER_SUBTYPE_3D |
1553 subop | (cmd_len - 2);
1554 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001555 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001556 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 dw[4] = 0;
1558 dw[5] = 0;
1559 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001560}
1561
Chia-I Wu625105f2014-10-13 15:35:29 +08001562static uint32_t emit_samplers(struct intel_cmd *cmd,
1563 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001564{
Chia-I Wu862c5572015-03-28 15:23:55 +08001565 const struct intel_desc_region *region = cmd->dev->desc_region;
1566 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001567 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1568 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001569 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001570 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001571 uint32_t surface_count;
1572 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001573
1574 CMD_ASSERT(cmd, 6, 7.5);
1575
Chia-I Wu625105f2014-10-13 15:35:29 +08001576 if (!rmap || !rmap->sampler_count)
1577 return 0;
1578
Cody Northrop40316a32014-12-09 19:08:33 -07001579 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001580
Chia-I Wudcb509d2014-12-10 08:53:10 +08001581 /*
1582 * note that we cannot call cmd_state_pointer() here as the following
1583 * cmd_state_pointer() would invalidate the pointer
1584 */
1585 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001586 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001587 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001588
1589 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001590 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001591 4 * rmap->sampler_count, &sampler_dw);
1592
Chia-I Wudcb509d2014-12-10 08:53:10 +08001593 cmd_state_update(cmd, border_offset,
1594 border_stride * rmap->sampler_count, &border_dw);
1595
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001596 for (i = 0; i < rmap->sampler_count; i++) {
1597 const struct intel_pipeline_rmap_slot *slot =
1598 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001599 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001600 const struct intel_sampler *sampler;
1601
Chia-I Wuf8385062015-01-04 16:27:24 +08001602 switch (slot->type) {
1603 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001604 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1605 &data->set_offsets[slot->index]);
1606 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001607 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001608 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001609 sampler = NULL;
1610 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001611 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001612 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001613 sampler = NULL;
1614 break;
1615 }
1616
1617 if (sampler) {
1618 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1619
1620 sampler_dw[0] = sampler->cmd[0];
1621 sampler_dw[1] = sampler->cmd[1];
1622 sampler_dw[2] = border_offset;
1623 sampler_dw[3] = sampler->cmd[2];
1624 } else {
1625 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1626 sampler_dw[1] = 0;
1627 sampler_dw[2] = 0;
1628 sampler_dw[3] = 0;
1629 }
1630
1631 border_offset += border_stride * 4;
1632 border_dw += border_stride;
1633 sampler_dw += 4;
1634 }
1635
Chia-I Wu625105f2014-10-13 15:35:29 +08001636 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001637}
1638
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001639static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001640 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001641 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001642{
Chia-I Wu862c5572015-03-28 15:23:55 +08001643 const struct intel_desc_region *region = cmd->dev->desc_region;
1644 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001645 const uint32_t sba_offset =
1646 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001647 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001648 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001649
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001650 CMD_ASSERT(cmd, 6, 7.5);
1651
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001652 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001653 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001654 if (!surface_count)
1655 return 0;
1656
Chia-I Wu42a56202014-08-23 16:47:48 +08001657 assert(surface_count <= ARRAY_SIZE(binding_table));
1658
1659 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001660 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001661 struct intel_null_view null_view;
1662 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001663
Chia-I Wuf8385062015-01-04 16:27:24 +08001664 switch (slot->type) {
1665 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001666 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001667 const struct intel_rt_view *view =
Chia-I Wu7732cb22015-03-26 15:27:55 +08001668 (slot->index < cmd->bind.fb->rt_count) ?
1669 cmd->bind.fb->rt[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001670
Chia-I Wu787a05b2014-12-05 11:02:20 +08001671 if (view) {
1672 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1673 GEN6_ALIGNMENT_SURFACE_STATE,
1674 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001675
Chia-I Wu787a05b2014-12-05 11:02:20 +08001676 cmd_reserve_reloc(cmd, 1);
1677 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1678 view->cmd[1], INTEL_RELOC_WRITE);
1679 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001680 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001681 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001682 }
1683 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001684 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001685 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001686 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001687 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001688 const struct intel_mem *mem;
1689 bool read_only;
1690 const uint32_t *cmd_data;
1691 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001692
Chia-I Wu862c5572015-03-28 15:23:55 +08001693 assert(dyn_idx < 0 || dyn_idx <
1694 cmd->bind.dset.graphics->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001695
Chia-I Wu862c5572015-03-28 15:23:55 +08001696 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1697 &data->set_offsets[slot->index]);
1698
1699 intel_desc_region_read_surface(region, &desc_offset, stage,
1700 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001701 if (mem) {
1702 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001703 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001704 const uint32_t reloc_flags =
1705 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001706
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001707 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001708 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001709 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001710
1711 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001712 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1713 cmd_data[1] + dynamic_offset, reloc_flags);
1714 } else {
1715 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001716 }
1717 }
1718 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001719 case INTEL_PIPELINE_RMAP_UNUSED:
1720 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001721 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001722 default:
1723 assert(!"unexpected rmap type");
1724 need_null_view = true;
1725 break;
1726 }
1727
1728 if (need_null_view) {
1729 intel_null_view_init(&null_view, cmd->dev);
1730 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1731 GEN6_ALIGNMENT_SURFACE_STATE,
1732 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001733 }
1734
Chia-I Wuf98dd882015-02-10 04:17:47 +08001735 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001736 }
1737
Chia-I Wuf98dd882015-02-10 04:17:47 +08001738 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001739 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001740 surface_count, binding_table) - sba_offset;
1741
1742 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1743 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1744
1745 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001746}
1747
Chia-I Wu1d125092014-10-08 08:49:38 +08001748static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1749{
1750 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001751 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1752 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001753 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001754
1755 CMD_ASSERT(cmd, 6, 7.5);
1756
1757 if (!pipeline->vb_count)
1758 return;
1759
1760 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1761
1762 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1763 dw++;
1764 pos++;
1765
1766 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001767 assert(pipeline->vb[i].strideInBytes <= 2048);
1768
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001769 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001770 pipeline->vb[i].strideInBytes;
1771
Chia-I Wub3686982015-02-27 09:51:16 -07001772 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001773 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1774 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001775 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001776
1777 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001778 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001779 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001780 dw[3] = 0;
1781 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001782 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001783 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001784 dw[3] = 1;
1785 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001786 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001787 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001788 dw[3] = 0;
1789 break;
1790 default:
1791 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001792 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001793 dw[3] = 0;
1794 break;
1795 }
1796
Chia-I Wu714df452015-01-01 07:55:04 +08001797 if (cmd->bind.vertex.buf[i]) {
1798 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001799 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001800
1801 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001802 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1803 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001804 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001805 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001806 dw[1] = 0;
1807 dw[2] = 0;
1808 }
1809
1810 dw += 4;
1811 pos += 4;
1812 }
1813}
1814
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001815static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1816{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001817 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1818 const struct intel_pipeline_shader *vs = &pipeline->vs;
1819 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001820 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001821 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001822 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001823 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001824
1825 CMD_ASSERT(cmd, 6, 7.5);
1826
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001827 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001828 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1829 *
1830 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1831 * 128-bit vertex elements to be passed into the payload for each
1832 * vertex."
1833 *
1834 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1835 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001836 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001837 vue_read_len = (vs->in_count + 1) / 2;
1838 if (!vue_read_len)
1839 vue_read_len = 1;
1840
1841 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1842 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1843
1844 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1845 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1846 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001847
1848 dw5 = GEN6_VS_DW5_STATISTICS |
1849 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001850
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001851 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001852 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001853 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001854 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001855
Chia-I Wube0a3d92014-09-02 13:20:59 +08001856 if (pipeline->disable_vs_cache)
1857 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1858
Chia-I Wu784d3042014-12-19 14:30:04 +08001859 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001860 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001861 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001862 dw[2] = dw2;
1863 dw[3] = 0; /* scratch */
1864 dw[4] = dw4;
1865 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001866
1867 if (vs->per_thread_scratch_size)
1868 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001869}
1870
Chia-I Wu625105f2014-10-13 15:35:29 +08001871static void emit_shader_resources(struct intel_cmd *cmd)
1872{
1873 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001874 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001875
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001876 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001877 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001878 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001879 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001880 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001881 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001882 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001883 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001884 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001885 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001886 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001887 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001888 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001889 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001890 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001891
1892 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1893 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1894 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1895 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1896 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1897
1898 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1899 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001900 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1901 binding_tables[0]);
1902 gen7_3dstate_pointer(cmd,
1903 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1904 binding_tables[1]);
1905 gen7_3dstate_pointer(cmd,
1906 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1907 binding_tables[2]);
1908 gen7_3dstate_pointer(cmd,
1909 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1910 binding_tables[3]);
1911 gen7_3dstate_pointer(cmd,
1912 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1913 binding_tables[4]);
1914
1915 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001916 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1917 samplers[0]);
1918 gen7_3dstate_pointer(cmd,
1919 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1920 samplers[1]);
1921 gen7_3dstate_pointer(cmd,
1922 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1923 samplers[2]);
1924 gen7_3dstate_pointer(cmd,
1925 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1926 samplers[3]);
1927 gen7_3dstate_pointer(cmd,
1928 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1929 samplers[4]);
1930 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001931 assert(!binding_tables[1] && !binding_tables[2]);
1932 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1933 binding_tables[0], binding_tables[3], binding_tables[4]);
1934
Chia-I Wu625105f2014-10-13 15:35:29 +08001935 assert(!samplers[1] && !samplers[2]);
1936 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1937 samplers[0], samplers[3], samplers[4]);
1938 }
1939}
1940
Chia-I Wu8ada4242015-03-02 11:19:33 -07001941static void emit_msaa(struct intel_cmd *cmd)
1942{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001943 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001944
Chia-I Wubbc7d912015-02-27 14:59:50 -07001945 if (!cmd->bind.render_pass_changed)
1946 return;
1947
Chia-I Wu8ada4242015-03-02 11:19:33 -07001948 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001949 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001950
1951 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1952 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1953}
1954
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001955static void emit_rt(struct intel_cmd *cmd)
1956{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001957 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07001958
1959 if (!cmd->bind.render_pass_changed)
1960 return;
1961
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001962 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001963 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
1964 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001965}
1966
1967static void emit_ds(struct intel_cmd *cmd)
1968{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001969 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07001970 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001971
Chia-I Wubbc7d912015-02-27 14:59:50 -07001972 if (!cmd->bind.render_pass_changed)
1973 return;
1974
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001975 if (!ds) {
1976 /* all zeros */
1977 static const struct intel_ds_view null_ds;
1978 ds = &null_ds;
1979 }
1980
1981 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001982 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1983 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1984 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001985
1986 if (cmd_gen(cmd) >= INTEL_GEN(7))
1987 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1988 else
1989 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1990}
1991
Chia-I Wua57761b2014-10-14 14:27:44 +08001992static uint32_t emit_shader(struct intel_cmd *cmd,
1993 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001994{
Chia-I Wua57761b2014-10-14 14:27:44 +08001995 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1996 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001997 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001998
Chia-I Wua57761b2014-10-14 14:27:44 +08001999 /* see if the shader is already in the cache */
2000 for (i = 0; i < cache->used; i++) {
2001 if (cache->entries[i].shader == (const void *) shader)
2002 return cache->entries[i].kernel_offset;
2003 }
2004
2005 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2006
2007 /* grow the cache if full */
2008 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002009 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002010 void *entries;
2011
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002012 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002013 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002014 if (entries) {
2015 if (cache->entries) {
2016 memcpy(entries, cache->entries,
2017 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002018 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002019 }
2020
2021 cache->entries = entries;
2022 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002023 }
2024 }
2025
Chia-I Wua57761b2014-10-14 14:27:44 +08002026 /* add the shader to the cache */
2027 if (cache->used < cache->count) {
2028 cache->entries[cache->used].shader = (const void *) shader;
2029 cache->entries[cache->used].kernel_offset = offset;
2030 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002031 }
2032
Chia-I Wua57761b2014-10-14 14:27:44 +08002033 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002034}
2035
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002036static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002037{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002038 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002039
Chia-I Wu8370b402014-08-29 12:28:37 +08002040 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2041 cmd_wa_gen6_pre_depth_stall_write(cmd);
2042 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2043 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2044 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2045 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002046
2047 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002048 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002049 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002050
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002051 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002052 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002053 }
2054 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002055 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002056 }
2057 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002058 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2059 }
2060 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2061 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2062 }
2063 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2064 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002065 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002066
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002067 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2068 gen7_3DSTATE_GS(cmd);
2069 } else {
2070 gen6_3DSTATE_GS(cmd);
2071 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002072
Chia-I Wu8370b402014-08-29 12:28:37 +08002073 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2074 cmd_wa_gen7_post_command_cs_stall(cmd);
2075 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2076 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002077}
2078
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002079static void emit_bounded_states(struct intel_cmd *cmd)
2080{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002081 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002082
2083 emit_graphics_pipeline(cmd);
2084
2085 emit_rt(cmd);
2086 emit_ds(cmd);
2087
2088 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2089 gen7_cc_states(cmd);
2090 gen7_viewport_states(cmd);
2091
2092 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2093 &cmd->bind.pipeline.graphics->vs);
2094 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2095 &cmd->bind.pipeline.graphics->fs);
2096
2097 gen6_3DSTATE_CLIP(cmd);
2098 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002099 gen7_3DSTATE_WM(cmd);
2100 gen7_3DSTATE_PS(cmd);
2101 } else {
2102 gen6_cc_states(cmd);
2103 gen6_viewport_states(cmd);
2104
2105 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2106 &cmd->bind.pipeline.graphics->vs);
2107 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2108 &cmd->bind.pipeline.graphics->fs);
2109
2110 gen6_3DSTATE_CLIP(cmd);
2111 gen6_3DSTATE_SF(cmd);
2112 gen6_3DSTATE_WM(cmd);
2113 }
2114
2115 emit_shader_resources(cmd);
2116
2117 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002118
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002119 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2120 gen6_3DSTATE_VS(cmd);
2121}
2122
Tony Barbourfa6cac72015-01-16 14:27:35 -07002123static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002124 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002125{
2126 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2127 const uint8_t cmd_len = 3;
2128 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002129
2130 CMD_ASSERT(cmd, 6, 7.5);
2131
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002132 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002133 dw[0] = 0;
2134 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002135
2136 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2137 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2138 GEN6_COMPAREFUNCTION_NEVER << 27 |
2139 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2140 } else {
2141 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2142 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2143 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002144 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002145 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002146 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2147 (GEN6_STENCILOP_KEEP) << 25 |
2148 (GEN6_STENCILOP_KEEP) << 22 |
2149 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002150 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2151 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002152 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2153 (GEN6_STENCILOP_KEEP) << 9 |
2154 (GEN6_STENCILOP_KEEP) << 6 |
2155 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002156
Chia-I Wud850a392015-02-19 11:08:25 -07002157 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2158 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2159 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2160 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2161 dw[2] = 0;
2162 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002163
2164 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2165 cmd_align, cmd_len, dw);
2166}
2167
Chia-I Wu6032b892014-10-17 14:47:18 +08002168static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2169{
2170 const struct intel_cmd_meta *meta = cmd->bind.meta;
2171 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2172
2173 CMD_ASSERT(cmd, 6, 7.5);
2174
2175 blend_offset = 0;
2176 ds_offset = 0;
2177 cc_offset = 0;
2178 cc_vp_offset = 0;
2179
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002181 /* BLEND_STATE */
2182 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002183 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002184 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002185 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002186 }
2187
Chia-I Wu29e6f502014-11-24 14:27:29 +08002188 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002189 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002190 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002191 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2192 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002193
Chia-I Wu29e6f502014-11-24 14:27:29 +08002194 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002195 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002196
Chia-I Wu29e6f502014-11-24 14:27:29 +08002197 /* COLOR_CALC_STATE */
2198 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002199 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002200
Chia-I Wu29e6f502014-11-24 14:27:29 +08002201 /* CC_VIEWPORT */
2202 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002203 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002204 dw[0] = u_fui(0.0f);
2205 dw[1] = u_fui(1.0f);
2206 } else {
2207 /* DEPTH_STENCIL_STATE */
2208 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002209 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002210 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2211 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2212 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002213 }
2214
2215 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2216 gen7_3dstate_pointer(cmd,
2217 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2218 blend_offset);
2219 gen7_3dstate_pointer(cmd,
2220 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2221 ds_offset);
2222 gen7_3dstate_pointer(cmd,
2223 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2224
2225 gen7_3dstate_pointer(cmd,
2226 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2227 cc_vp_offset);
2228 } else {
2229 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002230 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002231
2232 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2233 cmd_batch_pointer(cmd, 4, &dw);
2234 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002235 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002236 dw[1] = 0;
2237 dw[2] = 0;
2238 dw[3] = cc_vp_offset;
2239 }
2240}
2241
2242static void gen6_meta_surface_states(struct intel_cmd *cmd)
2243{
2244 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002245 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002246 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002247 const uint32_t sba_offset =
2248 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002249
2250 CMD_ASSERT(cmd, 6, 7.5);
2251
Chia-I Wu29e6f502014-11-24 14:27:29 +08002252 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2253 return;
2254
Chia-I Wu005c47c2014-10-22 13:49:13 +08002255 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002256 if (meta->src.valid) {
2257 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002258 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002259 meta->src.surface_len, meta->src.surface);
2260
2261 cmd_reserve_reloc(cmd, 1);
2262 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2263 cmd_surface_reloc_writer(cmd, offset, 1,
2264 meta->src.reloc_target, meta->src.reloc_offset);
2265 } else {
2266 cmd_surface_reloc(cmd, offset, 1,
2267 (struct intel_bo *) meta->src.reloc_target,
2268 meta->src.reloc_offset, meta->src.reloc_flags);
2269 }
2270
Mike Stroyan9bfad482015-02-10 15:09:23 -07002271 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002272 }
2273 if (meta->dst.valid) {
2274 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002275 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002276 meta->dst.surface_len, meta->dst.surface);
2277
2278 cmd_reserve_reloc(cmd, 1);
2279 cmd_surface_reloc(cmd, offset, 1,
2280 (struct intel_bo *) meta->dst.reloc_target,
2281 meta->dst.reloc_offset, meta->dst.reloc_flags);
2282
Mike Stroyan9bfad482015-02-10 15:09:23 -07002283 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002284 }
2285
2286 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002287 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002288 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002289 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002290
2291 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2293 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2294 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002295 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002296 } else {
2297 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002298 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002299 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002300 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002301 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002302 }
2303}
2304
2305static void gen6_meta_urb(struct intel_cmd *cmd)
2306{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002307 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002308 uint32_t *dw;
2309
2310 CMD_ASSERT(cmd, 6, 6);
2311
2312 /* 3DSTATE_URB */
2313 cmd_batch_pointer(cmd, 3, &dw);
2314 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002315 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002316 dw[2] = 0;
2317}
2318
2319static void gen7_meta_urb(struct intel_cmd *cmd)
2320{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002321 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2322 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002323 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002324 uint32_t *dw;
2325
2326 CMD_ASSERT(cmd, 7, 7.5);
2327
Chia-I Wu6032b892014-10-17 14:47:18 +08002328 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2329
Chia-I Wu24aa1022014-11-25 11:53:19 +08002330 switch (cmd_gen(cmd)) {
2331 case INTEL_GEN(7.5):
2332 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2333 break;
2334 case INTEL_GEN(7):
2335 default:
2336 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2337 break;
2338 }
2339
Chia-I Wu6032b892014-10-17 14:47:18 +08002340 /* 3DSTATE_URB_x */
2341 cmd_batch_pointer(cmd, 8, &dw);
2342
2343 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002344 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002345 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002346 dw += 2;
2347
2348 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002349 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002350 dw += 2;
2351
2352 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002353 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002354 dw += 2;
2355
2356 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002357 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002358 dw += 2;
2359}
2360
2361static void gen6_meta_vf(struct intel_cmd *cmd)
2362{
2363 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002364 uint32_t vb_start, vb_end, vb_stride;
2365 int ve_format, ve_z_source;
2366 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002367 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002368
2369 CMD_ASSERT(cmd, 6, 7.5);
2370
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371 switch (meta->mode) {
2372 case INTEL_CMD_META_VS_POINTS:
2373 cmd_batch_pointer(cmd, 3, &dw);
2374 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002375 dw[1] = GEN6_VE_DW0_VALID;
2376 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2377 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2378 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2379 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002380 return;
2381 break;
2382 case INTEL_CMD_META_FS_RECT:
2383 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002384 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002385
Chia-I Wu29e6f502014-11-24 14:27:29 +08002386 vertices[0][0] = meta->dst.x + meta->width;
2387 vertices[0][1] = meta->dst.y + meta->height;
2388 vertices[1][0] = meta->dst.x;
2389 vertices[1][1] = meta->dst.y + meta->height;
2390 vertices[2][0] = meta->dst.x;
2391 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002392
Chia-I Wu29e6f502014-11-24 14:27:29 +08002393 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2394 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002395
Chia-I Wu29e6f502014-11-24 14:27:29 +08002396 vb_end = vb_start + sizeof(vertices) - 1;
2397 vb_stride = sizeof(vertices[0]);
2398 ve_z_source = GEN6_VFCOMP_STORE_0;
2399 ve_format = GEN6_FORMAT_R32G32_USCALED;
2400 }
2401 break;
2402 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2403 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002404 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002405
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002406 vertices[0][0] = (float) (meta->dst.x + meta->width);
2407 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002408 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002409 vertices[1][0] = (float) meta->dst.x;
2410 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002411 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002412 vertices[2][0] = (float) meta->dst.x;
2413 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002414 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002415
Chia-I Wu29e6f502014-11-24 14:27:29 +08002416 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2417 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002418
Chia-I Wu29e6f502014-11-24 14:27:29 +08002419 vb_end = vb_start + sizeof(vertices) - 1;
2420 vb_stride = sizeof(vertices[0]);
2421 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2422 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2423 }
2424 break;
2425 default:
2426 assert(!"unknown meta mode");
2427 return;
2428 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002429 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002430
2431 /* 3DSTATE_VERTEX_BUFFERS */
2432 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002433
Chia-I Wu6032b892014-10-17 14:47:18 +08002434 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002435 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002436 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002437 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002438
2439 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002440 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2441 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002442
2443 dw[4] = 0;
2444
2445 /* 3DSTATE_VERTEX_ELEMENTS */
2446 cmd_batch_pointer(cmd, 5, &dw);
2447 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002448 dw[1] = GEN6_VE_DW0_VALID;
2449 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2450 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2451 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2452 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2453 dw[3] = GEN6_VE_DW0_VALID |
2454 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2455 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2456 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2457 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2458 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002459}
2460
Chia-I Wu29e6f502014-11-24 14:27:29 +08002461static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002462{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002463 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002464 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002465 uint32_t consts[8];
2466 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002467
2468 CMD_ASSERT(cmd, 6, 7.5);
2469
2470 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002471 case INTEL_DEV_META_VS_FILL_MEM:
2472 consts[0] = meta->dst.x;
2473 consts[1] = meta->clear_val[0];
2474 const_count = 2;
2475 break;
2476 case INTEL_DEV_META_VS_COPY_MEM:
2477 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2478 consts[0] = meta->dst.x;
2479 consts[1] = meta->src.x;
2480 const_count = 2;
2481 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002482 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2483 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2484 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2485 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2486 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2487 consts[0] = meta->src.x;
2488 consts[1] = meta->src.y;
2489 consts[2] = meta->width;
2490 consts[3] = meta->dst.x;
2491 const_count = 4;
2492 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002493 default:
2494 assert(!"unknown meta shader id");
2495 const_count = 0;
2496 break;
2497 }
2498
2499 /* this can be skipped but it makes state dumping prettier */
2500 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2501
2502 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2503}
2504
2505static void gen6_meta_vs(struct intel_cmd *cmd)
2506{
2507 const struct intel_cmd_meta *meta = cmd->bind.meta;
2508 const struct intel_pipeline_shader *sh =
2509 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2510 uint32_t offset, *dw;
2511
2512 CMD_ASSERT(cmd, 6, 7.5);
2513
2514 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002515 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002516
2517 /* 3DSTATE_CONSTANT_VS */
2518 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2519 cmd_batch_pointer(cmd, cmd_len, &dw);
2520 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2522
2523 /* 3DSTATE_VS */
2524 cmd_batch_pointer(cmd, 6, &dw);
2525 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2526 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2527
2528 return;
2529 }
2530
2531 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2532
2533 /* 3DSTATE_CONSTANT_VS */
2534 offset = gen6_meta_vs_constants(cmd);
2535 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2536 cmd_batch_pointer(cmd, 7, &dw);
2537 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002538 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002539 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002540 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002541 dw[4] = 0;
2542 dw[5] = 0;
2543 dw[6] = 0;
2544 } else {
2545 cmd_batch_pointer(cmd, 5, &dw);
2546 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002547 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002548 dw[1] = offset;
2549 dw[2] = 0;
2550 dw[3] = 0;
2551 dw[4] = 0;
2552 }
2553
2554 /* 3DSTATE_VS */
2555 offset = emit_shader(cmd, sh);
2556 cmd_batch_pointer(cmd, 6, &dw);
2557 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2558 dw[1] = offset;
2559 dw[2] = GEN6_THREADDISP_SPF |
2560 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2561 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002562 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2564 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2565
2566 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2567 GEN6_VS_DW5_VS_ENABLE;
2568 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002569 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002570 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002571 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002572
2573 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002574}
2575
2576static void gen6_meta_disabled(struct intel_cmd *cmd)
2577{
Chia-I Wu6032b892014-10-17 14:47:18 +08002578 uint32_t *dw;
2579
2580 CMD_ASSERT(cmd, 6, 6);
2581
Chia-I Wu6032b892014-10-17 14:47:18 +08002582 /* 3DSTATE_CONSTANT_GS */
2583 cmd_batch_pointer(cmd, 5, &dw);
2584 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2585 dw[1] = 0;
2586 dw[2] = 0;
2587 dw[3] = 0;
2588 dw[4] = 0;
2589
2590 /* 3DSTATE_GS */
2591 cmd_batch_pointer(cmd, 7, &dw);
2592 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2593 dw[1] = 0;
2594 dw[2] = 0;
2595 dw[3] = 0;
2596 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2597 dw[5] = GEN6_GS_DW5_STATISTICS;
2598 dw[6] = 0;
2599
Chia-I Wu6032b892014-10-17 14:47:18 +08002600 /* 3DSTATE_SF */
2601 cmd_batch_pointer(cmd, 20, &dw);
2602 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2603 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2604 memset(&dw[2], 0, 18 * sizeof(*dw));
2605}
2606
2607static void gen7_meta_disabled(struct intel_cmd *cmd)
2608{
2609 uint32_t *dw;
2610
2611 CMD_ASSERT(cmd, 7, 7.5);
2612
Chia-I Wu6032b892014-10-17 14:47:18 +08002613 /* 3DSTATE_CONSTANT_HS */
2614 cmd_batch_pointer(cmd, 7, &dw);
2615 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2616 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2617
2618 /* 3DSTATE_HS */
2619 cmd_batch_pointer(cmd, 7, &dw);
2620 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2621 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2622
2623 /* 3DSTATE_TE */
2624 cmd_batch_pointer(cmd, 4, &dw);
2625 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2626 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2627
2628 /* 3DSTATE_CONSTANT_DS */
2629 cmd_batch_pointer(cmd, 7, &dw);
2630 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2631 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2632
2633 /* 3DSTATE_DS */
2634 cmd_batch_pointer(cmd, 6, &dw);
2635 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2636 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2637
2638 /* 3DSTATE_CONSTANT_GS */
2639 cmd_batch_pointer(cmd, 7, &dw);
2640 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2641 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2642
2643 /* 3DSTATE_GS */
2644 cmd_batch_pointer(cmd, 7, &dw);
2645 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2646 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2647
2648 /* 3DSTATE_STREAMOUT */
2649 cmd_batch_pointer(cmd, 3, &dw);
2650 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2651 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2652
Chia-I Wu6032b892014-10-17 14:47:18 +08002653 /* 3DSTATE_SF */
2654 cmd_batch_pointer(cmd, 7, &dw);
2655 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2656 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2657
2658 /* 3DSTATE_SBE */
2659 cmd_batch_pointer(cmd, 14, &dw);
2660 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2661 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2662 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002663}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002664
Chia-I Wu29e6f502014-11-24 14:27:29 +08002665static void gen6_meta_clip(struct intel_cmd *cmd)
2666{
2667 const struct intel_cmd_meta *meta = cmd->bind.meta;
2668 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002669
Chia-I Wu29e6f502014-11-24 14:27:29 +08002670 /* 3DSTATE_CLIP */
2671 cmd_batch_pointer(cmd, 4, &dw);
2672 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2673 dw[1] = 0;
2674 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2675 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2676 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2677 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002678 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002679 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002680 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002681}
2682
2683static void gen6_meta_wm(struct intel_cmd *cmd)
2684{
2685 const struct intel_cmd_meta *meta = cmd->bind.meta;
2686 uint32_t *dw;
2687
2688 CMD_ASSERT(cmd, 6, 7.5);
2689
2690 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2691
2692 /* 3DSTATE_MULTISAMPLE */
2693 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2694 cmd_batch_pointer(cmd, 4, &dw);
2695 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2696 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2697 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2698 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2699 dw[2] = 0;
2700 dw[3] = 0;
2701 } else {
2702 cmd_batch_pointer(cmd, 3, &dw);
2703 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2704 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2705 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2706 dw[2] = 0;
2707 }
2708
2709 /* 3DSTATE_SAMPLE_MASK */
2710 cmd_batch_pointer(cmd, 2, &dw);
2711 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2712 dw[1] = (1 << meta->samples) - 1;
2713
2714 /* 3DSTATE_DRAWING_RECTANGLE */
2715 cmd_batch_pointer(cmd, 4, &dw);
2716 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002717 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2718 /* unused */
2719 dw[1] = 0;
2720 dw[2] = 0;
2721 } else {
2722 dw[1] = meta->dst.y << 16 | meta->dst.x;
2723 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2724 (meta->dst.x + meta->width - 1);
2725 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002726 dw[3] = 0;
2727}
2728
2729static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2730{
2731 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002732 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002733 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002734 uint32_t consts[8];
2735 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002736
2737 CMD_ASSERT(cmd, 6, 7.5);
2738
2739 /* underflow is fine here */
2740 offset_x = meta->src.x - meta->dst.x;
2741 offset_y = meta->src.y - meta->dst.y;
2742
2743 switch (meta->shader_id) {
2744 case INTEL_DEV_META_FS_COPY_MEM:
2745 case INTEL_DEV_META_FS_COPY_1D:
2746 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2747 case INTEL_DEV_META_FS_COPY_2D:
2748 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2749 case INTEL_DEV_META_FS_COPY_2D_MS:
2750 consts[0] = offset_x;
2751 consts[1] = offset_y;
2752 consts[2] = meta->src.layer;
2753 consts[3] = meta->src.lod;
2754 const_count = 4;
2755 break;
2756 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2757 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2758 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2759 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2760 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2761 consts[0] = offset_x;
2762 consts[1] = offset_y;
2763 consts[2] = meta->src.layer;
2764 consts[3] = meta->src.lod;
2765 consts[4] = meta->src.x;
2766 consts[5] = meta->width;
2767 const_count = 6;
2768 break;
2769 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2770 consts[0] = offset_x;
2771 consts[1] = offset_y;
2772 consts[2] = meta->width;
2773 const_count = 3;
2774 break;
2775 case INTEL_DEV_META_FS_CLEAR_COLOR:
2776 consts[0] = meta->clear_val[0];
2777 consts[1] = meta->clear_val[1];
2778 consts[2] = meta->clear_val[2];
2779 consts[3] = meta->clear_val[3];
2780 const_count = 4;
2781 break;
2782 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2783 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002784 consts[1] = meta->clear_val[1];
2785 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002786 break;
2787 case INTEL_DEV_META_FS_RESOLVE_2X:
2788 case INTEL_DEV_META_FS_RESOLVE_4X:
2789 case INTEL_DEV_META_FS_RESOLVE_8X:
2790 case INTEL_DEV_META_FS_RESOLVE_16X:
2791 consts[0] = offset_x;
2792 consts[1] = offset_y;
2793 const_count = 2;
2794 break;
2795 default:
2796 assert(!"unknown meta shader id");
2797 const_count = 0;
2798 break;
2799 }
2800
2801 /* this can be skipped but it makes state dumping prettier */
2802 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2803
2804 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2805}
2806
2807static void gen6_meta_ps(struct intel_cmd *cmd)
2808{
2809 const struct intel_cmd_meta *meta = cmd->bind.meta;
2810 const struct intel_pipeline_shader *sh =
2811 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2812 uint32_t offset, *dw;
2813
2814 CMD_ASSERT(cmd, 6, 6);
2815
Chia-I Wu29e6f502014-11-24 14:27:29 +08002816 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2817 /* 3DSTATE_CONSTANT_PS */
2818 cmd_batch_pointer(cmd, 5, &dw);
2819 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2820 dw[1] = 0;
2821 dw[2] = 0;
2822 dw[3] = 0;
2823 dw[4] = 0;
2824
2825 /* 3DSTATE_WM */
2826 cmd_batch_pointer(cmd, 9, &dw);
2827 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2828 dw[1] = 0;
2829 dw[2] = 0;
2830 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002831
2832 switch (meta->ds.op) {
2833 case INTEL_CMD_META_DS_HIZ_CLEAR:
2834 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2835 break;
2836 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2837 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2838 break;
2839 case INTEL_CMD_META_DS_RESOLVE:
2840 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2841 break;
2842 default:
2843 dw[4] = 0;
2844 break;
2845 }
2846
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002847 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002848 dw[6] = 0;
2849 dw[7] = 0;
2850 dw[8] = 0;
2851
Chia-I Wu3adf7212014-10-24 15:34:07 +08002852 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002853 }
2854
Chia-I Wu3adf7212014-10-24 15:34:07 +08002855 /* a normal color write */
2856 assert(meta->dst.valid && !sh->uses);
2857
Chia-I Wu6032b892014-10-17 14:47:18 +08002858 /* 3DSTATE_CONSTANT_PS */
2859 offset = gen6_meta_ps_constants(cmd);
2860 cmd_batch_pointer(cmd, 5, &dw);
2861 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002862 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002863 dw[1] = offset;
2864 dw[2] = 0;
2865 dw[3] = 0;
2866 dw[4] = 0;
2867
2868 /* 3DSTATE_WM */
2869 offset = emit_shader(cmd, sh);
2870 cmd_batch_pointer(cmd, 9, &dw);
2871 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2872 dw[1] = offset;
2873 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2874 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002875 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002876 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002877 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002878 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2879 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002880
Chia-I Wu6032b892014-10-17 14:47:18 +08002881 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002882 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002883 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2884 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2885 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2886 if (meta->samples > 1) {
2887 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2888 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2889 } else {
2890 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2891 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2892 }
2893 dw[7] = 0;
2894 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002895
2896 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002897}
2898
2899static void gen7_meta_ps(struct intel_cmd *cmd)
2900{
2901 const struct intel_cmd_meta *meta = cmd->bind.meta;
2902 const struct intel_pipeline_shader *sh =
2903 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2904 uint32_t offset, *dw;
2905
2906 CMD_ASSERT(cmd, 7, 7.5);
2907
Chia-I Wu29e6f502014-11-24 14:27:29 +08002908 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2909 /* 3DSTATE_WM */
2910 cmd_batch_pointer(cmd, 3, &dw);
2911 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002912
2913 switch (meta->ds.op) {
2914 case INTEL_CMD_META_DS_HIZ_CLEAR:
2915 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2916 break;
2917 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2918 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2919 break;
2920 case INTEL_CMD_META_DS_RESOLVE:
2921 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2922 break;
2923 default:
2924 dw[1] = 0;
2925 break;
2926 }
2927
2928 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002929
2930 /* 3DSTATE_CONSTANT_GS */
2931 cmd_batch_pointer(cmd, 7, &dw);
2932 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2933 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2934
2935 /* 3DSTATE_PS */
2936 cmd_batch_pointer(cmd, 8, &dw);
2937 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2938 dw[1] = 0;
2939 dw[2] = 0;
2940 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002941 /* required to avoid hangs */
2942 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002943 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002944 dw[5] = 0;
2945 dw[6] = 0;
2946 dw[7] = 0;
2947
Chia-I Wu3adf7212014-10-24 15:34:07 +08002948 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002949 }
2950
Chia-I Wu3adf7212014-10-24 15:34:07 +08002951 /* a normal color write */
2952 assert(meta->dst.valid && !sh->uses);
2953
Chia-I Wu6032b892014-10-17 14:47:18 +08002954 /* 3DSTATE_WM */
2955 cmd_batch_pointer(cmd, 3, &dw);
2956 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002957 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002958 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2959 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2960 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2961 dw[2] = 0;
2962
2963 /* 3DSTATE_CONSTANT_PS */
2964 offset = gen6_meta_ps_constants(cmd);
2965 cmd_batch_pointer(cmd, 7, &dw);
2966 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002967 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002968 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002969 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002970 dw[4] = 0;
2971 dw[5] = 0;
2972 dw[6] = 0;
2973
2974 /* 3DSTATE_PS */
2975 offset = emit_shader(cmd, sh);
2976 cmd_batch_pointer(cmd, 8, &dw);
2977 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2978 dw[1] = offset;
2979 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2980 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002981 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002982
2983 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2984 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002985 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002986
2987 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002988 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002989 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002990 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002991 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002992 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002993
2994 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2995 dw[6] = 0;
2996 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002997
2998 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002999}
3000
3001static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3002{
3003 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003004 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003005
3006 CMD_ASSERT(cmd, 6, 7.5);
3007
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003008 if (!ds) {
3009 /* all zeros */
3010 static const struct intel_ds_view null_ds;
3011 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003012 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003013
3014 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003015 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3016 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3017 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003018
3019 if (cmd_gen(cmd) >= INTEL_GEN(7))
3020 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3021 else
3022 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003023}
3024
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003025static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3026 const struct intel_pipeline *pipeline)
3027{
3028 cmd->bind.pipeline.graphics = pipeline;
3029}
3030
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003031static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3032 const struct intel_pipeline *pipeline)
3033{
3034 cmd->bind.pipeline.compute = pipeline;
3035}
3036
Chia-I Wu862c5572015-03-28 15:23:55 +08003037static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3038 struct intel_cmd_dset_data *data,
3039 const struct intel_desc_layout_chain *chain)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003040{
Chia-I Wu862c5572015-03-28 15:23:55 +08003041 if (data->set_offset_count < chain->layout_count) {
3042 if (data->set_offsets)
3043 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003044
Chia-I Wu862c5572015-03-28 15:23:55 +08003045 data->set_offsets = intel_alloc(cmd,
3046 sizeof(data->set_offsets[0]) * chain->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003047 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003048 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003049 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003050 data->set_offset_count = 0;
3051 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003052 }
3053
Chia-I Wu862c5572015-03-28 15:23:55 +08003054 data->set_offset_count = chain->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003055 }
3056
Chia-I Wu862c5572015-03-28 15:23:55 +08003057 if (data->dynamic_offset_count < chain->total_dynamic_desc_count) {
3058 if (data->dynamic_offsets)
3059 intel_free(cmd, data->dynamic_offsets);
3060
3061 data->dynamic_offsets = intel_alloc(cmd,
3062 sizeof(data->dynamic_offsets[0]) * chain->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003063 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003064 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003065 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003066 data->dynamic_offset_count = 0;
3067 return false;
3068 }
3069
3070 data->dynamic_offset_count = chain->total_dynamic_desc_count;
3071 }
3072
3073 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003074}
3075
Chia-I Wu862c5572015-03-28 15:23:55 +08003076static void cmd_copy_dset_data(struct intel_cmd *cmd,
3077 struct intel_cmd_dset_data *data,
3078 const struct intel_desc_layout_chain *chain,
3079 uint32_t index,
3080 const struct intel_desc_set *set,
3081 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003082{
Chia-I Wu862c5572015-03-28 15:23:55 +08003083 const struct intel_desc_layout *layout = chain->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003084
Chia-I Wu862c5572015-03-28 15:23:55 +08003085 assert(index < data->set_offset_count);
3086 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003087
Chia-I Wu862c5572015-03-28 15:23:55 +08003088 if (layout->dynamic_desc_count) {
3089 assert(chain->dynamic_desc_indices[index] +
3090 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003091
Chia-I Wu862c5572015-03-28 15:23:55 +08003092 memcpy(&data->dynamic_offsets[chain->dynamic_desc_indices[index]],
3093 dynamic_offsets,
3094 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003095 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003096}
3097
Chia-I Wu3b04af52014-11-08 10:48:20 +08003098static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003099 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003100 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003101{
Chia-I Wu714df452015-01-01 07:55:04 +08003102 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003103 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003104 return;
3105 }
3106
Chia-I Wu714df452015-01-01 07:55:04 +08003107 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003108 cmd->bind.vertex.offset[binding] = offset;
3109}
3110
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003111static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003112 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003113 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114{
Chia-I Wu714df452015-01-01 07:55:04 +08003115 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003116 cmd->bind.index.offset = offset;
3117 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003118}
3119
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003120static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003121 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003122{
3123 cmd->bind.state.viewport = state;
3124}
3125
3126static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003127 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003128{
3129 cmd->bind.state.raster = state;
3130}
3131
3132static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003133 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003134{
3135 cmd->bind.state.ds = state;
3136}
3137
3138static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003139 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003140{
3141 cmd->bind.state.blend = state;
3142}
3143
Chia-I Wuf98dd882015-02-10 04:17:47 +08003144static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3145{
3146 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3147 struct intel_pipeline_rmap *rmaps[5] = {
3148 pipeline->vs.rmap,
3149 pipeline->tcs.rmap,
3150 pipeline->tes.rmap,
3151 pipeline->gs.rmap,
3152 pipeline->fs.rmap,
3153 };
3154 uint32_t max_write;
3155 int i;
3156
3157 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3158 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3159 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3160
3161 /* pad first */
3162 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3163
3164 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3165 const struct intel_pipeline_rmap *rmap = rmaps[i];
3166 const uint32_t surface_count = (rmap) ?
3167 rmap->rt_count + rmap->texture_resource_count +
3168 rmap->resource_count + rmap->uav_count : 0;
3169
3170 if (surface_count) {
3171 /* SURFACE_STATEs */
3172 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3173
3174 /* BINDING_TABLE_STATE */
3175 max_write += u_align(sizeof(uint32_t) * surface_count,
3176 GEN6_ALIGNMENT_SURFACE_STATE);
3177 }
3178 }
3179
3180 return max_write;
3181}
3182
3183static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3184{
3185 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3186 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3187 uint32_t max_surface_write;
3188
3189 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3190 if (cmd->bind.meta)
3191 max_surface_write = 64 * sizeof(uint32_t);
3192 else
3193 max_surface_write = cmd_get_max_surface_write(cmd);
3194
3195 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3196 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3197 /* SBA expects page-aligned addresses */
3198 writer->sba_offset = writer->used & ~0xfff;
3199
3200 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3201
3202 cmd_batch_state_base_address(cmd);
3203 }
3204}
3205
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003207 uint32_t vertex_start,
3208 uint32_t vertex_count,
3209 uint32_t instance_start,
3210 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003212 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213{
3214 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003215 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003216 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3217
3218 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003219
3220 emit_bounded_states(cmd);
3221
Chia-I Wuf98dd882015-02-10 04:17:47 +08003222 /* sanity check on cmd_get_max_surface_write() */
3223 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3224 surface_writer_used <= cmd_get_max_surface_write(cmd));
3225
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003226 if (indexed) {
3227 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003228 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003229
3230 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3231 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3232 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003233 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003234 cmd->bind.index.offset, cmd->bind.index.type,
3235 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003236 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003237 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003238 cmd->bind.index.offset, cmd->bind.index.type,
3239 p->primitive_restart);
3240 }
3241 } else {
3242 assert(!vertex_base);
3243 }
3244
3245 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3246 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3247 vertex_start, instance_count, instance_start, vertex_base);
3248 } else {
3249 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3250 vertex_start, instance_count, instance_start, vertex_base);
3251 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003252
Chia-I Wu707a29e2014-08-27 12:51:47 +08003253 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003254 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003255 /* need to re-emit all workarounds */
3256 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003257
3258 if (intel_debug & INTEL_DEBUG_NOCACHE)
3259 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003260}
3261
Chia-I Wuc14d1562014-10-17 09:49:22 +08003262void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3263{
Chia-I Wu6032b892014-10-17 14:47:18 +08003264 cmd->bind.meta = meta;
3265
Chia-I Wuf98dd882015-02-10 04:17:47 +08003266 cmd_adjust_state_base_address(cmd);
3267
Chia-I Wu6032b892014-10-17 14:47:18 +08003268 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003269 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003270
3271 gen6_meta_dynamic_states(cmd);
3272 gen6_meta_surface_states(cmd);
3273
3274 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3275 gen7_meta_urb(cmd);
3276 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003277 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003278 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003279 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003280 gen6_meta_wm(cmd);
3281 gen7_meta_ps(cmd);
3282 gen6_meta_depth_buffer(cmd);
3283
3284 cmd_wa_gen7_post_command_cs_stall(cmd);
3285 cmd_wa_gen7_post_command_depth_stall(cmd);
3286
Chia-I Wu29e6f502014-11-24 14:27:29 +08003287 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3288 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003289 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003290 } else {
3291 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3292 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003293 } else {
3294 gen6_meta_urb(cmd);
3295 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003296 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003297 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003298 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003299 gen6_meta_wm(cmd);
3300 gen6_meta_ps(cmd);
3301 gen6_meta_depth_buffer(cmd);
3302
Chia-I Wu29e6f502014-11-24 14:27:29 +08003303 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3304 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003305 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003306 } else {
3307 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3308 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003309 }
3310
3311 cmd->bind.draw_count++;
3312 /* need to re-emit all workarounds */
3313 cmd->bind.wa_flags = 0;
3314
3315 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003316
Chia-I Wubbc7d912015-02-27 14:59:50 -07003317 /* make the normal path believe the render pass has changed */
3318 cmd->bind.render_pass_changed = true;
3319
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003320 if (intel_debug & INTEL_DEBUG_NOCACHE)
3321 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003322}
3323
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003324ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003325 VkCmdBuffer cmdBuffer,
3326 VkPipelineBindPoint pipelineBindPoint,
3327 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003328{
3329 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3330
3331 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003332 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003333 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003334 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003335 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003336 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003337 break;
3338 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003339 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003340 break;
3341 }
3342}
3343
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003344ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003345 VkCmdBuffer cmdBuffer,
3346 VkStateBindPoint stateBindPoint,
3347 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003348{
3349 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3350
3351 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003352 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003353 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003354 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003355 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003356 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003357 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003358 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003359 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003360 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003361 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003362 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003363 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003364 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003365 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003366 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003367 break;
3368 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003369 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003370 break;
3371 }
3372}
3373
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003374ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003375 VkCmdBuffer cmdBuffer,
3376 VkPipelineBindPoint pipelineBindPoint,
3377 VkDescriptorSetLayoutChain layoutChain,
Chia-I Wu862c5572015-03-28 15:23:55 +08003378 uint32_t layoutChainSlot,
3379 uint32_t count,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003380 const VkDescriptorSet* pDescriptorSets,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003381 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003382{
3383 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu862c5572015-03-28 15:23:55 +08003384 struct intel_desc_layout_chain *chain =
3385 intel_desc_layout_chain(layoutChain);
3386 struct intel_cmd_dset_data *data;
3387 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003388
3389 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003390 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003391 cmd->bind.dset.compute = chain;
3392 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003393 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003394 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003395 cmd->bind.dset.graphics = chain;
3396 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003397 break;
3398 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003399 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003400 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003401 break;
3402 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003403
3404 if (!cmd_alloc_dset_data(cmd, data, chain))
3405 return;
3406
3407 for (i = 0; i < count; i++) {
3408 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3409
3410 cmd_copy_dset_data(cmd, data, chain, layoutChainSlot + i,
3411 dset, pUserData);
3412 pUserData += chain->layouts[layoutChainSlot + i]->dynamic_desc_count;
3413 }
Chia-I Wub2755562014-08-20 13:38:52 +08003414}
3415
Tony Barbour8205d902015-04-16 15:59:00 -06003416
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003417ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3418 VkCmdBuffer cmdBuffer,
3419 uint32_t startBinding,
3420 uint32_t bindingCount,
3421 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003422 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003423{
3424 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003425
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003426 for (uint32_t i = 0; i < bindingCount; i++) {
3427 struct intel_buf *buf = intel_buf(pBuffers[i]);
3428 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3429 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003430}
3431
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003432ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003433 VkCmdBuffer cmdBuffer,
3434 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003435 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003436 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003437{
3438 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003439 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003440
Chia-I Wu714df452015-01-01 07:55:04 +08003441 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003442}
3443
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003444ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003445 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003446 uint32_t firstVertex,
3447 uint32_t vertexCount,
3448 uint32_t firstInstance,
3449 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003450{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003451 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003452
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003453 cmd_draw(cmd, firstVertex, vertexCount,
3454 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003455}
3456
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003457ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003458 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003459 uint32_t firstIndex,
3460 uint32_t indexCount,
3461 int32_t vertexOffset,
3462 uint32_t firstInstance,
3463 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003464{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003465 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003466
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003467 cmd_draw(cmd, firstIndex, indexCount,
3468 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003469}
3470
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003471ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003472 VkCmdBuffer cmdBuffer,
3473 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003474 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003475 uint32_t count,
3476 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003477{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003478 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3479
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003480 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003481}
3482
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003483ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003484 VkCmdBuffer cmdBuffer,
3485 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003486 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003487 uint32_t count,
3488 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003489{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003490 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3491
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003492 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003493}
3494
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003495ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003496 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003497 uint32_t x,
3498 uint32_t y,
3499 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003500{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003501 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3502
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003503 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003504}
3505
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003506ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003507 VkCmdBuffer cmdBuffer,
3508 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003509 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003510{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003511 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3512
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003513 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003514}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003515
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003516ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003517 VkCmdBuffer cmdBuffer,
3518 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003519{
3520 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3521
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003522 cmd_begin_render_pass(cmd, (struct intel_render_pass *) pRenderPassBegin->renderPass, pRenderPassBegin->framebuffer);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003523}
3524
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003525ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003526 VkCmdBuffer cmdBuffer,
3527 VkRenderPass renderPass)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003528{
3529 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3530
3531 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3532}