diff --git a/README.md b/README.md index a636b17..3e5228b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This package exposes two modules: `wgpu-c` and `wgpu`. ## Adding this package to your build Add the package to your dependencies, either with: ```sh -zig fetch --save https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v6.5.0.tar.gz +zig fetch --save https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v7.0.0.tar.gz ``` or by manually adding to your `build.zig.zon`: ```zig @@ -24,7 +24,7 @@ or by manually adding to your `build.zig.zon`: // You can either use a commit hash: .url="https://github.com/bronter/wgpu_native_zig/archive/.tar.gz", // or a tagged release: - // .url = "https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v6.5.0.tar.gz` + // .url = "https://github.com/bronter/wgpu_native_zig/archive/refs/tags/v7.0.0.tar.gz` .hash="" } } @@ -97,7 +97,7 @@ b.getInstallStep().dependOn(&install_dll.step); ## Building `wgpu-native` -`wgpu-native` v25.0.2.1 is built from its pinned source commit by default. The matching +`wgpu-native` v29.0.0.0 is built from its pinned source commit by default. The matching `webgpu-headers` commit is pinned separately, so the generated C ABI does not drift when an upstream branch changes. diff --git a/build.zig.zon b/build.zig.zon index 78f56f9..7acecb2 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,7 +2,7 @@ .name = .wgpu_native_zig, // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. - .version = "6.5.0", + .version = "7.0.0", .fingerprint = 0xdd8fa7c40cded807, // This field is optional. @@ -17,13 +17,19 @@ // internet connectivity. .dependencies = .{ .wgpu_native_source = .{ - .url = "https://github.com/gfx-rs/wgpu-native/archive/af9074edf144efe4f1432b2e42c477429c4964c1.tar.gz", - .hash = "N-V-__8AAMkXCADZTmf51o8SSzRb6oYEb3rjtHl5duhu7Wzs", + .url = "https://github.com/gfx-rs/wgpu-native/archive/d2e3330ade4ae1bb238d76b485926f067e7ee64c.tar.gz", + .hash = "N-V-__8AAOEBCQDjHbYvo-IVZoEoDA_pik7xV3_cNs5ykiVr", .lazy = true, }, .webgpu_headers_source = .{ - .url = "https://github.com/webgpu-native/webgpu-headers/archive/bac520839ff5ed2e2b648ed540bd9ec45edbccbc.tar.gz", - .hash = "N-V-__8AAIEJBgDDDaQxHnH7W6qR_NeONW1g8R_Tt0Xe9n_u", + .url = "https://github.com/webgpu-native/webgpu-headers/archive/7d3186c3dd2c708703524027b46b8703534ab3cc.tar.gz", + .hash = "N-V-__8AAKfVCwACaVDbxAcElqWNITTDQQSvqtRBmFQOAqNe", + .lazy = true, + }, + // Used only for the OHOS ARMv7 source-build compatibility patch. + .wgpu_source_29_0_1 = .{ + .url = "https://github.com/gfx-rs/wgpu/archive/refs/tags/v29.0.1.tar.gz", + .hash = "N-V-__8AAL7MCAI7KtjV9IE2GaelUvxkij22ME6R6LDsbqf_", .lazy = true, }, // See `zig fetch --save ` for a command-line interface for adding dependencies. @@ -55,153 +61,153 @@ // .lazy = false, //}, .wgpu_android_aarch64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-aarch64-debug.zip", - .hash = "N-V-__8AAPQyVxT6i7mm0AzaidOZmgXO0JlVRTK4cIzdhiIJ", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-aarch64-debug.zip", + .hash = "N-V-__8AAGvq2hPU8ujk0mlr_vLyNpYkVeX6BUcQidclfVuU", .lazy = true, }, .wgpu_android_aarch64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-aarch64-release.zip", - .hash = "N-V-__8AAH5jwgMJj3SR-h6LEpl2nU1rEwl4tS6ZGvV4Kr_A", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-aarch64-release.zip", + .hash = "N-V-__8AAOMZ3ANUM5Mf7SFpwenzHmljuL9nsBw7bYm_j9XB", .lazy = true, }, .wgpu_android_armv7_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-armv7-debug.zip", - .hash = "N-V-__8AAPrsHxCJ4mgD4JYP4LlWrV8cgHLPzAdz5HePfW-0", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-armv7-debug.zip", + .hash = "N-V-__8AAClDaA-MHVqMD1xRgIqdgFKweiw2ywkgNZiu9Qkn", .lazy = true, }, .wgpu_android_armv7_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-armv7-release.zip", - .hash = "N-V-__8AAHKm5wI40Gj43wFTj6iZnGz9id_y087a-jnfQBRi", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-armv7-release.zip", + .hash = "N-V-__8AAOmN9ALJB8B1icJzGxvqBOHJNKFhl2WwM6ky917M", .lazy = true, }, .wgpu_android_x86_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-i686-debug.zip", - .hash = "N-V-__8AAMD9TBCN2rrJG9dqTyQh0Wv9MWisv3bSIdoMH_VG", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-i686-debug.zip", + .hash = "N-V-__8AAPccow-KeS6dXalYiOfK81kEY7jAq2AVdoMI2nC3", .lazy = true, }, .wgpu_android_x86_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-i686-release.zip", - .hash = "N-V-__8AAFwDIQNZ003uYMHrFbiexqSqI3sVgpXB2W4DLoqq", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-i686-release.zip", + .hash = "N-V-__8AAM0GMAMMU13eBN4312YYvpIJTNuXqNogMJmOPeoZ", .lazy = true, }, .wgpu_android_x86_64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-x86_64-debug.zip", - .hash = "N-V-__8AAAAjNBQaSprsYmeSlIDJWQg-jZHiUxxIMHylLp7E", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-x86_64-debug.zip", + .hash = "N-V-__8AAE33nBNB72cm_xYb6e_GtlGlbLTtScwaE2E_N9Wz", .lazy = true, }, .wgpu_android_x86_64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-android-x86_64-release.zip", - .hash = "N-V-__8AALxtxANPhha93qENJNdLw9ZAaHUXp2_X8QBskpOM", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-android-x86_64-release.zip", + .hash = "N-V-__8AADV_2wPw7GHtKerUKEqePfOeoGXWkkf69e5zPrnY", .lazy = true, }, .wgpu_ios_aarch64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-ios-aarch64-debug.zip", - .hash = "N-V-__8AAJj1lQlJYBWH3qMo3USVJcGKJ1ithSzQ-u04QUxa", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-ios-aarch64-debug.zip", + .hash = "N-V-__8AAGUI9wkBlccBNSsG48_rzB9fsMXwEf8YEPp7QgEs", .lazy = true, }, .wgpu_ios_aarch64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-ios-aarch64-release.zip", - .hash = "N-V-__8AALh8YgKjs1OKvnTlaRqB_euceGNN_TfX1HLMrnNi", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-ios-aarch64-release.zip", + .hash = "N-V-__8AALXGeALDqM9vK52Fl1Gdx_6FqOSJe3E3fr9Wxoai", .lazy = true, }, .wgpu_ios_aarch64_simulator_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-ios-aarch64-simulator-debug.zip", - .hash = "N-V-__8AAABClgk_Seuqe9XuxYUDDZe9T9aOYuhd4JhXTeg9", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-ios-aarch64-simulator-debug.zip", + .hash = "N-V-__8AAN2V9QniUxPATeZOAyxQ7i7AlZT2vuckfvG59smj", .lazy = true, }, .wgpu_ios_aarch64_simulator_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-ios-aarch64-simulator-release.zip", - .hash = "N-V-__8AAAgFYgLavBRZjHgkULhWRweVNw-VeLMxcxRHZYF1", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-ios-aarch64-simulator-release.zip", + .hash = "N-V-__8AAKUqeALw8NE3fLChLjnbhA4Eyh3MTIndQjHUXqQ_", .lazy = true, }, .wgpu_ios_x86_64_simulator_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-ios-x86_64-simulator-debug.zip", - .hash = "N-V-__8AAKCSXgkyBFHn1Uwy1Sop2KeA6XwmrVs2_C8cru8M", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-ios-x86_64-simulator-debug.zip", + .hash = "N-V-__8AAL1vqQn1EUdyeRKU2bLMigXtGPUY8-ptcaLd__Lc", .lazy = true, }, .wgpu_ios_x86_64_simulator_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-ios-x86_64-simulator-release.zip", - .hash = "N-V-__8AAPBFWQJxhwRTeBxlztWVNalvobmyX_zEoF24X_S6", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-ios-x86_64-simulator-release.zip", + .hash = "N-V-__8AAK24awL0PMrxiMcIeJMCXHQQO3e5Ob3iHiASC5oY", .lazy = true, }, .wgpu_linux_aarch64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-linux-aarch64-debug.zip", - .hash = "N-V-__8AALSbGhS93ZKwkkKk-yN3BzFl6iBPh9etfftVkhSk", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-linux-aarch64-debug.zip", + .hash = "N-V-__8AACtu0BMX4pgKXB-7p-u92hlo_KBVXVhe5jDiYUVH", .lazy = true, }, .wgpu_linux_aarch64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-linux-aarch64-release.zip", - .hash = "N-V-__8AAC42tgMsCqChk-HZ0n7dyD1HT29f6QM0UTCdj_iF", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-linux-aarch64-release.zip", + .hash = "N-V-__8AAD8s1gO92sAkRd4lIm3Sow3jGcX0f6ty2I298rxL", .lazy = true, }, .wgpu_linux_x86_64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-linux-x86_64-debug.zip", - .hash = "N-V-__8AAHS_-BNtAmT4hK9geZG361RETmD2lG0fk2gyDYh-", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-linux-x86_64-debug.zip", + .hash = "N-V-__8AAI0zpRP5NvcMEE7UL_eWX3DbOhCbLnzOMGg44neR", .lazy = true, }, .wgpu_linux_x86_64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-linux-x86_64-release.zip", - .hash = "N-V-__8AALK1sQPqMGESXUOHBpzwDj1GMf_nYBdfbjewJ9kH", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-linux-x86_64-release.zip", + .hash = "N-V-__8AAO3k0AME91yU7p-wkAjsf9Fudl9z8rFKgyS-aTY9", .lazy = true, }, .wgpu_macos_aarch64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-macos-aarch64-debug.zip", - .hash = "N-V-__8AACj6lQmZEGeyjdn2CCD0as1hGMvrAUBsoTuBu_cR", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-macos-aarch64-debug.zip", + .hash = "N-V-__8AAB2H_Ak1UD-N-htQMSB2q19yVCDulGJU5NDFjCF4", .lazy = true, }, .wgpu_macos_aarch64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-macos-aarch64-release.zip", - .hash = "N-V-__8AAGDGYgIAQ6tOKxxonhabDmuFj9Y35AKvPwynW_UO", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-macos-aarch64-release.zip", + .hash = "N-V-__8AAP25fAK9uyvxPl28uoHYZhzGkEqs3Z34Dz4IN5Vk", .lazy = true, }, .wgpu_macos_x86_64_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-macos-x86_64-debug.zip", - .hash = "N-V-__8AAOCufAlp1bMuFqQCd152bYQLNu-tjLdu9edJ8b4e", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-macos-x86_64-debug.zip", + .hash = "N-V-__8AAD3zzgk2_Za_1BnKJTDKjIWKAybnN_AREgeWnU7c", .lazy = true, }, .wgpu_macos_x86_64_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-macos-x86_64-release.zip", - .hash = "N-V-__8AAFi6YgLHU9dEEx9n190MvnIZaCq5SVMg8BX7zD87", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-macos-x86_64-release.zip", + .hash = "N-V-__8AAF0KeQIPjq2ZGVZ2r_mwwK6lDxHhxsko_HfbMLqO", .lazy = true, }, .wgpu_windows_aarch64_msvc_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-aarch64-msvc-debug.zip", - .hash = "N-V-__8AACUsDR0QuXpFRCjd-TcdKredsnN5Uiy6thaqghfy", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-aarch64-msvc-debug.zip", + .hash = "N-V-__8AACR_jRy9PoTB6DtWxJsTzDpcliqoXnjjyOmtK3_x", .lazy = true, }, .wgpu_windows_aarch64_msvc_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-aarch64-msvc-release.zip", - .hash = "N-V-__8AAEmpwwOechqvtlmAlMzCIbnIzIgSYcfEUWhSZ7Cj", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-aarch64-msvc-release.zip", + .hash = "N-V-__8AAPL82gO12EjKN3FMSnNzuq8xKdJhzFNdWKWwoWxP", .lazy = true, }, .wgpu_windows_x86_msvc_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-i686-msvc-debug.zip", - .hash = "N-V-__8AAP8AIx3OgW8N8DkBj5JMcJUkcy7iHLuOH--fY3IX", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-i686-msvc-debug.zip", + .hash = "N-V-__8AAIYYnhxrJqvgsFXiRoZpJmLC-sUyHPTkf_UxtoZd", .lazy = true, }, .wgpu_windows_x86_msvc_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-i686-msvc-release.zip", - .hash = "N-V-__8AAMn2lQPoxD9cdgm97Fvxqes4Jlvwct-GWDgsws5k", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-i686-msvc-release.zip", + .hash = "N-V-__8AADhArAPYIeixMT3RgXwugtnm6pLjyz9GGXEek5SF", .lazy = true, }, .wgpu_windows_x86_64_msvc_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-x86_64-msvc-debug.zip", - .hash = "N-V-__8AADEvMB0uTuAXXabR4Fw-2LjtJfoSP8vux2m_eDok", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-x86_64-msvc-debug.zip", + .hash = "N-V-__8AAJp8mRy3JMOU_ZRRs2WSNEeuuoSd2Gl6cdzzP9bm", .lazy = true, }, .wgpu_windows_x86_64_msvc_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-x86_64-msvc-release.zip", - .hash = "N-V-__8AAG8mAQR0Vg9K8e0Ln46g_UJq1HqtXwif_Uvt1_ZE", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-x86_64-msvc-release.zip", + .hash = "N-V-__8AAP4LGAR-T-GjxNppMymyVapVHz-QnVYrZWHEXrgT", .lazy = true, }, .wgpu_windows_x86_64_gnu_debug = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-x86_64-gnu-debug.zip", - .hash = "N-V-__8AAFICSxIMF7kdKvI3pTwiLWmIxjSopWIadDt9yUpp", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-x86_64-gnu-debug.zip", + .hash = "N-V-__8AAC6shBE4wBzzVdpWviXEn7AM65QV6HwbnoeaArsO", .lazy = true, }, .wgpu_windows_x86_64_gnu_release = .{ - .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v25.0.2.1/wgpu-windows-x86_64-gnu-release.zip", - .hash = "N-V-__8AAMZ8DwPtTjIxd_0zIGEoJwriDQY-Ykx8ldVc_7N0", + .url = "https://github.com/gfx-rs/wgpu-native/releases/download/v29.0.0.0/wgpu-windows-x86_64-gnu-release.zip", + .hash = "N-V-__8AAPBAGQNbEfPkUyAa2C7P_x-f2gJZo-2MF9t16C7j", .lazy = true, }, }, @@ -217,6 +223,7 @@ .paths = .{ "build.zig", "build.zig.zon", + "build", "src", // For example... //"LICENSE", diff --git a/build/WgpuNativeArtifact.zig b/build/WgpuNativeArtifact.zig index fd43c61..d0ac1da 100644 --- a/build/WgpuNativeArtifact.zig +++ b/build/WgpuNativeArtifact.zig @@ -1,5 +1,6 @@ const std = @import("std"); const Platform = @import("platform/root.zig"); +const addDirectoryFiles = @import("file_tree.zig").addDirectoryFiles; pub const Result = struct { header: std.Build.LazyPath, @@ -76,7 +77,12 @@ fn buildSource( if (source_dependency == null or headers_dependency == null) return null; const staged_source = b.addWriteFiles(); - _ = staged_source.addCopyDirectory(source_dependency.?.path(""), "", .{}); + addDirectoryFiles( + b, + staged_source, + source_dependency.?.path(""), + "", + ); _ = staged_source.addCopyDirectory( headers_dependency.?.path(""), "ffi/webgpu-headers", @@ -86,6 +92,12 @@ fn buildSource( headers_dependency.?.path("webgpu.h"), "ffi/webgpu.h", ); + if (!Platform.patchSource( + b, + staged_source, + source_dependency.?.path(""), + platform, + )) return null; const source_root = staged_source.getDirectory(); const cargo = b.addSystemCommand(&.{ @@ -96,6 +108,10 @@ fn buildSource( }); cargo.setName(b.fmt("build wgpu-native for {s}", .{platform.rust_target})); cargo.addFileArg(source_root.path(b, "Cargo.toml")); + if (Platform.hasSourceCargoConfig(platform)) { + cargo.addArg("--config"); + cargo.addFileArg(source_root.path(b, ".cargo/config.toml")); + } cargo.addArgs(&.{ "--target", platform.rust_target, "--target-dir" }); const cargo_target_dir = cargo.addOutputDirectoryArg("wgpu-native-target"); if (optimize != .Debug) cargo.addArg("--release"); diff --git a/build/file_tree.zig b/build/file_tree.zig new file mode 100644 index 0000000..3695f7c --- /dev/null +++ b/build/file_tree.zig @@ -0,0 +1,32 @@ +const std = @import("std"); + +pub fn addDirectoryFiles( + b: *std.Build, + staged_source: *std.Build.Step.WriteFile, + source: std.Build.LazyPath, + destination: []const u8, +) void { + const resolved = source.getPath3(b, null); + var directory = resolved.root_dir.handle.openDir( + b.graph.io, + resolved.subPathOrDot(), + .{ .iterate = true }, + ) catch |err| std.debug.panic( + "unable to open {s}: {s}", + .{ source.getPath(b), @errorName(err) }, + ); + defer directory.close(b.graph.io); + + var iterator = directory.walk(b.allocator) catch @panic("out of memory"); + defer iterator.deinit(); + while (iterator.next(b.graph.io) catch |err| std.debug.panic( + "unable to walk {s}: {s}", + .{ source.getPath(b), @errorName(err) }, + )) |entry| { + if (entry.kind != .file) continue; + _ = staged_source.addCopyFile( + source.path(b, entry.path), + b.pathJoin(&.{ destination, entry.path }), + ); + } +} diff --git a/build/patches/wgpu-hal-29.0.1/Cargo.toml b/build/patches/wgpu-hal-29.0.1/Cargo.toml new file mode 100644 index 0000000..62f4e6d --- /dev/null +++ b/build/patches/wgpu-hal-29.0.1/Cargo.toml @@ -0,0 +1,512 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +rust-version = "1.87" +name = "wgpu-hal" +version = "29.0.1" +authors = ["gfx-rs developers"] +build = "build.rs" +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "Hardware abstraction layer for wgpu, the cross-platform, safe, pure-rust graphics API" +homepage = "https://wgpu.rs/" +readme = "README.md" +keywords = ["graphics"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/gfx-rs/wgpu" + +[package.metadata.docs.rs] +features = [ + "metal", + "vulkan", + "gles", + "renderdoc", +] +rustdoc-args = [ + "--cfg", + "docsrs", +] +targets = [ + "x86_64-unknown-linux-gnu", + "x86_64-apple-darwin", + "x86_64-pc-windows-msvc", + "wasm32-unknown-unknown", +] + +[package.metadata.cargo-machete] +ignored = ["cfg_aliases"] + +[features] +device_lost_panic = [] +dx12 = [ + "naga/hlsl-out", + "dep:arrayvec", + "dep:bit-set", + "dep:bytemuck", + "dep:hashbrown", + "dep:libloading", + "dep:ordered-float", + "dep:once_cell", + "dep:parking_lot", + "dep:profiling", + "dep:range-alloc", + "dep:windows-core", + "dep:gpu-allocator", + "gpu-allocator/d3d12", + "windows/Win32_Devices_DeviceAndDriverInstallation", + "windows/Win32_Graphics_Direct3D_Fxc", + "windows/Win32_Graphics_Direct3D_Dxc", + "windows/Win32_Graphics_Direct3D", + "windows/Win32_Graphics_Direct3D12", + "windows/Win32_Graphics_DirectComposition", + "windows/Win32_Graphics_Dxgi_Common", + "windows/Win32_Security", + "windows/Win32_System_Diagnostics_Debug", + "windows/Win32_System_Kernel", + "windows/Win32_System_Performance", + "windows/Win32_System_Threading", + "windows/Win32_UI_WindowsAndMessaging", +] +fragile-send-sync-non-atomic-wasm = ["wgpu-types/fragile-send-sync-non-atomic-wasm"] +gles = [ + "naga/glsl-out", + "dep:arrayvec", + "dep:bytemuck", + "dep:glow", + "dep:glutin_wgl_sys", + "dep:hashbrown", + "dep:js-sys", + "dep:khronos-egl", + "dep:wayland-sys", + "dep:libloading", + "dep:ndk-sys", + "dep:objc2", + "dep:parking_lot", + "dep:profiling", + "dep:wasm-bindgen", + "dep:web-sys", + "wgpu-types/web", + "windows/Win32_Graphics_OpenGL", + "windows/Win32_Graphics_Gdi", + "windows/Win32_System_LibraryLoader", + "windows/Win32_UI_WindowsAndMessaging", +] +internal_error_panic = [] +metal = [ + "naga/msl-out", + "dep:arrayvec", + "dep:block2", + "dep:bytemuck", + "dep:hashbrown", + "dep:libc", + "dep:objc2", + "dep:objc2-core-foundation", + "dep:objc2-foundation", + "dep:objc2-metal", + "dep:objc2-quartz-core", + "dep:parking_lot", + "dep:profiling", + "dep:smallvec", + "dep:raw-window-metal", +] +portable-atomic = [ + "dep:portable-atomic", + "dep:portable-atomic-util", +] +renderdoc = [ + "dep:libloading", + "dep:renderdoc-sys", +] +static-dxc = ["dep:mach-dxcompiler-rs"] +validation_canary = ["dep:parking_lot"] +vulkan = [ + "naga/spv-out", + "dep:android_system_properties", + "dep:arrayvec", + "dep:ash", + "dep:bytemuck", + "dep:gpu-descriptor", + "dep:hashbrown", + "dep:libc", + "dep:libloading", + "dep:ordered-float", + "dep:parking_lot", + "dep:profiling", + "dep:raw-window-metal", + "dep:smallvec", + "dep:windows", + "gpu-allocator/vulkan", + "windows/Win32", +] + +[lib] +name = "wgpu_hal" +path = "src/lib.rs" + +[[example]] +name = "halmark" +path = "examples/halmark/main.rs" + +[[example]] +name = "raw-gles" +path = "examples/raw-gles.rs" +required-features = ["gles"] + +[[example]] +name = "ray-traced-triangle" +path = "examples/ray-traced-triangle/main.rs" + +[dependencies.arrayvec] +version = "0.7.1" +optional = true +default-features = false + +[dependencies.bitflags] +version = "2.9" + +[dependencies.bytemuck] +version = "1.22" +features = [ + "extern_crate_alloc", + "min_const_generics", + "derive", +] +optional = true + +[dependencies.cfg-if] +version = "1" + +[dependencies.glow] +version = "0.17" +optional = true + +[dependencies.hashbrown] +version = "0.16" +features = [ + "default-hasher", + "inline-more", +] +optional = true +default-features = false + +[dependencies.log] +version = "0.4.29" + +[dependencies.naga] +version = "29.0.1" + +[dependencies.ordered-float] +version = ">=3, <6.0" +optional = true +default-features = false + +[dependencies.parking_lot] +version = "0.12.3" +optional = true + +[dependencies.profiling] +version = "1.0.1" +optional = true +default-features = false + +[dependencies.raw-window-handle] +version = "0.6.2" +default-features = false + +[dependencies.thiserror] +version = "2.0.12" +default-features = false + +[dependencies.wgpu-naga-bridge] +version = "29.0.1" + +[dependencies.wgpu-types] +version = "29.0.1" +default-features = false + +[dev-dependencies.env_logger] +version = "0.11" +default-features = false + +[dev-dependencies.glam] +version = "0.32.0" + +[dev-dependencies.naga] +version = "29.0.1" +features = [ + "wgsl-in", + "termcolor", +] + +[dev-dependencies.winit] +version = "0.30.8" +features = ["android-native-activity"] + +[build-dependencies.cfg_aliases] +version = "0.2.1" + +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies.js-sys] +version = "0.3.85" +optional = true +default-features = true + +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies.wasm-bindgen] +version = "0.2.108" +optional = true +default-features = false + +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies.web-sys] +version = "0.3.85" +features = [ + "default", + "Window", + "HtmlCanvasElement", + "WebGl2RenderingContext", + "OffscreenCanvas", +] +optional = true +default-features = false + +[target.'cfg(all(windows, not(target_arch = "aarch64"), target_env = "msvc"))'.dependencies.mach-dxcompiler-rs] +version = "0.1.4" +optional = true +default-features = false + +[target.'cfg(any(not(target_has_atomic = "64"), not(target_has_atomic = "ptr")))'.dependencies.portable-atomic] +version = "1.10" +optional = true + +[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos", target_env = "ohos")))'.dev-dependencies.glutin] +version = "0.32" +features = [ + "egl", + "wgl", + "wayland", + "x11", +] +default-features = false + +[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos", target_env = "ohos")))'.dev-dependencies.glutin-winit] +version = "0.5" +features = [ + "egl", + "wgl", + "wayland", + "x11", +] +default-features = false + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.ash] +version = "0.38" +optional = true + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.gpu-allocator] +version = "0.28" +features = ["hashbrown"] +optional = true +default-features = false + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.gpu-descriptor] +version = "0.3.2" +optional = true + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.khronos-egl] +version = "6" +features = ["dynamic"] +optional = true + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.libloading] +version = "0.8" +optional = true + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.renderdoc-sys] +version = "1" +optional = true + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.smallvec] +version = "1.14" +features = ["union"] +optional = true + +[target.'cfg(not(target_has_atomic = "ptr"))'.dependencies.portable-atomic-util] +version = "0.2.4" +features = ["alloc"] +optional = true + +[target.'cfg(target_os = "android")'.dependencies.android_system_properties] +version = "0.1.1" +optional = true + +[target.'cfg(target_os = "android")'.dependencies.ndk-sys] +version = "0.6" +optional = true + +[target.'cfg(target_os = "emscripten")'.dependencies.khronos-egl] +version = "6" +features = [ + "static", + "no-pkg-config", +] +optional = true + +[target.'cfg(target_os = "emscripten")'.dependencies.libloading] +version = "0.8" +optional = true + +[target.'cfg(target_vendor = "apple")'.dependencies.block2] +version = "0.6.2" +optional = true + +[target.'cfg(target_vendor = "apple")'.dependencies.bytemuck] +version = "1.22" +features = [ + "extern_crate_alloc", + "min_const_generics", +] +optional = true + +[target.'cfg(target_vendor = "apple")'.dependencies.objc2] +version = "0.6.3" +optional = true + +[target.'cfg(target_vendor = "apple")'.dependencies.objc2-core-foundation] +version = "0.3.2" +features = [ + "std", + "CFCGTypes", +] +optional = true +default-features = false + +[target.'cfg(target_vendor = "apple")'.dependencies.objc2-foundation] +version = "0.3.2" +features = [ + "std", + "NSError", + "NSProcessInfo", + "NSRange", + "NSString", +] +optional = true +default-features = false + +[target.'cfg(target_vendor = "apple")'.dependencies.objc2-metal] +version = "0.3.2" +features = [ + "std", + "block2", + "MTLAllocation", + "MTLBlitCommandEncoder", + "MTLBlitPass", + "MTLBuffer", + "MTLCaptureManager", + "MTLCaptureScope", + "MTLCommandBuffer", + "MTLCommandEncoder", + "MTLCommandQueue", + "MTLComputeCommandEncoder", + "MTLComputePass", + "MTLComputePipeline", + "MTLCounters", + "MTLDepthStencil", + "MTLDevice", + "MTLDrawable", + "MTLEvent", + "MTLLibrary", + "MTLPipeline", + "MTLPixelFormat", + "MTLRenderCommandEncoder", + "MTLRenderPass", + "MTLRenderPipeline", + "MTLResource", + "MTLSampler", + "MTLStageInputOutputDescriptor", + "MTLTexture", + "MTLTypes", + "MTLVertexDescriptor", + "MTLAccelerationStructure", + "MTLAccelerationStructureTypes", + "MTLAccelerationStructureCommandEncoder", + "MTLResidencySet", +] +optional = true +default-features = false + +[target.'cfg(target_vendor = "apple")'.dependencies.objc2-quartz-core] +version = "0.3.2" +features = [ + "std", + "objc2-core-foundation", + "CALayer", + "CAMetalLayer", + "objc2-metal", +] +optional = true +default-features = false + +[target.'cfg(target_vendor = "apple")'.dependencies.raw-window-metal] +version = "1.0" +optional = true + +[target."cfg(unix)".dependencies.libc] +version = "0.2.172" +optional = true +default-features = false + +[target."cfg(unix)".dependencies.wayland-sys] +version = "0.31.3" +features = [ + "client", + "dlopen", + "egl", +] +optional = true + +[target."cfg(windows)".dependencies.bit-set] +version = "0.9" +optional = true +default-features = false + +[target."cfg(windows)".dependencies.glutin_wgl_sys] +version = "0.6" +optional = true + +[target."cfg(windows)".dependencies.once_cell] +version = "1.21" +optional = true +default-features = false + +[target."cfg(windows)".dependencies.range-alloc] +version = "0.1" +optional = true + +[target."cfg(windows)".dependencies.windows] +version = "0.62" +optional = true +default-features = false + +[target."cfg(windows)".dependencies.windows-core] +version = "0.62" +optional = true +default-features = false + +[lints.rust.unexpected_cfgs] +level = "warn" +priority = 0 +check-cfg = [ + 'cfg(feature, values("cargo-clippy"))', + "cfg(web_sys_unstable_apis)", +] diff --git a/build/platform/ohos.zig b/build/platform/ohos.zig index 5b87651..099b98f 100644 --- a/build/platform/ohos.zig +++ b/build/platform/ohos.zig @@ -1,6 +1,7 @@ const std = @import("std"); const common = @import("common.zig"); const types = @import("types.zig"); +const addDirectoryFiles = @import("../file_tree.zig").addDirectoryFiles; pub fn build(_: *std.Build, target: std.Build.ResolvedTarget) types.Config { const result = target.result; @@ -61,6 +62,68 @@ pub fn configureSource( ); } +pub fn patchSource( + b: *std.Build, + staged_source: *std.Build.Step.WriteFile, + source_root: std.Build.LazyPath, + config: types.Config, +) bool { + if (config.target.result.cpu.arch != .arm) return true; + + const wgpu_source = b.lazyDependency("wgpu_source_29_0_1", .{}) orelse + return false; + addDirectoryFiles( + b, + staged_source, + wgpu_source.path("wgpu-hal"), + "vendor/wgpu-hal", + ); + _ = staged_source.addCopyFile( + b.path("build/patches/wgpu-hal-29.0.1/Cargo.toml"), + "vendor/wgpu-hal/Cargo.toml", + ); + + const adapter = readFile( + b, + wgpu_source.path("wgpu-hal/src/vulkan/adapter.rs"), + 1024 * 1024, + ); + const old_timespec = + \\ let mut timespec = libc::timespec { + \\ tv_sec: 0, + \\ tv_nsec: 0, + \\ }; + ; + const new_timespec = + \\ // Backported from wgpu-hal 30.0.0 for 32-bit OHOS, where + \\ // libc::timespec contains a private padding field. + \\ let mut timespec = libc::timespec::default(); + ; + _ = staged_source.add( + "vendor/wgpu-hal/src/vulkan/adapter.rs", + replaceExactlyOnce(b, adapter, old_timespec, new_timespec), + ); + + const cargo_lock = readFile(b, source_root.path(b, "Cargo.lock"), 1024 * 1024); + const registry_entry = + \\source = "registry+https://github.com/rust-lang/crates.io-index" + \\checksum = "89a47aef47636562f3937285af4c44b4b5b404b46577471411cc5313a921da7e" + ; + _ = staged_source.add( + "Cargo.lock", + replaceExactlyOnce(b, cargo_lock, registry_entry, ""), + ); + _ = staged_source.add(".cargo/config.toml", + \\# wgpu-hal 29.0.1 constructs libc::timespec with a struct literal. + \\# Its private padding field makes that fail for 32-bit OHOS. Keep the + \\# same crate version and apply the initialization used by wgpu-hal 30. + \\[patch.crates-io] + \\wgpu-hal = { path = "vendor/wgpu-hal" } + \\ + ); + return true; +} + pub fn configureModule( b: *std.Build, config: types.Config, @@ -104,3 +167,40 @@ fn nativeRoot(b: *std.Build, config: types.Config) []const u8 { else b.pathJoin(&.{ sdk_root, "native" }); } + +fn readFile( + b: *std.Build, + path: std.Build.LazyPath, + max_bytes: usize, +) []const u8 { + const resolved = path.getPath3(b, null); + return resolved.root_dir.handle.readFileAlloc( + b.graph.io, + resolved.sub_path, + b.allocator, + .limited(max_bytes), + ) catch |err| std.debug.panic( + "unable to read {s}: {s}", + .{ path.getPath(b), @errorName(err) }, + ); +} + +fn replaceExactlyOnce( + b: *std.Build, + input: []const u8, + needle: []const u8, + replacement: []const u8, +) []const u8 { + const first = std.mem.indexOf(u8, input, needle) orelse + std.debug.panic("wgpu source patch no longer applies", .{}); + if (std.mem.indexOfPos(u8, input, first + needle.len, needle) != null) { + std.debug.panic("wgpu source patch matched more than once", .{}); + } + return std.mem.replaceOwned( + u8, + b.allocator, + input, + needle, + replacement, + ) catch @panic("out of memory"); +} diff --git a/build/platform/root.zig b/build/platform/root.zig index c6f2e37..0014d68 100644 --- a/build/platform/root.zig +++ b/build/platform/root.zig @@ -39,6 +39,22 @@ pub fn configureSource( } } +pub fn patchSource( + b: *std.Build, + staged_source: *std.Build.Step.WriteFile, + source_root: std.Build.LazyPath, + config: Config, +) bool { + return switch (config.kind) { + .ohos => ohos.patchSource(b, staged_source, source_root, config), + else => true, + }; +} + +pub fn hasSourceCargoConfig(config: Config) bool { + return config.kind == .ohos and config.target.result.cpu.arch == .arm; +} + pub fn configureModule( b: *std.Build, config: Config, diff --git a/src/adapter.zig b/src/adapter.zig index 27dcdfa..3ff62d3 100644 --- a/src/adapter.zig +++ b/src/adapter.zig @@ -55,6 +55,7 @@ pub const BackendType = enum(u32) { }; pub const FeatureLevel = enum(u32) { + undefined = 0x00000000, compatibility = 0x00000001, // "Compatibility" profile which can be supported on OpenGL ES 3.1. core = 0x00000002, // "Core" profile which can be supported on Vulkan/Metal/D3D12. }; @@ -84,12 +85,18 @@ pub const RequestAdapterOptions = extern struct { compatible_surface: ?*Surface = null, }; +pub const RequestAdapterWebXROptions = extern struct { + chain: ChainedStruct = .{ + .s_type = .request_adapter_webxr_options, + }, + xr_compatible: WGPUBool = @intFromBool(false), +}; + pub const RequestAdapterStatus = enum(u32) { success = 0x00000001, - instance_dropped = 0x00000002, + callback_cancelled = 0x00000002, unavailable = 0x00000003, @"error" = 0x00000004, - unknown = 0x00000005, }; pub const RequestAdapterCallbackInfo = extern struct { @@ -134,6 +141,8 @@ pub const AdapterInfo = extern struct { adapter_type: AdapterType, vendor_id: u32, device_id: u32, + subgroup_min_size: u32, + subgroup_max_size: u32, pub inline fn freeMembers(self: AdapterInfo) void { wgpuAdapterInfoFreeMembers(self); @@ -228,16 +237,21 @@ pub const Adapter = opaque { test "can request device" { const testing = @import("std").testing; - const instance = Instance.create(null); - const adapter_response = try instance.?.requestAdapterSync(std.testing.io, null, 200_000_000); + const instance = Instance.create(null).?; + defer instance.release(); + const adapter_response = try instance.requestAdapterSync(std.testing.io, null, 200_000_000); const adapter: ?*Adapter = switch (adapter_response.status) { .success => adapter_response.adapter, else => null, }; - const device_response = try adapter.?.requestDeviceSync(std.testing.io, instance.?, null, 200_000_000); + if (adapter == null) return error.SkipZigTest; + defer adapter.?.release(); + const device_response = try adapter.?.requestDeviceSync(std.testing.io, instance, null, 200_000_000); const device: ?*Device = switch (device_response.status) { .success => device_response.device, else => null, }; + if (device == null) return error.SkipZigTest; + defer device.?.release(); try testing.expect(device != null); } diff --git a/src/async.zig b/src/async.zig index 1704868..7afa79e 100644 --- a/src/async.zig +++ b/src/async.zig @@ -40,14 +40,8 @@ pub const WaitStatus = enum(u32) { // No Futures completed within the timeout. timed_out = 0x00000002, - // A Timed-Wait was performed when InstanceCapabilities.timed_wait_any_enable is false. - unsupported_timeout = 0x00000003, - - // The number of futures waited on in a Timed-Wait is greater than the supported InstanceCapabilities.timed_wait_any_max_count. - unsupported_count = 0x00000004, - - // An invalid wait was performed with Mixed-Sources. - unsupported_mixed_sources = 0x00000005, + // The call was invalid for some reason. + @"error" = 0x00000003, }; // diff --git a/src/bind_group.zig b/src/bind_group.zig index 9c0280a..e1b6c83 100644 --- a/src/bind_group.zig +++ b/src/bind_group.zig @@ -25,6 +25,32 @@ const _misc = @import("misc.zig"); const WGPU_WHOLE_SIZE = _misc.WGPU_WHOLE_SIZE; const StringView = _misc.StringView; +pub const ExternalTexture = opaque { + pub inline fn addRef(self: *ExternalTexture) void { + wgpuExternalTextureAddRef(self); + } + + pub inline fn release(self: *ExternalTexture) void { + wgpuExternalTextureRelease(self); + } +}; + +extern fn wgpuExternalTextureAddRef(external_texture: *ExternalTexture) void; +extern fn wgpuExternalTextureRelease(external_texture: *ExternalTexture) void; + +pub const ExternalTextureBindingLayout = extern struct { + chain: ChainedStruct = .{ + .s_type = .external_texture_binding_layout, + }, +}; + +pub const ExternalTextureBindingEntry = extern struct { + chain: ChainedStruct = .{ + .s_type = .external_texture_binding_entry, + }, + external_texture: ?*ExternalTexture = null, +}; + pub const BindGroupLayoutEntryExtras = extern struct { chain: ChainedStruct = ChainedStruct{ .s_type = SType.bind_group_layout_entry_extras, @@ -38,6 +64,7 @@ pub const BindGroupLayoutEntry = extern struct { next_in_chain: ?*const ChainedStruct = null, binding: u32, visibility: ShaderStage, + binding_array_size: u32 = 0, buffer: BufferBindingLayout = BufferBindingLayout{ .type = BufferBindingType.binding_not_used, }, @@ -78,8 +105,8 @@ extern fn wgpuBindGroupLayoutAddRef(bind_group_layout: *BindGroupLayout) void; extern fn wgpuBindGroupLayoutRelease(bind_group_layout: *BindGroupLayout) void; pub const BindGroupLayout = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L17 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *BindGroupLayout, label: []const u8) void { // wgpuBindGroupLayoutSetLabel(self, StringView.fromSlice(label)); // } @@ -139,8 +166,8 @@ extern fn wgpuBindGroupAddRef(bind_group: *BindGroup) void; extern fn wgpuBindGroupRelease(bind_group: *BindGroup) void; pub const BindGroup = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L9 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *BindGroup, label: []const u8) void { // wgpuBindGroupSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/buffer.zig b/src/buffer.zig index fddaa97..edd0d67 100644 --- a/src/buffer.zig +++ b/src/buffer.zig @@ -57,10 +57,9 @@ pub const MapModes = struct { pub const MapAsyncStatus = enum(u32) { success = 0x00000001, - instance_dropped = 0x00000002, + callback_cancelled = 0x00000002, @"error" = 0x00000003, aborted = 0x00000004, - unknown = 0x00000005, }; pub const BufferMapCallbackInfo = extern struct { @@ -134,8 +133,8 @@ pub const Buffer = opaque { return wgpuBufferGetConstMappedRange(self, offset, size); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L25 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn getMapState(self: *Buffer) BufferMapState { // return wgpuBufferGetMapState(self); // } @@ -168,8 +167,8 @@ pub const Buffer = opaque { return wgpuBufferMapAsync(self, mode, offset, size, callback_info); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L30 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *Buffer, label: []const u8) void { // wgpuBufferSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/chained_struct.zig b/src/chained_struct.zig index 2910b1d..47b909c 100644 --- a/src/chained_struct.zig +++ b/src/chained_struct.zig @@ -8,6 +8,13 @@ pub const SType = enum(u32) { surface_source_wayland_surface = 0x00000007, surface_source_android_native_window = 0x00000008, surface_source_xcb_window = 0x00000009, + surface_color_management = 0x0000000A, + request_adapter_webxr_options = 0x0000000B, + texture_component_swizzle_descriptor = 0x0000000C, + external_texture_binding_layout = 0x0000000D, + external_texture_binding_entry = 0x0000000E, + compatibility_mode_limits = 0x0000000F, + texture_binding_view_dimension = 0x00000010, // wgpu-native extras (wgpu.h) device_extras = 0x00030001, @@ -19,10 +26,12 @@ pub const SType = enum(u32) { bind_group_layout_entry_extras = 0x00030008, query_set_descriptor_extras = 0x00030009, surface_configuration_extras = 0x0003000A, + surface_source_swap_chain_panel = 0x0003000B, + primitive_state_extras = 0x0003000C, }; pub const ChainedStruct = extern struct { - next: ?*const ChainedStruct = null, + next: ?*ChainedStruct = null, s_type: SType, }; diff --git a/src/command_encoder.zig b/src/command_encoder.zig index dfb37cf..f8ab0c2 100644 --- a/src/command_encoder.zig +++ b/src/command_encoder.zig @@ -1,3 +1,5 @@ +const std = @import("std"); + const _chained_struct = @import("chained_struct.zig"); const ChainedStruct = _chained_struct.ChainedStruct; const SType = _chained_struct.SType; @@ -25,23 +27,20 @@ const RenderPipeline = _pipeline.RenderPipeline; const RenderBundle = @import("render_bundle.zig").RenderBundle; -const ShaderStage = @import("shader.zig").ShaderStage; - pub const WGPU_DEPTH_SLICE_UNDEFINED = U32_MAX; pub const WGPU_QUERY_SET_INDEX_UNDEFINED = U32_MAX; -pub const TimestampWrites = extern struct { +pub const PassTimestampWrites = extern struct { + next_in_chain: ?*const ChainedStruct = null, query_set: *QuerySet, beginning_of_pass_write_index: u32 = WGPU_QUERY_SET_INDEX_UNDEFINED, end_of_pass_write_index: u32 = WGPU_QUERY_SET_INDEX_UNDEFINED, }; -pub const ComputePassTimestampWrites = TimestampWrites; - pub const ComputePassDescriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: StringView = StringView{}, - timestamp_writes: ?*const ComputePassTimestampWrites = null, + timestamp_writes: ?*const PassTimestampWrites = null, }; pub const CommandEncoderDescriptor = extern struct { @@ -63,7 +62,6 @@ const ComputePassEncoderProcs = struct { pub const Release = *const fn (*ComputePassEncoder) callconv(.c) void; // wgpu-native procs? - // pub const SetPushConstants = *const fn(*ComputePassEncoder, u32, u32, *const anyopaque) callconv(.c) void; // pub const BeginPipelineStatisticsQuery = *const fn(*ComputePassEncoder, *QuerySet, u32) callconv(.c) void; // pub const EndPipelineStatisticsQuery = *const fn(*ComputePassEncoder) callconv(.c) void; // pub const WriteTimestamp = *const fn(*ComputePassEncoder, *QuerySet, u32) callconv(.c) void; @@ -82,7 +80,7 @@ extern fn wgpuComputePassEncoderAddRef(compute_pass_encoder: *ComputePassEncoder extern fn wgpuComputePassEncoderRelease(compute_pass_encoder: *ComputePassEncoder) void; // wgpu-native -extern fn wgpuComputePassEncoderSetPushConstants(compute_pass_encoder: *ComputePassEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void; +extern fn wgpuComputePassEncoderSetImmediates(compute_pass_encoder: *ComputePassEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void; extern fn wgpuComputePassEncoderBeginPipelineStatisticsQuery(compute_pass_encoder: *ComputePassEncoder, query_set: *QuerySet, query_index: u32) void; extern fn wgpuComputePassEncoderEndPipelineStatisticsQuery(compute_pass_encoder: *ComputePassEncoder) void; extern fn wgpuComputePassEncoderWriteTimestamp(compute_pass_encoder: *ComputePassEncoder, query_set: *QuerySet, query_index: u32) void; @@ -110,8 +108,8 @@ pub const ComputePassEncoder = opaque { wgpuComputePassEncoderSetBindGroup(self, group_index, group, dynamic_offset_count, dynamic_offsets); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L51 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *ComputePassEncoder, label: []const u8) void { // wgpuComputePassEncoderSetLabel(self, StringView.fromSlice(label)); // } @@ -127,8 +125,8 @@ pub const ComputePassEncoder = opaque { } // wgpu-native - pub inline fn setPushConstants(self: *ComputePassEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void { - wgpuComputePassEncoderSetPushConstants(self, offset, size_bytes, data); + pub inline fn setImmediates(self: *ComputePassEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void { + wgpuComputePassEncoderSetImmediates(self, offset, size_bytes, data); } pub inline fn beginPipelineStatisticsQuery(self: *ComputePassEncoder, query_set: *QuerySet, query_index: u32) void { wgpuComputePassEncoderBeginPipelineStatisticsQuery(self, query_set, query_index); @@ -171,10 +169,11 @@ pub const ColorAttachment = extern struct { }; pub const DepthStencilAttachment = extern struct { + next_in_chain: ?*const ChainedStruct = null, view: *TextureView, depth_load_op: LoadOp = LoadOp.undefined, depth_store_op: StoreOp = StoreOp.undefined, - depth_clear_value: f32 = 0, + depth_clear_value: f32 = std.math.nan(f32), depth_read_only: WGPUBool = @intFromBool(false), stencil_load_op: LoadOp = LoadOp.undefined, stencil_store_op: StoreOp = StoreOp.undefined, @@ -182,8 +181,6 @@ pub const DepthStencilAttachment = extern struct { stencil_read_only: WGPUBool = @intFromBool(false), }; -pub const RenderPassTimestampWrites = TimestampWrites; - pub const RenderPassMaxDrawCount = extern struct { chain: ChainedStruct = ChainedStruct{ .s_type = SType.render_pass_max_draw_count }, max_draw_count: u64 = 50000000, @@ -196,7 +193,7 @@ pub const RenderPassDescriptor = extern struct { color_attachments: [*]const ColorAttachment, depth_stencil_attachment: ?*const DepthStencilAttachment = null, occlusion_query_set: ?*QuerySet = null, - timestamp_writes: ?*const RenderPassTimestampWrites = null, + timestamp_writes: ?*const PassTimestampWrites = null, pub inline fn withMaxDrawCount(self: RenderPassDescriptor, max_draw_count: u64) RenderPassDescriptor { var descriptor = self; @@ -233,7 +230,6 @@ pub const RenderPassEncoderProcs = struct { pub const Release = *const fn (*RenderPassEncoder) callconv(.c) void; // wgpu-native procs? - // pub const SetPushConstants = *const fn(*RenderPassEncoder, ShaderStage, u32, u32, *const anyopaque) callconv(.c) void; // pub const MultiDrawIndirect = *const fn(*RenderPassEncoder, *Buffer, u64, u32) callconv(.c) void; // pub const MultiDrawIndexedIndirect = *const fn(*RenderPassEncoder, *Buffer, u64, u32) callconv(.c) void; // pub const MultiDrawIndirectCount = *const fn(*RenderPassEncoder, *Buffer, u64, *Buffer, u64, u32) callconv(.c) void; @@ -267,7 +263,7 @@ extern fn wgpuRenderPassEncoderAddRef(render_pass_encoder: *RenderPassEncoder) v extern fn wgpuRenderPassEncoderRelease(render_pass_encoder: *RenderPassEncoder) void; // wgpu-native -extern fn wgpuRenderPassEncoderSetPushConstants(render_pass_encoder: *RenderPassEncoder, stages: ShaderStage, offset: u32, size_bytes: u32, data: *const anyopaque) void; +extern fn wgpuRenderPassEncoderSetImmediates(render_pass_encoder: *RenderPassEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void; extern fn wgpuRenderPassEncoderMultiDrawIndirect(render_pass_encoder: *RenderPassEncoder, buffer: *Buffer, offset: u64, count: u32) void; extern fn wgpuRenderPassEncoderMultiDrawIndexedIndirect(render_pass_encoder: *RenderPassEncoder, buffer: *Buffer, offset: u64, count: u32) void; extern fn wgpuRenderPassEncoderMultiDrawIndirectCount(render_pass_encoder: *RenderPassEncoder, buffer: *Buffer, offset: u64, count_buffer: *Buffer, count_buffer_offset: u64, max_count: u32) void; @@ -320,8 +316,8 @@ pub const RenderPassEncoder = opaque { wgpuRenderPassEncoderSetIndexBuffer(self, buffer, format, offset, size); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L153 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *RenderPassEncoder, label: []const u8) void { // wgpuRenderPassEncoderSetLabel(self, StringView.fromSlice(label)); // } @@ -349,8 +345,8 @@ pub const RenderPassEncoder = opaque { } // wgpu-native - pub inline fn setPushConstants(self: *RenderPassEncoder, stages: ShaderStage, offset: u32, size_bytes: u32, data: *const anyopaque) void { - wgpuRenderPassEncoderSetPushConstants(self, stages, offset, size_bytes, data); + pub inline fn setImmediates(self: *RenderPassEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void { + wgpuRenderPassEncoderSetImmediates(self, offset, size_bytes, data); } pub inline fn multiDrawIndirect(self: *RenderPassEncoder, buffer: *Buffer, offset: u64, count: u32) void { wgpuRenderPassEncoderMultiDrawIndirect(self, buffer, offset, count); @@ -391,8 +387,8 @@ extern fn wgpuCommandBufferAddRef(command_buffer: *CommandBuffer) void; extern fn wgpuCommandBufferRelease(command_buffer: *CommandBuffer) void; pub const CommandBuffer = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L35 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *CommandBuffer, label: []const u8) void { // wgpuCommandBufferSetLabel(self, StringView.fromSlice(label)); // } @@ -479,8 +475,8 @@ pub const CommandEncoder = opaque { wgpuCommandEncoderResolveQuerySet(self, query_set, first_query, query_count, destination, destination_offset); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L43 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *CommandEncoder, label: []const u8) void { // wgpuCommandEncoderSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/device.zig b/src/device.zig index 9d66b5d..88bc43c 100644 --- a/src/device.zig +++ b/src/device.zig @@ -73,7 +73,7 @@ const Texture = _texture.Texture; pub const DeviceLostReason = enum(u32) { unknown = 0x00000001, destroyed = 0x00000002, - instance_dropped = 0x00000003, + callback_cancelled = 0x00000003, failed_creation = 0x00000004, }; @@ -156,9 +156,8 @@ pub const DeviceDescriptor = extern struct { pub const RequestDeviceStatus = enum(u32) { success = 0x00000001, - instance_dropped = 0x00000002, + callback_cancelled = 0x00000002, @"error" = 0x00000003, - unknown = 0x00000004, }; // TODO: This probably belongs in adapter.zig @@ -183,8 +182,8 @@ pub const RequestDeviceCallbackInfo = extern struct { pub const PopErrorScopeStatus = enum(u32) { success = 0x00000001, // The error scope stack was successfully popped and a result was reported. - instance_dropped = 0x00000002, - empty_stack = 0x00000003, // The error scope stack could not be popped, because it was empty. + callback_cancelled = 0x00000002, + @"error" = 0x00000003, // The error scope stack could not be popped, because it was empty. }; // status @@ -265,7 +264,7 @@ extern fn wgpuDeviceCreateSampler(device: *Device, descriptor: *const SamplerDes extern fn wgpuDeviceCreateShaderModule(device: *Device, descriptor: *const ShaderModuleDescriptor) ?*ShaderModule; extern fn wgpuDeviceCreateTexture(device: *Device, descriptor: *const TextureDescriptor) ?*Texture; extern fn wgpuDeviceDestroy(device: *Device) void; -extern fn wgpuDeviceGetAdapterInfo(device: *Device) AdapterInfo; +extern fn wgpuDeviceGetAdapterInfo(device: *Device, adapter_info: *AdapterInfo) Status; extern fn wgpuDeviceGetFeatures(device: *Device, features: *SupportedFeatures) void; extern fn wgpuDeviceGetLimits(device: *Device, limits: *Limits) Status; extern fn wgpuDeviceGetLostFuture(device: *Device) Future; @@ -298,8 +297,8 @@ pub const Device = opaque { return wgpuDeviceCreateComputePipeline(self, descriptor); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L67 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn createComputePipelineAsync(self: *Device, descriptor: *const ComputePipelineDescriptor, callback_info: CreateComputePipelineAsyncCallbackInfo) Future { // return wgpuDeviceCreateComputePipelineAsync(self, descriptor, callback_info); // } @@ -317,8 +316,8 @@ pub const Device = opaque { return wgpuDeviceCreateRenderPipeline(self, descriptor); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L76 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn createRenderPipelineAsync(self: *Device, descriptor: *const RenderPipelineDescriptor, callback_info: CreateRenderPipelineAsyncCallbackInfo) Future { // return wgpuDeviceCreateRenderPipelineAsync(self, descriptor, callback_info); // } @@ -336,10 +335,10 @@ pub const Device = opaque { wgpuDeviceDestroy(self); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L85 - // pub inline fn getAdapterInfo(self: *Device) AdapterInfo { - // return wgpuDeviceGetAdapterInfo(self); + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs + // pub inline fn getAdapterInfo(self: *Device, adapter_info: *AdapterInfo) Status { + // return wgpuDeviceGetAdapterInfo(self, adapter_info); // } pub inline fn getFeatures(self: *Device, features: *SupportedFeatures) void { @@ -349,8 +348,8 @@ pub const Device = opaque { return wgpuDeviceGetLimits(self, limits); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L90 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // Returns the Future for the device-lost event of the device. // pub inline fn getLostFuture(self: *Device) Future { // return wgpuDeviceGetLostFuture(self); @@ -370,8 +369,8 @@ pub const Device = opaque { wgpuDevicePushErrorScope(self, filter); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L95 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *Device, label: []const u8) void { // wgpuDeviceSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/instance.zig b/src/instance.zig index 3aaa889..0d8c1da 100644 --- a/src/instance.zig +++ b/src/instance.zig @@ -2,7 +2,6 @@ const std = @import("std"); const _chained_struct = @import("chained_struct.zig"); const ChainedStruct = _chained_struct.ChainedStruct; -const ChainedStructOut = _chained_struct.ChainedStructOut; const SType = _chained_struct.SType; const _adapter = @import("adapter.zig"); @@ -79,6 +78,46 @@ pub const GLFenceBehaviour = enum(u32) { gl_fence_behaviour_auto_finish = 0x00000001, }; +pub const Dx12SwapchainKind = enum(u32) { + undefined = 0x00000000, + dxgi_from_hwnd = 0x00000001, + dxgi_from_visual = 0x00000002, +}; + +pub const NativeDisplayHandleType = enum(u32) { + none = 0x00000000, + xlib = 0x00000001, + xcb = 0x00000002, + wayland = 0x00000003, +}; + +pub const XlibDisplayHandle = extern struct { + display: ?*anyopaque = null, + screen: c_int = 0, +}; + +pub const XcbDisplayHandle = extern struct { + connection: ?*anyopaque = null, + screen: c_int = 0, +}; + +pub const WaylandDisplayHandle = extern struct { + display: ?*anyopaque = null, +}; + +pub const NativeDisplayHandleData = extern union { + xlib: XlibDisplayHandle, + xcb: XcbDisplayHandle, + wayland: WaylandDisplayHandle, +}; + +pub const NativeDisplayHandle = extern struct { + type: NativeDisplayHandleType = .none, + data: NativeDisplayHandleData = .{ + .wayland = .{}, + }, +}; + pub const InstanceExtras = extern struct { chain: ChainedStruct = ChainedStruct{ .s_type = SType.instance_extras, @@ -88,27 +127,39 @@ pub const InstanceExtras = extern struct { dx12_shader_compiler: Dx12Compiler, gles3_minor_version: Gles3MinorVersion, gl_fence_behavior: GLFenceBehaviour, - dxil_path: StringView = StringView{}, dxc_path: StringView = StringView{}, dxc_max_shader_model: DxcMaxShaderModel, + dx12_presentation_system: Dx12SwapchainKind = .undefined, + budget_for_device_creation: ?*const u8 = null, + budget_for_device_loss: ?*const u8 = null, + display_handle: NativeDisplayHandle = .{}, }; -pub const InstanceCapabilities = extern struct { - // This struct chain is used as mutable in some places and immutable in others. - next_in_chain: ?*ChainedStructOut = null, +pub const InstanceFeatureName = enum(u32) { + timed_wait_any = 0x00000001, + shader_source_spirv = 0x00000002, + multiple_devices_per_adapter = 0x00000003, +}; - // Enable use of ::wgpuInstanceWaitAny with `timeoutNS > 0`. - timed_wait_any_enable: WGPUBool, +pub const SupportedInstanceFeatures = extern struct { + feature_count: usize = 0, + features: [*]const InstanceFeatureName = &[0]InstanceFeatureName{}, - // The maximum number FutureWaitInfo supported in a call to ::wgpuInstanceWaitAny with `timeoutNS > 0`. - timed_wait_any_max_count: usize, + pub inline fn freeMembers(self: SupportedInstanceFeatures) void { + wgpuSupportedInstanceFeaturesFreeMembers(self); + } }; -pub const InstanceDescriptor = extern struct { +pub const InstanceLimits = extern struct { next_in_chain: ?*const ChainedStruct = null, + timed_wait_any_max_count: usize = 0, +}; - // Instance features to enable - features: InstanceCapabilities, +pub const InstanceDescriptor = extern struct { + next_in_chain: ?*const ChainedStruct = null, + required_feature_count: usize = 0, + required_features: [*]const InstanceFeatureName = &[0]InstanceFeatureName{}, + required_limits: ?*const InstanceLimits = null, pub inline fn withNativeExtras(self: InstanceDescriptor, extras: *InstanceExtras) InstanceDescriptor { var id = self; @@ -122,6 +173,11 @@ pub const WGSLLanguageFeatureName = enum(u32) { packed4x8_integer_dot_product = 0x00000002, unrestricted_pointer_parameters = 0x00000003, pointer_composite_access = 0x00000004, + uniform_buffer_standard_layout = 0x00000005, + subgroup_id = 0x00000006, + texture_and_sampler_let = 0x00000007, + subgroup_uniformity = 0x00000008, + texture_formats_tier_1 = 0x00000009, }; pub const SupportedWGSLLanguageFeaturesProcs = struct { @@ -134,8 +190,8 @@ pub const SupportedWGSLLanguageFeatures = extern struct { feature_count: usize, features: [*]const WGSLLanguageFeatureName, - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L193 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn freeMembers(self: SupportedWGSLLanguageFeatures) void { // wgpuSupportedWGSLLanguageFeaturesFreeMembers(self); // } @@ -143,10 +199,12 @@ pub const SupportedWGSLLanguageFeatures = extern struct { pub const InstanceProcs = struct { pub const CreateInstance = *const fn (?*const InstanceDescriptor) callconv(.c) ?*Instance; - pub const GetCapabilities = *const fn (*InstanceCapabilities) callconv(.c) Status; + pub const GetInstanceFeatures = *const fn (*SupportedInstanceFeatures) callconv(.c) void; + pub const GetInstanceLimits = *const fn (*InstanceLimits) callconv(.c) Status; + pub const HasInstanceFeature = *const fn (InstanceFeatureName) callconv(.c) WGPUBool; pub const CreateSurface = *const fn (*Instance, *const SurfaceDescriptor) callconv(.c) ?*Surface; - pub const GetWGSLLanguageFeatures = *const fn (*Instance, *SupportedWGSLLanguageFeatures) callconv(.c) Status; + pub const GetWGSLLanguageFeatures = *const fn (*Instance, *SupportedWGSLLanguageFeatures) callconv(.c) void; pub const HasWGSLLanguageFeature = *const fn (*Instance, WGSLLanguageFeatureName) callconv(.c) WGPUBool; pub const ProcessEvents = *const fn (*Instance) callconv(.c) void; pub const RequestAdapter = *const fn (*Instance, ?*const RequestAdapterOptions, RequestAdapterCallbackInfo) callconv(.c) Future; @@ -159,11 +217,14 @@ pub const InstanceProcs = struct { // pub const EnumerateAdapters = *const fn(*Instance, ?*const EnumerateAdapterOptions, ?[*]Adapter) callconv(.c) usize; }; -extern fn wgpuGetInstanceCapabilities(capabilities: *InstanceCapabilities) Status; +extern fn wgpuGetInstanceFeatures(features: *SupportedInstanceFeatures) void; +extern fn wgpuGetInstanceLimits(limits: *InstanceLimits) Status; +extern fn wgpuHasInstanceFeature(feature: InstanceFeatureName) WGPUBool; +extern fn wgpuSupportedInstanceFeaturesFreeMembers(features: SupportedInstanceFeatures) void; extern fn wgpuCreateInstance(descriptor: ?*const InstanceDescriptor) ?*Instance; extern fn wgpuInstanceCreateSurface(instance: *Instance, descriptor: *const SurfaceDescriptor) ?*Surface; -extern fn wgpuInstanceGetWGSLLanguageFeatures(instance: *Instance, features: *SupportedWGSLLanguageFeatures) Status; +extern fn wgpuInstanceGetWGSLLanguageFeatures(instance: *Instance, features: *SupportedWGSLLanguageFeatures) void; extern fn wgpuInstanceHasWGSLLanguageFeature(instance: *Instance, feature: WGSLLanguageFeatureName) WGPUBool; extern fn wgpuInstanceProcessEvents(instance: *Instance) void; extern fn wgpuInstanceRequestAdapter(instance: *Instance, options: ?*const RequestAdapterOptions, callback_info: RequestAdapterCallbackInfo) Future; @@ -218,24 +279,30 @@ pub const Instance = opaque { return wgpuCreateInstance(descriptor); } - // This is also a global function, but I think it would make sense being a member of Instance; - // You'd use it like `const status = Instance.getCapabilities(&capabilities);` - pub inline fn getCapabilities(capabilities: *InstanceCapabilities) Status { - return wgpuGetInstanceCapabilities(capabilities); + pub inline fn getFeatures(features: *SupportedInstanceFeatures) void { + wgpuGetInstanceFeatures(features); + } + + pub inline fn getLimits(limits: *InstanceLimits) Status { + return wgpuGetInstanceLimits(limits); + } + + pub inline fn hasFeature(feature: InstanceFeatureName) bool { + return wgpuHasInstanceFeature(feature) != 0; } pub inline fn createSurface(self: *Instance, descriptor: *const SurfaceDescriptor) ?*Surface { return wgpuInstanceCreateSurface(self, descriptor); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L100 - // pub inline fn getWGSLLanguageFeatures(self: *Instance, features: *SupportedWGSLLanguageFeatures) Status { - // return wgpuInstanceGetWGSLLanguageFeatures(self, features); + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs + // pub inline fn getWGSLLanguageFeatures(self: *Instance, features: *SupportedWGSLLanguageFeatures) void { + // wgpuInstanceGetWGSLLanguageFeatures(self, features); // } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L108 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn hasWGSLLanguageFeature(self: *Instance, feature: WGSLLanguageFeatureName) bool { // return wgpuInstanceHasWGSLLanguageFeature(self, feature) != 0; // } @@ -290,8 +357,8 @@ pub const Instance = opaque { return wgpuInstanceRequestAdapter(self, options, callback_info); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L224 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // Wait for at least one Future in `futures` to complete, and call callbacks of the respective completed asynchronous operations. // pub inline fn waitAny(self: *Instance, future_count: usize, futures: ?[*] FutureWaitInfo, timeout_ns: u64) WaitStatus { // return wgpuInstanceWaitAny(self, future_count, futures, timeout_ns); @@ -325,11 +392,14 @@ test "can create instance (and release it afterwards)" { test "can request adapter" { const testing = @import("std").testing; - const instance = Instance.create(null); - const response = try instance.?.requestAdapterSync(std.testing.io, null, 200_000_000); + const instance = Instance.create(null).?; + defer instance.release(); + const response = try instance.requestAdapterSync(std.testing.io, null, 200_000_000); const adapter: ?*Adapter = switch (response.status) { .success => response.adapter, else => null, }; - try testing.expect(adapter != null); + if (adapter == null) return error.SkipZigTest; + defer adapter.?.release(); + try testing.expect(response.status == .success); } diff --git a/src/limits.zig b/src/limits.zig index a649be0..c662e68 100644 --- a/src/limits.zig +++ b/src/limits.zig @@ -45,12 +45,24 @@ pub const Limits = extern struct { max_compute_workgroup_size_y: u32 = WGPU_LIMIT_U32_UNDEFINED, max_compute_workgroup_size_z: u32 = WGPU_LIMIT_U32_UNDEFINED, max_compute_workgroups_per_dimension: u32 = WGPU_LIMIT_U32_UNDEFINED, + max_immediate_size: u32 = WGPU_LIMIT_U32_UNDEFINED, }; pub const WGPUNativeLimits = extern struct { - chain: ChainedStructOut = ChainedStructOut{ + chain: ChainedStruct = ChainedStruct{ .s_type = SType.native_limits, }, - max_push_constant_size: u32, - max_non_sampler_bindings: u32, + max_immediate_size: u32 = 0, + max_non_sampler_bindings: u32 = 1_000_000, + max_binding_array_elements_per_shader_stage: u32 = 0, +}; + +pub const CompatibilityModeLimits = extern struct { + chain: ChainedStruct = .{ + .s_type = .compatibility_mode_limits, + }, + max_storage_buffers_in_vertex_stage: u32 = WGPU_LIMIT_U32_UNDEFINED, + max_storage_textures_in_vertex_stage: u32 = WGPU_LIMIT_U32_UNDEFINED, + max_storage_buffers_in_fragment_stage: u32 = WGPU_LIMIT_U32_UNDEFINED, + max_storage_textures_in_fragment_stage: u32 = WGPU_LIMIT_U32_UNDEFINED, }; diff --git a/src/misc.zig b/src/misc.zig index 7e5e538..4b94b35 100644 --- a/src/misc.zig +++ b/src/misc.zig @@ -27,28 +27,32 @@ pub const OptionalBool = enum(u32) { // but idk if they should go in device.zig, adapter.zig, or their own separate file. // So they're going in the "miscellaneous" pile for now. pub const FeatureName = enum(u32) { - undefined = 0x00000000, - depth_clip_control = 0x00000001, - depth32_float_stencil8 = 0x00000002, - timestamp_query = 0x00000003, + core_features_and_limits = 0x00000001, + depth_clip_control = 0x00000002, + depth32_float_stencil8 = 0x00000003, texture_compression_bc = 0x00000004, texture_compression_bc_sliced_3d = 0x00000005, texture_compression_etc2 = 0x00000006, texture_compression_astc = 0x00000007, texture_compression_astc_sliced_3d = 0x00000008, - indirect_first_instance = 0x00000009, - shader_f16 = 0x0000000A, - rg11b10_ufloat_renderable = 0x0000000B, - bgra8_unorm_storage = 0x0000000C, - float32_filterable = 0x0000000D, - float32_blendable = 0x0000000E, - clip_distances = 0x0000000F, - dual_source_blending = 0x00000010, + timestamp_query = 0x00000009, + indirect_first_instance = 0x0000000A, + shader_f16 = 0x0000000B, + rg11b10_ufloat_renderable = 0x0000000C, + bgra8_unorm_storage = 0x0000000D, + float32_filterable = 0x0000000E, + float32_blendable = 0x0000000F, + clip_distances = 0x00000010, + dual_source_blending = 0x00000011, + subgroups = 0x00000012, + texture_formats_tier_1 = 0x00000013, + texture_formats_tier_2 = 0x00000014, + primitive_index = 0x00000015, + texture_component_swizzle = 0x00000016, // wgpu-native extras - push_constants = 0x00030001, + immediates = 0x00030001, texture_adapter_specific_format_features = 0x00030002, - multi_draw_indirect = 0x00030003, multi_draw_indirect_count = 0x00030004, vertex_writable_storage = 0x00030005, texture_binding_array = 0x00030006, @@ -61,20 +65,22 @@ pub const FeatureName = enum(u32) { mappable_primary_buffers = 0x0003000E, buffer_binding_array = 0x0003000F, uniform_buffer_and_storage_texture_array_non_uniform_indexing = 0x00030010, + polygon_mode_line = 0x00030013, + polygon_mode_point = 0x00030014, + conservative_rasterization = 0x00030015, spirv_shader_passthrough = 0x00030017, vertex_attribute_64bit = 0x00030019, texture_format_nv12 = 0x0003001A, - ray_tracing_acceleration_structure = 0x0003001B, ray_query = 0x0003001C, shader_f64 = 0x0003001D, shader_i16 = 0x0003001E, - shader_primitive_index = 0x0003001F, shader_early_depth_test = 0x00030020, subgroup = 0x00030021, subgroup_vertex = 0x00030022, subgroup_barrier = 0x00030023, timestamp_query_inside_encoders = 0x00030024, timestamp_query_inside_passes = 0x00030025, + shader_int64 = 0x00030026, }; pub const SupportedFeaturesProcs = struct { diff --git a/src/pipeline.zig b/src/pipeline.zig index 348234d..60c0cac 100644 --- a/src/pipeline.zig +++ b/src/pipeline.zig @@ -4,7 +4,6 @@ const SType = _chained_struct.SType; const _shader = @import("shader.zig"); const ShaderModule = _shader.ShaderModule; -const ShaderStage = _shader.ShaderStage; const BindGroupLayout = @import("bind_group.zig").BindGroupLayout; @@ -21,18 +20,11 @@ const CallbackMode = _async.CallbackMode; const TextureFormat = @import("texture.zig").TextureFormat; -pub const PushConstantRange = extern struct { - stages: ShaderStage, - start: u32, - end: u32, -}; - pub const PipelineLayoutExtras = extern struct { chain: ChainedStruct = ChainedStruct{ .s_type = SType.pipeline_layout_extras, }, - push_constant_range_count: usize, - push_constant_ranges: [*]const PushConstantRange, + immediate_data_size: u32 = 0, }; pub const PipelineLayoutDescriptor = extern struct { @@ -40,12 +32,12 @@ pub const PipelineLayoutDescriptor = extern struct { label: StringView = StringView{}, bind_group_layout_count: usize, bind_group_layouts: [*]const *BindGroupLayout, + immediate_size: u32 = 0, - pub inline fn withPushConstantRanges(self: PipelineLayoutDescriptor, push_constant_range_count: usize, push_constant_ranges: [*]const PushConstantRange) PipelineLayoutDescriptor { + pub inline fn withImmediateDataSize(self: PipelineLayoutDescriptor, immediate_data_size: u32) PipelineLayoutDescriptor { var pld = self; pld.next_in_chain = @ptrCast(&PipelineLayoutExtras{ - .push_constant_range_count = push_constant_range_count, - .push_constant_ranges = push_constant_ranges, + .immediate_data_size = immediate_data_size, }); return pld; } @@ -63,8 +55,8 @@ extern fn wgpuPipelineLayoutRelease(pipeline_layout: *PipelineLayout) void; pub const PipelineLayout = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L116 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *PipelineLayout, label: []const u8) void { // wgpuPipelineLayoutSetLabel(self, StringView.fromSlice(label)); // } @@ -83,7 +75,7 @@ pub const ConstantEntry = extern struct { value: f64, }; -pub const ProgrammableStageDescriptor = extern struct { +pub const ComputeState = extern struct { next_in_chain: ?*const ChainedStruct = null, module: *ShaderModule, entry_point: StringView = StringView{}, @@ -95,15 +87,14 @@ pub const ComputePipelineDescriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: StringView = StringView{}, layout: ?*PipelineLayout = null, - compute: ProgrammableStageDescriptor, + compute: ComputeState, }; pub const CreatePipelineAsyncStatus = enum(u32) { success = 0x00000001, - instance_dropped = 0x00000002, + callback_cancelled = 0x00000002, validation_error = 0x00000003, internal_error = 0x00000004, - unknown = 0x00000005, }; pub const CreateComputePipelineAsyncCallbackInfo = extern struct { @@ -143,8 +134,8 @@ pub const ComputePipeline = opaque { return wgpuComputePipelineGetBindGroupLayout(self, group_index); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L59 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *ComputePipeline, label: []const u8) void { // wgpuComputePipelineSetLabel(self, StringView.fromSlice(label)); // } @@ -158,10 +149,9 @@ pub const ComputePipeline = opaque { }; pub const VertexStepMode = enum(u32) { - vertex_buffer_not_used = 0x00000000, // This VertexBufferLayout is a "hole" in the VertexState `buffers` array. - undefined = 0x00000001, // Indicates no value is passed for this argument. - vertex = 0x00000002, - instance = 0x00000003, + undefined = 0x00000000, // Indicates no value is passed for this argument. + vertex = 0x00000001, + instance = 0x00000002, }; pub const VertexFormat = enum(u32) { @@ -209,16 +199,19 @@ pub const VertexFormat = enum(u32) { }; pub const VertexAttribute = extern struct { + next_in_chain: ?*const ChainedStruct = null, format: VertexFormat, offset: u64, shader_location: u32, }; pub const VertexBufferLayout = extern struct { + next_in_chain: ?*const ChainedStruct = null, + // The step mode for the vertex buffer. If VertexStepMode.vertex_buffer_not_used, // indicates a "hole" in the parent VertexState `buffers` array: // the pipeline does not use a vertex buffer at this `location`. - step_mode: VertexStepMode = VertexStepMode.vertex, + step_mode: VertexStepMode = VertexStepMode.undefined, array_stride: u64, attribute_count: usize, @@ -266,6 +259,20 @@ pub const PrimitiveState = extern struct { unclipped_depth: WGPUBool = @intFromBool(false), }; +pub const PolygonMode = enum(u32) { + fill = 0, + line = 1, + point = 2, +}; + +pub const PrimitiveStateExtras = extern struct { + chain: ChainedStruct = .{ + .s_type = .primitive_state_extras, + }, + polygon_mode: PolygonMode = .fill, + conservative: WGPUBool = @intFromBool(false), +}; + pub const StencilOperation = enum(u32) { undefined = 0x00000000, // Indicates no value is passed for this argument. keep = 0x00000001, @@ -437,8 +444,8 @@ pub const RenderPipeline = opaque { return wgpuRenderPipelineGetBindGroupLayout(self, group_index); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L161 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *RenderPipeline, label: []const u8) void { // wgpuRenderPipelineSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/query_set.zig b/src/query_set.zig index bc1529a..3c4eaa3 100644 --- a/src/query_set.zig +++ b/src/query_set.zig @@ -71,8 +71,8 @@ pub const QuerySet = opaque { return wgpuQuerySetGetType(self); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L124 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *QuerySet, label: []const u8) void { // wgpuQuerySetSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/queue.zig b/src/queue.zig index 70e889f..bc2edd2 100644 --- a/src/queue.zig +++ b/src/queue.zig @@ -22,9 +22,8 @@ pub const QueueDescriptor = extern struct { pub const WorkDoneStatus = enum(u32) { success = 0x00000001, - instance_dropped = 0x00000002, + callback_cancelled = 0x00000002, @"error" = 0x00000003, - unknown = 0x00000004, }; pub const QueueWorkDoneCallbackInfo = extern struct { @@ -38,7 +37,7 @@ pub const QueueWorkDoneCallbackInfo = extern struct { userdata2: ?*anyopaque = null, }; -pub const QueueWorkDoneCallback = *const fn (status: WorkDoneStatus, userdata1: ?*anyopaque, userdata2: ?*anyopaque) callconv(.c) void; +pub const QueueWorkDoneCallback = *const fn (status: WorkDoneStatus, message: StringView, userdata1: ?*anyopaque, userdata2: ?*anyopaque) callconv(.c) void; pub const QueueProcs = struct { pub const OnSubmittedWorkDone = *const fn (*Queue, QueueWorkDoneCallbackInfo) callconv(.c) Future; @@ -69,8 +68,8 @@ pub const Queue = opaque { return wgpuQueueOnSubmittedWorkDone(self, callback_info); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L132 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *Queue, label: []const u8) void { // wgpuQueueSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/render_bundle.zig b/src/render_bundle.zig index 5307a66..47e0629 100644 --- a/src/render_bundle.zig +++ b/src/render_bundle.zig @@ -8,8 +8,6 @@ const TextureFormat = @import("texture.zig").TextureFormat; const Buffer = @import("buffer.zig").Buffer; const BindGroup = @import("bind_group.zig").BindGroup; const RenderPipeline = @import("pipeline.zig").RenderPipeline; -const ShaderStage = @import("shader.zig").ShaderStage; - pub const RenderBundleEncoderDescriptor = extern struct { next_in_chain: ?*const ChainedStruct = null, label: StringView = StringView{}, @@ -37,9 +35,6 @@ pub const RenderBundleEncoderProcs = struct { pub const SetVertexBuffer = *const fn (*RenderBundleEncoder, u32, *Buffer, u64, u64) callconv(.c) void; pub const AddRef = *const fn (*RenderBundleEncoder) callconv(.c) void; pub const Release = *const fn (*RenderBundleEncoder) callconv(.c) void; - - // wgpu-native procs? - // pub const SetPushConstants = *const fn(*RenderBundleEncoder, ShaderStage, u32, u32, *const anyopaque) callconv(.c) void; }; extern fn wgpuRenderBundleEncoderDraw(render_bundle_encoder: *RenderBundleEncoder, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32) void; @@ -59,7 +54,7 @@ extern fn wgpuRenderBundleEncoderAddRef(render_bundle_encoder: *RenderBundleEnco extern fn wgpuRenderBundleEncoderRelease(render_bundle_encoder: *RenderBundleEncoder) void; // wgpu-native -extern fn wgpuRenderBundleEncoderSetPushConstants(render_bundle_encoder: *RenderBundleEncoder, stages: ShaderStage, offset: u32, size_bytes: u32, data: *const anyopaque) void; +extern fn wgpuRenderBundleEncoderSetImmediates(render_bundle_encoder: *RenderBundleEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void; // TODO: This is very similar to CommandEncoder; should it go in the same file? There's a lot of duplicated import code. pub const RenderBundleEncoder = opaque { @@ -94,8 +89,8 @@ pub const RenderBundleEncoder = opaque { wgpuRenderBundleEncoderSetIndexBuffer(self, buffer, format, offset, size); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L145 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *RenderBundleEncoder, label: []const u8) void { // wgpuRenderBundleEncoderSetLabel(self, StringView.fromSlice(label)); // } @@ -114,8 +109,8 @@ pub const RenderBundleEncoder = opaque { } // wgpu-native - pub inline fn setPushConstants(self: *RenderBundleEncoder, stages: ShaderStage, offset: u32, size_bytes: u32, data: *const anyopaque) void { - wgpuRenderBundleEncoderSetPushConstants(self, stages, offset, size_bytes, data); + pub inline fn setImmediates(self: *RenderBundleEncoder, offset: u32, size_bytes: u32, data: *const anyopaque) void { + wgpuRenderBundleEncoderSetImmediates(self, offset, size_bytes, data); } }; @@ -135,8 +130,8 @@ extern fn wgpuRenderBundleAddRef(render_bundle: *RenderBundle) void; extern fn wgpuRenderBundleRelease(render_bundle: *RenderBundle) void; pub const RenderBundle = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L137 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *RenderBundle, label: []const u8) void { // wgpuRenderBundleSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/root.zig b/src/root.zig index 1be3735..4a954db 100644 --- a/src/root.zig +++ b/src/root.zig @@ -22,6 +22,7 @@ pub const AdapterType = _adapter.AdapterType; pub const BackendType = _adapter.BackendType; pub const FeatureLevel = _adapter.FeatureLevel; pub const RequestAdapterOptions = _adapter.RequestAdapterOptions; +pub const RequestAdapterWebXROptions = _adapter.RequestAdapterWebXROptions; pub const RequestAdapterStatus = _adapter.RequestAdapterStatus; pub const RequestAdapterCallbackInfo = _adapter.RequestAdapterCallbackInfo; pub const RequestAdapterCallback = _adapter.RequestAdapterCallback; @@ -32,6 +33,9 @@ pub const AdapterProcs = _adapter.AdapterProcs; pub const Adapter = _adapter.Adapter; const _bind_group = @import("bind_group.zig"); +pub const ExternalTexture = _bind_group.ExternalTexture; +pub const ExternalTextureBindingLayout = _bind_group.ExternalTextureBindingLayout; +pub const ExternalTextureBindingEntry = _bind_group.ExternalTextureBindingEntry; pub const BindGroupLayoutEntryExtras = _bind_group.BindGroupLayoutEntryExtras; pub const BindGroupLayoutEntry = _bind_group.BindGroupLayoutEntry; pub const BindGroupLayoutDescriptor = _bind_group.BindGroupLayoutDescriptor; @@ -67,8 +71,7 @@ pub const ChainedStructOut = _chained_struct.ChainedStructOut; const _command_encoder = @import("command_encoder.zig"); pub const WGPU_DEPTH_SLICE_UNDEFINED = _command_encoder.WGPU_DEPTH_SLICE_UNDEFINED; pub const WGPU_QUERY_SET_INDEX_UNDEFINED = _command_encoder.WGPU_QUERY_SET_INDEX_UNDEFINED; -pub const TimestampWrites = _command_encoder.TimestampWrites; -pub const ComputePassTimestampWrites = _command_encoder.ComputePassTimestampWrites; +pub const PassTimestampWrites = _command_encoder.PassTimestampWrites; pub const ComputePassDescriptor = _command_encoder.ComputePassDescriptor; pub const CommandEncoderDescriptor = _command_encoder.CommandEncoderDescriptor; pub const ComputePassEncoder = _command_encoder.ComputePassEncoder; @@ -77,7 +80,6 @@ pub const StoreOp = _command_encoder.StoreOp; pub const Color = _command_encoder.Color; pub const ColorAttachment = _command_encoder.ColorAttachment; pub const DepthStencilAttachment = _command_encoder.DepthStencilAttachment; -pub const RenderPassTimestampWrites = _command_encoder.RenderPassTimestampWrites; pub const RenderPassMaxDrawCount = _command_encoder.RenderPassMaxDrawCount; pub const RenderPassDescriptor = _command_encoder.RenderPassDescriptor; pub const RenderPassEncoderProcs = _command_encoder.RenderPassEncoderProcs; @@ -118,8 +120,17 @@ pub const Dx12Compiler = _instance.Dx12Compiler; pub const Gles3MinorVersion = _instance.Gles3MinorVersion; pub const DxcMaxShaderModel = _instance.DxcMaxShaderModel; pub const GLFenceBehaviour = _instance.GLFenceBehaviour; +pub const Dx12SwapchainKind = _instance.Dx12SwapchainKind; +pub const NativeDisplayHandleType = _instance.NativeDisplayHandleType; +pub const XlibDisplayHandle = _instance.XlibDisplayHandle; +pub const XcbDisplayHandle = _instance.XcbDisplayHandle; +pub const WaylandDisplayHandle = _instance.WaylandDisplayHandle; +pub const NativeDisplayHandleData = _instance.NativeDisplayHandleData; +pub const NativeDisplayHandle = _instance.NativeDisplayHandle; pub const InstanceExtras = _instance.InstanceExtras; -pub const InstanceCapabilities = _instance.InstanceCapabilities; +pub const InstanceFeatureName = _instance.InstanceFeatureName; +pub const SupportedInstanceFeatures = _instance.SupportedInstanceFeatures; +pub const InstanceLimits = _instance.InstanceLimits; pub const InstanceDescriptor = _instance.InstanceDescriptor; pub const WGSLLanguageFeatureName = _instance.WGSLLanguageFeatureName; pub const SupportedWGSLLanguageFeaturesProcs = _instance.SupportedWGSLLanguageFeaturesProcs; @@ -136,6 +147,7 @@ pub const WGPU_LIMIT_U32_UNDEFINED = _limits.WGPU_LIMIT_U32_UNDEFINED; pub const WGPU_LIMIT_U64_UNDEFINED = _limits.WGPU_LIMIT_U64_UNDEFINED; pub const Limits = _limits.Limits; pub const WGPUNativeLimits = _limits.WGPUNativeLimits; +pub const CompatibilityModeLimits = _limits.CompatibilityModeLimits; const _log = @import("log.zig"); pub const LogLevel = _log.LogLevel; @@ -144,13 +156,12 @@ pub const setLogCallback = _log.setLogCallback; pub const setLogLevel = _log.setLogLevel; const _pipeline = @import("pipeline.zig"); -pub const PushConstantRange = _pipeline.PushConstantRange; pub const PipelineLayoutExtras = _pipeline.PipelineLayoutExtras; pub const PipelineLayoutDescriptor = _pipeline.PipelineLayoutDescriptor; pub const PipelineLayoutProcs = _pipeline.PipelineLayoutProcs; pub const PipelineLayout = _pipeline.PipelineLayout; pub const ConstantEntry = _pipeline.ConstantEntry; -pub const ProgrammableStageDescriptor = _pipeline.ProgrammableStageDescriptor; +pub const ComputeState = _pipeline.ComputeState; pub const ComputePipelineDescriptor = _pipeline.ComputePipelineDescriptor; pub const CreatePipelineAsyncStatus = _pipeline.CreatePipelineAsyncStatus; pub const CreateComputePipelineAsyncCallbackInfo = _pipeline.CreateComputePipelineAsyncCallbackInfo; @@ -166,6 +177,8 @@ pub const PrimitiveTopology = _pipeline.PrimitiveTopology; pub const FrontFace = _pipeline.FrontFace; pub const CullMode = _pipeline.CullMode; pub const PrimitiveState = _pipeline.PrimitiveState; +pub const PolygonMode = _pipeline.PolygonMode; +pub const PrimitiveStateExtras = _pipeline.PrimitiveStateExtras; pub const StencilOperation = _pipeline.StencilOperation; pub const StencilFaceState = _pipeline.StencilFaceState; pub const DepthStencilState = _pipeline.DepthStencilState; @@ -255,6 +268,7 @@ pub const SurfaceSourceWaylandSurface = _surface.SurfaceSourceWaylandSurface; pub const MergedSurfaceDescriptorFromWaylandSurface = _surface.MergedSurfaceDescriptorFromWaylandSurface; pub const surfaceDescriptorFromWaylandSurface = _surface.surfaceDescriptorFromWaylandSurface; pub const SurfaceSourceWindowsHWND = _surface.SurfaceSourceWindowsHWND; +pub const SurfaceSourceSwapChainPanel = _surface.SurfaceSourceSwapChainPanel; pub const MergedSurfaceDescriptorFromWindowsHWND = _surface.MergedSurfaceDescriptorFromWindowsHWND; pub const surfaceDescriptorFromWindowsHWND = _surface.surfaceDescriptorFromWindowsHWND; pub const SurfaceSourceXCBWindow = _surface.SurfaceSourceXCBWindow; @@ -265,6 +279,9 @@ pub const MergedSurfaceDescriptorFromXlibWindow = _surface.MergedSurfaceDescript pub const surfaceDescriptorFromXlibWindow = _surface.surfaceDescriptorFromXlibWindow; pub const CompositeAlphaMode = _surface.CompositeAlphaMode; pub const PresentMode = _surface.PresentMode; +pub const PredefinedColorSpace = _surface.PredefinedColorSpace; +pub const ToneMappingMode = _surface.ToneMappingMode; +pub const SurfaceColorManagement = _surface.SurfaceColorManagement; pub const SurfaceConfigurationExtras = _surface.SurfaceConfigurationExtras; pub const SurfaceConfiguration = _surface.SurfaceConfiguration; pub const SurfaceCapabilitiesProcs = _surface.SurfaceCapabilitiesProcs; @@ -283,10 +300,14 @@ pub const TextureUsage = _texture.TextureUsage; pub const TextureUsages = _texture.TextureUsages; pub const TextureAspect = _texture.TextureAspect; pub const TextureViewDescriptor = _texture.TextureViewDescriptor; +pub const ComponentSwizzle = _texture.ComponentSwizzle; +pub const TextureComponentSwizzle = _texture.TextureComponentSwizzle; +pub const TextureComponentSwizzleDescriptor = _texture.TextureComponentSwizzleDescriptor; pub const TextureViewProcs = _texture.TextureViewProcs; pub const TextureView = _texture.TextureView; pub const SampleType = _texture.SampleType; pub const ViewDimension = _texture.ViewDimension; +pub const TextureBindingViewDimension = _texture.TextureBindingViewDimension; pub const TextureBindingLayout = _texture.TextureBindingLayout; pub const StorageTextureAccess = _texture.StorageTextureAccess; pub const StorageTextureBindingLayout = _texture.StorageTextureBindingLayout; diff --git a/src/sampler.zig b/src/sampler.zig index adb4e2a..932a54b 100644 --- a/src/sampler.zig +++ b/src/sampler.zig @@ -66,8 +66,8 @@ extern fn wgpuSamplerAddRef(sampler: *Sampler) void; extern fn wgpuSamplerRelease(sampler: *Sampler) void; pub const Sampler = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L169 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *Sampler, label: []const u8) void { // wgpuSamplerSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/shader.zig b/src/shader.zig index f0d1b8a..29585e1 100644 --- a/src/shader.zig +++ b/src/shader.zig @@ -108,9 +108,7 @@ pub inline fn shaderModuleGLSLDescriptor( pub const CompilationInfoRequestStatus = enum(u32) { success = 0x00000001, - instance_dropped = 0x00000002, - @"error" = 0x00000003, - unknown = 0x00000004, + callback_cancelled = 0x00000002, }; pub const CompilationMessageType = enum(u32) { @@ -171,14 +169,14 @@ extern fn wgpuShaderModuleAddRef(shader_module: *ShaderModule) void; extern fn wgpuShaderModuleRelease(shader_module: *ShaderModule) void; pub const ShaderModule = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L177 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn getCompilationInfo(self: *ShaderModule, callback_info: CompilationInfoCallbackInfo) Future { // return wgpuShaderModuleGetCompilationInfo(self, callback_info); // } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L185 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *ShaderModule, label: []const u8) void { // wgpuShaderModuleSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/surface.zig b/src/surface.zig index 04ac6c6..0f80b52 100644 --- a/src/surface.zig +++ b/src/surface.zig @@ -203,6 +203,13 @@ pub const CompositeAlphaMode = enum(u32) { inherit = 0x00000004, }; +pub const SurfaceSourceSwapChainPanel = extern struct { + chain: ChainedStruct = .{ + .s_type = .surface_source_swap_chain_panel, + }, + panel_native: ?*anyopaque = null, +}; + // Describes when and in which order frames are presented on the screen when `::wgpuSurfacePresent` is called. pub const PresentMode = enum(u32) { // Present mode is not specified. Use the default. @@ -227,6 +234,24 @@ pub const PresentMode = enum(u32) { mailbox = 0x00000004, }; +pub const PredefinedColorSpace = enum(u32) { + srgb = 0x00000001, + display_p3 = 0x00000002, +}; + +pub const ToneMappingMode = enum(u32) { + standard = 0x00000001, + extended = 0x00000002, +}; + +pub const SurfaceColorManagement = extern struct { + chain: ChainedStruct = .{ + .s_type = .surface_color_management, + }, + color_space: PredefinedColorSpace, + tone_mapping_mode: ToneMappingMode, +}; + pub const SurfaceConfigurationExtras = extern struct { chain: ChainedStruct = ChainedStruct{ .s_type = SType.surface_configuration_extras, @@ -325,14 +350,11 @@ pub const GetCurrentTextureStatus = enum(u32) { // The connection to whatever owns the surface was lost. lost = 0x00000005, - // The system ran out of memory. - out_of_memory = 0x00000006, - - // The Device configured on the Surface was lost. - device_lost = 0x00000007, - // The surface is not configured, or there was an OutStructChainError. - @"error" = 0x00000008, + @"error" = 0x00000006, + + // wgpu-native extension: the surface is currently occluded. + occluded = 0x00030001, }; // Queried each frame from a Surface to get a Texture to render to along with some metadata. @@ -405,8 +427,8 @@ pub const Surface = opaque { return wgpuSurfacePresent(self); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L200 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *Surface, label: []const u8) void { // wgpuSurfaceSetLabel(self, StringView.fromSlice(label)); // } diff --git a/src/texture.zig b/src/texture.zig index b20f7d9..4629532 100644 --- a/src/texture.zig +++ b/src/texture.zig @@ -18,106 +18,113 @@ pub const TextureFormat = enum(u32) { r8_snorm = 0x00000002, r8_uint = 0x00000003, r8_sint = 0x00000004, - r16_uint = 0x00000005, - r16_sint = 0x00000006, - r16_float = 0x00000007, - rg8_unorm = 0x00000008, - rg8_snorm = 0x00000009, - rg8_uint = 0x0000000A, - rg8_sint = 0x0000000B, - r32_float = 0x0000000C, - r32_uint = 0x0000000D, - r32_sint = 0x0000000E, - rg16_uint = 0x0000000F, - rg16_sint = 0x00000010, - rg16_float = 0x00000011, - rgba8_unorm = 0x00000012, - rgba8_unorm_srgb = 0x00000013, - rgba8_snorm = 0x00000014, - rgba8_uint = 0x00000015, - rgba8_sint = 0x00000016, - bgra8_unorm = 0x00000017, - bgra8_unorm_srgb = 0x00000018, - rgb10a2_uint = 0x00000019, - rgb10a2_unorm = 0x0000001A, - rg11b10_ufloat = 0x0000001B, - rgb9e5_ufloat = 0x0000001C, - rg32_float = 0x0000001D, - rg32_uint = 0x0000001E, - rg32_sint = 0x0000001F, - rgba16_uint = 0x00000020, - rgba16_sint = 0x00000021, - rgba16_float = 0x00000022, - rgba32_float = 0x00000023, - rgba32_uint = 0x00000024, - rgba32_sint = 0x00000025, - stencil8 = 0x00000026, - depth16_unorm = 0x00000027, - depth24_plus = 0x00000028, - depth24_plus_stencil8 = 0x00000029, - depth32_float = 0x0000002A, - depth32_float_stencil8 = 0x0000002B, - bc1_rgba_unorm = 0x0000002C, - bc1_rgba_unorm_srgb = 0x0000002D, - bc2_rgba_unorm = 0x0000002E, - bc2_rgba_unorm_srgb = 0x0000002F, - bc3_rgba_unorm = 0x00000030, - bc3_rgba_unorm_srgb = 0x00000031, - bc4_r_unorm = 0x00000032, - bc4_r_snorm = 0x00000033, - bc5_rg_unorm = 0x00000034, - bc5_rg_snorm = 0x00000035, - bc6_hrgb_ufloat = 0x00000036, - bc6_hrgb_float = 0x00000037, - bc7_rgba_unorm = 0x00000038, - bc7_rgba_unorm_srgb = 0x00000039, - etc2_rgb8_unorm = 0x0000003A, - etc2_rgb8_unorm_srgb = 0x0000003B, - etc2_rgb8a1_unorm = 0x0000003C, - etc2_rgb8a1_unorm_srgb = 0x0000003D, - etc2_rgba8_unorm = 0x0000003E, - etc2_rgba8_unorm_srgb = 0x0000003F, - eacr11_unorm = 0x00000040, - eacr11_snorm = 0x00000041, - eacrg11_unorm = 0x00000042, - eacrg11_snorm = 0x00000043, - astc4x4_unorm = 0x00000044, - astc4x4_unorm_srgb = 0x00000045, - astc5x4_unorm = 0x00000046, - astc5x4_unorm_srgb = 0x00000047, - astc5x5_unorm = 0x00000048, - astc5x5_unorm_srgb = 0x00000049, - astc6x5_unorm = 0x0000004A, - astc6x5_unorm_srgb = 0x0000004B, - astc6x6_unorm = 0x0000004C, - astc6x6_unorm_srgb = 0x0000004D, - astc8x5_unorm = 0x0000004E, - astc8x5_unorm_srgb = 0x0000004F, - astc8x6_unorm = 0x00000050, - astc8x6_unorm_srgb = 0x00000051, - astc8x8_unorm = 0x00000052, - astc8x8_unorm_srgb = 0x00000053, - astc10x5_unorm = 0x00000054, - astc10x5_unorm_srgb = 0x00000055, - astc10x6_unorm = 0x00000056, - astc10x6_unorm_srgb = 0x00000057, - astc10x8_unorm = 0x00000058, - astc10x8_unorm_srgb = 0x00000059, - astc10x10_unorm = 0x0000005A, - astc10x10_unorm_srgb = 0x0000005B, - astc12x10_unorm = 0x0000005C, - astc12x10_unorm_srgb = 0x0000005D, - astc12x12_unorm = 0x0000005E, - astc12x12_unorm_srgb = 0x0000005F, + r16_unorm = 0x00000005, + r16_snorm = 0x00000006, + r16_uint = 0x00000007, + r16_sint = 0x00000008, + r16_float = 0x00000009, + rg8_unorm = 0x0000000A, + rg8_snorm = 0x0000000B, + rg8_uint = 0x0000000C, + rg8_sint = 0x0000000D, + r32_float = 0x0000000E, + r32_uint = 0x0000000F, + r32_sint = 0x00000010, + rg16_unorm = 0x00000011, + rg16_snorm = 0x00000012, + rg16_uint = 0x00000013, + rg16_sint = 0x00000014, + rg16_float = 0x00000015, + rgba8_unorm = 0x00000016, + rgba8_unorm_srgb = 0x00000017, + rgba8_snorm = 0x00000018, + rgba8_uint = 0x00000019, + rgba8_sint = 0x0000001A, + bgra8_unorm = 0x0000001B, + bgra8_unorm_srgb = 0x0000001C, + rgb10a2_uint = 0x0000001D, + rgb10a2_unorm = 0x0000001E, + rg11b10_ufloat = 0x0000001F, + rgb9e5_ufloat = 0x00000020, + rg32_float = 0x00000021, + rg32_uint = 0x00000022, + rg32_sint = 0x00000023, + rgba16_unorm = 0x00000024, + rgba16_snorm = 0x00000025, + rgba16_uint = 0x00000026, + rgba16_sint = 0x00000027, + rgba16_float = 0x00000028, + rgba32_float = 0x00000029, + rgba32_uint = 0x0000002A, + rgba32_sint = 0x0000002B, + stencil8 = 0x0000002C, + depth16_unorm = 0x0000002D, + depth24_plus = 0x0000002E, + depth24_plus_stencil8 = 0x0000002F, + depth32_float = 0x00000030, + depth32_float_stencil8 = 0x00000031, + bc1_rgba_unorm = 0x00000032, + bc1_rgba_unorm_srgb = 0x00000033, + bc2_rgba_unorm = 0x00000034, + bc2_rgba_unorm_srgb = 0x00000035, + bc3_rgba_unorm = 0x00000036, + bc3_rgba_unorm_srgb = 0x00000037, + bc4_r_unorm = 0x00000038, + bc4_r_snorm = 0x00000039, + bc5_rg_unorm = 0x0000003A, + bc5_rg_snorm = 0x0000003B, + bc6_hrgb_ufloat = 0x0000003C, + bc6_hrgb_float = 0x0000003D, + bc7_rgba_unorm = 0x0000003E, + bc7_rgba_unorm_srgb = 0x0000003F, + etc2_rgb8_unorm = 0x00000040, + etc2_rgb8_unorm_srgb = 0x00000041, + etc2_rgb8a1_unorm = 0x00000042, + etc2_rgb8a1_unorm_srgb = 0x00000043, + etc2_rgba8_unorm = 0x00000044, + etc2_rgba8_unorm_srgb = 0x00000045, + eacr11_unorm = 0x00000046, + eacr11_snorm = 0x00000047, + eacrg11_unorm = 0x00000048, + eacrg11_snorm = 0x00000049, + astc4x4_unorm = 0x0000004A, + astc4x4_unorm_srgb = 0x0000004B, + astc5x4_unorm = 0x0000004C, + astc5x4_unorm_srgb = 0x0000004D, + astc5x5_unorm = 0x0000004E, + astc5x5_unorm_srgb = 0x0000004F, + astc6x5_unorm = 0x00000050, + astc6x5_unorm_srgb = 0x00000051, + astc6x6_unorm = 0x00000052, + astc6x6_unorm_srgb = 0x00000053, + astc8x5_unorm = 0x00000054, + astc8x5_unorm_srgb = 0x00000055, + astc8x6_unorm = 0x00000056, + astc8x6_unorm_srgb = 0x00000057, + astc8x8_unorm = 0x00000058, + astc8x8_unorm_srgb = 0x00000059, + astc10x5_unorm = 0x0000005A, + astc10x5_unorm_srgb = 0x0000005B, + astc10x6_unorm = 0x0000005C, + astc10x6_unorm_srgb = 0x0000005D, + astc10x8_unorm = 0x0000005E, + astc10x8_unorm_srgb = 0x0000005F, + astc10x10_unorm = 0x00000060, + astc10x10_unorm_srgb = 0x00000061, + astc12x10_unorm = 0x00000062, + astc12x10_unorm_srgb = 0x00000063, + astc12x12_unorm = 0x00000064, + astc12x12_unorm_srgb = 0x00000065, // wgpu-native texture formats - r16_unorm = 0x00030001, - r16_snorm = 0x00030002, - rg16_unorm = 0x00030003, - rg16_snorm = 0x00030004, - rgba16_unorm = 0x00030005, - rgba16_snorm = 0x00030006, + native_r16_unorm = 0x00030001, + native_r16_snorm = 0x00030002, + native_rg16_unorm = 0x00030003, + native_rg16_snorm = 0x00030004, + native_rgba16_unorm = 0x00030005, + native_rgba16_snorm = 0x00030006, nv12 = 0x00030007, + p010 = 0x00030008, }; pub const TextureUsage = WGPUFlags; @@ -128,6 +135,7 @@ pub const TextureUsages = struct { pub const texture_binding = @as(TextureUsage, 0x0000000000000004); pub const storage_binding = @as(TextureUsage, 0x0000000000000008); pub const render_attachment = @as(TextureUsage, 0x0000000000000010); + pub const transient_attachment = @as(TextureUsage, 0x0000000000000020); }; // TODO: Like a lot of things in this file, this breaks from the wrapper code convention by having an unneeded prefix ("Texture") @@ -153,6 +161,30 @@ pub const TextureViewDescriptor = extern struct { usage: TextureUsage = TextureUsages.none, }; +pub const ComponentSwizzle = enum(u32) { + undefined = 0x00000000, + zero = 0x00000001, + one = 0x00000002, + r = 0x00000003, + g = 0x00000004, + b = 0x00000005, + a = 0x00000006, +}; + +pub const TextureComponentSwizzle = extern struct { + r: ComponentSwizzle = .undefined, + g: ComponentSwizzle = .undefined, + b: ComponentSwizzle = .undefined, + a: ComponentSwizzle = .undefined, +}; + +pub const TextureComponentSwizzleDescriptor = extern struct { + chain: ChainedStruct = .{ + .s_type = .texture_component_swizzle_descriptor, + }, + swizzle: TextureComponentSwizzle = .{}, +}; + pub const TextureViewProcs = struct { pub const SetLabel = *const fn (*TextureView, StringView) callconv(.c) void; pub const AddRef = *const fn (*TextureView) callconv(.c) void; @@ -164,8 +196,8 @@ extern fn wgpuTextureViewAddRef(texture_view: *TextureView) void; extern fn wgpuTextureViewRelease(texture_view: *TextureView) void; pub const TextureView = opaque { - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L216 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *TextureView, label: []const u8) void { // wgpuTextureViewSetLabel(self, StringView.fromSlice(label)); // } @@ -203,6 +235,13 @@ pub const ViewDimension = enum(u32) { @"3d" = 0x00000006, }; +pub const TextureBindingViewDimension = extern struct { + chain: ChainedStruct = .{ + .s_type = .texture_binding_view_dimension, + }, + texture_binding_view_dimension: ViewDimension = .undefined, +}; + pub const TextureBindingLayout = extern struct { next_in_chain: ?*const ChainedStruct = null, sample_type: SampleType = SampleType.undefined, @@ -317,8 +356,8 @@ pub const Texture = opaque { return wgpuTextureGetWidth(self); } - // Unimplemented as of wgpu-native v25.0.2.1, - // see https://github.com/gfx-rs/wgpu-native/blob/d8238888998db26ceab41942f269da0fa32b890c/src/unimplemented.rs#L208 + // Unimplemented as of wgpu-native v29.0.0.0, + // see https://github.com/gfx-rs/wgpu-native/blob/d2e3330ade4ae1bb238d76b485926f067e7ee64c/src/unimplemented.rs // pub inline fn setLabel(self: *Texture, label: []const u8) void { // wgpuTextureSetLabel(self, StringView.fromSlice(label)); // } diff --git a/tests/abi.zig b/tests/abi.zig new file mode 100644 index 0000000..e10f274 --- /dev/null +++ b/tests/abi.zig @@ -0,0 +1,200 @@ +const std = @import("std"); +const wgpu = @import("wgpu"); +const c = @import("wgpu-c"); + +fn cTypeName(comptime zig_name: []const u8) []const u8 { + if (std.mem.eql(u8, zig_name, "ColorAttachment")) + return "WGPURenderPassColorAttachment"; + if (std.mem.eql(u8, zig_name, "DepthStencilAttachment")) + return "WGPURenderPassDepthStencilAttachment"; + if (std.mem.eql(u8, zig_name, "EnumerateAdapterOptions")) + return "WGPUInstanceEnumerateAdapterOptions"; + if (std.mem.eql(u8, zig_name, "GetCurrentTextureStatus")) + return "WGPUSurfaceGetCurrentTextureStatus"; + if (std.mem.eql(u8, zig_name, "SampleType")) + return "WGPUTextureSampleType"; + if (std.mem.eql(u8, zig_name, "ViewDimension")) + return "WGPUTextureViewDimension"; + if (std.mem.eql(u8, zig_name, "WorkDoneStatus")) + return "WGPUQueueWorkDoneStatus"; + if (std.mem.startsWith(u8, zig_name, "WGPU")) + return zig_name; + return "WGPU" ++ zig_name; +} + +fn isEnumConstant( + comptime declaration_name: []const u8, + comptime zig_name: []const u8, + comptime c_name: []const u8, +) bool { + if (std.mem.endsWith(u8, declaration_name, "_Force32")) return false; + if (std.mem.startsWith(u8, declaration_name, c_name ++ "_")) return true; + if (std.mem.eql(u8, zig_name, "FeatureName") and + std.mem.startsWith(u8, declaration_name, "WGPUNativeFeature_")) + { + return true; + } + if (std.mem.eql(u8, zig_name, "TextureFormat") and + std.mem.startsWith(u8, declaration_name, "WGPUNativeTextureFormat_")) + { + return true; + } + if (std.mem.eql(u8, zig_name, "QueryType") and + std.mem.startsWith(u8, declaration_name, "WGPUNativeQueryType_")) + { + return true; + } + return false; +} + +test "pure Zig structs match the C ABI" { + comptime { + @setEvalBranchQuota(10_000_000); + for (std.meta.declarations(wgpu)) |declaration| { + const zig_declaration = @field(wgpu, declaration.name); + if (@TypeOf(zig_declaration) != type) continue; + + const c_name = cTypeName(declaration.name); + if (!@hasDecl(c, c_name)) continue; + + const ZigType = zig_declaration; + const CType = @field(c, c_name); + if (@TypeOf(CType) != type) continue; + + switch (@typeInfo(ZigType)) { + .@"struct", .@"union", .@"enum" => {}, + else => continue, + } + switch (@typeInfo(CType)) { + .@"struct", .@"union", .@"enum", .int => {}, + else => continue, + } + + if (@typeInfo(ZigType) == .@"enum") { + const zig_fields = @typeInfo(ZigType).@"enum".fields; + var c_values: [256]u64 = undefined; + var c_names: [256][]const u8 = undefined; + var c_value_count = 0; + for (std.meta.declarations(c)) |c_declaration| { + if (!isEnumConstant( + c_declaration.name, + declaration.name, + c_name, + )) continue; + const c_value = @field(c, c_declaration.name); + if (@TypeOf(c_value) == type) continue; + + c_values[c_value_count] = @intCast(c_value); + c_names[c_value_count] = c_declaration.name; + c_value_count += 1; + } + for ( + c_values[0..c_value_count], + c_names[0..c_value_count], + ) |c_value, c_declaration_name| { + var found = false; + for (zig_fields) |zig_field| { + const zig_value: u64 = @intFromEnum( + @field(ZigType, zig_field.name), + ); + if (zig_value == c_value) found = true; + } + if (!found) { + @compileError(std.fmt.comptimePrint( + "{s} is missing {s} ({d})", + .{ declaration.name, c_declaration_name, c_value }, + )); + } + } + for (zig_fields) |zig_field| { + const zig_value: u64 = @intFromEnum( + @field(ZigType, zig_field.name), + ); + var found = false; + for (c_values[0..c_value_count]) |c_value| { + if (zig_value == c_value) found = true; + } + if (!found) { + @compileError(std.fmt.comptimePrint( + "{s}.{s} ({d}) is not present in the C API", + .{ declaration.name, zig_field.name, zig_value }, + )); + } + } + } + + if (@sizeOf(ZigType) != @sizeOf(CType)) { + @compileError(std.fmt.comptimePrint( + "{s} has size {d}, but {s} has size {d}", + .{ + declaration.name, + @sizeOf(ZigType), + c_name, + @sizeOf(CType), + }, + )); + } + if (@alignOf(ZigType) != @alignOf(CType)) { + @compileError(std.fmt.comptimePrint( + "{s} has alignment {d}, but {s} has alignment {d}", + .{ + declaration.name, + @alignOf(ZigType), + c_name, + @alignOf(CType), + }, + )); + } + + if (@typeInfo(ZigType) == .@"struct" and + @typeInfo(CType) == .@"struct") + { + const zig_fields = @typeInfo(ZigType).@"struct".fields; + const c_fields = @typeInfo(CType).@"struct".fields; + if (zig_fields.len != c_fields.len) { + @compileError(std.fmt.comptimePrint( + "{s} has {d} fields, but {s} has {d}", + .{ + declaration.name, + zig_fields.len, + c_name, + c_fields.len, + }, + )); + } + for (zig_fields, 0..) |zig_field, index| { + if (index >= c_fields.len) continue; + const c_field = c_fields[index]; + if (@offsetOf(ZigType, zig_field.name) != + @offsetOf(CType, c_field.name)) + { + @compileError(std.fmt.comptimePrint( + "{s}.{s} has offset {d}, but {s}.{s} has offset {d}", + .{ + declaration.name, + zig_field.name, + @offsetOf(ZigType, zig_field.name), + c_name, + c_field.name, + @offsetOf(CType, c_field.name), + }, + )); + } + if (@sizeOf(zig_field.type) != @sizeOf(c_field.type)) { + @compileError(std.fmt.comptimePrint( + "{s}.{s} has size {d}, but {s}.{s} has size {d}", + .{ + declaration.name, + zig_field.name, + @sizeOf(zig_field.type), + c_name, + c_field.name, + @sizeOf(c_field.type), + }, + )); + } + } + } + } + } +} diff --git a/tests/build.zig b/tests/build.zig index 37a5df7..5b6806f 100644 --- a/tests/build.zig +++ b/tests/build.zig @@ -14,9 +14,30 @@ pub fn build(b: *std.Build) void { } unitTests(b, library, check_step); + abiTest(b, library, check_step); computeTests(b, library, check_step); } +fn abiTest( + b: *std.Build, + library: Library.Result, + check_step: *std.Build.Step, +) void { + const test_mod = b.createModule(.{ + .root_source_file = b.path("tests/abi.zig"), + .target = library.target, + .optimize = library.optimize, + }); + test_mod.addImport("wgpu", library.wgpu_mod); + test_mod.addImport("wgpu-c", library.wgpu_c_mod); + const test_exe = b.addTest(.{ + .name = "abi-test", + .root_module = test_mod, + }); + library.configureCompile(test_exe); + check_step.dependOn(&test_exe.step); +} + fn unitTests( b: *std.Build, library: Library.Result, diff --git a/tests/compute.zig b/tests/compute.zig index 2fd0330..d942da0 100644 --- a/tests/compute.zig +++ b/tests/compute.zig @@ -58,7 +58,7 @@ fn compute_collatz() ![4]u32 { const compute_pipeline = device.createComputePipeline(&wgpu.ComputePipelineDescriptor{ .label = wgpu.StringView.fromSlice("compute_pipeline"), - .compute = wgpu.ProgrammableStageDescriptor{ + .compute = wgpu.ComputeState{ .module = shader_module, .entry_point = wgpu.StringView.fromSlice("main"), }, @@ -126,7 +126,10 @@ fn compute_collatz() ![4]u32 { } test "compute functionality" { - const values = try compute_collatz(); + const values = compute_collatz() catch |err| switch (err) { + error.NoAdapter, error.NoDevice => return error.SkipZigTest, + else => return err, + }; try testing.expect(values[0] == 0); try testing.expect(values[1] == 1); diff --git a/tests/compute_c.zig b/tests/compute_c.zig index ab7943a..9f7eb6b 100644 --- a/tests/compute_c.zig +++ b/tests/compute_c.zig @@ -44,7 +44,7 @@ fn waitForCompletion(instance: wgpu.WGPUInstance, complete: *bool) void { } } -fn compute_collatz() [4]u32 { +fn compute_collatz() ![4]u32 { const numbers = [_]u32{ 1, 2, 3, 4 }; const numbers_size = @sizeOf(@TypeOf(numbers)); const numbers_length = numbers_size / @sizeOf(u32); @@ -64,6 +64,7 @@ fn compute_collatz() [4]u32 { }); waitForCompletion(instance, &request_complete); } + if (adapter == null) return error.NoAdapter; defer wgpu.wgpuAdapterRelease(adapter); var device: wgpu.WGPUDevice = null; @@ -78,26 +79,28 @@ fn compute_collatz() [4]u32 { }); waitForCompletion(instance, &request_complete); } + if (device == null) return error.NoDevice; defer wgpu.wgpuDeviceRelease(device); const queue = wgpu.wgpuDeviceGetQueue(device.?); defer wgpu.wgpuQueueRelease(queue); const compute_shader = @embedFile("./compute.wgsl"); + var shader_source = wgpu.WGPUShaderSourceWGSL{ + .chain = wgpu.WGPUChainedStruct{ + .sType = wgpu.WGPUSType_ShaderSourceWGSL, + }, + .code = wgpu.WGPUStringView{ + .data = compute_shader.ptr, + .length = compute_shader.len, + }, + }; const shader_module = wgpu.wgpuDeviceCreateShaderModule(device.?, &wgpu.WGPUShaderModuleDescriptor{ .label = wgpu.WGPUStringView{ .data = "compute.wgsl", .length = wgpu.WGPU_STRLEN, // Treat as null-terminated string }, - .nextInChain = @ptrCast(&wgpu.WGPUShaderSourceWGSL{ - .chain = wgpu.WGPUChainedStruct{ - .sType = wgpu.WGPUSType_ShaderSourceWGSL, - }, - .code = wgpu.WGPUStringView{ - .data = compute_shader.ptr, - .length = compute_shader.len, - }, - }), + .nextInChain = &shader_source.chain, }); defer wgpu.wgpuShaderModuleRelease(shader_module); @@ -128,7 +131,7 @@ fn compute_collatz() [4]u32 { .data = "compute_pipeline", .length = wgpu.WGPU_STRLEN, }, - .compute = wgpu.WGPUProgrammableStageDescriptor{ + .compute = wgpu.WGPUComputeState{ .module = shader_module, .entryPoint = wgpu.WGPUStringView{ .data = "main", @@ -213,7 +216,7 @@ fn compute_collatz() [4]u32 { } test "compute functionality" { - const values = compute_collatz(); + const values = compute_collatz() catch return error.SkipZigTest; try testing.expect(values[0] == 0); try testing.expect(values[1] == 1);