lsfg-vk/framegen/include/core/device.hpp
2025-08-12 20:30:34 +02:00

56 lines
1.8 KiB
C++

#pragma once
#include "core/instance.hpp"
#include <vulkan/vulkan_core.h>
#include <cstdint>
#include <memory>
namespace LSFG::Core {
///
/// C++ wrapper class for a Vulkan device.
///
/// This class manages the lifetime of a Vulkan device.
///
class Device {
public:
///
/// Create the device.
///
/// @param instance Vulkan instance
/// @param deviceUUID The UUID of the Vulkan device to use.
///
/// @throws LSFG::vulkan_error if object creation fails.
///
Device(const Instance& instance, uint64_t deviceUUID);
/// Get the Vulkan handle.
[[nodiscard]] auto handle() const { return *this->device; }
/// Get the physical device associated with this logical device.
[[nodiscard]] VkPhysicalDevice getPhysicalDevice() const { return this->physicalDevice; }
/// Get the compute queue family index.
[[nodiscard]] uint32_t getComputeFamilyIdx() const { return this->computeFamilyIdx; }
/// Get the compute queue.
[[nodiscard]] VkQueue getComputeQueue() const { return this->computeQueue; }
/// Check if the device supports FP16.
[[nodiscard]] bool getFP16Support() const { return this->supportsFP16; }
// Trivially copyable, moveable and destructible
Device(const Core::Device&) noexcept = default;
Device& operator=(const Core::Device&) noexcept = default;
Device(Device&&) noexcept = default;
Device& operator=(Device&&) noexcept = default;
~Device() = default;
private:
std::shared_ptr<VkDevice> device;
VkPhysicalDevice physicalDevice{};
uint32_t computeFamilyIdx{0};
bool supportsFP16{false};
VkQueue computeQueue{};
};
}