blob: 0762f2fe90b7a629662a3e8f3b97fa9a32654d79 [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 Wub2755562014-08-20 13:38:52 +080030#include "dset.h"
Chia-I Wu714df452015-01-01 07:55:04 +080031#include "buf.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;
378 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
379 const struct intel_raster_state *raster = cmd->bind.state.raster;
380 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
381 uint32_t dw1, dw2, dw3;
382 int point_width;
383
384 CMD_ASSERT(cmd, 6, 7.5);
385
386 dw1 = GEN7_SF_DW1_STATISTICS |
387 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
388 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
389 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
390 GEN7_SF_DW1_VIEWPORT_ENABLE |
391 raster->cmd_sf_fill;
392
393 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
394 int format;
395
396 switch (pipeline->db_format.channelFormat) {
397 case XGL_CH_FMT_R16:
398 format = GEN6_ZFORMAT_D16_UNORM;
399 break;
400 case XGL_CH_FMT_R32:
401 case XGL_CH_FMT_R32G8:
402 format = GEN6_ZFORMAT_D32_FLOAT;
403 break;
404 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700405 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800406 format = 0;
407 break;
408 }
409
410 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
411 }
412
413 dw2 = raster->cmd_sf_cull;
414
415 if (msaa->sample_count > 1) {
416 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
417 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
418 } else {
419 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
420 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
421 }
422
423 if (viewport->scissor_enable)
424 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
425
426 /* in U8.3 */
427 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
428 point_width = U_CLAMP(point_width, 1, 2047);
429
430 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
431 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
432 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
433 GEN7_SF_DW3_SUBPIXEL_8BITS |
434 GEN7_SF_DW3_USE_POINT_WIDTH |
435 point_width;
436
437 body[0] = dw1;
438 body[1] = dw2;
439 body[2] = dw3;
440 body[3] = raster->cmd_depth_offset_const;
441 body[4] = raster->cmd_depth_offset_scale;
442 body[5] = raster->cmd_depth_offset_clamp;
443}
444
445static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
446 uint32_t body[13])
447{
GregF8cd81832014-11-18 18:01:01 -0700448 XGL_UINT sbe_offset;
449 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800450
451 CMD_ASSERT(cmd, 6, 7.5);
452
GregF8cd81832014-11-18 18:01:01 -0700453 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800454
GregF8cd81832014-11-18 18:01:01 -0700455 for (i = 0; i < 13; i++) {
456 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
457 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800458 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800459}
460
461static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
462{
463 const uint8_t cmd_len = 20;
464 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
465 (cmd_len - 2);
466 uint32_t sf[6];
467 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800469
470 CMD_ASSERT(cmd, 6, 6);
471
472 gen7_fill_3DSTATE_SF_body(cmd, sf);
473 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
474
Chia-I Wu72292b72014-09-09 10:48:33 +0800475 cmd_batch_pointer(cmd, cmd_len, &dw);
476 dw[0] = dw0;
477 dw[1] = sbe[0];
478 memcpy(&dw[2], sf, sizeof(sf));
479 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800480}
481
482static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
483{
484 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800485 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800486
487 CMD_ASSERT(cmd, 7, 7.5);
488
Chia-I Wu72292b72014-09-09 10:48:33 +0800489 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800490 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
491 (cmd_len - 2);
492 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800493}
494
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800495static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
496{
497 const uint8_t cmd_len = 4;
498 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
499 (cmd_len - 2);
500 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700501 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800502 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
504 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800505 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800506
507 CMD_ASSERT(cmd, 6, 7.5);
508
509 dw1 = GEN6_CLIP_DW1_STATISTICS;
510 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
511 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
512 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
513 raster->cmd_clip_cull;
514 }
515
516 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
517 GEN6_CLIP_DW2_XY_TEST_ENABLE |
518 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700519 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800520 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
521 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
522 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
523
524 if (pipeline->rasterizerDiscardEnable)
525 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
526 else
527 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
528
529 if (pipeline->depthClipEnable)
530 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
531
532 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
533 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
534 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
535 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
536
537 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
538 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
539 (viewport->viewport_count - 1);
540
Chia-I Wu72292b72014-09-09 10:48:33 +0800541 cmd_batch_pointer(cmd, cmd_len, &dw);
542 dw[0] = dw0;
543 dw[1] = dw1;
544 dw[2] = dw2;
545 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800546}
547
Chia-I Wu784d3042014-12-19 14:30:04 +0800548static void gen6_add_scratch_space(struct intel_cmd *cmd,
549 XGL_UINT batch_pos,
550 const struct intel_pipeline *pipeline,
551 const struct intel_pipeline_shader *sh)
552{
553 int scratch_space;
554
555 CMD_ASSERT(cmd, 6, 7.5);
556
557 assert(sh->per_thread_scratch_size &&
558 sh->per_thread_scratch_size % 1024 == 0 &&
559 u_is_pow2(sh->per_thread_scratch_size) &&
560 sh->scratch_offset % 1024 == 0);
561 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
562
563 cmd_reserve_reloc(cmd, 1);
564 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
565 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
566}
567
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800568static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
569{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800570 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800571 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
573 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800574 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800575 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800576
577 CMD_ASSERT(cmd, 6, 6);
578
579 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
580
581 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
582 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
583
584 dw4 = GEN6_WM_DW4_STATISTICS |
585 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
586 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
587 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
588
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800589 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800590 GEN6_WM_DW5_PS_ENABLE |
591 GEN6_WM_DW5_8_PIXEL_DISPATCH;
592
593 if (fs->uses & INTEL_SHADER_USE_KILL ||
594 pipeline->cb_state.alphaToCoverageEnable)
595 dw5 |= GEN6_WM_DW5_PS_KILL;
596
Cody Northrope238deb2015-01-26 14:41:36 -0700597 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800598 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
599 if (fs->uses & INTEL_SHADER_USE_DEPTH)
600 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
601 if (fs->uses & INTEL_SHADER_USE_W)
602 dw5 |= GEN6_WM_DW5_PS_USE_W;
603
604 if (pipeline->cb_state.dualSourceBlendEnable)
605 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
606
607 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
608 GEN6_WM_DW6_POSOFFSET_NONE |
609 GEN6_WM_DW6_ZW_INTERP_PIXEL |
610 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
611 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
612
613 if (msaa->sample_count > 1) {
614 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
615 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
616 } else {
617 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
618 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
619 }
620
Chia-I Wu784d3042014-12-19 14:30:04 +0800621 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800622 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800623 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800624 dw[2] = dw2;
625 dw[3] = 0; /* scratch */
626 dw[4] = dw4;
627 dw[5] = dw5;
628 dw[6] = dw6;
629 dw[7] = 0; /* kernel 1 */
630 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800631
632 if (fs->per_thread_scratch_size)
633 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800634}
635
636static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
637{
638 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800639 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800640 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
641 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
667 if (msaa->sample_count > 1) {
668 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 struct intel_msaa_state *msaa = cmd->bind.state.msaa;
686 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800687 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800688 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800689
690 CMD_ASSERT(cmd, 7, 7.5);
691
692 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
693
694 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
695 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
696
697 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
698 GEN7_PS_DW4_8_PIXEL_DISPATCH;
699
700 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800701 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800702 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
703 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800704 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800705 }
706
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800707 if (fs->in_count)
708 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
709
710 if (pipeline->cb_state.dualSourceBlendEnable)
711 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
712
713 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
714 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
715 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
716
Chia-I Wu784d3042014-12-19 14:30:04 +0800717 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800718 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800719 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800720 dw[2] = dw2;
721 dw[3] = 0; /* scratch */
722 dw[4] = dw4;
723 dw[5] = dw5;
724 dw[6] = 0; /* kernel 1 */
725 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800726
727 if (fs->per_thread_scratch_size)
728 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800729}
730
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800731static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
732 const struct intel_ds_view *view)
733{
734 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800735 uint32_t dw0, *dw;
736 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800737
738 CMD_ASSERT(cmd, 6, 7.5);
739
740 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800741 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
742 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800743 dw0 |= (cmd_len - 2);
744
Chia-I Wu72292b72014-09-09 10:48:33 +0800745 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
746 dw[0] = dw0;
747 dw[1] = view->cmd[0];
748 dw[2] = 0;
749 dw[3] = view->cmd[2];
750 dw[4] = view->cmd[3];
751 dw[5] = view->cmd[4];
752 dw[6] = view->cmd[5];
753
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600754 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800755 cmd_reserve_reloc(cmd, 1);
756 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
757 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600758 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800759}
760
761static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
762 const struct intel_ds_view *view)
763{
764 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800765 uint32_t dw0, *dw;
766 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767
768 CMD_ASSERT(cmd, 6, 7.5);
769
770 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800771 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
772 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800773 dw0 |= (cmd_len - 2);
774
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
776 dw[0] = dw0;
777 dw[1] = view->cmd[6];
778 dw[2] = 0;
779
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600780 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800781 cmd_reserve_reloc(cmd, 1);
782 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
783 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600784 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800785}
786
787static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
788 const struct intel_ds_view *view)
789{
790 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800791 uint32_t dw0, *dw;
792 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793
794 CMD_ASSERT(cmd, 6, 7.5);
795
796 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800797 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
798 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799 dw0 |= (cmd_len - 2);
800
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
802 dw[0] = dw0;
803 dw[1] = view->cmd[8];
804 dw[2] = 0;
805
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600806 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800807 cmd_reserve_reloc(cmd, 1);
808 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
809 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600810 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800811}
812
Chia-I Wuf8231032014-08-25 10:44:45 +0800813static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
814 uint32_t clear_val)
815{
816 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800817 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800818 GEN6_CLEAR_PARAMS_DW0_VALID |
819 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800820 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800821
822 CMD_ASSERT(cmd, 6, 6);
823
Chia-I Wu72292b72014-09-09 10:48:33 +0800824 cmd_batch_pointer(cmd, cmd_len, &dw);
825 dw[0] = dw0;
826 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800827}
828
829static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
830 uint32_t clear_val)
831{
832 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800833 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800834 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800835 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800836
837 CMD_ASSERT(cmd, 7, 7.5);
838
Chia-I Wu72292b72014-09-09 10:48:33 +0800839 cmd_batch_pointer(cmd, cmd_len, &dw);
840 dw[0] = dw0;
841 dw[1] = clear_val;
842 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800843}
844
Chia-I Wu302742d2014-08-22 10:28:29 +0800845static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 uint32_t blend_offset,
847 uint32_t ds_offset,
848 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800849{
850 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800851 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800852
853 CMD_ASSERT(cmd, 6, 6);
854
Chia-I Wu426072d2014-08-26 14:31:55 +0800855 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800856 (cmd_len - 2);
857
Chia-I Wu72292b72014-09-09 10:48:33 +0800858 cmd_batch_pointer(cmd, cmd_len, &dw);
859 dw[0] = dw0;
860 dw[1] = blend_offset | 1;
861 dw[2] = ds_offset | 1;
862 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800863}
864
Chia-I Wu1744cca2014-08-22 11:10:17 +0800865static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800866 uint32_t clip_offset,
867 uint32_t sf_offset,
868 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800869{
870 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800872
873 CMD_ASSERT(cmd, 6, 6);
874
Chia-I Wu426072d2014-08-26 14:31:55 +0800875 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800876 GEN6_PTR_VP_DW0_CLIP_CHANGED |
877 GEN6_PTR_VP_DW0_SF_CHANGED |
878 GEN6_PTR_VP_DW0_CC_CHANGED |
879 (cmd_len - 2);
880
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 cmd_batch_pointer(cmd, cmd_len, &dw);
882 dw[0] = dw0;
883 dw[1] = clip_offset;
884 dw[2] = sf_offset;
885 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800886}
887
888static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800890{
891 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893
894 CMD_ASSERT(cmd, 6, 6);
895
Chia-I Wu426072d2014-08-26 14:31:55 +0800896 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800897 (cmd_len - 2);
898
Chia-I Wu72292b72014-09-09 10:48:33 +0800899 cmd_batch_pointer(cmd, cmd_len, &dw);
900 dw[0] = dw0;
901 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800902}
903
Chia-I Wu42a56202014-08-23 16:47:48 +0800904static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 uint32_t vs_offset,
906 uint32_t gs_offset,
907 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800908{
909 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800910 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800911
912 CMD_ASSERT(cmd, 6, 6);
913
Chia-I Wu426072d2014-08-26 14:31:55 +0800914 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800915 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
916 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
917 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
918 (cmd_len - 2);
919
Chia-I Wu72292b72014-09-09 10:48:33 +0800920 cmd_batch_pointer(cmd, cmd_len, &dw);
921 dw[0] = dw0;
922 dw[1] = vs_offset;
923 dw[2] = gs_offset;
924 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800925}
926
Chia-I Wu257e75e2014-08-29 14:06:35 +0800927static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800928 uint32_t vs_offset,
929 uint32_t gs_offset,
930 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800931{
932 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800934
935 CMD_ASSERT(cmd, 6, 6);
936
937 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
938 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
939 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
940 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
941 (cmd_len - 2);
942
Chia-I Wu72292b72014-09-09 10:48:33 +0800943 cmd_batch_pointer(cmd, cmd_len, &dw);
944 dw[0] = dw0;
945 dw[1] = vs_offset;
946 dw[2] = gs_offset;
947 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800948}
949
Chia-I Wu302742d2014-08-22 10:28:29 +0800950static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800952{
953 const uint8_t cmd_len = 2;
954 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
955 GEN6_RENDER_SUBTYPE_3D |
956 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800958
Chia-I Wu72292b72014-09-09 10:48:33 +0800959 cmd_batch_pointer(cmd, cmd_len, &dw);
960 dw[0] = dw0;
961 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800962}
963
Chia-I Wua6c4f152014-12-02 04:19:58 +0800964static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800965{
Chia-I Wue6073342014-11-30 09:43:42 +0800966 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800967 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
Chia-I Wua6c4f152014-12-02 04:19:58 +0800968 const XGL_PIPELINE_CB_STATE *cb = &cmd->bind.pipeline.graphics->cb_state;
969 const struct intel_blend_state *blend = cmd->bind.state.blend;
970 uint32_t dw[XGL_MAX_COLOR_ATTACHMENTS * 2];
971 int i;
Chia-I Wu302742d2014-08-22 10:28:29 +0800972
973 CMD_ASSERT(cmd, 6, 7.5);
Chia-I Wua6c4f152014-12-02 04:19:58 +0800974 STATIC_ASSERT(ARRAY_SIZE(blend->cmd_blend) >= XGL_MAX_COLOR_ATTACHMENTS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800975
Chia-I Wua6c4f152014-12-02 04:19:58 +0800976 for (i = 0; i < XGL_MAX_COLOR_ATTACHMENTS; i++) {
977 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &cb->attachment[i];
978 uint32_t dw0, dw1;
979
980 dw0 = 0;
981 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
982 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
983 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
984
985 if (cb->logicOp != XGL_LOGIC_OP_COPY) {
986 int logicop;
987
988 switch (cb->logicOp) {
989 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
990 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
991 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
992 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
993 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
994 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
995 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
996 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
997 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
998 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
999 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1000 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1001 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1002 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1003 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1004 default:
1005 assert(!"unknown logic op");
1006 logicop = GEN6_LOGICOP_CLEAR;
1007 break;
1008 }
1009
1010 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1011 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1012 } else if (att->blendEnable && blend) {
1013 dw0 |= blend->cmd_blend[i];
1014 }
1015
1016 if (!(att->channelWriteMask & 0x1))
1017 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1018 if (!(att->channelWriteMask & 0x2))
1019 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1020 if (!(att->channelWriteMask & 0x4))
1021 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1022 if (!(att->channelWriteMask & 0x8))
1023 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1024
1025 dw[2 * i] = dw0;
1026 dw[2 * i + 1] = dw1;
1027 }
1028
1029 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001030}
1031
Chia-I Wu72292b72014-09-09 10:48:33 +08001032static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001033 const struct intel_ds_state *state)
1034{
Chia-I Wue6073342014-11-30 09:43:42 +08001035 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001036 const uint8_t cmd_len = 3;
1037
1038 CMD_ASSERT(cmd, 6, 7.5);
1039 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1040
Chia-I Wu00b51a82014-09-09 12:07:37 +08001041 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1042 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001043}
1044
Chia-I Wu72292b72014-09-09 10:48:33 +08001045static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001046 uint32_t stencil_ref,
1047 const uint32_t blend_color[4])
1048{
Chia-I Wue6073342014-11-30 09:43:42 +08001049 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001050 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001051 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001052
1053 CMD_ASSERT(cmd, 6, 7.5);
1054
Chia-I Wu00b51a82014-09-09 12:07:37 +08001055 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1056 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001057 dw[0] = stencil_ref;
1058 dw[1] = 0;
1059 dw[2] = blend_color[0];
1060 dw[3] = blend_color[1];
1061 dw[4] = blend_color[2];
1062 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001063
Chia-I Wu72292b72014-09-09 10:48:33 +08001064 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001065}
1066
Chia-I Wu8370b402014-08-29 12:28:37 +08001067static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001068{
Chia-I Wu8370b402014-08-29 12:28:37 +08001069 CMD_ASSERT(cmd, 6, 7.5);
1070
Chia-I Wu707a29e2014-08-27 12:51:47 +08001071 if (!cmd->bind.draw_count)
1072 return;
1073
Chia-I Wu8370b402014-08-29 12:28:37 +08001074 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001075 return;
1076
Chia-I Wu8370b402014-08-29 12:28:37 +08001077 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001078
1079 /*
1080 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1081 *
1082 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1083 * pipe-control with a post-sync op and no write-cache flushes."
1084 *
1085 * The workaround below necessitates this workaround.
1086 */
1087 gen6_PIPE_CONTROL(cmd,
1088 GEN6_PIPE_CONTROL_CS_STALL |
1089 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001090 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001091
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1093 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001094}
1095
Chia-I Wu8370b402014-08-29 12:28:37 +08001096static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001097{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001098 CMD_ASSERT(cmd, 6, 7.5);
1099
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001100 if (!cmd->bind.draw_count)
1101 return;
1102
Chia-I Wud6d079d2014-08-31 13:14:21 +08001103 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1104 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001105}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001106
Chia-I Wu8370b402014-08-29 12:28:37 +08001107static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1108{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001109 CMD_ASSERT(cmd, 7, 7.5);
1110
Chia-I Wu8370b402014-08-29 12:28:37 +08001111 if (!cmd->bind.draw_count)
1112 return;
1113
1114 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001115
1116 gen6_PIPE_CONTROL(cmd,
1117 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001118 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001119}
1120
Chia-I Wu8370b402014-08-29 12:28:37 +08001121static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1122{
1123 CMD_ASSERT(cmd, 7, 7.5);
1124
1125 if (!cmd->bind.draw_count)
1126 return;
1127
1128 /*
1129 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1130 *
1131 * "One of the following must also be set (when CS stall is set):
1132 *
1133 * * Render Target Cache Flush Enable ([12] of DW1)
1134 * * Depth Cache Flush Enable ([0] of DW1)
1135 * * Stall at Pixel Scoreboard ([1] of DW1)
1136 * * Depth Stall ([13] of DW1)
1137 * * Post-Sync Operation ([13] of DW1)"
1138 */
1139 gen6_PIPE_CONTROL(cmd,
1140 GEN6_PIPE_CONTROL_CS_STALL |
1141 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001142 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001143}
1144
1145static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1146{
1147 CMD_ASSERT(cmd, 7, 7.5);
1148
1149 if (!cmd->bind.draw_count)
1150 return;
1151
1152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
Chia-I Wud6d079d2014-08-31 13:14:21 +08001154 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
1156
1157static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1158{
1159 CMD_ASSERT(cmd, 6, 7.5);
1160
1161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 /*
1165 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1166 *
1167 * "Driver must guarentee that all the caches in the depth pipe are
1168 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1169 * requires driver to send a PIPE_CONTROL with a CS stall along with
1170 * a Depth Flush prior to this command."
1171 *
1172 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1173 *
1174 * "Driver must ierarchi that all the caches in the depth pipe are
1175 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1176 * requires driver to send a PIPE_CONTROL with a CS stall along with
1177 * a Depth Flush prior to this command.
1178 */
1179 gen6_PIPE_CONTROL(cmd,
1180 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1181 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001182 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001183}
1184
1185static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1186{
1187 CMD_ASSERT(cmd, 6, 7.5);
1188
1189 if (!cmd->bind.draw_count)
1190 return;
1191
1192 /*
1193 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1194 *
1195 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1196 * and a post sync operation prior to the group of depth
1197 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1198 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1199 *
1200 * This workaround satifies all the conditions.
1201 */
1202 cmd_wa_gen6_pre_depth_stall_write(cmd);
1203
1204 /*
1205 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1206 *
1207 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1208 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1209 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1210 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1211 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1212 * Depth Flush Bit set, followed by another pipelined depth stall
1213 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1214 * guarantee that the pipeline from WM onwards is already flushed
1215 * (e.g., via a preceding MI_FLUSH)."
1216 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001217 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1218 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1219 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001220}
1221
Chia-I Wu525c6602014-08-27 10:22:34 +08001222void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1223{
1224 if (!cmd->bind.draw_count)
1225 return;
1226
1227 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1228
Chia-I Wu8370b402014-08-29 12:28:37 +08001229 /*
1230 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1231 *
1232 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1233 * PIPE_CONTROL with any non-zero post-sync-op is required."
1234 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001235 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001236 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001237
Chia-I Wu092279a2014-08-30 19:05:30 +08001238 /*
1239 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1240 *
1241 * "One of the following must also be set (when CS stall is set):
1242 *
1243 * * Render Target Cache Flush Enable ([12] of DW1)
1244 * * Depth Cache Flush Enable ([0] of DW1)
1245 * * Stall at Pixel Scoreboard ([1] of DW1)
1246 * * Depth Stall ([13] of DW1)
1247 * * Post-Sync Operation ([13] of DW1)"
1248 */
1249 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1250 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1251 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1252 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1253 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1254 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1255
Chia-I Wud6d079d2014-08-31 13:14:21 +08001256 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001257}
1258
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001259void cmd_batch_flush_all(struct intel_cmd *cmd)
1260{
1261 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1262 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1263 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1264 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1265 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1266 GEN6_PIPE_CONTROL_CS_STALL);
1267}
1268
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001269void cmd_batch_depth_count(struct intel_cmd *cmd,
1270 struct intel_bo *bo,
1271 XGL_GPU_SIZE offset)
1272{
1273 cmd_wa_gen6_pre_depth_stall_write(cmd);
1274
1275 gen6_PIPE_CONTROL(cmd,
1276 GEN6_PIPE_CONTROL_DEPTH_STALL |
1277 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001278 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001279}
1280
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001281void cmd_batch_timestamp(struct intel_cmd *cmd,
1282 struct intel_bo *bo,
1283 XGL_GPU_SIZE offset)
1284{
1285 /* need any WA or stall? */
1286 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1287}
1288
1289void cmd_batch_immediate(struct intel_cmd *cmd,
1290 struct intel_bo *bo,
1291 XGL_GPU_SIZE offset,
1292 uint64_t val)
1293{
1294 /* need any WA or stall? */
1295 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1296}
1297
Chia-I Wu302742d2014-08-22 10:28:29 +08001298static void gen6_cc_states(struct intel_cmd *cmd)
1299{
1300 const struct intel_blend_state *blend = cmd->bind.state.blend;
1301 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001302 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001303 uint32_t stencil_ref;
1304 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001305
1306 CMD_ASSERT(cmd, 6, 6);
1307
Chia-I Wua6c4f152014-12-02 04:19:58 +08001308 blend_offset = gen6_BLEND_STATE(cmd);
1309
1310 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001311 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001312 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001313 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001314
1315 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001316 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001317 stencil_ref = ds->cmd_stencil_ref;
1318 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001319 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001320 stencil_ref = 0;
1321 }
1322
Chia-I Wu72292b72014-09-09 10:48:33 +08001323 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001324
Chia-I Wu72292b72014-09-09 10:48:33 +08001325 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001326}
1327
Chia-I Wu1744cca2014-08-22 11:10:17 +08001328static void gen6_viewport_states(struct intel_cmd *cmd)
1329{
1330 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001331 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001332
1333 if (!viewport)
1334 return;
1335
Chia-I Wub1d450a2014-09-09 13:48:03 +08001336 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1337 viewport->viewport_count);
1338
1339 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001340 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001341 viewport->cmd);
1342
1343 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001344 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001345 &viewport->cmd[viewport->cmd_clip_pos]);
1346
1347 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001348 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001349 &viewport->cmd[viewport->cmd_cc_pos]);
1350
1351 if (viewport->scissor_enable) {
1352 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001353 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001354 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1355 } else {
1356 scissor_offset = 0;
1357 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001358
1359 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001360 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001361
Chia-I Wub1d450a2014-09-09 13:48:03 +08001362 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001363}
1364
Chia-I Wu302742d2014-08-22 10:28:29 +08001365static void gen7_cc_states(struct intel_cmd *cmd)
1366{
1367 const struct intel_blend_state *blend = cmd->bind.state.blend;
1368 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001369 uint32_t stencil_ref;
1370 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001372
1373 CMD_ASSERT(cmd, 7, 7.5);
1374
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001375 if (!blend && !ds)
1376 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001377
Chia-I Wua6c4f152014-12-02 04:19:58 +08001378 offset = gen6_BLEND_STATE(cmd);
1379 gen7_3dstate_pointer(cmd,
1380 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001381
Chia-I Wua6c4f152014-12-02 04:19:58 +08001382 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001383 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001384 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001385 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001386
1387 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001388 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Mike Stroyan214ad462015-01-15 11:27:12 -07001389 stencil_ref = ds->cmd_stencil_ref;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001390 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001391 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1392 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001393 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1394 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001395 } else {
1396 stencil_ref = 0;
1397 }
1398
Chia-I Wu72292b72014-09-09 10:48:33 +08001399 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001400 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001401 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001402}
1403
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404static void gen7_viewport_states(struct intel_cmd *cmd)
1405{
1406 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001407 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001408
1409 if (!viewport)
1410 return;
1411
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1413 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001414
Chia-I Wub1d450a2014-09-09 13:48:03 +08001415 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001416 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001418 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001419 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1420 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001421
1422 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001423 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001425 gen7_3dstate_pointer(cmd,
1426 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001428
Chia-I Wu1744cca2014-08-22 11:10:17 +08001429 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001430 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001431 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001432 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001433 gen7_3dstate_pointer(cmd,
1434 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001435 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001436 }
1437}
1438
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001439static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001440 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001441{
1442 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001443 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001444
Chia-I Wu72292b72014-09-09 10:48:33 +08001445 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001446
1447 dw[0] = GEN6_RENDER_TYPE_RENDER |
1448 GEN6_RENDER_SUBTYPE_3D |
1449 subop | (cmd_len - 2);
1450 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001451 dw[2] = 0;
1452 dw[3] = 0;
1453 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001454}
1455
1456static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001457 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001458{
1459 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001460 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001461
Chia-I Wu72292b72014-09-09 10:48:33 +08001462 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001463
1464 dw[0] = GEN6_RENDER_TYPE_RENDER |
1465 GEN6_RENDER_SUBTYPE_3D |
1466 subop | (cmd_len - 2);
1467 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001468 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001469 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001470 dw[4] = 0;
1471 dw[5] = 0;
1472 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001473}
1474
Chia-I Wu625105f2014-10-13 15:35:29 +08001475static uint32_t emit_samplers(struct intel_cmd *cmd,
1476 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001477{
1478 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1479 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001480 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001481 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001482 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001483 XGL_UINT i;
1484
1485 CMD_ASSERT(cmd, 6, 7.5);
1486
Chia-I Wu625105f2014-10-13 15:35:29 +08001487 if (!rmap || !rmap->sampler_count)
1488 return 0;
1489
Cody Northrop40316a32014-12-09 19:08:33 -07001490 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001491
Chia-I Wudcb509d2014-12-10 08:53:10 +08001492 /*
1493 * note that we cannot call cmd_state_pointer() here as the following
1494 * cmd_state_pointer() would invalidate the pointer
1495 */
1496 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001497 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001498 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001499
1500 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001501 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001502 4 * rmap->sampler_count, &sampler_dw);
1503
Chia-I Wudcb509d2014-12-10 08:53:10 +08001504 cmd_state_update(cmd, border_offset,
1505 border_stride * rmap->sampler_count, &border_dw);
1506
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001507 for (i = 0; i < rmap->sampler_count; i++) {
1508 const struct intel_pipeline_rmap_slot *slot =
1509 &rmap->slots[surface_count + i];
1510 const struct intel_sampler *sampler;
1511
1512 switch (slot->path_len) {
1513 case 0:
1514 sampler = NULL;
1515 break;
1516 case INTEL_PIPELINE_RMAP_SLOT_RT:
1517 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1518 assert(!"unexpected rmap slot type");
1519 sampler = NULL;
1520 break;
1521 case 1:
1522 {
1523 const struct intel_dset *dset = cmd->bind.dset.graphics;
1524 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1525 const struct intel_dset_slot *dset_slot =
1526 &dset->slots[slot_offset + slot->u.index];
1527
1528 switch (dset_slot->type) {
1529 case INTEL_DSET_SLOT_SAMPLER:
1530 sampler = dset_slot->u.sampler;
1531 break;
1532 default:
1533 assert(!"unexpected dset slot type");
1534 sampler = NULL;
1535 break;
1536 }
1537 }
1538 break;
1539 default:
1540 assert(!"nested descriptor set unsupported");
1541 sampler = NULL;
1542 break;
1543 }
1544
1545 if (sampler) {
1546 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1547
1548 sampler_dw[0] = sampler->cmd[0];
1549 sampler_dw[1] = sampler->cmd[1];
1550 sampler_dw[2] = border_offset;
1551 sampler_dw[3] = sampler->cmd[2];
1552 } else {
1553 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1554 sampler_dw[1] = 0;
1555 sampler_dw[2] = 0;
1556 sampler_dw[3] = 0;
1557 }
1558
1559 border_offset += border_stride * 4;
1560 border_dw += border_stride;
1561 sampler_dw += 4;
1562 }
1563
Chia-I Wu625105f2014-10-13 15:35:29 +08001564 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001565}
1566
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001567static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001568 const struct intel_pipeline_rmap *rmap,
1569 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001570{
Chia-I Wu72292b72014-09-09 10:48:33 +08001571 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001572 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001574 CMD_ASSERT(cmd, 6, 7.5);
1575
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001576 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001577 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001578 if (!surface_count)
1579 return 0;
1580
Chia-I Wu42a56202014-08-23 16:47:48 +08001581 assert(surface_count <= ARRAY_SIZE(binding_table));
1582
1583 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001584 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001585
1586 switch (slot->path_len) {
1587 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001588 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001589 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001590 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001591 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001592 const struct intel_rt_view *view =
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001593 (slot->u.index < cmd->bind.render_pass->fb->rt_count) ?
1594 cmd->bind.render_pass->fb->rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001595
Chia-I Wu787a05b2014-12-05 11:02:20 +08001596 if (view) {
1597 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1598 GEN6_ALIGNMENT_SURFACE_STATE,
1599 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001600
Chia-I Wu787a05b2014-12-05 11:02:20 +08001601 cmd_reserve_reloc(cmd, 1);
1602 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1603 view->cmd[1], INTEL_RELOC_WRITE);
1604 } else {
1605 struct intel_null_view null_view;
1606 intel_null_view_init(&null_view, cmd->dev);
1607
1608 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1609 GEN6_ALIGNMENT_SURFACE_STATE,
1610 null_view.cmd_len, null_view.cmd);
1611 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001612 }
1613 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001614 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001615 {
Chia-I Wu714df452015-01-01 07:55:04 +08001616 const struct intel_buf_view *view =
1617 cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001618
Chia-I Wu00b51a82014-09-09 12:07:37 +08001619 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001620 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001621 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001622
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 cmd_reserve_reloc(cmd, 1);
Chia-I Wu714df452015-01-01 07:55:04 +08001624 cmd_surface_reloc(cmd, offset, 1, view->buf->obj.mem->bo,
Chia-I Wu72292b72014-09-09 10:48:33 +08001625 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001626 }
1627 break;
1628 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001629 {
1630 const struct intel_dset *dset = cmd->bind.dset.graphics;
1631 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1632 const struct intel_dset_slot *dset_slot =
1633 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001634 const uint32_t reloc_flags =
1635 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001636
1637 switch (dset_slot->type) {
1638 case INTEL_DSET_SLOT_IMG_VIEW:
1639 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001640 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641 dset_slot->u.img_view->cmd_len,
1642 dset_slot->u.img_view->cmd);
1643
1644 cmd_reserve_reloc(cmd, 1);
1645 cmd_surface_reloc(cmd, offset, 1,
1646 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001647 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001648 break;
Chia-I Wu714df452015-01-01 07:55:04 +08001649 case INTEL_DSET_SLOT_BUF_VIEW:
Cody Northrop7c76f302014-12-18 11:52:58 -07001650 {
Chia-I Wu714df452015-01-01 07:55:04 +08001651 XGL_BUFFER_VIEW_CREATE_INFO tmp_info =
1652 dset_slot->u.buf_view->info;
1653 struct intel_buf_view *tmp;
1654 XGL_RESULT res;
Cody Northrop7c76f302014-12-18 11:52:58 -07001655
1656 /* The compiler expects uniform buffers to have pitch of
1657 * 4 for fragment shaders, but 16 for other stages.
1658 */
Cody Northropbef0e552015-01-13 12:13:46 -07001659 tmp_info.format.channelFormat = XGL_CH_FMT_R32G32B32A32;
1660 tmp_info.format.numericFormat = XGL_NUM_FMT_FLOAT;
Cody Northrop7c76f302014-12-18 11:52:58 -07001661 if (XGL_SHADER_STAGE_FRAGMENT == stage) {
1662 tmp_info.stride = 4;
1663 } else {
1664 tmp_info.stride = 16;
1665 }
1666
Chia-I Wu714df452015-01-01 07:55:04 +08001667 res = intel_buf_view_create(cmd->dev, &tmp_info, &tmp);
1668 if (res != XGL_SUCCESS) {
1669 cmd->result = res;
1670 break;
1671 }
Cody Northrop7c76f302014-12-18 11:52:58 -07001672
1673 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1674 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu714df452015-01-01 07:55:04 +08001675 tmp->cmd_len,
1676 tmp->cmd);
Cody Northrop7c76f302014-12-18 11:52:58 -07001677
1678 cmd_reserve_reloc(cmd, 1);
1679 cmd_surface_reloc(cmd, offset, 1,
Chia-I Wu714df452015-01-01 07:55:04 +08001680 dset_slot->u.buf_view->buf->obj.mem->bo,
1681 tmp->cmd[1], reloc_flags);
1682
1683 intel_buf_view_destroy(tmp);
Cody Northrop7c76f302014-12-18 11:52:58 -07001684 }
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001685 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001686 case INTEL_DSET_SLOT_SAMPLER:
1687 assert(0 == cmd->bind.dset.graphics_offset);
1688
1689 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001690 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001691 16, dset_slot->u.sampler->cmd);
1692 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001693 default:
1694 assert(!"unexpected dset slot type");
1695 break;
1696 }
1697 }
1698 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001699 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001700 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001701 break;
1702 }
1703
Chia-I Wu72292b72014-09-09 10:48:33 +08001704 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001705 }
1706
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001707 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001708 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001709 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001710}
1711
Chia-I Wu1d125092014-10-08 08:49:38 +08001712static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1713{
1714 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001715 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1716 uint32_t *dw;
1717 XGL_UINT pos, i;
1718
1719 CMD_ASSERT(cmd, 6, 7.5);
1720
1721 if (!pipeline->vb_count)
1722 return;
1723
1724 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1725
1726 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1727 dw++;
1728 pos++;
1729
1730 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001731 assert(pipeline->vb[i].strideInBytes <= 2048);
1732
1733 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1734 pipeline->vb[i].strideInBytes;
1735
1736 if (cmd_gen(cmd) >= INTEL_GEN(7))
1737 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1738
1739 switch (pipeline->vb[i].stepRate) {
1740 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1741 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1742 dw[3] = 0;
1743 break;
1744 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1745 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1746 dw[3] = 1;
1747 break;
1748 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1749 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1750 dw[3] = 0;
1751 break;
1752 default:
1753 assert(!"unknown step rate");
1754 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1755 dw[3] = 0;
1756 break;
1757 }
1758
Chia-I Wu714df452015-01-01 07:55:04 +08001759 if (cmd->bind.vertex.buf[i]) {
1760 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001761 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001762
1763 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001764 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1765 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001766 } else {
1767 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1768 dw[1] = 0;
1769 dw[2] = 0;
1770 }
1771
1772 dw += 4;
1773 pos += 4;
1774 }
1775}
1776
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001777static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1778{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001779 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1780 const struct intel_pipeline_shader *vs = &pipeline->vs;
1781 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001782 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001783 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001784 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001785 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001786
1787 CMD_ASSERT(cmd, 6, 7.5);
1788
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001789 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001790 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1791 *
1792 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1793 * 128-bit vertex elements to be passed into the payload for each
1794 * vertex."
1795 *
1796 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1797 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001798 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001799 vue_read_len = (vs->in_count + 1) / 2;
1800 if (!vue_read_len)
1801 vue_read_len = 1;
1802
1803 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1804 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1805
1806 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1807 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1808 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001809
1810 dw5 = GEN6_VS_DW5_STATISTICS |
1811 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001812
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001813 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001814 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001815 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001816 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001817
Chia-I Wube0a3d92014-09-02 13:20:59 +08001818 if (pipeline->disable_vs_cache)
1819 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1820
Chia-I Wu784d3042014-12-19 14:30:04 +08001821 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001822 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001823 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001824 dw[2] = dw2;
1825 dw[3] = 0; /* scratch */
1826 dw[4] = dw4;
1827 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001828
1829 if (vs->per_thread_scratch_size)
1830 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001831}
1832
Chia-I Wu625105f2014-10-13 15:35:29 +08001833static void emit_shader_resources(struct intel_cmd *cmd)
1834{
1835 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001836 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001837
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001838 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001839 cmd->bind.pipeline.graphics->vs.rmap,
1840 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001841 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001842 cmd->bind.pipeline.graphics->tcs.rmap,
1843 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001844 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001845 cmd->bind.pipeline.graphics->tes.rmap,
1846 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001847 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001848 cmd->bind.pipeline.graphics->gs.rmap,
1849 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001850 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001851 cmd->bind.pipeline.graphics->fs.rmap,
1852 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001853
1854 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1855 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1856 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1857 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1858 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1859
1860 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1861 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001862 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1863 binding_tables[0]);
1864 gen7_3dstate_pointer(cmd,
1865 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1866 binding_tables[1]);
1867 gen7_3dstate_pointer(cmd,
1868 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1869 binding_tables[2]);
1870 gen7_3dstate_pointer(cmd,
1871 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1872 binding_tables[3]);
1873 gen7_3dstate_pointer(cmd,
1874 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1875 binding_tables[4]);
1876
1877 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001878 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1879 samplers[0]);
1880 gen7_3dstate_pointer(cmd,
1881 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1882 samplers[1]);
1883 gen7_3dstate_pointer(cmd,
1884 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1885 samplers[2]);
1886 gen7_3dstate_pointer(cmd,
1887 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1888 samplers[3]);
1889 gen7_3dstate_pointer(cmd,
1890 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1891 samplers[4]);
1892 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001893 assert(!binding_tables[1] && !binding_tables[2]);
1894 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1895 binding_tables[0], binding_tables[3], binding_tables[4]);
1896
Chia-I Wu625105f2014-10-13 15:35:29 +08001897 assert(!samplers[1] && !samplers[2]);
1898 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1899 samplers[0], samplers[3], samplers[4]);
1900 }
1901}
1902
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001903static void emit_rt(struct intel_cmd *cmd)
1904{
1905 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001906 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1907 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001908}
1909
1910static void emit_ds(struct intel_cmd *cmd)
1911{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001912 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001913
1914 if (!ds) {
1915 /* all zeros */
1916 static const struct intel_ds_view null_ds;
1917 ds = &null_ds;
1918 }
1919
1920 cmd_wa_gen6_pre_ds_flush(cmd);
1921 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1922 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1923 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1924
1925 if (cmd_gen(cmd) >= INTEL_GEN(7))
1926 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1927 else
1928 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1929}
1930
Chia-I Wua57761b2014-10-14 14:27:44 +08001931static uint32_t emit_shader(struct intel_cmd *cmd,
1932 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001933{
Chia-I Wua57761b2014-10-14 14:27:44 +08001934 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1935 uint32_t offset;
1936 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001937
Chia-I Wua57761b2014-10-14 14:27:44 +08001938 /* see if the shader is already in the cache */
1939 for (i = 0; i < cache->used; i++) {
1940 if (cache->entries[i].shader == (const void *) shader)
1941 return cache->entries[i].kernel_offset;
1942 }
1943
1944 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1945
1946 /* grow the cache if full */
1947 if (cache->used >= cache->count) {
1948 const XGL_UINT count = cache->count + 16;
1949 void *entries;
1950
1951 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1952 XGL_SYSTEM_ALLOC_INTERNAL);
1953 if (entries) {
1954 if (cache->entries) {
1955 memcpy(entries, cache->entries,
1956 sizeof(cache->entries[0]) * cache->used);
1957 icd_free(cache->entries);
1958 }
1959
1960 cache->entries = entries;
1961 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001962 }
1963 }
1964
Chia-I Wua57761b2014-10-14 14:27:44 +08001965 /* add the shader to the cache */
1966 if (cache->used < cache->count) {
1967 cache->entries[cache->used].shader = (const void *) shader;
1968 cache->entries[cache->used].kernel_offset = offset;
1969 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001970 }
1971
Chia-I Wua57761b2014-10-14 14:27:44 +08001972 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001973}
1974
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001975static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001976{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001977 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001978
Chia-I Wu8370b402014-08-29 12:28:37 +08001979 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1980 cmd_wa_gen6_pre_depth_stall_write(cmd);
1981 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1982 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1983 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1984 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001985
1986 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001987 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001988 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001989
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001990 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001991 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001992 }
1993 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001994 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001995 }
1996 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001997 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1998 }
1999 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2000 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2001 }
2002 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2003 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002004 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002005
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002006 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2007 gen7_3DSTATE_GS(cmd);
2008 } else {
2009 gen6_3DSTATE_GS(cmd);
2010 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002011
Chia-I Wu8370b402014-08-29 12:28:37 +08002012 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2013 cmd_wa_gen7_post_command_cs_stall(cmd);
2014 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2015 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002016}
2017
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002018static void emit_bounded_states(struct intel_cmd *cmd)
2019{
2020 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
2021
2022 emit_graphics_pipeline(cmd);
2023
2024 emit_rt(cmd);
2025 emit_ds(cmd);
2026
2027 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2028 gen7_cc_states(cmd);
2029 gen7_viewport_states(cmd);
2030
2031 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2032 &cmd->bind.pipeline.graphics->vs);
2033 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2034 &cmd->bind.pipeline.graphics->fs);
2035
2036 gen6_3DSTATE_CLIP(cmd);
2037 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002038 gen7_3DSTATE_WM(cmd);
2039 gen7_3DSTATE_PS(cmd);
2040 } else {
2041 gen6_cc_states(cmd);
2042 gen6_viewport_states(cmd);
2043
2044 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2045 &cmd->bind.pipeline.graphics->vs);
2046 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2047 &cmd->bind.pipeline.graphics->fs);
2048
2049 gen6_3DSTATE_CLIP(cmd);
2050 gen6_3DSTATE_SF(cmd);
2051 gen6_3DSTATE_WM(cmd);
2052 }
2053
2054 emit_shader_resources(cmd);
2055
2056 cmd_wa_gen6_pre_depth_stall_write(cmd);
2057 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2058
2059 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2060 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2061
2062 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2063 gen6_3DSTATE_VS(cmd);
2064}
2065
Chia-I Wu6032b892014-10-17 14:47:18 +08002066static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2067{
2068 const struct intel_cmd_meta *meta = cmd->bind.meta;
2069 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2070
2071 CMD_ASSERT(cmd, 6, 7.5);
2072
2073 blend_offset = 0;
2074 ds_offset = 0;
2075 cc_offset = 0;
2076 cc_vp_offset = 0;
2077
Chia-I Wu29e6f502014-11-24 14:27:29 +08002078 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002079 /* BLEND_STATE */
2080 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002081 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002082 dw[0] = 0;
2083 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2084 }
2085
Chia-I Wu29e6f502014-11-24 14:27:29 +08002086 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2087 if (meta->ds.state) {
2088 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002089
Chia-I Wu29e6f502014-11-24 14:27:29 +08002090 /* DEPTH_STENCIL_STATE */
2091 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002092
Chia-I Wu29e6f502014-11-24 14:27:29 +08002093 /* COLOR_CALC_STATE */
2094 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2095 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002096
Chia-I Wu29e6f502014-11-24 14:27:29 +08002097 /* CC_VIEWPORT */
2098 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002099 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002100 dw[0] = u_fui(0.0f);
2101 dw[1] = u_fui(1.0f);
2102 } else {
2103 /* DEPTH_STENCIL_STATE */
2104 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002105 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002106 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2107 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2108 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002109 }
2110
2111 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2112 gen7_3dstate_pointer(cmd,
2113 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2114 blend_offset);
2115 gen7_3dstate_pointer(cmd,
2116 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2117 ds_offset);
2118 gen7_3dstate_pointer(cmd,
2119 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2120
2121 gen7_3dstate_pointer(cmd,
2122 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2123 cc_vp_offset);
2124 } else {
2125 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002126 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002127
2128 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2129 cmd_batch_pointer(cmd, 4, &dw);
2130 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2131 GEN6_PTR_VP_DW0_CC_CHANGED;
2132 dw[1] = 0;
2133 dw[2] = 0;
2134 dw[3] = cc_vp_offset;
2135 }
2136}
2137
2138static void gen6_meta_surface_states(struct intel_cmd *cmd)
2139{
2140 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002141 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002142 uint32_t offset;
2143
2144 CMD_ASSERT(cmd, 6, 7.5);
2145
Chia-I Wu29e6f502014-11-24 14:27:29 +08002146 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2147 return;
2148
Chia-I Wu005c47c2014-10-22 13:49:13 +08002149 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002150 if (meta->src.valid) {
2151 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002152 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 meta->src.surface_len, meta->src.surface);
2154
2155 cmd_reserve_reloc(cmd, 1);
2156 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2157 cmd_surface_reloc_writer(cmd, offset, 1,
2158 meta->src.reloc_target, meta->src.reloc_offset);
2159 } else {
2160 cmd_surface_reloc(cmd, offset, 1,
2161 (struct intel_bo *) meta->src.reloc_target,
2162 meta->src.reloc_offset, meta->src.reloc_flags);
2163 }
2164
Chia-I Wu005c47c2014-10-22 13:49:13 +08002165 binding_table[0] = offset;
2166 }
2167 if (meta->dst.valid) {
2168 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002169 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002170 meta->dst.surface_len, meta->dst.surface);
2171
2172 cmd_reserve_reloc(cmd, 1);
2173 cmd_surface_reloc(cmd, offset, 1,
2174 (struct intel_bo *) meta->dst.reloc_target,
2175 meta->dst.reloc_offset, meta->dst.reloc_flags);
2176
2177 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002178 }
2179
2180 /* BINDING_TABLE */
2181 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002182 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002183 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002184
2185 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002186 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2187 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2188 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2189 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002190 } else {
2191 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002192 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2193 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2194 else
2195 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002196 }
2197}
2198
2199static void gen6_meta_urb(struct intel_cmd *cmd)
2200{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002201 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002202 uint32_t *dw;
2203
2204 CMD_ASSERT(cmd, 6, 6);
2205
2206 /* 3DSTATE_URB */
2207 cmd_batch_pointer(cmd, 3, &dw);
2208 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002209 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002210 dw[2] = 0;
2211}
2212
2213static void gen7_meta_urb(struct intel_cmd *cmd)
2214{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002215 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002216 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002217 uint32_t *dw;
2218
2219 CMD_ASSERT(cmd, 7, 7.5);
2220
2221 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2222 cmd_batch_pointer(cmd, 10, &dw);
2223
2224 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002225 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002226 dw += 2;
2227
2228 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2229 dw[1] = 0;
2230 dw += 2;
2231
2232 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2233 dw[1] = 0;
2234 dw += 2;
2235
2236 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2237 dw[1] = 0;
2238 dw += 2;
2239
2240 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002241 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002242
2243 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2244
Chia-I Wu24aa1022014-11-25 11:53:19 +08002245 switch (cmd_gen(cmd)) {
2246 case INTEL_GEN(7.5):
2247 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2248 break;
2249 case INTEL_GEN(7):
2250 default:
2251 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2252 break;
2253 }
2254
Chia-I Wu6032b892014-10-17 14:47:18 +08002255 /* 3DSTATE_URB_x */
2256 cmd_batch_pointer(cmd, 8, &dw);
2257
2258 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2259 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002260 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002261 dw += 2;
2262
2263 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2264 dw[1] = 0;
2265 dw += 2;
2266
2267 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2268 dw[1] = 0;
2269 dw += 2;
2270
2271 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2272 dw[1] = 0;
2273 dw += 2;
2274}
2275
2276static void gen6_meta_vf(struct intel_cmd *cmd)
2277{
2278 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002279 uint32_t vb_start, vb_end, vb_stride;
2280 int ve_format, ve_z_source;
2281 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002282 XGL_UINT pos;
2283
2284 CMD_ASSERT(cmd, 6, 7.5);
2285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 switch (meta->mode) {
2287 case INTEL_CMD_META_VS_POINTS:
2288 cmd_batch_pointer(cmd, 3, &dw);
2289 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2290 dw[1] = GEN6_VE_STATE_DW0_VALID;
2291 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2292 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2293 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2294 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2295 return;
2296 break;
2297 case INTEL_CMD_META_FS_RECT:
2298 {
2299 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002300
Chia-I Wu29e6f502014-11-24 14:27:29 +08002301 vertices[0][0] = meta->dst.x + meta->width;
2302 vertices[0][1] = meta->dst.y + meta->height;
2303 vertices[1][0] = meta->dst.x;
2304 vertices[1][1] = meta->dst.y + meta->height;
2305 vertices[2][0] = meta->dst.x;
2306 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002307
Chia-I Wu29e6f502014-11-24 14:27:29 +08002308 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2309 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002310
Chia-I Wu29e6f502014-11-24 14:27:29 +08002311 vb_end = vb_start + sizeof(vertices) - 1;
2312 vb_stride = sizeof(vertices[0]);
2313 ve_z_source = GEN6_VFCOMP_STORE_0;
2314 ve_format = GEN6_FORMAT_R32G32_USCALED;
2315 }
2316 break;
2317 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2318 {
2319 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002320
Chia-I Wu29e6f502014-11-24 14:27:29 +08002321 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2322 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2323 vertices[0][2] = u_uif(meta->clear_val[0]);
2324 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2325 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2326 vertices[1][2] = u_uif(meta->clear_val[0]);
2327 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2328 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2329 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002330
Chia-I Wu29e6f502014-11-24 14:27:29 +08002331 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2332 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333
Chia-I Wu29e6f502014-11-24 14:27:29 +08002334 vb_end = vb_start + sizeof(vertices) - 1;
2335 vb_stride = sizeof(vertices[0]);
2336 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2337 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2338 }
2339 break;
2340 default:
2341 assert(!"unknown meta mode");
2342 return;
2343 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002344 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002345
2346 /* 3DSTATE_VERTEX_BUFFERS */
2347 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002348
Chia-I Wu6032b892014-10-17 14:47:18 +08002349 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002350 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002351 if (cmd_gen(cmd) >= INTEL_GEN(7))
2352 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2353
2354 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002355 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2356 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002357
2358 dw[4] = 0;
2359
2360 /* 3DSTATE_VERTEX_ELEMENTS */
2361 cmd_batch_pointer(cmd, 5, &dw);
2362 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002363 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002364 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2365 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2366 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2367 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2368 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002369 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002370 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2371 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002372 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002373 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2374}
2375
Chia-I Wu29e6f502014-11-24 14:27:29 +08002376static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002377{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002378 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002379 /* one GPR */
2380 XGL_UINT consts[8];
2381 XGL_UINT const_count;
2382
2383 CMD_ASSERT(cmd, 6, 7.5);
2384
2385 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002386 case INTEL_DEV_META_VS_FILL_MEM:
2387 consts[0] = meta->dst.x;
2388 consts[1] = meta->clear_val[0];
2389 const_count = 2;
2390 break;
2391 case INTEL_DEV_META_VS_COPY_MEM:
2392 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2393 consts[0] = meta->dst.x;
2394 consts[1] = meta->src.x;
2395 const_count = 2;
2396 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002397 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2398 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2399 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2400 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2401 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2402 consts[0] = meta->src.x;
2403 consts[1] = meta->src.y;
2404 consts[2] = meta->width;
2405 consts[3] = meta->dst.x;
2406 const_count = 4;
2407 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002408 default:
2409 assert(!"unknown meta shader id");
2410 const_count = 0;
2411 break;
2412 }
2413
2414 /* this can be skipped but it makes state dumping prettier */
2415 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2416
2417 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2418}
2419
2420static void gen6_meta_vs(struct intel_cmd *cmd)
2421{
2422 const struct intel_cmd_meta *meta = cmd->bind.meta;
2423 const struct intel_pipeline_shader *sh =
2424 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2425 uint32_t offset, *dw;
2426
2427 CMD_ASSERT(cmd, 6, 7.5);
2428
2429 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2430 XGL_UINT cmd_len;
2431
2432 /* 3DSTATE_CONSTANT_VS */
2433 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2434 cmd_batch_pointer(cmd, cmd_len, &dw);
2435 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2436 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2437
2438 /* 3DSTATE_VS */
2439 cmd_batch_pointer(cmd, 6, &dw);
2440 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2441 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2442
2443 return;
2444 }
2445
2446 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2447
2448 /* 3DSTATE_CONSTANT_VS */
2449 offset = gen6_meta_vs_constants(cmd);
2450 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2451 cmd_batch_pointer(cmd, 7, &dw);
2452 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2453 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2454 dw[2] = 0;
2455 dw[3] = offset;
2456 dw[4] = 0;
2457 dw[5] = 0;
2458 dw[6] = 0;
2459 } else {
2460 cmd_batch_pointer(cmd, 5, &dw);
2461 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2462 GEN6_PCB_ANY_DW0_PCB0_VALID;
2463 dw[1] = offset;
2464 dw[2] = 0;
2465 dw[3] = 0;
2466 dw[4] = 0;
2467 }
2468
2469 /* 3DSTATE_VS */
2470 offset = emit_shader(cmd, sh);
2471 cmd_batch_pointer(cmd, 6, &dw);
2472 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2473 dw[1] = offset;
2474 dw[2] = GEN6_THREADDISP_SPF |
2475 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2476 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002477 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002478 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2479 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2480
2481 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2482 GEN6_VS_DW5_VS_ENABLE;
2483 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002484 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002485 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002486 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002487
2488 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002489}
2490
2491static void gen6_meta_disabled(struct intel_cmd *cmd)
2492{
Chia-I Wu6032b892014-10-17 14:47:18 +08002493 uint32_t *dw;
2494
2495 CMD_ASSERT(cmd, 6, 6);
2496
Chia-I Wu6032b892014-10-17 14:47:18 +08002497 /* 3DSTATE_CONSTANT_GS */
2498 cmd_batch_pointer(cmd, 5, &dw);
2499 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2500 dw[1] = 0;
2501 dw[2] = 0;
2502 dw[3] = 0;
2503 dw[4] = 0;
2504
2505 /* 3DSTATE_GS */
2506 cmd_batch_pointer(cmd, 7, &dw);
2507 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2508 dw[1] = 0;
2509 dw[2] = 0;
2510 dw[3] = 0;
2511 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2512 dw[5] = GEN6_GS_DW5_STATISTICS;
2513 dw[6] = 0;
2514
Chia-I Wu6032b892014-10-17 14:47:18 +08002515 /* 3DSTATE_SF */
2516 cmd_batch_pointer(cmd, 20, &dw);
2517 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2518 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2519 memset(&dw[2], 0, 18 * sizeof(*dw));
2520}
2521
2522static void gen7_meta_disabled(struct intel_cmd *cmd)
2523{
2524 uint32_t *dw;
2525
2526 CMD_ASSERT(cmd, 7, 7.5);
2527
Chia-I Wu6032b892014-10-17 14:47:18 +08002528 /* 3DSTATE_CONSTANT_HS */
2529 cmd_batch_pointer(cmd, 7, &dw);
2530 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2531 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2532
2533 /* 3DSTATE_HS */
2534 cmd_batch_pointer(cmd, 7, &dw);
2535 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2536 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2537
2538 /* 3DSTATE_TE */
2539 cmd_batch_pointer(cmd, 4, &dw);
2540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2541 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2542
2543 /* 3DSTATE_CONSTANT_DS */
2544 cmd_batch_pointer(cmd, 7, &dw);
2545 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2546 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2547
2548 /* 3DSTATE_DS */
2549 cmd_batch_pointer(cmd, 6, &dw);
2550 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2551 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2552
2553 /* 3DSTATE_CONSTANT_GS */
2554 cmd_batch_pointer(cmd, 7, &dw);
2555 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2556 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2557
2558 /* 3DSTATE_GS */
2559 cmd_batch_pointer(cmd, 7, &dw);
2560 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2561 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2562
2563 /* 3DSTATE_STREAMOUT */
2564 cmd_batch_pointer(cmd, 3, &dw);
2565 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2566 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2567
Chia-I Wu6032b892014-10-17 14:47:18 +08002568 /* 3DSTATE_SF */
2569 cmd_batch_pointer(cmd, 7, &dw);
2570 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2571 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2572
2573 /* 3DSTATE_SBE */
2574 cmd_batch_pointer(cmd, 14, &dw);
2575 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2576 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2577 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002578}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002579
Chia-I Wu29e6f502014-11-24 14:27:29 +08002580static void gen6_meta_clip(struct intel_cmd *cmd)
2581{
2582 const struct intel_cmd_meta *meta = cmd->bind.meta;
2583 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002584
Chia-I Wu29e6f502014-11-24 14:27:29 +08002585 /* 3DSTATE_CLIP */
2586 cmd_batch_pointer(cmd, 4, &dw);
2587 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2588 dw[1] = 0;
2589 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2590 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2591 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2592 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002593 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002594 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002595 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002596}
2597
2598static void gen6_meta_wm(struct intel_cmd *cmd)
2599{
2600 const struct intel_cmd_meta *meta = cmd->bind.meta;
2601 uint32_t *dw;
2602
2603 CMD_ASSERT(cmd, 6, 7.5);
2604
2605 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2606
2607 /* 3DSTATE_MULTISAMPLE */
2608 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2609 cmd_batch_pointer(cmd, 4, &dw);
2610 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2611 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2612 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2613 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2614 dw[2] = 0;
2615 dw[3] = 0;
2616 } else {
2617 cmd_batch_pointer(cmd, 3, &dw);
2618 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2619 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2620 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2621 dw[2] = 0;
2622 }
2623
2624 /* 3DSTATE_SAMPLE_MASK */
2625 cmd_batch_pointer(cmd, 2, &dw);
2626 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2627 dw[1] = (1 << meta->samples) - 1;
2628
2629 /* 3DSTATE_DRAWING_RECTANGLE */
2630 cmd_batch_pointer(cmd, 4, &dw);
2631 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2632 dw[1] = meta->dst.y << 16 | meta->dst.x;
2633 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2634 (meta->dst.x + meta->width - 1);
2635 dw[3] = 0;
2636}
2637
2638static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2639{
2640 const struct intel_cmd_meta *meta = cmd->bind.meta;
2641 XGL_UINT offset_x, offset_y;
2642 /* one GPR */
2643 XGL_UINT consts[8];
2644 XGL_UINT const_count;
2645
2646 CMD_ASSERT(cmd, 6, 7.5);
2647
2648 /* underflow is fine here */
2649 offset_x = meta->src.x - meta->dst.x;
2650 offset_y = meta->src.y - meta->dst.y;
2651
2652 switch (meta->shader_id) {
2653 case INTEL_DEV_META_FS_COPY_MEM:
2654 case INTEL_DEV_META_FS_COPY_1D:
2655 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2656 case INTEL_DEV_META_FS_COPY_2D:
2657 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2658 case INTEL_DEV_META_FS_COPY_2D_MS:
2659 consts[0] = offset_x;
2660 consts[1] = offset_y;
2661 consts[2] = meta->src.layer;
2662 consts[3] = meta->src.lod;
2663 const_count = 4;
2664 break;
2665 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2666 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2667 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2668 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2669 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2670 consts[0] = offset_x;
2671 consts[1] = offset_y;
2672 consts[2] = meta->src.layer;
2673 consts[3] = meta->src.lod;
2674 consts[4] = meta->src.x;
2675 consts[5] = meta->width;
2676 const_count = 6;
2677 break;
2678 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2679 consts[0] = offset_x;
2680 consts[1] = offset_y;
2681 consts[2] = meta->width;
2682 const_count = 3;
2683 break;
2684 case INTEL_DEV_META_FS_CLEAR_COLOR:
2685 consts[0] = meta->clear_val[0];
2686 consts[1] = meta->clear_val[1];
2687 consts[2] = meta->clear_val[2];
2688 consts[3] = meta->clear_val[3];
2689 const_count = 4;
2690 break;
2691 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2692 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002693 consts[1] = meta->clear_val[1];
2694 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002695 break;
2696 case INTEL_DEV_META_FS_RESOLVE_2X:
2697 case INTEL_DEV_META_FS_RESOLVE_4X:
2698 case INTEL_DEV_META_FS_RESOLVE_8X:
2699 case INTEL_DEV_META_FS_RESOLVE_16X:
2700 consts[0] = offset_x;
2701 consts[1] = offset_y;
2702 const_count = 2;
2703 break;
2704 default:
2705 assert(!"unknown meta shader id");
2706 const_count = 0;
2707 break;
2708 }
2709
2710 /* this can be skipped but it makes state dumping prettier */
2711 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2712
2713 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2714}
2715
2716static void gen6_meta_ps(struct intel_cmd *cmd)
2717{
2718 const struct intel_cmd_meta *meta = cmd->bind.meta;
2719 const struct intel_pipeline_shader *sh =
2720 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2721 uint32_t offset, *dw;
2722
2723 CMD_ASSERT(cmd, 6, 6);
2724
Chia-I Wu29e6f502014-11-24 14:27:29 +08002725 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2726 /* 3DSTATE_CONSTANT_PS */
2727 cmd_batch_pointer(cmd, 5, &dw);
2728 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2729 dw[1] = 0;
2730 dw[2] = 0;
2731 dw[3] = 0;
2732 dw[4] = 0;
2733
2734 /* 3DSTATE_WM */
2735 cmd_batch_pointer(cmd, 9, &dw);
2736 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2737 dw[1] = 0;
2738 dw[2] = 0;
2739 dw[3] = 0;
2740 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002741 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002742 dw[6] = 0;
2743 dw[7] = 0;
2744 dw[8] = 0;
2745
Chia-I Wu3adf7212014-10-24 15:34:07 +08002746 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002747 }
2748
Chia-I Wu3adf7212014-10-24 15:34:07 +08002749 /* a normal color write */
2750 assert(meta->dst.valid && !sh->uses);
2751
Chia-I Wu6032b892014-10-17 14:47:18 +08002752 /* 3DSTATE_CONSTANT_PS */
2753 offset = gen6_meta_ps_constants(cmd);
2754 cmd_batch_pointer(cmd, 5, &dw);
2755 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2756 GEN6_PCB_ANY_DW0_PCB0_VALID;
2757 dw[1] = offset;
2758 dw[2] = 0;
2759 dw[3] = 0;
2760 dw[4] = 0;
2761
2762 /* 3DSTATE_WM */
2763 offset = emit_shader(cmd, sh);
2764 cmd_batch_pointer(cmd, 9, &dw);
2765 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2766 dw[1] = offset;
2767 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2768 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002769 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002770 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002771 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002772 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002773 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2774
Chia-I Wu6032b892014-10-17 14:47:18 +08002775 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2776 GEN6_WM_DW6_POSOFFSET_NONE |
2777 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2778 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2779 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2780 if (meta->samples > 1) {
2781 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2782 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2783 } else {
2784 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2785 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2786 }
2787 dw[7] = 0;
2788 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002789
2790 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002791}
2792
2793static void gen7_meta_ps(struct intel_cmd *cmd)
2794{
2795 const struct intel_cmd_meta *meta = cmd->bind.meta;
2796 const struct intel_pipeline_shader *sh =
2797 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2798 uint32_t offset, *dw;
2799
2800 CMD_ASSERT(cmd, 7, 7.5);
2801
Chia-I Wu29e6f502014-11-24 14:27:29 +08002802 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2803 /* 3DSTATE_WM */
2804 cmd_batch_pointer(cmd, 3, &dw);
2805 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2806 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2807
2808 /* 3DSTATE_CONSTANT_GS */
2809 cmd_batch_pointer(cmd, 7, &dw);
2810 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2811 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2812
2813 /* 3DSTATE_PS */
2814 cmd_batch_pointer(cmd, 8, &dw);
2815 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2816 dw[1] = 0;
2817 dw[2] = 0;
2818 dw[3] = 0;
2819 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002820 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002821 dw[5] = 0;
2822 dw[6] = 0;
2823 dw[7] = 0;
2824
Chia-I Wu3adf7212014-10-24 15:34:07 +08002825 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002826 }
2827
Chia-I Wu3adf7212014-10-24 15:34:07 +08002828 /* a normal color write */
2829 assert(meta->dst.valid && !sh->uses);
2830
Chia-I Wu6032b892014-10-17 14:47:18 +08002831 /* 3DSTATE_WM */
2832 cmd_batch_pointer(cmd, 3, &dw);
2833 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2834 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2835 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2836 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2837 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2838 dw[2] = 0;
2839
2840 /* 3DSTATE_CONSTANT_PS */
2841 offset = gen6_meta_ps_constants(cmd);
2842 cmd_batch_pointer(cmd, 7, &dw);
2843 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2844 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2845 dw[2] = 0;
2846 dw[3] = offset;
2847 dw[4] = 0;
2848 dw[5] = 0;
2849 dw[6] = 0;
2850
2851 /* 3DSTATE_PS */
2852 offset = emit_shader(cmd, sh);
2853 cmd_batch_pointer(cmd, 8, &dw);
2854 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2855 dw[1] = offset;
2856 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2857 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002858 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002859
2860 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2861 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002862 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2863
2864 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002865 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002866 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002867 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002868 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002869 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002870
2871 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2872 dw[6] = 0;
2873 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002874
2875 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002876}
2877
2878static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2879{
2880 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002881 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002882
2883 CMD_ASSERT(cmd, 6, 7.5);
2884
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002885 if (!ds) {
2886 /* all zeros */
2887 static const struct intel_ds_view null_ds;
2888 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002889 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002890
2891 cmd_wa_gen6_pre_ds_flush(cmd);
2892 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2893 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2894 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2895
2896 if (cmd_gen(cmd) >= INTEL_GEN(7))
2897 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2898 else
2899 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002900}
2901
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002902static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2903 const struct intel_pipeline *pipeline)
2904{
2905 cmd->bind.pipeline.graphics = pipeline;
2906}
2907
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002908static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2909 const struct intel_pipeline *pipeline)
2910{
2911 cmd->bind.pipeline.compute = pipeline;
2912}
2913
2914static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2915 const struct intel_pipeline_delta *delta)
2916{
2917 cmd->bind.pipeline.graphics_delta = delta;
2918}
2919
2920static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2921 const struct intel_pipeline_delta *delta)
2922{
2923 cmd->bind.pipeline.compute_delta = delta;
2924}
2925
2926static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2927 const struct intel_dset *dset,
2928 XGL_UINT slot_offset)
2929{
2930 cmd->bind.dset.graphics = dset;
2931 cmd->bind.dset.graphics_offset = slot_offset;
2932}
2933
2934static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2935 const struct intel_dset *dset,
2936 XGL_UINT slot_offset)
2937{
2938 cmd->bind.dset.compute = dset;
2939 cmd->bind.dset.compute_offset = slot_offset;
2940}
2941
2942static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002943 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002944{
Chia-I Wu714df452015-01-01 07:55:04 +08002945 cmd->bind.dyn_view.graphics = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002946}
2947
2948static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002949 const XGL_BUFFER_VIEW_ATTACH_INFO *info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950{
Chia-I Wu714df452015-01-01 07:55:04 +08002951 cmd->bind.dyn_view.compute = intel_buf_view(info->view);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952}
2953
Chia-I Wu3b04af52014-11-08 10:48:20 +08002954static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002955 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002956 XGL_GPU_SIZE offset, XGL_UINT binding)
2957{
Chia-I Wu714df452015-01-01 07:55:04 +08002958 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002959 cmd->result = XGL_ERROR_UNKNOWN;
2960 return;
2961 }
2962
Chia-I Wu714df452015-01-01 07:55:04 +08002963 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002964 cmd->bind.vertex.offset[binding] = offset;
2965}
2966
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002968 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2970{
Chia-I Wu714df452015-01-01 07:55:04 +08002971 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002972 cmd->bind.index.offset = offset;
2973 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002974}
2975
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002976static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2977 const struct intel_viewport_state *state)
2978{
2979 cmd->bind.state.viewport = state;
2980}
2981
2982static void cmd_bind_raster_state(struct intel_cmd *cmd,
2983 const struct intel_raster_state *state)
2984{
2985 cmd->bind.state.raster = state;
2986}
2987
2988static void cmd_bind_ds_state(struct intel_cmd *cmd,
2989 const struct intel_ds_state *state)
2990{
2991 cmd->bind.state.ds = state;
2992}
2993
2994static void cmd_bind_blend_state(struct intel_cmd *cmd,
2995 const struct intel_blend_state *state)
2996{
2997 cmd->bind.state.blend = state;
2998}
2999
3000static void cmd_bind_msaa_state(struct intel_cmd *cmd,
3001 const struct intel_msaa_state *state)
3002{
3003 cmd->bind.state.msaa = state;
3004}
3005
3006static void cmd_draw(struct intel_cmd *cmd,
3007 XGL_UINT vertex_start,
3008 XGL_UINT vertex_count,
3009 XGL_UINT instance_start,
3010 XGL_UINT instance_count,
3011 bool indexed,
3012 XGL_UINT vertex_base)
3013{
3014 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3015
3016 emit_bounded_states(cmd);
3017
3018 if (indexed) {
3019 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3020 cmd->result = XGL_ERROR_UNKNOWN;
3021
3022 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3023 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3024 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003025 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003026 cmd->bind.index.offset, cmd->bind.index.type,
3027 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003028 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003029 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003030 cmd->bind.index.offset, cmd->bind.index.type,
3031 p->primitive_restart);
3032 }
3033 } else {
3034 assert(!vertex_base);
3035 }
3036
3037 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3038 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3039 vertex_start, instance_count, instance_start, vertex_base);
3040 } else {
3041 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3042 vertex_start, instance_count, instance_start, vertex_base);
3043 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003044
Chia-I Wu707a29e2014-08-27 12:51:47 +08003045 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003046 /* need to re-emit all workarounds */
3047 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003048
3049 if (intel_debug & INTEL_DEBUG_NOCACHE)
3050 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003051}
3052
Chia-I Wuc14d1562014-10-17 09:49:22 +08003053void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3054{
Chia-I Wu6032b892014-10-17 14:47:18 +08003055 cmd->bind.meta = meta;
3056
3057 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003058 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003059
3060 gen6_meta_dynamic_states(cmd);
3061 gen6_meta_surface_states(cmd);
3062
3063 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3064 gen7_meta_urb(cmd);
3065 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003066 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003067 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003068 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003069 gen6_meta_wm(cmd);
3070 gen7_meta_ps(cmd);
3071 gen6_meta_depth_buffer(cmd);
3072
3073 cmd_wa_gen7_post_command_cs_stall(cmd);
3074 cmd_wa_gen7_post_command_depth_stall(cmd);
3075
Chia-I Wu29e6f502014-11-24 14:27:29 +08003076 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3077 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003078 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003079 } else {
3080 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3081 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003082 } else {
3083 gen6_meta_urb(cmd);
3084 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003085 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003086 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003087 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003088 gen6_meta_wm(cmd);
3089 gen6_meta_ps(cmd);
3090 gen6_meta_depth_buffer(cmd);
3091
Chia-I Wu29e6f502014-11-24 14:27:29 +08003092 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3093 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003094 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003095 } else {
3096 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3097 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003098 }
3099
3100 cmd->bind.draw_count++;
3101 /* need to re-emit all workarounds */
3102 cmd->bind.wa_flags = 0;
3103
3104 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003105
3106 if (intel_debug & INTEL_DEBUG_NOCACHE)
3107 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003108}
3109
Chia-I Wu96177272015-01-03 15:27:41 +08003110ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003111 XGL_CMD_BUFFER cmdBuffer,
3112 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3113 XGL_PIPELINE pipeline)
3114{
3115 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3116
3117 switch (pipelineBindPoint) {
3118 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003119 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003120 break;
3121 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003122 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003123 break;
3124 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003125 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003126 break;
3127 }
3128}
3129
Chia-I Wu96177272015-01-03 15:27:41 +08003130ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003131 XGL_CMD_BUFFER cmdBuffer,
3132 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3133 XGL_PIPELINE_DELTA delta)
3134{
3135 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3136
3137 switch (pipelineBindPoint) {
3138 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003139 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003140 break;
3141 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003142 cmd_bind_graphics_delta(cmd, delta);
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 Wu96177272015-01-03 15:27:41 +08003150ICD_EXPORT XGL_VOID XGLAPI xglCmdBindStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003151 XGL_CMD_BUFFER cmdBuffer,
3152 XGL_STATE_BIND_POINT stateBindPoint,
3153 XGL_STATE_OBJECT state)
3154{
3155 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3156
3157 switch (stateBindPoint) {
3158 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003159 cmd_bind_viewport_state(cmd,
3160 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003161 break;
3162 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003163 cmd_bind_raster_state(cmd,
3164 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003165 break;
3166 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003167 cmd_bind_ds_state(cmd,
3168 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003169 break;
3170 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003171 cmd_bind_blend_state(cmd,
3172 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003173 break;
3174 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003175 cmd_bind_msaa_state(cmd,
3176 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003177 break;
3178 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003179 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003180 break;
3181 }
3182}
3183
Chia-I Wu96177272015-01-03 15:27:41 +08003184ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003185 XGL_CMD_BUFFER cmdBuffer,
3186 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3187 XGL_UINT index,
3188 XGL_DESCRIPTOR_SET descriptorSet,
3189 XGL_UINT slotOffset)
3190{
3191 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3192 struct intel_dset *dset = intel_dset(descriptorSet);
3193
3194 assert(!index);
3195
3196 switch (pipelineBindPoint) {
3197 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003198 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003199 break;
3200 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003201 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003202 break;
3203 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003204 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003205 break;
3206 }
3207}
3208
Chia-I Wu714df452015-01-01 07:55:04 +08003209ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicBufferView(
Chia-I Wub2755562014-08-20 13:38:52 +08003210 XGL_CMD_BUFFER cmdBuffer,
3211 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wu714df452015-01-01 07:55:04 +08003212 const XGL_BUFFER_VIEW_ATTACH_INFO* pBufferView)
Chia-I Wub2755562014-08-20 13:38:52 +08003213{
3214 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3215
3216 switch (pipelineBindPoint) {
3217 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu714df452015-01-01 07:55:04 +08003218 cmd_bind_compute_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003219 break;
3220 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu714df452015-01-01 07:55:04 +08003221 cmd_bind_graphics_dyn_view(cmd, pBufferView);
Chia-I Wub2755562014-08-20 13:38:52 +08003222 break;
3223 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003224 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003225 break;
3226 }
3227}
3228
Chia-I Wu714df452015-01-01 07:55:04 +08003229ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003230 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003231 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003232 XGL_GPU_SIZE offset,
3233 XGL_UINT binding)
3234{
3235 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003236 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003237
Chia-I Wu714df452015-01-01 07:55:04 +08003238 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003239}
3240
Chia-I Wu714df452015-01-01 07:55:04 +08003241ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003242 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003243 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003244 XGL_GPU_SIZE offset,
3245 XGL_INDEX_TYPE indexType)
3246{
3247 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003248 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003249
Chia-I Wu714df452015-01-01 07:55:04 +08003250 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003251}
3252
Chia-I Wu96177272015-01-03 15:27:41 +08003253ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003254 XGL_CMD_BUFFER cmdBuffer,
3255 XGL_UINT firstVertex,
3256 XGL_UINT vertexCount,
3257 XGL_UINT firstInstance,
3258 XGL_UINT instanceCount)
3259{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003260 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003261
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003262 cmd_draw(cmd, firstVertex, vertexCount,
3263 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003264}
3265
Chia-I Wu96177272015-01-03 15:27:41 +08003266ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003267 XGL_CMD_BUFFER cmdBuffer,
3268 XGL_UINT firstIndex,
3269 XGL_UINT indexCount,
3270 XGL_INT vertexOffset,
3271 XGL_UINT firstInstance,
3272 XGL_UINT instanceCount)
3273{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003274 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003275
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003276 cmd_draw(cmd, firstIndex, indexCount,
3277 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003278}
3279
Chia-I Wu96177272015-01-03 15:27:41 +08003280ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003281 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003282 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003283 XGL_GPU_SIZE offset,
3284 XGL_UINT32 count,
3285 XGL_UINT32 stride)
3286{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003287 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3288
3289 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003290}
3291
Chia-I Wu96177272015-01-03 15:27:41 +08003292ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003293 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003294 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003295 XGL_GPU_SIZE offset,
3296 XGL_UINT32 count,
3297 XGL_UINT32 stride)
3298{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003299 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3300
3301 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003302}
3303
Chia-I Wu96177272015-01-03 15:27:41 +08003304ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003305 XGL_CMD_BUFFER cmdBuffer,
3306 XGL_UINT x,
3307 XGL_UINT y,
3308 XGL_UINT z)
3309{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003310 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3311
3312 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003313}
3314
Chia-I Wu96177272015-01-03 15:27:41 +08003315ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003316 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003317 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003318 XGL_GPU_SIZE offset)
3319{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003320 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3321
3322 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003323}