blob: 0d76e121a32edb6121be713d818f1bc08ed255a7 [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"
36
Chia-I Wua4d1b392014-10-10 13:57:29 +080037enum intel_pipeline_shader_use {
38 INTEL_SHADER_USE_VID = (1 << 0),
39 INTEL_SHADER_USE_IID = (1 << 1),
40
41 INTEL_SHADER_USE_KILL = (1 << 2),
Cody Northrope238deb2015-01-26 14:41:36 -070042 INTEL_SHADER_USE_DEPTH = (1 << 3),
43 INTEL_SHADER_USE_W = (1 << 4),
44};
45
46/* This order must match Pixel Shader Computed Depth Mode in 3DSTATE_WM */
47enum intel_computed_depth_mode {
48 INTEL_COMPUTED_DEPTH_MODE_NONE,
49 INTEL_COMPUTED_DEPTH_MODE_ON,
50 INTEL_COMPUTED_DEPTH_MODE_ON_GE,
51 INTEL_COMPUTED_DEPTH_MODE_ON_LE
Chia-I Wua4d1b392014-10-10 13:57:29 +080052};
53
Chia-I Wuf8385062015-01-04 16:27:24 +080054enum intel_pipeline_rmap_slot_type {
55 INTEL_PIPELINE_RMAP_UNUSED,
56 INTEL_PIPELINE_RMAP_RT,
57 INTEL_PIPELINE_RMAP_SURFACE,
58 INTEL_PIPELINE_RMAP_SAMPLER,
59};
60
Chia-I Wu20983762014-09-02 12:07:28 +080061struct intel_pipeline_rmap_slot {
Chia-I Wuf8385062015-01-04 16:27:24 +080062 enum intel_pipeline_rmap_slot_type type;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080063
Chia-I Wu7732cb22015-03-26 15:27:55 +080064 uint32_t index; /* in the render target array or layout chain */
Chia-I Wu1f7540b2014-08-22 13:56:18 +080065 union {
Chia-I Wuf8385062015-01-04 16:27:24 +080066 struct {
67 struct intel_desc_offset offset;
68 int dynamic_offset_index;
69 } surface;
70 struct intel_desc_offset sampler;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080071 } u;
72};
73
74/**
75 * Shader resource mapping.
76 */
Chia-I Wu20983762014-09-02 12:07:28 +080077struct intel_pipeline_rmap {
Chia-I Wu1f7540b2014-08-22 13:56:18 +080078 /* this is not an intel_obj */
79
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060080 uint32_t rt_count;
81 uint32_t texture_resource_count;
82 uint32_t resource_count;
83 uint32_t uav_count;
84 uint32_t sampler_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080085
86 /*
87 * rt_count slots +
88 * resource_count slots +
89 * uav_count slots +
Chia-I Wu3b04af52014-11-08 10:48:20 +080090 * sampler_count slots
Chia-I Wu1f7540b2014-08-22 13:56:18 +080091 */
Chia-I Wu20983762014-09-02 12:07:28 +080092 struct intel_pipeline_rmap_slot *slots;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -060093 uint32_t slot_count;
Chia-I Wu1f7540b2014-08-22 13:56:18 +080094};
95
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060096#define SHADER_VERTEX_FLAG (1 << VK_SHADER_STAGE_VERTEX)
97#define SHADER_TESS_CONTROL_FLAG (1 << VK_SHADER_STAGE_TESS_CONTROL)
98#define SHADER_TESS_EVAL_FLAG (1 << VK_SHADER_STAGE_TESS_EVALUATION)
99#define SHADER_GEOMETRY_FLAG (1 << VK_SHADER_STAGE_GEOMETRY)
100#define SHADER_FRAGMENT_FLAG (1 << VK_SHADER_STAGE_FRAGMENT)
101#define SHADER_COMPUTE_FLAG (1 << VK_SHADER_STAGE_COMPUTE)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600102
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800103struct intel_pipeline_shader {
104 /* this is not an intel_obj */
105
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600106 void *pCode;
107 uint32_t codeSize;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600108
109 /*
110 * must grab everything we need from shader object as that
111 * can go away after the pipeline is created
112 */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600113 VkFlags uses;
GregF8cd81832014-11-18 18:01:01 -0700114 uint64_t inputs_read;
115 uint64_t outputs_written;
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600116 uint32_t outputs_offset;
117 uint32_t generic_input_start;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600118
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600119 bool32_t enable_user_clip;
120 bool32_t reads_user_clip;
GregFfd4c1f92014-11-07 15:32:52 -0700121
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600122 uint32_t in_count;
123 uint32_t out_count;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600124
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600125 uint32_t sampler_count;
126 uint32_t surface_count;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600127
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600128 uint32_t ubo_start;
129 uint32_t urb_grf_start;
Cody Northrope86574e2015-02-24 14:15:29 -0700130 uint32_t urb_grf_start_16;
131
132 /* If present, where does the SIMD16 kernel start? */
133 uint32_t offset_16;
Courtney Goeltzenleuchterc4ef6142014-08-29 16:25:30 -0600134
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600135 VkFlags barycentric_interps;
136 VkFlags point_sprite_enables;
Chia-I Wu39026c92014-09-02 10:03:19 +0800137
Tony Barbour8205d902015-04-16 15:59:00 -0600138 VkDeviceSize per_thread_scratch_size;
Chia-I Wub1024732014-12-19 13:00:29 +0800139
Cody Northrope238deb2015-01-26 14:41:36 -0700140 enum intel_computed_depth_mode computed_depth_mode;
141
Chia-I Wu20983762014-09-02 12:07:28 +0800142 struct intel_pipeline_rmap *rmap;
Chia-I Wu5667d6f2014-12-11 22:37:37 +0800143
144 /* these are set up by the driver */
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600145 uint32_t max_threads;
Tony Barbour8205d902015-04-16 15:59:00 -0600146 VkDeviceSize scratch_offset;
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -0600147};
148
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800149/*
150 * On GEN6, there are
151 *
152 * - 3DSTATE_URB (3)
Chia-I Wu24693712014-11-08 11:54:47 +0800153 * - 3DSTATE_VERTEX_ELEMENTS (1+2*INTEL_MAX_VERTEX_ELEMENT_COUNT)
Tony Barbourfa6cac72015-01-16 14:27:35 -0700154 * - 3DSTATE_SAMPLE_MASK (2)
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800155 *
156 * On GEN7, there are
157 *
158 * - 3DSTATE_URB_x (2*4)
Chia-I Wu24693712014-11-08 11:54:47 +0800159 * - 3DSTATE_VERTEX_ELEMENTS (1+2*INTEL_MAX_VERTEX_ELEMENT_COUNT)
Tony Barbourfa6cac72015-01-16 14:27:35 -0700160 * - 3DSTATE_SBE (14)
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800161 * - 3DSTATE_HS (7)
162 * - 3DSTATE_TE (4)
163 * - 3DSTATE_DS (6)
Tony Barbourfa6cac72015-01-16 14:27:35 -0700164 * - 3DSTATE_SAMPLE_MASK (2)
Chia-I Wu1638c1c2014-08-29 14:01:16 +0800165 */
Chia-I Wu1d125092014-10-08 08:49:38 +0800166#define INTEL_PSO_CMD_ENTRIES 128
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600167
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600168/**
169 * 3D pipeline.
170 */
171struct intel_pipeline {
172 struct intel_obj obj;
173
174 struct intel_dev *dev;
175
Chia-I Wudf601c42015-04-17 01:58:07 +0800176 const struct intel_desc_layout_chain *layout_chain;
177
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600178 VkVertexInputBindingDescription vb[INTEL_MAX_VERTEX_BINDING_COUNT];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600179 uint32_t vb_count;
Chia-I Wu1d125092014-10-08 08:49:38 +0800180
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600181 /* VkPipelineIaStateCreateInfo */
182 VkPrimitiveTopology topology;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600183 int prim_type;
Chia-I Wube0a3d92014-09-02 13:20:59 +0800184 bool disable_vs_cache;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600185 bool primitive_restart;
186 uint32_t primitive_restart_index;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600187 /* Index of provoking vertex for each prim type */
188 int provoking_vertex_tri;
189 int provoking_vertex_trifan;
190 int provoking_vertex_line;
191
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600192 // TODO: This should probably be Intel HW state, not VK state.
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600193 /* Depth Buffer format */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600194 VkFormat db_format;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600195
Chia-I Wub6386202015-03-24 11:13:06 +0800196 bool depth_zero_to_one;
197
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600198 VkPipelineCbStateCreateInfo cb_state;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600199
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600200 // VkPipelineRsStateCreateInfo rs_state;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600201 bool depthClipEnable;
202 bool rasterizerDiscardEnable;
Chia-I Wudb3fbc42015-03-24 10:55:40 +0800203 bool use_rs_point_size;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600204
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600205 VkPipelineTessStateCreateInfo tess_state;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600206
207 uint32_t active_shaders;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800208 struct intel_pipeline_shader vs;
Chia-I Wu95959fb2014-09-02 11:01:03 +0800209 struct intel_pipeline_shader tcs;
210 struct intel_pipeline_shader tes;
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800211 struct intel_pipeline_shader gs;
212 struct intel_pipeline_shader fs;
Chia-I Wu95959fb2014-09-02 11:01:03 +0800213 struct intel_pipeline_shader cs;
Tony Barbour8205d902015-04-16 15:59:00 -0600214 VkDeviceSize scratch_size;
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600215
Chia-I Wu8370b402014-08-29 12:28:37 +0800216 uint32_t wa_flags;
217
Courtney Goeltzenleuchter814cd292014-08-28 13:16:27 -0600218 uint32_t cmds[INTEL_PSO_CMD_ENTRIES];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600219 uint32_t cmd_len;
Tony Barbourfa6cac72015-01-16 14:27:35 -0700220
Courtney Goeltzenleuchterdf13a4d2015-02-11 14:14:45 -0700221 bool dual_source_blend_enable;
222
Tony Barbourfa6cac72015-01-16 14:27:35 -0700223 /* The following are only partial HW commands that will need
224 * more processing before sending to the HW
225 */
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600226 // VkPipelineDsStateCreateInfo ds_state
Tony Barbourfa6cac72015-01-16 14:27:35 -0700227 bool stencilTestEnable;
228 uint32_t cmd_depth_stencil;
229 uint32_t cmd_depth_test;
230
231 uint32_t cmd_sf_fill;
232 uint32_t cmd_clip_cull;
233 uint32_t cmd_sf_cull;
234 uint32_t cmd_cb[2 * INTEL_MAX_RENDER_TARGETS];
235 uint32_t sample_count;
236 uint32_t cmd_sample_mask;
Chia-I Wuf85def42015-01-29 00:34:24 +0800237
238 uint32_t cmd_3dstate_sbe[14];
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600239};
240
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600241static inline struct intel_pipeline *intel_pipeline(VkPipeline pipeline)
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600242{
243 return (struct intel_pipeline *) pipeline;
244}
245
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600246static inline struct intel_pipeline *intel_pipeline_from_base(struct intel_base *base)
247{
248 return (struct intel_pipeline *) base;
249}
250
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600251static inline struct intel_pipeline *intel_pipeline_from_obj(struct intel_obj *obj)
252{
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -0600253 return intel_pipeline_from_base(&obj->base);
Courtney Goeltzenleuchter05a60542014-08-15 14:54:34 -0600254}
255
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800256struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev,
257 enum intel_dev_meta_shader id);
Chia-I Wuf13ed3c2015-02-22 14:09:00 +0800258void intel_pipeline_shader_destroy(struct intel_dev *dev,
259 struct intel_pipeline_shader *sh);
Chia-I Wu9fe3ec42014-10-17 09:49:16 +0800260
Chia-I Wu38d1ddf2015-03-02 10:51:39 -0700261void intel_pipeline_init_default_sample_patterns(const struct intel_dev *dev,
262 uint8_t *pat_1x, uint8_t *pat_2x,
263 uint8_t *pat_4x, uint8_t *pat_8x,
264 uint8_t *pat_16x);
265
Chia-I Wuf2b6d722014-09-02 08:52:27 +0800266#endif /* PIPELINE_H */