blob: 7d90307866b916176c66b7b6fc637b08d02e866f [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:
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700273 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -0700279 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280 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
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700413 /* Scissor is always enabled */
414 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
415
Tony Barbourfa6cac72015-01-16 14:27:35 -0700416 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800417 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
419 } else {
420 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
421 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
422 }
423
Chia-I Wu8016a172014-08-29 18:31:32 +0800424 /* 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 */
Chia-I Wu4f7730d2015-02-18 15:21:38 -0700522 if (cmd->bind.render_pass->fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600523 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
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700588 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800589 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
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700692 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800693 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;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700760 if (view->has_stencil) {
761 dw[1] = view->cmd[6];
762
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);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700766 } else {
767 dw[1] = 0;
768 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600769 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800770}
771
772static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
773 const struct intel_ds_view *view)
774{
775 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800776 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600777 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800778
779 CMD_ASSERT(cmd, 6, 7.5);
780
781 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800782 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
783 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800784 dw0 |= (cmd_len - 2);
785
Chia-I Wu72292b72014-09-09 10:48:33 +0800786 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
787 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800788
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700789 if (view->has_hiz) {
790 dw[1] = view->cmd[8];
791
Chia-I Wu72292b72014-09-09 10:48:33 +0800792 cmd_reserve_reloc(cmd, 1);
793 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
794 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700795 } else {
796 dw[1] = 0;
797 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600798 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800799}
800
Chia-I Wuf8231032014-08-25 10:44:45 +0800801static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
802 uint32_t clear_val)
803{
804 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800805 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800806 GEN6_CLEAR_PARAMS_DW0_VALID |
807 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800808 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800809
810 CMD_ASSERT(cmd, 6, 6);
811
Chia-I Wu72292b72014-09-09 10:48:33 +0800812 cmd_batch_pointer(cmd, cmd_len, &dw);
813 dw[0] = dw0;
814 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800815}
816
817static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
818 uint32_t clear_val)
819{
820 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800821 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800822 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800823 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800824
825 CMD_ASSERT(cmd, 7, 7.5);
826
Chia-I Wu72292b72014-09-09 10:48:33 +0800827 cmd_batch_pointer(cmd, cmd_len, &dw);
828 dw[0] = dw0;
829 dw[1] = clear_val;
830 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800831}
832
Chia-I Wu302742d2014-08-22 10:28:29 +0800833static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800834 uint32_t blend_offset,
835 uint32_t ds_offset,
836 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800837{
838 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800839 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800840
841 CMD_ASSERT(cmd, 6, 6);
842
Chia-I Wu426072d2014-08-26 14:31:55 +0800843 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800844 (cmd_len - 2);
845
Chia-I Wu72292b72014-09-09 10:48:33 +0800846 cmd_batch_pointer(cmd, cmd_len, &dw);
847 dw[0] = dw0;
848 dw[1] = blend_offset | 1;
849 dw[2] = ds_offset | 1;
850 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800851}
852
Chia-I Wu1744cca2014-08-22 11:10:17 +0800853static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 uint32_t clip_offset,
855 uint32_t sf_offset,
856 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800857{
858 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800860
861 CMD_ASSERT(cmd, 6, 6);
862
Chia-I Wu426072d2014-08-26 14:31:55 +0800863 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800864 GEN6_PTR_VP_DW0_CLIP_CHANGED |
865 GEN6_PTR_VP_DW0_SF_CHANGED |
866 GEN6_PTR_VP_DW0_CC_CHANGED |
867 (cmd_len - 2);
868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 cmd_batch_pointer(cmd, cmd_len, &dw);
870 dw[0] = dw0;
871 dw[1] = clip_offset;
872 dw[2] = sf_offset;
873 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800874}
875
876static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800878{
879 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800880 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800881
882 CMD_ASSERT(cmd, 6, 6);
883
Chia-I Wu426072d2014-08-26 14:31:55 +0800884 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800885 (cmd_len - 2);
886
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 cmd_batch_pointer(cmd, cmd_len, &dw);
888 dw[0] = dw0;
889 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800890}
891
Chia-I Wu42a56202014-08-23 16:47:48 +0800892static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 uint32_t vs_offset,
894 uint32_t gs_offset,
895 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800896{
897 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800899
900 CMD_ASSERT(cmd, 6, 6);
901
Chia-I Wu426072d2014-08-26 14:31:55 +0800902 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800903 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
904 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
905 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
906 (cmd_len - 2);
907
Chia-I Wu72292b72014-09-09 10:48:33 +0800908 cmd_batch_pointer(cmd, cmd_len, &dw);
909 dw[0] = dw0;
910 dw[1] = vs_offset;
911 dw[2] = gs_offset;
912 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800913}
914
Chia-I Wu257e75e2014-08-29 14:06:35 +0800915static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 uint32_t vs_offset,
917 uint32_t gs_offset,
918 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800919{
920 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800921 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800922
923 CMD_ASSERT(cmd, 6, 6);
924
925 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
926 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
927 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
928 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
929 (cmd_len - 2);
930
Chia-I Wu72292b72014-09-09 10:48:33 +0800931 cmd_batch_pointer(cmd, cmd_len, &dw);
932 dw[0] = dw0;
933 dw[1] = vs_offset;
934 dw[2] = gs_offset;
935 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800936}
937
Chia-I Wu302742d2014-08-22 10:28:29 +0800938static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800940{
941 const uint8_t cmd_len = 2;
942 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
943 GEN6_RENDER_SUBTYPE_3D |
944 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800946
Chia-I Wu72292b72014-09-09 10:48:33 +0800947 cmd_batch_pointer(cmd, cmd_len, &dw);
948 dw[0] = dw0;
949 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800950}
951
Chia-I Wua6c4f152014-12-02 04:19:58 +0800952static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800953{
Chia-I Wue6073342014-11-30 09:43:42 +0800954 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700955 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
956 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800957
958 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700959 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800960
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800962}
963
Chia-I Wu72292b72014-09-09 10:48:33 +0800964static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700965 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800966{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700967 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800968 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800969 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700970 uint32_t dw[3];
971
972 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700973 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700974 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700975 (state->ds_info.stencilWriteMask & 0xff) << 16 |
976 (state->ds_info.stencilReadMask & 0xff) << 8 |
977 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800979
980 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700981
982 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
983 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800984
Chia-I Wu00b51a82014-09-09 12:07:37 +0800985 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700986 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800987}
988
Chia-I Wu72292b72014-09-09 10:48:33 +0800989static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800990 uint32_t stencil_ref,
991 const uint32_t blend_color[4])
992{
Chia-I Wue6073342014-11-30 09:43:42 +0800993 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800994 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +0800995 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800996
997 CMD_ASSERT(cmd, 6, 7.5);
998
Chia-I Wu00b51a82014-09-09 12:07:37 +0800999 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1000 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001001 dw[0] = stencil_ref;
1002 dw[1] = 0;
1003 dw[2] = blend_color[0];
1004 dw[3] = blend_color[1];
1005 dw[4] = blend_color[2];
1006 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001007
Chia-I Wu72292b72014-09-09 10:48:33 +08001008 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001009}
1010
Chia-I Wu8370b402014-08-29 12:28:37 +08001011static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001012{
Chia-I Wu8370b402014-08-29 12:28:37 +08001013 CMD_ASSERT(cmd, 6, 7.5);
1014
Chia-I Wu707a29e2014-08-27 12:51:47 +08001015 if (!cmd->bind.draw_count)
1016 return;
1017
Chia-I Wu8370b402014-08-29 12:28:37 +08001018 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001019 return;
1020
Chia-I Wu8370b402014-08-29 12:28:37 +08001021 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001022
1023 /*
1024 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1025 *
1026 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1027 * pipe-control with a post-sync op and no write-cache flushes."
1028 *
1029 * The workaround below necessitates this workaround.
1030 */
1031 gen6_PIPE_CONTROL(cmd,
1032 GEN6_PIPE_CONTROL_CS_STALL |
1033 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001034 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001035
Chia-I Wud6d079d2014-08-31 13:14:21 +08001036 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1037 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001038}
1039
Chia-I Wu8370b402014-08-29 12:28:37 +08001040static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001041{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001042 CMD_ASSERT(cmd, 6, 7.5);
1043
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001044 if (!cmd->bind.draw_count)
1045 return;
1046
Chia-I Wud6d079d2014-08-31 13:14:21 +08001047 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1048 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001049}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001050
Chia-I Wu8370b402014-08-29 12:28:37 +08001051static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1052{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001053 CMD_ASSERT(cmd, 7, 7.5);
1054
Chia-I Wu8370b402014-08-29 12:28:37 +08001055 if (!cmd->bind.draw_count)
1056 return;
1057
1058 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001059
1060 gen6_PIPE_CONTROL(cmd,
1061 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001062 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001063}
1064
Chia-I Wu8370b402014-08-29 12:28:37 +08001065static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1066{
1067 CMD_ASSERT(cmd, 7, 7.5);
1068
Chia-I Wu8370b402014-08-29 12:28:37 +08001069 /*
1070 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1071 *
1072 * "One of the following must also be set (when CS stall is set):
1073 *
1074 * * Render Target Cache Flush Enable ([12] of DW1)
1075 * * Depth Cache Flush Enable ([0] of DW1)
1076 * * Stall at Pixel Scoreboard ([1] of DW1)
1077 * * Depth Stall ([13] of DW1)
1078 * * Post-Sync Operation ([13] of DW1)"
1079 */
1080 gen6_PIPE_CONTROL(cmd,
1081 GEN6_PIPE_CONTROL_CS_STALL |
1082 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001083 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001084}
1085
1086static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1087{
1088 CMD_ASSERT(cmd, 7, 7.5);
1089
Chia-I Wu8370b402014-08-29 12:28:37 +08001090 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);
Chia-I Wu3c276c92015-02-16 15:34:45 -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) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001316 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001317
1318 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001319 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001320 viewport->cmd);
1321
1322 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001323 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001324 &viewport->cmd[viewport->cmd_clip_pos]);
1325
1326 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001327 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001328 &viewport->cmd[viewport->cmd_cc_pos]);
1329
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001330 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1331 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1332 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001333
1334 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001335 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001336
Chia-I Wub1d450a2014-09-09 13:48:03 +08001337 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001338}
1339
Chia-I Wu302742d2014-08-22 10:28:29 +08001340static void gen7_cc_states(struct intel_cmd *cmd)
1341{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001342 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1343 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001344 uint32_t stencil_ref;
1345 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001346 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001347
1348 CMD_ASSERT(cmd, 7, 7.5);
1349
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001350 if (!blend && !ds)
1351 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001352
Chia-I Wua6c4f152014-12-02 04:19:58 +08001353 offset = gen6_BLEND_STATE(cmd);
1354 gen7_3dstate_pointer(cmd,
1355 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001356
Chia-I Wua6c4f152014-12-02 04:19:58 +08001357 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001358 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001359 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001360 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001361
1362 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001363 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001364 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1365 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001366 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001367 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1368 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -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 } else {
1372 stencil_ref = 0;
1373 }
1374
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001376 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001377 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001378}
1379
Chia-I Wu1744cca2014-08-22 11:10:17 +08001380static void gen7_viewport_states(struct intel_cmd *cmd)
1381{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001382 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001383 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001384
1385 if (!viewport)
1386 return;
1387
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001388 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001389
Chia-I Wub1d450a2014-09-09 13:48:03 +08001390 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001391 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001394 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1395 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001396
1397 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001398 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001399 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001400 gen7_3dstate_pointer(cmd,
1401 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001402 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001403
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001404 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1405 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1406 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1407 gen7_3dstate_pointer(cmd,
1408 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1409 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001410}
1411
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001412static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001413 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001414{
1415 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001416 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001417
Chia-I Wu72292b72014-09-09 10:48:33 +08001418 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001419
1420 dw[0] = GEN6_RENDER_TYPE_RENDER |
1421 GEN6_RENDER_SUBTYPE_3D |
1422 subop | (cmd_len - 2);
1423 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001424 dw[2] = 0;
1425 dw[3] = 0;
1426 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001427}
1428
1429static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001430 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001431{
1432 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001433 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001434
Chia-I Wu72292b72014-09-09 10:48:33 +08001435 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001436
1437 dw[0] = GEN6_RENDER_TYPE_RENDER |
1438 GEN6_RENDER_SUBTYPE_3D |
1439 subop | (cmd_len - 2);
1440 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001441 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001442 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001443 dw[4] = 0;
1444 dw[5] = 0;
1445 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001446}
1447
Chia-I Wu625105f2014-10-13 15:35:29 +08001448static uint32_t emit_samplers(struct intel_cmd *cmd,
1449 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001450{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001451 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1452 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001453 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001454 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001455 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001456 uint32_t surface_count;
1457 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001458
1459 CMD_ASSERT(cmd, 6, 7.5);
1460
Chia-I Wu625105f2014-10-13 15:35:29 +08001461 if (!rmap || !rmap->sampler_count)
1462 return 0;
1463
Cody Northrop40316a32014-12-09 19:08:33 -07001464 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001465
Chia-I Wudcb509d2014-12-10 08:53:10 +08001466 /*
1467 * note that we cannot call cmd_state_pointer() here as the following
1468 * cmd_state_pointer() would invalidate the pointer
1469 */
1470 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001471 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001472 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001473
1474 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001475 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001476 4 * rmap->sampler_count, &sampler_dw);
1477
Chia-I Wudcb509d2014-12-10 08:53:10 +08001478 cmd_state_update(cmd, border_offset,
1479 border_stride * rmap->sampler_count, &border_dw);
1480
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001481 for (i = 0; i < rmap->sampler_count; i++) {
1482 const struct intel_pipeline_rmap_slot *slot =
1483 &rmap->slots[surface_count + i];
1484 const struct intel_sampler *sampler;
1485
Chia-I Wuf8385062015-01-04 16:27:24 +08001486 switch (slot->type) {
1487 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001488 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001490 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001491 sampler = NULL;
1492 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001493 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001494 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001495 sampler = NULL;
1496 break;
1497 }
1498
1499 if (sampler) {
1500 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1501
1502 sampler_dw[0] = sampler->cmd[0];
1503 sampler_dw[1] = sampler->cmd[1];
1504 sampler_dw[2] = border_offset;
1505 sampler_dw[3] = sampler->cmd[2];
1506 } else {
1507 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1508 sampler_dw[1] = 0;
1509 sampler_dw[2] = 0;
1510 sampler_dw[3] = 0;
1511 }
1512
1513 border_offset += border_stride * 4;
1514 border_dw += border_stride;
1515 sampler_dw += 4;
1516 }
1517
Chia-I Wu625105f2014-10-13 15:35:29 +08001518 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001519}
1520
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001521static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001522 const struct intel_pipeline_rmap *rmap,
1523 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001524{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001525 const uint32_t sba_offset =
1526 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001527 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001529 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001530
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001531 CMD_ASSERT(cmd, 6, 7.5);
1532
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001533 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001534 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001535 if (!surface_count)
1536 return 0;
1537
Chia-I Wu42a56202014-08-23 16:47:48 +08001538 assert(surface_count <= ARRAY_SIZE(binding_table));
1539
1540 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001541 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001542 struct intel_null_view null_view;
1543 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001544
Chia-I Wuf8385062015-01-04 16:27:24 +08001545 switch (slot->type) {
1546 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001547 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001548 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001549 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1550 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001551
Chia-I Wu787a05b2014-12-05 11:02:20 +08001552 if (view) {
1553 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1554 GEN6_ALIGNMENT_SURFACE_STATE,
1555 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001556
Chia-I Wu787a05b2014-12-05 11:02:20 +08001557 cmd_reserve_reloc(cmd, 1);
1558 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1559 view->cmd[1], INTEL_RELOC_WRITE);
1560 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001561 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001562 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001563 }
1564 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001565 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001566 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001567 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1568 const struct intel_mem *mem;
1569 bool read_only;
1570 const uint32_t *cmd_data;
1571 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001572
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001573 assert(dyn_idx < 0 ||
1574 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001575
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001576 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1577 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001578 if (mem) {
1579 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1580 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1581 const uint32_t reloc_flags =
1582 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001583
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001584 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001585 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001586 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001587
1588 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001589 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1590 cmd_data[1] + dynamic_offset, reloc_flags);
1591 } else {
1592 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001593 }
1594 }
1595 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001596 case INTEL_PIPELINE_RMAP_UNUSED:
1597 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001598 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001599 default:
1600 assert(!"unexpected rmap type");
1601 need_null_view = true;
1602 break;
1603 }
1604
1605 if (need_null_view) {
1606 intel_null_view_init(&null_view, cmd->dev);
1607 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1608 GEN6_ALIGNMENT_SURFACE_STATE,
1609 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001610 }
1611
Chia-I Wuf98dd882015-02-10 04:17:47 +08001612 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001613 }
1614
Chia-I Wuf98dd882015-02-10 04:17:47 +08001615 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001616 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001617 surface_count, binding_table) - sba_offset;
1618
1619 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1620 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1621
1622 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001623}
1624
Chia-I Wu1d125092014-10-08 08:49:38 +08001625static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1626{
1627 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001628 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1629 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001630 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001631
1632 CMD_ASSERT(cmd, 6, 7.5);
1633
1634 if (!pipeline->vb_count)
1635 return;
1636
1637 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1638
1639 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1640 dw++;
1641 pos++;
1642
1643 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001644 assert(pipeline->vb[i].strideInBytes <= 2048);
1645
1646 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1647 pipeline->vb[i].strideInBytes;
1648
1649 if (cmd_gen(cmd) >= INTEL_GEN(7))
1650 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1651
1652 switch (pipeline->vb[i].stepRate) {
1653 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1654 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1655 dw[3] = 0;
1656 break;
1657 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1658 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1659 dw[3] = 1;
1660 break;
1661 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1662 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1663 dw[3] = 0;
1664 break;
1665 default:
1666 assert(!"unknown step rate");
1667 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1668 dw[3] = 0;
1669 break;
1670 }
1671
Chia-I Wu714df452015-01-01 07:55:04 +08001672 if (cmd->bind.vertex.buf[i]) {
1673 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001674 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001675
1676 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001677 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1678 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001679 } else {
1680 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1681 dw[1] = 0;
1682 dw[2] = 0;
1683 }
1684
1685 dw += 4;
1686 pos += 4;
1687 }
1688}
1689
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001690static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1691{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001692 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1693 const struct intel_pipeline_shader *vs = &pipeline->vs;
1694 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001695 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001696 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001697 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001698 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001699
1700 CMD_ASSERT(cmd, 6, 7.5);
1701
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001702 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001703 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1704 *
1705 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1706 * 128-bit vertex elements to be passed into the payload for each
1707 * vertex."
1708 *
1709 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1710 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001711 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001712 vue_read_len = (vs->in_count + 1) / 2;
1713 if (!vue_read_len)
1714 vue_read_len = 1;
1715
1716 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1717 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1718
1719 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1720 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1721 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001722
1723 dw5 = GEN6_VS_DW5_STATISTICS |
1724 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001725
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001726 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001727 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001728 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001729 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001730
Chia-I Wube0a3d92014-09-02 13:20:59 +08001731 if (pipeline->disable_vs_cache)
1732 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1733
Chia-I Wu784d3042014-12-19 14:30:04 +08001734 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001735 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001736 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001737 dw[2] = dw2;
1738 dw[3] = 0; /* scratch */
1739 dw[4] = dw4;
1740 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001741
1742 if (vs->per_thread_scratch_size)
1743 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001744}
1745
Chia-I Wu625105f2014-10-13 15:35:29 +08001746static void emit_shader_resources(struct intel_cmd *cmd)
1747{
1748 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001749 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001750
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001751 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001752 cmd->bind.pipeline.graphics->vs.rmap,
1753 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001754 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001755 cmd->bind.pipeline.graphics->tcs.rmap,
1756 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001757 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001758 cmd->bind.pipeline.graphics->tes.rmap,
1759 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001760 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001761 cmd->bind.pipeline.graphics->gs.rmap,
1762 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001763 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001764 cmd->bind.pipeline.graphics->fs.rmap,
1765 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001766
1767 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1768 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1769 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1770 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1771 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1772
1773 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1774 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001775 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1776 binding_tables[0]);
1777 gen7_3dstate_pointer(cmd,
1778 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1779 binding_tables[1]);
1780 gen7_3dstate_pointer(cmd,
1781 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1782 binding_tables[2]);
1783 gen7_3dstate_pointer(cmd,
1784 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1785 binding_tables[3]);
1786 gen7_3dstate_pointer(cmd,
1787 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1788 binding_tables[4]);
1789
1790 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001791 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1792 samplers[0]);
1793 gen7_3dstate_pointer(cmd,
1794 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1795 samplers[1]);
1796 gen7_3dstate_pointer(cmd,
1797 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1798 samplers[2]);
1799 gen7_3dstate_pointer(cmd,
1800 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1801 samplers[3]);
1802 gen7_3dstate_pointer(cmd,
1803 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1804 samplers[4]);
1805 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001806 assert(!binding_tables[1] && !binding_tables[2]);
1807 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1808 binding_tables[0], binding_tables[3], binding_tables[4]);
1809
Chia-I Wu625105f2014-10-13 15:35:29 +08001810 assert(!samplers[1] && !samplers[2]);
1811 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1812 samplers[0], samplers[3], samplers[4]);
1813 }
1814}
1815
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001816static void emit_rt(struct intel_cmd *cmd)
1817{
1818 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001819 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1820 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001821}
1822
1823static void emit_ds(struct intel_cmd *cmd)
1824{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001825 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001826
1827 if (!ds) {
1828 /* all zeros */
1829 static const struct intel_ds_view null_ds;
1830 ds = &null_ds;
1831 }
1832
1833 cmd_wa_gen6_pre_ds_flush(cmd);
1834 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1835 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1836 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1837
1838 if (cmd_gen(cmd) >= INTEL_GEN(7))
1839 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1840 else
1841 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1842}
1843
Chia-I Wua57761b2014-10-14 14:27:44 +08001844static uint32_t emit_shader(struct intel_cmd *cmd,
1845 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001846{
Chia-I Wua57761b2014-10-14 14:27:44 +08001847 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1848 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001849 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001850
Chia-I Wua57761b2014-10-14 14:27:44 +08001851 /* see if the shader is already in the cache */
1852 for (i = 0; i < cache->used; i++) {
1853 if (cache->entries[i].shader == (const void *) shader)
1854 return cache->entries[i].kernel_offset;
1855 }
1856
1857 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1858
1859 /* grow the cache if full */
1860 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001861 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001862 void *entries;
1863
1864 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1865 XGL_SYSTEM_ALLOC_INTERNAL);
1866 if (entries) {
1867 if (cache->entries) {
1868 memcpy(entries, cache->entries,
1869 sizeof(cache->entries[0]) * cache->used);
1870 icd_free(cache->entries);
1871 }
1872
1873 cache->entries = entries;
1874 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001875 }
1876 }
1877
Chia-I Wua57761b2014-10-14 14:27:44 +08001878 /* add the shader to the cache */
1879 if (cache->used < cache->count) {
1880 cache->entries[cache->used].shader = (const void *) shader;
1881 cache->entries[cache->used].kernel_offset = offset;
1882 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001883 }
1884
Chia-I Wua57761b2014-10-14 14:27:44 +08001885 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001886}
1887
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001888static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001889{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001890 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001891
Chia-I Wu8370b402014-08-29 12:28:37 +08001892 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1893 cmd_wa_gen6_pre_depth_stall_write(cmd);
1894 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1895 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1896 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1897 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001898
1899 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001900 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001901 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001902
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001903 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001904 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001905 }
1906 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001907 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001908 }
1909 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001910 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1911 }
1912 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1913 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1914 }
1915 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1916 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001918
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001919 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1920 gen7_3DSTATE_GS(cmd);
1921 } else {
1922 gen6_3DSTATE_GS(cmd);
1923 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001924
Chia-I Wu8370b402014-08-29 12:28:37 +08001925 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1926 cmd_wa_gen7_post_command_cs_stall(cmd);
1927 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1928 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001929}
1930
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001931static void emit_bounded_states(struct intel_cmd *cmd)
1932{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001933
1934 emit_graphics_pipeline(cmd);
1935
1936 emit_rt(cmd);
1937 emit_ds(cmd);
1938
1939 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1940 gen7_cc_states(cmd);
1941 gen7_viewport_states(cmd);
1942
1943 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1944 &cmd->bind.pipeline.graphics->vs);
1945 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1946 &cmd->bind.pipeline.graphics->fs);
1947
1948 gen6_3DSTATE_CLIP(cmd);
1949 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001950 gen7_3DSTATE_WM(cmd);
1951 gen7_3DSTATE_PS(cmd);
1952 } else {
1953 gen6_cc_states(cmd);
1954 gen6_viewport_states(cmd);
1955
1956 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1957 &cmd->bind.pipeline.graphics->vs);
1958 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1959 &cmd->bind.pipeline.graphics->fs);
1960
1961 gen6_3DSTATE_CLIP(cmd);
1962 gen6_3DSTATE_SF(cmd);
1963 gen6_3DSTATE_WM(cmd);
1964 }
1965
1966 emit_shader_resources(cmd);
1967
1968 cmd_wa_gen6_pre_depth_stall_write(cmd);
1969 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1970
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001971 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1972 gen6_3DSTATE_VS(cmd);
1973}
1974
Tony Barbourfa6cac72015-01-16 14:27:35 -07001975static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07001976 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001977{
1978 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1979 const uint8_t cmd_len = 3;
1980 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07001981
1982 CMD_ASSERT(cmd, 6, 7.5);
1983
Tony Barbourfa6cac72015-01-16 14:27:35 -07001984 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07001985 dw[0] = 0;
1986 dw[1] = 0;
1987 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
1988 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
1989 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
1990 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001991 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
1992 (GEN6_STENCILOP_KEEP) << 25 |
1993 (GEN6_STENCILOP_KEEP) << 22 |
1994 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07001995 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
1996 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07001997 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
1998 (GEN6_STENCILOP_KEEP) << 9 |
1999 (GEN6_STENCILOP_KEEP) << 6 |
2000 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002001
Chia-I Wud850a392015-02-19 11:08:25 -07002002 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2003 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2004 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2005 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2006 dw[2] = 0;
2007 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002008
2009 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2010 cmd_align, cmd_len, dw);
2011}
2012
Chia-I Wu6032b892014-10-17 14:47:18 +08002013static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2014{
2015 const struct intel_cmd_meta *meta = cmd->bind.meta;
2016 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2017
2018 CMD_ASSERT(cmd, 6, 7.5);
2019
2020 blend_offset = 0;
2021 ds_offset = 0;
2022 cc_offset = 0;
2023 cc_vp_offset = 0;
2024
Chia-I Wu29e6f502014-11-24 14:27:29 +08002025 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002026 /* BLEND_STATE */
2027 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002028 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002029 dw[0] = 0;
2030 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2031 }
2032
Chia-I Wu29e6f502014-11-24 14:27:29 +08002033 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002034 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002035 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002036 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2037 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002038
Chia-I Wu29e6f502014-11-24 14:27:29 +08002039 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002040 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002041
Chia-I Wu29e6f502014-11-24 14:27:29 +08002042 /* COLOR_CALC_STATE */
2043 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002044 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002045
Chia-I Wu29e6f502014-11-24 14:27:29 +08002046 /* CC_VIEWPORT */
2047 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002048 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 dw[0] = u_fui(0.0f);
2050 dw[1] = u_fui(1.0f);
2051 } else {
2052 /* DEPTH_STENCIL_STATE */
2053 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002054 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002055 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2056 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2057 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002058 }
2059
2060 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2061 gen7_3dstate_pointer(cmd,
2062 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2063 blend_offset);
2064 gen7_3dstate_pointer(cmd,
2065 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2066 ds_offset);
2067 gen7_3dstate_pointer(cmd,
2068 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2069
2070 gen7_3dstate_pointer(cmd,
2071 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2072 cc_vp_offset);
2073 } else {
2074 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002075 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002076
2077 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2078 cmd_batch_pointer(cmd, 4, &dw);
2079 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2080 GEN6_PTR_VP_DW0_CC_CHANGED;
2081 dw[1] = 0;
2082 dw[2] = 0;
2083 dw[3] = cc_vp_offset;
2084 }
2085}
2086
2087static void gen6_meta_surface_states(struct intel_cmd *cmd)
2088{
2089 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002090 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002091 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002092 const uint32_t sba_offset =
2093 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002094
2095 CMD_ASSERT(cmd, 6, 7.5);
2096
Chia-I Wu29e6f502014-11-24 14:27:29 +08002097 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2098 return;
2099
Chia-I Wu005c47c2014-10-22 13:49:13 +08002100 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002101 if (meta->src.valid) {
2102 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002103 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002104 meta->src.surface_len, meta->src.surface);
2105
2106 cmd_reserve_reloc(cmd, 1);
2107 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2108 cmd_surface_reloc_writer(cmd, offset, 1,
2109 meta->src.reloc_target, meta->src.reloc_offset);
2110 } else {
2111 cmd_surface_reloc(cmd, offset, 1,
2112 (struct intel_bo *) meta->src.reloc_target,
2113 meta->src.reloc_offset, meta->src.reloc_flags);
2114 }
2115
Mike Stroyan9bfad482015-02-10 15:09:23 -07002116 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002117 }
2118 if (meta->dst.valid) {
2119 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002120 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002121 meta->dst.surface_len, meta->dst.surface);
2122
2123 cmd_reserve_reloc(cmd, 1);
2124 cmd_surface_reloc(cmd, offset, 1,
2125 (struct intel_bo *) meta->dst.reloc_target,
2126 meta->dst.reloc_offset, meta->dst.reloc_flags);
2127
Mike Stroyan9bfad482015-02-10 15:09:23 -07002128 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002129 }
2130
2131 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002132 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002133 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002134 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002135
2136 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002137 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2138 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2139 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002140 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002141 } else {
2142 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002143 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002144 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002145 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002146 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002147 }
2148}
2149
2150static void gen6_meta_urb(struct intel_cmd *cmd)
2151{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002152 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 uint32_t *dw;
2154
2155 CMD_ASSERT(cmd, 6, 6);
2156
2157 /* 3DSTATE_URB */
2158 cmd_batch_pointer(cmd, 3, &dw);
2159 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002160 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002161 dw[2] = 0;
2162}
2163
2164static void gen7_meta_urb(struct intel_cmd *cmd)
2165{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002166 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2167 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002168 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 uint32_t *dw;
2170
2171 CMD_ASSERT(cmd, 7, 7.5);
2172
2173 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2174 cmd_batch_pointer(cmd, 10, &dw);
2175
2176 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002177 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
2178 dw += 2;
2179
2180 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2181 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
2182 pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002183 dw += 2;
2184
2185 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2186 dw[1] = 0;
2187 dw += 2;
2188
2189 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2190 dw[1] = 0;
2191 dw += 2;
2192
2193 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2194 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002195
Chia-I Wu15dacac2015-02-05 11:14:01 -07002196 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002197
2198 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2199
Chia-I Wu24aa1022014-11-25 11:53:19 +08002200 switch (cmd_gen(cmd)) {
2201 case INTEL_GEN(7.5):
2202 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2203 break;
2204 case INTEL_GEN(7):
2205 default:
2206 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2207 break;
2208 }
2209
Chia-I Wu6032b892014-10-17 14:47:18 +08002210 /* 3DSTATE_URB_x */
2211 cmd_batch_pointer(cmd, 8, &dw);
2212
2213 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002214 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002215 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002216 dw += 2;
2217
2218 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002219 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002220 dw += 2;
2221
2222 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002223 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002224 dw += 2;
2225
2226 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002227 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002228 dw += 2;
2229}
2230
2231static void gen6_meta_vf(struct intel_cmd *cmd)
2232{
2233 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002234 uint32_t vb_start, vb_end, vb_stride;
2235 int ve_format, ve_z_source;
2236 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002237 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002238
2239 CMD_ASSERT(cmd, 6, 7.5);
2240
Chia-I Wu29e6f502014-11-24 14:27:29 +08002241 switch (meta->mode) {
2242 case INTEL_CMD_META_VS_POINTS:
2243 cmd_batch_pointer(cmd, 3, &dw);
2244 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2245 dw[1] = GEN6_VE_STATE_DW0_VALID;
2246 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2247 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2248 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2249 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2250 return;
2251 break;
2252 case INTEL_CMD_META_FS_RECT:
2253 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002254 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002255
Chia-I Wu29e6f502014-11-24 14:27:29 +08002256 vertices[0][0] = meta->dst.x + meta->width;
2257 vertices[0][1] = meta->dst.y + meta->height;
2258 vertices[1][0] = meta->dst.x;
2259 vertices[1][1] = meta->dst.y + meta->height;
2260 vertices[2][0] = meta->dst.x;
2261 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002262
Chia-I Wu29e6f502014-11-24 14:27:29 +08002263 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2264 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002265
Chia-I Wu29e6f502014-11-24 14:27:29 +08002266 vb_end = vb_start + sizeof(vertices) - 1;
2267 vb_stride = sizeof(vertices[0]);
2268 ve_z_source = GEN6_VFCOMP_STORE_0;
2269 ve_format = GEN6_FORMAT_R32G32_USCALED;
2270 }
2271 break;
2272 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2273 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002274 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002275
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002276 vertices[0][0] = (float) (meta->dst.x + meta->width);
2277 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002278 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002279 vertices[1][0] = (float) meta->dst.x;
2280 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002282 vertices[2][0] = (float) meta->dst.x;
2283 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002284 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002285
Chia-I Wu29e6f502014-11-24 14:27:29 +08002286 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2287 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002288
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 vb_end = vb_start + sizeof(vertices) - 1;
2290 vb_stride = sizeof(vertices[0]);
2291 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2292 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2293 }
2294 break;
2295 default:
2296 assert(!"unknown meta mode");
2297 return;
2298 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002299 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002300
2301 /* 3DSTATE_VERTEX_BUFFERS */
2302 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002303
Chia-I Wu6032b892014-10-17 14:47:18 +08002304 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002306 if (cmd_gen(cmd) >= INTEL_GEN(7))
2307 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2308
2309 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002310 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2311 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002312
2313 dw[4] = 0;
2314
2315 /* 3DSTATE_VERTEX_ELEMENTS */
2316 cmd_batch_pointer(cmd, 5, &dw);
2317 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002318 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002319 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2320 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2321 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2322 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2323 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002324 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002325 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2326 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002327 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002328 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2329}
2330
Chia-I Wu29e6f502014-11-24 14:27:29 +08002331static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002332{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002333 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002334 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002335 uint32_t consts[8];
2336 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002337
2338 CMD_ASSERT(cmd, 6, 7.5);
2339
2340 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002341 case INTEL_DEV_META_VS_FILL_MEM:
2342 consts[0] = meta->dst.x;
2343 consts[1] = meta->clear_val[0];
2344 const_count = 2;
2345 break;
2346 case INTEL_DEV_META_VS_COPY_MEM:
2347 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2348 consts[0] = meta->dst.x;
2349 consts[1] = meta->src.x;
2350 const_count = 2;
2351 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002352 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2353 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2354 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2355 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2356 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2357 consts[0] = meta->src.x;
2358 consts[1] = meta->src.y;
2359 consts[2] = meta->width;
2360 consts[3] = meta->dst.x;
2361 const_count = 4;
2362 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002363 default:
2364 assert(!"unknown meta shader id");
2365 const_count = 0;
2366 break;
2367 }
2368
2369 /* this can be skipped but it makes state dumping prettier */
2370 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2371
2372 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2373}
2374
2375static void gen6_meta_vs(struct intel_cmd *cmd)
2376{
2377 const struct intel_cmd_meta *meta = cmd->bind.meta;
2378 const struct intel_pipeline_shader *sh =
2379 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2380 uint32_t offset, *dw;
2381
2382 CMD_ASSERT(cmd, 6, 7.5);
2383
2384 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002385 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002386
2387 /* 3DSTATE_CONSTANT_VS */
2388 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2389 cmd_batch_pointer(cmd, cmd_len, &dw);
2390 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2391 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2392
2393 /* 3DSTATE_VS */
2394 cmd_batch_pointer(cmd, 6, &dw);
2395 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2396 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2397
2398 return;
2399 }
2400
2401 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2402
2403 /* 3DSTATE_CONSTANT_VS */
2404 offset = gen6_meta_vs_constants(cmd);
2405 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2406 cmd_batch_pointer(cmd, 7, &dw);
2407 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2408 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2409 dw[2] = 0;
2410 dw[3] = offset;
2411 dw[4] = 0;
2412 dw[5] = 0;
2413 dw[6] = 0;
2414 } else {
2415 cmd_batch_pointer(cmd, 5, &dw);
2416 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2417 GEN6_PCB_ANY_DW0_PCB0_VALID;
2418 dw[1] = offset;
2419 dw[2] = 0;
2420 dw[3] = 0;
2421 dw[4] = 0;
2422 }
2423
2424 /* 3DSTATE_VS */
2425 offset = emit_shader(cmd, sh);
2426 cmd_batch_pointer(cmd, 6, &dw);
2427 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2428 dw[1] = offset;
2429 dw[2] = GEN6_THREADDISP_SPF |
2430 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2431 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002432 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002433 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2434 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2435
2436 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2437 GEN6_VS_DW5_VS_ENABLE;
2438 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002439 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002440 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002441 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002442
2443 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002444}
2445
2446static void gen6_meta_disabled(struct intel_cmd *cmd)
2447{
Chia-I Wu6032b892014-10-17 14:47:18 +08002448 uint32_t *dw;
2449
2450 CMD_ASSERT(cmd, 6, 6);
2451
Chia-I Wu6032b892014-10-17 14:47:18 +08002452 /* 3DSTATE_CONSTANT_GS */
2453 cmd_batch_pointer(cmd, 5, &dw);
2454 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2455 dw[1] = 0;
2456 dw[2] = 0;
2457 dw[3] = 0;
2458 dw[4] = 0;
2459
2460 /* 3DSTATE_GS */
2461 cmd_batch_pointer(cmd, 7, &dw);
2462 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2463 dw[1] = 0;
2464 dw[2] = 0;
2465 dw[3] = 0;
2466 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2467 dw[5] = GEN6_GS_DW5_STATISTICS;
2468 dw[6] = 0;
2469
Chia-I Wu6032b892014-10-17 14:47:18 +08002470 /* 3DSTATE_SF */
2471 cmd_batch_pointer(cmd, 20, &dw);
2472 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2473 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2474 memset(&dw[2], 0, 18 * sizeof(*dw));
2475}
2476
2477static void gen7_meta_disabled(struct intel_cmd *cmd)
2478{
2479 uint32_t *dw;
2480
2481 CMD_ASSERT(cmd, 7, 7.5);
2482
Chia-I Wu6032b892014-10-17 14:47:18 +08002483 /* 3DSTATE_CONSTANT_HS */
2484 cmd_batch_pointer(cmd, 7, &dw);
2485 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2486 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2487
2488 /* 3DSTATE_HS */
2489 cmd_batch_pointer(cmd, 7, &dw);
2490 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2491 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2492
2493 /* 3DSTATE_TE */
2494 cmd_batch_pointer(cmd, 4, &dw);
2495 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2496 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2497
2498 /* 3DSTATE_CONSTANT_DS */
2499 cmd_batch_pointer(cmd, 7, &dw);
2500 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2501 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2502
2503 /* 3DSTATE_DS */
2504 cmd_batch_pointer(cmd, 6, &dw);
2505 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2506 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2507
2508 /* 3DSTATE_CONSTANT_GS */
2509 cmd_batch_pointer(cmd, 7, &dw);
2510 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2511 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2512
2513 /* 3DSTATE_GS */
2514 cmd_batch_pointer(cmd, 7, &dw);
2515 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2516 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2517
2518 /* 3DSTATE_STREAMOUT */
2519 cmd_batch_pointer(cmd, 3, &dw);
2520 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2521 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2522
Chia-I Wu6032b892014-10-17 14:47:18 +08002523 /* 3DSTATE_SF */
2524 cmd_batch_pointer(cmd, 7, &dw);
2525 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2526 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2527
2528 /* 3DSTATE_SBE */
2529 cmd_batch_pointer(cmd, 14, &dw);
2530 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2531 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2532 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002533}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002534
Chia-I Wu29e6f502014-11-24 14:27:29 +08002535static void gen6_meta_clip(struct intel_cmd *cmd)
2536{
2537 const struct intel_cmd_meta *meta = cmd->bind.meta;
2538 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002539
Chia-I Wu29e6f502014-11-24 14:27:29 +08002540 /* 3DSTATE_CLIP */
2541 cmd_batch_pointer(cmd, 4, &dw);
2542 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2543 dw[1] = 0;
2544 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2545 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2546 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2547 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002548 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002549 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002550 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002551}
2552
2553static void gen6_meta_wm(struct intel_cmd *cmd)
2554{
2555 const struct intel_cmd_meta *meta = cmd->bind.meta;
2556 uint32_t *dw;
2557
2558 CMD_ASSERT(cmd, 6, 7.5);
2559
2560 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2561
2562 /* 3DSTATE_MULTISAMPLE */
2563 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2564 cmd_batch_pointer(cmd, 4, &dw);
2565 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2566 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2567 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2568 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2569 dw[2] = 0;
2570 dw[3] = 0;
2571 } else {
2572 cmd_batch_pointer(cmd, 3, &dw);
2573 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2574 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2575 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2576 dw[2] = 0;
2577 }
2578
2579 /* 3DSTATE_SAMPLE_MASK */
2580 cmd_batch_pointer(cmd, 2, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2582 dw[1] = (1 << meta->samples) - 1;
2583
2584 /* 3DSTATE_DRAWING_RECTANGLE */
2585 cmd_batch_pointer(cmd, 4, &dw);
2586 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002587 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2588 /* unused */
2589 dw[1] = 0;
2590 dw[2] = 0;
2591 } else {
2592 dw[1] = meta->dst.y << 16 | meta->dst.x;
2593 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2594 (meta->dst.x + meta->width - 1);
2595 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002596 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) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002901 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002902 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) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002926 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002927 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 Wu4e5577a2015-02-10 11:04:44 -07002942 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08002943 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 Wu08cd6e92015-02-11 13:44:50 -07003054 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003055 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))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003067 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003068
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 Wu4e5577a2015-02-10 11:04:44 -07003174 cmd_fail(cmd, 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 Wu4e5577a2015-02-10 11:04:44 -07003194 cmd_fail(cmd, 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 Wu4e5577a2015-02-10 11:04:44 -07003224 cmd_fail(cmd, 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 Wu4e5577a2015-02-10 11:04:44 -07003246 cmd_fail(cmd, 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
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003311 cmd_fail(cmd, 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
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003323 cmd_fail(cmd, 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
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003334 cmd_fail(cmd, 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
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003344 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003345}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003346
Chia-I Wude26bdf2015-02-18 15:47:12 -07003347ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003348 XGL_CMD_BUFFER cmdBuffer,
3349 XGL_RENDER_PASS renderPass)
3350{
3351 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3352
3353 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3354}
3355
Chia-I Wude26bdf2015-02-18 15:47:12 -07003356ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003357 XGL_CMD_BUFFER cmdBuffer,
3358 XGL_RENDER_PASS renderPass)
3359{
3360 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3361
3362 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3363}