1 /*
2 * Copyright 2020 Mike Blumenkrantz
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 /** this file exists for organization and to be included in nir_to_spirv/ without pulling in extra deps */
26 #ifndef ZINK_SHADER_KEYS_H
27 # define ZINK_SHADER_KEYS_H
28
29 #include "compiler/shader_info.h"
30
31 struct zink_vs_key_base {
32 bool clip_halfz;
33 bool push_drawid;
34 bool last_vertex_stage;
35 };
36
37 struct zink_vs_key {
38 struct zink_vs_key_base base;
39 uint8_t pad;
40 union {
41 struct {
42 uint32_t decomposed_attrs;
43 uint32_t decomposed_attrs_without_w;
44 } u32;
45 struct {
46 uint16_t decomposed_attrs;
47 uint16_t decomposed_attrs_without_w;
48 } u16;
49 struct {
50 uint8_t decomposed_attrs;
51 uint8_t decomposed_attrs_without_w;
52 } u8;
53 };
54 // not hashed
55 unsigned size;
56 };
57
58 struct zink_fs_key {
59 uint8_t coord_replace_bits;
60 bool coord_replace_yinvert;
61 bool samples;
62 bool force_dual_color_blend;
63 bool force_persample_interp;
64 bool fbfetch_ms;
65 };
66
67 struct zink_tcs_key {
68 uint8_t patch_vertices;
69 };
70
71 struct zink_shader_key_base {
72 uint32_t nonseamless_cube_mask;
73 uint32_t inlined_uniform_values[MAX_INLINABLE_UNIFORMS];
74 };
75
76 /* a shader key is used for swapping out shader modules based on pipeline states,
77 * e.g., if sampleCount changes, we must verify that the fs doesn't need a recompile
78 * to account for GL ignoring gl_SampleMask in some cases when VK will not
79 * which allows us to avoid recompiling shaders when the pipeline state changes repeatedly
80 */
81 struct zink_shader_key {
82 union {
83 /* reuse vs key for now with tes/gs since we only use clip_halfz */
84 struct zink_vs_key vs;
85 struct zink_vs_key_base vs_base;
86 struct zink_tcs_key tcs;
87 struct zink_fs_key fs;
88 } key;
89 struct zink_shader_key_base base;
90 unsigned inline_uniforms:1;
91 uint32_t size;
92 };
93
94 static inline const struct zink_fs_key *
zink_fs_key(const struct zink_shader_key * key)95 zink_fs_key(const struct zink_shader_key *key)
96 {
97 assert(key);
98 return &key->key.fs;
99 }
100
101 static inline const struct zink_vs_key_base *
zink_vs_key_base(const struct zink_shader_key * key)102 zink_vs_key_base(const struct zink_shader_key *key)
103 {
104 return &key->key.vs_base;
105 }
106
107 static inline const struct zink_vs_key *
zink_vs_key(const struct zink_shader_key * key)108 zink_vs_key(const struct zink_shader_key *key)
109 {
110 assert(key);
111 return &key->key.vs;
112 }
113
114 static inline const struct zink_tcs_key *
zink_tcs_key(const struct zink_shader_key * key)115 zink_tcs_key(const struct zink_shader_key *key)
116 {
117 assert(key);
118 return &key->key.tcs;
119 }
120
121
122
123 #endif
124