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
);
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 ctx
->compute_grid
= info
;
92 struct mali_job_descriptor_header job
= {
93 .job_type
= JOB_TYPE_COMPUTE
,
94 .job_descriptor_size
= 1,
99 struct midgard_payload_vertex_tiler
*payload
= &ctx
->payloads
[PIPE_SHADER_COMPUTE
];
101 panfrost_emit_for_draw(ctx
, false);
103 /* Compute jobs have a "compute FBD". It's not a real framebuffer
104 * descriptor - there is no framebuffer - but it takes the place of
105 * one. As far as I can tell, it's actually the beginning of a
106 * single-render-target framebuffer descriptor with almost everything
109 struct mali_compute_fbd compute_fbd
= {
111 0, 0x1F, 0, 0, 0, 0, 0, 0
115 payload
->postfix
.framebuffer
=
116 panfrost_upload_transient(ctx
, &compute_fbd
, sizeof(compute_fbd
));
118 /* Invoke according to the grid info */
120 panfrost_pack_work_groups_compute(&payload
->prefix
,
121 info
->grid
[0], info
->grid
[1], info
->grid
[2],
122 info
->block
[0], info
->block
[1], info
->block
[2]);
124 /* Upload the payload */
126 struct panfrost_transfer transfer
= panfrost_allocate_transient(ctx
, sizeof(job
) + sizeof(*payload
));
127 memcpy(transfer
.cpu
, &job
, sizeof(job
));
128 memcpy(transfer
.cpu
+ sizeof(job
), payload
, sizeof(*payload
));
130 /* TODO: Do we want a special compute-only batch? */
131 struct panfrost_job
*batch
= panfrost_get_job_for_fbo(ctx
);
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
;