summaryrefslogtreecommitdiff
path: root/drivers/vulkan/rendering_device_vulkan.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vulkan/rendering_device_vulkan.h')
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h68
1 files changed, 42 insertions, 26 deletions
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index 30c10e922e..6432946fbe 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -34,11 +34,13 @@
#include "core/oa_hash_map.h"
#include "core/os/thread_safe.h"
#include "core/rid_owner.h"
-#include "servers/visual/rendering_device.h"
+#include "servers/rendering/rendering_device.h"
#ifdef DEBUG_ENABLED
+#ifndef _DEBUG
#define _DEBUG
#endif
+#endif
#include "vk_mem_alloc.h"
#include <vulkan/vulkan.h>
//todo:
@@ -78,7 +80,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
static void get_compressed_image_format_block_dimensions(DataFormat p_format, uint32_t &r_w, uint32_t &r_h);
uint32_t get_compressed_image_format_block_byte_size(DataFormat p_format);
static uint32_t get_compressed_image_format_pixel_rshift(DataFormat p_format);
- static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = NULL, uint32_t *r_blockh = NULL, uint32_t *r_depth = NULL);
+ static uint32_t get_image_format_required_size(DataFormat p_format, uint32_t p_width, uint32_t p_height, uint32_t p_depth, uint32_t p_mipmaps, uint32_t *r_blockw = nullptr, uint32_t *r_blockh = nullptr, uint32_t *r_depth = nullptr);
static uint32_t get_image_required_mipmaps(uint32_t p_width, uint32_t p_height, uint32_t p_depth);
static bool format_has_stencil(DataFormat p_format);
@@ -98,8 +100,8 @@ class RenderingDeviceVulkan : public RenderingDevice {
VkDevice device;
- Map<RID, Set<RID> > dependency_map; //IDs to IDs that depend on it
- Map<RID, Set<RID> > reverse_dependency_map; //same as above, but in reverse
+ Map<RID, Set<RID>> dependency_map; //IDs to IDs that depend on it
+ Map<RID, Set<RID>> reverse_dependency_map; //same as above, but in reverse
void _add_dependency(RID p_id, RID p_depends_on);
void _free_dependencies(RID p_id);
@@ -136,6 +138,8 @@ class RenderingDeviceVulkan : public RenderingDevice {
uint32_t layers;
uint32_t mipmaps;
uint32_t usage_flags;
+ uint32_t base_mipmap;
+ uint32_t base_layer;
Vector<DataFormat> allowed_shared_formats;
@@ -207,8 +211,8 @@ class RenderingDeviceVulkan : public RenderingDevice {
VkDescriptorBufferInfo buffer_info; //used for binding
Buffer() {
size = 0;
- buffer = NULL;
- allocation = NULL;
+ buffer = VK_NULL_HANDLE;
+ allocation = nullptr;
}
};
@@ -260,7 +264,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
}
};
- VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depthcolor_action, int *r_color_attachment_count = NULL);
+ VkRenderPass _render_pass_create(const Vector<AttachmentFormat> &p_format, InitialAction p_initial_action, FinalAction p_final_action, InitialAction p_initial_depth_action, FinalAction p_final_depthcolor_action, int *r_color_attachment_count = nullptr);
// This is a cache and it's never freed, it ensures
// IDs for a given format are always unique.
@@ -328,7 +332,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
RID_Owner<Buffer, true> vertex_buffer_owner;
struct VertexDescriptionKey {
- Vector<VertexDescription> vertex_formats;
+ Vector<VertexAttribute> vertex_formats;
bool operator==(const VertexDescriptionKey &p_key) const {
int vdc = vertex_formats.size();
int vdck = p_key.vertex_formats.size();
@@ -336,11 +340,11 @@ class RenderingDeviceVulkan : public RenderingDevice {
if (vdc != vdck) {
return false;
} else {
- const VertexDescription *a_ptr = vertex_formats.ptr();
- const VertexDescription *b_ptr = p_key.vertex_formats.ptr();
+ const VertexAttribute *a_ptr = vertex_formats.ptr();
+ const VertexAttribute *b_ptr = p_key.vertex_formats.ptr();
for (int i = 0; i < vdc; i++) {
- const VertexDescription &a = a_ptr[i];
- const VertexDescription &b = b_ptr[i];
+ const VertexAttribute &a = a_ptr[i];
+ const VertexAttribute &b = b_ptr[i];
if (a.location != b.location) {
return false;
@@ -365,9 +369,9 @@ class RenderingDeviceVulkan : public RenderingDevice {
uint32_t hash() const {
int vdc = vertex_formats.size();
uint32_t h = hash_djb2_one_32(vdc);
- const VertexDescription *ptr = vertex_formats.ptr();
+ const VertexAttribute *ptr = vertex_formats.ptr();
for (int i = 0; i < vdc; i++) {
- const VertexDescription &vd = ptr[i];
+ const VertexAttribute &vd = ptr[i];
h = hash_djb2_one_32(vd.location, h);
h = hash_djb2_one_32(vd.offset, h);
h = hash_djb2_one_32(vd.format, h);
@@ -389,7 +393,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
HashMap<VertexDescriptionKey, VertexFormatID, VertexDescriptionHash> vertex_format_cache;
struct VertexDescriptionCache {
- Vector<VertexDescription> vertex_formats;
+ Vector<VertexAttribute> vertex_formats;
VkVertexInputBindingDescription *bindings;
VkVertexInputAttributeDescription *attributes;
VkPipelineVertexInputStateCreateInfo create_info;
@@ -602,7 +606,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
uint32_t usage;
};
- Map<DescriptorPoolKey, Set<DescriptorPool *> > descriptor_pools;
+ Map<DescriptorPoolKey, Set<DescriptorPool *>> descriptor_pools;
uint32_t max_descriptors_per_pool;
DescriptorPool *_descriptor_pool_allocate(const DescriptorPoolKey &p_key);
@@ -948,10 +952,12 @@ class RenderingDeviceVulkan : public RenderingDevice {
uint32_t max_timestamp_query_elements;
- Frame *frames; //frames available, they are cycled (usually 3)
+ Frame *frames; //frames available, for main device they are cycled (usually 3), for local devices only 1
int frame; //current frame
int frame_count; //total amount of frames
uint64_t frames_drawn;
+ RID local_device;
+ bool local_device_processing = false;
void _free_pending_resources(int p_frame);
@@ -967,8 +973,11 @@ class RenderingDeviceVulkan : public RenderingDevice {
template <class T>
void _free_rids(T &p_owner, const char *p_type);
+ void _finalize_command_bufers();
+ void _begin_frame();
+
public:
- virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t> > &p_data = Vector<Vector<uint8_t> >());
+ virtual RID texture_create(const TextureFormat &p_format, const TextureView &p_view, const Vector<Vector<uint8_t>> &p_data = Vector<Vector<uint8_t>>());
virtual RID texture_create_shared(const TextureView &p_view, RID p_with_texture);
virtual RID texture_create_shared_from_slice(const TextureView &p_view, RID p_with_texture, uint32_t p_layer, uint32_t p_mipmap, TextureSliceType p_slice_type = TEXTURE_SLICE_2D);
@@ -981,6 +990,7 @@ public:
virtual Error texture_copy(RID p_from_texture, RID p_to_texture, const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_size, uint32_t p_src_mipmap, uint32_t p_dst_mipmap, uint32_t p_src_layer, uint32_t p_dst_layer, bool p_sync_with_draw = false);
virtual Error texture_clear(RID p_texture, const Color &p_color, uint32_t p_base_mipmap, uint32_t p_mipmaps, uint32_t p_base_layer, uint32_t p_layers, bool p_sync_with_draw = false);
+ virtual Error texture_resolve_multisample(RID p_from_texture, RID p_to_texture, bool p_sync_with_draw = false);
/*********************/
/**** FRAMEBUFFER ****/
@@ -1006,7 +1016,7 @@ public:
virtual RID vertex_buffer_create(uint32_t p_size_bytes, const Vector<uint8_t> &p_data = Vector<uint8_t>());
// Internally reference counted, this ID is warranted to be unique for the same description, but needs to be freed as many times as it was allocated
- virtual VertexFormatID vertex_format_create(const Vector<VertexDescription> &p_vertex_formats);
+ virtual VertexFormatID vertex_format_create(const Vector<VertexAttribute> &p_vertex_formats);
virtual RID vertex_array_create(uint32_t p_vertex_count, VertexFormatID p_vertex_format, const Vector<RID> &p_src_buffers);
virtual RID index_buffer_create(uint32_t p_size_indices, IndexBufferFormat p_format, const Vector<uint8_t> &p_data = Vector<uint8_t>(), bool p_use_restart_indices = false);
@@ -1052,15 +1062,15 @@ public:
/**** SCREEN ****/
/****************/
- virtual int screen_get_width(int p_screen = 0) const;
- virtual int screen_get_height(int p_screen = 0) const;
+ virtual int screen_get_width(DisplayServer::WindowID p_screen = 0) const;
+ virtual int screen_get_height(DisplayServer::WindowID p_screen = 0) const;
virtual FramebufferFormatID screen_get_framebuffer_format() const;
/********************/
/**** DRAW LISTS ****/
/********************/
- virtual DrawListID draw_list_begin_for_screen(int p_screen = 0, const Color &p_clear_color = Color());
+ virtual DrawListID draw_list_begin_for_screen(DisplayServer::WindowID p_screen = 0, const Color &p_clear_color = Color());
virtual DrawListID draw_list_begin(RID p_framebuffer, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
virtual Error draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, DrawListID *r_split_ids, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2());
@@ -1070,7 +1080,7 @@ public:
virtual void draw_list_bind_vertex_array(DrawListID p_list, RID p_vertex_array);
virtual void draw_list_bind_index_array(DrawListID p_list, RID p_index_array);
virtual void draw_list_set_line_width(DrawListID p_list, float p_width);
- virtual void draw_list_set_push_constant(DrawListID p_list, void *p_data, uint32_t p_data_size);
+ virtual void draw_list_set_push_constant(DrawListID p_list, const void *p_data, uint32_t p_data_size);
virtual void draw_list_draw(DrawListID p_list, bool p_use_indices, uint32_t p_instances = 1, uint32_t p_procedural_vertices = 0);
@@ -1086,7 +1096,7 @@ public:
virtual ComputeListID compute_list_begin();
virtual void compute_list_bind_compute_pipeline(ComputeListID p_list, RID p_compute_pipeline);
virtual void compute_list_bind_uniform_set(ComputeListID p_list, RID p_uniform_set, uint32_t p_index);
- virtual void compute_list_set_push_constant(ComputeListID p_list, void *p_data, uint32_t p_data_size);
+ virtual void compute_list_set_push_constant(ComputeListID p_list, const void *p_data, uint32_t p_data_size);
virtual void compute_list_add_barrier(ComputeListID p_list);
virtual void compute_list_dispatch(ComputeListID p_list, uint32_t p_x_groups, uint32_t p_y_groups, uint32_t p_z_groups);
@@ -1116,14 +1126,20 @@ public:
virtual int limit_get(Limit p_limit);
virtual void prepare_screen_for_drawing();
- void initialize(VulkanContext *p_context);
+ void initialize(VulkanContext *p_context, bool p_local_device = false);
void finalize();
- virtual void swap_buffers();
+ virtual void swap_buffers(); //for main device
+
+ virtual void submit(); //for local device
+ virtual void sync(); //for local device
virtual uint32_t get_frame_delay() const;
+ virtual RenderingDevice *create_local_device();
+
RenderingDeviceVulkan();
+ ~RenderingDeviceVulkan();
};
#endif // RENDERING_DEVICE_VULKAN_H