blob: cbb77e137e2e38824e7d88d840e6cb31edc0d8b7 [file] [log] [blame]
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -06003 *
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 * Courtney Goeltzenleuchter <courtney@lunarg.com>
26 * Chia-I Wu <olv@lunarg.com>
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060027 */
28
29#ifndef PIPELINE_H
30#define PIPELINE_H
31
32#include "intel.h"
33#include "obj.h"
Chia-I Wuf8385062015-01-04 16:27:24 +080034#include "desc.h"
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060035#include "dev.h"
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -060036#include "state.h"
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -060037
Chia-I Wua4d1b392014-10-10 13:57:29 +080038enum intel_pipeline_shader_use {
39 INTEL_SHADER_USE_VID = (1 << 0),
40 INTEL_SHADER_USE_IID = (1 << 1),
41
42 INTEL_SHADER_USE_KILL = (1 << 2),
Cody Northrope238deb2015-01-26 14:41:36 -070043 INTEL_SHADER_USE_DEPTH = (1 << 3),
44 INTEL_SHADER_USE_W = (1 << 4),
45};
46
47/* This order must match Pixel Shader Computed Depth Mode in 3DSTATE_WM */
48enum intel_computed_depth_mode {
49 INTEL_COMPUTED_DEPTH_MODE_NONE,
50 INTEL_COMPUTED_DEPTH_MODE_ON,
51 INTEL_COMPUTED_DEPTH_MODE_ON_GE,
52 INTEL_COMPUTED_DEPTH_MODE_ON_LE
Chia-I Wua4d1b392014-10-10 13:57:29 +080053};
54
Chia-I Wuf8385062015-01-04 16:27:24 +080055enum intel_pipeline_rmap_slot_type {
56 INTEL_PIPELINE_RMAP_UNUSED,
57 INTEL_PIPELINE_RMAP_RT,
58 INTEL_PIPELINE_RMAP_SURFACE,
59 INTEL_PIPELINE_RMAP_SAMPLER,
60};
61
Chia-I Wu20983762014-09-02 12:07:28 +080062struct intel_pipeline_rmap_slot {
Chia-I Wuf8385062015-01-04 16:27:24 +080063 enum intel_pipeline_rmap_slot_type type;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080064
Chia-I Wu7732cb22015-03-26 15:27:55 +080065 uint32_t index; /* in the render target array or layout chain */
Chia-I Wu1f7540b2014-08-22 13:56:18 +080066 union {
Chia-I Wuf8385062015-01-04 16:27:24 +080067 struct {
68 struct intel_desc_offset offset;
69 int dynamic_offset_index;
70 } surface;
71 struct intel_desc_offset sampler;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080072 } u;
73};
74
75/**
76 * Shader resource mapping.
77 */
Chia-I Wu20983762014-09-02 12:07:28 +080078struct intel_pipeline_rmap {
Chia-I Wu1f7540b2014-08-22 13:56:18 +080079 /* this is not an intel_obj */
80
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060081 uint32_t rt_count;
82 uint32_t texture_resource_count;
83 uint32_t resource_count;
84 uint32_t uav_count;
85 uint32_t sampler_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080086
87 /*
88 * rt_count slots +
89 * resource_count slots +
90 * uav_count slots +
Chia-I Wu3b04af52014-11-08 10:48:20 +080091 * sampler_count slots
Chia-I Wu1f7540b2014-08-22 13:56:18 +080092 */
Chia-I Wu20983762014-09-02 12:07:28 +080093 struct intel_pipeline_rmap_slot *slots;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060094 uint32_t slot_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080095};
96
Courtney Goeltzenleuchter8e2f0972015-10-21 17:08:06 -060097#define SHADER_VERTEX_FLAG VK_SHADER_STAGE_VERTEX_BIT
98#define SHADER_TESS_CONTROL_FLAG VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
99#define SHADER_TESS_EVAL_FLAG VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
100#define SHADER_GEOMETRY_FLAG VK_SHADER_STAGE_GEOMETRY_BIT
101#define SHADER_FRAGMENT_FLAG VK_SHADER_STAGE_FRAGMENT_BIT
102#define SHADER_COMPUTE_FLAG VK_SHADER_STAGE_COMPUTE_BIT
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600103
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800104struct intel_pipeline_shader {
105 /* this is not an intel_obj */
106
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600107 void *pCode;
108 uint32_t codeSize;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600109
110 /*
111 * must grab everything we need from shader object as that
112 * can go away after the pipeline is created
113 */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600114 VkFlags uses;
GregF8cd81832014-11-18 18:01:01 -0700115 uint64_t inputs_read;
116 uint64_t outputs_written;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600117 uint32_t outputs_offset;
118 uint32_t generic_input_start;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600119
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600120 VkBool32 enable_user_clip;
121 VkBool32 reads_user_clip;
GregFfd4c1f92014-11-07 15:32:52 -0700122
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600123 uint32_t in_count;
124 uint32_t out_count;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600125
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600126 uint32_t sampler_count;
127 uint32_t surface_count;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600128
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600129 uint32_t ubo_start;
Cody Northrop293d4502015-05-05 09:38:03 -0600130
131 // geometry shader specific
132 uint32_t output_size_hwords;
133 uint32_t output_topology;
134 uint32_t control_data_header_size_hwords;
135 uint32_t control_data_format;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600136 VkBool32 include_primitive_id;
Cody Northrop293d4502015-05-05 09:38:03 -0600137 int32_t invocations;
Courtney Goeltzenleuchter1f41f542015-07-09 11:44:38 -0600138 VkBool32 dual_instanced_dispatch;
139 VkBool32 discard_adj;
Cody Northrop293d4502015-05-05 09:38:03 -0600140
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600141 uint32_t urb_grf_start;
Cody Northrope86574e2015-02-24 14:15:29 -0700142 uint32_t urb_grf_start_16;
143
144 /* If present, where does the SIMD16 kernel start? */
145 uint32_t offset_16;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600146
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600147 VkFlags barycentric_interps;
148 VkFlags point_sprite_enables;
Chia-I Wu39026c92014-09-02 10:03:19 +0800149
Tony Barbour8205d902015-04-16 15:59:00 -0600150 VkDeviceSize per_thread_scratch_size;
Chia-I Wub1024732014-12-19 13:00:29 +0800151
Cody Northrope238deb2015-01-26 14:41:36 -0700152 enum intel_computed_depth_mode computed_depth_mode;
153
Chia-I Wu20983762014-09-02 12:07:28 +0800154 struct intel_pipeline_rmap *rmap;
Chia-I Wu5667d6f2014-12-11 22:37:37 +0800155
156 /* these are set up by the driver */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600157 uint32_t max_threads;
Tony Barbour8205d902015-04-16 15:59:00 -0600158 VkDeviceSize scratch_offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600159};
160
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800161/*
162 * On GEN6, there are
163 *
164 * - 3DSTATE_URB (3)
Chia-I Wu24693712014-11-08 11:54:47 +0800165 * - 3DSTATE_VERTEX_ELEMENTS (1+2*INTEL_MAX_VERTEX_ELEMENT_COUNT)
Tony Barbourfa6cac72015-01-16 14:27:35 -0700166 * - 3DSTATE_SAMPLE_MASK (2)
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800167 *
168 * On GEN7, there are
169 *
170 * - 3DSTATE_URB_x (2*4)
Chia-I Wu24693712014-11-08 11:54:47 +0800171 * - 3DSTATE_VERTEX_ELEMENTS (1+2*INTEL_MAX_VERTEX_ELEMENT_COUNT)
Tony Barbourfa6cac72015-01-16 14:27:35 -0700172 * - 3DSTATE_SBE (14)
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800173 * - 3DSTATE_HS (7)
174 * - 3DSTATE_TE (4)
175 * - 3DSTATE_DS (6)
Tony Barbourfa6cac72015-01-16 14:27:35 -0700176 * - 3DSTATE_SAMPLE_MASK (2)
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800177 */
Chia-I Wu1d125092014-10-08 08:49:38 +0800178#define INTEL_PSO_CMD_ENTRIES 128
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600179
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600180/**
181 * 3D pipeline.
182 */
183struct intel_pipeline {
184 struct intel_obj obj;
185
186 struct intel_dev *dev;
187
Mark Lobodzinski556f7212015-04-17 14:11:39 -0500188 const struct intel_pipeline_layout *pipeline_layout;
Chia-I Wudf601c42015-04-17 01:58:07 +0800189
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600190 VkVertexInputBindingDescription vb[INTEL_MAX_VERTEX_BINDING_COUNT];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600191 uint32_t vb_count;
Chia-I Wu1d125092014-10-08 08:49:38 +0800192
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600193 /* VkPipelineIaStateCreateInfo */
194 VkPrimitiveTopology topology;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600195 int prim_type;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800196 bool disable_vs_cache;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600197 bool primitive_restart;
198 uint32_t primitive_restart_index;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600199
Tony Barboure307f582015-07-10 15:29:03 -0600200 // TODO: This should probably be Intel HW state, not VK state.
201 /* Depth Buffer format */
202 VkFormat db_format;
203
204 VkPipelineColorBlendStateCreateInfo cb_state;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600205
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600206 // VkPipelineRsStateCreateInfo rs_state;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600207 bool depthClipEnable;
208 bool rasterizerDiscardEnable;
Cody Northropf5bd2252015-08-17 11:10:49 -0600209 bool depthBiasEnable;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600210
Courtney Goeltzenleuchterc8f54f72015-10-15 17:59:39 -0600211 bool alphaToCoverageEnable;
Courtney Goeltzenleuchterd4a39bf2015-10-23 15:47:29 -0600212 bool alphaToOneEnable;
Courtney Goeltzenleuchterc8f54f72015-10-15 17:59:39 -0600213
Tony Barboure307f582015-07-10 15:29:03 -0600214 VkPipelineTessellationStateCreateInfo tess_state;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600215
216 uint32_t active_shaders;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800217 struct intel_pipeline_shader vs;
Chia-I Wu95959fb2014-09-02 11:01:03 +0800218 struct intel_pipeline_shader tcs;
219 struct intel_pipeline_shader tes;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800220 struct intel_pipeline_shader gs;
221 struct intel_pipeline_shader fs;
Chia-I Wu95959fb2014-09-02 11:01:03 +0800222 struct intel_pipeline_shader cs;
Tony Barbour8205d902015-04-16 15:59:00 -0600223 VkDeviceSize scratch_size;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600224
Chia-I Wu8370b402014-08-29 12:28:37 +0800225 uint32_t wa_flags;
226
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600227 uint32_t cmds[INTEL_PSO_CMD_ENTRIES];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600228 uint32_t cmd_len;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700229
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700230 bool dual_source_blend_enable;
231
Tony Barbourfa6cac72015-01-16 14:27:35 -0700232 /* The following are only partial HW commands that will need
233 * more processing before sending to the HW
234 */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600235 // VkPipelineDsStateCreateInfo ds_state
Tony Barbourfa6cac72015-01-16 14:27:35 -0700236 bool stencilTestEnable;
Courtney Goeltzenleuchtere20aaa22015-09-21 17:19:25 -0600237
238 /* Dynamic state specified at PSO create time */
239 struct {
240 VkFlags use_pipeline_dynamic_state;
241 struct intel_dynamic_viewport viewport;
242 struct intel_dynamic_line_width line_width;
243 struct intel_dynamic_depth_bias depth_bias;
244 struct intel_dynamic_blend blend;
245 struct intel_dynamic_depth_bounds depth_bounds;
246 struct intel_dynamic_stencil stencil;
247 } state;
248
Tony Barbourfa6cac72015-01-16 14:27:35 -0700249 uint32_t cmd_depth_stencil;
250 uint32_t cmd_depth_test;
251
252 uint32_t cmd_sf_fill;
253 uint32_t cmd_clip_cull;
254 uint32_t cmd_sf_cull;
255 uint32_t cmd_cb[2 * INTEL_MAX_RENDER_TARGETS];
256 uint32_t sample_count;
257 uint32_t cmd_sample_mask;
Chia-I Wuf85def42015-01-29 00:34:24 +0800258
259 uint32_t cmd_3dstate_sbe[14];
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600260};
261
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600262static inline struct intel_pipeline *intel_pipeline(VkPipeline pipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600263{
Tony Barbourde4124d2015-07-03 10:33:54 -0600264 return *(struct intel_pipeline **) &pipeline;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600265}
266
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600267static inline struct intel_pipeline *intel_pipeline_from_base(struct intel_base *base)
268{
269 return (struct intel_pipeline *) base;
270}
271
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600272static inline struct intel_pipeline *intel_pipeline_from_obj(struct intel_obj *obj)
273{
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600274 return intel_pipeline_from_base(&obj->base);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600275}
276
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800277struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
278 enum intel_dev_meta_shader id);
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800279void intel_pipeline_shader_destroy(struct intel_dev *dev,
280 struct intel_pipeline_shader *sh);
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800281
Chia-I Wu38d1ddf2015-03-02 10:51:39 -0700282void intel_pipeline_init_default_sample_patterns(const struct intel_dev *dev,
283 uint8_t *pat_1x, uint8_t *pat_2x,
284 uint8_t *pat_4x, uint8_t *pat_8x,
285 uint8_t *pat_16x);
286
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800287#endif /* PIPELINE_H */