Big code changes
This commit is contained in:
+45
-37
@@ -3,24 +3,23 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <set>
|
||||
#include <sophia/util/logger.hpp>
|
||||
|
||||
#include "util/logger.hpp"
|
||||
namespace sophia {
|
||||
|
||||
namespace hep {
|
||||
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL
|
||||
debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT m_severity,
|
||||
VkDebugUtilsMessageTypeFlagsEXT m_type,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallback_data,
|
||||
static VKAPI_ATTR vk::Bool32 VKAPI_CALL
|
||||
debugCallback(vk::DebugUtilsMessageSeverityFlagBitsEXT m_severity,
|
||||
vk::DebugUtilsMessageTypeFlagsEXT m_type,
|
||||
const vk::DebugUtilsMessengerCallbackDataEXT* pCallback_data,
|
||||
void* pUser_data) {
|
||||
(void)m_type;
|
||||
(void)pCallback_data;
|
||||
(void)pUser_data;
|
||||
|
||||
if (m_severity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
|
||||
if (m_severity == vk::DebugUtilsMessageSeverityFlagBitsEXT::eError) {
|
||||
log::error(pCallback_data->pMessage);
|
||||
return VK_SUCCESS;
|
||||
} else if (m_severity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) {
|
||||
} else if (m_severity == vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning) {
|
||||
log::warning(pCallback_data->pMessage);
|
||||
} else {
|
||||
log::info(pCallback_data->pMessage);
|
||||
@@ -30,8 +29,7 @@ debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT m_severity,
|
||||
}
|
||||
|
||||
VkResult createDebugUtilsMessengerEXT(
|
||||
VkInstance instance,
|
||||
const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
|
||||
VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo,
|
||||
const VkAllocationCallbacks* pAllocator,
|
||||
VkDebugUtilsMessengerEXT* pCallback) {
|
||||
auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
|
||||
@@ -48,7 +46,9 @@ void destroyDebugUtilsMessengerEXT(VkInstance instance,
|
||||
const VkAllocationCallbacks* pAllocator) {
|
||||
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
|
||||
instance, "vkDestroyDebugUtilsMessengerEXT");
|
||||
if (func != nullptr) { func(instance, callback, pAllocator); }
|
||||
if (func != nullptr) {
|
||||
func(instance, callback, pAllocator);
|
||||
}
|
||||
}
|
||||
|
||||
Device::Device(Window& window) : window{window} {
|
||||
@@ -91,8 +91,7 @@ u32 Device::findMemoryType(u32 typeFilter, vk::MemoryPropertyFlags properties) {
|
||||
}
|
||||
|
||||
vk::Format Device::findSupportedFormat(
|
||||
const std::vector<vk::Format>& candidates,
|
||||
vk::ImageTiling tiling,
|
||||
const std::vector<vk::Format>& candidates, vk::ImageTiling tiling,
|
||||
vk::FormatFeatureFlags features) {
|
||||
for (vk::Format format : candidates) {
|
||||
vk::FormatProperties properties =
|
||||
@@ -110,11 +109,9 @@ vk::Format Device::findSupportedFormat(
|
||||
throw std::runtime_error("failed to find supported format");
|
||||
}
|
||||
|
||||
void Device::createBuffer(vk::DeviceSize size,
|
||||
vk::BufferUsageFlags usage,
|
||||
void Device::createBuffer(vk::DeviceSize size, vk::BufferUsageFlags usage,
|
||||
vk::MemoryPropertyFlags properties,
|
||||
vk::Buffer& buffer,
|
||||
vk::DeviceMemory& bufferMemory) {
|
||||
vk::Buffer& buffer, vk::DeviceMemory& bufferMemory) {
|
||||
vk::BufferCreateInfo bufferInfo = {};
|
||||
bufferInfo.size = size;
|
||||
bufferInfo.usage = usage;
|
||||
@@ -156,7 +153,9 @@ vk::CommandBuffer Device::beginSingleTimeCommands() {
|
||||
try {
|
||||
vk::Result result =
|
||||
this->device->allocateCommandBuffers(&allocInfo, &commandBuffer);
|
||||
if (result != vk::Result::eSuccess) { throw vk::SystemError(result); }
|
||||
if (result != vk::Result::eSuccess) {
|
||||
throw vk::SystemError(result);
|
||||
}
|
||||
} catch (const vk::SystemError& error) {
|
||||
log::error("failed to allocate single time commandBuffer. Error: ",
|
||||
error.what());
|
||||
@@ -168,7 +167,9 @@ vk::CommandBuffer Device::beginSingleTimeCommands() {
|
||||
|
||||
try {
|
||||
vk::Result result = commandBuffer.begin(&beginInfo);
|
||||
if (result != vk::Result::eSuccess) { throw vk::SystemError(result); }
|
||||
if (result != vk::Result::eSuccess) {
|
||||
throw vk::SystemError(result);
|
||||
}
|
||||
} catch (const vk::SystemError& error) {
|
||||
log::error("failed to begin single time commandBuffer. Error: ",
|
||||
error.what());
|
||||
@@ -191,8 +192,7 @@ void Device::endSingleTimeCommands(vk::CommandBuffer commandBuffer) {
|
||||
this->device->freeCommandBuffers(commandPool, commandBuffer);
|
||||
}
|
||||
|
||||
void Device::copyBuffer(vk::Buffer sourceBuffer,
|
||||
vk::Buffer destinationBuffer,
|
||||
void Device::copyBuffer(vk::Buffer sourceBuffer, vk::Buffer destinationBuffer,
|
||||
vk::DeviceSize size) {
|
||||
vk::CommandBuffer commandBuffer = beginSingleTimeCommands();
|
||||
|
||||
@@ -210,7 +210,9 @@ void Device::createImageWithInfo(const vk::ImageCreateInfo& imageInfo,
|
||||
vk::DeviceMemory& imageMemory) {
|
||||
try {
|
||||
vk::Result result = this->device->createImage(&imageInfo, nullptr, &image);
|
||||
if (result != vk::Result::eSuccess) { throw vk::SystemError(result); }
|
||||
if (result != vk::Result::eSuccess) {
|
||||
throw vk::SystemError(result);
|
||||
}
|
||||
} catch (const vk::SystemError& error) {
|
||||
log::fatal("failed to create image. Error: ", error.what());
|
||||
throw std::runtime_error("failed to create image");
|
||||
@@ -227,7 +229,9 @@ void Device::createImageWithInfo(const vk::ImageCreateInfo& imageInfo,
|
||||
try {
|
||||
vk::Result result =
|
||||
this->device->allocateMemory(&allocateInfo, nullptr, &imageMemory);
|
||||
if (result != vk::Result::eSuccess) { throw vk::SystemError(result); }
|
||||
if (result != vk::Result::eSuccess) {
|
||||
throw vk::SystemError(result);
|
||||
}
|
||||
} catch (const vk::SystemError& error) {
|
||||
log::fatal("failed to allocate image memory. Error: ", error.what());
|
||||
throw std::runtime_error("failed to allocate image memory");
|
||||
@@ -243,7 +247,7 @@ void Device::createImageWithInfo(const vk::ImageCreateInfo& imageInfo,
|
||||
|
||||
void Device::populateImGuiInitInfo(ImGui_ImplVulkan_InitInfo& initInfo) {
|
||||
initInfo.Instance = this->instance.get();
|
||||
initInfo.ApiVersion = HEP_VULKAN_API_VERSION;
|
||||
initInfo.ApiVersion = SOPHIA_VULKAN_API_VERSION;
|
||||
initInfo.PhysicalDevice = this->physicalDevice;
|
||||
initInfo.Device = this->device.get();
|
||||
|
||||
@@ -286,7 +290,9 @@ bool Device::checkValidationLayerSupport() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!layerFound) { return false; }
|
||||
if (!layerFound) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -309,7 +315,9 @@ std::vector<const char*> Device::getRequiredExtensions() {
|
||||
vk::Result result = vk::enumerateInstanceExtensionProperties(
|
||||
nullptr, &available_extension_count, nullptr);
|
||||
|
||||
if (result != vk::Result::eSuccess) { throw std::exception(); }
|
||||
if (result != vk::Result::eSuccess) {
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
std::vector<vk::ExtensionProperties> available_extensions(
|
||||
available_extension_count);
|
||||
@@ -317,7 +325,9 @@ std::vector<const char*> Device::getRequiredExtensions() {
|
||||
result = vk::enumerateInstanceExtensionProperties(
|
||||
nullptr, &available_extension_count, available_extensions.data());
|
||||
|
||||
if (result != vk::Result::eSuccess) { throw std::exception(); }
|
||||
if (result != vk::Result::eSuccess) {
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
log::verbose("Number of available extensions: ", available_extension_count);
|
||||
|
||||
@@ -326,7 +336,9 @@ std::vector<const char*> Device::getRequiredExtensions() {
|
||||
std::cout << '\t' << e.extensionName << '\n';
|
||||
}
|
||||
std::cout << "Required extensions:\n";
|
||||
for (const auto& e : extensions) { std::cout << "\t" << e << '\n'; }
|
||||
for (const auto& e : extensions) {
|
||||
std::cout << "\t" << e << '\n';
|
||||
}
|
||||
#endif
|
||||
|
||||
return extensions;
|
||||
@@ -373,7 +385,9 @@ QueueFamilyIndices Device::findQueueFamilies(vk::PhysicalDevice device) {
|
||||
indices.presentFamily = i;
|
||||
}
|
||||
|
||||
if (indices.isComplete()) { break; }
|
||||
if (indices.isComplete()) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -457,12 +471,6 @@ void Device::createLogicalDevice() {
|
||||
static_cast<uint32_t>(this->enabledExtensions.size());
|
||||
createInfo.ppEnabledExtensionNames = this->enabledExtensions.data();
|
||||
|
||||
if (this->enableValidationLayers) {
|
||||
createInfo.enabledLayerCount =
|
||||
static_cast<uint32_t>(this->enabledLayers.size());
|
||||
createInfo.ppEnabledLayerNames = this->enabledLayers.data();
|
||||
}
|
||||
|
||||
try {
|
||||
this->device = this->physicalDevice.createDeviceUnique(createInfo);
|
||||
log::trace("created vk::Device.");
|
||||
@@ -502,4 +510,4 @@ void Device::createCommandPool() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace hep
|
||||
} // namespace sophia
|
||||
|
||||
Reference in New Issue
Block a user