| 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 |
#ifndef PVR_CLEAR_H |
| 25 |
#define PVR_CLEAR_H |
| 26 |
|
| 27 |
#include <stdbool.h> |
| 28 |
#include <stdint.h> |
| 29 |
#include <vulkan/vulkan_core.h> |
| 30 |
|
| 31 |
#include "pvr_common.h" |
| 32 |
#include "pvr_csb.h" |
| 33 |
#include "pvr_device_info.h" |
| 34 |
#include "util/macros.h" |
| 35 |
|
| 36 |
#define PVR_CLEAR_VERTEX_COUNT 4 |
| 37 |
#define PVR_CLEAR_VERTEX_COORDINATES 3 |
| 38 |
#define PVR_NUM_CLEAR_ATTACH_SHADERS 20U |
| 39 |
|
| 40 |
/* These can be used as offsets within a PVR_STATIC_CLEAR_PDS_STATE_COUNT dwords |
| 41 |
* sized array to get the respective state word. |
| 42 |
* |
| 43 |
* The values are based on the lengths of the state words. |
| 44 |
*/ |
| 45 |
enum pvr_static_clear_ppp_pds_state_type { |
| 46 |
/* Words enabled by pres_pds_state_ptr0. */ |
| 47 |
PVR_STATIC_CLEAR_PPP_PDS_TYPE_SHADERBASE = 0, |
| 48 |
PVR_STATIC_CLEAR_PPP_PDS_TYPE_TEXUNICODEBASE = 1, |
| 49 |
PVR_STATIC_CLEAR_PPP_PDS_TYPE_SIZEINFO1 = 2, |
| 50 |
PVR_STATIC_CLEAR_PPP_PDS_TYPE_SIZEINFO2 = 3, |
| 51 |
|
| 52 |
/* Word enabled by pres_pds_state_ptr1. */ |
| 53 |
PVR_STATIC_CLEAR_PPP_PDS_TYPE_VARYINGBASE = 4, |
| 54 |
|
| 55 |
/* Word enabled by pres_pds_state_ptr2. */ |
| 56 |
PVR_STATIC_CLEAR_PPP_PDS_TYPE_TEXTUREDATABASE = 5, |
| 57 |
}; |
| 58 |
|
| 59 |
#define PVR_PDS_STATE_LENGTH (PVR_STATIC_CLEAR_PPP_PDS_TYPE_TEXTUREDATABASE + 1) |
| 60 |
|
| 61 |
#define PVR_STATIC_CLEAR_VARIANT_COUNT (VK_IMAGE_ASPECT_STENCIL_BIT << 1U) |
| 62 |
|
| 63 |
struct pvr_bo; |
| 64 |
struct pvr_cmd_buffer; |
| 65 |
struct pvr_device; |
| 66 |
struct pvr_pds_upload; |
| 67 |
struct pvr_pds_vertex_shader_program; |
| 68 |
|
| 69 |
struct pvr_static_clear_ppp_base { |
| 70 |
uint32_t wclamp; |
| 71 |
uint32_t varying_word[3]; |
| 72 |
uint32_t ppp_ctrl; |
| 73 |
uint32_t stream_out0; |
| 74 |
}; |
| 75 |
|
| 76 |
struct pvr_static_clear_ppp_template { |
| 77 |
/* Pre-packed control words. */ |
| 78 |
uint32_t header; |
| 79 |
uint32_t ispb; |
| 80 |
|
| 81 |
bool requires_pds_state; |
| 82 |
|
| 83 |
/* Configurable control words. |
| 84 |
* These are initialized and can be modified as needed before emitting them. |
| 85 |
*/ |
| 86 |
struct { |
| 87 |
struct ROGUE_TA_STATE_ISPCTL ispctl; |
| 88 |
struct ROGUE_TA_STATE_ISPA ispa; |
| 89 |
|
| 90 |
/* In case the template requires_pds_state this needs to be a valid |
| 91 |
* pointer to a pre-packed PDS state before emitting. |
| 92 |
* |
| 93 |
* Note: this is a pointer to an array of const uint32_t and not an array |
| 94 |
* of pointers or a function pointer. |
| 95 |
*/ |
| 96 |
const uint32_t (*pds_state)[PVR_PDS_STATE_LENGTH]; |
| 97 |
|
| 98 |
struct ROGUE_TA_REGION_CLIP0 region_clip0; |
| 99 |
struct ROGUE_TA_REGION_CLIP1 region_clip1; |
| 100 |
|
| 101 |
struct ROGUE_TA_OUTPUT_SEL output_sel; |
| 102 |
} config; |
| 103 |
}; |
| 104 |
|
| 105 |
struct pvr_device_static_clear_state { |
| 106 |
struct pvr_suballoc_bo *usc_vertex_shader_bo; |
| 107 |
struct pvr_suballoc_bo *vertices_bo; |
| 108 |
struct pvr_pds_upload pds; |
| 109 |
|
| 110 |
/* Only valid if PVR_HAS_FEATURE(dev_info, gs_rta_support). */ |
| 111 |
struct pvr_suballoc_bo *usc_multi_layer_vertex_shader_bo; |
| 112 |
|
| 113 |
struct pvr_static_clear_ppp_base ppp_base; |
| 114 |
/* Indexable using VkImageAspectFlags. */ |
| 115 |
struct pvr_static_clear_ppp_template |
| 116 |
ppp_templates[PVR_STATIC_CLEAR_VARIANT_COUNT]; |
| 117 |
|
| 118 |
const uint32_t *vdm_words; |
| 119 |
const uint32_t *large_clear_vdm_words; |
| 120 |
|
| 121 |
struct pvr_suballoc_bo *usc_clear_attachment_programs; |
| 122 |
struct pvr_suballoc_bo *pds_clear_attachment_programs; |
| 123 |
/* TODO: See if we can use PVR_CLEAR_ATTACHMENT_PROGRAM_COUNT to save some |
| 124 |
* memory. |
| 125 |
*/ |
| 126 |
struct pvr_pds_clear_attachment_program_info { |
| 127 |
pvr_dev_addr_t texture_program_offset; |
| 128 |
pvr_dev_addr_t pixel_program_offset; |
| 129 |
|
| 130 |
uint32_t texture_program_pds_temps_count; |
| 131 |
/* Size in dwords. */ |
| 132 |
uint32_t texture_program_data_size; |
| 133 |
} pds_clear_attachment_program_info[PVR_NUM_CLEAR_ATTACH_SHADERS]; |
| 134 |
}; |
| 135 |
|
| 136 |
VkResult pvr_device_init_graphics_static_clear_state(struct pvr_device *device); |
| 137 |
void pvr_device_finish_graphics_static_clear_state(struct pvr_device *device); |
| 138 |
|
| 139 |
VkResult pvr_emit_ppp_from_template( |
| 140 |
struct pvr_csb *const csb, |
| 141 |
const struct pvr_static_clear_ppp_template *const template, |
| 142 |
struct pvr_suballoc_bo **const pvr_bo_out); |
| 143 |
|
| 144 |
void pvr_pds_clear_vertex_shader_program_init_base( |
| 145 |
struct pvr_pds_vertex_shader_program *program, |
| 146 |
const struct pvr_suballoc_bo *usc_shader_bo); |
| 147 |
|
| 148 |
VkResult pvr_pds_clear_vertex_shader_program_create_and_upload( |
| 149 |
struct pvr_pds_vertex_shader_program *program, |
| 150 |
struct pvr_device *device, |
| 151 |
const struct pvr_suballoc_bo *vertices_bo, |
| 152 |
struct pvr_pds_upload *const upload_out); |
| 153 |
VkResult pvr_pds_clear_vertex_shader_program_create_and_upload_data( |
| 154 |
struct pvr_pds_vertex_shader_program *program, |
| 155 |
struct pvr_cmd_buffer *cmd_buffer, |
| 156 |
struct pvr_suballoc_bo *vertices_bo, |
| 157 |
struct pvr_pds_upload *const pds_upload_out); |
| 158 |
|
| 159 |
void pvr_pds_clear_rta_vertex_shader_program_init_base( |
| 160 |
struct pvr_pds_vertex_shader_program *program, |
| 161 |
const struct pvr_suballoc_bo *usc_shader_bo); |
| 162 |
|
| 163 |
/* Each code and data upload function clears the other's fields in the |
| 164 |
* pds_upload_out. So when uploading the code, the data fields will be 0. |
| 165 |
*/ |
| 166 |
VkResult pvr_pds_clear_rta_vertex_shader_program_create_and_upload_code( |
| 167 |
struct pvr_pds_vertex_shader_program *program, |
| 168 |
struct pvr_cmd_buffer *cmd_buffer, |
| 169 |
uint32_t base_array_layer, |
| 170 |
struct pvr_pds_upload *const pds_upload_out); |
| 171 |
|
| 172 |
static inline VkResult |
| 173 |
pvr_pds_clear_rta_vertex_shader_program_create_and_upload_data( |
| 174 |
struct pvr_pds_vertex_shader_program *program, |
| 175 |
struct pvr_cmd_buffer *cmd_buffer, |
| 176 |
struct pvr_suballoc_bo *vertices_bo, |
| 177 |
struct pvr_pds_upload *const pds_upload_out) |
| 178 |
{ |
| 179 |
return pvr_pds_clear_vertex_shader_program_create_and_upload_data( |
| 180 |
program, |
| 181 |
cmd_buffer, |
| 182 |
vertices_bo, |
| 183 |
pds_upload_out); |
| 184 |
} |
| 185 |
|
| 186 |
static inline uint32_t |
| 187 |
pvr_clear_vdm_state_get_size_in_dw(const struct pvr_device_info *const dev_info, |
| 188 |
uint32_t layer_count) |
| 189 |
{ |
| 190 |
uint32_t size_in_dw = |
| 191 |
pvr_cmd_length(VDMCTRL_VDM_STATE0) + pvr_cmd_length(VDMCTRL_VDM_STATE2) + |
| 192 |
pvr_cmd_length(VDMCTRL_VDM_STATE3) + pvr_cmd_length(VDMCTRL_VDM_STATE4) + |
| 193 |
pvr_cmd_length(VDMCTRL_VDM_STATE5) + pvr_cmd_length(VDMCTRL_INDEX_LIST0) + |
| 194 |
pvr_cmd_length(VDMCTRL_INDEX_LIST2); |
| 195 |
|
| 196 |
const bool needs_instance_count = |
| 197 |
PVR_HAS_FEATURE(dev_info, gs_rta_support) && layer_count > 1; |
| 198 |
|
| 199 |
if (needs_instance_count) |
| 200 |
size_in_dw += pvr_cmd_length(VDMCTRL_INDEX_LIST3); |
| 201 |
|
| 202 |
return size_in_dw; |
| 203 |
} |
| 204 |
|
| 205 |
void pvr_pack_clear_vdm_state(const struct pvr_device_info *const dev_info, |
| 206 |
const struct pvr_pds_upload *const program, |
| 207 |
uint32_t temps, |
| 208 |
uint32_t index_count, |
| 209 |
uint32_t vs_output_size_in_bytes, |
| 210 |
uint32_t layer_count, |
| 211 |
uint32_t *const state_buffer); |
| 212 |
|
| 213 |
VkResult pvr_clear_vertices_upload(struct pvr_device *device, |
| 214 |
const VkRect2D *rect, |
| 215 |
float depth, |
| 216 |
struct pvr_suballoc_bo **const pvr_bo_out); |
| 217 |
|
| 218 |
#endif /* PVR_CLEAR_H */ |