diff --git a/lib/ivis_opengl/gfx_api_gl.cpp b/lib/ivis_opengl/gfx_api_gl.cpp index e52a309ce3e..dbcd235238b 100644 --- a/lib/ivis_opengl/gfx_api_gl.cpp +++ b/lib/ivis_opengl/gfx_api_gl.cpp @@ -2976,7 +2976,7 @@ optional gl_context::getSuggestedDefaultDepthBufferResolution() const GLint total_graphics_mem_kb = 0; glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &total_graphics_mem_kb); - if ((total_graphics_mem_kb / 1024) > 4096) // If > 4GB graphics memory + if ((total_graphics_mem_kb / 1024) >= 4096) // If >= 4GB graphics memory { return 4096; } @@ -2996,7 +2996,7 @@ optional gl_context::getSuggestedDefaultDepthBufferResolution() const } uint32_t currentFreeTextureMemory_mb = static_cast(stats_kb[0] / 1024); - if (currentFreeTextureMemory_mb > 4096) // If > 4 GB free texture memory + if (currentFreeTextureMemory_mb >= 4096) // If >= 4 GB free texture memory { return 4096; } diff --git a/lib/ivis_opengl/gfx_api_vk.cpp b/lib/ivis_opengl/gfx_api_vk.cpp index 5f6d29902ef..ca85062bce6 100644 --- a/lib/ivis_opengl/gfx_api_vk.cpp +++ b/lib/ivis_opengl/gfx_api_vk.cpp @@ -4258,6 +4258,47 @@ bool VkRoot::createSwapchain() return true; } +static uint32_t getVKSuggestedDefaultDepthBufferResolution(const vk::PhysicalDeviceMemoryProperties& memprops) +{ + optional largestDeviceLocalMemoryHeap; + for (uint32_t i = 0; i < memprops.memoryTypeCount; ++i) + { + if ((memprops.memoryTypes[i].propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal) == vk::MemoryPropertyFlagBits::eDeviceLocal) + { + auto currHeapIndex = memprops.memoryTypes[i].heapIndex; + if (currHeapIndex >= memprops.memoryHeapCount) + { + continue; + } + if (largestDeviceLocalMemoryHeap.has_value()) + { + if (currHeapIndex != largestDeviceLocalMemoryHeap.value() + && (memprops.memoryHeaps[currHeapIndex].size > memprops.memoryHeaps[largestDeviceLocalMemoryHeap.value()].size)) + { + largestDeviceLocalMemoryHeap = currHeapIndex; + } + } + else + { + largestDeviceLocalMemoryHeap = currHeapIndex; + } + } + } + + ASSERT_OR_RETURN(2048, largestDeviceLocalMemoryHeap.has_value(), "Couldn't find the largest device local memory heap?"); + + auto largestDeviceLocalMemoryHeapSize = memprops.memoryHeaps[largestDeviceLocalMemoryHeap.value()].size; + + if ((largestDeviceLocalMemoryHeapSize / 1048576) >= 4096) // If >= 4GB device-local memory + { + return 4096; + } + else + { + return 2048; + } +} + bool VkRoot::canUseVulkanInstanceAPI(uint32_t minVulkanAPICoreVersion) const { ASSERT(inst, "Instance is null"); @@ -4575,7 +4616,7 @@ bool VkRoot::_initialize(const gfx_api::backend_Impl_Factory& impl, int32_t anti if (depthMapSize == 0) { - depthMapSize = 2048; // Future TODO: Could try various heuristics to determine whether the default depthMapSize should be 2048 or 4096 (perhaps based on available graphics memory, if it's a dedicated GPU, etc) + depthMapSize = getVKSuggestedDefaultDepthBufferResolution(memprops); } createDepthPasses(depthBufferFormat); // TODO: Handle failures?