Skip to content

Commit

Permalink
Improve determining default depth buffer resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 15, 2023
1 parent a6dbf64 commit 62ee485
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/ivis_opengl/gfx_api_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2976,7 +2976,7 @@ optional<uint32_t> 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;
}
Expand All @@ -2996,7 +2996,7 @@ optional<uint32_t> gl_context::getSuggestedDefaultDepthBufferResolution() const
}
uint32_t currentFreeTextureMemory_mb = static_cast<uint32_t>(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;
}
Expand Down
43 changes: 42 additions & 1 deletion lib/ivis_opengl/gfx_api_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4258,6 +4258,47 @@ bool VkRoot::createSwapchain()
return true;
}

static uint32_t getVKSuggestedDefaultDepthBufferResolution(const vk::PhysicalDeviceMemoryProperties& memprops)
{
optional<uint32_t> 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");
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 62ee485

Please sign in to comment.