blob: 1857b6ba7e682c62500077491182cb2cefb66280 [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{
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800446 const struct intel_pipeline_shader *vs = &cmd->bind.pipeline.graphics->vs;
447 const struct intel_pipeline_shader *fs = &cmd->bind.pipeline.graphics->fs;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448 XGL_UINT attr_skip, attr_count;
449 XGL_UINT vue_offset, vue_len;
450 XGL_UINT i;
451 uint32_t dw1;
452
453 CMD_ASSERT(cmd, 6, 7.5);
454
455 /* VS outputs VUE header and position additionally */
GregFbcbe19a2014-11-07 11:01:01 -0700456 assert(vs->out_count >= fs->in_count + 2);
457 attr_skip = vs->out_count - fs->in_count;
Chia-I Wu8016a172014-08-29 18:31:32 +0800458 attr_count = vs->out_count - attr_skip;
Chia-I Wu8016a172014-08-29 18:31:32 +0800459 assert(fs->in_count <= 32);
460
GregFbcbe19a2014-11-07 11:01:01 -0700461 vue_offset = (attr_skip + 1) / 2;
Chia-I Wu8016a172014-08-29 18:31:32 +0800462 vue_len = (attr_count + 1) / 2;
463 if (!vue_len)
464 vue_len = 1;
465
466 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
467 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
468 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
469
470 body[0] = dw1;
471
472 for (i = 0; i < 8; i++) {
473 uint16_t hi, lo;
474
475 /* no attr swizzles */
476 if (i * 2 + 1 < fs->in_count) {
477 hi = i * 2 + 1;
478 lo = i * 2;
479 } else if (i * 2 < fs->in_count) {
480 hi = 0;
481 lo = i * 2;
482 } else {
483 hi = 0;
484 lo = 0;
485 }
486
487 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
488 }
489
490 body[9] = 0; /* point sprite enables */
491 body[10] = 0; /* constant interpolation enables */
492 body[11] = 0; /* WrapShortest enables */
493 body[12] = 0;
494}
495
496static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
497{
498 const uint8_t cmd_len = 20;
499 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
500 (cmd_len - 2);
501 uint32_t sf[6];
502 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800503 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800504
505 CMD_ASSERT(cmd, 6, 6);
506
507 gen7_fill_3DSTATE_SF_body(cmd, sf);
508 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
509
Chia-I Wu72292b72014-09-09 10:48:33 +0800510 cmd_batch_pointer(cmd, cmd_len, &dw);
511 dw[0] = dw0;
512 dw[1] = sbe[0];
513 memcpy(&dw[2], sf, sizeof(sf));
514 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800515}
516
517static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
518{
519 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800520 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800521
522 CMD_ASSERT(cmd, 7, 7.5);
523
Chia-I Wu72292b72014-09-09 10:48:33 +0800524 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
526 (cmd_len - 2);
527 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800528}
529
530static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
531{
532 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800533 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800534
535 CMD_ASSERT(cmd, 7, 7.5);
536
Chia-I Wu72292b72014-09-09 10:48:33 +0800537 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800538 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
539 (cmd_len - 2);
540 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800541}
542
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800543static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
544{
545 const uint8_t cmd_len = 4;
546 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
547 (cmd_len - 2);
548 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700549 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800550 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800551 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
552 const struct intel_raster_state *raster = cmd->bind.state.raster;
Chia-I Wu72292b72014-09-09 10:48:33 +0800553 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800554
555 CMD_ASSERT(cmd, 6, 7.5);
556
557 dw1 = GEN6_CLIP_DW1_STATISTICS;
558 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
559 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
560 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
561 raster->cmd_clip_cull;
562 }
563
564 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
565 GEN6_CLIP_DW2_XY_TEST_ENABLE |
566 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700567 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800568 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
569 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
570 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
571
572 if (pipeline->rasterizerDiscardEnable)
573 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
574 else
575 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
576
577 if (pipeline->depthClipEnable)
578 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
579
580 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
581 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
582 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
583 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
584
585 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
586 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
587 (viewport->viewport_count - 1);
588
Chia-I Wu72292b72014-09-09 10:48:33 +0800589 cmd_batch_pointer(cmd, cmd_len, &dw);
590 dw[0] = dw0;
591 dw[1] = dw1;
592 dw[2] = dw2;
593 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800594}
595
Chia-I Wu05990612014-11-25 11:36:35 +0800596static int cmd_vs_max_threads(const struct intel_cmd *cmd)
597{
598 switch (cmd_gen(cmd)) {
599 case INTEL_GEN(7.5):
600 return (cmd->dev->gpu->gt >= 2) ? 280 : 70;
601 case INTEL_GEN(7):
602 return (cmd->dev->gpu->gt == 2) ? 128 : 36;
603 case INTEL_GEN(6):
604 return (cmd->dev->gpu->gt == 2) ? 60 : 24;
605 default:
606 return 1;
607 }
608}
609
610static int cmd_ps_max_threads(const struct intel_cmd *cmd)
611{
612 switch (cmd_gen(cmd)) {
613 case INTEL_GEN(7.5):
614 return (cmd->dev->gpu->gt == 3) ? 408 :
615 (cmd->dev->gpu->gt == 2) ? 204 : 102;
616 case INTEL_GEN(7):
617 return (cmd->dev->gpu->gt == 2) ? 172 : 48;
618 case INTEL_GEN(6):
619 return (cmd->dev->gpu->gt == 2) ? 80 : 40;
620 default:
621 return 4;
622 }
623}
624
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800625static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
626{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800628 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800629 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
630 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800631 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632
633 CMD_ASSERT(cmd, 6, 6);
634
635 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
636
637 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
638 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
639
640 dw4 = GEN6_WM_DW4_STATISTICS |
641 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
642 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
643 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
644
Chia-I Wu05990612014-11-25 11:36:35 +0800645 dw5 = (cmd_ps_max_threads(cmd) - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800646 GEN6_WM_DW5_PS_ENABLE |
647 GEN6_WM_DW5_8_PIXEL_DISPATCH;
648
649 if (fs->uses & INTEL_SHADER_USE_KILL ||
650 pipeline->cb_state.alphaToCoverageEnable)
651 dw5 |= GEN6_WM_DW5_PS_KILL;
652
653 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
654 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
655 if (fs->uses & INTEL_SHADER_USE_DEPTH)
656 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
657 if (fs->uses & INTEL_SHADER_USE_W)
658 dw5 |= GEN6_WM_DW5_PS_USE_W;
659
660 if (pipeline->cb_state.dualSourceBlendEnable)
661 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
662
663 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
664 GEN6_WM_DW6_POSOFFSET_NONE |
665 GEN6_WM_DW6_ZW_INTERP_PIXEL |
666 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
667 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
668
669 if (msaa->sample_count > 1) {
670 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
671 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
672 } else {
673 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
674 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
675 }
676
Chia-I Wu72292b72014-09-09 10:48:33 +0800677 cmd_batch_pointer(cmd, cmd_len, &dw);
678 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800679 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800680 dw[2] = dw2;
681 dw[3] = 0; /* scratch */
682 dw[4] = dw4;
683 dw[5] = dw5;
684 dw[6] = dw6;
685 dw[7] = 0; /* kernel 1 */
686 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687}
688
689static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
690{
691 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800692 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
694 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800695 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800696
697 CMD_ASSERT(cmd, 7, 7.5);
698
699 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
700
701 dw1 = GEN7_WM_DW1_STATISTICS |
702 GEN7_WM_DW1_PS_ENABLE |
703 GEN7_WM_DW1_ZW_INTERP_PIXEL |
704 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
705 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
706
707 if (fs->uses & INTEL_SHADER_USE_KILL ||
708 pipeline->cb_state.alphaToCoverageEnable)
709 dw1 |= GEN7_WM_DW1_PS_KILL;
710
711 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
712 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
713 if (fs->uses & INTEL_SHADER_USE_DEPTH)
714 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
715 if (fs->uses & INTEL_SHADER_USE_W)
716 dw1 |= GEN7_WM_DW1_PS_USE_W;
717
718 dw2 = 0;
719
720 if (msaa->sample_count > 1) {
721 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
722 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
723 } else {
724 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
725 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
726 }
727
Chia-I Wu72292b72014-09-09 10:48:33 +0800728 cmd_batch_pointer(cmd, cmd_len, &dw);
729 dw[0] = dw0;
730 dw[1] = dw1;
731 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800732}
733
734static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
735{
736 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800737 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800738 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
Chia-I Wu05990612014-11-25 11:36:35 +0800739 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800740 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800741 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800742
743 CMD_ASSERT(cmd, 7, 7.5);
744
745 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
746
747 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
748 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
749
750 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
751 GEN7_PS_DW4_8_PIXEL_DISPATCH;
752
753 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800754 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
755 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
756 } else {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800757 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
758 }
759
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800760 if (fs->in_count)
761 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
762
763 if (pipeline->cb_state.dualSourceBlendEnable)
764 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
765
766 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
767 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
768 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
769
Chia-I Wu72292b72014-09-09 10:48:33 +0800770 cmd_batch_pointer(cmd, cmd_len, &dw);
771 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800772 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800773 dw[2] = dw2;
774 dw[3] = 0; /* scratch */
775 dw[4] = dw4;
776 dw[5] = dw5;
777 dw[6] = 0; /* kernel 1 */
778 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800779}
780
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800781static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
782 const struct intel_ds_view *view)
783{
784 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 uint32_t dw0, *dw;
786 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787
788 CMD_ASSERT(cmd, 6, 7.5);
789
790 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800791 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
792 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793 dw0 |= (cmd_len - 2);
794
Chia-I Wu72292b72014-09-09 10:48:33 +0800795 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
796 dw[0] = dw0;
797 dw[1] = view->cmd[0];
798 dw[2] = 0;
799 dw[3] = view->cmd[2];
800 dw[4] = view->cmd[3];
801 dw[5] = view->cmd[4];
802 dw[6] = view->cmd[5];
803
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800805 cmd_reserve_reloc(cmd, 1);
806 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
807 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600808 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800809}
810
811static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
812 const struct intel_ds_view *view)
813{
814 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800815 uint32_t dw0, *dw;
816 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800817
818 CMD_ASSERT(cmd, 6, 7.5);
819
820 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800821 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
822 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800823 dw0 |= (cmd_len - 2);
824
Chia-I Wu72292b72014-09-09 10:48:33 +0800825 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
826 dw[0] = dw0;
827 dw[1] = view->cmd[6];
828 dw[2] = 0;
829
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600830 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 cmd_reserve_reloc(cmd, 1);
832 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
833 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600834 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835}
836
837static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
838 const struct intel_ds_view *view)
839{
840 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800841 uint32_t dw0, *dw;
842 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800843
844 CMD_ASSERT(cmd, 6, 7.5);
845
846 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800847 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
848 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800849 dw0 |= (cmd_len - 2);
850
Chia-I Wu72292b72014-09-09 10:48:33 +0800851 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
852 dw[0] = dw0;
853 dw[1] = view->cmd[8];
854 dw[2] = 0;
855
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600856 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 cmd_reserve_reloc(cmd, 1);
858 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
859 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600860 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800861}
862
Chia-I Wuf8231032014-08-25 10:44:45 +0800863static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
864 uint32_t clear_val)
865{
866 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800867 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800868 GEN6_CLEAR_PARAMS_DW0_VALID |
869 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 cmd_batch_pointer(cmd, cmd_len, &dw);
875 dw[0] = dw0;
876 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800877}
878
879static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
880 uint32_t clear_val)
881{
882 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800883 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800884 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800886
887 CMD_ASSERT(cmd, 7, 7.5);
888
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 cmd_batch_pointer(cmd, cmd_len, &dw);
890 dw[0] = dw0;
891 dw[1] = clear_val;
892 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800893}
894
Chia-I Wu302742d2014-08-22 10:28:29 +0800895static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800896 uint32_t blend_offset,
897 uint32_t ds_offset,
898 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800899{
900 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800902
903 CMD_ASSERT(cmd, 6, 6);
904
Chia-I Wu426072d2014-08-26 14:31:55 +0800905 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800906 (cmd_len - 2);
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_batch_pointer(cmd, cmd_len, &dw);
909 dw[0] = dw0;
910 dw[1] = blend_offset | 1;
911 dw[2] = ds_offset | 1;
912 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800913}
914
Chia-I Wu1744cca2014-08-22 11:10:17 +0800915static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t clip_offset,
917 uint32_t sf_offset,
918 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800919{
920 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800921 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800922
923 CMD_ASSERT(cmd, 6, 6);
924
Chia-I Wu426072d2014-08-26 14:31:55 +0800925 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800926 GEN6_PTR_VP_DW0_CLIP_CHANGED |
927 GEN6_PTR_VP_DW0_SF_CHANGED |
928 GEN6_PTR_VP_DW0_CC_CHANGED |
929 (cmd_len - 2);
930
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 cmd_batch_pointer(cmd, cmd_len, &dw);
932 dw[0] = dw0;
933 dw[1] = clip_offset;
934 dw[2] = sf_offset;
935 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800936}
937
938static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800940{
941 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800943
944 CMD_ASSERT(cmd, 6, 6);
945
Chia-I Wu426072d2014-08-26 14:31:55 +0800946 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800947 (cmd_len - 2);
948
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 cmd_batch_pointer(cmd, cmd_len, &dw);
950 dw[0] = dw0;
951 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800952}
953
Chia-I Wu42a56202014-08-23 16:47:48 +0800954static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 uint32_t vs_offset,
956 uint32_t gs_offset,
957 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800958{
959 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800960 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800961
962 CMD_ASSERT(cmd, 6, 6);
963
Chia-I Wu426072d2014-08-26 14:31:55 +0800964 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800965 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
966 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
967 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
968 (cmd_len - 2);
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970 cmd_batch_pointer(cmd, cmd_len, &dw);
971 dw[0] = dw0;
972 dw[1] = vs_offset;
973 dw[2] = gs_offset;
974 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800975}
976
Chia-I Wu257e75e2014-08-29 14:06:35 +0800977static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800978 uint32_t vs_offset,
979 uint32_t gs_offset,
980 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800981{
982 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800984
985 CMD_ASSERT(cmd, 6, 6);
986
987 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
988 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
989 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
990 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
991 (cmd_len - 2);
992
Chia-I Wu72292b72014-09-09 10:48:33 +0800993 cmd_batch_pointer(cmd, cmd_len, &dw);
994 dw[0] = dw0;
995 dw[1] = vs_offset;
996 dw[2] = gs_offset;
997 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800998}
999
Chia-I Wu302742d2014-08-22 10:28:29 +08001000static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001002{
1003 const uint8_t cmd_len = 2;
1004 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1005 GEN6_RENDER_SUBTYPE_3D |
1006 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001008
Chia-I Wu72292b72014-09-09 10:48:33 +08001009 cmd_batch_pointer(cmd, cmd_len, &dw);
1010 dw[0] = dw0;
1011 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wua6c4f152014-12-02 04:19:58 +08001014static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001015{
Chia-I Wue6073342014-11-30 09:43:42 +08001016 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001017 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
Chia-I Wua6c4f152014-12-02 04:19:58 +08001018 const XGL_PIPELINE_CB_STATE *cb = &cmd->bind.pipeline.graphics->cb_state;
1019 const struct intel_blend_state *blend = cmd->bind.state.blend;
1020 uint32_t dw[XGL_MAX_COLOR_ATTACHMENTS * 2];
1021 int i;
Chia-I Wu302742d2014-08-22 10:28:29 +08001022
1023 CMD_ASSERT(cmd, 6, 7.5);
Chia-I Wua6c4f152014-12-02 04:19:58 +08001024 STATIC_ASSERT(ARRAY_SIZE(blend->cmd_blend) >= XGL_MAX_COLOR_ATTACHMENTS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001025
Chia-I Wua6c4f152014-12-02 04:19:58 +08001026 for (i = 0; i < XGL_MAX_COLOR_ATTACHMENTS; i++) {
1027 const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = &cb->attachment[i];
1028 uint32_t dw0, dw1;
1029
1030 dw0 = 0;
1031 dw1 = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
1032 GEN6_BLEND_DW1_PRE_BLEND_CLAMP |
1033 GEN6_BLEND_DW1_POST_BLEND_CLAMP;
1034
1035 if (cb->logicOp != XGL_LOGIC_OP_COPY) {
1036 int logicop;
1037
1038 switch (cb->logicOp) {
1039 case XGL_LOGIC_OP_CLEAR: logicop = GEN6_LOGICOP_CLEAR; break;
1040 case XGL_LOGIC_OP_AND: logicop = GEN6_LOGICOP_AND; break;
1041 case XGL_LOGIC_OP_AND_REVERSE: logicop = GEN6_LOGICOP_AND_REVERSE; break;
1042 case XGL_LOGIC_OP_AND_INVERTED: logicop = GEN6_LOGICOP_AND_INVERTED; break;
1043 case XGL_LOGIC_OP_NOOP: logicop = GEN6_LOGICOP_NOOP; break;
1044 case XGL_LOGIC_OP_XOR: logicop = GEN6_LOGICOP_XOR; break;
1045 case XGL_LOGIC_OP_OR: logicop = GEN6_LOGICOP_OR; break;
1046 case XGL_LOGIC_OP_NOR: logicop = GEN6_LOGICOP_NOR; break;
1047 case XGL_LOGIC_OP_EQUIV: logicop = GEN6_LOGICOP_EQUIV; break;
1048 case XGL_LOGIC_OP_INVERT: logicop = GEN6_LOGICOP_INVERT; break;
1049 case XGL_LOGIC_OP_OR_REVERSE: logicop = GEN6_LOGICOP_OR_REVERSE; break;
1050 case XGL_LOGIC_OP_COPY_INVERTED: logicop = GEN6_LOGICOP_COPY_INVERTED; break;
1051 case XGL_LOGIC_OP_OR_INVERTED: logicop = GEN6_LOGICOP_OR_INVERTED; break;
1052 case XGL_LOGIC_OP_NAND: logicop = GEN6_LOGICOP_NAND; break;
1053 case XGL_LOGIC_OP_SET: logicop = GEN6_LOGICOP_SET; break;
1054 default:
1055 assert(!"unknown logic op");
1056 logicop = GEN6_LOGICOP_CLEAR;
1057 break;
1058 }
1059
1060 dw1 |= GEN6_BLEND_DW1_LOGICOP_ENABLE |
1061 logicop << GEN6_BLEND_DW1_LOGICOP_FUNC__SHIFT;
1062 } else if (att->blendEnable && blend) {
1063 dw0 |= blend->cmd_blend[i];
1064 }
1065
1066 if (!(att->channelWriteMask & 0x1))
1067 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_R;
1068 if (!(att->channelWriteMask & 0x2))
1069 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_G;
1070 if (!(att->channelWriteMask & 0x4))
1071 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_B;
1072 if (!(att->channelWriteMask & 0x8))
1073 dw1 |= GEN6_BLEND_DW1_WRITE_DISABLE_A;
1074
1075 dw[2 * i] = dw0;
1076 dw[2 * i + 1] = dw1;
1077 }
1078
1079 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001080}
1081
Chia-I Wu72292b72014-09-09 10:48:33 +08001082static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001083 const struct intel_ds_state *state)
1084{
Chia-I Wue6073342014-11-30 09:43:42 +08001085 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001086 const uint8_t cmd_len = 3;
1087
1088 CMD_ASSERT(cmd, 6, 7.5);
1089 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1090
Chia-I Wu00b51a82014-09-09 12:07:37 +08001091 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1092 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001093}
1094
Chia-I Wu72292b72014-09-09 10:48:33 +08001095static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001096 uint32_t stencil_ref,
1097 const uint32_t blend_color[4])
1098{
Chia-I Wue6073342014-11-30 09:43:42 +08001099 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001100 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001101 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001102
1103 CMD_ASSERT(cmd, 6, 7.5);
1104
Chia-I Wu00b51a82014-09-09 12:07:37 +08001105 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1106 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001107 dw[0] = stencil_ref;
1108 dw[1] = 0;
1109 dw[2] = blend_color[0];
1110 dw[3] = blend_color[1];
1111 dw[4] = blend_color[2];
1112 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001113
Chia-I Wu72292b72014-09-09 10:48:33 +08001114 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001115}
1116
Chia-I Wu8370b402014-08-29 12:28:37 +08001117static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001118{
Chia-I Wu8370b402014-08-29 12:28:37 +08001119 CMD_ASSERT(cmd, 6, 7.5);
1120
Chia-I Wu707a29e2014-08-27 12:51:47 +08001121 if (!cmd->bind.draw_count)
1122 return;
1123
Chia-I Wu8370b402014-08-29 12:28:37 +08001124 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001125 return;
1126
Chia-I Wu8370b402014-08-29 12:28:37 +08001127 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001128
1129 /*
1130 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1131 *
1132 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1133 * pipe-control with a post-sync op and no write-cache flushes."
1134 *
1135 * The workaround below necessitates this workaround.
1136 */
1137 gen6_PIPE_CONTROL(cmd,
1138 GEN6_PIPE_CONTROL_CS_STALL |
1139 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001140 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001141
Chia-I Wud6d079d2014-08-31 13:14:21 +08001142 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1143 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001144}
1145
Chia-I Wu8370b402014-08-29 12:28:37 +08001146static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001147{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001148 CMD_ASSERT(cmd, 6, 7.5);
1149
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001150 if (!cmd->bind.draw_count)
1151 return;
1152
Chia-I Wud6d079d2014-08-31 13:14:21 +08001153 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1154 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001155}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001156
Chia-I Wu8370b402014-08-29 12:28:37 +08001157static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1158{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001159 CMD_ASSERT(cmd, 7, 7.5);
1160
Chia-I Wu8370b402014-08-29 12:28:37 +08001161 if (!cmd->bind.draw_count)
1162 return;
1163
1164 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001165
1166 gen6_PIPE_CONTROL(cmd,
1167 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001168 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001169}
1170
Chia-I Wu8370b402014-08-29 12:28:37 +08001171static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1172{
1173 CMD_ASSERT(cmd, 7, 7.5);
1174
1175 if (!cmd->bind.draw_count)
1176 return;
1177
1178 /*
1179 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1180 *
1181 * "One of the following must also be set (when CS stall is set):
1182 *
1183 * * Render Target Cache Flush Enable ([12] of DW1)
1184 * * Depth Cache Flush Enable ([0] of DW1)
1185 * * Stall at Pixel Scoreboard ([1] of DW1)
1186 * * Depth Stall ([13] of DW1)
1187 * * Post-Sync Operation ([13] of DW1)"
1188 */
1189 gen6_PIPE_CONTROL(cmd,
1190 GEN6_PIPE_CONTROL_CS_STALL |
1191 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001192 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001193}
1194
1195static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1196{
1197 CMD_ASSERT(cmd, 7, 7.5);
1198
1199 if (!cmd->bind.draw_count)
1200 return;
1201
1202 cmd_wa_gen6_pre_depth_stall_write(cmd);
1203
Chia-I Wud6d079d2014-08-31 13:14:21 +08001204 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001205}
1206
1207static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1208{
1209 CMD_ASSERT(cmd, 6, 7.5);
1210
1211 if (!cmd->bind.draw_count)
1212 return;
1213
1214 /*
1215 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1216 *
1217 * "Driver must guarentee that all the caches in the depth pipe are
1218 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1219 * requires driver to send a PIPE_CONTROL with a CS stall along with
1220 * a Depth Flush prior to this command."
1221 *
1222 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1223 *
1224 * "Driver must ierarchi that all the caches in the depth pipe are
1225 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1226 * requires driver to send a PIPE_CONTROL with a CS stall along with
1227 * a Depth Flush prior to this command.
1228 */
1229 gen6_PIPE_CONTROL(cmd,
1230 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1231 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001232 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001233}
1234
1235static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1236{
1237 CMD_ASSERT(cmd, 6, 7.5);
1238
1239 if (!cmd->bind.draw_count)
1240 return;
1241
1242 /*
1243 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1244 *
1245 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1246 * and a post sync operation prior to the group of depth
1247 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1248 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1249 *
1250 * This workaround satifies all the conditions.
1251 */
1252 cmd_wa_gen6_pre_depth_stall_write(cmd);
1253
1254 /*
1255 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1256 *
1257 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1258 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1259 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1260 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1261 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1262 * Depth Flush Bit set, followed by another pipelined depth stall
1263 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1264 * guarantee that the pipeline from WM onwards is already flushed
1265 * (e.g., via a preceding MI_FLUSH)."
1266 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001267 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1268 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1269 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001270}
1271
Chia-I Wu525c6602014-08-27 10:22:34 +08001272void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1273{
1274 if (!cmd->bind.draw_count)
1275 return;
1276
1277 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1278
Chia-I Wu8370b402014-08-29 12:28:37 +08001279 /*
1280 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1281 *
1282 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1283 * PIPE_CONTROL with any non-zero post-sync-op is required."
1284 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001285 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001286 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001287
Chia-I Wu092279a2014-08-30 19:05:30 +08001288 /*
1289 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1290 *
1291 * "One of the following must also be set (when CS stall is set):
1292 *
1293 * * Render Target Cache Flush Enable ([12] of DW1)
1294 * * Depth Cache Flush Enable ([0] of DW1)
1295 * * Stall at Pixel Scoreboard ([1] of DW1)
1296 * * Depth Stall ([13] of DW1)
1297 * * Post-Sync Operation ([13] of DW1)"
1298 */
1299 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1300 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1301 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1302 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1303 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1304 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1305
Chia-I Wud6d079d2014-08-31 13:14:21 +08001306 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001307}
1308
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001309void cmd_batch_flush_all(struct intel_cmd *cmd)
1310{
1311 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1312 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1313 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1314 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1315 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1316 GEN6_PIPE_CONTROL_CS_STALL);
1317}
1318
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001319void cmd_batch_depth_count(struct intel_cmd *cmd,
1320 struct intel_bo *bo,
1321 XGL_GPU_SIZE offset)
1322{
1323 cmd_wa_gen6_pre_depth_stall_write(cmd);
1324
1325 gen6_PIPE_CONTROL(cmd,
1326 GEN6_PIPE_CONTROL_DEPTH_STALL |
1327 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001328 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001329}
1330
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001331void cmd_batch_timestamp(struct intel_cmd *cmd,
1332 struct intel_bo *bo,
1333 XGL_GPU_SIZE offset)
1334{
1335 /* need any WA or stall? */
1336 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1337}
1338
1339void cmd_batch_immediate(struct intel_cmd *cmd,
1340 struct intel_bo *bo,
1341 XGL_GPU_SIZE offset,
1342 uint64_t val)
1343{
1344 /* need any WA or stall? */
1345 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1346}
1347
Chia-I Wu302742d2014-08-22 10:28:29 +08001348static void gen6_cc_states(struct intel_cmd *cmd)
1349{
1350 const struct intel_blend_state *blend = cmd->bind.state.blend;
1351 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001352 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001353 uint32_t stencil_ref;
1354 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001355
1356 CMD_ASSERT(cmd, 6, 6);
1357
Chia-I Wua6c4f152014-12-02 04:19:58 +08001358 blend_offset = gen6_BLEND_STATE(cmd);
1359
1360 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001361 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001362 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001363 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001364
1365 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001366 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001367 stencil_ref = ds->cmd_stencil_ref;
1368 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001369 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001370 stencil_ref = 0;
1371 }
1372
Chia-I Wu72292b72014-09-09 10:48:33 +08001373 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001374
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001376}
1377
Chia-I Wu1744cca2014-08-22 11:10:17 +08001378static void gen6_viewport_states(struct intel_cmd *cmd)
1379{
1380 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001382
1383 if (!viewport)
1384 return;
1385
Chia-I Wub1d450a2014-09-09 13:48:03 +08001386 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1387 viewport->viewport_count);
1388
1389 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001390 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001391 viewport->cmd);
1392
1393 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001394 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001395 &viewport->cmd[viewport->cmd_clip_pos]);
1396
1397 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001398 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 &viewport->cmd[viewport->cmd_cc_pos]);
1400
1401 if (viewport->scissor_enable) {
1402 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001403 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001404 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1405 } else {
1406 scissor_offset = 0;
1407 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001408
1409 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001411
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001413}
1414
Chia-I Wu302742d2014-08-22 10:28:29 +08001415static void gen7_cc_states(struct intel_cmd *cmd)
1416{
1417 const struct intel_blend_state *blend = cmd->bind.state.blend;
1418 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001419 uint32_t stencil_ref;
1420 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001421 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001422
1423 CMD_ASSERT(cmd, 7, 7.5);
1424
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001425 if (!blend && !ds)
1426 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001427
Chia-I Wua6c4f152014-12-02 04:19:58 +08001428 offset = gen6_BLEND_STATE(cmd);
1429 gen7_3dstate_pointer(cmd,
1430 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001431
Chia-I Wua6c4f152014-12-02 04:19:58 +08001432 if (blend)
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001433 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001434 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001435 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001436
1437 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001438 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001439 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001440 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1441 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001442 } else {
1443 stencil_ref = 0;
1444 }
1445
Chia-I Wu72292b72014-09-09 10:48:33 +08001446 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001447 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001448 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001449}
1450
Chia-I Wu1744cca2014-08-22 11:10:17 +08001451static void gen7_viewport_states(struct intel_cmd *cmd)
1452{
1453 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001454 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001455
1456 if (!viewport)
1457 return;
1458
Chia-I Wub1d450a2014-09-09 13:48:03 +08001459 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1460 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001461
Chia-I Wub1d450a2014-09-09 13:48:03 +08001462 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001463 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001464 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001465 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001466 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1467 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001468
1469 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001470 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001471 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001472 gen7_3dstate_pointer(cmd,
1473 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001474 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001475
Chia-I Wu1744cca2014-08-22 11:10:17 +08001476 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001477 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001478 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001479 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001480 gen7_3dstate_pointer(cmd,
1481 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001482 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001483 }
1484}
1485
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001486static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001487 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001488{
1489 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001490 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001491
Chia-I Wu72292b72014-09-09 10:48:33 +08001492 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001493
1494 dw[0] = GEN6_RENDER_TYPE_RENDER |
1495 GEN6_RENDER_SUBTYPE_3D |
1496 subop | (cmd_len - 2);
1497 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001498 dw[2] = 0;
1499 dw[3] = 0;
1500 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001501}
1502
1503static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001504 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001505{
1506 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001507 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001508
Chia-I Wu72292b72014-09-09 10:48:33 +08001509 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001510
1511 dw[0] = GEN6_RENDER_TYPE_RENDER |
1512 GEN6_RENDER_SUBTYPE_3D |
1513 subop | (cmd_len - 2);
1514 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001515 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001516 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001517 dw[4] = 0;
1518 dw[5] = 0;
1519 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001520}
1521
Chia-I Wu625105f2014-10-13 15:35:29 +08001522static uint32_t emit_samplers(struct intel_cmd *cmd,
1523 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001524{
1525 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1526 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001527 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001528 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001529 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001530 XGL_UINT i;
1531
1532 CMD_ASSERT(cmd, 6, 7.5);
1533
Chia-I Wu625105f2014-10-13 15:35:29 +08001534 if (!rmap || !rmap->sampler_count)
1535 return 0;
1536
1537 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1538
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001539 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001540 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001541 border_stride * rmap->sampler_count, &border_dw);
1542
1543 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001544 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001545 4 * rmap->sampler_count, &sampler_dw);
1546
1547 for (i = 0; i < rmap->sampler_count; i++) {
1548 const struct intel_pipeline_rmap_slot *slot =
1549 &rmap->slots[surface_count + i];
1550 const struct intel_sampler *sampler;
1551
1552 switch (slot->path_len) {
1553 case 0:
1554 sampler = NULL;
1555 break;
1556 case INTEL_PIPELINE_RMAP_SLOT_RT:
1557 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1558 assert(!"unexpected rmap slot type");
1559 sampler = NULL;
1560 break;
1561 case 1:
1562 {
1563 const struct intel_dset *dset = cmd->bind.dset.graphics;
1564 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1565 const struct intel_dset_slot *dset_slot =
1566 &dset->slots[slot_offset + slot->u.index];
1567
1568 switch (dset_slot->type) {
1569 case INTEL_DSET_SLOT_SAMPLER:
1570 sampler = dset_slot->u.sampler;
1571 break;
1572 default:
1573 assert(!"unexpected dset slot type");
1574 sampler = NULL;
1575 break;
1576 }
1577 }
1578 break;
1579 default:
1580 assert(!"nested descriptor set unsupported");
1581 sampler = NULL;
1582 break;
1583 }
1584
1585 if (sampler) {
1586 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1587
1588 sampler_dw[0] = sampler->cmd[0];
1589 sampler_dw[1] = sampler->cmd[1];
1590 sampler_dw[2] = border_offset;
1591 sampler_dw[3] = sampler->cmd[2];
1592 } else {
1593 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1594 sampler_dw[1] = 0;
1595 sampler_dw[2] = 0;
1596 sampler_dw[3] = 0;
1597 }
1598
1599 border_offset += border_stride * 4;
1600 border_dw += border_stride;
1601 sampler_dw += 4;
1602 }
1603
Chia-I Wu625105f2014-10-13 15:35:29 +08001604 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001605}
1606
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001607static uint32_t emit_binding_table(struct intel_cmd *cmd,
1608 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001609{
Chia-I Wu72292b72014-09-09 10:48:33 +08001610 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001611 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001612
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001613 CMD_ASSERT(cmd, 6, 7.5);
1614
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001615 surface_count = (rmap) ?
1616 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1617 if (!surface_count)
1618 return 0;
1619
Chia-I Wu42a56202014-08-23 16:47:48 +08001620 assert(surface_count <= ARRAY_SIZE(binding_table));
1621
1622 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001623 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001624
1625 switch (slot->path_len) {
1626 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001627 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001628 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001629 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001630 {
1631 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1632
Chia-I Wu00b51a82014-09-09 12:07:37 +08001633 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001634 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001635 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001636
Chia-I Wu72292b72014-09-09 10:48:33 +08001637 cmd_reserve_reloc(cmd, 1);
1638 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1639 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001640 }
1641 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001642 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001643 {
1644 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001645 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001646
Chia-I Wu00b51a82014-09-09 12:07:37 +08001647 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001648 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001649 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001650
Chia-I Wu72292b72014-09-09 10:48:33 +08001651 cmd_reserve_reloc(cmd, 1);
1652 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1653 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001654 }
1655 break;
1656 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001657 {
1658 const struct intel_dset *dset = cmd->bind.dset.graphics;
1659 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1660 const struct intel_dset_slot *dset_slot =
1661 &dset->slots[slot_offset + slot->u.index];
Chia-I Wu55dffd32014-11-25 11:18:44 +08001662 const uint32_t reloc_flags =
1663 (dset_slot->read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001664
1665 switch (dset_slot->type) {
1666 case INTEL_DSET_SLOT_IMG_VIEW:
1667 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001668 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001669 dset_slot->u.img_view->cmd_len,
1670 dset_slot->u.img_view->cmd);
1671
1672 cmd_reserve_reloc(cmd, 1);
1673 cmd_surface_reloc(cmd, offset, 1,
1674 dset_slot->u.img_view->img->obj.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001675 dset_slot->u.img_view->cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001676 break;
1677 case INTEL_DSET_SLOT_MEM_VIEW:
1678 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001679 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001680 dset_slot->u.mem_view.cmd_len,
1681 dset_slot->u.mem_view.cmd);
1682
1683 cmd_reserve_reloc(cmd, 1);
1684 cmd_surface_reloc(cmd, offset, 1,
1685 dset_slot->u.mem_view.mem->bo,
Chia-I Wu55dffd32014-11-25 11:18:44 +08001686 dset_slot->u.mem_view.cmd[1], reloc_flags);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001687 break;
Cody Northrop47b12182014-10-06 15:41:18 -06001688 case INTEL_DSET_SLOT_SAMPLER:
1689 assert(0 == cmd->bind.dset.graphics_offset);
1690
1691 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001692 GEN6_ALIGNMENT_SURFACE_STATE,
Cody Northrop47b12182014-10-06 15:41:18 -06001693 16, dset_slot->u.sampler->cmd);
1694 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001695 default:
1696 assert(!"unexpected dset slot type");
1697 break;
1698 }
1699 }
1700 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001701 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001702 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001703 break;
1704 }
1705
Chia-I Wu72292b72014-09-09 10:48:33 +08001706 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001707 }
1708
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001709 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001710 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001711 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001712}
1713
Chia-I Wu1d125092014-10-08 08:49:38 +08001714static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1715{
1716 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001717 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1718 uint32_t *dw;
1719 XGL_UINT pos, i;
1720
1721 CMD_ASSERT(cmd, 6, 7.5);
1722
1723 if (!pipeline->vb_count)
1724 return;
1725
1726 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1727
1728 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1729 dw++;
1730 pos++;
1731
1732 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001733 assert(pipeline->vb[i].strideInBytes <= 2048);
1734
1735 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1736 pipeline->vb[i].strideInBytes;
1737
1738 if (cmd_gen(cmd) >= INTEL_GEN(7))
1739 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1740
1741 switch (pipeline->vb[i].stepRate) {
1742 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1743 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1744 dw[3] = 0;
1745 break;
1746 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1747 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1748 dw[3] = 1;
1749 break;
1750 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1751 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1752 dw[3] = 0;
1753 break;
1754 default:
1755 assert(!"unknown step rate");
1756 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1757 dw[3] = 0;
1758 break;
1759 }
1760
Chia-I Wu3b04af52014-11-08 10:48:20 +08001761 if (cmd->bind.vertex.mem[i]) {
1762 const struct intel_mem *mem = cmd->bind.vertex.mem[i];
1763 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001764
1765 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3b04af52014-11-08 10:48:20 +08001766 cmd_batch_reloc(cmd, pos + 1, mem->bo, offset, 0);
1767 cmd_batch_reloc(cmd, pos + 2, mem->bo, mem->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001768 } else {
1769 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1770 dw[1] = 0;
1771 dw[2] = 0;
1772 }
1773
1774 dw += 4;
1775 pos += 4;
1776 }
1777}
1778
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001779static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1780{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001781 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1782 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wu05990612014-11-25 11:36:35 +08001783 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001784 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001785 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001786 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu05990612014-11-25 11:36:35 +08001787 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001788
1789 CMD_ASSERT(cmd, 6, 7.5);
1790
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001791 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001792 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1793 *
1794 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1795 * 128-bit vertex elements to be passed into the payload for each
1796 * vertex."
1797 *
1798 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1799 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001800 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001801 vue_read_len = (vs->in_count + 1) / 2;
1802 if (!vue_read_len)
1803 vue_read_len = 1;
1804
1805 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1806 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1807
1808 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1809 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1810 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001811
1812 dw5 = GEN6_VS_DW5_STATISTICS |
1813 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001814
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001815 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1816 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1817 else
1818 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1819
Chia-I Wube0a3d92014-09-02 13:20:59 +08001820 if (pipeline->disable_vs_cache)
1821 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1822
Chia-I Wu72292b72014-09-09 10:48:33 +08001823 cmd_batch_pointer(cmd, cmd_len, &dw);
1824 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001825 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001826 dw[2] = dw2;
1827 dw[3] = 0; /* scratch */
1828 dw[4] = dw4;
1829 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001830}
1831
Chia-I Wu625105f2014-10-13 15:35:29 +08001832static void emit_shader_resources(struct intel_cmd *cmd)
1833{
1834 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001835 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001836
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001837 binding_tables[0] = emit_binding_table(cmd,
1838 cmd->bind.pipeline.graphics->vs.rmap);
1839 binding_tables[1] = emit_binding_table(cmd,
1840 cmd->bind.pipeline.graphics->tcs.rmap);
1841 binding_tables[2] = emit_binding_table(cmd,
1842 cmd->bind.pipeline.graphics->tes.rmap);
1843 binding_tables[3] = emit_binding_table(cmd,
1844 cmd->bind.pipeline.graphics->gs.rmap);
1845 binding_tables[4] = emit_binding_table(cmd,
1846 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001847
1848 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1849 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1850 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1851 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1852 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1853
1854 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1855 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001856 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1857 binding_tables[0]);
1858 gen7_3dstate_pointer(cmd,
1859 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1860 binding_tables[1]);
1861 gen7_3dstate_pointer(cmd,
1862 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1863 binding_tables[2]);
1864 gen7_3dstate_pointer(cmd,
1865 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1866 binding_tables[3]);
1867 gen7_3dstate_pointer(cmd,
1868 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1869 binding_tables[4]);
1870
1871 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001872 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1873 samplers[0]);
1874 gen7_3dstate_pointer(cmd,
1875 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1876 samplers[1]);
1877 gen7_3dstate_pointer(cmd,
1878 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1879 samplers[2]);
1880 gen7_3dstate_pointer(cmd,
1881 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1882 samplers[3]);
1883 gen7_3dstate_pointer(cmd,
1884 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1885 samplers[4]);
1886 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001887 assert(!binding_tables[1] && !binding_tables[2]);
1888 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1889 binding_tables[0], binding_tables[3], binding_tables[4]);
1890
Chia-I Wu625105f2014-10-13 15:35:29 +08001891 assert(!samplers[1] && !samplers[2]);
1892 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1893 samplers[0], samplers[3], samplers[4]);
1894 }
1895}
1896
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001897static void emit_rt(struct intel_cmd *cmd)
1898{
1899 cmd_wa_gen6_pre_depth_stall_write(cmd);
1900 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1901 cmd->bind.att.height);
1902}
1903
1904static void emit_ds(struct intel_cmd *cmd)
1905{
1906 const struct intel_ds_view *ds = cmd->bind.att.ds;
1907
1908 if (!ds) {
1909 /* all zeros */
1910 static const struct intel_ds_view null_ds;
1911 ds = &null_ds;
1912 }
1913
1914 cmd_wa_gen6_pre_ds_flush(cmd);
1915 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1916 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1917 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1918
1919 if (cmd_gen(cmd) >= INTEL_GEN(7))
1920 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1921 else
1922 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1923}
1924
Chia-I Wua57761b2014-10-14 14:27:44 +08001925static uint32_t emit_shader(struct intel_cmd *cmd,
1926 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001927{
Chia-I Wua57761b2014-10-14 14:27:44 +08001928 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1929 uint32_t offset;
1930 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001931
Chia-I Wua57761b2014-10-14 14:27:44 +08001932 /* see if the shader is already in the cache */
1933 for (i = 0; i < cache->used; i++) {
1934 if (cache->entries[i].shader == (const void *) shader)
1935 return cache->entries[i].kernel_offset;
1936 }
1937
1938 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1939
1940 /* grow the cache if full */
1941 if (cache->used >= cache->count) {
1942 const XGL_UINT count = cache->count + 16;
1943 void *entries;
1944
1945 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1946 XGL_SYSTEM_ALLOC_INTERNAL);
1947 if (entries) {
1948 if (cache->entries) {
1949 memcpy(entries, cache->entries,
1950 sizeof(cache->entries[0]) * cache->used);
1951 icd_free(cache->entries);
1952 }
1953
1954 cache->entries = entries;
1955 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001956 }
1957 }
1958
Chia-I Wua57761b2014-10-14 14:27:44 +08001959 /* add the shader to the cache */
1960 if (cache->used < cache->count) {
1961 cache->entries[cache->used].shader = (const void *) shader;
1962 cache->entries[cache->used].kernel_offset = offset;
1963 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001964 }
1965
Chia-I Wua57761b2014-10-14 14:27:44 +08001966 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001967}
1968
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001969static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001970{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001971 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001972
Chia-I Wu8370b402014-08-29 12:28:37 +08001973 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1974 cmd_wa_gen6_pre_depth_stall_write(cmd);
1975 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1976 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1977 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1978 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001979
1980 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001981 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001982 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001983
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001984 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001985 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001986 }
1987 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001988 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001989 }
1990 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001991 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1992 }
1993 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1994 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1995 }
1996 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1997 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001998 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001999
Chia-I Wud95aa2b2014-08-29 12:07:47 +08002000 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2001 gen7_3DSTATE_GS(cmd);
2002 } else {
2003 gen6_3DSTATE_GS(cmd);
2004 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06002005
Chia-I Wu8370b402014-08-29 12:28:37 +08002006 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2007 cmd_wa_gen7_post_command_cs_stall(cmd);
2008 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2009 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002010}
2011
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002012static void emit_bounded_states(struct intel_cmd *cmd)
2013{
2014 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
2015
2016 emit_graphics_pipeline(cmd);
2017
2018 emit_rt(cmd);
2019 emit_ds(cmd);
2020
2021 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2022 gen7_cc_states(cmd);
2023 gen7_viewport_states(cmd);
2024
2025 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2026 &cmd->bind.pipeline.graphics->vs);
2027 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2028 &cmd->bind.pipeline.graphics->fs);
2029
2030 gen6_3DSTATE_CLIP(cmd);
2031 gen7_3DSTATE_SF(cmd);
2032 gen7_3DSTATE_SBE(cmd);
2033 gen7_3DSTATE_WM(cmd);
2034 gen7_3DSTATE_PS(cmd);
2035 } else {
2036 gen6_cc_states(cmd);
2037 gen6_viewport_states(cmd);
2038
2039 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2040 &cmd->bind.pipeline.graphics->vs);
2041 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2042 &cmd->bind.pipeline.graphics->fs);
2043
2044 gen6_3DSTATE_CLIP(cmd);
2045 gen6_3DSTATE_SF(cmd);
2046 gen6_3DSTATE_WM(cmd);
2047 }
2048
2049 emit_shader_resources(cmd);
2050
2051 cmd_wa_gen6_pre_depth_stall_write(cmd);
2052 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2053
2054 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
2055 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
2056
2057 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2058 gen6_3DSTATE_VS(cmd);
2059}
2060
Chia-I Wu6032b892014-10-17 14:47:18 +08002061static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2062{
2063 const struct intel_cmd_meta *meta = cmd->bind.meta;
2064 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2065
2066 CMD_ASSERT(cmd, 6, 7.5);
2067
2068 blend_offset = 0;
2069 ds_offset = 0;
2070 cc_offset = 0;
2071 cc_vp_offset = 0;
2072
Chia-I Wu29e6f502014-11-24 14:27:29 +08002073 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002074 /* BLEND_STATE */
2075 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002076 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002077 dw[0] = 0;
2078 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2079 }
2080
Chia-I Wu29e6f502014-11-24 14:27:29 +08002081 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2082 if (meta->ds.state) {
2083 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002084
Chia-I Wu29e6f502014-11-24 14:27:29 +08002085 /* DEPTH_STENCIL_STATE */
2086 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002087
Chia-I Wu29e6f502014-11-24 14:27:29 +08002088 /* COLOR_CALC_STATE */
2089 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2090 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002091
Chia-I Wu29e6f502014-11-24 14:27:29 +08002092 /* CC_VIEWPORT */
2093 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002094 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002095 dw[0] = u_fui(0.0f);
2096 dw[1] = u_fui(1.0f);
2097 } else {
2098 /* DEPTH_STENCIL_STATE */
2099 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002100 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002101 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2102 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2103 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002104 }
2105
2106 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2107 gen7_3dstate_pointer(cmd,
2108 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2109 blend_offset);
2110 gen7_3dstate_pointer(cmd,
2111 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2112 ds_offset);
2113 gen7_3dstate_pointer(cmd,
2114 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2115
2116 gen7_3dstate_pointer(cmd,
2117 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2118 cc_vp_offset);
2119 } else {
2120 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002121 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002122
2123 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2124 cmd_batch_pointer(cmd, 4, &dw);
2125 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2126 GEN6_PTR_VP_DW0_CC_CHANGED;
2127 dw[1] = 0;
2128 dw[2] = 0;
2129 dw[3] = cc_vp_offset;
2130 }
2131}
2132
2133static void gen6_meta_surface_states(struct intel_cmd *cmd)
2134{
2135 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002136 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002137 uint32_t offset;
2138
2139 CMD_ASSERT(cmd, 6, 7.5);
2140
Chia-I Wu29e6f502014-11-24 14:27:29 +08002141 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2142 return;
2143
Chia-I Wu005c47c2014-10-22 13:49:13 +08002144 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002145 if (meta->src.valid) {
2146 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002147 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002148 meta->src.surface_len, meta->src.surface);
2149
2150 cmd_reserve_reloc(cmd, 1);
2151 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2152 cmd_surface_reloc_writer(cmd, offset, 1,
2153 meta->src.reloc_target, meta->src.reloc_offset);
2154 } else {
2155 cmd_surface_reloc(cmd, offset, 1,
2156 (struct intel_bo *) meta->src.reloc_target,
2157 meta->src.reloc_offset, meta->src.reloc_flags);
2158 }
2159
Chia-I Wu005c47c2014-10-22 13:49:13 +08002160 binding_table[0] = offset;
2161 }
2162 if (meta->dst.valid) {
2163 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002164 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002165 meta->dst.surface_len, meta->dst.surface);
2166
2167 cmd_reserve_reloc(cmd, 1);
2168 cmd_surface_reloc(cmd, offset, 1,
2169 (struct intel_bo *) meta->dst.reloc_target,
2170 meta->dst.reloc_offset, meta->dst.reloc_flags);
2171
2172 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002173 }
2174
2175 /* BINDING_TABLE */
2176 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002177 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002178 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002179
2180 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002181 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2182 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2183 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2184 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002185 } else {
2186 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002187 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2188 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2189 else
2190 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002191 }
2192}
2193
2194static void gen6_meta_urb(struct intel_cmd *cmd)
2195{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002196 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002197 uint32_t *dw;
2198
2199 CMD_ASSERT(cmd, 6, 6);
2200
2201 /* 3DSTATE_URB */
2202 cmd_batch_pointer(cmd, 3, &dw);
2203 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002204 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002205 dw[2] = 0;
2206}
2207
2208static void gen7_meta_urb(struct intel_cmd *cmd)
2209{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002210 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002211 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002212 uint32_t *dw;
2213
2214 CMD_ASSERT(cmd, 7, 7.5);
2215
2216 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2217 cmd_batch_pointer(cmd, 10, &dw);
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002220 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002221 dw += 2;
2222
2223 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2224 dw[1] = 0;
2225 dw += 2;
2226
2227 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2228 dw[1] = 0;
2229 dw += 2;
2230
2231 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2232 dw[1] = 0;
2233 dw += 2;
2234
2235 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002236 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002237
2238 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2239
Chia-I Wu24aa1022014-11-25 11:53:19 +08002240 switch (cmd_gen(cmd)) {
2241 case INTEL_GEN(7.5):
2242 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2243 break;
2244 case INTEL_GEN(7):
2245 default:
2246 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2247 break;
2248 }
2249
Chia-I Wu6032b892014-10-17 14:47:18 +08002250 /* 3DSTATE_URB_x */
2251 cmd_batch_pointer(cmd, 8, &dw);
2252
2253 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2254 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002255 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002256 dw += 2;
2257
2258 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2259 dw[1] = 0;
2260 dw += 2;
2261
2262 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2263 dw[1] = 0;
2264 dw += 2;
2265
2266 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2267 dw[1] = 0;
2268 dw += 2;
2269}
2270
2271static void gen6_meta_vf(struct intel_cmd *cmd)
2272{
2273 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002274 uint32_t vb_start, vb_end, vb_stride;
2275 int ve_format, ve_z_source;
2276 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002277 XGL_UINT pos;
2278
2279 CMD_ASSERT(cmd, 6, 7.5);
2280
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 switch (meta->mode) {
2282 case INTEL_CMD_META_VS_POINTS:
2283 cmd_batch_pointer(cmd, 3, &dw);
2284 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2285 dw[1] = GEN6_VE_STATE_DW0_VALID;
2286 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2287 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2288 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2289 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2290 return;
2291 break;
2292 case INTEL_CMD_META_FS_RECT:
2293 {
2294 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002295
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 vertices[0][0] = meta->dst.x + meta->width;
2297 vertices[0][1] = meta->dst.y + meta->height;
2298 vertices[1][0] = meta->dst.x;
2299 vertices[1][1] = meta->dst.y + meta->height;
2300 vertices[2][0] = meta->dst.x;
2301 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002302
Chia-I Wu29e6f502014-11-24 14:27:29 +08002303 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2304 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305
Chia-I Wu29e6f502014-11-24 14:27:29 +08002306 vb_end = vb_start + sizeof(vertices) - 1;
2307 vb_stride = sizeof(vertices[0]);
2308 ve_z_source = GEN6_VFCOMP_STORE_0;
2309 ve_format = GEN6_FORMAT_R32G32_USCALED;
2310 }
2311 break;
2312 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2313 {
2314 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002315
Chia-I Wu29e6f502014-11-24 14:27:29 +08002316 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2317 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2318 vertices[0][2] = u_uif(meta->clear_val[0]);
2319 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2320 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2321 vertices[1][2] = u_uif(meta->clear_val[0]);
2322 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2323 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2324 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002325
Chia-I Wu29e6f502014-11-24 14:27:29 +08002326 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2327 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002328
Chia-I Wu29e6f502014-11-24 14:27:29 +08002329 vb_end = vb_start + sizeof(vertices) - 1;
2330 vb_stride = sizeof(vertices[0]);
2331 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2332 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2333 }
2334 break;
2335 default:
2336 assert(!"unknown meta mode");
2337 return;
2338 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002339 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002340
2341 /* 3DSTATE_VERTEX_BUFFERS */
2342 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002343
Chia-I Wu6032b892014-10-17 14:47:18 +08002344 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002345 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002346 if (cmd_gen(cmd) >= INTEL_GEN(7))
2347 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2348
2349 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002350 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2351 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002352
2353 dw[4] = 0;
2354
2355 /* 3DSTATE_VERTEX_ELEMENTS */
2356 cmd_batch_pointer(cmd, 5, &dw);
2357 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002358 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002359 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2360 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2361 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2362 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2363 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002364 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002365 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2366 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002367 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002368 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2369}
2370
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002372{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002373 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002374 /* one GPR */
2375 XGL_UINT consts[8];
2376 XGL_UINT const_count;
2377
2378 CMD_ASSERT(cmd, 6, 7.5);
2379
2380 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002381 case INTEL_DEV_META_VS_FILL_MEM:
2382 consts[0] = meta->dst.x;
2383 consts[1] = meta->clear_val[0];
2384 const_count = 2;
2385 break;
2386 case INTEL_DEV_META_VS_COPY_MEM:
2387 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2388 consts[0] = meta->dst.x;
2389 consts[1] = meta->src.x;
2390 const_count = 2;
2391 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002392 default:
2393 assert(!"unknown meta shader id");
2394 const_count = 0;
2395 break;
2396 }
2397
2398 /* this can be skipped but it makes state dumping prettier */
2399 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2400
2401 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2402}
2403
2404static void gen6_meta_vs(struct intel_cmd *cmd)
2405{
2406 const struct intel_cmd_meta *meta = cmd->bind.meta;
2407 const struct intel_pipeline_shader *sh =
2408 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002409 const int max_threads = cmd_vs_max_threads(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002410 uint32_t offset, *dw;
2411
2412 CMD_ASSERT(cmd, 6, 7.5);
2413
2414 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2415 XGL_UINT cmd_len;
2416
2417 /* 3DSTATE_CONSTANT_VS */
2418 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2419 cmd_batch_pointer(cmd, cmd_len, &dw);
2420 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2421 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2422
2423 /* 3DSTATE_VS */
2424 cmd_batch_pointer(cmd, 6, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2426 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2427
2428 return;
2429 }
2430
2431 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2432
2433 /* 3DSTATE_CONSTANT_VS */
2434 offset = gen6_meta_vs_constants(cmd);
2435 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2436 cmd_batch_pointer(cmd, 7, &dw);
2437 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2438 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2439 dw[2] = 0;
2440 dw[3] = offset;
2441 dw[4] = 0;
2442 dw[5] = 0;
2443 dw[6] = 0;
2444 } else {
2445 cmd_batch_pointer(cmd, 5, &dw);
2446 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2447 GEN6_PCB_ANY_DW0_PCB0_VALID;
2448 dw[1] = offset;
2449 dw[2] = 0;
2450 dw[3] = 0;
2451 dw[4] = 0;
2452 }
2453
2454 /* 3DSTATE_VS */
2455 offset = emit_shader(cmd, sh);
2456 cmd_batch_pointer(cmd, 6, &dw);
2457 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2458 dw[1] = offset;
2459 dw[2] = GEN6_THREADDISP_SPF |
2460 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2461 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2462 dw[3] = 0;
2463 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2464 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2465
2466 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2467 GEN6_VS_DW5_VS_ENABLE;
2468 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu05990612014-11-25 11:36:35 +08002469 dw[5] |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002470 else
Chia-I Wu05990612014-11-25 11:36:35 +08002471 dw[5] |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472}
2473
2474static void gen6_meta_disabled(struct intel_cmd *cmd)
2475{
Chia-I Wu6032b892014-10-17 14:47:18 +08002476 uint32_t *dw;
2477
2478 CMD_ASSERT(cmd, 6, 6);
2479
Chia-I Wu6032b892014-10-17 14:47:18 +08002480 /* 3DSTATE_CONSTANT_GS */
2481 cmd_batch_pointer(cmd, 5, &dw);
2482 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2483 dw[1] = 0;
2484 dw[2] = 0;
2485 dw[3] = 0;
2486 dw[4] = 0;
2487
2488 /* 3DSTATE_GS */
2489 cmd_batch_pointer(cmd, 7, &dw);
2490 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2491 dw[1] = 0;
2492 dw[2] = 0;
2493 dw[3] = 0;
2494 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2495 dw[5] = GEN6_GS_DW5_STATISTICS;
2496 dw[6] = 0;
2497
Chia-I Wu6032b892014-10-17 14:47:18 +08002498 /* 3DSTATE_SF */
2499 cmd_batch_pointer(cmd, 20, &dw);
2500 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2501 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2502 memset(&dw[2], 0, 18 * sizeof(*dw));
2503}
2504
2505static void gen7_meta_disabled(struct intel_cmd *cmd)
2506{
2507 uint32_t *dw;
2508
2509 CMD_ASSERT(cmd, 7, 7.5);
2510
Chia-I Wu6032b892014-10-17 14:47:18 +08002511 /* 3DSTATE_CONSTANT_HS */
2512 cmd_batch_pointer(cmd, 7, &dw);
2513 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2514 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2515
2516 /* 3DSTATE_HS */
2517 cmd_batch_pointer(cmd, 7, &dw);
2518 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2520
2521 /* 3DSTATE_TE */
2522 cmd_batch_pointer(cmd, 4, &dw);
2523 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2525
2526 /* 3DSTATE_CONSTANT_DS */
2527 cmd_batch_pointer(cmd, 7, &dw);
2528 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2529 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2530
2531 /* 3DSTATE_DS */
2532 cmd_batch_pointer(cmd, 6, &dw);
2533 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2534 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2535
2536 /* 3DSTATE_CONSTANT_GS */
2537 cmd_batch_pointer(cmd, 7, &dw);
2538 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2539 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2540
2541 /* 3DSTATE_GS */
2542 cmd_batch_pointer(cmd, 7, &dw);
2543 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2544 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2545
2546 /* 3DSTATE_STREAMOUT */
2547 cmd_batch_pointer(cmd, 3, &dw);
2548 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2549 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2550
Chia-I Wu6032b892014-10-17 14:47:18 +08002551 /* 3DSTATE_SF */
2552 cmd_batch_pointer(cmd, 7, &dw);
2553 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2554 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2555
2556 /* 3DSTATE_SBE */
2557 cmd_batch_pointer(cmd, 14, &dw);
2558 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2559 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2560 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002561}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002562
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563static void gen6_meta_clip(struct intel_cmd *cmd)
2564{
2565 const struct intel_cmd_meta *meta = cmd->bind.meta;
2566 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002567
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568 /* 3DSTATE_CLIP */
2569 cmd_batch_pointer(cmd, 4, &dw);
2570 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2571 dw[1] = 0;
2572 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2573 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2574 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2575 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002576 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002577 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002578 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002579}
2580
2581static void gen6_meta_wm(struct intel_cmd *cmd)
2582{
2583 const struct intel_cmd_meta *meta = cmd->bind.meta;
2584 uint32_t *dw;
2585
2586 CMD_ASSERT(cmd, 6, 7.5);
2587
2588 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2589
2590 /* 3DSTATE_MULTISAMPLE */
2591 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2592 cmd_batch_pointer(cmd, 4, &dw);
2593 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2594 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2595 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2596 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2597 dw[2] = 0;
2598 dw[3] = 0;
2599 } else {
2600 cmd_batch_pointer(cmd, 3, &dw);
2601 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2602 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2603 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2604 dw[2] = 0;
2605 }
2606
2607 /* 3DSTATE_SAMPLE_MASK */
2608 cmd_batch_pointer(cmd, 2, &dw);
2609 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2610 dw[1] = (1 << meta->samples) - 1;
2611
2612 /* 3DSTATE_DRAWING_RECTANGLE */
2613 cmd_batch_pointer(cmd, 4, &dw);
2614 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2615 dw[1] = meta->dst.y << 16 | meta->dst.x;
2616 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2617 (meta->dst.x + meta->width - 1);
2618 dw[3] = 0;
2619}
2620
2621static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2622{
2623 const struct intel_cmd_meta *meta = cmd->bind.meta;
2624 XGL_UINT offset_x, offset_y;
2625 /* one GPR */
2626 XGL_UINT consts[8];
2627 XGL_UINT const_count;
2628
2629 CMD_ASSERT(cmd, 6, 7.5);
2630
2631 /* underflow is fine here */
2632 offset_x = meta->src.x - meta->dst.x;
2633 offset_y = meta->src.y - meta->dst.y;
2634
2635 switch (meta->shader_id) {
2636 case INTEL_DEV_META_FS_COPY_MEM:
2637 case INTEL_DEV_META_FS_COPY_1D:
2638 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2639 case INTEL_DEV_META_FS_COPY_2D:
2640 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2641 case INTEL_DEV_META_FS_COPY_2D_MS:
2642 consts[0] = offset_x;
2643 consts[1] = offset_y;
2644 consts[2] = meta->src.layer;
2645 consts[3] = meta->src.lod;
2646 const_count = 4;
2647 break;
2648 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2649 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2650 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2651 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2652 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2653 consts[0] = offset_x;
2654 consts[1] = offset_y;
2655 consts[2] = meta->src.layer;
2656 consts[3] = meta->src.lod;
2657 consts[4] = meta->src.x;
2658 consts[5] = meta->width;
2659 const_count = 6;
2660 break;
2661 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2662 consts[0] = offset_x;
2663 consts[1] = offset_y;
2664 consts[2] = meta->width;
2665 const_count = 3;
2666 break;
2667 case INTEL_DEV_META_FS_CLEAR_COLOR:
2668 consts[0] = meta->clear_val[0];
2669 consts[1] = meta->clear_val[1];
2670 consts[2] = meta->clear_val[2];
2671 consts[3] = meta->clear_val[3];
2672 const_count = 4;
2673 break;
2674 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2675 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002676 consts[1] = meta->clear_val[1];
2677 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002678 break;
2679 case INTEL_DEV_META_FS_RESOLVE_2X:
2680 case INTEL_DEV_META_FS_RESOLVE_4X:
2681 case INTEL_DEV_META_FS_RESOLVE_8X:
2682 case INTEL_DEV_META_FS_RESOLVE_16X:
2683 consts[0] = offset_x;
2684 consts[1] = offset_y;
2685 const_count = 2;
2686 break;
2687 default:
2688 assert(!"unknown meta shader id");
2689 const_count = 0;
2690 break;
2691 }
2692
2693 /* this can be skipped but it makes state dumping prettier */
2694 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2695
2696 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2697}
2698
2699static void gen6_meta_ps(struct intel_cmd *cmd)
2700{
2701 const struct intel_cmd_meta *meta = cmd->bind.meta;
2702 const struct intel_pipeline_shader *sh =
2703 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002704 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002705 uint32_t offset, *dw;
2706
2707 CMD_ASSERT(cmd, 6, 6);
2708
Chia-I Wu29e6f502014-11-24 14:27:29 +08002709 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2710 /* 3DSTATE_CONSTANT_PS */
2711 cmd_batch_pointer(cmd, 5, &dw);
2712 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2713 dw[1] = 0;
2714 dw[2] = 0;
2715 dw[3] = 0;
2716 dw[4] = 0;
2717
2718 /* 3DSTATE_WM */
2719 cmd_batch_pointer(cmd, 9, &dw);
2720 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2721 dw[1] = 0;
2722 dw[2] = 0;
2723 dw[3] = 0;
2724 dw[4] = 0;
Chia-I Wu05990612014-11-25 11:36:35 +08002725 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002726 dw[6] = 0;
2727 dw[7] = 0;
2728 dw[8] = 0;
2729
Chia-I Wu3adf7212014-10-24 15:34:07 +08002730 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002731 }
2732
Chia-I Wu3adf7212014-10-24 15:34:07 +08002733 /* a normal color write */
2734 assert(meta->dst.valid && !sh->uses);
2735
Chia-I Wu6032b892014-10-17 14:47:18 +08002736 /* 3DSTATE_CONSTANT_PS */
2737 offset = gen6_meta_ps_constants(cmd);
2738 cmd_batch_pointer(cmd, 5, &dw);
2739 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2740 GEN6_PCB_ANY_DW0_PCB0_VALID;
2741 dw[1] = offset;
2742 dw[2] = 0;
2743 dw[3] = 0;
2744 dw[4] = 0;
2745
2746 /* 3DSTATE_WM */
2747 offset = emit_shader(cmd, sh);
2748 cmd_batch_pointer(cmd, 9, &dw);
2749 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2750 dw[1] = offset;
2751 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2752 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2753 dw[3] = 0;
2754 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002755 dw[5] = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002756 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002757 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2758
Chia-I Wu6032b892014-10-17 14:47:18 +08002759 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2760 GEN6_WM_DW6_POSOFFSET_NONE |
2761 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2762 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2763 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2764 if (meta->samples > 1) {
2765 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2766 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2767 } else {
2768 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2769 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2770 }
2771 dw[7] = 0;
2772 dw[8] = 0;
2773}
2774
2775static void gen7_meta_ps(struct intel_cmd *cmd)
2776{
2777 const struct intel_cmd_meta *meta = cmd->bind.meta;
2778 const struct intel_pipeline_shader *sh =
2779 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
Chia-I Wu05990612014-11-25 11:36:35 +08002780 const int max_threads = cmd_ps_max_threads(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002781 uint32_t offset, *dw;
2782
2783 CMD_ASSERT(cmd, 7, 7.5);
2784
Chia-I Wu29e6f502014-11-24 14:27:29 +08002785 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2786 /* 3DSTATE_WM */
2787 cmd_batch_pointer(cmd, 3, &dw);
2788 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2789 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2790
2791 /* 3DSTATE_CONSTANT_GS */
2792 cmd_batch_pointer(cmd, 7, &dw);
2793 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2794 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2795
2796 /* 3DSTATE_PS */
2797 cmd_batch_pointer(cmd, 8, &dw);
2798 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2799 dw[1] = 0;
2800 dw[2] = 0;
2801 dw[3] = 0;
2802 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu05990612014-11-25 11:36:35 +08002803 (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002804 dw[5] = 0;
2805 dw[6] = 0;
2806 dw[7] = 0;
2807
Chia-I Wu3adf7212014-10-24 15:34:07 +08002808 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002809 }
2810
Chia-I Wu3adf7212014-10-24 15:34:07 +08002811 /* a normal color write */
2812 assert(meta->dst.valid && !sh->uses);
2813
Chia-I Wu6032b892014-10-17 14:47:18 +08002814 /* 3DSTATE_WM */
2815 cmd_batch_pointer(cmd, 3, &dw);
2816 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2817 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2818 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2819 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2820 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2821 dw[2] = 0;
2822
2823 /* 3DSTATE_CONSTANT_PS */
2824 offset = gen6_meta_ps_constants(cmd);
2825 cmd_batch_pointer(cmd, 7, &dw);
2826 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2827 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2828 dw[2] = 0;
2829 dw[3] = offset;
2830 dw[4] = 0;
2831 dw[5] = 0;
2832 dw[6] = 0;
2833
2834 /* 3DSTATE_PS */
2835 offset = emit_shader(cmd, sh);
2836 cmd_batch_pointer(cmd, 8, &dw);
2837 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2838 dw[1] = offset;
2839 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2840 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2841 dw[3] = 0;
2842
2843 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2844 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002845 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2846
2847 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2848 dw[4] |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002849 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002850 } else {
2851 dw[4] |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2852 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002853
2854 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2855 dw[6] = 0;
2856 dw[7] = 0;
2857}
2858
2859static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2860{
2861 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002862 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002863
2864 CMD_ASSERT(cmd, 6, 7.5);
2865
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002866 if (!ds) {
2867 /* all zeros */
2868 static const struct intel_ds_view null_ds;
2869 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002870 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002871
2872 cmd_wa_gen6_pre_ds_flush(cmd);
2873 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2874 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2875 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2876
2877 if (cmd_gen(cmd) >= INTEL_GEN(7))
2878 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2879 else
2880 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002881}
2882
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002883static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2884 const struct intel_pipeline *pipeline)
2885{
2886 cmd->bind.pipeline.graphics = pipeline;
2887}
2888
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002889static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2890 const struct intel_pipeline *pipeline)
2891{
2892 cmd->bind.pipeline.compute = pipeline;
2893}
2894
2895static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2896 const struct intel_pipeline_delta *delta)
2897{
2898 cmd->bind.pipeline.graphics_delta = delta;
2899}
2900
2901static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2902 const struct intel_pipeline_delta *delta)
2903{
2904 cmd->bind.pipeline.compute_delta = delta;
2905}
2906
2907static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2908 const struct intel_dset *dset,
2909 XGL_UINT slot_offset)
2910{
2911 cmd->bind.dset.graphics = dset;
2912 cmd->bind.dset.graphics_offset = slot_offset;
2913}
2914
2915static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2916 const struct intel_dset *dset,
2917 XGL_UINT slot_offset)
2918{
2919 cmd->bind.dset.compute = dset;
2920 cmd->bind.dset.compute_offset = slot_offset;
2921}
2922
2923static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2924 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2925{
2926 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2927}
2928
2929static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2930 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2931{
2932 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2933}
2934
Chia-I Wu3b04af52014-11-08 10:48:20 +08002935static void cmd_bind_vertex_data(struct intel_cmd *cmd,
2936 const struct intel_mem *mem,
2937 XGL_GPU_SIZE offset, XGL_UINT binding)
2938{
2939 if (binding >= ARRAY_SIZE(cmd->bind.vertex.mem)) {
2940 cmd->result = XGL_ERROR_UNKNOWN;
2941 return;
2942 }
2943
2944 cmd->bind.vertex.mem[binding] = mem;
2945 cmd->bind.vertex.offset[binding] = offset;
2946}
2947
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002948static void cmd_bind_index_data(struct intel_cmd *cmd,
2949 const struct intel_mem *mem,
2950 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2951{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002952 cmd->bind.index.mem = mem;
2953 cmd->bind.index.offset = offset;
2954 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002955}
2956
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002957static void cmd_bind_attachments(struct intel_cmd *cmd,
2958 XGL_UINT rt_count,
2959 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2960 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002962 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002963 XGL_UINT i;
2964
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002965 for (i = 0; i < rt_count; i++) {
2966 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002968 const struct intel_layout *layout = &rt->img->layout;
2969
2970 if (i == 0) {
2971 width = layout->width0;
2972 height = layout->height0;
2973 } else {
2974 if (width > layout->width0)
2975 width = layout->width0;
2976 if (height > layout->height0)
2977 height = layout->height0;
2978 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002979
2980 cmd->bind.att.rt[i] = rt;
2981 }
2982
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002983 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002984
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002985 if (ds_info) {
2986 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002987
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002988 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2989 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002991 if (width > layout->width0)
2992 width = layout->width0;
2993 if (height > layout->height0)
2994 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002995 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002996 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997 }
2998
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002999 cmd->bind.att.width = width;
3000 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003001}
3002
3003static void cmd_bind_viewport_state(struct intel_cmd *cmd,
3004 const struct intel_viewport_state *state)
3005{
3006 cmd->bind.state.viewport = state;
3007}
3008
3009static void cmd_bind_raster_state(struct intel_cmd *cmd,
3010 const struct intel_raster_state *state)
3011{
3012 cmd->bind.state.raster = state;
3013}
3014
3015static void cmd_bind_ds_state(struct intel_cmd *cmd,
3016 const struct intel_ds_state *state)
3017{
3018 cmd->bind.state.ds = state;
3019}
3020
3021static void cmd_bind_blend_state(struct intel_cmd *cmd,
3022 const struct intel_blend_state *state)
3023{
3024 cmd->bind.state.blend = state;
3025}
3026
3027static void cmd_bind_msaa_state(struct intel_cmd *cmd,
3028 const struct intel_msaa_state *state)
3029{
3030 cmd->bind.state.msaa = state;
3031}
3032
3033static void cmd_draw(struct intel_cmd *cmd,
3034 XGL_UINT vertex_start,
3035 XGL_UINT vertex_count,
3036 XGL_UINT instance_start,
3037 XGL_UINT instance_count,
3038 bool indexed,
3039 XGL_UINT vertex_base)
3040{
3041 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
3042
3043 emit_bounded_states(cmd);
3044
3045 if (indexed) {
3046 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3047 cmd->result = XGL_ERROR_UNKNOWN;
3048
3049 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3050 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3051 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003052 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3053 cmd->bind.index.offset, cmd->bind.index.type,
3054 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003055 } else {
3056 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
3057 cmd->bind.index.offset, cmd->bind.index.type,
3058 p->primitive_restart);
3059 }
3060 } else {
3061 assert(!vertex_base);
3062 }
3063
3064 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3065 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3066 vertex_start, instance_count, instance_start, vertex_base);
3067 } else {
3068 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3069 vertex_start, instance_count, instance_start, vertex_base);
3070 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003071
Chia-I Wu707a29e2014-08-27 12:51:47 +08003072 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003073 /* need to re-emit all workarounds */
3074 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003075
3076 if (intel_debug & INTEL_DEBUG_NOCACHE)
3077 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003078}
3079
Chia-I Wuc14d1562014-10-17 09:49:22 +08003080void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3081{
Chia-I Wu6032b892014-10-17 14:47:18 +08003082 cmd->bind.meta = meta;
3083
3084 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003085 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003086
3087 gen6_meta_dynamic_states(cmd);
3088 gen6_meta_surface_states(cmd);
3089
3090 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3091 gen7_meta_urb(cmd);
3092 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003093 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003094 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003095 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003096 gen6_meta_wm(cmd);
3097 gen7_meta_ps(cmd);
3098 gen6_meta_depth_buffer(cmd);
3099
3100 cmd_wa_gen7_post_command_cs_stall(cmd);
3101 cmd_wa_gen7_post_command_depth_stall(cmd);
3102
Chia-I Wu29e6f502014-11-24 14:27:29 +08003103 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3104 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3105 meta->width, 0, 1, 0, 0);
3106 } else {
3107 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3108 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003109 } else {
3110 gen6_meta_urb(cmd);
3111 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003112 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003113 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003114 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003115 gen6_meta_wm(cmd);
3116 gen6_meta_ps(cmd);
3117 gen6_meta_depth_buffer(cmd);
3118
Chia-I Wu29e6f502014-11-24 14:27:29 +08003119 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3120 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
3121 meta->width, 0, 1, 0, 0);
3122 } else {
3123 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3124 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003125 }
3126
3127 cmd->bind.draw_count++;
3128 /* need to re-emit all workarounds */
3129 cmd->bind.wa_flags = 0;
3130
3131 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003132
3133 if (intel_debug & INTEL_DEBUG_NOCACHE)
3134 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003135}
3136
Chia-I Wub2755562014-08-20 13:38:52 +08003137XGL_VOID XGLAPI intelCmdBindPipeline(
3138 XGL_CMD_BUFFER cmdBuffer,
3139 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3140 XGL_PIPELINE pipeline)
3141{
3142 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3143
3144 switch (pipelineBindPoint) {
3145 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003146 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003147 break;
3148 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003149 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003150 break;
3151 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003152 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003153 break;
3154 }
3155}
3156
3157XGL_VOID XGLAPI intelCmdBindPipelineDelta(
3158 XGL_CMD_BUFFER cmdBuffer,
3159 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3160 XGL_PIPELINE_DELTA delta)
3161{
3162 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3163
3164 switch (pipelineBindPoint) {
3165 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003166 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003167 break;
3168 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003169 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003170 break;
3171 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003172 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003173 break;
3174 }
3175}
3176
3177XGL_VOID XGLAPI intelCmdBindStateObject(
3178 XGL_CMD_BUFFER cmdBuffer,
3179 XGL_STATE_BIND_POINT stateBindPoint,
3180 XGL_STATE_OBJECT state)
3181{
3182 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3183
3184 switch (stateBindPoint) {
3185 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003186 cmd_bind_viewport_state(cmd,
3187 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003188 break;
3189 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003190 cmd_bind_raster_state(cmd,
3191 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003192 break;
3193 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003194 cmd_bind_ds_state(cmd,
3195 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003196 break;
3197 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003198 cmd_bind_blend_state(cmd,
3199 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003200 break;
3201 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003202 cmd_bind_msaa_state(cmd,
3203 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003204 break;
3205 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003207 break;
3208 }
3209}
3210
3211XGL_VOID XGLAPI intelCmdBindDescriptorSet(
3212 XGL_CMD_BUFFER cmdBuffer,
3213 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3214 XGL_UINT index,
3215 XGL_DESCRIPTOR_SET descriptorSet,
3216 XGL_UINT slotOffset)
3217{
3218 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3219 struct intel_dset *dset = intel_dset(descriptorSet);
3220
3221 assert(!index);
3222
3223 switch (pipelineBindPoint) {
3224 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003226 break;
3227 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003228 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003229 break;
3230 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003231 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003232 break;
3233 }
3234}
3235
3236XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3237 XGL_CMD_BUFFER cmdBuffer,
3238 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3239 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3240{
3241 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3242
3243 switch (pipelineBindPoint) {
3244 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003245 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003246 break;
3247 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003248 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003249 break;
3250 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003251 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003252 break;
3253 }
3254}
3255
Chia-I Wu3b04af52014-11-08 10:48:20 +08003256XGL_VOID XGLAPI intelCmdBindVertexData(
3257 XGL_CMD_BUFFER cmdBuffer,
3258 XGL_GPU_MEMORY mem_,
3259 XGL_GPU_SIZE offset,
3260 XGL_UINT binding)
3261{
3262 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3263 struct intel_mem *mem = intel_mem(mem_);
3264
3265 cmd_bind_vertex_data(cmd, mem, offset, binding);
3266}
3267
Chia-I Wub2755562014-08-20 13:38:52 +08003268XGL_VOID XGLAPI intelCmdBindIndexData(
3269 XGL_CMD_BUFFER cmdBuffer,
3270 XGL_GPU_MEMORY mem_,
3271 XGL_GPU_SIZE offset,
3272 XGL_INDEX_TYPE indexType)
3273{
3274 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3275 struct intel_mem *mem = intel_mem(mem_);
3276
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003277 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003278}
3279
3280XGL_VOID XGLAPI intelCmdBindAttachments(
3281 XGL_CMD_BUFFER cmdBuffer,
3282 XGL_UINT colorAttachmentCount,
3283 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3284 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3285{
3286 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003287
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003288 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3289 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003290}
3291
3292XGL_VOID XGLAPI intelCmdDraw(
3293 XGL_CMD_BUFFER cmdBuffer,
3294 XGL_UINT firstVertex,
3295 XGL_UINT vertexCount,
3296 XGL_UINT firstInstance,
3297 XGL_UINT instanceCount)
3298{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003299 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003300
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003301 cmd_draw(cmd, firstVertex, vertexCount,
3302 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003303}
3304
3305XGL_VOID XGLAPI intelCmdDrawIndexed(
3306 XGL_CMD_BUFFER cmdBuffer,
3307 XGL_UINT firstIndex,
3308 XGL_UINT indexCount,
3309 XGL_INT vertexOffset,
3310 XGL_UINT firstInstance,
3311 XGL_UINT instanceCount)
3312{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003313 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003314
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003315 cmd_draw(cmd, firstIndex, indexCount,
3316 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003317}
3318
3319XGL_VOID XGLAPI intelCmdDrawIndirect(
3320 XGL_CMD_BUFFER cmdBuffer,
3321 XGL_GPU_MEMORY mem,
3322 XGL_GPU_SIZE offset,
3323 XGL_UINT32 count,
3324 XGL_UINT32 stride)
3325{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003326 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3327
3328 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003329}
3330
3331XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3332 XGL_CMD_BUFFER cmdBuffer,
3333 XGL_GPU_MEMORY mem,
3334 XGL_GPU_SIZE offset,
3335 XGL_UINT32 count,
3336 XGL_UINT32 stride)
3337{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003338 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3339
3340 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003341}
3342
3343XGL_VOID XGLAPI intelCmdDispatch(
3344 XGL_CMD_BUFFER cmdBuffer,
3345 XGL_UINT x,
3346 XGL_UINT y,
3347 XGL_UINT z)
3348{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003349 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3350
3351 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003352}
3353
3354XGL_VOID XGLAPI intelCmdDispatchIndirect(
3355 XGL_CMD_BUFFER cmdBuffer,
3356 XGL_GPU_MEMORY mem,
3357 XGL_GPU_SIZE offset)
3358{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003359 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3360
3361 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003362}