mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-14 10:46:58 +02:00
[vk] properly handle multithreading with global constants without using TLS (#3368)
TL;DR basically multiple threads writing to the same memory, now they dont, everyone happy Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3368 Reviewed-by: DraVee <dravee@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
6afe209b60
commit
ea932fbf40
2 changed files with 102 additions and 94 deletions
|
|
@ -1,17 +1,72 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "shader_recompiler/program_header.h"
|
||||
#include "shader_recompiler/shader_info.h"
|
||||
#include "shader_recompiler/stage.h"
|
||||
#include "shader_recompiler/frontend/ir/value.h"
|
||||
|
||||
namespace Shader::IR {
|
||||
class Inst;
|
||||
}
|
||||
|
||||
namespace Shader {
|
||||
|
||||
struct CbufWordKey {
|
||||
u32 index;
|
||||
u32 offset;
|
||||
constexpr bool operator==(const CbufWordKey& o) const noexcept {
|
||||
return index == o.index && offset == o.offset;
|
||||
}
|
||||
};
|
||||
|
||||
struct CbufWordKeyHash {
|
||||
constexpr size_t operator()(const CbufWordKey& k) const noexcept {
|
||||
return (size_t(k.index) << 32) ^ k.offset;
|
||||
}
|
||||
};
|
||||
|
||||
struct HandleKey {
|
||||
u32 index, offset, shift_left;
|
||||
u32 sec_index, sec_offset, sec_shift_left;
|
||||
bool has_secondary;
|
||||
constexpr bool operator==(const HandleKey& o) const noexcept {
|
||||
return std::tie(index, offset, shift_left, sec_index, sec_offset, sec_shift_left, has_secondary)
|
||||
== std::tie(o.index, o.offset, o.shift_left, o.sec_index, o.sec_offset, o.sec_shift_left, o.has_secondary);
|
||||
}
|
||||
};
|
||||
struct HandleKeyHash {
|
||||
constexpr size_t operator()(const HandleKey& k) const noexcept {
|
||||
size_t h = (size_t(k.index) << 32) ^ k.offset;
|
||||
h ^= (size_t(k.shift_left) << 1);
|
||||
h ^= (size_t(k.sec_index) << 33) ^ (size_t(k.sec_offset) << 2);
|
||||
h ^= (size_t(k.sec_shift_left) << 3);
|
||||
h ^= k.has_secondary ? 0x9e3779b97f4a7c15ULL : 0ULL;
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
struct ConstBufferAddr {
|
||||
u32 index;
|
||||
u32 offset;
|
||||
u32 shift_left;
|
||||
u32 secondary_index;
|
||||
u32 secondary_offset;
|
||||
u32 secondary_shift_left;
|
||||
IR::U32 dynamic_offset;
|
||||
u32 count;
|
||||
bool has_secondary;
|
||||
};
|
||||
|
||||
class Environment {
|
||||
public:
|
||||
virtual ~Environment() = default;
|
||||
|
|
@ -69,6 +124,10 @@ protected:
|
|||
Stage stage{};
|
||||
u32 start_address{};
|
||||
bool is_proprietary_driver{};
|
||||
public:
|
||||
std::unordered_map<CbufWordKey, u32, CbufWordKeyHash> cbuf_word_cache;
|
||||
std::unordered_map<HandleKey, u32, HandleKeyHash> handle_cache;
|
||||
std::unordered_map<const IR::Inst*, ConstBufferAddr> track_cache;
|
||||
};
|
||||
|
||||
} // namespace Shader
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue