mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-07 14:26:36 +00:00
Compare commits
2 Commits
f9560a2594
...
f4e48b5d8c
| Author | SHA1 | Date | |
|---|---|---|---|
| f4e48b5d8c | |||
| 3d891a8743 |
@@ -207,12 +207,22 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am
|
||||
std::optional<WindowBufferRef> src_window;
|
||||
std::optional<WindowBufferRef> dst_window;
|
||||
if constexpr (USE_UNIFIED_DIRECT_BINDING) {
|
||||
src_window = TryObtainWindowBuffer(*cpu_src_address, static_cast<u32>(amount),
|
||||
UNIFIED_COPY_BINDING_ALIGNMENT,
|
||||
ObtainBufferOperation::DoNothing);
|
||||
dst_window = TryObtainWindowBuffer(*cpu_dest_address, static_cast<u32>(amount),
|
||||
UNIFIED_COPY_BINDING_ALIGNMENT,
|
||||
ObtainBufferOperation::DoNothing);
|
||||
if (amount <= (std::numeric_limits<u32>::max)()) {
|
||||
src_window = TryObtainWindowBuffer(*cpu_src_address, static_cast<u32>(amount),
|
||||
UNIFIED_COPY_BINDING_ALIGNMENT,
|
||||
ObtainBufferOperation::DoNothing);
|
||||
dst_window = TryObtainWindowBuffer(*cpu_dest_address, static_cast<u32>(amount),
|
||||
UNIFIED_COPY_BINDING_ALIGNMENT,
|
||||
ObtainBufferOperation::DoNothing);
|
||||
if (src_window && dst_window &&
|
||||
src_window->window_index == dst_window->window_index) {
|
||||
const u64 src_begin = src_window->offset;
|
||||
const u64 dst_begin = dst_window->offset;
|
||||
if (src_begin < dst_begin + amount && dst_begin < src_begin + amount) {
|
||||
dst_window.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ClearDownload(*cpu_dest_address, amount);
|
||||
@@ -359,6 +369,17 @@ auto BufferCache<P>::TryObtainWindowBufferGpu(GPUVAddr gpu_addr, u32 size, u64 a
|
||||
return TryObtainWindowBuffer(*device_addr, size, alignment, post_op);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
void BufferCache<P>::MarkGpuWrittenRange(DAddr device_addr, u32 size) {
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
memory_tracker.MarkRegionAsGpuModified(device_addr, size);
|
||||
gpu_modified_ranges.Add(device_addr, size);
|
||||
uncommitted_gpu_modified_ranges.Add(device_addr, size);
|
||||
in_place_gpu_written_ranges.Subtract(device_addr, size);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
std::pair<typename P::Buffer*, u32> BufferCache<P>::ObtainBuffer(GPUVAddr gpu_addr, u32 size,
|
||||
ObtainBufferSynchronize sync_info,
|
||||
@@ -1856,14 +1877,6 @@ void BufferCache<P>::ForgetGpuModifiedRange(DAddr device_addr, u64 size) {
|
||||
in_place_gpu_written_ranges.Subtract(device_addr, size);
|
||||
}
|
||||
|
||||
template <class P>
|
||||
bool BufferCache<P>::IsRegionWrittenInPlace(DAddr device_addr, u64 size) {
|
||||
u64 covered = 0;
|
||||
in_place_gpu_written_ranges.ForEachInRange(
|
||||
device_addr, size, [&](DAddr start, DAddr end) { covered += end - start; });
|
||||
return covered == size;
|
||||
}
|
||||
|
||||
template <class P>
|
||||
bool BufferCache<P>::IntersectsInPlaceWrites(DAddr device_addr, u64 size) {
|
||||
bool intersects = false;
|
||||
@@ -2200,8 +2213,7 @@ bool BufferCache<P>::ResolveUnifiedDirectBinding([[maybe_unused]] DAddr device_a
|
||||
}
|
||||
contiguous += Core::DEVICE_PAGESIZE;
|
||||
}
|
||||
if (IsRegionGpuModified(device_addr, size) &&
|
||||
!IsRegionWrittenInPlace(device_addr, size)) {
|
||||
if (IsRegionGpuModified(device_addr, size)) {
|
||||
return false;
|
||||
}
|
||||
window_index = relative / window_size;
|
||||
@@ -2311,6 +2323,9 @@ bool BufferCache<P>::TryUnifiedUploadMemory([[maybe_unused]] Buffer& buffer,
|
||||
if (Settings::values.enable_gpu_buffer_readback.GetValue()) {
|
||||
return false;
|
||||
}
|
||||
if (!runtime.SupportsUnifiedUploads()) {
|
||||
return false;
|
||||
}
|
||||
boost::container::small_vector<u64, 4> window_ids;
|
||||
UnifiedWindowGroups groups;
|
||||
for (const BufferCopy& copy : copies) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <numeric>
|
||||
@@ -286,6 +287,8 @@ public:
|
||||
[[nodiscard]] std::optional<WindowBufferRef> TryObtainWindowBufferGpu(
|
||||
GPUVAddr gpu_addr, u32 size, u64 alignment, ObtainBufferOperation post_op);
|
||||
|
||||
void MarkGpuWrittenRange(DAddr device_addr, u32 size);
|
||||
|
||||
[[nodiscard]] std::pair<Buffer*, u32> ObtainBuffer(GPUVAddr gpu_addr, u32 size,
|
||||
ObtainBufferSynchronize sync_info,
|
||||
ObtainBufferOperation post_op);
|
||||
@@ -447,8 +450,6 @@ private:
|
||||
|
||||
void ForgetGpuModifiedRange(DAddr device_addr, u64 size);
|
||||
|
||||
[[nodiscard]] bool IsRegionWrittenInPlace(DAddr device_addr, u64 size);
|
||||
|
||||
[[nodiscard]] bool IntersectsInPlaceWrites(DAddr device_addr, u64 size);
|
||||
|
||||
void WaitForInPlaceWrites();
|
||||
|
||||
@@ -124,6 +124,10 @@ public:
|
||||
return unified_memory != nullptr && unified_memory->SupportsDirectDescriptors();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool SupportsUnifiedUploads() const noexcept {
|
||||
return unified_memory != nullptr && unified_memory->IsHardwareBufferBacked();
|
||||
}
|
||||
|
||||
[[nodiscard]] VkBuffer UnifiedWindowBuffer(size_t window_index) const noexcept {
|
||||
if (!unified_memory || window_index >= unified_memory->GetWindowCount()) {
|
||||
return VK_NULL_HANDLE;
|
||||
|
||||
@@ -1663,6 +1663,10 @@ void QueryCacheRuntime::SyncValues(std::span<SyncValuesType> values, VkBuffer ba
|
||||
pair.first, static_cast<u32>(pair.second - pair.first), sync_info, post_op);
|
||||
impl->buffers_to_upload_to.emplace_back(buffer->Handle(), offset);
|
||||
}
|
||||
for (const auto& sync_val : values) {
|
||||
impl->buffer_cache.MarkGpuWrittenRange(sync_val.address,
|
||||
static_cast<u32>(sync_val.size));
|
||||
}
|
||||
});
|
||||
|
||||
VkBuffer src_buffer;
|
||||
|
||||
@@ -564,6 +564,7 @@ namespace Vulkan {
|
||||
return false;
|
||||
}
|
||||
foreign_ownership = true;
|
||||
hardware_buffer_backed = true;
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
||||
@@ -134,6 +134,10 @@ namespace Vulkan {
|
||||
return direct_addresses;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsHardwareBufferBacked() const noexcept {
|
||||
return hardware_buffer_backed;
|
||||
}
|
||||
|
||||
[[nodiscard]] VkDeviceAddress GetWindowAddress(size_t index) const noexcept {
|
||||
return windows[index].address;
|
||||
}
|
||||
@@ -171,6 +175,7 @@ namespace Vulkan {
|
||||
bool foreign_ownership{};
|
||||
bool direct_descriptors{};
|
||||
bool direct_addresses{};
|
||||
bool hardware_buffer_backed{};
|
||||
};
|
||||
|
||||
/// Memory allocator container.
|
||||
|
||||
Reference in New Issue
Block a user