summaryrefslogtreecommitdiff
path: root/src/gallium/winsys/svga/drm/vmw_screen_pools.c
blob: 1815bfa67072770521c943571fdb5a47378acc33 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/**********************************************************
 * Copyright 2009 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 "vmw_screen.h"

#include "vmw_buffer.h"
#include "vmw_fence.h"

#include "pipebuffer/pb_buffer.h"
#include "pipebuffer/pb_bufmgr.h"

/**
 * vmw_pools_cleanup - Destroy the buffer pools.
 *
 * @vws: pointer to a struct vmw_winsys_screen.
 */
void
vmw_pools_cleanup(struct vmw_winsys_screen *vws)
{
   if (vws->pools.mob_shader_slab_fenced)
      vws->pools.mob_shader_slab_fenced->destroy
         (vws->pools.mob_shader_slab_fenced);
   if (vws->pools.mob_shader_slab)
      vws->pools.mob_shader_slab->destroy(vws->pools.mob_shader_slab);
   if (vws->pools.mob_fenced)
      vws->pools.mob_fenced->destroy(vws->pools.mob_fenced);
   if (vws->pools.mob_cache)
      vws->pools.mob_cache->destroy(vws->pools.mob_cache);

   if (vws->pools.query_fenced)
      vws->pools.query_fenced->destroy(vws->pools.query_fenced);
   if (vws->pools.query_mm)
      vws->pools.query_mm->destroy(vws->pools.query_mm);

   if(vws->pools.gmr_fenced)
      vws->pools.gmr_fenced->destroy(vws->pools.gmr_fenced);
   if (vws->pools.gmr_mm)
      vws->pools.gmr_mm->destroy(vws->pools.gmr_mm);
   if (vws->pools.gmr_slab_fenced)
      vws->pools.gmr_slab_fenced->destroy(vws->pools.gmr_slab_fenced);
   if (vws->pools.gmr_slab)
      vws->pools.gmr_slab->destroy(vws->pools.gmr_slab);

   if(vws->pools.gmr)
      vws->pools.gmr->destroy(vws->pools.gmr);
}


/**
 * vmw_query_pools_init - Create a pool of query buffers.
 *
 * @vws: Pointer to a struct vmw_winsys_screen.
 *
 * Typically this pool should be created on demand when we
 * detect that the app will be using queries. There's nothing
 * special with this pool other than the backing kernel buffer sizes,
 * which are limited to 8192.
 * If there is a performance issue with allocation and freeing of the
 * query slabs, it should be easily fixable by allocating them out
 * of a buffer cache.
 */
boolean
vmw_query_pools_init(struct vmw_winsys_screen *vws)
{
   struct pb_desc desc;

   desc.alignment = 16;
   desc.usage = ~(VMW_BUFFER_USAGE_SHARED | VMW_BUFFER_USAGE_SYNC);

   vws->pools.query_mm = pb_slab_range_manager_create(vws->pools.gmr, 16, 128,
                                                      VMW_QUERY_POOL_SIZE,
                                                      &desc);
   if (!vws->pools.query_mm)
      return FALSE;

   vws->pools.query_fenced = simple_fenced_bufmgr_create(
      vws->pools.query_mm, vws->fence_ops);

   if(!vws->pools.query_fenced)
      goto out_no_query_fenced;

   return TRUE;

  out_no_query_fenced:
   vws->pools.query_mm->destroy(vws->pools.query_mm);
   return FALSE;
}

/**
 * vmw_mob_pool_init - Create a pool of fenced kernel buffers.
 *
 * @vws: Pointer to a struct vmw_winsys_screen.
 *
 * Typically this pool should be created on demand when we
 * detect that the app will be using MOB buffers.
 */
boolean
vmw_mob_pools_init(struct vmw_winsys_screen *vws)
{
   struct pb_desc desc;

   vws->pools.mob_cache = 
      pb_cache_manager_create(vws->pools.gmr, 100000, 2.0f,
                              VMW_BUFFER_USAGE_SHARED,
                              64 * 1024 * 1024);
   if (!vws->pools.mob_cache)
      return FALSE;

   vws->pools.mob_fenced = 
      simple_fenced_bufmgr_create(vws->pools.mob_cache,
                                  vws->fence_ops);
   if(!vws->pools.mob_fenced)
      goto out_no_mob_fenced;
   
   desc.alignment = 64;
   desc.usage = ~(SVGA_BUFFER_USAGE_PINNED | VMW_BUFFER_USAGE_SHARED |
                  VMW_BUFFER_USAGE_SYNC);
   vws->pools.mob_shader_slab =
      pb_slab_range_manager_create(vws->pools.mob_cache,
                                   64,
                                   8192,
                                   16384,
                                   &desc);
   if(!vws->pools.mob_shader_slab)
      goto out_no_mob_shader_slab;

   vws->pools.mob_shader_slab_fenced =
      simple_fenced_bufmgr_create(vws->pools.mob_shader_slab,
				  vws->fence_ops);
   if(!vws->pools.mob_fenced)
      goto out_no_mob_shader_slab_fenced;

   return TRUE;

 out_no_mob_shader_slab_fenced:
   vws->pools.mob_shader_slab->destroy(vws->pools.mob_shader_slab);
 out_no_mob_shader_slab:
   vws->pools.mob_fenced->destroy(vws->pools.mob_fenced);
 out_no_mob_fenced:
   vws->pools.mob_cache->destroy(vws->pools.mob_cache);
   return FALSE;
}

/**
 * vmw_pools_init - Create a pool of GMR buffers.
 *
 * @vws: Pointer to a struct vmw_winsys_screen.
 */
boolean
vmw_pools_init(struct vmw_winsys_screen *vws)
{
   struct pb_desc desc;

   vws->pools.gmr = vmw_gmr_bufmgr_create(vws);
   if(!vws->pools.gmr)
      goto error;

   if ((vws->base.have_gb_objects && vws->base.have_gb_dma) ||
       !vws->base.have_gb_objects) {
      /*
       * A managed pool for DMA buffers.
       */
      vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr,
                                           VMW_GMR_POOL_SIZE,
                                           12 /* 4096 alignment */);
      if(!vws->pools.gmr_mm)
         goto error;

      vws->pools.gmr_fenced = simple_fenced_bufmgr_create
         (vws->pools.gmr_mm, vws->fence_ops);

#ifdef DEBUG
      vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced,
                                                      4096,
                                                      4096);
#endif
      if(!vws->pools.gmr_fenced)
         goto error;

   /*
    * The slab pool allocates buffers directly from the kernel except
    * for very small buffers which are allocated from a slab in order
    * not to waste memory, since a kernel buffer is a minimum 4096 bytes.
    *
    * Here we use it only for emergency in the case our pre-allocated
    * managed buffer pool runs out of memory.
    */

      desc.alignment = 64;
      desc.usage = ~(SVGA_BUFFER_USAGE_PINNED | SVGA_BUFFER_USAGE_SHADER |
                     VMW_BUFFER_USAGE_SHARED | VMW_BUFFER_USAGE_SYNC);
      vws->pools.gmr_slab = pb_slab_range_manager_create(vws->pools.gmr,
                                                         64,
                                                         8192,
                                                         16384,
                                                         &desc);
      if (!vws->pools.gmr_slab)
         goto error;

      vws->pools.gmr_slab_fenced =
         simple_fenced_bufmgr_create(vws->pools.gmr_slab, vws->fence_ops);

      if (!vws->pools.gmr_slab_fenced)
         goto error;
   }

   vws->pools.query_fenced = NULL;
   vws->pools.query_mm = NULL;
   vws->pools.mob_cache = NULL;

   if (vws->base.have_gb_objects && !vmw_mob_pools_init(vws))
      goto error;

   return TRUE;

error:
   vmw_pools_cleanup(vws);
   return FALSE;
}