blob: 26db520d1aad3ee8966e27800c31ec302ee95d8f [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
221 case XGL_INDEX_8:
222 supported = (p->primitive_restart_index != 0xffu);
223 break;
224 case XGL_INDEX_16:
225 supported = (p->primitive_restart_index != 0xffffu);
226 break;
227 case XGL_INDEX_32:
228 supported = (p->primitive_restart_index != 0xffffffffu);
229 break;
230 default:
231 supported = false;
232 break;
233 }
234
235 return supported;
236}
237
Chia-I Wu59c097e2014-08-21 10:51:07 +0800238static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800239 const struct intel_buf *buf,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 XGL_GPU_SIZE offset,
241 XGL_INDEX_TYPE type,
242 bool enable_cut_index)
243{
244 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800245 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600247 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
273 cmd->result = XGL_ERROR_INVALID_VALUE;
274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
279 cmd->result = XGL_ERROR_INVALID_VALUE;
280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600350 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800351{
352 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800353 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800354 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800355 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800356
357 CMD_ASSERT(cmd, 6, 7.5);
358
Chia-I Wu72292b72014-09-09 10:48:33 +0800359 cmd_batch_pointer(cmd, cmd_len, &dw);
360 dw[0] = dw0;
361
Chia-I Wud88e02d2014-08-25 10:56:13 +0800362 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[1] = 0;
364 dw[2] = (height - 1) << 16 |
365 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800366 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[1] = 1;
368 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800369 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800370
371 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800372}
373
Chia-I Wu8016a172014-08-29 18:31:32 +0800374static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
375 uint32_t body[6])
376{
377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700378 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800379 uint32_t dw1, dw2, dw3;
380 int point_width;
381
382 CMD_ASSERT(cmd, 6, 7.5);
383
384 dw1 = GEN7_SF_DW1_STATISTICS |
385 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
386 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
387 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
388 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700389 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800390
391 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
392 int format;
393
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700394 switch (pipeline->db_format) {
395 case XGL_FMT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
Jeremy Hayes2b7e88a2015-01-23 08:51:43 -0700398 case XGL_FMT_D32_SFLOAT:
399 case XGL_FMT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 if (pipeline->scissor_enable)
Chia-I Wu8016a172014-08-29 18:31:32 +0800422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600446 uint32_t sbe_offset;
447 int32_t i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700501 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800502 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503
504 CMD_ASSERT(cmd, 6, 7.5);
505
506 dw1 = GEN6_CLIP_DW1_STATISTICS;
507 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
508 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
509 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 }
512
513 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
514 GEN6_CLIP_DW2_XY_TEST_ENABLE |
515 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700516 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800517 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
518 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
520
521 if (pipeline->rasterizerDiscardEnable)
522 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
523 else
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
525
526 if (pipeline->depthClipEnable)
527 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
528
529 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
530 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
531 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
532 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
533
534 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
535 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
536 (viewport->viewport_count - 1);
537
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600538 /* TODO: framebuffer requests layer_count > 1 */
539 if (cmd->bind.render_pass->fb->layer_count == 1) {
540 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
541 }
542
Chia-I Wu72292b72014-09-09 10:48:33 +0800543 cmd_batch_pointer(cmd, cmd_len, &dw);
544 dw[0] = dw0;
545 dw[1] = dw1;
546 dw[2] = dw2;
547 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800548}
549
Chia-I Wu784d3042014-12-19 14:30:04 +0800550static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600551 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800552 const struct intel_pipeline *pipeline,
553 const struct intel_pipeline_shader *sh)
554{
555 int scratch_space;
556
557 CMD_ASSERT(cmd, 6, 7.5);
558
559 assert(sh->per_thread_scratch_size &&
560 sh->per_thread_scratch_size % 1024 == 0 &&
561 u_is_pow2(sh->per_thread_scratch_size) &&
562 sh->scratch_offset % 1024 == 0);
563 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
564
565 cmd_reserve_reloc(cmd, 1);
566 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
567 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
568}
569
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800570static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
571{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800573 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600575 uint32_t pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800576 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800577
578 CMD_ASSERT(cmd, 6, 6);
579
580 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
581
582 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
583 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
584
585 dw4 = GEN6_WM_DW4_STATISTICS |
586 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
587 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
588 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
589
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800590 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800591 GEN6_WM_DW5_PS_ENABLE |
592 GEN6_WM_DW5_8_PIXEL_DISPATCH;
593
594 if (fs->uses & INTEL_SHADER_USE_KILL ||
595 pipeline->cb_state.alphaToCoverageEnable)
596 dw5 |= GEN6_WM_DW5_PS_KILL;
597
Cody Northrope238deb2015-01-26 14:41:36 -0700598 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800599 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
600 if (fs->uses & INTEL_SHADER_USE_DEPTH)
601 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
602 if (fs->uses & INTEL_SHADER_USE_W)
603 dw5 |= GEN6_WM_DW5_PS_USE_W;
604
605 if (pipeline->cb_state.dualSourceBlendEnable)
606 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
607
608 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
609 GEN6_WM_DW6_POSOFFSET_NONE |
610 GEN6_WM_DW6_ZW_INTERP_PIXEL |
611 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
612 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
613
Tony Barbourfa6cac72015-01-16 14:27:35 -0700614 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800615 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
616 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
617 } else {
618 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
619 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
620 }
621
Chia-I Wu784d3042014-12-19 14:30:04 +0800622 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800623 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800624 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800625 dw[2] = dw2;
626 dw[3] = 0; /* scratch */
627 dw[4] = dw4;
628 dw[5] = dw5;
629 dw[6] = dw6;
630 dw[7] = 0; /* kernel 1 */
631 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800632
633 if (fs->per_thread_scratch_size)
634 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635}
636
637static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
638{
639 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800640 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800642 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643
644 CMD_ASSERT(cmd, 7, 7.5);
645
646 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
647
648 dw1 = GEN7_WM_DW1_STATISTICS |
649 GEN7_WM_DW1_PS_ENABLE |
650 GEN7_WM_DW1_ZW_INTERP_PIXEL |
651 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
652 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
653
654 if (fs->uses & INTEL_SHADER_USE_KILL ||
655 pipeline->cb_state.alphaToCoverageEnable)
656 dw1 |= GEN7_WM_DW1_PS_KILL;
657
Cody Northrope238deb2015-01-26 14:41:36 -0700658 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
659
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660 if (fs->uses & INTEL_SHADER_USE_DEPTH)
661 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
662 if (fs->uses & INTEL_SHADER_USE_W)
663 dw1 |= GEN7_WM_DW1_PS_USE_W;
664
665 dw2 = 0;
666
Tony Barbourfa6cac72015-01-16 14:27:35 -0700667 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
669 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
670 } else {
671 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
672 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
673 }
674
Chia-I Wu72292b72014-09-09 10:48:33 +0800675 cmd_batch_pointer(cmd, cmd_len, &dw);
676 dw[0] = dw0;
677 dw[1] = dw1;
678 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679}
680
681static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
682{
683 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800684 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 uint32_t dw0, dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600687 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688
689 CMD_ASSERT(cmd, 7, 7.5);
690
691 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
692
693 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
694 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
695
696 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
697 GEN7_PS_DW4_8_PIXEL_DISPATCH;
698
699 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800700 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700701 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800702 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800703 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 }
705
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706 if (fs->in_count)
707 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
708
709 if (pipeline->cb_state.dualSourceBlendEnable)
710 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
711
712 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
713 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
714 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
715
Chia-I Wu784d3042014-12-19 14:30:04 +0800716 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800718 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800719 dw[2] = dw2;
720 dw[3] = 0; /* scratch */
721 dw[4] = dw4;
722 dw[5] = dw5;
723 dw[6] = 0; /* kernel 1 */
724 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800725
726 if (fs->per_thread_scratch_size)
727 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800728}
729
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800730static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
731 const struct intel_ds_view *view)
732{
733 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800734 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600735 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800736
737 CMD_ASSERT(cmd, 6, 7.5);
738
739 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800740 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
741 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800742 dw0 |= (cmd_len - 2);
743
Chia-I Wu72292b72014-09-09 10:48:33 +0800744 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
745 dw[0] = dw0;
746 dw[1] = view->cmd[0];
747 dw[2] = 0;
748 dw[3] = view->cmd[2];
749 dw[4] = view->cmd[3];
750 dw[5] = view->cmd[4];
751 dw[6] = view->cmd[5];
752
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600753 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800754 cmd_reserve_reloc(cmd, 1);
755 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
756 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600757 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800758}
759
760static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
761 const struct intel_ds_view *view)
762{
763 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800764 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600765 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800766
767 CMD_ASSERT(cmd, 6, 7.5);
768
769 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800770 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
771 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800772 dw0 |= (cmd_len - 2);
773
Chia-I Wu72292b72014-09-09 10:48:33 +0800774 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
775 dw[0] = dw0;
776 dw[1] = view->cmd[6];
777 dw[2] = 0;
778
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600779 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800780 cmd_reserve_reloc(cmd, 1);
781 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
782 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600783 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784}
785
786static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
787 const struct intel_ds_view *view)
788{
789 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600791 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792
793 CMD_ASSERT(cmd, 6, 7.5);
794
795 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800796 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
797 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800798 dw0 |= (cmd_len - 2);
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
801 dw[0] = dw0;
802 dw[1] = view->cmd[8];
803 dw[2] = 0;
804
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600805 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_reserve_reloc(cmd, 1);
807 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
808 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600809 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800810}
811
Chia-I Wuf8231032014-08-25 10:44:45 +0800812static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
813 uint32_t clear_val)
814{
815 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800816 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800817 GEN6_CLEAR_PARAMS_DW0_VALID |
818 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800819 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800820
821 CMD_ASSERT(cmd, 6, 6);
822
Chia-I Wu72292b72014-09-09 10:48:33 +0800823 cmd_batch_pointer(cmd, cmd_len, &dw);
824 dw[0] = dw0;
825 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800826}
827
828static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
829 uint32_t clear_val)
830{
831 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800832 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800833 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800835
836 CMD_ASSERT(cmd, 7, 7.5);
837
Chia-I Wu72292b72014-09-09 10:48:33 +0800838 cmd_batch_pointer(cmd, cmd_len, &dw);
839 dw[0] = dw0;
840 dw[1] = clear_val;
841 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800842}
843
Chia-I Wu302742d2014-08-22 10:28:29 +0800844static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t blend_offset,
846 uint32_t ds_offset,
847 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800848{
849 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800851
852 CMD_ASSERT(cmd, 6, 6);
853
Chia-I Wu426072d2014-08-26 14:31:55 +0800854 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800855 (cmd_len - 2);
856
Chia-I Wu72292b72014-09-09 10:48:33 +0800857 cmd_batch_pointer(cmd, cmd_len, &dw);
858 dw[0] = dw0;
859 dw[1] = blend_offset | 1;
860 dw[2] = ds_offset | 1;
861 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800862}
863
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t clip_offset,
866 uint32_t sf_offset,
867 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868{
869 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800871
872 CMD_ASSERT(cmd, 6, 6);
873
Chia-I Wu426072d2014-08-26 14:31:55 +0800874 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875 GEN6_PTR_VP_DW0_CLIP_CHANGED |
876 GEN6_PTR_VP_DW0_SF_CHANGED |
877 GEN6_PTR_VP_DW0_CC_CHANGED |
878 (cmd_len - 2);
879
Chia-I Wu72292b72014-09-09 10:48:33 +0800880 cmd_batch_pointer(cmd, cmd_len, &dw);
881 dw[0] = dw0;
882 dw[1] = clip_offset;
883 dw[2] = sf_offset;
884 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885}
886
887static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889{
890 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800891 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800892
893 CMD_ASSERT(cmd, 6, 6);
894
Chia-I Wu426072d2014-08-26 14:31:55 +0800895 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896 (cmd_len - 2);
897
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 cmd_batch_pointer(cmd, cmd_len, &dw);
899 dw[0] = dw0;
900 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800901}
902
Chia-I Wu42a56202014-08-23 16:47:48 +0800903static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t vs_offset,
905 uint32_t gs_offset,
906 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800907{
908 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800910
911 CMD_ASSERT(cmd, 6, 6);
912
Chia-I Wu426072d2014-08-26 14:31:55 +0800913 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800914 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
915 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
916 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
917 (cmd_len - 2);
918
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 cmd_batch_pointer(cmd, cmd_len, &dw);
920 dw[0] = dw0;
921 dw[1] = vs_offset;
922 dw[2] = gs_offset;
923 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800924}
925
Chia-I Wu257e75e2014-08-29 14:06:35 +0800926static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t vs_offset,
928 uint32_t gs_offset,
929 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930{
931 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800932 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800933
934 CMD_ASSERT(cmd, 6, 6);
935
936 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
937 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
938 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
939 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
940 (cmd_len - 2);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = vs_offset;
945 dw[2] = gs_offset;
946 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800947}
948
Chia-I Wu302742d2014-08-22 10:28:29 +0800949static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800951{
952 const uint8_t cmd_len = 2;
953 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
954 GEN6_RENDER_SUBTYPE_3D |
955 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958 cmd_batch_pointer(cmd, cmd_len, &dw);
959 dw[0] = dw0;
960 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800961}
962
Chia-I Wua6c4f152014-12-02 04:19:58 +0800963static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800964{
Chia-I Wue6073342014-11-30 09:43:42 +0800965 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700966 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
967 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800968
969 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700970 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800971
Tony Barbourfa6cac72015-01-16 14:27:35 -0700972 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800973}
974
Chia-I Wu72292b72014-09-09 10:48:33 +0800975static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700976 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800977{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800979 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800980 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700981 uint32_t dw[3];
982
983 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700984 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700985 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700986 (state->ds_info.stencilWriteMask & 0xff) << 16 |
987 (state->ds_info.stencilReadMask & 0xff) << 8 |
988 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700989 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
991 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992
993 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
994 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800995
Chia-I Wu00b51a82014-09-09 12:07:37 +0800996 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700997 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800998}
999
Chia-I Wu72292b72014-09-09 10:48:33 +08001000static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001001 uint32_t stencil_ref,
1002 const uint32_t blend_color[4])
1003{
Chia-I Wue6073342014-11-30 09:43:42 +08001004 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001005 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001006 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001007
1008 CMD_ASSERT(cmd, 6, 7.5);
1009
Chia-I Wu00b51a82014-09-09 12:07:37 +08001010 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1011 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001012 dw[0] = stencil_ref;
1013 dw[1] = 0;
1014 dw[2] = blend_color[0];
1015 dw[3] = blend_color[1];
1016 dw[4] = blend_color[2];
1017 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001018
Chia-I Wu72292b72014-09-09 10:48:33 +08001019 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001020}
1021
Chia-I Wu8370b402014-08-29 12:28:37 +08001022static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001023{
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 CMD_ASSERT(cmd, 6, 7.5);
1025
Chia-I Wu707a29e2014-08-27 12:51:47 +08001026 if (!cmd->bind.draw_count)
1027 return;
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030 return;
1031
Chia-I Wu8370b402014-08-29 12:28:37 +08001032 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001033
1034 /*
1035 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1036 *
1037 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1038 * pipe-control with a post-sync op and no write-cache flushes."
1039 *
1040 * The workaround below necessitates this workaround.
1041 */
1042 gen6_PIPE_CONTROL(cmd,
1043 GEN6_PIPE_CONTROL_CS_STALL |
1044 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001045 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001046
Chia-I Wud6d079d2014-08-31 13:14:21 +08001047 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1048 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001049}
1050
Chia-I Wu8370b402014-08-29 12:28:37 +08001051static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001052{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001053 CMD_ASSERT(cmd, 6, 7.5);
1054
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001055 if (!cmd->bind.draw_count)
1056 return;
1057
Chia-I Wud6d079d2014-08-31 13:14:21 +08001058 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1059 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001060}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001061
Chia-I Wu8370b402014-08-29 12:28:37 +08001062static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1063{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001064 CMD_ASSERT(cmd, 7, 7.5);
1065
Chia-I Wu8370b402014-08-29 12:28:37 +08001066 if (!cmd->bind.draw_count)
1067 return;
1068
1069 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001070
1071 gen6_PIPE_CONTROL(cmd,
1072 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001073 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001074}
1075
Chia-I Wu8370b402014-08-29 12:28:37 +08001076static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1077{
1078 CMD_ASSERT(cmd, 7, 7.5);
1079
1080 if (!cmd->bind.draw_count)
1081 return;
1082
1083 /*
1084 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1085 *
1086 * "One of the following must also be set (when CS stall is set):
1087 *
1088 * * Render Target Cache Flush Enable ([12] of DW1)
1089 * * Depth Cache Flush Enable ([0] of DW1)
1090 * * Stall at Pixel Scoreboard ([1] of DW1)
1091 * * Depth Stall ([13] of DW1)
1092 * * Post-Sync Operation ([13] of DW1)"
1093 */
1094 gen6_PIPE_CONTROL(cmd,
1095 GEN6_PIPE_CONTROL_CS_STALL |
1096 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001097 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001098}
1099
1100static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1101{
1102 CMD_ASSERT(cmd, 7, 7.5);
1103
1104 if (!cmd->bind.draw_count)
1105 return;
1106
1107 cmd_wa_gen6_pre_depth_stall_write(cmd);
1108
Chia-I Wud6d079d2014-08-31 13:14:21 +08001109 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001110}
1111
1112static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1113{
1114 CMD_ASSERT(cmd, 6, 7.5);
1115
1116 if (!cmd->bind.draw_count)
1117 return;
1118
1119 /*
1120 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1121 *
1122 * "Driver must guarentee that all the caches in the depth pipe are
1123 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1124 * requires driver to send a PIPE_CONTROL with a CS stall along with
1125 * a Depth Flush prior to this command."
1126 *
1127 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1128 *
1129 * "Driver must ierarchi that all the caches in the depth pipe are
1130 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1131 * requires driver to send a PIPE_CONTROL with a CS stall along with
1132 * a Depth Flush prior to this command.
1133 */
1134 gen6_PIPE_CONTROL(cmd,
1135 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1136 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001137 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001138}
1139
1140static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1141{
1142 CMD_ASSERT(cmd, 6, 7.5);
1143
1144 if (!cmd->bind.draw_count)
1145 return;
1146
1147 /*
1148 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1149 *
1150 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1151 * and a post sync operation prior to the group of depth
1152 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1153 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1154 *
1155 * This workaround satifies all the conditions.
1156 */
1157 cmd_wa_gen6_pre_depth_stall_write(cmd);
1158
1159 /*
1160 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1161 *
1162 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1163 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1164 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1165 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1166 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1167 * Depth Flush Bit set, followed by another pipelined depth stall
1168 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1169 * guarantee that the pipeline from WM onwards is already flushed
1170 * (e.g., via a preceding MI_FLUSH)."
1171 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001172 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1173 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1174 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001175}
1176
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001177void cmd_batch_state_base_address(struct intel_cmd *cmd)
1178{
1179 const uint8_t cmd_len = 10;
1180 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1181 (cmd_len - 2);
1182 uint32_t pos;
1183 uint32_t *dw;
1184
1185 CMD_ASSERT(cmd, 6, 7.5);
1186
1187 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1188
1189 dw[0] = dw0;
1190 /* start offsets */
1191 dw[1] = 1;
1192 dw[2] = 1;
1193 dw[3] = 1;
1194 dw[4] = 1;
1195 dw[5] = 1;
1196 /* end offsets */
1197 dw[6] = 1;
1198 dw[7] = 1 + 0xfffff000;
1199 dw[8] = 1 + 0xfffff000;
1200 dw[9] = 1;
1201
1202 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001203 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1204 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1205 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1206 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1207 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1208 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001209}
1210
Chia-I Wu525c6602014-08-27 10:22:34 +08001211void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1212{
1213 if (!cmd->bind.draw_count)
1214 return;
1215
1216 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1217
Chia-I Wu8370b402014-08-29 12:28:37 +08001218 /*
1219 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1220 *
1221 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1222 * PIPE_CONTROL with any non-zero post-sync-op is required."
1223 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001224 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001225 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001226
Chia-I Wu092279a2014-08-30 19:05:30 +08001227 /*
1228 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1229 *
1230 * "One of the following must also be set (when CS stall is set):
1231 *
1232 * * Render Target Cache Flush Enable ([12] of DW1)
1233 * * Depth Cache Flush Enable ([0] of DW1)
1234 * * Stall at Pixel Scoreboard ([1] of DW1)
1235 * * Depth Stall ([13] of DW1)
1236 * * Post-Sync Operation ([13] of DW1)"
1237 */
1238 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1239 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1240 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1241 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1242 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1243 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1244
Chia-I Wud6d079d2014-08-31 13:14:21 +08001245 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001246}
1247
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001248void cmd_batch_flush_all(struct intel_cmd *cmd)
1249{
1250 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1251 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1252 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1253 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1254 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1255 GEN6_PIPE_CONTROL_CS_STALL);
1256}
1257
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001258void cmd_batch_depth_count(struct intel_cmd *cmd,
1259 struct intel_bo *bo,
1260 XGL_GPU_SIZE offset)
1261{
1262 cmd_wa_gen6_pre_depth_stall_write(cmd);
1263
1264 gen6_PIPE_CONTROL(cmd,
1265 GEN6_PIPE_CONTROL_DEPTH_STALL |
1266 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001267 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001268}
1269
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001270void cmd_batch_timestamp(struct intel_cmd *cmd,
1271 struct intel_bo *bo,
1272 XGL_GPU_SIZE offset)
1273{
1274 /* need any WA or stall? */
1275 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1276}
1277
1278void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001279 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001280 struct intel_bo *bo,
1281 XGL_GPU_SIZE offset,
1282 uint64_t val)
1283{
1284 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001285 gen6_PIPE_CONTROL(cmd,
1286 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1287 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001288}
1289
Chia-I Wu302742d2014-08-22 10:28:29 +08001290static void gen6_cc_states(struct intel_cmd *cmd)
1291{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001292 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1293 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001294 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001295 uint32_t stencil_ref;
1296 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001297
1298 CMD_ASSERT(cmd, 6, 6);
1299
Chia-I Wua6c4f152014-12-02 04:19:58 +08001300 blend_offset = gen6_BLEND_STATE(cmd);
1301
1302 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001303 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001304 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001305 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001306
1307 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001308 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001309 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1310 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001311 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001312 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001313 stencil_ref = 0;
1314 }
1315
Chia-I Wu72292b72014-09-09 10:48:33 +08001316 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001317
Chia-I Wu72292b72014-09-09 10:48:33 +08001318 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001319}
1320
Chia-I Wu1744cca2014-08-22 11:10:17 +08001321static void gen6_viewport_states(struct intel_cmd *cmd)
1322{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001323 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001324 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001325
1326 if (!viewport)
1327 return;
1328
Tony Barbourfa6cac72015-01-16 14:27:35 -07001329 assert(viewport->cmd_len == (8 + 4 + 2) *
1330 viewport->viewport_count + (viewport->has_scissor_rects) ?
1331 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332
1333 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001334 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335 viewport->cmd);
1336
1337 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001338 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001339 &viewport->cmd[viewport->cmd_clip_pos]);
1340
1341 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001342 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001343 &viewport->cmd[viewport->cmd_cc_pos]);
1344
Tony Barbourfa6cac72015-01-16 14:27:35 -07001345 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001346 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001347 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001348 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1349 } else {
1350 scissor_offset = 0;
1351 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001352
1353 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001354 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001355
Chia-I Wub1d450a2014-09-09 13:48:03 +08001356 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001357}
1358
Chia-I Wu302742d2014-08-22 10:28:29 +08001359static void gen7_cc_states(struct intel_cmd *cmd)
1360{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001361 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1362 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001363 uint32_t stencil_ref;
1364 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001365 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001366
1367 CMD_ASSERT(cmd, 7, 7.5);
1368
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001369 if (!blend && !ds)
1370 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001371
Chia-I Wua6c4f152014-12-02 04:19:58 +08001372 offset = gen6_BLEND_STATE(cmd);
1373 gen7_3dstate_pointer(cmd,
1374 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001375
Chia-I Wua6c4f152014-12-02 04:19:58 +08001376 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001377 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001378 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001379 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001380
1381 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001382 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001383 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1384 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001385 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001386 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1387 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001388 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1389 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001390 } else {
1391 stencil_ref = 0;
1392 }
1393
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001395 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001396 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001397}
1398
Chia-I Wu1744cca2014-08-22 11:10:17 +08001399static void gen7_viewport_states(struct intel_cmd *cmd)
1400{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001401 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1402 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001403 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001404
1405 if (!viewport)
1406 return;
1407
Tony Barbourfa6cac72015-01-16 14:27:35 -07001408 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001409 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001410
Chia-I Wub1d450a2014-09-09 13:48:03 +08001411 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001412 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001413 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001414 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001415 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1416 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417
1418 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001419 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001421 gen7_3dstate_pointer(cmd,
1422 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001423 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001424
Tony Barbourfa6cac72015-01-16 14:27:35 -07001425 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001426 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001427 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001428 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001429 gen7_3dstate_pointer(cmd,
1430 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001431 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001432 }
1433}
1434
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001435static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001436 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001437{
1438 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001439 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001440
Chia-I Wu72292b72014-09-09 10:48:33 +08001441 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001442
1443 dw[0] = GEN6_RENDER_TYPE_RENDER |
1444 GEN6_RENDER_SUBTYPE_3D |
1445 subop | (cmd_len - 2);
1446 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001447 dw[2] = 0;
1448 dw[3] = 0;
1449 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001450}
1451
1452static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001453 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001454{
1455 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001456 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001457
Chia-I Wu72292b72014-09-09 10:48:33 +08001458 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001459
1460 dw[0] = GEN6_RENDER_TYPE_RENDER |
1461 GEN6_RENDER_SUBTYPE_3D |
1462 subop | (cmd_len - 2);
1463 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001464 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001465 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001466 dw[4] = 0;
1467 dw[5] = 0;
1468 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001469}
1470
Chia-I Wu625105f2014-10-13 15:35:29 +08001471static uint32_t emit_samplers(struct intel_cmd *cmd,
1472 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001473{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001474 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1475 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001476 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001477 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001478 uint32_t surface_count;
1479 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001480
1481 CMD_ASSERT(cmd, 6, 7.5);
1482
Chia-I Wu625105f2014-10-13 15:35:29 +08001483 if (!rmap || !rmap->sampler_count)
1484 return 0;
1485
Cody Northrop40316a32014-12-09 19:08:33 -07001486 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001487
Chia-I Wudcb509d2014-12-10 08:53:10 +08001488 /*
1489 * note that we cannot call cmd_state_pointer() here as the following
1490 * cmd_state_pointer() would invalidate the pointer
1491 */
1492 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001493 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001494 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495
1496 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001497 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001498 4 * rmap->sampler_count, &sampler_dw);
1499
Chia-I Wudcb509d2014-12-10 08:53:10 +08001500 cmd_state_update(cmd, border_offset,
1501 border_stride * rmap->sampler_count, &border_dw);
1502
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001503 for (i = 0; i < rmap->sampler_count; i++) {
1504 const struct intel_pipeline_rmap_slot *slot =
1505 &rmap->slots[surface_count + i];
1506 const struct intel_sampler *sampler;
1507
Chia-I Wuf8385062015-01-04 16:27:24 +08001508 switch (slot->type) {
1509 case INTEL_PIPELINE_RMAP_SAMPLER:
1510 intel_desc_pool_read_sampler(cmd->dev->desc_pool,
1511 &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001512 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001513 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001514 sampler = NULL;
1515 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001516 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001517 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001518 sampler = NULL;
1519 break;
1520 }
1521
1522 if (sampler) {
1523 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1524
1525 sampler_dw[0] = sampler->cmd[0];
1526 sampler_dw[1] = sampler->cmd[1];
1527 sampler_dw[2] = border_offset;
1528 sampler_dw[3] = sampler->cmd[2];
1529 } else {
1530 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1531 sampler_dw[1] = 0;
1532 sampler_dw[2] = 0;
1533 sampler_dw[3] = 0;
1534 }
1535
1536 border_offset += border_stride * 4;
1537 border_dw += border_stride;
1538 sampler_dw += 4;
1539 }
1540
Chia-I Wu625105f2014-10-13 15:35:29 +08001541 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001542}
1543
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001544static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001545 const struct intel_pipeline_rmap *rmap,
1546 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001547{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001548 const uint32_t sba_offset =
1549 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001550 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001551 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001552
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001553 CMD_ASSERT(cmd, 6, 7.5);
1554
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001555 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001556 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001557 if (!surface_count)
1558 return 0;
1559
Chia-I Wu42a56202014-08-23 16:47:48 +08001560 assert(surface_count <= ARRAY_SIZE(binding_table));
1561
1562 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001563 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001564 struct intel_null_view null_view;
1565 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001566
Chia-I Wuf8385062015-01-04 16:27:24 +08001567 switch (slot->type) {
1568 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001569 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001570 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001571 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1572 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001573
Chia-I Wu787a05b2014-12-05 11:02:20 +08001574 if (view) {
1575 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1576 GEN6_ALIGNMENT_SURFACE_STATE,
1577 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001578
Chia-I Wu787a05b2014-12-05 11:02:20 +08001579 cmd_reserve_reloc(cmd, 1);
1580 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1581 view->cmd[1], INTEL_RELOC_WRITE);
1582 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001583 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001584 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001585 }
1586 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001587 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001588 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001589 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1590 const struct intel_mem *mem;
1591 bool read_only;
1592 const uint32_t *cmd_data;
1593 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001594
Chia-I Wuf8385062015-01-04 16:27:24 +08001595 assert(dyn_idx < 0 || dyn_idx <
1596 cmd->bind.dset.graphics->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001597
Chia-I Wuf8385062015-01-04 16:27:24 +08001598 intel_desc_pool_read_surface(cmd->dev->desc_pool,
1599 &slot->u.surface.offset, stage, &mem,
1600 &read_only, &cmd_data, &cmd_len);
1601 if (mem) {
1602 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1603 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1604 const uint32_t reloc_flags =
1605 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001606
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001607 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001608 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001609 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001610
1611 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001612 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1613 cmd_data[1] + dynamic_offset, reloc_flags);
1614 } else {
1615 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001616 }
1617 }
1618 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001619 case INTEL_PIPELINE_RMAP_UNUSED:
1620 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001621 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001622 default:
1623 assert(!"unexpected rmap type");
1624 need_null_view = true;
1625 break;
1626 }
1627
1628 if (need_null_view) {
1629 intel_null_view_init(&null_view, cmd->dev);
1630 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1631 GEN6_ALIGNMENT_SURFACE_STATE,
1632 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001633 }
1634
Chia-I Wuf98dd882015-02-10 04:17:47 +08001635 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001636 }
1637
Chia-I Wuf98dd882015-02-10 04:17:47 +08001638 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001639 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001640 surface_count, binding_table) - sba_offset;
1641
1642 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1643 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1644
1645 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001646}
1647
Chia-I Wu1d125092014-10-08 08:49:38 +08001648static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1649{
1650 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001651 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1652 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001653 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001654
1655 CMD_ASSERT(cmd, 6, 7.5);
1656
1657 if (!pipeline->vb_count)
1658 return;
1659
1660 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1661
1662 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1663 dw++;
1664 pos++;
1665
1666 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001667 assert(pipeline->vb[i].strideInBytes <= 2048);
1668
1669 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1670 pipeline->vb[i].strideInBytes;
1671
1672 if (cmd_gen(cmd) >= INTEL_GEN(7))
1673 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1674
1675 switch (pipeline->vb[i].stepRate) {
1676 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1677 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1678 dw[3] = 0;
1679 break;
1680 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1681 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1682 dw[3] = 1;
1683 break;
1684 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1685 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1686 dw[3] = 0;
1687 break;
1688 default:
1689 assert(!"unknown step rate");
1690 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1691 dw[3] = 0;
1692 break;
1693 }
1694
Chia-I Wu714df452015-01-01 07:55:04 +08001695 if (cmd->bind.vertex.buf[i]) {
1696 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001697 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001698
1699 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001700 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1701 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001702 } else {
1703 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1704 dw[1] = 0;
1705 dw[2] = 0;
1706 }
1707
1708 dw += 4;
1709 pos += 4;
1710 }
1711}
1712
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001713static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1714{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001715 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1716 const struct intel_pipeline_shader *vs = &pipeline->vs;
1717 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001718 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001719 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001720 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001721 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001722
1723 CMD_ASSERT(cmd, 6, 7.5);
1724
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001725 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001726 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1727 *
1728 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1729 * 128-bit vertex elements to be passed into the payload for each
1730 * vertex."
1731 *
1732 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1733 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001734 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001735 vue_read_len = (vs->in_count + 1) / 2;
1736 if (!vue_read_len)
1737 vue_read_len = 1;
1738
1739 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1740 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1741
1742 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1743 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1744 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001745
1746 dw5 = GEN6_VS_DW5_STATISTICS |
1747 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001748
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001749 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001750 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001752 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001753
Chia-I Wube0a3d92014-09-02 13:20:59 +08001754 if (pipeline->disable_vs_cache)
1755 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1756
Chia-I Wu784d3042014-12-19 14:30:04 +08001757 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001758 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001759 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001760 dw[2] = dw2;
1761 dw[3] = 0; /* scratch */
1762 dw[4] = dw4;
1763 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001764
1765 if (vs->per_thread_scratch_size)
1766 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001767}
1768
Chia-I Wu625105f2014-10-13 15:35:29 +08001769static void emit_shader_resources(struct intel_cmd *cmd)
1770{
1771 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001772 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001773
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001774 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001775 cmd->bind.pipeline.graphics->vs.rmap,
1776 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001777 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001778 cmd->bind.pipeline.graphics->tcs.rmap,
1779 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001780 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001781 cmd->bind.pipeline.graphics->tes.rmap,
1782 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001783 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001784 cmd->bind.pipeline.graphics->gs.rmap,
1785 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001786 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001787 cmd->bind.pipeline.graphics->fs.rmap,
1788 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001789
1790 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1791 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1792 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1793 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1794 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1795
1796 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1797 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001798 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1799 binding_tables[0]);
1800 gen7_3dstate_pointer(cmd,
1801 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1802 binding_tables[1]);
1803 gen7_3dstate_pointer(cmd,
1804 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1805 binding_tables[2]);
1806 gen7_3dstate_pointer(cmd,
1807 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1808 binding_tables[3]);
1809 gen7_3dstate_pointer(cmd,
1810 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1811 binding_tables[4]);
1812
1813 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001814 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1815 samplers[0]);
1816 gen7_3dstate_pointer(cmd,
1817 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1818 samplers[1]);
1819 gen7_3dstate_pointer(cmd,
1820 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1821 samplers[2]);
1822 gen7_3dstate_pointer(cmd,
1823 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1824 samplers[3]);
1825 gen7_3dstate_pointer(cmd,
1826 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1827 samplers[4]);
1828 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001829 assert(!binding_tables[1] && !binding_tables[2]);
1830 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1831 binding_tables[0], binding_tables[3], binding_tables[4]);
1832
Chia-I Wu625105f2014-10-13 15:35:29 +08001833 assert(!samplers[1] && !samplers[2]);
1834 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1835 samplers[0], samplers[3], samplers[4]);
1836 }
1837}
1838
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001839static void emit_rt(struct intel_cmd *cmd)
1840{
1841 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001842 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1843 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001844}
1845
1846static void emit_ds(struct intel_cmd *cmd)
1847{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001848 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001849
1850 if (!ds) {
1851 /* all zeros */
1852 static const struct intel_ds_view null_ds;
1853 ds = &null_ds;
1854 }
1855
1856 cmd_wa_gen6_pre_ds_flush(cmd);
1857 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1858 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1859 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1860
1861 if (cmd_gen(cmd) >= INTEL_GEN(7))
1862 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1863 else
1864 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1865}
1866
Chia-I Wua57761b2014-10-14 14:27:44 +08001867static uint32_t emit_shader(struct intel_cmd *cmd,
1868 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001869{
Chia-I Wua57761b2014-10-14 14:27:44 +08001870 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1871 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001872 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001873
Chia-I Wua57761b2014-10-14 14:27:44 +08001874 /* see if the shader is already in the cache */
1875 for (i = 0; i < cache->used; i++) {
1876 if (cache->entries[i].shader == (const void *) shader)
1877 return cache->entries[i].kernel_offset;
1878 }
1879
1880 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1881
1882 /* grow the cache if full */
1883 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001884 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001885 void *entries;
1886
1887 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1888 XGL_SYSTEM_ALLOC_INTERNAL);
1889 if (entries) {
1890 if (cache->entries) {
1891 memcpy(entries, cache->entries,
1892 sizeof(cache->entries[0]) * cache->used);
1893 icd_free(cache->entries);
1894 }
1895
1896 cache->entries = entries;
1897 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001898 }
1899 }
1900
Chia-I Wua57761b2014-10-14 14:27:44 +08001901 /* add the shader to the cache */
1902 if (cache->used < cache->count) {
1903 cache->entries[cache->used].shader = (const void *) shader;
1904 cache->entries[cache->used].kernel_offset = offset;
1905 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001906 }
1907
Chia-I Wua57761b2014-10-14 14:27:44 +08001908 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001909}
1910
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001911static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001912{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001913 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001914
Chia-I Wu8370b402014-08-29 12:28:37 +08001915 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1916 cmd_wa_gen6_pre_depth_stall_write(cmd);
1917 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1918 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1919 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1920 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001921
1922 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001923 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001924 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001925
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001926 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001927 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001928 }
1929 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001930 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001931 }
1932 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001933 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1934 }
1935 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1936 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1937 }
1938 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1939 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001940 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001941
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001942 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1943 gen7_3DSTATE_GS(cmd);
1944 } else {
1945 gen6_3DSTATE_GS(cmd);
1946 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001947
Chia-I Wu8370b402014-08-29 12:28:37 +08001948 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1949 cmd_wa_gen7_post_command_cs_stall(cmd);
1950 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1951 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001952}
1953
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001954static void emit_bounded_states(struct intel_cmd *cmd)
1955{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001956
1957 emit_graphics_pipeline(cmd);
1958
1959 emit_rt(cmd);
1960 emit_ds(cmd);
1961
1962 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1963 gen7_cc_states(cmd);
1964 gen7_viewport_states(cmd);
1965
1966 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1967 &cmd->bind.pipeline.graphics->vs);
1968 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1969 &cmd->bind.pipeline.graphics->fs);
1970
1971 gen6_3DSTATE_CLIP(cmd);
1972 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001973 gen7_3DSTATE_WM(cmd);
1974 gen7_3DSTATE_PS(cmd);
1975 } else {
1976 gen6_cc_states(cmd);
1977 gen6_viewport_states(cmd);
1978
1979 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1980 &cmd->bind.pipeline.graphics->vs);
1981 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1982 &cmd->bind.pipeline.graphics->fs);
1983
1984 gen6_3DSTATE_CLIP(cmd);
1985 gen6_3DSTATE_SF(cmd);
1986 gen6_3DSTATE_WM(cmd);
1987 }
1988
1989 emit_shader_resources(cmd);
1990
1991 cmd_wa_gen6_pre_depth_stall_write(cmd);
1992 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1993
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001994 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1995 gen6_3DSTATE_VS(cmd);
1996}
1997
Tony Barbourfa6cac72015-01-16 14:27:35 -07001998static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1999 const struct intel_cmd_meta *meta)
2000{
2001 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2002 const uint8_t cmd_len = 3;
2003 uint32_t dw[3];
2004 uint32_t cmd_depth_stencil;
2005 uint32_t cmd_depth_test;
2006
2007 CMD_ASSERT(cmd, 6, 7.5);
2008
2009 cmd_depth_stencil = 0;
2010 cmd_depth_test = 0;
2011 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2012 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2013 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2014 }
2015 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2016 cmd_depth_stencil = 1 << 31 |
2017 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2018 (GEN6_STENCILOP_KEEP) << 25 |
2019 (GEN6_STENCILOP_KEEP) << 22 |
2020 (GEN6_STENCILOP_REPLACE) << 19 |
2021 1 << 15 |
2022 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2023 (GEN6_STENCILOP_KEEP) << 9 |
2024 (GEN6_STENCILOP_KEEP) << 6 |
2025 (GEN6_STENCILOP_REPLACE) << 3;
2026 }
2027
2028 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2029 dw[0] = cmd_depth_stencil | 1 << 18;
2030 dw[1] = (0xff) << 24 | (0xff) << 16;
2031 dw[2] = cmd_depth_test;
2032
2033 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2034 cmd_align, cmd_len, dw);
2035}
2036
Chia-I Wu6032b892014-10-17 14:47:18 +08002037static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2038{
2039 const struct intel_cmd_meta *meta = cmd->bind.meta;
2040 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2041
2042 CMD_ASSERT(cmd, 6, 7.5);
2043
2044 blend_offset = 0;
2045 ds_offset = 0;
2046 cc_offset = 0;
2047 cc_vp_offset = 0;
2048
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002050 /* BLEND_STATE */
2051 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002052 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002053 dw[0] = 0;
2054 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2055 }
2056
Chia-I Wu29e6f502014-11-24 14:27:29 +08002057 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002058 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002059 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002060 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2061 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002062
Chia-I Wu29e6f502014-11-24 14:27:29 +08002063 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002064 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002065
Chia-I Wu29e6f502014-11-24 14:27:29 +08002066 /* COLOR_CALC_STATE */
2067 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002068 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002069
Chia-I Wu29e6f502014-11-24 14:27:29 +08002070 /* CC_VIEWPORT */
2071 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002072 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002073 dw[0] = u_fui(0.0f);
2074 dw[1] = u_fui(1.0f);
2075 } else {
2076 /* DEPTH_STENCIL_STATE */
2077 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002078 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002079 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2080 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2081 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002082 }
2083
2084 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2085 gen7_3dstate_pointer(cmd,
2086 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2087 blend_offset);
2088 gen7_3dstate_pointer(cmd,
2089 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2090 ds_offset);
2091 gen7_3dstate_pointer(cmd,
2092 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2093
2094 gen7_3dstate_pointer(cmd,
2095 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2096 cc_vp_offset);
2097 } else {
2098 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002099 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002100
2101 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2102 cmd_batch_pointer(cmd, 4, &dw);
2103 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2104 GEN6_PTR_VP_DW0_CC_CHANGED;
2105 dw[1] = 0;
2106 dw[2] = 0;
2107 dw[3] = cc_vp_offset;
2108 }
2109}
2110
2111static void gen6_meta_surface_states(struct intel_cmd *cmd)
2112{
2113 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002114 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002115 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002116 const uint32_t sba_offset =
2117 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002118
2119 CMD_ASSERT(cmd, 6, 7.5);
2120
Chia-I Wu29e6f502014-11-24 14:27:29 +08002121 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2122 return;
2123
Chia-I Wu005c47c2014-10-22 13:49:13 +08002124 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002125 if (meta->src.valid) {
2126 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002127 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002128 meta->src.surface_len, meta->src.surface);
2129
2130 cmd_reserve_reloc(cmd, 1);
2131 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2132 cmd_surface_reloc_writer(cmd, offset, 1,
2133 meta->src.reloc_target, meta->src.reloc_offset);
2134 } else {
2135 cmd_surface_reloc(cmd, offset, 1,
2136 (struct intel_bo *) meta->src.reloc_target,
2137 meta->src.reloc_offset, meta->src.reloc_flags);
2138 }
2139
Mike Stroyan9bfad482015-02-10 15:09:23 -07002140 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002141 }
2142 if (meta->dst.valid) {
2143 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002144 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002145 meta->dst.surface_len, meta->dst.surface);
2146
2147 cmd_reserve_reloc(cmd, 1);
2148 cmd_surface_reloc(cmd, offset, 1,
2149 (struct intel_bo *) meta->dst.reloc_target,
2150 meta->dst.reloc_offset, meta->dst.reloc_flags);
2151
Mike Stroyan9bfad482015-02-10 15:09:23 -07002152 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 }
2154
2155 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002156 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002157 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002158 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002159
2160 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002161 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2162 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2163 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002164 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002165 } else {
2166 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002167 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002168 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002169 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002170 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002171 }
2172}
2173
2174static void gen6_meta_urb(struct intel_cmd *cmd)
2175{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002176 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002177 uint32_t *dw;
2178
2179 CMD_ASSERT(cmd, 6, 6);
2180
2181 /* 3DSTATE_URB */
2182 cmd_batch_pointer(cmd, 3, &dw);
2183 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002184 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002185 dw[2] = 0;
2186}
2187
2188static void gen7_meta_urb(struct intel_cmd *cmd)
2189{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002190 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002191 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002192 uint32_t *dw;
2193
2194 CMD_ASSERT(cmd, 7, 7.5);
2195
2196 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2197 cmd_batch_pointer(cmd, 10, &dw);
2198
2199 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002200 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002201 dw += 2;
2202
2203 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2204 dw[1] = 0;
2205 dw += 2;
2206
2207 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2208 dw[1] = 0;
2209 dw += 2;
2210
2211 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2212 dw[1] = 0;
2213 dw += 2;
2214
2215 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002216 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002217
2218 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2219
Chia-I Wu24aa1022014-11-25 11:53:19 +08002220 switch (cmd_gen(cmd)) {
2221 case INTEL_GEN(7.5):
2222 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2223 break;
2224 case INTEL_GEN(7):
2225 default:
2226 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2227 break;
2228 }
2229
Chia-I Wu6032b892014-10-17 14:47:18 +08002230 /* 3DSTATE_URB_x */
2231 cmd_batch_pointer(cmd, 8, &dw);
2232
2233 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2234 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002235 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002236 dw += 2;
2237
2238 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2239 dw[1] = 0;
2240 dw += 2;
2241
2242 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2243 dw[1] = 0;
2244 dw += 2;
2245
2246 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2247 dw[1] = 0;
2248 dw += 2;
2249}
2250
2251static void gen6_meta_vf(struct intel_cmd *cmd)
2252{
2253 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002254 uint32_t vb_start, vb_end, vb_stride;
2255 int ve_format, ve_z_source;
2256 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002257 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002258
2259 CMD_ASSERT(cmd, 6, 7.5);
2260
Chia-I Wu29e6f502014-11-24 14:27:29 +08002261 switch (meta->mode) {
2262 case INTEL_CMD_META_VS_POINTS:
2263 cmd_batch_pointer(cmd, 3, &dw);
2264 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2265 dw[1] = GEN6_VE_STATE_DW0_VALID;
2266 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2267 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2268 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2269 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2270 return;
2271 break;
2272 case INTEL_CMD_META_FS_RECT:
2273 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002274 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 vertices[0][0] = meta->dst.x + meta->width;
2277 vertices[0][1] = meta->dst.y + meta->height;
2278 vertices[1][0] = meta->dst.x;
2279 vertices[1][1] = meta->dst.y + meta->height;
2280 vertices[2][0] = meta->dst.x;
2281 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002282
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2284 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vb_end = vb_start + sizeof(vertices) - 1;
2287 vb_stride = sizeof(vertices[0]);
2288 ve_z_source = GEN6_VFCOMP_STORE_0;
2289 ve_format = GEN6_FORMAT_R32G32_USCALED;
2290 }
2291 break;
2292 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2293 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002294 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002295
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002296 vertices[0][0] = (float) (meta->dst.x + meta->width);
2297 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002298 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002299 vertices[1][0] = (float) meta->dst.x;
2300 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002301 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002302 vertices[2][0] = (float) meta->dst.x;
2303 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002304 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305
Chia-I Wu29e6f502014-11-24 14:27:29 +08002306 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2307 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002308
Chia-I Wu29e6f502014-11-24 14:27:29 +08002309 vb_end = vb_start + sizeof(vertices) - 1;
2310 vb_stride = sizeof(vertices[0]);
2311 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2312 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2313 }
2314 break;
2315 default:
2316 assert(!"unknown meta mode");
2317 return;
2318 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002319 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002320
2321 /* 3DSTATE_VERTEX_BUFFERS */
2322 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002323
Chia-I Wu6032b892014-10-17 14:47:18 +08002324 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002325 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002326 if (cmd_gen(cmd) >= INTEL_GEN(7))
2327 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2328
2329 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002330 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2331 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002332
2333 dw[4] = 0;
2334
2335 /* 3DSTATE_VERTEX_ELEMENTS */
2336 cmd_batch_pointer(cmd, 5, &dw);
2337 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002338 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002339 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2340 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2341 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2342 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2343 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002344 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2346 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002347 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2349}
2350
Chia-I Wu29e6f502014-11-24 14:27:29 +08002351static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002352{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002353 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002354 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002355 uint32_t consts[8];
2356 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002357
2358 CMD_ASSERT(cmd, 6, 7.5);
2359
2360 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002361 case INTEL_DEV_META_VS_FILL_MEM:
2362 consts[0] = meta->dst.x;
2363 consts[1] = meta->clear_val[0];
2364 const_count = 2;
2365 break;
2366 case INTEL_DEV_META_VS_COPY_MEM:
2367 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2368 consts[0] = meta->dst.x;
2369 consts[1] = meta->src.x;
2370 const_count = 2;
2371 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002372 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2373 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2374 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2375 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2376 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2377 consts[0] = meta->src.x;
2378 consts[1] = meta->src.y;
2379 consts[2] = meta->width;
2380 consts[3] = meta->dst.x;
2381 const_count = 4;
2382 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002383 default:
2384 assert(!"unknown meta shader id");
2385 const_count = 0;
2386 break;
2387 }
2388
2389 /* this can be skipped but it makes state dumping prettier */
2390 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2391
2392 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2393}
2394
2395static void gen6_meta_vs(struct intel_cmd *cmd)
2396{
2397 const struct intel_cmd_meta *meta = cmd->bind.meta;
2398 const struct intel_pipeline_shader *sh =
2399 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2400 uint32_t offset, *dw;
2401
2402 CMD_ASSERT(cmd, 6, 7.5);
2403
2404 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002405 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002406
2407 /* 3DSTATE_CONSTANT_VS */
2408 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2409 cmd_batch_pointer(cmd, cmd_len, &dw);
2410 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2411 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2412
2413 /* 3DSTATE_VS */
2414 cmd_batch_pointer(cmd, 6, &dw);
2415 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2416 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2417
2418 return;
2419 }
2420
2421 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2422
2423 /* 3DSTATE_CONSTANT_VS */
2424 offset = gen6_meta_vs_constants(cmd);
2425 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2426 cmd_batch_pointer(cmd, 7, &dw);
2427 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2428 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2429 dw[2] = 0;
2430 dw[3] = offset;
2431 dw[4] = 0;
2432 dw[5] = 0;
2433 dw[6] = 0;
2434 } else {
2435 cmd_batch_pointer(cmd, 5, &dw);
2436 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2437 GEN6_PCB_ANY_DW0_PCB0_VALID;
2438 dw[1] = offset;
2439 dw[2] = 0;
2440 dw[3] = 0;
2441 dw[4] = 0;
2442 }
2443
2444 /* 3DSTATE_VS */
2445 offset = emit_shader(cmd, sh);
2446 cmd_batch_pointer(cmd, 6, &dw);
2447 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2448 dw[1] = offset;
2449 dw[2] = GEN6_THREADDISP_SPF |
2450 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2451 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002452 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002453 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2454 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2455
2456 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2457 GEN6_VS_DW5_VS_ENABLE;
2458 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002459 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002460 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002461 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002462
2463 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002464}
2465
2466static void gen6_meta_disabled(struct intel_cmd *cmd)
2467{
Chia-I Wu6032b892014-10-17 14:47:18 +08002468 uint32_t *dw;
2469
2470 CMD_ASSERT(cmd, 6, 6);
2471
Chia-I Wu6032b892014-10-17 14:47:18 +08002472 /* 3DSTATE_CONSTANT_GS */
2473 cmd_batch_pointer(cmd, 5, &dw);
2474 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2475 dw[1] = 0;
2476 dw[2] = 0;
2477 dw[3] = 0;
2478 dw[4] = 0;
2479
2480 /* 3DSTATE_GS */
2481 cmd_batch_pointer(cmd, 7, &dw);
2482 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2483 dw[1] = 0;
2484 dw[2] = 0;
2485 dw[3] = 0;
2486 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2487 dw[5] = GEN6_GS_DW5_STATISTICS;
2488 dw[6] = 0;
2489
Chia-I Wu6032b892014-10-17 14:47:18 +08002490 /* 3DSTATE_SF */
2491 cmd_batch_pointer(cmd, 20, &dw);
2492 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2493 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2494 memset(&dw[2], 0, 18 * sizeof(*dw));
2495}
2496
2497static void gen7_meta_disabled(struct intel_cmd *cmd)
2498{
2499 uint32_t *dw;
2500
2501 CMD_ASSERT(cmd, 7, 7.5);
2502
Chia-I Wu6032b892014-10-17 14:47:18 +08002503 /* 3DSTATE_CONSTANT_HS */
2504 cmd_batch_pointer(cmd, 7, &dw);
2505 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2506 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2507
2508 /* 3DSTATE_HS */
2509 cmd_batch_pointer(cmd, 7, &dw);
2510 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2511 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2512
2513 /* 3DSTATE_TE */
2514 cmd_batch_pointer(cmd, 4, &dw);
2515 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2516 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2517
2518 /* 3DSTATE_CONSTANT_DS */
2519 cmd_batch_pointer(cmd, 7, &dw);
2520 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2522
2523 /* 3DSTATE_DS */
2524 cmd_batch_pointer(cmd, 6, &dw);
2525 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2526 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2527
2528 /* 3DSTATE_CONSTANT_GS */
2529 cmd_batch_pointer(cmd, 7, &dw);
2530 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2531 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2532
2533 /* 3DSTATE_GS */
2534 cmd_batch_pointer(cmd, 7, &dw);
2535 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2536 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2537
2538 /* 3DSTATE_STREAMOUT */
2539 cmd_batch_pointer(cmd, 3, &dw);
2540 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2541 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2542
Chia-I Wu6032b892014-10-17 14:47:18 +08002543 /* 3DSTATE_SF */
2544 cmd_batch_pointer(cmd, 7, &dw);
2545 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2546 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2547
2548 /* 3DSTATE_SBE */
2549 cmd_batch_pointer(cmd, 14, &dw);
2550 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2551 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2552 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002554
Chia-I Wu29e6f502014-11-24 14:27:29 +08002555static void gen6_meta_clip(struct intel_cmd *cmd)
2556{
2557 const struct intel_cmd_meta *meta = cmd->bind.meta;
2558 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002559
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560 /* 3DSTATE_CLIP */
2561 cmd_batch_pointer(cmd, 4, &dw);
2562 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2563 dw[1] = 0;
2564 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2565 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2566 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2567 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002568 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002569 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002570 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002571}
2572
2573static void gen6_meta_wm(struct intel_cmd *cmd)
2574{
2575 const struct intel_cmd_meta *meta = cmd->bind.meta;
2576 uint32_t *dw;
2577
2578 CMD_ASSERT(cmd, 6, 7.5);
2579
2580 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2581
2582 /* 3DSTATE_MULTISAMPLE */
2583 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2584 cmd_batch_pointer(cmd, 4, &dw);
2585 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2586 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2587 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2588 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2589 dw[2] = 0;
2590 dw[3] = 0;
2591 } else {
2592 cmd_batch_pointer(cmd, 3, &dw);
2593 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2594 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2595 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2596 dw[2] = 0;
2597 }
2598
2599 /* 3DSTATE_SAMPLE_MASK */
2600 cmd_batch_pointer(cmd, 2, &dw);
2601 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2602 dw[1] = (1 << meta->samples) - 1;
2603
2604 /* 3DSTATE_DRAWING_RECTANGLE */
2605 cmd_batch_pointer(cmd, 4, &dw);
2606 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2607 dw[1] = meta->dst.y << 16 | meta->dst.x;
2608 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2609 (meta->dst.x + meta->width - 1);
2610 dw[3] = 0;
2611}
2612
2613static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2614{
2615 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002616 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002617 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002618 uint32_t consts[8];
2619 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002620
2621 CMD_ASSERT(cmd, 6, 7.5);
2622
2623 /* underflow is fine here */
2624 offset_x = meta->src.x - meta->dst.x;
2625 offset_y = meta->src.y - meta->dst.y;
2626
2627 switch (meta->shader_id) {
2628 case INTEL_DEV_META_FS_COPY_MEM:
2629 case INTEL_DEV_META_FS_COPY_1D:
2630 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2631 case INTEL_DEV_META_FS_COPY_2D:
2632 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2633 case INTEL_DEV_META_FS_COPY_2D_MS:
2634 consts[0] = offset_x;
2635 consts[1] = offset_y;
2636 consts[2] = meta->src.layer;
2637 consts[3] = meta->src.lod;
2638 const_count = 4;
2639 break;
2640 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2641 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2642 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2643 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2644 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2645 consts[0] = offset_x;
2646 consts[1] = offset_y;
2647 consts[2] = meta->src.layer;
2648 consts[3] = meta->src.lod;
2649 consts[4] = meta->src.x;
2650 consts[5] = meta->width;
2651 const_count = 6;
2652 break;
2653 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2654 consts[0] = offset_x;
2655 consts[1] = offset_y;
2656 consts[2] = meta->width;
2657 const_count = 3;
2658 break;
2659 case INTEL_DEV_META_FS_CLEAR_COLOR:
2660 consts[0] = meta->clear_val[0];
2661 consts[1] = meta->clear_val[1];
2662 consts[2] = meta->clear_val[2];
2663 consts[3] = meta->clear_val[3];
2664 const_count = 4;
2665 break;
2666 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2667 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002668 consts[1] = meta->clear_val[1];
2669 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002670 break;
2671 case INTEL_DEV_META_FS_RESOLVE_2X:
2672 case INTEL_DEV_META_FS_RESOLVE_4X:
2673 case INTEL_DEV_META_FS_RESOLVE_8X:
2674 case INTEL_DEV_META_FS_RESOLVE_16X:
2675 consts[0] = offset_x;
2676 consts[1] = offset_y;
2677 const_count = 2;
2678 break;
2679 default:
2680 assert(!"unknown meta shader id");
2681 const_count = 0;
2682 break;
2683 }
2684
2685 /* this can be skipped but it makes state dumping prettier */
2686 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2687
2688 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2689}
2690
2691static void gen6_meta_ps(struct intel_cmd *cmd)
2692{
2693 const struct intel_cmd_meta *meta = cmd->bind.meta;
2694 const struct intel_pipeline_shader *sh =
2695 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2696 uint32_t offset, *dw;
2697
2698 CMD_ASSERT(cmd, 6, 6);
2699
Chia-I Wu29e6f502014-11-24 14:27:29 +08002700 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2701 /* 3DSTATE_CONSTANT_PS */
2702 cmd_batch_pointer(cmd, 5, &dw);
2703 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2704 dw[1] = 0;
2705 dw[2] = 0;
2706 dw[3] = 0;
2707 dw[4] = 0;
2708
2709 /* 3DSTATE_WM */
2710 cmd_batch_pointer(cmd, 9, &dw);
2711 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2712 dw[1] = 0;
2713 dw[2] = 0;
2714 dw[3] = 0;
2715 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002716 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002717 dw[6] = 0;
2718 dw[7] = 0;
2719 dw[8] = 0;
2720
Chia-I Wu3adf7212014-10-24 15:34:07 +08002721 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002722 }
2723
Chia-I Wu3adf7212014-10-24 15:34:07 +08002724 /* a normal color write */
2725 assert(meta->dst.valid && !sh->uses);
2726
Chia-I Wu6032b892014-10-17 14:47:18 +08002727 /* 3DSTATE_CONSTANT_PS */
2728 offset = gen6_meta_ps_constants(cmd);
2729 cmd_batch_pointer(cmd, 5, &dw);
2730 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2731 GEN6_PCB_ANY_DW0_PCB0_VALID;
2732 dw[1] = offset;
2733 dw[2] = 0;
2734 dw[3] = 0;
2735 dw[4] = 0;
2736
2737 /* 3DSTATE_WM */
2738 offset = emit_shader(cmd, sh);
2739 cmd_batch_pointer(cmd, 9, &dw);
2740 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2741 dw[1] = offset;
2742 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2743 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002744 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002745 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002746 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002747 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002748 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2749
Chia-I Wu6032b892014-10-17 14:47:18 +08002750 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2751 GEN6_WM_DW6_POSOFFSET_NONE |
2752 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2753 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2754 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2755 if (meta->samples > 1) {
2756 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2757 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2758 } else {
2759 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2760 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2761 }
2762 dw[7] = 0;
2763 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002764
2765 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002766}
2767
2768static void gen7_meta_ps(struct intel_cmd *cmd)
2769{
2770 const struct intel_cmd_meta *meta = cmd->bind.meta;
2771 const struct intel_pipeline_shader *sh =
2772 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2773 uint32_t offset, *dw;
2774
2775 CMD_ASSERT(cmd, 7, 7.5);
2776
Chia-I Wu29e6f502014-11-24 14:27:29 +08002777 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2778 /* 3DSTATE_WM */
2779 cmd_batch_pointer(cmd, 3, &dw);
2780 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2781 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2782
2783 /* 3DSTATE_CONSTANT_GS */
2784 cmd_batch_pointer(cmd, 7, &dw);
2785 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2786 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2787
2788 /* 3DSTATE_PS */
2789 cmd_batch_pointer(cmd, 8, &dw);
2790 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2791 dw[1] = 0;
2792 dw[2] = 0;
2793 dw[3] = 0;
2794 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002795 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002796 dw[5] = 0;
2797 dw[6] = 0;
2798 dw[7] = 0;
2799
Chia-I Wu3adf7212014-10-24 15:34:07 +08002800 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002801 }
2802
Chia-I Wu3adf7212014-10-24 15:34:07 +08002803 /* a normal color write */
2804 assert(meta->dst.valid && !sh->uses);
2805
Chia-I Wu6032b892014-10-17 14:47:18 +08002806 /* 3DSTATE_WM */
2807 cmd_batch_pointer(cmd, 3, &dw);
2808 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2809 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2810 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2811 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2812 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2813 dw[2] = 0;
2814
2815 /* 3DSTATE_CONSTANT_PS */
2816 offset = gen6_meta_ps_constants(cmd);
2817 cmd_batch_pointer(cmd, 7, &dw);
2818 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2819 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2820 dw[2] = 0;
2821 dw[3] = offset;
2822 dw[4] = 0;
2823 dw[5] = 0;
2824 dw[6] = 0;
2825
2826 /* 3DSTATE_PS */
2827 offset = emit_shader(cmd, sh);
2828 cmd_batch_pointer(cmd, 8, &dw);
2829 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2830 dw[1] = offset;
2831 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2832 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002833 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002834
2835 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2836 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002837 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2838
2839 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002840 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002841 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002842 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002843 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002844 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002845
2846 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2847 dw[6] = 0;
2848 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002849
2850 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002851}
2852
2853static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2854{
2855 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002856 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002857
2858 CMD_ASSERT(cmd, 6, 7.5);
2859
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002860 if (!ds) {
2861 /* all zeros */
2862 static const struct intel_ds_view null_ds;
2863 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002864 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002865
2866 cmd_wa_gen6_pre_ds_flush(cmd);
2867 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2868 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2869 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2870
2871 if (cmd_gen(cmd) >= INTEL_GEN(7))
2872 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2873 else
2874 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002875}
2876
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002877static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2878 const struct intel_pipeline *pipeline)
2879{
2880 cmd->bind.pipeline.graphics = pipeline;
2881}
2882
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002883static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2884 const struct intel_pipeline *pipeline)
2885{
2886 cmd->bind.pipeline.compute = pipeline;
2887}
2888
2889static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2890 const struct intel_pipeline_delta *delta)
2891{
2892 cmd->bind.pipeline.graphics_delta = delta;
2893}
2894
2895static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2896 const struct intel_pipeline_delta *delta)
2897{
2898 cmd->bind.pipeline.compute_delta = delta;
2899}
2900
2901static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002902 const struct intel_desc_set *dset,
2903 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002904{
Chia-I Wuf8385062015-01-04 16:27:24 +08002905 const uint32_t size = sizeof(*dynamic_offsets) *
2906 dset->layout->dynamic_desc_count;
2907
2908 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2909 if (cmd->bind.dset.graphics_dynamic_offsets)
2910 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2911
2912 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2913 4, XGL_SYSTEM_ALLOC_INTERNAL);
2914 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2915 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2916 return;
2917 }
2918
2919 cmd->bind.dset.graphics_dynamic_offset_size = size;
2920 }
2921
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002922 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002923 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002924}
2925
2926static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002927 const struct intel_desc_set *dset,
2928 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002929{
Chia-I Wuf8385062015-01-04 16:27:24 +08002930 const uint32_t size = sizeof(*dynamic_offsets) *
2931 dset->layout->dynamic_desc_count;
2932
2933 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2934 if (cmd->bind.dset.compute_dynamic_offsets)
2935 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2936
2937 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2938 4, XGL_SYSTEM_ALLOC_INTERNAL);
2939 if (!cmd->bind.dset.compute_dynamic_offsets) {
2940 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2941 return;
2942 }
2943
2944 cmd->bind.dset.compute_dynamic_offset_size = size;
2945 }
2946
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002948 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002949}
2950
Chia-I Wu3b04af52014-11-08 10:48:20 +08002951static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002952 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002953 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002954{
Chia-I Wu714df452015-01-01 07:55:04 +08002955 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002956 cmd->result = XGL_ERROR_UNKNOWN;
2957 return;
2958 }
2959
Chia-I Wu714df452015-01-01 07:55:04 +08002960 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002961 cmd->bind.vertex.offset[binding] = offset;
2962}
2963
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002964static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002965 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002966 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2967{
Chia-I Wu714df452015-01-01 07:55:04 +08002968 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002969 cmd->bind.index.offset = offset;
2970 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002971}
2972
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002974 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002975{
2976 cmd->bind.state.viewport = state;
2977}
2978
2979static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002980 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002981{
2982 cmd->bind.state.raster = state;
2983}
2984
2985static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002986 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002987{
2988 cmd->bind.state.ds = state;
2989}
2990
2991static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002992 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002993{
2994 cmd->bind.state.blend = state;
2995}
2996
Chia-I Wuf98dd882015-02-10 04:17:47 +08002997static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
2998{
2999 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3000 struct intel_pipeline_rmap *rmaps[5] = {
3001 pipeline->vs.rmap,
3002 pipeline->tcs.rmap,
3003 pipeline->tes.rmap,
3004 pipeline->gs.rmap,
3005 pipeline->fs.rmap,
3006 };
3007 uint32_t max_write;
3008 int i;
3009
3010 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3011 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3012 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3013
3014 /* pad first */
3015 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3016
3017 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3018 const struct intel_pipeline_rmap *rmap = rmaps[i];
3019 const uint32_t surface_count = (rmap) ?
3020 rmap->rt_count + rmap->texture_resource_count +
3021 rmap->resource_count + rmap->uav_count : 0;
3022
3023 if (surface_count) {
3024 /* SURFACE_STATEs */
3025 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3026
3027 /* BINDING_TABLE_STATE */
3028 max_write += u_align(sizeof(uint32_t) * surface_count,
3029 GEN6_ALIGNMENT_SURFACE_STATE);
3030 }
3031 }
3032
3033 return max_write;
3034}
3035
3036static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3037{
3038 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3039 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3040 uint32_t max_surface_write;
3041
3042 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3043 if (cmd->bind.meta)
3044 max_surface_write = 64 * sizeof(uint32_t);
3045 else
3046 max_surface_write = cmd_get_max_surface_write(cmd);
3047
3048 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3049 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3050 /* SBA expects page-aligned addresses */
3051 writer->sba_offset = writer->used & ~0xfff;
3052
3053 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3054
3055 cmd_batch_state_base_address(cmd);
3056 }
3057}
3058
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003059static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003060 uint32_t vertex_start,
3061 uint32_t vertex_count,
3062 uint32_t instance_start,
3063 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003064 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003065 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003066{
3067 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wuf98dd882015-02-10 04:17:47 +08003068 const uint32_t surface_writer_used =
3069 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3070
3071 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003072
3073 emit_bounded_states(cmd);
3074
Chia-I Wuf98dd882015-02-10 04:17:47 +08003075 /* sanity check on cmd_get_max_surface_write() */
3076 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3077 surface_writer_used <= cmd_get_max_surface_write(cmd));
3078
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003079 if (indexed) {
3080 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3081 cmd->result = XGL_ERROR_UNKNOWN;
3082
3083 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3084 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3085 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003086 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003087 cmd->bind.index.offset, cmd->bind.index.type,
3088 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003089 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003090 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003091 cmd->bind.index.offset, cmd->bind.index.type,
3092 p->primitive_restart);
3093 }
3094 } else {
3095 assert(!vertex_base);
3096 }
3097
3098 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3099 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3100 vertex_start, instance_count, instance_start, vertex_base);
3101 } else {
3102 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3103 vertex_start, instance_count, instance_start, vertex_base);
3104 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003105
Chia-I Wu707a29e2014-08-27 12:51:47 +08003106 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003107 /* need to re-emit all workarounds */
3108 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003109
3110 if (intel_debug & INTEL_DEBUG_NOCACHE)
3111 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003112}
3113
Chia-I Wuc14d1562014-10-17 09:49:22 +08003114void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3115{
Chia-I Wu6032b892014-10-17 14:47:18 +08003116 cmd->bind.meta = meta;
3117
Chia-I Wuf98dd882015-02-10 04:17:47 +08003118 cmd_adjust_state_base_address(cmd);
3119
Chia-I Wu6032b892014-10-17 14:47:18 +08003120 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003121 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003122
3123 gen6_meta_dynamic_states(cmd);
3124 gen6_meta_surface_states(cmd);
3125
3126 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3127 gen7_meta_urb(cmd);
3128 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003129 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003130 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003131 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003132 gen6_meta_wm(cmd);
3133 gen7_meta_ps(cmd);
3134 gen6_meta_depth_buffer(cmd);
3135
3136 cmd_wa_gen7_post_command_cs_stall(cmd);
3137 cmd_wa_gen7_post_command_depth_stall(cmd);
3138
Chia-I Wu29e6f502014-11-24 14:27:29 +08003139 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3140 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003141 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003142 } else {
3143 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3144 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003145 } else {
3146 gen6_meta_urb(cmd);
3147 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003148 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003149 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003150 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003151 gen6_meta_wm(cmd);
3152 gen6_meta_ps(cmd);
3153 gen6_meta_depth_buffer(cmd);
3154
Chia-I Wu29e6f502014-11-24 14:27:29 +08003155 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3156 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003157 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003158 } else {
3159 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3160 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003161 }
3162
3163 cmd->bind.draw_count++;
3164 /* need to re-emit all workarounds */
3165 cmd->bind.wa_flags = 0;
3166
3167 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003168
3169 if (intel_debug & INTEL_DEBUG_NOCACHE)
3170 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003171}
3172
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003173ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003174 XGL_CMD_BUFFER cmdBuffer,
3175 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3176 XGL_PIPELINE pipeline)
3177{
3178 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3179
3180 switch (pipelineBindPoint) {
3181 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003182 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003183 break;
3184 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003186 break;
3187 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003189 break;
3190 }
3191}
3192
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003193ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003194 XGL_CMD_BUFFER cmdBuffer,
3195 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3196 XGL_PIPELINE_DELTA delta)
3197{
3198 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3199
3200 switch (pipelineBindPoint) {
3201 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003202 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003203 break;
3204 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003209 break;
3210 }
3211}
3212
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003213ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003214 XGL_CMD_BUFFER cmdBuffer,
3215 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003216 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003217{
3218 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3219
3220 switch (stateBindPoint) {
3221 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003222 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003223 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003224 break;
3225 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003226 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003227 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003228 break;
3229 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003230 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003231 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003232 break;
3233 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003234 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003235 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003236 break;
3237 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003238 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003239 break;
3240 }
3241}
3242
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003243ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003244 XGL_CMD_BUFFER cmdBuffer,
3245 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003246 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003247 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003248{
3249 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003250 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003251
3252 switch (pipelineBindPoint) {
3253 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003254 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003255 break;
3256 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003257 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003258 break;
3259 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003260 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003261 break;
3262 }
3263}
3264
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003265ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003266 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003267 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003268 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003269 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003270{
3271 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003272 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003273
Chia-I Wu714df452015-01-01 07:55:04 +08003274 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003275}
3276
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003277ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003278 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003279 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003280 XGL_GPU_SIZE offset,
3281 XGL_INDEX_TYPE indexType)
3282{
3283 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003284 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003285
Chia-I Wu714df452015-01-01 07:55:04 +08003286 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003287}
3288
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003289ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003290 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003291 uint32_t firstVertex,
3292 uint32_t vertexCount,
3293 uint32_t firstInstance,
3294 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003295{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003296 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003297
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003298 cmd_draw(cmd, firstVertex, vertexCount,
3299 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003300}
3301
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003302ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003303 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003304 uint32_t firstIndex,
3305 uint32_t indexCount,
3306 int32_t vertexOffset,
3307 uint32_t firstInstance,
3308 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003309{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003310 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003311
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003312 cmd_draw(cmd, firstIndex, indexCount,
3313 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003314}
3315
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003316ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003317 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003318 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003319 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003320 uint32_t count,
3321 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003322{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003323 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3324
3325 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003326}
3327
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003328ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003329 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003330 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003331 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003332 uint32_t count,
3333 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003334{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003335 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3336
3337 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003338}
3339
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003340ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003341 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003342 uint32_t x,
3343 uint32_t y,
3344 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003345{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003346 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3347
3348 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003349}
3350
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003351ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003352 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003353 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003354 XGL_GPU_SIZE offset)
3355{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003356 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3357
3358 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003359}