Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 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 
26
 */
27
 
28
#ifndef ILO_SHADER_INTERNAL_H
29
#define ILO_SHADER_INTERNAL_H
30
 
31
#include "ilo_common.h"
32
#include "ilo_state.h"
33
#include "ilo_shader.h"
34
 
35
/* XXX The interface needs to be reworked */
36
 
37
/**
38
 * A shader variant.  It consists of non-orthogonal states of the pipe context
39
 * affecting the compilation of a shader.
40
 */
41
struct ilo_shader_variant {
42
   union {
43
      struct {
44
         bool rasterizer_discard;
45
         int num_ucps;
46
      } vs;
47
 
48
      struct {
49
         bool rasterizer_discard;
50
         int num_inputs;
51
         int semantic_names[PIPE_MAX_SHADER_INPUTS];
52
         int semantic_indices[PIPE_MAX_SHADER_INPUTS];
53
      } gs;
54
 
55
      struct {
56
         bool flatshade;
57
         int fb_height;
58
         int num_cbufs;
59
      } fs;
60
   } u;
61
 
62
   bool use_pcb;
63
 
64
   int num_sampler_views;
65
   struct {
66
      unsigned r:3;
67
      unsigned g:3;
68
      unsigned b:3;
69
      unsigned a:3;
70
   } sampler_view_swizzles[ILO_MAX_SAMPLER_VIEWS];
71
 
72
   uint32_t saturate_tex_coords[3];
73
};
74
 
75
/**
76
 * A compiled shader.
77
 */
78
struct ilo_shader {
79
   struct ilo_shader_variant variant;
80
 
81
   struct ilo_shader_cso cso;
82
 
83
   struct {
84
      int semantic_names[PIPE_MAX_SHADER_INPUTS];
85
      int semantic_indices[PIPE_MAX_SHADER_INPUTS];
86
      int interp[PIPE_MAX_SHADER_INPUTS];
87
      bool centroid[PIPE_MAX_SHADER_INPUTS];
88
      int count;
89
 
90
      int start_grf;
91
      bool has_pos;
92
      bool has_linear_interp;
93
      int barycentric_interpolation_mode;
94
      uint32_t const_interp_enable;
95
      bool discard_adj;
96
   } in;
97
 
98
   struct {
99
      int register_indices[PIPE_MAX_SHADER_OUTPUTS];
100
      int semantic_names[PIPE_MAX_SHADER_OUTPUTS];
101
      int semantic_indices[PIPE_MAX_SHADER_OUTPUTS];
102
      int count;
103
 
104
      bool has_pos;
105
   } out;
106
 
107
   bool skip_cbuf0_upload;
108
 
109
   bool has_kill;
110
   bool dispatch_16;
111
 
112
   bool stream_output;
113
   int svbi_post_inc;
114
   struct pipe_stream_output_info so_info;
115
 
116
   /* for VS stream output / rasterizer discard */
117
   int gs_offsets[3];
118
   int gs_start_grf;
119
   int gs_bt_so_count;
120
 
121
   void *kernel;
122
   int kernel_size;
123
 
124
   bool routing_initialized;
125
   int routing_src_semantics[PIPE_MAX_SHADER_OUTPUTS];
126
   int routing_src_indices[PIPE_MAX_SHADER_OUTPUTS];
127
   uint32_t routing_sprite_coord_enable;
128
   struct ilo_kernel_routing routing;
129
 
130
   /* what does the push constant buffer consist of? */
131
   struct {
132
      int cbuf0_size;
133
      int clip_state_size;
134
   } pcb;
135
 
136
   /* binding table */
137
   struct {
138
      int rt_base, rt_count;
139
      int tex_base, tex_count;
140
      int const_base, const_count;
141
      int res_base, res_count;
142
 
143
      int gen6_so_base, gen6_so_count;
144
 
145
      int global_base, global_count;
146
 
147
      int total_count;
148
   } bt;
149
 
150
   struct list_head list;
151
 
152
   /* managed by shader cache */
153
   bool uploaded;
154
   uint32_t cache_offset;
155
};
156
 
157
/**
158
 * Information about a shader state.
159
 */
160
struct ilo_shader_info {
161
   const struct ilo_dev *dev;
162
   int type;
163
 
164
   const struct tgsi_token *tokens;
165
 
166
   struct pipe_stream_output_info stream_output;
167
   struct {
168
      unsigned req_local_mem;
169
      unsigned req_private_mem;
170
      unsigned req_input_mem;
171
   } compute;
172
 
173
   uint32_t non_orthogonal_states;
174
 
175
   bool has_color_interp;
176
   bool has_pos;
177
   bool has_vertexid;
178
   bool has_instanceid;
179
   bool fs_color0_writes_all_cbufs;
180
 
181
   int edgeflag_in;
182
   int edgeflag_out;
183
 
184
   uint32_t shadow_samplers;
185
   int num_samplers;
186
 
187
   int constant_buffer_count;
188
};
189
 
190
/**
191
 * A shader state.
192
 */
193
struct ilo_shader_state {
194
   struct ilo_shader_info info;
195
 
196
   struct list_head variants;
197
   int num_variants, total_size;
198
 
199
   struct ilo_shader *shader;
200
 
201
   /* managed by shader cache */
202
   struct ilo_shader_cache *cache;
203
   struct list_head list;
204
};
205
 
206
void
207
ilo_shader_variant_init(struct ilo_shader_variant *variant,
208
                        const struct ilo_shader_info *info,
209
                        const struct ilo_state_vector *vec);
210
 
211
bool
212
ilo_shader_state_use_variant(struct ilo_shader_state *state,
213
                             const struct ilo_shader_variant *variant);
214
 
215
struct ilo_shader *
216
ilo_shader_compile_vs(const struct ilo_shader_state *state,
217
                      const struct ilo_shader_variant *variant);
218
 
219
struct ilo_shader *
220
ilo_shader_compile_gs(const struct ilo_shader_state *state,
221
                      const struct ilo_shader_variant *variant);
222
 
223
bool
224
ilo_shader_compile_gs_passthrough(const struct ilo_shader_state *vs_state,
225
                                  const struct ilo_shader_variant *vs_variant,
226
                                  const int *so_mapping,
227
                                  struct ilo_shader *vs);
228
 
229
struct ilo_shader *
230
ilo_shader_compile_fs(const struct ilo_shader_state *state,
231
                      const struct ilo_shader_variant *variant);
232
 
233
struct ilo_shader *
234
ilo_shader_compile_cs(const struct ilo_shader_state *state,
235
                      const struct ilo_shader_variant *variant);
236
 
237
static inline void
238
ilo_shader_destroy_kernel(struct ilo_shader *sh)
239
{
240
   FREE(sh->kernel);
241
   FREE(sh);
242
}
243
 
244
#endif /* ILO_SHADER_INTERNAL_H */