const_buffer_locker.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <unordered_map>
  6. #include "common/common_types.h"
  7. #include "common/hash.h"
  8. #include "video_core/engines/const_buffer_engine_interface.h"
  9. namespace VideoCommon::Shader {
  10. class ConstBufferLocker {
  11. public:
  12. explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage);
  13. explicit ConstBufferLocker(Tegra::Engines::ShaderType shader_stage,
  14. Tegra::Engines::ConstBufferEngineInterface* engine);
  15. // Checks if an engine is setup, it may be possible that during disk shader
  16. // cache run, the engines have not been created yet.
  17. bool IsEngineSet() const;
  18. // Use this to set/change the engine used for this shader.
  19. void SetEngine(Tegra::Engines::ConstBufferEngineInterface* engine);
  20. // Retrieves a key from the locker, if it's registered, it will give the
  21. // registered value, if not it will obtain it from maxwell3d and register it.
  22. std::optional<u32> ObtainKey(u32 buffer, u32 offset);
  23. // Manually inserts a key.
  24. void InsertKey(u32 buffer, u32 offset, u32 value);
  25. // Retrieves the number of keys registered.
  26. u32 NumKeys() const;
  27. // Gives an accessor to the key's database.
  28. const std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>& AccessKeys() const;
  29. // Checks keys against maxwell3d's current const buffers. Returns true if they
  30. // are the same value, false otherwise;
  31. bool AreKeysConsistant() const;
  32. private:
  33. Tegra::Engines::ConstBufferEngineInterface* engine;
  34. Tegra::Engines::ShaderType shader_stage;
  35. std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash> keys{};
  36. };
  37. } // namespace VideoCommon::Shader