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);
}
VkPhysicalDeviceFeatures VulkanExampleBase::getEnabledFeatures()
{
return VkPhysicalDeviceFeatures{};
}
std::string VulkanExampleBase::getWindowTitle()
{
std::string device(deviceProperties.deviceName);
@ -676,7 +681,7 @@ void VulkanExampleBase::submitFrame()
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
}
VulkanExampleBase::VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatures enabledFeaturesFn)
VulkanExampleBase::VulkanExampleBase(bool enableValidation)
{
// Parse command line arguments
for (auto arg : args)
@ -700,11 +705,6 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatur
initxcbConnection();
#endif
if (enabledFeaturesFn != nullptr)
{
this->enabledFeatures = enabledFeaturesFn();
}
#if defined(_WIN32)
// Enable console if validation is active
// 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
// and encapsulates functions related to a device
vulkanDevice = new vk::VulkanDevice(physicalDevice);
VK_CHECK_RESULT(vulkanDevice->createLogicalDevice(enabledFeatures));
VK_CHECK_RESULT(vulkanDevice->createLogicalDevice(getEnabledFeatures()));
device = vulkanDevice->logicalDevice;
// todo: remove

View file

@ -206,7 +206,7 @@ public:
#endif
// Default ctor
VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatures enabledFeaturesFn = nullptr);
VulkanExampleBase(bool enableValidation);
// dtor
~VulkanExampleBase();
@ -233,6 +233,13 @@ public:
*/
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)
virtual void render() = 0;
// Called when view change occurs

View file

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

View file

@ -65,14 +65,15 @@ public:
} pipelines;
// 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;
return enabledFeatures;
}
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION, getEnabledFeatures)
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
{
zoom = -10.5f;
rotation = glm::vec3(-25.0f, 15.0f, 0.0f);

View file

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