1 // Copyright 2021 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef SRC_GRAPHICS_LIB_COMPUTE_RADIX_SORT_PLATFORMS_VK_SHADERS_PUSH_H_ 6 #define SRC_GRAPHICS_LIB_COMPUTE_RADIX_SORT_PLATFORMS_VK_SHADERS_PUSH_H_ 7 8 // 9 // There is a limit to the maximum number of keyvals that can be sorted because 10 // the top 2 bits in the atomic lookback counters are used as tag bits. 11 // 12 #define RS_MAX_KEYVALS ((1 << 30) - 1) 13 14 // 15 // Right now, the entire implementation is very much dependent on an 8-bit radix 16 // size. Most of the shaders attempt to honor this defined size but there are 17 // still a number of places where 256 is assumed. 18 // 19 #define RS_RADIX_LOG2 8 20 #define RS_RADIX_SIZE (1 << RS_RADIX_LOG2) 21 22 // 23 // LOOKBACK STATUS FLAGS 24 // 25 // The decoupled lookback status flags are stored in the two 26 // high bits of the count: 27 // 28 // 0 31 29 // | REDUCTION OR PREFIX COUNT | STATUS | 30 // +---------------------------+--------+ 31 // | 30 | 2 | 32 // 33 // This limits the keyval extent size to (2^30-1). 34 // 35 // Valid status flags are: 36 // 37 // EVEN PASS ODD PASS 38 // ----------------------- ----------------------- 39 // 0 : invalid 0 : prefix available 40 // 1 : reduction available 1 : --- 41 // 2 : prefix available 2 : invalid 42 // 3 : --- 3 : reduction available 43 // 44 // Atomically adding +1 to a "reduction available" status results in a "prefix 45 // available" status. 46 // 47 // clang-format off 48 #define RS_PARTITION_STATUS_EVEN_INVALID (0u) 49 #define RS_PARTITION_STATUS_EVEN_REDUCTION (1u) 50 #define RS_PARTITION_STATUS_EVEN_PREFIX (2u) 51 52 #define RS_PARTITION_STATUS_ODD_INVALID (2u) 53 #define RS_PARTITION_STATUS_ODD_REDUCTION (3u) 54 #define RS_PARTITION_STATUS_ODD_PREFIX (0u) 55 // clang-format on 56 57 // 58 // Arguments to indirectly launched shaders. 59 // 60 // struct rs_indirect_info_dispatch 61 // { 62 // u32vec4 pad; 63 // u32vec4 zero; 64 // u32vec4 histogram; 65 // u32vec4 scatter; 66 // }; 67 // 68 // struct rs_indirect_info_fill 69 // { 70 // uint32_t block_offset; 71 // uint32_t dword_offset_min; 72 // uint32_t dword_offset_max_minus_min; 73 // uint32_t reserved; // padding for 16 bytes 74 // }; 75 // 76 // struct rs_indirect_info 77 // { 78 // rs_indirect_info_fill pad; 79 // rs_indirect_info_fill zero; 80 // rs_indirect_info_dispatch dispatch; 81 // }; 82 // 83 #define RS_STRUCT_INDIRECT_INFO_DISPATCH() \ 84 struct rs_indirect_info_dispatch \ 85 { \ 86 RS_STRUCT_MEMBER_STRUCT(u32vec4, pad) \ 87 RS_STRUCT_MEMBER_STRUCT(u32vec4, zero) \ 88 RS_STRUCT_MEMBER_STRUCT(u32vec4, histogram) \ 89 RS_STRUCT_MEMBER_STRUCT(u32vec4, scatter) \ 90 } 91 92 #define RS_STRUCT_INDIRECT_INFO_FILL() \ 93 struct rs_indirect_info_fill \ 94 { \ 95 RS_STRUCT_MEMBER(uint32_t, block_offset) \ 96 RS_STRUCT_MEMBER(uint32_t, dword_offset_min) \ 97 RS_STRUCT_MEMBER(uint32_t, dword_offset_max_minus_min) \ 98 RS_STRUCT_MEMBER(uint32_t, reserved) \ 99 } 100 101 #define RS_STRUCT_INDIRECT_INFO() \ 102 RS_STRUCT_INDIRECT_INFO_DISPATCH(); \ 103 RS_STRUCT_INDIRECT_INFO_FILL(); \ 104 struct rs_indirect_info \ 105 { \ 106 RS_STRUCT_MEMBER_STRUCT(rs_indirect_info_fill, pad) \ 107 RS_STRUCT_MEMBER_STRUCT(rs_indirect_info_fill, zero) \ 108 RS_STRUCT_MEMBER_STRUCT(rs_indirect_info_dispatch, dispatch) \ 109 } 110 111 // 112 // Define the push constant structures shared by the host and device. 113 // 114 // INIT 115 // ---- 116 // struct rs_push_init 117 // { 118 // uint64_t devaddr_count; // address of count buffer 119 // uint64_t devaddr_indirect; // address of indirect info buffer 120 // }; 121 // 122 // FILL 123 // ---- 124 // struct rs_push_fill 125 // { 126 // uint64_t devaddr_info; // address of indirect info for fill shader 127 // uint64_t devaddr_dwords; // address of dwords extent 128 // uint32_t dword; // dword value used to fill the dwords extent 129 // }; 130 // 131 // HISTOGRAM 132 // --------- 133 // struct rs_push_histogram 134 // { 135 // uint64_t devaddr_histograms; // address of histograms extent 136 // uint64_t devaddr_keyvals; // address of keyvals extent 137 // uint32_t passes; // number of passes 138 // }; 139 // 140 // PREFIX 141 // ------ 142 // struct rs_push_prefix 143 // { 144 // uint64_t devaddr_histograms; // address of histograms extent 145 // }; 146 // 147 // SCATTER 148 // ------- 149 // struct rs_push_scatter 150 // { 151 // uint64_t devaddr_keyvals_in; // address of input keyvals 152 // uint64_t devaddr_keyvals_out; // address of output keyvals 153 // uint64_t devaddr_partitions // address of partitions 154 // uint64_t devaddr_histogram; // address of pass histogram 155 // uint32_t pass_offset; // keyval pass offset 156 // }; 157 // 158 #define RS_STRUCT_PUSH_INIT() \ 159 struct rs_push_init \ 160 { \ 161 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_info) \ 162 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_count) \ 163 RS_STRUCT_MEMBER(uint32_t, passes) \ 164 } 165 166 #define RS_STRUCT_PUSH_FILL() \ 167 struct rs_push_fill \ 168 { \ 169 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_info) \ 170 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_dwords) \ 171 RS_STRUCT_MEMBER(uint32_t, dword) \ 172 } 173 174 #define RS_STRUCT_PUSH_HISTOGRAM() \ 175 struct rs_push_histogram \ 176 { \ 177 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_histograms) \ 178 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_keyvals) \ 179 RS_STRUCT_MEMBER(uint32_t, passes) \ 180 } 181 182 #define RS_STRUCT_PUSH_PREFIX() \ 183 struct rs_push_prefix \ 184 { \ 185 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_histograms) \ 186 } 187 188 #define RS_STRUCT_PUSH_SCATTER() \ 189 struct rs_push_scatter \ 190 { \ 191 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_keyvals_even) \ 192 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_keyvals_odd) \ 193 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_partitions) \ 194 RS_STRUCT_MEMBER(RS_DEVADDR, devaddr_histograms) \ 195 RS_STRUCT_MEMBER(uint32_t, pass_offset) \ 196 } 197 198 //////////////////////////////////////////////////////////////////// 199 // 200 // GLSL 201 // 202 #ifdef VULKAN // defined by GLSL/VK compiler 203 204 // clang-format off 205 #define RS_STRUCT_MEMBER(type_, name_) type_ name_; 206 #define RS_STRUCT_MEMBER_FARRAY(type_, len_, name_) type_ name_[len_]; 207 #define RS_STRUCT_MEMBER_STRUCT(type_, name_) type_ name_; 208 // clang-format on 209 210 //////////////////////////////////////////////////////////////////// 211 // 212 // C/C++ 213 // 214 #else 215 216 #ifdef __cplusplus 217 extern "C" { 218 #endif 219 220 // 221 // 222 // 223 224 #include <stdint.h> 225 226 struct u32vec4 227 { 228 uint32_t x; 229 uint32_t y; 230 uint32_t z; 231 uint32_t w; 232 }; 233 234 // clang-format off 235 #define RS_DEVADDR uint64_t 236 #define RS_STRUCT_MEMBER(type_, name_) type_ name_; 237 #define RS_STRUCT_MEMBER_FARRAY(type_, len_, name_) type_ name_[len_]; 238 #define RS_STRUCT_MEMBER_STRUCT(type_, name_) struct type_ name_; 239 // clang-format on 240 241 RS_STRUCT_PUSH_INIT(); 242 RS_STRUCT_PUSH_FILL(); 243 RS_STRUCT_PUSH_HISTOGRAM(); 244 RS_STRUCT_PUSH_PREFIX(); 245 RS_STRUCT_PUSH_SCATTER(); 246 247 RS_STRUCT_INDIRECT_INFO(); 248 249 // 250 // 251 // 252 253 #ifdef __cplusplus 254 } 255 #endif 256 257 #endif 258 259 // 260 // 261 // 262 263 #endif // SRC_GRAPHICS_LIB_COMPUTE_RADIX_SORT_PLATFORMS_VK_SHADERS_PUSH_H_ 264