[common] rework BitField and BitUtil, use concepts whenever possible (#4076)

test no regressions especially on Liiinux

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4076
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
lizzie
2026-07-09 03:47:04 +02:00
committed by crueter
parent c2e74a9380
commit 41762940d6
31 changed files with 529 additions and 757 deletions
@@ -526,7 +526,7 @@ private:
template <bool is_resolve>
size_t ObtainBuffer(size_t num_needed) {
const size_t log_2 = std::max<size_t>(11U, Common::Log2Ceil64(num_needed));
const size_t log_2 = std::max<size_t>(11U, Common::Log2Ceil(num_needed));
if constexpr (is_resolve) {
if (resolve_table[log_2] != 0) {
return resolve_table[log_2] - 1;
@@ -174,7 +174,7 @@ StagingBufferRef StagingBufferPool::GetStagingBuffer(size_t size, MemoryUsage us
std::optional<StagingBufferRef> StagingBufferPool::TryGetReservedBuffer(size_t size,
MemoryUsage usage,
bool deferred) {
StagingBuffers& cache_level = GetCache(usage)[Common::Log2Ceil64(size)];
StagingBuffers& cache_level = GetCache(usage)[Common::Log2Ceil(size)];
const auto is_free = [this](const StagingBuffer& entry) {
return !entry.deferred && scheduler.IsFree(entry.tick);
@@ -195,14 +195,13 @@ std::optional<StagingBufferRef> StagingBufferPool::TryGetReservedBuffer(size_t s
return it->Ref();
}
StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, MemoryUsage usage,
bool deferred) {
const u32 log2 = Common::Log2Ceil64(size);
StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, MemoryUsage usage, bool deferred) {
auto const log2_size = Common::Log2Ceil<u32>(u32(size));
VkBufferCreateInfo buffer_ci = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.size = 1ULL << log2,
.size = 1ULL << log2_size,
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
@@ -219,11 +218,11 @@ StagingBufferRef StagingBufferPool::CreateStagingBuffer(size_t size, MemoryUsage
buffer.SetObjectNameEXT(fmt::format("Staging Buffer {}", buffer_index).c_str());
}
const std::span<u8> mapped_span = buffer.Mapped();
StagingBuffer& entry = GetCache(usage)[log2].entries.emplace_back(StagingBuffer{
StagingBuffer& entry = GetCache(usage)[log2_size].entries.emplace_back(StagingBuffer{
.buffer = std::move(buffer),
.mapped_span = mapped_span,
.usage = usage,
.log2_level = log2,
.log2_level = log2_size,
.index = unique_ids++,
.tick = deferred ? (std::numeric_limits<u64>::max)() : scheduler.CurrentTick(),
.deferred = deferred,
+5 -8
View File
@@ -219,16 +219,13 @@ void SerializePipeline(std::span<const char> key, std::span<const GenericEnviron
const std::filesystem::path& filename, u32 cache_version);
template <typename Key, typename Envs>
void SerializePipeline(const Key& key, const Envs& envs, const std::filesystem::path& filename,
u32 cache_version) {
static_assert(std::is_trivially_copyable_v<Key>);
static_assert(std::has_unique_object_representations_v<Key>);
SerializePipeline(std::span(reinterpret_cast<const char*>(&key), sizeof(key)),
std::span(envs.data(), envs.size()), filename, cache_version);
requires std::is_trivially_copyable_v<Key>
&& std::has_unique_object_representations_v<Key>
void SerializePipeline(const Key& key, const Envs& envs, const std::filesystem::path& filename, u32 cache_version) {
SerializePipeline(std::span(reinterpret_cast<const char*>(&key), sizeof(key)), std::span(envs.data(), envs.size()), filename, cache_version);
}
void LoadPipelines(
std::stop_token stop_loading, const std::filesystem::path& filename, u32 expected_cache_version,
void LoadPipelines(std::stop_token stop_loading, const std::filesystem::path& filename, u32 expected_cache_version,
Common::UniqueFunction<void, std::ifstream&, FileEnvironment> load_compute,
Common::UniqueFunction<void, std::ifstream&, std::vector<FileEnvironment>> load_graphics);
@@ -1357,10 +1357,9 @@ public:
}
template <typename T>
void PushConstants(VkPipelineLayout layout, VkShaderStageFlags flags,
const T& data) const noexcept {
static_assert(std::is_trivially_copyable_v<T>, "<data> is not trivially copyable");
dld->vkCmdPushConstants(handle, layout, flags, 0, static_cast<u32>(sizeof(T)), &data);
requires std::is_trivially_copyable_v<T>
void PushConstants(VkPipelineLayout layout, VkShaderStageFlags flags, const T& data) const noexcept {
dld->vkCmdPushConstants(handle, layout, flags, 0, u32(sizeof(T)), std::addressof(data));
}
void SetViewport(u32 first, Span<VkViewport> viewports) const noexcept {