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 lp_fragment_shader_variant
*lp
)
46 struct gallivm_state
*gallivm
= lp
->gallivm
;
47 LLVMContextRef lc
= gallivm
->context
;
48 LLVMTypeRef viewport_type
, texture_type
, sampler_type
;
50 /* struct lp_jit_viewport */
52 LLVMTypeRef elem_types
[LP_JIT_VIEWPORT_NUM_FIELDS
];
54 elem_types
[LP_JIT_VIEWPORT_MIN_DEPTH
] =
55 elem_types
[LP_JIT_VIEWPORT_MAX_DEPTH
] = LLVMFloatTypeInContext(lc
);
57 viewport_type
= LLVMStructTypeInContext(lc
, elem_types
,
58 Elements(elem_types
), 0);
60 #if HAVE_LLVM < 0x0300
61 LLVMAddTypeName(gallivm
->module
, "viewport", viewport_type
);
63 LLVMInvalidateStructLayout(gallivm
->target
, viewport_type
);
66 LP_CHECK_MEMBER_OFFSET(struct lp_jit_viewport
, min_depth
,
67 gallivm
->target
, viewport_type
,
68 LP_JIT_VIEWPORT_MIN_DEPTH
);
69 LP_CHECK_MEMBER_OFFSET(struct lp_jit_viewport
, max_depth
,
70 gallivm
->target
, viewport_type
,
71 LP_JIT_VIEWPORT_MAX_DEPTH
);
72 LP_CHECK_STRUCT_SIZE(struct lp_jit_viewport
,
73 gallivm
->target
, viewport_type
);
76 /* struct lp_jit_texture */
78 LLVMTypeRef elem_types
[LP_JIT_TEXTURE_NUM_FIELDS
];
80 elem_types
[LP_JIT_TEXTURE_WIDTH
] =
81 elem_types
[LP_JIT_TEXTURE_HEIGHT
] =
82 elem_types
[LP_JIT_TEXTURE_DEPTH
] =
83 elem_types
[LP_JIT_TEXTURE_FIRST_LEVEL
] =
84 elem_types
[LP_JIT_TEXTURE_LAST_LEVEL
] = LLVMInt32TypeInContext(lc
);
85 elem_types
[LP_JIT_TEXTURE_BASE
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
86 elem_types
[LP_JIT_TEXTURE_ROW_STRIDE
] =
87 elem_types
[LP_JIT_TEXTURE_IMG_STRIDE
] =
88 elem_types
[LP_JIT_TEXTURE_MIP_OFFSETS
] =
89 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TEXTURE_LEVELS
);
91 texture_type
= LLVMStructTypeInContext(lc
, elem_types
,
92 Elements(elem_types
), 0);
93 #if HAVE_LLVM < 0x0300
94 LLVMAddTypeName(gallivm
->module
, "texture", texture_type
);
96 LLVMInvalidateStructLayout(gallivm
->target
, texture_type
);
99 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, width
,
100 gallivm
->target
, texture_type
,
101 LP_JIT_TEXTURE_WIDTH
);
102 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, height
,
103 gallivm
->target
, texture_type
,
104 LP_JIT_TEXTURE_HEIGHT
);
105 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, depth
,
106 gallivm
->target
, texture_type
,
107 LP_JIT_TEXTURE_DEPTH
);
108 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, first_level
,
109 gallivm
->target
, texture_type
,
110 LP_JIT_TEXTURE_FIRST_LEVEL
);
111 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, last_level
,
112 gallivm
->target
, texture_type
,
113 LP_JIT_TEXTURE_LAST_LEVEL
);
114 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, base
,
115 gallivm
->target
, texture_type
,
116 LP_JIT_TEXTURE_BASE
);
117 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, row_stride
,
118 gallivm
->target
, texture_type
,
119 LP_JIT_TEXTURE_ROW_STRIDE
);
120 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, img_stride
,
121 gallivm
->target
, texture_type
,
122 LP_JIT_TEXTURE_IMG_STRIDE
);
123 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, mip_offsets
,
124 gallivm
->target
, texture_type
,
125 LP_JIT_TEXTURE_MIP_OFFSETS
);
126 LP_CHECK_STRUCT_SIZE(struct lp_jit_texture
,
127 gallivm
->target
, texture_type
);
130 /* struct lp_jit_sampler */
132 LLVMTypeRef elem_types
[LP_JIT_SAMPLER_NUM_FIELDS
];
133 elem_types
[LP_JIT_SAMPLER_MIN_LOD
] =
134 elem_types
[LP_JIT_SAMPLER_MAX_LOD
] =
135 elem_types
[LP_JIT_SAMPLER_LOD_BIAS
] = LLVMFloatTypeInContext(lc
);
136 elem_types
[LP_JIT_SAMPLER_BORDER_COLOR
] =
137 LLVMArrayType(LLVMFloatTypeInContext(lc
), 4);
139 sampler_type
= LLVMStructTypeInContext(lc
, elem_types
,
140 Elements(elem_types
), 0);
141 #if HAVE_LLVM < 0x0300
142 LLVMAddTypeName(gallivm
->module
, "sampler", sampler_type
);
144 LLVMInvalidateStructLayout(gallivm
->target
, sampler_type
);
147 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, min_lod
,
148 gallivm
->target
, sampler_type
,
149 LP_JIT_SAMPLER_MIN_LOD
);
150 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, max_lod
,
151 gallivm
->target
, sampler_type
,
152 LP_JIT_SAMPLER_MAX_LOD
);
153 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, lod_bias
,
154 gallivm
->target
, sampler_type
,
155 LP_JIT_SAMPLER_LOD_BIAS
);
156 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, border_color
,
157 gallivm
->target
, sampler_type
,
158 LP_JIT_SAMPLER_BORDER_COLOR
);
159 LP_CHECK_STRUCT_SIZE(struct lp_jit_sampler
,
160 gallivm
->target
, sampler_type
);
163 /* struct lp_jit_context */
165 LLVMTypeRef elem_types
[LP_JIT_CTX_COUNT
];
166 LLVMTypeRef context_type
;
168 elem_types
[LP_JIT_CTX_CONSTANTS
] =
169 LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc
), 0), LP_MAX_TGSI_CONST_BUFFERS
);
170 elem_types
[LP_JIT_CTX_NUM_CONSTANTS
] =
171 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TGSI_CONST_BUFFERS
);
172 elem_types
[LP_JIT_CTX_ALPHA_REF
] = LLVMFloatTypeInContext(lc
);
173 elem_types
[LP_JIT_CTX_STENCIL_REF_FRONT
] =
174 elem_types
[LP_JIT_CTX_STENCIL_REF_BACK
] = LLVMInt32TypeInContext(lc
);
175 elem_types
[LP_JIT_CTX_U8_BLEND_COLOR
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
176 elem_types
[LP_JIT_CTX_F_BLEND_COLOR
] = LLVMPointerType(LLVMFloatTypeInContext(lc
), 0);
177 elem_types
[LP_JIT_CTX_VIEWPORTS
] = LLVMPointerType(viewport_type
, 0);
178 elem_types
[LP_JIT_CTX_TEXTURES
] = LLVMArrayType(texture_type
,
179 PIPE_MAX_SHADER_SAMPLER_VIEWS
);
180 elem_types
[LP_JIT_CTX_SAMPLERS
] = LLVMArrayType(sampler_type
,
183 context_type
= LLVMStructTypeInContext(lc
, elem_types
,
184 Elements(elem_types
), 0);
186 #if HAVE_LLVM < 0x0300
187 LLVMInvalidateStructLayout(gallivm
->target
, context_type
);
189 LLVMAddTypeName(gallivm
->module
, "context", context_type
);
192 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
193 gallivm
->target
, context_type
,
194 LP_JIT_CTX_CONSTANTS
);
195 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, num_constants
,
196 gallivm
->target
, context_type
,
197 LP_JIT_CTX_NUM_CONSTANTS
);
198 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
199 gallivm
->target
, context_type
,
200 LP_JIT_CTX_ALPHA_REF
);
201 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_front
,
202 gallivm
->target
, context_type
,
203 LP_JIT_CTX_STENCIL_REF_FRONT
);
204 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_back
,
205 gallivm
->target
, context_type
,
206 LP_JIT_CTX_STENCIL_REF_BACK
);
207 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, u8_blend_color
,
208 gallivm
->target
, context_type
,
209 LP_JIT_CTX_U8_BLEND_COLOR
);
210 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, f_blend_color
,
211 gallivm
->target
, context_type
,
212 LP_JIT_CTX_F_BLEND_COLOR
);
213 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, viewports
,
214 gallivm
->target
, context_type
,
215 LP_JIT_CTX_VIEWPORTS
);
216 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, textures
,
217 gallivm
->target
, context_type
,
218 LP_JIT_CTX_TEXTURES
);
219 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, samplers
,
220 gallivm
->target
, context_type
,
221 LP_JIT_CTX_SAMPLERS
);
222 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
223 gallivm
->target
, context_type
);
225 lp
->jit_context_ptr_type
= LLVMPointerType(context_type
, 0);
228 /* struct lp_jit_thread_data */
230 LLVMTypeRef elem_types
[LP_JIT_THREAD_DATA_COUNT
];
231 LLVMTypeRef thread_data_type
;
233 elem_types
[LP_JIT_THREAD_DATA_COUNTER
] = LLVMInt64TypeInContext(lc
);
234 elem_types
[LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX
] =
235 LLVMInt32TypeInContext(lc
);
237 thread_data_type
= LLVMStructTypeInContext(lc
, elem_types
,
238 Elements(elem_types
), 0);
240 #if HAVE_LLVM < 0x0300
241 LLVMInvalidateStructLayout(gallivm
->target
, thread_data_type
);
243 LLVMAddTypeName(gallivm
->module
, "thread_data", thread_data_type
);
246 lp
->jit_thread_data_ptr_type
= LLVMPointerType(thread_data_type
, 0);
249 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
250 LLVMDumpModule(gallivm
->module
);
256 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
263 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
270 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
)
272 if (!lp
->jit_context_ptr_type
)
273 lp_jit_create_types(lp
);