| 443 | #define kBufferSize 32 |
| 444 | |
| 445 | std::string NumToNiceStr(const size_t sz) { |
| 446 | const char prefixes[] = "KMGTPEZY"; |
| 447 | char buf[kBufferSize]; |
| 448 | int which = -1; |
| 449 | double result = (double)sz; |
| 450 | while (result > 1024 && which < 7) { |
| 451 | result /= 1024; |
| 452 | ++which; |
| 453 | } |
| 454 | |
| 455 | char unit[] = "\0i"; |
| 456 | if (which >= 0) { |
| 457 | unit[0] = prefixes[which]; |
| 458 | } |
| 459 | #ifdef _WIN32 |
| 460 | _snprintf_s(buf, kBufferSize * sizeof(char), kBufferSize, "%.2f %sB", result, unit); |
| 461 | #else |
| 462 | snprintf(buf, kBufferSize, "%.2f %sB", result, unit); |
| 463 | #endif |
| 464 | return std::string(buf); |
| 465 | } |
| 466 | |
| 467 | std::string append_human_readable(VkDeviceSize memory) { |
| 468 | return std::to_string(memory) + " (" + to_hex_str(memory) + ") (" + NumToNiceStr(static_cast<size_t>(memory)) + ")"; |
no outgoing calls
no test coverage detected