| 74 | } |
| 75 | |
| 76 | void initialize(void* usrdata) |
| 77 | { |
| 78 | // WASM |
| 79 | wa_watcher = watch_wasm(); |
| 80 | // Create window |
| 81 | SDL_SysWMinfo wmInfo; |
| 82 | backend = *(ECGPUBackend*)usrdata; |
| 83 | |
| 84 | sdl_window = SDL_CreateWindow(gCGPUBackendNames[backend], |
| 85 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, |
| 86 | BACK_BUFFER_WIDTH, BACK_BUFFER_HEIGHT, |
| 87 | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); |
| 88 | SDL_VERSION(&wmInfo.version); |
| 89 | SDL_GetWindowWMInfo(sdl_window, &wmInfo); |
| 90 | |
| 91 | // Create instance |
| 92 | CGPUInstanceDescriptor instance_desc = { |
| 93 | .backend = backend, |
| 94 | .enable_debug_layer = true, |
| 95 | .enable_gpu_based_validation = true, |
| 96 | .enable_set_name = true |
| 97 | }; |
| 98 | instance = cgpu_create_instance(&instance_desc); |
| 99 | |
| 100 | // Filter adapters |
| 101 | uint32_t adapters_count = 0; |
| 102 | cgpu_enum_adapters(instance, CGPU_NULLPTR, &adapters_count); |
| 103 | SKR_DECLARE_ZERO_VLA(CGPUAdapterId, adapters, adapters_count); |
| 104 | cgpu_enum_adapters(instance, adapters, &adapters_count); |
| 105 | adapter = adapters[0]; |
| 106 | |
| 107 | // Create device |
| 108 | CGPUQueueGroupDescriptor G = { |
| 109 | .queue_type = CGPU_QUEUE_TYPE_GRAPHICS, |
| 110 | .queue_count = 1 |
| 111 | }; |
| 112 | CGPUDeviceDescriptor device_desc = { |
| 113 | .queue_groups = &G, |
| 114 | .queue_group_count = 1 |
| 115 | }; |
| 116 | device = cgpu_create_device(adapter, &device_desc); |
| 117 | gfx_queue = cgpu_get_queue(device, CGPU_QUEUE_TYPE_GRAPHICS, 0); |
| 118 | present_fence = cgpu_create_fence(device); |
| 119 | |
| 120 | // Create swapchain |
| 121 | #if defined(_WIN32) || defined(_WIN64) |
| 122 | surface = cgpu_surface_from_hwnd(device, wmInfo.info.win.window); |
| 123 | #elif defined(__APPLE__) |
| 124 | struct CGPUNSView* ns_view = (struct CGPUNSView*)nswindow_get_content_view(wmInfo.info.cocoa.window); |
| 125 | surface = cgpu_surface_from_ns_view(device, ns_view); |
| 126 | #endif |
| 127 | CGPUSwapChainDescriptor descriptor = { |
| 128 | .present_queues = &gfx_queue, |
| 129 | .present_queues_count = 1, |
| 130 | .width = BACK_BUFFER_WIDTH, |
| 131 | .height = BACK_BUFFER_HEIGHT, |
| 132 | .surface = surface, |
| 133 | .image_count = 3, |
no test coverage detected