From 7f3036449bf86212e92abebd8b046e39f736018c Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 26 Feb 2020 13:49:56 +0000 Subject: [PATCH] Bug 1614702 - WebGPU textures, texture views, and samplers r=jgilbert,webidl,smaug this change adds an ability to create WebGPU textures, views, and samplers Differential Revision: https://phabricator.services.mozilla.com/D63595 [ghsync] From https://hg.mozilla.org/mozilla-central/rev/7d59549f2fda3aed3927ab49b940d9024e161798 --- wgpu-remote/cbindgen.toml | 1 + wgpu-remote/src/lib.rs | 76 +++++++++++++++++++++++++++++++++++++++ wgpu-remote/src/server.rs | 54 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/wgpu-remote/cbindgen.toml b/wgpu-remote/cbindgen.toml index 9a514af18f..12a84cef42 100644 --- a/wgpu-remote/cbindgen.toml +++ b/wgpu-remote/cbindgen.toml @@ -40,6 +40,7 @@ derive_eq = true [enum] prefix_with_name = true derive_helper_methods = true +add_sentinel = true [macro_expansion] bitflags = true diff --git a/wgpu-remote/src/lib.rs b/wgpu-remote/src/lib.rs index d48f1327ef..c0b53585c3 100644 --- a/wgpu-remote/src/lib.rs +++ b/wgpu-remote/src/lib.rs @@ -32,6 +32,9 @@ struct IdentityHub { shader_modules: IdentityManager, compute_pipelines: IdentityManager, render_pipelines: IdentityManager, + textures: IdentityManager, + texture_views: IdentityManager, + samplers: IdentityManager, } #[derive(Debug, Default)] @@ -179,6 +182,79 @@ pub extern "C" fn wgpu_client_kill_buffer_id(client: &Client, id: id::BufferId) .free(id) } +#[no_mangle] +pub extern "C" fn wgpu_client_make_texture_id(client: &Client, device_id: id::DeviceId) -> id::TextureId { + let backend = device_id.backend(); + client + .identities + .lock() + .select(backend) + .textures + .alloc(backend) +} + +#[no_mangle] +pub extern "C" fn wgpu_client_kill_texture_id( + client: &Client, + id: id::TextureId, +) { + client + .identities + .lock() + .select(id.backend()) + .textures + .free(id) +} + + +#[no_mangle] +pub extern "C" fn wgpu_client_make_texture_view_id(client: &Client, device_id: id::DeviceId) -> id::TextureViewId { + let backend = device_id.backend(); + client + .identities + .lock() + .select(backend) + .texture_views + .alloc(backend) +} + +#[no_mangle] +pub extern "C" fn wgpu_client_kill_texture_view_id( + client: &Client, + id: id::TextureViewId, +) { + client + .identities + .lock() + .select(id.backend()) + .texture_views + .free(id) +} + +#[no_mangle] +pub extern "C" fn wgpu_client_make_sampler_id(client: &Client, device_id: id::DeviceId) -> id::SamplerId { + let backend = device_id.backend(); + client + .identities + .lock() + .select(backend) + .samplers + .alloc(backend) +} + +#[no_mangle] +pub extern "C" fn wgpu_client_kill_sampler_id( + client: &Client, + id: id::SamplerId, +) { + client + .identities + .lock() + .select(id.backend()) + .samplers + .free(id) +} + #[no_mangle] pub extern "C" fn wgpu_client_make_encoder_id( client: &Client, diff --git a/wgpu-remote/src/server.rs b/wgpu-remote/src/server.rs index d69c03e7c1..95f4aef1d2 100644 --- a/wgpu-remote/src/server.rs +++ b/wgpu-remote/src/server.rs @@ -334,3 +334,57 @@ pub extern "C" fn wgpu_server_render_pipeline_destroy( ) { gfx_select!(self_id => global.render_pipeline_destroy(self_id)); } + +#[no_mangle] +pub extern "C" fn wgpu_server_device_create_texture( + global: &Global, + self_id: id::DeviceId, + desc: &core::resource::TextureDescriptor, + new_id: id::TextureId, +) { + gfx_select!(self_id => global.device_create_texture(self_id, desc, new_id)); +} + +#[no_mangle] +pub extern "C" fn wgpu_server_texture_create_view( + global: &Global, + self_id: id::TextureId, + desc: Option<&core::resource::TextureViewDescriptor>, + new_id: id::TextureViewId, +) { + gfx_select!(self_id => global.texture_create_view(self_id, desc, new_id)); +} + +#[no_mangle] +pub extern "C" fn wgpu_server_texture_destroy( + global: &Global, + self_id: id::TextureId, +) { + gfx_select!(self_id => global.texture_destroy(self_id)); +} + +#[no_mangle] +pub extern "C" fn wgpu_server_texture_view_destroy( + global: &Global, + self_id: id::TextureViewId, +) { + gfx_select!(self_id => global.texture_view_destroy(self_id)); +} + +#[no_mangle] +pub extern "C" fn wgpu_server_device_create_sampler( + global: &Global, + self_id: id::DeviceId, + desc: &core::resource::SamplerDescriptor, + new_id: id::SamplerId, +) { + gfx_select!(self_id => global.device_create_sampler(self_id, desc, new_id)); +} + +#[no_mangle] +pub extern "C" fn wgpu_server_sampler_destroy( + global: &Global, + self_id: id::SamplerId, +) { + gfx_select!(self_id => global.sampler_destroy(self_id)); +}