Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_texture.h
4574 views
1
/*
2
* Copyright (C) 2016 Rob Clark <[email protected]>
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 <[email protected]>
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 "fd6_format.h"
38
39
struct fd6_sampler_stateobj {
40
struct pipe_sampler_state base;
41
uint32_t texsamp0, texsamp1, texsamp2, texsamp3;
42
bool needs_border;
43
uint16_t seqno;
44
};
45
46
static inline struct fd6_sampler_stateobj *
47
fd6_sampler_stateobj(struct pipe_sampler_state *samp)
48
{
49
return (struct fd6_sampler_stateobj *)samp;
50
}
51
52
struct fd6_pipe_sampler_view {
53
struct pipe_sampler_view base;
54
uint32_t texconst0, texconst1, texconst2, texconst3, texconst5;
55
uint32_t texconst6, texconst7, texconst8, texconst9, texconst10, texconst11;
56
uint32_t offset1, offset2;
57
struct fd_resource *ptr1, *ptr2;
58
uint16_t seqno;
59
60
/* For detecting when a resource has transitioned from UBWC compressed
61
* to uncompressed, which means the sampler state needs to be updated
62
*/
63
uint16_t rsc_seqno;
64
65
bool needs_validate;
66
};
67
68
static inline struct fd6_pipe_sampler_view *
69
fd6_pipe_sampler_view(struct pipe_sampler_view *pview)
70
{
71
return (struct fd6_pipe_sampler_view *)pview;
72
}
73
74
void fd6_sampler_view_update(struct fd_context *ctx,
75
struct fd6_pipe_sampler_view *so) assert_dt;
76
77
void fd6_texture_init(struct pipe_context *pctx);
78
void fd6_texture_fini(struct pipe_context *pctx);
79
80
static inline enum a6xx_tex_type
81
fd6_tex_type(unsigned target)
82
{
83
switch (target) {
84
default:
85
assert(0);
86
case PIPE_BUFFER:
87
case PIPE_TEXTURE_1D:
88
case PIPE_TEXTURE_1D_ARRAY:
89
return A6XX_TEX_1D;
90
case PIPE_TEXTURE_RECT:
91
case PIPE_TEXTURE_2D:
92
case PIPE_TEXTURE_2D_ARRAY:
93
return A6XX_TEX_2D;
94
case PIPE_TEXTURE_3D:
95
return A6XX_TEX_3D;
96
case PIPE_TEXTURE_CUBE:
97
case PIPE_TEXTURE_CUBE_ARRAY:
98
return A6XX_TEX_CUBE;
99
}
100
}
101
102
static inline unsigned
103
fd6_border_color_offset(struct fd_context *ctx, enum pipe_shader_type type,
104
struct fd_texture_stateobj *tex) assert_dt
105
{
106
/* Currently we put the FS border-color state after VS. Possibly
107
* we could swap the order.
108
*
109
* This will need update for HS/DS/GS
110
*/
111
if (type != PIPE_SHADER_FRAGMENT)
112
return 0;
113
114
unsigned needs_border = false;
115
116
for (unsigned i = 0; i < tex->num_samplers; i++) {
117
if (!tex->samplers[i])
118
continue;
119
120
struct fd6_sampler_stateobj *sampler =
121
fd6_sampler_stateobj(tex->samplers[i]);
122
123
needs_border |= sampler->needs_border;
124
}
125
126
if (!needs_border)
127
return 0;
128
129
return ctx->tex[PIPE_SHADER_VERTEX].num_samplers;
130
}
131
132
/*
133
* Texture stateobj:
134
*
135
* The sampler and sampler-view state is mapped to a single hardware
136
* stateobj which can be emit'd as a pointer in a CP_SET_DRAW_STATE
137
* packet, to avoid the overhead of re-generating the entire cmdstream
138
* when application toggles thru multiple different texture states.
139
*/
140
141
struct fd6_texture_key {
142
struct {
143
/* We need to track the seqno of the rsc as well as of the
144
* sampler view, because resource shadowing/etc can result
145
* that the underlying bo changes (which means the previous
146
* state was no longer valid.
147
*/
148
uint16_t rsc_seqno;
149
uint16_t seqno;
150
} view[16];
151
struct {
152
uint16_t seqno;
153
} samp[16];
154
uint8_t type;
155
uint8_t bcolor_offset;
156
};
157
158
struct fd6_texture_state {
159
struct pipe_reference reference;
160
struct fd6_texture_key key;
161
struct fd_ringbuffer *stateobj;
162
bool needs_border;
163
};
164
165
struct fd6_texture_state *
166
fd6_texture_state(struct fd_context *ctx, enum pipe_shader_type type,
167
struct fd_texture_stateobj *tex) assert_dt;
168
169
/* not called directly: */
170
void __fd6_texture_state_describe(char *buf,
171
const struct fd6_texture_state *tex);
172
void __fd6_texture_state_destroy(struct fd6_texture_state *tex);
173
174
static inline void
175
fd6_texture_state_reference(struct fd6_texture_state **ptr,
176
struct fd6_texture_state *tex)
177
{
178
struct fd6_texture_state *old_tex = *ptr;
179
180
if (pipe_reference_described(
181
&(*ptr)->reference, &tex->reference,
182
(debug_reference_descriptor)__fd6_texture_state_describe))
183
__fd6_texture_state_destroy(old_tex);
184
185
*ptr = tex;
186
}
187
188
#endif /* FD6_TEXTURE_H_ */
189
190