summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp4
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp3
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.h2
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp43
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h24
5 files changed, 52 insertions, 24 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index e859a900c..67789db73 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -190,6 +190,10 @@ CachedProgram SpecializeShader(const std::string& code, const GLShader::ShaderEn
190 source += fmt::format("#define SAMPLER_BINDING_{} {}\n", sampler.GetIndex(), 190 source += fmt::format("#define SAMPLER_BINDING_{} {}\n", sampler.GetIndex(),
191 base_bindings.sampler++); 191 base_bindings.sampler++);
192 } 192 }
193 for (const auto& image : entries.images) {
194 source +=
195 fmt::format("#define IMAGE_BINDING_{} {}\n", image.GetIndex(), base_bindings.image++);
196 }
193 197
194 // Transform 1D textures to texture samplers by declaring its preprocessor macros. 198 // Transform 1D textures to texture samplers by declaring its preprocessor macros.
195 for (std::size_t i = 0; i < texture_buffer_usage.size(); ++i) { 199 for (std::size_t i = 0; i < texture_buffer_usage.size(); ++i) {
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 2ae2f1db2..ca04d8618 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -235,6 +235,9 @@ public:
235 for (const auto& sampler : ir.GetSamplers()) { 235 for (const auto& sampler : ir.GetSamplers()) {
236 entries.samplers.emplace_back(sampler); 236 entries.samplers.emplace_back(sampler);
237 } 237 }
238 for (const auto& image : ir.GetImages()) {
239 entries.images.emplace_back(image);
240 }
238 for (const auto& gmem_pair : ir.GetGlobalMemory()) { 241 for (const auto& gmem_pair : ir.GetGlobalMemory()) {
239 const auto& [base, usage] = gmem_pair; 242 const auto& [base, usage] = gmem_pair;
240 entries.global_memory_entries.emplace_back(base.cbuf_index, base.cbuf_offset, 243 entries.global_memory_entries.emplace_back(base.cbuf_index, base.cbuf_offset,
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.h b/src/video_core/renderer_opengl/gl_shader_decompiler.h
index c1569e737..14d11c7fc 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.h
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.h
@@ -27,6 +27,7 @@ struct ShaderEntries;
27using Maxwell = Tegra::Engines::Maxwell3D::Regs; 27using Maxwell = Tegra::Engines::Maxwell3D::Regs;
28using ProgramResult = std::pair<std::string, ShaderEntries>; 28using ProgramResult = std::pair<std::string, ShaderEntries>;
29using SamplerEntry = VideoCommon::Shader::Sampler; 29using SamplerEntry = VideoCommon::Shader::Sampler;
30using ImageEntry = VideoCommon::Shader::Image;
30 31
31class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer { 32class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer {
32public: 33public:
@@ -74,6 +75,7 @@ struct ShaderEntries {
74 std::vector<ConstBufferEntry> const_buffers; 75 std::vector<ConstBufferEntry> const_buffers;
75 std::vector<SamplerEntry> samplers; 76 std::vector<SamplerEntry> samplers;
76 std::vector<SamplerEntry> bindless_samplers; 77 std::vector<SamplerEntry> bindless_samplers;
78 std::vector<ImageEntry> images;
77 std::vector<GlobalMemoryEntry> global_memory_entries; 79 std::vector<GlobalMemoryEntry> global_memory_entries;
78 std::array<bool, Maxwell::NumClipDistances> clip_distances{}; 80 std::array<bool, Maxwell::NumClipDistances> clip_distances{};
79 std::size_t shader_length{}; 81 std::size_t shader_length{};
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 d338ece8e..51d9aae94 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp
@@ -34,11 +34,11 @@ enum class PrecompiledEntryKind : u32 {
34 Dump, 34 Dump,
35}; 35};
36 36
37constexpr u32 NativeVersion = 2; 37constexpr u32 NativeVersion = 3;
38 38
39// Making sure sizes doesn't change by accident 39// Making sure sizes doesn't change by accident
40static_assert(sizeof(BaseBindings) == 12); 40static_assert(sizeof(BaseBindings) == 16);
41static_assert(sizeof(ShaderDiskCacheUsage) == 32); 41static_assert(sizeof(ShaderDiskCacheUsage) == 40);
42 42
43namespace { 43namespace {
44 44
@@ -285,8 +285,7 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
285 if (!LoadObjectFromPrecompiled(code_size)) { 285 if (!LoadObjectFromPrecompiled(code_size)) {
286 return {}; 286 return {};
287 } 287 }
288 288 std::vector<u8> code(code_size);
289 std::string code(code_size, '\0');
290 if (!LoadArrayFromPrecompiled(code.data(), code.size())) { 289 if (!LoadArrayFromPrecompiled(code.data(), code.size())) {
291 return {}; 290 return {};
292 } 291 }
@@ -298,7 +297,6 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
298 if (!LoadObjectFromPrecompiled(const_buffers_count)) { 297 if (!LoadObjectFromPrecompiled(const_buffers_count)) {
299 return {}; 298 return {};
300 } 299 }
301
302 for (u32 i = 0; i < const_buffers_count; ++i) { 300 for (u32 i = 0; i < const_buffers_count; ++i) {
303 u32 max_offset{}; 301 u32 max_offset{};
304 u32 index{}; 302 u32 index{};
@@ -314,7 +312,6 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
314 if (!LoadObjectFromPrecompiled(samplers_count)) { 312 if (!LoadObjectFromPrecompiled(samplers_count)) {
315 return {}; 313 return {};
316 } 314 }
317
318 for (u32 i = 0; i < samplers_count; ++i) { 315 for (u32 i = 0; i < samplers_count; ++i) {
319 u64 offset{}; 316 u64 offset{};
320 u64 index{}; 317 u64 index{};
@@ -332,11 +329,28 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
332 static_cast<Tegra::Shader::TextureType>(type), is_array, is_shadow, is_bindless); 329 static_cast<Tegra::Shader::TextureType>(type), is_array, is_shadow, is_bindless);
333 } 330 }
334 331
332 u32 images_count{};
333 if (!LoadObjectFromPrecompiled(images_count)) {
334 return {};
335 }
336 for (u32 i = 0; i < images_count; ++i) {
337 u64 offset{};
338 u64 index{};
339 u32 type{};
340 u8 is_bindless{};
341 if (!LoadObjectFromPrecompiled(offset) || !LoadObjectFromPrecompiled(index) ||
342 !LoadObjectFromPrecompiled(type) || !LoadObjectFromPrecompiled(is_bindless)) {
343 return {};
344 }
345 entry.entries.images.emplace_back(
346 static_cast<std::size_t>(offset), static_cast<std::size_t>(index),
347 static_cast<Tegra::Shader::ImageType>(type), is_bindless != 0);
348 }
349
335 u32 global_memory_count{}; 350 u32 global_memory_count{};
336 if (!LoadObjectFromPrecompiled(global_memory_count)) { 351 if (!LoadObjectFromPrecompiled(global_memory_count)) {
337 return {}; 352 return {};
338 } 353 }
339
340 for (u32 i = 0; i < global_memory_count; ++i) { 354 for (u32 i = 0; i < global_memory_count; ++i) {
341 u32 cbuf_index{}; 355 u32 cbuf_index{};
342 u32 cbuf_offset{}; 356 u32 cbuf_offset{};
@@ -360,7 +374,6 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
360 if (!LoadObjectFromPrecompiled(shader_length)) { 374 if (!LoadObjectFromPrecompiled(shader_length)) {
361 return {}; 375 return {};
362 } 376 }
363
364 entry.entries.shader_length = static_cast<std::size_t>(shader_length); 377 entry.entries.shader_length = static_cast<std::size_t>(shader_length);
365 378
366 return entry; 379 return entry;
@@ -400,6 +413,18 @@ bool ShaderDiskCacheOpenGL::SaveDecompiledFile(u64 unique_identifier, const std:
400 } 413 }
401 } 414 }
402 415
416 if (!SaveObjectToPrecompiled(static_cast<u32>(entries.images.size()))) {
417 return false;
418 }
419 for (const auto& image : entries.images) {
420 if (!SaveObjectToPrecompiled(static_cast<u64>(image.GetOffset())) ||
421 !SaveObjectToPrecompiled(static_cast<u64>(image.GetIndex())) ||
422 !SaveObjectToPrecompiled(static_cast<u32>(image.GetType())) ||
423 !SaveObjectToPrecompiled(static_cast<u8>(image.IsBindless() ? 1 : 0))) {
424 return false;
425 }
426 }
427
403 if (!SaveObjectToPrecompiled(static_cast<u32>(entries.global_memory_entries.size()))) { 428 if (!SaveObjectToPrecompiled(static_cast<u32>(entries.global_memory_entries.size()))) {
404 return false; 429 return false;
405 } 430 }
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 7c9f0cc75..aa12ffc71 100644
--- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h
@@ -45,9 +45,11 @@ struct BaseBindings {
45 u32 cbuf{}; 45 u32 cbuf{};
46 u32 gmem{}; 46 u32 gmem{};
47 u32 sampler{}; 47 u32 sampler{};
48 u32 image{};
48 49
49 bool operator==(const BaseBindings& rhs) const { 50 bool operator==(const BaseBindings& rhs) const {
50 return std::tie(cbuf, gmem, sampler) == std::tie(rhs.cbuf, rhs.gmem, rhs.sampler); 51 return std::tie(cbuf, gmem, sampler, image) ==
52 std::tie(rhs.cbuf, rhs.gmem, rhs.sampler, rhs.image);
51 } 53 }
52 54
53 bool operator!=(const BaseBindings& rhs) const { 55 bool operator!=(const BaseBindings& rhs) const {
@@ -91,8 +93,11 @@ namespace std {
91 93
92template <> 94template <>
93struct hash<OpenGL::BaseBindings> { 95struct hash<OpenGL::BaseBindings> {
94 std::size_t operator()(const OpenGL::BaseBindings& bindings) const noexcept { 96 std::size_t operator()(const OpenGL::BaseBindings& bindings) const {
95 return bindings.cbuf | bindings.gmem << 8 | bindings.sampler << 16; 97 return static_cast<std::size_t>(bindings.cbuf) ^
98 (static_cast<std::size_t>(bindings.gmem) << 8) ^
99 (static_cast<std::size_t>(bindings.sampler) << 16) ^
100 (static_cast<std::size_t>(bindings.image) << 24);
96 } 101 }
97}; 102};
98 103
@@ -300,19 +305,8 @@ private:
300 return LoadArrayFromPrecompiled(&object, 1); 305 return LoadArrayFromPrecompiled(&object, 1);
301 } 306 }
302 307
303 bool LoadObjectFromPrecompiled(bool& object) {
304 u8 value;
305 const bool read_ok = LoadArrayFromPrecompiled(&value, 1);
306 if (!read_ok) {
307 return false;
308 }
309
310 object = value != 0;
311 return true;
312 }
313
314 // Core system
315 Core::System& system; 308 Core::System& system;
309
316 // Stores whole precompiled cache which will be read from or saved to the precompiled chache 310 // Stores whole precompiled cache which will be read from or saved to the precompiled chache
317 // file 311 // file
318 FileSys::VectorVfsFile precompiled_cache_virtual_file; 312 FileSys::VectorVfsFile precompiled_cache_virtual_file;