2 * Copyright 2008 VMware, Inc.
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:
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
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.
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.
36 * Keith Whitwell <keithw@vmware.com>
43 #include "pipe/p_compiler.h"
44 #include "pipe/p_format.h"
45 #include "pipe/p_state.h"
48 * Translate has to work on one more attribute because
49 * the draw module has to be able to pass the vertex
50 * position even if the fragment shader already consumes
51 * PIPE_MAX_ATTRIBS inputs.
53 #define TRANSLATE_MAX_ATTRIBS (PIPE_MAX_ATTRIBS + 1)
55 enum translate_element_type
{
56 TRANSLATE_ELEMENT_NORMAL
,
57 TRANSLATE_ELEMENT_INSTANCE_ID
60 struct translate_element
62 enum translate_element_type type
;
63 enum pipe_format input_format
;
64 enum pipe_format output_format
;
65 unsigned input_buffer
:8;
66 unsigned input_offset
:24;
67 unsigned instance_divisor
;
68 unsigned output_offset
;
72 struct translate_key
{
73 unsigned output_stride
;
75 struct translate_element element
[TRANSLATE_MAX_ATTRIBS
];
82 typedef void (PIPE_CDECL
*run_elts_func
)(struct translate
*,
85 unsigned start_instance
,
89 typedef void (PIPE_CDECL
*run_elts16_func
)(struct translate
*,
92 unsigned start_instance
,
96 typedef void (PIPE_CDECL
*run_elts8_func
)(struct translate
*,
99 unsigned start_instance
,
100 unsigned instance_id
,
101 void *output_buffer
);
103 typedef void (PIPE_CDECL
*run_func
)(struct translate
*,
106 unsigned start_instance
,
107 unsigned instance_id
,
108 void *output_buffer
);
111 struct translate_key key
;
113 void (*release
)( struct translate
* );
115 void (*set_buffer
)( struct translate
*,
119 unsigned max_index
);
121 run_elts_func run_elts
;
122 run_elts16_func run_elts16
;
123 run_elts8_func run_elts8
;
129 struct translate
*translate_create( const struct translate_key
*key
);
131 boolean
translate_is_output_format_supported(enum pipe_format format
);
133 static inline int translate_keysize( const struct translate_key
*key
)
135 return 2 * sizeof(int) + key
->nr_elements
* sizeof(struct translate_element
);
138 static inline int translate_key_compare( const struct translate_key
*a
,
139 const struct translate_key
*b
)
141 int keysize_a
= translate_keysize(a
);
142 int keysize_b
= translate_keysize(b
);
144 if (keysize_a
!= keysize_b
) {
145 return keysize_a
- keysize_b
;
147 return memcmp(a
, b
, keysize_a
);
151 static inline void translate_key_sanitize( struct translate_key
*a
)
153 int keysize
= translate_keysize(a
);
154 char *ptr
= (char *)a
;
155 memset(ptr
+ keysize
, 0, sizeof(*a
) - keysize
);
159 /*******************************************************************************
162 struct translate
*translate_sse2_create( const struct translate_key
*key
);
164 struct translate
*translate_generic_create( const struct translate_key
*key
);
166 boolean
translate_generic_is_output_format_supported(enum pipe_format format
);