blob: de2adfdf56833d00b2649b43fbe18094a0468e5a [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700273 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700279 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800380
381 CMD_ASSERT(cmd, 6, 7.5);
382
383 dw1 = GEN7_SF_DW1_STATISTICS |
384 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
385 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
386 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
387 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700388 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800389
390 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
391 int format;
392
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700393 switch (pipeline->db_format) {
394 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800395 format = GEN6_ZFORMAT_D16_UNORM;
396 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700397 case XGL_FMT_D32_SFLOAT:
398 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800399 format = GEN6_ZFORMAT_D32_FLOAT;
400 break;
401 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700402 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800403 format = 0;
404 break;
405 }
406
407 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
408 }
409
Tony Barbourfa6cac72015-01-16 14:27:35 -0700410 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800411
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700412 /* Scissor is always enabled */
413 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
414
Tony Barbourfa6cac72015-01-16 14:27:35 -0700415 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800416 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
417 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
418 } else {
419 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
420 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
421 }
422
Chia-I Wu8016a172014-08-29 18:31:32 +0800423 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
424 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
425 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800426 GEN7_SF_DW3_SUBPIXEL_8BITS;
427
428 if (pipeline->use_rs_point_size) {
429 int point_width;
430
431 /* in U8.3 */
432 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
433 point_width = U_CLAMP(point_width, 1, 2047);
434
435 dw3 |= GEN7_SF_DW3_USE_POINT_WIDTH | point_width;
436 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800437
438 body[0] = dw1;
439 body[1] = dw2;
440 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700441 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
442 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
443 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800444}
445
Chia-I Wu8016a172014-08-29 18:31:32 +0800446static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
447{
448 const uint8_t cmd_len = 20;
449 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
450 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800451 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800453 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800454
455 CMD_ASSERT(cmd, 6, 6);
456
457 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800458
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 cmd_batch_pointer(cmd, cmd_len, &dw);
460 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800461 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800462 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800463 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800464}
465
466static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
467{
468 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800469 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800470
471 CMD_ASSERT(cmd, 7, 7.5);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
475 (cmd_len - 2);
476 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800477}
478
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800479static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
480{
481 const uint8_t cmd_len = 4;
482 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
483 (cmd_len - 2);
484 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700485 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800486 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700487 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800488 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800489
490 CMD_ASSERT(cmd, 6, 7.5);
491
492 dw1 = GEN6_CLIP_DW1_STATISTICS;
493 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
494 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
495 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700496 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800497 }
498
499 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
500 GEN6_CLIP_DW2_XY_TEST_ENABLE |
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 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700529 if (cmd->bind.render_pass->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 =
Chia-I Wuf8385062015-01-04 16:27:24 +08001663 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1664 cmd->bind.render_pass->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{
1934 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1935
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{
Chia-I Wubbc7d912015-02-27 14:59:50 -07001948 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1949
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);
Chia-I Wubbc7d912015-02-27 14:59:50 -07001954 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width, fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001955}
1956
1957static void emit_ds(struct intel_cmd *cmd)
1958{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001959 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1960 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001961
Chia-I Wubbc7d912015-02-27 14:59:50 -07001962 if (!cmd->bind.render_pass_changed)
1963 return;
1964
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001965 if (!ds) {
1966 /* all zeros */
1967 static const struct intel_ds_view null_ds;
1968 ds = &null_ds;
1969 }
1970
1971 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001972 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1973 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1974 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001975
1976 if (cmd_gen(cmd) >= INTEL_GEN(7))
1977 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1978 else
1979 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1980}
1981
Chia-I Wua57761b2014-10-14 14:27:44 +08001982static uint32_t emit_shader(struct intel_cmd *cmd,
1983 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001984{
Chia-I Wua57761b2014-10-14 14:27:44 +08001985 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1986 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001987 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001988
Chia-I Wua57761b2014-10-14 14:27:44 +08001989 /* see if the shader is already in the cache */
1990 for (i = 0; i < cache->used; i++) {
1991 if (cache->entries[i].shader == (const void *) shader)
1992 return cache->entries[i].kernel_offset;
1993 }
1994
1995 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1996
1997 /* grow the cache if full */
1998 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001999 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002000 void *entries;
2001
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002002 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Chia-I Wua57761b2014-10-14 14:27:44 +08002003 XGL_SYSTEM_ALLOC_INTERNAL);
2004 if (entries) {
2005 if (cache->entries) {
2006 memcpy(entries, cache->entries,
2007 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002008 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002009 }
2010
2011 cache->entries = entries;
2012 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002013 }
2014 }
2015
Chia-I Wua57761b2014-10-14 14:27:44 +08002016 /* add the shader to the cache */
2017 if (cache->used < cache->count) {
2018 cache->entries[cache->used].shader = (const void *) shader;
2019 cache->entries[cache->used].kernel_offset = offset;
2020 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002021 }
2022
Chia-I Wua57761b2014-10-14 14:27:44 +08002023 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002024}
2025
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002026static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002027{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002028 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002029
Chia-I Wu8370b402014-08-29 12:28:37 +08002030 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2031 cmd_wa_gen6_pre_depth_stall_write(cmd);
2032 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2033 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2034 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2035 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002036
2037 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002038 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002039 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002040
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002041 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002042 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002043 }
2044 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002045 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002046 }
2047 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002048 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2049 }
2050 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2051 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2052 }
2053 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2054 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002055 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002056
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002057 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2058 gen7_3DSTATE_GS(cmd);
2059 } else {
2060 gen6_3DSTATE_GS(cmd);
2061 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002062
Chia-I Wu8370b402014-08-29 12:28:37 +08002063 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2064 cmd_wa_gen7_post_command_cs_stall(cmd);
2065 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2066 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002067}
2068
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002069static void emit_bounded_states(struct intel_cmd *cmd)
2070{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002071 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002072
2073 emit_graphics_pipeline(cmd);
2074
2075 emit_rt(cmd);
2076 emit_ds(cmd);
2077
2078 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2079 gen7_cc_states(cmd);
2080 gen7_viewport_states(cmd);
2081
2082 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2083 &cmd->bind.pipeline.graphics->vs);
2084 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2085 &cmd->bind.pipeline.graphics->fs);
2086
2087 gen6_3DSTATE_CLIP(cmd);
2088 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002089 gen7_3DSTATE_WM(cmd);
2090 gen7_3DSTATE_PS(cmd);
2091 } else {
2092 gen6_cc_states(cmd);
2093 gen6_viewport_states(cmd);
2094
2095 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2096 &cmd->bind.pipeline.graphics->vs);
2097 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2098 &cmd->bind.pipeline.graphics->fs);
2099
2100 gen6_3DSTATE_CLIP(cmd);
2101 gen6_3DSTATE_SF(cmd);
2102 gen6_3DSTATE_WM(cmd);
2103 }
2104
2105 emit_shader_resources(cmd);
2106
2107 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002108
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002109 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2110 gen6_3DSTATE_VS(cmd);
2111}
2112
Tony Barbourfa6cac72015-01-16 14:27:35 -07002113static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002114 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002115{
2116 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2117 const uint8_t cmd_len = 3;
2118 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002119
2120 CMD_ASSERT(cmd, 6, 7.5);
2121
Tony Barbourfa6cac72015-01-16 14:27:35 -07002122 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002123 dw[0] = 0;
2124 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002125
2126 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2127 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2128 GEN6_COMPAREFUNCTION_NEVER << 27 |
2129 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2130 } else {
2131 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2132 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2133 }
Chia-I Wud850a392015-02-19 11:08:25 -07002134 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2135 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002136 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2137 (GEN6_STENCILOP_KEEP) << 25 |
2138 (GEN6_STENCILOP_KEEP) << 22 |
2139 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002140 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2141 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002142 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2143 (GEN6_STENCILOP_KEEP) << 9 |
2144 (GEN6_STENCILOP_KEEP) << 6 |
2145 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002146
Chia-I Wud850a392015-02-19 11:08:25 -07002147 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2148 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2149 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2150 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2151 dw[2] = 0;
2152 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002153
2154 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2155 cmd_align, cmd_len, dw);
2156}
2157
Chia-I Wu6032b892014-10-17 14:47:18 +08002158static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2159{
2160 const struct intel_cmd_meta *meta = cmd->bind.meta;
2161 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2162
2163 CMD_ASSERT(cmd, 6, 7.5);
2164
2165 blend_offset = 0;
2166 ds_offset = 0;
2167 cc_offset = 0;
2168 cc_vp_offset = 0;
2169
Chia-I Wu29e6f502014-11-24 14:27:29 +08002170 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002171 /* BLEND_STATE */
2172 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002173 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002174 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002175 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002176 }
2177
Chia-I Wu29e6f502014-11-24 14:27:29 +08002178 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002179 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002181 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2182 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002183
Chia-I Wu29e6f502014-11-24 14:27:29 +08002184 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002185 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002186
Chia-I Wu29e6f502014-11-24 14:27:29 +08002187 /* COLOR_CALC_STATE */
2188 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002189 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002190
Chia-I Wu29e6f502014-11-24 14:27:29 +08002191 /* CC_VIEWPORT */
2192 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002193 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002194 dw[0] = u_fui(0.0f);
2195 dw[1] = u_fui(1.0f);
2196 } else {
2197 /* DEPTH_STENCIL_STATE */
2198 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002199 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002200 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2201 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2202 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002203 }
2204
2205 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2206 gen7_3dstate_pointer(cmd,
2207 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2208 blend_offset);
2209 gen7_3dstate_pointer(cmd,
2210 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2211 ds_offset);
2212 gen7_3dstate_pointer(cmd,
2213 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2214
2215 gen7_3dstate_pointer(cmd,
2216 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2217 cc_vp_offset);
2218 } else {
2219 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002220 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002221
2222 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2223 cmd_batch_pointer(cmd, 4, &dw);
2224 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002225 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002226 dw[1] = 0;
2227 dw[2] = 0;
2228 dw[3] = cc_vp_offset;
2229 }
2230}
2231
2232static void gen6_meta_surface_states(struct intel_cmd *cmd)
2233{
2234 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002235 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002236 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002237 const uint32_t sba_offset =
2238 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002239
2240 CMD_ASSERT(cmd, 6, 7.5);
2241
Chia-I Wu29e6f502014-11-24 14:27:29 +08002242 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2243 return;
2244
Chia-I Wu005c47c2014-10-22 13:49:13 +08002245 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002246 if (meta->src.valid) {
2247 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002248 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002249 meta->src.surface_len, meta->src.surface);
2250
2251 cmd_reserve_reloc(cmd, 1);
2252 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2253 cmd_surface_reloc_writer(cmd, offset, 1,
2254 meta->src.reloc_target, meta->src.reloc_offset);
2255 } else {
2256 cmd_surface_reloc(cmd, offset, 1,
2257 (struct intel_bo *) meta->src.reloc_target,
2258 meta->src.reloc_offset, meta->src.reloc_flags);
2259 }
2260
Mike Stroyan9bfad482015-02-10 15:09:23 -07002261 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002262 }
2263 if (meta->dst.valid) {
2264 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002265 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002266 meta->dst.surface_len, meta->dst.surface);
2267
2268 cmd_reserve_reloc(cmd, 1);
2269 cmd_surface_reloc(cmd, offset, 1,
2270 (struct intel_bo *) meta->dst.reloc_target,
2271 meta->dst.reloc_offset, meta->dst.reloc_flags);
2272
Mike Stroyan9bfad482015-02-10 15:09:23 -07002273 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002274 }
2275
2276 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002277 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002278 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002279 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002280
2281 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002282 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2283 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2284 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002285 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002286 } else {
2287 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002288 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002289 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002291 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002292 }
2293}
2294
2295static void gen6_meta_urb(struct intel_cmd *cmd)
2296{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002297 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002298 uint32_t *dw;
2299
2300 CMD_ASSERT(cmd, 6, 6);
2301
2302 /* 3DSTATE_URB */
2303 cmd_batch_pointer(cmd, 3, &dw);
2304 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002305 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002306 dw[2] = 0;
2307}
2308
2309static void gen7_meta_urb(struct intel_cmd *cmd)
2310{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002311 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2312 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002313 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 uint32_t *dw;
2315
2316 CMD_ASSERT(cmd, 7, 7.5);
2317
Chia-I Wu6032b892014-10-17 14:47:18 +08002318 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2319
Chia-I Wu24aa1022014-11-25 11:53:19 +08002320 switch (cmd_gen(cmd)) {
2321 case INTEL_GEN(7.5):
2322 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2323 break;
2324 case INTEL_GEN(7):
2325 default:
2326 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2327 break;
2328 }
2329
Chia-I Wu6032b892014-10-17 14:47:18 +08002330 /* 3DSTATE_URB_x */
2331 cmd_batch_pointer(cmd, 8, &dw);
2332
2333 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002334 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002335 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002336 dw += 2;
2337
2338 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002339 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002340 dw += 2;
2341
2342 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002343 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002344 dw += 2;
2345
2346 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002347 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 dw += 2;
2349}
2350
2351static void gen6_meta_vf(struct intel_cmd *cmd)
2352{
2353 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002354 uint32_t vb_start, vb_end, vb_stride;
2355 int ve_format, ve_z_source;
2356 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002357 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002358
2359 CMD_ASSERT(cmd, 6, 7.5);
2360
Chia-I Wu29e6f502014-11-24 14:27:29 +08002361 switch (meta->mode) {
2362 case INTEL_CMD_META_VS_POINTS:
2363 cmd_batch_pointer(cmd, 3, &dw);
2364 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002365 dw[1] = GEN6_VE_DW0_VALID;
2366 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2367 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2368 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2369 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002370 return;
2371 break;
2372 case INTEL_CMD_META_FS_RECT:
2373 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002374 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002375
Chia-I Wu29e6f502014-11-24 14:27:29 +08002376 vertices[0][0] = meta->dst.x + meta->width;
2377 vertices[0][1] = meta->dst.y + meta->height;
2378 vertices[1][0] = meta->dst.x;
2379 vertices[1][1] = meta->dst.y + meta->height;
2380 vertices[2][0] = meta->dst.x;
2381 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002382
Chia-I Wu29e6f502014-11-24 14:27:29 +08002383 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2384 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002385
Chia-I Wu29e6f502014-11-24 14:27:29 +08002386 vb_end = vb_start + sizeof(vertices) - 1;
2387 vb_stride = sizeof(vertices[0]);
2388 ve_z_source = GEN6_VFCOMP_STORE_0;
2389 ve_format = GEN6_FORMAT_R32G32_USCALED;
2390 }
2391 break;
2392 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2393 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002394 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002395
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002396 vertices[0][0] = (float) (meta->dst.x + meta->width);
2397 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002398 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002399 vertices[1][0] = (float) meta->dst.x;
2400 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002401 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002402 vertices[2][0] = (float) meta->dst.x;
2403 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002404 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002405
Chia-I Wu29e6f502014-11-24 14:27:29 +08002406 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2407 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002408
Chia-I Wu29e6f502014-11-24 14:27:29 +08002409 vb_end = vb_start + sizeof(vertices) - 1;
2410 vb_stride = sizeof(vertices[0]);
2411 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2412 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2413 }
2414 break;
2415 default:
2416 assert(!"unknown meta mode");
2417 return;
2418 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002419 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002420
2421 /* 3DSTATE_VERTEX_BUFFERS */
2422 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002423
Chia-I Wu6032b892014-10-17 14:47:18 +08002424 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002425 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002426 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002427 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002428
2429 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002430 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2431 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002432
2433 dw[4] = 0;
2434
2435 /* 3DSTATE_VERTEX_ELEMENTS */
2436 cmd_batch_pointer(cmd, 5, &dw);
2437 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002438 dw[1] = GEN6_VE_DW0_VALID;
2439 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2440 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2441 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2442 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2443 dw[3] = GEN6_VE_DW0_VALID |
2444 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2445 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2446 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2447 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2448 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002449}
2450
Chia-I Wu29e6f502014-11-24 14:27:29 +08002451static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002452{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002453 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002454 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002455 uint32_t consts[8];
2456 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002457
2458 CMD_ASSERT(cmd, 6, 7.5);
2459
2460 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002461 case INTEL_DEV_META_VS_FILL_MEM:
2462 consts[0] = meta->dst.x;
2463 consts[1] = meta->clear_val[0];
2464 const_count = 2;
2465 break;
2466 case INTEL_DEV_META_VS_COPY_MEM:
2467 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2468 consts[0] = meta->dst.x;
2469 consts[1] = meta->src.x;
2470 const_count = 2;
2471 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002472 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2473 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2474 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2475 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2476 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2477 consts[0] = meta->src.x;
2478 consts[1] = meta->src.y;
2479 consts[2] = meta->width;
2480 consts[3] = meta->dst.x;
2481 const_count = 4;
2482 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002483 default:
2484 assert(!"unknown meta shader id");
2485 const_count = 0;
2486 break;
2487 }
2488
2489 /* this can be skipped but it makes state dumping prettier */
2490 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2491
2492 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2493}
2494
2495static void gen6_meta_vs(struct intel_cmd *cmd)
2496{
2497 const struct intel_cmd_meta *meta = cmd->bind.meta;
2498 const struct intel_pipeline_shader *sh =
2499 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2500 uint32_t offset, *dw;
2501
2502 CMD_ASSERT(cmd, 6, 7.5);
2503
2504 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002505 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002506
2507 /* 3DSTATE_CONSTANT_VS */
2508 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2509 cmd_batch_pointer(cmd, cmd_len, &dw);
2510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2511 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2512
2513 /* 3DSTATE_VS */
2514 cmd_batch_pointer(cmd, 6, &dw);
2515 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2516 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2517
2518 return;
2519 }
2520
2521 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2522
2523 /* 3DSTATE_CONSTANT_VS */
2524 offset = gen6_meta_vs_constants(cmd);
2525 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2526 cmd_batch_pointer(cmd, 7, &dw);
2527 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002528 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002529 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002530 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002531 dw[4] = 0;
2532 dw[5] = 0;
2533 dw[6] = 0;
2534 } else {
2535 cmd_batch_pointer(cmd, 5, &dw);
2536 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002537 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002538 dw[1] = offset;
2539 dw[2] = 0;
2540 dw[3] = 0;
2541 dw[4] = 0;
2542 }
2543
2544 /* 3DSTATE_VS */
2545 offset = emit_shader(cmd, sh);
2546 cmd_batch_pointer(cmd, 6, &dw);
2547 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2548 dw[1] = offset;
2549 dw[2] = GEN6_THREADDISP_SPF |
2550 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2551 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002552 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2554 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2555
2556 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2557 GEN6_VS_DW5_VS_ENABLE;
2558 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002559 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002561 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002562
2563 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002564}
2565
2566static void gen6_meta_disabled(struct intel_cmd *cmd)
2567{
Chia-I Wu6032b892014-10-17 14:47:18 +08002568 uint32_t *dw;
2569
2570 CMD_ASSERT(cmd, 6, 6);
2571
Chia-I Wu6032b892014-10-17 14:47:18 +08002572 /* 3DSTATE_CONSTANT_GS */
2573 cmd_batch_pointer(cmd, 5, &dw);
2574 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2575 dw[1] = 0;
2576 dw[2] = 0;
2577 dw[3] = 0;
2578 dw[4] = 0;
2579
2580 /* 3DSTATE_GS */
2581 cmd_batch_pointer(cmd, 7, &dw);
2582 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2583 dw[1] = 0;
2584 dw[2] = 0;
2585 dw[3] = 0;
2586 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2587 dw[5] = GEN6_GS_DW5_STATISTICS;
2588 dw[6] = 0;
2589
Chia-I Wu6032b892014-10-17 14:47:18 +08002590 /* 3DSTATE_SF */
2591 cmd_batch_pointer(cmd, 20, &dw);
2592 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2593 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2594 memset(&dw[2], 0, 18 * sizeof(*dw));
2595}
2596
2597static void gen7_meta_disabled(struct intel_cmd *cmd)
2598{
2599 uint32_t *dw;
2600
2601 CMD_ASSERT(cmd, 7, 7.5);
2602
Chia-I Wu6032b892014-10-17 14:47:18 +08002603 /* 3DSTATE_CONSTANT_HS */
2604 cmd_batch_pointer(cmd, 7, &dw);
2605 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2606 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2607
2608 /* 3DSTATE_HS */
2609 cmd_batch_pointer(cmd, 7, &dw);
2610 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2611 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2612
2613 /* 3DSTATE_TE */
2614 cmd_batch_pointer(cmd, 4, &dw);
2615 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2616 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2617
2618 /* 3DSTATE_CONSTANT_DS */
2619 cmd_batch_pointer(cmd, 7, &dw);
2620 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2621 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2622
2623 /* 3DSTATE_DS */
2624 cmd_batch_pointer(cmd, 6, &dw);
2625 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2626 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2627
2628 /* 3DSTATE_CONSTANT_GS */
2629 cmd_batch_pointer(cmd, 7, &dw);
2630 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2631 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2632
2633 /* 3DSTATE_GS */
2634 cmd_batch_pointer(cmd, 7, &dw);
2635 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2636 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2637
2638 /* 3DSTATE_STREAMOUT */
2639 cmd_batch_pointer(cmd, 3, &dw);
2640 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2641 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2642
Chia-I Wu6032b892014-10-17 14:47:18 +08002643 /* 3DSTATE_SF */
2644 cmd_batch_pointer(cmd, 7, &dw);
2645 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2646 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2647
2648 /* 3DSTATE_SBE */
2649 cmd_batch_pointer(cmd, 14, &dw);
2650 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2651 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2652 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002653}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002654
Chia-I Wu29e6f502014-11-24 14:27:29 +08002655static void gen6_meta_clip(struct intel_cmd *cmd)
2656{
2657 const struct intel_cmd_meta *meta = cmd->bind.meta;
2658 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002659
Chia-I Wu29e6f502014-11-24 14:27:29 +08002660 /* 3DSTATE_CLIP */
2661 cmd_batch_pointer(cmd, 4, &dw);
2662 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2663 dw[1] = 0;
2664 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2665 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2666 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2667 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002668 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002669 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002670 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002671}
2672
2673static void gen6_meta_wm(struct intel_cmd *cmd)
2674{
2675 const struct intel_cmd_meta *meta = cmd->bind.meta;
2676 uint32_t *dw;
2677
2678 CMD_ASSERT(cmd, 6, 7.5);
2679
2680 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2681
2682 /* 3DSTATE_MULTISAMPLE */
2683 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2684 cmd_batch_pointer(cmd, 4, &dw);
2685 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2686 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2687 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2688 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2689 dw[2] = 0;
2690 dw[3] = 0;
2691 } else {
2692 cmd_batch_pointer(cmd, 3, &dw);
2693 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2694 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2695 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2696 dw[2] = 0;
2697 }
2698
2699 /* 3DSTATE_SAMPLE_MASK */
2700 cmd_batch_pointer(cmd, 2, &dw);
2701 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2702 dw[1] = (1 << meta->samples) - 1;
2703
2704 /* 3DSTATE_DRAWING_RECTANGLE */
2705 cmd_batch_pointer(cmd, 4, &dw);
2706 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002707 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2708 /* unused */
2709 dw[1] = 0;
2710 dw[2] = 0;
2711 } else {
2712 dw[1] = meta->dst.y << 16 | meta->dst.x;
2713 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2714 (meta->dst.x + meta->width - 1);
2715 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002716 dw[3] = 0;
2717}
2718
2719static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2720{
2721 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002722 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002723 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002724 uint32_t consts[8];
2725 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002726
2727 CMD_ASSERT(cmd, 6, 7.5);
2728
2729 /* underflow is fine here */
2730 offset_x = meta->src.x - meta->dst.x;
2731 offset_y = meta->src.y - meta->dst.y;
2732
2733 switch (meta->shader_id) {
2734 case INTEL_DEV_META_FS_COPY_MEM:
2735 case INTEL_DEV_META_FS_COPY_1D:
2736 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2737 case INTEL_DEV_META_FS_COPY_2D:
2738 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2739 case INTEL_DEV_META_FS_COPY_2D_MS:
2740 consts[0] = offset_x;
2741 consts[1] = offset_y;
2742 consts[2] = meta->src.layer;
2743 consts[3] = meta->src.lod;
2744 const_count = 4;
2745 break;
2746 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2747 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2748 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2749 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2750 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2751 consts[0] = offset_x;
2752 consts[1] = offset_y;
2753 consts[2] = meta->src.layer;
2754 consts[3] = meta->src.lod;
2755 consts[4] = meta->src.x;
2756 consts[5] = meta->width;
2757 const_count = 6;
2758 break;
2759 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2760 consts[0] = offset_x;
2761 consts[1] = offset_y;
2762 consts[2] = meta->width;
2763 const_count = 3;
2764 break;
2765 case INTEL_DEV_META_FS_CLEAR_COLOR:
2766 consts[0] = meta->clear_val[0];
2767 consts[1] = meta->clear_val[1];
2768 consts[2] = meta->clear_val[2];
2769 consts[3] = meta->clear_val[3];
2770 const_count = 4;
2771 break;
2772 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2773 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002774 consts[1] = meta->clear_val[1];
2775 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002776 break;
2777 case INTEL_DEV_META_FS_RESOLVE_2X:
2778 case INTEL_DEV_META_FS_RESOLVE_4X:
2779 case INTEL_DEV_META_FS_RESOLVE_8X:
2780 case INTEL_DEV_META_FS_RESOLVE_16X:
2781 consts[0] = offset_x;
2782 consts[1] = offset_y;
2783 const_count = 2;
2784 break;
2785 default:
2786 assert(!"unknown meta shader id");
2787 const_count = 0;
2788 break;
2789 }
2790
2791 /* this can be skipped but it makes state dumping prettier */
2792 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2793
2794 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2795}
2796
2797static void gen6_meta_ps(struct intel_cmd *cmd)
2798{
2799 const struct intel_cmd_meta *meta = cmd->bind.meta;
2800 const struct intel_pipeline_shader *sh =
2801 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2802 uint32_t offset, *dw;
2803
2804 CMD_ASSERT(cmd, 6, 6);
2805
Chia-I Wu29e6f502014-11-24 14:27:29 +08002806 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2807 /* 3DSTATE_CONSTANT_PS */
2808 cmd_batch_pointer(cmd, 5, &dw);
2809 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2810 dw[1] = 0;
2811 dw[2] = 0;
2812 dw[3] = 0;
2813 dw[4] = 0;
2814
2815 /* 3DSTATE_WM */
2816 cmd_batch_pointer(cmd, 9, &dw);
2817 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2818 dw[1] = 0;
2819 dw[2] = 0;
2820 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002821
2822 switch (meta->ds.op) {
2823 case INTEL_CMD_META_DS_HIZ_CLEAR:
2824 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2825 break;
2826 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2827 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2828 break;
2829 case INTEL_CMD_META_DS_RESOLVE:
2830 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2831 break;
2832 default:
2833 dw[4] = 0;
2834 break;
2835 }
2836
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002837 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002838 dw[6] = 0;
2839 dw[7] = 0;
2840 dw[8] = 0;
2841
Chia-I Wu3adf7212014-10-24 15:34:07 +08002842 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002843 }
2844
Chia-I Wu3adf7212014-10-24 15:34:07 +08002845 /* a normal color write */
2846 assert(meta->dst.valid && !sh->uses);
2847
Chia-I Wu6032b892014-10-17 14:47:18 +08002848 /* 3DSTATE_CONSTANT_PS */
2849 offset = gen6_meta_ps_constants(cmd);
2850 cmd_batch_pointer(cmd, 5, &dw);
2851 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002852 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002853 dw[1] = offset;
2854 dw[2] = 0;
2855 dw[3] = 0;
2856 dw[4] = 0;
2857
2858 /* 3DSTATE_WM */
2859 offset = emit_shader(cmd, sh);
2860 cmd_batch_pointer(cmd, 9, &dw);
2861 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2862 dw[1] = offset;
2863 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2864 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002865 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002866 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002867 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002868 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2869 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002870
Chia-I Wu6032b892014-10-17 14:47:18 +08002871 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002872 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002873 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2874 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2875 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2876 if (meta->samples > 1) {
2877 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2878 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2879 } else {
2880 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2881 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2882 }
2883 dw[7] = 0;
2884 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002885
2886 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002887}
2888
2889static void gen7_meta_ps(struct intel_cmd *cmd)
2890{
2891 const struct intel_cmd_meta *meta = cmd->bind.meta;
2892 const struct intel_pipeline_shader *sh =
2893 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2894 uint32_t offset, *dw;
2895
2896 CMD_ASSERT(cmd, 7, 7.5);
2897
Chia-I Wu29e6f502014-11-24 14:27:29 +08002898 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2899 /* 3DSTATE_WM */
2900 cmd_batch_pointer(cmd, 3, &dw);
2901 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002902
2903 switch (meta->ds.op) {
2904 case INTEL_CMD_META_DS_HIZ_CLEAR:
2905 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2906 break;
2907 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2908 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2909 break;
2910 case INTEL_CMD_META_DS_RESOLVE:
2911 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2912 break;
2913 default:
2914 dw[1] = 0;
2915 break;
2916 }
2917
2918 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002919
2920 /* 3DSTATE_CONSTANT_GS */
2921 cmd_batch_pointer(cmd, 7, &dw);
2922 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2923 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2924
2925 /* 3DSTATE_PS */
2926 cmd_batch_pointer(cmd, 8, &dw);
2927 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2928 dw[1] = 0;
2929 dw[2] = 0;
2930 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002931 /* required to avoid hangs */
2932 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002933 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002934 dw[5] = 0;
2935 dw[6] = 0;
2936 dw[7] = 0;
2937
Chia-I Wu3adf7212014-10-24 15:34:07 +08002938 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002939 }
2940
Chia-I Wu3adf7212014-10-24 15:34:07 +08002941 /* a normal color write */
2942 assert(meta->dst.valid && !sh->uses);
2943
Chia-I Wu6032b892014-10-17 14:47:18 +08002944 /* 3DSTATE_WM */
2945 cmd_batch_pointer(cmd, 3, &dw);
2946 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002947 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002948 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2949 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2950 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2951 dw[2] = 0;
2952
2953 /* 3DSTATE_CONSTANT_PS */
2954 offset = gen6_meta_ps_constants(cmd);
2955 cmd_batch_pointer(cmd, 7, &dw);
2956 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002957 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002958 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002959 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002960 dw[4] = 0;
2961 dw[5] = 0;
2962 dw[6] = 0;
2963
2964 /* 3DSTATE_PS */
2965 offset = emit_shader(cmd, sh);
2966 cmd_batch_pointer(cmd, 8, &dw);
2967 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2968 dw[1] = offset;
2969 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2970 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002971 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002972
2973 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2974 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002975 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002976
2977 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002978 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002979 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002980 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002981 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002982 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002983
2984 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2985 dw[6] = 0;
2986 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002987
2988 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002989}
2990
2991static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2992{
2993 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002994 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002995
2996 CMD_ASSERT(cmd, 6, 7.5);
2997
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002998 if (!ds) {
2999 /* all zeros */
3000 static const struct intel_ds_view null_ds;
3001 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08003002 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003003
3004 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003005 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
3006 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3007 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003008
3009 if (cmd_gen(cmd) >= INTEL_GEN(7))
3010 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3011 else
3012 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003013}
3014
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003015static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3016 const struct intel_pipeline *pipeline)
3017{
3018 cmd->bind.pipeline.graphics = pipeline;
3019}
3020
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003021static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3022 const struct intel_pipeline *pipeline)
3023{
3024 cmd->bind.pipeline.compute = pipeline;
3025}
3026
3027static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
3028 const struct intel_pipeline_delta *delta)
3029{
3030 cmd->bind.pipeline.graphics_delta = delta;
3031}
3032
3033static void cmd_bind_compute_delta(struct intel_cmd *cmd,
3034 const struct intel_pipeline_delta *delta)
3035{
3036 cmd->bind.pipeline.compute_delta = delta;
3037}
3038
3039static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003040 const struct intel_desc_set *dset,
3041 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003042{
Chia-I Wuf8385062015-01-04 16:27:24 +08003043 const uint32_t size = sizeof(*dynamic_offsets) *
3044 dset->layout->dynamic_desc_count;
3045
3046 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
3047 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003048 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003049
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003050 cmd->bind.dset.graphics_dynamic_offsets = intel_alloc(cmd,
3051 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003052 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003053 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003054 return;
3055 }
3056
3057 cmd->bind.dset.graphics_dynamic_offset_size = size;
3058 }
3059
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003060 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003061 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003062}
3063
3064static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003065 const struct intel_desc_set *dset,
3066 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003067{
Chia-I Wuf8385062015-01-04 16:27:24 +08003068 const uint32_t size = sizeof(*dynamic_offsets) *
3069 dset->layout->dynamic_desc_count;
3070
3071 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
3072 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003073 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003074
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003075 cmd->bind.dset.compute_dynamic_offsets = intel_alloc(cmd,
3076 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003077 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003078 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003079 return;
3080 }
3081
3082 cmd->bind.dset.compute_dynamic_offset_size = size;
3083 }
3084
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003085 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003086 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003087}
3088
Chia-I Wu3b04af52014-11-08 10:48:20 +08003089static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003090 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003091 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003092{
Chia-I Wu714df452015-01-01 07:55:04 +08003093 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003094 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003095 return;
3096 }
3097
Chia-I Wu714df452015-01-01 07:55:04 +08003098 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003099 cmd->bind.vertex.offset[binding] = offset;
3100}
3101
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003102static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003103 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3105{
Chia-I Wu714df452015-01-01 07:55:04 +08003106 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003107 cmd->bind.index.offset = offset;
3108 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003109}
3110
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003111static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003112 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003113{
3114 cmd->bind.state.viewport = state;
3115}
3116
3117static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003118 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003119{
3120 cmd->bind.state.raster = state;
3121}
3122
3123static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003124 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003125{
3126 cmd->bind.state.ds = state;
3127}
3128
3129static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003130 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003131{
3132 cmd->bind.state.blend = state;
3133}
3134
Chia-I Wuf98dd882015-02-10 04:17:47 +08003135static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3136{
3137 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3138 struct intel_pipeline_rmap *rmaps[5] = {
3139 pipeline->vs.rmap,
3140 pipeline->tcs.rmap,
3141 pipeline->tes.rmap,
3142 pipeline->gs.rmap,
3143 pipeline->fs.rmap,
3144 };
3145 uint32_t max_write;
3146 int i;
3147
3148 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3149 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3150 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3151
3152 /* pad first */
3153 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3154
3155 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3156 const struct intel_pipeline_rmap *rmap = rmaps[i];
3157 const uint32_t surface_count = (rmap) ?
3158 rmap->rt_count + rmap->texture_resource_count +
3159 rmap->resource_count + rmap->uav_count : 0;
3160
3161 if (surface_count) {
3162 /* SURFACE_STATEs */
3163 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3164
3165 /* BINDING_TABLE_STATE */
3166 max_write += u_align(sizeof(uint32_t) * surface_count,
3167 GEN6_ALIGNMENT_SURFACE_STATE);
3168 }
3169 }
3170
3171 return max_write;
3172}
3173
3174static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3175{
3176 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3177 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3178 uint32_t max_surface_write;
3179
3180 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3181 if (cmd->bind.meta)
3182 max_surface_write = 64 * sizeof(uint32_t);
3183 else
3184 max_surface_write = cmd_get_max_surface_write(cmd);
3185
3186 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3187 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3188 /* SBA expects page-aligned addresses */
3189 writer->sba_offset = writer->used & ~0xfff;
3190
3191 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3192
3193 cmd_batch_state_base_address(cmd);
3194 }
3195}
3196
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003197static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003198 uint32_t vertex_start,
3199 uint32_t vertex_count,
3200 uint32_t instance_start,
3201 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003202 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003203 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003204{
3205 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003206 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003207 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3208
3209 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210
3211 emit_bounded_states(cmd);
3212
Chia-I Wuf98dd882015-02-10 04:17:47 +08003213 /* sanity check on cmd_get_max_surface_write() */
3214 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3215 surface_writer_used <= cmd_get_max_surface_write(cmd));
3216
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217 if (indexed) {
3218 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003219 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003220
3221 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3222 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3223 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003224 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003225 cmd->bind.index.offset, cmd->bind.index.type,
3226 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003227 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003228 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003229 cmd->bind.index.offset, cmd->bind.index.type,
3230 p->primitive_restart);
3231 }
3232 } else {
3233 assert(!vertex_base);
3234 }
3235
3236 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3237 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3238 vertex_start, instance_count, instance_start, vertex_base);
3239 } else {
3240 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3241 vertex_start, instance_count, instance_start, vertex_base);
3242 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003243
Chia-I Wu707a29e2014-08-27 12:51:47 +08003244 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003245 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003246 /* need to re-emit all workarounds */
3247 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003248
3249 if (intel_debug & INTEL_DEBUG_NOCACHE)
3250 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003251}
3252
Chia-I Wuc14d1562014-10-17 09:49:22 +08003253void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3254{
Chia-I Wu6032b892014-10-17 14:47:18 +08003255 cmd->bind.meta = meta;
3256
Chia-I Wuf98dd882015-02-10 04:17:47 +08003257 cmd_adjust_state_base_address(cmd);
3258
Chia-I Wu6032b892014-10-17 14:47:18 +08003259 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003260 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003261
3262 gen6_meta_dynamic_states(cmd);
3263 gen6_meta_surface_states(cmd);
3264
3265 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3266 gen7_meta_urb(cmd);
3267 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003268 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003269 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003270 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003271 gen6_meta_wm(cmd);
3272 gen7_meta_ps(cmd);
3273 gen6_meta_depth_buffer(cmd);
3274
3275 cmd_wa_gen7_post_command_cs_stall(cmd);
3276 cmd_wa_gen7_post_command_depth_stall(cmd);
3277
Chia-I Wu29e6f502014-11-24 14:27:29 +08003278 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3279 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003280 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003281 } else {
3282 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3283 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003284 } else {
3285 gen6_meta_urb(cmd);
3286 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003287 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003288 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003289 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003290 gen6_meta_wm(cmd);
3291 gen6_meta_ps(cmd);
3292 gen6_meta_depth_buffer(cmd);
3293
Chia-I Wu29e6f502014-11-24 14:27:29 +08003294 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3295 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003296 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003297 } else {
3298 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3299 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003300 }
3301
3302 cmd->bind.draw_count++;
3303 /* need to re-emit all workarounds */
3304 cmd->bind.wa_flags = 0;
3305
3306 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003307
Chia-I Wubbc7d912015-02-27 14:59:50 -07003308 /* make the normal path believe the render pass has changed */
3309 cmd->bind.render_pass_changed = true;
3310
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003311 if (intel_debug & INTEL_DEBUG_NOCACHE)
3312 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003313}
3314
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003315ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003316 XGL_CMD_BUFFER cmdBuffer,
3317 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3318 XGL_PIPELINE pipeline)
3319{
3320 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3321
3322 switch (pipelineBindPoint) {
3323 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003324 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003325 break;
3326 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003327 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003328 break;
3329 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003330 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003331 break;
3332 }
3333}
3334
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003335ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003336 XGL_CMD_BUFFER cmdBuffer,
3337 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3338 XGL_PIPELINE_DELTA delta)
3339{
3340 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3341
3342 switch (pipelineBindPoint) {
3343 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003344 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003345 break;
3346 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003347 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003348 break;
3349 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003350 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003351 break;
3352 }
3353}
3354
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003355ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003356 XGL_CMD_BUFFER cmdBuffer,
3357 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003358 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003359{
3360 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3361
3362 switch (stateBindPoint) {
3363 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003364 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003365 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003366 break;
3367 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003368 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003369 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003370 break;
3371 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003372 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003373 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003374 break;
3375 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003376 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003377 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003378 break;
3379 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003380 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003381 break;
3382 }
3383}
3384
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003385ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003386 XGL_CMD_BUFFER cmdBuffer,
3387 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003388 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003389 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003390{
3391 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003392 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003393
3394 switch (pipelineBindPoint) {
3395 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003396 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003397 break;
3398 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003399 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003400 break;
3401 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003402 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003403 break;
3404 }
3405}
3406
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003407ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003408 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003409 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003410 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003411 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003412{
3413 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003414 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003415
Chia-I Wu714df452015-01-01 07:55:04 +08003416 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003417}
3418
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003419ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003420 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003421 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003422 XGL_GPU_SIZE offset,
3423 XGL_INDEX_TYPE indexType)
3424{
3425 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003426 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003427
Chia-I Wu714df452015-01-01 07:55:04 +08003428 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003429}
3430
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003431ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003432 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003433 uint32_t firstVertex,
3434 uint32_t vertexCount,
3435 uint32_t firstInstance,
3436 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003437{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003438 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003439
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003440 cmd_draw(cmd, firstVertex, vertexCount,
3441 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003442}
3443
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003444ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003445 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003446 uint32_t firstIndex,
3447 uint32_t indexCount,
3448 int32_t vertexOffset,
3449 uint32_t firstInstance,
3450 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003451{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003452 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003453
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003454 cmd_draw(cmd, firstIndex, indexCount,
3455 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003456}
3457
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003458ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003459 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003460 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003461 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003462 uint32_t count,
3463 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003464{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003465 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3466
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003467 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003468}
3469
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003470ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003471 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003472 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003473 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003474 uint32_t count,
3475 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003476{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003477 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3478
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003479 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003480}
3481
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003482ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003483 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003484 uint32_t x,
3485 uint32_t y,
3486 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003487{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003488 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3489
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003490 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003491}
3492
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003493ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003494 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003495 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003496 XGL_GPU_SIZE offset)
3497{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003498 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3499
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003500 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003501}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003502
Chia-I Wude26bdf2015-02-18 15:47:12 -07003503ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003504 XGL_CMD_BUFFER cmdBuffer,
3505 XGL_RENDER_PASS renderPass)
3506{
3507 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3508
3509 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3510}
3511
Chia-I Wude26bdf2015-02-18 15:47:12 -07003512ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003513 XGL_CMD_BUFFER cmdBuffer,
3514 XGL_RENDER_PASS renderPass)
3515{
3516 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3517
3518 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3519}