From 401369f716796a792be13d5064c7783d7be92d27 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Wed, 14 Dec 2016 21:38:45 +0100 Subject: [PATCH] Removed function to get enabled features, features can be set directly in derived constructor due to new explicit Vulkan initialization --- base/vulkanexamplebase.cpp | 7 +---- base/vulkanexamplebase.h | 21 +++++--------- .../geometryshader/normaldebug.geom.spv | Bin 2876 -> 2852 bytes displacement/displacement.cpp | 18 +++++++----- geometryshader/geometryshader.cpp | 3 ++ terraintessellation/terraintessellation.cpp | 26 ++++++++---------- tessellation/tessellation.cpp | 16 +++++++---- 7 files changed, 44 insertions(+), 47 deletions(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 073f8a35..bcc8f1a0 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -54,11 +54,6 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) return vkCreateInstance(&instanceCreateInfo, nullptr, &instance); } -VkPhysicalDeviceFeatures VulkanExampleBase::getEnabledFeatures() -{ - return VkPhysicalDeviceFeatures{}; -} - std::string VulkanExampleBase::getWindowTitle() { std::string device(deviceProperties.deviceName); @@ -830,7 +825,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(getEnabledFeatures())); + VK_CHECK_RESULT(vulkanDevice->createLogicalDevice(enabledFeatures)); device = vulkanDevice->logicalDevice; // todo: remove diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 653bb701..94c879b1 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -44,17 +44,11 @@ #include "vulkantextoverlay.hpp" #include "camera.hpp" -// Function pointer for getting physical device fetures to be enabled -typedef VkPhysicalDeviceFeatures (*PFN_GetEnabledFeatures)(); - class VulkanExampleBase { private: // Set to true if v-sync will be forced for the swapchain bool enableVSync = false; - // Device features enabled by the example - // If not set, no additional features are enabled (may result in validation layer errors) - VkPhysicalDeviceFeatures enabledFeatures = {}; // fps timer (one second interval) float fpsTimer = 0.0f; // Get window title with example name, device, et. @@ -81,10 +75,16 @@ protected: VkPhysicalDevice physicalDevice; // Stores physical device properties (for e.g. checking device limits) VkPhysicalDeviceProperties deviceProperties; - // Stores phyiscal device features (for e.g. checking if a feature is available) + // Stores the features available on the selected physical device (for e.g. checking if a feature is available) VkPhysicalDeviceFeatures deviceFeatures; // Stores all available memory (type) properties for the physical device VkPhysicalDeviceMemoryProperties deviceMemoryProperties; + /** + * Set of physical device features to be enabled for this example (must be set in the derived constructor) + * + * @note By default no phyiscal device features are enabled + */ + VkPhysicalDeviceFeatures enabledFeatures{}; /** @brief Logical device, application's view of the physical device (GPU) */ // todo: getter? should always point to VulkanDevice->device VkDevice device; @@ -233,13 +233,6 @@ 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/data/shaders/geometryshader/normaldebug.geom.spv b/data/shaders/geometryshader/normaldebug.geom.spv index a5c732a96b8309722c2a9caa3a98f83eebca2a2c..105ecee112f894b77a3253609d82549c44f5d53a 100644 GIT binary patch delta 10 RcmdlZwnS`#%tjLqZU7ZY12F&q delta 32 fcmZ1?wnuD&jHn<36N3Z;0|SUwfYOQ^CAql)PtXIv diff --git a/displacement/displacement.cpp b/displacement/displacement.cpp index 71eaa5ac..28d25b0e 100644 --- a/displacement/displacement.cpp +++ b/displacement/displacement.cpp @@ -79,8 +79,6 @@ public: virtual VkPhysicalDeviceFeatures getEnabledFeatures() { VkPhysicalDeviceFeatures enabledFeatures{}; - enabledFeatures.tessellationShader = VK_TRUE; - enabledFeatures.fillModeNonSolid = VK_TRUE; return enabledFeatures; } @@ -90,11 +88,11 @@ public: rotation = glm::vec3(-20.0f, 45.0f, 0.0f); enableTextOverlay = true; title = "Vulkan Example - Tessellation shader displacement mapping"; - // Support for tessellation shaders is optional, so check first - if (!deviceFeatures.tessellationShader) - { - vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); - } + // Enable physical device features required for this example + // Tell the driver that we are going to use geometry shaders + enabledFeatures.tessellationShader = VK_TRUE; + // Example also uses a wireframe pipeline, enable non-solid fill modes + enabledFeatures.fillModeNonSolid = VK_TRUE; } ~VulkanExample() @@ -508,6 +506,12 @@ public: void prepare() { + // Check if device supports tessellation shaders + if (!deviceFeatures.tessellationShader) + { + vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); + } + VulkanExampleBase::prepare(); loadMeshes(); loadTextures(); diff --git a/geometryshader/geometryshader.cpp b/geometryshader/geometryshader.cpp index 4d7dc59a..f99ad88a 100644 --- a/geometryshader/geometryshader.cpp +++ b/geometryshader/geometryshader.cpp @@ -76,6 +76,9 @@ public: rotation = glm::vec3(0.0f, -25.0f, 0.0f); enableTextOverlay = true; title = "Vulkan Example - Geometry shader"; + // Enable physical device features required for this example + // Tell the driver that we are going to use geometry shaders + enabledFeatures.geometryShader = VK_TRUE; } ~VulkanExample() diff --git a/terraintessellation/terraintessellation.cpp b/terraintessellation/terraintessellation.cpp index 8a7e671f..18fe9938 100644 --- a/terraintessellation/terraintessellation.cpp +++ b/terraintessellation/terraintessellation.cpp @@ -112,15 +112,6 @@ public: // View frustum passed to tessellation control shader for culling vkTools::Frustum frustum; - // Device features to be enabled for this example - virtual VkPhysicalDeviceFeatures getEnabledFeatures() - { - VkPhysicalDeviceFeatures enabledFeatures{}; - enabledFeatures.tessellationShader = VK_TRUE; - enabledFeatures.fillModeNonSolid = VK_TRUE; - return enabledFeatures; - } - VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { enableTextOverlay = true; @@ -129,13 +120,12 @@ public: camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f); camera.setRotation(glm::vec3(-12.0f, 159.0f, 0.0f)); camera.setTranslation(glm::vec3(18.0f, 22.5f, 57.5f)); - camera.movementSpeed = 7.5f; - // Support for tessellation shaders is optional, so check first - //if (!deviceFeatures.tessellationShader) - //{ - // vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); - //} + // Enable physical device features required for this example + // Tell the driver that we are going to use geometry shaders + enabledFeatures.tessellationShader = VK_TRUE; + // Example also uses a wireframe pipeline, enable non-solid fill modes + enabledFeatures.fillModeNonSolid = VK_TRUE; } ~VulkanExample() @@ -896,6 +886,12 @@ public: void prepare() { + // Check if device supports tessellation shaders + if (!deviceFeatures.tessellationShader) + { + vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); + } + VulkanExampleBase::prepare(); loadMeshes(); loadTextures(); diff --git a/tessellation/tessellation.cpp b/tessellation/tessellation.cpp index d1e925d8..3a7078ed 100644 --- a/tessellation/tessellation.cpp +++ b/tessellation/tessellation.cpp @@ -94,11 +94,11 @@ public: cameraPos = glm::vec3(-3.0f, 2.3f, 0.0f); title = "Vulkan Example - Tessellation shader (PN Triangles)"; enableTextOverlay = true; - // Support for tessellation shaders is optional, so check first - if (!deviceFeatures.tessellationShader) - { - vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); - } + // Enable physical device features required for this example + // Tell the driver that we are going to use geometry shaders + enabledFeatures.tessellationShader = VK_TRUE; + // Example also uses a wireframe pipeline, enable non-solid fill modes + enabledFeatures.fillModeNonSolid = VK_TRUE; } ~VulkanExample() @@ -511,6 +511,12 @@ public: void prepare() { + // Check if device supports tessellation shaders + if (!deviceFeatures.tessellationShader) + { + vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); + } + VulkanExampleBase::prepare(); loadTextures(); loadMeshes();