| 209 | } |
| 210 | |
| 211 | Astc::Astc(const Image &image) : |
| 212 | Image{image.get_name()} |
| 213 | { |
| 214 | init(); |
| 215 | |
| 216 | auto fs = vkb::filesystem::get(); |
| 217 | |
| 218 | size_t key = ASTC_CACHE_SEED; |
| 219 | glm::detail::hash_combine(key, image.get_data_hash()); |
| 220 | |
| 221 | constexpr bool use_cache = true; |
| 222 | constexpr uint32_t bytes_per_pixel = 4; |
| 223 | constexpr const char file_cache_header[ASTC_CACHE_HEADER_SIZE] = "ASTCConvertedDataV01"; |
| 224 | const auto profile = to_profile(image.get_format()); |
| 225 | |
| 226 | auto can_load_from_file = [this, profile, fs, file_cache_header, bytes_per_pixel, use_cache](const Path &path, std::vector<uint8_t> &dst_data, uint32_t width, uint32_t height, uint32_t depth) { |
| 227 | if (!use_cache) |
| 228 | { |
| 229 | LOGD("Device does not support ASTC format and cache is disabled. ASTC image {} will be decoded.", get_name()) |
| 230 | return false; |
| 231 | } |
| 232 | try |
| 233 | { |
| 234 | if (!fs->exists(path)) |
| 235 | { |
| 236 | LOGW("Device does not support ASTC format and cache file {} does not exist. ASTC image {} will be decoded.", path.string(), get_name()) |
| 237 | return false; |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | LOGD("Loading ASTC image {} from cache file {}", get_name(), path.string()) |
| 242 | } |
| 243 | size_t offset = 0; |
| 244 | |
| 245 | auto copy_from_file = [fs, path](void *dst, size_t *offset, size_t content_size) { |
| 246 | const auto bin_content = fs->read_chunk(path, *offset, content_size); |
| 247 | std::memcpy(dst, &bin_content[0], content_size); |
| 248 | *offset += content_size; |
| 249 | }; |
| 250 | |
| 251 | char header[ASTC_CACHE_HEADER_SIZE]; |
| 252 | copy_from_file(&header, &offset, ASTC_CACHE_HEADER_SIZE); |
| 253 | if (std::strcmp(header, file_cache_header) != 0) |
| 254 | { |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | uint32_t file_width, file_height, file_depth; |
| 259 | copy_from_file(&file_width, &offset, sizeof(std::uint32_t)); |
| 260 | copy_from_file(&file_height, &offset, sizeof(std::uint32_t)); |
| 261 | copy_from_file(&file_depth, &offset, sizeof(std::uint32_t)); |
| 262 | |
| 263 | if (file_width != width || width == 0 || |
| 264 | file_height != height || height == 0 || |
| 265 | file_depth != depth || depth == 0) |
| 266 | { |
| 267 | return false; |
| 268 | } |
nothing calls this directly
no test coverage detected