1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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 VMWARE 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 "draw/draw_context.h"
30 #include "draw/draw_private.h"
31 #include "draw/draw_vbuf.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_pt.h"
34 #include "translate/translate.h"
35 #include "translate/translate_cache.h"
38 struct draw_context
*draw
;
40 struct translate
*translate
;
42 struct translate_cache
*cache
;
45 const struct vertex_info
*vinfo
;
50 prepare_so_emit( struct pt_so_emit
*emit
,
51 const struct vertex_info
*vinfo
)
53 struct draw_context
*draw
= emit
->draw
;
55 struct translate_key hw_key
;
56 unsigned dst_offset
= 0;
59 for (i
= 0; i
< draw
->so
.state
.num_outputs
; ++i
) {
60 unsigned src_offset
= (draw
->so
.state
.register_index
[i
] * 4 *
62 unsigned output_format
;
64 /*unsigned output_bytes = util_format_get_blocksize(output_format);
65 unsigned nr_compo = util_format_get_nr_components(output_format);*/
67 output_format
= draw_translate_vinfo_format(vinfo
->attrib
[i
].emit
);
68 emit_sz
= draw_translate_vinfo_size(vinfo
->attrib
[i
].emit
);
70 /* doesn't handle EMIT_OMIT */
73 if (draw
->so
.state
.register_mask
[i
] != TGSI_WRITEMASK_XYZW
) {
74 /* we only support rendering with XYZW writemask*/
75 debug_printf("NOT_IMPLEMENTED(writemask with stream output) at %s: %s:%d\n",
76 __FUNCTION__
, __FILE__
, __LINE__
);
79 hw_key
.element
[i
].type
= TRANSLATE_ELEMENT_NORMAL
;
80 hw_key
.element
[i
].input_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
81 hw_key
.element
[i
].input_buffer
= 0;
82 hw_key
.element
[i
].input_offset
= src_offset
;
83 hw_key
.element
[i
].instance_divisor
= 0;
84 hw_key
.element
[i
].output_format
= output_format
;
85 hw_key
.element
[i
].output_offset
= dst_offset
;
87 dst_offset
+= emit_sz
;
89 hw_key
.nr_elements
= draw
->so
.state
.num_outputs
;
90 hw_key
.output_stride
= draw
->so
.state
.stride
;
92 if (!emit
->translate
||
93 translate_key_compare(&emit
->translate
->key
, &hw_key
) != 0)
95 translate_key_sanitize(&hw_key
);
96 emit
->translate
= translate_cache_find(emit
->cache
, &hw_key
);
99 /* no stream output */
100 emit
->translate
= NULL
;
105 void draw_pt_so_emit_prepare( struct pt_so_emit
*emit
,
108 struct draw_context
*draw
= emit
->draw
;
111 emit
->has_so
= (draw
->so
.state
.num_outputs
> 0);
116 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
118 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
122 ok
= draw
->render
->set_primitive(draw
->render
, emit
->prim
);
128 /* Must do this after set_primitive() above: */
129 emit
->vinfo
= draw
->render
->get_vertex_info(draw
->render
);
131 prepare_so_emit( emit
, emit
->vinfo
);
135 void draw_pt_so_emit( struct pt_so_emit
*emit
,
136 const float (*vertex_data
)[4],
137 unsigned vertex_count
,
140 struct draw_context
*draw
= emit
->draw
;
141 struct translate
*translate
= emit
->translate
;
142 struct vbuf_render
*render
= draw
->render
;
148 so_buffer
= draw
->so
.buffers
[0];
150 /* XXX: need to flush to get prim_vbuf.c to release its allocation??*/
151 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
153 if (vertex_count
== 0)
156 if (vertex_count
>= UNDEFINED_VERTEX_ID
) {
161 /* XXX we only support single output buffer */
162 if (draw
->so
.num_buffers
!= 1) {
163 debug_printf("NOT_IMPLEMENTED(multiple stream output buffers) at %s: %s:%d\n",
164 __FUNCTION__
, __FILE__
, __LINE__
);
167 translate
->set_buffer(translate
, 0, vertex_data
,
169 translate
->run(translate
, 0, vertex_count
,
170 draw
->instance_id
, so_buffer
);
172 render
->set_stream_output_info(render
, 0, vertex_count
);
176 struct pt_so_emit
*draw_pt_so_emit_create( struct draw_context
*draw
)
178 struct pt_so_emit
*emit
= CALLOC_STRUCT(pt_so_emit
);
183 emit
->cache
= translate_cache_create();
192 void draw_pt_so_emit_destroy( struct pt_so_emit
*emit
)
195 translate_cache_destroy(emit
->cache
);