blob: a63ebd99ae0db428881cac3d37d2b9636e20c2e5 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700273 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700279 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700394 switch (pipeline->db_format) {
395 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700398 case XGL_FMT_D32_SFLOAT:
399 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700413 /* Scissor is always enabled */
414 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
415
Tony Barbourfa6cac72015-01-16 14:27:35 -0700416 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800417 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
419 } else {
420 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
421 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
422 }
423
Chia-I Wu8016a172014-08-29 18:31:32 +0800424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
Chia-I Wu8016a172014-08-29 18:31:32 +0800443static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
444{
445 const uint8_t cmd_len = 20;
446 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
447 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800448 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800450 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800451
452 CMD_ASSERT(cmd, 6, 6);
453
454 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800455
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 cmd_batch_pointer(cmd, cmd_len, &dw);
457 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800458 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800460 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800461}
462
463static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
464{
465 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 7, 7.5);
469
Chia-I Wu72292b72014-09-09 10:48:33 +0800470 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800471 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
472 (cmd_len - 2);
473 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474}
475
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800476static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
477{
478 const uint8_t cmd_len = 4;
479 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
480 (cmd_len - 2);
481 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700482 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800483 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700484 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800485 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800486
487 CMD_ASSERT(cmd, 6, 7.5);
488
489 dw1 = GEN6_CLIP_DW1_STATISTICS;
490 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
491 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
492 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800494 }
495
496 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
497 GEN6_CLIP_DW2_XY_TEST_ENABLE |
498 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700499 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800500 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
501 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
502 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
503
504 if (pipeline->rasterizerDiscardEnable)
505 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
506 else
507 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
508
509 if (pipeline->depthClipEnable)
510 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
511
512 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
513 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
514 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
515 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
516
517 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
518 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
519 (viewport->viewport_count - 1);
520
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600521 /* TODO: framebuffer requests layer_count > 1 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700522 if (cmd->bind.render_pass->fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600523 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
524 }
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
527 dw[0] = dw0;
528 dw[1] = dw1;
529 dw[2] = dw2;
530 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800531}
532
Chia-I Wu784d3042014-12-19 14:30:04 +0800533static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600534 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800535 const struct intel_pipeline *pipeline,
536 const struct intel_pipeline_shader *sh)
537{
538 int scratch_space;
539
540 CMD_ASSERT(cmd, 6, 7.5);
541
542 assert(sh->per_thread_scratch_size &&
543 sh->per_thread_scratch_size % 1024 == 0 &&
544 u_is_pow2(sh->per_thread_scratch_size) &&
545 sh->scratch_offset % 1024 == 0);
546 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
547
548 cmd_reserve_reloc(cmd, 1);
549 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
550 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
551}
552
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800553static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
554{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800555 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800556 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800557 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600558 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700559 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560
561 CMD_ASSERT(cmd, 6, 6);
562
563 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
564
565 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
566 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
567
568 dw4 = GEN6_WM_DW4_STATISTICS |
569 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
570 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700571 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800573 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700574 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
575 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800576
Cody Northrope86574e2015-02-24 14:15:29 -0700577 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700578 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700579
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800580 if (fs->uses & INTEL_SHADER_USE_KILL ||
581 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700582 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800583
Cody Northrope238deb2015-01-26 14:41:36 -0700584 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800585 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
586 if (fs->uses & INTEL_SHADER_USE_DEPTH)
587 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
588 if (fs->uses & INTEL_SHADER_USE_W)
589 dw5 |= GEN6_WM_DW5_PS_USE_W;
590
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700591 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700592 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800593
594 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700595 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596 GEN6_WM_DW6_ZW_INTERP_PIXEL |
597 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
598 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
599
Tony Barbourfa6cac72015-01-16 14:27:35 -0700600 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800601 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
602 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
603 } else {
604 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
605 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
606 }
607
Cody Northrope86574e2015-02-24 14:15:29 -0700608 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
609
Chia-I Wu784d3042014-12-19 14:30:04 +0800610 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800611 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800612 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800613 dw[2] = dw2;
614 dw[3] = 0; /* scratch */
615 dw[4] = dw4;
616 dw[5] = dw5;
617 dw[6] = dw6;
618 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700619 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800620
621 if (fs->per_thread_scratch_size)
622 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800623}
624
625static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
626{
627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800628 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800629 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800630 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800631
632 CMD_ASSERT(cmd, 7, 7.5);
633
634 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
635
636 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700637 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638 GEN7_WM_DW1_ZW_INTERP_PIXEL |
639 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
640 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
641
642 if (fs->uses & INTEL_SHADER_USE_KILL ||
643 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700644 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800645
Cody Northrope238deb2015-01-26 14:41:36 -0700646 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
647
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800648 if (fs->uses & INTEL_SHADER_USE_DEPTH)
649 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
650 if (fs->uses & INTEL_SHADER_USE_W)
651 dw1 |= GEN7_WM_DW1_PS_USE_W;
652
653 dw2 = 0;
654
Tony Barbourfa6cac72015-01-16 14:27:35 -0700655 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800656 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
657 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
658 } else {
659 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
660 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
661 }
662
Chia-I Wu72292b72014-09-09 10:48:33 +0800663 cmd_batch_pointer(cmd, cmd_len, &dw);
664 dw[0] = dw0;
665 dw[1] = dw1;
666 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667}
668
669static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
670{
671 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800672 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800673 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700674 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600675 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676
677 CMD_ASSERT(cmd, 7, 7.5);
678
679 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
680
681 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
682 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
683
684 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700685 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800686
Cody Northrope86574e2015-02-24 14:15:29 -0700687 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700688 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700689
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800691 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700692 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800694 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800695 }
696
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 if (fs->in_count)
698 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
699
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700700 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
702
703 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
704 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700705 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
706
707 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800708
Chia-I Wu784d3042014-12-19 14:30:04 +0800709 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800710 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800711 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[2] = dw2;
713 dw[3] = 0; /* scratch */
714 dw[4] = dw4;
715 dw[5] = dw5;
716 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700717 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800718
719 if (fs->per_thread_scratch_size)
720 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800721}
722
Chia-I Wu8ada4242015-03-02 11:19:33 -0700723static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
724 uint32_t sample_count)
725{
726 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
727 uint32_t dw1, dw2, dw3, *dw;
728
729 CMD_ASSERT(cmd, 6, 7.5);
730
731 switch (sample_count) {
732 case 4:
733 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
734 dw2 = cmd->dev->sample_pattern_4x;
735 dw3 = 0;
736 break;
737 case 8:
738 assert(cmd_gen(cmd) >= INTEL_GEN(7));
739 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
740 dw2 = cmd->dev->sample_pattern_8x[0];
741 dw3 = cmd->dev->sample_pattern_8x[1];
742 break;
743 default:
744 assert(sample_count <= 1);
745 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
746 dw2 = 0;
747 dw3 = 0;
748 break;
749 }
750
751 cmd_batch_pointer(cmd, cmd_len, &dw);
752
753 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
754 dw[1] = dw1;
755 dw[2] = dw2;
756 if (cmd_gen(cmd) >= INTEL_GEN(7))
757 dw[3] = dw3;
758}
759
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800760static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700761 const struct intel_ds_view *view,
762 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800763{
764 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800765 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600766 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767
768 CMD_ASSERT(cmd, 6, 7.5);
769
770 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800771 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
772 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773 dw0 |= (cmd_len - 2);
774
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
776 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700777
Chia-I Wu72292b72014-09-09 10:48:33 +0800778 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700779 /* note that we only enable HiZ on Gen7+ */
780 if (!optimal_ds)
781 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
782
Chia-I Wu72292b72014-09-09 10:48:33 +0800783 dw[2] = 0;
784 dw[3] = view->cmd[2];
785 dw[4] = view->cmd[3];
786 dw[5] = view->cmd[4];
787 dw[6] = view->cmd[5];
788
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600789 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 cmd_reserve_reloc(cmd, 1);
791 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
792 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600793 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800794}
795
796static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700797 const struct intel_ds_view *view,
798 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799{
800 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600802 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800803
804 CMD_ASSERT(cmd, 6, 7.5);
805
806 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800807 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
808 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809 dw0 |= (cmd_len - 2);
810
Chia-I Wu72292b72014-09-09 10:48:33 +0800811 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
812 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800813
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700814 if (view->has_stencil) {
815 dw[1] = view->cmd[6];
816
Chia-I Wu72292b72014-09-09 10:48:33 +0800817 cmd_reserve_reloc(cmd, 1);
818 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
819 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700820 } else {
821 dw[1] = 0;
822 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600823 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800824}
825
826static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700827 const struct intel_ds_view *view,
828 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800829{
830 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600832 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800833
834 CMD_ASSERT(cmd, 6, 7.5);
835
836 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800837 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
838 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800839 dw0 |= (cmd_len - 2);
840
Chia-I Wu72292b72014-09-09 10:48:33 +0800841 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
842 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800843
Chia-I Wu73520ac2015-02-19 11:17:45 -0700844 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700845 dw[1] = view->cmd[8];
846
Chia-I Wu72292b72014-09-09 10:48:33 +0800847 cmd_reserve_reloc(cmd, 1);
848 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
849 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700850 } else {
851 dw[1] = 0;
852 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600853 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800854}
855
Chia-I Wuf8231032014-08-25 10:44:45 +0800856static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
857 uint32_t clear_val)
858{
859 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800860 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800861 GEN6_CLEAR_PARAMS_DW0_VALID |
862 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800864
865 CMD_ASSERT(cmd, 6, 6);
866
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 cmd_batch_pointer(cmd, cmd_len, &dw);
868 dw[0] = dw0;
869 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800870}
871
872static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
873 uint32_t clear_val)
874{
875 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800876 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800877 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800878 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800879
880 CMD_ASSERT(cmd, 7, 7.5);
881
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_batch_pointer(cmd, cmd_len, &dw);
883 dw[0] = dw0;
884 dw[1] = clear_val;
885 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800886}
887
Chia-I Wu302742d2014-08-22 10:28:29 +0800888static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 uint32_t blend_offset,
890 uint32_t ds_offset,
891 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800892{
893 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800894 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800895
896 CMD_ASSERT(cmd, 6, 6);
897
Chia-I Wu426072d2014-08-26 14:31:55 +0800898 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800899 (cmd_len - 2);
900
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 cmd_batch_pointer(cmd, cmd_len, &dw);
902 dw[0] = dw0;
903 dw[1] = blend_offset | 1;
904 dw[2] = ds_offset | 1;
905 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800906}
907
Chia-I Wu1744cca2014-08-22 11:10:17 +0800908static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t clip_offset,
910 uint32_t sf_offset,
911 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800912{
913 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915
916 CMD_ASSERT(cmd, 6, 6);
917
Chia-I Wu426072d2014-08-26 14:31:55 +0800918 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700919 GEN6_VP_PTR_DW0_CLIP_CHANGED |
920 GEN6_VP_PTR_DW0_SF_CHANGED |
921 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922 (cmd_len - 2);
923
Chia-I Wu72292b72014-09-09 10:48:33 +0800924 cmd_batch_pointer(cmd, cmd_len, &dw);
925 dw[0] = dw0;
926 dw[1] = clip_offset;
927 dw[2] = sf_offset;
928 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800929}
930
931static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800933{
934 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936
937 CMD_ASSERT(cmd, 6, 6);
938
Chia-I Wu426072d2014-08-26 14:31:55 +0800939 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800940 (cmd_len - 2);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800945}
946
Chia-I Wu42a56202014-08-23 16:47:48 +0800947static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800948 uint32_t vs_offset,
949 uint32_t gs_offset,
950 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800951{
952 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800954
955 CMD_ASSERT(cmd, 6, 6);
956
Chia-I Wu426072d2014-08-26 14:31:55 +0800957 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700958 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
959 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
960 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +0800961 (cmd_len - 2);
962
Chia-I Wu72292b72014-09-09 10:48:33 +0800963 cmd_batch_pointer(cmd, cmd_len, &dw);
964 dw[0] = dw0;
965 dw[1] = vs_offset;
966 dw[2] = gs_offset;
967 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800968}
969
Chia-I Wu257e75e2014-08-29 14:06:35 +0800970static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800971 uint32_t vs_offset,
972 uint32_t gs_offset,
973 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800974{
975 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977
978 CMD_ASSERT(cmd, 6, 6);
979
980 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700981 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
982 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
983 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +0800984 (cmd_len - 2);
985
Chia-I Wu72292b72014-09-09 10:48:33 +0800986 cmd_batch_pointer(cmd, cmd_len, &dw);
987 dw[0] = dw0;
988 dw[1] = vs_offset;
989 dw[2] = gs_offset;
990 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800991}
992
Chia-I Wu302742d2014-08-22 10:28:29 +0800993static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800994 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800995{
996 const uint8_t cmd_len = 2;
997 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
998 GEN6_RENDER_SUBTYPE_3D |
999 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001000 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002 cmd_batch_pointer(cmd, cmd_len, &dw);
1003 dw[0] = dw0;
1004 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005}
1006
Chia-I Wua6c4f152014-12-02 04:19:58 +08001007static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001008{
Chia-I Wue6073342014-11-30 09:43:42 +08001009 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001010 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1011 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012
1013 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001014 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001015
Tony Barbourfa6cac72015-01-16 14:27:35 -07001016 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001017}
1018
Chia-I Wu72292b72014-09-09 10:48:33 +08001019static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001020 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001021{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001022 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001023 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001024 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001025 uint32_t dw[3];
1026
1027 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001028 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001029 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001030 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1031 (state->ds_info.stencilReadMask & 0xff) << 8 |
1032 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001033 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034
1035 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001036
1037 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1038 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001039
Chia-I Wu00b51a82014-09-09 12:07:37 +08001040 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001041 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001042}
1043
Chia-I Wu72292b72014-09-09 10:48:33 +08001044static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001045 uint32_t stencil_ref,
1046 const uint32_t blend_color[4])
1047{
Chia-I Wue6073342014-11-30 09:43:42 +08001048 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001049 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001050 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001051
1052 CMD_ASSERT(cmd, 6, 7.5);
1053
Chia-I Wu00b51a82014-09-09 12:07:37 +08001054 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1055 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001056 dw[0] = stencil_ref;
1057 dw[1] = 0;
1058 dw[2] = blend_color[0];
1059 dw[3] = blend_color[1];
1060 dw[4] = blend_color[2];
1061 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001062
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001064}
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067{
Chia-I Wu8370b402014-08-29 12:28:37 +08001068 CMD_ASSERT(cmd, 6, 7.5);
1069
Chia-I Wu707a29e2014-08-27 12:51:47 +08001070 if (!cmd->bind.draw_count)
1071 return;
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001074 return;
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001077
1078 /*
1079 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1080 *
1081 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1082 * pipe-control with a post-sync op and no write-cache flushes."
1083 *
1084 * The workaround below necessitates this workaround.
1085 */
1086 gen6_PIPE_CONTROL(cmd,
1087 GEN6_PIPE_CONTROL_CS_STALL |
1088 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001089 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001090
Chia-I Wud6d079d2014-08-31 13:14:21 +08001091 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1092 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001093}
1094
Chia-I Wu8370b402014-08-29 12:28:37 +08001095static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001096{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001097 CMD_ASSERT(cmd, 6, 7.5);
1098
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001099 if (!cmd->bind.draw_count)
1100 return;
1101
Chia-I Wud6d079d2014-08-31 13:14:21 +08001102 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1103 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001104}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001105
Chia-I Wu8370b402014-08-29 12:28:37 +08001106static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1107{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001108 CMD_ASSERT(cmd, 7, 7.5);
1109
Chia-I Wu8370b402014-08-29 12:28:37 +08001110 if (!cmd->bind.draw_count)
1111 return;
1112
1113 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001114
1115 gen6_PIPE_CONTROL(cmd,
1116 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001117 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001118}
1119
Chia-I Wu8370b402014-08-29 12:28:37 +08001120static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1121{
1122 CMD_ASSERT(cmd, 7, 7.5);
1123
Chia-I Wu8370b402014-08-29 12:28:37 +08001124 /*
1125 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1126 *
1127 * "One of the following must also be set (when CS stall is set):
1128 *
1129 * * Render Target Cache Flush Enable ([12] of DW1)
1130 * * Depth Cache Flush Enable ([0] of DW1)
1131 * * Stall at Pixel Scoreboard ([1] of DW1)
1132 * * Depth Stall ([13] of DW1)
1133 * * Post-Sync Operation ([13] of DW1)"
1134 */
1135 gen6_PIPE_CONTROL(cmd,
1136 GEN6_PIPE_CONTROL_CS_STALL |
1137 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001138 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001139}
1140
1141static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1142{
1143 CMD_ASSERT(cmd, 7, 7.5);
1144
Chia-I Wu8370b402014-08-29 12:28:37 +08001145 cmd_wa_gen6_pre_depth_stall_write(cmd);
1146
Chia-I Wud6d079d2014-08-31 13:14:21 +08001147 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001148}
1149
1150static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1151{
1152 CMD_ASSERT(cmd, 6, 7.5);
1153
1154 if (!cmd->bind.draw_count)
1155 return;
1156
1157 /*
1158 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1159 *
1160 * "Driver must guarentee that all the caches in the depth pipe are
1161 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1162 * requires driver to send a PIPE_CONTROL with a CS stall along with
1163 * a Depth Flush prior to this command."
1164 *
1165 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1166 *
1167 * "Driver must ierarchi that all the caches in the depth pipe are
1168 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1169 * requires driver to send a PIPE_CONTROL with a CS stall along with
1170 * a Depth Flush prior to this command.
1171 */
1172 gen6_PIPE_CONTROL(cmd,
1173 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1174 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001175 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001176}
1177
1178static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1179{
1180 CMD_ASSERT(cmd, 6, 7.5);
1181
1182 if (!cmd->bind.draw_count)
1183 return;
1184
1185 /*
1186 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1187 *
1188 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1189 * and a post sync operation prior to the group of depth
1190 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1191 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1192 *
1193 * This workaround satifies all the conditions.
1194 */
1195 cmd_wa_gen6_pre_depth_stall_write(cmd);
1196
1197 /*
1198 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1199 *
1200 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1201 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1202 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1203 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1204 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1205 * Depth Flush Bit set, followed by another pipelined depth stall
1206 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1207 * guarantee that the pipeline from WM onwards is already flushed
1208 * (e.g., via a preceding MI_FLUSH)."
1209 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001210 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1211 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1212 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001213}
1214
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001215void cmd_batch_state_base_address(struct intel_cmd *cmd)
1216{
1217 const uint8_t cmd_len = 10;
1218 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1219 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001220 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001221 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001222 uint32_t pos;
1223 uint32_t *dw;
1224
1225 CMD_ASSERT(cmd, 6, 7.5);
1226
1227 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1228
1229 dw[0] = dw0;
1230 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001231 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001232 dw[2] = 1;
1233 dw[3] = 1;
1234 dw[4] = 1;
1235 dw[5] = 1;
1236 /* end offsets */
1237 dw[6] = 1;
1238 dw[7] = 1 + 0xfffff000;
1239 dw[8] = 1 + 0xfffff000;
1240 dw[9] = 1;
1241
1242 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001243 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1244 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1245 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1246 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1247 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1248 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001249}
1250
Chia-I Wu7c853562015-02-27 14:35:08 -07001251void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1252{
1253 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1254 const uint8_t cmd_len = 2;
1255 uint32_t offset = 0;
1256 uint32_t *dw;
1257
1258 if (cmd_gen(cmd) <= INTEL_GEN(6))
1259 return;
1260
1261 CMD_ASSERT(cmd, 7, 7.5);
1262
1263 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1264 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1265 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1266 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1267 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1268 offset += size;
1269
1270 dw += 2;
1271 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1272 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1273 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1274
1275 dw += 2;
1276 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1277 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1278 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1279
1280 dw += 2;
1281 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1282 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1283 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1284
1285 dw += 2;
1286 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1287 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1288 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1289
1290 /*
1291 *
1292 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1293 *
1294 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1295 * in the ring after this instruction
1296 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1297 */
1298 cmd_wa_gen7_post_command_cs_stall(cmd);
1299}
1300
Chia-I Wu525c6602014-08-27 10:22:34 +08001301void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1302{
Mike Stroyan552fda42015-01-30 17:21:08 -07001303 if (pipe_control_dw0 == 0)
1304 return;
1305
Chia-I Wu525c6602014-08-27 10:22:34 +08001306 if (!cmd->bind.draw_count)
1307 return;
1308
1309 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1310
Chia-I Wu8370b402014-08-29 12:28:37 +08001311 /*
1312 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1313 *
1314 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1315 * PIPE_CONTROL with any non-zero post-sync-op is required."
1316 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001317 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001318 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001319
Chia-I Wu092279a2014-08-30 19:05:30 +08001320 /*
1321 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1322 *
1323 * "One of the following must also be set (when CS stall is set):
1324 *
1325 * * Render Target Cache Flush Enable ([12] of DW1)
1326 * * Depth Cache Flush Enable ([0] of DW1)
1327 * * Stall at Pixel Scoreboard ([1] of DW1)
1328 * * Depth Stall ([13] of DW1)
1329 * * Post-Sync Operation ([13] of DW1)"
1330 */
1331 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1332 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1333 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1334 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1335 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1336 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1337
Chia-I Wud6d079d2014-08-31 13:14:21 +08001338 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001339}
1340
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001341void cmd_batch_flush_all(struct intel_cmd *cmd)
1342{
1343 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1344 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1345 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1346 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1347 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1348 GEN6_PIPE_CONTROL_CS_STALL);
1349}
1350
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001351void cmd_batch_depth_count(struct intel_cmd *cmd,
1352 struct intel_bo *bo,
1353 XGL_GPU_SIZE offset)
1354{
1355 cmd_wa_gen6_pre_depth_stall_write(cmd);
1356
1357 gen6_PIPE_CONTROL(cmd,
1358 GEN6_PIPE_CONTROL_DEPTH_STALL |
1359 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001360 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001361}
1362
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001363void cmd_batch_timestamp(struct intel_cmd *cmd,
1364 struct intel_bo *bo,
1365 XGL_GPU_SIZE offset)
1366{
1367 /* need any WA or stall? */
1368 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1369}
1370
1371void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001372 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001373 struct intel_bo *bo,
1374 XGL_GPU_SIZE offset,
1375 uint64_t val)
1376{
1377 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001378 gen6_PIPE_CONTROL(cmd,
1379 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1380 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001381}
1382
Chia-I Wu302742d2014-08-22 10:28:29 +08001383static void gen6_cc_states(struct intel_cmd *cmd)
1384{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001385 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1386 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001387 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001388 uint32_t stencil_ref;
1389 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001390
1391 CMD_ASSERT(cmd, 6, 6);
1392
Chia-I Wua6c4f152014-12-02 04:19:58 +08001393 blend_offset = gen6_BLEND_STATE(cmd);
1394
1395 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001396 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001397 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001398 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001399
1400 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001401 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001402 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1403 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001404 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001405 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001406 stencil_ref = 0;
1407 }
1408
Chia-I Wu72292b72014-09-09 10:48:33 +08001409 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001410
Chia-I Wu72292b72014-09-09 10:48:33 +08001411 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001412}
1413
Chia-I Wu1744cca2014-08-22 11:10:17 +08001414static void gen6_viewport_states(struct intel_cmd *cmd)
1415{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001416 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001418
1419 if (!viewport)
1420 return;
1421
Tony Barbourfa6cac72015-01-16 14:27:35 -07001422 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001423 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424
1425 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001426 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 viewport->cmd);
1428
1429 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001430 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001431 &viewport->cmd[viewport->cmd_clip_pos]);
1432
1433 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001434 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001435 &viewport->cmd[viewport->cmd_cc_pos]);
1436
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001437 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1438 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1439 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001440
1441 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001442 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001443
Chia-I Wub1d450a2014-09-09 13:48:03 +08001444 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001445}
1446
Chia-I Wu302742d2014-08-22 10:28:29 +08001447static void gen7_cc_states(struct intel_cmd *cmd)
1448{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001449 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1450 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001451 uint32_t stencil_ref;
1452 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001453 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001454
1455 CMD_ASSERT(cmd, 7, 7.5);
1456
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001457 if (!blend && !ds)
1458 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001459
Chia-I Wua6c4f152014-12-02 04:19:58 +08001460 offset = gen6_BLEND_STATE(cmd);
1461 gen7_3dstate_pointer(cmd,
1462 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001463
Chia-I Wua6c4f152014-12-02 04:19:58 +08001464 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001465 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001466 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001467 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001468
1469 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001470 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001471 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1472 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001473 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001474 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1475 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001476 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1477 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001478 } else {
1479 stencil_ref = 0;
1480 }
1481
Chia-I Wu72292b72014-09-09 10:48:33 +08001482 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001483 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001484 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001485}
1486
Chia-I Wu1744cca2014-08-22 11:10:17 +08001487static void gen7_viewport_states(struct intel_cmd *cmd)
1488{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001489 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001490 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001491
1492 if (!viewport)
1493 return;
1494
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001495 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001496
Chia-I Wub1d450a2014-09-09 13:48:03 +08001497 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001498 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001499 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001500 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001501 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1502 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001503
1504 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001505 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001507 gen7_3dstate_pointer(cmd,
1508 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001509 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001510
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001511 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1512 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1513 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1514 gen7_3dstate_pointer(cmd,
1515 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1516 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001517}
1518
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001519static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001520 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001521{
1522 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001523 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001524
Chia-I Wu72292b72014-09-09 10:48:33 +08001525 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001526
1527 dw[0] = GEN6_RENDER_TYPE_RENDER |
1528 GEN6_RENDER_SUBTYPE_3D |
1529 subop | (cmd_len - 2);
1530 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001531 dw[2] = 0;
1532 dw[3] = 0;
1533 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001534}
1535
1536static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001537 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001538{
1539 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001540 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001541
Chia-I Wu72292b72014-09-09 10:48:33 +08001542 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001543
1544 dw[0] = GEN6_RENDER_TYPE_RENDER |
1545 GEN6_RENDER_SUBTYPE_3D |
1546 subop | (cmd_len - 2);
1547 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001549 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001550 dw[4] = 0;
1551 dw[5] = 0;
1552 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001553}
1554
Chia-I Wu625105f2014-10-13 15:35:29 +08001555static uint32_t emit_samplers(struct intel_cmd *cmd,
1556 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001557{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001558 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1559 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001560 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001561 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001562 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001563 uint32_t surface_count;
1564 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001565
1566 CMD_ASSERT(cmd, 6, 7.5);
1567
Chia-I Wu625105f2014-10-13 15:35:29 +08001568 if (!rmap || !rmap->sampler_count)
1569 return 0;
1570
Cody Northrop40316a32014-12-09 19:08:33 -07001571 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001572
Chia-I Wudcb509d2014-12-10 08:53:10 +08001573 /*
1574 * note that we cannot call cmd_state_pointer() here as the following
1575 * cmd_state_pointer() would invalidate the pointer
1576 */
1577 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001578 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001579 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001580
1581 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001582 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001583 4 * rmap->sampler_count, &sampler_dw);
1584
Chia-I Wudcb509d2014-12-10 08:53:10 +08001585 cmd_state_update(cmd, border_offset,
1586 border_stride * rmap->sampler_count, &border_dw);
1587
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001588 for (i = 0; i < rmap->sampler_count; i++) {
1589 const struct intel_pipeline_rmap_slot *slot =
1590 &rmap->slots[surface_count + i];
1591 const struct intel_sampler *sampler;
1592
Chia-I Wuf8385062015-01-04 16:27:24 +08001593 switch (slot->type) {
1594 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001595 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001596 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001597 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001598 sampler = NULL;
1599 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001600 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001601 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001602 sampler = NULL;
1603 break;
1604 }
1605
1606 if (sampler) {
1607 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1608
1609 sampler_dw[0] = sampler->cmd[0];
1610 sampler_dw[1] = sampler->cmd[1];
1611 sampler_dw[2] = border_offset;
1612 sampler_dw[3] = sampler->cmd[2];
1613 } else {
1614 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1615 sampler_dw[1] = 0;
1616 sampler_dw[2] = 0;
1617 sampler_dw[3] = 0;
1618 }
1619
1620 border_offset += border_stride * 4;
1621 border_dw += border_stride;
1622 sampler_dw += 4;
1623 }
1624
Chia-I Wu625105f2014-10-13 15:35:29 +08001625 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001626}
1627
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001628static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001629 const struct intel_pipeline_rmap *rmap,
1630 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001631{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001632 const uint32_t sba_offset =
1633 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001634 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001635 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001636 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001637
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638 CMD_ASSERT(cmd, 6, 7.5);
1639
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001640 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001641 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001642 if (!surface_count)
1643 return 0;
1644
Chia-I Wu42a56202014-08-23 16:47:48 +08001645 assert(surface_count <= ARRAY_SIZE(binding_table));
1646
1647 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001648 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001649 struct intel_null_view null_view;
1650 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001651
Chia-I Wuf8385062015-01-04 16:27:24 +08001652 switch (slot->type) {
1653 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001654 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001655 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001656 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1657 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001658
Chia-I Wu787a05b2014-12-05 11:02:20 +08001659 if (view) {
1660 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1661 GEN6_ALIGNMENT_SURFACE_STATE,
1662 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001663
Chia-I Wu787a05b2014-12-05 11:02:20 +08001664 cmd_reserve_reloc(cmd, 1);
1665 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1666 view->cmd[1], INTEL_RELOC_WRITE);
1667 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001668 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001669 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001670 }
1671 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001672 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001673 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001674 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1675 const struct intel_mem *mem;
1676 bool read_only;
1677 const uint32_t *cmd_data;
1678 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001679
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001680 assert(dyn_idx < 0 ||
1681 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001682
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001683 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1684 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001685 if (mem) {
1686 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1687 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1688 const uint32_t reloc_flags =
1689 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001690
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001691 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001692 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001693 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001694
1695 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001696 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1697 cmd_data[1] + dynamic_offset, reloc_flags);
1698 } else {
1699 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001700 }
1701 }
1702 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001703 case INTEL_PIPELINE_RMAP_UNUSED:
1704 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001705 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001706 default:
1707 assert(!"unexpected rmap type");
1708 need_null_view = true;
1709 break;
1710 }
1711
1712 if (need_null_view) {
1713 intel_null_view_init(&null_view, cmd->dev);
1714 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1715 GEN6_ALIGNMENT_SURFACE_STATE,
1716 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001717 }
1718
Chia-I Wuf98dd882015-02-10 04:17:47 +08001719 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001720 }
1721
Chia-I Wuf98dd882015-02-10 04:17:47 +08001722 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001723 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001724 surface_count, binding_table) - sba_offset;
1725
1726 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1727 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1728
1729 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001730}
1731
Chia-I Wu1d125092014-10-08 08:49:38 +08001732static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1733{
1734 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001735 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1736 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001737 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001738
1739 CMD_ASSERT(cmd, 6, 7.5);
1740
1741 if (!pipeline->vb_count)
1742 return;
1743
1744 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1745
1746 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1747 dw++;
1748 pos++;
1749
1750 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001751 assert(pipeline->vb[i].strideInBytes <= 2048);
1752
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001753 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001754 pipeline->vb[i].strideInBytes;
1755
Chia-I Wub3686982015-02-27 09:51:16 -07001756 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001757 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1758 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001759 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001760
1761 switch (pipeline->vb[i].stepRate) {
1762 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001763 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001764 dw[3] = 0;
1765 break;
1766 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001767 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001768 dw[3] = 1;
1769 break;
1770 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001771 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001772 dw[3] = 0;
1773 break;
1774 default:
1775 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001776 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001777 dw[3] = 0;
1778 break;
1779 }
1780
Chia-I Wu714df452015-01-01 07:55:04 +08001781 if (cmd->bind.vertex.buf[i]) {
1782 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001783 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001784
1785 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001786 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1787 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001788 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001789 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001790 dw[1] = 0;
1791 dw[2] = 0;
1792 }
1793
1794 dw += 4;
1795 pos += 4;
1796 }
1797}
1798
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001799static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1800{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001801 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1802 const struct intel_pipeline_shader *vs = &pipeline->vs;
1803 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001804 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001805 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001806 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001807 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001808
1809 CMD_ASSERT(cmd, 6, 7.5);
1810
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001811 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001812 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1813 *
1814 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1815 * 128-bit vertex elements to be passed into the payload for each
1816 * vertex."
1817 *
1818 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1819 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001820 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001821 vue_read_len = (vs->in_count + 1) / 2;
1822 if (!vue_read_len)
1823 vue_read_len = 1;
1824
1825 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1826 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1827
1828 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1829 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1830 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001831
1832 dw5 = GEN6_VS_DW5_STATISTICS |
1833 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001834
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001835 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001836 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001837 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001838 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001839
Chia-I Wube0a3d92014-09-02 13:20:59 +08001840 if (pipeline->disable_vs_cache)
1841 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1842
Chia-I Wu784d3042014-12-19 14:30:04 +08001843 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001844 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001845 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001846 dw[2] = dw2;
1847 dw[3] = 0; /* scratch */
1848 dw[4] = dw4;
1849 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001850
1851 if (vs->per_thread_scratch_size)
1852 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001853}
1854
Chia-I Wu625105f2014-10-13 15:35:29 +08001855static void emit_shader_resources(struct intel_cmd *cmd)
1856{
1857 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001858 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001859
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001860 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001861 cmd->bind.pipeline.graphics->vs.rmap,
1862 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001863 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001864 cmd->bind.pipeline.graphics->tcs.rmap,
1865 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001866 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001867 cmd->bind.pipeline.graphics->tes.rmap,
1868 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001869 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001870 cmd->bind.pipeline.graphics->gs.rmap,
1871 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001872 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001873 cmd->bind.pipeline.graphics->fs.rmap,
1874 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001875
1876 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1877 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1878 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1879 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1880 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1881
1882 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1883 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001884 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1885 binding_tables[0]);
1886 gen7_3dstate_pointer(cmd,
1887 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1888 binding_tables[1]);
1889 gen7_3dstate_pointer(cmd,
1890 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1891 binding_tables[2]);
1892 gen7_3dstate_pointer(cmd,
1893 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1894 binding_tables[3]);
1895 gen7_3dstate_pointer(cmd,
1896 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1897 binding_tables[4]);
1898
1899 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001900 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1901 samplers[0]);
1902 gen7_3dstate_pointer(cmd,
1903 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1904 samplers[1]);
1905 gen7_3dstate_pointer(cmd,
1906 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1907 samplers[2]);
1908 gen7_3dstate_pointer(cmd,
1909 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1910 samplers[3]);
1911 gen7_3dstate_pointer(cmd,
1912 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1913 samplers[4]);
1914 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001915 assert(!binding_tables[1] && !binding_tables[2]);
1916 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1917 binding_tables[0], binding_tables[3], binding_tables[4]);
1918
Chia-I Wu625105f2014-10-13 15:35:29 +08001919 assert(!samplers[1] && !samplers[2]);
1920 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1921 samplers[0], samplers[3], samplers[4]);
1922 }
1923}
1924
Chia-I Wu8ada4242015-03-02 11:19:33 -07001925static void emit_msaa(struct intel_cmd *cmd)
1926{
1927 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1928
Chia-I Wubbc7d912015-02-27 14:59:50 -07001929 if (!cmd->bind.render_pass_changed)
1930 return;
1931
Chia-I Wu8ada4242015-03-02 11:19:33 -07001932 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
1933 cmd->result = XGL_ERROR_UNKNOWN;
1934
1935 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1936 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
1937}
1938
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001939static void emit_rt(struct intel_cmd *cmd)
1940{
Chia-I Wubbc7d912015-02-27 14:59:50 -07001941 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1942
1943 if (!cmd->bind.render_pass_changed)
1944 return;
1945
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001946 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubbc7d912015-02-27 14:59:50 -07001947 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width, fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001948}
1949
1950static void emit_ds(struct intel_cmd *cmd)
1951{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001952 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1953 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001954
Chia-I Wubbc7d912015-02-27 14:59:50 -07001955 if (!cmd->bind.render_pass_changed)
1956 return;
1957
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001958 if (!ds) {
1959 /* all zeros */
1960 static const struct intel_ds_view null_ds;
1961 ds = &null_ds;
1962 }
1963
1964 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001965 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1966 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1967 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001968
1969 if (cmd_gen(cmd) >= INTEL_GEN(7))
1970 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1971 else
1972 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1973}
1974
Chia-I Wua57761b2014-10-14 14:27:44 +08001975static uint32_t emit_shader(struct intel_cmd *cmd,
1976 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001977{
Chia-I Wua57761b2014-10-14 14:27:44 +08001978 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1979 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001980 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001981
Chia-I Wua57761b2014-10-14 14:27:44 +08001982 /* see if the shader is already in the cache */
1983 for (i = 0; i < cache->used; i++) {
1984 if (cache->entries[i].shader == (const void *) shader)
1985 return cache->entries[i].kernel_offset;
1986 }
1987
1988 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1989
1990 /* grow the cache if full */
1991 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001992 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001993 void *entries;
1994
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08001995 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Chia-I Wua57761b2014-10-14 14:27:44 +08001996 XGL_SYSTEM_ALLOC_INTERNAL);
1997 if (entries) {
1998 if (cache->entries) {
1999 memcpy(entries, cache->entries,
2000 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002001 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002002 }
2003
2004 cache->entries = entries;
2005 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002006 }
2007 }
2008
Chia-I Wua57761b2014-10-14 14:27:44 +08002009 /* add the shader to the cache */
2010 if (cache->used < cache->count) {
2011 cache->entries[cache->used].shader = (const void *) shader;
2012 cache->entries[cache->used].kernel_offset = offset;
2013 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002014 }
2015
Chia-I Wua57761b2014-10-14 14:27:44 +08002016 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002017}
2018
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002019static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002020{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002021 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002022
Chia-I Wu8370b402014-08-29 12:28:37 +08002023 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2024 cmd_wa_gen6_pre_depth_stall_write(cmd);
2025 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2026 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2027 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2028 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002029
2030 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002031 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002032 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002033
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002034 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002035 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002036 }
2037 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002038 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002039 }
2040 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002041 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2042 }
2043 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2044 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2045 }
2046 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2047 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002048 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002049
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002050 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2051 gen7_3DSTATE_GS(cmd);
2052 } else {
2053 gen6_3DSTATE_GS(cmd);
2054 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002055
Chia-I Wu8370b402014-08-29 12:28:37 +08002056 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2057 cmd_wa_gen7_post_command_cs_stall(cmd);
2058 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2059 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002060}
2061
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002062static void emit_bounded_states(struct intel_cmd *cmd)
2063{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002064 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002065
2066 emit_graphics_pipeline(cmd);
2067
2068 emit_rt(cmd);
2069 emit_ds(cmd);
2070
2071 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2072 gen7_cc_states(cmd);
2073 gen7_viewport_states(cmd);
2074
2075 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2076 &cmd->bind.pipeline.graphics->vs);
2077 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2078 &cmd->bind.pipeline.graphics->fs);
2079
2080 gen6_3DSTATE_CLIP(cmd);
2081 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002082 gen7_3DSTATE_WM(cmd);
2083 gen7_3DSTATE_PS(cmd);
2084 } else {
2085 gen6_cc_states(cmd);
2086 gen6_viewport_states(cmd);
2087
2088 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2089 &cmd->bind.pipeline.graphics->vs);
2090 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2091 &cmd->bind.pipeline.graphics->fs);
2092
2093 gen6_3DSTATE_CLIP(cmd);
2094 gen6_3DSTATE_SF(cmd);
2095 gen6_3DSTATE_WM(cmd);
2096 }
2097
2098 emit_shader_resources(cmd);
2099
2100 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002101
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002102 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2103 gen6_3DSTATE_VS(cmd);
2104}
2105
Tony Barbourfa6cac72015-01-16 14:27:35 -07002106static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002107 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002108{
2109 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2110 const uint8_t cmd_len = 3;
2111 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002112
2113 CMD_ASSERT(cmd, 6, 7.5);
2114
Tony Barbourfa6cac72015-01-16 14:27:35 -07002115 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002116 dw[0] = 0;
2117 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002118
2119 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2120 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2121 GEN6_COMPAREFUNCTION_NEVER << 27 |
2122 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2123 } else {
2124 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2125 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2126 }
Chia-I Wud850a392015-02-19 11:08:25 -07002127 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2128 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002129 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2130 (GEN6_STENCILOP_KEEP) << 25 |
2131 (GEN6_STENCILOP_KEEP) << 22 |
2132 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002133 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2134 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002135 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2136 (GEN6_STENCILOP_KEEP) << 9 |
2137 (GEN6_STENCILOP_KEEP) << 6 |
2138 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002139
Chia-I Wud850a392015-02-19 11:08:25 -07002140 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2141 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2142 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2143 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2144 dw[2] = 0;
2145 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002146
2147 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2148 cmd_align, cmd_len, dw);
2149}
2150
Chia-I Wu6032b892014-10-17 14:47:18 +08002151static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2152{
2153 const struct intel_cmd_meta *meta = cmd->bind.meta;
2154 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2155
2156 CMD_ASSERT(cmd, 6, 7.5);
2157
2158 blend_offset = 0;
2159 ds_offset = 0;
2160 cc_offset = 0;
2161 cc_vp_offset = 0;
2162
Chia-I Wu29e6f502014-11-24 14:27:29 +08002163 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002164 /* BLEND_STATE */
2165 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002166 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002167 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002168 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 }
2170
Chia-I Wu29e6f502014-11-24 14:27:29 +08002171 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002172 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002173 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002174 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2175 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002176
Chia-I Wu29e6f502014-11-24 14:27:29 +08002177 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002178 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002179
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 /* COLOR_CALC_STATE */
2181 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002182 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002183
Chia-I Wu29e6f502014-11-24 14:27:29 +08002184 /* CC_VIEWPORT */
2185 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002186 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002187 dw[0] = u_fui(0.0f);
2188 dw[1] = u_fui(1.0f);
2189 } else {
2190 /* DEPTH_STENCIL_STATE */
2191 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002192 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002193 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2194 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2195 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002196 }
2197
2198 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2199 gen7_3dstate_pointer(cmd,
2200 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2201 blend_offset);
2202 gen7_3dstate_pointer(cmd,
2203 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2204 ds_offset);
2205 gen7_3dstate_pointer(cmd,
2206 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2207
2208 gen7_3dstate_pointer(cmd,
2209 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2210 cc_vp_offset);
2211 } else {
2212 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002213 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002214
2215 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2216 cmd_batch_pointer(cmd, 4, &dw);
2217 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002218 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002219 dw[1] = 0;
2220 dw[2] = 0;
2221 dw[3] = cc_vp_offset;
2222 }
2223}
2224
2225static void gen6_meta_surface_states(struct intel_cmd *cmd)
2226{
2227 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002228 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002229 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002230 const uint32_t sba_offset =
2231 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002232
2233 CMD_ASSERT(cmd, 6, 7.5);
2234
Chia-I Wu29e6f502014-11-24 14:27:29 +08002235 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2236 return;
2237
Chia-I Wu005c47c2014-10-22 13:49:13 +08002238 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002239 if (meta->src.valid) {
2240 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002241 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002242 meta->src.surface_len, meta->src.surface);
2243
2244 cmd_reserve_reloc(cmd, 1);
2245 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2246 cmd_surface_reloc_writer(cmd, offset, 1,
2247 meta->src.reloc_target, meta->src.reloc_offset);
2248 } else {
2249 cmd_surface_reloc(cmd, offset, 1,
2250 (struct intel_bo *) meta->src.reloc_target,
2251 meta->src.reloc_offset, meta->src.reloc_flags);
2252 }
2253
Mike Stroyan9bfad482015-02-10 15:09:23 -07002254 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002255 }
2256 if (meta->dst.valid) {
2257 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002258 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002259 meta->dst.surface_len, meta->dst.surface);
2260
2261 cmd_reserve_reloc(cmd, 1);
2262 cmd_surface_reloc(cmd, offset, 1,
2263 (struct intel_bo *) meta->dst.reloc_target,
2264 meta->dst.reloc_offset, meta->dst.reloc_flags);
2265
Mike Stroyan9bfad482015-02-10 15:09:23 -07002266 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002267 }
2268
2269 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002270 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002271 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002272 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002273
2274 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002275 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2276 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2277 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002278 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002279 } else {
2280 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002282 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002284 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002285 }
2286}
2287
2288static void gen6_meta_urb(struct intel_cmd *cmd)
2289{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002290 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002291 uint32_t *dw;
2292
2293 CMD_ASSERT(cmd, 6, 6);
2294
2295 /* 3DSTATE_URB */
2296 cmd_batch_pointer(cmd, 3, &dw);
2297 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002298 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002299 dw[2] = 0;
2300}
2301
2302static void gen7_meta_urb(struct intel_cmd *cmd)
2303{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002304 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2305 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002306 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002307 uint32_t *dw;
2308
2309 CMD_ASSERT(cmd, 7, 7.5);
2310
Chia-I Wu6032b892014-10-17 14:47:18 +08002311 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2312
Chia-I Wu24aa1022014-11-25 11:53:19 +08002313 switch (cmd_gen(cmd)) {
2314 case INTEL_GEN(7.5):
2315 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2316 break;
2317 case INTEL_GEN(7):
2318 default:
2319 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2320 break;
2321 }
2322
Chia-I Wu6032b892014-10-17 14:47:18 +08002323 /* 3DSTATE_URB_x */
2324 cmd_batch_pointer(cmd, 8, &dw);
2325
2326 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002327 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002328 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002329 dw += 2;
2330
2331 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002332 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002333 dw += 2;
2334
2335 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002336 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002337 dw += 2;
2338
2339 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002340 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002341 dw += 2;
2342}
2343
2344static void gen6_meta_vf(struct intel_cmd *cmd)
2345{
2346 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002347 uint32_t vb_start, vb_end, vb_stride;
2348 int ve_format, ve_z_source;
2349 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002350 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002351
2352 CMD_ASSERT(cmd, 6, 7.5);
2353
Chia-I Wu29e6f502014-11-24 14:27:29 +08002354 switch (meta->mode) {
2355 case INTEL_CMD_META_VS_POINTS:
2356 cmd_batch_pointer(cmd, 3, &dw);
2357 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002358 dw[1] = GEN6_VE_DW0_VALID;
2359 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2360 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2361 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2362 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002363 return;
2364 break;
2365 case INTEL_CMD_META_FS_RECT:
2366 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002367 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002368
Chia-I Wu29e6f502014-11-24 14:27:29 +08002369 vertices[0][0] = meta->dst.x + meta->width;
2370 vertices[0][1] = meta->dst.y + meta->height;
2371 vertices[1][0] = meta->dst.x;
2372 vertices[1][1] = meta->dst.y + meta->height;
2373 vertices[2][0] = meta->dst.x;
2374 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002375
Chia-I Wu29e6f502014-11-24 14:27:29 +08002376 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2377 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002378
Chia-I Wu29e6f502014-11-24 14:27:29 +08002379 vb_end = vb_start + sizeof(vertices) - 1;
2380 vb_stride = sizeof(vertices[0]);
2381 ve_z_source = GEN6_VFCOMP_STORE_0;
2382 ve_format = GEN6_FORMAT_R32G32_USCALED;
2383 }
2384 break;
2385 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2386 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002387 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002388
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002389 vertices[0][0] = (float) (meta->dst.x + meta->width);
2390 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002391 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002392 vertices[1][0] = (float) meta->dst.x;
2393 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002394 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002395 vertices[2][0] = (float) meta->dst.x;
2396 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002397 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002398
Chia-I Wu29e6f502014-11-24 14:27:29 +08002399 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2400 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002401
Chia-I Wu29e6f502014-11-24 14:27:29 +08002402 vb_end = vb_start + sizeof(vertices) - 1;
2403 vb_stride = sizeof(vertices[0]);
2404 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2405 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2406 }
2407 break;
2408 default:
2409 assert(!"unknown meta mode");
2410 return;
2411 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002412 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002413
2414 /* 3DSTATE_VERTEX_BUFFERS */
2415 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002416
Chia-I Wu6032b892014-10-17 14:47:18 +08002417 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002418 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002419 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002420 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002421
2422 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002423 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2424 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002425
2426 dw[4] = 0;
2427
2428 /* 3DSTATE_VERTEX_ELEMENTS */
2429 cmd_batch_pointer(cmd, 5, &dw);
2430 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002431 dw[1] = GEN6_VE_DW0_VALID;
2432 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2433 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2434 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2435 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2436 dw[3] = GEN6_VE_DW0_VALID |
2437 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2438 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2439 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2440 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2441 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002442}
2443
Chia-I Wu29e6f502014-11-24 14:27:29 +08002444static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002445{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002446 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002447 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002448 uint32_t consts[8];
2449 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002450
2451 CMD_ASSERT(cmd, 6, 7.5);
2452
2453 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002454 case INTEL_DEV_META_VS_FILL_MEM:
2455 consts[0] = meta->dst.x;
2456 consts[1] = meta->clear_val[0];
2457 const_count = 2;
2458 break;
2459 case INTEL_DEV_META_VS_COPY_MEM:
2460 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2461 consts[0] = meta->dst.x;
2462 consts[1] = meta->src.x;
2463 const_count = 2;
2464 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002465 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2466 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2467 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2468 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2469 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2470 consts[0] = meta->src.x;
2471 consts[1] = meta->src.y;
2472 consts[2] = meta->width;
2473 consts[3] = meta->dst.x;
2474 const_count = 4;
2475 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002476 default:
2477 assert(!"unknown meta shader id");
2478 const_count = 0;
2479 break;
2480 }
2481
2482 /* this can be skipped but it makes state dumping prettier */
2483 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2484
2485 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2486}
2487
2488static void gen6_meta_vs(struct intel_cmd *cmd)
2489{
2490 const struct intel_cmd_meta *meta = cmd->bind.meta;
2491 const struct intel_pipeline_shader *sh =
2492 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2493 uint32_t offset, *dw;
2494
2495 CMD_ASSERT(cmd, 6, 7.5);
2496
2497 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002498 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002499
2500 /* 3DSTATE_CONSTANT_VS */
2501 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2502 cmd_batch_pointer(cmd, cmd_len, &dw);
2503 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2504 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2505
2506 /* 3DSTATE_VS */
2507 cmd_batch_pointer(cmd, 6, &dw);
2508 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2509 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2510
2511 return;
2512 }
2513
2514 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2515
2516 /* 3DSTATE_CONSTANT_VS */
2517 offset = gen6_meta_vs_constants(cmd);
2518 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2519 cmd_batch_pointer(cmd, 7, &dw);
2520 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002521 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002522 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002523 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002524 dw[4] = 0;
2525 dw[5] = 0;
2526 dw[6] = 0;
2527 } else {
2528 cmd_batch_pointer(cmd, 5, &dw);
2529 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002530 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002531 dw[1] = offset;
2532 dw[2] = 0;
2533 dw[3] = 0;
2534 dw[4] = 0;
2535 }
2536
2537 /* 3DSTATE_VS */
2538 offset = emit_shader(cmd, sh);
2539 cmd_batch_pointer(cmd, 6, &dw);
2540 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2541 dw[1] = offset;
2542 dw[2] = GEN6_THREADDISP_SPF |
2543 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2544 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002545 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002546 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2547 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2548
2549 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2550 GEN6_VS_DW5_VS_ENABLE;
2551 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002552 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002554 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002555
2556 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002557}
2558
2559static void gen6_meta_disabled(struct intel_cmd *cmd)
2560{
Chia-I Wu6032b892014-10-17 14:47:18 +08002561 uint32_t *dw;
2562
2563 CMD_ASSERT(cmd, 6, 6);
2564
Chia-I Wu6032b892014-10-17 14:47:18 +08002565 /* 3DSTATE_CONSTANT_GS */
2566 cmd_batch_pointer(cmd, 5, &dw);
2567 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2568 dw[1] = 0;
2569 dw[2] = 0;
2570 dw[3] = 0;
2571 dw[4] = 0;
2572
2573 /* 3DSTATE_GS */
2574 cmd_batch_pointer(cmd, 7, &dw);
2575 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2576 dw[1] = 0;
2577 dw[2] = 0;
2578 dw[3] = 0;
2579 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2580 dw[5] = GEN6_GS_DW5_STATISTICS;
2581 dw[6] = 0;
2582
Chia-I Wu6032b892014-10-17 14:47:18 +08002583 /* 3DSTATE_SF */
2584 cmd_batch_pointer(cmd, 20, &dw);
2585 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2586 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2587 memset(&dw[2], 0, 18 * sizeof(*dw));
2588}
2589
2590static void gen7_meta_disabled(struct intel_cmd *cmd)
2591{
2592 uint32_t *dw;
2593
2594 CMD_ASSERT(cmd, 7, 7.5);
2595
Chia-I Wu6032b892014-10-17 14:47:18 +08002596 /* 3DSTATE_CONSTANT_HS */
2597 cmd_batch_pointer(cmd, 7, &dw);
2598 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2599 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2600
2601 /* 3DSTATE_HS */
2602 cmd_batch_pointer(cmd, 7, &dw);
2603 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2604 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2605
2606 /* 3DSTATE_TE */
2607 cmd_batch_pointer(cmd, 4, &dw);
2608 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2609 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2610
2611 /* 3DSTATE_CONSTANT_DS */
2612 cmd_batch_pointer(cmd, 7, &dw);
2613 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2614 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2615
2616 /* 3DSTATE_DS */
2617 cmd_batch_pointer(cmd, 6, &dw);
2618 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2619 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2620
2621 /* 3DSTATE_CONSTANT_GS */
2622 cmd_batch_pointer(cmd, 7, &dw);
2623 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2624 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2625
2626 /* 3DSTATE_GS */
2627 cmd_batch_pointer(cmd, 7, &dw);
2628 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2629 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2630
2631 /* 3DSTATE_STREAMOUT */
2632 cmd_batch_pointer(cmd, 3, &dw);
2633 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2634 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2635
Chia-I Wu6032b892014-10-17 14:47:18 +08002636 /* 3DSTATE_SF */
2637 cmd_batch_pointer(cmd, 7, &dw);
2638 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2639 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2640
2641 /* 3DSTATE_SBE */
2642 cmd_batch_pointer(cmd, 14, &dw);
2643 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2644 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2645 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002646}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002647
Chia-I Wu29e6f502014-11-24 14:27:29 +08002648static void gen6_meta_clip(struct intel_cmd *cmd)
2649{
2650 const struct intel_cmd_meta *meta = cmd->bind.meta;
2651 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002652
Chia-I Wu29e6f502014-11-24 14:27:29 +08002653 /* 3DSTATE_CLIP */
2654 cmd_batch_pointer(cmd, 4, &dw);
2655 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2656 dw[1] = 0;
2657 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2658 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2659 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2660 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002661 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002662 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002663 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002664}
2665
2666static void gen6_meta_wm(struct intel_cmd *cmd)
2667{
2668 const struct intel_cmd_meta *meta = cmd->bind.meta;
2669 uint32_t *dw;
2670
2671 CMD_ASSERT(cmd, 6, 7.5);
2672
2673 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2674
2675 /* 3DSTATE_MULTISAMPLE */
2676 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2677 cmd_batch_pointer(cmd, 4, &dw);
2678 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2679 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2680 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2681 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2682 dw[2] = 0;
2683 dw[3] = 0;
2684 } else {
2685 cmd_batch_pointer(cmd, 3, &dw);
2686 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2687 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2688 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2689 dw[2] = 0;
2690 }
2691
2692 /* 3DSTATE_SAMPLE_MASK */
2693 cmd_batch_pointer(cmd, 2, &dw);
2694 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2695 dw[1] = (1 << meta->samples) - 1;
2696
2697 /* 3DSTATE_DRAWING_RECTANGLE */
2698 cmd_batch_pointer(cmd, 4, &dw);
2699 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002700 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2701 /* unused */
2702 dw[1] = 0;
2703 dw[2] = 0;
2704 } else {
2705 dw[1] = meta->dst.y << 16 | meta->dst.x;
2706 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2707 (meta->dst.x + meta->width - 1);
2708 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002709 dw[3] = 0;
2710}
2711
2712static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2713{
2714 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002715 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002716 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002717 uint32_t consts[8];
2718 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002719
2720 CMD_ASSERT(cmd, 6, 7.5);
2721
2722 /* underflow is fine here */
2723 offset_x = meta->src.x - meta->dst.x;
2724 offset_y = meta->src.y - meta->dst.y;
2725
2726 switch (meta->shader_id) {
2727 case INTEL_DEV_META_FS_COPY_MEM:
2728 case INTEL_DEV_META_FS_COPY_1D:
2729 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2730 case INTEL_DEV_META_FS_COPY_2D:
2731 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2732 case INTEL_DEV_META_FS_COPY_2D_MS:
2733 consts[0] = offset_x;
2734 consts[1] = offset_y;
2735 consts[2] = meta->src.layer;
2736 consts[3] = meta->src.lod;
2737 const_count = 4;
2738 break;
2739 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2740 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2741 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2742 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2743 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2744 consts[0] = offset_x;
2745 consts[1] = offset_y;
2746 consts[2] = meta->src.layer;
2747 consts[3] = meta->src.lod;
2748 consts[4] = meta->src.x;
2749 consts[5] = meta->width;
2750 const_count = 6;
2751 break;
2752 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2753 consts[0] = offset_x;
2754 consts[1] = offset_y;
2755 consts[2] = meta->width;
2756 const_count = 3;
2757 break;
2758 case INTEL_DEV_META_FS_CLEAR_COLOR:
2759 consts[0] = meta->clear_val[0];
2760 consts[1] = meta->clear_val[1];
2761 consts[2] = meta->clear_val[2];
2762 consts[3] = meta->clear_val[3];
2763 const_count = 4;
2764 break;
2765 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2766 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002767 consts[1] = meta->clear_val[1];
2768 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002769 break;
2770 case INTEL_DEV_META_FS_RESOLVE_2X:
2771 case INTEL_DEV_META_FS_RESOLVE_4X:
2772 case INTEL_DEV_META_FS_RESOLVE_8X:
2773 case INTEL_DEV_META_FS_RESOLVE_16X:
2774 consts[0] = offset_x;
2775 consts[1] = offset_y;
2776 const_count = 2;
2777 break;
2778 default:
2779 assert(!"unknown meta shader id");
2780 const_count = 0;
2781 break;
2782 }
2783
2784 /* this can be skipped but it makes state dumping prettier */
2785 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2786
2787 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2788}
2789
2790static void gen6_meta_ps(struct intel_cmd *cmd)
2791{
2792 const struct intel_cmd_meta *meta = cmd->bind.meta;
2793 const struct intel_pipeline_shader *sh =
2794 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2795 uint32_t offset, *dw;
2796
2797 CMD_ASSERT(cmd, 6, 6);
2798
Chia-I Wu29e6f502014-11-24 14:27:29 +08002799 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2800 /* 3DSTATE_CONSTANT_PS */
2801 cmd_batch_pointer(cmd, 5, &dw);
2802 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2803 dw[1] = 0;
2804 dw[2] = 0;
2805 dw[3] = 0;
2806 dw[4] = 0;
2807
2808 /* 3DSTATE_WM */
2809 cmd_batch_pointer(cmd, 9, &dw);
2810 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2811 dw[1] = 0;
2812 dw[2] = 0;
2813 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002814
2815 switch (meta->ds.op) {
2816 case INTEL_CMD_META_DS_HIZ_CLEAR:
2817 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2818 break;
2819 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2820 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2821 break;
2822 case INTEL_CMD_META_DS_RESOLVE:
2823 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2824 break;
2825 default:
2826 dw[4] = 0;
2827 break;
2828 }
2829
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002830 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002831 dw[6] = 0;
2832 dw[7] = 0;
2833 dw[8] = 0;
2834
Chia-I Wu3adf7212014-10-24 15:34:07 +08002835 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002836 }
2837
Chia-I Wu3adf7212014-10-24 15:34:07 +08002838 /* a normal color write */
2839 assert(meta->dst.valid && !sh->uses);
2840
Chia-I Wu6032b892014-10-17 14:47:18 +08002841 /* 3DSTATE_CONSTANT_PS */
2842 offset = gen6_meta_ps_constants(cmd);
2843 cmd_batch_pointer(cmd, 5, &dw);
2844 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002845 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002846 dw[1] = offset;
2847 dw[2] = 0;
2848 dw[3] = 0;
2849 dw[4] = 0;
2850
2851 /* 3DSTATE_WM */
2852 offset = emit_shader(cmd, sh);
2853 cmd_batch_pointer(cmd, 9, &dw);
2854 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2855 dw[1] = offset;
2856 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2857 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002858 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002859 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002860 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002861 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2862 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002863
Chia-I Wu6032b892014-10-17 14:47:18 +08002864 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002865 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002866 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2867 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2868 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2869 if (meta->samples > 1) {
2870 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2871 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2872 } else {
2873 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2874 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2875 }
2876 dw[7] = 0;
2877 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002878
2879 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002880}
2881
2882static void gen7_meta_ps(struct intel_cmd *cmd)
2883{
2884 const struct intel_cmd_meta *meta = cmd->bind.meta;
2885 const struct intel_pipeline_shader *sh =
2886 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2887 uint32_t offset, *dw;
2888
2889 CMD_ASSERT(cmd, 7, 7.5);
2890
Chia-I Wu29e6f502014-11-24 14:27:29 +08002891 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2892 /* 3DSTATE_WM */
2893 cmd_batch_pointer(cmd, 3, &dw);
2894 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002895
2896 switch (meta->ds.op) {
2897 case INTEL_CMD_META_DS_HIZ_CLEAR:
2898 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2899 break;
2900 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2901 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2902 break;
2903 case INTEL_CMD_META_DS_RESOLVE:
2904 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2905 break;
2906 default:
2907 dw[1] = 0;
2908 break;
2909 }
2910
2911 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002912
2913 /* 3DSTATE_CONSTANT_GS */
2914 cmd_batch_pointer(cmd, 7, &dw);
2915 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2916 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2917
2918 /* 3DSTATE_PS */
2919 cmd_batch_pointer(cmd, 8, &dw);
2920 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2921 dw[1] = 0;
2922 dw[2] = 0;
2923 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002924 /* required to avoid hangs */
2925 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002926 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002927 dw[5] = 0;
2928 dw[6] = 0;
2929 dw[7] = 0;
2930
Chia-I Wu3adf7212014-10-24 15:34:07 +08002931 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002932 }
2933
Chia-I Wu3adf7212014-10-24 15:34:07 +08002934 /* a normal color write */
2935 assert(meta->dst.valid && !sh->uses);
2936
Chia-I Wu6032b892014-10-17 14:47:18 +08002937 /* 3DSTATE_WM */
2938 cmd_batch_pointer(cmd, 3, &dw);
2939 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002940 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002941 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2942 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2943 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2944 dw[2] = 0;
2945
2946 /* 3DSTATE_CONSTANT_PS */
2947 offset = gen6_meta_ps_constants(cmd);
2948 cmd_batch_pointer(cmd, 7, &dw);
2949 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002950 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002951 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002952 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08002953 dw[4] = 0;
2954 dw[5] = 0;
2955 dw[6] = 0;
2956
2957 /* 3DSTATE_PS */
2958 offset = emit_shader(cmd, sh);
2959 cmd_batch_pointer(cmd, 8, &dw);
2960 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2961 dw[1] = offset;
2962 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2963 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002964 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002965
2966 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2967 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002968 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002969
2970 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002971 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002972 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002973 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002974 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002975 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002976
2977 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2978 dw[6] = 0;
2979 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002980
2981 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002982}
2983
2984static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2985{
2986 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002987 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002988
2989 CMD_ASSERT(cmd, 6, 7.5);
2990
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002991 if (!ds) {
2992 /* all zeros */
2993 static const struct intel_ds_view null_ds;
2994 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002995 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002996
2997 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002998 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
2999 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
3000 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003001
3002 if (cmd_gen(cmd) >= INTEL_GEN(7))
3003 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3004 else
3005 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003006}
3007
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003008static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3009 const struct intel_pipeline *pipeline)
3010{
3011 cmd->bind.pipeline.graphics = pipeline;
3012}
3013
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003014static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3015 const struct intel_pipeline *pipeline)
3016{
3017 cmd->bind.pipeline.compute = pipeline;
3018}
3019
3020static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
3021 const struct intel_pipeline_delta *delta)
3022{
3023 cmd->bind.pipeline.graphics_delta = delta;
3024}
3025
3026static void cmd_bind_compute_delta(struct intel_cmd *cmd,
3027 const struct intel_pipeline_delta *delta)
3028{
3029 cmd->bind.pipeline.compute_delta = delta;
3030}
3031
3032static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003033 const struct intel_desc_set *dset,
3034 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003035{
Chia-I Wuf8385062015-01-04 16:27:24 +08003036 const uint32_t size = sizeof(*dynamic_offsets) *
3037 dset->layout->dynamic_desc_count;
3038
3039 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
3040 if (cmd->bind.dset.graphics_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003041 intel_free(cmd, cmd->bind.dset.graphics_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003042
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003043 cmd->bind.dset.graphics_dynamic_offsets = intel_alloc(cmd,
3044 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003045 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003046 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003047 return;
3048 }
3049
3050 cmd->bind.dset.graphics_dynamic_offset_size = size;
3051 }
3052
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003053 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003054 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003055}
3056
3057static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08003058 const struct intel_desc_set *dset,
3059 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003060{
Chia-I Wuf8385062015-01-04 16:27:24 +08003061 const uint32_t size = sizeof(*dynamic_offsets) *
3062 dset->layout->dynamic_desc_count;
3063
3064 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
3065 if (cmd->bind.dset.compute_dynamic_offsets)
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003066 intel_free(cmd, cmd->bind.dset.compute_dynamic_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003067
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08003068 cmd->bind.dset.compute_dynamic_offsets = intel_alloc(cmd,
3069 size, 4, XGL_SYSTEM_ALLOC_INTERNAL);
Chia-I Wuf8385062015-01-04 16:27:24 +08003070 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003071 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08003072 return;
3073 }
3074
3075 cmd->bind.dset.compute_dynamic_offset_size = size;
3076 }
3077
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003078 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08003079 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003080}
3081
Chia-I Wu3b04af52014-11-08 10:48:20 +08003082static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003083 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003084 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003085{
Chia-I Wu714df452015-01-01 07:55:04 +08003086 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003087 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003088 return;
3089 }
3090
Chia-I Wu714df452015-01-01 07:55:04 +08003091 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003092 cmd->bind.vertex.offset[binding] = offset;
3093}
3094
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003095static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003096 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003097 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3098{
Chia-I Wu714df452015-01-01 07:55:04 +08003099 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003100 cmd->bind.index.offset = offset;
3101 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003102}
3103
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003104static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003105 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003106{
3107 cmd->bind.state.viewport = state;
3108}
3109
3110static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003111 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003112{
3113 cmd->bind.state.raster = state;
3114}
3115
3116static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003117 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003118{
3119 cmd->bind.state.ds = state;
3120}
3121
3122static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003123 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124{
3125 cmd->bind.state.blend = state;
3126}
3127
Chia-I Wuf98dd882015-02-10 04:17:47 +08003128static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3129{
3130 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3131 struct intel_pipeline_rmap *rmaps[5] = {
3132 pipeline->vs.rmap,
3133 pipeline->tcs.rmap,
3134 pipeline->tes.rmap,
3135 pipeline->gs.rmap,
3136 pipeline->fs.rmap,
3137 };
3138 uint32_t max_write;
3139 int i;
3140
3141 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3142 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3143 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3144
3145 /* pad first */
3146 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3147
3148 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3149 const struct intel_pipeline_rmap *rmap = rmaps[i];
3150 const uint32_t surface_count = (rmap) ?
3151 rmap->rt_count + rmap->texture_resource_count +
3152 rmap->resource_count + rmap->uav_count : 0;
3153
3154 if (surface_count) {
3155 /* SURFACE_STATEs */
3156 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3157
3158 /* BINDING_TABLE_STATE */
3159 max_write += u_align(sizeof(uint32_t) * surface_count,
3160 GEN6_ALIGNMENT_SURFACE_STATE);
3161 }
3162 }
3163
3164 return max_write;
3165}
3166
3167static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3168{
3169 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3170 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3171 uint32_t max_surface_write;
3172
3173 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3174 if (cmd->bind.meta)
3175 max_surface_write = 64 * sizeof(uint32_t);
3176 else
3177 max_surface_write = cmd_get_max_surface_write(cmd);
3178
3179 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3180 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3181 /* SBA expects page-aligned addresses */
3182 writer->sba_offset = writer->used & ~0xfff;
3183
3184 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3185
3186 cmd_batch_state_base_address(cmd);
3187 }
3188}
3189
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003190static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003191 uint32_t vertex_start,
3192 uint32_t vertex_count,
3193 uint32_t instance_start,
3194 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003195 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003196 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003197{
3198 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003199 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003200 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3201
3202 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203
3204 emit_bounded_states(cmd);
3205
Chia-I Wuf98dd882015-02-10 04:17:47 +08003206 /* sanity check on cmd_get_max_surface_write() */
3207 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3208 surface_writer_used <= cmd_get_max_surface_write(cmd));
3209
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003210 if (indexed) {
3211 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003212 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213
3214 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3215 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3216 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003217 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003218 cmd->bind.index.offset, cmd->bind.index.type,
3219 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003220 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003221 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003222 cmd->bind.index.offset, cmd->bind.index.type,
3223 p->primitive_restart);
3224 }
3225 } else {
3226 assert(!vertex_base);
3227 }
3228
3229 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3230 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3231 vertex_start, instance_count, instance_start, vertex_base);
3232 } else {
3233 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3234 vertex_start, instance_count, instance_start, vertex_base);
3235 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003236
Chia-I Wu707a29e2014-08-27 12:51:47 +08003237 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003238 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003239 /* need to re-emit all workarounds */
3240 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003241
3242 if (intel_debug & INTEL_DEBUG_NOCACHE)
3243 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003244}
3245
Chia-I Wuc14d1562014-10-17 09:49:22 +08003246void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3247{
Chia-I Wu6032b892014-10-17 14:47:18 +08003248 cmd->bind.meta = meta;
3249
Chia-I Wuf98dd882015-02-10 04:17:47 +08003250 cmd_adjust_state_base_address(cmd);
3251
Chia-I Wu6032b892014-10-17 14:47:18 +08003252 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003253 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003254
3255 gen6_meta_dynamic_states(cmd);
3256 gen6_meta_surface_states(cmd);
3257
3258 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3259 gen7_meta_urb(cmd);
3260 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003261 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003262 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003263 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003264 gen6_meta_wm(cmd);
3265 gen7_meta_ps(cmd);
3266 gen6_meta_depth_buffer(cmd);
3267
3268 cmd_wa_gen7_post_command_cs_stall(cmd);
3269 cmd_wa_gen7_post_command_depth_stall(cmd);
3270
Chia-I Wu29e6f502014-11-24 14:27:29 +08003271 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3272 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003273 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003274 } else {
3275 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3276 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003277 } else {
3278 gen6_meta_urb(cmd);
3279 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003280 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003281 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003282 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003283 gen6_meta_wm(cmd);
3284 gen6_meta_ps(cmd);
3285 gen6_meta_depth_buffer(cmd);
3286
Chia-I Wu29e6f502014-11-24 14:27:29 +08003287 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3288 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003289 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003290 } else {
3291 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3292 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003293 }
3294
3295 cmd->bind.draw_count++;
3296 /* need to re-emit all workarounds */
3297 cmd->bind.wa_flags = 0;
3298
3299 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003300
Chia-I Wubbc7d912015-02-27 14:59:50 -07003301 /* make the normal path believe the render pass has changed */
3302 cmd->bind.render_pass_changed = true;
3303
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003304 if (intel_debug & INTEL_DEBUG_NOCACHE)
3305 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003306}
3307
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003308ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003309 XGL_CMD_BUFFER cmdBuffer,
3310 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3311 XGL_PIPELINE pipeline)
3312{
3313 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3314
3315 switch (pipelineBindPoint) {
3316 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003317 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003318 break;
3319 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003320 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003321 break;
3322 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003323 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003324 break;
3325 }
3326}
3327
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003328ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003329 XGL_CMD_BUFFER cmdBuffer,
3330 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3331 XGL_PIPELINE_DELTA delta)
3332{
3333 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3334
3335 switch (pipelineBindPoint) {
3336 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003337 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003338 break;
3339 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003340 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003341 break;
3342 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003343 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003344 break;
3345 }
3346}
3347
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003348ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003349 XGL_CMD_BUFFER cmdBuffer,
3350 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003351 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003352{
3353 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3354
3355 switch (stateBindPoint) {
3356 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003357 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003358 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003359 break;
3360 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003361 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003362 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003363 break;
3364 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003365 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003366 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003367 break;
3368 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003369 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003370 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003371 break;
3372 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003373 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003374 break;
3375 }
3376}
3377
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003378ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003379 XGL_CMD_BUFFER cmdBuffer,
3380 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003381 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003382 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003383{
3384 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003385 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003386
3387 switch (pipelineBindPoint) {
3388 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003389 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003390 break;
3391 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003392 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003393 break;
3394 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003395 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003396 break;
3397 }
3398}
3399
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003400ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003401 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003402 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003403 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003404 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003405{
3406 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003407 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003408
Chia-I Wu714df452015-01-01 07:55:04 +08003409 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003410}
3411
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003412ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003413 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003414 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003415 XGL_GPU_SIZE offset,
3416 XGL_INDEX_TYPE indexType)
3417{
3418 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003419 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003420
Chia-I Wu714df452015-01-01 07:55:04 +08003421 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003422}
3423
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003424ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003425 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003426 uint32_t firstVertex,
3427 uint32_t vertexCount,
3428 uint32_t firstInstance,
3429 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003430{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003431 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003432
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003433 cmd_draw(cmd, firstVertex, vertexCount,
3434 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003435}
3436
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003437ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003438 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003439 uint32_t firstIndex,
3440 uint32_t indexCount,
3441 int32_t vertexOffset,
3442 uint32_t firstInstance,
3443 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003444{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003445 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003446
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003447 cmd_draw(cmd, firstIndex, indexCount,
3448 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003449}
3450
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003451ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003452 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003453 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003454 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003455 uint32_t count,
3456 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003457{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003458 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3459
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003460 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003461}
3462
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003463ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003464 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003465 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003466 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003467 uint32_t count,
3468 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003469{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003470 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3471
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003472 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003473}
3474
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003475ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003476 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003477 uint32_t x,
3478 uint32_t y,
3479 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003480{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003481 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3482
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003483 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003484}
3485
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003486ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003487 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003488 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003489 XGL_GPU_SIZE offset)
3490{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003491 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3492
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003493 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003494}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003495
Chia-I Wude26bdf2015-02-18 15:47:12 -07003496ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003497 XGL_CMD_BUFFER cmdBuffer,
3498 XGL_RENDER_PASS renderPass)
3499{
3500 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3501
3502 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3503}
3504
Chia-I Wude26bdf2015-02-18 15:47:12 -07003505ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003506 XGL_CMD_BUFFER cmdBuffer,
3507 XGL_RENDER_PASS renderPass)
3508{
3509 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3510
3511 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3512}