diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-12 17:14:57 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-12 17:14:57 +0100 |
| commit | efad11008616d30f685752fc70aa05be524c1a78 (patch) | |
| tree | 3a2dad4e054749af900c03800b3868d7a26a7678 | |
| parent | ce032eb25a480c086edcd7bbfa4a742e5e44a6a7 (diff) | |
fix(win): update wgpu-native to v27, unify Windows/macOS API paths
- 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 <noreply@anthropic.com>
| -rw-r--r-- | cmake/Toolchain-MinGW-w64.cmake | 10 | ||||
| -rwxr-xr-x | scripts/build_win.sh | 29 | ||||
| -rwxr-xr-x | scripts/fetch_win_deps.sh | 14 | ||||
| -rwxr-xr-x | scripts/run_win.sh | 3 | ||||
| -rw-r--r-- | src/3d/renderer_pipelines.cc | 6 | ||||
| -rw-r--r-- | src/3d/visual_debug.cc | 18 | ||||
| -rw-r--r-- | src/audio/tracker.cc | 5 | ||||
| -rw-r--r-- | src/effects/hybrid3_d_effect.cc | 6 | ||||
| -rw-r--r-- | src/effects/rotating_cube_effect.cc | 13 | ||||
| -rw-r--r-- | src/gpu/gpu.cc | 70 | ||||
| -rw-r--r-- | src/gpu/gpu.h | 7 | ||||
| -rw-r--r-- | src/gpu/pipeline_builder.cc | 3 | ||||
| -rw-r--r-- | src/gpu/texture_readback.cc | 26 | ||||
| -rw-r--r-- | src/platform/platform.h | 35 | ||||
| -rw-r--r-- | src/util/asset_manager.cc | 6 | ||||
| -rw-r--r-- | third_party/glfw3webgpu/glfw3webgpu.c | 14 |
16 files changed, 79 insertions, 186 deletions
diff --git a/cmake/Toolchain-MinGW-w64.cmake b/cmake/Toolchain-MinGW-w64.cmake index 57c146a..910efb4 100644 --- a/cmake/Toolchain-MinGW-w64.cmake +++ b/cmake/Toolchain-MinGW-w64.cmake @@ -6,7 +6,11 @@ set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) # Where is the target environment located -set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 /usr/local/opt/mingw-w64) +set(CMAKE_FIND_ROOT_PATH + /usr/x86_64-w64-mingw32 + /usr/local/opt/mingw-w64 + /opt/homebrew/Cellar/mingw-w64/13.0.0_2/toolchain-x86_64/x86_64-w64-mingw32 +) # Adjust the default behavior of the FIND_XXX() commands: # search for headers and libraries in the target environment, @@ -15,5 +19,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +# Statically link MinGW runtimes so the exe needs no libgcc/libstdc++/libwinpthread DLLs. +# wgpu_native.dll is still dynamic (linked via import lib). +set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-Bstatic -lwinpthread -Wl,-Bdynamic") + # Define a flag to identify this specific build set(DEMO_CROSS_COMPILE_WIN32 ON) diff --git a/scripts/build_win.sh b/scripts/build_win.sh index da75748..4b7f576 100755 --- a/scripts/build_win.sh +++ b/scripts/build_win.sh @@ -15,32 +15,23 @@ cmake -S . -B build_win \ -DDEMO_CROSS_COMPILE_WIN32=ON \ -DDEMO_STRIP_ALL=ON \ -DASSET_PACKER_PATH=$ASSET_PACKER_PATH \ - -DTRACKER_COMPILER_PATH=$TRACKER_COMPILER_PATH + -DTRACKER_COMPILER_PATH=$TRACKER_COMPILER_PATH \ + "-DCMAKE_EXE_LINKER_FLAGS=-static-libgcc -static-libstdc++ -Wl,-Bstatic -lwinpthread -Wl,-Bdynamic" cmake --build build_win -j8 # 3. Copy runtime DLLs to build_win so we can run it cp third_party/windows/lib/wgpu_native.dll build_win/ -# Copy MinGW DLLs (pthread, etc.) -echo "Copying MinGW DLLs..." -if [[ "$(uname)" == "Darwin" ]]; then - MINGW_SEARCH_ROOTS="/opt/homebrew" -else - # Linux / WSL: mingw-w64 installed via apt - MINGW_SEARCH_ROOTS="/usr/x86_64-w64-mingw32 /usr/lib/gcc/x86_64-w64-mingw32" +# Copy libwinpthread-1.dll (wgpu_native.dll depends on it even when exe statically links it) +WINPTHREAD_DLL=$(x86_64-w64-mingw32-gcc --print-file-name=libwinpthread-1.dll 2>/dev/null) +if [ ! -f "$WINPTHREAD_DLL" ]; then + WINPTHREAD_DLL=$(find /opt/homebrew /usr /usr/local -path "*x86_64*" -name "libwinpthread-1.dll" 2>/dev/null | head -1) fi -COPIED=0 -for dll in libwinpthread-1.dll libgcc_s_seh-1.dll libstdc++-6.dll; do - src=$(find $MINGW_SEARCH_ROOTS -name "$dll" 2>/dev/null | head -n 1) - if [ -n "$src" ]; then - cp "$src" build_win/ - echo " Copied: $dll" - COPIED=$((COPIED+1)) - fi -done -if [ "$COPIED" -eq 0 ]; then - echo "Warning: Could not find MinGW DLLs. You might need them to run the exe." +if [ -f "$WINPTHREAD_DLL" ]; then + cp "$WINPTHREAD_DLL" build_win/ +else + echo "Warning: libwinpthread-1.dll not found — Wine may fail to run" fi # 4. Crunch the binary diff --git a/scripts/fetch_win_deps.sh b/scripts/fetch_win_deps.sh index a32f047..c66fc34 100755 --- a/scripts/fetch_win_deps.sh +++ b/scripts/fetch_win_deps.sh @@ -13,17 +13,17 @@ cp glfw-3.4.bin.WIN64/lib-mingw-w64/libglfw3.a third_party/windows/lib/ cp glfw-3.4.bin.WIN64/include/GLFW/* third_party/windows/include/GLFW/ rm -rf glfw.zip glfw-3.4.bin.WIN64 -echo "Fetching wgpu-native v0.19.4.1..." -curl -L -o wgpu.zip https://github.com/gfx-rs/wgpu-native/releases/download/v0.19.4.1/wgpu-windows-x86_64-release.zip +echo "Fetching wgpu-native v27.0.4.0..." +curl -L -o wgpu.zip https://github.com/gfx-rs/wgpu-native/releases/download/v27.0.4.0/wgpu-windows-x86_64-msvc-release.zip unzip -q wgpu.zip -d wgpu_temp -# Copy import library (renaming for MinGW convention, though it can usually read .lib) -cp wgpu_temp/wgpu_native.dll.lib third_party/windows/lib/libwgpu_native.dll.a +# Copy import library (renaming for MinGW convention) +cp wgpu_temp/lib/wgpu_native.dll.lib third_party/windows/lib/libwgpu_native.dll.a # Copy runtime DLL (will be needed next to executable) -cp wgpu_temp/wgpu_native.dll third_party/windows/lib/wgpu_native.dll +cp wgpu_temp/lib/wgpu_native.dll third_party/windows/lib/wgpu_native.dll # Copy headers mkdir -p third_party/windows/include/webgpu -cp wgpu_temp/webgpu.h third_party/windows/include/webgpu/ -cp wgpu_temp/wgpu.h third_party/windows/include/webgpu/ +cp wgpu_temp/include/webgpu/webgpu.h third_party/windows/include/webgpu/ +cp wgpu_temp/include/webgpu/wgpu.h third_party/windows/include/webgpu/ rm -rf wgpu.zip wgpu_temp echo "Windows dependencies fetched." diff --git a/scripts/run_win.sh b/scripts/run_win.sh index 853a985..fabb3fe 100755 --- a/scripts/run_win.sh +++ b/scripts/run_win.sh @@ -5,5 +5,4 @@ if [ ! -f build_win/demo64k.exe ]; then fi echo "Running with Wine..." -# Wine might output a lot of debug info, but for now we let it flow. -wine build_win/demo64k.exe "$@" +WINEPATH="$(pwd)/build_win" wine build_win/demo64k.exe "$@" 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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 <webgpu/webgpu.h> #include <webgpu/wgpu.h> -#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 || diff --git a/third_party/glfw3webgpu/glfw3webgpu.c b/third_party/glfw3webgpu/glfw3webgpu.c index b605753..38eaec0 100644 --- a/third_party/glfw3webgpu/glfw3webgpu.c +++ b/third_party/glfw3webgpu/glfw3webgpu.c @@ -137,19 +137,6 @@ WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* windo HWND hwnd = glfwGetWin32Window(window); HINSTANCE hinstance = GetModuleHandle(NULL); -#if defined(DEMO_CROSS_COMPILE_WIN32) - // Old API (wgpu-native v0.19) - WGPUSurfaceDescriptorFromWindowsHWND fromWindowsHWND; - fromWindowsHWND.chain.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND; - fromWindowsHWND.chain.next = NULL; - fromWindowsHWND.hinstance = hinstance; - fromWindowsHWND.hwnd = hwnd; - - WGPUSurfaceDescriptor surfaceDescriptor; - surfaceDescriptor.nextInChain = (const WGPUChainedStruct*)&fromWindowsHWND; - surfaceDescriptor.label = NULL; -#else - // New API WGPUSurfaceSourceWindowsHWND fromWindowsHWND; fromWindowsHWND.chain.sType = WGPUSType_SurfaceSourceWindowsHWND; fromWindowsHWND.chain.next = NULL; @@ -159,7 +146,6 @@ WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* windo WGPUSurfaceDescriptor surfaceDescriptor; surfaceDescriptor.nextInChain = &fromWindowsHWND.chain; surfaceDescriptor.label = (WGPUStringView){ NULL, WGPU_STRLEN }; -#endif return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); } |
