1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2022 Imagination Technologies Ltd.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
5bf215546Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal
6bf215546Sopenharmony_ci * in the Software without restriction, including without limitation the rights
7bf215546Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8bf215546Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is
9bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18bf215546Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef PVR_JOB_CONTEXT_H
25bf215546Sopenharmony_ci#define PVR_JOB_CONTEXT_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "pvr_private.h"
28bf215546Sopenharmony_ci#include "pvr_types.h"
29bf215546Sopenharmony_ci#include "pvr_winsys.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci/* Support PDS code/data loading/storing to the 'B' shared register state
32bf215546Sopenharmony_ci * buffers.
33bf215546Sopenharmony_ci */
34bf215546Sopenharmony_ci#define ROGUE_NUM_SHADER_STATE_BUFFERS 2U
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci/* TODO: Add reset framework support. */
37bf215546Sopenharmony_cistruct pvr_reset_cmd {
38bf215546Sopenharmony_ci};
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct pvr_compute_ctx;
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct rogue_sr_programs {
43bf215546Sopenharmony_ci   struct pvr_bo *store_load_state_bo;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   struct {
46bf215546Sopenharmony_ci      uint8_t unified_size;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci      struct pvr_bo *store_program_bo;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci      struct pvr_bo *load_program_bo;
51bf215546Sopenharmony_ci   } usc;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   struct {
54bf215546Sopenharmony_ci      struct pvr_pds_upload store_program;
55bf215546Sopenharmony_ci      struct pvr_pds_upload load_program;
56bf215546Sopenharmony_ci   } pds;
57bf215546Sopenharmony_ci};
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_cistruct pvr_render_ctx {
60bf215546Sopenharmony_ci   struct pvr_device *device;
61bf215546Sopenharmony_ci
62bf215546Sopenharmony_ci   struct pvr_winsys_render_ctx *ws_ctx;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   /* Buffer to hold the VDM call stack */
65bf215546Sopenharmony_ci   struct pvr_bo *vdm_callstack_bo;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   struct pvr_render_ctx_switch {
68bf215546Sopenharmony_ci      /* Buffer to hold the VDM context resume control stream. */
69bf215546Sopenharmony_ci      struct pvr_bo *vdm_state_bo;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci      struct pvr_bo *geom_state_bo;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci      struct pvr_render_ctx_programs {
74bf215546Sopenharmony_ci         /* Context switch persistent state programs. */
75bf215546Sopenharmony_ci         struct rogue_pt_programs {
76bf215546Sopenharmony_ci            /* Buffer used to hold the persistent state. */
77bf215546Sopenharmony_ci            struct pvr_bo *store_resume_state_bo;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci            /* PDS program to store out the persistent state in
80bf215546Sopenharmony_ci             * 'store_resume_state_bo'.
81bf215546Sopenharmony_ci             */
82bf215546Sopenharmony_ci            struct pvr_pds_upload pds_store_program;
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci            /* PDS program to load in the persistent state in
85bf215546Sopenharmony_ci             * 'store_resume_state_bo'.
86bf215546Sopenharmony_ci             */
87bf215546Sopenharmony_ci            struct pvr_pds_upload pds_resume_program;
88bf215546Sopenharmony_ci         } pt;
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci         /* Context switch shared register programs. */
91bf215546Sopenharmony_ci         struct rogue_sr_programs sr;
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci      } programs[ROGUE_NUM_SHADER_STATE_BUFFERS];
94bf215546Sopenharmony_ci   } ctx_switch;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   /* Reset framework. */
97bf215546Sopenharmony_ci   struct pvr_reset_cmd reset_cmd;
98bf215546Sopenharmony_ci};
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci/******************************************************************************
101bf215546Sopenharmony_ci   Compute context
102bf215546Sopenharmony_ci ******************************************************************************/
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_cistruct pvr_compute_ctx {
105bf215546Sopenharmony_ci   struct pvr_device *device;
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci   struct pvr_winsys_compute_ctx *ws_ctx;
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   struct pvr_compute_ctx_switch {
110bf215546Sopenharmony_ci      struct pvr_bo *compute_state_bo;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci      struct rogue_sr_programs sr[ROGUE_NUM_SHADER_STATE_BUFFERS];
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci      struct pvr_pds_upload sr_fence_terminate_program;
115bf215546Sopenharmony_ci   } ctx_switch;
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci   /* Reset framework. */
118bf215546Sopenharmony_ci   struct pvr_reset_cmd reset_cmd;
119bf215546Sopenharmony_ci};
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci/******************************************************************************
122bf215546Sopenharmony_ci   Transfer context
123bf215546Sopenharmony_ci ******************************************************************************/
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci/* TODO: Can we move these to pds code headers? */
126bf215546Sopenharmony_ci/* Maximum number of DMAs in the PDS TexState/Uniform program. */
127bf215546Sopenharmony_ci#define PVR_TRANSFER_MAX_UNIFORM_DMA 1U
128bf215546Sopenharmony_ci#define PVR_TRANSFER_MAX_TEXSTATE_DMA 2U
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci#if (PVR_TRANSFER_MAX_TEXSTATE_DMA >= PVR_PDS_MAX_NUM_DMA_KICKS) || \
131bf215546Sopenharmony_ci   (PVR_TRANSFER_MAX_UNIFORM_DMA >= PVR_PDS_MAX_NUM_DMA_KICKS)
132bf215546Sopenharmony_ci#   error \
133bf215546Sopenharmony_ci      "Transfer queue can not support more DMA kicks than supported by PDS codegen."
134bf215546Sopenharmony_ci#endif
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_cistruct pvr_transfer_ctx {
137bf215546Sopenharmony_ci   struct pvr_device *device;
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   /* Reset framework. */
140bf215546Sopenharmony_ci   struct pvr_reset_cmd reset_cmd;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   struct pvr_winsys_transfer_ctx *ws_ctx;
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ci   /* Multiple on-chip render targets (MRT). */
145bf215546Sopenharmony_ci   pvr_dev_addr_t transfer_mrts[PVR_TRANSFER_MAX_RENDER_TARGETS];
146bf215546Sopenharmony_ci   struct pvr_bo *usc_eot_bo;
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci   struct pvr_pds_upload pds_unitex_code[PVR_TRANSFER_MAX_TEXSTATE_DMA]
149bf215546Sopenharmony_ci                                        [PVR_TRANSFER_MAX_UNIFORM_DMA];
150bf215546Sopenharmony_ci};
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_ci/******************************************************************************
153bf215546Sopenharmony_ci   Function prototypes
154bf215546Sopenharmony_ci ******************************************************************************/
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ciVkResult pvr_render_ctx_create(struct pvr_device *device,
157bf215546Sopenharmony_ci                               enum pvr_winsys_ctx_priority priority,
158bf215546Sopenharmony_ci                               struct pvr_render_ctx **const ctx_out);
159bf215546Sopenharmony_civoid pvr_render_ctx_destroy(struct pvr_render_ctx *ctx);
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ciVkResult pvr_compute_ctx_create(struct pvr_device *const device,
162bf215546Sopenharmony_ci                                enum pvr_winsys_ctx_priority priority,
163bf215546Sopenharmony_ci                                struct pvr_compute_ctx **const ctx_out);
164bf215546Sopenharmony_civoid pvr_compute_ctx_destroy(struct pvr_compute_ctx *ctx);
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_ciVkResult pvr_transfer_ctx_create(struct pvr_device *const device,
167bf215546Sopenharmony_ci                                 enum pvr_winsys_ctx_priority priority,
168bf215546Sopenharmony_ci                                 struct pvr_transfer_ctx **const ctx_out);
169bf215546Sopenharmony_civoid pvr_transfer_ctx_destroy(struct pvr_transfer_ctx *const ctx);
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci#endif /* PVR_JOB_CONTEXT_H */
172