Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/panfrost/pan_compute.c
4570 views
1
/*
2
* Copyright (C) 2019 Collabora, Ltd.
3
* Copyright (C) 2019 Red Hat 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 (Collabora):
25
* Alyssa Rosenzweig <[email protected]>
26
*
27
*/
28
29
#include "pan_context.h"
30
#include "panfrost-quirks.h"
31
#include "pan_bo.h"
32
#include "pan_shader.h"
33
#include "util/u_memory.h"
34
#include "nir_serialize.h"
35
36
/* Compute CSOs are tracked like graphics shader CSOs, but are
37
* considerably simpler. We do not implement multiple
38
* variants/keying. So the CSO create function just goes ahead and
39
* compiles the thing. */
40
41
static void *
42
panfrost_create_compute_state(
43
struct pipe_context *pctx,
44
const struct pipe_compute_state *cso)
45
{
46
struct panfrost_context *ctx = pan_context(pctx);
47
struct panfrost_device *dev = pan_device(pctx->screen);
48
49
struct panfrost_shader_variants *so = CALLOC_STRUCT(panfrost_shader_variants);
50
so->cbase = *cso;
51
so->is_compute = true;
52
53
struct panfrost_shader_state *v = calloc(1, sizeof(*v));
54
so->variants = v;
55
56
so->variant_count = 1;
57
so->active_variant = 0;
58
59
if (cso->ir_type == PIPE_SHADER_IR_NIR_SERIALIZED) {
60
struct blob_reader reader;
61
const struct pipe_binary_program_header *hdr = cso->prog;
62
63
blob_reader_init(&reader, hdr->blob, hdr->num_bytes);
64
65
const struct nir_shader_compiler_options *options =
66
pan_shader_get_compiler_options(dev);
67
68
so->cbase.prog = nir_deserialize(NULL, options, &reader);
69
so->cbase.ir_type = PIPE_SHADER_IR_NIR;
70
}
71
72
panfrost_shader_compile(pctx->screen, &ctx->shaders, &ctx->descs,
73
so->cbase.ir_type, so->cbase.prog, MESA_SHADER_COMPUTE,
74
v);
75
76
return so;
77
}
78
79
static void
80
panfrost_bind_compute_state(struct pipe_context *pipe, void *cso)
81
{
82
struct panfrost_context *ctx = pan_context(pipe);
83
ctx->shader[PIPE_SHADER_COMPUTE] = cso;
84
}
85
86
static void
87
panfrost_delete_compute_state(struct pipe_context *pipe, void *cso)
88
{
89
free(cso);
90
}
91
92
static void
93
panfrost_set_compute_resources(struct pipe_context *pctx,
94
unsigned start, unsigned count,
95
struct pipe_surface **resources)
96
{
97
/* TODO */
98
}
99
100
static void
101
panfrost_set_global_binding(struct pipe_context *pctx,
102
unsigned first, unsigned count,
103
struct pipe_resource **resources,
104
uint32_t **handles)
105
{
106
if (!resources)
107
return;
108
109
struct panfrost_context *ctx = pan_context(pctx);
110
struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
111
112
for (unsigned i = first; i < first + count; ++i) {
113
struct panfrost_resource *rsrc = pan_resource(resources[i]);
114
panfrost_batch_write_rsrc(batch, rsrc, PIPE_SHADER_COMPUTE);
115
116
util_range_add(&rsrc->base, &rsrc->valid_buffer_range,
117
0, rsrc->base.width0);
118
119
/* The handle points to uint32_t, but space is allocated for 64 bits */
120
memcpy(handles[i], &rsrc->image.data.bo->ptr.gpu, sizeof(mali_ptr));
121
}
122
}
123
124
static void
125
panfrost_memory_barrier(struct pipe_context *pctx, unsigned flags)
126
{
127
/* TODO: Be smart and only flush the minimum needed, maybe emitting a
128
* cache flush job if that would help */
129
panfrost_flush_all_batches(pan_context(pctx));
130
}
131
132
void
133
panfrost_compute_context_init(struct pipe_context *pctx)
134
{
135
pctx->create_compute_state = panfrost_create_compute_state;
136
pctx->bind_compute_state = panfrost_bind_compute_state;
137
pctx->delete_compute_state = panfrost_delete_compute_state;
138
139
pctx->set_compute_resources = panfrost_set_compute_resources;
140
pctx->set_global_binding = panfrost_set_global_binding;
141
142
pctx->memory_barrier = panfrost_memory_barrier;
143
}
144
145