1/*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * 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 THE
18 * 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
24#include <stdbool.h>
25
26#include "pvr_hw_pass.h"
27#include "pvr_private.h"
28#include "vk_alloc.h"
29
30void pvr_destroy_renderpass_hwsetup(struct pvr_device *device,
31                                    struct pvr_renderpass_hwsetup *hw_setup)
32{
33   vk_free(&device->vk.alloc, hw_setup);
34}
35
36struct pvr_renderpass_hwsetup *
37pvr_create_renderpass_hwsetup(struct pvr_device *device,
38                              struct pvr_render_pass *pass,
39                              bool disable_merge)
40{
41   struct pvr_renderpass_hwsetup_eot_surface *eot_surface;
42   enum pvr_renderpass_surface_initop *color_initops;
43   struct pvr_renderpass_hwsetup_subpass *subpasses;
44   struct pvr_renderpass_hwsetup_render *renders;
45   struct pvr_renderpass_colorinit *color_inits;
46   struct pvr_renderpass_hwsetup *hw_setup;
47   struct pvr_renderpass_hw_map *subpass_map;
48   struct usc_mrt_resource *mrt_resources;
49
50   VK_MULTIALLOC(ma);
51   vk_multialloc_add(&ma, &hw_setup, __typeof__(*hw_setup), 1);
52   vk_multialloc_add(&ma, &renders, __typeof__(*renders), 1);
53   vk_multialloc_add(&ma, &color_inits, __typeof__(*color_inits), 1);
54   vk_multialloc_add(&ma, &subpass_map, __typeof__(*subpass_map), 1);
55   vk_multialloc_add(&ma, &mrt_resources, __typeof__(*mrt_resources), 2);
56   vk_multialloc_add(&ma, &subpasses, __typeof__(*subpasses), 1);
57   vk_multialloc_add(&ma, &eot_surface, __typeof__(*eot_surface), 1);
58   vk_multialloc_add(&ma,
59                     &color_initops,
60                     __typeof__(*color_initops),
61                     pass->subpasses[0].color_count);
62   /* Note, no more multialloc slots available (maximum supported is 8). */
63
64   if (!vk_multialloc_zalloc(&ma,
65                             &device->vk.alloc,
66                             VK_SYSTEM_ALLOCATION_SCOPE_DEVICE)) {
67      return NULL;
68   }
69
70   /* FIXME: Remove hardcoding of hw_setup structure. */
71   subpasses[0].z_replicate = -1;
72   subpasses[0].depth_initop = RENDERPASS_SURFACE_INITOP_CLEAR;
73   subpasses[0].stencil_clear = false;
74   subpasses[0].driver_id = 0;
75   color_initops[0] = RENDERPASS_SURFACE_INITOP_NOP;
76   subpasses[0].color_initops = color_initops;
77   subpasses[0].client_data = NULL;
78   renders[0].subpass_count = 1;
79   renders[0].subpasses = subpasses;
80
81   renders[0].sample_count = 1;
82   renders[0].ds_surface_id = 1;
83   renders[0].depth_init = RENDERPASS_SURFACE_INITOP_CLEAR;
84   renders[0].stencil_init = RENDERPASS_SURFACE_INITOP_NOP;
85
86   mrt_resources[0].type = USC_MRT_RESOURCE_TYPE_OUTPUT_REGISTER;
87   mrt_resources[0].u.reg.out_reg = 0;
88   mrt_resources[0].u.reg.offset = 0;
89   renders[0].init_setup.render_targets_count = 1;
90   renders[0].init_setup.mrt_resources = &mrt_resources[0];
91
92   color_inits[0].op = RENDERPASS_SURFACE_INITOP_CLEAR;
93   color_inits[0].driver_id = 0;
94   renders[0].color_init_count = 1;
95   renders[0].color_init = color_inits;
96
97   mrt_resources[1].type = USC_MRT_RESOURCE_TYPE_OUTPUT_REGISTER;
98   mrt_resources[1].u.reg.out_reg = 0;
99   mrt_resources[1].u.reg.offset = 0;
100   renders[0].eot_setup.render_targets_count = 1;
101   renders[0].eot_setup.mrt_resources = &mrt_resources[1];
102
103   eot_surface->mrt_index = 0;
104   eot_surface->attachment_index = 0;
105   eot_surface->need_resolve = false;
106   eot_surface->resolve_type = PVR_RESOLVE_TYPE_INVALID;
107   eot_surface->src_attachment_index = 0;
108   renders[0].eot_surfaces = eot_surface;
109   renders[0].eot_surface_count = 1;
110
111   renders[0].output_regs_count = 1;
112   renders[0].tile_buffers_count = 0;
113   renders[0].client_data = NULL;
114   hw_setup->render_count = 1;
115   hw_setup->renders = renders;
116
117   subpass_map->render = 0;
118   subpass_map->subpass = 0;
119   hw_setup->subpass_map = subpass_map;
120
121   return hw_setup;
122}
123