blob: f8f23eae93b5e9c6533656f1b520eafb8168789b [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 */
456 assert(vs->out_count >= 2);
457 attr_skip = 2;
458 attr_count = vs->out_count - attr_skip;
459 assert(fs->in_count == attr_count);
460 assert(fs->in_count <= 32);
461
462 vue_offset = attr_skip / 2;
463 vue_len = (attr_count + 1) / 2;
464 if (!vue_len)
465 vue_len = 1;
466
467 dw1 = fs->in_count << GEN7_SBE_DW1_ATTR_COUNT__SHIFT |
468 vue_len << GEN7_SBE_DW1_URB_READ_LEN__SHIFT |
469 vue_offset << GEN7_SBE_DW1_URB_READ_OFFSET__SHIFT;
470
471 body[0] = dw1;
472
473 for (i = 0; i < 8; i++) {
474 uint16_t hi, lo;
475
476 /* no attr swizzles */
477 if (i * 2 + 1 < fs->in_count) {
478 hi = i * 2 + 1;
479 lo = i * 2;
480 } else if (i * 2 < fs->in_count) {
481 hi = 0;
482 lo = i * 2;
483 } else {
484 hi = 0;
485 lo = 0;
486 }
487
488 body[1 + i] = hi << GEN7_SBE_ATTR_HIGH__SHIFT | lo;
489 }
490
491 body[9] = 0; /* point sprite enables */
492 body[10] = 0; /* constant interpolation enables */
493 body[11] = 0; /* WrapShortest enables */
494 body[12] = 0;
495}
496
497static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
498{
499 const uint8_t cmd_len = 20;
500 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
501 (cmd_len - 2);
502 uint32_t sf[6];
503 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800504 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800505
506 CMD_ASSERT(cmd, 6, 6);
507
508 gen7_fill_3DSTATE_SF_body(cmd, sf);
509 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
510
Chia-I Wu72292b72014-09-09 10:48:33 +0800511 cmd_batch_pointer(cmd, cmd_len, &dw);
512 dw[0] = dw0;
513 dw[1] = sbe[0];
514 memcpy(&dw[2], sf, sizeof(sf));
515 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800516}
517
518static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
519{
520 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800521 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800522
523 CMD_ASSERT(cmd, 7, 7.5);
524
Chia-I Wu72292b72014-09-09 10:48:33 +0800525 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
527 (cmd_len - 2);
528 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800529}
530
531static void gen7_3DSTATE_SBE(struct intel_cmd *cmd)
532{
533 const uint8_t cmd_len = 14;
Chia-I Wu72292b72014-09-09 10:48:33 +0800534 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800535
536 CMD_ASSERT(cmd, 7, 7.5);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800539 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) |
540 (cmd_len - 2);
541 gen7_fill_3DSTATE_SBE_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800542}
543
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800544static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
545{
546 const uint8_t cmd_len = 4;
547 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
548 (cmd_len - 2);
549 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
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 |
567 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
568 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
569 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
570
571 if (pipeline->rasterizerDiscardEnable)
572 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
573 else
574 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
575
576 if (pipeline->depthClipEnable)
577 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
578
579 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
580 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
581 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
582 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
583
584 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
585 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
586 (viewport->viewport_count - 1);
587
Chia-I Wu72292b72014-09-09 10:48:33 +0800588 cmd_batch_pointer(cmd, cmd_len, &dw);
589 dw[0] = dw0;
590 dw[1] = dw1;
591 dw[2] = dw2;
592 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593}
594
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800595static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
596{
597 const int max_threads = (cmd->dev->gpu->gt == 2) ? 80 : 40;
598 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800599 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800600 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
601 const uint8_t cmd_len = 9;
Chia-I Wu72292b72014-09-09 10:48:33 +0800602 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800603
604 CMD_ASSERT(cmd, 6, 6);
605
606 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
607
608 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
609 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
610
611 dw4 = GEN6_WM_DW4_STATISTICS |
612 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
613 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
614 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
615
616 dw5 = (max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
617 GEN6_WM_DW5_PS_ENABLE |
618 GEN6_WM_DW5_8_PIXEL_DISPATCH;
619
620 if (fs->uses & INTEL_SHADER_USE_KILL ||
621 pipeline->cb_state.alphaToCoverageEnable)
622 dw5 |= GEN6_WM_DW5_PS_KILL;
623
624 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
625 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
626 if (fs->uses & INTEL_SHADER_USE_DEPTH)
627 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
628 if (fs->uses & INTEL_SHADER_USE_W)
629 dw5 |= GEN6_WM_DW5_PS_USE_W;
630
631 if (pipeline->cb_state.dualSourceBlendEnable)
632 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
633
634 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
635 GEN6_WM_DW6_POSOFFSET_NONE |
636 GEN6_WM_DW6_ZW_INTERP_PIXEL |
637 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
638 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
639
640 if (msaa->sample_count > 1) {
641 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
642 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
643 } else {
644 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
645 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
646 }
647
Chia-I Wu72292b72014-09-09 10:48:33 +0800648 cmd_batch_pointer(cmd, cmd_len, &dw);
649 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800650 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800651 dw[2] = dw2;
652 dw[3] = 0; /* scratch */
653 dw[4] = dw4;
654 dw[5] = dw5;
655 dw[6] = dw6;
656 dw[7] = 0; /* kernel 1 */
657 dw[8] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658}
659
660static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
661{
662 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800663 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800664 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
665 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800666 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667
668 CMD_ASSERT(cmd, 7, 7.5);
669
670 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
671
672 dw1 = GEN7_WM_DW1_STATISTICS |
673 GEN7_WM_DW1_PS_ENABLE |
674 GEN7_WM_DW1_ZW_INTERP_PIXEL |
675 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
676 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
677
678 if (fs->uses & INTEL_SHADER_USE_KILL ||
679 pipeline->cb_state.alphaToCoverageEnable)
680 dw1 |= GEN7_WM_DW1_PS_KILL;
681
682 if (fs->uses & INTEL_SHADER_USE_COMPUTED_DEPTH)
683 dw1 |= GEN7_WM_DW1_PSCDEPTH_ON;
684 if (fs->uses & INTEL_SHADER_USE_DEPTH)
685 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
686 if (fs->uses & INTEL_SHADER_USE_W)
687 dw1 |= GEN7_WM_DW1_PS_USE_W;
688
689 dw2 = 0;
690
691 if (msaa->sample_count > 1) {
692 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
693 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
694 } else {
695 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
696 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
697 }
698
Chia-I Wu72292b72014-09-09 10:48:33 +0800699 cmd_batch_pointer(cmd, cmd_len, &dw);
700 dw[0] = dw0;
701 dw[1] = dw1;
702 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800703}
704
705static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
706{
707 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800708 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800709 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
710 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800711 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800712
713 CMD_ASSERT(cmd, 7, 7.5);
714
715 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
716
717 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
718 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
719
720 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
721 GEN7_PS_DW4_8_PIXEL_DISPATCH;
722
723 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
724 const int max_threads =
725 (cmd->dev->gpu->gt == 3) ? 408 :
726 (cmd->dev->gpu->gt == 2) ? 204 : 102;
727 dw4 |= (max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
728 dw4 |= msaa->cmd[msaa->cmd_len - 1] << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
729 } else {
730 const int max_threads = (cmd->dev->gpu->gt == 2) ? 172 : 48;
731 dw4 |= (max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
732 }
733
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800734 if (fs->in_count)
735 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
736
737 if (pipeline->cb_state.dualSourceBlendEnable)
738 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
739
740 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
741 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
742 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800746 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800747 dw[2] = dw2;
748 dw[3] = 0; /* scratch */
749 dw[4] = dw4;
750 dw[5] = dw5;
751 dw[6] = 0; /* kernel 1 */
752 dw[7] = 0; /* kernel 2 */
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800753}
754
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800755static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
756 const struct intel_ds_view *view)
757{
758 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759 uint32_t dw0, *dw;
760 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761
762 CMD_ASSERT(cmd, 6, 7.5);
763
764 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800765 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
766 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767 dw0 |= (cmd_len - 2);
768
Chia-I Wu72292b72014-09-09 10:48:33 +0800769 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
770 dw[0] = dw0;
771 dw[1] = view->cmd[0];
772 dw[2] = 0;
773 dw[3] = view->cmd[2];
774 dw[4] = view->cmd[3];
775 dw[5] = view->cmd[4];
776 dw[6] = view->cmd[5];
777
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800779 cmd_reserve_reloc(cmd, 1);
780 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
781 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600782 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800783}
784
785static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
786 const struct intel_ds_view *view)
787{
788 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 uint32_t dw0, *dw;
790 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800791
792 CMD_ASSERT(cmd, 6, 7.5);
793
794 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800795 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
796 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800797 dw0 |= (cmd_len - 2);
798
Chia-I Wu72292b72014-09-09 10:48:33 +0800799 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
800 dw[0] = dw0;
801 dw[1] = view->cmd[6];
802 dw[2] = 0;
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[7], 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_HIER_DEPTH_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_HIER_DEPTH_BUFFER) :
822 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_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[8];
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[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600834 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835}
836
Chia-I Wuf8231032014-08-25 10:44:45 +0800837static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
838 uint32_t clear_val)
839{
840 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800841 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800842 GEN6_CLEAR_PARAMS_DW0_VALID |
843 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800844 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800845
846 CMD_ASSERT(cmd, 6, 6);
847
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 cmd_batch_pointer(cmd, cmd_len, &dw);
849 dw[0] = dw0;
850 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800851}
852
853static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
854 uint32_t clear_val)
855{
856 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800857 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800858 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800860
861 CMD_ASSERT(cmd, 7, 7.5);
862
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 cmd_batch_pointer(cmd, cmd_len, &dw);
864 dw[0] = dw0;
865 dw[1] = clear_val;
866 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800867}
868
Chia-I Wu302742d2014-08-22 10:28:29 +0800869static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t blend_offset,
871 uint32_t ds_offset,
872 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800873{
874 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800876
877 CMD_ASSERT(cmd, 6, 6);
878
Chia-I Wu426072d2014-08-26 14:31:55 +0800879 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800880 (cmd_len - 2);
881
Chia-I Wu72292b72014-09-09 10:48:33 +0800882 cmd_batch_pointer(cmd, cmd_len, &dw);
883 dw[0] = dw0;
884 dw[1] = blend_offset | 1;
885 dw[2] = ds_offset | 1;
886 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800887}
888
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800890 uint32_t clip_offset,
891 uint32_t sf_offset,
892 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893{
894 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896
897 CMD_ASSERT(cmd, 6, 6);
898
Chia-I Wu426072d2014-08-26 14:31:55 +0800899 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800900 GEN6_PTR_VP_DW0_CLIP_CHANGED |
901 GEN6_PTR_VP_DW0_SF_CHANGED |
902 GEN6_PTR_VP_DW0_CC_CHANGED |
903 (cmd_len - 2);
904
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 cmd_batch_pointer(cmd, cmd_len, &dw);
906 dw[0] = dw0;
907 dw[1] = clip_offset;
908 dw[2] = sf_offset;
909 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800910}
911
912static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800913 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800914{
915 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800917
918 CMD_ASSERT(cmd, 6, 6);
919
Chia-I Wu426072d2014-08-26 14:31:55 +0800920 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800921 (cmd_len - 2);
922
Chia-I Wu72292b72014-09-09 10:48:33 +0800923 cmd_batch_pointer(cmd, cmd_len, &dw);
924 dw[0] = dw0;
925 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800926}
927
Chia-I Wu42a56202014-08-23 16:47:48 +0800928static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800929 uint32_t vs_offset,
930 uint32_t gs_offset,
931 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800932{
933 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800934 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800935
936 CMD_ASSERT(cmd, 6, 6);
937
Chia-I Wu426072d2014-08-26 14:31:55 +0800938 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800939 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
940 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
941 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
942 (cmd_len - 2);
943
Chia-I Wu72292b72014-09-09 10:48:33 +0800944 cmd_batch_pointer(cmd, cmd_len, &dw);
945 dw[0] = dw0;
946 dw[1] = vs_offset;
947 dw[2] = gs_offset;
948 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800949}
950
Chia-I Wu257e75e2014-08-29 14:06:35 +0800951static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800952 uint32_t vs_offset,
953 uint32_t gs_offset,
954 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800955{
956 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800958
959 CMD_ASSERT(cmd, 6, 6);
960
961 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
962 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
963 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
964 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
965 (cmd_len - 2);
966
Chia-I Wu72292b72014-09-09 10:48:33 +0800967 cmd_batch_pointer(cmd, cmd_len, &dw);
968 dw[0] = dw0;
969 dw[1] = vs_offset;
970 dw[2] = gs_offset;
971 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800972}
973
Chia-I Wu302742d2014-08-22 10:28:29 +0800974static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800975 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800976{
977 const uint8_t cmd_len = 2;
978 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
979 GEN6_RENDER_SUBTYPE_3D |
980 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800982
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 cmd_batch_pointer(cmd, cmd_len, &dw);
984 dw[0] = dw0;
985 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800986}
987
Chia-I Wu72292b72014-09-09 10:48:33 +0800988static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800989 const struct intel_blend_state *state)
990{
Chia-I Wu72292b72014-09-09 10:48:33 +0800991 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992 const uint8_t cmd_len = XGL_MAX_COLOR_ATTACHMENTS * 2;
993
994 CMD_ASSERT(cmd, 6, 7.5);
995 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
996
Chia-I Wu00b51a82014-09-09 12:07:37 +0800997 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND,
998 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +0800999}
1000
Chia-I Wu72292b72014-09-09 10:48:33 +08001001static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001002 const struct intel_ds_state *state)
1003{
Chia-I Wu72292b72014-09-09 10:48:33 +08001004 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const uint8_t cmd_len = 3;
1006
1007 CMD_ASSERT(cmd, 6, 7.5);
1008 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= cmd_len);
1009
Chia-I Wu00b51a82014-09-09 12:07:37 +08001010 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1011 cmd_align, cmd_len, state->cmd);
Chia-I Wu302742d2014-08-22 10:28:29 +08001012}
1013
Chia-I Wu72292b72014-09-09 10:48:33 +08001014static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001015 uint32_t stencil_ref,
1016 const uint32_t blend_color[4])
1017{
Chia-I Wu72292b72014-09-09 10:48:33 +08001018 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE * 4;
Chia-I Wu302742d2014-08-22 10:28:29 +08001019 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001020 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001021
1022 CMD_ASSERT(cmd, 6, 7.5);
1023
Chia-I Wu00b51a82014-09-09 12:07:37 +08001024 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1025 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001026 dw[0] = stencil_ref;
1027 dw[1] = 0;
1028 dw[2] = blend_color[0];
1029 dw[3] = blend_color[1];
1030 dw[4] = blend_color[2];
1031 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001032
Chia-I Wu72292b72014-09-09 10:48:33 +08001033 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001034}
1035
Chia-I Wu8370b402014-08-29 12:28:37 +08001036static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001037{
Chia-I Wu8370b402014-08-29 12:28:37 +08001038 CMD_ASSERT(cmd, 6, 7.5);
1039
Chia-I Wu707a29e2014-08-27 12:51:47 +08001040 if (!cmd->bind.draw_count)
1041 return;
1042
Chia-I Wu8370b402014-08-29 12:28:37 +08001043 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044 return;
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001047
1048 /*
1049 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1050 *
1051 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1052 * pipe-control with a post-sync op and no write-cache flushes."
1053 *
1054 * The workaround below necessitates this workaround.
1055 */
1056 gen6_PIPE_CONTROL(cmd,
1057 GEN6_PIPE_CONTROL_CS_STALL |
1058 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001059 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001060
Chia-I Wud6d079d2014-08-31 13:14:21 +08001061 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1062 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001066{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001067 CMD_ASSERT(cmd, 6, 7.5);
1068
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001069 if (!cmd->bind.draw_count)
1070 return;
1071
Chia-I Wud6d079d2014-08-31 13:14:21 +08001072 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1073 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001074}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1077{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001078 CMD_ASSERT(cmd, 7, 7.5);
1079
Chia-I Wu8370b402014-08-29 12:28:37 +08001080 if (!cmd->bind.draw_count)
1081 return;
1082
1083 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001084
1085 gen6_PIPE_CONTROL(cmd,
1086 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001087 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001088}
1089
Chia-I Wu8370b402014-08-29 12:28:37 +08001090static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1091{
1092 CMD_ASSERT(cmd, 7, 7.5);
1093
1094 if (!cmd->bind.draw_count)
1095 return;
1096
1097 /*
1098 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1099 *
1100 * "One of the following must also be set (when CS stall is set):
1101 *
1102 * * Render Target Cache Flush Enable ([12] of DW1)
1103 * * Depth Cache Flush Enable ([0] of DW1)
1104 * * Stall at Pixel Scoreboard ([1] of DW1)
1105 * * Depth Stall ([13] of DW1)
1106 * * Post-Sync Operation ([13] of DW1)"
1107 */
1108 gen6_PIPE_CONTROL(cmd,
1109 GEN6_PIPE_CONTROL_CS_STALL |
1110 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001111 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001112}
1113
1114static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1115{
1116 CMD_ASSERT(cmd, 7, 7.5);
1117
1118 if (!cmd->bind.draw_count)
1119 return;
1120
1121 cmd_wa_gen6_pre_depth_stall_write(cmd);
1122
Chia-I Wud6d079d2014-08-31 13:14:21 +08001123 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001124}
1125
1126static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1127{
1128 CMD_ASSERT(cmd, 6, 7.5);
1129
1130 if (!cmd->bind.draw_count)
1131 return;
1132
1133 /*
1134 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1135 *
1136 * "Driver must guarentee that all the caches in the depth pipe are
1137 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1138 * requires driver to send a PIPE_CONTROL with a CS stall along with
1139 * a Depth Flush prior to this command."
1140 *
1141 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1142 *
1143 * "Driver must ierarchi that all the caches in the depth pipe are
1144 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1145 * requires driver to send a PIPE_CONTROL with a CS stall along with
1146 * a Depth Flush prior to this command.
1147 */
1148 gen6_PIPE_CONTROL(cmd,
1149 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1150 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001151 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001152}
1153
1154static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1155{
1156 CMD_ASSERT(cmd, 6, 7.5);
1157
1158 if (!cmd->bind.draw_count)
1159 return;
1160
1161 /*
1162 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1163 *
1164 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1165 * and a post sync operation prior to the group of depth
1166 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1167 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1168 *
1169 * This workaround satifies all the conditions.
1170 */
1171 cmd_wa_gen6_pre_depth_stall_write(cmd);
1172
1173 /*
1174 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1175 *
1176 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1177 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1178 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1179 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1180 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1181 * Depth Flush Bit set, followed by another pipelined depth stall
1182 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1183 * guarantee that the pipeline from WM onwards is already flushed
1184 * (e.g., via a preceding MI_FLUSH)."
1185 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001186 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1187 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1188 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001189}
1190
Chia-I Wu525c6602014-08-27 10:22:34 +08001191void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1192{
1193 if (!cmd->bind.draw_count)
1194 return;
1195
1196 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198 /*
1199 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1200 *
1201 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1202 * PIPE_CONTROL with any non-zero post-sync-op is required."
1203 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001204 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001205 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001206
Chia-I Wu092279a2014-08-30 19:05:30 +08001207 /*
1208 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1209 *
1210 * "One of the following must also be set (when CS stall is set):
1211 *
1212 * * Render Target Cache Flush Enable ([12] of DW1)
1213 * * Depth Cache Flush Enable ([0] of DW1)
1214 * * Stall at Pixel Scoreboard ([1] of DW1)
1215 * * Depth Stall ([13] of DW1)
1216 * * Post-Sync Operation ([13] of DW1)"
1217 */
1218 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1219 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1220 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1221 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1222 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1223 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1224
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001226}
1227
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001228void cmd_batch_depth_count(struct intel_cmd *cmd,
1229 struct intel_bo *bo,
1230 XGL_GPU_SIZE offset)
1231{
1232 cmd_wa_gen6_pre_depth_stall_write(cmd);
1233
1234 gen6_PIPE_CONTROL(cmd,
1235 GEN6_PIPE_CONTROL_DEPTH_STALL |
1236 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001237 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001238}
1239
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001240void cmd_batch_timestamp(struct intel_cmd *cmd,
1241 struct intel_bo *bo,
1242 XGL_GPU_SIZE offset)
1243{
1244 /* need any WA or stall? */
1245 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1246}
1247
1248void cmd_batch_immediate(struct intel_cmd *cmd,
1249 struct intel_bo *bo,
1250 XGL_GPU_SIZE offset,
1251 uint64_t val)
1252{
1253 /* need any WA or stall? */
1254 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM, bo, offset, val);
1255}
1256
Chia-I Wu302742d2014-08-22 10:28:29 +08001257static void gen6_cc_states(struct intel_cmd *cmd)
1258{
1259 const struct intel_blend_state *blend = cmd->bind.state.blend;
1260 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001261 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001262 uint32_t stencil_ref;
1263 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001264
1265 CMD_ASSERT(cmd, 6, 6);
1266
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001267 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001268 blend_offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001269 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1270 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001271 blend_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272 memset(blend_color, 0, sizeof(blend_color));
1273 }
1274
1275 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001276 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001277 stencil_ref = ds->cmd_stencil_ref;
1278 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001280 stencil_ref = 0;
1281 }
1282
Chia-I Wu72292b72014-09-09 10:48:33 +08001283 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001284
Chia-I Wu72292b72014-09-09 10:48:33 +08001285 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001286}
1287
Chia-I Wu1744cca2014-08-22 11:10:17 +08001288static void gen6_viewport_states(struct intel_cmd *cmd)
1289{
1290 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001291 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001292
1293 if (!viewport)
1294 return;
1295
Chia-I Wub1d450a2014-09-09 13:48:03 +08001296 assert(viewport->cmd_len == (8 + 4 + 2 + 2 * viewport->scissor_enable) *
1297 viewport->viewport_count);
1298
1299 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1300 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 8 * viewport->viewport_count,
1301 viewport->cmd);
1302
1303 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
1304 GEN6_ALIGNMENT_CLIP_VIEWPORT * 4, 4 * viewport->viewport_count,
1305 &viewport->cmd[viewport->cmd_clip_pos]);
1306
1307 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1308 GEN6_ALIGNMENT_SF_VIEWPORT * 4, 2 * viewport->viewport_count,
1309 &viewport->cmd[viewport->cmd_cc_pos]);
1310
1311 if (viewport->scissor_enable) {
1312 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1313 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1314 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1315 } else {
1316 scissor_offset = 0;
1317 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001318
1319 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001320 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001321
Chia-I Wub1d450a2014-09-09 13:48:03 +08001322 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001323}
1324
Chia-I Wu302742d2014-08-22 10:28:29 +08001325static void gen7_cc_states(struct intel_cmd *cmd)
1326{
1327 const struct intel_blend_state *blend = cmd->bind.state.blend;
1328 const struct intel_ds_state *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001329 uint32_t stencil_ref;
1330 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001331 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001332
1333 CMD_ASSERT(cmd, 7, 7.5);
1334
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001335 if (!blend && !ds)
1336 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001337
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001338 if (blend) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001339 offset = gen6_BLEND_STATE(cmd, blend);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001341 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001342
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001343 memcpy(blend_color, blend->cmd_blend_color, sizeof(blend_color));
1344 } else {
1345 memset(blend_color, 0, sizeof(blend_color));
1346 }
1347
1348 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001349 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1352 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001353 } else {
1354 stencil_ref = 0;
1355 }
1356
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001358 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001359 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001360}
1361
Chia-I Wu1744cca2014-08-22 11:10:17 +08001362static void gen7_viewport_states(struct intel_cmd *cmd)
1363{
1364 const struct intel_viewport_state *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001365 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001366
1367 if (!viewport)
1368 return;
1369
Chia-I Wub1d450a2014-09-09 13:48:03 +08001370 assert(viewport->cmd_len == (16 + 2 + 2 * viewport->scissor_enable) *
1371 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001372
Chia-I Wub1d450a2014-09-09 13:48:03 +08001373 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
1374 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT * 4, 16 * viewport->viewport_count,
1375 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001376 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1378 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001379
1380 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
1381 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2 * viewport->viewport_count,
1382 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001383 gen7_3dstate_pointer(cmd,
1384 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001385 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001386
Chia-I Wu1744cca2014-08-22 11:10:17 +08001387 if (viewport->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001388 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1389 GEN6_ALIGNMENT_SCISSOR_RECT * 4, 2 * viewport->viewport_count,
1390 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001391 gen7_3dstate_pointer(cmd,
1392 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001393 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001394 }
1395}
1396
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001397static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001398 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001399{
1400 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001401 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001402
Chia-I Wu72292b72014-09-09 10:48:33 +08001403 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001404
1405 dw[0] = GEN6_RENDER_TYPE_RENDER |
1406 GEN6_RENDER_SUBTYPE_3D |
1407 subop | (cmd_len - 2);
1408 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001409 dw[2] = 0;
1410 dw[3] = 0;
1411 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412}
1413
1414static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001415 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001416{
1417 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001418 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001419
Chia-I Wu72292b72014-09-09 10:48:33 +08001420 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001421
1422 dw[0] = GEN6_RENDER_TYPE_RENDER |
1423 GEN6_RENDER_SUBTYPE_3D |
1424 subop | (cmd_len - 2);
1425 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001426 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001427 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001428 dw[4] = 0;
1429 dw[5] = 0;
1430 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001431}
1432
Chia-I Wu625105f2014-10-13 15:35:29 +08001433static uint32_t emit_samplers(struct intel_cmd *cmd,
1434 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001435{
1436 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1437 const XGL_UINT border_stride =
1438 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001439 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001440 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001441 XGL_UINT i;
1442
1443 CMD_ASSERT(cmd, 6, 7.5);
1444
Chia-I Wu625105f2014-10-13 15:35:29 +08001445 if (!rmap || !rmap->sampler_count)
1446 return 0;
1447
1448 surface_count = rmap->rt_count + rmap->resource_count + rmap->uav_count;
1449
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450 border_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLOB,
1451 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR * 4,
1452 border_stride * rmap->sampler_count, &border_dw);
1453
1454 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
1455 GEN6_ALIGNMENT_SAMPLER_STATE * 4,
1456 4 * rmap->sampler_count, &sampler_dw);
1457
1458 for (i = 0; i < rmap->sampler_count; i++) {
1459 const struct intel_pipeline_rmap_slot *slot =
1460 &rmap->slots[surface_count + i];
1461 const struct intel_sampler *sampler;
1462
1463 switch (slot->path_len) {
1464 case 0:
1465 sampler = NULL;
1466 break;
1467 case INTEL_PIPELINE_RMAP_SLOT_RT:
1468 case INTEL_PIPELINE_RMAP_SLOT_DYN:
1469 assert(!"unexpected rmap slot type");
1470 sampler = NULL;
1471 break;
1472 case 1:
1473 {
1474 const struct intel_dset *dset = cmd->bind.dset.graphics;
1475 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1476 const struct intel_dset_slot *dset_slot =
1477 &dset->slots[slot_offset + slot->u.index];
1478
1479 switch (dset_slot->type) {
1480 case INTEL_DSET_SLOT_SAMPLER:
1481 sampler = dset_slot->u.sampler;
1482 break;
1483 default:
1484 assert(!"unexpected dset slot type");
1485 sampler = NULL;
1486 break;
1487 }
1488 }
1489 break;
1490 default:
1491 assert(!"nested descriptor set unsupported");
1492 sampler = NULL;
1493 break;
1494 }
1495
1496 if (sampler) {
1497 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1498
1499 sampler_dw[0] = sampler->cmd[0];
1500 sampler_dw[1] = sampler->cmd[1];
1501 sampler_dw[2] = border_offset;
1502 sampler_dw[3] = sampler->cmd[2];
1503 } else {
1504 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1505 sampler_dw[1] = 0;
1506 sampler_dw[2] = 0;
1507 sampler_dw[3] = 0;
1508 }
1509
1510 border_offset += border_stride * 4;
1511 border_dw += border_stride;
1512 sampler_dw += 4;
1513 }
1514
Chia-I Wu625105f2014-10-13 15:35:29 +08001515 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001516}
1517
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001518static uint32_t emit_binding_table(struct intel_cmd *cmd,
1519 const struct intel_pipeline_rmap *rmap)
Chia-I Wu42a56202014-08-23 16:47:48 +08001520{
Chia-I Wu72292b72014-09-09 10:48:33 +08001521 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001522 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001523
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001524 CMD_ASSERT(cmd, 6, 7.5);
1525
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001526 surface_count = (rmap) ?
1527 rmap->rt_count + rmap->resource_count + rmap->uav_count : 0;
1528 if (!surface_count)
1529 return 0;
1530
Chia-I Wu42a56202014-08-23 16:47:48 +08001531 assert(surface_count <= ARRAY_SIZE(binding_table));
1532
1533 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001534 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wu42a56202014-08-23 16:47:48 +08001535
1536 switch (slot->path_len) {
1537 case 0:
Chia-I Wu72292b72014-09-09 10:48:33 +08001538 offset = 0;
Chia-I Wu42a56202014-08-23 16:47:48 +08001539 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001540 case INTEL_PIPELINE_RMAP_SLOT_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001541 {
1542 const struct intel_rt_view *view = cmd->bind.att.rt[i];
1543
Chia-I Wu00b51a82014-09-09 12:07:37 +08001544 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1546 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001547
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 cmd_reserve_reloc(cmd, 1);
1549 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1550 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001551 }
1552 break;
Chia-I Wu20983762014-09-02 12:07:28 +08001553 case INTEL_PIPELINE_RMAP_SLOT_DYN:
Chia-I Wu42a56202014-08-23 16:47:48 +08001554 {
1555 const struct intel_mem_view *view =
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001556 &cmd->bind.dyn_view.graphics;
Chia-I Wu42a56202014-08-23 16:47:48 +08001557
Chia-I Wu00b51a82014-09-09 12:07:37 +08001558 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1560 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001561
Chia-I Wu72292b72014-09-09 10:48:33 +08001562 cmd_reserve_reloc(cmd, 1);
1563 cmd_surface_reloc(cmd, offset, 1, view->mem->bo,
1564 view->cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu42a56202014-08-23 16:47:48 +08001565 }
1566 break;
1567 case 1:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001568 {
1569 const struct intel_dset *dset = cmd->bind.dset.graphics;
1570 const XGL_UINT slot_offset = cmd->bind.dset.graphics_offset;
1571 const struct intel_dset_slot *dset_slot =
1572 &dset->slots[slot_offset + slot->u.index];
1573
1574 switch (dset_slot->type) {
1575 case INTEL_DSET_SLOT_IMG_VIEW:
1576 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1577 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1578 dset_slot->u.img_view->cmd_len,
1579 dset_slot->u.img_view->cmd);
1580
1581 cmd_reserve_reloc(cmd, 1);
1582 cmd_surface_reloc(cmd, offset, 1,
1583 dset_slot->u.img_view->img->obj.mem->bo,
1584 dset_slot->u.img_view->cmd[1], 0);
1585 break;
1586 case INTEL_DSET_SLOT_MEM_VIEW:
1587 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1588 GEN6_ALIGNMENT_SURFACE_STATE * 4,
1589 dset_slot->u.mem_view.cmd_len,
1590 dset_slot->u.mem_view.cmd);
1591
1592 cmd_reserve_reloc(cmd, 1);
1593 cmd_surface_reloc(cmd, offset, 1,
1594 dset_slot->u.mem_view.mem->bo,
1595 dset_slot->u.mem_view.cmd[1], 0);
1596 break;
1597 default:
1598 assert(!"unexpected dset slot type");
1599 break;
1600 }
1601 }
1602 break;
Chia-I Wu42a56202014-08-23 16:47:48 +08001603 default:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001604 assert(!"nested descriptor set unsupported");
Chia-I Wu42a56202014-08-23 16:47:48 +08001605 break;
1606 }
1607
Chia-I Wu72292b72014-09-09 10:48:33 +08001608 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001609 }
1610
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001611 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wu00b51a82014-09-09 12:07:37 +08001612 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
Chia-I Wu72292b72014-09-09 10:48:33 +08001613 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001614}
1615
Chia-I Wu1d125092014-10-08 08:49:38 +08001616static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1617{
1618 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1619 const struct intel_pipeline_rmap *rmap = pipeline->vs.rmap;
1620 const struct intel_dset *dset = cmd->bind.dset.graphics;
1621 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1622 uint32_t *dw;
1623 XGL_UINT pos, i;
1624
1625 CMD_ASSERT(cmd, 6, 7.5);
1626
1627 if (!pipeline->vb_count)
1628 return;
1629
1630 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1631
1632 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1633 dw++;
1634 pos++;
1635
1636 for (i = 0; i < pipeline->vb_count; i++) {
1637 const XGL_UINT vb_offset = rmap->rt_count + rmap->resource_count +
1638 rmap->uav_count + rmap->sampler_count;
1639 const struct intel_pipeline_rmap_slot *slot = (i < rmap->vb_count) ?
1640 &rmap->slots[vb_offset + i] : NULL;
1641 struct intel_mem_view *view = NULL;
1642
1643 if (slot) {
1644 switch (slot->path_len) {
1645 case 1:
1646 view = (dset->slots[slot->u.index].type ==
1647 INTEL_DSET_SLOT_MEM_VIEW) ?
1648 &dset->slots[slot->u.index].u.mem_view : NULL;
1649 break;
1650 default:
1651 break;
1652 }
1653 }
1654
1655 assert(pipeline->vb[i].strideInBytes <= 2048);
1656
1657 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1658 pipeline->vb[i].strideInBytes;
1659
1660 if (cmd_gen(cmd) >= INTEL_GEN(7))
1661 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1662
1663 switch (pipeline->vb[i].stepRate) {
1664 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1665 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1666 dw[3] = 0;
1667 break;
1668 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1669 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1670 dw[3] = 1;
1671 break;
1672 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1673 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1674 dw[3] = 0;
1675 break;
1676 default:
1677 assert(!"unknown step rate");
1678 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1679 dw[3] = 0;
1680 break;
1681 }
1682
1683 if (view) {
1684 const uint32_t begin = view->cmd[1];
1685 const uint32_t end = view->mem->size - 1;
1686
1687 cmd_reserve_reloc(cmd, 2);
1688 cmd_batch_reloc(cmd, pos + 1, view->mem->bo, begin, 0);
1689 cmd_batch_reloc(cmd, pos + 2, view->mem->bo, end, 0);
1690 } else {
1691 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1692 dw[1] = 0;
1693 dw[2] = 0;
1694 }
1695
1696 dw += 4;
1697 pos += 4;
1698 }
1699}
1700
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001701static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1702{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001703 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1704 const struct intel_pipeline_shader *vs = &pipeline->vs;
1705 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001706 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001707 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001708 int vue_read_len, max_threads;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001709
1710 CMD_ASSERT(cmd, 6, 7.5);
1711
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001712 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001713 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1714 *
1715 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1716 * 128-bit vertex elements to be passed into the payload for each
1717 * vertex."
1718 *
1719 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1720 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001721 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001722 vue_read_len = (vs->in_count + 1) / 2;
1723 if (!vue_read_len)
1724 vue_read_len = 1;
1725
1726 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1727 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1728
1729 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1730 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1731 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001732
1733 dw5 = GEN6_VS_DW5_STATISTICS |
1734 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001735
1736 switch (cmd_gen(cmd)) {
1737 case INTEL_GEN(7.5):
1738 max_threads = (cmd->dev->gpu->gt >= 2) ? 280 : 70;
1739 break;
1740 case INTEL_GEN(7):
1741 max_threads = (cmd->dev->gpu->gt == 2) ? 128 : 36;
1742 break;
1743 case INTEL_GEN(6):
1744 max_threads = (cmd->dev->gpu->gt == 2) ? 60 : 24;
1745 break;
1746 default:
1747 max_threads = 1;
1748 break;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001749 }
1750
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
1752 dw5 |= (max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
1753 else
1754 dw5 |= (max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
1755
Chia-I Wube0a3d92014-09-02 13:20:59 +08001756 if (pipeline->disable_vs_cache)
1757 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1758
Chia-I Wu72292b72014-09-09 10:48:33 +08001759 cmd_batch_pointer(cmd, cmd_len, &dw);
1760 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001761 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001762 dw[2] = dw2;
1763 dw[3] = 0; /* scratch */
1764 dw[4] = dw4;
1765 dw[5] = dw5;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001766}
1767
Chia-I Wu625105f2014-10-13 15:35:29 +08001768static void emit_shader_resources(struct intel_cmd *cmd)
1769{
1770 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001771 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001772
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001773 binding_tables[0] = emit_binding_table(cmd,
1774 cmd->bind.pipeline.graphics->vs.rmap);
1775 binding_tables[1] = emit_binding_table(cmd,
1776 cmd->bind.pipeline.graphics->tcs.rmap);
1777 binding_tables[2] = emit_binding_table(cmd,
1778 cmd->bind.pipeline.graphics->tes.rmap);
1779 binding_tables[3] = emit_binding_table(cmd,
1780 cmd->bind.pipeline.graphics->gs.rmap);
1781 binding_tables[4] = emit_binding_table(cmd,
1782 cmd->bind.pipeline.graphics->fs.rmap);
Chia-I Wu625105f2014-10-13 15:35:29 +08001783
1784 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1785 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1786 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1787 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1788 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1789
1790 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1791 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001792 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1793 binding_tables[0]);
1794 gen7_3dstate_pointer(cmd,
1795 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1796 binding_tables[1]);
1797 gen7_3dstate_pointer(cmd,
1798 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1799 binding_tables[2]);
1800 gen7_3dstate_pointer(cmd,
1801 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1802 binding_tables[3]);
1803 gen7_3dstate_pointer(cmd,
1804 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1805 binding_tables[4]);
1806
1807 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001808 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1809 samplers[0]);
1810 gen7_3dstate_pointer(cmd,
1811 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1812 samplers[1]);
1813 gen7_3dstate_pointer(cmd,
1814 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1815 samplers[2]);
1816 gen7_3dstate_pointer(cmd,
1817 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1818 samplers[3]);
1819 gen7_3dstate_pointer(cmd,
1820 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1821 samplers[4]);
1822 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001823 assert(!binding_tables[1] && !binding_tables[2]);
1824 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1825 binding_tables[0], binding_tables[3], binding_tables[4]);
1826
Chia-I Wu625105f2014-10-13 15:35:29 +08001827 assert(!samplers[1] && !samplers[2]);
1828 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1829 samplers[0], samplers[3], samplers[4]);
1830 }
1831}
1832
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001833static void emit_rt(struct intel_cmd *cmd)
1834{
1835 cmd_wa_gen6_pre_depth_stall_write(cmd);
1836 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.att.width,
1837 cmd->bind.att.height);
1838}
1839
1840static void emit_ds(struct intel_cmd *cmd)
1841{
1842 const struct intel_ds_view *ds = cmd->bind.att.ds;
1843
1844 if (!ds) {
1845 /* all zeros */
1846 static const struct intel_ds_view null_ds;
1847 ds = &null_ds;
1848 }
1849
1850 cmd_wa_gen6_pre_ds_flush(cmd);
1851 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1852 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1853 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1854
1855 if (cmd_gen(cmd) >= INTEL_GEN(7))
1856 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1857 else
1858 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1859}
1860
Chia-I Wua57761b2014-10-14 14:27:44 +08001861static uint32_t emit_shader(struct intel_cmd *cmd,
1862 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001863{
Chia-I Wua57761b2014-10-14 14:27:44 +08001864 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1865 uint32_t offset;
1866 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001867
Chia-I Wua57761b2014-10-14 14:27:44 +08001868 /* see if the shader is already in the cache */
1869 for (i = 0; i < cache->used; i++) {
1870 if (cache->entries[i].shader == (const void *) shader)
1871 return cache->entries[i].kernel_offset;
1872 }
1873
1874 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1875
1876 /* grow the cache if full */
1877 if (cache->used >= cache->count) {
1878 const XGL_UINT count = cache->count + 16;
1879 void *entries;
1880
1881 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1882 XGL_SYSTEM_ALLOC_INTERNAL);
1883 if (entries) {
1884 if (cache->entries) {
1885 memcpy(entries, cache->entries,
1886 sizeof(cache->entries[0]) * cache->used);
1887 icd_free(cache->entries);
1888 }
1889
1890 cache->entries = entries;
1891 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001892 }
1893 }
1894
Chia-I Wua57761b2014-10-14 14:27:44 +08001895 /* add the shader to the cache */
1896 if (cache->used < cache->count) {
1897 cache->entries[cache->used].shader = (const void *) shader;
1898 cache->entries[cache->used].kernel_offset = offset;
1899 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001900 }
1901
Chia-I Wua57761b2014-10-14 14:27:44 +08001902 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001903}
1904
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001905static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001906{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001907 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001908
Chia-I Wu8370b402014-08-29 12:28:37 +08001909 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1910 cmd_wa_gen6_pre_depth_stall_write(cmd);
1911 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1912 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1913 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1914 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001915
1916 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001917 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001918 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001919
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001920 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001921 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001922 }
1923 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001924 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001925 }
1926 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001927 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1928 }
1929 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1930 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1931 }
1932 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1933 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001934 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001935
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001936 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1937 gen7_3DSTATE_GS(cmd);
1938 } else {
1939 gen6_3DSTATE_GS(cmd);
1940 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001941
Chia-I Wu8370b402014-08-29 12:28:37 +08001942 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1943 cmd_wa_gen7_post_command_cs_stall(cmd);
1944 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1945 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001946}
1947
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001948static void emit_bounded_states(struct intel_cmd *cmd)
1949{
1950 const struct intel_msaa_state *msaa = cmd->bind.state.msaa;
1951
1952 emit_graphics_pipeline(cmd);
1953
1954 emit_rt(cmd);
1955 emit_ds(cmd);
1956
1957 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1958 gen7_cc_states(cmd);
1959 gen7_viewport_states(cmd);
1960
1961 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1962 &cmd->bind.pipeline.graphics->vs);
1963 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1964 &cmd->bind.pipeline.graphics->fs);
1965
1966 gen6_3DSTATE_CLIP(cmd);
1967 gen7_3DSTATE_SF(cmd);
1968 gen7_3DSTATE_SBE(cmd);
1969 gen7_3DSTATE_WM(cmd);
1970 gen7_3DSTATE_PS(cmd);
1971 } else {
1972 gen6_cc_states(cmd);
1973 gen6_viewport_states(cmd);
1974
1975 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1976 &cmd->bind.pipeline.graphics->vs);
1977 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1978 &cmd->bind.pipeline.graphics->fs);
1979
1980 gen6_3DSTATE_CLIP(cmd);
1981 gen6_3DSTATE_SF(cmd);
1982 gen6_3DSTATE_WM(cmd);
1983 }
1984
1985 emit_shader_resources(cmd);
1986
1987 cmd_wa_gen6_pre_depth_stall_write(cmd);
1988 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1989
1990 /* 3DSTATE_MULTISAMPLE and 3DSTATE_SAMPLE_MASK */
1991 cmd_batch_write(cmd, msaa->cmd_len, msaa->cmd);
1992
1993 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1994 gen6_3DSTATE_VS(cmd);
1995}
1996
Chia-I Wu6032b892014-10-17 14:47:18 +08001997static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
1998{
1999 const struct intel_cmd_meta *meta = cmd->bind.meta;
2000 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2001
2002 CMD_ASSERT(cmd, 6, 7.5);
2003
2004 blend_offset = 0;
2005 ds_offset = 0;
2006 cc_offset = 0;
2007 cc_vp_offset = 0;
2008
2009 if (meta->dst.valid) {
2010 /* BLEND_STATE */
2011 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
2012 GEN6_ALIGNMENT_BLEND_STATE * 4, 2, &dw);
2013 dw[0] = 0;
2014 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2015 }
2016
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002017 if (meta->ds.state) {
2018 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002019
2020 /* DEPTH_STENCIL_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002021 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, meta->ds.state);
Chia-I Wu6032b892014-10-17 14:47:18 +08002022
2023 /* COLOR_CALC_STATE */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002024 cc_offset = gen6_COLOR_CALC_STATE(cmd,
2025 meta->ds.state->cmd_stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002026
2027 /* CC_VIEWPORT */
2028 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
2029 GEN6_ALIGNMENT_CC_VIEWPORT * 4, 2, &dw);
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002030 dw[0] = u_fui(0.0f);
2031 dw[1] = u_fui(1.0f);
Chia-I Wu6032b892014-10-17 14:47:18 +08002032 }
2033
2034 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2035 gen7_3dstate_pointer(cmd,
2036 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2037 blend_offset);
2038 gen7_3dstate_pointer(cmd,
2039 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2040 ds_offset);
2041 gen7_3dstate_pointer(cmd,
2042 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2043
2044 gen7_3dstate_pointer(cmd,
2045 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2046 cc_vp_offset);
2047 } else {
2048 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002049 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002050
2051 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2052 cmd_batch_pointer(cmd, 4, &dw);
2053 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2054 GEN6_PTR_VP_DW0_CC_CHANGED;
2055 dw[1] = 0;
2056 dw[2] = 0;
2057 dw[3] = cc_vp_offset;
2058 }
2059}
2060
2061static void gen6_meta_surface_states(struct intel_cmd *cmd)
2062{
2063 const struct intel_cmd_meta *meta = cmd->bind.meta;
2064 uint32_t binding_table[2];
2065 XGL_UINT surface_count = 0;
2066 uint32_t offset;
2067
2068 CMD_ASSERT(cmd, 6, 7.5);
2069
2070 /* SURFACE_STATE */
2071 if (meta->dst.valid) {
2072 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2073 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2074 meta->dst.surface_len, meta->dst.surface);
2075
2076 cmd_reserve_reloc(cmd, 1);
2077 cmd_surface_reloc(cmd, offset, 1,
2078 (struct intel_bo *) meta->dst.reloc_target,
2079 meta->dst.reloc_offset, meta->dst.reloc_flags);
2080
2081 binding_table[surface_count++] = offset;
2082 }
2083 if (meta->src.valid) {
2084 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
2085 GEN6_ALIGNMENT_SURFACE_STATE * 4,
2086 meta->src.surface_len, meta->src.surface);
2087
2088 cmd_reserve_reloc(cmd, 1);
2089 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2090 cmd_surface_reloc_writer(cmd, offset, 1,
2091 meta->src.reloc_target, meta->src.reloc_offset);
2092 } else {
2093 cmd_surface_reloc(cmd, offset, 1,
2094 (struct intel_bo *) meta->src.reloc_target,
2095 meta->src.reloc_offset, meta->src.reloc_flags);
2096 }
2097
2098 binding_table[surface_count++] = offset;
2099 }
2100
2101 /* BINDING_TABLE */
2102 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
2103 GEN6_ALIGNMENT_BINDING_TABLE_STATE * 4,
2104 surface_count, binding_table);
2105
2106 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2107 gen7_3dstate_pointer(cmd,
2108 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2109 offset);
2110 } else {
2111 /* 3DSTATE_BINDING_TABLE_POINTERS */
2112 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
2113 }
2114}
2115
2116static void gen6_meta_urb(struct intel_cmd *cmd)
2117{
2118 uint32_t *dw;
2119
2120 CMD_ASSERT(cmd, 6, 6);
2121
2122 /* 3DSTATE_URB */
2123 cmd_batch_pointer(cmd, 3, &dw);
2124 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
2125 dw[1] = 128 << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
2126 dw[2] = 0;
2127}
2128
2129static void gen7_meta_urb(struct intel_cmd *cmd)
2130{
2131 uint32_t *dw;
2132
2133 CMD_ASSERT(cmd, 7, 7.5);
2134
2135 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2136 cmd_batch_pointer(cmd, 10, &dw);
2137
2138 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
2139 dw[1] = 0;
2140 dw += 2;
2141
2142 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2143 dw[1] = 0;
2144 dw += 2;
2145
2146 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2147 dw[1] = 0;
2148 dw += 2;
2149
2150 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2151 dw[1] = 0;
2152 dw += 2;
2153
2154 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2155 dw[1] = 1;
2156
2157 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2158
2159 /* 3DSTATE_URB_x */
2160 cmd_batch_pointer(cmd, 8, &dw);
2161
2162 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2163 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
2164 512;
2165 dw += 2;
2166
2167 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2168 dw[1] = 0;
2169 dw += 2;
2170
2171 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2172 dw[1] = 0;
2173 dw += 2;
2174
2175 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2176 dw[1] = 0;
2177 dw += 2;
2178}
2179
2180static void gen6_meta_vf(struct intel_cmd *cmd)
2181{
2182 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002183 uint32_t vb_start, vb_end, vb_stride;
2184 int ve_format, ve_z_source;
2185 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002186 XGL_UINT pos;
2187
2188 CMD_ASSERT(cmd, 6, 7.5);
2189
2190 /* write vertices */
Chia-I Wu3adf7212014-10-24 15:34:07 +08002191 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2192 XGL_FLOAT vertices[3][3];
2193
2194 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2195 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2196 vertices[0][2] = u_uif(meta->clear_val[0]);
2197 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2198 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2199 vertices[1][2] = u_uif(meta->clear_val[0]);
2200 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2201 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2202 vertices[2][2] = u_uif(meta->clear_val[0]);
2203
2204 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2205 sizeof(vertices) / 4, (const uint32_t *) vertices);
2206
2207 vb_end = vb_start + sizeof(vertices) - 1;
2208 vb_stride = sizeof(vertices[0]);
2209 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2210 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2211 } else {
2212 XGL_UINT vertices[3][2];
2213
2214 vertices[0][0] = meta->dst.x + meta->width;
2215 vertices[0][1] = meta->dst.y + meta->height;
2216 vertices[1][0] = meta->dst.x;
2217 vertices[1][1] = meta->dst.y + meta->height;
2218 vertices[2][0] = meta->dst.x;
2219 vertices[2][1] = meta->dst.y;
2220
2221 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2222 sizeof(vertices) / 4, (const uint32_t *) vertices);
2223
2224 vb_end = vb_start + sizeof(vertices) - 1;
2225 vb_stride = sizeof(vertices[0]);
2226 ve_z_source = GEN6_VFCOMP_STORE_0;
2227 ve_format = GEN6_FORMAT_R32G32_USCALED;
2228 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002229
2230 /* 3DSTATE_VERTEX_BUFFERS */
2231 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002232
Chia-I Wu6032b892014-10-17 14:47:18 +08002233 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002234 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002235 if (cmd_gen(cmd) >= INTEL_GEN(7))
2236 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2237
2238 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002239 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2240 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002241
2242 dw[4] = 0;
2243
2244 /* 3DSTATE_VERTEX_ELEMENTS */
2245 cmd_batch_pointer(cmd, 5, &dw);
2246 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
2247 dw[1] = GEN6_VE_STATE_DW0_VALID,
2248 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2249 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2250 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2251 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2252 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002253 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002254 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2255 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002256 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002257 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2258}
2259
2260static void gen6_meta_disabled(struct intel_cmd *cmd)
2261{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002262 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002263 uint32_t *dw;
2264
2265 CMD_ASSERT(cmd, 6, 6);
2266
2267 /* 3DSTATE_CONSTANT_VS */
2268 cmd_batch_pointer(cmd, 5, &dw);
2269 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2);
2270 dw[1] = 0;
2271 dw[2] = 0;
2272 dw[3] = 0;
2273 dw[4] = 0;
2274
2275 /* 3DSTATE_VS */
2276 cmd_batch_pointer(cmd, 6, &dw);
2277 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2278 dw[1] = 0;
2279 dw[2] = 0;
2280 dw[3] = 0;
2281 dw[4] = 0;
2282 dw[5] = 0;
2283
2284 /* 3DSTATE_CONSTANT_GS */
2285 cmd_batch_pointer(cmd, 5, &dw);
2286 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2287 dw[1] = 0;
2288 dw[2] = 0;
2289 dw[3] = 0;
2290 dw[4] = 0;
2291
2292 /* 3DSTATE_GS */
2293 cmd_batch_pointer(cmd, 7, &dw);
2294 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2295 dw[1] = 0;
2296 dw[2] = 0;
2297 dw[3] = 0;
2298 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2299 dw[5] = GEN6_GS_DW5_STATISTICS;
2300 dw[6] = 0;
2301
2302 /* 3DSTATE_CLIP */
2303 cmd_batch_pointer(cmd, 4, &dw);
2304 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2305 dw[1] = 0;
2306 dw[2] = 0;
2307 dw[3] = 0;
2308
2309 /* 3DSTATE_SF */
2310 cmd_batch_pointer(cmd, 20, &dw);
2311 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2312 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2313 memset(&dw[2], 0, 18 * sizeof(*dw));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002314
2315 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2316 /* 3DSTATE_CONSTANT_PS */
2317 cmd_batch_pointer(cmd, 5, &dw);
2318 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2319 dw[1] = 0;
2320 dw[2] = 0;
2321 dw[3] = 0;
2322 dw[4] = 0;
2323
2324 /* 3DSTATE_WM */
2325 cmd_batch_pointer(cmd, 9, &dw);
2326 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2327 dw[1] = 0;
2328 dw[2] = 0;
2329 dw[3] = 0;
2330 dw[4] = 0;
2331 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
2332 dw[6] = 0;
2333 dw[7] = 0;
2334 dw[8] = 0;
2335 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002336}
2337
2338static void gen7_meta_disabled(struct intel_cmd *cmd)
2339{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002340 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu6032b892014-10-17 14:47:18 +08002341 uint32_t *dw;
2342
2343 CMD_ASSERT(cmd, 7, 7.5);
2344
2345 /* 3DSTATE_CONSTANT_VS */
2346 cmd_batch_pointer(cmd, 7, &dw);
2347 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2348 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2349
2350 /* 3DSTATE_VS */
2351 cmd_batch_pointer(cmd, 6, &dw);
2352 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2353 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2354
2355 /* 3DSTATE_CONSTANT_HS */
2356 cmd_batch_pointer(cmd, 7, &dw);
2357 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2358 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2359
2360 /* 3DSTATE_HS */
2361 cmd_batch_pointer(cmd, 7, &dw);
2362 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2363 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2364
2365 /* 3DSTATE_TE */
2366 cmd_batch_pointer(cmd, 4, &dw);
2367 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2368 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2369
2370 /* 3DSTATE_CONSTANT_DS */
2371 cmd_batch_pointer(cmd, 7, &dw);
2372 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2373 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2374
2375 /* 3DSTATE_DS */
2376 cmd_batch_pointer(cmd, 6, &dw);
2377 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2378 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2379
2380 /* 3DSTATE_CONSTANT_GS */
2381 cmd_batch_pointer(cmd, 7, &dw);
2382 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2383 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2384
2385 /* 3DSTATE_GS */
2386 cmd_batch_pointer(cmd, 7, &dw);
2387 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2388 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2389
2390 /* 3DSTATE_STREAMOUT */
2391 cmd_batch_pointer(cmd, 3, &dw);
2392 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2393 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2394
2395 /* 3DSTATE_CLIP */
2396 cmd_batch_pointer(cmd, 4, &dw);
2397 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2398 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2399
2400 /* 3DSTATE_SF */
2401 cmd_batch_pointer(cmd, 7, &dw);
2402 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2403 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2404
2405 /* 3DSTATE_SBE */
2406 cmd_batch_pointer(cmd, 14, &dw);
2407 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2408 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2409 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu3adf7212014-10-24 15:34:07 +08002410
2411 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH) {
2412 /* 3DSTATE_WM */
2413 cmd_batch_pointer(cmd, 3, &dw);
2414 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2415 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2416
2417 /* 3DSTATE_CONSTANT_GS */
2418 cmd_batch_pointer(cmd, 7, &dw);
2419 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2420 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2421
2422 /* 3DSTATE_PS */
2423 cmd_batch_pointer(cmd, 8, &dw);
2424 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2425 dw[1] = 0;
2426 dw[2] = 0;
2427 dw[3] = 0;
2428 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
2429 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2430 dw[5] = 0;
2431 dw[6] = 0;
2432 dw[7] = 0;
2433 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002434}
2435
2436static void gen6_meta_wm(struct intel_cmd *cmd)
2437{
2438 const struct intel_cmd_meta *meta = cmd->bind.meta;
2439 uint32_t *dw;
2440
2441 CMD_ASSERT(cmd, 6, 7.5);
2442
2443 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2444
2445 /* 3DSTATE_MULTISAMPLE */
2446 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2447 cmd_batch_pointer(cmd, 4, &dw);
2448 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2449 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2450 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2451 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2452 dw[2] = 0;
2453 dw[3] = 0;
2454 } else {
2455 cmd_batch_pointer(cmd, 3, &dw);
2456 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2457 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2458 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2459 dw[2] = 0;
2460 }
2461
2462 /* 3DSTATE_SAMPLE_MASK */
2463 cmd_batch_pointer(cmd, 2, &dw);
2464 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2465 dw[1] = (1 << meta->samples) - 1;
2466
2467 /* 3DSTATE_DRAWING_RECTANGLE */
2468 cmd_batch_pointer(cmd, 4, &dw);
2469 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2470 dw[1] = meta->dst.y << 16 | meta->dst.x;
2471 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2472 (meta->dst.x + meta->width - 1);
2473 dw[3] = 0;
2474}
2475
2476static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2477{
2478 const struct intel_cmd_meta *meta = cmd->bind.meta;
2479 XGL_UINT offset_x, offset_y;
2480 /* one GPR */
2481 XGL_UINT consts[8];
2482 XGL_UINT const_count;
2483
2484 CMD_ASSERT(cmd, 6, 7.5);
2485
2486 /* underflow is fine here */
2487 offset_x = meta->src.x - meta->dst.x;
2488 offset_y = meta->src.y - meta->dst.y;
2489
2490 switch (meta->shader_id) {
2491 case INTEL_DEV_META_FS_COPY_MEM:
2492 case INTEL_DEV_META_FS_COPY_1D:
2493 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2494 case INTEL_DEV_META_FS_COPY_2D:
2495 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2496 case INTEL_DEV_META_FS_COPY_2D_MS:
2497 consts[0] = offset_x;
2498 consts[1] = offset_y;
2499 consts[2] = meta->src.layer;
2500 consts[3] = meta->src.lod;
2501 const_count = 4;
2502 break;
2503 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2504 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2505 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2506 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2507 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2508 consts[0] = offset_x;
2509 consts[1] = offset_y;
2510 consts[2] = meta->src.layer;
2511 consts[3] = meta->src.lod;
2512 consts[4] = meta->src.x;
2513 consts[5] = meta->width;
2514 const_count = 6;
2515 break;
2516 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2517 consts[0] = offset_x;
2518 consts[1] = offset_y;
2519 consts[2] = meta->width;
2520 const_count = 3;
2521 break;
2522 case INTEL_DEV_META_FS_CLEAR_COLOR:
2523 consts[0] = meta->clear_val[0];
2524 consts[1] = meta->clear_val[1];
2525 consts[2] = meta->clear_val[2];
2526 consts[3] = meta->clear_val[3];
2527 const_count = 4;
2528 break;
2529 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2530 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002531 consts[1] = meta->clear_val[1];
2532 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002533 break;
2534 case INTEL_DEV_META_FS_RESOLVE_2X:
2535 case INTEL_DEV_META_FS_RESOLVE_4X:
2536 case INTEL_DEV_META_FS_RESOLVE_8X:
2537 case INTEL_DEV_META_FS_RESOLVE_16X:
2538 consts[0] = offset_x;
2539 consts[1] = offset_y;
2540 const_count = 2;
2541 break;
2542 default:
2543 assert(!"unknown meta shader id");
2544 const_count = 0;
2545 break;
2546 }
2547
2548 /* this can be skipped but it makes state dumping prettier */
2549 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2550
2551 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2552}
2553
2554static void gen6_meta_ps(struct intel_cmd *cmd)
2555{
2556 const struct intel_cmd_meta *meta = cmd->bind.meta;
2557 const struct intel_pipeline_shader *sh =
2558 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2559 uint32_t offset, *dw;
2560
2561 CMD_ASSERT(cmd, 6, 6);
2562
Chia-I Wu3adf7212014-10-24 15:34:07 +08002563 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2564 return;
2565 /* a normal color write */
2566 assert(meta->dst.valid && !sh->uses);
2567
Chia-I Wu6032b892014-10-17 14:47:18 +08002568 /* 3DSTATE_CONSTANT_PS */
2569 offset = gen6_meta_ps_constants(cmd);
2570 cmd_batch_pointer(cmd, 5, &dw);
2571 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2572 GEN6_PCB_ANY_DW0_PCB0_VALID;
2573 dw[1] = offset;
2574 dw[2] = 0;
2575 dw[3] = 0;
2576 dw[4] = 0;
2577
2578 /* 3DSTATE_WM */
2579 offset = emit_shader(cmd, sh);
2580 cmd_batch_pointer(cmd, 9, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2582 dw[1] = offset;
2583 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2584 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2585 dw[3] = 0;
2586 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
2587 dw[5] = (40 - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
2588 GEN6_WM_DW5_PS_ENABLE |
2589 GEN6_WM_DW5_8_PIXEL_DISPATCH;
2590 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2591 GEN6_WM_DW6_POSOFFSET_NONE |
2592 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2593 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2594 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2595 if (meta->samples > 1) {
2596 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2597 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2598 } else {
2599 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2600 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2601 }
2602 dw[7] = 0;
2603 dw[8] = 0;
2604}
2605
2606static void gen7_meta_ps(struct intel_cmd *cmd)
2607{
2608 const struct intel_cmd_meta *meta = cmd->bind.meta;
2609 const struct intel_pipeline_shader *sh =
2610 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2611 uint32_t offset, *dw;
2612
2613 CMD_ASSERT(cmd, 7, 7.5);
2614
Chia-I Wu3adf7212014-10-24 15:34:07 +08002615 if (meta->shader_id == INTEL_DEV_META_FS_CLEAR_DEPTH)
2616 return;
2617 /* a normal color write */
2618 assert(meta->dst.valid && !sh->uses);
2619
Chia-I Wu6032b892014-10-17 14:47:18 +08002620 /* 3DSTATE_WM */
2621 cmd_batch_pointer(cmd, 3, &dw);
2622 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2623 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2624 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2625 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2626 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2627 dw[2] = 0;
2628
2629 /* 3DSTATE_CONSTANT_PS */
2630 offset = gen6_meta_ps_constants(cmd);
2631 cmd_batch_pointer(cmd, 7, &dw);
2632 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2633 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2634 dw[2] = 0;
2635 dw[3] = offset;
2636 dw[4] = 0;
2637 dw[5] = 0;
2638 dw[6] = 0;
2639
2640 /* 3DSTATE_PS */
2641 offset = emit_shader(cmd, sh);
2642 cmd_batch_pointer(cmd, 8, &dw);
2643 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2644 dw[1] = offset;
2645 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2646 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
2647 dw[3] = 0;
2648
2649 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2650 GEN7_PS_DW4_POSOFFSET_NONE |
2651 GEN7_PS_DW4_8_PIXEL_DISPATCH |
2652 (48 - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
2653 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
2654 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
2655
2656 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2657 dw[6] = 0;
2658 dw[7] = 0;
2659}
2660
2661static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2662{
2663 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002664 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002665
2666 CMD_ASSERT(cmd, 6, 7.5);
2667
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002668 if (!ds) {
2669 /* all zeros */
2670 static const struct intel_ds_view null_ds;
2671 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002672 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002673
2674 cmd_wa_gen6_pre_ds_flush(cmd);
2675 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2676 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2677 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2678
2679 if (cmd_gen(cmd) >= INTEL_GEN(7))
2680 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2681 else
2682 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002683}
2684
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002685static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2686 const struct intel_pipeline *pipeline)
2687{
2688 cmd->bind.pipeline.graphics = pipeline;
2689}
2690
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002691static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2692 const struct intel_pipeline *pipeline)
2693{
2694 cmd->bind.pipeline.compute = pipeline;
2695}
2696
2697static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2698 const struct intel_pipeline_delta *delta)
2699{
2700 cmd->bind.pipeline.graphics_delta = delta;
2701}
2702
2703static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2704 const struct intel_pipeline_delta *delta)
2705{
2706 cmd->bind.pipeline.compute_delta = delta;
2707}
2708
2709static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
2710 const struct intel_dset *dset,
2711 XGL_UINT slot_offset)
2712{
2713 cmd->bind.dset.graphics = dset;
2714 cmd->bind.dset.graphics_offset = slot_offset;
2715}
2716
2717static void cmd_bind_compute_dset(struct intel_cmd *cmd,
2718 const struct intel_dset *dset,
2719 XGL_UINT slot_offset)
2720{
2721 cmd->bind.dset.compute = dset;
2722 cmd->bind.dset.compute_offset = slot_offset;
2723}
2724
2725static void cmd_bind_graphics_dyn_view(struct intel_cmd *cmd,
2726 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2727{
2728 intel_mem_view_init(&cmd->bind.dyn_view.graphics, cmd->dev, info);
2729}
2730
2731static void cmd_bind_compute_dyn_view(struct intel_cmd *cmd,
2732 const XGL_MEMORY_VIEW_ATTACH_INFO *info)
2733{
2734 intel_mem_view_init(&cmd->bind.dyn_view.compute, cmd->dev, info);
2735}
2736
2737static void cmd_bind_index_data(struct intel_cmd *cmd,
2738 const struct intel_mem *mem,
2739 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2740{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002741 cmd->bind.index.mem = mem;
2742 cmd->bind.index.offset = offset;
2743 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002744}
2745
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002746static void cmd_bind_attachments(struct intel_cmd *cmd,
2747 XGL_UINT rt_count,
2748 const XGL_COLOR_ATTACHMENT_BIND_INFO *rt_info,
2749 const XGL_DEPTH_STENCIL_BIND_INFO *ds_info)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002750{
Chia-I Wud88e02d2014-08-25 10:56:13 +08002751 XGL_UINT width = 0, height = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002752 XGL_UINT i;
2753
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002754 for (i = 0; i < rt_count; i++) {
2755 const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &rt_info[i];
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002756 const struct intel_rt_view *rt = intel_rt_view(att->view);
Chia-I Wud88e02d2014-08-25 10:56:13 +08002757 const struct intel_layout *layout = &rt->img->layout;
2758
2759 if (i == 0) {
2760 width = layout->width0;
2761 height = layout->height0;
2762 } else {
2763 if (width > layout->width0)
2764 width = layout->width0;
2765 if (height > layout->height0)
2766 height = layout->height0;
2767 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002768
2769 cmd->bind.att.rt[i] = rt;
2770 }
2771
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002772 cmd->bind.att.rt_count = rt_count;
Chia-I Wud88e02d2014-08-25 10:56:13 +08002773
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002774 if (ds_info) {
2775 const struct intel_layout *layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002776
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002777 cmd->bind.att.ds = intel_ds_view(ds_info->view);
2778 layout = &cmd->bind.att.ds->img->layout;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002779
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002780 if (width > layout->width0)
2781 width = layout->width0;
2782 if (height > layout->height0)
2783 height = layout->height0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002784 } else {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002785 cmd->bind.att.ds = NULL;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002786 }
2787
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002788 cmd->bind.att.width = width;
2789 cmd->bind.att.height = height;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002790}
2791
2792static void cmd_bind_viewport_state(struct intel_cmd *cmd,
2793 const struct intel_viewport_state *state)
2794{
2795 cmd->bind.state.viewport = state;
2796}
2797
2798static void cmd_bind_raster_state(struct intel_cmd *cmd,
2799 const struct intel_raster_state *state)
2800{
2801 cmd->bind.state.raster = state;
2802}
2803
2804static void cmd_bind_ds_state(struct intel_cmd *cmd,
2805 const struct intel_ds_state *state)
2806{
2807 cmd->bind.state.ds = state;
2808}
2809
2810static void cmd_bind_blend_state(struct intel_cmd *cmd,
2811 const struct intel_blend_state *state)
2812{
2813 cmd->bind.state.blend = state;
2814}
2815
2816static void cmd_bind_msaa_state(struct intel_cmd *cmd,
2817 const struct intel_msaa_state *state)
2818{
2819 cmd->bind.state.msaa = state;
2820}
2821
2822static void cmd_draw(struct intel_cmd *cmd,
2823 XGL_UINT vertex_start,
2824 XGL_UINT vertex_count,
2825 XGL_UINT instance_start,
2826 XGL_UINT instance_count,
2827 bool indexed,
2828 XGL_UINT vertex_base)
2829{
2830 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2831
2832 emit_bounded_states(cmd);
2833
2834 if (indexed) {
2835 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2836 cmd->result = XGL_ERROR_UNKNOWN;
2837
2838 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2839 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2840 p->primitive_restart_index);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002841 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2842 cmd->bind.index.offset, cmd->bind.index.type,
2843 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002844 } else {
2845 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.mem,
2846 cmd->bind.index.offset, cmd->bind.index.type,
2847 p->primitive_restart);
2848 }
2849 } else {
2850 assert(!vertex_base);
2851 }
2852
2853 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2854 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2855 vertex_start, instance_count, instance_start, vertex_base);
2856 } else {
2857 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2858 vertex_start, instance_count, instance_start, vertex_base);
2859 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002860
Chia-I Wu707a29e2014-08-27 12:51:47 +08002861 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002862 /* need to re-emit all workarounds */
2863 cmd->bind.wa_flags = 0;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002864}
2865
Chia-I Wuc14d1562014-10-17 09:49:22 +08002866void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2867{
Chia-I Wu6032b892014-10-17 14:47:18 +08002868 cmd->bind.meta = meta;
2869
2870 cmd_wa_gen6_pre_depth_stall_write(cmd);
2871
2872 gen6_meta_dynamic_states(cmd);
2873 gen6_meta_surface_states(cmd);
2874
2875 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2876 gen7_meta_urb(cmd);
2877 gen6_meta_vf(cmd);
2878 gen7_meta_disabled(cmd);
2879 gen6_meta_wm(cmd);
2880 gen7_meta_ps(cmd);
2881 gen6_meta_depth_buffer(cmd);
2882
2883 cmd_wa_gen7_post_command_cs_stall(cmd);
2884 cmd_wa_gen7_post_command_depth_stall(cmd);
2885
2886 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2887 } else {
2888 gen6_meta_urb(cmd);
2889 gen6_meta_vf(cmd);
2890 gen6_meta_disabled(cmd);
2891 gen6_meta_wm(cmd);
2892 gen6_meta_ps(cmd);
2893 gen6_meta_depth_buffer(cmd);
2894
2895 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
2896 }
2897
2898 cmd->bind.draw_count++;
2899 /* need to re-emit all workarounds */
2900 cmd->bind.wa_flags = 0;
2901
2902 cmd->bind.meta = NULL;
Chia-I Wuc14d1562014-10-17 09:49:22 +08002903}
2904
Chia-I Wub2755562014-08-20 13:38:52 +08002905XGL_VOID XGLAPI intelCmdBindPipeline(
2906 XGL_CMD_BUFFER cmdBuffer,
2907 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2908 XGL_PIPELINE pipeline)
2909{
2910 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2911
2912 switch (pipelineBindPoint) {
2913 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002914 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002915 break;
2916 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002917 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08002918 break;
2919 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002920 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002921 break;
2922 }
2923}
2924
2925XGL_VOID XGLAPI intelCmdBindPipelineDelta(
2926 XGL_CMD_BUFFER cmdBuffer,
2927 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2928 XGL_PIPELINE_DELTA delta)
2929{
2930 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2931
2932 switch (pipelineBindPoint) {
2933 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002934 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002935 break;
2936 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08002938 break;
2939 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002940 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002941 break;
2942 }
2943}
2944
2945XGL_VOID XGLAPI intelCmdBindStateObject(
2946 XGL_CMD_BUFFER cmdBuffer,
2947 XGL_STATE_BIND_POINT stateBindPoint,
2948 XGL_STATE_OBJECT state)
2949{
2950 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2951
2952 switch (stateBindPoint) {
2953 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002954 cmd_bind_viewport_state(cmd,
2955 intel_viewport_state((XGL_VIEWPORT_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002956 break;
2957 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002958 cmd_bind_raster_state(cmd,
2959 intel_raster_state((XGL_RASTER_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002960 break;
2961 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002962 cmd_bind_ds_state(cmd,
2963 intel_ds_state((XGL_DEPTH_STENCIL_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002964 break;
2965 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002966 cmd_bind_blend_state(cmd,
2967 intel_blend_state((XGL_COLOR_BLEND_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002968 break;
2969 case XGL_STATE_BIND_MSAA:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002970 cmd_bind_msaa_state(cmd,
2971 intel_msaa_state((XGL_MSAA_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08002972 break;
2973 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002974 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08002975 break;
2976 }
2977}
2978
2979XGL_VOID XGLAPI intelCmdBindDescriptorSet(
2980 XGL_CMD_BUFFER cmdBuffer,
2981 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
2982 XGL_UINT index,
2983 XGL_DESCRIPTOR_SET descriptorSet,
2984 XGL_UINT slotOffset)
2985{
2986 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
2987 struct intel_dset *dset = intel_dset(descriptorSet);
2988
2989 assert(!index);
2990
2991 switch (pipelineBindPoint) {
2992 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002993 cmd_bind_compute_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002994 break;
2995 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002996 cmd_bind_graphics_dset(cmd, dset, slotOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08002997 break;
2998 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002999 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003000 break;
3001 }
3002}
3003
3004XGL_VOID XGLAPI intelCmdBindDynamicMemoryView(
3005 XGL_CMD_BUFFER cmdBuffer,
3006 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3007 const XGL_MEMORY_VIEW_ATTACH_INFO* pMemView)
3008{
3009 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3010
3011 switch (pipelineBindPoint) {
3012 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003013 cmd_bind_compute_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003014 break;
3015 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003016 cmd_bind_graphics_dyn_view(cmd, pMemView);
Chia-I Wub2755562014-08-20 13:38:52 +08003017 break;
3018 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003019 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003020 break;
3021 }
3022}
3023
3024XGL_VOID XGLAPI intelCmdBindIndexData(
3025 XGL_CMD_BUFFER cmdBuffer,
3026 XGL_GPU_MEMORY mem_,
3027 XGL_GPU_SIZE offset,
3028 XGL_INDEX_TYPE indexType)
3029{
3030 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3031 struct intel_mem *mem = intel_mem(mem_);
3032
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003033 cmd_bind_index_data(cmd, mem, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003034}
3035
3036XGL_VOID XGLAPI intelCmdBindAttachments(
3037 XGL_CMD_BUFFER cmdBuffer,
3038 XGL_UINT colorAttachmentCount,
3039 const XGL_COLOR_ATTACHMENT_BIND_INFO* pColorAttachments,
3040 const XGL_DEPTH_STENCIL_BIND_INFO* pDepthStencilAttachment)
3041{
3042 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003043
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08003044 cmd_bind_attachments(cmd, colorAttachmentCount, pColorAttachments,
3045 pDepthStencilAttachment);
Chia-I Wub2755562014-08-20 13:38:52 +08003046}
3047
3048XGL_VOID XGLAPI intelCmdDraw(
3049 XGL_CMD_BUFFER cmdBuffer,
3050 XGL_UINT firstVertex,
3051 XGL_UINT vertexCount,
3052 XGL_UINT firstInstance,
3053 XGL_UINT instanceCount)
3054{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003055 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003056
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003057 cmd_draw(cmd, firstVertex, vertexCount,
3058 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003059}
3060
3061XGL_VOID XGLAPI intelCmdDrawIndexed(
3062 XGL_CMD_BUFFER cmdBuffer,
3063 XGL_UINT firstIndex,
3064 XGL_UINT indexCount,
3065 XGL_INT vertexOffset,
3066 XGL_UINT firstInstance,
3067 XGL_UINT instanceCount)
3068{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003069 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003070
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003071 cmd_draw(cmd, firstIndex, indexCount,
3072 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003073}
3074
3075XGL_VOID XGLAPI intelCmdDrawIndirect(
3076 XGL_CMD_BUFFER cmdBuffer,
3077 XGL_GPU_MEMORY mem,
3078 XGL_GPU_SIZE offset,
3079 XGL_UINT32 count,
3080 XGL_UINT32 stride)
3081{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003082 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3083
3084 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003085}
3086
3087XGL_VOID XGLAPI intelCmdDrawIndexedIndirect(
3088 XGL_CMD_BUFFER cmdBuffer,
3089 XGL_GPU_MEMORY mem,
3090 XGL_GPU_SIZE offset,
3091 XGL_UINT32 count,
3092 XGL_UINT32 stride)
3093{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003094 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3095
3096 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003097}
3098
3099XGL_VOID XGLAPI intelCmdDispatch(
3100 XGL_CMD_BUFFER cmdBuffer,
3101 XGL_UINT x,
3102 XGL_UINT y,
3103 XGL_UINT z)
3104{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003105 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3106
3107 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003108}
3109
3110XGL_VOID XGLAPI intelCmdDispatchIndirect(
3111 XGL_CMD_BUFFER cmdBuffer,
3112 XGL_GPU_MEMORY mem,
3113 XGL_GPU_SIZE offset)
3114{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003115 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3116
3117 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003118}