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 "gallivm/lp_bld_intr.h"
40 #include "lp_context.h"
41 #include "lp_screen.h"
46 lp_jit_create_types(struct llvmpipe_context
*lp
)
48 struct gallivm_state
*gallivm
= lp
->gallivm
;
49 LLVMContextRef lc
= gallivm
->context
;
50 LLVMTypeRef texture_type
;
52 /* struct lp_jit_texture */
54 LLVMTypeRef elem_types
[LP_JIT_TEXTURE_NUM_FIELDS
];
56 elem_types
[LP_JIT_TEXTURE_WIDTH
] =
57 elem_types
[LP_JIT_TEXTURE_HEIGHT
] =
58 elem_types
[LP_JIT_TEXTURE_DEPTH
] =
59 elem_types
[LP_JIT_TEXTURE_LAST_LEVEL
] = LLVMInt32TypeInContext(lc
);
60 elem_types
[LP_JIT_TEXTURE_ROW_STRIDE
] =
61 elem_types
[LP_JIT_TEXTURE_IMG_STRIDE
] =
62 LLVMArrayType(LLVMInt32TypeInContext(lc
), LP_MAX_TEXTURE_LEVELS
);
63 elem_types
[LP_JIT_TEXTURE_DATA
] =
64 LLVMArrayType(LLVMPointerType(LLVMInt8TypeInContext(lc
), 0),
65 LP_MAX_TEXTURE_LEVELS
);
66 elem_types
[LP_JIT_TEXTURE_MIN_LOD
] =
67 elem_types
[LP_JIT_TEXTURE_MAX_LOD
] =
68 elem_types
[LP_JIT_TEXTURE_LOD_BIAS
] = LLVMFloatTypeInContext(lc
);
69 elem_types
[LP_JIT_TEXTURE_BORDER_COLOR
] =
70 LLVMArrayType(LLVMFloatTypeInContext(lc
), 4);
72 texture_type
= LLVMStructTypeInContext(lc
, elem_types
,
73 Elements(elem_types
), 0);
75 LLVMInvalidateStructLayout(gallivm
->target
, texture_type
);
77 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, width
,
78 gallivm
->target
, texture_type
,
79 LP_JIT_TEXTURE_WIDTH
);
80 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, height
,
81 gallivm
->target
, texture_type
,
82 LP_JIT_TEXTURE_HEIGHT
);
83 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, depth
,
84 gallivm
->target
, texture_type
,
85 LP_JIT_TEXTURE_DEPTH
);
86 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, last_level
,
87 gallivm
->target
, texture_type
,
88 LP_JIT_TEXTURE_LAST_LEVEL
);
89 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, row_stride
,
90 gallivm
->target
, texture_type
,
91 LP_JIT_TEXTURE_ROW_STRIDE
);
92 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, img_stride
,
93 gallivm
->target
, texture_type
,
94 LP_JIT_TEXTURE_IMG_STRIDE
);
95 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, data
,
96 gallivm
->target
, texture_type
,
98 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, min_lod
,
99 gallivm
->target
, texture_type
,
100 LP_JIT_TEXTURE_MIN_LOD
);
101 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, max_lod
,
102 gallivm
->target
, texture_type
,
103 LP_JIT_TEXTURE_MAX_LOD
);
104 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, lod_bias
,
105 gallivm
->target
, texture_type
,
106 LP_JIT_TEXTURE_LOD_BIAS
);
107 LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture
, border_color
,
108 gallivm
->target
, texture_type
,
109 LP_JIT_TEXTURE_BORDER_COLOR
);
111 LP_CHECK_STRUCT_SIZE(struct lp_jit_texture
,
112 gallivm
->target
, texture_type
);
114 LLVMAddTypeName(gallivm
->module
, "texture", texture_type
);
117 /* struct lp_jit_context */
119 LLVMTypeRef elem_types
[LP_JIT_CTX_COUNT
];
120 LLVMTypeRef context_type
;
122 elem_types
[LP_JIT_CTX_CONSTANTS
] = LLVMPointerType(LLVMFloatTypeInContext(lc
), 0);
123 elem_types
[LP_JIT_CTX_ALPHA_REF
] = LLVMFloatTypeInContext(lc
);
124 elem_types
[LP_JIT_CTX_STENCIL_REF_FRONT
] =
125 elem_types
[LP_JIT_CTX_STENCIL_REF_BACK
] = LLVMInt32TypeInContext(lc
);
126 elem_types
[LP_JIT_CTX_BLEND_COLOR
] = LLVMPointerType(LLVMInt8TypeInContext(lc
), 0);
127 elem_types
[LP_JIT_CTX_TEXTURES
] = LLVMArrayType(texture_type
,
130 context_type
= LLVMStructTypeInContext(lc
, elem_types
,
131 Elements(elem_types
), 0);
133 LLVMInvalidateStructLayout(gallivm
->target
, context_type
);
135 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
136 gallivm
->target
, context_type
,
137 LP_JIT_CTX_CONSTANTS
);
138 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
139 gallivm
->target
, context_type
,
140 LP_JIT_CTX_ALPHA_REF
);
141 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_front
,
142 gallivm
->target
, context_type
,
143 LP_JIT_CTX_STENCIL_REF_FRONT
);
144 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, stencil_ref_back
,
145 gallivm
->target
, context_type
,
146 LP_JIT_CTX_STENCIL_REF_BACK
);
147 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, blend_color
,
148 gallivm
->target
, context_type
,
149 LP_JIT_CTX_BLEND_COLOR
);
150 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, textures
,
151 gallivm
->target
, context_type
,
152 LP_JIT_CTX_TEXTURES
);
153 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
154 gallivm
->target
, context_type
);
156 LLVMAddTypeName(gallivm
->module
, "context", context_type
);
158 lp
->jit_context_ptr_type
= LLVMPointerType(context_type
, 0);
161 if (gallivm_debug
& GALLIVM_DEBUG_IR
) {
162 LLVMDumpModule(gallivm
->module
);
168 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
175 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
182 lp_jit_get_context_type(struct llvmpipe_context
*lp
)
184 if (!lp
->jit_context_ptr_type
)
185 lp_jit_create_types(lp
);
187 return lp
->jit_context_ptr_type
;