summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp6
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h20
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp12
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h82
4 files changed, 64 insertions, 56 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index bbcd15867..4883e4f62 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -431,11 +431,11 @@ CachedProgram ShaderCacheOpenGL::GeneratePrecompiledProgram(
431 return shader; 431 return shader;
432} 432}
433 433
434std::map<u64, UnspecializedShader> ShaderCacheOpenGL::GenerateUnspecializedShaders( 434std::unordered_map<u64, UnspecializedShader> ShaderCacheOpenGL::GenerateUnspecializedShaders(
435 const std::atomic_bool& stop_loading, const VideoCore::DiskResourceLoadCallback& callback, 435 const std::atomic_bool& stop_loading, const VideoCore::DiskResourceLoadCallback& callback,
436 const std::vector<ShaderDiskCacheRaw>& raws, 436 const std::vector<ShaderDiskCacheRaw>& raws,
437 const std::map<u64, ShaderDiskCacheDecompiled>& decompiled) { 437 const std::unordered_map<u64, ShaderDiskCacheDecompiled>& decompiled) {
438 std::map<u64, UnspecializedShader> unspecialized; 438 std::unordered_map<u64, UnspecializedShader> unspecialized;
439 439
440 if (callback) 440 if (callback)
441 callback(VideoCore::LoadCallbackStage::Decompile, 0, raws.size()); 441 callback(VideoCore::LoadCallbackStage::Decompile, 0, raws.size());
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h
index 9c6b19fc3..97eed192f 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_cache.h
@@ -5,10 +5,10 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <map>
9#include <memory> 8#include <memory>
10#include <set> 9#include <set>
11#include <tuple> 10#include <tuple>
11#include <unordered_map>
12 12
13#include <glad/glad.h> 13#include <glad/glad.h>
14 14
@@ -34,8 +34,8 @@ struct UnspecializedShader;
34using Shader = std::shared_ptr<CachedShader>; 34using Shader = std::shared_ptr<CachedShader>;
35using CachedProgram = std::shared_ptr<OGLProgram>; 35using CachedProgram = std::shared_ptr<OGLProgram>;
36using Maxwell = Tegra::Engines::Maxwell3D::Regs; 36using Maxwell = Tegra::Engines::Maxwell3D::Regs;
37using PrecompiledPrograms = std::map<ShaderDiskCacheUsage, CachedProgram>; 37using PrecompiledPrograms = std::unordered_map<ShaderDiskCacheUsage, CachedProgram>;
38using PrecompiledShaders = std::map<u64, GLShader::ProgramResult>; 38using PrecompiledShaders = std::unordered_map<u64, GLShader::ProgramResult>;
39 39
40class CachedShader final : public RasterizerCacheObject { 40class CachedShader final : public RasterizerCacheObject {
41public: 41public:
@@ -102,12 +102,12 @@ private:
102 102
103 std::string code; 103 std::string code;
104 104
105 std::map<BaseBindings, CachedProgram> programs; 105 std::unordered_map<BaseBindings, CachedProgram> programs;
106 std::map<BaseBindings, GeometryPrograms> geometry_programs; 106 std::unordered_map<BaseBindings, GeometryPrograms> geometry_programs;
107 107
108 std::map<u32, GLuint> cbuf_resource_cache; 108 std::unordered_map<u32, GLuint> cbuf_resource_cache;
109 std::map<u32, GLuint> gmem_resource_cache; 109 std::unordered_map<u32, GLuint> gmem_resource_cache;
110 std::map<u32, GLint> uniform_cache; 110 std::unordered_map<u32, GLint> uniform_cache;
111}; 111};
112 112
113class ShaderCacheOpenGL final : public RasterizerCache<Shader> { 113class ShaderCacheOpenGL final : public RasterizerCache<Shader> {
@@ -122,10 +122,10 @@ public:
122 Shader GetStageProgram(Maxwell::ShaderProgram program); 122 Shader GetStageProgram(Maxwell::ShaderProgram program);
123 123
124private: 124private:
125 std::map<u64, UnspecializedShader> GenerateUnspecializedShaders( 125 std::unordered_map<u64, UnspecializedShader> GenerateUnspecializedShaders(
126 const std::atomic_bool& stop_loading, const VideoCore::DiskResourceLoadCallback& callback, 126 const std::atomic_bool& stop_loading, const VideoCore::DiskResourceLoadCallback& callback,
127 const std::vector<ShaderDiskCacheRaw>& raws, 127 const std::vector<ShaderDiskCacheRaw>& raws,
128 const std::map<u64, ShaderDiskCacheDecompiled>& decompiled); 128 const std::unordered_map<u64, ShaderDiskCacheDecompiled>& decompiled);
129 129
130 CachedProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump, 130 CachedProgram GeneratePrecompiledProgram(const ShaderDiskCacheDump& dump,
131 const std::set<GLenum>& supported_formats); 131 const std::set<GLenum>& supported_formats);
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 d88fff388..554d0dfb9 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
@@ -211,8 +211,8 @@ ShaderDiskCacheOpenGL::LoadTransferable() {
211 return {{raws, usages}}; 211 return {{raws, usages}};
212} 212}
213 213
214std::pair<std::map<u64, ShaderDiskCacheDecompiled>, 214std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>,
215 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>> 215 std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>
216ShaderDiskCacheOpenGL::LoadPrecompiled() { 216ShaderDiskCacheOpenGL::LoadPrecompiled() {
217 if (!IsUsable()) 217 if (!IsUsable())
218 return {}; 218 return {};
@@ -236,8 +236,8 @@ ShaderDiskCacheOpenGL::LoadPrecompiled() {
236 return *result; 236 return *result;
237} 237}
238 238
239std::optional<std::pair<std::map<u64, ShaderDiskCacheDecompiled>, 239std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>,
240 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>> 240 std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>>
241ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) { 241ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
242 ShaderCacheVersionHash file_hash{}; 242 ShaderCacheVersionHash file_hash{};
243 if (file.ReadArray(file_hash.data(), file_hash.size()) != file_hash.size()) { 243 if (file.ReadArray(file_hash.data(), file_hash.size()) != file_hash.size()) {
@@ -248,8 +248,8 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
248 return {}; 248 return {};
249 } 249 }
250 250
251 std::map<u64, ShaderDiskCacheDecompiled> decompiled; 251 std::unordered_map<u64, ShaderDiskCacheDecompiled> decompiled;
252 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps; 252 std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps;
253 while (file.Tell() < file.GetSize()) { 253 while (file.Tell() < file.GetSize()) {
254 PrecompiledEntryKind kind{}; 254 PrecompiledEntryKind kind{};
255 if (file.ReadBytes(&kind, sizeof(u32)) != sizeof(u32)) { 255 if (file.ReadBytes(&kind, sizeof(u32)) != sizeof(u32)) {
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 061c4f204..6be0c0547 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h
@@ -5,9 +5,10 @@
5#pragma once 5#pragma once
6 6
7#include <optional> 7#include <optional>
8#include <set>
9#include <string> 8#include <string>
10#include <tuple> 9#include <tuple>
10#include <unordered_map>
11#include <unordered_set>
11#include <utility> 12#include <utility>
12#include <vector> 13#include <vector>
13 14
@@ -37,23 +38,54 @@ struct BaseBindings {
37 u32 gmem{}; 38 u32 gmem{};
38 u32 sampler{}; 39 u32 sampler{};
39 40
40 bool operator<(const BaseBindings& rhs) const {
41 return Tie() < rhs.Tie();
42 }
43
44 bool operator==(const BaseBindings& rhs) const { 41 bool operator==(const BaseBindings& rhs) const {
45 return Tie() == rhs.Tie(); 42 return std::tie(cbuf, gmem, sampler) == std::tie(rhs.cbuf, rhs.gmem, rhs.sampler);
46 } 43 }
47 44
48 bool operator!=(const BaseBindings& rhs) const { 45 bool operator!=(const BaseBindings& rhs) const {
49 return !operator==(rhs); 46 return !operator==(rhs);
50 } 47 }
48};
49
50/// Describes how a shader is used
51struct ShaderDiskCacheUsage {
52 u64 unique_identifier{};
53 BaseBindings bindings;
54 GLenum primitive{};
55
56 bool operator==(const ShaderDiskCacheUsage& rhs) const {
57 return std::tie(unique_identifier, bindings, primitive) ==
58 std::tie(rhs.unique_identifier, rhs.bindings, rhs.primitive);
59 }
60
61 bool operator!=(const ShaderDiskCacheUsage& rhs) const {
62 return !operator==(rhs);
63 }
64};
65
66} // namespace OpenGL
67
68namespace std {
69
70template <>
71struct hash<OpenGL::BaseBindings> {
72 std::size_t operator()(const OpenGL::BaseBindings& bindings) const {
73 return bindings.cbuf | bindings.gmem << 8 | bindings.sampler << 16;
74 }
75};
51 76
52 std::tuple<u32, u32, u32> Tie() const { 77template <>
53 return std::tie(cbuf, gmem, sampler); 78struct hash<OpenGL::ShaderDiskCacheUsage> {
79 std::size_t operator()(const OpenGL::ShaderDiskCacheUsage& usage) const {
80 return static_cast<std::size_t>(usage.unique_identifier) ^
81 std::hash<OpenGL::BaseBindings>()(usage.bindings) ^ usage.primitive << 16;
54 } 82 }
55}; 83};
56 84
85} // namespace std
86
87namespace OpenGL {
88
57/// Describes a shader how it's used by the guest GPU 89/// Describes a shader how it's used by the guest GPU
58class ShaderDiskCacheRaw { 90class ShaderDiskCacheRaw {
59public: 91public:
@@ -114,30 +146,6 @@ private:
114 ProgramCode program_code_b; 146 ProgramCode program_code_b;
115}; 147};
116 148
117/// Describes how a shader is used
118struct ShaderDiskCacheUsage {
119 bool operator<(const ShaderDiskCacheUsage& rhs) const {
120 return Tie() < rhs.Tie();
121 }
122
123 bool operator==(const ShaderDiskCacheUsage& rhs) const {
124 return Tie() == rhs.Tie();
125 }
126
127 bool operator!=(const ShaderDiskCacheUsage& rhs) const {
128 return !operator==(rhs);
129 }
130
131 u64 unique_identifier{};
132 BaseBindings bindings;
133 GLenum primitive{};
134
135private:
136 std::tuple<u64, BaseBindings, GLenum> Tie() const {
137 return std::tie(unique_identifier, bindings, primitive);
138 }
139};
140
141/// Contains decompiled data from a shader 149/// Contains decompiled data from a shader
142struct ShaderDiskCacheDecompiled { 150struct ShaderDiskCacheDecompiled {
143 std::string code; 151 std::string code;
@@ -159,8 +167,8 @@ public:
159 LoadTransferable(); 167 LoadTransferable();
160 168
161 /// Loads current game's precompiled cache. Invalidates on failure. 169 /// Loads current game's precompiled cache. Invalidates on failure.
162 std::pair<std::map<u64, ShaderDiskCacheDecompiled>, 170 std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>,
163 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>> 171 std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>
164 LoadPrecompiled(); 172 LoadPrecompiled();
165 173
166 /// Removes the transferable (and precompiled) cache file. 174 /// Removes the transferable (and precompiled) cache file.
@@ -184,8 +192,8 @@ public:
184 192
185private: 193private:
186 /// Loads the transferable cache. Returns empty on failure. 194 /// Loads the transferable cache. Returns empty on failure.
187 std::optional<std::pair<std::map<u64, ShaderDiskCacheDecompiled>, 195 std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>,
188 std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>> 196 std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>>
189 LoadPrecompiledFile(FileUtil::IOFile& file); 197 LoadPrecompiledFile(FileUtil::IOFile& file);
190 198
191 /// Loads a decompiled cache entry from the passed file. Returns empty on failure. 199 /// Loads a decompiled cache entry from the passed file. Returns empty on failure.
@@ -229,7 +237,7 @@ private:
229 // Copre system 237 // Copre system
230 Core::System& system; 238 Core::System& system;
231 // Stored transferable shaders 239 // Stored transferable shaders
232 std::map<u64, std::set<ShaderDiskCacheUsage>> transferable; 240 std::map<u64, std::unordered_set<ShaderDiskCacheUsage>> transferable;
233 // The cache has been loaded at boot 241 // The cache has been loaded at boot
234 bool tried_to_load{}; 242 bool tried_to_load{};
235}; 243};