重构至debugCallBack
parent
1d6521570e
commit
77e93d01d1
|
@ -1801,6 +1801,7 @@ void VulkanExampleBase::setupFrameBuffer()
|
|||
imageCI.samples = settings.sampleCount;
|
||||
imageCI.usage = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
imageCI.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
|
||||
VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &multisampleTarget.color.image));
|
||||
|
||||
VkMemoryRequirements memReqs;
|
||||
|
|
|
@ -43,6 +43,8 @@ void PlumageRender::framebufferResizeCallback(GLFWwindow* window, int width, int
|
|||
app->framebufferResized = true;
|
||||
}
|
||||
|
||||
|
||||
// 重构至gltfModel中
|
||||
void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFModel::Material::AlphaMode alphaMode) {
|
||||
if (node->mesh) {
|
||||
// Render mesh primitives
|
||||
|
@ -670,6 +672,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
// generate two cube maps
|
||||
// irradiance cube map
|
||||
// prefileter environment cube map
|
||||
// 重构到PBR中
|
||||
void PlumageRender::generateCubemaps()
|
||||
{
|
||||
enum Target { IRRADIANCE = 0, PREFILTEREDENV = 1 };
|
||||
|
@ -1208,6 +1211,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
}
|
||||
}
|
||||
// generate BRDF integration map for roughness/NdotV
|
||||
// 重构到PBR
|
||||
void PlumageRender::generateBRDFLUT()
|
||||
{
|
||||
auto tStart = std::chrono::high_resolution_clock::now();
|
||||
|
@ -1475,7 +1479,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
}
|
||||
updateUniformBuffers();
|
||||
}
|
||||
|
||||
// 更新统一缓冲区
|
||||
void PlumageRender::updateUniformBuffers()
|
||||
{
|
||||
// Scene
|
||||
|
@ -1513,7 +1517,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
cos(glm::radians(lightSource.rotation.x)) * cos(glm::radians(lightSource.rotation.y)),
|
||||
0.0f);
|
||||
}
|
||||
|
||||
// todo:重写成glfw的
|
||||
void PlumageRender::windowResized()
|
||||
{
|
||||
buildCommandBuffers();
|
||||
|
@ -1601,6 +1605,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
}
|
||||
|
||||
// todo :根据physicalDeviceIndex确定子文件夹路径,frameIndex确定fileName
|
||||
// 移动到fileSystem里
|
||||
void PlumageRender::writeImageToFile(std::string filePath)
|
||||
{
|
||||
|
||||
|
@ -2050,7 +2055,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
buildCommandBuffers();
|
||||
|
||||
}
|
||||
|
||||
// 重构到单独的UI里
|
||||
void PlumageRender::updateUIOverlay()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
@ -2265,7 +2270,7 @@ void PlumageRender::renderNode(glTFModel::Node* node, uint32_t cbIndex, glTFMode
|
|||
}
|
||||
|
||||
|
||||
|
||||
// 完全重写,避免OS specific
|
||||
PlumageRender* plumageRender;
|
||||
// OS specific macros for the example main entry points
|
||||
#if defined(_WIN32)
|
||||
|
|
|
@ -1,5 +1,125 @@
|
|||
#include "vulkanFoundation.h"
|
||||
|
||||
VKAPI_ATTR VkBool32 VKAPI_CALL VulkanBackend::VulkanFondation::debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageTypes, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData)
|
||||
{
|
||||
std::cerr << "validation layer: " << pCallbackData->pMessage << std::endl;
|
||||
|
||||
return VK_FALSE;
|
||||
}
|
||||
|
||||
void VulkanBackend::VulkanFondation::createInstance()
|
||||
{
|
||||
// check validation layers
|
||||
if (setter.settings.validation && !checkValidationLayerSupport())
|
||||
{
|
||||
throw std::runtime_error("validation layers requsted,but not available");
|
||||
}
|
||||
|
||||
//setup appliaction info
|
||||
VkApplicationInfo appInfo{};
|
||||
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "Hello Triangle";
|
||||
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.pEngineName = "No_Engine";
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.apiVersion = VK_API_VERSION_1_0;
|
||||
|
||||
// setup createInfo
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
createInfo.pApplicationInfo = &appInfo;
|
||||
|
||||
auto requiredExtensions = getRequiredExtensions();
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(requiredExtensions.size());
|
||||
createInfo.ppEnabledExtensionNames = requiredExtensions.data();
|
||||
|
||||
|
||||
// enable validation layer if available in createInfo
|
||||
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo{};
|
||||
if (setter.settings.validation)
|
||||
{
|
||||
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
|
||||
createInfo.ppEnabledLayerNames = validationLayers.data();
|
||||
|
||||
populateDebugMessengerCreateInfo(debugCreateInfo);
|
||||
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*)&debugCreateInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
createInfo.enabledLayerCount = 0;
|
||||
createInfo.pNext = nullptr;
|
||||
}
|
||||
|
||||
// throw error in creating instance
|
||||
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("failed to create instance");
|
||||
}
|
||||
}
|
||||
|
||||
bool VulkanBackend::VulkanFondation::checkValidationLayerSupport()
|
||||
{
|
||||
uint32_t layerCount;
|
||||
vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
|
||||
|
||||
std::vector<VkLayerProperties> availableLayers(layerCount);
|
||||
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
|
||||
|
||||
// check if validationLayers can be found in availableLayers
|
||||
for (const char* layerName : validationLayers)
|
||||
{
|
||||
bool layerFound = false;
|
||||
for (const auto& layerProperties : availableLayers) {
|
||||
if (strcmp(layerName, layerProperties.layerName) == 0)
|
||||
{
|
||||
layerFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!layerFound)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<const char*> VulkanBackend::VulkanFondation::getRequiredExtensions()
|
||||
{
|
||||
std::vector<const char*> extensions;
|
||||
if (!setter.settings.headless)
|
||||
{
|
||||
uint32_t glfwExtensionCount = 0;
|
||||
const char** glfwExtensions;
|
||||
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
||||
|
||||
std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
|
||||
}
|
||||
|
||||
if (setter.settings.validation)
|
||||
{
|
||||
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
void VulkanBackend::VulkanFondation::populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugCreateInfo)
|
||||
{
|
||||
debugCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||
|
||||
debugCreateInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
|
||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
|
||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||
debugCreateInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
|
||||
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
|
||||
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
||||
debugCreateInfo.pfnUserCallback = &debugCallback;
|
||||
debugCreateInfo.pUserData = nullptr;
|
||||
}
|
||||
|
||||
void VulkanBackend::VulkanFondation::createSurface()
|
||||
{
|
||||
|
||||
|
@ -45,7 +165,7 @@ bool VulkanBackend::VulkanFondation::isDeviceSuitable(VkPhysicalDevice device)
|
|||
return extensionsSupported;
|
||||
}
|
||||
else
|
||||
{
|
||||
{ // 非无头下在检查扩展支持的同时要检查swapchain
|
||||
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
||||
bool swapChainAdequate = false;
|
||||
QueueFamilyIndices indices = findQueueFamilies(device);
|
||||
|
@ -59,7 +179,21 @@ bool VulkanBackend::VulkanFondation::isDeviceSuitable(VkPhysicalDevice device)
|
|||
|
||||
bool VulkanBackend::VulkanFondation::checkDeviceExtensionSupport(VkPhysicalDevice device)
|
||||
{
|
||||
return false;
|
||||
uint32_t extensionCount;
|
||||
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
|
||||
|
||||
std::vector<VkExtensionProperties> availableExtensions(extensionCount);
|
||||
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data());
|
||||
|
||||
std::set<std::string> requiredExtensions(swapchainExtensions.begin(), swapchainExtensions.end());
|
||||
|
||||
for (const auto& extension : availableExtensions)
|
||||
{
|
||||
requiredExtensions.erase(extension.extensionName);
|
||||
}
|
||||
|
||||
return requiredExtensions.empty();
|
||||
|
||||
}
|
||||
|
||||
VulkanBackend::VulkanFondation::QueueFamilyIndices VulkanBackend::VulkanFondation::findQueueFamilies(VkPhysicalDevice device)
|
||||
|
@ -74,18 +208,32 @@ VulkanBackend::VulkanFondation::QueueFamilyIndices VulkanBackend::VulkanFondatio
|
|||
|
||||
VkBool32 presentSupport = false;
|
||||
|
||||
|
||||
// 检查队列支持
|
||||
int i = 0;
|
||||
if (!setter.settings.headless)
|
||||
{
|
||||
vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
|
||||
}
|
||||
for (const auto& queueFamily : queueFamilies)
|
||||
{
|
||||
if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
|
||||
indices.graphicsFamily = i;
|
||||
}
|
||||
if (indices.isComplete())
|
||||
// 无头下不需要检查present queue
|
||||
if (setter.settings.headless)
|
||||
{
|
||||
if (indices.isGraphicsFamilyComplete())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (indices.isGraphicsFamilyComplete() && indices.isPresentFamilyComplete())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (presentSupport)
|
||||
{
|
||||
indices.presentFamily = i;
|
||||
|
@ -100,5 +248,28 @@ VulkanBackend::VulkanFondation::QueueFamilyIndices VulkanBackend::VulkanFondatio
|
|||
|
||||
VulkanBackend::VulkanFondation::SwapChainSupportDetails VulkanBackend::VulkanFondation::querySwapChainSupport(VkPhysicalDevice device)
|
||||
{
|
||||
// 获得surface细节
|
||||
SwapChainSupportDetails details;
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);
|
||||
|
||||
// 检查格式支持(image)
|
||||
uint32_t formatCount;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
||||
if (formatCount != 0)
|
||||
{
|
||||
details.formats.resize(formatCount);
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());
|
||||
}
|
||||
|
||||
// 检查显示模式支持
|
||||
uint32_t presentModeCount;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
|
||||
|
||||
if (presentModeCount != 0)
|
||||
{
|
||||
details.presentModes.resize(presentModeCount);
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
||||
#include "renderSetter.h"
|
||||
|
||||
|
@ -16,13 +17,25 @@ namespace VulkanBackend
|
|||
VulkanFondation();
|
||||
~VulkanFondation();
|
||||
|
||||
const std::vector<const char*> validationLayers = {
|
||||
"VK_LAYER_KHRONOS_validation"
|
||||
|
||||
};
|
||||
|
||||
const std::vector<const char*> swapchainExtensions = {
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
//"VK_EXT_headless_surface"
|
||||
};
|
||||
|
||||
VulkanBackend::Setter setter;
|
||||
|
||||
VkInstance instance;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
VkInstance instance;
|
||||
VkDebugUtilsMessengerEXT debugMessenger;
|
||||
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice device;
|
||||
VkSurfaceKHR surface;
|
||||
|
@ -31,8 +44,13 @@ namespace VulkanBackend
|
|||
std::optional<uint32_t> graphicsFamily;
|
||||
std::optional<uint32_t> presentFamily;
|
||||
|
||||
bool isComplete() {
|
||||
return graphicsFamily.has_value() && presentFamily.has_value();
|
||||
bool isGraphicsFamilyComplete()
|
||||
{
|
||||
return graphicsFamily.has_value();
|
||||
}
|
||||
bool isPresentFamilyComplete()
|
||||
{
|
||||
return presentFamily.has_value();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,14 +61,19 @@ namespace VulkanBackend
|
|||
std::vector<VkPresentModeKHR> presentModes;
|
||||
};
|
||||
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
||||
VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT messageTypes,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||
void* pUserData);
|
||||
|
||||
|
||||
void pickPhysicalDevice();
|
||||
|
||||
|
||||
void createInstance();
|
||||
bool checkValidationLayerSupport();
|
||||
std::vector<const char*> getRequiredExtensions();
|
||||
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& debugCreateInfo);
|
||||
|
||||
void createSurface();
|
||||
|
||||
void pickPhysicalDevice();
|
||||
bool isDeviceSuitable(VkPhysicalDevice device);
|
||||
bool checkDeviceExtensionSupport(VkPhysicalDevice device);
|
||||
VulkanBackend::VulkanFondation::QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
|
||||
|
|
Loading…
Reference in New Issue