Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/freedreno_texture.c
4570 views
1
/*
2
* Copyright (C) 2012 Rob Clark <[email protected]>
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 FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
* Authors:
24
* Rob Clark <[email protected]>
25
*/
26
27
#include "pipe/p_state.h"
28
#include "util/u_inlines.h"
29
#include "util/u_memory.h"
30
#include "util/u_string.h"
31
32
#include "freedreno_context.h"
33
#include "freedreno_resource.h"
34
#include "freedreno_texture.h"
35
#include "freedreno_util.h"
36
37
static void
38
fd_sampler_state_delete(struct pipe_context *pctx, void *hwcso)
39
{
40
FREE(hwcso);
41
}
42
43
static void
44
fd_sampler_view_destroy(struct pipe_context *pctx,
45
struct pipe_sampler_view *view)
46
{
47
pipe_resource_reference(&view->texture, NULL);
48
FREE(view);
49
}
50
51
static void
52
bind_sampler_states(struct fd_texture_stateobj *tex, unsigned start,
53
unsigned nr, void **hwcso)
54
{
55
unsigned i;
56
57
for (i = 0; i < nr; i++) {
58
unsigned p = i + start;
59
tex->samplers[p] = hwcso[i];
60
if (tex->samplers[p])
61
tex->valid_samplers |= (1 << p);
62
else
63
tex->valid_samplers &= ~(1 << p);
64
}
65
66
tex->num_samplers = util_last_bit(tex->valid_samplers);
67
}
68
69
static void
70
set_sampler_views(struct fd_texture_stateobj *tex, unsigned start, unsigned nr,
71
unsigned unbind_num_trailing_slots,
72
struct pipe_sampler_view **views)
73
{
74
unsigned i;
75
76
for (i = 0; i < nr; i++) {
77
struct pipe_sampler_view *view = views ? views[i] : NULL;
78
unsigned p = i + start;
79
pipe_sampler_view_reference(&tex->textures[p], view);
80
if (tex->textures[p]) {
81
fd_resource_set_usage(tex->textures[p]->texture, FD_DIRTY_TEX);
82
tex->valid_textures |= (1 << p);
83
} else {
84
tex->valid_textures &= ~(1 << p);
85
}
86
}
87
for (; i < nr + unbind_num_trailing_slots; i++) {
88
unsigned p = i + start;
89
pipe_sampler_view_reference(&tex->textures[p], NULL);
90
tex->valid_textures &= ~(1 << p);
91
}
92
93
tex->num_textures = util_last_bit(tex->valid_textures);
94
}
95
96
void
97
fd_sampler_states_bind(struct pipe_context *pctx, enum pipe_shader_type shader,
98
unsigned start, unsigned nr, void **hwcso) in_dt
99
{
100
struct fd_context *ctx = fd_context(pctx);
101
102
bind_sampler_states(&ctx->tex[shader], start, nr, hwcso);
103
fd_context_dirty_shader(ctx, shader, FD_DIRTY_SHADER_TEX);
104
}
105
106
void
107
fd_set_sampler_views(struct pipe_context *pctx, enum pipe_shader_type shader,
108
unsigned start, unsigned nr,
109
unsigned unbind_num_trailing_slots,
110
struct pipe_sampler_view **views) in_dt
111
{
112
struct fd_context *ctx = fd_context(pctx);
113
114
set_sampler_views(&ctx->tex[shader], start, nr, unbind_num_trailing_slots,
115
views);
116
fd_context_dirty_shader(ctx, shader, FD_DIRTY_SHADER_TEX);
117
}
118
119
void
120
fd_texture_init(struct pipe_context *pctx)
121
{
122
if (!pctx->delete_sampler_state)
123
pctx->delete_sampler_state = fd_sampler_state_delete;
124
if (!pctx->sampler_view_destroy)
125
pctx->sampler_view_destroy = fd_sampler_view_destroy;
126
}
127
128
/* helper for setting up border-color buffer for a3xx/a4xx: */
129
void
130
fd_setup_border_colors(struct fd_texture_stateobj *tex, void *ptr,
131
unsigned offset)
132
{
133
unsigned i, j;
134
135
for (i = 0; i < tex->num_samplers; i++) {
136
struct pipe_sampler_state *sampler = tex->samplers[i];
137
uint16_t *bcolor =
138
(uint16_t *)((uint8_t *)ptr + (BORDERCOLOR_SIZE * offset) +
139
(BORDERCOLOR_SIZE * i));
140
uint32_t *bcolor32 = (uint32_t *)&bcolor[16];
141
142
if (!sampler)
143
continue;
144
145
/*
146
* XXX HACK ALERT XXX
147
*
148
* The border colors need to be swizzled in a particular
149
* format-dependent order. Even though samplers don't know about
150
* formats, we can assume that with a GL state tracker, there's a
151
* 1:1 correspondence between sampler and texture. Take advantage
152
* of that knowledge.
153
*/
154
if (i < tex->num_textures && tex->textures[i]) {
155
const struct util_format_description *desc =
156
util_format_description(tex->textures[i]->format);
157
for (j = 0; j < 4; j++) {
158
if (desc->swizzle[j] >= 4)
159
continue;
160
161
const struct util_format_channel_description *chan =
162
&desc->channel[desc->swizzle[j]];
163
if (chan->pure_integer) {
164
bcolor32[desc->swizzle[j] + 4] = sampler->border_color.i[j];
165
bcolor[desc->swizzle[j] + 8] = sampler->border_color.i[j];
166
} else {
167
bcolor32[desc->swizzle[j]] = fui(sampler->border_color.f[j]);
168
bcolor[desc->swizzle[j]] =
169
_mesa_float_to_half(sampler->border_color.f[j]);
170
}
171
}
172
}
173
}
174
}
175
176