1 /*
2 * Copyright (c) 2012-2015 Etnaviv Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Wladimir J. van der Laan <[email protected]>
25 */
26
27 #ifndef H_ETNAVIV_SHADER
28 #define H_ETNAVIV_SHADER
29
30 #include "mesa/main/config.h"
31 #include "etna_core_info.h"
32 #include "nir.h"
33 #include "pipe/p_state.h"
34 #include "util/disk_cache.h"
35 #include "util/u_queue.h"
36
37 struct etna_context;
38 struct etna_shader_variant;
39 struct nir_shader;
40
41 struct etna_shader_key
42 {
43 union {
44 struct {
45 /*
46 * Combined Vertex/Fragment shader parameters:
47 */
48
49 /* do we need to swap rb in frag color? */
50 unsigned frag_rb_swap : 1;
51 /* do we need to invert front facing value? */
52 unsigned front_ccw : 1;
53 /* do we need to replace glTexCoord.xy ? */
54 unsigned sprite_coord_enable : MAX_TEXTURE_COORD_UNITS;
55 unsigned sprite_coord_yinvert : 1;
56 /* do we need to lower sample_tex_compare */
57 unsigned has_sample_tex_compare : 1;
58 };
59 uint32_t global;
60 };
61
62 int num_texture_states;
63 nir_lower_tex_shadow_swizzle tex_swizzle[16];
64 enum compare_func tex_compare_func[16];
65 };
66
67 static inline bool
etna_shader_key_equal(const struct etna_shader_key * const a,const struct etna_shader_key * const b)68 etna_shader_key_equal(const struct etna_shader_key* const a,
69 const struct etna_shader_key* const b)
70 {
71 /* slow-path if we need to check tex_{swizzle,compare_func} */
72 if (unlikely(a->has_sample_tex_compare || b->has_sample_tex_compare))
73 return memcmp(a, b, sizeof(struct etna_shader_key)) == 0;
74 else
75 return a->global == b->global;
76 }
77
78 struct etna_shader {
79 /* shader id (for debug): */
80 uint32_t id;
81 uint32_t variant_count;
82
83 struct nir_shader *nir;
84 const struct etna_core_info *info;
85 const struct etna_specs *specs;
86 struct etna_compiler *compiler;
87
88 struct etna_shader_variant *variants;
89
90 cache_key cache_key; /* shader disk-cache key */
91
92 /* parallel shader compiles */
93 struct util_queue_fence ready;
94 };
95
96 bool
97 etna_shader_link(struct etna_context *ctx);
98
99 bool
100 etna_shader_update_vertex(struct etna_context *ctx);
101
102 struct etna_shader_variant *
103 etna_shader_variant(struct etna_shader *shader,
104 const struct etna_shader_key* const key,
105 struct util_debug_callback *debug,
106 bool called_from_draw);
107
108 void
109 etna_shader_init(struct pipe_context *pctx);
110
111 bool
112 etna_shader_screen_init(struct pipe_screen *pscreen);
113
114 void
115 etna_shader_screen_fini(struct pipe_screen *pscreen);
116
117 #endif
118