1 /* 2 * Copyright 2021 Advanced Micro Devices, Inc. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * on the rights to use, copy, modify, merge, publish, distribute, sub 9 * license, and/or sell copies of the Software, and to permit persons to whom 10 * the Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22 * USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 /* This deduplicates pipe_vertex_state CSOs to enable draw merging in 26 * u_threaded_context because the draw merging is possible only if different 27 * display lists use the same pipe_vertex_state CSO. 28 */ 29 30 #ifndef U_VERTEX_STATE_CACHE_H 31 #define U_VERTEX_STATE_CACHE_H 32 33 #include "util/simple_mtx.h" 34 #include "pipe/p_screen.h" 35 #include "pipe/p_state.h" 36 37 struct util_vertex_state_cache { 38 simple_mtx_t lock; 39 struct set *set; 40 41 pipe_create_vertex_state_func create; 42 pipe_vertex_state_destroy_func destroy; 43 }; 44 45 void 46 util_vertex_state_cache_init(struct util_vertex_state_cache *cache, 47 pipe_create_vertex_state_func create, 48 pipe_vertex_state_destroy_func destroy); 49 50 void 51 util_vertex_state_cache_deinit(struct util_vertex_state_cache *cache); 52 53 struct pipe_vertex_state * 54 util_vertex_state_cache_get(struct pipe_screen *screen, 55 struct pipe_vertex_buffer *buffer, 56 const struct pipe_vertex_element *elements, 57 unsigned num_elements, 58 struct pipe_resource *indexbuf, 59 uint32_t full_velem_mask, 60 struct util_vertex_state_cache *cache); 61 62 void 63 util_vertex_state_destroy(struct pipe_screen *screen, 64 struct util_vertex_state_cache *cache, 65 struct pipe_vertex_state *state); 66 67 #endif 68