通用图元(线/箭头四翼头/球/胶囊/盒)瞬时+持久双缓冲聚合; 物理 pass 画刚体速度/重力/接触反力;角色 collider 与力学 线归位(引擎只画资产、脚本画行为);线宽按设备上限钳制
102 lines
3.5 KiB
C++
102 lines
3.5 KiB
C++
//
|
||
// Created by atdunbg on 2026/9/20.
|
||
//
|
||
|
||
#ifndef HELLOVULKAN_DEVICE_H
|
||
#define HELLOVULKAN_DEVICE_H
|
||
|
||
|
||
#include <vulkan/vulkan.hpp>
|
||
#include <vector>
|
||
|
||
namespace Engine {
|
||
|
||
class Window;
|
||
|
||
class Device {
|
||
public:
|
||
Device(Window& window);
|
||
~Device();
|
||
|
||
Device(const Device&) = delete;
|
||
Device& operator=(const Device&) = delete;
|
||
|
||
vk::Instance GetInstance() const { return m_Instance; }
|
||
vk::PhysicalDevice GetPhysicalDevice() const { return m_PhysicalDevice; }
|
||
vk::Device GetDevice() const { return m_Device; }
|
||
vk::SurfaceKHR GetSurface() const { return m_Surface; }
|
||
|
||
vk::Queue GetGraphicsQueue() const { return m_GraphicsQueue; }
|
||
vk::Queue GetPresentQueue() const { return m_PresentQueue; }
|
||
|
||
uint32_t GetGraphicsFamily() const { return m_GraphicsFamily; }
|
||
uint32_t GetPresentFamily() const { return m_PresentFamily; }
|
||
|
||
uint32_t FindMemoryType(uint32_t typeFilter, vk::MemoryPropertyFlags props) const;
|
||
|
||
// 在候选列表中找到第一个满足 tiling+features 的格式,找不到则 FATAL
|
||
vk::Format FindSupportedFormat(const std::vector<vk::Format>& candidates,
|
||
vk::ImageTiling tiling,
|
||
vk::FormatFeatureFlags features) const;
|
||
|
||
// 1.4 特性查询
|
||
bool IsDynamicRenderingSupported() const { return m_DynamicRenderingSupported; }
|
||
bool IsShaderObjectSupported() const { return m_ShaderObjectSupported; }
|
||
bool IsSynchronization2Supported() const { return m_Synchronization2Supported; }
|
||
// MDI:drawCount>1 的 drawIndexedIndirect(Count) 必需(core 特性位)
|
||
bool IsMultiDrawIndirectSupported() const { return m_MultiDrawIndirectSupported; }
|
||
// 各向异性过滤:纹理采样器清晰度(掠射角材质锐利度)的硬件开关
|
||
bool IsSamplerAnisotropySupported() const { return m_SamplerAnisotropySupported; }
|
||
float MaxSamplerAnisotropy() const { return m_MaxSamplerAnisotropy; }
|
||
bool IsWideLinesSupported() const { return m_WideLinesSupported; }
|
||
float MaxLineWidth() const { return m_MaxLineWidth; }
|
||
|
||
private:
|
||
void CreateInstance();
|
||
void SetupDebugMessenger();
|
||
void CreateSurface(Window& window);
|
||
void PickPhysicalDevice();
|
||
void CreateLogicalDevice();
|
||
|
||
bool IsDeviceSuitable(vk::PhysicalDevice device);
|
||
bool CheckValidationLayerSupport();
|
||
|
||
vk::Instance m_Instance;
|
||
vk::DebugUtilsMessengerEXT m_DebugMessenger;
|
||
vk::SurfaceKHR m_Surface;
|
||
vk::PhysicalDevice m_PhysicalDevice;
|
||
vk::Device m_Device;
|
||
|
||
vk::Queue m_GraphicsQueue;
|
||
vk::Queue m_PresentQueue;
|
||
|
||
uint32_t m_GraphicsFamily = 0;
|
||
uint32_t m_PresentFamily = 0;
|
||
|
||
vk::PhysicalDeviceMemoryProperties m_MemoryProperties;
|
||
|
||
// 1.4 特性标志
|
||
bool m_DynamicRenderingSupported = false;
|
||
bool m_ShaderObjectSupported = false;
|
||
bool m_Synchronization2Supported = false;
|
||
bool m_MultiDrawIndirectSupported = false;
|
||
bool m_DrawIndirectCountSupported = false;
|
||
bool m_SamplerAnisotropySupported = false;
|
||
float m_MaxSamplerAnisotropy = 1.0f;
|
||
bool m_WideLinesSupported = false;
|
||
float m_MaxLineWidth = 1.0f; // 设备线宽上限(像素,limits.lineWidthRange[1])
|
||
|
||
std::vector<const char*> m_ValidationLayers = { "VK_LAYER_KHRONOS_validation" };
|
||
std::vector<const char*> m_DeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
|
||
|
||
#ifdef NDEBUG
|
||
static constexpr bool kEnableValidation = false;
|
||
#else
|
||
static constexpr bool kEnableValidation = true;
|
||
#endif
|
||
};
|
||
|
||
} // namespace Engine
|
||
|
||
#endif //HELLOVULKAN_DEVICE_H
|