| 986 | } |
| 987 | |
| 988 | static std::vector<uint32_t> LoadSpirvFile(const std::string& path) { |
| 989 | std::ifstream stream(path, std::ios::binary | std::ios::ate); |
| 990 | if (!stream.is_open()) |
| 991 | throw std::runtime_error("Unable to open SPIR-V shader: " + path); |
| 992 | const std::streamsize size = stream.tellg(); |
| 993 | constexpr std::streamsize kMaxShaderBytes = 16 * 1024 * 1024; |
| 994 | if (size <= 0 || size > kMaxShaderBytes || (size % 4) != 0) |
| 995 | throw std::runtime_error("Invalid SPIR-V shader size: " + path); |
| 996 | stream.seekg(0, std::ios::beg); |
| 997 | std::vector<uint32_t> code(static_cast<size_t>(size) / 4); |
| 998 | const size_t byte_count = code.size() * sizeof(uint32_t); |
| 999 | if (byte_count != static_cast<size_t>(size)) |
| 1000 | throw std::runtime_error("SPIR-V shader size overflow: " + path); |
| 1001 | char* byte_ptr = reinterpret_cast<char*>(code.data()); |
| 1002 | if (!stream.read(byte_ptr, static_cast<std::streamsize>(byte_count)) || |
| 1003 | stream.gcount() != static_cast<std::streamsize>(byte_count)) |
| 1004 | throw std::runtime_error("Unable to read SPIR-V shader: " + path); |
| 1005 | return code; |
| 1006 | } |
| 1007 | |
| 1008 | static void CheckVk(VkResult result, const std::string& context) { |
| 1009 | if (result != VK_SUCCESS) |