blob: ac6e68c2e152df7ee693e98c6c438203e9f4c74b [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{
Mike Stroyan552fda42015-01-30 17:21:08 -07001213 if (pipe_control_dw0 == 0)
1214 return;
1215
Chia-I Wu525c6602014-08-27 10:22:34 +08001216 if (!cmd->bind.draw_count)
1217 return;
1218
1219 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1220
Chia-I Wu8370b402014-08-29 12:28:37 +08001221 /*
1222 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1223 *
1224 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1225 * PIPE_CONTROL with any non-zero post-sync-op is required."
1226 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001227 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001228 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001229
Chia-I Wu092279a2014-08-30 19:05:30 +08001230 /*
1231 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1232 *
1233 * "One of the following must also be set (when CS stall is set):
1234 *
1235 * * Render Target Cache Flush Enable ([12] of DW1)
1236 * * Depth Cache Flush Enable ([0] of DW1)
1237 * * Stall at Pixel Scoreboard ([1] of DW1)
1238 * * Depth Stall ([13] of DW1)
1239 * * Post-Sync Operation ([13] of DW1)"
1240 */
1241 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1242 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1243 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1244 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1245 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1246 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1247
Chia-I Wud6d079d2014-08-31 13:14:21 +08001248 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001249}
1250
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001251void cmd_batch_flush_all(struct intel_cmd *cmd)
1252{
1253 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1254 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1255 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1256 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1257 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1258 GEN6_PIPE_CONTROL_CS_STALL);
1259}
1260
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001261void cmd_batch_depth_count(struct intel_cmd *cmd,
1262 struct intel_bo *bo,
1263 XGL_GPU_SIZE offset)
1264{
1265 cmd_wa_gen6_pre_depth_stall_write(cmd);
1266
1267 gen6_PIPE_CONTROL(cmd,
1268 GEN6_PIPE_CONTROL_DEPTH_STALL |
1269 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001270 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001271}
1272
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001273void cmd_batch_timestamp(struct intel_cmd *cmd,
1274 struct intel_bo *bo,
1275 XGL_GPU_SIZE offset)
1276{
1277 /* need any WA or stall? */
1278 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1279}
1280
1281void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001282 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001283 struct intel_bo *bo,
1284 XGL_GPU_SIZE offset,
1285 uint64_t val)
1286{
1287 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001288 gen6_PIPE_CONTROL(cmd,
1289 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1290 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001291}
1292
Chia-I Wu302742d2014-08-22 10:28:29 +08001293static void gen6_cc_states(struct intel_cmd *cmd)
1294{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001295 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1296 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001297 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001298 uint32_t stencil_ref;
1299 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001300
1301 CMD_ASSERT(cmd, 6, 6);
1302
Chia-I Wua6c4f152014-12-02 04:19:58 +08001303 blend_offset = gen6_BLEND_STATE(cmd);
1304
1305 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001306 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001307 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001308 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001309
1310 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001311 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001312 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1313 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001314 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001315 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001316 stencil_ref = 0;
1317 }
1318
Chia-I Wu72292b72014-09-09 10:48:33 +08001319 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001320
Chia-I Wu72292b72014-09-09 10:48:33 +08001321 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001322}
1323
Chia-I Wu1744cca2014-08-22 11:10:17 +08001324static void gen6_viewport_states(struct intel_cmd *cmd)
1325{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001326 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001327 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001328
1329 if (!viewport)
1330 return;
1331
Tony Barbourfa6cac72015-01-16 14:27:35 -07001332 assert(viewport->cmd_len == (8 + 4 + 2) *
1333 viewport->viewport_count + (viewport->has_scissor_rects) ?
1334 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335
1336 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001337 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001338 viewport->cmd);
1339
1340 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001341 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001342 &viewport->cmd[viewport->cmd_clip_pos]);
1343
1344 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001345 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001346 &viewport->cmd[viewport->cmd_cc_pos]);
1347
Tony Barbourfa6cac72015-01-16 14:27:35 -07001348 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001349 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001350 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001351 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1352 } else {
1353 scissor_offset = 0;
1354 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001355
1356 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001357 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001358
Chia-I Wub1d450a2014-09-09 13:48:03 +08001359 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001360}
1361
Chia-I Wu302742d2014-08-22 10:28:29 +08001362static void gen7_cc_states(struct intel_cmd *cmd)
1363{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001364 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1365 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 uint32_t stencil_ref;
1367 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001368 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001369
1370 CMD_ASSERT(cmd, 7, 7.5);
1371
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001372 if (!blend && !ds)
1373 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001374
Chia-I Wua6c4f152014-12-02 04:19:58 +08001375 offset = gen6_BLEND_STATE(cmd);
1376 gen7_3dstate_pointer(cmd,
1377 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001378
Chia-I Wua6c4f152014-12-02 04:19:58 +08001379 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001380 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001381 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001382 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001383
1384 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001385 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001386 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1387 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001388 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001389 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1390 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001391 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1392 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001393 } else {
1394 stencil_ref = 0;
1395 }
1396
Chia-I Wu72292b72014-09-09 10:48:33 +08001397 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001398 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001399 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001400}
1401
Chia-I Wu1744cca2014-08-22 11:10:17 +08001402static void gen7_viewport_states(struct intel_cmd *cmd)
1403{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001404 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1405 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001406 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001407
1408 if (!viewport)
1409 return;
1410
Tony Barbourfa6cac72015-01-16 14:27:35 -07001411 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001413
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001415 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001416 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001417 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001418 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1419 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001420
1421 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001422 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001423 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001424 gen7_3dstate_pointer(cmd,
1425 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001426 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001427
Tony Barbourfa6cac72015-01-16 14:27:35 -07001428 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001429 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001430 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001431 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001432 gen7_3dstate_pointer(cmd,
1433 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001434 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001435 }
1436}
1437
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001438static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001439 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001440{
1441 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001442 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001443
Chia-I Wu72292b72014-09-09 10:48:33 +08001444 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001445
1446 dw[0] = GEN6_RENDER_TYPE_RENDER |
1447 GEN6_RENDER_SUBTYPE_3D |
1448 subop | (cmd_len - 2);
1449 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001450 dw[2] = 0;
1451 dw[3] = 0;
1452 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001453}
1454
1455static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001456 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001457{
1458 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001459 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001460
Chia-I Wu72292b72014-09-09 10:48:33 +08001461 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001462
1463 dw[0] = GEN6_RENDER_TYPE_RENDER |
1464 GEN6_RENDER_SUBTYPE_3D |
1465 subop | (cmd_len - 2);
1466 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001467 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001468 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001469 dw[4] = 0;
1470 dw[5] = 0;
1471 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001472}
1473
Chia-I Wu625105f2014-10-13 15:35:29 +08001474static uint32_t emit_samplers(struct intel_cmd *cmd,
1475 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001477 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1478 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001479 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001480 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001481 uint32_t surface_count;
1482 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001483
1484 CMD_ASSERT(cmd, 6, 7.5);
1485
Chia-I Wu625105f2014-10-13 15:35:29 +08001486 if (!rmap || !rmap->sampler_count)
1487 return 0;
1488
Cody Northrop40316a32014-12-09 19:08:33 -07001489 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001490
Chia-I Wudcb509d2014-12-10 08:53:10 +08001491 /*
1492 * note that we cannot call cmd_state_pointer() here as the following
1493 * cmd_state_pointer() would invalidate the pointer
1494 */
1495 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001496 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001497 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001498
1499 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001500 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001501 4 * rmap->sampler_count, &sampler_dw);
1502
Chia-I Wudcb509d2014-12-10 08:53:10 +08001503 cmd_state_update(cmd, border_offset,
1504 border_stride * rmap->sampler_count, &border_dw);
1505
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001506 for (i = 0; i < rmap->sampler_count; i++) {
1507 const struct intel_pipeline_rmap_slot *slot =
1508 &rmap->slots[surface_count + i];
1509 const struct intel_sampler *sampler;
1510
Chia-I Wuf8385062015-01-04 16:27:24 +08001511 switch (slot->type) {
1512 case INTEL_PIPELINE_RMAP_SAMPLER:
1513 intel_desc_pool_read_sampler(cmd->dev->desc_pool,
1514 &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001515 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001516 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001517 sampler = NULL;
1518 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001519 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001520 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001521 sampler = NULL;
1522 break;
1523 }
1524
1525 if (sampler) {
1526 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1527
1528 sampler_dw[0] = sampler->cmd[0];
1529 sampler_dw[1] = sampler->cmd[1];
1530 sampler_dw[2] = border_offset;
1531 sampler_dw[3] = sampler->cmd[2];
1532 } else {
1533 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1534 sampler_dw[1] = 0;
1535 sampler_dw[2] = 0;
1536 sampler_dw[3] = 0;
1537 }
1538
1539 border_offset += border_stride * 4;
1540 border_dw += border_stride;
1541 sampler_dw += 4;
1542 }
1543
Chia-I Wu625105f2014-10-13 15:35:29 +08001544 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001545}
1546
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001547static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001548 const struct intel_pipeline_rmap *rmap,
1549 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001550{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001551 const uint32_t sba_offset =
1552 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001553 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001554 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001555
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001556 CMD_ASSERT(cmd, 6, 7.5);
1557
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001558 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001559 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001560 if (!surface_count)
1561 return 0;
1562
Chia-I Wu42a56202014-08-23 16:47:48 +08001563 assert(surface_count <= ARRAY_SIZE(binding_table));
1564
1565 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001566 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001567 struct intel_null_view null_view;
1568 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001569
Chia-I Wuf8385062015-01-04 16:27:24 +08001570 switch (slot->type) {
1571 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001572 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001573 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001574 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1575 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001576
Chia-I Wu787a05b2014-12-05 11:02:20 +08001577 if (view) {
1578 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1579 GEN6_ALIGNMENT_SURFACE_STATE,
1580 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001581
Chia-I Wu787a05b2014-12-05 11:02:20 +08001582 cmd_reserve_reloc(cmd, 1);
1583 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1584 view->cmd[1], INTEL_RELOC_WRITE);
1585 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001586 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001587 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001588 }
1589 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001590 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001591 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001592 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1593 const struct intel_mem *mem;
1594 bool read_only;
1595 const uint32_t *cmd_data;
1596 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001597
Chia-I Wuf8385062015-01-04 16:27:24 +08001598 assert(dyn_idx < 0 || dyn_idx <
1599 cmd->bind.dset.graphics->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001600
Chia-I Wuf8385062015-01-04 16:27:24 +08001601 intel_desc_pool_read_surface(cmd->dev->desc_pool,
1602 &slot->u.surface.offset, stage, &mem,
1603 &read_only, &cmd_data, &cmd_len);
1604 if (mem) {
1605 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1606 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1607 const uint32_t reloc_flags =
1608 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001609
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001610 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001611 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001612 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001613
1614 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001615 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1616 cmd_data[1] + dynamic_offset, reloc_flags);
1617 } else {
1618 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001619 }
1620 }
1621 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001622 case INTEL_PIPELINE_RMAP_UNUSED:
1623 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001624 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001625 default:
1626 assert(!"unexpected rmap type");
1627 need_null_view = true;
1628 break;
1629 }
1630
1631 if (need_null_view) {
1632 intel_null_view_init(&null_view, cmd->dev);
1633 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1634 GEN6_ALIGNMENT_SURFACE_STATE,
1635 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001636 }
1637
Chia-I Wuf98dd882015-02-10 04:17:47 +08001638 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001639 }
1640
Chia-I Wuf98dd882015-02-10 04:17:47 +08001641 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001642 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001643 surface_count, binding_table) - sba_offset;
1644
1645 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1646 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1647
1648 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001649}
1650
Chia-I Wu1d125092014-10-08 08:49:38 +08001651static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1652{
1653 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001654 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1655 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001656 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001657
1658 CMD_ASSERT(cmd, 6, 7.5);
1659
1660 if (!pipeline->vb_count)
1661 return;
1662
1663 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1664
1665 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1666 dw++;
1667 pos++;
1668
1669 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001670 assert(pipeline->vb[i].strideInBytes <= 2048);
1671
1672 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1673 pipeline->vb[i].strideInBytes;
1674
1675 if (cmd_gen(cmd) >= INTEL_GEN(7))
1676 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1677
1678 switch (pipeline->vb[i].stepRate) {
1679 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1680 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1681 dw[3] = 0;
1682 break;
1683 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1684 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1685 dw[3] = 1;
1686 break;
1687 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1688 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1689 dw[3] = 0;
1690 break;
1691 default:
1692 assert(!"unknown step rate");
1693 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1694 dw[3] = 0;
1695 break;
1696 }
1697
Chia-I Wu714df452015-01-01 07:55:04 +08001698 if (cmd->bind.vertex.buf[i]) {
1699 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001700 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001701
1702 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001703 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1704 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001705 } else {
1706 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1707 dw[1] = 0;
1708 dw[2] = 0;
1709 }
1710
1711 dw += 4;
1712 pos += 4;
1713 }
1714}
1715
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001716static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1717{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001718 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1719 const struct intel_pipeline_shader *vs = &pipeline->vs;
1720 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001721 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001722 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001723 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001724 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001725
1726 CMD_ASSERT(cmd, 6, 7.5);
1727
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001728 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001729 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1730 *
1731 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1732 * 128-bit vertex elements to be passed into the payload for each
1733 * vertex."
1734 *
1735 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1736 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001737 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001738 vue_read_len = (vs->in_count + 1) / 2;
1739 if (!vue_read_len)
1740 vue_read_len = 1;
1741
1742 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1743 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1744
1745 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1746 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1747 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001748
1749 dw5 = GEN6_VS_DW5_STATISTICS |
1750 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001751
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001752 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001753 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001754 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001755 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001756
Chia-I Wube0a3d92014-09-02 13:20:59 +08001757 if (pipeline->disable_vs_cache)
1758 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1759
Chia-I Wu784d3042014-12-19 14:30:04 +08001760 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001761 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001762 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001763 dw[2] = dw2;
1764 dw[3] = 0; /* scratch */
1765 dw[4] = dw4;
1766 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001767
1768 if (vs->per_thread_scratch_size)
1769 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001770}
1771
Chia-I Wu625105f2014-10-13 15:35:29 +08001772static void emit_shader_resources(struct intel_cmd *cmd)
1773{
1774 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001775 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001776
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001777 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001778 cmd->bind.pipeline.graphics->vs.rmap,
1779 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001780 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001781 cmd->bind.pipeline.graphics->tcs.rmap,
1782 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001783 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001784 cmd->bind.pipeline.graphics->tes.rmap,
1785 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001786 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001787 cmd->bind.pipeline.graphics->gs.rmap,
1788 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001789 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001790 cmd->bind.pipeline.graphics->fs.rmap,
1791 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001792
1793 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1794 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1795 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1796 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1797 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1798
1799 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1800 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001801 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1802 binding_tables[0]);
1803 gen7_3dstate_pointer(cmd,
1804 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1805 binding_tables[1]);
1806 gen7_3dstate_pointer(cmd,
1807 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1808 binding_tables[2]);
1809 gen7_3dstate_pointer(cmd,
1810 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1811 binding_tables[3]);
1812 gen7_3dstate_pointer(cmd,
1813 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1814 binding_tables[4]);
1815
1816 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001817 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1818 samplers[0]);
1819 gen7_3dstate_pointer(cmd,
1820 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1821 samplers[1]);
1822 gen7_3dstate_pointer(cmd,
1823 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1824 samplers[2]);
1825 gen7_3dstate_pointer(cmd,
1826 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1827 samplers[3]);
1828 gen7_3dstate_pointer(cmd,
1829 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1830 samplers[4]);
1831 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001832 assert(!binding_tables[1] && !binding_tables[2]);
1833 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1834 binding_tables[0], binding_tables[3], binding_tables[4]);
1835
Chia-I Wu625105f2014-10-13 15:35:29 +08001836 assert(!samplers[1] && !samplers[2]);
1837 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1838 samplers[0], samplers[3], samplers[4]);
1839 }
1840}
1841
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001842static void emit_rt(struct intel_cmd *cmd)
1843{
1844 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001845 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1846 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001847}
1848
1849static void emit_ds(struct intel_cmd *cmd)
1850{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001851 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001852
1853 if (!ds) {
1854 /* all zeros */
1855 static const struct intel_ds_view null_ds;
1856 ds = &null_ds;
1857 }
1858
1859 cmd_wa_gen6_pre_ds_flush(cmd);
1860 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1861 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1862 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1863
1864 if (cmd_gen(cmd) >= INTEL_GEN(7))
1865 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1866 else
1867 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1868}
1869
Chia-I Wua57761b2014-10-14 14:27:44 +08001870static uint32_t emit_shader(struct intel_cmd *cmd,
1871 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001872{
Chia-I Wua57761b2014-10-14 14:27:44 +08001873 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1874 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001875 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001876
Chia-I Wua57761b2014-10-14 14:27:44 +08001877 /* see if the shader is already in the cache */
1878 for (i = 0; i < cache->used; i++) {
1879 if (cache->entries[i].shader == (const void *) shader)
1880 return cache->entries[i].kernel_offset;
1881 }
1882
1883 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1884
1885 /* grow the cache if full */
1886 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001887 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001888 void *entries;
1889
1890 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1891 XGL_SYSTEM_ALLOC_INTERNAL);
1892 if (entries) {
1893 if (cache->entries) {
1894 memcpy(entries, cache->entries,
1895 sizeof(cache->entries[0]) * cache->used);
1896 icd_free(cache->entries);
1897 }
1898
1899 cache->entries = entries;
1900 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001901 }
1902 }
1903
Chia-I Wua57761b2014-10-14 14:27:44 +08001904 /* add the shader to the cache */
1905 if (cache->used < cache->count) {
1906 cache->entries[cache->used].shader = (const void *) shader;
1907 cache->entries[cache->used].kernel_offset = offset;
1908 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001909 }
1910
Chia-I Wua57761b2014-10-14 14:27:44 +08001911 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001912}
1913
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001914static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001915{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001916 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001917
Chia-I Wu8370b402014-08-29 12:28:37 +08001918 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1919 cmd_wa_gen6_pre_depth_stall_write(cmd);
1920 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1921 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1922 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1923 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001924
1925 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001926 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001927 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001928
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001929 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001930 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001931 }
1932 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001933 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001934 }
1935 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001936 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1937 }
1938 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1939 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1940 }
1941 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1942 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001943 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001944
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001945 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1946 gen7_3DSTATE_GS(cmd);
1947 } else {
1948 gen6_3DSTATE_GS(cmd);
1949 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001950
Chia-I Wu8370b402014-08-29 12:28:37 +08001951 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1952 cmd_wa_gen7_post_command_cs_stall(cmd);
1953 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1954 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001955}
1956
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001957static void emit_bounded_states(struct intel_cmd *cmd)
1958{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001959
1960 emit_graphics_pipeline(cmd);
1961
1962 emit_rt(cmd);
1963 emit_ds(cmd);
1964
1965 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1966 gen7_cc_states(cmd);
1967 gen7_viewport_states(cmd);
1968
1969 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1970 &cmd->bind.pipeline.graphics->vs);
1971 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1972 &cmd->bind.pipeline.graphics->fs);
1973
1974 gen6_3DSTATE_CLIP(cmd);
1975 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001976 gen7_3DSTATE_WM(cmd);
1977 gen7_3DSTATE_PS(cmd);
1978 } else {
1979 gen6_cc_states(cmd);
1980 gen6_viewport_states(cmd);
1981
1982 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1983 &cmd->bind.pipeline.graphics->vs);
1984 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1985 &cmd->bind.pipeline.graphics->fs);
1986
1987 gen6_3DSTATE_CLIP(cmd);
1988 gen6_3DSTATE_SF(cmd);
1989 gen6_3DSTATE_WM(cmd);
1990 }
1991
1992 emit_shader_resources(cmd);
1993
1994 cmd_wa_gen6_pre_depth_stall_write(cmd);
1995 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1996
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001997 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1998 gen6_3DSTATE_VS(cmd);
1999}
2000
Tony Barbourfa6cac72015-01-16 14:27:35 -07002001static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
2002 const struct intel_cmd_meta *meta)
2003{
2004 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2005 const uint8_t cmd_len = 3;
2006 uint32_t dw[3];
2007 uint32_t cmd_depth_stencil;
2008 uint32_t cmd_depth_test;
2009
2010 CMD_ASSERT(cmd, 6, 7.5);
2011
2012 cmd_depth_stencil = 0;
2013 cmd_depth_test = 0;
2014 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
2015 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
2016 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2017 }
2018 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2019 cmd_depth_stencil = 1 << 31 |
2020 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2021 (GEN6_STENCILOP_KEEP) << 25 |
2022 (GEN6_STENCILOP_KEEP) << 22 |
2023 (GEN6_STENCILOP_REPLACE) << 19 |
2024 1 << 15 |
2025 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2026 (GEN6_STENCILOP_KEEP) << 9 |
2027 (GEN6_STENCILOP_KEEP) << 6 |
2028 (GEN6_STENCILOP_REPLACE) << 3;
2029 }
2030
2031 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2032 dw[0] = cmd_depth_stencil | 1 << 18;
2033 dw[1] = (0xff) << 24 | (0xff) << 16;
2034 dw[2] = cmd_depth_test;
2035
2036 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2037 cmd_align, cmd_len, dw);
2038}
2039
Chia-I Wu6032b892014-10-17 14:47:18 +08002040static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2041{
2042 const struct intel_cmd_meta *meta = cmd->bind.meta;
2043 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2044
2045 CMD_ASSERT(cmd, 6, 7.5);
2046
2047 blend_offset = 0;
2048 ds_offset = 0;
2049 cc_offset = 0;
2050 cc_vp_offset = 0;
2051
Chia-I Wu29e6f502014-11-24 14:27:29 +08002052 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002053 /* BLEND_STATE */
2054 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002055 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002056 dw[0] = 0;
2057 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2058 }
2059
Chia-I Wu29e6f502014-11-24 14:27:29 +08002060 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002061 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002062 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002063 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2064 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002065
Chia-I Wu29e6f502014-11-24 14:27:29 +08002066 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002067 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002068
Chia-I Wu29e6f502014-11-24 14:27:29 +08002069 /* COLOR_CALC_STATE */
2070 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002071 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002072
Chia-I Wu29e6f502014-11-24 14:27:29 +08002073 /* CC_VIEWPORT */
2074 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002075 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002076 dw[0] = u_fui(0.0f);
2077 dw[1] = u_fui(1.0f);
2078 } else {
2079 /* DEPTH_STENCIL_STATE */
2080 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002081 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002082 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2083 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2084 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002085 }
2086
2087 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2088 gen7_3dstate_pointer(cmd,
2089 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2090 blend_offset);
2091 gen7_3dstate_pointer(cmd,
2092 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2093 ds_offset);
2094 gen7_3dstate_pointer(cmd,
2095 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2096
2097 gen7_3dstate_pointer(cmd,
2098 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2099 cc_vp_offset);
2100 } else {
2101 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002102 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002103
2104 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2105 cmd_batch_pointer(cmd, 4, &dw);
2106 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2107 GEN6_PTR_VP_DW0_CC_CHANGED;
2108 dw[1] = 0;
2109 dw[2] = 0;
2110 dw[3] = cc_vp_offset;
2111 }
2112}
2113
2114static void gen6_meta_surface_states(struct intel_cmd *cmd)
2115{
2116 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002117 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002118 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002119 const uint32_t sba_offset =
2120 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002121
2122 CMD_ASSERT(cmd, 6, 7.5);
2123
Chia-I Wu29e6f502014-11-24 14:27:29 +08002124 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2125 return;
2126
Chia-I Wu005c47c2014-10-22 13:49:13 +08002127 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002128 if (meta->src.valid) {
2129 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002130 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002131 meta->src.surface_len, meta->src.surface);
2132
2133 cmd_reserve_reloc(cmd, 1);
2134 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2135 cmd_surface_reloc_writer(cmd, offset, 1,
2136 meta->src.reloc_target, meta->src.reloc_offset);
2137 } else {
2138 cmd_surface_reloc(cmd, offset, 1,
2139 (struct intel_bo *) meta->src.reloc_target,
2140 meta->src.reloc_offset, meta->src.reloc_flags);
2141 }
2142
Mike Stroyan9bfad482015-02-10 15:09:23 -07002143 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002144 }
2145 if (meta->dst.valid) {
2146 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002147 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002148 meta->dst.surface_len, meta->dst.surface);
2149
2150 cmd_reserve_reloc(cmd, 1);
2151 cmd_surface_reloc(cmd, offset, 1,
2152 (struct intel_bo *) meta->dst.reloc_target,
2153 meta->dst.reloc_offset, meta->dst.reloc_flags);
2154
Mike Stroyan9bfad482015-02-10 15:09:23 -07002155 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002156 }
2157
2158 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002159 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002160 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002161 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002162
2163 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002164 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2165 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2166 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002167 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002168 } else {
2169 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002170 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002171 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002172 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002173 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002174 }
2175}
2176
2177static void gen6_meta_urb(struct intel_cmd *cmd)
2178{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002179 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002180 uint32_t *dw;
2181
2182 CMD_ASSERT(cmd, 6, 6);
2183
2184 /* 3DSTATE_URB */
2185 cmd_batch_pointer(cmd, 3, &dw);
2186 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002187 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002188 dw[2] = 0;
2189}
2190
2191static void gen7_meta_urb(struct intel_cmd *cmd)
2192{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002193 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002194 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002195 uint32_t *dw;
2196
2197 CMD_ASSERT(cmd, 7, 7.5);
2198
2199 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2200 cmd_batch_pointer(cmd, 10, &dw);
2201
2202 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002203 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002204 dw += 2;
2205
2206 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2207 dw[1] = 0;
2208 dw += 2;
2209
2210 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2211 dw[1] = 0;
2212 dw += 2;
2213
2214 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2215 dw[1] = 0;
2216 dw += 2;
2217
2218 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002219 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002220
2221 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2222
Chia-I Wu24aa1022014-11-25 11:53:19 +08002223 switch (cmd_gen(cmd)) {
2224 case INTEL_GEN(7.5):
2225 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2226 break;
2227 case INTEL_GEN(7):
2228 default:
2229 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2230 break;
2231 }
2232
Chia-I Wu6032b892014-10-17 14:47:18 +08002233 /* 3DSTATE_URB_x */
2234 cmd_batch_pointer(cmd, 8, &dw);
2235
2236 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2237 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002238 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002239 dw += 2;
2240
2241 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2242 dw[1] = 0;
2243 dw += 2;
2244
2245 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2246 dw[1] = 0;
2247 dw += 2;
2248
2249 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2250 dw[1] = 0;
2251 dw += 2;
2252}
2253
2254static void gen6_meta_vf(struct intel_cmd *cmd)
2255{
2256 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002257 uint32_t vb_start, vb_end, vb_stride;
2258 int ve_format, ve_z_source;
2259 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002260 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002261
2262 CMD_ASSERT(cmd, 6, 7.5);
2263
Chia-I Wu29e6f502014-11-24 14:27:29 +08002264 switch (meta->mode) {
2265 case INTEL_CMD_META_VS_POINTS:
2266 cmd_batch_pointer(cmd, 3, &dw);
2267 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2268 dw[1] = GEN6_VE_STATE_DW0_VALID;
2269 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2270 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2271 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2272 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2273 return;
2274 break;
2275 case INTEL_CMD_META_FS_RECT:
2276 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002277 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002278
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 vertices[0][0] = meta->dst.x + meta->width;
2280 vertices[0][1] = meta->dst.y + meta->height;
2281 vertices[1][0] = meta->dst.x;
2282 vertices[1][1] = meta->dst.y + meta->height;
2283 vertices[2][0] = meta->dst.x;
2284 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2287 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002288
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 vb_end = vb_start + sizeof(vertices) - 1;
2290 vb_stride = sizeof(vertices[0]);
2291 ve_z_source = GEN6_VFCOMP_STORE_0;
2292 ve_format = GEN6_FORMAT_R32G32_USCALED;
2293 }
2294 break;
2295 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2296 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002297 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002298
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002299 vertices[0][0] = (float) (meta->dst.x + meta->width);
2300 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002301 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002302 vertices[1][0] = (float) meta->dst.x;
2303 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002304 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002305 vertices[2][0] = (float) meta->dst.x;
2306 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002307 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002308
Chia-I Wu29e6f502014-11-24 14:27:29 +08002309 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2310 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311
Chia-I Wu29e6f502014-11-24 14:27:29 +08002312 vb_end = vb_start + sizeof(vertices) - 1;
2313 vb_stride = sizeof(vertices[0]);
2314 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2315 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2316 }
2317 break;
2318 default:
2319 assert(!"unknown meta mode");
2320 return;
2321 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002322 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002323
2324 /* 3DSTATE_VERTEX_BUFFERS */
2325 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002326
Chia-I Wu6032b892014-10-17 14:47:18 +08002327 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002328 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002329 if (cmd_gen(cmd) >= INTEL_GEN(7))
2330 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2331
2332 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2334 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002335
2336 dw[4] = 0;
2337
2338 /* 3DSTATE_VERTEX_ELEMENTS */
2339 cmd_batch_pointer(cmd, 5, &dw);
2340 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002341 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002342 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2343 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2344 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2345 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2346 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002347 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002348 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2349 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002350 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002351 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2352}
2353
Chia-I Wu29e6f502014-11-24 14:27:29 +08002354static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002355{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002356 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002357 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002358 uint32_t consts[8];
2359 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002360
2361 CMD_ASSERT(cmd, 6, 7.5);
2362
2363 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002364 case INTEL_DEV_META_VS_FILL_MEM:
2365 consts[0] = meta->dst.x;
2366 consts[1] = meta->clear_val[0];
2367 const_count = 2;
2368 break;
2369 case INTEL_DEV_META_VS_COPY_MEM:
2370 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2371 consts[0] = meta->dst.x;
2372 consts[1] = meta->src.x;
2373 const_count = 2;
2374 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002375 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2376 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2377 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2378 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2379 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2380 consts[0] = meta->src.x;
2381 consts[1] = meta->src.y;
2382 consts[2] = meta->width;
2383 consts[3] = meta->dst.x;
2384 const_count = 4;
2385 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002386 default:
2387 assert(!"unknown meta shader id");
2388 const_count = 0;
2389 break;
2390 }
2391
2392 /* this can be skipped but it makes state dumping prettier */
2393 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2394
2395 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2396}
2397
2398static void gen6_meta_vs(struct intel_cmd *cmd)
2399{
2400 const struct intel_cmd_meta *meta = cmd->bind.meta;
2401 const struct intel_pipeline_shader *sh =
2402 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2403 uint32_t offset, *dw;
2404
2405 CMD_ASSERT(cmd, 6, 7.5);
2406
2407 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002408 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002409
2410 /* 3DSTATE_CONSTANT_VS */
2411 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2412 cmd_batch_pointer(cmd, cmd_len, &dw);
2413 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2414 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2415
2416 /* 3DSTATE_VS */
2417 cmd_batch_pointer(cmd, 6, &dw);
2418 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2419 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2420
2421 return;
2422 }
2423
2424 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2425
2426 /* 3DSTATE_CONSTANT_VS */
2427 offset = gen6_meta_vs_constants(cmd);
2428 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2429 cmd_batch_pointer(cmd, 7, &dw);
2430 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2431 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2432 dw[2] = 0;
2433 dw[3] = offset;
2434 dw[4] = 0;
2435 dw[5] = 0;
2436 dw[6] = 0;
2437 } else {
2438 cmd_batch_pointer(cmd, 5, &dw);
2439 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2440 GEN6_PCB_ANY_DW0_PCB0_VALID;
2441 dw[1] = offset;
2442 dw[2] = 0;
2443 dw[3] = 0;
2444 dw[4] = 0;
2445 }
2446
2447 /* 3DSTATE_VS */
2448 offset = emit_shader(cmd, sh);
2449 cmd_batch_pointer(cmd, 6, &dw);
2450 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2451 dw[1] = offset;
2452 dw[2] = GEN6_THREADDISP_SPF |
2453 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2454 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002455 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002456 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2457 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2458
2459 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2460 GEN6_VS_DW5_VS_ENABLE;
2461 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002462 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002463 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002464 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002465
2466 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002467}
2468
2469static void gen6_meta_disabled(struct intel_cmd *cmd)
2470{
Chia-I Wu6032b892014-10-17 14:47:18 +08002471 uint32_t *dw;
2472
2473 CMD_ASSERT(cmd, 6, 6);
2474
Chia-I Wu6032b892014-10-17 14:47:18 +08002475 /* 3DSTATE_CONSTANT_GS */
2476 cmd_batch_pointer(cmd, 5, &dw);
2477 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2478 dw[1] = 0;
2479 dw[2] = 0;
2480 dw[3] = 0;
2481 dw[4] = 0;
2482
2483 /* 3DSTATE_GS */
2484 cmd_batch_pointer(cmd, 7, &dw);
2485 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2486 dw[1] = 0;
2487 dw[2] = 0;
2488 dw[3] = 0;
2489 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2490 dw[5] = GEN6_GS_DW5_STATISTICS;
2491 dw[6] = 0;
2492
Chia-I Wu6032b892014-10-17 14:47:18 +08002493 /* 3DSTATE_SF */
2494 cmd_batch_pointer(cmd, 20, &dw);
2495 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2496 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2497 memset(&dw[2], 0, 18 * sizeof(*dw));
2498}
2499
2500static void gen7_meta_disabled(struct intel_cmd *cmd)
2501{
2502 uint32_t *dw;
2503
2504 CMD_ASSERT(cmd, 7, 7.5);
2505
Chia-I Wu6032b892014-10-17 14:47:18 +08002506 /* 3DSTATE_CONSTANT_HS */
2507 cmd_batch_pointer(cmd, 7, &dw);
2508 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2509 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2510
2511 /* 3DSTATE_HS */
2512 cmd_batch_pointer(cmd, 7, &dw);
2513 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2514 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2515
2516 /* 3DSTATE_TE */
2517 cmd_batch_pointer(cmd, 4, &dw);
2518 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2519 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2520
2521 /* 3DSTATE_CONSTANT_DS */
2522 cmd_batch_pointer(cmd, 7, &dw);
2523 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2524 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2525
2526 /* 3DSTATE_DS */
2527 cmd_batch_pointer(cmd, 6, &dw);
2528 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2529 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2530
2531 /* 3DSTATE_CONSTANT_GS */
2532 cmd_batch_pointer(cmd, 7, &dw);
2533 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2534 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2535
2536 /* 3DSTATE_GS */
2537 cmd_batch_pointer(cmd, 7, &dw);
2538 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2539 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2540
2541 /* 3DSTATE_STREAMOUT */
2542 cmd_batch_pointer(cmd, 3, &dw);
2543 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2544 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2545
Chia-I Wu6032b892014-10-17 14:47:18 +08002546 /* 3DSTATE_SF */
2547 cmd_batch_pointer(cmd, 7, &dw);
2548 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2549 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2550
2551 /* 3DSTATE_SBE */
2552 cmd_batch_pointer(cmd, 14, &dw);
2553 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2554 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2555 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002556}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002557
Chia-I Wu29e6f502014-11-24 14:27:29 +08002558static void gen6_meta_clip(struct intel_cmd *cmd)
2559{
2560 const struct intel_cmd_meta *meta = cmd->bind.meta;
2561 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002562
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563 /* 3DSTATE_CLIP */
2564 cmd_batch_pointer(cmd, 4, &dw);
2565 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2566 dw[1] = 0;
2567 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2568 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2569 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2570 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002571 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002572 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002573 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002574}
2575
2576static void gen6_meta_wm(struct intel_cmd *cmd)
2577{
2578 const struct intel_cmd_meta *meta = cmd->bind.meta;
2579 uint32_t *dw;
2580
2581 CMD_ASSERT(cmd, 6, 7.5);
2582
2583 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2584
2585 /* 3DSTATE_MULTISAMPLE */
2586 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2587 cmd_batch_pointer(cmd, 4, &dw);
2588 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2589 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2590 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2591 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2592 dw[2] = 0;
2593 dw[3] = 0;
2594 } else {
2595 cmd_batch_pointer(cmd, 3, &dw);
2596 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2597 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2598 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2599 dw[2] = 0;
2600 }
2601
2602 /* 3DSTATE_SAMPLE_MASK */
2603 cmd_batch_pointer(cmd, 2, &dw);
2604 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2605 dw[1] = (1 << meta->samples) - 1;
2606
2607 /* 3DSTATE_DRAWING_RECTANGLE */
2608 cmd_batch_pointer(cmd, 4, &dw);
2609 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2610 dw[1] = meta->dst.y << 16 | meta->dst.x;
2611 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2612 (meta->dst.x + meta->width - 1);
2613 dw[3] = 0;
2614}
2615
2616static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2617{
2618 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002619 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002620 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002621 uint32_t consts[8];
2622 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002623
2624 CMD_ASSERT(cmd, 6, 7.5);
2625
2626 /* underflow is fine here */
2627 offset_x = meta->src.x - meta->dst.x;
2628 offset_y = meta->src.y - meta->dst.y;
2629
2630 switch (meta->shader_id) {
2631 case INTEL_DEV_META_FS_COPY_MEM:
2632 case INTEL_DEV_META_FS_COPY_1D:
2633 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2634 case INTEL_DEV_META_FS_COPY_2D:
2635 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2636 case INTEL_DEV_META_FS_COPY_2D_MS:
2637 consts[0] = offset_x;
2638 consts[1] = offset_y;
2639 consts[2] = meta->src.layer;
2640 consts[3] = meta->src.lod;
2641 const_count = 4;
2642 break;
2643 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2644 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2645 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2646 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2647 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2648 consts[0] = offset_x;
2649 consts[1] = offset_y;
2650 consts[2] = meta->src.layer;
2651 consts[3] = meta->src.lod;
2652 consts[4] = meta->src.x;
2653 consts[5] = meta->width;
2654 const_count = 6;
2655 break;
2656 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2657 consts[0] = offset_x;
2658 consts[1] = offset_y;
2659 consts[2] = meta->width;
2660 const_count = 3;
2661 break;
2662 case INTEL_DEV_META_FS_CLEAR_COLOR:
2663 consts[0] = meta->clear_val[0];
2664 consts[1] = meta->clear_val[1];
2665 consts[2] = meta->clear_val[2];
2666 consts[3] = meta->clear_val[3];
2667 const_count = 4;
2668 break;
2669 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2670 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002671 consts[1] = meta->clear_val[1];
2672 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002673 break;
2674 case INTEL_DEV_META_FS_RESOLVE_2X:
2675 case INTEL_DEV_META_FS_RESOLVE_4X:
2676 case INTEL_DEV_META_FS_RESOLVE_8X:
2677 case INTEL_DEV_META_FS_RESOLVE_16X:
2678 consts[0] = offset_x;
2679 consts[1] = offset_y;
2680 const_count = 2;
2681 break;
2682 default:
2683 assert(!"unknown meta shader id");
2684 const_count = 0;
2685 break;
2686 }
2687
2688 /* this can be skipped but it makes state dumping prettier */
2689 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2690
2691 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2692}
2693
2694static void gen6_meta_ps(struct intel_cmd *cmd)
2695{
2696 const struct intel_cmd_meta *meta = cmd->bind.meta;
2697 const struct intel_pipeline_shader *sh =
2698 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2699 uint32_t offset, *dw;
2700
2701 CMD_ASSERT(cmd, 6, 6);
2702
Chia-I Wu29e6f502014-11-24 14:27:29 +08002703 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2704 /* 3DSTATE_CONSTANT_PS */
2705 cmd_batch_pointer(cmd, 5, &dw);
2706 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2707 dw[1] = 0;
2708 dw[2] = 0;
2709 dw[3] = 0;
2710 dw[4] = 0;
2711
2712 /* 3DSTATE_WM */
2713 cmd_batch_pointer(cmd, 9, &dw);
2714 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2715 dw[1] = 0;
2716 dw[2] = 0;
2717 dw[3] = 0;
2718 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002719 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002720 dw[6] = 0;
2721 dw[7] = 0;
2722 dw[8] = 0;
2723
Chia-I Wu3adf7212014-10-24 15:34:07 +08002724 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002725 }
2726
Chia-I Wu3adf7212014-10-24 15:34:07 +08002727 /* a normal color write */
2728 assert(meta->dst.valid && !sh->uses);
2729
Chia-I Wu6032b892014-10-17 14:47:18 +08002730 /* 3DSTATE_CONSTANT_PS */
2731 offset = gen6_meta_ps_constants(cmd);
2732 cmd_batch_pointer(cmd, 5, &dw);
2733 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2734 GEN6_PCB_ANY_DW0_PCB0_VALID;
2735 dw[1] = offset;
2736 dw[2] = 0;
2737 dw[3] = 0;
2738 dw[4] = 0;
2739
2740 /* 3DSTATE_WM */
2741 offset = emit_shader(cmd, sh);
2742 cmd_batch_pointer(cmd, 9, &dw);
2743 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2744 dw[1] = offset;
2745 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2746 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002747 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002748 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002749 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002750 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002751 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2752
Chia-I Wu6032b892014-10-17 14:47:18 +08002753 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2754 GEN6_WM_DW6_POSOFFSET_NONE |
2755 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2756 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2757 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2758 if (meta->samples > 1) {
2759 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2760 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2761 } else {
2762 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2763 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2764 }
2765 dw[7] = 0;
2766 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002767
2768 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002769}
2770
2771static void gen7_meta_ps(struct intel_cmd *cmd)
2772{
2773 const struct intel_cmd_meta *meta = cmd->bind.meta;
2774 const struct intel_pipeline_shader *sh =
2775 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2776 uint32_t offset, *dw;
2777
2778 CMD_ASSERT(cmd, 7, 7.5);
2779
Chia-I Wu29e6f502014-11-24 14:27:29 +08002780 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2781 /* 3DSTATE_WM */
2782 cmd_batch_pointer(cmd, 3, &dw);
2783 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2784 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2785
2786 /* 3DSTATE_CONSTANT_GS */
2787 cmd_batch_pointer(cmd, 7, &dw);
2788 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2789 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2790
2791 /* 3DSTATE_PS */
2792 cmd_batch_pointer(cmd, 8, &dw);
2793 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2794 dw[1] = 0;
2795 dw[2] = 0;
2796 dw[3] = 0;
2797 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002798 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002799 dw[5] = 0;
2800 dw[6] = 0;
2801 dw[7] = 0;
2802
Chia-I Wu3adf7212014-10-24 15:34:07 +08002803 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002804 }
2805
Chia-I Wu3adf7212014-10-24 15:34:07 +08002806 /* a normal color write */
2807 assert(meta->dst.valid && !sh->uses);
2808
Chia-I Wu6032b892014-10-17 14:47:18 +08002809 /* 3DSTATE_WM */
2810 cmd_batch_pointer(cmd, 3, &dw);
2811 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2812 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2813 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2814 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2815 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2816 dw[2] = 0;
2817
2818 /* 3DSTATE_CONSTANT_PS */
2819 offset = gen6_meta_ps_constants(cmd);
2820 cmd_batch_pointer(cmd, 7, &dw);
2821 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2822 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2823 dw[2] = 0;
2824 dw[3] = offset;
2825 dw[4] = 0;
2826 dw[5] = 0;
2827 dw[6] = 0;
2828
2829 /* 3DSTATE_PS */
2830 offset = emit_shader(cmd, sh);
2831 cmd_batch_pointer(cmd, 8, &dw);
2832 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2833 dw[1] = offset;
2834 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2835 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002836 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002837
2838 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2839 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002840 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2841
2842 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002843 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002844 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002845 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002846 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002847 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002848
2849 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2850 dw[6] = 0;
2851 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002852
2853 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002854}
2855
2856static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2857{
2858 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002859 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002860
2861 CMD_ASSERT(cmd, 6, 7.5);
2862
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002863 if (!ds) {
2864 /* all zeros */
2865 static const struct intel_ds_view null_ds;
2866 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002867 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002868
2869 cmd_wa_gen6_pre_ds_flush(cmd);
2870 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2871 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2872 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2873
2874 if (cmd_gen(cmd) >= INTEL_GEN(7))
2875 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2876 else
2877 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002878}
2879
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002880static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2881 const struct intel_pipeline *pipeline)
2882{
2883 cmd->bind.pipeline.graphics = pipeline;
2884}
2885
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002886static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2887 const struct intel_pipeline *pipeline)
2888{
2889 cmd->bind.pipeline.compute = pipeline;
2890}
2891
2892static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2893 const struct intel_pipeline_delta *delta)
2894{
2895 cmd->bind.pipeline.graphics_delta = delta;
2896}
2897
2898static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2899 const struct intel_pipeline_delta *delta)
2900{
2901 cmd->bind.pipeline.compute_delta = delta;
2902}
2903
2904static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002905 const struct intel_desc_set *dset,
2906 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002907{
Chia-I Wuf8385062015-01-04 16:27:24 +08002908 const uint32_t size = sizeof(*dynamic_offsets) *
2909 dset->layout->dynamic_desc_count;
2910
2911 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2912 if (cmd->bind.dset.graphics_dynamic_offsets)
2913 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2914
2915 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2916 4, XGL_SYSTEM_ALLOC_INTERNAL);
2917 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2918 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2919 return;
2920 }
2921
2922 cmd->bind.dset.graphics_dynamic_offset_size = size;
2923 }
2924
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002925 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002926 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002927}
2928
2929static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002930 const struct intel_desc_set *dset,
2931 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002932{
Chia-I Wuf8385062015-01-04 16:27:24 +08002933 const uint32_t size = sizeof(*dynamic_offsets) *
2934 dset->layout->dynamic_desc_count;
2935
2936 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2937 if (cmd->bind.dset.compute_dynamic_offsets)
2938 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2939
2940 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2941 4, XGL_SYSTEM_ALLOC_INTERNAL);
2942 if (!cmd->bind.dset.compute_dynamic_offsets) {
2943 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2944 return;
2945 }
2946
2947 cmd->bind.dset.compute_dynamic_offset_size = size;
2948 }
2949
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002951 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952}
2953
Chia-I Wu3b04af52014-11-08 10:48:20 +08002954static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002955 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002956 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002957{
Chia-I Wu714df452015-01-01 07:55:04 +08002958 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002959 cmd->result = XGL_ERROR_UNKNOWN;
2960 return;
2961 }
2962
Chia-I Wu714df452015-01-01 07:55:04 +08002963 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002964 cmd->bind.vertex.offset[binding] = offset;
2965}
2966
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002968 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002969 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2970{
Chia-I Wu714df452015-01-01 07:55:04 +08002971 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002972 cmd->bind.index.offset = offset;
2973 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002974}
2975
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002976static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002977 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002978{
2979 cmd->bind.state.viewport = state;
2980}
2981
2982static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002983 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002984{
2985 cmd->bind.state.raster = state;
2986}
2987
2988static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002989 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002990{
2991 cmd->bind.state.ds = state;
2992}
2993
2994static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002995 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002996{
2997 cmd->bind.state.blend = state;
2998}
2999
Chia-I Wuf98dd882015-02-10 04:17:47 +08003000static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3001{
3002 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3003 struct intel_pipeline_rmap *rmaps[5] = {
3004 pipeline->vs.rmap,
3005 pipeline->tcs.rmap,
3006 pipeline->tes.rmap,
3007 pipeline->gs.rmap,
3008 pipeline->fs.rmap,
3009 };
3010 uint32_t max_write;
3011 int i;
3012
3013 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3014 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3015 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3016
3017 /* pad first */
3018 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3019
3020 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3021 const struct intel_pipeline_rmap *rmap = rmaps[i];
3022 const uint32_t surface_count = (rmap) ?
3023 rmap->rt_count + rmap->texture_resource_count +
3024 rmap->resource_count + rmap->uav_count : 0;
3025
3026 if (surface_count) {
3027 /* SURFACE_STATEs */
3028 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3029
3030 /* BINDING_TABLE_STATE */
3031 max_write += u_align(sizeof(uint32_t) * surface_count,
3032 GEN6_ALIGNMENT_SURFACE_STATE);
3033 }
3034 }
3035
3036 return max_write;
3037}
3038
3039static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3040{
3041 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3042 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3043 uint32_t max_surface_write;
3044
3045 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3046 if (cmd->bind.meta)
3047 max_surface_write = 64 * sizeof(uint32_t);
3048 else
3049 max_surface_write = cmd_get_max_surface_write(cmd);
3050
3051 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3052 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3053 /* SBA expects page-aligned addresses */
3054 writer->sba_offset = writer->used & ~0xfff;
3055
3056 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3057
3058 cmd_batch_state_base_address(cmd);
3059 }
3060}
3061
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003062static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003063 uint32_t vertex_start,
3064 uint32_t vertex_count,
3065 uint32_t instance_start,
3066 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003067 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003068 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003069{
3070 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wuf98dd882015-02-10 04:17:47 +08003071 const uint32_t surface_writer_used =
3072 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3073
3074 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003075
3076 emit_bounded_states(cmd);
3077
Chia-I Wuf98dd882015-02-10 04:17:47 +08003078 /* sanity check on cmd_get_max_surface_write() */
3079 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3080 surface_writer_used <= cmd_get_max_surface_write(cmd));
3081
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003082 if (indexed) {
3083 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3084 cmd->result = XGL_ERROR_UNKNOWN;
3085
3086 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3087 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3088 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003089 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003090 cmd->bind.index.offset, cmd->bind.index.type,
3091 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003092 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003093 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003094 cmd->bind.index.offset, cmd->bind.index.type,
3095 p->primitive_restart);
3096 }
3097 } else {
3098 assert(!vertex_base);
3099 }
3100
3101 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3102 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3103 vertex_start, instance_count, instance_start, vertex_base);
3104 } else {
3105 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3106 vertex_start, instance_count, instance_start, vertex_base);
3107 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003108
Chia-I Wu707a29e2014-08-27 12:51:47 +08003109 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003110 /* need to re-emit all workarounds */
3111 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003112
3113 if (intel_debug & INTEL_DEBUG_NOCACHE)
3114 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115}
3116
Chia-I Wuc14d1562014-10-17 09:49:22 +08003117void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3118{
Chia-I Wu6032b892014-10-17 14:47:18 +08003119 cmd->bind.meta = meta;
3120
Chia-I Wuf98dd882015-02-10 04:17:47 +08003121 cmd_adjust_state_base_address(cmd);
3122
Chia-I Wu6032b892014-10-17 14:47:18 +08003123 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003124 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003125
3126 gen6_meta_dynamic_states(cmd);
3127 gen6_meta_surface_states(cmd);
3128
3129 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3130 gen7_meta_urb(cmd);
3131 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003132 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003133 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003134 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003135 gen6_meta_wm(cmd);
3136 gen7_meta_ps(cmd);
3137 gen6_meta_depth_buffer(cmd);
3138
3139 cmd_wa_gen7_post_command_cs_stall(cmd);
3140 cmd_wa_gen7_post_command_depth_stall(cmd);
3141
Chia-I Wu29e6f502014-11-24 14:27:29 +08003142 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3143 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003144 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003145 } else {
3146 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3147 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003148 } else {
3149 gen6_meta_urb(cmd);
3150 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003151 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003152 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003153 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003154 gen6_meta_wm(cmd);
3155 gen6_meta_ps(cmd);
3156 gen6_meta_depth_buffer(cmd);
3157
Chia-I Wu29e6f502014-11-24 14:27:29 +08003158 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3159 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003160 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003161 } else {
3162 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3163 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003164 }
3165
3166 cmd->bind.draw_count++;
3167 /* need to re-emit all workarounds */
3168 cmd->bind.wa_flags = 0;
3169
3170 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003171
3172 if (intel_debug & INTEL_DEBUG_NOCACHE)
3173 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003174}
3175
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003176ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003177 XGL_CMD_BUFFER cmdBuffer,
3178 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3179 XGL_PIPELINE pipeline)
3180{
3181 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3182
3183 switch (pipelineBindPoint) {
3184 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003185 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003186 break;
3187 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003189 break;
3190 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003191 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003192 break;
3193 }
3194}
3195
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003196ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003197 XGL_CMD_BUFFER cmdBuffer,
3198 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3199 XGL_PIPELINE_DELTA delta)
3200{
3201 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3202
3203 switch (pipelineBindPoint) {
3204 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003206 break;
3207 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003209 break;
3210 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003211 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003212 break;
3213 }
3214}
3215
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003216ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003217 XGL_CMD_BUFFER cmdBuffer,
3218 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003219 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003220{
3221 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3222
3223 switch (stateBindPoint) {
3224 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003226 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003227 break;
3228 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003229 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003230 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003231 break;
3232 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003233 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003234 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003235 break;
3236 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003238 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003239 break;
3240 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003241 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003242 break;
3243 }
3244}
3245
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003246ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003247 XGL_CMD_BUFFER cmdBuffer,
3248 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003249 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003250 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003251{
3252 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003253 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003254
3255 switch (pipelineBindPoint) {
3256 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003257 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003258 break;
3259 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003260 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003261 break;
3262 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003263 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003264 break;
3265 }
3266}
3267
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003268ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003269 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003270 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003271 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003272 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003273{
3274 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003275 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003276
Chia-I Wu714df452015-01-01 07:55:04 +08003277 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003278}
3279
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003280ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003281 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003282 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003283 XGL_GPU_SIZE offset,
3284 XGL_INDEX_TYPE indexType)
3285{
3286 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003287 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003288
Chia-I Wu714df452015-01-01 07:55:04 +08003289 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003290}
3291
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003292ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003293 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003294 uint32_t firstVertex,
3295 uint32_t vertexCount,
3296 uint32_t firstInstance,
3297 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003298{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003299 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003300
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003301 cmd_draw(cmd, firstVertex, vertexCount,
3302 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003303}
3304
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003305ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003306 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003307 uint32_t firstIndex,
3308 uint32_t indexCount,
3309 int32_t vertexOffset,
3310 uint32_t firstInstance,
3311 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003312{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003313 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003314
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003315 cmd_draw(cmd, firstIndex, indexCount,
3316 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003317}
3318
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003319ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003320 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003321 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003322 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003323 uint32_t count,
3324 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003325{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003326 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3327
3328 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003329}
3330
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003331ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003332 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003333 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003334 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003335 uint32_t count,
3336 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003337{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003338 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3339
3340 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003341}
3342
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003343ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003344 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003345 uint32_t x,
3346 uint32_t y,
3347 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003348{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003349 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3350
3351 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003352}
3353
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003354ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003355 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003356 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003357 XGL_GPU_SIZE offset)
3358{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003359 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3360
3361 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003362}