summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/ilo/ilo_shader.h
blob: 9318785adbd700ba0e37535ee1ecb0645f7562ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
 * Mesa 3-D graphics library
 *
 * Copyright (C) 2012-2013 LunarG, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Chia-I Wu <olv@lunarg.com>
 */

#ifndef ILO_SHADER_H
#define ILO_SHADER_H

#include "ilo_common.h"
#include "ilo_context.h"

struct ilo_shader_cache;

/* XXX The interface needs to be reworked */

/**
 * A shader variant.  It consists of non-orthogonal states of the pipe context
 * affecting the compilation of a shader.
 */
struct ilo_shader_variant {
   union {
      struct {
         bool rasterizer_discard;
         int num_ucps;
      } vs;

      struct {
         bool rasterizer_discard;
         int num_inputs;
         int semantic_names[PIPE_MAX_SHADER_INPUTS];
         int semantic_indices[PIPE_MAX_SHADER_INPUTS];
      } gs;

      struct {
         bool flatshade;
         int fb_height;
         int num_cbufs;
      } fs;
   } u;

   int num_sampler_views;
   struct {
      unsigned r:3;
      unsigned g:3;
      unsigned b:3;
      unsigned a:3;
   } sampler_view_swizzles[ILO_MAX_SAMPLER_VIEWS];

   uint32_t saturate_tex_coords[3];
};

/**
 * A compiled shader.
 */
struct ilo_shader {
   struct ilo_shader_variant variant;

   struct {
      int semantic_names[PIPE_MAX_SHADER_INPUTS];
      int semantic_indices[PIPE_MAX_SHADER_INPUTS];
      int interp[PIPE_MAX_SHADER_INPUTS];
      bool centroid[PIPE_MAX_SHADER_INPUTS];
      int count;

      int start_grf;
      bool has_pos;
      bool has_linear_interp;
      int barycentric_interpolation_mode;
      bool discard_adj;
   } in;

   struct {
      int register_indices[PIPE_MAX_SHADER_OUTPUTS];
      int semantic_names[PIPE_MAX_SHADER_OUTPUTS];
      int semantic_indices[PIPE_MAX_SHADER_OUTPUTS];
      int count;

      bool has_pos;
   } out;

   bool has_kill;
   bool dispatch_16;

   bool stream_output;
   int svbi_post_inc;
   /* for VS stream output / rasterizer discard */
   int gs_offsets[3];
   int gs_start_grf;

   void *kernel;
   int kernel_size;

   /* what does the push constant buffer consist of? */
   struct {
      int clip_state_size;
   } pcb;

   struct list_head list;

   /* managed by shader cache */
   bool uploaded;
   uint32_t cache_offset;
};

/**
 * Information about a shader state.
 */
struct ilo_shader_info {
   const struct ilo_dev_info *dev;
   int type;

   const struct tgsi_token *tokens;

   struct pipe_stream_output_info stream_output;
   struct {
      unsigned req_local_mem;
      unsigned req_private_mem;
      unsigned req_input_mem;
   } compute;

   bool has_color_interp;
   bool has_pos;
   bool has_vertexid;
   bool has_instanceid;
   bool fs_color0_writes_all_cbufs;

   int edgeflag_in;
   int edgeflag_out;

   uint32_t shadow_samplers;
   int num_samplers;
};

/**
 * A shader state.
 */
struct ilo_shader_state {
   struct ilo_shader_info info;

   struct list_head variants;
   int num_variants, total_size;

   struct ilo_shader *shader;

   /* managed by shader cache */
   struct ilo_shader_cache *cache;
   struct list_head list;
};

struct ilo_shader_cache *
ilo_shader_cache_create(void);

void
ilo_shader_cache_destroy(struct ilo_shader_cache *shc);

void
ilo_shader_cache_add(struct ilo_shader_cache *shc,
                     struct ilo_shader_state *shader);

void
ilo_shader_cache_remove(struct ilo_shader_cache *shc,
                        struct ilo_shader_state *shader);

int
ilo_shader_cache_upload(struct ilo_shader_cache *shc,
                        struct intel_bo *bo, unsigned offset,
                        bool incremental);

void
ilo_shader_variant_init(struct ilo_shader_variant *variant,
                        const struct ilo_shader_info *info,
                        const struct ilo_context *ilo);

struct ilo_shader_state *
ilo_shader_state_create(const struct ilo_context *ilo,
                        int type, const void *templ);

void
ilo_shader_state_destroy(struct ilo_shader_state *state);

struct ilo_shader *
ilo_shader_state_add_variant(struct ilo_shader_state *state,
                             const struct ilo_shader_variant *variant);

bool
ilo_shader_state_use_variant(struct ilo_shader_state *state,
                             const struct ilo_shader_variant *variant);

struct ilo_shader *
ilo_shader_compile_vs(const struct ilo_shader_state *state,
                      const struct ilo_shader_variant *variant);

struct ilo_shader *
ilo_shader_compile_gs(const struct ilo_shader_state *state,
                      const struct ilo_shader_variant *variant);

bool
ilo_shader_compile_gs_passthrough(const struct ilo_shader_state *vs_state,
                                  const struct ilo_shader_variant *vs_variant,
                                  const int *so_mapping,
                                  struct ilo_shader *vs);

struct ilo_shader *
ilo_shader_compile_fs(const struct ilo_shader_state *state,
                      const struct ilo_shader_variant *variant);

struct ilo_shader *
ilo_shader_compile_cs(const struct ilo_shader_state *state,
                      const struct ilo_shader_variant *variant);

static inline void
ilo_shader_destroy(struct ilo_shader *sh)
{
   FREE(sh->kernel);
   FREE(sh);
}

#endif /* ILO_SHADER_H */