2 /**********************************************************
3 * Copyright 2008-2009 VMware, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 **********************************************************/
27 #ifndef SVGA_SCREEN_CACHE_H_
28 #define SVGA_SCREEN_CACHE_H_
31 #include "svga_types.h"
33 #include "svga3d_reg.h"
35 #include "os/os_thread.h"
37 #include "util/u_double_list.h"
40 /* Guess the storage size of cached surfaces and try and keep it under
43 #define SVGA_HOST_SURFACE_CACHE_BYTES (16 * 1024 * 1024)
45 /* Maximum number of discrete surfaces in the cache:
47 #define SVGA_HOST_SURFACE_CACHE_SIZE 1024
49 /* Number of hash buckets:
51 #define SVGA_HOST_SURFACE_CACHE_BUCKETS 256
54 struct svga_winsys_surface
;
58 * Same as svga_winsys_screen::surface_create.
60 struct svga_host_surface_cache_key
62 SVGA3dSurfaceFlags flags
;
63 SVGA3dSurfaceFormat format
;
66 uint32_t numMipLevels
:7;
67 uint32_t cachable
:1; /* False if this is a shared surface */
71 struct svga_host_surface_cache_entry
74 * Head for the LRU list, svga_host_surface_cache::unused, and
75 * svga_host_surface_cache::empty
77 struct list_head head
;
79 /** Head for the bucket lists. */
80 struct list_head bucket_head
;
82 struct svga_host_surface_cache_key key
;
83 struct svga_winsys_surface
*handle
;
85 struct pipe_fence_handle
*fence
;
90 * Cache of the host surfaces.
92 * A cache entry can be in the following stages:
93 * 1. empty (entry->handle = NULL)
94 * 2. holding a buffer in a validate list
95 * 3. holding a flushed buffer (not in any validate list) with an active fence
96 * 4. holding a flushed buffer with an expired fence
98 * An entry progresses from 1 -> 2 -> 3 -> 4. When we need an entry to put a
99 * buffer into we preferentially take from 1, or from the least recently used
102 struct svga_host_surface_cache
106 /* Unused buffers are put in buckets to speed up lookups */
107 struct list_head bucket
[SVGA_HOST_SURFACE_CACHE_BUCKETS
];
109 /* Entries with unused buffers, ordered from most to least recently used
111 struct list_head unused
;
113 /* Entries with buffers still in validate lists (2) */
114 struct list_head validated
;
116 /** Empty entries (1) */
117 struct list_head empty
;
119 /** The actual storage for the entries */
120 struct svga_host_surface_cache_entry entries
[SVGA_HOST_SURFACE_CACHE_SIZE
];
122 /** Sum of sizes of all surfaces (in bytes) */
128 svga_screen_cache_cleanup(struct svga_screen
*svgascreen
);
131 svga_screen_cache_flush(struct svga_screen
*svgascreen
,
132 struct pipe_fence_handle
*fence
);
135 svga_screen_cache_init(struct svga_screen
*svgascreen
);
138 struct svga_winsys_surface
*
139 svga_screen_surface_create(struct svga_screen
*svgascreen
,
140 struct svga_host_surface_cache_key
*key
);
143 svga_screen_surface_destroy(struct svga_screen
*svgascreen
,
144 const struct svga_host_surface_cache_key
*key
,
145 struct svga_winsys_surface
**handle
);
148 svga_screen_cache_dump(const struct svga_screen
*svgascreen
);
151 #endif /* SVGA_SCREEN_CACHE_H_ */