blob: 1d6093cf41f16e9c640c9dad9681c944b9e4e070 [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,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700714 const struct intel_ds_view *view,
715 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800716{
717 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800718 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600719 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800720
721 CMD_ASSERT(cmd, 6, 7.5);
722
723 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800724 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
725 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800726 dw0 |= (cmd_len - 2);
727
Chia-I Wu72292b72014-09-09 10:48:33 +0800728 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
729 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700730
Chia-I Wu72292b72014-09-09 10:48:33 +0800731 dw[1] = view->cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700732 /* note that we only enable HiZ on Gen7+ */
733 if (!optimal_ds)
734 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
735
Chia-I Wu72292b72014-09-09 10:48:33 +0800736 dw[2] = 0;
737 dw[3] = view->cmd[2];
738 dw[4] = view->cmd[3];
739 dw[5] = view->cmd[4];
740 dw[6] = view->cmd[5];
741
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600742 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800743 cmd_reserve_reloc(cmd, 1);
744 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
745 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600746 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800747}
748
749static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700750 const struct intel_ds_view *view,
751 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800752{
753 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800754 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600755 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800756
757 CMD_ASSERT(cmd, 6, 7.5);
758
759 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800760 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
761 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800762 dw0 |= (cmd_len - 2);
763
Chia-I Wu72292b72014-09-09 10:48:33 +0800764 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
765 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800766
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700767 if (view->has_stencil) {
768 dw[1] = view->cmd[6];
769
Chia-I Wu72292b72014-09-09 10:48:33 +0800770 cmd_reserve_reloc(cmd, 1);
771 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
772 view->cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700773 } else {
774 dw[1] = 0;
775 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600776 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800777}
778
779static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700780 const struct intel_ds_view *view,
781 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800782{
783 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800784 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600785 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800786
787 CMD_ASSERT(cmd, 6, 7.5);
788
789 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800790 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
791 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800792 dw0 |= (cmd_len - 2);
793
Chia-I Wu72292b72014-09-09 10:48:33 +0800794 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
795 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800796
Chia-I Wu73520ac2015-02-19 11:17:45 -0700797 if (view->has_hiz && optimal_ds) {
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700798 dw[1] = view->cmd[8];
799
Chia-I Wu72292b72014-09-09 10:48:33 +0800800 cmd_reserve_reloc(cmd, 1);
801 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
802 view->cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700803 } else {
804 dw[1] = 0;
805 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600806 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800807}
808
Chia-I Wuf8231032014-08-25 10:44:45 +0800809static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
810 uint32_t clear_val)
811{
812 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800813 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800814 GEN6_CLEAR_PARAMS_DW0_VALID |
815 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800816 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800817
818 CMD_ASSERT(cmd, 6, 6);
819
Chia-I Wu72292b72014-09-09 10:48:33 +0800820 cmd_batch_pointer(cmd, cmd_len, &dw);
821 dw[0] = dw0;
822 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800823}
824
825static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
826 uint32_t clear_val)
827{
828 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800829 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800830 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800831 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800832
833 CMD_ASSERT(cmd, 7, 7.5);
834
Chia-I Wu72292b72014-09-09 10:48:33 +0800835 cmd_batch_pointer(cmd, cmd_len, &dw);
836 dw[0] = dw0;
837 dw[1] = clear_val;
838 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800839}
840
Chia-I Wu302742d2014-08-22 10:28:29 +0800841static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800842 uint32_t blend_offset,
843 uint32_t ds_offset,
844 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800845{
846 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800847 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800848
849 CMD_ASSERT(cmd, 6, 6);
850
Chia-I Wu426072d2014-08-26 14:31:55 +0800851 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800852 (cmd_len - 2);
853
Chia-I Wu72292b72014-09-09 10:48:33 +0800854 cmd_batch_pointer(cmd, cmd_len, &dw);
855 dw[0] = dw0;
856 dw[1] = blend_offset | 1;
857 dw[2] = ds_offset | 1;
858 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800859}
860
Chia-I Wu1744cca2014-08-22 11:10:17 +0800861static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800862 uint32_t clip_offset,
863 uint32_t sf_offset,
864 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800865{
866 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800867 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800868
869 CMD_ASSERT(cmd, 6, 6);
870
Chia-I Wu426072d2014-08-26 14:31:55 +0800871 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800872 GEN6_PTR_VP_DW0_CLIP_CHANGED |
873 GEN6_PTR_VP_DW0_SF_CHANGED |
874 GEN6_PTR_VP_DW0_CC_CHANGED |
875 (cmd_len - 2);
876
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 cmd_batch_pointer(cmd, cmd_len, &dw);
878 dw[0] = dw0;
879 dw[1] = clip_offset;
880 dw[2] = sf_offset;
881 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800882}
883
884static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800885 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800886{
887 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800889
890 CMD_ASSERT(cmd, 6, 6);
891
Chia-I Wu426072d2014-08-26 14:31:55 +0800892 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800893 (cmd_len - 2);
894
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 cmd_batch_pointer(cmd, cmd_len, &dw);
896 dw[0] = dw0;
897 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800898}
899
Chia-I Wu42a56202014-08-23 16:47:48 +0800900static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800901 uint32_t vs_offset,
902 uint32_t gs_offset,
903 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800904{
905 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800906 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800907
908 CMD_ASSERT(cmd, 6, 6);
909
Chia-I Wu426072d2014-08-26 14:31:55 +0800910 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800911 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
912 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
913 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
914 (cmd_len - 2);
915
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 cmd_batch_pointer(cmd, cmd_len, &dw);
917 dw[0] = dw0;
918 dw[1] = vs_offset;
919 dw[2] = gs_offset;
920 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800921}
922
Chia-I Wu257e75e2014-08-29 14:06:35 +0800923static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800924 uint32_t vs_offset,
925 uint32_t gs_offset,
926 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800927{
928 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800929 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800930
931 CMD_ASSERT(cmd, 6, 6);
932
933 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
934 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
935 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
936 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
937 (cmd_len - 2);
938
Chia-I Wu72292b72014-09-09 10:48:33 +0800939 cmd_batch_pointer(cmd, cmd_len, &dw);
940 dw[0] = dw0;
941 dw[1] = vs_offset;
942 dw[2] = gs_offset;
943 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800944}
945
Chia-I Wu302742d2014-08-22 10:28:29 +0800946static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800947 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800948{
949 const uint8_t cmd_len = 2;
950 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
951 GEN6_RENDER_SUBTYPE_3D |
952 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800954
Chia-I Wu72292b72014-09-09 10:48:33 +0800955 cmd_batch_pointer(cmd, cmd_len, &dw);
956 dw[0] = dw0;
957 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800958}
959
Chia-I Wua6c4f152014-12-02 04:19:58 +0800960static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800961{
Chia-I Wue6073342014-11-30 09:43:42 +0800962 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700963 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
964 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800965
966 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700967 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800968
Tony Barbourfa6cac72015-01-16 14:27:35 -0700969 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800970}
971
Chia-I Wu72292b72014-09-09 10:48:33 +0800972static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700973 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800974{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700975 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800976 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800977 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700978 uint32_t dw[3];
979
980 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700981 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700982 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700983 (state->ds_info.stencilWriteMask & 0xff) << 16 |
984 (state->ds_info.stencilReadMask & 0xff) << 8 |
985 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700986 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800987
988 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700989
990 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
991 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992
Chia-I Wu00b51a82014-09-09 12:07:37 +0800993 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700994 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800995}
996
Chia-I Wu72292b72014-09-09 10:48:33 +0800997static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800998 uint32_t stencil_ref,
999 const uint32_t blend_color[4])
1000{
Chia-I Wue6073342014-11-30 09:43:42 +08001001 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001002 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001003 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001004
1005 CMD_ASSERT(cmd, 6, 7.5);
1006
Chia-I Wu00b51a82014-09-09 12:07:37 +08001007 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1008 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001009 dw[0] = stencil_ref;
1010 dw[1] = 0;
1011 dw[2] = blend_color[0];
1012 dw[3] = blend_color[1];
1013 dw[4] = blend_color[2];
1014 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001015
Chia-I Wu72292b72014-09-09 10:48:33 +08001016 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001017}
1018
Chia-I Wu8370b402014-08-29 12:28:37 +08001019static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001020{
Chia-I Wu8370b402014-08-29 12:28:37 +08001021 CMD_ASSERT(cmd, 6, 7.5);
1022
Chia-I Wu707a29e2014-08-27 12:51:47 +08001023 if (!cmd->bind.draw_count)
1024 return;
1025
Chia-I Wu8370b402014-08-29 12:28:37 +08001026 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001027 return;
1028
Chia-I Wu8370b402014-08-29 12:28:37 +08001029 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001030
1031 /*
1032 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1033 *
1034 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1035 * pipe-control with a post-sync op and no write-cache flushes."
1036 *
1037 * The workaround below necessitates this workaround.
1038 */
1039 gen6_PIPE_CONTROL(cmd,
1040 GEN6_PIPE_CONTROL_CS_STALL |
1041 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001042 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001043
Chia-I Wud6d079d2014-08-31 13:14:21 +08001044 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1045 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001046}
1047
Chia-I Wu8370b402014-08-29 12:28:37 +08001048static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001049{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001050 CMD_ASSERT(cmd, 6, 7.5);
1051
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001052 if (!cmd->bind.draw_count)
1053 return;
1054
Chia-I Wud6d079d2014-08-31 13:14:21 +08001055 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1056 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001057}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001058
Chia-I Wu8370b402014-08-29 12:28:37 +08001059static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1060{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001061 CMD_ASSERT(cmd, 7, 7.5);
1062
Chia-I Wu8370b402014-08-29 12:28:37 +08001063 if (!cmd->bind.draw_count)
1064 return;
1065
1066 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001067
1068 gen6_PIPE_CONTROL(cmd,
1069 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001070 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001071}
1072
Chia-I Wu8370b402014-08-29 12:28:37 +08001073static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1074{
1075 CMD_ASSERT(cmd, 7, 7.5);
1076
Chia-I Wu8370b402014-08-29 12:28:37 +08001077 /*
1078 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1079 *
1080 * "One of the following must also be set (when CS stall is set):
1081 *
1082 * * Render Target Cache Flush Enable ([12] of DW1)
1083 * * Depth Cache Flush Enable ([0] of DW1)
1084 * * Stall at Pixel Scoreboard ([1] of DW1)
1085 * * Depth Stall ([13] of DW1)
1086 * * Post-Sync Operation ([13] of DW1)"
1087 */
1088 gen6_PIPE_CONTROL(cmd,
1089 GEN6_PIPE_CONTROL_CS_STALL |
1090 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001091 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001092}
1093
1094static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1095{
1096 CMD_ASSERT(cmd, 7, 7.5);
1097
Chia-I Wu8370b402014-08-29 12:28:37 +08001098 cmd_wa_gen6_pre_depth_stall_write(cmd);
1099
Chia-I Wud6d079d2014-08-31 13:14:21 +08001100 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001101}
1102
1103static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1104{
1105 CMD_ASSERT(cmd, 6, 7.5);
1106
1107 if (!cmd->bind.draw_count)
1108 return;
1109
1110 /*
1111 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1112 *
1113 * "Driver must guarentee that all the caches in the depth pipe are
1114 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1115 * requires driver to send a PIPE_CONTROL with a CS stall along with
1116 * a Depth Flush prior to this command."
1117 *
1118 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1119 *
1120 * "Driver must ierarchi that all the caches in the depth pipe are
1121 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1122 * requires driver to send a PIPE_CONTROL with a CS stall along with
1123 * a Depth Flush prior to this command.
1124 */
1125 gen6_PIPE_CONTROL(cmd,
1126 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1127 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001128 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001129}
1130
1131static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1132{
1133 CMD_ASSERT(cmd, 6, 7.5);
1134
1135 if (!cmd->bind.draw_count)
1136 return;
1137
1138 /*
1139 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1140 *
1141 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1142 * and a post sync operation prior to the group of depth
1143 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1144 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1145 *
1146 * This workaround satifies all the conditions.
1147 */
1148 cmd_wa_gen6_pre_depth_stall_write(cmd);
1149
1150 /*
1151 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1152 *
1153 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1154 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1155 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1156 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1157 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1158 * Depth Flush Bit set, followed by another pipelined depth stall
1159 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1160 * guarantee that the pipeline from WM onwards is already flushed
1161 * (e.g., via a preceding MI_FLUSH)."
1162 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001163 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1164 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1165 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001166}
1167
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001168void cmd_batch_state_base_address(struct intel_cmd *cmd)
1169{
1170 const uint8_t cmd_len = 10;
1171 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1172 (cmd_len - 2);
1173 uint32_t pos;
1174 uint32_t *dw;
1175
1176 CMD_ASSERT(cmd, 6, 7.5);
1177
1178 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1179
1180 dw[0] = dw0;
1181 /* start offsets */
1182 dw[1] = 1;
1183 dw[2] = 1;
1184 dw[3] = 1;
1185 dw[4] = 1;
1186 dw[5] = 1;
1187 /* end offsets */
1188 dw[6] = 1;
1189 dw[7] = 1 + 0xfffff000;
1190 dw[8] = 1 + 0xfffff000;
1191 dw[9] = 1;
1192
1193 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001194 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1195 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1196 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1197 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1198 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1199 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001200}
1201
Chia-I Wu525c6602014-08-27 10:22:34 +08001202void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1203{
Mike Stroyan552fda42015-01-30 17:21:08 -07001204 if (pipe_control_dw0 == 0)
1205 return;
1206
Chia-I Wu525c6602014-08-27 10:22:34 +08001207 if (!cmd->bind.draw_count)
1208 return;
1209
1210 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1211
Chia-I Wu8370b402014-08-29 12:28:37 +08001212 /*
1213 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1214 *
1215 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1216 * PIPE_CONTROL with any non-zero post-sync-op is required."
1217 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001218 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001219 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001220
Chia-I Wu092279a2014-08-30 19:05:30 +08001221 /*
1222 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1223 *
1224 * "One of the following must also be set (when CS stall is set):
1225 *
1226 * * Render Target Cache Flush Enable ([12] of DW1)
1227 * * Depth Cache Flush Enable ([0] of DW1)
1228 * * Stall at Pixel Scoreboard ([1] of DW1)
1229 * * Depth Stall ([13] of DW1)
1230 * * Post-Sync Operation ([13] of DW1)"
1231 */
1232 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1233 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1234 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1235 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1236 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1237 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1238
Chia-I Wud6d079d2014-08-31 13:14:21 +08001239 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001240}
1241
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001242void cmd_batch_flush_all(struct intel_cmd *cmd)
1243{
1244 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1245 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1246 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1247 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1248 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1249 GEN6_PIPE_CONTROL_CS_STALL);
1250}
1251
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001252void cmd_batch_depth_count(struct intel_cmd *cmd,
1253 struct intel_bo *bo,
1254 XGL_GPU_SIZE offset)
1255{
1256 cmd_wa_gen6_pre_depth_stall_write(cmd);
1257
1258 gen6_PIPE_CONTROL(cmd,
1259 GEN6_PIPE_CONTROL_DEPTH_STALL |
1260 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001261 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001262}
1263
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001264void cmd_batch_timestamp(struct intel_cmd *cmd,
1265 struct intel_bo *bo,
1266 XGL_GPU_SIZE offset)
1267{
1268 /* need any WA or stall? */
1269 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1270}
1271
1272void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001273 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001274 struct intel_bo *bo,
1275 XGL_GPU_SIZE offset,
1276 uint64_t val)
1277{
1278 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001279 gen6_PIPE_CONTROL(cmd,
1280 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1281 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001282}
1283
Chia-I Wu302742d2014-08-22 10:28:29 +08001284static void gen6_cc_states(struct intel_cmd *cmd)
1285{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001286 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1287 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001288 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001289 uint32_t stencil_ref;
1290 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001291
1292 CMD_ASSERT(cmd, 6, 6);
1293
Chia-I Wua6c4f152014-12-02 04:19:58 +08001294 blend_offset = gen6_BLEND_STATE(cmd);
1295
1296 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001297 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001298 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001299 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001300
1301 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001302 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001303 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1304 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001305 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001306 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001307 stencil_ref = 0;
1308 }
1309
Chia-I Wu72292b72014-09-09 10:48:33 +08001310 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001311
Chia-I Wu72292b72014-09-09 10:48:33 +08001312 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001313}
1314
Chia-I Wu1744cca2014-08-22 11:10:17 +08001315static void gen6_viewport_states(struct intel_cmd *cmd)
1316{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001317 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001318 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001319
1320 if (!viewport)
1321 return;
1322
Tony Barbourfa6cac72015-01-16 14:27:35 -07001323 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001324 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001325
1326 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001327 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001328 viewport->cmd);
1329
1330 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001331 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001332 &viewport->cmd[viewport->cmd_clip_pos]);
1333
1334 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001335 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001336 &viewport->cmd[viewport->cmd_cc_pos]);
1337
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001338 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1339 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1340 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001341
1342 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001343 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001344
Chia-I Wub1d450a2014-09-09 13:48:03 +08001345 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001346}
1347
Chia-I Wu302742d2014-08-22 10:28:29 +08001348static void gen7_cc_states(struct intel_cmd *cmd)
1349{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001350 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1351 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001352 uint32_t stencil_ref;
1353 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001354 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001355
1356 CMD_ASSERT(cmd, 7, 7.5);
1357
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001358 if (!blend && !ds)
1359 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001360
Chia-I Wua6c4f152014-12-02 04:19:58 +08001361 offset = gen6_BLEND_STATE(cmd);
1362 gen7_3dstate_pointer(cmd,
1363 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001364
Chia-I Wua6c4f152014-12-02 04:19:58 +08001365 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001366 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001367 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001368 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001369
1370 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001371 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001372 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1373 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001374 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001375 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1376 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001377 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1378 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001379 } else {
1380 stencil_ref = 0;
1381 }
1382
Chia-I Wu72292b72014-09-09 10:48:33 +08001383 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001384 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001385 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001386}
1387
Chia-I Wu1744cca2014-08-22 11:10:17 +08001388static void gen7_viewport_states(struct intel_cmd *cmd)
1389{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001390 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001391 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001392
1393 if (!viewport)
1394 return;
1395
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001396 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001397
Chia-I Wub1d450a2014-09-09 13:48:03 +08001398 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001399 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001400 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001401 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1403 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001404
1405 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001406 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001407 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001408 gen7_3dstate_pointer(cmd,
1409 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001410 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001411
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001412 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1413 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1414 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1415 gen7_3dstate_pointer(cmd,
1416 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1417 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001418}
1419
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001420static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001421 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001422{
1423 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001424 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001425
Chia-I Wu72292b72014-09-09 10:48:33 +08001426 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001427
1428 dw[0] = GEN6_RENDER_TYPE_RENDER |
1429 GEN6_RENDER_SUBTYPE_3D |
1430 subop | (cmd_len - 2);
1431 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001432 dw[2] = 0;
1433 dw[3] = 0;
1434 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001435}
1436
1437static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001438 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001439{
1440 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001441 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001442
Chia-I Wu72292b72014-09-09 10:48:33 +08001443 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001444
1445 dw[0] = GEN6_RENDER_TYPE_RENDER |
1446 GEN6_RENDER_SUBTYPE_3D |
1447 subop | (cmd_len - 2);
1448 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001449 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001450 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001451 dw[4] = 0;
1452 dw[5] = 0;
1453 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001454}
1455
Chia-I Wu625105f2014-10-13 15:35:29 +08001456static uint32_t emit_samplers(struct intel_cmd *cmd,
1457 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001458{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001459 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1460 const uint32_t border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001461 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001462 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001463 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001464 uint32_t surface_count;
1465 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001466
1467 CMD_ASSERT(cmd, 6, 7.5);
1468
Chia-I Wu625105f2014-10-13 15:35:29 +08001469 if (!rmap || !rmap->sampler_count)
1470 return 0;
1471
Cody Northrop40316a32014-12-09 19:08:33 -07001472 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001473
Chia-I Wudcb509d2014-12-10 08:53:10 +08001474 /*
1475 * note that we cannot call cmd_state_pointer() here as the following
1476 * cmd_state_pointer() would invalidate the pointer
1477 */
1478 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001479 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001480 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001481
1482 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001483 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001484 4 * rmap->sampler_count, &sampler_dw);
1485
Chia-I Wudcb509d2014-12-10 08:53:10 +08001486 cmd_state_update(cmd, border_offset,
1487 border_stride * rmap->sampler_count, &border_dw);
1488
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001489 for (i = 0; i < rmap->sampler_count; i++) {
1490 const struct intel_pipeline_rmap_slot *slot =
1491 &rmap->slots[surface_count + i];
1492 const struct intel_sampler *sampler;
1493
Chia-I Wuf8385062015-01-04 16:27:24 +08001494 switch (slot->type) {
1495 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001496 intel_desc_set_read_sampler(set, &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001497 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001498 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001499 sampler = NULL;
1500 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001501 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001502 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001503 sampler = NULL;
1504 break;
1505 }
1506
1507 if (sampler) {
1508 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1509
1510 sampler_dw[0] = sampler->cmd[0];
1511 sampler_dw[1] = sampler->cmd[1];
1512 sampler_dw[2] = border_offset;
1513 sampler_dw[3] = sampler->cmd[2];
1514 } else {
1515 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1516 sampler_dw[1] = 0;
1517 sampler_dw[2] = 0;
1518 sampler_dw[3] = 0;
1519 }
1520
1521 border_offset += border_stride * 4;
1522 border_dw += border_stride;
1523 sampler_dw += 4;
1524 }
1525
Chia-I Wu625105f2014-10-13 15:35:29 +08001526 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001527}
1528
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001529static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001530 const struct intel_pipeline_rmap *rmap,
1531 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001532{
Chia-I Wuf98dd882015-02-10 04:17:47 +08001533 const uint32_t sba_offset =
1534 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001535 const struct intel_desc_set *set = cmd->bind.dset.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001536 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001537 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001538
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001539 CMD_ASSERT(cmd, 6, 7.5);
1540
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001541 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001542 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001543 if (!surface_count)
1544 return 0;
1545
Chia-I Wu42a56202014-08-23 16:47:48 +08001546 assert(surface_count <= ARRAY_SIZE(binding_table));
1547
1548 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001549 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001550 struct intel_null_view null_view;
1551 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001552
Chia-I Wuf8385062015-01-04 16:27:24 +08001553 switch (slot->type) {
1554 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001555 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001556 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001557 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1558 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001559
Chia-I Wu787a05b2014-12-05 11:02:20 +08001560 if (view) {
1561 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1562 GEN6_ALIGNMENT_SURFACE_STATE,
1563 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001564
Chia-I Wu787a05b2014-12-05 11:02:20 +08001565 cmd_reserve_reloc(cmd, 1);
1566 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1567 view->cmd[1], INTEL_RELOC_WRITE);
1568 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001569 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001570 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001571 }
1572 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001573 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001574 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001575 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1576 const struct intel_mem *mem;
1577 bool read_only;
1578 const uint32_t *cmd_data;
1579 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001580
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001581 assert(dyn_idx < 0 ||
1582 dyn_idx < set->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001583
Chia-I Wu2f0cba82015-02-12 10:15:42 -07001584 intel_desc_set_read_surface(set, &slot->u.surface.offset,
1585 stage, &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001586 if (mem) {
1587 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1588 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1589 const uint32_t reloc_flags =
1590 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001591
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001592 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001593 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001594 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001595
1596 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001597 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1598 cmd_data[1] + dynamic_offset, reloc_flags);
1599 } else {
1600 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001601 }
1602 }
1603 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001604 case INTEL_PIPELINE_RMAP_UNUSED:
1605 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001606 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001607 default:
1608 assert(!"unexpected rmap type");
1609 need_null_view = true;
1610 break;
1611 }
1612
1613 if (need_null_view) {
1614 intel_null_view_init(&null_view, cmd->dev);
1615 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1616 GEN6_ALIGNMENT_SURFACE_STATE,
1617 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001618 }
1619
Chia-I Wuf98dd882015-02-10 04:17:47 +08001620 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001621 }
1622
Chia-I Wuf98dd882015-02-10 04:17:47 +08001623 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001624 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001625 surface_count, binding_table) - sba_offset;
1626
1627 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1628 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1629
1630 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001631}
1632
Chia-I Wu1d125092014-10-08 08:49:38 +08001633static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1634{
1635 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001636 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1637 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001638 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001639
1640 CMD_ASSERT(cmd, 6, 7.5);
1641
1642 if (!pipeline->vb_count)
1643 return;
1644
1645 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1646
1647 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1648 dw++;
1649 pos++;
1650
1651 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001652 assert(pipeline->vb[i].strideInBytes <= 2048);
1653
1654 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1655 pipeline->vb[i].strideInBytes;
1656
1657 if (cmd_gen(cmd) >= INTEL_GEN(7))
1658 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1659
1660 switch (pipeline->vb[i].stepRate) {
1661 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1662 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1663 dw[3] = 0;
1664 break;
1665 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1666 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1667 dw[3] = 1;
1668 break;
1669 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1670 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1671 dw[3] = 0;
1672 break;
1673 default:
1674 assert(!"unknown step rate");
1675 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1676 dw[3] = 0;
1677 break;
1678 }
1679
Chia-I Wu714df452015-01-01 07:55:04 +08001680 if (cmd->bind.vertex.buf[i]) {
1681 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001682 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001683
1684 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001685 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1686 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001687 } else {
1688 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1689 dw[1] = 0;
1690 dw[2] = 0;
1691 }
1692
1693 dw += 4;
1694 pos += 4;
1695 }
1696}
1697
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001698static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1699{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001700 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1701 const struct intel_pipeline_shader *vs = &pipeline->vs;
1702 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001703 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001704 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001705 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001706 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001707
1708 CMD_ASSERT(cmd, 6, 7.5);
1709
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001710 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001711 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1712 *
1713 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1714 * 128-bit vertex elements to be passed into the payload for each
1715 * vertex."
1716 *
1717 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1718 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001719 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001720 vue_read_len = (vs->in_count + 1) / 2;
1721 if (!vue_read_len)
1722 vue_read_len = 1;
1723
1724 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1725 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1726
1727 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1728 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1729 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001730
1731 dw5 = GEN6_VS_DW5_STATISTICS |
1732 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001733
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001734 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001735 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001736 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001737 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001738
Chia-I Wube0a3d92014-09-02 13:20:59 +08001739 if (pipeline->disable_vs_cache)
1740 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1741
Chia-I Wu784d3042014-12-19 14:30:04 +08001742 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001743 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001744 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001745 dw[2] = dw2;
1746 dw[3] = 0; /* scratch */
1747 dw[4] = dw4;
1748 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001749
1750 if (vs->per_thread_scratch_size)
1751 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001752}
1753
Chia-I Wu625105f2014-10-13 15:35:29 +08001754static void emit_shader_resources(struct intel_cmd *cmd)
1755{
1756 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001757 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001758
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001759 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001760 cmd->bind.pipeline.graphics->vs.rmap,
1761 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001762 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001763 cmd->bind.pipeline.graphics->tcs.rmap,
1764 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001765 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001766 cmd->bind.pipeline.graphics->tes.rmap,
1767 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001768 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001769 cmd->bind.pipeline.graphics->gs.rmap,
1770 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001771 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001772 cmd->bind.pipeline.graphics->fs.rmap,
1773 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001774
1775 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1776 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1777 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1778 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1779 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1780
1781 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1782 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001783 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1784 binding_tables[0]);
1785 gen7_3dstate_pointer(cmd,
1786 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1787 binding_tables[1]);
1788 gen7_3dstate_pointer(cmd,
1789 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1790 binding_tables[2]);
1791 gen7_3dstate_pointer(cmd,
1792 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1793 binding_tables[3]);
1794 gen7_3dstate_pointer(cmd,
1795 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1796 binding_tables[4]);
1797
1798 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001799 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1800 samplers[0]);
1801 gen7_3dstate_pointer(cmd,
1802 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1803 samplers[1]);
1804 gen7_3dstate_pointer(cmd,
1805 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1806 samplers[2]);
1807 gen7_3dstate_pointer(cmd,
1808 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1809 samplers[3]);
1810 gen7_3dstate_pointer(cmd,
1811 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1812 samplers[4]);
1813 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001814 assert(!binding_tables[1] && !binding_tables[2]);
1815 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1816 binding_tables[0], binding_tables[3], binding_tables[4]);
1817
Chia-I Wu625105f2014-10-13 15:35:29 +08001818 assert(!samplers[1] && !samplers[2]);
1819 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1820 samplers[0], samplers[3], samplers[4]);
1821 }
1822}
1823
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001824static void emit_rt(struct intel_cmd *cmd)
1825{
1826 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001827 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1828 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001829}
1830
1831static void emit_ds(struct intel_cmd *cmd)
1832{
Chia-I Wu73520ac2015-02-19 11:17:45 -07001833 const struct intel_fb *fb = cmd->bind.render_pass->fb;
1834 const struct intel_ds_view *ds = fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001835
1836 if (!ds) {
1837 /* all zeros */
1838 static const struct intel_ds_view null_ds;
1839 ds = &null_ds;
1840 }
1841
1842 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wuc45db532015-02-19 11:20:38 -07001843 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
1844 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, fb->optimal_ds);
1845 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, fb->optimal_ds);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001846
1847 if (cmd_gen(cmd) >= INTEL_GEN(7))
1848 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1849 else
1850 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1851}
1852
Chia-I Wua57761b2014-10-14 14:27:44 +08001853static uint32_t emit_shader(struct intel_cmd *cmd,
1854 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001855{
Chia-I Wua57761b2014-10-14 14:27:44 +08001856 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1857 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001858 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001859
Chia-I Wua57761b2014-10-14 14:27:44 +08001860 /* see if the shader is already in the cache */
1861 for (i = 0; i < cache->used; i++) {
1862 if (cache->entries[i].shader == (const void *) shader)
1863 return cache->entries[i].kernel_offset;
1864 }
1865
1866 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1867
1868 /* grow the cache if full */
1869 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001870 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08001871 void *entries;
1872
1873 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1874 XGL_SYSTEM_ALLOC_INTERNAL);
1875 if (entries) {
1876 if (cache->entries) {
1877 memcpy(entries, cache->entries,
1878 sizeof(cache->entries[0]) * cache->used);
1879 icd_free(cache->entries);
1880 }
1881
1882 cache->entries = entries;
1883 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001884 }
1885 }
1886
Chia-I Wua57761b2014-10-14 14:27:44 +08001887 /* add the shader to the cache */
1888 if (cache->used < cache->count) {
1889 cache->entries[cache->used].shader = (const void *) shader;
1890 cache->entries[cache->used].kernel_offset = offset;
1891 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001892 }
1893
Chia-I Wua57761b2014-10-14 14:27:44 +08001894 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001895}
1896
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001897static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001898{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001899 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001900
Chia-I Wu8370b402014-08-29 12:28:37 +08001901 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1902 cmd_wa_gen6_pre_depth_stall_write(cmd);
1903 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1904 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1905 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1906 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001907
1908 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001909 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001910 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001911
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001912 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001913 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001914 }
1915 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001916 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001917 }
1918 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001919 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1920 }
1921 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1922 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1923 }
1924 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1925 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001926 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001927
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001928 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1929 gen7_3DSTATE_GS(cmd);
1930 } else {
1931 gen6_3DSTATE_GS(cmd);
1932 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001933
Chia-I Wu8370b402014-08-29 12:28:37 +08001934 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1935 cmd_wa_gen7_post_command_cs_stall(cmd);
1936 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1937 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001938}
1939
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001940static void emit_bounded_states(struct intel_cmd *cmd)
1941{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001942
1943 emit_graphics_pipeline(cmd);
1944
1945 emit_rt(cmd);
1946 emit_ds(cmd);
1947
1948 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1949 gen7_cc_states(cmd);
1950 gen7_viewport_states(cmd);
1951
1952 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1953 &cmd->bind.pipeline.graphics->vs);
1954 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1955 &cmd->bind.pipeline.graphics->fs);
1956
1957 gen6_3DSTATE_CLIP(cmd);
1958 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001959 gen7_3DSTATE_WM(cmd);
1960 gen7_3DSTATE_PS(cmd);
1961 } else {
1962 gen6_cc_states(cmd);
1963 gen6_viewport_states(cmd);
1964
1965 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1966 &cmd->bind.pipeline.graphics->vs);
1967 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1968 &cmd->bind.pipeline.graphics->fs);
1969
1970 gen6_3DSTATE_CLIP(cmd);
1971 gen6_3DSTATE_SF(cmd);
1972 gen6_3DSTATE_WM(cmd);
1973 }
1974
1975 emit_shader_resources(cmd);
1976
1977 cmd_wa_gen6_pre_depth_stall_write(cmd);
1978 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1979
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001980 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1981 gen6_3DSTATE_VS(cmd);
1982}
1983
Tony Barbourfa6cac72015-01-16 14:27:35 -07001984static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07001985 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001986{
1987 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1988 const uint8_t cmd_len = 3;
1989 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07001990
1991 CMD_ASSERT(cmd, 6, 7.5);
1992
Tony Barbourfa6cac72015-01-16 14:27:35 -07001993 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07001994 dw[0] = 0;
1995 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07001996
1997 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
1998 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
1999 GEN6_COMPAREFUNCTION_NEVER << 27 |
2000 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2001 } else {
2002 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2003 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2004 }
Chia-I Wud850a392015-02-19 11:08:25 -07002005 } else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
2006 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002007 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2008 (GEN6_STENCILOP_KEEP) << 25 |
2009 (GEN6_STENCILOP_KEEP) << 22 |
2010 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002011 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2012 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002013 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2014 (GEN6_STENCILOP_KEEP) << 9 |
2015 (GEN6_STENCILOP_KEEP) << 6 |
2016 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002017
Chia-I Wud850a392015-02-19 11:08:25 -07002018 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2019 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2020 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2021 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2022 dw[2] = 0;
2023 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002024
2025 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2026 cmd_align, cmd_len, dw);
2027}
2028
Chia-I Wu6032b892014-10-17 14:47:18 +08002029static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2030{
2031 const struct intel_cmd_meta *meta = cmd->bind.meta;
2032 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2033
2034 CMD_ASSERT(cmd, 6, 7.5);
2035
2036 blend_offset = 0;
2037 ds_offset = 0;
2038 cc_offset = 0;
2039 cc_vp_offset = 0;
2040
Chia-I Wu29e6f502014-11-24 14:27:29 +08002041 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002042 /* BLEND_STATE */
2043 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002044 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002045 dw[0] = 0;
2046 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2047 }
2048
Chia-I Wu29e6f502014-11-24 14:27:29 +08002049 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002050 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002051 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002052 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2053 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002054
Chia-I Wu29e6f502014-11-24 14:27:29 +08002055 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002056 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002057
Chia-I Wu29e6f502014-11-24 14:27:29 +08002058 /* COLOR_CALC_STATE */
2059 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002060 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002061
Chia-I Wu29e6f502014-11-24 14:27:29 +08002062 /* CC_VIEWPORT */
2063 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002064 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002065 dw[0] = u_fui(0.0f);
2066 dw[1] = u_fui(1.0f);
2067 } else {
2068 /* DEPTH_STENCIL_STATE */
2069 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002070 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002071 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2072 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2073 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002074 }
2075
2076 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2077 gen7_3dstate_pointer(cmd,
2078 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2079 blend_offset);
2080 gen7_3dstate_pointer(cmd,
2081 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2082 ds_offset);
2083 gen7_3dstate_pointer(cmd,
2084 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2085
2086 gen7_3dstate_pointer(cmd,
2087 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2088 cc_vp_offset);
2089 } else {
2090 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002091 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002092
2093 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2094 cmd_batch_pointer(cmd, 4, &dw);
2095 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2096 GEN6_PTR_VP_DW0_CC_CHANGED;
2097 dw[1] = 0;
2098 dw[2] = 0;
2099 dw[3] = cc_vp_offset;
2100 }
2101}
2102
2103static void gen6_meta_surface_states(struct intel_cmd *cmd)
2104{
2105 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002106 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002107 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002108 const uint32_t sba_offset =
2109 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002110
2111 CMD_ASSERT(cmd, 6, 7.5);
2112
Chia-I Wu29e6f502014-11-24 14:27:29 +08002113 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2114 return;
2115
Chia-I Wu005c47c2014-10-22 13:49:13 +08002116 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002117 if (meta->src.valid) {
2118 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002119 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002120 meta->src.surface_len, meta->src.surface);
2121
2122 cmd_reserve_reloc(cmd, 1);
2123 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2124 cmd_surface_reloc_writer(cmd, offset, 1,
2125 meta->src.reloc_target, meta->src.reloc_offset);
2126 } else {
2127 cmd_surface_reloc(cmd, offset, 1,
2128 (struct intel_bo *) meta->src.reloc_target,
2129 meta->src.reloc_offset, meta->src.reloc_flags);
2130 }
2131
Mike Stroyan9bfad482015-02-10 15:09:23 -07002132 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002133 }
2134 if (meta->dst.valid) {
2135 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002136 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002137 meta->dst.surface_len, meta->dst.surface);
2138
2139 cmd_reserve_reloc(cmd, 1);
2140 cmd_surface_reloc(cmd, offset, 1,
2141 (struct intel_bo *) meta->dst.reloc_target,
2142 meta->dst.reloc_offset, meta->dst.reloc_flags);
2143
Mike Stroyan9bfad482015-02-10 15:09:23 -07002144 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002145 }
2146
2147 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002148 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002149 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002150 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002151
2152 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002153 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2154 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2155 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002156 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002157 } else {
2158 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002159 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002160 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002161 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002162 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002163 }
2164}
2165
2166static void gen6_meta_urb(struct intel_cmd *cmd)
2167{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002168 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002169 uint32_t *dw;
2170
2171 CMD_ASSERT(cmd, 6, 6);
2172
2173 /* 3DSTATE_URB */
2174 cmd_batch_pointer(cmd, 3, &dw);
2175 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002176 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002177 dw[2] = 0;
2178}
2179
2180static void gen7_meta_urb(struct intel_cmd *cmd)
2181{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002182 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2183 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002184 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002185 uint32_t *dw;
2186
2187 CMD_ASSERT(cmd, 7, 7.5);
2188
2189 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2190 cmd_batch_pointer(cmd, 10, &dw);
2191
2192 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002193 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
2194 dw += 2;
2195
2196 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
2197 dw[1] = pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_OFFSET__SHIFT |
2198 pcb_alloc << GEN7_PCB_ALLOC_ANY_DW1_SIZE__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002199 dw += 2;
2200
2201 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2202 dw[1] = 0;
2203 dw += 2;
2204
2205 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2206 dw[1] = 0;
2207 dw += 2;
2208
2209 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2210 dw[1] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002211
Chia-I Wu15dacac2015-02-05 11:14:01 -07002212 cmd_wa_gen7_post_command_cs_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08002213
2214 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2215
Chia-I Wu24aa1022014-11-25 11:53:19 +08002216 switch (cmd_gen(cmd)) {
2217 case INTEL_GEN(7.5):
2218 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2219 break;
2220 case INTEL_GEN(7):
2221 default:
2222 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2223 break;
2224 }
2225
Chia-I Wu6032b892014-10-17 14:47:18 +08002226 /* 3DSTATE_URB_x */
2227 cmd_batch_pointer(cmd, 8, &dw);
2228
2229 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002230 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002231 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002232 dw += 2;
2233
2234 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002235 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002236 dw += 2;
2237
2238 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002239 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002240 dw += 2;
2241
2242 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu15dacac2015-02-05 11:14:01 -07002243 dw[1] = urb_offset << GEN7_URB_ANY_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002244 dw += 2;
2245}
2246
2247static void gen6_meta_vf(struct intel_cmd *cmd)
2248{
2249 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002250 uint32_t vb_start, vb_end, vb_stride;
2251 int ve_format, ve_z_source;
2252 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002253 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002254
2255 CMD_ASSERT(cmd, 6, 7.5);
2256
Chia-I Wu29e6f502014-11-24 14:27:29 +08002257 switch (meta->mode) {
2258 case INTEL_CMD_META_VS_POINTS:
2259 cmd_batch_pointer(cmd, 3, &dw);
2260 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2261 dw[1] = GEN6_VE_STATE_DW0_VALID;
2262 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2263 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2264 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2265 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2266 return;
2267 break;
2268 case INTEL_CMD_META_FS_RECT:
2269 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002270 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002271
Chia-I Wu29e6f502014-11-24 14:27:29 +08002272 vertices[0][0] = meta->dst.x + meta->width;
2273 vertices[0][1] = meta->dst.y + meta->height;
2274 vertices[1][0] = meta->dst.x;
2275 vertices[1][1] = meta->dst.y + meta->height;
2276 vertices[2][0] = meta->dst.x;
2277 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002278
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2280 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002281
Chia-I Wu29e6f502014-11-24 14:27:29 +08002282 vb_end = vb_start + sizeof(vertices) - 1;
2283 vb_stride = sizeof(vertices[0]);
2284 ve_z_source = GEN6_VFCOMP_STORE_0;
2285 ve_format = GEN6_FORMAT_R32G32_USCALED;
2286 }
2287 break;
2288 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2289 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002290 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002291
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002292 vertices[0][0] = (float) (meta->dst.x + meta->width);
2293 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002294 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002295 vertices[1][0] = (float) meta->dst.x;
2296 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002297 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002298 vertices[2][0] = (float) meta->dst.x;
2299 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002300 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002301
Chia-I Wu29e6f502014-11-24 14:27:29 +08002302 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2303 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002304
Chia-I Wu29e6f502014-11-24 14:27:29 +08002305 vb_end = vb_start + sizeof(vertices) - 1;
2306 vb_stride = sizeof(vertices[0]);
2307 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2308 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2309 }
2310 break;
2311 default:
2312 assert(!"unknown meta mode");
2313 return;
2314 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002315 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002316
2317 /* 3DSTATE_VERTEX_BUFFERS */
2318 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002319
Chia-I Wu6032b892014-10-17 14:47:18 +08002320 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002321 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002322 if (cmd_gen(cmd) >= INTEL_GEN(7))
2323 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2324
2325 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002326 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2327 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002328
2329 dw[4] = 0;
2330
2331 /* 3DSTATE_VERTEX_ELEMENTS */
2332 cmd_batch_pointer(cmd, 5, &dw);
2333 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002334 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002335 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2336 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2337 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2338 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2339 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002340 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002341 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2342 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002343 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002344 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2345}
2346
Chia-I Wu29e6f502014-11-24 14:27:29 +08002347static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002348{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002349 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002350 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002351 uint32_t consts[8];
2352 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002353
2354 CMD_ASSERT(cmd, 6, 7.5);
2355
2356 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002357 case INTEL_DEV_META_VS_FILL_MEM:
2358 consts[0] = meta->dst.x;
2359 consts[1] = meta->clear_val[0];
2360 const_count = 2;
2361 break;
2362 case INTEL_DEV_META_VS_COPY_MEM:
2363 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2364 consts[0] = meta->dst.x;
2365 consts[1] = meta->src.x;
2366 const_count = 2;
2367 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002368 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2369 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2370 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2371 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2372 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2373 consts[0] = meta->src.x;
2374 consts[1] = meta->src.y;
2375 consts[2] = meta->width;
2376 consts[3] = meta->dst.x;
2377 const_count = 4;
2378 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002379 default:
2380 assert(!"unknown meta shader id");
2381 const_count = 0;
2382 break;
2383 }
2384
2385 /* this can be skipped but it makes state dumping prettier */
2386 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2387
2388 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2389}
2390
2391static void gen6_meta_vs(struct intel_cmd *cmd)
2392{
2393 const struct intel_cmd_meta *meta = cmd->bind.meta;
2394 const struct intel_pipeline_shader *sh =
2395 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2396 uint32_t offset, *dw;
2397
2398 CMD_ASSERT(cmd, 6, 7.5);
2399
2400 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002401 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002402
2403 /* 3DSTATE_CONSTANT_VS */
2404 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2405 cmd_batch_pointer(cmd, cmd_len, &dw);
2406 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2407 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2408
2409 /* 3DSTATE_VS */
2410 cmd_batch_pointer(cmd, 6, &dw);
2411 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2412 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2413
2414 return;
2415 }
2416
2417 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2418
2419 /* 3DSTATE_CONSTANT_VS */
2420 offset = gen6_meta_vs_constants(cmd);
2421 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2422 cmd_batch_pointer(cmd, 7, &dw);
2423 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2424 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2425 dw[2] = 0;
2426 dw[3] = offset;
2427 dw[4] = 0;
2428 dw[5] = 0;
2429 dw[6] = 0;
2430 } else {
2431 cmd_batch_pointer(cmd, 5, &dw);
2432 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2433 GEN6_PCB_ANY_DW0_PCB0_VALID;
2434 dw[1] = offset;
2435 dw[2] = 0;
2436 dw[3] = 0;
2437 dw[4] = 0;
2438 }
2439
2440 /* 3DSTATE_VS */
2441 offset = emit_shader(cmd, sh);
2442 cmd_batch_pointer(cmd, 6, &dw);
2443 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2444 dw[1] = offset;
2445 dw[2] = GEN6_THREADDISP_SPF |
2446 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2447 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002448 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002449 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2450 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2451
2452 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2453 GEN6_VS_DW5_VS_ENABLE;
2454 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002455 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002456 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002457 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002458
2459 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002460}
2461
2462static void gen6_meta_disabled(struct intel_cmd *cmd)
2463{
Chia-I Wu6032b892014-10-17 14:47:18 +08002464 uint32_t *dw;
2465
2466 CMD_ASSERT(cmd, 6, 6);
2467
Chia-I Wu6032b892014-10-17 14:47:18 +08002468 /* 3DSTATE_CONSTANT_GS */
2469 cmd_batch_pointer(cmd, 5, &dw);
2470 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2471 dw[1] = 0;
2472 dw[2] = 0;
2473 dw[3] = 0;
2474 dw[4] = 0;
2475
2476 /* 3DSTATE_GS */
2477 cmd_batch_pointer(cmd, 7, &dw);
2478 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2479 dw[1] = 0;
2480 dw[2] = 0;
2481 dw[3] = 0;
2482 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2483 dw[5] = GEN6_GS_DW5_STATISTICS;
2484 dw[6] = 0;
2485
Chia-I Wu6032b892014-10-17 14:47:18 +08002486 /* 3DSTATE_SF */
2487 cmd_batch_pointer(cmd, 20, &dw);
2488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2489 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2490 memset(&dw[2], 0, 18 * sizeof(*dw));
2491}
2492
2493static void gen7_meta_disabled(struct intel_cmd *cmd)
2494{
2495 uint32_t *dw;
2496
2497 CMD_ASSERT(cmd, 7, 7.5);
2498
Chia-I Wu6032b892014-10-17 14:47:18 +08002499 /* 3DSTATE_CONSTANT_HS */
2500 cmd_batch_pointer(cmd, 7, &dw);
2501 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2502 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2503
2504 /* 3DSTATE_HS */
2505 cmd_batch_pointer(cmd, 7, &dw);
2506 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2507 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2508
2509 /* 3DSTATE_TE */
2510 cmd_batch_pointer(cmd, 4, &dw);
2511 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2512 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2513
2514 /* 3DSTATE_CONSTANT_DS */
2515 cmd_batch_pointer(cmd, 7, &dw);
2516 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2517 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2518
2519 /* 3DSTATE_DS */
2520 cmd_batch_pointer(cmd, 6, &dw);
2521 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2522 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2523
2524 /* 3DSTATE_CONSTANT_GS */
2525 cmd_batch_pointer(cmd, 7, &dw);
2526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2527 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2528
2529 /* 3DSTATE_GS */
2530 cmd_batch_pointer(cmd, 7, &dw);
2531 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2532 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2533
2534 /* 3DSTATE_STREAMOUT */
2535 cmd_batch_pointer(cmd, 3, &dw);
2536 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2537 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2538
Chia-I Wu6032b892014-10-17 14:47:18 +08002539 /* 3DSTATE_SF */
2540 cmd_batch_pointer(cmd, 7, &dw);
2541 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2542 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2543
2544 /* 3DSTATE_SBE */
2545 cmd_batch_pointer(cmd, 14, &dw);
2546 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2547 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2548 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002549}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002550
Chia-I Wu29e6f502014-11-24 14:27:29 +08002551static void gen6_meta_clip(struct intel_cmd *cmd)
2552{
2553 const struct intel_cmd_meta *meta = cmd->bind.meta;
2554 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002555
Chia-I Wu29e6f502014-11-24 14:27:29 +08002556 /* 3DSTATE_CLIP */
2557 cmd_batch_pointer(cmd, 4, &dw);
2558 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2559 dw[1] = 0;
2560 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2561 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2562 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2563 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002564 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002565 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002566 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002567}
2568
2569static void gen6_meta_wm(struct intel_cmd *cmd)
2570{
2571 const struct intel_cmd_meta *meta = cmd->bind.meta;
2572 uint32_t *dw;
2573
2574 CMD_ASSERT(cmd, 6, 7.5);
2575
2576 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2577
2578 /* 3DSTATE_MULTISAMPLE */
2579 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2580 cmd_batch_pointer(cmd, 4, &dw);
2581 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2582 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2583 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2584 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2585 dw[2] = 0;
2586 dw[3] = 0;
2587 } else {
2588 cmd_batch_pointer(cmd, 3, &dw);
2589 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2590 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2591 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2592 dw[2] = 0;
2593 }
2594
2595 /* 3DSTATE_SAMPLE_MASK */
2596 cmd_batch_pointer(cmd, 2, &dw);
2597 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2598 dw[1] = (1 << meta->samples) - 1;
2599
2600 /* 3DSTATE_DRAWING_RECTANGLE */
2601 cmd_batch_pointer(cmd, 4, &dw);
2602 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002603 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2604 /* unused */
2605 dw[1] = 0;
2606 dw[2] = 0;
2607 } else {
2608 dw[1] = meta->dst.y << 16 | meta->dst.x;
2609 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2610 (meta->dst.x + meta->width - 1);
2611 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002612 dw[3] = 0;
2613}
2614
2615static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2616{
2617 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002618 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002619 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002620 uint32_t consts[8];
2621 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002622
2623 CMD_ASSERT(cmd, 6, 7.5);
2624
2625 /* underflow is fine here */
2626 offset_x = meta->src.x - meta->dst.x;
2627 offset_y = meta->src.y - meta->dst.y;
2628
2629 switch (meta->shader_id) {
2630 case INTEL_DEV_META_FS_COPY_MEM:
2631 case INTEL_DEV_META_FS_COPY_1D:
2632 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2633 case INTEL_DEV_META_FS_COPY_2D:
2634 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2635 case INTEL_DEV_META_FS_COPY_2D_MS:
2636 consts[0] = offset_x;
2637 consts[1] = offset_y;
2638 consts[2] = meta->src.layer;
2639 consts[3] = meta->src.lod;
2640 const_count = 4;
2641 break;
2642 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2643 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2644 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2645 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2646 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2647 consts[0] = offset_x;
2648 consts[1] = offset_y;
2649 consts[2] = meta->src.layer;
2650 consts[3] = meta->src.lod;
2651 consts[4] = meta->src.x;
2652 consts[5] = meta->width;
2653 const_count = 6;
2654 break;
2655 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2656 consts[0] = offset_x;
2657 consts[1] = offset_y;
2658 consts[2] = meta->width;
2659 const_count = 3;
2660 break;
2661 case INTEL_DEV_META_FS_CLEAR_COLOR:
2662 consts[0] = meta->clear_val[0];
2663 consts[1] = meta->clear_val[1];
2664 consts[2] = meta->clear_val[2];
2665 consts[3] = meta->clear_val[3];
2666 const_count = 4;
2667 break;
2668 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2669 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002670 consts[1] = meta->clear_val[1];
2671 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002672 break;
2673 case INTEL_DEV_META_FS_RESOLVE_2X:
2674 case INTEL_DEV_META_FS_RESOLVE_4X:
2675 case INTEL_DEV_META_FS_RESOLVE_8X:
2676 case INTEL_DEV_META_FS_RESOLVE_16X:
2677 consts[0] = offset_x;
2678 consts[1] = offset_y;
2679 const_count = 2;
2680 break;
2681 default:
2682 assert(!"unknown meta shader id");
2683 const_count = 0;
2684 break;
2685 }
2686
2687 /* this can be skipped but it makes state dumping prettier */
2688 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2689
2690 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2691}
2692
2693static void gen6_meta_ps(struct intel_cmd *cmd)
2694{
2695 const struct intel_cmd_meta *meta = cmd->bind.meta;
2696 const struct intel_pipeline_shader *sh =
2697 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2698 uint32_t offset, *dw;
2699
2700 CMD_ASSERT(cmd, 6, 6);
2701
Chia-I Wu29e6f502014-11-24 14:27:29 +08002702 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2703 /* 3DSTATE_CONSTANT_PS */
2704 cmd_batch_pointer(cmd, 5, &dw);
2705 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2706 dw[1] = 0;
2707 dw[2] = 0;
2708 dw[3] = 0;
2709 dw[4] = 0;
2710
2711 /* 3DSTATE_WM */
2712 cmd_batch_pointer(cmd, 9, &dw);
2713 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2714 dw[1] = 0;
2715 dw[2] = 0;
2716 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002717
2718 switch (meta->ds.op) {
2719 case INTEL_CMD_META_DS_HIZ_CLEAR:
2720 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2721 break;
2722 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2723 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2724 break;
2725 case INTEL_CMD_META_DS_RESOLVE:
2726 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2727 break;
2728 default:
2729 dw[4] = 0;
2730 break;
2731 }
2732
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002733 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002734 dw[6] = 0;
2735 dw[7] = 0;
2736 dw[8] = 0;
2737
Chia-I Wu3adf7212014-10-24 15:34:07 +08002738 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002739 }
2740
Chia-I Wu3adf7212014-10-24 15:34:07 +08002741 /* a normal color write */
2742 assert(meta->dst.valid && !sh->uses);
2743
Chia-I Wu6032b892014-10-17 14:47:18 +08002744 /* 3DSTATE_CONSTANT_PS */
2745 offset = gen6_meta_ps_constants(cmd);
2746 cmd_batch_pointer(cmd, 5, &dw);
2747 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2748 GEN6_PCB_ANY_DW0_PCB0_VALID;
2749 dw[1] = offset;
2750 dw[2] = 0;
2751 dw[3] = 0;
2752 dw[4] = 0;
2753
2754 /* 3DSTATE_WM */
2755 offset = emit_shader(cmd, sh);
2756 cmd_batch_pointer(cmd, 9, &dw);
2757 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2758 dw[1] = offset;
2759 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2760 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002761 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002762 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002763 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002764 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002765 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2766
Chia-I Wu6032b892014-10-17 14:47:18 +08002767 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2768 GEN6_WM_DW6_POSOFFSET_NONE |
2769 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2770 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2771 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2772 if (meta->samples > 1) {
2773 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2774 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2775 } else {
2776 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2777 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2778 }
2779 dw[7] = 0;
2780 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002781
2782 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002783}
2784
2785static void gen7_meta_ps(struct intel_cmd *cmd)
2786{
2787 const struct intel_cmd_meta *meta = cmd->bind.meta;
2788 const struct intel_pipeline_shader *sh =
2789 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2790 uint32_t offset, *dw;
2791
2792 CMD_ASSERT(cmd, 7, 7.5);
2793
Chia-I Wu29e6f502014-11-24 14:27:29 +08002794 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2795 /* 3DSTATE_WM */
2796 cmd_batch_pointer(cmd, 3, &dw);
2797 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002798
2799 switch (meta->ds.op) {
2800 case INTEL_CMD_META_DS_HIZ_CLEAR:
2801 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2802 break;
2803 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2804 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2805 break;
2806 case INTEL_CMD_META_DS_RESOLVE:
2807 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2808 break;
2809 default:
2810 dw[1] = 0;
2811 break;
2812 }
2813
2814 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002815
2816 /* 3DSTATE_CONSTANT_GS */
2817 cmd_batch_pointer(cmd, 7, &dw);
2818 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2819 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2820
2821 /* 3DSTATE_PS */
2822 cmd_batch_pointer(cmd, 8, &dw);
2823 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2824 dw[1] = 0;
2825 dw[2] = 0;
2826 dw[3] = 0;
2827 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002828 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002829 dw[5] = 0;
2830 dw[6] = 0;
2831 dw[7] = 0;
2832
Chia-I Wu3adf7212014-10-24 15:34:07 +08002833 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002834 }
2835
Chia-I Wu3adf7212014-10-24 15:34:07 +08002836 /* a normal color write */
2837 assert(meta->dst.valid && !sh->uses);
2838
Chia-I Wu6032b892014-10-17 14:47:18 +08002839 /* 3DSTATE_WM */
2840 cmd_batch_pointer(cmd, 3, &dw);
2841 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2842 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2843 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2844 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2845 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2846 dw[2] = 0;
2847
2848 /* 3DSTATE_CONSTANT_PS */
2849 offset = gen6_meta_ps_constants(cmd);
2850 cmd_batch_pointer(cmd, 7, &dw);
2851 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2852 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2853 dw[2] = 0;
2854 dw[3] = offset;
2855 dw[4] = 0;
2856 dw[5] = 0;
2857 dw[6] = 0;
2858
2859 /* 3DSTATE_PS */
2860 offset = emit_shader(cmd, sh);
2861 cmd_batch_pointer(cmd, 8, &dw);
2862 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2863 dw[1] = offset;
2864 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2865 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002866 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002867
2868 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2869 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002870 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2871
2872 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002873 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002874 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002875 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002876 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002877 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002878
2879 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2880 dw[6] = 0;
2881 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002882
2883 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002884}
2885
2886static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2887{
2888 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002889 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002890
2891 CMD_ASSERT(cmd, 6, 7.5);
2892
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002893 if (!ds) {
2894 /* all zeros */
2895 static const struct intel_ds_view null_ds;
2896 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002897 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002898
2899 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002900 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
2901 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds, meta->ds.optimal);
2902 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002903
2904 if (cmd_gen(cmd) >= INTEL_GEN(7))
2905 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2906 else
2907 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002908}
2909
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002910static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2911 const struct intel_pipeline *pipeline)
2912{
2913 cmd->bind.pipeline.graphics = pipeline;
2914}
2915
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002916static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2917 const struct intel_pipeline *pipeline)
2918{
2919 cmd->bind.pipeline.compute = pipeline;
2920}
2921
2922static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2923 const struct intel_pipeline_delta *delta)
2924{
2925 cmd->bind.pipeline.graphics_delta = delta;
2926}
2927
2928static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2929 const struct intel_pipeline_delta *delta)
2930{
2931 cmd->bind.pipeline.compute_delta = delta;
2932}
2933
2934static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002935 const struct intel_desc_set *dset,
2936 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002937{
Chia-I Wuf8385062015-01-04 16:27:24 +08002938 const uint32_t size = sizeof(*dynamic_offsets) *
2939 dset->layout->dynamic_desc_count;
2940
2941 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2942 if (cmd->bind.dset.graphics_dynamic_offsets)
2943 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2944
2945 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2946 4, XGL_SYSTEM_ALLOC_INTERNAL);
2947 if (!cmd->bind.dset.graphics_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002948 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002949 return;
2950 }
2951
2952 cmd->bind.dset.graphics_dynamic_offset_size = size;
2953 }
2954
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002955 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002956 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002957}
2958
2959static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002960 const struct intel_desc_set *dset,
2961 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002962{
Chia-I Wuf8385062015-01-04 16:27:24 +08002963 const uint32_t size = sizeof(*dynamic_offsets) *
2964 dset->layout->dynamic_desc_count;
2965
2966 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2967 if (cmd->bind.dset.compute_dynamic_offsets)
2968 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2969
2970 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2971 4, XGL_SYSTEM_ALLOC_INTERNAL);
2972 if (!cmd->bind.dset.compute_dynamic_offsets) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002973 cmd_fail(cmd, XGL_ERROR_OUT_OF_MEMORY);
Chia-I Wuf8385062015-01-04 16:27:24 +08002974 return;
2975 }
2976
2977 cmd->bind.dset.compute_dynamic_offset_size = size;
2978 }
2979
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002980 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002981 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002982}
2983
Chia-I Wu3b04af52014-11-08 10:48:20 +08002984static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002985 const struct intel_buf *buf,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002986 XGL_GPU_SIZE offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08002987{
Chia-I Wu714df452015-01-01 07:55:04 +08002988 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu4e5577a2015-02-10 11:04:44 -07002989 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08002990 return;
2991 }
2992
Chia-I Wu714df452015-01-01 07:55:04 +08002993 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002994 cmd->bind.vertex.offset[binding] = offset;
2995}
2996
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002997static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002998 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002999 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
3000{
Chia-I Wu714df452015-01-01 07:55:04 +08003001 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003002 cmd->bind.index.offset = offset;
3003 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003004}
3005
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003006static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003007 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003008{
3009 cmd->bind.state.viewport = state;
3010}
3011
3012static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003013 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003014{
3015 cmd->bind.state.raster = state;
3016}
3017
3018static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003019 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003020{
3021 cmd->bind.state.ds = state;
3022}
3023
3024static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003025 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003026{
3027 cmd->bind.state.blend = state;
3028}
3029
Chia-I Wuf98dd882015-02-10 04:17:47 +08003030static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3031{
3032 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3033 struct intel_pipeline_rmap *rmaps[5] = {
3034 pipeline->vs.rmap,
3035 pipeline->tcs.rmap,
3036 pipeline->tes.rmap,
3037 pipeline->gs.rmap,
3038 pipeline->fs.rmap,
3039 };
3040 uint32_t max_write;
3041 int i;
3042
3043 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3044 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3045 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3046
3047 /* pad first */
3048 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3049
3050 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3051 const struct intel_pipeline_rmap *rmap = rmaps[i];
3052 const uint32_t surface_count = (rmap) ?
3053 rmap->rt_count + rmap->texture_resource_count +
3054 rmap->resource_count + rmap->uav_count : 0;
3055
3056 if (surface_count) {
3057 /* SURFACE_STATEs */
3058 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3059
3060 /* BINDING_TABLE_STATE */
3061 max_write += u_align(sizeof(uint32_t) * surface_count,
3062 GEN6_ALIGNMENT_SURFACE_STATE);
3063 }
3064 }
3065
3066 return max_write;
3067}
3068
3069static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3070{
3071 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3072 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3073 uint32_t max_surface_write;
3074
3075 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3076 if (cmd->bind.meta)
3077 max_surface_write = 64 * sizeof(uint32_t);
3078 else
3079 max_surface_write = cmd_get_max_surface_write(cmd);
3080
3081 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3082 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3083 /* SBA expects page-aligned addresses */
3084 writer->sba_offset = writer->used & ~0xfff;
3085
3086 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3087
3088 cmd_batch_state_base_address(cmd);
3089 }
3090}
3091
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003092static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003093 uint32_t vertex_start,
3094 uint32_t vertex_count,
3095 uint32_t instance_start,
3096 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003097 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003098 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003099{
3100 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003101 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003102 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3103
3104 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003105
3106 emit_bounded_states(cmd);
3107
Chia-I Wuf98dd882015-02-10 04:17:47 +08003108 /* sanity check on cmd_get_max_surface_write() */
3109 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3110 surface_writer_used <= cmd_get_max_surface_write(cmd));
3111
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003112 if (indexed) {
3113 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003114 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003115
3116 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3117 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3118 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003119 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003120 cmd->bind.index.offset, cmd->bind.index.type,
3121 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003122 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003123 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003124 cmd->bind.index.offset, cmd->bind.index.type,
3125 p->primitive_restart);
3126 }
3127 } else {
3128 assert(!vertex_base);
3129 }
3130
3131 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3132 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3133 vertex_start, instance_count, instance_start, vertex_base);
3134 } else {
3135 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3136 vertex_start, instance_count, instance_start, vertex_base);
3137 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003138
Chia-I Wu707a29e2014-08-27 12:51:47 +08003139 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003140 /* need to re-emit all workarounds */
3141 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003142
3143 if (intel_debug & INTEL_DEBUG_NOCACHE)
3144 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003145}
3146
Chia-I Wuc14d1562014-10-17 09:49:22 +08003147void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3148{
Chia-I Wu6032b892014-10-17 14:47:18 +08003149 cmd->bind.meta = meta;
3150
Chia-I Wuf98dd882015-02-10 04:17:47 +08003151 cmd_adjust_state_base_address(cmd);
3152
Chia-I Wu6032b892014-10-17 14:47:18 +08003153 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003154 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003155
3156 gen6_meta_dynamic_states(cmd);
3157 gen6_meta_surface_states(cmd);
3158
3159 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3160 gen7_meta_urb(cmd);
3161 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003162 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003163 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003164 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003165 gen6_meta_wm(cmd);
3166 gen7_meta_ps(cmd);
3167 gen6_meta_depth_buffer(cmd);
3168
3169 cmd_wa_gen7_post_command_cs_stall(cmd);
3170 cmd_wa_gen7_post_command_depth_stall(cmd);
3171
Chia-I Wu29e6f502014-11-24 14:27:29 +08003172 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3173 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003174 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003175 } else {
3176 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3177 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003178 } else {
3179 gen6_meta_urb(cmd);
3180 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003181 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003182 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003183 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003184 gen6_meta_wm(cmd);
3185 gen6_meta_ps(cmd);
3186 gen6_meta_depth_buffer(cmd);
3187
Chia-I Wu29e6f502014-11-24 14:27:29 +08003188 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3189 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003190 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003191 } else {
3192 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3193 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003194 }
3195
3196 cmd->bind.draw_count++;
3197 /* need to re-emit all workarounds */
3198 cmd->bind.wa_flags = 0;
3199
3200 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003201
3202 if (intel_debug & INTEL_DEBUG_NOCACHE)
3203 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003204}
3205
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003206ICD_EXPORT void XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003207 XGL_CMD_BUFFER cmdBuffer,
3208 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3209 XGL_PIPELINE pipeline)
3210{
3211 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3212
3213 switch (pipelineBindPoint) {
3214 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003216 break;
3217 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003218 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003219 break;
3220 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003221 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003222 break;
3223 }
3224}
3225
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003226ICD_EXPORT void XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003227 XGL_CMD_BUFFER cmdBuffer,
3228 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3229 XGL_PIPELINE_DELTA delta)
3230{
3231 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3232
3233 switch (pipelineBindPoint) {
3234 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003235 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003236 break;
3237 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003238 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003239 break;
3240 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003241 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003242 break;
3243 }
3244}
3245
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003246ICD_EXPORT void XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003247 XGL_CMD_BUFFER cmdBuffer,
3248 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003249 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003250{
3251 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3252
3253 switch (stateBindPoint) {
3254 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003255 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003256 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003257 break;
3258 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003259 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003260 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003261 break;
3262 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003263 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003264 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003265 break;
3266 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003267 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003268 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003269 break;
3270 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003271 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003272 break;
3273 }
3274}
3275
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003276ICD_EXPORT void XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003277 XGL_CMD_BUFFER cmdBuffer,
3278 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003279 XGL_DESCRIPTOR_SET descriptorSet,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003280 const uint32_t* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003281{
3282 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003283 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003284
3285 switch (pipelineBindPoint) {
3286 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003287 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003288 break;
3289 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003290 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003291 break;
3292 default:
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003293 cmd_fail(cmd, XGL_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003294 break;
3295 }
3296}
3297
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003298ICD_EXPORT void XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003299 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003300 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003301 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003302 uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003303{
3304 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003305 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003306
Chia-I Wu714df452015-01-01 07:55:04 +08003307 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003308}
3309
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003310ICD_EXPORT void XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003311 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003312 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003313 XGL_GPU_SIZE offset,
3314 XGL_INDEX_TYPE indexType)
3315{
3316 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003317 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003318
Chia-I Wu714df452015-01-01 07:55:04 +08003319 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003320}
3321
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003322ICD_EXPORT void XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003323 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003324 uint32_t firstVertex,
3325 uint32_t vertexCount,
3326 uint32_t firstInstance,
3327 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003328{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003329 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003330
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003331 cmd_draw(cmd, firstVertex, vertexCount,
3332 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003333}
3334
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003335ICD_EXPORT void XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003336 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003337 uint32_t firstIndex,
3338 uint32_t indexCount,
3339 int32_t vertexOffset,
3340 uint32_t firstInstance,
3341 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003342{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003343 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003344
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003345 cmd_draw(cmd, firstIndex, indexCount,
3346 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003347}
3348
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003349ICD_EXPORT void XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003350 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003351 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003352 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003353 uint32_t count,
3354 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003355{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003356 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3357
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003358 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003359}
3360
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003361ICD_EXPORT void XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003362 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003363 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003364 XGL_GPU_SIZE offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003365 uint32_t count,
3366 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003367{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003368 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3369
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003370 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003371}
3372
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003373ICD_EXPORT void XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003374 XGL_CMD_BUFFER cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003375 uint32_t x,
3376 uint32_t y,
3377 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003378{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003379 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3380
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003381 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003382}
3383
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003384ICD_EXPORT void XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003385 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003386 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003387 XGL_GPU_SIZE offset)
3388{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003389 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3390
Chia-I Wu4e5577a2015-02-10 11:04:44 -07003391 cmd_fail(cmd, XGL_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003392}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003393
Chia-I Wude26bdf2015-02-18 15:47:12 -07003394ICD_EXPORT void XGLAPI xglCmdBeginRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003395 XGL_CMD_BUFFER cmdBuffer,
3396 XGL_RENDER_PASS renderPass)
3397{
3398 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3399
3400 cmd_begin_render_pass(cmd, (struct intel_render_pass *) renderPass);
3401}
3402
Chia-I Wude26bdf2015-02-18 15:47:12 -07003403ICD_EXPORT void XGLAPI xglCmdEndRenderPass(
Chia-I Wub5af7c52015-02-18 14:51:59 -07003404 XGL_CMD_BUFFER cmdBuffer,
3405 XGL_RENDER_PASS renderPass)
3406{
3407 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3408
3409 cmd_end_render_pass(cmd, (struct intel_render_pass *) renderPass);
3410}