Extended remote example

This commit is contained in:
Dzmitry Malyshau 2019-10-29 13:31:40 -04:00
parent 41132a3762
commit 4635f1eb07
3 changed files with 49 additions and 10 deletions

View File

@ -6,23 +6,49 @@
int main() {
WGPUInfrastructure infra = wgpu_client_new();
WGPUClient *client = infra.client;
if (!infra.client || infra.error) {
printf("Cannot initialize WGPU client: %s", infra.error);
if (!client || infra.error) {
printf("Cannot initialize WGPU client: %s\n", infra.error);
return 1;
}
WGPUGlobal* server = wgpu_server_new();
if (!server) {
printf("Cannot initialize WGPU client: %s", server);
printf("Cannot initialize WGPU client: %s\n", server);
return 1;
}
WGPUAdapterId adapterId = 0;
{
WGPUAdapterId ids[10];
int count = wgpu_client_make_adapter_ids(client, ids, 10);
WGPURequestAdapterOptions options = {
.power_preference = WGPUPowerPreference_LowPower,
.backends = 2 | 4 | 8,
};
char index = wgpu_server_instance_request_adapter(server, &options, ids, count);
if (index < 0) {
printf("No available GPU adapters!\n");
return 2;
}
wgpu_client_kill_adapter_ids(client, ids, index);
wgpu_client_kill_adapter_ids(client, ids+index+1, count-index-1);
adapterId = ids[index];
}
//TODO: do something meaningful
if (adapterId) {
//wgpu_server_destroy_adapter()
wgpu_client_kill_adapter_ids(client, &adapterId, 1);
}
wgpu_server_delete(server);
wgpu_client_delete(infra.client);
wgpu_client_delete(client);
printf("Done\n");
return 0;
}

View File

@ -108,11 +108,17 @@ void wgpu_server_device_destroy(const WGPUGlobal *aGlobal,
WGPUDeviceId aSelfId)
WGPU_FUNC;
/**
* Request an adapter according to the specified options.
* Provide the list of IDs to pick from.
*
* Returns the index in this list, or -1 if unable to pick.
*/
WGPU_INLINE
WGPUAdapterId wgpu_server_instance_request_adapter(const WGPUGlobal *aGlobal,
const WGPURequestAdapterOptions *aDesc,
const WGPUAdapterId *aIds,
uintptr_t aIdLength)
int8_t wgpu_server_instance_request_adapter(const WGPUGlobal *aGlobal,
const WGPURequestAdapterOptions *aDesc,
const WGPUAdapterId *aIds,
uintptr_t aIdLength)
WGPU_FUNC;
WGPU_INLINE

View File

@ -17,15 +17,22 @@ pub extern "C" fn wgpu_server_delete(global: *mut wgn::Global) {
log::info!("\t...done");
}
/// Request an adapter according to the specified options.
/// Provide the list of IDs to pick from.
///
/// Returns the index in this list, or -1 if unable to pick.
#[no_mangle]
pub extern "C" fn wgpu_server_instance_request_adapter(
global: &wgn::Global,
desc: &wgn::RequestAdapterOptions,
ids: *const wgn::AdapterId,
id_length: usize,
) -> wgn::AdapterId {
) -> i8 {
let ids = unsafe { slice::from_raw_parts(ids, id_length) };
wgn::request_adapter(global, desc, ids).unwrap()
match wgn::request_adapter(global, desc, ids) {
Some(id) => ids.iter().position(|&i| i == id).unwrap() as i8,
None => -1,
}
}
#[no_mangle]