cache directwrite
This commit is contained in:
parent
69641f1c44
commit
ab222ffa1f
3 changed files with 32 additions and 5 deletions
|
|
@ -780,6 +780,7 @@ void Device::Initialize() {
|
|||
CheckVkResult(vkCreateCommandPool(device, &commandPoolcreateInfo, NULL, &commandPool));
|
||||
|
||||
vkGetPhysicalDeviceMemoryProperties(physDevice, &memoryProperties);
|
||||
CacheUploadStrategy();
|
||||
|
||||
vkGetAccelerationStructureBuildSizesKHR = reinterpret_cast<PFN_vkGetAccelerationStructureBuildSizesKHR>(vkGetInstanceProcAddr(instance, "vkGetAccelerationStructureBuildSizesKHR"));
|
||||
vkCreateAccelerationStructureKHR = reinterpret_cast<PFN_vkCreateAccelerationStructureKHR>(vkGetInstanceProcAddr(instance, "vkCreateAccelerationStructureKHR"));
|
||||
|
|
@ -842,7 +843,7 @@ std::uint32_t Device::GetMemoryType(uint32_t typeBits, VkMemoryPropertyFlags req
|
|||
throw std::runtime_error("Could not find a matching memory type");
|
||||
}
|
||||
|
||||
bool Device::PreferDirectDeviceWrite(VkDeviceSize size) {
|
||||
void Device::CacheUploadStrategy() {
|
||||
constexpr VkMemoryPropertyFlags directFlags =
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
||||
|
||||
|
|
@ -858,7 +859,8 @@ bool Device::PreferDirectDeviceWrite(VkDeviceSize size) {
|
|||
}
|
||||
}
|
||||
if (!haveDirectType) {
|
||||
return false;
|
||||
directWriteBudget = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Compare the host-visible device-local heap against the largest plain
|
||||
|
|
@ -871,10 +873,11 @@ bool Device::PreferDirectDeviceWrite(VkDeviceSize size) {
|
|||
}
|
||||
}
|
||||
|
||||
// 3. ReBAR / UMA: the BAR heap covers (almost) all of VRAM -> direct.
|
||||
// 3. ReBAR / UMA: the BAR heap covers (almost) all of VRAM -> map any size.
|
||||
// barHeap >= 0.9 * vram, written to dodge floating point / overflow.
|
||||
if (barHeap >= vram - vram / 10) {
|
||||
return true;
|
||||
directWriteBudget = std::numeric_limits<VkDeviceSize>::max();
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. Small BAR window: direct only for buffers small enough that several
|
||||
|
|
@ -884,5 +887,11 @@ bool Device::PreferDirectDeviceWrite(VkDeviceSize size) {
|
|||
// both a 256 MiB and a 4 GiB window). VK_EXT_memory_budget would refine
|
||||
// this to the window's *remaining* space; see the header note.
|
||||
constexpr VkDeviceSize barWindowFraction = 8;
|
||||
return size <= barHeap / barWindowFraction;
|
||||
directWriteBudget = barHeap / barWindowFraction;
|
||||
}
|
||||
|
||||
bool Device::PreferDirectDeviceWrite(VkDeviceSize size) {
|
||||
// directWriteBudget caches the size-independent decision (CacheUploadStrategy):
|
||||
// 0 -> never direct, max -> ReBAR/UMA so any size, else the small-window cap.
|
||||
return directWriteBudget != 0 && size <= directWriteBudget;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue