blob: 60e0f607cde5be716e4e1f40a973486411118233 [file] [log] [blame]
Chia-I Wub2755562014-08-20 13:38:52 +08001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Chia-I Wub2755562014-08-20 13:38:52 +08003 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 * Courtney Goeltzenleuchter <courtney@lunarg.com>
Chia-I Wub2755562014-08-20 13:38:52 +080027 */
28
Chia-I Wu9f039862014-08-20 15:39:56 +080029#include "genhw/genhw.h"
Chia-I Wu714df452015-01-01 07:55:04 +080030#include "buf.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080031#include "desc.h"
Chia-I Wu7fae4e32014-08-21 11:39:44 +080032#include "img.h"
Chia-I Wub2755562014-08-20 13:38:52 +080033#include "mem.h"
Chia-I Wu018a3962014-08-21 10:37:52 +080034#include "pipeline.h"
Chia-I Wufc05a2e2014-10-07 00:34:13 +080035#include "sampler.h"
Chia-I Wu1f2fd292014-08-29 15:07:09 +080036#include "shader.h"
Chia-I Wub2755562014-08-20 13:38:52 +080037#include "state.h"
38#include "view.h"
39#include "cmd_priv.h"
Jon Ashburnc04b4dc2015-01-08 18:48:10 -070040#include "fb.h"
Chia-I Wub2755562014-08-20 13:38:52 +080041
Chia-I Wu59c097e2014-08-21 10:51:07 +080042static void gen6_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080043 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080044 uint32_t vertex_count,
45 uint32_t vertex_start,
46 uint32_t instance_count,
47 uint32_t instance_start,
48 uint32_t vertex_base)
49{
50 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +080051 uint32_t dw0, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080052
53 CMD_ASSERT(cmd, 6, 6);
54
Chia-I Wu426072d2014-08-26 14:31:55 +080055 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
Chia-I Wu254db422014-08-21 11:54:29 +080056 prim_type << GEN6_3DPRIM_DW0_TYPE__SHIFT |
Chia-I Wu59c097e2014-08-21 10:51:07 +080057 (cmd_len - 2);
58
59 if (indexed)
60 dw0 |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
61
Chia-I Wu72292b72014-09-09 10:48:33 +080062 cmd_batch_pointer(cmd, cmd_len, &dw);
63 dw[0] = dw0;
64 dw[1] = vertex_count;
65 dw[2] = vertex_start;
66 dw[3] = instance_count;
67 dw[4] = instance_start;
68 dw[5] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080069}
70
71static void gen7_3DPRIMITIVE(struct intel_cmd *cmd,
Chia-I Wu254db422014-08-21 11:54:29 +080072 int prim_type, bool indexed,
Chia-I Wu59c097e2014-08-21 10:51:07 +080073 uint32_t vertex_count,
74 uint32_t vertex_start,
75 uint32_t instance_count,
76 uint32_t instance_start,
77 uint32_t vertex_base)
78{
79 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +080080 uint32_t dw0, dw1, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +080081
82 CMD_ASSERT(cmd, 7, 7.5);
83
Chia-I Wu426072d2014-08-26 14:31:55 +080084 dw0 = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +080085 dw1 = prim_type << GEN7_3DPRIM_DW1_TYPE__SHIFT;
Chia-I Wu59c097e2014-08-21 10:51:07 +080086
87 if (indexed)
88 dw1 |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
89
Chia-I Wu72292b72014-09-09 10:48:33 +080090 cmd_batch_pointer(cmd, cmd_len, &dw);
91 dw[0] = dw0;
92 dw[1] = dw1;
93 dw[2] = vertex_count;
94 dw[3] = vertex_start;
95 dw[4] = instance_count;
96 dw[5] = instance_start;
97 dw[6] = vertex_base;
Chia-I Wu59c097e2014-08-21 10:51:07 +080098}
99
Chia-I Wu270b1e82014-08-25 15:53:39 +0800100static void gen6_PIPE_CONTROL(struct intel_cmd *cmd, uint32_t dw1,
Chia-I Wud6d079d2014-08-31 13:14:21 +0800101 struct intel_bo *bo, uint32_t bo_offset,
102 uint64_t imm)
Chia-I Wu270b1e82014-08-25 15:53:39 +0800103{
104 const uint8_t cmd_len = 5;
Chia-I Wu426072d2014-08-26 14:31:55 +0800105 const uint32_t dw0 = GEN6_RENDER_CMD(3D, PIPE_CONTROL) |
Chia-I Wu270b1e82014-08-25 15:53:39 +0800106 (cmd_len - 2);
Chia-I Wu2caf7492014-08-31 12:28:38 +0800107 uint32_t reloc_flags = INTEL_RELOC_WRITE;
Chia-I Wu72292b72014-09-09 10:48:33 +0800108 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600109 uint32_t pos;
Chia-I Wu270b1e82014-08-25 15:53:39 +0800110
111 CMD_ASSERT(cmd, 6, 7.5);
112
113 assert(bo_offset % 8 == 0);
114
115 if (dw1 & GEN6_PIPE_CONTROL_CS_STALL) {
116 /*
117 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
118 *
119 * "1 of the following must also be set (when CS stall is set):
120 *
121 * * Depth Cache Flush Enable ([0] of DW1)
122 * * Stall at Pixel Scoreboard ([1] of DW1)
123 * * Depth Stall ([13] of DW1)
124 * * Post-Sync Operation ([13] of DW1)
125 * * Render Target Cache Flush Enable ([12] of DW1)
126 * * Notify Enable ([8] of DW1)"
127 *
128 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
129 *
130 * "One of the following must also be set (when CS stall is set):
131 *
132 * * Render Target Cache Flush Enable ([12] of DW1)
133 * * Depth Cache Flush Enable ([0] of DW1)
134 * * Stall at Pixel Scoreboard ([1] of DW1)
135 * * Depth Stall ([13] of DW1)
136 * * Post-Sync Operation ([13] of DW1)"
137 */
138 uint32_t bit_test = GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
139 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
140 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
141 GEN6_PIPE_CONTROL_DEPTH_STALL;
142
143 /* post-sync op */
144 bit_test |= GEN6_PIPE_CONTROL_WRITE_IMM |
145 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT |
146 GEN6_PIPE_CONTROL_WRITE_TIMESTAMP;
147
148 if (cmd_gen(cmd) == INTEL_GEN(6))
149 bit_test |= GEN6_PIPE_CONTROL_NOTIFY_ENABLE;
150
151 assert(dw1 & bit_test);
152 }
153
154 if (dw1 & GEN6_PIPE_CONTROL_DEPTH_STALL) {
155 /*
156 * From the Sandy Bridge PRM, volume 2 part 1, page 73:
157 *
158 * "Following bits must be clear (when Depth Stall is set):
159 *
160 * * Render Target Cache Flush Enable ([12] of DW1)
161 * * Depth Cache Flush Enable ([0] of DW1)"
162 */
163 assert(!(dw1 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
164 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH)));
165 }
166
167 /*
168 * From the Sandy Bridge PRM, volume 1 part 3, page 19:
169 *
170 * "[DevSNB] PPGTT memory writes by MI_* (such as MI_STORE_DATA_IMM)
171 * and PIPE_CONTROL are not supported."
172 *
173 * The kernel will add the mapping automatically (when write domain is
174 * INTEL_DOMAIN_INSTRUCTION).
175 */
Chia-I Wu2caf7492014-08-31 12:28:38 +0800176 if (cmd_gen(cmd) == INTEL_GEN(6) && bo) {
Chia-I Wu270b1e82014-08-25 15:53:39 +0800177 bo_offset |= GEN6_PIPE_CONTROL_DW2_USE_GGTT;
Chia-I Wu2caf7492014-08-31 12:28:38 +0800178 reloc_flags |= INTEL_RELOC_GGTT;
179 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800180
Chia-I Wu72292b72014-09-09 10:48:33 +0800181 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
182 dw[0] = dw0;
183 dw[1] = dw1;
184 dw[2] = 0;
185 dw[3] = (uint32_t) imm;
186 dw[4] = (uint32_t) (imm >> 32);
187
188 if (bo) {
189 cmd_reserve_reloc(cmd, 1);
190 cmd_batch_reloc(cmd, pos + 2, bo, bo_offset, reloc_flags);
191 }
Chia-I Wu270b1e82014-08-25 15:53:39 +0800192}
193
Chia-I Wu254db422014-08-21 11:54:29 +0800194static bool gen6_can_primitive_restart(const struct intel_cmd *cmd)
195{
196 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
197 bool supported;
198
199 CMD_ASSERT(cmd, 6, 7.5);
200
201 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
202 return (p->prim_type != GEN6_3DPRIM_RECTLIST);
203
204 switch (p->prim_type) {
205 case GEN6_3DPRIM_POINTLIST:
206 case GEN6_3DPRIM_LINELIST:
207 case GEN6_3DPRIM_LINESTRIP:
208 case GEN6_3DPRIM_TRILIST:
209 case GEN6_3DPRIM_TRISTRIP:
210 supported = true;
211 break;
212 default:
213 supported = false;
214 break;
215 }
216
217 if (!supported)
218 return false;
219
220 switch (cmd->bind.index.type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600221 case VK_INDEX_TYPE_UINT16:
Chia-I Wu254db422014-08-21 11:54:29 +0800222 supported = (p->primitive_restart_index != 0xffffu);
223 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600224 case VK_INDEX_TYPE_UINT32:
Chia-I Wu254db422014-08-21 11:54:29 +0800225 supported = (p->primitive_restart_index != 0xffffffffu);
226 break;
227 default:
228 supported = false;
229 break;
230 }
231
232 return supported;
233}
234
Chia-I Wu59c097e2014-08-21 10:51:07 +0800235static void gen6_3DSTATE_INDEX_BUFFER(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +0800236 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -0600237 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600238 VkIndexType type,
Chia-I Wu59c097e2014-08-21 10:51:07 +0800239 bool enable_cut_index)
240{
241 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800242 uint32_t dw0, end_offset, *dw;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800243 unsigned offset_align;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600244 uint32_t pos;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800245
246 CMD_ASSERT(cmd, 6, 7.5);
247
Chia-I Wu426072d2014-08-26 14:31:55 +0800248 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_INDEX_BUFFER) | (cmd_len - 2);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800249
250 /* the bit is moved to 3DSTATE_VF */
251 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
252 assert(!enable_cut_index);
253 if (enable_cut_index)
254 dw0 |= GEN6_IB_DW0_CUT_INDEX_ENABLE;
255
256 switch (type) {
Tony Barbour8205d902015-04-16 15:59:00 -0600257 case VK_INDEX_TYPE_UINT16:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800258 dw0 |= GEN6_IB_DW0_FORMAT_WORD;
259 offset_align = 2;
260 break;
Tony Barbour8205d902015-04-16 15:59:00 -0600261 case VK_INDEX_TYPE_UINT32:
Chia-I Wu59c097e2014-08-21 10:51:07 +0800262 dw0 |= GEN6_IB_DW0_FORMAT_DWORD;
263 offset_align = 4;
264 break;
265 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600266 /* TODOVV: Make sure covered in validation test */
267// cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800268 return;
269 break;
270 }
271
272 if (offset % offset_align) {
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -0600273 /* TODOVV: Make sure covered in validation test */
274// cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800275 return;
276 }
277
278 /* aligned and inclusive */
Chia-I Wu714df452015-01-01 07:55:04 +0800279 end_offset = buf->size - (buf->size % offset_align) - 1;
Chia-I Wu59c097e2014-08-21 10:51:07 +0800280
Chia-I Wu72292b72014-09-09 10:48:33 +0800281 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
282 dw[0] = dw0;
283
284 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +0800285 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
286 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, end_offset, 0);
Chia-I Wu59c097e2014-08-21 10:51:07 +0800287}
288
Chia-I Wu62a7f252014-08-29 11:31:16 +0800289static void gen75_3DSTATE_VF(struct intel_cmd *cmd,
290 bool enable_cut_index,
291 uint32_t cut_index)
Chia-I Wu254db422014-08-21 11:54:29 +0800292{
293 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800294 uint32_t dw0, *dw;
Chia-I Wu254db422014-08-21 11:54:29 +0800295
296 CMD_ASSERT(cmd, 7.5, 7.5);
297
Chia-I Wu426072d2014-08-26 14:31:55 +0800298 dw0 = GEN75_RENDER_CMD(3D, 3DSTATE_VF) | (cmd_len - 2);
Chia-I Wu254db422014-08-21 11:54:29 +0800299 if (enable_cut_index)
300 dw0 |= GEN75_VF_DW0_CUT_INDEX_ENABLE;
301
Chia-I Wu72292b72014-09-09 10:48:33 +0800302 cmd_batch_pointer(cmd, cmd_len, &dw);
303 dw[0] = dw0;
304 dw[1] = cut_index;
Chia-I Wu254db422014-08-21 11:54:29 +0800305}
306
Cody Northrop293d4502015-05-05 09:38:03 -0600307static void gen6_add_scratch_space(struct intel_cmd *cmd,
308 uint32_t batch_pos,
309 const struct intel_pipeline *pipeline,
310 const struct intel_pipeline_shader *sh)
311{
312 int scratch_space;
313
314 CMD_ASSERT(cmd, 6, 7.5);
315
316 assert(sh->per_thread_scratch_size &&
317 sh->per_thread_scratch_size % 1024 == 0 &&
318 u_is_pow2(sh->per_thread_scratch_size) &&
319 sh->scratch_offset % 1024 == 0);
320 scratch_space = u_ffs(sh->per_thread_scratch_size) - 11;
321
322 cmd_reserve_reloc(cmd, 1);
323 cmd_batch_reloc(cmd, batch_pos, pipeline->obj.mem->bo,
324 sh->scratch_offset | scratch_space, INTEL_RELOC_WRITE);
325}
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -0600326
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800327static void gen6_3DSTATE_GS(struct intel_cmd *cmd)
328{
Cody Northrop293d4502015-05-05 09:38:03 -0600329 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
330 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800331 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600332 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800333 CMD_ASSERT(cmd, 6, 6);
Cody Northrop293d4502015-05-05 09:38:03 -0600334 int vue_read_len = 0;
335 int pos = 0;
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800336
Cody Northrop293d4502015-05-05 09:38:03 -0600337 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
338
339 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
340
341 // based on ilo_gpe_init_gs_cso_gen6
342 vue_read_len = (gs->in_count + 1) / 2;
343 if (!vue_read_len)
344 vue_read_len = 1;
345
346 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
347 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT |
348 GEN6_THREADDISP_SPF;
349
350 dw4 = vue_read_len << GEN6_GS_DW4_URB_READ_LEN__SHIFT |
351 0 << GEN6_GS_DW4_URB_READ_OFFSET__SHIFT |
352 gs->urb_grf_start << GEN6_GS_DW4_URB_GRF_START__SHIFT;
353
354 dw5 = (gs->max_threads - 1) << GEN6_GS_DW5_MAX_THREADS__SHIFT |
355 GEN6_GS_DW5_STATISTICS |
356 GEN6_GS_DW5_RENDER_ENABLE;
357
358 dw6 = GEN6_GS_DW6_GS_ENABLE;
359
360 if (gs->discard_adj)
361 dw6 |= GEN6_GS_DW6_DISCARD_ADJACENCY;
362
363 } else {
364 dw2 = 0;
365 dw4 = 0;
366 dw5 = GEN6_GS_DW5_STATISTICS;
367 dw6 = 0;
368 }
369
370 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800371 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600372 dw[1] = cmd->bind.pipeline.gs_offset;
373 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800374 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600375 dw[4] = dw4;
376 dw[5] = dw5;
377 dw[6] = dw6;
378
379 if (gs->per_thread_scratch_size)
380 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wud95aa2b2014-08-29 12:07:47 +0800381}
382
Chia-I Wu62a7f252014-08-29 11:31:16 +0800383static void gen7_3DSTATE_GS(struct intel_cmd *cmd)
384{
Cody Northrop293d4502015-05-05 09:38:03 -0600385 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
386 const struct intel_pipeline_shader *gs = &pipeline->gs;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800387 const uint8_t cmd_len = 7;
Cody Northrop293d4502015-05-05 09:38:03 -0600388 uint32_t dw0, dw2, dw4, dw5, dw6, *dw;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800389 CMD_ASSERT(cmd, 7, 7.5);
Cody Northrop293d4502015-05-05 09:38:03 -0600390 int vue_read_len = 0;
391 int pos = 0;
Chia-I Wu62a7f252014-08-29 11:31:16 +0800392
Cody Northrop293d4502015-05-05 09:38:03 -0600393 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (cmd_len - 2);
394
395 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
396
397 // based on upload_gs_state
398 dw2 = (gs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
399 gs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
400
401 vue_read_len = (gs->in_count + 1) / 2;
402 if (!vue_read_len)
403 vue_read_len = 1;
404
405 dw4 = (gs->output_size_hwords * 2 - 1) << GEN7_GS_DW4_OUTPUT_SIZE__SHIFT |
406 gs->output_topology << GEN7_GS_DW4_OUTPUT_TOPO__SHIFT |
407 vue_read_len << GEN7_GS_DW4_URB_READ_LEN__SHIFT |
408 0 << GEN7_GS_DW4_URB_READ_OFFSET__SHIFT |
409 gs->urb_grf_start << GEN7_GS_DW4_URB_GRF_START__SHIFT;
410
411
412 dw5 = gs->control_data_header_size_hwords << GEN7_GS_DW5_CONTROL_DATA_HEADER_SIZE__SHIFT |
413 (gs->invocations - 1) << GEN7_GS_DW5_INSTANCE_CONTROL__SHIFT |
414 GEN7_GS_DW5_STATISTICS |
415 GEN7_GS_DW5_GS_ENABLE;
416
417 dw5 |= (gs->dual_instanced_dispatch) ? GEN7_GS_DW5_DISPATCH_MODE_DUAL_INSTANCE
418 : GEN7_GS_DW5_DISPATCH_MODE_DUAL_OBJECT;
419
420 if (gs->include_primitive_id)
421 dw5 |= GEN7_GS_DW5_INCLUDE_PRIMITIVE_ID;
422
423 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
424 dw5 |= (gs->max_threads - 1) << GEN75_GS_DW5_MAX_THREADS__SHIFT;
425 dw5 |= GEN75_GS_DW5_REORDER_TRAILING;
426 dw6 = gs->control_data_format << GEN75_GS_DW6_GSCTRL__SHIFT;
427 } else {
428 dw5 |= (gs->max_threads - 1) << GEN7_GS_DW5_MAX_THREADS__SHIFT;
429 dw5 |= gs->control_data_format << GEN7_GS_DW5_GSCTRL__SHIFT;
430 dw6 = 0;
431 }
432 } else {
433 dw2 = 0;
434 dw4 = 0;
435 dw5 = GEN7_GS_DW5_STATISTICS;
436 dw6 = 0;
437 }
438
439 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800440 dw[0] = dw0;
Cody Northrop293d4502015-05-05 09:38:03 -0600441 dw[1] = cmd->bind.pipeline.gs_offset;
442 dw[2] = dw2;
Chia-I Wu72292b72014-09-09 10:48:33 +0800443 dw[3] = 0;
Cody Northrop293d4502015-05-05 09:38:03 -0600444 dw[4] = dw4;
445 dw[5] = dw5;
446 dw[6] = dw6;
447
448 if (gs->per_thread_scratch_size)
449 gen6_add_scratch_space(cmd, pos + 3, pipeline, gs);
Chia-I Wu62a7f252014-08-29 11:31:16 +0800450}
451
Chia-I Wud88e02d2014-08-25 10:56:13 +0800452static void gen6_3DSTATE_DRAWING_RECTANGLE(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600453 uint32_t width, uint32_t height)
Chia-I Wud88e02d2014-08-25 10:56:13 +0800454{
455 const uint8_t cmd_len = 4;
Chia-I Wu426072d2014-08-26 14:31:55 +0800456 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) |
Chia-I Wud88e02d2014-08-25 10:56:13 +0800457 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800458 uint32_t *dw;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800459
460 CMD_ASSERT(cmd, 6, 7.5);
461
Chia-I Wu72292b72014-09-09 10:48:33 +0800462 cmd_batch_pointer(cmd, cmd_len, &dw);
463 dw[0] = dw0;
464
Chia-I Wud88e02d2014-08-25 10:56:13 +0800465 if (width && height) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800466 dw[1] = 0;
467 dw[2] = (height - 1) << 16 |
468 (width - 1);
Chia-I Wud88e02d2014-08-25 10:56:13 +0800469 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +0800470 dw[1] = 1;
471 dw[2] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800472 }
Chia-I Wu72292b72014-09-09 10:48:33 +0800473
474 dw[3] = 0;
Chia-I Wud88e02d2014-08-25 10:56:13 +0800475}
476
Chia-I Wu8016a172014-08-29 18:31:32 +0800477static void gen7_fill_3DSTATE_SF_body(const struct intel_cmd *cmd,
478 uint32_t body[6])
479{
480 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu9e81ebb2015-07-09 10:16:34 +0800481 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +0800482 const struct intel_render_pass_subpass *subpass =
483 cmd->bind.render_pass_subpass;
Cody Northrope4bc6942015-08-26 10:01:32 -0600484 const struct intel_dynamic_line_width *line_width = cmd->bind.state.line_width;
485 const struct intel_dynamic_depth_bias *depth_bias = cmd->bind.state.depth_bias;
Cody Northropf5bd2252015-08-17 11:10:49 -0600486 uint32_t dw1, dw2, dw3, dw4, dw5, dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800487
488 CMD_ASSERT(cmd, 6, 7.5);
489
490 dw1 = GEN7_SF_DW1_STATISTICS |
491 GEN7_SF_DW1_DEPTH_OFFSET_SOLID |
492 GEN7_SF_DW1_DEPTH_OFFSET_WIREFRAME |
493 GEN7_SF_DW1_DEPTH_OFFSET_POINT |
494 GEN7_SF_DW1_VIEWPORT_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700495 pipeline->cmd_sf_fill;
Chia-I Wu8016a172014-08-29 18:31:32 +0800496
497 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wubdeed152015-07-09 12:16:29 +0800498 int format = GEN6_ZFORMAT_D32_FLOAT;
Chia-I Wu8016a172014-08-29 18:31:32 +0800499
Chia-I Wubdeed152015-07-09 12:16:29 +0800500 if (subpass->ds_index < rp->attachment_count) {
501 switch (rp->attachments[subpass->ds_index].format) {
502 case VK_FORMAT_D16_UNORM:
503 format = GEN6_ZFORMAT_D16_UNORM;
504 break;
505 case VK_FORMAT_D32_SFLOAT:
506 case VK_FORMAT_D32_SFLOAT_S8_UINT:
507 format = GEN6_ZFORMAT_D32_FLOAT;
508 break;
509 default:
510 assert(!"unsupported depth/stencil format");
511 break;
512 }
Chia-I Wu8016a172014-08-29 18:31:32 +0800513 }
514
515 dw1 |= format << GEN7_SF_DW1_DEPTH_FORMAT__SHIFT;
516 }
517
Tony Barbourfa6cac72015-01-16 14:27:35 -0700518 dw2 = pipeline->cmd_sf_cull;
Chia-I Wu8016a172014-08-29 18:31:32 +0800519
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -0700520 /* Scissor is always enabled */
521 dw2 |= GEN7_SF_DW2_SCISSOR_ENABLE;
522
Cody Northropf5bd2252015-08-17 11:10:49 -0600523 // TODO: line width support
Cody Northrope4bc6942015-08-26 10:01:32 -0600524 (void) line_width;
Cody Northropf5bd2252015-08-17 11:10:49 -0600525
Tony Barbourfa6cac72015-01-16 14:27:35 -0700526 if (pipeline->sample_count > 1) {
Chia-I Wu8016a172014-08-29 18:31:32 +0800527 dw2 |= 128 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
528 GEN7_SF_DW2_MSRASTMODE_ON_PATTERN;
529 } else {
530 dw2 |= 0 << GEN7_SF_DW2_LINE_WIDTH__SHIFT |
531 GEN7_SF_DW2_MSRASTMODE_OFF_PIXEL;
532 }
533
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600534 dw3 = 2 << GEN7_SF_DW3_TRI_PROVOKE__SHIFT |
535 1 << GEN7_SF_DW3_LINE_PROVOKE__SHIFT |
536 2 << GEN7_SF_DW3_TRIFAN_PROVOKE__SHIFT |
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800537 GEN7_SF_DW3_SUBPIXEL_8BITS;
538
Cody Northropf5bd2252015-08-17 11:10:49 -0600539 if (pipeline->depthBiasEnable) {
Cody Northrope4bc6942015-08-26 10:01:32 -0600540 dw4 = u_fui((float) depth_bias->depth_bias_info.depthBias * 2.0f);
541 dw5 = u_fui(depth_bias->depth_bias_info.slopeScaledDepthBias);
542 dw6 = u_fui(depth_bias->depth_bias_info.depthBiasClamp);
Cody Northropf5bd2252015-08-17 11:10:49 -0600543 } else {
544 dw4 = 0;
545 dw5 = 0;
546 dw6 = 0;
547 }
548
Chia-I Wu8016a172014-08-29 18:31:32 +0800549 body[0] = dw1;
550 body[1] = dw2;
551 body[2] = dw3;
Cody Northropf5bd2252015-08-17 11:10:49 -0600552 body[3] = dw4;
553 body[4] = dw5;
554 body[5] = dw6;
Chia-I Wu8016a172014-08-29 18:31:32 +0800555}
556
Chia-I Wu8016a172014-08-29 18:31:32 +0800557static void gen6_3DSTATE_SF(struct intel_cmd *cmd)
558{
559 const uint8_t cmd_len = 20;
560 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
561 (cmd_len - 2);
Chia-I Wuf85def42015-01-29 00:34:24 +0800562 const uint32_t *sbe = cmd->bind.pipeline.graphics->cmd_3dstate_sbe;
Chia-I Wu8016a172014-08-29 18:31:32 +0800563 uint32_t sf[6];
Chia-I Wu72292b72014-09-09 10:48:33 +0800564 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800565
566 CMD_ASSERT(cmd, 6, 6);
567
568 gen7_fill_3DSTATE_SF_body(cmd, sf);
Chia-I Wu8016a172014-08-29 18:31:32 +0800569
Chia-I Wu72292b72014-09-09 10:48:33 +0800570 cmd_batch_pointer(cmd, cmd_len, &dw);
571 dw[0] = dw0;
Chia-I Wuf85def42015-01-29 00:34:24 +0800572 dw[1] = sbe[1];
Chia-I Wu72292b72014-09-09 10:48:33 +0800573 memcpy(&dw[2], sf, sizeof(sf));
Chia-I Wuf85def42015-01-29 00:34:24 +0800574 memcpy(&dw[8], &sbe[2], 12);
Chia-I Wu8016a172014-08-29 18:31:32 +0800575}
576
577static void gen7_3DSTATE_SF(struct intel_cmd *cmd)
578{
579 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800580 uint32_t *dw;
Chia-I Wu8016a172014-08-29 18:31:32 +0800581
582 CMD_ASSERT(cmd, 7, 7.5);
583
Chia-I Wu72292b72014-09-09 10:48:33 +0800584 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu8016a172014-08-29 18:31:32 +0800585 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) |
586 (cmd_len - 2);
587 gen7_fill_3DSTATE_SF_body(cmd, &dw[1]);
Chia-I Wu8016a172014-08-29 18:31:32 +0800588}
589
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800590static void gen6_3DSTATE_CLIP(struct intel_cmd *cmd)
591{
592 const uint8_t cmd_len = 4;
593 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) |
594 (cmd_len - 2);
595 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
GregFfd4c1f92014-11-07 15:32:52 -0700596 const struct intel_pipeline_shader *vs = &pipeline->vs;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800597 const struct intel_pipeline_shader *fs = &pipeline->fs;
Tony Barbourde4124d2015-07-03 10:33:54 -0600598 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +0800599 uint32_t dw1, dw2, dw3, *dw;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800600
601 CMD_ASSERT(cmd, 6, 7.5);
602
603 dw1 = GEN6_CLIP_DW1_STATISTICS;
604 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
605 dw1 |= GEN7_CLIP_DW1_SUBPIXEL_8BITS |
606 GEN7_CLIP_DW1_EARLY_CULL_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -0700607 pipeline->cmd_clip_cull;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800608 }
609
610 dw2 = GEN6_CLIP_DW2_CLIP_ENABLE |
Chia-I Wue2504cb2015-04-22 14:20:52 +0800611 GEN6_CLIP_DW2_APIMODE_D3D | /* depth range [0, 1] */
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800612 GEN6_CLIP_DW2_XY_TEST_ENABLE |
GregFfd4c1f92014-11-07 15:32:52 -0700613 (vs->enable_user_clip ? 1 : 0) << GEN6_CLIP_DW2_UCP_CLIP_ENABLES__SHIFT |
Courtney Goeltzenleuchter80926f72015-07-12 15:08:32 -0600614 2 << GEN6_CLIP_DW2_TRI_PROVOKE__SHIFT |
615 1 << GEN6_CLIP_DW2_LINE_PROVOKE__SHIFT |
616 2 << GEN6_CLIP_DW2_TRIFAN_PROVOKE__SHIFT;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800617
618 if (pipeline->rasterizerDiscardEnable)
619 dw2 |= GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
620 else
621 dw2 |= GEN6_CLIP_DW2_CLIPMODE_NORMAL;
622
623 if (pipeline->depthClipEnable)
624 dw2 |= GEN6_CLIP_DW2_Z_TEST_ENABLE;
625
626 if (fs->barycentric_interps & (GEN6_INTERP_NONPERSPECTIVE_PIXEL |
627 GEN6_INTERP_NONPERSPECTIVE_CENTROID |
628 GEN6_INTERP_NONPERSPECTIVE_SAMPLE))
629 dw2 |= GEN6_CLIP_DW2_NONPERSPECTIVE_BARYCENTRIC_ENABLE;
630
631 dw3 = 0x1 << GEN6_CLIP_DW3_MIN_POINT_WIDTH__SHIFT |
632 0x7ff << GEN6_CLIP_DW3_MAX_POINT_WIDTH__SHIFT |
633 (viewport->viewport_count - 1);
634
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600635 /* TODO: framebuffer requests layer_count > 1 */
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -0600636 if (cmd->bind.fb->array_size == 1) {
Mark Lobodzinski71fcc2d2015-01-27 13:24:03 -0600637 dw3 |= GEN6_CLIP_DW3_RTAINDEX_FORCED_ZERO;
638 }
639
Chia-I Wu72292b72014-09-09 10:48:33 +0800640 cmd_batch_pointer(cmd, cmd_len, &dw);
641 dw[0] = dw0;
642 dw[1] = dw1;
643 dw[2] = dw2;
644 dw[3] = dw3;
Chia-I Wuc3f9c092014-08-30 14:29:29 +0800645}
646
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800647static void gen6_3DSTATE_WM(struct intel_cmd *cmd)
648{
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800649 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800650 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800651 const uint8_t cmd_len = 9;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600652 uint32_t pos;
Cody Northrope86574e2015-02-24 14:15:29 -0700653 uint32_t dw0, dw2, dw4, dw5, dw6, dw8, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800654
655 CMD_ASSERT(cmd, 6, 6);
656
657 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
658
659 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
660 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
661
662 dw4 = GEN6_WM_DW4_STATISTICS |
663 fs->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT |
664 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700665 fs->urb_grf_start_16 << GEN6_WM_DW4_URB_GRF_START2__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800666
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800667 dw5 = (fs->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700668 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
669 GEN6_PS_DISPATCH_8 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800670
Cody Northrope86574e2015-02-24 14:15:29 -0700671 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700672 dw5 |= GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700673
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800674 if (fs->uses & INTEL_SHADER_USE_KILL ||
675 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700676 dw5 |= GEN6_WM_DW5_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800677
Cody Northrope238deb2015-01-26 14:41:36 -0700678 if (fs->computed_depth_mode)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800679 dw5 |= GEN6_WM_DW5_PS_COMPUTE_DEPTH;
680 if (fs->uses & INTEL_SHADER_USE_DEPTH)
681 dw5 |= GEN6_WM_DW5_PS_USE_DEPTH;
682 if (fs->uses & INTEL_SHADER_USE_W)
683 dw5 |= GEN6_WM_DW5_PS_USE_W;
684
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700685 if (pipeline->dual_source_blend_enable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700686 dw5 |= GEN6_WM_DW5_PS_DUAL_SOURCE_BLEND;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800687
688 dw6 = fs->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700689 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800690 GEN6_WM_DW6_ZW_INTERP_PIXEL |
691 fs->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
692 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
693
Tony Barbourfa6cac72015-01-16 14:27:35 -0700694 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800695 dw6 |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
696 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
697 } else {
698 dw6 |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
699 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
700 }
701
Cody Northrope86574e2015-02-24 14:15:29 -0700702 dw8 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
703
Chia-I Wu784d3042014-12-19 14:30:04 +0800704 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800705 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800706 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800707 dw[2] = dw2;
708 dw[3] = 0; /* scratch */
709 dw[4] = dw4;
710 dw[5] = dw5;
711 dw[6] = dw6;
712 dw[7] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700713 dw[8] = dw8; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800714
715 if (fs->per_thread_scratch_size)
716 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800717}
718
719static void gen7_3DSTATE_WM(struct intel_cmd *cmd)
720{
721 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800722 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800723 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800724 uint32_t dw0, dw1, dw2, *dw;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800725
726 CMD_ASSERT(cmd, 7, 7.5);
727
728 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (cmd_len - 2);
729
730 dw1 = GEN7_WM_DW1_STATISTICS |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700731 GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800732 GEN7_WM_DW1_ZW_INTERP_PIXEL |
733 fs->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
734 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
735
736 if (fs->uses & INTEL_SHADER_USE_KILL ||
737 pipeline->cb_state.alphaToCoverageEnable)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700738 dw1 |= GEN7_WM_DW1_PS_KILL_PIXEL;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800739
Cody Northrope238deb2015-01-26 14:41:36 -0700740 dw1 |= fs->computed_depth_mode << GEN7_WM_DW1_PSCDEPTH__SHIFT;
741
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800742 if (fs->uses & INTEL_SHADER_USE_DEPTH)
743 dw1 |= GEN7_WM_DW1_PS_USE_DEPTH;
744 if (fs->uses & INTEL_SHADER_USE_W)
745 dw1 |= GEN7_WM_DW1_PS_USE_W;
746
747 dw2 = 0;
748
Tony Barbourfa6cac72015-01-16 14:27:35 -0700749 if (pipeline->sample_count > 1) {
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800750 dw1 |= GEN7_WM_DW1_MSRASTMODE_ON_PATTERN;
751 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERPIXEL;
752 } else {
753 dw1 |= GEN7_WM_DW1_MSRASTMODE_OFF_PIXEL;
754 dw2 |= GEN7_WM_DW2_MSDISPMODE_PERSAMPLE;
755 }
756
Chia-I Wu72292b72014-09-09 10:48:33 +0800757 cmd_batch_pointer(cmd, cmd_len, &dw);
758 dw[0] = dw0;
759 dw[1] = dw1;
760 dw[2] = dw2;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800761}
762
763static void gen7_3DSTATE_PS(struct intel_cmd *cmd)
764{
765 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800766 const struct intel_pipeline_shader *fs = &pipeline->fs;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800767 const uint8_t cmd_len = 8;
Cody Northrope86574e2015-02-24 14:15:29 -0700768 uint32_t dw0, dw2, dw4, dw5, dw7, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600769 uint32_t pos;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800770
771 CMD_ASSERT(cmd, 7, 7.5);
772
773 dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (cmd_len - 2);
774
775 dw2 = (fs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
776 fs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
777
778 dw4 = GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700779 GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800780
Cody Northrope86574e2015-02-24 14:15:29 -0700781 if (fs->offset_16)
Chia-I Wu97aa4de2015-03-05 15:43:16 -0700782 dw4 |= GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Cody Northrope86574e2015-02-24 14:15:29 -0700783
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800784 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800785 dw4 |= (fs->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700786 dw4 |= pipeline->cmd_sample_mask << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800787 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +0800788 dw4 |= (fs->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800789 }
790
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800791 if (fs->in_count)
792 dw4 |= GEN7_PS_DW4_ATTR_ENABLE;
793
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700794 if (pipeline->dual_source_blend_enable)
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800795 dw4 |= GEN7_PS_DW4_DUAL_SOURCE_BLEND;
796
797 dw5 = fs->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT |
798 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT |
Cody Northrope86574e2015-02-24 14:15:29 -0700799 fs->urb_grf_start_16 << GEN7_PS_DW5_URB_GRF_START2__SHIFT;
800
801 dw7 = (fs->offset_16) ? cmd->bind.pipeline.fs_offset + fs->offset_16 : 0;
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800802
Chia-I Wu784d3042014-12-19 14:30:04 +0800803 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +0800804 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +0800805 dw[1] = cmd->bind.pipeline.fs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +0800806 dw[2] = dw2;
807 dw[3] = 0; /* scratch */
808 dw[4] = dw4;
809 dw[5] = dw5;
810 dw[6] = 0; /* kernel 1 */
Cody Northrope86574e2015-02-24 14:15:29 -0700811 dw[7] = dw7; /* kernel 2 */
Chia-I Wu784d3042014-12-19 14:30:04 +0800812
813 if (fs->per_thread_scratch_size)
814 gen6_add_scratch_space(cmd, pos + 3, pipeline, fs);
Chia-I Wu1f2fd292014-08-29 15:07:09 +0800815}
816
Chia-I Wu8ada4242015-03-02 11:19:33 -0700817static void gen6_3DSTATE_MULTISAMPLE(struct intel_cmd *cmd,
818 uint32_t sample_count)
819{
820 const uint8_t cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 3;
821 uint32_t dw1, dw2, dw3, *dw;
822
823 CMD_ASSERT(cmd, 6, 7.5);
824
825 switch (sample_count) {
826 case 4:
827 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
828 dw2 = cmd->dev->sample_pattern_4x;
829 dw3 = 0;
830 break;
831 case 8:
832 assert(cmd_gen(cmd) >= INTEL_GEN(7));
833 dw1 = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
834 dw2 = cmd->dev->sample_pattern_8x[0];
835 dw3 = cmd->dev->sample_pattern_8x[1];
836 break;
837 default:
838 assert(sample_count <= 1);
839 dw1 = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
840 dw2 = 0;
841 dw3 = 0;
842 break;
843 }
844
845 cmd_batch_pointer(cmd, cmd_len, &dw);
846
847 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (cmd_len - 2);
848 dw[1] = dw1;
849 dw[2] = dw2;
850 if (cmd_gen(cmd) >= INTEL_GEN(7))
851 dw[3] = dw3;
852}
853
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800854static void gen6_3DSTATE_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800855 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700856 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800857{
858 const uint8_t cmd_len = 7;
Chia-I Wu72292b72014-09-09 10:48:33 +0800859 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600860 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800861
862 CMD_ASSERT(cmd, 6, 7.5);
863
864 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800865 GEN7_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER) :
866 GEN6_RENDER_CMD(3D, 3DSTATE_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800867 dw0 |= (cmd_len - 2);
868
Chia-I Wu72292b72014-09-09 10:48:33 +0800869 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
870 dw[0] = dw0;
Chia-I Wu73520ac2015-02-19 11:17:45 -0700871
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800872 dw[1] = view->att_cmd[0];
Chia-I Wu73520ac2015-02-19 11:17:45 -0700873 /* note that we only enable HiZ on Gen7+ */
874 if (!optimal_ds)
875 dw[1] &= ~GEN7_DEPTH_DW1_HIZ_ENABLE;
876
Chia-I Wu72292b72014-09-09 10:48:33 +0800877 dw[2] = 0;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800878 dw[3] = view->att_cmd[2];
879 dw[4] = view->att_cmd[3];
880 dw[5] = view->att_cmd[4];
881 dw[6] = view->att_cmd[5];
Chia-I Wu72292b72014-09-09 10:48:33 +0800882
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600883 if (view->img) {
Chia-I Wu72292b72014-09-09 10:48:33 +0800884 cmd_reserve_reloc(cmd, 1);
885 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800886 view->att_cmd[1], INTEL_RELOC_WRITE);
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600887 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800888}
889
890static void gen6_3DSTATE_STENCIL_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800891 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700892 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800893{
894 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800895 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600896 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800897
898 CMD_ASSERT(cmd, 6, 7.5);
899
900 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800901 GEN7_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER) :
902 GEN6_RENDER_CMD(3D, 3DSTATE_STENCIL_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800903 dw0 |= (cmd_len - 2);
904
Chia-I Wu72292b72014-09-09 10:48:33 +0800905 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
906 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800907
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700908 if (view->has_stencil) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800909 dw[1] = view->att_cmd[6];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700910
Chia-I Wu72292b72014-09-09 10:48:33 +0800911 cmd_reserve_reloc(cmd, 1);
912 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800913 view->att_cmd[7], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700914 } else {
915 dw[1] = 0;
916 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600917 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800918}
919
920static void gen6_3DSTATE_HIER_DEPTH_BUFFER(struct intel_cmd *cmd,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800921 const struct intel_att_view *view,
Chia-I Wu73520ac2015-02-19 11:17:45 -0700922 bool optimal_ds)
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800923{
924 const uint8_t cmd_len = 3;
Chia-I Wu72292b72014-09-09 10:48:33 +0800925 uint32_t dw0, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600926 uint32_t pos;
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800927
928 CMD_ASSERT(cmd, 6, 7.5);
929
930 dw0 = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu426072d2014-08-26 14:31:55 +0800931 GEN7_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER) :
932 GEN6_RENDER_CMD(3D, 3DSTATE_HIER_DEPTH_BUFFER);
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800933 dw0 |= (cmd_len - 2);
934
Chia-I Wu72292b72014-09-09 10:48:33 +0800935 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
936 dw[0] = dw0;
Chia-I Wu72292b72014-09-09 10:48:33 +0800937
Chia-I Wu73520ac2015-02-19 11:17:45 -0700938 if (view->has_hiz && optimal_ds) {
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800939 dw[1] = view->att_cmd[8];
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700940
Chia-I Wu72292b72014-09-09 10:48:33 +0800941 cmd_reserve_reloc(cmd, 1);
942 cmd_batch_reloc(cmd, pos + 2, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +0800943 view->att_cmd[9], INTEL_RELOC_WRITE);
Chia-I Wu3defd1f2015-02-18 12:21:22 -0700944 } else {
945 dw[1] = 0;
946 dw[2] = 0;
Courtney Goeltzenleuchtere316d972014-08-22 16:25:24 -0600947 }
Chia-I Wu7fae4e32014-08-21 11:39:44 +0800948}
949
Chia-I Wuf8231032014-08-25 10:44:45 +0800950static void gen6_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
951 uint32_t clear_val)
952{
953 const uint8_t cmd_len = 2;
Chia-I Wu426072d2014-08-26 14:31:55 +0800954 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800955 GEN6_CLEAR_PARAMS_DW0_VALID |
956 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800957 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800958
959 CMD_ASSERT(cmd, 6, 6);
960
Chia-I Wu72292b72014-09-09 10:48:33 +0800961 cmd_batch_pointer(cmd, cmd_len, &dw);
962 dw[0] = dw0;
963 dw[1] = clear_val;
Chia-I Wuf8231032014-08-25 10:44:45 +0800964}
965
966static void gen7_3DSTATE_CLEAR_PARAMS(struct intel_cmd *cmd,
967 uint32_t clear_val)
968{
969 const uint8_t cmd_len = 3;
Chia-I Wu426072d2014-08-26 14:31:55 +0800970 const uint32_t dw0 = GEN7_RENDER_CMD(3D, 3DSTATE_CLEAR_PARAMS) |
Chia-I Wuf8231032014-08-25 10:44:45 +0800971 (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +0800972 uint32_t *dw;
Chia-I Wuf8231032014-08-25 10:44:45 +0800973
974 CMD_ASSERT(cmd, 7, 7.5);
975
Chia-I Wu72292b72014-09-09 10:48:33 +0800976 cmd_batch_pointer(cmd, cmd_len, &dw);
977 dw[0] = dw0;
978 dw[1] = clear_val;
979 dw[2] = 1;
Chia-I Wuf8231032014-08-25 10:44:45 +0800980}
981
Chia-I Wu302742d2014-08-22 10:28:29 +0800982static void gen6_3DSTATE_CC_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +0800983 uint32_t blend_offset,
984 uint32_t ds_offset,
985 uint32_t cc_offset)
Chia-I Wu302742d2014-08-22 10:28:29 +0800986{
987 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +0800988 uint32_t dw0, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +0800989
990 CMD_ASSERT(cmd, 6, 6);
991
Chia-I Wu426072d2014-08-26 14:31:55 +0800992 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_CC_STATE_POINTERS) |
Chia-I Wu302742d2014-08-22 10:28:29 +0800993 (cmd_len - 2);
994
Chia-I Wu72292b72014-09-09 10:48:33 +0800995 cmd_batch_pointer(cmd, cmd_len, &dw);
996 dw[0] = dw0;
997 dw[1] = blend_offset | 1;
998 dw[2] = ds_offset | 1;
999 dw[3] = cc_offset | 1;
Chia-I Wu302742d2014-08-22 10:28:29 +08001000}
1001
Chia-I Wu1744cca2014-08-22 11:10:17 +08001002static void gen6_3DSTATE_VIEWPORT_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001003 uint32_t clip_offset,
1004 uint32_t sf_offset,
1005 uint32_t cc_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001006{
1007 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001008 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001009
1010 CMD_ASSERT(cmd, 6, 6);
1011
Chia-I Wu426072d2014-08-26 14:31:55 +08001012 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001013 GEN6_VP_PTR_DW0_CLIP_CHANGED |
1014 GEN6_VP_PTR_DW0_SF_CHANGED |
1015 GEN6_VP_PTR_DW0_CC_CHANGED |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001016 (cmd_len - 2);
1017
Chia-I Wu72292b72014-09-09 10:48:33 +08001018 cmd_batch_pointer(cmd, cmd_len, &dw);
1019 dw[0] = dw0;
1020 dw[1] = clip_offset;
1021 dw[2] = sf_offset;
1022 dw[3] = cc_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001023}
1024
1025static void gen6_3DSTATE_SCISSOR_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001026 uint32_t scissor_offset)
Chia-I Wu1744cca2014-08-22 11:10:17 +08001027{
1028 const uint8_t cmd_len = 2;
Chia-I Wu72292b72014-09-09 10:48:33 +08001029 uint32_t dw0, *dw;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001030
1031 CMD_ASSERT(cmd, 6, 6);
1032
Chia-I Wu426072d2014-08-26 14:31:55 +08001033 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SCISSOR_STATE_POINTERS) |
Chia-I Wu1744cca2014-08-22 11:10:17 +08001034 (cmd_len - 2);
1035
Chia-I Wu72292b72014-09-09 10:48:33 +08001036 cmd_batch_pointer(cmd, cmd_len, &dw);
1037 dw[0] = dw0;
1038 dw[1] = scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001039}
1040
Chia-I Wu42a56202014-08-23 16:47:48 +08001041static void gen6_3DSTATE_BINDING_TABLE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001042 uint32_t vs_offset,
1043 uint32_t gs_offset,
1044 uint32_t ps_offset)
Chia-I Wu42a56202014-08-23 16:47:48 +08001045{
1046 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001047 uint32_t dw0, *dw;
Chia-I Wu42a56202014-08-23 16:47:48 +08001048
1049 CMD_ASSERT(cmd, 6, 6);
1050
Chia-I Wu426072d2014-08-26 14:31:55 +08001051 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_BINDING_TABLE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001052 GEN6_BINDING_TABLE_PTR_DW0_VS_CHANGED |
1053 GEN6_BINDING_TABLE_PTR_DW0_GS_CHANGED |
1054 GEN6_BINDING_TABLE_PTR_DW0_PS_CHANGED |
Chia-I Wu42a56202014-08-23 16:47:48 +08001055 (cmd_len - 2);
1056
Chia-I Wu72292b72014-09-09 10:48:33 +08001057 cmd_batch_pointer(cmd, cmd_len, &dw);
1058 dw[0] = dw0;
1059 dw[1] = vs_offset;
1060 dw[2] = gs_offset;
1061 dw[3] = ps_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001062}
1063
Chia-I Wu257e75e2014-08-29 14:06:35 +08001064static void gen6_3DSTATE_SAMPLER_STATE_POINTERS(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001065 uint32_t vs_offset,
1066 uint32_t gs_offset,
1067 uint32_t ps_offset)
Chia-I Wu257e75e2014-08-29 14:06:35 +08001068{
1069 const uint8_t cmd_len = 4;
Chia-I Wu72292b72014-09-09 10:48:33 +08001070 uint32_t dw0, *dw;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001071
1072 CMD_ASSERT(cmd, 6, 6);
1073
1074 dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLER_STATE_POINTERS) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001075 GEN6_SAMPLER_PTR_DW0_VS_CHANGED |
1076 GEN6_SAMPLER_PTR_DW0_GS_CHANGED |
1077 GEN6_SAMPLER_PTR_DW0_PS_CHANGED |
Chia-I Wu257e75e2014-08-29 14:06:35 +08001078 (cmd_len - 2);
1079
Chia-I Wu72292b72014-09-09 10:48:33 +08001080 cmd_batch_pointer(cmd, cmd_len, &dw);
1081 dw[0] = dw0;
1082 dw[1] = vs_offset;
1083 dw[2] = gs_offset;
1084 dw[3] = ps_offset;
Chia-I Wu257e75e2014-08-29 14:06:35 +08001085}
1086
Chia-I Wu302742d2014-08-22 10:28:29 +08001087static void gen7_3dstate_pointer(struct intel_cmd *cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001088 int subop, uint32_t offset)
Chia-I Wu302742d2014-08-22 10:28:29 +08001089{
1090 const uint8_t cmd_len = 2;
1091 const uint32_t dw0 = GEN6_RENDER_TYPE_RENDER |
1092 GEN6_RENDER_SUBTYPE_3D |
1093 subop | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001094 uint32_t *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001095
Chia-I Wu72292b72014-09-09 10:48:33 +08001096 cmd_batch_pointer(cmd, cmd_len, &dw);
1097 dw[0] = dw0;
1098 dw[1] = offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001099}
1100
Chia-I Wua6c4f152014-12-02 04:19:58 +08001101static uint32_t gen6_BLEND_STATE(struct intel_cmd *cmd)
Chia-I Wu302742d2014-08-22 10:28:29 +08001102{
Chia-I Wue6073342014-11-30 09:43:42 +08001103 const uint8_t cmd_align = GEN6_ALIGNMENT_BLEND_STATE;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001104 const uint8_t cmd_len = INTEL_MAX_RENDER_TARGETS * 2;
1105 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu302742d2014-08-22 10:28:29 +08001106
1107 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001108 STATIC_ASSERT(ARRAY_SIZE(pipeline->cmd_cb) >= INTEL_MAX_RENDER_TARGETS);
Chia-I Wu302742d2014-08-22 10:28:29 +08001109
Tony Barbourfa6cac72015-01-16 14:27:35 -07001110 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLEND, cmd_align, cmd_len, pipeline->cmd_cb);
Chia-I Wu302742d2014-08-22 10:28:29 +08001111}
1112
Chia-I Wu72292b72014-09-09 10:48:33 +08001113static uint32_t gen6_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Cody Northrop2605cb02015-08-18 15:21:16 -06001114 const struct intel_dynamic_stencil *stencil_state)
Chia-I Wu302742d2014-08-22 10:28:29 +08001115{
Tony Barbourfa6cac72015-01-16 14:27:35 -07001116 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wue6073342014-11-30 09:43:42 +08001117 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001118 const uint8_t cmd_len = 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07001119 uint32_t dw[3];
1120
1121 dw[0] = pipeline->cmd_depth_stencil;
Cody Northrop2605cb02015-08-18 15:21:16 -06001122
1123 /* TODO: enable back facing stencil state */
Courtney Goeltzenleuchter5a054a62015-01-23 15:21:37 -07001124 /* same read and write masks for both front and back faces */
Cody Northrope4bc6942015-08-26 10:01:32 -06001125 dw[1] = (stencil_state->stencil_info_front.stencilCompareMask & 0xff) << 24 |
Cody Northrop2605cb02015-08-18 15:21:16 -06001126 (stencil_state->stencil_info_front.stencilWriteMask & 0xff) << 16 |
Cody Northrope4bc6942015-08-26 10:01:32 -06001127 (stencil_state->stencil_info_front.stencilCompareMask & 0xff) << 8 |
Cody Northrop2605cb02015-08-18 15:21:16 -06001128 (stencil_state->stencil_info_front.stencilWriteMask & 0xff);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001129 dw[2] = pipeline->cmd_depth_test;
Chia-I Wu302742d2014-08-22 10:28:29 +08001130
1131 CMD_ASSERT(cmd, 6, 7.5);
Tony Barbourfa6cac72015-01-16 14:27:35 -07001132
Cody Northrop2605cb02015-08-18 15:21:16 -06001133 if (stencil_state->stencil_info_front.stencilWriteMask && pipeline->stencilTestEnable)
Tony Barbourfa6cac72015-01-16 14:27:35 -07001134 dw[0] |= 1 << 18;
Chia-I Wu302742d2014-08-22 10:28:29 +08001135
Chia-I Wu00b51a82014-09-09 12:07:37 +08001136 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Tony Barbourfa6cac72015-01-16 14:27:35 -07001137 cmd_align, cmd_len, dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001138}
1139
Chia-I Wu72292b72014-09-09 10:48:33 +08001140static uint32_t gen6_COLOR_CALC_STATE(struct intel_cmd *cmd,
Chia-I Wu302742d2014-08-22 10:28:29 +08001141 uint32_t stencil_ref,
1142 const uint32_t blend_color[4])
1143{
Chia-I Wue6073342014-11-30 09:43:42 +08001144 const uint8_t cmd_align = GEN6_ALIGNMENT_COLOR_CALC_STATE;
Chia-I Wu302742d2014-08-22 10:28:29 +08001145 const uint8_t cmd_len = 6;
Chia-I Wu72292b72014-09-09 10:48:33 +08001146 uint32_t offset, *dw;
Chia-I Wu302742d2014-08-22 10:28:29 +08001147
1148 CMD_ASSERT(cmd, 6, 7.5);
1149
Chia-I Wu00b51a82014-09-09 12:07:37 +08001150 offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_COLOR_CALC,
1151 cmd_align, cmd_len, &dw);
Chia-I Wu302742d2014-08-22 10:28:29 +08001152 dw[0] = stencil_ref;
1153 dw[1] = 0;
1154 dw[2] = blend_color[0];
1155 dw[3] = blend_color[1];
1156 dw[4] = blend_color[2];
1157 dw[5] = blend_color[3];
Chia-I Wu302742d2014-08-22 10:28:29 +08001158
Chia-I Wu72292b72014-09-09 10:48:33 +08001159 return offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001160}
1161
Chia-I Wu8370b402014-08-29 12:28:37 +08001162static void cmd_wa_gen6_pre_depth_stall_write(struct intel_cmd *cmd)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001163{
Chia-I Wu8370b402014-08-29 12:28:37 +08001164 CMD_ASSERT(cmd, 6, 7.5);
1165
Chia-I Wu707a29e2014-08-27 12:51:47 +08001166 if (!cmd->bind.draw_count)
1167 return;
1168
Chia-I Wu8370b402014-08-29 12:28:37 +08001169 if (cmd->bind.wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
Chia-I Wu48c283d2014-08-25 23:13:46 +08001170 return;
1171
Chia-I Wu8370b402014-08-29 12:28:37 +08001172 cmd->bind.wa_flags |= INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE;
Chia-I Wu48c283d2014-08-25 23:13:46 +08001173
1174 /*
1175 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1176 *
1177 * "Pipe-control with CS-stall bit set must be sent BEFORE the
1178 * pipe-control with a post-sync op and no write-cache flushes."
1179 *
1180 * The workaround below necessitates this workaround.
1181 */
1182 gen6_PIPE_CONTROL(cmd,
1183 GEN6_PIPE_CONTROL_CS_STALL |
1184 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001185 NULL, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001186
Chia-I Wud6d079d2014-08-31 13:14:21 +08001187 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_IMM,
1188 cmd->scratch_bo, 0, 0);
Chia-I Wu48c283d2014-08-25 23:13:46 +08001189}
1190
Chia-I Wu8370b402014-08-29 12:28:37 +08001191static void cmd_wa_gen6_pre_command_scoreboard_stall(struct intel_cmd *cmd)
Courtney Goeltzenleuchterf9e1a412014-08-27 13:59:36 -06001192{
Chia-I Wu48c283d2014-08-25 23:13:46 +08001193 CMD_ASSERT(cmd, 6, 7.5);
1194
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001195 if (!cmd->bind.draw_count)
1196 return;
1197
Chia-I Wud6d079d2014-08-31 13:14:21 +08001198 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
1199 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001200}
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001201
Chia-I Wu8370b402014-08-29 12:28:37 +08001202static void cmd_wa_gen7_pre_vs_depth_stall_write(struct intel_cmd *cmd)
1203{
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001204 CMD_ASSERT(cmd, 7, 7.5);
1205
Chia-I Wu8370b402014-08-29 12:28:37 +08001206 if (!cmd->bind.draw_count)
1207 return;
1208
1209 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001210
1211 gen6_PIPE_CONTROL(cmd,
1212 GEN6_PIPE_CONTROL_DEPTH_STALL | GEN6_PIPE_CONTROL_WRITE_IMM,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001213 cmd->scratch_bo, 0, 0);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08001214}
1215
Chia-I Wu8370b402014-08-29 12:28:37 +08001216static void cmd_wa_gen7_post_command_cs_stall(struct intel_cmd *cmd)
1217{
1218 CMD_ASSERT(cmd, 7, 7.5);
1219
Chia-I Wu8370b402014-08-29 12:28:37 +08001220 /*
1221 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1222 *
1223 * "One of the following must also be set (when CS stall is set):
1224 *
1225 * * Render Target Cache Flush Enable ([12] of DW1)
1226 * * Depth Cache Flush Enable ([0] of DW1)
1227 * * Stall at Pixel Scoreboard ([1] of DW1)
1228 * * Depth Stall ([13] of DW1)
1229 * * Post-Sync Operation ([13] of DW1)"
1230 */
1231 gen6_PIPE_CONTROL(cmd,
1232 GEN6_PIPE_CONTROL_CS_STALL |
1233 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001234 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001235}
1236
1237static void cmd_wa_gen7_post_command_depth_stall(struct intel_cmd *cmd)
1238{
1239 CMD_ASSERT(cmd, 7, 7.5);
1240
Chia-I Wu8370b402014-08-29 12:28:37 +08001241 cmd_wa_gen6_pre_depth_stall_write(cmd);
1242
Chia-I Wud6d079d2014-08-31 13:14:21 +08001243 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001244}
1245
1246static void cmd_wa_gen6_pre_multisample_depth_flush(struct intel_cmd *cmd)
1247{
1248 CMD_ASSERT(cmd, 6, 7.5);
1249
1250 if (!cmd->bind.draw_count)
1251 return;
1252
1253 /*
1254 * From the Sandy Bridge PRM, volume 2 part 1, page 305:
1255 *
1256 * "Driver must guarentee 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 * From the Ivy Bridge PRM, volume 2 part 1, page 304:
1262 *
1263 * "Driver must ierarchi that all the caches in the depth pipe are
1264 * flushed before this command (3DSTATE_MULTISAMPLE) is parsed. This
1265 * requires driver to send a PIPE_CONTROL with a CS stall along with
1266 * a Depth Flush prior to this command.
1267 */
1268 gen6_PIPE_CONTROL(cmd,
1269 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1270 GEN6_PIPE_CONTROL_CS_STALL,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001271 NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001272}
1273
1274static void cmd_wa_gen6_pre_ds_flush(struct intel_cmd *cmd)
1275{
1276 CMD_ASSERT(cmd, 6, 7.5);
1277
1278 if (!cmd->bind.draw_count)
1279 return;
1280
1281 /*
1282 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1283 *
1284 * "Driver must send a least one PIPE_CONTROL command with CS Stall
1285 * and a post sync operation prior to the group of depth
1286 * commands(3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1287 * 3DSTATE_STENCIL_BUFFER, and 3DSTATE_HIER_DEPTH_BUFFER)."
1288 *
1289 * This workaround satifies all the conditions.
1290 */
1291 cmd_wa_gen6_pre_depth_stall_write(cmd);
1292
1293 /*
1294 * From the Ivy Bridge PRM, volume 2 part 1, page 315:
1295 *
1296 * "Restriction: Prior to changing Depth/Stencil Buffer state (i.e.,
1297 * any combination of 3DSTATE_DEPTH_BUFFER, 3DSTATE_CLEAR_PARAMS,
1298 * 3DSTATE_STENCIL_BUFFER, 3DSTATE_HIER_DEPTH_BUFFER) SW must first
1299 * issue a pipelined depth stall (PIPE_CONTROL with Depth Stall bit
1300 * set), followed by a pipelined depth cache flush (PIPE_CONTROL with
1301 * Depth Flush Bit set, followed by another pipelined depth stall
1302 * (PIPE_CONTROL with Depth Stall Bit set), unless SW can otherwise
1303 * guarantee that the pipeline from WM onwards is already flushed
1304 * (e.g., via a preceding MI_FLUSH)."
1305 */
Chia-I Wud6d079d2014-08-31 13:14:21 +08001306 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
1307 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH, NULL, 0, 0);
1308 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_DEPTH_STALL, NULL, 0, 0);
Chia-I Wu8370b402014-08-29 12:28:37 +08001309}
1310
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001311void cmd_batch_state_base_address(struct intel_cmd *cmd)
1312{
1313 const uint8_t cmd_len = 10;
1314 const uint32_t dw0 = GEN6_RENDER_CMD(COMMON, STATE_BASE_ADDRESS) |
1315 (cmd_len - 2);
Chia-I Wub3686982015-02-27 09:51:16 -07001316 const uint32_t mocs = (cmd_gen(cmd) >= INTEL_GEN(7)) ?
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001317 (GEN7_MOCS_L3_WB << 8 | GEN7_MOCS_L3_WB << 4) : 0;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001318 uint32_t pos;
1319 uint32_t *dw;
1320
1321 CMD_ASSERT(cmd, 6, 7.5);
1322
1323 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1324
1325 dw[0] = dw0;
1326 /* start offsets */
Chia-I Wub3686982015-02-27 09:51:16 -07001327 dw[1] = mocs | 1;
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001328 dw[2] = 1;
1329 dw[3] = 1;
1330 dw[4] = 1;
1331 dw[5] = 1;
1332 /* end offsets */
1333 dw[6] = 1;
1334 dw[7] = 1 + 0xfffff000;
1335 dw[8] = 1 + 0xfffff000;
1336 dw[9] = 1;
1337
1338 cmd_reserve_reloc(cmd, 3);
Chia-I Wuf98dd882015-02-10 04:17:47 +08001339 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE,
1340 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset + 1);
1341 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE,
1342 cmd->writers[INTEL_CMD_WRITER_STATE].sba_offset + 1);
1343 cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION,
1344 cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].sba_offset + 1);
Chia-I Wu66bdcd72015-02-10 04:11:31 +08001345}
1346
Chia-I Wu7c853562015-02-27 14:35:08 -07001347void cmd_batch_push_const_alloc(struct intel_cmd *cmd)
1348{
1349 const uint32_t size = (cmd->dev->gpu->gt == 3) ? 16 : 8;
1350 const uint8_t cmd_len = 2;
1351 uint32_t offset = 0;
1352 uint32_t *dw;
1353
1354 if (cmd_gen(cmd) <= INTEL_GEN(6))
1355 return;
1356
1357 CMD_ASSERT(cmd, 7, 7.5);
1358
1359 /* 3DSTATE_PUSH_CONSTANT_ALLOC_x */
1360 cmd_batch_pointer(cmd, cmd_len * 5, &dw);
1361 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_VS) | (cmd_len - 2);
1362 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1363 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1364 offset += size;
1365
1366 dw += 2;
1367 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_PS) | (cmd_len - 2);
1368 dw[1] = offset << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1369 size << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1370
1371 dw += 2;
1372 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_HS) | (cmd_len - 2);
1373 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1374 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1375
1376 dw += 2;
1377 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_DS) | (cmd_len - 2);
1378 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1379 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1380
1381 dw += 2;
1382 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PUSH_CONSTANT_ALLOC_GS) | (cmd_len - 2);
1383 dw[1] = 0 << GEN7_PCB_ALLOC_DW1_OFFSET__SHIFT |
1384 0 << GEN7_PCB_ALLOC_DW1_SIZE__SHIFT;
1385
1386 /*
1387 *
1388 * From the Ivy Bridge PRM, volume 2 part 1, page 292:
1389 *
1390 * "A PIPE_CONTOL command with the CS Stall bit set must be programmed
1391 * in the ring after this instruction
1392 * (3DSTATE_PUSH_CONSTANT_ALLOC_PS)."
1393 */
1394 cmd_wa_gen7_post_command_cs_stall(cmd);
1395}
1396
Chia-I Wu525c6602014-08-27 10:22:34 +08001397void cmd_batch_flush(struct intel_cmd *cmd, uint32_t pipe_control_dw0)
1398{
Mike Stroyan552fda42015-01-30 17:21:08 -07001399 if (pipe_control_dw0 == 0)
1400 return;
1401
Chia-I Wu525c6602014-08-27 10:22:34 +08001402 if (!cmd->bind.draw_count)
1403 return;
1404
1405 assert(!(pipe_control_dw0 & GEN6_PIPE_CONTROL_WRITE__MASK));
1406
Chia-I Wu8370b402014-08-29 12:28:37 +08001407 /*
1408 * From the Sandy Bridge PRM, volume 2 part 1, page 60:
1409 *
1410 * "Before a PIPE_CONTROL with Write Cache Flush Enable =1, a
1411 * PIPE_CONTROL with any non-zero post-sync-op is required."
1412 */
Chia-I Wu525c6602014-08-27 10:22:34 +08001413 if (pipe_control_dw0 & GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH)
Chia-I Wu8370b402014-08-29 12:28:37 +08001414 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wu525c6602014-08-27 10:22:34 +08001415
Chia-I Wu092279a2014-08-30 19:05:30 +08001416 /*
1417 * From the Ivy Bridge PRM, volume 2 part 1, page 61:
1418 *
1419 * "One of the following must also be set (when CS stall is set):
1420 *
1421 * * Render Target Cache Flush Enable ([12] of DW1)
1422 * * Depth Cache Flush Enable ([0] of DW1)
1423 * * Stall at Pixel Scoreboard ([1] of DW1)
1424 * * Depth Stall ([13] of DW1)
1425 * * Post-Sync Operation ([13] of DW1)"
1426 */
1427 if ((pipe_control_dw0 & GEN6_PIPE_CONTROL_CS_STALL) &&
1428 !(pipe_control_dw0 & (GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1429 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1430 GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL |
1431 GEN6_PIPE_CONTROL_DEPTH_STALL)))
1432 pipe_control_dw0 |= GEN6_PIPE_CONTROL_PIXEL_SCOREBOARD_STALL;
1433
Chia-I Wud6d079d2014-08-31 13:14:21 +08001434 gen6_PIPE_CONTROL(cmd, pipe_control_dw0, NULL, 0, 0);
Chia-I Wu525c6602014-08-27 10:22:34 +08001435}
1436
Chia-I Wu3fb47ce2014-10-28 11:19:36 +08001437void cmd_batch_flush_all(struct intel_cmd *cmd)
1438{
1439 cmd_batch_flush(cmd, GEN6_PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE |
1440 GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH |
1441 GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH |
1442 GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE |
1443 GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
1444 GEN6_PIPE_CONTROL_CS_STALL);
1445}
1446
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001447void cmd_batch_depth_count(struct intel_cmd *cmd,
1448 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001449 VkDeviceSize offset)
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001450{
1451 cmd_wa_gen6_pre_depth_stall_write(cmd);
1452
1453 gen6_PIPE_CONTROL(cmd,
1454 GEN6_PIPE_CONTROL_DEPTH_STALL |
1455 GEN6_PIPE_CONTROL_WRITE_PS_DEPTH_COUNT,
Chia-I Wud6d079d2014-08-31 13:14:21 +08001456 bo, offset, 0);
Chia-I Wu759fa2e2014-08-30 18:44:47 +08001457}
1458
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001459void cmd_batch_timestamp(struct intel_cmd *cmd,
1460 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001461 VkDeviceSize offset)
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001462{
1463 /* need any WA or stall? */
1464 gen6_PIPE_CONTROL(cmd, GEN6_PIPE_CONTROL_WRITE_TIMESTAMP, bo, offset, 0);
1465}
1466
1467void cmd_batch_immediate(struct intel_cmd *cmd,
Mike Stroyan55658c22014-12-04 11:08:39 +00001468 uint32_t pipe_control_flags,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001469 struct intel_bo *bo,
Tony Barbour8205d902015-04-16 15:59:00 -06001470 VkDeviceSize offset,
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001471 uint64_t val)
1472{
1473 /* need any WA or stall? */
Mike Stroyan55658c22014-12-04 11:08:39 +00001474 gen6_PIPE_CONTROL(cmd,
1475 GEN6_PIPE_CONTROL_WRITE_IMM | pipe_control_flags,
1476 bo, offset, val);
Chia-I Wue8dbd5d2014-08-31 13:15:58 +08001477}
1478
Chia-I Wu302742d2014-08-22 10:28:29 +08001479static void gen6_cc_states(struct intel_cmd *cmd)
1480{
Cody Northrope4bc6942015-08-26 10:01:32 -06001481 const struct intel_dynamic_blend *blend = cmd->bind.state.blend;
Cody Northrop2605cb02015-08-18 15:21:16 -06001482 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wu72292b72014-09-09 10:48:33 +08001483 uint32_t blend_offset, ds_offset, cc_offset;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001484 uint32_t stencil_ref;
1485 uint32_t blend_color[4];
Chia-I Wu302742d2014-08-22 10:28:29 +08001486
1487 CMD_ASSERT(cmd, 6, 6);
1488
Chia-I Wua6c4f152014-12-02 04:19:58 +08001489 blend_offset = gen6_BLEND_STATE(cmd);
1490
1491 if (blend)
Cody Northrope4bc6942015-08-26 10:01:32 -06001492 memcpy(blend_color, blend->blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001493 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001494 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001495
Cody Northrop2605cb02015-08-18 15:21:16 -06001496 if (ss) {
1497 ds_offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1498 /* TODO: enable back facing stencil state */
1499 /* same reference for both front and back faces */
1500 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1501 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001502 } else {
Chia-I Wu72292b72014-09-09 10:48:33 +08001503 ds_offset = 0;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001504 stencil_ref = 0;
1505 }
1506
Chia-I Wu72292b72014-09-09 10:48:33 +08001507 cc_offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001508
Chia-I Wu72292b72014-09-09 10:48:33 +08001509 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001510}
1511
Chia-I Wu1744cca2014-08-22 11:10:17 +08001512static void gen6_viewport_states(struct intel_cmd *cmd)
1513{
Tony Barbourde4124d2015-07-03 10:33:54 -06001514 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wub1d450a2014-09-09 13:48:03 +08001515 uint32_t sf_offset, clip_offset, cc_offset, scissor_offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001516
1517 if (!viewport)
1518 return;
1519
Tony Barbourfa6cac72015-01-16 14:27:35 -07001520 assert(viewport->cmd_len == (8 + 4 + 2) *
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001521 /* viewports */ viewport->viewport_count + (/* scissor */ viewport->viewport_count * 2));
Chia-I Wub1d450a2014-09-09 13:48:03 +08001522
1523 sf_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001524 GEN6_ALIGNMENT_SF_VIEWPORT, 8 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001525 viewport->cmd);
1526
1527 clip_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CLIP_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001528 GEN6_ALIGNMENT_CLIP_VIEWPORT, 4 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001529 &viewport->cmd[viewport->cmd_clip_pos]);
1530
1531 cc_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001532 GEN6_ALIGNMENT_SF_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001533 &viewport->cmd[viewport->cmd_cc_pos]);
1534
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001535 scissor_offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1536 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1537 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001538
1539 gen6_3DSTATE_VIEWPORT_STATE_POINTERS(cmd,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001540 clip_offset, sf_offset, cc_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001541
Chia-I Wub1d450a2014-09-09 13:48:03 +08001542 gen6_3DSTATE_SCISSOR_STATE_POINTERS(cmd, scissor_offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001543}
1544
Chia-I Wu302742d2014-08-22 10:28:29 +08001545static void gen7_cc_states(struct intel_cmd *cmd)
1546{
Cody Northrope4bc6942015-08-26 10:01:32 -06001547 const struct intel_dynamic_blend *blend = cmd->bind.state.blend;
1548 const struct intel_dynamic_depth_bounds *ds = cmd->bind.state.depth_bounds;
Cody Northrop2605cb02015-08-18 15:21:16 -06001549 const struct intel_dynamic_stencil *ss = cmd->bind.state.stencil;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001550 uint32_t stencil_ref;
1551 uint32_t blend_color[4];
Chia-I Wu72292b72014-09-09 10:48:33 +08001552 uint32_t offset;
Chia-I Wu302742d2014-08-22 10:28:29 +08001553
1554 CMD_ASSERT(cmd, 7, 7.5);
1555
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001556 if (!blend && !ds)
1557 return;
Chia-I Wu302742d2014-08-22 10:28:29 +08001558
Chia-I Wua6c4f152014-12-02 04:19:58 +08001559 offset = gen6_BLEND_STATE(cmd);
1560 gen7_3dstate_pointer(cmd,
1561 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001562
Chia-I Wua6c4f152014-12-02 04:19:58 +08001563 if (blend)
Cody Northrope4bc6942015-08-26 10:01:32 -06001564 memcpy(blend_color, blend->blend_info.blendConst, sizeof(blend_color));
Chia-I Wua6c4f152014-12-02 04:19:58 +08001565 else
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001566 memset(blend_color, 0, sizeof(blend_color));
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001567
Cody Northrop2605cb02015-08-18 15:21:16 -06001568 if (ss) {
1569 offset = gen6_DEPTH_STENCIL_STATE(cmd, ss);
1570 /* TODO: enable back facing stencil state */
1571 /* same reference for both front and back faces */
1572 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1573 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001574 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001575 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
1576 offset);
Cody Northrop2605cb02015-08-18 15:21:16 -06001577 stencil_ref = (ss->stencil_info_front.stencilReference & 0xff) << 24 |
1578 (ss->stencil_info_front.stencilReference & 0xff) << 16;
Chia-I Wuce9f11f2014-08-22 10:38:51 +08001579 } else {
1580 stencil_ref = 0;
1581 }
1582
Chia-I Wu72292b72014-09-09 10:48:33 +08001583 offset = gen6_COLOR_CALC_STATE(cmd, stencil_ref, blend_color);
Chia-I Wu302742d2014-08-22 10:28:29 +08001584 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001585 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, offset);
Chia-I Wu302742d2014-08-22 10:28:29 +08001586}
1587
Chia-I Wu1744cca2014-08-22 11:10:17 +08001588static void gen7_viewport_states(struct intel_cmd *cmd)
1589{
Tony Barbourde4124d2015-07-03 10:33:54 -06001590 const struct intel_dynamic_viewport *viewport = cmd->bind.state.viewport;
Chia-I Wu72292b72014-09-09 10:48:33 +08001591 uint32_t offset;
Chia-I Wu1744cca2014-08-22 11:10:17 +08001592
1593 if (!viewport)
1594 return;
1595
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001596 assert(viewport->cmd_len == (16 + 2 + 2) * viewport->viewport_count);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001597
Chia-I Wub1d450a2014-09-09 13:48:03 +08001598 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SF_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001599 GEN7_ALIGNMENT_SF_CLIP_VIEWPORT, 16 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001600 viewport->cmd);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001601 gen7_3dstate_pointer(cmd,
Chia-I Wu72292b72014-09-09 10:48:33 +08001602 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP,
1603 offset);
Chia-I Wub1d450a2014-09-09 13:48:03 +08001604
1605 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08001606 GEN6_ALIGNMENT_CC_VIEWPORT, 2 * viewport->viewport_count,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001607 &viewport->cmd[viewport->cmd_cc_pos]);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001608 gen7_3dstate_pointer(cmd,
1609 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
Chia-I Wub1d450a2014-09-09 13:48:03 +08001610 offset);
Chia-I Wu72292b72014-09-09 10:48:33 +08001611
Courtney Goeltzenleuchterc6e32f92015-02-11 14:13:34 -07001612 offset = cmd_state_write(cmd, INTEL_CMD_ITEM_SCISSOR_RECT,
1613 GEN6_ALIGNMENT_SCISSOR_RECT, 2 * viewport->viewport_count,
1614 &viewport->cmd[viewport->cmd_scissor_rect_pos]);
1615 gen7_3dstate_pointer(cmd,
1616 GEN6_RENDER_OPCODE_3DSTATE_SCISSOR_STATE_POINTERS,
1617 offset);
Chia-I Wu1744cca2014-08-22 11:10:17 +08001618}
1619
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001620static void gen6_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001621 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001622{
1623 const uint8_t cmd_len = 5;
Chia-I Wu46809782014-10-07 15:40:38 +08001624 uint32_t *dw;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001625
Chia-I Wu72292b72014-09-09 10:48:33 +08001626 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001627
1628 dw[0] = GEN6_RENDER_TYPE_RENDER |
1629 GEN6_RENDER_SUBTYPE_3D |
1630 subop | (cmd_len - 2);
1631 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001632 dw[2] = 0;
1633 dw[3] = 0;
1634 dw[4] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001635}
1636
1637static void gen7_pcb(struct intel_cmd *cmd, int subop,
Chia-I Wuf2b6d722014-09-02 08:52:27 +08001638 const struct intel_pipeline_shader *sh)
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001639{
1640 const uint8_t cmd_len = 7;
Chia-I Wu46809782014-10-07 15:40:38 +08001641 uint32_t *dw;
Chia-I Wuc3ddee62014-09-02 10:53:20 +08001642
Chia-I Wu72292b72014-09-09 10:48:33 +08001643 cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu46809782014-10-07 15:40:38 +08001644
1645 dw[0] = GEN6_RENDER_TYPE_RENDER |
1646 GEN6_RENDER_SUBTYPE_3D |
1647 subop | (cmd_len - 2);
1648 dw[1] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001649 dw[2] = 0;
Chia-I Wu46809782014-10-07 15:40:38 +08001650 dw[3] = 0;
Chia-I Wu72292b72014-09-09 10:48:33 +08001651 dw[4] = 0;
1652 dw[5] = 0;
1653 dw[6] = 0;
Chia-I Wu7fd5cac2014-08-27 13:19:29 +08001654}
1655
Chia-I Wu625105f2014-10-13 15:35:29 +08001656static uint32_t emit_samplers(struct intel_cmd *cmd,
1657 const struct intel_pipeline_rmap *rmap)
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001658{
Chia-I Wu862c5572015-03-28 15:23:55 +08001659 const struct intel_desc_region *region = cmd->dev->desc_region;
1660 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001661 const uint32_t border_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 4 : 12;
1662 const uint32_t border_stride =
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001663 u_align(border_len, GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE / 4);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001664 uint32_t border_offset, *border_dw, sampler_offset, *sampler_dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001665 uint32_t surface_count;
1666 uint32_t i;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001667
1668 CMD_ASSERT(cmd, 6, 7.5);
1669
Chia-I Wu625105f2014-10-13 15:35:29 +08001670 if (!rmap || !rmap->sampler_count)
1671 return 0;
1672
Cody Northrop40316a32014-12-09 19:08:33 -07001673 surface_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count;
Chia-I Wu625105f2014-10-13 15:35:29 +08001674
Chia-I Wudcb509d2014-12-10 08:53:10 +08001675 /*
1676 * note that we cannot call cmd_state_pointer() here as the following
1677 * cmd_state_pointer() would invalidate the pointer
1678 */
1679 border_offset = cmd_state_reserve(cmd, INTEL_CMD_ITEM_BLOB,
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001680 GEN6_ALIGNMENT_SAMPLER_BORDER_COLOR_STATE,
Chia-I Wudcb509d2014-12-10 08:53:10 +08001681 border_stride * rmap->sampler_count);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001682
1683 sampler_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_SAMPLER,
Chia-I Wue6073342014-11-30 09:43:42 +08001684 GEN6_ALIGNMENT_SAMPLER_STATE,
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001685 4 * rmap->sampler_count, &sampler_dw);
1686
Chia-I Wudcb509d2014-12-10 08:53:10 +08001687 cmd_state_update(cmd, border_offset,
1688 border_stride * rmap->sampler_count, &border_dw);
1689
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001690 for (i = 0; i < rmap->sampler_count; i++) {
1691 const struct intel_pipeline_rmap_slot *slot =
1692 &rmap->slots[surface_count + i];
Chia-I Wu862c5572015-03-28 15:23:55 +08001693 struct intel_desc_offset desc_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001694 const struct intel_sampler *sampler;
1695
Chia-I Wuf8385062015-01-04 16:27:24 +08001696 switch (slot->type) {
1697 case INTEL_PIPELINE_RMAP_SAMPLER:
Chia-I Wu862c5572015-03-28 15:23:55 +08001698 intel_desc_offset_add(&desc_offset, &slot->u.sampler,
1699 &data->set_offsets[slot->index]);
1700 intel_desc_region_read_sampler(region, &desc_offset, &sampler);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001701 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001702 case INTEL_PIPELINE_RMAP_UNUSED:
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001703 sampler = NULL;
1704 break;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001705 default:
Chia-I Wuf8385062015-01-04 16:27:24 +08001706 assert(!"unexpected rmap type");
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001707 sampler = NULL;
1708 break;
1709 }
1710
1711 if (sampler) {
1712 memcpy(border_dw, &sampler->cmd[3], border_len * 4);
1713
1714 sampler_dw[0] = sampler->cmd[0];
1715 sampler_dw[1] = sampler->cmd[1];
1716 sampler_dw[2] = border_offset;
1717 sampler_dw[3] = sampler->cmd[2];
1718 } else {
1719 sampler_dw[0] = GEN6_SAMPLER_DW0_DISABLE;
1720 sampler_dw[1] = 0;
1721 sampler_dw[2] = 0;
1722 sampler_dw[3] = 0;
1723 }
1724
1725 border_offset += border_stride * 4;
1726 border_dw += border_stride;
1727 sampler_dw += 4;
1728 }
1729
Chia-I Wu625105f2014-10-13 15:35:29 +08001730 return sampler_offset;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001731}
1732
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001733static uint32_t emit_binding_table(struct intel_cmd *cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001734 const struct intel_pipeline_rmap *rmap,
Tony Barbour8205d902015-04-16 15:59:00 -06001735 const VkShaderStage stage)
Chia-I Wu42a56202014-08-23 16:47:48 +08001736{
Chia-I Wu862c5572015-03-28 15:23:55 +08001737 const struct intel_desc_region *region = cmd->dev->desc_region;
1738 const struct intel_cmd_dset_data *data = &cmd->bind.dset.graphics_data;
Chia-I Wuf98dd882015-02-10 04:17:47 +08001739 const uint32_t sba_offset =
1740 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001741 uint32_t binding_table[256], offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001742 uint32_t surface_count, i;
Chia-I Wu42a56202014-08-23 16:47:48 +08001743
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001744 CMD_ASSERT(cmd, 6, 7.5);
1745
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001746 surface_count = (rmap) ?
Cody Northrop40316a32014-12-09 19:08:33 -07001747 rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + rmap->uav_count : 0;
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001748 if (!surface_count)
1749 return 0;
1750
Chia-I Wu42a56202014-08-23 16:47:48 +08001751 assert(surface_count <= ARRAY_SIZE(binding_table));
1752
1753 for (i = 0; i < surface_count; i++) {
Chia-I Wu20983762014-09-02 12:07:28 +08001754 const struct intel_pipeline_rmap_slot *slot = &rmap->slots[i];
Chia-I Wuf8385062015-01-04 16:27:24 +08001755 struct intel_null_view null_view;
1756 bool need_null_view = false;
Chia-I Wu42a56202014-08-23 16:47:48 +08001757
Chia-I Wuf8385062015-01-04 16:27:24 +08001758 switch (slot->type) {
1759 case INTEL_PIPELINE_RMAP_RT:
Chia-I Wu42a56202014-08-23 16:47:48 +08001760 {
Chia-I Wubdeed152015-07-09 12:16:29 +08001761 const struct intel_render_pass_subpass *subpass =
1762 cmd->bind.render_pass_subpass;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001763 const struct intel_fb *fb = cmd->bind.fb;
1764 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08001765 (slot->index < subpass->color_count &&
1766 subpass->color_indices[slot->index] < fb->view_count) ?
1767 fb->views[subpass->color_indices[slot->index]] : NULL;
Chia-I Wu42a56202014-08-23 16:47:48 +08001768
Chia-I Wu787a05b2014-12-05 11:02:20 +08001769 if (view) {
1770 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1771 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001772 view->cmd_len, view->att_cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001773
Chia-I Wu787a05b2014-12-05 11:02:20 +08001774 cmd_reserve_reloc(cmd, 1);
1775 cmd_surface_reloc(cmd, offset, 1, view->img->obj.mem->bo,
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08001776 view->att_cmd[1], INTEL_RELOC_WRITE);
Chia-I Wu787a05b2014-12-05 11:02:20 +08001777 } else {
Chia-I Wuf8385062015-01-04 16:27:24 +08001778 need_null_view = true;
Chia-I Wu787a05b2014-12-05 11:02:20 +08001779 }
Chia-I Wu42a56202014-08-23 16:47:48 +08001780 }
1781 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001782 case INTEL_PIPELINE_RMAP_SURFACE:
Chia-I Wu42a56202014-08-23 16:47:48 +08001783 {
Tony Barbour22a30862015-04-22 09:02:32 -06001784 const struct intel_pipeline_layout U_ASSERT_ONLY *pipeline_layout =
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001785 cmd->bind.pipeline.graphics->pipeline_layout;
Chia-I Wuf8385062015-01-04 16:27:24 +08001786 const int32_t dyn_idx = slot->u.surface.dynamic_offset_index;
Chia-I Wu862c5572015-03-28 15:23:55 +08001787 struct intel_desc_offset desc_offset;
Chia-I Wuf8385062015-01-04 16:27:24 +08001788 const struct intel_mem *mem;
1789 bool read_only;
1790 const uint32_t *cmd_data;
1791 uint32_t cmd_len;
Chia-I Wu42a56202014-08-23 16:47:48 +08001792
Chia-I Wu6097f3a2015-04-17 02:00:54 +08001793 assert(dyn_idx < 0 ||
Mark Lobodzinski556f7212015-04-17 14:11:39 -05001794 dyn_idx < pipeline_layout->total_dynamic_desc_count);
Chia-I Wu42a56202014-08-23 16:47:48 +08001795
Chia-I Wu862c5572015-03-28 15:23:55 +08001796 intel_desc_offset_add(&desc_offset, &slot->u.surface.offset,
1797 &data->set_offsets[slot->index]);
1798
1799 intel_desc_region_read_surface(region, &desc_offset, stage,
1800 &mem, &read_only, &cmd_data, &cmd_len);
Chia-I Wuf8385062015-01-04 16:27:24 +08001801 if (mem) {
1802 const uint32_t dynamic_offset = (dyn_idx >= 0) ?
Chia-I Wu862c5572015-03-28 15:23:55 +08001803 data->dynamic_offsets[dyn_idx] : 0;
Chia-I Wuf8385062015-01-04 16:27:24 +08001804 const uint32_t reloc_flags =
1805 (read_only) ? 0 : INTEL_RELOC_WRITE;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001806
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001807 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08001808 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wuf8385062015-01-04 16:27:24 +08001809 cmd_len, cmd_data);
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001810
1811 cmd_reserve_reloc(cmd, 1);
Chia-I Wuf8385062015-01-04 16:27:24 +08001812 cmd_surface_reloc(cmd, offset, 1, mem->bo,
1813 cmd_data[1] + dynamic_offset, reloc_flags);
1814 } else {
1815 need_null_view = true;
Chia-I Wufc05a2e2014-10-07 00:34:13 +08001816 }
1817 }
1818 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001819 case INTEL_PIPELINE_RMAP_UNUSED:
1820 need_null_view = true;
Chia-I Wu42a56202014-08-23 16:47:48 +08001821 break;
Chia-I Wuf8385062015-01-04 16:27:24 +08001822 default:
1823 assert(!"unexpected rmap type");
1824 need_null_view = true;
1825 break;
1826 }
1827
1828 if (need_null_view) {
1829 intel_null_view_init(&null_view, cmd->dev);
1830 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
1831 GEN6_ALIGNMENT_SURFACE_STATE,
1832 null_view.cmd_len, null_view.cmd);
Chia-I Wu42a56202014-08-23 16:47:48 +08001833 }
1834
Chia-I Wuf98dd882015-02-10 04:17:47 +08001835 binding_table[i] = offset - sba_offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001836 }
1837
Chia-I Wuf98dd882015-02-10 04:17:47 +08001838 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08001839 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wuf98dd882015-02-10 04:17:47 +08001840 surface_count, binding_table) - sba_offset;
1841
1842 /* there is a 64KB limit on BINIDNG_TABLE_STATEs */
1843 assert(offset + sizeof(uint32_t) * surface_count <= 64 * 1024);
1844
1845 return offset;
Chia-I Wu42a56202014-08-23 16:47:48 +08001846}
1847
Chia-I Wu1d125092014-10-08 08:49:38 +08001848static void gen6_3DSTATE_VERTEX_BUFFERS(struct intel_cmd *cmd)
1849{
1850 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu1d125092014-10-08 08:49:38 +08001851 const uint8_t cmd_len = 1 + 4 * pipeline->vb_count;
1852 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001853 uint32_t pos, i;
Chia-I Wu1d125092014-10-08 08:49:38 +08001854
1855 CMD_ASSERT(cmd, 6, 7.5);
1856
1857 if (!pipeline->vb_count)
1858 return;
1859
1860 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
1861
1862 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
1863 dw++;
1864 pos++;
1865
1866 for (i = 0; i < pipeline->vb_count; i++) {
Chia-I Wu1d125092014-10-08 08:49:38 +08001867 assert(pipeline->vb[i].strideInBytes <= 2048);
1868
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001869 dw[0] = i << GEN6_VB_DW0_INDEX__SHIFT |
Chia-I Wu1d125092014-10-08 08:49:38 +08001870 pipeline->vb[i].strideInBytes;
1871
Chia-I Wub3686982015-02-27 09:51:16 -07001872 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001873 dw[0] |= GEN7_MOCS_L3_WB << GEN6_VB_DW0_MOCS__SHIFT |
1874 GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wub3686982015-02-27 09:51:16 -07001875 }
Chia-I Wu1d125092014-10-08 08:49:38 +08001876
1877 switch (pipeline->vb[i].stepRate) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001878 case VK_VERTEX_INPUT_STEP_RATE_VERTEX:
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;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001882 case VK_VERTEX_INPUT_STEP_RATE_INSTANCE:
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001883 dw[0] |= GEN6_VB_DW0_ACCESS_INSTANCEDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001884 dw[3] = 1;
1885 break;
Chia-I Wu1d125092014-10-08 08:49:38 +08001886 default:
1887 assert(!"unknown step rate");
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001888 dw[0] |= GEN6_VB_DW0_ACCESS_VERTEXDATA;
Chia-I Wu1d125092014-10-08 08:49:38 +08001889 dw[3] = 0;
1890 break;
1891 }
1892
Chia-I Wu714df452015-01-01 07:55:04 +08001893 if (cmd->bind.vertex.buf[i]) {
1894 const struct intel_buf *buf = cmd->bind.vertex.buf[i];
Tony Barbour8205d902015-04-16 15:59:00 -06001895 const VkDeviceSize offset = cmd->bind.vertex.offset[i];
Chia-I Wu1d125092014-10-08 08:49:38 +08001896
1897 cmd_reserve_reloc(cmd, 2);
Chia-I Wu714df452015-01-01 07:55:04 +08001898 cmd_batch_reloc(cmd, pos + 1, buf->obj.mem->bo, offset, 0);
1899 cmd_batch_reloc(cmd, pos + 2, buf->obj.mem->bo, buf->size - 1, 0);
Chia-I Wu1d125092014-10-08 08:49:38 +08001900 } else {
Chia-I Wu97aa4de2015-03-05 15:43:16 -07001901 dw[0] |= GEN6_VB_DW0_IS_NULL;
Chia-I Wu1d125092014-10-08 08:49:38 +08001902 dw[1] = 0;
1903 dw[2] = 0;
1904 }
1905
1906 dw += 4;
1907 pos += 4;
1908 }
1909}
1910
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001911static void gen6_3DSTATE_VS(struct intel_cmd *cmd)
1912{
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001913 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
1914 const struct intel_pipeline_shader *vs = &pipeline->vs;
1915 const uint8_t cmd_len = 6;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001916 const uint32_t dw0 = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (cmd_len - 2);
Chia-I Wu72292b72014-09-09 10:48:33 +08001917 uint32_t dw2, dw4, dw5, *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06001918 uint32_t pos;
Chia-I Wu05990612014-11-25 11:36:35 +08001919 int vue_read_len;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001920
1921 CMD_ASSERT(cmd, 6, 7.5);
1922
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001923 /*
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001924 * From the Sandy Bridge PRM, volume 2 part 1, page 135:
1925 *
1926 * "(Vertex URB Entry Read Length) Specifies the number of pairs of
1927 * 128-bit vertex elements to be passed into the payload for each
1928 * vertex."
1929 *
1930 * "It is UNDEFINED to set this field to 0 indicating no Vertex URB
1931 * data to be read and passed to the thread."
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001932 */
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001933 vue_read_len = (vs->in_count + 1) / 2;
1934 if (!vue_read_len)
1935 vue_read_len = 1;
1936
1937 dw2 = (vs->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
1938 vs->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
1939
1940 dw4 = vs->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
1941 vue_read_len << GEN6_VS_DW4_URB_READ_LEN__SHIFT |
1942 0 << GEN6_VS_DW4_URB_READ_OFFSET__SHIFT;
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001943
1944 dw5 = GEN6_VS_DW5_STATISTICS |
1945 GEN6_VS_DW5_VS_ENABLE;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001946
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001947 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001948 dw5 |= (vs->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001949 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08001950 dw5 |= (vs->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu72f9b8d2014-09-02 13:27:48 +08001951
Chia-I Wube0a3d92014-09-02 13:20:59 +08001952 if (pipeline->disable_vs_cache)
1953 dw5 |= GEN6_VS_DW5_CACHE_DISABLE;
1954
Chia-I Wu784d3042014-12-19 14:30:04 +08001955 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
Chia-I Wu72292b72014-09-09 10:48:33 +08001956 dw[0] = dw0;
Chia-I Wua57761b2014-10-14 14:27:44 +08001957 dw[1] = cmd->bind.pipeline.vs_offset;
Chia-I Wu72292b72014-09-09 10:48:33 +08001958 dw[2] = dw2;
1959 dw[3] = 0; /* scratch */
1960 dw[4] = dw4;
1961 dw[5] = dw5;
Chia-I Wu784d3042014-12-19 14:30:04 +08001962
1963 if (vs->per_thread_scratch_size)
1964 gen6_add_scratch_space(cmd, pos + 3, pipeline, vs);
Courtney Goeltzenleuchter3d72e8c2014-08-29 16:27:47 -06001965}
1966
Chia-I Wu625105f2014-10-13 15:35:29 +08001967static void emit_shader_resources(struct intel_cmd *cmd)
1968{
1969 /* five HW shader stages */
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001970 uint32_t binding_tables[5], samplers[5];
Chia-I Wu625105f2014-10-13 15:35:29 +08001971
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001972 binding_tables[0] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001973 cmd->bind.pipeline.graphics->vs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001974 VK_SHADER_STAGE_VERTEX);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001975 binding_tables[1] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001976 cmd->bind.pipeline.graphics->tcs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001977 VK_SHADER_STAGE_TESS_CONTROL);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001978 binding_tables[2] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001979 cmd->bind.pipeline.graphics->tes.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001980 VK_SHADER_STAGE_TESS_EVALUATION);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001981 binding_tables[3] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001982 cmd->bind.pipeline.graphics->gs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001983 VK_SHADER_STAGE_GEOMETRY);
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001984 binding_tables[4] = emit_binding_table(cmd,
Cody Northrop7c76f302014-12-18 11:52:58 -07001985 cmd->bind.pipeline.graphics->fs.rmap,
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001986 VK_SHADER_STAGE_FRAGMENT);
Chia-I Wu625105f2014-10-13 15:35:29 +08001987
1988 samplers[0] = emit_samplers(cmd, cmd->bind.pipeline.graphics->vs.rmap);
1989 samplers[1] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tcs.rmap);
1990 samplers[2] = emit_samplers(cmd, cmd->bind.pipeline.graphics->tes.rmap);
1991 samplers[3] = emit_samplers(cmd, cmd->bind.pipeline.graphics->gs.rmap);
1992 samplers[4] = emit_samplers(cmd, cmd->bind.pipeline.graphics->fs.rmap);
1993
1994 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
1995 gen7_3dstate_pointer(cmd,
Chia-I Wu8f6043a2014-10-13 15:44:06 +08001996 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS,
1997 binding_tables[0]);
1998 gen7_3dstate_pointer(cmd,
1999 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_HS,
2000 binding_tables[1]);
2001 gen7_3dstate_pointer(cmd,
2002 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_DS,
2003 binding_tables[2]);
2004 gen7_3dstate_pointer(cmd,
2005 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_GS,
2006 binding_tables[3]);
2007 gen7_3dstate_pointer(cmd,
2008 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS,
2009 binding_tables[4]);
2010
2011 gen7_3dstate_pointer(cmd,
Chia-I Wu625105f2014-10-13 15:35:29 +08002012 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_VS,
2013 samplers[0]);
2014 gen7_3dstate_pointer(cmd,
2015 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_HS,
2016 samplers[1]);
2017 gen7_3dstate_pointer(cmd,
2018 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_DS,
2019 samplers[2]);
2020 gen7_3dstate_pointer(cmd,
2021 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_GS,
2022 samplers[3]);
2023 gen7_3dstate_pointer(cmd,
2024 GEN7_RENDER_OPCODE_3DSTATE_SAMPLER_STATE_POINTERS_PS,
2025 samplers[4]);
2026 } else {
Chia-I Wu8f6043a2014-10-13 15:44:06 +08002027 assert(!binding_tables[1] && !binding_tables[2]);
2028 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd,
2029 binding_tables[0], binding_tables[3], binding_tables[4]);
2030
Chia-I Wu625105f2014-10-13 15:35:29 +08002031 assert(!samplers[1] && !samplers[2]);
2032 gen6_3DSTATE_SAMPLER_STATE_POINTERS(cmd,
2033 samplers[0], samplers[3], samplers[4]);
2034 }
2035}
2036
Chia-I Wu8ada4242015-03-02 11:19:33 -07002037static void emit_msaa(struct intel_cmd *cmd)
2038{
Chia-I Wuc278df82015-07-07 11:50:03 +08002039 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wu8ada4242015-03-02 11:19:33 -07002040
Chia-I Wubbc7d912015-02-27 14:59:50 -07002041 if (!cmd->bind.render_pass_changed)
2042 return;
2043
Chia-I Wu8ada4242015-03-02 11:19:33 -07002044 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
Chia-I Wuc278df82015-07-07 11:50:03 +08002045 gen6_3DSTATE_MULTISAMPLE(cmd, pipeline->sample_count);
Chia-I Wu8ada4242015-03-02 11:19:33 -07002046}
2047
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002048static void emit_rt(struct intel_cmd *cmd)
2049{
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002050 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wubbc7d912015-02-27 14:59:50 -07002051
2052 if (!cmd->bind.render_pass_changed)
2053 return;
2054
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002055 cmd_wa_gen6_pre_depth_stall_write(cmd);
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002056 gen6_3DSTATE_DRAWING_RECTANGLE(cmd, fb->width,
2057 fb->height);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002058}
2059
2060static void emit_ds(struct intel_cmd *cmd)
2061{
Chia-I Wu1af1a782015-07-09 10:46:39 +08002062 const struct intel_render_pass *rp = cmd->bind.render_pass;
Chia-I Wubdeed152015-07-09 12:16:29 +08002063 const struct intel_render_pass_subpass *subpass =
2064 cmd->bind.render_pass_subpass;
Courtney Goeltzenleuchtere3b0f3a2015-04-03 15:25:24 -06002065 const struct intel_fb *fb = cmd->bind.fb;
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002066 const struct intel_att_view *view =
Chia-I Wubdeed152015-07-09 12:16:29 +08002067 (subpass->ds_index < rp->attachment_count) ?
2068 fb->views[subpass->ds_index] : NULL;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002069
Chia-I Wubbc7d912015-02-27 14:59:50 -07002070 if (!cmd->bind.render_pass_changed)
2071 return;
2072
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002073 if (!view) {
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002074 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08002075 static const struct intel_att_view null_view;
2076 view = &null_view;
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002077 }
2078
2079 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wubdeed152015-07-09 12:16:29 +08002080 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
2081 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, subpass->ds_optimal);
2082 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, subpass->ds_optimal);
Chia-I Wu2e5ec9b2014-10-14 13:37:21 +08002083
2084 if (cmd_gen(cmd) >= INTEL_GEN(7))
2085 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
2086 else
2087 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
2088}
2089
Chia-I Wua57761b2014-10-14 14:27:44 +08002090static uint32_t emit_shader(struct intel_cmd *cmd,
2091 const struct intel_pipeline_shader *shader)
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002092{
Chia-I Wua57761b2014-10-14 14:27:44 +08002093 struct intel_cmd_shader_cache *cache = &cmd->bind.shader_cache;
2094 uint32_t offset;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002095 uint32_t i;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002096
Chia-I Wua57761b2014-10-14 14:27:44 +08002097 /* see if the shader is already in the cache */
2098 for (i = 0; i < cache->used; i++) {
2099 if (cache->entries[i].shader == (const void *) shader)
2100 return cache->entries[i].kernel_offset;
2101 }
2102
2103 offset = cmd_instruction_write(cmd, shader->codeSize, shader->pCode);
2104
2105 /* grow the cache if full */
2106 if (cache->used >= cache->count) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002107 const uint32_t count = cache->count + 16;
Chia-I Wua57761b2014-10-14 14:27:44 +08002108 void *entries;
2109
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002110 entries = intel_alloc(cmd, sizeof(cache->entries[0]) * count, 0,
Tony Barbour8205d902015-04-16 15:59:00 -06002111 VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wua57761b2014-10-14 14:27:44 +08002112 if (entries) {
2113 if (cache->entries) {
2114 memcpy(entries, cache->entries,
2115 sizeof(cache->entries[0]) * cache->used);
Chia-I Wuf9c81ef2015-02-22 13:49:15 +08002116 intel_free(cmd, cache->entries);
Chia-I Wua57761b2014-10-14 14:27:44 +08002117 }
2118
2119 cache->entries = entries;
2120 cache->count = count;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002121 }
2122 }
2123
Chia-I Wua57761b2014-10-14 14:27:44 +08002124 /* add the shader to the cache */
2125 if (cache->used < cache->count) {
2126 cache->entries[cache->used].shader = (const void *) shader;
2127 cache->entries[cache->used].kernel_offset = offset;
2128 cache->used++;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002129 }
2130
Chia-I Wua57761b2014-10-14 14:27:44 +08002131 return offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002132}
2133
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002134static void emit_graphics_pipeline(struct intel_cmd *cmd)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002135{
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002136 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002137
Chia-I Wu8370b402014-08-29 12:28:37 +08002138 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_DEPTH_STALL_WRITE)
2139 cmd_wa_gen6_pre_depth_stall_write(cmd);
2140 if (pipeline->wa_flags & INTEL_CMD_WA_GEN6_PRE_COMMAND_SCOREBOARD_STALL)
2141 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
2142 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_PRE_VS_DEPTH_STALL_WRITE)
2143 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002144
2145 /* 3DSTATE_URB_VS and etc. */
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -06002146 assert(pipeline->cmd_len);
Chia-I Wu72292b72014-09-09 10:48:33 +08002147 cmd_batch_write(cmd, pipeline->cmd_len, pipeline->cmds);
Chia-I Wubb2d8ca2014-08-28 23:15:48 +08002148
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002149 if (pipeline->active_shaders & SHADER_VERTEX_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002150 cmd->bind.pipeline.vs_offset = emit_shader(cmd, &pipeline->vs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002151 }
2152 if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002153 cmd->bind.pipeline.tcs_offset = emit_shader(cmd, &pipeline->tcs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002154 }
2155 if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) {
Chia-I Wua57761b2014-10-14 14:27:44 +08002156 cmd->bind.pipeline.tes_offset = emit_shader(cmd, &pipeline->tes);
2157 }
2158 if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) {
2159 cmd->bind.pipeline.gs_offset = emit_shader(cmd, &pipeline->gs);
2160 }
2161 if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) {
2162 cmd->bind.pipeline.fs_offset = emit_shader(cmd, &pipeline->fs);
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -06002163 }
Courtney Goeltzenleuchter68d9bef2014-08-28 17:35:03 -06002164
Chia-I Wu8370b402014-08-29 12:28:37 +08002165 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_CS_STALL)
2166 cmd_wa_gen7_post_command_cs_stall(cmd);
2167 if (pipeline->wa_flags & INTEL_CMD_WA_GEN7_POST_COMMAND_DEPTH_STALL)
2168 cmd_wa_gen7_post_command_depth_stall(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08002169}
2170
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002171static void emit_bounded_states(struct intel_cmd *cmd)
2172{
Chia-I Wu8ada4242015-03-02 11:19:33 -07002173 emit_msaa(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002174
2175 emit_graphics_pipeline(cmd);
2176
2177 emit_rt(cmd);
2178 emit_ds(cmd);
2179
2180 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2181 gen7_cc_states(cmd);
2182 gen7_viewport_states(cmd);
2183
2184 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2185 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002186 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2187 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002188 gen7_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2189 &cmd->bind.pipeline.graphics->fs);
2190
Cody Northrop293d4502015-05-05 09:38:03 -06002191 gen7_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002192 gen6_3DSTATE_CLIP(cmd);
2193 gen7_3DSTATE_SF(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002194 gen7_3DSTATE_WM(cmd);
2195 gen7_3DSTATE_PS(cmd);
2196 } else {
2197 gen6_cc_states(cmd);
2198 gen6_viewport_states(cmd);
2199
2200 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_VS,
2201 &cmd->bind.pipeline.graphics->vs);
Cody Northrop293d4502015-05-05 09:38:03 -06002202 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_GS,
2203 &cmd->bind.pipeline.graphics->gs);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002204 gen6_pcb(cmd, GEN6_RENDER_OPCODE_3DSTATE_CONSTANT_PS,
2205 &cmd->bind.pipeline.graphics->fs);
2206
Cody Northrop293d4502015-05-05 09:38:03 -06002207 gen6_3DSTATE_GS(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002208 gen6_3DSTATE_CLIP(cmd);
2209 gen6_3DSTATE_SF(cmd);
2210 gen6_3DSTATE_WM(cmd);
2211 }
2212
2213 emit_shader_resources(cmd);
2214
2215 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002216
Chia-I Wuc29afdd2014-10-14 13:22:31 +08002217 gen6_3DSTATE_VERTEX_BUFFERS(cmd);
2218 gen6_3DSTATE_VS(cmd);
2219}
2220
Tony Barbourfa6cac72015-01-16 14:27:35 -07002221static uint32_t gen6_meta_DEPTH_STENCIL_STATE(struct intel_cmd *cmd,
Chia-I Wud850a392015-02-19 11:08:25 -07002222 const struct intel_cmd_meta *meta)
Tony Barbourfa6cac72015-01-16 14:27:35 -07002223{
2224 const uint8_t cmd_align = GEN6_ALIGNMENT_DEPTH_STENCIL_STATE;
2225 const uint8_t cmd_len = 3;
2226 uint32_t dw[3];
Tony Barbourfa6cac72015-01-16 14:27:35 -07002227
2228 CMD_ASSERT(cmd, 6, 7.5);
2229
Courtney Goeltzenleuchteraeffeae2015-09-10 17:58:54 -06002230 /* TODO: aspect is now a mask, can you do both? */
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002231 if (meta->ds.aspect == VK_IMAGE_ASPECT_DEPTH) {
Chia-I Wud850a392015-02-19 11:08:25 -07002232 dw[0] = 0;
2233 dw[1] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002234
2235 if (meta->ds.op == INTEL_CMD_META_DS_RESOLVE) {
2236 dw[2] = GEN6_ZS_DW2_DEPTH_TEST_ENABLE |
2237 GEN6_COMPAREFUNCTION_NEVER << 27 |
2238 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2239 } else {
2240 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27 |
2241 GEN6_ZS_DW2_DEPTH_WRITE_ENABLE;
2242 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002243 } else if (meta->ds.aspect == VK_IMAGE_ASPECT_STENCIL) {
Chia-I Wud850a392015-02-19 11:08:25 -07002244 dw[0] = GEN6_ZS_DW0_STENCIL_TEST_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002245 (GEN6_COMPAREFUNCTION_ALWAYS) << 28 |
2246 (GEN6_STENCILOP_KEEP) << 25 |
2247 (GEN6_STENCILOP_KEEP) << 22 |
2248 (GEN6_STENCILOP_REPLACE) << 19 |
Chia-I Wud850a392015-02-19 11:08:25 -07002249 GEN6_ZS_DW0_STENCIL_WRITE_ENABLE |
2250 GEN6_ZS_DW0_STENCIL1_ENABLE |
Tony Barbourfa6cac72015-01-16 14:27:35 -07002251 (GEN6_COMPAREFUNCTION_ALWAYS) << 12 |
2252 (GEN6_STENCILOP_KEEP) << 9 |
2253 (GEN6_STENCILOP_KEEP) << 6 |
2254 (GEN6_STENCILOP_REPLACE) << 3;
Tony Barbourfa6cac72015-01-16 14:27:35 -07002255
Chia-I Wud850a392015-02-19 11:08:25 -07002256 dw[1] = 0xff << GEN6_ZS_DW1_STENCIL0_VALUEMASK__SHIFT |
2257 0xff << GEN6_ZS_DW1_STENCIL0_WRITEMASK__SHIFT |
2258 0xff << GEN6_ZS_DW1_STENCIL1_VALUEMASK__SHIFT |
2259 0xff << GEN6_ZS_DW1_STENCIL1_WRITEMASK__SHIFT;
2260 dw[2] = 0;
2261 }
Tony Barbourfa6cac72015-01-16 14:27:35 -07002262
2263 return cmd_state_write(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
2264 cmd_align, cmd_len, dw);
2265}
2266
Chia-I Wu6032b892014-10-17 14:47:18 +08002267static void gen6_meta_dynamic_states(struct intel_cmd *cmd)
2268{
2269 const struct intel_cmd_meta *meta = cmd->bind.meta;
2270 uint32_t blend_offset, ds_offset, cc_offset, cc_vp_offset, *dw;
2271
2272 CMD_ASSERT(cmd, 6, 7.5);
2273
2274 blend_offset = 0;
2275 ds_offset = 0;
2276 cc_offset = 0;
2277 cc_vp_offset = 0;
2278
Chia-I Wu29e6f502014-11-24 14:27:29 +08002279 if (meta->mode == INTEL_CMD_META_FS_RECT) {
Chia-I Wu6032b892014-10-17 14:47:18 +08002280 /* BLEND_STATE */
2281 blend_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_BLEND,
Chia-I Wue6073342014-11-30 09:43:42 +08002282 GEN6_ALIGNMENT_BLEND_STATE, 2, &dw);
Chia-I Wu6032b892014-10-17 14:47:18 +08002283 dw[0] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002284 dw[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT | 0x3;
Chia-I Wu6032b892014-10-17 14:47:18 +08002285 }
2286
Chia-I Wu29e6f502014-11-24 14:27:29 +08002287 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002288 if (meta->ds.aspect != VK_IMAGE_ASPECT_COLOR) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002289 const uint32_t blend_color[4] = { 0, 0, 0, 0 };
Chia-I Wu2ed603e2015-02-17 09:48:37 -07002290 uint32_t stencil_ref = (meta->ds.stencil_ref & 0xff) << 24 |
2291 (meta->ds.stencil_ref & 0xff) << 16;
Chia-I Wu6032b892014-10-17 14:47:18 +08002292
Chia-I Wu29e6f502014-11-24 14:27:29 +08002293 /* DEPTH_STENCIL_STATE */
Tony Barbourfa6cac72015-01-16 14:27:35 -07002294 ds_offset = gen6_meta_DEPTH_STENCIL_STATE(cmd, meta);
Chia-I Wu6032b892014-10-17 14:47:18 +08002295
Chia-I Wu29e6f502014-11-24 14:27:29 +08002296 /* COLOR_CALC_STATE */
2297 cc_offset = gen6_COLOR_CALC_STATE(cmd,
Tony Barbourfa6cac72015-01-16 14:27:35 -07002298 stencil_ref, blend_color);
Chia-I Wu6032b892014-10-17 14:47:18 +08002299
Chia-I Wu29e6f502014-11-24 14:27:29 +08002300 /* CC_VIEWPORT */
2301 cc_vp_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_CC_VIEWPORT,
Chia-I Wue6073342014-11-30 09:43:42 +08002302 GEN6_ALIGNMENT_CC_VIEWPORT, 2, &dw);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002303 dw[0] = u_fui(0.0f);
2304 dw[1] = u_fui(1.0f);
2305 } else {
2306 /* DEPTH_STENCIL_STATE */
2307 ds_offset = cmd_state_pointer(cmd, INTEL_CMD_ITEM_DEPTH_STENCIL,
Chia-I Wue6073342014-11-30 09:43:42 +08002308 GEN6_ALIGNMENT_DEPTH_STENCIL_STATE,
Chia-I Wu29e6f502014-11-24 14:27:29 +08002309 GEN6_DEPTH_STENCIL_STATE__SIZE, &dw);
2310 memset(dw, 0, sizeof(*dw) * GEN6_DEPTH_STENCIL_STATE__SIZE);
2311 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002312 }
2313
2314 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2315 gen7_3dstate_pointer(cmd,
2316 GEN7_RENDER_OPCODE_3DSTATE_BLEND_STATE_POINTERS,
2317 blend_offset);
2318 gen7_3dstate_pointer(cmd,
2319 GEN7_RENDER_OPCODE_3DSTATE_DEPTH_STENCIL_STATE_POINTERS,
2320 ds_offset);
2321 gen7_3dstate_pointer(cmd,
2322 GEN6_RENDER_OPCODE_3DSTATE_CC_STATE_POINTERS, cc_offset);
2323
2324 gen7_3dstate_pointer(cmd,
2325 GEN7_RENDER_OPCODE_3DSTATE_VIEWPORT_STATE_POINTERS_CC,
2326 cc_vp_offset);
2327 } else {
2328 /* 3DSTATE_CC_STATE_POINTERS */
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002329 gen6_3DSTATE_CC_STATE_POINTERS(cmd, blend_offset, ds_offset, cc_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002330
2331 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
2332 cmd_batch_pointer(cmd, 4, &dw);
2333 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VIEWPORT_STATE_POINTERS) | (4 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002334 GEN6_VP_PTR_DW0_CC_CHANGED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002335 dw[1] = 0;
2336 dw[2] = 0;
2337 dw[3] = cc_vp_offset;
2338 }
2339}
2340
2341static void gen6_meta_surface_states(struct intel_cmd *cmd)
2342{
2343 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002344 uint32_t binding_table[2] = { 0, 0 };
Chia-I Wu6032b892014-10-17 14:47:18 +08002345 uint32_t offset;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002346 const uint32_t sba_offset =
2347 cmd->writers[INTEL_CMD_WRITER_SURFACE].sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002348
2349 CMD_ASSERT(cmd, 6, 7.5);
2350
Chia-I Wu29e6f502014-11-24 14:27:29 +08002351 if (meta->mode == INTEL_CMD_META_DEPTH_STENCIL_RECT)
2352 return;
2353
Chia-I Wu005c47c2014-10-22 13:49:13 +08002354 /* SURFACE_STATEs */
Chia-I Wu6032b892014-10-17 14:47:18 +08002355 if (meta->src.valid) {
2356 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002357 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu6032b892014-10-17 14:47:18 +08002358 meta->src.surface_len, meta->src.surface);
2359
2360 cmd_reserve_reloc(cmd, 1);
2361 if (meta->src.reloc_flags & INTEL_CMD_RELOC_TARGET_IS_WRITER) {
2362 cmd_surface_reloc_writer(cmd, offset, 1,
2363 meta->src.reloc_target, meta->src.reloc_offset);
2364 } else {
2365 cmd_surface_reloc(cmd, offset, 1,
2366 (struct intel_bo *) meta->src.reloc_target,
2367 meta->src.reloc_offset, meta->src.reloc_flags);
2368 }
2369
Mike Stroyan9bfad482015-02-10 15:09:23 -07002370 binding_table[0] = offset - sba_offset;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002371 }
2372 if (meta->dst.valid) {
2373 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_SURFACE,
Chia-I Wue6073342014-11-30 09:43:42 +08002374 GEN6_ALIGNMENT_SURFACE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002375 meta->dst.surface_len, meta->dst.surface);
2376
2377 cmd_reserve_reloc(cmd, 1);
2378 cmd_surface_reloc(cmd, offset, 1,
2379 (struct intel_bo *) meta->dst.reloc_target,
2380 meta->dst.reloc_offset, meta->dst.reloc_flags);
2381
Mike Stroyan9bfad482015-02-10 15:09:23 -07002382 binding_table[1] = offset - sba_offset;
Chia-I Wu6032b892014-10-17 14:47:18 +08002383 }
2384
2385 /* BINDING_TABLE */
Chia-I Wu0b7b1a32015-02-10 04:07:29 +08002386 offset = cmd_surface_write(cmd, INTEL_CMD_ITEM_BINDING_TABLE,
Chia-I Wue6073342014-11-30 09:43:42 +08002387 GEN6_ALIGNMENT_BINDING_TABLE_STATE,
Chia-I Wu005c47c2014-10-22 13:49:13 +08002388 2, binding_table);
Chia-I Wu6032b892014-10-17 14:47:18 +08002389
2390 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
Chia-I Wu29e6f502014-11-24 14:27:29 +08002391 const int subop = (meta->mode == INTEL_CMD_META_VS_POINTS) ?
2392 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_VS :
2393 GEN7_RENDER_OPCODE_3DSTATE_BINDING_TABLE_POINTERS_PS;
Mike Stroyan9bfad482015-02-10 15:09:23 -07002394 gen7_3dstate_pointer(cmd, subop, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002395 } else {
2396 /* 3DSTATE_BINDING_TABLE_POINTERS */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002397 if (meta->mode == INTEL_CMD_META_VS_POINTS)
Mike Stroyan9bfad482015-02-10 15:09:23 -07002398 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, offset - sba_offset, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002399 else
Mike Stroyan9bfad482015-02-10 15:09:23 -07002400 gen6_3DSTATE_BINDING_TABLE_POINTERS(cmd, 0, 0, offset - sba_offset);
Chia-I Wu6032b892014-10-17 14:47:18 +08002401 }
2402}
2403
2404static void gen6_meta_urb(struct intel_cmd *cmd)
2405{
Chia-I Wu24aa1022014-11-25 11:53:19 +08002406 const int vs_entry_count = (cmd->dev->gpu->gt == 2) ? 256 : 128;
Chia-I Wu6032b892014-10-17 14:47:18 +08002407 uint32_t *dw;
2408
2409 CMD_ASSERT(cmd, 6, 6);
2410
2411 /* 3DSTATE_URB */
2412 cmd_batch_pointer(cmd, 3, &dw);
2413 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_URB) | (3 - 2);
Chia-I Wu24aa1022014-11-25 11:53:19 +08002414 dw[1] = vs_entry_count << GEN6_URB_DW1_VS_ENTRY_COUNT__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002415 dw[2] = 0;
2416}
2417
2418static void gen7_meta_urb(struct intel_cmd *cmd)
2419{
Chia-I Wu15dacac2015-02-05 11:14:01 -07002420 const int pcb_alloc = (cmd->dev->gpu->gt == 3) ? 16 : 8;
2421 const int urb_offset = pcb_alloc / 8;
Chia-I Wu24aa1022014-11-25 11:53:19 +08002422 int vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002423 uint32_t *dw;
2424
2425 CMD_ASSERT(cmd, 7, 7.5);
2426
Chia-I Wu6032b892014-10-17 14:47:18 +08002427 cmd_wa_gen7_pre_vs_depth_stall_write(cmd);
2428
Chia-I Wu24aa1022014-11-25 11:53:19 +08002429 switch (cmd_gen(cmd)) {
2430 case INTEL_GEN(7.5):
2431 vs_entry_count = (cmd->dev->gpu->gt >= 2) ? 1664 : 640;
2432 break;
2433 case INTEL_GEN(7):
2434 default:
2435 vs_entry_count = (cmd->dev->gpu->gt == 2) ? 704 : 512;
2436 break;
2437 }
2438
Chia-I Wu6032b892014-10-17 14:47:18 +08002439 /* 3DSTATE_URB_x */
2440 cmd_batch_pointer(cmd, 8, &dw);
2441
2442 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_VS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002443 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT |
Chia-I Wu24aa1022014-11-25 11:53:19 +08002444 vs_entry_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002445 dw += 2;
2446
2447 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_HS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002448 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002449 dw += 2;
2450
2451 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_DS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002452 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002453 dw += 2;
2454
2455 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_URB_GS) | (2 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002456 dw[1] = urb_offset << GEN7_URB_DW1_OFFSET__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002457 dw += 2;
2458}
2459
2460static void gen6_meta_vf(struct intel_cmd *cmd)
2461{
2462 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002463 uint32_t vb_start, vb_end, vb_stride;
2464 int ve_format, ve_z_source;
2465 uint32_t *dw;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002466 uint32_t pos;
Chia-I Wu6032b892014-10-17 14:47:18 +08002467
2468 CMD_ASSERT(cmd, 6, 7.5);
2469
Chia-I Wu29e6f502014-11-24 14:27:29 +08002470 switch (meta->mode) {
2471 case INTEL_CMD_META_VS_POINTS:
2472 cmd_batch_pointer(cmd, 3, &dw);
2473 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002474 dw[1] = GEN6_VE_DW0_VALID;
2475 dw[2] = GEN6_VFCOMP_STORE_VID << GEN6_VE_DW1_COMP0__SHIFT |
2476 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP1__SHIFT |
2477 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP2__SHIFT |
2478 GEN6_VFCOMP_NOSTORE << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002479 return;
2480 break;
2481 case INTEL_CMD_META_FS_RECT:
2482 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002483 uint32_t vertices[3][2];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002484
Chia-I Wu29e6f502014-11-24 14:27:29 +08002485 vertices[0][0] = meta->dst.x + meta->width;
2486 vertices[0][1] = meta->dst.y + meta->height;
2487 vertices[1][0] = meta->dst.x;
2488 vertices[1][1] = meta->dst.y + meta->height;
2489 vertices[2][0] = meta->dst.x;
2490 vertices[2][1] = meta->dst.y;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002491
Chia-I Wu29e6f502014-11-24 14:27:29 +08002492 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2493 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002494
Chia-I Wu29e6f502014-11-24 14:27:29 +08002495 vb_end = vb_start + sizeof(vertices) - 1;
2496 vb_stride = sizeof(vertices[0]);
2497 ve_z_source = GEN6_VFCOMP_STORE_0;
2498 ve_format = GEN6_FORMAT_R32G32_USCALED;
2499 }
2500 break;
2501 case INTEL_CMD_META_DEPTH_STENCIL_RECT:
2502 {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002503 float vertices[3][3];
Chia-I Wu3adf7212014-10-24 15:34:07 +08002504
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002505 vertices[0][0] = (float) (meta->dst.x + meta->width);
2506 vertices[0][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002507 vertices[0][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002508 vertices[1][0] = (float) meta->dst.x;
2509 vertices[1][1] = (float) (meta->dst.y + meta->height);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002510 vertices[1][2] = u_uif(meta->clear_val[0]);
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002511 vertices[2][0] = (float) meta->dst.x;
2512 vertices[2][1] = (float) meta->dst.y;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002513 vertices[2][2] = u_uif(meta->clear_val[0]);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002514
Chia-I Wu29e6f502014-11-24 14:27:29 +08002515 vb_start = cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32,
2516 sizeof(vertices) / 4, (const uint32_t *) vertices);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002517
Chia-I Wu29e6f502014-11-24 14:27:29 +08002518 vb_end = vb_start + sizeof(vertices) - 1;
2519 vb_stride = sizeof(vertices[0]);
2520 ve_z_source = GEN6_VFCOMP_STORE_SRC;
2521 ve_format = GEN6_FORMAT_R32G32B32_FLOAT;
2522 }
2523 break;
2524 default:
2525 assert(!"unknown meta mode");
2526 return;
2527 break;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002528 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002529
2530 /* 3DSTATE_VERTEX_BUFFERS */
2531 pos = cmd_batch_pointer(cmd, 5, &dw);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002532
Chia-I Wu6032b892014-10-17 14:47:18 +08002533 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (5 - 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002534 dw[1] = vb_stride;
Chia-I Wu6032b892014-10-17 14:47:18 +08002535 if (cmd_gen(cmd) >= INTEL_GEN(7))
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002536 dw[1] |= GEN7_VB_DW0_ADDR_MODIFIED;
Chia-I Wu6032b892014-10-17 14:47:18 +08002537
2538 cmd_reserve_reloc(cmd, 2);
Chia-I Wu3adf7212014-10-24 15:34:07 +08002539 cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, vb_start);
2540 cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, vb_end);
Chia-I Wu6032b892014-10-17 14:47:18 +08002541
2542 dw[4] = 0;
2543
2544 /* 3DSTATE_VERTEX_ELEMENTS */
2545 cmd_batch_pointer(cmd, 5, &dw);
2546 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_ELEMENTS) | (5 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002547 dw[1] = GEN6_VE_DW0_VALID;
2548 dw[2] = GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP0__SHIFT | /* Reserved */
2549 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP1__SHIFT | /* Render Target Array Index */
2550 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP2__SHIFT | /* Viewport Index */
2551 GEN6_VFCOMP_STORE_0 << GEN6_VE_DW1_COMP3__SHIFT; /* Point Width */
2552 dw[3] = GEN6_VE_DW0_VALID |
2553 ve_format << GEN6_VE_DW0_FORMAT__SHIFT;
2554 dw[4] = GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP0__SHIFT |
2555 GEN6_VFCOMP_STORE_SRC << GEN6_VE_DW1_COMP1__SHIFT |
2556 ve_z_source << GEN6_VE_DW1_COMP2__SHIFT |
2557 GEN6_VFCOMP_STORE_1_FP << GEN6_VE_DW1_COMP3__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002558}
2559
Chia-I Wu29e6f502014-11-24 14:27:29 +08002560static uint32_t gen6_meta_vs_constants(struct intel_cmd *cmd)
Chia-I Wu6032b892014-10-17 14:47:18 +08002561{
Chia-I Wu3adf7212014-10-24 15:34:07 +08002562 const struct intel_cmd_meta *meta = cmd->bind.meta;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002563 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002564 uint32_t consts[8];
2565 uint32_t const_count;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002566
2567 CMD_ASSERT(cmd, 6, 7.5);
2568
2569 switch (meta->shader_id) {
Chia-I Wu0c87f472014-11-25 14:37:30 +08002570 case INTEL_DEV_META_VS_FILL_MEM:
2571 consts[0] = meta->dst.x;
2572 consts[1] = meta->clear_val[0];
2573 const_count = 2;
2574 break;
2575 case INTEL_DEV_META_VS_COPY_MEM:
2576 case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED:
2577 consts[0] = meta->dst.x;
2578 consts[1] = meta->src.x;
2579 const_count = 2;
2580 break;
Chia-I Wu4d344e62014-12-20 21:06:04 +08002581 case INTEL_DEV_META_VS_COPY_R8_TO_MEM:
2582 case INTEL_DEV_META_VS_COPY_R16_TO_MEM:
2583 case INTEL_DEV_META_VS_COPY_R32_TO_MEM:
2584 case INTEL_DEV_META_VS_COPY_R32G32_TO_MEM:
2585 case INTEL_DEV_META_VS_COPY_R32G32B32A32_TO_MEM:
2586 consts[0] = meta->src.x;
2587 consts[1] = meta->src.y;
2588 consts[2] = meta->width;
2589 consts[3] = meta->dst.x;
2590 const_count = 4;
2591 break;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002592 default:
2593 assert(!"unknown meta shader id");
2594 const_count = 0;
2595 break;
2596 }
2597
2598 /* this can be skipped but it makes state dumping prettier */
2599 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2600
2601 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2602}
2603
2604static void gen6_meta_vs(struct intel_cmd *cmd)
2605{
2606 const struct intel_cmd_meta *meta = cmd->bind.meta;
2607 const struct intel_pipeline_shader *sh =
2608 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2609 uint32_t offset, *dw;
2610
2611 CMD_ASSERT(cmd, 6, 7.5);
2612
2613 if (meta->mode != INTEL_CMD_META_VS_POINTS) {
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002614 uint32_t cmd_len;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002615
2616 /* 3DSTATE_CONSTANT_VS */
2617 cmd_len = (cmd_gen(cmd) >= INTEL_GEN(7)) ? 7 : 5;
2618 cmd_batch_pointer(cmd, cmd_len, &dw);
2619 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (cmd_len - 2);
2620 memset(&dw[1], 0, sizeof(*dw) * (cmd_len - 1));
2621
2622 /* 3DSTATE_VS */
2623 cmd_batch_pointer(cmd, 6, &dw);
2624 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2625 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2626
2627 return;
2628 }
2629
2630 assert(meta->dst.valid && sh->uses == INTEL_SHADER_USE_VID);
2631
2632 /* 3DSTATE_CONSTANT_VS */
2633 offset = gen6_meta_vs_constants(cmd);
2634 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2635 cmd_batch_pointer(cmd, 7, &dw);
2636 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002637 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002638 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002639 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002640 dw[4] = 0;
2641 dw[5] = 0;
2642 dw[6] = 0;
2643 } else {
2644 cmd_batch_pointer(cmd, 5, &dw);
2645 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_VS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002646 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002647 dw[1] = offset;
2648 dw[2] = 0;
2649 dw[3] = 0;
2650 dw[4] = 0;
2651 }
2652
2653 /* 3DSTATE_VS */
2654 offset = emit_shader(cmd, sh);
2655 cmd_batch_pointer(cmd, 6, &dw);
2656 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VS) | (6 - 2);
2657 dw[1] = offset;
2658 dw[2] = GEN6_THREADDISP_SPF |
2659 (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2660 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002661 dw[3] = 0; /* scratch */
Chia-I Wu29e6f502014-11-24 14:27:29 +08002662 dw[4] = sh->urb_grf_start << GEN6_VS_DW4_URB_GRF_START__SHIFT |
2663 1 << GEN6_VS_DW4_URB_READ_LEN__SHIFT;
2664
2665 dw[5] = GEN6_VS_DW5_CACHE_DISABLE |
2666 GEN6_VS_DW5_VS_ENABLE;
2667 if (cmd_gen(cmd) >= INTEL_GEN(7.5))
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002668 dw[5] |= (sh->max_threads - 1) << GEN75_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002669 else
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002670 dw[5] |= (sh->max_threads - 1) << GEN6_VS_DW5_MAX_THREADS__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002671
2672 assert(!sh->per_thread_scratch_size);
Chia-I Wu29e6f502014-11-24 14:27:29 +08002673}
2674
2675static void gen6_meta_disabled(struct intel_cmd *cmd)
2676{
Chia-I Wu6032b892014-10-17 14:47:18 +08002677 uint32_t *dw;
2678
2679 CMD_ASSERT(cmd, 6, 6);
2680
Chia-I Wu6032b892014-10-17 14:47:18 +08002681 /* 3DSTATE_CONSTANT_GS */
2682 cmd_batch_pointer(cmd, 5, &dw);
2683 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (5 - 2);
2684 dw[1] = 0;
2685 dw[2] = 0;
2686 dw[3] = 0;
2687 dw[4] = 0;
2688
2689 /* 3DSTATE_GS */
2690 cmd_batch_pointer(cmd, 7, &dw);
2691 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2692 dw[1] = 0;
2693 dw[2] = 0;
2694 dw[3] = 0;
2695 dw[4] = 1 << GEN6_GS_DW4_URB_READ_LEN__SHIFT;
2696 dw[5] = GEN6_GS_DW5_STATISTICS;
2697 dw[6] = 0;
2698
Chia-I Wu6032b892014-10-17 14:47:18 +08002699 /* 3DSTATE_SF */
2700 cmd_batch_pointer(cmd, 20, &dw);
2701 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (20 - 2);
2702 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2703 memset(&dw[2], 0, 18 * sizeof(*dw));
2704}
2705
2706static void gen7_meta_disabled(struct intel_cmd *cmd)
2707{
2708 uint32_t *dw;
2709
2710 CMD_ASSERT(cmd, 7, 7.5);
2711
Chia-I Wu6032b892014-10-17 14:47:18 +08002712 /* 3DSTATE_CONSTANT_HS */
2713 cmd_batch_pointer(cmd, 7, &dw);
2714 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_HS) | (7 - 2);
2715 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2716
2717 /* 3DSTATE_HS */
2718 cmd_batch_pointer(cmd, 7, &dw);
2719 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_HS) | (7 - 2);
2720 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2721
2722 /* 3DSTATE_TE */
2723 cmd_batch_pointer(cmd, 4, &dw);
2724 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_TE) | (4 - 2);
2725 memset(&dw[1], 0, sizeof(*dw) * (4 - 1));
2726
2727 /* 3DSTATE_CONSTANT_DS */
2728 cmd_batch_pointer(cmd, 7, &dw);
2729 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_CONSTANT_DS) | (7 - 2);
2730 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2731
2732 /* 3DSTATE_DS */
2733 cmd_batch_pointer(cmd, 6, &dw);
2734 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_DS) | (6 - 2);
2735 memset(&dw[1], 0, sizeof(*dw) * (6 - 1));
2736
2737 /* 3DSTATE_CONSTANT_GS */
2738 cmd_batch_pointer(cmd, 7, &dw);
2739 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_GS) | (7 - 2);
2740 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2741
2742 /* 3DSTATE_GS */
2743 cmd_batch_pointer(cmd, 7, &dw);
2744 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_GS) | (7 - 2);
2745 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2746
2747 /* 3DSTATE_STREAMOUT */
2748 cmd_batch_pointer(cmd, 3, &dw);
2749 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_STREAMOUT) | (3 - 2);
2750 memset(&dw[1], 0, sizeof(*dw) * (3 - 1));
2751
Chia-I Wu6032b892014-10-17 14:47:18 +08002752 /* 3DSTATE_SF */
2753 cmd_batch_pointer(cmd, 7, &dw);
2754 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SF) | (7 - 2);
2755 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
2756
2757 /* 3DSTATE_SBE */
2758 cmd_batch_pointer(cmd, 14, &dw);
2759 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_SBE) | (14 - 2);
2760 dw[1] = 1 << GEN7_SBE_DW1_URB_READ_LEN__SHIFT;
2761 memset(&dw[2], 0, sizeof(*dw) * (14 - 2));
Chia-I Wu29e6f502014-11-24 14:27:29 +08002762}
Chia-I Wu3adf7212014-10-24 15:34:07 +08002763
Chia-I Wu29e6f502014-11-24 14:27:29 +08002764static void gen6_meta_clip(struct intel_cmd *cmd)
2765{
2766 const struct intel_cmd_meta *meta = cmd->bind.meta;
2767 uint32_t *dw;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002768
Chia-I Wu29e6f502014-11-24 14:27:29 +08002769 /* 3DSTATE_CLIP */
2770 cmd_batch_pointer(cmd, 4, &dw);
2771 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CLIP) | (4 - 2);
2772 dw[1] = 0;
2773 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2774 dw[2] = GEN6_CLIP_DW2_CLIP_ENABLE |
2775 GEN6_CLIP_DW2_CLIPMODE_REJECT_ALL;
2776 } else {
Chia-I Wu3adf7212014-10-24 15:34:07 +08002777 dw[2] = 0;
Chia-I Wu3adf7212014-10-24 15:34:07 +08002778 }
Chia-I Wu29e6f502014-11-24 14:27:29 +08002779 dw[3] = 0;
Chia-I Wu6032b892014-10-17 14:47:18 +08002780}
2781
2782static void gen6_meta_wm(struct intel_cmd *cmd)
2783{
2784 const struct intel_cmd_meta *meta = cmd->bind.meta;
2785 uint32_t *dw;
2786
2787 CMD_ASSERT(cmd, 6, 7.5);
2788
2789 cmd_wa_gen6_pre_multisample_depth_flush(cmd);
2790
2791 /* 3DSTATE_MULTISAMPLE */
2792 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
2793 cmd_batch_pointer(cmd, 4, &dw);
2794 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (4 - 2);
2795 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2796 (meta->samples <= 4) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4 :
2797 GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
2798 dw[2] = 0;
2799 dw[3] = 0;
2800 } else {
2801 cmd_batch_pointer(cmd, 3, &dw);
2802 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE) | (3 - 2);
2803 dw[1] = (meta->samples <= 1) ? GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1 :
2804 GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
2805 dw[2] = 0;
2806 }
2807
2808 /* 3DSTATE_SAMPLE_MASK */
2809 cmd_batch_pointer(cmd, 2, &dw);
2810 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK) | (2 - 2);
2811 dw[1] = (1 << meta->samples) - 1;
2812
2813 /* 3DSTATE_DRAWING_RECTANGLE */
2814 cmd_batch_pointer(cmd, 4, &dw);
2815 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_DRAWING_RECTANGLE) | (4 - 2);
Chia-I Wu7ee64472015-01-29 00:35:56 +08002816 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
2817 /* unused */
2818 dw[1] = 0;
2819 dw[2] = 0;
2820 } else {
2821 dw[1] = meta->dst.y << 16 | meta->dst.x;
2822 dw[2] = (meta->dst.y + meta->height - 1) << 16 |
2823 (meta->dst.x + meta->width - 1);
2824 }
Chia-I Wu6032b892014-10-17 14:47:18 +08002825 dw[3] = 0;
2826}
2827
2828static uint32_t gen6_meta_ps_constants(struct intel_cmd *cmd)
2829{
2830 const struct intel_cmd_meta *meta = cmd->bind.meta;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002831 uint32_t offset_x, offset_y;
Chia-I Wu6032b892014-10-17 14:47:18 +08002832 /* one GPR */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06002833 uint32_t consts[8];
2834 uint32_t const_count;
Chia-I Wu6032b892014-10-17 14:47:18 +08002835
2836 CMD_ASSERT(cmd, 6, 7.5);
2837
2838 /* underflow is fine here */
2839 offset_x = meta->src.x - meta->dst.x;
2840 offset_y = meta->src.y - meta->dst.y;
2841
2842 switch (meta->shader_id) {
2843 case INTEL_DEV_META_FS_COPY_MEM:
2844 case INTEL_DEV_META_FS_COPY_1D:
2845 case INTEL_DEV_META_FS_COPY_1D_ARRAY:
2846 case INTEL_DEV_META_FS_COPY_2D:
2847 case INTEL_DEV_META_FS_COPY_2D_ARRAY:
2848 case INTEL_DEV_META_FS_COPY_2D_MS:
2849 consts[0] = offset_x;
2850 consts[1] = offset_y;
2851 consts[2] = meta->src.layer;
2852 consts[3] = meta->src.lod;
2853 const_count = 4;
2854 break;
2855 case INTEL_DEV_META_FS_COPY_1D_TO_MEM:
2856 case INTEL_DEV_META_FS_COPY_1D_ARRAY_TO_MEM:
2857 case INTEL_DEV_META_FS_COPY_2D_TO_MEM:
2858 case INTEL_DEV_META_FS_COPY_2D_ARRAY_TO_MEM:
2859 case INTEL_DEV_META_FS_COPY_2D_MS_TO_MEM:
2860 consts[0] = offset_x;
2861 consts[1] = offset_y;
2862 consts[2] = meta->src.layer;
2863 consts[3] = meta->src.lod;
2864 consts[4] = meta->src.x;
2865 consts[5] = meta->width;
2866 const_count = 6;
2867 break;
2868 case INTEL_DEV_META_FS_COPY_MEM_TO_IMG:
2869 consts[0] = offset_x;
2870 consts[1] = offset_y;
2871 consts[2] = meta->width;
2872 const_count = 3;
2873 break;
2874 case INTEL_DEV_META_FS_CLEAR_COLOR:
2875 consts[0] = meta->clear_val[0];
2876 consts[1] = meta->clear_val[1];
2877 consts[2] = meta->clear_val[2];
2878 consts[3] = meta->clear_val[3];
2879 const_count = 4;
2880 break;
2881 case INTEL_DEV_META_FS_CLEAR_DEPTH:
2882 consts[0] = meta->clear_val[0];
Chia-I Wu429a0aa2014-10-24 11:57:51 +08002883 consts[1] = meta->clear_val[1];
2884 const_count = 2;
Chia-I Wu6032b892014-10-17 14:47:18 +08002885 break;
2886 case INTEL_DEV_META_FS_RESOLVE_2X:
2887 case INTEL_DEV_META_FS_RESOLVE_4X:
2888 case INTEL_DEV_META_FS_RESOLVE_8X:
2889 case INTEL_DEV_META_FS_RESOLVE_16X:
2890 consts[0] = offset_x;
2891 consts[1] = offset_y;
2892 const_count = 2;
2893 break;
2894 default:
2895 assert(!"unknown meta shader id");
2896 const_count = 0;
2897 break;
2898 }
2899
2900 /* this can be skipped but it makes state dumping prettier */
2901 memset(&consts[const_count], 0, sizeof(consts[0]) * (8 - const_count));
2902
2903 return cmd_state_write(cmd, INTEL_CMD_ITEM_BLOB, 32, 8, consts);
2904}
2905
2906static void gen6_meta_ps(struct intel_cmd *cmd)
2907{
2908 const struct intel_cmd_meta *meta = cmd->bind.meta;
2909 const struct intel_pipeline_shader *sh =
2910 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
2911 uint32_t offset, *dw;
2912
2913 CMD_ASSERT(cmd, 6, 6);
2914
Chia-I Wu29e6f502014-11-24 14:27:29 +08002915 if (meta->mode != INTEL_CMD_META_FS_RECT) {
2916 /* 3DSTATE_CONSTANT_PS */
2917 cmd_batch_pointer(cmd, 5, &dw);
2918 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2);
2919 dw[1] = 0;
2920 dw[2] = 0;
2921 dw[3] = 0;
2922 dw[4] = 0;
2923
2924 /* 3DSTATE_WM */
2925 cmd_batch_pointer(cmd, 9, &dw);
2926 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2927 dw[1] = 0;
2928 dw[2] = 0;
2929 dw[3] = 0;
Chia-I Wu73520ac2015-02-19 11:17:45 -07002930
2931 switch (meta->ds.op) {
2932 case INTEL_CMD_META_DS_HIZ_CLEAR:
2933 dw[4] = GEN6_WM_DW4_DEPTH_CLEAR;
2934 break;
2935 case INTEL_CMD_META_DS_HIZ_RESOLVE:
2936 dw[4] = GEN6_WM_DW4_HIZ_RESOLVE;
2937 break;
2938 case INTEL_CMD_META_DS_RESOLVE:
2939 dw[4] = GEN6_WM_DW4_DEPTH_RESOLVE;
2940 break;
2941 default:
2942 dw[4] = 0;
2943 break;
2944 }
2945
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002946 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002947 dw[6] = 0;
2948 dw[7] = 0;
2949 dw[8] = 0;
2950
Chia-I Wu3adf7212014-10-24 15:34:07 +08002951 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08002952 }
2953
Chia-I Wu3adf7212014-10-24 15:34:07 +08002954 /* a normal color write */
2955 assert(meta->dst.valid && !sh->uses);
2956
Chia-I Wu6032b892014-10-17 14:47:18 +08002957 /* 3DSTATE_CONSTANT_PS */
2958 offset = gen6_meta_ps_constants(cmd);
2959 cmd_batch_pointer(cmd, 5, &dw);
2960 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (5 - 2) |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002961 1 << GEN6_CONSTANT_DW0_BUFFER_ENABLES__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08002962 dw[1] = offset;
2963 dw[2] = 0;
2964 dw[3] = 0;
2965 dw[4] = 0;
2966
2967 /* 3DSTATE_WM */
2968 offset = emit_shader(cmd, sh);
2969 cmd_batch_pointer(cmd, 9, &dw);
2970 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (9 - 2);
2971 dw[1] = offset;
2972 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
2973 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08002974 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08002975 dw[4] = sh->urb_grf_start << GEN6_WM_DW4_URB_GRF_START0__SHIFT;
Chia-I Wu3f4bd102014-12-19 13:14:42 +08002976 dw[5] = (sh->max_threads - 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002977 GEN6_WM_DW5_PS_DISPATCH_ENABLE |
2978 GEN6_PS_DISPATCH_16 << GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT;
Chia-I Wu005c47c2014-10-22 13:49:13 +08002979
Chia-I Wu6032b892014-10-17 14:47:18 +08002980 dw[6] = sh->in_count << GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07002981 GEN6_WM_DW6_PS_POSOFFSET_NONE |
Chia-I Wu6032b892014-10-17 14:47:18 +08002982 GEN6_WM_DW6_ZW_INTERP_PIXEL |
2983 sh->barycentric_interps << GEN6_WM_DW6_BARYCENTRIC_INTERP__SHIFT |
2984 GEN6_WM_DW6_POINT_RASTRULE_UPPER_RIGHT;
2985 if (meta->samples > 1) {
2986 dw[6] |= GEN6_WM_DW6_MSRASTMODE_ON_PATTERN |
2987 GEN6_WM_DW6_MSDISPMODE_PERPIXEL;
2988 } else {
2989 dw[6] |= GEN6_WM_DW6_MSRASTMODE_OFF_PIXEL |
2990 GEN6_WM_DW6_MSDISPMODE_PERSAMPLE;
2991 }
2992 dw[7] = 0;
2993 dw[8] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08002994
2995 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08002996}
2997
2998static void gen7_meta_ps(struct intel_cmd *cmd)
2999{
3000 const struct intel_cmd_meta *meta = cmd->bind.meta;
3001 const struct intel_pipeline_shader *sh =
3002 intel_dev_get_meta_shader(cmd->dev, meta->shader_id);
3003 uint32_t offset, *dw;
3004
3005 CMD_ASSERT(cmd, 7, 7.5);
3006
Chia-I Wu29e6f502014-11-24 14:27:29 +08003007 if (meta->mode != INTEL_CMD_META_FS_RECT) {
3008 /* 3DSTATE_WM */
3009 cmd_batch_pointer(cmd, 3, &dw);
3010 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu73520ac2015-02-19 11:17:45 -07003011
3012 switch (meta->ds.op) {
3013 case INTEL_CMD_META_DS_HIZ_CLEAR:
3014 dw[1] = GEN7_WM_DW1_DEPTH_CLEAR;
3015 break;
3016 case INTEL_CMD_META_DS_HIZ_RESOLVE:
3017 dw[1] = GEN7_WM_DW1_HIZ_RESOLVE;
3018 break;
3019 case INTEL_CMD_META_DS_RESOLVE:
3020 dw[1] = GEN7_WM_DW1_DEPTH_RESOLVE;
3021 break;
3022 default:
3023 dw[1] = 0;
3024 break;
3025 }
3026
3027 dw[2] = 0;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003028
3029 /* 3DSTATE_CONSTANT_GS */
3030 cmd_batch_pointer(cmd, 7, &dw);
3031 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
3032 memset(&dw[1], 0, sizeof(*dw) * (7 - 1));
3033
3034 /* 3DSTATE_PS */
3035 cmd_batch_pointer(cmd, 8, &dw);
3036 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3037 dw[1] = 0;
3038 dw[2] = 0;
3039 dw[3] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003040 /* required to avoid hangs */
3041 dw[4] = GEN6_PS_DISPATCH_8 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT |
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003042 (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003043 dw[5] = 0;
3044 dw[6] = 0;
3045 dw[7] = 0;
3046
Chia-I Wu3adf7212014-10-24 15:34:07 +08003047 return;
Chia-I Wu29e6f502014-11-24 14:27:29 +08003048 }
3049
Chia-I Wu3adf7212014-10-24 15:34:07 +08003050 /* a normal color write */
3051 assert(meta->dst.valid && !sh->uses);
3052
Chia-I Wu6032b892014-10-17 14:47:18 +08003053 /* 3DSTATE_WM */
3054 cmd_batch_pointer(cmd, 3, &dw);
3055 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_WM) | (3 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003056 dw[1] = GEN7_WM_DW1_PS_DISPATCH_ENABLE |
Chia-I Wu6032b892014-10-17 14:47:18 +08003057 GEN7_WM_DW1_ZW_INTERP_PIXEL |
3058 sh->barycentric_interps << GEN7_WM_DW1_BARYCENTRIC_INTERP__SHIFT |
3059 GEN7_WM_DW1_POINT_RASTRULE_UPPER_RIGHT;
3060 dw[2] = 0;
3061
3062 /* 3DSTATE_CONSTANT_PS */
3063 offset = gen6_meta_ps_constants(cmd);
3064 cmd_batch_pointer(cmd, 7, &dw);
3065 dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_CONSTANT_PS) | (7 - 2);
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003066 dw[1] = 1 << GEN7_CONSTANT_DW1_BUFFER0_READ_LEN__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003067 dw[2] = 0;
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003068 dw[3] = offset | GEN7_MOCS_L3_WB;
Chia-I Wu6032b892014-10-17 14:47:18 +08003069 dw[4] = 0;
3070 dw[5] = 0;
3071 dw[6] = 0;
3072
3073 /* 3DSTATE_PS */
3074 offset = emit_shader(cmd, sh);
3075 cmd_batch_pointer(cmd, 8, &dw);
3076 dw[0] = GEN7_RENDER_CMD(3D, 3DSTATE_PS) | (8 - 2);
3077 dw[1] = offset;
3078 dw[2] = (sh->sampler_count + 3) / 4 << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT |
3079 sh->surface_count << GEN6_THREADDISP_BINDING_TABLE_SIZE__SHIFT;
Chia-I Wu784d3042014-12-19 14:30:04 +08003080 dw[3] = 0; /* scratch */
Chia-I Wu6032b892014-10-17 14:47:18 +08003081
3082 dw[4] = GEN7_PS_DW4_PUSH_CONSTANT_ENABLE |
3083 GEN7_PS_DW4_POSOFFSET_NONE |
Chia-I Wu97aa4de2015-03-05 15:43:16 -07003084 GEN6_PS_DISPATCH_16 << GEN7_PS_DW4_DISPATCH_MODE__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003085
3086 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003087 dw[4] |= (sh->max_threads - 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu6032b892014-10-17 14:47:18 +08003088 dw[4] |= ((1 << meta->samples) - 1) << GEN75_PS_DW4_SAMPLE_MASK__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003089 } else {
Chia-I Wu3f4bd102014-12-19 13:14:42 +08003090 dw[4] |= (sh->max_threads - 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT;
Chia-I Wu05990612014-11-25 11:36:35 +08003091 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003092
3093 dw[5] = sh->urb_grf_start << GEN7_PS_DW5_URB_GRF_START0__SHIFT;
3094 dw[6] = 0;
3095 dw[7] = 0;
Chia-I Wu784d3042014-12-19 14:30:04 +08003096
3097 assert(!sh->per_thread_scratch_size);
Chia-I Wu6032b892014-10-17 14:47:18 +08003098}
3099
3100static void gen6_meta_depth_buffer(struct intel_cmd *cmd)
3101{
3102 const struct intel_cmd_meta *meta = cmd->bind.meta;
Courtney Goeltzenleuchter1856d6f2015-09-01 17:30:39 -06003103 const struct intel_att_view *view = &meta->ds.view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003104
3105 CMD_ASSERT(cmd, 6, 7.5);
3106
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003107 if (!view) {
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003108 /* all zeros */
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003109 static const struct intel_att_view null_view;
3110 view = &null_view;
Chia-I Wu6032b892014-10-17 14:47:18 +08003111 }
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003112
3113 cmd_wa_gen6_pre_ds_flush(cmd);
Chia-I Wu3d4d4a62015-07-09 10:34:10 +08003114 gen6_3DSTATE_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
3115 gen6_3DSTATE_STENCIL_BUFFER(cmd, view, meta->ds.optimal);
3116 gen6_3DSTATE_HIER_DEPTH_BUFFER(cmd, view, meta->ds.optimal);
Chia-I Wube2f0ad2014-10-24 09:49:50 +08003117
3118 if (cmd_gen(cmd) >= INTEL_GEN(7))
3119 gen7_3DSTATE_CLEAR_PARAMS(cmd, 0);
3120 else
3121 gen6_3DSTATE_CLEAR_PARAMS(cmd, 0);
Chia-I Wu6032b892014-10-17 14:47:18 +08003122}
3123
Chia-I Wu862c5572015-03-28 15:23:55 +08003124static bool cmd_alloc_dset_data(struct intel_cmd *cmd,
3125 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003126 const struct intel_pipeline_layout *pipeline_layout)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003127{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003128 if (data->set_offset_count < pipeline_layout->layout_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003129 if (data->set_offsets)
3130 intel_free(cmd, data->set_offsets);
Chia-I Wuf8385062015-01-04 16:27:24 +08003131
Chia-I Wu862c5572015-03-28 15:23:55 +08003132 data->set_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003133 sizeof(data->set_offsets[0]) * pipeline_layout->layout_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003134 sizeof(data->set_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003135 if (!data->set_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003136 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003137 data->set_offset_count = 0;
3138 return false;
Chia-I Wuf8385062015-01-04 16:27:24 +08003139 }
3140
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003141 data->set_offset_count = pipeline_layout->layout_count;
Chia-I Wuf8385062015-01-04 16:27:24 +08003142 }
3143
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003144 if (data->dynamic_offset_count < pipeline_layout->total_dynamic_desc_count) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003145 if (data->dynamic_offsets)
3146 intel_free(cmd, data->dynamic_offsets);
3147
3148 data->dynamic_offsets = intel_alloc(cmd,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003149 sizeof(data->dynamic_offsets[0]) * pipeline_layout->total_dynamic_desc_count,
Tony Barbour8205d902015-04-16 15:59:00 -06003150 sizeof(data->dynamic_offsets[0]), VK_SYSTEM_ALLOC_TYPE_INTERNAL);
Chia-I Wu862c5572015-03-28 15:23:55 +08003151 if (!data->dynamic_offsets) {
Tony Barbour8205d902015-04-16 15:59:00 -06003152 cmd_fail(cmd, VK_ERROR_OUT_OF_HOST_MEMORY);
Chia-I Wu862c5572015-03-28 15:23:55 +08003153 data->dynamic_offset_count = 0;
3154 return false;
3155 }
3156
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003157 data->dynamic_offset_count = pipeline_layout->total_dynamic_desc_count;
Chia-I Wu862c5572015-03-28 15:23:55 +08003158 }
3159
3160 return true;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003161}
3162
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003163static void cmd_bind_graphics_pipeline(struct intel_cmd *cmd,
3164 const struct intel_pipeline *pipeline)
3165{
3166 cmd->bind.pipeline.graphics = pipeline;
3167
3168 cmd_alloc_dset_data(cmd, &cmd->bind.dset.graphics_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003169 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003170}
3171
3172static void cmd_bind_compute_pipeline(struct intel_cmd *cmd,
3173 const struct intel_pipeline *pipeline)
3174{
3175 cmd->bind.pipeline.compute = pipeline;
3176
3177 cmd_alloc_dset_data(cmd, &cmd->bind.dset.compute_data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003178 pipeline->pipeline_layout);
Chia-I Wu6097f3a2015-04-17 02:00:54 +08003179}
3180
Chia-I Wu862c5572015-03-28 15:23:55 +08003181static void cmd_copy_dset_data(struct intel_cmd *cmd,
3182 struct intel_cmd_dset_data *data,
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003183 const struct intel_pipeline_layout *pipeline_layout,
Chia-I Wu862c5572015-03-28 15:23:55 +08003184 uint32_t index,
3185 const struct intel_desc_set *set,
3186 const uint32_t *dynamic_offsets)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003187{
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003188 const struct intel_desc_layout *layout = pipeline_layout->layouts[index];
Chia-I Wuf8385062015-01-04 16:27:24 +08003189
Chia-I Wu862c5572015-03-28 15:23:55 +08003190 assert(index < data->set_offset_count);
3191 data->set_offsets[index] = set->region_begin;
Chia-I Wuf8385062015-01-04 16:27:24 +08003192
Chia-I Wu862c5572015-03-28 15:23:55 +08003193 if (layout->dynamic_desc_count) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003194 assert(pipeline_layout->dynamic_desc_indices[index] +
Chia-I Wu862c5572015-03-28 15:23:55 +08003195 layout->dynamic_desc_count - 1 < data->dynamic_offset_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003196
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003197 memcpy(&data->dynamic_offsets[pipeline_layout->dynamic_desc_indices[index]],
Chia-I Wu862c5572015-03-28 15:23:55 +08003198 dynamic_offsets,
3199 sizeof(dynamic_offsets[0]) * layout->dynamic_desc_count);
Chia-I Wuf8385062015-01-04 16:27:24 +08003200 }
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003201}
3202
Chia-I Wu3b04af52014-11-08 10:48:20 +08003203static void cmd_bind_vertex_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003204 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003205 VkDeviceSize offset, uint32_t binding)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003206{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003207 /* TODOVV: verify */
3208 assert(!(binding >= ARRAY_SIZE(cmd->bind.vertex.buf)) && "binding exceeds buf size");
Chia-I Wu3b04af52014-11-08 10:48:20 +08003209
Chia-I Wu714df452015-01-01 07:55:04 +08003210 cmd->bind.vertex.buf[binding] = buf;
Chia-I Wu3b04af52014-11-08 10:48:20 +08003211 cmd->bind.vertex.offset[binding] = offset;
3212}
3213
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003214static void cmd_bind_index_data(struct intel_cmd *cmd,
Chia-I Wu714df452015-01-01 07:55:04 +08003215 const struct intel_buf *buf,
Tony Barbour8205d902015-04-16 15:59:00 -06003216 VkDeviceSize offset, VkIndexType type)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003217{
Chia-I Wu714df452015-01-01 07:55:04 +08003218 cmd->bind.index.buf = buf;
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003219 cmd->bind.index.offset = offset;
3220 cmd->bind.index.type = type;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003221}
3222
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003223static void cmd_bind_viewport_state(struct intel_cmd *cmd,
Tony Barbourde4124d2015-07-03 10:33:54 -06003224 const struct intel_dynamic_viewport *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003225{
3226 cmd->bind.state.viewport = state;
3227}
3228
Cody Northrope4bc6942015-08-26 10:01:32 -06003229static void cmd_bind_line_width_state(struct intel_cmd *cmd,
3230 const struct intel_dynamic_line_width *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003231{
Cody Northrope4bc6942015-08-26 10:01:32 -06003232 cmd->bind.state.line_width = state;
Cody Northropf5bd2252015-08-17 11:10:49 -06003233}
3234
Cody Northrope4bc6942015-08-26 10:01:32 -06003235static void cmd_bind_depth_bias_state(struct intel_cmd *cmd,
3236 const struct intel_dynamic_depth_bias *state)
Cody Northropf5bd2252015-08-17 11:10:49 -06003237{
Cody Northrope4bc6942015-08-26 10:01:32 -06003238 cmd->bind.state.depth_bias = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003239}
3240
Cody Northrope4bc6942015-08-26 10:01:32 -06003241static void cmd_bind_depth_bounds_state(struct intel_cmd *cmd,
3242 const struct intel_dynamic_depth_bounds *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003243{
Cody Northrope4bc6942015-08-26 10:01:32 -06003244 cmd->bind.state.depth_bounds = state;
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003245}
3246
Cody Northrop2605cb02015-08-18 15:21:16 -06003247static void cmd_bind_stencil_state(struct intel_cmd *cmd,
3248 const struct intel_dynamic_stencil *state)
3249{
3250 cmd->bind.state.stencil = state;
3251}
3252
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003253static void cmd_bind_blend_state(struct intel_cmd *cmd,
Cody Northrope4bc6942015-08-26 10:01:32 -06003254 const struct intel_dynamic_blend *state)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003255{
3256 cmd->bind.state.blend = state;
3257}
3258
Chia-I Wuf98dd882015-02-10 04:17:47 +08003259static uint32_t cmd_get_max_surface_write(const struct intel_cmd *cmd)
3260{
3261 const struct intel_pipeline *pipeline = cmd->bind.pipeline.graphics;
3262 struct intel_pipeline_rmap *rmaps[5] = {
3263 pipeline->vs.rmap,
3264 pipeline->tcs.rmap,
3265 pipeline->tes.rmap,
3266 pipeline->gs.rmap,
3267 pipeline->fs.rmap,
3268 };
3269 uint32_t max_write;
3270 int i;
3271
3272 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >= GEN6_SURFACE_STATE__SIZE);
3273 STATIC_ASSERT(GEN6_ALIGNMENT_SURFACE_STATE >=
3274 GEN6_ALIGNMENT_BINDING_TABLE_STATE);
3275
3276 /* pad first */
3277 max_write = GEN6_ALIGNMENT_SURFACE_STATE;
3278
3279 for (i = 0; i < ARRAY_SIZE(rmaps); i++) {
3280 const struct intel_pipeline_rmap *rmap = rmaps[i];
3281 const uint32_t surface_count = (rmap) ?
3282 rmap->rt_count + rmap->texture_resource_count +
3283 rmap->resource_count + rmap->uav_count : 0;
3284
3285 if (surface_count) {
3286 /* SURFACE_STATEs */
3287 max_write += GEN6_ALIGNMENT_SURFACE_STATE * surface_count;
3288
3289 /* BINDING_TABLE_STATE */
3290 max_write += u_align(sizeof(uint32_t) * surface_count,
3291 GEN6_ALIGNMENT_SURFACE_STATE);
3292 }
3293 }
3294
3295 return max_write;
3296}
3297
3298static void cmd_adjust_state_base_address(struct intel_cmd *cmd)
3299{
3300 struct intel_cmd_writer *writer = &cmd->writers[INTEL_CMD_WRITER_SURFACE];
3301 const uint32_t cur_surface_offset = writer->used - writer->sba_offset;
3302 uint32_t max_surface_write;
3303
3304 /* enough for src and dst SURFACE_STATEs plus BINDING_TABLE_STATE */
3305 if (cmd->bind.meta)
3306 max_surface_write = 64 * sizeof(uint32_t);
3307 else
3308 max_surface_write = cmd_get_max_surface_write(cmd);
3309
3310 /* there is a 64KB limit on BINDING_TABLE_STATEs */
3311 if (cur_surface_offset + max_surface_write > 64 * 1024) {
3312 /* SBA expects page-aligned addresses */
3313 writer->sba_offset = writer->used & ~0xfff;
3314
3315 assert((writer->used & 0xfff) + max_surface_write <= 64 * 1024);
3316
3317 cmd_batch_state_base_address(cmd);
3318 }
3319}
3320
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003321static void cmd_draw(struct intel_cmd *cmd,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003322 uint32_t vertex_start,
3323 uint32_t vertex_count,
3324 uint32_t instance_start,
3325 uint32_t instance_count,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003326 bool indexed,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003327 uint32_t vertex_base)
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003328{
3329 const struct intel_pipeline *p = cmd->bind.pipeline.graphics;
Chia-I Wu08cd6e92015-02-11 13:44:50 -07003330 const uint32_t surface_writer_used U_ASSERT_ONLY =
Chia-I Wuf98dd882015-02-10 04:17:47 +08003331 cmd->writers[INTEL_CMD_WRITER_SURFACE].used;
3332
3333 cmd_adjust_state_base_address(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003334
3335 emit_bounded_states(cmd);
3336
Chia-I Wuf98dd882015-02-10 04:17:47 +08003337 /* sanity check on cmd_get_max_surface_write() */
3338 assert(cmd->writers[INTEL_CMD_WRITER_SURFACE].used -
3339 surface_writer_used <= cmd_get_max_surface_write(cmd));
3340
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003341 if (indexed) {
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003342 assert(!(p->primitive_restart && !gen6_can_primitive_restart(cmd)) && "Primitive restart unsupported on this device");
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003343
3344 if (cmd_gen(cmd) >= INTEL_GEN(7.5)) {
3345 gen75_3DSTATE_VF(cmd, p->primitive_restart,
3346 p->primitive_restart_index);
Chia-I Wu714df452015-01-01 07:55:04 +08003347 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wuc29afdd2014-10-14 13:22:31 +08003348 cmd->bind.index.offset, cmd->bind.index.type,
3349 false);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003350 } else {
Chia-I Wu714df452015-01-01 07:55:04 +08003351 gen6_3DSTATE_INDEX_BUFFER(cmd, cmd->bind.index.buf,
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003352 cmd->bind.index.offset, cmd->bind.index.type,
3353 p->primitive_restart);
3354 }
3355 } else {
3356 assert(!vertex_base);
3357 }
3358
3359 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3360 gen7_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3361 vertex_start, instance_count, instance_start, vertex_base);
3362 } else {
3363 gen6_3DPRIMITIVE(cmd, p->prim_type, indexed, vertex_count,
3364 vertex_start, instance_count, instance_start, vertex_base);
3365 }
Chia-I Wu48c283d2014-08-25 23:13:46 +08003366
Chia-I Wu707a29e2014-08-27 12:51:47 +08003367 cmd->bind.draw_count++;
Chia-I Wubbc7d912015-02-27 14:59:50 -07003368 cmd->bind.render_pass_changed = false;
Chia-I Wu48c283d2014-08-25 23:13:46 +08003369 /* need to re-emit all workarounds */
3370 cmd->bind.wa_flags = 0;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003371
3372 if (intel_debug & INTEL_DEBUG_NOCACHE)
3373 cmd_batch_flush_all(cmd);
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003374}
3375
Chia-I Wuc14d1562014-10-17 09:49:22 +08003376void cmd_draw_meta(struct intel_cmd *cmd, const struct intel_cmd_meta *meta)
3377{
Chia-I Wu6032b892014-10-17 14:47:18 +08003378 cmd->bind.meta = meta;
3379
Chia-I Wuf98dd882015-02-10 04:17:47 +08003380 cmd_adjust_state_base_address(cmd);
3381
Chia-I Wu6032b892014-10-17 14:47:18 +08003382 cmd_wa_gen6_pre_depth_stall_write(cmd);
Chia-I Wub4077f92014-10-28 11:19:14 +08003383 cmd_wa_gen6_pre_command_scoreboard_stall(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003384
3385 gen6_meta_dynamic_states(cmd);
3386 gen6_meta_surface_states(cmd);
3387
3388 if (cmd_gen(cmd) >= INTEL_GEN(7)) {
3389 gen7_meta_urb(cmd);
3390 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003391 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003392 gen7_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003393 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003394 gen6_meta_wm(cmd);
3395 gen7_meta_ps(cmd);
3396 gen6_meta_depth_buffer(cmd);
3397
3398 cmd_wa_gen7_post_command_cs_stall(cmd);
3399 cmd_wa_gen7_post_command_depth_stall(cmd);
3400
Chia-I Wu29e6f502014-11-24 14:27:29 +08003401 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3402 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003403 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003404 } else {
3405 gen7_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3406 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003407 } else {
3408 gen6_meta_urb(cmd);
3409 gen6_meta_vf(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003410 gen6_meta_vs(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003411 gen6_meta_disabled(cmd);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003412 gen6_meta_clip(cmd);
Chia-I Wu6032b892014-10-17 14:47:18 +08003413 gen6_meta_wm(cmd);
3414 gen6_meta_ps(cmd);
3415 gen6_meta_depth_buffer(cmd);
3416
Chia-I Wu29e6f502014-11-24 14:27:29 +08003417 if (meta->mode == INTEL_CMD_META_VS_POINTS) {
3418 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_POINTLIST, false,
Chia-I Wu4d344e62014-12-20 21:06:04 +08003419 meta->width * meta->height, 0, 1, 0, 0);
Chia-I Wu29e6f502014-11-24 14:27:29 +08003420 } else {
3421 gen6_3DPRIMITIVE(cmd, GEN6_3DPRIM_RECTLIST, false, 3, 0, 1, 0, 0);
3422 }
Chia-I Wu6032b892014-10-17 14:47:18 +08003423 }
3424
3425 cmd->bind.draw_count++;
3426 /* need to re-emit all workarounds */
3427 cmd->bind.wa_flags = 0;
3428
3429 cmd->bind.meta = NULL;
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003430
Chia-I Wubbc7d912015-02-27 14:59:50 -07003431 /* make the normal path believe the render pass has changed */
3432 cmd->bind.render_pass_changed = true;
3433
Chia-I Wubeb07aa2014-11-22 02:58:40 +08003434 if (intel_debug & INTEL_DEBUG_NOCACHE)
3435 cmd_batch_flush_all(cmd);
Chia-I Wuc14d1562014-10-17 09:49:22 +08003436}
3437
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003438static void cmd_exec(struct intel_cmd *cmd, struct intel_bo *bo)
3439{
3440 const uint8_t cmd_len = 2;
3441 uint32_t *dw;
3442 uint32_t pos;
3443
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003444 assert(!(cmd_gen(cmd) < INTEL_GEN(7.5)) && "Invalid GPU version");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003445
3446 pos = cmd_batch_pointer(cmd, cmd_len, &dw);
3447 dw[0] = GEN6_MI_CMD(MI_BATCH_BUFFER_START) | (cmd_len - 2) |
3448 GEN75_MI_BATCH_BUFFER_START_DW0_SECOND_LEVEL |
3449 GEN75_MI_BATCH_BUFFER_START_DW0_NON_PRIVILEGED |
3450 GEN6_MI_BATCH_BUFFER_START_DW0_USE_PPGTT;
3451
3452 cmd_batch_reloc(cmd, pos + 1, bo, 0, 0);
3453}
3454
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003455ICD_EXPORT void VKAPI vkCmdBindPipeline(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003456 VkCmdBuffer cmdBuffer,
3457 VkPipelineBindPoint pipelineBindPoint,
3458 VkPipeline pipeline)
Chia-I Wub2755562014-08-20 13:38:52 +08003459{
3460 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3461
3462 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003463 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003464 cmd_bind_compute_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003465 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003466 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003467 cmd_bind_graphics_pipeline(cmd, intel_pipeline(pipeline));
Chia-I Wub2755562014-08-20 13:38:52 +08003468 break;
3469 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003470 /* TODOVV: Move test to validation layer */
3471// cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wub2755562014-08-20 13:38:52 +08003472 break;
3473 }
3474}
3475
Tony Barbourde4124d2015-07-03 10:33:54 -06003476ICD_EXPORT void VKAPI vkCmdBindDynamicViewportState(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003477 VkCmdBuffer cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003478 VkDynamicViewportState state)
Chia-I Wub2755562014-08-20 13:38:52 +08003479{
3480 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3481
Tony Barbourde4124d2015-07-03 10:33:54 -06003482 cmd_bind_viewport_state(cmd,
3483 intel_dynamic_viewport(state));
3484}
3485
Cody Northrope4bc6942015-08-26 10:01:32 -06003486ICD_EXPORT void VKAPI vkCmdBindDynamicLineWidthState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003487 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003488 VkDynamicLineWidthState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003489{
3490 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3491
Cody Northrope4bc6942015-08-26 10:01:32 -06003492 cmd_bind_line_width_state(cmd,
3493 intel_dynamic_line_width(state));
Cody Northropf5bd2252015-08-17 11:10:49 -06003494}
3495
Cody Northrope4bc6942015-08-26 10:01:32 -06003496ICD_EXPORT void VKAPI vkCmdBindDynamicDepthBiasState(
Cody Northropf5bd2252015-08-17 11:10:49 -06003497 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003498 VkDynamicDepthBiasState state)
Cody Northropf5bd2252015-08-17 11:10:49 -06003499{
3500 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3501
Cody Northrope4bc6942015-08-26 10:01:32 -06003502 cmd_bind_depth_bias_state(cmd,
3503 intel_dynamic_depth_bias(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003504}
3505
Cody Northrope4bc6942015-08-26 10:01:32 -06003506ICD_EXPORT void VKAPI vkCmdBindDynamicBlendState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003507 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003508 VkDynamicBlendState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003509{
3510 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3511
3512 cmd_bind_blend_state(cmd,
Cody Northrope4bc6942015-08-26 10:01:32 -06003513 intel_dynamic_blend(state));
Tony Barbourde4124d2015-07-03 10:33:54 -06003514}
3515
Cody Northrope4bc6942015-08-26 10:01:32 -06003516ICD_EXPORT void VKAPI vkCmdBindDynamicDepthBoundsState(
Tony Barbourde4124d2015-07-03 10:33:54 -06003517 VkCmdBuffer cmdBuffer,
Cody Northrope4bc6942015-08-26 10:01:32 -06003518 VkDynamicDepthBoundsState state)
Tony Barbourde4124d2015-07-03 10:33:54 -06003519{
3520 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3521
Cody Northrope4bc6942015-08-26 10:01:32 -06003522 cmd_bind_depth_bounds_state(cmd,
3523 intel_dynamic_depth_bounds(state));
Cody Northrop2605cb02015-08-18 15:21:16 -06003524}
3525
3526ICD_EXPORT void VKAPI vkCmdBindDynamicStencilState(
3527 VkCmdBuffer cmdBuffer,
3528 VkDynamicStencilState state)
3529{
3530 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3531
3532 cmd_bind_stencil_state(cmd,
3533 intel_dynamic_stencil(state));
Chia-I Wub2755562014-08-20 13:38:52 +08003534}
3535
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003536ICD_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003537 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003538 VkPipelineBindPoint pipelineBindPoint,
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003539 VkPipelineLayout layout,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003540 uint32_t firstSet,
3541 uint32_t setCount,
3542 const VkDescriptorSet* pDescriptorSets,
3543 uint32_t dynamicOffsetCount,
3544 const uint32_t* pDynamicOffsets)
Chia-I Wub2755562014-08-20 13:38:52 +08003545{
3546 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003547 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wu862c5572015-03-28 15:23:55 +08003548 struct intel_cmd_dset_data *data;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003549 uint32_t offset_count = 0;
Chia-I Wu862c5572015-03-28 15:23:55 +08003550 uint32_t i;
Chia-I Wub2755562014-08-20 13:38:52 +08003551
Mark Lobodzinskia65c4632015-06-15 13:21:21 -06003552 pipeline_layout = intel_pipeline_layout(layout);
3553
Chia-I Wub2755562014-08-20 13:38:52 +08003554 switch (pipelineBindPoint) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003555 case VK_PIPELINE_BIND_POINT_COMPUTE:
Chia-I Wu862c5572015-03-28 15:23:55 +08003556 data = &cmd->bind.dset.compute_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003557 break;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003558 case VK_PIPELINE_BIND_POINT_GRAPHICS:
Chia-I Wu862c5572015-03-28 15:23:55 +08003559 data = &cmd->bind.dset.graphics_data;
Chia-I Wub2755562014-08-20 13:38:52 +08003560 break;
3561 default:
Courtney Goeltzenleuchtera54b76a2015-09-04 13:39:59 -06003562 /* TODOVV: Move test to validation layer */
3563// cmd_fail(cmd, VK_ERROR_INVALID_VALUE);
Chia-I Wu862c5572015-03-28 15:23:55 +08003564 return;
Chia-I Wub2755562014-08-20 13:38:52 +08003565 break;
3566 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003567
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003568 for (i = 0; i < setCount; i++) {
Chia-I Wu862c5572015-03-28 15:23:55 +08003569 struct intel_desc_set *dset = intel_desc_set(pDescriptorSets[i]);
3570
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003571 offset_count += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003572 if (offset_count <= dynamicOffsetCount) {
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003573 cmd_copy_dset_data(cmd, data, pipeline_layout, firstSet + i,
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003574 dset, pDynamicOffsets);
Mark Lobodzinski556f7212015-04-17 14:11:39 -05003575 pDynamicOffsets += pipeline_layout->layouts[firstSet + i]->dynamic_desc_count;
Cody Northrop1a01b1d2015-04-16 13:41:56 -06003576 }
Chia-I Wu862c5572015-03-28 15:23:55 +08003577 }
Chia-I Wub2755562014-08-20 13:38:52 +08003578}
3579
Tony Barbour8205d902015-04-16 15:59:00 -06003580
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003581ICD_EXPORT void VKAPI vkCmdBindVertexBuffers(
3582 VkCmdBuffer cmdBuffer,
3583 uint32_t startBinding,
3584 uint32_t bindingCount,
3585 const VkBuffer* pBuffers,
Tony Barbour8205d902015-04-16 15:59:00 -06003586 const VkDeviceSize* pOffsets)
Chia-I Wu3b04af52014-11-08 10:48:20 +08003587{
3588 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu3b04af52014-11-08 10:48:20 +08003589
Courtney Goeltzenleuchter46962942015-04-16 13:38:46 -06003590 for (uint32_t i = 0; i < bindingCount; i++) {
3591 struct intel_buf *buf = intel_buf(pBuffers[i]);
3592 cmd_bind_vertex_data(cmd, buf, pOffsets[i], startBinding + i);
3593 }
Chia-I Wu3b04af52014-11-08 10:48:20 +08003594}
3595
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003596ICD_EXPORT void VKAPI vkCmdBindIndexBuffer(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003597 VkCmdBuffer cmdBuffer,
3598 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003599 VkDeviceSize offset,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003600 VkIndexType indexType)
Chia-I Wub2755562014-08-20 13:38:52 +08003601{
3602 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu714df452015-01-01 07:55:04 +08003603 struct intel_buf *buf = intel_buf(buffer);
Chia-I Wub2755562014-08-20 13:38:52 +08003604
Chia-I Wu714df452015-01-01 07:55:04 +08003605 cmd_bind_index_data(cmd, buf, offset, indexType);
Chia-I Wub2755562014-08-20 13:38:52 +08003606}
3607
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003608ICD_EXPORT void VKAPI vkCmdDraw(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003609 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003610 uint32_t firstVertex,
3611 uint32_t vertexCount,
3612 uint32_t firstInstance,
3613 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003614{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003615 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003616
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003617 cmd_draw(cmd, firstVertex, vertexCount,
3618 firstInstance, instanceCount, false, 0);
Chia-I Wub2755562014-08-20 13:38:52 +08003619}
3620
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003621ICD_EXPORT void VKAPI vkCmdDrawIndexed(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003622 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003623 uint32_t firstIndex,
3624 uint32_t indexCount,
3625 int32_t vertexOffset,
3626 uint32_t firstInstance,
3627 uint32_t instanceCount)
Chia-I Wub2755562014-08-20 13:38:52 +08003628{
Chia-I Wu59c097e2014-08-21 10:51:07 +08003629 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu59c097e2014-08-21 10:51:07 +08003630
Chia-I Wu9f1722c2014-08-25 10:17:58 +08003631 cmd_draw(cmd, firstIndex, indexCount,
3632 firstInstance, instanceCount, true, vertexOffset);
Chia-I Wub2755562014-08-20 13:38:52 +08003633}
3634
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003635ICD_EXPORT void VKAPI vkCmdDrawIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003636 VkCmdBuffer cmdBuffer,
3637 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003638 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003639 uint32_t count,
3640 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003641{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003642 assert(0 && "vkCmdDrawIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003643}
3644
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003645ICD_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003646 VkCmdBuffer cmdBuffer,
3647 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003648 VkDeviceSize offset,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003649 uint32_t count,
3650 uint32_t stride)
Chia-I Wub2755562014-08-20 13:38:52 +08003651{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003652 assert(0 && "vkCmdDrawIndexedIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003653}
3654
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003655ICD_EXPORT void VKAPI vkCmdDispatch(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003656 VkCmdBuffer cmdBuffer,
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -06003657 uint32_t x,
3658 uint32_t y,
3659 uint32_t z)
Chia-I Wub2755562014-08-20 13:38:52 +08003660{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003661 assert(0 && "vkCmdDispatch not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003662}
3663
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003664ICD_EXPORT void VKAPI vkCmdDispatchIndirect(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06003665 VkCmdBuffer cmdBuffer,
3666 VkBuffer buffer,
Tony Barbour8205d902015-04-16 15:59:00 -06003667 VkDeviceSize offset)
Chia-I Wub2755562014-08-20 13:38:52 +08003668{
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003669 assert(0 && "vkCmdDisatchIndirect not implemented");
Chia-I Wub2755562014-08-20 13:38:52 +08003670}
Chia-I Wub5af7c52015-02-18 14:51:59 -07003671
Courtney Goeltzenleuchtera375b622015-07-27 14:04:01 -06003672void VKAPI vkCmdPushConstants(
3673 VkCmdBuffer cmdBuffer,
3674 VkPipelineLayout layout,
3675 VkShaderStageFlags stageFlags,
3676 uint32_t start,
3677 uint32_t length,
3678 const void* values)
3679{
3680 /* TODO: Implement */
3681}
Courtney Goeltzenleuchter07fe0662015-07-27 13:47:08 -06003682
3683VkResult VKAPI vkGetRenderAreaGranularity(
3684 VkDevice device,
3685 VkRenderPass renderPass,
3686 VkExtent2D* pGranularity)
3687{
3688 pGranularity->height = 1;
3689 pGranularity->width = 1;
3690
3691 return VK_SUCCESS;
3692}
3693
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003694ICD_EXPORT void VKAPI vkCmdBeginRenderPass(
Chia-I Wuc278df82015-07-07 11:50:03 +08003695 VkCmdBuffer cmdBuffer,
3696 const VkRenderPassBeginInfo* pRenderPassBegin,
3697 VkRenderPassContents contents)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003698{
Chia-I Wubdeed152015-07-09 12:16:29 +08003699 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3700 const struct intel_render_pass *rp =
3701 intel_render_pass(pRenderPassBegin->renderPass);
3702 const struct intel_fb *fb = intel_fb(pRenderPassBegin->framebuffer);
3703 const struct intel_att_view *view;
3704 uint32_t i;
Chia-I Wub5af7c52015-02-18 14:51:59 -07003705
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003706 /* TODOVV: */
3707 assert(!(!cmd->primary || rp->attachment_count != fb->view_count) && "Invalid RenderPass");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003708
Cody Northrop16898b02015-08-11 11:35:58 -06003709 cmd_begin_render_pass(cmd, rp, fb, 0, contents);
Chris Forbesfff9bf42015-06-15 15:26:19 +12003710
Chia-I Wubdeed152015-07-09 12:16:29 +08003711 for (i = 0; i < rp->attachment_count; i++) {
3712 const struct intel_render_pass_attachment *att = &rp->attachments[i];
Chia-I Wuc278df82015-07-07 11:50:03 +08003713 const VkClearValue *clear_val =
Cody Northropc332eef2015-08-04 11:51:03 -06003714 &pRenderPassBegin->pClearValues[i];
Chia-I Wubdeed152015-07-09 12:16:29 +08003715 VkImageSubresourceRange range;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003716
Chia-I Wubdeed152015-07-09 12:16:29 +08003717 if (!att->clear_on_load)
3718 continue;
Chris Forbesfff9bf42015-06-15 15:26:19 +12003719
Chia-I Wubdeed152015-07-09 12:16:29 +08003720 view = fb->views[i];
3721 range.baseMipLevel = view->mipLevel;
3722 range.mipLevels = 1;
Courtney Goeltzenleuchter3dee8082015-09-10 16:38:41 -06003723 range.baseArrayLayer = view->baseArrayLayer;
Chia-I Wubdeed152015-07-09 12:16:29 +08003724 range.arraySize = view->array_size;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003725
Chia-I Wubdeed152015-07-09 12:16:29 +08003726 if (view->is_rt) {
Courtney Goeltzenleuchteraeffeae2015-09-10 17:58:54 -06003727 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003728
Tony Barbourde4124d2015-07-03 10:33:54 -06003729 cmd_meta_clear_color_image(cmdBuffer, view->img,
Chia-I Wuc278df82015-07-07 11:50:03 +08003730 att->initial_layout, &clear_val->color, 1, &range);
Chia-I Wubdeed152015-07-09 12:16:29 +08003731 } else {
Courtney Goeltzenleuchteraeffeae2015-09-10 17:58:54 -06003732 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003733
Chia-I Wubdeed152015-07-09 12:16:29 +08003734 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003735 view->img, att->initial_layout,
Cody Northrop2563a032015-08-25 15:26:38 -06003736 clear_val->depthStencil.depth, clear_val->depthStencil.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003737 1, &range);
Chris Forbes4cf9d102015-06-22 18:46:05 +12003738
Chia-I Wubdeed152015-07-09 12:16:29 +08003739 if (att->stencil_clear_on_load) {
Courtney Goeltzenleuchteraeffeae2015-09-10 17:58:54 -06003740 range.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
Chris Forbes4cf9d102015-06-22 18:46:05 +12003741
Chia-I Wubdeed152015-07-09 12:16:29 +08003742 cmd_meta_clear_depth_stencil_image(cmdBuffer,
Tony Barbourde4124d2015-07-03 10:33:54 -06003743 view->img, att->initial_layout,
Cody Northrop2563a032015-08-25 15:26:38 -06003744 clear_val->depthStencil.depth, clear_val->depthStencil.stencil,
Chia-I Wubdeed152015-07-09 12:16:29 +08003745 1, &range);
3746 }
3747 }
3748 }
Chia-I Wub5af7c52015-02-18 14:51:59 -07003749}
3750
Chia-I Wuc278df82015-07-07 11:50:03 +08003751ICD_EXPORT void VKAPI vkCmdNextSubpass(
3752 VkCmdBuffer cmdBuffer,
3753 VkRenderPassContents contents)
3754{
3755 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3756 const struct intel_render_pass *rp = cmd->bind.render_pass;
3757
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003758 /* TODOVV */
3759 assert(!(cmd->bind.render_pass_subpass >= rp->subpasses +
3760 rp->subpass_count - 1) && "Invalid RenderPassContents");
Chia-I Wuc278df82015-07-07 11:50:03 +08003761
3762 cmd->bind.render_pass_changed = true;
3763 cmd->bind.render_pass_subpass++;
3764 cmd->bind.render_pass_contents = contents;
3765}
3766
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06003767ICD_EXPORT void VKAPI vkCmdEndRenderPass(
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003768 VkCmdBuffer cmdBuffer)
Chia-I Wub5af7c52015-02-18 14:51:59 -07003769{
3770 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
3771
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003772 cmd_end_render_pass(cmd);
3773}
3774
3775ICD_EXPORT void VKAPI vkCmdExecuteCommands(
3776 VkCmdBuffer cmdBuffer,
3777 uint32_t cmdBuffersCount,
3778 const VkCmdBuffer* pCmdBuffers)
3779{
3780 struct intel_cmd *cmd = intel_cmd(cmdBuffer);
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003781 uint32_t i;
Chia-I Wu88eaa3b2015-06-26 15:34:39 +08003782
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003783 /* TODOVV */
3784 assert(!(!cmd->bind.render_pass || cmd->bind.render_pass_contents !=
3785 VK_RENDER_PASS_CONTENTS_SECONDARY_CMD_BUFFERS) && "Invalid RenderPass");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003786
3787 for (i = 0; i < cmdBuffersCount; i++) {
3788 const struct intel_cmd *secondary = intel_cmd(pCmdBuffers[i]);
3789
Courtney Goeltzenleuchterac544f32015-09-14 18:01:17 -06003790 /* TODOVV: Move test to validation layer */
3791 assert(!(secondary->primary) && "Cannot be primary command buffer");
Chia-I Wu513ae5b2015-07-01 19:04:59 +08003792
3793 cmd_exec(cmd, intel_cmd_get_batch(secondary, NULL));
3794 }
3795
3796 if (i)
3797 cmd_batch_state_base_address(cmd);
Chia-I Wub5af7c52015-02-18 14:51:59 -07003798}