xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/ir3/ir3_cache.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2018 Rob Clark <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Rob Clark <[email protected]>
7  */
8 
9 #ifndef IR3_CACHE_H_
10 #define IR3_CACHE_H_
11 
12 #include "pipe/p_state.h"
13 
14 #include "ir3/ir3_shader.h"
15 
16 BEGINC;
17 
18 /*
19  * An in-memory cache for mapping shader state objects plus shader key to
20  * hw specific state object for the specified shader variant.  This is to
21  * allow re-using things like the register setup for varying linkage, etc.
22  */
23 
24 /* key into program state cache */
25 struct ir3_cache_key {
26    struct ir3_shader_state *vs, *hs, *ds, *gs, *fs; // 5 pointers
27    struct ir3_shader_key key;                       // 7 dwords
28 
29    /* Additional state that effects the cached program state, but
30     * not the compiled shader:
31     */
32    unsigned clip_plane_enable : PIPE_MAX_CLIP_PLANES;
33    unsigned patch_vertices;
34 };
35 
36 /* per-gen backend program state object should subclass this for it's
37  * state object, mainly because we need a copy of the key that is not
38  * allocated on the stack
39  */
40 struct ir3_program_state {
41    struct ir3_cache_key key;
42 };
43 
44 struct ir3_cache_funcs {
45    struct ir3_program_state *(*create_state)(
46       void *data, const struct ir3_shader_variant *bs, /* binning pass vs */
47       const struct ir3_shader_variant *vs, const struct ir3_shader_variant *hs,
48       const struct ir3_shader_variant *ds, const struct ir3_shader_variant *gs,
49       const struct ir3_shader_variant *fs, const struct ir3_cache_key *key);
50    void (*destroy_state)(void *data, struct ir3_program_state *state);
51 };
52 
53 struct ir3_cache;
54 
55 /* construct a shader cache.  Free with ralloc_free() */
56 struct ir3_cache *ir3_cache_create(const struct ir3_cache_funcs *funcs,
57                                    void *data);
58 void ir3_cache_destroy(struct ir3_cache *cache);
59 
60 /* debug callback is used for shader-db logs in case the lookup triggers
61  * shader variant compilation.
62  */
63 struct ir3_program_state *ir3_cache_lookup(struct ir3_cache *cache,
64                                            const struct ir3_cache_key *key,
65                                            struct util_debug_callback *debug);
66 
67 /* call when an API level state object is destroyed, to invalidate
68  * cache entries which reference that state object.
69  */
70 void ir3_cache_invalidate(struct ir3_cache *cache, void *stobj);
71 
72 ENDC;
73 
74 #endif /* IR3_CACHE_H_ */
75