blob: 2859a0a21c026c060777e931d9d0527635911b88 [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:
273 cmd->result = XGL_ERROR_INVALID_VALUE;
274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
279 cmd->result = XGL_ERROR_INVALID_VALUE;
280 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
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 if (pipeline->scissor_enable)
Chia-I Wu8016a172014-08-29 18:31:32 +0800422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* 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
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600446 uint32_t sbe_offset;
447 int32_t i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
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, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700501 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800502 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503
504 CMD_ASSERT(cmd, 6, 7.5);
505
506 dw1 = GEN6_CLIP_DW1_STATISTICS;
507 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
508 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
509 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 }
512
513 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
514 GEN6_CLIP_DW2_XY_TEST_ENABLE |
515 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700516 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800517 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
518 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
520
521 if (pipeline->rasterizerDiscardEnable)
522 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
523 else
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
525
526 if (pipeline->depthClipEnable)
527 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
528
529 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
530 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
531 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
532 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
533
534 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
535 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
536 (viewport->viewport_count - 1);
537
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600538 /* TODO: framebuffer requests layer_count > 1 */
539 if (cmd->bind.render_pass->fb->layer_count == 1) {
540 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
541 }
542
Chia-I Wu72292b72014-09-09 10:48:33 +0800543 cmd_batch_pointer(cmd, cmd_len, &dw);
544 dw[0] = dw0;
545 dw[1] = dw1;
546 dw[2] = dw2;
547 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800548}
549
Chia-I Wu784d3042014-12-19 14:30:04 +0800550static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600551 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800552 const struct intel_pipeline *pipeline,
553 const struct intel_pipeline_shader *sh)
554{
555 int scratch_space;
556
557 CMD_ASSERT(cmd, 6, 7.5);
558
559 assert(sh->per_thread_scratch_size &&
560 sh->per_thread_scratch_size % 1024 == 0 &&
561 u_is_pow2(sh->per_thread_scratch_size) &&
562 sh->scratch_offset % 1024 == 0);
563 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
564
565 cmd_reserve_reloc(cmd, 1);
566 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
567 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
568}
569
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800570static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
571{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800573 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600575 uint32_t pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800576 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800577
578 CMD_ASSERT(cmd, 6, 6);
579
580 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
581
582 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
583 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
584
585 dw4 = GEN6_WM_DW4_STATISTICS |
586 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
587 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
588 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
589
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800590 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800591 GEN6_WM_DW5_PS_ENABLE |
592 GEN6_WM_DW5_8_PIXEL_DISPATCH;
593
594 if (fs->uses & INTEL_SHADER_USE_KILL ||
595 pipeline->cb_state.alphaToCoverageEnable)
596 dw5 |= GEN6_WM_DW5_PS_KILL;
597
Cody Northrope238deb2015-01-26 14:41:36 -0700598 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800599 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
600 if (fs->uses & INTEL_SHADER_USE_DEPTH)
601 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
602 if (fs->uses & INTEL_SHADER_USE_W)
603 dw5 |= GEN6_WM_DW5_PS_USE_W;
604
605 if (pipeline->cb_state.dualSourceBlendEnable)
606 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
607
608 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
609 GEN6_WM_DW6_POSOFFSET_NONE |
610 GEN6_WM_DW6_ZW_INTERP_PIXEL |
611 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
612 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
613
Tony Barbourfa6cac72015-01-16 14:27:35 -0700614 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800615 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
616 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
617 } else {
618 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
619 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
620 }
621
Chia-I Wu784d3042014-12-19 14:30:04 +0800622 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800623 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800624 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800625 dw[2] = dw2;
626 dw[3] = 0; /* scratch */
627 dw[4] = dw4;
628 dw[5] = dw5;
629 dw[6] = dw6;
630 dw[7] = 0; /* kernel 1 */
631 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800632
633 if (fs->per_thread_scratch_size)
634 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635}
636
637static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
638{
639 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800640 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800642 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643
644 CMD_ASSERT(cmd, 7, 7.5);
645
646 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
647
648 dw1 = GEN7_WM_DW1_STATISTICS |
649 GEN7_WM_DW1_PS_ENABLE |
650 GEN7_WM_DW1_ZW_INTERP_PIXEL |
651 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
652 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
653
654 if (fs->uses & INTEL_SHADER_USE_KILL ||
655 pipeline->cb_state.alphaToCoverageEnable)
656 dw1 |= GEN7_WM_DW1_PS_KILL;
657
Cody Northrope238deb2015-01-26 14:41:36 -0700658 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
659
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660 if (fs->uses & INTEL_SHADER_USE_DEPTH)
661 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
662 if (fs->uses & INTEL_SHADER_USE_W)
663 dw1 |= GEN7_WM_DW1_PS_USE_W;
664
665 dw2 = 0;
666
Tony Barbourfa6cac72015-01-16 14:27:35 -0700667 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
669 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
670 } else {
671 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
672 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
673 }
674
Chia-I Wu72292b72014-09-09 10:48:33 +0800675 cmd_batch_pointer(cmd, cmd_len, &dw);
676 dw[0] = dw0;
677 dw[1] = dw1;
678 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679}
680
681static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
682{
683 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800684 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 uint32_t dw0, dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600687 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688
689 CMD_ASSERT(cmd, 7, 7.5);
690
691 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
692
693 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
694 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
695
696 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
697 GEN7_PS_DW4_8_PIXEL_DISPATCH;
698
699 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800700 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700701 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800702 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800703 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 }
705
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706 if (fs->in_count)
707 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
708
709 if (pipeline->cb_state.dualSourceBlendEnable)
710 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
711
712 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
713 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
714 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
715
Chia-I Wu784d3042014-12-19 14:30:04 +0800716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800718 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800719 dw[2] = dw2;
720 dw[3] = 0; /* scratch */
721 dw[4] = dw4;
722 dw[5] = dw5;
723 dw[6] = 0; /* kernel 1 */
724 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800725
726 if (fs->per_thread_scratch_size)
727 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800728}
729
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800730static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
731 const struct intel_ds_view *view)
732{
733 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800734 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600735 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800736
737 CMD_ASSERT(cmd, 6, 7.5);
738
739 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800740 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
741 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800742 dw0 |= (cmd_len - 2);
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
746 dw[1] = view->cmd[0];
747 dw[2] = 0;
748 dw[3] = view->cmd[2];
749 dw[4] = view->cmd[3];
750 dw[5] = view->cmd[4];
751 dw[6] = view->cmd[5];
752
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600753 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800754 cmd_reserve_reloc(cmd, 1);
755 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
756 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600757 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800758}
759
760static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
761 const struct intel_ds_view *view)
762{
763 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800764 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600765 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766
767 CMD_ASSERT(cmd, 6, 7.5);
768
769 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800770 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
771 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800772 dw0 |= (cmd_len - 2);
773
Chia-I Wu72292b72014-09-09 10:48:33 +0800774 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
775 dw[0] = dw0;
776 dw[1] = view->cmd[6];
777 dw[2] = 0;
778
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600779 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600783 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784}
785
786static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
787 const struct intel_ds_view *view)
788{
789 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600791 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792
793 CMD_ASSERT(cmd, 6, 7.5);
794
795 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800796 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
797 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798 dw0 |= (cmd_len - 2);
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
801 dw[0] = dw0;
802 dw[1] = view->cmd[8];
803 dw[2] = 0;
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
Chia-I Wuf8231032014-08-25 10:44:45 +0800812static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
813 uint32_t clear_val)
814{
815 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800816 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800817 GEN6_CLEAR_PARAMS_DW0_VALID |
818 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800819 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800820
821 CMD_ASSERT(cmd, 6, 6);
822
Chia-I Wu72292b72014-09-09 10:48:33 +0800823 cmd_batch_pointer(cmd, cmd_len, &dw);
824 dw[0] = dw0;
825 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800826}
827
828static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
829 uint32_t clear_val)
830{
831 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800832 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800833 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800835
836 CMD_ASSERT(cmd, 7, 7.5);
837
Chia-I Wu72292b72014-09-09 10:48:33 +0800838 cmd_batch_pointer(cmd, cmd_len, &dw);
839 dw[0] = dw0;
840 dw[1] = clear_val;
841 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800842}
843
Chia-I Wu302742d2014-08-22 10:28:29 +0800844static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t blend_offset,
846 uint32_t ds_offset,
847 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800848{
849 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800851
852 CMD_ASSERT(cmd, 6, 6);
853
Chia-I Wu426072d2014-08-26 14:31:55 +0800854 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800855 (cmd_len - 2);
856
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 cmd_batch_pointer(cmd, cmd_len, &dw);
858 dw[0] = dw0;
859 dw[1] = blend_offset | 1;
860 dw[2] = ds_offset | 1;
861 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800862}
863
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t clip_offset,
866 uint32_t sf_offset,
867 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868{
869 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu426072d2014-08-26 14:31:55 +0800874 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875 GEN6_PTR_VP_DW0_CLIP_CHANGED |
876 GEN6_PTR_VP_DW0_SF_CHANGED |
877 GEN6_PTR_VP_DW0_CC_CHANGED |
878 (cmd_len - 2);
879
Chia-I Wu72292b72014-09-09 10:48:33 +0800880 cmd_batch_pointer(cmd, cmd_len, &dw);
881 dw[0] = dw0;
882 dw[1] = clip_offset;
883 dw[2] = sf_offset;
884 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885}
886
887static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889{
890 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892
893 CMD_ASSERT(cmd, 6, 6);
894
Chia-I Wu426072d2014-08-26 14:31:55 +0800895 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896 (cmd_len - 2);
897
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 cmd_batch_pointer(cmd, cmd_len, &dw);
899 dw[0] = dw0;
900 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800901}
902
Chia-I Wu42a56202014-08-23 16:47:48 +0800903static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t vs_offset,
905 uint32_t gs_offset,
906 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800907{
908 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800910
911 CMD_ASSERT(cmd, 6, 6);
912
Chia-I Wu426072d2014-08-26 14:31:55 +0800913 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800914 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
915 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
916 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
917 (cmd_len - 2);
918
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 cmd_batch_pointer(cmd, cmd_len, &dw);
920 dw[0] = dw0;
921 dw[1] = vs_offset;
922 dw[2] = gs_offset;
923 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800924}
925
Chia-I Wu257e75e2014-08-29 14:06:35 +0800926static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t vs_offset,
928 uint32_t gs_offset,
929 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930{
931 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800933
934 CMD_ASSERT(cmd, 6, 6);
935
936 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
937 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
938 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
939 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
940 (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] = vs_offset;
945 dw[2] = gs_offset;
946 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800947}
948
Chia-I Wu302742d2014-08-22 10:28:29 +0800949static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800951{
952 const uint8_t cmd_len = 2;
953 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
954 GEN6_RENDER_SUBTYPE_3D |
955 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 cmd_batch_pointer(cmd, cmd_len, &dw);
959 dw[0] = dw0;
960 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800961}
962
Chia-I Wua6c4f152014-12-02 04:19:58 +0800963static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800964{
Chia-I Wue6073342014-11-30 09:43:42 +0800965 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700966 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
967 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800968
969 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700970 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800971
Tony Barbourfa6cac72015-01-16 14:27:35 -0700972 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800973}
974
Chia-I Wu72292b72014-09-09 10:48:33 +0800975static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700976 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800977{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800979 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800980 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700981 uint32_t dw[3];
982
983 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700984 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700985 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700986 (state->ds_info.stencilWriteMask & 0xff) << 16 |
987 (state->ds_info.stencilReadMask & 0xff) << 8 |
988 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700989 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
991 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992
993 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
994 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800995
Chia-I Wu00b51a82014-09-09 12:07:37 +0800996 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700997 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800998}
999
Chia-I Wu72292b72014-09-09 10:48:33 +08001000static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001001 uint32_t stencil_ref,
1002 const uint32_t blend_color[4])
1003{
Chia-I Wue6073342014-11-30 09:43:42 +08001004 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001007
1008 CMD_ASSERT(cmd, 6, 7.5);
1009
Chia-I Wu00b51a82014-09-09 12:07:37 +08001010 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1011 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001012 dw[0] = stencil_ref;
1013 dw[1] = 0;
1014 dw[2] = blend_color[0];
1015 dw[3] = blend_color[1];
1016 dw[4] = blend_color[2];
1017 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001018
Chia-I Wu72292b72014-09-09 10:48:33 +08001019 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001020}
1021
Chia-I Wu8370b402014-08-29 12:28:37 +08001022static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001023{
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 CMD_ASSERT(cmd, 6, 7.5);
1025
Chia-I Wu707a29e2014-08-27 12:51:47 +08001026 if (!cmd->bind.draw_count)
1027 return;
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030 return;
1031
Chia-I Wu8370b402014-08-29 12:28:37 +08001032 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001033
1034 /*
1035 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1036 *
1037 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1038 * pipe-control with a post-sync op and no write-cache flushes."
1039 *
1040 * The workaround below necessitates this workaround.
1041 */
1042 gen6_PIPE_CONTROL(cmd,
1043 GEN6_PIPE_CONTROL_CS_STALL |
1044 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001045 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001046
Chia-I Wud6d079d2014-08-31 13:14:21 +08001047 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1048 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001049}
1050
Chia-I Wu8370b402014-08-29 12:28:37 +08001051static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001052{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053 CMD_ASSERT(cmd, 6, 7.5);
1054
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001055 if (!cmd->bind.draw_count)
1056 return;
1057
Chia-I Wud6d079d2014-08-31 13:14:21 +08001058 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1059 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001060}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001061
Chia-I Wu8370b402014-08-29 12:28:37 +08001062static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1063{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001064 CMD_ASSERT(cmd, 7, 7.5);
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066 if (!cmd->bind.draw_count)
1067 return;
1068
1069 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001070
1071 gen6_PIPE_CONTROL(cmd,
1072 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001073 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001074}
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1077{
1078 CMD_ASSERT(cmd, 7, 7.5);
1079
1080 if (!cmd->bind.draw_count)
1081 return;
1082
1083 /*
1084 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1085 *
1086 * "One of the following must also be set (when CS stall is set):
1087 *
1088 * * Render Target Cache Flush Enable ([12] of DW1)
1089 * * Depth Cache Flush Enable ([0] of DW1)
1090 * * Stall at Pixel Scoreboard ([1] of DW1)
1091 * * Depth Stall ([13] of DW1)
1092 * * Post-Sync Operation ([13] of DW1)"
1093 */
1094 gen6_PIPE_CONTROL(cmd,
1095 GEN6_PIPE_CONTROL_CS_STALL |
1096 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001097 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001098}
1099
1100static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1101{
1102 CMD_ASSERT(cmd, 7, 7.5);
1103
1104 if (!cmd->bind.draw_count)
1105 return;
1106
1107 cmd_wa_gen6_pre_depth_stall_write(cmd);
1108
Chia-I Wud6d079d2014-08-31 13:14:21 +08001109 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001110}
1111
1112static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1113{
1114 CMD_ASSERT(cmd, 6, 7.5);
1115
1116 if (!cmd->bind.draw_count)
1117 return;
1118
1119 /*
1120 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1121 *
1122 * "Driver must guarentee that all the caches in the depth pipe are
1123 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1124 * requires driver to send a PIPE_CONTROL with a CS stall along with
1125 * a Depth Flush prior to this command."
1126 *
1127 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1128 *
1129 * "Driver must ierarchi that all the caches in the depth pipe are
1130 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1131 * requires driver to send a PIPE_CONTROL with a CS stall along with
1132 * a Depth Flush prior to this command.
1133 */
1134 gen6_PIPE_CONTROL(cmd,
1135 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1136 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001137 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001138}
1139
1140static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1141{
1142 CMD_ASSERT(cmd, 6, 7.5);
1143
1144 if (!cmd->bind.draw_count)
1145 return;
1146
1147 /*
1148 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1149 *
1150 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1151 * and a post sync operation prior to the group of depth
1152 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1153 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1154 *
1155 * This workaround satifies all the conditions.
1156 */
1157 cmd_wa_gen6_pre_depth_stall_write(cmd);
1158
1159 /*
1160 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1161 *
1162 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1163 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1164 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1165 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1166 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1167 * Depth Flush Bit set, followed by another pipelined depth stall
1168 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1169 * guarantee that the pipeline from WM onwards is already flushed
1170 * (e.g., via a preceding MI_FLUSH)."
1171 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001172 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1173 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1174 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001175}
1176
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001177void cmd_batch_state_base_address(struct intel_cmd *cmd)
1178{
1179 const uint8_t cmd_len = 10;
1180 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1181 (cmd_len - 2);
1182 uint32_t pos;
1183 uint32_t *dw;
1184
1185 CMD_ASSERT(cmd, 6, 7.5);
1186
1187 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1188
1189 dw[0] = dw0;
1190 /* start offsets */
1191 dw[1] = 1;
1192 dw[2] = 1;
1193 dw[3] = 1;
1194 dw[4] = 1;
1195 dw[5] = 1;
1196 /* end offsets */
1197 dw[6] = 1;
1198 dw[7] = 1 + 0xfffff000;
1199 dw[8] = 1 + 0xfffff000;
1200 dw[9] = 1;
1201
1202 cmd_reserve_reloc(cmd, 3);
1203 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, 1);
1204 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, 1);
1205 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION, 1);
1206}
1207
Chia-I Wu525c6602014-08-27 10:22:34 +08001208void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1209{
1210 if (!cmd->bind.draw_count)
1211 return;
1212
1213 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1214
Chia-I Wu8370b402014-08-29 12:28:37 +08001215 /*
1216 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1217 *
1218 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1219 * PIPE_CONTROL with any non-zero post-sync-op is required."
1220 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001221 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001222 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001223
Chia-I Wu092279a2014-08-30 19:05:30 +08001224 /*
1225 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1226 *
1227 * "One of the following must also be set (when CS stall is set):
1228 *
1229 * * Render Target Cache Flush Enable ([12] of DW1)
1230 * * Depth Cache Flush Enable ([0] of DW1)
1231 * * Stall at Pixel Scoreboard ([1] of DW1)
1232 * * Depth Stall ([13] of DW1)
1233 * * Post-Sync Operation ([13] of DW1)"
1234 */
1235 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1236 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1237 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1238 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1239 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1240 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1241
Chia-I Wud6d079d2014-08-31 13:14:21 +08001242 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001243}
1244
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001245void cmd_batch_flush_all(struct intel_cmd *cmd)
1246{
1247 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1248 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1249 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1250 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1251 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1252 GEN6_PIPE_CONTROL_CS_STALL);
1253}
1254
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001255void cmd_batch_depth_count(struct intel_cmd *cmd,
1256 struct intel_bo *bo,
1257 XGL_GPU_SIZE offset)
1258{
1259 cmd_wa_gen6_pre_depth_stall_write(cmd);
1260
1261 gen6_PIPE_CONTROL(cmd,
1262 GEN6_PIPE_CONTROL_DEPTH_STALL |
1263 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001264 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001265}
1266
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001267void cmd_batch_timestamp(struct intel_cmd *cmd,
1268 struct intel_bo *bo,
1269 XGL_GPU_SIZE offset)
1270{
1271 /* need any WA or stall? */
1272 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1273}
1274
1275void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001276 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001277 struct intel_bo *bo,
1278 XGL_GPU_SIZE offset,
1279 uint64_t val)
1280{
1281 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001282 gen6_PIPE_CONTROL(cmd,
1283 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1284 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001285}
1286
Chia-I Wu302742d2014-08-22 10:28:29 +08001287static void gen6_cc_states(struct intel_cmd *cmd)
1288{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001289 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1290 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001291 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001292 uint32_t stencil_ref;
1293 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001294
1295 CMD_ASSERT(cmd, 6, 6);
1296
Chia-I Wua6c4f152014-12-02 04:19:58 +08001297 blend_offset = gen6_BLEND_STATE(cmd);
1298
1299 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001300 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001301 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001302 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001303
1304 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001305 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001306 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1307 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001308 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001309 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001310 stencil_ref = 0;
1311 }
1312
Chia-I Wu72292b72014-09-09 10:48:33 +08001313 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001314
Chia-I Wu72292b72014-09-09 10:48:33 +08001315 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001316}
1317
Chia-I Wu1744cca2014-08-22 11:10:17 +08001318static void gen6_viewport_states(struct intel_cmd *cmd)
1319{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001320 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001321 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001322
1323 if (!viewport)
1324 return;
1325
Tony Barbourfa6cac72015-01-16 14:27:35 -07001326 assert(viewport->cmd_len == (8 + 4 + 2) *
1327 viewport->viewport_count + (viewport->has_scissor_rects) ?
1328 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001329
1330 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001331 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332 viewport->cmd);
1333
1334 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001335 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001336 &viewport->cmd[viewport->cmd_clip_pos]);
1337
1338 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001339 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001340 &viewport->cmd[viewport->cmd_cc_pos]);
1341
Tony Barbourfa6cac72015-01-16 14:27:35 -07001342 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001343 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001344 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001345 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1346 } else {
1347 scissor_offset = 0;
1348 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001349
1350 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001351 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001352
Chia-I Wub1d450a2014-09-09 13:48:03 +08001353 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001354}
1355
Chia-I Wu302742d2014-08-22 10:28:29 +08001356static void gen7_cc_states(struct intel_cmd *cmd)
1357{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001358 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1359 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001360 uint32_t stencil_ref;
1361 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001362 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001363
1364 CMD_ASSERT(cmd, 7, 7.5);
1365
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 if (!blend && !ds)
1367 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001368
Chia-I Wua6c4f152014-12-02 04:19:58 +08001369 offset = gen6_BLEND_STATE(cmd);
1370 gen7_3dstate_pointer(cmd,
1371 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001372
Chia-I Wua6c4f152014-12-02 04:19:58 +08001373 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001374 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001375 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001376 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001377
1378 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001379 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001380 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1381 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001382 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001383 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1384 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001385 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1386 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001387 } else {
1388 stencil_ref = 0;
1389 }
1390
Chia-I Wu72292b72014-09-09 10:48:33 +08001391 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001392 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001393 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001394}
1395
Chia-I Wu1744cca2014-08-22 11:10:17 +08001396static void gen7_viewport_states(struct intel_cmd *cmd)
1397{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001398 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1399 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001400 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001401
1402 if (!viewport)
1403 return;
1404
Tony Barbourfa6cac72015-01-16 14:27:35 -07001405 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001406 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001407
Chia-I Wub1d450a2014-09-09 13:48:03 +08001408 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001409 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001411 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001412 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1413 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414
1415 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001416 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001418 gen7_3dstate_pointer(cmd,
1419 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001421
Tony Barbourfa6cac72015-01-16 14:27:35 -07001422 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001423 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001424 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001425 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001426 gen7_3dstate_pointer(cmd,
1427 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001428 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001429 }
1430}
1431
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001432static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001433 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001434{
1435 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001436 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001437
Chia-I Wu72292b72014-09-09 10:48:33 +08001438 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001439
1440 dw[0] = GEN6_RENDER_TYPE_RENDER |
1441 GEN6_RENDER_SUBTYPE_3D |
1442 subop | (cmd_len - 2);
1443 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001444 dw[2] = 0;
1445 dw[3] = 0;
1446 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001447}
1448
1449static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001450 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001451{
1452 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001453 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001454
Chia-I Wu72292b72014-09-09 10:48:33 +08001455 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001456
1457 dw[0] = GEN6_RENDER_TYPE_RENDER |
1458 GEN6_RENDER_SUBTYPE_3D |
1459 subop | (cmd_len - 2);
1460 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001461 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001462 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001463 dw[4] = 0;
1464 dw[5] = 0;
1465 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001466}
1467
Chia-I Wu625105f2014-10-13 15:35:29 +08001468static uint32_t emit_samplers(struct intel_cmd *cmd,
1469 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001470{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001471 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1472 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001473 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001474 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001475 uint32_t surface_count;
1476 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001477
1478 CMD_ASSERT(cmd, 6, 7.5);
1479
Chia-I Wu625105f2014-10-13 15:35:29 +08001480 if (!rmap || !rmap->sampler_count)
1481 return 0;
1482
Cody Northrop40316a32014-12-09 19:08:33 -07001483 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001484
Chia-I Wudcb509d2014-12-10 08:53:10 +08001485 /*
1486 * note that we cannot call cmd_state_pointer() here as the following
1487 * cmd_state_pointer() would invalidate the pointer
1488 */
1489 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001490 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001491 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001492
1493 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001494 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495 4 * rmap->sampler_count, &sampler_dw);
1496
Chia-I Wudcb509d2014-12-10 08:53:10 +08001497 cmd_state_update(cmd, border_offset,
1498 border_stride * rmap->sampler_count, &border_dw);
1499
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001500 for (i = 0; i < rmap->sampler_count; i++) {
1501 const struct intel_pipeline_rmap_slot *slot =
1502 &rmap->slots[surface_count + i];
1503 const struct intel_sampler *sampler;
1504
Chia-I Wuf8385062015-01-04 16:27:24 +08001505 switch (slot->type) {
1506 case INTEL_PIPELINE_RMAP_SAMPLER:
1507 intel_desc_pool_read_sampler(cmd->dev->desc_pool,
1508 &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001509 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001510 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001511 sampler = NULL;
1512 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001513 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001514 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001515 sampler = NULL;
1516 break;
1517 }
1518
1519 if (sampler) {
1520 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1521
1522 sampler_dw[0] = sampler->cmd[0];
1523 sampler_dw[1] = sampler->cmd[1];
1524 sampler_dw[2] = border_offset;
1525 sampler_dw[3] = sampler->cmd[2];
1526 } else {
1527 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1528 sampler_dw[1] = 0;
1529 sampler_dw[2] = 0;
1530 sampler_dw[3] = 0;
1531 }
1532
1533 border_offset += border_stride * 4;
1534 border_dw += border_stride;
1535 sampler_dw += 4;
1536 }
1537
Chia-I Wu625105f2014-10-13 15:35:29 +08001538 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001539}
1540
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001541static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001542 const struct intel_pipeline_rmap *rmap,
1543 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001544{
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001546 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001547
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001548 CMD_ASSERT(cmd, 6, 7.5);
1549
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001550 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001551 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001552 if (!surface_count)
1553 return 0;
1554
Chia-I Wu42a56202014-08-23 16:47:48 +08001555 assert(surface_count <= ARRAY_SIZE(binding_table));
1556
1557 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001558 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001559 struct intel_null_view null_view;
1560 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001561
Chia-I Wuf8385062015-01-04 16:27:24 +08001562 switch (slot->type) {
1563 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001564 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001565 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001566 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1567 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001568
Chia-I Wu787a05b2014-12-05 11:02:20 +08001569 if (view) {
1570 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1571 GEN6_ALIGNMENT_SURFACE_STATE,
1572 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wu787a05b2014-12-05 11:02:20 +08001574 cmd_reserve_reloc(cmd, 1);
1575 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1576 view->cmd[1], INTEL_RELOC_WRITE);
1577 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001578 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001579 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001580 }
1581 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001582 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001583 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001584 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1585 const struct intel_mem *mem;
1586 bool read_only;
1587 const uint32_t *cmd_data;
1588 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001589
Chia-I Wuf8385062015-01-04 16:27:24 +08001590 assert(dyn_idx < 0 || dyn_idx <
1591 cmd->bind.dset.graphics->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001592
Chia-I Wuf8385062015-01-04 16:27:24 +08001593 intel_desc_pool_read_surface(cmd->dev->desc_pool,
1594 &slot->u.surface.offset, stage, &mem,
1595 &read_only, &cmd_data, &cmd_len);
1596 if (mem) {
1597 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1598 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1599 const uint32_t reloc_flags =
1600 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001601
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001602 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001603 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001604 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605
1606 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001607 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1608 cmd_data[1] + dynamic_offset, reloc_flags);
1609 } else {
1610 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001611 }
1612 }
1613 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001614 case INTEL_PIPELINE_RMAP_UNUSED:
1615 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001616 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001617 default:
1618 assert(!"unexpected rmap type");
1619 need_null_view = true;
1620 break;
1621 }
1622
1623 if (need_null_view) {
1624 intel_null_view_init(&null_view, cmd->dev);
1625 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1626 GEN6_ALIGNMENT_SURFACE_STATE,
1627 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001628 }
1629
Chia-I Wu72292b72014-09-09 10:48:33 +08001630 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001631 }
1632
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001633 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001634 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001635 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001636}
1637
Chia-I Wu1d125092014-10-08 08:49:38 +08001638static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1639{
1640 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001641 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1642 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001643 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001644
1645 CMD_ASSERT(cmd, 6, 7.5);
1646
1647 if (!pipeline->vb_count)
1648 return;
1649
1650 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1651
1652 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1653 dw++;
1654 pos++;
1655
1656 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001657 assert(pipeline->vb[i].strideInBytes <= 2048);
1658
1659 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1660 pipeline->vb[i].strideInBytes;
1661
1662 if (cmd_gen(cmd) >= INTEL_GEN(7))
1663 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1664
1665 switch (pipeline->vb[i].stepRate) {
1666 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1667 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1668 dw[3] = 0;
1669 break;
1670 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1671 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1672 dw[3] = 1;
1673 break;
1674 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1675 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1676 dw[3] = 0;
1677 break;
1678 default:
1679 assert(!"unknown step rate");
1680 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1681 dw[3] = 0;
1682 break;
1683 }
1684
Chia-I Wu714df452015-01-01 07:55:04 +08001685 if (cmd->bind.vertex.buf[i]) {
1686 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001687 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001688
1689 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001690 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1691 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001692 } else {
1693 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1694 dw[1] = 0;
1695 dw[2] = 0;
1696 }
1697
1698 dw += 4;
1699 pos += 4;
1700 }
1701}
1702
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001703static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1704{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001705 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1706 const struct intel_pipeline_shader *vs = &pipeline->vs;
1707 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001708 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001709 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001710 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001711 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001712
1713 CMD_ASSERT(cmd, 6, 7.5);
1714
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001715 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001716 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1717 *
1718 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1719 * 128-bit vertex elements to be passed into the payload for each
1720 * vertex."
1721 *
1722 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1723 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001724 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001725 vue_read_len = (vs->in_count + 1) / 2;
1726 if (!vue_read_len)
1727 vue_read_len = 1;
1728
1729 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1730 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1731
1732 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1733 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1734 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001735
1736 dw5 = GEN6_VS_DW5_STATISTICS |
1737 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001738
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001739 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001740 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001741 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001742 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001743
Chia-I Wube0a3d92014-09-02 13:20:59 +08001744 if (pipeline->disable_vs_cache)
1745 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1746
Chia-I Wu784d3042014-12-19 14:30:04 +08001747 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001748 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001749 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001750 dw[2] = dw2;
1751 dw[3] = 0; /* scratch */
1752 dw[4] = dw4;
1753 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001754
1755 if (vs->per_thread_scratch_size)
1756 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001757}
1758
Chia-I Wu625105f2014-10-13 15:35:29 +08001759static void emit_shader_resources(struct intel_cmd *cmd)
1760{
1761 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001762 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001763
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001764 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001765 cmd->bind.pipeline.graphics->vs.rmap,
1766 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001767 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001768 cmd->bind.pipeline.graphics->tcs.rmap,
1769 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001770 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001771 cmd->bind.pipeline.graphics->tes.rmap,
1772 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001773 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001774 cmd->bind.pipeline.graphics->gs.rmap,
1775 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001776 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001777 cmd->bind.pipeline.graphics->fs.rmap,
1778 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001779
1780 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1781 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1782 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1783 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1784 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1785
1786 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1787 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001788 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1789 binding_tables[0]);
1790 gen7_3dstate_pointer(cmd,
1791 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1792 binding_tables[1]);
1793 gen7_3dstate_pointer(cmd,
1794 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1795 binding_tables[2]);
1796 gen7_3dstate_pointer(cmd,
1797 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1798 binding_tables[3]);
1799 gen7_3dstate_pointer(cmd,
1800 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1801 binding_tables[4]);
1802
1803 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001804 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1805 samplers[0]);
1806 gen7_3dstate_pointer(cmd,
1807 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1808 samplers[1]);
1809 gen7_3dstate_pointer(cmd,
1810 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1811 samplers[2]);
1812 gen7_3dstate_pointer(cmd,
1813 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1814 samplers[3]);
1815 gen7_3dstate_pointer(cmd,
1816 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1817 samplers[4]);
1818 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001819 assert(!binding_tables[1] && !binding_tables[2]);
1820 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1821 binding_tables[0], binding_tables[3], binding_tables[4]);
1822
Chia-I Wu625105f2014-10-13 15:35:29 +08001823 assert(!samplers[1] && !samplers[2]);
1824 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1825 samplers[0], samplers[3], samplers[4]);
1826 }
1827}
1828
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001829static void emit_rt(struct intel_cmd *cmd)
1830{
1831 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001832 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1833 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001834}
1835
1836static void emit_ds(struct intel_cmd *cmd)
1837{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001838 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001839
1840 if (!ds) {
1841 /* all zeros */
1842 static const struct intel_ds_view null_ds;
1843 ds = &null_ds;
1844 }
1845
1846 cmd_wa_gen6_pre_ds_flush(cmd);
1847 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1848 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1849 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1850
1851 if (cmd_gen(cmd) >= INTEL_GEN(7))
1852 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1853 else
1854 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1855}
1856
Chia-I Wua57761b2014-10-14 14:27:44 +08001857static uint32_t emit_shader(struct intel_cmd *cmd,
1858 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001859{
Chia-I Wua57761b2014-10-14 14:27:44 +08001860 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1861 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001862 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001863
Chia-I Wua57761b2014-10-14 14:27:44 +08001864 /* see if the shader is already in the cache */
1865 for (i = 0; i < cache->used; i++) {
1866 if (cache->entries[i].shader == (const void *) shader)
1867 return cache->entries[i].kernel_offset;
1868 }
1869
1870 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1871
1872 /* grow the cache if full */
1873 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001874 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001875 void *entries;
1876
1877 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1878 XGL_SYSTEM_ALLOC_INTERNAL);
1879 if (entries) {
1880 if (cache->entries) {
1881 memcpy(entries, cache->entries,
1882 sizeof(cache->entries[0]) * cache->used);
1883 icd_free(cache->entries);
1884 }
1885
1886 cache->entries = entries;
1887 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001888 }
1889 }
1890
Chia-I Wua57761b2014-10-14 14:27:44 +08001891 /* add the shader to the cache */
1892 if (cache->used < cache->count) {
1893 cache->entries[cache->used].shader = (const void *) shader;
1894 cache->entries[cache->used].kernel_offset = offset;
1895 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001896 }
1897
Chia-I Wua57761b2014-10-14 14:27:44 +08001898 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001899}
1900
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001901static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001902{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001903 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001904
Chia-I Wu8370b402014-08-29 12:28:37 +08001905 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1906 cmd_wa_gen6_pre_depth_stall_write(cmd);
1907 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1908 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1909 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1910 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001911
1912 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001913 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001914 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001915
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001916 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001917 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001918 }
1919 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001920 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001921 }
1922 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001923 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1924 }
1925 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1926 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1927 }
1928 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1929 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001930 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001931
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001932 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1933 gen7_3DSTATE_GS(cmd);
1934 } else {
1935 gen6_3DSTATE_GS(cmd);
1936 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001937
Chia-I Wu8370b402014-08-29 12:28:37 +08001938 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1939 cmd_wa_gen7_post_command_cs_stall(cmd);
1940 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1941 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001942}
1943
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001944static void emit_bounded_states(struct intel_cmd *cmd)
1945{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001946
1947 emit_graphics_pipeline(cmd);
1948
1949 emit_rt(cmd);
1950 emit_ds(cmd);
1951
1952 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1953 gen7_cc_states(cmd);
1954 gen7_viewport_states(cmd);
1955
1956 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1957 &cmd->bind.pipeline.graphics->vs);
1958 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1959 &cmd->bind.pipeline.graphics->fs);
1960
1961 gen6_3DSTATE_CLIP(cmd);
1962 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001963 gen7_3DSTATE_WM(cmd);
1964 gen7_3DSTATE_PS(cmd);
1965 } else {
1966 gen6_cc_states(cmd);
1967 gen6_viewport_states(cmd);
1968
1969 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1970 &cmd->bind.pipeline.graphics->vs);
1971 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1972 &cmd->bind.pipeline.graphics->fs);
1973
1974 gen6_3DSTATE_CLIP(cmd);
1975 gen6_3DSTATE_SF(cmd);
1976 gen6_3DSTATE_WM(cmd);
1977 }
1978
1979 emit_shader_resources(cmd);
1980
1981 cmd_wa_gen6_pre_depth_stall_write(cmd);
1982 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1983
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001984 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1985 gen6_3DSTATE_VS(cmd);
1986}
1987
Tony Barbourfa6cac72015-01-16 14:27:35 -07001988static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1989 const struct intel_cmd_meta *meta)
1990{
1991 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1992 const uint8_t cmd_len = 3;
1993 uint32_t dw[3];
1994 uint32_t cmd_depth_stencil;
1995 uint32_t cmd_depth_test;
1996
1997 CMD_ASSERT(cmd, 6, 7.5);
1998
1999 cmd_depth_stencil = 0;
2000 cmd_depth_test = 0;
2001 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2002 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2003 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2004 }
2005 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2006 cmd_depth_stencil = 1 << 31 |
2007 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2008 (GEN6_STENCILOP_KEEP) << 25 |
2009 (GEN6_STENCILOP_KEEP) << 22 |
2010 (GEN6_STENCILOP_REPLACE) << 19 |
2011 1 << 15 |
2012 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2013 (GEN6_STENCILOP_KEEP) << 9 |
2014 (GEN6_STENCILOP_KEEP) << 6 |
2015 (GEN6_STENCILOP_REPLACE) << 3;
2016 }
2017
2018 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2019 dw[0] = cmd_depth_stencil | 1 << 18;
2020 dw[1] = (0xff) << 24 | (0xff) << 16;
2021 dw[2] = cmd_depth_test;
2022
2023 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2024 cmd_align, cmd_len, dw);
2025}
2026
Chia-I Wu6032b892014-10-17 14:47:18 +08002027static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2028{
2029 const struct intel_cmd_meta *meta = cmd->bind.meta;
2030 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2031
2032 CMD_ASSERT(cmd, 6, 7.5);
2033
2034 blend_offset = 0;
2035 ds_offset = 0;
2036 cc_offset = 0;
2037 cc_vp_offset = 0;
2038
Chia-I Wu29e6f502014-11-24 14:27:29 +08002039 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002040 /* BLEND_STATE */
2041 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002042 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002043 dw[0] = 0;
2044 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2045 }
2046
Chia-I Wu29e6f502014-11-24 14:27:29 +08002047 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002048 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002050 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2051 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002052
Chia-I Wu29e6f502014-11-24 14:27:29 +08002053 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002054 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002055
Chia-I Wu29e6f502014-11-24 14:27:29 +08002056 /* COLOR_CALC_STATE */
2057 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002058 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002059
Chia-I Wu29e6f502014-11-24 14:27:29 +08002060 /* CC_VIEWPORT */
2061 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002062 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002063 dw[0] = u_fui(0.0f);
2064 dw[1] = u_fui(1.0f);
2065 } else {
2066 /* DEPTH_STENCIL_STATE */
2067 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002068 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002069 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2070 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2071 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002072 }
2073
2074 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2075 gen7_3dstate_pointer(cmd,
2076 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2077 blend_offset);
2078 gen7_3dstate_pointer(cmd,
2079 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2080 ds_offset);
2081 gen7_3dstate_pointer(cmd,
2082 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2083
2084 gen7_3dstate_pointer(cmd,
2085 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2086 cc_vp_offset);
2087 } else {
2088 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002089 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002090
2091 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2092 cmd_batch_pointer(cmd, 4, &dw);
2093 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2094 GEN6_PTR_VP_DW0_CC_CHANGED;
2095 dw[1] = 0;
2096 dw[2] = 0;
2097 dw[3] = cc_vp_offset;
2098 }
2099}
2100
2101static void gen6_meta_surface_states(struct intel_cmd *cmd)
2102{
2103 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002104 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002105 uint32_t offset;
2106
2107 CMD_ASSERT(cmd, 6, 7.5);
2108
Chia-I Wu29e6f502014-11-24 14:27:29 +08002109 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2110 return;
2111
Chia-I Wu005c47c2014-10-22 13:49:13 +08002112 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002113 if (meta->src.valid) {
2114 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002115 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002116 meta->src.surface_len, meta->src.surface);
2117
2118 cmd_reserve_reloc(cmd, 1);
2119 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2120 cmd_surface_reloc_writer(cmd, offset, 1,
2121 meta->src.reloc_target, meta->src.reloc_offset);
2122 } else {
2123 cmd_surface_reloc(cmd, offset, 1,
2124 (struct intel_bo *) meta->src.reloc_target,
2125 meta->src.reloc_offset, meta->src.reloc_flags);
2126 }
2127
Chia-I Wu005c47c2014-10-22 13:49:13 +08002128 binding_table[0] = offset;
2129 }
2130 if (meta->dst.valid) {
2131 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002132 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002133 meta->dst.surface_len, meta->dst.surface);
2134
2135 cmd_reserve_reloc(cmd, 1);
2136 cmd_surface_reloc(cmd, offset, 1,
2137 (struct intel_bo *) meta->dst.reloc_target,
2138 meta->dst.reloc_offset, meta->dst.reloc_flags);
2139
2140 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002141 }
2142
2143 /* BINDING_TABLE */
2144 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002145 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002146 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002147
2148 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002149 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2150 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2151 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2152 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 } else {
2154 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002155 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2156 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2157 else
2158 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002159 }
2160}
2161
2162static void gen6_meta_urb(struct intel_cmd *cmd)
2163{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002164 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002165 uint32_t *dw;
2166
2167 CMD_ASSERT(cmd, 6, 6);
2168
2169 /* 3DSTATE_URB */
2170 cmd_batch_pointer(cmd, 3, &dw);
2171 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002172 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002173 dw[2] = 0;
2174}
2175
2176static void gen7_meta_urb(struct intel_cmd *cmd)
2177{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002178 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002179 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002180 uint32_t *dw;
2181
2182 CMD_ASSERT(cmd, 7, 7.5);
2183
2184 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2185 cmd_batch_pointer(cmd, 10, &dw);
2186
2187 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002188 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002189 dw += 2;
2190
2191 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2192 dw[1] = 0;
2193 dw += 2;
2194
2195 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2196 dw[1] = 0;
2197 dw += 2;
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2200 dw[1] = 0;
2201 dw += 2;
2202
2203 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002204 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002205
2206 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2207
Chia-I Wu24aa1022014-11-25 11:53:19 +08002208 switch (cmd_gen(cmd)) {
2209 case INTEL_GEN(7.5):
2210 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2211 break;
2212 case INTEL_GEN(7):
2213 default:
2214 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2215 break;
2216 }
2217
Chia-I Wu6032b892014-10-17 14:47:18 +08002218 /* 3DSTATE_URB_x */
2219 cmd_batch_pointer(cmd, 8, &dw);
2220
2221 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2222 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002223 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002224 dw += 2;
2225
2226 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2227 dw[1] = 0;
2228 dw += 2;
2229
2230 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2231 dw[1] = 0;
2232 dw += 2;
2233
2234 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2235 dw[1] = 0;
2236 dw += 2;
2237}
2238
2239static void gen6_meta_vf(struct intel_cmd *cmd)
2240{
2241 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002242 uint32_t vb_start, vb_end, vb_stride;
2243 int ve_format, ve_z_source;
2244 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002245 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002246
2247 CMD_ASSERT(cmd, 6, 7.5);
2248
Chia-I Wu29e6f502014-11-24 14:27:29 +08002249 switch (meta->mode) {
2250 case INTEL_CMD_META_VS_POINTS:
2251 cmd_batch_pointer(cmd, 3, &dw);
2252 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2253 dw[1] = GEN6_VE_STATE_DW0_VALID;
2254 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2255 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2256 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2257 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2258 return;
2259 break;
2260 case INTEL_CMD_META_FS_RECT:
2261 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002262 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 vertices[0][0] = meta->dst.x + meta->width;
2265 vertices[0][1] = meta->dst.y + meta->height;
2266 vertices[1][0] = meta->dst.x;
2267 vertices[1][1] = meta->dst.y + meta->height;
2268 vertices[2][0] = meta->dst.x;
2269 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002270
Chia-I Wu29e6f502014-11-24 14:27:29 +08002271 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2272 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002273
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 vb_end = vb_start + sizeof(vertices) - 1;
2275 vb_stride = sizeof(vertices[0]);
2276 ve_z_source = GEN6_VFCOMP_STORE_0;
2277 ve_format = GEN6_FORMAT_R32G32_USCALED;
2278 }
2279 break;
2280 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2281 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002282 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002283
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002284 vertices[0][0] = (float) (meta->dst.x + meta->width);
2285 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002287 vertices[1][0] = (float) meta->dst.x;
2288 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002290 vertices[2][0] = (float) meta->dst.x;
2291 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002293
Chia-I Wu29e6f502014-11-24 14:27:29 +08002294 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2295 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002296
Chia-I Wu29e6f502014-11-24 14:27:29 +08002297 vb_end = vb_start + sizeof(vertices) - 1;
2298 vb_stride = sizeof(vertices[0]);
2299 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2300 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2301 }
2302 break;
2303 default:
2304 assert(!"unknown meta mode");
2305 return;
2306 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002307 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002308
2309 /* 3DSTATE_VERTEX_BUFFERS */
2310 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311
Chia-I Wu6032b892014-10-17 14:47:18 +08002312 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002313 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002314 if (cmd_gen(cmd) >= INTEL_GEN(7))
2315 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2316
2317 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002318 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2319 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002320
2321 dw[4] = 0;
2322
2323 /* 3DSTATE_VERTEX_ELEMENTS */
2324 cmd_batch_pointer(cmd, 5, &dw);
2325 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002326 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002327 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2328 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2329 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2330 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2331 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002332 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002333 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2334 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002335 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002336 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2337}
2338
Chia-I Wu29e6f502014-11-24 14:27:29 +08002339static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002340{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002341 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002342 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002343 uint32_t consts[8];
2344 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002345
2346 CMD_ASSERT(cmd, 6, 7.5);
2347
2348 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002349 case INTEL_DEV_META_VS_FILL_MEM:
2350 consts[0] = meta->dst.x;
2351 consts[1] = meta->clear_val[0];
2352 const_count = 2;
2353 break;
2354 case INTEL_DEV_META_VS_COPY_MEM:
2355 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2356 consts[0] = meta->dst.x;
2357 consts[1] = meta->src.x;
2358 const_count = 2;
2359 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002360 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2361 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2362 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2363 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2364 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2365 consts[0] = meta->src.x;
2366 consts[1] = meta->src.y;
2367 consts[2] = meta->width;
2368 consts[3] = meta->dst.x;
2369 const_count = 4;
2370 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371 default:
2372 assert(!"unknown meta shader id");
2373 const_count = 0;
2374 break;
2375 }
2376
2377 /* this can be skipped but it makes state dumping prettier */
2378 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2379
2380 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2381}
2382
2383static void gen6_meta_vs(struct intel_cmd *cmd)
2384{
2385 const struct intel_cmd_meta *meta = cmd->bind.meta;
2386 const struct intel_pipeline_shader *sh =
2387 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2388 uint32_t offset, *dw;
2389
2390 CMD_ASSERT(cmd, 6, 7.5);
2391
2392 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002393 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002394
2395 /* 3DSTATE_CONSTANT_VS */
2396 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2397 cmd_batch_pointer(cmd, cmd_len, &dw);
2398 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2399 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2400
2401 /* 3DSTATE_VS */
2402 cmd_batch_pointer(cmd, 6, &dw);
2403 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2404 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2405
2406 return;
2407 }
2408
2409 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2410
2411 /* 3DSTATE_CONSTANT_VS */
2412 offset = gen6_meta_vs_constants(cmd);
2413 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2414 cmd_batch_pointer(cmd, 7, &dw);
2415 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2416 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2417 dw[2] = 0;
2418 dw[3] = offset;
2419 dw[4] = 0;
2420 dw[5] = 0;
2421 dw[6] = 0;
2422 } else {
2423 cmd_batch_pointer(cmd, 5, &dw);
2424 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2425 GEN6_PCB_ANY_DW0_PCB0_VALID;
2426 dw[1] = offset;
2427 dw[2] = 0;
2428 dw[3] = 0;
2429 dw[4] = 0;
2430 }
2431
2432 /* 3DSTATE_VS */
2433 offset = emit_shader(cmd, sh);
2434 cmd_batch_pointer(cmd, 6, &dw);
2435 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2436 dw[1] = offset;
2437 dw[2] = GEN6_THREADDISP_SPF |
2438 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2439 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002440 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002441 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2442 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2443
2444 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2445 GEN6_VS_DW5_VS_ENABLE;
2446 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002447 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002448 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002449 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002450
2451 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002452}
2453
2454static void gen6_meta_disabled(struct intel_cmd *cmd)
2455{
Chia-I Wu6032b892014-10-17 14:47:18 +08002456 uint32_t *dw;
2457
2458 CMD_ASSERT(cmd, 6, 6);
2459
Chia-I Wu6032b892014-10-17 14:47:18 +08002460 /* 3DSTATE_CONSTANT_GS */
2461 cmd_batch_pointer(cmd, 5, &dw);
2462 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2463 dw[1] = 0;
2464 dw[2] = 0;
2465 dw[3] = 0;
2466 dw[4] = 0;
2467
2468 /* 3DSTATE_GS */
2469 cmd_batch_pointer(cmd, 7, &dw);
2470 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2471 dw[1] = 0;
2472 dw[2] = 0;
2473 dw[3] = 0;
2474 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2475 dw[5] = GEN6_GS_DW5_STATISTICS;
2476 dw[6] = 0;
2477
Chia-I Wu6032b892014-10-17 14:47:18 +08002478 /* 3DSTATE_SF */
2479 cmd_batch_pointer(cmd, 20, &dw);
2480 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2481 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2482 memset(&dw[2], 0, 18 * sizeof(*dw));
2483}
2484
2485static void gen7_meta_disabled(struct intel_cmd *cmd)
2486{
2487 uint32_t *dw;
2488
2489 CMD_ASSERT(cmd, 7, 7.5);
2490
Chia-I Wu6032b892014-10-17 14:47:18 +08002491 /* 3DSTATE_CONSTANT_HS */
2492 cmd_batch_pointer(cmd, 7, &dw);
2493 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2494 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2495
2496 /* 3DSTATE_HS */
2497 cmd_batch_pointer(cmd, 7, &dw);
2498 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2499 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2500
2501 /* 3DSTATE_TE */
2502 cmd_batch_pointer(cmd, 4, &dw);
2503 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2504 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2505
2506 /* 3DSTATE_CONSTANT_DS */
2507 cmd_batch_pointer(cmd, 7, &dw);
2508 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2509 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2510
2511 /* 3DSTATE_DS */
2512 cmd_batch_pointer(cmd, 6, &dw);
2513 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2514 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2515
2516 /* 3DSTATE_CONSTANT_GS */
2517 cmd_batch_pointer(cmd, 7, &dw);
2518 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2520
2521 /* 3DSTATE_GS */
2522 cmd_batch_pointer(cmd, 7, &dw);
2523 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2525
2526 /* 3DSTATE_STREAMOUT */
2527 cmd_batch_pointer(cmd, 3, &dw);
2528 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2529 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2530
Chia-I Wu6032b892014-10-17 14:47:18 +08002531 /* 3DSTATE_SF */
2532 cmd_batch_pointer(cmd, 7, &dw);
2533 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2534 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2535
2536 /* 3DSTATE_SBE */
2537 cmd_batch_pointer(cmd, 14, &dw);
2538 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2539 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2540 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002541}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002542
Chia-I Wu29e6f502014-11-24 14:27:29 +08002543static void gen6_meta_clip(struct intel_cmd *cmd)
2544{
2545 const struct intel_cmd_meta *meta = cmd->bind.meta;
2546 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002547
Chia-I Wu29e6f502014-11-24 14:27:29 +08002548 /* 3DSTATE_CLIP */
2549 cmd_batch_pointer(cmd, 4, &dw);
2550 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2551 dw[1] = 0;
2552 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2553 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2554 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2555 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002556 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002557 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002558 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002559}
2560
2561static void gen6_meta_wm(struct intel_cmd *cmd)
2562{
2563 const struct intel_cmd_meta *meta = cmd->bind.meta;
2564 uint32_t *dw;
2565
2566 CMD_ASSERT(cmd, 6, 7.5);
2567
2568 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2569
2570 /* 3DSTATE_MULTISAMPLE */
2571 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2572 cmd_batch_pointer(cmd, 4, &dw);
2573 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2574 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2575 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2576 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2577 dw[2] = 0;
2578 dw[3] = 0;
2579 } else {
2580 cmd_batch_pointer(cmd, 3, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2582 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2583 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2584 dw[2] = 0;
2585 }
2586
2587 /* 3DSTATE_SAMPLE_MASK */
2588 cmd_batch_pointer(cmd, 2, &dw);
2589 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2590 dw[1] = (1 << meta->samples) - 1;
2591
2592 /* 3DSTATE_DRAWING_RECTANGLE */
2593 cmd_batch_pointer(cmd, 4, &dw);
2594 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2595 dw[1] = meta->dst.y << 16 | meta->dst.x;
2596 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2597 (meta->dst.x + meta->width - 1);
2598 dw[3] = 0;
2599}
2600
2601static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2602{
2603 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002604 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002605 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002606 uint32_t consts[8];
2607 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002608
2609 CMD_ASSERT(cmd, 6, 7.5);
2610
2611 /* underflow is fine here */
2612 offset_x = meta->src.x - meta->dst.x;
2613 offset_y = meta->src.y - meta->dst.y;
2614
2615 switch (meta->shader_id) {
2616 case INTEL_DEV_META_FS_COPY_MEM:
2617 case INTEL_DEV_META_FS_COPY_1D:
2618 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2619 case INTEL_DEV_META_FS_COPY_2D:
2620 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2621 case INTEL_DEV_META_FS_COPY_2D_MS:
2622 consts[0] = offset_x;
2623 consts[1] = offset_y;
2624 consts[2] = meta->src.layer;
2625 consts[3] = meta->src.lod;
2626 const_count = 4;
2627 break;
2628 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2629 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2630 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2631 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2632 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2633 consts[0] = offset_x;
2634 consts[1] = offset_y;
2635 consts[2] = meta->src.layer;
2636 consts[3] = meta->src.lod;
2637 consts[4] = meta->src.x;
2638 consts[5] = meta->width;
2639 const_count = 6;
2640 break;
2641 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2642 consts[0] = offset_x;
2643 consts[1] = offset_y;
2644 consts[2] = meta->width;
2645 const_count = 3;
2646 break;
2647 case INTEL_DEV_META_FS_CLEAR_COLOR:
2648 consts[0] = meta->clear_val[0];
2649 consts[1] = meta->clear_val[1];
2650 consts[2] = meta->clear_val[2];
2651 consts[3] = meta->clear_val[3];
2652 const_count = 4;
2653 break;
2654 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2655 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002656 consts[1] = meta->clear_val[1];
2657 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002658 break;
2659 case INTEL_DEV_META_FS_RESOLVE_2X:
2660 case INTEL_DEV_META_FS_RESOLVE_4X:
2661 case INTEL_DEV_META_FS_RESOLVE_8X:
2662 case INTEL_DEV_META_FS_RESOLVE_16X:
2663 consts[0] = offset_x;
2664 consts[1] = offset_y;
2665 const_count = 2;
2666 break;
2667 default:
2668 assert(!"unknown meta shader id");
2669 const_count = 0;
2670 break;
2671 }
2672
2673 /* this can be skipped but it makes state dumping prettier */
2674 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2675
2676 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2677}
2678
2679static void gen6_meta_ps(struct intel_cmd *cmd)
2680{
2681 const struct intel_cmd_meta *meta = cmd->bind.meta;
2682 const struct intel_pipeline_shader *sh =
2683 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2684 uint32_t offset, *dw;
2685
2686 CMD_ASSERT(cmd, 6, 6);
2687
Chia-I Wu29e6f502014-11-24 14:27:29 +08002688 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2689 /* 3DSTATE_CONSTANT_PS */
2690 cmd_batch_pointer(cmd, 5, &dw);
2691 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2692 dw[1] = 0;
2693 dw[2] = 0;
2694 dw[3] = 0;
2695 dw[4] = 0;
2696
2697 /* 3DSTATE_WM */
2698 cmd_batch_pointer(cmd, 9, &dw);
2699 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2700 dw[1] = 0;
2701 dw[2] = 0;
2702 dw[3] = 0;
2703 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002704 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002705 dw[6] = 0;
2706 dw[7] = 0;
2707 dw[8] = 0;
2708
Chia-I Wu3adf7212014-10-24 15:34:07 +08002709 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002710 }
2711
Chia-I Wu3adf7212014-10-24 15:34:07 +08002712 /* a normal color write */
2713 assert(meta->dst.valid && !sh->uses);
2714
Chia-I Wu6032b892014-10-17 14:47:18 +08002715 /* 3DSTATE_CONSTANT_PS */
2716 offset = gen6_meta_ps_constants(cmd);
2717 cmd_batch_pointer(cmd, 5, &dw);
2718 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2719 GEN6_PCB_ANY_DW0_PCB0_VALID;
2720 dw[1] = offset;
2721 dw[2] = 0;
2722 dw[3] = 0;
2723 dw[4] = 0;
2724
2725 /* 3DSTATE_WM */
2726 offset = emit_shader(cmd, sh);
2727 cmd_batch_pointer(cmd, 9, &dw);
2728 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2729 dw[1] = offset;
2730 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2731 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002732 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002733 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002734 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002735 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002736 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2737
Chia-I Wu6032b892014-10-17 14:47:18 +08002738 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2739 GEN6_WM_DW6_POSOFFSET_NONE |
2740 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2741 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2742 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2743 if (meta->samples > 1) {
2744 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2745 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2746 } else {
2747 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2748 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2749 }
2750 dw[7] = 0;
2751 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002752
2753 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002754}
2755
2756static void gen7_meta_ps(struct intel_cmd *cmd)
2757{
2758 const struct intel_cmd_meta *meta = cmd->bind.meta;
2759 const struct intel_pipeline_shader *sh =
2760 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2761 uint32_t offset, *dw;
2762
2763 CMD_ASSERT(cmd, 7, 7.5);
2764
Chia-I Wu29e6f502014-11-24 14:27:29 +08002765 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2766 /* 3DSTATE_WM */
2767 cmd_batch_pointer(cmd, 3, &dw);
2768 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2769 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2770
2771 /* 3DSTATE_CONSTANT_GS */
2772 cmd_batch_pointer(cmd, 7, &dw);
2773 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2774 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2775
2776 /* 3DSTATE_PS */
2777 cmd_batch_pointer(cmd, 8, &dw);
2778 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2779 dw[1] = 0;
2780 dw[2] = 0;
2781 dw[3] = 0;
2782 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002783 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002784 dw[5] = 0;
2785 dw[6] = 0;
2786 dw[7] = 0;
2787
Chia-I Wu3adf7212014-10-24 15:34:07 +08002788 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002789 }
2790
Chia-I Wu3adf7212014-10-24 15:34:07 +08002791 /* a normal color write */
2792 assert(meta->dst.valid && !sh->uses);
2793
Chia-I Wu6032b892014-10-17 14:47:18 +08002794 /* 3DSTATE_WM */
2795 cmd_batch_pointer(cmd, 3, &dw);
2796 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2797 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2798 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2799 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2800 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2801 dw[2] = 0;
2802
2803 /* 3DSTATE_CONSTANT_PS */
2804 offset = gen6_meta_ps_constants(cmd);
2805 cmd_batch_pointer(cmd, 7, &dw);
2806 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2807 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2808 dw[2] = 0;
2809 dw[3] = offset;
2810 dw[4] = 0;
2811 dw[5] = 0;
2812 dw[6] = 0;
2813
2814 /* 3DSTATE_PS */
2815 offset = emit_shader(cmd, sh);
2816 cmd_batch_pointer(cmd, 8, &dw);
2817 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2818 dw[1] = offset;
2819 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2820 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002821 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002822
2823 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2824 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002825 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2826
2827 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002828 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002829 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002830 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002831 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002832 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002833
2834 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2835 dw[6] = 0;
2836 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002837
2838 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002839}
2840
2841static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2842{
2843 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002844 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002845
2846 CMD_ASSERT(cmd, 6, 7.5);
2847
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002848 if (!ds) {
2849 /* all zeros */
2850 static const struct intel_ds_view null_ds;
2851 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002852 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002853
2854 cmd_wa_gen6_pre_ds_flush(cmd);
2855 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2856 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2857 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2858
2859 if (cmd_gen(cmd) >= INTEL_GEN(7))
2860 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2861 else
2862 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002863}
2864
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002865static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2866 const struct intel_pipeline *pipeline)
2867{
2868 cmd->bind.pipeline.graphics = pipeline;
2869}
2870
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002871static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2872 const struct intel_pipeline *pipeline)
2873{
2874 cmd->bind.pipeline.compute = pipeline;
2875}
2876
2877static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2878 const struct intel_pipeline_delta *delta)
2879{
2880 cmd->bind.pipeline.graphics_delta = delta;
2881}
2882
2883static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2884 const struct intel_pipeline_delta *delta)
2885{
2886 cmd->bind.pipeline.compute_delta = delta;
2887}
2888
2889static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002890 const struct intel_desc_set *dset,
2891 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002892{
Chia-I Wuf8385062015-01-04 16:27:24 +08002893 const uint32_t size = sizeof(*dynamic_offsets) *
2894 dset->layout->dynamic_desc_count;
2895
2896 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2897 if (cmd->bind.dset.graphics_dynamic_offsets)
2898 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2899
2900 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2901 4, XGL_SYSTEM_ALLOC_INTERNAL);
2902 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2903 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2904 return;
2905 }
2906
2907 cmd->bind.dset.graphics_dynamic_offset_size = size;
2908 }
2909
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002910 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002911 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002912}
2913
2914static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002915 const struct intel_desc_set *dset,
2916 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002917{
Chia-I Wuf8385062015-01-04 16:27:24 +08002918 const uint32_t size = sizeof(*dynamic_offsets) *
2919 dset->layout->dynamic_desc_count;
2920
2921 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2922 if (cmd->bind.dset.compute_dynamic_offsets)
2923 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2924
2925 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2926 4, XGL_SYSTEM_ALLOC_INTERNAL);
2927 if (!cmd->bind.dset.compute_dynamic_offsets) {
2928 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2929 return;
2930 }
2931
2932 cmd->bind.dset.compute_dynamic_offset_size = size;
2933 }
2934
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002935 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002936 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937}
2938
Chia-I Wu3b04af52014-11-08 10:48:20 +08002939static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002940 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002941 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002942{
Chia-I Wu714df452015-01-01 07:55:04 +08002943 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002944 cmd->result = XGL_ERROR_UNKNOWN;
2945 return;
2946 }
2947
Chia-I Wu714df452015-01-01 07:55:04 +08002948 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002949 cmd->bind.vertex.offset[binding] = offset;
2950}
2951
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002953 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002954 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2955{
Chia-I Wu714df452015-01-01 07:55:04 +08002956 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002957 cmd->bind.index.offset = offset;
2958 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002959}
2960
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002962 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002963{
2964 cmd->bind.state.viewport = state;
2965}
2966
2967static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002968 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969{
2970 cmd->bind.state.raster = state;
2971}
2972
2973static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002974 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002975{
2976 cmd->bind.state.ds = state;
2977}
2978
2979static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002980 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002981{
2982 cmd->bind.state.blend = state;
2983}
2984
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002985static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002986 uint32_t vertex_start,
2987 uint32_t vertex_count,
2988 uint32_t instance_start,
2989 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002991 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002992{
2993 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2994
2995 emit_bounded_states(cmd);
2996
2997 if (indexed) {
2998 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2999 cmd->result = XGL_ERROR_UNKNOWN;
3000
3001 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3002 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3003 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003004 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003005 cmd->bind.index.offset, cmd->bind.index.type,
3006 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003007 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003008 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003009 cmd->bind.index.offset, cmd->bind.index.type,
3010 p->primitive_restart);
3011 }
3012 } else {
3013 assert(!vertex_base);
3014 }
3015
3016 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3017 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3018 vertex_start, instance_count, instance_start, vertex_base);
3019 } else {
3020 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3021 vertex_start, instance_count, instance_start, vertex_base);
3022 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003023
Chia-I Wu707a29e2014-08-27 12:51:47 +08003024 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003025 /* need to re-emit all workarounds */
3026 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003027
3028 if (intel_debug & INTEL_DEBUG_NOCACHE)
3029 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003030}
3031
Chia-I Wuc14d1562014-10-17 09:49:22 +08003032void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3033{
Chia-I Wu6032b892014-10-17 14:47:18 +08003034 cmd->bind.meta = meta;
3035
3036 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003037 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003038
3039 gen6_meta_dynamic_states(cmd);
3040 gen6_meta_surface_states(cmd);
3041
3042 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3043 gen7_meta_urb(cmd);
3044 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003045 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003046 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003047 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003048 gen6_meta_wm(cmd);
3049 gen7_meta_ps(cmd);
3050 gen6_meta_depth_buffer(cmd);
3051
3052 cmd_wa_gen7_post_command_cs_stall(cmd);
3053 cmd_wa_gen7_post_command_depth_stall(cmd);
3054
Chia-I Wu29e6f502014-11-24 14:27:29 +08003055 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3056 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003057 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003058 } else {
3059 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3060 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003061 } else {
3062 gen6_meta_urb(cmd);
3063 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003064 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003065 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003066 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003067 gen6_meta_wm(cmd);
3068 gen6_meta_ps(cmd);
3069 gen6_meta_depth_buffer(cmd);
3070
Chia-I Wu29e6f502014-11-24 14:27:29 +08003071 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3072 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003073 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003074 } else {
3075 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3076 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003077 }
3078
3079 cmd->bind.draw_count++;
3080 /* need to re-emit all workarounds */
3081 cmd->bind.wa_flags = 0;
3082
3083 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003084
3085 if (intel_debug & INTEL_DEBUG_NOCACHE)
3086 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003087}
3088
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003089ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003090 XGL_CMD_BUFFER cmdBuffer,
3091 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3092 XGL_PIPELINE pipeline)
3093{
3094 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3095
3096 switch (pipelineBindPoint) {
3097 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003098 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003099 break;
3100 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003101 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003102 break;
3103 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003105 break;
3106 }
3107}
3108
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003109ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003110 XGL_CMD_BUFFER cmdBuffer,
3111 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3112 XGL_PIPELINE_DELTA delta)
3113{
3114 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3115
3116 switch (pipelineBindPoint) {
3117 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003118 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003119 break;
3120 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003121 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003122 break;
3123 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003125 break;
3126 }
3127}
3128
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003129ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003130 XGL_CMD_BUFFER cmdBuffer,
3131 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003132 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003133{
3134 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3135
3136 switch (stateBindPoint) {
3137 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003138 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003139 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003140 break;
3141 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003142 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003143 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003144 break;
3145 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003146 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003147 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003148 break;
3149 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003150 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003151 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003152 break;
3153 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003154 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003155 break;
3156 }
3157}
3158
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003159ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003160 XGL_CMD_BUFFER cmdBuffer,
3161 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003162 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003163 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003164{
3165 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003166 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003167
3168 switch (pipelineBindPoint) {
3169 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003170 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003171 break;
3172 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003173 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003174 break;
3175 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003176 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003177 break;
3178 }
3179}
3180
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003181ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003182 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003183 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003184 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003185 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003186{
3187 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003188 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003189
Chia-I Wu714df452015-01-01 07:55:04 +08003190 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003191}
3192
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003193ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003194 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003195 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003196 XGL_GPU_SIZE offset,
3197 XGL_INDEX_TYPE indexType)
3198{
3199 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003200 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003201
Chia-I Wu714df452015-01-01 07:55:04 +08003202 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003203}
3204
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003205ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003206 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003207 uint32_t firstVertex,
3208 uint32_t vertexCount,
3209 uint32_t firstInstance,
3210 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003211{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003212 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003213
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003214 cmd_draw(cmd, firstVertex, vertexCount,
3215 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003216}
3217
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003218ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003219 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003220 uint32_t firstIndex,
3221 uint32_t indexCount,
3222 int32_t vertexOffset,
3223 uint32_t firstInstance,
3224 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003225{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003226 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003227
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003228 cmd_draw(cmd, firstIndex, indexCount,
3229 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003230}
3231
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003232ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003233 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003234 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003235 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003236 uint32_t count,
3237 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003238{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003239 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3240
3241 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003242}
3243
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003244ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003245 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003246 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003247 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003248 uint32_t count,
3249 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003250{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003251 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3252
3253 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003254}
3255
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003256ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003257 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003258 uint32_t x,
3259 uint32_t y,
3260 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003261{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003262 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3263
3264 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003265}
3266
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003267ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003268 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003269 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003270 XGL_GPU_SIZE offset)
3271{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003272 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3273
3274 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003275}