|
| 1 | +// Standalone CI probe: repeated fallback-adapter + device acquire/release |
| 2 | +// cycles on one WGPUInstance — the exact pattern the integration suite runs |
| 3 | +// before wgpuInstanceRequestAdapter starts panicking on lavapipe (CI Linux, |
| 4 | +// core-dump verified). Running it outside Flutter keeps wgpu's panic message |
| 5 | +// on a visible stderr. |
| 6 | +// |
| 7 | +// Build (from the repo root, after fetch_wgpu_native.sh): |
| 8 | +// cc scripts/ci/adapter_cycle_probe.c \ |
| 9 | +// src/third_party/wgpu_native/linux-x86_64/lib/libwgpu_native.a \ |
| 10 | +// -Isrc/third_party/wgpu_native/include -lm -ldl -lpthread \ |
| 11 | +// -o /tmp/adapter_cycle_probe |
| 12 | +#include <stdio.h> |
| 13 | +#include <webgpu/webgpu.h> |
| 14 | + |
| 15 | +static WGPUAdapter g_adapter; |
| 16 | +static WGPUDevice g_device; |
| 17 | + |
| 18 | +static void onAdapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, |
| 19 | + WGPUStringView message, void* u1, void* u2) { |
| 20 | + (void)u1; (void)u2; |
| 21 | + if (status != WGPURequestAdapterStatus_Success) { |
| 22 | + fprintf(stderr, "adapter error: %.*s\n", (int)message.length, |
| 23 | + message.data ? message.data : ""); |
| 24 | + } |
| 25 | + g_adapter = adapter; |
| 26 | +} |
| 27 | + |
| 28 | +static void onDevice(WGPURequestDeviceStatus status, WGPUDevice device, |
| 29 | + WGPUStringView message, void* u1, void* u2) { |
| 30 | + (void)u1; (void)u2; |
| 31 | + if (status != WGPURequestDeviceStatus_Success) { |
| 32 | + fprintf(stderr, "device error: %.*s\n", (int)message.length, |
| 33 | + message.data ? message.data : ""); |
| 34 | + } |
| 35 | + g_device = device; |
| 36 | +} |
| 37 | + |
| 38 | +int main(void) { |
| 39 | + WGPUInstance instance = wgpuCreateInstance(NULL); |
| 40 | + if (!instance) { |
| 41 | + fprintf(stderr, "wgpuCreateInstance failed\n"); |
| 42 | + return 1; |
| 43 | + } |
| 44 | + for (int i = 0; i < 40; i++) { |
| 45 | + g_adapter = NULL; |
| 46 | + g_device = NULL; |
| 47 | + |
| 48 | + WGPURequestAdapterOptions opts = WGPU_REQUEST_ADAPTER_OPTIONS_INIT; |
| 49 | + opts.forceFallbackAdapter = 1; |
| 50 | + WGPURequestAdapterCallbackInfo acb = |
| 51 | + WGPU_REQUEST_ADAPTER_CALLBACK_INFO_INIT; |
| 52 | + acb.mode = WGPUCallbackMode_AllowProcessEvents; |
| 53 | + acb.callback = onAdapter; |
| 54 | + wgpuInstanceRequestAdapter(instance, &opts, acb); |
| 55 | + for (int t = 0; t < 1000 && !g_adapter; t++) { |
| 56 | + wgpuInstanceProcessEvents(instance); |
| 57 | + } |
| 58 | + if (!g_adapter) { |
| 59 | + fprintf(stderr, "iter %d: no adapter\n", i); |
| 60 | + return 1; |
| 61 | + } |
| 62 | + |
| 63 | + WGPUDeviceDescriptor dd = WGPU_DEVICE_DESCRIPTOR_INIT; |
| 64 | + WGPURequestDeviceCallbackInfo dcb = |
| 65 | + WGPU_REQUEST_DEVICE_CALLBACK_INFO_INIT; |
| 66 | + dcb.mode = WGPUCallbackMode_AllowProcessEvents; |
| 67 | + dcb.callback = onDevice; |
| 68 | + wgpuAdapterRequestDevice(g_adapter, &dd, dcb); |
| 69 | + for (int t = 0; t < 1000 && !g_device; t++) { |
| 70 | + wgpuInstanceProcessEvents(instance); |
| 71 | + } |
| 72 | + if (!g_device) { |
| 73 | + fprintf(stderr, "iter %d: no device\n", i); |
| 74 | + return 1; |
| 75 | + } |
| 76 | + |
| 77 | + WGPUQueue queue = wgpuDeviceGetQueue(g_device); |
| 78 | + wgpuQueueRelease(queue); |
| 79 | + wgpuDeviceRelease(g_device); |
| 80 | + wgpuAdapterRelease(g_adapter); |
| 81 | + fprintf(stderr, "iter %d ok\n", i); |
| 82 | + } |
| 83 | + fprintf(stderr, "PROBE PASSED: 40 adapter+device cycles\n"); |
| 84 | + return 0; |
| 85 | +} |
0 commit comments