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 LP_CHECK_MEMBER_OFFSET(struct lp_jit_viewport
, min_depth
,
61 gallivm
->target
, viewport_type
,
62 LP_JIT_VIEWPORT_MIN_DEPTH
);
63 LP_CHECK_MEMBER_OFFSET(struct lp_jit_viewport
, max_depth
,
64 gallivm
->target
, viewport_type
,
65 LP_JIT_VIEWPORT_MAX_DEPTH
);
66 LP_CHECK_STRUCT_SIZE(struct lp_jit_viewport
,
67 gallivm
->target
, viewport_type
);
70 /* struct lp_jit_texture */
72 LLVMTypeRef elem_types
[LP_JIT_TEXTURE_NUM_FIELDS
];
74 elem_types
[LP_JIT_TEXTURE_WIDTH
] =
75 elem_types
[LP_JIT_TEXTURE_HEIGHT
] =
76 elem_types
[LP_JIT_TEXTURE_DEPTH
] =
77 elem_types
[LP_JIT_TEXTURE_FIRST_LEVEL
] =
78 elem_types
[LP_JIT_TEXTURE_LAST_LEVEL
] = LLVMInt32TypeInContext(lc
);
79 elem_types
[LP_JIT_TEXTURE_BASE
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
80 elem_types
[LP_JIT_TEXTURE_ROW_STRIDE
] =
81 elem_types
[LP_JIT_TEXTURE_IMG_STRIDE
] =
82 elem_types
[LP_JIT_TEXTURE_MIP_OFFSETS
] =
83 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TEXTURE_LEVELS
);
85 texture_type
= LLVMStructTypeInContext(lc
, elem_types
,
86 Elements(elem_types
), 0);
88 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, width
,
89 gallivm
->target
, texture_type
,
90 LP_JIT_TEXTURE_WIDTH
);
91 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, height
,
92 gallivm
->target
, texture_type
,
93 LP_JIT_TEXTURE_HEIGHT
);
94 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, depth
,
95 gallivm
->target
, texture_type
,
96 LP_JIT_TEXTURE_DEPTH
);
97 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, first_level
,
98 gallivm
->target
, texture_type
,
99 LP_JIT_TEXTURE_FIRST_LEVEL
);
100 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, last_level
,
101 gallivm
->target
, texture_type
,
102 LP_JIT_TEXTURE_LAST_LEVEL
);
103 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, base
,
104 gallivm
->target
, texture_type
,
105 LP_JIT_TEXTURE_BASE
);
106 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, row_stride
,
107 gallivm
->target
, texture_type
,
108 LP_JIT_TEXTURE_ROW_STRIDE
);
109 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, img_stride
,
110 gallivm
->target
, texture_type
,
111 LP_JIT_TEXTURE_IMG_STRIDE
);
112 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, mip_offsets
,
113 gallivm
->target
, texture_type
,
114 LP_JIT_TEXTURE_MIP_OFFSETS
);
115 LP_CHECK_STRUCT_SIZE(struct lp_jit_texture
,
116 gallivm
->target
, texture_type
);
119 /* struct lp_jit_sampler */
121 LLVMTypeRef elem_types
[LP_JIT_SAMPLER_NUM_FIELDS
];
122 elem_types
[LP_JIT_SAMPLER_MIN_LOD
] =
123 elem_types
[LP_JIT_SAMPLER_MAX_LOD
] =
124 elem_types
[LP_JIT_SAMPLER_LOD_BIAS
] = LLVMFloatTypeInContext(lc
);
125 elem_types
[LP_JIT_SAMPLER_BORDER_COLOR
] =
126 LLVMArrayType(LLVMFloatTypeInContext(lc
), 4);
128 sampler_type
= LLVMStructTypeInContext(lc
, elem_types
,
129 Elements(elem_types
), 0);
131 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, min_lod
,
132 gallivm
->target
, sampler_type
,
133 LP_JIT_SAMPLER_MIN_LOD
);
134 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, max_lod
,
135 gallivm
->target
, sampler_type
,
136 LP_JIT_SAMPLER_MAX_LOD
);
137 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, lod_bias
,
138 gallivm
->target
, sampler_type
,
139 LP_JIT_SAMPLER_LOD_BIAS
);
140 LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler
, border_color
,
141 gallivm
->target
, sampler_type
,
142 LP_JIT_SAMPLER_BORDER_COLOR
);
143 LP_CHECK_STRUCT_SIZE(struct lp_jit_sampler
,
144 gallivm
->target
, sampler_type
);
147 /* struct lp_jit_context */
149 LLVMTypeRef elem_types
[LP_JIT_CTX_COUNT
];
150 LLVMTypeRef context_type
;
152 elem_types
[LP_JIT_CTX_CONSTANTS
] =
153 LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc
), 0), LP_MAX_TGSI_CONST_BUFFERS
);
154 elem_types
[LP_JIT_CTX_NUM_CONSTANTS
] =
155 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TGSI_CONST_BUFFERS
);
156 elem_types
[LP_JIT_CTX_ALPHA_REF
] = LLVMFloatTypeInContext(lc
);
157 elem_types
[LP_JIT_CTX_STENCIL_REF_FRONT
] =
158 elem_types
[LP_JIT_CTX_STENCIL_REF_BACK
] = LLVMInt32TypeInContext(lc
);
159 elem_types
[LP_JIT_CTX_U8_BLEND_COLOR
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
160 elem_types
[LP_JIT_CTX_F_BLEND_COLOR
] = LLVMPointerType(LLVMFloatTypeInContext(lc
), 0);
161 elem_types
[LP_JIT_CTX_VIEWPORTS
] = LLVMPointerType(viewport_type
, 0);
162 elem_types
[LP_JIT_CTX_TEXTURES
] = LLVMArrayType(texture_type
,
163 PIPE_MAX_SHADER_SAMPLER_VIEWS
);
164 elem_types
[LP_JIT_CTX_SAMPLERS
] = LLVMArrayType(sampler_type
,
167 context_type
= LLVMStructTypeInContext(lc
, elem_types
,
168 Elements(elem_types
), 0);
170 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
171 gallivm
->target
, context_type
,
172 LP_JIT_CTX_CONSTANTS
);
173 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, num_constants
,
174 gallivm
->target
, context_type
,
175 LP_JIT_CTX_NUM_CONSTANTS
);
176 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
177 gallivm
->target
, context_type
,
178 LP_JIT_CTX_ALPHA_REF
);
179 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_front
,
180 gallivm
->target
, context_type
,
181 LP_JIT_CTX_STENCIL_REF_FRONT
);
182 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_back
,
183 gallivm
->target
, context_type
,
184 LP_JIT_CTX_STENCIL_REF_BACK
);
185 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, u8_blend_color
,
186 gallivm
->target
, context_type
,
187 LP_JIT_CTX_U8_BLEND_COLOR
);
188 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, f_blend_color
,
189 gallivm
->target
, context_type
,
190 LP_JIT_CTX_F_BLEND_COLOR
);
191 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, viewports
,
192 gallivm
->target
, context_type
,
193 LP_JIT_CTX_VIEWPORTS
);
194 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, textures
,
195 gallivm
->target
, context_type
,
196 LP_JIT_CTX_TEXTURES
);
197 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, samplers
,
198 gallivm
->target
, context_type
,
199 LP_JIT_CTX_SAMPLERS
);
200 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
201 gallivm
->target
, context_type
);
203 lp
->jit_context_ptr_type
= LLVMPointerType(context_type
, 0);
206 /* struct lp_jit_thread_data */
208 LLVMTypeRef elem_types
[LP_JIT_THREAD_DATA_COUNT
];
209 LLVMTypeRef thread_data_type
;
211 elem_types
[LP_JIT_THREAD_DATA_COUNTER
] = LLVMInt64TypeInContext(lc
);
212 elem_types
[LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX
] =
213 LLVMInt32TypeInContext(lc
);
215 thread_data_type
= LLVMStructTypeInContext(lc
, elem_types
,
216 Elements(elem_types
), 0);
218 lp
->jit_thread_data_ptr_type
= LLVMPointerType(thread_data_type
, 0);
221 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
222 LLVMDumpModule(gallivm
->module
);
228 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
235 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
237 return lp_build_init();
242 lp_jit_init_types(struct lp_fragment_shader_variant
*lp
)
244 if (!lp
->jit_context_ptr_type
)
245 lp_jit_create_types(lp
);