summaryrefslogtreecommitdiff
path: root/drivers/vulkan
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vulkan')
-rw-r--r--drivers/vulkan/SCsub1
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp25
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h4
-rw-r--r--drivers/vulkan/vulkan_context.cpp37
-rw-r--r--drivers/vulkan/vulkan_context.h55
5 files changed, 58 insertions, 64 deletions
diff --git a/drivers/vulkan/SCsub b/drivers/vulkan/SCsub
index 61d91711da..13fcaf16d2 100644
--- a/drivers/vulkan/SCsub
+++ b/drivers/vulkan/SCsub
@@ -59,7 +59,6 @@ elif env["builtin_vulkan"]:
if env["platform"] == "windows":
loader_sources.append("dirent_on_windows.c")
- loader_sources.append("dxgi_loader.c")
env_thirdparty.AppendUnique(
CPPDEFINES=[
"VK_USE_PLATFORM_WIN32_KHR",
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 2cbb305153..902876616b 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -30,10 +30,10 @@
#include "rendering_device_vulkan.h"
-#include "core/hashfuncs.h"
+#include "core/config/project_settings.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
-#include "core/project_settings.h"
+#include "core/templates/hashfuncs.h"
#include "drivers/vulkan/vulkan_context.h"
#include "thirdparty/spirv-reflect/spirv_reflect.h"
@@ -2947,7 +2947,7 @@ Error RenderingDeviceVulkan::texture_clear(RID p_texture, const Color &p_color,
image_memory_barrier.srcAccessMask = valid_texture_access;
image_memory_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
image_memory_barrier.oldLayout = src_tex->layout;
- image_memory_barrier.oldLayout = clear_layout;
+ image_memory_barrier.newLayout = clear_layout;
image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
@@ -3227,8 +3227,8 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF
}
if (reference.layout != description.finalLayout) {
// NOTE: this should be smarter based on the textures knowledge of it's subsequent role
- dependency_from_external.dstStageMask |= VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
- dependency_from_external.dstAccessMask |= VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
+ dependency_to_external.dstStageMask |= VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+ dependency_to_external.dstAccessMask |= VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
}
}
@@ -4312,8 +4312,10 @@ RID RenderingDeviceVulkan::shader_create(const Vector<ShaderStageData> &p_stages
}
pipeline_layout_create_info.pSetLayouts = layouts.ptr();
+ // Needs to be declared in this outer scope, otherwise it may not outlive its assignment
+ // to pipeline_layout_create_info.
+ VkPushConstantRange push_constant_range;
if (push_constant.push_constant_size) {
- VkPushConstantRange push_constant_range;
push_constant_range.stageFlags = push_constant.push_constants_vk_stage;
push_constant_range.offset = 0;
push_constant_range.size = push_constant.push_constant_size;
@@ -4610,12 +4612,12 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms,
}
}
ERR_FAIL_COND_V_MSG(uniform_idx == -1, RID(),
- "All the shader bindings for the given set must be covered by the uniforms provided. Binding (" + itos(set_uniform.binding) + ") was not provided.");
+ "All the shader bindings for the given set must be covered by the uniforms provided. Binding (" + itos(set_uniform.binding) + "), set (" + itos(p_shader_set) + ") was not provided.");
const Uniform &uniform = uniforms[uniform_idx];
ERR_FAIL_COND_V_MSG(uniform.type != set_uniform.type, RID(),
- "Mismatch uniform type for binding (" + itos(set_uniform.binding) + "). Expected '" + shader_uniform_names[set_uniform.type] + "', supplied: '" + shader_uniform_names[uniform.type] + "'.");
+ "Mismatch uniform type for binding (" + itos(set_uniform.binding) + "), set (" + itos(p_shader_set) + "). Expected '" + shader_uniform_names[set_uniform.type] + "', supplied: '" + shader_uniform_names[uniform.type] + "'.");
VkWriteDescriptorSet write; //common header
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
@@ -6793,13 +6795,12 @@ void RenderingDeviceVulkan::compute_list_add_barrier(ComputeListID p_list) {
void RenderingDeviceVulkan::compute_list_end() {
ERR_FAIL_COND(!compute_list);
- const VkPipelineStageFlags dest_stage_mask = VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT;
for (Set<Texture *>::Element *E = compute_list->state.textures_to_sampled_layout.front(); E; E = E->next()) {
VkImageMemoryBarrier image_memory_barrier;
image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
image_memory_barrier.pNext = nullptr;
image_memory_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
- image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
+ image_memory_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT;
image_memory_barrier.oldLayout = E->get()->layout;
image_memory_barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@@ -6813,7 +6814,7 @@ void RenderingDeviceVulkan::compute_list_end() {
image_memory_barrier.subresourceRange.layerCount = E->get()->layers;
// TODO: Look at the usages in the compute list and determine tighter dst stage and access masks based on some "final" usage equivalent
- vkCmdPipelineBarrier(compute_list->command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dest_stage_mask, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
+ vkCmdPipelineBarrier(compute_list->command_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, &image_memory_barrier);
E->get()->layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
@@ -6823,7 +6824,7 @@ void RenderingDeviceVulkan::compute_list_end() {
#ifdef FORCE_FULL_BARRIER
_full_barrier(true);
#else
- _memory_barrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dest_stage_mask, VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT, true);
+ _memory_barrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INDIRECT_COMMAND_READ_BIT, true);
#endif
}
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index e6cbf2e01d..6463078d0a 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -31,9 +31,9 @@
#ifndef RENDERING_DEVICE_VULKAN_H
#define RENDERING_DEVICE_VULKAN_H
-#include "core/oa_hash_map.h"
#include "core/os/thread_safe.h"
-#include "core/rid_owner.h"
+#include "core/templates/oa_hash_map.h"
+#include "core/templates/rid_owner.h"
#include "servers/rendering/rendering_device.h"
#ifdef DEBUG_ENABLED
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 997ed3935f..28634d5e70 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -30,9 +30,9 @@
#include "vulkan_context.h"
-#include "core/engine.h"
-#include "core/project_settings.h"
-#include "core/ustring.h"
+#include "core/config/engine.h"
+#include "core/config/project_settings.h"
+#include "core/string/ustring.h"
#include "core/version.h"
#include "vk_enum_string_helper.h"
@@ -154,7 +154,7 @@ VkBool32 VulkanContext::_check_layers(uint32_t check_count, const char **check_n
}
}
if (!found) {
- ERR_PRINT("Can't find layer: " + String(check_names[i]));
+ WARN_PRINT("Can't find layer: " + String(check_names[i]));
return 0;
}
}
@@ -707,7 +707,8 @@ Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, VkSurfa
// We use a single GPU, but we need a surface to initialize the
// queues, so this process must be deferred until a surface
// is created.
- _initialize_queues(p_surface);
+ Error err = _initialize_queues(p_surface);
+ ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
}
Window window;
@@ -1479,23 +1480,6 @@ VkPhysicalDeviceLimits VulkanContext::get_device_limits() const {
return gpu_props.limits;
}
-VulkanContext::VulkanContext() {
- queue_props = nullptr;
- command_buffer_count = 0;
- instance_validation_layers = nullptr;
- use_validation_layers = true;
- VK_KHR_incremental_present_enabled = true;
- VK_GOOGLE_display_timing_enabled = true;
-
- command_buffer_queue.resize(1); //first one is the setup command always
- command_buffer_queue.write[0] = nullptr;
- command_buffer_count = 1;
- queues_initialized = false;
-
- buffers_prepared = false;
- swapchainImageCount = 0;
-}
-
RID VulkanContext::local_device_create() {
LocalDevice ld;
@@ -1583,6 +1567,13 @@ void VulkanContext::local_device_free(RID p_local_device) {
local_device_owner.free(p_local_device);
}
+VulkanContext::VulkanContext() {
+ use_validation_layers = Engine::get_singleton()->is_validation_layers_enabled();
+
+ command_buffer_queue.resize(1); // First one is always the setup command.
+ command_buffer_queue.write[0] = nullptr;
+}
+
VulkanContext::~VulkanContext() {
if (queue_props) {
free(queue_props);
@@ -1596,7 +1587,7 @@ VulkanContext::~VulkanContext() {
vkDestroySemaphore(device, image_ownership_semaphores[i], nullptr);
}
}
- if (inst_initialized) {
+ if (inst_initialized && use_validation_layers) {
DestroyDebugUtilsMessengerEXT(inst, dbg_messenger, nullptr);
}
vkDestroyDevice(device, nullptr);
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index 9ebea42ecb..26d4b76e86 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -31,12 +31,13 @@
#ifndef VULKAN_CONTEXT_H
#define VULKAN_CONTEXT_H
-#include "core/error_list.h"
-#include "core/map.h"
+#include "core/error/error_list.h"
#include "core/os/mutex.h"
-#include "core/rid_owner.h"
-#include "core/ustring.h"
+#include "core/string/ustring.h"
+#include "core/templates/map.h"
+#include "core/templates/rid_owner.h"
#include "servers/display_server.h"
+
#include <vulkan/vulkan.h>
class VulkanContext {
@@ -51,13 +52,15 @@ class VulkanContext {
VkPhysicalDevice gpu;
VkPhysicalDeviceProperties gpu_props;
uint32_t queue_family_count;
- VkQueueFamilyProperties *queue_props;
+ VkQueueFamilyProperties *queue_props = nullptr;
VkDevice device;
bool device_initialized = false;
bool inst_initialized = false;
- //present
- bool queues_initialized;
+ bool buffers_prepared = false;
+
+ // Present queue.
+ bool queues_initialized = false;
uint32_t graphics_queue_family_index;
uint32_t present_queue_family_index;
bool separate_present_queue;
@@ -78,7 +81,6 @@ class VulkanContext {
VkCommandBuffer graphics_to_present_cmd;
VkImageView view;
VkFramebuffer framebuffer;
-
} SwapchainImageResources;
struct Window {
@@ -89,7 +91,7 @@ class VulkanContext {
uint32_t current_buffer = 0;
int width = 0;
int height = 0;
- VkCommandPool present_cmd_pool; //for separate present queue
+ VkCommandPool present_cmd_pool; // For separate present queue.
VkRenderPass render_pass = VK_NULL_HANDLE;
};
@@ -102,19 +104,24 @@ class VulkanContext {
RID_Owner<LocalDevice, true> local_device_owner;
Map<DisplayServer::WindowID, Window> windows;
- uint32_t swapchainImageCount;
+ uint32_t swapchainImageCount = 0;
- //commands
+ // Commands.
bool prepared;
- //extensions
- bool VK_KHR_incremental_present_enabled;
- bool VK_GOOGLE_display_timing_enabled;
- const char **instance_validation_layers;
- uint32_t enabled_extension_count;
- uint32_t enabled_layer_count;
+ Vector<VkCommandBuffer> command_buffer_queue;
+ int command_buffer_count = 1;
+
+ // Extensions.
+
+ bool VK_KHR_incremental_present_enabled = true;
+ bool VK_GOOGLE_display_timing_enabled = true;
+ uint32_t enabled_extension_count = 0;
const char *extension_names[MAX_EXTENSIONS];
+
+ const char **instance_validation_layers = nullptr;
+ uint32_t enabled_layer_count = 0;
const char *enabled_layers[MAX_LAYERS];
PFN_vkCreateDebugUtilsMessengerEXT CreateDebugUtilsMessengerEXT;
@@ -142,7 +149,8 @@ class VulkanContext {
Error _initialize_extensions();
VkBool32 _check_layers(uint32_t check_count, const char **check_names, uint32_t layer_count, VkLayerProperties *layers);
- static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_messenger_callback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
+ static VKAPI_ATTR VkBool32 VKAPI_CALL _debug_messenger_callback(
+ VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
VkDebugUtilsMessageTypeFlagsEXT messageType,
const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData,
void *pUserData);
@@ -160,12 +168,11 @@ class VulkanContext {
Error _create_swap_chain();
Error _create_semaphores();
- Vector<VkCommandBuffer> command_buffer_queue;
- int command_buffer_count;
-
protected:
virtual const char *_get_platform_surface_extension() const = 0;
- // virtual VkResult _create_surface(VkSurfaceKHR *surface, VkInstance p_instance) = 0;
+
+ // Enabled via command line argument.
+ bool use_validation_layers = false;
virtual Error _window_create(DisplayServer::WindowID p_window_id, VkSurfaceKHR p_surface, int p_width, int p_height);
@@ -173,10 +180,6 @@ protected:
return inst;
}
- bool buffers_prepared;
-
- bool use_validation_layers;
-
public:
VkDevice get_device();
VkPhysicalDevice get_physical_device();