blob: c16aff35c39e4d1f6506077d647727f43859dcff [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 Wu7fae4e32014-08-21 11:39:44 +080031#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080032#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080033#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080034#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080035#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080036#include "state.h"
37#include "view.h"
38#include "cmd_priv.h"
39
Chia-I Wu59c097e2014-08-21 10:51:07 +080040static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080041 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080042 uint32_t vertex_count,
43 uint32_t vertex_start,
44 uint32_t instance_count,
45 uint32_t instance_start,
46 uint32_t vertex_base)
47{
48 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080049 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080050
51 CMD_ASSERT(cmd, 6, 6);
52
Chia-I Wu426072d2014-08-26 14:31:55 +080053 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080054 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080055 (cmd_len - 2);
56
57 if (indexed)
58 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
59
Chia-I Wu72292b72014-09-09 10:48:33 +080060 cmd_batch_pointer(cmd, cmd_len, &dw);
61 dw[0] = dw0;
62 dw[1] = vertex_count;
63 dw[2] = vertex_start;
64 dw[3] = instance_count;
65 dw[4] = instance_start;
66 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080067}
68
69static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080070 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080071 uint32_t vertex_count,
72 uint32_t vertex_start,
73 uint32_t instance_count,
74 uint32_t instance_start,
75 uint32_t vertex_base)
76{
77 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080078 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080079
80 CMD_ASSERT(cmd, 7, 7.5);
81
Chia-I Wu426072d2014-08-26 14:31:55 +080082 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080083 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080084
85 if (indexed)
86 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
87
Chia-I Wu72292b72014-09-09 10:48:33 +080088 cmd_batch_pointer(cmd, cmd_len, &dw);
89 dw[0] = dw0;
90 dw[1] = dw1;
91 dw[2] = vertex_count;
92 dw[3] = vertex_start;
93 dw[4] = instance_count;
94 dw[5] = instance_start;
95 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080096}
97
Chia-I Wu270b1e82014-08-25 15:53:39 +080098static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +080099 struct intel_bo *bo, uint32_t bo_offset,
100 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101{
102 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800103 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800104 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800105 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800106 uint32_t *dw;
107 XGL_UINT pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800108
109 CMD_ASSERT(cmd, 6, 7.5);
110
111 assert(bo_offset % 8 == 0);
112
113 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
114 /*
115 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
116 *
117 * "1 of the following must also be set (when CS stall is set):
118 *
119 * * Depth Cache Flush Enable ([0] of DW1)
120 * * Stall at Pixel Scoreboard ([1] of DW1)
121 * * Depth Stall ([13] of DW1)
122 * * Post-Sync Operation ([13] of DW1)
123 * * Render Target Cache Flush Enable ([12] of DW1)
124 * * Notify Enable ([8] of DW1)"
125 *
126 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
127 *
128 * "One of the following must also be set (when CS stall is set):
129 *
130 * * Render Target Cache Flush Enable ([12] of DW1)
131 * * Depth Cache Flush Enable ([0] of DW1)
132 * * Stall at Pixel Scoreboard ([1] of DW1)
133 * * Depth Stall ([13] of DW1)
134 * * Post-Sync Operation ([13] of DW1)"
135 */
136 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
137 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
138 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
139 GEN6_PIPE_CONTROL_DEPTH_STALL;
140
141 /* post-sync op */
142 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
143 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
144 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
145
146 if (cmd_gen(cmd) == INTEL_GEN(6))
147 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
148
149 assert(dw1 & bit_test);
150 }
151
152 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
153 /*
154 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
155 *
156 * "Following bits must be clear (when Depth Stall is set):
157 *
158 * * Render Target Cache Flush Enable ([12] of DW1)
159 * * Depth Cache Flush Enable ([0] of DW1)"
160 */
161 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
162 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
163 }
164
165 /*
166 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
167 *
168 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
169 * and PIPE_CONTROL are not supported."
170 *
171 * The kernel will add the mapping automatically (when write domain is
172 * INTEL_DOMAIN_INSTRUCTION).
173 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800174 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800175 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 reloc_flags |= INTEL_RELOC_GGTT;
177 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178
Chia-I Wu72292b72014-09-09 10:48:33 +0800179 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
180 dw[0] = dw0;
181 dw[1] = dw1;
182 dw[2] = 0;
183 dw[3] = (uint32_t) imm;
184 dw[4] = (uint32_t) (imm >> 32);
185
186 if (bo) {
187 cmd_reserve_reloc(cmd, 1);
188 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
189 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800190}
191
Chia-I Wu254db422014-08-21 11:54:29 +0800192static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
193{
194 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
195 bool supported;
196
197 CMD_ASSERT(cmd, 6, 7.5);
198
199 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
200 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
201
202 switch (p->prim_type) {
203 case GEN6_3DPRIM_POINTLIST:
204 case GEN6_3DPRIM_LINELIST:
205 case GEN6_3DPRIM_LINESTRIP:
206 case GEN6_3DPRIM_TRILIST:
207 case GEN6_3DPRIM_TRISTRIP:
208 supported = true;
209 break;
210 default:
211 supported = false;
212 break;
213 }
214
215 if (!supported)
216 return false;
217
218 switch (cmd->bind.index.type) {
219 case XGL_INDEX_8:
220 supported = (p->primitive_restart_index != 0xffu);
221 break;
222 case XGL_INDEX_16:
223 supported = (p->primitive_restart_index != 0xffffu);
224 break;
225 case XGL_INDEX_32:
226 supported = (p->primitive_restart_index != 0xffffffffu);
227 break;
228 default:
229 supported = false;
230 break;
231 }
232
233 return supported;
234}
235
Chia-I Wu59c097e2014-08-21 10:51:07 +0800236static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu958d1b72014-08-21 11:28:11 +0800237 const struct intel_mem *mem,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238 XGL_GPU_SIZE offset,
239 XGL_INDEX_TYPE type,
240 bool enable_cut_index)
241{
242 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800243 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800244 unsigned offset_align;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246
247 CMD_ASSERT(cmd, 6, 7.5);
248
Chia-I Wu426072d2014-08-26 14:31:55 +0800249 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800250
251 /* the bit is moved to 3DSTATE_VF */
252 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
253 assert(!enable_cut_index);
254 if (enable_cut_index)
255 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
256
257 switch (type) {
258 case XGL_INDEX_8:
259 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
260 offset_align = 1;
261 break;
262 case XGL_INDEX_16:
263 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
264 offset_align = 2;
265 break;
266 case XGL_INDEX_32:
267 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
268 offset_align = 4;
269 break;
270 default:
271 cmd->result = XGL_ERROR_INVALID_VALUE;
272 return;
273 break;
274 }
275
276 if (offset % offset_align) {
277 cmd->result = XGL_ERROR_INVALID_VALUE;
278 return;
279 }
280
281 /* aligned and inclusive */
282 end_offset = mem->size - (mem->size % offset_align) - 1;
283
Chia-I Wu72292b72014-09-09 10:48:33 +0800284 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
285 dw[0] = dw0;
286
287 cmd_reserve_reloc(cmd, 2);
288 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
289 cmd_batch_reloc(cmd, pos + 2, mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800290}
291
Chia-I Wu62a7f252014-08-29 11:31:16 +0800292static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
293 bool enable_cut_index,
294 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800295{
296 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800297 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800298
299 CMD_ASSERT(cmd, 7.5, 7.5);
300
Chia-I Wu426072d2014-08-26 14:31:55 +0800301 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800302 if (enable_cut_index)
303 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
304
Chia-I Wu72292b72014-09-09 10:48:33 +0800305 cmd_batch_pointer(cmd, cmd_len, &dw);
306 dw[0] = dw0;
307 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800308}
309
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600310
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800311static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
312{
313 const uint8_t cmd_len = 7;
314 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800315 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800316
317 CMD_ASSERT(cmd, 6, 6);
318
Chia-I Wu72292b72014-09-09 10:48:33 +0800319 cmd_batch_pointer(cmd, cmd_len, &dw);
320 dw[0] = dw0;
321 dw[1] = 0;
322 dw[2] = 0;
323 dw[3] = 0;
324 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
325 dw[5] = GEN6_GS_DW5_STATISTICS;
326 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800327}
328
Chia-I Wu62a7f252014-08-29 11:31:16 +0800329static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
330{
331 const uint8_t cmd_len = 7;
332 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800333 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800334
335 CMD_ASSERT(cmd, 7, 7.5);
336
Chia-I Wu72292b72014-09-09 10:48:33 +0800337 cmd_batch_pointer(cmd, cmd_len, &dw);
338 dw[0] = dw0;
339 dw[1] = 0;
340 dw[2] = 0;
341 dw[3] = 0;
342 dw[4] = 0;
343 dw[5] = GEN6_GS_DW5_STATISTICS;
344 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800345}
346
Chia-I Wud88e02d2014-08-25 10:56:13 +0800347static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
348 XGL_UINT width, XGL_UINT height)
349{
350 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800351 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800352 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800353 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354
355 CMD_ASSERT(cmd, 6, 7.5);
356
Chia-I Wu72292b72014-09-09 10:48:33 +0800357 cmd_batch_pointer(cmd, cmd_len, &dw);
358 dw[0] = dw0;
359
Chia-I Wud88e02d2014-08-25 10:56:13 +0800360 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800361 dw[1] = 0;
362 dw[2] = (height - 1) << 16 |
363 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800364 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800365 dw[1] = 1;
366 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800367 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800368
369 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800370}
371
Chia-I Wu8016a172014-08-29 18:31:32 +0800372static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
373 uint32_t body[6])
374{
375 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
376 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
377 const struct intel_raster_state *raster = cmd->bind.state.raster;
378 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
389 raster->cmd_sf_fill;
390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
403 assert(!"unknown depth format");
404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
411 dw2 = raster->cmd_sf_cull;
412
413 if (msaa->sample_count > 1) {
414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
421 if (viewport->scissor_enable)
422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
425 point_width = (int) (pipeline->pointSize * 8.0f + 0.5f);
426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
438 body[3] = raster->cmd_depth_offset_const;
439 body[4] = raster->cmd_depth_offset_scale;
440 body[5] = raster->cmd_depth_offset_clamp;
441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
GregF8cd81832014-11-18 18:01:01 -0700446 XGL_UINT sbe_offset;
447 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800501 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
502 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800503 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800504
505 CMD_ASSERT(cmd, 6, 7.5);
506
507 dw1 = GEN6_CLIP_DW1_STATISTICS;
508 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
509 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
510 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
511 raster->cmd_clip_cull;
512 }
513
514 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
515 GEN6_CLIP_DW2_XY_TEST_ENABLE |
516 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700517 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800518 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
520 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
521
522 if (pipeline->rasterizerDiscardEnable)
523 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
524 else
525 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
526
527 if (pipeline->depthClipEnable)
528 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
529
530 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
531 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
532 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
533 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
534
535 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
536 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
537 (viewport->viewport_count - 1);
538
Chia-I Wu72292b72014-09-09 10:48:33 +0800539 cmd_batch_pointer(cmd, cmd_len, &dw);
540 dw[0] = dw0;
541 dw[1] = dw1;
542 dw[2] = dw2;
543 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544}
545
Chia-I Wu05990612014-11-25 11:36:35 +0800546static int cmd_vs_max_threads(const struct intel_cmd *cmd)
547{
548 switch (cmd_gen(cmd)) {
549 case INTEL_GEN(7.5):
550 return (cmd->dev->gpu->gt >= 2) ? 280 : 70;
551 case INTEL_GEN(7):
552 return (cmd->dev->gpu->gt == 2) ? 128 : 36;
553 case INTEL_GEN(6):
554 return (cmd->dev->gpu->gt == 2) ? 60 : 24;
555 default:
556 return 1;
557 }
558}
559
560static int cmd_ps_max_threads(const struct intel_cmd *cmd)
561{
562 switch (cmd_gen(cmd)) {
563 case INTEL_GEN(7.5):
564 return (cmd->dev->gpu->gt == 3) ? 408 :
565 (cmd->dev->gpu->gt == 2) ? 204 : 102;
566 case INTEL_GEN(7):
567 return (cmd->dev->gpu->gt == 2) ? 172 : 48;
568 case INTEL_GEN(6):
569 return (cmd->dev->gpu->gt == 2) ? 80 : 40;
570 default:
571 return 4;
572 }
573}
574
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800575static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
576{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800577 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800578 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800579 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
580 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800581 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800582
583 CMD_ASSERT(cmd, 6, 6);
584
585 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
586
587 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
588 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
589
590 dw4 = GEN6_WM_DW4_STATISTICS |
591 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
592 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
593 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
594
Chia-I Wu05990612014-11-25 11:36:35 +0800595 dw5 = (cmd_ps_max_threads(cmd) - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800596 GEN6_WM_DW5_PS_ENABLE |
597 GEN6_WM_DW5_8_PIXEL_DISPATCH;
598
599 if (fs->uses & INTEL_SHADER_USE_KILL ||
600 pipeline->cb_state.alphaToCoverageEnable)
601 dw5 |= GEN6_WM_DW5_PS_KILL;
602
603 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
604 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
605 if (fs->uses & INTEL_SHADER_USE_DEPTH)
606 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
607 if (fs->uses & INTEL_SHADER_USE_W)
608 dw5 |= GEN6_WM_DW5_PS_USE_W;
609
610 if (pipeline->cb_state.dualSourceBlendEnable)
611 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
612
613 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
614 GEN6_WM_DW6_POSOFFSET_NONE |
615 GEN6_WM_DW6_ZW_INTERP_PIXEL |
616 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
617 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
618
619 if (msaa->sample_count > 1) {
620 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
621 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
622 } else {
623 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
624 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
625 }
626
Chia-I Wu72292b72014-09-09 10:48:33 +0800627 cmd_batch_pointer(cmd, cmd_len, &dw);
628 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800629 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800630 dw[2] = dw2;
631 dw[3] = 0; /* scratch */
632 dw[4] = dw4;
633 dw[5] = dw5;
634 dw[6] = dw6;
635 dw[7] = 0; /* kernel 1 */
636 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800637}
638
639static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
640{
641 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800642 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
644 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800645 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800646
647 CMD_ASSERT(cmd, 7, 7.5);
648
649 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
650
651 dw1 = GEN7_WM_DW1_STATISTICS |
652 GEN7_WM_DW1_PS_ENABLE |
653 GEN7_WM_DW1_ZW_INTERP_PIXEL |
654 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
655 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
656
657 if (fs->uses & INTEL_SHADER_USE_KILL ||
658 pipeline->cb_state.alphaToCoverageEnable)
659 dw1 |= GEN7_WM_DW1_PS_KILL;
660
661 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
662 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
663 if (fs->uses & INTEL_SHADER_USE_DEPTH)
664 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
665 if (fs->uses & INTEL_SHADER_USE_W)
666 dw1 |= GEN7_WM_DW1_PS_USE_W;
667
668 dw2 = 0;
669
670 if (msaa->sample_count > 1) {
671 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
672 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
673 } else {
674 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
675 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
676 }
677
Chia-I Wu72292b72014-09-09 10:48:33 +0800678 cmd_batch_pointer(cmd, cmd_len, &dw);
679 dw[0] = dw0;
680 dw[1] = dw1;
681 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800682}
683
684static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
685{
686 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800687 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
Chia-I Wu05990612014-11-25 11:36:35 +0800689 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800691 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800692
693 CMD_ASSERT(cmd, 7, 7.5);
694
695 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
696
697 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
698 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
699
700 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
701 GEN7_PS_DW4_8_PIXEL_DISPATCH;
702
703 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
705 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
706 } else {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800707 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
708 }
709
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800710 if (fs->in_count)
711 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
712
713 if (pipeline->cb_state.dualSourceBlendEnable)
714 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
715
716 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
717 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
718 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
719
Chia-I Wu72292b72014-09-09 10:48:33 +0800720 cmd_batch_pointer(cmd, cmd_len, &dw);
721 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800722 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800723 dw[2] = dw2;
724 dw[3] = 0; /* scratch */
725 dw[4] = dw4;
726 dw[5] = dw5;
727 dw[6] = 0; /* kernel 1 */
728 dw[7] = 0; /* kernel 2 */
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);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001389 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001390 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1391 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001392 } else {
1393 stencil_ref = 0;
1394 }
1395
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001398 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001399}
1400
Chia-I Wu1744cca2014-08-22 11:10:17 +08001401static void gen7_viewport_states(struct intel_cmd *cmd)
1402{
1403 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001404 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001405
1406 if (!viewport)
1407 return;
1408
Chia-I Wub1d450a2014-09-09 13:48:03 +08001409 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1410 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001411
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001413 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001415 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001416 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1417 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001418
1419 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001420 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001421 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001422 gen7_3dstate_pointer(cmd,
1423 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001424 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001425
Chia-I Wu1744cca2014-08-22 11:10:17 +08001426 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001427 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001428 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001429 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001430 gen7_3dstate_pointer(cmd,
1431 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001432 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001433 }
1434}
1435
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001437 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001438{
1439 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001440 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001441
Chia-I Wu72292b72014-09-09 10:48:33 +08001442 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001443
1444 dw[0] = GEN6_RENDER_TYPE_RENDER |
1445 GEN6_RENDER_SUBTYPE_3D |
1446 subop | (cmd_len - 2);
1447 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001448 dw[2] = 0;
1449 dw[3] = 0;
1450 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001451}
1452
1453static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001454 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001455{
1456 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001457 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001458
Chia-I Wu72292b72014-09-09 10:48:33 +08001459 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001460
1461 dw[0] = GEN6_RENDER_TYPE_RENDER |
1462 GEN6_RENDER_SUBTYPE_3D |
1463 subop | (cmd_len - 2);
1464 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001466 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001467 dw[4] = 0;
1468 dw[5] = 0;
1469 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001470}
1471
Chia-I Wu625105f2014-10-13 15:35:29 +08001472static uint32_t emit_samplers(struct intel_cmd *cmd,
1473 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001474{
1475 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1476 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001477 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001478 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001479 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001480 XGL_UINT i;
1481
1482 CMD_ASSERT(cmd, 6, 7.5);
1483
Chia-I Wu625105f2014-10-13 15:35:29 +08001484 if (!rmap || !rmap->sampler_count)
1485 return 0;
1486
1487 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1488
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001490 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001491 border_stride * rmap->sampler_count, &border_dw);
1492
1493 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001494 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495 4 * rmap->sampler_count, &sampler_dw);
1496
1497 for (i = 0; i < rmap->sampler_count; i++) {
1498 const struct intel_pipeline_rmap_slot *slot =
1499 &rmap->slots[surface_count + i];
1500 const struct intel_sampler *sampler;
1501
1502 switch (slot->path_len) {
1503 case 0:
1504 sampler = NULL;
1505 break;
1506 case INTEL_PIPELINE_RMAP_SLOT_RT:
1507 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1508 assert(!"unexpected rmap slot type");
1509 sampler = NULL;
1510 break;
1511 case 1:
1512 {
1513 const struct intel_dset *dset = cmd->bind.dset.graphics;
1514 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1515 const struct intel_dset_slot *dset_slot =
1516 &dset->slots[slot_offset + slot->u.index];
1517
1518 switch (dset_slot->type) {
1519 case INTEL_DSET_SLOT_SAMPLER:
1520 sampler = dset_slot->u.sampler;
1521 break;
1522 default:
1523 assert(!"unexpected dset slot type");
1524 sampler = NULL;
1525 break;
1526 }
1527 }
1528 break;
1529 default:
1530 assert(!"nested descriptor set unsupported");
1531 sampler = NULL;
1532 break;
1533 }
1534
1535 if (sampler) {
1536 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1537
1538 sampler_dw[0] = sampler->cmd[0];
1539 sampler_dw[1] = sampler->cmd[1];
1540 sampler_dw[2] = border_offset;
1541 sampler_dw[3] = sampler->cmd[2];
1542 } else {
1543 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1544 sampler_dw[1] = 0;
1545 sampler_dw[2] = 0;
1546 sampler_dw[3] = 0;
1547 }
1548
1549 border_offset += border_stride * 4;
1550 border_dw += border_stride;
1551 sampler_dw += 4;
1552 }
1553
Chia-I Wu625105f2014-10-13 15:35:29 +08001554 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001555}
1556
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001557static uint32_t emit_binding_table(struct intel_cmd *cmd,
1558 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001559{
Chia-I Wu72292b72014-09-09 10:48:33 +08001560 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001561 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001562
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001563 CMD_ASSERT(cmd, 6, 7.5);
1564
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001565 surface_count = (rmap) ?
1566 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1567 if (!surface_count)
1568 return 0;
1569
Chia-I Wu42a56202014-08-23 16:47:48 +08001570 assert(surface_count <= ARRAY_SIZE(binding_table));
1571
1572 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001573 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001574
1575 switch (slot->path_len) {
1576 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001577 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001578 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001579 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001580 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001581 const struct intel_rt_view *view =
1582 (slot->u.index < cmd->bind.att.rt_count) ?
1583 cmd->bind.att.rt[slot->u.index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001584
Chia-I Wu787a05b2014-12-05 11:02:20 +08001585 if (view) {
1586 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1587 GEN6_ALIGNMENT_SURFACE_STATE,
1588 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001589
Chia-I Wu787a05b2014-12-05 11:02:20 +08001590 cmd_reserve_reloc(cmd, 1);
1591 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1592 view->cmd[1], INTEL_RELOC_WRITE);
1593 } else {
1594 struct intel_null_view null_view;
1595 intel_null_view_init(&null_view, cmd->dev);
1596
1597 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1598 GEN6_ALIGNMENT_SURFACE_STATE,
1599 null_view.cmd_len, null_view.cmd);
1600 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001601 }
1602 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001603 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001604 {
1605 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001606 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001607
Chia-I Wu00b51a82014-09-09 12:07:37 +08001608 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001609 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001610 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001611
Chia-I Wu72292b72014-09-09 10:48:33 +08001612 cmd_reserve_reloc(cmd, 1);
1613 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1614 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001615 }
1616 break;
1617 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001618 {
1619 const struct intel_dset *dset = cmd->bind.dset.graphics;
1620 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1621 const struct intel_dset_slot *dset_slot =
1622 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001623 const uint32_t reloc_flags =
1624 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001625
1626 switch (dset_slot->type) {
1627 case INTEL_DSET_SLOT_IMG_VIEW:
1628 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001629 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001630 dset_slot->u.img_view->cmd_len,
1631 dset_slot->u.img_view->cmd);
1632
1633 cmd_reserve_reloc(cmd, 1);
1634 cmd_surface_reloc(cmd, offset, 1,
1635 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001636 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001637 break;
1638 case INTEL_DSET_SLOT_MEM_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.mem_view.cmd_len,
1642 dset_slot->u.mem_view.cmd);
1643
1644 cmd_reserve_reloc(cmd, 1);
1645 cmd_surface_reloc(cmd, offset, 1,
1646 dset_slot->u.mem_view.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001647 dset_slot->u.mem_view.cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001648 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001649 case INTEL_DSET_SLOT_SAMPLER:
1650 assert(0 == cmd->bind.dset.graphics_offset);
1651
1652 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001653 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001654 16, dset_slot->u.sampler->cmd);
1655 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001656 default:
1657 assert(!"unexpected dset slot type");
1658 break;
1659 }
1660 }
1661 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001662 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001663 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001664 break;
1665 }
1666
Chia-I Wu72292b72014-09-09 10:48:33 +08001667 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001668 }
1669
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001670 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001671 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001672 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001673}
1674
Chia-I Wu1d125092014-10-08 08:49:38 +08001675static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1676{
1677 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001678 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1679 uint32_t *dw;
1680 XGL_UINT pos, i;
1681
1682 CMD_ASSERT(cmd, 6, 7.5);
1683
1684 if (!pipeline->vb_count)
1685 return;
1686
1687 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1688
1689 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1690 dw++;
1691 pos++;
1692
1693 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001694 assert(pipeline->vb[i].strideInBytes <= 2048);
1695
1696 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1697 pipeline->vb[i].strideInBytes;
1698
1699 if (cmd_gen(cmd) >= INTEL_GEN(7))
1700 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1701
1702 switch (pipeline->vb[i].stepRate) {
1703 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1704 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1705 dw[3] = 0;
1706 break;
1707 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1708 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1709 dw[3] = 1;
1710 break;
1711 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1712 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1713 dw[3] = 0;
1714 break;
1715 default:
1716 assert(!"unknown step rate");
1717 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1718 dw[3] = 0;
1719 break;
1720 }
1721
Chia-I Wu3b04af52014-11-08 10:48:20 +08001722 if (cmd->bind.vertex.mem[i]) {
1723 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1724 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001725
1726 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001727 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1728 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001729 } else {
1730 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1731 dw[1] = 0;
1732 dw[2] = 0;
1733 }
1734
1735 dw += 4;
1736 pos += 4;
1737 }
1738}
1739
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001740static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1741{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001742 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1743 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu05990612014-11-25 11:36:35 +08001744 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001745 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001746 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001747 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu05990612014-11-25 11:36:35 +08001748 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001749
1750 CMD_ASSERT(cmd, 6, 7.5);
1751
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001752 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001753 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1754 *
1755 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1756 * 128-bit vertex elements to be passed into the payload for each
1757 * vertex."
1758 *
1759 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1760 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001761 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001762 vue_read_len = (vs->in_count + 1) / 2;
1763 if (!vue_read_len)
1764 vue_read_len = 1;
1765
1766 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1767 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1768
1769 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1770 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1771 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001772
1773 dw5 = GEN6_VS_DW5_STATISTICS |
1774 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001775
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001776 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1777 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1778 else
1779 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1780
Chia-I Wube0a3d92014-09-02 13:20:59 +08001781 if (pipeline->disable_vs_cache)
1782 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1783
Chia-I Wu72292b72014-09-09 10:48:33 +08001784 cmd_batch_pointer(cmd, cmd_len, &dw);
1785 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001786 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001787 dw[2] = dw2;
1788 dw[3] = 0; /* scratch */
1789 dw[4] = dw4;
1790 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001791}
1792
Chia-I Wu625105f2014-10-13 15:35:29 +08001793static void emit_shader_resources(struct intel_cmd *cmd)
1794{
1795 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001796 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001797
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001798 binding_tables[0] = emit_binding_table(cmd,
1799 cmd->bind.pipeline.graphics->vs.rmap);
1800 binding_tables[1] = emit_binding_table(cmd,
1801 cmd->bind.pipeline.graphics->tcs.rmap);
1802 binding_tables[2] = emit_binding_table(cmd,
1803 cmd->bind.pipeline.graphics->tes.rmap);
1804 binding_tables[3] = emit_binding_table(cmd,
1805 cmd->bind.pipeline.graphics->gs.rmap);
1806 binding_tables[4] = emit_binding_table(cmd,
1807 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001808
1809 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1810 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1811 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1812 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1813 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1814
1815 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1816 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001817 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1818 binding_tables[0]);
1819 gen7_3dstate_pointer(cmd,
1820 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1821 binding_tables[1]);
1822 gen7_3dstate_pointer(cmd,
1823 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1824 binding_tables[2]);
1825 gen7_3dstate_pointer(cmd,
1826 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1827 binding_tables[3]);
1828 gen7_3dstate_pointer(cmd,
1829 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1830 binding_tables[4]);
1831
1832 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001833 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1834 samplers[0]);
1835 gen7_3dstate_pointer(cmd,
1836 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1837 samplers[1]);
1838 gen7_3dstate_pointer(cmd,
1839 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1840 samplers[2]);
1841 gen7_3dstate_pointer(cmd,
1842 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1843 samplers[3]);
1844 gen7_3dstate_pointer(cmd,
1845 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1846 samplers[4]);
1847 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001848 assert(!binding_tables[1] && !binding_tables[2]);
1849 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1850 binding_tables[0], binding_tables[3], binding_tables[4]);
1851
Chia-I Wu625105f2014-10-13 15:35:29 +08001852 assert(!samplers[1] && !samplers[2]);
1853 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1854 samplers[0], samplers[3], samplers[4]);
1855 }
1856}
1857
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001858static void emit_rt(struct intel_cmd *cmd)
1859{
1860 cmd_wa_gen6_pre_depth_stall_write(cmd);
1861 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1862 cmd->bind.att.height);
1863}
1864
1865static void emit_ds(struct intel_cmd *cmd)
1866{
1867 const struct intel_ds_view *ds = cmd->bind.att.ds;
1868
1869 if (!ds) {
1870 /* all zeros */
1871 static const struct intel_ds_view null_ds;
1872 ds = &null_ds;
1873 }
1874
1875 cmd_wa_gen6_pre_ds_flush(cmd);
1876 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1877 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1878 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1879
1880 if (cmd_gen(cmd) >= INTEL_GEN(7))
1881 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1882 else
1883 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1884}
1885
Chia-I Wua57761b2014-10-14 14:27:44 +08001886static uint32_t emit_shader(struct intel_cmd *cmd,
1887 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001888{
Chia-I Wua57761b2014-10-14 14:27:44 +08001889 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1890 uint32_t offset;
1891 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001892
Chia-I Wua57761b2014-10-14 14:27:44 +08001893 /* see if the shader is already in the cache */
1894 for (i = 0; i < cache->used; i++) {
1895 if (cache->entries[i].shader == (const void *) shader)
1896 return cache->entries[i].kernel_offset;
1897 }
1898
1899 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1900
1901 /* grow the cache if full */
1902 if (cache->used >= cache->count) {
1903 const XGL_UINT count = cache->count + 16;
1904 void *entries;
1905
1906 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1907 XGL_SYSTEM_ALLOC_INTERNAL);
1908 if (entries) {
1909 if (cache->entries) {
1910 memcpy(entries, cache->entries,
1911 sizeof(cache->entries[0]) * cache->used);
1912 icd_free(cache->entries);
1913 }
1914
1915 cache->entries = entries;
1916 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917 }
1918 }
1919
Chia-I Wua57761b2014-10-14 14:27:44 +08001920 /* add the shader to the cache */
1921 if (cache->used < cache->count) {
1922 cache->entries[cache->used].shader = (const void *) shader;
1923 cache->entries[cache->used].kernel_offset = offset;
1924 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001925 }
1926
Chia-I Wua57761b2014-10-14 14:27:44 +08001927 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001928}
1929
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001930static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001931{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001932 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001933
Chia-I Wu8370b402014-08-29 12:28:37 +08001934 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1935 cmd_wa_gen6_pre_depth_stall_write(cmd);
1936 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1937 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1938 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1939 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001940
1941 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001942 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001943 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001944
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001945 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001946 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001947 }
1948 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001949 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001950 }
1951 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001952 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1953 }
1954 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1955 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1956 }
1957 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1958 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001959 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001960
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001961 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1962 gen7_3DSTATE_GS(cmd);
1963 } else {
1964 gen6_3DSTATE_GS(cmd);
1965 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001966
Chia-I Wu8370b402014-08-29 12:28:37 +08001967 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1968 cmd_wa_gen7_post_command_cs_stall(cmd);
1969 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1970 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001971}
1972
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001973static void emit_bounded_states(struct intel_cmd *cmd)
1974{
1975 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1976
1977 emit_graphics_pipeline(cmd);
1978
1979 emit_rt(cmd);
1980 emit_ds(cmd);
1981
1982 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1983 gen7_cc_states(cmd);
1984 gen7_viewport_states(cmd);
1985
1986 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1987 &cmd->bind.pipeline.graphics->vs);
1988 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1989 &cmd->bind.pipeline.graphics->fs);
1990
1991 gen6_3DSTATE_CLIP(cmd);
1992 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001993 gen7_3DSTATE_WM(cmd);
1994 gen7_3DSTATE_PS(cmd);
1995 } else {
1996 gen6_cc_states(cmd);
1997 gen6_viewport_states(cmd);
1998
1999 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2000 &cmd->bind.pipeline.graphics->vs);
2001 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2002 &cmd->bind.pipeline.graphics->fs);
2003
2004 gen6_3DSTATE_CLIP(cmd);
2005 gen6_3DSTATE_SF(cmd);
2006 gen6_3DSTATE_WM(cmd);
2007 }
2008
2009 emit_shader_resources(cmd);
2010
2011 cmd_wa_gen6_pre_depth_stall_write(cmd);
2012 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2013
2014 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2015 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2016
2017 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2018 gen6_3DSTATE_VS(cmd);
2019}
2020
Chia-I Wu6032b892014-10-17 14:47:18 +08002021static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2022{
2023 const struct intel_cmd_meta *meta = cmd->bind.meta;
2024 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2025
2026 CMD_ASSERT(cmd, 6, 7.5);
2027
2028 blend_offset = 0;
2029 ds_offset = 0;
2030 cc_offset = 0;
2031 cc_vp_offset = 0;
2032
Chia-I Wu29e6f502014-11-24 14:27:29 +08002033 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002034 /* BLEND_STATE */
2035 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002036 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002037 dw[0] = 0;
2038 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2039 }
2040
Chia-I Wu29e6f502014-11-24 14:27:29 +08002041 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2042 if (meta->ds.state) {
2043 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002044
Chia-I Wu29e6f502014-11-24 14:27:29 +08002045 /* DEPTH_STENCIL_STATE */
2046 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002047
Chia-I Wu29e6f502014-11-24 14:27:29 +08002048 /* COLOR_CALC_STATE */
2049 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2050 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002051
Chia-I Wu29e6f502014-11-24 14:27:29 +08002052 /* CC_VIEWPORT */
2053 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002054 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002055 dw[0] = u_fui(0.0f);
2056 dw[1] = u_fui(1.0f);
2057 } else {
2058 /* DEPTH_STENCIL_STATE */
2059 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002060 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002061 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2062 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2063 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002064 }
2065
2066 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2067 gen7_3dstate_pointer(cmd,
2068 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2069 blend_offset);
2070 gen7_3dstate_pointer(cmd,
2071 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2072 ds_offset);
2073 gen7_3dstate_pointer(cmd,
2074 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2075
2076 gen7_3dstate_pointer(cmd,
2077 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2078 cc_vp_offset);
2079 } else {
2080 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002081 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002082
2083 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2084 cmd_batch_pointer(cmd, 4, &dw);
2085 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2086 GEN6_PTR_VP_DW0_CC_CHANGED;
2087 dw[1] = 0;
2088 dw[2] = 0;
2089 dw[3] = cc_vp_offset;
2090 }
2091}
2092
2093static void gen6_meta_surface_states(struct intel_cmd *cmd)
2094{
2095 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002096 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002097 uint32_t offset;
2098
2099 CMD_ASSERT(cmd, 6, 7.5);
2100
Chia-I Wu29e6f502014-11-24 14:27:29 +08002101 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2102 return;
2103
Chia-I Wu005c47c2014-10-22 13:49:13 +08002104 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002105 if (meta->src.valid) {
2106 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002107 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002108 meta->src.surface_len, meta->src.surface);
2109
2110 cmd_reserve_reloc(cmd, 1);
2111 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2112 cmd_surface_reloc_writer(cmd, offset, 1,
2113 meta->src.reloc_target, meta->src.reloc_offset);
2114 } else {
2115 cmd_surface_reloc(cmd, offset, 1,
2116 (struct intel_bo *) meta->src.reloc_target,
2117 meta->src.reloc_offset, meta->src.reloc_flags);
2118 }
2119
Chia-I Wu005c47c2014-10-22 13:49:13 +08002120 binding_table[0] = offset;
2121 }
2122 if (meta->dst.valid) {
2123 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002124 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002125 meta->dst.surface_len, meta->dst.surface);
2126
2127 cmd_reserve_reloc(cmd, 1);
2128 cmd_surface_reloc(cmd, offset, 1,
2129 (struct intel_bo *) meta->dst.reloc_target,
2130 meta->dst.reloc_offset, meta->dst.reloc_flags);
2131
2132 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002133 }
2134
2135 /* BINDING_TABLE */
2136 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002137 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002138 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002139
2140 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002141 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2142 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2143 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2144 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002145 } else {
2146 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002147 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2148 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2149 else
2150 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002151 }
2152}
2153
2154static void gen6_meta_urb(struct intel_cmd *cmd)
2155{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002156 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002157 uint32_t *dw;
2158
2159 CMD_ASSERT(cmd, 6, 6);
2160
2161 /* 3DSTATE_URB */
2162 cmd_batch_pointer(cmd, 3, &dw);
2163 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002164 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002165 dw[2] = 0;
2166}
2167
2168static void gen7_meta_urb(struct intel_cmd *cmd)
2169{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002170 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002171 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002172 uint32_t *dw;
2173
2174 CMD_ASSERT(cmd, 7, 7.5);
2175
2176 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2177 cmd_batch_pointer(cmd, 10, &dw);
2178
2179 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002180 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002181 dw += 2;
2182
2183 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2184 dw[1] = 0;
2185 dw += 2;
2186
2187 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2188 dw[1] = 0;
2189 dw += 2;
2190
2191 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2192 dw[1] = 0;
2193 dw += 2;
2194
2195 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002196 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002197
2198 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2199
Chia-I Wu24aa1022014-11-25 11:53:19 +08002200 switch (cmd_gen(cmd)) {
2201 case INTEL_GEN(7.5):
2202 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2203 break;
2204 case INTEL_GEN(7):
2205 default:
2206 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2207 break;
2208 }
2209
Chia-I Wu6032b892014-10-17 14:47:18 +08002210 /* 3DSTATE_URB_x */
2211 cmd_batch_pointer(cmd, 8, &dw);
2212
2213 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2214 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002215 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002216 dw += 2;
2217
2218 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2219 dw[1] = 0;
2220 dw += 2;
2221
2222 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2223 dw[1] = 0;
2224 dw += 2;
2225
2226 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2227 dw[1] = 0;
2228 dw += 2;
2229}
2230
2231static void gen6_meta_vf(struct intel_cmd *cmd)
2232{
2233 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002234 uint32_t vb_start, vb_end, vb_stride;
2235 int ve_format, ve_z_source;
2236 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002237 XGL_UINT pos;
2238
2239 CMD_ASSERT(cmd, 6, 7.5);
2240
Chia-I Wu29e6f502014-11-24 14:27:29 +08002241 switch (meta->mode) {
2242 case INTEL_CMD_META_VS_POINTS:
2243 cmd_batch_pointer(cmd, 3, &dw);
2244 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2245 dw[1] = GEN6_VE_STATE_DW0_VALID;
2246 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2247 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2248 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2249 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2250 return;
2251 break;
2252 case INTEL_CMD_META_FS_RECT:
2253 {
2254 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002255
Chia-I Wu29e6f502014-11-24 14:27:29 +08002256 vertices[0][0] = meta->dst.x + meta->width;
2257 vertices[0][1] = meta->dst.y + meta->height;
2258 vertices[1][0] = meta->dst.x;
2259 vertices[1][1] = meta->dst.y + meta->height;
2260 vertices[2][0] = meta->dst.x;
2261 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002262
Chia-I Wu29e6f502014-11-24 14:27:29 +08002263 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2264 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002265
Chia-I Wu29e6f502014-11-24 14:27:29 +08002266 vb_end = vb_start + sizeof(vertices) - 1;
2267 vb_stride = sizeof(vertices[0]);
2268 ve_z_source = GEN6_VFCOMP_STORE_0;
2269 ve_format = GEN6_FORMAT_R32G32_USCALED;
2270 }
2271 break;
2272 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2273 {
2274 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2277 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2278 vertices[0][2] = u_uif(meta->clear_val[0]);
2279 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2280 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2281 vertices[1][2] = u_uif(meta->clear_val[0]);
2282 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2283 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2284 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2287 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002288
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 vb_end = vb_start + sizeof(vertices) - 1;
2290 vb_stride = sizeof(vertices[0]);
2291 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2292 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2293 }
2294 break;
2295 default:
2296 assert(!"unknown meta mode");
2297 return;
2298 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002299 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002300
2301 /* 3DSTATE_VERTEX_BUFFERS */
2302 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002303
Chia-I Wu6032b892014-10-17 14:47:18 +08002304 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002306 if (cmd_gen(cmd) >= INTEL_GEN(7))
2307 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2308
2309 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002310 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2311 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002312
2313 dw[4] = 0;
2314
2315 /* 3DSTATE_VERTEX_ELEMENTS */
2316 cmd_batch_pointer(cmd, 5, &dw);
2317 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002318 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002319 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2320 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2321 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2322 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2323 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002324 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002325 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2326 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002327 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002328 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2329}
2330
Chia-I Wu29e6f502014-11-24 14:27:29 +08002331static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002332{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002334 /* one GPR */
2335 XGL_UINT consts[8];
2336 XGL_UINT const_count;
2337
2338 CMD_ASSERT(cmd, 6, 7.5);
2339
2340 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002341 case INTEL_DEV_META_VS_FILL_MEM:
2342 consts[0] = meta->dst.x;
2343 consts[1] = meta->clear_val[0];
2344 const_count = 2;
2345 break;
2346 case INTEL_DEV_META_VS_COPY_MEM:
2347 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2348 consts[0] = meta->dst.x;
2349 consts[1] = meta->src.x;
2350 const_count = 2;
2351 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002352 default:
2353 assert(!"unknown meta shader id");
2354 const_count = 0;
2355 break;
2356 }
2357
2358 /* this can be skipped but it makes state dumping prettier */
2359 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2360
2361 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2362}
2363
2364static void gen6_meta_vs(struct intel_cmd *cmd)
2365{
2366 const struct intel_cmd_meta *meta = cmd->bind.meta;
2367 const struct intel_pipeline_shader *sh =
2368 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002369 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002370 uint32_t offset, *dw;
2371
2372 CMD_ASSERT(cmd, 6, 7.5);
2373
2374 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2375 XGL_UINT cmd_len;
2376
2377 /* 3DSTATE_CONSTANT_VS */
2378 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2379 cmd_batch_pointer(cmd, cmd_len, &dw);
2380 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2381 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2382
2383 /* 3DSTATE_VS */
2384 cmd_batch_pointer(cmd, 6, &dw);
2385 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2386 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2387
2388 return;
2389 }
2390
2391 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2392
2393 /* 3DSTATE_CONSTANT_VS */
2394 offset = gen6_meta_vs_constants(cmd);
2395 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2396 cmd_batch_pointer(cmd, 7, &dw);
2397 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2398 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2399 dw[2] = 0;
2400 dw[3] = offset;
2401 dw[4] = 0;
2402 dw[5] = 0;
2403 dw[6] = 0;
2404 } else {
2405 cmd_batch_pointer(cmd, 5, &dw);
2406 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2407 GEN6_PCB_ANY_DW0_PCB0_VALID;
2408 dw[1] = offset;
2409 dw[2] = 0;
2410 dw[3] = 0;
2411 dw[4] = 0;
2412 }
2413
2414 /* 3DSTATE_VS */
2415 offset = emit_shader(cmd, sh);
2416 cmd_batch_pointer(cmd, 6, &dw);
2417 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2418 dw[1] = offset;
2419 dw[2] = GEN6_THREADDISP_SPF |
2420 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2421 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2422 dw[3] = 0;
2423 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2424 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2425
2426 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2427 GEN6_VS_DW5_VS_ENABLE;
2428 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu05990612014-11-25 11:36:35 +08002429 dw[5] |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002430 else
Chia-I Wu05990612014-11-25 11:36:35 +08002431 dw[5] |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002432}
2433
2434static void gen6_meta_disabled(struct intel_cmd *cmd)
2435{
Chia-I Wu6032b892014-10-17 14:47:18 +08002436 uint32_t *dw;
2437
2438 CMD_ASSERT(cmd, 6, 6);
2439
Chia-I Wu6032b892014-10-17 14:47:18 +08002440 /* 3DSTATE_CONSTANT_GS */
2441 cmd_batch_pointer(cmd, 5, &dw);
2442 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2443 dw[1] = 0;
2444 dw[2] = 0;
2445 dw[3] = 0;
2446 dw[4] = 0;
2447
2448 /* 3DSTATE_GS */
2449 cmd_batch_pointer(cmd, 7, &dw);
2450 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2451 dw[1] = 0;
2452 dw[2] = 0;
2453 dw[3] = 0;
2454 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2455 dw[5] = GEN6_GS_DW5_STATISTICS;
2456 dw[6] = 0;
2457
Chia-I Wu6032b892014-10-17 14:47:18 +08002458 /* 3DSTATE_SF */
2459 cmd_batch_pointer(cmd, 20, &dw);
2460 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2461 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2462 memset(&dw[2], 0, 18 * sizeof(*dw));
2463}
2464
2465static void gen7_meta_disabled(struct intel_cmd *cmd)
2466{
2467 uint32_t *dw;
2468
2469 CMD_ASSERT(cmd, 7, 7.5);
2470
Chia-I Wu6032b892014-10-17 14:47:18 +08002471 /* 3DSTATE_CONSTANT_HS */
2472 cmd_batch_pointer(cmd, 7, &dw);
2473 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2474 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2475
2476 /* 3DSTATE_HS */
2477 cmd_batch_pointer(cmd, 7, &dw);
2478 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2479 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2480
2481 /* 3DSTATE_TE */
2482 cmd_batch_pointer(cmd, 4, &dw);
2483 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2484 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2485
2486 /* 3DSTATE_CONSTANT_DS */
2487 cmd_batch_pointer(cmd, 7, &dw);
2488 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2489 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2490
2491 /* 3DSTATE_DS */
2492 cmd_batch_pointer(cmd, 6, &dw);
2493 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2494 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2495
2496 /* 3DSTATE_CONSTANT_GS */
2497 cmd_batch_pointer(cmd, 7, &dw);
2498 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2499 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2500
2501 /* 3DSTATE_GS */
2502 cmd_batch_pointer(cmd, 7, &dw);
2503 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2504 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2505
2506 /* 3DSTATE_STREAMOUT */
2507 cmd_batch_pointer(cmd, 3, &dw);
2508 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2509 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2510
Chia-I Wu6032b892014-10-17 14:47:18 +08002511 /* 3DSTATE_SF */
2512 cmd_batch_pointer(cmd, 7, &dw);
2513 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2514 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2515
2516 /* 3DSTATE_SBE */
2517 cmd_batch_pointer(cmd, 14, &dw);
2518 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2519 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2520 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002521}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002522
Chia-I Wu29e6f502014-11-24 14:27:29 +08002523static void gen6_meta_clip(struct intel_cmd *cmd)
2524{
2525 const struct intel_cmd_meta *meta = cmd->bind.meta;
2526 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002527
Chia-I Wu29e6f502014-11-24 14:27:29 +08002528 /* 3DSTATE_CLIP */
2529 cmd_batch_pointer(cmd, 4, &dw);
2530 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2531 dw[1] = 0;
2532 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2533 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2534 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2535 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002536 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002537 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002538 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002539}
2540
2541static void gen6_meta_wm(struct intel_cmd *cmd)
2542{
2543 const struct intel_cmd_meta *meta = cmd->bind.meta;
2544 uint32_t *dw;
2545
2546 CMD_ASSERT(cmd, 6, 7.5);
2547
2548 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2549
2550 /* 3DSTATE_MULTISAMPLE */
2551 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2552 cmd_batch_pointer(cmd, 4, &dw);
2553 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2554 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2555 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2556 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2557 dw[2] = 0;
2558 dw[3] = 0;
2559 } else {
2560 cmd_batch_pointer(cmd, 3, &dw);
2561 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2562 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2563 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2564 dw[2] = 0;
2565 }
2566
2567 /* 3DSTATE_SAMPLE_MASK */
2568 cmd_batch_pointer(cmd, 2, &dw);
2569 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2570 dw[1] = (1 << meta->samples) - 1;
2571
2572 /* 3DSTATE_DRAWING_RECTANGLE */
2573 cmd_batch_pointer(cmd, 4, &dw);
2574 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2575 dw[1] = meta->dst.y << 16 | meta->dst.x;
2576 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2577 (meta->dst.x + meta->width - 1);
2578 dw[3] = 0;
2579}
2580
2581static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2582{
2583 const struct intel_cmd_meta *meta = cmd->bind.meta;
2584 XGL_UINT offset_x, offset_y;
2585 /* one GPR */
2586 XGL_UINT consts[8];
2587 XGL_UINT const_count;
2588
2589 CMD_ASSERT(cmd, 6, 7.5);
2590
2591 /* underflow is fine here */
2592 offset_x = meta->src.x - meta->dst.x;
2593 offset_y = meta->src.y - meta->dst.y;
2594
2595 switch (meta->shader_id) {
2596 case INTEL_DEV_META_FS_COPY_MEM:
2597 case INTEL_DEV_META_FS_COPY_1D:
2598 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2599 case INTEL_DEV_META_FS_COPY_2D:
2600 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2601 case INTEL_DEV_META_FS_COPY_2D_MS:
2602 consts[0] = offset_x;
2603 consts[1] = offset_y;
2604 consts[2] = meta->src.layer;
2605 consts[3] = meta->src.lod;
2606 const_count = 4;
2607 break;
2608 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2609 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2610 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2611 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2612 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2613 consts[0] = offset_x;
2614 consts[1] = offset_y;
2615 consts[2] = meta->src.layer;
2616 consts[3] = meta->src.lod;
2617 consts[4] = meta->src.x;
2618 consts[5] = meta->width;
2619 const_count = 6;
2620 break;
2621 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2622 consts[0] = offset_x;
2623 consts[1] = offset_y;
2624 consts[2] = meta->width;
2625 const_count = 3;
2626 break;
2627 case INTEL_DEV_META_FS_CLEAR_COLOR:
2628 consts[0] = meta->clear_val[0];
2629 consts[1] = meta->clear_val[1];
2630 consts[2] = meta->clear_val[2];
2631 consts[3] = meta->clear_val[3];
2632 const_count = 4;
2633 break;
2634 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2635 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002636 consts[1] = meta->clear_val[1];
2637 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002638 break;
2639 case INTEL_DEV_META_FS_RESOLVE_2X:
2640 case INTEL_DEV_META_FS_RESOLVE_4X:
2641 case INTEL_DEV_META_FS_RESOLVE_8X:
2642 case INTEL_DEV_META_FS_RESOLVE_16X:
2643 consts[0] = offset_x;
2644 consts[1] = offset_y;
2645 const_count = 2;
2646 break;
2647 default:
2648 assert(!"unknown meta shader id");
2649 const_count = 0;
2650 break;
2651 }
2652
2653 /* this can be skipped but it makes state dumping prettier */
2654 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2655
2656 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2657}
2658
2659static void gen6_meta_ps(struct intel_cmd *cmd)
2660{
2661 const struct intel_cmd_meta *meta = cmd->bind.meta;
2662 const struct intel_pipeline_shader *sh =
2663 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002664 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002665 uint32_t offset, *dw;
2666
2667 CMD_ASSERT(cmd, 6, 6);
2668
Chia-I Wu29e6f502014-11-24 14:27:29 +08002669 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2670 /* 3DSTATE_CONSTANT_PS */
2671 cmd_batch_pointer(cmd, 5, &dw);
2672 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2673 dw[1] = 0;
2674 dw[2] = 0;
2675 dw[3] = 0;
2676 dw[4] = 0;
2677
2678 /* 3DSTATE_WM */
2679 cmd_batch_pointer(cmd, 9, &dw);
2680 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2681 dw[1] = 0;
2682 dw[2] = 0;
2683 dw[3] = 0;
2684 dw[4] = 0;
Chia-I Wu05990612014-11-25 11:36:35 +08002685 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002686 dw[6] = 0;
2687 dw[7] = 0;
2688 dw[8] = 0;
2689
Chia-I Wu3adf7212014-10-24 15:34:07 +08002690 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002691 }
2692
Chia-I Wu3adf7212014-10-24 15:34:07 +08002693 /* a normal color write */
2694 assert(meta->dst.valid && !sh->uses);
2695
Chia-I Wu6032b892014-10-17 14:47:18 +08002696 /* 3DSTATE_CONSTANT_PS */
2697 offset = gen6_meta_ps_constants(cmd);
2698 cmd_batch_pointer(cmd, 5, &dw);
2699 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2700 GEN6_PCB_ANY_DW0_PCB0_VALID;
2701 dw[1] = offset;
2702 dw[2] = 0;
2703 dw[3] = 0;
2704 dw[4] = 0;
2705
2706 /* 3DSTATE_WM */
2707 offset = emit_shader(cmd, sh);
2708 cmd_batch_pointer(cmd, 9, &dw);
2709 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2710 dw[1] = offset;
2711 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2712 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2713 dw[3] = 0;
2714 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002715 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002716 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002717 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2718
Chia-I Wu6032b892014-10-17 14:47:18 +08002719 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2720 GEN6_WM_DW6_POSOFFSET_NONE |
2721 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2722 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2723 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2724 if (meta->samples > 1) {
2725 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2726 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2727 } else {
2728 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2729 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2730 }
2731 dw[7] = 0;
2732 dw[8] = 0;
2733}
2734
2735static void gen7_meta_ps(struct intel_cmd *cmd)
2736{
2737 const struct intel_cmd_meta *meta = cmd->bind.meta;
2738 const struct intel_pipeline_shader *sh =
2739 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002740 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002741 uint32_t offset, *dw;
2742
2743 CMD_ASSERT(cmd, 7, 7.5);
2744
Chia-I Wu29e6f502014-11-24 14:27:29 +08002745 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2746 /* 3DSTATE_WM */
2747 cmd_batch_pointer(cmd, 3, &dw);
2748 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2749 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2750
2751 /* 3DSTATE_CONSTANT_GS */
2752 cmd_batch_pointer(cmd, 7, &dw);
2753 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2754 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2755
2756 /* 3DSTATE_PS */
2757 cmd_batch_pointer(cmd, 8, &dw);
2758 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2759 dw[1] = 0;
2760 dw[2] = 0;
2761 dw[3] = 0;
2762 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu05990612014-11-25 11:36:35 +08002763 (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002764 dw[5] = 0;
2765 dw[6] = 0;
2766 dw[7] = 0;
2767
Chia-I Wu3adf7212014-10-24 15:34:07 +08002768 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002769 }
2770
Chia-I Wu3adf7212014-10-24 15:34:07 +08002771 /* a normal color write */
2772 assert(meta->dst.valid && !sh->uses);
2773
Chia-I Wu6032b892014-10-17 14:47:18 +08002774 /* 3DSTATE_WM */
2775 cmd_batch_pointer(cmd, 3, &dw);
2776 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2777 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2778 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2779 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2780 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2781 dw[2] = 0;
2782
2783 /* 3DSTATE_CONSTANT_PS */
2784 offset = gen6_meta_ps_constants(cmd);
2785 cmd_batch_pointer(cmd, 7, &dw);
2786 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2787 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2788 dw[2] = 0;
2789 dw[3] = offset;
2790 dw[4] = 0;
2791 dw[5] = 0;
2792 dw[6] = 0;
2793
2794 /* 3DSTATE_PS */
2795 offset = emit_shader(cmd, sh);
2796 cmd_batch_pointer(cmd, 8, &dw);
2797 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2798 dw[1] = offset;
2799 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2800 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2801 dw[3] = 0;
2802
2803 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2804 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002805 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2806
2807 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2808 dw[4] |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002809 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002810 } else {
2811 dw[4] |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2812 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002813
2814 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2815 dw[6] = 0;
2816 dw[7] = 0;
2817}
2818
2819static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2820{
2821 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002822 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002823
2824 CMD_ASSERT(cmd, 6, 7.5);
2825
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002826 if (!ds) {
2827 /* all zeros */
2828 static const struct intel_ds_view null_ds;
2829 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002830 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002831
2832 cmd_wa_gen6_pre_ds_flush(cmd);
2833 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2834 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2835 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2836
2837 if (cmd_gen(cmd) >= INTEL_GEN(7))
2838 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2839 else
2840 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002841}
2842
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002843static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2844 const struct intel_pipeline *pipeline)
2845{
2846 cmd->bind.pipeline.graphics = pipeline;
2847}
2848
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002849static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2850 const struct intel_pipeline *pipeline)
2851{
2852 cmd->bind.pipeline.compute = pipeline;
2853}
2854
2855static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2856 const struct intel_pipeline_delta *delta)
2857{
2858 cmd->bind.pipeline.graphics_delta = delta;
2859}
2860
2861static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2862 const struct intel_pipeline_delta *delta)
2863{
2864 cmd->bind.pipeline.compute_delta = delta;
2865}
2866
2867static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2868 const struct intel_dset *dset,
2869 XGL_UINT slot_offset)
2870{
2871 cmd->bind.dset.graphics = dset;
2872 cmd->bind.dset.graphics_offset = slot_offset;
2873}
2874
2875static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2876 const struct intel_dset *dset,
2877 XGL_UINT slot_offset)
2878{
2879 cmd->bind.dset.compute = dset;
2880 cmd->bind.dset.compute_offset = slot_offset;
2881}
2882
2883static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2884 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2885{
2886 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2887}
2888
2889static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2890 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2891{
2892 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2893}
2894
Chia-I Wu3b04af52014-11-08 10:48:20 +08002895static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2896 const struct intel_mem *mem,
2897 XGL_GPU_SIZE offset, XGL_UINT binding)
2898{
2899 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2900 cmd->result = XGL_ERROR_UNKNOWN;
2901 return;
2902 }
2903
2904 cmd->bind.vertex.mem[binding] = mem;
2905 cmd->bind.vertex.offset[binding] = offset;
2906}
2907
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002908static void cmd_bind_index_data(struct intel_cmd *cmd,
2909 const struct intel_mem *mem,
2910 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2911{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002912 cmd->bind.index.mem = mem;
2913 cmd->bind.index.offset = offset;
2914 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002915}
2916
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002917static void cmd_bind_attachments(struct intel_cmd *cmd,
2918 XGL_UINT rt_count,
2919 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2920 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002921{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002922 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002923 XGL_UINT i;
2924
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002925 for (i = 0; i < rt_count; i++) {
2926 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002927 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002928 const struct intel_layout *layout = &rt->img->layout;
2929
2930 if (i == 0) {
2931 width = layout->width0;
2932 height = layout->height0;
2933 } else {
2934 if (width > layout->width0)
2935 width = layout->width0;
2936 if (height > layout->height0)
2937 height = layout->height0;
2938 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002939
2940 cmd->bind.att.rt[i] = rt;
2941 }
2942
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002943 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002944
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002945 if (ds_info) {
2946 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002948 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2949 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002951 if (width > layout->width0)
2952 width = layout->width0;
2953 if (height > layout->height0)
2954 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002955 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002956 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957 }
2958
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002959 cmd->bind.att.width = width;
2960 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961}
2962
2963static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2964 const struct intel_viewport_state *state)
2965{
2966 cmd->bind.state.viewport = state;
2967}
2968
2969static void cmd_bind_raster_state(struct intel_cmd *cmd,
2970 const struct intel_raster_state *state)
2971{
2972 cmd->bind.state.raster = state;
2973}
2974
2975static void cmd_bind_ds_state(struct intel_cmd *cmd,
2976 const struct intel_ds_state *state)
2977{
2978 cmd->bind.state.ds = state;
2979}
2980
2981static void cmd_bind_blend_state(struct intel_cmd *cmd,
2982 const struct intel_blend_state *state)
2983{
2984 cmd->bind.state.blend = state;
2985}
2986
2987static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2988 const struct intel_msaa_state *state)
2989{
2990 cmd->bind.state.msaa = state;
2991}
2992
2993static void cmd_draw(struct intel_cmd *cmd,
2994 XGL_UINT vertex_start,
2995 XGL_UINT vertex_count,
2996 XGL_UINT instance_start,
2997 XGL_UINT instance_count,
2998 bool indexed,
2999 XGL_UINT vertex_base)
3000{
3001 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3002
3003 emit_bounded_states(cmd);
3004
3005 if (indexed) {
3006 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3007 cmd->result = XGL_ERROR_UNKNOWN;
3008
3009 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3010 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3011 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003012 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3013 cmd->bind.index.offset, cmd->bind.index.type,
3014 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003015 } else {
3016 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3017 cmd->bind.index.offset, cmd->bind.index.type,
3018 p->primitive_restart);
3019 }
3020 } else {
3021 assert(!vertex_base);
3022 }
3023
3024 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3025 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3026 vertex_start, instance_count, instance_start, vertex_base);
3027 } else {
3028 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3029 vertex_start, instance_count, instance_start, vertex_base);
3030 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003031
Chia-I Wu707a29e2014-08-27 12:51:47 +08003032 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003033 /* need to re-emit all workarounds */
3034 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003035
3036 if (intel_debug & INTEL_DEBUG_NOCACHE)
3037 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003038}
3039
Chia-I Wuc14d1562014-10-17 09:49:22 +08003040void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3041{
Chia-I Wu6032b892014-10-17 14:47:18 +08003042 cmd->bind.meta = meta;
3043
3044 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003045 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003046
3047 gen6_meta_dynamic_states(cmd);
3048 gen6_meta_surface_states(cmd);
3049
3050 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3051 gen7_meta_urb(cmd);
3052 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003053 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003054 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003055 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003056 gen6_meta_wm(cmd);
3057 gen7_meta_ps(cmd);
3058 gen6_meta_depth_buffer(cmd);
3059
3060 cmd_wa_gen7_post_command_cs_stall(cmd);
3061 cmd_wa_gen7_post_command_depth_stall(cmd);
3062
Chia-I Wu29e6f502014-11-24 14:27:29 +08003063 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3064 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3065 meta->width, 0, 1, 0, 0);
3066 } else {
3067 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3068 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003069 } else {
3070 gen6_meta_urb(cmd);
3071 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003072 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003073 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003074 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003075 gen6_meta_wm(cmd);
3076 gen6_meta_ps(cmd);
3077 gen6_meta_depth_buffer(cmd);
3078
Chia-I Wu29e6f502014-11-24 14:27:29 +08003079 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3080 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3081 meta->width, 0, 1, 0, 0);
3082 } else {
3083 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3084 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003085 }
3086
3087 cmd->bind.draw_count++;
3088 /* need to re-emit all workarounds */
3089 cmd->bind.wa_flags = 0;
3090
3091 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003092
3093 if (intel_debug & INTEL_DEBUG_NOCACHE)
3094 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003095}
3096
Chia-I Wub2755562014-08-20 13:38:52 +08003097XGL_VOID XGLAPI intelCmdBindPipeline(
3098 XGL_CMD_BUFFER cmdBuffer,
3099 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3100 XGL_PIPELINE pipeline)
3101{
3102 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3103
3104 switch (pipelineBindPoint) {
3105 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003106 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003107 break;
3108 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003109 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003110 break;
3111 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003112 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003113 break;
3114 }
3115}
3116
3117XGL_VOID XGLAPI intelCmdBindPipelineDelta(
3118 XGL_CMD_BUFFER cmdBuffer,
3119 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3120 XGL_PIPELINE_DELTA delta)
3121{
3122 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3123
3124 switch (pipelineBindPoint) {
3125 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003126 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003127 break;
3128 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003129 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003130 break;
3131 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003132 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003133 break;
3134 }
3135}
3136
3137XGL_VOID XGLAPI intelCmdBindStateObject(
3138 XGL_CMD_BUFFER cmdBuffer,
3139 XGL_STATE_BIND_POINT stateBindPoint,
3140 XGL_STATE_OBJECT state)
3141{
3142 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3143
3144 switch (stateBindPoint) {
3145 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003146 cmd_bind_viewport_state(cmd,
3147 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003148 break;
3149 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003150 cmd_bind_raster_state(cmd,
3151 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003152 break;
3153 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003154 cmd_bind_ds_state(cmd,
3155 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003156 break;
3157 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003158 cmd_bind_blend_state(cmd,
3159 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003160 break;
3161 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003162 cmd_bind_msaa_state(cmd,
3163 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003164 break;
3165 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003166 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003167 break;
3168 }
3169}
3170
3171XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3172 XGL_CMD_BUFFER cmdBuffer,
3173 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3174 XGL_UINT index,
3175 XGL_DESCRIPTOR_SET descriptorSet,
3176 XGL_UINT slotOffset)
3177{
3178 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3179 struct intel_dset *dset = intel_dset(descriptorSet);
3180
3181 assert(!index);
3182
3183 switch (pipelineBindPoint) {
3184 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003186 break;
3187 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003189 break;
3190 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003191 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003192 break;
3193 }
3194}
3195
3196XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3197 XGL_CMD_BUFFER cmdBuffer,
3198 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3199 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3200{
3201 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3202
3203 switch (pipelineBindPoint) {
3204 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003209 break;
3210 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003212 break;
3213 }
3214}
3215
Chia-I Wu3b04af52014-11-08 10:48:20 +08003216XGL_VOID XGLAPI intelCmdBindVertexData(
3217 XGL_CMD_BUFFER cmdBuffer,
3218 XGL_GPU_MEMORY mem_,
3219 XGL_GPU_SIZE offset,
3220 XGL_UINT binding)
3221{
3222 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3223 struct intel_mem *mem = intel_mem(mem_);
3224
3225 cmd_bind_vertex_data(cmd, mem, offset, binding);
3226}
3227
Chia-I Wub2755562014-08-20 13:38:52 +08003228XGL_VOID XGLAPI intelCmdBindIndexData(
3229 XGL_CMD_BUFFER cmdBuffer,
3230 XGL_GPU_MEMORY mem_,
3231 XGL_GPU_SIZE offset,
3232 XGL_INDEX_TYPE indexType)
3233{
3234 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3235 struct intel_mem *mem = intel_mem(mem_);
3236
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003238}
3239
3240XGL_VOID XGLAPI intelCmdBindAttachments(
3241 XGL_CMD_BUFFER cmdBuffer,
3242 XGL_UINT colorAttachmentCount,
3243 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3244 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3245{
3246 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003247
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003248 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3249 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003250}
3251
3252XGL_VOID XGLAPI intelCmdDraw(
3253 XGL_CMD_BUFFER cmdBuffer,
3254 XGL_UINT firstVertex,
3255 XGL_UINT vertexCount,
3256 XGL_UINT firstInstance,
3257 XGL_UINT instanceCount)
3258{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003259 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003260
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003261 cmd_draw(cmd, firstVertex, vertexCount,
3262 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003263}
3264
3265XGL_VOID XGLAPI intelCmdDrawIndexed(
3266 XGL_CMD_BUFFER cmdBuffer,
3267 XGL_UINT firstIndex,
3268 XGL_UINT indexCount,
3269 XGL_INT vertexOffset,
3270 XGL_UINT firstInstance,
3271 XGL_UINT instanceCount)
3272{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003273 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003274
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003275 cmd_draw(cmd, firstIndex, indexCount,
3276 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003277}
3278
3279XGL_VOID XGLAPI intelCmdDrawIndirect(
3280 XGL_CMD_BUFFER cmdBuffer,
3281 XGL_GPU_MEMORY mem,
3282 XGL_GPU_SIZE offset,
3283 XGL_UINT32 count,
3284 XGL_UINT32 stride)
3285{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003286 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3287
3288 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003289}
3290
3291XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3292 XGL_CMD_BUFFER cmdBuffer,
3293 XGL_GPU_MEMORY mem,
3294 XGL_GPU_SIZE offset,
3295 XGL_UINT32 count,
3296 XGL_UINT32 stride)
3297{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003298 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3299
3300 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003301}
3302
3303XGL_VOID XGLAPI intelCmdDispatch(
3304 XGL_CMD_BUFFER cmdBuffer,
3305 XGL_UINT x,
3306 XGL_UINT y,
3307 XGL_UINT z)
3308{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003309 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3310
3311 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003312}
3313
3314XGL_VOID XGLAPI intelCmdDispatchIndirect(
3315 XGL_CMD_BUFFER cmdBuffer,
3316 XGL_GPU_MEMORY mem,
3317 XGL_GPU_SIZE offset)
3318{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003319 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3320
3321 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003322}