blob: cd002bd3e0a7dc995da509784da9eb73391224e1 [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"
26#include "shader_il.h"
27
28static void intelShaderDestroy(struct intel_obj *obj)
29{
30 struct intel_shader *shader = intel_shader_from_obj(obj);
31
32 icd_free(shader->pCode);
33 intel_base_destroy(&shader->obj.base);
34}
35
36XGL_RESULT XGLAPI intelCreateShader(
37 XGL_DEVICE device,
38 const XGL_SHADER_CREATE_INFO* pCreateInfo,
39 XGL_SHADER* pShader)
40{
41 struct intel_dev *dev = intel_dev(device);
42 struct intel_shader *shader;
43 const struct bil_header *pBIL = pCreateInfo->pCode;
44
45 *pShader = NULL;
46
47 if (pCreateInfo->codeSize == 0) {
48 return XGL_ERROR_INVALID_MEMORY_SIZE;
49 }
50
51 // FYI: for shader allocs XGL_SYSTEM_ALLOC_INTERNAL_SHADER
52
53// typedef struct _XGL_SHADER_CREATE_INFO
54// {
55// XGL_STRUCTURE_TYPE sType; // Must be XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO
56// const XGL_VOID* pNext; // Pointer to next structure
57// XGL_SIZE codeSize; // Specified in bytes
58// const XGL_VOID* pCode;
59// XGL_FLAGS flags; // Reserved
60// } XGL_SHADER_CREATE_INFO;
61
62 // TODO: really validate IL
63 if (pBIL->bil_magic == BILMagicNumber) {
64
65 shader = (struct intel_shader *) intel_base_create(dev, sizeof(*shader),
66 dev->base.dbg, XGL_DBG_OBJECT_SHADER, pCreateInfo, 0);
67 if (!shader)
68 return XGL_ERROR_OUT_OF_MEMORY;
69
70 shader->dev = dev;
71
72 shader->pCode = icd_alloc(pCreateInfo->codeSize, 4, XGL_SYSTEM_ALLOC_INTERNAL_SHADER);
73 if (shader->pCode == NULL) {
74 intel_base_destroy(&shader->obj.base);
75 return XGL_ERROR_OUT_OF_MEMORY;
76 }
77 shader->codeSize = pCreateInfo->codeSize;
78 shader->obj.destroy = intelShaderDestroy;
79
80 // TODO: Shader pre-processing
81
82 memcpy(shader->pCode, pCreateInfo->pCode, pCreateInfo->codeSize);
83 *pShader = shader;
84
85 return XGL_SUCCESS;
86 }
87
88 return XGL_ERROR_BAD_SHADER_CODE;
89}
90