mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "vk/core/instance.hpp"
|
|
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
#include <optional>
|
|
#include <cstdint>
|
|
#include <bitset>
|
|
#include <memory>
|
|
|
|
namespace VK::Core {
|
|
|
|
// FIXME: The toggle for fp32 shouldn't be implemented here.
|
|
// FIXME: Device UUID needs an overhaul.
|
|
|
|
///
|
|
/// 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 uuid The UUID of the Vulkan device to use.
|
|
/// @param enforceFP32 Whether to enforce FP32 support even if FP16 is available.
|
|
///
|
|
/// @throws VK::vulkan_error if object creation fails.
|
|
///
|
|
Device(const Instance& instance, uint64_t uuid, bool enforceFP32);
|
|
|
|
///
|
|
/// Find a suitable memory type.
|
|
///
|
|
/// @param validTypes A bitset representing the valid memory types.
|
|
/// @param hostVisible Whether the memory should be host visible.
|
|
///
|
|
/// @return The index of a suitable memory type, or std::nullopt if none found.
|
|
///
|
|
[[nodiscard]] std::optional<uint32_t> findMemoryType(
|
|
std::bitset<32> validTypes, bool hostVisible = false) const;
|
|
|
|
/// Get the Vulkan handle.
|
|
[[nodiscard]] auto handle() const { return *this->device; }
|
|
|
|
/// Get the physical device associated with this logical device.
|
|
[[nodiscard]] auto getPhysicalDevice() const { return this->physicalDevice; }
|
|
/// Get the compute queue.
|
|
[[nodiscard]] auto getComputeQueue() const { return this->computeQueue; }
|
|
|
|
/// Get the compute queue family index.
|
|
[[nodiscard]] auto getComputeFamilyIdx() const { return this->computeFamilyIdx; }
|
|
/// Check if the device supports FP16.
|
|
[[nodiscard]] auto supportsFP16() const { return this->fp16; }
|
|
private:
|
|
std::shared_ptr<VkDevice> device;
|
|
|
|
VkPhysicalDevice physicalDevice{};
|
|
VkQueue computeQueue{};
|
|
|
|
uint32_t computeFamilyIdx{0};
|
|
bool fp16{false};
|
|
|
|
};
|
|
|
|
}
|