| 193 | } |
| 194 | |
| 195 | void initialize(void* usrdata) |
| 196 | { |
| 197 | backend = *(ECGPUBackend*)usrdata; |
| 198 | |
| 199 | // Create window |
| 200 | SDL_SysWMinfo wmInfo; |
| 201 | sdl_window = SDL_CreateWindow(gCGPUBackendNames[backend], |
| 202 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, |
| 203 | BACK_BUFFER_WIDTH, BACK_BUFFER_HEIGHT, |
| 204 | SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); |
| 205 | SDL_VERSION(&wmInfo.version); |
| 206 | SDL_GetWindowWMInfo(sdl_window, &wmInfo); |
| 207 | |
| 208 | // Create instance |
| 209 | CGPUInstanceDescriptor instance_desc = { |
| 210 | .backend = backend, |
| 211 | .enable_debug_layer = true, |
| 212 | .enable_gpu_based_validation = true, |
| 213 | .enable_set_name = true |
| 214 | }; |
| 215 | instance = cgpu_create_instance(&instance_desc); |
| 216 | // Filter adapters |
| 217 | uint32_t adapters_count = 0; |
| 218 | cgpu_enum_adapters(instance, CGPU_NULLPTR, &adapters_count); |
| 219 | SKR_DECLARE_ZERO_VLA(CGPUAdapterId, adapters, adapters_count); |
| 220 | cgpu_enum_adapters(instance, adapters, &adapters_count); |
| 221 | adapter = adapters[0]; |
| 222 | |
| 223 | // Create device |
| 224 | CGPUQueueGroupDescriptor G = { |
| 225 | .queue_type = CGPU_QUEUE_TYPE_GRAPHICS, |
| 226 | .queue_count = 1 |
| 227 | }; |
| 228 | CGPUDeviceDescriptor device_desc = { |
| 229 | .queue_groups = &G, |
| 230 | .queue_group_count = 1 |
| 231 | }; |
| 232 | device = cgpu_create_device(adapter, &device_desc); |
| 233 | // Create command objects |
| 234 | gfx_queue = cgpu_get_queue(device, CGPU_QUEUE_TYPE_GRAPHICS, 0); |
| 235 | present_semaphore = cgpu_create_semaphore(device); |
| 236 | for (uint32_t i = 0; i < FLIGHT_FRAMES; i++) |
| 237 | { |
| 238 | pools[i] = cgpu_create_command_pool(gfx_queue, CGPU_NULLPTR); |
| 239 | CGPUCommandBufferDescriptor cmd_desc = { .is_secondary = false }; |
| 240 | cmds[i] = cgpu_create_command_buffer(pools[i], &cmd_desc); |
| 241 | exec_fences[i] = cgpu_create_fence(device); |
| 242 | } |
| 243 | // Create swapchain |
| 244 | #if defined(_WIN32) || defined(_WIN64) |
| 245 | surface = cgpu_surface_from_hwnd(device, wmInfo.info.win.window); |
| 246 | #elif defined(__APPLE__) |
| 247 | struct CGPUNSView* ns_view = (struct CGPUNSView*)nswindow_get_content_view(wmInfo.info.cocoa.window); |
| 248 | surface = cgpu_surface_from_ns_view(device, ns_view); |
| 249 | #endif |
| 250 | CGPUSwapChainDescriptor descriptor = { |
| 251 | .present_queues = &gfx_queue, |
| 252 | .present_queues_count = 1, |
no test coverage detected