Merge branch '7.8'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_jit.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * C - JIT interfaces
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35 #ifndef LP_JIT_H
36 #define LP_JIT_H
37
38
39 #include "gallivm/lp_bld_struct.h"
40
41 #include "pipe/p_state.h"
42 #include "lp_texture.h"
43
44
45 struct llvmpipe_screen;
46
47
48 struct lp_jit_texture
49 {
50 uint32_t width;
51 uint32_t height;
52 uint32_t depth;
53 uint32_t last_level;
54 uint32_t row_stride[LP_MAX_TEXTURE_2D_LEVELS];
55 const void *data[LP_MAX_TEXTURE_2D_LEVELS];
56 };
57
58
59 enum {
60 LP_JIT_TEXTURE_WIDTH = 0,
61 LP_JIT_TEXTURE_HEIGHT,
62 LP_JIT_TEXTURE_DEPTH,
63 LP_JIT_TEXTURE_LAST_LEVEL,
64 LP_JIT_TEXTURE_ROW_STRIDE,
65 LP_JIT_TEXTURE_DATA
66 };
67
68
69
70 /**
71 * This structure is passed directly to the generated fragment shader.
72 *
73 * It contains the derived state.
74 *
75 * Changes here must be reflected in the lp_jit_context_* macros and
76 * lp_jit_init_types function. Changes to the ordering should be avoided.
77 *
78 * Only use types with a clear size and padding here, in particular prefer the
79 * stdint.h types to the basic integer types.
80 */
81 struct lp_jit_context
82 {
83 const float *constants;
84
85 float alpha_ref_value;
86
87 uint32_t stencil_ref_front, stencil_ref_back;
88
89 /** floats, not ints */
90 float scissor_xmin, scissor_ymin, scissor_xmax, scissor_ymax;
91
92 /* FIXME: store (also?) in floats */
93 uint8_t *blend_color;
94
95 struct lp_jit_texture textures[PIPE_MAX_SAMPLERS];
96 };
97
98
99 /**
100 * These enum values must match the position of the fields in the
101 * lp_jit_context struct above.
102 */
103 enum {
104 LP_JIT_CTX_CONSTANTS = 0,
105 LP_JIT_CTX_ALPHA_REF,
106 LP_JIT_CTX_STENCIL_REF_FRONT,
107 LP_JIT_CTX_STENCIL_REF_BACK,
108 LP_JIT_CTX_SCISSOR_XMIN,
109 LP_JIT_CTX_SCISSOR_YMIN,
110 LP_JIT_CTX_SCISSOR_XMAX,
111 LP_JIT_CTX_SCISSOR_YMAX,
112 LP_JIT_CTX_BLEND_COLOR,
113 LP_JIT_CTX_TEXTURES,
114 LP_JIT_CTX_COUNT
115 };
116
117
118 #define lp_jit_context_constants(_builder, _ptr) \
119 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
120
121 #define lp_jit_context_alpha_ref_value(_builder, _ptr) \
122 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
123
124 #define lp_jit_context_stencil_ref_front_value(_builder, _ptr) \
125 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
126
127 #define lp_jit_context_stencil_ref_back_value(_builder, _ptr) \
128 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
129
130 #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \
131 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMIN, "scissor_xmin")
132
133 #define lp_jit_context_scissor_ymin_value(_builder, _ptr) \
134 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_YMIN, "scissor_ymin")
135
136 #define lp_jit_context_scissor_xmax_value(_builder, _ptr) \
137 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMAX, "scissor_xmax")
138
139 #define lp_jit_context_scissor_ymax_value(_builder, _ptr) \
140 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_YMAX, "scissor_ymax")
141
142 #define lp_jit_context_blend_color(_builder, _ptr) \
143 lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_BLEND_COLOR, "blend_color")
144
145 #define lp_jit_context_textures(_builder, _ptr) \
146 lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CONTEXT_TEXTURES, "textures")
147
148
149 /** Indexes into jit_function[] array */
150 #define RAST_WHOLE 0
151 #define RAST_EDGE_TEST 1
152
153
154 typedef void
155 (*lp_jit_frag_func)(const struct lp_jit_context *context,
156 uint32_t x,
157 uint32_t y,
158 float facing,
159 const void *a0,
160 const void *dadx,
161 const void *dady,
162 uint8_t **color,
163 void *depth,
164 const int32_t c1,
165 const int32_t c2,
166 const int32_t c3,
167 const int32_t *step1,
168 const int32_t *step2,
169 const int32_t *step3);
170
171
172 void
173 lp_jit_screen_cleanup(struct llvmpipe_screen *screen);
174
175
176 void
177 lp_jit_screen_init(struct llvmpipe_screen *screen);
178
179
180 #endif /* LP_JIT_H */