Skip to content

Commit dd539ca

Browse files
authored
[merge] Merge pull request #455 from inexorgame/hanni/vulkan_function_wrappers
Refactoring: Introduce wrapper functions for Vulkan create methods
2 parents 20add16 + 2994c26 commit dd539ca

20 files changed

+296
-145
lines changed

include/inexor/vulkan-renderer/render_graph.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class RenderResource : public RenderGraphObject {
7070

7171
RenderResource &operator=(const RenderResource &) = delete;
7272
RenderResource &operator=(RenderResource &&) = delete;
73+
74+
[[nodiscard]] const std::string &name() const {
75+
return m_name;
76+
}
7377
};
7478

7579
enum class BufferUsage {
@@ -197,6 +201,10 @@ class RenderStage : public RenderGraphObject {
197201
m_push_constant_ranges.push_back(range);
198202
}
199203

204+
[[nodiscard]] const std::string &name() const {
205+
return m_name;
206+
}
207+
200208
/// @brief Specifies a function that will be called during command buffer recording for this stage
201209
/// @details This function can be used to specify other vulkan commands during command buffer recording. The most
202210
/// common use for this is for draw commands.

include/inexor/vulkan-renderer/wrapper/command_pool.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Device;
1111

1212
/// @brief RAII wrapper class for VkCommandPool.
1313
class CommandPool {
14+
std::string m_name;
1415
const Device &m_device;
1516
VkCommandPool m_command_pool{VK_NULL_HANDLE};
1617

@@ -19,9 +20,10 @@ class CommandPool {
1920
/// @note It is important that the queue family index is specified in the abstraction above this command pool
2021
/// wrapper. We can't choose one queue family index automatically inside of this wrapper which fits every purpose,
2122
/// because some wrappers require a queue family index which supports graphics bit, other require transfer bit.
22-
/// @param device The const reference to the device RAII wrapper class.
23-
/// @param queue_family_index The queue family index which is used by this command pool.
24-
CommandPool(const Device &device, std::uint32_t queue_family_index);
23+
/// @param device The const reference to the device RAII wrapper class
24+
/// @param queue_family_index The queue family index which is used by this command pool
25+
/// @param name The internal debug marker name which will be assigned to this command pool
26+
CommandPool(const Device &device, std::uint32_t queue_family_index, std::string name);
2527

2628
CommandPool(const CommandPool &) = delete;
2729
CommandPool(CommandPool &&) noexcept;

include/inexor/vulkan-renderer/wrapper/cpu_texture.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CpuTexture {
3939
CpuTexture &operator=(const CpuTexture &) = delete;
4040
CpuTexture &operator=(CpuTexture &&) = default;
4141

42-
[[nodiscard]] std::string name() const {
42+
[[nodiscard]] const std::string &name() const {
4343
return m_name;
4444
}
4545

include/inexor/vulkan-renderer/wrapper/device.hpp

Lines changed: 124 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,32 @@ class Device {
4141

4242
public:
4343
/// @brief Check if a certain device extension is available for a specific graphics card.
44-
/// @param graphics_card The graphics card.
45-
/// @param extension The name of the device extension.
46-
/// @return ``true`` if the requested device extension is available.
44+
/// @param graphics_card The graphics card
45+
/// @param extension The name of the device extension
46+
/// @return ``true`` if the requested device extension is available
4747
[[nodiscard]] static bool is_extension_supported(VkPhysicalDevice graphics_card, const std::string &extension);
4848

4949
/// @brief Check if a swapchain is available for a specific graphics card.
50-
/// @param graphics_card The graphics card.
51-
/// @return ``true`` if swapchain is supported.
50+
/// @param graphics_card The graphics card
51+
/// @return ``true`` if swapchain is supported
5252
[[nodiscard]] static bool is_swapchain_supported(VkPhysicalDevice graphics_card);
5353

5454
/// @brief Check if presentation is available for a specific combination of graphics card and surface.
55-
/// @param graphics_card The graphics card.
56-
/// @param surface The (window) surface.
57-
/// @return ``true`` if presentation is supported.
55+
/// @param graphics_card The graphics card
56+
/// @param surface The window surface
57+
/// @return ``true`` if presentation is supported
5858
[[nodiscard]] static bool is_presentation_supported(VkPhysicalDevice graphics_card, VkSurfaceKHR surface);
5959

6060
/// @brief Default constructor.
61-
/// @param instance The instance wrapper from which the device will be created.
62-
/// @param surface The surface which will be associated with the device.
63-
/// @param enable_vulkan_debug_markers True if Vulkan debug markers should be enabled, false otherwise.
64-
/// @param prefer_distinct_transfer_queue True if a distinct data transfer queue (if available) should be
65-
/// enabled, false otherwise.
61+
/// @param instance The instance wrapper from which the device will be created
62+
/// @param surface The surface which will be associated with the device
63+
/// @param enable_vulkan_debug_markers ``true`` if Vulkan debug markers should be enabled
64+
/// @param prefer_distinct_transfer_queue ``true`` if a distinct data transfer queue should be preferred
6665
/// @param preferred_physical_device_index The index of the preferred graphics card which should be used,
6766
/// starting from 0. If the graphics card index is invalid or if the graphics card is unsuitable for the
6867
/// application's purpose, another graphics card will be selected automatically. See the details of the device
69-
/// selection mechanism!
70-
/// @todo Add overloaded constructors for VkPhysicalDeviceFeatures and requested device extensions in the
71-
/// future!
68+
/// selection mechanism.
69+
/// TODO: Add overloaded constructors for VkPhysicalDeviceFeatures and requested device extensions
7270
Device(const wrapper::Instance &instance, VkSurfaceKHR surface, bool enable_vulkan_debug_markers,
7371
bool prefer_distinct_transfer_queue,
7472
std::optional<std::uint32_t> preferred_physical_device_index = std::nullopt);
@@ -126,39 +124,131 @@ class Device {
126124
/// @brief Assign an internal Vulkan debug marker name to a Vulkan object.
127125
/// This internal name can be seen in external debuggers like RenderDoc.
128126
/// @note This method is only available in debug mode with ``VK_EXT_debug_marker`` device extension enabled.
129-
/// @param object The Vulkan object.
130-
/// @param object_type The Vulkan debug report object type.
131-
/// @param name The internal name of the Vulkan object.
127+
/// @param object The Vulkan object
128+
/// @param object_type The Vulkan debug report object type
129+
/// @param name The internal name of the Vulkan object
132130
void set_debug_marker_name(void *object, VkDebugReportObjectTypeEXT object_type, const std::string &name) const;
133131

134132
/// @brief Assigns a block of memory to a Vulkan resource.
135133
/// This memory block can be seen in external debuggers like RenderDoc.
136134
/// @note This method is only available in debug mode with ``VK_EXT_debug_marker`` device extension enabled.
137-
/// @param object The Vulkan object.
138-
/// @param object_type The Vulkan debug report object type.
139-
/// @param name The name of the memory block which will be connected to this object.
140-
/// @param memory_size The size of the memory block in bytes.
141-
/// @param memory_address The memory address to read from.
135+
/// @param object The Vulkan object
136+
/// @param object_type The Vulkan debug report object type
137+
/// @param name The name of the memory block which will be connected to this object
138+
/// @param memory_size The size of the memory block in bytes
139+
/// @param memory_block The memory block to read from
142140
void set_memory_block_attachment(void *object, VkDebugReportObjectTypeEXT object_type, std::uint64_t name,
143141
std::size_t memory_size, const void *memory_block) const;
144142

145-
/// @param color [in] The rgba color of the rendering region.
146-
/// @param name [in] The name of the rendering region.
147-
/// @param command_buffer [in] The associated command buffer.
148-
/// The rendering region will be visible in external debuggers like RenderDoc.
149143
/// @brief Vulkan debug markers: Annotation of a rendering region.
144+
/// The rendering region will be visible in external debuggers like RenderDoc.
145+
/// @param command_buffer The associated command buffer
146+
/// @param name The name of the rendering region
147+
/// @param color The rgba color of the rendering region
150148
void bind_debug_region(VkCommandBuffer command_buffer, const std::string &name, std::array<float, 4> color) const;
151149

152-
/// @brief Insert a debug markers into the current renderpass using vkCmdDebugMarkerInsertEXT. This debug
153-
/// markers can be seen in external debuggers like RenderDoc.
154-
/// @param command_buffer The command buffer which is associated to the debug marker.
155-
/// @param name The name of the debug marker.
156-
/// @param color An array of red, green, blue and alpha values for the debug region's color.
150+
/// @brief Insert a debug markers into the current renderpass using vkCmdDebugMarkerInsertEXT.
151+
/// This debug markers can be seen in external debuggers like RenderDoc.
152+
/// @param command_buffer The command buffer which is associated to the debug marker
153+
/// @param name The name of the debug marker
154+
/// @param color An array of red, green, blue and alpha values for the debug region's color
157155
void insert_debug_marker(VkCommandBuffer command_buffer, const std::string &name, std::array<float, 4> color) const;
158156

159157
/// @brief End the debug region of the current renderpass using vkCmdDebugMarkerEndEXT.
160-
/// @param command_buffer The command buffer which is associated to the debug marker.
158+
/// @param command_buffer The command buffer which is associated to the debug marker
161159
void end_debug_region(VkCommandBuffer command_buffer) const;
160+
161+
/// @brief Call vkCreateCommandPool
162+
/// @param command_pool_ci The command pool create info structure
163+
/// @param command_pool The command pool to create
164+
/// @param name The internal debug marker name which will be assigned to this command pool
165+
void create_command_pool(const VkCommandPoolCreateInfo &command_pool_ci, VkCommandPool *command_pool,
166+
const std::string &name) const;
167+
168+
/// @brief Call vkCreateDescriptorPool
169+
/// @param descriptor_pool_ci The descriptor pool create info structure
170+
/// @param descriptor_pool The descriptor pool to create
171+
/// @param name The internal debug marker name which will be assigned to this command pool
172+
void create_descriptor_pool(const VkDescriptorPoolCreateInfo &descriptor_pool_ci, VkDescriptorPool *descriptor_pool,
173+
const std::string &name) const;
174+
175+
/// @brief Call vkCreateDescriptorSetLayout
176+
/// @param descriptor_set_layout_ci The descriptor set layout create info structure
177+
/// @param descriptor_set_layout The descriptor set layout to create
178+
/// @param name The internal debug marker name which will be assigned to this descriptor set layout
179+
void create_descriptor_set_layout(const VkDescriptorSetLayoutCreateInfo &descriptor_set_layout_ci,
180+
VkDescriptorSetLayout *descriptor_set_layout, const std::string &name) const;
181+
182+
/// @brief Call vkCreateFence
183+
/// @param fence_ci The fence create info structure
184+
/// @param fence The fence to create
185+
/// @param name The internal debug marker name which will be assigned to this fence
186+
void create_fence(const VkFenceCreateInfo &fence_ci, VkFence *fence, const std::string &name) const;
187+
188+
/// @brief Call vkCreateFramebuffer
189+
/// @param framebuffer_ci The framebuffer create info structure
190+
/// @param framebuffer The Vulkan framebuffer to create
191+
/// @param name The internal debug marker name which will be assigned to this framebuffer
192+
void create_framebuffer(const VkFramebufferCreateInfo &framebuffer_ci, VkFramebuffer *framebuffer,
193+
const std::string &name) const;
194+
195+
/// @brief Call vkCreateGraphicsPipelines
196+
/// @param pipeline_ci The graphics pipeline create info structure
197+
/// @param pipeline The graphics pipeline to create
198+
/// @param name The internal debug marker name which will be assigned to this pipeline
199+
// TODO: Offer parameter for Vulkan pipeline caches!
200+
// TODO: Use std::span to offer a more general method (creating multiple pipelines with one call)
201+
// TODO: We might want to use std::span<std::pair<VkGraphicsPipelineCreateInfo, VkPipeline *>>
202+
void create_graphics_pipeline(const VkGraphicsPipelineCreateInfo &pipeline_ci, VkPipeline *pipeline,
203+
const std::string &name) const;
204+
205+
/// @brief Call vkCreateImageView
206+
/// @param image_view_ci The image view create info structure
207+
/// @param image_view The image view to create
208+
/// @param name The internal debug marker name which will be assigned to this image view
209+
void create_image_view(const VkImageViewCreateInfo &image_view_ci, VkImageView *image_view,
210+
const std::string &name) const;
211+
212+
/// @brief Call vkCreatePipelineLayout
213+
/// @param pipeline_layout_ci The pipeline layout create info structure
214+
/// @param pipeline_layout The pipeline layout to create
215+
/// @param name The internal debug marker name which will be assigned to this pipeline layout
216+
void create_pipeline_layout(const VkPipelineLayoutCreateInfo &pipeline_layout_ci, VkPipelineLayout *pipeline_layout,
217+
const std::string &name) const;
218+
219+
/// @brief Call vkCreateRenderPass
220+
/// @param render_pass_ci The render pass create info structure
221+
/// @param render_pass The render pass to create
222+
/// @param name The internal debug marker name which will be assigned to this render pass
223+
void create_render_pass(const VkRenderPassCreateInfo &render_pass_ci, VkRenderPass *render_pass,
224+
const std::string &name) const;
225+
226+
/// @brief Call vkCreateSampler
227+
/// @param sampler_ci The sampler create info structure
228+
/// @param sampler The sampler to create
229+
/// @param name The internal debug marker name which will be assigned to this sampler
230+
void create_sampler(const VkSamplerCreateInfo &sampler_ci, VkSampler *sampler, const std::string &name) const;
231+
232+
/// @brief Call vkCreateSemaphore
233+
/// @param semaphore_ci The semaphore create info structure
234+
/// @param semaphore The semaphore to create
235+
/// @param name The internal debug marker name which will be assigned to this semaphore
236+
void create_semaphore(const VkSemaphoreCreateInfo &semaphore_ci, VkSemaphore *semaphore,
237+
const std::string &name) const;
238+
239+
/// @brief Call vkCreateShaderModule
240+
/// @param shader_module_ci The shader module create info structure
241+
/// @param shader_module The shader module to create
242+
/// @param name The internal debug marker name which will be assigned to this shader module
243+
void create_shader_module(const VkShaderModuleCreateInfo &shader_module_ci, VkShaderModule *shader_module,
244+
const std::string &name) const;
245+
246+
/// @brief Call vkCreateSwapchainKHR
247+
/// @param swapchain_ci The swapchain_ci create info structure
248+
/// @param swapchain The swapchain to create
249+
/// @param name The internal debug marker name which will be assigned to this swapchain
250+
void create_swapchain(const VkSwapchainCreateInfoKHR &swapchain_ci, VkSwapchainKHR *swapchain,
251+
const std::string &name) const;
162252
};
163253

164254
} // namespace inexor::vulkan_renderer::wrapper

include/inexor/vulkan-renderer/wrapper/gpu_texture.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GpuTexture {
7474
GpuTexture &operator=(const GpuTexture &) = delete;
7575
GpuTexture &operator=(GpuTexture &&) = delete;
7676

77-
[[nodiscard]] std::string name() const {
77+
[[nodiscard]] const std::string &name() const {
7878
return m_name;
7979
}
8080

include/inexor/vulkan-renderer/wrapper/once_command_buffer.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Device;
1919
/// tell the driver about our intent using VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT.
2020
class OnceCommandBuffer {
2121
const Device &m_device;
22+
std::string m_name;
2223
// We must store the VkQueue separately since we don't know from
2324
// the context of the use of this OnceCommandBuffer which queue to use!
2425
VkQueue m_queue{VK_NULL_HANDLE};
@@ -32,10 +33,11 @@ class OnceCommandBuffer {
3233
/// @param device The const reference to a device RAII wrapper instance.
3334
/// @param queue The Vulkan queue to use.
3435
/// @param queue_family_index The Vulkan queue family index to use.
36+
/// @param name The internal debug marker name which will be assigned to this command buffer
3537
/// @warn We can't determine the queue and queue family index to use automatically using the device wrapper
3638
/// reference because we might choose a queue which is unsuitable for the requested purpose!
3739
/// This is the reason we must specify the queue and queue family index in the constructor.
38-
OnceCommandBuffer(const Device &device, VkQueue queue, std::uint32_t queue_family_index);
40+
OnceCommandBuffer(const Device &device, VkQueue queue, std::uint32_t queue_family_index, const std::string &name);
3941

4042
OnceCommandBuffer(const OnceCommandBuffer &) = delete;
4143
OnceCommandBuffer(OnceCommandBuffer &&) noexcept;

src/vulkan-renderer/application.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ Application::Application(int argc, char **argv) {
483483
load_textures();
484484
load_shaders();
485485

486-
m_command_pool = std::make_unique<wrapper::CommandPool>(*m_device, m_device->graphics_queue_family_index());
486+
m_command_pool =
487+
std::make_unique<wrapper::CommandPool>(*m_device, m_device->graphics_queue_family_index(), "command pool");
487488

488489
m_uniform_buffers.emplace_back(*m_device, "matrices uniform buffer", sizeof(UniformBufferObject));
489490

0 commit comments

Comments
 (0)