Skip to content

Commit 5b7951f

Browse files
committed
GPU Vulkan Display: Improve device initialization
1 parent 7b44870 commit 5b7951f

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

‎GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.cxx‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static inline void clearVector(T& v, S func, bool downsize = true)
273273

274274
// ---------------------------- VULKAN DEVICE MANAGEMENT ----------------------------
275275

276-
double GPUDisplayBackendVulkan::checkDevice(vk::PhysicalDevice device, const std::vector<const char*>& reqDeviceExtensions)
276+
double GPUDisplayBackendVulkan::checkDevice(vk::PhysicalDevice device, const std::vector<const char*>& reqDeviceExtensions, bool silent)
277277
{
278278
double score = -1.;
279279
vk::PhysicalDeviceProperties deviceProperties = device.getProperties();
@@ -287,18 +287,20 @@ double GPUDisplayBackendVulkan::checkDevice(vk::PhysicalDevice device, const std
287287
bool found = false;
288288
for (uint32_t i = 0; i < queueFamilies.size(); i++) {
289289
if (!(queueFamilies[i].queueFlags & vk::QueueFlagBits::eGraphics)) {
290-
return (-1);
290+
continue;
291291
}
292292
vk::Bool32 presentSupport = device.getSurfaceSupportKHR(i, mSurface);
293293
if (!presentSupport) {
294-
return (-1);
294+
continue;
295295
}
296296
mGraphicsFamily = i;
297297
found = true;
298298
break;
299299
}
300300
if (!found) {
301-
GPUInfo("%s ignored due to missing queue properties", &deviceProperties.deviceName[0]);
301+
if (!silent) {
302+
GPUInfo("%s ignored due to missing queue properties", &deviceProperties.deviceName[0]);
303+
}
302304
return (-1);
303305
}
304306

@@ -313,13 +315,17 @@ double GPUDisplayBackendVulkan::checkDevice(vk::PhysicalDevice device, const std
313315
}
314316
}
315317
if (extensionsFound < reqDeviceExtensions.size()) {
316-
GPUInfo("%s ignored due to missing extensions", &deviceProperties.deviceName[0]);
318+
if (!silent) {
319+
GPUInfo("%s ignored due to missing extensions", &deviceProperties.deviceName[0]);
320+
}
317321
return (-1);
318322
}
319323

320324
updateSwapChainDetails(device);
321325
if (mSwapChainDetails.formats.empty() || mSwapChainDetails.presentModes.empty()) {
322-
GPUInfo("%s ignored due to incompatible swap chain", &deviceProperties.deviceName[0]);
326+
if (!silent) {
327+
GPUInfo("%s ignored due to incompatible swap chain", &deviceProperties.deviceName[0]);
328+
}
323329
return (-1);
324330
}
325331

@@ -454,21 +460,22 @@ void GPUDisplayBackendVulkan::createDevice()
454460
if (!mPhysicalDevice) {
455461
throw std::runtime_error("All available Vulkan devices unsuited");
456462
}
463+
if (checkDevice(mPhysicalDevice, reqDeviceExtensions, true) <= 0) {
464+
throw std::runtime_error("Selected vulkan device is incompatible");
465+
}
457466

458467
updateSwapChainDetails(mPhysicalDevice);
459468
vk::PhysicalDeviceProperties deviceProperties = mPhysicalDevice.getProperties();
460469
vk::PhysicalDeviceFeatures deviceFeatures = mPhysicalDevice.getFeatures();
461470
vk::FormatProperties depth32FormatProperties = mPhysicalDevice.getFormatProperties(vk::Format::eD32Sfloat);
462471
vk::FormatProperties depth64FormatProperties = mPhysicalDevice.getFormatProperties(vk::Format::eD32SfloatS8Uint);
463-
vk::FormatProperties formatProperties = mPhysicalDevice.getFormatProperties(mSurfaceFormat.format);
464472
GPUInfo("Using physical Vulkan device %s", &deviceProperties.deviceName[0]);
465473
mMaxMSAAsupported = getMaxUsableSampleCount(deviceProperties);
466474
mZSupported = (bool)(depth32FormatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment);
467475
mStencilSupported = (bool)(depth64FormatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment);
468-
mCubicFilterSupported = (bool)(formatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eSampledImageFilterCubicEXT);
469476
bool mailboxSupported = std::find(mSwapChainDetails.presentModes.begin(), mSwapChainDetails.presentModes.end(), vk::PresentModeKHR::eMailbox) != mSwapChainDetails.presentModes.end();
470477
if (mDisplay->GetProcessingSettings().debugLevel >= 2) {
471-
GPUInfo("Max MSAA: %d, 32 bit Z buffer %d, 32 bit Z buffer + stencil buffer %d, Cubic Filtering %d, Mailbox present mode %d\n", (int32_t)mMaxMSAAsupported, (int32_t)mZSupported, (int32_t)mStencilSupported, (int32_t)mCubicFilterSupported, (int32_t)mailboxSupported);
478+
GPUInfo("Max MSAA: %d, 32 bit Z buffer %d, 32 bit Z buffer + stencil buffer %d, Mailbox present mode %d\n", (int32_t)mMaxMSAAsupported, (int32_t)mZSupported, (int32_t)mStencilSupported, (int32_t)mailboxSupported);
472479
}
473480

474481
vk::DeviceQueueCreateInfo queueCreateInfo{};
@@ -1893,8 +1900,8 @@ void GPUDisplayBackendVulkan::OpenGLPrint(const char* s, float x, float y, float
18931900
scale *= 0.25f; // Font size is 48 to have nice bitmap, scale to size 12
18941901
}
18951902

1896-
for (const char* c = s; *c; c++) {
1897-
if ((int32_t)*c > (int32_t)mFontSymbols.size()) {
1903+
for (const unsigned char* c = (const unsigned char*)s; *c; c++) {
1904+
if ((int32_t)*c >= (int32_t)mFontSymbols.size()) {
18981905
GPUError("Trying to draw unsupported symbol: %d > %d\n", (int32_t)*c, (int32_t)mFontSymbols.size());
18991906
continue;
19001907
}

‎GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class GPUDisplayBackendVulkan : public GPUDisplayBackend
8383
float getYFactor() const override { return -1.0f; }
8484
int32_t getMaxMSAA() const override { return mMaxMSAAsupported; }
8585

86-
double checkDevice(vk::PhysicalDevice device, const std::vector<const char*>& reqDeviceExtensions);
86+
double checkDevice(vk::PhysicalDevice device, const std::vector<const char*>& reqDeviceExtensions, bool silent = false);
8787
vk::Extent2D chooseSwapExtent(const vk::SurfaceCapabilitiesKHR& capabilities);
8888
void transitionImageLayout(vk::CommandBuffer commandBuffer, vk::Image image, vk::Format format, vk::ImageLayout oldLayout, vk::ImageLayout newLayout);
8989
VulkanBuffer createBuffer(size_t size, const void* srcData = nullptr, vk::BufferUsageFlags type = vk::BufferUsageFlagBits::eVertexBuffer, int32_t deviceMemory = 1);
@@ -208,7 +208,6 @@ class GPUDisplayBackendVulkan : public GPUDisplayBackend
208208
bool mZActive = false;
209209
bool mZSupported = false;
210210
bool mStencilSupported = false;
211-
bool mCubicFilterSupported = false;
212211
bool mDownsampleFSAA = false;
213212
bool mMixingSupported = 0;
214213

0 commit comments

Comments
 (0)