blob: d83f6a133596276a4a9ae4dab518abf2de296e4a [file] [log] [blame]
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -06001/*
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.
23 */
24
25#include "shader.h"
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -060026
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -060027static void shader_destroy(struct intel_obj *obj)
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -060028{
29 struct intel_shader *shader = intel_shader_from_obj(obj);
30
31 icd_free(shader->pCode);
32 intel_base_destroy(&shader->obj.base);
33}
34
35XGL_RESULT XGLAPI intelCreateShader(
36 XGL_DEVICE device,
37 const XGL_SHADER_CREATE_INFO* pCreateInfo,
38 XGL_SHADER* pShader)
39{
40 struct intel_dev *dev = intel_dev(device);
41 struct intel_shader *shader;
Chia-I Wu4115c892014-08-28 11:56:29 +080042 const struct icd_bil_header *pBIL = pCreateInfo->pCode;
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -060043
44 *pShader = NULL;
45
46 if (pCreateInfo->codeSize == 0) {
47 return XGL_ERROR_INVALID_MEMORY_SIZE;
48 }
49
50 // FYI: for shader allocs XGL_SYSTEM_ALLOC_INTERNAL_SHADER
51
52// typedef struct _XGL_SHADER_CREATE_INFO
53// {
54// XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO
55// const XGL_VOID* pNext; // Pointer to next structure
56// XGL_SIZE codeSize; // Specified in bytes
57// const XGL_VOID* pCode;
58// XGL_FLAGS flags; // Reserved
59// } XGL_SHADER_CREATE_INFO;
60
61 // TODO: really validate IL
Chia-I Wu4115c892014-08-28 11:56:29 +080062 if (pBIL->magic == ICD_BIL_MAGIC) {
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -060063
64 shader = (struct intel_shader *) intel_base_create(dev, sizeof(*shader),
65 dev->base.dbg, XGL_DBG_OBJECT_SHADER, pCreateInfo, 0);
66 if (!shader)
67 return XGL_ERROR_OUT_OF_MEMORY;
68
69 shader->dev = dev;
70
Courtney Goeltzenleuchterd85c1d62014-08-27 14:04:53 -060071 shader->codeSize = pCreateInfo->codeSize;
Courtney Goeltzenleuchtere453b1f2014-08-22 09:24:52 -060072
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -060073 shader->pCode = icd_alloc(pCreateInfo->codeSize, 4, XGL_SYSTEM_ALLOC_INTERNAL_SHADER);
74 if (shader->pCode == NULL) {
75 intel_base_destroy(&shader->obj.base);
76 return XGL_ERROR_OUT_OF_MEMORY;
77 }
Courtney Goeltzenleuchtere453b1f2014-08-22 09:24:52 -060078
Courtney Goeltzenleuchter42509992014-08-21 17:33:46 -060079 shader->obj.destroy = shader_destroy;
Courtney Goeltzenleuchter52ec3362014-08-19 11:52:02 -060080
81 // TODO: Shader pre-processing
82
83 memcpy(shader->pCode, pCreateInfo->pCode, pCreateInfo->codeSize);
84 *pShader = shader;
85
86 return XGL_SUCCESS;
87 }
88
89 return XGL_ERROR_BAD_SHADER_CODE;
90}
91