Class VulkanDevice¶
Defined in File vulkan_device.h
Nested Relationships¶
Nested Types¶
Inheritance Relationships¶
Base Type¶
public portal::renderer::Device(Class Device)
Class Documentation¶
-
class VulkanDevice : public portal::renderer::Device¶
Logical Vulkan device with resource creation, command submission, and synchronization.
Creates the logical device from a physical device, manages queue family setup, and provides resource creation methods (buffers, images, pipelines, etc.). Maintains an immediate command buffer for synchronous GPU operations and a pipeline cache for PSO reuse.
Initialization:
Creates queues (graphics, compute, transfer, optionally present)
Initializes immediate command buffer (command pool + buffer + fence)
Creates empty pipeline cache
Enables debug markers (VK_EXT_debug_utils) if available
Public Types
Public Functions
-
VulkanDevice(const VulkanPhysicalDevice &physical_device, const VulkanPhysicalDevice::Features &device_features)¶
Creates logical device with specified features.
- Parameters:
physical_device – The physical device (GPU)
device_features – Feature chain to enable
-
void add_present_queue(Surface &surface)¶
Adds present queue for surface presentation.
- Parameters:
surface – The surface to present to
-
AllocatedBuffer create_buffer(const BufferBuilder &builder) const¶
Creates VMA-allocated buffer.
- Parameters:
builder – Buffer builder with size, usage, and VMA options
- Returns:
Creates VMA-allocated buffer in shared_ptr.
- Parameters:
builder – Buffer builder
- Returns:
Shared pointer to AllocatedBuffer
-
ImageAllocation create_image(const ImageBuilder &builder) const¶
Creates VMA-allocated image.
- Parameters:
builder – Image builder with extent, format, usage, and VMA options
- Returns:
-
vk::ImageView create_image_view(const vk::ImageViewCreateInfo &info) const¶
Creates image view.
-
void destory_image_view(vk::ImageView image_view) const¶
-
vk::raii::Sampler create_sampler(const vk::SamplerCreateInfo &info) const¶
Creates sampler.
-
vk::raii::DescriptorSetLayout create_descriptor_set_layout(portal::renderer::vulkan::DescriptorLayoutBuilder &builder) const¶
Creates descriptor set layout.
- Parameters:
builder – Descriptor layout builder
- Returns:
Descriptor set layout handle
-
vk::raii::PipelineLayout create_pipeline_layout(const vk::PipelineLayoutCreateInfo &pipeline_layout_info) const¶
Creates pipeline layout.
-
vk::raii::ShaderModule create_shader_module(const Buffer &code) const¶
Creates shader module from SPIR-V bytecode.
- Parameters:
code – SPIR-V bytecode buffer
- Returns:
Shader module handle
-
vk::raii::Pipeline create_pipeline(vulkan::PipelineBuilder &builder) const¶
Creates graphics or compute pipeline.
-
void immediate_submit(std::function<void(const vk::raii::CommandBuffer&)> &&function) const¶
Submits commands synchronously (waits for completion)
Flow:
Resets fence and command buffer
Begins command buffer
Executes function (records commands)
Ends command buffer
Submits to graphics queue with fence
Waits for fence (blocks until completion)
Used for one-off operations like initial texture uploads.
- Parameters:
function – Lambda receiving command buffer for recording
-
void wait_for_fences(vk::ArrayProxy<const vk::Fence> fences, bool wait_all, size_t timeout = std::numeric_limits<size_t>::max()) const¶
Waits for one or more fences to be signaled or until the timeout expires.
This method is used to synchronize the execution of the application with the GPU by waiting for specified fences to achieve the signaled state. This can be helpful in ensuring that GPU operations are completed before the application progresses further.
- Parameters:
fenceHandles – A list of fence handles to wait on. These fences must have been created and submitted prior to the invocation of this method.
timeout – The maximum amount of time, in nanoseconds, to wait for the fences to become signaled. A value of UINT64_MAX can be used to wait indefinitely.
waitAll – A boolean value indicating whether the function should wait for all of the specified fences to be signaled (true) or any one fence to be signaled (false).
- Returns:
Returns a success or timeout result indicating whether the operation completed successfully, timed out, or encountered an error.
-
virtual void wait_idle() const¶
Waits for all device operations to complete.
-
inline vk::raii::Device &get_handle()¶
Gets device handle (mutable)
-
inline const vk::raii::Device &get_handle() const¶
Gets device handle (const)
-
const VulkanQueue &get_graphics_queue() const¶
Gets graphics queue.
-
const VulkanQueue &get_compute_queue() const¶
Gets compute queue.
-
const VulkanQueue &get_transfer_queue() const¶
Gets transfer queue.
-
const VulkanQueue &get_present_queue() const¶
Gets present queue.
-
template<typename T>
inline void set_debug_name(const T &handle, StringId name) const¶ Sets debug name using StringId.
- Parameters:
handle – Vulkan handle
name – Debug name as StringId
-
template<typename T>
inline void set_debug_name(const T &handle, const char *name) const¶ Sets debug name for Vulkan object (handles both RAII and plain handles)
- Parameters:
handle – Vulkan handle (vk::Buffer or vk::raii::Buffer)
name – Debug name (appears in GPU debuggers)
-
void set_debug_name(vk::ObjectType type, uint64_t handle, const char *name) const¶
Sets debug name (low-level)
- Parameters:
type – Vulkan object type
handle – Handle as uint64_t
name – Debug name