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 "ir3/ir3_shader.h" 31 32 /* 33 * An in-memory cache for mapping shader state objects plus shader key to 34 * hw specific state object for the specified shader variant. This is to 35 * allow re-using things like the register setup for varying linkage, etc. 36 */ 37 38 /* key into program state cache */ 39 struct ir3_cache_key { 40 struct ir3_shader_state *vs, *hs, *ds, *gs, *fs; // 5 pointers 41 struct ir3_shader_key key; // 7 dwords 42 }; 43 44 /* per-gen backend program state object should subclass this for it's 45 * state object, mainly because we need a copy of the key that is not 46 * allocated on the stack 47 */ 48 struct ir3_program_state { 49 struct ir3_cache_key key; 50 }; 51 52 struct ir3_cache_funcs { 53 struct ir3_program_state *(*create_state)( 54 void *data, struct ir3_shader_variant *bs, /* binning pass vs */ 55 struct ir3_shader_variant *vs, struct ir3_shader_variant *hs, 56 struct ir3_shader_variant *ds, struct ir3_shader_variant *gs, 57 struct ir3_shader_variant *fs, const struct ir3_shader_key *key); 58 void (*destroy_state)(void *data, struct ir3_program_state *state); 59 }; 60 61 struct ir3_cache; 62 63 /* construct a shader cache. Free with ralloc_free() */ 64 struct ir3_cache *ir3_cache_create(const struct ir3_cache_funcs *funcs, 65 void *data); 66 void ir3_cache_destroy(struct ir3_cache *cache); 67 68 /* debug callback is used for shader-db logs in case the lookup triggers 69 * shader variant compilation. 70 */ 71 struct ir3_program_state *ir3_cache_lookup(struct ir3_cache *cache, 72 const struct ir3_cache_key *key, 73 struct pipe_debug_callback *debug); 74 75 /* call when an API level state object is destroyed, to invalidate 76 * cache entries which reference that state object. 77 */ 78 void ir3_cache_invalidate(struct ir3_cache *cache, void *stobj); 79 80 #endif /* IR3_CACHE_H_ */ 81