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 */ 39struct ir3_cache_key { 40 struct ir3_shader *vs, *fs; // 4 dwords 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 */ 48struct ir3_program_state { 49 struct ir3_cache_key key; 50}; 51 52struct ir3_cache_funcs { 53 struct ir3_program_state *(*create_state)(void *data, 54 struct ir3_shader_variant *bs, /* binning pass vs */ 55 struct ir3_shader_variant *vs, 56 struct ir3_shader_variant *fs, 57 const struct ir3_shader_key *key); 58 void (*destroy_state)(void *data, struct ir3_program_state *state); 59}; 60 61struct ir3_cache; 62 63/* construct a shader cache. Free with ralloc_free() */ 64struct ir3_cache * ir3_cache_create(const struct ir3_cache_funcs *funcs, void *data); 65void ir3_cache_destroy(struct ir3_cache *cache); 66 67/* debug callback is used for shader-db logs in case the lookup triggers 68 * shader variant compilation. 69 */ 70struct ir3_program_state * ir3_cache_lookup(struct ir3_cache *cache, 71 const struct ir3_cache_key *key, 72 struct pipe_debug_callback *debug); 73 74/* call when an API level state object is destroyed, to invalidate 75 * cache entries which reference that state object. 76 */ 77void ir3_cache_invalidate(struct ir3_cache *cache, void *stobj); 78 79#endif /* IR3_CACHE_H_ */ 80