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 "pipe/p_thread.h"
36 #include "util/u_double_list.h"
39 /* TODO: Reduce this once we don't allocate an index buffer per draw call */
40 #define SVGA_HOST_SURFACE_CACHE_SIZE 1024
42 #define SVGA_HOST_SURFACE_CACHE_BUCKETS 64
45 struct svga_winsys_surface
;
49 * Same as svga_winsys_screen::surface_create.
51 struct svga_host_surface_cache_key
53 SVGA3dSurfaceFlags flags
;
54 SVGA3dSurfaceFormat format
;
57 uint32_t numMipLevels
;
61 struct svga_host_surface_cache_entry
64 * Head for the LRU list, svga_host_surface_cache::unused, and
65 * svga_host_surface_cache::empty
67 struct list_head head
;
69 /** Head for the bucket lists. */
70 struct list_head bucket_head
;
72 struct svga_host_surface_cache_key key
;
73 struct svga_winsys_surface
*handle
;
75 struct pipe_fence_handle
*fence
;
80 * Cache of the host surfaces.
82 * A cache entry can be in the following stages:
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
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
92 struct svga_host_surface_cache
96 /* Unused buffers are put in buckets to speed up lookups */
97 struct list_head bucket
[SVGA_HOST_SURFACE_CACHE_BUCKETS
];
99 /* Entries with unused buffers, ordered from most to least recently used
101 struct list_head unused
;
103 /* Entries with buffers still in validate lists (2) */
104 struct list_head validated
;
106 /** Empty entries (1) */
107 struct list_head empty
;
109 /** The actual storage for the entries */
110 struct svga_host_surface_cache_entry entries
[SVGA_HOST_SURFACE_CACHE_SIZE
];
115 svga_screen_cache_cleanup(struct svga_screen
*svgascreen
);
118 svga_screen_cache_flush(struct svga_screen
*svgascreen
,
119 struct pipe_fence_handle
*fence
);
122 svga_screen_cache_init(struct svga_screen
*svgascreen
);
125 struct svga_winsys_surface
*
126 svga_screen_surface_create(struct svga_screen
*svgascreen
,
127 struct svga_host_surface_cache_key
*key
);
130 svga_screen_surface_destroy(struct svga_screen
*svgascreen
,
131 const struct svga_host_surface_cache_key
*key
,
132 struct svga_winsys_surface
**handle
);
135 #endif /* SVGA_SCREEN_CACHE_H_ */