blob: 29967ccd4cf9d3bb0b531ba57970051557042142 [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:
Tobin Ehlis8d199e52015-09-17 12:24:13 -0600266 assert(!"unsupported index type");
Chia-I Wu59c097e2014-08-21 10:51:07 +0800267 break;
268 }
269
Chia-I Wu59c097e2014-08-21 10:51:07 +0800270 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800271 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800272
Chia-I Wu72292b72014-09-09 10:48:33 +0800273 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
274 dw[0] = dw0;
275
276 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800277 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
278 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800279}
280
Chia-I Wu62a7f252014-08-29 11:31:16 +0800281static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
282 bool enable_cut_index,
283 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800284{
285 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800286 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800287
288 CMD_ASSERT(cmd, 7.5, 7.5);
289
Chia-I Wu426072d2014-08-26 14:31:55 +0800290 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800291 if (enable_cut_index)
292 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
293
Chia-I Wu72292b72014-09-09 10:48:33 +0800294 cmd_batch_pointer(cmd, cmd_len, &dw);
295 dw[0] = dw0;
296 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800297}
298
Cody Northrop293d4502015-05-05 09:38:03 -0600299static void gen6_add_scratch_space(struct intel_cmd *cmd,
300 uint32_t batch_pos,
301 const struct intel_pipeline *pipeline,
302 const struct intel_pipeline_shader *sh)
303{
304 int scratch_space;
305
306 CMD_ASSERT(cmd, 6, 7.5);
307
308 assert(sh->per_thread_scratch_size &&
309 sh->per_thread_scratch_size % 1024 == 0 &&
310 u_is_pow2(sh->per_thread_scratch_size) &&
311 sh->scratch_offset % 1024 == 0);
312 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
313
314 cmd_reserve_reloc(cmd, 1);
315 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
316 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
317}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600318
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800319static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
320{
Cody Northrop293d4502015-05-05 09:38:03 -0600321 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
322 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800323 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600324 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800325 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600326 int vue_read_len = 0;
327 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800328
Cody Northrop293d4502015-05-05 09:38:03 -0600329 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
330
331 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
332
333 // based on ilo_gpe_init_gs_cso_gen6
334 vue_read_len = (gs->in_count + 1) / 2;
335 if (!vue_read_len)
336 vue_read_len = 1;
337
338 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
339 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
340 GEN6_THREADDISP_SPF;
341
342 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
343 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
344 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
345
346 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
347 GEN6_GS_DW5_STATISTICS |
348 GEN6_GS_DW5_RENDER_ENABLE;
349
350 dw6 = GEN6_GS_DW6_GS_ENABLE;
351
352 if (gs->discard_adj)
353 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
354
355 } else {
356 dw2 = 0;
357 dw4 = 0;
358 dw5 = GEN6_GS_DW5_STATISTICS;
359 dw6 = 0;
360 }
361
362 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800363 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600364 dw[1] = cmd->bind.pipeline.gs_offset;
365 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800366 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600367 dw[4] = dw4;
368 dw[5] = dw5;
369 dw[6] = dw6;
370
371 if (gs->per_thread_scratch_size)
372 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800373}
374
Chia-I Wu62a7f252014-08-29 11:31:16 +0800375static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
376{
Cody Northrop293d4502015-05-05 09:38:03 -0600377 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
378 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800379 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600380 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800381 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600382 int vue_read_len = 0;
383 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800384
Cody Northrop293d4502015-05-05 09:38:03 -0600385 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
386
387 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
388
389 // based on upload_gs_state
390 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
391 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
392
393 vue_read_len = (gs->in_count + 1) / 2;
394 if (!vue_read_len)
395 vue_read_len = 1;
396
397 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
398 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
399 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
400 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
401 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
402
403
404 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
405 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
406 GEN7_GS_DW5_STATISTICS |
407 GEN7_GS_DW5_GS_ENABLE;
408
409 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
410 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
411
412 if (gs->include_primitive_id)
413 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
414
415 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
416 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
417 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
418 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
419 } else {
420 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
421 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
422 dw6 = 0;
423 }
424 } else {
425 dw2 = 0;
426 dw4 = 0;
427 dw5 = GEN7_GS_DW5_STATISTICS;
428 dw6 = 0;
429 }
430
431 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800432 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600433 dw[1] = cmd->bind.pipeline.gs_offset;
434 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800435 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600436 dw[4] = dw4;
437 dw[5] = dw5;
438 dw[6] = dw6;
439
440 if (gs->per_thread_scratch_size)
441 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800442}
443
Chia-I Wud88e02d2014-08-25 10:56:13 +0800444static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600445 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800446{
447 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800448 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800449 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800450 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800451
452 CMD_ASSERT(cmd, 6, 7.5);
453
Chia-I Wu72292b72014-09-09 10:48:33 +0800454 cmd_batch_pointer(cmd, cmd_len, &dw);
455 dw[0] = dw0;
456
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800458 dw[1] = 0;
459 dw[2] = (height - 1) << 16 |
460 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800461 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800462 dw[1] = 1;
463 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800464 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800465
466 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800467}
468
Chia-I Wu8016a172014-08-29 18:31:32 +0800469static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
470 uint32_t body[6])
471{
472 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800473 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800474 const struct intel_render_pass_subpass *subpass =
475 cmd->bind.render_pass_subpass;
Cody Northrope4bc6942015-08-26 10:01:32 -0600476 const struct intel_dynamic_line_width *line_width = cmd->bind.state.line_width;
477 const struct intel_dynamic_depth_bias *depth_bias = cmd->bind.state.depth_bias;
Cody Northropf5bd2252015-08-17 11:10:49 -0600478 uint32_t dw1, dw2, dw3, dw4, dw5, dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800479
480 CMD_ASSERT(cmd, 6, 7.5);
481
482 dw1 = GEN7_SF_DW1_STATISTICS |
483 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
484 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
485 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
486 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700487 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800488
489 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800490 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800491
Chia-I Wubdeed152015-07-09 12:16:29 +0800492 if (subpass->ds_index < rp->attachment_count) {
493 switch (rp->attachments[subpass->ds_index].format) {
494 case VK_FORMAT_D16_UNORM:
495 format = GEN6_ZFORMAT_D16_UNORM;
496 break;
497 case VK_FORMAT_D32_SFLOAT:
498 case VK_FORMAT_D32_SFLOAT_S8_UINT:
499 format = GEN6_ZFORMAT_D32_FLOAT;
500 break;
501 default:
502 assert(!"unsupported depth/stencil format");
503 break;
504 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800505 }
506
507 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
508 }
509
Tony Barbourfa6cac72015-01-16 14:27:35 -0700510 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800511
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700512 /* Scissor is always enabled */
513 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
514
Cody Northropf5bd2252015-08-17 11:10:49 -0600515 // TODO: line width support
Cody Northrope4bc6942015-08-26 10:01:32 -0600516 (void) line_width;
Cody Northropf5bd2252015-08-17 11:10:49 -0600517
Tony Barbourfa6cac72015-01-16 14:27:35 -0700518 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800519 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
520 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
521 } else {
522 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
523 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
524 }
525
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600526 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
527 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
528 2 << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800529 GEN7_SF_DW3_SUBPIXEL_8BITS;
530
Cody Northropf5bd2252015-08-17 11:10:49 -0600531 if (pipeline->depthBiasEnable) {
Cody Northrope4bc6942015-08-26 10:01:32 -0600532 dw4 = u_fui((float) depth_bias->depth_bias_info.depthBias * 2.0f);
533 dw5 = u_fui(depth_bias->depth_bias_info.slopeScaledDepthBias);
534 dw6 = u_fui(depth_bias->depth_bias_info.depthBiasClamp);
Cody Northropf5bd2252015-08-17 11:10:49 -0600535 } else {
536 dw4 = 0;
537 dw5 = 0;
538 dw6 = 0;
539 }
540
Chia-I Wu8016a172014-08-29 18:31:32 +0800541 body[0] = dw1;
542 body[1] = dw2;
543 body[2] = dw3;
Cody Northropf5bd2252015-08-17 11:10:49 -0600544 body[3] = dw4;
545 body[4] = dw5;
546 body[5] = dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800547}
548
Chia-I Wu8016a172014-08-29 18:31:32 +0800549static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
550{
551 const uint8_t cmd_len = 20;
552 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
553 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800554 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800555 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800556 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800557
558 CMD_ASSERT(cmd, 6, 6);
559
560 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800561
Chia-I Wu72292b72014-09-09 10:48:33 +0800562 cmd_batch_pointer(cmd, cmd_len, &dw);
563 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800564 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800565 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800566 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800567}
568
569static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
570{
571 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800572 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800573
574 CMD_ASSERT(cmd, 7, 7.5);
575
Chia-I Wu72292b72014-09-09 10:48:33 +0800576 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800577 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
578 (cmd_len - 2);
579 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800580}
581
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800582static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
583{
584 const uint8_t cmd_len = 4;
585 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
586 (cmd_len - 2);
587 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700588 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800589 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourde4124d2015-07-03 10:33:54 -0600590 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800591 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800592
593 CMD_ASSERT(cmd, 6, 7.5);
594
595 dw1 = GEN6_CLIP_DW1_STATISTICS;
596 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
597 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
598 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700599 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800600 }
601
602 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800603 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800604 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700605 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600606 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
607 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
608 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800609
610 if (pipeline->rasterizerDiscardEnable)
611 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
612 else
613 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
614
615 if (pipeline->depthClipEnable)
616 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
617
618 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
619 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
620 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
621 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
622
623 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
624 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
625 (viewport->viewport_count - 1);
626
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600627 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600628 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600629 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
630 }
631
Chia-I Wu72292b72014-09-09 10:48:33 +0800632 cmd_batch_pointer(cmd, cmd_len, &dw);
633 dw[0] = dw0;
634 dw[1] = dw1;
635 dw[2] = dw2;
636 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800637}
638
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800639static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
640{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800641 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800642 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800643 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600644 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700645 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800646
647 CMD_ASSERT(cmd, 6, 6);
648
649 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
650
651 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
652 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
653
654 dw4 = GEN6_WM_DW4_STATISTICS |
655 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
656 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700657 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800658
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800659 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700660 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
661 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800662
Cody Northrope86574e2015-02-24 14:15:29 -0700663 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700664 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700665
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800666 if (fs->uses & INTEL_SHADER_USE_KILL ||
667 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700668 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800669
Cody Northrope238deb2015-01-26 14:41:36 -0700670 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800671 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
672 if (fs->uses & INTEL_SHADER_USE_DEPTH)
673 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
674 if (fs->uses & INTEL_SHADER_USE_W)
675 dw5 |= GEN6_WM_DW5_PS_USE_W;
676
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700677 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700678 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679
680 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700681 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800682 GEN6_WM_DW6_ZW_INTERP_PIXEL |
683 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
684 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
685
Tony Barbourfa6cac72015-01-16 14:27:35 -0700686 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
688 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
689 } else {
690 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
691 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
692 }
693
Cody Northrope86574e2015-02-24 14:15:29 -0700694 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
695
Chia-I Wu784d3042014-12-19 14:30:04 +0800696 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800697 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800698 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800699 dw[2] = dw2;
700 dw[3] = 0; /* scratch */
701 dw[4] = dw4;
702 dw[5] = dw5;
703 dw[6] = dw6;
704 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700705 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800706
707 if (fs->per_thread_scratch_size)
708 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800709}
710
711static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
712{
713 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800714 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800715 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800716 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800717
718 CMD_ASSERT(cmd, 7, 7.5);
719
720 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
721
722 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700723 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800724 GEN7_WM_DW1_ZW_INTERP_PIXEL |
725 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
726 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
727
728 if (fs->uses & INTEL_SHADER_USE_KILL ||
729 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700730 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800731
Cody Northrope238deb2015-01-26 14:41:36 -0700732 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
733
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800734 if (fs->uses & INTEL_SHADER_USE_DEPTH)
735 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
736 if (fs->uses & INTEL_SHADER_USE_W)
737 dw1 |= GEN7_WM_DW1_PS_USE_W;
738
739 dw2 = 0;
740
Tony Barbourfa6cac72015-01-16 14:27:35 -0700741 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800742 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
743 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
744 } else {
745 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
746 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
747 }
748
Chia-I Wu72292b72014-09-09 10:48:33 +0800749 cmd_batch_pointer(cmd, cmd_len, &dw);
750 dw[0] = dw0;
751 dw[1] = dw1;
752 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800753}
754
755static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
756{
757 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800758 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800759 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700760 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600761 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800762
763 CMD_ASSERT(cmd, 7, 7.5);
764
765 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
766
767 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
768 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
769
770 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700771 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800772
Cody Northrope86574e2015-02-24 14:15:29 -0700773 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700774 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700775
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800776 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800777 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700778 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800779 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800780 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800781 }
782
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800783 if (fs->in_count)
784 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
785
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700786 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800787 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
788
789 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
790 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700791 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
792
793 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800794
Chia-I Wu784d3042014-12-19 14:30:04 +0800795 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800796 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800797 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800798 dw[2] = dw2;
799 dw[3] = 0; /* scratch */
800 dw[4] = dw4;
801 dw[5] = dw5;
802 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700803 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800804
805 if (fs->per_thread_scratch_size)
806 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800807}
808
Chia-I Wu8ada4242015-03-02 11:19:33 -0700809static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
810 uint32_t sample_count)
811{
812 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
813 uint32_t dw1, dw2, dw3, *dw;
814
815 CMD_ASSERT(cmd, 6, 7.5);
816
817 switch (sample_count) {
818 case 4:
819 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
820 dw2 = cmd->dev->sample_pattern_4x;
821 dw3 = 0;
822 break;
823 case 8:
824 assert(cmd_gen(cmd) >= INTEL_GEN(7));
825 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
826 dw2 = cmd->dev->sample_pattern_8x[0];
827 dw3 = cmd->dev->sample_pattern_8x[1];
828 break;
829 default:
830 assert(sample_count <= 1);
831 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
832 dw2 = 0;
833 dw3 = 0;
834 break;
835 }
836
837 cmd_batch_pointer(cmd, cmd_len, &dw);
838
839 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
840 dw[1] = dw1;
841 dw[2] = dw2;
842 if (cmd_gen(cmd) >= INTEL_GEN(7))
843 dw[3] = dw3;
844}
845
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800846static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800847 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700848 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800849{
850 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800851 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600852 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800853
854 CMD_ASSERT(cmd, 6, 7.5);
855
856 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800857 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
858 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800859 dw0 |= (cmd_len - 2);
860
Chia-I Wu72292b72014-09-09 10:48:33 +0800861 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
862 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700863
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800864 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700865 /* note that we only enable HiZ on Gen7+ */
866 if (!optimal_ds)
867 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800870 dw[3] = view->att_cmd[2];
871 dw[4] = view->att_cmd[3];
872 dw[5] = view->att_cmd[4];
873 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800874
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600875 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800876 cmd_reserve_reloc(cmd, 1);
877 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800878 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600879 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800880}
881
882static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800883 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700884 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800885{
886 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800887 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600888 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800889
890 CMD_ASSERT(cmd, 6, 7.5);
891
892 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800893 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
894 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800895 dw0 |= (cmd_len - 2);
896
Chia-I Wu72292b72014-09-09 10:48:33 +0800897 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
898 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800899
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700900 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800901 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700902
Chia-I Wu72292b72014-09-09 10:48:33 +0800903 cmd_reserve_reloc(cmd, 1);
904 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800905 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700906 } else {
907 dw[1] = 0;
908 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600909 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800910}
911
912static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800913 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700914 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800915{
916 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800917 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600918 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800919
920 CMD_ASSERT(cmd, 6, 7.5);
921
922 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800923 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
924 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800925 dw0 |= (cmd_len - 2);
926
Chia-I Wu72292b72014-09-09 10:48:33 +0800927 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
928 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800929
Chia-I Wu73520ac2015-02-19 11:17:45 -0700930 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800931 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700932
Chia-I Wu72292b72014-09-09 10:48:33 +0800933 cmd_reserve_reloc(cmd, 1);
934 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800935 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700936 } else {
937 dw[1] = 0;
938 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600939 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800940}
941
Chia-I Wuf8231032014-08-25 10:44:45 +0800942static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
943 uint32_t clear_val)
944{
945 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800946 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800947 GEN6_CLEAR_PARAMS_DW0_VALID |
948 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800949 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800950
951 CMD_ASSERT(cmd, 6, 6);
952
Chia-I Wu72292b72014-09-09 10:48:33 +0800953 cmd_batch_pointer(cmd, cmd_len, &dw);
954 dw[0] = dw0;
955 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800956}
957
958static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
959 uint32_t clear_val)
960{
961 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800962 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800963 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800964 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800965
966 CMD_ASSERT(cmd, 7, 7.5);
967
Chia-I Wu72292b72014-09-09 10:48:33 +0800968 cmd_batch_pointer(cmd, cmd_len, &dw);
969 dw[0] = dw0;
970 dw[1] = clear_val;
971 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800972}
973
Chia-I Wu302742d2014-08-22 10:28:29 +0800974static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800975 uint32_t blend_offset,
976 uint32_t ds_offset,
977 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800978{
979 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800980 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800981
982 CMD_ASSERT(cmd, 6, 6);
983
Chia-I Wu426072d2014-08-26 14:31:55 +0800984 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800985 (cmd_len - 2);
986
Chia-I Wu72292b72014-09-09 10:48:33 +0800987 cmd_batch_pointer(cmd, cmd_len, &dw);
988 dw[0] = dw0;
989 dw[1] = blend_offset | 1;
990 dw[2] = ds_offset | 1;
991 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800992}
993
Chia-I Wu1744cca2014-08-22 11:10:17 +0800994static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800995 uint32_t clip_offset,
996 uint32_t sf_offset,
997 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800998{
999 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001000 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001001
1002 CMD_ASSERT(cmd, 6, 6);
1003
Chia-I Wu426072d2014-08-26 14:31:55 +08001004 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001005 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1006 GEN6_VP_PTR_DW0_SF_CHANGED |
1007 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001008 (cmd_len - 2);
1009
Chia-I Wu72292b72014-09-09 10:48:33 +08001010 cmd_batch_pointer(cmd, cmd_len, &dw);
1011 dw[0] = dw0;
1012 dw[1] = clip_offset;
1013 dw[2] = sf_offset;
1014 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001015}
1016
1017static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001018 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001019{
1020 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001021 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001022
1023 CMD_ASSERT(cmd, 6, 6);
1024
Chia-I Wu426072d2014-08-26 14:31:55 +08001025 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001026 (cmd_len - 2);
1027
Chia-I Wu72292b72014-09-09 10:48:33 +08001028 cmd_batch_pointer(cmd, cmd_len, &dw);
1029 dw[0] = dw0;
1030 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001031}
1032
Chia-I Wu42a56202014-08-23 16:47:48 +08001033static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001034 uint32_t vs_offset,
1035 uint32_t gs_offset,
1036 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001037{
1038 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001039 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001040
1041 CMD_ASSERT(cmd, 6, 6);
1042
Chia-I Wu426072d2014-08-26 14:31:55 +08001043 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001044 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1045 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1046 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001047 (cmd_len - 2);
1048
Chia-I Wu72292b72014-09-09 10:48:33 +08001049 cmd_batch_pointer(cmd, cmd_len, &dw);
1050 dw[0] = dw0;
1051 dw[1] = vs_offset;
1052 dw[2] = gs_offset;
1053 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001054}
1055
Chia-I Wu257e75e2014-08-29 14:06:35 +08001056static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001057 uint32_t vs_offset,
1058 uint32_t gs_offset,
1059 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001060{
1061 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001062 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001063
1064 CMD_ASSERT(cmd, 6, 6);
1065
1066 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001067 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1068 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1069 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001070 (cmd_len - 2);
1071
Chia-I Wu72292b72014-09-09 10:48:33 +08001072 cmd_batch_pointer(cmd, cmd_len, &dw);
1073 dw[0] = dw0;
1074 dw[1] = vs_offset;
1075 dw[2] = gs_offset;
1076 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001077}
1078
Chia-I Wu302742d2014-08-22 10:28:29 +08001079static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001080 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001081{
1082 const uint8_t cmd_len = 2;
1083 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1084 GEN6_RENDER_SUBTYPE_3D |
1085 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001086 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001087
Chia-I Wu72292b72014-09-09 10:48:33 +08001088 cmd_batch_pointer(cmd, cmd_len, &dw);
1089 dw[0] = dw0;
1090 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001091}
1092
Chia-I Wua6c4f152014-12-02 04:19:58 +08001093static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001094{
Chia-I Wue6073342014-11-30 09:43:42 +08001095 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001096 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1097 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001098
1099 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001100 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001101
Tony Barbourfa6cac72015-01-16 14:27:35 -07001102 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001103}
1104
Chia-I Wu72292b72014-09-09 10:48:33 +08001105static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Cody Northrop2605cb02015-08-18 15:21:16 -06001106 const struct intel_dynamic_stencil *stencil_state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001107{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001109 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001110 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001111 uint32_t dw[3];
1112
1113 dw[0] = pipeline->cmd_depth_stencil;
Cody Northrop2605cb02015-08-18 15:21:16 -06001114
1115 /* TODO: enable back facing stencil state */
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001116 /* same read and write masks for both front and back faces */
Cody Northrope4bc6942015-08-26 10:01:32 -06001117 dw[1] = (stencil_state->stencil_info_front.stencilCompareMask & 0xff) << 24 |
Cody Northrop2605cb02015-08-18 15:21:16 -06001118 (stencil_state->stencil_info_front.stencilWriteMask & 0xff) << 16 |
Cody Northrope4bc6942015-08-26 10:01:32 -06001119 (stencil_state->stencil_info_front.stencilCompareMask & 0xff) << 8 |
Cody Northrop2605cb02015-08-18 15:21:16 -06001120 (stencil_state->stencil_info_front.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001121 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001122
1123 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001124
Cody Northrop2605cb02015-08-18 15:21:16 -06001125 if (stencil_state->stencil_info_front.stencilWriteMask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001126 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001127
Chia-I Wu00b51a82014-09-09 12:07:37 +08001128 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001129 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001130}
1131
Chia-I Wu72292b72014-09-09 10:48:33 +08001132static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001133 uint32_t stencil_ref,
1134 const uint32_t blend_color[4])
1135{
Chia-I Wue6073342014-11-30 09:43:42 +08001136 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001137 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001138 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001139
1140 CMD_ASSERT(cmd, 6, 7.5);
1141
Chia-I Wu00b51a82014-09-09 12:07:37 +08001142 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1143 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001144 dw[0] = stencil_ref;
1145 dw[1] = 0;
1146 dw[2] = blend_color[0];
1147 dw[3] = blend_color[1];
1148 dw[4] = blend_color[2];
1149 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001150
Chia-I Wu72292b72014-09-09 10:48:33 +08001151 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001152}
1153
Chia-I Wu8370b402014-08-29 12:28:37 +08001154static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001155{
Chia-I Wu8370b402014-08-29 12:28:37 +08001156 CMD_ASSERT(cmd, 6, 7.5);
1157
Chia-I Wu707a29e2014-08-27 12:51:47 +08001158 if (!cmd->bind.draw_count)
1159 return;
1160
Chia-I Wu8370b402014-08-29 12:28:37 +08001161 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001162 return;
1163
Chia-I Wu8370b402014-08-29 12:28:37 +08001164 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001165
1166 /*
1167 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1168 *
1169 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1170 * pipe-control with a post-sync op and no write-cache flushes."
1171 *
1172 * The workaround below necessitates this workaround.
1173 */
1174 gen6_PIPE_CONTROL(cmd,
1175 GEN6_PIPE_CONTROL_CS_STALL |
1176 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001177 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001178
Chia-I Wud6d079d2014-08-31 13:14:21 +08001179 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1180 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001181}
1182
Chia-I Wu8370b402014-08-29 12:28:37 +08001183static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001184{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001185 CMD_ASSERT(cmd, 6, 7.5);
1186
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001187 if (!cmd->bind.draw_count)
1188 return;
1189
Chia-I Wud6d079d2014-08-31 13:14:21 +08001190 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1191 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001192}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001193
Chia-I Wu8370b402014-08-29 12:28:37 +08001194static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1195{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001196 CMD_ASSERT(cmd, 7, 7.5);
1197
Chia-I Wu8370b402014-08-29 12:28:37 +08001198 if (!cmd->bind.draw_count)
1199 return;
1200
1201 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001202
1203 gen6_PIPE_CONTROL(cmd,
1204 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001205 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001206}
1207
Chia-I Wu8370b402014-08-29 12:28:37 +08001208static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1209{
1210 CMD_ASSERT(cmd, 7, 7.5);
1211
Chia-I Wu8370b402014-08-29 12:28:37 +08001212 /*
1213 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1214 *
1215 * "One of the following must also be set (when CS stall is set):
1216 *
1217 * * Render Target Cache Flush Enable ([12] of DW1)
1218 * * Depth Cache Flush Enable ([0] of DW1)
1219 * * Stall at Pixel Scoreboard ([1] of DW1)
1220 * * Depth Stall ([13] of DW1)
1221 * * Post-Sync Operation ([13] of DW1)"
1222 */
1223 gen6_PIPE_CONTROL(cmd,
1224 GEN6_PIPE_CONTROL_CS_STALL |
1225 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001226 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001227}
1228
1229static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1230{
1231 CMD_ASSERT(cmd, 7, 7.5);
1232
Chia-I Wu8370b402014-08-29 12:28:37 +08001233 cmd_wa_gen6_pre_depth_stall_write(cmd);
1234
Chia-I Wud6d079d2014-08-31 13:14:21 +08001235 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001236}
1237
1238static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1239{
1240 CMD_ASSERT(cmd, 6, 7.5);
1241
1242 if (!cmd->bind.draw_count)
1243 return;
1244
1245 /*
1246 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1247 *
1248 * "Driver must guarentee that all the caches in the depth pipe are
1249 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1250 * requires driver to send a PIPE_CONTROL with a CS stall along with
1251 * a Depth Flush prior to this command."
1252 *
1253 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1254 *
1255 * "Driver must ierarchi that all the caches in the depth pipe are
1256 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1257 * requires driver to send a PIPE_CONTROL with a CS stall along with
1258 * a Depth Flush prior to this command.
1259 */
1260 gen6_PIPE_CONTROL(cmd,
1261 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1262 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001263 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001264}
1265
1266static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1267{
1268 CMD_ASSERT(cmd, 6, 7.5);
1269
1270 if (!cmd->bind.draw_count)
1271 return;
1272
1273 /*
1274 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1275 *
1276 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1277 * and a post sync operation prior to the group of depth
1278 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1279 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1280 *
1281 * This workaround satifies all the conditions.
1282 */
1283 cmd_wa_gen6_pre_depth_stall_write(cmd);
1284
1285 /*
1286 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1287 *
1288 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1289 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1290 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1291 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1292 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1293 * Depth Flush Bit set, followed by another pipelined depth stall
1294 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1295 * guarantee that the pipeline from WM onwards is already flushed
1296 * (e.g., via a preceding MI_FLUSH)."
1297 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001298 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1299 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1300 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001301}
1302
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001303void cmd_batch_state_base_address(struct intel_cmd *cmd)
1304{
1305 const uint8_t cmd_len = 10;
1306 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1307 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001308 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001309 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001310 uint32_t pos;
1311 uint32_t *dw;
1312
1313 CMD_ASSERT(cmd, 6, 7.5);
1314
1315 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1316
1317 dw[0] = dw0;
1318 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001319 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001320 dw[2] = 1;
1321 dw[3] = 1;
1322 dw[4] = 1;
1323 dw[5] = 1;
1324 /* end offsets */
1325 dw[6] = 1;
1326 dw[7] = 1 + 0xfffff000;
1327 dw[8] = 1 + 0xfffff000;
1328 dw[9] = 1;
1329
1330 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001331 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1332 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1333 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1334 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1335 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1336 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001337}
1338
Chia-I Wu7c853562015-02-27 14:35:08 -07001339void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1340{
1341 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1342 const uint8_t cmd_len = 2;
1343 uint32_t offset = 0;
1344 uint32_t *dw;
1345
1346 if (cmd_gen(cmd) <= INTEL_GEN(6))
1347 return;
1348
1349 CMD_ASSERT(cmd, 7, 7.5);
1350
1351 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1352 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1353 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1354 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1355 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1356 offset += size;
1357
1358 dw += 2;
1359 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1360 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1361 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1362
1363 dw += 2;
1364 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1365 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1366 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1367
1368 dw += 2;
1369 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1370 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1371 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1372
1373 dw += 2;
1374 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1375 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1376 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1377
1378 /*
1379 *
1380 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1381 *
1382 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1383 * in the ring after this instruction
1384 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1385 */
1386 cmd_wa_gen7_post_command_cs_stall(cmd);
1387}
1388
Chia-I Wu525c6602014-08-27 10:22:34 +08001389void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1390{
Mike Stroyan552fda42015-01-30 17:21:08 -07001391 if (pipe_control_dw0 == 0)
1392 return;
1393
Chia-I Wu525c6602014-08-27 10:22:34 +08001394 if (!cmd->bind.draw_count)
1395 return;
1396
1397 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1398
Chia-I Wu8370b402014-08-29 12:28:37 +08001399 /*
1400 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1401 *
1402 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1403 * PIPE_CONTROL with any non-zero post-sync-op is required."
1404 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001405 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001406 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001407
Chia-I Wu092279a2014-08-30 19:05:30 +08001408 /*
1409 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1410 *
1411 * "One of the following must also be set (when CS stall is set):
1412 *
1413 * * Render Target Cache Flush Enable ([12] of DW1)
1414 * * Depth Cache Flush Enable ([0] of DW1)
1415 * * Stall at Pixel Scoreboard ([1] of DW1)
1416 * * Depth Stall ([13] of DW1)
1417 * * Post-Sync Operation ([13] of DW1)"
1418 */
1419 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1420 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1421 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1422 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1423 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1424 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1425
Chia-I Wud6d079d2014-08-31 13:14:21 +08001426 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001427}
1428
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001429void cmd_batch_flush_all(struct intel_cmd *cmd)
1430{
1431 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1432 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1433 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1434 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1435 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1436 GEN6_PIPE_CONTROL_CS_STALL);
1437}
1438
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001439void cmd_batch_depth_count(struct intel_cmd *cmd,
1440 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001441 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001442{
1443 cmd_wa_gen6_pre_depth_stall_write(cmd);
1444
1445 gen6_PIPE_CONTROL(cmd,
1446 GEN6_PIPE_CONTROL_DEPTH_STALL |
1447 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001448 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001449}
1450
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001451void cmd_batch_timestamp(struct intel_cmd *cmd,
1452 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001453 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001454{
1455 /* need any WA or stall? */
1456 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1457}
1458
1459void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001460 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001461 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001462 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001463 uint64_t val)
1464{
1465 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001466 gen6_PIPE_CONTROL(cmd,
1467 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1468 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001469}
1470
Chia-I Wu302742d2014-08-22 10:28:29 +08001471static void gen6_cc_states(struct intel_cmd *cmd)
1472{
Cody Northrope4bc6942015-08-26 10:01:32 -06001473 const struct intel_dynamic_blend *blend = cmd->bind.state.blend;
Cody Northrop2605cb02015-08-18 15:21:16 -06001474 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wu72292b72014-09-09 10:48:33 +08001475 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001476 uint32_t stencil_ref;
1477 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001478
1479 CMD_ASSERT(cmd, 6, 6);
1480
Chia-I Wua6c4f152014-12-02 04:19:58 +08001481 blend_offset = gen6_BLEND_STATE(cmd);
1482
1483 if (blend)
Cody Northrope4bc6942015-08-26 10:01:32 -06001484 memcpy(blend_color, blend->blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001485 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001486 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001487
Cody Northrop2605cb02015-08-18 15:21:16 -06001488 if (ss) {
1489 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1490 /* TODO: enable back facing stencil state */
1491 /* same reference for both front and back faces */
1492 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1493 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001494 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001495 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001496 stencil_ref = 0;
1497 }
1498
Chia-I Wu72292b72014-09-09 10:48:33 +08001499 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001500
Chia-I Wu72292b72014-09-09 10:48:33 +08001501 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001502}
1503
Chia-I Wu1744cca2014-08-22 11:10:17 +08001504static void gen6_viewport_states(struct intel_cmd *cmd)
1505{
Tony Barbourde4124d2015-07-03 10:33:54 -06001506 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001507 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001508
1509 if (!viewport)
1510 return;
1511
Tony Barbourfa6cac72015-01-16 14:27:35 -07001512 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001513 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001514
1515 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001516 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001517 viewport->cmd);
1518
1519 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001520 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001521 &viewport->cmd[viewport->cmd_clip_pos]);
1522
1523 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001524 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001525 &viewport->cmd[viewport->cmd_cc_pos]);
1526
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001527 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1528 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1529 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001530
1531 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001532 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001533
Chia-I Wub1d450a2014-09-09 13:48:03 +08001534 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001535}
1536
Chia-I Wu302742d2014-08-22 10:28:29 +08001537static void gen7_cc_states(struct intel_cmd *cmd)
1538{
Cody Northrope4bc6942015-08-26 10:01:32 -06001539 const struct intel_dynamic_blend *blend = cmd->bind.state.blend;
1540 const struct intel_dynamic_depth_bounds *ds = cmd->bind.state.depth_bounds;
Cody Northrop2605cb02015-08-18 15:21:16 -06001541 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001542 uint32_t stencil_ref;
1543 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001544 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001545
1546 CMD_ASSERT(cmd, 7, 7.5);
1547
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001548 if (!blend && !ds)
1549 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001550
Chia-I Wua6c4f152014-12-02 04:19:58 +08001551 offset = gen6_BLEND_STATE(cmd);
1552 gen7_3dstate_pointer(cmd,
1553 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001554
Chia-I Wua6c4f152014-12-02 04:19:58 +08001555 if (blend)
Cody Northrope4bc6942015-08-26 10:01:32 -06001556 memcpy(blend_color, blend->blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001557 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001558 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001559
Cody Northrop2605cb02015-08-18 15:21:16 -06001560 if (ss) {
1561 offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1562 /* TODO: enable back facing stencil state */
1563 /* same reference for both front and back faces */
1564 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1565 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001566 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001567 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1568 offset);
Cody Northrop2605cb02015-08-18 15:21:16 -06001569 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1570 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001571 } else {
1572 stencil_ref = 0;
1573 }
1574
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001576 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001577 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001578}
1579
Chia-I Wu1744cca2014-08-22 11:10:17 +08001580static void gen7_viewport_states(struct intel_cmd *cmd)
1581{
Tony Barbourde4124d2015-07-03 10:33:54 -06001582 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001583 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001584
1585 if (!viewport)
1586 return;
1587
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001588 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001589
Chia-I Wub1d450a2014-09-09 13:48:03 +08001590 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001591 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001592 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001593 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001594 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1595 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001596
1597 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001598 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001599 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001600 gen7_3dstate_pointer(cmd,
1601 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001602 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001603
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001604 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1605 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1606 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1607 gen7_3dstate_pointer(cmd,
1608 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1609 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001610}
1611
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001612static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001613 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001614{
1615 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001616 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001617
Chia-I Wu72292b72014-09-09 10:48:33 +08001618 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001619
1620 dw[0] = GEN6_RENDER_TYPE_RENDER |
1621 GEN6_RENDER_SUBTYPE_3D |
1622 subop | (cmd_len - 2);
1623 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001624 dw[2] = 0;
1625 dw[3] = 0;
1626 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001627}
1628
1629static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001630 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001631{
1632 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001633 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001634
Chia-I Wu72292b72014-09-09 10:48:33 +08001635 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001636
1637 dw[0] = GEN6_RENDER_TYPE_RENDER |
1638 GEN6_RENDER_SUBTYPE_3D |
1639 subop | (cmd_len - 2);
1640 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001641 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001642 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001643 dw[4] = 0;
1644 dw[5] = 0;
1645 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001646}
1647
Chia-I Wu625105f2014-10-13 15:35:29 +08001648static uint32_t emit_samplers(struct intel_cmd *cmd,
1649 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001650{
Chia-I Wu862c5572015-03-28 15:23:55 +08001651 const struct intel_desc_region *region = cmd->dev->desc_region;
1652 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001653 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1654 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001655 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001656 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001657 uint32_t surface_count;
1658 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001659
1660 CMD_ASSERT(cmd, 6, 7.5);
1661
Chia-I Wu625105f2014-10-13 15:35:29 +08001662 if (!rmap || !rmap->sampler_count)
1663 return 0;
1664
Cody Northrop40316a32014-12-09 19:08:33 -07001665 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001666
Chia-I Wudcb509d2014-12-10 08:53:10 +08001667 /*
1668 * note that we cannot call cmd_state_pointer() here as the following
1669 * cmd_state_pointer() would invalidate the pointer
1670 */
1671 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001672 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001673 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001674
1675 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001676 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001677 4 * rmap->sampler_count, &sampler_dw);
1678
Chia-I Wudcb509d2014-12-10 08:53:10 +08001679 cmd_state_update(cmd, border_offset,
1680 border_stride * rmap->sampler_count, &border_dw);
1681
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001682 for (i = 0; i < rmap->sampler_count; i++) {
1683 const struct intel_pipeline_rmap_slot *slot =
1684 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001685 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001686 const struct intel_sampler *sampler;
1687
Chia-I Wuf8385062015-01-04 16:27:24 +08001688 switch (slot->type) {
1689 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001690 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1691 &data->set_offsets[slot->index]);
1692 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001693 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001694 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001695 sampler = NULL;
1696 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001697 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001698 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001699 sampler = NULL;
1700 break;
1701 }
1702
1703 if (sampler) {
1704 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1705
1706 sampler_dw[0] = sampler->cmd[0];
1707 sampler_dw[1] = sampler->cmd[1];
1708 sampler_dw[2] = border_offset;
1709 sampler_dw[3] = sampler->cmd[2];
1710 } else {
1711 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1712 sampler_dw[1] = 0;
1713 sampler_dw[2] = 0;
1714 sampler_dw[3] = 0;
1715 }
1716
1717 border_offset += border_stride * 4;
1718 border_dw += border_stride;
1719 sampler_dw += 4;
1720 }
1721
Chia-I Wu625105f2014-10-13 15:35:29 +08001722 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001723}
1724
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001725static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001726 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001727 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001728{
Chia-I Wu862c5572015-03-28 15:23:55 +08001729 const struct intel_desc_region *region = cmd->dev->desc_region;
1730 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001731 const uint32_t sba_offset =
1732 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001733 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001734 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001735
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001736 CMD_ASSERT(cmd, 6, 7.5);
1737
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001738 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001739 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001740 if (!surface_count)
1741 return 0;
1742
Chia-I Wu42a56202014-08-23 16:47:48 +08001743 assert(surface_count <= ARRAY_SIZE(binding_table));
1744
1745 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001746 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001747 struct intel_null_view null_view;
1748 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001749
Chia-I Wuf8385062015-01-04 16:27:24 +08001750 switch (slot->type) {
1751 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001752 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001753 const struct intel_render_pass_subpass *subpass =
1754 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001755 const struct intel_fb *fb = cmd->bind.fb;
1756 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001757 (slot->index < subpass->color_count &&
1758 subpass->color_indices[slot->index] < fb->view_count) ?
1759 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001760
Chia-I Wu787a05b2014-12-05 11:02:20 +08001761 if (view) {
1762 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1763 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001764 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001765
Chia-I Wu787a05b2014-12-05 11:02:20 +08001766 cmd_reserve_reloc(cmd, 1);
1767 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001768 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001769 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001770 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001771 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001772 }
1773 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001774 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001775 {
Tony Barbour22a30862015-04-22 09:02:32 -06001776 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001777 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001778 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001779 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001780 const struct intel_mem *mem;
1781 bool read_only;
1782 const uint32_t *cmd_data;
1783 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001784
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001785 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001786 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001787
Chia-I Wu862c5572015-03-28 15:23:55 +08001788 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1789 &data->set_offsets[slot->index]);
1790
1791 intel_desc_region_read_surface(region, &desc_offset, stage,
1792 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001793 if (mem) {
1794 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001795 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001796 const uint32_t reloc_flags =
1797 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001798
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001799 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001800 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001801 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001802
1803 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001804 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1805 cmd_data[1] + dynamic_offset, reloc_flags);
1806 } else {
1807 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001808 }
1809 }
1810 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001811 case INTEL_PIPELINE_RMAP_UNUSED:
1812 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001813 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001814 default:
1815 assert(!"unexpected rmap type");
1816 need_null_view = true;
1817 break;
1818 }
1819
1820 if (need_null_view) {
1821 intel_null_view_init(&null_view, cmd->dev);
1822 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1823 GEN6_ALIGNMENT_SURFACE_STATE,
1824 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001825 }
1826
Chia-I Wuf98dd882015-02-10 04:17:47 +08001827 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001828 }
1829
Chia-I Wuf98dd882015-02-10 04:17:47 +08001830 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001831 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001832 surface_count, binding_table) - sba_offset;
1833
1834 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1835 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1836
1837 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001838}
1839
Chia-I Wu1d125092014-10-08 08:49:38 +08001840static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1841{
1842 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001843 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1844 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001845 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001846
1847 CMD_ASSERT(cmd, 6, 7.5);
1848
1849 if (!pipeline->vb_count)
1850 return;
1851
1852 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1853
1854 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1855 dw++;
1856 pos++;
1857
1858 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001859 assert(pipeline->vb[i].strideInBytes <= 2048);
1860
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001861 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001862 pipeline->vb[i].strideInBytes;
1863
Chia-I Wub3686982015-02-27 09:51:16 -07001864 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001865 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1866 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001867 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001868
1869 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001870 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001871 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001872 dw[3] = 0;
1873 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001874 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001875 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001876 dw[3] = 1;
1877 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001878 default:
1879 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001880 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001881 dw[3] = 0;
1882 break;
1883 }
1884
Chia-I Wu714df452015-01-01 07:55:04 +08001885 if (cmd->bind.vertex.buf[i]) {
1886 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001887 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001888
1889 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001890 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1891 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001892 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001893 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001894 dw[1] = 0;
1895 dw[2] = 0;
1896 }
1897
1898 dw += 4;
1899 pos += 4;
1900 }
1901}
1902
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001903static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1904{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001905 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1906 const struct intel_pipeline_shader *vs = &pipeline->vs;
1907 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001908 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001909 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001910 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001911 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001912
1913 CMD_ASSERT(cmd, 6, 7.5);
1914
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001915 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001916 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1917 *
1918 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1919 * 128-bit vertex elements to be passed into the payload for each
1920 * vertex."
1921 *
1922 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1923 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001924 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001925 vue_read_len = (vs->in_count + 1) / 2;
1926 if (!vue_read_len)
1927 vue_read_len = 1;
1928
1929 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1930 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1931
1932 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1933 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1934 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001935
1936 dw5 = GEN6_VS_DW5_STATISTICS |
1937 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001938
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001939 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001940 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001941 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001942 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001943
Chia-I Wube0a3d92014-09-02 13:20:59 +08001944 if (pipeline->disable_vs_cache)
1945 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1946
Chia-I Wu784d3042014-12-19 14:30:04 +08001947 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001948 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001949 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001950 dw[2] = dw2;
1951 dw[3] = 0; /* scratch */
1952 dw[4] = dw4;
1953 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001954
1955 if (vs->per_thread_scratch_size)
1956 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001957}
1958
Chia-I Wu625105f2014-10-13 15:35:29 +08001959static void emit_shader_resources(struct intel_cmd *cmd)
1960{
1961 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001962 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001963
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001964 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001965 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001966 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001967 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001968 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001969 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001970 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001971 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001972 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001973 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001974 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001975 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001976 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001977 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001978 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001979
1980 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1981 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1982 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1983 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1984 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1985
1986 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1987 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001988 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1989 binding_tables[0]);
1990 gen7_3dstate_pointer(cmd,
1991 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1992 binding_tables[1]);
1993 gen7_3dstate_pointer(cmd,
1994 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1995 binding_tables[2]);
1996 gen7_3dstate_pointer(cmd,
1997 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1998 binding_tables[3]);
1999 gen7_3dstate_pointer(cmd,
2000 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2001 binding_tables[4]);
2002
2003 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002004 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2005 samplers[0]);
2006 gen7_3dstate_pointer(cmd,
2007 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2008 samplers[1]);
2009 gen7_3dstate_pointer(cmd,
2010 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2011 samplers[2]);
2012 gen7_3dstate_pointer(cmd,
2013 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2014 samplers[3]);
2015 gen7_3dstate_pointer(cmd,
2016 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2017 samplers[4]);
2018 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002019 assert(!binding_tables[1] && !binding_tables[2]);
2020 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2021 binding_tables[0], binding_tables[3], binding_tables[4]);
2022
Chia-I Wu625105f2014-10-13 15:35:29 +08002023 assert(!samplers[1] && !samplers[2]);
2024 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2025 samplers[0], samplers[3], samplers[4]);
2026 }
2027}
2028
Chia-I Wu8ada4242015-03-02 11:19:33 -07002029static void emit_msaa(struct intel_cmd *cmd)
2030{
Chia-I Wuc278df82015-07-07 11:50:03 +08002031 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002032
Chia-I Wubbc7d912015-02-27 14:59:50 -07002033 if (!cmd->bind.render_pass_changed)
2034 return;
2035
Chia-I Wu8ada4242015-03-02 11:19:33 -07002036 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002037 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002038}
2039
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002040static void emit_rt(struct intel_cmd *cmd)
2041{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002042 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002043
2044 if (!cmd->bind.render_pass_changed)
2045 return;
2046
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002047 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002048 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2049 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002050}
2051
2052static void emit_ds(struct intel_cmd *cmd)
2053{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002054 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002055 const struct intel_render_pass_subpass *subpass =
2056 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002057 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002058 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002059 (subpass->ds_index < rp->attachment_count) ?
2060 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002061
Chia-I Wubbc7d912015-02-27 14:59:50 -07002062 if (!cmd->bind.render_pass_changed)
2063 return;
2064
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002065 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002066 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002067 static const struct intel_att_view null_view;
2068 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002069 }
2070
2071 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002072 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2073 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2074 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002075
2076 if (cmd_gen(cmd) >= INTEL_GEN(7))
2077 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2078 else
2079 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2080}
2081
Chia-I Wua57761b2014-10-14 14:27:44 +08002082static uint32_t emit_shader(struct intel_cmd *cmd,
2083 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002084{
Chia-I Wua57761b2014-10-14 14:27:44 +08002085 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2086 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002087 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002088
Chia-I Wua57761b2014-10-14 14:27:44 +08002089 /* see if the shader is already in the cache */
2090 for (i = 0; i < cache->used; i++) {
2091 if (cache->entries[i].shader == (const void *) shader)
2092 return cache->entries[i].kernel_offset;
2093 }
2094
2095 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2096
2097 /* grow the cache if full */
2098 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002099 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002100 void *entries;
2101
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002102 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002103 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002104 if (entries) {
2105 if (cache->entries) {
2106 memcpy(entries, cache->entries,
2107 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002108 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002109 }
2110
2111 cache->entries = entries;
2112 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002113 }
2114 }
2115
Chia-I Wua57761b2014-10-14 14:27:44 +08002116 /* add the shader to the cache */
2117 if (cache->used < cache->count) {
2118 cache->entries[cache->used].shader = (const void *) shader;
2119 cache->entries[cache->used].kernel_offset = offset;
2120 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002121 }
2122
Chia-I Wua57761b2014-10-14 14:27:44 +08002123 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002124}
2125
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002126static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002127{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002128 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002129
Chia-I Wu8370b402014-08-29 12:28:37 +08002130 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2131 cmd_wa_gen6_pre_depth_stall_write(cmd);
2132 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2133 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2134 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2135 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002136
2137 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002138 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002139 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002140
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002141 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002142 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002143 }
2144 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002145 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002146 }
2147 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002148 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2149 }
2150 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2151 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2152 }
2153 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2154 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002155 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002156
Chia-I Wu8370b402014-08-29 12:28:37 +08002157 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2158 cmd_wa_gen7_post_command_cs_stall(cmd);
2159 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2160 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002161}
2162
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002163static void emit_bounded_states(struct intel_cmd *cmd)
2164{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002165 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002166
2167 emit_graphics_pipeline(cmd);
2168
2169 emit_rt(cmd);
2170 emit_ds(cmd);
2171
2172 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2173 gen7_cc_states(cmd);
2174 gen7_viewport_states(cmd);
2175
2176 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2177 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002178 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2179 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002180 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2181 &cmd->bind.pipeline.graphics->fs);
2182
Cody Northrop293d4502015-05-05 09:38:03 -06002183 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002184 gen6_3DSTATE_CLIP(cmd);
2185 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002186 gen7_3DSTATE_WM(cmd);
2187 gen7_3DSTATE_PS(cmd);
2188 } else {
2189 gen6_cc_states(cmd);
2190 gen6_viewport_states(cmd);
2191
2192 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2193 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002194 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2195 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002196 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2197 &cmd->bind.pipeline.graphics->fs);
2198
Cody Northrop293d4502015-05-05 09:38:03 -06002199 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002200 gen6_3DSTATE_CLIP(cmd);
2201 gen6_3DSTATE_SF(cmd);
2202 gen6_3DSTATE_WM(cmd);
2203 }
2204
2205 emit_shader_resources(cmd);
2206
2207 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002208
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002209 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2210 gen6_3DSTATE_VS(cmd);
2211}
2212
Tony Barbourfa6cac72015-01-16 14:27:35 -07002213static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002214 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002215{
2216 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2217 const uint8_t cmd_len = 3;
2218 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002219
2220 CMD_ASSERT(cmd, 6, 7.5);
2221
Courtney Goeltzenleuchteraeffeae2015-09-10 17:58:54 -06002222 /* TODO: aspect is now a mask, can you do both? */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002223 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002224 dw[0] = 0;
2225 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002226
2227 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2228 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2229 GEN6_COMPAREFUNCTION_NEVER << 27 |
2230 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2231 } else {
2232 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2233 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2234 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002235 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002236 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002237 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2238 (GEN6_STENCILOP_KEEP) << 25 |
2239 (GEN6_STENCILOP_KEEP) << 22 |
2240 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002241 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2242 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002243 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2244 (GEN6_STENCILOP_KEEP) << 9 |
2245 (GEN6_STENCILOP_KEEP) << 6 |
2246 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002247
Chia-I Wud850a392015-02-19 11:08:25 -07002248 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2249 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2250 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2251 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2252 dw[2] = 0;
2253 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002254
2255 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2256 cmd_align, cmd_len, dw);
2257}
2258
Chia-I Wu6032b892014-10-17 14:47:18 +08002259static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2260{
2261 const struct intel_cmd_meta *meta = cmd->bind.meta;
2262 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2263
2264 CMD_ASSERT(cmd, 6, 7.5);
2265
2266 blend_offset = 0;
2267 ds_offset = 0;
2268 cc_offset = 0;
2269 cc_vp_offset = 0;
2270
Chia-I Wu29e6f502014-11-24 14:27:29 +08002271 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002272 /* BLEND_STATE */
2273 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002274 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002275 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002276 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002277 }
2278
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002280 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002281 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002282 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2283 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002284
Chia-I Wu29e6f502014-11-24 14:27:29 +08002285 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002286 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002287
Chia-I Wu29e6f502014-11-24 14:27:29 +08002288 /* COLOR_CALC_STATE */
2289 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002290 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002291
Chia-I Wu29e6f502014-11-24 14:27:29 +08002292 /* CC_VIEWPORT */
2293 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002294 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002295 dw[0] = u_fui(0.0f);
2296 dw[1] = u_fui(1.0f);
2297 } else {
2298 /* DEPTH_STENCIL_STATE */
2299 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002300 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002301 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2302 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2303 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002304 }
2305
2306 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2307 gen7_3dstate_pointer(cmd,
2308 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2309 blend_offset);
2310 gen7_3dstate_pointer(cmd,
2311 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2312 ds_offset);
2313 gen7_3dstate_pointer(cmd,
2314 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2315
2316 gen7_3dstate_pointer(cmd,
2317 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2318 cc_vp_offset);
2319 } else {
2320 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002321 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002322
2323 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2324 cmd_batch_pointer(cmd, 4, &dw);
2325 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002326 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002327 dw[1] = 0;
2328 dw[2] = 0;
2329 dw[3] = cc_vp_offset;
2330 }
2331}
2332
2333static void gen6_meta_surface_states(struct intel_cmd *cmd)
2334{
2335 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002336 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002337 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002338 const uint32_t sba_offset =
2339 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002340
2341 CMD_ASSERT(cmd, 6, 7.5);
2342
Chia-I Wu29e6f502014-11-24 14:27:29 +08002343 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2344 return;
2345
Chia-I Wu005c47c2014-10-22 13:49:13 +08002346 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002347 if (meta->src.valid) {
2348 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002349 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002350 meta->src.surface_len, meta->src.surface);
2351
2352 cmd_reserve_reloc(cmd, 1);
2353 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2354 cmd_surface_reloc_writer(cmd, offset, 1,
2355 meta->src.reloc_target, meta->src.reloc_offset);
2356 } else {
2357 cmd_surface_reloc(cmd, offset, 1,
2358 (struct intel_bo *) meta->src.reloc_target,
2359 meta->src.reloc_offset, meta->src.reloc_flags);
2360 }
2361
Mike Stroyan9bfad482015-02-10 15:09:23 -07002362 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002363 }
2364 if (meta->dst.valid) {
2365 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002366 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002367 meta->dst.surface_len, meta->dst.surface);
2368
2369 cmd_reserve_reloc(cmd, 1);
2370 cmd_surface_reloc(cmd, offset, 1,
2371 (struct intel_bo *) meta->dst.reloc_target,
2372 meta->dst.reloc_offset, meta->dst.reloc_flags);
2373
Mike Stroyan9bfad482015-02-10 15:09:23 -07002374 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002375 }
2376
2377 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002378 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002379 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002380 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002381
2382 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002383 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2384 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2385 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002386 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002387 } else {
2388 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002389 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002390 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002391 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002392 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002393 }
2394}
2395
2396static void gen6_meta_urb(struct intel_cmd *cmd)
2397{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002398 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002399 uint32_t *dw;
2400
2401 CMD_ASSERT(cmd, 6, 6);
2402
2403 /* 3DSTATE_URB */
2404 cmd_batch_pointer(cmd, 3, &dw);
2405 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002406 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002407 dw[2] = 0;
2408}
2409
2410static void gen7_meta_urb(struct intel_cmd *cmd)
2411{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002412 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2413 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002414 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002415 uint32_t *dw;
2416
2417 CMD_ASSERT(cmd, 7, 7.5);
2418
Chia-I Wu6032b892014-10-17 14:47:18 +08002419 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2420
Chia-I Wu24aa1022014-11-25 11:53:19 +08002421 switch (cmd_gen(cmd)) {
2422 case INTEL_GEN(7.5):
2423 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2424 break;
2425 case INTEL_GEN(7):
2426 default:
2427 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2428 break;
2429 }
2430
Chia-I Wu6032b892014-10-17 14:47:18 +08002431 /* 3DSTATE_URB_x */
2432 cmd_batch_pointer(cmd, 8, &dw);
2433
2434 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002435 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002436 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002437 dw += 2;
2438
2439 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002440 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002441 dw += 2;
2442
2443 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002444 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002445 dw += 2;
2446
2447 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002448 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002449 dw += 2;
2450}
2451
2452static void gen6_meta_vf(struct intel_cmd *cmd)
2453{
2454 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002455 uint32_t vb_start, vb_end, vb_stride;
2456 int ve_format, ve_z_source;
2457 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002458 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002459
2460 CMD_ASSERT(cmd, 6, 7.5);
2461
Chia-I Wu29e6f502014-11-24 14:27:29 +08002462 switch (meta->mode) {
2463 case INTEL_CMD_META_VS_POINTS:
2464 cmd_batch_pointer(cmd, 3, &dw);
2465 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002466 dw[1] = GEN6_VE_DW0_VALID;
2467 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2468 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2469 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2470 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002471 return;
2472 break;
2473 case INTEL_CMD_META_FS_RECT:
2474 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002475 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002476
Chia-I Wu29e6f502014-11-24 14:27:29 +08002477 vertices[0][0] = meta->dst.x + meta->width;
2478 vertices[0][1] = meta->dst.y + meta->height;
2479 vertices[1][0] = meta->dst.x;
2480 vertices[1][1] = meta->dst.y + meta->height;
2481 vertices[2][0] = meta->dst.x;
2482 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002483
Chia-I Wu29e6f502014-11-24 14:27:29 +08002484 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2485 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002486
Chia-I Wu29e6f502014-11-24 14:27:29 +08002487 vb_end = vb_start + sizeof(vertices) - 1;
2488 vb_stride = sizeof(vertices[0]);
2489 ve_z_source = GEN6_VFCOMP_STORE_0;
2490 ve_format = GEN6_FORMAT_R32G32_USCALED;
2491 }
2492 break;
2493 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2494 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002495 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002496
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002497 vertices[0][0] = (float) (meta->dst.x + meta->width);
2498 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002499 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002500 vertices[1][0] = (float) meta->dst.x;
2501 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002502 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002503 vertices[2][0] = (float) meta->dst.x;
2504 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002505 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002506
Chia-I Wu29e6f502014-11-24 14:27:29 +08002507 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2508 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002509
Chia-I Wu29e6f502014-11-24 14:27:29 +08002510 vb_end = vb_start + sizeof(vertices) - 1;
2511 vb_stride = sizeof(vertices[0]);
2512 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2513 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2514 }
2515 break;
2516 default:
2517 assert(!"unknown meta mode");
2518 return;
2519 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002520 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002521
2522 /* 3DSTATE_VERTEX_BUFFERS */
2523 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002524
Chia-I Wu6032b892014-10-17 14:47:18 +08002525 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002526 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002527 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002528 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002529
2530 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002531 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2532 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002533
2534 dw[4] = 0;
2535
2536 /* 3DSTATE_VERTEX_ELEMENTS */
2537 cmd_batch_pointer(cmd, 5, &dw);
2538 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002539 dw[1] = GEN6_VE_DW0_VALID;
2540 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2541 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2542 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2543 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2544 dw[3] = GEN6_VE_DW0_VALID |
2545 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2546 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2547 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2548 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2549 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002550}
2551
Chia-I Wu29e6f502014-11-24 14:27:29 +08002552static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002553{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002554 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002555 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002556 uint32_t consts[8];
2557 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002558
2559 CMD_ASSERT(cmd, 6, 7.5);
2560
2561 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002562 case INTEL_DEV_META_VS_FILL_MEM:
2563 consts[0] = meta->dst.x;
2564 consts[1] = meta->clear_val[0];
2565 const_count = 2;
2566 break;
2567 case INTEL_DEV_META_VS_COPY_MEM:
2568 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2569 consts[0] = meta->dst.x;
2570 consts[1] = meta->src.x;
2571 const_count = 2;
2572 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002573 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2574 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2575 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2576 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2577 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2578 consts[0] = meta->src.x;
2579 consts[1] = meta->src.y;
2580 consts[2] = meta->width;
2581 consts[3] = meta->dst.x;
2582 const_count = 4;
2583 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002584 default:
2585 assert(!"unknown meta shader id");
2586 const_count = 0;
2587 break;
2588 }
2589
2590 /* this can be skipped but it makes state dumping prettier */
2591 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2592
2593 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2594}
2595
2596static void gen6_meta_vs(struct intel_cmd *cmd)
2597{
2598 const struct intel_cmd_meta *meta = cmd->bind.meta;
2599 const struct intel_pipeline_shader *sh =
2600 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2601 uint32_t offset, *dw;
2602
2603 CMD_ASSERT(cmd, 6, 7.5);
2604
2605 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002606 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002607
2608 /* 3DSTATE_CONSTANT_VS */
2609 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2610 cmd_batch_pointer(cmd, cmd_len, &dw);
2611 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2612 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2613
2614 /* 3DSTATE_VS */
2615 cmd_batch_pointer(cmd, 6, &dw);
2616 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2617 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2618
2619 return;
2620 }
2621
2622 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2623
2624 /* 3DSTATE_CONSTANT_VS */
2625 offset = gen6_meta_vs_constants(cmd);
2626 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2627 cmd_batch_pointer(cmd, 7, &dw);
2628 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002629 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002630 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002631 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002632 dw[4] = 0;
2633 dw[5] = 0;
2634 dw[6] = 0;
2635 } else {
2636 cmd_batch_pointer(cmd, 5, &dw);
2637 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002638 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002639 dw[1] = offset;
2640 dw[2] = 0;
2641 dw[3] = 0;
2642 dw[4] = 0;
2643 }
2644
2645 /* 3DSTATE_VS */
2646 offset = emit_shader(cmd, sh);
2647 cmd_batch_pointer(cmd, 6, &dw);
2648 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2649 dw[1] = offset;
2650 dw[2] = GEN6_THREADDISP_SPF |
2651 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2652 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002653 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002654 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2655 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2656
2657 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2658 GEN6_VS_DW5_VS_ENABLE;
2659 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002660 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002661 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002662 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002663
2664 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002665}
2666
2667static void gen6_meta_disabled(struct intel_cmd *cmd)
2668{
Chia-I Wu6032b892014-10-17 14:47:18 +08002669 uint32_t *dw;
2670
2671 CMD_ASSERT(cmd, 6, 6);
2672
Chia-I Wu6032b892014-10-17 14:47:18 +08002673 /* 3DSTATE_CONSTANT_GS */
2674 cmd_batch_pointer(cmd, 5, &dw);
2675 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2676 dw[1] = 0;
2677 dw[2] = 0;
2678 dw[3] = 0;
2679 dw[4] = 0;
2680
2681 /* 3DSTATE_GS */
2682 cmd_batch_pointer(cmd, 7, &dw);
2683 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2684 dw[1] = 0;
2685 dw[2] = 0;
2686 dw[3] = 0;
2687 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2688 dw[5] = GEN6_GS_DW5_STATISTICS;
2689 dw[6] = 0;
2690
Chia-I Wu6032b892014-10-17 14:47:18 +08002691 /* 3DSTATE_SF */
2692 cmd_batch_pointer(cmd, 20, &dw);
2693 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2694 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2695 memset(&dw[2], 0, 18 * sizeof(*dw));
2696}
2697
2698static void gen7_meta_disabled(struct intel_cmd *cmd)
2699{
2700 uint32_t *dw;
2701
2702 CMD_ASSERT(cmd, 7, 7.5);
2703
Chia-I Wu6032b892014-10-17 14:47:18 +08002704 /* 3DSTATE_CONSTANT_HS */
2705 cmd_batch_pointer(cmd, 7, &dw);
2706 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2707 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2708
2709 /* 3DSTATE_HS */
2710 cmd_batch_pointer(cmd, 7, &dw);
2711 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2712 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2713
2714 /* 3DSTATE_TE */
2715 cmd_batch_pointer(cmd, 4, &dw);
2716 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2717 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2718
2719 /* 3DSTATE_CONSTANT_DS */
2720 cmd_batch_pointer(cmd, 7, &dw);
2721 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2722 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2723
2724 /* 3DSTATE_DS */
2725 cmd_batch_pointer(cmd, 6, &dw);
2726 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2727 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2728
2729 /* 3DSTATE_CONSTANT_GS */
2730 cmd_batch_pointer(cmd, 7, &dw);
2731 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2732 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2733
2734 /* 3DSTATE_GS */
2735 cmd_batch_pointer(cmd, 7, &dw);
2736 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2737 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2738
2739 /* 3DSTATE_STREAMOUT */
2740 cmd_batch_pointer(cmd, 3, &dw);
2741 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2742 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2743
Chia-I Wu6032b892014-10-17 14:47:18 +08002744 /* 3DSTATE_SF */
2745 cmd_batch_pointer(cmd, 7, &dw);
2746 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2747 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2748
2749 /* 3DSTATE_SBE */
2750 cmd_batch_pointer(cmd, 14, &dw);
2751 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2752 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2753 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002754}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002755
Chia-I Wu29e6f502014-11-24 14:27:29 +08002756static void gen6_meta_clip(struct intel_cmd *cmd)
2757{
2758 const struct intel_cmd_meta *meta = cmd->bind.meta;
2759 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002760
Chia-I Wu29e6f502014-11-24 14:27:29 +08002761 /* 3DSTATE_CLIP */
2762 cmd_batch_pointer(cmd, 4, &dw);
2763 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2764 dw[1] = 0;
2765 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2766 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2767 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2768 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002769 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002770 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002771 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002772}
2773
2774static void gen6_meta_wm(struct intel_cmd *cmd)
2775{
2776 const struct intel_cmd_meta *meta = cmd->bind.meta;
2777 uint32_t *dw;
2778
2779 CMD_ASSERT(cmd, 6, 7.5);
2780
2781 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2782
2783 /* 3DSTATE_MULTISAMPLE */
2784 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2785 cmd_batch_pointer(cmd, 4, &dw);
2786 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2787 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2788 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2789 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2790 dw[2] = 0;
2791 dw[3] = 0;
2792 } else {
2793 cmd_batch_pointer(cmd, 3, &dw);
2794 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2795 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2796 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2797 dw[2] = 0;
2798 }
2799
2800 /* 3DSTATE_SAMPLE_MASK */
2801 cmd_batch_pointer(cmd, 2, &dw);
2802 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2803 dw[1] = (1 << meta->samples) - 1;
2804
2805 /* 3DSTATE_DRAWING_RECTANGLE */
2806 cmd_batch_pointer(cmd, 4, &dw);
2807 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002808 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2809 /* unused */
2810 dw[1] = 0;
2811 dw[2] = 0;
2812 } else {
2813 dw[1] = meta->dst.y << 16 | meta->dst.x;
2814 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2815 (meta->dst.x + meta->width - 1);
2816 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002817 dw[3] = 0;
2818}
2819
2820static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2821{
2822 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002823 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002824 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002825 uint32_t consts[8];
2826 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002827
2828 CMD_ASSERT(cmd, 6, 7.5);
2829
2830 /* underflow is fine here */
2831 offset_x = meta->src.x - meta->dst.x;
2832 offset_y = meta->src.y - meta->dst.y;
2833
2834 switch (meta->shader_id) {
2835 case INTEL_DEV_META_FS_COPY_MEM:
2836 case INTEL_DEV_META_FS_COPY_1D:
2837 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2838 case INTEL_DEV_META_FS_COPY_2D:
2839 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2840 case INTEL_DEV_META_FS_COPY_2D_MS:
2841 consts[0] = offset_x;
2842 consts[1] = offset_y;
2843 consts[2] = meta->src.layer;
2844 consts[3] = meta->src.lod;
2845 const_count = 4;
2846 break;
2847 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2848 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2849 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2850 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2851 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2852 consts[0] = offset_x;
2853 consts[1] = offset_y;
2854 consts[2] = meta->src.layer;
2855 consts[3] = meta->src.lod;
2856 consts[4] = meta->src.x;
2857 consts[5] = meta->width;
2858 const_count = 6;
2859 break;
2860 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2861 consts[0] = offset_x;
2862 consts[1] = offset_y;
2863 consts[2] = meta->width;
2864 const_count = 3;
2865 break;
2866 case INTEL_DEV_META_FS_CLEAR_COLOR:
2867 consts[0] = meta->clear_val[0];
2868 consts[1] = meta->clear_val[1];
2869 consts[2] = meta->clear_val[2];
2870 consts[3] = meta->clear_val[3];
2871 const_count = 4;
2872 break;
2873 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2874 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002875 consts[1] = meta->clear_val[1];
2876 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002877 break;
2878 case INTEL_DEV_META_FS_RESOLVE_2X:
2879 case INTEL_DEV_META_FS_RESOLVE_4X:
2880 case INTEL_DEV_META_FS_RESOLVE_8X:
2881 case INTEL_DEV_META_FS_RESOLVE_16X:
2882 consts[0] = offset_x;
2883 consts[1] = offset_y;
2884 const_count = 2;
2885 break;
2886 default:
2887 assert(!"unknown meta shader id");
2888 const_count = 0;
2889 break;
2890 }
2891
2892 /* this can be skipped but it makes state dumping prettier */
2893 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2894
2895 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2896}
2897
2898static void gen6_meta_ps(struct intel_cmd *cmd)
2899{
2900 const struct intel_cmd_meta *meta = cmd->bind.meta;
2901 const struct intel_pipeline_shader *sh =
2902 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2903 uint32_t offset, *dw;
2904
2905 CMD_ASSERT(cmd, 6, 6);
2906
Chia-I Wu29e6f502014-11-24 14:27:29 +08002907 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2908 /* 3DSTATE_CONSTANT_PS */
2909 cmd_batch_pointer(cmd, 5, &dw);
2910 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2911 dw[1] = 0;
2912 dw[2] = 0;
2913 dw[3] = 0;
2914 dw[4] = 0;
2915
2916 /* 3DSTATE_WM */
2917 cmd_batch_pointer(cmd, 9, &dw);
2918 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2919 dw[1] = 0;
2920 dw[2] = 0;
2921 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002922
2923 switch (meta->ds.op) {
2924 case INTEL_CMD_META_DS_HIZ_CLEAR:
2925 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2926 break;
2927 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2928 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2929 break;
2930 case INTEL_CMD_META_DS_RESOLVE:
2931 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2932 break;
2933 default:
2934 dw[4] = 0;
2935 break;
2936 }
2937
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002938 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002939 dw[6] = 0;
2940 dw[7] = 0;
2941 dw[8] = 0;
2942
Chia-I Wu3adf7212014-10-24 15:34:07 +08002943 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002944 }
2945
Chia-I Wu3adf7212014-10-24 15:34:07 +08002946 /* a normal color write */
2947 assert(meta->dst.valid && !sh->uses);
2948
Chia-I Wu6032b892014-10-17 14:47:18 +08002949 /* 3DSTATE_CONSTANT_PS */
2950 offset = gen6_meta_ps_constants(cmd);
2951 cmd_batch_pointer(cmd, 5, &dw);
2952 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002953 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002954 dw[1] = offset;
2955 dw[2] = 0;
2956 dw[3] = 0;
2957 dw[4] = 0;
2958
2959 /* 3DSTATE_WM */
2960 offset = emit_shader(cmd, sh);
2961 cmd_batch_pointer(cmd, 9, &dw);
2962 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2963 dw[1] = offset;
2964 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2965 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002966 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002967 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002968 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002969 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2970 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002971
Chia-I Wu6032b892014-10-17 14:47:18 +08002972 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002973 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002974 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2975 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2976 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2977 if (meta->samples > 1) {
2978 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2979 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2980 } else {
2981 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2982 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2983 }
2984 dw[7] = 0;
2985 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002986
2987 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002988}
2989
2990static void gen7_meta_ps(struct intel_cmd *cmd)
2991{
2992 const struct intel_cmd_meta *meta = cmd->bind.meta;
2993 const struct intel_pipeline_shader *sh =
2994 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2995 uint32_t offset, *dw;
2996
2997 CMD_ASSERT(cmd, 7, 7.5);
2998
Chia-I Wu29e6f502014-11-24 14:27:29 +08002999 if (meta->mode != INTEL_CMD_META_FS_RECT) {
3000 /* 3DSTATE_WM */
3001 cmd_batch_pointer(cmd, 3, &dw);
3002 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003003
3004 switch (meta->ds.op) {
3005 case INTEL_CMD_META_DS_HIZ_CLEAR:
3006 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3007 break;
3008 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3009 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3010 break;
3011 case INTEL_CMD_META_DS_RESOLVE:
3012 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3013 break;
3014 default:
3015 dw[1] = 0;
3016 break;
3017 }
3018
3019 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003020
3021 /* 3DSTATE_CONSTANT_GS */
3022 cmd_batch_pointer(cmd, 7, &dw);
3023 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3024 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3025
3026 /* 3DSTATE_PS */
3027 cmd_batch_pointer(cmd, 8, &dw);
3028 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3029 dw[1] = 0;
3030 dw[2] = 0;
3031 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003032 /* required to avoid hangs */
3033 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003034 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003035 dw[5] = 0;
3036 dw[6] = 0;
3037 dw[7] = 0;
3038
Chia-I Wu3adf7212014-10-24 15:34:07 +08003039 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003040 }
3041
Chia-I Wu3adf7212014-10-24 15:34:07 +08003042 /* a normal color write */
3043 assert(meta->dst.valid && !sh->uses);
3044
Chia-I Wu6032b892014-10-17 14:47:18 +08003045 /* 3DSTATE_WM */
3046 cmd_batch_pointer(cmd, 3, &dw);
3047 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003048 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003049 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3050 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3051 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3052 dw[2] = 0;
3053
3054 /* 3DSTATE_CONSTANT_PS */
3055 offset = gen6_meta_ps_constants(cmd);
3056 cmd_batch_pointer(cmd, 7, &dw);
3057 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003058 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003059 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003060 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003061 dw[4] = 0;
3062 dw[5] = 0;
3063 dw[6] = 0;
3064
3065 /* 3DSTATE_PS */
3066 offset = emit_shader(cmd, sh);
3067 cmd_batch_pointer(cmd, 8, &dw);
3068 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3069 dw[1] = offset;
3070 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3071 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003072 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003073
3074 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3075 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003076 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003077
3078 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003079 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003080 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003081 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003082 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003083 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003084
3085 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3086 dw[6] = 0;
3087 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003088
3089 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003090}
3091
3092static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3093{
3094 const struct intel_cmd_meta *meta = cmd->bind.meta;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06003095 const struct intel_att_view *view = &meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003096
3097 CMD_ASSERT(cmd, 6, 7.5);
3098
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003099 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003100 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003101 static const struct intel_att_view null_view;
3102 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003103 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003104
3105 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003106 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3107 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3108 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003109
3110 if (cmd_gen(cmd) >= INTEL_GEN(7))
3111 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3112 else
3113 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003114}
3115
Chia-I Wu862c5572015-03-28 15:23:55 +08003116static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3117 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003118 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003119{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003120 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003121 if (data->set_offsets)
3122 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003123
Chia-I Wu862c5572015-03-28 15:23:55 +08003124 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003125 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003126 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003127 if (!data->set_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->set_offset_count = 0;
3130 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003131 }
3132
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003133 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003134 }
3135
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003136 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003137 if (data->dynamic_offsets)
3138 intel_free(cmd, data->dynamic_offsets);
3139
3140 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003141 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003142 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003143 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003144 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003145 data->dynamic_offset_count = 0;
3146 return false;
3147 }
3148
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003149 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003150 }
3151
3152 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003153}
3154
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003155static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3156 const struct intel_pipeline *pipeline)
3157{
3158 cmd->bind.pipeline.graphics = pipeline;
3159
3160 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003161 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003162}
3163
3164static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3165 const struct intel_pipeline *pipeline)
3166{
3167 cmd->bind.pipeline.compute = pipeline;
3168
3169 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003170 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003171}
3172
Chia-I Wu862c5572015-03-28 15:23:55 +08003173static void cmd_copy_dset_data(struct intel_cmd *cmd,
3174 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003175 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003176 uint32_t index,
3177 const struct intel_desc_set *set,
3178 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003179{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003180 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003181
Chia-I Wu862c5572015-03-28 15:23:55 +08003182 assert(index < data->set_offset_count);
3183 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003184
Chia-I Wu862c5572015-03-28 15:23:55 +08003185 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003186 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003187 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003188
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003189 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003190 dynamic_offsets,
3191 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003192 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003193}
3194
Chia-I Wu3b04af52014-11-08 10:48:20 +08003195static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003196 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003197 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003198{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003199 /* TODOVV: verify */
3200 assert(!(binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) && "binding exceeds buf size");
Chia-I Wu3b04af52014-11-08 10:48:20 +08003201
Chia-I Wu714df452015-01-01 07:55:04 +08003202 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003203 cmd->bind.vertex.offset[binding] = offset;
3204}
3205
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003206static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003207 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003208 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003209{
Chia-I Wu714df452015-01-01 07:55:04 +08003210 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003211 cmd->bind.index.offset = offset;
3212 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003213}
3214
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003215static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003216 const struct intel_dynamic_viewport *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217{
3218 cmd->bind.state.viewport = state;
3219}
3220
Cody Northrope4bc6942015-08-26 10:01:32 -06003221static void cmd_bind_line_width_state(struct intel_cmd *cmd,
3222 const struct intel_dynamic_line_width *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003223{
Cody Northrope4bc6942015-08-26 10:01:32 -06003224 cmd->bind.state.line_width = state;
Cody Northropf5bd2252015-08-17 11:10:49 -06003225}
3226
Cody Northrope4bc6942015-08-26 10:01:32 -06003227static void cmd_bind_depth_bias_state(struct intel_cmd *cmd,
3228 const struct intel_dynamic_depth_bias *state)
Cody Northropf5bd2252015-08-17 11:10:49 -06003229{
Cody Northrope4bc6942015-08-26 10:01:32 -06003230 cmd->bind.state.depth_bias = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003231}
3232
Cody Northrope4bc6942015-08-26 10:01:32 -06003233static void cmd_bind_depth_bounds_state(struct intel_cmd *cmd,
3234 const struct intel_dynamic_depth_bounds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003235{
Cody Northrope4bc6942015-08-26 10:01:32 -06003236 cmd->bind.state.depth_bounds = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003237}
3238
Cody Northrop2605cb02015-08-18 15:21:16 -06003239static void cmd_bind_stencil_state(struct intel_cmd *cmd,
3240 const struct intel_dynamic_stencil *state)
3241{
3242 cmd->bind.state.stencil = state;
3243}
3244
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003245static void cmd_bind_blend_state(struct intel_cmd *cmd,
Cody Northrope4bc6942015-08-26 10:01:32 -06003246 const struct intel_dynamic_blend *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003247{
3248 cmd->bind.state.blend = state;
3249}
3250
Chia-I Wuf98dd882015-02-10 04:17:47 +08003251static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3252{
3253 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3254 struct intel_pipeline_rmap *rmaps[5] = {
3255 pipeline->vs.rmap,
3256 pipeline->tcs.rmap,
3257 pipeline->tes.rmap,
3258 pipeline->gs.rmap,
3259 pipeline->fs.rmap,
3260 };
3261 uint32_t max_write;
3262 int i;
3263
3264 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3265 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3266 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3267
3268 /* pad first */
3269 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3270
3271 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3272 const struct intel_pipeline_rmap *rmap = rmaps[i];
3273 const uint32_t surface_count = (rmap) ?
3274 rmap->rt_count + rmap->texture_resource_count +
3275 rmap->resource_count + rmap->uav_count : 0;
3276
3277 if (surface_count) {
3278 /* SURFACE_STATEs */
3279 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3280
3281 /* BINDING_TABLE_STATE */
3282 max_write += u_align(sizeof(uint32_t) * surface_count,
3283 GEN6_ALIGNMENT_SURFACE_STATE);
3284 }
3285 }
3286
3287 return max_write;
3288}
3289
3290static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3291{
3292 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3293 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3294 uint32_t max_surface_write;
3295
3296 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3297 if (cmd->bind.meta)
3298 max_surface_write = 64 * sizeof(uint32_t);
3299 else
3300 max_surface_write = cmd_get_max_surface_write(cmd);
3301
3302 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3303 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3304 /* SBA expects page-aligned addresses */
3305 writer->sba_offset = writer->used & ~0xfff;
3306
3307 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3308
3309 cmd_batch_state_base_address(cmd);
3310 }
3311}
3312
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003313static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003314 uint32_t vertex_start,
3315 uint32_t vertex_count,
3316 uint32_t instance_start,
3317 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003318 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003319 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003320{
3321 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003322 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003323 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3324
3325 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003326
3327 emit_bounded_states(cmd);
3328
Chia-I Wuf98dd882015-02-10 04:17:47 +08003329 /* sanity check on cmd_get_max_surface_write() */
3330 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3331 surface_writer_used <= cmd_get_max_surface_write(cmd));
3332
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003333 if (indexed) {
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003334 assert(!(p->primitive_restart && !gen6_can_primitive_restart(cmd)) && "Primitive restart unsupported on this device");
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003335
3336 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3337 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3338 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003339 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003340 cmd->bind.index.offset, cmd->bind.index.type,
3341 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003342 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003343 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003344 cmd->bind.index.offset, cmd->bind.index.type,
3345 p->primitive_restart);
3346 }
3347 } else {
3348 assert(!vertex_base);
3349 }
3350
3351 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3352 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3353 vertex_start, instance_count, instance_start, vertex_base);
3354 } else {
3355 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3356 vertex_start, instance_count, instance_start, vertex_base);
3357 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003358
Chia-I Wu707a29e2014-08-27 12:51:47 +08003359 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003360 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003361 /* need to re-emit all workarounds */
3362 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003363
3364 if (intel_debug & INTEL_DEBUG_NOCACHE)
3365 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003366}
3367
Chia-I Wuc14d1562014-10-17 09:49:22 +08003368void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3369{
Chia-I Wu6032b892014-10-17 14:47:18 +08003370 cmd->bind.meta = meta;
3371
Chia-I Wuf98dd882015-02-10 04:17:47 +08003372 cmd_adjust_state_base_address(cmd);
3373
Chia-I Wu6032b892014-10-17 14:47:18 +08003374 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003375 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003376
3377 gen6_meta_dynamic_states(cmd);
3378 gen6_meta_surface_states(cmd);
3379
3380 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3381 gen7_meta_urb(cmd);
3382 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003383 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003384 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003385 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003386 gen6_meta_wm(cmd);
3387 gen7_meta_ps(cmd);
3388 gen6_meta_depth_buffer(cmd);
3389
3390 cmd_wa_gen7_post_command_cs_stall(cmd);
3391 cmd_wa_gen7_post_command_depth_stall(cmd);
3392
Chia-I Wu29e6f502014-11-24 14:27:29 +08003393 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3394 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003395 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003396 } else {
3397 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3398 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003399 } else {
3400 gen6_meta_urb(cmd);
3401 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003402 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003403 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003404 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003405 gen6_meta_wm(cmd);
3406 gen6_meta_ps(cmd);
3407 gen6_meta_depth_buffer(cmd);
3408
Chia-I Wu29e6f502014-11-24 14:27:29 +08003409 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3410 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003411 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003412 } else {
3413 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3414 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003415 }
3416
3417 cmd->bind.draw_count++;
3418 /* need to re-emit all workarounds */
3419 cmd->bind.wa_flags = 0;
3420
3421 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003422
Chia-I Wubbc7d912015-02-27 14:59:50 -07003423 /* make the normal path believe the render pass has changed */
3424 cmd->bind.render_pass_changed = true;
3425
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003426 if (intel_debug & INTEL_DEBUG_NOCACHE)
3427 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003428}
3429
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003430static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3431{
3432 const uint8_t cmd_len = 2;
3433 uint32_t *dw;
3434 uint32_t pos;
3435
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003436 assert(!(cmd_gen(cmd) < INTEL_GEN(7.5)) && "Invalid GPU version");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003437
3438 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3439 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3440 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3441 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3442 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3443
3444 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3445}
3446
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003447ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003448 VkCmdBuffer cmdBuffer,
3449 VkPipelineBindPoint pipelineBindPoint,
3450 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003451{
3452 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3453
3454 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003455 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003456 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003457 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003458 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003459 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003460 break;
3461 default:
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003462 assert(!"unsupported pipelineBindPoint");
Chia-I Wub2755562014-08-20 13:38:52 +08003463 break;
3464 }
3465}
3466
Tony Barbourde4124d2015-07-03 10:33:54 -06003467ICD_EXPORT void VKAPI vkCmdBindDynamicViewportState(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003468 VkCmdBuffer cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003469 VkDynamicViewportState state)
Chia-I Wub2755562014-08-20 13:38:52 +08003470{
3471 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3472
Tony Barbourde4124d2015-07-03 10:33:54 -06003473 cmd_bind_viewport_state(cmd,
3474 intel_dynamic_viewport(state));
3475}
3476
Cody Northrope4bc6942015-08-26 10:01:32 -06003477ICD_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003478 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003479 VkDynamicLineWidthState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003480{
3481 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3482
Cody Northrope4bc6942015-08-26 10:01:32 -06003483 cmd_bind_line_width_state(cmd,
3484 intel_dynamic_line_width(state));
Cody Northropf5bd2252015-08-17 11:10:49 -06003485}
3486
Cody Northrope4bc6942015-08-26 10:01:32 -06003487ICD_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(
Cody Northropf5bd2252015-08-17 11:10:49 -06003488 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003489 VkDynamicDepthBiasState state)
Cody Northropf5bd2252015-08-17 11:10:49 -06003490{
3491 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3492
Cody Northrope4bc6942015-08-26 10:01:32 -06003493 cmd_bind_depth_bias_state(cmd,
3494 intel_dynamic_depth_bias(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003495}
3496
Cody Northrope4bc6942015-08-26 10:01:32 -06003497ICD_EXPORT void VKAPI vkCmdBindDynamicBlendState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003498 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003499 VkDynamicBlendState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003500{
3501 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3502
3503 cmd_bind_blend_state(cmd,
Cody Northrope4bc6942015-08-26 10:01:32 -06003504 intel_dynamic_blend(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003505}
3506
Cody Northrope4bc6942015-08-26 10:01:32 -06003507ICD_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003508 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003509 VkDynamicDepthBoundsState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003510{
3511 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3512
Cody Northrope4bc6942015-08-26 10:01:32 -06003513 cmd_bind_depth_bounds_state(cmd,
3514 intel_dynamic_depth_bounds(state));
Cody Northrop2605cb02015-08-18 15:21:16 -06003515}
3516
3517ICD_EXPORT void VKAPI vkCmdBindDynamicStencilState(
3518 VkCmdBuffer cmdBuffer,
3519 VkDynamicStencilState state)
3520{
3521 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3522
3523 cmd_bind_stencil_state(cmd,
3524 intel_dynamic_stencil(state));
Chia-I Wub2755562014-08-20 13:38:52 +08003525}
3526
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003527ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003528 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003529 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003530 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003531 uint32_t firstSet,
3532 uint32_t setCount,
3533 const VkDescriptorSet* pDescriptorSets,
3534 uint32_t dynamicOffsetCount,
3535 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003536{
3537 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003538 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003539 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003540 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003541 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003542
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003543 pipeline_layout = intel_pipeline_layout(layout);
3544
Chia-I Wub2755562014-08-20 13:38:52 +08003545 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003546 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003547 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003548 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003549 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003550 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003551 break;
3552 default:
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003553 assert(!"unsupported pipelineBindPoint");
Chia-I Wub2755562014-08-20 13:38:52 +08003554 break;
3555 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003556
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003557 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003558 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3559
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003560 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003561 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003562 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003563 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003564 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003565 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003566 }
Chia-I Wub2755562014-08-20 13:38:52 +08003567}
3568
Tony Barbour8205d902015-04-16 15:59:00 -06003569
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003570ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3571 VkCmdBuffer cmdBuffer,
3572 uint32_t startBinding,
3573 uint32_t bindingCount,
3574 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003575 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003576{
3577 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003578
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003579 for (uint32_t i = 0; i < bindingCount; i++) {
3580 struct intel_buf *buf = intel_buf(pBuffers[i]);
3581 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3582 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003583}
3584
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003585ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003586 VkCmdBuffer cmdBuffer,
3587 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003588 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003589 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003590{
3591 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003592 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003593
Chia-I Wu714df452015-01-01 07:55:04 +08003594 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003595}
3596
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003597ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003598 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003599 uint32_t firstVertex,
3600 uint32_t vertexCount,
3601 uint32_t firstInstance,
3602 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003603{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003604 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003605
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003606 cmd_draw(cmd, firstVertex, vertexCount,
3607 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003608}
3609
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003610ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003611 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003612 uint32_t firstIndex,
3613 uint32_t indexCount,
3614 int32_t vertexOffset,
3615 uint32_t firstInstance,
3616 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003617{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003618 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003619
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003620 cmd_draw(cmd, firstIndex, indexCount,
3621 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003622}
3623
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003624ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003625 VkCmdBuffer cmdBuffer,
3626 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003627 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003628 uint32_t count,
3629 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003630{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003631 assert(0 && "vkCmdDrawIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003632}
3633
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003634ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003635 VkCmdBuffer cmdBuffer,
3636 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003637 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003638 uint32_t count,
3639 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003640{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003641 assert(0 && "vkCmdDrawIndexedIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003642}
3643
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003644ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003645 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003646 uint32_t x,
3647 uint32_t y,
3648 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003649{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003650 assert(0 && "vkCmdDispatch not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003651}
3652
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003653ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003654 VkCmdBuffer cmdBuffer,
3655 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003656 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003657{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003658 assert(0 && "vkCmdDisatchIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003659}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003660
Courtney Goeltzenleuchtera375b622015-07-27 14:04:01 -06003661void VKAPI vkCmdPushConstants(
3662 VkCmdBuffer cmdBuffer,
3663 VkPipelineLayout layout,
3664 VkShaderStageFlags stageFlags,
3665 uint32_t start,
3666 uint32_t length,
3667 const void* values)
3668{
3669 /* TODO: Implement */
3670}
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003671
3672VkResult VKAPI vkGetRenderAreaGranularity(
3673 VkDevice device,
3674 VkRenderPass renderPass,
3675 VkExtent2D* pGranularity)
3676{
3677 pGranularity->height = 1;
3678 pGranularity->width = 1;
3679
3680 return VK_SUCCESS;
3681}
3682
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003683ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003684 VkCmdBuffer cmdBuffer,
3685 const VkRenderPassBeginInfo* pRenderPassBegin,
3686 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003687{
Chia-I Wubdeed152015-07-09 12:16:29 +08003688 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3689 const struct intel_render_pass *rp =
3690 intel_render_pass(pRenderPassBegin->renderPass);
3691 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3692 const struct intel_att_view *view;
3693 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003694
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003695 /* TODOVV: */
3696 assert(!(!cmd->primary || rp->attachment_count != fb->view_count) && "Invalid RenderPass");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003697
Cody Northrop16898b02015-08-11 11:35:58 -06003698 cmd_begin_render_pass(cmd, rp, fb, 0, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003699
Chia-I Wubdeed152015-07-09 12:16:29 +08003700 for (i = 0; i < rp->attachment_count; i++) {
3701 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003702 const VkClearValue *clear_val =
Cody Northropc332eef2015-08-04 11:51:03 -06003703 &pRenderPassBegin->pClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003704 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003705
Chia-I Wubdeed152015-07-09 12:16:29 +08003706 view = fb->views[i];
3707 range.baseMipLevel = view->mipLevel;
3708 range.mipLevels = 1;
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -06003709 range.baseArrayLayer = view->baseArrayLayer;
Chia-I Wubdeed152015-07-09 12:16:29 +08003710 range.arraySize = view->array_size;
Chris Forbesf4107bd2015-09-18 13:23:32 +12003711 range.aspectMask = 0;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003712
Chia-I Wubdeed152015-07-09 12:16:29 +08003713 if (view->is_rt) {
Chris Forbesf4107bd2015-09-18 13:23:32 +12003714 /* color */
3715 if (att->clear_on_load) {
3716 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003717
Chris Forbesf4107bd2015-09-18 13:23:32 +12003718 cmd_meta_clear_color_image(cmdBuffer, view->img,
3719 att->initial_layout, &clear_val->color, 1, &range);
3720 }
Chia-I Wubdeed152015-07-09 12:16:29 +08003721 } else {
Chris Forbesf4107bd2015-09-18 13:23:32 +12003722 /* depth/stencil */
3723 if (att->clear_on_load) {
3724 range.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
3725 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003726
Chia-I Wubdeed152015-07-09 12:16:29 +08003727 if (att->stencil_clear_on_load) {
Chris Forbesf4107bd2015-09-18 13:23:32 +12003728 range.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
3729 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003730
Chris Forbesf4107bd2015-09-18 13:23:32 +12003731 if (range.aspectMask) {
Chia-I Wubdeed152015-07-09 12:16:29 +08003732 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003733 view->img, att->initial_layout,
Cody Northrop2563a032015-08-25 15:26:38 -06003734 clear_val->depthStencil.depth, clear_val->depthStencil.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003735 1, &range);
3736 }
3737 }
3738 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003739}
3740
Chia-I Wuc278df82015-07-07 11:50:03 +08003741ICD_EXPORT void VKAPI vkCmdNextSubpass(
3742 VkCmdBuffer cmdBuffer,
3743 VkRenderPassContents contents)
3744{
3745 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3746 const struct intel_render_pass *rp = cmd->bind.render_pass;
3747
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003748 /* TODOVV */
3749 assert(!(cmd->bind.render_pass_subpass >= rp->subpasses +
3750 rp->subpass_count - 1) && "Invalid RenderPassContents");
Chia-I Wuc278df82015-07-07 11:50:03 +08003751
3752 cmd->bind.render_pass_changed = true;
3753 cmd->bind.render_pass_subpass++;
3754 cmd->bind.render_pass_contents = contents;
3755}
3756
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003757ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003758 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003759{
3760 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3761
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003762 cmd_end_render_pass(cmd);
3763}
3764
3765ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3766 VkCmdBuffer cmdBuffer,
3767 uint32_t cmdBuffersCount,
3768 const VkCmdBuffer* pCmdBuffers)
3769{
3770 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003771 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003772
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003773 /* TODOVV */
3774 assert(!(!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3775 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) && "Invalid RenderPass");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003776
3777 for (i = 0; i < cmdBuffersCount; i++) {
3778 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3779
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003780 /* TODOVV: Move test to validation layer */
3781 assert(!(secondary->primary) && "Cannot be primary command buffer");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003782
3783 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3784 }
3785
3786 if (i)
3787 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003788}