blob: 0a39032b589ef950c812728189e781e4428f4ae8 [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;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700480 const struct intel_dynamic_rs *raster = cmd->bind.state.raster;
Chia-I Wu8016a172014-08-29 18:31:32 +0800481 uint32_t dw1, dw2, dw3;
Chia-I Wu8016a172014-08-29 18:31:32 +0800482
483 CMD_ASSERT(cmd, 6, 7.5);
484
485 dw1 = GEN7_SF_DW1_STATISTICS |
486 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
487 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
488 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
489 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700490 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800491
492 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
493 int format;
494
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800495 switch (rp->depthStencilFormat) {
Tony Barbour8205d902015-04-16 15:59:00 -0600496 case VK_FORMAT_D16_UNORM:
Chia-I Wu8016a172014-08-29 18:31:32 +0800497 format = GEN6_ZFORMAT_D16_UNORM;
498 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600499 case VK_FORMAT_D32_SFLOAT:
500 case VK_FORMAT_D32_SFLOAT_S8_UINT:
Chia-I Wu8016a172014-08-29 18:31:32 +0800501 format = GEN6_ZFORMAT_D32_FLOAT;
502 break;
503 default:
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800504 assert(rp->depthStencilFormat == VK_FORMAT_UNDEFINED);
505 format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800506 break;
507 }
508
509 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
510 }
511
Tony Barbourfa6cac72015-01-16 14:27:35 -0700512 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800513
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700514 /* Scissor is always enabled */
515 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
516
Tony Barbourfa6cac72015-01-16 14:27:35 -0700517 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800518 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
519 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
520 } else {
521 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
522 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
523 }
524
Chia-I Wu8016a172014-08-29 18:31:32 +0800525 dw3 = pipeline->provoking_vertex_tri << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
526 pipeline->provoking_vertex_line << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
527 pipeline->provoking_vertex_trifan << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800528 GEN7_SF_DW3_SUBPIXEL_8BITS;
529
Chia-I Wu8016a172014-08-29 18:31:32 +0800530 body[0] = dw1;
531 body[1] = dw2;
532 body[2] = dw3;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700533 body[3] = u_fui((float) raster->rs_info.depthBias * 2.0f);
534 body[4] = u_fui(raster->rs_info.slopeScaledDepthBias);
535 body[5] = u_fui(raster->rs_info.depthBiasClamp);
Chia-I Wu8016a172014-08-29 18:31:32 +0800536}
537
Chia-I Wu8016a172014-08-29 18:31:32 +0800538static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
539{
540 const uint8_t cmd_len = 20;
541 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
542 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800543 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800544 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800545 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800546
547 CMD_ASSERT(cmd, 6, 6);
548
549 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800550
Chia-I Wu72292b72014-09-09 10:48:33 +0800551 cmd_batch_pointer(cmd, cmd_len, &dw);
552 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800553 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800554 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800555 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800556}
557
558static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
559{
560 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800561 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800562
563 CMD_ASSERT(cmd, 7, 7.5);
564
Chia-I Wu72292b72014-09-09 10:48:33 +0800565 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800566 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
567 (cmd_len - 2);
568 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800569}
570
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800571static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
572{
573 const uint8_t cmd_len = 4;
574 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
575 (cmd_len - 2);
576 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700577 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800578 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700579 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800580 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800581
582 CMD_ASSERT(cmd, 6, 7.5);
583
584 dw1 = GEN6_CLIP_DW1_STATISTICS;
585 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
586 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
587 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700588 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800589 }
590
591 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800592 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700594 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800595 pipeline->provoking_vertex_tri << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
596 pipeline->provoking_vertex_line << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
597 pipeline->provoking_vertex_trifan << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
598
599 if (pipeline->rasterizerDiscardEnable)
600 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
601 else
602 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
603
604 if (pipeline->depthClipEnable)
605 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
606
607 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
608 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
609 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
610 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
611
612 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
613 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
614 (viewport->viewport_count - 1);
615
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600616 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600617 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600618 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
619 }
620
Chia-I Wu72292b72014-09-09 10:48:33 +0800621 cmd_batch_pointer(cmd, cmd_len, &dw);
622 dw[0] = dw0;
623 dw[1] = dw1;
624 dw[2] = dw2;
625 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800626}
627
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800628static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
629{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800630 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800631 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800632 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600633 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700634 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800635
636 CMD_ASSERT(cmd, 6, 6);
637
638 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
639
640 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
641 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
642
643 dw4 = GEN6_WM_DW4_STATISTICS |
644 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
645 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700646 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800648 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700649 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
650 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651
Cody Northrope86574e2015-02-24 14:15:29 -0700652 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700653 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700654
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800655 if (fs->uses & INTEL_SHADER_USE_KILL ||
656 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700657 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658
Cody Northrope238deb2015-01-26 14:41:36 -0700659 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800660 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
661 if (fs->uses & INTEL_SHADER_USE_DEPTH)
662 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
663 if (fs->uses & INTEL_SHADER_USE_W)
664 dw5 |= GEN6_WM_DW5_PS_USE_W;
665
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700666 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700667 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800668
669 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700670 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671 GEN6_WM_DW6_ZW_INTERP_PIXEL |
672 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
673 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
674
Tony Barbourfa6cac72015-01-16 14:27:35 -0700675 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800676 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
677 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
678 } else {
679 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
680 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
681 }
682
Cody Northrope86574e2015-02-24 14:15:29 -0700683 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
684
Chia-I Wu784d3042014-12-19 14:30:04 +0800685 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800686 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800687 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800688 dw[2] = dw2;
689 dw[3] = 0; /* scratch */
690 dw[4] = dw4;
691 dw[5] = dw5;
692 dw[6] = dw6;
693 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700694 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800695
696 if (fs->per_thread_scratch_size)
697 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800698}
699
700static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
701{
702 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800703 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800704 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800706
707 CMD_ASSERT(cmd, 7, 7.5);
708
709 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
710
711 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700712 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800713 GEN7_WM_DW1_ZW_INTERP_PIXEL |
714 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
715 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
716
717 if (fs->uses & INTEL_SHADER_USE_KILL ||
718 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700719 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800720
Cody Northrope238deb2015-01-26 14:41:36 -0700721 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
722
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723 if (fs->uses & INTEL_SHADER_USE_DEPTH)
724 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
725 if (fs->uses & INTEL_SHADER_USE_W)
726 dw1 |= GEN7_WM_DW1_PS_USE_W;
727
728 dw2 = 0;
729
Tony Barbourfa6cac72015-01-16 14:27:35 -0700730 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800731 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
732 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
733 } else {
734 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
735 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
736 }
737
Chia-I Wu72292b72014-09-09 10:48:33 +0800738 cmd_batch_pointer(cmd, cmd_len, &dw);
739 dw[0] = dw0;
740 dw[1] = dw1;
741 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800742}
743
744static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
745{
746 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800747 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800748 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700749 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600750 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800751
752 CMD_ASSERT(cmd, 7, 7.5);
753
754 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
755
756 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
757 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
758
759 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700760 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800761
Cody Northrope86574e2015-02-24 14:15:29 -0700762 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700763 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700764
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800765 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800766 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700767 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800768 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800769 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800770 }
771
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800772 if (fs->in_count)
773 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
774
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700775 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800776 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
777
778 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
779 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700780 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
781
782 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800783
Chia-I Wu784d3042014-12-19 14:30:04 +0800784 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800785 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800786 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800787 dw[2] = dw2;
788 dw[3] = 0; /* scratch */
789 dw[4] = dw4;
790 dw[5] = dw5;
791 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700792 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800793
794 if (fs->per_thread_scratch_size)
795 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800796}
797
Chia-I Wu8ada4242015-03-02 11:19:33 -0700798static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
799 uint32_t sample_count)
800{
801 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
802 uint32_t dw1, dw2, dw3, *dw;
803
804 CMD_ASSERT(cmd, 6, 7.5);
805
806 switch (sample_count) {
807 case 4:
808 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
809 dw2 = cmd->dev->sample_pattern_4x;
810 dw3 = 0;
811 break;
812 case 8:
813 assert(cmd_gen(cmd) >= INTEL_GEN(7));
814 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
815 dw2 = cmd->dev->sample_pattern_8x[0];
816 dw3 = cmd->dev->sample_pattern_8x[1];
817 break;
818 default:
819 assert(sample_count <= 1);
820 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
821 dw2 = 0;
822 dw3 = 0;
823 break;
824 }
825
826 cmd_batch_pointer(cmd, cmd_len, &dw);
827
828 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
829 dw[1] = dw1;
830 dw[2] = dw2;
831 if (cmd_gen(cmd) >= INTEL_GEN(7))
832 dw[3] = dw3;
833}
834
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800835static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800836 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700837 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800838{
839 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800840 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600841 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800842
843 CMD_ASSERT(cmd, 6, 7.5);
844
845 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800846 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
847 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800848 dw0 |= (cmd_len - 2);
849
Chia-I Wu72292b72014-09-09 10:48:33 +0800850 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
851 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700852
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800853 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700854 /* note that we only enable HiZ on Gen7+ */
855 if (!optimal_ds)
856 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
857
Chia-I Wu72292b72014-09-09 10:48:33 +0800858 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800859 dw[3] = view->att_cmd[2];
860 dw[4] = view->att_cmd[3];
861 dw[5] = view->att_cmd[4];
862 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800863
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600864 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800865 cmd_reserve_reloc(cmd, 1);
866 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800867 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600868 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800869}
870
871static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800872 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700873 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800874{
875 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600877 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800878
879 CMD_ASSERT(cmd, 6, 7.5);
880
881 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800882 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
883 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800884 dw0 |= (cmd_len - 2);
885
Chia-I Wu72292b72014-09-09 10:48:33 +0800886 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
887 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800888
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700889 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800890 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700891
Chia-I Wu72292b72014-09-09 10:48:33 +0800892 cmd_reserve_reloc(cmd, 1);
893 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800894 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700895 } else {
896 dw[1] = 0;
897 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600898 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800899}
900
901static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800902 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700903 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800904{
905 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800906 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600907 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800908
909 CMD_ASSERT(cmd, 6, 7.5);
910
911 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800912 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
913 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800914 dw0 |= (cmd_len - 2);
915
Chia-I Wu72292b72014-09-09 10:48:33 +0800916 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
917 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800918
Chia-I Wu73520ac2015-02-19 11:17:45 -0700919 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800920 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700921
Chia-I Wu72292b72014-09-09 10:48:33 +0800922 cmd_reserve_reloc(cmd, 1);
923 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800924 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700925 } else {
926 dw[1] = 0;
927 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600928 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800929}
930
Chia-I Wuf8231032014-08-25 10:44:45 +0800931static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
932 uint32_t clear_val)
933{
934 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800935 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800936 GEN6_CLEAR_PARAMS_DW0_VALID |
937 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800938 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800939
940 CMD_ASSERT(cmd, 6, 6);
941
Chia-I Wu72292b72014-09-09 10:48:33 +0800942 cmd_batch_pointer(cmd, cmd_len, &dw);
943 dw[0] = dw0;
944 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800945}
946
947static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
948 uint32_t clear_val)
949{
950 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800951 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800952 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800954
955 CMD_ASSERT(cmd, 7, 7.5);
956
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 cmd_batch_pointer(cmd, cmd_len, &dw);
958 dw[0] = dw0;
959 dw[1] = clear_val;
960 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800961}
962
Chia-I Wu302742d2014-08-22 10:28:29 +0800963static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800964 uint32_t blend_offset,
965 uint32_t ds_offset,
966 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800967{
968 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800970
971 CMD_ASSERT(cmd, 6, 6);
972
Chia-I Wu426072d2014-08-26 14:31:55 +0800973 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800974 (cmd_len - 2);
975
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 cmd_batch_pointer(cmd, cmd_len, &dw);
977 dw[0] = dw0;
978 dw[1] = blend_offset | 1;
979 dw[2] = ds_offset | 1;
980 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800981}
982
Chia-I Wu1744cca2014-08-22 11:10:17 +0800983static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800984 uint32_t clip_offset,
985 uint32_t sf_offset,
986 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800987{
988 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800989 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +0800990
991 CMD_ASSERT(cmd, 6, 6);
992
Chia-I Wu426072d2014-08-26 14:31:55 +0800993 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700994 GEN6_VP_PTR_DW0_CLIP_CHANGED |
995 GEN6_VP_PTR_DW0_SF_CHANGED |
996 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +0800997 (cmd_len - 2);
998
Chia-I Wu72292b72014-09-09 10:48:33 +0800999 cmd_batch_pointer(cmd, cmd_len, &dw);
1000 dw[0] = dw0;
1001 dw[1] = clip_offset;
1002 dw[2] = sf_offset;
1003 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001004}
1005
1006static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001007 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001008{
1009 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001011
1012 CMD_ASSERT(cmd, 6, 6);
1013
Chia-I Wu426072d2014-08-26 14:31:55 +08001014 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001015 (cmd_len - 2);
1016
Chia-I Wu72292b72014-09-09 10:48:33 +08001017 cmd_batch_pointer(cmd, cmd_len, &dw);
1018 dw[0] = dw0;
1019 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001020}
1021
Chia-I Wu42a56202014-08-23 16:47:48 +08001022static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001023 uint32_t vs_offset,
1024 uint32_t gs_offset,
1025 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001026{
1027 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001028 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001029
1030 CMD_ASSERT(cmd, 6, 6);
1031
Chia-I Wu426072d2014-08-26 14:31:55 +08001032 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001033 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1034 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1035 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001036 (cmd_len - 2);
1037
Chia-I Wu72292b72014-09-09 10:48:33 +08001038 cmd_batch_pointer(cmd, cmd_len, &dw);
1039 dw[0] = dw0;
1040 dw[1] = vs_offset;
1041 dw[2] = gs_offset;
1042 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001043}
1044
Chia-I Wu257e75e2014-08-29 14:06:35 +08001045static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001046 uint32_t vs_offset,
1047 uint32_t gs_offset,
1048 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001049{
1050 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001051 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001052
1053 CMD_ASSERT(cmd, 6, 6);
1054
1055 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001056 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1057 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1058 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001059 (cmd_len - 2);
1060
Chia-I Wu72292b72014-09-09 10:48:33 +08001061 cmd_batch_pointer(cmd, cmd_len, &dw);
1062 dw[0] = dw0;
1063 dw[1] = vs_offset;
1064 dw[2] = gs_offset;
1065 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001066}
1067
Chia-I Wu302742d2014-08-22 10:28:29 +08001068static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001069 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001070{
1071 const uint8_t cmd_len = 2;
1072 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1073 GEN6_RENDER_SUBTYPE_3D |
1074 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001075 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001076
Chia-I Wu72292b72014-09-09 10:48:33 +08001077 cmd_batch_pointer(cmd, cmd_len, &dw);
1078 dw[0] = dw0;
1079 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001080}
1081
Chia-I Wua6c4f152014-12-02 04:19:58 +08001082static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001083{
Chia-I Wue6073342014-11-30 09:43:42 +08001084 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001085 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1086 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001087
1088 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001089 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001090
Tony Barbourfa6cac72015-01-16 14:27:35 -07001091 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001092}
1093
Chia-I Wu72292b72014-09-09 10:48:33 +08001094static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001095 const struct intel_dynamic_ds *state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001096{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001097 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001098 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001099 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001100 uint32_t dw[3];
1101
1102 dw[0] = pipeline->cmd_depth_stencil;
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001103 /* same read and write masks for both front and back faces */
Tony Barbourfa6cac72015-01-16 14:27:35 -07001104 dw[1] = (state->ds_info.stencilReadMask & 0xff) << 24 |
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001105 (state->ds_info.stencilWriteMask & 0xff) << 16 |
1106 (state->ds_info.stencilReadMask & 0xff) << 8 |
1107 (state->ds_info.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001109
1110 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001111
1112 if (state->ds_info.stencilWriteMask && pipeline->stencilTestEnable)
1113 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001114
Chia-I Wu00b51a82014-09-09 12:07:37 +08001115 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001116 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001117}
1118
Chia-I Wu72292b72014-09-09 10:48:33 +08001119static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001120 uint32_t stencil_ref,
1121 const uint32_t blend_color[4])
1122{
Chia-I Wue6073342014-11-30 09:43:42 +08001123 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001124 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001125 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001126
1127 CMD_ASSERT(cmd, 6, 7.5);
1128
Chia-I Wu00b51a82014-09-09 12:07:37 +08001129 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1130 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001131 dw[0] = stencil_ref;
1132 dw[1] = 0;
1133 dw[2] = blend_color[0];
1134 dw[3] = blend_color[1];
1135 dw[4] = blend_color[2];
1136 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001137
Chia-I Wu72292b72014-09-09 10:48:33 +08001138 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001139}
1140
Chia-I Wu8370b402014-08-29 12:28:37 +08001141static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001142{
Chia-I Wu8370b402014-08-29 12:28:37 +08001143 CMD_ASSERT(cmd, 6, 7.5);
1144
Chia-I Wu707a29e2014-08-27 12:51:47 +08001145 if (!cmd->bind.draw_count)
1146 return;
1147
Chia-I Wu8370b402014-08-29 12:28:37 +08001148 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001149 return;
1150
Chia-I Wu8370b402014-08-29 12:28:37 +08001151 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001152
1153 /*
1154 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1155 *
1156 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1157 * pipe-control with a post-sync op and no write-cache flushes."
1158 *
1159 * The workaround below necessitates this workaround.
1160 */
1161 gen6_PIPE_CONTROL(cmd,
1162 GEN6_PIPE_CONTROL_CS_STALL |
1163 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001164 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001165
Chia-I Wud6d079d2014-08-31 13:14:21 +08001166 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1167 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001168}
1169
Chia-I Wu8370b402014-08-29 12:28:37 +08001170static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001171{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001172 CMD_ASSERT(cmd, 6, 7.5);
1173
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001174 if (!cmd->bind.draw_count)
1175 return;
1176
Chia-I Wud6d079d2014-08-31 13:14:21 +08001177 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1178 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001179}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001180
Chia-I Wu8370b402014-08-29 12:28:37 +08001181static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1182{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001183 CMD_ASSERT(cmd, 7, 7.5);
1184
Chia-I Wu8370b402014-08-29 12:28:37 +08001185 if (!cmd->bind.draw_count)
1186 return;
1187
1188 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001189
1190 gen6_PIPE_CONTROL(cmd,
1191 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001192 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001193}
1194
Chia-I Wu8370b402014-08-29 12:28:37 +08001195static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1196{
1197 CMD_ASSERT(cmd, 7, 7.5);
1198
Chia-I Wu8370b402014-08-29 12:28:37 +08001199 /*
1200 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1201 *
1202 * "One of the following must also be set (when CS stall is set):
1203 *
1204 * * Render Target Cache Flush Enable ([12] of DW1)
1205 * * Depth Cache Flush Enable ([0] of DW1)
1206 * * Stall at Pixel Scoreboard ([1] of DW1)
1207 * * Depth Stall ([13] of DW1)
1208 * * Post-Sync Operation ([13] of DW1)"
1209 */
1210 gen6_PIPE_CONTROL(cmd,
1211 GEN6_PIPE_CONTROL_CS_STALL |
1212 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001214}
1215
1216static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1217{
1218 CMD_ASSERT(cmd, 7, 7.5);
1219
Chia-I Wu8370b402014-08-29 12:28:37 +08001220 cmd_wa_gen6_pre_depth_stall_write(cmd);
1221
Chia-I Wud6d079d2014-08-31 13:14:21 +08001222 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001223}
1224
1225static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1226{
1227 CMD_ASSERT(cmd, 6, 7.5);
1228
1229 if (!cmd->bind.draw_count)
1230 return;
1231
1232 /*
1233 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1234 *
1235 * "Driver must guarentee that all the caches in the depth pipe are
1236 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1237 * requires driver to send a PIPE_CONTROL with a CS stall along with
1238 * a Depth Flush prior to this command."
1239 *
1240 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1241 *
1242 * "Driver must ierarchi that all the caches in the depth pipe are
1243 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1244 * requires driver to send a PIPE_CONTROL with a CS stall along with
1245 * a Depth Flush prior to this command.
1246 */
1247 gen6_PIPE_CONTROL(cmd,
1248 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1249 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001250 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001251}
1252
1253static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1254{
1255 CMD_ASSERT(cmd, 6, 7.5);
1256
1257 if (!cmd->bind.draw_count)
1258 return;
1259
1260 /*
1261 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1262 *
1263 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1264 * and a post sync operation prior to the group of depth
1265 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1266 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1267 *
1268 * This workaround satifies all the conditions.
1269 */
1270 cmd_wa_gen6_pre_depth_stall_write(cmd);
1271
1272 /*
1273 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1274 *
1275 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1276 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1277 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1278 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1279 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1280 * Depth Flush Bit set, followed by another pipelined depth stall
1281 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1282 * guarantee that the pipeline from WM onwards is already flushed
1283 * (e.g., via a preceding MI_FLUSH)."
1284 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001285 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1286 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1287 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001288}
1289
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001290void cmd_batch_state_base_address(struct intel_cmd *cmd)
1291{
1292 const uint8_t cmd_len = 10;
1293 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1294 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001295 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001296 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001297 uint32_t pos;
1298 uint32_t *dw;
1299
1300 CMD_ASSERT(cmd, 6, 7.5);
1301
1302 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1303
1304 dw[0] = dw0;
1305 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001306 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001307 dw[2] = 1;
1308 dw[3] = 1;
1309 dw[4] = 1;
1310 dw[5] = 1;
1311 /* end offsets */
1312 dw[6] = 1;
1313 dw[7] = 1 + 0xfffff000;
1314 dw[8] = 1 + 0xfffff000;
1315 dw[9] = 1;
1316
1317 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001318 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1319 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1320 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1321 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1322 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1323 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001324}
1325
Chia-I Wu7c853562015-02-27 14:35:08 -07001326void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1327{
1328 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1329 const uint8_t cmd_len = 2;
1330 uint32_t offset = 0;
1331 uint32_t *dw;
1332
1333 if (cmd_gen(cmd) <= INTEL_GEN(6))
1334 return;
1335
1336 CMD_ASSERT(cmd, 7, 7.5);
1337
1338 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1339 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1340 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1341 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1342 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1343 offset += size;
1344
1345 dw += 2;
1346 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1347 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1348 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1349
1350 dw += 2;
1351 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1352 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1353 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1354
1355 dw += 2;
1356 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1357 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1358 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1359
1360 dw += 2;
1361 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1362 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1363 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1364
1365 /*
1366 *
1367 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1368 *
1369 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1370 * in the ring after this instruction
1371 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1372 */
1373 cmd_wa_gen7_post_command_cs_stall(cmd);
1374}
1375
Chia-I Wu525c6602014-08-27 10:22:34 +08001376void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1377{
Mike Stroyan552fda42015-01-30 17:21:08 -07001378 if (pipe_control_dw0 == 0)
1379 return;
1380
Chia-I Wu525c6602014-08-27 10:22:34 +08001381 if (!cmd->bind.draw_count)
1382 return;
1383
1384 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1385
Chia-I Wu8370b402014-08-29 12:28:37 +08001386 /*
1387 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1388 *
1389 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1390 * PIPE_CONTROL with any non-zero post-sync-op is required."
1391 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001392 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001393 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001394
Chia-I Wu092279a2014-08-30 19:05:30 +08001395 /*
1396 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1397 *
1398 * "One of the following must also be set (when CS stall is set):
1399 *
1400 * * Render Target Cache Flush Enable ([12] of DW1)
1401 * * Depth Cache Flush Enable ([0] of DW1)
1402 * * Stall at Pixel Scoreboard ([1] of DW1)
1403 * * Depth Stall ([13] of DW1)
1404 * * Post-Sync Operation ([13] of DW1)"
1405 */
1406 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1407 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1408 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1409 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1410 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1411 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1412
Chia-I Wud6d079d2014-08-31 13:14:21 +08001413 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001414}
1415
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001416void cmd_batch_flush_all(struct intel_cmd *cmd)
1417{
1418 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1419 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1420 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1421 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1422 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1423 GEN6_PIPE_CONTROL_CS_STALL);
1424}
1425
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001426void cmd_batch_depth_count(struct intel_cmd *cmd,
1427 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001428 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001429{
1430 cmd_wa_gen6_pre_depth_stall_write(cmd);
1431
1432 gen6_PIPE_CONTROL(cmd,
1433 GEN6_PIPE_CONTROL_DEPTH_STALL |
1434 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001435 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001436}
1437
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001438void cmd_batch_timestamp(struct intel_cmd *cmd,
1439 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001440 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001441{
1442 /* need any WA or stall? */
1443 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1444}
1445
1446void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001447 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001448 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001449 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001450 uint64_t val)
1451{
1452 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001453 gen6_PIPE_CONTROL(cmd,
1454 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1455 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001456}
1457
Chia-I Wu302742d2014-08-22 10:28:29 +08001458static void gen6_cc_states(struct intel_cmd *cmd)
1459{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001460 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1461 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wu72292b72014-09-09 10:48:33 +08001462 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001463 uint32_t stencil_ref;
1464 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001465
1466 CMD_ASSERT(cmd, 6, 6);
1467
Chia-I Wua6c4f152014-12-02 04:19:58 +08001468 blend_offset = gen6_BLEND_STATE(cmd);
1469
1470 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001471 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001472 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001473 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001474
1475 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001476 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001477 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1478 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001479 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001480 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001481 stencil_ref = 0;
1482 }
1483
Chia-I Wu72292b72014-09-09 10:48:33 +08001484 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001485
Chia-I Wu72292b72014-09-09 10:48:33 +08001486 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001487}
1488
Chia-I Wu1744cca2014-08-22 11:10:17 +08001489static void gen6_viewport_states(struct intel_cmd *cmd)
1490{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001491 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001492 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001493
1494 if (!viewport)
1495 return;
1496
Tony Barbourfa6cac72015-01-16 14:27:35 -07001497 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001498 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001499
1500 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001501 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001502 viewport->cmd);
1503
1504 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001505 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001506 &viewport->cmd[viewport->cmd_clip_pos]);
1507
1508 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001509 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001510 &viewport->cmd[viewport->cmd_cc_pos]);
1511
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001512 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1513 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1514 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001515
1516 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001517 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001518
Chia-I Wub1d450a2014-09-09 13:48:03 +08001519 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001520}
1521
Chia-I Wu302742d2014-08-22 10:28:29 +08001522static void gen7_cc_states(struct intel_cmd *cmd)
1523{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001524 const struct intel_dynamic_cb *blend = cmd->bind.state.blend;
1525 const struct intel_dynamic_ds *ds = cmd->bind.state.ds;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001526 uint32_t stencil_ref;
1527 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001528 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001529
1530 CMD_ASSERT(cmd, 7, 7.5);
1531
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001532 if (!blend && !ds)
1533 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001534
Chia-I Wua6c4f152014-12-02 04:19:58 +08001535 offset = gen6_BLEND_STATE(cmd);
1536 gen7_3dstate_pointer(cmd,
1537 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001538
Chia-I Wua6c4f152014-12-02 04:19:58 +08001539 if (blend)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001540 memcpy(blend_color, blend->cb_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001541 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001542 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001543
1544 if (ds) {
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 offset = gen6_DEPTH_STENCIL_STATE(cmd, ds);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001546 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1547 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001549 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1550 offset);
Chia-I Wu3c276c92015-02-16 15:34:45 -07001551 stencil_ref = (ds->ds_info.stencilFrontRef & 0xff) << 24 |
1552 (ds->ds_info.stencilBackRef & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001553 } else {
1554 stencil_ref = 0;
1555 }
1556
Chia-I Wu72292b72014-09-09 10:48:33 +08001557 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001558 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001559 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001560}
1561
Chia-I Wu1744cca2014-08-22 11:10:17 +08001562static void gen7_viewport_states(struct intel_cmd *cmd)
1563{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001564 const struct intel_dynamic_vp *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001565 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001566
1567 if (!viewport)
1568 return;
1569
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001570 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001571
Chia-I Wub1d450a2014-09-09 13:48:03 +08001572 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001573 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001574 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001575 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1577 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001578
1579 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001580 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001581 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001582 gen7_3dstate_pointer(cmd,
1583 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001584 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001585
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001586 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1587 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1588 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1589 gen7_3dstate_pointer(cmd,
1590 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1591 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001592}
1593
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001594static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001595 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001596{
1597 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001598 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001599
Chia-I Wu72292b72014-09-09 10:48:33 +08001600 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001601
1602 dw[0] = GEN6_RENDER_TYPE_RENDER |
1603 GEN6_RENDER_SUBTYPE_3D |
1604 subop | (cmd_len - 2);
1605 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001606 dw[2] = 0;
1607 dw[3] = 0;
1608 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001609}
1610
1611static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001612 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001613{
1614 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001615 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001616
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001618
1619 dw[0] = GEN6_RENDER_TYPE_RENDER |
1620 GEN6_RENDER_SUBTYPE_3D |
1621 subop | (cmd_len - 2);
1622 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001624 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001625 dw[4] = 0;
1626 dw[5] = 0;
1627 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001628}
1629
Chia-I Wu625105f2014-10-13 15:35:29 +08001630static uint32_t emit_samplers(struct intel_cmd *cmd,
1631 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001632{
Chia-I Wu862c5572015-03-28 15:23:55 +08001633 const struct intel_desc_region *region = cmd->dev->desc_region;
1634 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001635 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1636 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001637 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001638 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001639 uint32_t surface_count;
1640 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001641
1642 CMD_ASSERT(cmd, 6, 7.5);
1643
Chia-I Wu625105f2014-10-13 15:35:29 +08001644 if (!rmap || !rmap->sampler_count)
1645 return 0;
1646
Cody Northrop40316a32014-12-09 19:08:33 -07001647 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001648
Chia-I Wudcb509d2014-12-10 08:53:10 +08001649 /*
1650 * note that we cannot call cmd_state_pointer() here as the following
1651 * cmd_state_pointer() would invalidate the pointer
1652 */
1653 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001654 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001655 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001656
1657 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001658 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001659 4 * rmap->sampler_count, &sampler_dw);
1660
Chia-I Wudcb509d2014-12-10 08:53:10 +08001661 cmd_state_update(cmd, border_offset,
1662 border_stride * rmap->sampler_count, &border_dw);
1663
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001664 for (i = 0; i < rmap->sampler_count; i++) {
1665 const struct intel_pipeline_rmap_slot *slot =
1666 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001667 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001668 const struct intel_sampler *sampler;
1669
Chia-I Wuf8385062015-01-04 16:27:24 +08001670 switch (slot->type) {
1671 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001672 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1673 &data->set_offsets[slot->index]);
1674 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001675 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001676 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001677 sampler = NULL;
1678 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001679 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001680 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681 sampler = NULL;
1682 break;
1683 }
1684
1685 if (sampler) {
1686 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1687
1688 sampler_dw[0] = sampler->cmd[0];
1689 sampler_dw[1] = sampler->cmd[1];
1690 sampler_dw[2] = border_offset;
1691 sampler_dw[3] = sampler->cmd[2];
1692 } else {
1693 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1694 sampler_dw[1] = 0;
1695 sampler_dw[2] = 0;
1696 sampler_dw[3] = 0;
1697 }
1698
1699 border_offset += border_stride * 4;
1700 border_dw += border_stride;
1701 sampler_dw += 4;
1702 }
1703
Chia-I Wu625105f2014-10-13 15:35:29 +08001704 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001705}
1706
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001707static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001708 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001709 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001710{
Chia-I Wu862c5572015-03-28 15:23:55 +08001711 const struct intel_desc_region *region = cmd->dev->desc_region;
1712 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001713 const uint32_t sba_offset =
1714 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001715 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001716 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001717
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001718 CMD_ASSERT(cmd, 6, 7.5);
1719
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001720 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001721 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001722 if (!surface_count)
1723 return 0;
1724
Chia-I Wu42a56202014-08-23 16:47:48 +08001725 assert(surface_count <= ARRAY_SIZE(binding_table));
1726
1727 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001728 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001729 struct intel_null_view null_view;
1730 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001731
Chia-I Wuf8385062015-01-04 16:27:24 +08001732 switch (slot->type) {
1733 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001734 {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001735 const struct intel_render_pass *rp = cmd->bind.render_pass;
1736 const struct intel_fb *fb = cmd->bind.fb;
1737 const struct intel_att_view *view =
1738 (slot->index < rp->colorAttachmentCount) ?
1739 fb->views[slot->index] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001740
Chia-I Wu787a05b2014-12-05 11:02:20 +08001741 if (view) {
1742 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1743 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001744 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001745
Chia-I Wu787a05b2014-12-05 11:02:20 +08001746 cmd_reserve_reloc(cmd, 1);
1747 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001748 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001749 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001750 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001751 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001752 }
1753 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001754 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001755 {
Tony Barbour22a30862015-04-22 09:02:32 -06001756 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001757 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001758 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001759 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001760 const struct intel_mem *mem;
1761 bool read_only;
1762 const uint32_t *cmd_data;
1763 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001764
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001765 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001766 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001767
Chia-I Wu862c5572015-03-28 15:23:55 +08001768 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1769 &data->set_offsets[slot->index]);
1770
1771 intel_desc_region_read_surface(region, &desc_offset, stage,
1772 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001773 if (mem) {
1774 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001775 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001776 const uint32_t reloc_flags =
1777 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001778
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001779 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001780 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001781 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001782
1783 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001784 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1785 cmd_data[1] + dynamic_offset, reloc_flags);
1786 } else {
1787 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001788 }
1789 }
1790 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001791 case INTEL_PIPELINE_RMAP_UNUSED:
1792 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001793 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001794 default:
1795 assert(!"unexpected rmap type");
1796 need_null_view = true;
1797 break;
1798 }
1799
1800 if (need_null_view) {
1801 intel_null_view_init(&null_view, cmd->dev);
1802 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1803 GEN6_ALIGNMENT_SURFACE_STATE,
1804 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001805 }
1806
Chia-I Wuf98dd882015-02-10 04:17:47 +08001807 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001808 }
1809
Chia-I Wuf98dd882015-02-10 04:17:47 +08001810 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001811 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001812 surface_count, binding_table) - sba_offset;
1813
1814 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1815 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1816
1817 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001818}
1819
Chia-I Wu1d125092014-10-08 08:49:38 +08001820static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1821{
1822 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001823 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1824 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001825 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001826
1827 CMD_ASSERT(cmd, 6, 7.5);
1828
1829 if (!pipeline->vb_count)
1830 return;
1831
1832 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1833
1834 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1835 dw++;
1836 pos++;
1837
1838 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001839 assert(pipeline->vb[i].strideInBytes <= 2048);
1840
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001841 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001842 pipeline->vb[i].strideInBytes;
1843
Chia-I Wub3686982015-02-27 09:51:16 -07001844 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001845 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1846 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001847 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001848
1849 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001850 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001851 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001852 dw[3] = 0;
1853 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001854 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001855 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001856 dw[3] = 1;
1857 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 case VK_VERTEX_INPUT_STEP_RATE_DRAW:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001859 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001860 dw[3] = 0;
1861 break;
1862 default:
1863 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001864 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001865 dw[3] = 0;
1866 break;
1867 }
1868
Chia-I Wu714df452015-01-01 07:55:04 +08001869 if (cmd->bind.vertex.buf[i]) {
1870 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001871 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001872
1873 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001874 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1875 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001876 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001877 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001878 dw[1] = 0;
1879 dw[2] = 0;
1880 }
1881
1882 dw += 4;
1883 pos += 4;
1884 }
1885}
1886
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001887static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1888{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001889 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1890 const struct intel_pipeline_shader *vs = &pipeline->vs;
1891 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001892 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001893 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001894 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001895 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001896
1897 CMD_ASSERT(cmd, 6, 7.5);
1898
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001899 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001900 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1901 *
1902 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1903 * 128-bit vertex elements to be passed into the payload for each
1904 * vertex."
1905 *
1906 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1907 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001908 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001909 vue_read_len = (vs->in_count + 1) / 2;
1910 if (!vue_read_len)
1911 vue_read_len = 1;
1912
1913 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1914 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1915
1916 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1917 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1918 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001919
1920 dw5 = GEN6_VS_DW5_STATISTICS |
1921 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001922
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001923 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001924 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001925 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001926 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001927
Chia-I Wube0a3d92014-09-02 13:20:59 +08001928 if (pipeline->disable_vs_cache)
1929 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1930
Chia-I Wu784d3042014-12-19 14:30:04 +08001931 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001932 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001933 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001934 dw[2] = dw2;
1935 dw[3] = 0; /* scratch */
1936 dw[4] = dw4;
1937 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001938
1939 if (vs->per_thread_scratch_size)
1940 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001941}
1942
Chia-I Wu625105f2014-10-13 15:35:29 +08001943static void emit_shader_resources(struct intel_cmd *cmd)
1944{
1945 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001946 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001947
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001948 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001949 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001950 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001951 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001952 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001953 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001954 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001955 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001956 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001957 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001958 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001959 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001960 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001961 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001962 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001963
1964 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1965 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1966 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1967 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1968 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1969
1970 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1971 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001972 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1973 binding_tables[0]);
1974 gen7_3dstate_pointer(cmd,
1975 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1976 binding_tables[1]);
1977 gen7_3dstate_pointer(cmd,
1978 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1979 binding_tables[2]);
1980 gen7_3dstate_pointer(cmd,
1981 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1982 binding_tables[3]);
1983 gen7_3dstate_pointer(cmd,
1984 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
1985 binding_tables[4]);
1986
1987 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08001988 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
1989 samplers[0]);
1990 gen7_3dstate_pointer(cmd,
1991 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
1992 samplers[1]);
1993 gen7_3dstate_pointer(cmd,
1994 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
1995 samplers[2]);
1996 gen7_3dstate_pointer(cmd,
1997 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
1998 samplers[3]);
1999 gen7_3dstate_pointer(cmd,
2000 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2001 samplers[4]);
2002 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002003 assert(!binding_tables[1] && !binding_tables[2]);
2004 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2005 binding_tables[0], binding_tables[3], binding_tables[4]);
2006
Chia-I Wu625105f2014-10-13 15:35:29 +08002007 assert(!samplers[1] && !samplers[2]);
2008 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2009 samplers[0], samplers[3], samplers[4]);
2010 }
2011}
2012
Chia-I Wu8ada4242015-03-02 11:19:33 -07002013static void emit_msaa(struct intel_cmd *cmd)
2014{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002015 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002016
Chia-I Wubbc7d912015-02-27 14:59:50 -07002017 if (!cmd->bind.render_pass_changed)
2018 return;
2019
Chia-I Wu8ada4242015-03-02 11:19:33 -07002020 if (fb->sample_count != cmd->bind.pipeline.graphics->sample_count)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002021 cmd->result = VK_ERROR_UNKNOWN;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002022
2023 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2024 gen6_3DSTATE_MULTISAMPLE(cmd, fb->sample_count);
2025}
2026
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002027static void emit_rt(struct intel_cmd *cmd)
2028{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002029 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002030
2031 if (!cmd->bind.render_pass_changed)
2032 return;
2033
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002034 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002035 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2036 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002037}
2038
2039static void emit_ds(struct intel_cmd *cmd)
2040{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002041 const struct intel_render_pass *rp = cmd->bind.render_pass;
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 =
2044 (rp->depthStencilFormat != VK_FORMAT_UNDEFINED) ?
2045 fb->views[rp->colorAttachmentCount] : 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 Wu3d4d4a62015-07-09 10:34:10 +08002057 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, rp->optimal_ds);
2058 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, rp->optimal_ds);
2059 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, rp->optimal_ds);
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 Barbourfa6cac72015-01-16 14:27:35 -07003202 const struct intel_dynamic_vp *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 Barbourfa6cac72015-01-16 14:27:35 -07003208 const struct intel_dynamic_rs *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003209{
3210 cmd->bind.state.raster = state;
3211}
3212
3213static void cmd_bind_ds_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003214 const struct intel_dynamic_ds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215{
3216 cmd->bind.state.ds = state;
3217}
3218
3219static void cmd_bind_blend_state(struct intel_cmd *cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07003220 const struct intel_dynamic_cb *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
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003445ICD_EXPORT void VKAPI vkCmdBindDynamicStateObject(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003446 VkCmdBuffer cmdBuffer,
3447 VkStateBindPoint stateBindPoint,
3448 VkDynamicStateObject state)
Chia-I Wub2755562014-08-20 13:38:52 +08003449{
3450 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3451
3452 switch (stateBindPoint) {
Tony Barbour8205d902015-04-16 15:59:00 -06003453 case VK_STATE_BIND_POINT_VIEWPORT:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003454 cmd_bind_viewport_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003455 intel_dynamic_vp((VkDynamicVpState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003456 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003457 case VK_STATE_BIND_POINT_RASTER:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003458 cmd_bind_raster_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003459 intel_dynamic_rs((VkDynamicRsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003460 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003461 case VK_STATE_BIND_POINT_DEPTH_STENCIL:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003462 cmd_bind_ds_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003463 intel_dynamic_ds((VkDynamicDsState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003464 break;
Tony Barbour8205d902015-04-16 15:59:00 -06003465 case VK_STATE_BIND_POINT_COLOR_BLEND:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003466 cmd_bind_blend_state(cmd,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06003467 intel_dynamic_cb((VkDynamicCbState) state));
Chia-I Wub2755562014-08-20 13:38:52 +08003468 break;
3469 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003470 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003471 break;
3472 }
3473}
3474
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003475ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003476 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003477 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003478 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003479 uint32_t firstSet,
3480 uint32_t setCount,
3481 const VkDescriptorSet* pDescriptorSets,
3482 uint32_t dynamicOffsetCount,
3483 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003484{
3485 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003486 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003487 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003488 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003489 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003490
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003491 pipeline_layout = intel_pipeline_layout(layout);
3492
Chia-I Wub2755562014-08-20 13:38:52 +08003493 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003494 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003495 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003496 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003497 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003498 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003499 break;
3500 default:
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003501 cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003502 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003503 break;
3504 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003505
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003506 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003507 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3508
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003509 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003510 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003511 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003512 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003513 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003514 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003515 }
Chia-I Wub2755562014-08-20 13:38:52 +08003516}
3517
Tony Barbour8205d902015-04-16 15:59:00 -06003518
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003519ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3520 VkCmdBuffer cmdBuffer,
3521 uint32_t startBinding,
3522 uint32_t bindingCount,
3523 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003524 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003525{
3526 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003527
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003528 for (uint32_t i = 0; i < bindingCount; i++) {
3529 struct intel_buf *buf = intel_buf(pBuffers[i]);
3530 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3531 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003532}
3533
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003534ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003535 VkCmdBuffer cmdBuffer,
3536 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003537 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003538 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003539{
3540 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003541 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003542
Chia-I Wu714df452015-01-01 07:55:04 +08003543 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003544}
3545
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003546ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003547 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003548 uint32_t firstVertex,
3549 uint32_t vertexCount,
3550 uint32_t firstInstance,
3551 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003552{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003553 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003554
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003555 cmd_draw(cmd, firstVertex, vertexCount,
3556 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003557}
3558
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003559ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003560 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003561 uint32_t firstIndex,
3562 uint32_t indexCount,
3563 int32_t vertexOffset,
3564 uint32_t firstInstance,
3565 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003566{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003567 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003568
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003569 cmd_draw(cmd, firstIndex, indexCount,
3570 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003571}
3572
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003573ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003574 VkCmdBuffer cmdBuffer,
3575 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003576 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003577 uint32_t count,
3578 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003579{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003580 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3581
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003582 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003583}
3584
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003585ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003586 VkCmdBuffer cmdBuffer,
3587 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003588 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003589 uint32_t count,
3590 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003591{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003592 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3593
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003594 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003595}
3596
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003597ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003598 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003599 uint32_t x,
3600 uint32_t y,
3601 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003602{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003603 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3604
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003605 cmd_fail(cmd, VK_ERROR_UNKNOWN);
Chia-I Wub2755562014-08-20 13:38:52 +08003606}
3607
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003608ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003609 VkCmdBuffer cmdBuffer,
3610 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003611 VkDeviceSize offset)
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}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003617
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003618ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003619 VkCmdBuffer cmdBuffer,
3620 const VkRenderPassBegin* pRenderPassBegin)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003621{
3622 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003623 const struct intel_render_pass *rp =
3624 intel_render_pass(pRenderPassBegin->renderPass);
3625 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3626 const struct intel_att_view *view;
3627 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003628
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003629 if (!cmd->primary) {
3630 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3631 return;
3632 }
3633
3634 cmd_begin_render_pass(cmd, rp, fb, pRenderPassBegin->contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003635
3636 /* issue load ops */
3637 for (i = 0; i < rp->colorAttachmentCount; i++) {
3638 if (rp->colorLoadOps[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) {
3639 /* issue clear of this attachment */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003640 view = fb->views[i];
Chris Forbesfff9bf42015-06-15 15:26:19 +12003641
3642 VkImageSubresourceRange ranges[1] = {{
3643 VK_IMAGE_ASPECT_COLOR,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003644 view->mipLevel,
Chris Forbesfff9bf42015-06-15 15:26:19 +12003645 1,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003646 view->baseArraySlice,
3647 view->array_size
Chris Forbesfff9bf42015-06-15 15:26:19 +12003648 }};
3649
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003650 cmd_meta_clear_color_image(cmdBuffer, (VkImage) view->img,
Chris Forbesfff9bf42015-06-15 15:26:19 +12003651 rp->colorLayouts[i],
3652 &rp->colorClearValues[i],
3653 1,
3654 ranges);
3655 }
3656 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003657
3658 if (rp->depthLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003659 view = fb->views[rp->colorAttachmentCount];
Chris Forbes4cf9d102015-06-22 18:46:05 +12003660
3661 VkImageSubresourceRange ranges[1] = {{
3662 VK_IMAGE_ASPECT_DEPTH,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003663 0, /* view->mipLevel, */
Chris Forbes4cf9d102015-06-22 18:46:05 +12003664 1,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003665 0, /* view->baseArraySlice, */
3666 view->array_size
Chris Forbes4cf9d102015-06-22 18:46:05 +12003667 }};
3668
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003669 cmd_meta_clear_depth_stencil_image(cmdBuffer, (VkImage) view->img,
Chris Forbes4cf9d102015-06-22 18:46:05 +12003670 rp->depthStencilLayout,
3671 rp->depthLoadClearValue,
3672 0,
3673 1,
3674 ranges);
3675 }
3676
3677 if (rp->stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003678 view = fb->views[rp->colorAttachmentCount];
Chris Forbes4cf9d102015-06-22 18:46:05 +12003679
3680 VkImageSubresourceRange ranges[1] = {{
3681 VK_IMAGE_ASPECT_STENCIL,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003682 0, /* view->mipLevel, */
Chris Forbes4cf9d102015-06-22 18:46:05 +12003683 1,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003684 0, /* view->baseArraySlice, */
3685 view->array_size
Chris Forbes4cf9d102015-06-22 18:46:05 +12003686 }};
3687
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003688 cmd_meta_clear_depth_stencil_image(cmdBuffer, (VkImage) view->img,
Chris Forbes4cf9d102015-06-22 18:46:05 +12003689 rp->depthStencilLayout,
3690 0.0f,
3691 rp->stencilLoadClearValue,
3692 1,
3693 ranges);
3694 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003695}
3696
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003697ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003698 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003699{
3700 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3701
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003702 cmd_end_render_pass(cmd);
3703}
3704
3705ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3706 VkCmdBuffer cmdBuffer,
3707 uint32_t cmdBuffersCount,
3708 const VkCmdBuffer* pCmdBuffers)
3709{
3710 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003711 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003712
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003713 if (!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3714 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) {
3715 cmd_fail(cmd, VK_ERROR_UNKNOWN);
3716 return;
3717 }
3718
3719 for (i = 0; i < cmdBuffersCount; i++) {
3720 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3721
3722 if (secondary->primary) {
3723 cmd->result = VK_ERROR_INVALID_VALUE;
3724 break;
3725 }
3726
3727 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3728 }
3729
3730 if (i)
3731 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003732}