• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**********************************************************
2  * Copyright 2015 VMware, Inc.  All rights reserved.
3  *
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:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
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
22  * SOFTWARE.
23  *
24  **********************************************************/
25 
26 #include "pipebuffer/pb_bufmgr.h"
27 #include "util/u_memory.h"
28 
29 #include "vmw_screen.h"
30 #include "vmw_buffer.h"
31 #include "vmw_query.h"
32 
33 
34 
35 struct svga_winsys_gb_query *
vmw_svga_winsys_query_create(struct svga_winsys_screen * sws,uint32 queryResultLen)36 vmw_svga_winsys_query_create(struct svga_winsys_screen *sws,
37                              uint32 queryResultLen)
38 {
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;
44 
45    query = CALLOC_STRUCT(svga_winsys_gb_query);
46    if (!query)
47       return NULL;
48 
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);
53 
54    if (!query->buf) {
55       debug_printf("Failed to allocate memory for queries\n");
56       FREE(query);
57       query = NULL;
58    }
59 
60    return query;
61 }
62 
63 
64 
65 void
vmw_svga_winsys_query_destroy(struct svga_winsys_screen * sws,struct svga_winsys_gb_query * query)66 vmw_svga_winsys_query_destroy(struct svga_winsys_screen *sws,
67                               struct svga_winsys_gb_query *query)
68 {
69    vmw_svga_winsys_buffer_destroy(sws, query->buf);
70    FREE(query);
71 }
72 
73 
74 
75 int
vmw_svga_winsys_query_init(struct svga_winsys_screen * sws,struct svga_winsys_gb_query * query,unsigned offset,SVGA3dQueryState queryState)76 vmw_svga_winsys_query_init(struct svga_winsys_screen *sws,
77                            struct svga_winsys_gb_query *query,
78                            unsigned offset,
79                            SVGA3dQueryState queryState)
80 {
81    SVGA3dQueryState *state;
82 
83    state = (SVGA3dQueryState *) vmw_svga_winsys_buffer_map(sws,
84                                        query->buf,
85                                        PIPE_TRANSFER_WRITE);
86    if (!state) {
87       debug_printf("Failed to map query result memory for initialization\n");
88       return -1;
89    }
90 
91    /* Initialize the query state for the specified query slot */
92    state = (SVGA3dQueryState *)((char *)state + offset);
93    *state = queryState;
94 
95    vmw_svga_winsys_buffer_unmap(sws, query->buf);
96 
97    return 0;
98 }
99 
100 
101 
102 void
vmw_svga_winsys_query_get_result(struct svga_winsys_screen * sws,struct svga_winsys_gb_query * query,unsigned offset,SVGA3dQueryState * queryState,void * result,uint32 resultLen)103 vmw_svga_winsys_query_get_result(struct svga_winsys_screen *sws,
104                                  struct svga_winsys_gb_query *query,
105                                  unsigned offset,
106                                  SVGA3dQueryState *queryState,
107                                  void *result, uint32 resultLen)
108 {
109    SVGA3dQueryState *state;
110 
111    state = (SVGA3dQueryState *) vmw_svga_winsys_buffer_map(sws,
112                                        query->buf,
113                                        PIPE_TRANSFER_READ);
114    if (!state) {
115       debug_printf("Failed to lock query result memory\n");
116 
117       if (queryState)
118          *queryState = SVGA3D_QUERYSTATE_FAILED;
119 
120       return;
121    }
122 
123    state = (SVGA3dQueryState *)((char *)state + offset);
124 
125    if (queryState)
126       *queryState = *state;
127 
128    if (result) {
129       memcpy(result, state + 1, resultLen);
130    }
131 
132    vmw_svga_winsys_buffer_unmap(sws, query->buf);
133 }
134 
135 
136 enum pipe_error
vmw_swc_query_bind(struct svga_winsys_context * swc,struct svga_winsys_gb_query * query,unsigned flags)137 vmw_swc_query_bind(struct svga_winsys_context *swc,
138                    struct svga_winsys_gb_query *query,
139                    unsigned flags)
140 {
141    /* no-op on Linux */
142    return PIPE_OK;
143 }
144 
145