Skip to content

Update API according to the upstream spec #285

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

Merged
merged 2 commits into from
Aug 17, 2019
Merged
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
cargo build --manifest-path wgpu-remote/Cargo.toml --features $(FEATURE_RUST)

$(FFI_DIR)/wgpu.h: wgpu-native/cbindgen.toml $(WILDCARD_WGPU_NATIVE)
rustup run nightly cbindgen wgpu-native > $(FFI_DIR)/wgpu.h
rustup run nightly cbindgen -o $(FFI_DIR)/wgpu.h wgpu-native

$(FFI_DIR)/wgpu-remote.h: wgpu-remote/cbindgen.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
rustup run nightly cbindgen wgpu-remote > $(FFI_DIR)/wgpu-remote.h
rustup run nightly cbindgen -o $(FFI_DIR)/wgpu-remote.h wgpu-remote

example-compute: lib-native $(FFI_DIR)/wgpu.h examples/compute/main.c
cd examples/compute && $(CREATE_BUILD_DIR) && cd build && cmake .. -DBACKEND=$(FEATURE_RUST) $(GENERATOR_PLATFORM) && cmake --build .
Expand Down
32 changes: 12 additions & 20 deletions examples/compute/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define BIND_GROUP_LAYOUTS_LENGTH (1)

int main(
int argc,
int argc,
char *argv[]) {

if (argc != 5) {
Expand All @@ -32,28 +32,20 @@ int main(
uint32_t numbers_length = size / sizeof(uint32_t);

WGPUInstanceId instance = wgpu_create_instance();

WGPUAdapterId adapter = wgpu_instance_get_adapter(instance,
&(WGPUAdapterDescriptor){
.power_preference = WGPUPowerPreference_LowPower,
});

WGPUDeviceId device = wgpu_adapter_request_device(adapter,
&(WGPUDeviceDescriptor){
.extensions = NULL
});
WGPUAdapterId adapter = wgpu_instance_request_adapter(instance, NULL);
WGPUDeviceId device = wgpu_adapter_request_device(adapter, NULL);

uint8_t *staging_memory;

WGPUBufferId staging_buffer = wgpu_device_create_buffer_mapped(device,
&(WGPUBufferDescriptor){
.size = size,
.size = size,
.usage = WGPUBufferUsage_MAP_READ},
&staging_memory);

memcpy((uint32_t *) staging_memory, numbers, size);
wgpu_buffer_unmap(staging_buffer);

wgpu_buffer_unmap(staging_buffer);

WGPUBufferId storage_buffer = wgpu_device_create_buffer(device,
&(WGPUBufferDescriptor){
Expand All @@ -72,14 +64,14 @@ int main(
WGPUBindingResource resource = {
.tag = WGPUBindingResource_Buffer,
.buffer = (WGPUBufferBinding){
.buffer = storage_buffer,
.size = size,
.buffer = storage_buffer,
.size = size,
.offset = 0}};

WGPUBindGroupId bind_group = wgpu_device_create_bind_group(device,
&(WGPUBindGroupDescriptor){.layout = bind_group_layout,
.bindings = &(WGPUBindGroupBinding){
.binding = 0,
.binding = 0,
.resource = resource},
.bindings_length = BINDINGS_LENGTH});

Expand All @@ -100,7 +92,7 @@ int main(
wgpu_device_create_compute_pipeline(device,
&(WGPUComputePipelineDescriptor){
.layout = pipeline_layout,
.compute_stage = (WGPUPipelineStageDescriptor){
.compute_stage = (WGPUProgrammableStageDescriptor){
.module = shader_module,
.entry_point = "main"
}});
Expand All @@ -126,7 +118,7 @@ int main(

WGPUQueueId queue = wgpu_device_get_queue(device);

WGPUCommandBufferId command_buffer = wgpu_command_encoder_finish(encoder);
WGPUCommandBufferId command_buffer = wgpu_command_encoder_finish(encoder, NULL);

wgpu_queue_submit(queue, &command_buffer, 1);

Expand All @@ -135,4 +127,4 @@ int main(
wgpu_device_poll(device, true);

return 0;
}
}
12 changes: 6 additions & 6 deletions examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
int main() {
WGPUInstanceId instance = wgpu_create_instance();

WGPUAdapterId adapter = wgpu_instance_get_adapter(instance,
&(WGPUAdapterDescriptor){
WGPUAdapterId adapter = wgpu_instance_request_adapter(instance,
&(WGPURequestAdapterOptions){
.power_preference = WGPUPowerPreference_LowPower,
});

Expand Down Expand Up @@ -88,17 +88,17 @@ int main() {
&(WGPURenderPipelineDescriptor){
.layout = pipeline_layout,
.vertex_stage =
(WGPUPipelineStageDescriptor){
(WGPUProgrammableStageDescriptor){
.module = vertex_shader,
.entry_point = "main",
},
.fragment_stage =
&(WGPUPipelineStageDescriptor){
&(WGPUProgrammableStageDescriptor){
.module = fragment_shader,
.entry_point = "main",
},
.rasterization_state =
(WGPURasterizationStateDescriptor){
&(WGPURasterizationStateDescriptor){
.front_face = WGPUFrontFace_Ccw,
.cull_mode = WGPUCullMode_None,
.depth_bias = 0,
Expand Down Expand Up @@ -238,7 +238,7 @@ int main() {
wgpu_render_pass_draw(rpass, 3, 1, 0, 0);
WGPUQueueId queue = wgpu_device_get_queue(device);
wgpu_render_pass_end_pass(rpass);
WGPUCommandBufferId cmd_buf = wgpu_command_encoder_finish(cmd_encoder);
WGPUCommandBufferId cmd_buf = wgpu_command_encoder_finish(cmd_encoder, NULL);
wgpu_queue_submit(queue, &cmd_buf, 1);
wgpu_swap_chain_present(swap_chain);

Expand Down
5 changes: 3 additions & 2 deletions ffi/wgpu-remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct {

typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
} WGPURequestAdapterOptions;

typedef struct {
WGPUClientFactory *factory;
Expand All @@ -63,7 +63,8 @@ WGPUClient *wgpu_client_create(const WGPUClientFactory *factory);

void wgpu_client_destroy(const WGPUClientFactory *factory, WGPUClient *client);

WGPUAdapterId wgpu_client_get_adapter(const WGPUClient *client, const WGPUAdapterDescriptor *desc);
WGPUAdapterId wgpu_client_get_adapter(const WGPUClient *client,
const WGPURequestAdapterOptions *desc);

WGPUInfrastructure wgpu_initialize(void);

Expand Down
Loading