@@ -170,6 +170,8 @@ class VKDevice : public offloadtest::Device {
170
170
}
171
171
}
172
172
173
+ const VkPhysicalDeviceProperties &getProps () const { return Props; }
174
+
173
175
private:
174
176
void queryCapabilities () {
175
177
@@ -779,31 +781,57 @@ class VKContext {
779
781
}
780
782
781
783
llvm::Error initialize () {
784
+ // Create a Vulkan 1.1 instance to determine the API version
782
785
VkApplicationInfo AppInfo = {};
783
786
AppInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
784
787
AppInfo.pApplicationName = " OffloadTest" ;
788
+ // TODO: We should set this based on a command line flag, and simplify the
789
+ // code below to error if the requested version isn't supported.
785
790
AppInfo.apiVersion = VK_API_VERSION_1_1;
786
791
787
792
VkInstanceCreateInfo CreateInfo = {};
788
793
CreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
789
794
CreateInfo.pApplicationInfo = &AppInfo;
790
795
796
+ VkResult Res = vkCreateInstance (&CreateInfo, NULL , &Instance);
797
+ if (Res == VK_ERROR_INCOMPATIBLE_DRIVER)
798
+ return llvm::createStringError (std::errc::no_such_device,
799
+ " Cannot find a compatible Vulkan device" );
800
+ else if (Res)
801
+ return llvm::createStringError (std::errc::no_such_device,
802
+ " Unkown Vulkan initialization error" );
803
+
804
+ uint32_t DeviceCount = 0 ;
805
+ if (vkEnumeratePhysicalDevices (Instance, &DeviceCount, nullptr ))
806
+ return llvm::createStringError (std::errc::no_such_device,
807
+ " Failed to get device count" );
808
+ std::vector<VkPhysicalDevice> PhysicalDevicesTmp (DeviceCount);
809
+ if (vkEnumeratePhysicalDevices (Instance, &DeviceCount,
810
+ PhysicalDevicesTmp.data ()))
811
+ return llvm::createStringError (std::errc::no_such_device,
812
+ " Failed to enumerate devices" );
813
+ {
814
+ auto TmpDev = std::make_shared<VKDevice>(PhysicalDevicesTmp[0 ]);
815
+ AppInfo.apiVersion = TmpDev->getProps ().apiVersion ;
816
+ }
817
+ vkDestroyInstance (Instance, NULL );
818
+
791
819
// TODO: This is a bit hacky but matches what I did in DX.
792
820
#ifndef NDEBUG
793
821
const char *ValidationLayer = " VK_LAYER_KHRONOS_validation" ;
794
822
CreateInfo.ppEnabledLayerNames = &ValidationLayer;
795
823
CreateInfo.enabledLayerCount = 1 ;
796
824
#endif
797
825
798
- VkResult Res = vkCreateInstance (&CreateInfo, NULL , &Instance);
826
+ Res = vkCreateInstance (&CreateInfo, NULL , &Instance);
799
827
if (Res == VK_ERROR_INCOMPATIBLE_DRIVER)
800
828
return llvm::createStringError (std::errc::no_such_device,
801
829
" Cannot find a compatible Vulkan device" );
802
830
else if (Res)
803
831
return llvm::createStringError (std::errc::no_such_device,
804
832
" Unkown Vulkan initialization error" );
805
833
806
- uint32_t DeviceCount = 0 ;
834
+ DeviceCount = 0 ;
807
835
if (vkEnumeratePhysicalDevices (Instance, &DeviceCount, nullptr ))
808
836
return llvm::createStringError (std::errc::no_such_device,
809
837
" Failed to get device count" );
0 commit comments