2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2022 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-10-31 16:01:02 +01:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup gpu
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "gpu_context_private.hh"
|
2023-08-29 15:05:08 +02:00
|
|
|
|
|
|
|
|
#include "GHOST_Types.h"
|
|
|
|
|
|
2023-10-30 14:21:14 +01:00
|
|
|
#include "vk_command_buffers.hh"
|
2023-04-21 12:32:40 +02:00
|
|
|
#include "vk_common.hh"
|
|
|
|
|
#include "vk_debug.hh"
|
2023-02-21 15:03:12 +01:00
|
|
|
#include "vk_descriptor_pools.hh"
|
2022-11-23 14:42:11 +01:00
|
|
|
|
2022-10-31 16:01:02 +01:00
|
|
|
namespace blender::gpu {
|
2023-03-28 11:51:32 +02:00
|
|
|
class VKFrameBuffer;
|
2023-05-11 13:01:56 +02:00
|
|
|
class VKVertexAttributeObject;
|
|
|
|
|
class VKBatch;
|
2023-04-26 09:23:58 +02:00
|
|
|
class VKStateManager;
|
2022-10-31 16:01:02 +01:00
|
|
|
|
2023-04-26 09:23:58 +02:00
|
|
|
class VKContext : public Context, NonCopyable {
|
2022-11-23 14:42:11 +01:00
|
|
|
private:
|
2023-10-30 14:21:14 +01:00
|
|
|
VKCommandBuffers command_buffers_;
|
2023-11-16 15:03:47 +01:00
|
|
|
VKDescriptorPools descriptor_pools_;
|
|
|
|
|
VKDescriptorSetTracker descriptor_set_;
|
2023-04-21 12:32:40 +02:00
|
|
|
|
2023-08-29 15:05:08 +02:00
|
|
|
VkExtent2D vk_extent_ = {};
|
|
|
|
|
VkFormat swap_chain_format_ = {};
|
|
|
|
|
GPUTexture *surface_texture_ = nullptr;
|
2023-02-21 15:03:12 +01:00
|
|
|
void *ghost_context_;
|
2022-11-23 14:42:11 +01:00
|
|
|
|
2022-10-31 16:01:02 +01:00
|
|
|
public:
|
2022-11-23 14:42:11 +01:00
|
|
|
VKContext(void *ghost_window, void *ghost_context);
|
|
|
|
|
virtual ~VKContext();
|
2022-10-31 16:01:02 +01:00
|
|
|
|
|
|
|
|
void activate() override;
|
|
|
|
|
void deactivate() override;
|
|
|
|
|
void begin_frame() override;
|
|
|
|
|
void end_frame() override;
|
|
|
|
|
|
|
|
|
|
void flush() override;
|
|
|
|
|
void finish() override;
|
|
|
|
|
|
2023-11-20 14:08:19 +01:00
|
|
|
void memory_statistics_get(int *r_total_mem_kb, int *r_free_mem_kb) override;
|
2022-10-31 16:01:02 +01:00
|
|
|
|
|
|
|
|
void debug_group_begin(const char *, int) override;
|
|
|
|
|
void debug_group_end() override;
|
2023-03-16 08:54:05 +01:00
|
|
|
bool debug_capture_begin() override;
|
|
|
|
|
void debug_capture_end() override;
|
|
|
|
|
void *debug_capture_scope_create(const char *name) override;
|
|
|
|
|
bool debug_capture_scope_begin(void *scope) override;
|
|
|
|
|
void debug_capture_scope_end(void *scope) override;
|
2022-11-23 14:42:11 +01:00
|
|
|
|
2023-05-09 09:22:26 +02:00
|
|
|
bool has_active_framebuffer() const;
|
2023-03-28 11:51:32 +02:00
|
|
|
void activate_framebuffer(VKFrameBuffer &framebuffer);
|
|
|
|
|
void deactivate_framebuffer();
|
2023-05-09 09:22:26 +02:00
|
|
|
VKFrameBuffer *active_framebuffer_get() const;
|
|
|
|
|
|
2023-05-11 13:01:56 +02:00
|
|
|
void bind_compute_pipeline();
|
|
|
|
|
void bind_graphics_pipeline(const GPUPrimType prim_type,
|
|
|
|
|
const VKVertexAttributeObject &vertex_attribute_object);
|
2023-05-09 09:22:26 +02:00
|
|
|
void sync_backbuffer();
|
2023-03-28 11:51:32 +02:00
|
|
|
|
2023-08-05 12:32:59 +10:00
|
|
|
static VKContext *get()
|
2022-12-12 12:22:38 +01:00
|
|
|
{
|
|
|
|
|
return static_cast<VKContext *>(Context::get());
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-30 14:21:14 +01:00
|
|
|
VKCommandBuffers &command_buffers_get()
|
2023-02-21 15:03:12 +01:00
|
|
|
{
|
2023-10-30 14:21:14 +01:00
|
|
|
return command_buffers_;
|
2023-02-21 15:03:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-16 15:03:47 +01:00
|
|
|
VKDescriptorPools &descriptor_pools_get()
|
|
|
|
|
{
|
|
|
|
|
return descriptor_pools_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VKDescriptorSetTracker &descriptor_set_get()
|
|
|
|
|
{
|
|
|
|
|
return descriptor_set_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 08:14:37 +02:00
|
|
|
VKStateManager &state_manager_get() const;
|
2023-08-29 15:05:08 +02:00
|
|
|
|
|
|
|
|
static void swap_buffers_pre_callback(const GHOST_VulkanSwapChainData *data);
|
|
|
|
|
static void swap_buffers_post_callback();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void swap_buffers_pre_handler(const GHOST_VulkanSwapChainData &data);
|
|
|
|
|
void swap_buffers_post_handler();
|
2022-10-31 16:01:02 +01:00
|
|
|
};
|
|
|
|
|
|
2023-06-15 08:14:37 +02:00
|
|
|
BLI_INLINE bool operator==(const VKContext &a, const VKContext &b)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<const void *>(&a) == static_cast<const void *>(&b);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 15:49:04 +11:00
|
|
|
} // namespace blender::gpu
|