blob: 17f63e6cb0dd2109474b236bf3dcb77f229c73e1 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I 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) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 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,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 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) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700273 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700279 cmd_fail(cmd, XGL_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) {
394 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800395 format = GEN6_ZFORMAT_D16_UNORM;
396 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700397 case XGL_FMT_D32_SFLOAT:
398 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800399 format = GEN6_ZFORMAT_D32_FLOAT;
400 break;
401 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700402 assert(!cmd->bind.render_pass->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 |
501 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700502 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
504 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
505 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
506
507 if (pipeline->rasterizerDiscardEnable)
508 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
509 else
510 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
511
512 if (pipeline->depthClipEnable)
513 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
514
515 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
516 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
517 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
518 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
519
520 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
521 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
522 (viewport->viewport_count - 1);
523
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600524 /* TODO: framebuffer requests layer_count > 1 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700525 if (cmd->bind.render_pass->fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600526 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
527 }
528
Chia-I Wu72292b72014-09-09 10:48:33 +0800529 cmd_batch_pointer(cmd, cmd_len, &dw);
530 dw[0] = dw0;
531 dw[1] = dw1;
532 dw[2] = dw2;
533 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800534}
535
Chia-I Wu784d3042014-12-19 14:30:04 +0800536static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600537 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800538 const struct intel_pipeline *pipeline,
539 const struct intel_pipeline_shader *sh)
540{
541 int scratch_space;
542
543 CMD_ASSERT(cmd, 6, 7.5);
544
545 assert(sh->per_thread_scratch_size &&
546 sh->per_thread_scratch_size % 1024 == 0 &&
547 u_is_pow2(sh->per_thread_scratch_size) &&
548 sh->scratch_offset % 1024 == 0);
549 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
550
551 cmd_reserve_reloc(cmd, 1);
552 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
553 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
554}
555
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800556static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
557{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800558 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800559 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600561 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700562 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800563
564 CMD_ASSERT(cmd, 6, 6);
565
566 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
567
568 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
569 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
570
571 dw4 = GEN6_WM_DW4_STATISTICS |
572 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
573 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700574 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800575
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800576 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700577 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
578 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800579
Cody Northrope86574e2015-02-24 14:15:29 -0700580 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700581 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700582
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583 if (fs->uses & INTEL_SHADER_USE_KILL ||
584 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700585 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800586
Cody Northrope238deb2015-01-26 14:41:36 -0700587 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800588 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
589 if (fs->uses & INTEL_SHADER_USE_DEPTH)
590 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
591 if (fs->uses & INTEL_SHADER_USE_W)
592 dw5 |= GEN6_WM_DW5_PS_USE_W;
593
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700594 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700595 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596
597 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700598 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800599 GEN6_WM_DW6_ZW_INTERP_PIXEL |
600 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
601 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
602
Tony Barbourfa6cac72015-01-16 14:27:35 -0700603 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800604 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
605 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
606 } else {
607 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
608 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
609 }
610
Cody Northrope86574e2015-02-24 14:15:29 -0700611 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
612
Chia-I Wu784d3042014-12-19 14:30:04 +0800613 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800614 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800615 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800616 dw[2] = dw2;
617 dw[3] = 0; /* scratch */
618 dw[4] = dw4;
619 dw[5] = dw5;
620 dw[6] = dw6;
621 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700622 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800623
624 if (fs->per_thread_scratch_size)
625 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800626}
627
628static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
629{
630 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800631 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800633 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800634
635 CMD_ASSERT(cmd, 7, 7.5);
636
637 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
638
639 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700640 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641 GEN7_WM_DW1_ZW_INTERP_PIXEL |
642 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
643 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
644
645 if (fs->uses & INTEL_SHADER_USE_KILL ||
646 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700647 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648
Cody Northrope238deb2015-01-26 14:41:36 -0700649 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
650
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651 if (fs->uses & INTEL_SHADER_USE_DEPTH)
652 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
653 if (fs->uses & INTEL_SHADER_USE_W)
654 dw1 |= GEN7_WM_DW1_PS_USE_W;
655
656 dw2 = 0;
657
Tony Barbourfa6cac72015-01-16 14:27:35 -0700658 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
660 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
661 } else {
662 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
663 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
664 }
665
Chia-I Wu72292b72014-09-09 10:48:33 +0800666 cmd_batch_pointer(cmd, cmd_len, &dw);
667 dw[0] = dw0;
668 dw[1] = dw1;
669 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670}
671
672static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
673{
674 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800675 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700677 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600678 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679
680 CMD_ASSERT(cmd, 7, 7.5);
681
682 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
683
684 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
685 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
686
687 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700688 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800689
Cody Northrope86574e2015-02-24 14:15:29 -0700690 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700691 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700692
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800694 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700695 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800696 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800697 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800698 }
699
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800700 if (fs->in_count)
701 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
702
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700703 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
705
706 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
707 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700708 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
709
710 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800711
Chia-I Wu784d3042014-12-19 14:30:04 +0800712 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800713 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800714 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800715 dw[2] = dw2;
716 dw[3] = 0; /* scratch */
717 dw[4] = dw4;
718 dw[5] = dw5;
719 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700720 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800721
722 if (fs->per_thread_scratch_size)
723 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800724}
725
Chia-I Wu8ada4242015-03-02 11:19:33 -0700726static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
727 uint32_t sample_count)
728{
729 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
730 uint32_t dw1, dw2, dw3, *dw;
731
732 CMD_ASSERT(cmd, 6, 7.5);
733
734 switch (sample_count) {
735 case 4:
736 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
737 dw2 = cmd->dev->sample_pattern_4x;
738 dw3 = 0;
739 break;
740 case 8:
741 assert(cmd_gen(cmd) >= INTEL_GEN(7));
742 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
743 dw2 = cmd->dev->sample_pattern_8x[0];
744 dw3 = cmd->dev->sample_pattern_8x[1];
745 break;
746 default:
747 assert(sample_count <= 1);
748 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
749 dw2 = 0;
750 dw3 = 0;
751 break;
752 }
753
754 cmd_batch_pointer(cmd, cmd_len, &dw);
755
756 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
757 dw[1] = dw1;
758 dw[2] = dw2;
759 if (cmd_gen(cmd) >= INTEL_GEN(7))
760 dw[3] = dw3;
761}
762
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800763static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700764 const struct intel_ds_view *view,
765 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766{
767 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800768 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600769 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770
771 CMD_ASSERT(cmd, 6, 7.5);
772
773 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800774 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
775 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800776 dw0 |= (cmd_len - 2);
777
Chia-I Wu72292b72014-09-09 10:48:33 +0800778 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
779 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700780
Chia-I Wu72292b72014-09-09 10:48:33 +0800781 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700782 /* note that we only enable HiZ on Gen7+ */
783 if (!optimal_ds)
784 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
785
Chia-I Wu72292b72014-09-09 10:48:33 +0800786 dw[2] = 0;
787 dw[3] = view->cmd[2];
788 dw[4] = view->cmd[3];
789 dw[5] = view->cmd[4];
790 dw[6] = view->cmd[5];
791
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600792 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800793 cmd_reserve_reloc(cmd, 1);
794 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
795 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600796 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797}
798
799static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700800 const struct intel_ds_view *view,
801 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800802{
803 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600805 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800806
807 CMD_ASSERT(cmd, 6, 7.5);
808
809 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800810 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
811 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800812 dw0 |= (cmd_len - 2);
813
Chia-I Wu72292b72014-09-09 10:48:33 +0800814 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
815 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800816
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700817 if (view->has_stencil) {
818 dw[1] = view->cmd[6];
819
Chia-I Wu72292b72014-09-09 10:48:33 +0800820 cmd_reserve_reloc(cmd, 1);
821 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
822 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700823 } else {
824 dw[1] = 0;
825 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600826 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800827}
828
829static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700830 const struct intel_ds_view *view,
831 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800832{
833 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600835 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836
837 CMD_ASSERT(cmd, 6, 7.5);
838
839 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800840 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
841 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800842 dw0 |= (cmd_len - 2);
843
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
845 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800846
Chia-I Wu73520ac2015-02-19 11:17:45 -0700847 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700848 dw[1] = view->cmd[8];
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 cmd_reserve_reloc(cmd, 1);
851 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
852 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700853 } else {
854 dw[1] = 0;
855 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600856 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800857}
858
Chia-I Wuf8231032014-08-25 10:44:45 +0800859static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
860 uint32_t clear_val)
861{
862 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800864 GEN6_CLEAR_PARAMS_DW0_VALID |
865 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800866 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800867
868 CMD_ASSERT(cmd, 6, 6);
869
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 cmd_batch_pointer(cmd, cmd_len, &dw);
871 dw[0] = dw0;
872 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800873}
874
875static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
876 uint32_t clear_val)
877{
878 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800879 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800880 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800882
883 CMD_ASSERT(cmd, 7, 7.5);
884
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 cmd_batch_pointer(cmd, cmd_len, &dw);
886 dw[0] = dw0;
887 dw[1] = clear_val;
888 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800889}
890
Chia-I Wu302742d2014-08-22 10:28:29 +0800891static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t blend_offset,
893 uint32_t ds_offset,
894 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800895{
896 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800898
899 CMD_ASSERT(cmd, 6, 6);
900
Chia-I Wu426072d2014-08-26 14:31:55 +0800901 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800902 (cmd_len - 2);
903
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 cmd_batch_pointer(cmd, cmd_len, &dw);
905 dw[0] = dw0;
906 dw[1] = blend_offset | 1;
907 dw[2] = ds_offset | 1;
908 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800909}
910
Chia-I Wu1744cca2014-08-22 11:10:17 +0800911static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800912 uint32_t clip_offset,
913 uint32_t sf_offset,
914 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915{
916 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800918
919 CMD_ASSERT(cmd, 6, 6);
920
Chia-I Wu426072d2014-08-26 14:31:55 +0800921 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700922 GEN6_VP_PTR_DW0_CLIP_CHANGED |
923 GEN6_VP_PTR_DW0_SF_CHANGED |
924 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800925 (cmd_len - 2);
926
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 cmd_batch_pointer(cmd, cmd_len, &dw);
928 dw[0] = dw0;
929 dw[1] = clip_offset;
930 dw[2] = sf_offset;
931 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800932}
933
934static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936{
937 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800939
940 CMD_ASSERT(cmd, 6, 6);
941
Chia-I Wu426072d2014-08-26 14:31:55 +0800942 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800943 (cmd_len - 2);
944
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 cmd_batch_pointer(cmd, cmd_len, &dw);
946 dw[0] = dw0;
947 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800948}
949
Chia-I Wu42a56202014-08-23 16:47:48 +0800950static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 uint32_t vs_offset,
952 uint32_t gs_offset,
953 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800954{
955 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800957
958 CMD_ASSERT(cmd, 6, 6);
959
Chia-I Wu426072d2014-08-26 14:31:55 +0800960 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700961 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
962 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
963 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800964 (cmd_len - 2);
965
Chia-I Wu72292b72014-09-09 10:48:33 +0800966 cmd_batch_pointer(cmd, cmd_len, &dw);
967 dw[0] = dw0;
968 dw[1] = vs_offset;
969 dw[2] = gs_offset;
970 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800971}
972
Chia-I Wu257e75e2014-08-29 14:06:35 +0800973static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800974 uint32_t vs_offset,
975 uint32_t gs_offset,
976 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977{
978 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800979 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800980
981 CMD_ASSERT(cmd, 6, 6);
982
983 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700984 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
985 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
986 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800987 (cmd_len - 2);
988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 cmd_batch_pointer(cmd, cmd_len, &dw);
990 dw[0] = dw0;
991 dw[1] = vs_offset;
992 dw[2] = gs_offset;
993 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800994}
995
Chia-I Wu302742d2014-08-22 10:28:29 +0800996static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800997 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800998{
999 const uint8_t cmd_len = 2;
1000 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1001 GEN6_RENDER_SUBTYPE_3D |
1002 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001003 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001004
Chia-I Wu72292b72014-09-09 10:48:33 +08001005 cmd_batch_pointer(cmd, cmd_len, &dw);
1006 dw[0] = dw0;
1007 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001008}
1009
Chia-I Wua6c4f152014-12-02 04:19:58 +08001010static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001011{
Chia-I Wue6073342014-11-30 09:43:42 +08001012 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001013 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1014 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001015
1016 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001017 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001018
Tony Barbourfa6cac72015-01-16 14:27:35 -07001019 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001020}
1021
Chia-I Wu72292b72014-09-09 10:48:33 +08001022static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001023 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001024{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001025 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001026 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001027 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001028 uint32_t dw[3];
1029
1030 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001031 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001032 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001033 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1034 (state->ds_info.stencilReadMask & 0xff) << 8 |
1035 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001037
1038 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001039
1040 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1041 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001042
Chia-I Wu00b51a82014-09-09 12:07:37 +08001043 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001044 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001045}
1046
Chia-I Wu72292b72014-09-09 10:48:33 +08001047static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001048 uint32_t stencil_ref,
1049 const uint32_t blend_color[4])
1050{
Chia-I Wue6073342014-11-30 09:43:42 +08001051 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001052 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001053 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001054
1055 CMD_ASSERT(cmd, 6, 7.5);
1056
Chia-I Wu00b51a82014-09-09 12:07:37 +08001057 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1058 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001059 dw[0] = stencil_ref;
1060 dw[1] = 0;
1061 dw[2] = blend_color[0];
1062 dw[3] = blend_color[1];
1063 dw[4] = blend_color[2];
1064 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001065
Chia-I Wu72292b72014-09-09 10:48:33 +08001066 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001067}
1068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001070{
Chia-I Wu8370b402014-08-29 12:28:37 +08001071 CMD_ASSERT(cmd, 6, 7.5);
1072
Chia-I Wu707a29e2014-08-27 12:51:47 +08001073 if (!cmd->bind.draw_count)
1074 return;
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001077 return;
1078
Chia-I Wu8370b402014-08-29 12:28:37 +08001079 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001080
1081 /*
1082 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1083 *
1084 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1085 * pipe-control with a post-sync op and no write-cache flushes."
1086 *
1087 * The workaround below necessitates this workaround.
1088 */
1089 gen6_PIPE_CONTROL(cmd,
1090 GEN6_PIPE_CONTROL_CS_STALL |
1091 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001093
Chia-I Wud6d079d2014-08-31 13:14:21 +08001094 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1095 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001096}
1097
Chia-I Wu8370b402014-08-29 12:28:37 +08001098static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001099{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001100 CMD_ASSERT(cmd, 6, 7.5);
1101
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001102 if (!cmd->bind.draw_count)
1103 return;
1104
Chia-I Wud6d079d2014-08-31 13:14:21 +08001105 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1106 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001107}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001108
Chia-I Wu8370b402014-08-29 12:28:37 +08001109static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1110{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001111 CMD_ASSERT(cmd, 7, 7.5);
1112
Chia-I Wu8370b402014-08-29 12:28:37 +08001113 if (!cmd->bind.draw_count)
1114 return;
1115
1116 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001117
1118 gen6_PIPE_CONTROL(cmd,
1119 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001120 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001121}
1122
Chia-I Wu8370b402014-08-29 12:28:37 +08001123static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1124{
1125 CMD_ASSERT(cmd, 7, 7.5);
1126
Chia-I Wu8370b402014-08-29 12:28:37 +08001127 /*
1128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1129 *
1130 * "One of the following must also be set (when CS stall is set):
1131 *
1132 * * Render Target Cache Flush Enable ([12] of DW1)
1133 * * Depth Cache Flush Enable ([0] of DW1)
1134 * * Stall at Pixel Scoreboard ([1] of DW1)
1135 * * Depth Stall ([13] of DW1)
1136 * * Post-Sync Operation ([13] of DW1)"
1137 */
1138 gen6_PIPE_CONTROL(cmd,
1139 GEN6_PIPE_CONTROL_CS_STALL |
1140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001141 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001142}
1143
1144static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1145{
1146 CMD_ASSERT(cmd, 7, 7.5);
1147
Chia-I Wu8370b402014-08-29 12:28:37 +08001148 cmd_wa_gen6_pre_depth_stall_write(cmd);
1149
Chia-I Wud6d079d2014-08-31 13:14:21 +08001150 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001151}
1152
1153static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1154{
1155 CMD_ASSERT(cmd, 6, 7.5);
1156
1157 if (!cmd->bind.draw_count)
1158 return;
1159
1160 /*
1161 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1162 *
1163 * "Driver must guarentee that all the caches in the depth pipe are
1164 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1165 * requires driver to send a PIPE_CONTROL with a CS stall along with
1166 * a Depth Flush prior to this command."
1167 *
1168 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1169 *
1170 * "Driver must ierarchi that all the caches in the depth pipe are
1171 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1172 * requires driver to send a PIPE_CONTROL with a CS stall along with
1173 * a Depth Flush prior to this command.
1174 */
1175 gen6_PIPE_CONTROL(cmd,
1176 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1177 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001178 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001179}
1180
1181static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1182{
1183 CMD_ASSERT(cmd, 6, 7.5);
1184
1185 if (!cmd->bind.draw_count)
1186 return;
1187
1188 /*
1189 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1190 *
1191 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1192 * and a post sync operation prior to the group of depth
1193 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1194 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1195 *
1196 * This workaround satifies all the conditions.
1197 */
1198 cmd_wa_gen6_pre_depth_stall_write(cmd);
1199
1200 /*
1201 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1202 *
1203 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1204 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1205 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1206 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1207 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1208 * Depth Flush Bit set, followed by another pipelined depth stall
1209 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1210 * guarantee that the pipeline from WM onwards is already flushed
1211 * (e.g., via a preceding MI_FLUSH)."
1212 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1214 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1215 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001216}
1217
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001218void cmd_batch_state_base_address(struct intel_cmd *cmd)
1219{
1220 const uint8_t cmd_len = 10;
1221 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1222 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001223 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001224 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001225 uint32_t pos;
1226 uint32_t *dw;
1227
1228 CMD_ASSERT(cmd, 6, 7.5);
1229
1230 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1231
1232 dw[0] = dw0;
1233 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001234 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001235 dw[2] = 1;
1236 dw[3] = 1;
1237 dw[4] = 1;
1238 dw[5] = 1;
1239 /* end offsets */
1240 dw[6] = 1;
1241 dw[7] = 1 + 0xfffff000;
1242 dw[8] = 1 + 0xfffff000;
1243 dw[9] = 1;
1244
1245 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001246 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1247 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1248 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1249 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1250 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1251 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001252}
1253
Chia-I Wu7c853562015-02-27 14:35:08 -07001254void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1255{
1256 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1257 const uint8_t cmd_len = 2;
1258 uint32_t offset = 0;
1259 uint32_t *dw;
1260
1261 if (cmd_gen(cmd) <= INTEL_GEN(6))
1262 return;
1263
1264 CMD_ASSERT(cmd, 7, 7.5);
1265
1266 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1267 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1268 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1269 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1270 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1271 offset += size;
1272
1273 dw += 2;
1274 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1275 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1276 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1277
1278 dw += 2;
1279 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1280 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1281 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1282
1283 dw += 2;
1284 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1285 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1286 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1287
1288 dw += 2;
1289 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1290 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1291 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1292
1293 /*
1294 *
1295 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1296 *
1297 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1298 * in the ring after this instruction
1299 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1300 */
1301 cmd_wa_gen7_post_command_cs_stall(cmd);
1302}
1303
Chia-I Wu525c6602014-08-27 10:22:34 +08001304void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1305{
Mike Stroyan552fda42015-01-30 17:21:08 -07001306 if (pipe_control_dw0 == 0)
1307 return;
1308
Chia-I Wu525c6602014-08-27 10:22:34 +08001309 if (!cmd->bind.draw_count)
1310 return;
1311
1312 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1313
Chia-I Wu8370b402014-08-29 12:28:37 +08001314 /*
1315 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1316 *
1317 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1318 * PIPE_CONTROL with any non-zero post-sync-op is required."
1319 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001320 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001321 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001322
Chia-I Wu092279a2014-08-30 19:05:30 +08001323 /*
1324 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1325 *
1326 * "One of the following must also be set (when CS stall is set):
1327 *
1328 * * Render Target Cache Flush Enable ([12] of DW1)
1329 * * Depth Cache Flush Enable ([0] of DW1)
1330 * * Stall at Pixel Scoreboard ([1] of DW1)
1331 * * Depth Stall ([13] of DW1)
1332 * * Post-Sync Operation ([13] of DW1)"
1333 */
1334 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1335 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1336 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1337 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1338 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1339 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1340
Chia-I Wud6d079d2014-08-31 13:14:21 +08001341 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001342}
1343
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001344void cmd_batch_flush_all(struct intel_cmd *cmd)
1345{
1346 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1347 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1348 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1349 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1350 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1351 GEN6_PIPE_CONTROL_CS_STALL);
1352}
1353
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001354void cmd_batch_depth_count(struct intel_cmd *cmd,
1355 struct intel_bo *bo,
1356 XGL_GPU_SIZE offset)
1357{
1358 cmd_wa_gen6_pre_depth_stall_write(cmd);
1359
1360 gen6_PIPE_CONTROL(cmd,
1361 GEN6_PIPE_CONTROL_DEPTH_STALL |
1362 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001363 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001364}
1365
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001366void cmd_batch_timestamp(struct intel_cmd *cmd,
1367 struct intel_bo *bo,
1368 XGL_GPU_SIZE offset)
1369{
1370 /* need any WA or stall? */
1371 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1372}
1373
1374void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001375 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001376 struct intel_bo *bo,
1377 XGL_GPU_SIZE offset,
1378 uint64_t val)
1379{
1380 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001381 gen6_PIPE_CONTROL(cmd,
1382 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1383 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001384}
1385
Chia-I Wu302742d2014-08-22 10:28:29 +08001386static void gen6_cc_states(struct intel_cmd *cmd)
1387{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001388 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1389 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001390 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001391 uint32_t stencil_ref;
1392 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001393
1394 CMD_ASSERT(cmd, 6, 6);
1395
Chia-I Wua6c4f152014-12-02 04:19:58 +08001396 blend_offset = gen6_BLEND_STATE(cmd);
1397
1398 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001399 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001400 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001401 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001402
1403 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001404 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001405 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1406 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001407 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001408 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001409 stencil_ref = 0;
1410 }
1411
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001413
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001415}
1416
Chia-I Wu1744cca2014-08-22 11:10:17 +08001417static void gen6_viewport_states(struct intel_cmd *cmd)
1418{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001419 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001421
1422 if (!viewport)
1423 return;
1424
Tony Barbourfa6cac72015-01-16 14:27:35 -07001425 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001426 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427
1428 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001429 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001430 viewport->cmd);
1431
1432 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001433 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001434 &viewport->cmd[viewport->cmd_clip_pos]);
1435
1436 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001437 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001438 &viewport->cmd[viewport->cmd_cc_pos]);
1439
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001440 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1441 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1442 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001443
1444 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001445 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001446
Chia-I Wub1d450a2014-09-09 13:48:03 +08001447 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001448}
1449
Chia-I Wu302742d2014-08-22 10:28:29 +08001450static void gen7_cc_states(struct intel_cmd *cmd)
1451{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001452 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1453 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001454 uint32_t stencil_ref;
1455 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001456 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001457
1458 CMD_ASSERT(cmd, 7, 7.5);
1459
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001460 if (!blend && !ds)
1461 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001462
Chia-I Wua6c4f152014-12-02 04:19:58 +08001463 offset = gen6_BLEND_STATE(cmd);
1464 gen7_3dstate_pointer(cmd,
1465 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001466
Chia-I Wua6c4f152014-12-02 04:19:58 +08001467 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001468 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001469 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001470 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001471
1472 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001473 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001474 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1475 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001476 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001477 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1478 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001479 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1480 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001481 } else {
1482 stencil_ref = 0;
1483 }
1484
Chia-I Wu72292b72014-09-09 10:48:33 +08001485 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001486 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001487 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001488}
1489
Chia-I Wu1744cca2014-08-22 11:10:17 +08001490static void gen7_viewport_states(struct intel_cmd *cmd)
1491{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001492 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001493 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001494
1495 if (!viewport)
1496 return;
1497
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001498 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001499
Chia-I Wub1d450a2014-09-09 13:48:03 +08001500 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001501 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001502 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001503 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001504 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1505 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506
1507 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001508 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001509 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001510 gen7_3dstate_pointer(cmd,
1511 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001512 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001513
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001514 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1515 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1516 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1517 gen7_3dstate_pointer(cmd,
1518 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1519 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001520}
1521
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001522static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001523 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001524{
1525 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001526 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001527
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001529
1530 dw[0] = GEN6_RENDER_TYPE_RENDER |
1531 GEN6_RENDER_SUBTYPE_3D |
1532 subop | (cmd_len - 2);
1533 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001534 dw[2] = 0;
1535 dw[3] = 0;
1536 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001537}
1538
1539static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001540 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001541{
1542 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001543 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001544
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001546
1547 dw[0] = GEN6_RENDER_TYPE_RENDER |
1548 GEN6_RENDER_SUBTYPE_3D |
1549 subop | (cmd_len - 2);
1550 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001551 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001552 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001553 dw[4] = 0;
1554 dw[5] = 0;
1555 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001556}
1557
Chia-I Wu625105f2014-10-13 15:35:29 +08001558static uint32_t emit_samplers(struct intel_cmd *cmd,
1559 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001560{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001561 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1562 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001563 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001564 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001565 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001566 uint32_t surface_count;
1567 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001568
1569 CMD_ASSERT(cmd, 6, 7.5);
1570
Chia-I Wu625105f2014-10-13 15:35:29 +08001571 if (!rmap || !rmap->sampler_count)
1572 return 0;
1573
Cody Northrop40316a32014-12-09 19:08:33 -07001574 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001575
Chia-I Wudcb509d2014-12-10 08:53:10 +08001576 /*
1577 * note that we cannot call cmd_state_pointer() here as the following
1578 * cmd_state_pointer() would invalidate the pointer
1579 */
1580 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001581 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001582 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001583
1584 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001585 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001586 4 * rmap->sampler_count, &sampler_dw);
1587
Chia-I Wudcb509d2014-12-10 08:53:10 +08001588 cmd_state_update(cmd, border_offset,
1589 border_stride * rmap->sampler_count, &border_dw);
1590
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001591 for (i = 0; i < rmap->sampler_count; i++) {
1592 const struct intel_pipeline_rmap_slot *slot =
1593 &rmap->slots[surface_count + i];
1594 const struct intel_sampler *sampler;
1595
Chia-I Wuf8385062015-01-04 16:27:24 +08001596 switch (slot->type) {
1597 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001598 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001599 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001600 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001601 sampler = NULL;
1602 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001603 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001604 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605 sampler = NULL;
1606 break;
1607 }
1608
1609 if (sampler) {
1610 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1611
1612 sampler_dw[0] = sampler->cmd[0];
1613 sampler_dw[1] = sampler->cmd[1];
1614 sampler_dw[2] = border_offset;
1615 sampler_dw[3] = sampler->cmd[2];
1616 } else {
1617 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1618 sampler_dw[1] = 0;
1619 sampler_dw[2] = 0;
1620 sampler_dw[3] = 0;
1621 }
1622
1623 border_offset += border_stride * 4;
1624 border_dw += border_stride;
1625 sampler_dw += 4;
1626 }
1627
Chia-I Wu625105f2014-10-13 15:35:29 +08001628 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001629}
1630
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001631static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001632 const struct intel_pipeline_rmap *rmap,
1633 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001634{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001635 const uint32_t sba_offset =
1636 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001637 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001638 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001639 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001640
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641 CMD_ASSERT(cmd, 6, 7.5);
1642
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001643 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001644 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001645 if (!surface_count)
1646 return 0;
1647
Chia-I Wu42a56202014-08-23 16:47:48 +08001648 assert(surface_count <= ARRAY_SIZE(binding_table));
1649
1650 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001651 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001652 struct intel_null_view null_view;
1653 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001654
Chia-I Wuf8385062015-01-04 16:27:24 +08001655 switch (slot->type) {
1656 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001657 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001658 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001659 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1660 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001661
Chia-I Wu787a05b2014-12-05 11:02:20 +08001662 if (view) {
1663 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1664 GEN6_ALIGNMENT_SURFACE_STATE,
1665 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001666
Chia-I Wu787a05b2014-12-05 11:02:20 +08001667 cmd_reserve_reloc(cmd, 1);
1668 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1669 view->cmd[1], INTEL_RELOC_WRITE);
1670 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001671 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001672 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001673 }
1674 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001675 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001676 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001677 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1678 const struct intel_mem *mem;
1679 bool read_only;
1680 const uint32_t *cmd_data;
1681 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001682
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001683 assert(dyn_idx < 0 ||
1684 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001685
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001686 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1687 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001688 if (mem) {
1689 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1690 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1691 const uint32_t reloc_flags =
1692 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001693
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001694 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001695 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001696 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001697
1698 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001699 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1700 cmd_data[1] + dynamic_offset, reloc_flags);
1701 } else {
1702 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001703 }
1704 }
1705 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001706 case INTEL_PIPELINE_RMAP_UNUSED:
1707 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001708 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001709 default:
1710 assert(!"unexpected rmap type");
1711 need_null_view = true;
1712 break;
1713 }
1714
1715 if (need_null_view) {
1716 intel_null_view_init(&null_view, cmd->dev);
1717 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1718 GEN6_ALIGNMENT_SURFACE_STATE,
1719 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001720 }
1721
Chia-I Wuf98dd882015-02-10 04:17:47 +08001722 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001723 }
1724
Chia-I Wuf98dd882015-02-10 04:17:47 +08001725 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001726 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001727 surface_count, binding_table) - sba_offset;
1728
1729 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1730 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1731
1732 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001733}
1734
Chia-I Wu1d125092014-10-08 08:49:38 +08001735static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1736{
1737 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001738 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1739 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001740 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001741
1742 CMD_ASSERT(cmd, 6, 7.5);
1743
1744 if (!pipeline->vb_count)
1745 return;
1746
1747 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1748
1749 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1750 dw++;
1751 pos++;
1752
1753 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001754 assert(pipeline->vb[i].strideInBytes <= 2048);
1755
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001756 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001757 pipeline->vb[i].strideInBytes;
1758
Chia-I Wub3686982015-02-27 09:51:16 -07001759 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001760 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1761 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001762 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001763
1764 switch (pipeline->vb[i].stepRate) {
1765 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001766 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001767 dw[3] = 0;
1768 break;
1769 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001770 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001771 dw[3] = 1;
1772 break;
1773 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001774 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001775 dw[3] = 0;
1776 break;
1777 default:
1778 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001779 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001780 dw[3] = 0;
1781 break;
1782 }
1783
Chia-I Wu714df452015-01-01 07:55:04 +08001784 if (cmd->bind.vertex.buf[i]) {
1785 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001786 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001787
1788 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001789 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1790 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001791 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001792 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001793 dw[1] = 0;
1794 dw[2] = 0;
1795 }
1796
1797 dw += 4;
1798 pos += 4;
1799 }
1800}
1801
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001802static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1803{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001804 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1805 const struct intel_pipeline_shader *vs = &pipeline->vs;
1806 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001807 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001808 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001809 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001810 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001811
1812 CMD_ASSERT(cmd, 6, 7.5);
1813
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001814 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001815 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1816 *
1817 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1818 * 128-bit vertex elements to be passed into the payload for each
1819 * vertex."
1820 *
1821 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1822 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001823 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001824 vue_read_len = (vs->in_count + 1) / 2;
1825 if (!vue_read_len)
1826 vue_read_len = 1;
1827
1828 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1829 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1830
1831 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1832 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1833 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001834
1835 dw5 = GEN6_VS_DW5_STATISTICS |
1836 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001837
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001838 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001839 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001840 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001841 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001842
Chia-I Wube0a3d92014-09-02 13:20:59 +08001843 if (pipeline->disable_vs_cache)
1844 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1845
Chia-I Wu784d3042014-12-19 14:30:04 +08001846 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001847 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001848 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001849 dw[2] = dw2;
1850 dw[3] = 0; /* scratch */
1851 dw[4] = dw4;
1852 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001853
1854 if (vs->per_thread_scratch_size)
1855 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001856}
1857
Chia-I Wu625105f2014-10-13 15:35:29 +08001858static void emit_shader_resources(struct intel_cmd *cmd)
1859{
1860 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001861 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001862
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001863 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001864 cmd->bind.pipeline.graphics->vs.rmap,
1865 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001866 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001867 cmd->bind.pipeline.graphics->tcs.rmap,
1868 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001869 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001870 cmd->bind.pipeline.graphics->tes.rmap,
1871 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001872 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001873 cmd->bind.pipeline.graphics->gs.rmap,
1874 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001875 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001876 cmd->bind.pipeline.graphics->fs.rmap,
1877 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001878
1879 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1880 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1881 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1882 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1883 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1884
1885 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1886 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001887 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1888 binding_tables[0]);
1889 gen7_3dstate_pointer(cmd,
1890 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1891 binding_tables[1]);
1892 gen7_3dstate_pointer(cmd,
1893 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1894 binding_tables[2]);
1895 gen7_3dstate_pointer(cmd,
1896 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1897 binding_tables[3]);
1898 gen7_3dstate_pointer(cmd,
1899 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1900 binding_tables[4]);
1901
1902 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001903 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1904 samplers[0]);
1905 gen7_3dstate_pointer(cmd,
1906 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1907 samplers[1]);
1908 gen7_3dstate_pointer(cmd,
1909 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1910 samplers[2]);
1911 gen7_3dstate_pointer(cmd,
1912 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1913 samplers[3]);
1914 gen7_3dstate_pointer(cmd,
1915 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1916 samplers[4]);
1917 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001918 assert(!binding_tables[1] && !binding_tables[2]);
1919 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1920 binding_tables[0], binding_tables[3], binding_tables[4]);
1921
Chia-I Wu625105f2014-10-13 15:35:29 +08001922 assert(!samplers[1] && !samplers[2]);
1923 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1924 samplers[0], samplers[3], samplers[4]);
1925 }
1926}
1927
Chia-I Wu8ada4242015-03-02 11:19:33 -07001928static void emit_msaa(struct intel_cmd *cmd)
1929{
1930 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1931
Chia-I Wubbc7d912015-02-27 14:59:50 -07001932 if (!cmd->bind.render_pass_changed)
1933 return;
1934
Chia-I Wu8ada4242015-03-02 11:19:33 -07001935 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
1936 cmd->result = XGL_ERROR_UNKNOWN;
1937
1938 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1939 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1940}
1941
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001942static void emit_rt(struct intel_cmd *cmd)
1943{
Chia-I Wubbc7d912015-02-27 14:59:50 -07001944 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1945
1946 if (!cmd->bind.render_pass_changed)
1947 return;
1948
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001949 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubbc7d912015-02-27 14:59:50 -07001950 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width, fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001951}
1952
1953static void emit_ds(struct intel_cmd *cmd)
1954{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001955 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1956 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001957
Chia-I Wubbc7d912015-02-27 14:59:50 -07001958 if (!cmd->bind.render_pass_changed)
1959 return;
1960
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001961 if (!ds) {
1962 /* all zeros */
1963 static const struct intel_ds_view null_ds;
1964 ds = &null_ds;
1965 }
1966
1967 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001968 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1969 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1970 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001971
1972 if (cmd_gen(cmd) >= INTEL_GEN(7))
1973 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1974 else
1975 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1976}
1977
Chia-I Wua57761b2014-10-14 14:27:44 +08001978static uint32_t emit_shader(struct intel_cmd *cmd,
1979 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001980{
Chia-I Wua57761b2014-10-14 14:27:44 +08001981 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1982 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001983 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001984
Chia-I Wua57761b2014-10-14 14:27:44 +08001985 /* see if the shader is already in the cache */
1986 for (i = 0; i < cache->used; i++) {
1987 if (cache->entries[i].shader == (const void *) shader)
1988 return cache->entries[i].kernel_offset;
1989 }
1990
1991 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1992
1993 /* grow the cache if full */
1994 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001995 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001996 void *entries;
1997
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08001998 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Chia-I Wua57761b2014-10-14 14:27:44 +08001999 XGL_SYSTEM_ALLOC_INTERNAL);
2000 if (entries) {
2001 if (cache->entries) {
2002 memcpy(entries, cache->entries,
2003 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002004 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002005 }
2006
2007 cache->entries = entries;
2008 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002009 }
2010 }
2011
Chia-I Wua57761b2014-10-14 14:27:44 +08002012 /* add the shader to the cache */
2013 if (cache->used < cache->count) {
2014 cache->entries[cache->used].shader = (const void *) shader;
2015 cache->entries[cache->used].kernel_offset = offset;
2016 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002017 }
2018
Chia-I Wua57761b2014-10-14 14:27:44 +08002019 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002020}
2021
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002022static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002023{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002024 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002025
Chia-I Wu8370b402014-08-29 12:28:37 +08002026 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2027 cmd_wa_gen6_pre_depth_stall_write(cmd);
2028 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2029 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2030 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2031 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002032
2033 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002034 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002035 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002036
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002037 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002038 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002039 }
2040 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002041 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002042 }
2043 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002044 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2045 }
2046 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2047 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2048 }
2049 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2050 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002051 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002052
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002053 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2054 gen7_3DSTATE_GS(cmd);
2055 } else {
2056 gen6_3DSTATE_GS(cmd);
2057 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002058
Chia-I Wu8370b402014-08-29 12:28:37 +08002059 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2060 cmd_wa_gen7_post_command_cs_stall(cmd);
2061 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2062 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002063}
2064
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002065static void emit_bounded_states(struct intel_cmd *cmd)
2066{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002067 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002068
2069 emit_graphics_pipeline(cmd);
2070
2071 emit_rt(cmd);
2072 emit_ds(cmd);
2073
2074 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2075 gen7_cc_states(cmd);
2076 gen7_viewport_states(cmd);
2077
2078 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2079 &cmd->bind.pipeline.graphics->vs);
2080 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2081 &cmd->bind.pipeline.graphics->fs);
2082
2083 gen6_3DSTATE_CLIP(cmd);
2084 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002085 gen7_3DSTATE_WM(cmd);
2086 gen7_3DSTATE_PS(cmd);
2087 } else {
2088 gen6_cc_states(cmd);
2089 gen6_viewport_states(cmd);
2090
2091 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2092 &cmd->bind.pipeline.graphics->vs);
2093 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2094 &cmd->bind.pipeline.graphics->fs);
2095
2096 gen6_3DSTATE_CLIP(cmd);
2097 gen6_3DSTATE_SF(cmd);
2098 gen6_3DSTATE_WM(cmd);
2099 }
2100
2101 emit_shader_resources(cmd);
2102
2103 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002104
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002105 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2106 gen6_3DSTATE_VS(cmd);
2107}
2108
Tony Barbourfa6cac72015-01-16 14:27:35 -07002109static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002110 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002111{
2112 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2113 const uint8_t cmd_len = 3;
2114 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002115
2116 CMD_ASSERT(cmd, 6, 7.5);
2117
Tony Barbourfa6cac72015-01-16 14:27:35 -07002118 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002119 dw[0] = 0;
2120 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002121
2122 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2123 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2124 GEN6_COMPAREFUNCTION_NEVER << 27 |
2125 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2126 } else {
2127 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2128 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2129 }
Chia-I Wud850a392015-02-19 11:08:25 -07002130 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2131 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002132 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2133 (GEN6_STENCILOP_KEEP) << 25 |
2134 (GEN6_STENCILOP_KEEP) << 22 |
2135 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002136 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2137 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002138 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2139 (GEN6_STENCILOP_KEEP) << 9 |
2140 (GEN6_STENCILOP_KEEP) << 6 |
2141 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002142
Chia-I Wud850a392015-02-19 11:08:25 -07002143 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2144 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2145 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2146 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2147 dw[2] = 0;
2148 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002149
2150 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2151 cmd_align, cmd_len, dw);
2152}
2153
Chia-I Wu6032b892014-10-17 14:47:18 +08002154static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2155{
2156 const struct intel_cmd_meta *meta = cmd->bind.meta;
2157 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2158
2159 CMD_ASSERT(cmd, 6, 7.5);
2160
2161 blend_offset = 0;
2162 ds_offset = 0;
2163 cc_offset = 0;
2164 cc_vp_offset = 0;
2165
Chia-I Wu29e6f502014-11-24 14:27:29 +08002166 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002167 /* BLEND_STATE */
2168 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002169 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002170 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002171 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002172 }
2173
Chia-I Wu29e6f502014-11-24 14:27:29 +08002174 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002175 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002176 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002177 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2178 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002179
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002181 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002182
Chia-I Wu29e6f502014-11-24 14:27:29 +08002183 /* COLOR_CALC_STATE */
2184 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002185 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002186
Chia-I Wu29e6f502014-11-24 14:27:29 +08002187 /* CC_VIEWPORT */
2188 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002189 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002190 dw[0] = u_fui(0.0f);
2191 dw[1] = u_fui(1.0f);
2192 } else {
2193 /* DEPTH_STENCIL_STATE */
2194 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002195 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002196 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2197 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2198 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002199 }
2200
2201 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2202 gen7_3dstate_pointer(cmd,
2203 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2204 blend_offset);
2205 gen7_3dstate_pointer(cmd,
2206 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2207 ds_offset);
2208 gen7_3dstate_pointer(cmd,
2209 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2210
2211 gen7_3dstate_pointer(cmd,
2212 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2213 cc_vp_offset);
2214 } else {
2215 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002216 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002217
2218 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2219 cmd_batch_pointer(cmd, 4, &dw);
2220 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002221 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002222 dw[1] = 0;
2223 dw[2] = 0;
2224 dw[3] = cc_vp_offset;
2225 }
2226}
2227
2228static void gen6_meta_surface_states(struct intel_cmd *cmd)
2229{
2230 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002231 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002232 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002233 const uint32_t sba_offset =
2234 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002235
2236 CMD_ASSERT(cmd, 6, 7.5);
2237
Chia-I Wu29e6f502014-11-24 14:27:29 +08002238 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2239 return;
2240
Chia-I Wu005c47c2014-10-22 13:49:13 +08002241 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002242 if (meta->src.valid) {
2243 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002244 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002245 meta->src.surface_len, meta->src.surface);
2246
2247 cmd_reserve_reloc(cmd, 1);
2248 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2249 cmd_surface_reloc_writer(cmd, offset, 1,
2250 meta->src.reloc_target, meta->src.reloc_offset);
2251 } else {
2252 cmd_surface_reloc(cmd, offset, 1,
2253 (struct intel_bo *) meta->src.reloc_target,
2254 meta->src.reloc_offset, meta->src.reloc_flags);
2255 }
2256
Mike Stroyan9bfad482015-02-10 15:09:23 -07002257 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002258 }
2259 if (meta->dst.valid) {
2260 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002261 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002262 meta->dst.surface_len, meta->dst.surface);
2263
2264 cmd_reserve_reloc(cmd, 1);
2265 cmd_surface_reloc(cmd, offset, 1,
2266 (struct intel_bo *) meta->dst.reloc_target,
2267 meta->dst.reloc_offset, meta->dst.reloc_flags);
2268
Mike Stroyan9bfad482015-02-10 15:09:23 -07002269 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002270 }
2271
2272 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002273 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002274 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002275 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002276
2277 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002278 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2279 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2280 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002281 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 } else {
2283 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002285 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002287 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002288 }
2289}
2290
2291static void gen6_meta_urb(struct intel_cmd *cmd)
2292{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002293 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002294 uint32_t *dw;
2295
2296 CMD_ASSERT(cmd, 6, 6);
2297
2298 /* 3DSTATE_URB */
2299 cmd_batch_pointer(cmd, 3, &dw);
2300 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002301 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002302 dw[2] = 0;
2303}
2304
2305static void gen7_meta_urb(struct intel_cmd *cmd)
2306{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002307 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2308 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002309 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002310 uint32_t *dw;
2311
2312 CMD_ASSERT(cmd, 7, 7.5);
2313
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2315
Chia-I Wu24aa1022014-11-25 11:53:19 +08002316 switch (cmd_gen(cmd)) {
2317 case INTEL_GEN(7.5):
2318 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2319 break;
2320 case INTEL_GEN(7):
2321 default:
2322 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2323 break;
2324 }
2325
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 /* 3DSTATE_URB_x */
2327 cmd_batch_pointer(cmd, 8, &dw);
2328
2329 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002330 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002331 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002332 dw += 2;
2333
2334 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002335 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002336 dw += 2;
2337
2338 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002339 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002340 dw += 2;
2341
2342 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002343 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002344 dw += 2;
2345}
2346
2347static void gen6_meta_vf(struct intel_cmd *cmd)
2348{
2349 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002350 uint32_t vb_start, vb_end, vb_stride;
2351 int ve_format, ve_z_source;
2352 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002353 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002354
2355 CMD_ASSERT(cmd, 6, 7.5);
2356
Chia-I Wu29e6f502014-11-24 14:27:29 +08002357 switch (meta->mode) {
2358 case INTEL_CMD_META_VS_POINTS:
2359 cmd_batch_pointer(cmd, 3, &dw);
2360 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002361 dw[1] = GEN6_VE_DW0_VALID;
2362 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2363 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2364 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2365 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002366 return;
2367 break;
2368 case INTEL_CMD_META_FS_RECT:
2369 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002370 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002371
Chia-I Wu29e6f502014-11-24 14:27:29 +08002372 vertices[0][0] = meta->dst.x + meta->width;
2373 vertices[0][1] = meta->dst.y + meta->height;
2374 vertices[1][0] = meta->dst.x;
2375 vertices[1][1] = meta->dst.y + meta->height;
2376 vertices[2][0] = meta->dst.x;
2377 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002378
Chia-I Wu29e6f502014-11-24 14:27:29 +08002379 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2380 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002381
Chia-I Wu29e6f502014-11-24 14:27:29 +08002382 vb_end = vb_start + sizeof(vertices) - 1;
2383 vb_stride = sizeof(vertices[0]);
2384 ve_z_source = GEN6_VFCOMP_STORE_0;
2385 ve_format = GEN6_FORMAT_R32G32_USCALED;
2386 }
2387 break;
2388 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2389 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002390 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002391
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002392 vertices[0][0] = (float) (meta->dst.x + meta->width);
2393 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002394 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002395 vertices[1][0] = (float) meta->dst.x;
2396 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002397 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002398 vertices[2][0] = (float) meta->dst.x;
2399 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002400 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002401
Chia-I Wu29e6f502014-11-24 14:27:29 +08002402 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2403 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002404
Chia-I Wu29e6f502014-11-24 14:27:29 +08002405 vb_end = vb_start + sizeof(vertices) - 1;
2406 vb_stride = sizeof(vertices[0]);
2407 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2408 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2409 }
2410 break;
2411 default:
2412 assert(!"unknown meta mode");
2413 return;
2414 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002415 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002416
2417 /* 3DSTATE_VERTEX_BUFFERS */
2418 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002419
Chia-I Wu6032b892014-10-17 14:47:18 +08002420 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002421 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002422 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002423 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002424
2425 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002426 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2427 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002428
2429 dw[4] = 0;
2430
2431 /* 3DSTATE_VERTEX_ELEMENTS */
2432 cmd_batch_pointer(cmd, 5, &dw);
2433 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002434 dw[1] = GEN6_VE_DW0_VALID;
2435 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2436 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2437 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2438 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2439 dw[3] = GEN6_VE_DW0_VALID |
2440 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2441 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2442 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2443 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2444 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002445}
2446
Chia-I Wu29e6f502014-11-24 14:27:29 +08002447static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002448{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002449 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002450 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002451 uint32_t consts[8];
2452 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002453
2454 CMD_ASSERT(cmd, 6, 7.5);
2455
2456 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002457 case INTEL_DEV_META_VS_FILL_MEM:
2458 consts[0] = meta->dst.x;
2459 consts[1] = meta->clear_val[0];
2460 const_count = 2;
2461 break;
2462 case INTEL_DEV_META_VS_COPY_MEM:
2463 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2464 consts[0] = meta->dst.x;
2465 consts[1] = meta->src.x;
2466 const_count = 2;
2467 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002468 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2469 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2470 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2471 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2472 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2473 consts[0] = meta->src.x;
2474 consts[1] = meta->src.y;
2475 consts[2] = meta->width;
2476 consts[3] = meta->dst.x;
2477 const_count = 4;
2478 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002479 default:
2480 assert(!"unknown meta shader id");
2481 const_count = 0;
2482 break;
2483 }
2484
2485 /* this can be skipped but it makes state dumping prettier */
2486 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2487
2488 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2489}
2490
2491static void gen6_meta_vs(struct intel_cmd *cmd)
2492{
2493 const struct intel_cmd_meta *meta = cmd->bind.meta;
2494 const struct intel_pipeline_shader *sh =
2495 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2496 uint32_t offset, *dw;
2497
2498 CMD_ASSERT(cmd, 6, 7.5);
2499
2500 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002501 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002502
2503 /* 3DSTATE_CONSTANT_VS */
2504 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2505 cmd_batch_pointer(cmd, cmd_len, &dw);
2506 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2507 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2508
2509 /* 3DSTATE_VS */
2510 cmd_batch_pointer(cmd, 6, &dw);
2511 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2512 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2513
2514 return;
2515 }
2516
2517 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2518
2519 /* 3DSTATE_CONSTANT_VS */
2520 offset = gen6_meta_vs_constants(cmd);
2521 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2522 cmd_batch_pointer(cmd, 7, &dw);
2523 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002524 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002525 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002526 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002527 dw[4] = 0;
2528 dw[5] = 0;
2529 dw[6] = 0;
2530 } else {
2531 cmd_batch_pointer(cmd, 5, &dw);
2532 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002533 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002534 dw[1] = offset;
2535 dw[2] = 0;
2536 dw[3] = 0;
2537 dw[4] = 0;
2538 }
2539
2540 /* 3DSTATE_VS */
2541 offset = emit_shader(cmd, sh);
2542 cmd_batch_pointer(cmd, 6, &dw);
2543 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2544 dw[1] = offset;
2545 dw[2] = GEN6_THREADDISP_SPF |
2546 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2547 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002548 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002549 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2550 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2551
2552 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2553 GEN6_VS_DW5_VS_ENABLE;
2554 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002555 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002556 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002557 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002558
2559 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560}
2561
2562static void gen6_meta_disabled(struct intel_cmd *cmd)
2563{
Chia-I Wu6032b892014-10-17 14:47:18 +08002564 uint32_t *dw;
2565
2566 CMD_ASSERT(cmd, 6, 6);
2567
Chia-I Wu6032b892014-10-17 14:47:18 +08002568 /* 3DSTATE_CONSTANT_GS */
2569 cmd_batch_pointer(cmd, 5, &dw);
2570 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2571 dw[1] = 0;
2572 dw[2] = 0;
2573 dw[3] = 0;
2574 dw[4] = 0;
2575
2576 /* 3DSTATE_GS */
2577 cmd_batch_pointer(cmd, 7, &dw);
2578 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2579 dw[1] = 0;
2580 dw[2] = 0;
2581 dw[3] = 0;
2582 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2583 dw[5] = GEN6_GS_DW5_STATISTICS;
2584 dw[6] = 0;
2585
Chia-I Wu6032b892014-10-17 14:47:18 +08002586 /* 3DSTATE_SF */
2587 cmd_batch_pointer(cmd, 20, &dw);
2588 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2589 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2590 memset(&dw[2], 0, 18 * sizeof(*dw));
2591}
2592
2593static void gen7_meta_disabled(struct intel_cmd *cmd)
2594{
2595 uint32_t *dw;
2596
2597 CMD_ASSERT(cmd, 7, 7.5);
2598
Chia-I Wu6032b892014-10-17 14:47:18 +08002599 /* 3DSTATE_CONSTANT_HS */
2600 cmd_batch_pointer(cmd, 7, &dw);
2601 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2602 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2603
2604 /* 3DSTATE_HS */
2605 cmd_batch_pointer(cmd, 7, &dw);
2606 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2607 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2608
2609 /* 3DSTATE_TE */
2610 cmd_batch_pointer(cmd, 4, &dw);
2611 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2612 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2613
2614 /* 3DSTATE_CONSTANT_DS */
2615 cmd_batch_pointer(cmd, 7, &dw);
2616 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2617 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2618
2619 /* 3DSTATE_DS */
2620 cmd_batch_pointer(cmd, 6, &dw);
2621 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2622 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2623
2624 /* 3DSTATE_CONSTANT_GS */
2625 cmd_batch_pointer(cmd, 7, &dw);
2626 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2627 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2628
2629 /* 3DSTATE_GS */
2630 cmd_batch_pointer(cmd, 7, &dw);
2631 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2632 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2633
2634 /* 3DSTATE_STREAMOUT */
2635 cmd_batch_pointer(cmd, 3, &dw);
2636 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2637 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2638
Chia-I Wu6032b892014-10-17 14:47:18 +08002639 /* 3DSTATE_SF */
2640 cmd_batch_pointer(cmd, 7, &dw);
2641 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2642 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2643
2644 /* 3DSTATE_SBE */
2645 cmd_batch_pointer(cmd, 14, &dw);
2646 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2647 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2648 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002649}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002650
Chia-I Wu29e6f502014-11-24 14:27:29 +08002651static void gen6_meta_clip(struct intel_cmd *cmd)
2652{
2653 const struct intel_cmd_meta *meta = cmd->bind.meta;
2654 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002655
Chia-I Wu29e6f502014-11-24 14:27:29 +08002656 /* 3DSTATE_CLIP */
2657 cmd_batch_pointer(cmd, 4, &dw);
2658 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2659 dw[1] = 0;
2660 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2661 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2662 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2663 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002664 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002665 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002666 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002667}
2668
2669static void gen6_meta_wm(struct intel_cmd *cmd)
2670{
2671 const struct intel_cmd_meta *meta = cmd->bind.meta;
2672 uint32_t *dw;
2673
2674 CMD_ASSERT(cmd, 6, 7.5);
2675
2676 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2677
2678 /* 3DSTATE_MULTISAMPLE */
2679 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2680 cmd_batch_pointer(cmd, 4, &dw);
2681 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2682 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2683 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2684 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2685 dw[2] = 0;
2686 dw[3] = 0;
2687 } else {
2688 cmd_batch_pointer(cmd, 3, &dw);
2689 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2690 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2691 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2692 dw[2] = 0;
2693 }
2694
2695 /* 3DSTATE_SAMPLE_MASK */
2696 cmd_batch_pointer(cmd, 2, &dw);
2697 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2698 dw[1] = (1 << meta->samples) - 1;
2699
2700 /* 3DSTATE_DRAWING_RECTANGLE */
2701 cmd_batch_pointer(cmd, 4, &dw);
2702 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002703 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2704 /* unused */
2705 dw[1] = 0;
2706 dw[2] = 0;
2707 } else {
2708 dw[1] = meta->dst.y << 16 | meta->dst.x;
2709 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2710 (meta->dst.x + meta->width - 1);
2711 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002712 dw[3] = 0;
2713}
2714
2715static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2716{
2717 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002718 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002719 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002720 uint32_t consts[8];
2721 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002722
2723 CMD_ASSERT(cmd, 6, 7.5);
2724
2725 /* underflow is fine here */
2726 offset_x = meta->src.x - meta->dst.x;
2727 offset_y = meta->src.y - meta->dst.y;
2728
2729 switch (meta->shader_id) {
2730 case INTEL_DEV_META_FS_COPY_MEM:
2731 case INTEL_DEV_META_FS_COPY_1D:
2732 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2733 case INTEL_DEV_META_FS_COPY_2D:
2734 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2735 case INTEL_DEV_META_FS_COPY_2D_MS:
2736 consts[0] = offset_x;
2737 consts[1] = offset_y;
2738 consts[2] = meta->src.layer;
2739 consts[3] = meta->src.lod;
2740 const_count = 4;
2741 break;
2742 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2743 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2744 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2745 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2746 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2747 consts[0] = offset_x;
2748 consts[1] = offset_y;
2749 consts[2] = meta->src.layer;
2750 consts[3] = meta->src.lod;
2751 consts[4] = meta->src.x;
2752 consts[5] = meta->width;
2753 const_count = 6;
2754 break;
2755 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2756 consts[0] = offset_x;
2757 consts[1] = offset_y;
2758 consts[2] = meta->width;
2759 const_count = 3;
2760 break;
2761 case INTEL_DEV_META_FS_CLEAR_COLOR:
2762 consts[0] = meta->clear_val[0];
2763 consts[1] = meta->clear_val[1];
2764 consts[2] = meta->clear_val[2];
2765 consts[3] = meta->clear_val[3];
2766 const_count = 4;
2767 break;
2768 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2769 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002770 consts[1] = meta->clear_val[1];
2771 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002772 break;
2773 case INTEL_DEV_META_FS_RESOLVE_2X:
2774 case INTEL_DEV_META_FS_RESOLVE_4X:
2775 case INTEL_DEV_META_FS_RESOLVE_8X:
2776 case INTEL_DEV_META_FS_RESOLVE_16X:
2777 consts[0] = offset_x;
2778 consts[1] = offset_y;
2779 const_count = 2;
2780 break;
2781 default:
2782 assert(!"unknown meta shader id");
2783 const_count = 0;
2784 break;
2785 }
2786
2787 /* this can be skipped but it makes state dumping prettier */
2788 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2789
2790 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2791}
2792
2793static void gen6_meta_ps(struct intel_cmd *cmd)
2794{
2795 const struct intel_cmd_meta *meta = cmd->bind.meta;
2796 const struct intel_pipeline_shader *sh =
2797 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2798 uint32_t offset, *dw;
2799
2800 CMD_ASSERT(cmd, 6, 6);
2801
Chia-I Wu29e6f502014-11-24 14:27:29 +08002802 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2803 /* 3DSTATE_CONSTANT_PS */
2804 cmd_batch_pointer(cmd, 5, &dw);
2805 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2806 dw[1] = 0;
2807 dw[2] = 0;
2808 dw[3] = 0;
2809 dw[4] = 0;
2810
2811 /* 3DSTATE_WM */
2812 cmd_batch_pointer(cmd, 9, &dw);
2813 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2814 dw[1] = 0;
2815 dw[2] = 0;
2816 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002817
2818 switch (meta->ds.op) {
2819 case INTEL_CMD_META_DS_HIZ_CLEAR:
2820 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2821 break;
2822 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2823 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2824 break;
2825 case INTEL_CMD_META_DS_RESOLVE:
2826 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2827 break;
2828 default:
2829 dw[4] = 0;
2830 break;
2831 }
2832
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002833 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002834 dw[6] = 0;
2835 dw[7] = 0;
2836 dw[8] = 0;
2837
Chia-I Wu3adf7212014-10-24 15:34:07 +08002838 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002839 }
2840
Chia-I Wu3adf7212014-10-24 15:34:07 +08002841 /* a normal color write */
2842 assert(meta->dst.valid && !sh->uses);
2843
Chia-I Wu6032b892014-10-17 14:47:18 +08002844 /* 3DSTATE_CONSTANT_PS */
2845 offset = gen6_meta_ps_constants(cmd);
2846 cmd_batch_pointer(cmd, 5, &dw);
2847 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002848 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002849 dw[1] = offset;
2850 dw[2] = 0;
2851 dw[3] = 0;
2852 dw[4] = 0;
2853
2854 /* 3DSTATE_WM */
2855 offset = emit_shader(cmd, sh);
2856 cmd_batch_pointer(cmd, 9, &dw);
2857 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2858 dw[1] = offset;
2859 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2860 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002861 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002862 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002863 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002864 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2865 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002866
Chia-I Wu6032b892014-10-17 14:47:18 +08002867 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002868 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002869 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2870 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2871 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2872 if (meta->samples > 1) {
2873 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2874 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2875 } else {
2876 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2877 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2878 }
2879 dw[7] = 0;
2880 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002881
2882 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002883}
2884
2885static void gen7_meta_ps(struct intel_cmd *cmd)
2886{
2887 const struct intel_cmd_meta *meta = cmd->bind.meta;
2888 const struct intel_pipeline_shader *sh =
2889 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2890 uint32_t offset, *dw;
2891
2892 CMD_ASSERT(cmd, 7, 7.5);
2893
Chia-I Wu29e6f502014-11-24 14:27:29 +08002894 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2895 /* 3DSTATE_WM */
2896 cmd_batch_pointer(cmd, 3, &dw);
2897 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002898
2899 switch (meta->ds.op) {
2900 case INTEL_CMD_META_DS_HIZ_CLEAR:
2901 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2902 break;
2903 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2904 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2905 break;
2906 case INTEL_CMD_META_DS_RESOLVE:
2907 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2908 break;
2909 default:
2910 dw[1] = 0;
2911 break;
2912 }
2913
2914 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002915
2916 /* 3DSTATE_CONSTANT_GS */
2917 cmd_batch_pointer(cmd, 7, &dw);
2918 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2919 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2920
2921 /* 3DSTATE_PS */
2922 cmd_batch_pointer(cmd, 8, &dw);
2923 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2924 dw[1] = 0;
2925 dw[2] = 0;
2926 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002927 /* required to avoid hangs */
2928 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002929 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002930 dw[5] = 0;
2931 dw[6] = 0;
2932 dw[7] = 0;
2933
Chia-I Wu3adf7212014-10-24 15:34:07 +08002934 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002935 }
2936
Chia-I Wu3adf7212014-10-24 15:34:07 +08002937 /* a normal color write */
2938 assert(meta->dst.valid && !sh->uses);
2939
Chia-I Wu6032b892014-10-17 14:47:18 +08002940 /* 3DSTATE_WM */
2941 cmd_batch_pointer(cmd, 3, &dw);
2942 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002943 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002944 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2945 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2946 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2947 dw[2] = 0;
2948
2949 /* 3DSTATE_CONSTANT_PS */
2950 offset = gen6_meta_ps_constants(cmd);
2951 cmd_batch_pointer(cmd, 7, &dw);
2952 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002953 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002954 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002955 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002956 dw[4] = 0;
2957 dw[5] = 0;
2958 dw[6] = 0;
2959
2960 /* 3DSTATE_PS */
2961 offset = emit_shader(cmd, sh);
2962 cmd_batch_pointer(cmd, 8, &dw);
2963 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2964 dw[1] = offset;
2965 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2966 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002967 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002968
2969 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2970 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002971 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002972
2973 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002974 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002975 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002976 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002977 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002978 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002979
2980 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2981 dw[6] = 0;
2982 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002983
2984 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002985}
2986
2987static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2988{
2989 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002990 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002991
2992 CMD_ASSERT(cmd, 6, 7.5);
2993
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002994 if (!ds) {
2995 /* all zeros */
2996 static const struct intel_ds_view null_ds;
2997 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002998 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002999
3000 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003001 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3002 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3003 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003004
3005 if (cmd_gen(cmd) >= INTEL_GEN(7))
3006 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3007 else
3008 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003009}
3010
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003011static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3012 const struct intel_pipeline *pipeline)
3013{
3014 cmd->bind.pipeline.graphics = pipeline;
3015}
3016
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003017static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3018 const struct intel_pipeline *pipeline)
3019{
3020 cmd->bind.pipeline.compute = pipeline;
3021}
3022
3023static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
3024 const struct intel_pipeline_delta *delta)
3025{
3026 cmd->bind.pipeline.graphics_delta = delta;
3027}
3028
3029static void cmd_bind_compute_delta(struct intel_cmd *cmd,
3030 const struct intel_pipeline_delta *delta)
3031{
3032 cmd->bind.pipeline.compute_delta = delta;
3033}
3034
3035static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003036 const struct intel_desc_set *dset,
3037 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003038{
Chia-I Wuf8385062015-01-04 16:27:24 +08003039 const uint32_t size = sizeof(*dynamic_offsets) *
3040 dset->layout->dynamic_desc_count;
3041
3042 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
3043 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003044 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003045
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003046 cmd->bind.dset.graphics_dynamic_offsets = intel_alloc(cmd,
3047 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003048 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003049 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003050 return;
3051 }
3052
3053 cmd->bind.dset.graphics_dynamic_offset_size = size;
3054 }
3055
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003056 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003057 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003058}
3059
3060static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003061 const struct intel_desc_set *dset,
3062 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003063{
Chia-I Wuf8385062015-01-04 16:27:24 +08003064 const uint32_t size = sizeof(*dynamic_offsets) *
3065 dset->layout->dynamic_desc_count;
3066
3067 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
3068 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003069 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003070
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003071 cmd->bind.dset.compute_dynamic_offsets = intel_alloc(cmd,
3072 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003073 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003074 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003075 return;
3076 }
3077
3078 cmd->bind.dset.compute_dynamic_offset_size = size;
3079 }
3080
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003081 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003082 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003083}
3084
Chia-I Wu3b04af52014-11-08 10:48:20 +08003085static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003086 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003087 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003088{
Chia-I Wu714df452015-01-01 07:55:04 +08003089 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003090 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003091 return;
3092 }
3093
Chia-I Wu714df452015-01-01 07:55:04 +08003094 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003095 cmd->bind.vertex.offset[binding] = offset;
3096}
3097
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003098static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003099 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003100 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3101{
Chia-I Wu714df452015-01-01 07:55:04 +08003102 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003103 cmd->bind.index.offset = offset;
3104 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003105}
3106
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003108 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003109{
3110 cmd->bind.state.viewport = state;
3111}
3112
3113static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003114 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115{
3116 cmd->bind.state.raster = state;
3117}
3118
3119static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003120 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003121{
3122 cmd->bind.state.ds = state;
3123}
3124
3125static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003126 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127{
3128 cmd->bind.state.blend = state;
3129}
3130
Chia-I Wuf98dd882015-02-10 04:17:47 +08003131static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3132{
3133 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3134 struct intel_pipeline_rmap *rmaps[5] = {
3135 pipeline->vs.rmap,
3136 pipeline->tcs.rmap,
3137 pipeline->tes.rmap,
3138 pipeline->gs.rmap,
3139 pipeline->fs.rmap,
3140 };
3141 uint32_t max_write;
3142 int i;
3143
3144 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3145 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3146 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3147
3148 /* pad first */
3149 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3150
3151 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3152 const struct intel_pipeline_rmap *rmap = rmaps[i];
3153 const uint32_t surface_count = (rmap) ?
3154 rmap->rt_count + rmap->texture_resource_count +
3155 rmap->resource_count + rmap->uav_count : 0;
3156
3157 if (surface_count) {
3158 /* SURFACE_STATEs */
3159 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3160
3161 /* BINDING_TABLE_STATE */
3162 max_write += u_align(sizeof(uint32_t) * surface_count,
3163 GEN6_ALIGNMENT_SURFACE_STATE);
3164 }
3165 }
3166
3167 return max_write;
3168}
3169
3170static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3171{
3172 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3173 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3174 uint32_t max_surface_write;
3175
3176 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3177 if (cmd->bind.meta)
3178 max_surface_write = 64 * sizeof(uint32_t);
3179 else
3180 max_surface_write = cmd_get_max_surface_write(cmd);
3181
3182 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3183 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3184 /* SBA expects page-aligned addresses */
3185 writer->sba_offset = writer->used & ~0xfff;
3186
3187 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3188
3189 cmd_batch_state_base_address(cmd);
3190 }
3191}
3192
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003193static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003194 uint32_t vertex_start,
3195 uint32_t vertex_count,
3196 uint32_t instance_start,
3197 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003198 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003199 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003200{
3201 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003202 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003203 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3204
3205 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206
3207 emit_bounded_states(cmd);
3208
Chia-I Wuf98dd882015-02-10 04:17:47 +08003209 /* sanity check on cmd_get_max_surface_write() */
3210 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3211 surface_writer_used <= cmd_get_max_surface_write(cmd));
3212
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213 if (indexed) {
3214 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003215 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003216
3217 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3218 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3219 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003220 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003221 cmd->bind.index.offset, cmd->bind.index.type,
3222 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003223 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003224 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225 cmd->bind.index.offset, cmd->bind.index.type,
3226 p->primitive_restart);
3227 }
3228 } else {
3229 assert(!vertex_base);
3230 }
3231
3232 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3233 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3234 vertex_start, instance_count, instance_start, vertex_base);
3235 } else {
3236 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3237 vertex_start, instance_count, instance_start, vertex_base);
3238 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003239
Chia-I Wu707a29e2014-08-27 12:51:47 +08003240 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003241 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003242 /* need to re-emit all workarounds */
3243 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003244
3245 if (intel_debug & INTEL_DEBUG_NOCACHE)
3246 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003247}
3248
Chia-I Wuc14d1562014-10-17 09:49:22 +08003249void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3250{
Chia-I Wu6032b892014-10-17 14:47:18 +08003251 cmd->bind.meta = meta;
3252
Chia-I Wuf98dd882015-02-10 04:17:47 +08003253 cmd_adjust_state_base_address(cmd);
3254
Chia-I Wu6032b892014-10-17 14:47:18 +08003255 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003256 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003257
3258 gen6_meta_dynamic_states(cmd);
3259 gen6_meta_surface_states(cmd);
3260
3261 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3262 gen7_meta_urb(cmd);
3263 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003264 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003265 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003266 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003267 gen6_meta_wm(cmd);
3268 gen7_meta_ps(cmd);
3269 gen6_meta_depth_buffer(cmd);
3270
3271 cmd_wa_gen7_post_command_cs_stall(cmd);
3272 cmd_wa_gen7_post_command_depth_stall(cmd);
3273
Chia-I Wu29e6f502014-11-24 14:27:29 +08003274 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3275 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003276 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003277 } else {
3278 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3279 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003280 } else {
3281 gen6_meta_urb(cmd);
3282 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003283 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003284 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003285 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003286 gen6_meta_wm(cmd);
3287 gen6_meta_ps(cmd);
3288 gen6_meta_depth_buffer(cmd);
3289
Chia-I Wu29e6f502014-11-24 14:27:29 +08003290 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3291 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003292 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003293 } else {
3294 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3295 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003296 }
3297
3298 cmd->bind.draw_count++;
3299 /* need to re-emit all workarounds */
3300 cmd->bind.wa_flags = 0;
3301
3302 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003303
Chia-I Wubbc7d912015-02-27 14:59:50 -07003304 /* make the normal path believe the render pass has changed */
3305 cmd->bind.render_pass_changed = true;
3306
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003307 if (intel_debug & INTEL_DEBUG_NOCACHE)
3308 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003309}
3310
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003311ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003312 XGL_CMD_BUFFER cmdBuffer,
3313 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3314 XGL_PIPELINE pipeline)
3315{
3316 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3317
3318 switch (pipelineBindPoint) {
3319 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003320 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003321 break;
3322 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003323 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003324 break;
3325 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003326 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003327 break;
3328 }
3329}
3330
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003331ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003332 XGL_CMD_BUFFER cmdBuffer,
3333 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3334 XGL_PIPELINE_DELTA delta)
3335{
3336 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3337
3338 switch (pipelineBindPoint) {
3339 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003340 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003341 break;
3342 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003343 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003344 break;
3345 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003346 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003347 break;
3348 }
3349}
3350
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003351ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003352 XGL_CMD_BUFFER cmdBuffer,
3353 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003354 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003355{
3356 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3357
3358 switch (stateBindPoint) {
3359 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003360 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003361 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003362 break;
3363 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003364 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003365 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003366 break;
3367 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003368 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003369 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003370 break;
3371 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003372 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003373 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003374 break;
3375 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003376 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003377 break;
3378 }
3379}
3380
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003381ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003382 XGL_CMD_BUFFER cmdBuffer,
3383 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003384 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003385 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003386{
3387 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003388 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003389
3390 switch (pipelineBindPoint) {
3391 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003392 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003393 break;
3394 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003395 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003396 break;
3397 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003398 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003399 break;
3400 }
3401}
3402
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003403ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003404 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003405 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003406 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003407 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003408{
3409 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003410 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003411
Chia-I Wu714df452015-01-01 07:55:04 +08003412 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003413}
3414
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003415ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003416 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003417 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003418 XGL_GPU_SIZE offset,
3419 XGL_INDEX_TYPE indexType)
3420{
3421 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003422 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003423
Chia-I Wu714df452015-01-01 07:55:04 +08003424 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003425}
3426
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003427ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003428 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003429 uint32_t firstVertex,
3430 uint32_t vertexCount,
3431 uint32_t firstInstance,
3432 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003433{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003434 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003435
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003436 cmd_draw(cmd, firstVertex, vertexCount,
3437 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003438}
3439
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003440ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003441 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003442 uint32_t firstIndex,
3443 uint32_t indexCount,
3444 int32_t vertexOffset,
3445 uint32_t firstInstance,
3446 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003447{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003448 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003449
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003450 cmd_draw(cmd, firstIndex, indexCount,
3451 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003452}
3453
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003454ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003455 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003456 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003457 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003458 uint32_t count,
3459 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003460{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003461 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3462
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003463 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003464}
3465
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003466ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003467 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003468 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003469 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003470 uint32_t count,
3471 uint32_t stride)
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);
3474
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003475 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003476}
3477
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003478ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003479 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003480 uint32_t x,
3481 uint32_t y,
3482 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003483{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003484 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3485
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003486 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003487}
3488
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003489ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003490 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003491 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003492 XGL_GPU_SIZE offset)
3493{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003494 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3495
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003496 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003497}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003498
Chia-I Wude26bdf2015-02-18 15:47:12 -07003499ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003500 XGL_CMD_BUFFER cmdBuffer,
3501 XGL_RENDER_PASS renderPass)
3502{
3503 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3504
3505 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3506}
3507
Chia-I Wude26bdf2015-02-18 15:47:12 -07003508ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003509 XGL_CMD_BUFFER cmdBuffer,
3510 XGL_RENDER_PASS renderPass)
3511{
3512 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3513
3514 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3515}