1 /* 2 * Copyright © 2023 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_USCGEN_H 25 #define PVR_USCGEN_H 26 27 #include <stdbool.h> 28 #include <stdint.h> 29 30 #include "pvr_common.h" 31 #include "pvr_formats.h" 32 #include "util/u_dynarray.h" 33 34 enum pvr_int_coord_set_floats { 35 PVR_INT_COORD_SET_FLOATS_0 = 0, 36 PVR_INT_COORD_SET_FLOATS_4 = 1, 37 /* For rate changes to 0 base screen space. */ 38 PVR_INT_COORD_SET_FLOATS_6 = 2, 39 PVR_INT_COORD_SET_FLOATS_NUM = 3 40 }; 41 42 struct pvr_tq_shader_properties { 43 /* Controls whether this is an iterated shader. */ 44 bool iterated; 45 46 /* Controls whether this is meant to be running at full rate. */ 47 bool full_rate; 48 49 /* Sample specific channel of pixel. */ 50 bool pick_component; 51 52 struct pvr_tq_layer_properties { 53 /* Controls whether we need to send the sample count to the TPU. */ 54 bool msaa; 55 56 /* In case we run pixel rate, to do an USC resolve - but still in MSAA TPU 57 * samples. 58 */ 59 uint32_t sample_count; 60 61 enum pvr_resolve_op resolve_op; 62 63 /* Selects the pixel conversion that we have to perform. */ 64 enum pvr_transfer_pbe_pixel_src pbe_format; 65 66 /* Sampling from a 3D texture with a constant Z position. */ 67 bool sample; 68 69 /* Number of float coefficients to get from screen space to texture space. 70 */ 71 enum pvr_int_coord_set_floats layer_floats; 72 73 /* Unaligned texture address in bytes. */ 74 uint32_t byte_unwind; 75 76 /* Enable bilinear filter in shader. */ 77 bool linear; 78 } layer_props; 79 }; 80 81 /* All offsets are in dwords. */ 82 /* Devices may have more than 256 sh regs but we're expecting to use vary few so 83 * let's use uint8_t. 84 */ 85 struct pvr_tq_frag_sh_reg_layout { 86 struct { 87 /* How many image sampler descriptors are present. */ 88 uint8_t count; 89 /* TODO: See if we ever need more than one combined image sampler 90 * descriptor. If this is linked to the amount of layers used, we only 91 * ever use one layer so this wouldn't need to be an array. 92 */ 93 struct { 94 uint8_t image; 95 uint8_t sampler; 96 } offsets[PVR_TRANSFER_MAX_IMAGES]; 97 } combined_image_samplers; 98 99 /* TODO: Dynamic consts are used for various things so do this properly by 100 * having an actual layout instead of chucking them all together using an 101 * implicit layout. 102 */ 103 struct { 104 /* How many dynamic consts regs have been allocated. */ 105 uint8_t count; 106 uint8_t offset; 107 } dynamic_consts; 108 109 /* Total sh regs allocated by the driver. It does not include the regs 110 * necessary for compiler_out. 111 */ 112 uint8_t driver_total; 113 114 /* Provided by the compiler to the driver to be appended to the shareds. */ 115 /* No offset field since these will be appended at the end so driver_total 116 * can be used instead. 117 */ 118 struct { 119 struct { 120 /* TODO: Remove this count and just use `compiler_out_total`? Or remove 121 * that one and use this one? 122 */ 123 uint8_t count; 124 /* TODO: The array size is chosen arbitrarily based on the max 125 * constants currently produced by the compiler. Make this dynamic? 126 */ 127 /* Values to fill in into each shared reg used for usc constants. */ 128 uint32_t values[10]; 129 } usc_constants; 130 } compiler_out; 131 132 /* Total extra sh regs needed by the compiler that need to be appended to the 133 * shareds by the driver. 134 */ 135 uint8_t compiler_out_total; 136 }; 137 138 /* TODO: Shader caching (not pipeline caching) support. */ 139 140 void pvr_uscgen_eot(const char *name, 141 uint32_t emit_count, 142 const uint32_t *emit_state, 143 unsigned *temps_used, 144 struct util_dynarray *binary); 145 146 void pvr_uscgen_nop(struct util_dynarray *binary); 147 148 void pvr_uscgen_tq_frag(const struct pvr_tq_shader_properties *shader_props, 149 struct pvr_tq_frag_sh_reg_layout *sh_reg_layout, 150 unsigned *temps_used, 151 struct util_dynarray *binary); 152 153 void pvr_uscgen_tq_eot(unsigned rt_count, 154 const uint64_t *pbe_regs, 155 struct util_dynarray *binary); 156 157 #endif /* PVR_USCGEN_H */ 158