• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 lp_fragment_shader_variant;
46 struct llvmpipe_screen;
47 
48 
49 struct lp_jit_texture
50 {
51    uint32_t width;
52    uint32_t height;
53    uint32_t depth;
54    uint32_t first_level;
55    uint32_t last_level;
56    uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
57    uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
58    const void *data[LP_MAX_TEXTURE_LEVELS];
59    /* sampler state, actually */
60    float min_lod;
61    float max_lod;
62    float lod_bias;
63    float border_color[4];
64 };
65 
66 
67 enum {
68    LP_JIT_TEXTURE_WIDTH = 0,
69    LP_JIT_TEXTURE_HEIGHT,
70    LP_JIT_TEXTURE_DEPTH,
71    LP_JIT_TEXTURE_FIRST_LEVEL,
72    LP_JIT_TEXTURE_LAST_LEVEL,
73    LP_JIT_TEXTURE_ROW_STRIDE,
74    LP_JIT_TEXTURE_IMG_STRIDE,
75    LP_JIT_TEXTURE_DATA,
76    LP_JIT_TEXTURE_MIN_LOD,
77    LP_JIT_TEXTURE_MAX_LOD,
78    LP_JIT_TEXTURE_LOD_BIAS,
79    LP_JIT_TEXTURE_BORDER_COLOR,
80    LP_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
81 };
82 
83 
84 
85 /**
86  * This structure is passed directly to the generated fragment shader.
87  *
88  * It contains the derived state.
89  *
90  * Changes here must be reflected in the lp_jit_context_* macros and
91  * lp_jit_init_types function. Changes to the ordering should be avoided.
92  *
93  * Only use types with a clear size and padding here, in particular prefer the
94  * stdint.h types to the basic integer types.
95  */
96 struct lp_jit_context
97 {
98    const float *constants;
99 
100    float alpha_ref_value;
101 
102    uint32_t stencil_ref_front, stencil_ref_back;
103 
104    /* FIXME: store (also?) in floats */
105    uint8_t *blend_color;
106 
107    struct lp_jit_texture textures[PIPE_MAX_SAMPLERS];
108 };
109 
110 
111 /**
112  * These enum values must match the position of the fields in the
113  * lp_jit_context struct above.
114  */
115 enum {
116    LP_JIT_CTX_CONSTANTS = 0,
117    LP_JIT_CTX_ALPHA_REF,
118    LP_JIT_CTX_STENCIL_REF_FRONT,
119    LP_JIT_CTX_STENCIL_REF_BACK,
120    LP_JIT_CTX_BLEND_COLOR,
121    LP_JIT_CTX_TEXTURES,
122    LP_JIT_CTX_COUNT
123 };
124 
125 
126 #define lp_jit_context_constants(_gallivm, _ptr) \
127    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
128 
129 #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
130    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
131 
132 #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
133    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
134 
135 #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
136    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
137 
138 #define lp_jit_context_blend_color(_gallivm, _ptr) \
139    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_BLEND_COLOR, "blend_color")
140 
141 #define lp_jit_context_textures(_gallivm, _ptr) \
142    lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
143 
144 
145 
146 typedef void
147 (*lp_jit_frag_func)(const struct lp_jit_context *context,
148                     uint32_t x,
149                     uint32_t y,
150                     uint32_t facing,
151                     const void *a0,
152                     const void *dadx,
153                     const void *dady,
154                     uint8_t **color,
155                     void *depth,
156                     uint32_t mask,
157                     uint32_t *counter);
158 
159 
160 void
161 lp_jit_screen_cleanup(struct llvmpipe_screen *screen);
162 
163 
164 void
165 lp_jit_screen_init(struct llvmpipe_screen *screen);
166 
167 
168 void
169 lp_jit_init_types(struct lp_fragment_shader_variant *lp);
170 
171 
172 #endif /* LP_JIT_H */
173