Skip to content

Commit

Permalink
tools: Add Vulkan SC variant of vulkaninfo
Browse files Browse the repository at this point in the history
  • Loading branch information
aqnuep committed Jan 5, 2024
1 parent 1e7139b commit 9013ecd
Show file tree
Hide file tree
Showing 16 changed files with 3,989 additions and 300 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(API_TYPE "vulkan")

if(VULKANSC)
set(API_TYPE "vulkansc")
add_definitions(-DVULKANSC)
endif()

add_subdirectory(scripts)
Expand All @@ -49,7 +50,6 @@ option(BUILD_ICD "Build icd" ON)

if(VULKANSC)
set(BUILD_CUBE OFF CACHE BOOL "cube sample is not currently supported for Vulkan SC" FORCE)
set(BUILD_VULKANINFO OFF CACHE BOOL "vulkaninfo is not currently supported for Vulkan SC" FORCE)
else()
set(BUILD_VKSC_DEVSIM OFF CACHE BOOL "Vulkan SC device simulation layer is not supported for Vulkan" FORCE)
endif()
Expand Down
2 changes: 1 addition & 1 deletion devsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ elseif(APPLE)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_definitions(VK_USE_PLATFORM_MACOS_MVK)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD|QNX")
if (BUILD_WSI_XCB_SUPPORT)
add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DVK_USE_PLATFORM_XCB_KHX)
set(DisplayServer Xcb)
Expand Down
2 changes: 1 addition & 1 deletion icd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ elseif(APPLE)
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
elseif(BUILD_MOCK_ANDROID_SUPPORT)
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|BSD|QNX")
if(BUILD_WSI_XCB_SUPPORT)
add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DVK_USE_PLATFORM_XCB_KHX)
endif()
Expand Down
5 changes: 2 additions & 3 deletions icd/generated-vksc/function_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,10 @@ static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(
pProperties->vendorID = 0xba5eba11;
pProperties->deviceID = 0xf005ba11;
pProperties->deviceType = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
//std::string devName = "Vulkan Mock Device";
strcpy(pProperties->deviceName, "Vulkan Mock Device");
strcpy(pProperties->deviceName, "Vulkan SC Mock Device");
pProperties->pipelineCacheUUID[0] = 18;
pProperties->limits = SetLimits(&pProperties->limits);
pProperties->sparseProperties = { VK_TRUE, VK_TRUE, VK_TRUE, VK_TRUE, VK_TRUE };
pProperties->sparseProperties = {VK_FALSE, VK_FALSE, VK_FALSE, VK_FALSE, VK_FALSE};
}

static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceQueueFamilyProperties(
Expand Down
3 changes: 2 additions & 1 deletion scripts/generate_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def main(argv):
if args.api == 'vulkansc':
files_to_gen = {str(os.path.join('icd','generated-vksc')) : ['vk_typemap_helper.h',
'function_definitions.h',
'function_declarations.h']}
'function_declarations.h'],
str(os.path.join('vulkaninfo','generated-vksc')): ['vulkaninfo.hpp']}

#base directory for the source repository
repo_dir = common_codegen.repo_relative('')
Expand Down
11 changes: 11 additions & 0 deletions scripts/mock_icd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,17 @@
}
''',
# Replace device properties query
'vkGetPhysicalDeviceProperties': '''
pProperties->apiVersion = VK_HEADER_VERSION_COMPLETE;
pProperties->driverVersion = 1;
pProperties->vendorID = 0xba5eba11;
pProperties->deviceID = 0xf005ba11;
pProperties->deviceType = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
strcpy(pProperties->deviceName, "Vulkan SC Mock Device");
pProperties->pipelineCacheUUID[0] = 18;
pProperties->limits = SetLimits(&pProperties->limits);
pProperties->sparseProperties = {VK_FALSE, VK_FALSE, VK_FALSE, VK_FALSE, VK_FALSE};
''',
'vkGetPhysicalDeviceProperties2KHR': None,
'vkGetPhysicalDeviceProperties2': '''
GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
Expand Down
45 changes: 15 additions & 30 deletions scripts/vulkaninfo_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) 2019-2022 Valve Corporation
# Copyright (c) 2019-2022 LunarG, Inc.
# Copyright (c) 2019-2022 Google Inc.
# Copyright (c) 2023-2023 RasterGrid Kft.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +32,7 @@
* Copyright (c) 2019-2022 The Khronos Group Inc.
* Copyright (c) 2019-2022 Valve Corporation
* Copyright (c) 2019-2022 LunarG, Inc.
* Copyright (c) 2023-2023 RasterGrid Kft.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -288,13 +290,6 @@ def endFile(self):
for key, value in self.extension_sets.items():
self.extension_sets[key] = sorted(value)

alias_versions = OrderedDict()
for version in self.vulkan_versions:
for aliases in self.aliases.values():
for alias in aliases:
if alias in version.names:
alias_versions[alias] = version.minorVersion

self.enums = sorted(self.enums, key=operator.attrgetter('name'))
self.flags = sorted(self.flags, key=operator.attrgetter('name'))
self.bitmasks = sorted(self.bitmasks, key=operator.attrgetter('name'))
Expand Down Expand Up @@ -408,7 +403,7 @@ def findFormatRanges(self):
min_val = min(min_val, value)
max_val = max(max_val, value)
if min_val < 2**32 and max_val > 0:
self.format_ranges.append(VulkanFormatRange(0,None, min_val, max_val))
self.format_ranges.append(VulkanFormatRange(0, None, min_val, max_val))

for feature in self.registry.reg.findall('feature'):
for require in feature.findall('require'):
Expand All @@ -425,13 +420,13 @@ def findFormatRanges(self):
min_val = min(min_val, value)
max_val = max(max_val, value)
if min_val < 2**32 and max_val > 0:
self.format_ranges.append(VulkanFormatRange(feature.get('number').split('.')[1],None, min_val, max_val))
self.format_ranges.append(VulkanFormatRange(feature.get('name').replace('_VERSION_', '_API_VERSION_'), None, min_val, max_val))
# If the formats came from an extension, add a format range for that extension so it'll be printed if the ext is supported but not the core version
if original_ext is not None:
self.format_ranges.append(VulkanFormatRange(0,original_ext, min_val, max_val))
self.format_ranges.append(VulkanFormatRange(0, original_ext, min_val, max_val))

for extension in self.registry.reg.find('extensions').findall('extension'):
if extension.get('supported') in ['disabled', 'vulkansc']:
if not self.genOpts.apiname in extension.get('supported').split(','):
continue

min_val = 2**32
Expand Down Expand Up @@ -766,7 +761,7 @@ def PrintChainStruct(listName, structures, all_structures, chain_details, extTyp
out += AddGuardFooter(s)


out += ' std::vector<VkBaseOutStructure*> chain_members;\n'
out += ' std::vector<VkBaseOutStructure*> chain_members{};\n'
for s in structs_to_print:
if s.name in STRUCT_BLACKLIST:
continue
Expand All @@ -781,7 +776,7 @@ def PrintChainStruct(listName, structures, all_structures, chain_details, extTyp
oldVersionName = None
for v in vulkan_versions:
if s.name in v.names:
version = v.minorVersion
version = v
if s.name in aliases.keys():
for alias in aliases[s.name]:
oldVersionName = alias
Expand All @@ -807,9 +802,9 @@ def PrintChainStruct(listName, structures, all_structures, chain_details, extTyp
assert False, 'Should never get here'
if has_version:
if has_printed_condition:
out += f')\n && {version_desc}.minor < {str(version)}'
out += f')\n && {version_desc} < {version.constant}'
else:
out += f'{version_desc}.minor >= {str(version)}'
out += f'{version_desc} >= {version.constant}'
out += ')\n '
else:
out += ' '
Expand Down Expand Up @@ -865,7 +860,7 @@ def PrintChainStruct(listName, structures, all_structures, chain_details, extTyp
oldVersionName = None
for v in vulkan_versions:
if s.name in v.names:
version = v.minorVersion
version = v
if s.name in aliases.keys():
for alias in aliases[s.name]:
oldVersionName = alias
Expand Down Expand Up @@ -897,15 +892,15 @@ def PrintChainStruct(listName, structures, all_structures, chain_details, extTyp
assert False, 'Should never get here'
if has_version:
if has_printed_condition:
out += f') &&\n {version_desc}.minor < {str(version)}'
out += f') &&\n {version_desc} < {version.constant}'
else:
out += f'{version_desc}.minor >= {str(version)}'
out += f'{version_desc} >= {version.constant}'
out += ')'
out += ') {\n'
out += f' {s.name}* props = ({s.name}*)structure;\n'
out += f' Dump{s.name}(p, '
if s.name in aliases.keys() and version is not None:
out += f'{version_desc}.minor >= {version} ?"{s.name}":"{oldVersionName}"'
out += f'{version_desc} >= {version.constant} ?"{s.name}":"{oldVersionName}"'
else:
out += f'"{s.name}"'
out += ', *props);\n'
Expand Down Expand Up @@ -1135,16 +1130,8 @@ def __init__(self, rootNode):
self.vkfuncs = []
self.constants = OrderedDict()
self.enumValues = OrderedDict()
self.version = 0
self.node = rootNode

promotedto = rootNode.get('promotedto')
if promotedto is not None:
# get last char of VK_VERSION_1_1 or VK_VERSION_1_2
minorVersion = promotedto[-1:]
if minorVersion.isdigit():
self.version = minorVersion

for req in rootNode.findall('require'):
for ty in req.findall('type'):
self.vktypes.append(ty.get('name'))
Expand Down Expand Up @@ -1179,9 +1166,7 @@ def __init__(self, rootNode):
class VulkanVersion:
def __init__(self, rootNode):
self.name = rootNode.get('name')
version_str = rootNode.get('number').split('.')
self.majorVersion = version_str[0]
self.minorVersion = version_str[1]
self.constant = self.name.replace('_VERSION_', '_API_VERSION_')
self.names = set()

for req in rootNode.findall('require'):
Expand Down
33 changes: 28 additions & 5 deletions vulkaninfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ~~~
# Copyright (c) 2018-2023 Valve Corporation
# Copyright (c) 2018-2023 LunarG, Inc.
# Copyright (c) 2023-2023 RasterGrid Kft.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,7 +16,18 @@
# limitations under the License.
# ~~~

# These variables enable downstream users to customize the CMake targets
# based on the target API variant (e.g. Vulkan SC)
set(VULKANINFO_NAME vulkaninfo)
set(GENERATED generated)

if(VULKANSC)
set(VULKANINFO_NAME vulkanscinfo)
set(GENERATED generated-vksc)
endif()

add_executable(vulkaninfo)
set_target_properties(vulkaninfo PROPERTIES OUTPUT_NAME ${VULKANINFO_NAME})

target_sources(vulkaninfo PRIVATE vulkaninfo.cpp)

Expand Down Expand Up @@ -49,17 +61,24 @@ if(WIN32)
endif()

target_include_directories(vulkaninfo PRIVATE
generated
${GENERATED}
.
)

target_compile_definitions(vulkaninfo PRIVATE VK_ENABLE_BETA_EXTENSIONS VK_NO_PROTOTYPES)

if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD|QNX")
if(VULKANSC)
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" OFF)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" OFF)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" OFF)
else()
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
endif()
option(BUILD_WSI_DIRECTFB_SUPPORT "Build DirectFB WSI support" OFF)
option(BUILD_WSI_SCI_SUPPORT "Build SCI WSI support" OFF)

find_package(PkgConfig REQUIRED QUIET) # Use PkgConfig to find Linux system libraries

Expand All @@ -86,6 +105,10 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux|BSD")
target_compile_definitions(vulkaninfo PRIVATE VK_USE_PLATFORM_DIRECTFB_EXT)
target_link_libraries(vulkaninfo PRIVATE PkgConfig::DirectFB)
endif()

if(BUILD_WSI_SCI_SUPPORT)
target_compile_definitions(platform_wsi INTERFACE VK_USE_PLATFORM_SCI)
endif()
endif()

if(APPLE)
Expand Down
5 changes: 5 additions & 0 deletions vulkaninfo/generated-vksc/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# Disable clang-format for generated code
DisableFormat: true
SortIncludes: false
...
Loading

0 comments on commit 9013ecd

Please sign in to comment.