1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/**
29bf215546Sopenharmony_ci * @file
30bf215546Sopenharmony_ci * C - JIT interfaces
31bf215546Sopenharmony_ci *
32bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com>
33bf215546Sopenharmony_ci */
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include <llvm/Config/llvm-config.h>
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "util/u_memory.h"
38bf215546Sopenharmony_ci#include "gallivm/lp_bld_init.h"
39bf215546Sopenharmony_ci#include "gallivm/lp_bld_debug.h"
40bf215546Sopenharmony_ci#include "gallivm/lp_bld_format.h"
41bf215546Sopenharmony_ci#include "lp_context.h"
42bf215546Sopenharmony_ci#include "lp_screen.h"
43bf215546Sopenharmony_ci#include "lp_jit.h"
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistatic LLVMTypeRef
46bf215546Sopenharmony_cicreate_jit_texture_type(struct gallivm_state *gallivm)
47bf215546Sopenharmony_ci{
48bf215546Sopenharmony_ci   LLVMContextRef lc = gallivm->context;
49bf215546Sopenharmony_ci   LLVMTypeRef texture_type;
50bf215546Sopenharmony_ci   LLVMTypeRef elem_types[LP_JIT_TEXTURE_NUM_FIELDS];
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci   /* struct lp_jit_texture */
53bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_WIDTH]  =
54bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_HEIGHT] =
55bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_DEPTH] =
56bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_NUM_SAMPLES] =
57bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_SAMPLE_STRIDE] =
58bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_FIRST_LEVEL] =
59bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32TypeInContext(lc);
60bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_BASE] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
61bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_ROW_STRIDE] =
62bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_IMG_STRIDE] =
63bf215546Sopenharmony_ci   elem_types[LP_JIT_TEXTURE_MIP_OFFSETS] =
64bf215546Sopenharmony_ci      LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TEXTURE_LEVELS);
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci   texture_type = LLVMStructTypeInContext(lc, elem_types,
67bf215546Sopenharmony_ci                                          ARRAY_SIZE(elem_types), 0);
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, width,
70bf215546Sopenharmony_ci                          gallivm->target, texture_type,
71bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_WIDTH);
72bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, height,
73bf215546Sopenharmony_ci                          gallivm->target, texture_type,
74bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_HEIGHT);
75bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, depth,
76bf215546Sopenharmony_ci                          gallivm->target, texture_type,
77bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_DEPTH);
78bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, base,
79bf215546Sopenharmony_ci                          gallivm->target, texture_type,
80bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_BASE);
81bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, row_stride,
82bf215546Sopenharmony_ci                          gallivm->target, texture_type,
83bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_ROW_STRIDE);
84bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, img_stride,
85bf215546Sopenharmony_ci                          gallivm->target, texture_type,
86bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_IMG_STRIDE);
87bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, first_level,
88bf215546Sopenharmony_ci                          gallivm->target, texture_type,
89bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_FIRST_LEVEL);
90bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, last_level,
91bf215546Sopenharmony_ci                          gallivm->target, texture_type,
92bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_LAST_LEVEL);
93bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, mip_offsets,
94bf215546Sopenharmony_ci                          gallivm->target, texture_type,
95bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_MIP_OFFSETS);
96bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, num_samples,
97bf215546Sopenharmony_ci                          gallivm->target, texture_type,
98bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_NUM_SAMPLES);
99bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, sample_stride,
100bf215546Sopenharmony_ci                          gallivm->target, texture_type,
101bf215546Sopenharmony_ci                          LP_JIT_TEXTURE_SAMPLE_STRIDE);
102bf215546Sopenharmony_ci   LP_CHECK_STRUCT_SIZE(struct lp_jit_texture,
103bf215546Sopenharmony_ci                        gallivm->target, texture_type);
104bf215546Sopenharmony_ci   return texture_type;
105bf215546Sopenharmony_ci}
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_cistatic LLVMTypeRef
108bf215546Sopenharmony_cicreate_jit_sampler_type(struct gallivm_state *gallivm)
109bf215546Sopenharmony_ci{
110bf215546Sopenharmony_ci   LLVMContextRef lc = gallivm->context;
111bf215546Sopenharmony_ci   LLVMTypeRef sampler_type;
112bf215546Sopenharmony_ci   LLVMTypeRef elem_types[LP_JIT_SAMPLER_NUM_FIELDS];
113bf215546Sopenharmony_ci   elem_types[LP_JIT_SAMPLER_MIN_LOD] =
114bf215546Sopenharmony_ci   elem_types[LP_JIT_SAMPLER_MAX_LOD] =
115bf215546Sopenharmony_ci   elem_types[LP_JIT_SAMPLER_LOD_BIAS] =
116bf215546Sopenharmony_ci   elem_types[LP_JIT_SAMPLER_MAX_ANISO] = LLVMFloatTypeInContext(lc);
117bf215546Sopenharmony_ci   elem_types[LP_JIT_SAMPLER_BORDER_COLOR] =
118bf215546Sopenharmony_ci      LLVMArrayType(LLVMFloatTypeInContext(lc), 4);
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_ci   sampler_type = LLVMStructTypeInContext(lc, elem_types,
121bf215546Sopenharmony_ci                                          ARRAY_SIZE(elem_types), 0);
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, min_lod,
124bf215546Sopenharmony_ci                          gallivm->target, sampler_type,
125bf215546Sopenharmony_ci                          LP_JIT_SAMPLER_MIN_LOD);
126bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, max_lod,
127bf215546Sopenharmony_ci                          gallivm->target, sampler_type,
128bf215546Sopenharmony_ci                          LP_JIT_SAMPLER_MAX_LOD);
129bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, lod_bias,
130bf215546Sopenharmony_ci                          gallivm->target, sampler_type,
131bf215546Sopenharmony_ci                          LP_JIT_SAMPLER_LOD_BIAS);
132bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, border_color,
133bf215546Sopenharmony_ci                          gallivm->target, sampler_type,
134bf215546Sopenharmony_ci                          LP_JIT_SAMPLER_BORDER_COLOR);
135bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, max_aniso,
136bf215546Sopenharmony_ci                          gallivm->target, sampler_type,
137bf215546Sopenharmony_ci                          LP_JIT_SAMPLER_MAX_ANISO);
138bf215546Sopenharmony_ci   LP_CHECK_STRUCT_SIZE(struct lp_jit_sampler,
139bf215546Sopenharmony_ci                        gallivm->target, sampler_type);
140bf215546Sopenharmony_ci   return sampler_type;
141bf215546Sopenharmony_ci}
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_cistatic LLVMTypeRef
144bf215546Sopenharmony_cicreate_jit_image_type(struct gallivm_state *gallivm)
145bf215546Sopenharmony_ci{
146bf215546Sopenharmony_ci   LLVMContextRef lc = gallivm->context;
147bf215546Sopenharmony_ci   LLVMTypeRef image_type;
148bf215546Sopenharmony_ci   LLVMTypeRef elem_types[LP_JIT_IMAGE_NUM_FIELDS];
149bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_WIDTH] =
150bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_HEIGHT] =
151bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_DEPTH] = LLVMInt32TypeInContext(lc);
152bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_BASE] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
153bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_ROW_STRIDE] =
154bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_IMG_STRIDE] =
155bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_NUM_SAMPLES] =
156bf215546Sopenharmony_ci   elem_types[LP_JIT_IMAGE_SAMPLE_STRIDE] = LLVMInt32TypeInContext(lc);
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci   image_type = LLVMStructTypeInContext(lc, elem_types,
159bf215546Sopenharmony_ci                                        ARRAY_SIZE(elem_types), 0);
160bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, width,
161bf215546Sopenharmony_ci                          gallivm->target, image_type,
162bf215546Sopenharmony_ci                          LP_JIT_IMAGE_WIDTH);
163bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, height,
164bf215546Sopenharmony_ci                          gallivm->target, image_type,
165bf215546Sopenharmony_ci                          LP_JIT_IMAGE_HEIGHT);
166bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, depth,
167bf215546Sopenharmony_ci                          gallivm->target, image_type,
168bf215546Sopenharmony_ci                          LP_JIT_IMAGE_DEPTH);
169bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, base,
170bf215546Sopenharmony_ci                          gallivm->target, image_type,
171bf215546Sopenharmony_ci                          LP_JIT_IMAGE_BASE);
172bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, row_stride,
173bf215546Sopenharmony_ci                          gallivm->target, image_type,
174bf215546Sopenharmony_ci                          LP_JIT_IMAGE_ROW_STRIDE);
175bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, img_stride,
176bf215546Sopenharmony_ci                          gallivm->target, image_type,
177bf215546Sopenharmony_ci                          LP_JIT_IMAGE_IMG_STRIDE);
178bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, num_samples,
179bf215546Sopenharmony_ci                          gallivm->target, image_type,
180bf215546Sopenharmony_ci                          LP_JIT_IMAGE_NUM_SAMPLES);
181bf215546Sopenharmony_ci   LP_CHECK_MEMBER_OFFSET(struct lp_jit_image, sample_stride,
182bf215546Sopenharmony_ci                          gallivm->target, image_type,
183bf215546Sopenharmony_ci                          LP_JIT_IMAGE_SAMPLE_STRIDE);
184bf215546Sopenharmony_ci   return image_type;
185bf215546Sopenharmony_ci}
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_cistatic void
188bf215546Sopenharmony_cilp_jit_create_types(struct lp_fragment_shader_variant *lp)
189bf215546Sopenharmony_ci{
190bf215546Sopenharmony_ci   struct gallivm_state *gallivm = lp->gallivm;
191bf215546Sopenharmony_ci   LLVMContextRef lc = gallivm->context;
192bf215546Sopenharmony_ci   LLVMTypeRef viewport_type, texture_type, sampler_type, image_type;
193bf215546Sopenharmony_ci   LLVMTypeRef linear_elem_type;
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_ci   /* struct lp_jit_viewport */
196bf215546Sopenharmony_ci   {
197bf215546Sopenharmony_ci      LLVMTypeRef elem_types[LP_JIT_VIEWPORT_NUM_FIELDS];
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_ci      elem_types[LP_JIT_VIEWPORT_MIN_DEPTH] =
200bf215546Sopenharmony_ci      elem_types[LP_JIT_VIEWPORT_MAX_DEPTH] = LLVMFloatTypeInContext(lc);
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_ci      viewport_type = LLVMStructTypeInContext(lc, elem_types,
203bf215546Sopenharmony_ci                                              ARRAY_SIZE(elem_types), 0);
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_viewport, min_depth,
206bf215546Sopenharmony_ci                             gallivm->target, viewport_type,
207bf215546Sopenharmony_ci                             LP_JIT_VIEWPORT_MIN_DEPTH);
208bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_viewport, max_depth,
209bf215546Sopenharmony_ci                             gallivm->target, viewport_type,
210bf215546Sopenharmony_ci                             LP_JIT_VIEWPORT_MAX_DEPTH);
211bf215546Sopenharmony_ci      LP_CHECK_STRUCT_SIZE(struct lp_jit_viewport,
212bf215546Sopenharmony_ci                           gallivm->target, viewport_type);
213bf215546Sopenharmony_ci   }
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ci   texture_type = create_jit_texture_type(gallivm);
216bf215546Sopenharmony_ci   sampler_type = create_jit_sampler_type(gallivm);
217bf215546Sopenharmony_ci   image_type = create_jit_image_type(gallivm);
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci   /* struct lp_jit_context */
220bf215546Sopenharmony_ci   {
221bf215546Sopenharmony_ci      LLVMTypeRef elem_types[LP_JIT_CTX_COUNT];
222bf215546Sopenharmony_ci      LLVMTypeRef context_type;
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_CONSTANTS] =
225bf215546Sopenharmony_ci         LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc), 0), LP_MAX_TGSI_CONST_BUFFERS);
226bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_NUM_CONSTANTS] =
227bf215546Sopenharmony_ci            LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_CONST_BUFFERS);
228bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type,
229bf215546Sopenharmony_ci                                                      PIPE_MAX_SHADER_SAMPLER_VIEWS);
230bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_SAMPLERS] = LLVMArrayType(sampler_type,
231bf215546Sopenharmony_ci                                                      PIPE_MAX_SAMPLERS);
232bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_IMAGES] = LLVMArrayType(image_type,
233bf215546Sopenharmony_ci                                                    PIPE_MAX_SHADER_IMAGES);
234bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_ALPHA_REF] = LLVMFloatTypeInContext(lc);
235bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_SAMPLE_MASK] =
236bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_STENCIL_REF_FRONT] =
237bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_STENCIL_REF_BACK] = LLVMInt32TypeInContext(lc);
238bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_U8_BLEND_COLOR] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
239bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_F_BLEND_COLOR] = LLVMPointerType(LLVMFloatTypeInContext(lc), 0);
240bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_VIEWPORTS] = LLVMPointerType(viewport_type, 0);
241bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(LLVMFloatTypeInContext(lc), 0);
242bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_SSBOS] =
243bf215546Sopenharmony_ci         LLVMArrayType(LLVMPointerType(LLVMInt32TypeInContext(lc), 0), LP_MAX_TGSI_SHADER_BUFFERS);
244bf215546Sopenharmony_ci      elem_types[LP_JIT_CTX_NUM_SSBOS] =
245bf215546Sopenharmony_ci            LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_SHADER_BUFFERS);
246bf215546Sopenharmony_ci      context_type = LLVMStructTypeInContext(lc, elem_types,
247bf215546Sopenharmony_ci                                             ARRAY_SIZE(elem_types), 0);
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, constants,
250bf215546Sopenharmony_ci                             gallivm->target, context_type,
251bf215546Sopenharmony_ci                             LP_JIT_CTX_CONSTANTS);
252bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, num_constants,
253bf215546Sopenharmony_ci                             gallivm->target, context_type,
254bf215546Sopenharmony_ci                             LP_JIT_CTX_NUM_CONSTANTS);
255bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, textures,
256bf215546Sopenharmony_ci                             gallivm->target, context_type,
257bf215546Sopenharmony_ci                             LP_JIT_CTX_TEXTURES);
258bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, samplers,
259bf215546Sopenharmony_ci                             gallivm->target, context_type,
260bf215546Sopenharmony_ci                             LP_JIT_CTX_SAMPLERS);
261bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, images,
262bf215546Sopenharmony_ci                             gallivm->target, context_type,
263bf215546Sopenharmony_ci                             LP_JIT_CTX_IMAGES);
264bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, alpha_ref_value,
265bf215546Sopenharmony_ci                             gallivm->target, context_type,
266bf215546Sopenharmony_ci                             LP_JIT_CTX_ALPHA_REF);
267bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_front,
268bf215546Sopenharmony_ci                             gallivm->target, context_type,
269bf215546Sopenharmony_ci                             LP_JIT_CTX_STENCIL_REF_FRONT);
270bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_back,
271bf215546Sopenharmony_ci                             gallivm->target, context_type,
272bf215546Sopenharmony_ci                             LP_JIT_CTX_STENCIL_REF_BACK);
273bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, u8_blend_color,
274bf215546Sopenharmony_ci                             gallivm->target, context_type,
275bf215546Sopenharmony_ci                             LP_JIT_CTX_U8_BLEND_COLOR);
276bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, f_blend_color,
277bf215546Sopenharmony_ci                             gallivm->target, context_type,
278bf215546Sopenharmony_ci                             LP_JIT_CTX_F_BLEND_COLOR);
279bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, viewports,
280bf215546Sopenharmony_ci                             gallivm->target, context_type,
281bf215546Sopenharmony_ci                             LP_JIT_CTX_VIEWPORTS);
282bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, ssbos,
283bf215546Sopenharmony_ci                             gallivm->target, context_type,
284bf215546Sopenharmony_ci                             LP_JIT_CTX_SSBOS);
285bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, num_ssbos,
286bf215546Sopenharmony_ci                             gallivm->target, context_type,
287bf215546Sopenharmony_ci                             LP_JIT_CTX_NUM_SSBOS);
288bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, sample_mask,
289bf215546Sopenharmony_ci                             gallivm->target, context_type,
290bf215546Sopenharmony_ci                             LP_JIT_CTX_SAMPLE_MASK);
291bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, aniso_filter_table,
292bf215546Sopenharmony_ci                             gallivm->target, context_type,
293bf215546Sopenharmony_ci                             LP_JIT_CTX_ANISO_FILTER_TABLE);
294bf215546Sopenharmony_ci      LP_CHECK_STRUCT_SIZE(struct lp_jit_context,
295bf215546Sopenharmony_ci                           gallivm->target, context_type);
296bf215546Sopenharmony_ci
297bf215546Sopenharmony_ci      lp->jit_context_ptr_type = LLVMPointerType(context_type, 0);
298bf215546Sopenharmony_ci   }
299bf215546Sopenharmony_ci
300bf215546Sopenharmony_ci   /* struct lp_jit_thread_data */
301bf215546Sopenharmony_ci   {
302bf215546Sopenharmony_ci      LLVMTypeRef elem_types[LP_JIT_THREAD_DATA_COUNT];
303bf215546Sopenharmony_ci      LLVMTypeRef thread_data_type;
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci      elem_types[LP_JIT_THREAD_DATA_CACHE] =
306bf215546Sopenharmony_ci            LLVMPointerType(lp_build_format_cache_type(gallivm), 0);
307bf215546Sopenharmony_ci      elem_types[LP_JIT_THREAD_DATA_COUNTER] = LLVMInt64TypeInContext(lc);
308bf215546Sopenharmony_ci      elem_types[LP_JIT_THREAD_DATA_INVOCATIONS] = LLVMInt64TypeInContext(lc);
309bf215546Sopenharmony_ci      elem_types[LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX] =
310bf215546Sopenharmony_ci      elem_types[LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX] =
311bf215546Sopenharmony_ci            LLVMInt32TypeInContext(lc);
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci      thread_data_type = LLVMStructTypeInContext(lc, elem_types,
314bf215546Sopenharmony_ci                                                 ARRAY_SIZE(elem_types), 0);
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci      lp->jit_thread_data_ptr_type = LLVMPointerType(thread_data_type, 0);
317bf215546Sopenharmony_ci   }
318bf215546Sopenharmony_ci
319bf215546Sopenharmony_ci   /*
320bf215546Sopenharmony_ci    * lp_linear_elem
321bf215546Sopenharmony_ci    *
322bf215546Sopenharmony_ci    * XXX: it can be instanced only once due to the use of opaque types, and
323bf215546Sopenharmony_ci    * the fact that screen->module is also a global.
324bf215546Sopenharmony_ci    */
325bf215546Sopenharmony_ci   {
326bf215546Sopenharmony_ci      LLVMTypeRef ret_type;
327bf215546Sopenharmony_ci      LLVMTypeRef arg_types[1];
328bf215546Sopenharmony_ci      LLVMTypeRef func_type;
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci      ret_type = LLVMPointerType(LLVMVectorType(LLVMInt8TypeInContext(lc), 16), 0);
331bf215546Sopenharmony_ci
332bf215546Sopenharmony_ci      arg_types[0] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_ci      /* lp_linear_func */
335bf215546Sopenharmony_ci      func_type = LLVMFunctionType(ret_type, arg_types, ARRAY_SIZE(arg_types), 0);
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci      /*
338bf215546Sopenharmony_ci       * We actually define lp_linear_elem not as a structure but simply as a
339bf215546Sopenharmony_ci       * lp_linear_func pointer
340bf215546Sopenharmony_ci       */
341bf215546Sopenharmony_ci      linear_elem_type = LLVMPointerType(func_type, 0);
342bf215546Sopenharmony_ci   }
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   /* struct lp_jit_linear_context */
345bf215546Sopenharmony_ci   {
346bf215546Sopenharmony_ci      LLVMTypeRef linear_elem_ptr_type = LLVMPointerType(linear_elem_type, 0);
347bf215546Sopenharmony_ci      LLVMTypeRef elem_types[LP_JIT_LINEAR_CTX_COUNT];
348bf215546Sopenharmony_ci      LLVMTypeRef linear_context_type;
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci      elem_types[LP_JIT_LINEAR_CTX_CONSTANTS] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
352bf215546Sopenharmony_ci      elem_types[LP_JIT_LINEAR_CTX_TEX] =
353bf215546Sopenharmony_ci            LLVMArrayType(linear_elem_ptr_type, LP_MAX_LINEAR_TEXTURES);
354bf215546Sopenharmony_ci      elem_types[LP_JIT_LINEAR_CTX_INPUTS] =
355bf215546Sopenharmony_ci            LLVMArrayType(linear_elem_ptr_type, LP_MAX_LINEAR_INPUTS);
356bf215546Sopenharmony_ci      elem_types[LP_JIT_LINEAR_CTX_COLOR0] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
357bf215546Sopenharmony_ci      elem_types[LP_JIT_LINEAR_CTX_BLEND_COLOR] = LLVMInt32TypeInContext(lc);
358bf215546Sopenharmony_ci      elem_types[LP_JIT_LINEAR_CTX_ALPHA_REF] = LLVMInt8TypeInContext(lc);
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci      linear_context_type = LLVMStructTypeInContext(lc, elem_types,
361bf215546Sopenharmony_ci                                                    ARRAY_SIZE(elem_types), 0);
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_linear_context, constants,
364bf215546Sopenharmony_ci                             gallivm->target, linear_context_type,
365bf215546Sopenharmony_ci                             LP_JIT_LINEAR_CTX_CONSTANTS);
366bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_linear_context, tex,
367bf215546Sopenharmony_ci                             gallivm->target, linear_context_type,
368bf215546Sopenharmony_ci                             LP_JIT_LINEAR_CTX_TEX);
369bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_linear_context, inputs,
370bf215546Sopenharmony_ci                             gallivm->target, linear_context_type,
371bf215546Sopenharmony_ci                             LP_JIT_LINEAR_CTX_INPUTS);
372bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_linear_context, color0,
373bf215546Sopenharmony_ci                             gallivm->target, linear_context_type,
374bf215546Sopenharmony_ci                             LP_JIT_LINEAR_CTX_COLOR0);
375bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_linear_context, blend_color,
376bf215546Sopenharmony_ci                             gallivm->target, linear_context_type,
377bf215546Sopenharmony_ci                             LP_JIT_LINEAR_CTX_BLEND_COLOR);
378bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_linear_context, alpha_ref_value,
379bf215546Sopenharmony_ci                             gallivm->target, linear_context_type,
380bf215546Sopenharmony_ci                             LP_JIT_LINEAR_CTX_ALPHA_REF);
381bf215546Sopenharmony_ci      LP_CHECK_STRUCT_SIZE(struct lp_jit_linear_context,
382bf215546Sopenharmony_ci                           gallivm->target, linear_context_type);
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci      lp->jit_linear_context_ptr_type = LLVMPointerType(linear_context_type, 0);
385bf215546Sopenharmony_ci   }
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci   if (gallivm_debug & GALLIVM_DEBUG_IR) {
388bf215546Sopenharmony_ci      char *str = LLVMPrintModuleToString(gallivm->module);
389bf215546Sopenharmony_ci      fprintf(stderr, "%s", str);
390bf215546Sopenharmony_ci      LLVMDisposeMessage(str);
391bf215546Sopenharmony_ci   }
392bf215546Sopenharmony_ci}
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_civoid
396bf215546Sopenharmony_cilp_jit_screen_cleanup(struct llvmpipe_screen *screen)
397bf215546Sopenharmony_ci{
398bf215546Sopenharmony_ci   /* nothing */
399bf215546Sopenharmony_ci}
400bf215546Sopenharmony_ci
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ciboolean
403bf215546Sopenharmony_cilp_jit_screen_init(struct llvmpipe_screen *screen)
404bf215546Sopenharmony_ci{
405bf215546Sopenharmony_ci   return lp_build_init();
406bf215546Sopenharmony_ci}
407bf215546Sopenharmony_ci
408bf215546Sopenharmony_ci
409bf215546Sopenharmony_civoid
410bf215546Sopenharmony_cilp_jit_init_types(struct lp_fragment_shader_variant *lp)
411bf215546Sopenharmony_ci{
412bf215546Sopenharmony_ci   if (!lp->jit_context_ptr_type)
413bf215546Sopenharmony_ci      lp_jit_create_types(lp);
414bf215546Sopenharmony_ci}
415bf215546Sopenharmony_ci
416bf215546Sopenharmony_cistatic void
417bf215546Sopenharmony_cilp_jit_create_cs_types(struct lp_compute_shader_variant *lp)
418bf215546Sopenharmony_ci{
419bf215546Sopenharmony_ci   struct gallivm_state *gallivm = lp->gallivm;
420bf215546Sopenharmony_ci   LLVMContextRef lc = gallivm->context;
421bf215546Sopenharmony_ci   LLVMTypeRef texture_type, sampler_type, image_type;
422bf215546Sopenharmony_ci
423bf215546Sopenharmony_ci   texture_type = create_jit_texture_type(gallivm);
424bf215546Sopenharmony_ci   sampler_type = create_jit_sampler_type(gallivm);
425bf215546Sopenharmony_ci   image_type = create_jit_image_type(gallivm);
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_ci   /* struct lp_jit_cs_thread_data */
428bf215546Sopenharmony_ci   {
429bf215546Sopenharmony_ci      LLVMTypeRef elem_types[LP_JIT_CS_THREAD_DATA_COUNT];
430bf215546Sopenharmony_ci      LLVMTypeRef thread_data_type;
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_THREAD_DATA_CACHE] =
433bf215546Sopenharmony_ci            LLVMPointerType(lp_build_format_cache_type(gallivm), 0);
434bf215546Sopenharmony_ci
435bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_THREAD_DATA_SHARED] = LLVMPointerType(LLVMInt32TypeInContext(lc), 0);
436bf215546Sopenharmony_ci      thread_data_type = LLVMStructTypeInContext(lc, elem_types,
437bf215546Sopenharmony_ci                                                 ARRAY_SIZE(elem_types), 0);
438bf215546Sopenharmony_ci
439bf215546Sopenharmony_ci      lp->jit_cs_thread_data_ptr_type = LLVMPointerType(thread_data_type, 0);
440bf215546Sopenharmony_ci   }
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_ci   /* struct lp_jit_cs_context */
443bf215546Sopenharmony_ci   {
444bf215546Sopenharmony_ci      LLVMTypeRef elem_types[LP_JIT_CS_CTX_COUNT];
445bf215546Sopenharmony_ci      LLVMTypeRef cs_context_type;
446bf215546Sopenharmony_ci
447bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_CONSTANTS] =
448bf215546Sopenharmony_ci         LLVMArrayType(LLVMPointerType(LLVMFloatTypeInContext(lc), 0), LP_MAX_TGSI_CONST_BUFFERS);
449bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_NUM_CONSTANTS] =
450bf215546Sopenharmony_ci            LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_CONST_BUFFERS);
451bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_TEXTURES] = LLVMArrayType(texture_type,
452bf215546Sopenharmony_ci                                                      PIPE_MAX_SHADER_SAMPLER_VIEWS);
453bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_SAMPLERS] = LLVMArrayType(sampler_type,
454bf215546Sopenharmony_ci                                                      PIPE_MAX_SAMPLERS);
455bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_IMAGES] = LLVMArrayType(image_type,
456bf215546Sopenharmony_ci                                                       PIPE_MAX_SHADER_IMAGES);
457bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_SSBOS] =
458bf215546Sopenharmony_ci         LLVMArrayType(LLVMPointerType(LLVMInt32TypeInContext(lc), 0), LP_MAX_TGSI_SHADER_BUFFERS);
459bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_NUM_SSBOS] =
460bf215546Sopenharmony_ci            LLVMArrayType(LLVMInt32TypeInContext(lc), LP_MAX_TGSI_SHADER_BUFFERS);
461bf215546Sopenharmony_ci
462bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_SHARED_SIZE] = LLVMInt32TypeInContext(lc);
463bf215546Sopenharmony_ci
464bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_KERNEL_ARGS] = LLVMPointerType(LLVMInt8TypeInContext(lc), 0);
465bf215546Sopenharmony_ci
466bf215546Sopenharmony_ci      elem_types[LP_JIT_CS_CTX_ANISO_FILTER_TABLE] = LLVMPointerType(LLVMFloatTypeInContext(lc), 0);
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_ci      cs_context_type = LLVMStructTypeInContext(lc, elem_types,
469bf215546Sopenharmony_ci                                             ARRAY_SIZE(elem_types), 0);
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, constants,
472bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
473bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_CONSTANTS);
474bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, num_constants,
475bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
476bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_NUM_CONSTANTS);
477bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, textures,
478bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
479bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_TEXTURES);
480bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, samplers,
481bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
482bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_SAMPLERS);
483bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, images,
484bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
485bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_IMAGES);
486bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, ssbos,
487bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
488bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_SSBOS);
489bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, num_ssbos,
490bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
491bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_NUM_SSBOS);
492bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, shared_size,
493bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
494bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_SHARED_SIZE);
495bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, kernel_args,
496bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
497bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_KERNEL_ARGS);
498bf215546Sopenharmony_ci      LP_CHECK_MEMBER_OFFSET(struct lp_jit_cs_context, aniso_filter_table,
499bf215546Sopenharmony_ci                             gallivm->target, cs_context_type,
500bf215546Sopenharmony_ci                             LP_JIT_CS_CTX_ANISO_FILTER_TABLE);
501bf215546Sopenharmony_ci      LP_CHECK_STRUCT_SIZE(struct lp_jit_cs_context,
502bf215546Sopenharmony_ci                           gallivm->target, cs_context_type);
503bf215546Sopenharmony_ci
504bf215546Sopenharmony_ci      lp->jit_cs_context_ptr_type = LLVMPointerType(cs_context_type, 0);
505bf215546Sopenharmony_ci   }
506bf215546Sopenharmony_ci
507bf215546Sopenharmony_ci   if (gallivm_debug & GALLIVM_DEBUG_IR) {
508bf215546Sopenharmony_ci      char *str = LLVMPrintModuleToString(gallivm->module);
509bf215546Sopenharmony_ci      fprintf(stderr, "%s", str);
510bf215546Sopenharmony_ci      LLVMDisposeMessage(str);
511bf215546Sopenharmony_ci   }
512bf215546Sopenharmony_ci}
513bf215546Sopenharmony_ci
514bf215546Sopenharmony_civoid
515bf215546Sopenharmony_cilp_jit_init_cs_types(struct lp_compute_shader_variant *lp)
516bf215546Sopenharmony_ci{
517bf215546Sopenharmony_ci   if (!lp->jit_cs_context_ptr_type)
518bf215546Sopenharmony_ci      lp_jit_create_cs_types(lp);
519bf215546Sopenharmony_ci}
520