blob: 97baed834933fd58f567b5cee28877a06a213a35 [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;
2116
2117 CMD_ASSERT(cmd, 6, 7.5);
2118
Chia-I Wu29e6f502014-11-24 14:27:29 +08002119 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2120 return;
2121
Chia-I Wu005c47c2014-10-22 13:49:13 +08002122 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002123 if (meta->src.valid) {
2124 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002125 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002126 meta->src.surface_len, meta->src.surface);
2127
2128 cmd_reserve_reloc(cmd, 1);
2129 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2130 cmd_surface_reloc_writer(cmd, offset, 1,
2131 meta->src.reloc_target, meta->src.reloc_offset);
2132 } else {
2133 cmd_surface_reloc(cmd, offset, 1,
2134 (struct intel_bo *) meta->src.reloc_target,
2135 meta->src.reloc_offset, meta->src.reloc_flags);
2136 }
2137
Chia-I Wu005c47c2014-10-22 13:49:13 +08002138 binding_table[0] = offset;
2139 }
2140 if (meta->dst.valid) {
2141 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002142 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002143 meta->dst.surface_len, meta->dst.surface);
2144
2145 cmd_reserve_reloc(cmd, 1);
2146 cmd_surface_reloc(cmd, offset, 1,
2147 (struct intel_bo *) meta->dst.reloc_target,
2148 meta->dst.reloc_offset, meta->dst.reloc_flags);
2149
2150 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002151 }
2152
2153 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002154 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002155 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002156 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002157
2158 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002159 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2160 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2161 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2162 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002163 } else {
2164 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002165 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2166 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2167 else
2168 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 }
2170}
2171
2172static void gen6_meta_urb(struct intel_cmd *cmd)
2173{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002174 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002175 uint32_t *dw;
2176
2177 CMD_ASSERT(cmd, 6, 6);
2178
2179 /* 3DSTATE_URB */
2180 cmd_batch_pointer(cmd, 3, &dw);
2181 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002182 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002183 dw[2] = 0;
2184}
2185
2186static void gen7_meta_urb(struct intel_cmd *cmd)
2187{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002188 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002189 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002190 uint32_t *dw;
2191
2192 CMD_ASSERT(cmd, 7, 7.5);
2193
2194 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2195 cmd_batch_pointer(cmd, 10, &dw);
2196
2197 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002198 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002199 dw += 2;
2200
2201 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2202 dw[1] = 0;
2203 dw += 2;
2204
2205 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2206 dw[1] = 0;
2207 dw += 2;
2208
2209 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2210 dw[1] = 0;
2211 dw += 2;
2212
2213 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002214 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002215
2216 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2217
Chia-I Wu24aa1022014-11-25 11:53:19 +08002218 switch (cmd_gen(cmd)) {
2219 case INTEL_GEN(7.5):
2220 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2221 break;
2222 case INTEL_GEN(7):
2223 default:
2224 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2225 break;
2226 }
2227
Chia-I Wu6032b892014-10-17 14:47:18 +08002228 /* 3DSTATE_URB_x */
2229 cmd_batch_pointer(cmd, 8, &dw);
2230
2231 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2232 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002233 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002234 dw += 2;
2235
2236 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2237 dw[1] = 0;
2238 dw += 2;
2239
2240 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2241 dw[1] = 0;
2242 dw += 2;
2243
2244 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2245 dw[1] = 0;
2246 dw += 2;
2247}
2248
2249static void gen6_meta_vf(struct intel_cmd *cmd)
2250{
2251 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002252 uint32_t vb_start, vb_end, vb_stride;
2253 int ve_format, ve_z_source;
2254 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002255 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002256
2257 CMD_ASSERT(cmd, 6, 7.5);
2258
Chia-I Wu29e6f502014-11-24 14:27:29 +08002259 switch (meta->mode) {
2260 case INTEL_CMD_META_VS_POINTS:
2261 cmd_batch_pointer(cmd, 3, &dw);
2262 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2263 dw[1] = GEN6_VE_STATE_DW0_VALID;
2264 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2265 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2266 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2267 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2268 return;
2269 break;
2270 case INTEL_CMD_META_FS_RECT:
2271 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002272 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002273
Chia-I Wu29e6f502014-11-24 14:27:29 +08002274 vertices[0][0] = meta->dst.x + meta->width;
2275 vertices[0][1] = meta->dst.y + meta->height;
2276 vertices[1][0] = meta->dst.x;
2277 vertices[1][1] = meta->dst.y + meta->height;
2278 vertices[2][0] = meta->dst.x;
2279 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002280
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2282 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002283
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 vb_end = vb_start + sizeof(vertices) - 1;
2285 vb_stride = sizeof(vertices[0]);
2286 ve_z_source = GEN6_VFCOMP_STORE_0;
2287 ve_format = GEN6_FORMAT_R32G32_USCALED;
2288 }
2289 break;
2290 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2291 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002292 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002293
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002294 vertices[0][0] = (float) (meta->dst.x + meta->width);
2295 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002297 vertices[1][0] = (float) meta->dst.x;
2298 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002299 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002300 vertices[2][0] = (float) meta->dst.x;
2301 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002302 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002303
Chia-I Wu29e6f502014-11-24 14:27:29 +08002304 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2305 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002306
Chia-I Wu29e6f502014-11-24 14:27:29 +08002307 vb_end = vb_start + sizeof(vertices) - 1;
2308 vb_stride = sizeof(vertices[0]);
2309 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2310 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2311 }
2312 break;
2313 default:
2314 assert(!"unknown meta mode");
2315 return;
2316 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002317 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002318
2319 /* 3DSTATE_VERTEX_BUFFERS */
2320 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002321
Chia-I Wu6032b892014-10-17 14:47:18 +08002322 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002323 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002324 if (cmd_gen(cmd) >= INTEL_GEN(7))
2325 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2326
2327 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002328 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2329 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002330
2331 dw[4] = 0;
2332
2333 /* 3DSTATE_VERTEX_ELEMENTS */
2334 cmd_batch_pointer(cmd, 5, &dw);
2335 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002336 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002337 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2338 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2339 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2340 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2341 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002342 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002343 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2344 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002345 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002346 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2347}
2348
Chia-I Wu29e6f502014-11-24 14:27:29 +08002349static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002350{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002351 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002352 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002353 uint32_t consts[8];
2354 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002355
2356 CMD_ASSERT(cmd, 6, 7.5);
2357
2358 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002359 case INTEL_DEV_META_VS_FILL_MEM:
2360 consts[0] = meta->dst.x;
2361 consts[1] = meta->clear_val[0];
2362 const_count = 2;
2363 break;
2364 case INTEL_DEV_META_VS_COPY_MEM:
2365 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2366 consts[0] = meta->dst.x;
2367 consts[1] = meta->src.x;
2368 const_count = 2;
2369 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002370 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2371 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2372 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2373 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2374 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2375 consts[0] = meta->src.x;
2376 consts[1] = meta->src.y;
2377 consts[2] = meta->width;
2378 consts[3] = meta->dst.x;
2379 const_count = 4;
2380 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002381 default:
2382 assert(!"unknown meta shader id");
2383 const_count = 0;
2384 break;
2385 }
2386
2387 /* this can be skipped but it makes state dumping prettier */
2388 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2389
2390 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2391}
2392
2393static void gen6_meta_vs(struct intel_cmd *cmd)
2394{
2395 const struct intel_cmd_meta *meta = cmd->bind.meta;
2396 const struct intel_pipeline_shader *sh =
2397 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2398 uint32_t offset, *dw;
2399
2400 CMD_ASSERT(cmd, 6, 7.5);
2401
2402 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002403 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002404
2405 /* 3DSTATE_CONSTANT_VS */
2406 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2407 cmd_batch_pointer(cmd, cmd_len, &dw);
2408 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2409 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2410
2411 /* 3DSTATE_VS */
2412 cmd_batch_pointer(cmd, 6, &dw);
2413 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2414 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2415
2416 return;
2417 }
2418
2419 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2420
2421 /* 3DSTATE_CONSTANT_VS */
2422 offset = gen6_meta_vs_constants(cmd);
2423 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2424 cmd_batch_pointer(cmd, 7, &dw);
2425 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2426 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2427 dw[2] = 0;
2428 dw[3] = offset;
2429 dw[4] = 0;
2430 dw[5] = 0;
2431 dw[6] = 0;
2432 } else {
2433 cmd_batch_pointer(cmd, 5, &dw);
2434 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2435 GEN6_PCB_ANY_DW0_PCB0_VALID;
2436 dw[1] = offset;
2437 dw[2] = 0;
2438 dw[3] = 0;
2439 dw[4] = 0;
2440 }
2441
2442 /* 3DSTATE_VS */
2443 offset = emit_shader(cmd, sh);
2444 cmd_batch_pointer(cmd, 6, &dw);
2445 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2446 dw[1] = offset;
2447 dw[2] = GEN6_THREADDISP_SPF |
2448 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2449 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002450 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002451 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2452 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2453
2454 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2455 GEN6_VS_DW5_VS_ENABLE;
2456 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002457 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002458 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002459 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002460
2461 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002462}
2463
2464static void gen6_meta_disabled(struct intel_cmd *cmd)
2465{
Chia-I Wu6032b892014-10-17 14:47:18 +08002466 uint32_t *dw;
2467
2468 CMD_ASSERT(cmd, 6, 6);
2469
Chia-I Wu6032b892014-10-17 14:47:18 +08002470 /* 3DSTATE_CONSTANT_GS */
2471 cmd_batch_pointer(cmd, 5, &dw);
2472 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2473 dw[1] = 0;
2474 dw[2] = 0;
2475 dw[3] = 0;
2476 dw[4] = 0;
2477
2478 /* 3DSTATE_GS */
2479 cmd_batch_pointer(cmd, 7, &dw);
2480 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2481 dw[1] = 0;
2482 dw[2] = 0;
2483 dw[3] = 0;
2484 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2485 dw[5] = GEN6_GS_DW5_STATISTICS;
2486 dw[6] = 0;
2487
Chia-I Wu6032b892014-10-17 14:47:18 +08002488 /* 3DSTATE_SF */
2489 cmd_batch_pointer(cmd, 20, &dw);
2490 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2491 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2492 memset(&dw[2], 0, 18 * sizeof(*dw));
2493}
2494
2495static void gen7_meta_disabled(struct intel_cmd *cmd)
2496{
2497 uint32_t *dw;
2498
2499 CMD_ASSERT(cmd, 7, 7.5);
2500
Chia-I Wu6032b892014-10-17 14:47:18 +08002501 /* 3DSTATE_CONSTANT_HS */
2502 cmd_batch_pointer(cmd, 7, &dw);
2503 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2504 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2505
2506 /* 3DSTATE_HS */
2507 cmd_batch_pointer(cmd, 7, &dw);
2508 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2509 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2510
2511 /* 3DSTATE_TE */
2512 cmd_batch_pointer(cmd, 4, &dw);
2513 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2514 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2515
2516 /* 3DSTATE_CONSTANT_DS */
2517 cmd_batch_pointer(cmd, 7, &dw);
2518 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2520
2521 /* 3DSTATE_DS */
2522 cmd_batch_pointer(cmd, 6, &dw);
2523 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2525
2526 /* 3DSTATE_CONSTANT_GS */
2527 cmd_batch_pointer(cmd, 7, &dw);
2528 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2529 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2530
2531 /* 3DSTATE_GS */
2532 cmd_batch_pointer(cmd, 7, &dw);
2533 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2534 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2535
2536 /* 3DSTATE_STREAMOUT */
2537 cmd_batch_pointer(cmd, 3, &dw);
2538 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2539 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2540
Chia-I Wu6032b892014-10-17 14:47:18 +08002541 /* 3DSTATE_SF */
2542 cmd_batch_pointer(cmd, 7, &dw);
2543 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2544 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2545
2546 /* 3DSTATE_SBE */
2547 cmd_batch_pointer(cmd, 14, &dw);
2548 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2549 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2550 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002551}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002552
Chia-I Wu29e6f502014-11-24 14:27:29 +08002553static void gen6_meta_clip(struct intel_cmd *cmd)
2554{
2555 const struct intel_cmd_meta *meta = cmd->bind.meta;
2556 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002557
Chia-I Wu29e6f502014-11-24 14:27:29 +08002558 /* 3DSTATE_CLIP */
2559 cmd_batch_pointer(cmd, 4, &dw);
2560 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2561 dw[1] = 0;
2562 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2563 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2564 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2565 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002566 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002567 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002569}
2570
2571static void gen6_meta_wm(struct intel_cmd *cmd)
2572{
2573 const struct intel_cmd_meta *meta = cmd->bind.meta;
2574 uint32_t *dw;
2575
2576 CMD_ASSERT(cmd, 6, 7.5);
2577
2578 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2579
2580 /* 3DSTATE_MULTISAMPLE */
2581 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2582 cmd_batch_pointer(cmd, 4, &dw);
2583 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2584 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2585 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2586 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2587 dw[2] = 0;
2588 dw[3] = 0;
2589 } else {
2590 cmd_batch_pointer(cmd, 3, &dw);
2591 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2592 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2593 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2594 dw[2] = 0;
2595 }
2596
2597 /* 3DSTATE_SAMPLE_MASK */
2598 cmd_batch_pointer(cmd, 2, &dw);
2599 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2600 dw[1] = (1 << meta->samples) - 1;
2601
2602 /* 3DSTATE_DRAWING_RECTANGLE */
2603 cmd_batch_pointer(cmd, 4, &dw);
2604 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2605 dw[1] = meta->dst.y << 16 | meta->dst.x;
2606 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2607 (meta->dst.x + meta->width - 1);
2608 dw[3] = 0;
2609}
2610
2611static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2612{
2613 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002614 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002615 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002616 uint32_t consts[8];
2617 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002618
2619 CMD_ASSERT(cmd, 6, 7.5);
2620
2621 /* underflow is fine here */
2622 offset_x = meta->src.x - meta->dst.x;
2623 offset_y = meta->src.y - meta->dst.y;
2624
2625 switch (meta->shader_id) {
2626 case INTEL_DEV_META_FS_COPY_MEM:
2627 case INTEL_DEV_META_FS_COPY_1D:
2628 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2629 case INTEL_DEV_META_FS_COPY_2D:
2630 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2631 case INTEL_DEV_META_FS_COPY_2D_MS:
2632 consts[0] = offset_x;
2633 consts[1] = offset_y;
2634 consts[2] = meta->src.layer;
2635 consts[3] = meta->src.lod;
2636 const_count = 4;
2637 break;
2638 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2639 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2640 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2641 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2642 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2643 consts[0] = offset_x;
2644 consts[1] = offset_y;
2645 consts[2] = meta->src.layer;
2646 consts[3] = meta->src.lod;
2647 consts[4] = meta->src.x;
2648 consts[5] = meta->width;
2649 const_count = 6;
2650 break;
2651 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2652 consts[0] = offset_x;
2653 consts[1] = offset_y;
2654 consts[2] = meta->width;
2655 const_count = 3;
2656 break;
2657 case INTEL_DEV_META_FS_CLEAR_COLOR:
2658 consts[0] = meta->clear_val[0];
2659 consts[1] = meta->clear_val[1];
2660 consts[2] = meta->clear_val[2];
2661 consts[3] = meta->clear_val[3];
2662 const_count = 4;
2663 break;
2664 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2665 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002666 consts[1] = meta->clear_val[1];
2667 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002668 break;
2669 case INTEL_DEV_META_FS_RESOLVE_2X:
2670 case INTEL_DEV_META_FS_RESOLVE_4X:
2671 case INTEL_DEV_META_FS_RESOLVE_8X:
2672 case INTEL_DEV_META_FS_RESOLVE_16X:
2673 consts[0] = offset_x;
2674 consts[1] = offset_y;
2675 const_count = 2;
2676 break;
2677 default:
2678 assert(!"unknown meta shader id");
2679 const_count = 0;
2680 break;
2681 }
2682
2683 /* this can be skipped but it makes state dumping prettier */
2684 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2685
2686 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2687}
2688
2689static void gen6_meta_ps(struct intel_cmd *cmd)
2690{
2691 const struct intel_cmd_meta *meta = cmd->bind.meta;
2692 const struct intel_pipeline_shader *sh =
2693 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2694 uint32_t offset, *dw;
2695
2696 CMD_ASSERT(cmd, 6, 6);
2697
Chia-I Wu29e6f502014-11-24 14:27:29 +08002698 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2699 /* 3DSTATE_CONSTANT_PS */
2700 cmd_batch_pointer(cmd, 5, &dw);
2701 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2702 dw[1] = 0;
2703 dw[2] = 0;
2704 dw[3] = 0;
2705 dw[4] = 0;
2706
2707 /* 3DSTATE_WM */
2708 cmd_batch_pointer(cmd, 9, &dw);
2709 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2710 dw[1] = 0;
2711 dw[2] = 0;
2712 dw[3] = 0;
2713 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002714 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002715 dw[6] = 0;
2716 dw[7] = 0;
2717 dw[8] = 0;
2718
Chia-I Wu3adf7212014-10-24 15:34:07 +08002719 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002720 }
2721
Chia-I Wu3adf7212014-10-24 15:34:07 +08002722 /* a normal color write */
2723 assert(meta->dst.valid && !sh->uses);
2724
Chia-I Wu6032b892014-10-17 14:47:18 +08002725 /* 3DSTATE_CONSTANT_PS */
2726 offset = gen6_meta_ps_constants(cmd);
2727 cmd_batch_pointer(cmd, 5, &dw);
2728 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2729 GEN6_PCB_ANY_DW0_PCB0_VALID;
2730 dw[1] = offset;
2731 dw[2] = 0;
2732 dw[3] = 0;
2733 dw[4] = 0;
2734
2735 /* 3DSTATE_WM */
2736 offset = emit_shader(cmd, sh);
2737 cmd_batch_pointer(cmd, 9, &dw);
2738 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2739 dw[1] = offset;
2740 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2741 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002742 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002743 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002744 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002745 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002746 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2747
Chia-I Wu6032b892014-10-17 14:47:18 +08002748 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2749 GEN6_WM_DW6_POSOFFSET_NONE |
2750 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2751 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2752 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2753 if (meta->samples > 1) {
2754 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2755 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2756 } else {
2757 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2758 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2759 }
2760 dw[7] = 0;
2761 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002762
2763 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002764}
2765
2766static void gen7_meta_ps(struct intel_cmd *cmd)
2767{
2768 const struct intel_cmd_meta *meta = cmd->bind.meta;
2769 const struct intel_pipeline_shader *sh =
2770 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2771 uint32_t offset, *dw;
2772
2773 CMD_ASSERT(cmd, 7, 7.5);
2774
Chia-I Wu29e6f502014-11-24 14:27:29 +08002775 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2776 /* 3DSTATE_WM */
2777 cmd_batch_pointer(cmd, 3, &dw);
2778 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2779 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2780
2781 /* 3DSTATE_CONSTANT_GS */
2782 cmd_batch_pointer(cmd, 7, &dw);
2783 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2784 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2785
2786 /* 3DSTATE_PS */
2787 cmd_batch_pointer(cmd, 8, &dw);
2788 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2789 dw[1] = 0;
2790 dw[2] = 0;
2791 dw[3] = 0;
2792 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002793 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002794 dw[5] = 0;
2795 dw[6] = 0;
2796 dw[7] = 0;
2797
Chia-I Wu3adf7212014-10-24 15:34:07 +08002798 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002799 }
2800
Chia-I Wu3adf7212014-10-24 15:34:07 +08002801 /* a normal color write */
2802 assert(meta->dst.valid && !sh->uses);
2803
Chia-I Wu6032b892014-10-17 14:47:18 +08002804 /* 3DSTATE_WM */
2805 cmd_batch_pointer(cmd, 3, &dw);
2806 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2807 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2808 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2809 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2810 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2811 dw[2] = 0;
2812
2813 /* 3DSTATE_CONSTANT_PS */
2814 offset = gen6_meta_ps_constants(cmd);
2815 cmd_batch_pointer(cmd, 7, &dw);
2816 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2817 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2818 dw[2] = 0;
2819 dw[3] = offset;
2820 dw[4] = 0;
2821 dw[5] = 0;
2822 dw[6] = 0;
2823
2824 /* 3DSTATE_PS */
2825 offset = emit_shader(cmd, sh);
2826 cmd_batch_pointer(cmd, 8, &dw);
2827 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2828 dw[1] = offset;
2829 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2830 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002831 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002832
2833 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2834 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002835 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2836
2837 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002838 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002839 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002840 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002841 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002842 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002843
2844 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2845 dw[6] = 0;
2846 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002847
2848 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002849}
2850
2851static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2852{
2853 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002854 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002855
2856 CMD_ASSERT(cmd, 6, 7.5);
2857
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002858 if (!ds) {
2859 /* all zeros */
2860 static const struct intel_ds_view null_ds;
2861 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002862 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002863
2864 cmd_wa_gen6_pre_ds_flush(cmd);
2865 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2866 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2867 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2868
2869 if (cmd_gen(cmd) >= INTEL_GEN(7))
2870 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2871 else
2872 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002873}
2874
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002875static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2876 const struct intel_pipeline *pipeline)
2877{
2878 cmd->bind.pipeline.graphics = pipeline;
2879}
2880
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002881static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2882 const struct intel_pipeline *pipeline)
2883{
2884 cmd->bind.pipeline.compute = pipeline;
2885}
2886
2887static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2888 const struct intel_pipeline_delta *delta)
2889{
2890 cmd->bind.pipeline.graphics_delta = delta;
2891}
2892
2893static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2894 const struct intel_pipeline_delta *delta)
2895{
2896 cmd->bind.pipeline.compute_delta = delta;
2897}
2898
2899static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002900 const struct intel_desc_set *dset,
2901 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002902{
Chia-I Wuf8385062015-01-04 16:27:24 +08002903 const uint32_t size = sizeof(*dynamic_offsets) *
2904 dset->layout->dynamic_desc_count;
2905
2906 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2907 if (cmd->bind.dset.graphics_dynamic_offsets)
2908 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2909
2910 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2911 4, XGL_SYSTEM_ALLOC_INTERNAL);
2912 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2913 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2914 return;
2915 }
2916
2917 cmd->bind.dset.graphics_dynamic_offset_size = size;
2918 }
2919
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002920 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002921 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002922}
2923
2924static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002925 const struct intel_desc_set *dset,
2926 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002927{
Chia-I Wuf8385062015-01-04 16:27:24 +08002928 const uint32_t size = sizeof(*dynamic_offsets) *
2929 dset->layout->dynamic_desc_count;
2930
2931 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2932 if (cmd->bind.dset.compute_dynamic_offsets)
2933 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2934
2935 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2936 4, XGL_SYSTEM_ALLOC_INTERNAL);
2937 if (!cmd->bind.dset.compute_dynamic_offsets) {
2938 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2939 return;
2940 }
2941
2942 cmd->bind.dset.compute_dynamic_offset_size = size;
2943 }
2944
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002945 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002946 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002947}
2948
Chia-I Wu3b04af52014-11-08 10:48:20 +08002949static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002950 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002951 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002952{
Chia-I Wu714df452015-01-01 07:55:04 +08002953 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002954 cmd->result = XGL_ERROR_UNKNOWN;
2955 return;
2956 }
2957
Chia-I Wu714df452015-01-01 07:55:04 +08002958 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002959 cmd->bind.vertex.offset[binding] = offset;
2960}
2961
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002962static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002963 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002964 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2965{
Chia-I Wu714df452015-01-01 07:55:04 +08002966 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002967 cmd->bind.index.offset = offset;
2968 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969}
2970
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002971static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002972 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973{
2974 cmd->bind.state.viewport = state;
2975}
2976
2977static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002978 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002979{
2980 cmd->bind.state.raster = state;
2981}
2982
2983static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002984 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002985{
2986 cmd->bind.state.ds = state;
2987}
2988
2989static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002990 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002991{
2992 cmd->bind.state.blend = state;
2993}
2994
Chia-I Wuf98dd882015-02-10 04:17:47 +08002995static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
2996{
2997 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
2998 struct intel_pipeline_rmap *rmaps[5] = {
2999 pipeline->vs.rmap,
3000 pipeline->tcs.rmap,
3001 pipeline->tes.rmap,
3002 pipeline->gs.rmap,
3003 pipeline->fs.rmap,
3004 };
3005 uint32_t max_write;
3006 int i;
3007
3008 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3009 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3010 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3011
3012 /* pad first */
3013 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3014
3015 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3016 const struct intel_pipeline_rmap *rmap = rmaps[i];
3017 const uint32_t surface_count = (rmap) ?
3018 rmap->rt_count + rmap->texture_resource_count +
3019 rmap->resource_count + rmap->uav_count : 0;
3020
3021 if (surface_count) {
3022 /* SURFACE_STATEs */
3023 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3024
3025 /* BINDING_TABLE_STATE */
3026 max_write += u_align(sizeof(uint32_t) * surface_count,
3027 GEN6_ALIGNMENT_SURFACE_STATE);
3028 }
3029 }
3030
3031 return max_write;
3032}
3033
3034static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3035{
3036 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3037 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3038 uint32_t max_surface_write;
3039
3040 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3041 if (cmd->bind.meta)
3042 max_surface_write = 64 * sizeof(uint32_t);
3043 else
3044 max_surface_write = cmd_get_max_surface_write(cmd);
3045
3046 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3047 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3048 /* SBA expects page-aligned addresses */
3049 writer->sba_offset = writer->used & ~0xfff;
3050
3051 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3052
3053 cmd_batch_state_base_address(cmd);
3054 }
3055}
3056
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003057static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003058 uint32_t vertex_start,
3059 uint32_t vertex_count,
3060 uint32_t instance_start,
3061 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003062 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003063 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003064{
3065 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wuf98dd882015-02-10 04:17:47 +08003066 const uint32_t surface_writer_used =
3067 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3068
3069 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003070
3071 emit_bounded_states(cmd);
3072
Chia-I Wuf98dd882015-02-10 04:17:47 +08003073 /* sanity check on cmd_get_max_surface_write() */
3074 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3075 surface_writer_used <= cmd_get_max_surface_write(cmd));
3076
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003077 if (indexed) {
3078 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3079 cmd->result = XGL_ERROR_UNKNOWN;
3080
3081 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3082 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3083 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003084 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003085 cmd->bind.index.offset, cmd->bind.index.type,
3086 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003087 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003088 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003089 cmd->bind.index.offset, cmd->bind.index.type,
3090 p->primitive_restart);
3091 }
3092 } else {
3093 assert(!vertex_base);
3094 }
3095
3096 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3097 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3098 vertex_start, instance_count, instance_start, vertex_base);
3099 } else {
3100 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3101 vertex_start, instance_count, instance_start, vertex_base);
3102 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003103
Chia-I Wu707a29e2014-08-27 12:51:47 +08003104 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003105 /* need to re-emit all workarounds */
3106 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003107
3108 if (intel_debug & INTEL_DEBUG_NOCACHE)
3109 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003110}
3111
Chia-I Wuc14d1562014-10-17 09:49:22 +08003112void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3113{
Chia-I Wu6032b892014-10-17 14:47:18 +08003114 cmd->bind.meta = meta;
3115
Chia-I Wuf98dd882015-02-10 04:17:47 +08003116 cmd_adjust_state_base_address(cmd);
3117
Chia-I Wu6032b892014-10-17 14:47:18 +08003118 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003119 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003120
3121 gen6_meta_dynamic_states(cmd);
3122 gen6_meta_surface_states(cmd);
3123
3124 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3125 gen7_meta_urb(cmd);
3126 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003127 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003128 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003129 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003130 gen6_meta_wm(cmd);
3131 gen7_meta_ps(cmd);
3132 gen6_meta_depth_buffer(cmd);
3133
3134 cmd_wa_gen7_post_command_cs_stall(cmd);
3135 cmd_wa_gen7_post_command_depth_stall(cmd);
3136
Chia-I Wu29e6f502014-11-24 14:27:29 +08003137 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3138 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003139 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003140 } else {
3141 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3142 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003143 } else {
3144 gen6_meta_urb(cmd);
3145 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003146 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003147 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003148 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003149 gen6_meta_wm(cmd);
3150 gen6_meta_ps(cmd);
3151 gen6_meta_depth_buffer(cmd);
3152
Chia-I Wu29e6f502014-11-24 14:27:29 +08003153 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3154 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003155 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003156 } else {
3157 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3158 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003159 }
3160
3161 cmd->bind.draw_count++;
3162 /* need to re-emit all workarounds */
3163 cmd->bind.wa_flags = 0;
3164
3165 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003166
3167 if (intel_debug & INTEL_DEBUG_NOCACHE)
3168 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003169}
3170
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003171ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003172 XGL_CMD_BUFFER cmdBuffer,
3173 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3174 XGL_PIPELINE pipeline)
3175{
3176 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3177
3178 switch (pipelineBindPoint) {
3179 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003180 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003181 break;
3182 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003183 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003184 break;
3185 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003186 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003187 break;
3188 }
3189}
3190
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003191ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003192 XGL_CMD_BUFFER cmdBuffer,
3193 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3194 XGL_PIPELINE_DELTA delta)
3195{
3196 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3197
3198 switch (pipelineBindPoint) {
3199 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003200 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003201 break;
3202 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003204 break;
3205 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003207 break;
3208 }
3209}
3210
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003211ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003212 XGL_CMD_BUFFER cmdBuffer,
3213 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003214 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003215{
3216 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3217
3218 switch (stateBindPoint) {
3219 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003220 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003221 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003222 break;
3223 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003224 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003225 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003226 break;
3227 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003228 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003229 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003230 break;
3231 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003232 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003233 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003234 break;
3235 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003236 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003237 break;
3238 }
3239}
3240
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003241ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003242 XGL_CMD_BUFFER cmdBuffer,
3243 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003244 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003245 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003246{
3247 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003248 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003249
3250 switch (pipelineBindPoint) {
3251 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003252 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003253 break;
3254 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003255 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003256 break;
3257 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003258 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003259 break;
3260 }
3261}
3262
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003263ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003264 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003265 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003266 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003267 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003268{
3269 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003270 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003271
Chia-I Wu714df452015-01-01 07:55:04 +08003272 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003273}
3274
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003275ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003276 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003277 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003278 XGL_GPU_SIZE offset,
3279 XGL_INDEX_TYPE indexType)
3280{
3281 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003282 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003283
Chia-I Wu714df452015-01-01 07:55:04 +08003284 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003285}
3286
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003287ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003288 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003289 uint32_t firstVertex,
3290 uint32_t vertexCount,
3291 uint32_t firstInstance,
3292 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003293{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003294 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003295
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003296 cmd_draw(cmd, firstVertex, vertexCount,
3297 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003298}
3299
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003300ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003301 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003302 uint32_t firstIndex,
3303 uint32_t indexCount,
3304 int32_t vertexOffset,
3305 uint32_t firstInstance,
3306 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003307{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003308 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003309
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003310 cmd_draw(cmd, firstIndex, indexCount,
3311 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003312}
3313
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003314ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003315 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003316 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003317 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003318 uint32_t count,
3319 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003320{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003321 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3322
3323 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003324}
3325
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003326ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003327 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003328 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003329 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003330 uint32_t count,
3331 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003332{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003333 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3334
3335 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003336}
3337
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003338ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003339 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003340 uint32_t x,
3341 uint32_t y,
3342 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003343{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003344 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3345
3346 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003347}
3348
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003349ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003350 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003351 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003352 XGL_GPU_SIZE offset)
3353{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003354 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3355
3356 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003357}