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