xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/a6xx/fd6_texture.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2016 Rob Clark <[email protected]>
3  * Copyright © 2018 Google, Inc.
4  * SPDX-License-Identifier: MIT
5  *
6  * Authors:
7  *    Rob Clark <[email protected]>
8  */
9 
10 #ifndef FD6_TEXTURE_H_
11 #define FD6_TEXTURE_H_
12 
13 #include "pipe/p_context.h"
14 
15 #include "freedreno_resource.h"
16 #include "freedreno_texture.h"
17 
18 #include "fd6_context.h"
19 #include "fdl/fd6_format_table.h"
20 
21 
22 BEGINC;
23 
24 /* Border color layout is diff from a4xx/a5xx.. if it turns out to be
25  * the same as a6xx then move this somewhere common ;-)
26  *
27  * Entry layout looks like (total size, 0x80 bytes):
28  */
29 
30 struct PACKED fd6_bcolor_entry {
31    uint32_t fp32[4];
32    uint16_t ui16[4];
33    int16_t si16[4];
34    uint16_t fp16[4];
35    uint16_t rgb565;
36    uint16_t rgb5a1;
37    uint16_t rgba4;
38    uint8_t __pad0[2];
39    uint8_t ui8[4];
40    int8_t si8[4];
41    uint32_t rgb10a2;
42    uint32_t z24;
43    uint16_t srgb[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
44    uint8_t __pad1[56];
45 };
46 
47 #define FD6_BORDER_COLOR_SIZE sizeof(struct fd6_bcolor_entry)
48 #define FD6_MAX_BORDER_COLORS 256
49 
50 struct fd6_sampler_stateobj {
51    struct pipe_sampler_state base;
52    uint32_t texsamp0, texsamp1, texsamp2, texsamp3;
53    uint16_t seqno;
54 };
55 
56 static inline struct fd6_sampler_stateobj *
fd6_sampler_stateobj(struct pipe_sampler_state * samp)57 fd6_sampler_stateobj(struct pipe_sampler_state *samp)
58 {
59    return (struct fd6_sampler_stateobj *)samp;
60 }
61 
62 struct fd6_pipe_sampler_view {
63    struct pipe_sampler_view base;
64    struct fd_resource *ptr1, *ptr2;
65    uint16_t seqno;
66 
67    /* TEX_CONST descriptor, with just offsets from the BOs in the iova dwords. */
68    uint32_t descriptor[FDL6_TEX_CONST_DWORDS];
69 
70    /* For detecting when a resource has transitioned from UBWC compressed
71     * to uncompressed, which means the sampler state needs to be updated
72     */
73    uint16_t rsc_seqno;
74 };
75 
76 static inline struct fd6_pipe_sampler_view *
fd6_pipe_sampler_view(struct pipe_sampler_view * pview)77 fd6_pipe_sampler_view(struct pipe_sampler_view *pview)
78 {
79    return (struct fd6_pipe_sampler_view *)pview;
80 }
81 
82 void fd6_texture_init(struct pipe_context *pctx);
83 void fd6_texture_fini(struct pipe_context *pctx);
84 
85 /*
86  * Texture stateobj:
87  *
88  * The sampler and sampler-view state is mapped to a single hardware
89  * stateobj which can be emit'd as a pointer in a CP_SET_DRAW_STATE
90  * packet, to avoid the overhead of re-generating the entire cmdstream
91  * when application toggles thru multiple different texture states.
92  */
93 
94 struct fd6_texture_key {
95    uint16_t view_seqno[16];
96    uint16_t samp_seqno[16];
97    uint8_t type;
98 };
99 
100 struct fd6_texture_state {
101    struct fd6_texture_key key;
102    struct fd_ringbuffer *stateobj;
103    /**
104     * Track the rsc seqno's associated with the texture views so
105     * we know what to invalidate when a rsc is rebound when the
106     * underlying bo changes.  (For example, demotion from UBWC.)
107     */
108    uint16_t view_rsc_seqno[16];
109    bool invalidate;
110 };
111 
112 struct fd6_texture_state *
113 fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type) assert_dt;
114 
115 ENDC;
116 
117 #endif /* FD6_TEXTURE_H_ */
118