Merge branch 'width0'
[mesa.git] / src / gallium / drivers / svga / svga_screen_cache.h
1 /**********************************************************
2 * Copyright 2008-2009 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 #ifndef SVGA_SCREEN_CACHE_H_
27 #define SVGA_SCREEN_CACHE_H_
28
29
30 #include "svga_types.h"
31 #include "svga_reg.h"
32 #include "svga3d_reg.h"
33
34 #include "pipe/p_thread.h"
35
36 #include "util/u_double_list.h"
37
38
39 /* TODO: Reduce this once we don't allocate an index buffer per draw call */
40 #define SVGA_HOST_SURFACE_CACHE_SIZE 1024
41
42 #define SVGA_HOST_SURFACE_CACHE_BUCKETS 64
43
44
45 struct svga_winsys_surface;
46 struct svga_screen;
47
48 /**
49 * Same as svga_winsys_screen::surface_create.
50 */
51 struct svga_host_surface_cache_key
52 {
53 SVGA3dSurfaceFlags flags;
54 SVGA3dSurfaceFormat format;
55 SVGA3dSize size;
56 uint32_t numFaces;
57 uint32_t numMipLevels;
58 };
59
60
61 struct svga_host_surface_cache_entry
62 {
63 /**
64 * Head for the LRU list, svga_host_surface_cache::unused, and
65 * svga_host_surface_cache::empty
66 */
67 struct list_head head;
68
69 /** Head for the bucket lists. */
70 struct list_head bucket_head;
71
72 struct svga_host_surface_cache_key key;
73 struct svga_winsys_surface *handle;
74
75 struct pipe_fence_handle *fence;
76 };
77
78
79 /**
80 * Cache of the host surfaces.
81 *
82 * A cache entry can be in the following stages:
83 * 1. empty
84 * 2. holding a buffer in a validate list
85 * 3. holding a flushed buffer (not in any validate list) with an active fence
86 * 4. holding a flushed buffer with an expired fence
87 *
88 * An entry progresses from 1 -> 2 -> 3 -> 4. When we need an entry to put a
89 * buffer into we preferencial take from 1, or from the least recentely used
90 * buffer from 3/4.
91 */
92 struct svga_host_surface_cache
93 {
94 pipe_mutex mutex;
95
96 /* Unused buffers are put in buckets to speed up lookups */
97 struct list_head bucket[SVGA_HOST_SURFACE_CACHE_BUCKETS];
98
99 /* Entries with unused buffers, ordered from most to least recently used
100 * (3 and 4) */
101 struct list_head unused;
102
103 /* Entries with buffers still in validate lists (2) */
104 struct list_head validated;
105
106 /** Empty entries (1) */
107 struct list_head empty;
108
109 /** The actual storage for the entries */
110 struct svga_host_surface_cache_entry entries[SVGA_HOST_SURFACE_CACHE_SIZE];
111 };
112
113
114 void
115 svga_screen_cache_cleanup(struct svga_screen *svgascreen);
116
117 void
118 svga_screen_cache_flush(struct svga_screen *svgascreen,
119 struct pipe_fence_handle *fence);
120
121 enum pipe_error
122 svga_screen_cache_init(struct svga_screen *svgascreen);
123
124
125 struct svga_winsys_surface *
126 svga_screen_surface_create(struct svga_screen *svgascreen,
127 struct svga_host_surface_cache_key *key);
128
129 void
130 svga_screen_surface_destroy(struct svga_screen *svgascreen,
131 const struct svga_host_surface_cache_key *key,
132 struct svga_winsys_surface **handle);
133
134
135 #endif /* SVGA_SCREEN_CACHE_H_ */