st/nine: Enforce centroid for color input when multisampling is on
[mesa.git] / src / gallium / state_trackers / nine / nine_shader.h
1 /*
2 * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
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 #ifndef _NINE_SHADER_H_
24 #define _NINE_SHADER_H_
25
26 #include "d3d9types.h"
27 #include "d3d9caps.h"
28 #include "nine_defines.h"
29 #include "pipe/p_state.h" /* PIPE_MAX_ATTRIBS */
30 #include "util/u_memory.h"
31
32 struct NineDevice9;
33
34 struct nine_lconstf /* NOTE: both pointers should be FREE'd by the user */
35 {
36 struct nine_range *ranges; /* single MALLOC, but next-pointers valid */
37 float *data;
38 };
39
40 struct nine_shader_info
41 {
42 unsigned type; /* in, PIPE_SHADER_x */
43
44 uint8_t version; /* (major << 4) | minor */
45
46 const DWORD *byte_code; /* in, pointer to shader tokens */
47 DWORD byte_size; /* out, size of data at byte_code */
48
49 void *cso; /* out, pipe cso for bind_vs,fs_state */
50
51 uint16_t input_map[PIPE_MAX_ATTRIBS]; /* VS input -> NINE_DECLUSAGE_x */
52 uint8_t num_inputs; /* there may be unused inputs (NINE_DECLUSAGE_NONE) */
53
54 boolean position_t; /* out, true if VP writes pre-transformed position */
55 boolean point_size; /* out, true if VP writes point size */
56
57 uint32_t sampler_ps1xtypes; /* 2 bits per sampler */
58 uint16_t sampler_mask; /* out, which samplers are being used */
59 uint16_t sampler_mask_shadow; /* in, which samplers use depth compare */
60 uint8_t rt_mask; /* out, which render targets are being written */
61
62 uint8_t fog_enable;
63 uint8_t fog_mode;
64 uint8_t force_color_in_centroid;
65 uint16_t projected; /* ps 1.1 to 1.3 */
66
67 unsigned const_i_base; /* in vec4 (16 byte) units */
68 unsigned const_b_base; /* in vec4 (16 byte) units */
69 unsigned const_used_size;
70
71 unsigned const_float_slots;
72 unsigned const_int_slots;
73 unsigned const_bool_slots;
74
75 struct nine_lconstf lconstf; /* out, NOTE: members to be free'd by user */
76 uint8_t bumpenvmat_needed;
77 };
78
79 static inline void
80 nine_info_mark_const_f_used(struct nine_shader_info *info, int idx)
81 {
82 if (info->const_float_slots < (idx + 1))
83 info->const_float_slots = idx + 1;
84 }
85 static inline void
86 nine_info_mark_const_i_used(struct nine_shader_info *info, int idx)
87 {
88 if (info->const_int_slots < (idx + 1))
89 info->const_int_slots = idx + 1;
90 }
91 static inline void
92 nine_info_mark_const_b_used(struct nine_shader_info *info, int idx)
93 {
94 if (info->const_bool_slots < (idx + 1))
95 info->const_bool_slots = idx + 1;
96 }
97
98 HRESULT
99 nine_translate_shader(struct NineDevice9 *device, struct nine_shader_info *);
100
101
102 struct nine_shader_variant
103 {
104 struct nine_shader_variant *next;
105 void *cso;
106 uint32_t key;
107 };
108
109 static inline void *
110 nine_shader_variant_get(struct nine_shader_variant *list, uint32_t key)
111 {
112 while (list->key != key && list->next)
113 list = list->next;
114 if (list->key == key)
115 return list->cso;
116 return NULL;
117 }
118
119 static inline boolean
120 nine_shader_variant_add(struct nine_shader_variant *list,
121 uint32_t key, void *cso)
122 {
123 while (list->next) {
124 assert(list->key != key);
125 list = list->next;
126 }
127 list->next = MALLOC_STRUCT(nine_shader_variant);
128 if (!list->next)
129 return FALSE;
130 list->next->next = NULL;
131 list->next->key = key;
132 list->next->cso = cso;
133 return TRUE;
134 }
135
136 static inline void
137 nine_shader_variants_free(struct nine_shader_variant *list)
138 {
139 while (list->next) {
140 struct nine_shader_variant *ptr = list->next;
141 list->next = ptr->next;
142 FREE(ptr);
143 }
144 }
145
146 struct nine_shader_variant64
147 {
148 struct nine_shader_variant64 *next;
149 void *cso;
150 uint64_t key;
151 };
152
153 static inline void *
154 nine_shader_variant_get64(struct nine_shader_variant64 *list, uint64_t key)
155 {
156 while (list->key != key && list->next)
157 list = list->next;
158 if (list->key == key)
159 return list->cso;
160 return NULL;
161 }
162
163 static inline boolean
164 nine_shader_variant_add64(struct nine_shader_variant64 *list,
165 uint64_t key, void *cso)
166 {
167 while (list->next) {
168 assert(list->key != key);
169 list = list->next;
170 }
171 list->next = MALLOC_STRUCT(nine_shader_variant64);
172 if (!list->next)
173 return FALSE;
174 list->next->next = NULL;
175 list->next->key = key;
176 list->next->cso = cso;
177 return TRUE;
178 }
179
180 static inline void
181 nine_shader_variants_free64(struct nine_shader_variant64 *list)
182 {
183 while (list->next) {
184 struct nine_shader_variant64 *ptr = list->next;
185 list->next = ptr->next;
186 FREE(ptr);
187 }
188 }
189
190 #endif /* _NINE_SHADER_H_ */