diff options
| author | 2019-09-23 14:02:02 -0400 | |
|---|---|---|
| committer | 2019-10-25 09:01:29 -0400 | |
| commit | 1a58f45d76fe7756dd365e099d1536da769c1eab (patch) | |
| tree | 668a61e870c57249edf94ba2e2002d3ace18b118 | |
| parent | Shader_IR: Implement BRX tracking. (diff) | |
| download | yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.gz yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.xz yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.zip | |
VideoCore: Unify const buffer accessing along engines and provide ConstBufferLocker class to shaders.
| -rw-r--r-- | CMakeModules/GenerateSCMRev.cmake | 6 | ||||
| -rw-r--r-- | src/common/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/common/hash.h | 11 | ||||
| -rw-r--r-- | src/video_core/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | src/video_core/engines/const_buffer_engine_interface.h | 26 | ||||
| -rw-r--r-- | src/video_core/engines/kepler_compute.cpp | 3 | ||||
| -rw-r--r-- | src/video_core/engines/kepler_compute.h | 5 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 3 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/shader/const_buffer_locker.cpp | 72 | ||||
| -rw-r--r-- | src/video_core/shader/const_buffer_locker.h | 50 | ||||
| -rw-r--r-- | src/video_core/shader/shader_ir.h | 1 |
13 files changed, 187 insertions, 15 deletions
diff --git a/CMakeModules/GenerateSCMRev.cmake b/CMakeModules/GenerateSCMRev.cmake index 09eabe2c7..21e03ae98 100644 --- a/CMakeModules/GenerateSCMRev.cmake +++ b/CMakeModules/GenerateSCMRev.cmake | |||
| @@ -85,10 +85,12 @@ set(HASH_FILES | |||
| 85 | "${VIDEO_CORE}/shader/decode/xmad.cpp" | 85 | "${VIDEO_CORE}/shader/decode/xmad.cpp" |
| 86 | "${VIDEO_CORE}/shader/ast.cpp" | 86 | "${VIDEO_CORE}/shader/ast.cpp" |
| 87 | "${VIDEO_CORE}/shader/ast.h" | 87 | "${VIDEO_CORE}/shader/ast.h" |
| 88 | "${VIDEO_CORE}/shader/control_flow.cpp" | ||
| 89 | "${VIDEO_CORE}/shader/control_flow.h" | ||
| 90 | "${VIDEO_CORE}/shader/compiler_settings.cpp" | 88 | "${VIDEO_CORE}/shader/compiler_settings.cpp" |
| 91 | "${VIDEO_CORE}/shader/compiler_settings.h" | 89 | "${VIDEO_CORE}/shader/compiler_settings.h" |
| 90 | "${VIDEO_CORE}/shader/const_buffer_locker.cpp" | ||
| 91 | "${VIDEO_CORE}/shader/const_buffer_locker.h" | ||
| 92 | "${VIDEO_CORE}/shader/control_flow.cpp" | ||
| 93 | "${VIDEO_CORE}/shader/control_flow.h" | ||
| 92 | "${VIDEO_CORE}/shader/decode.cpp" | 94 | "${VIDEO_CORE}/shader/decode.cpp" |
| 93 | "${VIDEO_CORE}/shader/expr.cpp" | 95 | "${VIDEO_CORE}/shader/expr.cpp" |
| 94 | "${VIDEO_CORE}/shader/expr.h" | 96 | "${VIDEO_CORE}/shader/expr.h" |
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 5b51fcafa..9c6f1c07c 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -74,10 +74,12 @@ add_custom_command(OUTPUT scm_rev.cpp | |||
| 74 | "${VIDEO_CORE}/shader/decode/xmad.cpp" | 74 | "${VIDEO_CORE}/shader/decode/xmad.cpp" |
| 75 | "${VIDEO_CORE}/shader/ast.cpp" | 75 | "${VIDEO_CORE}/shader/ast.cpp" |
| 76 | "${VIDEO_CORE}/shader/ast.h" | 76 | "${VIDEO_CORE}/shader/ast.h" |
| 77 | "${VIDEO_CORE}/shader/control_flow.cpp" | ||
| 78 | "${VIDEO_CORE}/shader/control_flow.h" | ||
| 79 | "${VIDEO_CORE}/shader/compiler_settings.cpp" | 77 | "${VIDEO_CORE}/shader/compiler_settings.cpp" |
| 80 | "${VIDEO_CORE}/shader/compiler_settings.h" | 78 | "${VIDEO_CORE}/shader/compiler_settings.h" |
| 79 | "${VIDEO_CORE}/shader/const_buffer_locker.cpp" | ||
| 80 | "${VIDEO_CORE}/shader/const_buffer_locker.h" | ||
| 81 | "${VIDEO_CORE}/shader/control_flow.cpp" | ||
| 82 | "${VIDEO_CORE}/shader/control_flow.h" | ||
| 81 | "${VIDEO_CORE}/shader/decode.cpp" | 83 | "${VIDEO_CORE}/shader/decode.cpp" |
| 82 | "${VIDEO_CORE}/shader/expr.cpp" | 84 | "${VIDEO_CORE}/shader/expr.cpp" |
| 83 | "${VIDEO_CORE}/shader/expr.h" | 85 | "${VIDEO_CORE}/shader/expr.h" |
diff --git a/src/common/hash.h b/src/common/hash.h index 40194d1ee..c939709bc 100644 --- a/src/common/hash.h +++ b/src/common/hash.h | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | #include <cstring> | 8 | #include <cstring> |
| 9 | #include <utility> | ||
| 10 | #include <boost/functional/hash.hpp> | ||
| 9 | #include "common/cityhash.h" | 11 | #include "common/cityhash.h" |
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | 13 | ||
| @@ -68,4 +70,13 @@ struct HashableStruct { | |||
| 68 | } | 70 | } |
| 69 | }; | 71 | }; |
| 70 | 72 | ||
| 73 | struct PairHash { | ||
| 74 | template <class T1, class T2> | ||
| 75 | std::size_t operator()(const std::pair<T1, T2>& pair) const { | ||
| 76 | std::size_t seed = std::hash<T1>()(pair.first); | ||
| 77 | boost::hash_combine(seed, std::hash<T2>()(pair.second)); | ||
| 78 | return seed; | ||
| 79 | } | ||
| 80 | }; | ||
| 81 | |||
| 71 | } // namespace Common | 82 | } // namespace Common |
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index eaa694ff8..cb6eda1b8 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -6,6 +6,7 @@ add_library(video_core STATIC | |||
| 6 | dma_pusher.h | 6 | dma_pusher.h |
| 7 | debug_utils/debug_utils.cpp | 7 | debug_utils/debug_utils.cpp |
| 8 | debug_utils/debug_utils.h | 8 | debug_utils/debug_utils.h |
| 9 | engines/const_buffer_engine_interface.h | ||
| 9 | engines/const_buffer_info.h | 10 | engines/const_buffer_info.h |
| 10 | engines/engine_upload.cpp | 11 | engines/engine_upload.cpp |
| 11 | engines/engine_upload.h | 12 | engines/engine_upload.h |
| @@ -107,10 +108,12 @@ add_library(video_core STATIC | |||
| 107 | shader/decode/other.cpp | 108 | shader/decode/other.cpp |
| 108 | shader/ast.cpp | 109 | shader/ast.cpp |
| 109 | shader/ast.h | 110 | shader/ast.h |
| 110 | shader/control_flow.cpp | ||
| 111 | shader/control_flow.h | ||
| 112 | shader/compiler_settings.cpp | 111 | shader/compiler_settings.cpp |
| 113 | shader/compiler_settings.h | 112 | shader/compiler_settings.h |
| 113 | shader/const_buffer_locker.cpp | ||
| 114 | shader/const_buffer_locker.h | ||
| 115 | shader/control_flow.cpp | ||
| 116 | shader/control_flow.h | ||
| 114 | shader/decode.cpp | 117 | shader/decode.cpp |
| 115 | shader/expr.cpp | 118 | shader/expr.cpp |
| 116 | shader/expr.h | 119 | shader/expr.h |
diff --git a/src/video_core/engines/const_buffer_engine_interface.h b/src/video_core/engines/const_buffer_engine_interface.h new file mode 100644 index 000000000..cc41a9cac --- /dev/null +++ b/src/video_core/engines/const_buffer_engine_interface.h | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | namespace Tegra::Engines { | ||
| 10 | |||
| 11 | enum class ShaderType : u32 { | ||
| 12 | Vertex = 0, | ||
| 13 | TesselationControl = 1, | ||
| 14 | TesselationEval = 2, | ||
| 15 | Geometry = 3, | ||
| 16 | Fragment = 4, | ||
| 17 | Compute = 5, | ||
| 18 | }; | ||
| 19 | |||
| 20 | class ConstBufferEngineInterface { | ||
| 21 | public: | ||
| 22 | virtual ~ConstBufferEngineInterface() {} | ||
| 23 | virtual u32 AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const = 0; | ||
| 24 | }; | ||
| 25 | |||
| 26 | } | ||
diff --git a/src/video_core/engines/kepler_compute.cpp b/src/video_core/engines/kepler_compute.cpp index 63d449135..ba97c2894 100644 --- a/src/video_core/engines/kepler_compute.cpp +++ b/src/video_core/engines/kepler_compute.cpp | |||
| @@ -70,7 +70,8 @@ Texture::FullTextureInfo KeplerCompute::GetTextureInfo(const Texture::TextureHan | |||
| 70 | GetTSCEntry(tex_handle.tsc_id)}; | 70 | GetTSCEntry(tex_handle.tsc_id)}; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | u32 KeplerCompute::AccessConstBuffer32(u64 const_buffer, u64 offset) const { | 73 | u32 KeplerCompute::AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const { |
| 74 | ASSERT(stage == ShaderType::Compute); | ||
| 74 | const auto& buffer = launch_description.const_buffer_config[const_buffer]; | 75 | const auto& buffer = launch_description.const_buffer_config[const_buffer]; |
| 75 | u32 result; | 76 | u32 result; |
| 76 | std::memcpy(&result, memory_manager.GetPointer(buffer.Address() + offset), sizeof(u32)); | 77 | std::memcpy(&result, memory_manager.GetPointer(buffer.Address() + offset), sizeof(u32)); |
diff --git a/src/video_core/engines/kepler_compute.h b/src/video_core/engines/kepler_compute.h index 90cf650d2..d7e0dfcd6 100644 --- a/src/video_core/engines/kepler_compute.h +++ b/src/video_core/engines/kepler_compute.h | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "common/common_funcs.h" | 11 | #include "common/common_funcs.h" |
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "video_core/engines/engine_upload.h" | 13 | #include "video_core/engines/engine_upload.h" |
| 14 | #include "video_core/engines/const_buffer_engine_interface.h" | ||
| 14 | #include "video_core/gpu.h" | 15 | #include "video_core/gpu.h" |
| 15 | #include "video_core/textures/texture.h" | 16 | #include "video_core/textures/texture.h" |
| 16 | 17 | ||
| @@ -37,7 +38,7 @@ namespace Tegra::Engines { | |||
| 37 | #define KEPLER_COMPUTE_REG_INDEX(field_name) \ | 38 | #define KEPLER_COMPUTE_REG_INDEX(field_name) \ |
| 38 | (offsetof(Tegra::Engines::KeplerCompute::Regs, field_name) / sizeof(u32)) | 39 | (offsetof(Tegra::Engines::KeplerCompute::Regs, field_name) / sizeof(u32)) |
| 39 | 40 | ||
| 40 | class KeplerCompute final { | 41 | class KeplerCompute final : public ConstBufferEngineInterface { |
| 41 | public: | 42 | public: |
| 42 | explicit KeplerCompute(Core::System& system, VideoCore::RasterizerInterface& rasterizer, | 43 | explicit KeplerCompute(Core::System& system, VideoCore::RasterizerInterface& rasterizer, |
| 43 | MemoryManager& memory_manager); | 44 | MemoryManager& memory_manager); |
| @@ -201,7 +202,7 @@ public: | |||
| 201 | Texture::FullTextureInfo GetTextureInfo(const Texture::TextureHandle tex_handle, | 202 | Texture::FullTextureInfo GetTextureInfo(const Texture::TextureHandle tex_handle, |
| 202 | std::size_t offset) const; | 203 | std::size_t offset) const; |
| 203 | 204 | ||
| 204 | u32 AccessConstBuffer32(u64 const_buffer, u64 offset) const; | 205 | u32 AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const override; |
| 205 | 206 | ||
| 206 | private: | 207 | private: |
| 207 | Core::System& system; | 208 | Core::System& system; |
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 59976943a..92e38b071 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -847,7 +847,8 @@ void Maxwell3D::ProcessClearBuffers() { | |||
| 847 | rasterizer.Clear(); | 847 | rasterizer.Clear(); |
| 848 | } | 848 | } |
| 849 | 849 | ||
| 850 | u32 Maxwell3D::AccessConstBuffer32(Regs::ShaderStage stage, u64 const_buffer, u64 offset) const { | 850 | u32 Maxwell3D::AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const { |
| 851 | ASSERT(stage != ShaderType::Compute); | ||
| 851 | const auto& shader_stage = state.shader_stages[static_cast<std::size_t>(stage)]; | 852 | const auto& shader_stage = state.shader_stages[static_cast<std::size_t>(stage)]; |
| 852 | const auto& buffer = shader_stage.const_buffers[const_buffer]; | 853 | const auto& buffer = shader_stage.const_buffers[const_buffer]; |
| 853 | u32 result; | 854 | u32 result; |
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index e3f1047d5..04d02d208 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "common/common_types.h" | 16 | #include "common/common_types.h" |
| 17 | #include "common/math_util.h" | 17 | #include "common/math_util.h" |
| 18 | #include "video_core/engines/const_buffer_info.h" | 18 | #include "video_core/engines/const_buffer_info.h" |
| 19 | #include "video_core/engines/const_buffer_engine_interface.h" | ||
| 19 | #include "video_core/engines/engine_upload.h" | 20 | #include "video_core/engines/engine_upload.h" |
| 20 | #include "video_core/gpu.h" | 21 | #include "video_core/gpu.h" |
| 21 | #include "video_core/macro_interpreter.h" | 22 | #include "video_core/macro_interpreter.h" |
| @@ -44,7 +45,7 @@ namespace Tegra::Engines { | |||
| 44 | #define MAXWELL3D_REG_INDEX(field_name) \ | 45 | #define MAXWELL3D_REG_INDEX(field_name) \ |
| 45 | (offsetof(Tegra::Engines::Maxwell3D::Regs, field_name) / sizeof(u32)) | 46 | (offsetof(Tegra::Engines::Maxwell3D::Regs, field_name) / sizeof(u32)) |
| 46 | 47 | ||
| 47 | class Maxwell3D final { | 48 | class Maxwell3D final : public ConstBufferEngineInterface { |
| 48 | public: | 49 | public: |
| 49 | explicit Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer, | 50 | explicit Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer, |
| 50 | MemoryManager& memory_manager); | 51 | MemoryManager& memory_manager); |
| @@ -1257,7 +1258,7 @@ public: | |||
| 1257 | /// Returns the texture information for a specific texture in a specific shader stage. | 1258 | /// Returns the texture information for a specific texture in a specific shader stage. |
| 1258 | Texture::FullTextureInfo GetStageTexture(Regs::ShaderStage stage, std::size_t offset) const; | 1259 | Texture::FullTextureInfo GetStageTexture(Regs::ShaderStage stage, std::size_t offset) const; |
| 1259 | 1260 | ||
| 1260 | u32 AccessConstBuffer32(Regs::ShaderStage stage, u64 const_buffer, u64 offset) const; | 1261 | u32 AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const override; |
| 1261 | 1262 | ||
| 1262 | /// Memory for macro code - it's undetermined how big this is, however 1MB is much larger than | 1263 | /// Memory for macro code - it's undetermined how big this is, however 1MB is much larger than |
| 1263 | /// we've seen used. | 1264 | /// we've seen used. |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index cbcf81414..10114909b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -975,7 +975,8 @@ TextureBufferUsage RasterizerOpenGL::SetupDrawTextures(Maxwell::ShaderStage stag | |||
| 975 | } | 975 | } |
| 976 | const auto cbuf = entry.GetBindlessCBuf(); | 976 | const auto cbuf = entry.GetBindlessCBuf(); |
| 977 | Tegra::Texture::TextureHandle tex_handle; | 977 | Tegra::Texture::TextureHandle tex_handle; |
| 978 | tex_handle.raw = maxwell3d.AccessConstBuffer32(stage, cbuf.first, cbuf.second); | 978 | Tegra::Engines::ShaderType shader_type = static_cast<Tegra::Engines::ShaderType>(stage); |
| 979 | tex_handle.raw = maxwell3d.AccessConstBuffer32(shader_type, cbuf.first, cbuf.second); | ||
| 979 | return maxwell3d.GetTextureInfo(tex_handle, entry.GetOffset()); | 980 | return maxwell3d.GetTextureInfo(tex_handle, entry.GetOffset()); |
| 980 | }(); | 981 | }(); |
| 981 | 982 | ||
| @@ -1005,7 +1006,7 @@ TextureBufferUsage RasterizerOpenGL::SetupComputeTextures(const Shader& kernel) | |||
| 1005 | } | 1006 | } |
| 1006 | const auto cbuf = entry.GetBindlessCBuf(); | 1007 | const auto cbuf = entry.GetBindlessCBuf(); |
| 1007 | Tegra::Texture::TextureHandle tex_handle; | 1008 | Tegra::Texture::TextureHandle tex_handle; |
| 1008 | tex_handle.raw = compute.AccessConstBuffer32(cbuf.first, cbuf.second); | 1009 | tex_handle.raw = compute.AccessConstBuffer32(Tegra::Engines::ShaderType::Compute, cbuf.first, cbuf.second); |
| 1009 | return compute.GetTextureInfo(tex_handle, entry.GetOffset()); | 1010 | return compute.GetTextureInfo(tex_handle, entry.GetOffset()); |
| 1010 | }(); | 1011 | }(); |
| 1011 | 1012 | ||
| @@ -1050,7 +1051,7 @@ void RasterizerOpenGL::SetupComputeImages(const Shader& shader) { | |||
| 1050 | } | 1051 | } |
| 1051 | const auto cbuf = entry.GetBindlessCBuf(); | 1052 | const auto cbuf = entry.GetBindlessCBuf(); |
| 1052 | Tegra::Texture::TextureHandle tex_handle; | 1053 | Tegra::Texture::TextureHandle tex_handle; |
| 1053 | tex_handle.raw = compute.AccessConstBuffer32(cbuf.first, cbuf.second); | 1054 | tex_handle.raw = compute.AccessConstBuffer32(Tegra::Engines::ShaderType::Compute, cbuf.first, cbuf.second); |
| 1054 | return compute.GetTextureInfo(tex_handle, entry.GetOffset()).tic; | 1055 | return compute.GetTextureInfo(tex_handle, entry.GetOffset()).tic; |
| 1055 | }(); | 1056 | }(); |
| 1056 | SetupImage(bindpoint, tic, entry); | 1057 | SetupImage(bindpoint, tic, entry); |
diff --git a/src/video_core/shader/const_buffer_locker.cpp b/src/video_core/shader/const_buffer_locker.cpp new file mode 100644 index 000000000..6a9e0ed5e --- /dev/null +++ b/src/video_core/shader/const_buffer_locker.cpp | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "video_core/engines/maxwell_3d.h" | ||
| 10 | #include "video_core/shader/const_buffer_locker.h" | ||
| 11 | |||
| 12 | namespace VideoCommon::Shader { | ||
| 13 | |||
| 14 | ConstBufferLocker::ConstBufferLocker(Tegra::Engines::ShaderType shader_stage) | ||
| 15 | : engine{nullptr}, shader_stage{shader_stage} {} | ||
| 16 | |||
| 17 | ConstBufferLocker::ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, | ||
| 18 | Tegra::Engines::ConstBufferEngineInterface* engine) | ||
| 19 | : engine{engine}, shader_stage{shader_stage} {} | ||
| 20 | |||
| 21 | bool ConstBufferLocker::IsEngineSet() const { | ||
| 22 | return engine != nullptr; | ||
| 23 | } | ||
| 24 | |||
| 25 | void ConstBufferLocker::SetEngine(Tegra::Engines::ConstBufferEngineInterface* engine_) { | ||
| 26 | engine = engine_; | ||
| 27 | } | ||
| 28 | |||
| 29 | std::optional<u32> ConstBufferLocker::ObtainKey(u32 buffer, u32 offset) { | ||
| 30 | const std::pair<u32, u32> key = {buffer, offset}; | ||
| 31 | const auto iter = keys.find(key); | ||
| 32 | if (iter != keys.end()) { | ||
| 33 | return {iter->second}; | ||
| 34 | } | ||
| 35 | if (!IsEngineSet()) { | ||
| 36 | return {}; | ||
| 37 | } | ||
| 38 | const u32 value = engine->AccessConstBuffer32(shader_stage, buffer, offset); | ||
| 39 | keys.emplace(key, value); | ||
| 40 | return {value}; | ||
| 41 | } | ||
| 42 | |||
| 43 | void ConstBufferLocker::InsertKey(u32 buffer, u32 offset, u32 value) { | ||
| 44 | const std::pair<u32, u32> key = {buffer, offset}; | ||
| 45 | keys[key] = value; | ||
| 46 | } | ||
| 47 | |||
| 48 | u32 ConstBufferLocker::NumKeys() const { | ||
| 49 | return keys.size(); | ||
| 50 | } | ||
| 51 | |||
| 52 | const std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>& | ||
| 53 | ConstBufferLocker::AccessKeys() const { | ||
| 54 | return keys; | ||
| 55 | } | ||
| 56 | |||
| 57 | bool ConstBufferLocker::AreKeysConsistant() const { | ||
| 58 | if (!IsEngineSet()) { | ||
| 59 | return false; | ||
| 60 | } | ||
| 61 | for (const auto& key_val : keys) { | ||
| 62 | const std::pair<u32, u32> key = key_val.first; | ||
| 63 | const u32 value = key_val.second; | ||
| 64 | const u32 other_value = engine->AccessConstBuffer32(shader_stage, key.first, key.second); | ||
| 65 | if (other_value != value) { | ||
| 66 | return false; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | return true; | ||
| 70 | } | ||
| 71 | |||
| 72 | } // namespace VideoCommon::Shader | ||
diff --git a/src/video_core/shader/const_buffer_locker.h b/src/video_core/shader/const_buffer_locker.h new file mode 100644 index 000000000..39e62584d --- /dev/null +++ b/src/video_core/shader/const_buffer_locker.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <unordered_map> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "common/hash.h" | ||
| 10 | #include "video_core/engines/const_buffer_engine_interface.h" | ||
| 11 | |||
| 12 | namespace VideoCommon::Shader { | ||
| 13 | |||
| 14 | class ConstBufferLocker { | ||
| 15 | public: | ||
| 16 | explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage); | ||
| 17 | |||
| 18 | explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, | ||
| 19 | Tegra::Engines::ConstBufferEngineInterface* engine); | ||
| 20 | |||
| 21 | // Checks if an engine is setup, it may be possible that during disk shader | ||
| 22 | // cache run, the engines have not been created yet. | ||
| 23 | bool IsEngineSet() const; | ||
| 24 | |||
| 25 | // Use this to set/change the engine used for this shader. | ||
| 26 | void SetEngine(Tegra::Engines::ConstBufferEngineInterface* engine); | ||
| 27 | |||
| 28 | // Retrieves a key from the locker, if it's registered, it will give the | ||
| 29 | // registered value, if not it will obtain it from maxwell3d and register it. | ||
| 30 | std::optional<u32> ObtainKey(u32 buffer, u32 offset); | ||
| 31 | |||
| 32 | // Manually inserts a key. | ||
| 33 | void InsertKey(u32 buffer, u32 offset, u32 value); | ||
| 34 | |||
| 35 | // Retrieves the number of keys registered. | ||
| 36 | u32 NumKeys() const; | ||
| 37 | |||
| 38 | // Gives an accessor to the key's database. | ||
| 39 | const std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>& AccessKeys() const; | ||
| 40 | |||
| 41 | // Checks keys against maxwell3d's current const buffers. Returns true if they | ||
| 42 | // are the same value, false otherwise; | ||
| 43 | bool AreKeysConsistant() const; | ||
| 44 | |||
| 45 | private: | ||
| 46 | Tegra::Engines::ConstBufferEngineInterface* engine; | ||
| 47 | Tegra::Engines::ShaderType shader_stage; | ||
| 48 | std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash> keys{}; | ||
| 49 | }; | ||
| 50 | } // namespace VideoCommon::Shader | ||
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 91cd0a534..68818643c 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "video_core/engines/shader_header.h" | 17 | #include "video_core/engines/shader_header.h" |
| 18 | #include "video_core/shader/ast.h" | 18 | #include "video_core/shader/ast.h" |
| 19 | #include "video_core/shader/compiler_settings.h" | 19 | #include "video_core/shader/compiler_settings.h" |
| 20 | #include "video_core/shader/const_buffer_locker.h" | ||
| 20 | #include "video_core/shader/node.h" | 21 | #include "video_core/shader/node.h" |
| 21 | 22 | ||
| 22 | namespace VideoCommon::Shader { | 23 | namespace VideoCommon::Shader { |