blob: 1e6260b1b616be053e13bd163035c0548667bc22 [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 Barbourde4124d2015-07-03 10:33:54 -0600482 const struct intel_dynamic_raster *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
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600528 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
529 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
530 2 << 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 Barbourde4124d2015-07-03 10:33:54 -0600536 body[3] = u_fui((float) raster->raster_info.depthBias * 2.0f);
537 body[4] = u_fui(raster->raster_info.slopeScaledDepthBias);
538 body[5] = u_fui(raster->raster_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 Barbourde4124d2015-07-03 10:33:54 -0600582 const struct intel_dynamic_viewport *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 |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600598 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
599 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
600 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800601
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 Barbourde4124d2015-07-03 10:33:54 -06001098 const struct intel_dynamic_depth_stencil *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 Barbourde4124d2015-07-03 10:33:54 -06001107 dw[1] = (state->depth_stencil_info.stencilReadMask & 0xff) << 24 |
1108 (state->depth_stencil_info.stencilWriteMask & 0xff) << 16 |
1109 (state->depth_stencil_info.stencilReadMask & 0xff) << 8 |
1110 (state->depth_stencil_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
Tony Barbourde4124d2015-07-03 10:33:54 -06001115 if (state->depth_stencil_info.stencilWriteMask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001116 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 Barbourde4124d2015-07-03 10:33:54 -06001463 const struct intel_dynamic_color_blend *blend = cmd->bind.state.blend;
1464 const struct intel_dynamic_depth_stencil *ds = cmd->bind.state.depth;
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 Barbourde4124d2015-07-03 10:33:54 -06001474 memcpy(blend_color, blend->color_blend_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);
Tony Barbourde4124d2015-07-03 10:33:54 -06001480 stencil_ref = (ds->depth_stencil_info.stencilFrontRef & 0xff) << 24 |
1481 (ds->depth_stencil_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 Barbourde4124d2015-07-03 10:33:54 -06001494 const struct intel_dynamic_viewport *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 Barbourde4124d2015-07-03 10:33:54 -06001527 const struct intel_dynamic_color_blend *blend = cmd->bind.state.blend;
1528 const struct intel_dynamic_depth_stencil *ds = cmd->bind.state.depth;
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 Barbourde4124d2015-07-03 10:33:54 -06001543 memcpy(blend_color, blend->color_blend_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);
Tony Barbourde4124d2015-07-03 10:33:54 -06001549 stencil_ref = (ds->depth_stencil_info.stencilFrontRef & 0xff) << 24 |
1550 (ds->depth_stencil_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);
Tony Barbourde4124d2015-07-03 10:33:54 -06001554 stencil_ref = (ds->depth_stencil_info.stencilFrontRef & 0xff) << 24 |
1555 (ds->depth_stencil_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 Barbourde4124d2015-07-03 10:33:54 -06001567 const struct intel_dynamic_viewport *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;
Chia-I Wu1d125092014-10-08 08:49:38 +08001863 default:
1864 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001865 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001866 dw[3] = 0;
1867 break;
1868 }
1869
Chia-I Wu714df452015-01-01 07:55:04 +08001870 if (cmd->bind.vertex.buf[i]) {
1871 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001872 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001873
1874 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001875 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1876 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001877 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001878 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001879 dw[1] = 0;
1880 dw[2] = 0;
1881 }
1882
1883 dw += 4;
1884 pos += 4;
1885 }
1886}
1887
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001888static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1889{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001890 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1891 const struct intel_pipeline_shader *vs = &pipeline->vs;
1892 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001893 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001894 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001895 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001896 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001897
1898 CMD_ASSERT(cmd, 6, 7.5);
1899
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001900 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001901 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1902 *
1903 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1904 * 128-bit vertex elements to be passed into the payload for each
1905 * vertex."
1906 *
1907 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1908 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001909 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001910 vue_read_len = (vs->in_count + 1) / 2;
1911 if (!vue_read_len)
1912 vue_read_len = 1;
1913
1914 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1915 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1916
1917 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1918 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1919 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001920
1921 dw5 = GEN6_VS_DW5_STATISTICS |
1922 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001923
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001924 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001925 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001926 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001927 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001928
Chia-I Wube0a3d92014-09-02 13:20:59 +08001929 if (pipeline->disable_vs_cache)
1930 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1931
Chia-I Wu784d3042014-12-19 14:30:04 +08001932 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001933 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001934 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001935 dw[2] = dw2;
1936 dw[3] = 0; /* scratch */
1937 dw[4] = dw4;
1938 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001939
1940 if (vs->per_thread_scratch_size)
1941 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001942}
1943
Chia-I Wu625105f2014-10-13 15:35:29 +08001944static void emit_shader_resources(struct intel_cmd *cmd)
1945{
1946 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001947 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001948
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001949 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001950 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001952 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001953 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001954 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001955 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001956 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001957 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001958 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001959 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001960 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001961 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001962 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001963 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001964
1965 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1966 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1967 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1968 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1969 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1970
1971 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1972 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001973 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1974 binding_tables[0]);
1975 gen7_3dstate_pointer(cmd,
1976 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1977 binding_tables[1]);
1978 gen7_3dstate_pointer(cmd,
1979 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1980 binding_tables[2]);
1981 gen7_3dstate_pointer(cmd,
1982 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1983 binding_tables[3]);
1984 gen7_3dstate_pointer(cmd,
1985 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1986 binding_tables[4]);
1987
1988 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001989 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1990 samplers[0]);
1991 gen7_3dstate_pointer(cmd,
1992 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1993 samplers[1]);
1994 gen7_3dstate_pointer(cmd,
1995 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1996 samplers[2]);
1997 gen7_3dstate_pointer(cmd,
1998 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1999 samplers[3]);
2000 gen7_3dstate_pointer(cmd,
2001 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2002 samplers[4]);
2003 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002004 assert(!binding_tables[1] && !binding_tables[2]);
2005 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2006 binding_tables[0], binding_tables[3], binding_tables[4]);
2007
Chia-I Wu625105f2014-10-13 15:35:29 +08002008 assert(!samplers[1] && !samplers[2]);
2009 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2010 samplers[0], samplers[3], samplers[4]);
2011 }
2012}
2013
Chia-I Wu8ada4242015-03-02 11:19:33 -07002014static void emit_msaa(struct intel_cmd *cmd)
2015{
Chia-I Wuc278df82015-07-07 11:50:03 +08002016 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002017
Chia-I Wubbc7d912015-02-27 14:59:50 -07002018 if (!cmd->bind.render_pass_changed)
2019 return;
2020
Chia-I Wu8ada4242015-03-02 11:19:33 -07002021 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002022 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002023}
2024
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002025static void emit_rt(struct intel_cmd *cmd)
2026{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002027 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002028
2029 if (!cmd->bind.render_pass_changed)
2030 return;
2031
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002032 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002033 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2034 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002035}
2036
2037static void emit_ds(struct intel_cmd *cmd)
2038{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002039 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002040 const struct intel_render_pass_subpass *subpass =
2041 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002042 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002043 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002044 (subpass->ds_index < rp->attachment_count) ?
2045 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002046
Chia-I Wubbc7d912015-02-27 14:59:50 -07002047 if (!cmd->bind.render_pass_changed)
2048 return;
2049
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002050 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002051 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002052 static const struct intel_att_view null_view;
2053 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002054 }
2055
2056 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002057 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2058 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2059 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002060
2061 if (cmd_gen(cmd) >= INTEL_GEN(7))
2062 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2063 else
2064 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2065}
2066
Chia-I Wua57761b2014-10-14 14:27:44 +08002067static uint32_t emit_shader(struct intel_cmd *cmd,
2068 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002069{
Chia-I Wua57761b2014-10-14 14:27:44 +08002070 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2071 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002072 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002073
Chia-I Wua57761b2014-10-14 14:27:44 +08002074 /* see if the shader is already in the cache */
2075 for (i = 0; i < cache->used; i++) {
2076 if (cache->entries[i].shader == (const void *) shader)
2077 return cache->entries[i].kernel_offset;
2078 }
2079
2080 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2081
2082 /* grow the cache if full */
2083 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002084 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002085 void *entries;
2086
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002087 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002088 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002089 if (entries) {
2090 if (cache->entries) {
2091 memcpy(entries, cache->entries,
2092 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002093 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002094 }
2095
2096 cache->entries = entries;
2097 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002098 }
2099 }
2100
Chia-I Wua57761b2014-10-14 14:27:44 +08002101 /* add the shader to the cache */
2102 if (cache->used < cache->count) {
2103 cache->entries[cache->used].shader = (const void *) shader;
2104 cache->entries[cache->used].kernel_offset = offset;
2105 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002106 }
2107
Chia-I Wua57761b2014-10-14 14:27:44 +08002108 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002109}
2110
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002111static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002112{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002113 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002114
Chia-I Wu8370b402014-08-29 12:28:37 +08002115 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2116 cmd_wa_gen6_pre_depth_stall_write(cmd);
2117 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2118 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2119 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2120 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002121
2122 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002123 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002124 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002125
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002126 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002127 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002128 }
2129 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002130 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002131 }
2132 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002133 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2134 }
2135 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2136 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2137 }
2138 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2139 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002140 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002141
Chia-I Wu8370b402014-08-29 12:28:37 +08002142 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2143 cmd_wa_gen7_post_command_cs_stall(cmd);
2144 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2145 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002146}
2147
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002148static void emit_bounded_states(struct intel_cmd *cmd)
2149{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002150 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002151
2152 emit_graphics_pipeline(cmd);
2153
2154 emit_rt(cmd);
2155 emit_ds(cmd);
2156
2157 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2158 gen7_cc_states(cmd);
2159 gen7_viewport_states(cmd);
2160
2161 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2162 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002163 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2164 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002165 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2166 &cmd->bind.pipeline.graphics->fs);
2167
Cody Northrop293d4502015-05-05 09:38:03 -06002168 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002169 gen6_3DSTATE_CLIP(cmd);
2170 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002171 gen7_3DSTATE_WM(cmd);
2172 gen7_3DSTATE_PS(cmd);
2173 } else {
2174 gen6_cc_states(cmd);
2175 gen6_viewport_states(cmd);
2176
2177 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2178 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002179 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2180 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002181 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2182 &cmd->bind.pipeline.graphics->fs);
2183
Cody Northrop293d4502015-05-05 09:38:03 -06002184 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002185 gen6_3DSTATE_CLIP(cmd);
2186 gen6_3DSTATE_SF(cmd);
2187 gen6_3DSTATE_WM(cmd);
2188 }
2189
2190 emit_shader_resources(cmd);
2191
2192 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002193
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002194 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2195 gen6_3DSTATE_VS(cmd);
2196}
2197
Tony Barbourfa6cac72015-01-16 14:27:35 -07002198static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002199 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002200{
2201 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2202 const uint8_t cmd_len = 3;
2203 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002204
2205 CMD_ASSERT(cmd, 6, 7.5);
2206
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002207 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002208 dw[0] = 0;
2209 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002210
2211 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2212 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2213 GEN6_COMPAREFUNCTION_NEVER << 27 |
2214 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2215 } else {
2216 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2217 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2218 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002219 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002220 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002221 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2222 (GEN6_STENCILOP_KEEP) << 25 |
2223 (GEN6_STENCILOP_KEEP) << 22 |
2224 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002225 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2226 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002227 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2228 (GEN6_STENCILOP_KEEP) << 9 |
2229 (GEN6_STENCILOP_KEEP) << 6 |
2230 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002231
Chia-I Wud850a392015-02-19 11:08:25 -07002232 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2233 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2234 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2235 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2236 dw[2] = 0;
2237 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002238
2239 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2240 cmd_align, cmd_len, dw);
2241}
2242
Chia-I Wu6032b892014-10-17 14:47:18 +08002243static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2244{
2245 const struct intel_cmd_meta *meta = cmd->bind.meta;
2246 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2247
2248 CMD_ASSERT(cmd, 6, 7.5);
2249
2250 blend_offset = 0;
2251 ds_offset = 0;
2252 cc_offset = 0;
2253 cc_vp_offset = 0;
2254
Chia-I Wu29e6f502014-11-24 14:27:29 +08002255 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002256 /* BLEND_STATE */
2257 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002258 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002259 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002260 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002261 }
2262
Chia-I Wu29e6f502014-11-24 14:27:29 +08002263 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002264 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002265 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002266 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2267 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002268
Chia-I Wu29e6f502014-11-24 14:27:29 +08002269 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002270 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002271
Chia-I Wu29e6f502014-11-24 14:27:29 +08002272 /* COLOR_CALC_STATE */
2273 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002274 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002275
Chia-I Wu29e6f502014-11-24 14:27:29 +08002276 /* CC_VIEWPORT */
2277 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002278 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 dw[0] = u_fui(0.0f);
2280 dw[1] = u_fui(1.0f);
2281 } else {
2282 /* DEPTH_STENCIL_STATE */
2283 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002284 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002285 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2286 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2287 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002288 }
2289
2290 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2291 gen7_3dstate_pointer(cmd,
2292 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2293 blend_offset);
2294 gen7_3dstate_pointer(cmd,
2295 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2296 ds_offset);
2297 gen7_3dstate_pointer(cmd,
2298 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2299
2300 gen7_3dstate_pointer(cmd,
2301 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2302 cc_vp_offset);
2303 } else {
2304 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002305 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002306
2307 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2308 cmd_batch_pointer(cmd, 4, &dw);
2309 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002310 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002311 dw[1] = 0;
2312 dw[2] = 0;
2313 dw[3] = cc_vp_offset;
2314 }
2315}
2316
2317static void gen6_meta_surface_states(struct intel_cmd *cmd)
2318{
2319 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002320 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002321 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002322 const uint32_t sba_offset =
2323 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002324
2325 CMD_ASSERT(cmd, 6, 7.5);
2326
Chia-I Wu29e6f502014-11-24 14:27:29 +08002327 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2328 return;
2329
Chia-I Wu005c47c2014-10-22 13:49:13 +08002330 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002331 if (meta->src.valid) {
2332 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002333 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002334 meta->src.surface_len, meta->src.surface);
2335
2336 cmd_reserve_reloc(cmd, 1);
2337 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2338 cmd_surface_reloc_writer(cmd, offset, 1,
2339 meta->src.reloc_target, meta->src.reloc_offset);
2340 } else {
2341 cmd_surface_reloc(cmd, offset, 1,
2342 (struct intel_bo *) meta->src.reloc_target,
2343 meta->src.reloc_offset, meta->src.reloc_flags);
2344 }
2345
Mike Stroyan9bfad482015-02-10 15:09:23 -07002346 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002347 }
2348 if (meta->dst.valid) {
2349 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002350 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002351 meta->dst.surface_len, meta->dst.surface);
2352
2353 cmd_reserve_reloc(cmd, 1);
2354 cmd_surface_reloc(cmd, offset, 1,
2355 (struct intel_bo *) meta->dst.reloc_target,
2356 meta->dst.reloc_offset, meta->dst.reloc_flags);
2357
Mike Stroyan9bfad482015-02-10 15:09:23 -07002358 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002359 }
2360
2361 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002362 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002363 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002364 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002365
2366 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002367 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2368 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2369 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002370 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002371 } else {
2372 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002373 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002374 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002375 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002376 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002377 }
2378}
2379
2380static void gen6_meta_urb(struct intel_cmd *cmd)
2381{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002382 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002383 uint32_t *dw;
2384
2385 CMD_ASSERT(cmd, 6, 6);
2386
2387 /* 3DSTATE_URB */
2388 cmd_batch_pointer(cmd, 3, &dw);
2389 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002390 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002391 dw[2] = 0;
2392}
2393
2394static void gen7_meta_urb(struct intel_cmd *cmd)
2395{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002396 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2397 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002398 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002399 uint32_t *dw;
2400
2401 CMD_ASSERT(cmd, 7, 7.5);
2402
Chia-I Wu6032b892014-10-17 14:47:18 +08002403 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2404
Chia-I Wu24aa1022014-11-25 11:53:19 +08002405 switch (cmd_gen(cmd)) {
2406 case INTEL_GEN(7.5):
2407 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2408 break;
2409 case INTEL_GEN(7):
2410 default:
2411 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2412 break;
2413 }
2414
Chia-I Wu6032b892014-10-17 14:47:18 +08002415 /* 3DSTATE_URB_x */
2416 cmd_batch_pointer(cmd, 8, &dw);
2417
2418 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002419 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002420 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002421 dw += 2;
2422
2423 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002424 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002425 dw += 2;
2426
2427 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (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_GS) | (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
2436static void gen6_meta_vf(struct intel_cmd *cmd)
2437{
2438 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002439 uint32_t vb_start, vb_end, vb_stride;
2440 int ve_format, ve_z_source;
2441 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002442 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002443
2444 CMD_ASSERT(cmd, 6, 7.5);
2445
Chia-I Wu29e6f502014-11-24 14:27:29 +08002446 switch (meta->mode) {
2447 case INTEL_CMD_META_VS_POINTS:
2448 cmd_batch_pointer(cmd, 3, &dw);
2449 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002450 dw[1] = GEN6_VE_DW0_VALID;
2451 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2452 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2453 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2454 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002455 return;
2456 break;
2457 case INTEL_CMD_META_FS_RECT:
2458 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002459 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002460
Chia-I Wu29e6f502014-11-24 14:27:29 +08002461 vertices[0][0] = meta->dst.x + meta->width;
2462 vertices[0][1] = meta->dst.y + meta->height;
2463 vertices[1][0] = meta->dst.x;
2464 vertices[1][1] = meta->dst.y + meta->height;
2465 vertices[2][0] = meta->dst.x;
2466 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002467
Chia-I Wu29e6f502014-11-24 14:27:29 +08002468 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2469 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002470
Chia-I Wu29e6f502014-11-24 14:27:29 +08002471 vb_end = vb_start + sizeof(vertices) - 1;
2472 vb_stride = sizeof(vertices[0]);
2473 ve_z_source = GEN6_VFCOMP_STORE_0;
2474 ve_format = GEN6_FORMAT_R32G32_USCALED;
2475 }
2476 break;
2477 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2478 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002479 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002480
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002481 vertices[0][0] = (float) (meta->dst.x + meta->width);
2482 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002483 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002484 vertices[1][0] = (float) meta->dst.x;
2485 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002486 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002487 vertices[2][0] = (float) meta->dst.x;
2488 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002489 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002490
Chia-I Wu29e6f502014-11-24 14:27:29 +08002491 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2492 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002493
Chia-I Wu29e6f502014-11-24 14:27:29 +08002494 vb_end = vb_start + sizeof(vertices) - 1;
2495 vb_stride = sizeof(vertices[0]);
2496 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2497 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2498 }
2499 break;
2500 default:
2501 assert(!"unknown meta mode");
2502 return;
2503 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002504 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002505
2506 /* 3DSTATE_VERTEX_BUFFERS */
2507 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002508
Chia-I Wu6032b892014-10-17 14:47:18 +08002509 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002510 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002511 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002512 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002513
2514 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002515 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2516 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002517
2518 dw[4] = 0;
2519
2520 /* 3DSTATE_VERTEX_ELEMENTS */
2521 cmd_batch_pointer(cmd, 5, &dw);
2522 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002523 dw[1] = GEN6_VE_DW0_VALID;
2524 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2525 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2526 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2527 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2528 dw[3] = GEN6_VE_DW0_VALID |
2529 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2530 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2531 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2532 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2533 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002534}
2535
Chia-I Wu29e6f502014-11-24 14:27:29 +08002536static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002537{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002538 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002539 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002540 uint32_t consts[8];
2541 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002542
2543 CMD_ASSERT(cmd, 6, 7.5);
2544
2545 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002546 case INTEL_DEV_META_VS_FILL_MEM:
2547 consts[0] = meta->dst.x;
2548 consts[1] = meta->clear_val[0];
2549 const_count = 2;
2550 break;
2551 case INTEL_DEV_META_VS_COPY_MEM:
2552 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2553 consts[0] = meta->dst.x;
2554 consts[1] = meta->src.x;
2555 const_count = 2;
2556 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002557 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2558 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2559 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2560 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2561 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2562 consts[0] = meta->src.x;
2563 consts[1] = meta->src.y;
2564 consts[2] = meta->width;
2565 consts[3] = meta->dst.x;
2566 const_count = 4;
2567 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568 default:
2569 assert(!"unknown meta shader id");
2570 const_count = 0;
2571 break;
2572 }
2573
2574 /* this can be skipped but it makes state dumping prettier */
2575 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2576
2577 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2578}
2579
2580static void gen6_meta_vs(struct intel_cmd *cmd)
2581{
2582 const struct intel_cmd_meta *meta = cmd->bind.meta;
2583 const struct intel_pipeline_shader *sh =
2584 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2585 uint32_t offset, *dw;
2586
2587 CMD_ASSERT(cmd, 6, 7.5);
2588
2589 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002590 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002591
2592 /* 3DSTATE_CONSTANT_VS */
2593 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2594 cmd_batch_pointer(cmd, cmd_len, &dw);
2595 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2596 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2597
2598 /* 3DSTATE_VS */
2599 cmd_batch_pointer(cmd, 6, &dw);
2600 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2601 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2602
2603 return;
2604 }
2605
2606 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2607
2608 /* 3DSTATE_CONSTANT_VS */
2609 offset = gen6_meta_vs_constants(cmd);
2610 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2611 cmd_batch_pointer(cmd, 7, &dw);
2612 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002613 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002614 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002615 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002616 dw[4] = 0;
2617 dw[5] = 0;
2618 dw[6] = 0;
2619 } else {
2620 cmd_batch_pointer(cmd, 5, &dw);
2621 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002622 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002623 dw[1] = offset;
2624 dw[2] = 0;
2625 dw[3] = 0;
2626 dw[4] = 0;
2627 }
2628
2629 /* 3DSTATE_VS */
2630 offset = emit_shader(cmd, sh);
2631 cmd_batch_pointer(cmd, 6, &dw);
2632 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2633 dw[1] = offset;
2634 dw[2] = GEN6_THREADDISP_SPF |
2635 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2636 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002637 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002638 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2639 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2640
2641 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2642 GEN6_VS_DW5_VS_ENABLE;
2643 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002644 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002645 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002646 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002647
2648 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002649}
2650
2651static void gen6_meta_disabled(struct intel_cmd *cmd)
2652{
Chia-I Wu6032b892014-10-17 14:47:18 +08002653 uint32_t *dw;
2654
2655 CMD_ASSERT(cmd, 6, 6);
2656
Chia-I Wu6032b892014-10-17 14:47:18 +08002657 /* 3DSTATE_CONSTANT_GS */
2658 cmd_batch_pointer(cmd, 5, &dw);
2659 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2660 dw[1] = 0;
2661 dw[2] = 0;
2662 dw[3] = 0;
2663 dw[4] = 0;
2664
2665 /* 3DSTATE_GS */
2666 cmd_batch_pointer(cmd, 7, &dw);
2667 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2668 dw[1] = 0;
2669 dw[2] = 0;
2670 dw[3] = 0;
2671 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2672 dw[5] = GEN6_GS_DW5_STATISTICS;
2673 dw[6] = 0;
2674
Chia-I Wu6032b892014-10-17 14:47:18 +08002675 /* 3DSTATE_SF */
2676 cmd_batch_pointer(cmd, 20, &dw);
2677 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2678 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2679 memset(&dw[2], 0, 18 * sizeof(*dw));
2680}
2681
2682static void gen7_meta_disabled(struct intel_cmd *cmd)
2683{
2684 uint32_t *dw;
2685
2686 CMD_ASSERT(cmd, 7, 7.5);
2687
Chia-I Wu6032b892014-10-17 14:47:18 +08002688 /* 3DSTATE_CONSTANT_HS */
2689 cmd_batch_pointer(cmd, 7, &dw);
2690 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2691 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2692
2693 /* 3DSTATE_HS */
2694 cmd_batch_pointer(cmd, 7, &dw);
2695 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2696 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2697
2698 /* 3DSTATE_TE */
2699 cmd_batch_pointer(cmd, 4, &dw);
2700 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2701 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2702
2703 /* 3DSTATE_CONSTANT_DS */
2704 cmd_batch_pointer(cmd, 7, &dw);
2705 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2706 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2707
2708 /* 3DSTATE_DS */
2709 cmd_batch_pointer(cmd, 6, &dw);
2710 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2711 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2712
2713 /* 3DSTATE_CONSTANT_GS */
2714 cmd_batch_pointer(cmd, 7, &dw);
2715 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2716 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2717
2718 /* 3DSTATE_GS */
2719 cmd_batch_pointer(cmd, 7, &dw);
2720 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2721 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2722
2723 /* 3DSTATE_STREAMOUT */
2724 cmd_batch_pointer(cmd, 3, &dw);
2725 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2726 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2727
Chia-I Wu6032b892014-10-17 14:47:18 +08002728 /* 3DSTATE_SF */
2729 cmd_batch_pointer(cmd, 7, &dw);
2730 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2731 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2732
2733 /* 3DSTATE_SBE */
2734 cmd_batch_pointer(cmd, 14, &dw);
2735 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2736 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2737 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002738}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002739
Chia-I Wu29e6f502014-11-24 14:27:29 +08002740static void gen6_meta_clip(struct intel_cmd *cmd)
2741{
2742 const struct intel_cmd_meta *meta = cmd->bind.meta;
2743 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002744
Chia-I Wu29e6f502014-11-24 14:27:29 +08002745 /* 3DSTATE_CLIP */
2746 cmd_batch_pointer(cmd, 4, &dw);
2747 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2748 dw[1] = 0;
2749 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2750 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2751 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2752 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002753 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002754 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002755 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002756}
2757
2758static void gen6_meta_wm(struct intel_cmd *cmd)
2759{
2760 const struct intel_cmd_meta *meta = cmd->bind.meta;
2761 uint32_t *dw;
2762
2763 CMD_ASSERT(cmd, 6, 7.5);
2764
2765 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2766
2767 /* 3DSTATE_MULTISAMPLE */
2768 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2769 cmd_batch_pointer(cmd, 4, &dw);
2770 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2771 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2772 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2773 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2774 dw[2] = 0;
2775 dw[3] = 0;
2776 } else {
2777 cmd_batch_pointer(cmd, 3, &dw);
2778 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2779 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2780 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2781 dw[2] = 0;
2782 }
2783
2784 /* 3DSTATE_SAMPLE_MASK */
2785 cmd_batch_pointer(cmd, 2, &dw);
2786 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2787 dw[1] = (1 << meta->samples) - 1;
2788
2789 /* 3DSTATE_DRAWING_RECTANGLE */
2790 cmd_batch_pointer(cmd, 4, &dw);
2791 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002792 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2793 /* unused */
2794 dw[1] = 0;
2795 dw[2] = 0;
2796 } else {
2797 dw[1] = meta->dst.y << 16 | meta->dst.x;
2798 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2799 (meta->dst.x + meta->width - 1);
2800 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002801 dw[3] = 0;
2802}
2803
2804static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2805{
2806 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002807 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002808 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002809 uint32_t consts[8];
2810 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002811
2812 CMD_ASSERT(cmd, 6, 7.5);
2813
2814 /* underflow is fine here */
2815 offset_x = meta->src.x - meta->dst.x;
2816 offset_y = meta->src.y - meta->dst.y;
2817
2818 switch (meta->shader_id) {
2819 case INTEL_DEV_META_FS_COPY_MEM:
2820 case INTEL_DEV_META_FS_COPY_1D:
2821 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2822 case INTEL_DEV_META_FS_COPY_2D:
2823 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2824 case INTEL_DEV_META_FS_COPY_2D_MS:
2825 consts[0] = offset_x;
2826 consts[1] = offset_y;
2827 consts[2] = meta->src.layer;
2828 consts[3] = meta->src.lod;
2829 const_count = 4;
2830 break;
2831 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2832 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2833 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2834 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2835 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2836 consts[0] = offset_x;
2837 consts[1] = offset_y;
2838 consts[2] = meta->src.layer;
2839 consts[3] = meta->src.lod;
2840 consts[4] = meta->src.x;
2841 consts[5] = meta->width;
2842 const_count = 6;
2843 break;
2844 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2845 consts[0] = offset_x;
2846 consts[1] = offset_y;
2847 consts[2] = meta->width;
2848 const_count = 3;
2849 break;
2850 case INTEL_DEV_META_FS_CLEAR_COLOR:
2851 consts[0] = meta->clear_val[0];
2852 consts[1] = meta->clear_val[1];
2853 consts[2] = meta->clear_val[2];
2854 consts[3] = meta->clear_val[3];
2855 const_count = 4;
2856 break;
2857 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2858 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002859 consts[1] = meta->clear_val[1];
2860 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002861 break;
2862 case INTEL_DEV_META_FS_RESOLVE_2X:
2863 case INTEL_DEV_META_FS_RESOLVE_4X:
2864 case INTEL_DEV_META_FS_RESOLVE_8X:
2865 case INTEL_DEV_META_FS_RESOLVE_16X:
2866 consts[0] = offset_x;
2867 consts[1] = offset_y;
2868 const_count = 2;
2869 break;
2870 default:
2871 assert(!"unknown meta shader id");
2872 const_count = 0;
2873 break;
2874 }
2875
2876 /* this can be skipped but it makes state dumping prettier */
2877 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2878
2879 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2880}
2881
2882static void gen6_meta_ps(struct intel_cmd *cmd)
2883{
2884 const struct intel_cmd_meta *meta = cmd->bind.meta;
2885 const struct intel_pipeline_shader *sh =
2886 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2887 uint32_t offset, *dw;
2888
2889 CMD_ASSERT(cmd, 6, 6);
2890
Chia-I Wu29e6f502014-11-24 14:27:29 +08002891 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2892 /* 3DSTATE_CONSTANT_PS */
2893 cmd_batch_pointer(cmd, 5, &dw);
2894 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2895 dw[1] = 0;
2896 dw[2] = 0;
2897 dw[3] = 0;
2898 dw[4] = 0;
2899
2900 /* 3DSTATE_WM */
2901 cmd_batch_pointer(cmd, 9, &dw);
2902 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2903 dw[1] = 0;
2904 dw[2] = 0;
2905 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002906
2907 switch (meta->ds.op) {
2908 case INTEL_CMD_META_DS_HIZ_CLEAR:
2909 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2910 break;
2911 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2912 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2913 break;
2914 case INTEL_CMD_META_DS_RESOLVE:
2915 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2916 break;
2917 default:
2918 dw[4] = 0;
2919 break;
2920 }
2921
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002922 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002923 dw[6] = 0;
2924 dw[7] = 0;
2925 dw[8] = 0;
2926
Chia-I Wu3adf7212014-10-24 15:34:07 +08002927 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002928 }
2929
Chia-I Wu3adf7212014-10-24 15:34:07 +08002930 /* a normal color write */
2931 assert(meta->dst.valid && !sh->uses);
2932
Chia-I Wu6032b892014-10-17 14:47:18 +08002933 /* 3DSTATE_CONSTANT_PS */
2934 offset = gen6_meta_ps_constants(cmd);
2935 cmd_batch_pointer(cmd, 5, &dw);
2936 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002937 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002938 dw[1] = offset;
2939 dw[2] = 0;
2940 dw[3] = 0;
2941 dw[4] = 0;
2942
2943 /* 3DSTATE_WM */
2944 offset = emit_shader(cmd, sh);
2945 cmd_batch_pointer(cmd, 9, &dw);
2946 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2947 dw[1] = offset;
2948 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2949 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002950 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002951 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002952 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002953 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2954 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002955
Chia-I Wu6032b892014-10-17 14:47:18 +08002956 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002957 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002958 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2959 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2960 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2961 if (meta->samples > 1) {
2962 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2963 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2964 } else {
2965 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2966 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2967 }
2968 dw[7] = 0;
2969 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002970
2971 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002972}
2973
2974static void gen7_meta_ps(struct intel_cmd *cmd)
2975{
2976 const struct intel_cmd_meta *meta = cmd->bind.meta;
2977 const struct intel_pipeline_shader *sh =
2978 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2979 uint32_t offset, *dw;
2980
2981 CMD_ASSERT(cmd, 7, 7.5);
2982
Chia-I Wu29e6f502014-11-24 14:27:29 +08002983 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2984 /* 3DSTATE_WM */
2985 cmd_batch_pointer(cmd, 3, &dw);
2986 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07002987
2988 switch (meta->ds.op) {
2989 case INTEL_CMD_META_DS_HIZ_CLEAR:
2990 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
2991 break;
2992 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2993 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
2994 break;
2995 case INTEL_CMD_META_DS_RESOLVE:
2996 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
2997 break;
2998 default:
2999 dw[1] = 0;
3000 break;
3001 }
3002
3003 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003004
3005 /* 3DSTATE_CONSTANT_GS */
3006 cmd_batch_pointer(cmd, 7, &dw);
3007 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3008 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3009
3010 /* 3DSTATE_PS */
3011 cmd_batch_pointer(cmd, 8, &dw);
3012 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3013 dw[1] = 0;
3014 dw[2] = 0;
3015 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003016 /* required to avoid hangs */
3017 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003018 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003019 dw[5] = 0;
3020 dw[6] = 0;
3021 dw[7] = 0;
3022
Chia-I Wu3adf7212014-10-24 15:34:07 +08003023 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003024 }
3025
Chia-I Wu3adf7212014-10-24 15:34:07 +08003026 /* a normal color write */
3027 assert(meta->dst.valid && !sh->uses);
3028
Chia-I Wu6032b892014-10-17 14:47:18 +08003029 /* 3DSTATE_WM */
3030 cmd_batch_pointer(cmd, 3, &dw);
3031 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003032 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003033 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3034 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3035 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3036 dw[2] = 0;
3037
3038 /* 3DSTATE_CONSTANT_PS */
3039 offset = gen6_meta_ps_constants(cmd);
3040 cmd_batch_pointer(cmd, 7, &dw);
3041 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003042 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003043 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003044 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003045 dw[4] = 0;
3046 dw[5] = 0;
3047 dw[6] = 0;
3048
3049 /* 3DSTATE_PS */
3050 offset = emit_shader(cmd, sh);
3051 cmd_batch_pointer(cmd, 8, &dw);
3052 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3053 dw[1] = offset;
3054 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3055 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003056 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003057
3058 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3059 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003060 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003061
3062 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003063 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003064 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003065 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003066 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003067 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003068
3069 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3070 dw[6] = 0;
3071 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003072
3073 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003074}
3075
3076static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3077{
3078 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003079 const struct intel_att_view *view = meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003080
3081 CMD_ASSERT(cmd, 6, 7.5);
3082
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003083 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003084 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003085 static const struct intel_att_view null_view;
3086 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003087 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003088
3089 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003090 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3091 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3092 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003093
3094 if (cmd_gen(cmd) >= INTEL_GEN(7))
3095 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3096 else
3097 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003098}
3099
Chia-I Wu862c5572015-03-28 15:23:55 +08003100static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3101 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003102 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003103{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003104 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003105 if (data->set_offsets)
3106 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003107
Chia-I Wu862c5572015-03-28 15:23:55 +08003108 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003109 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003110 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003111 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003112 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003113 data->set_offset_count = 0;
3114 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003115 }
3116
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003117 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003118 }
3119
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003120 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003121 if (data->dynamic_offsets)
3122 intel_free(cmd, data->dynamic_offsets);
3123
3124 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003125 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003126 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003127 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003128 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003129 data->dynamic_offset_count = 0;
3130 return false;
3131 }
3132
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003133 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003134 }
3135
3136 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003137}
3138
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003139static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3140 const struct intel_pipeline *pipeline)
3141{
3142 cmd->bind.pipeline.graphics = pipeline;
3143
3144 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003145 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003146}
3147
3148static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3149 const struct intel_pipeline *pipeline)
3150{
3151 cmd->bind.pipeline.compute = pipeline;
3152
3153 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003154 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003155}
3156
Chia-I Wu862c5572015-03-28 15:23:55 +08003157static void cmd_copy_dset_data(struct intel_cmd *cmd,
3158 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003159 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003160 uint32_t index,
3161 const struct intel_desc_set *set,
3162 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003163{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003164 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003165
Chia-I Wu862c5572015-03-28 15:23:55 +08003166 assert(index < data->set_offset_count);
3167 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003168
Chia-I Wu862c5572015-03-28 15:23:55 +08003169 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003170 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003171 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003172
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003173 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003174 dynamic_offsets,
3175 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003176 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003177}
3178
Chia-I Wu3b04af52014-11-08 10:48:20 +08003179static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003180 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003181 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003182{
Chia-I Wu714df452015-01-01 07:55:04 +08003183 if (binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003184 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003185 return;
3186 }
3187
Chia-I Wu714df452015-01-01 07:55:04 +08003188 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003189 cmd->bind.vertex.offset[binding] = offset;
3190}
3191
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003192static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003193 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003194 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003195{
Chia-I Wu714df452015-01-01 07:55:04 +08003196 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003197 cmd->bind.index.offset = offset;
3198 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003199}
3200
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003201static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003202 const struct intel_dynamic_viewport *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003203{
3204 cmd->bind.state.viewport = state;
3205}
3206
3207static void cmd_bind_raster_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003208 const struct intel_dynamic_raster *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003209{
3210 cmd->bind.state.raster = state;
3211}
3212
Tony Barbourde4124d2015-07-03 10:33:54 -06003213static void cmd_bind_depth_stencil_state(struct intel_cmd *cmd,
3214 const struct intel_dynamic_depth_stencil *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215{
Tony Barbourde4124d2015-07-03 10:33:54 -06003216 cmd->bind.state.depth = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217}
3218
3219static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003220 const struct intel_dynamic_color_blend *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003221{
3222 cmd->bind.state.blend = state;
3223}
3224
Chia-I Wuf98dd882015-02-10 04:17:47 +08003225static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3226{
3227 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3228 struct intel_pipeline_rmap *rmaps[5] = {
3229 pipeline->vs.rmap,
3230 pipeline->tcs.rmap,
3231 pipeline->tes.rmap,
3232 pipeline->gs.rmap,
3233 pipeline->fs.rmap,
3234 };
3235 uint32_t max_write;
3236 int i;
3237
3238 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3239 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3240 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3241
3242 /* pad first */
3243 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3244
3245 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3246 const struct intel_pipeline_rmap *rmap = rmaps[i];
3247 const uint32_t surface_count = (rmap) ?
3248 rmap->rt_count + rmap->texture_resource_count +
3249 rmap->resource_count + rmap->uav_count : 0;
3250
3251 if (surface_count) {
3252 /* SURFACE_STATEs */
3253 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3254
3255 /* BINDING_TABLE_STATE */
3256 max_write += u_align(sizeof(uint32_t) * surface_count,
3257 GEN6_ALIGNMENT_SURFACE_STATE);
3258 }
3259 }
3260
3261 return max_write;
3262}
3263
3264static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3265{
3266 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3267 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3268 uint32_t max_surface_write;
3269
3270 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3271 if (cmd->bind.meta)
3272 max_surface_write = 64 * sizeof(uint32_t);
3273 else
3274 max_surface_write = cmd_get_max_surface_write(cmd);
3275
3276 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3277 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3278 /* SBA expects page-aligned addresses */
3279 writer->sba_offset = writer->used & ~0xfff;
3280
3281 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3282
3283 cmd_batch_state_base_address(cmd);
3284 }
3285}
3286
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003287static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003288 uint32_t vertex_start,
3289 uint32_t vertex_count,
3290 uint32_t instance_start,
3291 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003292 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003293 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003294{
3295 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003296 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003297 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3298
3299 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003300
3301 emit_bounded_states(cmd);
3302
Chia-I Wuf98dd882015-02-10 04:17:47 +08003303 /* sanity check on cmd_get_max_surface_write() */
3304 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3305 surface_writer_used <= cmd_get_max_surface_write(cmd));
3306
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003307 if (indexed) {
3308 if (p->primitive_restart && !gen6_can_primitive_restart(cmd))
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003309 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003310
3311 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3312 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3313 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003314 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003315 cmd->bind.index.offset, cmd->bind.index.type,
3316 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003317 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003318 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003319 cmd->bind.index.offset, cmd->bind.index.type,
3320 p->primitive_restart);
3321 }
3322 } else {
3323 assert(!vertex_base);
3324 }
3325
3326 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3327 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3328 vertex_start, instance_count, instance_start, vertex_base);
3329 } else {
3330 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3331 vertex_start, instance_count, instance_start, vertex_base);
3332 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003333
Chia-I Wu707a29e2014-08-27 12:51:47 +08003334 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003335 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003336 /* need to re-emit all workarounds */
3337 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003338
3339 if (intel_debug & INTEL_DEBUG_NOCACHE)
3340 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003341}
3342
Chia-I Wuc14d1562014-10-17 09:49:22 +08003343void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3344{
Chia-I Wu6032b892014-10-17 14:47:18 +08003345 cmd->bind.meta = meta;
3346
Chia-I Wuf98dd882015-02-10 04:17:47 +08003347 cmd_adjust_state_base_address(cmd);
3348
Chia-I Wu6032b892014-10-17 14:47:18 +08003349 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003350 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003351
3352 gen6_meta_dynamic_states(cmd);
3353 gen6_meta_surface_states(cmd);
3354
3355 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3356 gen7_meta_urb(cmd);
3357 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003358 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003359 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003360 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003361 gen6_meta_wm(cmd);
3362 gen7_meta_ps(cmd);
3363 gen6_meta_depth_buffer(cmd);
3364
3365 cmd_wa_gen7_post_command_cs_stall(cmd);
3366 cmd_wa_gen7_post_command_depth_stall(cmd);
3367
Chia-I Wu29e6f502014-11-24 14:27:29 +08003368 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3369 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003370 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003371 } else {
3372 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3373 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003374 } else {
3375 gen6_meta_urb(cmd);
3376 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003377 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003378 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003379 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003380 gen6_meta_wm(cmd);
3381 gen6_meta_ps(cmd);
3382 gen6_meta_depth_buffer(cmd);
3383
Chia-I Wu29e6f502014-11-24 14:27:29 +08003384 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3385 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003386 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003387 } else {
3388 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3389 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003390 }
3391
3392 cmd->bind.draw_count++;
3393 /* need to re-emit all workarounds */
3394 cmd->bind.wa_flags = 0;
3395
3396 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003397
Chia-I Wubbc7d912015-02-27 14:59:50 -07003398 /* make the normal path believe the render pass has changed */
3399 cmd->bind.render_pass_changed = true;
3400
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003401 if (intel_debug & INTEL_DEBUG_NOCACHE)
3402 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003403}
3404
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003405static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3406{
3407 const uint8_t cmd_len = 2;
3408 uint32_t *dw;
3409 uint32_t pos;
3410
3411 if (cmd_gen(cmd) < INTEL_GEN(7.5)) {
3412 cmd->result = VK_ERROR_UNKNOWN;
3413 return;
3414 }
3415
3416 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3417 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3418 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3419 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3420 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3421
3422 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3423}
3424
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003425ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003426 VkCmdBuffer cmdBuffer,
3427 VkPipelineBindPoint pipelineBindPoint,
3428 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003429{
3430 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3431
3432 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003433 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003434 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003435 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003436 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003437 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003438 break;
3439 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003440 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003441 break;
3442 }
3443}
3444
Tony Barbourde4124d2015-07-03 10:33:54 -06003445ICD_EXPORT void VKAPI vkCmdBindDynamicViewportState(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003446 VkCmdBuffer cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003447 VkDynamicViewportState state)
Chia-I Wub2755562014-08-20 13:38:52 +08003448{
3449 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3450
Tony Barbourde4124d2015-07-03 10:33:54 -06003451 cmd_bind_viewport_state(cmd,
3452 intel_dynamic_viewport(state));
3453}
3454
3455ICD_EXPORT void VKAPI vkCmdBindDynamicRasterState(
3456 VkCmdBuffer cmdBuffer,
3457 VkDynamicRasterState state)
3458{
3459 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3460
3461 cmd_bind_raster_state(cmd,
3462 intel_dynamic_raster(state));
3463}
3464
3465ICD_EXPORT void VKAPI vkCmdBindDynamicColorBlendState(
3466 VkCmdBuffer cmdBuffer,
3467 VkDynamicColorBlendState state)
3468{
3469 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3470
3471 cmd_bind_blend_state(cmd,
3472 intel_dynamic_color_blend(state));
3473}
3474
3475ICD_EXPORT void VKAPI vkCmdBindDynamicDepthStencilState(
3476 VkCmdBuffer cmdBuffer,
3477 VkDynamicDepthStencilState state)
3478{
3479 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3480
3481 cmd_bind_depth_stencil_state(cmd,
3482 intel_dynamic_depth_stencil(state));
Chia-I Wub2755562014-08-20 13:38:52 +08003483}
3484
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003485ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003486 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003487 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003488 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003489 uint32_t firstSet,
3490 uint32_t setCount,
3491 const VkDescriptorSet* pDescriptorSets,
3492 uint32_t dynamicOffsetCount,
3493 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003494{
3495 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003496 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003497 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003498 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003499 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003500
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003501 pipeline_layout = intel_pipeline_layout(layout);
3502
Chia-I Wub2755562014-08-20 13:38:52 +08003503 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003504 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003505 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003506 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003507 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003508 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003509 break;
3510 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003511 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003512 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003513 break;
3514 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003515
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003516 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003517 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3518
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003519 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003520 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003521 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003522 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003523 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003524 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003525 }
Chia-I Wub2755562014-08-20 13:38:52 +08003526}
3527
Tony Barbour8205d902015-04-16 15:59:00 -06003528
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003529ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3530 VkCmdBuffer cmdBuffer,
3531 uint32_t startBinding,
3532 uint32_t bindingCount,
3533 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003534 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003535{
3536 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003537
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003538 for (uint32_t i = 0; i < bindingCount; i++) {
3539 struct intel_buf *buf = intel_buf(pBuffers[i]);
3540 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3541 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003542}
3543
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003544ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003545 VkCmdBuffer cmdBuffer,
3546 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003547 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003548 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003549{
3550 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003551 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003552
Chia-I Wu714df452015-01-01 07:55:04 +08003553 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003554}
3555
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003556ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003557 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003558 uint32_t firstVertex,
3559 uint32_t vertexCount,
3560 uint32_t firstInstance,
3561 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003562{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003563 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003564
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003565 cmd_draw(cmd, firstVertex, vertexCount,
3566 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003567}
3568
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003569ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003570 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003571 uint32_t firstIndex,
3572 uint32_t indexCount,
3573 int32_t vertexOffset,
3574 uint32_t firstInstance,
3575 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003576{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003577 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003578
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003579 cmd_draw(cmd, firstIndex, indexCount,
3580 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003581}
3582
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003583ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003584 VkCmdBuffer cmdBuffer,
3585 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003586 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003587 uint32_t count,
3588 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003589{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003590 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3591
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003592 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003593}
3594
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003595ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003596 VkCmdBuffer cmdBuffer,
3597 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003598 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003599 uint32_t count,
3600 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003601{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003602 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3603
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003604 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003605}
3606
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003607ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003608 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003609 uint32_t x,
3610 uint32_t y,
3611 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003612{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003613 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3614
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003615 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003616}
3617
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003618ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003619 VkCmdBuffer cmdBuffer,
3620 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003621 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003622{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003623 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3624
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003625 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003626}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003627
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003628ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003629 VkCmdBuffer cmdBuffer,
3630 const VkRenderPassBeginInfo* pRenderPassBegin,
3631 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003632{
Chia-I Wubdeed152015-07-09 12:16:29 +08003633 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3634 const struct intel_render_pass *rp =
3635 intel_render_pass(pRenderPassBegin->renderPass);
3636 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3637 const struct intel_att_view *view;
3638 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003639
Chia-I Wubdeed152015-07-09 12:16:29 +08003640 if (!cmd->primary || rp->attachment_count != fb->view_count) {
3641 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3642 return;
3643 }
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003644
Chia-I Wuc278df82015-07-07 11:50:03 +08003645 cmd_begin_render_pass(cmd, rp, fb, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003646
Chia-I Wubdeed152015-07-09 12:16:29 +08003647 for (i = 0; i < rp->attachment_count; i++) {
3648 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003649 const VkClearValue *clear_val =
3650 &pRenderPassBegin->pAttachmentClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003651 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003652
Chia-I Wubdeed152015-07-09 12:16:29 +08003653 if (!att->clear_on_load)
3654 continue;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003655
Chia-I Wubdeed152015-07-09 12:16:29 +08003656 view = fb->views[i];
3657 range.baseMipLevel = view->mipLevel;
3658 range.mipLevels = 1;
3659 range.baseArraySlice = view->baseArraySlice;
3660 range.arraySize = view->array_size;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003661
Chia-I Wubdeed152015-07-09 12:16:29 +08003662 if (view->is_rt) {
3663 range.aspect = VK_IMAGE_ASPECT_COLOR;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003664
Tony Barbourde4124d2015-07-03 10:33:54 -06003665 cmd_meta_clear_color_image(cmdBuffer, view->img,
Chia-I Wuc278df82015-07-07 11:50:03 +08003666 att->initial_layout, &clear_val->color, 1, &range);
Chia-I Wubdeed152015-07-09 12:16:29 +08003667 } else {
3668 range.aspect = VK_IMAGE_ASPECT_DEPTH;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003669
Chia-I Wubdeed152015-07-09 12:16:29 +08003670 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003671 view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003672 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003673 1, &range);
Chris Forbes4cf9d102015-06-22 18:46:05 +12003674
Chia-I Wubdeed152015-07-09 12:16:29 +08003675 if (att->stencil_clear_on_load) {
3676 range.aspect = VK_IMAGE_ASPECT_STENCIL;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003677
Chia-I Wubdeed152015-07-09 12:16:29 +08003678 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003679 view->img, att->initial_layout,
Chia-I Wuc278df82015-07-07 11:50:03 +08003680 clear_val->ds.depth, clear_val->ds.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003681 1, &range);
3682 }
3683 }
3684 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003685}
3686
Chia-I Wuc278df82015-07-07 11:50:03 +08003687ICD_EXPORT void VKAPI vkCmdNextSubpass(
3688 VkCmdBuffer cmdBuffer,
3689 VkRenderPassContents contents)
3690{
3691 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3692 const struct intel_render_pass *rp = cmd->bind.render_pass;
3693
3694 if (cmd->bind.render_pass_subpass >= rp->subpasses +
3695 rp->subpass_count - 1) {
3696 cmd->result = VK_ERROR_UNKNOWN;
3697 return;
3698 }
3699
3700 cmd->bind.render_pass_changed = true;
3701 cmd->bind.render_pass_subpass++;
3702 cmd->bind.render_pass_contents = contents;
3703}
3704
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003705ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003706 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003707{
3708 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3709
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003710 cmd_end_render_pass(cmd);
3711}
3712
3713ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3714 VkCmdBuffer cmdBuffer,
3715 uint32_t cmdBuffersCount,
3716 const VkCmdBuffer* pCmdBuffers)
3717{
3718 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003719 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003720
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003721 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3722 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3723 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3724 return;
3725 }
3726
3727 for (i = 0; i < cmdBuffersCount; i++) {
3728 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3729
3730 if (secondary->primary) {
3731 cmd->result = VK_ERROR_INVALID_VALUE;
3732 break;
3733 }
3734
3735 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3736 }
3737
3738 if (i)
3739 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003740}