// Covers the initialization dependency fixed by Segmentree in PR #228. // Build: clang++ -std=c++20 -O2 -I"%VULKAN_SDK%/Include" nx2/texture_init_dependency_probe.cpp -o texture_init_dependency_probe.exe // Set VK_LAYER_PATH to the Khronos validation layer directory; run the executable with old, then fixed. // API dependency probe only: no game data and no claim about coloured-noise causality. // Run with Khronos validation installed. old: expect SYNC-HAZARD-WRITE-AFTER-WRITE; // fixed: expect no validation errors. Uses the exact PR228 dependency scopes. #define WIN32_LEAN_AND_MEAN #define VK_NO_PROTOTYPES #include #include #include #include #include #include #define CHECK(v) do {if(!(v)){std::fprintf(stderr,"FAIL:%d %s\n",__LINE__,#v);std::exit(2);}}while(0) #define APIS(X) X(vkCreateInstance) X(vkDestroyInstance) X(vkEnumeratePhysicalDevices) X(vkGetPhysicalDeviceProperties) X(vkGetPhysicalDeviceQueueFamilyProperties) X(vkGetPhysicalDeviceMemoryProperties) X(vkCreateDevice) X(vkDestroyDevice) X(vkGetDeviceQueue) X(vkCreateImage) X(vkDestroyImage) X(vkGetImageMemoryRequirements) X(vkAllocateMemory) X(vkFreeMemory) X(vkBindImageMemory) X(vkCreateBuffer) X(vkDestroyBuffer) X(vkGetBufferMemoryRequirements) X(vkBindBufferMemory) X(vkMapMemory) X(vkUnmapMemory) X(vkCreateCommandPool) X(vkDestroyCommandPool) X(vkAllocateCommandBuffers) X(vkBeginCommandBuffer) X(vkEndCommandBuffer) X(vkCmdPipelineBarrier2) X(vkCmdClearColorImage) X(vkCmdCopyBufferToImage) X(vkQueueSubmit) X(vkQueueWaitIdle) #define DECL(n) PFN_##n n; APIS(DECL) int errors=0,hazards=0; VKAPI_ATTR VkBool32 VKAPI_CALL debug(VkDebugUtilsMessageSeverityFlagBitsEXT severity,VkDebugUtilsMessageTypeFlagsEXT,const VkDebugUtilsMessengerCallbackDataEXT* data,void*) { if(severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT){errors++;std::fprintf(stderr,"%s: %s\n",data->pMessageIdName ? data->pMessageIdName : "(no message ID)",data->pMessage);} if((data->pMessageIdName && std::strstr(data->pMessageIdName,"SYNC-HAZARD-WRITE-AFTER-WRITE")) || std::strstr(data->pMessage,"WRITE_AFTER_WRITE"))hazards++; return VK_FALSE; } int main(int argc,char**argv) { const bool fixed=argc==2 && !std::strcmp(argv[1],"fixed");CHECK(fixed || (argc==2 && !std::strcmp(argv[1],"old"))); auto loader=LoadLibraryA("vulkan-1.dll");CHECK(loader); #define LOAD(n) n=(PFN_##n)GetProcAddress(loader,#n);CHECK(n); APIS(LOAD) auto gip=(PFN_vkGetInstanceProcAddr)GetProcAddress(loader,"vkGetInstanceProcAddr");CHECK(gip); VkValidationFeatureEnableEXT feature=VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT; VkValidationFeaturesEXT vf{VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT};vf.enabledValidationFeatureCount=1;vf.pEnabledValidationFeatures=&feature; VkDebugUtilsMessengerCreateInfoEXT db{VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT}; db.messageSeverity=VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;db.messageType=VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;db.pfnUserCallback=debug;db.pNext=&vf; const char* layers[]={"VK_LAYER_KHRONOS_validation"};const char* extensions[]={VK_EXT_DEBUG_UTILS_EXTENSION_NAME,VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME}; VkApplicationInfo app{VK_STRUCTURE_TYPE_APPLICATION_INFO};app.apiVersion=VK_API_VERSION_1_3; VkInstanceCreateInfo ici{VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};ici.pNext=&db;ici.pApplicationInfo=&app;ici.enabledLayerCount=1;ici.ppEnabledLayerNames=layers;ici.enabledExtensionCount=2;ici.ppEnabledExtensionNames=extensions; VkInstance instance{};CHECK(vkCreateInstance(&ici,nullptr,&instance)==VK_SUCCESS); auto createDebug=(PFN_vkCreateDebugUtilsMessengerEXT)gip(instance,"vkCreateDebugUtilsMessengerEXT");auto destroyDebug=(PFN_vkDestroyDebugUtilsMessengerEXT)gip(instance,"vkDestroyDebugUtilsMessengerEXT");CHECK(createDebug && destroyDebug); db.pNext=nullptr;VkDebugUtilsMessengerEXT messenger{};CHECK(createDebug(instance,&db,nullptr,&messenger)==VK_SUCCESS); uint32_t n=0;CHECK(vkEnumeratePhysicalDevices(instance,&n,nullptr)==VK_SUCCESS && n);std::vector devices(n);CHECK(vkEnumeratePhysicalDevices(instance,&n,devices.data())==VK_SUCCESS); auto physical=devices[0];for(auto d:devices){VkPhysicalDeviceProperties props{};vkGetPhysicalDeviceProperties(d,&props);if(props.vendorID==0x1002)physical=d;} VkPhysicalDeviceProperties props{};vkGetPhysicalDeviceProperties(physical,&props);std::printf("device: %s; mode: %s\n",props.deviceName,argv[1]); vkGetPhysicalDeviceQueueFamilyProperties(physical,&n,nullptr);std::vector families(n);vkGetPhysicalDeviceQueueFamilyProperties(physical,&n,families.data());uint32_t family=0;while(family0);puts("PASS: API dependency probe expectation met"); }