Files
test2/source/blender/gpu/vulkan/vk_common.hh
Jeroen Bakker bee3f645d8 Vulkan: Rewrite GHOST_ContextVK
This is a rewrite of GHOST_ContextVK to align with Metal backend as described
in #111389 - solution 3 with the adaptation that GHOST is still responsible
for presenting the swap chain image and a post callback is still needed in
case the swapchain is recreated.

This PR also includes some smaller improvements in stability.

Technical documentation: https://developer.blender.org/docs/eevee_and_viewport/gpu/vulkan/swap_chain/

* Renderpasses and framebuffers are not owned anymore by GHOST_ContextVK
* VKFramebuffer doesn't contain a swap chain image.
* Swapchain images can only be used as a blit destination or present source.
  Not as an attachment.
* GHOST_ContextVK::swapBuffers would call a callback with the image the
  GPU module needs to blit the results to.
* Clearing of depth/stencil attachments when no depth write state is set.
* Enable VK_KHR_maintenance4 to relax the stage interface mapping.
* Removes most vulkan validation warnings/errors.
* Detection of frame buffer changes that needs to be applied before
  performing a command requiring render pass (draw/clear attachment)

**Benefits**

* Late retrieval of a swap chain image results in better overall performance as
  Blender doesn't need to wait until the image is presented on the screen.
* Easier API and clearer state (transitions)
* More control over Image layouts and command buffer states. (Better alignment with
  Vulkan API)

Pull Request: https://projects.blender.org/blender/blender/pulls/111473
2023-08-29 15:05:08 +02:00

125 lines
4.6 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include <typeinfo>
#ifdef __APPLE__
# include <MoltenVK/vk_mvk_moltenvk.h>
#else
# include <vulkan/vulkan.h>
#endif
#include "vk_mem_alloc.h"
#include "gpu_index_buffer_private.hh"
#include "gpu_shader_create_info.hh"
#include "gpu_texture_private.hh"
namespace blender::gpu {
/**
* Based on the usage of an Image View a different image view type should be created.
*
* When using a GPU_TEXTURE_CUBE as an frame buffer attachment it will be used as a
* GPU_TEXTURE_2D_ARRAY. eg only a single side of the cube map will be attached. But when bound as
* a shader resource the cube-map will be used.
*/
enum class eImageViewUsage {
/** Image View will be used as a bindable shader resource. */
ShaderBinding,
/** Image View will be used as an frame-buffer attachment. */
Attachment,
};
VkImageAspectFlagBits to_vk_image_aspect_flag_bits(const eGPUTextureFormat format);
VkImageAspectFlagBits to_vk_image_aspect_flag_bits(const eGPUFrameBufferBits buffers);
VkFormat to_vk_format(const eGPUTextureFormat format);
eGPUTextureFormat to_gpu_format(const VkFormat format);
VkFormat to_vk_format(const GPUVertCompType type,
const uint32_t size,
const GPUVertFetchMode fetch_mode);
VkFormat to_vk_format(const shader::Type type);
VkComponentMapping to_vk_component_mapping(const eGPUTextureFormat format);
VkImageViewType to_vk_image_view_type(const eGPUTextureType type, eImageViewUsage view_type);
VkImageType to_vk_image_type(const eGPUTextureType type);
VkClearColorValue to_vk_clear_color_value(const eGPUDataFormat format, const void *data);
VkIndexType to_vk_index_type(const GPUIndexBufType index_type);
VkPrimitiveTopology to_vk_primitive_topology(const GPUPrimType prim_type);
VkCullModeFlags to_vk_cull_mode_flags(const eGPUFaceCullTest cull_test);
const char *to_string(VkObjectType type);
template<typename T> VkObjectType to_vk_object_type(T /*vk_obj*/)
{
const std::type_info &tid = typeid(T);
#define VK_EQ_TYPEID(name, name2) \
if (tid == typeid(name)) { \
return VK_OBJECT_TYPE_##name2; \
}
VK_EQ_TYPEID(VkInstance, INSTANCE);
VK_EQ_TYPEID(VkPhysicalDevice, PHYSICAL_DEVICE);
VK_EQ_TYPEID(VkDevice, DEVICE);
VK_EQ_TYPEID(VkQueue, QUEUE);
VK_EQ_TYPEID(VkSemaphore, SEMAPHORE);
VK_EQ_TYPEID(VkCommandBuffer, COMMAND_BUFFER);
VK_EQ_TYPEID(VkFence, FENCE);
VK_EQ_TYPEID(VkDeviceMemory, DEVICE_MEMORY);
VK_EQ_TYPEID(VkBuffer, BUFFER);
VK_EQ_TYPEID(VkImage, IMAGE);
VK_EQ_TYPEID(VkEvent, EVENT);
VK_EQ_TYPEID(VkQueryPool, QUERY_POOL);
VK_EQ_TYPEID(VkBufferView, BUFFER_VIEW);
VK_EQ_TYPEID(VkImageView, IMAGE_VIEW);
VK_EQ_TYPEID(VkShaderModule, SHADER_MODULE);
VK_EQ_TYPEID(VkPipelineCache, PIPELINE_CACHE);
VK_EQ_TYPEID(VkPipelineLayout, PIPELINE_LAYOUT);
VK_EQ_TYPEID(VkRenderPass, RENDER_PASS);
VK_EQ_TYPEID(VkPipeline, PIPELINE);
VK_EQ_TYPEID(VkDescriptorSetLayout, DESCRIPTOR_SET_LAYOUT);
VK_EQ_TYPEID(VkSampler, SAMPLER);
VK_EQ_TYPEID(VkDescriptorPool, DESCRIPTOR_POOL);
VK_EQ_TYPEID(VkDescriptorSet, DESCRIPTOR_SET);
VK_EQ_TYPEID(VkFramebuffer, FRAMEBUFFER);
VK_EQ_TYPEID(VkCommandPool, COMMAND_POOL);
VK_EQ_TYPEID(VkSamplerYcbcrConversion, SAMPLER_YCBCR_CONVERSION);
VK_EQ_TYPEID(VkDescriptorUpdateTemplate, DESCRIPTOR_UPDATE_TEMPLATE);
VK_EQ_TYPEID(VkSurfaceKHR, SURFACE_KHR);
VK_EQ_TYPEID(VkSwapchainKHR, SWAPCHAIN_KHR);
VK_EQ_TYPEID(VkDisplayKHR, DISPLAY_KHR);
VK_EQ_TYPEID(VkDisplayModeKHR, DISPLAY_MODE_KHR);
VK_EQ_TYPEID(VkDebugReportCallbackEXT, DEBUG_REPORT_CALLBACK_EXT);
#ifdef VK_ENABLE_BETA_EXTENSIONS
VK_EQ_TYPEID(VkVideoSessionKHR, VIDEO_SESSION_KHR);
#endif
#ifdef VK_ENABLE_BETA_EXTENSIONS
VK_EQ_TYPEID(VkVideoSessionParametersKHR, VIDEO_SESSION_PARAMETERS_KHR);
#endif
VK_EQ_TYPEID(VkCuModuleNVX, CU_MODULE_NVX);
VK_EQ_TYPEID(VkCuFunctionNVX, CU_FUNCTION_NVX);
VK_EQ_TYPEID(VkDebugUtilsMessengerEXT, DEBUG_UTILS_MESSENGER_EXT);
VK_EQ_TYPEID(VkAccelerationStructureKHR, ACCELERATION_STRUCTURE_KHR);
VK_EQ_TYPEID(VkValidationCacheEXT, VALIDATION_CACHE_EXT);
VK_EQ_TYPEID(VkAccelerationStructureNV, ACCELERATION_STRUCTURE_NV);
VK_EQ_TYPEID(VkPerformanceConfigurationINTEL, PERFORMANCE_CONFIGURATION_INTEL);
VK_EQ_TYPEID(VkDeferredOperationKHR, DEFERRED_OPERATION_KHR);
VK_EQ_TYPEID(VkIndirectCommandsLayoutNV, INDIRECT_COMMANDS_LAYOUT_NV);
VK_EQ_TYPEID(VkPrivateDataSlotEXT, PRIVATE_DATA_SLOT_EXT);
BLI_assert_unreachable();
#undef VK_EQ_TYPEID
return VK_OBJECT_TYPE_UNKNOWN;
}
#define NOT_YET_IMPLEMENTED \
printf("%s:%d `%s` not implemented yet\n", __FILE__, __LINE__, __func__);
} // namespace blender::gpu