mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 15:56:01 +00:00
fix(venus): destroying a null handle no longer grows the Mali layer's maps (#3101)
The handle maps use key 0 for an empty slot. vkDestroyBuffer, vkFreeMemory and the other destroy calls accept VK_NULL_HANDLE, and map_remove(0) matched the first empty slot it reached, so every such call lowered count without removing anything. Once count wrapped below zero, every map_put saw a full table and doubled it, and each rehash took twice as long as the one before. Steam's web helper frees null buffers about 50,000 times in a few minutes. On a Mali-G610 its UI stalled periodically for 0.2 s, 0.37 s, 0.75 s, 1.5 s and then 3 s, and the buffer map reported a count of 4294967295. map_get, map_put and map_remove now ignore key 0. On a Nothing Phone (2a) running 0.7.1 with this change, the buffer map stayed at 256 slots after 115,000 frees and the stalls were gone.
This commit is contained in:
1 parent
1f82db66ac
commit
6e252ea3ad
2 files changed
+26
-2
No files matched your search
@@ -182,6 +182,25 @@ static void test_spirv(const char *directory)
|
|||||||
assert(!spirv_strip_dual_source(truncated, 5, &out));
|
assert(!spirv_strip_dual_source(truncated, 5, &out));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_handle_map_null_key(void)
|
||||||
|
{
|
||||||
|
struct handle_map map = {0};
|
||||||
|
int first, second;
|
||||||
|
map_put(&map, 0x1000, &first);
|
||||||
|
map_put(&map, 0x2000, &second);
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
assert(!map_remove(&map, 0));
|
||||||
|
map_put(&map, 0, &first);
|
||||||
|
assert(map.count == 2 && !map_get(&map, 0));
|
||||||
|
for (uint64_t key = 1; key <= 30; key++) {
|
||||||
|
map_put(&map, 0x100000 + key, &first);
|
||||||
|
assert(map_remove(&map, 0x100000 + key) == &first);
|
||||||
|
}
|
||||||
|
assert(map.count == 2 && map.capacity == 64);
|
||||||
|
assert(map_get(&map, 0x1000) == &first && map_get(&map, 0x2000) == &second);
|
||||||
|
map_free(&map);
|
||||||
|
}
|
||||||
|
|
||||||
static VkResult VKAPI_CALL mock_create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator,
|
static VkResult VKAPI_CALL mock_create_instance(const VkInstanceCreateInfo *info, const VkAllocationCallbacks *allocator,
|
||||||
VkInstance *instance)
|
VkInstance *instance)
|
||||||
{
|
{
|
||||||
@@ -464,6 +483,7 @@ static void test_capable_device(void)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
test_spirv(argc > 1 ? argv[1] : NULL);
|
test_spirv(argc > 1 ? argv[1] : NULL);
|
||||||
|
test_handle_map_null_key();
|
||||||
|
|
||||||
setenv("WINEPREFIX", "/nonexistent", 1);
|
setenv("WINEPREFIX", "/nonexistent", 1);
|
||||||
unsetenv("DROIDDECK_MALI_COMPAT");
|
unsetenv("DROIDDECK_MALI_COMPAT");
|
||||||
|
|||||||
@@ -60,9 +60,11 @@ static uint64_t hash(uint64_t key)
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Key 0 marks an empty slot, so VK_NULL_HANDLE is never looked up, stored or removed. Destroying a
|
||||||
|
* null handle is valid Vulkan, and map_remove(0) would otherwise match an empty slot and drop count. */
|
||||||
void *map_get(const struct handle_map *map, uint64_t key)
|
void *map_get(const struct handle_map *map, uint64_t key)
|
||||||
{
|
{
|
||||||
if (!map->capacity)
|
if (!map->capacity || !key)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (uint32_t i = hash(key) & (map->capacity - 1);; i = (i + 1) & (map->capacity - 1)) {
|
for (uint32_t i = hash(key) & (map->capacity - 1);; i = (i + 1) & (map->capacity - 1)) {
|
||||||
if (map->keys[i] == key)
|
if (map->keys[i] == key)
|
||||||
@@ -90,6 +92,8 @@ static void map_grow(struct handle_map *map)
|
|||||||
|
|
||||||
void map_put(struct handle_map *map, uint64_t key, void *value)
|
void map_put(struct handle_map *map, uint64_t key, void *value)
|
||||||
{
|
{
|
||||||
|
if (!key)
|
||||||
|
return;
|
||||||
if ((map->count + 1) * 4 > map->capacity * 3)
|
if ((map->count + 1) * 4 > map->capacity * 3)
|
||||||
map_grow(map);
|
map_grow(map);
|
||||||
uint32_t i = hash(key) & (map->capacity - 1);
|
uint32_t i = hash(key) & (map->capacity - 1);
|
||||||
@@ -103,7 +107,7 @@ void map_put(struct handle_map *map, uint64_t key, void *value)
|
|||||||
|
|
||||||
void *map_remove(struct handle_map *map, uint64_t key)
|
void *map_remove(struct handle_map *map, uint64_t key)
|
||||||
{
|
{
|
||||||
if (!map->capacity)
|
if (!map->capacity || !key)
|
||||||
return NULL;
|
return NULL;
|
||||||
uint32_t mask = map->capacity - 1;
|
uint32_t mask = map->capacity - 1;
|
||||||
uint32_t i = hash(key) & mask;
|
uint32_t i = hash(key) & mask;
|
||||||
|
|||||||
Reference in new issue
Block a user