summaryrefslogtreecommitdiff
path: root/drivers/vulkan
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-29 20:44:14 +0200
committerGitHub <noreply@github.com>2020-02-11 11:57:40 +0100
commit6289e7d1479f6e7c9e55890c8c66d2e5e0a1481a (patch)
tree8223d907b1aa8184295240a7b6f63023da05c02f /drivers/vulkan
parent6ecedd1e6ca7d8b10b13a3dab19074fd51b17bcf (diff)
parentb456bfad5cee3922f55621bf7c133cc67337636a (diff)
Merge pull request #29993 from bruvzg/vulkan
Initial Vulkan support for macOS (MoltenVK) and Windows
Diffstat (limited to 'drivers/vulkan')
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp47
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h41
-rw-r--r--drivers/vulkan/vk_mem_alloc.cpp32
-rw-r--r--drivers/vulkan/vulkan_context.cpp329
-rw-r--r--drivers/vulkan/vulkan_context.h32
5 files changed, 338 insertions, 143 deletions
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index a14d45067a..265dfc69d4 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* rendering_device_vulkan.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#include "rendering_device_vulkan.h"
#include "core/hashfuncs.h"
#include "core/os/file_access.h"
@@ -4875,7 +4905,9 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin_for_screen(in
VkCommandBuffer command_buffer = frames[frame].draw_command_buffer;
draw_list = memnew(DrawList);
draw_list->command_buffer = command_buffer;
+#ifdef DEBUG_ENABLED
draw_list->validation.framebuffer_format = screen_get_framebuffer_format();
+#endif
draw_list_count = 0;
draw_list_split = false;
@@ -5071,7 +5103,9 @@ RenderingDevice::DrawListID RenderingDeviceVulkan::draw_list_begin(RID p_framebu
draw_list = memnew(DrawList);
draw_list->command_buffer = command_buffer;
+#ifdef DEBUG_ENABLED
draw_list->validation.framebuffer_format = framebuffer->format_id;
+#endif
draw_list_count = 0;
draw_list_split = false;
@@ -5216,7 +5250,9 @@ Error RenderingDeviceVulkan::draw_list_begin_split(RID p_framebuffer, uint32_t p
}
draw_list[i].command_buffer = command_buffer;
+#ifdef DEBUG_ENABLED
draw_list[i].validation.framebuffer_format = framebuffer->format_id;
+#endif
VkViewport viewport;
viewport.x = viewport_offset.x;
@@ -5400,9 +5436,9 @@ void RenderingDeviceVulkan::draw_list_bind_vertex_array(DrawListID p_list, RID p
#ifdef DEBUG_ENABLED
dl->validation.vertex_format = vertex_array->description;
- dl->validation.vertex_array_size = vertex_array->vertex_count;
dl->validation.vertex_max_instances_allowed = vertex_array->max_instances_allowed;
#endif
+ dl->validation.vertex_array_size = vertex_array->vertex_count;
vkCmdBindVertexBuffers(dl->command_buffer, 0, vertex_array->buffers.size(), vertex_array->buffers.ptr(), vertex_array->offsets.ptr());
}
void RenderingDeviceVulkan::draw_list_bind_index_array(DrawListID p_list, RID p_index_array) {
@@ -5422,10 +5458,11 @@ void RenderingDeviceVulkan::draw_list_bind_index_array(DrawListID p_list, RID p_
dl->state.index_array = p_index_array;
#ifdef DEBUG_ENABLED
- dl->validation.index_array_size = index_array->indices;
dl->validation.index_array_max_index = index_array->max_index;
- dl->validation.index_array_offset = index_array->offset;
#endif
+ dl->validation.index_array_size = index_array->indices;
+ dl->validation.index_array_offset = index_array->offset;
+
vkCmdBindIndexBuffer(dl->command_buffer, index_array->buffer, index_array->offset, index_array->index_type);
}
@@ -5433,7 +5470,9 @@ void RenderingDeviceVulkan::draw_list_set_line_width(DrawListID p_list, float p_
DrawList *dl = _get_draw_list_ptr(p_list);
ERR_FAIL_COND(!dl);
+#ifdef DEBUG_ENABLED
ERR_FAIL_COND_MSG(!dl->validation.active, "Submitted Draw Lists can no longer be modified.");
+#endif
vkCmdSetLineWidth(dl->command_buffer, p_width);
}
@@ -5451,7 +5490,9 @@ void RenderingDeviceVulkan::draw_list_set_push_constant(DrawListID p_list, void
"This render pipeline requires (" + itos(dl->validation.pipeline_push_constant_size) + ") bytes of push constant data, supplied: (" + itos(p_data_size) + ")");
#endif
vkCmdPushConstants(dl->command_buffer, dl->state.pipeline_layout, dl->state.pipeline_push_constant_stages, 0, p_data_size, p_data);
+#ifdef DEBUG_ENABLED
dl->validation.pipeline_push_constant_suppplied = true;
+#endif
}
void RenderingDeviceVulkan::draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances) {
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index 87971ba2b8..af144a7f6b 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* rendering_device_vulkan.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#ifndef RENDERING_DEVICE_VULKAN_H
#define RENDERING_DEVICE_VULKAN_H
@@ -737,6 +767,17 @@ class RenderingDeviceVulkan : public RenderingDevice {
pipeline_push_constant_suppplied = false;
}
} validation;
+#else
+ struct Validation {
+ uint32_t vertex_array_size; //0 if not set
+ uint32_t index_array_size; //0 if index buffer not set
+ uint32_t index_array_offset;
+
+ Validation() {
+ vertex_array_size = 0;
+ index_array_size = 0; //not sent
+ }
+ } validation;
#endif
};
diff --git a/drivers/vulkan/vk_mem_alloc.cpp b/drivers/vulkan/vk_mem_alloc.cpp
index 8e91e8a08c..dcfc98bf63 100644
--- a/drivers/vulkan/vk_mem_alloc.cpp
+++ b/drivers/vulkan/vk_mem_alloc.cpp
@@ -1,5 +1,37 @@
+/*************************************************************************/
+/* vk_mem_alloc.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#define VMA_IMPLEMENTATION
#ifdef DEBUG_ENABLED
+#ifndef _MSC_VER
#define _DEBUG
#endif
+#endif
#include "vk_mem_alloc.h"
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 2f02c20bdb..efd025c1e2 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* vulkan_context.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#include "vulkan_context.h"
#include "core/print_string.h"
#include "core/project_settings.h"
@@ -222,22 +252,23 @@ Error VulkanContext::_create_physical_device() {
String name = "GodotEngine " + String(VERSION_FULL_NAME);
CharString namecs = name.utf8();
const VkApplicationInfo app = {
- .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
- .pNext = NULL,
- .pApplicationName = cs.get_data(),
- .applicationVersion = 0,
- .pEngineName = namecs.get_data(),
- .engineVersion = 0,
- .apiVersion = VK_API_VERSION_1_0,
+ /*sType*/ VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ /*pNext*/ NULL,
+ /*pApplicationName*/ cs.get_data(),
+ /*applicationVersion*/ 0,
+ /*pEngineName*/ namecs.get_data(),
+ /*engineVersion*/ 0,
+ /*apiVersion*/ VK_API_VERSION_1_0,
};
VkInstanceCreateInfo inst_info = {
- .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
- .pNext = NULL,
- .pApplicationInfo = &app,
- .enabledLayerCount = enabled_layer_count,
- .ppEnabledLayerNames = (const char *const *)instance_validation_layers,
- .enabledExtensionCount = enabled_extension_count,
- .ppEnabledExtensionNames = (const char *const *)extension_names,
+ /*sType*/ VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*pApplicationInfo*/ &app,
+ /*enabledLayerCount*/ enabled_layer_count,
+ /*ppEnabledLayerNames*/ (const char *const *)instance_validation_layers,
+ /*enabledExtensionCount*/ enabled_extension_count,
+ /*ppEnabledExtensionNames*/ (const char *const *)extension_names,
};
/*
@@ -447,15 +478,17 @@ Error VulkanContext::_create_device() {
queues[0].flags = 0;
VkDeviceCreateInfo sdevice = {
- .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
- .pNext = NULL,
- .queueCreateInfoCount = 1,
- .pQueueCreateInfos = queues,
- .enabledLayerCount = 0,
- .ppEnabledLayerNames = NULL,
- .enabledExtensionCount = enabled_extension_count,
- .ppEnabledExtensionNames = (const char *const *)extension_names,
- .pEnabledFeatures = &physical_device_features, // If specific features are required, pass them in here
+ /*sType*/ VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*queueCreateInfoCount*/ 1,
+ /*pQueueCreateInfos*/ queues,
+ /*enabledLayerCount*/ 0,
+ /*ppEnabledLayerNames*/ NULL,
+ /*enabledExtensionCount*/ enabled_extension_count,
+ /*ppEnabledExtensionNames*/ (const char *const *)extension_names,
+ /*pEnabledFeatures*/ &physical_device_features, // If specific features are required, pass them in here
+
};
if (separate_present_queue) {
queues[1].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
@@ -579,15 +612,17 @@ Error VulkanContext::_create_semaphores() {
// Create semaphores to synchronize acquiring presentable buffers before
// rendering and waiting for drawing to be complete before presenting
VkSemaphoreCreateInfo semaphoreCreateInfo = {
- .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
- .pNext = NULL,
- .flags = 0,
+ /*sType*/ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
};
// Create fences that we can use to throttle if we get too far
// ahead of the image presents
VkFenceCreateInfo fence_ci = {
- .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, .pNext = NULL, .flags = VK_FENCE_CREATE_SIGNALED_BIT
+ /*sType*/ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ VK_FENCE_CREATE_SIGNALED_BIT
};
for (uint32_t i = 0; i < FRAME_LAG; i++) {
err = vkCreateFence(device, &fence_ci, NULL, &fences[i]);
@@ -828,26 +863,27 @@ Error VulkanContext::_update_swap_chain(Window *window) {
}
VkSwapchainCreateInfoKHR swapchain_ci = {
- .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
- .pNext = NULL,
- .surface = window->surface,
- .minImageCount = desiredNumOfSwapchainImages,
- .imageFormat = format,
- .imageColorSpace = color_space,
- .imageExtent = {
- .width = swapchainExtent.width,
- .height = swapchainExtent.height,
+ /*sType*/ VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*surface*/ window->surface,
+ /*minImageCount*/ desiredNumOfSwapchainImages,
+ /*imageFormat*/ format,
+ /*imageColorSpace*/ color_space,
+ /*imageExtent*/ {
+ /*width*/ swapchainExtent.width,
+ /*height*/ swapchainExtent.height,
},
- .imageArrayLayers = 1,
- .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
- .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
- .queueFamilyIndexCount = 0,
- .pQueueFamilyIndices = NULL,
- .preTransform = (VkSurfaceTransformFlagBitsKHR)preTransform,
- .compositeAlpha = compositeAlpha,
- .presentMode = swapchainPresentMode,
- .clipped = true,
- .oldSwapchain = NULL,
+ /*imageArrayLayers*/ 1,
+ /*imageUsage*/ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+ /*imageSharingMode*/ VK_SHARING_MODE_EXCLUSIVE,
+ /*queueFamilyIndexCount*/ 0,
+ /*pQueueFamilyIndices*/ NULL,
+ /*preTransform*/ (VkSurfaceTransformFlagBitsKHR)preTransform,
+ /*compositeAlpha*/ compositeAlpha,
+ /*presentMode*/ swapchainPresentMode,
+ /*clipped*/ true,
+ /*oldSwapchain*/ NULL,
};
err = fpCreateSwapchainKHR(device, &swapchain_ci, NULL, &window->swapchain);
@@ -875,18 +911,25 @@ Error VulkanContext::_update_swap_chain(Window *window) {
for (uint32_t i = 0; i < swapchainImageCount; i++) {
VkImageViewCreateInfo color_image_view = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .pNext = NULL,
- .flags = 0,
- .viewType = VK_IMAGE_VIEW_TYPE_2D,
- .format = format,
- .components = {
- .r = VK_COMPONENT_SWIZZLE_R,
- .g = VK_COMPONENT_SWIZZLE_G,
- .b = VK_COMPONENT_SWIZZLE_B,
- .a = VK_COMPONENT_SWIZZLE_A,
+ /*sType*/ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*image*/ swapchainImages[i],
+ /*viewType*/ VK_IMAGE_VIEW_TYPE_2D,
+ /*format*/ format,
+ /*components*/ {
+ /*r*/ VK_COMPONENT_SWIZZLE_R,
+ /*g*/ VK_COMPONENT_SWIZZLE_G,
+ /*b*/ VK_COMPONENT_SWIZZLE_B,
+ /*a*/ VK_COMPONENT_SWIZZLE_A,
+ },
+ /*subresourceRange*/ {
+ /*aspectMask*/ VK_IMAGE_ASPECT_COLOR_BIT,
+ /*baseMipLevel*/ 0,
+ /*levelCount*/ 1,
+ /*baseArrayLayer*/ 0,
+ /*layerCount*/ 1
},
- .subresourceRange = { .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .baseMipLevel = 0, .levelCount = 1, .baseArrayLayer = 0, .layerCount = 1 },
};
window->swapchain_image_resources[i].image = swapchainImages[i];
@@ -906,44 +949,44 @@ Error VulkanContext::_update_swap_chain(Window *window) {
{
const VkAttachmentDescription attachment = {
- .flags = 0,
- .format = format,
- .samples = VK_SAMPLE_COUNT_1_BIT,
- .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
- .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
- .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
- .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
- .finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
+ /*flags*/ 0,
+ /*format*/ format,
+ /*samples*/ VK_SAMPLE_COUNT_1_BIT,
+ /*loadOp*/ VK_ATTACHMENT_LOAD_OP_CLEAR,
+ /*storeOp*/ VK_ATTACHMENT_STORE_OP_STORE,
+ /*stencilLoadOp*/ VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ /*stencilStoreOp*/ VK_ATTACHMENT_STORE_OP_DONT_CARE,
+ /*initialLayout*/ VK_IMAGE_LAYOUT_UNDEFINED,
+ /*finalLayout*/ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
};
const VkAttachmentReference color_reference = {
- .attachment = 0,
- .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
+ /*attachment*/ 0,
+ /*layout*/ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
};
const VkSubpassDescription subpass = {
- .flags = 0,
- .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
- .inputAttachmentCount = 0,
- .pInputAttachments = NULL,
- .colorAttachmentCount = 1,
- .pColorAttachments = &color_reference,
- .pResolveAttachments = NULL,
- .pDepthStencilAttachment = NULL,
- .preserveAttachmentCount = 0,
- .pPreserveAttachments = NULL,
+ /*flags*/ 0,
+ /*pipelineBindPoint*/ VK_PIPELINE_BIND_POINT_GRAPHICS,
+ /*inputAttachmentCount*/ 0,
+ /*pInputAttachments*/ NULL,
+ /*colorAttachmentCount*/ 1,
+ /*pColorAttachments*/ &color_reference,
+ /*pResolveAttachments*/ NULL,
+ /*pDepthStencilAttachment*/ NULL,
+ /*preserveAttachmentCount*/ 0,
+ /*pPreserveAttachments*/ NULL,
};
const VkRenderPassCreateInfo rp_info = {
- .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
- .pNext = NULL,
- .flags = 0,
- .attachmentCount = 1,
- .pAttachments = &attachment,
- .subpassCount = 1,
- .pSubpasses = &subpass,
- .dependencyCount = 0,
- .pDependencies = NULL,
+ /*sTyp*/ VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*attachmentCount*/ 1,
+ /*pAttachments*/ &attachment,
+ /*subpassCount*/ 1,
+ /*pSubpasses*/ &subpass,
+ /*dependencyCount*/ 0,
+ /*pDependencies*/ NULL,
};
err = vkCreateRenderPass(device, &rp_info, NULL, &window->render_pass);
@@ -951,14 +994,15 @@ Error VulkanContext::_update_swap_chain(Window *window) {
for (uint32_t i = 0; i < swapchainImageCount; i++) {
const VkFramebufferCreateInfo fb_info = {
- .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
- .pNext = NULL,
- .renderPass = window->render_pass,
- .attachmentCount = 1,
- .pAttachments = &window->swapchain_image_resources[i].view,
- .width = (uint32_t)window->width,
- .height = (uint32_t)window->height,
- .layers = 1,
+ /*sType*/ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*renderPass*/ window->render_pass,
+ /*attachmentCount*/ 1,
+ /*pAttachments*/ &window->swapchain_image_resources[i].view,
+ /*width*/ (uint32_t)window->width,
+ /*height*/ (uint32_t)window->height,
+ /*layers*/ 1,
};
err = vkCreateFramebuffer(device, &fb_info, NULL, &window->swapchain_image_resources[i].framebuffer);
@@ -970,19 +1014,19 @@ Error VulkanContext::_update_swap_chain(Window *window) {
if (separate_present_queue) {
const VkCommandPoolCreateInfo present_cmd_pool_info = {
- .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
- .pNext = NULL,
- .flags = 0,
- .queueFamilyIndex = present_queue_family_index,
+ /*sType*/ VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ 0,
+ /*queueFamilyIndex*/ present_queue_family_index,
};
err = vkCreateCommandPool(device, &present_cmd_pool_info, NULL, &window->present_cmd_pool);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
const VkCommandBufferAllocateInfo present_cmd_info = {
- .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
- .pNext = NULL,
- .commandPool = window->present_cmd_pool,
- .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
- .commandBufferCount = 1,
+ /*sType*/ VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
+ /*pNext*/ NULL,
+ /*commandPool*/ window->present_cmd_pool,
+ /*level*/ VK_COMMAND_BUFFER_LEVEL_PRIMARY,
+ /*commandBufferCount*/ 1,
};
for (uint32_t i = 0; i < swapchainImageCount; i++) {
err = vkAllocateCommandBuffers(device, &present_cmd_info,
@@ -990,24 +1034,26 @@ Error VulkanContext::_update_swap_chain(Window *window) {
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
const VkCommandBufferBeginInfo cmd_buf_info = {
- .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
- .pNext = NULL,
- .flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
- .pInheritanceInfo = NULL,
+ /*sType*/ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
+ /*pNext*/ NULL,
+ /*flags*/ VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
+ /*pInheritanceInfo*/ NULL,
};
err = vkBeginCommandBuffer(window->swapchain_image_resources[i].graphics_to_present_cmd, &cmd_buf_info);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
- VkImageMemoryBarrier image_ownership_barrier = { .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
- .pNext = NULL,
- .srcAccessMask = 0,
- .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
- .oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
- .newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
- .srcQueueFamilyIndex = graphics_queue_family_index,
- .dstQueueFamilyIndex = present_queue_family_index,
- .image = window->swapchain_image_resources[i].image,
- .subresourceRange = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } };
+ VkImageMemoryBarrier image_ownership_barrier = {
+ /*sType*/ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
+ /*pNext*/ NULL,
+ /*srcAccessMask*/ 0,
+ /*dstAccessMask*/ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
+ /*oldLayout*/ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
+ /*newLayout*/ VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
+ /*srcQueueFamilyIndex*/ graphics_queue_family_index,
+ /*dstQueueFamilyIndex*/ present_queue_family_index,
+ /*image*/ window->swapchain_image_resources[i].image,
+ /*subresourceRange*/ { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }
+ };
vkCmdPipelineBarrier(window->swapchain_image_resources[i].graphics_to_present_cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, NULL, 0, NULL, 1, &image_ownership_barrier);
@@ -1233,13 +1279,13 @@ Error VulkanContext::swap_buffers() {
// If we are using separate queues we have to wait for image ownership,
// otherwise wait for draw complete
VkPresentInfoKHR present = {
- .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
- .pNext = NULL,
- .waitSemaphoreCount = 1,
- .pWaitSemaphores = (separate_present_queue) ? &image_ownership_semaphores[frame_index] : &draw_complete_semaphores[frame_index],
- .swapchainCount = 0,
- .pSwapchains = NULL,
- .pImageIndices = NULL,
+ /*sType*/ VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
+ /*pNext*/ NULL,
+ /*waitSemaphoreCount*/ 1,
+ /*pWaitSemaphores*/ (separate_present_queue) ? &image_ownership_semaphores[frame_index] : &draw_complete_semaphores[frame_index],
+ /*swapchainCount*/ 0,
+ /*pSwapchain*/ NULL,
+ /*pImageIndices*/ NULL,
};
VkSwapchainKHR *pSwapchains = (VkSwapchainKHR *)alloca(sizeof(VkSwapchainKHR *) * windows.size());
@@ -1270,21 +1316,21 @@ Error VulkanContext::swap_buffers() {
uint32_t eighthOfWidth = width / 8;
uint32_t eighthOfHeight = height / 8;
VkRectLayerKHR rect = {
- .offset.x = eighthOfWidth,
- .offset.y = eighthOfHeight,
- .extent.width = eighthOfWidth * 6,
- .extent.height = eighthOfHeight * 6,
- .layer = 0,
+ /*offset.x*/ eighthOfWidth,
+ /*offset.y*/ eighthOfHeight,
+ /*extent.width*/ eighthOfWidth * 6,
+ /*extent.height*/ eighthOfHeight * 6,
+ /*layer*/ 0,
};
VkPresentRegionKHR region = {
- .rectangleCount = 1,
- .pRectangles = &rect,
+ /*rectangleCount*/ 1,
+ /*pRectangles*/ &rect,
};
VkPresentRegionsKHR regions = {
- .sType = VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR,
- .pNext = present.pNext,
- .swapchainCount = present.swapchainCount,
- .pRegions = &region,
+ /*sType*/ VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR,
+ /*pNext*/ present.pNext,
+ /*swapchainCount*/ present.swapchainCount,
+ /*pRegions*/ &region,
};
present.pNext = &regions;
}
@@ -1316,10 +1362,10 @@ Error VulkanContext::swap_buffers() {
prev_desired_present_time = ptime.desiredPresentTime;
VkPresentTimesInfoGOOGLE present_time = {
- .sType = VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE,
- .pNext = present.pNext,
- .swapchainCount = present.swapchainCount,
- .pTimes = &ptime,
+ /*sType*/ VK_STRUCTURE_TYPE_PRESENT_TIMES_INFO_GOOGLE,
+ /*pNext*/ present.pNext,
+ /*swapchainCount*/ present.swapchainCount,
+ /*pTimes*/ &ptime,
};
if (VK_GOOGLE_display_timing_enabled) {
present.pNext = &present_time;
@@ -1392,3 +1438,6 @@ VulkanContext::VulkanContext() {
swapchainImageCount = 0;
last_window_id = 0;
}
+
+VulkanContext::~VulkanContext() {
+}
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index 50205c1abb..90368f270b 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -1,3 +1,33 @@
+/*************************************************************************/
+/* vulkan_context.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
#ifndef VULKAN_CONTEXT_H
#define VULKAN_CONTEXT_H
@@ -174,7 +204,9 @@ public:
Error prepare_buffers();
Error swap_buffers();
Error initialize();
+
VulkanContext();
+ virtual ~VulkanContext();
};
#endif // VULKAN_DEVICE_H