blob: 20bd8e4c1dd85d7f8884498e525df4fc67cd888b [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
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -060029#include <math.h>
Chia-I Wu9f039862014-08-20 15:39:56 +080030#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080031#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080032#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080033#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080034#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080035#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080036#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080037#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080038#include "state.h"
39#include "view.h"
40#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070041#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080042
Chia-I Wu59c097e2014-08-21 10:51:07 +080043static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080044 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080045 uint32_t vertex_count,
46 uint32_t vertex_start,
47 uint32_t instance_count,
48 uint32_t instance_start,
49 uint32_t vertex_base)
50{
51 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080052 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080053
54 CMD_ASSERT(cmd, 6, 6);
55
Chia-I Wu426072d2014-08-26 14:31:55 +080056 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080057 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080058 (cmd_len - 2);
59
60 if (indexed)
61 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
62
Chia-I Wu72292b72014-09-09 10:48:33 +080063 cmd_batch_pointer(cmd, cmd_len, &dw);
64 dw[0] = dw0;
65 dw[1] = vertex_count;
66 dw[2] = vertex_start;
67 dw[3] = instance_count;
68 dw[4] = instance_start;
69 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080070}
71
72static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080073 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080074 uint32_t vertex_count,
75 uint32_t vertex_start,
76 uint32_t instance_count,
77 uint32_t instance_start,
78 uint32_t vertex_base)
79{
80 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080081 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080082
83 CMD_ASSERT(cmd, 7, 7.5);
84
Chia-I Wu426072d2014-08-26 14:31:55 +080085 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080086 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080087
88 if (indexed)
89 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
90
Chia-I Wu72292b72014-09-09 10:48:33 +080091 cmd_batch_pointer(cmd, cmd_len, &dw);
92 dw[0] = dw0;
93 dw[1] = dw1;
94 dw[2] = vertex_count;
95 dw[3] = vertex_start;
96 dw[4] = instance_count;
97 dw[5] = instance_start;
98 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080099}
100
Chia-I Wu270b1e82014-08-25 15:53:39 +0800101static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800102 struct intel_bo *bo, uint32_t bo_offset,
103 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800104{
105 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800106 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800107 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800108 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800109 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600110 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800111
112 CMD_ASSERT(cmd, 6, 7.5);
113
114 assert(bo_offset % 8 == 0);
115
116 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
117 /*
118 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
119 *
120 * "1 of the following must also be set (when CS stall is set):
121 *
122 * * Depth Cache Flush Enable ([0] of DW1)
123 * * Stall at Pixel Scoreboard ([1] of DW1)
124 * * Depth Stall ([13] of DW1)
125 * * Post-Sync Operation ([13] of DW1)
126 * * Render Target Cache Flush Enable ([12] of DW1)
127 * * Notify Enable ([8] of DW1)"
128 *
129 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
130 *
131 * "One of the following must also be set (when CS stall is set):
132 *
133 * * Render Target Cache Flush Enable ([12] of DW1)
134 * * Depth Cache Flush Enable ([0] of DW1)
135 * * Stall at Pixel Scoreboard ([1] of DW1)
136 * * Depth Stall ([13] of DW1)
137 * * Post-Sync Operation ([13] of DW1)"
138 */
139 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
141 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
142 GEN6_PIPE_CONTROL_DEPTH_STALL;
143
144 /* post-sync op */
145 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
146 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
147 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
148
149 if (cmd_gen(cmd) == INTEL_GEN(6))
150 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
151
152 assert(dw1 & bit_test);
153 }
154
155 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
156 /*
157 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
158 *
159 * "Following bits must be clear (when Depth Stall is set):
160 *
161 * * Render Target Cache Flush Enable ([12] of DW1)
162 * * Depth Cache Flush Enable ([0] of DW1)"
163 */
164 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
165 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
166 }
167
168 /*
169 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
170 *
171 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
172 * and PIPE_CONTROL are not supported."
173 *
174 * The kernel will add the mapping automatically (when write domain is
175 * INTEL_DOMAIN_INSTRUCTION).
176 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800177 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800178 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800179 reloc_flags |= INTEL_RELOC_GGTT;
180 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800181
Chia-I Wu72292b72014-09-09 10:48:33 +0800182 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
183 dw[0] = dw0;
184 dw[1] = dw1;
185 dw[2] = 0;
186 dw[3] = (uint32_t) imm;
187 dw[4] = (uint32_t) (imm >> 32);
188
189 if (bo) {
190 cmd_reserve_reloc(cmd, 1);
191 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
192 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800193}
194
Chia-I Wu254db422014-08-21 11:54:29 +0800195static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
196{
197 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
198 bool supported;
199
200 CMD_ASSERT(cmd, 6, 7.5);
201
202 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
203 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
204
205 switch (p->prim_type) {
206 case GEN6_3DPRIM_POINTLIST:
207 case GEN6_3DPRIM_LINELIST:
208 case GEN6_3DPRIM_LINESTRIP:
209 case GEN6_3DPRIM_TRILIST:
210 case GEN6_3DPRIM_TRISTRIP:
211 supported = true;
212 break;
213 default:
214 supported = false;
215 break;
216 }
217
218 if (!supported)
219 return false;
220
221 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600222 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800223 supported = (p->primitive_restart_index != 0xffffu);
224 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600225 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800226 supported = (p->primitive_restart_index != 0xffffffffu);
227 break;
228 default:
229 supported = false;
230 break;
231 }
232
233 return supported;
234}
235
Chia-I Wu59c097e2014-08-21 10:51:07 +0800236static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800237 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600238 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600239 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800240 bool enable_cut_index)
241{
242 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800243 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800244 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600245 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800246
247 CMD_ASSERT(cmd, 6, 7.5);
248
Chia-I Wu426072d2014-08-26 14:31:55 +0800249 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800250
251 /* the bit is moved to 3DSTATE_VF */
252 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
253 assert(!enable_cut_index);
254 if (enable_cut_index)
255 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
256
257 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600258 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800259 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
260 offset_align = 2;
261 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600262 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800263 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
264 offset_align = 4;
265 break;
266 default:
Tobin Ehlis8d199e52015-09-17 12:24:13 -0600267 assert(!"unsupported index type");
Chia-I Wu59c097e2014-08-21 10:51:07 +0800268 break;
269 }
270
Chia-I Wu59c097e2014-08-21 10:51:07 +0800271 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800272 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800273
Chia-I Wu72292b72014-09-09 10:48:33 +0800274 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
275 dw[0] = dw0;
276
277 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800278 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
279 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280}
281
Chia-I Wu62a7f252014-08-29 11:31:16 +0800282static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
283 bool enable_cut_index,
284 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800285{
286 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800287 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800288
289 CMD_ASSERT(cmd, 7.5, 7.5);
290
Chia-I Wu426072d2014-08-26 14:31:55 +0800291 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800292 if (enable_cut_index)
293 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
294
Chia-I Wu72292b72014-09-09 10:48:33 +0800295 cmd_batch_pointer(cmd, cmd_len, &dw);
296 dw[0] = dw0;
297 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800298}
299
Cody Northrop293d4502015-05-05 09:38:03 -0600300static void gen6_add_scratch_space(struct intel_cmd *cmd,
301 uint32_t batch_pos,
302 const struct intel_pipeline *pipeline,
303 const struct intel_pipeline_shader *sh)
304{
305 int scratch_space;
306
307 CMD_ASSERT(cmd, 6, 7.5);
308
309 assert(sh->per_thread_scratch_size &&
310 sh->per_thread_scratch_size % 1024 == 0 &&
311 u_is_pow2(sh->per_thread_scratch_size) &&
312 sh->scratch_offset % 1024 == 0);
313 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
314
315 cmd_reserve_reloc(cmd, 1);
316 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
317 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
318}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600319
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800320static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
321{
Cody Northrop293d4502015-05-05 09:38:03 -0600322 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
323 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800324 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600325 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800326 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600327 int vue_read_len = 0;
328 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800329
Cody Northrop293d4502015-05-05 09:38:03 -0600330 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
331
332 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
333
334 // based on ilo_gpe_init_gs_cso_gen6
335 vue_read_len = (gs->in_count + 1) / 2;
336 if (!vue_read_len)
337 vue_read_len = 1;
338
339 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
340 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
341 GEN6_THREADDISP_SPF;
342
343 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
344 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
345 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
346
347 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
348 GEN6_GS_DW5_STATISTICS |
349 GEN6_GS_DW5_RENDER_ENABLE;
350
351 dw6 = GEN6_GS_DW6_GS_ENABLE;
352
353 if (gs->discard_adj)
354 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
355
356 } else {
357 dw2 = 0;
358 dw4 = 0;
359 dw5 = GEN6_GS_DW5_STATISTICS;
360 dw6 = 0;
361 }
362
363 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800364 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600365 dw[1] = cmd->bind.pipeline.gs_offset;
366 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800367 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600368 dw[4] = dw4;
369 dw[5] = dw5;
370 dw[6] = dw6;
371
372 if (gs->per_thread_scratch_size)
373 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800374}
375
Chia-I Wu62a7f252014-08-29 11:31:16 +0800376static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
377{
Cody Northrop293d4502015-05-05 09:38:03 -0600378 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
379 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800380 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600381 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800382 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600383 int vue_read_len = 0;
384 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800385
Cody Northrop293d4502015-05-05 09:38:03 -0600386 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
387
388 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
389
390 // based on upload_gs_state
391 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
392 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
393
394 vue_read_len = (gs->in_count + 1) / 2;
395 if (!vue_read_len)
396 vue_read_len = 1;
397
398 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
399 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
400 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
401 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
402 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
403
404
405 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
406 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
407 GEN7_GS_DW5_STATISTICS |
408 GEN7_GS_DW5_GS_ENABLE;
409
410 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
411 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
412
413 if (gs->include_primitive_id)
414 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
415
416 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
417 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
418 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
419 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
420 } else {
421 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
422 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
423 dw6 = 0;
424 }
425 } else {
426 dw2 = 0;
427 dw4 = 0;
428 dw5 = GEN7_GS_DW5_STATISTICS;
429 dw6 = 0;
430 }
431
432 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800433 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600434 dw[1] = cmd->bind.pipeline.gs_offset;
435 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800436 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600437 dw[4] = dw4;
438 dw[5] = dw5;
439 dw[6] = dw6;
440
441 if (gs->per_thread_scratch_size)
442 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800443}
444
Chia-I Wud88e02d2014-08-25 10:56:13 +0800445static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600446 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800447{
448 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800449 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800450 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800451 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452
453 CMD_ASSERT(cmd, 6, 7.5);
454
Chia-I Wu72292b72014-09-09 10:48:33 +0800455 cmd_batch_pointer(cmd, cmd_len, &dw);
456 dw[0] = dw0;
457
Chia-I Wud88e02d2014-08-25 10:56:13 +0800458 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800459 dw[1] = 0;
460 dw[2] = (height - 1) << 16 |
461 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800462 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800463 dw[1] = 1;
464 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800465 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800466
467 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800468}
469
Chia-I Wu8016a172014-08-29 18:31:32 +0800470static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
471 uint32_t body[6])
472{
473 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800474 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800475 const struct intel_render_pass_subpass *subpass =
476 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600477 const struct intel_dynamic_line_width *line_width = &cmd->bind.state.line_width;
478 const struct intel_dynamic_depth_bias *depth_bias = &cmd->bind.state.depth_bias;
Cody Northropf5bd2252015-08-17 11:10:49 -0600479 uint32_t dw1, dw2, dw3, dw4, dw5, dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800480
481 CMD_ASSERT(cmd, 6, 7.5);
482
483 dw1 = GEN7_SF_DW1_STATISTICS |
484 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
485 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
486 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
487 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700488 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800489
490 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800491 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800492
Chia-I Wubdeed152015-07-09 12:16:29 +0800493 if (subpass->ds_index < rp->attachment_count) {
494 switch (rp->attachments[subpass->ds_index].format) {
495 case VK_FORMAT_D16_UNORM:
496 format = GEN6_ZFORMAT_D16_UNORM;
497 break;
498 case VK_FORMAT_D32_SFLOAT:
499 case VK_FORMAT_D32_SFLOAT_S8_UINT:
500 format = GEN6_ZFORMAT_D32_FLOAT;
501 break;
502 default:
503 assert(!"unsupported depth/stencil format");
504 break;
505 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800506 }
507
508 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
509 }
510
Tony Barbourfa6cac72015-01-16 14:27:35 -0700511 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800512
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700513 /* Scissor is always enabled */
514 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
515
Cody Northropf5bd2252015-08-17 11:10:49 -0600516 // TODO: line width support
Cody Northrope4bc6942015-08-26 10:01:32 -0600517 (void) line_width;
Cody Northropf5bd2252015-08-17 11:10:49 -0600518
Tony Barbourfa6cac72015-01-16 14:27:35 -0700519 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800520 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
521 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
522 } else {
523 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
524 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
525 }
526
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600527 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
528 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
529 2 << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800530 GEN7_SF_DW3_SUBPIXEL_8BITS;
531
Cody Northropf5bd2252015-08-17 11:10:49 -0600532 if (pipeline->depthBiasEnable) {
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600533 dw4 = u_fui((float) depth_bias->depth_bias * 2.0f);
534 dw5 = u_fui(depth_bias->slope_scaled_depth_bias);
535 dw6 = u_fui(depth_bias->depth_bias_clamp);
Cody Northropf5bd2252015-08-17 11:10:49 -0600536 } else {
537 dw4 = 0;
538 dw5 = 0;
539 dw6 = 0;
540 }
541
Chia-I Wu8016a172014-08-29 18:31:32 +0800542 body[0] = dw1;
543 body[1] = dw2;
544 body[2] = dw3;
Cody Northropf5bd2252015-08-17 11:10:49 -0600545 body[3] = dw4;
546 body[4] = dw5;
547 body[5] = dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800548}
549
Chia-I Wu8016a172014-08-29 18:31:32 +0800550static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
551{
552 const uint8_t cmd_len = 20;
553 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
554 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800555 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800556 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800557 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800558
559 CMD_ASSERT(cmd, 6, 6);
560
561 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800562
Chia-I Wu72292b72014-09-09 10:48:33 +0800563 cmd_batch_pointer(cmd, cmd_len, &dw);
564 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800565 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800566 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800567 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800568}
569
570static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
571{
572 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800573 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800574
575 CMD_ASSERT(cmd, 7, 7.5);
576
Chia-I Wu72292b72014-09-09 10:48:33 +0800577 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800578 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
579 (cmd_len - 2);
580 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800581}
582
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800583static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
584{
585 const uint8_t cmd_len = 4;
586 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
587 (cmd_len - 2);
588 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700589 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800590 const struct intel_pipeline_shader *fs = &pipeline->fs;
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600591 const struct intel_dynamic_viewport *viewport = &cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800592 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800593
594 CMD_ASSERT(cmd, 6, 7.5);
595
596 dw1 = GEN6_CLIP_DW1_STATISTICS;
597 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
598 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
599 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700600 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800601 }
602
603 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800604 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800605 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700606 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600607 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
608 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
609 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800610
611 if (pipeline->rasterizerDiscardEnable)
612 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
613 else
614 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
615
616 if (pipeline->depthClipEnable)
617 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
618
619 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
620 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
621 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
622 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
623
624 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
625 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
626 (viewport->viewport_count - 1);
627
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600628 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600629 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600630 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
631 }
632
Chia-I Wu72292b72014-09-09 10:48:33 +0800633 cmd_batch_pointer(cmd, cmd_len, &dw);
634 dw[0] = dw0;
635 dw[1] = dw1;
636 dw[2] = dw2;
637 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800638}
639
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800640static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
641{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800642 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800643 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800644 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600645 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700646 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647
648 CMD_ASSERT(cmd, 6, 6);
649
650 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
651
652 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
653 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
654
655 dw4 = GEN6_WM_DW4_STATISTICS |
656 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
657 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700658 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800659
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800660 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700661 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
662 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800663
Cody Northrope86574e2015-02-24 14:15:29 -0700664 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700665 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700666
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800667 if (fs->uses & INTEL_SHADER_USE_KILL ||
Courtney Goeltzenleuchterc8f54f72015-10-15 17:59:39 -0600668 pipeline->alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700669 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670
Cody Northrope238deb2015-01-26 14:41:36 -0700671 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800672 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
673 if (fs->uses & INTEL_SHADER_USE_DEPTH)
674 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
675 if (fs->uses & INTEL_SHADER_USE_W)
676 dw5 |= GEN6_WM_DW5_PS_USE_W;
677
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700678 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700679 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800680
681 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700682 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800683 GEN6_WM_DW6_ZW_INTERP_PIXEL |
684 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
685 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
686
Tony Barbourfa6cac72015-01-16 14:27:35 -0700687 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800688 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
689 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
690 } else {
691 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
692 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
693 }
694
Cody Northrope86574e2015-02-24 14:15:29 -0700695 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
696
Chia-I Wu784d3042014-12-19 14:30:04 +0800697 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800698 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800699 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800700 dw[2] = dw2;
701 dw[3] = 0; /* scratch */
702 dw[4] = dw4;
703 dw[5] = dw5;
704 dw[6] = dw6;
705 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700706 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800707
708 if (fs->per_thread_scratch_size)
709 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800710}
711
712static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
713{
714 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800715 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800716 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800717 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800718
719 CMD_ASSERT(cmd, 7, 7.5);
720
721 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
722
723 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700724 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800725 GEN7_WM_DW1_ZW_INTERP_PIXEL |
726 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
727 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
728
729 if (fs->uses & INTEL_SHADER_USE_KILL ||
Courtney Goeltzenleuchterc8f54f72015-10-15 17:59:39 -0600730 pipeline->alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700731 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800732
Cody Northrope238deb2015-01-26 14:41:36 -0700733 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
734
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800735 if (fs->uses & INTEL_SHADER_USE_DEPTH)
736 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
737 if (fs->uses & INTEL_SHADER_USE_W)
738 dw1 |= GEN7_WM_DW1_PS_USE_W;
739
740 dw2 = 0;
741
Tony Barbourfa6cac72015-01-16 14:27:35 -0700742 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800743 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
744 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
745 } else {
746 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
747 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
748 }
749
Chia-I Wu72292b72014-09-09 10:48:33 +0800750 cmd_batch_pointer(cmd, cmd_len, &dw);
751 dw[0] = dw0;
752 dw[1] = dw1;
753 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800754}
755
756static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
757{
758 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800759 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800760 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700761 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600762 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800763
764 CMD_ASSERT(cmd, 7, 7.5);
765
766 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
767
768 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
769 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
770
771 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700772 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800773
Cody Northrope86574e2015-02-24 14:15:29 -0700774 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700775 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700776
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800777 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800778 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700779 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800780 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800781 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800782 }
783
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800784 if (fs->in_count)
785 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
786
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700787 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800788 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
789
790 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
791 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700792 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
793
794 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800795
Chia-I Wu784d3042014-12-19 14:30:04 +0800796 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800797 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800798 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800799 dw[2] = dw2;
800 dw[3] = 0; /* scratch */
801 dw[4] = dw4;
802 dw[5] = dw5;
803 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700804 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800805
806 if (fs->per_thread_scratch_size)
807 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800808}
809
Chia-I Wu8ada4242015-03-02 11:19:33 -0700810static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
811 uint32_t sample_count)
812{
813 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
814 uint32_t dw1, dw2, dw3, *dw;
815
816 CMD_ASSERT(cmd, 6, 7.5);
817
818 switch (sample_count) {
819 case 4:
820 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
821 dw2 = cmd->dev->sample_pattern_4x;
822 dw3 = 0;
823 break;
824 case 8:
825 assert(cmd_gen(cmd) >= INTEL_GEN(7));
826 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
827 dw2 = cmd->dev->sample_pattern_8x[0];
828 dw3 = cmd->dev->sample_pattern_8x[1];
829 break;
830 default:
831 assert(sample_count <= 1);
832 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
833 dw2 = 0;
834 dw3 = 0;
835 break;
836 }
837
838 cmd_batch_pointer(cmd, cmd_len, &dw);
839
840 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
841 dw[1] = dw1;
842 dw[2] = dw2;
843 if (cmd_gen(cmd) >= INTEL_GEN(7))
844 dw[3] = dw3;
845}
846
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800847static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800848 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700849 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800850{
851 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800852 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600853 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800854
855 CMD_ASSERT(cmd, 6, 7.5);
856
857 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800858 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
859 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800860 dw0 |= (cmd_len - 2);
861
Chia-I Wu72292b72014-09-09 10:48:33 +0800862 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
863 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700864
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800865 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700866 /* note that we only enable HiZ on Gen7+ */
867 if (!optimal_ds)
868 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
869
Chia-I Wu72292b72014-09-09 10:48:33 +0800870 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800871 dw[3] = view->att_cmd[2];
872 dw[4] = view->att_cmd[3];
873 dw[5] = view->att_cmd[4];
874 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800875
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600876 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 cmd_reserve_reloc(cmd, 1);
878 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800879 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600880 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800881}
882
883static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800884 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700885 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800886{
887 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800888 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600889 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800890
891 CMD_ASSERT(cmd, 6, 7.5);
892
893 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800894 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
895 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800896 dw0 |= (cmd_len - 2);
897
Chia-I Wu72292b72014-09-09 10:48:33 +0800898 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
899 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800900
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700901 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800902 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700903
Chia-I Wu72292b72014-09-09 10:48:33 +0800904 cmd_reserve_reloc(cmd, 1);
905 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800906 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700907 } else {
908 dw[1] = 0;
909 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600910 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800911}
912
913static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800914 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700915 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800916{
917 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800918 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600919 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800920
921 CMD_ASSERT(cmd, 6, 7.5);
922
923 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800924 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
925 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800926 dw0 |= (cmd_len - 2);
927
Chia-I Wu72292b72014-09-09 10:48:33 +0800928 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
929 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800930
Chia-I Wu73520ac2015-02-19 11:17:45 -0700931 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800932 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700933
Chia-I Wu72292b72014-09-09 10:48:33 +0800934 cmd_reserve_reloc(cmd, 1);
935 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800936 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700937 } else {
938 dw[1] = 0;
939 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600940 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800941}
942
Chia-I Wuf8231032014-08-25 10:44:45 +0800943static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
944 uint32_t clear_val)
945{
946 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800947 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800948 GEN6_CLEAR_PARAMS_DW0_VALID |
949 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800950 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800951
952 CMD_ASSERT(cmd, 6, 6);
953
Chia-I Wu72292b72014-09-09 10:48:33 +0800954 cmd_batch_pointer(cmd, cmd_len, &dw);
955 dw[0] = dw0;
956 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800957}
958
959static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
960 uint32_t clear_val)
961{
962 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800963 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800964 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800965 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800966
967 CMD_ASSERT(cmd, 7, 7.5);
968
Chia-I Wu72292b72014-09-09 10:48:33 +0800969 cmd_batch_pointer(cmd, cmd_len, &dw);
970 dw[0] = dw0;
971 dw[1] = clear_val;
972 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800973}
974
Chia-I Wu302742d2014-08-22 10:28:29 +0800975static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 uint32_t blend_offset,
977 uint32_t ds_offset,
978 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800979{
980 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800981 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800982
983 CMD_ASSERT(cmd, 6, 6);
984
Chia-I Wu426072d2014-08-26 14:31:55 +0800985 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800986 (cmd_len - 2);
987
Chia-I Wu72292b72014-09-09 10:48:33 +0800988 cmd_batch_pointer(cmd, cmd_len, &dw);
989 dw[0] = dw0;
990 dw[1] = blend_offset | 1;
991 dw[2] = ds_offset | 1;
992 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +0800993}
994
Chia-I Wu1744cca2014-08-22 11:10:17 +0800995static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800996 uint32_t clip_offset,
997 uint32_t sf_offset,
998 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +0800999{
1000 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001001 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001002
1003 CMD_ASSERT(cmd, 6, 6);
1004
Chia-I Wu426072d2014-08-26 14:31:55 +08001005 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001006 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1007 GEN6_VP_PTR_DW0_SF_CHANGED |
1008 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001009 (cmd_len - 2);
1010
Chia-I Wu72292b72014-09-09 10:48:33 +08001011 cmd_batch_pointer(cmd, cmd_len, &dw);
1012 dw[0] = dw0;
1013 dw[1] = clip_offset;
1014 dw[2] = sf_offset;
1015 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001016}
1017
1018static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001019 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001020{
1021 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001022 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001023
1024 CMD_ASSERT(cmd, 6, 6);
1025
Chia-I Wu426072d2014-08-26 14:31:55 +08001026 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001027 (cmd_len - 2);
1028
Chia-I Wu72292b72014-09-09 10:48:33 +08001029 cmd_batch_pointer(cmd, cmd_len, &dw);
1030 dw[0] = dw0;
1031 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001032}
1033
Chia-I Wu42a56202014-08-23 16:47:48 +08001034static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001035 uint32_t vs_offset,
1036 uint32_t gs_offset,
1037 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001038{
1039 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001040 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001041
1042 CMD_ASSERT(cmd, 6, 6);
1043
Chia-I Wu426072d2014-08-26 14:31:55 +08001044 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001045 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1046 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1047 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001048 (cmd_len - 2);
1049
Chia-I Wu72292b72014-09-09 10:48:33 +08001050 cmd_batch_pointer(cmd, cmd_len, &dw);
1051 dw[0] = dw0;
1052 dw[1] = vs_offset;
1053 dw[2] = gs_offset;
1054 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001055}
1056
Chia-I Wu257e75e2014-08-29 14:06:35 +08001057static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001058 uint32_t vs_offset,
1059 uint32_t gs_offset,
1060 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001061{
1062 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001063 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001064
1065 CMD_ASSERT(cmd, 6, 6);
1066
1067 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001068 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1069 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1070 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001071 (cmd_len - 2);
1072
Chia-I Wu72292b72014-09-09 10:48:33 +08001073 cmd_batch_pointer(cmd, cmd_len, &dw);
1074 dw[0] = dw0;
1075 dw[1] = vs_offset;
1076 dw[2] = gs_offset;
1077 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001078}
1079
Chia-I Wu302742d2014-08-22 10:28:29 +08001080static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001081 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001082{
1083 const uint8_t cmd_len = 2;
1084 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1085 GEN6_RENDER_SUBTYPE_3D |
1086 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001087 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001088
Chia-I Wu72292b72014-09-09 10:48:33 +08001089 cmd_batch_pointer(cmd, cmd_len, &dw);
1090 dw[0] = dw0;
1091 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001092}
1093
Chia-I Wua6c4f152014-12-02 04:19:58 +08001094static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001095{
Chia-I Wue6073342014-11-30 09:43:42 +08001096 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001097 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1098 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001099
1100 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001101 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001102
Tony Barbourfa6cac72015-01-16 14:27:35 -07001103 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001104}
1105
Chia-I Wu72292b72014-09-09 10:48:33 +08001106static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Cody Northrop2605cb02015-08-18 15:21:16 -06001107 const struct intel_dynamic_stencil *stencil_state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001108{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001109 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001110 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001111 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001112 uint32_t dw[3];
1113
1114 dw[0] = pipeline->cmd_depth_stencil;
Cody Northrop2605cb02015-08-18 15:21:16 -06001115
1116 /* TODO: enable back facing stencil state */
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001117 /* same read and write masks for both front and back faces */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001118 dw[1] = (stencil_state->front.stencil_compare_mask & 0xff) << 24 |
1119 (stencil_state->front.stencil_write_mask & 0xff) << 16 |
1120 (stencil_state->front.stencil_compare_mask & 0xff) << 8 |
1121 (stencil_state->front.stencil_write_mask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001122 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001123
1124 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001125
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001126 if (stencil_state->front.stencil_write_mask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001127 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001128
Chia-I Wu00b51a82014-09-09 12:07:37 +08001129 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001130 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001131}
1132
Chia-I Wu72292b72014-09-09 10:48:33 +08001133static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001134 uint32_t stencil_ref,
1135 const uint32_t blend_color[4])
1136{
Chia-I Wue6073342014-11-30 09:43:42 +08001137 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001138 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001139 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001140
1141 CMD_ASSERT(cmd, 6, 7.5);
1142
Chia-I Wu00b51a82014-09-09 12:07:37 +08001143 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1144 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001145 dw[0] = stencil_ref;
1146 dw[1] = 0;
1147 dw[2] = blend_color[0];
1148 dw[3] = blend_color[1];
1149 dw[4] = blend_color[2];
1150 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001151
Chia-I Wu72292b72014-09-09 10:48:33 +08001152 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001153}
1154
Chia-I Wu8370b402014-08-29 12:28:37 +08001155static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001156{
Chia-I Wu8370b402014-08-29 12:28:37 +08001157 CMD_ASSERT(cmd, 6, 7.5);
1158
Chia-I Wu707a29e2014-08-27 12:51:47 +08001159 if (!cmd->bind.draw_count)
1160 return;
1161
Chia-I Wu8370b402014-08-29 12:28:37 +08001162 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001163 return;
1164
Chia-I Wu8370b402014-08-29 12:28:37 +08001165 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001166
1167 /*
1168 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1169 *
1170 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1171 * pipe-control with a post-sync op and no write-cache flushes."
1172 *
1173 * The workaround below necessitates this workaround.
1174 */
1175 gen6_PIPE_CONTROL(cmd,
1176 GEN6_PIPE_CONTROL_CS_STALL |
1177 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001178 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001179
Chia-I Wud6d079d2014-08-31 13:14:21 +08001180 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1181 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001182}
1183
Chia-I Wu8370b402014-08-29 12:28:37 +08001184static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001185{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001186 CMD_ASSERT(cmd, 6, 7.5);
1187
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001188 if (!cmd->bind.draw_count)
1189 return;
1190
Chia-I Wud6d079d2014-08-31 13:14:21 +08001191 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1192 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001193}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001194
Chia-I Wu8370b402014-08-29 12:28:37 +08001195static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1196{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001197 CMD_ASSERT(cmd, 7, 7.5);
1198
Chia-I Wu8370b402014-08-29 12:28:37 +08001199 if (!cmd->bind.draw_count)
1200 return;
1201
1202 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001203
1204 gen6_PIPE_CONTROL(cmd,
1205 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001206 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001207}
1208
Chia-I Wu8370b402014-08-29 12:28:37 +08001209static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1210{
1211 CMD_ASSERT(cmd, 7, 7.5);
1212
Chia-I Wu8370b402014-08-29 12:28:37 +08001213 /*
1214 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1215 *
1216 * "One of the following must also be set (when CS stall is set):
1217 *
1218 * * Render Target Cache Flush Enable ([12] of DW1)
1219 * * Depth Cache Flush Enable ([0] of DW1)
1220 * * Stall at Pixel Scoreboard ([1] of DW1)
1221 * * Depth Stall ([13] of DW1)
1222 * * Post-Sync Operation ([13] of DW1)"
1223 */
1224 gen6_PIPE_CONTROL(cmd,
1225 GEN6_PIPE_CONTROL_CS_STALL |
1226 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001227 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001228}
1229
1230static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1231{
1232 CMD_ASSERT(cmd, 7, 7.5);
1233
Chia-I Wu8370b402014-08-29 12:28:37 +08001234 cmd_wa_gen6_pre_depth_stall_write(cmd);
1235
Chia-I Wud6d079d2014-08-31 13:14:21 +08001236 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001237}
1238
1239static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1240{
1241 CMD_ASSERT(cmd, 6, 7.5);
1242
1243 if (!cmd->bind.draw_count)
1244 return;
1245
1246 /*
1247 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1248 *
1249 * "Driver must guarentee that all the caches in the depth pipe are
1250 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1251 * requires driver to send a PIPE_CONTROL with a CS stall along with
1252 * a Depth Flush prior to this command."
1253 *
1254 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1255 *
1256 * "Driver must ierarchi that all the caches in the depth pipe are
1257 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1258 * requires driver to send a PIPE_CONTROL with a CS stall along with
1259 * a Depth Flush prior to this command.
1260 */
1261 gen6_PIPE_CONTROL(cmd,
1262 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1263 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001264 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001265}
1266
1267static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1268{
1269 CMD_ASSERT(cmd, 6, 7.5);
1270
1271 if (!cmd->bind.draw_count)
1272 return;
1273
1274 /*
1275 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1276 *
1277 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1278 * and a post sync operation prior to the group of depth
1279 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1280 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1281 *
1282 * This workaround satifies all the conditions.
1283 */
1284 cmd_wa_gen6_pre_depth_stall_write(cmd);
1285
1286 /*
1287 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1288 *
1289 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1290 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1291 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1292 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1293 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1294 * Depth Flush Bit set, followed by another pipelined depth stall
1295 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1296 * guarantee that the pipeline from WM onwards is already flushed
1297 * (e.g., via a preceding MI_FLUSH)."
1298 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001299 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1300 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1301 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001302}
1303
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001304void cmd_batch_state_base_address(struct intel_cmd *cmd)
1305{
1306 const uint8_t cmd_len = 10;
1307 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1308 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001309 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001310 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001311 uint32_t pos;
1312 uint32_t *dw;
1313
1314 CMD_ASSERT(cmd, 6, 7.5);
1315
1316 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1317
1318 dw[0] = dw0;
1319 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001320 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001321 dw[2] = 1;
1322 dw[3] = 1;
1323 dw[4] = 1;
1324 dw[5] = 1;
1325 /* end offsets */
1326 dw[6] = 1;
1327 dw[7] = 1 + 0xfffff000;
1328 dw[8] = 1 + 0xfffff000;
1329 dw[9] = 1;
1330
1331 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001332 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1333 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1334 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1335 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1336 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1337 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001338}
1339
Chia-I Wu7c853562015-02-27 14:35:08 -07001340void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1341{
1342 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1343 const uint8_t cmd_len = 2;
1344 uint32_t offset = 0;
1345 uint32_t *dw;
1346
1347 if (cmd_gen(cmd) <= INTEL_GEN(6))
1348 return;
1349
1350 CMD_ASSERT(cmd, 7, 7.5);
1351
1352 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1353 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1354 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1355 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1356 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1357 offset += size;
1358
1359 dw += 2;
1360 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1361 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1362 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1363
1364 dw += 2;
1365 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1366 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1367 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1368
1369 dw += 2;
1370 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1371 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1372 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1373
1374 dw += 2;
1375 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1376 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1377 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1378
1379 /*
1380 *
1381 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1382 *
1383 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1384 * in the ring after this instruction
1385 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1386 */
1387 cmd_wa_gen7_post_command_cs_stall(cmd);
1388}
1389
Chia-I Wu525c6602014-08-27 10:22:34 +08001390void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1391{
Mike Stroyan552fda42015-01-30 17:21:08 -07001392 if (pipe_control_dw0 == 0)
1393 return;
1394
Chia-I Wu525c6602014-08-27 10:22:34 +08001395 if (!cmd->bind.draw_count)
1396 return;
1397
1398 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1399
Chia-I Wu8370b402014-08-29 12:28:37 +08001400 /*
1401 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1402 *
1403 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1404 * PIPE_CONTROL with any non-zero post-sync-op is required."
1405 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001406 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001407 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001408
Chia-I Wu092279a2014-08-30 19:05:30 +08001409 /*
1410 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1411 *
1412 * "One of the following must also be set (when CS stall is set):
1413 *
1414 * * Render Target Cache Flush Enable ([12] of DW1)
1415 * * Depth Cache Flush Enable ([0] of DW1)
1416 * * Stall at Pixel Scoreboard ([1] of DW1)
1417 * * Depth Stall ([13] of DW1)
1418 * * Post-Sync Operation ([13] of DW1)"
1419 */
1420 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1421 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1422 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1423 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1424 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1425 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1426
Chia-I Wud6d079d2014-08-31 13:14:21 +08001427 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001428}
1429
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001430void cmd_batch_flush_all(struct intel_cmd *cmd)
1431{
1432 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1433 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1434 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1435 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1436 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1437 GEN6_PIPE_CONTROL_CS_STALL);
1438}
1439
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001440void cmd_batch_depth_count(struct intel_cmd *cmd,
1441 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001442 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001443{
1444 cmd_wa_gen6_pre_depth_stall_write(cmd);
1445
1446 gen6_PIPE_CONTROL(cmd,
1447 GEN6_PIPE_CONTROL_DEPTH_STALL |
1448 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001449 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001450}
1451
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001452void cmd_batch_timestamp(struct intel_cmd *cmd,
1453 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001454 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001455{
1456 /* need any WA or stall? */
1457 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1458}
1459
1460void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001461 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001462 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001463 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001464 uint64_t val)
1465{
1466 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001467 gen6_PIPE_CONTROL(cmd,
1468 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1469 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001470}
1471
Chia-I Wu302742d2014-08-22 10:28:29 +08001472static void gen6_cc_states(struct intel_cmd *cmd)
1473{
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001474 const struct intel_dynamic_blend *blend = &cmd->bind.state.blend;
1475 const struct intel_dynamic_stencil *ss = &cmd->bind.state.stencil;
Chia-I Wu72292b72014-09-09 10:48:33 +08001476 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001477 uint32_t stencil_ref;
1478 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001479
1480 CMD_ASSERT(cmd, 6, 6);
1481
Chia-I Wua6c4f152014-12-02 04:19:58 +08001482 blend_offset = gen6_BLEND_STATE(cmd);
1483
1484 if (blend)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001485 memcpy(blend_color, blend->blend_const, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001486 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001487 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001488
Cody Northrop2605cb02015-08-18 15:21:16 -06001489 if (ss) {
1490 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1491 /* TODO: enable back facing stencil state */
1492 /* same reference for both front and back faces */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001493 stencil_ref = (ss->front.stencil_reference & 0xff) << 24 |
1494 (ss->front.stencil_reference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001495 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001496 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001497 stencil_ref = 0;
1498 }
1499
Chia-I Wu72292b72014-09-09 10:48:33 +08001500 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001501
Chia-I Wu72292b72014-09-09 10:48:33 +08001502 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001503}
1504
Chia-I Wu1744cca2014-08-22 11:10:17 +08001505static void gen6_viewport_states(struct intel_cmd *cmd)
1506{
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001507 const struct intel_dynamic_viewport *viewport = &cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001508 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001509
1510 if (!viewport)
1511 return;
1512
Tony Barbourfa6cac72015-01-16 14:27:35 -07001513 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001514 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001515
1516 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001517 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001518 viewport->cmd);
1519
1520 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001521 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001522 &viewport->cmd[viewport->cmd_clip_pos]);
1523
1524 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001525 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001526 &viewport->cmd[viewport->cmd_cc_pos]);
1527
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001528 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1529 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1530 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001531
1532 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001533 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001534
Chia-I Wub1d450a2014-09-09 13:48:03 +08001535 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001536}
1537
Chia-I Wu302742d2014-08-22 10:28:29 +08001538static void gen7_cc_states(struct intel_cmd *cmd)
1539{
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001540 const struct intel_dynamic_blend *blend = &cmd->bind.state.blend;
1541 const struct intel_dynamic_depth_bounds *ds = &cmd->bind.state.depth_bounds;
1542 const struct intel_dynamic_stencil *ss = &cmd->bind.state.stencil;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001543 uint32_t stencil_ref;
1544 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001545 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001546
1547 CMD_ASSERT(cmd, 7, 7.5);
1548
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001549 if (!blend && !ds)
1550 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001551
Chia-I Wua6c4f152014-12-02 04:19:58 +08001552 offset = gen6_BLEND_STATE(cmd);
1553 gen7_3dstate_pointer(cmd,
1554 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001555
Chia-I Wua6c4f152014-12-02 04:19:58 +08001556 if (blend)
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001557 memcpy(blend_color, blend->blend_const, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001558 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001559 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001560
Cody Northrop2605cb02015-08-18 15:21:16 -06001561 if (ss) {
1562 offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1563 /* TODO: enable back facing stencil state */
1564 /* same reference for both front and back faces */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001565 stencil_ref = (ss->front.stencil_reference & 0xff) << 24 |
1566 (ss->front.stencil_reference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001567 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001568 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1569 offset);
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001570 } else {
1571 stencil_ref = 0;
1572 }
1573
Chia-I Wu72292b72014-09-09 10:48:33 +08001574 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001575 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001576 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001577}
1578
Chia-I Wu1744cca2014-08-22 11:10:17 +08001579static void gen7_viewport_states(struct intel_cmd *cmd)
1580{
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -06001581 const struct intel_dynamic_viewport *viewport = &cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001582 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001583
1584 if (!viewport)
1585 return;
1586
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001587 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001588
Chia-I Wub1d450a2014-09-09 13:48:03 +08001589 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001590 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001591 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001592 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001593 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1594 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001595
1596 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001597 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001598 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001599 gen7_3dstate_pointer(cmd,
1600 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001601 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001602
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001603 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1604 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1605 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1606 gen7_3dstate_pointer(cmd,
1607 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1608 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001609}
1610
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001611static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001612 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001613{
1614 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001615 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001616
Chia-I Wu72292b72014-09-09 10:48:33 +08001617 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001618
1619 dw[0] = GEN6_RENDER_TYPE_RENDER |
1620 GEN6_RENDER_SUBTYPE_3D |
1621 subop | (cmd_len - 2);
1622 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001623 dw[2] = 0;
1624 dw[3] = 0;
1625 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001626}
1627
1628static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001629 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001630{
1631 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001632 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001633
Chia-I Wu72292b72014-09-09 10:48:33 +08001634 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001635
1636 dw[0] = GEN6_RENDER_TYPE_RENDER |
1637 GEN6_RENDER_SUBTYPE_3D |
1638 subop | (cmd_len - 2);
1639 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001640 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001641 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001642 dw[4] = 0;
1643 dw[5] = 0;
1644 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001645}
1646
Chia-I Wu625105f2014-10-13 15:35:29 +08001647static uint32_t emit_samplers(struct intel_cmd *cmd,
1648 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001649{
Chia-I Wu862c5572015-03-28 15:23:55 +08001650 const struct intel_desc_region *region = cmd->dev->desc_region;
1651 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001652 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1653 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001654 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001655 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001656 uint32_t surface_count;
1657 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001658
1659 CMD_ASSERT(cmd, 6, 7.5);
1660
Chia-I Wu625105f2014-10-13 15:35:29 +08001661 if (!rmap || !rmap->sampler_count)
1662 return 0;
1663
Cody Northrop40316a32014-12-09 19:08:33 -07001664 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001665
Chia-I Wudcb509d2014-12-10 08:53:10 +08001666 /*
1667 * note that we cannot call cmd_state_pointer() here as the following
1668 * cmd_state_pointer() would invalidate the pointer
1669 */
1670 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001671 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001672 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001673
1674 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001675 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001676 4 * rmap->sampler_count, &sampler_dw);
1677
Chia-I Wudcb509d2014-12-10 08:53:10 +08001678 cmd_state_update(cmd, border_offset,
1679 border_stride * rmap->sampler_count, &border_dw);
1680
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001681 for (i = 0; i < rmap->sampler_count; i++) {
1682 const struct intel_pipeline_rmap_slot *slot =
1683 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001684 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001685 const struct intel_sampler *sampler;
1686
Chia-I Wuf8385062015-01-04 16:27:24 +08001687 switch (slot->type) {
1688 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001689 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1690 &data->set_offsets[slot->index]);
1691 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001692 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001693 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001694 sampler = NULL;
1695 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001696 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001697 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001698 sampler = NULL;
1699 break;
1700 }
1701
1702 if (sampler) {
1703 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1704
1705 sampler_dw[0] = sampler->cmd[0];
1706 sampler_dw[1] = sampler->cmd[1];
1707 sampler_dw[2] = border_offset;
1708 sampler_dw[3] = sampler->cmd[2];
1709 } else {
1710 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1711 sampler_dw[1] = 0;
1712 sampler_dw[2] = 0;
1713 sampler_dw[3] = 0;
1714 }
1715
1716 border_offset += border_stride * 4;
1717 border_dw += border_stride;
1718 sampler_dw += 4;
1719 }
1720
Chia-I Wu625105f2014-10-13 15:35:29 +08001721 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001722}
1723
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001724static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001725 const struct intel_pipeline_rmap *rmap,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001726 const VkShaderStageFlagBits stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001727{
Chia-I Wu862c5572015-03-28 15:23:55 +08001728 const struct intel_desc_region *region = cmd->dev->desc_region;
1729 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001730 const uint32_t sba_offset =
1731 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001732 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001733 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001734
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001735 CMD_ASSERT(cmd, 6, 7.5);
1736
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001737 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001738 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001739 if (!surface_count)
1740 return 0;
1741
Chia-I Wu42a56202014-08-23 16:47:48 +08001742 assert(surface_count <= ARRAY_SIZE(binding_table));
1743
1744 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001745 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001746 struct intel_null_view null_view;
1747 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001748
Chia-I Wuf8385062015-01-04 16:27:24 +08001749 switch (slot->type) {
1750 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001751 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001752 const struct intel_render_pass_subpass *subpass =
1753 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001754 const struct intel_fb *fb = cmd->bind.fb;
1755 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001756 (slot->index < subpass->color_count &&
1757 subpass->color_indices[slot->index] < fb->view_count) ?
1758 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001759
Chia-I Wu787a05b2014-12-05 11:02:20 +08001760 if (view) {
1761 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1762 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001763 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001764
Chia-I Wu787a05b2014-12-05 11:02:20 +08001765 cmd_reserve_reloc(cmd, 1);
1766 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001767 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001768 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001769 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001770 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001771 }
1772 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001773 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001774 {
Tony Barbour22a30862015-04-22 09:02:32 -06001775 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001776 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001777 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001778 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001779 const struct intel_mem *mem;
1780 bool read_only;
1781 const uint32_t *cmd_data;
1782 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001783
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001784 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001785 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001786
Chia-I Wu862c5572015-03-28 15:23:55 +08001787 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1788 &data->set_offsets[slot->index]);
1789
1790 intel_desc_region_read_surface(region, &desc_offset, stage,
1791 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001792 if (mem) {
1793 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001794 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001795 const uint32_t reloc_flags =
1796 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001797
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001798 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001799 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001800 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001801
1802 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001803 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1804 cmd_data[1] + dynamic_offset, reloc_flags);
1805 } else {
1806 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001807 }
1808 }
1809 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001810 case INTEL_PIPELINE_RMAP_UNUSED:
1811 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001812 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001813 default:
1814 assert(!"unexpected rmap type");
1815 need_null_view = true;
1816 break;
1817 }
1818
1819 if (need_null_view) {
1820 intel_null_view_init(&null_view, cmd->dev);
1821 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1822 GEN6_ALIGNMENT_SURFACE_STATE,
1823 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001824 }
1825
Chia-I Wuf98dd882015-02-10 04:17:47 +08001826 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001827 }
1828
Chia-I Wuf98dd882015-02-10 04:17:47 +08001829 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001830 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001831 surface_count, binding_table) - sba_offset;
1832
1833 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1834 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1835
1836 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001837}
1838
Chia-I Wu1d125092014-10-08 08:49:38 +08001839static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1840{
1841 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001842 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1843 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001844 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001845
1846 CMD_ASSERT(cmd, 6, 7.5);
1847
1848 if (!pipeline->vb_count)
1849 return;
1850
1851 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1852
1853 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1854 dw++;
1855 pos++;
1856
1857 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001858 assert(pipeline->vb[i].strideInBytes <= 2048);
1859
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001860 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001861 pipeline->vb[i].strideInBytes;
1862
Chia-I Wub3686982015-02-27 09:51:16 -07001863 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001864 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1865 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001866 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001867
1868 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001869 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001870 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001871 dw[3] = 0;
1872 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001873 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001874 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001875 dw[3] = 1;
1876 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001877 default:
1878 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001879 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001880 dw[3] = 0;
1881 break;
1882 }
1883
Chia-I Wu714df452015-01-01 07:55:04 +08001884 if (cmd->bind.vertex.buf[i]) {
1885 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001886 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001887
1888 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001889 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1890 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001891 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001892 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001893 dw[1] = 0;
1894 dw[2] = 0;
1895 }
1896
1897 dw += 4;
1898 pos += 4;
1899 }
1900}
1901
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001902static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1903{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001904 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1905 const struct intel_pipeline_shader *vs = &pipeline->vs;
1906 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001907 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001908 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001909 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001910 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001911
1912 CMD_ASSERT(cmd, 6, 7.5);
1913
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001914 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001915 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1916 *
1917 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1918 * 128-bit vertex elements to be passed into the payload for each
1919 * vertex."
1920 *
1921 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1922 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001923 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001924 vue_read_len = (vs->in_count + 1) / 2;
1925 if (!vue_read_len)
1926 vue_read_len = 1;
1927
1928 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1929 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1930
1931 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1932 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1933 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001934
1935 dw5 = GEN6_VS_DW5_STATISTICS |
1936 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001937
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001938 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001939 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001940 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001941 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001942
Chia-I Wube0a3d92014-09-02 13:20:59 +08001943 if (pipeline->disable_vs_cache)
1944 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1945
Chia-I Wu784d3042014-12-19 14:30:04 +08001946 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001947 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001948 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001949 dw[2] = dw2;
1950 dw[3] = 0; /* scratch */
1951 dw[4] = dw4;
1952 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001953
1954 if (vs->per_thread_scratch_size)
1955 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001956}
1957
Chia-I Wu625105f2014-10-13 15:35:29 +08001958static void emit_shader_resources(struct intel_cmd *cmd)
1959{
1960 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001961 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001962
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001963 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001964 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001965 VK_SHADER_STAGE_VERTEX_BIT);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001966 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001967 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001968 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001969 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001970 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001971 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001972 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001973 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001974 VK_SHADER_STAGE_GEOMETRY_BIT);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001975 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001976 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -06001977 VK_SHADER_STAGE_FRAGMENT_BIT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001978
1979 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1980 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1981 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1982 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1983 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1984
1985 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1986 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001987 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1988 binding_tables[0]);
1989 gen7_3dstate_pointer(cmd,
1990 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
1991 binding_tables[1]);
1992 gen7_3dstate_pointer(cmd,
1993 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
1994 binding_tables[2]);
1995 gen7_3dstate_pointer(cmd,
1996 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
1997 binding_tables[3]);
1998 gen7_3dstate_pointer(cmd,
1999 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2000 binding_tables[4]);
2001
2002 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002003 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2004 samplers[0]);
2005 gen7_3dstate_pointer(cmd,
2006 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2007 samplers[1]);
2008 gen7_3dstate_pointer(cmd,
2009 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2010 samplers[2]);
2011 gen7_3dstate_pointer(cmd,
2012 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2013 samplers[3]);
2014 gen7_3dstate_pointer(cmd,
2015 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2016 samplers[4]);
2017 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002018 assert(!binding_tables[1] && !binding_tables[2]);
2019 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2020 binding_tables[0], binding_tables[3], binding_tables[4]);
2021
Chia-I Wu625105f2014-10-13 15:35:29 +08002022 assert(!samplers[1] && !samplers[2]);
2023 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2024 samplers[0], samplers[3], samplers[4]);
2025 }
2026}
2027
Chia-I Wu8ada4242015-03-02 11:19:33 -07002028static void emit_msaa(struct intel_cmd *cmd)
2029{
Chia-I Wuc278df82015-07-07 11:50:03 +08002030 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002031
Chia-I Wubbc7d912015-02-27 14:59:50 -07002032 if (!cmd->bind.render_pass_changed)
2033 return;
2034
Chia-I Wu8ada4242015-03-02 11:19:33 -07002035 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002036 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002037}
2038
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002039static void emit_rt(struct intel_cmd *cmd)
2040{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002041 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002042
2043 if (!cmd->bind.render_pass_changed)
2044 return;
2045
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002046 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002047 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2048 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002049}
2050
2051static void emit_ds(struct intel_cmd *cmd)
2052{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002053 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002054 const struct intel_render_pass_subpass *subpass =
2055 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002056 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002057 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002058 (subpass->ds_index < rp->attachment_count) ?
2059 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002060
Chia-I Wubbc7d912015-02-27 14:59:50 -07002061 if (!cmd->bind.render_pass_changed)
2062 return;
2063
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002064 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002065 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002066 static const struct intel_att_view null_view;
2067 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002068 }
2069
2070 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002071 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2072 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2073 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002074
2075 if (cmd_gen(cmd) >= INTEL_GEN(7))
2076 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2077 else
2078 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2079}
2080
Chia-I Wua57761b2014-10-14 14:27:44 +08002081static uint32_t emit_shader(struct intel_cmd *cmd,
2082 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002083{
Chia-I Wua57761b2014-10-14 14:27:44 +08002084 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2085 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002086 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002087
Chia-I Wua57761b2014-10-14 14:27:44 +08002088 /* see if the shader is already in the cache */
2089 for (i = 0; i < cache->used; i++) {
2090 if (cache->entries[i].shader == (const void *) shader)
2091 return cache->entries[i].kernel_offset;
2092 }
2093
2094 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2095
2096 /* grow the cache if full */
2097 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002098 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002099 void *entries;
2100
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002101 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002102 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002103 if (entries) {
2104 if (cache->entries) {
2105 memcpy(entries, cache->entries,
2106 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002107 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002108 }
2109
2110 cache->entries = entries;
2111 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002112 }
2113 }
2114
Chia-I Wua57761b2014-10-14 14:27:44 +08002115 /* add the shader to the cache */
2116 if (cache->used < cache->count) {
2117 cache->entries[cache->used].shader = (const void *) shader;
2118 cache->entries[cache->used].kernel_offset = offset;
2119 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002120 }
2121
Chia-I Wua57761b2014-10-14 14:27:44 +08002122 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002123}
2124
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002125static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002126{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002127 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002128
Chia-I Wu8370b402014-08-29 12:28:37 +08002129 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2130 cmd_wa_gen6_pre_depth_stall_write(cmd);
2131 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2132 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2133 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2134 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002135
2136 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002137 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002138 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002139
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002140 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002141 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002142 }
2143 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002144 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002145 }
2146 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002147 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2148 }
2149 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2150 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2151 }
2152 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2153 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002154 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002155
Chia-I Wu8370b402014-08-29 12:28:37 +08002156 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2157 cmd_wa_gen7_post_command_cs_stall(cmd);
2158 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2159 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002160}
2161
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002162static void
2163viewport_get_guardband(const struct intel_gpu *gpu,
2164 int center_x, int center_y,
2165 int *min_gbx, int *max_gbx,
2166 int *min_gby, int *max_gby)
2167{
2168 /*
2169 * From the Sandy Bridge PRM, volume 2 part 1, page 234:
2170 *
2171 * "Per-Device Guardband Extents
2172 *
2173 * - Supported X,Y ScreenSpace "Guardband" Extent: [-16K,16K-1]
2174 * - Maximum Post-Clamp Delta (X or Y): 16K"
2175 *
2176 * "In addition, in order to be correctly rendered, objects must have a
2177 * screenspace bounding box not exceeding 8K in the X or Y direction.
2178 * This additional restriction must also be comprehended by software,
2179 * i.e., enforced by use of clipping."
2180 *
2181 * From the Ivy Bridge PRM, volume 2 part 1, page 248:
2182 *
2183 * "Per-Device Guardband Extents
2184 *
2185 * - Supported X,Y ScreenSpace "Guardband" Extent: [-32K,32K-1]
2186 * - Maximum Post-Clamp Delta (X or Y): N/A"
2187 *
2188 * "In addition, in order to be correctly rendered, objects must have a
2189 * screenspace bounding box not exceeding 8K in the X or Y direction.
2190 * This additional restriction must also be comprehended by software,
2191 * i.e., enforced by use of clipping."
2192 *
2193 * Combined, the bounding box of any object can not exceed 8K in both
2194 * width and height.
2195 *
2196 * Below we set the guardband as a squre of length 8K, centered at where
2197 * the viewport is. This makes sure all objects passing the GB test are
2198 * valid to the renderer, and those failing the XY clipping have a
2199 * better chance of passing the GB test.
2200 */
2201 const int max_extent = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 32768 : 16384;
2202 const int half_len = 8192 / 2;
2203
2204 /* make sure the guardband is within the valid range */
2205 if (center_x - half_len < -max_extent)
2206 center_x = -max_extent + half_len;
2207 else if (center_x + half_len > max_extent - 1)
2208 center_x = max_extent - half_len;
2209
2210 if (center_y - half_len < -max_extent)
2211 center_y = -max_extent + half_len;
2212 else if (center_y + half_len > max_extent - 1)
2213 center_y = max_extent - half_len;
2214
2215 *min_gbx = (float) (center_x - half_len);
2216 *max_gbx = (float) (center_x + half_len);
2217 *min_gby = (float) (center_y - half_len);
2218 *max_gby = (float) (center_y + half_len);
2219}
2220
2221static void
2222viewport_state_cmd(struct intel_dynamic_viewport *state,
2223 const struct intel_gpu *gpu,
2224 uint32_t count)
2225{
2226 INTEL_GPU_ASSERT(gpu, 6, 7.5);
2227
2228 state->viewport_count = count;
2229
2230 assert(count <= INTEL_MAX_VIEWPORTS);
2231
2232 if (intel_gpu_gen(gpu) >= INTEL_GEN(7)) {
2233 state->cmd_len = 16 * count;
2234
2235 state->cmd_clip_pos = 8;
2236 } else {
2237 state->cmd_len = 8 * count;
2238
2239 state->cmd_clip_pos = state->cmd_len;
2240 state->cmd_len += 4 * count;
2241 }
2242
2243 state->cmd_cc_pos = state->cmd_len;
2244 state->cmd_len += 2 * count;
2245
2246 state->cmd_scissor_rect_pos = state->cmd_len;
2247 state->cmd_len += 2 * count;
2248
2249 assert(sizeof(uint32_t) * state->cmd_len <= sizeof(state->cmd));
2250}
2251
2252static void
2253set_viewport_state(
2254 struct intel_cmd* cmd)
2255{
2256 const struct intel_gpu *gpu = cmd->dev->gpu;
2257 struct intel_dynamic_viewport *state = &cmd->bind.state.viewport;
2258 const uint32_t sf_stride = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16 : 8;
2259 const uint32_t clip_stride = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16 : 4;
2260 uint32_t *sf_viewport, *clip_viewport, *cc_viewport, *scissor_rect;
2261 uint32_t i;
2262
2263 INTEL_GPU_ASSERT(gpu, 6, 7.5);
2264
2265 viewport_state_cmd(state, gpu, cmd->bind.state.viewport.viewport_count);
2266
2267 sf_viewport = state->cmd;
2268 clip_viewport = state->cmd + state->cmd_clip_pos;
2269 cc_viewport = state->cmd + state->cmd_cc_pos;
2270 scissor_rect = state->cmd + state->cmd_scissor_rect_pos;
2271
2272 for (i = 0; i < cmd->bind.state.viewport.viewport_count; i++) {
2273 const VkViewport *viewport = &cmd->bind.state.viewport.viewports[i];
2274 uint32_t *dw = NULL;
2275 float translate[3], scale[3];
2276 int min_gbx, max_gbx, min_gby, max_gby;
2277
2278 scale[0] = viewport->width / 2.0f;
2279 scale[1] = viewport->height / 2.0f;
2280 scale[2] = viewport->maxDepth - viewport->minDepth;
2281 translate[0] = viewport->originX + scale[0];
2282 translate[1] = viewport->originY + scale[1];
2283 translate[2] = viewport->minDepth;
2284
2285 viewport_get_guardband(gpu, (int) translate[0], (int) translate[1],
2286 &min_gbx, &max_gbx, &min_gby, &max_gby);
2287
2288 /* SF_VIEWPORT */
2289 dw = sf_viewport;
2290 dw[0] = u_fui(scale[0]);
2291 dw[1] = u_fui(scale[1]);
2292 dw[2] = u_fui(scale[2]);
2293 dw[3] = u_fui(translate[0]);
2294 dw[4] = u_fui(translate[1]);
2295 dw[5] = u_fui(translate[2]);
2296 dw[6] = 0;
2297 dw[7] = 0;
2298 sf_viewport += sf_stride;
2299
2300 /* CLIP_VIEWPORT */
2301 dw = clip_viewport;
2302 dw[0] = u_fui(((float) min_gbx - translate[0]) / fabsf(scale[0]));
2303 dw[1] = u_fui(((float) max_gbx - translate[0]) / fabsf(scale[0]));
2304 dw[2] = u_fui(((float) min_gby - translate[1]) / fabsf(scale[1]));
2305 dw[3] = u_fui(((float) max_gby - translate[1]) / fabsf(scale[1]));
2306 clip_viewport += clip_stride;
2307
2308 /* CC_VIEWPORT */
2309 dw = cc_viewport;
2310 dw[0] = u_fui(viewport->minDepth);
2311 dw[1] = u_fui(viewport->maxDepth);
2312 cc_viewport += 2;
2313 }
2314
2315 for (i = 0; i < cmd->bind.state.viewport.viewport_count; i++) {
2316 const VkRect2D *scissor = &cmd->bind.state.viewport.scissors[i];
2317 /* SCISSOR_RECT */
2318 int16_t max_x, max_y;
2319 uint32_t *dw = NULL;
2320
2321 max_x = (scissor->offset.x + scissor->extent.width - 1) & 0xffff;
2322 max_y = (scissor->offset.y + scissor->extent.height - 1) & 0xffff;
2323
2324 dw = scissor_rect;
2325 if (scissor->extent.width && scissor->extent.height) {
2326 dw[0] = (scissor->offset.y & 0xffff) << 16 |
2327 (scissor->offset.x & 0xffff);
2328 dw[1] = max_y << 16 | max_x;
2329 } else {
2330 dw[0] = 1 << 16 | 1;
2331 dw[1] = 0;
2332 }
2333 scissor_rect += 2;
2334 }
2335}
2336
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002337static void emit_bounded_states(struct intel_cmd *cmd)
2338{
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -06002339 set_viewport_state(cmd);
2340
Chia-I Wu8ada4242015-03-02 11:19:33 -07002341 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002342
2343 emit_graphics_pipeline(cmd);
2344
2345 emit_rt(cmd);
2346 emit_ds(cmd);
2347
2348 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2349 gen7_cc_states(cmd);
2350 gen7_viewport_states(cmd);
2351
2352 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2353 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002354 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2355 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002356 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2357 &cmd->bind.pipeline.graphics->fs);
2358
Cody Northrop293d4502015-05-05 09:38:03 -06002359 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002360 gen6_3DSTATE_CLIP(cmd);
2361 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002362 gen7_3DSTATE_WM(cmd);
2363 gen7_3DSTATE_PS(cmd);
2364 } else {
2365 gen6_cc_states(cmd);
2366 gen6_viewport_states(cmd);
2367
2368 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2369 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002370 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2371 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002372 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2373 &cmd->bind.pipeline.graphics->fs);
2374
Cody Northrop293d4502015-05-05 09:38:03 -06002375 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002376 gen6_3DSTATE_CLIP(cmd);
2377 gen6_3DSTATE_SF(cmd);
2378 gen6_3DSTATE_WM(cmd);
2379 }
2380
2381 emit_shader_resources(cmd);
2382
2383 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002384
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002385 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2386 gen6_3DSTATE_VS(cmd);
2387}
2388
Tony Barbourfa6cac72015-01-16 14:27:35 -07002389static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002390 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002391{
2392 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2393 const uint8_t cmd_len = 3;
2394 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002395
2396 CMD_ASSERT(cmd, 6, 7.5);
2397
Courtney Goeltzenleuchteraeffeae2015-09-10 17:58:54 -06002398 /* TODO: aspect is now a mask, can you do both? */
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06002399 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH_BIT) {
Chia-I Wud850a392015-02-19 11:08:25 -07002400 dw[0] = 0;
2401 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002402
2403 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2404 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2405 GEN6_COMPAREFUNCTION_NEVER << 27 |
2406 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2407 } else {
2408 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2409 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2410 }
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06002411 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL_BIT) {
Chia-I Wud850a392015-02-19 11:08:25 -07002412 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002413 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2414 (GEN6_STENCILOP_KEEP) << 25 |
2415 (GEN6_STENCILOP_KEEP) << 22 |
2416 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002417 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2418 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002419 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2420 (GEN6_STENCILOP_KEEP) << 9 |
2421 (GEN6_STENCILOP_KEEP) << 6 |
2422 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002423
Chia-I Wud850a392015-02-19 11:08:25 -07002424 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2425 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2426 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2427 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2428 dw[2] = 0;
2429 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002430
2431 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2432 cmd_align, cmd_len, dw);
2433}
2434
Chia-I Wu6032b892014-10-17 14:47:18 +08002435static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2436{
2437 const struct intel_cmd_meta *meta = cmd->bind.meta;
2438 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2439
2440 CMD_ASSERT(cmd, 6, 7.5);
2441
2442 blend_offset = 0;
2443 ds_offset = 0;
2444 cc_offset = 0;
2445 cc_vp_offset = 0;
2446
Chia-I Wu29e6f502014-11-24 14:27:29 +08002447 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002448 /* BLEND_STATE */
2449 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002450 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002451 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002452 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002453 }
2454
Chia-I Wu29e6f502014-11-24 14:27:29 +08002455 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchterba11ebe2015-10-21 17:00:51 -06002456 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH_BIT ||
2457 meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL_BIT) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002458 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002459 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2460 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002461
Chia-I Wu29e6f502014-11-24 14:27:29 +08002462 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002463 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002464
Chia-I Wu29e6f502014-11-24 14:27:29 +08002465 /* COLOR_CALC_STATE */
2466 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002467 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002468
Chia-I Wu29e6f502014-11-24 14:27:29 +08002469 /* CC_VIEWPORT */
2470 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002471 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002472 dw[0] = u_fui(0.0f);
2473 dw[1] = u_fui(1.0f);
2474 } else {
2475 /* DEPTH_STENCIL_STATE */
2476 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002477 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002478 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2479 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2480 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002481 }
2482
2483 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2484 gen7_3dstate_pointer(cmd,
2485 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2486 blend_offset);
2487 gen7_3dstate_pointer(cmd,
2488 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2489 ds_offset);
2490 gen7_3dstate_pointer(cmd,
2491 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2492
2493 gen7_3dstate_pointer(cmd,
2494 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2495 cc_vp_offset);
2496 } else {
2497 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002498 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002499
2500 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2501 cmd_batch_pointer(cmd, 4, &dw);
2502 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002503 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002504 dw[1] = 0;
2505 dw[2] = 0;
2506 dw[3] = cc_vp_offset;
2507 }
2508}
2509
2510static void gen6_meta_surface_states(struct intel_cmd *cmd)
2511{
2512 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002513 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002514 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002515 const uint32_t sba_offset =
2516 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002517
2518 CMD_ASSERT(cmd, 6, 7.5);
2519
Chia-I Wu29e6f502014-11-24 14:27:29 +08002520 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2521 return;
2522
Chia-I Wu005c47c2014-10-22 13:49:13 +08002523 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002524 if (meta->src.valid) {
2525 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002526 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002527 meta->src.surface_len, meta->src.surface);
2528
2529 cmd_reserve_reloc(cmd, 1);
2530 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2531 cmd_surface_reloc_writer(cmd, offset, 1,
2532 meta->src.reloc_target, meta->src.reloc_offset);
2533 } else {
2534 cmd_surface_reloc(cmd, offset, 1,
2535 (struct intel_bo *) meta->src.reloc_target,
2536 meta->src.reloc_offset, meta->src.reloc_flags);
2537 }
2538
Mike Stroyan9bfad482015-02-10 15:09:23 -07002539 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002540 }
2541 if (meta->dst.valid) {
2542 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002543 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002544 meta->dst.surface_len, meta->dst.surface);
2545
2546 cmd_reserve_reloc(cmd, 1);
2547 cmd_surface_reloc(cmd, offset, 1,
2548 (struct intel_bo *) meta->dst.reloc_target,
2549 meta->dst.reloc_offset, meta->dst.reloc_flags);
2550
Mike Stroyan9bfad482015-02-10 15:09:23 -07002551 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002552 }
2553
2554 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002555 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002556 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002557 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002558
2559 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2561 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2562 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002563 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002564 } else {
2565 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002566 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002567 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002568 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002569 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002570 }
2571}
2572
2573static void gen6_meta_urb(struct intel_cmd *cmd)
2574{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002575 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002576 uint32_t *dw;
2577
2578 CMD_ASSERT(cmd, 6, 6);
2579
2580 /* 3DSTATE_URB */
2581 cmd_batch_pointer(cmd, 3, &dw);
2582 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002583 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002584 dw[2] = 0;
2585}
2586
2587static void gen7_meta_urb(struct intel_cmd *cmd)
2588{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002589 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2590 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002591 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002592 uint32_t *dw;
2593
2594 CMD_ASSERT(cmd, 7, 7.5);
2595
Chia-I Wu6032b892014-10-17 14:47:18 +08002596 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2597
Chia-I Wu24aa1022014-11-25 11:53:19 +08002598 switch (cmd_gen(cmd)) {
2599 case INTEL_GEN(7.5):
2600 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2601 break;
2602 case INTEL_GEN(7):
2603 default:
2604 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2605 break;
2606 }
2607
Chia-I Wu6032b892014-10-17 14:47:18 +08002608 /* 3DSTATE_URB_x */
2609 cmd_batch_pointer(cmd, 8, &dw);
2610
2611 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002612 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002613 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002614 dw += 2;
2615
2616 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002617 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002618 dw += 2;
2619
2620 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002621 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002622 dw += 2;
2623
2624 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002625 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002626 dw += 2;
2627}
2628
2629static void gen6_meta_vf(struct intel_cmd *cmd)
2630{
2631 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002632 uint32_t vb_start, vb_end, vb_stride;
2633 int ve_format, ve_z_source;
2634 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002635 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002636
2637 CMD_ASSERT(cmd, 6, 7.5);
2638
Chia-I Wu29e6f502014-11-24 14:27:29 +08002639 switch (meta->mode) {
2640 case INTEL_CMD_META_VS_POINTS:
2641 cmd_batch_pointer(cmd, 3, &dw);
2642 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002643 dw[1] = GEN6_VE_DW0_VALID;
2644 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2645 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2646 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2647 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002648 return;
2649 break;
2650 case INTEL_CMD_META_FS_RECT:
2651 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002652 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002653
Chia-I Wu29e6f502014-11-24 14:27:29 +08002654 vertices[0][0] = meta->dst.x + meta->width;
2655 vertices[0][1] = meta->dst.y + meta->height;
2656 vertices[1][0] = meta->dst.x;
2657 vertices[1][1] = meta->dst.y + meta->height;
2658 vertices[2][0] = meta->dst.x;
2659 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002660
Chia-I Wu29e6f502014-11-24 14:27:29 +08002661 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2662 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002663
Chia-I Wu29e6f502014-11-24 14:27:29 +08002664 vb_end = vb_start + sizeof(vertices) - 1;
2665 vb_stride = sizeof(vertices[0]);
2666 ve_z_source = GEN6_VFCOMP_STORE_0;
2667 ve_format = GEN6_FORMAT_R32G32_USCALED;
2668 }
2669 break;
2670 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2671 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002672 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002673
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002674 vertices[0][0] = (float) (meta->dst.x + meta->width);
2675 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002676 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002677 vertices[1][0] = (float) meta->dst.x;
2678 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002679 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002680 vertices[2][0] = (float) meta->dst.x;
2681 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002682 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002683
Chia-I Wu29e6f502014-11-24 14:27:29 +08002684 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2685 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002686
Chia-I Wu29e6f502014-11-24 14:27:29 +08002687 vb_end = vb_start + sizeof(vertices) - 1;
2688 vb_stride = sizeof(vertices[0]);
2689 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2690 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2691 }
2692 break;
2693 default:
2694 assert(!"unknown meta mode");
2695 return;
2696 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002697 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002698
2699 /* 3DSTATE_VERTEX_BUFFERS */
2700 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002701
Chia-I Wu6032b892014-10-17 14:47:18 +08002702 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002703 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002704 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002705 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002706
2707 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002708 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2709 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002710
2711 dw[4] = 0;
2712
2713 /* 3DSTATE_VERTEX_ELEMENTS */
2714 cmd_batch_pointer(cmd, 5, &dw);
2715 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002716 dw[1] = GEN6_VE_DW0_VALID;
2717 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2718 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2719 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2720 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2721 dw[3] = GEN6_VE_DW0_VALID |
2722 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2723 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2724 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2725 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2726 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002727}
2728
Chia-I Wu29e6f502014-11-24 14:27:29 +08002729static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002730{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002731 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002732 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002733 uint32_t consts[8];
2734 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002735
2736 CMD_ASSERT(cmd, 6, 7.5);
2737
2738 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002739 case INTEL_DEV_META_VS_FILL_MEM:
2740 consts[0] = meta->dst.x;
2741 consts[1] = meta->clear_val[0];
2742 const_count = 2;
2743 break;
2744 case INTEL_DEV_META_VS_COPY_MEM:
2745 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2746 consts[0] = meta->dst.x;
2747 consts[1] = meta->src.x;
2748 const_count = 2;
2749 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002750 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2751 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2752 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2753 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2754 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2755 consts[0] = meta->src.x;
2756 consts[1] = meta->src.y;
2757 consts[2] = meta->width;
2758 consts[3] = meta->dst.x;
2759 const_count = 4;
2760 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002761 default:
2762 assert(!"unknown meta shader id");
2763 const_count = 0;
2764 break;
2765 }
2766
2767 /* this can be skipped but it makes state dumping prettier */
2768 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2769
2770 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2771}
2772
2773static void gen6_meta_vs(struct intel_cmd *cmd)
2774{
2775 const struct intel_cmd_meta *meta = cmd->bind.meta;
2776 const struct intel_pipeline_shader *sh =
2777 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2778 uint32_t offset, *dw;
2779
2780 CMD_ASSERT(cmd, 6, 7.5);
2781
2782 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002783 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002784
2785 /* 3DSTATE_CONSTANT_VS */
2786 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2787 cmd_batch_pointer(cmd, cmd_len, &dw);
2788 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2789 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2790
2791 /* 3DSTATE_VS */
2792 cmd_batch_pointer(cmd, 6, &dw);
2793 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2794 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2795
2796 return;
2797 }
2798
2799 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2800
2801 /* 3DSTATE_CONSTANT_VS */
2802 offset = gen6_meta_vs_constants(cmd);
2803 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2804 cmd_batch_pointer(cmd, 7, &dw);
2805 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002806 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002807 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002808 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002809 dw[4] = 0;
2810 dw[5] = 0;
2811 dw[6] = 0;
2812 } else {
2813 cmd_batch_pointer(cmd, 5, &dw);
2814 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002815 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002816 dw[1] = offset;
2817 dw[2] = 0;
2818 dw[3] = 0;
2819 dw[4] = 0;
2820 }
2821
2822 /* 3DSTATE_VS */
2823 offset = emit_shader(cmd, sh);
2824 cmd_batch_pointer(cmd, 6, &dw);
2825 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2826 dw[1] = offset;
2827 dw[2] = GEN6_THREADDISP_SPF |
2828 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2829 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002830 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002831 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2832 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2833
2834 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2835 GEN6_VS_DW5_VS_ENABLE;
2836 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002837 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002838 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002839 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002840
2841 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002842}
2843
2844static void gen6_meta_disabled(struct intel_cmd *cmd)
2845{
Chia-I Wu6032b892014-10-17 14:47:18 +08002846 uint32_t *dw;
2847
2848 CMD_ASSERT(cmd, 6, 6);
2849
Chia-I Wu6032b892014-10-17 14:47:18 +08002850 /* 3DSTATE_CONSTANT_GS */
2851 cmd_batch_pointer(cmd, 5, &dw);
2852 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2853 dw[1] = 0;
2854 dw[2] = 0;
2855 dw[3] = 0;
2856 dw[4] = 0;
2857
2858 /* 3DSTATE_GS */
2859 cmd_batch_pointer(cmd, 7, &dw);
2860 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2861 dw[1] = 0;
2862 dw[2] = 0;
2863 dw[3] = 0;
2864 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2865 dw[5] = GEN6_GS_DW5_STATISTICS;
2866 dw[6] = 0;
2867
Chia-I Wu6032b892014-10-17 14:47:18 +08002868 /* 3DSTATE_SF */
2869 cmd_batch_pointer(cmd, 20, &dw);
2870 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2871 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2872 memset(&dw[2], 0, 18 * sizeof(*dw));
2873}
2874
2875static void gen7_meta_disabled(struct intel_cmd *cmd)
2876{
2877 uint32_t *dw;
2878
2879 CMD_ASSERT(cmd, 7, 7.5);
2880
Chia-I Wu6032b892014-10-17 14:47:18 +08002881 /* 3DSTATE_CONSTANT_HS */
2882 cmd_batch_pointer(cmd, 7, &dw);
2883 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2884 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2885
2886 /* 3DSTATE_HS */
2887 cmd_batch_pointer(cmd, 7, &dw);
2888 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2889 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2890
2891 /* 3DSTATE_TE */
2892 cmd_batch_pointer(cmd, 4, &dw);
2893 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2894 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2895
2896 /* 3DSTATE_CONSTANT_DS */
2897 cmd_batch_pointer(cmd, 7, &dw);
2898 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2899 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2900
2901 /* 3DSTATE_DS */
2902 cmd_batch_pointer(cmd, 6, &dw);
2903 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2904 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2905
2906 /* 3DSTATE_CONSTANT_GS */
2907 cmd_batch_pointer(cmd, 7, &dw);
2908 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2909 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2910
2911 /* 3DSTATE_GS */
2912 cmd_batch_pointer(cmd, 7, &dw);
2913 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2914 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2915
2916 /* 3DSTATE_STREAMOUT */
2917 cmd_batch_pointer(cmd, 3, &dw);
2918 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2919 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2920
Chia-I Wu6032b892014-10-17 14:47:18 +08002921 /* 3DSTATE_SF */
2922 cmd_batch_pointer(cmd, 7, &dw);
2923 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2924 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2925
2926 /* 3DSTATE_SBE */
2927 cmd_batch_pointer(cmd, 14, &dw);
2928 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2929 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2930 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002931}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002932
Chia-I Wu29e6f502014-11-24 14:27:29 +08002933static void gen6_meta_clip(struct intel_cmd *cmd)
2934{
2935 const struct intel_cmd_meta *meta = cmd->bind.meta;
2936 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002937
Chia-I Wu29e6f502014-11-24 14:27:29 +08002938 /* 3DSTATE_CLIP */
2939 cmd_batch_pointer(cmd, 4, &dw);
2940 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2941 dw[1] = 0;
2942 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2943 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2944 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2945 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002946 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002947 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002948 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002949}
2950
2951static void gen6_meta_wm(struct intel_cmd *cmd)
2952{
2953 const struct intel_cmd_meta *meta = cmd->bind.meta;
2954 uint32_t *dw;
2955
2956 CMD_ASSERT(cmd, 6, 7.5);
2957
2958 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2959
2960 /* 3DSTATE_MULTISAMPLE */
2961 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2962 cmd_batch_pointer(cmd, 4, &dw);
2963 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2964 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2965 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2966 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2967 dw[2] = 0;
2968 dw[3] = 0;
2969 } else {
2970 cmd_batch_pointer(cmd, 3, &dw);
2971 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2972 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2973 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2974 dw[2] = 0;
2975 }
2976
2977 /* 3DSTATE_SAMPLE_MASK */
2978 cmd_batch_pointer(cmd, 2, &dw);
2979 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2980 dw[1] = (1 << meta->samples) - 1;
2981
2982 /* 3DSTATE_DRAWING_RECTANGLE */
2983 cmd_batch_pointer(cmd, 4, &dw);
2984 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002985 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2986 /* unused */
2987 dw[1] = 0;
2988 dw[2] = 0;
2989 } else {
2990 dw[1] = meta->dst.y << 16 | meta->dst.x;
2991 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2992 (meta->dst.x + meta->width - 1);
2993 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002994 dw[3] = 0;
2995}
2996
2997static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2998{
2999 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003000 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08003001 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003002 uint32_t consts[8];
3003 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08003004
3005 CMD_ASSERT(cmd, 6, 7.5);
3006
3007 /* underflow is fine here */
3008 offset_x = meta->src.x - meta->dst.x;
3009 offset_y = meta->src.y - meta->dst.y;
3010
3011 switch (meta->shader_id) {
3012 case INTEL_DEV_META_FS_COPY_MEM:
3013 case INTEL_DEV_META_FS_COPY_1D:
3014 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
3015 case INTEL_DEV_META_FS_COPY_2D:
3016 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
3017 case INTEL_DEV_META_FS_COPY_2D_MS:
3018 consts[0] = offset_x;
3019 consts[1] = offset_y;
3020 consts[2] = meta->src.layer;
3021 consts[3] = meta->src.lod;
3022 const_count = 4;
3023 break;
3024 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
3025 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
3026 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
3027 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
3028 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
3029 consts[0] = offset_x;
3030 consts[1] = offset_y;
3031 consts[2] = meta->src.layer;
3032 consts[3] = meta->src.lod;
3033 consts[4] = meta->src.x;
3034 consts[5] = meta->width;
3035 const_count = 6;
3036 break;
3037 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
3038 consts[0] = offset_x;
3039 consts[1] = offset_y;
3040 consts[2] = meta->width;
3041 const_count = 3;
3042 break;
3043 case INTEL_DEV_META_FS_CLEAR_COLOR:
3044 consts[0] = meta->clear_val[0];
3045 consts[1] = meta->clear_val[1];
3046 consts[2] = meta->clear_val[2];
3047 consts[3] = meta->clear_val[3];
3048 const_count = 4;
3049 break;
3050 case INTEL_DEV_META_FS_CLEAR_DEPTH:
3051 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08003052 consts[1] = meta->clear_val[1];
3053 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08003054 break;
3055 case INTEL_DEV_META_FS_RESOLVE_2X:
3056 case INTEL_DEV_META_FS_RESOLVE_4X:
3057 case INTEL_DEV_META_FS_RESOLVE_8X:
3058 case INTEL_DEV_META_FS_RESOLVE_16X:
3059 consts[0] = offset_x;
3060 consts[1] = offset_y;
3061 const_count = 2;
3062 break;
3063 default:
3064 assert(!"unknown meta shader id");
3065 const_count = 0;
3066 break;
3067 }
3068
3069 /* this can be skipped but it makes state dumping prettier */
3070 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
3071
3072 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
3073}
3074
3075static void gen6_meta_ps(struct intel_cmd *cmd)
3076{
3077 const struct intel_cmd_meta *meta = cmd->bind.meta;
3078 const struct intel_pipeline_shader *sh =
3079 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
3080 uint32_t offset, *dw;
3081
3082 CMD_ASSERT(cmd, 6, 6);
3083
Chia-I Wu29e6f502014-11-24 14:27:29 +08003084 if (meta->mode != INTEL_CMD_META_FS_RECT) {
3085 /* 3DSTATE_CONSTANT_PS */
3086 cmd_batch_pointer(cmd, 5, &dw);
3087 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
3088 dw[1] = 0;
3089 dw[2] = 0;
3090 dw[3] = 0;
3091 dw[4] = 0;
3092
3093 /* 3DSTATE_WM */
3094 cmd_batch_pointer(cmd, 9, &dw);
3095 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
3096 dw[1] = 0;
3097 dw[2] = 0;
3098 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07003099
3100 switch (meta->ds.op) {
3101 case INTEL_CMD_META_DS_HIZ_CLEAR:
3102 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
3103 break;
3104 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3105 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
3106 break;
3107 case INTEL_CMD_META_DS_RESOLVE:
3108 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
3109 break;
3110 default:
3111 dw[4] = 0;
3112 break;
3113 }
3114
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003115 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003116 dw[6] = 0;
3117 dw[7] = 0;
3118 dw[8] = 0;
3119
Chia-I Wu3adf7212014-10-24 15:34:07 +08003120 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003121 }
3122
Chia-I Wu3adf7212014-10-24 15:34:07 +08003123 /* a normal color write */
3124 assert(meta->dst.valid && !sh->uses);
3125
Chia-I Wu6032b892014-10-17 14:47:18 +08003126 /* 3DSTATE_CONSTANT_PS */
3127 offset = gen6_meta_ps_constants(cmd);
3128 cmd_batch_pointer(cmd, 5, &dw);
3129 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003130 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003131 dw[1] = offset;
3132 dw[2] = 0;
3133 dw[3] = 0;
3134 dw[4] = 0;
3135
3136 /* 3DSTATE_WM */
3137 offset = emit_shader(cmd, sh);
3138 cmd_batch_pointer(cmd, 9, &dw);
3139 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
3140 dw[1] = offset;
3141 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3142 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003143 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003144 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003145 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003146 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
3147 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08003148
Chia-I Wu6032b892014-10-17 14:47:18 +08003149 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003150 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003151 GEN6_WM_DW6_ZW_INTERP_PIXEL |
3152 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
3153 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
3154 if (meta->samples > 1) {
3155 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
3156 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
3157 } else {
3158 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
3159 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
3160 }
3161 dw[7] = 0;
3162 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003163
3164 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003165}
3166
3167static void gen7_meta_ps(struct intel_cmd *cmd)
3168{
3169 const struct intel_cmd_meta *meta = cmd->bind.meta;
3170 const struct intel_pipeline_shader *sh =
3171 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
3172 uint32_t offset, *dw;
3173
3174 CMD_ASSERT(cmd, 7, 7.5);
3175
Chia-I Wu29e6f502014-11-24 14:27:29 +08003176 if (meta->mode != INTEL_CMD_META_FS_RECT) {
3177 /* 3DSTATE_WM */
3178 cmd_batch_pointer(cmd, 3, &dw);
3179 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003180
3181 switch (meta->ds.op) {
3182 case INTEL_CMD_META_DS_HIZ_CLEAR:
3183 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3184 break;
3185 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3186 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3187 break;
3188 case INTEL_CMD_META_DS_RESOLVE:
3189 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3190 break;
3191 default:
3192 dw[1] = 0;
3193 break;
3194 }
3195
3196 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003197
3198 /* 3DSTATE_CONSTANT_GS */
3199 cmd_batch_pointer(cmd, 7, &dw);
3200 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3201 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3202
3203 /* 3DSTATE_PS */
3204 cmd_batch_pointer(cmd, 8, &dw);
3205 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3206 dw[1] = 0;
3207 dw[2] = 0;
3208 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003209 /* required to avoid hangs */
3210 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003211 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003212 dw[5] = 0;
3213 dw[6] = 0;
3214 dw[7] = 0;
3215
Chia-I Wu3adf7212014-10-24 15:34:07 +08003216 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003217 }
3218
Chia-I Wu3adf7212014-10-24 15:34:07 +08003219 /* a normal color write */
3220 assert(meta->dst.valid && !sh->uses);
3221
Chia-I Wu6032b892014-10-17 14:47:18 +08003222 /* 3DSTATE_WM */
3223 cmd_batch_pointer(cmd, 3, &dw);
3224 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003225 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003226 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3227 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3228 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3229 dw[2] = 0;
3230
3231 /* 3DSTATE_CONSTANT_PS */
3232 offset = gen6_meta_ps_constants(cmd);
3233 cmd_batch_pointer(cmd, 7, &dw);
3234 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003235 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003236 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003237 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003238 dw[4] = 0;
3239 dw[5] = 0;
3240 dw[6] = 0;
3241
3242 /* 3DSTATE_PS */
3243 offset = emit_shader(cmd, sh);
3244 cmd_batch_pointer(cmd, 8, &dw);
3245 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3246 dw[1] = offset;
3247 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3248 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003249 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003250
3251 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3252 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003253 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003254
3255 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003256 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003257 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003258 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003259 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003260 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003261
3262 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3263 dw[6] = 0;
3264 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003265
3266 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003267}
3268
3269static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3270{
3271 const struct intel_cmd_meta *meta = cmd->bind.meta;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06003272 const struct intel_att_view *view = &meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003273
3274 CMD_ASSERT(cmd, 6, 7.5);
3275
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003276 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003277 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003278 static const struct intel_att_view null_view;
3279 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003280 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003281
3282 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003283 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3284 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3285 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003286
3287 if (cmd_gen(cmd) >= INTEL_GEN(7))
3288 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3289 else
3290 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003291}
3292
Chia-I Wu862c5572015-03-28 15:23:55 +08003293static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3294 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003295 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003296{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003297 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003298 if (data->set_offsets)
3299 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003300
Chia-I Wu862c5572015-03-28 15:23:55 +08003301 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003302 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003303 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003304 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003305 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003306 data->set_offset_count = 0;
3307 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003308 }
3309
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003310 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003311 }
3312
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003313 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003314 if (data->dynamic_offsets)
3315 intel_free(cmd, data->dynamic_offsets);
3316
3317 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003318 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003319 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003320 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003321 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003322 data->dynamic_offset_count = 0;
3323 return false;
3324 }
3325
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003326 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003327 }
3328
3329 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003330}
3331
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06003332static void cmd_bind_dynamic_state(struct intel_cmd *cmd,
3333 const struct intel_pipeline *pipeline)
3334
3335{
3336 VkFlags use_flags = pipeline->state.use_pipeline_dynamic_state;
3337 if (!use_flags) {
3338 return;
3339 }
3340 cmd->bind.state.use_pipeline_dynamic_state = use_flags;
3341 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_VIEWPORT) {
3342 const struct intel_dynamic_viewport *viewport = &pipeline->state.viewport;
3343 intel_set_viewport(cmd, viewport->viewport_count, viewport->viewports);
3344 }
Chris Forbesaf56e162015-10-07 12:24:34 +13003345 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_SCISSOR) {
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06003346 const struct intel_dynamic_viewport *viewport = &pipeline->state.viewport;
Chris Forbesaf56e162015-10-07 12:24:34 +13003347 intel_set_scissor(cmd, viewport->scissor_count, viewport->scissors);
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06003348 }
3349 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_LINE_WIDTH) {
3350 intel_set_line_width(cmd, pipeline->state.line_width.line_width);
3351 }
3352 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_DEPTH_BIAS) {
3353 const struct intel_dynamic_depth_bias *s = &pipeline->state.depth_bias;
3354 intel_set_depth_bias(cmd, s->depth_bias, s->depth_bias_clamp, s->slope_scaled_depth_bias);
3355 }
3356 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_BLEND_CONSTANTS) {
3357 const struct intel_dynamic_blend *s = &pipeline->state.blend;
3358 intel_set_blend_constants(cmd, s->blend_const);
3359 }
3360 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_DEPTH_BOUNDS) {
3361 const struct intel_dynamic_depth_bounds *s = &pipeline->state.depth_bounds;
3362 intel_set_depth_bounds(cmd, s->min_depth_bounds, s->max_depth_bounds);
3363 }
3364 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_STENCIL_COMPARE_MASK) {
3365 const struct intel_dynamic_stencil *s = &pipeline->state.stencil;
3366 intel_set_stencil_compare_mask(cmd, VK_STENCIL_FACE_FRONT_BIT, s->front.stencil_compare_mask);
3367 intel_set_stencil_compare_mask(cmd, VK_STENCIL_FACE_BACK_BIT, s->back.stencil_compare_mask);
3368 }
3369 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_STENCIL_WRITE_MASK) {
3370 const struct intel_dynamic_stencil *s = &pipeline->state.stencil;
3371 intel_set_stencil_write_mask(cmd, VK_STENCIL_FACE_FRONT_BIT, s->front.stencil_write_mask);
3372 intel_set_stencil_write_mask(cmd, VK_STENCIL_FACE_BACK_BIT, s->back.stencil_write_mask);
3373 }
3374 if (use_flags & INTEL_USE_PIPELINE_DYNAMIC_STENCIL_REFERENCE) {
3375 const struct intel_dynamic_stencil *s = &pipeline->state.stencil;
3376 intel_set_stencil_reference(cmd, VK_STENCIL_FACE_FRONT_BIT, s->front.stencil_reference);
3377 intel_set_stencil_reference(cmd, VK_STENCIL_FACE_BACK_BIT, s->back.stencil_reference);
3378 }
3379}
3380
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003381static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3382 const struct intel_pipeline *pipeline)
3383{
3384 cmd->bind.pipeline.graphics = pipeline;
3385
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -06003386 cmd_bind_dynamic_state(cmd, pipeline);
3387
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003388 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003389 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003390}
3391
3392static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3393 const struct intel_pipeline *pipeline)
3394{
3395 cmd->bind.pipeline.compute = pipeline;
3396
3397 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003398 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003399}
3400
Chia-I Wu862c5572015-03-28 15:23:55 +08003401static void cmd_copy_dset_data(struct intel_cmd *cmd,
3402 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003403 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003404 uint32_t index,
3405 const struct intel_desc_set *set,
3406 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003407{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003408 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003409
Chia-I Wu862c5572015-03-28 15:23:55 +08003410 assert(index < data->set_offset_count);
3411 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003412
Chia-I Wu862c5572015-03-28 15:23:55 +08003413 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003414 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003415 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003416
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003417 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003418 dynamic_offsets,
3419 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003420 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003421}
3422
Chia-I Wu3b04af52014-11-08 10:48:20 +08003423static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003424 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003425 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003426{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003427 /* TODOVV: verify */
3428 assert(!(binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) && "binding exceeds buf size");
Chia-I Wu3b04af52014-11-08 10:48:20 +08003429
Chia-I Wu714df452015-01-01 07:55:04 +08003430 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003431 cmd->bind.vertex.offset[binding] = offset;
3432}
3433
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003434static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003435 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003436 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003437{
Chia-I Wu714df452015-01-01 07:55:04 +08003438 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003439 cmd->bind.index.offset = offset;
3440 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003441}
3442
Chia-I Wuf98dd882015-02-10 04:17:47 +08003443static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3444{
3445 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3446 struct intel_pipeline_rmap *rmaps[5] = {
3447 pipeline->vs.rmap,
3448 pipeline->tcs.rmap,
3449 pipeline->tes.rmap,
3450 pipeline->gs.rmap,
3451 pipeline->fs.rmap,
3452 };
3453 uint32_t max_write;
3454 int i;
3455
3456 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3457 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3458 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3459
3460 /* pad first */
3461 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3462
3463 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3464 const struct intel_pipeline_rmap *rmap = rmaps[i];
3465 const uint32_t surface_count = (rmap) ?
3466 rmap->rt_count + rmap->texture_resource_count +
3467 rmap->resource_count + rmap->uav_count : 0;
3468
3469 if (surface_count) {
3470 /* SURFACE_STATEs */
3471 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3472
3473 /* BINDING_TABLE_STATE */
3474 max_write += u_align(sizeof(uint32_t) * surface_count,
3475 GEN6_ALIGNMENT_SURFACE_STATE);
3476 }
3477 }
3478
3479 return max_write;
3480}
3481
3482static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3483{
3484 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3485 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3486 uint32_t max_surface_write;
3487
3488 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3489 if (cmd->bind.meta)
3490 max_surface_write = 64 * sizeof(uint32_t);
3491 else
3492 max_surface_write = cmd_get_max_surface_write(cmd);
3493
3494 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3495 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3496 /* SBA expects page-aligned addresses */
3497 writer->sba_offset = writer->used & ~0xfff;
3498
3499 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3500
3501 cmd_batch_state_base_address(cmd);
3502 }
3503}
3504
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003505static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003506 uint32_t vertex_start,
3507 uint32_t vertex_count,
3508 uint32_t instance_start,
3509 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003510 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003511 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003512{
3513 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003514 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003515 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3516
3517 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003518
3519 emit_bounded_states(cmd);
3520
Chia-I Wuf98dd882015-02-10 04:17:47 +08003521 /* sanity check on cmd_get_max_surface_write() */
3522 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3523 surface_writer_used <= cmd_get_max_surface_write(cmd));
3524
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003525 if (indexed) {
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003526 assert(!(p->primitive_restart && !gen6_can_primitive_restart(cmd)) && "Primitive restart unsupported on this device");
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003527
3528 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3529 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3530 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003531 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003532 cmd->bind.index.offset, cmd->bind.index.type,
3533 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003534 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003535 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003536 cmd->bind.index.offset, cmd->bind.index.type,
3537 p->primitive_restart);
3538 }
3539 } else {
3540 assert(!vertex_base);
3541 }
3542
3543 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3544 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3545 vertex_start, instance_count, instance_start, vertex_base);
3546 } else {
3547 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3548 vertex_start, instance_count, instance_start, vertex_base);
3549 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003550
Chia-I Wu707a29e2014-08-27 12:51:47 +08003551 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003552 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003553 /* need to re-emit all workarounds */
3554 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003555
3556 if (intel_debug & INTEL_DEBUG_NOCACHE)
3557 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003558}
3559
Chia-I Wuc14d1562014-10-17 09:49:22 +08003560void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3561{
Chia-I Wu6032b892014-10-17 14:47:18 +08003562 cmd->bind.meta = meta;
3563
Chia-I Wuf98dd882015-02-10 04:17:47 +08003564 cmd_adjust_state_base_address(cmd);
3565
Chia-I Wu6032b892014-10-17 14:47:18 +08003566 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003567 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003568
3569 gen6_meta_dynamic_states(cmd);
3570 gen6_meta_surface_states(cmd);
3571
3572 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3573 gen7_meta_urb(cmd);
3574 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003575 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003576 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003577 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003578 gen6_meta_wm(cmd);
3579 gen7_meta_ps(cmd);
3580 gen6_meta_depth_buffer(cmd);
3581
3582 cmd_wa_gen7_post_command_cs_stall(cmd);
3583 cmd_wa_gen7_post_command_depth_stall(cmd);
3584
Chia-I Wu29e6f502014-11-24 14:27:29 +08003585 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3586 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003587 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003588 } else {
3589 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3590 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003591 } else {
3592 gen6_meta_urb(cmd);
3593 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003594 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003595 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003596 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003597 gen6_meta_wm(cmd);
3598 gen6_meta_ps(cmd);
3599 gen6_meta_depth_buffer(cmd);
3600
Chia-I Wu29e6f502014-11-24 14:27:29 +08003601 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3602 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003603 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003604 } else {
3605 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3606 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003607 }
3608
3609 cmd->bind.draw_count++;
3610 /* need to re-emit all workarounds */
3611 cmd->bind.wa_flags = 0;
3612
3613 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003614
Chia-I Wubbc7d912015-02-27 14:59:50 -07003615 /* make the normal path believe the render pass has changed */
3616 cmd->bind.render_pass_changed = true;
3617
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003618 if (intel_debug & INTEL_DEBUG_NOCACHE)
3619 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003620}
3621
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003622static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3623{
3624 const uint8_t cmd_len = 2;
3625 uint32_t *dw;
3626 uint32_t pos;
3627
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003628 assert(!(cmd_gen(cmd) < INTEL_GEN(7.5)) && "Invalid GPU version");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003629
3630 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3631 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3632 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3633 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3634 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3635
3636 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3637}
3638
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003639ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003640 VkCmdBuffer cmdBuffer,
3641 VkPipelineBindPoint pipelineBindPoint,
3642 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003643{
3644 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3645
3646 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003647 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003648 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003649 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003650 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003651 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003652 break;
3653 default:
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003654 assert(!"unsupported pipelineBindPoint");
Chia-I Wub2755562014-08-20 13:38:52 +08003655 break;
3656 }
3657}
3658
Chia-I Wub2755562014-08-20 13:38:52 +08003659
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003660ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003661 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003662 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003663 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003664 uint32_t firstSet,
3665 uint32_t setCount,
3666 const VkDescriptorSet* pDescriptorSets,
3667 uint32_t dynamicOffsetCount,
3668 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003669{
3670 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003671 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003672 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003673 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003674 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003675
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003676 pipeline_layout = intel_pipeline_layout(layout);
3677
Chia-I Wub2755562014-08-20 13:38:52 +08003678 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003679 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003680 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003681 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003682 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003683 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003684 break;
3685 default:
Tobin Ehlis5f728d32015-09-17 14:18:16 -06003686 assert(!"unsupported pipelineBindPoint");
Chia-I Wub2755562014-08-20 13:38:52 +08003687 break;
3688 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003689
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003690 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003691 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3692
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003693 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003694 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003695 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003696 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003697 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003698 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003699 }
Chia-I Wub2755562014-08-20 13:38:52 +08003700}
3701
Tony Barbour8205d902015-04-16 15:59:00 -06003702
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003703ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3704 VkCmdBuffer cmdBuffer,
3705 uint32_t startBinding,
3706 uint32_t bindingCount,
3707 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003708 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003709{
3710 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003711
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003712 for (uint32_t i = 0; i < bindingCount; i++) {
3713 struct intel_buf *buf = intel_buf(pBuffers[i]);
3714 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3715 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003716}
3717
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003718ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003719 VkCmdBuffer cmdBuffer,
3720 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003721 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003722 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003723{
3724 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003725 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003726
Chia-I Wu714df452015-01-01 07:55:04 +08003727 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003728}
3729
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003730ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003731 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003732 uint32_t vertexCount,
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003733 uint32_t instanceCount,
3734 uint32_t firstVertex,
3735 uint32_t firstInstance)
Chia-I Wub2755562014-08-20 13:38:52 +08003736{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003737 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003738
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003739 cmd_draw(cmd, firstVertex, vertexCount,
3740 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003741}
3742
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003743ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003744 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003745 uint32_t indexCount,
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003746 uint32_t instanceCount,
3747 uint32_t firstIndex,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003748 int32_t vertexOffset,
Courtney Goeltzenleuchter4ff11cc2015-09-23 12:31:50 -06003749 uint32_t firstInstance)
Chia-I Wub2755562014-08-20 13:38:52 +08003750{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003751 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003752
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003753 cmd_draw(cmd, firstIndex, indexCount,
3754 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003755}
3756
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003757ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003758 VkCmdBuffer cmdBuffer,
3759 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003760 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003761 uint32_t count,
3762 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003763{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003764 assert(0 && "vkCmdDrawIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003765}
3766
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003767ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003768 VkCmdBuffer cmdBuffer,
3769 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003770 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003771 uint32_t count,
3772 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003773{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003774 assert(0 && "vkCmdDrawIndexedIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003775}
3776
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003777ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003778 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003779 uint32_t x,
3780 uint32_t y,
3781 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003782{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003783 assert(0 && "vkCmdDispatch not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003784}
3785
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003786ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003787 VkCmdBuffer cmdBuffer,
3788 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003789 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003790{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003791 assert(0 && "vkCmdDisatchIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003792}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003793
Courtney Goeltzenleuchtera375b622015-07-27 14:04:01 -06003794void VKAPI vkCmdPushConstants(
3795 VkCmdBuffer cmdBuffer,
3796 VkPipelineLayout layout,
3797 VkShaderStageFlags stageFlags,
3798 uint32_t start,
3799 uint32_t length,
3800 const void* values)
3801{
3802 /* TODO: Implement */
3803}
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003804
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -06003805void VKAPI vkGetRenderAreaGranularity(
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003806 VkDevice device,
3807 VkRenderPass renderPass,
3808 VkExtent2D* pGranularity)
3809{
3810 pGranularity->height = 1;
3811 pGranularity->width = 1;
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003812}
3813
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003814ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003815 VkCmdBuffer cmdBuffer,
3816 const VkRenderPassBeginInfo* pRenderPassBegin,
3817 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003818{
Chia-I Wubdeed152015-07-09 12:16:29 +08003819 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3820 const struct intel_render_pass *rp =
3821 intel_render_pass(pRenderPassBegin->renderPass);
3822 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3823 const struct intel_att_view *view;
3824 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003825
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003826 /* TODOVV: */
3827 assert(!(!cmd->primary || rp->attachment_count != fb->view_count) && "Invalid RenderPass");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003828
Cody Northrop16898b02015-08-11 11:35:58 -06003829 cmd_begin_render_pass(cmd, rp, fb, 0, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003830
Chia-I Wubdeed152015-07-09 12:16:29 +08003831 for (i = 0; i < rp->attachment_count; i++) {
3832 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003833 const VkClearValue *clear_val =
Cody Northropc332eef2015-08-04 11:51:03 -06003834 &pRenderPassBegin->pClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003835 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003836
Chia-I Wubdeed152015-07-09 12:16:29 +08003837 view = fb->views[i];
3838 range.baseMipLevel = view->mipLevel;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06003839 range.numLevels = 1;
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -06003840 range.baseArrayLayer = view->baseArrayLayer;
Courtney Goeltzenleuchter63f0ead2015-10-16 09:46:00 -06003841 range.numLayers = view->array_size;
Chris Forbesf4107bd2015-09-18 13:23:32 +12003842 range.aspectMask = 0;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003843
Chia-I Wubdeed152015-07-09 12:16:29 +08003844 if (view->is_rt) {
Chris Forbesf4107bd2015-09-18 13:23:32 +12003845 /* color */
3846 if (att->clear_on_load) {
3847 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003848
Chris Forbesf4107bd2015-09-18 13:23:32 +12003849 cmd_meta_clear_color_image(cmdBuffer, view->img,
3850 att->initial_layout, &clear_val->color, 1, &range);
3851 }
Chia-I Wubdeed152015-07-09 12:16:29 +08003852 } else {
Chris Forbesf4107bd2015-09-18 13:23:32 +12003853 /* depth/stencil */
3854 if (att->clear_on_load) {
3855 range.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
3856 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003857
Chia-I Wubdeed152015-07-09 12:16:29 +08003858 if (att->stencil_clear_on_load) {
Chris Forbesf4107bd2015-09-18 13:23:32 +12003859 range.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
3860 }
Chris Forbes4cf9d102015-06-22 18:46:05 +12003861
Chris Forbesf4107bd2015-09-18 13:23:32 +12003862 if (range.aspectMask) {
Chia-I Wubdeed152015-07-09 12:16:29 +08003863 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003864 view->img, att->initial_layout,
Cody Northrop2563a032015-08-25 15:26:38 -06003865 clear_val->depthStencil.depth, clear_val->depthStencil.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003866 1, &range);
3867 }
3868 }
3869 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003870}
3871
Chia-I Wuc278df82015-07-07 11:50:03 +08003872ICD_EXPORT void VKAPI vkCmdNextSubpass(
3873 VkCmdBuffer cmdBuffer,
3874 VkRenderPassContents contents)
3875{
3876 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3877 const struct intel_render_pass *rp = cmd->bind.render_pass;
3878
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003879 /* TODOVV */
3880 assert(!(cmd->bind.render_pass_subpass >= rp->subpasses +
3881 rp->subpass_count - 1) && "Invalid RenderPassContents");
Chia-I Wuc278df82015-07-07 11:50:03 +08003882
3883 cmd->bind.render_pass_changed = true;
3884 cmd->bind.render_pass_subpass++;
3885 cmd->bind.render_pass_contents = contents;
3886}
3887
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003888ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003889 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003890{
3891 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3892
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003893 cmd_end_render_pass(cmd);
3894}
3895
3896ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3897 VkCmdBuffer cmdBuffer,
3898 uint32_t cmdBuffersCount,
3899 const VkCmdBuffer* pCmdBuffers)
3900{
3901 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003902 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003903
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003904 /* TODOVV */
3905 assert(!(!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3906 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) && "Invalid RenderPass");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003907
3908 for (i = 0; i < cmdBuffersCount; i++) {
3909 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3910
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003911 /* TODOVV: Move test to validation layer */
3912 assert(!(secondary->primary) && "Cannot be primary command buffer");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003913
3914 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3915 }
3916
3917 if (i)
3918 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003919}