Brian Paul | 500e7c5 | 2011-12-07 16:57:11 -0700 | [diff] [blame] | 1 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 2 | /********************************************************** |
| 3 | * Copyright 2008-2009 VMware, Inc. All rights reserved. |
| 4 | * |
| 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: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be |
| 14 | * included in all copies or substantial portions of the Software. |
| 15 | * |
| 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 |
| 23 | * SOFTWARE. |
| 24 | * |
| 25 | **********************************************************/ |
| 26 | |
| 27 | #ifndef SVGA_SCREEN_CACHE_H_ |
| 28 | #define SVGA_SCREEN_CACHE_H_ |
| 29 | |
| 30 | |
| 31 | #include "svga_types.h" |
| 32 | #include "svga_reg.h" |
| 33 | #include "svga3d_reg.h" |
| 34 | |
José Fonseca | 2aaca1d | 2010-02-02 15:18:01 +0000 | [diff] [blame] | 35 | #include "os/os_thread.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 36 | |
Jason Ekstrand | 7a30668 | 2015-04-27 17:41:27 -0700 | [diff] [blame] | 37 | #include "util/list.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 38 | |
| 39 | |
Keith Whitwell | f1ce37f | 2009-11-24 21:13:18 +0000 | [diff] [blame] | 40 | /* Guess the storage size of cached surfaces and try and keep it under |
| 41 | * this amount: |
| 42 | */ |
Brian Paul | 500e7c5 | 2011-12-07 16:57:11 -0700 | [diff] [blame] | 43 | #define SVGA_HOST_SURFACE_CACHE_BYTES (16 * 1024 * 1024) |
Keith Whitwell | f1ce37f | 2009-11-24 21:13:18 +0000 | [diff] [blame] | 44 | |
| 45 | /* Maximum number of discrete surfaces in the cache: |
| 46 | */ |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 47 | #define SVGA_HOST_SURFACE_CACHE_SIZE 1024 |
| 48 | |
Keith Whitwell | f1ce37f | 2009-11-24 21:13:18 +0000 | [diff] [blame] | 49 | /* Number of hash buckets: |
| 50 | */ |
| 51 | #define SVGA_HOST_SURFACE_CACHE_BUCKETS 256 |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 52 | |
| 53 | |
| 54 | struct svga_winsys_surface; |
| 55 | struct svga_screen; |
Charmaine Lee | 16bd2c6 | 2017-01-26 18:46:23 -0800 | [diff] [blame] | 56 | struct svga_context; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Same as svga_winsys_screen::surface_create. |
| 60 | */ |
| 61 | struct svga_host_surface_cache_key |
| 62 | { |
Keith Whitwell | 55b0157 | 2009-11-25 11:44:41 +0000 | [diff] [blame] | 63 | SVGA3dSurfaceFlags flags; |
| 64 | SVGA3dSurfaceFormat format; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 65 | SVGA3dSize size; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 66 | uint32_t numFaces:3; |
| 67 | uint32_t arraySize:16; |
| 68 | uint32_t numMipLevels:6; |
Keith Whitwell | f1ce37f | 2009-11-24 21:13:18 +0000 | [diff] [blame] | 69 | uint32_t cachable:1; /* False if this is a shared surface */ |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 70 | uint32_t sampleCount:5; |
| 71 | uint32_t scanout:1; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | |
| 75 | struct svga_host_surface_cache_entry |
| 76 | { |
| 77 | /** |
| 78 | * Head for the LRU list, svga_host_surface_cache::unused, and |
| 79 | * svga_host_surface_cache::empty |
| 80 | */ |
| 81 | struct list_head head; |
| 82 | |
| 83 | /** Head for the bucket lists. */ |
| 84 | struct list_head bucket_head; |
| 85 | |
| 86 | struct svga_host_surface_cache_key key; |
| 87 | struct svga_winsys_surface *handle; |
| 88 | |
| 89 | struct pipe_fence_handle *fence; |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | /** |
| 94 | * Cache of the host surfaces. |
| 95 | * |
| 96 | * A cache entry can be in the following stages: |
Brian Paul | 500e7c5 | 2011-12-07 16:57:11 -0700 | [diff] [blame] | 97 | * 1. empty (entry->handle = NULL) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 98 | * 2. holding a buffer in a validate list |
Charmaine Lee | da98cee | 2016-03-08 11:18:51 -0800 | [diff] [blame] | 99 | * 3. holding a buffer in an invalidate list |
| 100 | * 4. holding a flushed buffer (not in any validate list) with an active fence |
| 101 | * 5. holding a flushed buffer with an expired fence |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 102 | * |
Charmaine Lee | da98cee | 2016-03-08 11:18:51 -0800 | [diff] [blame] | 103 | * An entry progresses from 1 -> 2 -> 3 -> 4 -> 5. When we need an entry to put a |
Brian Paul | 02bf645 | 2013-02-23 06:59:39 -0700 | [diff] [blame] | 104 | * buffer into we preferentially take from 1, or from the least recently used |
Charmaine Lee | da98cee | 2016-03-08 11:18:51 -0800 | [diff] [blame] | 105 | * buffer from 4/5. |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 106 | */ |
| 107 | struct svga_host_surface_cache |
| 108 | { |
Timothy Arceri | 2efddc6 | 2017-03-05 12:32:01 +1100 | [diff] [blame] | 109 | mtx_t mutex; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 110 | |
| 111 | /* Unused buffers are put in buckets to speed up lookups */ |
| 112 | struct list_head bucket[SVGA_HOST_SURFACE_CACHE_BUCKETS]; |
| 113 | |
| 114 | /* Entries with unused buffers, ordered from most to least recently used |
| 115 | * (3 and 4) */ |
| 116 | struct list_head unused; |
| 117 | |
Charmaine Lee | da98cee | 2016-03-08 11:18:51 -0800 | [diff] [blame] | 118 | /* Entries with buffers still in validate list (2) */ |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 119 | struct list_head validated; |
| 120 | |
Charmaine Lee | da98cee | 2016-03-08 11:18:51 -0800 | [diff] [blame] | 121 | /* Entries with buffers still in invalidate list (3) */ |
| 122 | struct list_head invalidated; |
| 123 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 124 | /** Empty entries (1) */ |
| 125 | struct list_head empty; |
| 126 | |
| 127 | /** The actual storage for the entries */ |
| 128 | struct svga_host_surface_cache_entry entries[SVGA_HOST_SURFACE_CACHE_SIZE]; |
Brian Paul | 500e7c5 | 2011-12-07 16:57:11 -0700 | [diff] [blame] | 129 | |
| 130 | /** Sum of sizes of all surfaces (in bytes) */ |
| 131 | unsigned total_size; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | |
| 135 | void |
| 136 | svga_screen_cache_cleanup(struct svga_screen *svgascreen); |
| 137 | |
| 138 | void |
| 139 | svga_screen_cache_flush(struct svga_screen *svgascreen, |
Charmaine Lee | 16bd2c6 | 2017-01-26 18:46:23 -0800 | [diff] [blame] | 140 | struct svga_context *svga, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 141 | struct pipe_fence_handle *fence); |
| 142 | |
| 143 | enum pipe_error |
| 144 | svga_screen_cache_init(struct svga_screen *svgascreen); |
| 145 | |
| 146 | |
| 147 | struct svga_winsys_surface * |
| 148 | svga_screen_surface_create(struct svga_screen *svgascreen, |
Brian Paul | 45078e8 | 2016-05-25 17:13:23 -0600 | [diff] [blame] | 149 | unsigned bind_flags, enum pipe_resource_usage usage, |
Charmaine Lee | 8a195e2 | 2016-10-26 16:15:23 -0700 | [diff] [blame] | 150 | boolean *validated, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 151 | struct svga_host_surface_cache_key *key); |
| 152 | |
| 153 | void |
| 154 | svga_screen_surface_destroy(struct svga_screen *svgascreen, |
| 155 | const struct svga_host_surface_cache_key *key, |
| 156 | struct svga_winsys_surface **handle); |
| 157 | |
Brian Paul | 0d1ee26 | 2012-10-17 09:55:54 -0600 | [diff] [blame] | 158 | void |
| 159 | svga_screen_cache_dump(const struct svga_screen *svgascreen); |
| 160 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 161 | |
| 162 | #endif /* SVGA_SCREEN_CACHE_H_ */ |