gallium: fix reference counting functions to be strict-aliasing compliant
[mesa.git] / src / gallium / drivers / r300 / r300_vbo.c
1 /*
2 * Copyright 2009 Maciej Cencora <m.cencora@gmail.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
24 /* r300_vbo: Various helpers for emitting vertex buffers. Needs cleanup,
25 * refactoring, etc. */
26
27 #include "r300_vbo.h"
28
29 #include "pipe/p_format.h"
30
31 #include "r300_cs.h"
32 #include "r300_context.h"
33 #include "r300_state_inlines.h"
34 #include "r300_reg.h"
35
36 #include "radeon_winsys.h"
37
38 static INLINE int get_buffer_offset(struct r300_context *r300,
39 unsigned int buf_nr,
40 unsigned int elem_offset)
41 {
42 return r300->vertex_buffer[buf_nr].buffer_offset + elem_offset;
43 }
44 #if 0
45 /* XXX not called at all */
46 static void setup_vertex_buffers(struct r300_context *r300)
47 {
48 struct pipe_vertex_element *vert_elem;
49 int i;
50
51 for (i = 0; i < r300->aos_count; i++)
52 {
53 vert_elem = &r300->vertex_element[i];
54 /* XXX use translate module to convert the data */
55 if (!format_is_supported(vert_elem->src_format,
56 vert_elem->nr_components)) {
57 assert(0);
58 /*
59 struct pipe_buffer *buf;
60 const unsigned int max_index = r300->vertex_buffers[vert_elem->vertex_buffer_index].max_index;
61 buf = pipe_buffer_create(r300->context.screen, 4, usage, vert_elem->nr_components * max_index * sizeof(float));
62 */
63 }
64
65 if (get_buffer_offset(r300,
66 vert_elem->vertex_buffer_index,
67 vert_elem->src_offset) % 4) {
68 /* XXX need to align buffer */
69 assert(0);
70 }
71 }
72 }
73 #endif
74 /* XXX these shouldn't be asserts since we can work around bad indexbufs */
75 void setup_index_buffer(struct r300_context *r300,
76 struct pipe_buffer* indexBuffer,
77 unsigned indexSize)
78 {
79 if (!r300->winsys->add_buffer(r300->winsys, indexBuffer,
80 RADEON_GEM_DOMAIN_GTT, 0)) {
81 assert(0);
82 }
83
84 if (!r300->winsys->validate(r300->winsys)) {
85 assert(0);
86 }
87 }