blob: 6474f8d9fbe0791b0f99e63421a2b08df0f7639b [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600266 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 return;
268 break;
269 }
270
271 if (offset % offset_align) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600272 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273 return;
274 }
275
276 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800277 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800278
Chia-I Wu72292b72014-09-09 10:48:33 +0800279 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
280 dw[0] = dw0;
281
282 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800283 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
284 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800285}
286
Chia-I Wu62a7f252014-08-29 11:31:16 +0800287static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
288 bool enable_cut_index,
289 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800290{
291 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800292 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800293
294 CMD_ASSERT(cmd, 7.5, 7.5);
295
Chia-I Wu426072d2014-08-26 14:31:55 +0800296 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800297 if (enable_cut_index)
298 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
299
Chia-I Wu72292b72014-09-09 10:48:33 +0800300 cmd_batch_pointer(cmd, cmd_len, &dw);
301 dw[0] = dw0;
302 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800303}
304
Cody Northrop293d4502015-05-05 09:38:03 -0600305static void gen6_add_scratch_space(struct intel_cmd *cmd,
306 uint32_t batch_pos,
307 const struct intel_pipeline *pipeline,
308 const struct intel_pipeline_shader *sh)
309{
310 int scratch_space;
311
312 CMD_ASSERT(cmd, 6, 7.5);
313
314 assert(sh->per_thread_scratch_size &&
315 sh->per_thread_scratch_size % 1024 == 0 &&
316 u_is_pow2(sh->per_thread_scratch_size) &&
317 sh->scratch_offset % 1024 == 0);
318 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
319
320 cmd_reserve_reloc(cmd, 1);
321 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
322 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
323}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600324
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
326{
Cody Northrop293d4502015-05-05 09:38:03 -0600327 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
328 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600330 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600332 int vue_read_len = 0;
333 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800334
Cody Northrop293d4502015-05-05 09:38:03 -0600335 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
336
337 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
338
339 // based on ilo_gpe_init_gs_cso_gen6
340 vue_read_len = (gs->in_count + 1) / 2;
341 if (!vue_read_len)
342 vue_read_len = 1;
343
344 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
345 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
346 GEN6_THREADDISP_SPF;
347
348 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
349 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
350 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
351
352 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
353 GEN6_GS_DW5_STATISTICS |
354 GEN6_GS_DW5_RENDER_ENABLE;
355
356 dw6 = GEN6_GS_DW6_GS_ENABLE;
357
358 if (gs->discard_adj)
359 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
360
361 } else {
362 dw2 = 0;
363 dw4 = 0;
364 dw5 = GEN6_GS_DW5_STATISTICS;
365 dw6 = 0;
366 }
367
368 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800369 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600370 dw[1] = cmd->bind.pipeline.gs_offset;
371 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800372 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600373 dw[4] = dw4;
374 dw[5] = dw5;
375 dw[6] = dw6;
376
377 if (gs->per_thread_scratch_size)
378 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800379}
380
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
382{
Cody Northrop293d4502015-05-05 09:38:03 -0600383 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
384 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600386 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600388 int vue_read_len = 0;
389 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800390
Cody Northrop293d4502015-05-05 09:38:03 -0600391 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
392
393 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
394
395 // based on upload_gs_state
396 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
397 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
398
399 vue_read_len = (gs->in_count + 1) / 2;
400 if (!vue_read_len)
401 vue_read_len = 1;
402
403 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
404 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
405 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
406 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
407 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
408
409
410 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
411 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
412 GEN7_GS_DW5_STATISTICS |
413 GEN7_GS_DW5_GS_ENABLE;
414
415 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
416 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
417
418 if (gs->include_primitive_id)
419 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
420
421 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
422 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
423 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
424 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
425 } else {
426 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
427 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
428 dw6 = 0;
429 }
430 } else {
431 dw2 = 0;
432 dw4 = 0;
433 dw5 = GEN7_GS_DW5_STATISTICS;
434 dw6 = 0;
435 }
436
437 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800438 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600439 dw[1] = cmd->bind.pipeline.gs_offset;
440 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800441 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600442 dw[4] = dw4;
443 dw[5] = dw5;
444 dw[6] = dw6;
445
446 if (gs->per_thread_scratch_size)
447 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800448}
449
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600451 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452{
453 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800454 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800455 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800456 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457
458 CMD_ASSERT(cmd, 6, 7.5);
459
Chia-I Wu72292b72014-09-09 10:48:33 +0800460 cmd_batch_pointer(cmd, cmd_len, &dw);
461 dw[0] = dw0;
462
Chia-I Wud88e02d2014-08-25 10:56:13 +0800463 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800464 dw[1] = 0;
465 dw[2] = (height - 1) << 16 |
466 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800468 dw[1] = 1;
469 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800470 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800471
472 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800473}
474
Chia-I Wu8016a172014-08-29 18:31:32 +0800475static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
476 uint32_t body[6])
477{
478 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800479 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800480 const struct intel_render_pass_subpass *subpass =
481 cmd->bind.render_pass_subpass;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700482 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800483 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800484
485 CMD_ASSERT(cmd, 6, 7.5);
486
487 dw1 = GEN7_SF_DW1_STATISTICS |
488 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
489 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
490 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
491 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700492 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800493
494 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800495 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800496
Chia-I Wubdeed152015-07-09 12:16:29 +0800497 if (subpass->ds_index < rp->attachment_count) {
498 switch (rp->attachments[subpass->ds_index].format) {
499 case VK_FORMAT_D16_UNORM:
500 format = GEN6_ZFORMAT_D16_UNORM;
501 break;
502 case VK_FORMAT_D32_SFLOAT:
503 case VK_FORMAT_D32_SFLOAT_S8_UINT:
504 format = GEN6_ZFORMAT_D32_FLOAT;
505 break;
506 default:
507 assert(!"unsupported depth/stencil format");
508 break;
509 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800510 }
511
512 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
513 }
514
Tony Barbourfa6cac72015-01-16 14:27:35 -0700515 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800516
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700517 /* Scissor is always enabled */
518 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
519
Tony Barbourfa6cac72015-01-16 14:27:35 -0700520 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800521 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
522 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
523 } else {
524 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
525 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
526 }
527
Chia-I Wu8016a172014-08-29 18:31:32 +0800528 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
529 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
530 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800531 GEN7_SF_DW3_SUBPIXEL_8BITS;
532
Chia-I Wu8016a172014-08-29 18:31:32 +0800533 body[0] = dw1;
534 body[1] = dw2;
535 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700536 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
537 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
538 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800539}
540
Chia-I Wu8016a172014-08-29 18:31:32 +0800541static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
542{
543 const uint8_t cmd_len = 20;
544 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
545 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800546 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800547 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800548 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800549
550 CMD_ASSERT(cmd, 6, 6);
551
552 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800553
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 cmd_batch_pointer(cmd, cmd_len, &dw);
555 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800556 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800557 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800558 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800559}
560
561static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
562{
563 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800564 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800565
566 CMD_ASSERT(cmd, 7, 7.5);
567
Chia-I Wu72292b72014-09-09 10:48:33 +0800568 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800569 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
570 (cmd_len - 2);
571 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800572}
573
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800574static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
575{
576 const uint8_t cmd_len = 4;
577 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
578 (cmd_len - 2);
579 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700580 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800581 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700582 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800583 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800584
585 CMD_ASSERT(cmd, 6, 7.5);
586
587 dw1 = GEN6_CLIP_DW1_STATISTICS;
588 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
589 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
590 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700591 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800592 }
593
594 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800595 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800596 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700597 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800598 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
599 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
600 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
601
602 if (pipeline->rasterizerDiscardEnable)
603 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
604 else
605 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
606
607 if (pipeline->depthClipEnable)
608 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
609
610 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
611 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
612 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
613 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
614
615 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
616 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
617 (viewport->viewport_count - 1);
618
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600619 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600620 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600621 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
622 }
623
Chia-I Wu72292b72014-09-09 10:48:33 +0800624 cmd_batch_pointer(cmd, cmd_len, &dw);
625 dw[0] = dw0;
626 dw[1] = dw1;
627 dw[2] = dw2;
628 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800629}
630
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800631static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
632{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800633 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800634 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600636 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700637 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800638
639 CMD_ASSERT(cmd, 6, 6);
640
641 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
642
643 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
644 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
645
646 dw4 = GEN6_WM_DW4_STATISTICS |
647 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
648 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700649 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800650
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800651 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700652 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
653 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800654
Cody Northrope86574e2015-02-24 14:15:29 -0700655 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700656 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700657
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658 if (fs->uses & INTEL_SHADER_USE_KILL ||
659 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700660 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800661
Cody Northrope238deb2015-01-26 14:41:36 -0700662 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
664 if (fs->uses & INTEL_SHADER_USE_DEPTH)
665 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
666 if (fs->uses & INTEL_SHADER_USE_W)
667 dw5 |= GEN6_WM_DW5_PS_USE_W;
668
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700669 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671
672 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700673 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674 GEN6_WM_DW6_ZW_INTERP_PIXEL |
675 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
676 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
677
Tony Barbourfa6cac72015-01-16 14:27:35 -0700678 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
680 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
681 } else {
682 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
683 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
684 }
685
Cody Northrope86574e2015-02-24 14:15:29 -0700686 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
687
Chia-I Wu784d3042014-12-19 14:30:04 +0800688 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800689 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800690 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800691 dw[2] = dw2;
692 dw[3] = 0; /* scratch */
693 dw[4] = dw4;
694 dw[5] = dw5;
695 dw[6] = dw6;
696 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700697 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800698
699 if (fs->per_thread_scratch_size)
700 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800701}
702
703static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
704{
705 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800706 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800707 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800708 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800709
710 CMD_ASSERT(cmd, 7, 7.5);
711
712 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
713
714 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700715 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800716 GEN7_WM_DW1_ZW_INTERP_PIXEL |
717 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
718 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
719
720 if (fs->uses & INTEL_SHADER_USE_KILL ||
721 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700722 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723
Cody Northrope238deb2015-01-26 14:41:36 -0700724 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
725
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800726 if (fs->uses & INTEL_SHADER_USE_DEPTH)
727 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
728 if (fs->uses & INTEL_SHADER_USE_W)
729 dw1 |= GEN7_WM_DW1_PS_USE_W;
730
731 dw2 = 0;
732
Tony Barbourfa6cac72015-01-16 14:27:35 -0700733 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800734 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
735 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
736 } else {
737 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
738 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
739 }
740
Chia-I Wu72292b72014-09-09 10:48:33 +0800741 cmd_batch_pointer(cmd, cmd_len, &dw);
742 dw[0] = dw0;
743 dw[1] = dw1;
744 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800745}
746
747static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
748{
749 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800750 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800751 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700752 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600753 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800754
755 CMD_ASSERT(cmd, 7, 7.5);
756
757 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
758
759 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
760 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
761
762 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700763 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800764
Cody Northrope86574e2015-02-24 14:15:29 -0700765 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700766 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700767
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800769 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700770 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800771 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800772 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800773 }
774
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800775 if (fs->in_count)
776 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
777
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700778 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800779 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
780
781 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
782 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700783 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
784
785 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800786
Chia-I Wu784d3042014-12-19 14:30:04 +0800787 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800788 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800789 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800790 dw[2] = dw2;
791 dw[3] = 0; /* scratch */
792 dw[4] = dw4;
793 dw[5] = dw5;
794 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700795 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800796
797 if (fs->per_thread_scratch_size)
798 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800799}
800
Chia-I Wu8ada4242015-03-02 11:19:33 -0700801static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
802 uint32_t sample_count)
803{
804 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
805 uint32_t dw1, dw2, dw3, *dw;
806
807 CMD_ASSERT(cmd, 6, 7.5);
808
809 switch (sample_count) {
810 case 4:
811 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
812 dw2 = cmd->dev->sample_pattern_4x;
813 dw3 = 0;
814 break;
815 case 8:
816 assert(cmd_gen(cmd) >= INTEL_GEN(7));
817 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
818 dw2 = cmd->dev->sample_pattern_8x[0];
819 dw3 = cmd->dev->sample_pattern_8x[1];
820 break;
821 default:
822 assert(sample_count <= 1);
823 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
824 dw2 = 0;
825 dw3 = 0;
826 break;
827 }
828
829 cmd_batch_pointer(cmd, cmd_len, &dw);
830
831 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
832 dw[1] = dw1;
833 dw[2] = dw2;
834 if (cmd_gen(cmd) >= INTEL_GEN(7))
835 dw[3] = dw3;
836}
837
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800838static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800839 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700840 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800841{
842 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800843 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600844 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800845
846 CMD_ASSERT(cmd, 6, 7.5);
847
848 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800849 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
850 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800851 dw0 |= (cmd_len - 2);
852
Chia-I Wu72292b72014-09-09 10:48:33 +0800853 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
854 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700855
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800856 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700857 /* note that we only enable HiZ on Gen7+ */
858 if (!optimal_ds)
859 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
860
Chia-I Wu72292b72014-09-09 10:48:33 +0800861 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800862 dw[3] = view->att_cmd[2];
863 dw[4] = view->att_cmd[3];
864 dw[5] = view->att_cmd[4];
865 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800866
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600867 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800868 cmd_reserve_reloc(cmd, 1);
869 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800870 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600871 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800872}
873
874static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800875 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700876 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800877{
878 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800879 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600880 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800881
882 CMD_ASSERT(cmd, 6, 7.5);
883
884 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800885 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
886 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800887 dw0 |= (cmd_len - 2);
888
Chia-I Wu72292b72014-09-09 10:48:33 +0800889 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
890 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800891
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700892 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800893 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700894
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 cmd_reserve_reloc(cmd, 1);
896 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800897 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700898 } else {
899 dw[1] = 0;
900 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600901 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800902}
903
904static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800905 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700906 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800907{
908 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800909 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600910 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800911
912 CMD_ASSERT(cmd, 6, 7.5);
913
914 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800915 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
916 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800917 dw0 |= (cmd_len - 2);
918
Chia-I Wu72292b72014-09-09 10:48:33 +0800919 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
920 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800921
Chia-I Wu73520ac2015-02-19 11:17:45 -0700922 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800923 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700924
Chia-I Wu72292b72014-09-09 10:48:33 +0800925 cmd_reserve_reloc(cmd, 1);
926 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800927 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700928 } else {
929 dw[1] = 0;
930 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600931 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800932}
933
Chia-I Wuf8231032014-08-25 10:44:45 +0800934static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
935 uint32_t clear_val)
936{
937 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800938 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800939 GEN6_CLEAR_PARAMS_DW0_VALID |
940 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800942
943 CMD_ASSERT(cmd, 6, 6);
944
Chia-I Wu72292b72014-09-09 10:48:33 +0800945 cmd_batch_pointer(cmd, cmd_len, &dw);
946 dw[0] = dw0;
947 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800948}
949
950static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
951 uint32_t clear_val)
952{
953 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800954 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800955 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800956 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800957
958 CMD_ASSERT(cmd, 7, 7.5);
959
Chia-I Wu72292b72014-09-09 10:48:33 +0800960 cmd_batch_pointer(cmd, cmd_len, &dw);
961 dw[0] = dw0;
962 dw[1] = clear_val;
963 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800964}
965
Chia-I Wu302742d2014-08-22 10:28:29 +0800966static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800967 uint32_t blend_offset,
968 uint32_t ds_offset,
969 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800970{
971 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800972 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800973
974 CMD_ASSERT(cmd, 6, 6);
975
Chia-I Wu426072d2014-08-26 14:31:55 +0800976 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800977 (cmd_len - 2);
978
Chia-I Wu72292b72014-09-09 10:48:33 +0800979 cmd_batch_pointer(cmd, cmd_len, &dw);
980 dw[0] = dw0;
981 dw[1] = blend_offset | 1;
982 dw[2] = ds_offset | 1;
983 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800984}
985
Chia-I Wu1744cca2014-08-22 11:10:17 +0800986static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800987 uint32_t clip_offset,
988 uint32_t sf_offset,
989 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800990{
991 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800992 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800993
994 CMD_ASSERT(cmd, 6, 6);
995
Chia-I Wu426072d2014-08-26 14:31:55 +0800996 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700997 GEN6_VP_PTR_DW0_CLIP_CHANGED |
998 GEN6_VP_PTR_DW0_SF_CHANGED |
999 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001000 (cmd_len - 2);
1001
Chia-I Wu72292b72014-09-09 10:48:33 +08001002 cmd_batch_pointer(cmd, cmd_len, &dw);
1003 dw[0] = dw0;
1004 dw[1] = clip_offset;
1005 dw[2] = sf_offset;
1006 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001007}
1008
1009static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001011{
1012 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001013 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001014
1015 CMD_ASSERT(cmd, 6, 6);
1016
Chia-I Wu426072d2014-08-26 14:31:55 +08001017 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001018 (cmd_len - 2);
1019
Chia-I Wu72292b72014-09-09 10:48:33 +08001020 cmd_batch_pointer(cmd, cmd_len, &dw);
1021 dw[0] = dw0;
1022 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001023}
1024
Chia-I Wu42a56202014-08-23 16:47:48 +08001025static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 uint32_t vs_offset,
1027 uint32_t gs_offset,
1028 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001029{
1030 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001031 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001032
1033 CMD_ASSERT(cmd, 6, 6);
1034
Chia-I Wu426072d2014-08-26 14:31:55 +08001035 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001036 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1037 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1038 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001039 (cmd_len - 2);
1040
Chia-I Wu72292b72014-09-09 10:48:33 +08001041 cmd_batch_pointer(cmd, cmd_len, &dw);
1042 dw[0] = dw0;
1043 dw[1] = vs_offset;
1044 dw[2] = gs_offset;
1045 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001046}
1047
Chia-I Wu257e75e2014-08-29 14:06:35 +08001048static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001049 uint32_t vs_offset,
1050 uint32_t gs_offset,
1051 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001052{
1053 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001054 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001055
1056 CMD_ASSERT(cmd, 6, 6);
1057
1058 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001059 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1060 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1061 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001062 (cmd_len - 2);
1063
Chia-I Wu72292b72014-09-09 10:48:33 +08001064 cmd_batch_pointer(cmd, cmd_len, &dw);
1065 dw[0] = dw0;
1066 dw[1] = vs_offset;
1067 dw[2] = gs_offset;
1068 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001069}
1070
Chia-I Wu302742d2014-08-22 10:28:29 +08001071static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001072 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001073{
1074 const uint8_t cmd_len = 2;
1075 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1076 GEN6_RENDER_SUBTYPE_3D |
1077 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001078 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001079
Chia-I Wu72292b72014-09-09 10:48:33 +08001080 cmd_batch_pointer(cmd, cmd_len, &dw);
1081 dw[0] = dw0;
1082 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001083}
1084
Chia-I Wua6c4f152014-12-02 04:19:58 +08001085static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001086{
Chia-I Wue6073342014-11-30 09:43:42 +08001087 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001088 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1089 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001090
1091 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001092 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001093
Tony Barbourfa6cac72015-01-16 14:27:35 -07001094 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001095}
1096
Chia-I Wu72292b72014-09-09 10:48:33 +08001097static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001098 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001099{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001100 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001101 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001102 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001103 uint32_t dw[3];
1104
1105 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001106 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001107 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001108 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1109 (state->ds_info.stencilReadMask & 0xff) << 8 |
1110 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001111 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001112
1113 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001114
1115 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1116 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001117
Chia-I Wu00b51a82014-09-09 12:07:37 +08001118 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001119 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001120}
1121
Chia-I Wu72292b72014-09-09 10:48:33 +08001122static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001123 uint32_t stencil_ref,
1124 const uint32_t blend_color[4])
1125{
Chia-I Wue6073342014-11-30 09:43:42 +08001126 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001127 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001128 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001129
1130 CMD_ASSERT(cmd, 6, 7.5);
1131
Chia-I Wu00b51a82014-09-09 12:07:37 +08001132 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1133 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001134 dw[0] = stencil_ref;
1135 dw[1] = 0;
1136 dw[2] = blend_color[0];
1137 dw[3] = blend_color[1];
1138 dw[4] = blend_color[2];
1139 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001140
Chia-I Wu72292b72014-09-09 10:48:33 +08001141 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001142}
1143
Chia-I Wu8370b402014-08-29 12:28:37 +08001144static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001145{
Chia-I Wu8370b402014-08-29 12:28:37 +08001146 CMD_ASSERT(cmd, 6, 7.5);
1147
Chia-I Wu707a29e2014-08-27 12:51:47 +08001148 if (!cmd->bind.draw_count)
1149 return;
1150
Chia-I Wu8370b402014-08-29 12:28:37 +08001151 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001152 return;
1153
Chia-I Wu8370b402014-08-29 12:28:37 +08001154 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001155
1156 /*
1157 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1158 *
1159 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1160 * pipe-control with a post-sync op and no write-cache flushes."
1161 *
1162 * The workaround below necessitates this workaround.
1163 */
1164 gen6_PIPE_CONTROL(cmd,
1165 GEN6_PIPE_CONTROL_CS_STALL |
1166 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001167 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168
Chia-I Wud6d079d2014-08-31 13:14:21 +08001169 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1170 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001171}
1172
Chia-I Wu8370b402014-08-29 12:28:37 +08001173static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001174{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001175 CMD_ASSERT(cmd, 6, 7.5);
1176
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001177 if (!cmd->bind.draw_count)
1178 return;
1179
Chia-I Wud6d079d2014-08-31 13:14:21 +08001180 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1181 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001182}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001183
Chia-I Wu8370b402014-08-29 12:28:37 +08001184static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1185{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001186 CMD_ASSERT(cmd, 7, 7.5);
1187
Chia-I Wu8370b402014-08-29 12:28:37 +08001188 if (!cmd->bind.draw_count)
1189 return;
1190
1191 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001192
1193 gen6_PIPE_CONTROL(cmd,
1194 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001195 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001196}
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1199{
1200 CMD_ASSERT(cmd, 7, 7.5);
1201
Chia-I Wu8370b402014-08-29 12:28:37 +08001202 /*
1203 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1204 *
1205 * "One of the following must also be set (when CS stall is set):
1206 *
1207 * * Render Target Cache Flush Enable ([12] of DW1)
1208 * * Depth Cache Flush Enable ([0] of DW1)
1209 * * Stall at Pixel Scoreboard ([1] of DW1)
1210 * * Depth Stall ([13] of DW1)
1211 * * Post-Sync Operation ([13] of DW1)"
1212 */
1213 gen6_PIPE_CONTROL(cmd,
1214 GEN6_PIPE_CONTROL_CS_STALL |
1215 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001216 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001217}
1218
1219static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1220{
1221 CMD_ASSERT(cmd, 7, 7.5);
1222
Chia-I Wu8370b402014-08-29 12:28:37 +08001223 cmd_wa_gen6_pre_depth_stall_write(cmd);
1224
Chia-I Wud6d079d2014-08-31 13:14:21 +08001225 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001226}
1227
1228static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1229{
1230 CMD_ASSERT(cmd, 6, 7.5);
1231
1232 if (!cmd->bind.draw_count)
1233 return;
1234
1235 /*
1236 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1237 *
1238 * "Driver must guarentee that all the caches in the depth pipe are
1239 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1240 * requires driver to send a PIPE_CONTROL with a CS stall along with
1241 * a Depth Flush prior to this command."
1242 *
1243 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1244 *
1245 * "Driver must ierarchi that all the caches in the depth pipe are
1246 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1247 * requires driver to send a PIPE_CONTROL with a CS stall along with
1248 * a Depth Flush prior to this command.
1249 */
1250 gen6_PIPE_CONTROL(cmd,
1251 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1252 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001253 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001254}
1255
1256static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1257{
1258 CMD_ASSERT(cmd, 6, 7.5);
1259
1260 if (!cmd->bind.draw_count)
1261 return;
1262
1263 /*
1264 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1265 *
1266 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1267 * and a post sync operation prior to the group of depth
1268 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1269 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1270 *
1271 * This workaround satifies all the conditions.
1272 */
1273 cmd_wa_gen6_pre_depth_stall_write(cmd);
1274
1275 /*
1276 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1277 *
1278 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1279 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1280 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1281 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1282 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1283 * Depth Flush Bit set, followed by another pipelined depth stall
1284 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1285 * guarantee that the pipeline from WM onwards is already flushed
1286 * (e.g., via a preceding MI_FLUSH)."
1287 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001288 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1289 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1290 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001291}
1292
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001293void cmd_batch_state_base_address(struct intel_cmd *cmd)
1294{
1295 const uint8_t cmd_len = 10;
1296 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1297 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001298 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001299 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001300 uint32_t pos;
1301 uint32_t *dw;
1302
1303 CMD_ASSERT(cmd, 6, 7.5);
1304
1305 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1306
1307 dw[0] = dw0;
1308 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001309 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001310 dw[2] = 1;
1311 dw[3] = 1;
1312 dw[4] = 1;
1313 dw[5] = 1;
1314 /* end offsets */
1315 dw[6] = 1;
1316 dw[7] = 1 + 0xfffff000;
1317 dw[8] = 1 + 0xfffff000;
1318 dw[9] = 1;
1319
1320 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001321 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1322 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1323 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1324 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1325 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1326 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001327}
1328
Chia-I Wu7c853562015-02-27 14:35:08 -07001329void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1330{
1331 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1332 const uint8_t cmd_len = 2;
1333 uint32_t offset = 0;
1334 uint32_t *dw;
1335
1336 if (cmd_gen(cmd) <= INTEL_GEN(6))
1337 return;
1338
1339 CMD_ASSERT(cmd, 7, 7.5);
1340
1341 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1342 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1343 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1344 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1345 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1346 offset += size;
1347
1348 dw += 2;
1349 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1350 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1351 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1352
1353 dw += 2;
1354 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1355 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1356 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1357
1358 dw += 2;
1359 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1360 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1361 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1362
1363 dw += 2;
1364 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1365 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1366 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1367
1368 /*
1369 *
1370 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1371 *
1372 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1373 * in the ring after this instruction
1374 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1375 */
1376 cmd_wa_gen7_post_command_cs_stall(cmd);
1377}
1378
Chia-I Wu525c6602014-08-27 10:22:34 +08001379void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1380{
Mike Stroyan552fda42015-01-30 17:21:08 -07001381 if (pipe_control_dw0 == 0)
1382 return;
1383
Chia-I Wu525c6602014-08-27 10:22:34 +08001384 if (!cmd->bind.draw_count)
1385 return;
1386
1387 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1388
Chia-I Wu8370b402014-08-29 12:28:37 +08001389 /*
1390 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1391 *
1392 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1393 * PIPE_CONTROL with any non-zero post-sync-op is required."
1394 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001395 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001396 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001397
Chia-I Wu092279a2014-08-30 19:05:30 +08001398 /*
1399 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1400 *
1401 * "One of the following must also be set (when CS stall is set):
1402 *
1403 * * Render Target Cache Flush Enable ([12] of DW1)
1404 * * Depth Cache Flush Enable ([0] of DW1)
1405 * * Stall at Pixel Scoreboard ([1] of DW1)
1406 * * Depth Stall ([13] of DW1)
1407 * * Post-Sync Operation ([13] of DW1)"
1408 */
1409 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1410 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1411 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1412 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1413 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1414 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1415
Chia-I Wud6d079d2014-08-31 13:14:21 +08001416 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001417}
1418
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001419void cmd_batch_flush_all(struct intel_cmd *cmd)
1420{
1421 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1422 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1423 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1424 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1425 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1426 GEN6_PIPE_CONTROL_CS_STALL);
1427}
1428
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001429void cmd_batch_depth_count(struct intel_cmd *cmd,
1430 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001431 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001432{
1433 cmd_wa_gen6_pre_depth_stall_write(cmd);
1434
1435 gen6_PIPE_CONTROL(cmd,
1436 GEN6_PIPE_CONTROL_DEPTH_STALL |
1437 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001438 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001439}
1440
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001441void cmd_batch_timestamp(struct intel_cmd *cmd,
1442 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001443 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001444{
1445 /* need any WA or stall? */
1446 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1447}
1448
1449void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001450 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001451 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001452 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001453 uint64_t val)
1454{
1455 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001456 gen6_PIPE_CONTROL(cmd,
1457 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1458 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001459}
1460
Chia-I Wu302742d2014-08-22 10:28:29 +08001461static void gen6_cc_states(struct intel_cmd *cmd)
1462{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001463 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1464 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001465 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001466 uint32_t stencil_ref;
1467 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001468
1469 CMD_ASSERT(cmd, 6, 6);
1470
Chia-I Wua6c4f152014-12-02 04:19:58 +08001471 blend_offset = gen6_BLEND_STATE(cmd);
1472
1473 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001474 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001475 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001476 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001477
1478 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001479 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001480 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1481 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001482 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001483 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001484 stencil_ref = 0;
1485 }
1486
Chia-I Wu72292b72014-09-09 10:48:33 +08001487 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001488
Chia-I Wu72292b72014-09-09 10:48:33 +08001489 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001490}
1491
Chia-I Wu1744cca2014-08-22 11:10:17 +08001492static void gen6_viewport_states(struct intel_cmd *cmd)
1493{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001494 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001495 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001496
1497 if (!viewport)
1498 return;
1499
Tony Barbourfa6cac72015-01-16 14:27:35 -07001500 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001501 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001502
1503 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001504 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001505 viewport->cmd);
1506
1507 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001508 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001509 &viewport->cmd[viewport->cmd_clip_pos]);
1510
1511 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001512 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001513 &viewport->cmd[viewport->cmd_cc_pos]);
1514
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001515 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1516 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1517 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001518
1519 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001520 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001521
Chia-I Wub1d450a2014-09-09 13:48:03 +08001522 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001523}
1524
Chia-I Wu302742d2014-08-22 10:28:29 +08001525static void gen7_cc_states(struct intel_cmd *cmd)
1526{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001527 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1528 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001529 uint32_t stencil_ref;
1530 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001531 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001532
1533 CMD_ASSERT(cmd, 7, 7.5);
1534
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001535 if (!blend && !ds)
1536 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001537
Chia-I Wua6c4f152014-12-02 04:19:58 +08001538 offset = gen6_BLEND_STATE(cmd);
1539 gen7_3dstate_pointer(cmd,
1540 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001541
Chia-I Wua6c4f152014-12-02 04:19:58 +08001542 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001543 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001544 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001545 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001546
1547 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001548 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001549 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1550 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001551 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001552 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1553 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001554 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1555 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001556 } else {
1557 stencil_ref = 0;
1558 }
1559
Chia-I Wu72292b72014-09-09 10:48:33 +08001560 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001561 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001562 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001563}
1564
Chia-I Wu1744cca2014-08-22 11:10:17 +08001565static void gen7_viewport_states(struct intel_cmd *cmd)
1566{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001567 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001568 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001569
1570 if (!viewport)
1571 return;
1572
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001573 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001574
Chia-I Wub1d450a2014-09-09 13:48:03 +08001575 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001576 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001577 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001578 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001579 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1580 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001581
1582 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001583 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001584 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001585 gen7_3dstate_pointer(cmd,
1586 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001587 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001588
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001589 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1590 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1591 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1592 gen7_3dstate_pointer(cmd,
1593 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1594 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001595}
1596
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001597static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001598 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001599{
1600 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001601 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001602
Chia-I Wu72292b72014-09-09 10:48:33 +08001603 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001604
1605 dw[0] = GEN6_RENDER_TYPE_RENDER |
1606 GEN6_RENDER_SUBTYPE_3D |
1607 subop | (cmd_len - 2);
1608 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001609 dw[2] = 0;
1610 dw[3] = 0;
1611 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001612}
1613
1614static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001615 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001616{
1617 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001618 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001619
Chia-I Wu72292b72014-09-09 10:48:33 +08001620 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001621
1622 dw[0] = GEN6_RENDER_TYPE_RENDER |
1623 GEN6_RENDER_SUBTYPE_3D |
1624 subop | (cmd_len - 2);
1625 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001626 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001627 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001628 dw[4] = 0;
1629 dw[5] = 0;
1630 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001631}
1632
Chia-I Wu625105f2014-10-13 15:35:29 +08001633static uint32_t emit_samplers(struct intel_cmd *cmd,
1634 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001635{
Chia-I Wu862c5572015-03-28 15:23:55 +08001636 const struct intel_desc_region *region = cmd->dev->desc_region;
1637 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001638 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1639 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001640 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001642 uint32_t surface_count;
1643 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001644
1645 CMD_ASSERT(cmd, 6, 7.5);
1646
Chia-I Wu625105f2014-10-13 15:35:29 +08001647 if (!rmap || !rmap->sampler_count)
1648 return 0;
1649
Cody Northrop40316a32014-12-09 19:08:33 -07001650 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001651
Chia-I Wudcb509d2014-12-10 08:53:10 +08001652 /*
1653 * note that we cannot call cmd_state_pointer() here as the following
1654 * cmd_state_pointer() would invalidate the pointer
1655 */
1656 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001657 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001658 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001659
1660 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001661 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001662 4 * rmap->sampler_count, &sampler_dw);
1663
Chia-I Wudcb509d2014-12-10 08:53:10 +08001664 cmd_state_update(cmd, border_offset,
1665 border_stride * rmap->sampler_count, &border_dw);
1666
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001667 for (i = 0; i < rmap->sampler_count; i++) {
1668 const struct intel_pipeline_rmap_slot *slot =
1669 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001670 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001671 const struct intel_sampler *sampler;
1672
Chia-I Wuf8385062015-01-04 16:27:24 +08001673 switch (slot->type) {
1674 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001675 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1676 &data->set_offsets[slot->index]);
1677 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001678 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001679 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001680 sampler = NULL;
1681 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001682 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001683 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001684 sampler = NULL;
1685 break;
1686 }
1687
1688 if (sampler) {
1689 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1690
1691 sampler_dw[0] = sampler->cmd[0];
1692 sampler_dw[1] = sampler->cmd[1];
1693 sampler_dw[2] = border_offset;
1694 sampler_dw[3] = sampler->cmd[2];
1695 } else {
1696 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1697 sampler_dw[1] = 0;
1698 sampler_dw[2] = 0;
1699 sampler_dw[3] = 0;
1700 }
1701
1702 border_offset += border_stride * 4;
1703 border_dw += border_stride;
1704 sampler_dw += 4;
1705 }
1706
Chia-I Wu625105f2014-10-13 15:35:29 +08001707 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001708}
1709
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001710static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001711 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001712 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001713{
Chia-I Wu862c5572015-03-28 15:23:55 +08001714 const struct intel_desc_region *region = cmd->dev->desc_region;
1715 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001716 const uint32_t sba_offset =
1717 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001718 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001719 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001720
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001721 CMD_ASSERT(cmd, 6, 7.5);
1722
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001723 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001724 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001725 if (!surface_count)
1726 return 0;
1727
Chia-I Wu42a56202014-08-23 16:47:48 +08001728 assert(surface_count <= ARRAY_SIZE(binding_table));
1729
1730 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001731 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001732 struct intel_null_view null_view;
1733 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001734
Chia-I Wuf8385062015-01-04 16:27:24 +08001735 switch (slot->type) {
1736 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001737 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001738 const struct intel_render_pass_subpass *subpass =
1739 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001740 const struct intel_fb *fb = cmd->bind.fb;
1741 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001742 (slot->index < subpass->color_count &&
1743 subpass->color_indices[slot->index] < fb->view_count) ?
1744 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001745
Chia-I Wu787a05b2014-12-05 11:02:20 +08001746 if (view) {
1747 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1748 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001749 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001750
Chia-I Wu787a05b2014-12-05 11:02:20 +08001751 cmd_reserve_reloc(cmd, 1);
1752 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001753 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001754 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001755 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001756 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001757 }
1758 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001759 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001760 {
Tony Barbour22a30862015-04-22 09:02:32 -06001761 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001762 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001763 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001764 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001765 const struct intel_mem *mem;
1766 bool read_only;
1767 const uint32_t *cmd_data;
1768 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001769
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001770 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001771 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001772
Chia-I Wu862c5572015-03-28 15:23:55 +08001773 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1774 &data->set_offsets[slot->index]);
1775
1776 intel_desc_region_read_surface(region, &desc_offset, stage,
1777 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001778 if (mem) {
1779 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001780 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001781 const uint32_t reloc_flags =
1782 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001783
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001784 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001785 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001786 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001787
1788 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001789 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1790 cmd_data[1] + dynamic_offset, reloc_flags);
1791 } else {
1792 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001793 }
1794 }
1795 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001796 case INTEL_PIPELINE_RMAP_UNUSED:
1797 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001798 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001799 default:
1800 assert(!"unexpected rmap type");
1801 need_null_view = true;
1802 break;
1803 }
1804
1805 if (need_null_view) {
1806 intel_null_view_init(&null_view, cmd->dev);
1807 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1808 GEN6_ALIGNMENT_SURFACE_STATE,
1809 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001810 }
1811
Chia-I Wuf98dd882015-02-10 04:17:47 +08001812 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001813 }
1814
Chia-I Wuf98dd882015-02-10 04:17:47 +08001815 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001816 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001817 surface_count, binding_table) - sba_offset;
1818
1819 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1820 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1821
1822 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001823}
1824
Chia-I Wu1d125092014-10-08 08:49:38 +08001825static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1826{
1827 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001828 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1829 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001830 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001831
1832 CMD_ASSERT(cmd, 6, 7.5);
1833
1834 if (!pipeline->vb_count)
1835 return;
1836
1837 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1838
1839 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1840 dw++;
1841 pos++;
1842
1843 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001844 assert(pipeline->vb[i].strideInBytes <= 2048);
1845
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001846 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001847 pipeline->vb[i].strideInBytes;
1848
Chia-I Wub3686982015-02-27 09:51:16 -07001849 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001850 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1851 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001852 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001853
1854 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001855 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001856 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001857 dw[3] = 0;
1858 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001860 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001861 dw[3] = 1;
1862 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001863 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001864 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001865 dw[3] = 0;
1866 break;
1867 default:
1868 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001869 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001870 dw[3] = 0;
1871 break;
1872 }
1873
Chia-I Wu714df452015-01-01 07:55:04 +08001874 if (cmd->bind.vertex.buf[i]) {
1875 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001876 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001877
1878 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001879 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1880 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001881 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001882 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001883 dw[1] = 0;
1884 dw[2] = 0;
1885 }
1886
1887 dw += 4;
1888 pos += 4;
1889 }
1890}
1891
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001892static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1893{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001894 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1895 const struct intel_pipeline_shader *vs = &pipeline->vs;
1896 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001897 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001898 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001899 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001900 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001901
1902 CMD_ASSERT(cmd, 6, 7.5);
1903
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001904 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001905 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1906 *
1907 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1908 * 128-bit vertex elements to be passed into the payload for each
1909 * vertex."
1910 *
1911 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1912 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001913 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001914 vue_read_len = (vs->in_count + 1) / 2;
1915 if (!vue_read_len)
1916 vue_read_len = 1;
1917
1918 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1919 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1920
1921 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1922 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1923 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001924
1925 dw5 = GEN6_VS_DW5_STATISTICS |
1926 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001927
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001928 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001929 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001930 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001931 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001932
Chia-I Wube0a3d92014-09-02 13:20:59 +08001933 if (pipeline->disable_vs_cache)
1934 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1935
Chia-I Wu784d3042014-12-19 14:30:04 +08001936 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001937 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001938 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001939 dw[2] = dw2;
1940 dw[3] = 0; /* scratch */
1941 dw[4] = dw4;
1942 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001943
1944 if (vs->per_thread_scratch_size)
1945 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001946}
1947
Chia-I Wu625105f2014-10-13 15:35:29 +08001948static void emit_shader_resources(struct intel_cmd *cmd)
1949{
1950 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001951 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001952
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001953 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001954 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001955 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001956 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001957 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001958 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001959 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001960 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001961 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001962 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001963 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001964 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001965 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001966 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001967 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001968
1969 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1970 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1971 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1972 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1973 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1974
1975 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1976 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001977 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1978 binding_tables[0]);
1979 gen7_3dstate_pointer(cmd,
1980 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1981 binding_tables[1]);
1982 gen7_3dstate_pointer(cmd,
1983 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1984 binding_tables[2]);
1985 gen7_3dstate_pointer(cmd,
1986 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1987 binding_tables[3]);
1988 gen7_3dstate_pointer(cmd,
1989 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1990 binding_tables[4]);
1991
1992 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001993 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1994 samplers[0]);
1995 gen7_3dstate_pointer(cmd,
1996 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1997 samplers[1]);
1998 gen7_3dstate_pointer(cmd,
1999 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2000 samplers[2]);
2001 gen7_3dstate_pointer(cmd,
2002 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2003 samplers[3]);
2004 gen7_3dstate_pointer(cmd,
2005 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2006 samplers[4]);
2007 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002008 assert(!binding_tables[1] && !binding_tables[2]);
2009 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2010 binding_tables[0], binding_tables[3], binding_tables[4]);
2011
Chia-I Wu625105f2014-10-13 15:35:29 +08002012 assert(!samplers[1] && !samplers[2]);
2013 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2014 samplers[0], samplers[3], samplers[4]);
2015 }
2016}
2017
Chia-I Wu8ada4242015-03-02 11:19:33 -07002018static void emit_msaa(struct intel_cmd *cmd)
2019{
Chia-I Wuc278df82015-07-07 11:50:03 +08002020 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002021
Chia-I Wubbc7d912015-02-27 14:59:50 -07002022 if (!cmd->bind.render_pass_changed)
2023 return;
2024
Chia-I Wu8ada4242015-03-02 11:19:33 -07002025 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002026 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002027}
2028
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002029static void emit_rt(struct intel_cmd *cmd)
2030{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002031 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002032
2033 if (!cmd->bind.render_pass_changed)
2034 return;
2035
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002036 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002037 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2038 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002039}
2040
2041static void emit_ds(struct intel_cmd *cmd)
2042{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002043 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002044 const struct intel_render_pass_subpass *subpass =
2045 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002046 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002047 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002048 (subpass->ds_index < rp->attachment_count) ?
2049 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002050
Chia-I Wubbc7d912015-02-27 14:59:50 -07002051 if (!cmd->bind.render_pass_changed)
2052 return;
2053
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002054 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002055 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002056 static const struct intel_att_view null_view;
2057 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002058 }
2059
2060 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002061 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2062 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2063 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002064
2065 if (cmd_gen(cmd) >= INTEL_GEN(7))
2066 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2067 else
2068 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2069}
2070
Chia-I Wua57761b2014-10-14 14:27:44 +08002071static uint32_t emit_shader(struct intel_cmd *cmd,
2072 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002073{
Chia-I Wua57761b2014-10-14 14:27:44 +08002074 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2075 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002076 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002077
Chia-I Wua57761b2014-10-14 14:27:44 +08002078 /* see if the shader is already in the cache */
2079 for (i = 0; i < cache->used; i++) {
2080 if (cache->entries[i].shader == (const void *) shader)
2081 return cache->entries[i].kernel_offset;
2082 }
2083
2084 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2085
2086 /* grow the cache if full */
2087 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002088 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002089 void *entries;
2090
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002091 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002092 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002093 if (entries) {
2094 if (cache->entries) {
2095 memcpy(entries, cache->entries,
2096 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002097 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002098 }
2099
2100 cache->entries = entries;
2101 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002102 }
2103 }
2104
Chia-I Wua57761b2014-10-14 14:27:44 +08002105 /* add the shader to the cache */
2106 if (cache->used < cache->count) {
2107 cache->entries[cache->used].shader = (const void *) shader;
2108 cache->entries[cache->used].kernel_offset = offset;
2109 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002110 }
2111
Chia-I Wua57761b2014-10-14 14:27:44 +08002112 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002113}
2114
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002115static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002116{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002117 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002118
Chia-I Wu8370b402014-08-29 12:28:37 +08002119 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2120 cmd_wa_gen6_pre_depth_stall_write(cmd);
2121 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2122 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2123 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2124 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002125
2126 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002127 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002128 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002129
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002130 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002131 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002132 }
2133 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002134 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002135 }
2136 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002137 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2138 }
2139 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2140 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2141 }
2142 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2143 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002144 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002145
Chia-I Wu8370b402014-08-29 12:28:37 +08002146 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2147 cmd_wa_gen7_post_command_cs_stall(cmd);
2148 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2149 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002150}
2151
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002152static void emit_bounded_states(struct intel_cmd *cmd)
2153{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002154 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002155
2156 emit_graphics_pipeline(cmd);
2157
2158 emit_rt(cmd);
2159 emit_ds(cmd);
2160
2161 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2162 gen7_cc_states(cmd);
2163 gen7_viewport_states(cmd);
2164
2165 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2166 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002167 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2168 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002169 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2170 &cmd->bind.pipeline.graphics->fs);
2171
Cody Northrop293d4502015-05-05 09:38:03 -06002172 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002173 gen6_3DSTATE_CLIP(cmd);
2174 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002175 gen7_3DSTATE_WM(cmd);
2176 gen7_3DSTATE_PS(cmd);
2177 } else {
2178 gen6_cc_states(cmd);
2179 gen6_viewport_states(cmd);
2180
2181 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2182 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002183 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2184 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002185 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2186 &cmd->bind.pipeline.graphics->fs);
2187
Cody Northrop293d4502015-05-05 09:38:03 -06002188 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002189 gen6_3DSTATE_CLIP(cmd);
2190 gen6_3DSTATE_SF(cmd);
2191 gen6_3DSTATE_WM(cmd);
2192 }
2193
2194 emit_shader_resources(cmd);
2195
2196 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002197
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002198 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2199 gen6_3DSTATE_VS(cmd);
2200}
2201
Tony Barbourfa6cac72015-01-16 14:27:35 -07002202static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002203 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002204{
2205 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2206 const uint8_t cmd_len = 3;
2207 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002208
2209 CMD_ASSERT(cmd, 6, 7.5);
2210
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002211 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002212 dw[0] = 0;
2213 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002214
2215 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2216 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2217 GEN6_COMPAREFUNCTION_NEVER << 27 |
2218 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2219 } else {
2220 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2221 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2222 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002223 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002224 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002225 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2226 (GEN6_STENCILOP_KEEP) << 25 |
2227 (GEN6_STENCILOP_KEEP) << 22 |
2228 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002229 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2230 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002231 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2232 (GEN6_STENCILOP_KEEP) << 9 |
2233 (GEN6_STENCILOP_KEEP) << 6 |
2234 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002235
Chia-I Wud850a392015-02-19 11:08:25 -07002236 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2237 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2238 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2239 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2240 dw[2] = 0;
2241 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002242
2243 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2244 cmd_align, cmd_len, dw);
2245}
2246
Chia-I Wu6032b892014-10-17 14:47:18 +08002247static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2248{
2249 const struct intel_cmd_meta *meta = cmd->bind.meta;
2250 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2251
2252 CMD_ASSERT(cmd, 6, 7.5);
2253
2254 blend_offset = 0;
2255 ds_offset = 0;
2256 cc_offset = 0;
2257 cc_vp_offset = 0;
2258
Chia-I Wu29e6f502014-11-24 14:27:29 +08002259 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002260 /* BLEND_STATE */
2261 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002262 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002263 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002264 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002265 }
2266
Chia-I Wu29e6f502014-11-24 14:27:29 +08002267 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002268 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002269 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002270 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2271 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002272
Chia-I Wu29e6f502014-11-24 14:27:29 +08002273 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002274 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 /* COLOR_CALC_STATE */
2277 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002278 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002279
Chia-I Wu29e6f502014-11-24 14:27:29 +08002280 /* CC_VIEWPORT */
2281 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002282 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002283 dw[0] = u_fui(0.0f);
2284 dw[1] = u_fui(1.0f);
2285 } else {
2286 /* DEPTH_STENCIL_STATE */
2287 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002288 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2290 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2291 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002292 }
2293
2294 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2295 gen7_3dstate_pointer(cmd,
2296 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2297 blend_offset);
2298 gen7_3dstate_pointer(cmd,
2299 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2300 ds_offset);
2301 gen7_3dstate_pointer(cmd,
2302 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2303
2304 gen7_3dstate_pointer(cmd,
2305 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2306 cc_vp_offset);
2307 } else {
2308 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002309 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002310
2311 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2312 cmd_batch_pointer(cmd, 4, &dw);
2313 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002314 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002315 dw[1] = 0;
2316 dw[2] = 0;
2317 dw[3] = cc_vp_offset;
2318 }
2319}
2320
2321static void gen6_meta_surface_states(struct intel_cmd *cmd)
2322{
2323 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002324 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002325 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002326 const uint32_t sba_offset =
2327 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002328
2329 CMD_ASSERT(cmd, 6, 7.5);
2330
Chia-I Wu29e6f502014-11-24 14:27:29 +08002331 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2332 return;
2333
Chia-I Wu005c47c2014-10-22 13:49:13 +08002334 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002335 if (meta->src.valid) {
2336 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002337 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002338 meta->src.surface_len, meta->src.surface);
2339
2340 cmd_reserve_reloc(cmd, 1);
2341 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2342 cmd_surface_reloc_writer(cmd, offset, 1,
2343 meta->src.reloc_target, meta->src.reloc_offset);
2344 } else {
2345 cmd_surface_reloc(cmd, offset, 1,
2346 (struct intel_bo *) meta->src.reloc_target,
2347 meta->src.reloc_offset, meta->src.reloc_flags);
2348 }
2349
Mike Stroyan9bfad482015-02-10 15:09:23 -07002350 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002351 }
2352 if (meta->dst.valid) {
2353 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002354 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002355 meta->dst.surface_len, meta->dst.surface);
2356
2357 cmd_reserve_reloc(cmd, 1);
2358 cmd_surface_reloc(cmd, offset, 1,
2359 (struct intel_bo *) meta->dst.reloc_target,
2360 meta->dst.reloc_offset, meta->dst.reloc_flags);
2361
Mike Stroyan9bfad482015-02-10 15:09:23 -07002362 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002363 }
2364
2365 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002366 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002367 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002368 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002369
2370 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002371 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2372 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2373 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002374 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002375 } else {
2376 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002377 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002378 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002379 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002380 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002381 }
2382}
2383
2384static void gen6_meta_urb(struct intel_cmd *cmd)
2385{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002386 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002387 uint32_t *dw;
2388
2389 CMD_ASSERT(cmd, 6, 6);
2390
2391 /* 3DSTATE_URB */
2392 cmd_batch_pointer(cmd, 3, &dw);
2393 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002394 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002395 dw[2] = 0;
2396}
2397
2398static void gen7_meta_urb(struct intel_cmd *cmd)
2399{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002400 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2401 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002402 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002403 uint32_t *dw;
2404
2405 CMD_ASSERT(cmd, 7, 7.5);
2406
Chia-I Wu6032b892014-10-17 14:47:18 +08002407 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2408
Chia-I Wu24aa1022014-11-25 11:53:19 +08002409 switch (cmd_gen(cmd)) {
2410 case INTEL_GEN(7.5):
2411 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2412 break;
2413 case INTEL_GEN(7):
2414 default:
2415 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2416 break;
2417 }
2418
Chia-I Wu6032b892014-10-17 14:47:18 +08002419 /* 3DSTATE_URB_x */
2420 cmd_batch_pointer(cmd, 8, &dw);
2421
2422 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002423 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002424 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 dw += 2;
2426
2427 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002428 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002429 dw += 2;
2430
2431 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002432 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002433 dw += 2;
2434
2435 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002436 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002437 dw += 2;
2438}
2439
2440static void gen6_meta_vf(struct intel_cmd *cmd)
2441{
2442 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002443 uint32_t vb_start, vb_end, vb_stride;
2444 int ve_format, ve_z_source;
2445 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002446 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002447
2448 CMD_ASSERT(cmd, 6, 7.5);
2449
Chia-I Wu29e6f502014-11-24 14:27:29 +08002450 switch (meta->mode) {
2451 case INTEL_CMD_META_VS_POINTS:
2452 cmd_batch_pointer(cmd, 3, &dw);
2453 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002454 dw[1] = GEN6_VE_DW0_VALID;
2455 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2456 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2457 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2458 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002459 return;
2460 break;
2461 case INTEL_CMD_META_FS_RECT:
2462 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002463 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002464
Chia-I Wu29e6f502014-11-24 14:27:29 +08002465 vertices[0][0] = meta->dst.x + meta->width;
2466 vertices[0][1] = meta->dst.y + meta->height;
2467 vertices[1][0] = meta->dst.x;
2468 vertices[1][1] = meta->dst.y + meta->height;
2469 vertices[2][0] = meta->dst.x;
2470 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002471
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2473 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002474
Chia-I Wu29e6f502014-11-24 14:27:29 +08002475 vb_end = vb_start + sizeof(vertices) - 1;
2476 vb_stride = sizeof(vertices[0]);
2477 ve_z_source = GEN6_VFCOMP_STORE_0;
2478 ve_format = GEN6_FORMAT_R32G32_USCALED;
2479 }
2480 break;
2481 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2482 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002483 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002484
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002485 vertices[0][0] = (float) (meta->dst.x + meta->width);
2486 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002487 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002488 vertices[1][0] = (float) meta->dst.x;
2489 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002490 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002491 vertices[2][0] = (float) meta->dst.x;
2492 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002493 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002494
Chia-I Wu29e6f502014-11-24 14:27:29 +08002495 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2496 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002497
Chia-I Wu29e6f502014-11-24 14:27:29 +08002498 vb_end = vb_start + sizeof(vertices) - 1;
2499 vb_stride = sizeof(vertices[0]);
2500 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2501 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2502 }
2503 break;
2504 default:
2505 assert(!"unknown meta mode");
2506 return;
2507 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002508 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002509
2510 /* 3DSTATE_VERTEX_BUFFERS */
2511 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002512
Chia-I Wu6032b892014-10-17 14:47:18 +08002513 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002514 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002515 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002516 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002517
2518 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002519 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2520 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002521
2522 dw[4] = 0;
2523
2524 /* 3DSTATE_VERTEX_ELEMENTS */
2525 cmd_batch_pointer(cmd, 5, &dw);
2526 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002527 dw[1] = GEN6_VE_DW0_VALID;
2528 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2529 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2530 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2531 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2532 dw[3] = GEN6_VE_DW0_VALID |
2533 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2534 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2535 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2536 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2537 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002538}
2539
Chia-I Wu29e6f502014-11-24 14:27:29 +08002540static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002541{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002542 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002543 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002544 uint32_t consts[8];
2545 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002546
2547 CMD_ASSERT(cmd, 6, 7.5);
2548
2549 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002550 case INTEL_DEV_META_VS_FILL_MEM:
2551 consts[0] = meta->dst.x;
2552 consts[1] = meta->clear_val[0];
2553 const_count = 2;
2554 break;
2555 case INTEL_DEV_META_VS_COPY_MEM:
2556 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2557 consts[0] = meta->dst.x;
2558 consts[1] = meta->src.x;
2559 const_count = 2;
2560 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002561 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2562 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2563 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2564 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2565 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2566 consts[0] = meta->src.x;
2567 consts[1] = meta->src.y;
2568 consts[2] = meta->width;
2569 consts[3] = meta->dst.x;
2570 const_count = 4;
2571 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002572 default:
2573 assert(!"unknown meta shader id");
2574 const_count = 0;
2575 break;
2576 }
2577
2578 /* this can be skipped but it makes state dumping prettier */
2579 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2580
2581 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2582}
2583
2584static void gen6_meta_vs(struct intel_cmd *cmd)
2585{
2586 const struct intel_cmd_meta *meta = cmd->bind.meta;
2587 const struct intel_pipeline_shader *sh =
2588 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2589 uint32_t offset, *dw;
2590
2591 CMD_ASSERT(cmd, 6, 7.5);
2592
2593 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002594 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002595
2596 /* 3DSTATE_CONSTANT_VS */
2597 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2598 cmd_batch_pointer(cmd, cmd_len, &dw);
2599 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2600 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2601
2602 /* 3DSTATE_VS */
2603 cmd_batch_pointer(cmd, 6, &dw);
2604 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2605 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2606
2607 return;
2608 }
2609
2610 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2611
2612 /* 3DSTATE_CONSTANT_VS */
2613 offset = gen6_meta_vs_constants(cmd);
2614 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2615 cmd_batch_pointer(cmd, 7, &dw);
2616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002617 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002618 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002619 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002620 dw[4] = 0;
2621 dw[5] = 0;
2622 dw[6] = 0;
2623 } else {
2624 cmd_batch_pointer(cmd, 5, &dw);
2625 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002626 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002627 dw[1] = offset;
2628 dw[2] = 0;
2629 dw[3] = 0;
2630 dw[4] = 0;
2631 }
2632
2633 /* 3DSTATE_VS */
2634 offset = emit_shader(cmd, sh);
2635 cmd_batch_pointer(cmd, 6, &dw);
2636 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2637 dw[1] = offset;
2638 dw[2] = GEN6_THREADDISP_SPF |
2639 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2640 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002641 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002642 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2643 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2644
2645 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2646 GEN6_VS_DW5_VS_ENABLE;
2647 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002648 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002649 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002650 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002651
2652 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002653}
2654
2655static void gen6_meta_disabled(struct intel_cmd *cmd)
2656{
Chia-I Wu6032b892014-10-17 14:47:18 +08002657 uint32_t *dw;
2658
2659 CMD_ASSERT(cmd, 6, 6);
2660
Chia-I Wu6032b892014-10-17 14:47:18 +08002661 /* 3DSTATE_CONSTANT_GS */
2662 cmd_batch_pointer(cmd, 5, &dw);
2663 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2664 dw[1] = 0;
2665 dw[2] = 0;
2666 dw[3] = 0;
2667 dw[4] = 0;
2668
2669 /* 3DSTATE_GS */
2670 cmd_batch_pointer(cmd, 7, &dw);
2671 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2672 dw[1] = 0;
2673 dw[2] = 0;
2674 dw[3] = 0;
2675 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2676 dw[5] = GEN6_GS_DW5_STATISTICS;
2677 dw[6] = 0;
2678
Chia-I Wu6032b892014-10-17 14:47:18 +08002679 /* 3DSTATE_SF */
2680 cmd_batch_pointer(cmd, 20, &dw);
2681 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2682 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2683 memset(&dw[2], 0, 18 * sizeof(*dw));
2684}
2685
2686static void gen7_meta_disabled(struct intel_cmd *cmd)
2687{
2688 uint32_t *dw;
2689
2690 CMD_ASSERT(cmd, 7, 7.5);
2691
Chia-I Wu6032b892014-10-17 14:47:18 +08002692 /* 3DSTATE_CONSTANT_HS */
2693 cmd_batch_pointer(cmd, 7, &dw);
2694 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2695 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2696
2697 /* 3DSTATE_HS */
2698 cmd_batch_pointer(cmd, 7, &dw);
2699 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2700 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2701
2702 /* 3DSTATE_TE */
2703 cmd_batch_pointer(cmd, 4, &dw);
2704 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2705 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2706
2707 /* 3DSTATE_CONSTANT_DS */
2708 cmd_batch_pointer(cmd, 7, &dw);
2709 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2710 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2711
2712 /* 3DSTATE_DS */
2713 cmd_batch_pointer(cmd, 6, &dw);
2714 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2715 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2716
2717 /* 3DSTATE_CONSTANT_GS */
2718 cmd_batch_pointer(cmd, 7, &dw);
2719 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2720 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2721
2722 /* 3DSTATE_GS */
2723 cmd_batch_pointer(cmd, 7, &dw);
2724 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2725 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2726
2727 /* 3DSTATE_STREAMOUT */
2728 cmd_batch_pointer(cmd, 3, &dw);
2729 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2730 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2731
Chia-I Wu6032b892014-10-17 14:47:18 +08002732 /* 3DSTATE_SF */
2733 cmd_batch_pointer(cmd, 7, &dw);
2734 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2735 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2736
2737 /* 3DSTATE_SBE */
2738 cmd_batch_pointer(cmd, 14, &dw);
2739 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2740 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2741 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002742}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002743
Chia-I Wu29e6f502014-11-24 14:27:29 +08002744static void gen6_meta_clip(struct intel_cmd *cmd)
2745{
2746 const struct intel_cmd_meta *meta = cmd->bind.meta;
2747 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002748
Chia-I Wu29e6f502014-11-24 14:27:29 +08002749 /* 3DSTATE_CLIP */
2750 cmd_batch_pointer(cmd, 4, &dw);
2751 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2752 dw[1] = 0;
2753 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2754 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2755 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2756 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002757 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002758 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002759 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002760}
2761
2762static void gen6_meta_wm(struct intel_cmd *cmd)
2763{
2764 const struct intel_cmd_meta *meta = cmd->bind.meta;
2765 uint32_t *dw;
2766
2767 CMD_ASSERT(cmd, 6, 7.5);
2768
2769 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2770
2771 /* 3DSTATE_MULTISAMPLE */
2772 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2773 cmd_batch_pointer(cmd, 4, &dw);
2774 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2775 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2776 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2777 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2778 dw[2] = 0;
2779 dw[3] = 0;
2780 } else {
2781 cmd_batch_pointer(cmd, 3, &dw);
2782 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2783 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2784 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2785 dw[2] = 0;
2786 }
2787
2788 /* 3DSTATE_SAMPLE_MASK */
2789 cmd_batch_pointer(cmd, 2, &dw);
2790 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2791 dw[1] = (1 << meta->samples) - 1;
2792
2793 /* 3DSTATE_DRAWING_RECTANGLE */
2794 cmd_batch_pointer(cmd, 4, &dw);
2795 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002796 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2797 /* unused */
2798 dw[1] = 0;
2799 dw[2] = 0;
2800 } else {
2801 dw[1] = meta->dst.y << 16 | meta->dst.x;
2802 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2803 (meta->dst.x + meta->width - 1);
2804 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002805 dw[3] = 0;
2806}
2807
2808static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2809{
2810 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002811 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002812 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002813 uint32_t consts[8];
2814 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002815
2816 CMD_ASSERT(cmd, 6, 7.5);
2817
2818 /* underflow is fine here */
2819 offset_x = meta->src.x - meta->dst.x;
2820 offset_y = meta->src.y - meta->dst.y;
2821
2822 switch (meta->shader_id) {
2823 case INTEL_DEV_META_FS_COPY_MEM:
2824 case INTEL_DEV_META_FS_COPY_1D:
2825 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2826 case INTEL_DEV_META_FS_COPY_2D:
2827 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2828 case INTEL_DEV_META_FS_COPY_2D_MS:
2829 consts[0] = offset_x;
2830 consts[1] = offset_y;
2831 consts[2] = meta->src.layer;
2832 consts[3] = meta->src.lod;
2833 const_count = 4;
2834 break;
2835 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2836 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2837 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2838 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2839 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2840 consts[0] = offset_x;
2841 consts[1] = offset_y;
2842 consts[2] = meta->src.layer;
2843 consts[3] = meta->src.lod;
2844 consts[4] = meta->src.x;
2845 consts[5] = meta->width;
2846 const_count = 6;
2847 break;
2848 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2849 consts[0] = offset_x;
2850 consts[1] = offset_y;
2851 consts[2] = meta->width;
2852 const_count = 3;
2853 break;
2854 case INTEL_DEV_META_FS_CLEAR_COLOR:
2855 consts[0] = meta->clear_val[0];
2856 consts[1] = meta->clear_val[1];
2857 consts[2] = meta->clear_val[2];
2858 consts[3] = meta->clear_val[3];
2859 const_count = 4;
2860 break;
2861 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2862 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002863 consts[1] = meta->clear_val[1];
2864 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002865 break;
2866 case INTEL_DEV_META_FS_RESOLVE_2X:
2867 case INTEL_DEV_META_FS_RESOLVE_4X:
2868 case INTEL_DEV_META_FS_RESOLVE_8X:
2869 case INTEL_DEV_META_FS_RESOLVE_16X:
2870 consts[0] = offset_x;
2871 consts[1] = offset_y;
2872 const_count = 2;
2873 break;
2874 default:
2875 assert(!"unknown meta shader id");
2876 const_count = 0;
2877 break;
2878 }
2879
2880 /* this can be skipped but it makes state dumping prettier */
2881 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2882
2883 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2884}
2885
2886static void gen6_meta_ps(struct intel_cmd *cmd)
2887{
2888 const struct intel_cmd_meta *meta = cmd->bind.meta;
2889 const struct intel_pipeline_shader *sh =
2890 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2891 uint32_t offset, *dw;
2892
2893 CMD_ASSERT(cmd, 6, 6);
2894
Chia-I Wu29e6f502014-11-24 14:27:29 +08002895 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2896 /* 3DSTATE_CONSTANT_PS */
2897 cmd_batch_pointer(cmd, 5, &dw);
2898 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2899 dw[1] = 0;
2900 dw[2] = 0;
2901 dw[3] = 0;
2902 dw[4] = 0;
2903
2904 /* 3DSTATE_WM */
2905 cmd_batch_pointer(cmd, 9, &dw);
2906 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2907 dw[1] = 0;
2908 dw[2] = 0;
2909 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002910
2911 switch (meta->ds.op) {
2912 case INTEL_CMD_META_DS_HIZ_CLEAR:
2913 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2914 break;
2915 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2916 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2917 break;
2918 case INTEL_CMD_META_DS_RESOLVE:
2919 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2920 break;
2921 default:
2922 dw[4] = 0;
2923 break;
2924 }
2925
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002926 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002927 dw[6] = 0;
2928 dw[7] = 0;
2929 dw[8] = 0;
2930
Chia-I Wu3adf7212014-10-24 15:34:07 +08002931 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002932 }
2933
Chia-I Wu3adf7212014-10-24 15:34:07 +08002934 /* a normal color write */
2935 assert(meta->dst.valid && !sh->uses);
2936
Chia-I Wu6032b892014-10-17 14:47:18 +08002937 /* 3DSTATE_CONSTANT_PS */
2938 offset = gen6_meta_ps_constants(cmd);
2939 cmd_batch_pointer(cmd, 5, &dw);
2940 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002941 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002942 dw[1] = offset;
2943 dw[2] = 0;
2944 dw[3] = 0;
2945 dw[4] = 0;
2946
2947 /* 3DSTATE_WM */
2948 offset = emit_shader(cmd, sh);
2949 cmd_batch_pointer(cmd, 9, &dw);
2950 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2951 dw[1] = offset;
2952 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2953 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002954 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002955 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002956 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002957 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2958 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002959
Chia-I Wu6032b892014-10-17 14:47:18 +08002960 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002961 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002962 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2963 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2964 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2965 if (meta->samples > 1) {
2966 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2967 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2968 } else {
2969 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2970 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2971 }
2972 dw[7] = 0;
2973 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002974
2975 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002976}
2977
2978static void gen7_meta_ps(struct intel_cmd *cmd)
2979{
2980 const struct intel_cmd_meta *meta = cmd->bind.meta;
2981 const struct intel_pipeline_shader *sh =
2982 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2983 uint32_t offset, *dw;
2984
2985 CMD_ASSERT(cmd, 7, 7.5);
2986
Chia-I Wu29e6f502014-11-24 14:27:29 +08002987 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2988 /* 3DSTATE_WM */
2989 cmd_batch_pointer(cmd, 3, &dw);
2990 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002991
2992 switch (meta->ds.op) {
2993 case INTEL_CMD_META_DS_HIZ_CLEAR:
2994 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2995 break;
2996 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2997 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2998 break;
2999 case INTEL_CMD_META_DS_RESOLVE:
3000 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3001 break;
3002 default:
3003 dw[1] = 0;
3004 break;
3005 }
3006
3007 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003008
3009 /* 3DSTATE_CONSTANT_GS */
3010 cmd_batch_pointer(cmd, 7, &dw);
3011 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3012 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3013
3014 /* 3DSTATE_PS */
3015 cmd_batch_pointer(cmd, 8, &dw);
3016 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3017 dw[1] = 0;
3018 dw[2] = 0;
3019 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003020 /* required to avoid hangs */
3021 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003022 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003023 dw[5] = 0;
3024 dw[6] = 0;
3025 dw[7] = 0;
3026
Chia-I Wu3adf7212014-10-24 15:34:07 +08003027 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003028 }
3029
Chia-I Wu3adf7212014-10-24 15:34:07 +08003030 /* a normal color write */
3031 assert(meta->dst.valid && !sh->uses);
3032
Chia-I Wu6032b892014-10-17 14:47:18 +08003033 /* 3DSTATE_WM */
3034 cmd_batch_pointer(cmd, 3, &dw);
3035 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003036 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003037 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3038 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3039 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3040 dw[2] = 0;
3041
3042 /* 3DSTATE_CONSTANT_PS */
3043 offset = gen6_meta_ps_constants(cmd);
3044 cmd_batch_pointer(cmd, 7, &dw);
3045 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003046 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003047 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003048 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003049 dw[4] = 0;
3050 dw[5] = 0;
3051 dw[6] = 0;
3052
3053 /* 3DSTATE_PS */
3054 offset = emit_shader(cmd, sh);
3055 cmd_batch_pointer(cmd, 8, &dw);
3056 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3057 dw[1] = offset;
3058 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3059 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003060 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003061
3062 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3063 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003064 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003065
3066 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003067 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003068 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003069 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003070 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003071 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003072
3073 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3074 dw[6] = 0;
3075 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003076
3077 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003078}
3079
3080static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3081{
3082 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003083 const struct intel_att_view *view = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003084
3085 CMD_ASSERT(cmd, 6, 7.5);
3086
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003087 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003088 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003089 static const struct intel_att_view null_view;
3090 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003091 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003092
3093 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003094 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3095 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3096 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003097
3098 if (cmd_gen(cmd) >= INTEL_GEN(7))
3099 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3100 else
3101 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003102}
3103
Chia-I Wu862c5572015-03-28 15:23:55 +08003104static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3105 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003106 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003107{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003108 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003109 if (data->set_offsets)
3110 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003111
Chia-I Wu862c5572015-03-28 15:23:55 +08003112 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003113 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003114 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003115 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003116 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003117 data->set_offset_count = 0;
3118 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003119 }
3120
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003121 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003122 }
3123
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003124 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003125 if (data->dynamic_offsets)
3126 intel_free(cmd, data->dynamic_offsets);
3127
3128 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003129 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003130 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003131 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003132 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003133 data->dynamic_offset_count = 0;
3134 return false;
3135 }
3136
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003137 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003138 }
3139
3140 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003141}
3142
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003143static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3144 const struct intel_pipeline *pipeline)
3145{
3146 cmd->bind.pipeline.graphics = pipeline;
3147
3148 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003149 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003150}
3151
3152static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3153 const struct intel_pipeline *pipeline)
3154{
3155 cmd->bind.pipeline.compute = pipeline;
3156
3157 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003158 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003159}
3160
Chia-I Wu862c5572015-03-28 15:23:55 +08003161static void cmd_copy_dset_data(struct intel_cmd *cmd,
3162 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003163 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003164 uint32_t index,
3165 const struct intel_desc_set *set,
3166 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003167{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003168 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003169
Chia-I Wu862c5572015-03-28 15:23:55 +08003170 assert(index < data->set_offset_count);
3171 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003172
Chia-I Wu862c5572015-03-28 15:23:55 +08003173 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003174 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003175 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003176
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003177 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003178 dynamic_offsets,
3179 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003180 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003181}
3182
Chia-I Wu3b04af52014-11-08 10:48:20 +08003183static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003184 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003185 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003186{
Chia-I Wu714df452015-01-01 07:55:04 +08003187 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003188 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003189 return;
3190 }
3191
Chia-I Wu714df452015-01-01 07:55:04 +08003192 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003193 cmd->bind.vertex.offset[binding] = offset;
3194}
3195
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003196static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003197 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003198 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003199{
Chia-I Wu714df452015-01-01 07:55:04 +08003200 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003201 cmd->bind.index.offset = offset;
3202 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203}
3204
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003205static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003206 const struct intel_dynamic_vp *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003207{
3208 cmd->bind.state.viewport = state;
3209}
3210
3211static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003212 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213{
3214 cmd->bind.state.raster = state;
3215}
3216
3217static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003218 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003219{
3220 cmd->bind.state.ds = state;
3221}
3222
3223static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003224 const struct intel_dynamic_cb *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225{
3226 cmd->bind.state.blend = state;
3227}
3228
Chia-I Wuf98dd882015-02-10 04:17:47 +08003229static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3230{
3231 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3232 struct intel_pipeline_rmap *rmaps[5] = {
3233 pipeline->vs.rmap,
3234 pipeline->tcs.rmap,
3235 pipeline->tes.rmap,
3236 pipeline->gs.rmap,
3237 pipeline->fs.rmap,
3238 };
3239 uint32_t max_write;
3240 int i;
3241
3242 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3243 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3244 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3245
3246 /* pad first */
3247 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3248
3249 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3250 const struct intel_pipeline_rmap *rmap = rmaps[i];
3251 const uint32_t surface_count = (rmap) ?
3252 rmap->rt_count + rmap->texture_resource_count +
3253 rmap->resource_count + rmap->uav_count : 0;
3254
3255 if (surface_count) {
3256 /* SURFACE_STATEs */
3257 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3258
3259 /* BINDING_TABLE_STATE */
3260 max_write += u_align(sizeof(uint32_t) * surface_count,
3261 GEN6_ALIGNMENT_SURFACE_STATE);
3262 }
3263 }
3264
3265 return max_write;
3266}
3267
3268static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3269{
3270 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3271 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3272 uint32_t max_surface_write;
3273
3274 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3275 if (cmd->bind.meta)
3276 max_surface_write = 64 * sizeof(uint32_t);
3277 else
3278 max_surface_write = cmd_get_max_surface_write(cmd);
3279
3280 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3281 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3282 /* SBA expects page-aligned addresses */
3283 writer->sba_offset = writer->used & ~0xfff;
3284
3285 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3286
3287 cmd_batch_state_base_address(cmd);
3288 }
3289}
3290
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003291static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003292 uint32_t vertex_start,
3293 uint32_t vertex_count,
3294 uint32_t instance_start,
3295 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003296 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003297 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003298{
3299 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003300 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003301 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3302
3303 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003304
3305 emit_bounded_states(cmd);
3306
Chia-I Wuf98dd882015-02-10 04:17:47 +08003307 /* sanity check on cmd_get_max_surface_write() */
3308 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3309 surface_writer_used <= cmd_get_max_surface_write(cmd));
3310
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003311 if (indexed) {
3312 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003313 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003314
3315 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3316 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3317 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003318 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003319 cmd->bind.index.offset, cmd->bind.index.type,
3320 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003321 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003322 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003323 cmd->bind.index.offset, cmd->bind.index.type,
3324 p->primitive_restart);
3325 }
3326 } else {
3327 assert(!vertex_base);
3328 }
3329
3330 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3331 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3332 vertex_start, instance_count, instance_start, vertex_base);
3333 } else {
3334 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3335 vertex_start, instance_count, instance_start, vertex_base);
3336 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003337
Chia-I Wu707a29e2014-08-27 12:51:47 +08003338 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003339 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003340 /* need to re-emit all workarounds */
3341 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003342
3343 if (intel_debug & INTEL_DEBUG_NOCACHE)
3344 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003345}
3346
Chia-I Wuc14d1562014-10-17 09:49:22 +08003347void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3348{
Chia-I Wu6032b892014-10-17 14:47:18 +08003349 cmd->bind.meta = meta;
3350
Chia-I Wuf98dd882015-02-10 04:17:47 +08003351 cmd_adjust_state_base_address(cmd);
3352
Chia-I Wu6032b892014-10-17 14:47:18 +08003353 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003354 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003355
3356 gen6_meta_dynamic_states(cmd);
3357 gen6_meta_surface_states(cmd);
3358
3359 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3360 gen7_meta_urb(cmd);
3361 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003362 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003363 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003364 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003365 gen6_meta_wm(cmd);
3366 gen7_meta_ps(cmd);
3367 gen6_meta_depth_buffer(cmd);
3368
3369 cmd_wa_gen7_post_command_cs_stall(cmd);
3370 cmd_wa_gen7_post_command_depth_stall(cmd);
3371
Chia-I Wu29e6f502014-11-24 14:27:29 +08003372 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3373 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003374 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003375 } else {
3376 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3377 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003378 } else {
3379 gen6_meta_urb(cmd);
3380 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003381 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003382 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003383 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003384 gen6_meta_wm(cmd);
3385 gen6_meta_ps(cmd);
3386 gen6_meta_depth_buffer(cmd);
3387
Chia-I Wu29e6f502014-11-24 14:27:29 +08003388 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3389 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003390 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003391 } else {
3392 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3393 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003394 }
3395
3396 cmd->bind.draw_count++;
3397 /* need to re-emit all workarounds */
3398 cmd->bind.wa_flags = 0;
3399
3400 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003401
Chia-I Wubbc7d912015-02-27 14:59:50 -07003402 /* make the normal path believe the render pass has changed */
3403 cmd->bind.render_pass_changed = true;
3404
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003405 if (intel_debug & INTEL_DEBUG_NOCACHE)
3406 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003407}
3408
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003409static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3410{
3411 const uint8_t cmd_len = 2;
3412 uint32_t *dw;
3413 uint32_t pos;
3414
3415 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3416 cmd->result = VK_ERROR_UNKNOWN;
3417 return;
3418 }
3419
3420 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3421 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3422 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3423 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3424 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3425
3426 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3427}
3428
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003429ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003430 VkCmdBuffer cmdBuffer,
3431 VkPipelineBindPoint pipelineBindPoint,
3432 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003433{
3434 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3435
3436 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003437 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003438 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003439 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003440 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003441 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003442 break;
3443 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003444 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003445 break;
3446 }
3447}
3448
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003449ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003450 VkCmdBuffer cmdBuffer,
3451 VkStateBindPoint stateBindPoint,
3452 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003453{
3454 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3455
3456 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003457 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003458 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003459 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003460 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003461 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003462 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003463 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003464 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003465 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003466 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003467 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003468 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003469 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003470 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003471 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003472 break;
3473 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003474 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003475 break;
3476 }
3477}
3478
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003479ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003480 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003481 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003482 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003483 uint32_t firstSet,
3484 uint32_t setCount,
3485 const VkDescriptorSet* pDescriptorSets,
3486 uint32_t dynamicOffsetCount,
3487 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003488{
3489 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003490 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003491 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003492 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003493 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003494
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003495 pipeline_layout = intel_pipeline_layout(layout);
3496
Chia-I Wub2755562014-08-20 13:38:52 +08003497 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003498 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003499 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003500 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003501 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003502 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003503 break;
3504 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003505 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003506 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003507 break;
3508 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003509
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003510 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003511 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3512
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003513 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003514 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003515 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003516 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003517 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003518 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003519 }
Chia-I Wub2755562014-08-20 13:38:52 +08003520}
3521
Tony Barbour8205d902015-04-16 15:59:00 -06003522
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003523ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3524 VkCmdBuffer cmdBuffer,
3525 uint32_t startBinding,
3526 uint32_t bindingCount,
3527 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003528 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003529{
3530 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003531
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003532 for (uint32_t i = 0; i < bindingCount; i++) {
3533 struct intel_buf *buf = intel_buf(pBuffers[i]);
3534 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3535 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003536}
3537
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003538ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003539 VkCmdBuffer cmdBuffer,
3540 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003541 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003542 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003543{
3544 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003545 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003546
Chia-I Wu714df452015-01-01 07:55:04 +08003547 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003548}
3549
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003550ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003551 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003552 uint32_t firstVertex,
3553 uint32_t vertexCount,
3554 uint32_t firstInstance,
3555 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003556{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003557 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003558
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003559 cmd_draw(cmd, firstVertex, vertexCount,
3560 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003561}
3562
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003563ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003564 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003565 uint32_t firstIndex,
3566 uint32_t indexCount,
3567 int32_t vertexOffset,
3568 uint32_t firstInstance,
3569 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003570{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003571 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003572
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003573 cmd_draw(cmd, firstIndex, indexCount,
3574 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003575}
3576
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003577ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003578 VkCmdBuffer cmdBuffer,
3579 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003580 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003581 uint32_t count,
3582 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003583{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003584 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3585
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003586 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003587}
3588
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003589ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003590 VkCmdBuffer cmdBuffer,
3591 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003592 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003593 uint32_t count,
3594 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003595{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003596 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3597
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003598 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003599}
3600
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003601ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003602 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003603 uint32_t x,
3604 uint32_t y,
3605 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003606{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003607 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3608
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003609 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003610}
3611
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003612ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003613 VkCmdBuffer cmdBuffer,
3614 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003615 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003616{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003617 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3618
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003619 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003620}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003621
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003622ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003623 VkCmdBuffer cmdBuffer,
3624 const VkRenderPassBeginInfo* pRenderPassBegin,
3625 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003626{
Chia-I Wubdeed152015-07-09 12:16:29 +08003627 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3628 const struct intel_render_pass *rp =
3629 intel_render_pass(pRenderPassBegin->renderPass);
3630 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3631 const struct intel_att_view *view;
3632 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003633
Chia-I Wubdeed152015-07-09 12:16:29 +08003634 if (!cmd->primary || rp->attachment_count != fb->view_count) {
3635 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3636 return;
3637 }
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003638
Chia-I Wuc278df82015-07-07 11:50:03 +08003639 cmd_begin_render_pass(cmd, rp, fb, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003640
Chia-I Wubdeed152015-07-09 12:16:29 +08003641 for (i = 0; i < rp->attachment_count; i++) {
3642 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003643 const VkClearValue *clear_val =
3644 &pRenderPassBegin->pAttachmentClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003645 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003646
Chia-I Wubdeed152015-07-09 12:16:29 +08003647 if (!att->clear_on_load)
3648 continue;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003649
Chia-I Wubdeed152015-07-09 12:16:29 +08003650 view = fb->views[i];
3651 range.baseMipLevel = view->mipLevel;
3652 range.mipLevels = 1;
3653 range.baseArraySlice = view->baseArraySlice;
3654 range.arraySize = view->array_size;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003655
Chia-I Wubdeed152015-07-09 12:16:29 +08003656 if (view->is_rt) {
3657 range.aspect = VK_IMAGE_ASPECT_COLOR;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003658
Chia-I Wubdeed152015-07-09 12:16:29 +08003659 cmd_meta_clear_color_image(cmdBuffer, (VkImage) view->img,
Chia-I Wuc278df82015-07-07 11:50:03 +08003660 att->initial_layout, &clear_val->color, 1, &range);
Chia-I Wubdeed152015-07-09 12:16:29 +08003661 } else {
3662 range.aspect = VK_IMAGE_ASPECT_DEPTH;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003663
Chia-I Wubdeed152015-07-09 12:16:29 +08003664 cmd_meta_clear_depth_stencil_image(cmdBuffer,
3665 (VkImage) view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003666 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003667 1, &range);
Chris Forbes4cf9d102015-06-22 18:46:05 +12003668
Chia-I Wubdeed152015-07-09 12:16:29 +08003669 if (att->stencil_clear_on_load) {
3670 range.aspect = VK_IMAGE_ASPECT_STENCIL;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003671
Chia-I Wubdeed152015-07-09 12:16:29 +08003672 cmd_meta_clear_depth_stencil_image(cmdBuffer,
3673 (VkImage) view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003674 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003675 1, &range);
3676 }
3677 }
3678 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003679}
3680
Chia-I Wuc278df82015-07-07 11:50:03 +08003681ICD_EXPORT void VKAPI vkCmdNextSubpass(
3682 VkCmdBuffer cmdBuffer,
3683 VkRenderPassContents contents)
3684{
3685 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3686 const struct intel_render_pass *rp = cmd->bind.render_pass;
3687
3688 if (cmd->bind.render_pass_subpass >= rp->subpasses +
3689 rp->subpass_count - 1) {
3690 cmd->result = VK_ERROR_UNKNOWN;
3691 return;
3692 }
3693
3694 cmd->bind.render_pass_changed = true;
3695 cmd->bind.render_pass_subpass++;
3696 cmd->bind.render_pass_contents = contents;
3697}
3698
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003699ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003700 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003701{
3702 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3703
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003704 cmd_end_render_pass(cmd);
3705}
3706
3707ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3708 VkCmdBuffer cmdBuffer,
3709 uint32_t cmdBuffersCount,
3710 const VkCmdBuffer* pCmdBuffers)
3711{
3712 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003713 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003714
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003715 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3716 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3717 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3718 return;
3719 }
3720
3721 for (i = 0; i < cmdBuffersCount; i++) {
3722 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3723
3724 if (secondary->primary) {
3725 cmd->result = VK_ERROR_INVALID_VALUE;
3726 break;
3727 }
3728
3729 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3730 }
3731
3732 if (i)
3733 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003734}