Merge branch 'master' of warwick-new.co.uk:yave
This commit is contained in:
commit
f1186130b6
2 changed files with 61 additions and 2 deletions
|
|
@ -7,8 +7,12 @@ namespace yave {
|
||||||
YaveVulkanInstance::YaveVulkanInstance() {
|
YaveVulkanInstance::YaveVulkanInstance() {
|
||||||
createInstance();
|
createInstance();
|
||||||
pickPhysicalDevice();
|
pickPhysicalDevice();
|
||||||
|
createLogicalDevice();
|
||||||
|
}
|
||||||
|
YaveVulkanInstance::~YaveVulkanInstance() {
|
||||||
|
destroyLogicalDevice();
|
||||||
|
destroyInstance();
|
||||||
}
|
}
|
||||||
YaveVulkanInstance::~YaveVulkanInstance() { destroyInstance(); }
|
|
||||||
|
|
||||||
void YaveVulkanInstance::createInstance() {
|
void YaveVulkanInstance::createInstance() {
|
||||||
VkApplicationInfo appInfo{};
|
VkApplicationInfo appInfo{};
|
||||||
|
|
@ -147,4 +151,52 @@ YaveVulkanInstance::findQueueFamilies(VkPhysicalDevice device) {
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YaveVulkanInstance::createLogicalDevice() {
|
||||||
|
QueueFamilyIndices indices = findQueueFamilies(physicalDevice);
|
||||||
|
|
||||||
|
// Only need a single queue as we can feed it with multiple threads and
|
||||||
|
// trigger it from the main thread to start off with.
|
||||||
|
VkDeviceQueueCreateInfo queueCreateInfo{};
|
||||||
|
queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
|
||||||
|
queueCreateInfo.queueFamilyIndex = indices.graphicsFamily.value();
|
||||||
|
queueCreateInfo.queueCount = 1;
|
||||||
|
// Since we only have one queue it has all the priority.
|
||||||
|
float queuePriority = 1.0f;
|
||||||
|
queueCreateInfo.pQueuePriorities = &queuePriority;
|
||||||
|
|
||||||
|
// TODO: set up device with interesting features as we use them
|
||||||
|
VkPhysicalDeviceFeatures deviceFeatures{};
|
||||||
|
|
||||||
|
// Create logical device.
|
||||||
|
VkDeviceCreateInfo createInfo{};
|
||||||
|
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
||||||
|
createInfo.pQueueCreateInfos = &queueCreateInfo;
|
||||||
|
createInfo.queueCreateInfoCount = 1;
|
||||||
|
createInfo.pEnabledFeatures = &deviceFeatures;
|
||||||
|
|
||||||
|
// TODO: Require specific features when we need some
|
||||||
|
// Device specific create information
|
||||||
|
createInfo.enabledExtensionCount = 0;
|
||||||
|
if (enableValidationLayers) {
|
||||||
|
createInfo.enabledLayerCount =
|
||||||
|
static_cast<uint32_t>(validationLayers.size());
|
||||||
|
createInfo.ppEnabledLayerNames = validationLayers.data();
|
||||||
|
} else {
|
||||||
|
createInfo.enabledLayerCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create logical device
|
||||||
|
if (vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) !=
|
||||||
|
VK_SUCCESS) {
|
||||||
|
throw std::runtime_error("failed to create logical device!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whilst we're here we might as well set up our queue
|
||||||
|
vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YaveVulkanInstance::destroyLogicalDevice() {
|
||||||
|
vkDestroyDevice(device, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace yave
|
} // namespace yave
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ class YaveVulkanInstance {
|
||||||
private:
|
private:
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
VkPhysicalDevice physicalDevice;
|
VkPhysicalDevice physicalDevice;
|
||||||
|
VkDevice device;
|
||||||
|
VkQueue graphicsQueue;
|
||||||
|
|
||||||
// Vulkan instance
|
// Vulkan instance
|
||||||
void createInstance();
|
void createInstance();
|
||||||
|
|
@ -33,6 +35,11 @@ private:
|
||||||
bool isDeviceSuitable(VkPhysicalDevice device);
|
bool isDeviceSuitable(VkPhysicalDevice device);
|
||||||
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
|
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
|
||||||
|
|
||||||
|
// TODO: Move Logical device code to it's own class
|
||||||
|
// Logical device
|
||||||
|
void createLogicalDevice();
|
||||||
|
void destroyLogicalDevice();
|
||||||
|
|
||||||
// Validation support
|
// Validation support
|
||||||
bool checkLayersValidSuppport(VkInstanceCreateInfo &createInfo);
|
bool checkLayersValidSuppport(VkInstanceCreateInfo &createInfo);
|
||||||
const std::vector<const char *> validationLayers = {
|
const std::vector<const char *> validationLayers = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue