363: Extended remote example r=kvark a=kvark

The remote example is now successfully able to request an adapter and to clean up the IDs.
In the near future, we need to change the example so that the server is run on a different thread...

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot]andDzmitry Malyshau authored and GitHub committed 2019-10-30 03:24:05 +00:00
commit b8d26c9186
6 files changed
+54 -13

No files matched your search

+30 -4
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;
}
+10 -4
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
+3 -2
View File
@@ -775,10 +775,11 @@ impl<B: hal::Backend> Device<B> {
}
}
pub(crate) fn destroy_self(self) {
pub(crate) fn dispose(self) {
self.com_allocator.destroy(&self.raw);
let desc_alloc = self.desc_allocator.into_inner();
unsafe {
self.desc_allocator.lock().cleanup(&self.raw);
desc_alloc.dispose(&self.raw);
}
}
}
+1 -1
View File
@@ -445,7 +445,7 @@ impl<B: hal::Backend> Drop for Hub<B> {
// self.adapters
for (_, (device, _)) in devices.map.drain() {
device.destroy_self();
device.dispose();
}
}
}
+1
View File
@@ -73,6 +73,7 @@ impl Instance {
}
#[cfg(any(target_os = "ios", target_os = "macos"))]
{
let _ = surface;
//self.metal.destroy_surface(surface.metal);
}
#[cfg(windows)]
+9 -2
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]