[TEST] Mark GPU written range within uploads

This commit is contained in:
CamilleLaVey
2026-08-09 09:17:50 -04:00
parent f9560a2594
commit 3d891a8743
6 changed files with 31 additions and 0 deletions
@@ -359,6 +359,18 @@ 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;
}
const BufferId buffer_id = FindBuffer(device_addr, size);
if (buffer_id == NULL_BUFFER_ID) {
return;
}
MarkWrittenBuffer(buffer_id, device_addr, size);
}
template <class P>
std::pair<typename P::Buffer*, u32> BufferCache<P>::ObtainBuffer(GPUVAddr gpu_addr, u32 size,
ObtainBufferSynchronize sync_info,
@@ -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) {
@@ -286,6 +286,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);
@@ -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.