Skip to content

Commit

Permalink
Replaced per-sample validation define with global define in base class
Browse files Browse the repository at this point in the history
Toggling validation via command line arguments is the preferred way anyway
Define was also added as a CMake option
  • Loading branch information
SaschaWillems committed Dec 30, 2023
1 parent a04a506 commit d0211d1
Show file tree
Hide file tree
Showing 86 changed files with 90 additions and 205 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OPTION(USE_DIRECTFB_WSI "Build the project using DirectFB swapchain" OFF)
OPTION(USE_WAYLAND_WSI "Build the project using Wayland swapchain" OFF)
OPTION(USE_HEADLESS "Build the project using headless extension swapchain" OFF)
OPTION(USE_RELATIVE_ASSET_PATH "Load assets (shaders, models, textures) from a fixed path relative to the binar" OFF)
OPTION(FORCE_VALIDATION "Forces validation on for all samples at compile time (prefer using the -v / --validation command line arguments)" OFF)

set(RESOURCE_INSTALL_DIR "" CACHE PATH "Path to install resources to (leave empty for running uninstalled)")

Expand Down Expand Up @@ -128,6 +129,11 @@ else()
endif()
endif()

# Force validation at compile time
if (FORCE_VALIDATION)
add_definitions(-DFORCE_VALIDATION)
endif()

# Compiler specific stuff
IF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
Expand Down
7 changes: 5 additions & 2 deletions base/vulkanexamplebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ void VulkanExampleBase::submitFrame()
VK_CHECK_RESULT(vkQueueWaitIdle(queue));
}

VulkanExampleBase::VulkanExampleBase(bool enableValidation)
VulkanExampleBase::VulkanExampleBase()
{
#if !defined(VK_USE_PLATFORM_ANDROID_KHR)
// Check for a valid asset path
Expand All @@ -796,7 +796,10 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation)
}
#endif

settings.validation = enableValidation;
// Validation for all samples can be forced at compile time using the FORCE_VALIDATION define
#if defined(FORCE_VALIDATION)
settings.validation = true;
#endif

// Command line arguments
commandLineParser.add("help", { "--help" }, 0, "Show help");
Expand Down
3 changes: 2 additions & 1 deletion base/vulkanexamplebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ class VulkanExampleBase
bool quit = false;
#endif

VulkanExampleBase(bool enableValidation = false);
/** @brief Default base class constructor */
VulkanExampleBase();
virtual ~VulkanExampleBase();
/** @brief Setup the vulkan instance, enable required extensions and connect to the physical device (GPU) */
bool initVulkan();
Expand Down
3 changes: 1 addition & 2 deletions examples/bloom/bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

// Offscreen frame buffer properties
#define FB_DIM 256
Expand Down Expand Up @@ -93,7 +92,7 @@ class VulkanExample : public VulkanExampleBase
std::array<FrameBuffer, 2> framebuffers;
} offscreenPass;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Bloom (offscreen rendering)";
timerSpeed *= 0.5f;
Expand Down
3 changes: 1 addition & 2 deletions examples/computecloth/computecloth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand Down Expand Up @@ -89,7 +88,7 @@ class VulkanExample : public VulkanExampleBase
glm::vec2 size = glm::vec2(5.0f);
} cloth;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Compute shader cloth simulation";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/computecullandlod/computecullandlod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "VulkanglTFModel.h"
#include "frustum.hpp"

#define ENABLE_VALIDATION false

// Total number of objects (^3) in the scene
#if defined(__ANDROID__)
Expand Down Expand Up @@ -89,7 +88,7 @@ class VulkanExample : public VulkanExampleBase

uint32_t objectCount = 0;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Vulkan Example - Compute cull and lod";
camera.type = Camera::CameraType::firstperson;
Expand Down
3 changes: 1 addition & 2 deletions examples/computenbody/computenbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"

#define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false
#if defined(__ANDROID__)
// Lower particle count on Android for performance reasons
#define PARTICLES_PER_ATTRACTOR 3 * 1024
Expand Down Expand Up @@ -79,7 +78,7 @@ class VulkanExample : public VulkanExampleBase
glm::vec4 vel; // xyz = velocity, w = gradient texture position
};

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Compute shader N-body system";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/computeparticles/computeparticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "vulkanexamplebase.h"

#define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false
#if defined(__ANDROID__)
// Lower particle count on Android for performance reasons
#define PARTICLE_COUNT 128 * 1024
Expand Down Expand Up @@ -75,7 +74,7 @@ class VulkanExample : public VulkanExampleBase
glm::vec4 gradientPos; // Texture coordinates for the gradient ramp map
};

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Compute shader particle system";
}
Expand Down
3 changes: 1 addition & 2 deletions examples/computeraytracing/computeraytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"

#define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false

#if defined(__ANDROID__)
#define TEX_DIM 1024
Expand Down Expand Up @@ -79,7 +78,7 @@ class VulkanExample : public VulkanExampleBase
glm::ivec3 _pad;
};

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Compute shader ray tracing";
compute.ubo.aspectRatio = (float)width / (float)height;
Expand Down
3 changes: 1 addition & 2 deletions examples/computeshader/computeshader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"

#define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false

// Vertex layout for this example
struct Vertex {
Expand Down Expand Up @@ -67,7 +66,7 @@ class VulkanExample : public VulkanExampleBase

std::vector<std::string> shaderNames;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Compute shader image load/store";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/conditionalrender/conditionalrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand All @@ -40,7 +39,7 @@ class VulkanExample : public VulkanExampleBase
VkDescriptorSetLayout descriptorSetLayout;
VkDescriptorSet descriptorSet;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Conditional rendering";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/conservativeraster/conservativeraster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "vulkanexamplebase.h"

#define ENABLE_VALIDATION false

#define FB_COLOR_FORMAT VK_FORMAT_R8G8B8A8_UNORM
#define ZOOM_FACTOR 16
Expand Down Expand Up @@ -84,7 +83,7 @@ class VulkanExample : public VulkanExampleBase
VkDescriptorImageInfo descriptor;
} offscreenPass;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Conservative rasterization";

Expand Down
3 changes: 1 addition & 2 deletions examples/debugprintf/debugprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand All @@ -36,7 +35,7 @@ class VulkanExample : public VulkanExampleBase
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Debug output with shader printf";
camera.setRotation(glm::vec3(-4.35f, 16.25f, 0.0f));
Expand Down
4 changes: 1 addition & 3 deletions examples/debugutils/debugutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
public:
Expand Down Expand Up @@ -79,7 +77,7 @@ class VulkanExample : public VulkanExampleBase
PFN_vkQueueEndDebugUtilsLabelEXT vkQueueEndDebugUtilsLabelEXT{ nullptr };
PFN_vkSetDebugUtilsObjectNameEXT vkSetDebugUtilsObjectNameEXT{ nullptr };

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Debugging with VK_EXT_debug_utils";
camera.setRotation(glm::vec3(-4.35f, 16.25f, 0.0f));
Expand Down
3 changes: 1 addition & 2 deletions examples/deferred/deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

// Texture properties
#define TEX_DIM 2048
Expand Down Expand Up @@ -100,7 +99,7 @@ class VulkanExample : public VulkanExampleBase
// Semaphore used to synchronize between offscreen and final scene rendering
VkSemaphore offscreenSemaphore = VK_NULL_HANDLE;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Deferred shading";
camera.type = Camera::CameraType::firstperson;
Expand Down
3 changes: 1 addition & 2 deletions examples/deferredmultisampling/deferredmultisampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "VulkanFrameBuffer.hpp"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

#if defined(__ANDROID__)
// Use max. screen dimension as deferred framebuffer size
Expand Down Expand Up @@ -90,7 +89,7 @@ class VulkanExample : public VulkanExampleBase
// Semaphore used to synchronize between offscreen and final scene rendering
VkSemaphore offscreenSemaphore = VK_NULL_HANDLE;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Multi sampled deferred shading";
camera.type = Camera::CameraType::firstperson;
Expand Down
3 changes: 1 addition & 2 deletions examples/deferredshadows/deferredshadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "VulkanglTFModel.h"

#define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false

// Shadowmap properties
#if defined(__ANDROID__)
Expand Down Expand Up @@ -129,7 +128,7 @@ class VulkanExample : public VulkanExampleBase
// Semaphore used to synchronize between offscreen and final scene rendering
VkSemaphore offscreenSemaphore = VK_NULL_HANDLE;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Deferred shading with shadows";
camera.type = Camera::CameraType::firstperson;
Expand Down
3 changes: 1 addition & 2 deletions examples/descriptorbuffer/descriptorbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand Down Expand Up @@ -63,7 +62,7 @@ class VulkanExample : public VulkanExampleBase
return vkGetBufferDeviceAddressKHR(vulkanDevice->logicalDevice, &bufferDeviceAI);
}

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Descriptor buffers (VK_EXT_descriptor_buffer)";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/descriptorindexing/descriptorindexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "vulkanexamplebase.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand Down Expand Up @@ -45,7 +44,7 @@ class VulkanExample : public VulkanExampleBase
int32_t textureIndex;
};

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Descriptor indexing";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/descriptorsets/descriptorsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand All @@ -38,7 +37,7 @@ class VulkanExample : public VulkanExampleBase

VkDescriptorSetLayout descriptorSetLayout;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Using descriptor Sets";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/displacement/displacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand Down Expand Up @@ -48,7 +47,7 @@ class VulkanExample : public VulkanExampleBase
VkDescriptorSet descriptorSet;
VkDescriptorSetLayout descriptorSetLayout;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Tessellation shader displacement";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/distancefieldfonts/distancefieldfonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "vulkanexamplebase.h"

#define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false

// Vertex layout for this example
struct Vertex {
Expand Down Expand Up @@ -93,7 +92,7 @@ class VulkanExample : public VulkanExampleBase
VkPipelineLayout pipelineLayout;
VkDescriptorSetLayout descriptorSetLayout;

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Distance field font rendering";
camera.type = Camera::CameraType::lookat;
Expand Down
3 changes: 1 addition & 2 deletions examples/dynamicrendering/dynamicrendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "vulkanexamplebase.h"
#include "VulkanglTFModel.h"

#define ENABLE_VALIDATION false

class VulkanExample : public VulkanExampleBase
{
Expand All @@ -33,7 +32,7 @@ class VulkanExample : public VulkanExampleBase
VkDescriptorSet descriptorSet{ VK_NULL_HANDLE };
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };

VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
VulkanExample() : VulkanExampleBase()
{
title = "Dynamic rendering";
camera.type = Camera::CameraType::lookat;
Expand Down
Loading

0 comments on commit d0211d1

Please sign in to comment.