• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
3  * Copyright © 2018 Google, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * Authors:
25  *    Rob Clark <robclark@freedesktop.org>
26  */
27 
28 #ifndef FD6_TEXTURE_H_
29 #define FD6_TEXTURE_H_
30 
31 #include "pipe/p_context.h"
32 
33 #include "freedreno_resource.h"
34 #include "freedreno_texture.h"
35 
36 #include "fd6_context.h"
37 #include "fdl/fd6_format_table.h"
38 
39 
40 BEGINC;
41 
42 /* Border color layout is diff from a4xx/a5xx.. if it turns out to be
43  * the same as a6xx then move this somewhere common ;-)
44  *
45  * Entry layout looks like (total size, 0x80 bytes):
46  */
47 
48 struct PACKED fd6_bcolor_entry {
49    uint32_t fp32[4];
50    uint16_t ui16[4];
51    int16_t si16[4];
52    uint16_t fp16[4];
53    uint16_t rgb565;
54    uint16_t rgb5a1;
55    uint16_t rgba4;
56    uint8_t __pad0[2];
57    uint8_t ui8[4];
58    int8_t si8[4];
59    uint32_t rgb10a2;
60    uint32_t z24;
61    uint16_t srgb[4]; /* appears to duplicate fp16[], but clamped, used for srgb */
62    uint8_t __pad1[56];
63 };
64 
65 #define FD6_BORDER_COLOR_SIZE sizeof(struct fd6_bcolor_entry)
66 #define FD6_MAX_BORDER_COLORS 256
67 
68 struct fd6_sampler_stateobj {
69    struct pipe_sampler_state base;
70    uint32_t texsamp0, texsamp1, texsamp2, texsamp3;
71    uint16_t seqno;
72 };
73 
74 static inline struct fd6_sampler_stateobj *
fd6_sampler_stateobj(struct pipe_sampler_state * samp)75 fd6_sampler_stateobj(struct pipe_sampler_state *samp)
76 {
77    return (struct fd6_sampler_stateobj *)samp;
78 }
79 
80 struct fd6_pipe_sampler_view {
81    struct pipe_sampler_view base;
82    struct fd_resource *ptr1, *ptr2;
83    uint16_t seqno;
84 
85    /* TEX_CONST descriptor, with just offsets from the BOs in the iova dwords. */
86    uint32_t descriptor[FDL6_TEX_CONST_DWORDS];
87 
88    /* For detecting when a resource has transitioned from UBWC compressed
89     * to uncompressed, which means the sampler state needs to be updated
90     */
91    uint16_t rsc_seqno;
92 };
93 
94 static inline struct fd6_pipe_sampler_view *
fd6_pipe_sampler_view(struct pipe_sampler_view * pview)95 fd6_pipe_sampler_view(struct pipe_sampler_view *pview)
96 {
97    return (struct fd6_pipe_sampler_view *)pview;
98 }
99 
100 void fd6_texture_init(struct pipe_context *pctx);
101 void fd6_texture_fini(struct pipe_context *pctx);
102 
103 /*
104  * Texture stateobj:
105  *
106  * The sampler and sampler-view state is mapped to a single hardware
107  * stateobj which can be emit'd as a pointer in a CP_SET_DRAW_STATE
108  * packet, to avoid the overhead of re-generating the entire cmdstream
109  * when application toggles thru multiple different texture states.
110  */
111 
112 struct fd6_texture_key {
113    uint16_t view_seqno[16];
114    uint16_t samp_seqno[16];
115    uint8_t type;
116 };
117 
118 struct fd6_texture_state {
119    struct fd6_texture_key key;
120    struct fd_ringbuffer *stateobj;
121    /**
122     * Track the rsc seqno's associated with the texture views so
123     * we know what to invalidate when a rsc is rebound when the
124     * underlying bo changes.  (For example, demotion from UBWC.)
125     */
126    uint16_t view_rsc_seqno[16];
127    bool invalidate;
128 };
129 
130 struct fd6_texture_state *
131 fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type) assert_dt;
132 
133 ENDC;
134 
135 #endif /* FD6_TEXTURE_H_ */
136