blob: 23fcae9f2186234e6ad9004630f11e0809c29c20 [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;
109 XGL_UINT 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;
Chia-I Wu72292b72014-09-09 10:48:33 +0800247 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
273 cmd->result = XGL_ERROR_INVALID_VALUE;
274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
279 cmd->result = XGL_ERROR_INVALID_VALUE;
280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
350 XGL_UINT width, XGL_UINT height)
351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700394 switch (pipeline->db_format) {
395 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700398 case XGL_FMT_D32_SFLOAT:
399 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 if (pipeline->scissor_enable)
Chia-I Wu8016a172014-08-29 18:31:32 +0800422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
GregF8cd81832014-11-18 18:01:01 -0700446 XGL_UINT sbe_offset;
447 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700501 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800502 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503
504 CMD_ASSERT(cmd, 6, 7.5);
505
506 dw1 = GEN6_CLIP_DW1_STATISTICS;
507 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
508 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
509 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 }
512
513 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
514 GEN6_CLIP_DW2_XY_TEST_ENABLE |
515 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700516 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800517 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
518 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
520
521 if (pipeline->rasterizerDiscardEnable)
522 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
523 else
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
525
526 if (pipeline->depthClipEnable)
527 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
528
529 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
530 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
531 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
532 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
533
534 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
535 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
536 (viewport->viewport_count - 1);
537
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600538 /* TODO: framebuffer requests layer_count > 1 */
539 if (cmd->bind.render_pass->fb->layer_count == 1) {
540 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
541 }
542
Chia-I Wu72292b72014-09-09 10:48:33 +0800543 cmd_batch_pointer(cmd, cmd_len, &dw);
544 dw[0] = dw0;
545 dw[1] = dw1;
546 dw[2] = dw2;
547 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800548}
549
Chia-I Wu784d3042014-12-19 14:30:04 +0800550static void gen6_add_scratch_space(struct intel_cmd *cmd,
551 XGL_UINT batch_pos,
552 const struct intel_pipeline *pipeline,
553 const struct intel_pipeline_shader *sh)
554{
555 int scratch_space;
556
557 CMD_ASSERT(cmd, 6, 7.5);
558
559 assert(sh->per_thread_scratch_size &&
560 sh->per_thread_scratch_size % 1024 == 0 &&
561 u_is_pow2(sh->per_thread_scratch_size) &&
562 sh->scratch_offset % 1024 == 0);
563 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
564
565 cmd_reserve_reloc(cmd, 1);
566 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
567 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
568}
569
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800570static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
571{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800573 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800575 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800576 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800577
578 CMD_ASSERT(cmd, 6, 6);
579
580 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
581
582 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
583 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
584
585 dw4 = GEN6_WM_DW4_STATISTICS |
586 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
587 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
588 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
589
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800590 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800591 GEN6_WM_DW5_PS_ENABLE |
592 GEN6_WM_DW5_8_PIXEL_DISPATCH;
593
594 if (fs->uses & INTEL_SHADER_USE_KILL ||
595 pipeline->cb_state.alphaToCoverageEnable)
596 dw5 |= GEN6_WM_DW5_PS_KILL;
597
Cody Northrope238deb2015-01-26 14:41:36 -0700598 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800599 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
600 if (fs->uses & INTEL_SHADER_USE_DEPTH)
601 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
602 if (fs->uses & INTEL_SHADER_USE_W)
603 dw5 |= GEN6_WM_DW5_PS_USE_W;
604
605 if (pipeline->cb_state.dualSourceBlendEnable)
606 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
607
608 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
609 GEN6_WM_DW6_POSOFFSET_NONE |
610 GEN6_WM_DW6_ZW_INTERP_PIXEL |
611 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
612 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
613
Tony Barbourfa6cac72015-01-16 14:27:35 -0700614 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800615 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
616 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
617 } else {
618 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
619 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
620 }
621
Chia-I Wu784d3042014-12-19 14:30:04 +0800622 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800623 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800624 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800625 dw[2] = dw2;
626 dw[3] = 0; /* scratch */
627 dw[4] = dw4;
628 dw[5] = dw5;
629 dw[6] = dw6;
630 dw[7] = 0; /* kernel 1 */
631 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800632
633 if (fs->per_thread_scratch_size)
634 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635}
636
637static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
638{
639 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800640 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800642 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643
644 CMD_ASSERT(cmd, 7, 7.5);
645
646 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
647
648 dw1 = GEN7_WM_DW1_STATISTICS |
649 GEN7_WM_DW1_PS_ENABLE |
650 GEN7_WM_DW1_ZW_INTERP_PIXEL |
651 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
652 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
653
654 if (fs->uses & INTEL_SHADER_USE_KILL ||
655 pipeline->cb_state.alphaToCoverageEnable)
656 dw1 |= GEN7_WM_DW1_PS_KILL;
657
Cody Northrope238deb2015-01-26 14:41:36 -0700658 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
659
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660 if (fs->uses & INTEL_SHADER_USE_DEPTH)
661 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
662 if (fs->uses & INTEL_SHADER_USE_W)
663 dw1 |= GEN7_WM_DW1_PS_USE_W;
664
665 dw2 = 0;
666
Tony Barbourfa6cac72015-01-16 14:27:35 -0700667 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
669 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
670 } else {
671 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
672 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
673 }
674
Chia-I Wu72292b72014-09-09 10:48:33 +0800675 cmd_batch_pointer(cmd, cmd_len, &dw);
676 dw[0] = dw0;
677 dw[1] = dw1;
678 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679}
680
681static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
682{
683 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800684 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800687 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688
689 CMD_ASSERT(cmd, 7, 7.5);
690
691 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
692
693 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
694 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
695
696 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
697 GEN7_PS_DW4_8_PIXEL_DISPATCH;
698
699 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800700 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700701 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800702 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800703 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 }
705
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706 if (fs->in_count)
707 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
708
709 if (pipeline->cb_state.dualSourceBlendEnable)
710 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
711
712 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
713 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
714 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
715
Chia-I Wu784d3042014-12-19 14:30:04 +0800716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800718 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800719 dw[2] = dw2;
720 dw[3] = 0; /* scratch */
721 dw[4] = dw4;
722 dw[5] = dw5;
723 dw[6] = 0; /* kernel 1 */
724 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800725
726 if (fs->per_thread_scratch_size)
727 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800728}
729
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800730static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
731 const struct intel_ds_view *view)
732{
733 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800734 uint32_t dw0, *dw;
735 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800736
737 CMD_ASSERT(cmd, 6, 7.5);
738
739 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800740 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
741 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800742 dw0 |= (cmd_len - 2);
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
746 dw[1] = view->cmd[0];
747 dw[2] = 0;
748 dw[3] = view->cmd[2];
749 dw[4] = view->cmd[3];
750 dw[5] = view->cmd[4];
751 dw[6] = view->cmd[5];
752
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600753 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800754 cmd_reserve_reloc(cmd, 1);
755 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
756 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600757 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800758}
759
760static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
761 const struct intel_ds_view *view)
762{
763 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800764 uint32_t dw0, *dw;
765 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766
767 CMD_ASSERT(cmd, 6, 7.5);
768
769 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800770 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
771 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800772 dw0 |= (cmd_len - 2);
773
Chia-I Wu72292b72014-09-09 10:48:33 +0800774 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
775 dw[0] = dw0;
776 dw[1] = view->cmd[6];
777 dw[2] = 0;
778
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600779 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600783 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784}
785
786static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
787 const struct intel_ds_view *view)
788{
789 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 uint32_t dw0, *dw;
791 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792
793 CMD_ASSERT(cmd, 6, 7.5);
794
795 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800796 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
797 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798 dw0 |= (cmd_len - 2);
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
801 dw[0] = dw0;
802 dw[1] = view->cmd[8];
803 dw[2] = 0;
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
Chia-I Wuf8231032014-08-25 10:44:45 +0800812static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
813 uint32_t clear_val)
814{
815 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800816 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800817 GEN6_CLEAR_PARAMS_DW0_VALID |
818 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800819 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800820
821 CMD_ASSERT(cmd, 6, 6);
822
Chia-I Wu72292b72014-09-09 10:48:33 +0800823 cmd_batch_pointer(cmd, cmd_len, &dw);
824 dw[0] = dw0;
825 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800826}
827
828static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
829 uint32_t clear_val)
830{
831 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800832 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800833 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800835
836 CMD_ASSERT(cmd, 7, 7.5);
837
Chia-I Wu72292b72014-09-09 10:48:33 +0800838 cmd_batch_pointer(cmd, cmd_len, &dw);
839 dw[0] = dw0;
840 dw[1] = clear_val;
841 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800842}
843
Chia-I Wu302742d2014-08-22 10:28:29 +0800844static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t blend_offset,
846 uint32_t ds_offset,
847 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800848{
849 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800851
852 CMD_ASSERT(cmd, 6, 6);
853
Chia-I Wu426072d2014-08-26 14:31:55 +0800854 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800855 (cmd_len - 2);
856
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 cmd_batch_pointer(cmd, cmd_len, &dw);
858 dw[0] = dw0;
859 dw[1] = blend_offset | 1;
860 dw[2] = ds_offset | 1;
861 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800862}
863
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t clip_offset,
866 uint32_t sf_offset,
867 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868{
869 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu426072d2014-08-26 14:31:55 +0800874 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875 GEN6_PTR_VP_DW0_CLIP_CHANGED |
876 GEN6_PTR_VP_DW0_SF_CHANGED |
877 GEN6_PTR_VP_DW0_CC_CHANGED |
878 (cmd_len - 2);
879
Chia-I Wu72292b72014-09-09 10:48:33 +0800880 cmd_batch_pointer(cmd, cmd_len, &dw);
881 dw[0] = dw0;
882 dw[1] = clip_offset;
883 dw[2] = sf_offset;
884 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885}
886
887static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889{
890 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892
893 CMD_ASSERT(cmd, 6, 6);
894
Chia-I Wu426072d2014-08-26 14:31:55 +0800895 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896 (cmd_len - 2);
897
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 cmd_batch_pointer(cmd, cmd_len, &dw);
899 dw[0] = dw0;
900 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800901}
902
Chia-I Wu42a56202014-08-23 16:47:48 +0800903static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t vs_offset,
905 uint32_t gs_offset,
906 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800907{
908 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800910
911 CMD_ASSERT(cmd, 6, 6);
912
Chia-I Wu426072d2014-08-26 14:31:55 +0800913 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800914 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
915 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
916 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
917 (cmd_len - 2);
918
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 cmd_batch_pointer(cmd, cmd_len, &dw);
920 dw[0] = dw0;
921 dw[1] = vs_offset;
922 dw[2] = gs_offset;
923 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800924}
925
Chia-I Wu257e75e2014-08-29 14:06:35 +0800926static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t vs_offset,
928 uint32_t gs_offset,
929 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930{
931 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800933
934 CMD_ASSERT(cmd, 6, 6);
935
936 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
937 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
938 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
939 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
940 (cmd_len - 2);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = vs_offset;
945 dw[2] = gs_offset;
946 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800947}
948
Chia-I Wu302742d2014-08-22 10:28:29 +0800949static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800951{
952 const uint8_t cmd_len = 2;
953 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
954 GEN6_RENDER_SUBTYPE_3D |
955 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 cmd_batch_pointer(cmd, cmd_len, &dw);
959 dw[0] = dw0;
960 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800961}
962
Chia-I Wua6c4f152014-12-02 04:19:58 +0800963static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800964{
Chia-I Wue6073342014-11-30 09:43:42 +0800965 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700966 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
967 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800968
969 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700970 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800971
Tony Barbourfa6cac72015-01-16 14:27:35 -0700972 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800973}
974
Chia-I Wu72292b72014-09-09 10:48:33 +0800975static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700976 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800977{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800979 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800980 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700981 uint32_t dw[3];
982
983 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700984 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700985 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700986 (state->ds_info.stencilWriteMask & 0xff) << 16 |
987 (state->ds_info.stencilReadMask & 0xff) << 8 |
988 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700989 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
991 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992
993 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
994 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800995
Chia-I Wu00b51a82014-09-09 12:07:37 +0800996 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700997 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800998}
999
Chia-I Wu72292b72014-09-09 10:48:33 +08001000static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001001 uint32_t stencil_ref,
1002 const uint32_t blend_color[4])
1003{
Chia-I Wue6073342014-11-30 09:43:42 +08001004 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001007
1008 CMD_ASSERT(cmd, 6, 7.5);
1009
Chia-I Wu00b51a82014-09-09 12:07:37 +08001010 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1011 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001012 dw[0] = stencil_ref;
1013 dw[1] = 0;
1014 dw[2] = blend_color[0];
1015 dw[3] = blend_color[1];
1016 dw[4] = blend_color[2];
1017 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001018
Chia-I Wu72292b72014-09-09 10:48:33 +08001019 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001020}
1021
Chia-I Wu8370b402014-08-29 12:28:37 +08001022static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001023{
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 CMD_ASSERT(cmd, 6, 7.5);
1025
Chia-I Wu707a29e2014-08-27 12:51:47 +08001026 if (!cmd->bind.draw_count)
1027 return;
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030 return;
1031
Chia-I Wu8370b402014-08-29 12:28:37 +08001032 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001033
1034 /*
1035 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1036 *
1037 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1038 * pipe-control with a post-sync op and no write-cache flushes."
1039 *
1040 * The workaround below necessitates this workaround.
1041 */
1042 gen6_PIPE_CONTROL(cmd,
1043 GEN6_PIPE_CONTROL_CS_STALL |
1044 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001045 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001046
Chia-I Wud6d079d2014-08-31 13:14:21 +08001047 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1048 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001049}
1050
Chia-I Wu8370b402014-08-29 12:28:37 +08001051static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001052{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053 CMD_ASSERT(cmd, 6, 7.5);
1054
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001055 if (!cmd->bind.draw_count)
1056 return;
1057
Chia-I Wud6d079d2014-08-31 13:14:21 +08001058 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1059 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001060}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001061
Chia-I Wu8370b402014-08-29 12:28:37 +08001062static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1063{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001064 CMD_ASSERT(cmd, 7, 7.5);
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066 if (!cmd->bind.draw_count)
1067 return;
1068
1069 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001070
1071 gen6_PIPE_CONTROL(cmd,
1072 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001073 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001074}
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1077{
1078 CMD_ASSERT(cmd, 7, 7.5);
1079
1080 if (!cmd->bind.draw_count)
1081 return;
1082
1083 /*
1084 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1085 *
1086 * "One of the following must also be set (when CS stall is set):
1087 *
1088 * * Render Target Cache Flush Enable ([12] of DW1)
1089 * * Depth Cache Flush Enable ([0] of DW1)
1090 * * Stall at Pixel Scoreboard ([1] of DW1)
1091 * * Depth Stall ([13] of DW1)
1092 * * Post-Sync Operation ([13] of DW1)"
1093 */
1094 gen6_PIPE_CONTROL(cmd,
1095 GEN6_PIPE_CONTROL_CS_STALL |
1096 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001097 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001098}
1099
1100static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1101{
1102 CMD_ASSERT(cmd, 7, 7.5);
1103
1104 if (!cmd->bind.draw_count)
1105 return;
1106
1107 cmd_wa_gen6_pre_depth_stall_write(cmd);
1108
Chia-I Wud6d079d2014-08-31 13:14:21 +08001109 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001110}
1111
1112static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1113{
1114 CMD_ASSERT(cmd, 6, 7.5);
1115
1116 if (!cmd->bind.draw_count)
1117 return;
1118
1119 /*
1120 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1121 *
1122 * "Driver must guarentee that all the caches in the depth pipe are
1123 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1124 * requires driver to send a PIPE_CONTROL with a CS stall along with
1125 * a Depth Flush prior to this command."
1126 *
1127 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1128 *
1129 * "Driver must ierarchi that all the caches in the depth pipe are
1130 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1131 * requires driver to send a PIPE_CONTROL with a CS stall along with
1132 * a Depth Flush prior to this command.
1133 */
1134 gen6_PIPE_CONTROL(cmd,
1135 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1136 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001137 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001138}
1139
1140static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1141{
1142 CMD_ASSERT(cmd, 6, 7.5);
1143
1144 if (!cmd->bind.draw_count)
1145 return;
1146
1147 /*
1148 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1149 *
1150 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1151 * and a post sync operation prior to the group of depth
1152 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1153 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1154 *
1155 * This workaround satifies all the conditions.
1156 */
1157 cmd_wa_gen6_pre_depth_stall_write(cmd);
1158
1159 /*
1160 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1161 *
1162 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1163 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1164 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1165 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1166 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1167 * Depth Flush Bit set, followed by another pipelined depth stall
1168 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1169 * guarantee that the pipeline from WM onwards is already flushed
1170 * (e.g., via a preceding MI_FLUSH)."
1171 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001172 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1173 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1174 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001175}
1176
Chia-I Wu525c6602014-08-27 10:22:34 +08001177void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1178{
1179 if (!cmd->bind.draw_count)
1180 return;
1181
1182 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1183
Chia-I Wu8370b402014-08-29 12:28:37 +08001184 /*
1185 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1186 *
1187 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1188 * PIPE_CONTROL with any non-zero post-sync-op is required."
1189 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001190 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001191 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001192
Chia-I Wu092279a2014-08-30 19:05:30 +08001193 /*
1194 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1195 *
1196 * "One of the following must also be set (when CS stall is set):
1197 *
1198 * * Render Target Cache Flush Enable ([12] of DW1)
1199 * * Depth Cache Flush Enable ([0] of DW1)
1200 * * Stall at Pixel Scoreboard ([1] of DW1)
1201 * * Depth Stall ([13] of DW1)
1202 * * Post-Sync Operation ([13] of DW1)"
1203 */
1204 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1205 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1206 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1207 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1208 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1209 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1210
Chia-I Wud6d079d2014-08-31 13:14:21 +08001211 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001212}
1213
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001214void cmd_batch_flush_all(struct intel_cmd *cmd)
1215{
1216 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1217 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1218 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1219 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1220 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1221 GEN6_PIPE_CONTROL_CS_STALL);
1222}
1223
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001224void cmd_batch_depth_count(struct intel_cmd *cmd,
1225 struct intel_bo *bo,
1226 XGL_GPU_SIZE offset)
1227{
1228 cmd_wa_gen6_pre_depth_stall_write(cmd);
1229
1230 gen6_PIPE_CONTROL(cmd,
1231 GEN6_PIPE_CONTROL_DEPTH_STALL |
1232 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001233 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001234}
1235
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001236void cmd_batch_timestamp(struct intel_cmd *cmd,
1237 struct intel_bo *bo,
1238 XGL_GPU_SIZE offset)
1239{
1240 /* need any WA or stall? */
1241 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1242}
1243
1244void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001245 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001246 struct intel_bo *bo,
1247 XGL_GPU_SIZE offset,
1248 uint64_t val)
1249{
1250 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001251 gen6_PIPE_CONTROL(cmd,
1252 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1253 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001254}
1255
Chia-I Wu302742d2014-08-22 10:28:29 +08001256static void gen6_cc_states(struct intel_cmd *cmd)
1257{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001258 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1259 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001260 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001261 uint32_t stencil_ref;
1262 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001263
1264 CMD_ASSERT(cmd, 6, 6);
1265
Chia-I Wua6c4f152014-12-02 04:19:58 +08001266 blend_offset = gen6_BLEND_STATE(cmd);
1267
1268 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001269 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001270 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001271 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272
1273 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001274 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001275 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1276 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001277 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001278 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001279 stencil_ref = 0;
1280 }
1281
Chia-I Wu72292b72014-09-09 10:48:33 +08001282 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001283
Chia-I Wu72292b72014-09-09 10:48:33 +08001284 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001285}
1286
Chia-I Wu1744cca2014-08-22 11:10:17 +08001287static void gen6_viewport_states(struct intel_cmd *cmd)
1288{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001289 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001290 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001291
1292 if (!viewport)
1293 return;
1294
Tony Barbourfa6cac72015-01-16 14:27:35 -07001295 assert(viewport->cmd_len == (8 + 4 + 2) *
1296 viewport->viewport_count + (viewport->has_scissor_rects) ?
1297 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001298
1299 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001300 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001301 viewport->cmd);
1302
1303 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001304 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001305 &viewport->cmd[viewport->cmd_clip_pos]);
1306
1307 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001308 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001309 &viewport->cmd[viewport->cmd_cc_pos]);
1310
Tony Barbourfa6cac72015-01-16 14:27:35 -07001311 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001312 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001313 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001314 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1315 } else {
1316 scissor_offset = 0;
1317 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001318
1319 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001320 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001321
Chia-I Wub1d450a2014-09-09 13:48:03 +08001322 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001323}
1324
Chia-I Wu302742d2014-08-22 10:28:29 +08001325static void gen7_cc_states(struct intel_cmd *cmd)
1326{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001327 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1328 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001329 uint32_t stencil_ref;
1330 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001331 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001332
1333 CMD_ASSERT(cmd, 7, 7.5);
1334
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001335 if (!blend && !ds)
1336 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001337
Chia-I Wua6c4f152014-12-02 04:19:58 +08001338 offset = gen6_BLEND_STATE(cmd);
1339 gen7_3dstate_pointer(cmd,
1340 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001341
Chia-I Wua6c4f152014-12-02 04:19:58 +08001342 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001343 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001344 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001345 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001346
1347 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001348 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001349 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1350 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001352 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1353 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001354 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1355 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001356 } else {
1357 stencil_ref = 0;
1358 }
1359
Chia-I Wu72292b72014-09-09 10:48:33 +08001360 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001361 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001362 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001363}
1364
Chia-I Wu1744cca2014-08-22 11:10:17 +08001365static void gen7_viewport_states(struct intel_cmd *cmd)
1366{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001367 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1368 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001370
1371 if (!viewport)
1372 return;
1373
Tony Barbourfa6cac72015-01-16 14:27:35 -07001374 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001375 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376
Chia-I Wub1d450a2014-09-09 13:48:03 +08001377 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001378 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001379 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001380 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001381 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1382 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001383
1384 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001385 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 gen7_3dstate_pointer(cmd,
1388 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001390
Tony Barbourfa6cac72015-01-16 14:27:35 -07001391 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001393 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001394 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001395 gen7_3dstate_pointer(cmd,
1396 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001397 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001398 }
1399}
1400
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001401static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001402 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001403{
1404 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001405 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001406
Chia-I Wu72292b72014-09-09 10:48:33 +08001407 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001408
1409 dw[0] = GEN6_RENDER_TYPE_RENDER |
1410 GEN6_RENDER_SUBTYPE_3D |
1411 subop | (cmd_len - 2);
1412 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001413 dw[2] = 0;
1414 dw[3] = 0;
1415 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001416}
1417
1418static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001419 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001420{
1421 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001422 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001423
Chia-I Wu72292b72014-09-09 10:48:33 +08001424 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001425
1426 dw[0] = GEN6_RENDER_TYPE_RENDER |
1427 GEN6_RENDER_SUBTYPE_3D |
1428 subop | (cmd_len - 2);
1429 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001430 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001431 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001432 dw[4] = 0;
1433 dw[5] = 0;
1434 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001435}
1436
Chia-I Wu625105f2014-10-13 15:35:29 +08001437static uint32_t emit_samplers(struct intel_cmd *cmd,
1438 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001439{
1440 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1441 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001442 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001443 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001444 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001445 XGL_UINT i;
1446
1447 CMD_ASSERT(cmd, 6, 7.5);
1448
Chia-I Wu625105f2014-10-13 15:35:29 +08001449 if (!rmap || !rmap->sampler_count)
1450 return 0;
1451
Cody Northrop40316a32014-12-09 19:08:33 -07001452 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001453
Chia-I Wudcb509d2014-12-10 08:53:10 +08001454 /*
1455 * note that we cannot call cmd_state_pointer() here as the following
1456 * cmd_state_pointer() would invalidate the pointer
1457 */
1458 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001459 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001460 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001461
1462 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001463 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001464 4 * rmap->sampler_count, &sampler_dw);
1465
Chia-I Wudcb509d2014-12-10 08:53:10 +08001466 cmd_state_update(cmd, border_offset,
1467 border_stride * rmap->sampler_count, &border_dw);
1468
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001469 for (i = 0; i < rmap->sampler_count; i++) {
1470 const struct intel_pipeline_rmap_slot *slot =
1471 &rmap->slots[surface_count + i];
1472 const struct intel_sampler *sampler;
1473
Chia-I Wuf8385062015-01-04 16:27:24 +08001474 switch (slot->type) {
1475 case INTEL_PIPELINE_RMAP_SAMPLER:
1476 intel_desc_pool_read_sampler(cmd->dev->desc_pool,
1477 &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001479 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001480 sampler = NULL;
1481 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001482 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001483 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001484 sampler = NULL;
1485 break;
1486 }
1487
1488 if (sampler) {
1489 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1490
1491 sampler_dw[0] = sampler->cmd[0];
1492 sampler_dw[1] = sampler->cmd[1];
1493 sampler_dw[2] = border_offset;
1494 sampler_dw[3] = sampler->cmd[2];
1495 } else {
1496 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1497 sampler_dw[1] = 0;
1498 sampler_dw[2] = 0;
1499 sampler_dw[3] = 0;
1500 }
1501
1502 border_offset += border_stride * 4;
1503 border_dw += border_stride;
1504 sampler_dw += 4;
1505 }
1506
Chia-I Wu625105f2014-10-13 15:35:29 +08001507 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001508}
1509
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001510static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001511 const struct intel_pipeline_rmap *rmap,
1512 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001513{
Chia-I Wu72292b72014-09-09 10:48:33 +08001514 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001515 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001516
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001517 CMD_ASSERT(cmd, 6, 7.5);
1518
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001519 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001520 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001521 if (!surface_count)
1522 return 0;
1523
Chia-I Wu42a56202014-08-23 16:47:48 +08001524 assert(surface_count <= ARRAY_SIZE(binding_table));
1525
1526 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001527 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001528 struct intel_null_view null_view;
1529 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001530
Chia-I Wuf8385062015-01-04 16:27:24 +08001531 switch (slot->type) {
1532 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001533 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001534 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001535 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1536 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001537
Chia-I Wu787a05b2014-12-05 11:02:20 +08001538 if (view) {
1539 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1540 GEN6_ALIGNMENT_SURFACE_STATE,
1541 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001542
Chia-I Wu787a05b2014-12-05 11:02:20 +08001543 cmd_reserve_reloc(cmd, 1);
1544 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1545 view->cmd[1], INTEL_RELOC_WRITE);
1546 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001547 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001548 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001549 }
1550 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001551 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001552 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001553 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1554 const struct intel_mem *mem;
1555 bool read_only;
1556 const uint32_t *cmd_data;
1557 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001558
Chia-I Wuf8385062015-01-04 16:27:24 +08001559 assert(dyn_idx < 0 || dyn_idx <
1560 cmd->bind.dset.graphics->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001561
Chia-I Wuf8385062015-01-04 16:27:24 +08001562 intel_desc_pool_read_surface(cmd->dev->desc_pool,
1563 &slot->u.surface.offset, stage, &mem,
1564 &read_only, &cmd_data, &cmd_len);
1565 if (mem) {
1566 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1567 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1568 const uint32_t reloc_flags =
1569 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001570
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001571 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001572 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001573 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001574
1575 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001576 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1577 cmd_data[1] + dynamic_offset, reloc_flags);
1578 } else {
1579 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001580 }
1581 }
1582 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001583 case INTEL_PIPELINE_RMAP_UNUSED:
1584 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001585 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001586 default:
1587 assert(!"unexpected rmap type");
1588 need_null_view = true;
1589 break;
1590 }
1591
1592 if (need_null_view) {
1593 intel_null_view_init(&null_view, cmd->dev);
1594 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1595 GEN6_ALIGNMENT_SURFACE_STATE,
1596 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001597 }
1598
Chia-I Wu72292b72014-09-09 10:48:33 +08001599 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001600 }
1601
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001602 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001603 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001604 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001605}
1606
Chia-I Wu1d125092014-10-08 08:49:38 +08001607static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1608{
1609 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001610 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1611 uint32_t *dw;
1612 XGL_UINT pos, i;
1613
1614 CMD_ASSERT(cmd, 6, 7.5);
1615
1616 if (!pipeline->vb_count)
1617 return;
1618
1619 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1620
1621 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1622 dw++;
1623 pos++;
1624
1625 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001626 assert(pipeline->vb[i].strideInBytes <= 2048);
1627
1628 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1629 pipeline->vb[i].strideInBytes;
1630
1631 if (cmd_gen(cmd) >= INTEL_GEN(7))
1632 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1633
1634 switch (pipeline->vb[i].stepRate) {
1635 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1636 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1637 dw[3] = 0;
1638 break;
1639 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1640 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1641 dw[3] = 1;
1642 break;
1643 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1644 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1645 dw[3] = 0;
1646 break;
1647 default:
1648 assert(!"unknown step rate");
1649 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1650 dw[3] = 0;
1651 break;
1652 }
1653
Chia-I Wu714df452015-01-01 07:55:04 +08001654 if (cmd->bind.vertex.buf[i]) {
1655 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001656 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001657
1658 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001659 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1660 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001661 } else {
1662 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1663 dw[1] = 0;
1664 dw[2] = 0;
1665 }
1666
1667 dw += 4;
1668 pos += 4;
1669 }
1670}
1671
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001672static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1673{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001674 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1675 const struct intel_pipeline_shader *vs = &pipeline->vs;
1676 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001677 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001678 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001679 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001680 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001681
1682 CMD_ASSERT(cmd, 6, 7.5);
1683
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001684 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001685 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1686 *
1687 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1688 * 128-bit vertex elements to be passed into the payload for each
1689 * vertex."
1690 *
1691 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1692 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001693 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001694 vue_read_len = (vs->in_count + 1) / 2;
1695 if (!vue_read_len)
1696 vue_read_len = 1;
1697
1698 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1699 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1700
1701 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1702 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1703 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001704
1705 dw5 = GEN6_VS_DW5_STATISTICS |
1706 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001707
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001708 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001709 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001710 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001711 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001712
Chia-I Wube0a3d92014-09-02 13:20:59 +08001713 if (pipeline->disable_vs_cache)
1714 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1715
Chia-I Wu784d3042014-12-19 14:30:04 +08001716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001718 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001719 dw[2] = dw2;
1720 dw[3] = 0; /* scratch */
1721 dw[4] = dw4;
1722 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001723
1724 if (vs->per_thread_scratch_size)
1725 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001726}
1727
Chia-I Wu625105f2014-10-13 15:35:29 +08001728static void emit_shader_resources(struct intel_cmd *cmd)
1729{
1730 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001731 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001732
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001733 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001734 cmd->bind.pipeline.graphics->vs.rmap,
1735 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001736 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001737 cmd->bind.pipeline.graphics->tcs.rmap,
1738 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001739 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001740 cmd->bind.pipeline.graphics->tes.rmap,
1741 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001742 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001743 cmd->bind.pipeline.graphics->gs.rmap,
1744 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001745 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001746 cmd->bind.pipeline.graphics->fs.rmap,
1747 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001748
1749 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1750 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1751 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1752 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1753 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1754
1755 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1756 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001757 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1758 binding_tables[0]);
1759 gen7_3dstate_pointer(cmd,
1760 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1761 binding_tables[1]);
1762 gen7_3dstate_pointer(cmd,
1763 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1764 binding_tables[2]);
1765 gen7_3dstate_pointer(cmd,
1766 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1767 binding_tables[3]);
1768 gen7_3dstate_pointer(cmd,
1769 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1770 binding_tables[4]);
1771
1772 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001773 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1774 samplers[0]);
1775 gen7_3dstate_pointer(cmd,
1776 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1777 samplers[1]);
1778 gen7_3dstate_pointer(cmd,
1779 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1780 samplers[2]);
1781 gen7_3dstate_pointer(cmd,
1782 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1783 samplers[3]);
1784 gen7_3dstate_pointer(cmd,
1785 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1786 samplers[4]);
1787 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001788 assert(!binding_tables[1] && !binding_tables[2]);
1789 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1790 binding_tables[0], binding_tables[3], binding_tables[4]);
1791
Chia-I Wu625105f2014-10-13 15:35:29 +08001792 assert(!samplers[1] && !samplers[2]);
1793 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1794 samplers[0], samplers[3], samplers[4]);
1795 }
1796}
1797
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001798static void emit_rt(struct intel_cmd *cmd)
1799{
1800 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001801 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1802 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001803}
1804
1805static void emit_ds(struct intel_cmd *cmd)
1806{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001807 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001808
1809 if (!ds) {
1810 /* all zeros */
1811 static const struct intel_ds_view null_ds;
1812 ds = &null_ds;
1813 }
1814
1815 cmd_wa_gen6_pre_ds_flush(cmd);
1816 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1817 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1818 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1819
1820 if (cmd_gen(cmd) >= INTEL_GEN(7))
1821 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1822 else
1823 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1824}
1825
Chia-I Wua57761b2014-10-14 14:27:44 +08001826static uint32_t emit_shader(struct intel_cmd *cmd,
1827 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001828{
Chia-I Wua57761b2014-10-14 14:27:44 +08001829 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1830 uint32_t offset;
1831 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001832
Chia-I Wua57761b2014-10-14 14:27:44 +08001833 /* see if the shader is already in the cache */
1834 for (i = 0; i < cache->used; i++) {
1835 if (cache->entries[i].shader == (const void *) shader)
1836 return cache->entries[i].kernel_offset;
1837 }
1838
1839 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1840
1841 /* grow the cache if full */
1842 if (cache->used >= cache->count) {
1843 const XGL_UINT count = cache->count + 16;
1844 void *entries;
1845
1846 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1847 XGL_SYSTEM_ALLOC_INTERNAL);
1848 if (entries) {
1849 if (cache->entries) {
1850 memcpy(entries, cache->entries,
1851 sizeof(cache->entries[0]) * cache->used);
1852 icd_free(cache->entries);
1853 }
1854
1855 cache->entries = entries;
1856 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001857 }
1858 }
1859
Chia-I Wua57761b2014-10-14 14:27:44 +08001860 /* add the shader to the cache */
1861 if (cache->used < cache->count) {
1862 cache->entries[cache->used].shader = (const void *) shader;
1863 cache->entries[cache->used].kernel_offset = offset;
1864 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001865 }
1866
Chia-I Wua57761b2014-10-14 14:27:44 +08001867 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001868}
1869
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001870static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001871{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001872 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001873
Chia-I Wu8370b402014-08-29 12:28:37 +08001874 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1875 cmd_wa_gen6_pre_depth_stall_write(cmd);
1876 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1877 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1878 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1879 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001880
1881 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001882 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001883 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001884
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001885 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001886 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001887 }
1888 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001889 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001890 }
1891 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001892 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1893 }
1894 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1895 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1896 }
1897 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1898 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001899 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001900
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001901 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1902 gen7_3DSTATE_GS(cmd);
1903 } else {
1904 gen6_3DSTATE_GS(cmd);
1905 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001906
Chia-I Wu8370b402014-08-29 12:28:37 +08001907 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1908 cmd_wa_gen7_post_command_cs_stall(cmd);
1909 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1910 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001911}
1912
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001913static void emit_bounded_states(struct intel_cmd *cmd)
1914{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001915
1916 emit_graphics_pipeline(cmd);
1917
1918 emit_rt(cmd);
1919 emit_ds(cmd);
1920
1921 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1922 gen7_cc_states(cmd);
1923 gen7_viewport_states(cmd);
1924
1925 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1926 &cmd->bind.pipeline.graphics->vs);
1927 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1928 &cmd->bind.pipeline.graphics->fs);
1929
1930 gen6_3DSTATE_CLIP(cmd);
1931 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001932 gen7_3DSTATE_WM(cmd);
1933 gen7_3DSTATE_PS(cmd);
1934 } else {
1935 gen6_cc_states(cmd);
1936 gen6_viewport_states(cmd);
1937
1938 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1939 &cmd->bind.pipeline.graphics->vs);
1940 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1941 &cmd->bind.pipeline.graphics->fs);
1942
1943 gen6_3DSTATE_CLIP(cmd);
1944 gen6_3DSTATE_SF(cmd);
1945 gen6_3DSTATE_WM(cmd);
1946 }
1947
1948 emit_shader_resources(cmd);
1949
1950 cmd_wa_gen6_pre_depth_stall_write(cmd);
1951 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1952
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001953 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1954 gen6_3DSTATE_VS(cmd);
1955}
1956
Tony Barbourfa6cac72015-01-16 14:27:35 -07001957static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1958 const struct intel_cmd_meta *meta)
1959{
1960 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1961 const uint8_t cmd_len = 3;
1962 uint32_t dw[3];
1963 uint32_t cmd_depth_stencil;
1964 uint32_t cmd_depth_test;
1965
1966 CMD_ASSERT(cmd, 6, 7.5);
1967
1968 cmd_depth_stencil = 0;
1969 cmd_depth_test = 0;
1970 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
1971 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
1972 GEN6_COMPAREFUNCTION_ALWAYS << 27;
1973 }
1974 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
1975 cmd_depth_stencil = 1 << 31 |
1976 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
1977 (GEN6_STENCILOP_KEEP) << 25 |
1978 (GEN6_STENCILOP_KEEP) << 22 |
1979 (GEN6_STENCILOP_REPLACE) << 19 |
1980 1 << 15 |
1981 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
1982 (GEN6_STENCILOP_KEEP) << 9 |
1983 (GEN6_STENCILOP_KEEP) << 6 |
1984 (GEN6_STENCILOP_REPLACE) << 3;
1985 }
1986
1987 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
1988 dw[0] = cmd_depth_stencil | 1 << 18;
1989 dw[1] = (0xff) << 24 | (0xff) << 16;
1990 dw[2] = cmd_depth_test;
1991
1992 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1993 cmd_align, cmd_len, dw);
1994}
1995
Chia-I Wu6032b892014-10-17 14:47:18 +08001996static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
1997{
1998 const struct intel_cmd_meta *meta = cmd->bind.meta;
1999 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2000
2001 CMD_ASSERT(cmd, 6, 7.5);
2002
2003 blend_offset = 0;
2004 ds_offset = 0;
2005 cc_offset = 0;
2006 cc_vp_offset = 0;
2007
Chia-I Wu29e6f502014-11-24 14:27:29 +08002008 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002009 /* BLEND_STATE */
2010 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002011 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002012 dw[0] = 0;
2013 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2014 }
2015
Chia-I Wu29e6f502014-11-24 14:27:29 +08002016 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002017 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002018 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002019 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2020 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002021
Chia-I Wu29e6f502014-11-24 14:27:29 +08002022 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002023 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002024
Chia-I Wu29e6f502014-11-24 14:27:29 +08002025 /* COLOR_CALC_STATE */
2026 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002027 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002028
Chia-I Wu29e6f502014-11-24 14:27:29 +08002029 /* CC_VIEWPORT */
2030 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002031 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002032 dw[0] = u_fui(0.0f);
2033 dw[1] = u_fui(1.0f);
2034 } else {
2035 /* DEPTH_STENCIL_STATE */
2036 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002037 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002038 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2039 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2040 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002041 }
2042
2043 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2044 gen7_3dstate_pointer(cmd,
2045 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2046 blend_offset);
2047 gen7_3dstate_pointer(cmd,
2048 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2049 ds_offset);
2050 gen7_3dstate_pointer(cmd,
2051 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2052
2053 gen7_3dstate_pointer(cmd,
2054 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2055 cc_vp_offset);
2056 } else {
2057 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002058 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002059
2060 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2061 cmd_batch_pointer(cmd, 4, &dw);
2062 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2063 GEN6_PTR_VP_DW0_CC_CHANGED;
2064 dw[1] = 0;
2065 dw[2] = 0;
2066 dw[3] = cc_vp_offset;
2067 }
2068}
2069
2070static void gen6_meta_surface_states(struct intel_cmd *cmd)
2071{
2072 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002073 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002074 uint32_t offset;
2075
2076 CMD_ASSERT(cmd, 6, 7.5);
2077
Chia-I Wu29e6f502014-11-24 14:27:29 +08002078 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2079 return;
2080
Chia-I Wu005c47c2014-10-22 13:49:13 +08002081 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002082 if (meta->src.valid) {
2083 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002084 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002085 meta->src.surface_len, meta->src.surface);
2086
2087 cmd_reserve_reloc(cmd, 1);
2088 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2089 cmd_surface_reloc_writer(cmd, offset, 1,
2090 meta->src.reloc_target, meta->src.reloc_offset);
2091 } else {
2092 cmd_surface_reloc(cmd, offset, 1,
2093 (struct intel_bo *) meta->src.reloc_target,
2094 meta->src.reloc_offset, meta->src.reloc_flags);
2095 }
2096
Chia-I Wu005c47c2014-10-22 13:49:13 +08002097 binding_table[0] = offset;
2098 }
2099 if (meta->dst.valid) {
2100 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002101 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002102 meta->dst.surface_len, meta->dst.surface);
2103
2104 cmd_reserve_reloc(cmd, 1);
2105 cmd_surface_reloc(cmd, offset, 1,
2106 (struct intel_bo *) meta->dst.reloc_target,
2107 meta->dst.reloc_offset, meta->dst.reloc_flags);
2108
2109 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002110 }
2111
2112 /* BINDING_TABLE */
2113 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002114 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002115 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002116
2117 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002118 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2119 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2120 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2121 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002122 } else {
2123 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002124 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2125 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2126 else
2127 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002128 }
2129}
2130
2131static void gen6_meta_urb(struct intel_cmd *cmd)
2132{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002133 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002134 uint32_t *dw;
2135
2136 CMD_ASSERT(cmd, 6, 6);
2137
2138 /* 3DSTATE_URB */
2139 cmd_batch_pointer(cmd, 3, &dw);
2140 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002141 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002142 dw[2] = 0;
2143}
2144
2145static void gen7_meta_urb(struct intel_cmd *cmd)
2146{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002147 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002148 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002149 uint32_t *dw;
2150
2151 CMD_ASSERT(cmd, 7, 7.5);
2152
2153 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2154 cmd_batch_pointer(cmd, 10, &dw);
2155
2156 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002157 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002158 dw += 2;
2159
2160 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2161 dw[1] = 0;
2162 dw += 2;
2163
2164 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2165 dw[1] = 0;
2166 dw += 2;
2167
2168 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2169 dw[1] = 0;
2170 dw += 2;
2171
2172 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002173 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002174
2175 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2176
Chia-I Wu24aa1022014-11-25 11:53:19 +08002177 switch (cmd_gen(cmd)) {
2178 case INTEL_GEN(7.5):
2179 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2180 break;
2181 case INTEL_GEN(7):
2182 default:
2183 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2184 break;
2185 }
2186
Chia-I Wu6032b892014-10-17 14:47:18 +08002187 /* 3DSTATE_URB_x */
2188 cmd_batch_pointer(cmd, 8, &dw);
2189
2190 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2191 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002192 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002193 dw += 2;
2194
2195 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2196 dw[1] = 0;
2197 dw += 2;
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2200 dw[1] = 0;
2201 dw += 2;
2202
2203 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2204 dw[1] = 0;
2205 dw += 2;
2206}
2207
2208static void gen6_meta_vf(struct intel_cmd *cmd)
2209{
2210 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002211 uint32_t vb_start, vb_end, vb_stride;
2212 int ve_format, ve_z_source;
2213 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002214 XGL_UINT pos;
2215
2216 CMD_ASSERT(cmd, 6, 7.5);
2217
Chia-I Wu29e6f502014-11-24 14:27:29 +08002218 switch (meta->mode) {
2219 case INTEL_CMD_META_VS_POINTS:
2220 cmd_batch_pointer(cmd, 3, &dw);
2221 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2222 dw[1] = GEN6_VE_STATE_DW0_VALID;
2223 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2224 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2225 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2226 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2227 return;
2228 break;
2229 case INTEL_CMD_META_FS_RECT:
2230 {
2231 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002232
Chia-I Wu29e6f502014-11-24 14:27:29 +08002233 vertices[0][0] = meta->dst.x + meta->width;
2234 vertices[0][1] = meta->dst.y + meta->height;
2235 vertices[1][0] = meta->dst.x;
2236 vertices[1][1] = meta->dst.y + meta->height;
2237 vertices[2][0] = meta->dst.x;
2238 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002239
Chia-I Wu29e6f502014-11-24 14:27:29 +08002240 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2241 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002242
Chia-I Wu29e6f502014-11-24 14:27:29 +08002243 vb_end = vb_start + sizeof(vertices) - 1;
2244 vb_stride = sizeof(vertices[0]);
2245 ve_z_source = GEN6_VFCOMP_STORE_0;
2246 ve_format = GEN6_FORMAT_R32G32_USCALED;
2247 }
2248 break;
2249 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2250 {
2251 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002252
Chia-I Wu29e6f502014-11-24 14:27:29 +08002253 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2254 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2255 vertices[0][2] = u_uif(meta->clear_val[0]);
2256 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2257 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2258 vertices[1][2] = u_uif(meta->clear_val[0]);
2259 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2260 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2261 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002262
Chia-I Wu29e6f502014-11-24 14:27:29 +08002263 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2264 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002265
Chia-I Wu29e6f502014-11-24 14:27:29 +08002266 vb_end = vb_start + sizeof(vertices) - 1;
2267 vb_stride = sizeof(vertices[0]);
2268 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2269 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2270 }
2271 break;
2272 default:
2273 assert(!"unknown meta mode");
2274 return;
2275 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002276 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002277
2278 /* 3DSTATE_VERTEX_BUFFERS */
2279 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002280
Chia-I Wu6032b892014-10-17 14:47:18 +08002281 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002282 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002283 if (cmd_gen(cmd) >= INTEL_GEN(7))
2284 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2285
2286 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002287 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2288 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002289
2290 dw[4] = 0;
2291
2292 /* 3DSTATE_VERTEX_ELEMENTS */
2293 cmd_batch_pointer(cmd, 5, &dw);
2294 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002295 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002296 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2297 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2298 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2299 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2300 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002301 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002302 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2303 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002304 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002305 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2306}
2307
Chia-I Wu29e6f502014-11-24 14:27:29 +08002308static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002309{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002310 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002311 /* one GPR */
2312 XGL_UINT consts[8];
2313 XGL_UINT const_count;
2314
2315 CMD_ASSERT(cmd, 6, 7.5);
2316
2317 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002318 case INTEL_DEV_META_VS_FILL_MEM:
2319 consts[0] = meta->dst.x;
2320 consts[1] = meta->clear_val[0];
2321 const_count = 2;
2322 break;
2323 case INTEL_DEV_META_VS_COPY_MEM:
2324 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2325 consts[0] = meta->dst.x;
2326 consts[1] = meta->src.x;
2327 const_count = 2;
2328 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002329 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2330 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2331 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2332 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2333 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2334 consts[0] = meta->src.x;
2335 consts[1] = meta->src.y;
2336 consts[2] = meta->width;
2337 consts[3] = meta->dst.x;
2338 const_count = 4;
2339 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002340 default:
2341 assert(!"unknown meta shader id");
2342 const_count = 0;
2343 break;
2344 }
2345
2346 /* this can be skipped but it makes state dumping prettier */
2347 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2348
2349 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2350}
2351
2352static void gen6_meta_vs(struct intel_cmd *cmd)
2353{
2354 const struct intel_cmd_meta *meta = cmd->bind.meta;
2355 const struct intel_pipeline_shader *sh =
2356 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2357 uint32_t offset, *dw;
2358
2359 CMD_ASSERT(cmd, 6, 7.5);
2360
2361 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2362 XGL_UINT cmd_len;
2363
2364 /* 3DSTATE_CONSTANT_VS */
2365 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2366 cmd_batch_pointer(cmd, cmd_len, &dw);
2367 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2368 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2369
2370 /* 3DSTATE_VS */
2371 cmd_batch_pointer(cmd, 6, &dw);
2372 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2373 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2374
2375 return;
2376 }
2377
2378 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2379
2380 /* 3DSTATE_CONSTANT_VS */
2381 offset = gen6_meta_vs_constants(cmd);
2382 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2383 cmd_batch_pointer(cmd, 7, &dw);
2384 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2385 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2386 dw[2] = 0;
2387 dw[3] = offset;
2388 dw[4] = 0;
2389 dw[5] = 0;
2390 dw[6] = 0;
2391 } else {
2392 cmd_batch_pointer(cmd, 5, &dw);
2393 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2394 GEN6_PCB_ANY_DW0_PCB0_VALID;
2395 dw[1] = offset;
2396 dw[2] = 0;
2397 dw[3] = 0;
2398 dw[4] = 0;
2399 }
2400
2401 /* 3DSTATE_VS */
2402 offset = emit_shader(cmd, sh);
2403 cmd_batch_pointer(cmd, 6, &dw);
2404 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2405 dw[1] = offset;
2406 dw[2] = GEN6_THREADDISP_SPF |
2407 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2408 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002409 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002410 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2411 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2412
2413 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2414 GEN6_VS_DW5_VS_ENABLE;
2415 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002416 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002417 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002418 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002419
2420 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002421}
2422
2423static void gen6_meta_disabled(struct intel_cmd *cmd)
2424{
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 uint32_t *dw;
2426
2427 CMD_ASSERT(cmd, 6, 6);
2428
Chia-I Wu6032b892014-10-17 14:47:18 +08002429 /* 3DSTATE_CONSTANT_GS */
2430 cmd_batch_pointer(cmd, 5, &dw);
2431 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2432 dw[1] = 0;
2433 dw[2] = 0;
2434 dw[3] = 0;
2435 dw[4] = 0;
2436
2437 /* 3DSTATE_GS */
2438 cmd_batch_pointer(cmd, 7, &dw);
2439 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2440 dw[1] = 0;
2441 dw[2] = 0;
2442 dw[3] = 0;
2443 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2444 dw[5] = GEN6_GS_DW5_STATISTICS;
2445 dw[6] = 0;
2446
Chia-I Wu6032b892014-10-17 14:47:18 +08002447 /* 3DSTATE_SF */
2448 cmd_batch_pointer(cmd, 20, &dw);
2449 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2450 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2451 memset(&dw[2], 0, 18 * sizeof(*dw));
2452}
2453
2454static void gen7_meta_disabled(struct intel_cmd *cmd)
2455{
2456 uint32_t *dw;
2457
2458 CMD_ASSERT(cmd, 7, 7.5);
2459
Chia-I Wu6032b892014-10-17 14:47:18 +08002460 /* 3DSTATE_CONSTANT_HS */
2461 cmd_batch_pointer(cmd, 7, &dw);
2462 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2463 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2464
2465 /* 3DSTATE_HS */
2466 cmd_batch_pointer(cmd, 7, &dw);
2467 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2468 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2469
2470 /* 3DSTATE_TE */
2471 cmd_batch_pointer(cmd, 4, &dw);
2472 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2473 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2474
2475 /* 3DSTATE_CONSTANT_DS */
2476 cmd_batch_pointer(cmd, 7, &dw);
2477 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2478 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2479
2480 /* 3DSTATE_DS */
2481 cmd_batch_pointer(cmd, 6, &dw);
2482 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2483 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2484
2485 /* 3DSTATE_CONSTANT_GS */
2486 cmd_batch_pointer(cmd, 7, &dw);
2487 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2488 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2489
2490 /* 3DSTATE_GS */
2491 cmd_batch_pointer(cmd, 7, &dw);
2492 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2493 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2494
2495 /* 3DSTATE_STREAMOUT */
2496 cmd_batch_pointer(cmd, 3, &dw);
2497 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2498 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2499
Chia-I Wu6032b892014-10-17 14:47:18 +08002500 /* 3DSTATE_SF */
2501 cmd_batch_pointer(cmd, 7, &dw);
2502 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2503 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2504
2505 /* 3DSTATE_SBE */
2506 cmd_batch_pointer(cmd, 14, &dw);
2507 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2508 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2509 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002510}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002511
Chia-I Wu29e6f502014-11-24 14:27:29 +08002512static void gen6_meta_clip(struct intel_cmd *cmd)
2513{
2514 const struct intel_cmd_meta *meta = cmd->bind.meta;
2515 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002516
Chia-I Wu29e6f502014-11-24 14:27:29 +08002517 /* 3DSTATE_CLIP */
2518 cmd_batch_pointer(cmd, 4, &dw);
2519 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2520 dw[1] = 0;
2521 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2522 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2523 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2524 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002525 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002526 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002527 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002528}
2529
2530static void gen6_meta_wm(struct intel_cmd *cmd)
2531{
2532 const struct intel_cmd_meta *meta = cmd->bind.meta;
2533 uint32_t *dw;
2534
2535 CMD_ASSERT(cmd, 6, 7.5);
2536
2537 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2538
2539 /* 3DSTATE_MULTISAMPLE */
2540 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2541 cmd_batch_pointer(cmd, 4, &dw);
2542 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2543 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2544 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2545 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2546 dw[2] = 0;
2547 dw[3] = 0;
2548 } else {
2549 cmd_batch_pointer(cmd, 3, &dw);
2550 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2551 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2552 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2553 dw[2] = 0;
2554 }
2555
2556 /* 3DSTATE_SAMPLE_MASK */
2557 cmd_batch_pointer(cmd, 2, &dw);
2558 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2559 dw[1] = (1 << meta->samples) - 1;
2560
2561 /* 3DSTATE_DRAWING_RECTANGLE */
2562 cmd_batch_pointer(cmd, 4, &dw);
2563 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2564 dw[1] = meta->dst.y << 16 | meta->dst.x;
2565 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2566 (meta->dst.x + meta->width - 1);
2567 dw[3] = 0;
2568}
2569
2570static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2571{
2572 const struct intel_cmd_meta *meta = cmd->bind.meta;
2573 XGL_UINT offset_x, offset_y;
2574 /* one GPR */
2575 XGL_UINT consts[8];
2576 XGL_UINT const_count;
2577
2578 CMD_ASSERT(cmd, 6, 7.5);
2579
2580 /* underflow is fine here */
2581 offset_x = meta->src.x - meta->dst.x;
2582 offset_y = meta->src.y - meta->dst.y;
2583
2584 switch (meta->shader_id) {
2585 case INTEL_DEV_META_FS_COPY_MEM:
2586 case INTEL_DEV_META_FS_COPY_1D:
2587 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2588 case INTEL_DEV_META_FS_COPY_2D:
2589 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2590 case INTEL_DEV_META_FS_COPY_2D_MS:
2591 consts[0] = offset_x;
2592 consts[1] = offset_y;
2593 consts[2] = meta->src.layer;
2594 consts[3] = meta->src.lod;
2595 const_count = 4;
2596 break;
2597 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2598 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2599 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2600 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2601 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2602 consts[0] = offset_x;
2603 consts[1] = offset_y;
2604 consts[2] = meta->src.layer;
2605 consts[3] = meta->src.lod;
2606 consts[4] = meta->src.x;
2607 consts[5] = meta->width;
2608 const_count = 6;
2609 break;
2610 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2611 consts[0] = offset_x;
2612 consts[1] = offset_y;
2613 consts[2] = meta->width;
2614 const_count = 3;
2615 break;
2616 case INTEL_DEV_META_FS_CLEAR_COLOR:
2617 consts[0] = meta->clear_val[0];
2618 consts[1] = meta->clear_val[1];
2619 consts[2] = meta->clear_val[2];
2620 consts[3] = meta->clear_val[3];
2621 const_count = 4;
2622 break;
2623 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2624 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002625 consts[1] = meta->clear_val[1];
2626 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002627 break;
2628 case INTEL_DEV_META_FS_RESOLVE_2X:
2629 case INTEL_DEV_META_FS_RESOLVE_4X:
2630 case INTEL_DEV_META_FS_RESOLVE_8X:
2631 case INTEL_DEV_META_FS_RESOLVE_16X:
2632 consts[0] = offset_x;
2633 consts[1] = offset_y;
2634 const_count = 2;
2635 break;
2636 default:
2637 assert(!"unknown meta shader id");
2638 const_count = 0;
2639 break;
2640 }
2641
2642 /* this can be skipped but it makes state dumping prettier */
2643 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2644
2645 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2646}
2647
2648static void gen6_meta_ps(struct intel_cmd *cmd)
2649{
2650 const struct intel_cmd_meta *meta = cmd->bind.meta;
2651 const struct intel_pipeline_shader *sh =
2652 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2653 uint32_t offset, *dw;
2654
2655 CMD_ASSERT(cmd, 6, 6);
2656
Chia-I Wu29e6f502014-11-24 14:27:29 +08002657 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2658 /* 3DSTATE_CONSTANT_PS */
2659 cmd_batch_pointer(cmd, 5, &dw);
2660 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2661 dw[1] = 0;
2662 dw[2] = 0;
2663 dw[3] = 0;
2664 dw[4] = 0;
2665
2666 /* 3DSTATE_WM */
2667 cmd_batch_pointer(cmd, 9, &dw);
2668 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2669 dw[1] = 0;
2670 dw[2] = 0;
2671 dw[3] = 0;
2672 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002673 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002674 dw[6] = 0;
2675 dw[7] = 0;
2676 dw[8] = 0;
2677
Chia-I Wu3adf7212014-10-24 15:34:07 +08002678 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002679 }
2680
Chia-I Wu3adf7212014-10-24 15:34:07 +08002681 /* a normal color write */
2682 assert(meta->dst.valid && !sh->uses);
2683
Chia-I Wu6032b892014-10-17 14:47:18 +08002684 /* 3DSTATE_CONSTANT_PS */
2685 offset = gen6_meta_ps_constants(cmd);
2686 cmd_batch_pointer(cmd, 5, &dw);
2687 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2688 GEN6_PCB_ANY_DW0_PCB0_VALID;
2689 dw[1] = offset;
2690 dw[2] = 0;
2691 dw[3] = 0;
2692 dw[4] = 0;
2693
2694 /* 3DSTATE_WM */
2695 offset = emit_shader(cmd, sh);
2696 cmd_batch_pointer(cmd, 9, &dw);
2697 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2698 dw[1] = offset;
2699 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2700 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002701 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002702 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002703 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002704 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002705 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2706
Chia-I Wu6032b892014-10-17 14:47:18 +08002707 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2708 GEN6_WM_DW6_POSOFFSET_NONE |
2709 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2710 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2711 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2712 if (meta->samples > 1) {
2713 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2714 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2715 } else {
2716 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2717 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2718 }
2719 dw[7] = 0;
2720 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002721
2722 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002723}
2724
2725static void gen7_meta_ps(struct intel_cmd *cmd)
2726{
2727 const struct intel_cmd_meta *meta = cmd->bind.meta;
2728 const struct intel_pipeline_shader *sh =
2729 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2730 uint32_t offset, *dw;
2731
2732 CMD_ASSERT(cmd, 7, 7.5);
2733
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2735 /* 3DSTATE_WM */
2736 cmd_batch_pointer(cmd, 3, &dw);
2737 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2738 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2739
2740 /* 3DSTATE_CONSTANT_GS */
2741 cmd_batch_pointer(cmd, 7, &dw);
2742 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2743 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2744
2745 /* 3DSTATE_PS */
2746 cmd_batch_pointer(cmd, 8, &dw);
2747 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2748 dw[1] = 0;
2749 dw[2] = 0;
2750 dw[3] = 0;
2751 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002752 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002753 dw[5] = 0;
2754 dw[6] = 0;
2755 dw[7] = 0;
2756
Chia-I Wu3adf7212014-10-24 15:34:07 +08002757 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002758 }
2759
Chia-I Wu3adf7212014-10-24 15:34:07 +08002760 /* a normal color write */
2761 assert(meta->dst.valid && !sh->uses);
2762
Chia-I Wu6032b892014-10-17 14:47:18 +08002763 /* 3DSTATE_WM */
2764 cmd_batch_pointer(cmd, 3, &dw);
2765 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2766 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2767 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2768 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2769 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2770 dw[2] = 0;
2771
2772 /* 3DSTATE_CONSTANT_PS */
2773 offset = gen6_meta_ps_constants(cmd);
2774 cmd_batch_pointer(cmd, 7, &dw);
2775 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2776 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2777 dw[2] = 0;
2778 dw[3] = offset;
2779 dw[4] = 0;
2780 dw[5] = 0;
2781 dw[6] = 0;
2782
2783 /* 3DSTATE_PS */
2784 offset = emit_shader(cmd, sh);
2785 cmd_batch_pointer(cmd, 8, &dw);
2786 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2787 dw[1] = offset;
2788 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2789 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002790 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002791
2792 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2793 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002794 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2795
2796 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002797 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002798 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002799 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002800 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002801 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002802
2803 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2804 dw[6] = 0;
2805 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002806
2807 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002808}
2809
2810static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2811{
2812 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002813 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002814
2815 CMD_ASSERT(cmd, 6, 7.5);
2816
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002817 if (!ds) {
2818 /* all zeros */
2819 static const struct intel_ds_view null_ds;
2820 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002821 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002822
2823 cmd_wa_gen6_pre_ds_flush(cmd);
2824 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2825 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2826 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2827
2828 if (cmd_gen(cmd) >= INTEL_GEN(7))
2829 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2830 else
2831 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002832}
2833
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002834static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2835 const struct intel_pipeline *pipeline)
2836{
2837 cmd->bind.pipeline.graphics = pipeline;
2838}
2839
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002840static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2841 const struct intel_pipeline *pipeline)
2842{
2843 cmd->bind.pipeline.compute = pipeline;
2844}
2845
2846static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2847 const struct intel_pipeline_delta *delta)
2848{
2849 cmd->bind.pipeline.graphics_delta = delta;
2850}
2851
2852static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2853 const struct intel_pipeline_delta *delta)
2854{
2855 cmd->bind.pipeline.compute_delta = delta;
2856}
2857
2858static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002859 const struct intel_desc_set *dset,
2860 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002861{
Chia-I Wuf8385062015-01-04 16:27:24 +08002862 const uint32_t size = sizeof(*dynamic_offsets) *
2863 dset->layout->dynamic_desc_count;
2864
2865 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2866 if (cmd->bind.dset.graphics_dynamic_offsets)
2867 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2868
2869 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2870 4, XGL_SYSTEM_ALLOC_INTERNAL);
2871 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2872 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2873 return;
2874 }
2875
2876 cmd->bind.dset.graphics_dynamic_offset_size = size;
2877 }
2878
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002879 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002880 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002881}
2882
2883static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002884 const struct intel_desc_set *dset,
2885 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002886{
Chia-I Wuf8385062015-01-04 16:27:24 +08002887 const uint32_t size = sizeof(*dynamic_offsets) *
2888 dset->layout->dynamic_desc_count;
2889
2890 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2891 if (cmd->bind.dset.compute_dynamic_offsets)
2892 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2893
2894 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2895 4, XGL_SYSTEM_ALLOC_INTERNAL);
2896 if (!cmd->bind.dset.compute_dynamic_offsets) {
2897 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2898 return;
2899 }
2900
2901 cmd->bind.dset.compute_dynamic_offset_size = size;
2902 }
2903
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002904 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002905 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002906}
2907
Chia-I Wu3b04af52014-11-08 10:48:20 +08002908static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002909 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002910 XGL_GPU_SIZE offset, XGL_UINT binding)
2911{
Chia-I Wu714df452015-01-01 07:55:04 +08002912 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002913 cmd->result = XGL_ERROR_UNKNOWN;
2914 return;
2915 }
2916
Chia-I Wu714df452015-01-01 07:55:04 +08002917 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002918 cmd->bind.vertex.offset[binding] = offset;
2919}
2920
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002921static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002922 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002923 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2924{
Chia-I Wu714df452015-01-01 07:55:04 +08002925 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002926 cmd->bind.index.offset = offset;
2927 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002928}
2929
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002930static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002931 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002932{
2933 cmd->bind.state.viewport = state;
2934}
2935
2936static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002937 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002938{
2939 cmd->bind.state.raster = state;
2940}
2941
2942static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002943 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944{
2945 cmd->bind.state.ds = state;
2946}
2947
2948static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002949 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950{
2951 cmd->bind.state.blend = state;
2952}
2953
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002954static void cmd_draw(struct intel_cmd *cmd,
2955 XGL_UINT vertex_start,
2956 XGL_UINT vertex_count,
2957 XGL_UINT instance_start,
2958 XGL_UINT instance_count,
2959 bool indexed,
2960 XGL_UINT vertex_base)
2961{
2962 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2963
2964 emit_bounded_states(cmd);
2965
2966 if (indexed) {
2967 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2968 cmd->result = XGL_ERROR_UNKNOWN;
2969
2970 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2971 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2972 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08002973 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002974 cmd->bind.index.offset, cmd->bind.index.type,
2975 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002976 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08002977 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002978 cmd->bind.index.offset, cmd->bind.index.type,
2979 p->primitive_restart);
2980 }
2981 } else {
2982 assert(!vertex_base);
2983 }
2984
2985 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2986 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2987 vertex_start, instance_count, instance_start, vertex_base);
2988 } else {
2989 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2990 vertex_start, instance_count, instance_start, vertex_base);
2991 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002992
Chia-I Wu707a29e2014-08-27 12:51:47 +08002993 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002994 /* need to re-emit all workarounds */
2995 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08002996
2997 if (intel_debug & INTEL_DEBUG_NOCACHE)
2998 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002999}
3000
Chia-I Wuc14d1562014-10-17 09:49:22 +08003001void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3002{
Chia-I Wu6032b892014-10-17 14:47:18 +08003003 cmd->bind.meta = meta;
3004
3005 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003006 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003007
3008 gen6_meta_dynamic_states(cmd);
3009 gen6_meta_surface_states(cmd);
3010
3011 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3012 gen7_meta_urb(cmd);
3013 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003014 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003015 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003016 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003017 gen6_meta_wm(cmd);
3018 gen7_meta_ps(cmd);
3019 gen6_meta_depth_buffer(cmd);
3020
3021 cmd_wa_gen7_post_command_cs_stall(cmd);
3022 cmd_wa_gen7_post_command_depth_stall(cmd);
3023
Chia-I Wu29e6f502014-11-24 14:27:29 +08003024 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3025 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003026 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003027 } else {
3028 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3029 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003030 } else {
3031 gen6_meta_urb(cmd);
3032 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003033 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003034 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003035 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003036 gen6_meta_wm(cmd);
3037 gen6_meta_ps(cmd);
3038 gen6_meta_depth_buffer(cmd);
3039
Chia-I Wu29e6f502014-11-24 14:27:29 +08003040 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3041 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003042 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003043 } else {
3044 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3045 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003046 }
3047
3048 cmd->bind.draw_count++;
3049 /* need to re-emit all workarounds */
3050 cmd->bind.wa_flags = 0;
3051
3052 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003053
3054 if (intel_debug & INTEL_DEBUG_NOCACHE)
3055 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003056}
3057
Chia-I Wu96177272015-01-03 15:27:41 +08003058ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003059 XGL_CMD_BUFFER cmdBuffer,
3060 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3061 XGL_PIPELINE pipeline)
3062{
3063 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3064
3065 switch (pipelineBindPoint) {
3066 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003067 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003068 break;
3069 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003070 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003071 break;
3072 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003073 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003074 break;
3075 }
3076}
3077
Chia-I Wu96177272015-01-03 15:27:41 +08003078ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003079 XGL_CMD_BUFFER cmdBuffer,
3080 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3081 XGL_PIPELINE_DELTA delta)
3082{
3083 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3084
3085 switch (pipelineBindPoint) {
3086 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003087 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003088 break;
3089 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003090 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003091 break;
3092 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003093 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003094 break;
3095 }
3096}
3097
Tony Barbourfa6cac72015-01-16 14:27:35 -07003098ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003099 XGL_CMD_BUFFER cmdBuffer,
3100 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003101 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003102{
3103 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3104
3105 switch (stateBindPoint) {
3106 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003108 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003109 break;
3110 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003111 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003112 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003113 break;
3114 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003116 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003117 break;
3118 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003119 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003120 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003121 break;
3122 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003123 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003124 break;
3125 }
3126}
3127
Chia-I Wu96177272015-01-03 15:27:41 +08003128ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003129 XGL_CMD_BUFFER cmdBuffer,
3130 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003131 XGL_DESCRIPTOR_SET descriptorSet,
Chia-I Wuf8385062015-01-04 16:27:24 +08003132 const XGL_UINT* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003133{
3134 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003135 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003136
3137 switch (pipelineBindPoint) {
3138 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003139 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003140 break;
3141 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003142 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003143 break;
3144 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003145 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003146 break;
3147 }
3148}
3149
Chia-I Wu714df452015-01-01 07:55:04 +08003150ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003151 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003152 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003153 XGL_GPU_SIZE offset,
3154 XGL_UINT binding)
3155{
3156 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003157 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003158
Chia-I Wu714df452015-01-01 07:55:04 +08003159 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003160}
3161
Chia-I Wu714df452015-01-01 07:55:04 +08003162ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003163 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003164 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003165 XGL_GPU_SIZE offset,
3166 XGL_INDEX_TYPE indexType)
3167{
3168 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003169 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003170
Chia-I Wu714df452015-01-01 07:55:04 +08003171 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003172}
3173
Chia-I Wu96177272015-01-03 15:27:41 +08003174ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003175 XGL_CMD_BUFFER cmdBuffer,
3176 XGL_UINT firstVertex,
3177 XGL_UINT vertexCount,
3178 XGL_UINT firstInstance,
3179 XGL_UINT instanceCount)
3180{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003181 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003182
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003183 cmd_draw(cmd, firstVertex, vertexCount,
3184 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003185}
3186
Chia-I Wu96177272015-01-03 15:27:41 +08003187ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003188 XGL_CMD_BUFFER cmdBuffer,
3189 XGL_UINT firstIndex,
3190 XGL_UINT indexCount,
3191 XGL_INT vertexOffset,
3192 XGL_UINT firstInstance,
3193 XGL_UINT instanceCount)
3194{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003195 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003196
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003197 cmd_draw(cmd, firstIndex, indexCount,
3198 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003199}
3200
Chia-I Wu96177272015-01-03 15:27:41 +08003201ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003202 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003203 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003204 XGL_GPU_SIZE offset,
3205 XGL_UINT32 count,
3206 XGL_UINT32 stride)
3207{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003208 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3209
3210 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003211}
3212
Chia-I Wu96177272015-01-03 15:27:41 +08003213ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003214 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003215 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003216 XGL_GPU_SIZE offset,
3217 XGL_UINT32 count,
3218 XGL_UINT32 stride)
3219{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003220 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3221
3222 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003223}
3224
Chia-I Wu96177272015-01-03 15:27:41 +08003225ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003226 XGL_CMD_BUFFER cmdBuffer,
3227 XGL_UINT x,
3228 XGL_UINT y,
3229 XGL_UINT z)
3230{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003231 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3232
3233 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003234}
3235
Chia-I Wu96177272015-01-03 15:27:41 +08003236ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003237 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003238 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003239 XGL_GPU_SIZE offset)
3240{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003241 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3242
3243 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003244}