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_ALPHA_REF
] = LLVMFloatTypeInContext(lc
);
171 elem_types
[LP_JIT_CTX_STENCIL_REF_FRONT
] =
172 elem_types
[LP_JIT_CTX_STENCIL_REF_BACK
] = LLVMInt32TypeInContext(lc
);
173 elem_types
[LP_JIT_CTX_U8_BLEND_COLOR
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
174 elem_types
[LP_JIT_CTX_F_BLEND_COLOR
] = LLVMPointerType(LLVMFloatTypeInContext(lc
), 0);
175 elem_types
[LP_JIT_CTX_VIEWPORTS
] = LLVMPointerType(viewport_type
, 0);
176 elem_types
[LP_JIT_CTX_TEXTURES
] = LLVMArrayType(texture_type
,
177 PIPE_MAX_SHADER_SAMPLER_VIEWS
);
178 elem_types
[LP_JIT_CTX_SAMPLERS
] = LLVMArrayType(sampler_type
,
181 context_type
= LLVMStructTypeInContext(lc
, elem_types
,
182 Elements(elem_types
), 0);
184 #if HAVE_LLVM < 0x0300
185 LLVMInvalidateStructLayout(gallivm
->target
, context_type
);
187 LLVMAddTypeName(gallivm
->module
, "context", context_type
);
190 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
191 gallivm
->target
, context_type
,
192 LP_JIT_CTX_CONSTANTS
);
193 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
194 gallivm
->target
, context_type
,
195 LP_JIT_CTX_ALPHA_REF
);
196 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_front
,
197 gallivm
->target
, context_type
,
198 LP_JIT_CTX_STENCIL_REF_FRONT
);
199 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_back
,
200 gallivm
->target
, context_type
,
201 LP_JIT_CTX_STENCIL_REF_BACK
);
202 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, u8_blend_color
,
203 gallivm
->target
, context_type
,
204 LP_JIT_CTX_U8_BLEND_COLOR
);
205 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, f_blend_color
,
206 gallivm
->target
, context_type
,
207 LP_JIT_CTX_F_BLEND_COLOR
);
208 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, viewports
,
209 gallivm
->target
, context_type
,
210 LP_JIT_CTX_VIEWPORTS
);
211 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, textures
,
212 gallivm
->target
, context_type
,
213 LP_JIT_CTX_TEXTURES
);
214 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, samplers
,
215 gallivm
->target
, context_type
,
216 LP_JIT_CTX_SAMPLERS
);
217 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
218 gallivm
->target
, context_type
);
220 lp
->jit_context_ptr_type
= LLVMPointerType(context_type
, 0);
223 /* struct lp_jit_thread_data */
225 LLVMTypeRef elem_types
[LP_JIT_THREAD_DATA_COUNT
];
226 LLVMTypeRef thread_data_type
;
228 elem_types
[LP_JIT_THREAD_DATA_COUNTER
] = LLVMInt64TypeInContext(lc
);
229 elem_types
[LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX
] =
230 LLVMInt32TypeInContext(lc
);
232 thread_data_type
= LLVMStructTypeInContext(lc
, elem_types
,
233 Elements(elem_types
), 0);
235 #if HAVE_LLVM < 0x0300
236 LLVMInvalidateStructLayout(gallivm
->target
, thread_data_type
);
238 LLVMAddTypeName(gallivm
->module
, "thread_data", thread_data_type
);
241 lp
->jit_thread_data_ptr_type
= LLVMPointerType(thread_data_type
, 0);
244 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
245 LLVMDumpModule(gallivm
->module
);
251 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
258 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
265 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
)
267 if (!lp
->jit_context_ptr_type
)
268 lp_jit_create_types(lp
);