xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/svga/svga_sampler_view.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 2008-2024 Broadcom. All Rights Reserved.
3  * The term “Broadcom” refers to Broadcom Inc.
4  * and/or its subsidiaries.
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #ifndef SVGA_SAMPLER_VIEW_H
9 #define SVGA_SAMPLER_VIEW_H
10 
11 
12 #include "util/compiler.h"
13 #include "pipe/p_state.h"
14 #include "util/u_inlines.h"
15 #include "svga_screen_cache.h"
16 
17 struct pipe_context;
18 struct pipe_screen;
19 struct svga_context;
20 struct svga_pipe_sampler_view;
21 struct svga_winsys_surface;
22 struct svga_surface;
23 enum SVGA3dSurfaceFormat;
24 
25 
26 /**
27  * A sampler's view into a texture
28  *
29  * We currently cache one sampler view on
30  * the texture and in there by holding a reference
31  * from the texture to the sampler view.
32  *
33  * Because of this we can not hold a refernce to the
34  * texture from the sampler view. So the user
35  * of the sampler views must make sure that the
36  * texture has a reference take for as long as
37  * the sampler view is refrenced.
38  *
39  * Just unreferencing the sampler_view before the
40  * texture is enough.
41  */
42 struct svga_sampler_view
43 {
44    struct pipe_reference reference;
45 
46    struct pipe_resource *texture;
47 
48    int min_lod;
49    int max_lod;
50 
51    unsigned age;
52 
53    struct svga_host_surface_cache_key key;
54    struct svga_winsys_surface *handle;
55 };
56 
57 
58 
59 extern struct svga_sampler_view *
60 svga_get_tex_sampler_view(struct pipe_context *pipe,
61                           struct pipe_resource *pt,
62                           unsigned min_lod, unsigned max_lod);
63 
64 void
65 svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v);
66 
67 void
68 svga_destroy_sampler_view_priv(struct svga_sampler_view *v);
69 
70 void
71 svga_debug_describe_sampler_view(char *buf, const struct svga_sampler_view *sv);
72 
73 static inline void
svga_sampler_view_reference(struct svga_sampler_view ** ptr,struct svga_sampler_view * v)74 svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v)
75 {
76    struct svga_sampler_view *old = *ptr;
77 
78    if (pipe_reference_described(&(*ptr)->reference, &v->reference,
79                                 (debug_reference_descriptor)svga_debug_describe_sampler_view))
80       svga_destroy_sampler_view_priv(old);
81    *ptr = v;
82 }
83 
84 bool
85 svga_check_sampler_view_resource_collision(const struct svga_context *svga,
86                                            const struct svga_winsys_surface *res,
87                                            enum pipe_shader_type shader);
88 
89 bool
90 svga_check_sampler_framebuffer_resource_collision(struct svga_context *svga,
91                                                   enum pipe_shader_type shader);
92 
93 enum pipe_error
94 svga_validate_pipe_sampler_view(struct svga_context *svga,
95                                 struct svga_pipe_sampler_view *sv);
96 
97 #endif
98