1 /* 2 * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Authors: 24 * Rob Clark <robclark@freedesktop.org> 25 */ 26 27 #ifndef IR3_CACHE_H_ 28 #define IR3_CACHE_H_ 29 30 #include "pipe/p_state.h" 31 32 #include "ir3/ir3_shader.h" 33 34 BEGINC; 35 36 /* 37 * An in-memory cache for mapping shader state objects plus shader key to 38 * hw specific state object for the specified shader variant. This is to 39 * allow re-using things like the register setup for varying linkage, etc. 40 */ 41 42 /* key into program state cache */ 43 struct ir3_cache_key { 44 struct ir3_shader_state *vs, *hs, *ds, *gs, *fs; // 5 pointers 45 struct ir3_shader_key key; // 7 dwords 46 47 /* Additional state that effects the cached program state, but 48 * not the compiled shader: 49 */ 50 unsigned clip_plane_enable : PIPE_MAX_CLIP_PLANES; 51 unsigned patch_vertices; 52 }; 53 54 /* per-gen backend program state object should subclass this for it's 55 * state object, mainly because we need a copy of the key that is not 56 * allocated on the stack 57 */ 58 struct ir3_program_state { 59 struct ir3_cache_key key; 60 }; 61 62 struct ir3_cache_funcs { 63 struct ir3_program_state *(*create_state)( 64 void *data, const struct ir3_shader_variant *bs, /* binning pass vs */ 65 const struct ir3_shader_variant *vs, const struct ir3_shader_variant *hs, 66 const struct ir3_shader_variant *ds, const struct ir3_shader_variant *gs, 67 const struct ir3_shader_variant *fs, const struct ir3_cache_key *key); 68 void (*destroy_state)(void *data, struct ir3_program_state *state); 69 }; 70 71 struct ir3_cache; 72 73 /* construct a shader cache. Free with ralloc_free() */ 74 struct ir3_cache *ir3_cache_create(const struct ir3_cache_funcs *funcs, 75 void *data); 76 void ir3_cache_destroy(struct ir3_cache *cache); 77 78 /* debug callback is used for shader-db logs in case the lookup triggers 79 * shader variant compilation. 80 */ 81 struct ir3_program_state *ir3_cache_lookup(struct ir3_cache *cache, 82 const struct ir3_cache_key *key, 83 struct util_debug_callback *debug); 84 85 /* call when an API level state object is destroyed, to invalidate 86 * cache entries which reference that state object. 87 */ 88 void ir3_cache_invalidate(struct ir3_cache *cache, void *stobj); 89 90 ENDC; 91 92 #endif /* IR3_CACHE_H_ */ 93