OSDN Git Service

ilo: use ilo_dev_info in toy compiler
[android-x86/external-mesa.git] / src / gallium / drivers / ilo / ilo_shader.h
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 2012-2013 LunarG, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Chia-I Wu <olv@lunarg.com>
26  */
27
28 #ifndef ILO_SHADER_H
29 #define ILO_SHADER_H
30
31 #include "ilo_common.h"
32 #include "ilo_context.h"
33
34 /* XXX The interface needs to be reworked */
35
36 /**
37  * A shader variant.  It consists of non-orthogonal states of the pipe context
38  * affecting the compilation of a shader.
39  */
40 struct ilo_shader_variant {
41    union {
42       struct {
43          bool rasterizer_discard;
44          int num_ucps;
45       } vs;
46
47       struct {
48          bool rasterizer_discard;
49          int num_inputs;
50          int semantic_names[PIPE_MAX_SHADER_INPUTS];
51          int semantic_indices[PIPE_MAX_SHADER_INPUTS];
52       } gs;
53
54       struct {
55          bool flatshade;
56          int fb_height;
57          int num_cbufs;
58       } fs;
59    } u;
60
61    int num_sampler_views;
62    struct {
63       unsigned r:3;
64       unsigned g:3;
65       unsigned b:3;
66       unsigned a:3;
67    } sampler_view_swizzles[ILO_MAX_SAMPLER_VIEWS];
68
69    uint32_t saturate_tex_coords[3];
70 };
71
72 /**
73  * A compiled shader.
74  */
75 struct ilo_shader {
76    struct ilo_shader_variant variant;
77    /* hash of the shader variant for quicker lookup */
78    unsigned hash;
79
80    struct {
81       int semantic_names[PIPE_MAX_SHADER_INPUTS];
82       int semantic_indices[PIPE_MAX_SHADER_INPUTS];
83       int interp[PIPE_MAX_SHADER_INPUTS];
84       bool centroid[PIPE_MAX_SHADER_INPUTS];
85       int count;
86
87       int start_grf;
88       bool has_pos;
89       bool has_linear_interp;
90       int barycentric_interpolation_mode;
91       bool discard_adj;
92    } in;
93
94    struct {
95       int semantic_names[PIPE_MAX_SHADER_OUTPUTS];
96       int semantic_indices[PIPE_MAX_SHADER_OUTPUTS];
97       int count;
98
99       bool has_pos;
100    } out;
101
102    bool has_kill;
103    bool dispatch_16;
104
105    bool stream_output;
106    int svbi_post_inc;
107    /* for VS stream output / rasterizer discard */
108    int gs_offsets[3];
109    int gs_start_grf;
110
111    void *kernel;
112    int kernel_size;
113
114    /* what does the push constant buffer consist of? */
115    struct {
116       int clip_state_size;
117    } pcb;
118
119    struct list_head list;
120
121    uint32_t cache_seqno;
122    uint32_t cache_offset;
123 };
124
125 /**
126  * Information about a shader state.
127  */
128 struct ilo_shader_info {
129    const struct ilo_dev_info *dev;
130    int type;
131
132    const struct tgsi_token *tokens;
133
134    struct pipe_stream_output_info stream_output;
135    struct {
136       unsigned req_local_mem;
137       unsigned req_private_mem;
138       unsigned req_input_mem;
139    } compute;
140
141    bool has_color_interp;
142    bool has_pos;
143    bool has_vertexid;
144    bool has_instanceid;
145    bool fs_color0_writes_all_cbufs;
146
147    int edgeflag_in;
148    int edgeflag_out;
149
150    uint32_t shadow_samplers;
151    int num_samplers;
152 };
153
154 /**
155  * A shader state.
156  */
157 struct ilo_shader_state {
158    struct ilo_shader_info info;
159
160    struct list_head variants;
161    int num_variants, total_size;
162
163    struct ilo_shader *shader;
164 };
165
166 struct ilo_shader_cache {
167    struct intel_winsys *winsys;
168    struct intel_bo *bo;
169    int cur, size;
170    bool busy;
171
172    /* starting from 1, incremented whenever a new bo is allocated */
173    uint32_t seqno;
174 };
175
176 void
177 ilo_shader_variant_init(struct ilo_shader_variant *variant,
178                         const struct ilo_shader_info *info,
179                         const struct ilo_context *ilo);
180
181 struct ilo_shader_state *
182 ilo_shader_state_create(const struct ilo_context *ilo,
183                         int type, const void *templ);
184
185 void
186 ilo_shader_state_destroy(struct ilo_shader_state *state);
187
188 struct ilo_shader *
189 ilo_shader_state_add_variant(struct ilo_shader_state *state,
190                              const struct ilo_shader_variant *variant);
191
192 bool
193 ilo_shader_state_use_variant(struct ilo_shader_state *state,
194                              const struct ilo_shader_variant *variant);
195
196 struct ilo_shader_cache *
197 ilo_shader_cache_create(struct intel_winsys *winsys);
198
199 void
200 ilo_shader_cache_destroy(struct ilo_shader_cache *shc);
201
202 void
203 ilo_shader_cache_set(struct ilo_shader_cache *shc,
204                      struct ilo_shader **shaders,
205                      int num_shaders);
206
207 static inline void
208 ilo_shader_cache_mark_busy(struct ilo_shader_cache *shc)
209 {
210    if (shc->cur)
211       shc->busy = true;
212 }
213
214 struct ilo_shader *
215 ilo_shader_compile_vs(const struct ilo_shader_state *state,
216                       const struct ilo_shader_variant *variant);
217
218 struct ilo_shader *
219 ilo_shader_compile_gs(const struct ilo_shader_state *state,
220                       const struct ilo_shader_variant *variant);
221
222 bool
223 ilo_shader_compile_gs_passthrough(const struct ilo_shader_state *vs_state,
224                                   const struct ilo_shader_variant *vs_variant,
225                                   const int *so_mapping,
226                                   struct ilo_shader *vs);
227
228 struct ilo_shader *
229 ilo_shader_compile_fs(const struct ilo_shader_state *state,
230                       const struct ilo_shader_variant *variant);
231
232 struct ilo_shader *
233 ilo_shader_compile_cs(const struct ilo_shader_state *state,
234                       const struct ilo_shader_variant *variant);
235
236 static inline void
237 ilo_shader_destroy(struct ilo_shader *sh)
238 {
239    FREE(sh->kernel);
240    FREE(sh);
241 }
242
243 #endif /* ILO_SHADER_H */