86 lines
2.3 KiB
C++
86 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#ifndef VK_USE_PLATFORM_WIN32_KHR
|
|
#define VK_USE_PLATFORM_WIN32_KHR
|
|
#endif
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#include "XCEngine/RHI/RHIEnums.h"
|
|
|
|
#include <string>
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
inline std::wstring WidenAscii(const char* value) {
|
|
if (value == nullptr) {
|
|
return {};
|
|
}
|
|
|
|
const std::string ascii(value);
|
|
return std::wstring(ascii.begin(), ascii.end());
|
|
}
|
|
|
|
inline VkFormat ToVulkanFormat(Format format) {
|
|
switch (format) {
|
|
case Format::R8G8B8A8_UNorm:
|
|
return VK_FORMAT_R8G8B8A8_UNORM;
|
|
case Format::D24_UNorm_S8_UInt:
|
|
return VK_FORMAT_D24_UNORM_S8_UINT;
|
|
case Format::D32_Float:
|
|
return VK_FORMAT_D32_SFLOAT;
|
|
case Format::R32_UInt:
|
|
return VK_FORMAT_R32_UINT;
|
|
case Format::R32G32_Float:
|
|
return VK_FORMAT_R32G32_SFLOAT;
|
|
case Format::R32G32B32A32_Float:
|
|
return VK_FORMAT_R32G32B32A32_SFLOAT;
|
|
default:
|
|
return VK_FORMAT_UNDEFINED;
|
|
}
|
|
}
|
|
|
|
inline Format ToRHIFormat(VkFormat format) {
|
|
switch (format) {
|
|
case VK_FORMAT_R8G8B8A8_UNORM:
|
|
case VK_FORMAT_B8G8R8A8_UNORM:
|
|
return Format::R8G8B8A8_UNorm;
|
|
case VK_FORMAT_D24_UNORM_S8_UINT:
|
|
return Format::D24_UNorm_S8_UInt;
|
|
case VK_FORMAT_D32_SFLOAT:
|
|
return Format::D32_Float;
|
|
case VK_FORMAT_R32_UINT:
|
|
return Format::R32_UInt;
|
|
case VK_FORMAT_R32G32_SFLOAT:
|
|
return Format::R32G32_Float;
|
|
case VK_FORMAT_R32G32B32A32_SFLOAT:
|
|
return Format::R32G32B32A32_Float;
|
|
default:
|
|
return Format::Unknown;
|
|
}
|
|
}
|
|
|
|
inline VkImageAspectFlags GetImageAspectMask(Format format) {
|
|
switch (format) {
|
|
case Format::D24_UNorm_S8_UInt:
|
|
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
case Format::D32_Float:
|
|
case Format::D16_UNorm:
|
|
return VK_IMAGE_ASPECT_DEPTH_BIT;
|
|
default:
|
|
return VK_IMAGE_ASPECT_COLOR_BIT;
|
|
}
|
|
}
|
|
|
|
inline uint32_t ResolveVulkanApiMajor(uint32_t apiVersion) {
|
|
return VK_API_VERSION_MAJOR(apiVersion);
|
|
}
|
|
|
|
inline uint32_t ResolveVulkanApiMinor(uint32_t apiVersion) {
|
|
return VK_API_VERSION_MINOR(apiVersion);
|
|
}
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|