1 /**********************************************************
2 * Copyright 2008-2009 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 #ifndef SVGA_SCREEN_CACHE_H_
27 #define SVGA_SCREEN_CACHE_H_
30 #include "svga_types.h"
32 #include "svga3d_reg.h"
34 #include "os/os_thread.h"
36 #include "util/u_double_list.h"
39 /* Guess the storage size of cached surfaces and try and keep it under
42 #define SVGA_HOST_SURFACE_CACHE_BYTES 16*1024*1024
44 /* Maximum number of discrete surfaces in the cache:
46 #define SVGA_HOST_SURFACE_CACHE_SIZE 1024
48 /* Number of hash buckets:
50 #define SVGA_HOST_SURFACE_CACHE_BUCKETS 256
53 struct svga_winsys_surface
;
57 * Same as svga_winsys_screen::surface_create.
59 struct svga_host_surface_cache_key
61 SVGA3dSurfaceFlags flags
;
62 SVGA3dSurfaceFormat format
;
65 uint32_t numMipLevels
:7;
66 uint32_t cachable
:1; /* False if this is a shared surface */
70 struct svga_host_surface_cache_entry
73 * Head for the LRU list, svga_host_surface_cache::unused, and
74 * svga_host_surface_cache::empty
76 struct list_head head
;
78 /** Head for the bucket lists. */
79 struct list_head bucket_head
;
81 struct svga_host_surface_cache_key key
;
82 struct svga_winsys_surface
*handle
;
84 struct pipe_fence_handle
*fence
;
89 * Cache of the host surfaces.
91 * A cache entry can be in the following stages:
93 * 2. holding a buffer in a validate list
94 * 3. holding a flushed buffer (not in any validate list) with an active fence
95 * 4. holding a flushed buffer with an expired fence
97 * An entry progresses from 1 -> 2 -> 3 -> 4. When we need an entry to put a
98 * buffer into we preferencial take from 1, or from the least recentely used
101 struct svga_host_surface_cache
105 /* Unused buffers are put in buckets to speed up lookups */
106 struct list_head bucket
[SVGA_HOST_SURFACE_CACHE_BUCKETS
];
108 /* Entries with unused buffers, ordered from most to least recently used
110 struct list_head unused
;
112 /* Entries with buffers still in validate lists (2) */
113 struct list_head validated
;
115 /** Empty entries (1) */
116 struct list_head empty
;
118 /** The actual storage for the entries */
119 struct svga_host_surface_cache_entry entries
[SVGA_HOST_SURFACE_CACHE_SIZE
];
124 svga_screen_cache_cleanup(struct svga_screen
*svgascreen
);
127 svga_screen_cache_flush(struct svga_screen
*svgascreen
,
128 struct pipe_fence_handle
*fence
);
131 svga_screen_cache_init(struct svga_screen
*svgascreen
);
134 struct svga_winsys_surface
*
135 svga_screen_surface_create(struct svga_screen
*svgascreen
,
136 struct svga_host_surface_cache_key
*key
);
139 svga_screen_surface_destroy(struct svga_screen
*svgascreen
,
140 const struct svga_host_surface_cache_key
*key
,
141 struct svga_winsys_surface
**handle
);
144 #endif /* SVGA_SCREEN_CACHE_H_ */