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 | { |
| 36 | const XGL_UINT resource_offset = rmap->rt_count; |
| 37 | const XGL_UINT uav_offset = resource_offset + rmap->resource_count; |
| 38 | const XGL_UINT sampler_offset = uav_offset + rmap->uav_count; |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 39 | struct intel_pipeline_rmap_slot *slot; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 40 | |
| 41 | switch (type) { |
| 42 | case XGL_SLOT_UNUSED: |
| 43 | slot = NULL; |
| 44 | break; |
| 45 | case XGL_SLOT_SHADER_RESOURCE: |
| 46 | slot = &rmap->slots[resource_offset + index]; |
| 47 | break; |
| 48 | case XGL_SLOT_SHADER_UAV: |
| 49 | slot = &rmap->slots[uav_offset + index]; |
| 50 | break; |
| 51 | case XGL_SLOT_SHADER_SAMPLER: |
| 52 | slot = &rmap->slots[sampler_offset + index]; |
| 53 | break; |
| 54 | default: |
| 55 | assert(!"unknown rmap slot type"); |
| 56 | slot = NULL; |
| 57 | break; |
| 58 | } |
| 59 | |
| 60 | return slot; |
| 61 | } |
| 62 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 63 | 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] | 64 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 65 | XGL_UINT *nest_path, |
| 66 | XGL_UINT nest_level) |
| 67 | { |
| 68 | XGL_UINT i; |
| 69 | |
| 70 | for (i = 0; i < mapping->descriptorCount; i++) { |
| 71 | const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i]; |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 72 | struct intel_pipeline_rmap_slot *slot; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 73 | |
| 74 | if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) { |
| 75 | nest_path[nest_level] = i; |
| 76 | if (!rmap_init_slots_with_path(rmap, info->pNextLevelSet, |
| 77 | nest_path, nest_level + 1)) |
| 78 | return false; |
| 79 | |
| 80 | continue; |
| 81 | } |
| 82 | |
| 83 | slot = rmap_get_slot(rmap, info->slotObjectType, |
| 84 | info->shaderEntityIndex); |
| 85 | if (!slot) |
| 86 | continue; |
| 87 | |
| 88 | assert(!slot->path_len); |
| 89 | slot->path_len = nest_level + 1; |
| 90 | |
| 91 | if (nest_level) { |
| 92 | slot->u.path = icd_alloc(sizeof(slot->u.path[0]) * |
| 93 | slot->path_len, 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 94 | if (!slot->u.path) { |
| 95 | slot->path_len = 0; |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | memcpy(slot->u.path, nest_path, |
| 100 | sizeof(slot->u.path[0]) * nest_level); |
| 101 | slot->u.path[nest_level] = i; |
| 102 | } else { |
| 103 | slot->u.index = i; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return true; |
| 108 | } |
| 109 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 110 | static bool rmap_init_slots(struct intel_pipeline_rmap *rmap, |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 111 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 112 | XGL_UINT depth) |
| 113 | { |
| 114 | XGL_UINT *nest_path; |
| 115 | bool ok; |
| 116 | |
| 117 | if (depth) { |
| 118 | nest_path = icd_alloc(sizeof(nest_path[0]) * depth, |
| 119 | 0, XGL_SYSTEM_ALLOC_INTERNAL_TEMP); |
| 120 | if (!nest_path) |
| 121 | return false; |
| 122 | } else { |
| 123 | nest_path = NULL; |
| 124 | } |
| 125 | |
| 126 | ok = rmap_init_slots_with_path(rmap, mapping, nest_path, 0); |
| 127 | |
| 128 | if (nest_path) |
| 129 | icd_free(nest_path); |
| 130 | |
| 131 | return ok; |
| 132 | } |
| 133 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 134 | static void rmap_update_count(struct intel_pipeline_rmap *rmap, |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 135 | XGL_DESCRIPTOR_SET_SLOT_TYPE type, |
| 136 | XGL_UINT index) |
| 137 | { |
| 138 | switch (type) { |
| 139 | case XGL_SLOT_UNUSED: |
| 140 | break; |
| 141 | case XGL_SLOT_SHADER_RESOURCE: |
| 142 | if (rmap->resource_count < index + 1) |
| 143 | rmap->resource_count = index + 1; |
| 144 | break; |
| 145 | case XGL_SLOT_SHADER_UAV: |
| 146 | if (rmap->uav_count < index + 1) |
| 147 | rmap->uav_count = index + 1; |
| 148 | break; |
| 149 | case XGL_SLOT_SHADER_SAMPLER: |
| 150 | if (rmap->sampler_count < index + 1) |
| 151 | rmap->sampler_count = index + 1; |
| 152 | break; |
| 153 | default: |
| 154 | assert(!"unknown rmap slot type"); |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 159 | static XGL_UINT rmap_init_counts(struct intel_pipeline_rmap *rmap, |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 160 | const XGL_DESCRIPTOR_SET_MAPPING *mapping) |
| 161 | { |
| 162 | XGL_UINT depth = 0; |
| 163 | XGL_UINT i; |
| 164 | |
| 165 | for (i = 0; i < mapping->descriptorCount; i++) { |
| 166 | const XGL_DESCRIPTOR_SLOT_INFO *info = &mapping->pDescriptorInfo[i]; |
| 167 | |
| 168 | if (info->slotObjectType == XGL_SLOT_NEXT_DESCRIPTOR_SET) { |
| 169 | const XGL_UINT d = rmap_init_counts(rmap, |
| 170 | info->pNextLevelSet); |
| 171 | if (depth < d + 1) |
| 172 | depth = d + 1; |
| 173 | |
| 174 | continue; |
| 175 | } |
| 176 | |
| 177 | rmap_update_count(rmap, info->slotObjectType, |
| 178 | info->shaderEntityIndex); |
| 179 | } |
| 180 | |
| 181 | return depth; |
| 182 | } |
| 183 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 184 | static void rmap_destroy(struct intel_pipeline_rmap *rmap) |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 185 | { |
| 186 | XGL_UINT i; |
| 187 | |
| 188 | for (i = 0; i < rmap->slot_count; i++) { |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 189 | struct intel_pipeline_rmap_slot *slot = &rmap->slots[i]; |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 190 | |
| 191 | switch (slot->path_len) { |
| 192 | case 0: |
| 193 | case 1: |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 194 | case INTEL_PIPELINE_RMAP_SLOT_RT: |
| 195 | case INTEL_PIPELINE_RMAP_SLOT_DYN: |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 196 | break; |
| 197 | default: |
| 198 | icd_free(slot->u.path); |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | icd_free(rmap->slots); |
| 204 | icd_free(rmap); |
| 205 | } |
| 206 | |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 207 | static struct intel_pipeline_rmap *rmap_create(struct intel_dev *dev, |
| 208 | const XGL_DESCRIPTOR_SET_MAPPING *mapping, |
| 209 | const XGL_DYNAMIC_MEMORY_VIEW_SLOT_INFO *dyn, |
| 210 | XGL_UINT rt_count) |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 211 | { |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 212 | struct intel_pipeline_rmap *rmap; |
| 213 | struct intel_pipeline_rmap_slot *slot; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 214 | XGL_UINT depth, rt; |
| 215 | |
| 216 | rmap = icd_alloc(sizeof(*rmap), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 217 | if (!rmap) |
| 218 | return NULL; |
| 219 | |
| 220 | memset(rmap, 0, sizeof(*rmap)); |
| 221 | |
| 222 | depth = rmap_init_counts(rmap, mapping); |
| 223 | |
| 224 | /* add RTs and the dynamic memory view */ |
| 225 | rmap_update_count(rmap, dyn->slotObjectType, dyn->shaderEntityIndex); |
| 226 | rmap->rt_count = rt_count; |
| 227 | |
| 228 | rmap->slot_count = rmap->rt_count + rmap->resource_count + |
Chia-I Wu | 3b04af5 | 2014-11-08 10:48:20 +0800 | [diff] [blame^] | 229 | rmap->uav_count + rmap->sampler_count; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 230 | |
| 231 | rmap->slots = icd_alloc(sizeof(rmap->slots[0]) * rmap->slot_count, |
| 232 | 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 233 | if (!rmap->slots) { |
| 234 | icd_free(rmap); |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | memset(rmap->slots, 0, sizeof(rmap->slots[0]) * rmap->slot_count); |
| 239 | |
| 240 | if (!rmap_init_slots(rmap, mapping, depth)) { |
Chia-I Wu | a6d50aa | 2014-09-02 10:21:34 +0800 | [diff] [blame] | 241 | rmap_destroy(rmap); |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 242 | return NULL; |
| 243 | } |
| 244 | |
| 245 | /* add RTs and the dynamic memory view */ |
| 246 | slot = rmap_get_slot(rmap, dyn->slotObjectType, dyn->shaderEntityIndex); |
| 247 | if (slot) { |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 248 | slot->path_len = INTEL_PIPELINE_RMAP_SLOT_DYN; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 249 | slot->u.index = 0; |
| 250 | } |
| 251 | for (rt = 0; rt < rmap->rt_count; rt++) { |
| 252 | slot = &rmap->slots[rt]; |
Chia-I Wu | 2098376 | 2014-09-02 12:07:28 +0800 | [diff] [blame] | 253 | slot->path_len = INTEL_PIPELINE_RMAP_SLOT_RT; |
Chia-I Wu | 1f7540b | 2014-08-22 13:56:18 +0800 | [diff] [blame] | 254 | slot->u.index = rt; |
| 255 | } |
| 256 | |
| 257 | return rmap; |
| 258 | } |
| 259 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 260 | static XGL_RESULT pipeline_build_vs(struct intel_pipeline *pipeline, |
| 261 | const struct intel_pipeline_create_info *info) |
| 262 | { |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 263 | struct intel_pipeline_shader *vs = &pipeline->vs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 264 | XGL_RESULT ret; |
| 265 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 266 | assert(!info->vs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 267 | |
Cody Northrop | 83e2b03 | 2014-09-25 17:00:31 -0600 | [diff] [blame] | 268 | // Right here, lower the IR to ISA using NOS |
| 269 | // This must be after assignment of pipeline constant buffer |
Chia-I Wu | 714f0a3 | 2014-10-11 14:08:15 +0800 | [diff] [blame] | 270 | ret = intel_pipeline_shader_compile(vs, pipeline->dev->gpu, |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 271 | intel_shader(info->vs.shader)->ir); |
Cody Northrop | 83e2b03 | 2014-09-25 17:00:31 -0600 | [diff] [blame] | 272 | if (ret != XGL_SUCCESS) |
| 273 | return ret; |
| 274 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 275 | vs->rmap = rmap_create(pipeline->dev, |
| 276 | &info->vs.descriptorSetMapping[0], |
| 277 | &info->vs.dynamicMemoryViewMapping, 0); |
| 278 | if (!vs->rmap) { |
| 279 | icd_free(vs->pCode); |
| 280 | return XGL_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 281 | } |
| 282 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 283 | pipeline->active_shaders |= SHADER_VERTEX_FLAG; |
| 284 | |
| 285 | return XGL_SUCCESS; |
| 286 | } |
| 287 | |
| 288 | static XGL_RESULT pipeline_build_tcs(struct intel_pipeline *pipeline, |
| 289 | const struct intel_pipeline_create_info *info) |
| 290 | { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 291 | struct intel_pipeline_shader *tcs = &pipeline->tcs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 292 | XGL_RESULT ret; |
| 293 | |
Chia-I Wu | 714f0a3 | 2014-10-11 14:08:15 +0800 | [diff] [blame] | 294 | ret = intel_pipeline_shader_compile(tcs, pipeline->dev->gpu, |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 295 | intel_shader(info->tcs.shader)->ir); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 296 | if (ret != XGL_SUCCESS) |
| 297 | return ret; |
| 298 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 299 | assert(!info->tcs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 300 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 301 | pipeline->active_shaders |= SHADER_TESS_CONTROL_FLAG; |
| 302 | |
| 303 | return XGL_SUCCESS; |
| 304 | } |
| 305 | |
| 306 | static XGL_RESULT pipeline_build_tes(struct intel_pipeline *pipeline, |
| 307 | const struct intel_pipeline_create_info *info) |
| 308 | { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 309 | struct intel_pipeline_shader *tes = &pipeline->tes; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 310 | XGL_RESULT ret; |
| 311 | |
Chia-I Wu | 714f0a3 | 2014-10-11 14:08:15 +0800 | [diff] [blame] | 312 | ret = intel_pipeline_shader_compile(tes, pipeline->dev->gpu, |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 313 | intel_shader(info->tes.shader)->ir); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 314 | if (ret != XGL_SUCCESS) |
| 315 | return ret; |
| 316 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 317 | assert(!info->tes.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 318 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 319 | pipeline->active_shaders |= SHADER_TESS_EVAL_FLAG; |
| 320 | |
| 321 | return XGL_SUCCESS; |
| 322 | } |
| 323 | |
| 324 | static XGL_RESULT pipeline_build_gs(struct intel_pipeline *pipeline, |
| 325 | const struct intel_pipeline_create_info *info) |
| 326 | { |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 327 | struct intel_pipeline_shader *gs = &pipeline->gs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 328 | XGL_RESULT ret; |
| 329 | |
Chia-I Wu | 714f0a3 | 2014-10-11 14:08:15 +0800 | [diff] [blame] | 330 | ret = intel_pipeline_shader_compile(gs, pipeline->dev->gpu, |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 331 | intel_shader(info->gs.shader)->ir); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 332 | if (ret != XGL_SUCCESS) |
| 333 | return ret; |
| 334 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 335 | assert(!info->tes.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 336 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 337 | pipeline->active_shaders |= SHADER_GEOMETRY_FLAG; |
| 338 | |
| 339 | return XGL_SUCCESS; |
| 340 | } |
| 341 | |
| 342 | static XGL_RESULT pipeline_build_fs(struct intel_pipeline *pipeline, |
| 343 | const struct intel_pipeline_create_info *info) |
| 344 | { |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 345 | struct intel_pipeline_shader *fs = &pipeline->fs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 346 | XGL_RESULT ret; |
| 347 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 348 | assert(!info->fs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 349 | |
Cody Northrop | bc85143 | 2014-09-23 10:06:32 -0600 | [diff] [blame] | 350 | // Right here, lower the IR to ISA using NOS |
Cody Northrop | 83e2b03 | 2014-09-25 17:00:31 -0600 | [diff] [blame] | 351 | // This must be after assignment of pipeline constant buffer |
Chia-I Wu | 714f0a3 | 2014-10-11 14:08:15 +0800 | [diff] [blame] | 352 | ret = intel_pipeline_shader_compile(fs, pipeline->dev->gpu, |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 353 | intel_shader(info->fs.shader)->ir); |
Cody Northrop | bc85143 | 2014-09-23 10:06:32 -0600 | [diff] [blame] | 354 | if (ret != XGL_SUCCESS) |
| 355 | return ret; |
| 356 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 357 | /* assuming one RT; need to parse the shader */ |
| 358 | fs->rmap = rmap_create(pipeline->dev, |
| 359 | &info->fs.descriptorSetMapping[0], |
| 360 | &info->fs.dynamicMemoryViewMapping, 1); |
| 361 | if (!fs->rmap) { |
| 362 | icd_free(fs->pCode); |
| 363 | return XGL_ERROR_OUT_OF_MEMORY; |
| 364 | } |
| 365 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 366 | pipeline->active_shaders |= SHADER_FRAGMENT_FLAG; |
| 367 | |
| 368 | return XGL_SUCCESS; |
| 369 | } |
| 370 | |
| 371 | static XGL_RESULT pipeline_build_cs(struct intel_pipeline *pipeline, |
| 372 | const struct intel_pipeline_create_info *info) |
| 373 | { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 374 | struct intel_pipeline_shader *cs = &pipeline->cs; |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 375 | XGL_RESULT ret; |
| 376 | |
Chia-I Wu | 714f0a3 | 2014-10-11 14:08:15 +0800 | [diff] [blame] | 377 | ret = intel_pipeline_shader_compile(cs, pipeline->dev->gpu, |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 378 | intel_shader(info->compute.cs.shader)->ir); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 379 | if (ret != XGL_SUCCESS) |
| 380 | return ret; |
| 381 | |
Chia-I Wu | 4680978 | 2014-10-07 15:40:38 +0800 | [diff] [blame] | 382 | assert(!info->compute.cs.linkConstBufferCount); |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 383 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 384 | pipeline->active_shaders |= SHADER_COMPUTE_FLAG; |
| 385 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 386 | return XGL_SUCCESS; |
| 387 | } |
| 388 | |
| 389 | XGL_RESULT pipeline_build_shaders(struct intel_pipeline *pipeline, |
| 390 | const struct intel_pipeline_create_info *info) |
| 391 | { |
| 392 | XGL_RESULT ret = XGL_SUCCESS; |
| 393 | |
| 394 | if (ret == XGL_SUCCESS && info->vs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 395 | ret = pipeline_build_vs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 396 | if (ret == XGL_SUCCESS && info->tcs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 397 | ret = pipeline_build_tcs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 398 | if (ret == XGL_SUCCESS && info->tes.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 399 | ret = pipeline_build_tes(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 400 | if (ret == XGL_SUCCESS && info->gs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 401 | ret = pipeline_build_gs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 402 | if (ret == XGL_SUCCESS && info->fs.shader) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 403 | ret = pipeline_build_fs(pipeline, info); |
| 404 | |
| 405 | if (ret == XGL_SUCCESS && info->compute.cs.shader) |
| 406 | ret = pipeline_build_cs(pipeline, info); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 407 | |
| 408 | return ret; |
| 409 | } |
| 410 | |
Chia-I Wu | f2b6d72 | 2014-09-02 08:52:27 +0800 | [diff] [blame] | 411 | static void pipeline_tear_shader(struct intel_pipeline_shader *sh) |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 412 | { |
| 413 | icd_free(sh->pCode); |
| 414 | if (sh->rmap) |
| 415 | rmap_destroy(sh->rmap); |
| 416 | } |
| 417 | |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 418 | void pipeline_tear_shaders(struct intel_pipeline *pipeline) |
| 419 | { |
| 420 | if (pipeline->active_shaders & SHADER_VERTEX_FLAG) { |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 421 | pipeline_tear_shader(&pipeline->vs); |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 422 | } |
| 423 | |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 424 | if (pipeline->active_shaders & SHADER_TESS_CONTROL_FLAG) { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 425 | pipeline_tear_shader(&pipeline->tcs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | if (pipeline->active_shaders & SHADER_TESS_EVAL_FLAG) { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 429 | pipeline_tear_shader(&pipeline->tes); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | if (pipeline->active_shaders & SHADER_GEOMETRY_FLAG) { |
| 433 | pipeline_tear_shader(&pipeline->gs); |
| 434 | } |
| 435 | |
| 436 | if (pipeline->active_shaders & SHADER_FRAGMENT_FLAG) { |
Chia-I Wu | c3ddee6 | 2014-09-02 10:53:20 +0800 | [diff] [blame] | 437 | pipeline_tear_shader(&pipeline->fs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | if (pipeline->active_shaders & SHADER_COMPUTE_FLAG) { |
Chia-I Wu | 95959fb | 2014-09-02 11:01:03 +0800 | [diff] [blame] | 441 | pipeline_tear_shader(&pipeline->cs); |
Chia-I Wu | 39026c9 | 2014-09-02 10:03:19 +0800 | [diff] [blame] | 442 | } |
Chia-I Wu | 9882459 | 2014-09-02 09:42:46 +0800 | [diff] [blame] | 443 | } |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 444 | |
| 445 | struct intel_pipeline_shader *intel_pipeline_shader_create_meta(struct intel_dev *dev, |
| 446 | enum intel_dev_meta_shader id) |
| 447 | { |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 448 | struct intel_pipeline_shader *sh; |
Chia-I Wu | 005c47c | 2014-10-22 13:49:13 +0800 | [diff] [blame] | 449 | XGL_RESULT ret; |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 450 | |
| 451 | sh = icd_alloc(sizeof(*sh), 0, XGL_SYSTEM_ALLOC_INTERNAL); |
| 452 | if (!sh) |
| 453 | return NULL; |
| 454 | memset(sh, 0, sizeof(*sh)); |
| 455 | |
Chia-I Wu | 005c47c | 2014-10-22 13:49:13 +0800 | [diff] [blame] | 456 | ret = intel_pipeline_shader_compile_meta(sh, dev->gpu, id); |
| 457 | if (ret != XGL_SUCCESS) { |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 458 | icd_free(sh); |
| 459 | return NULL; |
| 460 | } |
| 461 | |
Chia-I Wu | 9fe3ec4 | 2014-10-17 09:49:16 +0800 | [diff] [blame] | 462 | return sh; |
| 463 | } |
| 464 | |
| 465 | void intel_pipeline_shader_destroy(struct intel_pipeline_shader *sh) |
| 466 | { |
| 467 | if (sh->rmap) |
| 468 | rmap_destroy(sh->rmap); |
| 469 | if (sh->pCode) |
| 470 | icd_free(sh->pCode); |
| 471 | icd_free(sh); |
| 472 | } |