blob: 241baddc94aec6b89af7c5e5d05435d0c820ede5 [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
Chia-I Wu8016a172014-08-29 18:31:32 +0800443static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
444{
445 const uint8_t cmd_len = 20;
446 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
447 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800448 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800449 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800450 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800451
452 CMD_ASSERT(cmd, 6, 6);
453
454 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800455
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 cmd_batch_pointer(cmd, cmd_len, &dw);
457 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800458 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800460 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800461}
462
463static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
464{
465 const uint8_t cmd_len = 7;
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, 7, 7.5);
469
Chia-I Wu72292b72014-09-09 10:48:33 +0800470 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800471 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
472 (cmd_len - 2);
473 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800474}
475
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800476static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
477{
478 const uint8_t cmd_len = 4;
479 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
480 (cmd_len - 2);
481 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700482 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800483 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700484 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800485 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800486
487 CMD_ASSERT(cmd, 6, 7.5);
488
489 dw1 = GEN6_CLIP_DW1_STATISTICS;
490 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
491 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
492 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700493 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800494 }
495
496 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
497 GEN6_CLIP_DW2_XY_TEST_ENABLE |
498 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700499 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800500 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
501 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
502 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
503
504 if (pipeline->rasterizerDiscardEnable)
505 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
506 else
507 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
508
509 if (pipeline->depthClipEnable)
510 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
511
512 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
513 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
514 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
515 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
516
517 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
518 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
519 (viewport->viewport_count - 1);
520
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600521 /* TODO: framebuffer requests layer_count > 1 */
522 if (cmd->bind.render_pass->fb->layer_count == 1) {
523 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
524 }
525
Chia-I Wu72292b72014-09-09 10:48:33 +0800526 cmd_batch_pointer(cmd, cmd_len, &dw);
527 dw[0] = dw0;
528 dw[1] = dw1;
529 dw[2] = dw2;
530 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800531}
532
Chia-I Wu784d3042014-12-19 14:30:04 +0800533static void gen6_add_scratch_space(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600534 uint32_t batch_pos,
Chia-I Wu784d3042014-12-19 14:30:04 +0800535 const struct intel_pipeline *pipeline,
536 const struct intel_pipeline_shader *sh)
537{
538 int scratch_space;
539
540 CMD_ASSERT(cmd, 6, 7.5);
541
542 assert(sh->per_thread_scratch_size &&
543 sh->per_thread_scratch_size % 1024 == 0 &&
544 u_is_pow2(sh->per_thread_scratch_size) &&
545 sh->scratch_offset % 1024 == 0);
546 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
547
548 cmd_reserve_reloc(cmd, 1);
549 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
550 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
551}
552
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800553static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
554{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800555 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800556 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800557 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600558 uint32_t pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800559 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800560
561 CMD_ASSERT(cmd, 6, 6);
562
563 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
564
565 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
566 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
567
568 dw4 = GEN6_WM_DW4_STATISTICS |
569 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
570 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
571 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
572
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800573 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800574 GEN6_WM_DW5_PS_ENABLE |
575 GEN6_WM_DW5_8_PIXEL_DISPATCH;
576
577 if (fs->uses & INTEL_SHADER_USE_KILL ||
578 pipeline->cb_state.alphaToCoverageEnable)
579 dw5 |= GEN6_WM_DW5_PS_KILL;
580
Cody Northrope238deb2015-01-26 14:41:36 -0700581 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800582 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
583 if (fs->uses & INTEL_SHADER_USE_DEPTH)
584 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
585 if (fs->uses & INTEL_SHADER_USE_W)
586 dw5 |= GEN6_WM_DW5_PS_USE_W;
587
588 if (pipeline->cb_state.dualSourceBlendEnable)
589 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
590
591 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
592 GEN6_WM_DW6_POSOFFSET_NONE |
593 GEN6_WM_DW6_ZW_INTERP_PIXEL |
594 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
595 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
596
Tony Barbourfa6cac72015-01-16 14:27:35 -0700597 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800598 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
599 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
600 } else {
601 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
602 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
603 }
604
Chia-I Wu784d3042014-12-19 14:30:04 +0800605 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800606 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800607 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800608 dw[2] = dw2;
609 dw[3] = 0; /* scratch */
610 dw[4] = dw4;
611 dw[5] = dw5;
612 dw[6] = dw6;
613 dw[7] = 0; /* kernel 1 */
614 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800615
616 if (fs->per_thread_scratch_size)
617 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800618}
619
620static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
621{
622 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800623 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800624 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800625 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800626
627 CMD_ASSERT(cmd, 7, 7.5);
628
629 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
630
631 dw1 = GEN7_WM_DW1_STATISTICS |
632 GEN7_WM_DW1_PS_ENABLE |
633 GEN7_WM_DW1_ZW_INTERP_PIXEL |
634 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
635 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
636
637 if (fs->uses & INTEL_SHADER_USE_KILL ||
638 pipeline->cb_state.alphaToCoverageEnable)
639 dw1 |= GEN7_WM_DW1_PS_KILL;
640
Cody Northrope238deb2015-01-26 14:41:36 -0700641 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
642
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643 if (fs->uses & INTEL_SHADER_USE_DEPTH)
644 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
645 if (fs->uses & INTEL_SHADER_USE_W)
646 dw1 |= GEN7_WM_DW1_PS_USE_W;
647
648 dw2 = 0;
649
Tony Barbourfa6cac72015-01-16 14:27:35 -0700650 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
652 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
653 } else {
654 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
655 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
656 }
657
Chia-I Wu72292b72014-09-09 10:48:33 +0800658 cmd_batch_pointer(cmd, cmd_len, &dw);
659 dw[0] = dw0;
660 dw[1] = dw1;
661 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800662}
663
664static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
665{
666 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800667 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800669 uint32_t dw0, dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600670 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671
672 CMD_ASSERT(cmd, 7, 7.5);
673
674 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
675
676 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
677 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
678
679 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
680 GEN7_PS_DW4_8_PIXEL_DISPATCH;
681
682 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800683 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700684 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800685 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800686 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687 }
688
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800689 if (fs->in_count)
690 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
691
692 if (pipeline->cb_state.dualSourceBlendEnable)
693 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
694
695 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
696 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
697 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
698
Chia-I Wu784d3042014-12-19 14:30:04 +0800699 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800700 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800701 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800702 dw[2] = dw2;
703 dw[3] = 0; /* scratch */
704 dw[4] = dw4;
705 dw[5] = dw5;
706 dw[6] = 0; /* kernel 1 */
707 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800708
709 if (fs->per_thread_scratch_size)
710 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800711}
712
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800713static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
714 const struct intel_ds_view *view)
715{
716 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600718 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800719
720 CMD_ASSERT(cmd, 6, 7.5);
721
722 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800723 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
724 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800725 dw0 |= (cmd_len - 2);
726
Chia-I Wu72292b72014-09-09 10:48:33 +0800727 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
728 dw[0] = dw0;
729 dw[1] = view->cmd[0];
730 dw[2] = 0;
731 dw[3] = view->cmd[2];
732 dw[4] = view->cmd[3];
733 dw[5] = view->cmd[4];
734 dw[6] = view->cmd[5];
735
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600736 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800737 cmd_reserve_reloc(cmd, 1);
738 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
739 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600740 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800741}
742
743static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
744 const struct intel_ds_view *view)
745{
746 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800747 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600748 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800749
750 CMD_ASSERT(cmd, 6, 7.5);
751
752 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800753 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
754 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800755 dw0 |= (cmd_len - 2);
756
Chia-I Wu72292b72014-09-09 10:48:33 +0800757 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
758 dw[0] = dw0;
759 dw[1] = view->cmd[6];
760 dw[2] = 0;
761
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600762 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800763 cmd_reserve_reloc(cmd, 1);
764 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
765 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600766 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767}
768
769static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
770 const struct intel_ds_view *view)
771{
772 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800773 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600774 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800775
776 CMD_ASSERT(cmd, 6, 7.5);
777
778 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800779 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
780 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800781 dw0 |= (cmd_len - 2);
782
Chia-I Wu72292b72014-09-09 10:48:33 +0800783 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
784 dw[0] = dw0;
785 dw[1] = view->cmd[8];
786 dw[2] = 0;
787
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600788 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800789 cmd_reserve_reloc(cmd, 1);
790 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
791 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600792 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793}
794
Chia-I Wuf8231032014-08-25 10:44:45 +0800795static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
796 uint32_t clear_val)
797{
798 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800799 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800800 GEN6_CLEAR_PARAMS_DW0_VALID |
801 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800802 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800803
804 CMD_ASSERT(cmd, 6, 6);
805
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 cmd_batch_pointer(cmd, cmd_len, &dw);
807 dw[0] = dw0;
808 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800809}
810
811static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
812 uint32_t clear_val)
813{
814 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800815 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800816 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800817 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800818
819 CMD_ASSERT(cmd, 7, 7.5);
820
Chia-I Wu72292b72014-09-09 10:48:33 +0800821 cmd_batch_pointer(cmd, cmd_len, &dw);
822 dw[0] = dw0;
823 dw[1] = clear_val;
824 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800825}
826
Chia-I Wu302742d2014-08-22 10:28:29 +0800827static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800828 uint32_t blend_offset,
829 uint32_t ds_offset,
830 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800831{
832 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800834
835 CMD_ASSERT(cmd, 6, 6);
836
Chia-I Wu426072d2014-08-26 14:31:55 +0800837 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800838 (cmd_len - 2);
839
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 cmd_batch_pointer(cmd, cmd_len, &dw);
841 dw[0] = dw0;
842 dw[1] = blend_offset | 1;
843 dw[2] = ds_offset | 1;
844 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800845}
846
Chia-I Wu1744cca2014-08-22 11:10:17 +0800847static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800848 uint32_t clip_offset,
849 uint32_t sf_offset,
850 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800851{
852 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800853 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800854
855 CMD_ASSERT(cmd, 6, 6);
856
Chia-I Wu426072d2014-08-26 14:31:55 +0800857 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800858 GEN6_PTR_VP_DW0_CLIP_CHANGED |
859 GEN6_PTR_VP_DW0_SF_CHANGED |
860 GEN6_PTR_VP_DW0_CC_CHANGED |
861 (cmd_len - 2);
862
Chia-I Wu72292b72014-09-09 10:48:33 +0800863 cmd_batch_pointer(cmd, cmd_len, &dw);
864 dw[0] = dw0;
865 dw[1] = clip_offset;
866 dw[2] = sf_offset;
867 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868}
869
870static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800871 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800872{
873 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800874 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800875
876 CMD_ASSERT(cmd, 6, 6);
877
Chia-I Wu426072d2014-08-26 14:31:55 +0800878 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800879 (cmd_len - 2);
880
Chia-I Wu72292b72014-09-09 10:48:33 +0800881 cmd_batch_pointer(cmd, cmd_len, &dw);
882 dw[0] = dw0;
883 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884}
885
Chia-I Wu42a56202014-08-23 16:47:48 +0800886static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 uint32_t vs_offset,
888 uint32_t gs_offset,
889 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800890{
891 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800893
894 CMD_ASSERT(cmd, 6, 6);
895
Chia-I Wu426072d2014-08-26 14:31:55 +0800896 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800897 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
898 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
899 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
900 (cmd_len - 2);
901
Chia-I Wu72292b72014-09-09 10:48:33 +0800902 cmd_batch_pointer(cmd, cmd_len, &dw);
903 dw[0] = dw0;
904 dw[1] = vs_offset;
905 dw[2] = gs_offset;
906 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800907}
908
Chia-I Wu257e75e2014-08-29 14:06:35 +0800909static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800910 uint32_t vs_offset,
911 uint32_t gs_offset,
912 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800913{
914 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800915 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800916
917 CMD_ASSERT(cmd, 6, 6);
918
919 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
920 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
921 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
922 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
923 (cmd_len - 2);
924
Chia-I Wu72292b72014-09-09 10:48:33 +0800925 cmd_batch_pointer(cmd, cmd_len, &dw);
926 dw[0] = dw0;
927 dw[1] = vs_offset;
928 dw[2] = gs_offset;
929 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930}
931
Chia-I Wu302742d2014-08-22 10:28:29 +0800932static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800934{
935 const uint8_t cmd_len = 2;
936 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
937 GEN6_RENDER_SUBTYPE_3D |
938 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800940
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 cmd_batch_pointer(cmd, cmd_len, &dw);
942 dw[0] = dw0;
943 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800944}
945
Chia-I Wua6c4f152014-12-02 04:19:58 +0800946static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800947{
Chia-I Wue6073342014-11-30 09:43:42 +0800948 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700949 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
950 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800951
952 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700953 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800954
Tony Barbourfa6cac72015-01-16 14:27:35 -0700955 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800956}
957
Chia-I Wu72292b72014-09-09 10:48:33 +0800958static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700959 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800960{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800962 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800963 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700964 uint32_t dw[3];
965
966 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700967 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700968 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700969 (state->ds_info.stencilWriteMask & 0xff) << 16 |
970 (state->ds_info.stencilReadMask & 0xff) << 8 |
971 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700972 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800973
974 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700975
976 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
977 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800978
Chia-I Wu00b51a82014-09-09 12:07:37 +0800979 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700980 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800981}
982
Chia-I Wu72292b72014-09-09 10:48:33 +0800983static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800984 uint32_t stencil_ref,
985 const uint32_t blend_color[4])
986{
Chia-I Wue6073342014-11-30 09:43:42 +0800987 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800988 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
991 CMD_ASSERT(cmd, 6, 7.5);
992
Chia-I Wu00b51a82014-09-09 12:07:37 +0800993 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
994 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800995 dw[0] = stencil_ref;
996 dw[1] = 0;
997 dw[2] = blend_color[0];
998 dw[3] = blend_color[1];
999 dw[4] = blend_color[2];
1000 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001003}
1004
Chia-I Wu8370b402014-08-29 12:28:37 +08001005static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001006{
Chia-I Wu8370b402014-08-29 12:28:37 +08001007 CMD_ASSERT(cmd, 6, 7.5);
1008
Chia-I Wu707a29e2014-08-27 12:51:47 +08001009 if (!cmd->bind.draw_count)
1010 return;
1011
Chia-I Wu8370b402014-08-29 12:28:37 +08001012 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001013 return;
1014
Chia-I Wu8370b402014-08-29 12:28:37 +08001015 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001016
1017 /*
1018 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1019 *
1020 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1021 * pipe-control with a post-sync op and no write-cache flushes."
1022 *
1023 * The workaround below necessitates this workaround.
1024 */
1025 gen6_PIPE_CONTROL(cmd,
1026 GEN6_PIPE_CONTROL_CS_STALL |
1027 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001028 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001029
Chia-I Wud6d079d2014-08-31 13:14:21 +08001030 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1031 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001032}
1033
Chia-I Wu8370b402014-08-29 12:28:37 +08001034static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001035{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001036 CMD_ASSERT(cmd, 6, 7.5);
1037
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001038 if (!cmd->bind.draw_count)
1039 return;
1040
Chia-I Wud6d079d2014-08-31 13:14:21 +08001041 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1042 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001043}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001044
Chia-I Wu8370b402014-08-29 12:28:37 +08001045static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1046{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001047 CMD_ASSERT(cmd, 7, 7.5);
1048
Chia-I Wu8370b402014-08-29 12:28:37 +08001049 if (!cmd->bind.draw_count)
1050 return;
1051
1052 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053
1054 gen6_PIPE_CONTROL(cmd,
1055 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001056 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001057}
1058
Chia-I Wu8370b402014-08-29 12:28:37 +08001059static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1060{
1061 CMD_ASSERT(cmd, 7, 7.5);
1062
1063 if (!cmd->bind.draw_count)
1064 return;
1065
1066 /*
1067 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1068 *
1069 * "One of the following must also be set (when CS stall is set):
1070 *
1071 * * Render Target Cache Flush Enable ([12] of DW1)
1072 * * Depth Cache Flush Enable ([0] of DW1)
1073 * * Stall at Pixel Scoreboard ([1] of DW1)
1074 * * Depth Stall ([13] of DW1)
1075 * * Post-Sync Operation ([13] of DW1)"
1076 */
1077 gen6_PIPE_CONTROL(cmd,
1078 GEN6_PIPE_CONTROL_CS_STALL |
1079 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001080 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001081}
1082
1083static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1084{
1085 CMD_ASSERT(cmd, 7, 7.5);
1086
1087 if (!cmd->bind.draw_count)
1088 return;
1089
1090 cmd_wa_gen6_pre_depth_stall_write(cmd);
1091
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001093}
1094
1095static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1096{
1097 CMD_ASSERT(cmd, 6, 7.5);
1098
1099 if (!cmd->bind.draw_count)
1100 return;
1101
1102 /*
1103 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1104 *
1105 * "Driver must guarentee that all the caches in the depth pipe are
1106 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1107 * requires driver to send a PIPE_CONTROL with a CS stall along with
1108 * a Depth Flush prior to this command."
1109 *
1110 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1111 *
1112 * "Driver must ierarchi that all the caches in the depth pipe are
1113 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1114 * requires driver to send a PIPE_CONTROL with a CS stall along with
1115 * a Depth Flush prior to this command.
1116 */
1117 gen6_PIPE_CONTROL(cmd,
1118 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1119 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001120 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001121}
1122
1123static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1124{
1125 CMD_ASSERT(cmd, 6, 7.5);
1126
1127 if (!cmd->bind.draw_count)
1128 return;
1129
1130 /*
1131 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1132 *
1133 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1134 * and a post sync operation prior to the group of depth
1135 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1136 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1137 *
1138 * This workaround satifies all the conditions.
1139 */
1140 cmd_wa_gen6_pre_depth_stall_write(cmd);
1141
1142 /*
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1144 *
1145 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1146 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1147 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1148 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1149 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1150 * Depth Flush Bit set, followed by another pipelined depth stall
1151 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1152 * guarantee that the pipeline from WM onwards is already flushed
1153 * (e.g., via a preceding MI_FLUSH)."
1154 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001155 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1156 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1157 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001158}
1159
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001160void cmd_batch_state_base_address(struct intel_cmd *cmd)
1161{
1162 const uint8_t cmd_len = 10;
1163 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1164 (cmd_len - 2);
1165 uint32_t pos;
1166 uint32_t *dw;
1167
1168 CMD_ASSERT(cmd, 6, 7.5);
1169
1170 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1171
1172 dw[0] = dw0;
1173 /* start offsets */
1174 dw[1] = 1;
1175 dw[2] = 1;
1176 dw[3] = 1;
1177 dw[4] = 1;
1178 dw[5] = 1;
1179 /* end offsets */
1180 dw[6] = 1;
1181 dw[7] = 1 + 0xfffff000;
1182 dw[8] = 1 + 0xfffff000;
1183 dw[9] = 1;
1184
1185 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001186 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1187 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1188 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1189 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1190 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1191 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001192}
1193
Chia-I Wu525c6602014-08-27 10:22:34 +08001194void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1195{
Mike Stroyan552fda42015-01-30 17:21:08 -07001196 if (pipe_control_dw0 == 0)
1197 return;
1198
Chia-I Wu525c6602014-08-27 10:22:34 +08001199 if (!cmd->bind.draw_count)
1200 return;
1201
1202 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1203
Chia-I Wu8370b402014-08-29 12:28:37 +08001204 /*
1205 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1206 *
1207 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1208 * PIPE_CONTROL with any non-zero post-sync-op is required."
1209 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001210 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001211 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001212
Chia-I Wu092279a2014-08-30 19:05:30 +08001213 /*
1214 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1215 *
1216 * "One of the following must also be set (when CS stall is set):
1217 *
1218 * * Render Target Cache Flush Enable ([12] of DW1)
1219 * * Depth Cache Flush Enable ([0] of DW1)
1220 * * Stall at Pixel Scoreboard ([1] of DW1)
1221 * * Depth Stall ([13] of DW1)
1222 * * Post-Sync Operation ([13] of DW1)"
1223 */
1224 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1225 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1226 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1227 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1228 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1229 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1230
Chia-I Wud6d079d2014-08-31 13:14:21 +08001231 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001232}
1233
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001234void cmd_batch_flush_all(struct intel_cmd *cmd)
1235{
1236 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1237 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1238 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1239 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1240 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1241 GEN6_PIPE_CONTROL_CS_STALL);
1242}
1243
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001244void cmd_batch_depth_count(struct intel_cmd *cmd,
1245 struct intel_bo *bo,
1246 XGL_GPU_SIZE offset)
1247{
1248 cmd_wa_gen6_pre_depth_stall_write(cmd);
1249
1250 gen6_PIPE_CONTROL(cmd,
1251 GEN6_PIPE_CONTROL_DEPTH_STALL |
1252 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001253 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001254}
1255
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001256void cmd_batch_timestamp(struct intel_cmd *cmd,
1257 struct intel_bo *bo,
1258 XGL_GPU_SIZE offset)
1259{
1260 /* need any WA or stall? */
1261 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1262}
1263
1264void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001265 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001266 struct intel_bo *bo,
1267 XGL_GPU_SIZE offset,
1268 uint64_t val)
1269{
1270 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001271 gen6_PIPE_CONTROL(cmd,
1272 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1273 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001274}
1275
Chia-I Wu302742d2014-08-22 10:28:29 +08001276static void gen6_cc_states(struct intel_cmd *cmd)
1277{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001278 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1279 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001280 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001281 uint32_t stencil_ref;
1282 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001283
1284 CMD_ASSERT(cmd, 6, 6);
1285
Chia-I Wua6c4f152014-12-02 04:19:58 +08001286 blend_offset = gen6_BLEND_STATE(cmd);
1287
1288 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001289 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001290 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001291 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001292
1293 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001294 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001295 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1296 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001297 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001298 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001299 stencil_ref = 0;
1300 }
1301
Chia-I Wu72292b72014-09-09 10:48:33 +08001302 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001303
Chia-I Wu72292b72014-09-09 10:48:33 +08001304 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001305}
1306
Chia-I Wu1744cca2014-08-22 11:10:17 +08001307static void gen6_viewport_states(struct intel_cmd *cmd)
1308{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001309 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001310 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001311
1312 if (!viewport)
1313 return;
1314
Tony Barbourfa6cac72015-01-16 14:27:35 -07001315 assert(viewport->cmd_len == (8 + 4 + 2) *
1316 viewport->viewport_count + (viewport->has_scissor_rects) ?
1317 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001318
1319 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001320 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001321 viewport->cmd);
1322
1323 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001324 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001325 &viewport->cmd[viewport->cmd_clip_pos]);
1326
1327 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001328 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001329 &viewport->cmd[viewport->cmd_cc_pos]);
1330
Tony Barbourfa6cac72015-01-16 14:27:35 -07001331 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001333 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001334 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1335 } else {
1336 scissor_offset = 0;
1337 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001338
1339 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001340 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001341
Chia-I Wub1d450a2014-09-09 13:48:03 +08001342 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001343}
1344
Chia-I Wu302742d2014-08-22 10:28:29 +08001345static void gen7_cc_states(struct intel_cmd *cmd)
1346{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001347 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1348 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001349 uint32_t stencil_ref;
1350 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001351 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001352
1353 CMD_ASSERT(cmd, 7, 7.5);
1354
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001355 if (!blend && !ds)
1356 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001357
Chia-I Wua6c4f152014-12-02 04:19:58 +08001358 offset = gen6_BLEND_STATE(cmd);
1359 gen7_3dstate_pointer(cmd,
1360 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001361
Chia-I Wua6c4f152014-12-02 04:19:58 +08001362 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001363 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001364 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001365 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366
1367 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001368 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001369 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1370 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001371 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001372 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1373 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001374 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1375 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001376 } else {
1377 stencil_ref = 0;
1378 }
1379
Chia-I Wu72292b72014-09-09 10:48:33 +08001380 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001381 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001382 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001383}
1384
Chia-I Wu1744cca2014-08-22 11:10:17 +08001385static void gen7_viewport_states(struct intel_cmd *cmd)
1386{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001387 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1388 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001389 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001390
1391 if (!viewport)
1392 return;
1393
Tony Barbourfa6cac72015-01-16 14:27:35 -07001394 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001395 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001396
Chia-I Wub1d450a2014-09-09 13:48:03 +08001397 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001398 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001401 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1402 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001403
1404 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001405 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001406 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001407 gen7_3dstate_pointer(cmd,
1408 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001409 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001410
Tony Barbourfa6cac72015-01-16 14:27:35 -07001411 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001412 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001413 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001414 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001415 gen7_3dstate_pointer(cmd,
1416 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001417 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001418 }
1419}
1420
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001421static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001422 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001423{
1424 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001425 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001426
Chia-I Wu72292b72014-09-09 10:48:33 +08001427 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001428
1429 dw[0] = GEN6_RENDER_TYPE_RENDER |
1430 GEN6_RENDER_SUBTYPE_3D |
1431 subop | (cmd_len - 2);
1432 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001433 dw[2] = 0;
1434 dw[3] = 0;
1435 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001436}
1437
1438static void gen7_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 = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001442 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +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;
Chia-I Wu46809782014-10-07 15:40:38 +08001451 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001452 dw[4] = 0;
1453 dw[5] = 0;
1454 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001455}
1456
Chia-I Wu625105f2014-10-13 15:35:29 +08001457static uint32_t emit_samplers(struct intel_cmd *cmd,
1458 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001459{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001460 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1461 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001462 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001463 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001464 uint32_t surface_count;
1465 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001466
1467 CMD_ASSERT(cmd, 6, 7.5);
1468
Chia-I Wu625105f2014-10-13 15:35:29 +08001469 if (!rmap || !rmap->sampler_count)
1470 return 0;
1471
Cody Northrop40316a32014-12-09 19:08:33 -07001472 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001473
Chia-I Wudcb509d2014-12-10 08:53:10 +08001474 /*
1475 * note that we cannot call cmd_state_pointer() here as the following
1476 * cmd_state_pointer() would invalidate the pointer
1477 */
1478 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001479 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001480 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001481
1482 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001483 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001484 4 * rmap->sampler_count, &sampler_dw);
1485
Chia-I Wudcb509d2014-12-10 08:53:10 +08001486 cmd_state_update(cmd, border_offset,
1487 border_stride * rmap->sampler_count, &border_dw);
1488
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 for (i = 0; i < rmap->sampler_count; i++) {
1490 const struct intel_pipeline_rmap_slot *slot =
1491 &rmap->slots[surface_count + i];
1492 const struct intel_sampler *sampler;
1493
Chia-I Wuf8385062015-01-04 16:27:24 +08001494 switch (slot->type) {
1495 case INTEL_PIPELINE_RMAP_SAMPLER:
1496 intel_desc_pool_read_sampler(cmd->dev->desc_pool,
1497 &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001498 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001499 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001500 sampler = NULL;
1501 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001502 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001503 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001504 sampler = NULL;
1505 break;
1506 }
1507
1508 if (sampler) {
1509 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1510
1511 sampler_dw[0] = sampler->cmd[0];
1512 sampler_dw[1] = sampler->cmd[1];
1513 sampler_dw[2] = border_offset;
1514 sampler_dw[3] = sampler->cmd[2];
1515 } else {
1516 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1517 sampler_dw[1] = 0;
1518 sampler_dw[2] = 0;
1519 sampler_dw[3] = 0;
1520 }
1521
1522 border_offset += border_stride * 4;
1523 border_dw += border_stride;
1524 sampler_dw += 4;
1525 }
1526
Chia-I Wu625105f2014-10-13 15:35:29 +08001527 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001528}
1529
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001530static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001531 const struct intel_pipeline_rmap *rmap,
1532 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001533{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001534 const uint32_t sba_offset =
1535 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001536 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001537 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001538
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001539 CMD_ASSERT(cmd, 6, 7.5);
1540
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001541 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001542 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001543 if (!surface_count)
1544 return 0;
1545
Chia-I Wu42a56202014-08-23 16:47:48 +08001546 assert(surface_count <= ARRAY_SIZE(binding_table));
1547
1548 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001549 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001550 struct intel_null_view null_view;
1551 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001552
Chia-I Wuf8385062015-01-04 16:27:24 +08001553 switch (slot->type) {
1554 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001555 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001556 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001557 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1558 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001559
Chia-I Wu787a05b2014-12-05 11:02:20 +08001560 if (view) {
1561 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1562 GEN6_ALIGNMENT_SURFACE_STATE,
1563 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001564
Chia-I Wu787a05b2014-12-05 11:02:20 +08001565 cmd_reserve_reloc(cmd, 1);
1566 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1567 view->cmd[1], INTEL_RELOC_WRITE);
1568 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001569 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001570 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001571 }
1572 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001573 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001574 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001575 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1576 const struct intel_mem *mem;
1577 bool read_only;
1578 const uint32_t *cmd_data;
1579 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001580
Chia-I Wuf8385062015-01-04 16:27:24 +08001581 assert(dyn_idx < 0 || dyn_idx <
1582 cmd->bind.dset.graphics->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001583
Chia-I Wuf8385062015-01-04 16:27:24 +08001584 intel_desc_pool_read_surface(cmd->dev->desc_pool,
1585 &slot->u.surface.offset, stage, &mem,
1586 &read_only, &cmd_data, &cmd_len);
1587 if (mem) {
1588 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1589 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1590 const uint32_t reloc_flags =
1591 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001592
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001593 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001594 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001595 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001596
1597 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001598 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1599 cmd_data[1] + dynamic_offset, reloc_flags);
1600 } else {
1601 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001602 }
1603 }
1604 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001605 case INTEL_PIPELINE_RMAP_UNUSED:
1606 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001607 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001608 default:
1609 assert(!"unexpected rmap type");
1610 need_null_view = true;
1611 break;
1612 }
1613
1614 if (need_null_view) {
1615 intel_null_view_init(&null_view, cmd->dev);
1616 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1617 GEN6_ALIGNMENT_SURFACE_STATE,
1618 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001619 }
1620
Chia-I Wuf98dd882015-02-10 04:17:47 +08001621 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001622 }
1623
Chia-I Wuf98dd882015-02-10 04:17:47 +08001624 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001625 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001626 surface_count, binding_table) - sba_offset;
1627
1628 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1629 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1630
1631 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001632}
1633
Chia-I Wu1d125092014-10-08 08:49:38 +08001634static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1635{
1636 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001637 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1638 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001639 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001640
1641 CMD_ASSERT(cmd, 6, 7.5);
1642
1643 if (!pipeline->vb_count)
1644 return;
1645
1646 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1647
1648 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1649 dw++;
1650 pos++;
1651
1652 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001653 assert(pipeline->vb[i].strideInBytes <= 2048);
1654
1655 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1656 pipeline->vb[i].strideInBytes;
1657
1658 if (cmd_gen(cmd) >= INTEL_GEN(7))
1659 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1660
1661 switch (pipeline->vb[i].stepRate) {
1662 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1663 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1664 dw[3] = 0;
1665 break;
1666 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1667 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1668 dw[3] = 1;
1669 break;
1670 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1671 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1672 dw[3] = 0;
1673 break;
1674 default:
1675 assert(!"unknown step rate");
1676 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1677 dw[3] = 0;
1678 break;
1679 }
1680
Chia-I Wu714df452015-01-01 07:55:04 +08001681 if (cmd->bind.vertex.buf[i]) {
1682 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001683 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001684
1685 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001686 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1687 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001688 } else {
1689 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1690 dw[1] = 0;
1691 dw[2] = 0;
1692 }
1693
1694 dw += 4;
1695 pos += 4;
1696 }
1697}
1698
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001699static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1700{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001701 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1702 const struct intel_pipeline_shader *vs = &pipeline->vs;
1703 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001704 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001705 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001706 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001707 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001708
1709 CMD_ASSERT(cmd, 6, 7.5);
1710
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001711 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001712 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1713 *
1714 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1715 * 128-bit vertex elements to be passed into the payload for each
1716 * vertex."
1717 *
1718 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1719 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001720 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001721 vue_read_len = (vs->in_count + 1) / 2;
1722 if (!vue_read_len)
1723 vue_read_len = 1;
1724
1725 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1726 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1727
1728 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1729 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1730 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001731
1732 dw5 = GEN6_VS_DW5_STATISTICS |
1733 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001734
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001735 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001736 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001737 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001738 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001739
Chia-I Wube0a3d92014-09-02 13:20:59 +08001740 if (pipeline->disable_vs_cache)
1741 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1742
Chia-I Wu784d3042014-12-19 14:30:04 +08001743 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001744 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001745 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001746 dw[2] = dw2;
1747 dw[3] = 0; /* scratch */
1748 dw[4] = dw4;
1749 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001750
1751 if (vs->per_thread_scratch_size)
1752 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001753}
1754
Chia-I Wu625105f2014-10-13 15:35:29 +08001755static void emit_shader_resources(struct intel_cmd *cmd)
1756{
1757 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001758 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001759
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001760 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001761 cmd->bind.pipeline.graphics->vs.rmap,
1762 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001763 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001764 cmd->bind.pipeline.graphics->tcs.rmap,
1765 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001766 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001767 cmd->bind.pipeline.graphics->tes.rmap,
1768 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001769 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001770 cmd->bind.pipeline.graphics->gs.rmap,
1771 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001772 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001773 cmd->bind.pipeline.graphics->fs.rmap,
1774 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001775
1776 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1777 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1778 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1779 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1780 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1781
1782 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1783 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001784 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1785 binding_tables[0]);
1786 gen7_3dstate_pointer(cmd,
1787 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1788 binding_tables[1]);
1789 gen7_3dstate_pointer(cmd,
1790 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1791 binding_tables[2]);
1792 gen7_3dstate_pointer(cmd,
1793 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1794 binding_tables[3]);
1795 gen7_3dstate_pointer(cmd,
1796 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1797 binding_tables[4]);
1798
1799 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001800 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1801 samplers[0]);
1802 gen7_3dstate_pointer(cmd,
1803 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1804 samplers[1]);
1805 gen7_3dstate_pointer(cmd,
1806 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1807 samplers[2]);
1808 gen7_3dstate_pointer(cmd,
1809 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1810 samplers[3]);
1811 gen7_3dstate_pointer(cmd,
1812 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1813 samplers[4]);
1814 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001815 assert(!binding_tables[1] && !binding_tables[2]);
1816 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1817 binding_tables[0], binding_tables[3], binding_tables[4]);
1818
Chia-I Wu625105f2014-10-13 15:35:29 +08001819 assert(!samplers[1] && !samplers[2]);
1820 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1821 samplers[0], samplers[3], samplers[4]);
1822 }
1823}
1824
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001825static void emit_rt(struct intel_cmd *cmd)
1826{
1827 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001828 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1829 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001830}
1831
1832static void emit_ds(struct intel_cmd *cmd)
1833{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001834 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001835
1836 if (!ds) {
1837 /* all zeros */
1838 static const struct intel_ds_view null_ds;
1839 ds = &null_ds;
1840 }
1841
1842 cmd_wa_gen6_pre_ds_flush(cmd);
1843 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1844 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1845 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1846
1847 if (cmd_gen(cmd) >= INTEL_GEN(7))
1848 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1849 else
1850 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1851}
1852
Chia-I Wua57761b2014-10-14 14:27:44 +08001853static uint32_t emit_shader(struct intel_cmd *cmd,
1854 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001855{
Chia-I Wua57761b2014-10-14 14:27:44 +08001856 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1857 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001858 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001859
Chia-I Wua57761b2014-10-14 14:27:44 +08001860 /* see if the shader is already in the cache */
1861 for (i = 0; i < cache->used; i++) {
1862 if (cache->entries[i].shader == (const void *) shader)
1863 return cache->entries[i].kernel_offset;
1864 }
1865
1866 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1867
1868 /* grow the cache if full */
1869 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001870 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001871 void *entries;
1872
1873 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1874 XGL_SYSTEM_ALLOC_INTERNAL);
1875 if (entries) {
1876 if (cache->entries) {
1877 memcpy(entries, cache->entries,
1878 sizeof(cache->entries[0]) * cache->used);
1879 icd_free(cache->entries);
1880 }
1881
1882 cache->entries = entries;
1883 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001884 }
1885 }
1886
Chia-I Wua57761b2014-10-14 14:27:44 +08001887 /* add the shader to the cache */
1888 if (cache->used < cache->count) {
1889 cache->entries[cache->used].shader = (const void *) shader;
1890 cache->entries[cache->used].kernel_offset = offset;
1891 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001892 }
1893
Chia-I Wua57761b2014-10-14 14:27:44 +08001894 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001895}
1896
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001897static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001898{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001899 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001900
Chia-I Wu8370b402014-08-29 12:28:37 +08001901 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1902 cmd_wa_gen6_pre_depth_stall_write(cmd);
1903 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1904 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1905 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1906 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001907
1908 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001909 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001910 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001911
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001912 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001913 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001914 }
1915 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001916 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917 }
1918 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001919 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1920 }
1921 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1922 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1923 }
1924 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1925 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001926 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001927
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001928 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1929 gen7_3DSTATE_GS(cmd);
1930 } else {
1931 gen6_3DSTATE_GS(cmd);
1932 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001933
Chia-I Wu8370b402014-08-29 12:28:37 +08001934 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1935 cmd_wa_gen7_post_command_cs_stall(cmd);
1936 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1937 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001938}
1939
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001940static void emit_bounded_states(struct intel_cmd *cmd)
1941{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001942
1943 emit_graphics_pipeline(cmd);
1944
1945 emit_rt(cmd);
1946 emit_ds(cmd);
1947
1948 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1949 gen7_cc_states(cmd);
1950 gen7_viewport_states(cmd);
1951
1952 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1953 &cmd->bind.pipeline.graphics->vs);
1954 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1955 &cmd->bind.pipeline.graphics->fs);
1956
1957 gen6_3DSTATE_CLIP(cmd);
1958 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001959 gen7_3DSTATE_WM(cmd);
1960 gen7_3DSTATE_PS(cmd);
1961 } else {
1962 gen6_cc_states(cmd);
1963 gen6_viewport_states(cmd);
1964
1965 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1966 &cmd->bind.pipeline.graphics->vs);
1967 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1968 &cmd->bind.pipeline.graphics->fs);
1969
1970 gen6_3DSTATE_CLIP(cmd);
1971 gen6_3DSTATE_SF(cmd);
1972 gen6_3DSTATE_WM(cmd);
1973 }
1974
1975 emit_shader_resources(cmd);
1976
1977 cmd_wa_gen6_pre_depth_stall_write(cmd);
1978 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1979
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001980 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1981 gen6_3DSTATE_VS(cmd);
1982}
1983
Tony Barbourfa6cac72015-01-16 14:27:35 -07001984static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1985 const struct intel_cmd_meta *meta)
1986{
1987 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1988 const uint8_t cmd_len = 3;
1989 uint32_t dw[3];
1990 uint32_t cmd_depth_stencil;
1991 uint32_t cmd_depth_test;
1992
1993 CMD_ASSERT(cmd, 6, 7.5);
1994
1995 cmd_depth_stencil = 0;
1996 cmd_depth_test = 0;
1997 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
1998 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
1999 GEN6_COMPAREFUNCTION_ALWAYS << 27;
2000 }
2001 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2002 cmd_depth_stencil = 1 << 31 |
2003 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2004 (GEN6_STENCILOP_KEEP) << 25 |
2005 (GEN6_STENCILOP_KEEP) << 22 |
2006 (GEN6_STENCILOP_REPLACE) << 19 |
2007 1 << 15 |
2008 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2009 (GEN6_STENCILOP_KEEP) << 9 |
2010 (GEN6_STENCILOP_KEEP) << 6 |
2011 (GEN6_STENCILOP_REPLACE) << 3;
2012 }
2013
2014 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
2015 dw[0] = cmd_depth_stencil | 1 << 18;
2016 dw[1] = (0xff) << 24 | (0xff) << 16;
2017 dw[2] = cmd_depth_test;
2018
2019 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2020 cmd_align, cmd_len, dw);
2021}
2022
Chia-I Wu6032b892014-10-17 14:47:18 +08002023static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2024{
2025 const struct intel_cmd_meta *meta = cmd->bind.meta;
2026 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2027
2028 CMD_ASSERT(cmd, 6, 7.5);
2029
2030 blend_offset = 0;
2031 ds_offset = 0;
2032 cc_offset = 0;
2033 cc_vp_offset = 0;
2034
Chia-I Wu29e6f502014-11-24 14:27:29 +08002035 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002036 /* BLEND_STATE */
2037 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002038 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002039 dw[0] = 0;
2040 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2041 }
2042
Chia-I Wu29e6f502014-11-24 14:27:29 +08002043 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002044 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002045 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002046 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2047 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002048
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002050 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002051
Chia-I Wu29e6f502014-11-24 14:27:29 +08002052 /* COLOR_CALC_STATE */
2053 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002054 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002055
Chia-I Wu29e6f502014-11-24 14:27:29 +08002056 /* CC_VIEWPORT */
2057 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002058 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002059 dw[0] = u_fui(0.0f);
2060 dw[1] = u_fui(1.0f);
2061 } else {
2062 /* DEPTH_STENCIL_STATE */
2063 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002064 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002065 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2066 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2067 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002068 }
2069
2070 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2071 gen7_3dstate_pointer(cmd,
2072 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2073 blend_offset);
2074 gen7_3dstate_pointer(cmd,
2075 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2076 ds_offset);
2077 gen7_3dstate_pointer(cmd,
2078 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2079
2080 gen7_3dstate_pointer(cmd,
2081 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2082 cc_vp_offset);
2083 } else {
2084 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002085 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002086
2087 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2088 cmd_batch_pointer(cmd, 4, &dw);
2089 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2090 GEN6_PTR_VP_DW0_CC_CHANGED;
2091 dw[1] = 0;
2092 dw[2] = 0;
2093 dw[3] = cc_vp_offset;
2094 }
2095}
2096
2097static void gen6_meta_surface_states(struct intel_cmd *cmd)
2098{
2099 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002100 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002101 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002102 const uint32_t sba_offset =
2103 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002104
2105 CMD_ASSERT(cmd, 6, 7.5);
2106
Chia-I Wu29e6f502014-11-24 14:27:29 +08002107 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2108 return;
2109
Chia-I Wu005c47c2014-10-22 13:49:13 +08002110 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002111 if (meta->src.valid) {
2112 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002113 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002114 meta->src.surface_len, meta->src.surface);
2115
2116 cmd_reserve_reloc(cmd, 1);
2117 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2118 cmd_surface_reloc_writer(cmd, offset, 1,
2119 meta->src.reloc_target, meta->src.reloc_offset);
2120 } else {
2121 cmd_surface_reloc(cmd, offset, 1,
2122 (struct intel_bo *) meta->src.reloc_target,
2123 meta->src.reloc_offset, meta->src.reloc_flags);
2124 }
2125
Mike Stroyan9bfad482015-02-10 15:09:23 -07002126 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002127 }
2128 if (meta->dst.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 Wu005c47c2014-10-22 13:49:13 +08002131 meta->dst.surface_len, meta->dst.surface);
2132
2133 cmd_reserve_reloc(cmd, 1);
2134 cmd_surface_reloc(cmd, offset, 1,
2135 (struct intel_bo *) meta->dst.reloc_target,
2136 meta->dst.reloc_offset, meta->dst.reloc_flags);
2137
Mike Stroyan9bfad482015-02-10 15:09:23 -07002138 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002139 }
2140
2141 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002142 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002143 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002144 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002145
2146 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002147 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2148 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2149 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002150 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002151 } else {
2152 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002153 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002154 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002155 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002156 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002157 }
2158}
2159
2160static void gen6_meta_urb(struct intel_cmd *cmd)
2161{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002162 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002163 uint32_t *dw;
2164
2165 CMD_ASSERT(cmd, 6, 6);
2166
2167 /* 3DSTATE_URB */
2168 cmd_batch_pointer(cmd, 3, &dw);
2169 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002170 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002171 dw[2] = 0;
2172}
2173
2174static void gen7_meta_urb(struct intel_cmd *cmd)
2175{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002176 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002177 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002178 uint32_t *dw;
2179
2180 CMD_ASSERT(cmd, 7, 7.5);
2181
2182 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2183 cmd_batch_pointer(cmd, 10, &dw);
2184
2185 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002186 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002187 dw += 2;
2188
2189 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2190 dw[1] = 0;
2191 dw += 2;
2192
2193 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2194 dw[1] = 0;
2195 dw += 2;
2196
2197 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2198 dw[1] = 0;
2199 dw += 2;
2200
2201 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002202 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002203
2204 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2205
Chia-I Wu24aa1022014-11-25 11:53:19 +08002206 switch (cmd_gen(cmd)) {
2207 case INTEL_GEN(7.5):
2208 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2209 break;
2210 case INTEL_GEN(7):
2211 default:
2212 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2213 break;
2214 }
2215
Chia-I Wu6032b892014-10-17 14:47:18 +08002216 /* 3DSTATE_URB_x */
2217 cmd_batch_pointer(cmd, 8, &dw);
2218
2219 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2220 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002221 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002222 dw += 2;
2223
2224 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2225 dw[1] = 0;
2226 dw += 2;
2227
2228 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2229 dw[1] = 0;
2230 dw += 2;
2231
2232 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2233 dw[1] = 0;
2234 dw += 2;
2235}
2236
2237static void gen6_meta_vf(struct intel_cmd *cmd)
2238{
2239 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002240 uint32_t vb_start, vb_end, vb_stride;
2241 int ve_format, ve_z_source;
2242 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002243 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002244
2245 CMD_ASSERT(cmd, 6, 7.5);
2246
Chia-I Wu29e6f502014-11-24 14:27:29 +08002247 switch (meta->mode) {
2248 case INTEL_CMD_META_VS_POINTS:
2249 cmd_batch_pointer(cmd, 3, &dw);
2250 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2251 dw[1] = GEN6_VE_STATE_DW0_VALID;
2252 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2253 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2254 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2255 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2256 return;
2257 break;
2258 case INTEL_CMD_META_FS_RECT:
2259 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002260 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002261
Chia-I Wu29e6f502014-11-24 14:27:29 +08002262 vertices[0][0] = meta->dst.x + meta->width;
2263 vertices[0][1] = meta->dst.y + meta->height;
2264 vertices[1][0] = meta->dst.x;
2265 vertices[1][1] = meta->dst.y + meta->height;
2266 vertices[2][0] = meta->dst.x;
2267 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002268
Chia-I Wu29e6f502014-11-24 14:27:29 +08002269 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2270 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002271
Chia-I Wu29e6f502014-11-24 14:27:29 +08002272 vb_end = vb_start + sizeof(vertices) - 1;
2273 vb_stride = sizeof(vertices[0]);
2274 ve_z_source = GEN6_VFCOMP_STORE_0;
2275 ve_format = GEN6_FORMAT_R32G32_USCALED;
2276 }
2277 break;
2278 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2279 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002280 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002281
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002282 vertices[0][0] = (float) (meta->dst.x + meta->width);
2283 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002285 vertices[1][0] = (float) meta->dst.x;
2286 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002287 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002288 vertices[2][0] = (float) meta->dst.x;
2289 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002291
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2293 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002294
Chia-I Wu29e6f502014-11-24 14:27:29 +08002295 vb_end = vb_start + sizeof(vertices) - 1;
2296 vb_stride = sizeof(vertices[0]);
2297 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2298 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2299 }
2300 break;
2301 default:
2302 assert(!"unknown meta mode");
2303 return;
2304 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002306
2307 /* 3DSTATE_VERTEX_BUFFERS */
2308 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002309
Chia-I Wu6032b892014-10-17 14:47:18 +08002310 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002311 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002312 if (cmd_gen(cmd) >= INTEL_GEN(7))
2313 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2314
2315 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002316 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2317 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002318
2319 dw[4] = 0;
2320
2321 /* 3DSTATE_VERTEX_ELEMENTS */
2322 cmd_batch_pointer(cmd, 5, &dw);
2323 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002324 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002325 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2326 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2327 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2328 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2329 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002330 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002331 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2332 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002334 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2335}
2336
Chia-I Wu29e6f502014-11-24 14:27:29 +08002337static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002338{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002339 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002340 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002341 uint32_t consts[8];
2342 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002343
2344 CMD_ASSERT(cmd, 6, 7.5);
2345
2346 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002347 case INTEL_DEV_META_VS_FILL_MEM:
2348 consts[0] = meta->dst.x;
2349 consts[1] = meta->clear_val[0];
2350 const_count = 2;
2351 break;
2352 case INTEL_DEV_META_VS_COPY_MEM:
2353 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2354 consts[0] = meta->dst.x;
2355 consts[1] = meta->src.x;
2356 const_count = 2;
2357 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002358 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2359 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2360 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2361 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2362 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2363 consts[0] = meta->src.x;
2364 consts[1] = meta->src.y;
2365 consts[2] = meta->width;
2366 consts[3] = meta->dst.x;
2367 const_count = 4;
2368 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002369 default:
2370 assert(!"unknown meta shader id");
2371 const_count = 0;
2372 break;
2373 }
2374
2375 /* this can be skipped but it makes state dumping prettier */
2376 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2377
2378 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2379}
2380
2381static void gen6_meta_vs(struct intel_cmd *cmd)
2382{
2383 const struct intel_cmd_meta *meta = cmd->bind.meta;
2384 const struct intel_pipeline_shader *sh =
2385 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2386 uint32_t offset, *dw;
2387
2388 CMD_ASSERT(cmd, 6, 7.5);
2389
2390 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002391 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002392
2393 /* 3DSTATE_CONSTANT_VS */
2394 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2395 cmd_batch_pointer(cmd, cmd_len, &dw);
2396 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2397 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2398
2399 /* 3DSTATE_VS */
2400 cmd_batch_pointer(cmd, 6, &dw);
2401 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2402 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2403
2404 return;
2405 }
2406
2407 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2408
2409 /* 3DSTATE_CONSTANT_VS */
2410 offset = gen6_meta_vs_constants(cmd);
2411 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2412 cmd_batch_pointer(cmd, 7, &dw);
2413 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2414 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2415 dw[2] = 0;
2416 dw[3] = offset;
2417 dw[4] = 0;
2418 dw[5] = 0;
2419 dw[6] = 0;
2420 } else {
2421 cmd_batch_pointer(cmd, 5, &dw);
2422 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2423 GEN6_PCB_ANY_DW0_PCB0_VALID;
2424 dw[1] = offset;
2425 dw[2] = 0;
2426 dw[3] = 0;
2427 dw[4] = 0;
2428 }
2429
2430 /* 3DSTATE_VS */
2431 offset = emit_shader(cmd, sh);
2432 cmd_batch_pointer(cmd, 6, &dw);
2433 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2434 dw[1] = offset;
2435 dw[2] = GEN6_THREADDISP_SPF |
2436 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2437 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002438 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002439 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2440 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2441
2442 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2443 GEN6_VS_DW5_VS_ENABLE;
2444 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002445 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002446 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002447 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002448
2449 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002450}
2451
2452static void gen6_meta_disabled(struct intel_cmd *cmd)
2453{
Chia-I Wu6032b892014-10-17 14:47:18 +08002454 uint32_t *dw;
2455
2456 CMD_ASSERT(cmd, 6, 6);
2457
Chia-I Wu6032b892014-10-17 14:47:18 +08002458 /* 3DSTATE_CONSTANT_GS */
2459 cmd_batch_pointer(cmd, 5, &dw);
2460 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2461 dw[1] = 0;
2462 dw[2] = 0;
2463 dw[3] = 0;
2464 dw[4] = 0;
2465
2466 /* 3DSTATE_GS */
2467 cmd_batch_pointer(cmd, 7, &dw);
2468 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2469 dw[1] = 0;
2470 dw[2] = 0;
2471 dw[3] = 0;
2472 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2473 dw[5] = GEN6_GS_DW5_STATISTICS;
2474 dw[6] = 0;
2475
Chia-I Wu6032b892014-10-17 14:47:18 +08002476 /* 3DSTATE_SF */
2477 cmd_batch_pointer(cmd, 20, &dw);
2478 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2479 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2480 memset(&dw[2], 0, 18 * sizeof(*dw));
2481}
2482
2483static void gen7_meta_disabled(struct intel_cmd *cmd)
2484{
2485 uint32_t *dw;
2486
2487 CMD_ASSERT(cmd, 7, 7.5);
2488
Chia-I Wu6032b892014-10-17 14:47:18 +08002489 /* 3DSTATE_CONSTANT_HS */
2490 cmd_batch_pointer(cmd, 7, &dw);
2491 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2492 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2493
2494 /* 3DSTATE_HS */
2495 cmd_batch_pointer(cmd, 7, &dw);
2496 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2497 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2498
2499 /* 3DSTATE_TE */
2500 cmd_batch_pointer(cmd, 4, &dw);
2501 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2502 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2503
2504 /* 3DSTATE_CONSTANT_DS */
2505 cmd_batch_pointer(cmd, 7, &dw);
2506 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2507 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2508
2509 /* 3DSTATE_DS */
2510 cmd_batch_pointer(cmd, 6, &dw);
2511 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2512 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2513
2514 /* 3DSTATE_CONSTANT_GS */
2515 cmd_batch_pointer(cmd, 7, &dw);
2516 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2517 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2518
2519 /* 3DSTATE_GS */
2520 cmd_batch_pointer(cmd, 7, &dw);
2521 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2522 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2523
2524 /* 3DSTATE_STREAMOUT */
2525 cmd_batch_pointer(cmd, 3, &dw);
2526 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2527 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2528
Chia-I Wu6032b892014-10-17 14:47:18 +08002529 /* 3DSTATE_SF */
2530 cmd_batch_pointer(cmd, 7, &dw);
2531 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2532 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2533
2534 /* 3DSTATE_SBE */
2535 cmd_batch_pointer(cmd, 14, &dw);
2536 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2537 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2538 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002539}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002540
Chia-I Wu29e6f502014-11-24 14:27:29 +08002541static void gen6_meta_clip(struct intel_cmd *cmd)
2542{
2543 const struct intel_cmd_meta *meta = cmd->bind.meta;
2544 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002545
Chia-I Wu29e6f502014-11-24 14:27:29 +08002546 /* 3DSTATE_CLIP */
2547 cmd_batch_pointer(cmd, 4, &dw);
2548 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2549 dw[1] = 0;
2550 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2551 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2552 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2553 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002554 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002555 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002556 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002557}
2558
2559static void gen6_meta_wm(struct intel_cmd *cmd)
2560{
2561 const struct intel_cmd_meta *meta = cmd->bind.meta;
2562 uint32_t *dw;
2563
2564 CMD_ASSERT(cmd, 6, 7.5);
2565
2566 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2567
2568 /* 3DSTATE_MULTISAMPLE */
2569 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2570 cmd_batch_pointer(cmd, 4, &dw);
2571 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2572 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2573 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2574 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2575 dw[2] = 0;
2576 dw[3] = 0;
2577 } else {
2578 cmd_batch_pointer(cmd, 3, &dw);
2579 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2580 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2581 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2582 dw[2] = 0;
2583 }
2584
2585 /* 3DSTATE_SAMPLE_MASK */
2586 cmd_batch_pointer(cmd, 2, &dw);
2587 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2588 dw[1] = (1 << meta->samples) - 1;
2589
2590 /* 3DSTATE_DRAWING_RECTANGLE */
2591 cmd_batch_pointer(cmd, 4, &dw);
2592 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2593 dw[1] = meta->dst.y << 16 | meta->dst.x;
2594 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2595 (meta->dst.x + meta->width - 1);
2596 dw[3] = 0;
2597}
2598
2599static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2600{
2601 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002602 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002603 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002604 uint32_t consts[8];
2605 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002606
2607 CMD_ASSERT(cmd, 6, 7.5);
2608
2609 /* underflow is fine here */
2610 offset_x = meta->src.x - meta->dst.x;
2611 offset_y = meta->src.y - meta->dst.y;
2612
2613 switch (meta->shader_id) {
2614 case INTEL_DEV_META_FS_COPY_MEM:
2615 case INTEL_DEV_META_FS_COPY_1D:
2616 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2617 case INTEL_DEV_META_FS_COPY_2D:
2618 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2619 case INTEL_DEV_META_FS_COPY_2D_MS:
2620 consts[0] = offset_x;
2621 consts[1] = offset_y;
2622 consts[2] = meta->src.layer;
2623 consts[3] = meta->src.lod;
2624 const_count = 4;
2625 break;
2626 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2627 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2628 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2629 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2630 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2631 consts[0] = offset_x;
2632 consts[1] = offset_y;
2633 consts[2] = meta->src.layer;
2634 consts[3] = meta->src.lod;
2635 consts[4] = meta->src.x;
2636 consts[5] = meta->width;
2637 const_count = 6;
2638 break;
2639 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2640 consts[0] = offset_x;
2641 consts[1] = offset_y;
2642 consts[2] = meta->width;
2643 const_count = 3;
2644 break;
2645 case INTEL_DEV_META_FS_CLEAR_COLOR:
2646 consts[0] = meta->clear_val[0];
2647 consts[1] = meta->clear_val[1];
2648 consts[2] = meta->clear_val[2];
2649 consts[3] = meta->clear_val[3];
2650 const_count = 4;
2651 break;
2652 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2653 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002654 consts[1] = meta->clear_val[1];
2655 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002656 break;
2657 case INTEL_DEV_META_FS_RESOLVE_2X:
2658 case INTEL_DEV_META_FS_RESOLVE_4X:
2659 case INTEL_DEV_META_FS_RESOLVE_8X:
2660 case INTEL_DEV_META_FS_RESOLVE_16X:
2661 consts[0] = offset_x;
2662 consts[1] = offset_y;
2663 const_count = 2;
2664 break;
2665 default:
2666 assert(!"unknown meta shader id");
2667 const_count = 0;
2668 break;
2669 }
2670
2671 /* this can be skipped but it makes state dumping prettier */
2672 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2673
2674 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2675}
2676
2677static void gen6_meta_ps(struct intel_cmd *cmd)
2678{
2679 const struct intel_cmd_meta *meta = cmd->bind.meta;
2680 const struct intel_pipeline_shader *sh =
2681 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2682 uint32_t offset, *dw;
2683
2684 CMD_ASSERT(cmd, 6, 6);
2685
Chia-I Wu29e6f502014-11-24 14:27:29 +08002686 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2687 /* 3DSTATE_CONSTANT_PS */
2688 cmd_batch_pointer(cmd, 5, &dw);
2689 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2690 dw[1] = 0;
2691 dw[2] = 0;
2692 dw[3] = 0;
2693 dw[4] = 0;
2694
2695 /* 3DSTATE_WM */
2696 cmd_batch_pointer(cmd, 9, &dw);
2697 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2698 dw[1] = 0;
2699 dw[2] = 0;
2700 dw[3] = 0;
2701 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002702 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002703 dw[6] = 0;
2704 dw[7] = 0;
2705 dw[8] = 0;
2706
Chia-I Wu3adf7212014-10-24 15:34:07 +08002707 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002708 }
2709
Chia-I Wu3adf7212014-10-24 15:34:07 +08002710 /* a normal color write */
2711 assert(meta->dst.valid && !sh->uses);
2712
Chia-I Wu6032b892014-10-17 14:47:18 +08002713 /* 3DSTATE_CONSTANT_PS */
2714 offset = gen6_meta_ps_constants(cmd);
2715 cmd_batch_pointer(cmd, 5, &dw);
2716 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2717 GEN6_PCB_ANY_DW0_PCB0_VALID;
2718 dw[1] = offset;
2719 dw[2] = 0;
2720 dw[3] = 0;
2721 dw[4] = 0;
2722
2723 /* 3DSTATE_WM */
2724 offset = emit_shader(cmd, sh);
2725 cmd_batch_pointer(cmd, 9, &dw);
2726 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2727 dw[1] = offset;
2728 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2729 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002730 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002731 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002732 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002733 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002734 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2735
Chia-I Wu6032b892014-10-17 14:47:18 +08002736 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2737 GEN6_WM_DW6_POSOFFSET_NONE |
2738 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2739 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2740 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2741 if (meta->samples > 1) {
2742 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2743 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2744 } else {
2745 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2746 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2747 }
2748 dw[7] = 0;
2749 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002750
2751 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002752}
2753
2754static void gen7_meta_ps(struct intel_cmd *cmd)
2755{
2756 const struct intel_cmd_meta *meta = cmd->bind.meta;
2757 const struct intel_pipeline_shader *sh =
2758 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2759 uint32_t offset, *dw;
2760
2761 CMD_ASSERT(cmd, 7, 7.5);
2762
Chia-I Wu29e6f502014-11-24 14:27:29 +08002763 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2764 /* 3DSTATE_WM */
2765 cmd_batch_pointer(cmd, 3, &dw);
2766 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2767 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2768
2769 /* 3DSTATE_CONSTANT_GS */
2770 cmd_batch_pointer(cmd, 7, &dw);
2771 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2772 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2773
2774 /* 3DSTATE_PS */
2775 cmd_batch_pointer(cmd, 8, &dw);
2776 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2777 dw[1] = 0;
2778 dw[2] = 0;
2779 dw[3] = 0;
2780 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002781 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002782 dw[5] = 0;
2783 dw[6] = 0;
2784 dw[7] = 0;
2785
Chia-I Wu3adf7212014-10-24 15:34:07 +08002786 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002787 }
2788
Chia-I Wu3adf7212014-10-24 15:34:07 +08002789 /* a normal color write */
2790 assert(meta->dst.valid && !sh->uses);
2791
Chia-I Wu6032b892014-10-17 14:47:18 +08002792 /* 3DSTATE_WM */
2793 cmd_batch_pointer(cmd, 3, &dw);
2794 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2795 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2796 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2797 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2798 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2799 dw[2] = 0;
2800
2801 /* 3DSTATE_CONSTANT_PS */
2802 offset = gen6_meta_ps_constants(cmd);
2803 cmd_batch_pointer(cmd, 7, &dw);
2804 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2805 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2806 dw[2] = 0;
2807 dw[3] = offset;
2808 dw[4] = 0;
2809 dw[5] = 0;
2810 dw[6] = 0;
2811
2812 /* 3DSTATE_PS */
2813 offset = emit_shader(cmd, sh);
2814 cmd_batch_pointer(cmd, 8, &dw);
2815 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2816 dw[1] = offset;
2817 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2818 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002819 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002820
2821 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2822 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002823 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2824
2825 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002826 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002827 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002828 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002829 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002830 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002831
2832 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2833 dw[6] = 0;
2834 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002835
2836 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002837}
2838
2839static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2840{
2841 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002842 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002843
2844 CMD_ASSERT(cmd, 6, 7.5);
2845
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002846 if (!ds) {
2847 /* all zeros */
2848 static const struct intel_ds_view null_ds;
2849 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002850 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002851
2852 cmd_wa_gen6_pre_ds_flush(cmd);
2853 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2854 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2855 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2856
2857 if (cmd_gen(cmd) >= INTEL_GEN(7))
2858 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2859 else
2860 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002861}
2862
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002863static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2864 const struct intel_pipeline *pipeline)
2865{
2866 cmd->bind.pipeline.graphics = pipeline;
2867}
2868
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002869static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2870 const struct intel_pipeline *pipeline)
2871{
2872 cmd->bind.pipeline.compute = pipeline;
2873}
2874
2875static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2876 const struct intel_pipeline_delta *delta)
2877{
2878 cmd->bind.pipeline.graphics_delta = delta;
2879}
2880
2881static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2882 const struct intel_pipeline_delta *delta)
2883{
2884 cmd->bind.pipeline.compute_delta = delta;
2885}
2886
2887static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002888 const struct intel_desc_set *dset,
2889 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002890{
Chia-I Wuf8385062015-01-04 16:27:24 +08002891 const uint32_t size = sizeof(*dynamic_offsets) *
2892 dset->layout->dynamic_desc_count;
2893
2894 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2895 if (cmd->bind.dset.graphics_dynamic_offsets)
2896 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2897
2898 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2899 4, XGL_SYSTEM_ALLOC_INTERNAL);
2900 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2901 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2902 return;
2903 }
2904
2905 cmd->bind.dset.graphics_dynamic_offset_size = size;
2906 }
2907
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002908 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002909 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002910}
2911
2912static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002913 const struct intel_desc_set *dset,
2914 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002915{
Chia-I Wuf8385062015-01-04 16:27:24 +08002916 const uint32_t size = sizeof(*dynamic_offsets) *
2917 dset->layout->dynamic_desc_count;
2918
2919 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2920 if (cmd->bind.dset.compute_dynamic_offsets)
2921 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2922
2923 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2924 4, XGL_SYSTEM_ALLOC_INTERNAL);
2925 if (!cmd->bind.dset.compute_dynamic_offsets) {
2926 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2927 return;
2928 }
2929
2930 cmd->bind.dset.compute_dynamic_offset_size = size;
2931 }
2932
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002933 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002934 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002935}
2936
Chia-I Wu3b04af52014-11-08 10:48:20 +08002937static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002938 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002939 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002940{
Chia-I Wu714df452015-01-01 07:55:04 +08002941 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002942 cmd->result = XGL_ERROR_UNKNOWN;
2943 return;
2944 }
2945
Chia-I Wu714df452015-01-01 07:55:04 +08002946 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002947 cmd->bind.vertex.offset[binding] = offset;
2948}
2949
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002950static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002951 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002952 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2953{
Chia-I Wu714df452015-01-01 07:55:04 +08002954 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002955 cmd->bind.index.offset = offset;
2956 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957}
2958
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002959static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002960 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002961{
2962 cmd->bind.state.viewport = state;
2963}
2964
2965static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002966 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002967{
2968 cmd->bind.state.raster = state;
2969}
2970
2971static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002972 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973{
2974 cmd->bind.state.ds = state;
2975}
2976
2977static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002978 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002979{
2980 cmd->bind.state.blend = state;
2981}
2982
Chia-I Wuf98dd882015-02-10 04:17:47 +08002983static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
2984{
2985 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
2986 struct intel_pipeline_rmap *rmaps[5] = {
2987 pipeline->vs.rmap,
2988 pipeline->tcs.rmap,
2989 pipeline->tes.rmap,
2990 pipeline->gs.rmap,
2991 pipeline->fs.rmap,
2992 };
2993 uint32_t max_write;
2994 int i;
2995
2996 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
2997 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
2998 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
2999
3000 /* pad first */
3001 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3002
3003 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3004 const struct intel_pipeline_rmap *rmap = rmaps[i];
3005 const uint32_t surface_count = (rmap) ?
3006 rmap->rt_count + rmap->texture_resource_count +
3007 rmap->resource_count + rmap->uav_count : 0;
3008
3009 if (surface_count) {
3010 /* SURFACE_STATEs */
3011 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3012
3013 /* BINDING_TABLE_STATE */
3014 max_write += u_align(sizeof(uint32_t) * surface_count,
3015 GEN6_ALIGNMENT_SURFACE_STATE);
3016 }
3017 }
3018
3019 return max_write;
3020}
3021
3022static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3023{
3024 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3025 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3026 uint32_t max_surface_write;
3027
3028 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3029 if (cmd->bind.meta)
3030 max_surface_write = 64 * sizeof(uint32_t);
3031 else
3032 max_surface_write = cmd_get_max_surface_write(cmd);
3033
3034 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3035 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3036 /* SBA expects page-aligned addresses */
3037 writer->sba_offset = writer->used & ~0xfff;
3038
3039 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3040
3041 cmd_batch_state_base_address(cmd);
3042 }
3043}
3044
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003045static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003046 uint32_t vertex_start,
3047 uint32_t vertex_count,
3048 uint32_t instance_start,
3049 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003050 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003051 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003052{
3053 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wuf98dd882015-02-10 04:17:47 +08003054 const uint32_t surface_writer_used =
3055 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3056
3057 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003058
3059 emit_bounded_states(cmd);
3060
Chia-I Wuf98dd882015-02-10 04:17:47 +08003061 /* sanity check on cmd_get_max_surface_write() */
3062 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3063 surface_writer_used <= cmd_get_max_surface_write(cmd));
3064
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003065 if (indexed) {
3066 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
3067 cmd->result = XGL_ERROR_UNKNOWN;
3068
3069 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3070 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3071 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003072 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003073 cmd->bind.index.offset, cmd->bind.index.type,
3074 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003075 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003076 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003077 cmd->bind.index.offset, cmd->bind.index.type,
3078 p->primitive_restart);
3079 }
3080 } else {
3081 assert(!vertex_base);
3082 }
3083
3084 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3085 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3086 vertex_start, instance_count, instance_start, vertex_base);
3087 } else {
3088 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3089 vertex_start, instance_count, instance_start, vertex_base);
3090 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003091
Chia-I Wu707a29e2014-08-27 12:51:47 +08003092 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003093 /* need to re-emit all workarounds */
3094 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003095
3096 if (intel_debug & INTEL_DEBUG_NOCACHE)
3097 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003098}
3099
Chia-I Wuc14d1562014-10-17 09:49:22 +08003100void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3101{
Chia-I Wu6032b892014-10-17 14:47:18 +08003102 cmd->bind.meta = meta;
3103
Chia-I Wuf98dd882015-02-10 04:17:47 +08003104 cmd_adjust_state_base_address(cmd);
3105
Chia-I Wu6032b892014-10-17 14:47:18 +08003106 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003107 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003108
3109 gen6_meta_dynamic_states(cmd);
3110 gen6_meta_surface_states(cmd);
3111
3112 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3113 gen7_meta_urb(cmd);
3114 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003115 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003116 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003117 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003118 gen6_meta_wm(cmd);
3119 gen7_meta_ps(cmd);
3120 gen6_meta_depth_buffer(cmd);
3121
3122 cmd_wa_gen7_post_command_cs_stall(cmd);
3123 cmd_wa_gen7_post_command_depth_stall(cmd);
3124
Chia-I Wu29e6f502014-11-24 14:27:29 +08003125 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3126 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003127 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003128 } else {
3129 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3130 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003131 } else {
3132 gen6_meta_urb(cmd);
3133 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003134 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003135 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003136 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003137 gen6_meta_wm(cmd);
3138 gen6_meta_ps(cmd);
3139 gen6_meta_depth_buffer(cmd);
3140
Chia-I Wu29e6f502014-11-24 14:27:29 +08003141 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3142 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003143 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003144 } else {
3145 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3146 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003147 }
3148
3149 cmd->bind.draw_count++;
3150 /* need to re-emit all workarounds */
3151 cmd->bind.wa_flags = 0;
3152
3153 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003154
3155 if (intel_debug & INTEL_DEBUG_NOCACHE)
3156 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003157}
3158
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003159ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003160 XGL_CMD_BUFFER cmdBuffer,
3161 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3162 XGL_PIPELINE pipeline)
3163{
3164 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3165
3166 switch (pipelineBindPoint) {
3167 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003168 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003169 break;
3170 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003171 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003172 break;
3173 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003174 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003175 break;
3176 }
3177}
3178
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003179ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003180 XGL_CMD_BUFFER cmdBuffer,
3181 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3182 XGL_PIPELINE_DELTA delta)
3183{
3184 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3185
3186 switch (pipelineBindPoint) {
3187 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003188 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003189 break;
3190 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003191 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003192 break;
3193 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003194 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003195 break;
3196 }
3197}
3198
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003199ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003200 XGL_CMD_BUFFER cmdBuffer,
3201 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003202 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003203{
3204 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3205
3206 switch (stateBindPoint) {
3207 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003208 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003209 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003210 break;
3211 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003212 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003213 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003214 break;
3215 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003216 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003217 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003218 break;
3219 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003220 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003221 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003222 break;
3223 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003224 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003225 break;
3226 }
3227}
3228
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003229ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003230 XGL_CMD_BUFFER cmdBuffer,
3231 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003232 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003233 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003234{
3235 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003236 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003237
3238 switch (pipelineBindPoint) {
3239 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003240 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003241 break;
3242 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003243 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003244 break;
3245 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003246 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003247 break;
3248 }
3249}
3250
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003251ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003252 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003253 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003254 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003255 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003256{
3257 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003258 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003259
Chia-I Wu714df452015-01-01 07:55:04 +08003260 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003261}
3262
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003263ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003264 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003265 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003266 XGL_GPU_SIZE offset,
3267 XGL_INDEX_TYPE indexType)
3268{
3269 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003270 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003271
Chia-I Wu714df452015-01-01 07:55:04 +08003272 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003273}
3274
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003275ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003276 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003277 uint32_t firstVertex,
3278 uint32_t vertexCount,
3279 uint32_t firstInstance,
3280 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003281{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003282 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003283
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003284 cmd_draw(cmd, firstVertex, vertexCount,
3285 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003286}
3287
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003288ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003289 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003290 uint32_t firstIndex,
3291 uint32_t indexCount,
3292 int32_t vertexOffset,
3293 uint32_t firstInstance,
3294 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003295{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003296 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003297
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003298 cmd_draw(cmd, firstIndex, indexCount,
3299 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003300}
3301
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003302ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003303 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003304 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003305 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003306 uint32_t count,
3307 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003308{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003309 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3310
3311 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003312}
3313
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003314ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003315 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003316 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003317 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003318 uint32_t count,
3319 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003320{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003321 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3322
3323 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003324}
3325
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003326ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003327 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003328 uint32_t x,
3329 uint32_t y,
3330 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003331{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003332 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3333
3334 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003335}
3336
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003337ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003338 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003339 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003340 XGL_GPU_SIZE offset)
3341{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003342 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3343
3344 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003345}