blob: aa03f666a846b1e22621d1abb903d1ed7e4d14da [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;
109 XGL_UINT 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;
Chia-I Wu72292b72014-09-09 10:48:33 +0800247 XGL_UINT pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800248
249 CMD_ASSERT(cmd, 6, 7.5);
250
Chia-I Wu426072d2014-08-26 14:31:55 +0800251 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800252
253 /* the bit is moved to 3DSTATE_VF */
254 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
255 assert(!enable_cut_index);
256 if (enable_cut_index)
257 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
258
259 switch (type) {
260 case XGL_INDEX_8:
261 dw0 |= GEN6_IB_DW0_FORMAT_BYTE;
262 offset_align = 1;
263 break;
264 case XGL_INDEX_16:
265 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
266 offset_align = 2;
267 break;
268 case XGL_INDEX_32:
269 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
270 offset_align = 4;
271 break;
272 default:
273 cmd->result = XGL_ERROR_INVALID_VALUE;
274 return;
275 break;
276 }
277
278 if (offset % offset_align) {
279 cmd->result = XGL_ERROR_INVALID_VALUE;
280 return;
281 }
282
283 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800284 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
287 dw[0] = dw0;
288
289 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800290 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
291 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800292}
293
Chia-I Wu62a7f252014-08-29 11:31:16 +0800294static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
295 bool enable_cut_index,
296 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800297{
298 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800299 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800300
301 CMD_ASSERT(cmd, 7.5, 7.5);
302
Chia-I Wu426072d2014-08-26 14:31:55 +0800303 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800304 if (enable_cut_index)
305 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
306
Chia-I Wu72292b72014-09-09 10:48:33 +0800307 cmd_batch_pointer(cmd, cmd_len, &dw);
308 dw[0] = dw0;
309 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800310}
311
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600312
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800313static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
314{
315 const uint8_t cmd_len = 7;
316 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800317 uint32_t *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800318
319 CMD_ASSERT(cmd, 6, 6);
320
Chia-I Wu72292b72014-09-09 10:48:33 +0800321 cmd_batch_pointer(cmd, cmd_len, &dw);
322 dw[0] = dw0;
323 dw[1] = 0;
324 dw[2] = 0;
325 dw[3] = 0;
326 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
327 dw[5] = GEN6_GS_DW5_STATISTICS;
328 dw[6] = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329}
330
Chia-I Wu62a7f252014-08-29 11:31:16 +0800331static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
332{
333 const uint8_t cmd_len = 7;
334 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800335 uint32_t *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800336
337 CMD_ASSERT(cmd, 7, 7.5);
338
Chia-I Wu72292b72014-09-09 10:48:33 +0800339 cmd_batch_pointer(cmd, cmd_len, &dw);
340 dw[0] = dw0;
341 dw[1] = 0;
342 dw[2] = 0;
343 dw[3] = 0;
344 dw[4] = 0;
345 dw[5] = GEN6_GS_DW5_STATISTICS;
346 dw[6] = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800347}
348
Chia-I Wud88e02d2014-08-25 10:56:13 +0800349static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
350 XGL_UINT width, XGL_UINT height)
351{
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
394 switch (pipeline->db_format.channelFormat) {
395 case XGL_CH_FMT_R16:
396 format = GEN6_ZFORMAT_D16_UNORM;
397 break;
398 case XGL_CH_FMT_R32:
399 case XGL_CH_FMT_R32G8:
400 format = GEN6_ZFORMAT_D32_FLOAT;
401 break;
402 default:
Jeremy Hayese0c3b222015-01-14 16:17:08 -0700403 assert(!cmd->bind.render_pass->fb->ds); // Must have valid format if ds attached
Chia-I Wu8016a172014-08-29 18:31:32 +0800404 format = 0;
405 break;
406 }
407
408 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
409 }
410
Tony Barbourfa6cac72015-01-16 14:27:35 -0700411 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800412
Tony Barbourfa6cac72015-01-16 14:27:35 -0700413 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800414 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
415 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
416 } else {
417 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
418 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
419 }
420
Tony Barbourfa6cac72015-01-16 14:27:35 -0700421 if (pipeline->scissor_enable)
Chia-I Wu8016a172014-08-29 18:31:32 +0800422 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
423
424 /* in U8.3 */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700425 point_width = (int) (raster->rs_info.pointSize * 8.0f + 0.5f);
Chia-I Wu8016a172014-08-29 18:31:32 +0800426 point_width = U_CLAMP(point_width, 1, 2047);
427
428 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
429 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
430 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
431 GEN7_SF_DW3_SUBPIXEL_8BITS |
432 GEN7_SF_DW3_USE_POINT_WIDTH |
433 point_width;
434
435 body[0] = dw1;
436 body[1] = dw2;
437 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700438 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
439 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
440 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800441}
442
443static void gen7_fill_3DSTATE_SBE_body(const struct intel_cmd *cmd,
444 uint32_t body[13])
445{
GregF8cd81832014-11-18 18:01:01 -0700446 XGL_UINT sbe_offset;
447 XGL_INT i;
Chia-I Wu8016a172014-08-29 18:31:32 +0800448
449 CMD_ASSERT(cmd, 6, 7.5);
450
GregF8cd81832014-11-18 18:01:01 -0700451 sbe_offset = cmd->bind.pipeline.graphics->cmd_sbe_body_offset;
Chia-I Wu8016a172014-08-29 18:31:32 +0800452
GregF8cd81832014-11-18 18:01:01 -0700453 for (i = 0; i < 13; i++) {
454 uint32_t b = cmd->bind.pipeline.graphics->cmds[sbe_offset + i];
455 body[i] = b;
Chia-I Wu8016a172014-08-29 18:31:32 +0800456 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800457}
458
459static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
460{
461 const uint8_t cmd_len = 20;
462 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
463 (cmd_len - 2);
464 uint32_t sf[6];
465 uint32_t sbe[13];
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800467
468 CMD_ASSERT(cmd, 6, 6);
469
470 gen7_fill_3DSTATE_SF_body(cmd, sf);
471 gen7_fill_3DSTATE_SBE_body(cmd, sbe);
472
Chia-I Wu72292b72014-09-09 10:48:33 +0800473 cmd_batch_pointer(cmd, cmd_len, &dw);
474 dw[0] = dw0;
475 dw[1] = sbe[0];
476 memcpy(&dw[2], sf, sizeof(sf));
477 memcpy(&dw[8], &sbe[1], sizeof(sbe) - sizeof(sbe[0]));
Chia-I Wu8016a172014-08-29 18:31:32 +0800478}
479
480static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
481{
482 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800483 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 7, 7.5);
486
Chia-I Wu72292b72014-09-09 10:48:33 +0800487 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800488 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
489 (cmd_len - 2);
490 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800491}
492
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800493static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
494{
495 const uint8_t cmd_len = 4;
496 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
497 (cmd_len - 2);
498 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700499 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800500 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700501 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800502 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800503
504 CMD_ASSERT(cmd, 6, 7.5);
505
506 dw1 = GEN6_CLIP_DW1_STATISTICS;
507 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
508 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
509 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800511 }
512
513 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
514 GEN6_CLIP_DW2_XY_TEST_ENABLE |
515 GEN6_CLIP_DW2_APIMODE_OGL |
GregFfd4c1f92014-11-07 15:32:52 -0700516 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800517 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
518 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
519 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
520
521 if (pipeline->rasterizerDiscardEnable)
522 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
523 else
524 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
525
526 if (pipeline->depthClipEnable)
527 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
528
529 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
530 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
531 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
532 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
533
534 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
535 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
536 (viewport->viewport_count - 1);
537
Chia-I Wu72292b72014-09-09 10:48:33 +0800538 cmd_batch_pointer(cmd, cmd_len, &dw);
539 dw[0] = dw0;
540 dw[1] = dw1;
541 dw[2] = dw2;
542 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800543}
544
Chia-I Wu784d3042014-12-19 14:30:04 +0800545static void gen6_add_scratch_space(struct intel_cmd *cmd,
546 XGL_UINT batch_pos,
547 const struct intel_pipeline *pipeline,
548 const struct intel_pipeline_shader *sh)
549{
550 int scratch_space;
551
552 CMD_ASSERT(cmd, 6, 7.5);
553
554 assert(sh->per_thread_scratch_size &&
555 sh->per_thread_scratch_size % 1024 == 0 &&
556 u_is_pow2(sh->per_thread_scratch_size) &&
557 sh->scratch_offset % 1024 == 0);
558 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
559
560 cmd_reserve_reloc(cmd, 1);
561 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
562 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
563}
564
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800565static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
566{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800567 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800568 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800569 const uint8_t cmd_len = 9;
Chia-I Wu784d3042014-12-19 14:30:04 +0800570 XGL_UINT pos;
Chia-I Wu72292b72014-09-09 10:48:33 +0800571 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800572
573 CMD_ASSERT(cmd, 6, 6);
574
575 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
576
577 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
578 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
579
580 dw4 = GEN6_WM_DW4_STATISTICS |
581 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
582 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
583 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
584
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800585 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800586 GEN6_WM_DW5_PS_ENABLE |
587 GEN6_WM_DW5_8_PIXEL_DISPATCH;
588
589 if (fs->uses & INTEL_SHADER_USE_KILL ||
590 pipeline->cb_state.alphaToCoverageEnable)
591 dw5 |= GEN6_WM_DW5_PS_KILL;
592
Cody Northrope238deb2015-01-26 14:41:36 -0700593 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800594 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
595 if (fs->uses & INTEL_SHADER_USE_DEPTH)
596 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
597 if (fs->uses & INTEL_SHADER_USE_W)
598 dw5 |= GEN6_WM_DW5_PS_USE_W;
599
600 if (pipeline->cb_state.dualSourceBlendEnable)
601 dw5 |= GEN6_WM_DW5_DUAL_SOURCE_BLEND;
602
603 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
604 GEN6_WM_DW6_POSOFFSET_NONE |
605 GEN6_WM_DW6_ZW_INTERP_PIXEL |
606 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
607 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
608
Tony Barbourfa6cac72015-01-16 14:27:35 -0700609 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800610 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
611 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
612 } else {
613 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
614 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
615 }
616
Chia-I Wu784d3042014-12-19 14:30:04 +0800617 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800618 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800619 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800620 dw[2] = dw2;
621 dw[3] = 0; /* scratch */
622 dw[4] = dw4;
623 dw[5] = dw5;
624 dw[6] = dw6;
625 dw[7] = 0; /* kernel 1 */
626 dw[8] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800627
628 if (fs->per_thread_scratch_size)
629 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630}
631
632static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
633{
634 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800635 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800636 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800637 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638
639 CMD_ASSERT(cmd, 7, 7.5);
640
641 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
642
643 dw1 = GEN7_WM_DW1_STATISTICS |
644 GEN7_WM_DW1_PS_ENABLE |
645 GEN7_WM_DW1_ZW_INTERP_PIXEL |
646 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
647 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
648
649 if (fs->uses & INTEL_SHADER_USE_KILL ||
650 pipeline->cb_state.alphaToCoverageEnable)
651 dw1 |= GEN7_WM_DW1_PS_KILL;
652
Cody Northrope238deb2015-01-26 14:41:36 -0700653 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_DEPTH)
656 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
657 if (fs->uses & INTEL_SHADER_USE_W)
658 dw1 |= GEN7_WM_DW1_PS_USE_W;
659
660 dw2 = 0;
661
Tony Barbourfa6cac72015-01-16 14:27:35 -0700662 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
664 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
665 } else {
666 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
667 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
668 }
669
Chia-I Wu72292b72014-09-09 10:48:33 +0800670 cmd_batch_pointer(cmd, cmd_len, &dw);
671 dw[0] = dw0;
672 dw[1] = dw1;
673 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674}
675
676static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
677{
678 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800679 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800680 const uint8_t cmd_len = 8;
Chia-I Wu72292b72014-09-09 10:48:33 +0800681 uint32_t dw0, dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +0800682 XGL_UINT pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683
684 CMD_ASSERT(cmd, 7, 7.5);
685
686 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
687
688 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
689 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
690
691 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
692 GEN7_PS_DW4_8_PIXEL_DISPATCH;
693
694 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800695 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700696 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800697 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800698 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800699 }
700
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701 if (fs->in_count)
702 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
703
704 if (pipeline->cb_state.dualSourceBlendEnable)
705 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
706
707 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
708 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
709 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
710
Chia-I Wu784d3042014-12-19 14:30:04 +0800711 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800712 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800713 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800714 dw[2] = dw2;
715 dw[3] = 0; /* scratch */
716 dw[4] = dw4;
717 dw[5] = dw5;
718 dw[6] = 0; /* kernel 1 */
719 dw[7] = 0; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800720
721 if (fs->per_thread_scratch_size)
722 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723}
724
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800725static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
726 const struct intel_ds_view *view)
727{
728 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800729 uint32_t dw0, *dw;
730 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800731
732 CMD_ASSERT(cmd, 6, 7.5);
733
734 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800735 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
736 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800737 dw0 |= (cmd_len - 2);
738
Chia-I Wu72292b72014-09-09 10:48:33 +0800739 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
740 dw[0] = dw0;
741 dw[1] = view->cmd[0];
742 dw[2] = 0;
743 dw[3] = view->cmd[2];
744 dw[4] = view->cmd[3];
745 dw[5] = view->cmd[4];
746 dw[6] = view->cmd[5];
747
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600748 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800749 cmd_reserve_reloc(cmd, 1);
750 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
751 view->cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600752 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800753}
754
755static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
756 const struct intel_ds_view *view)
757{
758 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800759 uint32_t dw0, *dw;
760 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800761
762 CMD_ASSERT(cmd, 6, 7.5);
763
764 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800765 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
766 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800767 dw0 |= (cmd_len - 2);
768
Chia-I Wu72292b72014-09-09 10:48:33 +0800769 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
770 dw[0] = dw0;
771 dw[1] = view->cmd[6];
772 dw[2] = 0;
773
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600774 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800775 cmd_reserve_reloc(cmd, 1);
776 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
777 view->cmd[7], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600778 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800779}
780
781static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
782 const struct intel_ds_view *view)
783{
784 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 uint32_t dw0, *dw;
786 XGL_UINT pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800787
788 CMD_ASSERT(cmd, 6, 7.5);
789
790 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800791 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
792 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800793 dw0 |= (cmd_len - 2);
794
Chia-I Wu72292b72014-09-09 10:48:33 +0800795 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
796 dw[0] = dw0;
797 dw[1] = view->cmd[8];
798 dw[2] = 0;
799
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600800 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800801 cmd_reserve_reloc(cmd, 1);
802 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
803 view->cmd[9], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600804 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800805}
806
Chia-I Wuf8231032014-08-25 10:44:45 +0800807static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
808 uint32_t clear_val)
809{
810 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800811 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800812 GEN6_CLEAR_PARAMS_DW0_VALID |
813 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800814 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800815
816 CMD_ASSERT(cmd, 6, 6);
817
Chia-I Wu72292b72014-09-09 10:48:33 +0800818 cmd_batch_pointer(cmd, cmd_len, &dw);
819 dw[0] = dw0;
820 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800821}
822
823static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
824 uint32_t clear_val)
825{
826 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800827 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800828 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800829 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800830
831 CMD_ASSERT(cmd, 7, 7.5);
832
Chia-I Wu72292b72014-09-09 10:48:33 +0800833 cmd_batch_pointer(cmd, cmd_len, &dw);
834 dw[0] = dw0;
835 dw[1] = clear_val;
836 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800837}
838
Chia-I Wu302742d2014-08-22 10:28:29 +0800839static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 uint32_t blend_offset,
841 uint32_t ds_offset,
842 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800843{
844 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800845 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800846
847 CMD_ASSERT(cmd, 6, 6);
848
Chia-I Wu426072d2014-08-26 14:31:55 +0800849 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800850 (cmd_len - 2);
851
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 cmd_batch_pointer(cmd, cmd_len, &dw);
853 dw[0] = dw0;
854 dw[1] = blend_offset | 1;
855 dw[2] = ds_offset | 1;
856 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800857}
858
Chia-I Wu1744cca2014-08-22 11:10:17 +0800859static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800860 uint32_t clip_offset,
861 uint32_t sf_offset,
862 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800863{
864 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800866
867 CMD_ASSERT(cmd, 6, 6);
868
Chia-I Wu426072d2014-08-26 14:31:55 +0800869 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800870 GEN6_PTR_VP_DW0_CLIP_CHANGED |
871 GEN6_PTR_VP_DW0_SF_CHANGED |
872 GEN6_PTR_VP_DW0_CC_CHANGED |
873 (cmd_len - 2);
874
Chia-I Wu72292b72014-09-09 10:48:33 +0800875 cmd_batch_pointer(cmd, cmd_len, &dw);
876 dw[0] = dw0;
877 dw[1] = clip_offset;
878 dw[2] = sf_offset;
879 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800880}
881
882static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800883 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800884{
885 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800887
888 CMD_ASSERT(cmd, 6, 6);
889
Chia-I Wu426072d2014-08-26 14:31:55 +0800890 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800891 (cmd_len - 2);
892
Chia-I Wu72292b72014-09-09 10:48:33 +0800893 cmd_batch_pointer(cmd, cmd_len, &dw);
894 dw[0] = dw0;
895 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800896}
897
Chia-I Wu42a56202014-08-23 16:47:48 +0800898static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800899 uint32_t vs_offset,
900 uint32_t gs_offset,
901 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +0800902{
903 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +0800905
906 CMD_ASSERT(cmd, 6, 6);
907
Chia-I Wu426072d2014-08-26 14:31:55 +0800908 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu42a56202014-08-23 16:47:48 +0800909 GEN6_PTR_BINDING_TABLE_DW0_VS_CHANGED |
910 GEN6_PTR_BINDING_TABLE_DW0_GS_CHANGED |
911 GEN6_PTR_BINDING_TABLE_DW0_PS_CHANGED |
912 (cmd_len - 2);
913
Chia-I Wu72292b72014-09-09 10:48:33 +0800914 cmd_batch_pointer(cmd, cmd_len, &dw);
915 dw[0] = dw0;
916 dw[1] = vs_offset;
917 dw[2] = gs_offset;
918 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +0800919}
920
Chia-I Wu257e75e2014-08-29 14:06:35 +0800921static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 uint32_t vs_offset,
923 uint32_t gs_offset,
924 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +0800925{
926 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800928
929 CMD_ASSERT(cmd, 6, 6);
930
931 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
932 GEN6_PTR_SAMPLER_DW0_VS_CHANGED |
933 GEN6_PTR_SAMPLER_DW0_GS_CHANGED |
934 GEN6_PTR_SAMPLER_DW0_PS_CHANGED |
935 (cmd_len - 2);
936
Chia-I Wu72292b72014-09-09 10:48:33 +0800937 cmd_batch_pointer(cmd, cmd_len, &dw);
938 dw[0] = dw0;
939 dw[1] = vs_offset;
940 dw[2] = gs_offset;
941 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +0800942}
943
Chia-I Wu302742d2014-08-22 10:28:29 +0800944static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800946{
947 const uint8_t cmd_len = 2;
948 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
949 GEN6_RENDER_SUBTYPE_3D |
950 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800951 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800952
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 cmd_batch_pointer(cmd, cmd_len, &dw);
954 dw[0] = dw0;
955 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +0800956}
957
Chia-I Wua6c4f152014-12-02 04:19:58 +0800958static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +0800959{
Chia-I Wue6073342014-11-30 09:43:42 +0800960 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700961 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
962 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +0800963
964 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700965 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +0800966
Tony Barbourfa6cac72015-01-16 14:27:35 -0700967 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +0800968}
969
Chia-I Wu72292b72014-09-09 10:48:33 +0800970static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700971 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +0800972{
Tony Barbourfa6cac72015-01-16 14:27:35 -0700973 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +0800974 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +0800975 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700976 uint32_t dw[3];
977
978 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700979 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -0700980 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -0700981 (state->ds_info.stencilWriteMask & 0xff) << 16 |
982 (state->ds_info.stencilReadMask & 0xff) << 8 |
983 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700984 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +0800985
986 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -0700987
988 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
989 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +0800990
Chia-I Wu00b51a82014-09-09 12:07:37 +0800991 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -0700992 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +0800993}
994
Chia-I Wu72292b72014-09-09 10:48:33 +0800995static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +0800996 uint32_t stencil_ref,
997 const uint32_t blend_color[4])
998{
Chia-I Wue6073342014-11-30 09:43:42 +0800999 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001000 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001002
1003 CMD_ASSERT(cmd, 6, 7.5);
1004
Chia-I Wu00b51a82014-09-09 12:07:37 +08001005 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1006 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001007 dw[0] = stencil_ref;
1008 dw[1] = 0;
1009 dw[2] = blend_color[0];
1010 dw[3] = blend_color[1];
1011 dw[4] = blend_color[2];
1012 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001013
Chia-I Wu72292b72014-09-09 10:48:33 +08001014 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001015}
1016
Chia-I Wu8370b402014-08-29 12:28:37 +08001017static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001018{
Chia-I Wu8370b402014-08-29 12:28:37 +08001019 CMD_ASSERT(cmd, 6, 7.5);
1020
Chia-I Wu707a29e2014-08-27 12:51:47 +08001021 if (!cmd->bind.draw_count)
1022 return;
1023
Chia-I Wu8370b402014-08-29 12:28:37 +08001024 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001025 return;
1026
Chia-I Wu8370b402014-08-29 12:28:37 +08001027 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001028
1029 /*
1030 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1031 *
1032 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1033 * pipe-control with a post-sync op and no write-cache flushes."
1034 *
1035 * The workaround below necessitates this workaround.
1036 */
1037 gen6_PIPE_CONTROL(cmd,
1038 GEN6_PIPE_CONTROL_CS_STALL |
1039 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001040 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001041
Chia-I Wud6d079d2014-08-31 13:14:21 +08001042 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1043 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001044}
1045
Chia-I Wu8370b402014-08-29 12:28:37 +08001046static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001047{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001048 CMD_ASSERT(cmd, 6, 7.5);
1049
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001050 if (!cmd->bind.draw_count)
1051 return;
1052
Chia-I Wud6d079d2014-08-31 13:14:21 +08001053 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1054 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001055}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001056
Chia-I Wu8370b402014-08-29 12:28:37 +08001057static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1058{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001059 CMD_ASSERT(cmd, 7, 7.5);
1060
Chia-I Wu8370b402014-08-29 12:28:37 +08001061 if (!cmd->bind.draw_count)
1062 return;
1063
1064 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001065
1066 gen6_PIPE_CONTROL(cmd,
1067 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001068 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001069}
1070
Chia-I Wu8370b402014-08-29 12:28:37 +08001071static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1072{
1073 CMD_ASSERT(cmd, 7, 7.5);
1074
1075 if (!cmd->bind.draw_count)
1076 return;
1077
1078 /*
1079 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1080 *
1081 * "One of the following must also be set (when CS stall is set):
1082 *
1083 * * Render Target Cache Flush Enable ([12] of DW1)
1084 * * Depth Cache Flush Enable ([0] of DW1)
1085 * * Stall at Pixel Scoreboard ([1] of DW1)
1086 * * Depth Stall ([13] of DW1)
1087 * * Post-Sync Operation ([13] of DW1)"
1088 */
1089 gen6_PIPE_CONTROL(cmd,
1090 GEN6_PIPE_CONTROL_CS_STALL |
1091 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001092 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001093}
1094
1095static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1096{
1097 CMD_ASSERT(cmd, 7, 7.5);
1098
1099 if (!cmd->bind.draw_count)
1100 return;
1101
1102 cmd_wa_gen6_pre_depth_stall_write(cmd);
1103
Chia-I Wud6d079d2014-08-31 13:14:21 +08001104 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001105}
1106
1107static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1108{
1109 CMD_ASSERT(cmd, 6, 7.5);
1110
1111 if (!cmd->bind.draw_count)
1112 return;
1113
1114 /*
1115 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1116 *
1117 * "Driver must guarentee that all the caches in the depth pipe are
1118 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1119 * requires driver to send a PIPE_CONTROL with a CS stall along with
1120 * a Depth Flush prior to this command."
1121 *
1122 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1123 *
1124 * "Driver must ierarchi that all the caches in the depth pipe are
1125 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1126 * requires driver to send a PIPE_CONTROL with a CS stall along with
1127 * a Depth Flush prior to this command.
1128 */
1129 gen6_PIPE_CONTROL(cmd,
1130 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1131 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001132 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001133}
1134
1135static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1136{
1137 CMD_ASSERT(cmd, 6, 7.5);
1138
1139 if (!cmd->bind.draw_count)
1140 return;
1141
1142 /*
1143 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1144 *
1145 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1146 * and a post sync operation prior to the group of depth
1147 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1148 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1149 *
1150 * This workaround satifies all the conditions.
1151 */
1152 cmd_wa_gen6_pre_depth_stall_write(cmd);
1153
1154 /*
1155 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1156 *
1157 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1158 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1159 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1160 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1161 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1162 * Depth Flush Bit set, followed by another pipelined depth stall
1163 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1164 * guarantee that the pipeline from WM onwards is already flushed
1165 * (e.g., via a preceding MI_FLUSH)."
1166 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001167 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1168 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1169 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001170}
1171
Chia-I Wu525c6602014-08-27 10:22:34 +08001172void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1173{
1174 if (!cmd->bind.draw_count)
1175 return;
1176
1177 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1178
Chia-I Wu8370b402014-08-29 12:28:37 +08001179 /*
1180 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1181 *
1182 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1183 * PIPE_CONTROL with any non-zero post-sync-op is required."
1184 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001185 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001186 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001187
Chia-I Wu092279a2014-08-30 19:05:30 +08001188 /*
1189 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1190 *
1191 * "One of the following must also be set (when CS stall is set):
1192 *
1193 * * Render Target Cache Flush Enable ([12] of DW1)
1194 * * Depth Cache Flush Enable ([0] of DW1)
1195 * * Stall at Pixel Scoreboard ([1] of DW1)
1196 * * Depth Stall ([13] of DW1)
1197 * * Post-Sync Operation ([13] of DW1)"
1198 */
1199 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1200 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1201 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1202 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1203 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1204 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1205
Chia-I Wud6d079d2014-08-31 13:14:21 +08001206 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001207}
1208
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001209void cmd_batch_flush_all(struct intel_cmd *cmd)
1210{
1211 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1212 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1213 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1214 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1215 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1216 GEN6_PIPE_CONTROL_CS_STALL);
1217}
1218
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001219void cmd_batch_depth_count(struct intel_cmd *cmd,
1220 struct intel_bo *bo,
1221 XGL_GPU_SIZE offset)
1222{
1223 cmd_wa_gen6_pre_depth_stall_write(cmd);
1224
1225 gen6_PIPE_CONTROL(cmd,
1226 GEN6_PIPE_CONTROL_DEPTH_STALL |
1227 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001228 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001229}
1230
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001231void cmd_batch_timestamp(struct intel_cmd *cmd,
1232 struct intel_bo *bo,
1233 XGL_GPU_SIZE offset)
1234{
1235 /* need any WA or stall? */
1236 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1237}
1238
1239void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001240 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001241 struct intel_bo *bo,
1242 XGL_GPU_SIZE offset,
1243 uint64_t val)
1244{
1245 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001246 gen6_PIPE_CONTROL(cmd,
1247 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1248 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001249}
1250
Chia-I Wu302742d2014-08-22 10:28:29 +08001251static void gen6_cc_states(struct intel_cmd *cmd)
1252{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001253 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1254 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001255 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001256 uint32_t stencil_ref;
1257 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001258
1259 CMD_ASSERT(cmd, 6, 6);
1260
Chia-I Wua6c4f152014-12-02 04:19:58 +08001261 blend_offset = gen6_BLEND_STATE(cmd);
1262
1263 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001264 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001265 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001266 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001267
1268 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001269 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001270 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1271 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001272 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001273 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001274 stencil_ref = 0;
1275 }
1276
Chia-I Wu72292b72014-09-09 10:48:33 +08001277 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001278
Chia-I Wu72292b72014-09-09 10:48:33 +08001279 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001280}
1281
Chia-I Wu1744cca2014-08-22 11:10:17 +08001282static void gen6_viewport_states(struct intel_cmd *cmd)
1283{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001284 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001285 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001286
1287 if (!viewport)
1288 return;
1289
Tony Barbourfa6cac72015-01-16 14:27:35 -07001290 assert(viewport->cmd_len == (8 + 4 + 2) *
1291 viewport->viewport_count + (viewport->has_scissor_rects) ?
1292 (viewport->viewport_count * 2) : 0);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001293
1294 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001295 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001296 viewport->cmd);
1297
1298 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001299 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001300 &viewport->cmd[viewport->cmd_clip_pos]);
1301
1302 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001303 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001304 &viewport->cmd[viewport->cmd_cc_pos]);
1305
Tony Barbourfa6cac72015-01-16 14:27:35 -07001306 if (viewport->has_scissor_rects) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001307 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001308 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001309 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1310 } else {
1311 scissor_offset = 0;
1312 }
Chia-I Wu1744cca2014-08-22 11:10:17 +08001313
1314 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001315 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001316
Chia-I Wub1d450a2014-09-09 13:48:03 +08001317 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001318}
1319
Chia-I Wu302742d2014-08-22 10:28:29 +08001320static void gen7_cc_states(struct intel_cmd *cmd)
1321{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001322 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1323 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001324 uint32_t stencil_ref;
1325 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001326 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001327
1328 CMD_ASSERT(cmd, 7, 7.5);
1329
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001330 if (!blend && !ds)
1331 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001332
Chia-I Wua6c4f152014-12-02 04:19:58 +08001333 offset = gen6_BLEND_STATE(cmd);
1334 gen7_3dstate_pointer(cmd,
1335 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001336
Chia-I Wua6c4f152014-12-02 04:19:58 +08001337 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001338 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001339 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001340 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001341
1342 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001343 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001344 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1345 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001346 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001347 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1348 offset);
Tony Barbourfc2aba62015-01-22 18:01:18 -07001349 stencil_ref = (ds->ds_info.stencilFrontRef && 0xff) << 24 |
1350 (ds->ds_info.stencilBackRef && 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001351 } else {
1352 stencil_ref = 0;
1353 }
1354
Chia-I Wu72292b72014-09-09 10:48:33 +08001355 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001356 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001357 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001358}
1359
Chia-I Wu1744cca2014-08-22 11:10:17 +08001360static void gen7_viewport_states(struct intel_cmd *cmd)
1361{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001362 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
1363 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu72292b72014-09-09 10:48:33 +08001364 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001365
1366 if (!viewport)
1367 return;
1368
Tony Barbourfa6cac72015-01-16 14:27:35 -07001369 assert(viewport->cmd_len == (16 + 2 + 2 * pipeline->scissor_enable) *
Chia-I Wub1d450a2014-09-09 13:48:03 +08001370 viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001371
Chia-I Wub1d450a2014-09-09 13:48:03 +08001372 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001373 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001374 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001375 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001376 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1377 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001378
1379 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001380 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001381 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001382 gen7_3dstate_pointer(cmd,
1383 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001384 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001385
Tony Barbourfa6cac72015-01-16 14:27:35 -07001386 if (pipeline->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +08001387 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
Chia-I Wue6073342014-11-30 09:43:42 +08001388 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001389 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001390 gen7_3dstate_pointer(cmd,
1391 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001392 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001393 }
1394}
1395
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001396static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001397 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001398{
1399 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001400 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001401
Chia-I Wu72292b72014-09-09 10:48:33 +08001402 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001403
1404 dw[0] = GEN6_RENDER_TYPE_RENDER |
1405 GEN6_RENDER_SUBTYPE_3D |
1406 subop | (cmd_len - 2);
1407 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001408 dw[2] = 0;
1409 dw[3] = 0;
1410 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001411}
1412
1413static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001414 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001415{
1416 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001417 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001418
Chia-I Wu72292b72014-09-09 10:48:33 +08001419 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001420
1421 dw[0] = GEN6_RENDER_TYPE_RENDER |
1422 GEN6_RENDER_SUBTYPE_3D |
1423 subop | (cmd_len - 2);
1424 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001425 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001426 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001427 dw[4] = 0;
1428 dw[5] = 0;
1429 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001430}
1431
Chia-I Wu625105f2014-10-13 15:35:29 +08001432static uint32_t emit_samplers(struct intel_cmd *cmd,
1433 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001434{
1435 const XGL_UINT border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1436 const XGL_UINT border_stride =
Chia-I Wue6073342014-11-30 09:43:42 +08001437 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001438 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Chia-I Wu625105f2014-10-13 15:35:29 +08001439 XGL_UINT surface_count;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001440 XGL_UINT i;
1441
1442 CMD_ASSERT(cmd, 6, 7.5);
1443
Chia-I Wu625105f2014-10-13 15:35:29 +08001444 if (!rmap || !rmap->sampler_count)
1445 return 0;
1446
Cody Northrop40316a32014-12-09 19:08:33 -07001447 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001448
Chia-I Wudcb509d2014-12-10 08:53:10 +08001449 /*
1450 * note that we cannot call cmd_state_pointer() here as the following
1451 * cmd_state_pointer() would invalidate the pointer
1452 */
1453 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wue6073342014-11-30 09:43:42 +08001454 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001455 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001456
1457 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001458 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001459 4 * rmap->sampler_count, &sampler_dw);
1460
Chia-I Wudcb509d2014-12-10 08:53:10 +08001461 cmd_state_update(cmd, border_offset,
1462 border_stride * rmap->sampler_count, &border_dw);
1463
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001464 for (i = 0; i < rmap->sampler_count; i++) {
1465 const struct intel_pipeline_rmap_slot *slot =
1466 &rmap->slots[surface_count + i];
1467 const struct intel_sampler *sampler;
1468
Chia-I Wuf8385062015-01-04 16:27:24 +08001469 switch (slot->type) {
1470 case INTEL_PIPELINE_RMAP_SAMPLER:
1471 intel_desc_pool_read_sampler(cmd->dev->desc_pool,
1472 &slot->u.sampler, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001473 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001474 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001475 sampler = NULL;
1476 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001477 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001478 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001479 sampler = NULL;
1480 break;
1481 }
1482
1483 if (sampler) {
1484 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1485
1486 sampler_dw[0] = sampler->cmd[0];
1487 sampler_dw[1] = sampler->cmd[1];
1488 sampler_dw[2] = border_offset;
1489 sampler_dw[3] = sampler->cmd[2];
1490 } else {
1491 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1492 sampler_dw[1] = 0;
1493 sampler_dw[2] = 0;
1494 sampler_dw[3] = 0;
1495 }
1496
1497 border_offset += border_stride * 4;
1498 border_dw += border_stride;
1499 sampler_dw += 4;
1500 }
1501
Chia-I Wu625105f2014-10-13 15:35:29 +08001502 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001503}
1504
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001505static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001506 const struct intel_pipeline_rmap *rmap,
1507 const XGL_PIPELINE_SHADER_STAGE stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001508{
Chia-I Wu72292b72014-09-09 10:48:33 +08001509 uint32_t binding_table[256], offset;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001510 XGL_UINT surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001511
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001512 CMD_ASSERT(cmd, 6, 7.5);
1513
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001514 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001515 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001516 if (!surface_count)
1517 return 0;
1518
Chia-I Wu42a56202014-08-23 16:47:48 +08001519 assert(surface_count <= ARRAY_SIZE(binding_table));
1520
1521 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001522 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001523 struct intel_null_view null_view;
1524 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001525
Chia-I Wuf8385062015-01-04 16:27:24 +08001526 switch (slot->type) {
1527 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001528 {
Chia-I Wu787a05b2014-12-05 11:02:20 +08001529 const struct intel_rt_view *view =
Chia-I Wuf8385062015-01-04 16:27:24 +08001530 (slot->u.rt < cmd->bind.render_pass->fb->rt_count) ?
1531 cmd->bind.render_pass->fb->rt[slot->u.rt] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001532
Chia-I Wu787a05b2014-12-05 11:02:20 +08001533 if (view) {
1534 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1535 GEN6_ALIGNMENT_SURFACE_STATE,
1536 view->cmd_len, view->cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001537
Chia-I Wu787a05b2014-12-05 11:02:20 +08001538 cmd_reserve_reloc(cmd, 1);
1539 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
1540 view->cmd[1], INTEL_RELOC_WRITE);
1541 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001542 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001543 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001544 }
1545 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001546 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001547 {
Chia-I Wuf8385062015-01-04 16:27:24 +08001548 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
1549 const struct intel_mem *mem;
1550 bool read_only;
1551 const uint32_t *cmd_data;
1552 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001553
Chia-I Wuf8385062015-01-04 16:27:24 +08001554 assert(dyn_idx < 0 || dyn_idx <
1555 cmd->bind.dset.graphics->layout->dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001556
Chia-I Wuf8385062015-01-04 16:27:24 +08001557 intel_desc_pool_read_surface(cmd->dev->desc_pool,
1558 &slot->u.surface.offset, stage, &mem,
1559 &read_only, &cmd_data, &cmd_len);
1560 if (mem) {
1561 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
1562 cmd->bind.dset.graphics_dynamic_offsets[dyn_idx] : 0;
1563 const uint32_t reloc_flags =
1564 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001565
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001566 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001567 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001568 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001569
1570 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001571 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1572 cmd_data[1] + dynamic_offset, reloc_flags);
1573 } else {
1574 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001575 }
1576 }
1577 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001578 case INTEL_PIPELINE_RMAP_UNUSED:
1579 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001580 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001581 default:
1582 assert(!"unexpected rmap type");
1583 need_null_view = true;
1584 break;
1585 }
1586
1587 if (need_null_view) {
1588 intel_null_view_init(&null_view, cmd->dev);
1589 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1590 GEN6_ALIGNMENT_SURFACE_STATE,
1591 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001592 }
1593
Chia-I Wu72292b72014-09-09 10:48:33 +08001594 binding_table[i] = offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001595 }
1596
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001597 return cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001598 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu72292b72014-09-09 10:48:33 +08001599 surface_count, binding_table);
Chia-I Wu42a56202014-08-23 16:47:48 +08001600}
1601
Chia-I Wu1d125092014-10-08 08:49:38 +08001602static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1603{
1604 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001605 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1606 uint32_t *dw;
1607 XGL_UINT pos, i;
1608
1609 CMD_ASSERT(cmd, 6, 7.5);
1610
1611 if (!pipeline->vb_count)
1612 return;
1613
1614 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1615
1616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1617 dw++;
1618 pos++;
1619
1620 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001621 assert(pipeline->vb[i].strideInBytes <= 2048);
1622
1623 dw[0] = i << GEN6_VB_STATE_DW0_INDEX__SHIFT |
1624 pipeline->vb[i].strideInBytes;
1625
1626 if (cmd_gen(cmd) >= INTEL_GEN(7))
1627 dw[0] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
1628
1629 switch (pipeline->vb[i].stepRate) {
1630 case XGL_VERTEX_INPUT_STEP_RATE_VERTEX:
1631 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1632 dw[3] = 0;
1633 break;
1634 case XGL_VERTEX_INPUT_STEP_RATE_INSTANCE:
1635 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1636 dw[3] = 1;
1637 break;
1638 case XGL_VERTEX_INPUT_STEP_RATE_DRAW:
1639 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_INSTANCEDATA;
1640 dw[3] = 0;
1641 break;
1642 default:
1643 assert(!"unknown step rate");
1644 dw[0] |= GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA;
1645 dw[3] = 0;
1646 break;
1647 }
1648
Chia-I Wu714df452015-01-01 07:55:04 +08001649 if (cmd->bind.vertex.buf[i]) {
1650 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Chia-I Wu3b04af52014-11-08 10:48:20 +08001651 const XGL_GPU_SIZE offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001652
1653 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001654 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1655 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001656 } else {
1657 dw[0] |= GEN6_VB_STATE_DW0_IS_NULL;
1658 dw[1] = 0;
1659 dw[2] = 0;
1660 }
1661
1662 dw += 4;
1663 pos += 4;
1664 }
1665}
1666
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001667static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1668{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001669 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1670 const struct intel_pipeline_shader *vs = &pipeline->vs;
1671 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001672 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001673 uint32_t dw2, dw4, dw5, *dw;
Chia-I Wu784d3042014-12-19 14:30:04 +08001674 XGL_UINT pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001675 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001676
1677 CMD_ASSERT(cmd, 6, 7.5);
1678
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001679 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001680 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1681 *
1682 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1683 * 128-bit vertex elements to be passed into the payload for each
1684 * vertex."
1685 *
1686 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1687 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001688 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001689 vue_read_len = (vs->in_count + 1) / 2;
1690 if (!vue_read_len)
1691 vue_read_len = 1;
1692
1693 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1694 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1695
1696 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1697 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1698 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001699
1700 dw5 = GEN6_VS_DW5_STATISTICS |
1701 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001702
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001703 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001704 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001705 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001706 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001707
Chia-I Wube0a3d92014-09-02 13:20:59 +08001708 if (pipeline->disable_vs_cache)
1709 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1710
Chia-I Wu784d3042014-12-19 14:30:04 +08001711 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001712 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001713 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001714 dw[2] = dw2;
1715 dw[3] = 0; /* scratch */
1716 dw[4] = dw4;
1717 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001718
1719 if (vs->per_thread_scratch_size)
1720 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001721}
1722
Chia-I Wu625105f2014-10-13 15:35:29 +08001723static void emit_shader_resources(struct intel_cmd *cmd)
1724{
1725 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001726 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001727
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001728 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001729 cmd->bind.pipeline.graphics->vs.rmap,
1730 XGL_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001731 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001732 cmd->bind.pipeline.graphics->tcs.rmap,
1733 XGL_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001734 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001735 cmd->bind.pipeline.graphics->tes.rmap,
1736 XGL_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001737 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001738 cmd->bind.pipeline.graphics->gs.rmap,
1739 XGL_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001740 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001741 cmd->bind.pipeline.graphics->fs.rmap,
1742 XGL_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001743
1744 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1745 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1746 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1747 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1748 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1749
1750 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1751 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001752 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1753 binding_tables[0]);
1754 gen7_3dstate_pointer(cmd,
1755 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1756 binding_tables[1]);
1757 gen7_3dstate_pointer(cmd,
1758 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1759 binding_tables[2]);
1760 gen7_3dstate_pointer(cmd,
1761 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1762 binding_tables[3]);
1763 gen7_3dstate_pointer(cmd,
1764 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1765 binding_tables[4]);
1766
1767 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001768 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1769 samplers[0]);
1770 gen7_3dstate_pointer(cmd,
1771 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1772 samplers[1]);
1773 gen7_3dstate_pointer(cmd,
1774 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1775 samplers[2]);
1776 gen7_3dstate_pointer(cmd,
1777 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1778 samplers[3]);
1779 gen7_3dstate_pointer(cmd,
1780 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
1781 samplers[4]);
1782 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001783 assert(!binding_tables[1] && !binding_tables[2]);
1784 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
1785 binding_tables[0], binding_tables[3], binding_tables[4]);
1786
Chia-I Wu625105f2014-10-13 15:35:29 +08001787 assert(!samplers[1] && !samplers[2]);
1788 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
1789 samplers[0], samplers[3], samplers[4]);
1790 }
1791}
1792
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001793static void emit_rt(struct intel_cmd *cmd)
1794{
1795 cmd_wa_gen6_pre_depth_stall_write(cmd);
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001796 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, cmd->bind.render_pass->fb->width,
1797 cmd->bind.render_pass->fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001798}
1799
1800static void emit_ds(struct intel_cmd *cmd)
1801{
Jon Ashburnc04b4dc2015-01-08 18:48:10 -07001802 const struct intel_ds_view *ds = cmd->bind.render_pass->fb->ds;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08001803
1804 if (!ds) {
1805 /* all zeros */
1806 static const struct intel_ds_view null_ds;
1807 ds = &null_ds;
1808 }
1809
1810 cmd_wa_gen6_pre_ds_flush(cmd);
1811 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
1812 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
1813 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
1814
1815 if (cmd_gen(cmd) >= INTEL_GEN(7))
1816 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
1817 else
1818 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
1819}
1820
Chia-I Wua57761b2014-10-14 14:27:44 +08001821static uint32_t emit_shader(struct intel_cmd *cmd,
1822 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001823{
Chia-I Wua57761b2014-10-14 14:27:44 +08001824 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
1825 uint32_t offset;
1826 XGL_UINT i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001827
Chia-I Wua57761b2014-10-14 14:27:44 +08001828 /* see if the shader is already in the cache */
1829 for (i = 0; i < cache->used; i++) {
1830 if (cache->entries[i].shader == (const void *) shader)
1831 return cache->entries[i].kernel_offset;
1832 }
1833
1834 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
1835
1836 /* grow the cache if full */
1837 if (cache->used >= cache->count) {
1838 const XGL_UINT count = cache->count + 16;
1839 void *entries;
1840
1841 entries = icd_alloc(sizeof(cache->entries[0]) * count, 0,
1842 XGL_SYSTEM_ALLOC_INTERNAL);
1843 if (entries) {
1844 if (cache->entries) {
1845 memcpy(entries, cache->entries,
1846 sizeof(cache->entries[0]) * cache->used);
1847 icd_free(cache->entries);
1848 }
1849
1850 cache->entries = entries;
1851 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001852 }
1853 }
1854
Chia-I Wua57761b2014-10-14 14:27:44 +08001855 /* add the shader to the cache */
1856 if (cache->used < cache->count) {
1857 cache->entries[cache->used].shader = (const void *) shader;
1858 cache->entries[cache->used].kernel_offset = offset;
1859 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001860 }
1861
Chia-I Wua57761b2014-10-14 14:27:44 +08001862 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001863}
1864
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001865static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001866{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001867 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001868
Chia-I Wu8370b402014-08-29 12:28:37 +08001869 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
1870 cmd_wa_gen6_pre_depth_stall_write(cmd);
1871 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
1872 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
1873 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
1874 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001875
1876 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06001877 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08001878 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001879
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001880 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001881 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001882 }
1883 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001884 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001885 }
1886 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08001887 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
1888 }
1889 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
1890 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
1891 }
1892 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
1893 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06001894 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06001895
Chia-I Wud95aa2b2014-08-29 12:07:47 +08001896 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1897 gen7_3DSTATE_GS(cmd);
1898 } else {
1899 gen6_3DSTATE_GS(cmd);
1900 }
Courtney Goeltzenleuchterf782a852014-08-28 17:44:53 -06001901
Chia-I Wu8370b402014-08-29 12:28:37 +08001902 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
1903 cmd_wa_gen7_post_command_cs_stall(cmd);
1904 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
1905 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08001906}
1907
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001908static void emit_bounded_states(struct intel_cmd *cmd)
1909{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001910
1911 emit_graphics_pipeline(cmd);
1912
1913 emit_rt(cmd);
1914 emit_ds(cmd);
1915
1916 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1917 gen7_cc_states(cmd);
1918 gen7_viewport_states(cmd);
1919
1920 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1921 &cmd->bind.pipeline.graphics->vs);
1922 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1923 &cmd->bind.pipeline.graphics->fs);
1924
1925 gen6_3DSTATE_CLIP(cmd);
1926 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001927 gen7_3DSTATE_WM(cmd);
1928 gen7_3DSTATE_PS(cmd);
1929 } else {
1930 gen6_cc_states(cmd);
1931 gen6_viewport_states(cmd);
1932
1933 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
1934 &cmd->bind.pipeline.graphics->vs);
1935 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
1936 &cmd->bind.pipeline.graphics->fs);
1937
1938 gen6_3DSTATE_CLIP(cmd);
1939 gen6_3DSTATE_SF(cmd);
1940 gen6_3DSTATE_WM(cmd);
1941 }
1942
1943 emit_shader_resources(cmd);
1944
1945 cmd_wa_gen6_pre_depth_stall_write(cmd);
1946 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
1947
Chia-I Wuc29afdd2014-10-14 13:22:31 +08001948 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
1949 gen6_3DSTATE_VS(cmd);
1950}
1951
Tony Barbourfa6cac72015-01-16 14:27:35 -07001952static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
1953 const struct intel_cmd_meta *meta)
1954{
1955 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
1956 const uint8_t cmd_len = 3;
1957 uint32_t dw[3];
1958 uint32_t cmd_depth_stencil;
1959 uint32_t cmd_depth_test;
1960
1961 CMD_ASSERT(cmd, 6, 7.5);
1962
1963 cmd_depth_stencil = 0;
1964 cmd_depth_test = 0;
1965 if (meta->ds.aspect == XGL_IMAGE_ASPECT_DEPTH) {
1966 cmd_depth_test |= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE |
1967 GEN6_COMPAREFUNCTION_ALWAYS << 27;
1968 }
1969 else if (meta->ds.aspect == XGL_IMAGE_ASPECT_STENCIL) {
1970 cmd_depth_stencil = 1 << 31 |
1971 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
1972 (GEN6_STENCILOP_KEEP) << 25 |
1973 (GEN6_STENCILOP_KEEP) << 22 |
1974 (GEN6_STENCILOP_REPLACE) << 19 |
1975 1 << 15 |
1976 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
1977 (GEN6_STENCILOP_KEEP) << 9 |
1978 (GEN6_STENCILOP_KEEP) << 6 |
1979 (GEN6_STENCILOP_REPLACE) << 3;
1980 }
1981
1982 cmd_depth_test |= GEN6_COMPAREFUNCTION_ALWAYS << 27;
1983 dw[0] = cmd_depth_stencil | 1 << 18;
1984 dw[1] = (0xff) << 24 | (0xff) << 16;
1985 dw[2] = cmd_depth_test;
1986
1987 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
1988 cmd_align, cmd_len, dw);
1989}
1990
Chia-I Wu6032b892014-10-17 14:47:18 +08001991static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
1992{
1993 const struct intel_cmd_meta *meta = cmd->bind.meta;
1994 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
1995
1996 CMD_ASSERT(cmd, 6, 7.5);
1997
1998 blend_offset = 0;
1999 ds_offset = 0;
2000 cc_offset = 0;
2001 cc_vp_offset = 0;
2002
Chia-I Wu29e6f502014-11-24 14:27:29 +08002003 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002004 /* BLEND_STATE */
2005 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002006 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002007 dw[0] = 0;
2008 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT | 0x3;
2009 }
2010
Chia-I Wu29e6f502014-11-24 14:27:29 +08002011 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Tony Barbourfa6cac72015-01-16 14:27:35 -07002012 if (meta->ds.aspect != XGL_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002013 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Tony Barbourfa6cac72015-01-16 14:27:35 -07002014 uint32_t stencil_ref = (meta->ds.stencil_ref && 0xff) << 24 |
2015 (meta->ds.stencil_ref && 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002016
Chia-I Wu29e6f502014-11-24 14:27:29 +08002017 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002018 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002019
Chia-I Wu29e6f502014-11-24 14:27:29 +08002020 /* COLOR_CALC_STATE */
2021 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002022 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002023
Chia-I Wu29e6f502014-11-24 14:27:29 +08002024 /* CC_VIEWPORT */
2025 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002026 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002027 dw[0] = u_fui(0.0f);
2028 dw[1] = u_fui(1.0f);
2029 } else {
2030 /* DEPTH_STENCIL_STATE */
2031 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002032 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002033 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2034 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2035 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002036 }
2037
2038 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2039 gen7_3dstate_pointer(cmd,
2040 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2041 blend_offset);
2042 gen7_3dstate_pointer(cmd,
2043 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2044 ds_offset);
2045 gen7_3dstate_pointer(cmd,
2046 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2047
2048 gen7_3dstate_pointer(cmd,
2049 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2050 cc_vp_offset);
2051 } else {
2052 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002053 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002054
2055 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2056 cmd_batch_pointer(cmd, 4, &dw);
2057 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
2058 GEN6_PTR_VP_DW0_CC_CHANGED;
2059 dw[1] = 0;
2060 dw[2] = 0;
2061 dw[3] = cc_vp_offset;
2062 }
2063}
2064
2065static void gen6_meta_surface_states(struct intel_cmd *cmd)
2066{
2067 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002068 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002069 uint32_t offset;
2070
2071 CMD_ASSERT(cmd, 6, 7.5);
2072
Chia-I Wu29e6f502014-11-24 14:27:29 +08002073 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2074 return;
2075
Chia-I Wu005c47c2014-10-22 13:49:13 +08002076 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002077 if (meta->src.valid) {
2078 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002079 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002080 meta->src.surface_len, meta->src.surface);
2081
2082 cmd_reserve_reloc(cmd, 1);
2083 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2084 cmd_surface_reloc_writer(cmd, offset, 1,
2085 meta->src.reloc_target, meta->src.reloc_offset);
2086 } else {
2087 cmd_surface_reloc(cmd, offset, 1,
2088 (struct intel_bo *) meta->src.reloc_target,
2089 meta->src.reloc_offset, meta->src.reloc_flags);
2090 }
2091
Chia-I Wu005c47c2014-10-22 13:49:13 +08002092 binding_table[0] = offset;
2093 }
2094 if (meta->dst.valid) {
2095 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002096 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002097 meta->dst.surface_len, meta->dst.surface);
2098
2099 cmd_reserve_reloc(cmd, 1);
2100 cmd_surface_reloc(cmd, offset, 1,
2101 (struct intel_bo *) meta->dst.reloc_target,
2102 meta->dst.reloc_offset, meta->dst.reloc_flags);
2103
2104 binding_table[1] = offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002105 }
2106
2107 /* BINDING_TABLE */
2108 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002109 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002110 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002111
2112 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002113 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2114 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2115 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
2116 gen7_3dstate_pointer(cmd, subop, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002117 } else {
2118 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002119 if (meta->mode == INTEL_CMD_META_VS_POINTS)
2120 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset, 0, 0);
2121 else
2122 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002123 }
2124}
2125
2126static void gen6_meta_urb(struct intel_cmd *cmd)
2127{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002128 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002129 uint32_t *dw;
2130
2131 CMD_ASSERT(cmd, 6, 6);
2132
2133 /* 3DSTATE_URB */
2134 cmd_batch_pointer(cmd, 3, &dw);
2135 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002136 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002137 dw[2] = 0;
2138}
2139
2140static void gen7_meta_urb(struct intel_cmd *cmd)
2141{
Chia-I Wu29e6f502014-11-24 14:27:29 +08002142 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002143 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002144 uint32_t *dw;
2145
2146 CMD_ASSERT(cmd, 7, 7.5);
2147
2148 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
2149 cmd_batch_pointer(cmd, 10, &dw);
2150
2151 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002152 dw[1] = (meta->mode == INTEL_CMD_META_VS_POINTS);
Chia-I Wu6032b892014-10-17 14:47:18 +08002153 dw += 2;
2154
2155 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (2 - 2);
2156 dw[1] = 0;
2157 dw += 2;
2158
2159 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (2 - 2);
2160 dw[1] = 0;
2161 dw += 2;
2162
2163 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (2 - 2);
2164 dw[1] = 0;
2165 dw += 2;
2166
2167 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (2 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002168 dw[1] = (meta->mode == INTEL_CMD_META_FS_RECT);
Chia-I Wu6032b892014-10-17 14:47:18 +08002169
2170 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2171
Chia-I Wu24aa1022014-11-25 11:53:19 +08002172 switch (cmd_gen(cmd)) {
2173 case INTEL_GEN(7.5):
2174 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2175 break;
2176 case INTEL_GEN(7):
2177 default:
2178 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2179 break;
2180 }
2181
Chia-I Wu6032b892014-10-17 14:47:18 +08002182 /* 3DSTATE_URB_x */
2183 cmd_batch_pointer(cmd, 8, &dw);
2184
2185 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
2186 dw[1] = 1 << GEN7_URB_ANY_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002187 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002188 dw += 2;
2189
2190 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
2191 dw[1] = 0;
2192 dw += 2;
2193
2194 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
2195 dw[1] = 0;
2196 dw += 2;
2197
2198 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
2199 dw[1] = 0;
2200 dw += 2;
2201}
2202
2203static void gen6_meta_vf(struct intel_cmd *cmd)
2204{
2205 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002206 uint32_t vb_start, vb_end, vb_stride;
2207 int ve_format, ve_z_source;
2208 uint32_t *dw;
Chia-I Wu6032b892014-10-17 14:47:18 +08002209 XGL_UINT pos;
2210
2211 CMD_ASSERT(cmd, 6, 7.5);
2212
Chia-I Wu29e6f502014-11-24 14:27:29 +08002213 switch (meta->mode) {
2214 case INTEL_CMD_META_VS_POINTS:
2215 cmd_batch_pointer(cmd, 3, &dw);
2216 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
2217 dw[1] = GEN6_VE_STATE_DW0_VALID;
2218 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2219 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP1__SHIFT |
2220 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP2__SHIFT |
2221 GEN6_VFCOMP_NOSTORE << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2222 return;
2223 break;
2224 case INTEL_CMD_META_FS_RECT:
2225 {
2226 XGL_UINT vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002227
Chia-I Wu29e6f502014-11-24 14:27:29 +08002228 vertices[0][0] = meta->dst.x + meta->width;
2229 vertices[0][1] = meta->dst.y + meta->height;
2230 vertices[1][0] = meta->dst.x;
2231 vertices[1][1] = meta->dst.y + meta->height;
2232 vertices[2][0] = meta->dst.x;
2233 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002234
Chia-I Wu29e6f502014-11-24 14:27:29 +08002235 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2236 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002237
Chia-I Wu29e6f502014-11-24 14:27:29 +08002238 vb_end = vb_start + sizeof(vertices) - 1;
2239 vb_stride = sizeof(vertices[0]);
2240 ve_z_source = GEN6_VFCOMP_STORE_0;
2241 ve_format = GEN6_FORMAT_R32G32_USCALED;
2242 }
2243 break;
2244 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2245 {
2246 XGL_FLOAT vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002247
Chia-I Wu29e6f502014-11-24 14:27:29 +08002248 vertices[0][0] = (XGL_FLOAT) (meta->dst.x + meta->width);
2249 vertices[0][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2250 vertices[0][2] = u_uif(meta->clear_val[0]);
2251 vertices[1][0] = (XGL_FLOAT) meta->dst.x;
2252 vertices[1][1] = (XGL_FLOAT) (meta->dst.y + meta->height);
2253 vertices[1][2] = u_uif(meta->clear_val[0]);
2254 vertices[2][0] = (XGL_FLOAT) meta->dst.x;
2255 vertices[2][1] = (XGL_FLOAT) meta->dst.y;
2256 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002257
Chia-I Wu29e6f502014-11-24 14:27:29 +08002258 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2259 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002260
Chia-I Wu29e6f502014-11-24 14:27:29 +08002261 vb_end = vb_start + sizeof(vertices) - 1;
2262 vb_stride = sizeof(vertices[0]);
2263 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2264 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2265 }
2266 break;
2267 default:
2268 assert(!"unknown meta mode");
2269 return;
2270 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002271 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002272
2273 /* 3DSTATE_VERTEX_BUFFERS */
2274 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002275
Chia-I Wu6032b892014-10-17 14:47:18 +08002276 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002277 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002278 if (cmd_gen(cmd) >= INTEL_GEN(7))
2279 dw[1] |= GEN7_VB_STATE_DW0_ADDR_MODIFIED;
2280
2281 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002282 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2283 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002284
2285 dw[4] = 0;
2286
2287 /* 3DSTATE_VERTEX_ELEMENTS */
2288 cmd_batch_pointer(cmd, 5, &dw);
2289 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002290 dw[1] = GEN6_VE_STATE_DW0_VALID;
Chia-I Wu6032b892014-10-17 14:47:18 +08002291 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP0__SHIFT | /* Reserved */
2292 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2293 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP2__SHIFT | /* Viewport Index */
2294 GEN6_VFCOMP_STORE_0 << GEN6_VE_STATE_DW1_COMP3__SHIFT; /* Point Width */
2295 dw[3] = GEN6_VE_STATE_DW0_VALID |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002296 ve_format << GEN6_VE_STATE_DW0_FORMAT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002297 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP0__SHIFT |
2298 GEN6_VFCOMP_STORE_SRC << GEN6_VE_STATE_DW1_COMP1__SHIFT |
Chia-I Wu3adf7212014-10-24 15:34:07 +08002299 ve_z_source << GEN6_VE_STATE_DW1_COMP2__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002300 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_STATE_DW1_COMP3__SHIFT;
2301}
2302
Chia-I Wu29e6f502014-11-24 14:27:29 +08002303static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002304{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002305 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002306 /* one GPR */
2307 XGL_UINT consts[8];
2308 XGL_UINT const_count;
2309
2310 CMD_ASSERT(cmd, 6, 7.5);
2311
2312 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002313 case INTEL_DEV_META_VS_FILL_MEM:
2314 consts[0] = meta->dst.x;
2315 consts[1] = meta->clear_val[0];
2316 const_count = 2;
2317 break;
2318 case INTEL_DEV_META_VS_COPY_MEM:
2319 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2320 consts[0] = meta->dst.x;
2321 consts[1] = meta->src.x;
2322 const_count = 2;
2323 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002324 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2325 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2326 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2327 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2328 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2329 consts[0] = meta->src.x;
2330 consts[1] = meta->src.y;
2331 consts[2] = meta->width;
2332 consts[3] = meta->dst.x;
2333 const_count = 4;
2334 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002335 default:
2336 assert(!"unknown meta shader id");
2337 const_count = 0;
2338 break;
2339 }
2340
2341 /* this can be skipped but it makes state dumping prettier */
2342 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2343
2344 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2345}
2346
2347static void gen6_meta_vs(struct intel_cmd *cmd)
2348{
2349 const struct intel_cmd_meta *meta = cmd->bind.meta;
2350 const struct intel_pipeline_shader *sh =
2351 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2352 uint32_t offset, *dw;
2353
2354 CMD_ASSERT(cmd, 6, 7.5);
2355
2356 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
2357 XGL_UINT cmd_len;
2358
2359 /* 3DSTATE_CONSTANT_VS */
2360 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2361 cmd_batch_pointer(cmd, cmd_len, &dw);
2362 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2363 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2364
2365 /* 3DSTATE_VS */
2366 cmd_batch_pointer(cmd, 6, &dw);
2367 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2368 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2369
2370 return;
2371 }
2372
2373 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2374
2375 /* 3DSTATE_CONSTANT_VS */
2376 offset = gen6_meta_vs_constants(cmd);
2377 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2378 cmd_batch_pointer(cmd, 7, &dw);
2379 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
2380 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2381 dw[2] = 0;
2382 dw[3] = offset;
2383 dw[4] = 0;
2384 dw[5] = 0;
2385 dw[6] = 0;
2386 } else {
2387 cmd_batch_pointer(cmd, 5, &dw);
2388 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
2389 GEN6_PCB_ANY_DW0_PCB0_VALID;
2390 dw[1] = offset;
2391 dw[2] = 0;
2392 dw[3] = 0;
2393 dw[4] = 0;
2394 }
2395
2396 /* 3DSTATE_VS */
2397 offset = emit_shader(cmd, sh);
2398 cmd_batch_pointer(cmd, 6, &dw);
2399 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2400 dw[1] = offset;
2401 dw[2] = GEN6_THREADDISP_SPF |
2402 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2403 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002404 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002405 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2406 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2407
2408 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2409 GEN6_VS_DW5_VS_ENABLE;
2410 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002411 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002412 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002413 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002414
2415 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002416}
2417
2418static void gen6_meta_disabled(struct intel_cmd *cmd)
2419{
Chia-I Wu6032b892014-10-17 14:47:18 +08002420 uint32_t *dw;
2421
2422 CMD_ASSERT(cmd, 6, 6);
2423
Chia-I Wu6032b892014-10-17 14:47:18 +08002424 /* 3DSTATE_CONSTANT_GS */
2425 cmd_batch_pointer(cmd, 5, &dw);
2426 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2427 dw[1] = 0;
2428 dw[2] = 0;
2429 dw[3] = 0;
2430 dw[4] = 0;
2431
2432 /* 3DSTATE_GS */
2433 cmd_batch_pointer(cmd, 7, &dw);
2434 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2435 dw[1] = 0;
2436 dw[2] = 0;
2437 dw[3] = 0;
2438 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2439 dw[5] = GEN6_GS_DW5_STATISTICS;
2440 dw[6] = 0;
2441
Chia-I Wu6032b892014-10-17 14:47:18 +08002442 /* 3DSTATE_SF */
2443 cmd_batch_pointer(cmd, 20, &dw);
2444 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2445 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2446 memset(&dw[2], 0, 18 * sizeof(*dw));
2447}
2448
2449static void gen7_meta_disabled(struct intel_cmd *cmd)
2450{
2451 uint32_t *dw;
2452
2453 CMD_ASSERT(cmd, 7, 7.5);
2454
Chia-I Wu6032b892014-10-17 14:47:18 +08002455 /* 3DSTATE_CONSTANT_HS */
2456 cmd_batch_pointer(cmd, 7, &dw);
2457 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2458 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2459
2460 /* 3DSTATE_HS */
2461 cmd_batch_pointer(cmd, 7, &dw);
2462 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2463 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2464
2465 /* 3DSTATE_TE */
2466 cmd_batch_pointer(cmd, 4, &dw);
2467 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2468 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2469
2470 /* 3DSTATE_CONSTANT_DS */
2471 cmd_batch_pointer(cmd, 7, &dw);
2472 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2473 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2474
2475 /* 3DSTATE_DS */
2476 cmd_batch_pointer(cmd, 6, &dw);
2477 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2478 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2479
2480 /* 3DSTATE_CONSTANT_GS */
2481 cmd_batch_pointer(cmd, 7, &dw);
2482 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2483 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2484
2485 /* 3DSTATE_GS */
2486 cmd_batch_pointer(cmd, 7, &dw);
2487 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2488 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2489
2490 /* 3DSTATE_STREAMOUT */
2491 cmd_batch_pointer(cmd, 3, &dw);
2492 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2493 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2494
Chia-I Wu6032b892014-10-17 14:47:18 +08002495 /* 3DSTATE_SF */
2496 cmd_batch_pointer(cmd, 7, &dw);
2497 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2498 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2499
2500 /* 3DSTATE_SBE */
2501 cmd_batch_pointer(cmd, 14, &dw);
2502 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2503 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2504 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002505}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002506
Chia-I Wu29e6f502014-11-24 14:27:29 +08002507static void gen6_meta_clip(struct intel_cmd *cmd)
2508{
2509 const struct intel_cmd_meta *meta = cmd->bind.meta;
2510 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002511
Chia-I Wu29e6f502014-11-24 14:27:29 +08002512 /* 3DSTATE_CLIP */
2513 cmd_batch_pointer(cmd, 4, &dw);
2514 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2515 dw[1] = 0;
2516 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2517 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2518 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2519 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002520 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002521 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002522 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002523}
2524
2525static void gen6_meta_wm(struct intel_cmd *cmd)
2526{
2527 const struct intel_cmd_meta *meta = cmd->bind.meta;
2528 uint32_t *dw;
2529
2530 CMD_ASSERT(cmd, 6, 7.5);
2531
2532 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2533
2534 /* 3DSTATE_MULTISAMPLE */
2535 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2536 cmd_batch_pointer(cmd, 4, &dw);
2537 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2538 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2539 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2540 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2541 dw[2] = 0;
2542 dw[3] = 0;
2543 } else {
2544 cmd_batch_pointer(cmd, 3, &dw);
2545 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2546 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2547 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2548 dw[2] = 0;
2549 }
2550
2551 /* 3DSTATE_SAMPLE_MASK */
2552 cmd_batch_pointer(cmd, 2, &dw);
2553 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2554 dw[1] = (1 << meta->samples) - 1;
2555
2556 /* 3DSTATE_DRAWING_RECTANGLE */
2557 cmd_batch_pointer(cmd, 4, &dw);
2558 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
2559 dw[1] = meta->dst.y << 16 | meta->dst.x;
2560 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2561 (meta->dst.x + meta->width - 1);
2562 dw[3] = 0;
2563}
2564
2565static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2566{
2567 const struct intel_cmd_meta *meta = cmd->bind.meta;
2568 XGL_UINT offset_x, offset_y;
2569 /* one GPR */
2570 XGL_UINT consts[8];
2571 XGL_UINT const_count;
2572
2573 CMD_ASSERT(cmd, 6, 7.5);
2574
2575 /* underflow is fine here */
2576 offset_x = meta->src.x - meta->dst.x;
2577 offset_y = meta->src.y - meta->dst.y;
2578
2579 switch (meta->shader_id) {
2580 case INTEL_DEV_META_FS_COPY_MEM:
2581 case INTEL_DEV_META_FS_COPY_1D:
2582 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2583 case INTEL_DEV_META_FS_COPY_2D:
2584 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2585 case INTEL_DEV_META_FS_COPY_2D_MS:
2586 consts[0] = offset_x;
2587 consts[1] = offset_y;
2588 consts[2] = meta->src.layer;
2589 consts[3] = meta->src.lod;
2590 const_count = 4;
2591 break;
2592 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2593 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2594 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2595 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2596 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2597 consts[0] = offset_x;
2598 consts[1] = offset_y;
2599 consts[2] = meta->src.layer;
2600 consts[3] = meta->src.lod;
2601 consts[4] = meta->src.x;
2602 consts[5] = meta->width;
2603 const_count = 6;
2604 break;
2605 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2606 consts[0] = offset_x;
2607 consts[1] = offset_y;
2608 consts[2] = meta->width;
2609 const_count = 3;
2610 break;
2611 case INTEL_DEV_META_FS_CLEAR_COLOR:
2612 consts[0] = meta->clear_val[0];
2613 consts[1] = meta->clear_val[1];
2614 consts[2] = meta->clear_val[2];
2615 consts[3] = meta->clear_val[3];
2616 const_count = 4;
2617 break;
2618 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2619 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002620 consts[1] = meta->clear_val[1];
2621 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002622 break;
2623 case INTEL_DEV_META_FS_RESOLVE_2X:
2624 case INTEL_DEV_META_FS_RESOLVE_4X:
2625 case INTEL_DEV_META_FS_RESOLVE_8X:
2626 case INTEL_DEV_META_FS_RESOLVE_16X:
2627 consts[0] = offset_x;
2628 consts[1] = offset_y;
2629 const_count = 2;
2630 break;
2631 default:
2632 assert(!"unknown meta shader id");
2633 const_count = 0;
2634 break;
2635 }
2636
2637 /* this can be skipped but it makes state dumping prettier */
2638 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2639
2640 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2641}
2642
2643static void gen6_meta_ps(struct intel_cmd *cmd)
2644{
2645 const struct intel_cmd_meta *meta = cmd->bind.meta;
2646 const struct intel_pipeline_shader *sh =
2647 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2648 uint32_t offset, *dw;
2649
2650 CMD_ASSERT(cmd, 6, 6);
2651
Chia-I Wu29e6f502014-11-24 14:27:29 +08002652 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2653 /* 3DSTATE_CONSTANT_PS */
2654 cmd_batch_pointer(cmd, 5, &dw);
2655 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2656 dw[1] = 0;
2657 dw[2] = 0;
2658 dw[3] = 0;
2659 dw[4] = 0;
2660
2661 /* 3DSTATE_WM */
2662 cmd_batch_pointer(cmd, 9, &dw);
2663 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2664 dw[1] = 0;
2665 dw[2] = 0;
2666 dw[3] = 0;
2667 dw[4] = 0;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002668 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002669 dw[6] = 0;
2670 dw[7] = 0;
2671 dw[8] = 0;
2672
Chia-I Wu3adf7212014-10-24 15:34:07 +08002673 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002674 }
2675
Chia-I Wu3adf7212014-10-24 15:34:07 +08002676 /* a normal color write */
2677 assert(meta->dst.valid && !sh->uses);
2678
Chia-I Wu6032b892014-10-17 14:47:18 +08002679 /* 3DSTATE_CONSTANT_PS */
2680 offset = gen6_meta_ps_constants(cmd);
2681 cmd_batch_pointer(cmd, 5, &dw);
2682 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
2683 GEN6_PCB_ANY_DW0_PCB0_VALID;
2684 dw[1] = offset;
2685 dw[2] = 0;
2686 dw[3] = 0;
2687 dw[4] = 0;
2688
2689 /* 3DSTATE_WM */
2690 offset = emit_shader(cmd, sh);
2691 cmd_batch_pointer(cmd, 9, &dw);
2692 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2693 dw[1] = offset;
2694 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2695 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002696 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002697 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002698 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu6032b892014-10-17 14:47:18 +08002699 GEN6_WM_DW5_PS_ENABLE |
Chia-I Wu005c47c2014-10-22 13:49:13 +08002700 GEN6_WM_DW5_16_PIXEL_DISPATCH;
2701
Chia-I Wu6032b892014-10-17 14:47:18 +08002702 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
2703 GEN6_WM_DW6_POSOFFSET_NONE |
2704 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2705 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2706 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2707 if (meta->samples > 1) {
2708 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2709 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2710 } else {
2711 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2712 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2713 }
2714 dw[7] = 0;
2715 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002716
2717 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002718}
2719
2720static void gen7_meta_ps(struct intel_cmd *cmd)
2721{
2722 const struct intel_cmd_meta *meta = cmd->bind.meta;
2723 const struct intel_pipeline_shader *sh =
2724 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2725 uint32_t offset, *dw;
2726
2727 CMD_ASSERT(cmd, 7, 7.5);
2728
Chia-I Wu29e6f502014-11-24 14:27:29 +08002729 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2730 /* 3DSTATE_WM */
2731 cmd_batch_pointer(cmd, 3, &dw);
2732 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2733 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2734
2735 /* 3DSTATE_CONSTANT_GS */
2736 cmd_batch_pointer(cmd, 7, &dw);
2737 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2738 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2739
2740 /* 3DSTATE_PS */
2741 cmd_batch_pointer(cmd, 8, &dw);
2742 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2743 dw[1] = 0;
2744 dw[2] = 0;
2745 dw[3] = 0;
2746 dw[4] = GEN7_PS_DW4_8_PIXEL_DISPATCH | /* required to avoid hangs */
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002747 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002748 dw[5] = 0;
2749 dw[6] = 0;
2750 dw[7] = 0;
2751
Chia-I Wu3adf7212014-10-24 15:34:07 +08002752 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002753 }
2754
Chia-I Wu3adf7212014-10-24 15:34:07 +08002755 /* a normal color write */
2756 assert(meta->dst.valid && !sh->uses);
2757
Chia-I Wu6032b892014-10-17 14:47:18 +08002758 /* 3DSTATE_WM */
2759 cmd_batch_pointer(cmd, 3, &dw);
2760 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
2761 dw[1] = GEN7_WM_DW1_PS_ENABLE |
2762 GEN7_WM_DW1_ZW_INTERP_PIXEL |
2763 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
2764 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
2765 dw[2] = 0;
2766
2767 /* 3DSTATE_CONSTANT_PS */
2768 offset = gen6_meta_ps_constants(cmd);
2769 cmd_batch_pointer(cmd, 7, &dw);
2770 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
2771 dw[1] = 1 << GEN7_PCB_ANY_DW1_PCB0_SIZE__SHIFT;
2772 dw[2] = 0;
2773 dw[3] = offset;
2774 dw[4] = 0;
2775 dw[5] = 0;
2776 dw[6] = 0;
2777
2778 /* 3DSTATE_PS */
2779 offset = emit_shader(cmd, sh);
2780 cmd_batch_pointer(cmd, 8, &dw);
2781 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
2782 dw[1] = offset;
2783 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2784 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002785 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002786
2787 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
2788 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu05990612014-11-25 11:36:35 +08002789 GEN7_PS_DW4_16_PIXEL_DISPATCH;
2790
2791 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002792 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002793 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002794 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002795 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08002796 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002797
2798 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
2799 dw[6] = 0;
2800 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002801
2802 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002803}
2804
2805static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
2806{
2807 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002808 const struct intel_ds_view *ds = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08002809
2810 CMD_ASSERT(cmd, 6, 7.5);
2811
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002812 if (!ds) {
2813 /* all zeros */
2814 static const struct intel_ds_view null_ds;
2815 ds = &null_ds;
Chia-I Wu6032b892014-10-17 14:47:18 +08002816 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08002817
2818 cmd_wa_gen6_pre_ds_flush(cmd);
2819 gen6_3DSTATE_DEPTH_BUFFER(cmd, ds);
2820 gen6_3DSTATE_STENCIL_BUFFER(cmd, ds);
2821 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, ds);
2822
2823 if (cmd_gen(cmd) >= INTEL_GEN(7))
2824 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2825 else
2826 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08002827}
2828
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002829static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
2830 const struct intel_pipeline *pipeline)
2831{
2832 cmd->bind.pipeline.graphics = pipeline;
2833}
2834
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002835static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
2836 const struct intel_pipeline *pipeline)
2837{
2838 cmd->bind.pipeline.compute = pipeline;
2839}
2840
2841static void cmd_bind_graphics_delta(struct intel_cmd *cmd,
2842 const struct intel_pipeline_delta *delta)
2843{
2844 cmd->bind.pipeline.graphics_delta = delta;
2845}
2846
2847static void cmd_bind_compute_delta(struct intel_cmd *cmd,
2848 const struct intel_pipeline_delta *delta)
2849{
2850 cmd->bind.pipeline.compute_delta = delta;
2851}
2852
2853static void cmd_bind_graphics_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002854 const struct intel_desc_set *dset,
2855 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002856{
Chia-I Wuf8385062015-01-04 16:27:24 +08002857 const uint32_t size = sizeof(*dynamic_offsets) *
2858 dset->layout->dynamic_desc_count;
2859
2860 if (size > cmd->bind.dset.graphics_dynamic_offset_size) {
2861 if (cmd->bind.dset.graphics_dynamic_offsets)
2862 icd_free(cmd->bind.dset.graphics_dynamic_offsets);
2863
2864 cmd->bind.dset.graphics_dynamic_offsets = icd_alloc(size,
2865 4, XGL_SYSTEM_ALLOC_INTERNAL);
2866 if (!cmd->bind.dset.graphics_dynamic_offsets) {
2867 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2868 return;
2869 }
2870
2871 cmd->bind.dset.graphics_dynamic_offset_size = size;
2872 }
2873
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002874 cmd->bind.dset.graphics = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002875 memcpy(cmd->bind.dset.graphics_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002876}
2877
2878static void cmd_bind_compute_dset(struct intel_cmd *cmd,
Chia-I Wuf8385062015-01-04 16:27:24 +08002879 const struct intel_desc_set *dset,
2880 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002881{
Chia-I Wuf8385062015-01-04 16:27:24 +08002882 const uint32_t size = sizeof(*dynamic_offsets) *
2883 dset->layout->dynamic_desc_count;
2884
2885 if (size > cmd->bind.dset.compute_dynamic_offset_size) {
2886 if (cmd->bind.dset.compute_dynamic_offsets)
2887 icd_free(cmd->bind.dset.compute_dynamic_offsets);
2888
2889 cmd->bind.dset.compute_dynamic_offsets = icd_alloc(size,
2890 4, XGL_SYSTEM_ALLOC_INTERNAL);
2891 if (!cmd->bind.dset.compute_dynamic_offsets) {
2892 cmd->result = XGL_ERROR_OUT_OF_MEMORY;
2893 return;
2894 }
2895
2896 cmd->bind.dset.compute_dynamic_offset_size = size;
2897 }
2898
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002899 cmd->bind.dset.compute = dset;
Chia-I Wuf8385062015-01-04 16:27:24 +08002900 memcpy(cmd->bind.dset.compute_dynamic_offsets, dynamic_offsets, size);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002901}
2902
Chia-I Wu3b04af52014-11-08 10:48:20 +08002903static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002904 const struct intel_buf *buf,
Chia-I Wu3b04af52014-11-08 10:48:20 +08002905 XGL_GPU_SIZE offset, XGL_UINT binding)
2906{
Chia-I Wu714df452015-01-01 07:55:04 +08002907 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Chia-I Wu3b04af52014-11-08 10:48:20 +08002908 cmd->result = XGL_ERROR_UNKNOWN;
2909 return;
2910 }
2911
Chia-I Wu714df452015-01-01 07:55:04 +08002912 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08002913 cmd->bind.vertex.offset[binding] = offset;
2914}
2915
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002916static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08002917 const struct intel_buf *buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002918 XGL_GPU_SIZE offset, XGL_INDEX_TYPE type)
2919{
Chia-I Wu714df452015-01-01 07:55:04 +08002920 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002921 cmd->bind.index.offset = offset;
2922 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002923}
2924
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002925static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002926 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002927{
2928 cmd->bind.state.viewport = state;
2929}
2930
2931static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002932 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002933{
2934 cmd->bind.state.raster = state;
2935}
2936
2937static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002938 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002939{
2940 cmd->bind.state.ds = state;
2941}
2942
2943static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002944 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002945{
2946 cmd->bind.state.blend = state;
2947}
2948
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002949static void cmd_draw(struct intel_cmd *cmd,
2950 XGL_UINT vertex_start,
2951 XGL_UINT vertex_count,
2952 XGL_UINT instance_start,
2953 XGL_UINT instance_count,
2954 bool indexed,
2955 XGL_UINT vertex_base)
2956{
2957 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
2958
2959 emit_bounded_states(cmd);
2960
2961 if (indexed) {
2962 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
2963 cmd->result = XGL_ERROR_UNKNOWN;
2964
2965 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
2966 gen75_3DSTATE_VF(cmd, p->primitive_restart,
2967 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08002968 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002969 cmd->bind.index.offset, cmd->bind.index.type,
2970 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002971 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08002972 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002973 cmd->bind.index.offset, cmd->bind.index.type,
2974 p->primitive_restart);
2975 }
2976 } else {
2977 assert(!vertex_base);
2978 }
2979
2980 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2981 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2982 vertex_start, instance_count, instance_start, vertex_base);
2983 } else {
2984 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
2985 vertex_start, instance_count, instance_start, vertex_base);
2986 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08002987
Chia-I Wu707a29e2014-08-27 12:51:47 +08002988 cmd->bind.draw_count++;
Chia-I Wu48c283d2014-08-25 23:13:46 +08002989 /* need to re-emit all workarounds */
2990 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08002991
2992 if (intel_debug & INTEL_DEBUG_NOCACHE)
2993 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002994}
2995
Chia-I Wuc14d1562014-10-17 09:49:22 +08002996void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
2997{
Chia-I Wu6032b892014-10-17 14:47:18 +08002998 cmd->bind.meta = meta;
2999
3000 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003001 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003002
3003 gen6_meta_dynamic_states(cmd);
3004 gen6_meta_surface_states(cmd);
3005
3006 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3007 gen7_meta_urb(cmd);
3008 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003009 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003010 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003011 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003012 gen6_meta_wm(cmd);
3013 gen7_meta_ps(cmd);
3014 gen6_meta_depth_buffer(cmd);
3015
3016 cmd_wa_gen7_post_command_cs_stall(cmd);
3017 cmd_wa_gen7_post_command_depth_stall(cmd);
3018
Chia-I Wu29e6f502014-11-24 14:27:29 +08003019 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3020 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003021 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003022 } else {
3023 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3024 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003025 } else {
3026 gen6_meta_urb(cmd);
3027 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003028 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003029 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003030 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003031 gen6_meta_wm(cmd);
3032 gen6_meta_ps(cmd);
3033 gen6_meta_depth_buffer(cmd);
3034
Chia-I Wu29e6f502014-11-24 14:27:29 +08003035 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3036 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003037 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003038 } else {
3039 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3040 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003041 }
3042
3043 cmd->bind.draw_count++;
3044 /* need to re-emit all workarounds */
3045 cmd->bind.wa_flags = 0;
3046
3047 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003048
3049 if (intel_debug & INTEL_DEBUG_NOCACHE)
3050 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003051}
3052
Chia-I Wu96177272015-01-03 15:27:41 +08003053ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipeline(
Chia-I Wub2755562014-08-20 13:38:52 +08003054 XGL_CMD_BUFFER cmdBuffer,
3055 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3056 XGL_PIPELINE pipeline)
3057{
3058 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3059
3060 switch (pipelineBindPoint) {
3061 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003062 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003063 break;
3064 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003065 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003066 break;
3067 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003068 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003069 break;
3070 }
3071}
3072
Chia-I Wu96177272015-01-03 15:27:41 +08003073ICD_EXPORT XGL_VOID XGLAPI xglCmdBindPipelineDelta(
Chia-I Wub2755562014-08-20 13:38:52 +08003074 XGL_CMD_BUFFER cmdBuffer,
3075 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
3076 XGL_PIPELINE_DELTA delta)
3077{
3078 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3079
3080 switch (pipelineBindPoint) {
3081 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003082 cmd_bind_compute_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003083 break;
3084 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003085 cmd_bind_graphics_delta(cmd, delta);
Chia-I Wub2755562014-08-20 13:38:52 +08003086 break;
3087 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003088 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003089 break;
3090 }
3091}
3092
Tony Barbourfa6cac72015-01-16 14:27:35 -07003093ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDynamicStateObject(
Chia-I Wub2755562014-08-20 13:38:52 +08003094 XGL_CMD_BUFFER cmdBuffer,
3095 XGL_STATE_BIND_POINT stateBindPoint,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003096 XGL_DYNAMIC_STATE_OBJECT state)
Chia-I Wub2755562014-08-20 13:38:52 +08003097{
3098 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3099
3100 switch (stateBindPoint) {
3101 case XGL_STATE_BIND_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003102 cmd_bind_viewport_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003103 intel_dynamic_vp((XGL_DYNAMIC_VP_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003104 break;
3105 case XGL_STATE_BIND_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003106 cmd_bind_raster_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003107 intel_dynamic_rs((XGL_DYNAMIC_RS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003108 break;
3109 case XGL_STATE_BIND_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003110 cmd_bind_ds_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003111 intel_dynamic_ds((XGL_DYNAMIC_DS_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003112 break;
3113 case XGL_STATE_BIND_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003114 cmd_bind_blend_state(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003115 intel_dynamic_cb((XGL_DYNAMIC_CB_STATE_OBJECT) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003116 break;
3117 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003118 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003119 break;
3120 }
3121}
3122
Chia-I Wu96177272015-01-03 15:27:41 +08003123ICD_EXPORT XGL_VOID XGLAPI xglCmdBindDescriptorSet(
Chia-I Wub2755562014-08-20 13:38:52 +08003124 XGL_CMD_BUFFER cmdBuffer,
3125 XGL_PIPELINE_BIND_POINT pipelineBindPoint,
Chia-I Wub2755562014-08-20 13:38:52 +08003126 XGL_DESCRIPTOR_SET descriptorSet,
Chia-I Wuf8385062015-01-04 16:27:24 +08003127 const XGL_UINT* pUserData)
Chia-I Wub2755562014-08-20 13:38:52 +08003128{
3129 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wuf8385062015-01-04 16:27:24 +08003130 struct intel_desc_set *dset = intel_desc_set(descriptorSet);
Chia-I Wub2755562014-08-20 13:38:52 +08003131
3132 switch (pipelineBindPoint) {
3133 case XGL_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wuf8385062015-01-04 16:27:24 +08003134 cmd_bind_compute_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003135 break;
3136 case XGL_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wuf8385062015-01-04 16:27:24 +08003137 cmd_bind_graphics_dset(cmd, dset, pUserData);
Chia-I Wub2755562014-08-20 13:38:52 +08003138 break;
3139 default:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003140 cmd->result = XGL_ERROR_INVALID_VALUE;
Chia-I Wub2755562014-08-20 13:38:52 +08003141 break;
3142 }
3143}
3144
Chia-I Wu714df452015-01-01 07:55:04 +08003145ICD_EXPORT XGL_VOID XGLAPI xglCmdBindVertexBuffer(
Chia-I Wu3b04af52014-11-08 10:48:20 +08003146 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003147 XGL_BUFFER buffer,
Chia-I Wu3b04af52014-11-08 10:48:20 +08003148 XGL_GPU_SIZE offset,
3149 XGL_UINT binding)
3150{
3151 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003152 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003153
Chia-I Wu714df452015-01-01 07:55:04 +08003154 cmd_bind_vertex_data(cmd, buf, offset, binding);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003155}
3156
Chia-I Wu714df452015-01-01 07:55:04 +08003157ICD_EXPORT XGL_VOID XGLAPI xglCmdBindIndexBuffer(
Chia-I Wub2755562014-08-20 13:38:52 +08003158 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003159 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003160 XGL_GPU_SIZE offset,
3161 XGL_INDEX_TYPE indexType)
3162{
3163 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003164 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003165
Chia-I Wu714df452015-01-01 07:55:04 +08003166 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003167}
3168
Chia-I Wu96177272015-01-03 15:27:41 +08003169ICD_EXPORT XGL_VOID XGLAPI xglCmdDraw(
Chia-I Wub2755562014-08-20 13:38:52 +08003170 XGL_CMD_BUFFER cmdBuffer,
3171 XGL_UINT firstVertex,
3172 XGL_UINT vertexCount,
3173 XGL_UINT firstInstance,
3174 XGL_UINT instanceCount)
3175{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003176 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003177
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003178 cmd_draw(cmd, firstVertex, vertexCount,
3179 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003180}
3181
Chia-I Wu96177272015-01-03 15:27:41 +08003182ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexed(
Chia-I Wub2755562014-08-20 13:38:52 +08003183 XGL_CMD_BUFFER cmdBuffer,
3184 XGL_UINT firstIndex,
3185 XGL_UINT indexCount,
3186 XGL_INT vertexOffset,
3187 XGL_UINT firstInstance,
3188 XGL_UINT instanceCount)
3189{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003190 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003191
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003192 cmd_draw(cmd, firstIndex, indexCount,
3193 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003194}
3195
Chia-I Wu96177272015-01-03 15:27:41 +08003196ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003197 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003198 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003199 XGL_GPU_SIZE offset,
3200 XGL_UINT32 count,
3201 XGL_UINT32 stride)
3202{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003203 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3204
3205 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003206}
3207
Chia-I Wu96177272015-01-03 15:27:41 +08003208ICD_EXPORT XGL_VOID XGLAPI xglCmdDrawIndexedIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003209 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003210 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003211 XGL_GPU_SIZE offset,
3212 XGL_UINT32 count,
3213 XGL_UINT32 stride)
3214{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003215 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3216
3217 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003218}
3219
Chia-I Wu96177272015-01-03 15:27:41 +08003220ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatch(
Chia-I Wub2755562014-08-20 13:38:52 +08003221 XGL_CMD_BUFFER cmdBuffer,
3222 XGL_UINT x,
3223 XGL_UINT y,
3224 XGL_UINT z)
3225{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003226 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3227
3228 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003229}
3230
Chia-I Wu96177272015-01-03 15:27:41 +08003231ICD_EXPORT XGL_VOID XGLAPI xglCmdDispatchIndirect(
Chia-I Wub2755562014-08-20 13:38:52 +08003232 XGL_CMD_BUFFER cmdBuffer,
Chia-I Wu714df452015-01-01 07:55:04 +08003233 XGL_BUFFER buffer,
Chia-I Wub2755562014-08-20 13:38:52 +08003234 XGL_GPU_SIZE offset)
3235{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003236 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3237
3238 cmd->result = XGL_ERROR_UNKNOWN;
Chia-I Wub2755562014-08-20 13:38:52 +08003239}