/* Same standalone GPU-copy probe built as Linux AArch64 and Windows x86. * Tests actual Vulkan buffers, complete data comparison, noncoherent cache * operations, remapping with an offset and queue completion. No Steam API. */ #define VK_NO_PROTOTYPES #ifdef _WIN32 #include #else #include #endif #include #include #include #include #include #include #define IFNS(X) X(DestroyInstance) X(EnumeratePhysicalDevices) X(GetPhysicalDeviceProperties) \ X(GetPhysicalDeviceMemoryProperties) X(GetPhysicalDeviceQueueFamilyProperties) X(CreateDevice) X(GetDeviceProcAddr) #define DFNS(X) X(DestroyDevice) X(GetDeviceQueue) X(CreateBuffer) X(DestroyBuffer) \ X(GetBufferMemoryRequirements) X(AllocateMemory) X(FreeMemory) X(BindBufferMemory) \ X(MapMemory) X(UnmapMemory) X(FlushMappedMemoryRanges) X(InvalidateMappedMemoryRanges) \ X(CreateCommandPool) X(DestroyCommandPool) X(AllocateCommandBuffers) X(ResetCommandBuffer) \ X(BeginCommandBuffer) X(EndCommandBuffer) X(CmdCopyBuffer) X(CmdPipelineBarrier) \ X(CreateFence) X(DestroyFence) X(ResetFences) X(QueueSubmit) X(WaitForFences) #define DECL(n) static PFN_vk##n p##n; IFNS(DECL) DFNS(DECL) #undef DECL #define CHECK(x) do { VkResult rc=(x); if(rc!=VK_SUCCESS){printf("PROBE_FAIL stage=%s vk_result=%d\n",#x,rc);goto cleanup;} }while(0) #define REQUIRE(x,msg) do {if(!(x)){puts("PROBE_FAIL " msg);goto cleanup;}}while(0) int main(int argc,char **argv) { #ifdef _WIN32 /* Wine/Proton can detach the Windows console from the Linux pipe. */ if(argc>3 && !freopen(argv[3],"w",stdout)) return 4; #endif setvbuf(stdout,NULL,_IONBF,0); puts("PROBE_STAGE main"); unsigned mib=argc>1?(unsigned)strtoul(argv[1],NULL,10):32; int require_low=argc>2&&!strcmp(argv[2],"--require-low32"); if(mib<1||mib>256)return 2; const VkDeviceSize bytes=(VkDeviceSize)mib*1024*1024; VkInstance instance=VK_NULL_HANDLE;VkDevice device=VK_NULL_HANDLE; VkBuffer buffers[2]={0};VkDeviceMemory memories[2]={0}; VkDeviceSize allocated[2]={0};void *mapped[2]={0}; VkCommandPool pool=VK_NULL_HANDLE;VkFence fence=VK_NULL_HANDLE; int success=0,pending=0;uint64_t mismatches=0;unsigned iterations=0; int low_all=1;uint32_t memory_flags[2]={0}; PFN_vkGetInstanceProcAddr gipa; #ifdef _WIN32 HMODULE loader=LoadLibraryA("vulkan-1.dll"); REQUIRE(loader,"load_vulkan_failed"); gipa=(PFN_vkGetInstanceProcAddr)(void *)GetProcAddress(loader,"vkGetInstanceProcAddr"); #else void *loader=dlopen("libvulkan.so.1",RTLD_NOW|RTLD_LOCAL); REQUIRE(loader,"load_vulkan_failed"); gipa=(PFN_vkGetInstanceProcAddr)dlsym(loader,"vkGetInstanceProcAddr"); #endif REQUIRE(gipa,"missing_gipa"); puts("PROBE_STAGE vulkan_loader"); PFN_vkCreateInstance create=(PFN_vkCreateInstance)gipa(NULL,"vkCreateInstance"); REQUIRE(create,"missing_create_instance"); VkApplicationInfo app={.sType=VK_STRUCTURE_TYPE_APPLICATION_INFO, .pApplicationName="DroidDeck low32 buffer integrity probe",.apiVersion=VK_API_VERSION_1_1}; VkInstanceCreateInfo ici={.sType=VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,.pApplicationInfo=&app}; CHECK(create(&ici,NULL,&instance)); puts("PROBE_STAGE instance_created"); #define LOADI(n) p##n=(PFN_vk##n)gipa(instance,"vk" #n);REQUIRE(p##n,"missing_" #n); IFNS(LOADI) #undef LOADI uint32_t count=0;CHECK(pEnumeratePhysicalDevices(instance,&count,NULL)); puts("PROBE_STAGE physical_device_enumeration"); REQUIRE(count&&count<=16,"physical_device_count"); VkPhysicalDevice physicals[16],physical=VK_NULL_HANDLE; CHECK(pEnumeratePhysicalDevices(instance,&count,physicals)); VkPhysicalDeviceProperties properties; for(uint32_t i=0;i