Added device name and frame rate counter to window title

This commit is contained in:
saschawillems 2016-03-13 16:51:00 +01:00
parent af653e7bcf
commit 66607e2d2f
3 changed files with 32 additions and 3 deletions

View file

@ -75,6 +75,14 @@ VkResult VulkanExampleBase::createDevice(VkDeviceQueueCreateInfo requestedQueues
return vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &device); return vkCreateDevice(physicalDevice, &deviceCreateInfo, nullptr, &device);
} }
std::string VulkanExampleBase::getWindowTitle()
{
std::string device(deviceProperties.deviceName);
std::string windowTitle;
windowTitle = title + " - " + device + " - " + std::to_string(frameCounter) + " fps";
return windowTitle;
}
bool VulkanExampleBase::checkCommandBuffers() bool VulkanExampleBase::checkCommandBuffers()
{ {
for (auto& cmdBuffer : drawCmdBuffers) for (auto& cmdBuffer : drawCmdBuffers)
@ -303,6 +311,7 @@ void VulkanExampleBase::renderLoop()
DispatchMessage(&msg); DispatchMessage(&msg);
} }
render(); render();
frameCounter++;
auto tEnd = std::chrono::high_resolution_clock::now(); auto tEnd = std::chrono::high_resolution_clock::now();
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count(); auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
frameTimer = (float)tDiff / 1000.0f; frameTimer = (float)tDiff / 1000.0f;
@ -315,6 +324,16 @@ void VulkanExampleBase::renderLoop()
timer -= 1.0f; timer -= 1.0f;
} }
} }
fpsTimer += (float)tDiff;
if (fpsTimer > 1000.0f)
{
#ifdef _WIN32
std::string windowTitle = getWindowTitle();
SetWindowText(window, windowTitle.c_str());
#endif
fpsTimer = 0.0f;
frameCounter = 0.0f;
}
} }
#else #else
xcb_flush(connection); xcb_flush(connection);
@ -563,6 +582,8 @@ void VulkanExampleBase::initVulkan(bool enableValidation)
err = createDevice(queueCreateInfo, enableValidation); err = createDevice(queueCreateInfo, enableValidation);
assert(!err); assert(!err);
vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
// Gather physical device memory properties // Gather physical device memory properties
vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemoryProperties); vkGetPhysicalDeviceMemoryProperties(physicalDevice, &deviceMemoryProperties);
@ -710,10 +731,10 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
std::string windowTitle = getWindowTitle();
window = CreateWindowEx(0, window = CreateWindowEx(0,
name.c_str(), name.c_str(),
title.c_str(), windowTitle.c_str(),
// WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU,
dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
windowRect.left, windowRect.left,
windowRect.top, windowRect.top,

View file

@ -41,17 +41,25 @@ class VulkanExampleBase
private: private:
// Set to true when example is created with enabled validation layers // Set to true when example is created with enabled validation layers
bool enableValidation = false; bool enableValidation = false;
// fps timer (one second interval)
float fpsTimer = 0.0f;
// Create application wide Vulkan instance // Create application wide Vulkan instance
VkResult createInstance(bool enableValidation); VkResult createInstance(bool enableValidation);
// Create logical Vulkan device based on physical device // Create logical Vulkan device based on physical device
VkResult createDevice(VkDeviceQueueCreateInfo requestedQueues, bool enableValidation); VkResult createDevice(VkDeviceQueueCreateInfo requestedQueues, bool enableValidation);
// Get window title with example name, device, et.
std::string getWindowTitle();
protected: protected:
// Last frame time, measured using a high performance timer (if available) // Last frame time, measured using a high performance timer (if available)
float frameTimer = 1.0f; float frameTimer = 1.0f;
// Frame counter to display fps
uint32_t frameCounter = 0;
// Vulkan instance, stores all per-application states // Vulkan instance, stores all per-application states
VkInstance instance; VkInstance instance;
// Physical device (GPU) that Vulkan will ise // Physical device (GPU) that Vulkan will ise
VkPhysicalDevice physicalDevice; VkPhysicalDevice physicalDevice;
// Stores physical device properties (for e.g. checking device limits)
VkPhysicalDeviceProperties deviceProperties;
// Stores all available memory (type) properties for the physical device // Stores all available memory (type) properties for the physical device
VkPhysicalDeviceMemoryProperties deviceMemoryProperties; VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
// Logical device, application's view of the physical device (GPU) // Logical device, application's view of the physical device (GPU)

View file

@ -39,7 +39,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\</OutDir> <OutDir>$(SolutionDir)\bin\</OutDir>
<IntDir>$(SolutionDir)\bin\</IntDir> <IntDir>$(SolutionDir)\bin\intermediate\$(ProjectName)\$(ConfigurationName)</IntDir>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>