vk/0.210.0: Move alphaToOne and alphaToCoverate to multisample state
[mesa.git] / src / vulkan / gen7_pipeline.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "anv_private.h"
31
32 #include "gen7_pack.h"
33 #include "gen75_pack.h"
34
35 static void
36 gen7_emit_vertex_input(struct anv_pipeline *pipeline,
37 const VkPipelineVertexInputStateCreateInfo *info)
38 {
39 const bool sgvs = pipeline->vs_prog_data.uses_vertexid ||
40 pipeline->vs_prog_data.uses_instanceid;
41 const uint32_t element_count =
42 info->vertexAttributeDescriptionCount + (sgvs ? 1 : 0);
43 const uint32_t num_dwords = 1 + element_count * 2;
44 uint32_t *p;
45
46 if (info->vertexAttributeDescriptionCount == 0 && !sgvs)
47 return;
48
49 p = anv_batch_emitn(&pipeline->batch, num_dwords,
50 GEN7_3DSTATE_VERTEX_ELEMENTS);
51
52 for (uint32_t i = 0; i < info->vertexAttributeDescriptionCount; i++) {
53 const VkVertexInputAttributeDescription *desc =
54 &info->pVertexAttributeDescriptions[i];
55 const struct anv_format *format = anv_format_for_vk_format(desc->format);
56
57 struct GEN7_VERTEX_ELEMENT_STATE element = {
58 .VertexBufferIndex = desc->binding,
59 .Valid = true,
60 .SourceElementFormat = format->surface_format,
61 .EdgeFlagEnable = false,
62 .SourceElementOffset = desc->offset,
63 .Component0Control = VFCOMP_STORE_SRC,
64 .Component1Control = format->num_channels >= 2 ? VFCOMP_STORE_SRC : VFCOMP_STORE_0,
65 .Component2Control = format->num_channels >= 3 ? VFCOMP_STORE_SRC : VFCOMP_STORE_0,
66 .Component3Control = format->num_channels >= 4 ? VFCOMP_STORE_SRC : VFCOMP_STORE_1_FP
67 };
68 GEN7_VERTEX_ELEMENT_STATE_pack(NULL, &p[1 + i * 2], &element);
69 }
70
71 if (sgvs) {
72 struct GEN7_VERTEX_ELEMENT_STATE element = {
73 .Valid = true,
74 /* FIXME: Do we need to provide the base vertex as component 0 here
75 * to support the correct base vertex ID? */
76 .Component0Control = VFCOMP_STORE_0,
77 .Component1Control = VFCOMP_STORE_0,
78 .Component2Control = VFCOMP_STORE_VID,
79 .Component3Control = VFCOMP_STORE_IID
80 };
81 GEN7_VERTEX_ELEMENT_STATE_pack(NULL, &p[1 + info->vertexAttributeDescriptionCount * 2], &element);
82 }
83 }
84
85 static const uint32_t vk_to_gen_cullmode[] = {
86 [VK_CULL_MODE_NONE] = CULLMODE_NONE,
87 [VK_CULL_MODE_FRONT_BIT] = CULLMODE_FRONT,
88 [VK_CULL_MODE_BACK_BIT] = CULLMODE_BACK,
89 [VK_CULL_MODE_FRONT_AND_BACK] = CULLMODE_BOTH
90 };
91
92 static const uint32_t vk_to_gen_fillmode[] = {
93 [VK_POLYGON_MODE_FILL] = RASTER_SOLID,
94 [VK_POLYGON_MODE_LINE] = RASTER_WIREFRAME,
95 [VK_POLYGON_MODE_POINT] = RASTER_POINT,
96 };
97
98 static const uint32_t vk_to_gen_front_face[] = {
99 [VK_FRONT_FACE_COUNTER_CLOCKWISE] = 1,
100 [VK_FRONT_FACE_CLOCKWISE] = 0
101 };
102
103 static void
104 gen7_emit_rs_state(struct anv_pipeline *pipeline,
105 const VkPipelineRasterStateCreateInfo *info,
106 const struct anv_graphics_pipeline_create_info *extra)
107 {
108 struct GEN7_3DSTATE_SF sf = {
109 GEN7_3DSTATE_SF_header,
110
111 /* FIXME: Get this from pass info */
112 .DepthBufferSurfaceFormat = D24_UNORM_X8_UINT,
113
114 /* LegacyGlobalDepthBiasEnable */
115
116 .StatisticsEnable = true,
117 .FrontFaceFillMode = vk_to_gen_fillmode[info->polygonMode],
118 .BackFaceFillMode = vk_to_gen_fillmode[info->polygonMode],
119 .ViewTransformEnable = !(extra && extra->disable_viewport),
120 .FrontWinding = vk_to_gen_front_face[info->frontFace],
121 /* bool AntiAliasingEnable; */
122
123 .CullMode = vk_to_gen_cullmode[info->cullMode],
124
125 /* uint32_t LineEndCapAntialiasingRegionWidth; */
126 .ScissorRectangleEnable = !(extra && extra->disable_scissor),
127
128 /* uint32_t MultisampleRasterizationMode; */
129 /* bool LastPixelEnable; */
130
131 .TriangleStripListProvokingVertexSelect = 0,
132 .LineStripListProvokingVertexSelect = 0,
133 .TriangleFanProvokingVertexSelect = 0,
134
135 /* uint32_t AALineDistanceMode; */
136 /* uint32_t VertexSubPixelPrecisionSelect; */
137 .UsePointWidthState = !pipeline->writes_point_size,
138 .PointWidth = 1.0,
139 };
140
141 GEN7_3DSTATE_SF_pack(NULL, &pipeline->gen7.sf, &sf);
142 }
143
144 static const uint32_t vk_to_gen_compare_op[] = {
145 [VK_COMPARE_OP_NEVER] = PREFILTEROPNEVER,
146 [VK_COMPARE_OP_LESS] = PREFILTEROPLESS,
147 [VK_COMPARE_OP_EQUAL] = PREFILTEROPEQUAL,
148 [VK_COMPARE_OP_LESS_OR_EQUAL] = PREFILTEROPLEQUAL,
149 [VK_COMPARE_OP_GREATER] = PREFILTEROPGREATER,
150 [VK_COMPARE_OP_NOT_EQUAL] = PREFILTEROPNOTEQUAL,
151 [VK_COMPARE_OP_GREATER_OR_EQUAL] = PREFILTEROPGEQUAL,
152 [VK_COMPARE_OP_ALWAYS] = PREFILTEROPALWAYS,
153 };
154
155 static const uint32_t vk_to_gen_stencil_op[] = {
156 [VK_STENCIL_OP_KEEP] = STENCILOP_KEEP,
157 [VK_STENCIL_OP_ZERO] = STENCILOP_ZERO,
158 [VK_STENCIL_OP_REPLACE] = STENCILOP_REPLACE,
159 [VK_STENCIL_OP_INCREMENT_AND_CLAMP] = STENCILOP_INCRSAT,
160 [VK_STENCIL_OP_DECREMENT_AND_CLAMP] = STENCILOP_DECRSAT,
161 [VK_STENCIL_OP_INVERT] = STENCILOP_INVERT,
162 [VK_STENCIL_OP_INCREMENT_AND_WRAP] = STENCILOP_INCR,
163 [VK_STENCIL_OP_DECREMENT_AND_WRAP] = STENCILOP_DECR,
164 };
165
166 static const uint32_t vk_to_gen_blend_op[] = {
167 [VK_BLEND_OP_ADD] = BLENDFUNCTION_ADD,
168 [VK_BLEND_OP_SUBTRACT] = BLENDFUNCTION_SUBTRACT,
169 [VK_BLEND_OP_REVERSE_SUBTRACT] = BLENDFUNCTION_REVERSE_SUBTRACT,
170 [VK_BLEND_OP_MIN] = BLENDFUNCTION_MIN,
171 [VK_BLEND_OP_MAX] = BLENDFUNCTION_MAX,
172 };
173
174 static const uint32_t vk_to_gen_logic_op[] = {
175 [VK_LOGIC_OP_COPY] = LOGICOP_COPY,
176 [VK_LOGIC_OP_CLEAR] = LOGICOP_CLEAR,
177 [VK_LOGIC_OP_AND] = LOGICOP_AND,
178 [VK_LOGIC_OP_AND_REVERSE] = LOGICOP_AND_REVERSE,
179 [VK_LOGIC_OP_AND_INVERTED] = LOGICOP_AND_INVERTED,
180 [VK_LOGIC_OP_NO_OP] = LOGICOP_NOOP,
181 [VK_LOGIC_OP_XOR] = LOGICOP_XOR,
182 [VK_LOGIC_OP_OR] = LOGICOP_OR,
183 [VK_LOGIC_OP_NOR] = LOGICOP_NOR,
184 [VK_LOGIC_OP_EQUIVALENT] = LOGICOP_EQUIV,
185 [VK_LOGIC_OP_INVERT] = LOGICOP_INVERT,
186 [VK_LOGIC_OP_OR_REVERSE] = LOGICOP_OR_REVERSE,
187 [VK_LOGIC_OP_COPY_INVERTED] = LOGICOP_COPY_INVERTED,
188 [VK_LOGIC_OP_OR_INVERTED] = LOGICOP_OR_INVERTED,
189 [VK_LOGIC_OP_NAND] = LOGICOP_NAND,
190 [VK_LOGIC_OP_SET] = LOGICOP_SET,
191 };
192
193 static const uint32_t vk_to_gen_blend[] = {
194 [VK_BLEND_FACTOR_ZERO] = BLENDFACTOR_ZERO,
195 [VK_BLEND_FACTOR_ONE] = BLENDFACTOR_ONE,
196 [VK_BLEND_FACTOR_SRC_COLOR] = BLENDFACTOR_SRC_COLOR,
197 [VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR] = BLENDFACTOR_INV_SRC_COLOR,
198 [VK_BLEND_FACTOR_DST_COLOR] = BLENDFACTOR_DST_COLOR,
199 [VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR] = BLENDFACTOR_INV_DST_COLOR,
200 [VK_BLEND_FACTOR_SRC_ALPHA] = BLENDFACTOR_SRC_ALPHA,
201 [VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA] = BLENDFACTOR_INV_SRC_ALPHA,
202 [VK_BLEND_FACTOR_DST_ALPHA] = BLENDFACTOR_DST_ALPHA,
203 [VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA] = BLENDFACTOR_INV_DST_ALPHA,
204 [VK_BLEND_FACTOR_CONSTANT_COLOR] = BLENDFACTOR_CONST_COLOR,
205 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR] = BLENDFACTOR_INV_CONST_COLOR,
206 [VK_BLEND_FACTOR_CONSTANT_ALPHA] = BLENDFACTOR_CONST_ALPHA,
207 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA] = BLENDFACTOR_INV_CONST_ALPHA,
208 [VK_BLEND_FACTOR_SRC_ALPHA_SATURATE] = BLENDFACTOR_SRC_ALPHA_SATURATE,
209 [VK_BLEND_FACTOR_SRC1_COLOR] = BLENDFACTOR_SRC1_COLOR,
210 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR] = BLENDFACTOR_INV_SRC1_COLOR,
211 [VK_BLEND_FACTOR_SRC1_ALPHA] = BLENDFACTOR_SRC1_ALPHA,
212 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA] = BLENDFACTOR_INV_SRC1_ALPHA,
213 };
214
215 static void
216 gen7_emit_ds_state(struct anv_pipeline *pipeline,
217 const VkPipelineDepthStencilStateCreateInfo *info)
218 {
219 if (info == NULL) {
220 /* We're going to OR this together with the dynamic state. We need
221 * to make sure it's initialized to something useful.
222 */
223 memset(pipeline->gen7.depth_stencil_state, 0,
224 sizeof(pipeline->gen7.depth_stencil_state));
225 return;
226 }
227
228 struct GEN7_DEPTH_STENCIL_STATE state = {
229 .DepthTestEnable = info->depthTestEnable,
230 .DepthBufferWriteEnable = info->depthWriteEnable,
231 .DepthTestFunction = vk_to_gen_compare_op[info->depthCompareOp],
232 .DoubleSidedStencilEnable = true,
233
234 .StencilTestEnable = info->stencilTestEnable,
235 .StencilFailOp = vk_to_gen_stencil_op[info->front.failOp],
236 .StencilPassDepthPassOp = vk_to_gen_stencil_op[info->front.passOp],
237 .StencilPassDepthFailOp = vk_to_gen_stencil_op[info->front.depthFailOp],
238 .StencilTestFunction = vk_to_gen_compare_op[info->front.compareOp],
239
240 .BackfaceStencilFailOp = vk_to_gen_stencil_op[info->back.failOp],
241 .BackfaceStencilPassDepthPassOp = vk_to_gen_stencil_op[info->back.passOp],
242 .BackfaceStencilPassDepthFailOp = vk_to_gen_stencil_op[info->back.depthFailOp],
243 .BackFaceStencilTestFunction = vk_to_gen_compare_op[info->back.compareOp],
244 };
245
246 GEN7_DEPTH_STENCIL_STATE_pack(NULL, &pipeline->gen7.depth_stencil_state, &state);
247 }
248
249 static void
250 gen7_emit_cb_state(struct anv_pipeline *pipeline,
251 const VkPipelineColorBlendStateCreateInfo *info,
252 const VkPipelineMultisampleStateCreateInfo *ms_info)
253 {
254 struct anv_device *device = pipeline->device;
255
256 uint32_t num_dwords = GEN7_BLEND_STATE_length;
257 pipeline->blend_state =
258 anv_state_pool_alloc(&device->dynamic_state_pool, num_dwords * 4, 64);
259
260 if (info->pAttachments == NULL) {
261 struct GEN7_BLEND_STATE blend_state = {
262 .ColorBufferBlendEnable = false,
263 .WriteDisableAlpha = false,
264 .WriteDisableRed = false,
265 .WriteDisableGreen = false,
266 .WriteDisableBlue = false,
267 };
268
269 GEN7_BLEND_STATE_pack(NULL, pipeline->blend_state.map, &blend_state);
270 } else {
271 /* FIXME-GEN7: All render targets share blend state settings on gen7, we
272 * can't implement this.
273 */
274 const VkPipelineColorBlendAttachmentState *a = &info->pAttachments[0];
275
276 struct GEN7_BLEND_STATE blend_state = {
277 .ColorBufferBlendEnable = a->blendEnable,
278 .IndependentAlphaBlendEnable = true, /* FIXME: yes? */
279 .AlphaBlendFunction = vk_to_gen_blend_op[a->alphaBlendOp],
280
281 .SourceAlphaBlendFactor = vk_to_gen_blend[a->srcAlphaBlendFactor],
282 .DestinationAlphaBlendFactor = vk_to_gen_blend[a->dstAlphaBlendFactor],
283
284 .ColorBlendFunction = vk_to_gen_blend_op[a->colorBlendOp],
285 .SourceBlendFactor = vk_to_gen_blend[a->srcColorBlendFactor],
286 .DestinationBlendFactor = vk_to_gen_blend[a->dstColorBlendFactor],
287 .AlphaToCoverageEnable = ms_info && ms_info->alphaToCoverageEnable,
288
289 # if 0
290 bool AlphaToOneEnable;
291 bool AlphaToCoverageDitherEnable;
292 # endif
293
294 .WriteDisableAlpha = !(a->channelWriteMask & VK_CHANNEL_A_BIT),
295 .WriteDisableRed = !(a->channelWriteMask & VK_CHANNEL_R_BIT),
296 .WriteDisableGreen = !(a->channelWriteMask & VK_CHANNEL_G_BIT),
297 .WriteDisableBlue = !(a->channelWriteMask & VK_CHANNEL_B_BIT),
298
299 .LogicOpEnable = info->logicOpEnable,
300 .LogicOpFunction = vk_to_gen_logic_op[info->logicOp],
301
302 # if 0
303 bool AlphaTestEnable;
304 uint32_t AlphaTestFunction;
305 bool ColorDitherEnable;
306 uint32_t XDitherOffset;
307 uint32_t YDitherOffset;
308 uint32_t ColorClampRange;
309 bool PreBlendColorClampEnable;
310 bool PostBlendColorClampEnable;
311 # endif
312 };
313
314 GEN7_BLEND_STATE_pack(NULL, pipeline->blend_state.map, &blend_state);
315 }
316
317 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_BLEND_STATE_POINTERS,
318 .BlendStatePointer = pipeline->blend_state.offset);
319 }
320
321 static inline uint32_t
322 scratch_space(const struct brw_stage_prog_data *prog_data)
323 {
324 return ffs(prog_data->total_scratch / 1024);
325 }
326
327 GENX_FUNC(GEN7, GEN75) VkResult
328 genX(graphics_pipeline_create)(
329 VkDevice _device,
330 const VkGraphicsPipelineCreateInfo* pCreateInfo,
331 const struct anv_graphics_pipeline_create_info *extra,
332 VkPipeline* pPipeline)
333 {
334 ANV_FROM_HANDLE(anv_device, device, _device);
335 struct anv_pipeline *pipeline;
336 VkResult result;
337
338 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
339
340 pipeline = anv_device_alloc(device, sizeof(*pipeline), 8,
341 VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
342 if (pipeline == NULL)
343 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
344
345 result = anv_pipeline_init(pipeline, device, pCreateInfo, extra);
346 if (result != VK_SUCCESS) {
347 anv_device_free(device, pipeline);
348 return result;
349 }
350
351 assert(pCreateInfo->pVertexInputState);
352 gen7_emit_vertex_input(pipeline, pCreateInfo->pVertexInputState);
353
354 assert(pCreateInfo->pRasterState);
355 gen7_emit_rs_state(pipeline, pCreateInfo->pRasterState, extra);
356
357 gen7_emit_ds_state(pipeline, pCreateInfo->pDepthStencilState);
358
359 gen7_emit_cb_state(pipeline, pCreateInfo->pColorBlendState,
360 pCreateInfo->pMultisampleState);
361
362 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_VF_STATISTICS,
363 .StatisticsEnable = true);
364 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_HS, .Enable = false);
365 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_TE, .TEEnable = false);
366 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_DS, .DSFunctionEnable = false);
367 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_STREAMOUT, .SOFunctionEnable = false);
368
369 /* From the IVB PRM Vol. 2, Part 1, Section 3.2.1:
370 *
371 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
372 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
373 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
374 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
375 * needs to be sent before any combination of VS associated 3DSTATE."
376 */
377 anv_batch_emit(&pipeline->batch, GEN7_PIPE_CONTROL,
378 .DepthStallEnable = true,
379 .PostSyncOperation = WriteImmediateData,
380 .Address = { &device->workaround_bo, 0 });
381
382 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_VS,
383 .ConstantBufferOffset = 0,
384 .ConstantBufferSize = 4);
385 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_GS,
386 .ConstantBufferOffset = 4,
387 .ConstantBufferSize = 4);
388 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_PUSH_CONSTANT_ALLOC_PS,
389 .ConstantBufferOffset = 8,
390 .ConstantBufferSize = 4);
391
392 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_AA_LINE_PARAMETERS);
393
394 const VkPipelineRasterStateCreateInfo *rs_info = pCreateInfo->pRasterState;
395
396 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_CLIP,
397 .FrontWinding = vk_to_gen_front_face[rs_info->frontFace],
398 .CullMode = vk_to_gen_cullmode[rs_info->cullMode],
399 .ClipEnable = true,
400 .APIMode = APIMODE_OGL,
401 .ViewportXYClipTestEnable = !(extra && extra->disable_viewport),
402 .ClipMode = CLIPMODE_NORMAL,
403 .TriangleStripListProvokingVertexSelect = 0,
404 .LineStripListProvokingVertexSelect = 0,
405 .TriangleFanProvokingVertexSelect = 0,
406 .MinimumPointWidth = 0.125,
407 .MaximumPointWidth = 255.875);
408
409 uint32_t samples = 1;
410 uint32_t log2_samples = __builtin_ffs(samples) - 1;
411
412 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_MULTISAMPLE,
413 .PixelLocation = PIXLOC_CENTER,
414 .NumberofMultisamples = log2_samples);
415
416 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_SAMPLE_MASK,
417 .SampleMask = 0xff);
418
419 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_URB_VS,
420 .VSURBStartingAddress = pipeline->urb.vs_start,
421 .VSURBEntryAllocationSize = pipeline->urb.vs_size - 1,
422 .VSNumberofURBEntries = pipeline->urb.nr_vs_entries);
423
424 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_URB_GS,
425 .GSURBStartingAddress = pipeline->urb.gs_start,
426 .GSURBEntryAllocationSize = pipeline->urb.gs_size - 1,
427 .GSNumberofURBEntries = pipeline->urb.nr_gs_entries);
428
429 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_URB_HS,
430 .HSURBStartingAddress = pipeline->urb.vs_start,
431 .HSURBEntryAllocationSize = 0,
432 .HSNumberofURBEntries = 0);
433
434 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_URB_DS,
435 .DSURBStartingAddress = pipeline->urb.vs_start,
436 .DSURBEntryAllocationSize = 0,
437 .DSNumberofURBEntries = 0);
438
439 const struct brw_vue_prog_data *vue_prog_data = &pipeline->vs_prog_data.base;
440 /* The last geometry producing stage will set urb_offset and urb_length,
441 * which we use in 3DSTATE_SBE. Skip the VUE header and position slots. */
442 uint32_t urb_offset = 1;
443 uint32_t urb_length = (vue_prog_data->vue_map.num_slots + 1) / 2 - urb_offset;
444
445 #if 0
446 /* From gen7_vs_state.c */
447
448 /**
449 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
450 * Geometry > Geometry Shader > State:
451 *
452 * "Note: Because of corruption in IVB:GT2, software needs to flush the
453 * whole fixed function pipeline when the GS enable changes value in
454 * the 3DSTATE_GS."
455 *
456 * The hardware architects have clarified that in this context "flush the
457 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
458 * Stall" bit set.
459 */
460 if (!brw->is_haswell && !brw->is_baytrail)
461 gen7_emit_vs_workaround_flush(brw);
462 #endif
463
464 if (pipeline->vs_vec4 == NO_KERNEL || (extra && extra->disable_vs))
465 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VS), .VSFunctionEnable = false);
466 else
467 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VS),
468 .KernelStartPointer = pipeline->vs_vec4,
469 .ScratchSpaceBaseOffset = pipeline->scratch_start[VK_SHADER_STAGE_VERTEX],
470 .PerThreadScratchSpace = scratch_space(&vue_prog_data->base),
471
472 .DispatchGRFStartRegisterforURBData =
473 vue_prog_data->base.dispatch_grf_start_reg,
474 .VertexURBEntryReadLength = vue_prog_data->urb_read_length,
475 .VertexURBEntryReadOffset = 0,
476
477 .MaximumNumberofThreads = device->info.max_vs_threads - 1,
478 .StatisticsEnable = true,
479 .VSFunctionEnable = true);
480
481 const struct brw_gs_prog_data *gs_prog_data = &pipeline->gs_prog_data;
482
483 if (pipeline->gs_vec4 == NO_KERNEL || (extra && extra->disable_vs)) {
484 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_GS), .GSEnable = false);
485 } else {
486 urb_offset = 1;
487 urb_length = (gs_prog_data->base.vue_map.num_slots + 1) / 2 - urb_offset;
488
489 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_GS),
490 .KernelStartPointer = pipeline->gs_vec4,
491 .ScratchSpaceBasePointer = pipeline->scratch_start[VK_SHADER_STAGE_GEOMETRY],
492 .PerThreadScratchSpace = scratch_space(&gs_prog_data->base.base),
493
494 .OutputVertexSize = gs_prog_data->output_vertex_size_hwords * 2 - 1,
495 .OutputTopology = gs_prog_data->output_topology,
496 .VertexURBEntryReadLength = gs_prog_data->base.urb_read_length,
497 .DispatchGRFStartRegisterforURBData =
498 gs_prog_data->base.base.dispatch_grf_start_reg,
499
500 .MaximumNumberofThreads = device->info.max_gs_threads - 1,
501 /* This in the next dword on HSW. */
502 .ControlDataFormat = gs_prog_data->control_data_format,
503 .ControlDataHeaderSize = gs_prog_data->control_data_header_size_hwords,
504 .InstanceControl = MAX2(gs_prog_data->invocations, 1) - 1,
505 .DispatchMode = gs_prog_data->base.dispatch_mode,
506 .GSStatisticsEnable = true,
507 .IncludePrimitiveID = gs_prog_data->include_primitive_id,
508 # if (ANV_IS_HASWELL)
509 .ReorderMode = REORDER_TRAILING,
510 # else
511 .ReorderEnable = true,
512 # endif
513 .GSEnable = true);
514 }
515
516 const struct brw_wm_prog_data *wm_prog_data = &pipeline->wm_prog_data;
517 if (wm_prog_data->urb_setup[VARYING_SLOT_BFC0] != -1 ||
518 wm_prog_data->urb_setup[VARYING_SLOT_BFC1] != -1)
519 anv_finishme("two-sided color needs sbe swizzling setup");
520 if (wm_prog_data->urb_setup[VARYING_SLOT_PRIMITIVE_ID] != -1)
521 anv_finishme("primitive_id needs sbe swizzling setup");
522
523 /* FIXME: generated header doesn't emit attr swizzle fields */
524 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_SBE,
525 .NumberofSFOutputAttributes = pipeline->wm_prog_data.num_varying_inputs,
526 .VertexURBEntryReadLength = urb_length,
527 .VertexURBEntryReadOffset = urb_offset,
528 .PointSpriteTextureCoordinateOrigin = UPPERLEFT);
529
530 anv_batch_emit(&pipeline->batch, GENX(3DSTATE_PS),
531 .KernelStartPointer0 = pipeline->ps_ksp0,
532 .ScratchSpaceBasePointer = pipeline->scratch_start[VK_SHADER_STAGE_FRAGMENT],
533 .PerThreadScratchSpace = scratch_space(&wm_prog_data->base),
534
535 .MaximumNumberofThreads = device->info.max_wm_threads - 1,
536 .PushConstantEnable = wm_prog_data->base.nr_params > 0,
537 .AttributeEnable = wm_prog_data->num_varying_inputs > 0,
538 .oMaskPresenttoRenderTarget = wm_prog_data->uses_omask,
539
540 .RenderTargetFastClearEnable = false,
541 .DualSourceBlendEnable = false,
542 .RenderTargetResolveEnable = false,
543
544 .PositionXYOffsetSelect = wm_prog_data->uses_pos_offset ?
545 POSOFFSET_SAMPLE : POSOFFSET_NONE,
546
547 ._32PixelDispatchEnable = false,
548 ._16PixelDispatchEnable = pipeline->ps_simd16 != NO_KERNEL,
549 ._8PixelDispatchEnable = pipeline->ps_simd8 != NO_KERNEL,
550
551 .DispatchGRFStartRegisterforConstantSetupData0 = pipeline->ps_grf_start0,
552 .DispatchGRFStartRegisterforConstantSetupData1 = 0,
553 .DispatchGRFStartRegisterforConstantSetupData2 = pipeline->ps_grf_start2,
554
555 #if 0
556 /* Haswell requires the sample mask to be set in this packet as well as
557 * in 3DSTATE_SAMPLE_MASK; the values should match. */
558 /* _NEW_BUFFERS, _NEW_MULTISAMPLE */
559 #endif
560
561 .KernelStartPointer1 = 0,
562 .KernelStartPointer2 = pipeline->ps_ksp2);
563
564 /* FIXME-GEN7: This needs a lot more work, cf gen7 upload_wm_state(). */
565 anv_batch_emit(&pipeline->batch, GEN7_3DSTATE_WM,
566 .StatisticsEnable = true,
567 .ThreadDispatchEnable = true,
568 .LineEndCapAntialiasingRegionWidth = 0, /* 0.5 pixels */
569 .LineAntialiasingRegionWidth = 1, /* 1.0 pixels */
570 .EarlyDepthStencilControl = EDSC_NORMAL,
571 .PointRasterizationRule = RASTRULE_UPPER_RIGHT,
572 .PixelShaderComputedDepthMode = wm_prog_data->computed_depth_mode,
573 .BarycentricInterpolationMode = wm_prog_data->barycentric_interp_modes);
574
575 *pPipeline = anv_pipeline_to_handle(pipeline);
576
577 return VK_SUCCESS;
578 }
579
580 GENX_FUNC(GEN7, GEN75) VkResult
581 genX(compute_pipeline_create)(
582 VkDevice _device,
583 const VkComputePipelineCreateInfo* pCreateInfo,
584 VkPipeline* pPipeline)
585 {
586 anv_finishme("primitive_id needs sbe swizzling setup");
587 abort();
588 }