29#define CE_VK_SAFE_CAST
32#if defined(CE_VK_PROFILING)
33#define CE_VK_PROFILE_FUNC CE_PROFILE_FUNC
35#define CE_VK_PROFILE_FUNC
39#if defined(CE_VK_GPU_PROFILING)
43#include <TracyVulkan.hpp>
46#if CE_PLATFORM_MAC || CE_PLATFORM_IOS
47#define CE_VK_CHECK_PTR(P) true
49#define CE_VK_CHECK_PTR(P) (P != nullptr)
65 template<
typename T>
static VKObjectAllocator VKMakeObjectAllocator(
const std::size_t initialSize = 100) {
68 sizeof(
T) * initialSize,
75#define CE_VK_RENDER_API_OBJECT_FORWARD(N) \
77 using VK##N##Ptr = RC<VK##N>;
79#undef CE_VK_RENDER_API_OBJECT_FORWARD
81#if defined(CE_VK_SAFE_CAST)
82#define CE_VK_CAST dynamic_cast
84#define CE_VK_CAST static_cast
89 static void*
operator new(
size_t size)
noexcept;
90 static void operator delete(
void* p, std::size_t sz)
noexcept;
105 static ChildTypeName&
cast(ParentType&
object) {
return CE_VK_CAST<ChildTypeName&>(
object); }
111 static const ChildTypeName&
cast(
const ParentType&
object) {
return CE_VK_CAST<const ChildTypeName&>(
object); }
117 static ChildTypeName*
cast(ParentType*
object) {
return CE_VK_CAST<ChildTypeName*>(
object); }
123 static const ChildTypeName*
cast(
const ParentType*
object) {
return CE_VK_CAST<const ChildTypeName*>(
object); }
126 template<
typename ChildTypeName>
class VKObject<ChildTypeName, void> {};
142 template<typename ChildTypeName, typename ParentType =
void>
154 template<
typename ObjectType,
typename OwnerType = VKDevice,
typename DescriptorType =
typename ObjectType::Descriptor>
class VKObjectCache {
226 void convert(VkOffset3D& dst,
const TOffset3<UInt32>& src)
noexcept;
227 [[nodiscard]] VkOffset3D
convert(
const TOffset3<UInt32>& src)
noexcept;
229 void convert(VkExtent3D& dst,
const TExtent3<UInt32>& src)
noexcept;
230 [[nodiscard]] VkExtent3D
convert(
const TExtent3<UInt32>& src)
noexcept;
235 [[nodiscard]]
inline constexpr VkBool32
VKBoolean(
const bool value)
noexcept {
return (value ? VK_TRUE : VK_FALSE); }
302 [[nodiscard]]
Vector<VkLayerProperties> VKQueryInstanceLayerProperties();
307 [[nodiscard]]
Vector<VkExtensionProperties> VKQueryInstanceExtensionProperties(const
char* layerName =
nullptr);
312 [[nodiscard]]
Vector<VkPhysicalDevice> VKQueryPhysicalDevices(VkInstance instance);
317 [[nodiscard]]
Vector<VkExtensionProperties> VKQueryDeviceExtensionProperties(VkPhysicalDevice device);
322 [[nodiscard]]
Vector<VkQueueFamilyProperties> VKQueryQueueFamilyProperties(VkPhysicalDevice device);
326#define DECLARE_DEBUG_MARKER_TYPE_TRAIT(T, C) \
327 template<> struct VKDebugMarkerTypeTrait<T> { static const constexpr VkObjectType type = C; };
347 const VkDebugUtilsObjectNameInfoEXT objectNameInfo = {
348 VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
354 return vkSetDebugUtilsObjectNameEXT(device, &objectNameInfo);
#define CE_RENDER_API_OBJECT_EACH(F)
A macro that invokes the function-macro F for every RenderAPI object type.
Definition Forward.hpp:18
#define CE_VK_RENDER_API_OBJECT_FORWARD(N)
Definition VKCommon.hpp:75
#define DECLARE_DEBUG_MARKER_TYPE_TRAIT(T, C)
Definition VKCommon.hpp:326
#define CE_VK_CHECK_PTR(P)
Definition VKCommon.hpp:49
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Pointer get() const noexcept
Definition SmartPtr.hpp:244
Definition Optional.hpp:17
Definition VKDevice.hpp:79
Definition VKCommon.hpp:128
VKDeviceObjectBase(VKDevice &device) noexcept
Creates a new VKDeviceObjectBase from the given device.
~VKDeviceObjectBase() noexcept
Destroys the VKDeviceObjectBase.
VKDevice & deviceVK
The owning VKDevice instance.
Definition VKCommon.hpp:131
Definition VKCommon.hpp:143
VKDeviceObject(VKDevice &device) noexcept
Creates a new VKDeviceObject from the given device.
Definition VKCommon.hpp:147
Definition VKCommon.hpp:87
A object that caches existing Vulkan objects.
Definition VKCommon.hpp:154
~VKObjectCache()
Destroys the Vulkan device object cache.
void release(Object *object)
Releases a previously cached object.
DescriptorType Descriptor
The type of descriptor used to detect duplicates and create new objects.
Definition VKCommon.hpp:158
ObjectType Object
The type of object managed by the cache object.
Definition VKCommon.hpp:161
VKObjectCache(OwnerType &owner)
Creates a new Vulkan device object cache for the given device.
OwnerType & mOwner
The object owning the cached objects.
Definition VKCommon.hpp:168
HashMap< UInt64, Object * > mCache
A map that contains all cached objects.
Definition VKCommon.hpp:171
ObjectPtr get(const Descriptor &descriptor)
Searches for an existing object that is compatible with the given descriptor.
ObjectPtr operator[](const Descriptor &descriptor)
Searches for an existing object that is compatible with the given descriptor.
Definition VKCommon.hpp:190
Definition VKCommon.hpp:93
static const ChildTypeName * cast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition VKCommon.hpp:123
static const ChildTypeName & cast(const ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition VKCommon.hpp:111
static RC< ChildTypeName > cast(const RC< ParentType > &ptr)
Casts a RC containing a ParentType pointer to a pointer to a pointer to a ChildTypeName.
Definition VKCommon.hpp:99
static ChildTypeName & cast(ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition VKCommon.hpp:105
static ChildTypeName * cast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition VKCommon.hpp:117
Definition Application.hpp:19
VKSurfaceSupportDetails VKQuerySurfaceSupport(VkPhysicalDevice device, VkSurfaceKHR surface)
Queries the device for surface support details.
VkResult VKSetObjectName(const VkDevice device, T object, StringView name)
Definition VKCommon.hpp:342
std::uint64_t UInt64
Definition DataTypes.hpp:26
GPUAttachmentLoadOp
Enumeration for render pass attachment load operations.
Definition GPURenderPass.hpp:32
GPUImageSwizzle
Image component swizzle enumeration.
Definition GPUImage.hpp:192
GPUPolygonMode
Polygon filling modes enumeration.
Definition GPUGraphicsPipeline.hpp:143
VkImageAspectFlags toVkImageAspectFlags(Format format)
VKAllocator & gVKAllocator()
GPUCullMode
Polygon culling modes enumeration.
Definition GPUGraphicsPipeline.hpp:153
GPUImageLayout
Definition GPUImage.hpp:65
GPUAttachmentStoreOp
Enumeration for render pass attachment store operations.
Definition GPURenderPass.hpp:48
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
GPUSamplerAddressMode
Technique for resolving image coordinates that are outside of the range [0, 1].
Definition GPUSampler.hpp:29
GPUCompareOp
Compare operations enumeration.
Definition GPUGraphicsPipeline.hpp:37
GPUBlendOp
Blending operations enumeration.
Definition GPUGraphicsPipeline.hpp:84
Format
Definition TextureFormat.hpp:54
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
void convert(VkRect2D &dst, const Viewport &src) noexcept
GPUBlendArithmetic
Blending arithmetic operations enumeration.
Definition GPUGraphicsPipeline.hpp:129
GPUStencilOp
Stencil operations enumeration.
Definition GPUGraphicsPipeline.hpp:63
GPUImageType
Definition GPUImage.hpp:36
GPUResourceType
An enumeration of supported resource types.
Definition GPUResource.hpp:15
constexpr VkBool32 VKBoolean(const bool value) noexcept
Definition VKCommon.hpp:235
ThreadSafeAllocator< MemoryPool< NodePool, AllocatorReference< VKAllocator > > > VKObjectAllocator
A pool allocator to be used for individual object pools.
Definition VKCommon.hpp:59
Vector< T, VKAllocator > VKVector
Definition VKCommon.hpp:73
void VKThrowIfFailed(VkResult result, const char *info)
std::uint32_t UInt32
Definition DataTypes.hpp:23
VkShaderStageFlagBits VKMap(ShaderType shaderType)
StringView VKObjectTypeString(VkObjectType objectType) noexcept
foonathan::memory::thread_safe_allocator< RawAllocator, Mutex > ThreadSafeAllocator
Definition Allocator.hpp:104
GPULogicOp
Logical pixel operation enumeration.
Definition GPUGraphicsPipeline.hpp:166
Definition Allocator.hpp:66
Definition IndexType.hpp:20
Primitive topology enumeration.
Definition PrimitiveTopology.hpp:21
Definition GPUGraphicsPipeline.hpp:281
Shader type enumeration.
Definition ShaderType.hpp:59
Definition VKCommon.hpp:324
A structure that represents a picked queue family.
Definition VKCommon.hpp:253
UInt32 queueIndex
The index of the queue inside the picked family.
Definition VKCommon.hpp:258
UInt32 familyIndex
The index of picked the queue family.
Definition VKCommon.hpp:255
Struct that contains information about each queue family supported by the device.
Definition VKCommon.hpp:265
VkQueueFamilyProperties properties
A structure that contains properties of the queue family.
Definition VKCommon.hpp:270
UInt32 index
The queue family index.
Definition VKCommon.hpp:267
A helper class helps assigning a queue families.
Definition VKCommon.hpp:262
Vector< FamilyInfo > families
The set of supported families by the device.
Definition VKCommon.hpp:278
VKQueueFamilyAssigner(VkPhysicalDevice device) noexcept
Creates a new VKQueueFamilyAssigner.
Optional< VKPickedQueueFamily > pickFamily(VkQueueFlagBits capabilities) noexcept
Picks a new family that has the requested capabilities.
Optional< VKPickedQueueFamily > pickGraphicsFamily() noexcept
Picks a new queue family that is the most suitable for graphics.
Definition VKCommon.hpp:240
Vector< VkSurfaceFormatKHR > formats
Definition VKCommon.hpp:242
Vector< VkPresentModeKHR > presentModes
Definition VKCommon.hpp:243
VkSurfaceCapabilitiesKHR capabilities
Definition VKCommon.hpp:241
Definition GPUGraphicsPipeline.hpp:214