1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 * @author Jose Fonseca <jfonseca@vmware.com>
36 #include "util/u_memory.h"
37 #include "gallivm/lp_bld_init.h"
38 #include "gallivm/lp_bld_debug.h"
39 #include "lp_context.h"
44 lp_jit_create_types(struct llvmpipe_context
*lp
)
46 struct gallivm_state
*gallivm
= lp
->gallivm
;
47 LLVMContextRef lc
= gallivm
->context
;
48 LLVMTypeRef texture_type
;
50 /* struct lp_jit_texture */
52 LLVMTypeRef elem_types
[LP_JIT_TEXTURE_NUM_FIELDS
];
54 elem_types
[LP_JIT_TEXTURE_WIDTH
] =
55 elem_types
[LP_JIT_TEXTURE_HEIGHT
] =
56 elem_types
[LP_JIT_TEXTURE_DEPTH
] =
57 elem_types
[LP_JIT_TEXTURE_FIRST_LEVEL
] =
58 elem_types
[LP_JIT_TEXTURE_LAST_LEVEL
] = LLVMInt32TypeInContext(lc
);
59 elem_types
[LP_JIT_TEXTURE_ROW_STRIDE
] =
60 elem_types
[LP_JIT_TEXTURE_IMG_STRIDE
] =
61 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TEXTURE_LEVELS
);
62 elem_types
[LP_JIT_TEXTURE_DATA
] =
63 LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(lc
), 0),
64 LP_MAX_TEXTURE_LEVELS
);
65 elem_types
[LP_JIT_TEXTURE_MIN_LOD
] =
66 elem_types
[LP_JIT_TEXTURE_MAX_LOD
] =
67 elem_types
[LP_JIT_TEXTURE_LOD_BIAS
] = LLVMFloatTypeInContext(lc
);
68 elem_types
[LP_JIT_TEXTURE_BORDER_COLOR
] =
69 LLVMArrayType(LLVMFloatTypeInContext(lc
), 4);
71 #if HAVE_LLVM >= 0x0300
72 texture_type
= LLVMStructCreateNamed(gallivm
->context
, "texture");
73 LLVMStructSetBody(texture_type
, elem_types
,
74 Elements(elem_types
), 0);
76 texture_type
= LLVMStructTypeInContext(lc
, elem_types
,
77 Elements(elem_types
), 0);
78 LLVMAddTypeName(gallivm
->module
, "texture", texture_type
);
80 LLVMInvalidateStructLayout(gallivm
->target
, texture_type
);
83 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, width
,
84 gallivm
->target
, texture_type
,
85 LP_JIT_TEXTURE_WIDTH
);
86 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, height
,
87 gallivm
->target
, texture_type
,
88 LP_JIT_TEXTURE_HEIGHT
);
89 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, depth
,
90 gallivm
->target
, texture_type
,
91 LP_JIT_TEXTURE_DEPTH
);
92 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, first_level
,
93 gallivm
->target
, texture_type
,
94 LP_JIT_TEXTURE_FIRST_LEVEL
);
95 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, last_level
,
96 gallivm
->target
, texture_type
,
97 LP_JIT_TEXTURE_LAST_LEVEL
);
98 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, row_stride
,
99 gallivm
->target
, texture_type
,
100 LP_JIT_TEXTURE_ROW_STRIDE
);
101 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, img_stride
,
102 gallivm
->target
, texture_type
,
103 LP_JIT_TEXTURE_IMG_STRIDE
);
104 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, data
,
105 gallivm
->target
, texture_type
,
106 LP_JIT_TEXTURE_DATA
);
107 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, min_lod
,
108 gallivm
->target
, texture_type
,
109 LP_JIT_TEXTURE_MIN_LOD
);
110 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, max_lod
,
111 gallivm
->target
, texture_type
,
112 LP_JIT_TEXTURE_MAX_LOD
);
113 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, lod_bias
,
114 gallivm
->target
, texture_type
,
115 LP_JIT_TEXTURE_LOD_BIAS
);
116 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, border_color
,
117 gallivm
->target
, texture_type
,
118 LP_JIT_TEXTURE_BORDER_COLOR
);
120 LP_CHECK_STRUCT_SIZE(struct lp_jit_texture
,
121 gallivm
->target
, texture_type
);
124 /* struct lp_jit_context */
126 LLVMTypeRef elem_types
[LP_JIT_CTX_COUNT
];
127 LLVMTypeRef context_type
;
129 elem_types
[LP_JIT_CTX_CONSTANTS
] = LLVMPointerType(LLVMFloatTypeInContext(lc
), 0);
130 elem_types
[LP_JIT_CTX_ALPHA_REF
] = LLVMFloatTypeInContext(lc
);
131 elem_types
[LP_JIT_CTX_STENCIL_REF_FRONT
] =
132 elem_types
[LP_JIT_CTX_STENCIL_REF_BACK
] = LLVMInt32TypeInContext(lc
);
133 elem_types
[LP_JIT_CTX_BLEND_COLOR
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
134 elem_types
[LP_JIT_CTX_TEXTURES
] = LLVMArrayType(texture_type
,
137 #if HAVE_LLVM >= 0x0300
138 context_type
= LLVMStructCreateNamed(gallivm
->context
, "context");
139 LLVMStructSetBody(context_type
, elem_types
,
140 Elements(elem_types
), 0);
142 context_type
= LLVMStructTypeInContext(lc
, elem_types
,
143 Elements(elem_types
), 0);
145 LLVMInvalidateStructLayout(gallivm
->target
, context_type
);
147 LLVMAddTypeName(gallivm
->module
, "context", context_type
);
150 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
151 gallivm
->target
, context_type
,
152 LP_JIT_CTX_CONSTANTS
);
153 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
154 gallivm
->target
, context_type
,
155 LP_JIT_CTX_ALPHA_REF
);
156 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_front
,
157 gallivm
->target
, context_type
,
158 LP_JIT_CTX_STENCIL_REF_FRONT
);
159 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_back
,
160 gallivm
->target
, context_type
,
161 LP_JIT_CTX_STENCIL_REF_BACK
);
162 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, blend_color
,
163 gallivm
->target
, context_type
,
164 LP_JIT_CTX_BLEND_COLOR
);
165 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, textures
,
166 gallivm
->target
, context_type
,
167 LP_JIT_CTX_TEXTURES
);
168 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
169 gallivm
->target
, context_type
);
171 lp
->jit_context_ptr_type
= LLVMPointerType(context_type
, 0);
174 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
175 LLVMDumpModule(gallivm
->module
);
181 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
188 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
195 lp_jit_get_context_type(struct llvmpipe_context
*lp
)
197 if (!lp
->jit_context_ptr_type
)
198 lp_jit_create_types(lp
);
200 return lp
->jit_context_ptr_type
;