Virtual function for enabling physical device features (instead of function pointer in constructor)

This commit is contained in:
saschawillems 2016-12-14 20:17:15 +01:00
parent d24f8ec8b7
commit 00ed23db98
5 changed files with 29 additions and 21 deletions

View file

@ -54,6 +54,11 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
return vkCreateInstance(&instanceCreateInfo, nullptr, &instance); return vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
} }
VkPhysicalDeviceFeatures VulkanExampleBase::getEnabledFeatures()
{
return VkPhysicalDeviceFeatures{};
}
std::string VulkanExampleBase::getWindowTitle() std::string VulkanExampleBase::getWindowTitle()
{ {
std::string device(deviceProperties.deviceName); std::string device(deviceProperties.deviceName);
@ -676,7 +681,7 @@ void VulkanExampleBase::submitFrame()
VK_CHECK_RESULT(vkQueueWaitIdle(queue)); VK_CHECK_RESULT(vkQueueWaitIdle(queue));
} }
VulkanExampleBase::VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatures enabledFeaturesFn) VulkanExampleBase::VulkanExampleBase(bool enableValidation)
{ {
// Parse command line arguments // Parse command line arguments
for (auto arg : args) for (auto arg : args)
@ -700,11 +705,6 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatur
initxcbConnection(); initxcbConnection();
#endif #endif
if (enabledFeaturesFn != nullptr)
{
this->enabledFeatures = enabledFeaturesFn();
}
#if defined(_WIN32) #if defined(_WIN32)
// Enable console if validation is active // Enable console if validation is active
// Debug message callback will output to it // Debug message callback will output to it
@ -830,7 +830,7 @@ void VulkanExampleBase::initVulkan()
// This is handled by a separate class that gets a logical device representation // This is handled by a separate class that gets a logical device representation
// and encapsulates functions related to a device // and encapsulates functions related to a device
vulkanDevice = new vk::VulkanDevice(physicalDevice); vulkanDevice = new vk::VulkanDevice(physicalDevice);
VK_CHECK_RESULT(vulkanDevice->createLogicalDevice(enabledFeatures)); VK_CHECK_RESULT(vulkanDevice->createLogicalDevice(getEnabledFeatures()));
device = vulkanDevice->logicalDevice; device = vulkanDevice->logicalDevice;
// todo: remove // todo: remove

View file

@ -206,7 +206,7 @@ public:
#endif #endif
// Default ctor // Default ctor
VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatures enabledFeaturesFn = nullptr); VulkanExampleBase(bool enableValidation);
// dtor // dtor
~VulkanExampleBase(); ~VulkanExampleBase();
@ -233,6 +233,13 @@ public:
*/ */
virtual VkResult createInstance(bool enableValidation); virtual VkResult createInstance(bool enableValidation);
/**
* Get physical device features to be enabled for this example
*
* @note Virtual, can be overriden by derived example class for custom instance creation
*/
virtual VkPhysicalDeviceFeatures getEnabledFeatures();
// Pure virtual render function (override in derived class) // Pure virtual render function (override in derived class)
virtual void render() = 0; virtual void render() = 0;
// Called when view change occurs // Called when view change occurs

View file

@ -169,9 +169,9 @@ public:
VkSemaphore offscreenSemaphore = VK_NULL_HANDLE; VkSemaphore offscreenSemaphore = VK_NULL_HANDLE;
// Device features to be enabled for this example // Device features to be enabled for this example
static VkPhysicalDeviceFeatures getEnabledFeatures() virtual VkPhysicalDeviceFeatures getEnabledFeatures()
{ {
VkPhysicalDeviceFeatures enabledFeatures = {}; VkPhysicalDeviceFeatures enabledFeatures{};
enabledFeatures.geometryShader = VK_TRUE; enabledFeatures.geometryShader = VK_TRUE;
enabledFeatures.shaderClipDistance = VK_TRUE; enabledFeatures.shaderClipDistance = VK_TRUE;
enabledFeatures.shaderCullDistance = VK_TRUE; enabledFeatures.shaderCullDistance = VK_TRUE;
@ -179,7 +179,7 @@ public:
return enabledFeatures; return enabledFeatures;
} }
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION, getEnabledFeatures) VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
{ {
enableTextOverlay = true; enableTextOverlay = true;
title = "Vulkan Example - Deferred shading with shadows (2016 by Sascha Willems)"; title = "Vulkan Example - Deferred shading with shadows (2016 by Sascha Willems)";
@ -669,25 +669,25 @@ public:
vkTools::initializers::descriptorImageInfo( vkTools::initializers::descriptorImageInfo(
frameBuffers.deferred->sampler, frameBuffers.deferred->sampler,
frameBuffers.deferred->attachments[0].view, frameBuffers.deferred->attachments[0].view,
VK_IMAGE_LAYOUT_GENERAL); VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkDescriptorImageInfo texDescriptorNormal = VkDescriptorImageInfo texDescriptorNormal =
vkTools::initializers::descriptorImageInfo( vkTools::initializers::descriptorImageInfo(
frameBuffers.deferred->sampler, frameBuffers.deferred->sampler,
frameBuffers.deferred->attachments[1].view, frameBuffers.deferred->attachments[1].view,
VK_IMAGE_LAYOUT_GENERAL); VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkDescriptorImageInfo texDescriptorAlbedo = VkDescriptorImageInfo texDescriptorAlbedo =
vkTools::initializers::descriptorImageInfo( vkTools::initializers::descriptorImageInfo(
frameBuffers.deferred->sampler, frameBuffers.deferred->sampler,
frameBuffers.deferred->attachments[2].view, frameBuffers.deferred->attachments[2].view,
VK_IMAGE_LAYOUT_GENERAL); VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkDescriptorImageInfo texDescriptorShadowMap = VkDescriptorImageInfo texDescriptorShadowMap =
vkTools::initializers::descriptorImageInfo( vkTools::initializers::descriptorImageInfo(
frameBuffers.shadow->sampler, frameBuffers.shadow->sampler,
frameBuffers.shadow->attachments[0].view, frameBuffers.shadow->attachments[0].view,
VK_IMAGE_LAYOUT_GENERAL); VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
writeDescriptorSets = { writeDescriptorSets = {
// Binding 0: Vertex shader uniform buffer // Binding 0: Vertex shader uniform buffer

View file

@ -65,14 +65,15 @@ public:
} pipelines; } pipelines;
// Device features to be enabled for this example // Device features to be enabled for this example
static VkPhysicalDeviceFeatures getEnabledFeatures() virtual VkPhysicalDeviceFeatures getEnabledFeatures()
{ {
VkPhysicalDeviceFeatures enabledFeatures = {}; VkPhysicalDeviceFeatures enabledFeatures{};
enabledFeatures.fillModeNonSolid = VK_TRUE;
enabledFeatures.wideLines = VK_TRUE; enabledFeatures.wideLines = VK_TRUE;
return enabledFeatures; return enabledFeatures;
} }
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION, getEnabledFeatures) VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
{ {
zoom = -10.5f; zoom = -10.5f;
rotation = glm::vec3(-25.0f, 15.0f, 0.0f); rotation = glm::vec3(-25.0f, 15.0f, 0.0f);

View file

@ -233,15 +233,15 @@ public:
VkSemaphore bindSparseSemaphore = VK_NULL_HANDLE; VkSemaphore bindSparseSemaphore = VK_NULL_HANDLE;
// Device features to be enabled for this example // Device features to be enabled for this example
static VkPhysicalDeviceFeatures getEnabledFeatures() virtual VkPhysicalDeviceFeatures getEnabledFeatures()
{ {
VkPhysicalDeviceFeatures enabledFeatures = {}; VkPhysicalDeviceFeatures enabledFeatures{};
enabledFeatures.shaderResourceResidency = VK_TRUE; enabledFeatures.shaderResourceResidency = VK_TRUE;
enabledFeatures.shaderResourceMinLod = VK_TRUE; enabledFeatures.shaderResourceMinLod = VK_TRUE;
return enabledFeatures; return enabledFeatures;
} }
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION, getEnabledFeatures) VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
{ {
zoom = -1.3f; zoom = -1.3f;
rotation = { 76.25f, 0.0f, 0.0f }; rotation = { 76.25f, 0.0f, 0.0f };