Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/util/pan_sysval.c
4560 views
1
/*
2
* Copyright (C) 2020 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 FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
* Authors (Collabora):
24
* Alyssa Rosenzweig <[email protected]>
25
*/
26
27
#include "pan_ir.h"
28
#include "compiler/nir/nir_builder.h"
29
30
/* TODO: ssbo_size */
31
static int
32
panfrost_sysval_for_ssbo(nir_intrinsic_instr *instr)
33
{
34
nir_src index = instr->src[0];
35
assert(nir_src_is_const(index));
36
uint32_t uindex = nir_src_as_uint(index);
37
38
return PAN_SYSVAL(SSBO, uindex);
39
}
40
41
static int
42
panfrost_sysval_for_sampler(nir_intrinsic_instr *instr)
43
{
44
/* TODO: indirect samplers !!! */
45
nir_src index = instr->src[0];
46
assert(nir_src_is_const(index));
47
uint32_t uindex = nir_src_as_uint(index);
48
49
return PAN_SYSVAL(SAMPLER, uindex);
50
}
51
52
static int
53
panfrost_sysval_for_image_size(nir_intrinsic_instr *instr)
54
{
55
nir_src index = instr->src[0];
56
assert(nir_src_is_const(index));
57
58
bool is_array = nir_intrinsic_image_array(instr);
59
uint32_t uindex = nir_src_as_uint(index);
60
unsigned dim = nir_intrinsic_dest_components(instr) - is_array;
61
62
return PAN_SYSVAL(IMAGE_SIZE, PAN_TXS_SYSVAL_ID(uindex, dim, is_array));
63
}
64
65
static unsigned
66
panfrost_nir_sysval_for_intrinsic(nir_intrinsic_instr *instr)
67
{
68
switch (instr->intrinsic) {
69
case nir_intrinsic_load_viewport_scale:
70
return PAN_SYSVAL_VIEWPORT_SCALE;
71
case nir_intrinsic_load_viewport_offset:
72
return PAN_SYSVAL_VIEWPORT_OFFSET;
73
case nir_intrinsic_load_num_workgroups:
74
return PAN_SYSVAL_NUM_WORK_GROUPS;
75
case nir_intrinsic_load_workgroup_size:
76
return PAN_SYSVAL_LOCAL_GROUP_SIZE;
77
case nir_intrinsic_load_work_dim:
78
return PAN_SYSVAL_WORK_DIM;
79
case nir_intrinsic_load_sample_positions_pan:
80
return PAN_SYSVAL_SAMPLE_POSITIONS;
81
case nir_intrinsic_load_first_vertex:
82
case nir_intrinsic_load_base_vertex:
83
case nir_intrinsic_load_base_instance:
84
return PAN_SYSVAL_VERTEX_INSTANCE_OFFSETS;
85
case nir_intrinsic_load_draw_id:
86
return PAN_SYSVAL_DRAWID;
87
case nir_intrinsic_load_ssbo_address:
88
case nir_intrinsic_get_ssbo_size:
89
return panfrost_sysval_for_ssbo(instr);
90
case nir_intrinsic_load_sampler_lod_parameters_pan:
91
return panfrost_sysval_for_sampler(instr);
92
case nir_intrinsic_image_size:
93
return panfrost_sysval_for_image_size(instr);
94
default:
95
return ~0;
96
}
97
}
98
99
int
100
panfrost_sysval_for_instr(nir_instr *instr, nir_dest *dest)
101
{
102
nir_intrinsic_instr *intr;
103
nir_dest *dst = NULL;
104
nir_tex_instr *tex;
105
unsigned sysval = ~0;
106
107
switch (instr->type) {
108
case nir_instr_type_intrinsic:
109
intr = nir_instr_as_intrinsic(instr);
110
sysval = panfrost_nir_sysval_for_intrinsic(intr);
111
dst = &intr->dest;
112
break;
113
case nir_instr_type_tex:
114
tex = nir_instr_as_tex(instr);
115
if (tex->op != nir_texop_txs)
116
break;
117
118
sysval = PAN_SYSVAL(TEXTURE_SIZE,
119
PAN_TXS_SYSVAL_ID(tex->texture_index,
120
nir_tex_instr_dest_size(tex) -
121
(tex->is_array ? 1 : 0),
122
tex->is_array));
123
dst = &tex->dest;
124
break;
125
default:
126
break;
127
}
128
129
if (dest && dst)
130
*dest = *dst;
131
132
return sysval;
133
}
134
135
unsigned
136
pan_lookup_sysval(struct hash_table_u64 *sysval_to_id,
137
struct panfrost_sysvals *sysvals,
138
int sysval)
139
{
140
/* Try to lookup */
141
142
void *cached = _mesa_hash_table_u64_search(sysval_to_id, sysval);
143
144
if (cached)
145
return ((uintptr_t) cached) - 1;
146
147
/* Else assign */
148
149
unsigned id = sysvals->sysval_count++;
150
assert(id < MAX_SYSVAL_COUNT);
151
_mesa_hash_table_u64_insert(sysval_to_id, sysval, (void *) ((uintptr_t) id + 1));
152
sysvals->sysvals[id] = sysval;
153
154
return id;
155
}
156
157
struct hash_table_u64 *
158
panfrost_init_sysvals(struct panfrost_sysvals *sysvals, void *memctx)
159
{
160
sysvals->sysval_count = 0;
161
return _mesa_hash_table_u64_create(memctx);
162
}
163
164