blob: 00851e54e95a02360370963efaf58da38c7cc474 [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:
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600402 assert(!cmd->bind.fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800403 format = 0;
404 break;
405 }
406
407 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
408 }
409
Tony Barbourfa6cac72015-01-16 14:27:35 -0700410 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800411
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700412 /* Scissor is always enabled */
413 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
414
Tony Barbourfa6cac72015-01-16 14:27:35 -0700415 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800416 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
417 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
418 } else {
419 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
420 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
421 }
422
Chia-I Wu8016a172014-08-29 18:31:32 +0800423 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
424 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
425 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800426 GEN7_SF_DW3_SUBPIXEL_8BITS;
427
428 if (pipeline->use_rs_point_size) {
429 int point_width;
430
431 /* in U8.3 */
432 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
433 point_width = U_CLAMP(point_width, 1, 2047);
434
435 dw3 |= GEN7_SF_DW3_USE_POINT_WIDTH | point_width;
436 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800437
438 body[0] = dw1;
439 body[1] = dw2;
440 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700441 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
442 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
443 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800444}
445
Chia-I Wu8016a172014-08-29 18:31:32 +0800446static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
447{
448 const uint8_t cmd_len = 20;
449 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
450 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800451 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800453 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800454
455 CMD_ASSERT(cmd, 6, 6);
456
457 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800458
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 cmd_batch_pointer(cmd, cmd_len, &dw);
460 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800461 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800462 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800463 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800464}
465
466static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
467{
468 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800469 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800470
471 CMD_ASSERT(cmd, 7, 7.5);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
475 (cmd_len - 2);
476 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800477}
478
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800479static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
480{
481 const uint8_t cmd_len = 4;
482 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
483 (cmd_len - 2);
484 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700485 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800486 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700487 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800488 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800489
490 CMD_ASSERT(cmd, 6, 7.5);
491
492 dw1 = GEN6_CLIP_DW1_STATISTICS;
493 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
494 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
495 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700496 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800497 }
498
499 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
500 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700501 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800502 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
503 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
504 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
505
Chia-I Wub6386202015-03-24 11:13:06 +0800506 if (pipeline->depth_zero_to_one)
507 dw2 |= GEN6_CLIP_DW2_APIMODE_D3D;
508 else
509 dw2 |= GEN6_CLIP_DW2_APIMODE_OGL;
510
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 if (pipeline->rasterizerDiscardEnable)
512 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
513 else
514 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
515
516 if (pipeline->depthClipEnable)
517 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
518
519 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
520 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
521 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
522 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
523
524 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
525 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
526 (viewport->viewport_count - 1);
527
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600528 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600529 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600530 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
531 }
532
Chia-I Wu72292b72014-09-09 10:48:33 +0800533 cmd_batch_pointer(cmd, cmd_len, &dw);
534 dw[0] = dw0;
535 dw[1] = dw1;
536 dw[2] = dw2;
537 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800538}
539
Chia-I Wu784d3042014-12-19 14:30:04 +0800540static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600541 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800542 const struct intel_pipeline *pipeline,
543 const struct intel_pipeline_shader *sh)
544{
545 int scratch_space;
546
547 CMD_ASSERT(cmd, 6, 7.5);
548
549 assert(sh->per_thread_scratch_size &&
550 sh->per_thread_scratch_size % 1024 == 0 &&
551 u_is_pow2(sh->per_thread_scratch_size) &&
552 sh->scratch_offset % 1024 == 0);
553 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
554
555 cmd_reserve_reloc(cmd, 1);
556 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
557 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
558}
559
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
561{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800562 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800563 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800564 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600565 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700566 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800567
568 CMD_ASSERT(cmd, 6, 6);
569
570 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
571
572 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
573 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
574
575 dw4 = GEN6_WM_DW4_STATISTICS |
576 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
577 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700578 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800579
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800580 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700581 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
582 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583
Cody Northrope86574e2015-02-24 14:15:29 -0700584 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700585 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700586
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800587 if (fs->uses & INTEL_SHADER_USE_KILL ||
588 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700589 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800590
Cody Northrope238deb2015-01-26 14:41:36 -0700591 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800592 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
593 if (fs->uses & INTEL_SHADER_USE_DEPTH)
594 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
595 if (fs->uses & INTEL_SHADER_USE_W)
596 dw5 |= GEN6_WM_DW5_PS_USE_W;
597
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700598 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700599 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800600
601 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700602 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603 GEN6_WM_DW6_ZW_INTERP_PIXEL |
604 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
605 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
606
Tony Barbourfa6cac72015-01-16 14:27:35 -0700607 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800608 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
609 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
610 } else {
611 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
612 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
613 }
614
Cody Northrope86574e2015-02-24 14:15:29 -0700615 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
616
Chia-I Wu784d3042014-12-19 14:30:04 +0800617 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800618 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800619 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[2] = dw2;
621 dw[3] = 0; /* scratch */
622 dw[4] = dw4;
623 dw[5] = dw5;
624 dw[6] = dw6;
625 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700626 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800627
628 if (fs->per_thread_scratch_size)
629 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630}
631
632static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
633{
634 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800635 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800636 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800637 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638
639 CMD_ASSERT(cmd, 7, 7.5);
640
641 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
642
643 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700644 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645 GEN7_WM_DW1_ZW_INTERP_PIXEL |
646 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
647 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
648
649 if (fs->uses & INTEL_SHADER_USE_KILL ||
650 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700651 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800652
Cody Northrope238deb2015-01-26 14:41:36 -0700653 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_DEPTH)
656 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
657 if (fs->uses & INTEL_SHADER_USE_W)
658 dw1 |= GEN7_WM_DW1_PS_USE_W;
659
660 dw2 = 0;
661
Tony Barbourfa6cac72015-01-16 14:27:35 -0700662 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
664 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
665 } else {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
668 }
669
Chia-I Wu72292b72014-09-09 10:48:33 +0800670 cmd_batch_pointer(cmd, cmd_len, &dw);
671 dw[0] = dw0;
672 dw[1] = dw1;
673 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674}
675
676static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
677{
678 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800679 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800680 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700681 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600682 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683
684 CMD_ASSERT(cmd, 7, 7.5);
685
686 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
687
688 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
689 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
690
691 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700692 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693
Cody Northrope86574e2015-02-24 14:15:29 -0700694 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700695 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700696
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800698 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700699 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800700 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800701 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800702 }
703
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 if (fs->in_count)
705 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
706
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700707 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800708 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
709
710 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
711 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700712 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
713
714 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715
Chia-I Wu784d3042014-12-19 14:30:04 +0800716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800718 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800719 dw[2] = dw2;
720 dw[3] = 0; /* scratch */
721 dw[4] = dw4;
722 dw[5] = dw5;
723 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700724 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800725
726 if (fs->per_thread_scratch_size)
727 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800728}
729
Chia-I Wu8ada4242015-03-02 11:19:33 -0700730static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
731 uint32_t sample_count)
732{
733 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
734 uint32_t dw1, dw2, dw3, *dw;
735
736 CMD_ASSERT(cmd, 6, 7.5);
737
738 switch (sample_count) {
739 case 4:
740 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
741 dw2 = cmd->dev->sample_pattern_4x;
742 dw3 = 0;
743 break;
744 case 8:
745 assert(cmd_gen(cmd) >= INTEL_GEN(7));
746 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
747 dw2 = cmd->dev->sample_pattern_8x[0];
748 dw3 = cmd->dev->sample_pattern_8x[1];
749 break;
750 default:
751 assert(sample_count <= 1);
752 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
753 dw2 = 0;
754 dw3 = 0;
755 break;
756 }
757
758 cmd_batch_pointer(cmd, cmd_len, &dw);
759
760 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
761 dw[1] = dw1;
762 dw[2] = dw2;
763 if (cmd_gen(cmd) >= INTEL_GEN(7))
764 dw[3] = dw3;
765}
766
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700768 const struct intel_ds_view *view,
769 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770{
771 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800772 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600773 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800774
775 CMD_ASSERT(cmd, 6, 7.5);
776
777 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800778 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
779 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800780 dw0 |= (cmd_len - 2);
781
Chia-I Wu72292b72014-09-09 10:48:33 +0800782 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
783 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700784
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700786 /* note that we only enable HiZ on Gen7+ */
787 if (!optimal_ds)
788 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
789
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 dw[2] = 0;
791 dw[3] = view->cmd[2];
792 dw[4] = view->cmd[3];
793 dw[5] = view->cmd[4];
794 dw[6] = view->cmd[5];
795
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600796 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800797 cmd_reserve_reloc(cmd, 1);
798 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
799 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600800 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800801}
802
803static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700804 const struct intel_ds_view *view,
805 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800806{
807 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800808 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600809 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810
811 CMD_ASSERT(cmd, 6, 7.5);
812
813 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800814 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
815 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800816 dw0 |= (cmd_len - 2);
817
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
819 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800820
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700821 if (view->has_stencil) {
822 dw[1] = view->cmd[6];
823
Chia-I Wu72292b72014-09-09 10:48:33 +0800824 cmd_reserve_reloc(cmd, 1);
825 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
826 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700827 } else {
828 dw[1] = 0;
829 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600830 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800831}
832
833static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700834 const struct intel_ds_view *view,
835 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800836{
837 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800838 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600839 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800840
841 CMD_ASSERT(cmd, 6, 7.5);
842
843 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800844 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
845 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800846 dw0 |= (cmd_len - 2);
847
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
849 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800850
Chia-I Wu73520ac2015-02-19 11:17:45 -0700851 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700852 dw[1] = view->cmd[8];
853
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 cmd_reserve_reloc(cmd, 1);
855 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
856 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700857 } else {
858 dw[1] = 0;
859 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600860 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800861}
862
Chia-I Wuf8231032014-08-25 10:44:45 +0800863static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
864 uint32_t clear_val)
865{
866 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800867 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800868 GEN6_CLEAR_PARAMS_DW0_VALID |
869 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 cmd_batch_pointer(cmd, cmd_len, &dw);
875 dw[0] = dw0;
876 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800877}
878
879static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
880 uint32_t clear_val)
881{
882 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800883 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800884 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800886
887 CMD_ASSERT(cmd, 7, 7.5);
888
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 cmd_batch_pointer(cmd, cmd_len, &dw);
890 dw[0] = dw0;
891 dw[1] = clear_val;
892 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800893}
894
Chia-I Wu302742d2014-08-22 10:28:29 +0800895static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t blend_offset,
897 uint32_t ds_offset,
898 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800899{
900 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800902
903 CMD_ASSERT(cmd, 6, 6);
904
Chia-I Wu426072d2014-08-26 14:31:55 +0800905 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800906 (cmd_len - 2);
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_batch_pointer(cmd, cmd_len, &dw);
909 dw[0] = dw0;
910 dw[1] = blend_offset | 1;
911 dw[2] = ds_offset | 1;
912 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800913}
914
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t clip_offset,
917 uint32_t sf_offset,
918 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800919{
920 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800921 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922
923 CMD_ASSERT(cmd, 6, 6);
924
Chia-I Wu426072d2014-08-26 14:31:55 +0800925 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700926 GEN6_VP_PTR_DW0_CLIP_CHANGED |
927 GEN6_VP_PTR_DW0_SF_CHANGED |
928 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800929 (cmd_len - 2);
930
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 cmd_batch_pointer(cmd, cmd_len, &dw);
932 dw[0] = dw0;
933 dw[1] = clip_offset;
934 dw[2] = sf_offset;
935 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936}
937
938static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800940{
941 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800943
944 CMD_ASSERT(cmd, 6, 6);
945
Chia-I Wu426072d2014-08-26 14:31:55 +0800946 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800947 (cmd_len - 2);
948
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 cmd_batch_pointer(cmd, cmd_len, &dw);
950 dw[0] = dw0;
951 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800952}
953
Chia-I Wu42a56202014-08-23 16:47:48 +0800954static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t vs_offset,
956 uint32_t gs_offset,
957 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800958{
959 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800960 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800961
962 CMD_ASSERT(cmd, 6, 6);
963
Chia-I Wu426072d2014-08-26 14:31:55 +0800964 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700965 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
966 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
967 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800968 (cmd_len - 2);
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 cmd_batch_pointer(cmd, cmd_len, &dw);
971 dw[0] = dw0;
972 dw[1] = vs_offset;
973 dw[2] = gs_offset;
974 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800975}
976
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800978 uint32_t vs_offset,
979 uint32_t gs_offset,
980 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800981{
982 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800984
985 CMD_ASSERT(cmd, 6, 6);
986
987 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700988 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
989 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
990 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800991 (cmd_len - 2);
992
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 cmd_batch_pointer(cmd, cmd_len, &dw);
994 dw[0] = dw0;
995 dw[1] = vs_offset;
996 dw[2] = gs_offset;
997 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800998}
999
Chia-I Wu302742d2014-08-22 10:28:29 +08001000static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001002{
1003 const uint8_t cmd_len = 2;
1004 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1005 GEN6_RENDER_SUBTYPE_3D |
1006 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001008
Chia-I Wu72292b72014-09-09 10:48:33 +08001009 cmd_batch_pointer(cmd, cmd_len, &dw);
1010 dw[0] = dw0;
1011 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wua6c4f152014-12-02 04:19:58 +08001014static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001015{
Chia-I Wue6073342014-11-30 09:43:42 +08001016 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001017 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1018 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001019
1020 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001021 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001022
Tony Barbourfa6cac72015-01-16 14:27:35 -07001023 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001024}
1025
Chia-I Wu72292b72014-09-09 10:48:33 +08001026static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001027 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001028{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001029 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001030 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001031 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001032 uint32_t dw[3];
1033
1034 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001035 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001037 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1038 (state->ds_info.stencilReadMask & 0xff) << 8 |
1039 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001040 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001041
1042 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001043
1044 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1045 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001046
Chia-I Wu00b51a82014-09-09 12:07:37 +08001047 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001048 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001049}
1050
Chia-I Wu72292b72014-09-09 10:48:33 +08001051static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001052 uint32_t stencil_ref,
1053 const uint32_t blend_color[4])
1054{
Chia-I Wue6073342014-11-30 09:43:42 +08001055 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001056 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001057 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001058
1059 CMD_ASSERT(cmd, 6, 7.5);
1060
Chia-I Wu00b51a82014-09-09 12:07:37 +08001061 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1062 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001063 dw[0] = stencil_ref;
1064 dw[1] = 0;
1065 dw[2] = blend_color[0];
1066 dw[3] = blend_color[1];
1067 dw[4] = blend_color[2];
1068 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001069
Chia-I Wu72292b72014-09-09 10:48:33 +08001070 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001071}
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001074{
Chia-I Wu8370b402014-08-29 12:28:37 +08001075 CMD_ASSERT(cmd, 6, 7.5);
1076
Chia-I Wu707a29e2014-08-27 12:51:47 +08001077 if (!cmd->bind.draw_count)
1078 return;
1079
Chia-I Wu8370b402014-08-29 12:28:37 +08001080 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001081 return;
1082
Chia-I Wu8370b402014-08-29 12:28:37 +08001083 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001084
1085 /*
1086 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1087 *
1088 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1089 * pipe-control with a post-sync op and no write-cache flushes."
1090 *
1091 * The workaround below necessitates this workaround.
1092 */
1093 gen6_PIPE_CONTROL(cmd,
1094 GEN6_PIPE_CONTROL_CS_STALL |
1095 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001096 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001097
Chia-I Wud6d079d2014-08-31 13:14:21 +08001098 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1099 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001100}
1101
Chia-I Wu8370b402014-08-29 12:28:37 +08001102static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001103{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001104 CMD_ASSERT(cmd, 6, 7.5);
1105
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001106 if (!cmd->bind.draw_count)
1107 return;
1108
Chia-I Wud6d079d2014-08-31 13:14:21 +08001109 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1110 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001111}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001112
Chia-I Wu8370b402014-08-29 12:28:37 +08001113static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1114{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001115 CMD_ASSERT(cmd, 7, 7.5);
1116
Chia-I Wu8370b402014-08-29 12:28:37 +08001117 if (!cmd->bind.draw_count)
1118 return;
1119
1120 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001121
1122 gen6_PIPE_CONTROL(cmd,
1123 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001124 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001125}
1126
Chia-I Wu8370b402014-08-29 12:28:37 +08001127static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1128{
1129 CMD_ASSERT(cmd, 7, 7.5);
1130
Chia-I Wu8370b402014-08-29 12:28:37 +08001131 /*
1132 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1133 *
1134 * "One of the following must also be set (when CS stall is set):
1135 *
1136 * * Render Target Cache Flush Enable ([12] of DW1)
1137 * * Depth Cache Flush Enable ([0] of DW1)
1138 * * Stall at Pixel Scoreboard ([1] of DW1)
1139 * * Depth Stall ([13] of DW1)
1140 * * Post-Sync Operation ([13] of DW1)"
1141 */
1142 gen6_PIPE_CONTROL(cmd,
1143 GEN6_PIPE_CONTROL_CS_STALL |
1144 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001145 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001146}
1147
1148static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1149{
1150 CMD_ASSERT(cmd, 7, 7.5);
1151
Chia-I Wu8370b402014-08-29 12:28:37 +08001152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
Chia-I Wud6d079d2014-08-31 13:14:21 +08001154 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
1156
1157static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1158{
1159 CMD_ASSERT(cmd, 6, 7.5);
1160
1161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 /*
1165 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1166 *
1167 * "Driver must guarentee that all the caches in the depth pipe are
1168 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1169 * requires driver to send a PIPE_CONTROL with a CS stall along with
1170 * a Depth Flush prior to this command."
1171 *
1172 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1173 *
1174 * "Driver must ierarchi that all the caches in the depth pipe are
1175 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1176 * requires driver to send a PIPE_CONTROL with a CS stall along with
1177 * a Depth Flush prior to this command.
1178 */
1179 gen6_PIPE_CONTROL(cmd,
1180 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1181 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001182 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001183}
1184
1185static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1186{
1187 CMD_ASSERT(cmd, 6, 7.5);
1188
1189 if (!cmd->bind.draw_count)
1190 return;
1191
1192 /*
1193 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1194 *
1195 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1196 * and a post sync operation prior to the group of depth
1197 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1198 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1199 *
1200 * This workaround satifies all the conditions.
1201 */
1202 cmd_wa_gen6_pre_depth_stall_write(cmd);
1203
1204 /*
1205 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1206 *
1207 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1208 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1209 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1210 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1211 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1212 * Depth Flush Bit set, followed by another pipelined depth stall
1213 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1214 * guarantee that the pipeline from WM onwards is already flushed
1215 * (e.g., via a preceding MI_FLUSH)."
1216 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1218 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1219 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001220}
1221
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001222void cmd_batch_state_base_address(struct intel_cmd *cmd)
1223{
1224 const uint8_t cmd_len = 10;
1225 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1226 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001227 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001228 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001229 uint32_t pos;
1230 uint32_t *dw;
1231
1232 CMD_ASSERT(cmd, 6, 7.5);
1233
1234 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1235
1236 dw[0] = dw0;
1237 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001238 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001239 dw[2] = 1;
1240 dw[3] = 1;
1241 dw[4] = 1;
1242 dw[5] = 1;
1243 /* end offsets */
1244 dw[6] = 1;
1245 dw[7] = 1 + 0xfffff000;
1246 dw[8] = 1 + 0xfffff000;
1247 dw[9] = 1;
1248
1249 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001250 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1251 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1252 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1253 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1254 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1255 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001256}
1257
Chia-I Wu7c853562015-02-27 14:35:08 -07001258void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1259{
1260 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1261 const uint8_t cmd_len = 2;
1262 uint32_t offset = 0;
1263 uint32_t *dw;
1264
1265 if (cmd_gen(cmd) <= INTEL_GEN(6))
1266 return;
1267
1268 CMD_ASSERT(cmd, 7, 7.5);
1269
1270 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1271 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1272 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1273 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1274 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1275 offset += size;
1276
1277 dw += 2;
1278 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1279 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1280 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1281
1282 dw += 2;
1283 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1284 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1285 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1286
1287 dw += 2;
1288 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1289 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1290 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1291
1292 dw += 2;
1293 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1294 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1295 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1296
1297 /*
1298 *
1299 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1300 *
1301 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1302 * in the ring after this instruction
1303 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1304 */
1305 cmd_wa_gen7_post_command_cs_stall(cmd);
1306}
1307
Chia-I Wu525c6602014-08-27 10:22:34 +08001308void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1309{
Mike Stroyan552fda42015-01-30 17:21:08 -07001310 if (pipe_control_dw0 == 0)
1311 return;
1312
Chia-I Wu525c6602014-08-27 10:22:34 +08001313 if (!cmd->bind.draw_count)
1314 return;
1315
1316 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1317
Chia-I Wu8370b402014-08-29 12:28:37 +08001318 /*
1319 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1320 *
1321 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1322 * PIPE_CONTROL with any non-zero post-sync-op is required."
1323 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001324 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001325 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001326
Chia-I Wu092279a2014-08-30 19:05:30 +08001327 /*
1328 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1329 *
1330 * "One of the following must also be set (when CS stall is set):
1331 *
1332 * * Render Target Cache Flush Enable ([12] of DW1)
1333 * * Depth Cache Flush Enable ([0] of DW1)
1334 * * Stall at Pixel Scoreboard ([1] of DW1)
1335 * * Depth Stall ([13] of DW1)
1336 * * Post-Sync Operation ([13] of DW1)"
1337 */
1338 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1339 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1340 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1341 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1342 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1343 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1344
Chia-I Wud6d079d2014-08-31 13:14:21 +08001345 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001346}
1347
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001348void cmd_batch_flush_all(struct intel_cmd *cmd)
1349{
1350 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1351 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1352 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1353 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1354 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1355 GEN6_PIPE_CONTROL_CS_STALL);
1356}
1357
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001358void cmd_batch_depth_count(struct intel_cmd *cmd,
1359 struct intel_bo *bo,
1360 XGL_GPU_SIZE offset)
1361{
1362 cmd_wa_gen6_pre_depth_stall_write(cmd);
1363
1364 gen6_PIPE_CONTROL(cmd,
1365 GEN6_PIPE_CONTROL_DEPTH_STALL |
1366 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001367 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001368}
1369
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001370void cmd_batch_timestamp(struct intel_cmd *cmd,
1371 struct intel_bo *bo,
1372 XGL_GPU_SIZE offset)
1373{
1374 /* need any WA or stall? */
1375 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1376}
1377
1378void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001379 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001380 struct intel_bo *bo,
1381 XGL_GPU_SIZE offset,
1382 uint64_t val)
1383{
1384 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001385 gen6_PIPE_CONTROL(cmd,
1386 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1387 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001388}
1389
Chia-I Wu302742d2014-08-22 10:28:29 +08001390static void gen6_cc_states(struct intel_cmd *cmd)
1391{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001392 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1393 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001395 uint32_t stencil_ref;
1396 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001397
1398 CMD_ASSERT(cmd, 6, 6);
1399
Chia-I Wua6c4f152014-12-02 04:19:58 +08001400 blend_offset = gen6_BLEND_STATE(cmd);
1401
1402 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001403 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001404 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001405 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001406
1407 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001408 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001409 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1410 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001411 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001413 stencil_ref = 0;
1414 }
1415
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001417
Chia-I Wu72292b72014-09-09 10:48:33 +08001418 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001419}
1420
Chia-I Wu1744cca2014-08-22 11:10:17 +08001421static void gen6_viewport_states(struct intel_cmd *cmd)
1422{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001423 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001425
1426 if (!viewport)
1427 return;
1428
Tony Barbourfa6cac72015-01-16 14:27:35 -07001429 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001430 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001431
1432 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001433 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001434 viewport->cmd);
1435
1436 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001437 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001438 &viewport->cmd[viewport->cmd_clip_pos]);
1439
1440 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001441 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001442 &viewport->cmd[viewport->cmd_cc_pos]);
1443
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001444 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1445 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1446 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001447
1448 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001449 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001450
Chia-I Wub1d450a2014-09-09 13:48:03 +08001451 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001452}
1453
Chia-I Wu302742d2014-08-22 10:28:29 +08001454static void gen7_cc_states(struct intel_cmd *cmd)
1455{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001456 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1457 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001458 uint32_t stencil_ref;
1459 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001460 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001461
1462 CMD_ASSERT(cmd, 7, 7.5);
1463
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001464 if (!blend && !ds)
1465 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001466
Chia-I Wua6c4f152014-12-02 04:19:58 +08001467 offset = gen6_BLEND_STATE(cmd);
1468 gen7_3dstate_pointer(cmd,
1469 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001470
Chia-I Wua6c4f152014-12-02 04:19:58 +08001471 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001472 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001473 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001474 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001475
1476 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001477 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001478 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1479 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001480 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001481 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1482 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001483 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1484 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001485 } else {
1486 stencil_ref = 0;
1487 }
1488
Chia-I Wu72292b72014-09-09 10:48:33 +08001489 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001490 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001491 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001492}
1493
Chia-I Wu1744cca2014-08-22 11:10:17 +08001494static void gen7_viewport_states(struct intel_cmd *cmd)
1495{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001496 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001497 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001498
1499 if (!viewport)
1500 return;
1501
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001502 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001503
Chia-I Wub1d450a2014-09-09 13:48:03 +08001504 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001505 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001507 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001508 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1509 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001510
1511 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001512 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001513 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001514 gen7_3dstate_pointer(cmd,
1515 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001516 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001517
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001518 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1519 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1520 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1521 gen7_3dstate_pointer(cmd,
1522 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1523 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001524}
1525
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001526static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001527 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001528{
1529 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001530 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001531
Chia-I Wu72292b72014-09-09 10:48:33 +08001532 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001533
1534 dw[0] = GEN6_RENDER_TYPE_RENDER |
1535 GEN6_RENDER_SUBTYPE_3D |
1536 subop | (cmd_len - 2);
1537 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001538 dw[2] = 0;
1539 dw[3] = 0;
1540 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001541}
1542
1543static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001544 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001545{
1546 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001547 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001548
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001550
1551 dw[0] = GEN6_RENDER_TYPE_RENDER |
1552 GEN6_RENDER_SUBTYPE_3D |
1553 subop | (cmd_len - 2);
1554 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001555 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001556 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 dw[4] = 0;
1558 dw[5] = 0;
1559 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001560}
1561
Chia-I Wu625105f2014-10-13 15:35:29 +08001562static uint32_t emit_samplers(struct intel_cmd *cmd,
1563 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001564{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001565 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1566 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001567 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001568 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001569 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001570 uint32_t surface_count;
1571 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001572
1573 CMD_ASSERT(cmd, 6, 7.5);
1574
Chia-I Wu625105f2014-10-13 15:35:29 +08001575 if (!rmap || !rmap->sampler_count)
1576 return 0;
1577
Cody Northrop40316a32014-12-09 19:08:33 -07001578 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001579
Chia-I Wudcb509d2014-12-10 08:53:10 +08001580 /*
1581 * note that we cannot call cmd_state_pointer() here as the following
1582 * cmd_state_pointer() would invalidate the pointer
1583 */
1584 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001585 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001586 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587
1588 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001589 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001590 4 * rmap->sampler_count, &sampler_dw);
1591
Chia-I Wudcb509d2014-12-10 08:53:10 +08001592 cmd_state_update(cmd, border_offset,
1593 border_stride * rmap->sampler_count, &border_dw);
1594
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001595 for (i = 0; i < rmap->sampler_count; i++) {
1596 const struct intel_pipeline_rmap_slot *slot =
1597 &rmap->slots[surface_count + i];
1598 const struct intel_sampler *sampler;
1599
Chia-I Wuf8385062015-01-04 16:27:24 +08001600 switch (slot->type) {
1601 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001602 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001603 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001604 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605 sampler = NULL;
1606 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001607 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001608 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001609 sampler = NULL;
1610 break;
1611 }
1612
1613 if (sampler) {
1614 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1615
1616 sampler_dw[0] = sampler->cmd[0];
1617 sampler_dw[1] = sampler->cmd[1];
1618 sampler_dw[2] = border_offset;
1619 sampler_dw[3] = sampler->cmd[2];
1620 } else {
1621 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1622 sampler_dw[1] = 0;
1623 sampler_dw[2] = 0;
1624 sampler_dw[3] = 0;
1625 }
1626
1627 border_offset += border_stride * 4;
1628 border_dw += border_stride;
1629 sampler_dw += 4;
1630 }
1631
Chia-I Wu625105f2014-10-13 15:35:29 +08001632 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001633}
1634
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001635static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001636 const struct intel_pipeline_rmap *rmap,
1637 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001638{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001639 const uint32_t sba_offset =
1640 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001641 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001642 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001643 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001644
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001645 CMD_ASSERT(cmd, 6, 7.5);
1646
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001647 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001648 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001649 if (!surface_count)
1650 return 0;
1651
Chia-I Wu42a56202014-08-23 16:47:48 +08001652 assert(surface_count <= ARRAY_SIZE(binding_table));
1653
1654 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001655 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001656 struct intel_null_view null_view;
1657 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001658
Chia-I Wuf8385062015-01-04 16:27:24 +08001659 switch (slot->type) {
1660 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001661 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001662 const struct intel_rt_view *view =
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001663 (slot->u.rt < cmd->bind.fb->rt_count) ?
1664 cmd->bind.fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001665
Chia-I Wu787a05b2014-12-05 11:02:20 +08001666 if (view) {
1667 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1668 GEN6_ALIGNMENT_SURFACE_STATE,
1669 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001670
Chia-I Wu787a05b2014-12-05 11:02:20 +08001671 cmd_reserve_reloc(cmd, 1);
1672 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1673 view->cmd[1], INTEL_RELOC_WRITE);
1674 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001675 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001676 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001677 }
1678 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001679 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001680 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001681 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1682 const struct intel_mem *mem;
1683 bool read_only;
1684 const uint32_t *cmd_data;
1685 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001686
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001687 assert(dyn_idx < 0 ||
1688 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001689
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001690 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1691 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001692 if (mem) {
1693 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1694 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1695 const uint32_t reloc_flags =
1696 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001697
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001698 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001699 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001700 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001701
1702 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001703 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1704 cmd_data[1] + dynamic_offset, reloc_flags);
1705 } else {
1706 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001707 }
1708 }
1709 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001710 case INTEL_PIPELINE_RMAP_UNUSED:
1711 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001712 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001713 default:
1714 assert(!"unexpected rmap type");
1715 need_null_view = true;
1716 break;
1717 }
1718
1719 if (need_null_view) {
1720 intel_null_view_init(&null_view, cmd->dev);
1721 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1722 GEN6_ALIGNMENT_SURFACE_STATE,
1723 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001724 }
1725
Chia-I Wuf98dd882015-02-10 04:17:47 +08001726 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001727 }
1728
Chia-I Wuf98dd882015-02-10 04:17:47 +08001729 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001730 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001731 surface_count, binding_table) - sba_offset;
1732
1733 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1734 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1735
1736 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001737}
1738
Chia-I Wu1d125092014-10-08 08:49:38 +08001739static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1740{
1741 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001742 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1743 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001744 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001745
1746 CMD_ASSERT(cmd, 6, 7.5);
1747
1748 if (!pipeline->vb_count)
1749 return;
1750
1751 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1752
1753 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1754 dw++;
1755 pos++;
1756
1757 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001758 assert(pipeline->vb[i].strideInBytes <= 2048);
1759
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001760 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001761 pipeline->vb[i].strideInBytes;
1762
Chia-I Wub3686982015-02-27 09:51:16 -07001763 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001764 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1765 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001766 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001767
1768 switch (pipeline->vb[i].stepRate) {
1769 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001770 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001771 dw[3] = 0;
1772 break;
1773 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
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] = 1;
1776 break;
1777 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001778 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001779 dw[3] = 0;
1780 break;
1781 default:
1782 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001783 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001784 dw[3] = 0;
1785 break;
1786 }
1787
Chia-I Wu714df452015-01-01 07:55:04 +08001788 if (cmd->bind.vertex.buf[i]) {
1789 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001790 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001791
1792 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001793 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1794 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001795 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001796 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001797 dw[1] = 0;
1798 dw[2] = 0;
1799 }
1800
1801 dw += 4;
1802 pos += 4;
1803 }
1804}
1805
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001806static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1807{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001808 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1809 const struct intel_pipeline_shader *vs = &pipeline->vs;
1810 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001811 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001812 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001813 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001814 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001815
1816 CMD_ASSERT(cmd, 6, 7.5);
1817
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001818 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001819 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1820 *
1821 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1822 * 128-bit vertex elements to be passed into the payload for each
1823 * vertex."
1824 *
1825 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1826 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001827 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001828 vue_read_len = (vs->in_count + 1) / 2;
1829 if (!vue_read_len)
1830 vue_read_len = 1;
1831
1832 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1833 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1834
1835 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1836 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1837 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001838
1839 dw5 = GEN6_VS_DW5_STATISTICS |
1840 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001841
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001842 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001843 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001844 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001845 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001846
Chia-I Wube0a3d92014-09-02 13:20:59 +08001847 if (pipeline->disable_vs_cache)
1848 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1849
Chia-I Wu784d3042014-12-19 14:30:04 +08001850 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001851 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001852 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001853 dw[2] = dw2;
1854 dw[3] = 0; /* scratch */
1855 dw[4] = dw4;
1856 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001857
1858 if (vs->per_thread_scratch_size)
1859 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001860}
1861
Chia-I Wu625105f2014-10-13 15:35:29 +08001862static void emit_shader_resources(struct intel_cmd *cmd)
1863{
1864 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001865 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001866
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001867 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001868 cmd->bind.pipeline.graphics->vs.rmap,
1869 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001870 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001871 cmd->bind.pipeline.graphics->tcs.rmap,
1872 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001873 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001874 cmd->bind.pipeline.graphics->tes.rmap,
1875 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001876 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001877 cmd->bind.pipeline.graphics->gs.rmap,
1878 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001879 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001880 cmd->bind.pipeline.graphics->fs.rmap,
1881 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001882
1883 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1884 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1885 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1886 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1887 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1888
1889 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1890 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001891 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1892 binding_tables[0]);
1893 gen7_3dstate_pointer(cmd,
1894 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1895 binding_tables[1]);
1896 gen7_3dstate_pointer(cmd,
1897 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1898 binding_tables[2]);
1899 gen7_3dstate_pointer(cmd,
1900 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1901 binding_tables[3]);
1902 gen7_3dstate_pointer(cmd,
1903 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1904 binding_tables[4]);
1905
1906 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001907 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1908 samplers[0]);
1909 gen7_3dstate_pointer(cmd,
1910 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1911 samplers[1]);
1912 gen7_3dstate_pointer(cmd,
1913 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1914 samplers[2]);
1915 gen7_3dstate_pointer(cmd,
1916 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1917 samplers[3]);
1918 gen7_3dstate_pointer(cmd,
1919 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1920 samplers[4]);
1921 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001922 assert(!binding_tables[1] && !binding_tables[2]);
1923 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1924 binding_tables[0], binding_tables[3], binding_tables[4]);
1925
Chia-I Wu625105f2014-10-13 15:35:29 +08001926 assert(!samplers[1] && !samplers[2]);
1927 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1928 samplers[0], samplers[3], samplers[4]);
1929 }
1930}
1931
Chia-I Wu8ada4242015-03-02 11:19:33 -07001932static void emit_msaa(struct intel_cmd *cmd)
1933{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001934 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07001935
Chia-I Wubbc7d912015-02-27 14:59:50 -07001936 if (!cmd->bind.render_pass_changed)
1937 return;
1938
Chia-I Wu8ada4242015-03-02 11:19:33 -07001939 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
1940 cmd->result = XGL_ERROR_UNKNOWN;
1941
1942 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1943 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1944}
1945
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001946static void emit_rt(struct intel_cmd *cmd)
1947{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001948 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07001949
1950 if (!cmd->bind.render_pass_changed)
1951 return;
1952
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001953 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001954 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
1955 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001956}
1957
1958static void emit_ds(struct intel_cmd *cmd)
1959{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06001960 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu73520ac2015-02-19 11:17:45 -07001961 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001962
Chia-I Wubbc7d912015-02-27 14:59:50 -07001963 if (!cmd->bind.render_pass_changed)
1964 return;
1965
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001966 if (!ds) {
1967 /* all zeros */
1968 static const struct intel_ds_view null_ds;
1969 ds = &null_ds;
1970 }
1971
1972 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001973 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1974 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1975 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001976
1977 if (cmd_gen(cmd) >= INTEL_GEN(7))
1978 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1979 else
1980 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1981}
1982
Chia-I Wua57761b2014-10-14 14:27:44 +08001983static uint32_t emit_shader(struct intel_cmd *cmd,
1984 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001985{
Chia-I Wua57761b2014-10-14 14:27:44 +08001986 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1987 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001988 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001989
Chia-I Wua57761b2014-10-14 14:27:44 +08001990 /* see if the shader is already in the cache */
1991 for (i = 0; i < cache->used; i++) {
1992 if (cache->entries[i].shader == (const void *) shader)
1993 return cache->entries[i].kernel_offset;
1994 }
1995
1996 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1997
1998 /* grow the cache if full */
1999 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002000 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002001 void *entries;
2002
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002003 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Chia-I Wua57761b2014-10-14 14:27:44 +08002004 XGL_SYSTEM_ALLOC_INTERNAL);
2005 if (entries) {
2006 if (cache->entries) {
2007 memcpy(entries, cache->entries,
2008 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002009 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002010 }
2011
2012 cache->entries = entries;
2013 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002014 }
2015 }
2016
Chia-I Wua57761b2014-10-14 14:27:44 +08002017 /* add the shader to the cache */
2018 if (cache->used < cache->count) {
2019 cache->entries[cache->used].shader = (const void *) shader;
2020 cache->entries[cache->used].kernel_offset = offset;
2021 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002022 }
2023
Chia-I Wua57761b2014-10-14 14:27:44 +08002024 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002025}
2026
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002027static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002028{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002029 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002030
Chia-I Wu8370b402014-08-29 12:28:37 +08002031 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2032 cmd_wa_gen6_pre_depth_stall_write(cmd);
2033 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2034 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2035 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2036 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002037
2038 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002039 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002040 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002041
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002042 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002043 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002044 }
2045 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002046 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002047 }
2048 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002049 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2050 }
2051 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2052 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2053 }
2054 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2055 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002056 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002057
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002058 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2059 gen7_3DSTATE_GS(cmd);
2060 } else {
2061 gen6_3DSTATE_GS(cmd);
2062 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002063
Chia-I Wu8370b402014-08-29 12:28:37 +08002064 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2065 cmd_wa_gen7_post_command_cs_stall(cmd);
2066 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2067 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002068}
2069
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002070static void emit_bounded_states(struct intel_cmd *cmd)
2071{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002072 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002073
2074 emit_graphics_pipeline(cmd);
2075
2076 emit_rt(cmd);
2077 emit_ds(cmd);
2078
2079 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2080 gen7_cc_states(cmd);
2081 gen7_viewport_states(cmd);
2082
2083 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2084 &cmd->bind.pipeline.graphics->vs);
2085 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2086 &cmd->bind.pipeline.graphics->fs);
2087
2088 gen6_3DSTATE_CLIP(cmd);
2089 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002090 gen7_3DSTATE_WM(cmd);
2091 gen7_3DSTATE_PS(cmd);
2092 } else {
2093 gen6_cc_states(cmd);
2094 gen6_viewport_states(cmd);
2095
2096 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2097 &cmd->bind.pipeline.graphics->vs);
2098 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2099 &cmd->bind.pipeline.graphics->fs);
2100
2101 gen6_3DSTATE_CLIP(cmd);
2102 gen6_3DSTATE_SF(cmd);
2103 gen6_3DSTATE_WM(cmd);
2104 }
2105
2106 emit_shader_resources(cmd);
2107
2108 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002109
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002110 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2111 gen6_3DSTATE_VS(cmd);
2112}
2113
Tony Barbourfa6cac72015-01-16 14:27:35 -07002114static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002115 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002116{
2117 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2118 const uint8_t cmd_len = 3;
2119 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002120
2121 CMD_ASSERT(cmd, 6, 7.5);
2122
Tony Barbourfa6cac72015-01-16 14:27:35 -07002123 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002124 dw[0] = 0;
2125 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002126
2127 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2128 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2129 GEN6_COMPAREFUNCTION_NEVER << 27 |
2130 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2131 } else {
2132 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2133 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2134 }
Chia-I Wud850a392015-02-19 11:08:25 -07002135 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2136 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002137 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2138 (GEN6_STENCILOP_KEEP) << 25 |
2139 (GEN6_STENCILOP_KEEP) << 22 |
2140 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002141 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2142 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002143 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2144 (GEN6_STENCILOP_KEEP) << 9 |
2145 (GEN6_STENCILOP_KEEP) << 6 |
2146 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002147
Chia-I Wud850a392015-02-19 11:08:25 -07002148 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2149 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2150 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2151 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2152 dw[2] = 0;
2153 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002154
2155 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2156 cmd_align, cmd_len, dw);
2157}
2158
Chia-I Wu6032b892014-10-17 14:47:18 +08002159static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2160{
2161 const struct intel_cmd_meta *meta = cmd->bind.meta;
2162 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2163
2164 CMD_ASSERT(cmd, 6, 7.5);
2165
2166 blend_offset = 0;
2167 ds_offset = 0;
2168 cc_offset = 0;
2169 cc_vp_offset = 0;
2170
Chia-I Wu29e6f502014-11-24 14:27:29 +08002171 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002172 /* BLEND_STATE */
2173 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002174 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002175 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002176 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002177 }
2178
Chia-I Wu29e6f502014-11-24 14:27:29 +08002179 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002180 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002181 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002182 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2183 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002184
Chia-I Wu29e6f502014-11-24 14:27:29 +08002185 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002186 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002187
Chia-I Wu29e6f502014-11-24 14:27:29 +08002188 /* COLOR_CALC_STATE */
2189 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002190 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002191
Chia-I Wu29e6f502014-11-24 14:27:29 +08002192 /* CC_VIEWPORT */
2193 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002194 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002195 dw[0] = u_fui(0.0f);
2196 dw[1] = u_fui(1.0f);
2197 } else {
2198 /* DEPTH_STENCIL_STATE */
2199 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002200 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002201 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2202 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2203 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002204 }
2205
2206 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2207 gen7_3dstate_pointer(cmd,
2208 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2209 blend_offset);
2210 gen7_3dstate_pointer(cmd,
2211 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2212 ds_offset);
2213 gen7_3dstate_pointer(cmd,
2214 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2215
2216 gen7_3dstate_pointer(cmd,
2217 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2218 cc_vp_offset);
2219 } else {
2220 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002221 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002222
2223 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2224 cmd_batch_pointer(cmd, 4, &dw);
2225 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002226 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002227 dw[1] = 0;
2228 dw[2] = 0;
2229 dw[3] = cc_vp_offset;
2230 }
2231}
2232
2233static void gen6_meta_surface_states(struct intel_cmd *cmd)
2234{
2235 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002236 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002237 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002238 const uint32_t sba_offset =
2239 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002240
2241 CMD_ASSERT(cmd, 6, 7.5);
2242
Chia-I Wu29e6f502014-11-24 14:27:29 +08002243 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2244 return;
2245
Chia-I Wu005c47c2014-10-22 13:49:13 +08002246 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002247 if (meta->src.valid) {
2248 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002249 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002250 meta->src.surface_len, meta->src.surface);
2251
2252 cmd_reserve_reloc(cmd, 1);
2253 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2254 cmd_surface_reloc_writer(cmd, offset, 1,
2255 meta->src.reloc_target, meta->src.reloc_offset);
2256 } else {
2257 cmd_surface_reloc(cmd, offset, 1,
2258 (struct intel_bo *) meta->src.reloc_target,
2259 meta->src.reloc_offset, meta->src.reloc_flags);
2260 }
2261
Mike Stroyan9bfad482015-02-10 15:09:23 -07002262 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002263 }
2264 if (meta->dst.valid) {
2265 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002266 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002267 meta->dst.surface_len, meta->dst.surface);
2268
2269 cmd_reserve_reloc(cmd, 1);
2270 cmd_surface_reloc(cmd, offset, 1,
2271 (struct intel_bo *) meta->dst.reloc_target,
2272 meta->dst.reloc_offset, meta->dst.reloc_flags);
2273
Mike Stroyan9bfad482015-02-10 15:09:23 -07002274 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002275 }
2276
2277 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002278 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002279 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002280 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002281
2282 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2284 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2285 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002286 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002287 } else {
2288 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002290 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002291 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002292 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002293 }
2294}
2295
2296static void gen6_meta_urb(struct intel_cmd *cmd)
2297{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002298 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002299 uint32_t *dw;
2300
2301 CMD_ASSERT(cmd, 6, 6);
2302
2303 /* 3DSTATE_URB */
2304 cmd_batch_pointer(cmd, 3, &dw);
2305 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002306 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002307 dw[2] = 0;
2308}
2309
2310static void gen7_meta_urb(struct intel_cmd *cmd)
2311{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002312 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2313 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002314 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002315 uint32_t *dw;
2316
2317 CMD_ASSERT(cmd, 7, 7.5);
2318
Chia-I Wu6032b892014-10-17 14:47:18 +08002319 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2320
Chia-I Wu24aa1022014-11-25 11:53:19 +08002321 switch (cmd_gen(cmd)) {
2322 case INTEL_GEN(7.5):
2323 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2324 break;
2325 case INTEL_GEN(7):
2326 default:
2327 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2328 break;
2329 }
2330
Chia-I Wu6032b892014-10-17 14:47:18 +08002331 /* 3DSTATE_URB_x */
2332 cmd_batch_pointer(cmd, 8, &dw);
2333
2334 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002335 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002336 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002337 dw += 2;
2338
2339 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002340 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002341 dw += 2;
2342
2343 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002344 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 dw += 2;
2346
2347 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002348 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002349 dw += 2;
2350}
2351
2352static void gen6_meta_vf(struct intel_cmd *cmd)
2353{
2354 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002355 uint32_t vb_start, vb_end, vb_stride;
2356 int ve_format, ve_z_source;
2357 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002358 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002359
2360 CMD_ASSERT(cmd, 6, 7.5);
2361
Chia-I Wu29e6f502014-11-24 14:27:29 +08002362 switch (meta->mode) {
2363 case INTEL_CMD_META_VS_POINTS:
2364 cmd_batch_pointer(cmd, 3, &dw);
2365 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002366 dw[1] = GEN6_VE_DW0_VALID;
2367 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2368 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2369 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2370 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371 return;
2372 break;
2373 case INTEL_CMD_META_FS_RECT:
2374 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002375 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002376
Chia-I Wu29e6f502014-11-24 14:27:29 +08002377 vertices[0][0] = meta->dst.x + meta->width;
2378 vertices[0][1] = meta->dst.y + meta->height;
2379 vertices[1][0] = meta->dst.x;
2380 vertices[1][1] = meta->dst.y + meta->height;
2381 vertices[2][0] = meta->dst.x;
2382 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002383
Chia-I Wu29e6f502014-11-24 14:27:29 +08002384 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2385 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002386
Chia-I Wu29e6f502014-11-24 14:27:29 +08002387 vb_end = vb_start + sizeof(vertices) - 1;
2388 vb_stride = sizeof(vertices[0]);
2389 ve_z_source = GEN6_VFCOMP_STORE_0;
2390 ve_format = GEN6_FORMAT_R32G32_USCALED;
2391 }
2392 break;
2393 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2394 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002395 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002396
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002397 vertices[0][0] = (float) (meta->dst.x + meta->width);
2398 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002399 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002400 vertices[1][0] = (float) meta->dst.x;
2401 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002402 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002403 vertices[2][0] = (float) meta->dst.x;
2404 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002405 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002406
Chia-I Wu29e6f502014-11-24 14:27:29 +08002407 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2408 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002409
Chia-I Wu29e6f502014-11-24 14:27:29 +08002410 vb_end = vb_start + sizeof(vertices) - 1;
2411 vb_stride = sizeof(vertices[0]);
2412 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2413 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2414 }
2415 break;
2416 default:
2417 assert(!"unknown meta mode");
2418 return;
2419 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002420 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002421
2422 /* 3DSTATE_VERTEX_BUFFERS */
2423 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002424
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002426 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002427 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002428 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002429
2430 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002431 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2432 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002433
2434 dw[4] = 0;
2435
2436 /* 3DSTATE_VERTEX_ELEMENTS */
2437 cmd_batch_pointer(cmd, 5, &dw);
2438 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002439 dw[1] = GEN6_VE_DW0_VALID;
2440 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2441 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2442 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2443 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2444 dw[3] = GEN6_VE_DW0_VALID |
2445 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2446 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2447 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2448 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2449 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002450}
2451
Chia-I Wu29e6f502014-11-24 14:27:29 +08002452static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002453{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002454 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002455 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002456 uint32_t consts[8];
2457 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002458
2459 CMD_ASSERT(cmd, 6, 7.5);
2460
2461 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002462 case INTEL_DEV_META_VS_FILL_MEM:
2463 consts[0] = meta->dst.x;
2464 consts[1] = meta->clear_val[0];
2465 const_count = 2;
2466 break;
2467 case INTEL_DEV_META_VS_COPY_MEM:
2468 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2469 consts[0] = meta->dst.x;
2470 consts[1] = meta->src.x;
2471 const_count = 2;
2472 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002473 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2474 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2475 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2476 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2477 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2478 consts[0] = meta->src.x;
2479 consts[1] = meta->src.y;
2480 consts[2] = meta->width;
2481 consts[3] = meta->dst.x;
2482 const_count = 4;
2483 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002484 default:
2485 assert(!"unknown meta shader id");
2486 const_count = 0;
2487 break;
2488 }
2489
2490 /* this can be skipped but it makes state dumping prettier */
2491 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2492
2493 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2494}
2495
2496static void gen6_meta_vs(struct intel_cmd *cmd)
2497{
2498 const struct intel_cmd_meta *meta = cmd->bind.meta;
2499 const struct intel_pipeline_shader *sh =
2500 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2501 uint32_t offset, *dw;
2502
2503 CMD_ASSERT(cmd, 6, 7.5);
2504
2505 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002506 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002507
2508 /* 3DSTATE_CONSTANT_VS */
2509 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2510 cmd_batch_pointer(cmd, cmd_len, &dw);
2511 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2512 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2513
2514 /* 3DSTATE_VS */
2515 cmd_batch_pointer(cmd, 6, &dw);
2516 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2517 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2518
2519 return;
2520 }
2521
2522 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2523
2524 /* 3DSTATE_CONSTANT_VS */
2525 offset = gen6_meta_vs_constants(cmd);
2526 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2527 cmd_batch_pointer(cmd, 7, &dw);
2528 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002529 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002530 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002531 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002532 dw[4] = 0;
2533 dw[5] = 0;
2534 dw[6] = 0;
2535 } else {
2536 cmd_batch_pointer(cmd, 5, &dw);
2537 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002538 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002539 dw[1] = offset;
2540 dw[2] = 0;
2541 dw[3] = 0;
2542 dw[4] = 0;
2543 }
2544
2545 /* 3DSTATE_VS */
2546 offset = emit_shader(cmd, sh);
2547 cmd_batch_pointer(cmd, 6, &dw);
2548 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2549 dw[1] = offset;
2550 dw[2] = GEN6_THREADDISP_SPF |
2551 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2552 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002553 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002554 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2555 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2556
2557 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2558 GEN6_VS_DW5_VS_ENABLE;
2559 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002560 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002561 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002562 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002563
2564 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002565}
2566
2567static void gen6_meta_disabled(struct intel_cmd *cmd)
2568{
Chia-I Wu6032b892014-10-17 14:47:18 +08002569 uint32_t *dw;
2570
2571 CMD_ASSERT(cmd, 6, 6);
2572
Chia-I Wu6032b892014-10-17 14:47:18 +08002573 /* 3DSTATE_CONSTANT_GS */
2574 cmd_batch_pointer(cmd, 5, &dw);
2575 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2576 dw[1] = 0;
2577 dw[2] = 0;
2578 dw[3] = 0;
2579 dw[4] = 0;
2580
2581 /* 3DSTATE_GS */
2582 cmd_batch_pointer(cmd, 7, &dw);
2583 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2584 dw[1] = 0;
2585 dw[2] = 0;
2586 dw[3] = 0;
2587 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2588 dw[5] = GEN6_GS_DW5_STATISTICS;
2589 dw[6] = 0;
2590
Chia-I Wu6032b892014-10-17 14:47:18 +08002591 /* 3DSTATE_SF */
2592 cmd_batch_pointer(cmd, 20, &dw);
2593 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2594 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2595 memset(&dw[2], 0, 18 * sizeof(*dw));
2596}
2597
2598static void gen7_meta_disabled(struct intel_cmd *cmd)
2599{
2600 uint32_t *dw;
2601
2602 CMD_ASSERT(cmd, 7, 7.5);
2603
Chia-I Wu6032b892014-10-17 14:47:18 +08002604 /* 3DSTATE_CONSTANT_HS */
2605 cmd_batch_pointer(cmd, 7, &dw);
2606 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2607 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2608
2609 /* 3DSTATE_HS */
2610 cmd_batch_pointer(cmd, 7, &dw);
2611 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2612 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2613
2614 /* 3DSTATE_TE */
2615 cmd_batch_pointer(cmd, 4, &dw);
2616 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2617 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2618
2619 /* 3DSTATE_CONSTANT_DS */
2620 cmd_batch_pointer(cmd, 7, &dw);
2621 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2622 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2623
2624 /* 3DSTATE_DS */
2625 cmd_batch_pointer(cmd, 6, &dw);
2626 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2627 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2628
2629 /* 3DSTATE_CONSTANT_GS */
2630 cmd_batch_pointer(cmd, 7, &dw);
2631 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2632 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2633
2634 /* 3DSTATE_GS */
2635 cmd_batch_pointer(cmd, 7, &dw);
2636 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2637 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2638
2639 /* 3DSTATE_STREAMOUT */
2640 cmd_batch_pointer(cmd, 3, &dw);
2641 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2642 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2643
Chia-I Wu6032b892014-10-17 14:47:18 +08002644 /* 3DSTATE_SF */
2645 cmd_batch_pointer(cmd, 7, &dw);
2646 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2647 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2648
2649 /* 3DSTATE_SBE */
2650 cmd_batch_pointer(cmd, 14, &dw);
2651 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2652 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2653 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002654}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002655
Chia-I Wu29e6f502014-11-24 14:27:29 +08002656static void gen6_meta_clip(struct intel_cmd *cmd)
2657{
2658 const struct intel_cmd_meta *meta = cmd->bind.meta;
2659 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002660
Chia-I Wu29e6f502014-11-24 14:27:29 +08002661 /* 3DSTATE_CLIP */
2662 cmd_batch_pointer(cmd, 4, &dw);
2663 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2664 dw[1] = 0;
2665 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2666 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2667 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2668 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002669 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002670 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002671 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002672}
2673
2674static void gen6_meta_wm(struct intel_cmd *cmd)
2675{
2676 const struct intel_cmd_meta *meta = cmd->bind.meta;
2677 uint32_t *dw;
2678
2679 CMD_ASSERT(cmd, 6, 7.5);
2680
2681 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2682
2683 /* 3DSTATE_MULTISAMPLE */
2684 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2685 cmd_batch_pointer(cmd, 4, &dw);
2686 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2687 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2688 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2689 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2690 dw[2] = 0;
2691 dw[3] = 0;
2692 } else {
2693 cmd_batch_pointer(cmd, 3, &dw);
2694 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2695 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2696 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2697 dw[2] = 0;
2698 }
2699
2700 /* 3DSTATE_SAMPLE_MASK */
2701 cmd_batch_pointer(cmd, 2, &dw);
2702 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2703 dw[1] = (1 << meta->samples) - 1;
2704
2705 /* 3DSTATE_DRAWING_RECTANGLE */
2706 cmd_batch_pointer(cmd, 4, &dw);
2707 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002708 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2709 /* unused */
2710 dw[1] = 0;
2711 dw[2] = 0;
2712 } else {
2713 dw[1] = meta->dst.y << 16 | meta->dst.x;
2714 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2715 (meta->dst.x + meta->width - 1);
2716 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002717 dw[3] = 0;
2718}
2719
2720static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2721{
2722 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002723 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002724 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002725 uint32_t consts[8];
2726 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002727
2728 CMD_ASSERT(cmd, 6, 7.5);
2729
2730 /* underflow is fine here */
2731 offset_x = meta->src.x - meta->dst.x;
2732 offset_y = meta->src.y - meta->dst.y;
2733
2734 switch (meta->shader_id) {
2735 case INTEL_DEV_META_FS_COPY_MEM:
2736 case INTEL_DEV_META_FS_COPY_1D:
2737 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2738 case INTEL_DEV_META_FS_COPY_2D:
2739 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2740 case INTEL_DEV_META_FS_COPY_2D_MS:
2741 consts[0] = offset_x;
2742 consts[1] = offset_y;
2743 consts[2] = meta->src.layer;
2744 consts[3] = meta->src.lod;
2745 const_count = 4;
2746 break;
2747 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2748 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2749 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2750 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2751 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2752 consts[0] = offset_x;
2753 consts[1] = offset_y;
2754 consts[2] = meta->src.layer;
2755 consts[3] = meta->src.lod;
2756 consts[4] = meta->src.x;
2757 consts[5] = meta->width;
2758 const_count = 6;
2759 break;
2760 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2761 consts[0] = offset_x;
2762 consts[1] = offset_y;
2763 consts[2] = meta->width;
2764 const_count = 3;
2765 break;
2766 case INTEL_DEV_META_FS_CLEAR_COLOR:
2767 consts[0] = meta->clear_val[0];
2768 consts[1] = meta->clear_val[1];
2769 consts[2] = meta->clear_val[2];
2770 consts[3] = meta->clear_val[3];
2771 const_count = 4;
2772 break;
2773 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2774 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002775 consts[1] = meta->clear_val[1];
2776 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002777 break;
2778 case INTEL_DEV_META_FS_RESOLVE_2X:
2779 case INTEL_DEV_META_FS_RESOLVE_4X:
2780 case INTEL_DEV_META_FS_RESOLVE_8X:
2781 case INTEL_DEV_META_FS_RESOLVE_16X:
2782 consts[0] = offset_x;
2783 consts[1] = offset_y;
2784 const_count = 2;
2785 break;
2786 default:
2787 assert(!"unknown meta shader id");
2788 const_count = 0;
2789 break;
2790 }
2791
2792 /* this can be skipped but it makes state dumping prettier */
2793 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2794
2795 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2796}
2797
2798static void gen6_meta_ps(struct intel_cmd *cmd)
2799{
2800 const struct intel_cmd_meta *meta = cmd->bind.meta;
2801 const struct intel_pipeline_shader *sh =
2802 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2803 uint32_t offset, *dw;
2804
2805 CMD_ASSERT(cmd, 6, 6);
2806
Chia-I Wu29e6f502014-11-24 14:27:29 +08002807 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2808 /* 3DSTATE_CONSTANT_PS */
2809 cmd_batch_pointer(cmd, 5, &dw);
2810 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2811 dw[1] = 0;
2812 dw[2] = 0;
2813 dw[3] = 0;
2814 dw[4] = 0;
2815
2816 /* 3DSTATE_WM */
2817 cmd_batch_pointer(cmd, 9, &dw);
2818 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2819 dw[1] = 0;
2820 dw[2] = 0;
2821 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002822
2823 switch (meta->ds.op) {
2824 case INTEL_CMD_META_DS_HIZ_CLEAR:
2825 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2826 break;
2827 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2828 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2829 break;
2830 case INTEL_CMD_META_DS_RESOLVE:
2831 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2832 break;
2833 default:
2834 dw[4] = 0;
2835 break;
2836 }
2837
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002838 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002839 dw[6] = 0;
2840 dw[7] = 0;
2841 dw[8] = 0;
2842
Chia-I Wu3adf7212014-10-24 15:34:07 +08002843 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002844 }
2845
Chia-I Wu3adf7212014-10-24 15:34:07 +08002846 /* a normal color write */
2847 assert(meta->dst.valid && !sh->uses);
2848
Chia-I Wu6032b892014-10-17 14:47:18 +08002849 /* 3DSTATE_CONSTANT_PS */
2850 offset = gen6_meta_ps_constants(cmd);
2851 cmd_batch_pointer(cmd, 5, &dw);
2852 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002853 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002854 dw[1] = offset;
2855 dw[2] = 0;
2856 dw[3] = 0;
2857 dw[4] = 0;
2858
2859 /* 3DSTATE_WM */
2860 offset = emit_shader(cmd, sh);
2861 cmd_batch_pointer(cmd, 9, &dw);
2862 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2863 dw[1] = offset;
2864 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2865 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002866 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002867 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002868 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002869 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2870 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002871
Chia-I Wu6032b892014-10-17 14:47:18 +08002872 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002873 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002874 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2875 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2876 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2877 if (meta->samples > 1) {
2878 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2879 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2880 } else {
2881 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2882 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2883 }
2884 dw[7] = 0;
2885 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002886
2887 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002888}
2889
2890static void gen7_meta_ps(struct intel_cmd *cmd)
2891{
2892 const struct intel_cmd_meta *meta = cmd->bind.meta;
2893 const struct intel_pipeline_shader *sh =
2894 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2895 uint32_t offset, *dw;
2896
2897 CMD_ASSERT(cmd, 7, 7.5);
2898
Chia-I Wu29e6f502014-11-24 14:27:29 +08002899 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2900 /* 3DSTATE_WM */
2901 cmd_batch_pointer(cmd, 3, &dw);
2902 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002903
2904 switch (meta->ds.op) {
2905 case INTEL_CMD_META_DS_HIZ_CLEAR:
2906 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2907 break;
2908 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2909 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2910 break;
2911 case INTEL_CMD_META_DS_RESOLVE:
2912 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2913 break;
2914 default:
2915 dw[1] = 0;
2916 break;
2917 }
2918
2919 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002920
2921 /* 3DSTATE_CONSTANT_GS */
2922 cmd_batch_pointer(cmd, 7, &dw);
2923 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2924 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2925
2926 /* 3DSTATE_PS */
2927 cmd_batch_pointer(cmd, 8, &dw);
2928 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2929 dw[1] = 0;
2930 dw[2] = 0;
2931 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002932 /* required to avoid hangs */
2933 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002934 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002935 dw[5] = 0;
2936 dw[6] = 0;
2937 dw[7] = 0;
2938
Chia-I Wu3adf7212014-10-24 15:34:07 +08002939 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002940 }
2941
Chia-I Wu3adf7212014-10-24 15:34:07 +08002942 /* a normal color write */
2943 assert(meta->dst.valid && !sh->uses);
2944
Chia-I Wu6032b892014-10-17 14:47:18 +08002945 /* 3DSTATE_WM */
2946 cmd_batch_pointer(cmd, 3, &dw);
2947 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002948 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002949 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2950 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2951 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2952 dw[2] = 0;
2953
2954 /* 3DSTATE_CONSTANT_PS */
2955 offset = gen6_meta_ps_constants(cmd);
2956 cmd_batch_pointer(cmd, 7, &dw);
2957 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002958 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002959 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002960 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002961 dw[4] = 0;
2962 dw[5] = 0;
2963 dw[6] = 0;
2964
2965 /* 3DSTATE_PS */
2966 offset = emit_shader(cmd, sh);
2967 cmd_batch_pointer(cmd, 8, &dw);
2968 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2969 dw[1] = offset;
2970 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2971 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002972 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002973
2974 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2975 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002976 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002977
2978 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002979 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002980 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002981 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002982 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002983 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002984
2985 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2986 dw[6] = 0;
2987 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002988
2989 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002990}
2991
2992static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2993{
2994 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002995 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002996
2997 CMD_ASSERT(cmd, 6, 7.5);
2998
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002999 if (!ds) {
3000 /* all zeros */
3001 static const struct intel_ds_view null_ds;
3002 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003003 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003004
3005 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003006 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3007 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3008 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003009
3010 if (cmd_gen(cmd) >= INTEL_GEN(7))
3011 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3012 else
3013 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003014}
3015
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003016static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3017 const struct intel_pipeline *pipeline)
3018{
3019 cmd->bind.pipeline.graphics = pipeline;
3020}
3021
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003022static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3023 const struct intel_pipeline *pipeline)
3024{
3025 cmd->bind.pipeline.compute = pipeline;
3026}
3027
3028static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
3029 const struct intel_pipeline_delta *delta)
3030{
3031 cmd->bind.pipeline.graphics_delta = delta;
3032}
3033
3034static void cmd_bind_compute_delta(struct intel_cmd *cmd,
3035 const struct intel_pipeline_delta *delta)
3036{
3037 cmd->bind.pipeline.compute_delta = delta;
3038}
3039
3040static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003041 const struct intel_desc_set *dset,
3042 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003043{
Chia-I Wuf8385062015-01-04 16:27:24 +08003044 const uint32_t size = sizeof(*dynamic_offsets) *
3045 dset->layout->dynamic_desc_count;
3046
3047 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
3048 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003049 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003050
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003051 cmd->bind.dset.graphics_dynamic_offsets = intel_alloc(cmd,
3052 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003053 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003054 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003055 return;
3056 }
3057
3058 cmd->bind.dset.graphics_dynamic_offset_size = size;
3059 }
3060
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003061 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003062 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003063}
3064
3065static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003066 const struct intel_desc_set *dset,
3067 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003068{
Chia-I Wuf8385062015-01-04 16:27:24 +08003069 const uint32_t size = sizeof(*dynamic_offsets) *
3070 dset->layout->dynamic_desc_count;
3071
3072 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
3073 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003074 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003075
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003076 cmd->bind.dset.compute_dynamic_offsets = intel_alloc(cmd,
3077 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003078 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003079 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003080 return;
3081 }
3082
3083 cmd->bind.dset.compute_dynamic_offset_size = size;
3084 }
3085
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003086 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003087 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003088}
3089
Chia-I Wu3b04af52014-11-08 10:48:20 +08003090static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003091 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003092 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003093{
Chia-I Wu714df452015-01-01 07:55:04 +08003094 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003095 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003096 return;
3097 }
3098
Chia-I Wu714df452015-01-01 07:55:04 +08003099 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003100 cmd->bind.vertex.offset[binding] = offset;
3101}
3102
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003103static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003104 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003105 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3106{
Chia-I Wu714df452015-01-01 07:55:04 +08003107 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003108 cmd->bind.index.offset = offset;
3109 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003110}
3111
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003112static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003113 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114{
3115 cmd->bind.state.viewport = state;
3116}
3117
3118static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003119 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003120{
3121 cmd->bind.state.raster = state;
3122}
3123
3124static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003125 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003126{
3127 cmd->bind.state.ds = state;
3128}
3129
3130static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003131 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003132{
3133 cmd->bind.state.blend = state;
3134}
3135
Chia-I Wuf98dd882015-02-10 04:17:47 +08003136static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3137{
3138 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3139 struct intel_pipeline_rmap *rmaps[5] = {
3140 pipeline->vs.rmap,
3141 pipeline->tcs.rmap,
3142 pipeline->tes.rmap,
3143 pipeline->gs.rmap,
3144 pipeline->fs.rmap,
3145 };
3146 uint32_t max_write;
3147 int i;
3148
3149 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3150 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3151 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3152
3153 /* pad first */
3154 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3155
3156 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3157 const struct intel_pipeline_rmap *rmap = rmaps[i];
3158 const uint32_t surface_count = (rmap) ?
3159 rmap->rt_count + rmap->texture_resource_count +
3160 rmap->resource_count + rmap->uav_count : 0;
3161
3162 if (surface_count) {
3163 /* SURFACE_STATEs */
3164 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3165
3166 /* BINDING_TABLE_STATE */
3167 max_write += u_align(sizeof(uint32_t) * surface_count,
3168 GEN6_ALIGNMENT_SURFACE_STATE);
3169 }
3170 }
3171
3172 return max_write;
3173}
3174
3175static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3176{
3177 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3178 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3179 uint32_t max_surface_write;
3180
3181 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3182 if (cmd->bind.meta)
3183 max_surface_write = 64 * sizeof(uint32_t);
3184 else
3185 max_surface_write = cmd_get_max_surface_write(cmd);
3186
3187 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3188 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3189 /* SBA expects page-aligned addresses */
3190 writer->sba_offset = writer->used & ~0xfff;
3191
3192 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3193
3194 cmd_batch_state_base_address(cmd);
3195 }
3196}
3197
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003198static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003199 uint32_t vertex_start,
3200 uint32_t vertex_count,
3201 uint32_t instance_start,
3202 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003204 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205{
3206 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003207 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003208 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3209
3210 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211
3212 emit_bounded_states(cmd);
3213
Chia-I Wuf98dd882015-02-10 04:17:47 +08003214 /* sanity check on cmd_get_max_surface_write() */
3215 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3216 surface_writer_used <= cmd_get_max_surface_write(cmd));
3217
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003218 if (indexed) {
3219 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003220 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003221
3222 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3223 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3224 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003225 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003226 cmd->bind.index.offset, cmd->bind.index.type,
3227 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003228 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003229 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003230 cmd->bind.index.offset, cmd->bind.index.type,
3231 p->primitive_restart);
3232 }
3233 } else {
3234 assert(!vertex_base);
3235 }
3236
3237 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3238 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3239 vertex_start, instance_count, instance_start, vertex_base);
3240 } else {
3241 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3242 vertex_start, instance_count, instance_start, vertex_base);
3243 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003244
Chia-I Wu707a29e2014-08-27 12:51:47 +08003245 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003246 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003247 /* need to re-emit all workarounds */
3248 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003249
3250 if (intel_debug & INTEL_DEBUG_NOCACHE)
3251 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003252}
3253
Chia-I Wuc14d1562014-10-17 09:49:22 +08003254void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3255{
Chia-I Wu6032b892014-10-17 14:47:18 +08003256 cmd->bind.meta = meta;
3257
Chia-I Wuf98dd882015-02-10 04:17:47 +08003258 cmd_adjust_state_base_address(cmd);
3259
Chia-I Wu6032b892014-10-17 14:47:18 +08003260 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003261 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003262
3263 gen6_meta_dynamic_states(cmd);
3264 gen6_meta_surface_states(cmd);
3265
3266 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3267 gen7_meta_urb(cmd);
3268 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003269 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003270 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003271 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003272 gen6_meta_wm(cmd);
3273 gen7_meta_ps(cmd);
3274 gen6_meta_depth_buffer(cmd);
3275
3276 cmd_wa_gen7_post_command_cs_stall(cmd);
3277 cmd_wa_gen7_post_command_depth_stall(cmd);
3278
Chia-I Wu29e6f502014-11-24 14:27:29 +08003279 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3280 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003281 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003282 } else {
3283 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3284 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003285 } else {
3286 gen6_meta_urb(cmd);
3287 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003288 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003289 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003290 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003291 gen6_meta_wm(cmd);
3292 gen6_meta_ps(cmd);
3293 gen6_meta_depth_buffer(cmd);
3294
Chia-I Wu29e6f502014-11-24 14:27:29 +08003295 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3296 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003297 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003298 } else {
3299 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3300 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003301 }
3302
3303 cmd->bind.draw_count++;
3304 /* need to re-emit all workarounds */
3305 cmd->bind.wa_flags = 0;
3306
3307 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003308
Chia-I Wubbc7d912015-02-27 14:59:50 -07003309 /* make the normal path believe the render pass has changed */
3310 cmd->bind.render_pass_changed = true;
3311
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003312 if (intel_debug & INTEL_DEBUG_NOCACHE)
3313 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003314}
3315
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003316ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003317 XGL_CMD_BUFFER cmdBuffer,
3318 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3319 XGL_PIPELINE pipeline)
3320{
3321 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3322
3323 switch (pipelineBindPoint) {
3324 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003325 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003326 break;
3327 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003328 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003329 break;
3330 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003331 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003332 break;
3333 }
3334}
3335
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003336ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003337 XGL_CMD_BUFFER cmdBuffer,
3338 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3339 XGL_PIPELINE_DELTA delta)
3340{
3341 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3342
3343 switch (pipelineBindPoint) {
3344 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003345 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003346 break;
3347 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003348 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003349 break;
3350 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003351 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003352 break;
3353 }
3354}
3355
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003356ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003357 XGL_CMD_BUFFER cmdBuffer,
3358 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003359 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003360{
3361 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3362
3363 switch (stateBindPoint) {
3364 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003365 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003366 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003367 break;
3368 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003369 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003370 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003371 break;
3372 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003373 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003374 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003375 break;
3376 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003377 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003378 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003379 break;
3380 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003381 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003382 break;
3383 }
3384}
3385
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003386ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003387 XGL_CMD_BUFFER cmdBuffer,
3388 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003389 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003390 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003391{
3392 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003393 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003394
3395 switch (pipelineBindPoint) {
3396 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003397 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003398 break;
3399 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003400 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003401 break;
3402 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003403 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003404 break;
3405 }
3406}
3407
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003408ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003409 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003410 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003411 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003412 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003413{
3414 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003415 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003416
Chia-I Wu714df452015-01-01 07:55:04 +08003417 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003418}
3419
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003420ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003421 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003422 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003423 XGL_GPU_SIZE offset,
3424 XGL_INDEX_TYPE indexType)
3425{
3426 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003427 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003428
Chia-I Wu714df452015-01-01 07:55:04 +08003429 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003430}
3431
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003432ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003433 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003434 uint32_t firstVertex,
3435 uint32_t vertexCount,
3436 uint32_t firstInstance,
3437 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003438{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003439 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003440
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003441 cmd_draw(cmd, firstVertex, vertexCount,
3442 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003443}
3444
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003445ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003446 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003447 uint32_t firstIndex,
3448 uint32_t indexCount,
3449 int32_t vertexOffset,
3450 uint32_t firstInstance,
3451 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003452{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003453 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003454
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003455 cmd_draw(cmd, firstIndex, indexCount,
3456 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003457}
3458
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003459ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003460 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003461 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003462 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003463 uint32_t count,
3464 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003465{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003466 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3467
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003468 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003469}
3470
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003471ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003472 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003473 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003474 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003475 uint32_t count,
3476 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003477{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003478 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3479
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003480 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003481}
3482
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003483ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003484 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003485 uint32_t x,
3486 uint32_t y,
3487 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003488{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003489 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3490
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003491 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003492}
3493
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003494ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003495 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003496 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003497 XGL_GPU_SIZE offset)
3498{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003499 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3500
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003501 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003502}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003503
Chia-I Wude26bdf2015-02-18 15:47:12 -07003504ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003505 XGL_CMD_BUFFER cmdBuffer,
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003506 const XGL_RENDER_PASS_BEGIN* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003507{
3508 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3509
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06003510 cmd_begin_render_pass(cmd, (struct intel_render_pass *) pRenderPassBegin->renderPass, pRenderPassBegin->framebuffer);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003511}
3512
Chia-I Wude26bdf2015-02-18 15:47:12 -07003513ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003514 XGL_CMD_BUFFER cmdBuffer,
3515 XGL_RENDER_PASS renderPass)
3516{
3517 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3518
3519 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3520}