Branch data Line data Source code
1 : : /* 2 : : * This file is part of libplacebo. 3 : : * 4 : : * libplacebo is free software; you can redistribute it and/or 5 : : * modify it under the terms of the GNU Lesser General Public 6 : : * License as published by the Free Software Foundation; either 7 : : * version 2.1 of the License, or (at your option) any later version. 8 : : * 9 : : * libplacebo is distributed in the hope that it will be useful, 10 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : : * GNU Lesser General Public License for more details. 13 : : * 14 : : * You should have received a copy of the GNU Lesser General Public 15 : : * License along with libplacebo. If not, see <http://www.gnu.org/licenses/>. 16 : : */ 17 : : 18 : : #pragma once 19 : : 20 : : #include "common.h" 21 : : #include "hash.h" 22 : : 23 : : #include <libplacebo/cache.h> 24 : : 25 : : // Convenience wrapper around pl_cache_set 26 : : static inline void pl_cache_str(pl_cache cache, uint64_t key, pl_str *str) 27 : : { 28 : : pl_cache_set(cache, &(pl_cache_obj) { 29 : : .key = key, 30 : : .data = pl_steal(NULL, str->buf), 31 : : .size = str->len, 32 : : .free = pl_free, 33 : : }); 34 : : *str = (pl_str) {0}; 35 : : } 36 : : 37 : : // Steal and insert a cache object 38 : 482 : static inline void pl_cache_steal(pl_cache cache, pl_cache_obj *obj) 39 : : { 40 [ + + ]: 482 : if (obj->free == pl_free) 41 : 269 : obj->data = pl_steal(NULL, obj->data); 42 : 482 : pl_cache_set(cache, obj); 43 : 482 : } 44 : : 45 : : // Resize `obj->data` to a given size, re-using allocated buffers where possible 46 : 372 : static inline void pl_cache_obj_resize(void *alloc, pl_cache_obj *obj, size_t size) 47 : : { 48 [ + + ]: 372 : if (obj->free != pl_free) { 49 [ - + ]: 370 : if (obj->free) 50 : 0 : obj->free(obj->data); 51 : 370 : obj->data = pl_alloc(alloc, size); 52 : 370 : obj->free = pl_free; 53 [ - + ]: 2 : } else if (pl_get_size(obj->data) < size) { 54 : 0 : obj->data = pl_steal(alloc, obj->data); 55 : 0 : obj->data = pl_realloc(alloc, obj->data, size); 56 : : } 57 : 372 : obj->size = size; 58 : 372 : } 59 : : 60 : : // Internal list of base seeds for different object types, randomly generated 61 : : 62 : : enum { 63 : : CACHE_KEY_SH_LUT = UINT64_C(0x2206183d320352c6), // sh_lut cache 64 : : CACHE_KEY_ICC_3DLUT = UINT64_C(0xff703a6dd8a996f6), // ICC 3dlut 65 : : CACHE_KEY_DITHER = UINT64_C(0x6fed75eb6dce86cb), // dither matrix 66 : : CACHE_KEY_H274 = UINT64_C(0x2fb9adca04b42c4d), // H.274 film grain DB 67 : : CACHE_KEY_GAMUT_LUT = UINT64_C(0x6109e47f15d478b1), // gamut mapping 3DLUT 68 : : CACHE_KEY_SPIRV = UINT64_C(0x32352f6605ff60a7), // bare SPIR-V module 69 : : CACHE_KEY_VK_PIPE = UINT64_C(0x4bdab2817ad02ad4), // VkPipelineCache 70 : : CACHE_KEY_GL_PROG = UINT64_C(0x4274c309f4f0477b), // GL_ARB_get_program_binary 71 : : CACHE_KEY_D3D_DXBC = UINT64_C(0x5c9e6f43ec73f787), // DXBC bytecode 72 : : };