diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2019-09-23 20:02:02 +0200 |
---|---|---|
committer | FernandoS27 <fsahmkow27@gmail.com> | 2019-10-25 15:01:29 +0200 |
commit | 1a58f45d76fe7756dd365e099d1536da769c1eab (patch) | |
tree | 668a61e870c57249edf94ba2e2002d3ace18b118 /src/video_core/shader/const_buffer_locker.cpp | |
parent | Shader_IR: Implement BRX tracking. (diff) | |
download | yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.gz yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.bz2 yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.lz yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.xz yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.tar.zst yuzu-1a58f45d76fe7756dd365e099d1536da769c1eab.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/shader/const_buffer_locker.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
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 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/assert.h" +#include "common/common_types.h" +#include "video_core/engines/maxwell_3d.h" +#include "video_core/shader/const_buffer_locker.h" + +namespace VideoCommon::Shader { + +ConstBufferLocker::ConstBufferLocker(Tegra::Engines::ShaderType shader_stage) + : engine{nullptr}, shader_stage{shader_stage} {} + +ConstBufferLocker::ConstBufferLocker(Tegra::Engines::ShaderType shader_stage, + Tegra::Engines::ConstBufferEngineInterface* engine) + : engine{engine}, shader_stage{shader_stage} {} + +bool ConstBufferLocker::IsEngineSet() const { + return engine != nullptr; +} + +void ConstBufferLocker::SetEngine(Tegra::Engines::ConstBufferEngineInterface* engine_) { + engine = engine_; +} + +std::optional<u32> ConstBufferLocker::ObtainKey(u32 buffer, u32 offset) { + const std::pair<u32, u32> key = {buffer, offset}; + const auto iter = keys.find(key); + if (iter != keys.end()) { + return {iter->second}; + } + if (!IsEngineSet()) { + return {}; + } + const u32 value = engine->AccessConstBuffer32(shader_stage, buffer, offset); + keys.emplace(key, value); + return {value}; +} + +void ConstBufferLocker::InsertKey(u32 buffer, u32 offset, u32 value) { + const std::pair<u32, u32> key = {buffer, offset}; + keys[key] = value; +} + +u32 ConstBufferLocker::NumKeys() const { + return keys.size(); +} + +const std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>& +ConstBufferLocker::AccessKeys() const { + return keys; +} + +bool ConstBufferLocker::AreKeysConsistant() const { + if (!IsEngineSet()) { + return false; + } + for (const auto& key_val : keys) { + const std::pair<u32, u32> key = key_val.first; + const u32 value = key_val.second; + const u32 other_value = engine->AccessConstBuffer32(shader_stage, key.first, key.second); + if (other_value != value) { + return false; + } + } + return true; +} + +} // namespace VideoCommon::Shader |