Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update library to latest webgpu-native headers #427

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ log = "0.4"
thiserror = "1"
parking_lot = "0.12"
smallvec = "1"
bitflags = "2.6.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to be able to refer to bitflags types for the from_u64_bits helper.


[build-dependencies]
bindgen = "0.70"
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ fn main() {
.prepend_enum_name(false)
.size_t_is_usize(true)
.ignore_functions()
.layout_tests(true);
.layout_tests(true)
.clang_macro_fallback();

for (old_name, new_name) in types_to_rename {
let line = format!("pub type {old_name} = *const crate::{new_name};");
Expand Down
37 changes: 26 additions & 11 deletions examples/capture/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ const size_t COPY_BYTES_PER_ROW_ALIGNMENT = 256;

static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, char const *message,
void *userdata) {
void *userdata1, void *userdata2) {
UNUSED(status)
UNUSED(message)
*(WGPUAdapter *)userdata = adapter;
UNUSED(userdata2)
*(WGPUAdapter *)userdata1 = adapter;
}
static void handle_request_device(WGPURequestDeviceStatus status,
WGPUDevice device, char const *message,
void *userdata) {
void *userdata1, void *userdata2) {
UNUSED(status)
UNUSED(message)
*(WGPUDevice *)userdata = device;
UNUSED(userdata2)
*(WGPUDevice *)userdata1 = device;
}
static void handle_buffer_map(WGPUBufferMapAsyncStatus status, void *userdata) {
UNUSED(userdata)
static void handle_buffer_map(WGPUMapAsyncStatus status,
char const *message,
void *userdata1, void *userdata2) {
UNUSED(message)
UNUSED(userdata1)
UNUSED(userdata2)
printf(LOG_PREFIX " buffer_map status=%#.8x\n", status);
}

Expand Down Expand Up @@ -67,14 +73,21 @@ int main(int argc, char *argv[]) {
assert(instance);

WGPUAdapter adapter = NULL;
wgpuInstanceRequestAdapter(instance, NULL, handle_request_adapter,
(void *)&adapter);
wgpuInstanceRequestAdapter(instance, NULL,
(const WGPURequestAdapterCallbackInfo){
.callback = handle_request_adapter,
.userdata1 = &adapter
});
assert(adapter);

WGPUDevice device = NULL;
wgpuAdapterRequestDevice(adapter, NULL, handle_request_device,
(void *)&device);
wgpuAdapterRequestDevice(adapter, NULL,
(const WGPURequestDeviceCallbackInfo){
.callback = handle_request_device,
.userdata1 = &device
});
assert(device);

WGPUQueue queue = wgpuDeviceGetQueue(device);
assert(queue);

Expand Down Expand Up @@ -174,7 +187,9 @@ int main(int argc, char *argv[]) {
wgpuQueueSubmit(queue, 1, (const WGPUCommandBuffer[]){command_buffer});

wgpuBufferMapAsync(output_buffer, WGPUMapMode_Read, 0, buffer_size,
handle_buffer_map, NULL);
(const WGPUBufferMapCallbackInfo){
.callback = handle_buffer_map
});
wgpuDevicePoll(device, true, NULL);

uint8_t *buf =
Expand Down
35 changes: 24 additions & 11 deletions examples/compute/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@

static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, char const *message,
void *userdata) {
void *userdata1, void *userdata2) {
UNUSED(status)
UNUSED(message)
*(WGPUAdapter *)userdata = adapter;
UNUSED(userdata2)
*(WGPUAdapter *)userdata1 = adapter;
}
static void handle_request_device(WGPURequestDeviceStatus status,
WGPUDevice device, char const *message,
void *userdata) {
void *userdata1, void *userdata2) {
UNUSED(status)
UNUSED(message)
*(WGPUDevice *)userdata = device;
UNUSED(userdata2)
*(WGPUDevice *)userdata1 = device;
}
static void handle_buffer_map(WGPUBufferMapAsyncStatus status, void *userdata) {
UNUSED(userdata)
static void handle_buffer_map(WGPUMapAsyncStatus status,
char const * message,
void *userdata1, void *userdata2) {
UNUSED(userdata1)
UNUSED(userdata2)
printf(LOG_PREFIX " buffer_map status=%#.8x\n", status);
}

Expand All @@ -38,13 +43,19 @@ int main(int argc, char *argv[]) {
assert(instance);

WGPUAdapter adapter = NULL;
wgpuInstanceRequestAdapter(instance, NULL, handle_request_adapter,
(void *)&adapter);
wgpuInstanceRequestAdapter(instance, NULL,
(const WGPURequestAdapterCallbackInfo){
.callback = handle_request_adapter,
.userdata1 = &adapter
});
assert(adapter);

WGPUDevice device = NULL;
wgpuAdapterRequestDevice(adapter, NULL, handle_request_device,
(void *)&device);
wgpuAdapterRequestDevice(adapter, NULL,
(const WGPURequestDeviceCallbackInfo){
.callback = handle_request_device,
.userdata1 = &device
});
assert(device);

WGPUQueue queue = wgpuDeviceGetQueue(device);
Expand Down Expand Up @@ -139,7 +150,9 @@ int main(int argc, char *argv[]) {
wgpuQueueSubmit(queue, 1, &command_buffer);

wgpuBufferMapAsync(staging_buffer, WGPUMapMode_Read, 0, numbers_size,
handle_buffer_map, NULL);
(const WGPUBufferMapCallbackInfo){
.callback = handle_buffer_map
});
wgpuDevicePoll(device, true, NULL);

uint32_t *buf =
Expand Down
4 changes: 2 additions & 2 deletions examples/framework/framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ WGPUShaderModule frmwrk_load_shader_module(WGPUDevice device,
.label = name,
.nextInChain =
(const WGPUChainedStruct *)&(
const WGPUShaderModuleWGSLDescriptor){
const WGPUShaderSourceWGSL){
.chain =
(const WGPUChainedStruct){
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
.sType = WGPUSType_ShaderSourceWGSL,
},
.code = buf,
},
Expand Down
2 changes: 1 addition & 1 deletion examples/framework/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

typedef struct frmwrk_buffer_init_descriptor {
WGPU_NULLABLE char const *label;
WGPUBufferUsageFlags usage;
WGPUBufferUsage usage;
void *content;
size_t content_size;
} frmwrk_buffer_init_descriptor;
Expand Down
65 changes: 35 additions & 30 deletions examples/texture_arrays/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ struct demo {

static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, char const *message,
void *userdata) {
void *userdata1, void *userdata2) {
UNUSED(userdata2)
if (status == WGPURequestAdapterStatus_Success) {
struct demo *demo = userdata;
struct demo *demo = userdata1;
demo->adapter = adapter;
} else {
printf(LOG_PREFIX " request_adapter status=%#.8x message=%s\n", status,
Expand All @@ -38,9 +39,10 @@ static void handle_request_adapter(WGPURequestAdapterStatus status,
}
static void handle_request_device(WGPURequestDeviceStatus status,
WGPUDevice device, char const *message,
void *userdata) {
void *userdata1, void *userdata2) {
UNUSED(userdata2)
if (status == WGPURequestDeviceStatus_Success) {
struct demo *demo = userdata;
struct demo *demo = userdata1;
demo->device = device;
} else {
printf(LOG_PREFIX " request_device status=%#.8x message=%s\n", status,
Expand Down Expand Up @@ -147,10 +149,10 @@ int main(int argc, char *argv[]) {
&(const WGPUSurfaceDescriptor){
.nextInChain =
(const WGPUChainedStruct *)&(
const WGPUSurfaceDescriptorFromMetalLayer){
const WGPUSurfaceSourceMetalLayer){
.chain =
(const WGPUChainedStruct){
.sType = WGPUSType_SurfaceDescriptorFromMetalLayer,
.sType = WGPUSType_SurfaceSourceMetalLayer,
},
.layer = metal_layer,
},
Expand All @@ -165,10 +167,10 @@ int main(int argc, char *argv[]) {
&(const WGPUSurfaceDescriptor){
.nextInChain =
(const WGPUChainedStruct *)&(
const WGPUSurfaceDescriptorFromXlibWindow){
const WGPUSurfaceSourceXlibWindow){
.chain =
(const WGPUChainedStruct){
.sType = WGPUSType_SurfaceDescriptorFromXlibWindow,
.sType = WGPUSType_SurfaceSourceXlibWindow,
},
.display = x11_display,
.window = x11_window,
Expand All @@ -183,11 +185,11 @@ int main(int argc, char *argv[]) {
&(const WGPUSurfaceDescriptor){
.nextInChain =
(const WGPUChainedStruct *)&(
const WGPUSurfaceDescriptorFromWaylandSurface){
const WGPUSurfaceSourceWaylandSurface){
.chain =
(const WGPUChainedStruct){
.sType =
WGPUSType_SurfaceDescriptorFromWaylandSurface,
WGPUSType_SurfaceSourceWaylandSurface,
},
.display = wayland_display,
.surface = wayland_surface,
Expand All @@ -203,10 +205,10 @@ int main(int argc, char *argv[]) {
&(const WGPUSurfaceDescriptor){
.nextInChain =
(const WGPUChainedStruct *)&(
const WGPUSurfaceDescriptorFromWindowsHWND){
const WGPUSurfaceSourceWindowsHWND){
.chain =
(const WGPUChainedStruct){
.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND,
.sType = WGPUSType_SurfaceSourceWindowsHWND,
},
.hinstance = hinstance,
.hwnd = hwnd,
Expand All @@ -222,22 +224,22 @@ int main(int argc, char *argv[]) {
&(const WGPURequestAdapterOptions){
.compatibleSurface = demo.surface,
},
handle_request_adapter, &demo);
(const WGPURequestAdapterCallbackInfo){
.callback = handle_request_adapter,
.userdata1 = &demo
});
assert(demo.adapter);

WGPUSurfaceCapabilities surface_capabilities = {0};
wgpuSurfaceGetCapabilities(demo.surface, demo.adapter, &surface_capabilities);

size_t adapter_feature_count =
wgpuAdapterEnumerateFeatures(demo.adapter, NULL);
WGPUFeatureName *adapter_features = (WGPUFeatureName *)malloc(
sizeof(WGPUFeatureName) * adapter_feature_count);
wgpuAdapterEnumerateFeatures(demo.adapter, adapter_features);
WGPUSupportedFeatures adapter_features = {0};
wgpuAdapterGetFeatures(demo.adapter, &adapter_features);

bool adapter_has_required_features = false;
bool adapter_has_optional_features = false;
for (size_t i = 0; i < adapter_feature_count; i++) {
switch ((uint32_t)adapter_features[i]) {
for (size_t i = 0; i < adapter_features.featureCount; i++) {
switch ((uint32_t)adapter_features.features[i]) {
case WGPUNativeFeature_TextureBindingArray:
adapter_has_required_features = true;
break;
Expand All @@ -248,7 +250,7 @@ int main(int argc, char *argv[]) {
}
assert(
adapter_has_required_features /* Adapter must support WGPUNativeFeature_TextureBindingArray feature for this example */);
free(adapter_features);
wgpuSupportedFeaturesFreeMembers(adapter_features);

WGPUFeatureName required_device_features[2] = {
(WGPUFeatureName)WGPUNativeFeature_TextureBindingArray,
Expand All @@ -260,13 +262,15 @@ int main(int argc, char *argv[]) {
required_device_feature_count++;
}

wgpuAdapterRequestDevice(
demo.adapter,
&(const WGPUDeviceDescriptor){
.requiredFeatureCount = required_device_feature_count,
.requiredFeatures = required_device_features,
},
handle_request_device, &demo);
wgpuAdapterRequestDevice(demo.adapter,
&(const WGPUDeviceDescriptor){
.requiredFeatureCount = required_device_feature_count,
.requiredFeatures = required_device_features,
},
(const WGPURequestDeviceCallbackInfo){
.callback = handle_request_device,
.userdata1 = &demo
});
assert(demo.device);

WGPUQueue queue = wgpuDeviceGetQueue(demo.device);
Expand Down Expand Up @@ -648,8 +652,9 @@ int main(int argc, char *argv[]) {
WGPUSurfaceTexture surface_texture;
wgpuSurfaceGetCurrentTexture(demo.surface, &surface_texture);
switch (surface_texture.status) {
case WGPUSurfaceGetCurrentTextureStatus_Success:
// All good, could check for `surface_texture.suboptimal` here.
case WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal:
case WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal:
// All good, could handle suboptimal here
break;
case WGPUSurfaceGetCurrentTextureStatus_Timeout:
case WGPUSurfaceGetCurrentTextureStatus_Outdated:
Expand Down
Loading
Loading