2 * Copyright 2009 Maciej Cencora <m.cencora@gmail.com>
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:
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
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.
24 /* r300_vbo: Various helpers for emitting vertex buffers. Needs cleanup,
25 * refactoring, etc. */
29 #include "pipe/p_format.h"
32 #include "r300_context.h"
33 #include "r300_state_inlines.h"
35 #include "r300_winsys.h"
37 static INLINE
void setup_vertex_attribute(struct r300_vertex_info
*vinfo
,
38 struct pipe_vertex_element
*vert_elem
,
41 uint16_t hw_fmt1
, hw_fmt2
;
43 hw_fmt1
= r300_translate_vertex_data_type(vert_elem
->src_format
) |
44 (attr_num
<< R300_DST_VEC_LOC_SHIFT
);
45 hw_fmt2
= r300_translate_vertex_data_swizzle(vert_elem
->src_format
);
47 if (attr_num
% 2 == 0)
49 vinfo
->vap_prog_stream_cntl
[attr_num
>> 1] = hw_fmt1
;
50 vinfo
->vap_prog_stream_cntl_ext
[attr_num
>> 1] = hw_fmt2
;
54 vinfo
->vap_prog_stream_cntl
[attr_num
>> 1] |= hw_fmt1
<< 16;
55 vinfo
->vap_prog_stream_cntl_ext
[attr_num
>> 1] |= hw_fmt2
<< 16;
59 static void finish_vertex_attribs_setup(struct r300_vertex_info
*vinfo
,
62 uint32_t last_vec_bit
= (attribs_num
% 2 == 0) ?
63 (R300_LAST_VEC
<< 16) : R300_LAST_VEC
;
65 assert(attribs_num
> 0 && attribs_num
<= 16);
66 vinfo
->vap_prog_stream_cntl
[(attribs_num
- 1) >> 1] |= last_vec_bit
;
69 void setup_vertex_attributes(struct r300_context
*r300
)
71 struct pipe_vertex_element
*vert_elem
;
74 for (i
= 0; i
< r300
->vertex_element_count
; i
++) {
75 vert_elem
= &r300
->vertex_element
[i
];
76 setup_vertex_attribute(r300
->vertex_info
, vert_elem
, i
);
79 finish_vertex_attribs_setup(r300
->vertex_info
,
80 r300
->vertex_element_count
);
83 static INLINE
int get_buffer_offset(struct r300_context
*r300
,
85 unsigned int elem_offset
)
87 return r300
->vertex_buffer
[buf_nr
].buffer_offset
+ elem_offset
;
90 /* XXX not called at all */
91 static void setup_vertex_buffers(struct r300_context
*r300
)
93 struct pipe_vertex_element
*vert_elem
;
96 for (i
= 0; i
< r300
->aos_count
; i
++)
98 vert_elem
= &r300
->vertex_element
[i
];
99 /* XXX use translate module to convert the data */
100 if (!format_is_supported(vert_elem
->src_format
,
101 vert_elem
->nr_components
)) {
104 struct pipe_buffer *buf;
105 const unsigned int max_index = r300->vertex_buffers[vert_elem->vertex_buffer_index].max_index;
106 buf = pipe_buffer_create(r300->context.screen, 4, usage, vert_elem->nr_components * max_index * sizeof(float));
110 if (get_buffer_offset(r300
,
111 vert_elem
->vertex_buffer_index
,
112 vert_elem
->src_offset
) % 4) {
113 /* XXX need to align buffer */
119 /* XXX these shouldn't be asserts since we can work around bad indexbufs */
120 void setup_index_buffer(struct r300_context
*r300
,
121 struct pipe_buffer
* indexBuffer
,
124 if (!r300
->winsys
->add_buffer(r300
->winsys
, indexBuffer
,
125 RADEON_GEM_DOMAIN_GTT
, 0)) {
129 if (!r300
->winsys
->validate(r300
->winsys
)) {