A developer can switch `vk_common.hh#use_render_graph` to enable render graph. When enabled the buffers and images are tracked by the device resource state tracker. The storage buffer commands are recorded to the context render graph. The next unit tests will pass: - GPUVulkanTest.storage_buffer_create_update_read - GPUVulkanTest.storage_buffer_clear_zero - GPUVulkanTest.storage_buffer_clear - GPUVulkanTest.storage_buffer_copy_from_vertex_buffer The pattern to migrate to render graph is: - always construct CreateInfo for class. - based on `use_render_graph` call `context.command_buffers.something` or `context.render_graph.add_node`. - Hide calls to `context.flush` when `use_render_graph` is true. Pull Request: https://projects.blender.org/blender/blender/pulls/120812
135 lines
5.2 KiB
C++
135 lines
5.2 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.hh"
|
|
#include "gpu_shader_create_info.hh"
|
|
#include "gpu_texture_private.hh"
|
|
|
|
namespace blender::gpu {
|
|
|
|
/**
|
|
* The Vulkan backend is currently migrating to a render graph approach. This requires commands to
|
|
* be recorded in a different way. During the migration the backend will mist likely crash. With
|
|
* the `use_render_graph` constant we can switch back to the not render graph implementation.
|
|
* During development of the render graph this is set to true. But when committing to main this
|
|
* must be set to false.
|
|
*/
|
|
static constexpr bool use_render_graph = false;
|
|
|
|
/**
|
|
* 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,
|
|
};
|
|
|
|
VkImageAspectFlags to_vk_image_aspect_flag_bits(const eGPUTextureFormat format);
|
|
VkImageAspectFlags 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);
|
|
|
|
VkComponentSwizzle to_vk_component_swizzle(const char swizzle);
|
|
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);
|
|
VkSamplerAddressMode to_vk_sampler_address_mode(const GPUSamplerExtendMode extend_mode);
|
|
VkDescriptorType to_vk_descriptor_type(const shader::ShaderCreateInfo::Resource &resource);
|
|
|
|
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
|