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_HW_PASS_H
25bf215546Sopenharmony_ci#define PVR_HW_PASS_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include <stdbool.h>
28bf215546Sopenharmony_ci#include <stdint.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_cistruct pvr_device;
31bf215546Sopenharmony_cistruct pvr_render_pass;
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cienum pvr_renderpass_surface_initop {
34bf215546Sopenharmony_ci   RENDERPASS_SURFACE_INITOP_CLEAR,
35bf215546Sopenharmony_ci   RENDERPASS_SURFACE_INITOP_LOAD,
36bf215546Sopenharmony_ci   RENDERPASS_SURFACE_INITOP_NOP,
37bf215546Sopenharmony_ci};
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistruct pvr_renderpass_hwsetup_subpass {
40bf215546Sopenharmony_ci   /* If >=0 then copy the depth into this pixel output for all fragment
41bf215546Sopenharmony_ci    * programs in the subpass.
42bf215546Sopenharmony_ci    */
43bf215546Sopenharmony_ci   int32_t z_replicate;
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci   /* The operation to perform on the depth at the start of the subpass. Loads
46bf215546Sopenharmony_ci    * are deferred to subpasses when depth has been replicated
47bf215546Sopenharmony_ci    */
48bf215546Sopenharmony_ci   enum pvr_renderpass_surface_initop depth_initop;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   /* If true then clear the stencil at the start of the subpass. */
51bf215546Sopenharmony_ci   bool stencil_clear;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   /* Driver Id from the input pvr_render_subpass structure. */
54bf215546Sopenharmony_ci   uint32_t driver_id;
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   /* For each color attachment to the subpass: the operation to perform at
57bf215546Sopenharmony_ci    * the start of the subpass.
58bf215546Sopenharmony_ci    */
59bf215546Sopenharmony_ci   enum pvr_renderpass_surface_initop *color_initops;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   void *client_data;
62bf215546Sopenharmony_ci};
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_cistruct pvr_renderpass_colorinit {
65bf215546Sopenharmony_ci   /* Source surface for the operation. */
66bf215546Sopenharmony_ci   uint32_t driver_id;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   /* Type of operation: either clear or load. */
69bf215546Sopenharmony_ci   enum pvr_renderpass_surface_initop op;
70bf215546Sopenharmony_ci};
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci/* FIXME: Adding these USC enums and structures here for now to avoid adding
73bf215546Sopenharmony_ci * usc.h header. Needs to be moved to compiler specific header.
74bf215546Sopenharmony_ci */
75bf215546Sopenharmony_ci/* Specifies the location of render target writes. */
76bf215546Sopenharmony_cienum usc_mrt_resource_type {
77bf215546Sopenharmony_ci   USC_MRT_RESOURCE_TYPE_INVALID = 0, /* explicitly treat 0 as invalid */
78bf215546Sopenharmony_ci   USC_MRT_RESOURCE_TYPE_OUTPUT_REGISTER,
79bf215546Sopenharmony_ci   USC_MRT_RESOURCE_TYPE_MEMORY,
80bf215546Sopenharmony_ci};
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_cistruct usc_mrt_resource {
83bf215546Sopenharmony_ci   /* Resource type allocated for render target. */
84bf215546Sopenharmony_ci   enum usc_mrt_resource_type type;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   union {
87bf215546Sopenharmony_ci      /* If type == USC_MRT_RESOURCE_TYPE_OUTPUT_REGISTER. */
88bf215546Sopenharmony_ci      struct {
89bf215546Sopenharmony_ci         /* The output register to use. */
90bf215546Sopenharmony_ci         uint32_t out_reg;
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci         /* The offset in bytes into the output register. */
93bf215546Sopenharmony_ci         uint32_t offset;
94bf215546Sopenharmony_ci      } reg;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci      /* If type == USC_MRT_RESOURCE_TYPE_MEMORY. */
97bf215546Sopenharmony_ci      struct {
98bf215546Sopenharmony_ci         /* The number of the tile buffer to use. */
99bf215546Sopenharmony_ci         uint32_t tile_buffer;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci         /* The offset in dwords within the tile buffer. */
102bf215546Sopenharmony_ci         uint32_t offset_in_dwords;
103bf215546Sopenharmony_ci      } mem;
104bf215546Sopenharmony_ci   } u;
105bf215546Sopenharmony_ci};
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_cistruct usc_mrt_setup {
108bf215546Sopenharmony_ci   /* Number of render targets present. */
109bf215546Sopenharmony_ci   uint32_t render_targets_count;
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   /* Array of MRT resources allocated for each render target. The number of
112bf215546Sopenharmony_ci    * elements is determined by usc_mrt_setup::render_targets_count.
113bf215546Sopenharmony_ci    */
114bf215546Sopenharmony_ci   struct usc_mrt_resource *mrt_resources;
115bf215546Sopenharmony_ci};
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_cienum pvr_resolve_type {
118bf215546Sopenharmony_ci   PVR_RESOLVE_TYPE_INVALID = 0, /* explicitly treat 0 as invalid */
119bf215546Sopenharmony_ci   PVR_RESOLVE_TYPE_PBE,
120bf215546Sopenharmony_ci   PVR_RESOLVE_TYPE_TRANSFER,
121bf215546Sopenharmony_ci};
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistruct pvr_renderpass_hwsetup_eot_surface {
124bf215546Sopenharmony_ci   /* MRT index to store from. Also used to index into
125bf215546Sopenharmony_ci    * usc_mrt_setup::mrt_resources.
126bf215546Sopenharmony_ci    */
127bf215546Sopenharmony_ci   uint32_t mrt_index;
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   /* Index of pvr_render_pass_info::attachments to store into. */
130bf215546Sopenharmony_ci   uint32_t attachment_index;
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci   /* True if the surface should be resolved. */
133bf215546Sopenharmony_ci   bool need_resolve;
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci   /* How the surface should be resolved at the end of a render. Only valid if
136bf215546Sopenharmony_ci    * pvr_renderpass_hwsetup_eot_surface::need_resolve is set to true.
137bf215546Sopenharmony_ci    */
138bf215546Sopenharmony_ci   enum pvr_resolve_type resolve_type;
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci   /* Index of pvr_render_pass_info::attachments to resolve from. Only valid if
141bf215546Sopenharmony_ci    * pvr_renderpass_hwsetup_eot_surface::need_resolve is set to true.
142bf215546Sopenharmony_ci    */
143bf215546Sopenharmony_ci   uint32_t src_attachment_index;
144bf215546Sopenharmony_ci};
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_cistruct pvr_renderpass_hwsetup_render {
147bf215546Sopenharmony_ci   /* Number of pixel output registers to allocate for this render. */
148bf215546Sopenharmony_ci   uint32_t output_regs_count;
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci   /* Number of tile buffers to allocate for this render. */
151bf215546Sopenharmony_ci   uint32_t tile_buffers_count;
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci   /* Number of subpasses in this render. */
154bf215546Sopenharmony_ci   uint32_t subpass_count;
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   /* Description of each subpass. */
157bf215546Sopenharmony_ci   struct pvr_renderpass_hwsetup_subpass *subpasses;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   /* The sample count of every color attachment (or depth attachment if
160bf215546Sopenharmony_ci    * z-only) in this render
161bf215546Sopenharmony_ci    */
162bf215546Sopenharmony_ci   uint32_t sample_count;
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_ci   /* Driver Id for the surface to use for depth/stencil load/store in this
165bf215546Sopenharmony_ci    * render.
166bf215546Sopenharmony_ci    */
167bf215546Sopenharmony_ci   int32_t ds_surface_id;
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci   /* Operation on the on-chip depth at the start of the render.
170bf215546Sopenharmony_ci    * Either load from 'ds_surface_id', clear using 'ds_surface_id' or leave
171bf215546Sopenharmony_ci    * uninitialized.
172bf215546Sopenharmony_ci    */
173bf215546Sopenharmony_ci   enum pvr_renderpass_surface_initop depth_init;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   /* Operation on the on-chip stencil at the start of the render. */
176bf215546Sopenharmony_ci   enum pvr_renderpass_surface_initop stencil_init;
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci   /* For each operation: the destination in the on-chip color storage. */
179bf215546Sopenharmony_ci   struct usc_mrt_setup init_setup;
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ci   /* Count of operations on on-chip color storage at the start of the render.
182bf215546Sopenharmony_ci    */
183bf215546Sopenharmony_ci   uint32_t color_init_count;
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci   /* How to initialize render targets at the start of the render. */
186bf215546Sopenharmony_ci   struct pvr_renderpass_colorinit *color_init;
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ci   /* Describes the location of the source data for each stored surface. */
189bf215546Sopenharmony_ci   struct usc_mrt_setup eot_setup;
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci   struct pvr_renderpass_hwsetup_eot_surface *eot_surfaces;
192bf215546Sopenharmony_ci   uint32_t eot_surface_count;
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci   void *client_data;
195bf215546Sopenharmony_ci};
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_cistruct pvr_renderpass_hw_map {
198bf215546Sopenharmony_ci   uint32_t render;
199bf215546Sopenharmony_ci   uint32_t subpass;
200bf215546Sopenharmony_ci};
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_cistruct pvr_renderpass_hwsetup {
203bf215546Sopenharmony_ci   /* Number of renders. */
204bf215546Sopenharmony_ci   uint32_t render_count;
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci   /* Description of each render. */
207bf215546Sopenharmony_ci   struct pvr_renderpass_hwsetup_render *renders;
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci   /* Maps indices from pvr_render_pass::subpasses to the
210bf215546Sopenharmony_ci    * pvr_renderpass_hwsetup_render/pvr_renderpass_hwsetup_subpass relative to
211bf215546Sopenharmony_ci    * that render where the subpass is scheduled.
212bf215546Sopenharmony_ci    */
213bf215546Sopenharmony_ci   struct pvr_renderpass_hw_map *subpass_map;
214bf215546Sopenharmony_ci};
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_cistruct pvr_renderpass_hwsetup *
217bf215546Sopenharmony_cipvr_create_renderpass_hwsetup(struct pvr_device *device,
218bf215546Sopenharmony_ci                              struct pvr_render_pass *pass,
219bf215546Sopenharmony_ci                              bool disable_merge);
220bf215546Sopenharmony_civoid pvr_destroy_renderpass_hwsetup(struct pvr_device *device,
221bf215546Sopenharmony_ci                                    struct pvr_renderpass_hwsetup *hw_setup);
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci#endif /* PVR_HW_PASS_H */
224