2 * Copyright (C) 2018 Rob Clark <robclark@freedesktop.org>
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:
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
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
24 * Rob Clark <robclark@freedesktop.org>
30 #include "ir3/ir3_shader.h"
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.
38 /* key into program state cache */
39 struct ir3_cache_key
{
40 struct ir3_shader
*vs
, *hs
, *ds
, *gs
, *fs
; // 5 pointers
41 struct ir3_shader_key key
; // 7 dwords
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
48 struct ir3_program_state
{
49 struct ir3_cache_key key
;
52 struct 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
*hs
,
57 struct ir3_shader_variant
*ds
,
58 struct ir3_shader_variant
*gs
,
59 struct ir3_shader_variant
*fs
,
60 const struct ir3_shader_key
*key
);
61 void (*destroy_state
)(void *data
, struct ir3_program_state
*state
);
66 /* construct a shader cache. Free with ralloc_free() */
67 struct ir3_cache
* ir3_cache_create(const struct ir3_cache_funcs
*funcs
, void *data
);
68 void ir3_cache_destroy(struct ir3_cache
*cache
);
70 /* debug callback is used for shader-db logs in case the lookup triggers
71 * shader variant compilation.
73 struct ir3_program_state
* ir3_cache_lookup(struct ir3_cache
*cache
,
74 const struct ir3_cache_key
*key
,
75 struct pipe_debug_callback
*debug
);
77 /* call when an API level state object is destroyed, to invalidate
78 * cache entries which reference that state object.
80 void ir3_cache_invalidate(struct ir3_cache
*cache
, void *stobj
);
82 #endif /* IR3_CACHE_H_ */