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