diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index cddf55ae..073f8a35 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -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 diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index e2e9ad6a..653bb701 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -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 diff --git a/deferredshadows/deferredshadows.cpp b/deferredshadows/deferredshadows.cpp index e1bc6470..ccffbbc7 100644 --- a/deferredshadows/deferredshadows.cpp +++ b/deferredshadows/deferredshadows.cpp @@ -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 diff --git a/pipelines/pipelines.cpp b/pipelines/pipelines.cpp index 325e8b3d..a570afff 100644 --- a/pipelines/pipelines.cpp +++ b/pipelines/pipelines.cpp @@ -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); diff --git a/texturesparseresidency/texturesparseresidency.cpp b/texturesparseresidency/texturesparseresidency.cpp index 842c4886..7e1707ae 100644 --- a/texturesparseresidency/texturesparseresidency.cpp +++ b/texturesparseresidency/texturesparseresidency.cpp @@ -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 };