Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 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 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | * Chia-I Wu <olv@lunarg.com> |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 27 | */ |
| 28 | |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 29 | #include "dev.h" |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 30 | #include "shader.h" |
Cody Northrop | 0eb5eea | 2014-09-19 15:11:52 -0600 | [diff] [blame] | 31 | #include "compiler/shader/compiler_interface.h" |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 32 | |
Courtney Goeltzenleuchter | 4250999 | 2014-08-21 17:33:46 -0600 | [diff] [blame] | 33 | static void shader_destroy(struct intel_obj *obj) |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 34 | { |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 35 | struct intel_shader *sh = intel_shader_from_obj(obj); |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 36 | |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 37 | if (sh->ir) |
| 38 | shader_destroy_ir(sh->ir); |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 39 | intel_base_destroy(&sh->obj.base); |
| 40 | } |
| 41 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 42 | static VK_RESULT shader_create(struct intel_dev *dev, |
| 43 | const VK_SHADER_CREATE_INFO *info, |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 44 | struct intel_shader **sh_ret) |
| 45 | { |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 46 | const struct icd_spv_header *spv = |
| 47 | (const struct icd_spv_header *) info->pCode; |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 48 | struct intel_shader *sh; |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 49 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 50 | sh = (struct intel_shader *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 51 | sizeof(*sh), dev->base.dbg, VK_DBG_OBJECT_SHADER, info, 0); |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 52 | if (!sh) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 53 | return VK_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 54 | |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 55 | if (info->codeSize < sizeof(*spv)) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 56 | return VK_ERROR_INVALID_MEMORY_SIZE; |
Cody Northrop | acfb049 | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 57 | if (spv->magic != ICD_SPV_MAGIC) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 58 | return VK_ERROR_BAD_SHADER_CODE; |
Courtney Goeltzenleuchter | d7f0dce | 2014-10-06 09:45:33 -0600 | [diff] [blame] | 59 | |
Chia-I Wu | a4d1b39 | 2014-10-10 13:57:29 +0800 | [diff] [blame] | 60 | sh->ir = shader_create_ir(dev->gpu, info->pCode, info->codeSize); |
| 61 | if (!sh->ir) { |
Courtney Goeltzenleuchter | ef5b116 | 2014-10-10 16:29:46 -0600 | [diff] [blame] | 62 | shader_destroy(&sh->obj); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | return VK_ERROR_UNKNOWN; |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | sh->obj.destroy = shader_destroy; |
| 67 | |
| 68 | *sh_ret = sh; |
| 69 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 70 | return VK_SUCCESS; |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 71 | } |
| 72 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 73 | ICD_EXPORT VK_RESULT VKAPI vkCreateShader( |
| 74 | VK_DEVICE device, |
| 75 | const VK_SHADER_CREATE_INFO* pCreateInfo, |
| 76 | VK_SHADER* pShader) |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 77 | { |
| 78 | struct intel_dev *dev = intel_dev(device); |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 79 | |
Chia-I Wu | 9194a6d | 2014-08-28 11:36:48 +0800 | [diff] [blame] | 80 | return shader_create(dev, pCreateInfo, (struct intel_shader **) pShader); |
Courtney Goeltzenleuchter | 52ec336 | 2014-08-19 11:52:02 -0600 | [diff] [blame] | 81 | } |