gallivm,llvmpipe,draw: Support multiple constant buffers.
[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 #include "gallivm/lp_bld_limits.h"
41
42 #include "pipe/p_state.h"
43 #include "lp_texture.h"
44
45
46 struct lp_fragment_shader_variant;
47 struct llvmpipe_screen;
48
49
50 struct lp_jit_texture
51 {
52 uint32_t width;
53 uint32_t height;
54 uint32_t depth;
55 uint32_t first_level;
56 uint32_t last_level;
57 const void *base;
58 uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
59 uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
60 uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
61 /* sampler state, actually */
62 float min_lod;
63 float max_lod;
64 float lod_bias;
65 float border_color[4];
66 };
67
68
69 enum {
70 LP_JIT_TEXTURE_WIDTH = 0,
71 LP_JIT_TEXTURE_HEIGHT,
72 LP_JIT_TEXTURE_DEPTH,
73 LP_JIT_TEXTURE_FIRST_LEVEL,
74 LP_JIT_TEXTURE_LAST_LEVEL,
75 LP_JIT_TEXTURE_BASE,
76 LP_JIT_TEXTURE_ROW_STRIDE,
77 LP_JIT_TEXTURE_IMG_STRIDE,
78 LP_JIT_TEXTURE_MIP_OFFSETS,
79 LP_JIT_TEXTURE_MIN_LOD,
80 LP_JIT_TEXTURE_MAX_LOD,
81 LP_JIT_TEXTURE_LOD_BIAS,
82 LP_JIT_TEXTURE_BORDER_COLOR,
83 LP_JIT_TEXTURE_NUM_FIELDS /* number of fields above */
84 };
85
86
87
88 /**
89 * This structure is passed directly to the generated fragment shader.
90 *
91 * It contains the derived state.
92 *
93 * Changes here must be reflected in the lp_jit_context_* macros and
94 * lp_jit_init_types function. Changes to the ordering should be avoided.
95 *
96 * Only use types with a clear size and padding here, in particular prefer the
97 * stdint.h types to the basic integer types.
98 */
99 struct lp_jit_context
100 {
101 const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
102
103 float alpha_ref_value;
104
105 uint32_t stencil_ref_front, stencil_ref_back;
106
107 uint8_t *u8_blend_color;
108 float *f_blend_color;
109
110 struct lp_jit_texture textures[PIPE_MAX_SAMPLERS];
111 };
112
113
114 /**
115 * These enum values must match the position of the fields in the
116 * lp_jit_context struct above.
117 */
118 enum {
119 LP_JIT_CTX_CONSTANTS = 0,
120 LP_JIT_CTX_ALPHA_REF,
121 LP_JIT_CTX_STENCIL_REF_FRONT,
122 LP_JIT_CTX_STENCIL_REF_BACK,
123 LP_JIT_CTX_U8_BLEND_COLOR,
124 LP_JIT_CTX_F_BLEND_COLOR,
125 LP_JIT_CTX_TEXTURES,
126 LP_JIT_CTX_COUNT
127 };
128
129
130 #define lp_jit_context_constants(_gallivm, _ptr) \
131 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
132
133 #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
134 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
135
136 #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
137 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
138
139 #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
140 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
141
142 #define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
143 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
144
145 #define lp_jit_context_f_blend_color(_gallivm, _ptr) \
146 lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
147
148 #define lp_jit_context_textures(_gallivm, _ptr) \
149 lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
150
151
152
153 /**
154 * typedef for fragment shader function
155 *
156 * @param context jit context
157 * @param x block start x
158 * @param y block start y
159 * @param facing is front facing
160 * @param a0 shader input a0
161 * @param dadx shader input dadx
162 * @param dady shader input dady
163 * @param color color buffer
164 * @param depth depth buffer
165 * @param mask mask of visible pixels in block
166 * @param thread_data task thread data
167 * @param stride color buffer row stride in bytes
168 */
169 typedef void
170 (*lp_jit_frag_func)(const struct lp_jit_context *context,
171 uint32_t x,
172 uint32_t y,
173 uint32_t facing,
174 const void *a0,
175 const void *dadx,
176 const void *dady,
177 uint8_t **color,
178 void *depth,
179 uint32_t mask,
180 uint32_t *counter,
181 unsigned *stride);
182
183
184 void
185 lp_jit_screen_cleanup(struct llvmpipe_screen *screen);
186
187
188 void
189 lp_jit_screen_init(struct llvmpipe_screen *screen);
190
191
192 void
193 lp_jit_init_types(struct lp_fragment_shader_variant *lp);
194
195
196 #endif /* LP_JIT_H */