aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/svga/drm/vmw_query.c
blob: 7baf2c1d7ae142ba1ae01a2618e32a60ba8a2be7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**********************************************************
 * Copyright 2015 VMware, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **********************************************************/

#include "pipebuffer/pb_bufmgr.h"
#include "util/u_memory.h"

#include "vmw_screen.h"
#include "vmw_buffer.h"
#include "vmw_query.h"



struct svga_winsys_gb_query *
vmw_svga_winsys_query_create(struct svga_winsys_screen *sws,
                             uint32 queryResultLen)
{
   struct vmw_winsys_screen *vws = vmw_winsys_screen(sws);
   struct pb_manager *provider = vws->pools.gmr;
   struct pb_desc desc = {0};
   struct pb_buffer *pb_buf;
   struct svga_winsys_gb_query *query;

   query = CALLOC_STRUCT(svga_winsys_gb_query);
   if (!query)
      return NULL;

   /* Allocate memory to hold queries for this context */
   desc.alignment = 4096;
   pb_buf = provider->create_buffer(provider, queryResultLen, &desc);
   query->buf = vmw_svga_winsys_buffer_wrap(pb_buf);

   if (!query->buf) {
      debug_printf("Failed to allocate memory for queries\n");
      FREE(query);
      query = NULL;
   }

   return query;
}



void
vmw_svga_winsys_query_destroy(struct svga_winsys_screen *sws,
                              struct svga_winsys_gb_query *query)
{
   vmw_svga_winsys_buffer_destroy(sws, query->buf);
   FREE(query);
}



int
vmw_svga_winsys_query_init(struct svga_winsys_screen *sws,
                           struct svga_winsys_gb_query *query,
                           unsigned offset,
                           SVGA3dQueryState queryState)
{
   SVGA3dQueryState *state;

   state = (SVGA3dQueryState *) vmw_svga_winsys_buffer_map(sws,
                                       query->buf,
                                       PIPE_TRANSFER_WRITE);
   if (!state) {
      debug_printf("Failed to map query result memory for initialization\n");
      return -1;
   }

   /* Initialize the query state for the specified query slot */
   state = (SVGA3dQueryState *)((char *)state + offset);
   *state = queryState;

   vmw_svga_winsys_buffer_unmap(sws, query->buf);

   return 0;
}



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)
{
   SVGA3dQueryState *state;

   state = (SVGA3dQueryState *) vmw_svga_winsys_buffer_map(sws,
                                       query->buf,
                                       PIPE_TRANSFER_READ);
   if (!state) {
      debug_printf("Failed to lock query result memory\n");

      if (queryState)
         *queryState = SVGA3D_QUERYSTATE_FAILED;

      return;
   }

   state = (SVGA3dQueryState *)((char *)state + offset);

   if (queryState)
      *queryState = *state;

   if (result) {
      memcpy(result, state + 1, resultLen);
   }

   vmw_svga_winsys_buffer_unmap(sws, query->buf);
}


enum pipe_error
vmw_swc_query_bind(struct svga_winsys_context *swc, 
                   struct svga_winsys_gb_query *query,
                   unsigned flags)
{
   /* no-op on Linux */
   return PIPE_OK;
}