Skip to content

Commit

Permalink
Use Vulkan 1.4 if available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Dec 8, 2024
1 parent 974c763 commit a959b17
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 33 deletions.
4 changes: 2 additions & 2 deletions renderer/formats/scene_formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static bool mesh_unroll_vertices(Mesh &mesh)
mesh.attribute_stride);
}
}
else if (mesh.index_type == VK_INDEX_TYPE_UINT8_EXT)
else if (mesh.index_type == VK_INDEX_TYPE_UINT8)
{
const auto *ibo = mesh.indices.data();
for (unsigned i = 0; i < mesh.count; i++)
Expand Down Expand Up @@ -291,7 +291,7 @@ bool mesh_canonicalize_indices(SceneFormats::Mesh &mesh)
for (unsigned i = 0; i < mesh.count; i++)
unrolled_indices.push_back(mesh.primitive_restart && indices[i] == UINT16_MAX ? UINT32_MAX : indices[i]);
}
else if (mesh.index_type == VK_INDEX_TYPE_UINT8_EXT)
else if (mesh.index_type == VK_INDEX_TYPE_UINT8)
{
auto *indices = reinterpret_cast<const uint8_t *>(mesh.indices.data());
for (unsigned i = 0; i < mesh.count; i++)
Expand Down
2 changes: 1 addition & 1 deletion tests/meshlet_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ struct MeshletViewerApplication : Granite::Application, Granite::EventHandler //

cmd->set_program("assets://shaders/meshlet_debug.vert", "assets://shaders/meshlet_debug.frag",
{{ "SINGLE_INSTANCE_RENDER", 0}});
cmd->set_index_buffer(*ibo, 0, VK_INDEX_TYPE_UINT8_EXT);
cmd->set_index_buffer(*ibo, 0, VK_INDEX_TYPE_UINT8);
cmd->set_vertex_binding(0, *pos, 0, 12);
cmd->set_vertex_binding(1, *attr, 0, 16);
cmd->set_vertex_attrib(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0);
Expand Down
2 changes: 1 addition & 1 deletion vulkan/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct BufferCreateInfo
{
BufferDomain domain = BufferDomain::Device;
VkDeviceSize size = 0;
VkBufferUsageFlags2KHR usage = 0;
VkBufferUsageFlags2 usage = 0;
BufferMiscFlags misc = 0;
VkMemoryRequirements allocation_requirements = {};
ExternalHandle external;
Expand Down
2 changes: 1 addition & 1 deletion vulkan/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2688,7 +2688,7 @@ void CommandBuffer::push_descriptor_set(uint32_t set)

VkDescriptorUpdateTemplate update_template = pipeline_state.layout->get_update_template(set);
VK_ASSERT(update_template);
table.vkCmdPushDescriptorSetWithTemplateKHR(
table.vkCmdPushDescriptorSetWithTemplate(
cmd, update_template,
pipeline_state.layout->get_layout(), set, bindings.bindings[set]);
}
Expand Down
79 changes: 59 additions & 20 deletions vulkan/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ VkApplicationInfo Context::get_promoted_application_info() const
// Granite min-req is 1.1.
app_info.apiVersion = std::max(VK_API_VERSION_1_1, app_info.apiVersion);

// Target Vulkan 1.3 if available.
app_info.apiVersion = std::max(app_info.apiVersion, std::min(VK_API_VERSION_1_3, volkGetInstanceVersion()));
// Target Vulkan 1.4 if available.
app_info.apiVersion = std::max(app_info.apiVersion, std::min(VK_API_VERSION_1_4, volkGetInstanceVersion()));

return app_info;
}
Expand Down Expand Up @@ -1338,6 +1338,33 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
}
}

bool supports_khr_push_descriptor = false;

if (ext.device_api_core_version >= VK_API_VERSION_1_4)
{
ADD_CHAIN(ext.vk14_features, VULKAN_1_4_FEATURES);
}
else
{
if ((flags & CONTEXT_CREATION_ENABLE_PUSH_DESCRIPTOR_BIT) != 0 && has_extension(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
supports_khr_push_descriptor = true;
}

if (has_extension(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
ADD_CHAIN(ext.index_type_uint8_features, INDEX_TYPE_UINT8_FEATURES_EXT);
}

if (has_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
ADD_CHAIN(ext.maintenance5_features, MAINTENANCE_5_FEATURES_KHR);
}
}

if (has_extension(VK_KHR_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_KHR_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME);
Expand Down Expand Up @@ -1393,12 +1420,6 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
ADD_CHAIN(ext.mesh_shader_features, MESH_SHADER_FEATURES_EXT);
}

if (has_extension(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
ADD_CHAIN(ext.index_type_uint8_features, INDEX_TYPE_UINT8_FEATURES_EXT);
}

if (has_extension(VK_EXT_RGBA10X6_FORMATS_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_EXT_RGBA10X6_FORMATS_EXTENSION_NAME);
Expand All @@ -1423,12 +1444,6 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
ADD_CHAIN(ext.video_maintenance1_features, VIDEO_MAINTENANCE_1_FEATURES_KHR);
}

if ((flags & CONTEXT_CREATION_ENABLE_PUSH_DESCRIPTOR_BIT) != 0 && has_extension(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
ext.supports_push_descriptor = true;
}

if (has_extension(VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME);
Expand Down Expand Up @@ -1464,12 +1479,6 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
ADD_CHAIN(ext.pipeline_binary_features, PIPELINE_BINARY_FEATURES_KHR);
}

if (has_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
ADD_CHAIN(ext.maintenance5_features, MAINTENANCE_5_FEATURES_KHR);
}

if ((flags & CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT) != 0 && requires_swapchain)
{
if (has_extension(VK_KHR_PRESENT_ID_EXTENSION_NAME))
Expand Down Expand Up @@ -1538,6 +1547,13 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
ext.vk13_features.computeFullSubgroups = VK_TRUE;
if (ext.subgroup_size_control_features.subgroupSizeControl)
ext.vk13_features.subgroupSizeControl = VK_TRUE;

if (ext.maintenance5_features.maintenance5)
ext.vk14_features.maintenance5 = VK_TRUE;
if (supports_khr_push_descriptor)
ext.vk14_features.pushDescriptor = VK_TRUE;
if (ext.index_type_uint8_features.indexTypeUint8)
ext.vk14_features.indexTypeUint8 = VK_TRUE;
///

ext.vk11_features.multiviewGeometryShader = VK_FALSE;
Expand All @@ -1554,6 +1570,24 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
ext.vk13_features.inlineUniformBlock = VK_FALSE;
ext.vk13_features.privateData = VK_FALSE;

// Might be relevant when we move fully to 1.4.
ext.vk14_features.dynamicRenderingLocalRead = VK_FALSE;
// TODO: Maybe later.
ext.vk14_features.hostImageCopy = VK_FALSE;
ext.vk14_features.globalPriorityQuery = VK_FALSE;
ext.vk14_features.pipelineProtectedAccess = VK_FALSE;
ext.vk14_features.pipelineRobustness = VK_FALSE;
ext.vk14_features.vertexAttributeInstanceRateDivisor = VK_FALSE;
ext.vk14_features.vertexAttributeInstanceRateZeroDivisor = VK_FALSE;
ext.vk14_features.stippledBresenhamLines = VK_FALSE;
ext.vk14_features.stippledRectangularLines = VK_FALSE;
ext.vk14_features.stippledSmoothLines = VK_FALSE;
ext.vk14_features.rectangularLines = VK_FALSE;
ext.vk14_features.smoothLines = VK_FALSE;
ext.vk14_features.bresenhamLines = VK_FALSE;
if ((flags & CONTEXT_CREATION_ENABLE_PUSH_DESCRIPTOR_BIT) == 0)
ext.vk14_features.pushDescriptor = VK_FALSE;

ext.mesh_shader_features.primitiveFragmentShadingRateMeshShader = VK_FALSE;
ext.mesh_shader_features.meshShaderQueries = VK_FALSE;
ext.mesh_shader_features.multiviewMeshShader = VK_FALSE;
Expand Down Expand Up @@ -1665,6 +1699,9 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
else if (has_extension(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME))
ADD_CHAIN(size_control_props, SUBGROUP_SIZE_CONTROL_PROPERTIES);

if (ext.device_api_core_version >= VK_API_VERSION_1_4)
ADD_CHAIN(ext.vk14_props, VULKAN_1_4_PROPERTIES);

if (ext.supports_external_memory_host)
ADD_CHAIN(ext.host_memory_properties, EXTERNAL_MEMORY_HOST_PROPERTIES_EXT);

Expand Down Expand Up @@ -1777,6 +1814,8 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
device_table.vkCreateRenderPass2 = device_table.vkCreateRenderPass2KHR;
if (!device_table.vkResetQueryPool)
device_table.vkResetQueryPool = device_table.vkResetQueryPoolEXT;
if (!device_table.vkCmdPushDescriptorSetWithTemplate)
device_table.vkCmdPushDescriptorSetWithTemplate = device_table.vkCmdPushDescriptorSetWithTemplateKHR;

for (int i = 0; i < QUEUE_INDEX_COUNT; i++)
{
Expand Down
3 changes: 2 additions & 1 deletion vulkan/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ struct DeviceFeatures
bool supports_swapchain_colorspace = false;
bool supports_surface_maintenance1 = false;
bool supports_store_op_none = false;
bool supports_push_descriptor = false;

VkPhysicalDeviceFeatures enabled_features = {};

VkPhysicalDeviceVulkan11Features vk11_features = {};
VkPhysicalDeviceVulkan12Features vk12_features = {};
VkPhysicalDeviceVulkan13Features vk13_features = {};
VkPhysicalDeviceVulkan14Features vk14_features = {};
VkPhysicalDeviceVulkan11Properties vk11_props = {};
VkPhysicalDeviceVulkan12Properties vk12_props = {};
VkPhysicalDeviceVulkan13Properties vk13_props = {};
VkPhysicalDeviceVulkan14Properties vk14_props = {};

// KHR
VkPhysicalDeviceComputeShaderDerivativesFeaturesKHR compute_shader_derivative_features = {};
Expand Down
4 changes: 2 additions & 2 deletions vulkan/descriptor_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ DescriptorSetAllocator::DescriptorSetAllocator(Hash hash, Device *device_, const
device->register_descriptor_set_layout(set_layout_pool, get_hash(), info);
#endif

if (!bindless && device->get_device_features().supports_push_descriptor)
if (!bindless && device->get_device_features().vk14_features.pushDescriptor)
{
info.flags |= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
info.flags |= VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT;
for (auto &b : bindings)
if (b.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)
b.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Expand Down
8 changes: 4 additions & 4 deletions vulkan/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4368,7 +4368,7 @@ BufferHandle Device::create_imported_host_buffer(const BufferCreateInfo &create_
}

VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
VkBufferUsageFlags2CreateInfoKHR usage2 = { VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR };
VkBufferUsageFlags2CreateInfo usage2 = { VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO };
info.size = create_info.size;
usage2.usage = create_info.usage;
if (get_device_features().vk12_features.bufferDeviceAddress)
Expand All @@ -4381,7 +4381,7 @@ BufferHandle Device::create_imported_host_buffer(const BufferCreateInfo &create_
uint32_t sharing_indices[QUEUE_INDEX_COUNT];
fill_buffer_sharing_indices(info, sharing_indices);

if (ext.maintenance5_features.maintenance5)
if (ext.vk14_features.maintenance5)
{
usage2.pNext = info.pNext;
info.pNext = &usage2;
Expand Down Expand Up @@ -4509,7 +4509,7 @@ BufferHandle Device::create_buffer(const BufferCreateInfo &create_info, const vo
}

VkBufferCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
VkBufferUsageFlags2CreateInfoKHR usage2 = { VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO_KHR };
VkBufferUsageFlags2CreateInfo usage2 = { VK_STRUCTURE_TYPE_BUFFER_USAGE_FLAGS_2_CREATE_INFO };
info.size = create_info.size;
usage2.usage = create_info.usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
if (get_device_features().vk12_features.bufferDeviceAddress)
Expand Down Expand Up @@ -4561,7 +4561,7 @@ BufferHandle Device::create_buffer(const BufferCreateInfo &create_info, const vo
info.pNext = &external_info;
}

if (ext.maintenance5_features.maintenance5)
if (ext.vk14_features.maintenance5)
{
usage2.pNext = info.pNext;
info.pNext = &usage2;
Expand Down
2 changes: 1 addition & 1 deletion vulkan/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void PipelineLayout::create_update_templates()
if (desc_set == push_set_index)
{
info.descriptorSetLayout = set_allocators[desc_set]->get_layout_for_push();
info.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR;
info.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS;
}
else
{
Expand Down

0 comments on commit a959b17

Please sign in to comment.