panfrost: Flesh out launch_grid stub
[mesa.git] / src / gallium / drivers / panfrost / pan_compute.c
1 /*
2 * Copyright (C) 2019 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 <alyssa.rosenzweig@collabora.com>
25 *
26 */
27
28 #include "pan_context.h"
29 #include "util/u_memory.h"
30
31 static void *
32 panfrost_create_compute_state(
33 struct pipe_context *pctx,
34 const struct pipe_compute_state *cso)
35 {
36 return mem_dup(cso, sizeof(*cso));
37 }
38
39 static void
40 panfrost_bind_compute_state(struct pipe_context *pipe, void *cso)
41 {
42 struct pipe_compute_state *state = (struct pipe_compute_state *) cso;
43
44 printf("Binding compute %p\n", state);
45 /* Stub */
46 }
47
48 static void
49 panfrost_delete_compute_state(struct pipe_context *pipe, void *cso)
50 {
51 free(cso);
52 }
53
54 /* Launch grid is the compute equivalent of draw_vbo, so in this routine, we
55 * construct the COMPUTE job and some of its payload.
56 */
57
58 static void
59 panfrost_launch_grid(struct pipe_context *pipe,
60 const struct pipe_grid_info *info)
61 {
62 struct panfrost_context *ctx = pan_context(pipe);
63
64 struct mali_job_descriptor_header job = {
65 .job_type = JOB_TYPE_COMPUTE,
66 .job_descriptor_size = 1,
67 .job_barrier = 1
68 };
69
70 /* TODO: Stub */
71 struct midgard_payload_vertex_tiler *payload = &ctx->payloads[PIPE_SHADER_COMPUTE];
72
73 struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sizeof(job) + sizeof(*payload));
74 memcpy(transfer.cpu, &job, sizeof(job));
75 memcpy(transfer.cpu + sizeof(job), payload, sizeof(*payload));
76
77 /* TODO: Do we want a special compute-only batch? */
78 struct panfrost_job *batch = panfrost_get_job_for_fbo(ctx);
79
80 /* Queue the job */
81 panfrost_scoreboard_queue_compute_job(batch, transfer);
82 }
83
84 void
85 panfrost_compute_context_init(struct pipe_context *pctx)
86 {
87 pctx->create_compute_state = panfrost_create_compute_state;
88 pctx->bind_compute_state = panfrost_bind_compute_state;
89 pctx->delete_compute_state = panfrost_delete_compute_state;
90
91 pctx->launch_grid = panfrost_launch_grid;
92 }
93
94