blob: af96deddc76b05f6019651cb1b5dfaa8ba170218 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700273 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700279 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700394 switch (pipeline->db_format) {
395 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700398 case XGL_FMT_D32_SFLOAT:
399 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700413 /* Scissor is always enabled */
414 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
415
Tony Barbourfa6cac72015-01-16 14:27:35 -0700416 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800417 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
419 } else {
420 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
421 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
422 }
423
Chia-I Wu8016a172014-08-29 18:31:32 +0800424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
Chia-I Wu8016a172014-08-29 18:31:32 +0800443static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
444{
445 const uint8_t cmd_len = 20;
446 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
447 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800448 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800450 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800451
452 CMD_ASSERT(cmd, 6, 6);
453
454 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800455
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 cmd_batch_pointer(cmd, cmd_len, &dw);
457 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800458 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800460 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800461}
462
463static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
464{
465 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 7, 7.5);
469
Chia-I Wu72292b72014-09-09 10:48:33 +0800470 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800471 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
472 (cmd_len - 2);
473 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474}
475
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800476static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
477{
478 const uint8_t cmd_len = 4;
479 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
480 (cmd_len - 2);
481 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700482 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800483 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700484 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800485 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800486
487 CMD_ASSERT(cmd, 6, 7.5);
488
489 dw1 = GEN6_CLIP_DW1_STATISTICS;
490 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
491 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
492 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800494 }
495
496 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
497 GEN6_CLIP_DW2_XY_TEST_ENABLE |
498 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700499 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800500 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
501 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
502 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
503
504 if (pipeline->rasterizerDiscardEnable)
505 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
506 else
507 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
508
509 if (pipeline->depthClipEnable)
510 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
511
512 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
513 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
514 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
515 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
516
517 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
518 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
519 (viewport->viewport_count - 1);
520
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600521 /* TODO: framebuffer requests layer_count > 1 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700522 if (cmd->bind.render_pass->fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600523 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
524 }
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
527 dw[0] = dw0;
528 dw[1] = dw1;
529 dw[2] = dw2;
530 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800531}
532
Chia-I Wu784d3042014-12-19 14:30:04 +0800533static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600534 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800535 const struct intel_pipeline *pipeline,
536 const struct intel_pipeline_shader *sh)
537{
538 int scratch_space;
539
540 CMD_ASSERT(cmd, 6, 7.5);
541
542 assert(sh->per_thread_scratch_size &&
543 sh->per_thread_scratch_size % 1024 == 0 &&
544 u_is_pow2(sh->per_thread_scratch_size) &&
545 sh->scratch_offset % 1024 == 0);
546 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
547
548 cmd_reserve_reloc(cmd, 1);
549 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
550 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
551}
552
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800553static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
554{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800555 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800556 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800557 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600558 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700559 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560
561 CMD_ASSERT(cmd, 6, 6);
562
563 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
564
565 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
566 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
567
568 dw4 = GEN6_WM_DW4_STATISTICS |
569 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
570 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700571 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800573 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700574 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
575 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800576
Cody Northrope86574e2015-02-24 14:15:29 -0700577 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700578 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700579
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800580 if (fs->uses & INTEL_SHADER_USE_KILL ||
581 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700582 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583
Cody Northrope238deb2015-01-26 14:41:36 -0700584 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800585 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
586 if (fs->uses & INTEL_SHADER_USE_DEPTH)
587 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
588 if (fs->uses & INTEL_SHADER_USE_W)
589 dw5 |= GEN6_WM_DW5_PS_USE_W;
590
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700591 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700592 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800593
594 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700595 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596 GEN6_WM_DW6_ZW_INTERP_PIXEL |
597 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
598 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
599
Tony Barbourfa6cac72015-01-16 14:27:35 -0700600 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
602 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
603 } else {
604 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
605 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
606 }
607
Cody Northrope86574e2015-02-24 14:15:29 -0700608 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
609
Chia-I Wu784d3042014-12-19 14:30:04 +0800610 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800611 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800612 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800613 dw[2] = dw2;
614 dw[3] = 0; /* scratch */
615 dw[4] = dw4;
616 dw[5] = dw5;
617 dw[6] = dw6;
618 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700619 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800620
621 if (fs->per_thread_scratch_size)
622 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800623}
624
625static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
626{
627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800628 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800629 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800630 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800631
632 CMD_ASSERT(cmd, 7, 7.5);
633
634 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
635
636 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700637 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638 GEN7_WM_DW1_ZW_INTERP_PIXEL |
639 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
640 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
641
642 if (fs->uses & INTEL_SHADER_USE_KILL ||
643 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700644 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645
Cody Northrope238deb2015-01-26 14:41:36 -0700646 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
647
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648 if (fs->uses & INTEL_SHADER_USE_DEPTH)
649 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
650 if (fs->uses & INTEL_SHADER_USE_W)
651 dw1 |= GEN7_WM_DW1_PS_USE_W;
652
653 dw2 = 0;
654
Tony Barbourfa6cac72015-01-16 14:27:35 -0700655 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800656 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
657 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
658 } else {
659 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
660 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
661 }
662
Chia-I Wu72292b72014-09-09 10:48:33 +0800663 cmd_batch_pointer(cmd, cmd_len, &dw);
664 dw[0] = dw0;
665 dw[1] = dw1;
666 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667}
668
669static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
670{
671 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800672 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800673 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700674 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600675 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676
677 CMD_ASSERT(cmd, 7, 7.5);
678
679 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
680
681 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
682 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
683
684 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700685 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800686
Cody Northrope86574e2015-02-24 14:15:29 -0700687 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700688 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700689
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800691 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800694 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800695 }
696
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 if (fs->in_count)
698 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
699
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700700 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
702
703 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
704 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700705 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
706
707 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800708
Chia-I Wu784d3042014-12-19 14:30:04 +0800709 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800710 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800711 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[2] = dw2;
713 dw[3] = 0; /* scratch */
714 dw[4] = dw4;
715 dw[5] = dw5;
716 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700717 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800718
719 if (fs->per_thread_scratch_size)
720 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721}
722
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800723static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700724 const struct intel_ds_view *view,
725 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800726{
727 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800728 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600729 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800730
731 CMD_ASSERT(cmd, 6, 7.5);
732
733 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800734 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
735 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800736 dw0 |= (cmd_len - 2);
737
Chia-I Wu72292b72014-09-09 10:48:33 +0800738 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
739 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700740
Chia-I Wu72292b72014-09-09 10:48:33 +0800741 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700742 /* note that we only enable HiZ on Gen7+ */
743 if (!optimal_ds)
744 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
745
Chia-I Wu72292b72014-09-09 10:48:33 +0800746 dw[2] = 0;
747 dw[3] = view->cmd[2];
748 dw[4] = view->cmd[3];
749 dw[5] = view->cmd[4];
750 dw[6] = view->cmd[5];
751
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800753 cmd_reserve_reloc(cmd, 1);
754 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
755 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600756 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800757}
758
759static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700760 const struct intel_ds_view *view,
761 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800762{
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;
Chia-I Wu72292b72014-09-09 10:48:33 +0800776
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700777 if (view->has_stencil) {
778 dw[1] = view->cmd[6];
779
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);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700783 } else {
784 dw[1] = 0;
785 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600786 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787}
788
789static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700790 const struct intel_ds_view *view,
791 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792{
793 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800794 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600795 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800796
797 CMD_ASSERT(cmd, 6, 7.5);
798
799 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800800 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
801 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800802 dw0 |= (cmd_len - 2);
803
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
805 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800806
Chia-I Wu73520ac2015-02-19 11:17:45 -0700807 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700808 dw[1] = view->cmd[8];
809
Chia-I Wu72292b72014-09-09 10:48:33 +0800810 cmd_reserve_reloc(cmd, 1);
811 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
812 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700813 } else {
814 dw[1] = 0;
815 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600816 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800817}
818
Chia-I Wuf8231032014-08-25 10:44:45 +0800819static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
820 uint32_t clear_val)
821{
822 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800823 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800824 GEN6_CLEAR_PARAMS_DW0_VALID |
825 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800826 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800827
828 CMD_ASSERT(cmd, 6, 6);
829
Chia-I Wu72292b72014-09-09 10:48:33 +0800830 cmd_batch_pointer(cmd, cmd_len, &dw);
831 dw[0] = dw0;
832 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800833}
834
835static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
836 uint32_t clear_val)
837{
838 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800839 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800840 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800841 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800842
843 CMD_ASSERT(cmd, 7, 7.5);
844
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 cmd_batch_pointer(cmd, cmd_len, &dw);
846 dw[0] = dw0;
847 dw[1] = clear_val;
848 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800849}
850
Chia-I Wu302742d2014-08-22 10:28:29 +0800851static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 uint32_t blend_offset,
853 uint32_t ds_offset,
854 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800855{
856 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800858
859 CMD_ASSERT(cmd, 6, 6);
860
Chia-I Wu426072d2014-08-26 14:31:55 +0800861 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800862 (cmd_len - 2);
863
Chia-I Wu72292b72014-09-09 10:48:33 +0800864 cmd_batch_pointer(cmd, cmd_len, &dw);
865 dw[0] = dw0;
866 dw[1] = blend_offset | 1;
867 dw[2] = ds_offset | 1;
868 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800869}
870
Chia-I Wu1744cca2014-08-22 11:10:17 +0800871static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800872 uint32_t clip_offset,
873 uint32_t sf_offset,
874 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875{
876 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800878
879 CMD_ASSERT(cmd, 6, 6);
880
Chia-I Wu426072d2014-08-26 14:31:55 +0800881 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700882 GEN6_VP_PTR_DW0_CLIP_CHANGED |
883 GEN6_VP_PTR_DW0_SF_CHANGED |
884 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885 (cmd_len - 2);
886
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 cmd_batch_pointer(cmd, cmd_len, &dw);
888 dw[0] = dw0;
889 dw[1] = clip_offset;
890 dw[2] = sf_offset;
891 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892}
893
894static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896{
897 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800899
900 CMD_ASSERT(cmd, 6, 6);
901
Chia-I Wu426072d2014-08-26 14:31:55 +0800902 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800903 (cmd_len - 2);
904
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 cmd_batch_pointer(cmd, cmd_len, &dw);
906 dw[0] = dw0;
907 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800908}
909
Chia-I Wu42a56202014-08-23 16:47:48 +0800910static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800911 uint32_t vs_offset,
912 uint32_t gs_offset,
913 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800914{
915 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800917
918 CMD_ASSERT(cmd, 6, 6);
919
Chia-I Wu426072d2014-08-26 14:31:55 +0800920 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700921 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
922 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
923 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800924 (cmd_len - 2);
925
Chia-I Wu72292b72014-09-09 10:48:33 +0800926 cmd_batch_pointer(cmd, cmd_len, &dw);
927 dw[0] = dw0;
928 dw[1] = vs_offset;
929 dw[2] = gs_offset;
930 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800931}
932
Chia-I Wu257e75e2014-08-29 14:06:35 +0800933static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800934 uint32_t vs_offset,
935 uint32_t gs_offset,
936 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800937{
938 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800940
941 CMD_ASSERT(cmd, 6, 6);
942
943 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700944 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
945 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
946 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800947 (cmd_len - 2);
948
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 cmd_batch_pointer(cmd, cmd_len, &dw);
950 dw[0] = dw0;
951 dw[1] = vs_offset;
952 dw[2] = gs_offset;
953 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800954}
955
Chia-I Wu302742d2014-08-22 10:28:29 +0800956static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800958{
959 const uint8_t cmd_len = 2;
960 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
961 GEN6_RENDER_SUBTYPE_3D |
962 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800964
Chia-I Wu72292b72014-09-09 10:48:33 +0800965 cmd_batch_pointer(cmd, cmd_len, &dw);
966 dw[0] = dw0;
967 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800968}
969
Chia-I Wua6c4f152014-12-02 04:19:58 +0800970static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800971{
Chia-I Wue6073342014-11-30 09:43:42 +0800972 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700973 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
974 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800975
976 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700977 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800978
Tony Barbourfa6cac72015-01-16 14:27:35 -0700979 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800980}
981
Chia-I Wu72292b72014-09-09 10:48:33 +0800982static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700983 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800984{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700985 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800986 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700988 uint32_t dw[3];
989
990 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700991 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700993 (state->ds_info.stencilWriteMask & 0xff) << 16 |
994 (state->ds_info.stencilReadMask & 0xff) << 8 |
995 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700996 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800997
998 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700999
1000 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1001 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001002
Chia-I Wu00b51a82014-09-09 12:07:37 +08001003 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001004 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001005}
1006
Chia-I Wu72292b72014-09-09 10:48:33 +08001007static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001008 uint32_t stencil_ref,
1009 const uint32_t blend_color[4])
1010{
Chia-I Wue6073342014-11-30 09:43:42 +08001011 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001013 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001014
1015 CMD_ASSERT(cmd, 6, 7.5);
1016
Chia-I Wu00b51a82014-09-09 12:07:37 +08001017 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1018 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 dw[0] = stencil_ref;
1020 dw[1] = 0;
1021 dw[2] = blend_color[0];
1022 dw[3] = blend_color[1];
1023 dw[4] = blend_color[2];
1024 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001025
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001027}
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030{
Chia-I Wu8370b402014-08-29 12:28:37 +08001031 CMD_ASSERT(cmd, 6, 7.5);
1032
Chia-I Wu707a29e2014-08-27 12:51:47 +08001033 if (!cmd->bind.draw_count)
1034 return;
1035
Chia-I Wu8370b402014-08-29 12:28:37 +08001036 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001037 return;
1038
Chia-I Wu8370b402014-08-29 12:28:37 +08001039 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001040
1041 /*
1042 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1043 *
1044 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1045 * pipe-control with a post-sync op and no write-cache flushes."
1046 *
1047 * The workaround below necessitates this workaround.
1048 */
1049 gen6_PIPE_CONTROL(cmd,
1050 GEN6_PIPE_CONTROL_CS_STALL |
1051 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001052 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053
Chia-I Wud6d079d2014-08-31 13:14:21 +08001054 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1055 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001056}
1057
Chia-I Wu8370b402014-08-29 12:28:37 +08001058static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001059{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001060 CMD_ASSERT(cmd, 6, 7.5);
1061
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001062 if (!cmd->bind.draw_count)
1063 return;
1064
Chia-I Wud6d079d2014-08-31 13:14:21 +08001065 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1066 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001067}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1070{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001071 CMD_ASSERT(cmd, 7, 7.5);
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073 if (!cmd->bind.draw_count)
1074 return;
1075
1076 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001077
1078 gen6_PIPE_CONTROL(cmd,
1079 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001080 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001081}
1082
Chia-I Wu8370b402014-08-29 12:28:37 +08001083static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1084{
1085 CMD_ASSERT(cmd, 7, 7.5);
1086
Chia-I Wu8370b402014-08-29 12:28:37 +08001087 /*
1088 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1089 *
1090 * "One of the following must also be set (when CS stall is set):
1091 *
1092 * * Render Target Cache Flush Enable ([12] of DW1)
1093 * * Depth Cache Flush Enable ([0] of DW1)
1094 * * Stall at Pixel Scoreboard ([1] of DW1)
1095 * * Depth Stall ([13] of DW1)
1096 * * Post-Sync Operation ([13] of DW1)"
1097 */
1098 gen6_PIPE_CONTROL(cmd,
1099 GEN6_PIPE_CONTROL_CS_STALL |
1100 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001101 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001102}
1103
1104static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1105{
1106 CMD_ASSERT(cmd, 7, 7.5);
1107
Chia-I Wu8370b402014-08-29 12:28:37 +08001108 cmd_wa_gen6_pre_depth_stall_write(cmd);
1109
Chia-I Wud6d079d2014-08-31 13:14:21 +08001110 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001111}
1112
1113static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1114{
1115 CMD_ASSERT(cmd, 6, 7.5);
1116
1117 if (!cmd->bind.draw_count)
1118 return;
1119
1120 /*
1121 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1122 *
1123 * "Driver must guarentee that all the caches in the depth pipe are
1124 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1125 * requires driver to send a PIPE_CONTROL with a CS stall along with
1126 * a Depth Flush prior to this command."
1127 *
1128 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1129 *
1130 * "Driver must ierarchi that all the caches in the depth pipe are
1131 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1132 * requires driver to send a PIPE_CONTROL with a CS stall along with
1133 * a Depth Flush prior to this command.
1134 */
1135 gen6_PIPE_CONTROL(cmd,
1136 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1137 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001138 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001139}
1140
1141static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1142{
1143 CMD_ASSERT(cmd, 6, 7.5);
1144
1145 if (!cmd->bind.draw_count)
1146 return;
1147
1148 /*
1149 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1150 *
1151 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1152 * and a post sync operation prior to the group of depth
1153 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1154 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1155 *
1156 * This workaround satifies all the conditions.
1157 */
1158 cmd_wa_gen6_pre_depth_stall_write(cmd);
1159
1160 /*
1161 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1162 *
1163 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1164 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1165 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1166 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1167 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1168 * Depth Flush Bit set, followed by another pipelined depth stall
1169 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1170 * guarantee that the pipeline from WM onwards is already flushed
1171 * (e.g., via a preceding MI_FLUSH)."
1172 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001173 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1174 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1175 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001176}
1177
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001178void cmd_batch_state_base_address(struct intel_cmd *cmd)
1179{
1180 const uint8_t cmd_len = 10;
1181 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1182 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001183 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001184 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001185 uint32_t pos;
1186 uint32_t *dw;
1187
1188 CMD_ASSERT(cmd, 6, 7.5);
1189
1190 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1191
1192 dw[0] = dw0;
1193 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001194 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001195 dw[2] = 1;
1196 dw[3] = 1;
1197 dw[4] = 1;
1198 dw[5] = 1;
1199 /* end offsets */
1200 dw[6] = 1;
1201 dw[7] = 1 + 0xfffff000;
1202 dw[8] = 1 + 0xfffff000;
1203 dw[9] = 1;
1204
1205 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001206 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1207 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1208 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1209 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1210 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1211 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001212}
1213
Chia-I Wu525c6602014-08-27 10:22:34 +08001214void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1215{
Mike Stroyan552fda42015-01-30 17:21:08 -07001216 if (pipe_control_dw0 == 0)
1217 return;
1218
Chia-I Wu525c6602014-08-27 10:22:34 +08001219 if (!cmd->bind.draw_count)
1220 return;
1221
1222 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1223
Chia-I Wu8370b402014-08-29 12:28:37 +08001224 /*
1225 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1226 *
1227 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1228 * PIPE_CONTROL with any non-zero post-sync-op is required."
1229 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001230 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001231 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001232
Chia-I Wu092279a2014-08-30 19:05:30 +08001233 /*
1234 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1235 *
1236 * "One of the following must also be set (when CS stall is set):
1237 *
1238 * * Render Target Cache Flush Enable ([12] of DW1)
1239 * * Depth Cache Flush Enable ([0] of DW1)
1240 * * Stall at Pixel Scoreboard ([1] of DW1)
1241 * * Depth Stall ([13] of DW1)
1242 * * Post-Sync Operation ([13] of DW1)"
1243 */
1244 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1245 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1246 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1247 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1248 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1249 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1250
Chia-I Wud6d079d2014-08-31 13:14:21 +08001251 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001252}
1253
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001254void cmd_batch_flush_all(struct intel_cmd *cmd)
1255{
1256 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1257 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1258 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1259 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1260 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1261 GEN6_PIPE_CONTROL_CS_STALL);
1262}
1263
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001264void cmd_batch_depth_count(struct intel_cmd *cmd,
1265 struct intel_bo *bo,
1266 XGL_GPU_SIZE offset)
1267{
1268 cmd_wa_gen6_pre_depth_stall_write(cmd);
1269
1270 gen6_PIPE_CONTROL(cmd,
1271 GEN6_PIPE_CONTROL_DEPTH_STALL |
1272 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001273 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001274}
1275
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001276void cmd_batch_timestamp(struct intel_cmd *cmd,
1277 struct intel_bo *bo,
1278 XGL_GPU_SIZE offset)
1279{
1280 /* need any WA or stall? */
1281 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1282}
1283
1284void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001285 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001286 struct intel_bo *bo,
1287 XGL_GPU_SIZE offset,
1288 uint64_t val)
1289{
1290 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001291 gen6_PIPE_CONTROL(cmd,
1292 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1293 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001294}
1295
Chia-I Wu302742d2014-08-22 10:28:29 +08001296static void gen6_cc_states(struct intel_cmd *cmd)
1297{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001298 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1299 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001300 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001301 uint32_t stencil_ref;
1302 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001303
1304 CMD_ASSERT(cmd, 6, 6);
1305
Chia-I Wua6c4f152014-12-02 04:19:58 +08001306 blend_offset = gen6_BLEND_STATE(cmd);
1307
1308 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001309 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001310 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001311 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001312
1313 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001314 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001315 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1316 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001317 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001318 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001319 stencil_ref = 0;
1320 }
1321
Chia-I Wu72292b72014-09-09 10:48:33 +08001322 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001323
Chia-I Wu72292b72014-09-09 10:48:33 +08001324 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001325}
1326
Chia-I Wu1744cca2014-08-22 11:10:17 +08001327static void gen6_viewport_states(struct intel_cmd *cmd)
1328{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001329 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001330 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001331
1332 if (!viewport)
1333 return;
1334
Tony Barbourfa6cac72015-01-16 14:27:35 -07001335 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001336 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001337
1338 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001339 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001340 viewport->cmd);
1341
1342 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001343 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001344 &viewport->cmd[viewport->cmd_clip_pos]);
1345
1346 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001347 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001348 &viewport->cmd[viewport->cmd_cc_pos]);
1349
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001350 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1351 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1352 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001353
1354 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001355 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001356
Chia-I Wub1d450a2014-09-09 13:48:03 +08001357 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001358}
1359
Chia-I Wu302742d2014-08-22 10:28:29 +08001360static void gen7_cc_states(struct intel_cmd *cmd)
1361{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001362 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1363 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001364 uint32_t stencil_ref;
1365 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001366 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001367
1368 CMD_ASSERT(cmd, 7, 7.5);
1369
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001370 if (!blend && !ds)
1371 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001372
Chia-I Wua6c4f152014-12-02 04:19:58 +08001373 offset = gen6_BLEND_STATE(cmd);
1374 gen7_3dstate_pointer(cmd,
1375 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001376
Chia-I Wua6c4f152014-12-02 04:19:58 +08001377 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001378 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001379 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001380 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001381
1382 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001383 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001384 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1385 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001386 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001387 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1388 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001389 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1390 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001391 } else {
1392 stencil_ref = 0;
1393 }
1394
Chia-I Wu72292b72014-09-09 10:48:33 +08001395 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001396 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001397 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001398}
1399
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400static void gen7_viewport_states(struct intel_cmd *cmd)
1401{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001402 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001403 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404
1405 if (!viewport)
1406 return;
1407
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001408 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001409
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001411 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001413 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001414 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1415 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001416
1417 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001418 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001419 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001420 gen7_3dstate_pointer(cmd,
1421 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001422 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001423
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001424 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1425 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1426 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1427 gen7_3dstate_pointer(cmd,
1428 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1429 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001430}
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 Wu97aa4de2015-03-05 15:43:16 -07001473 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001474 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001475 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001476 uint32_t surface_count;
1477 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478
1479 CMD_ASSERT(cmd, 6, 7.5);
1480
Chia-I Wu625105f2014-10-13 15:35:29 +08001481 if (!rmap || !rmap->sampler_count)
1482 return 0;
1483
Cody Northrop40316a32014-12-09 19:08:33 -07001484 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001485
Chia-I Wudcb509d2014-12-10 08:53:10 +08001486 /*
1487 * note that we cannot call cmd_state_pointer() here as the following
1488 * cmd_state_pointer() would invalidate the pointer
1489 */
1490 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001491 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001492 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001493
1494 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001495 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001496 4 * rmap->sampler_count, &sampler_dw);
1497
Chia-I Wudcb509d2014-12-10 08:53:10 +08001498 cmd_state_update(cmd, border_offset,
1499 border_stride * rmap->sampler_count, &border_dw);
1500
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001501 for (i = 0; i < rmap->sampler_count; i++) {
1502 const struct intel_pipeline_rmap_slot *slot =
1503 &rmap->slots[surface_count + i];
1504 const struct intel_sampler *sampler;
1505
Chia-I Wuf8385062015-01-04 16:27:24 +08001506 switch (slot->type) {
1507 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001508 intel_desc_set_read_sampler(set, &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 Wuf98dd882015-02-10 04:17:47 +08001545 const uint32_t sba_offset =
1546 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001547 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001549 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001550
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001551 CMD_ASSERT(cmd, 6, 7.5);
1552
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001553 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001554 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001555 if (!surface_count)
1556 return 0;
1557
Chia-I Wu42a56202014-08-23 16:47:48 +08001558 assert(surface_count <= ARRAY_SIZE(binding_table));
1559
1560 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001561 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001562 struct intel_null_view null_view;
1563 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001564
Chia-I Wuf8385062015-01-04 16:27:24 +08001565 switch (slot->type) {
1566 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001567 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001568 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001569 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1570 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001571
Chia-I Wu787a05b2014-12-05 11:02:20 +08001572 if (view) {
1573 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1574 GEN6_ALIGNMENT_SURFACE_STATE,
1575 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001576
Chia-I Wu787a05b2014-12-05 11:02:20 +08001577 cmd_reserve_reloc(cmd, 1);
1578 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1579 view->cmd[1], INTEL_RELOC_WRITE);
1580 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001581 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001582 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001583 }
1584 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001585 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001586 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001587 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1588 const struct intel_mem *mem;
1589 bool read_only;
1590 const uint32_t *cmd_data;
1591 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001592
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001593 assert(dyn_idx < 0 ||
1594 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001595
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001596 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1597 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001598 if (mem) {
1599 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1600 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1601 const uint32_t reloc_flags =
1602 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001603
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001604 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001605 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001606 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001607
1608 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001609 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1610 cmd_data[1] + dynamic_offset, reloc_flags);
1611 } else {
1612 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001613 }
1614 }
1615 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001616 case INTEL_PIPELINE_RMAP_UNUSED:
1617 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001618 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001619 default:
1620 assert(!"unexpected rmap type");
1621 need_null_view = true;
1622 break;
1623 }
1624
1625 if (need_null_view) {
1626 intel_null_view_init(&null_view, cmd->dev);
1627 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1628 GEN6_ALIGNMENT_SURFACE_STATE,
1629 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001630 }
1631
Chia-I Wuf98dd882015-02-10 04:17:47 +08001632 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001633 }
1634
Chia-I Wuf98dd882015-02-10 04:17:47 +08001635 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001636 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001637 surface_count, binding_table) - sba_offset;
1638
1639 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1640 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1641
1642 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001643}
1644
Chia-I Wu1d125092014-10-08 08:49:38 +08001645static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1646{
1647 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001648 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1649 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001650 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001651
1652 CMD_ASSERT(cmd, 6, 7.5);
1653
1654 if (!pipeline->vb_count)
1655 return;
1656
1657 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1658
1659 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1660 dw++;
1661 pos++;
1662
1663 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001664 assert(pipeline->vb[i].strideInBytes <= 2048);
1665
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001666 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001667 pipeline->vb[i].strideInBytes;
1668
Chia-I Wub3686982015-02-27 09:51:16 -07001669 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001670 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1671 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001672 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001673
1674 switch (pipeline->vb[i].stepRate) {
1675 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001676 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001677 dw[3] = 0;
1678 break;
1679 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001680 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001681 dw[3] = 1;
1682 break;
1683 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001684 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001685 dw[3] = 0;
1686 break;
1687 default:
1688 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001689 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001690 dw[3] = 0;
1691 break;
1692 }
1693
Chia-I Wu714df452015-01-01 07:55:04 +08001694 if (cmd->bind.vertex.buf[i]) {
1695 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001696 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001697
1698 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001699 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1700 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001701 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001702 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001703 dw[1] = 0;
1704 dw[2] = 0;
1705 }
1706
1707 dw += 4;
1708 pos += 4;
1709 }
1710}
1711
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001712static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1713{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001714 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1715 const struct intel_pipeline_shader *vs = &pipeline->vs;
1716 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001717 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001718 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001719 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001720 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001721
1722 CMD_ASSERT(cmd, 6, 7.5);
1723
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001724 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001725 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1726 *
1727 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1728 * 128-bit vertex elements to be passed into the payload for each
1729 * vertex."
1730 *
1731 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1732 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001733 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001734 vue_read_len = (vs->in_count + 1) / 2;
1735 if (!vue_read_len)
1736 vue_read_len = 1;
1737
1738 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1739 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1740
1741 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1742 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1743 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001744
1745 dw5 = GEN6_VS_DW5_STATISTICS |
1746 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001747
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001748 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001749 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001750 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001751 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001752
Chia-I Wube0a3d92014-09-02 13:20:59 +08001753 if (pipeline->disable_vs_cache)
1754 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1755
Chia-I Wu784d3042014-12-19 14:30:04 +08001756 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001757 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001758 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001759 dw[2] = dw2;
1760 dw[3] = 0; /* scratch */
1761 dw[4] = dw4;
1762 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001763
1764 if (vs->per_thread_scratch_size)
1765 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001766}
1767
Chia-I Wu625105f2014-10-13 15:35:29 +08001768static void emit_shader_resources(struct intel_cmd *cmd)
1769{
1770 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001771 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001772
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001773 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001774 cmd->bind.pipeline.graphics->vs.rmap,
1775 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001776 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001777 cmd->bind.pipeline.graphics->tcs.rmap,
1778 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001779 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001780 cmd->bind.pipeline.graphics->tes.rmap,
1781 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001782 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001783 cmd->bind.pipeline.graphics->gs.rmap,
1784 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001785 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001786 cmd->bind.pipeline.graphics->fs.rmap,
1787 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001788
1789 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1790 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1791 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1792 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1793 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1794
1795 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1796 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001797 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1798 binding_tables[0]);
1799 gen7_3dstate_pointer(cmd,
1800 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1801 binding_tables[1]);
1802 gen7_3dstate_pointer(cmd,
1803 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1804 binding_tables[2]);
1805 gen7_3dstate_pointer(cmd,
1806 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1807 binding_tables[3]);
1808 gen7_3dstate_pointer(cmd,
1809 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1810 binding_tables[4]);
1811
1812 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001813 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1814 samplers[0]);
1815 gen7_3dstate_pointer(cmd,
1816 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1817 samplers[1]);
1818 gen7_3dstate_pointer(cmd,
1819 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1820 samplers[2]);
1821 gen7_3dstate_pointer(cmd,
1822 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1823 samplers[3]);
1824 gen7_3dstate_pointer(cmd,
1825 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1826 samplers[4]);
1827 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001828 assert(!binding_tables[1] && !binding_tables[2]);
1829 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1830 binding_tables[0], binding_tables[3], binding_tables[4]);
1831
Chia-I Wu625105f2014-10-13 15:35:29 +08001832 assert(!samplers[1] && !samplers[2]);
1833 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1834 samplers[0], samplers[3], samplers[4]);
1835 }
1836}
1837
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001838static void emit_rt(struct intel_cmd *cmd)
1839{
1840 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001841 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1842 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001843}
1844
1845static void emit_ds(struct intel_cmd *cmd)
1846{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001847 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1848 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001849
1850 if (!ds) {
1851 /* all zeros */
1852 static const struct intel_ds_view null_ds;
1853 ds = &null_ds;
1854 }
1855
1856 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001857 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1858 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1859 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001860
1861 if (cmd_gen(cmd) >= INTEL_GEN(7))
1862 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1863 else
1864 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1865}
1866
Chia-I Wua57761b2014-10-14 14:27:44 +08001867static uint32_t emit_shader(struct intel_cmd *cmd,
1868 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001869{
Chia-I Wua57761b2014-10-14 14:27:44 +08001870 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1871 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001872 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001873
Chia-I Wua57761b2014-10-14 14:27:44 +08001874 /* see if the shader is already in the cache */
1875 for (i = 0; i < cache->used; i++) {
1876 if (cache->entries[i].shader == (const void *) shader)
1877 return cache->entries[i].kernel_offset;
1878 }
1879
1880 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1881
1882 /* grow the cache if full */
1883 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001884 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001885 void *entries;
1886
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08001887 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Chia-I Wua57761b2014-10-14 14:27:44 +08001888 XGL_SYSTEM_ALLOC_INTERNAL);
1889 if (entries) {
1890 if (cache->entries) {
1891 memcpy(entries, cache->entries,
1892 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08001893 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08001894 }
1895
1896 cache->entries = entries;
1897 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001898 }
1899 }
1900
Chia-I Wua57761b2014-10-14 14:27:44 +08001901 /* add the shader to the cache */
1902 if (cache->used < cache->count) {
1903 cache->entries[cache->used].shader = (const void *) shader;
1904 cache->entries[cache->used].kernel_offset = offset;
1905 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001906 }
1907
Chia-I Wua57761b2014-10-14 14:27:44 +08001908 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001909}
1910
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001911static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001912{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001913 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001914
Chia-I Wu8370b402014-08-29 12:28:37 +08001915 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1916 cmd_wa_gen6_pre_depth_stall_write(cmd);
1917 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1918 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1919 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1920 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001921
1922 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001923 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001924 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001925
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001926 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001927 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001928 }
1929 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001930 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001931 }
1932 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001933 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1934 }
1935 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1936 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1937 }
1938 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1939 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001940 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001941
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001942 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1943 gen7_3DSTATE_GS(cmd);
1944 } else {
1945 gen6_3DSTATE_GS(cmd);
1946 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001947
Chia-I Wu8370b402014-08-29 12:28:37 +08001948 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1949 cmd_wa_gen7_post_command_cs_stall(cmd);
1950 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1951 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001952}
1953
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001954static void emit_bounded_states(struct intel_cmd *cmd)
1955{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001956
1957 emit_graphics_pipeline(cmd);
1958
1959 emit_rt(cmd);
1960 emit_ds(cmd);
1961
1962 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1963 gen7_cc_states(cmd);
1964 gen7_viewport_states(cmd);
1965
1966 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1967 &cmd->bind.pipeline.graphics->vs);
1968 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1969 &cmd->bind.pipeline.graphics->fs);
1970
1971 gen6_3DSTATE_CLIP(cmd);
1972 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001973 gen7_3DSTATE_WM(cmd);
1974 gen7_3DSTATE_PS(cmd);
1975 } else {
1976 gen6_cc_states(cmd);
1977 gen6_viewport_states(cmd);
1978
1979 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1980 &cmd->bind.pipeline.graphics->vs);
1981 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1982 &cmd->bind.pipeline.graphics->fs);
1983
1984 gen6_3DSTATE_CLIP(cmd);
1985 gen6_3DSTATE_SF(cmd);
1986 gen6_3DSTATE_WM(cmd);
1987 }
1988
1989 emit_shader_resources(cmd);
1990
1991 cmd_wa_gen6_pre_depth_stall_write(cmd);
1992 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1993
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001994 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1995 gen6_3DSTATE_VS(cmd);
1996}
1997
Tony Barbourfa6cac72015-01-16 14:27:35 -07001998static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07001999 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002000{
2001 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2002 const uint8_t cmd_len = 3;
2003 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002004
2005 CMD_ASSERT(cmd, 6, 7.5);
2006
Tony Barbourfa6cac72015-01-16 14:27:35 -07002007 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002008 dw[0] = 0;
2009 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002010
2011 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2012 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2013 GEN6_COMPAREFUNCTION_NEVER << 27 |
2014 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2015 } else {
2016 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2017 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2018 }
Chia-I Wud850a392015-02-19 11:08:25 -07002019 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2020 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002021 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2022 (GEN6_STENCILOP_KEEP) << 25 |
2023 (GEN6_STENCILOP_KEEP) << 22 |
2024 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002025 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2026 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002027 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2028 (GEN6_STENCILOP_KEEP) << 9 |
2029 (GEN6_STENCILOP_KEEP) << 6 |
2030 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002031
Chia-I Wud850a392015-02-19 11:08:25 -07002032 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2033 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2034 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2035 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2036 dw[2] = 0;
2037 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002038
2039 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2040 cmd_align, cmd_len, dw);
2041}
2042
Chia-I Wu6032b892014-10-17 14:47:18 +08002043static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2044{
2045 const struct intel_cmd_meta *meta = cmd->bind.meta;
2046 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2047
2048 CMD_ASSERT(cmd, 6, 7.5);
2049
2050 blend_offset = 0;
2051 ds_offset = 0;
2052 cc_offset = 0;
2053 cc_vp_offset = 0;
2054
Chia-I Wu29e6f502014-11-24 14:27:29 +08002055 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002056 /* BLEND_STATE */
2057 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002058 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002059 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002060 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002061 }
2062
Chia-I Wu29e6f502014-11-24 14:27:29 +08002063 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002064 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002065 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002066 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2067 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002068
Chia-I Wu29e6f502014-11-24 14:27:29 +08002069 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002070 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002071
Chia-I Wu29e6f502014-11-24 14:27:29 +08002072 /* COLOR_CALC_STATE */
2073 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002074 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002075
Chia-I Wu29e6f502014-11-24 14:27:29 +08002076 /* CC_VIEWPORT */
2077 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002078 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002079 dw[0] = u_fui(0.0f);
2080 dw[1] = u_fui(1.0f);
2081 } else {
2082 /* DEPTH_STENCIL_STATE */
2083 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002084 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002085 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2086 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2087 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002088 }
2089
2090 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2091 gen7_3dstate_pointer(cmd,
2092 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2093 blend_offset);
2094 gen7_3dstate_pointer(cmd,
2095 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2096 ds_offset);
2097 gen7_3dstate_pointer(cmd,
2098 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2099
2100 gen7_3dstate_pointer(cmd,
2101 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2102 cc_vp_offset);
2103 } else {
2104 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002105 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002106
2107 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2108 cmd_batch_pointer(cmd, 4, &dw);
2109 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002110 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002111 dw[1] = 0;
2112 dw[2] = 0;
2113 dw[3] = cc_vp_offset;
2114 }
2115}
2116
2117static void gen6_meta_surface_states(struct intel_cmd *cmd)
2118{
2119 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002120 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002121 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002122 const uint32_t sba_offset =
2123 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002124
2125 CMD_ASSERT(cmd, 6, 7.5);
2126
Chia-I Wu29e6f502014-11-24 14:27:29 +08002127 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2128 return;
2129
Chia-I Wu005c47c2014-10-22 13:49:13 +08002130 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002131 if (meta->src.valid) {
2132 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002133 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002134 meta->src.surface_len, meta->src.surface);
2135
2136 cmd_reserve_reloc(cmd, 1);
2137 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2138 cmd_surface_reloc_writer(cmd, offset, 1,
2139 meta->src.reloc_target, meta->src.reloc_offset);
2140 } else {
2141 cmd_surface_reloc(cmd, offset, 1,
2142 (struct intel_bo *) meta->src.reloc_target,
2143 meta->src.reloc_offset, meta->src.reloc_flags);
2144 }
2145
Mike Stroyan9bfad482015-02-10 15:09:23 -07002146 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002147 }
2148 if (meta->dst.valid) {
2149 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002150 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002151 meta->dst.surface_len, meta->dst.surface);
2152
2153 cmd_reserve_reloc(cmd, 1);
2154 cmd_surface_reloc(cmd, offset, 1,
2155 (struct intel_bo *) meta->dst.reloc_target,
2156 meta->dst.reloc_offset, meta->dst.reloc_flags);
2157
Mike Stroyan9bfad482015-02-10 15:09:23 -07002158 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002159 }
2160
2161 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002162 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002163 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002164 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002165
2166 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002167 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2168 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2169 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002170 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002171 } else {
2172 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002173 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002174 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002175 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002176 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002177 }
2178}
2179
2180static void gen6_meta_urb(struct intel_cmd *cmd)
2181{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002182 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002183 uint32_t *dw;
2184
2185 CMD_ASSERT(cmd, 6, 6);
2186
2187 /* 3DSTATE_URB */
2188 cmd_batch_pointer(cmd, 3, &dw);
2189 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002190 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002191 dw[2] = 0;
2192}
2193
2194static void gen7_meta_urb(struct intel_cmd *cmd)
2195{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002196 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2197 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002198 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002199 uint32_t *dw;
2200
2201 CMD_ASSERT(cmd, 7, 7.5);
2202
2203 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2204 cmd_batch_pointer(cmd, 10, &dw);
2205
2206 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002207 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
Chia-I Wu15dacac2015-02-05 11:14:01 -07002208 dw += 2;
2209
2210 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002211 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
2212 pcb_alloc << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002213 dw += 2;
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2216 dw[1] = 0;
2217 dw += 2;
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2220 dw[1] = 0;
2221 dw += 2;
2222
2223 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2224 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002225
Chia-I Wu15dacac2015-02-05 11:14:01 -07002226 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002227
2228 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2229
Chia-I Wu24aa1022014-11-25 11:53:19 +08002230 switch (cmd_gen(cmd)) {
2231 case INTEL_GEN(7.5):
2232 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2233 break;
2234 case INTEL_GEN(7):
2235 default:
2236 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2237 break;
2238 }
2239
Chia-I Wu6032b892014-10-17 14:47:18 +08002240 /* 3DSTATE_URB_x */
2241 cmd_batch_pointer(cmd, 8, &dw);
2242
2243 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002244 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002245 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002246 dw += 2;
2247
2248 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002249 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002250 dw += 2;
2251
2252 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002253 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002254 dw += 2;
2255
2256 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002257 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002258 dw += 2;
2259}
2260
2261static void gen6_meta_vf(struct intel_cmd *cmd)
2262{
2263 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002264 uint32_t vb_start, vb_end, vb_stride;
2265 int ve_format, ve_z_source;
2266 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002267 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002268
2269 CMD_ASSERT(cmd, 6, 7.5);
2270
Chia-I Wu29e6f502014-11-24 14:27:29 +08002271 switch (meta->mode) {
2272 case INTEL_CMD_META_VS_POINTS:
2273 cmd_batch_pointer(cmd, 3, &dw);
2274 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002275 dw[1] = GEN6_VE_DW0_VALID;
2276 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2277 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2278 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2279 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002280 return;
2281 break;
2282 case INTEL_CMD_META_FS_RECT:
2283 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002284 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vertices[0][0] = meta->dst.x + meta->width;
2287 vertices[0][1] = meta->dst.y + meta->height;
2288 vertices[1][0] = meta->dst.x;
2289 vertices[1][1] = meta->dst.y + meta->height;
2290 vertices[2][0] = meta->dst.x;
2291 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002292
Chia-I Wu29e6f502014-11-24 14:27:29 +08002293 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2294 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002295
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 vb_end = vb_start + sizeof(vertices) - 1;
2297 vb_stride = sizeof(vertices[0]);
2298 ve_z_source = GEN6_VFCOMP_STORE_0;
2299 ve_format = GEN6_FORMAT_R32G32_USCALED;
2300 }
2301 break;
2302 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2303 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002304 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002306 vertices[0][0] = (float) (meta->dst.x + meta->width);
2307 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002308 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002309 vertices[1][0] = (float) meta->dst.x;
2310 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002311 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002312 vertices[2][0] = (float) meta->dst.x;
2313 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002314 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002315
Chia-I Wu29e6f502014-11-24 14:27:29 +08002316 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2317 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002318
Chia-I Wu29e6f502014-11-24 14:27:29 +08002319 vb_end = vb_start + sizeof(vertices) - 1;
2320 vb_stride = sizeof(vertices[0]);
2321 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2322 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2323 }
2324 break;
2325 default:
2326 assert(!"unknown meta mode");
2327 return;
2328 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002329 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002330
2331 /* 3DSTATE_VERTEX_BUFFERS */
2332 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333
Chia-I Wu6032b892014-10-17 14:47:18 +08002334 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002335 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002336 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002337 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002338
2339 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002340 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2341 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002342
2343 dw[4] = 0;
2344
2345 /* 3DSTATE_VERTEX_ELEMENTS */
2346 cmd_batch_pointer(cmd, 5, &dw);
2347 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002348 dw[1] = GEN6_VE_DW0_VALID;
2349 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2350 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2351 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2352 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2353 dw[3] = GEN6_VE_DW0_VALID |
2354 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2355 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2356 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2357 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2358 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002359}
2360
Chia-I Wu29e6f502014-11-24 14:27:29 +08002361static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002362{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002363 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002364 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002365 uint32_t consts[8];
2366 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367
2368 CMD_ASSERT(cmd, 6, 7.5);
2369
2370 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002371 case INTEL_DEV_META_VS_FILL_MEM:
2372 consts[0] = meta->dst.x;
2373 consts[1] = meta->clear_val[0];
2374 const_count = 2;
2375 break;
2376 case INTEL_DEV_META_VS_COPY_MEM:
2377 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2378 consts[0] = meta->dst.x;
2379 consts[1] = meta->src.x;
2380 const_count = 2;
2381 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002382 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2383 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2384 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2385 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2386 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2387 consts[0] = meta->src.x;
2388 consts[1] = meta->src.y;
2389 consts[2] = meta->width;
2390 consts[3] = meta->dst.x;
2391 const_count = 4;
2392 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002393 default:
2394 assert(!"unknown meta shader id");
2395 const_count = 0;
2396 break;
2397 }
2398
2399 /* this can be skipped but it makes state dumping prettier */
2400 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2401
2402 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2403}
2404
2405static void gen6_meta_vs(struct intel_cmd *cmd)
2406{
2407 const struct intel_cmd_meta *meta = cmd->bind.meta;
2408 const struct intel_pipeline_shader *sh =
2409 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2410 uint32_t offset, *dw;
2411
2412 CMD_ASSERT(cmd, 6, 7.5);
2413
2414 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002415 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002416
2417 /* 3DSTATE_CONSTANT_VS */
2418 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2419 cmd_batch_pointer(cmd, cmd_len, &dw);
2420 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2421 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2422
2423 /* 3DSTATE_VS */
2424 cmd_batch_pointer(cmd, 6, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2426 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2427
2428 return;
2429 }
2430
2431 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2432
2433 /* 3DSTATE_CONSTANT_VS */
2434 offset = gen6_meta_vs_constants(cmd);
2435 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2436 cmd_batch_pointer(cmd, 7, &dw);
2437 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002438 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002439 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002440 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002441 dw[4] = 0;
2442 dw[5] = 0;
2443 dw[6] = 0;
2444 } else {
2445 cmd_batch_pointer(cmd, 5, &dw);
2446 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002447 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002448 dw[1] = offset;
2449 dw[2] = 0;
2450 dw[3] = 0;
2451 dw[4] = 0;
2452 }
2453
2454 /* 3DSTATE_VS */
2455 offset = emit_shader(cmd, sh);
2456 cmd_batch_pointer(cmd, 6, &dw);
2457 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2458 dw[1] = offset;
2459 dw[2] = GEN6_THREADDISP_SPF |
2460 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2461 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002462 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002463 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2464 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2465
2466 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2467 GEN6_VS_DW5_VS_ENABLE;
2468 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002469 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002470 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002471 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002472
2473 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002474}
2475
2476static void gen6_meta_disabled(struct intel_cmd *cmd)
2477{
Chia-I Wu6032b892014-10-17 14:47:18 +08002478 uint32_t *dw;
2479
2480 CMD_ASSERT(cmd, 6, 6);
2481
Chia-I Wu6032b892014-10-17 14:47:18 +08002482 /* 3DSTATE_CONSTANT_GS */
2483 cmd_batch_pointer(cmd, 5, &dw);
2484 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2485 dw[1] = 0;
2486 dw[2] = 0;
2487 dw[3] = 0;
2488 dw[4] = 0;
2489
2490 /* 3DSTATE_GS */
2491 cmd_batch_pointer(cmd, 7, &dw);
2492 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2493 dw[1] = 0;
2494 dw[2] = 0;
2495 dw[3] = 0;
2496 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2497 dw[5] = GEN6_GS_DW5_STATISTICS;
2498 dw[6] = 0;
2499
Chia-I Wu6032b892014-10-17 14:47:18 +08002500 /* 3DSTATE_SF */
2501 cmd_batch_pointer(cmd, 20, &dw);
2502 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2503 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2504 memset(&dw[2], 0, 18 * sizeof(*dw));
2505}
2506
2507static void gen7_meta_disabled(struct intel_cmd *cmd)
2508{
2509 uint32_t *dw;
2510
2511 CMD_ASSERT(cmd, 7, 7.5);
2512
Chia-I Wu6032b892014-10-17 14:47:18 +08002513 /* 3DSTATE_CONSTANT_HS */
2514 cmd_batch_pointer(cmd, 7, &dw);
2515 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2516 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2517
2518 /* 3DSTATE_HS */
2519 cmd_batch_pointer(cmd, 7, &dw);
2520 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2522
2523 /* 3DSTATE_TE */
2524 cmd_batch_pointer(cmd, 4, &dw);
2525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2526 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2527
2528 /* 3DSTATE_CONSTANT_DS */
2529 cmd_batch_pointer(cmd, 7, &dw);
2530 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2531 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2532
2533 /* 3DSTATE_DS */
2534 cmd_batch_pointer(cmd, 6, &dw);
2535 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2536 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2537
2538 /* 3DSTATE_CONSTANT_GS */
2539 cmd_batch_pointer(cmd, 7, &dw);
2540 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2541 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2542
2543 /* 3DSTATE_GS */
2544 cmd_batch_pointer(cmd, 7, &dw);
2545 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2546 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2547
2548 /* 3DSTATE_STREAMOUT */
2549 cmd_batch_pointer(cmd, 3, &dw);
2550 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2551 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2552
Chia-I Wu6032b892014-10-17 14:47:18 +08002553 /* 3DSTATE_SF */
2554 cmd_batch_pointer(cmd, 7, &dw);
2555 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2556 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2557
2558 /* 3DSTATE_SBE */
2559 cmd_batch_pointer(cmd, 14, &dw);
2560 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2561 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2562 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002564
Chia-I Wu29e6f502014-11-24 14:27:29 +08002565static void gen6_meta_clip(struct intel_cmd *cmd)
2566{
2567 const struct intel_cmd_meta *meta = cmd->bind.meta;
2568 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002569
Chia-I Wu29e6f502014-11-24 14:27:29 +08002570 /* 3DSTATE_CLIP */
2571 cmd_batch_pointer(cmd, 4, &dw);
2572 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2573 dw[1] = 0;
2574 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2575 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2576 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2577 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002578 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002579 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002580 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002581}
2582
2583static void gen6_meta_wm(struct intel_cmd *cmd)
2584{
2585 const struct intel_cmd_meta *meta = cmd->bind.meta;
2586 uint32_t *dw;
2587
2588 CMD_ASSERT(cmd, 6, 7.5);
2589
2590 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2591
2592 /* 3DSTATE_MULTISAMPLE */
2593 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2594 cmd_batch_pointer(cmd, 4, &dw);
2595 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2596 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2597 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2598 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2599 dw[2] = 0;
2600 dw[3] = 0;
2601 } else {
2602 cmd_batch_pointer(cmd, 3, &dw);
2603 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2604 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2605 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2606 dw[2] = 0;
2607 }
2608
2609 /* 3DSTATE_SAMPLE_MASK */
2610 cmd_batch_pointer(cmd, 2, &dw);
2611 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2612 dw[1] = (1 << meta->samples) - 1;
2613
2614 /* 3DSTATE_DRAWING_RECTANGLE */
2615 cmd_batch_pointer(cmd, 4, &dw);
2616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002617 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2618 /* unused */
2619 dw[1] = 0;
2620 dw[2] = 0;
2621 } else {
2622 dw[1] = meta->dst.y << 16 | meta->dst.x;
2623 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2624 (meta->dst.x + meta->width - 1);
2625 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002626 dw[3] = 0;
2627}
2628
2629static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2630{
2631 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002632 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002633 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002634 uint32_t consts[8];
2635 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002636
2637 CMD_ASSERT(cmd, 6, 7.5);
2638
2639 /* underflow is fine here */
2640 offset_x = meta->src.x - meta->dst.x;
2641 offset_y = meta->src.y - meta->dst.y;
2642
2643 switch (meta->shader_id) {
2644 case INTEL_DEV_META_FS_COPY_MEM:
2645 case INTEL_DEV_META_FS_COPY_1D:
2646 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2647 case INTEL_DEV_META_FS_COPY_2D:
2648 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2649 case INTEL_DEV_META_FS_COPY_2D_MS:
2650 consts[0] = offset_x;
2651 consts[1] = offset_y;
2652 consts[2] = meta->src.layer;
2653 consts[3] = meta->src.lod;
2654 const_count = 4;
2655 break;
2656 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2657 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2658 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2659 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2660 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2661 consts[0] = offset_x;
2662 consts[1] = offset_y;
2663 consts[2] = meta->src.layer;
2664 consts[3] = meta->src.lod;
2665 consts[4] = meta->src.x;
2666 consts[5] = meta->width;
2667 const_count = 6;
2668 break;
2669 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2670 consts[0] = offset_x;
2671 consts[1] = offset_y;
2672 consts[2] = meta->width;
2673 const_count = 3;
2674 break;
2675 case INTEL_DEV_META_FS_CLEAR_COLOR:
2676 consts[0] = meta->clear_val[0];
2677 consts[1] = meta->clear_val[1];
2678 consts[2] = meta->clear_val[2];
2679 consts[3] = meta->clear_val[3];
2680 const_count = 4;
2681 break;
2682 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2683 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002684 consts[1] = meta->clear_val[1];
2685 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002686 break;
2687 case INTEL_DEV_META_FS_RESOLVE_2X:
2688 case INTEL_DEV_META_FS_RESOLVE_4X:
2689 case INTEL_DEV_META_FS_RESOLVE_8X:
2690 case INTEL_DEV_META_FS_RESOLVE_16X:
2691 consts[0] = offset_x;
2692 consts[1] = offset_y;
2693 const_count = 2;
2694 break;
2695 default:
2696 assert(!"unknown meta shader id");
2697 const_count = 0;
2698 break;
2699 }
2700
2701 /* this can be skipped but it makes state dumping prettier */
2702 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2703
2704 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2705}
2706
2707static void gen6_meta_ps(struct intel_cmd *cmd)
2708{
2709 const struct intel_cmd_meta *meta = cmd->bind.meta;
2710 const struct intel_pipeline_shader *sh =
2711 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2712 uint32_t offset, *dw;
2713
2714 CMD_ASSERT(cmd, 6, 6);
2715
Chia-I Wu29e6f502014-11-24 14:27:29 +08002716 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2717 /* 3DSTATE_CONSTANT_PS */
2718 cmd_batch_pointer(cmd, 5, &dw);
2719 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2720 dw[1] = 0;
2721 dw[2] = 0;
2722 dw[3] = 0;
2723 dw[4] = 0;
2724
2725 /* 3DSTATE_WM */
2726 cmd_batch_pointer(cmd, 9, &dw);
2727 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2728 dw[1] = 0;
2729 dw[2] = 0;
2730 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002731
2732 switch (meta->ds.op) {
2733 case INTEL_CMD_META_DS_HIZ_CLEAR:
2734 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2735 break;
2736 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2737 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2738 break;
2739 case INTEL_CMD_META_DS_RESOLVE:
2740 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2741 break;
2742 default:
2743 dw[4] = 0;
2744 break;
2745 }
2746
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002747 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002748 dw[6] = 0;
2749 dw[7] = 0;
2750 dw[8] = 0;
2751
Chia-I Wu3adf7212014-10-24 15:34:07 +08002752 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002753 }
2754
Chia-I Wu3adf7212014-10-24 15:34:07 +08002755 /* a normal color write */
2756 assert(meta->dst.valid && !sh->uses);
2757
Chia-I Wu6032b892014-10-17 14:47:18 +08002758 /* 3DSTATE_CONSTANT_PS */
2759 offset = gen6_meta_ps_constants(cmd);
2760 cmd_batch_pointer(cmd, 5, &dw);
2761 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002762 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002763 dw[1] = offset;
2764 dw[2] = 0;
2765 dw[3] = 0;
2766 dw[4] = 0;
2767
2768 /* 3DSTATE_WM */
2769 offset = emit_shader(cmd, sh);
2770 cmd_batch_pointer(cmd, 9, &dw);
2771 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2772 dw[1] = offset;
2773 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2774 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002775 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002776 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002777 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002778 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2779 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002780
Chia-I Wu6032b892014-10-17 14:47:18 +08002781 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002782 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002783 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2784 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2785 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2786 if (meta->samples > 1) {
2787 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2788 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2789 } else {
2790 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2791 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2792 }
2793 dw[7] = 0;
2794 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002795
2796 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002797}
2798
2799static void gen7_meta_ps(struct intel_cmd *cmd)
2800{
2801 const struct intel_cmd_meta *meta = cmd->bind.meta;
2802 const struct intel_pipeline_shader *sh =
2803 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2804 uint32_t offset, *dw;
2805
2806 CMD_ASSERT(cmd, 7, 7.5);
2807
Chia-I Wu29e6f502014-11-24 14:27:29 +08002808 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2809 /* 3DSTATE_WM */
2810 cmd_batch_pointer(cmd, 3, &dw);
2811 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002812
2813 switch (meta->ds.op) {
2814 case INTEL_CMD_META_DS_HIZ_CLEAR:
2815 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2816 break;
2817 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2818 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2819 break;
2820 case INTEL_CMD_META_DS_RESOLVE:
2821 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2822 break;
2823 default:
2824 dw[1] = 0;
2825 break;
2826 }
2827
2828 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002829
2830 /* 3DSTATE_CONSTANT_GS */
2831 cmd_batch_pointer(cmd, 7, &dw);
2832 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2833 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2834
2835 /* 3DSTATE_PS */
2836 cmd_batch_pointer(cmd, 8, &dw);
2837 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2838 dw[1] = 0;
2839 dw[2] = 0;
2840 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002841 /* required to avoid hangs */
2842 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002843 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002844 dw[5] = 0;
2845 dw[6] = 0;
2846 dw[7] = 0;
2847
Chia-I Wu3adf7212014-10-24 15:34:07 +08002848 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002849 }
2850
Chia-I Wu3adf7212014-10-24 15:34:07 +08002851 /* a normal color write */
2852 assert(meta->dst.valid && !sh->uses);
2853
Chia-I Wu6032b892014-10-17 14:47:18 +08002854 /* 3DSTATE_WM */
2855 cmd_batch_pointer(cmd, 3, &dw);
2856 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002857 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002858 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2859 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2860 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2861 dw[2] = 0;
2862
2863 /* 3DSTATE_CONSTANT_PS */
2864 offset = gen6_meta_ps_constants(cmd);
2865 cmd_batch_pointer(cmd, 7, &dw);
2866 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002867 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002868 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002869 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002870 dw[4] = 0;
2871 dw[5] = 0;
2872 dw[6] = 0;
2873
2874 /* 3DSTATE_PS */
2875 offset = emit_shader(cmd, sh);
2876 cmd_batch_pointer(cmd, 8, &dw);
2877 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2878 dw[1] = offset;
2879 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2880 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002881 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002882
2883 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2884 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002885 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002886
2887 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002888 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002889 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002890 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002891 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002892 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002893
2894 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2895 dw[6] = 0;
2896 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002897
2898 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002899}
2900
2901static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2902{
2903 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002904 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002905
2906 CMD_ASSERT(cmd, 6, 7.5);
2907
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002908 if (!ds) {
2909 /* all zeros */
2910 static const struct intel_ds_view null_ds;
2911 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002912 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002913
2914 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002915 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
2916 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
2917 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002918
2919 if (cmd_gen(cmd) >= INTEL_GEN(7))
2920 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2921 else
2922 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002923}
2924
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002925static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2926 const struct intel_pipeline *pipeline)
2927{
2928 cmd->bind.pipeline.graphics = pipeline;
2929}
2930
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002931static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2932 const struct intel_pipeline *pipeline)
2933{
2934 cmd->bind.pipeline.compute = pipeline;
2935}
2936
2937static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2938 const struct intel_pipeline_delta *delta)
2939{
2940 cmd->bind.pipeline.graphics_delta = delta;
2941}
2942
2943static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2944 const struct intel_pipeline_delta *delta)
2945{
2946 cmd->bind.pipeline.compute_delta = delta;
2947}
2948
2949static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002950 const struct intel_desc_set *dset,
2951 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952{
Chia-I Wuf8385062015-01-04 16:27:24 +08002953 const uint32_t size = sizeof(*dynamic_offsets) *
2954 dset->layout->dynamic_desc_count;
2955
2956 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2957 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002958 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08002959
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002960 cmd->bind.dset.graphics_dynamic_offsets = intel_alloc(cmd,
2961 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08002962 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002963 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002964 return;
2965 }
2966
2967 cmd->bind.dset.graphics_dynamic_offset_size = size;
2968 }
2969
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002970 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002971 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002972}
2973
2974static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002975 const struct intel_desc_set *dset,
2976 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002977{
Chia-I Wuf8385062015-01-04 16:27:24 +08002978 const uint32_t size = sizeof(*dynamic_offsets) *
2979 dset->layout->dynamic_desc_count;
2980
2981 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2982 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002983 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08002984
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002985 cmd->bind.dset.compute_dynamic_offsets = intel_alloc(cmd,
2986 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08002987 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002988 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002989 return;
2990 }
2991
2992 cmd->bind.dset.compute_dynamic_offset_size = size;
2993 }
2994
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002995 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002996 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997}
2998
Chia-I Wu3b04af52014-11-08 10:48:20 +08002999static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003000 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003001 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003002{
Chia-I Wu714df452015-01-01 07:55:04 +08003003 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003004 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003005 return;
3006 }
3007
Chia-I Wu714df452015-01-01 07:55:04 +08003008 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003009 cmd->bind.vertex.offset[binding] = offset;
3010}
3011
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003012static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003013 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003014 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3015{
Chia-I Wu714df452015-01-01 07:55:04 +08003016 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003017 cmd->bind.index.offset = offset;
3018 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003019}
3020
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003021static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003022 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003023{
3024 cmd->bind.state.viewport = state;
3025}
3026
3027static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003028 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003029{
3030 cmd->bind.state.raster = state;
3031}
3032
3033static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003034 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003035{
3036 cmd->bind.state.ds = state;
3037}
3038
3039static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003040 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003041{
3042 cmd->bind.state.blend = state;
3043}
3044
Chia-I Wuf98dd882015-02-10 04:17:47 +08003045static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3046{
3047 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3048 struct intel_pipeline_rmap *rmaps[5] = {
3049 pipeline->vs.rmap,
3050 pipeline->tcs.rmap,
3051 pipeline->tes.rmap,
3052 pipeline->gs.rmap,
3053 pipeline->fs.rmap,
3054 };
3055 uint32_t max_write;
3056 int i;
3057
3058 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3059 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3060 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3061
3062 /* pad first */
3063 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3064
3065 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3066 const struct intel_pipeline_rmap *rmap = rmaps[i];
3067 const uint32_t surface_count = (rmap) ?
3068 rmap->rt_count + rmap->texture_resource_count +
3069 rmap->resource_count + rmap->uav_count : 0;
3070
3071 if (surface_count) {
3072 /* SURFACE_STATEs */
3073 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3074
3075 /* BINDING_TABLE_STATE */
3076 max_write += u_align(sizeof(uint32_t) * surface_count,
3077 GEN6_ALIGNMENT_SURFACE_STATE);
3078 }
3079 }
3080
3081 return max_write;
3082}
3083
3084static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3085{
3086 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3087 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3088 uint32_t max_surface_write;
3089
3090 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3091 if (cmd->bind.meta)
3092 max_surface_write = 64 * sizeof(uint32_t);
3093 else
3094 max_surface_write = cmd_get_max_surface_write(cmd);
3095
3096 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3097 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3098 /* SBA expects page-aligned addresses */
3099 writer->sba_offset = writer->used & ~0xfff;
3100
3101 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3102
3103 cmd_batch_state_base_address(cmd);
3104 }
3105}
3106
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003108 uint32_t vertex_start,
3109 uint32_t vertex_count,
3110 uint32_t instance_start,
3111 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003112 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003113 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114{
3115 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003116 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003117 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3118
3119 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003120
3121 emit_bounded_states(cmd);
3122
Chia-I Wuf98dd882015-02-10 04:17:47 +08003123 /* sanity check on cmd_get_max_surface_write() */
3124 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3125 surface_writer_used <= cmd_get_max_surface_write(cmd));
3126
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127 if (indexed) {
3128 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003129 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003130
3131 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3132 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3133 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003134 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003135 cmd->bind.index.offset, cmd->bind.index.type,
3136 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003137 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003138 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003139 cmd->bind.index.offset, cmd->bind.index.type,
3140 p->primitive_restart);
3141 }
3142 } else {
3143 assert(!vertex_base);
3144 }
3145
3146 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3147 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3148 vertex_start, instance_count, instance_start, vertex_base);
3149 } else {
3150 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3151 vertex_start, instance_count, instance_start, vertex_base);
3152 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003153
Chia-I Wu707a29e2014-08-27 12:51:47 +08003154 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003155 /* need to re-emit all workarounds */
3156 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003157
3158 if (intel_debug & INTEL_DEBUG_NOCACHE)
3159 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003160}
3161
Chia-I Wuc14d1562014-10-17 09:49:22 +08003162void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3163{
Chia-I Wu6032b892014-10-17 14:47:18 +08003164 cmd->bind.meta = meta;
3165
Chia-I Wuf98dd882015-02-10 04:17:47 +08003166 cmd_adjust_state_base_address(cmd);
3167
Chia-I Wu6032b892014-10-17 14:47:18 +08003168 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003169 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003170
3171 gen6_meta_dynamic_states(cmd);
3172 gen6_meta_surface_states(cmd);
3173
3174 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3175 gen7_meta_urb(cmd);
3176 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003177 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003178 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003179 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003180 gen6_meta_wm(cmd);
3181 gen7_meta_ps(cmd);
3182 gen6_meta_depth_buffer(cmd);
3183
3184 cmd_wa_gen7_post_command_cs_stall(cmd);
3185 cmd_wa_gen7_post_command_depth_stall(cmd);
3186
Chia-I Wu29e6f502014-11-24 14:27:29 +08003187 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3188 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003189 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003190 } else {
3191 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3192 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003193 } else {
3194 gen6_meta_urb(cmd);
3195 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003196 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003197 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003198 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003199 gen6_meta_wm(cmd);
3200 gen6_meta_ps(cmd);
3201 gen6_meta_depth_buffer(cmd);
3202
Chia-I Wu29e6f502014-11-24 14:27:29 +08003203 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3204 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003205 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003206 } else {
3207 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3208 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003209 }
3210
3211 cmd->bind.draw_count++;
3212 /* need to re-emit all workarounds */
3213 cmd->bind.wa_flags = 0;
3214
3215 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003216
3217 if (intel_debug & INTEL_DEBUG_NOCACHE)
3218 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003219}
3220
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003221ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003222 XGL_CMD_BUFFER cmdBuffer,
3223 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3224 XGL_PIPELINE pipeline)
3225{
3226 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3227
3228 switch (pipelineBindPoint) {
3229 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003230 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003231 break;
3232 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003233 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003234 break;
3235 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003236 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003237 break;
3238 }
3239}
3240
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003241ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003242 XGL_CMD_BUFFER cmdBuffer,
3243 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3244 XGL_PIPELINE_DELTA delta)
3245{
3246 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3247
3248 switch (pipelineBindPoint) {
3249 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003250 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003251 break;
3252 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003253 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003254 break;
3255 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003256 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003257 break;
3258 }
3259}
3260
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003261ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003262 XGL_CMD_BUFFER cmdBuffer,
3263 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003264 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003265{
3266 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3267
3268 switch (stateBindPoint) {
3269 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003270 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003271 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003272 break;
3273 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003274 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003275 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003276 break;
3277 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003278 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003279 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003280 break;
3281 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003282 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003283 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003284 break;
3285 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003286 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003287 break;
3288 }
3289}
3290
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003291ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003292 XGL_CMD_BUFFER cmdBuffer,
3293 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003294 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003295 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003296{
3297 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003298 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003299
3300 switch (pipelineBindPoint) {
3301 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003302 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003303 break;
3304 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003305 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003306 break;
3307 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003308 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003309 break;
3310 }
3311}
3312
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003313ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003314 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003315 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003316 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003317 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003318{
3319 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003320 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003321
Chia-I Wu714df452015-01-01 07:55:04 +08003322 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003323}
3324
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003325ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003326 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003327 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003328 XGL_GPU_SIZE offset,
3329 XGL_INDEX_TYPE indexType)
3330{
3331 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003332 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003333
Chia-I Wu714df452015-01-01 07:55:04 +08003334 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003335}
3336
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003337ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003338 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003339 uint32_t firstVertex,
3340 uint32_t vertexCount,
3341 uint32_t firstInstance,
3342 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003343{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003344 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003345
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003346 cmd_draw(cmd, firstVertex, vertexCount,
3347 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003348}
3349
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003350ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003351 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003352 uint32_t firstIndex,
3353 uint32_t indexCount,
3354 int32_t vertexOffset,
3355 uint32_t firstInstance,
3356 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003357{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003358 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003359
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003360 cmd_draw(cmd, firstIndex, indexCount,
3361 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003362}
3363
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003364ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003365 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003366 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003367 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003368 uint32_t count,
3369 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003370{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003371 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3372
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003373 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003374}
3375
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003376ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003377 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003378 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003379 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003380 uint32_t count,
3381 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003382{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003383 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3384
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003385 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003386}
3387
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003388ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003389 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003390 uint32_t x,
3391 uint32_t y,
3392 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003393{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003394 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3395
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003396 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003397}
3398
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003399ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003400 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003401 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003402 XGL_GPU_SIZE offset)
3403{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003404 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3405
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003406 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003407}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003408
Chia-I Wude26bdf2015-02-18 15:47:12 -07003409ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003410 XGL_CMD_BUFFER cmdBuffer,
3411 XGL_RENDER_PASS renderPass)
3412{
3413 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3414
3415 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3416}
3417
Chia-I Wude26bdf2015-02-18 15:47:12 -07003418ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003419 XGL_CMD_BUFFER cmdBuffer,
3420 XGL_RENDER_PASS renderPass)
3421{
3422 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3423
3424 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3425}