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