From 25ea14c9655c4f49afb7207d8e14b88da2ffadc2 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 22 Nov 2017 12:05:59 +0000 Subject: [PATCH] Fix possible division by zero in edge cases * Reported by Coverity Scan --- qrenderdoc/Widgets/Extended/RDHeaderView.cpp | 2 +- qrenderdoc/Windows/StatisticsViewer.cpp | 7 +++++-- renderdoc/driver/d3d12/d3d12_debug.cpp | 6 ++++++ renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/qrenderdoc/Widgets/Extended/RDHeaderView.cpp b/qrenderdoc/Widgets/Extended/RDHeaderView.cpp index 74eff7802..749eca72e 100644 --- a/qrenderdoc/Widgets/Extended/RDHeaderView.cpp +++ b/qrenderdoc/Widgets/Extended/RDHeaderView.cpp @@ -364,7 +364,7 @@ void RDHeaderView::cacheSectionMinSizes() void RDHeaderView::resizeSectionsWithHints() { - if(m_sectionMinSizes.count() == 0) + if(m_sectionMinSizes.count() == 0 || m_sectionStretchHintTotal <= 0) return; QVector sizes = m_sectionMinSizes; diff --git a/qrenderdoc/Windows/StatisticsViewer.cpp b/qrenderdoc/Windows/StatisticsViewer.cpp index 7f5b29f4b..418a06aa1 100644 --- a/qrenderdoc/Windows/StatisticsViewer.cpp +++ b/qrenderdoc/Windows/StatisticsViewer.cpp @@ -758,6 +758,10 @@ void StatisticsViewer::GenerateReport() largeTexH /= largeTexCount; } + float drawRatio = 0.0f; + if(drawCount + dispatchCount > 0) + drawRatio = (float)numAPIcalls / (float)(drawCount + dispatchCount); + const FrameDescription &frameInfo = m_Ctx.FrameInfo(); float compressedMB = (float)frameInfo.compressedFileSize / (1024.0f * 1024.0f); @@ -776,8 +780,7 @@ void StatisticsViewer::GenerateReport() .arg(persistentMB, 2, 'f', 2) .arg(initDataMB, 2, 'f', 2); QString drawList = tr("Draw calls: %1\nDispatch calls: %2\n").arg(drawCount).arg(dispatchCount); - QString ratio = tr("API:Draw/Dispatch call ratio: %1\n\n") - .arg((float)numAPIcalls / (float)(drawCount + dispatchCount)); + QString ratio = tr("API:Draw/Dispatch call ratio: %1\n\n").arg(drawRatio); QString textures = tr("%1 Textures - %2 MB (%3 MB over 32x32), %4 RTs - %5 MB.\n" "Avg. tex dimension: %6x%7 (%8x%9 over 32x32)\n") .arg(numTextures) diff --git a/renderdoc/driver/d3d12/d3d12_debug.cpp b/renderdoc/driver/d3d12/d3d12_debug.cpp index e012c4017..9f1f09609 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_debug.cpp @@ -3921,6 +3921,12 @@ void D3D12DebugManager::InitPostVSBuffers(uint32_t eventID) sodecls.push_back(decl); } + if(stride == 0) + { + RDCERR("Didn't get valid stride! Setting to 4 bytes"); + stride = 4; + } + // shift position attribute up to first, keeping order otherwise // the same if(posidx > 0) diff --git a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp index 8917eed63..9ff98fda1 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_get_funcs.cpp @@ -165,7 +165,7 @@ void WrappedVulkan::vkGetImageMemoryRequirements(VkDevice device, VkImage image, // allow for this. The variability isn't quite clear, but for now we assume aligning size to // alignment * 4 should be sufficient (adding on a fixed padding won't help the problem as it // won't remove the variability, nor will adding then aligning for the same reason). - if(GetDriverVersion().IsAMD()) + if(GetDriverVersion().IsAMD() && pMemoryRequirements->size > 0) { VkMemoryRequirements &memreq = *pMemoryRequirements; @@ -247,7 +247,7 @@ void WrappedVulkan::vkGetImageMemoryRequirements2KHR(VkDevice device, // allow for this. The variability isn't quite clear, but for now we assume aligning size to // alignment * 4 should be sufficient (adding on a fixed padding won't help the problem as it // won't remove the variability, nor will adding then aligning for the same reason). - if(GetDriverVersion().IsAMD()) + if(GetDriverVersion().IsAMD() && pMemoryRequirements->memoryRequirements.size > 0) { VkMemoryRequirements &memreq = pMemoryRequirements->memoryRequirements;