1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "util/u_memory.h"
29 #include "util/u_math.h"
30 #include "draw/draw_context.h"
31 #include "draw/draw_private.h"
32 #include "draw/draw_pt.h"
33 #include "translate/translate.h"
34 #include "translate/translate_cache.h"
38 struct draw_context
*draw
;
40 struct translate
*translate
;
44 struct translate_cache
*cache
;
48 /* Perform the fetch from API vertex elements & vertex buffers, to a
49 * contiguous set of float[4] attributes as required for the
50 * vertex_shader->run_linear() method.
52 * This is used in all cases except pure passthrough
53 * (draw_pt_fetch_emit.c) which has its own version to translate
54 * directly to hw vertices.
57 void draw_pt_fetch_prepare( struct pt_fetch
*fetch
,
58 unsigned vs_input_count
,
60 unsigned instance_id_index
)
62 struct draw_context
*draw
= fetch
->draw
;
64 unsigned i
, nr
= 0, ei
= 0;
65 unsigned dst_offset
= 0;
66 unsigned num_extra_inputs
= 0;
67 struct translate_key key
;
69 fetch
->vertex_size
= vertex_size
;
71 /* Leave the clipmask/edgeflags/pad/vertex_id untouched
73 dst_offset
+= 1 * sizeof(float);
74 /* Just leave the clip[] array untouched.
76 dst_offset
+= 4 * sizeof(float);
78 if (instance_id_index
!= ~0) {
82 assert(draw
->pt
.nr_vertex_elements
+ num_extra_inputs
>= vs_input_count
);
84 nr_inputs
= MIN2(vs_input_count
, draw
->pt
.nr_vertex_elements
+ num_extra_inputs
);
86 for (i
= 0; i
< nr_inputs
; i
++) {
87 if (i
== instance_id_index
) {
88 key
.element
[nr
].type
= TRANSLATE_ELEMENT_INSTANCE_ID
;
89 key
.element
[nr
].input_format
= PIPE_FORMAT_R32_USCALED
;
90 key
.element
[nr
].output_format
= PIPE_FORMAT_R32_USCALED
;
91 key
.element
[nr
].output_offset
= dst_offset
;
93 dst_offset
+= sizeof(uint
);
95 key
.element
[nr
].type
= TRANSLATE_ELEMENT_NORMAL
;
96 key
.element
[nr
].input_format
= draw
->pt
.vertex_element
[ei
].src_format
;
97 key
.element
[nr
].input_buffer
= draw
->pt
.vertex_element
[ei
].vertex_buffer_index
;
98 key
.element
[nr
].input_offset
= draw
->pt
.vertex_element
[ei
].src_offset
;
99 key
.element
[nr
].instance_divisor
= draw
->pt
.vertex_element
[ei
].instance_divisor
;
100 key
.element
[nr
].output_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
101 key
.element
[nr
].output_offset
= dst_offset
;
104 dst_offset
+= 4 * sizeof(float);
110 assert(dst_offset
<= vertex_size
);
112 key
.nr_elements
= nr
;
113 key
.output_stride
= vertex_size
;
115 if (!fetch
->translate
||
116 translate_key_compare(&fetch
->translate
->key
, &key
) != 0)
118 translate_key_sanitize(&key
);
119 fetch
->translate
= translate_cache_find(fetch
->cache
, &key
);
127 void draw_pt_fetch_run( struct pt_fetch
*fetch
,
128 const unsigned *elts
,
132 struct draw_context
*draw
= fetch
->draw
;
133 struct translate
*translate
= fetch
->translate
;
136 for (i
= 0; i
< draw
->pt
.nr_vertex_buffers
; i
++) {
137 translate
->set_buffer(translate
,
139 ((char *)draw
->pt
.user
.vbuffer
[i
] +
140 draw
->pt
.vertex_buffer
[i
].buffer_offset
),
141 draw
->pt
.vertex_buffer
[i
].stride
,
145 translate
->run_elts( translate
,
154 void draw_pt_fetch_run_linear( struct pt_fetch
*fetch
,
159 struct draw_context
*draw
= fetch
->draw
;
160 struct translate
*translate
= fetch
->translate
;
163 for (i
= 0; i
< draw
->pt
.nr_vertex_buffers
; i
++) {
164 translate
->set_buffer(translate
,
166 ((char *)draw
->pt
.user
.vbuffer
[i
] +
167 draw
->pt
.vertex_buffer
[i
].buffer_offset
),
168 draw
->pt
.vertex_buffer
[i
].stride
,
169 draw
->pt
.user
.max_index
);
172 translate
->run( translate
,
180 struct pt_fetch
*draw_pt_fetch_create( struct draw_context
*draw
)
182 struct pt_fetch
*fetch
= CALLOC_STRUCT(pt_fetch
);
187 fetch
->cache
= translate_cache_create();
196 void draw_pt_fetch_destroy( struct pt_fetch
*fetch
)
199 translate_cache_destroy(fetch
->cache
);