| 115 | } |
| 116 | |
| 117 | static void LoadShaders() |
| 118 | { |
| 119 | static bool loaded = false; |
| 120 | if (loaded) |
| 121 | return; |
| 122 | loaded = true; |
| 123 | |
| 124 | try |
| 125 | { |
| 126 | FString path = CreateProgramCacheName(false); |
| 127 | FileReader fr; |
| 128 | if (!fr.OpenFile(path.GetChars())) |
| 129 | I_Error("Could not open shader file"); |
| 130 | |
| 131 | char magic[4]; |
| 132 | fr.Read(magic, 4); |
| 133 | if (memcmp(magic, ShaderMagic, 4) != 0) |
| 134 | I_Error("Not a shader cache file"); |
| 135 | |
| 136 | uint32_t count = fr.ReadUInt32(); |
| 137 | if (count > 512) |
| 138 | I_Error("Too many shaders cached"); |
| 139 | |
| 140 | for (uint32_t i = 0; i < count; i++) |
| 141 | { |
| 142 | char hexdigest[33]; |
| 143 | if (fr.Read(hexdigest, 32) != 32) |
| 144 | I_Error("Read error"); |
| 145 | hexdigest[32] = 0; |
| 146 | |
| 147 | std::unique_ptr<ProgramBinary> binary(new ProgramBinary()); |
| 148 | binary->format = fr.ReadUInt32(); |
| 149 | uint32_t size = fr.ReadUInt32(); |
| 150 | if (size > 1024 * 1024) |
| 151 | I_Error("Shader too big, probably file corruption"); |
| 152 | |
| 153 | binary->data.Resize(size); |
| 154 | if (fr.Read(binary->data.Data(), binary->data.Size()) != binary->data.Size()) |
| 155 | I_Error("Read error"); |
| 156 | |
| 157 | ShaderCache[hexdigest] = std::move(binary); |
| 158 | } |
| 159 | } |
| 160 | catch (...) |
| 161 | { |
| 162 | ShaderCache.clear(); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | static void SaveShaders() |
| 167 | { |
no test coverage detected