1 /**********************************************************
2 * Copyright 2015 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
26 #include "pipebuffer/pb_bufmgr.h"
27 #include "util/u_memory.h"
29 #include "vmw_screen.h"
30 #include "vmw_buffer.h"
31 #include "vmw_query.h"
35 struct svga_winsys_gb_query
*
36 vmw_svga_winsys_query_create(struct svga_winsys_screen
*sws
,
37 uint32 queryResultLen
)
39 struct vmw_winsys_screen
*vws
= vmw_winsys_screen(sws
);
40 struct pb_manager
*provider
= vws
->pools
.gmr
;
41 struct pb_desc desc
= {0};
42 struct pb_buffer
*pb_buf
;
43 struct svga_winsys_gb_query
*query
;
45 query
= CALLOC_STRUCT(svga_winsys_gb_query
);
49 /* Allocate memory to hold queries for this context */
50 desc
.alignment
= 4096;
51 pb_buf
= provider
->create_buffer(provider
, queryResultLen
, &desc
);
52 query
->buf
= vmw_svga_winsys_buffer_wrap(pb_buf
);
55 debug_printf("Failed to allocate memory for queries\n");
66 vmw_svga_winsys_query_destroy(struct svga_winsys_screen
*sws
,
67 struct svga_winsys_gb_query
*query
)
69 vmw_svga_winsys_buffer_destroy(sws
, query
->buf
);
76 vmw_svga_winsys_query_init(struct svga_winsys_screen
*sws
,
77 struct svga_winsys_gb_query
*query
,
79 SVGA3dQueryState queryState
)
81 SVGA3dQueryState
*state
;
83 state
= (SVGA3dQueryState
*) vmw_svga_winsys_buffer_map(sws
,
87 debug_printf("Failed to map query result memory for initialization\n");
91 /* Initialize the query state for the specified query slot */
92 state
= (SVGA3dQueryState
*)((char *)state
+ offset
);
95 vmw_svga_winsys_buffer_unmap(sws
, query
->buf
);
103 vmw_svga_winsys_query_get_result(struct svga_winsys_screen
*sws
,
104 struct svga_winsys_gb_query
*query
,
106 SVGA3dQueryState
*queryState
,
107 void *result
, uint32 resultLen
)
109 SVGA3dQueryState
*state
;
111 state
= (SVGA3dQueryState
*) vmw_svga_winsys_buffer_map(sws
,
115 debug_printf("Failed to lock query result memory\n");
118 *queryState
= SVGA3D_QUERYSTATE_FAILED
;
123 state
= (SVGA3dQueryState
*)((char *)state
+ offset
);
126 *queryState
= *state
;
129 memcpy(result
, state
+ 1, resultLen
);
132 vmw_svga_winsys_buffer_unmap(sws
, query
->buf
);
137 vmw_swc_query_bind(struct svga_winsys_context
*swc
,
138 struct svga_winsys_gb_query
*query
,