diff options
| author | 2019-01-13 23:33:00 -0300 | |
|---|---|---|
| committer | 2019-02-06 22:20:57 -0300 | |
| commit | 57fb15d2a3fcc6512145c5a46c18f168994a65b0 (patch) | |
| tree | 5c27e73872a6896f62fa6aa7fe8b1578d379cbbb /src | |
| parent | gl_shader_disk_cache: Add transferable load (diff) | |
| download | yuzu-57fb15d2a3fcc6512145c5a46c18f168994a65b0.tar.gz yuzu-57fb15d2a3fcc6512145c5a46c18f168994a65b0.tar.xz yuzu-57fb15d2a3fcc6512145c5a46c18f168994a65b0.zip | |
gl_shader_disk_cache: Add precompiled save
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 43 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.h | 14 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index eb9854b9f..0c42e3d8a 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | |||
| @@ -27,6 +27,9 @@ enum class EntryKind : u32 { | |||
| 27 | 27 | ||
| 28 | constexpr u32 NativeVersion = 1; | 28 | constexpr u32 NativeVersion = 1; |
| 29 | 29 | ||
| 30 | // TODO(Rodrigo): Hash files | ||
| 31 | constexpr u64 PrecompiledHash = 0xdeadbeefdeadbeef; | ||
| 32 | |||
| 30 | // Making sure sizes doesn't change by accident | 33 | // Making sure sizes doesn't change by accident |
| 31 | static_assert(sizeof(BaseBindings) == 12); | 34 | static_assert(sizeof(BaseBindings) == 12); |
| 32 | static_assert(sizeof(ShaderDiskCacheUsage) == 24); | 35 | static_assert(sizeof(ShaderDiskCacheUsage) == 24); |
| @@ -153,6 +156,26 @@ void ShaderDiskCacheOpenGL::SaveUsage(const ShaderDiskCacheUsage& usage) { | |||
| 153 | file.WriteObject(usage); | 156 | file.WriteObject(usage); |
| 154 | } | 157 | } |
| 155 | 158 | ||
| 159 | void ShaderDiskCacheOpenGL::SavePrecompiled(const ShaderDiskCacheUsage& usage, GLuint program) { | ||
| 160 | FileUtil::IOFile file = AppendPrecompiledFile(); | ||
| 161 | if (!file.IsOpen()) { | ||
| 162 | return; | ||
| 163 | } | ||
| 164 | |||
| 165 | file.WriteObject(usage); | ||
| 166 | |||
| 167 | GLint binary_length{}; | ||
| 168 | glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binary_length); | ||
| 169 | |||
| 170 | GLenum binary_format{}; | ||
| 171 | std::vector<u8> binary(binary_length); | ||
| 172 | glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data()); | ||
| 173 | |||
| 174 | file.WriteObject(static_cast<u32>(binary_format)); | ||
| 175 | file.WriteObject(static_cast<u32>(binary_length)); | ||
| 176 | file.WriteArray(binary.data(), binary.size()); | ||
| 177 | } | ||
| 178 | |||
| 156 | FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { | 179 | FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { |
| 157 | if (!EnsureDirectories()) { | 180 | if (!EnsureDirectories()) { |
| 158 | return {}; | 181 | return {}; |
| @@ -173,6 +196,26 @@ FileUtil::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { | |||
| 173 | return file; | 196 | return file; |
| 174 | } | 197 | } |
| 175 | 198 | ||
| 199 | FileUtil::IOFile ShaderDiskCacheOpenGL::AppendPrecompiledFile() const { | ||
| 200 | if (!EnsureDirectories()) { | ||
| 201 | return {}; | ||
| 202 | } | ||
| 203 | |||
| 204 | const auto precompiled_path{GetPrecompiledPath()}; | ||
| 205 | const bool existed = FileUtil::Exists(precompiled_path); | ||
| 206 | |||
| 207 | FileUtil::IOFile file(precompiled_path, "ab"); | ||
| 208 | if (!file.IsOpen()) { | ||
| 209 | LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path); | ||
| 210 | return {}; | ||
| 211 | } | ||
| 212 | |||
| 213 | if (!existed || file.GetSize() == 0) { | ||
| 214 | file.WriteObject(PrecompiledHash); | ||
| 215 | } | ||
| 216 | return file; | ||
| 217 | } | ||
| 218 | |||
| 176 | bool ShaderDiskCacheOpenGL::EnsureDirectories() const { | 219 | bool ShaderDiskCacheOpenGL::EnsureDirectories() const { |
| 177 | const auto CreateDir = [](const std::string& dir) { | 220 | const auto CreateDir = [](const std::string& dir) { |
| 178 | if (!FileUtil::CreateDir(dir)) { | 221 | if (!FileUtil::CreateDir(dir)) { |
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.h b/src/video_core/renderer_opengl/gl_shader_disk_cache.h index 46d762b64..fdb29caa5 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h | |||
| @@ -130,6 +130,14 @@ public: | |||
| 130 | } | 130 | } |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | struct ShaderDiskCachePrecompiledEntry { | ||
| 134 | ShaderDiskCacheUsage usage; | ||
| 135 | GLenum binary_format; | ||
| 136 | std::vector<u8> binary; | ||
| 137 | std::string code; | ||
| 138 | GLShader::ShaderEntries entries; | ||
| 139 | }; | ||
| 140 | |||
| 133 | class ShaderDiskCacheOpenGL { | 141 | class ShaderDiskCacheOpenGL { |
| 134 | public: | 142 | public: |
| 135 | /// Loads transferable cache. If file has a old version, it deletes it. Returns true on success. | 143 | /// Loads transferable cache. If file has a old version, it deletes it. Returns true on success. |
| @@ -142,10 +150,16 @@ public: | |||
| 142 | /// Saves shader usage to the transferable file. Does not check for collisions. | 150 | /// Saves shader usage to the transferable file. Does not check for collisions. |
| 143 | void SaveUsage(const ShaderDiskCacheUsage& usage); | 151 | void SaveUsage(const ShaderDiskCacheUsage& usage); |
| 144 | 152 | ||
| 153 | /// Saves a precompiled shader entry. Does not check for collisions. | ||
| 154 | void SavePrecompiled(const ShaderDiskCacheUsage& usage, GLuint program); | ||
| 155 | |||
| 145 | private: | 156 | private: |
| 146 | /// Opens current game's transferable file and write it's header if it doesn't exist | 157 | /// Opens current game's transferable file and write it's header if it doesn't exist |
| 147 | FileUtil::IOFile AppendTransferableFile() const; | 158 | FileUtil::IOFile AppendTransferableFile() const; |
| 148 | 159 | ||
| 160 | /// Opens current game's precompiled file and write it's header if it doesn't exist | ||
| 161 | FileUtil::IOFile AppendPrecompiledFile() const; | ||
| 162 | |||
| 149 | /// Create shader disk cache directories. Returns true on success. | 163 | /// Create shader disk cache directories. Returns true on success. |
| 150 | bool EnsureDirectories() const; | 164 | bool EnsureDirectories() const; |
| 151 | 165 | ||