1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2018-2019 Lima Project
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
12bf215546Sopenharmony_ci * all copies or substantial portions of the Software.
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17bf215546Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
21bf215546Sopenharmony_ci *
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef H_LIMA_JOB
25bf215546Sopenharmony_ci#define H_LIMA_JOB
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include <stdbool.h>
28bf215546Sopenharmony_ci#include <stdint.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include <util/u_dynarray.h>
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include <pipe/p_state.h>
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#define MAX_DRAWS_PER_JOB 2500
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cistruct lima_context;
37bf215546Sopenharmony_cistruct lima_bo;
38bf215546Sopenharmony_cistruct lima_dump;
39bf215546Sopenharmony_cistruct pipe_surface;
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_cistruct lima_job_key {
42bf215546Sopenharmony_ci   struct pipe_surface *cbuf;
43bf215546Sopenharmony_ci   struct pipe_surface *zsbuf;
44bf215546Sopenharmony_ci};
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_cistruct lima_job_clear {
47bf215546Sopenharmony_ci   unsigned buffers;
48bf215546Sopenharmony_ci   uint32_t color_8pc;
49bf215546Sopenharmony_ci   uint32_t depth;
50bf215546Sopenharmony_ci   uint32_t stencil;
51bf215546Sopenharmony_ci   uint64_t color_16pc;
52bf215546Sopenharmony_ci};
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_cistruct lima_job_fb_info {
55bf215546Sopenharmony_ci   int width, height;
56bf215546Sopenharmony_ci   int tiled_w, tiled_h;
57bf215546Sopenharmony_ci   int shift_w, shift_h;
58bf215546Sopenharmony_ci   int block_w, block_h;
59bf215546Sopenharmony_ci   int shift_min;
60bf215546Sopenharmony_ci};
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_cistruct lima_job {
63bf215546Sopenharmony_ci   int fd;
64bf215546Sopenharmony_ci   struct lima_context *ctx;
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci   struct util_dynarray gem_bos[2];
67bf215546Sopenharmony_ci   struct util_dynarray bos[2];
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci   struct lima_job_key key;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci   struct util_dynarray vs_cmd_array;
72bf215546Sopenharmony_ci   struct util_dynarray plbu_cmd_array;
73bf215546Sopenharmony_ci   struct util_dynarray plbu_cmd_head;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   unsigned resolve;
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci   int pp_max_stack_size;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   struct pipe_scissor_state damage_rect;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   struct lima_job_clear clear;
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   struct lima_job_fb_info fb;
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci   int draws;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   /* for dump command stream */
88bf215546Sopenharmony_ci   struct lima_dump *dump;
89bf215546Sopenharmony_ci};
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_cistatic inline bool
92bf215546Sopenharmony_cilima_job_has_draw_pending(struct lima_job *job)
93bf215546Sopenharmony_ci{
94bf215546Sopenharmony_ci   return !!job->plbu_cmd_array.size;
95bf215546Sopenharmony_ci}
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_cistruct lima_job *lima_job_get(struct lima_context *ctx);
98bf215546Sopenharmony_cistruct lima_job * lima_job_get_with_fb(struct lima_context *ctx,
99bf215546Sopenharmony_ci                                       struct pipe_surface *cbuf,
100bf215546Sopenharmony_ci                                       struct pipe_surface *zsbuf);
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_cibool lima_job_add_bo(struct lima_job *job, int pipe,
103bf215546Sopenharmony_ci                     struct lima_bo *bo, uint32_t flags);
104bf215546Sopenharmony_civoid *lima_job_create_stream_bo(struct lima_job *job, int pipe,
105bf215546Sopenharmony_ci                                unsigned size, uint32_t *va);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_civoid lima_do_job(struct lima_job *job);
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_cibool lima_job_init(struct lima_context *ctx);
110bf215546Sopenharmony_civoid lima_job_fini(struct lima_context *ctx);
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci#endif
113