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 texture_type
, sampler_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_BASE
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
60 elem_types
[LP_JIT_TEXTURE_ROW_STRIDE
] =
61 elem_types
[LP_JIT_TEXTURE_IMG_STRIDE
] =
62 elem_types
[LP_JIT_TEXTURE_MIP_OFFSETS
] =
63 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TEXTURE_LEVELS
);
65 texture_type
= LLVMStructTypeInContext(lc
, elem_types
,
66 Elements(elem_types
), 0);
67 #if HAVE_LLVM < 0x0300
68 LLVMAddTypeName(gallivm
->module
, "texture", texture_type
);
70 LLVMInvalidateStructLayout(gallivm
->target
, texture_type
);
73 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, width
,
74 gallivm
->target
, texture_type
,
75 LP_JIT_TEXTURE_WIDTH
);
76 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, height
,
77 gallivm
->target
, texture_type
,
78 LP_JIT_TEXTURE_HEIGHT
);
79 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, depth
,
80 gallivm
->target
, texture_type
,
81 LP_JIT_TEXTURE_DEPTH
);
82 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, first_level
,
83 gallivm
->target
, texture_type
,
84 LP_JIT_TEXTURE_FIRST_LEVEL
);
85 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, last_level
,
86 gallivm
->target
, texture_type
,
87 LP_JIT_TEXTURE_LAST_LEVEL
);
88 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, base
,
89 gallivm
->target
, texture_type
,
91 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, row_stride
,
92 gallivm
->target
, texture_type
,
93 LP_JIT_TEXTURE_ROW_STRIDE
);
94 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, img_stride
,
95 gallivm
->target
, texture_type
,
96 LP_JIT_TEXTURE_IMG_STRIDE
);
97 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, mip_offsets
,
98 gallivm
->target
, texture_type
,
99 LP_JIT_TEXTURE_MIP_OFFSETS
);
100 LP_CHECK_STRUCT_SIZE(struct lp_jit_texture
,
101 gallivm
->target
, texture_type
);
105 /* struct lp_jit_sampler */
106 LLVMTypeRef elem_types
[LP_JIT_SAMPLER_NUM_FIELDS
];
107 elem_types
[LP_JIT_SAMPLER_MIN_LOD
] =
108 elem_types
[LP_JIT_SAMPLER_MAX_LOD
] =
109 elem_types
[LP_JIT_SAMPLER_LOD_BIAS
] = LLVMFloatTypeInContext(lc
);
110 elem_types
[LP_JIT_SAMPLER_BORDER_COLOR
] =
111 LLVMArrayType(LLVMFloatTypeInContext(lc
), 4);
113 sampler_type
= LLVMStructTypeInContext(lc
, elem_types
,
114 Elements(elem_types
), 0);
115 #if HAVE_LLVM < 0x0300
116 LLVMAddTypeName(gallivm
->module
, "texture", texture_type
);
118 LLVMInvalidateStructLayout(gallivm
->target
, texture_type
);
121 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, min_lod
,
122 gallivm
->target
, texture_type
,
123 LP_JIT_SAMPLER_MIN_LOD
);
124 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, max_lod
,
125 gallivm
->target
, texture_type
,
126 LP_JIT_SAMPLER_MAX_LOD
);
127 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, lod_bias
,
128 gallivm
->target
, texture_type
,
129 LP_JIT_SAMPLER_LOD_BIAS
);
130 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, border_color
,
131 gallivm
->target
, texture_type
,
132 LP_JIT_SAMPLER_BORDER_COLOR
);
133 LP_CHECK_STRUCT_SIZE(struct lp_jit_sampler
,
134 gallivm
->target
, sampler_type
);
137 /* struct lp_jit_context */
139 LLVMTypeRef elem_types
[LP_JIT_CTX_COUNT
];
140 LLVMTypeRef context_type
;
142 elem_types
[LP_JIT_CTX_CONSTANTS
] =
143 LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc
), 0), LP_MAX_TGSI_CONST_BUFFERS
);
144 elem_types
[LP_JIT_CTX_ALPHA_REF
] = LLVMFloatTypeInContext(lc
);
145 elem_types
[LP_JIT_CTX_STENCIL_REF_FRONT
] =
146 elem_types
[LP_JIT_CTX_STENCIL_REF_BACK
] = LLVMInt32TypeInContext(lc
);
147 elem_types
[LP_JIT_CTX_U8_BLEND_COLOR
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
148 elem_types
[LP_JIT_CTX_F_BLEND_COLOR
] = LLVMPointerType(LLVMFloatTypeInContext(lc
), 0);
149 elem_types
[LP_JIT_CTX_TEXTURES
] = LLVMArrayType(texture_type
,
150 PIPE_MAX_SHADER_SAMPLER_VIEWS
);
151 elem_types
[LP_JIT_CTX_SAMPLERS
] = LLVMArrayType(sampler_type
,
154 context_type
= LLVMStructTypeInContext(lc
, elem_types
,
155 Elements(elem_types
), 0);
157 #if HAVE_LLVM < 0x0300
158 LLVMInvalidateStructLayout(gallivm
->target
, context_type
);
160 LLVMAddTypeName(gallivm
->module
, "context", context_type
);
163 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
164 gallivm
->target
, context_type
,
165 LP_JIT_CTX_CONSTANTS
);
166 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
167 gallivm
->target
, context_type
,
168 LP_JIT_CTX_ALPHA_REF
);
169 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_front
,
170 gallivm
->target
, context_type
,
171 LP_JIT_CTX_STENCIL_REF_FRONT
);
172 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_back
,
173 gallivm
->target
, context_type
,
174 LP_JIT_CTX_STENCIL_REF_BACK
);
175 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, u8_blend_color
,
176 gallivm
->target
, context_type
,
177 LP_JIT_CTX_U8_BLEND_COLOR
);
178 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, f_blend_color
,
179 gallivm
->target
, context_type
,
180 LP_JIT_CTX_F_BLEND_COLOR
);
181 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, textures
,
182 gallivm
->target
, context_type
,
183 LP_JIT_CTX_TEXTURES
);
184 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, samplers
,
185 gallivm
->target
, context_type
,
186 LP_JIT_CTX_SAMPLERS
);
187 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
188 gallivm
->target
, context_type
);
190 lp
->jit_context_ptr_type
= LLVMPointerType(context_type
, 0);
193 /* struct lp_jit_thread_data */
195 LLVMTypeRef elem_types
[LP_JIT_THREAD_DATA_COUNT
];
196 LLVMTypeRef thread_data_type
;
198 elem_types
[LP_JIT_THREAD_DATA_COUNTER
] = LLVMInt32TypeInContext(lc
);
200 thread_data_type
= LLVMStructTypeInContext(lc
, elem_types
,
201 Elements(elem_types
), 0);
203 #if HAVE_LLVM < 0x0300
204 LLVMInvalidateStructLayout(gallivm
->target
, thread_data_type
);
206 LLVMAddTypeName(gallivm
->module
, "thread_data", thread_data_type
);
209 lp
->jit_thread_data_ptr_type
= LLVMPointerType(thread_data_type
, 0);
212 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
213 LLVMDumpModule(gallivm
->module
);
219 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
226 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
233 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
)
235 if (!lp
->jit_context_ptr_type
)
236 lp_jit_create_types(lp
);