blob: 3005b5c3f70b86bbbc3945e9e69fe1c9784b1fff [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 {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001686 const struct intel_pipeline_layout *pipeline_layout =
1687 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001688 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001689 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001690 const struct intel_mem *mem;
1691 bool read_only;
1692 const uint32_t *cmd_data;
1693 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001694
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001695 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001696 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001697
Chia-I Wu862c5572015-03-28 15:23:55 +08001698 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1699 &data->set_offsets[slot->index]);
1700
1701 intel_desc_region_read_surface(region, &desc_offset, stage,
1702 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001703 if (mem) {
1704 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001705 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001706 const uint32_t reloc_flags =
1707 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001708
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001709 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001710 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001711 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001712
1713 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001714 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1715 cmd_data[1] + dynamic_offset, reloc_flags);
1716 } else {
1717 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001718 }
1719 }
1720 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001721 case INTEL_PIPELINE_RMAP_UNUSED:
1722 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001723 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001724 default:
1725 assert(!"unexpected rmap type");
1726 need_null_view = true;
1727 break;
1728 }
1729
1730 if (need_null_view) {
1731 intel_null_view_init(&null_view, cmd->dev);
1732 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1733 GEN6_ALIGNMENT_SURFACE_STATE,
1734 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001735 }
1736
Chia-I Wuf98dd882015-02-10 04:17:47 +08001737 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001738 }
1739
Chia-I Wuf98dd882015-02-10 04:17:47 +08001740 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001741 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001742 surface_count, binding_table) - sba_offset;
1743
1744 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1745 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1746
1747 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001748}
1749
Chia-I Wu1d125092014-10-08 08:49:38 +08001750static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1751{
1752 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001753 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1754 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001755 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001756
1757 CMD_ASSERT(cmd, 6, 7.5);
1758
1759 if (!pipeline->vb_count)
1760 return;
1761
1762 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1763
1764 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1765 dw++;
1766 pos++;
1767
1768 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001769 assert(pipeline->vb[i].strideInBytes <= 2048);
1770
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001771 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001772 pipeline->vb[i].strideInBytes;
1773
Chia-I Wub3686982015-02-27 09:51:16 -07001774 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001775 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1776 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001777 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001778
1779 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001780 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001781 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001782 dw[3] = 0;
1783 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001784 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001785 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001786 dw[3] = 1;
1787 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001788 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001789 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001790 dw[3] = 0;
1791 break;
1792 default:
1793 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001794 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001795 dw[3] = 0;
1796 break;
1797 }
1798
Chia-I Wu714df452015-01-01 07:55:04 +08001799 if (cmd->bind.vertex.buf[i]) {
1800 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001801 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001802
1803 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001804 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1805 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001806 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001807 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001808 dw[1] = 0;
1809 dw[2] = 0;
1810 }
1811
1812 dw += 4;
1813 pos += 4;
1814 }
1815}
1816
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001817static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1818{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001819 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1820 const struct intel_pipeline_shader *vs = &pipeline->vs;
1821 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001822 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001823 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001824 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001825 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001826
1827 CMD_ASSERT(cmd, 6, 7.5);
1828
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001829 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001830 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1831 *
1832 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1833 * 128-bit vertex elements to be passed into the payload for each
1834 * vertex."
1835 *
1836 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1837 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001838 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001839 vue_read_len = (vs->in_count + 1) / 2;
1840 if (!vue_read_len)
1841 vue_read_len = 1;
1842
1843 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1844 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1845
1846 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1847 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1848 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001849
1850 dw5 = GEN6_VS_DW5_STATISTICS |
1851 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001852
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001853 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001854 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001855 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001856 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001857
Chia-I Wube0a3d92014-09-02 13:20:59 +08001858 if (pipeline->disable_vs_cache)
1859 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1860
Chia-I Wu784d3042014-12-19 14:30:04 +08001861 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001862 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001863 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001864 dw[2] = dw2;
1865 dw[3] = 0; /* scratch */
1866 dw[4] = dw4;
1867 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001868
1869 if (vs->per_thread_scratch_size)
1870 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001871}
1872
Chia-I Wu625105f2014-10-13 15:35:29 +08001873static void emit_shader_resources(struct intel_cmd *cmd)
1874{
1875 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001876 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001877
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001878 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001879 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001880 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001881 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001882 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001883 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001884 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001885 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001887 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001888 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001889 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001890 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001891 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001892 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001893
1894 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1895 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1896 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1897 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1898 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1899
1900 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1901 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001902 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1903 binding_tables[0]);
1904 gen7_3dstate_pointer(cmd,
1905 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1906 binding_tables[1]);
1907 gen7_3dstate_pointer(cmd,
1908 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1909 binding_tables[2]);
1910 gen7_3dstate_pointer(cmd,
1911 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1912 binding_tables[3]);
1913 gen7_3dstate_pointer(cmd,
1914 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1915 binding_tables[4]);
1916
1917 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001918 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1919 samplers[0]);
1920 gen7_3dstate_pointer(cmd,
1921 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1922 samplers[1]);
1923 gen7_3dstate_pointer(cmd,
1924 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1925 samplers[2]);
1926 gen7_3dstate_pointer(cmd,
1927 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1928 samplers[3]);
1929 gen7_3dstate_pointer(cmd,
1930 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1931 samplers[4]);
1932 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001933 assert(!binding_tables[1] && !binding_tables[2]);
1934 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1935 binding_tables[0], binding_tables[3], binding_tables[4]);
1936
Chia-I Wu625105f2014-10-13 15:35:29 +08001937 assert(!samplers[1] && !samplers[2]);
1938 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1939 samplers[0], samplers[3], samplers[4]);
1940 }
1941}
1942
Chia-I Wu8ada4242015-03-02 11:19:33 -07001943static void emit_msaa(struct intel_cmd *cmd)
1944{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001945 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001946
Chia-I Wubbc7d912015-02-27 14:59:50 -07001947 if (!cmd->bind.render_pass_changed)
1948 return;
1949
Chia-I Wu8ada4242015-03-02 11:19:33 -07001950 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001952
1953 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1954 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1955}
1956
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001957static void emit_rt(struct intel_cmd *cmd)
1958{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001959 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07001960
1961 if (!cmd->bind.render_pass_changed)
1962 return;
1963
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001964 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001965 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
1966 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001967}
1968
1969static void emit_ds(struct intel_cmd *cmd)
1970{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001971 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07001972 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001973
Chia-I Wubbc7d912015-02-27 14:59:50 -07001974 if (!cmd->bind.render_pass_changed)
1975 return;
1976
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001977 if (!ds) {
1978 /* all zeros */
1979 static const struct intel_ds_view null_ds;
1980 ds = &null_ds;
1981 }
1982
1983 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001984 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1985 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1986 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001987
1988 if (cmd_gen(cmd) >= INTEL_GEN(7))
1989 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1990 else
1991 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1992}
1993
Chia-I Wua57761b2014-10-14 14:27:44 +08001994static uint32_t emit_shader(struct intel_cmd *cmd,
1995 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001996{
Chia-I Wua57761b2014-10-14 14:27:44 +08001997 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1998 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001999 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002000
Chia-I Wua57761b2014-10-14 14:27:44 +08002001 /* see if the shader is already in the cache */
2002 for (i = 0; i < cache->used; i++) {
2003 if (cache->entries[i].shader == (const void *) shader)
2004 return cache->entries[i].kernel_offset;
2005 }
2006
2007 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2008
2009 /* grow the cache if full */
2010 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002011 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002012 void *entries;
2013
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002014 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002015 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002016 if (entries) {
2017 if (cache->entries) {
2018 memcpy(entries, cache->entries,
2019 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002020 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002021 }
2022
2023 cache->entries = entries;
2024 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002025 }
2026 }
2027
Chia-I Wua57761b2014-10-14 14:27:44 +08002028 /* add the shader to the cache */
2029 if (cache->used < cache->count) {
2030 cache->entries[cache->used].shader = (const void *) shader;
2031 cache->entries[cache->used].kernel_offset = offset;
2032 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002033 }
2034
Chia-I Wua57761b2014-10-14 14:27:44 +08002035 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002036}
2037
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002038static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002039{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002040 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002041
Chia-I Wu8370b402014-08-29 12:28:37 +08002042 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2043 cmd_wa_gen6_pre_depth_stall_write(cmd);
2044 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2045 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2046 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2047 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002048
2049 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002050 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002051 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002052
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002053 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002054 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002055 }
2056 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002057 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002058 }
2059 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002060 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2061 }
2062 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2063 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2064 }
2065 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2066 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002067 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002068
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002069 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2070 gen7_3DSTATE_GS(cmd);
2071 } else {
2072 gen6_3DSTATE_GS(cmd);
2073 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002074
Chia-I Wu8370b402014-08-29 12:28:37 +08002075 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2076 cmd_wa_gen7_post_command_cs_stall(cmd);
2077 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2078 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002079}
2080
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002081static void emit_bounded_states(struct intel_cmd *cmd)
2082{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002083 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002084
2085 emit_graphics_pipeline(cmd);
2086
2087 emit_rt(cmd);
2088 emit_ds(cmd);
2089
2090 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2091 gen7_cc_states(cmd);
2092 gen7_viewport_states(cmd);
2093
2094 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2095 &cmd->bind.pipeline.graphics->vs);
2096 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2097 &cmd->bind.pipeline.graphics->fs);
2098
2099 gen6_3DSTATE_CLIP(cmd);
2100 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002101 gen7_3DSTATE_WM(cmd);
2102 gen7_3DSTATE_PS(cmd);
2103 } else {
2104 gen6_cc_states(cmd);
2105 gen6_viewport_states(cmd);
2106
2107 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2108 &cmd->bind.pipeline.graphics->vs);
2109 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2110 &cmd->bind.pipeline.graphics->fs);
2111
2112 gen6_3DSTATE_CLIP(cmd);
2113 gen6_3DSTATE_SF(cmd);
2114 gen6_3DSTATE_WM(cmd);
2115 }
2116
2117 emit_shader_resources(cmd);
2118
2119 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002120
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002121 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2122 gen6_3DSTATE_VS(cmd);
2123}
2124
Tony Barbourfa6cac72015-01-16 14:27:35 -07002125static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002126 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002127{
2128 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2129 const uint8_t cmd_len = 3;
2130 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002131
2132 CMD_ASSERT(cmd, 6, 7.5);
2133
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002134 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002135 dw[0] = 0;
2136 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002137
2138 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2139 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2140 GEN6_COMPAREFUNCTION_NEVER << 27 |
2141 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2142 } else {
2143 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2144 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2145 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002146 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002147 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002148 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2149 (GEN6_STENCILOP_KEEP) << 25 |
2150 (GEN6_STENCILOP_KEEP) << 22 |
2151 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002152 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2153 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002154 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2155 (GEN6_STENCILOP_KEEP) << 9 |
2156 (GEN6_STENCILOP_KEEP) << 6 |
2157 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002158
Chia-I Wud850a392015-02-19 11:08:25 -07002159 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2160 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2161 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2162 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2163 dw[2] = 0;
2164 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002165
2166 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2167 cmd_align, cmd_len, dw);
2168}
2169
Chia-I Wu6032b892014-10-17 14:47:18 +08002170static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2171{
2172 const struct intel_cmd_meta *meta = cmd->bind.meta;
2173 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2174
2175 CMD_ASSERT(cmd, 6, 7.5);
2176
2177 blend_offset = 0;
2178 ds_offset = 0;
2179 cc_offset = 0;
2180 cc_vp_offset = 0;
2181
Chia-I Wu29e6f502014-11-24 14:27:29 +08002182 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002183 /* BLEND_STATE */
2184 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002185 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002186 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002187 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002188 }
2189
Chia-I Wu29e6f502014-11-24 14:27:29 +08002190 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002191 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002192 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002193 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2194 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002195
Chia-I Wu29e6f502014-11-24 14:27:29 +08002196 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002197 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002198
Chia-I Wu29e6f502014-11-24 14:27:29 +08002199 /* COLOR_CALC_STATE */
2200 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002201 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002202
Chia-I Wu29e6f502014-11-24 14:27:29 +08002203 /* CC_VIEWPORT */
2204 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002205 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002206 dw[0] = u_fui(0.0f);
2207 dw[1] = u_fui(1.0f);
2208 } else {
2209 /* DEPTH_STENCIL_STATE */
2210 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002211 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002212 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2213 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2214 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002215 }
2216
2217 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2218 gen7_3dstate_pointer(cmd,
2219 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2220 blend_offset);
2221 gen7_3dstate_pointer(cmd,
2222 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2223 ds_offset);
2224 gen7_3dstate_pointer(cmd,
2225 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2226
2227 gen7_3dstate_pointer(cmd,
2228 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2229 cc_vp_offset);
2230 } else {
2231 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002232 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002233
2234 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2235 cmd_batch_pointer(cmd, 4, &dw);
2236 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002237 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002238 dw[1] = 0;
2239 dw[2] = 0;
2240 dw[3] = cc_vp_offset;
2241 }
2242}
2243
2244static void gen6_meta_surface_states(struct intel_cmd *cmd)
2245{
2246 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002247 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002248 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002249 const uint32_t sba_offset =
2250 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002251
2252 CMD_ASSERT(cmd, 6, 7.5);
2253
Chia-I Wu29e6f502014-11-24 14:27:29 +08002254 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2255 return;
2256
Chia-I Wu005c47c2014-10-22 13:49:13 +08002257 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002258 if (meta->src.valid) {
2259 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002260 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002261 meta->src.surface_len, meta->src.surface);
2262
2263 cmd_reserve_reloc(cmd, 1);
2264 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2265 cmd_surface_reloc_writer(cmd, offset, 1,
2266 meta->src.reloc_target, meta->src.reloc_offset);
2267 } else {
2268 cmd_surface_reloc(cmd, offset, 1,
2269 (struct intel_bo *) meta->src.reloc_target,
2270 meta->src.reloc_offset, meta->src.reloc_flags);
2271 }
2272
Mike Stroyan9bfad482015-02-10 15:09:23 -07002273 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002274 }
2275 if (meta->dst.valid) {
2276 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002277 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002278 meta->dst.surface_len, meta->dst.surface);
2279
2280 cmd_reserve_reloc(cmd, 1);
2281 cmd_surface_reloc(cmd, offset, 1,
2282 (struct intel_bo *) meta->dst.reloc_target,
2283 meta->dst.reloc_offset, meta->dst.reloc_flags);
2284
Mike Stroyan9bfad482015-02-10 15:09:23 -07002285 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002286 }
2287
2288 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002289 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002290 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002291 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002292
2293 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002294 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2295 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2296 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002297 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002298 } else {
2299 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002300 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002301 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002302 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002303 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002304 }
2305}
2306
2307static void gen6_meta_urb(struct intel_cmd *cmd)
2308{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002309 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002310 uint32_t *dw;
2311
2312 CMD_ASSERT(cmd, 6, 6);
2313
2314 /* 3DSTATE_URB */
2315 cmd_batch_pointer(cmd, 3, &dw);
2316 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002317 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002318 dw[2] = 0;
2319}
2320
2321static void gen7_meta_urb(struct intel_cmd *cmd)
2322{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002323 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2324 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002325 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 uint32_t *dw;
2327
2328 CMD_ASSERT(cmd, 7, 7.5);
2329
Chia-I Wu6032b892014-10-17 14:47:18 +08002330 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2331
Chia-I Wu24aa1022014-11-25 11:53:19 +08002332 switch (cmd_gen(cmd)) {
2333 case INTEL_GEN(7.5):
2334 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2335 break;
2336 case INTEL_GEN(7):
2337 default:
2338 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2339 break;
2340 }
2341
Chia-I Wu6032b892014-10-17 14:47:18 +08002342 /* 3DSTATE_URB_x */
2343 cmd_batch_pointer(cmd, 8, &dw);
2344
2345 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002346 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002347 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 dw += 2;
2349
2350 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002351 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002352 dw += 2;
2353
2354 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002355 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002356 dw += 2;
2357
2358 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002359 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002360 dw += 2;
2361}
2362
2363static void gen6_meta_vf(struct intel_cmd *cmd)
2364{
2365 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002366 uint32_t vb_start, vb_end, vb_stride;
2367 int ve_format, ve_z_source;
2368 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002369 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002370
2371 CMD_ASSERT(cmd, 6, 7.5);
2372
Chia-I Wu29e6f502014-11-24 14:27:29 +08002373 switch (meta->mode) {
2374 case INTEL_CMD_META_VS_POINTS:
2375 cmd_batch_pointer(cmd, 3, &dw);
2376 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002377 dw[1] = GEN6_VE_DW0_VALID;
2378 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2379 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2380 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2381 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002382 return;
2383 break;
2384 case INTEL_CMD_META_FS_RECT:
2385 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002386 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002387
Chia-I Wu29e6f502014-11-24 14:27:29 +08002388 vertices[0][0] = meta->dst.x + meta->width;
2389 vertices[0][1] = meta->dst.y + meta->height;
2390 vertices[1][0] = meta->dst.x;
2391 vertices[1][1] = meta->dst.y + meta->height;
2392 vertices[2][0] = meta->dst.x;
2393 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002394
Chia-I Wu29e6f502014-11-24 14:27:29 +08002395 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2396 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002397
Chia-I Wu29e6f502014-11-24 14:27:29 +08002398 vb_end = vb_start + sizeof(vertices) - 1;
2399 vb_stride = sizeof(vertices[0]);
2400 ve_z_source = GEN6_VFCOMP_STORE_0;
2401 ve_format = GEN6_FORMAT_R32G32_USCALED;
2402 }
2403 break;
2404 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2405 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002406 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002407
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002408 vertices[0][0] = (float) (meta->dst.x + meta->width);
2409 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002410 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002411 vertices[1][0] = (float) meta->dst.x;
2412 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002413 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002414 vertices[2][0] = (float) meta->dst.x;
2415 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002416 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002417
Chia-I Wu29e6f502014-11-24 14:27:29 +08002418 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2419 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002420
Chia-I Wu29e6f502014-11-24 14:27:29 +08002421 vb_end = vb_start + sizeof(vertices) - 1;
2422 vb_stride = sizeof(vertices[0]);
2423 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2424 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2425 }
2426 break;
2427 default:
2428 assert(!"unknown meta mode");
2429 return;
2430 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002431 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002432
2433 /* 3DSTATE_VERTEX_BUFFERS */
2434 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002435
Chia-I Wu6032b892014-10-17 14:47:18 +08002436 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002437 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002438 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002439 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002440
2441 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002442 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2443 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002444
2445 dw[4] = 0;
2446
2447 /* 3DSTATE_VERTEX_ELEMENTS */
2448 cmd_batch_pointer(cmd, 5, &dw);
2449 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002450 dw[1] = GEN6_VE_DW0_VALID;
2451 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2452 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2453 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2454 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2455 dw[3] = GEN6_VE_DW0_VALID |
2456 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2457 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2458 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2459 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2460 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002461}
2462
Chia-I Wu29e6f502014-11-24 14:27:29 +08002463static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002464{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002465 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002466 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002467 uint32_t consts[8];
2468 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002469
2470 CMD_ASSERT(cmd, 6, 7.5);
2471
2472 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002473 case INTEL_DEV_META_VS_FILL_MEM:
2474 consts[0] = meta->dst.x;
2475 consts[1] = meta->clear_val[0];
2476 const_count = 2;
2477 break;
2478 case INTEL_DEV_META_VS_COPY_MEM:
2479 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2480 consts[0] = meta->dst.x;
2481 consts[1] = meta->src.x;
2482 const_count = 2;
2483 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002484 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2485 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2486 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2487 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2488 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2489 consts[0] = meta->src.x;
2490 consts[1] = meta->src.y;
2491 consts[2] = meta->width;
2492 consts[3] = meta->dst.x;
2493 const_count = 4;
2494 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002495 default:
2496 assert(!"unknown meta shader id");
2497 const_count = 0;
2498 break;
2499 }
2500
2501 /* this can be skipped but it makes state dumping prettier */
2502 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2503
2504 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2505}
2506
2507static void gen6_meta_vs(struct intel_cmd *cmd)
2508{
2509 const struct intel_cmd_meta *meta = cmd->bind.meta;
2510 const struct intel_pipeline_shader *sh =
2511 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2512 uint32_t offset, *dw;
2513
2514 CMD_ASSERT(cmd, 6, 7.5);
2515
2516 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002517 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002518
2519 /* 3DSTATE_CONSTANT_VS */
2520 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2521 cmd_batch_pointer(cmd, cmd_len, &dw);
2522 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2523 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2524
2525 /* 3DSTATE_VS */
2526 cmd_batch_pointer(cmd, 6, &dw);
2527 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2528 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2529
2530 return;
2531 }
2532
2533 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2534
2535 /* 3DSTATE_CONSTANT_VS */
2536 offset = gen6_meta_vs_constants(cmd);
2537 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2538 cmd_batch_pointer(cmd, 7, &dw);
2539 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002540 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002541 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002542 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002543 dw[4] = 0;
2544 dw[5] = 0;
2545 dw[6] = 0;
2546 } else {
2547 cmd_batch_pointer(cmd, 5, &dw);
2548 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002549 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002550 dw[1] = offset;
2551 dw[2] = 0;
2552 dw[3] = 0;
2553 dw[4] = 0;
2554 }
2555
2556 /* 3DSTATE_VS */
2557 offset = emit_shader(cmd, sh);
2558 cmd_batch_pointer(cmd, 6, &dw);
2559 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2560 dw[1] = offset;
2561 dw[2] = GEN6_THREADDISP_SPF |
2562 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2563 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002564 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002565 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2566 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2567
2568 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2569 GEN6_VS_DW5_VS_ENABLE;
2570 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002571 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002572 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002573 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002574
2575 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002576}
2577
2578static void gen6_meta_disabled(struct intel_cmd *cmd)
2579{
Chia-I Wu6032b892014-10-17 14:47:18 +08002580 uint32_t *dw;
2581
2582 CMD_ASSERT(cmd, 6, 6);
2583
Chia-I Wu6032b892014-10-17 14:47:18 +08002584 /* 3DSTATE_CONSTANT_GS */
2585 cmd_batch_pointer(cmd, 5, &dw);
2586 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2587 dw[1] = 0;
2588 dw[2] = 0;
2589 dw[3] = 0;
2590 dw[4] = 0;
2591
2592 /* 3DSTATE_GS */
2593 cmd_batch_pointer(cmd, 7, &dw);
2594 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2595 dw[1] = 0;
2596 dw[2] = 0;
2597 dw[3] = 0;
2598 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2599 dw[5] = GEN6_GS_DW5_STATISTICS;
2600 dw[6] = 0;
2601
Chia-I Wu6032b892014-10-17 14:47:18 +08002602 /* 3DSTATE_SF */
2603 cmd_batch_pointer(cmd, 20, &dw);
2604 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2605 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2606 memset(&dw[2], 0, 18 * sizeof(*dw));
2607}
2608
2609static void gen7_meta_disabled(struct intel_cmd *cmd)
2610{
2611 uint32_t *dw;
2612
2613 CMD_ASSERT(cmd, 7, 7.5);
2614
Chia-I Wu6032b892014-10-17 14:47:18 +08002615 /* 3DSTATE_CONSTANT_HS */
2616 cmd_batch_pointer(cmd, 7, &dw);
2617 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2618 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2619
2620 /* 3DSTATE_HS */
2621 cmd_batch_pointer(cmd, 7, &dw);
2622 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2623 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2624
2625 /* 3DSTATE_TE */
2626 cmd_batch_pointer(cmd, 4, &dw);
2627 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2628 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2629
2630 /* 3DSTATE_CONSTANT_DS */
2631 cmd_batch_pointer(cmd, 7, &dw);
2632 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2633 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2634
2635 /* 3DSTATE_DS */
2636 cmd_batch_pointer(cmd, 6, &dw);
2637 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2638 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2639
2640 /* 3DSTATE_CONSTANT_GS */
2641 cmd_batch_pointer(cmd, 7, &dw);
2642 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2643 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2644
2645 /* 3DSTATE_GS */
2646 cmd_batch_pointer(cmd, 7, &dw);
2647 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2648 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2649
2650 /* 3DSTATE_STREAMOUT */
2651 cmd_batch_pointer(cmd, 3, &dw);
2652 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2653 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2654
Chia-I Wu6032b892014-10-17 14:47:18 +08002655 /* 3DSTATE_SF */
2656 cmd_batch_pointer(cmd, 7, &dw);
2657 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2658 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2659
2660 /* 3DSTATE_SBE */
2661 cmd_batch_pointer(cmd, 14, &dw);
2662 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2663 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2664 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002665}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002666
Chia-I Wu29e6f502014-11-24 14:27:29 +08002667static void gen6_meta_clip(struct intel_cmd *cmd)
2668{
2669 const struct intel_cmd_meta *meta = cmd->bind.meta;
2670 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002671
Chia-I Wu29e6f502014-11-24 14:27:29 +08002672 /* 3DSTATE_CLIP */
2673 cmd_batch_pointer(cmd, 4, &dw);
2674 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2675 dw[1] = 0;
2676 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2677 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2678 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2679 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002680 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002681 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002682 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002683}
2684
2685static void gen6_meta_wm(struct intel_cmd *cmd)
2686{
2687 const struct intel_cmd_meta *meta = cmd->bind.meta;
2688 uint32_t *dw;
2689
2690 CMD_ASSERT(cmd, 6, 7.5);
2691
2692 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2693
2694 /* 3DSTATE_MULTISAMPLE */
2695 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2696 cmd_batch_pointer(cmd, 4, &dw);
2697 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2698 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2699 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2700 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2701 dw[2] = 0;
2702 dw[3] = 0;
2703 } else {
2704 cmd_batch_pointer(cmd, 3, &dw);
2705 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2706 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2707 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2708 dw[2] = 0;
2709 }
2710
2711 /* 3DSTATE_SAMPLE_MASK */
2712 cmd_batch_pointer(cmd, 2, &dw);
2713 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2714 dw[1] = (1 << meta->samples) - 1;
2715
2716 /* 3DSTATE_DRAWING_RECTANGLE */
2717 cmd_batch_pointer(cmd, 4, &dw);
2718 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002719 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2720 /* unused */
2721 dw[1] = 0;
2722 dw[2] = 0;
2723 } else {
2724 dw[1] = meta->dst.y << 16 | meta->dst.x;
2725 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2726 (meta->dst.x + meta->width - 1);
2727 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002728 dw[3] = 0;
2729}
2730
2731static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2732{
2733 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002734 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002735 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002736 uint32_t consts[8];
2737 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002738
2739 CMD_ASSERT(cmd, 6, 7.5);
2740
2741 /* underflow is fine here */
2742 offset_x = meta->src.x - meta->dst.x;
2743 offset_y = meta->src.y - meta->dst.y;
2744
2745 switch (meta->shader_id) {
2746 case INTEL_DEV_META_FS_COPY_MEM:
2747 case INTEL_DEV_META_FS_COPY_1D:
2748 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2749 case INTEL_DEV_META_FS_COPY_2D:
2750 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2751 case INTEL_DEV_META_FS_COPY_2D_MS:
2752 consts[0] = offset_x;
2753 consts[1] = offset_y;
2754 consts[2] = meta->src.layer;
2755 consts[3] = meta->src.lod;
2756 const_count = 4;
2757 break;
2758 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2759 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2760 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2761 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2762 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2763 consts[0] = offset_x;
2764 consts[1] = offset_y;
2765 consts[2] = meta->src.layer;
2766 consts[3] = meta->src.lod;
2767 consts[4] = meta->src.x;
2768 consts[5] = meta->width;
2769 const_count = 6;
2770 break;
2771 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2772 consts[0] = offset_x;
2773 consts[1] = offset_y;
2774 consts[2] = meta->width;
2775 const_count = 3;
2776 break;
2777 case INTEL_DEV_META_FS_CLEAR_COLOR:
2778 consts[0] = meta->clear_val[0];
2779 consts[1] = meta->clear_val[1];
2780 consts[2] = meta->clear_val[2];
2781 consts[3] = meta->clear_val[3];
2782 const_count = 4;
2783 break;
2784 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2785 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002786 consts[1] = meta->clear_val[1];
2787 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002788 break;
2789 case INTEL_DEV_META_FS_RESOLVE_2X:
2790 case INTEL_DEV_META_FS_RESOLVE_4X:
2791 case INTEL_DEV_META_FS_RESOLVE_8X:
2792 case INTEL_DEV_META_FS_RESOLVE_16X:
2793 consts[0] = offset_x;
2794 consts[1] = offset_y;
2795 const_count = 2;
2796 break;
2797 default:
2798 assert(!"unknown meta shader id");
2799 const_count = 0;
2800 break;
2801 }
2802
2803 /* this can be skipped but it makes state dumping prettier */
2804 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2805
2806 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2807}
2808
2809static void gen6_meta_ps(struct intel_cmd *cmd)
2810{
2811 const struct intel_cmd_meta *meta = cmd->bind.meta;
2812 const struct intel_pipeline_shader *sh =
2813 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2814 uint32_t offset, *dw;
2815
2816 CMD_ASSERT(cmd, 6, 6);
2817
Chia-I Wu29e6f502014-11-24 14:27:29 +08002818 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2819 /* 3DSTATE_CONSTANT_PS */
2820 cmd_batch_pointer(cmd, 5, &dw);
2821 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2822 dw[1] = 0;
2823 dw[2] = 0;
2824 dw[3] = 0;
2825 dw[4] = 0;
2826
2827 /* 3DSTATE_WM */
2828 cmd_batch_pointer(cmd, 9, &dw);
2829 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2830 dw[1] = 0;
2831 dw[2] = 0;
2832 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002833
2834 switch (meta->ds.op) {
2835 case INTEL_CMD_META_DS_HIZ_CLEAR:
2836 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2837 break;
2838 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2839 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2840 break;
2841 case INTEL_CMD_META_DS_RESOLVE:
2842 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2843 break;
2844 default:
2845 dw[4] = 0;
2846 break;
2847 }
2848
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002849 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002850 dw[6] = 0;
2851 dw[7] = 0;
2852 dw[8] = 0;
2853
Chia-I Wu3adf7212014-10-24 15:34:07 +08002854 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002855 }
2856
Chia-I Wu3adf7212014-10-24 15:34:07 +08002857 /* a normal color write */
2858 assert(meta->dst.valid && !sh->uses);
2859
Chia-I Wu6032b892014-10-17 14:47:18 +08002860 /* 3DSTATE_CONSTANT_PS */
2861 offset = gen6_meta_ps_constants(cmd);
2862 cmd_batch_pointer(cmd, 5, &dw);
2863 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002864 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002865 dw[1] = offset;
2866 dw[2] = 0;
2867 dw[3] = 0;
2868 dw[4] = 0;
2869
2870 /* 3DSTATE_WM */
2871 offset = emit_shader(cmd, sh);
2872 cmd_batch_pointer(cmd, 9, &dw);
2873 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2874 dw[1] = offset;
2875 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2876 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002877 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002878 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002879 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002880 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2881 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002882
Chia-I Wu6032b892014-10-17 14:47:18 +08002883 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002884 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002885 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2886 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2887 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2888 if (meta->samples > 1) {
2889 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2890 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2891 } else {
2892 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2893 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2894 }
2895 dw[7] = 0;
2896 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002897
2898 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002899}
2900
2901static void gen7_meta_ps(struct intel_cmd *cmd)
2902{
2903 const struct intel_cmd_meta *meta = cmd->bind.meta;
2904 const struct intel_pipeline_shader *sh =
2905 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2906 uint32_t offset, *dw;
2907
2908 CMD_ASSERT(cmd, 7, 7.5);
2909
Chia-I Wu29e6f502014-11-24 14:27:29 +08002910 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2911 /* 3DSTATE_WM */
2912 cmd_batch_pointer(cmd, 3, &dw);
2913 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002914
2915 switch (meta->ds.op) {
2916 case INTEL_CMD_META_DS_HIZ_CLEAR:
2917 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2918 break;
2919 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2920 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2921 break;
2922 case INTEL_CMD_META_DS_RESOLVE:
2923 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2924 break;
2925 default:
2926 dw[1] = 0;
2927 break;
2928 }
2929
2930 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002931
2932 /* 3DSTATE_CONSTANT_GS */
2933 cmd_batch_pointer(cmd, 7, &dw);
2934 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2935 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2936
2937 /* 3DSTATE_PS */
2938 cmd_batch_pointer(cmd, 8, &dw);
2939 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2940 dw[1] = 0;
2941 dw[2] = 0;
2942 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002943 /* required to avoid hangs */
2944 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002945 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002946 dw[5] = 0;
2947 dw[6] = 0;
2948 dw[7] = 0;
2949
Chia-I Wu3adf7212014-10-24 15:34:07 +08002950 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002951 }
2952
Chia-I Wu3adf7212014-10-24 15:34:07 +08002953 /* a normal color write */
2954 assert(meta->dst.valid && !sh->uses);
2955
Chia-I Wu6032b892014-10-17 14:47:18 +08002956 /* 3DSTATE_WM */
2957 cmd_batch_pointer(cmd, 3, &dw);
2958 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002959 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002960 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2961 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2962 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2963 dw[2] = 0;
2964
2965 /* 3DSTATE_CONSTANT_PS */
2966 offset = gen6_meta_ps_constants(cmd);
2967 cmd_batch_pointer(cmd, 7, &dw);
2968 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002969 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002970 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002971 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002972 dw[4] = 0;
2973 dw[5] = 0;
2974 dw[6] = 0;
2975
2976 /* 3DSTATE_PS */
2977 offset = emit_shader(cmd, sh);
2978 cmd_batch_pointer(cmd, 8, &dw);
2979 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2980 dw[1] = offset;
2981 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2982 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002983 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002984
2985 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2986 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002987 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002988
2989 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002990 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002991 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002992 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002993 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002994 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002995
2996 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2997 dw[6] = 0;
2998 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002999
3000 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003001}
3002
3003static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3004{
3005 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003006 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003007
3008 CMD_ASSERT(cmd, 6, 7.5);
3009
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003010 if (!ds) {
3011 /* all zeros */
3012 static const struct intel_ds_view null_ds;
3013 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003014 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003015
3016 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003017 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3018 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3019 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003020
3021 if (cmd_gen(cmd) >= INTEL_GEN(7))
3022 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3023 else
3024 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003025}
3026
Chia-I Wu862c5572015-03-28 15:23:55 +08003027static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3028 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003029 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003030{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003031 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003032 if (data->set_offsets)
3033 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003034
Chia-I Wu862c5572015-03-28 15:23:55 +08003035 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003036 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003037 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003038 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003039 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003040 data->set_offset_count = 0;
3041 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003042 }
3043
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003044 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003045 }
3046
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003047 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003048 if (data->dynamic_offsets)
3049 intel_free(cmd, data->dynamic_offsets);
3050
3051 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003052 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003053 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003054 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003055 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003056 data->dynamic_offset_count = 0;
3057 return false;
3058 }
3059
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003060 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003061 }
3062
3063 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003064}
3065
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003066static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3067 const struct intel_pipeline *pipeline)
3068{
3069 cmd->bind.pipeline.graphics = pipeline;
3070
3071 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003072 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003073}
3074
3075static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3076 const struct intel_pipeline *pipeline)
3077{
3078 cmd->bind.pipeline.compute = pipeline;
3079
3080 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003081 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003082}
3083
Chia-I Wu862c5572015-03-28 15:23:55 +08003084static void cmd_copy_dset_data(struct intel_cmd *cmd,
3085 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003086 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003087 uint32_t index,
3088 const struct intel_desc_set *set,
3089 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003090{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003091 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003092
Chia-I Wu862c5572015-03-28 15:23:55 +08003093 assert(index < data->set_offset_count);
3094 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003095
Chia-I Wu862c5572015-03-28 15:23:55 +08003096 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003097 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003098 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003099
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003100 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003101 dynamic_offsets,
3102 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003103 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104}
3105
Chia-I Wu3b04af52014-11-08 10:48:20 +08003106static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003107 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003108 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003109{
Chia-I Wu714df452015-01-01 07:55:04 +08003110 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003111 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003112 return;
3113 }
3114
Chia-I Wu714df452015-01-01 07:55:04 +08003115 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003116 cmd->bind.vertex.offset[binding] = offset;
3117}
3118
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003119static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003120 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003121 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003122{
Chia-I Wu714df452015-01-01 07:55:04 +08003123 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003124 cmd->bind.index.offset = offset;
3125 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003126}
3127
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003128static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003129 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003130{
3131 cmd->bind.state.viewport = state;
3132}
3133
3134static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003135 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003136{
3137 cmd->bind.state.raster = state;
3138}
3139
3140static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003141 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003142{
3143 cmd->bind.state.ds = state;
3144}
3145
3146static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003147 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003148{
3149 cmd->bind.state.blend = state;
3150}
3151
Chia-I Wuf98dd882015-02-10 04:17:47 +08003152static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3153{
3154 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3155 struct intel_pipeline_rmap *rmaps[5] = {
3156 pipeline->vs.rmap,
3157 pipeline->tcs.rmap,
3158 pipeline->tes.rmap,
3159 pipeline->gs.rmap,
3160 pipeline->fs.rmap,
3161 };
3162 uint32_t max_write;
3163 int i;
3164
3165 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3166 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3167 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3168
3169 /* pad first */
3170 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3171
3172 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3173 const struct intel_pipeline_rmap *rmap = rmaps[i];
3174 const uint32_t surface_count = (rmap) ?
3175 rmap->rt_count + rmap->texture_resource_count +
3176 rmap->resource_count + rmap->uav_count : 0;
3177
3178 if (surface_count) {
3179 /* SURFACE_STATEs */
3180 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3181
3182 /* BINDING_TABLE_STATE */
3183 max_write += u_align(sizeof(uint32_t) * surface_count,
3184 GEN6_ALIGNMENT_SURFACE_STATE);
3185 }
3186 }
3187
3188 return max_write;
3189}
3190
3191static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3192{
3193 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3194 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3195 uint32_t max_surface_write;
3196
3197 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3198 if (cmd->bind.meta)
3199 max_surface_write = 64 * sizeof(uint32_t);
3200 else
3201 max_surface_write = cmd_get_max_surface_write(cmd);
3202
3203 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3204 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3205 /* SBA expects page-aligned addresses */
3206 writer->sba_offset = writer->used & ~0xfff;
3207
3208 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3209
3210 cmd_batch_state_base_address(cmd);
3211 }
3212}
3213
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003214static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003215 uint32_t vertex_start,
3216 uint32_t vertex_count,
3217 uint32_t instance_start,
3218 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003219 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003220 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003221{
3222 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003223 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003224 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3225
3226 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003227
3228 emit_bounded_states(cmd);
3229
Chia-I Wuf98dd882015-02-10 04:17:47 +08003230 /* sanity check on cmd_get_max_surface_write() */
3231 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3232 surface_writer_used <= cmd_get_max_surface_write(cmd));
3233
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003234 if (indexed) {
3235 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003236 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237
3238 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3239 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3240 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003241 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003242 cmd->bind.index.offset, cmd->bind.index.type,
3243 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003244 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003245 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003246 cmd->bind.index.offset, cmd->bind.index.type,
3247 p->primitive_restart);
3248 }
3249 } else {
3250 assert(!vertex_base);
3251 }
3252
3253 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3254 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3255 vertex_start, instance_count, instance_start, vertex_base);
3256 } else {
3257 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3258 vertex_start, instance_count, instance_start, vertex_base);
3259 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003260
Chia-I Wu707a29e2014-08-27 12:51:47 +08003261 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003262 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003263 /* need to re-emit all workarounds */
3264 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003265
3266 if (intel_debug & INTEL_DEBUG_NOCACHE)
3267 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003268}
3269
Chia-I Wuc14d1562014-10-17 09:49:22 +08003270void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3271{
Chia-I Wu6032b892014-10-17 14:47:18 +08003272 cmd->bind.meta = meta;
3273
Chia-I Wuf98dd882015-02-10 04:17:47 +08003274 cmd_adjust_state_base_address(cmd);
3275
Chia-I Wu6032b892014-10-17 14:47:18 +08003276 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003277 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003278
3279 gen6_meta_dynamic_states(cmd);
3280 gen6_meta_surface_states(cmd);
3281
3282 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3283 gen7_meta_urb(cmd);
3284 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003285 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003286 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003287 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003288 gen6_meta_wm(cmd);
3289 gen7_meta_ps(cmd);
3290 gen6_meta_depth_buffer(cmd);
3291
3292 cmd_wa_gen7_post_command_cs_stall(cmd);
3293 cmd_wa_gen7_post_command_depth_stall(cmd);
3294
Chia-I Wu29e6f502014-11-24 14:27:29 +08003295 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3296 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003297 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003298 } else {
3299 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3300 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003301 } else {
3302 gen6_meta_urb(cmd);
3303 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003304 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003305 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003306 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003307 gen6_meta_wm(cmd);
3308 gen6_meta_ps(cmd);
3309 gen6_meta_depth_buffer(cmd);
3310
Chia-I Wu29e6f502014-11-24 14:27:29 +08003311 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3312 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003313 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003314 } else {
3315 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3316 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003317 }
3318
3319 cmd->bind.draw_count++;
3320 /* need to re-emit all workarounds */
3321 cmd->bind.wa_flags = 0;
3322
3323 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003324
Chia-I Wubbc7d912015-02-27 14:59:50 -07003325 /* make the normal path believe the render pass has changed */
3326 cmd->bind.render_pass_changed = true;
3327
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003328 if (intel_debug & INTEL_DEBUG_NOCACHE)
3329 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003330}
3331
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003332ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003333 VkCmdBuffer cmdBuffer,
3334 VkPipelineBindPoint pipelineBindPoint,
3335 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003336{
3337 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3338
3339 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003340 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003341 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003342 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003343 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003344 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003345 break;
3346 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003347 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003348 break;
3349 }
3350}
3351
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003352ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003353 VkCmdBuffer cmdBuffer,
3354 VkStateBindPoint stateBindPoint,
3355 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003356{
3357 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3358
3359 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003360 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003361 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003362 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003363 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003364 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003365 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003366 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003367 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003368 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003369 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003370 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003371 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003372 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003373 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003374 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003375 break;
3376 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003377 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003378 break;
3379 }
3380}
3381
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003382ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003383 VkCmdBuffer cmdBuffer,
3384 VkPipelineBindPoint pipelineBindPoint,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003385 uint32_t firstSet,
3386 uint32_t setCount,
3387 const VkDescriptorSet* pDescriptorSets,
3388 uint32_t dynamicOffsetCount,
3389 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003390{
3391 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003392 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003393 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003394 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003395 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003396
3397 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003398 case VK_PIPELINE_BIND_POINT_COMPUTE:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003399 pipeline_layout = cmd->bind.pipeline.compute->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003400 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003401 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003402 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003403 pipeline_layout = cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003404 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003405 break;
3406 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003407 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003408 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003409 break;
3410 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003411
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003412 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003413 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3414
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003415 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003416 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003417 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003418 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003419 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003420 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003421 }
Chia-I Wub2755562014-08-20 13:38:52 +08003422}
3423
Tony Barbour8205d902015-04-16 15:59:00 -06003424
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003425ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3426 VkCmdBuffer cmdBuffer,
3427 uint32_t startBinding,
3428 uint32_t bindingCount,
3429 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003430 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003431{
3432 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003433
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003434 for (uint32_t i = 0; i < bindingCount; i++) {
3435 struct intel_buf *buf = intel_buf(pBuffers[i]);
3436 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3437 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003438}
3439
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003440ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003441 VkCmdBuffer cmdBuffer,
3442 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003443 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003444 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003445{
3446 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003447 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003448
Chia-I Wu714df452015-01-01 07:55:04 +08003449 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003450}
3451
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003452ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003453 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003454 uint32_t firstVertex,
3455 uint32_t vertexCount,
3456 uint32_t firstInstance,
3457 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003458{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003459 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003460
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003461 cmd_draw(cmd, firstVertex, vertexCount,
3462 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003463}
3464
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003465ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003466 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003467 uint32_t firstIndex,
3468 uint32_t indexCount,
3469 int32_t vertexOffset,
3470 uint32_t firstInstance,
3471 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003472{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003473 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003474
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003475 cmd_draw(cmd, firstIndex, indexCount,
3476 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003477}
3478
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003479ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003480 VkCmdBuffer cmdBuffer,
3481 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003482 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003483 uint32_t count,
3484 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003485{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003486 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3487
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003488 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003489}
3490
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003491ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003492 VkCmdBuffer cmdBuffer,
3493 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003494 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003495 uint32_t count,
3496 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003497{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003498 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3499
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003500 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003501}
3502
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003503ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003504 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003505 uint32_t x,
3506 uint32_t y,
3507 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003508{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003509 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3510
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003511 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003512}
3513
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003514ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003515 VkCmdBuffer cmdBuffer,
3516 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003517 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003518{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003519 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3520
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003521 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003522}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003523
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003524ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003525 VkCmdBuffer cmdBuffer,
3526 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003527{
3528 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3529
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003530 cmd_begin_render_pass(cmd, (struct intel_render_pass *) pRenderPassBegin->renderPass, pRenderPassBegin->framebuffer);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003531}
3532
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003533ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003534 VkCmdBuffer cmdBuffer,
3535 VkRenderPass renderPass)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003536{
3537 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3538
3539 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3540}