Skip to content

Commit

Permalink
[vulkan] Support Vulkan 1.3 (taichi-dev#4211)
Browse files Browse the repository at this point in the history
Co-authored-by: Taichi Gardener <[email protected]>
  • Loading branch information
bobcao3 and taichi-gardener authored Feb 7, 2022
1 parent c8d5b3f commit 6636922
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion external/SPIRV-Cross
Submodule SPIRV-Cross updated 263 files
2 changes: 1 addition & 1 deletion external/SPIRV-Headers
2 changes: 1 addition & 1 deletion external/SPIRV-Tools
Submodule SPIRV-Tools updated 254 files
2 changes: 1 addition & 1 deletion external/Vulkan-Headers
Submodule Vulkan-Headers updated 43 files
+10 −6 BUILD.gn
+235 −226 include/vk_video/vulkan_video_codec_h264std.h
+60 −49 include/vk_video/vulkan_video_codec_h264std_decode.h
+56 −53 include/vk_video/vulkan_video_codec_h264std_encode.h
+292 −287 include/vk_video/vulkan_video_codec_h265std.h
+32 −31 include/vk_video/vulkan_video_codec_h265std_decode.h
+85 −77 include/vk_video/vulkan_video_codec_h265std_encode.h
+14 −4 include/vk_video/vulkan_video_codecs_common.h
+2 −2 include/vulkan/vk_platform.h
+1 −1 include/vulkan/vulkan.h
+4,638 −4,251 include/vulkan/vulkan.hpp
+2 −2 include/vulkan/vulkan_android.h
+131 −44 include/vulkan/vulkan_beta.h
+1,793 −894 include/vulkan/vulkan_core.h
+1 −1 include/vulkan/vulkan_directfb.h
+5,278 −1,512 include/vulkan/vulkan_enums.hpp
+1 −1 include/vulkan/vulkan_fuchsia.h
+1,745 −717 include/vulkan/vulkan_funcs.hpp
+1 −1 include/vulkan/vulkan_ggp.h
+754 −289 include/vulkan/vulkan_handles.hpp
+13,191 −0 include/vulkan/vulkan_hash.hpp
+1 −1 include/vulkan/vulkan_ios.h
+1 −1 include/vulkan/vulkan_macos.h
+1 −1 include/vulkan/vulkan_metal.h
+3,904 −1,757 include/vulkan/vulkan_raii.hpp
+1 −1 include/vulkan/vulkan_screen.h
+27,281 −6,223 include/vulkan/vulkan_structs.hpp
+1 −1 include/vulkan/vulkan_vi.h
+1 −1 include/vulkan/vulkan_wayland.h
+1 −1 include/vulkan/vulkan_win32.h
+1 −1 include/vulkan/vulkan_xcb.h
+1 −1 include/vulkan/vulkan_xlib.h
+1 −1 include/vulkan/vulkan_xlib_xrandr.h
+11 −0 registry/apiconventions.py
+10 −6 registry/cgenerator.py
+3 −3 registry/conventions.py
+58 −16 registry/generator.py
+141 −24 registry/genvk.py
+271 −93 registry/reg.py
+1 −1 registry/spec_tools/util.py
+6,233 −2,943 registry/validusage.json
+3,155 −765 registry/vk.xml
+6 −5 registry/vkconventions.py
2 changes: 1 addition & 1 deletion external/VulkanMemoryAllocator
2 changes: 1 addition & 1 deletion external/volk
Submodule volk updated 3 files
+1 −1 CMakeLists.txt
+175 −0 volk.c
+116 −1 volk.h
4 changes: 1 addition & 3 deletions taichi/backends/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,9 +1811,8 @@ void VulkanDevice::create_vma_allocator() {
allocatorInfo.device = device_;
allocatorInfo.instance = instance_;

#ifndef __APPLE__
VolkDeviceTable table;
VmaVulkanFunctions vk_vma_functions;
VmaVulkanFunctions vk_vma_functions{0};

volkLoadDeviceTable(&table, device_);
vk_vma_functions.vkGetPhysicalDeviceProperties =
Expand Down Expand Up @@ -1851,7 +1850,6 @@ void VulkanDevice::create_vma_allocator() {
volkGetLoadedInstance(), "vkGetPhysicalDeviceMemoryProperties2KHR"));

allocatorInfo.pVulkanFunctions = &vk_vma_functions;
#endif

vmaCreateAllocator(&allocatorInfo, &allocator_);

Expand Down
31 changes: 25 additions & 6 deletions taichi/backends/vulkan/vulkan_device_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void VulkanDeviceCreator::create_instance() {
app_info.apiVersion = params_.api_version.value();
} else {
// The highest version designed to use
app_info.apiVersion = VK_API_VERSION_1_2;
app_info.apiVersion = VK_API_VERSION_1_3;
}

VkInstanceCreateInfo create_info{};
Expand Down Expand Up @@ -372,13 +372,24 @@ void VulkanDeviceCreator::create_logical_device() {
create_info.queueCreateInfoCount = queue_create_infos.size();

// Get device properties
VkPhysicalDeviceProperties physical_device_properties;
VkPhysicalDeviceProperties physical_device_properties{};
vkGetPhysicalDeviceProperties(physical_device_, &physical_device_properties);
TI_INFO("Vulkan Device \"{}\" supports Vulkan {} version {}.{}.{}",
physical_device_properties.deviceName,
VK_API_VERSION_VARIANT(physical_device_properties.apiVersion),
VK_API_VERSION_MAJOR(physical_device_properties.apiVersion),
VK_API_VERSION_MINOR(physical_device_properties.apiVersion),
VK_API_VERSION_PATCH(physical_device_properties.apiVersion));

ti_device_->set_cap(DeviceCapability::vk_api_version,
physical_device_properties.apiVersion);
ti_device_->set_cap(DeviceCapability::spirv_version, 0x10000);

if (physical_device_properties.apiVersion >= VK_API_VERSION_1_1) {
if (physical_device_properties.apiVersion >= VK_API_VERSION_1_3) {
ti_device_->set_cap(DeviceCapability::spirv_version, 0x10600);
} else if (physical_device_properties.apiVersion >= VK_API_VERSION_1_2) {
ti_device_->set_cap(DeviceCapability::spirv_version, 0x10500);
} else if (physical_device_properties.apiVersion >= VK_API_VERSION_1_1) {
ti_device_->set_cap(DeviceCapability::spirv_version, 0x10300);
}

Expand All @@ -392,7 +403,7 @@ void VulkanDeviceCreator::create_logical_device() {
vkEnumerateDeviceExtensionProperties(
physical_device_, nullptr, &extension_count, extension_properties.data());

bool has_surface = false, has_swapchain = false;
bool has_swapchain = false;

bool portability_subset_enabled = false;

Expand Down Expand Up @@ -420,8 +431,10 @@ void VulkanDeviceCreator::create_logical_device() {
} else if (name == VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME) {
enabled_extensions.push_back(ext.extensionName);
} else if (name == VK_KHR_SPIRV_1_4_EXTENSION_NAME) {
ti_device_->set_cap(DeviceCapability::spirv_version, 0x10400);
enabled_extensions.push_back(ext.extensionName);
if (ti_device_->get_cap(DeviceCapability::spirv_version) < 0x10400) {
ti_device_->set_cap(DeviceCapability::spirv_version, 0x10400);
enabled_extensions.push_back(ext.extensionName);
}
} else if (name == VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME ||
name == VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME) {
ti_device_->set_cap(DeviceCapability::vk_has_external_memory, true);
Expand All @@ -430,6 +443,12 @@ void VulkanDeviceCreator::create_logical_device() {
enabled_extensions.push_back(ext.extensionName);
} else if (name == VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME) {
enabled_extensions.push_back(ext.extensionName);
} else if (name == VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME) {
enabled_extensions.push_back(ext.extensionName);
} else if (name == VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) {
enabled_extensions.push_back(ext.extensionName);
} else if (name == VK_KHR_BIND_MEMORY_2_EXTENSION_NAME) {
enabled_extensions.push_back(ext.extensionName);
} else if (std::find(params_.additional_device_extensions.begin(),
params_.additional_device_extensions.end(),
name) != params_.additional_device_extensions.end()) {
Expand Down
1 change: 1 addition & 0 deletions taichi/backends/vulkan/vulkan_memory_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

#define VMA_IMPLEMENTATION
#define VMA_DEDICATED_ALLOCATION 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
#include "vk_mem_alloc.h"
18 changes: 16 additions & 2 deletions taichi/codegen/spirv/spirv_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1797,13 +1797,27 @@ static void spriv_message_consumer(spv_message_level_t level,

KernelCodegen::KernelCodegen(const Params &params)
: params_(params), ctx_attribs_(*params.kernel) {
spirv_opt_ = std::make_unique<spvtools::Optimizer>(SPV_ENV_VULKAN_1_2);
spv_target_env target_env = SPV_ENV_VULKAN_1_0;
uint32_t spirv_version =
params.device->get_cap(DeviceCapability::spirv_version);

if (spirv_version >= 0x10600) {
target_env = SPV_ENV_VULKAN_1_3;
} else if (spirv_version >= 0x10500) {
target_env = SPV_ENV_VULKAN_1_2;
} else if (spirv_version >= 0x10400) {
target_env = SPV_ENV_VULKAN_1_1_SPIRV_1_4;
} else if (spirv_version >= 0x10300) {
target_env = SPV_ENV_VULKAN_1_1;
}

spirv_opt_ = std::make_unique<spvtools::Optimizer>(target_env);
spirv_opt_->SetMessageConsumer(spriv_message_consumer);
if (params.enable_spv_opt)
spirv_opt_->RegisterPerformancePasses();
spirv_opt_options_.set_run_validator(false);

spirv_tools_ = std::make_unique<spvtools::SpirvTools>(SPV_ENV_VULKAN_1_2);
spirv_tools_ = std::make_unique<spvtools::SpirvTools>(target_env);
}

void KernelCodegen::run(TaichiKernelAttributes &kernel_attribs,
Expand Down

0 comments on commit 6636922

Please sign in to comment.