blob: c3f7c4bce7d7cde1f54b3e12efa417c47c8790e0 [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;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700394 switch (pipeline->db_format) {
395 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700398 case XGL_FMT_D32_SFLOAT:
399 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700413 /* Scissor is always enabled */
414 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
415
Tony Barbourfa6cac72015-01-16 14:27:35 -0700416 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800417 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
419 } else {
420 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
421 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
422 }
423
Chia-I Wu8016a172014-08-29 18:31:32 +0800424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
Chia-I Wu8016a172014-08-29 18:31:32 +0800443static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
444{
445 const uint8_t cmd_len = 20;
446 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
447 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800448 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800450 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800451
452 CMD_ASSERT(cmd, 6, 6);
453
454 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800455
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 cmd_batch_pointer(cmd, cmd_len, &dw);
457 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800458 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800460 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800461}
462
463static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
464{
465 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 7, 7.5);
469
Chia-I Wu72292b72014-09-09 10:48:33 +0800470 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800471 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
472 (cmd_len - 2);
473 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474}
475
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800476static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
477{
478 const uint8_t cmd_len = 4;
479 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
480 (cmd_len - 2);
481 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700482 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800483 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700484 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800485 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800486
487 CMD_ASSERT(cmd, 6, 7.5);
488
489 dw1 = GEN6_CLIP_DW1_STATISTICS;
490 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
491 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
492 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800494 }
495
496 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
497 GEN6_CLIP_DW2_XY_TEST_ENABLE |
498 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700499 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800500 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
501 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
502 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
503
504 if (pipeline->rasterizerDiscardEnable)
505 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
506 else
507 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
508
509 if (pipeline->depthClipEnable)
510 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
511
512 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
513 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
514 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
515 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
516
517 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
518 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
519 (viewport->viewport_count - 1);
520
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600521 /* TODO: framebuffer requests layer_count > 1 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700522 if (cmd->bind.render_pass->fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600523 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
524 }
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
527 dw[0] = dw0;
528 dw[1] = dw1;
529 dw[2] = dw2;
530 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800531}
532
Chia-I Wu784d3042014-12-19 14:30:04 +0800533static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600534 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800535 const struct intel_pipeline *pipeline,
536 const struct intel_pipeline_shader *sh)
537{
538 int scratch_space;
539
540 CMD_ASSERT(cmd, 6, 7.5);
541
542 assert(sh->per_thread_scratch_size &&
543 sh->per_thread_scratch_size % 1024 == 0 &&
544 u_is_pow2(sh->per_thread_scratch_size) &&
545 sh->scratch_offset % 1024 == 0);
546 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
547
548 cmd_reserve_reloc(cmd, 1);
549 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
550 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
551}
552
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800553static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
554{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800555 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800556 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800557 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600558 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700559 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560
561 CMD_ASSERT(cmd, 6, 6);
562
563 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
564
565 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
566 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
567
568 dw4 = GEN6_WM_DW4_STATISTICS |
569 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
570 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700571 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800573 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700574 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
575 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800576
Cody Northrope86574e2015-02-24 14:15:29 -0700577 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700578 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700579
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800580 if (fs->uses & INTEL_SHADER_USE_KILL ||
581 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700582 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583
Cody Northrope238deb2015-01-26 14:41:36 -0700584 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800585 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
586 if (fs->uses & INTEL_SHADER_USE_DEPTH)
587 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
588 if (fs->uses & INTEL_SHADER_USE_W)
589 dw5 |= GEN6_WM_DW5_PS_USE_W;
590
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700591 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700592 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800593
594 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700595 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596 GEN6_WM_DW6_ZW_INTERP_PIXEL |
597 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
598 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
599
Tony Barbourfa6cac72015-01-16 14:27:35 -0700600 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
602 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
603 } else {
604 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
605 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
606 }
607
Cody Northrope86574e2015-02-24 14:15:29 -0700608 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
609
Chia-I Wu784d3042014-12-19 14:30:04 +0800610 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800611 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800612 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800613 dw[2] = dw2;
614 dw[3] = 0; /* scratch */
615 dw[4] = dw4;
616 dw[5] = dw5;
617 dw[6] = dw6;
618 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700619 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800620
621 if (fs->per_thread_scratch_size)
622 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800623}
624
625static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
626{
627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800628 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800629 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800630 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800631
632 CMD_ASSERT(cmd, 7, 7.5);
633
634 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
635
636 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700637 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638 GEN7_WM_DW1_ZW_INTERP_PIXEL |
639 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
640 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
641
642 if (fs->uses & INTEL_SHADER_USE_KILL ||
643 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700644 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645
Cody Northrope238deb2015-01-26 14:41:36 -0700646 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
647
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648 if (fs->uses & INTEL_SHADER_USE_DEPTH)
649 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
650 if (fs->uses & INTEL_SHADER_USE_W)
651 dw1 |= GEN7_WM_DW1_PS_USE_W;
652
653 dw2 = 0;
654
Tony Barbourfa6cac72015-01-16 14:27:35 -0700655 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800656 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
657 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
658 } else {
659 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
660 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
661 }
662
Chia-I Wu72292b72014-09-09 10:48:33 +0800663 cmd_batch_pointer(cmd, cmd_len, &dw);
664 dw[0] = dw0;
665 dw[1] = dw1;
666 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667}
668
669static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
670{
671 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800672 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800673 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700674 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600675 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676
677 CMD_ASSERT(cmd, 7, 7.5);
678
679 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
680
681 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
682 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
683
684 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700685 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800686
Cody Northrope86574e2015-02-24 14:15:29 -0700687 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700688 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700689
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800691 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800694 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800695 }
696
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 if (fs->in_count)
698 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
699
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700700 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
702
703 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
704 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700705 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
706
707 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800708
Chia-I Wu784d3042014-12-19 14:30:04 +0800709 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800710 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800711 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[2] = dw2;
713 dw[3] = 0; /* scratch */
714 dw[4] = dw4;
715 dw[5] = dw5;
716 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700717 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800718
719 if (fs->per_thread_scratch_size)
720 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721}
722
Chia-I Wu8ada4242015-03-02 11:19:33 -0700723static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
724 uint32_t sample_count)
725{
726 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
727 uint32_t dw1, dw2, dw3, *dw;
728
729 CMD_ASSERT(cmd, 6, 7.5);
730
731 switch (sample_count) {
732 case 4:
733 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
734 dw2 = cmd->dev->sample_pattern_4x;
735 dw3 = 0;
736 break;
737 case 8:
738 assert(cmd_gen(cmd) >= INTEL_GEN(7));
739 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
740 dw2 = cmd->dev->sample_pattern_8x[0];
741 dw3 = cmd->dev->sample_pattern_8x[1];
742 break;
743 default:
744 assert(sample_count <= 1);
745 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
746 dw2 = 0;
747 dw3 = 0;
748 break;
749 }
750
751 cmd_batch_pointer(cmd, cmd_len, &dw);
752
753 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
754 dw[1] = dw1;
755 dw[2] = dw2;
756 if (cmd_gen(cmd) >= INTEL_GEN(7))
757 dw[3] = dw3;
758}
759
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800760static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700761 const struct intel_ds_view *view,
762 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800763{
764 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800765 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600766 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767
768 CMD_ASSERT(cmd, 6, 7.5);
769
770 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800771 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
772 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773 dw0 |= (cmd_len - 2);
774
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
776 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700777
Chia-I Wu72292b72014-09-09 10:48:33 +0800778 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700779 /* note that we only enable HiZ on Gen7+ */
780 if (!optimal_ds)
781 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
782
Chia-I Wu72292b72014-09-09 10:48:33 +0800783 dw[2] = 0;
784 dw[3] = view->cmd[2];
785 dw[4] = view->cmd[3];
786 dw[5] = view->cmd[4];
787 dw[6] = view->cmd[5];
788
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600789 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 cmd_reserve_reloc(cmd, 1);
791 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
792 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600793 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800794}
795
796static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700797 const struct intel_ds_view *view,
798 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799{
800 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600802 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800803
804 CMD_ASSERT(cmd, 6, 7.5);
805
806 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800807 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
808 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809 dw0 |= (cmd_len - 2);
810
Chia-I Wu72292b72014-09-09 10:48:33 +0800811 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
812 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800813
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700814 if (view->has_stencil) {
815 dw[1] = view->cmd[6];
816
Chia-I Wu72292b72014-09-09 10:48:33 +0800817 cmd_reserve_reloc(cmd, 1);
818 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
819 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700820 } else {
821 dw[1] = 0;
822 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600823 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800824}
825
826static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700827 const struct intel_ds_view *view,
828 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800829{
830 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600832 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800833
834 CMD_ASSERT(cmd, 6, 7.5);
835
836 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800837 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
838 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800839 dw0 |= (cmd_len - 2);
840
Chia-I Wu72292b72014-09-09 10:48:33 +0800841 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
842 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800843
Chia-I Wu73520ac2015-02-19 11:17:45 -0700844 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700845 dw[1] = view->cmd[8];
846
Chia-I Wu72292b72014-09-09 10:48:33 +0800847 cmd_reserve_reloc(cmd, 1);
848 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
849 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700850 } else {
851 dw[1] = 0;
852 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600853 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800854}
855
Chia-I Wuf8231032014-08-25 10:44:45 +0800856static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
857 uint32_t clear_val)
858{
859 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800860 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800861 GEN6_CLEAR_PARAMS_DW0_VALID |
862 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800864
865 CMD_ASSERT(cmd, 6, 6);
866
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 cmd_batch_pointer(cmd, cmd_len, &dw);
868 dw[0] = dw0;
869 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800870}
871
872static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
873 uint32_t clear_val)
874{
875 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800876 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800877 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800878 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800879
880 CMD_ASSERT(cmd, 7, 7.5);
881
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_batch_pointer(cmd, cmd_len, &dw);
883 dw[0] = dw0;
884 dw[1] = clear_val;
885 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800886}
887
Chia-I Wu302742d2014-08-22 10:28:29 +0800888static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 uint32_t blend_offset,
890 uint32_t ds_offset,
891 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800892{
893 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800894 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800895
896 CMD_ASSERT(cmd, 6, 6);
897
Chia-I Wu426072d2014-08-26 14:31:55 +0800898 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800899 (cmd_len - 2);
900
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 cmd_batch_pointer(cmd, cmd_len, &dw);
902 dw[0] = dw0;
903 dw[1] = blend_offset | 1;
904 dw[2] = ds_offset | 1;
905 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800906}
907
Chia-I Wu1744cca2014-08-22 11:10:17 +0800908static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t clip_offset,
910 uint32_t sf_offset,
911 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800912{
913 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915
916 CMD_ASSERT(cmd, 6, 6);
917
Chia-I Wu426072d2014-08-26 14:31:55 +0800918 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700919 GEN6_VP_PTR_DW0_CLIP_CHANGED |
920 GEN6_VP_PTR_DW0_SF_CHANGED |
921 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922 (cmd_len - 2);
923
Chia-I Wu72292b72014-09-09 10:48:33 +0800924 cmd_batch_pointer(cmd, cmd_len, &dw);
925 dw[0] = dw0;
926 dw[1] = clip_offset;
927 dw[2] = sf_offset;
928 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800929}
930
931static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800933{
934 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936
937 CMD_ASSERT(cmd, 6, 6);
938
Chia-I Wu426072d2014-08-26 14:31:55 +0800939 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800940 (cmd_len - 2);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800945}
946
Chia-I Wu42a56202014-08-23 16:47:48 +0800947static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800948 uint32_t vs_offset,
949 uint32_t gs_offset,
950 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800951{
952 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800954
955 CMD_ASSERT(cmd, 6, 6);
956
Chia-I Wu426072d2014-08-26 14:31:55 +0800957 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700958 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
959 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
960 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800961 (cmd_len - 2);
962
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 cmd_batch_pointer(cmd, cmd_len, &dw);
964 dw[0] = dw0;
965 dw[1] = vs_offset;
966 dw[2] = gs_offset;
967 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800968}
969
Chia-I Wu257e75e2014-08-29 14:06:35 +0800970static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800971 uint32_t vs_offset,
972 uint32_t gs_offset,
973 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800974{
975 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977
978 CMD_ASSERT(cmd, 6, 6);
979
980 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700981 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
982 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
983 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800984 (cmd_len - 2);
985
Chia-I Wu72292b72014-09-09 10:48:33 +0800986 cmd_batch_pointer(cmd, cmd_len, &dw);
987 dw[0] = dw0;
988 dw[1] = vs_offset;
989 dw[2] = gs_offset;
990 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800991}
992
Chia-I Wu302742d2014-08-22 10:28:29 +0800993static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800994 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800995{
996 const uint8_t cmd_len = 2;
997 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
998 GEN6_RENDER_SUBTYPE_3D |
999 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001000 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002 cmd_batch_pointer(cmd, cmd_len, &dw);
1003 dw[0] = dw0;
1004 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005}
1006
Chia-I Wua6c4f152014-12-02 04:19:58 +08001007static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001008{
Chia-I Wue6073342014-11-30 09:43:42 +08001009 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001010 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1011 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012
1013 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001014 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001015
Tony Barbourfa6cac72015-01-16 14:27:35 -07001016 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001017}
1018
Chia-I Wu72292b72014-09-09 10:48:33 +08001019static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001020 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001021{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001022 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001023 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001024 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001025 uint32_t dw[3];
1026
1027 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001028 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001029 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001030 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1031 (state->ds_info.stencilReadMask & 0xff) << 8 |
1032 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001033 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034
1035 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036
1037 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1038 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001039
Chia-I Wu00b51a82014-09-09 12:07:37 +08001040 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001041 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001042}
1043
Chia-I Wu72292b72014-09-09 10:48:33 +08001044static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001045 uint32_t stencil_ref,
1046 const uint32_t blend_color[4])
1047{
Chia-I Wue6073342014-11-30 09:43:42 +08001048 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001049 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001050 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001051
1052 CMD_ASSERT(cmd, 6, 7.5);
1053
Chia-I Wu00b51a82014-09-09 12:07:37 +08001054 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1055 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001056 dw[0] = stencil_ref;
1057 dw[1] = 0;
1058 dw[2] = blend_color[0];
1059 dw[3] = blend_color[1];
1060 dw[4] = blend_color[2];
1061 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001062
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001064}
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067{
Chia-I Wu8370b402014-08-29 12:28:37 +08001068 CMD_ASSERT(cmd, 6, 7.5);
1069
Chia-I Wu707a29e2014-08-27 12:51:47 +08001070 if (!cmd->bind.draw_count)
1071 return;
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001074 return;
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001077
1078 /*
1079 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1080 *
1081 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1082 * pipe-control with a post-sync op and no write-cache flushes."
1083 *
1084 * The workaround below necessitates this workaround.
1085 */
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_CS_STALL |
1088 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001090
Chia-I Wud6d079d2014-08-31 13:14:21 +08001091 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1092 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001093}
1094
Chia-I Wu8370b402014-08-29 12:28:37 +08001095static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001096{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001097 CMD_ASSERT(cmd, 6, 7.5);
1098
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001099 if (!cmd->bind.draw_count)
1100 return;
1101
Chia-I Wud6d079d2014-08-31 13:14:21 +08001102 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1103 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001104}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001105
Chia-I Wu8370b402014-08-29 12:28:37 +08001106static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1107{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001108 CMD_ASSERT(cmd, 7, 7.5);
1109
Chia-I Wu8370b402014-08-29 12:28:37 +08001110 if (!cmd->bind.draw_count)
1111 return;
1112
1113 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001114
1115 gen6_PIPE_CONTROL(cmd,
1116 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001117 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001118}
1119
Chia-I Wu8370b402014-08-29 12:28:37 +08001120static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1121{
1122 CMD_ASSERT(cmd, 7, 7.5);
1123
Chia-I Wu8370b402014-08-29 12:28:37 +08001124 /*
1125 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1126 *
1127 * "One of the following must also be set (when CS stall is set):
1128 *
1129 * * Render Target Cache Flush Enable ([12] of DW1)
1130 * * Depth Cache Flush Enable ([0] of DW1)
1131 * * Stall at Pixel Scoreboard ([1] of DW1)
1132 * * Depth Stall ([13] of DW1)
1133 * * Post-Sync Operation ([13] of DW1)"
1134 */
1135 gen6_PIPE_CONTROL(cmd,
1136 GEN6_PIPE_CONTROL_CS_STALL |
1137 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001138 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001139}
1140
1141static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1142{
1143 CMD_ASSERT(cmd, 7, 7.5);
1144
Chia-I Wu8370b402014-08-29 12:28:37 +08001145 cmd_wa_gen6_pre_depth_stall_write(cmd);
1146
Chia-I Wud6d079d2014-08-31 13:14:21 +08001147 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001148}
1149
1150static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1151{
1152 CMD_ASSERT(cmd, 6, 7.5);
1153
1154 if (!cmd->bind.draw_count)
1155 return;
1156
1157 /*
1158 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1159 *
1160 * "Driver must guarentee that all the caches in the depth pipe are
1161 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1162 * requires driver to send a PIPE_CONTROL with a CS stall along with
1163 * a Depth Flush prior to this command."
1164 *
1165 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1166 *
1167 * "Driver must ierarchi 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 gen6_PIPE_CONTROL(cmd,
1173 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1174 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001175 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001176}
1177
1178static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1179{
1180 CMD_ASSERT(cmd, 6, 7.5);
1181
1182 if (!cmd->bind.draw_count)
1183 return;
1184
1185 /*
1186 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1187 *
1188 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1189 * and a post sync operation prior to the group of depth
1190 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1191 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1192 *
1193 * This workaround satifies all the conditions.
1194 */
1195 cmd_wa_gen6_pre_depth_stall_write(cmd);
1196
1197 /*
1198 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1199 *
1200 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1201 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1202 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1203 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1204 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1205 * Depth Flush Bit set, followed by another pipelined depth stall
1206 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1207 * guarantee that the pipeline from WM onwards is already flushed
1208 * (e.g., via a preceding MI_FLUSH)."
1209 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001210 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1211 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1212 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001213}
1214
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001215void cmd_batch_state_base_address(struct intel_cmd *cmd)
1216{
1217 const uint8_t cmd_len = 10;
1218 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1219 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001220 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001221 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001222 uint32_t pos;
1223 uint32_t *dw;
1224
1225 CMD_ASSERT(cmd, 6, 7.5);
1226
1227 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1228
1229 dw[0] = dw0;
1230 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001231 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001232 dw[2] = 1;
1233 dw[3] = 1;
1234 dw[4] = 1;
1235 dw[5] = 1;
1236 /* end offsets */
1237 dw[6] = 1;
1238 dw[7] = 1 + 0xfffff000;
1239 dw[8] = 1 + 0xfffff000;
1240 dw[9] = 1;
1241
1242 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001243 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1244 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1245 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1246 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1247 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1248 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001249}
1250
Chia-I Wu525c6602014-08-27 10:22:34 +08001251void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1252{
Mike Stroyan552fda42015-01-30 17:21:08 -07001253 if (pipe_control_dw0 == 0)
1254 return;
1255
Chia-I Wu525c6602014-08-27 10:22:34 +08001256 if (!cmd->bind.draw_count)
1257 return;
1258
1259 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1260
Chia-I Wu8370b402014-08-29 12:28:37 +08001261 /*
1262 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1263 *
1264 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1265 * PIPE_CONTROL with any non-zero post-sync-op is required."
1266 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001267 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001268 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001269
Chia-I Wu092279a2014-08-30 19:05:30 +08001270 /*
1271 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1272 *
1273 * "One of the following must also be set (when CS stall is set):
1274 *
1275 * * Render Target Cache Flush Enable ([12] of DW1)
1276 * * Depth Cache Flush Enable ([0] of DW1)
1277 * * Stall at Pixel Scoreboard ([1] of DW1)
1278 * * Depth Stall ([13] of DW1)
1279 * * Post-Sync Operation ([13] of DW1)"
1280 */
1281 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1282 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1283 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1284 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1285 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1286 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1287
Chia-I Wud6d079d2014-08-31 13:14:21 +08001288 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001289}
1290
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001291void cmd_batch_flush_all(struct intel_cmd *cmd)
1292{
1293 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1294 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1295 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1296 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1297 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1298 GEN6_PIPE_CONTROL_CS_STALL);
1299}
1300
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001301void cmd_batch_depth_count(struct intel_cmd *cmd,
1302 struct intel_bo *bo,
1303 XGL_GPU_SIZE offset)
1304{
1305 cmd_wa_gen6_pre_depth_stall_write(cmd);
1306
1307 gen6_PIPE_CONTROL(cmd,
1308 GEN6_PIPE_CONTROL_DEPTH_STALL |
1309 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001310 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001311}
1312
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001313void cmd_batch_timestamp(struct intel_cmd *cmd,
1314 struct intel_bo *bo,
1315 XGL_GPU_SIZE offset)
1316{
1317 /* need any WA or stall? */
1318 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1319}
1320
1321void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001322 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001323 struct intel_bo *bo,
1324 XGL_GPU_SIZE offset,
1325 uint64_t val)
1326{
1327 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001328 gen6_PIPE_CONTROL(cmd,
1329 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1330 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001331}
1332
Chia-I Wu302742d2014-08-22 10:28:29 +08001333static void gen6_cc_states(struct intel_cmd *cmd)
1334{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001335 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1336 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001337 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001338 uint32_t stencil_ref;
1339 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001340
1341 CMD_ASSERT(cmd, 6, 6);
1342
Chia-I Wua6c4f152014-12-02 04:19:58 +08001343 blend_offset = gen6_BLEND_STATE(cmd);
1344
1345 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001346 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001347 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001348 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001349
1350 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001352 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1353 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001354 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001355 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001356 stencil_ref = 0;
1357 }
1358
Chia-I Wu72292b72014-09-09 10:48:33 +08001359 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001360
Chia-I Wu72292b72014-09-09 10:48:33 +08001361 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001362}
1363
Chia-I Wu1744cca2014-08-22 11:10:17 +08001364static void gen6_viewport_states(struct intel_cmd *cmd)
1365{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001366 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001367 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001368
1369 if (!viewport)
1370 return;
1371
Tony Barbourfa6cac72015-01-16 14:27:35 -07001372 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001373 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001374
1375 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001376 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001377 viewport->cmd);
1378
1379 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001380 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 &viewport->cmd[viewport->cmd_clip_pos]);
1382
1383 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001384 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001385 &viewport->cmd[viewport->cmd_cc_pos]);
1386
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001387 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1388 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1389 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001390
1391 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393
Chia-I Wub1d450a2014-09-09 13:48:03 +08001394 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001395}
1396
Chia-I Wu302742d2014-08-22 10:28:29 +08001397static void gen7_cc_states(struct intel_cmd *cmd)
1398{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001399 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1400 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001401 uint32_t stencil_ref;
1402 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001403 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001404
1405 CMD_ASSERT(cmd, 7, 7.5);
1406
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001407 if (!blend && !ds)
1408 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001409
Chia-I Wua6c4f152014-12-02 04:19:58 +08001410 offset = gen6_BLEND_STATE(cmd);
1411 gen7_3dstate_pointer(cmd,
1412 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001413
Chia-I Wua6c4f152014-12-02 04:19:58 +08001414 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001415 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001416 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001417 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001418
1419 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001420 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001421 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1422 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001423 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001424 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1425 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001426 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1427 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001428 } else {
1429 stencil_ref = 0;
1430 }
1431
Chia-I Wu72292b72014-09-09 10:48:33 +08001432 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001433 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001434 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001435}
1436
Chia-I Wu1744cca2014-08-22 11:10:17 +08001437static void gen7_viewport_states(struct intel_cmd *cmd)
1438{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001439 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001441
1442 if (!viewport)
1443 return;
1444
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001445 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001446
Chia-I Wub1d450a2014-09-09 13:48:03 +08001447 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001448 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001449 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001450 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001451 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1452 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001453
1454 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001455 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001456 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001457 gen7_3dstate_pointer(cmd,
1458 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001459 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001460
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001461 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1462 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1463 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1464 gen7_3dstate_pointer(cmd,
1465 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1466 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001467}
1468
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001469static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001470 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001471{
1472 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001473 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001474
Chia-I Wu72292b72014-09-09 10:48:33 +08001475 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001476
1477 dw[0] = GEN6_RENDER_TYPE_RENDER |
1478 GEN6_RENDER_SUBTYPE_3D |
1479 subop | (cmd_len - 2);
1480 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001481 dw[2] = 0;
1482 dw[3] = 0;
1483 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001484}
1485
1486static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001487 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001488{
1489 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001490 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001491
Chia-I Wu72292b72014-09-09 10:48:33 +08001492 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001493
1494 dw[0] = GEN6_RENDER_TYPE_RENDER |
1495 GEN6_RENDER_SUBTYPE_3D |
1496 subop | (cmd_len - 2);
1497 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001498 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001499 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001500 dw[4] = 0;
1501 dw[5] = 0;
1502 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001503}
1504
Chia-I Wu625105f2014-10-13 15:35:29 +08001505static uint32_t emit_samplers(struct intel_cmd *cmd,
1506 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001507{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001508 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1509 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001510 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001511 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001512 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001513 uint32_t surface_count;
1514 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001515
1516 CMD_ASSERT(cmd, 6, 7.5);
1517
Chia-I Wu625105f2014-10-13 15:35:29 +08001518 if (!rmap || !rmap->sampler_count)
1519 return 0;
1520
Cody Northrop40316a32014-12-09 19:08:33 -07001521 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001522
Chia-I Wudcb509d2014-12-10 08:53:10 +08001523 /*
1524 * note that we cannot call cmd_state_pointer() here as the following
1525 * cmd_state_pointer() would invalidate the pointer
1526 */
1527 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001528 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001529 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001530
1531 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001532 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001533 4 * rmap->sampler_count, &sampler_dw);
1534
Chia-I Wudcb509d2014-12-10 08:53:10 +08001535 cmd_state_update(cmd, border_offset,
1536 border_stride * rmap->sampler_count, &border_dw);
1537
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001538 for (i = 0; i < rmap->sampler_count; i++) {
1539 const struct intel_pipeline_rmap_slot *slot =
1540 &rmap->slots[surface_count + i];
1541 const struct intel_sampler *sampler;
1542
Chia-I Wuf8385062015-01-04 16:27:24 +08001543 switch (slot->type) {
1544 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001545 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001546 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001547 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001548 sampler = NULL;
1549 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001550 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001551 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001552 sampler = NULL;
1553 break;
1554 }
1555
1556 if (sampler) {
1557 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1558
1559 sampler_dw[0] = sampler->cmd[0];
1560 sampler_dw[1] = sampler->cmd[1];
1561 sampler_dw[2] = border_offset;
1562 sampler_dw[3] = sampler->cmd[2];
1563 } else {
1564 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1565 sampler_dw[1] = 0;
1566 sampler_dw[2] = 0;
1567 sampler_dw[3] = 0;
1568 }
1569
1570 border_offset += border_stride * 4;
1571 border_dw += border_stride;
1572 sampler_dw += 4;
1573 }
1574
Chia-I Wu625105f2014-10-13 15:35:29 +08001575 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001576}
1577
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001578static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001579 const struct intel_pipeline_rmap *rmap,
1580 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001581{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001582 const uint32_t sba_offset =
1583 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001584 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001585 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001586 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001587
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001588 CMD_ASSERT(cmd, 6, 7.5);
1589
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001590 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001591 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001592 if (!surface_count)
1593 return 0;
1594
Chia-I Wu42a56202014-08-23 16:47:48 +08001595 assert(surface_count <= ARRAY_SIZE(binding_table));
1596
1597 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001598 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001599 struct intel_null_view null_view;
1600 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001601
Chia-I Wuf8385062015-01-04 16:27:24 +08001602 switch (slot->type) {
1603 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001604 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001605 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001606 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1607 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001608
Chia-I Wu787a05b2014-12-05 11:02:20 +08001609 if (view) {
1610 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1611 GEN6_ALIGNMENT_SURFACE_STATE,
1612 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001613
Chia-I Wu787a05b2014-12-05 11:02:20 +08001614 cmd_reserve_reloc(cmd, 1);
1615 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1616 view->cmd[1], INTEL_RELOC_WRITE);
1617 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001618 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001619 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001620 }
1621 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001622 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001623 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001624 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1625 const struct intel_mem *mem;
1626 bool read_only;
1627 const uint32_t *cmd_data;
1628 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001629
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001630 assert(dyn_idx < 0 ||
1631 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001632
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001633 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1634 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001635 if (mem) {
1636 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1637 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1638 const uint32_t reloc_flags =
1639 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001640
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001642 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001643 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001644
1645 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001646 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1647 cmd_data[1] + dynamic_offset, reloc_flags);
1648 } else {
1649 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001650 }
1651 }
1652 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001653 case INTEL_PIPELINE_RMAP_UNUSED:
1654 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001655 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001656 default:
1657 assert(!"unexpected rmap type");
1658 need_null_view = true;
1659 break;
1660 }
1661
1662 if (need_null_view) {
1663 intel_null_view_init(&null_view, cmd->dev);
1664 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1665 GEN6_ALIGNMENT_SURFACE_STATE,
1666 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001667 }
1668
Chia-I Wuf98dd882015-02-10 04:17:47 +08001669 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001670 }
1671
Chia-I Wuf98dd882015-02-10 04:17:47 +08001672 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001673 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001674 surface_count, binding_table) - sba_offset;
1675
1676 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1677 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1678
1679 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001680}
1681
Chia-I Wu1d125092014-10-08 08:49:38 +08001682static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1683{
1684 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001685 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1686 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001687 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001688
1689 CMD_ASSERT(cmd, 6, 7.5);
1690
1691 if (!pipeline->vb_count)
1692 return;
1693
1694 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1695
1696 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1697 dw++;
1698 pos++;
1699
1700 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001701 assert(pipeline->vb[i].strideInBytes <= 2048);
1702
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001703 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001704 pipeline->vb[i].strideInBytes;
1705
Chia-I Wub3686982015-02-27 09:51:16 -07001706 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001707 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1708 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001709 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001710
1711 switch (pipeline->vb[i].stepRate) {
1712 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001713 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001714 dw[3] = 0;
1715 break;
1716 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001717 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001718 dw[3] = 1;
1719 break;
1720 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001721 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001722 dw[3] = 0;
1723 break;
1724 default:
1725 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001726 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001727 dw[3] = 0;
1728 break;
1729 }
1730
Chia-I Wu714df452015-01-01 07:55:04 +08001731 if (cmd->bind.vertex.buf[i]) {
1732 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001733 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001734
1735 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001736 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1737 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001738 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001739 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001740 dw[1] = 0;
1741 dw[2] = 0;
1742 }
1743
1744 dw += 4;
1745 pos += 4;
1746 }
1747}
1748
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001749static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1750{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1752 const struct intel_pipeline_shader *vs = &pipeline->vs;
1753 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001754 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001755 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001756 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001757 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001758
1759 CMD_ASSERT(cmd, 6, 7.5);
1760
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001761 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001762 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1763 *
1764 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1765 * 128-bit vertex elements to be passed into the payload for each
1766 * vertex."
1767 *
1768 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1769 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001770 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001771 vue_read_len = (vs->in_count + 1) / 2;
1772 if (!vue_read_len)
1773 vue_read_len = 1;
1774
1775 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1776 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1777
1778 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1779 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1780 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001781
1782 dw5 = GEN6_VS_DW5_STATISTICS |
1783 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001784
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001785 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001786 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001787 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001788 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001789
Chia-I Wube0a3d92014-09-02 13:20:59 +08001790 if (pipeline->disable_vs_cache)
1791 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1792
Chia-I Wu784d3042014-12-19 14:30:04 +08001793 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001794 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001795 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001796 dw[2] = dw2;
1797 dw[3] = 0; /* scratch */
1798 dw[4] = dw4;
1799 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001800
1801 if (vs->per_thread_scratch_size)
1802 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001803}
1804
Chia-I Wu625105f2014-10-13 15:35:29 +08001805static void emit_shader_resources(struct intel_cmd *cmd)
1806{
1807 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001808 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001809
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001810 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001811 cmd->bind.pipeline.graphics->vs.rmap,
1812 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001813 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001814 cmd->bind.pipeline.graphics->tcs.rmap,
1815 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001816 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001817 cmd->bind.pipeline.graphics->tes.rmap,
1818 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001819 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001820 cmd->bind.pipeline.graphics->gs.rmap,
1821 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001822 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001823 cmd->bind.pipeline.graphics->fs.rmap,
1824 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001825
1826 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1827 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1828 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1829 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1830 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1831
1832 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1833 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001834 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1835 binding_tables[0]);
1836 gen7_3dstate_pointer(cmd,
1837 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1838 binding_tables[1]);
1839 gen7_3dstate_pointer(cmd,
1840 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1841 binding_tables[2]);
1842 gen7_3dstate_pointer(cmd,
1843 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1844 binding_tables[3]);
1845 gen7_3dstate_pointer(cmd,
1846 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1847 binding_tables[4]);
1848
1849 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001850 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1851 samplers[0]);
1852 gen7_3dstate_pointer(cmd,
1853 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1854 samplers[1]);
1855 gen7_3dstate_pointer(cmd,
1856 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1857 samplers[2]);
1858 gen7_3dstate_pointer(cmd,
1859 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1860 samplers[3]);
1861 gen7_3dstate_pointer(cmd,
1862 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1863 samplers[4]);
1864 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001865 assert(!binding_tables[1] && !binding_tables[2]);
1866 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1867 binding_tables[0], binding_tables[3], binding_tables[4]);
1868
Chia-I Wu625105f2014-10-13 15:35:29 +08001869 assert(!samplers[1] && !samplers[2]);
1870 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1871 samplers[0], samplers[3], samplers[4]);
1872 }
1873}
1874
Chia-I Wu8ada4242015-03-02 11:19:33 -07001875static void emit_msaa(struct intel_cmd *cmd)
1876{
1877 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1878
1879 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
1880 cmd->result = XGL_ERROR_UNKNOWN;
1881
1882 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1883 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1884}
1885
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001886static void emit_rt(struct intel_cmd *cmd)
1887{
1888 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001889 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1890 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001891}
1892
1893static void emit_ds(struct intel_cmd *cmd)
1894{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001895 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1896 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001897
1898 if (!ds) {
1899 /* all zeros */
1900 static const struct intel_ds_view null_ds;
1901 ds = &null_ds;
1902 }
1903
1904 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001905 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1906 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1907 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001908
1909 if (cmd_gen(cmd) >= INTEL_GEN(7))
1910 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1911 else
1912 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1913}
1914
Chia-I Wua57761b2014-10-14 14:27:44 +08001915static uint32_t emit_shader(struct intel_cmd *cmd,
1916 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917{
Chia-I Wua57761b2014-10-14 14:27:44 +08001918 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1919 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001920 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001921
Chia-I Wua57761b2014-10-14 14:27:44 +08001922 /* see if the shader is already in the cache */
1923 for (i = 0; i < cache->used; i++) {
1924 if (cache->entries[i].shader == (const void *) shader)
1925 return cache->entries[i].kernel_offset;
1926 }
1927
1928 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1929
1930 /* grow the cache if full */
1931 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001932 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001933 void *entries;
1934
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08001935 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Chia-I Wua57761b2014-10-14 14:27:44 +08001936 XGL_SYSTEM_ALLOC_INTERNAL);
1937 if (entries) {
1938 if (cache->entries) {
1939 memcpy(entries, cache->entries,
1940 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08001941 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08001942 }
1943
1944 cache->entries = entries;
1945 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001946 }
1947 }
1948
Chia-I Wua57761b2014-10-14 14:27:44 +08001949 /* add the shader to the cache */
1950 if (cache->used < cache->count) {
1951 cache->entries[cache->used].shader = (const void *) shader;
1952 cache->entries[cache->used].kernel_offset = offset;
1953 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001954 }
1955
Chia-I Wua57761b2014-10-14 14:27:44 +08001956 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001957}
1958
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001959static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001960{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001961 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001962
Chia-I Wu8370b402014-08-29 12:28:37 +08001963 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1964 cmd_wa_gen6_pre_depth_stall_write(cmd);
1965 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1966 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1967 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1968 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001969
1970 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001971 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001972 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001973
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001974 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001975 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001976 }
1977 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001978 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001979 }
1980 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001981 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1982 }
1983 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1984 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1985 }
1986 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1987 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001988 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001989
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001990 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1991 gen7_3DSTATE_GS(cmd);
1992 } else {
1993 gen6_3DSTATE_GS(cmd);
1994 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001995
Chia-I Wu8370b402014-08-29 12:28:37 +08001996 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1997 cmd_wa_gen7_post_command_cs_stall(cmd);
1998 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1999 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002000}
2001
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002002static void emit_bounded_states(struct intel_cmd *cmd)
2003{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002004 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002005
2006 emit_graphics_pipeline(cmd);
2007
2008 emit_rt(cmd);
2009 emit_ds(cmd);
2010
2011 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2012 gen7_cc_states(cmd);
2013 gen7_viewport_states(cmd);
2014
2015 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2016 &cmd->bind.pipeline.graphics->vs);
2017 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2018 &cmd->bind.pipeline.graphics->fs);
2019
2020 gen6_3DSTATE_CLIP(cmd);
2021 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002022 gen7_3DSTATE_WM(cmd);
2023 gen7_3DSTATE_PS(cmd);
2024 } else {
2025 gen6_cc_states(cmd);
2026 gen6_viewport_states(cmd);
2027
2028 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2029 &cmd->bind.pipeline.graphics->vs);
2030 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2031 &cmd->bind.pipeline.graphics->fs);
2032
2033 gen6_3DSTATE_CLIP(cmd);
2034 gen6_3DSTATE_SF(cmd);
2035 gen6_3DSTATE_WM(cmd);
2036 }
2037
2038 emit_shader_resources(cmd);
2039
2040 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002041
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002042 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2043 gen6_3DSTATE_VS(cmd);
2044}
2045
Tony Barbourfa6cac72015-01-16 14:27:35 -07002046static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002047 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002048{
2049 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2050 const uint8_t cmd_len = 3;
2051 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002052
2053 CMD_ASSERT(cmd, 6, 7.5);
2054
Tony Barbourfa6cac72015-01-16 14:27:35 -07002055 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002056 dw[0] = 0;
2057 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002058
2059 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2060 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2061 GEN6_COMPAREFUNCTION_NEVER << 27 |
2062 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2063 } else {
2064 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2065 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2066 }
Chia-I Wud850a392015-02-19 11:08:25 -07002067 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2068 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002069 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2070 (GEN6_STENCILOP_KEEP) << 25 |
2071 (GEN6_STENCILOP_KEEP) << 22 |
2072 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002073 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2074 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002075 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2076 (GEN6_STENCILOP_KEEP) << 9 |
2077 (GEN6_STENCILOP_KEEP) << 6 |
2078 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002079
Chia-I Wud850a392015-02-19 11:08:25 -07002080 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2081 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2082 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2083 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2084 dw[2] = 0;
2085 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002086
2087 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2088 cmd_align, cmd_len, dw);
2089}
2090
Chia-I Wu6032b892014-10-17 14:47:18 +08002091static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2092{
2093 const struct intel_cmd_meta *meta = cmd->bind.meta;
2094 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2095
2096 CMD_ASSERT(cmd, 6, 7.5);
2097
2098 blend_offset = 0;
2099 ds_offset = 0;
2100 cc_offset = 0;
2101 cc_vp_offset = 0;
2102
Chia-I Wu29e6f502014-11-24 14:27:29 +08002103 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002104 /* BLEND_STATE */
2105 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002106 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002107 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002108 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002109 }
2110
Chia-I Wu29e6f502014-11-24 14:27:29 +08002111 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002112 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002113 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002114 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2115 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002116
Chia-I Wu29e6f502014-11-24 14:27:29 +08002117 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002118 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002119
Chia-I Wu29e6f502014-11-24 14:27:29 +08002120 /* COLOR_CALC_STATE */
2121 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002122 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002123
Chia-I Wu29e6f502014-11-24 14:27:29 +08002124 /* CC_VIEWPORT */
2125 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002126 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002127 dw[0] = u_fui(0.0f);
2128 dw[1] = u_fui(1.0f);
2129 } else {
2130 /* DEPTH_STENCIL_STATE */
2131 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002132 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002133 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2134 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2135 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002136 }
2137
2138 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2139 gen7_3dstate_pointer(cmd,
2140 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2141 blend_offset);
2142 gen7_3dstate_pointer(cmd,
2143 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2144 ds_offset);
2145 gen7_3dstate_pointer(cmd,
2146 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2147
2148 gen7_3dstate_pointer(cmd,
2149 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2150 cc_vp_offset);
2151 } else {
2152 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002153 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002154
2155 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2156 cmd_batch_pointer(cmd, 4, &dw);
2157 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002158 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002159 dw[1] = 0;
2160 dw[2] = 0;
2161 dw[3] = cc_vp_offset;
2162 }
2163}
2164
2165static void gen6_meta_surface_states(struct intel_cmd *cmd)
2166{
2167 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002168 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002170 const uint32_t sba_offset =
2171 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002172
2173 CMD_ASSERT(cmd, 6, 7.5);
2174
Chia-I Wu29e6f502014-11-24 14:27:29 +08002175 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2176 return;
2177
Chia-I Wu005c47c2014-10-22 13:49:13 +08002178 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002179 if (meta->src.valid) {
2180 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002181 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002182 meta->src.surface_len, meta->src.surface);
2183
2184 cmd_reserve_reloc(cmd, 1);
2185 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2186 cmd_surface_reloc_writer(cmd, offset, 1,
2187 meta->src.reloc_target, meta->src.reloc_offset);
2188 } else {
2189 cmd_surface_reloc(cmd, offset, 1,
2190 (struct intel_bo *) meta->src.reloc_target,
2191 meta->src.reloc_offset, meta->src.reloc_flags);
2192 }
2193
Mike Stroyan9bfad482015-02-10 15:09:23 -07002194 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002195 }
2196 if (meta->dst.valid) {
2197 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002198 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002199 meta->dst.surface_len, meta->dst.surface);
2200
2201 cmd_reserve_reloc(cmd, 1);
2202 cmd_surface_reloc(cmd, offset, 1,
2203 (struct intel_bo *) meta->dst.reloc_target,
2204 meta->dst.reloc_offset, meta->dst.reloc_flags);
2205
Mike Stroyan9bfad482015-02-10 15:09:23 -07002206 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002207 }
2208
2209 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002210 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002211 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002212 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002213
2214 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002215 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2216 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2217 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002218 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002219 } else {
2220 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002221 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002222 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002223 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002224 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002225 }
2226}
2227
2228static void gen6_meta_urb(struct intel_cmd *cmd)
2229{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002230 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002231 uint32_t *dw;
2232
2233 CMD_ASSERT(cmd, 6, 6);
2234
2235 /* 3DSTATE_URB */
2236 cmd_batch_pointer(cmd, 3, &dw);
2237 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002238 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002239 dw[2] = 0;
2240}
2241
2242static void gen7_meta_urb(struct intel_cmd *cmd)
2243{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002244 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2245 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002246 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002247 uint32_t *dw;
2248
2249 CMD_ASSERT(cmd, 7, 7.5);
2250
2251 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2252 cmd_batch_pointer(cmd, 10, &dw);
2253
2254 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002255 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
Chia-I Wu15dacac2015-02-05 11:14:01 -07002256 dw += 2;
2257
2258 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002259 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
2260 pcb_alloc << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002261 dw += 2;
2262
2263 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2264 dw[1] = 0;
2265 dw += 2;
2266
2267 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2268 dw[1] = 0;
2269 dw += 2;
2270
2271 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2272 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002273
Chia-I Wu15dacac2015-02-05 11:14:01 -07002274 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002275
2276 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2277
Chia-I Wu24aa1022014-11-25 11:53:19 +08002278 switch (cmd_gen(cmd)) {
2279 case INTEL_GEN(7.5):
2280 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2281 break;
2282 case INTEL_GEN(7):
2283 default:
2284 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2285 break;
2286 }
2287
Chia-I Wu6032b892014-10-17 14:47:18 +08002288 /* 3DSTATE_URB_x */
2289 cmd_batch_pointer(cmd, 8, &dw);
2290
2291 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002292 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002293 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002294 dw += 2;
2295
2296 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002297 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002298 dw += 2;
2299
2300 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002301 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002302 dw += 2;
2303
2304 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002305 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002306 dw += 2;
2307}
2308
2309static void gen6_meta_vf(struct intel_cmd *cmd)
2310{
2311 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002312 uint32_t vb_start, vb_end, vb_stride;
2313 int ve_format, ve_z_source;
2314 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002315 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002316
2317 CMD_ASSERT(cmd, 6, 7.5);
2318
Chia-I Wu29e6f502014-11-24 14:27:29 +08002319 switch (meta->mode) {
2320 case INTEL_CMD_META_VS_POINTS:
2321 cmd_batch_pointer(cmd, 3, &dw);
2322 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002323 dw[1] = GEN6_VE_DW0_VALID;
2324 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2325 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2326 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2327 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002328 return;
2329 break;
2330 case INTEL_CMD_META_FS_RECT:
2331 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002332 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333
Chia-I Wu29e6f502014-11-24 14:27:29 +08002334 vertices[0][0] = meta->dst.x + meta->width;
2335 vertices[0][1] = meta->dst.y + meta->height;
2336 vertices[1][0] = meta->dst.x;
2337 vertices[1][1] = meta->dst.y + meta->height;
2338 vertices[2][0] = meta->dst.x;
2339 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002340
Chia-I Wu29e6f502014-11-24 14:27:29 +08002341 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2342 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002343
Chia-I Wu29e6f502014-11-24 14:27:29 +08002344 vb_end = vb_start + sizeof(vertices) - 1;
2345 vb_stride = sizeof(vertices[0]);
2346 ve_z_source = GEN6_VFCOMP_STORE_0;
2347 ve_format = GEN6_FORMAT_R32G32_USCALED;
2348 }
2349 break;
2350 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2351 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002352 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002353
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002354 vertices[0][0] = (float) (meta->dst.x + meta->width);
2355 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002356 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002357 vertices[1][0] = (float) meta->dst.x;
2358 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002359 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002360 vertices[2][0] = (float) meta->dst.x;
2361 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002362 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002363
Chia-I Wu29e6f502014-11-24 14:27:29 +08002364 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2365 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002366
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367 vb_end = vb_start + sizeof(vertices) - 1;
2368 vb_stride = sizeof(vertices[0]);
2369 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2370 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2371 }
2372 break;
2373 default:
2374 assert(!"unknown meta mode");
2375 return;
2376 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002377 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002378
2379 /* 3DSTATE_VERTEX_BUFFERS */
2380 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002381
Chia-I Wu6032b892014-10-17 14:47:18 +08002382 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002383 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002384 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002385 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002386
2387 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002388 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2389 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002390
2391 dw[4] = 0;
2392
2393 /* 3DSTATE_VERTEX_ELEMENTS */
2394 cmd_batch_pointer(cmd, 5, &dw);
2395 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002396 dw[1] = GEN6_VE_DW0_VALID;
2397 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2398 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2399 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2400 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2401 dw[3] = GEN6_VE_DW0_VALID |
2402 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2403 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2404 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2405 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2406 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002407}
2408
Chia-I Wu29e6f502014-11-24 14:27:29 +08002409static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002410{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002411 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002412 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002413 uint32_t consts[8];
2414 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002415
2416 CMD_ASSERT(cmd, 6, 7.5);
2417
2418 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002419 case INTEL_DEV_META_VS_FILL_MEM:
2420 consts[0] = meta->dst.x;
2421 consts[1] = meta->clear_val[0];
2422 const_count = 2;
2423 break;
2424 case INTEL_DEV_META_VS_COPY_MEM:
2425 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2426 consts[0] = meta->dst.x;
2427 consts[1] = meta->src.x;
2428 const_count = 2;
2429 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002430 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2431 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2432 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2433 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2434 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2435 consts[0] = meta->src.x;
2436 consts[1] = meta->src.y;
2437 consts[2] = meta->width;
2438 consts[3] = meta->dst.x;
2439 const_count = 4;
2440 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002441 default:
2442 assert(!"unknown meta shader id");
2443 const_count = 0;
2444 break;
2445 }
2446
2447 /* this can be skipped but it makes state dumping prettier */
2448 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2449
2450 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2451}
2452
2453static void gen6_meta_vs(struct intel_cmd *cmd)
2454{
2455 const struct intel_cmd_meta *meta = cmd->bind.meta;
2456 const struct intel_pipeline_shader *sh =
2457 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2458 uint32_t offset, *dw;
2459
2460 CMD_ASSERT(cmd, 6, 7.5);
2461
2462 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002463 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002464
2465 /* 3DSTATE_CONSTANT_VS */
2466 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2467 cmd_batch_pointer(cmd, cmd_len, &dw);
2468 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2469 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2470
2471 /* 3DSTATE_VS */
2472 cmd_batch_pointer(cmd, 6, &dw);
2473 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2474 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2475
2476 return;
2477 }
2478
2479 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2480
2481 /* 3DSTATE_CONSTANT_VS */
2482 offset = gen6_meta_vs_constants(cmd);
2483 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2484 cmd_batch_pointer(cmd, 7, &dw);
2485 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002486 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002487 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002488 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002489 dw[4] = 0;
2490 dw[5] = 0;
2491 dw[6] = 0;
2492 } else {
2493 cmd_batch_pointer(cmd, 5, &dw);
2494 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002495 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002496 dw[1] = offset;
2497 dw[2] = 0;
2498 dw[3] = 0;
2499 dw[4] = 0;
2500 }
2501
2502 /* 3DSTATE_VS */
2503 offset = emit_shader(cmd, sh);
2504 cmd_batch_pointer(cmd, 6, &dw);
2505 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2506 dw[1] = offset;
2507 dw[2] = GEN6_THREADDISP_SPF |
2508 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2509 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002510 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002511 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2512 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2513
2514 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2515 GEN6_VS_DW5_VS_ENABLE;
2516 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002517 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002518 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002519 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002520
2521 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002522}
2523
2524static void gen6_meta_disabled(struct intel_cmd *cmd)
2525{
Chia-I Wu6032b892014-10-17 14:47:18 +08002526 uint32_t *dw;
2527
2528 CMD_ASSERT(cmd, 6, 6);
2529
Chia-I Wu6032b892014-10-17 14:47:18 +08002530 /* 3DSTATE_CONSTANT_GS */
2531 cmd_batch_pointer(cmd, 5, &dw);
2532 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2533 dw[1] = 0;
2534 dw[2] = 0;
2535 dw[3] = 0;
2536 dw[4] = 0;
2537
2538 /* 3DSTATE_GS */
2539 cmd_batch_pointer(cmd, 7, &dw);
2540 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2541 dw[1] = 0;
2542 dw[2] = 0;
2543 dw[3] = 0;
2544 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2545 dw[5] = GEN6_GS_DW5_STATISTICS;
2546 dw[6] = 0;
2547
Chia-I Wu6032b892014-10-17 14:47:18 +08002548 /* 3DSTATE_SF */
2549 cmd_batch_pointer(cmd, 20, &dw);
2550 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2551 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2552 memset(&dw[2], 0, 18 * sizeof(*dw));
2553}
2554
2555static void gen7_meta_disabled(struct intel_cmd *cmd)
2556{
2557 uint32_t *dw;
2558
2559 CMD_ASSERT(cmd, 7, 7.5);
2560
Chia-I Wu6032b892014-10-17 14:47:18 +08002561 /* 3DSTATE_CONSTANT_HS */
2562 cmd_batch_pointer(cmd, 7, &dw);
2563 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2564 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2565
2566 /* 3DSTATE_HS */
2567 cmd_batch_pointer(cmd, 7, &dw);
2568 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2569 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2570
2571 /* 3DSTATE_TE */
2572 cmd_batch_pointer(cmd, 4, &dw);
2573 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2574 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2575
2576 /* 3DSTATE_CONSTANT_DS */
2577 cmd_batch_pointer(cmd, 7, &dw);
2578 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2579 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2580
2581 /* 3DSTATE_DS */
2582 cmd_batch_pointer(cmd, 6, &dw);
2583 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2584 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2585
2586 /* 3DSTATE_CONSTANT_GS */
2587 cmd_batch_pointer(cmd, 7, &dw);
2588 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2589 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2590
2591 /* 3DSTATE_GS */
2592 cmd_batch_pointer(cmd, 7, &dw);
2593 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2594 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2595
2596 /* 3DSTATE_STREAMOUT */
2597 cmd_batch_pointer(cmd, 3, &dw);
2598 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2599 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2600
Chia-I Wu6032b892014-10-17 14:47:18 +08002601 /* 3DSTATE_SF */
2602 cmd_batch_pointer(cmd, 7, &dw);
2603 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2604 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2605
2606 /* 3DSTATE_SBE */
2607 cmd_batch_pointer(cmd, 14, &dw);
2608 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2609 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2610 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002611}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002612
Chia-I Wu29e6f502014-11-24 14:27:29 +08002613static void gen6_meta_clip(struct intel_cmd *cmd)
2614{
2615 const struct intel_cmd_meta *meta = cmd->bind.meta;
2616 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002617
Chia-I Wu29e6f502014-11-24 14:27:29 +08002618 /* 3DSTATE_CLIP */
2619 cmd_batch_pointer(cmd, 4, &dw);
2620 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2621 dw[1] = 0;
2622 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2623 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2624 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2625 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002626 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002627 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002628 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002629}
2630
2631static void gen6_meta_wm(struct intel_cmd *cmd)
2632{
2633 const struct intel_cmd_meta *meta = cmd->bind.meta;
2634 uint32_t *dw;
2635
2636 CMD_ASSERT(cmd, 6, 7.5);
2637
2638 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2639
2640 /* 3DSTATE_MULTISAMPLE */
2641 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2642 cmd_batch_pointer(cmd, 4, &dw);
2643 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2644 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2645 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2646 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2647 dw[2] = 0;
2648 dw[3] = 0;
2649 } else {
2650 cmd_batch_pointer(cmd, 3, &dw);
2651 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2652 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2653 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2654 dw[2] = 0;
2655 }
2656
2657 /* 3DSTATE_SAMPLE_MASK */
2658 cmd_batch_pointer(cmd, 2, &dw);
2659 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2660 dw[1] = (1 << meta->samples) - 1;
2661
2662 /* 3DSTATE_DRAWING_RECTANGLE */
2663 cmd_batch_pointer(cmd, 4, &dw);
2664 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002665 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2666 /* unused */
2667 dw[1] = 0;
2668 dw[2] = 0;
2669 } else {
2670 dw[1] = meta->dst.y << 16 | meta->dst.x;
2671 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2672 (meta->dst.x + meta->width - 1);
2673 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002674 dw[3] = 0;
2675}
2676
2677static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2678{
2679 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002680 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002681 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002682 uint32_t consts[8];
2683 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002684
2685 CMD_ASSERT(cmd, 6, 7.5);
2686
2687 /* underflow is fine here */
2688 offset_x = meta->src.x - meta->dst.x;
2689 offset_y = meta->src.y - meta->dst.y;
2690
2691 switch (meta->shader_id) {
2692 case INTEL_DEV_META_FS_COPY_MEM:
2693 case INTEL_DEV_META_FS_COPY_1D:
2694 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2695 case INTEL_DEV_META_FS_COPY_2D:
2696 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2697 case INTEL_DEV_META_FS_COPY_2D_MS:
2698 consts[0] = offset_x;
2699 consts[1] = offset_y;
2700 consts[2] = meta->src.layer;
2701 consts[3] = meta->src.lod;
2702 const_count = 4;
2703 break;
2704 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2705 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2706 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2707 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2708 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2709 consts[0] = offset_x;
2710 consts[1] = offset_y;
2711 consts[2] = meta->src.layer;
2712 consts[3] = meta->src.lod;
2713 consts[4] = meta->src.x;
2714 consts[5] = meta->width;
2715 const_count = 6;
2716 break;
2717 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2718 consts[0] = offset_x;
2719 consts[1] = offset_y;
2720 consts[2] = meta->width;
2721 const_count = 3;
2722 break;
2723 case INTEL_DEV_META_FS_CLEAR_COLOR:
2724 consts[0] = meta->clear_val[0];
2725 consts[1] = meta->clear_val[1];
2726 consts[2] = meta->clear_val[2];
2727 consts[3] = meta->clear_val[3];
2728 const_count = 4;
2729 break;
2730 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2731 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002732 consts[1] = meta->clear_val[1];
2733 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002734 break;
2735 case INTEL_DEV_META_FS_RESOLVE_2X:
2736 case INTEL_DEV_META_FS_RESOLVE_4X:
2737 case INTEL_DEV_META_FS_RESOLVE_8X:
2738 case INTEL_DEV_META_FS_RESOLVE_16X:
2739 consts[0] = offset_x;
2740 consts[1] = offset_y;
2741 const_count = 2;
2742 break;
2743 default:
2744 assert(!"unknown meta shader id");
2745 const_count = 0;
2746 break;
2747 }
2748
2749 /* this can be skipped but it makes state dumping prettier */
2750 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2751
2752 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2753}
2754
2755static void gen6_meta_ps(struct intel_cmd *cmd)
2756{
2757 const struct intel_cmd_meta *meta = cmd->bind.meta;
2758 const struct intel_pipeline_shader *sh =
2759 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2760 uint32_t offset, *dw;
2761
2762 CMD_ASSERT(cmd, 6, 6);
2763
Chia-I Wu29e6f502014-11-24 14:27:29 +08002764 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2765 /* 3DSTATE_CONSTANT_PS */
2766 cmd_batch_pointer(cmd, 5, &dw);
2767 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2768 dw[1] = 0;
2769 dw[2] = 0;
2770 dw[3] = 0;
2771 dw[4] = 0;
2772
2773 /* 3DSTATE_WM */
2774 cmd_batch_pointer(cmd, 9, &dw);
2775 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2776 dw[1] = 0;
2777 dw[2] = 0;
2778 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002779
2780 switch (meta->ds.op) {
2781 case INTEL_CMD_META_DS_HIZ_CLEAR:
2782 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2783 break;
2784 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2785 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2786 break;
2787 case INTEL_CMD_META_DS_RESOLVE:
2788 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2789 break;
2790 default:
2791 dw[4] = 0;
2792 break;
2793 }
2794
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002795 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002796 dw[6] = 0;
2797 dw[7] = 0;
2798 dw[8] = 0;
2799
Chia-I Wu3adf7212014-10-24 15:34:07 +08002800 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002801 }
2802
Chia-I Wu3adf7212014-10-24 15:34:07 +08002803 /* a normal color write */
2804 assert(meta->dst.valid && !sh->uses);
2805
Chia-I Wu6032b892014-10-17 14:47:18 +08002806 /* 3DSTATE_CONSTANT_PS */
2807 offset = gen6_meta_ps_constants(cmd);
2808 cmd_batch_pointer(cmd, 5, &dw);
2809 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002810 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002811 dw[1] = offset;
2812 dw[2] = 0;
2813 dw[3] = 0;
2814 dw[4] = 0;
2815
2816 /* 3DSTATE_WM */
2817 offset = emit_shader(cmd, sh);
2818 cmd_batch_pointer(cmd, 9, &dw);
2819 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2820 dw[1] = offset;
2821 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2822 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002823 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002824 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002825 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002826 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2827 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002828
Chia-I Wu6032b892014-10-17 14:47:18 +08002829 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002830 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002831 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2832 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2833 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2834 if (meta->samples > 1) {
2835 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2836 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2837 } else {
2838 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2839 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2840 }
2841 dw[7] = 0;
2842 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002843
2844 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002845}
2846
2847static void gen7_meta_ps(struct intel_cmd *cmd)
2848{
2849 const struct intel_cmd_meta *meta = cmd->bind.meta;
2850 const struct intel_pipeline_shader *sh =
2851 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2852 uint32_t offset, *dw;
2853
2854 CMD_ASSERT(cmd, 7, 7.5);
2855
Chia-I Wu29e6f502014-11-24 14:27:29 +08002856 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2857 /* 3DSTATE_WM */
2858 cmd_batch_pointer(cmd, 3, &dw);
2859 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002860
2861 switch (meta->ds.op) {
2862 case INTEL_CMD_META_DS_HIZ_CLEAR:
2863 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2864 break;
2865 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2866 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2867 break;
2868 case INTEL_CMD_META_DS_RESOLVE:
2869 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2870 break;
2871 default:
2872 dw[1] = 0;
2873 break;
2874 }
2875
2876 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002877
2878 /* 3DSTATE_CONSTANT_GS */
2879 cmd_batch_pointer(cmd, 7, &dw);
2880 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2881 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2882
2883 /* 3DSTATE_PS */
2884 cmd_batch_pointer(cmd, 8, &dw);
2885 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2886 dw[1] = 0;
2887 dw[2] = 0;
2888 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002889 /* required to avoid hangs */
2890 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002891 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002892 dw[5] = 0;
2893 dw[6] = 0;
2894 dw[7] = 0;
2895
Chia-I Wu3adf7212014-10-24 15:34:07 +08002896 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002897 }
2898
Chia-I Wu3adf7212014-10-24 15:34:07 +08002899 /* a normal color write */
2900 assert(meta->dst.valid && !sh->uses);
2901
Chia-I Wu6032b892014-10-17 14:47:18 +08002902 /* 3DSTATE_WM */
2903 cmd_batch_pointer(cmd, 3, &dw);
2904 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002905 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002906 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2907 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2908 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2909 dw[2] = 0;
2910
2911 /* 3DSTATE_CONSTANT_PS */
2912 offset = gen6_meta_ps_constants(cmd);
2913 cmd_batch_pointer(cmd, 7, &dw);
2914 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002915 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002916 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002917 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002918 dw[4] = 0;
2919 dw[5] = 0;
2920 dw[6] = 0;
2921
2922 /* 3DSTATE_PS */
2923 offset = emit_shader(cmd, sh);
2924 cmd_batch_pointer(cmd, 8, &dw);
2925 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2926 dw[1] = offset;
2927 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2928 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002929 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002930
2931 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2932 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002933 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002934
2935 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002936 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002937 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002938 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002939 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002940 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002941
2942 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2943 dw[6] = 0;
2944 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002945
2946 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002947}
2948
2949static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2950{
2951 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002952 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002953
2954 CMD_ASSERT(cmd, 6, 7.5);
2955
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002956 if (!ds) {
2957 /* all zeros */
2958 static const struct intel_ds_view null_ds;
2959 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002960 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002961
2962 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002963 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
2964 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
2965 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002966
2967 if (cmd_gen(cmd) >= INTEL_GEN(7))
2968 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2969 else
2970 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002971}
2972
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002973static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2974 const struct intel_pipeline *pipeline)
2975{
2976 cmd->bind.pipeline.graphics = pipeline;
2977}
2978
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002979static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2980 const struct intel_pipeline *pipeline)
2981{
2982 cmd->bind.pipeline.compute = pipeline;
2983}
2984
2985static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2986 const struct intel_pipeline_delta *delta)
2987{
2988 cmd->bind.pipeline.graphics_delta = delta;
2989}
2990
2991static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2992 const struct intel_pipeline_delta *delta)
2993{
2994 cmd->bind.pipeline.compute_delta = delta;
2995}
2996
2997static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002998 const struct intel_desc_set *dset,
2999 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003000{
Chia-I Wuf8385062015-01-04 16:27:24 +08003001 const uint32_t size = sizeof(*dynamic_offsets) *
3002 dset->layout->dynamic_desc_count;
3003
3004 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
3005 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003006 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003007
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003008 cmd->bind.dset.graphics_dynamic_offsets = intel_alloc(cmd,
3009 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003010 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003011 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003012 return;
3013 }
3014
3015 cmd->bind.dset.graphics_dynamic_offset_size = size;
3016 }
3017
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003018 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003019 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003020}
3021
3022static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003023 const struct intel_desc_set *dset,
3024 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003025{
Chia-I Wuf8385062015-01-04 16:27:24 +08003026 const uint32_t size = sizeof(*dynamic_offsets) *
3027 dset->layout->dynamic_desc_count;
3028
3029 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
3030 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003031 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003032
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003033 cmd->bind.dset.compute_dynamic_offsets = intel_alloc(cmd,
3034 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003035 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003036 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003037 return;
3038 }
3039
3040 cmd->bind.dset.compute_dynamic_offset_size = size;
3041 }
3042
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003043 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003044 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003045}
3046
Chia-I Wu3b04af52014-11-08 10:48:20 +08003047static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003048 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003049 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003050{
Chia-I Wu714df452015-01-01 07:55:04 +08003051 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003052 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003053 return;
3054 }
3055
Chia-I Wu714df452015-01-01 07:55:04 +08003056 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003057 cmd->bind.vertex.offset[binding] = offset;
3058}
3059
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003060static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003061 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003062 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3063{
Chia-I Wu714df452015-01-01 07:55:04 +08003064 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003065 cmd->bind.index.offset = offset;
3066 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003067}
3068
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003069static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003070 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003071{
3072 cmd->bind.state.viewport = state;
3073}
3074
3075static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003076 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003077{
3078 cmd->bind.state.raster = state;
3079}
3080
3081static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003082 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003083{
3084 cmd->bind.state.ds = state;
3085}
3086
3087static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003088 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003089{
3090 cmd->bind.state.blend = state;
3091}
3092
Chia-I Wuf98dd882015-02-10 04:17:47 +08003093static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3094{
3095 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3096 struct intel_pipeline_rmap *rmaps[5] = {
3097 pipeline->vs.rmap,
3098 pipeline->tcs.rmap,
3099 pipeline->tes.rmap,
3100 pipeline->gs.rmap,
3101 pipeline->fs.rmap,
3102 };
3103 uint32_t max_write;
3104 int i;
3105
3106 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3107 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3108 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3109
3110 /* pad first */
3111 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3112
3113 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3114 const struct intel_pipeline_rmap *rmap = rmaps[i];
3115 const uint32_t surface_count = (rmap) ?
3116 rmap->rt_count + rmap->texture_resource_count +
3117 rmap->resource_count + rmap->uav_count : 0;
3118
3119 if (surface_count) {
3120 /* SURFACE_STATEs */
3121 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3122
3123 /* BINDING_TABLE_STATE */
3124 max_write += u_align(sizeof(uint32_t) * surface_count,
3125 GEN6_ALIGNMENT_SURFACE_STATE);
3126 }
3127 }
3128
3129 return max_write;
3130}
3131
3132static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3133{
3134 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3135 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3136 uint32_t max_surface_write;
3137
3138 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3139 if (cmd->bind.meta)
3140 max_surface_write = 64 * sizeof(uint32_t);
3141 else
3142 max_surface_write = cmd_get_max_surface_write(cmd);
3143
3144 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3145 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3146 /* SBA expects page-aligned addresses */
3147 writer->sba_offset = writer->used & ~0xfff;
3148
3149 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3150
3151 cmd_batch_state_base_address(cmd);
3152 }
3153}
3154
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003155static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003156 uint32_t vertex_start,
3157 uint32_t vertex_count,
3158 uint32_t instance_start,
3159 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003160 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003161 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003162{
3163 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003164 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003165 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3166
3167 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003168
3169 emit_bounded_states(cmd);
3170
Chia-I Wuf98dd882015-02-10 04:17:47 +08003171 /* sanity check on cmd_get_max_surface_write() */
3172 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3173 surface_writer_used <= cmd_get_max_surface_write(cmd));
3174
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003175 if (indexed) {
3176 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003177 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003178
3179 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3180 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3181 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003182 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003183 cmd->bind.index.offset, cmd->bind.index.type,
3184 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003186 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003187 cmd->bind.index.offset, cmd->bind.index.type,
3188 p->primitive_restart);
3189 }
3190 } else {
3191 assert(!vertex_base);
3192 }
3193
3194 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3195 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3196 vertex_start, instance_count, instance_start, vertex_base);
3197 } else {
3198 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3199 vertex_start, instance_count, instance_start, vertex_base);
3200 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003201
Chia-I Wu707a29e2014-08-27 12:51:47 +08003202 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003203 /* need to re-emit all workarounds */
3204 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003205
3206 if (intel_debug & INTEL_DEBUG_NOCACHE)
3207 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208}
3209
Chia-I Wuc14d1562014-10-17 09:49:22 +08003210void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3211{
Chia-I Wu6032b892014-10-17 14:47:18 +08003212 cmd->bind.meta = meta;
3213
Chia-I Wuf98dd882015-02-10 04:17:47 +08003214 cmd_adjust_state_base_address(cmd);
3215
Chia-I Wu6032b892014-10-17 14:47:18 +08003216 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003217 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003218
3219 gen6_meta_dynamic_states(cmd);
3220 gen6_meta_surface_states(cmd);
3221
3222 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3223 gen7_meta_urb(cmd);
3224 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003225 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003226 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003227 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003228 gen6_meta_wm(cmd);
3229 gen7_meta_ps(cmd);
3230 gen6_meta_depth_buffer(cmd);
3231
3232 cmd_wa_gen7_post_command_cs_stall(cmd);
3233 cmd_wa_gen7_post_command_depth_stall(cmd);
3234
Chia-I Wu29e6f502014-11-24 14:27:29 +08003235 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3236 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003237 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003238 } else {
3239 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3240 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003241 } else {
3242 gen6_meta_urb(cmd);
3243 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003244 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003245 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003246 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003247 gen6_meta_wm(cmd);
3248 gen6_meta_ps(cmd);
3249 gen6_meta_depth_buffer(cmd);
3250
Chia-I Wu29e6f502014-11-24 14:27:29 +08003251 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3252 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003253 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003254 } else {
3255 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3256 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003257 }
3258
3259 cmd->bind.draw_count++;
3260 /* need to re-emit all workarounds */
3261 cmd->bind.wa_flags = 0;
3262
3263 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003264
3265 if (intel_debug & INTEL_DEBUG_NOCACHE)
3266 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003267}
3268
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003269ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003270 XGL_CMD_BUFFER cmdBuffer,
3271 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3272 XGL_PIPELINE pipeline)
3273{
3274 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3275
3276 switch (pipelineBindPoint) {
3277 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003278 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003279 break;
3280 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003281 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003282 break;
3283 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003284 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003285 break;
3286 }
3287}
3288
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003289ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003290 XGL_CMD_BUFFER cmdBuffer,
3291 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3292 XGL_PIPELINE_DELTA delta)
3293{
3294 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3295
3296 switch (pipelineBindPoint) {
3297 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003298 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003299 break;
3300 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003301 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003302 break;
3303 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003304 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003305 break;
3306 }
3307}
3308
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003309ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003310 XGL_CMD_BUFFER cmdBuffer,
3311 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003312 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003313{
3314 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3315
3316 switch (stateBindPoint) {
3317 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003318 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003319 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003320 break;
3321 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003322 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003323 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003324 break;
3325 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003326 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003327 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003328 break;
3329 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003330 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003331 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003332 break;
3333 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003334 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003335 break;
3336 }
3337}
3338
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003339ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003340 XGL_CMD_BUFFER cmdBuffer,
3341 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003342 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003343 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003344{
3345 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003346 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003347
3348 switch (pipelineBindPoint) {
3349 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003350 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003351 break;
3352 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003353 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003354 break;
3355 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003356 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003357 break;
3358 }
3359}
3360
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003361ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003362 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003363 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003364 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003365 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003366{
3367 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003368 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003369
Chia-I Wu714df452015-01-01 07:55:04 +08003370 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003371}
3372
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003373ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003374 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003375 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003376 XGL_GPU_SIZE offset,
3377 XGL_INDEX_TYPE indexType)
3378{
3379 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003380 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003381
Chia-I Wu714df452015-01-01 07:55:04 +08003382 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003383}
3384
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003385ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003386 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003387 uint32_t firstVertex,
3388 uint32_t vertexCount,
3389 uint32_t firstInstance,
3390 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003391{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003392 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003393
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003394 cmd_draw(cmd, firstVertex, vertexCount,
3395 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003396}
3397
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003398ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003399 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003400 uint32_t firstIndex,
3401 uint32_t indexCount,
3402 int32_t vertexOffset,
3403 uint32_t firstInstance,
3404 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003405{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003406 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003407
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003408 cmd_draw(cmd, firstIndex, indexCount,
3409 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003410}
3411
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003412ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003413 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003414 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003415 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003416 uint32_t count,
3417 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003418{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003419 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3420
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003421 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003422}
3423
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003424ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003425 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003426 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003427 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003428 uint32_t count,
3429 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003430{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003431 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3432
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003433 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003434}
3435
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003436ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003437 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003438 uint32_t x,
3439 uint32_t y,
3440 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003441{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003442 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3443
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003444 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003445}
3446
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003447ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003448 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003449 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003450 XGL_GPU_SIZE offset)
3451{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003452 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3453
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003454 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003455}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003456
Chia-I Wude26bdf2015-02-18 15:47:12 -07003457ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003458 XGL_CMD_BUFFER cmdBuffer,
3459 XGL_RENDER_PASS renderPass)
3460{
3461 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3462
3463 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3464}
3465
Chia-I Wude26bdf2015-02-18 15:47:12 -07003466ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003467 XGL_CMD_BUFFER cmdBuffer,
3468 XGL_RENDER_PASS renderPass)
3469{
3470 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3471
3472 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3473}