2 * Copyright (C) 2019 Collabora, Ltd.
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:
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
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
23 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
28 #include "pan_context.h"
29 #include "util/u_memory.h"
31 /* Compute CSOs are tracked like graphics shader CSOs, but are
32 * considerably simpler. We do not implement multiple
33 * variants/keying. So the CSO create function just goes ahead and
34 * compiles the thing. */
37 panfrost_create_compute_state(
38 struct pipe_context
*pctx
,
39 const struct pipe_compute_state
*cso
)
41 struct panfrost_context
*ctx
= pan_context(pctx
);
43 struct panfrost_shader_variants
*so
= CALLOC_STRUCT(panfrost_shader_variants
);
45 so
->is_compute
= true;
47 struct panfrost_shader_state
*v
= &so
->variants
[0];
49 so
->variant_count
= 1;
50 so
->active_variant
= 0;
52 v
->tripipe
= malloc(sizeof(struct mali_shader_meta
));
54 panfrost_shader_compile(ctx
, v
->tripipe
,
55 cso
->ir_type
, cso
->prog
,
56 MESA_SHADER_COMPUTE
, v
, NULL
);
64 panfrost_bind_compute_state(struct pipe_context
*pipe
, void *cso
)
66 struct panfrost_context
*ctx
= pan_context(pipe
);
68 struct panfrost_shader_variants
*variants
=
69 (struct panfrost_shader_variants
*) cso
;
71 ctx
->shader
[PIPE_SHADER_COMPUTE
] = variants
;
75 panfrost_delete_compute_state(struct pipe_context
*pipe
, void *cso
)
80 /* Launch grid is the compute equivalent of draw_vbo, so in this routine, we
81 * construct the COMPUTE job and some of its payload.
85 panfrost_launch_grid(struct pipe_context
*pipe
,
86 const struct pipe_grid_info
*info
)
88 struct panfrost_context
*ctx
= pan_context(pipe
);
90 /* TODO: Do we want a special compute-only batch? */
91 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
93 ctx
->compute_grid
= info
;
95 struct mali_job_descriptor_header job
= {
96 .job_type
= JOB_TYPE_COMPUTE
,
97 .job_descriptor_size
= 1,
102 struct midgard_payload_vertex_tiler
*payload
= &ctx
->payloads
[PIPE_SHADER_COMPUTE
];
104 panfrost_emit_for_draw(ctx
, false);
106 /* Compute jobs have a "compute FBD". It's not a real framebuffer
107 * descriptor - there is no framebuffer - but it takes the place of
108 * one. As far as I can tell, it's actually the beginning of a
109 * single-render-target framebuffer descriptor with almost everything
112 struct mali_compute_fbd compute_fbd
= {
114 0, 0x1F, 0, 0, 0, 0, 0, 0
118 payload
->postfix
.framebuffer
=
119 panfrost_upload_transient(batch
, &compute_fbd
, sizeof(compute_fbd
));
121 /* Invoke according to the grid info */
123 panfrost_pack_work_groups_compute(&payload
->prefix
,
124 info
->grid
[0], info
->grid
[1], info
->grid
[2],
125 info
->block
[0], info
->block
[1], info
->block
[2], false);
127 /* Upload the payload */
129 struct panfrost_transfer transfer
= panfrost_allocate_transient(batch
, sizeof(job
) + sizeof(*payload
));
130 memcpy(transfer
.cpu
, &job
, sizeof(job
));
131 memcpy(transfer
.cpu
+ sizeof(job
), payload
, sizeof(*payload
));
134 panfrost_scoreboard_queue_compute_job(batch
, transfer
);
136 panfrost_flush(pipe
, NULL
, PIPE_FLUSH_END_OF_FRAME
);
140 panfrost_compute_context_init(struct pipe_context
*pctx
)
142 pctx
->create_compute_state
= panfrost_create_compute_state
;
143 pctx
->bind_compute_state
= panfrost_bind_compute_state
;
144 pctx
->delete_compute_state
= panfrost_delete_compute_state
;
146 pctx
->launch_grid
= panfrost_launch_grid
;