mirror of https://github.com/yuzu-mirror/yuzu
VideoCore: Unify const buffer accessing along engines and provide ConstBufferLocker class to shaders.
parent
2ef696c85a
commit
1a58f45d76
@ -0,0 +1,26 @@
|
||||
// Copyright 2019 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Tegra::Engines {
|
||||
|
||||
enum class ShaderType : u32 {
|
||||
Vertex = 0,
|
||||
TesselationControl = 1,
|
||||
TesselationEval = 2,
|
||||
Geometry = 3,
|
||||
Fragment = 4,
|
||||
Compute = 5,
|
||||
};
|
||||
|
||||
class ConstBufferEngineInterface {
|
||||
public:
|
||||
virtual ~ConstBufferEngineInterface() {}
|
||||
virtual u32 AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const = 0;
|
||||
};
|
||||
|
||||
}
|
@ -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
|
@ -0,0 +1,50 @@
|
||||
// Copyright 2019 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include "common/common_types.h"
|
||||
#include "common/hash.h"
|
||||
#include "video_core/engines/const_buffer_engine_interface.h"
|
||||
|
||||
namespace VideoCommon::Shader {
|
||||
|
||||
class ConstBufferLocker {
|
||||
public:
|
||||
explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage);
|
||||
|
||||
explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage,
|
||||
Tegra::Engines::ConstBufferEngineInterface* engine);
|
||||
|
||||
// Checks if an engine is setup, it may be possible that during disk shader
|
||||
// cache run, the engines have not been created yet.
|
||||
bool IsEngineSet() const;
|
||||
|
||||
// Use this to set/change the engine used for this shader.
|
||||
void SetEngine(Tegra::Engines::ConstBufferEngineInterface* engine);
|
||||
|
||||
// Retrieves a key from the locker, if it's registered, it will give the
|
||||
// registered value, if not it will obtain it from maxwell3d and register it.
|
||||
std::optional<u32> ObtainKey(u32 buffer, u32 offset);
|
||||
|
||||
// Manually inserts a key.
|
||||
void InsertKey(u32 buffer, u32 offset, u32 value);
|
||||
|
||||
// Retrieves the number of keys registered.
|
||||
u32 NumKeys() const;
|
||||
|
||||
// Gives an accessor to the key's database.
|
||||
const std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>& AccessKeys() const;
|
||||
|
||||
// Checks keys against maxwell3d's current const buffers. Returns true if they
|
||||
// are the same value, false otherwise;
|
||||
bool AreKeysConsistant() const;
|
||||
|
||||
private:
|
||||
Tegra::Engines::ConstBufferEngineInterface* engine;
|
||||
Tegra::Engines::ShaderType shader_stage;
|
||||
std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash> keys{};
|
||||
};
|
||||
} // namespace VideoCommon::Shader
|
Loading…
Reference in New Issue