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 9 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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"

[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
51 changes: 33 additions & 18 deletions examples/capture/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ const size_t IMAGE_HEIGHT = 200;
const size_t COPY_BYTES_PER_ROW_ALIGNMENT = 256;

static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, char const *message,
void *userdata) {
WGPUAdapter adapter, WGPUStringView message,
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) {
WGPUDevice device, WGPUStringView message,
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,
WGPUStringView 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 All @@ -86,7 +99,7 @@ int main(int argc, char *argv[]) {

WGPUBuffer output_buffer = wgpuDeviceCreateBuffer(
device, &(const WGPUBufferDescriptor){
.label = "output_buffer",
.label = {"output_buffer", WGPU_STRLEN},
.size = buffer_size,
.usage = WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst,
.mappedAtCreation = false,
Expand All @@ -102,7 +115,7 @@ int main(int argc, char *argv[]) {
WGPUTexture texture = wgpuDeviceCreateTexture(
device,
&(const WGPUTextureDescriptor){
.label = "texture",
.label = {"texture", WGPU_STRLEN},
.size = texture_extent,
.mipLevelCount = 1,
.sampleCount = 1,
Expand All @@ -116,13 +129,13 @@ int main(int argc, char *argv[]) {

WGPUCommandEncoder command_encoder = wgpuDeviceCreateCommandEncoder(
device, &(const WGPUCommandEncoderDescriptor){
.label = "command_encoder",
.label = {"command_encoder", WGPU_STRLEN},
});
assert(command_encoder);

WGPURenderPassEncoder render_pass_encoder = wgpuCommandEncoderBeginRenderPass(
command_encoder, &(const WGPURenderPassDescriptor){
.label = "rende_pass_encoder",
.label = {"rende_pass_encoder", WGPU_STRLEN},
.colorAttachmentCount = 1,
.colorAttachments =
(const WGPURenderPassColorAttachment[]){
Expand Down Expand Up @@ -167,14 +180,16 @@ int main(int argc, char *argv[]) {

WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(
command_encoder, &(const WGPUCommandBufferDescriptor){
.label = "command_buffer",
.label = {"command_buffer", WGPU_STRLEN},
});
assert(command_buffer);

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
55 changes: 34 additions & 21 deletions examples/compute/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
#define LOG_PREFIX "[compute]"

static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, char const *message,
void *userdata) {
WGPUAdapter adapter, WGPUStringView message,
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) {
WGPUDevice device, WGPUStringView message,
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,
WGPUStringView 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 All @@ -56,7 +67,7 @@ int main(int argc, char *argv[]) {

WGPUBuffer staging_buffer = wgpuDeviceCreateBuffer(
device, &(const WGPUBufferDescriptor){
.label = "staging_buffer",
.label = {"staging_buffer", WGPU_STRLEN},
.usage = WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst,
.size = numbers_size,
.mappedAtCreation = false,
Expand All @@ -65,7 +76,7 @@ int main(int argc, char *argv[]) {

WGPUBuffer storage_buffer = wgpuDeviceCreateBuffer(
device, &(const WGPUBufferDescriptor){
.label = "storage_buffer",
.label = {"storage_buffer", WGPU_STRLEN},
.usage = WGPUBufferUsage_Storage | WGPUBufferUsage_CopyDst |
WGPUBufferUsage_CopySrc,
.size = numbers_size,
Expand All @@ -75,11 +86,11 @@ int main(int argc, char *argv[]) {

WGPUComputePipeline compute_pipeline = wgpuDeviceCreateComputePipeline(
device, &(const WGPUComputePipelineDescriptor){
.label = "compute_pipeline",
.label = {"compute_pipeline", WGPU_STRLEN},
.compute =
(const WGPUProgrammableStageDescriptor){
.module = shader_module,
.entryPoint = "main",
.entryPoint = {"main", WGPU_STRLEN},
},
});
assert(compute_pipeline);
Expand All @@ -90,7 +101,7 @@ int main(int argc, char *argv[]) {

WGPUBindGroup bind_group = wgpuDeviceCreateBindGroup(
device, &(const WGPUBindGroupDescriptor){
.label = "bind_group",
.label = {"bind_group", WGPU_STRLEN},
.layout = bind_group_layout,
.entryCount = 1,
.entries =
Expand All @@ -107,14 +118,14 @@ int main(int argc, char *argv[]) {

WGPUCommandEncoder command_encoder = wgpuDeviceCreateCommandEncoder(
device, &(const WGPUCommandEncoderDescriptor){
.label = "command_encoder",
.label = {"command_encoder", WGPU_STRLEN},
});
assert(command_encoder);

WGPUComputePassEncoder compute_pass_encoder =
wgpuCommandEncoderBeginComputePass(command_encoder,
&(const WGPUComputePassDescriptor){
.label = "compute_pass",
.label = {"compute_pass", WGPU_STRLEN},
});
assert(compute_pass_encoder);

Expand All @@ -131,15 +142,17 @@ int main(int argc, char *argv[]) {

WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(
command_encoder, &(const WGPUCommandBufferDescriptor){
.label = "command_buffer",
.label = {"command_buffer", WGPU_STRLEN},
});
assert(command_buffer);

wgpuQueueWriteBuffer(queue, storage_buffer, 0, &numbers, numbers_size);
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
11 changes: 6 additions & 5 deletions examples/enumerate_adapters/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ int main(int argc, char *argv[]) {
wgpuAdapterGetInfo(adapter, &info);
printf("WGPUAdapter: %d\n", i);
printf("WGPUAdapterInfo {\n"
"\tvendor: %s\n"
"\tarchitecture: %s\n"
"\tdevice: %s\n"
"\tdescription: %s\n"
"\tvendor: %.*s\n"
"\tarchitecture: %.*s\n"
"\tdevice: %.*s\n"
"\tdescription: %.*s\n"
"\tbackendType: %#.8x\n"
"\tadapterType: %#.8x\n"
"\tvendorID: %" PRIu32 "\n"
"\tdeviceID: %" PRIu32 "\n"
"}\n",
info.vendor, info.architecture, info.device, info.description,
(int) info.vendor.length, info.vendor.data, (int) info.architecture.length, info.architecture.data,
(int) info.device.length, info.device.data, (int) info.description.length, info.description.data,
info.backendType, info.adapterType, info.vendorID, info.deviceID);

wgpuAdapterInfoFreeMembers(info);
Expand Down
24 changes: 12 additions & 12 deletions examples/framework/framework.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "framework.h"

static void log_callback(WGPULogLevel level, char const *message,
static void log_callback(WGPULogLevel level, WGPUStringView message,
void *userdata) {
UNUSED(userdata)
char *level_str;
Expand All @@ -23,7 +23,7 @@ static void log_callback(WGPULogLevel level, char const *message,
default:
level_str = "unknown_level";
}
fprintf(stderr, "[wgpu] [%s] %s\n", level_str, message);
fprintf(stderr, "[wgpu] [%s] %.*s\n", level_str, (int) message.length, message.data);
}

void frmwrk_setup_logging(WGPULogLevel level) {
Expand Down Expand Up @@ -64,15 +64,15 @@ WGPUShaderModule frmwrk_load_shader_module(WGPUDevice device,

shader_module = wgpuDeviceCreateShaderModule(
device, &(const WGPUShaderModuleDescriptor){
.label = name,
.label = {name, WGPU_STRLEN},
.nextInChain =
(const WGPUChainedStruct *)&(
const WGPUShaderModuleWGSLDescriptor){
const WGPUShaderSourceWGSL){
.chain =
(const WGPUChainedStruct){
.sType = WGPUSType_ShaderModuleWGSLDescriptor,
.sType = WGPUSType_ShaderSourceWGSL,
},
.code = buf,
.code = {buf, WGPU_STRLEN},
},
});

Expand All @@ -92,7 +92,7 @@ WGPUBuffer frmwrk_device_create_buffer_init(
assert(descriptor);
if (descriptor->content_size == 0) {
return wgpuDeviceCreateBuffer(device, &(WGPUBufferDescriptor){
.label = descriptor->label,
.label = {descriptor->label, WGPU_STRLEN},
.size = 0,
.usage = descriptor->usage,
.mappedAtCreation = false,
Expand All @@ -105,7 +105,7 @@ WGPUBuffer frmwrk_device_create_buffer_init(
MAX((unpadded_size + align_mask) & ~align_mask, COPY_BUFFER_ALIGNMENT);
WGPUBuffer buffer =
wgpuDeviceCreateBuffer(device, &(WGPUBufferDescriptor){
.label = descriptor->label,
.label = {descriptor->label, WGPU_STRLEN},
.size = padded_size,
.usage = descriptor->usage,
.mappedAtCreation = true,
Expand Down Expand Up @@ -168,10 +168,10 @@ void frmwrk_print_global_report(WGPUGlobalReport report) {
void frmwrk_print_adapter_info(WGPUAdapter adapter) {
struct WGPUAdapterInfo info = {0};
wgpuAdapterGetInfo(adapter, &info);
printf("description: %s\n", info.description);
printf("vendor: %s\n", info.vendor);
printf("architecture: %s\n", info.architecture);
printf("device: %s\n", info.device);
printf("description: %.*s\n", (int) info.description.length, info.description.data);
printf("vendor: %.*s\n", (int) info.vendor.length, info.vendor.data);
printf("architecture: %.*s\n", (int) info.architecture.length, info.architecture.data);
printf("device: %.*s\n", (int) info.device.length, info.device.data);
printf("backend type: %u\n", info.backendType);
printf("adapter type: %u\n", info.adapterType);
printf("vendorID: %x\n", info.vendorID);
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
Loading
Loading