xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/llvmpipe/lp_texture_handle.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2023 Valve Corporation
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
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef LP_SAMPLER_MATRIX
25 #define LP_SAMPLER_MATRIX
26 
27 #include "util/bitset.h"
28 #include "util/u_atomic.h"
29 #include "util/u_dynarray.h"
30 #include "util/format/u_format.h"
31 #include "util/simple_mtx.h"
32 #include "gallivm/lp_bld_sample.h"
33 #include "gallivm/lp_bld_jit_sample.h"
34 
35 struct lp_sampler_matrix {
36    struct lp_texture_functions **textures;
37    struct lp_static_sampler_state *samplers;
38 
39    uint32_t texture_count;
40    uint32_t sampler_count;
41 
42    BITSET_DECLARE(sample_keys, LP_SAMPLE_KEY_COUNT);
43    BITSET_DECLARE(image_ops, LP_TOTAL_IMAGE_OP_COUNT);
44 
45    /* Per sample key functions which compile and cache sample functions on demand. */
46    void *jit_sample_functions[LP_SAMPLE_KEY_COUNT];
47    void *compile_function;
48    p_atomic_uint64_t latest_cache;
49    struct util_dynarray trash_caches;
50    simple_mtx_t lock;
51 
52    struct llvmpipe_context *ctx;
53 
54    /* Use a separate LLVMContext since it is not thread safe but can be accessed by shaders. */
55    lp_context_ref context;
56 
57    struct util_dynarray gallivms;
58 };
59 
60 void llvmpipe_init_sampler_matrix(struct llvmpipe_context *ctx);
61 
62 void llvmpipe_sampler_matrix_destroy(struct llvmpipe_context *ctx);
63 
64 void llvmpipe_register_shader(struct pipe_context *ctx, const struct pipe_shader_state *shader);
65 
66 void llvmpipe_clear_sample_functions_cache(struct llvmpipe_context *ctx, struct pipe_fence_handle **fence);
67 
68 #endif /* LP_SAMPLER_MATRIX */
69