Unverified Commit 4db1f160 by Rémi Verschelde Committed by GitHub

Merge pull request #39254 from akien-mga/vulkan-init-declare

Vulkan: Initialize struct members on declaration
parents 65a78711 5e62a2ee
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "core/os/os.h" #include "core/os/os.h"
#include "core/project_settings.h" #include "core/project_settings.h"
#include "drivers/vulkan/vulkan_context.h" #include "drivers/vulkan/vulkan_context.h"
#include "thirdparty/spirv-reflect/spirv_reflect.h" #include "thirdparty/spirv-reflect/spirv_reflect.h"
//#define FORCE_FULL_BARRIER //#define FORCE_FULL_BARRIER
...@@ -5905,7 +5906,7 @@ void RenderingDeviceVulkan::draw_list_bind_render_pipeline(DrawListID p_list, RI ...@@ -5905,7 +5906,7 @@ void RenderingDeviceVulkan::draw_list_bind_render_pipeline(DrawListID p_list, RI
if (pipeline->push_constant_size) { if (pipeline->push_constant_size) {
dl->state.pipeline_push_constant_stages = pipeline->push_constant_stages; dl->state.pipeline_push_constant_stages = pipeline->push_constant_stages;
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
dl->validation.pipeline_push_constant_suppplied = false; dl->validation.pipeline_push_constant_supplied = false;
#endif #endif
} }
...@@ -6036,7 +6037,7 @@ void RenderingDeviceVulkan::draw_list_set_push_constant(DrawListID p_list, const ...@@ -6036,7 +6037,7 @@ void RenderingDeviceVulkan::draw_list_set_push_constant(DrawListID p_list, const
#endif #endif
vkCmdPushConstants(dl->command_buffer, dl->state.pipeline_layout, dl->state.pipeline_push_constant_stages, 0, p_data_size, p_data); vkCmdPushConstants(dl->command_buffer, dl->state.pipeline_layout, dl->state.pipeline_push_constant_stages, 0, p_data_size, p_data);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
dl->validation.pipeline_push_constant_suppplied = true; dl->validation.pipeline_push_constant_supplied = true;
#endif #endif
} }
...@@ -6064,7 +6065,7 @@ void RenderingDeviceVulkan::draw_list_draw(DrawListID p_list, bool p_use_indices ...@@ -6064,7 +6065,7 @@ void RenderingDeviceVulkan::draw_list_draw(DrawListID p_list, bool p_use_indices
if (dl->validation.pipeline_push_constant_size > 0) { if (dl->validation.pipeline_push_constant_size > 0) {
//using push constants, check that they were supplied //using push constants, check that they were supplied
ERR_FAIL_COND_MSG(!dl->validation.pipeline_push_constant_suppplied, ERR_FAIL_COND_MSG(!dl->validation.pipeline_push_constant_supplied,
"The shader in this pipeline requires a push constant to be set before drawing, but it's not present."); "The shader in this pipeline requires a push constant to be set before drawing, but it's not present.");
} }
...@@ -6300,7 +6301,7 @@ void RenderingDeviceVulkan::compute_list_bind_compute_pipeline(ComputeListID p_l ...@@ -6300,7 +6301,7 @@ void RenderingDeviceVulkan::compute_list_bind_compute_pipeline(ComputeListID p_l
if (pipeline->push_constant_size) { if (pipeline->push_constant_size) {
cl->state.pipeline_push_constant_stages = pipeline->push_constant_stages; cl->state.pipeline_push_constant_stages = pipeline->push_constant_stages;
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
cl->validation.pipeline_push_constant_suppplied = false; cl->validation.pipeline_push_constant_supplied = false;
#endif #endif
} }
...@@ -6433,7 +6434,7 @@ void RenderingDeviceVulkan::compute_list_set_push_constant(ComputeListID p_list, ...@@ -6433,7 +6434,7 @@ void RenderingDeviceVulkan::compute_list_set_push_constant(ComputeListID p_list,
#endif #endif
vkCmdPushConstants(cl->command_buffer, cl->state.pipeline_layout, cl->state.pipeline_push_constant_stages, 0, p_data_size, p_data); vkCmdPushConstants(cl->command_buffer, cl->state.pipeline_layout, cl->state.pipeline_push_constant_stages, 0, p_data_size, p_data);
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
cl->validation.pipeline_push_constant_suppplied = true; cl->validation.pipeline_push_constant_supplied = true;
#endif #endif
} }
...@@ -6460,7 +6461,7 @@ void RenderingDeviceVulkan::compute_list_dispatch(ComputeListID p_list, uint32_t ...@@ -6460,7 +6461,7 @@ void RenderingDeviceVulkan::compute_list_dispatch(ComputeListID p_list, uint32_t
if (cl->validation.pipeline_push_constant_size > 0) { if (cl->validation.pipeline_push_constant_size > 0) {
//using push constants, check that they were supplied //using push constants, check that they were supplied
ERR_FAIL_COND_MSG(!cl->validation.pipeline_push_constant_suppplied, ERR_FAIL_COND_MSG(!cl->validation.pipeline_push_constant_supplied,
"The shader in this pipeline requires a push constant to be set before drawing, but it's not present."); "The shader in this pipeline requires a push constant to be set before drawing, but it's not present.");
} }
......
...@@ -42,7 +42,9 @@ ...@@ -42,7 +42,9 @@
#endif #endif
#endif #endif
#include "vk_mem_alloc.h" #include "vk_mem_alloc.h"
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
//todo: //todo:
//compute //compute
//push constants //push constants
...@@ -202,15 +204,10 @@ class RenderingDeviceVulkan : public RenderingDevice { ...@@ -202,15 +204,10 @@ class RenderingDeviceVulkan : public RenderingDevice {
Error _insert_staging_block(); Error _insert_staging_block();
struct Buffer { struct Buffer {
uint32_t size; uint32_t size = 0;
VkBuffer buffer; VkBuffer buffer = VK_NULL_HANDLE;
VmaAllocation allocation; VmaAllocation allocation = nullptr;
VkDescriptorBufferInfo buffer_info; //used for binding VkDescriptorBufferInfo buffer_info; //used for binding
Buffer() {
size = 0;
buffer = VK_NULL_HANDLE;
allocation = nullptr;
}
}; };
Error _buffer_allocate(Buffer *p_buffer, uint32_t p_size, uint32_t p_usage, VmaMemoryUsage p_mapping); Error _buffer_allocate(Buffer *p_buffer, uint32_t p_size, uint32_t p_usage, VmaMemoryUsage p_mapping);
...@@ -570,7 +567,7 @@ class RenderingDeviceVulkan : public RenderingDevice { ...@@ -570,7 +567,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
struct DescriptorPoolKey { struct DescriptorPoolKey {
union { union {
struct { struct {
uint16_t uniform_type[UNIFORM_TYPE_MAX]; //using 16 bits because, for sending arrays, each element is a pool set. uint16_t uniform_type[UNIFORM_TYPE_MAX]; // Using 16 bits because, for sending arrays, each element is a pool set.
}; };
struct { struct {
uint64_t key1; uint64_t key1;
...@@ -712,106 +709,67 @@ class RenderingDeviceVulkan : public RenderingDevice { ...@@ -712,106 +709,67 @@ class RenderingDeviceVulkan : public RenderingDevice {
Vector<SplitDrawListAllocator> split_draw_list_allocators; Vector<SplitDrawListAllocator> split_draw_list_allocators;
struct DrawList { struct DrawList {
VkCommandBuffer command_buffer; //if persistent, this is owned, otherwise it's shared with the ringbuffer VkCommandBuffer command_buffer; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
Rect2i viewport; Rect2i viewport;
struct SetState { struct SetState {
uint32_t pipeline_expected_format; uint32_t pipeline_expected_format = 0;
uint32_t uniform_set_format; uint32_t uniform_set_format = 0;
VkDescriptorSet descriptor_set; VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
RID uniform_set; RID uniform_set;
bool bound; bool bound = false;
SetState() {
bound = false;
pipeline_expected_format = 0;
uniform_set_format = 0;
descriptor_set = VK_NULL_HANDLE;
}
}; };
struct State { struct State {
SetState sets[MAX_UNIFORM_SETS]; SetState sets[MAX_UNIFORM_SETS];
uint32_t set_count; uint32_t set_count = 0;
RID pipeline; RID pipeline;
RID pipeline_shader; RID pipeline_shader;
VkPipelineLayout pipeline_layout; VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
RID vertex_array; RID vertex_array;
RID index_array; RID index_array;
uint32_t pipeline_push_constant_stages; uint32_t pipeline_push_constant_stages = 0;
State() {
set_count = 0;
pipeline_layout = VK_NULL_HANDLE;
pipeline_push_constant_stages = 0;
}
} state; } state;
#ifdef DEBUG_ENABLED
#ifdef DEBUG_ENABLED
struct Validation { struct Validation {
bool active; //means command buffer was not closes, so you can keep adding things bool active = true; // Means command buffer was not closed, so you can keep adding things.
FramebufferFormatID framebuffer_format; FramebufferFormatID framebuffer_format = INVALID_ID;
//actual render pass values // Actual render pass values.
uint32_t dynamic_state; uint32_t dynamic_state = 0;
VertexFormatID vertex_format; //INVALID_ID if not set VertexFormatID vertex_format = INVALID_ID;
uint32_t vertex_array_size; //0 if not set uint32_t vertex_array_size = 0;
uint32_t vertex_max_instances_allowed; uint32_t vertex_max_instances_allowed = 0xFFFFFFFF;
bool index_buffer_uses_restart_indices; bool index_buffer_uses_restart_indices = false;
uint32_t index_array_size; //0 if index buffer not set uint32_t index_array_size = 0;
uint32_t index_array_max_index; uint32_t index_array_max_index = 0;
uint32_t index_array_offset; uint32_t index_array_offset;
Vector<uint32_t> set_formats; Vector<uint32_t> set_formats;
Vector<bool> set_bound; Vector<bool> set_bound;
Vector<RID> set_rids; Vector<RID> set_rids;
//last pipeline set values // Last pipeline set values.
bool pipeline_active; bool pipeline_active = false;
uint32_t pipeline_dynamic_state; uint32_t pipeline_dynamic_state = 0;
VertexFormatID pipeline_vertex_format; VertexFormatID pipeline_vertex_format = INVALID_ID;
RID pipeline_shader; RID pipeline_shader;
uint32_t invalid_set_from; uint32_t invalid_set_from = 0;
bool pipeline_uses_restart_indices; bool pipeline_uses_restart_indices = false;
uint32_t pipeline_primitive_divisor; uint32_t pipeline_primitive_divisor;
uint32_t pipeline_primitive_minimum; uint32_t pipeline_primitive_minimum;
Vector<uint32_t> pipeline_set_formats; Vector<uint32_t> pipeline_set_formats;
uint32_t pipeline_push_constant_size; uint32_t pipeline_push_constant_size = 0;
bool pipeline_push_constant_suppplied; bool pipeline_push_constant_supplied = false;
Validation() {
active = true;
dynamic_state = 0;
vertex_format = INVALID_ID;
vertex_array_size = 0;
vertex_max_instances_allowed = 0xFFFFFFFF;
framebuffer_format = INVALID_ID;
index_array_size = 0; //not sent
index_array_max_index = 0; //not set
index_buffer_uses_restart_indices = false;
invalid_set_from = 0;
//pipeline state initalize
pipeline_active = false;
pipeline_dynamic_state = 0;
pipeline_vertex_format = INVALID_ID;
pipeline_uses_restart_indices = false;
pipeline_push_constant_size = 0;
pipeline_push_constant_suppplied = false;
}
} validation; } validation;
#else #else
struct Validation { struct Validation {
uint32_t vertex_array_size; //0 if not set uint32_t vertex_array_size = 0;
uint32_t index_array_size; //0 if index buffer not set uint32_t index_array_size = 0;
uint32_t index_array_offset; uint32_t index_array_offset;
Validation() {
vertex_array_size = 0;
index_array_size = 0; //not sent
}
} validation; } validation;
#endif #endif
}; };
DrawList *draw_list; //one for regular draw lists, multiple for split. DrawList *draw_list; // One for regular draw lists, multiple for split.
uint32_t draw_list_count; uint32_t draw_list_count;
bool draw_list_split; bool draw_list_split;
Vector<RID> draw_list_bound_textures; Vector<RID> draw_list_bound_textures;
...@@ -828,62 +786,39 @@ class RenderingDeviceVulkan : public RenderingDevice { ...@@ -828,62 +786,39 @@ class RenderingDeviceVulkan : public RenderingDevice {
/**********************/ /**********************/
struct ComputeList { struct ComputeList {
VkCommandBuffer command_buffer; //if persistent, this is owned, otherwise it's shared with the ringbuffer VkCommandBuffer command_buffer; // If persistent, this is owned, otherwise it's shared with the ringbuffer.
struct SetState { struct SetState {
uint32_t pipeline_expected_format; uint32_t pipeline_expected_format = 0;
uint32_t uniform_set_format; uint32_t uniform_set_format = 0;
VkDescriptorSet descriptor_set; VkDescriptorSet descriptor_set = VK_NULL_HANDLE;
RID uniform_set; RID uniform_set;
bool bound; bool bound = false;
SetState() {
bound = false;
pipeline_expected_format = 0;
uniform_set_format = 0;
descriptor_set = VK_NULL_HANDLE;
}
}; };
struct State { struct State {
Set<Texture *> textures_to_sampled_layout; Set<Texture *> textures_to_sampled_layout;
SetState sets[MAX_UNIFORM_SETS]; SetState sets[MAX_UNIFORM_SETS];
uint32_t set_count; uint32_t set_count = 0;
RID pipeline; RID pipeline;
RID pipeline_shader; RID pipeline_shader;
VkPipelineLayout pipeline_layout; VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
uint32_t pipeline_push_constant_stages; uint32_t pipeline_push_constant_stages = 0;
State() {
set_count = 0;
pipeline_layout = VK_NULL_HANDLE;
pipeline_push_constant_stages = 0;
}
} state; } state;
#ifdef DEBUG_ENABLED
#ifdef DEBUG_ENABLED
struct Validation { struct Validation {
bool active; //means command buffer was not closes, so you can keep adding things bool active = true; // Means command buffer was not closed, so you can keep adding things.
Vector<uint32_t> set_formats; Vector<uint32_t> set_formats;
Vector<bool> set_bound; Vector<bool> set_bound;
Vector<RID> set_rids; Vector<RID> set_rids;
//last pipeline set values // Last pipeline set values.
bool pipeline_active; bool pipeline_active = false;
RID pipeline_shader; RID pipeline_shader;
uint32_t invalid_set_from; uint32_t invalid_set_from = 0;
Vector<uint32_t> pipeline_set_formats; Vector<uint32_t> pipeline_set_formats;
uint32_t pipeline_push_constant_size; uint32_t pipeline_push_constant_size = 0;
bool pipeline_push_constant_suppplied; bool pipeline_push_constant_supplied = false;
Validation() {
active = true;
invalid_set_from = 0;
//pipeline state initalize
pipeline_active = false;
pipeline_push_constant_size = 0;
pipeline_push_constant_suppplied = false;
}
} validation; } validation;
#endif #endif
}; };
......
...@@ -80,29 +80,15 @@ class VulkanContext { ...@@ -80,29 +80,15 @@ class VulkanContext {
} SwapchainImageResources; } SwapchainImageResources;
struct Window { struct Window {
bool is_minimzed; VkSurfaceKHR surface = VK_NULL_HANDLE;
VkSurfaceKHR surface; VkSwapchainKHR swapchain = VK_NULL_HANDLE;
VkSwapchainKHR swapchain; SwapchainImageResources *swapchain_image_resources = VK_NULL_HANDLE;
SwapchainImageResources *swapchain_image_resources; VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
VkPresentModeKHR presentMode; uint32_t current_buffer = 0;
uint32_t current_buffer; int width = 0;
int width; int height = 0;
int height;
VkCommandPool present_cmd_pool; //for separate present queue VkCommandPool present_cmd_pool; //for separate present queue
VkRenderPass render_pass = VK_NULL_HANDLE;
VkRenderPass render_pass;
Window() {
width = 0;
height = 0;
render_pass = VK_NULL_HANDLE;
current_buffer = 0;
surface = VK_NULL_HANDLE;
swapchain_image_resources = VK_NULL_HANDLE;
swapchain = VK_NULL_HANDLE;
is_minimzed = false;
presentMode = VK_PRESENT_MODE_FIFO_KHR;
}
}; };
struct LocalDevice { struct LocalDevice {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment