2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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.
29 #include <pipe/p_screen.h>
30 #include <util/u_format.h>
31 #include <util/u_math.h>
32 #include <util/u_inlines.h>
33 #include <util/u_memory.h>
35 #include "r600_screen.h"
36 #include "r600_context.h"
37 #include "r600_resource.h"
38 #include "r600_state_inlines.h"
40 static int r600_draw_common(struct r600_draw
*draw
)
42 struct r600_context
*rctx
= r600_context(draw
->ctx
);
43 struct r600_screen
*rscreen
= rctx
->screen
;
44 /* FIXME vs_resource */
45 struct radeon_state
*vs_resource
;
46 struct r600_resource
*rbuffer
;
47 unsigned i
, j
, offset
, format
, prim
;
48 u32 vgt_dma_index_type
, vgt_draw_initiator
;
49 struct pipe_vertex_buffer
*vertex_buffer
;
52 r
= r600_context_hw_states(draw
->ctx
);
55 switch (draw
->index_size
) {
57 vgt_draw_initiator
= S_0287F0_SOURCE_SELECT(V_0287F0_DI_SRC_SEL_DMA
);
58 vgt_dma_index_type
= 0;
61 vgt_draw_initiator
= S_0287F0_SOURCE_SELECT(V_0287F0_DI_SRC_SEL_DMA
);
62 vgt_dma_index_type
= 1;
65 vgt_draw_initiator
= S_0287F0_SOURCE_SELECT(V_0287F0_DI_SRC_SEL_AUTO_INDEX
);
66 vgt_dma_index_type
= 0;
69 fprintf(stderr
, "%s %d unsupported index size %d\n", __func__
, __LINE__
, draw
->index_size
);
72 r
= r600_conv_pipe_prim(draw
->mode
, &prim
);
76 /* rebuild vertex shader if input format changed */
77 r
= r600_pipe_shader_update(draw
->ctx
, rctx
->vs_shader
);
80 r
= r600_pipe_shader_update(draw
->ctx
, rctx
->ps_shader
);
83 radeon_draw_bind(&rctx
->draw
, &rctx
->vs_shader
->rstate
[0]);
84 radeon_draw_bind(&rctx
->draw
, &rctx
->ps_shader
->rstate
[0]);
86 for (i
= 0 ; i
< rctx
->vs_nresource
; i
++) {
87 radeon_state_fini(&rctx
->vs_resource
[i
]);
89 for (i
= 0 ; i
< rctx
->vertex_elements
->count
; i
++) {
90 vs_resource
= &rctx
->vs_resource
[i
];
91 j
= rctx
->vertex_elements
->elements
[i
].vertex_buffer_index
;
92 vertex_buffer
= &rctx
->vertex_buffer
[j
];
93 rbuffer
= (struct r600_resource
*)vertex_buffer
->buffer
;
94 offset
= rctx
->vertex_elements
->elements
[i
].src_offset
+ vertex_buffer
->buffer_offset
;
95 format
= r600_translate_colorformat(rctx
->vertex_elements
->elements
[i
].src_format
);
97 rctx
->vtbl
->vs_resource(rctx
, i
, rbuffer
, offset
, vertex_buffer
->stride
, format
);
98 radeon_draw_bind(&rctx
->draw
, vs_resource
);
100 rctx
->vs_nresource
= rctx
->vertex_elements
->count
;
101 /* FIXME start need to change winsys */
102 rctx
->vtbl
->vgt_init(draw
, vgt_draw_initiator
);
103 radeon_draw_bind(&rctx
->draw
, &draw
->draw
);
105 rctx
->vtbl
->vgt_prim(draw
, prim
, vgt_dma_index_type
);
106 radeon_draw_bind(&rctx
->draw
, &draw
->vgt
);
108 r
= radeon_ctx_set_draw(rctx
->ctx
, &rctx
->draw
);
110 r600_flush(draw
->ctx
, 0, NULL
);
111 r
= radeon_ctx_set_draw(rctx
->ctx
, &rctx
->draw
);
114 radeon_state_fini(&draw
->draw
);
119 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
)
121 struct r600_context
*rctx
= r600_context(ctx
);
122 struct r600_draw draw
;
125 assert(info
->index_bias
== 0);
127 memset(&draw
, 0, sizeof(draw
));
129 if (rctx
->any_user_vbs
) {
130 r600_upload_user_buffers(rctx
);
131 rctx
->any_user_vbs
= false;
135 draw
.mode
= info
->mode
;
136 draw
.start
= info
->start
;
137 draw
.count
= info
->count
;
138 if (info
->indexed
&& rctx
->index_buffer
.buffer
) {
139 draw
.min_index
= info
->min_index
;
140 draw
.max_index
= info
->max_index
;
141 draw
.index_size
= rctx
->index_buffer
.index_size
;
142 draw
.index_buffer
= rctx
->index_buffer
.buffer
;
143 draw
.index_buffer_offset
= rctx
->index_buffer
.offset
;
145 assert(rctx
->index_buffer
.offset
%
146 rctx
->index_buffer
.index_size
== 0);
147 r600_upload_index_buffer(rctx
, &draw
);
151 draw
.index_buffer
= NULL
;
153 draw
.max_index
= 0xffffff;
154 draw
.index_buffer_offset
= 0;
156 r
= r600_draw_common(&draw
);
158 fprintf(stderr
,"draw common failed %d\n", r
);