Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 1 | /* |
| 2 | * XGL |
| 3 | * |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 28 | #include "shader.h" |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 29 | #include "pipeline_priv.h" |
Cody Northrop | bc85143 | 2014-09-23 10:06:32 -0600 | [diff] [blame] | 30 | #include "compiler/pipeline/pipeline_compiler_interface.h" |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 31 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 32 | static struct intel_pipeline_rmap_slot *rmap_get_slot(struct intel_pipeline_rmap *rmap, |
| 33 | XGL_DESCRIPTOR_SET_SLOT_TYPE type, |
| 34 | XGL_UINT index) |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 35 | { |
Cody Northrop | 40316a3 | 2014-12-09 19:08:33 -0700 | [diff] [blame] | 36 | // The ordering of below offsets is important. Textures need to come before |
| 37 | // buffers with the current compiler conventions. |
| 38 | const XGL_UINT texture_resource_offset = rmap->rt_count; |
| 39 | const XGL_UINT resource_offset = texture_resource_offset + rmap->texture_resource_count; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 40 | const XGL_UINT uav_offset = resource_offset + rmap->resource_count; |
| 41 | const XGL_UINT sampler_offset = uav_offset + rmap->uav_count; |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 42 | struct intel_pipeline_rmap_slot *slot; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 43 | |
| 44 | switch (type) { |
| 45 | case XGL_SLOT_UNUSED: |
| 46 | slot = NULL; |
| 47 | break; |
Cody Northrop | 40316a3 | 2014-12-09 19:08:33 -0700 | [diff] [blame] | 48 | case XGL_SLOT_SHADER_TEXTURE_RESOURCE: |
| 49 | slot = &rmap->slots[texture_resource_offset + index]; |
| 50 | break; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 51 | case XGL_SLOT_SHADER_RESOURCE: |
| 52 | slot = &rmap->slots[resource_offset + index]; |
| 53 | break; |
| 54 | case XGL_SLOT_SHADER_UAV: |
| 55 | slot = &rmap->slots[uav_offset + index]; |
| 56 | break; |
| 57 | case XGL_SLOT_SHADER_SAMPLER: |
| 58 | slot = &rmap->slots[sampler_offset + index]; |
| 59 | break; |
| 60 | default: |
| 61 | assert(!"unknown rmap slot type"); |
| 62 | slot = NULL; |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | return slot; |
| 67 | } |
| 68 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 69 | static bool rmap_init_slots_with_path(struct intel_pipeline_rmap *rmap, |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 70 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 71 | XGL_UINT *nest_path, |
| 72 | XGL_UINT nest_level) |
| 73 | { |
| 74 | XGL_UINT i; |
| 75 | |
| 76 | for (i = 0; i < mapping->descriptorCount; i++) { |
| 77 | const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i]; |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 78 | struct intel_pipeline_rmap_slot *slot; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 79 | |
| 80 | if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) { |
| 81 | nest_path[nest_level] = i; |
| 82 | if (!rmap_init_slots_with_path(rmap, info->pNextLevelSet, |
| 83 | nest_path, nest_level + 1)) |
| 84 | return false; |
| 85 | |
| 86 | continue; |
| 87 | } |
| 88 | |
| 89 | slot = rmap_get_slot(rmap, info->slotObjectType, |
| 90 | info->shaderEntityIndex); |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 91 | if (!slot || slot->path_len) |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 92 | continue; |
| 93 | |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 94 | slot->path_len = nest_level + 1; |
| 95 | |
| 96 | if (nest_level) { |
| 97 | slot->u.path = icd_alloc(sizeof(slot->u.path[0]) * |
| 98 | slot->path_len, 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 99 | if (!slot->u.path) { |
| 100 | slot->path_len = 0; |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | memcpy(slot->u.path, nest_path, |
| 105 | sizeof(slot->u.path[0]) * nest_level); |
| 106 | slot->u.path[nest_level] = i; |
| 107 | } else { |
| 108 | slot->u.index = i; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return true; |
| 113 | } |
| 114 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 115 | static bool rmap_init_slots(struct intel_pipeline_rmap *rmap, |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 116 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 117 | XGL_UINT depth) |
| 118 | { |
| 119 | XGL_UINT *nest_path; |
| 120 | bool ok; |
| 121 | |
| 122 | if (depth) { |
| 123 | nest_path = icd_alloc(sizeof(nest_path[0]) * depth, |
| 124 | 0, XGL_SYSTEM_ALLOC_INTERNAL_TEMP); |
| 125 | if (!nest_path) |
| 126 | return false; |
| 127 | } else { |
| 128 | nest_path = NULL; |
| 129 | } |
| 130 | |
| 131 | ok = rmap_init_slots_with_path(rmap, mapping, nest_path, 0); |
| 132 | |
| 133 | if (nest_path) |
| 134 | icd_free(nest_path); |
| 135 | |
| 136 | return ok; |
| 137 | } |
| 138 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 139 | static void rmap_update_count(struct intel_pipeline_rmap *rmap, |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 140 | XGL_DESCRIPTOR_SET_SLOT_TYPE type, |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 141 | XGL_UINT index, XGL_UINT rt_count, XGL_UINT ubo_start) |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 142 | { |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 143 | rmap->rt_count = rt_count; |
| 144 | |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 145 | switch (type) { |
| 146 | case XGL_SLOT_UNUSED: |
| 147 | break; |
Cody Northrop | 40316a3 | 2014-12-09 19:08:33 -0700 | [diff] [blame] | 148 | case XGL_SLOT_SHADER_TEXTURE_RESOURCE: |
| 149 | if (rmap->texture_resource_count < index + 1) |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 150 | if (index < ubo_start - rt_count) |
| 151 | rmap->texture_resource_count = index + 1; |
Cody Northrop | 40316a3 | 2014-12-09 19:08:33 -0700 | [diff] [blame] | 152 | break; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 153 | case XGL_SLOT_SHADER_RESOURCE: |
| 154 | if (rmap->resource_count < index + 1) |
| 155 | rmap->resource_count = index + 1; |
| 156 | break; |
| 157 | case XGL_SLOT_SHADER_UAV: |
| 158 | if (rmap->uav_count < index + 1) |
| 159 | rmap->uav_count = index + 1; |
| 160 | break; |
| 161 | case XGL_SLOT_SHADER_SAMPLER: |
| 162 | if (rmap->sampler_count < index + 1) |
| 163 | rmap->sampler_count = index + 1; |
| 164 | break; |
| 165 | default: |
| 166 | assert(!"unknown rmap slot type"); |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 171 | static XGL_UINT rmap_init_counts(struct intel_pipeline_rmap *rmap, |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 172 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 173 | XGL_UINT rt_count, XGL_UINT ubo_start) |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 174 | { |
| 175 | XGL_UINT depth = 0; |
| 176 | XGL_UINT i; |
| 177 | |
| 178 | for (i = 0; i < mapping->descriptorCount; i++) { |
| 179 | const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i]; |
| 180 | |
| 181 | if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) { |
| 182 | const XGL_UINT d = rmap_init_counts(rmap, |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 183 | info->pNextLevelSet, rt_count, ubo_start); |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 184 | if (depth < d + 1) |
| 185 | depth = d + 1; |
| 186 | |
| 187 | continue; |
| 188 | } |
| 189 | |
| 190 | rmap_update_count(rmap, info->slotObjectType, |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 191 | info->shaderEntityIndex, rt_count, ubo_start); |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | return depth; |
| 195 | } |
| 196 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 197 | static void rmap_destroy(struct intel_pipeline_rmap *rmap) |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 198 | { |
| 199 | XGL_UINT i; |
| 200 | |
| 201 | for (i = 0; i < rmap->slot_count; i++) { |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 202 | struct intel_pipeline_rmap_slot *slot = &rmap->slots[i]; |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 203 | |
| 204 | switch (slot->path_len) { |
| 205 | case 0: |
| 206 | case 1: |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 207 | case INTEL_PIPELINE_RMAP_SLOT_RT: |
| 208 | case INTEL_PIPELINE_RMAP_SLOT_DYN: |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 209 | break; |
| 210 | default: |
| 211 | icd_free(slot->u.path); |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | icd_free(rmap->slots); |
| 217 | icd_free(rmap); |
| 218 | } |
| 219 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 220 | static struct intel_pipeline_rmap *rmap_create(struct intel_dev *dev, |
| 221 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 222 | const XGL_DYNAMIC_MEMORY_VIEW_SLOT_INFO *dyn, |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 223 | XGL_UINT rt_count, XGL_UINT ubo_start) |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 224 | { |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 225 | struct intel_pipeline_rmap *rmap; |
| 226 | struct intel_pipeline_rmap_slot *slot; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 227 | XGL_UINT depth, rt; |
| 228 | |
| 229 | rmap = icd_alloc(sizeof(*rmap), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 230 | if (!rmap) |
| 231 | return NULL; |
| 232 | |
| 233 | memset(rmap, 0, sizeof(*rmap)); |
| 234 | |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 235 | depth = rmap_init_counts(rmap, mapping, rt_count, ubo_start); |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 236 | |
| 237 | /* add RTs and the dynamic memory view */ |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 238 | rmap_update_count(rmap, dyn->slotObjectType, dyn->shaderEntityIndex, rt_count, ubo_start); |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 239 | |
Cody Northrop | 40316a3 | 2014-12-09 19:08:33 -0700 | [diff] [blame] | 240 | rmap->slot_count = rmap->rt_count + rmap->texture_resource_count + rmap->resource_count + |
Chia-I Wu | 3b04af5 | 2014-11-08 10:48:20 +0800 | [diff] [blame] | 241 | rmap->uav_count + rmap->sampler_count; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 242 | |
| 243 | rmap->slots = icd_alloc(sizeof(rmap->slots[0]) * rmap->slot_count, |
| 244 | 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 245 | if (!rmap->slots) { |
| 246 | icd_free(rmap); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | memset(rmap->slots, 0, sizeof(rmap->slots[0]) * rmap->slot_count); |
| 251 | |
| 252 | if (!rmap_init_slots(rmap, mapping, depth)) { |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 253 | rmap_destroy(rmap); |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 254 | return NULL; |
| 255 | } |
| 256 | |
| 257 | /* add RTs and the dynamic memory view */ |
| 258 | slot = rmap_get_slot(rmap, dyn->slotObjectType, dyn->shaderEntityIndex); |
| 259 | if (slot) { |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 260 | slot->path_len = INTEL_PIPELINE_RMAP_SLOT_DYN; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 261 | slot->u.index = 0; |
| 262 | } |
| 263 | for (rt = 0; rt < rmap->rt_count; rt++) { |
| 264 | slot = &rmap->slots[rt]; |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 265 | slot->path_len = INTEL_PIPELINE_RMAP_SLOT_RT; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 266 | slot->u.index = rt; |
| 267 | } |
| 268 | |
| 269 | return rmap; |
| 270 | } |
| 271 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 272 | static XGL_RESULT pipeline_build_vs(struct intel_pipeline *pipeline, |
| 273 | const struct intel_pipeline_create_info *info) |
| 274 | { |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 275 | struct intel_pipeline_shader *vs = &pipeline->vs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 276 | XGL_RESULT ret; |
| 277 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 278 | assert(!info->vs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 279 | |
Cody Northrop | 83e2b03 | 2014-09-25 17:00:31 -0600 | [diff] [blame] | 280 | // Right here, lower the IR to ISA using NOS |
| 281 | // This must be after assignment of pipeline constant buffer |
Chia-I Wu | 00c8436 | 2014-12-11 10:14:40 +0800 | [diff] [blame^] | 282 | ret = intel_pipeline_shader_compile(vs, pipeline->dev->gpu, &info->vs); |
Cody Northrop | 83e2b03 | 2014-09-25 17:00:31 -0600 | [diff] [blame] | 283 | if (ret != XGL_SUCCESS) |
| 284 | return ret; |
| 285 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 286 | vs->rmap = rmap_create(pipeline->dev, |
| 287 | &info->vs.descriptorSetMapping[0], |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 288 | &info->vs.dynamicMemoryViewMapping, 0, vs->ubo_start); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 289 | if (!vs->rmap) { |
| 290 | icd_free(vs->pCode); |
| 291 | return XGL_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 292 | } |
| 293 | |
Cody Northrop | 37c4705 | 2014-12-11 09:58:50 -0700 | [diff] [blame] | 294 | // Ensure that all textures in descriptor set were consumed |
| 295 | // This is temporary until we move resource map building to compiler |
| 296 | assert(vs->ubo_start == vs->rmap->texture_resource_count); |
| 297 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 298 | pipeline->active_shaders |= SHADER_VERTEX_FLAG; |
| 299 | |
| 300 | return XGL_SUCCESS; |
| 301 | } |
| 302 | |
| 303 | static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline, |
| 304 | const struct intel_pipeline_create_info *info) |
| 305 | { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 306 | struct intel_pipeline_shader *tcs = &pipeline->tcs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 307 | XGL_RESULT ret; |
| 308 | |
Chia-I Wu | 00c8436 | 2014-12-11 10:14:40 +0800 | [diff] [blame^] | 309 | ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu, &info->tcs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 310 | if (ret != XGL_SUCCESS) |
| 311 | return ret; |
| 312 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 313 | assert(!info->tcs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 314 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 315 | pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG; |
| 316 | |
| 317 | return XGL_SUCCESS; |
| 318 | } |
| 319 | |
| 320 | static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline, |
| 321 | const struct intel_pipeline_create_info *info) |
| 322 | { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 323 | struct intel_pipeline_shader *tes = &pipeline->tes; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 324 | XGL_RESULT ret; |
| 325 | |
Chia-I Wu | 00c8436 | 2014-12-11 10:14:40 +0800 | [diff] [blame^] | 326 | ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu, &info->tes); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 327 | if (ret != XGL_SUCCESS) |
| 328 | return ret; |
| 329 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 330 | assert(!info->tes.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 331 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 332 | pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG; |
| 333 | |
| 334 | return XGL_SUCCESS; |
| 335 | } |
| 336 | |
| 337 | static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline, |
| 338 | const struct intel_pipeline_create_info *info) |
| 339 | { |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 340 | struct intel_pipeline_shader *gs = &pipeline->gs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 341 | XGL_RESULT ret; |
| 342 | |
Chia-I Wu | 00c8436 | 2014-12-11 10:14:40 +0800 | [diff] [blame^] | 343 | ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu, &info->gs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 344 | if (ret != XGL_SUCCESS) |
| 345 | return ret; |
| 346 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 347 | assert(!info->tes.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 348 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 349 | pipeline->active_shaders |= SHADER_GEOMETRY_FLAG; |
| 350 | |
| 351 | return XGL_SUCCESS; |
| 352 | } |
| 353 | |
Chia-I Wu | 787a05b | 2014-12-05 11:02:20 +0800 | [diff] [blame] | 354 | static int pipeline_get_last_color_attachment(const struct intel_pipeline *pipeline, |
| 355 | const struct intel_pipeline_create_info *info) |
| 356 | { |
| 357 | int idx; |
| 358 | |
| 359 | for (idx = ARRAY_SIZE(info->cb.attachment) - 1; idx >= 0; idx--) { |
| 360 | const XGL_PIPELINE_CB_ATTACHMENT_STATE *att = |
| 361 | &info->cb.attachment[idx]; |
| 362 | |
| 363 | if (!icd_format_is_undef(att->format)) |
| 364 | break; |
| 365 | } |
| 366 | |
| 367 | return idx; |
| 368 | } |
| 369 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 370 | static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline, |
| 371 | const struct intel_pipeline_create_info *info) |
| 372 | { |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 373 | struct intel_pipeline_shader *fs = &pipeline->fs; |
Chia-I Wu | 787a05b | 2014-12-05 11:02:20 +0800 | [diff] [blame] | 374 | int rt_count; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 375 | XGL_RESULT ret; |
| 376 | |
Chia-I Wu | 787a05b | 2014-12-05 11:02:20 +0800 | [diff] [blame] | 377 | rt_count = pipeline_get_last_color_attachment(pipeline, info) + 1; |
| 378 | /* at least one NULL RT */ |
| 379 | if (rt_count <= 0) |
| 380 | rt_count = 1; |
| 381 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 382 | assert(!info->fs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 383 | |
Cody Northrop | bc85143 | 2014-09-23 10:06:32 -0600 | [diff] [blame] | 384 | // Right here, lower the IR to ISA using NOS |
Cody Northrop | 83e2b03 | 2014-09-25 17:00:31 -0600 | [diff] [blame] | 385 | // This must be after assignment of pipeline constant buffer |
Chia-I Wu | 00c8436 | 2014-12-11 10:14:40 +0800 | [diff] [blame^] | 386 | ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu, &info->fs); |
Cody Northrop | bc85143 | 2014-09-23 10:06:32 -0600 | [diff] [blame] | 387 | if (ret != XGL_SUCCESS) |
| 388 | return ret; |
| 389 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 390 | fs->rmap = rmap_create(pipeline->dev, |
| 391 | &info->fs.descriptorSetMapping[0], |
Cody Northrop | e65465a | 2014-12-10 08:38:23 -0700 | [diff] [blame] | 392 | &info->fs.dynamicMemoryViewMapping, rt_count, fs->ubo_start); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 393 | if (!fs->rmap) { |
| 394 | icd_free(fs->pCode); |
| 395 | return XGL_ERROR_OUT_OF_MEMORY; |
| 396 | } |
| 397 | |
Cody Northrop | 37c4705 | 2014-12-11 09:58:50 -0700 | [diff] [blame] | 398 | // Ensure that all textures in descriptor set were consumed |
| 399 | // This is temporary until we move resource map building to compiler |
| 400 | assert(fs->ubo_start == fs->rmap->texture_resource_count + fs->rmap->rt_count); |
| 401 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 402 | pipeline->active_shaders |= SHADER_FRAGMENT_FLAG; |
| 403 | |
| 404 | return XGL_SUCCESS; |
| 405 | } |
| 406 | |
| 407 | static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline, |
| 408 | const struct intel_pipeline_create_info *info) |
| 409 | { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 410 | struct intel_pipeline_shader *cs = &pipeline->cs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 411 | XGL_RESULT ret; |
| 412 | |
Chia-I Wu | 00c8436 | 2014-12-11 10:14:40 +0800 | [diff] [blame^] | 413 | ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu, &info->compute.cs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 414 | if (ret != XGL_SUCCESS) |
| 415 | return ret; |
| 416 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 417 | assert(!info->compute.cs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 418 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 419 | pipeline->active_shaders |= SHADER_COMPUTE_FLAG; |
| 420 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 421 | return XGL_SUCCESS; |
| 422 | } |
| 423 | |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 424 | static void pipeline_post_build_shader(struct intel_pipeline *pipeline, |
| 425 | struct intel_pipeline_shader *sh, |
| 426 | const XGL_PIPELINE_SHADER *sh_info) |
| 427 | { |
| 428 | sh->max_threads = |
| 429 | intel_gpu_get_max_threads(pipeline->dev->gpu, sh_info->stage); |
Chia-I Wu | b102473 | 2014-12-19 13:00:29 +0800 | [diff] [blame] | 430 | |
| 431 | /* 1KB aligned */ |
| 432 | sh->scratch_offset = u_align(pipeline->scratch_size, 1024); |
| 433 | pipeline->scratch_size = sh->scratch_offset + |
| 434 | sh->per_thread_scratch_size * sh->max_threads; |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 435 | } |
| 436 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 437 | XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline, |
| 438 | const struct intel_pipeline_create_info *info) |
| 439 | { |
| 440 | XGL_RESULT ret = XGL_SUCCESS; |
| 441 | |
| 442 | if (ret == XGL_SUCCESS && info->vs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 443 | ret = pipeline_build_vs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 444 | if (ret == XGL_SUCCESS && info->tcs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 445 | ret = pipeline_build_tcs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 446 | if (ret == XGL_SUCCESS && info->tes.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 447 | ret = pipeline_build_tes(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 448 | if (ret == XGL_SUCCESS && info->gs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 449 | ret = pipeline_build_gs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 450 | if (ret == XGL_SUCCESS && info->fs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 451 | ret = pipeline_build_fs(pipeline, info); |
| 452 | |
| 453 | if (ret == XGL_SUCCESS && info->compute.cs.shader) |
| 454 | ret = pipeline_build_cs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 455 | |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 456 | if (pipeline->active_shaders & SHADER_VERTEX_FLAG) |
| 457 | pipeline_post_build_shader(pipeline, &pipeline->vs, &info->vs); |
| 458 | if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) |
| 459 | pipeline_post_build_shader(pipeline, &pipeline->tcs, &info->tcs); |
| 460 | if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) |
| 461 | pipeline_post_build_shader(pipeline, &pipeline->tes, &info->tes); |
| 462 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) |
| 463 | pipeline_post_build_shader(pipeline, &pipeline->gs, &info->gs); |
| 464 | if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) |
| 465 | pipeline_post_build_shader(pipeline, &pipeline->fs, &info->fs); |
| 466 | if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) |
| 467 | pipeline_post_build_shader(pipeline, &pipeline->cs, &info->compute.cs); |
| 468 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 469 | return ret; |
| 470 | } |
| 471 | |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 472 | static void pipeline_tear_shader(struct intel_pipeline_shader *sh) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 473 | { |
| 474 | icd_free(sh->pCode); |
| 475 | if (sh->rmap) |
| 476 | rmap_destroy(sh->rmap); |
| 477 | } |
| 478 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 479 | void pipeline_tear_shaders(struct intel_pipeline *pipeline) |
| 480 | { |
| 481 | if (pipeline->active_shaders & SHADER_VERTEX_FLAG) { |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 482 | pipeline_tear_shader(&pipeline->vs); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 483 | } |
| 484 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 485 | if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 486 | pipeline_tear_shader(&pipeline->tcs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 490 | pipeline_tear_shader(&pipeline->tes); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
| 494 | pipeline_tear_shader(&pipeline->gs); |
| 495 | } |
| 496 | |
| 497 | if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) { |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 498 | pipeline_tear_shader(&pipeline->fs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 502 | pipeline_tear_shader(&pipeline->cs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 503 | } |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 504 | } |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 505 | |
| 506 | struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev, |
| 507 | enum intel_dev_meta_shader id) |
| 508 | { |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 509 | struct intel_pipeline_shader *sh; |
Chia-I Wu | 005c47c | 2014-10-22 13:49:13 +0800 | [diff] [blame] | 510 | XGL_RESULT ret; |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 511 | |
| 512 | sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 513 | if (!sh) |
| 514 | return NULL; |
| 515 | memset(sh, 0, sizeof(*sh)); |
| 516 | |
Chia-I Wu | 005c47c | 2014-10-22 13:49:13 +0800 | [diff] [blame] | 517 | ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id); |
| 518 | if (ret != XGL_SUCCESS) { |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 519 | icd_free(sh); |
| 520 | return NULL; |
| 521 | } |
| 522 | |
Chia-I Wu | 3f4bd10 | 2014-12-19 13:14:42 +0800 | [diff] [blame] | 523 | switch (id) { |
| 524 | case INTEL_DEV_META_VS_FILL_MEM: |
| 525 | case INTEL_DEV_META_VS_COPY_MEM: |
| 526 | case INTEL_DEV_META_VS_COPY_MEM_UNALIGNED: |
| 527 | sh->max_threads = intel_gpu_get_max_threads(dev->gpu, |
| 528 | XGL_SHADER_STAGE_VERTEX); |
| 529 | break; |
| 530 | default: |
| 531 | sh->max_threads = intel_gpu_get_max_threads(dev->gpu, |
| 532 | XGL_SHADER_STAGE_FRAGMENT); |
| 533 | break; |
| 534 | } |
| 535 | |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 536 | return sh; |
| 537 | } |
| 538 | |
| 539 | void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh) |
| 540 | { |
| 541 | if (sh->rmap) |
| 542 | rmap_destroy(sh->rmap); |
| 543 | if (sh->pCode) |
| 544 | icd_free(sh->pCode); |
| 545 | icd_free(sh); |
| 546 | } |