From efad11008616d30f685752fc70aa05be524c1a78 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 12 Mar 2026 17:14:57 +0100 Subject: fix(win): update wgpu-native to v27, unify Windows/macOS API paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fetch_win_deps.sh: update wgpu-native v0.19.4.1 → v27.0.4.0 (same as macOS) - platform.h: remove v0.19 compat shims, Windows now uses WGPUStringView API - gpu.cc/gpu.h: remove DEMO_CROSS_COMPILE_WIN32 old-API branches - texture_readback.cc, visual_debug.cc, hybrid3d_effect.cc: same cleanup - rotating_cube_effect.cc: remove #ifdef guard for depthSlice - glfw3webgpu.c: remove old WGPUSurfaceDescriptorFromWindowsHWND branch - asset_manager.cc: fix DEMO_STRIP_ALL→STRIP_ALL guard (vs_main was missing in STRIP_ALL Windows builds because disk-loading path ran on embedded data) - tracker.cc: skip MP3 assets gracefully in STRIP_ALL builds instead of fatal handoff(Gemini): Windows .exe now runs under Wine. demo64k.exe renders frames and progresses through audio timeline. Pre-existing test failures unchanged. Co-Authored-By: Claude Sonnet 4.6 --- src/gpu/gpu.cc | 70 ++++++++------------------------------------- src/gpu/gpu.h | 7 ----- src/gpu/pipeline_builder.cc | 3 ++ src/gpu/texture_readback.cc | 26 +---------------- 4 files changed, 16 insertions(+), 90 deletions(-) (limited to 'src/gpu') diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index e743bf7..a463a10 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -325,30 +325,6 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, // --- Main Init/Draw --- #if !defined(STRIP_ALL) -#if defined(DEMO_CROSS_COMPILE_WIN32) -static void handle_request_adapter(WGPURequestAdapterStatus status, - WGPUAdapter adapter, const char* message, - void* userdata) { - if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter*)userdata) = adapter; - } else { - printf("Request adapter failed: %s\n", message ? message : "Unknown"); - } -} -static void handle_request_device(WGPURequestDeviceStatus status, - WGPUDevice device, const char* message, - void* userdata) { - if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice*)userdata) = device; - } else { - printf("Request device failed: %s\n", message ? message : "Unknown"); - } -} -static void handle_device_error(WGPUErrorType type, const char* message, - void* userdata) { - printf("WebGPU Error: %s\n", message ? message : "Unknown"); -} -#else static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata, void* userdata2) { @@ -377,29 +353,13 @@ static void handle_device_error(const WGPUDevice* device, WGPUErrorType type, (void)userdata2; printf("WebGPU Error: %.*s\n", (int)message.length, message.data); } -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ #else // STRIP_ALL versions -#if defined(DEMO_CROSS_COMPILE_WIN32) -static void handle_request_adapter(WGPURequestAdapterStatus status, - WGPUAdapter adapter, const char* message, - void* userdata) { - if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter*)userdata) = adapter; - } -} -static void handle_request_device(WGPURequestDeviceStatus status, - WGPUDevice device, const char* message, - void* userdata) { - if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice*)userdata) = device; - } -} -#else static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata, void* userdata2) { (void)userdata2; + (void)message; if (status == WGPURequestAdapterStatus_Success) { *((WGPUAdapter*)userdata) = adapter; } @@ -408,58 +368,52 @@ static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void* userdata, void* userdata2) { (void)userdata2; + (void)message; if (status == WGPURequestDeviceStatus_Success) { *((WGPUDevice*)userdata) = device; } } -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ #endif /* !defined(STRIP_ALL) */ void gpu_init(PlatformState* platform_state) { +#if defined(DEMO_CROSS_COMPILE_WIN32) + // Exclude GL backend: wgpu's WGL pixel-format selection panics under Wine. + WGPUInstanceExtras win_extras = {}; + win_extras.chain.sType = (WGPUSType)WGPUSType_InstanceExtras; + win_extras.backends = WGPUInstanceBackend_Primary; // Vulkan + DX12, no GL + WGPUInstanceDescriptor win_desc = {}; + win_desc.nextInChain = (WGPUChainedStruct*)&win_extras; + g_instance = wgpuCreateInstance(&win_desc); +#else g_instance = wgpuCreateInstance(nullptr); +#endif g_surface = platform_create_wgpu_surface(g_instance, platform_state); WGPURequestAdapterOptions adapter_opts = {}; adapter_opts.compatibleSurface = g_surface; adapter_opts.powerPreference = WGPUPowerPreference_HighPerformance; -#if defined(DEMO_CROSS_COMPILE_WIN32) - wgpuInstanceRequestAdapter(g_instance, &adapter_opts, handle_request_adapter, - &g_adapter); -#else WGPURequestAdapterCallbackInfo adapter_cb = {}; adapter_cb.mode = WGPUCallbackMode_WaitAnyOnly; adapter_cb.callback = handle_request_adapter; adapter_cb.userdata1 = &g_adapter; wgpuInstanceRequestAdapter(g_instance, &adapter_opts, adapter_cb); -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ while (!g_adapter) platform_wgpu_wait_any(g_instance); WGPUDeviceDescriptor device_desc = {}; #if !defined(STRIP_ALL) -#if !defined(DEMO_CROSS_COMPILE_WIN32) device_desc.uncapturedErrorCallbackInfo.callback = handle_device_error; -#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ #endif /* !defined(STRIP_ALL) */ -#if defined(DEMO_CROSS_COMPILE_WIN32) - wgpuAdapterRequestDevice(g_adapter, &device_desc, handle_request_device, - &g_device); -#else WGPURequestDeviceCallbackInfo device_cb = {}; device_cb.mode = WGPUCallbackMode_WaitAnyOnly; device_cb.callback = handle_request_device; device_cb.userdata1 = &g_device; wgpuAdapterRequestDevice(g_adapter, &device_desc, device_cb); -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ while (!g_device) platform_wgpu_wait_any(g_instance); -#if defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) - platform_wgpu_set_error_callback(g_device, handle_device_error); -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) */ - g_queue = wgpuDeviceGetQueue(g_device); WGPUSurfaceCapabilities caps = {}; diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h index 7754b29..bbced41 100644 --- a/src/gpu/gpu.h +++ b/src/gpu/gpu.h @@ -54,9 +54,7 @@ inline void gpu_init_color_attachment(WGPURenderPassColorAttachment& attachment, attachment.loadOp = WGPULoadOp_Clear; attachment.storeOp = WGPUStoreOp_Store; attachment.clearValue = {0.0f, 0.0f, 0.0f, 1.0f}; -#if !defined(DEMO_CROSS_COMPILE_WIN32) attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; -#endif } struct TextureWithView { @@ -64,13 +62,8 @@ struct TextureWithView { WGPUTextureView view; }; -#if defined(DEMO_CROSS_COMPILE_WIN32) -using GpuTextureCopyInfo = WGPUImageCopyTexture; -using GpuTextureDataLayout = WGPUTextureDataLayout; -#else using GpuTextureCopyInfo = WGPUTexelCopyTextureInfo; using GpuTextureDataLayout = WGPUTexelCopyBufferLayout; -#endif GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, const void* data = nullptr); diff --git a/src/gpu/pipeline_builder.cc b/src/gpu/pipeline_builder.cc index ea4a272..2d9ec07 100644 --- a/src/gpu/pipeline_builder.cc +++ b/src/gpu/pipeline_builder.cc @@ -54,6 +54,9 @@ RenderPipelineBuilder::depth(WGPUTextureFormat depth_fmt) { depth_.format = depth_fmt; depth_.depthWriteEnabled = WGPUOptionalBool_True; depth_.depthCompare = WGPUCompareFunction_Less; + // Vulkan backend panics on WGPUCompareFunction_Undefined (zero) in stencil + depth_.stencilFront.compare = WGPUCompareFunction_Always; + depth_.stencilBack.compare = WGPUCompareFunction_Always; return *this; } diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc index e512428..e7f2729 100644 --- a/src/gpu/texture_readback.cc +++ b/src/gpu/texture_readback.cc @@ -71,19 +71,7 @@ std::vector read_texture_pixels(WGPUInstance instance, // Wait for copy to complete before mapping wgpuDevicePoll(device, true, nullptr); - // Map buffer for reading (API differs between Win32 and native) -#if defined(DEMO_CROSS_COMPILE_WIN32) - // Win32: Old callback API - MapState map_state = {}; - auto map_cb = [](WGPUBufferMapAsyncStatus status, void* userdata) { - MapState* state = (MapState*)(userdata); - state->status = status; - state->done = true; - }; - wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buffer_size, map_cb, - &map_state); -#else - // Native: New callback info API + // Map buffer for reading MapState map_state = {}; auto map_cb = [](WGPUMapAsyncStatus status, WGPUStringView message, void* userdata, void* user2) { @@ -99,7 +87,6 @@ std::vector read_texture_pixels(WGPUInstance instance, map_info.callback = map_cb; map_info.userdata1 = &map_state; wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buffer_size, map_info); -#endif // Wait for mapping to complete (synchronous blocking) for (int i = 0; i < 100 && !map_state.done; ++i) { @@ -221,16 +208,6 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, wgpuDevicePoll(device, true, nullptr); // Map buffer -#if defined(DEMO_CROSS_COMPILE_WIN32) - MapState map_state = {}; - auto map_cb = [](WGPUBufferMapAsyncStatus status, void* userdata) { - MapState* state = (MapState*)(userdata); - state->status = status; - state->done = true; - }; - wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buffer_size, map_cb, - &map_state); -#else MapState map_state = {}; auto map_cb = [](WGPUMapAsyncStatus status, WGPUStringView message, void* userdata, void* user2) { @@ -245,7 +222,6 @@ std::vector texture_readback_fp16_to_u8(WGPUDevice device, map_info.callback = map_cb; map_info.userdata1 = &map_state; wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buffer_size, map_info); -#endif for (int i = 0; i < 100 && !map_state.done; ++i) { wgpuDevicePoll(device, true, nullptr); -- cgit v1.2.3