Skip to content

Commit

Permalink
Introduce type aliases for vkb::VulkanSample and vkb::core::VulkanRes…
Browse files Browse the repository at this point in the history
…ource. (KhronosGroup#1085)

* Introduce type aliases for vkb::VulkanSample and vkb::core::VulkanResource.

* Use type aliases in sample templates.
  • Loading branch information
asuessenbach authored Jul 16, 2024
1 parent 2cd7398 commit b115112
Show file tree
Hide file tree
Showing 138 changed files with 184 additions and 175 deletions.
2 changes: 1 addition & 1 deletion app/plugins/batch_mode/batch_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void BatchMode::on_update(float delta_time)
elapsed_time = 0.0f;

// Only check and advance the config if the application is a vulkan sample
if (auto *vulkan_app = dynamic_cast<vkb::VulkanSample<vkb::BindingType::C> *>(&platform->get_app()))
if (auto *vulkan_app = dynamic_cast<vkb::VulkanSampleC *>(&platform->get_app()))
{
auto &configuration = vulkan_app->get_configuration();

Expand Down
2 changes: 1 addition & 1 deletion bldsys/cmake/template/sample/sample.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool @SAMPLE_NAME@::prepare(const vkb::ApplicationOptions &options)
return true;
}

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_@SAMPLE_NAME_FILE@()
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@()
{
return std::make_unique<@SAMPLE_NAME@>();
}
4 changes: 2 additions & 2 deletions bldsys/cmake/template/sample/sample.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "scene_graph/components/camera.h"
#include "vulkan_sample.h"

class @SAMPLE_NAME@ : public vkb::VulkanSample<vkb::BindingType::C>
class @SAMPLE_NAME@ : public vkb::VulkanSampleC
{
public:
@SAMPLE_NAME@();
Expand All @@ -31,4 +31,4 @@ class @SAMPLE_NAME@ : public vkb::VulkanSample<vkb::BindingType::C>
virtual ~@SAMPLE_NAME@() = default;
};

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_@SAMPLE_NAME_FILE@();
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@();
2 changes: 1 addition & 1 deletion bldsys/cmake/template/sample_api/sample.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void @SAMPLE_NAME@::render(float delta_time)
ApiVulkanSample::submit_frame();
}

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_@SAMPLE_NAME_FILE@()
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@()
{
return std::make_unique<@SAMPLE_NAME@>();
}
2 changes: 1 addition & 1 deletion bldsys/cmake/template/sample_api/sample.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ class @SAMPLE_NAME@ : public ApiVulkanSample
VkPipelineLayout sample_pipeline_layout{};
};

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_@SAMPLE_NAME_FILE@();
std::unique_ptr<vkb::VulkanSampleC> create_@SAMPLE_NAME_FILE@();
2 changes: 1 addition & 1 deletion framework/api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct Meshlet
*
* See vkb::VulkanSample for documentation
*/
class ApiVulkanSample : public vkb::VulkanSample<vkb::BindingType::C>
class ApiVulkanSample : public vkb::VulkanSampleC
{
public:
ApiVulkanSample() = default;
Expand Down
2 changes: 1 addition & 1 deletion framework/common/hpp_resource_caching.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct hash<vkb::core::HPPImageView>
{
size_t operator()(const vkb::core::HPPImageView &image_view) const
{
size_t result = std::hash<vkb::core::VulkanResource<vkb::BindingType::Cpp, vk::ImageView>>()(image_view);
size_t result = std::hash<vkb::core::VulkanResourceCpp<vk::ImageView>>()(image_view);
vkb::hash_combine(result, image_view.get_image());
vkb::hash_combine(result, image_view.get_format());
vkb::hash_combine(result, image_view.get_subresource_range());
Expand Down
2 changes: 1 addition & 1 deletion framework/core/allocated.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class AllocatedBase
template <
typename HandleType,
typename MemoryType = VkDeviceMemory,
typename ParentType = vkb::core::VulkanResource<vkb::BindingType::C, HandleType>>
typename ParentType = vkb::core::VulkanResourceC<HandleType>>
class Allocated : public ParentType, public AllocatedBase
{
public:
Expand Down
2 changes: 1 addition & 1 deletion framework/core/command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ using SubpassC = Subpass<vkb::BindingType::C>;
* @brief Helper class to manage and record a command buffer, building and
* keeping track of pipeline state and resource bindings
*/
class CommandBuffer : public vkb::core::VulkanResource<vkb::BindingType::C, VkCommandBuffer>
class CommandBuffer : public vkb::core::VulkanResourceC<VkCommandBuffer>
{
public:
enum class ResetMode
Expand Down
2 changes: 1 addition & 1 deletion framework/core/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Device::Device(PhysicalDevice &gpu,
VkSurfaceKHR surface,
std::unique_ptr<DebugUtils> &&debug_utils,
std::unordered_map<const char *, bool> requested_extensions) :
vkb::core::VulkanResource<vkb::BindingType::C, VkDevice>{VK_NULL_HANDLE, this}, // Recursive, but valid
vkb::core::VulkanResourceC<VkDevice>{VK_NULL_HANDLE, this}, // Recursive, but valid
debug_utils{std::move(debug_utils)},
gpu{gpu},
resource_cache{*this}
Expand Down
2 changes: 1 addition & 1 deletion framework/core/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct DriverVersion
uint16_t patch;
};

class Device : public vkb::core::VulkanResource<vkb::BindingType::C, VkDevice>
class Device : public vkb::core::VulkanResourceC<VkDevice>
{
public:
/**
Expand Down
4 changes: 2 additions & 2 deletions framework/core/hpp_allocated.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ template <typename HandleType>
class HPPAllocated : public Allocated<
HandleType,
vk::DeviceMemory,
vkb::core::VulkanResource<vkb::BindingType::Cpp, HandleType>>
vkb::core::VulkanResourceCpp<HandleType>>
{
using Parent = Allocated<HandleType, vk::DeviceMemory, vkb::core::VulkanResource<vkb::BindingType::Cpp, HandleType>>;
using Parent = Allocated<HandleType, vk::DeviceMemory, vkb::core::VulkanResourceCpp<HandleType>>;

public:
using Parent::get_handle;
Expand Down
2 changes: 1 addition & 1 deletion framework/core/hpp_command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HPPDescriptorSetLayout;
* @brief Helper class to manage and record a command buffer, building and
* keeping track of pipeline state and resource bindings
*/
class HPPCommandBuffer : public vkb::core::VulkanResource<vkb::BindingType::Cpp, vk::CommandBuffer>
class HPPCommandBuffer : public vkb::core::VulkanResourceCpp<vk::CommandBuffer>
{
public:
struct RenderPassBinding
Expand Down
2 changes: 1 addition & 1 deletion framework/core/hpp_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace core
{
class HPPBuffer;

class HPPDevice : public vkb::core::VulkanResource<vkb::BindingType::Cpp, vk::Device>
class HPPDevice : public vkb::core::VulkanResourceCpp<vk::Device>
{
public:
/**
Expand Down
2 changes: 1 addition & 1 deletion framework/core/hpp_image_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace vkb
{
namespace core
{
class HPPImageView : public vkb::core::VulkanResource<vkb::BindingType::Cpp, vk::ImageView>
class HPPImageView : public vkb::core::VulkanResourceCpp<vk::ImageView>
{
public:
HPPImageView(vkb::core::HPPImage &image,
Expand Down
2 changes: 1 addition & 1 deletion framework/core/hpp_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace vkb
namespace core
{
HPPSampler::HPPSampler(vkb::core::HPPDevice &device, const vk::SamplerCreateInfo &info) :
vkb::core::VulkanResource<vkb::BindingType::Cpp, vk::Sampler>{device.get_handle().createSampler(info), &device}
vkb::core::VulkanResourceCpp<vk::Sampler>{device.get_handle().createSampler(info), &device}
{}

HPPSampler::HPPSampler(HPPSampler &&other) :
Expand Down
2 changes: 1 addition & 1 deletion framework/core/hpp_sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace core
/**
* @brief Represents a Vulkan Sampler, using Vulkan-Hpp
*/
class HPPSampler : public vkb::core::VulkanResource<vkb::BindingType::Cpp, vk::Sampler>
class HPPSampler : public vkb::core::VulkanResourceCpp<vk::Sampler>
{
public:
/**
Expand Down
2 changes: 1 addition & 1 deletion framework/core/image_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace vkb
{
namespace core
{
class ImageView : public vkb::core::VulkanResource<vkb::BindingType::C, VkImageView>
class ImageView : public vkb::core::VulkanResourceC<VkImageView>
{
public:
ImageView(Image &image, VkImageViewType view_type, VkFormat format = VK_FORMAT_UNDEFINED,
Expand Down
2 changes: 1 addition & 1 deletion framework/core/render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct SubpassInfo
std::string debug_name;
};

class RenderPass : public vkb::core::VulkanResource<vkb::BindingType::C, VkRenderPass>
class RenderPass : public vkb::core::VulkanResourceC<VkRenderPass>
{
public:
RenderPass(Device &device,
Expand Down
2 changes: 1 addition & 1 deletion framework/core/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace core
/**
* @brief Represents a Vulkan Sampler
*/
class Sampler : public VulkanResource<vkb::BindingType::C, VkSampler>
class Sampler : public VulkanResourceC<VkSampler>
{
public:
/**
Expand Down
5 changes: 5 additions & 0 deletions framework/core/vulkan_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,10 @@ inline void VulkanResource<bindingType, Handle>::set_handle(Handle hdl)
{
handle = hdl;
}

template <typename Handle>
using VulkanResourceC = VulkanResource<vkb::BindingType::C, Handle>;
template <typename Handle>
using VulkanResourceCpp = VulkanResource<vkb::BindingType::Cpp, Handle>;
} // namespace core
} // namespace vkb
2 changes: 1 addition & 1 deletion framework/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ImGuiWindowFlags Gui::options_flags = Gui::common_flags;

const ImGuiWindowFlags Gui::info_flags = Gui::common_flags | ImGuiWindowFlags_NoInputs;

Gui::Gui(VulkanSample<vkb::BindingType::C> &sample_, const Window &window, const Stats *stats, const float font_size, bool explicit_update) :
Gui::Gui(VulkanSampleC &sample_, const Window &window, const Stats *stats, const float font_size, bool explicit_update) :
sample{sample_},
content_scale_factor{window.get_content_scale_factor()},
dpi_factor{window.get_dpi_factor() * content_scale_factor},
Expand Down
4 changes: 2 additions & 2 deletions framework/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Gui
* @param font_size The font size
* @param explicit_update If true, update buffers every frame
*/
Gui(VulkanSample<vkb::BindingType::C> &sample, const Window &window, const Stats *stats = nullptr, const float font_size = 21.0f, bool explicit_update = false);
Gui(VulkanSampleC &sample, const Window &window, const Stats *stats = nullptr, const float font_size = 21.0f, bool explicit_update = false);

/**
* @brief Destroys the Gui
Expand Down Expand Up @@ -270,7 +270,7 @@ class Gui

static const ImGuiWindowFlags info_flags;

VulkanSample<vkb::BindingType::C> &sample;
VulkanSampleC &sample;

std::unique_ptr<core::Buffer> vertex_buffer;

Expand Down
8 changes: 4 additions & 4 deletions framework/hpp_api_vulkan_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE

bool HPPApiVulkanSample::prepare(const vkb::ApplicationOptions &options)
{
if (!VulkanSample<vkb::BindingType::Cpp>::prepare(options))
if (!vkb::VulkanSampleCpp::prepare(options))
{
return false;
}
Expand Down Expand Up @@ -160,17 +160,17 @@ void HPPApiVulkanSample::create_render_context()
auto surface_priority_list = std::vector<vk::SurfaceFormatKHR>{{vk::Format::eB8G8R8A8Srgb, vk::ColorSpaceKHR::eSrgbNonlinear},
{vk::Format::eR8G8B8A8Srgb, vk::ColorSpaceKHR::eSrgbNonlinear}};

VulkanSample<vkb::BindingType::Cpp>::create_render_context(surface_priority_list);
vkb::VulkanSampleCpp::create_render_context(surface_priority_list);
}

void HPPApiVulkanSample::prepare_render_context()
{
VulkanSample<vkb::BindingType::Cpp>::prepare_render_context();
vkb::VulkanSampleCpp::prepare_render_context();
}

void HPPApiVulkanSample::input_event(const vkb::InputEvent &input_event)
{
VulkanSample<vkb::BindingType::Cpp>::input_event(input_event);
vkb::VulkanSampleCpp::input_event(input_event);

bool gui_captures_event = false;

Expand Down
2 changes: 1 addition & 1 deletion framework/hpp_api_vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct HPPVertex
*
* See vkb::ApiVulkanSample for documentation
*/
class HPPApiVulkanSample : public vkb::VulkanSample<vkb::BindingType::Cpp>
class HPPApiVulkanSample : public vkb::VulkanSampleCpp
{
public:
HPPApiVulkanSample() = default;
Expand Down
2 changes: 1 addition & 1 deletion framework/hpp_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ImGuiWindowFlags HPPGui::common_flags = ImGuiWindowFlags_NoMove |
const ImGuiWindowFlags HPPGui::options_flags = HPPGui::common_flags;
const ImGuiWindowFlags HPPGui::info_flags = HPPGui::common_flags | ImGuiWindowFlags_NoInputs;

HPPGui::HPPGui(VulkanSample<BindingType::Cpp> &sample_, const vkb::Window &window, const vkb::stats::HPPStats *stats, float font_size, bool explicit_update) :
HPPGui::HPPGui(VulkanSampleCpp &sample_, const vkb::Window &window, const vkb::stats::HPPStats *stats, float font_size, bool explicit_update) :
sample{sample_}, content_scale_factor{window.get_content_scale_factor()}, dpi_factor{window.get_dpi_factor() * content_scale_factor}, explicit_update{explicit_update}, stats_view(stats)
{
ImGui::CreateContext();
Expand Down
15 changes: 8 additions & 7 deletions framework/hpp_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace vkb
{
template <vkb::BindingType bindingType>
class VulkanSample;
using VulkanSampleCpp = VulkanSample<vkb::BindingType::Cpp>;

/**
* @brief Helper structure for fonts loaded from TTF
Expand Down Expand Up @@ -62,7 +63,7 @@ struct HPPFont
}

std::vector<uint8_t> data;
ImFont *handle = nullptr;
ImFont *handle = nullptr;
std::string name;
float size = 0.0f;
};
Expand Down Expand Up @@ -117,11 +118,11 @@ class HPPGui
* @param font_size The font size
* @param explicit_update If true, update buffers every frame
*/
HPPGui(VulkanSample<vkb::BindingType::Cpp> &sample,
const vkb::Window &window,
const vkb::stats::HPPStats *stats = nullptr,
float font_size = 21.0f,
bool explicit_update = false);
HPPGui(VulkanSampleCpp &sample,
const vkb::Window &window,
const vkb::stats::HPPStats *stats = nullptr,
float font_size = 21.0f,
bool explicit_update = false);

/**
* @brief Destroys the HPPGui
Expand Down Expand Up @@ -258,7 +259,7 @@ class HPPGui

private:
PushConstBlock push_const_block;
VulkanSample<vkb::BindingType::Cpp> &sample;
VulkanSampleCpp &sample;
std::unique_ptr<vkb::core::HPPBuffer> vertex_buffer;
std::unique_ptr<vkb::core::HPPBuffer> index_buffer;
size_t last_vertex_buffer_size = 0;
Expand Down
4 changes: 2 additions & 2 deletions framework/platform/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ void Platform::update()
});
active_app->update(delta_time);

if (auto *app = dynamic_cast<VulkanSample<vkb::BindingType::Cpp> *>(active_app.get()))
if (auto *app = dynamic_cast<VulkanSampleCpp *>(active_app.get()))
{
if (app->has_render_context())
{
on_post_draw(reinterpret_cast<vkb::RenderContext &>(app->get_render_context()));
}
}
else if (auto *app = dynamic_cast<VulkanSample<vkb::BindingType::C> *>(active_app.get()))
else if (auto *app = dynamic_cast<VulkanSampleC *>(active_app.get()))
{
if (app->has_render_context())
{
Expand Down
5 changes: 4 additions & 1 deletion framework/vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ inline void VulkanSample<bindingType>::create_gui(const Window &window, StatsTyp
else
{
gui = std::make_unique<vkb::HPPGui>(
*reinterpret_cast<VulkanSample<vkb::BindingType::Cpp> *>(this), window, reinterpret_cast<vkb::stats::HPPStats const *>(stats), font_size, explicit_update);
*reinterpret_cast<VulkanSampleCpp *>(this), window, reinterpret_cast<vkb::stats::HPPStats const *>(stats), font_size, explicit_update);
}
}

Expand Down Expand Up @@ -1366,4 +1366,7 @@ inline void VulkanSample<bindingType>::update_stats(float delta_time)
}
}

using VulkanSampleC = VulkanSample<vkb::BindingType::C>;
using VulkanSampleCpp = VulkanSample<vkb::BindingType::Cpp>;

} // namespace vkb
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void HPPOITDepthPeeling::update_scene_constants()

////////////////////////////////////////////////////////////////////////////////

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::Cpp>> create_hpp_oit_depth_peeling()
std::unique_ptr<vkb::VulkanSampleCpp> create_hpp_oit_depth_peeling()
{
return std::make_unique<HPPOITDepthPeeling>();
}
2 changes: 1 addition & 1 deletion samples/api/hpp_oit_depth_peeling/hpp_oit_depth_peeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ class HPPOITDepthPeeling : public HPPApiVulkanSample
std::unique_ptr<vkb::core::HPPBuffer> scene_constants = {};
};

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::Cpp>> create_hpp_oit_depth_peeling();
std::unique_ptr<vkb::VulkanSampleCpp> create_hpp_oit_depth_peeling();
2 changes: 1 addition & 1 deletion samples/api/oit_depth_peeling/oit_depth_peeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void OITDepthPeeling::update_scene_constants()

////////////////////////////////////////////////////////////////////////////////

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_oit_depth_peeling()
std::unique_ptr<vkb::VulkanSampleC> create_oit_depth_peeling()
{
return std::make_unique<OITDepthPeeling>();
}
2 changes: 1 addition & 1 deletion samples/api/oit_depth_peeling/oit_depth_peeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ class OITDepthPeeling : public ApiVulkanSample
int32_t back_layer_index = kLayerMaxCount - 1;
};

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_oit_depth_peeling();
std::unique_ptr<vkb::VulkanSampleC> create_oit_depth_peeling();
2 changes: 1 addition & 1 deletion samples/api/oit_linked_lists/oit_linked_lists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ void OITLinkedLists::fill_instance_data()

////////////////////////////////////////////////////////////////////////////////

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_oit_linked_lists()
std::unique_ptr<vkb::VulkanSampleC> create_oit_linked_lists()
{
return std::make_unique<OITLinkedLists>();
}
2 changes: 1 addition & 1 deletion samples/api/oit_linked_lists/oit_linked_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ class OITLinkedLists : public ApiVulkanSample
float background_grayscale = 0.3f;
};

std::unique_ptr<vkb::VulkanSample<vkb::BindingType::C>> create_oit_linked_lists();
std::unique_ptr<vkb::VulkanSampleC> create_oit_linked_lists();
Loading

0 comments on commit b115112

Please sign in to comment.