From f67894c310eb2f920f133236396e9627596e82b3 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 24 Oct 2019 11:45:53 -0400 Subject: [PATCH] Explicit Global hubs --- ffi/wgpu.h | 86 ++++++++++++- wgpu-native/Cargo.toml | 2 +- wgpu-native/src/command/compute.rs | 41 ++++--- wgpu-native/src/command/mod.rs | 21 ++-- wgpu-native/src/command/render.rs | 104 ++++++++++------ wgpu-native/src/command/transfer.rs | 25 +++- wgpu-native/src/device.rs | 183 +++++++++++++++++----------- wgpu-native/src/hub.rs | 28 +++-- wgpu-native/src/instance.rs | 30 ++--- wgpu-native/src/swap_chain.rs | 21 ++-- wgpu-remote/src/server.rs | 5 +- 11 files changed, 369 insertions(+), 177 deletions(-) diff --git a/ffi/wgpu.h b/ffi/wgpu.h index b4935ef46..7b68d6948 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -244,6 +244,8 @@ typedef enum { WGPUVertexFormat_Int4 = 48, } WGPUVertexFormat; +typedef struct WGPUGlobal WGPUGlobal; + typedef uint64_t WGPUId_Device_Dummy; typedef WGPUId_Device_Dummy WGPUDeviceId; @@ -670,23 +672,33 @@ WGPUDeviceId wgpu_adapter_request_device(WGPUAdapterId adapter_id, const WGPUDeviceDescriptor *desc); #endif +#if !defined(WGPU_REMOTE) void wgpu_bind_group_destroy(WGPUBindGroupId bind_group_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_buffer_destroy(WGPUBufferId buffer_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_buffer_map_read_async(WGPUBufferId buffer_id, WGPUBufferAddress start, WGPUBufferAddress size, WGPUBufferMapReadCallback callback, uint8_t *userdata); +#endif +#if !defined(WGPU_REMOTE) void wgpu_buffer_map_write_async(WGPUBufferId buffer_id, WGPUBufferAddress start, WGPUBufferAddress size, WGPUBufferMapWriteCallback callback, uint8_t *userdata); +#endif +#if !defined(WGPU_REMOTE) void wgpu_buffer_unmap(WGPUBufferId buffer_id); +#endif #if !defined(WGPU_REMOTE) WGPUComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encoder_id, @@ -698,38 +710,54 @@ WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId enc const WGPURenderPassDescriptor *desc); #endif +#if !defined(WGPU_REMOTE) void wgpu_command_encoder_copy_buffer_to_buffer(WGPUCommandEncoderId command_encoder_id, WGPUBufferId source, WGPUBufferAddress source_offset, WGPUBufferId destination, WGPUBufferAddress destination_offset, WGPUBufferAddress size); +#endif +#if !defined(WGPU_REMOTE) void wgpu_command_encoder_copy_buffer_to_texture(WGPUCommandEncoderId command_encoder_id, const WGPUBufferCopyView *source, const WGPUTextureCopyView *destination, WGPUExtent3d copy_size); +#endif +#if !defined(WGPU_REMOTE) void wgpu_command_encoder_copy_texture_to_buffer(WGPUCommandEncoderId command_encoder_id, const WGPUTextureCopyView *source, const WGPUBufferCopyView *destination, WGPUExtent3d copy_size); +#endif +#if !defined(WGPU_REMOTE) void wgpu_command_encoder_copy_texture_to_texture(WGPUCommandEncoderId command_encoder_id, const WGPUTextureCopyView *source, const WGPUTextureCopyView *destination, WGPUExtent3d copy_size); +#endif +#if !defined(WGPU_REMOTE) WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId encoder_id, const WGPUCommandBufferDescriptor *desc); +#endif +#if !defined(WGPU_REMOTE) void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z); +#endif +#if !defined(WGPU_REMOTE) void wgpu_compute_pass_dispatch_indirect(WGPUComputePassId pass_id, WGPUBufferId indirect_buffer_id, WGPUBufferAddress indirect_offset); +#endif +#if !defined(WGPU_REMOTE) void wgpu_compute_pass_end_pass(WGPUComputePassId pass_id); +#endif void wgpu_compute_pass_insert_debug_marker(WGPUComputePassId _pass_id, WGPURawString _label); @@ -737,13 +765,17 @@ void wgpu_compute_pass_pop_debug_group(WGPUComputePassId _pass_id); void wgpu_compute_pass_push_debug_group(WGPUComputePassId _pass_id, WGPURawString _label); +#if !defined(WGPU_REMOTE) void wgpu_compute_pass_set_bind_group(WGPUComputePassId pass_id, uint32_t index, WGPUBindGroupId bind_group_id, const WGPUBufferAddress *offsets, uintptr_t offsets_length); +#endif +#if !defined(WGPU_REMOTE) void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id); +#endif #if !defined(WGPU_REMOTE) WGPUSurfaceId wgpu_create_surface_from_metal_layer(void *layer); @@ -816,81 +848,124 @@ WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id, WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc); #endif +#if !defined(WGPU_REMOTE) void wgpu_device_destroy(WGPUDeviceId device_id); +#endif #if !defined(WGPU_REMOTE) void wgpu_device_get_limits(WGPUDeviceId _device_id, WGPULimits *limits); #endif +#if !defined(WGPU_REMOTE) WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_device_poll(WGPUDeviceId device_id, bool force_wait); +#endif +#if !defined(WGPU_REMOTE) void wgpu_queue_submit(WGPUQueueId queue_id, const WGPUCommandBufferId *command_buffers, uintptr_t command_buffers_length); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_draw(WGPURenderPassId pass_id, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_draw_indexed(WGPURenderPassId pass_id, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t base_vertex, uint32_t first_instance); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_draw_indexed_indirect(WGPURenderPassId pass_id, WGPUBufferId indirect_buffer_id, WGPUBufferAddress indirect_offset); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_draw_indirect(WGPURenderPassId pass_id, WGPUBufferId indirect_buffer_id, WGPUBufferAddress indirect_offset); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_end_pass(WGPURenderPassId pass_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_execute_bundles(WGPURenderPassId _pass_id, const WGPURenderBundleId *_bundles, uintptr_t _bundles_length); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_insert_debug_marker(WGPURenderPassId _pass_id, WGPURawString _label); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_pop_debug_group(WGPURenderPassId _pass_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_push_debug_group(WGPURenderPassId _pass_id, WGPURawString _label); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_bind_group(WGPURenderPassId pass_id, uint32_t index, WGPUBindGroupId bind_group_id, const WGPUBufferAddress *offsets, uintptr_t offsets_length); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_blend_color(WGPURenderPassId pass_id, const WGPUColor *color); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_index_buffer(WGPURenderPassId pass_id, WGPUBufferId buffer_id, WGPUBufferAddress offset); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_pipeline(WGPURenderPassId pass_id, WGPURenderPipelineId pipeline_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_scissor_rect(WGPURenderPassId pass_id, uint32_t x, uint32_t y, uint32_t w, uint32_t h); +#endif -void wgpu_render_pass_set_stencil_reference(WGPURenderPassId pass_id, uint32_t value); +#if !defined(WGPU_REMOTE) +void wgpu_render_pass_set_stencil_reference(const WGPUGlobal *global, + WGPURenderPassId pass_id, + uint32_t value); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_vertex_buffers(WGPURenderPassId pass_id, uint32_t start_slot, const WGPUBufferId *buffers, const WGPUBufferAddress *offsets, uintptr_t length); +#endif +#if !defined(WGPU_REMOTE) void wgpu_render_pass_set_viewport(WGPURenderPassId pass_id, float x, float y, @@ -898,24 +973,33 @@ void wgpu_render_pass_set_viewport(WGPURenderPassId pass_id, float h, float min_depth, float max_depth); +#endif #if !defined(WGPU_REMOTE) WGPUAdapterId wgpu_request_adapter(const WGPURequestAdapterOptions *desc); #endif +#if !defined(WGPU_REMOTE) void wgpu_sampler_destroy(WGPUSamplerId sampler_id); +#endif #if !defined(WGPU_REMOTE) WGPUSwapChainOutput wgpu_swap_chain_get_next_texture(WGPUSwapChainId swap_chain_id); #endif +#if !defined(WGPU_REMOTE) void wgpu_swap_chain_present(WGPUSwapChainId swap_chain_id); +#endif #if !defined(WGPU_REMOTE) WGPUTextureViewId wgpu_texture_create_view(WGPUTextureId texture_id, const WGPUTextureViewDescriptor *desc); #endif +#if !defined(WGPU_REMOTE) void wgpu_texture_destroy(WGPUTextureId texture_id); +#endif +#if !defined(WGPU_REMOTE) void wgpu_texture_view_destroy(WGPUTextureViewId texture_view_id); +#endif diff --git a/wgpu-native/Cargo.toml b/wgpu-native/Cargo.toml index 0b62ef017..5c15c7980 100644 --- a/wgpu-native/Cargo.toml +++ b/wgpu-native/Cargo.toml @@ -26,7 +26,7 @@ metal-auto-capture = ["gfx-backend-metal/auto-capture"] arrayvec = "0.5" bitflags = "1.0" copyless = "0.1" -lazy_static = "1.1.0" +lazy_static = "1.1.0" #TODO: local only log = "0.4" hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "3d5db15661127c8cad8d85522a68ec36c82f6e69" } gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "3d5db15661127c8cad8d85522a68ec36c82f6e69" } diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index 87556cc5e..72e5ed654 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -5,8 +5,7 @@ use crate::{ command::bind::{Binder, LayoutChange}, device::all_buffer_stages, - gfx_select, - hub::{GfxBackend, Token}, + hub::{GfxBackend, Global, Token}, track::{Stitch, TrackerSet}, BindGroupId, BufferAddress, @@ -20,11 +19,15 @@ use crate::{ Stored, BIND_BUFFER_ALIGNMENT, }; +#[cfg(not(feature = "remote"))] +use crate::{gfx_select, hub::GLOBAL}; use hal::{self, command::CommandBuffer as _}; use log::trace; -use std::{iter, slice}; +use std::iter; +#[cfg(not(feature = "remote"))] +use std::slice; #[derive(Debug)] pub struct ComputePass { @@ -52,9 +55,9 @@ impl ComputePass { // Common routines between render/compute -pub fn compute_pass_end_pass(pass_id: ComputePassId) { +pub fn compute_pass_end_pass(global: &Global, pass_id: ComputePassId) { let mut token = Token::root(); - let hub = B::hub(); + let hub = B::hub(global); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); let (pass, _) = hub.compute_passes.unregister(pass_id, &mut token); let cmb = &mut cmb_guard[pass.cmb_id.value]; @@ -65,18 +68,20 @@ pub fn compute_pass_end_pass(pass_id: ComputePassId) { cmb.raw.push(pass.raw); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: ComputePassId) { - gfx_select!(pass_id => compute_pass_end_pass(pass_id)) + gfx_select!(pass_id => compute_pass_end_pass(&*GLOBAL, pass_id)) } pub fn compute_pass_set_bind_group( + global: &Global, pass_id: ComputePassId, index: u32, bind_group_id: BindGroupId, offsets: &[BufferAddress], ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token); @@ -143,6 +148,7 @@ pub fn compute_pass_set_bind_group( }; } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_compute_pass_set_bind_group( pass_id: ComputePassId, @@ -156,7 +162,7 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group( } else { &[] }; - gfx_select!(pass_id => compute_pass_set_bind_group(pass_id, index, bind_group_id, offsets)) + gfx_select!(pass_id => compute_pass_set_bind_group(&*GLOBAL, pass_id, index, bind_group_id, offsets)) } #[no_mangle] @@ -179,8 +185,8 @@ pub extern "C" fn wgpu_compute_pass_insert_debug_marker( // Compute-specific routines -pub fn compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u32, z: u32) { - let hub = B::hub(); +pub fn compute_pass_dispatch(global: &Global, pass_id: ComputePassId, x: u32, y: u32, z: u32) { + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.compute_passes.write(&mut token); unsafe { @@ -188,17 +194,19 @@ pub fn compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u32, z: u32) { - gfx_select!(pass_id => compute_pass_dispatch(pass_id, x, y, z)) + gfx_select!(pass_id => compute_pass_dispatch(&*GLOBAL, pass_id, x, y, z)) } pub fn compute_pass_dispatch_indirect( + global: &Global, pass_id: ComputePassId, indirect_buffer_id: BufferId, indirect_offset: BufferAddress, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (buffer_guard, _) = hub.buffers.read(&mut token); let (mut pass_guard, _) = hub.compute_passes.write(&mut token); @@ -229,20 +237,22 @@ pub fn compute_pass_dispatch_indirect( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_compute_pass_dispatch_indirect( pass_id: ComputePassId, indirect_buffer_id: BufferId, indirect_offset: BufferAddress, ) { - gfx_select!(pass_id => compute_pass_dispatch_indirect(pass_id, indirect_buffer_id, indirect_offset)) + gfx_select!(pass_id => compute_pass_dispatch_indirect(&*GLOBAL, pass_id, indirect_buffer_id, indirect_offset)) } pub fn compute_pass_set_pipeline( + global: &Global, pass_id: ComputePassId, pipeline_id: ComputePipelineId, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token); let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); @@ -292,10 +302,11 @@ pub fn compute_pass_set_pipeline( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_compute_pass_set_pipeline( pass_id: ComputePassId, pipeline_id: ComputePipelineId, ) { - gfx_select!(pass_id => compute_pass_set_pipeline(pass_id, pipeline_id)) + gfx_select!(pass_id => compute_pass_set_pipeline(&*GLOBAL, pass_id, pipeline_id)) } diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index 8e5cd17a3..83f0753d0 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -22,8 +22,7 @@ use crate::{ RenderPassContext, RenderPassKey, }, - gfx_select, - hub::{GfxBackend, Storage, Token}, + hub::{GfxBackend, Global, Storage, Token}, id::{Input, Output}, resource::TextureViewInner, track::{Stitch, TrackerSet}, @@ -43,6 +42,8 @@ use crate::{ TextureUsage, TextureViewId, }; +#[cfg(not(feature = "remote"))] +use crate::{gfx_select, hub::GLOBAL}; use arrayvec::ArrayVec; use hal::{adapter::PhysicalDevice as _, command::CommandBuffer as _, device::Device as _}; @@ -194,10 +195,11 @@ pub struct CommandBufferDescriptor { } pub fn command_encoder_finish( + global: &Global, encoder_id: CommandEncoderId, _desc: &CommandBufferDescriptor, ) -> CommandBufferId { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); //TODO: actually close the last recorded command buffer let (mut comb_guard, _) = hub.command_buffers.write(&mut token); @@ -211,21 +213,23 @@ pub fn command_encoder_finish( encoder_id } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_command_encoder_finish( encoder_id: CommandEncoderId, desc: Option<&CommandBufferDescriptor>, ) -> CommandBufferId { let desc = &desc.cloned().unwrap_or_default(); - gfx_select!(encoder_id => command_encoder_finish(encoder_id, desc)) + gfx_select!(encoder_id => command_encoder_finish(&*GLOBAL, encoder_id, desc)) } pub fn command_encoder_begin_render_pass( + global: &Global, encoder_id: CommandEncoderId, desc: &RenderPassDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (adapter_guard, mut token) = hub.adapters.read(&mut token); @@ -724,15 +728,16 @@ pub extern "C" fn wgpu_command_encoder_begin_render_pass( encoder_id: CommandEncoderId, desc: &RenderPassDescriptor, ) -> RenderPassId { - gfx_select!(encoder_id => command_encoder_begin_render_pass(encoder_id, desc, PhantomData)) + gfx_select!(encoder_id => command_encoder_begin_render_pass(&*GLOBAL, encoder_id, desc, PhantomData)) } pub fn command_encoder_begin_compute_pass( + global: &Global, encoder_id: CommandEncoderId, _desc: &ComputePassDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); @@ -757,5 +762,5 @@ pub extern "C" fn wgpu_command_encoder_begin_compute_pass( desc: Option<&ComputePassDescriptor>, ) -> ComputePassId { let desc = &desc.cloned().unwrap_or_default(); - gfx_select!(encoder_id => command_encoder_begin_compute_pass(encoder_id, desc, PhantomData)) + gfx_select!(encoder_id => command_encoder_begin_compute_pass(&*GLOBAL, encoder_id, desc, PhantomData)) } diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 35dc72ca3..233b5a7d8 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -6,8 +6,7 @@ use crate::{ command::bind::{Binder, LayoutChange}, conv, device::{RenderPassContext, BIND_BUFFER_ALIGNMENT, MAX_VERTEX_BUFFERS}, - gfx_select, - hub::{GfxBackend, Token}, + hub::{GfxBackend, Global, Token}, pipeline::{IndexFormat, InputStepMode, PipelineFlags}, resource::BufferUsage, track::{Stitch, TrackerSet}, @@ -17,17 +16,19 @@ use crate::{ Color, CommandBuffer, CommandBufferId, - RawString, - RenderBundleId, RenderPassId, RenderPipelineId, Stored, }; +#[cfg(not(feature = "remote"))] +use crate::{gfx_select, RawString, RenderBundleId, hub::GLOBAL}; use hal::command::CommandBuffer as _; use log::trace; -use std::{iter, ops::Range, slice}; +use std::{iter, ops::Range}; +#[cfg(not(feature = "remote"))] +use std::slice; #[derive(Debug, PartialEq)] enum OptionalState { @@ -181,8 +182,8 @@ impl RenderPass { // Common routines between render/compute -pub fn render_pass_end_pass(pass_id: RenderPassId) { - let hub = B::hub(); +pub fn render_pass_end_pass(global: &Global, pass_id: RenderPassId) { + let hub = B::hub(global); let mut token = Token::root(); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); let (mut pass, mut token) = hub.render_passes.unregister(pass_id, &mut token); @@ -215,18 +216,20 @@ pub fn render_pass_end_pass(pass_id: RenderPassId) { cmb.raw.push(pass.raw); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_end_pass(pass_id: RenderPassId) { - gfx_select!(pass_id => render_pass_end_pass(pass_id)) + gfx_select!(pass_id => render_pass_end_pass(&*GLOBAL, pass_id)) } pub fn render_pass_set_bind_group( + global: &Global, pass_id: RenderPassId, index: u32, bind_group_id: BindGroupId, offsets: &[BufferAddress], ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token); let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); @@ -276,6 +279,7 @@ pub fn render_pass_set_bind_group( }; } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_bind_group( pass_id: RenderPassId, @@ -289,19 +293,22 @@ pub extern "C" fn wgpu_render_pass_set_bind_group( } else { &[] }; - gfx_select!(pass_id => render_pass_set_bind_group(pass_id, index, bind_group_id, offsets)) + gfx_select!(pass_id => render_pass_set_bind_group(&*GLOBAL, pass_id, index, bind_group_id, offsets)) } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_push_debug_group(_pass_id: RenderPassId, _label: RawString) { //TODO } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_pop_debug_group(_pass_id: RenderPassId) { //TODO } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_insert_debug_marker(_pass_id: RenderPassId, _label: RawString) { //TODO @@ -310,11 +317,12 @@ pub extern "C" fn wgpu_render_pass_insert_debug_marker(_pass_id: RenderPassId, _ // Render-specific routines pub fn render_pass_set_index_buffer( + global: &Global, pass_id: RenderPassId, buffer_id: BufferId, offset: BufferAddress, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, mut token) = hub.render_passes.write(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); @@ -342,22 +350,24 @@ pub fn render_pass_set_index_buffer( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_index_buffer( pass_id: RenderPassId, buffer_id: BufferId, offset: BufferAddress, ) { - gfx_select!(pass_id => render_pass_set_index_buffer(pass_id, buffer_id, offset)) + gfx_select!(pass_id => render_pass_set_index_buffer(&*GLOBAL, pass_id, buffer_id, offset)) } pub fn render_pass_set_vertex_buffers( + global: &Global, pass_id: RenderPassId, start_slot: u32, buffers: &[BufferId], offsets: &[BufferAddress], ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); assert_eq!(buffers.len(), offsets.len()); @@ -391,6 +401,7 @@ pub fn render_pass_set_vertex_buffers( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_vertex_buffers( pass_id: RenderPassId, @@ -401,17 +412,18 @@ pub extern "C" fn wgpu_render_pass_set_vertex_buffers( ) { let buffers = unsafe { slice::from_raw_parts(buffers, length) }; let offsets = unsafe { slice::from_raw_parts(offsets, length) }; - gfx_select!(pass_id => render_pass_set_vertex_buffers(pass_id, start_slot, buffers, offsets)) + gfx_select!(pass_id => render_pass_set_vertex_buffers(&*GLOBAL, pass_id, start_slot, buffers, offsets)) } pub fn render_pass_draw( + global: &Global, pass_id: RenderPassId, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let pass = &mut pass_guard[pass_id]; @@ -434,6 +446,7 @@ pub fn render_pass_draw( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_draw( pass_id: RenderPassId, @@ -442,15 +455,16 @@ pub extern "C" fn wgpu_render_pass_draw( first_vertex: u32, first_instance: u32, ) { - gfx_select!(pass_id => render_pass_draw(pass_id, vertex_count, instance_count, first_vertex, first_instance)) + gfx_select!(pass_id => render_pass_draw(&*GLOBAL, pass_id, vertex_count, instance_count, first_vertex, first_instance)) } pub fn render_pass_draw_indirect( + global: &Global, pass_id: RenderPassId, indirect_buffer_id: BufferId, indirect_offset: BufferAddress, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); @@ -474,16 +488,18 @@ pub fn render_pass_draw_indirect( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_draw_indirect( pass_id: RenderPassId, indirect_buffer_id: BufferId, indirect_offset: BufferAddress, ) { - gfx_select!(pass_id => render_pass_draw_indirect(pass_id, indirect_buffer_id, indirect_offset)) + gfx_select!(pass_id => render_pass_draw_indirect(&*GLOBAL, pass_id, indirect_buffer_id, indirect_offset)) } pub fn render_pass_draw_indexed( + global: &Global, pass_id: RenderPassId, index_count: u32, instance_count: u32, @@ -491,7 +507,7 @@ pub fn render_pass_draw_indexed( base_vertex: i32, first_instance: u32, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let pass = &mut pass_guard[pass_id]; @@ -516,6 +532,7 @@ pub fn render_pass_draw_indexed( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_draw_indexed( pass_id: RenderPassId, @@ -525,15 +542,16 @@ pub extern "C" fn wgpu_render_pass_draw_indexed( base_vertex: i32, first_instance: u32, ) { - gfx_select!(pass_id => render_pass_draw_indexed(pass_id, index_count, instance_count, first_index, base_vertex, first_instance)) + gfx_select!(pass_id => render_pass_draw_indexed(&*GLOBAL, pass_id, index_count, instance_count, first_index, base_vertex, first_instance)) } pub fn render_pass_draw_indexed_indirect( + global: &Global, pass_id: RenderPassId, indirect_buffer_id: BufferId, indirect_offset: BufferAddress, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); @@ -558,20 +576,22 @@ pub fn render_pass_draw_indexed_indirect( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_draw_indexed_indirect( pass_id: RenderPassId, indirect_buffer_id: BufferId, indirect_offset: BufferAddress, ) { - gfx_select!(pass_id => render_pass_draw_indexed_indirect(pass_id, indirect_buffer_id, indirect_offset)) + gfx_select!(pass_id => render_pass_draw_indexed_indirect(&*GLOBAL, pass_id, indirect_buffer_id, indirect_offset)) } pub fn render_pass_set_pipeline( + global: &Global, pass_id: RenderPassId, pipeline_id: RenderPipelineId, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (pipeline_layout_guard, mut token) = hub.pipeline_layouts.read(&mut token); let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); @@ -675,16 +695,19 @@ pub fn render_pass_set_pipeline( pass.vertex_state.update_limits(); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_pipeline( pass_id: RenderPassId, pipeline_id: RenderPipelineId, ) { - gfx_select!(pass_id => render_pass_set_pipeline(pass_id, pipeline_id)) + gfx_select!(pass_id => render_pass_set_pipeline(&*GLOBAL, pass_id, pipeline_id)) } -pub fn render_pass_set_blend_color(pass_id: RenderPassId, color: &Color) { - let hub = B::hub(); +pub fn render_pass_set_blend_color( + global: &Global, pass_id: RenderPassId, color: &Color +) { + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let pass = &mut pass_guard[pass_id]; @@ -696,13 +719,16 @@ pub fn render_pass_set_blend_color(pass_id: RenderPassId, color: } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color: &Color) { - gfx_select!(pass_id => render_pass_set_blend_color(pass_id, color)) + gfx_select!(pass_id => render_pass_set_blend_color(&*GLOBAL, pass_id, color)) } -pub fn render_pass_set_stencil_reference(pass_id: RenderPassId, value: u32) { - let hub = B::hub(); +pub fn render_pass_set_stencil_reference( + global: &Global, pass_id: RenderPassId, value: u32 +) { + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let pass = &mut pass_guard[pass_id]; @@ -714,12 +740,16 @@ pub fn render_pass_set_stencil_reference(pass_id: RenderPassId, v } } +#[cfg(not(feature = "remote"))] #[no_mangle] -pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: RenderPassId, value: u32) { - gfx_select!(pass_id => render_pass_set_stencil_reference(pass_id, value)) +pub extern "C" fn wgpu_render_pass_set_stencil_reference( + pass_id: RenderPassId, value: u32 +) { + gfx_select!(pass_id => render_pass_set_stencil_reference(&*GLOBAL, pass_id, value)) } pub fn render_pass_set_viewport( + global: &Global, pass_id: RenderPassId, x: f32, y: f32, @@ -728,7 +758,7 @@ pub fn render_pass_set_viewport( min_depth: f32, max_depth: f32, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let pass = &mut pass_guard[pass_id]; @@ -752,6 +782,7 @@ pub fn render_pass_set_viewport( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_viewport( pass_id: RenderPassId, @@ -762,17 +793,18 @@ pub extern "C" fn wgpu_render_pass_set_viewport( min_depth: f32, max_depth: f32, ) { - gfx_select!(pass_id => render_pass_set_viewport(pass_id, x, y, w, h, min_depth, max_depth)) + gfx_select!(pass_id => render_pass_set_viewport(&*GLOBAL, pass_id, x, y, w, h, min_depth, max_depth)) } pub fn render_pass_set_scissor_rect( + global: &Global, pass_id: RenderPassId, x: u32, y: u32, w: u32, h: u32, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.render_passes.write(&mut token); let pass = &mut pass_guard[pass_id]; @@ -793,6 +825,7 @@ pub fn render_pass_set_scissor_rect( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_set_scissor_rect( pass_id: RenderPassId, @@ -801,9 +834,10 @@ pub extern "C" fn wgpu_render_pass_set_scissor_rect( w: u32, h: u32, ) { - gfx_select!(pass_id => render_pass_set_scissor_rect(pass_id, x, y, w, h)) + gfx_select!(pass_id => render_pass_set_scissor_rect(&*GLOBAL, pass_id, x, y, w, h)) } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_render_pass_execute_bundles( _pass_id: RenderPassId, diff --git a/wgpu-native/src/command/transfer.rs b/wgpu-native/src/command/transfer.rs index 58a5cc54b..d3579c64a 100644 --- a/wgpu-native/src/command/transfer.rs +++ b/wgpu-native/src/command/transfer.rs @@ -5,8 +5,7 @@ use crate::{ conv, device::{all_buffer_stages, all_image_stages}, - gfx_select, - hub::{GfxBackend, Token}, + hub::{GfxBackend, Global, Token}, BufferAddress, BufferId, BufferUsage, @@ -16,6 +15,8 @@ use crate::{ TextureId, TextureUsage, }; +#[cfg(not(feature = "remote"))] +use crate::{gfx_select, hub::GLOBAL}; use hal::command::CommandBuffer as _; @@ -65,6 +66,7 @@ impl TextureCopyView { } pub fn command_encoder_copy_buffer_to_buffer( + global: &Global, command_encoder_id: CommandEncoderId, source: BufferId, source_offset: BufferAddress, @@ -72,7 +74,7 @@ pub fn command_encoder_copy_buffer_to_buffer( destination_offset: BufferAddress, size: BufferAddress, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); @@ -124,6 +126,7 @@ pub fn command_encoder_copy_buffer_to_buffer( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_command_encoder_copy_buffer_to_buffer( command_encoder_id: CommandEncoderId, @@ -134,6 +137,7 @@ pub extern "C" fn wgpu_command_encoder_copy_buffer_to_buffer( size: BufferAddress, ) { gfx_select!(command_encoder_id => command_encoder_copy_buffer_to_buffer( + &*GLOBAL, command_encoder_id, source, source_offset, destination, @@ -142,12 +146,13 @@ pub extern "C" fn wgpu_command_encoder_copy_buffer_to_buffer( } pub fn command_encoder_copy_buffer_to_texture( + global: &Global, command_encoder_id: CommandEncoderId, source: &BufferCopyView, destination: &TextureCopyView, copy_size: Extent3d, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); let cmb = &mut cmb_guard[command_encoder_id]; @@ -215,6 +220,7 @@ pub fn command_encoder_copy_buffer_to_texture( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_command_encoder_copy_buffer_to_texture( command_encoder_id: CommandEncoderId, @@ -223,6 +229,7 @@ pub extern "C" fn wgpu_command_encoder_copy_buffer_to_texture( copy_size: Extent3d, ) { gfx_select!(command_encoder_id => command_encoder_copy_buffer_to_texture( + &*GLOBAL, command_encoder_id, source, destination, @@ -230,12 +237,13 @@ pub extern "C" fn wgpu_command_encoder_copy_buffer_to_texture( } pub fn command_encoder_copy_texture_to_buffer( + global: &Global, command_encoder_id: CommandEncoderId, source: &TextureCopyView, destination: &BufferCopyView, copy_size: Extent3d, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); let cmb = &mut cmb_guard[command_encoder_id]; @@ -305,6 +313,7 @@ pub fn command_encoder_copy_texture_to_buffer( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_command_encoder_copy_texture_to_buffer( command_encoder_id: CommandEncoderId, @@ -313,6 +322,7 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_buffer( copy_size: Extent3d, ) { gfx_select!(command_encoder_id => command_encoder_copy_texture_to_buffer( + &*GLOBAL, command_encoder_id, source, destination, @@ -320,12 +330,13 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_buffer( } pub fn command_encoder_copy_texture_to_texture( + global: &Global, command_encoder_id: CommandEncoderId, source: &TextureCopyView, destination: &TextureCopyView, copy_size: Extent3d, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (mut cmb_guard, mut token) = hub.command_buffers.write(&mut token); @@ -393,6 +404,7 @@ pub fn command_encoder_copy_texture_to_texture( } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_command_encoder_copy_texture_to_texture( command_encoder_id: CommandEncoderId, @@ -401,6 +413,7 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_texture( copy_size: Extent3d, ) { gfx_select!(command_encoder_id => command_encoder_copy_texture_to_texture( + &*GLOBAL, command_encoder_id, source, destination, diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index c8bebc958..7d8ff8a30 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -10,8 +10,7 @@ use crate::{ binding_model, command, conv, - gfx_select, - hub::{GfxBackend, Token, GLOBAL}, + hub::{GfxBackend, Global, Token}, id::{Input, Output}, pipeline, resource, @@ -46,6 +45,8 @@ use crate::{ TextureUsage, TextureViewId, }; +#[cfg(not(feature = "remote"))] +use crate::{gfx_select, hub::GLOBAL}; use arrayvec::ArrayVec; use copyless::VecHelper as _; @@ -275,7 +276,9 @@ impl PendingResources { last_done } - fn triage_referenced(&mut self, trackers: &mut TrackerSet, mut token: &mut Token>) { + fn triage_referenced( + &mut self, global: &Global, trackers: &mut TrackerSet, mut token: &mut Token> + ) { // Before destruction, a resource is expected to have the following strong refs: // - in resource itself // - in the device tracker @@ -286,7 +289,7 @@ impl PendingResources { return; } - let hub = B::hub(); + let hub = B::hub(global); //TODO: lock less, if possible let (mut bind_group_guard, mut token) = hub.bind_groups.write(&mut token); let (mut buffer_guard, mut token) = hub.buffers.write(&mut token); @@ -362,11 +365,11 @@ impl PendingResources { } } - fn triage_mapped(&mut self, token: &mut Token>) { + fn triage_mapped(&mut self, global: &Global, token: &mut Token>) { if self.mapped.is_empty() { return; } - let (buffer_guard, _) = B::hub().buffers.read(token); + let (buffer_guard, _) = B::hub(global).buffers.read(token); for stored in self.mapped.drain(..) { let resource_id = stored.value; @@ -390,10 +393,11 @@ impl PendingResources { fn triage_framebuffers( &mut self, + global: &Global, framebuffers: &mut FastHashMap, token: &mut Token>, ) { - let (texture_view_guard, _) = B::hub().texture_views.read(token); + let (texture_view_guard, _) = B::hub(global).texture_views.read(token); let remove_list = framebuffers .keys() .filter_map(|key| { @@ -428,13 +432,14 @@ impl PendingResources { fn handle_mapping( &mut self, + global: &Global, raw: &B::Device, token: &mut Token>, ) -> Vec { if self.ready_to_map.is_empty() { return Vec::new(); } - let (mut buffer_guard, _) = B::hub().buffers.write(token); + let (mut buffer_guard, _) = B::hub(global).buffers.write(token); self.ready_to_map .drain(..) .map(|buffer_id| { @@ -566,20 +571,20 @@ impl Device { } } - fn maintain(&self, force_wait: bool, token: &mut Token) -> Vec { + fn maintain(&self, global: &Global, force_wait: bool, token: &mut Token) -> Vec { let mut pending = self.pending.lock(); let mut trackers = self.trackers.lock(); - pending.triage_referenced(&mut *trackers, token); - pending.triage_mapped(token); - pending.triage_framebuffers(&mut *self.framebuffers.lock(), token); + pending.triage_referenced(global, &mut *trackers, token); + pending.triage_mapped(global, token); + pending.triage_framebuffers(global, &mut *self.framebuffers.lock(), token); let last_done = pending.cleanup( &self.raw, &self.mem_allocator, &self.desc_allocator, force_wait, ); - let callbacks = pending.handle_mapping(&self.raw, token); + let callbacks = pending.handle_mapping(global, &self.raw, token); unsafe { self.desc_allocator.lock().cleanup(&self.raw); @@ -767,11 +772,12 @@ pub struct ShaderModule { } pub fn device_create_buffer( + global: &Global, device_id: DeviceId, desc: &resource::BufferDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, _) = hub.devices.read(&mut token); @@ -797,16 +803,17 @@ pub extern "C" fn wgpu_device_create_buffer( device_id: DeviceId, desc: &resource::BufferDescriptor, ) -> BufferId { - gfx_select!(device_id => device_create_buffer(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_buffer(&*GLOBAL, device_id, desc, PhantomData)) } pub fn device_create_buffer_mapped( + global: &Global, device_id: DeviceId, desc: &resource::BufferDescriptor, mapped_ptr_out: *mut *mut u8, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let mut desc = desc.clone(); desc.usage |= resource::BufferUsage::MAP_WRITE; @@ -847,11 +854,11 @@ pub extern "C" fn wgpu_device_create_buffer_mapped( desc: &resource::BufferDescriptor, mapped_ptr_out: *mut *mut u8, ) -> BufferId { - gfx_select!(device_id => device_create_buffer_mapped(device_id, desc, mapped_ptr_out, PhantomData)) + gfx_select!(device_id => device_create_buffer_mapped(&*GLOBAL, device_id, desc, mapped_ptr_out, PhantomData)) } -pub fn buffer_destroy(buffer_id: BufferId) { - let hub = B::hub(); +pub fn buffer_destroy(global: &Global, buffer_id: BufferId) { + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token); @@ -862,17 +869,19 @@ pub fn buffer_destroy(buffer_id: BufferId) { ); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_buffer_destroy(buffer_id: BufferId) { - gfx_select!(buffer_id => buffer_destroy(buffer_id)) + gfx_select!(buffer_id => buffer_destroy(&*GLOBAL, buffer_id)) } pub fn device_create_texture( + global: &Global, device_id: DeviceId, desc: &resource::TextureDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, _) = hub.devices.read(&mut token); @@ -898,15 +907,16 @@ pub extern "C" fn wgpu_device_create_texture( device_id: DeviceId, desc: &resource::TextureDescriptor, ) -> TextureId { - gfx_select!(device_id => device_create_texture(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_texture(&*GLOBAL, device_id, desc, PhantomData)) } pub fn texture_create_view( + global: &Global, texture_id: TextureId, desc: Option<&resource::TextureViewDescriptor>, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -996,11 +1006,11 @@ pub extern "C" fn wgpu_texture_create_view( texture_id: TextureId, desc: Option<&resource::TextureViewDescriptor>, ) -> TextureViewId { - gfx_select!(texture_id => texture_create_view(texture_id, desc, PhantomData)) + gfx_select!(texture_id => texture_create_view(&*GLOBAL, texture_id, desc, PhantomData)) } -pub fn texture_destroy(texture_id: TextureId) { - let hub = B::hub(); +pub fn texture_destroy(global: &Global, texture_id: TextureId) { + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -1015,13 +1025,16 @@ pub fn texture_destroy(texture_id: TextureId) { ); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_texture_destroy(texture_id: TextureId) { - gfx_select!(texture_id => texture_destroy(texture_id)) + gfx_select!(texture_id => texture_destroy(&*GLOBAL, texture_id)) } -pub fn texture_view_destroy(texture_view_id: TextureViewId) { - let hub = B::hub(); +pub fn texture_view_destroy( + global: &Global, texture_view_id: TextureViewId +) { + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); let (texture_guard, mut token) = hub.textures.read(&mut token); @@ -1039,17 +1052,19 @@ pub fn texture_view_destroy(texture_view_id: TextureViewId) { ); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_texture_view_destroy(texture_view_id: TextureViewId) { - gfx_select!(texture_view_id => texture_view_destroy(texture_view_id)) + gfx_select!(texture_view_id => texture_view_destroy(&*GLOBAL, texture_view_id)) } pub fn device_create_sampler( + global: &Global, device_id: DeviceId, desc: &resource::SamplerDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[device_id]; @@ -1092,11 +1107,11 @@ pub extern "C" fn wgpu_device_create_sampler( device_id: DeviceId, desc: &resource::SamplerDescriptor, ) -> SamplerId { - gfx_select!(device_id => device_create_sampler(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_sampler(&*GLOBAL, device_id, desc, PhantomData)) } -pub fn sampler_destroy(sampler_id: SamplerId) { - let hub = B::hub(); +pub fn sampler_destroy(global: &Global, sampler_id: SamplerId) { + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); let (sampler_guard, _) = hub.samplers.read(&mut token); @@ -1110,18 +1125,20 @@ pub fn sampler_destroy(sampler_id: SamplerId) { ); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_sampler_destroy(sampler_id: SamplerId) { - gfx_select!(sampler_id => sampler_destroy(sampler_id)) + gfx_select!(sampler_id => sampler_destroy(&*GLOBAL, sampler_id)) } pub fn device_create_bind_group_layout( + global: &Global, device_id: DeviceId, desc: &binding_model::BindGroupLayoutDescriptor, id_in: Input, ) -> Output { let mut token = Token::root(); - let hub = B::hub(); + let hub = B::hub(global); let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) }; let raw_bindings = bindings @@ -1160,15 +1177,16 @@ pub extern "C" fn wgpu_device_create_bind_group_layout( device_id: DeviceId, desc: &binding_model::BindGroupLayoutDescriptor, ) -> BindGroupLayoutId { - gfx_select!(device_id => device_create_bind_group_layout(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_bind_group_layout(&*GLOBAL, device_id, desc, PhantomData)) } pub fn device_create_pipeline_layout( + global: &Global, device_id: DeviceId, desc: &binding_model::PipelineLayoutDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -1203,15 +1221,16 @@ pub extern "C" fn wgpu_device_create_pipeline_layout( device_id: DeviceId, desc: &binding_model::PipelineLayoutDescriptor, ) -> PipelineLayoutId { - gfx_select!(device_id => device_create_pipeline_layout(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_pipeline_layout(&*GLOBAL, device_id, desc, PhantomData)) } pub fn device_create_bind_group( + global: &Global, device_id: DeviceId, desc: &binding_model::BindGroupDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -1377,11 +1396,11 @@ pub extern "C" fn wgpu_device_create_bind_group( device_id: DeviceId, desc: &binding_model::BindGroupDescriptor, ) -> BindGroupId { - gfx_select!(device_id => device_create_bind_group(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_bind_group(&*GLOBAL, device_id, desc, PhantomData)) } -pub fn bind_group_destroy(bind_group_id: BindGroupId) { - let hub = B::hub(); +pub fn bind_group_destroy(global: &Global, bind_group_id: BindGroupId) { + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); let (bind_group_guard, _) = hub.bind_groups.read(&mut token); @@ -1395,17 +1414,19 @@ pub fn bind_group_destroy(bind_group_id: BindGroupId) { ); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_bind_group_destroy(bind_group_id: BindGroupId) { - gfx_select!(bind_group_id => bind_group_destroy(bind_group_id)) + gfx_select!(bind_group_id => bind_group_destroy(&*GLOBAL, bind_group_id)) } pub fn device_create_shader_module( + global: &Global, device_id: DeviceId, desc: &pipeline::ShaderModuleDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let spv = unsafe { slice::from_raw_parts(desc.code.bytes, desc.code.length) }; @@ -1430,15 +1451,16 @@ pub extern "C" fn wgpu_device_create_shader_module( device_id: DeviceId, desc: &pipeline::ShaderModuleDescriptor, ) -> ShaderModuleId { - gfx_select!(device_id => device_create_shader_module(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_shader_module(&*GLOBAL, device_id, desc, PhantomData)) } pub fn device_create_command_encoder( + global: &Global, device_id: DeviceId, _desc: &command::CommandEncoderDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -1467,16 +1489,21 @@ pub extern "C" fn wgpu_device_create_command_encoder( desc: Option<&command::CommandEncoderDescriptor>, ) -> CommandEncoderId { let desc = &desc.cloned().unwrap_or_default(); - gfx_select!(device_id => device_create_command_encoder(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_command_encoder(&*GLOBAL, device_id, desc, PhantomData)) } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_device_get_queue(device_id: DeviceId) -> QueueId { device_id } -pub fn queue_submit(queue_id: QueueId, command_buffer_ids: &[CommandBufferId]) { - let hub = B::hub(); +pub fn queue_submit( + global: &Global, + queue_id: QueueId, + command_buffer_ids: &[CommandBufferId], +) { + let hub = B::hub(global); let (submit_index, fence) = { let mut token = Token::root(); @@ -1607,7 +1634,7 @@ pub fn queue_submit(queue_id: QueueId, command_buffer_ids: &[Comm let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[queue_id]; - let callbacks = device.maintain(false, &mut token); + let callbacks = device.maintain(global, false, &mut token); device.pending.lock().active.alloc().init(ActiveSubmission { index: submit_index, fence, @@ -1627,6 +1654,7 @@ pub fn queue_submit(queue_id: QueueId, command_buffer_ids: &[Comm Device::::fire_map_callbacks(callbacks); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_queue_submit( queue_id: QueueId, @@ -1635,15 +1663,16 @@ pub extern "C" fn wgpu_queue_submit( ) { let command_buffer_ids = unsafe { slice::from_raw_parts(command_buffers, command_buffers_length) }; - gfx_select!(queue_id => queue_submit(queue_id, command_buffer_ids)) + gfx_select!(queue_id => queue_submit(&*GLOBAL, queue_id, command_buffer_ids)) } pub fn device_create_render_pipeline( + global: &Global, device_id: DeviceId, desc: &pipeline::RenderPipelineDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let sc = desc.sample_count; @@ -1904,15 +1933,16 @@ pub extern "C" fn wgpu_device_create_render_pipeline( device_id: DeviceId, desc: &pipeline::RenderPipelineDescriptor, ) -> RenderPipelineId { - gfx_select!(device_id => device_create_render_pipeline(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_render_pipeline(&*GLOBAL, device_id, desc, PhantomData)) } pub fn device_create_compute_pipeline( + global: &Global, device_id: DeviceId, desc: &pipeline::ComputePipelineDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let raw_pipeline = { @@ -1965,19 +1995,20 @@ pub extern "C" fn wgpu_device_create_compute_pipeline( device_id: DeviceId, desc: &pipeline::ComputePipelineDescriptor, ) -> ComputePipelineId { - gfx_select!(device_id => device_create_compute_pipeline(device_id, desc, PhantomData)) + gfx_select!(device_id => device_create_compute_pipeline(&*GLOBAL, device_id, desc, PhantomData)) } pub fn device_create_swap_chain( + global: &Global, device_id: DeviceId, surface_id: SurfaceId, desc: &swap_chain::SwapChainDescriptor, ) -> SwapChainId { log::info!("creating swap chain {:?}", desc); - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); - let (mut surface_guard, mut token) = GLOBAL.surfaces.write(&mut token); + let (mut surface_guard, mut token) = global.surfaces.write(&mut token); let (adapter_guard, mut token) = hub.adapters.read(&mut token); let (device_guard, mut token) = hub.devices.read(&mut token); let (mut swap_chain_guard, _) = hub.swap_chains.write(&mut token); @@ -2046,33 +2077,35 @@ pub extern "C" fn wgpu_device_create_swap_chain( surface_id: SurfaceId, desc: &swap_chain::SwapChainDescriptor, ) -> SwapChainId { - gfx_select!(device_id => device_create_swap_chain(device_id, surface_id, desc)) + gfx_select!(device_id => device_create_swap_chain(&*GLOBAL, device_id, surface_id, desc)) } -pub fn device_poll(device_id: DeviceId, force_wait: bool) { - let hub = B::hub(); +pub fn device_poll(global: &Global, device_id: DeviceId, force_wait: bool) { + let hub = B::hub(global); let callbacks = { let (device_guard, mut token) = hub.devices.read(&mut Token::root()); - device_guard[device_id].maintain(force_wait, &mut token) + device_guard[device_id].maintain(global, force_wait, &mut token) }; Device::::fire_map_callbacks(callbacks); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_device_poll(device_id: DeviceId, force_wait: bool) { - gfx_select!(device_id => device_poll(device_id, force_wait)) + gfx_select!(device_id => device_poll(&*GLOBAL, device_id, force_wait)) } -pub fn device_destroy(device_id: DeviceId) { - let hub = B::hub(); +pub fn device_destroy(global: &Global, device_id: DeviceId) { + let hub = B::hub(global); let (device, mut token) = hub.devices.unregister(device_id, &mut Token::root()); - device.maintain(true, &mut token); + device.maintain(global, true, &mut token); device.com_allocator.destroy(&device.raw); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_device_destroy(device_id: DeviceId) { - gfx_select!(device_id => device_destroy(device_id)) + gfx_select!(device_id => device_destroy(&*GLOBAL, device_id)) } pub type BufferMapReadCallback = @@ -2081,11 +2114,12 @@ pub type BufferMapWriteCallback = extern "C" fn(status: BufferMapAsyncStatus, data: *mut u8, userdata: *mut u8); pub fn buffer_map_async( + global: &Global, buffer_id: BufferId, usage: resource::BufferUsage, operation: BufferMapOperation, ) { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -2121,6 +2155,7 @@ pub fn buffer_map_async( device.pending.lock().map(buffer_id, ref_count); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_buffer_map_read_async( buffer_id: BufferId, @@ -2130,9 +2165,10 @@ pub extern "C" fn wgpu_buffer_map_read_async( userdata: *mut u8, ) { let operation = BufferMapOperation::Read(start .. start + size, callback, userdata); - gfx_select!(buffer_id => buffer_map_async(buffer_id, resource::BufferUsage::MAP_READ, operation)) + gfx_select!(buffer_id => buffer_map_async(&*GLOBAL, buffer_id, resource::BufferUsage::MAP_READ, operation)) } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_buffer_map_write_async( buffer_id: BufferId, @@ -2142,11 +2178,11 @@ pub extern "C" fn wgpu_buffer_map_write_async( userdata: *mut u8, ) { let operation = BufferMapOperation::Write(start .. start + size, callback, userdata); - gfx_select!(buffer_id => buffer_map_async(buffer_id, resource::BufferUsage::MAP_WRITE, operation)) + gfx_select!(buffer_id => buffer_map_async(&*GLOBAL, buffer_id, resource::BufferUsage::MAP_WRITE, operation)) } -pub fn buffer_unmap(buffer_id: BufferId) { - let hub = B::hub(); +pub fn buffer_unmap(global: &Global, buffer_id: BufferId) { + let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -2172,7 +2208,8 @@ pub fn buffer_unmap(buffer_id: BufferId) { buffer.memory.unmap(device_raw); } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_buffer_unmap(buffer_id: BufferId) { - gfx_select!(buffer_id => buffer_unmap(buffer_id)) + gfx_select!(buffer_id => buffer_unmap(&*GLOBAL, buffer_id)) } diff --git a/wgpu-native/src/hub.rs b/wgpu-native/src/hub.rs index c14893bec..2f6639194 100644 --- a/wgpu-native/src/hub.rs +++ b/wgpu-native/src/hub.rs @@ -46,15 +46,16 @@ use crate::{ TypedId, }; -use lazy_static::lazy_static; #[cfg(not(feature = "remote"))] use parking_lot::Mutex; use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use vec_map::VecMap; -#[allow(unused)] +#[cfg(debug_assertions)] use std::cell::Cell; -use std::{marker::PhantomData, ops, sync::Arc}; +#[cfg(not(feature = "remote"))] +use std::sync::Arc; +use std::{marker::PhantomData, ops}; /// A simple structure to manage identities of objects. @@ -406,7 +407,8 @@ pub struct Global { hubs: Hubs, } -lazy_static! { +#[cfg(not(feature = "remote"))] +lazy_static::lazy_static! { pub static ref GLOBAL: Arc = Arc::new(Global { instance: Instance::new("wgpu", 1), surfaces: Registry::new(Backend::Empty), @@ -416,15 +418,15 @@ lazy_static! { pub trait GfxBackend: hal::Backend { const VARIANT: Backend; - fn hub() -> &'static Hub; + fn hub(global: &Global) -> &Hub; fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface; } #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] impl GfxBackend for backend::Vulkan { const VARIANT: Backend = Backend::Vulkan; - fn hub() -> &'static Hub { - &GLOBAL.hubs.vulkan + fn hub(global: &Global) -> &Hub { + &global.hubs.vulkan } fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface { surface.vulkan.as_mut().unwrap() @@ -434,8 +436,8 @@ impl GfxBackend for backend::Vulkan { #[cfg(any(target_os = "ios", target_os = "macos"))] impl GfxBackend for backend::Metal { const VARIANT: Backend = Backend::Metal; - fn hub() -> &'static Hub { - &GLOBAL.hubs.metal + fn hub(global: &Global) -> &Hub { + &global.hubs.metal } fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface { &mut surface.metal @@ -445,8 +447,8 @@ impl GfxBackend for backend::Metal { #[cfg(windows)] impl GfxBackend for backend::Dx12 { const VARIANT: Backend = Backend::Dx12; - fn hub() -> &'static Hub { - &GLOBAL.hubs.dx12 + fn hub(global: &Global) -> &Hub { + &global.hubs.dx12 } fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface { surface.dx12.as_mut().unwrap() @@ -456,8 +458,8 @@ impl GfxBackend for backend::Dx12 { #[cfg(windows)] impl GfxBackend for backend::Dx11 { const VARIANT: Backend = Backend::Dx11; - fn hub() -> &'static Hub { - &GLOBAL.hubs.dx11 + fn hub(global: &Global) -> &Hub { + &global.hubs.dx11 } fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface { &mut surface.dx11 diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index 51469893c..e1342d43d 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -6,7 +6,7 @@ use crate::{ backend, binding_model::MAX_BIND_GROUPS, device::BIND_BUFFER_ALIGNMENT, - hub::{GfxBackend, Token, GLOBAL}, + hub::{GfxBackend, Global, Token}, id::{Input, Output}, AdapterId, AdapterInfo, @@ -15,7 +15,7 @@ use crate::{ DeviceId, }; #[cfg(not(feature = "remote"))] -use crate::{gfx_select, SurfaceId}; +use crate::{gfx_select, SurfaceId, hub::GLOBAL}; #[cfg(not(feature = "remote"))] use bitflags::bitflags; @@ -46,7 +46,7 @@ pub struct Instance { } impl Instance { - pub(crate) fn new(name: &str, version: u32) -> Self { + pub fn new(name: &str, version: u32) -> Self { Instance { #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] vulkan: gfx_backend_vulkan::Instance::create(name, version).ok(), @@ -267,10 +267,11 @@ pub extern "C" fn wgpu_create_surface_from_windows_hwnd( } pub fn request_adapter( + global: &Global, desc: &RequestAdapterOptions, input_ids: &[Input], ) -> Option { - let instance = &GLOBAL.instance; + let instance = &global.instance; let mut device_types = Vec::new(); #[cfg(feature = "remote")] @@ -367,7 +368,7 @@ pub fn request_adapter( raw: adapters_vk.swap_remove(selected), }; info!("Adapter Vulkan {:?}", adapter.raw.info); - let id_out = backend::Vulkan::hub().adapters.register_identity( + let id_out = backend::Vulkan::hub(global).adapters.register_identity( id_vulkan.unwrap(), adapter, &mut token, @@ -383,7 +384,7 @@ pub fn request_adapter( raw: adapters_mtl.swap_remove(selected), }; info!("Adapter Metal {:?}", adapter.raw.info); - let id_out = backend::Metal::hub().adapters.register_identity( + let id_out = backend::Metal::hub(global).adapters.register_identity( id_metal.unwrap(), adapter, &mut token, @@ -399,7 +400,7 @@ pub fn request_adapter( raw: adapters_dx12.swap_remove(selected), }; info!("Adapter Dx12 {:?}", adapter.raw.info); - let id_out = backend::Dx12::hub().adapters.register_identity( + let id_out = backend::Dx12::hub(global).adapters.register_identity( id_dx12.unwrap(), adapter, &mut token, @@ -412,7 +413,7 @@ pub fn request_adapter( raw: adapters_dx11.swap_remove(selected), }; info!("Adapter Dx11 {:?}", adapter.raw.info); - let id_out = backend::Dx11::hub().adapters.register_identity( + let id_out = backend::Dx11::hub(global).adapters.register_identity( id_dx11.unwrap(), adapter, &mut token, @@ -428,15 +429,16 @@ pub fn request_adapter( #[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_request_adapter(desc: Option<&RequestAdapterOptions>) -> AdapterId { - request_adapter(&desc.cloned().unwrap_or_default(), &[]).unwrap() + request_adapter(&*GLOBAL, &desc.cloned().unwrap_or_default(), &[]).unwrap() } pub fn adapter_request_device( + global: &Global, adapter_id: AdapterId, desc: &DeviceDescriptor, id_in: Input, ) -> Output { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); let device = { let (adapter_guard, _) = hub.adapters.read(&mut token); @@ -503,11 +505,11 @@ pub extern "C" fn wgpu_adapter_request_device( desc: Option<&DeviceDescriptor>, ) -> DeviceId { let desc = &desc.cloned().unwrap_or_default(); - gfx_select!(adapter_id => adapter_request_device(adapter_id, desc, PhantomData)) + gfx_select!(adapter_id => adapter_request_device(&*GLOBAL, adapter_id, desc, PhantomData)) } -pub fn adapter_get_info(adapter_id: AdapterId) -> AdapterInfo { - let hub = B::hub(); +pub fn adapter_get_info(global: &Global, adapter_id: AdapterId) -> AdapterInfo { + let hub = B::hub(global); let mut token = Token::root(); let (adapter_guard, _) = hub.adapters.read(&mut token); let adapter = &adapter_guard[adapter_id]; @@ -518,5 +520,5 @@ pub fn adapter_get_info(adapter_id: AdapterId) -> AdapterInfo { pub fn wgpu_adapter_get_info( adapter_id: AdapterId ) -> AdapterInfo { - gfx_select!(adapter_id => adapter_get_info(adapter_id)) + gfx_select!(adapter_id => adapter_get_info(&*GLOBAL, adapter_id)) } diff --git a/wgpu-native/src/swap_chain.rs b/wgpu-native/src/swap_chain.rs index 3846869db..3ddf18e4a 100644 --- a/wgpu-native/src/swap_chain.rs +++ b/wgpu-native/src/swap_chain.rs @@ -34,8 +34,7 @@ use crate::{ conv, - gfx_select, - hub::{GLOBAL, GfxBackend, Token}, + hub::{GfxBackend, Global, Token}, resource, DeviceId, Extent3d, @@ -46,6 +45,8 @@ use crate::{ SwapChainId, TextureViewId, }; +#[cfg(not(feature = "remote"))] +use crate::{gfx_select, hub::GLOBAL}; use hal::{ self, @@ -129,13 +130,14 @@ pub struct SwapChainOutput { } pub fn swap_chain_get_next_texture( + global: &Global, swap_chain_id: SwapChainId, view_id_in: Input, ) -> SwapChainOutput { - let hub = B::hub(); + let hub = B::hub(global); let mut token = Token::root(); - let (mut surface_guard, mut token) = GLOBAL.surfaces.write(&mut token); + let (mut surface_guard, mut token) = global.surfaces.write(&mut token); let surface = &mut surface_guard[swap_chain_id.to_surface_id()]; let (device_guard, mut token) = hub.devices.read(&mut token); let (mut swap_chain_guard, mut token) = hub.swap_chains.write(&mut token); @@ -205,14 +207,14 @@ pub fn swap_chain_get_next_texture( #[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) -> SwapChainOutput { - gfx_select!(swap_chain_id => swap_chain_get_next_texture(swap_chain_id, PhantomData)) + gfx_select!(swap_chain_id => swap_chain_get_next_texture(&*GLOBAL, swap_chain_id, PhantomData)) } -pub fn swap_chain_present(swap_chain_id: SwapChainId) { - let hub = B::hub(); +pub fn swap_chain_present(global: &Global, swap_chain_id: SwapChainId) { + let hub = B::hub(global); let mut token = Token::root(); - let (mut surface_guard, mut token) = GLOBAL.surfaces.write(&mut token); + let (mut surface_guard, mut token) = global.surfaces.write(&mut token); let surface = &mut surface_guard[swap_chain_id.to_surface_id()]; let (mut device_guard, mut token) = hub.devices.write(&mut token); let (mut swap_chain_guard, mut token) = hub.swap_chains.write(&mut token); @@ -247,7 +249,8 @@ pub fn swap_chain_present(swap_chain_id: SwapChainId) { } } +#[cfg(not(feature = "remote"))] #[no_mangle] pub extern "C" fn wgpu_swap_chain_present(swap_chain_id: SwapChainId) { - gfx_select!(swap_chain_id => swap_chain_present(swap_chain_id)) + gfx_select!(swap_chain_id => swap_chain_present(&*GLOBAL, swap_chain_id)) } diff --git a/wgpu-remote/src/server.rs b/wgpu-remote/src/server.rs index fe743de83..a909cb7ed 100644 --- a/wgpu-remote/src/server.rs +++ b/wgpu-remote/src/server.rs @@ -23,7 +23,8 @@ enum ControlFlow { Terminate, } -fn process(message: GlobalMessage) -> ControlFlow { +fn process(_message: GlobalMessage) -> ControlFlow { + /* match message { GlobalMessage::RequestAdapter(ref desc, ref ids) => { wgn::request_adapter(desc, ids); @@ -33,7 +34,7 @@ fn process(message: GlobalMessage) -> ControlFlow { wgn::gfx_select!(adapter_id => fun(adapter_id, desc, id)); } GlobalMessage::Terminate => return ControlFlow::Terminate, - } + }*/ ControlFlow::Continue }