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/3d/renderer_pipelines.cc | 6 ++++ src/3d/visual_debug.cc | 18 ++-------- src/audio/tracker.cc | 5 +-- src/effects/hybrid3_d_effect.cc | 6 ---- src/effects/rotating_cube_effect.cc | 13 ++++--- src/gpu/gpu.cc | 70 +++++++------------------------------ src/gpu/gpu.h | 7 ---- src/gpu/pipeline_builder.cc | 3 ++ src/gpu/texture_readback.cc | 26 +------------- src/platform/platform.h | 35 +++++++++---------- src/util/asset_manager.cc | 6 ++-- 11 files changed, 52 insertions(+), 143 deletions(-) (limited to 'src') diff --git a/src/3d/renderer_pipelines.cc b/src/3d/renderer_pipelines.cc index 2950a7f..3abc3bd 100644 --- a/src/3d/renderer_pipelines.cc +++ b/src/3d/renderer_pipelines.cc @@ -102,6 +102,8 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) { depth_stencil.format = WGPUTextureFormat_Depth24Plus; depth_stencil.depthWriteEnabled = WGPUOptionalBool_True; depth_stencil.depthCompare = WGPUCompareFunction_Less; + depth_stencil.stencilFront.compare = WGPUCompareFunction_Always; + depth_stencil.stencilBack.compare = WGPUCompareFunction_Always; WGPUColorTargetState color_target = {}; color_target.format = format_; @@ -214,6 +216,8 @@ void Renderer3D::create_mesh_pipeline() { depth_stencil.format = WGPUTextureFormat_Depth24Plus; depth_stencil.depthWriteEnabled = WGPUOptionalBool_True; depth_stencil.depthCompare = WGPUCompareFunction_Less; + depth_stencil.stencilFront.compare = WGPUCompareFunction_Always; + depth_stencil.stencilBack.compare = WGPUCompareFunction_Always; WGPUColorTargetState color_target = {}; color_target.format = format_; @@ -305,6 +309,8 @@ void Renderer3D::create_skybox_pipeline() { depth_stencil.format = WGPUTextureFormat_Depth24Plus; depth_stencil.depthWriteEnabled = WGPUOptionalBool_False; depth_stencil.depthCompare = WGPUCompareFunction_Always; + depth_stencil.stencilFront.compare = WGPUCompareFunction_Always; + depth_stencil.stencilBack.compare = WGPUCompareFunction_Always; WGPUColorTargetState color_target = {}; color_target.format = format_; diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc index f6796d5..036d6ce 100644 --- a/src/3d/visual_debug.cc +++ b/src/3d/visual_debug.cc @@ -68,19 +68,11 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) { const char* shader_code = (const char*)GetAsset(AssetId::ASSET_SHADER_VISUAL_DEBUG, &shader_len); -#if defined(DEMO_CROSS_COMPILE_WIN32) - WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; - wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; - wgsl_desc.code = shader_code; - WGPUShaderModuleDescriptor shader_desc = {}; - shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain; -#else WGPUShaderSourceWGSL wgsl_desc = {}; wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL; wgsl_desc.code = {shader_code, shader_len}; WGPUShaderModuleDescriptor shader_desc = {}; shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain; -#endif WGPUShaderModule shader_module = wgpuDeviceCreateShaderModule(device_, &shader_desc); @@ -105,21 +97,13 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) { WGPURenderPipelineDescriptor pipeline_desc = {}; pipeline_desc.layout = pipeline_layout; pipeline_desc.vertex.module = shader_module; -#if defined(DEMO_CROSS_COMPILE_WIN32) - pipeline_desc.vertex.entryPoint = "vs_main"; -#else pipeline_desc.vertex.entryPoint = str_view("vs_main"); -#endif pipeline_desc.vertex.bufferCount = 1; pipeline_desc.vertex.buffers = &vertex_layout; WGPUFragmentState fragment_state = {}; fragment_state.module = shader_module; -#if defined(DEMO_CROSS_COMPILE_WIN32) - fragment_state.entryPoint = "fs_main"; -#else fragment_state.entryPoint = str_view("fs_main"); -#endif fragment_state.targetCount = 1; WGPUColorTargetState color_target = {}; @@ -138,6 +122,8 @@ void VisualDebug::create_pipeline(WGPUTextureFormat format) { depth_stencil.depthWriteEnabled = WGPUOptionalBool_False; // Don't write depth depth_stencil.depthCompare = WGPUCompareFunction_Less; // But do test against it + depth_stencil.stencilFront.compare = WGPUCompareFunction_Always; + depth_stencil.stencilBack.compare = WGPUCompareFunction_Always; pipeline_desc.depthStencil = &depth_stencil; pipeline_desc.multisample.count = 1; diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc index 93c279e..d9beb56 100644 --- a/src/audio/tracker.cc +++ b/src/audio/tracker.cc @@ -158,8 +158,9 @@ void tracker_init() { } } else #else - FATAL_CHECK(data == nullptr || GetAssetType(aid) != AssetType::MP3, - "MP3 assets not supported in STRIP_ALL builds\n"); + if (data != nullptr && GetAssetType(aid) == AssetType::MP3) { + continue; // MP3 decoding not available in STRIP_ALL builds + } #endif if (data && size >= sizeof(SpecHeader)) { const SpecHeader* header = (const SpecHeader*)data; diff --git a/src/effects/hybrid3_d_effect.cc b/src/effects/hybrid3_d_effect.cc index 37d4158..33a2d73 100644 --- a/src/effects/hybrid3_d_effect.cc +++ b/src/effects/hybrid3_d_effect.cc @@ -33,15 +33,9 @@ Hybrid3D::Hybrid3D(const GpuContext& ctx, // Write white pixel uint32_t white_pixel = 0xFFFFFFFF; -#if defined(DEMO_CROSS_COMPILE_WIN32) - WGPUImageCopyTexture dst = { - .texture = dummy_texture_, .mipLevel = 0, .origin = {0, 0, 0}}; - WGPUTextureDataLayout data_layout = {.bytesPerRow = 4, .rowsPerImage = 1}; -#else WGPUTexelCopyTextureInfo dst = { .texture = dummy_texture_, .mipLevel = 0, .origin = {0, 0, 0}}; WGPUTexelCopyBufferLayout data_layout = {.bytesPerRow = 4, .rowsPerImage = 1}; -#endif WGPUExtent3D size = {1, 1, 1}; wgpuQueueWriteTexture(ctx_.queue, &dst, &white_pixel, 4, &data_layout, &size); diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc index 6ee3e85..82f90c5 100644 --- a/src/effects/rotating_cube_effect.cc +++ b/src/effects/rotating_cube_effect.cc @@ -59,11 +59,12 @@ RotatingCube::RotatingCube(const GpuContext& ctx, .writeMask = WGPUColorWriteMask_All, }; - const WGPUDepthStencilState depth_stencil = { - .format = WGPUTextureFormat_Depth24Plus, - .depthWriteEnabled = WGPUOptionalBool_True, - .depthCompare = WGPUCompareFunction_Less, - }; + WGPUDepthStencilState depth_stencil = {}; + depth_stencil.format = WGPUTextureFormat_Depth24Plus; + depth_stencil.depthWriteEnabled = WGPUOptionalBool_True; + depth_stencil.depthCompare = WGPUCompareFunction_Less; + depth_stencil.stencilFront.compare = WGPUCompareFunction_Always; + depth_stencil.stencilBack.compare = WGPUCompareFunction_Always; WGPUFragmentState fragment = {}; fragment.module = shader_module; @@ -181,9 +182,7 @@ void RotatingCube::render(WGPUCommandEncoder encoder, // Render pass with depth WGPURenderPassColorAttachment color_attachment = { .view = color_view, -#if !defined(DEMO_CROSS_COMPILE_WIN32) .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, -#endif // .loadOp = WGPULoadOp_Clear, .loadOp = WGPULoadOp_Load, .storeOp = WGPUStoreOp_Store, 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); diff --git a/src/platform/platform.h b/src/platform/platform.h index 03aa2b3..4b31ac3 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -14,32 +14,29 @@ #include #include -#define WGPUOptionalBool_True true -#define WGPUOptionalBool_False false -#define WGPUSType_ShaderSourceWGSL WGPUSType_ShaderModuleWGSLDescriptor -#define WGPU_DEPTH_SLICE_UNDEFINED 0xffffffff -#define WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal \ - WGPUSurfaceGetCurrentTextureStatus_Success -#define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ - WGPUSurfaceGetCurrentTextureStatus_Success -#define WGPUCallbackMode_WaitAnyOnly 0 - -typedef WGPUShaderModuleWGSLDescriptor WGPUShaderSourceWGSL; - -static inline const char* str_view(const char* str) { - return str; +static inline WGPUStringView str_view(const char* str) { + if (!str) + return {nullptr, 0}; + return {str, strlen(str)}; } -static inline const char* label_view(const char* str) { - return str; + +static inline WGPUStringView label_view(const char* str) { +#if !defined(STRIP_ALL) + if (!str) + return {nullptr, 0}; + return {str, strlen(str)}; +#else + (void)str; + return {nullptr, 0}; +#endif } static inline void platform_wgpu_wait_any(WGPUInstance instance) { - wgpuInstanceProcessEvents(instance); + wgpuInstanceWaitAny(instance, 0, nullptr, 0); } static inline void platform_wgpu_set_error_callback(WGPUDevice device, - WGPUErrorCallback callback) { - wgpuDeviceSetUncapturedErrorCallback(device, callback, nullptr); + WGPUUncapturedErrorCallback callback) { } #else diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc index 1c02626..0b96cb2 100644 --- a/src/util/asset_manager.cc +++ b/src/util/asset_manager.cc @@ -28,7 +28,7 @@ static const ProcGenEntry kAssetManagerProcGenFuncs[] = { {"gen_perlin", procedural::gen_perlin}, {"gen_grid", procedural::gen_grid}, {"make_periodic", procedural::make_periodic}, -#if !defined(DEMO_STRIP_ALL) +#if !defined(STRIP_ALL) {"gen_noise_256", procedural::gen_noise_256}, {"gen_fail", procedural::gen_fail}, #endif @@ -76,7 +76,7 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) { AssetRecord source_record = assets[index]; -#if !defined(DEMO_STRIP_ALL) +#if !defined(STRIP_ALL) if (source_record.type == AssetType::SPEC || source_record.type == AssetType::MP3 || source_record.type == AssetType::WGSL) { @@ -222,7 +222,7 @@ void DropAsset(AssetId asset_id, const uint8_t* asset) { delete[] g_asset_cache[index].data; g_asset_cache[index] = {}; // Zero out the struct to force re-generation } -#if !defined(DEMO_STRIP_ALL) +#if !defined(STRIP_ALL) if (g_asset_cache[index].data == asset && (g_asset_cache[index].type == AssetType::SPEC || g_asset_cache[index].type == AssetType::MP3 || -- cgit v1.2.3