st/nine: Fix vertex declarations for non-standard (usage/index)
[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 unsigned const_i_base; /* in vec4 (16 byte) units */
63 unsigned const_b_base; /* in vec4 (16 byte) units */
64 unsigned const_used_size;
65
66 struct nine_lconstf lconstf; /* out, NOTE: members to be free'd by user */
67 };
68
69 static INLINE void
70 nine_info_mark_const_f_used(struct nine_shader_info *info, int idx)
71 {
72 unsigned size = (idx + 1) * 16;
73
74 if (info->const_used_size < size)
75 info->const_used_size = size;
76 }
77 static INLINE void
78 nine_info_mark_const_i_used(struct nine_shader_info *info, int idx)
79 {
80 unsigned size = (info->const_i_base + (idx + 1)) * 16;
81
82 if (info->const_used_size < size)
83 info->const_used_size = size;
84 }
85 static INLINE void
86 nine_info_mark_const_b_used(struct nine_shader_info *info, int idx)
87 {
88 unsigned size = (info->const_b_base + ((idx + 4) / 4)) * 16;
89
90 if (info->const_used_size < size)
91 info->const_used_size = size;
92 }
93
94 HRESULT
95 nine_translate_shader(struct NineDevice9 *device, struct nine_shader_info *);
96
97
98 struct nine_shader_variant
99 {
100 struct nine_shader_variant *next;
101 void *cso;
102 uint32_t key;
103 };
104
105 static INLINE void *
106 nine_shader_variant_get(struct nine_shader_variant *list, uint32_t key)
107 {
108 while (list->key != key && list->next)
109 list = list->next;
110 if (list->key == key)
111 return list->cso;
112 return NULL;
113 }
114
115 static INLINE boolean
116 nine_shader_variant_add(struct nine_shader_variant *list,
117 uint32_t key, void *cso)
118 {
119 while (list->next) {
120 assert(list->key != key);
121 list = list->next;
122 }
123 list->next = MALLOC_STRUCT(nine_shader_variant);
124 if (!list->next)
125 return FALSE;
126 list->next->next = NULL;
127 list->next->key = key;
128 list->next->cso = cso;
129 return TRUE;
130 }
131
132 static INLINE void
133 nine_shader_variants_free(struct nine_shader_variant *list)
134 {
135 while (list->next) {
136 struct nine_shader_variant *ptr = list->next;
137 list->next = ptr->next;
138 FREE(ptr);
139 }
140 }
141
142 #endif /* _NINE_SHADER_H_ */