Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/vulkan/panvk_varyings.h
4560 views
1
/*
2
* Copyright (C) 2021 Collabora Ltd.
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
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
* DEALINGS IN THE SOFTWARE.
22
*/
23
24
#ifndef PANVK_VARYINGS_H
25
#define PANVK_VARYINGS_H
26
27
#include "util/bitset.h"
28
#include "util/format/u_format.h"
29
30
#include "compiler/shader_enums.h"
31
#include "midgard_pack.h"
32
#include "panfrost-job.h"
33
34
struct pan_pool;
35
struct panvk_device;
36
37
enum panvk_varying_buf_id {
38
PANVK_VARY_BUF_GENERAL,
39
PANVK_VARY_BUF_POSITION,
40
PANVK_VARY_BUF_PSIZ,
41
PANVK_VARY_BUF_PNTCOORD,
42
PANVK_VARY_BUF_FRAGCOORD,
43
44
/* Keep last */
45
PANVK_VARY_BUF_MAX,
46
};
47
48
struct panvk_varying {
49
unsigned buf;
50
unsigned offset;
51
enum pipe_format format;
52
};
53
54
struct panvk_varying_buf {
55
mali_ptr address;
56
void *cpu;
57
unsigned stride;
58
unsigned size;
59
};
60
61
struct panvk_varyings_info {
62
struct panvk_varying varying[VARYING_SLOT_MAX];
63
BITSET_DECLARE(active, VARYING_SLOT_MAX);
64
struct panvk_varying_buf buf[VARYING_SLOT_MAX];
65
struct {
66
unsigned count;
67
gl_varying_slot loc[VARYING_SLOT_MAX];
68
} stage[MESA_SHADER_STAGES];
69
unsigned buf_mask;
70
};
71
72
void
73
panvk_varyings_alloc(struct panvk_varyings_info *varyings,
74
struct pan_pool *varying_mem_pool,
75
unsigned vertex_count);
76
77
unsigned
78
panvk_varyings_buf_count(const struct panvk_device *dev,
79
struct panvk_varyings_info *varyings);
80
81
static inline unsigned
82
panvk_varying_buf_index(const struct panvk_varyings_info *varyings,
83
enum panvk_varying_buf_id b)
84
{
85
return util_bitcount(varyings->buf_mask & BITFIELD_MASK(b));
86
}
87
88
static inline enum panvk_varying_buf_id
89
panvk_varying_buf_id(bool fs, gl_varying_slot loc)
90
{
91
switch (loc) {
92
case VARYING_SLOT_POS:
93
return fs ? PANVK_VARY_BUF_FRAGCOORD : PANVK_VARY_BUF_POSITION;
94
case VARYING_SLOT_PSIZ:
95
return PANVK_VARY_BUF_PSIZ;
96
case VARYING_SLOT_PNTC:
97
return PANVK_VARY_BUF_PNTCOORD;
98
default:
99
return PANVK_VARY_BUF_GENERAL;
100
}
101
}
102
103
static inline bool
104
panvk_varying_is_builtin(gl_shader_stage stage, gl_varying_slot loc)
105
{
106
bool fs = stage == MESA_SHADER_FRAGMENT;
107
108
switch (loc) {
109
case VARYING_SLOT_POS:
110
case VARYING_SLOT_PNTC:
111
return fs;
112
default:
113
return false;
114
}
115
}
116
117
static inline enum mali_attribute_special
118
panvk_varying_special_buf_id(enum panvk_varying_buf_id buf_id)
119
{
120
switch (buf_id) {
121
case PANVK_VARY_BUF_PNTCOORD:
122
return MALI_ATTRIBUTE_SPECIAL_POINT_COORD;
123
case PANVK_VARY_BUF_FRAGCOORD:
124
return MALI_ATTRIBUTE_SPECIAL_FRAG_COORD;
125
default:
126
return 0;
127
}
128
}
129
130
static inline unsigned
131
panvk_varying_size(const struct panvk_varyings_info *varyings,
132
gl_varying_slot loc)
133
{
134
switch (loc) {
135
case VARYING_SLOT_POS:
136
return sizeof(float) * 4;
137
case VARYING_SLOT_PSIZ:
138
return sizeof(uint16_t);
139
default:
140
return util_format_get_blocksize(varyings->varying[loc].format);
141
}
142
}
143
144
#endif
145
146