1 /*
2 * Copyright 2008 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * Vertex fetch/store/convert code. This functionality is used in two places:
28 * 1. Vertex fetch/convert - to grab vertex data from incoming vertex
29 * arrays and convert to format needed by vertex shaders.
30 * 2. Vertex store/emit - to convert simple float[][4] vertex attributes
31 * (which is the organization used throughout the draw/prim pipeline) to
32 * hardware-specific formats and emit into hardware vertex buffers.
33 *
34 *
35 * Authors:
36 * Keith Whitwell <keithw@vmware.com>
37 */
38
39 #ifndef _TRANSLATE_H
40 #define _TRANSLATE_H
41
42
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_format.h"
45 #include "pipe/p_state.h"
46
47 /**
48 * Translate has to work on two more attributes because
49 * the draw module has to be able to pass a few fixed
50 * function vertex shader outputs even if the fragment
51 * shader already consumes PIPE_MAX_ATTRIBS inputs.
52 *
53 * These vertex shader outputs include:
54 * - position
55 * - bcolor (up to two)
56 * - point-size
57 * - viewport index
58 * - layer
59 */
60 #define TRANSLATE_MAX_ATTRIBS (PIPE_MAX_ATTRIBS + 6)
61
62 enum translate_element_type {
63 TRANSLATE_ELEMENT_NORMAL,
64 TRANSLATE_ELEMENT_INSTANCE_ID
65 };
66
67 struct translate_element
68 {
69 enum translate_element_type type;
70 enum pipe_format input_format;
71 enum pipe_format output_format;
72 unsigned input_buffer:8;
73 unsigned input_offset:24;
74 unsigned instance_divisor;
75 unsigned output_offset;
76 };
77
78
79 struct translate_key {
80 unsigned output_stride;
81 unsigned nr_elements;
82 struct translate_element element[TRANSLATE_MAX_ATTRIBS];
83 };
84
85
86 struct translate;
87
88
89 typedef void (PIPE_CDECL *run_elts_func)(struct translate *,
90 const unsigned *elts,
91 unsigned count,
92 unsigned start_instance,
93 unsigned instance_id,
94 void *output_buffer);
95
96 typedef void (PIPE_CDECL *run_elts16_func)(struct translate *,
97 const uint16_t *elts,
98 unsigned count,
99 unsigned start_instance,
100 unsigned instance_id,
101 void *output_buffer);
102
103 typedef void (PIPE_CDECL *run_elts8_func)(struct translate *,
104 const uint8_t *elts,
105 unsigned count,
106 unsigned start_instance,
107 unsigned instance_id,
108 void *output_buffer);
109
110 typedef void (PIPE_CDECL *run_func)(struct translate *,
111 unsigned start,
112 unsigned count,
113 unsigned start_instance,
114 unsigned instance_id,
115 void *output_buffer);
116
117 struct translate {
118 struct translate_key key;
119
120 void (*release)( struct translate * );
121
122 void (*set_buffer)( struct translate *,
123 unsigned i,
124 const void *ptr,
125 unsigned stride,
126 unsigned max_index );
127
128 run_elts_func run_elts;
129 run_elts16_func run_elts16;
130 run_elts8_func run_elts8;
131 run_func run;
132 };
133
134
135
136 struct translate *translate_create( const struct translate_key *key );
137
138 boolean translate_is_output_format_supported(enum pipe_format format);
139
translate_keysize(const struct translate_key * key)140 static inline int translate_keysize( const struct translate_key *key )
141 {
142 assert(key->nr_elements <= TRANSLATE_MAX_ATTRIBS);
143 return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element);
144 }
145
translate_key_compare(const struct translate_key * a,const struct translate_key * b)146 static inline int translate_key_compare( const struct translate_key *a,
147 const struct translate_key *b )
148 {
149 int keysize_a = translate_keysize(a);
150 int keysize_b = translate_keysize(b);
151
152 if (keysize_a != keysize_b) {
153 return keysize_a - keysize_b;
154 }
155 return memcmp(a, b, keysize_a);
156 }
157
158
translate_key_sanitize(struct translate_key * a)159 static inline void translate_key_sanitize( struct translate_key *a )
160 {
161 int keysize = translate_keysize(a);
162 char *ptr = (char *)a;
163 memset(ptr + keysize, 0, sizeof(*a) - keysize);
164 }
165
166
167 /*******************************************************************************
168 * Private:
169 */
170 struct translate *translate_sse2_create( const struct translate_key *key );
171
172 struct translate *translate_generic_create( const struct translate_key *key );
173
174 boolean translate_generic_is_output_format_supported(enum pipe_format format);
175
176 #endif
177