1 /**************************************************************************
3 * Copyright 2012 Marek Olšák <maraeo@gmail.com>
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 THE AUTHORS AND/OR THEIR 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_helpers.h"
29 #include "util/u_inlines.h"
30 #include "util/u_upload_mgr.h"
34 * This function is used to copy an array of pipe_vertex_buffer structures,
35 * while properly referencing the pipe_vertex_buffer::buffer member.
37 * enabled_buffers is updated such that the bits corresponding to the indices
38 * of disabled buffers are set to 0 and the enabled ones are set to 1.
40 * \sa util_copy_framebuffer_state
42 void util_set_vertex_buffers_mask(struct pipe_vertex_buffer
*dst
,
43 uint32_t *enabled_buffers
,
44 const struct pipe_vertex_buffer
*src
,
45 unsigned start_slot
, unsigned count
)
53 for (i
= 0; i
< count
; i
++) {
54 if (src
[i
].buffer
.resource
)
57 pipe_vertex_buffer_unreference(&dst
[i
]);
59 if (!src
[i
].is_user_buffer
)
60 pipe_resource_reference(&dst
[i
].buffer
.resource
, src
[i
].buffer
.resource
);
63 /* Copy over the other members of pipe_vertex_buffer. */
64 memcpy(dst
, src
, count
* sizeof(struct pipe_vertex_buffer
));
66 *enabled_buffers
&= ~(((1ull << count
) - 1) << start_slot
);
67 *enabled_buffers
|= bitmask
<< start_slot
;
70 /* Unreference the buffers. */
71 for (i
= 0; i
< count
; i
++)
72 pipe_vertex_buffer_unreference(&dst
[i
]);
74 *enabled_buffers
&= ~(((1ull << count
) - 1) << start_slot
);
79 * Same as util_set_vertex_buffers_mask, but it only returns the number
82 void util_set_vertex_buffers_count(struct pipe_vertex_buffer
*dst
,
84 const struct pipe_vertex_buffer
*src
,
85 unsigned start_slot
, unsigned count
)
88 uint32_t enabled_buffers
= 0;
90 for (i
= 0; i
< *dst_count
; i
++) {
91 if (dst
[i
].buffer
.resource
)
92 enabled_buffers
|= (1ull << i
);
95 util_set_vertex_buffers_mask(dst
, &enabled_buffers
, src
, start_slot
,
98 *dst_count
= util_last_bit(enabled_buffers
);
102 * Given a user index buffer, save the structure to "saved", and upload it.
105 util_upload_index_buffer(struct pipe_context
*pipe
,
106 const struct pipe_draw_info
*info
,
107 struct pipe_resource
**out_buffer
,
108 unsigned *out_offset
)
110 unsigned start_offset
= info
->start
* info
->index_size
;
112 u_upload_data(pipe
->stream_uploader
, start_offset
,
113 info
->count
* info
->index_size
, 4,
114 (char*)info
->index
.user
+ start_offset
,
115 out_offset
, out_buffer
);
116 u_upload_unmap(pipe
->stream_uploader
);
117 *out_offset
-= start_offset
;
118 return *out_buffer
!= NULL
;
122 util_begin_pipestat_query(struct pipe_context
*ctx
)
124 struct pipe_query
*q
=
125 ctx
->create_query(ctx
, PIPE_QUERY_PIPELINE_STATISTICS
, 0);
129 ctx
->begin_query(ctx
, q
);
134 util_end_pipestat_query(struct pipe_context
*ctx
, struct pipe_query
*q
,
137 static unsigned counter
;
138 struct pipe_query_data_pipeline_statistics stats
;
140 ctx
->end_query(ctx
, q
);
141 ctx
->get_query_result(ctx
, q
, true, (void*)&stats
);
142 ctx
->destroy_query(ctx
, q
);
146 " ia_vertices = %"PRIu64
"\n"
147 " ia_primitives = %"PRIu64
"\n"
148 " vs_invocations = %"PRIu64
"\n"
149 " gs_invocations = %"PRIu64
"\n"
150 " gs_primitives = %"PRIu64
"\n"
151 " c_invocations = %"PRIu64
"\n"
152 " c_primitives = %"PRIu64
"\n"
153 " ps_invocations = %"PRIu64
"\n"
154 " hs_invocations = %"PRIu64
"\n"
155 " ds_invocations = %"PRIu64
"\n"
156 " cs_invocations = %"PRIu64
"\n",
157 p_atomic_inc_return(&counter
),
160 stats
.vs_invocations
,
161 stats
.gs_invocations
,
165 stats
.ps_invocations
,
166 stats
.hs_invocations
,
167 stats
.ds_invocations
,
168 stats
.cs_invocations
);