Skip to content
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

Explicit Global hubs #357

Merged
merged 4 commits into from
Oct 25, 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ before_install:
script:
- cargo test
# TODO: enable GL backend
#- (cd wgpu-native && cargo check --features local,glutin)
- (cd wgpu-native && cargo check --features local)
- if [[ $TRAVIS_OS_NAME == "osx" ]]; then (cd wgpu-native && cargo check --features gfx-backend-vulkan); fi
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cargo check --release; fi
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo +nightly install cbindgen; fi
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ clear:
$(CLEAN_FFI_DIR)

lib-native: Cargo.lock wgpu-native/Cargo.toml $(WILDCARD_WGPU_NATIVE)
cargo build --manifest-path wgpu-native/Cargo.toml
cargo build --manifest-path wgpu-native/Cargo.toml --features local

lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
cargo build --manifest-path wgpu-remote/Cargo.toml
Expand Down
124 changes: 102 additions & 22 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,257 +665,337 @@ typedef struct {
uint32_t array_layer_count;
} WGPUTextureViewDescriptor;

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUDeviceId wgpu_adapter_request_device(WGPUAdapterId adapter_id,
const WGPUDeviceDescriptor *desc);
#endif

#if defined(WGPU_LOCAL)
void wgpu_bind_group_destroy(WGPUBindGroupId bind_group_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_buffer_destroy(WGPUBufferId buffer_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_buffer_map_read_async(WGPUBufferId buffer_id,
WGPUBufferAddress start,
WGPUBufferAddress size,
WGPUBufferMapReadCallback callback,
uint8_t *userdata);
#endif

#if defined(WGPU_LOCAL)
void wgpu_buffer_map_write_async(WGPUBufferId buffer_id,
WGPUBufferAddress start,
WGPUBufferAddress size,
WGPUBufferMapWriteCallback callback,
uint8_t *userdata);
#endif

#if defined(WGPU_LOCAL)
void wgpu_buffer_unmap(WGPUBufferId buffer_id);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUComputePassId wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encoder_id,
const WGPUComputePassDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
const WGPURenderPassDescriptor *desc);
#endif

#if defined(WGPU_LOCAL)
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_LOCAL)
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_LOCAL)
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_LOCAL)
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_LOCAL)
WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId encoder_id,
const WGPUCommandBufferDescriptor *desc);
#endif

#if defined(WGPU_LOCAL)
void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z);
#endif

#if defined(WGPU_LOCAL)
void wgpu_compute_pass_dispatch_indirect(WGPUComputePassId pass_id,
WGPUBufferId indirect_buffer_id,
WGPUBufferAddress indirect_offset);
#endif

#if defined(WGPU_LOCAL)
void wgpu_compute_pass_end_pass(WGPUComputePassId pass_id);
#endif

void wgpu_compute_pass_insert_debug_marker(WGPUComputePassId _pass_id, WGPURawString _label);

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_LOCAL)
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_LOCAL)
void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipelineId pipeline_id);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUSurfaceId wgpu_create_surface_from_metal_layer(void *layer);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUSurfaceId wgpu_create_surface_from_windows_hwnd(void *_hinstance, void *hwnd);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUSurfaceId wgpu_create_surface_from_xlib(const void **display, uint64_t window);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUBindGroupId wgpu_device_create_bind_group(WGPUDeviceId device_id,
const WGPUBindGroupDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUBindGroupLayoutId wgpu_device_create_bind_group_layout(WGPUDeviceId device_id,
const WGPUBindGroupLayoutDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUBufferId wgpu_device_create_buffer(WGPUDeviceId device_id, const WGPUBufferDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUBufferId wgpu_device_create_buffer_mapped(WGPUDeviceId device_id,
const WGPUBufferDescriptor *desc,
uint8_t **mapped_ptr_out);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUCommandEncoderId wgpu_device_create_command_encoder(WGPUDeviceId device_id,
const WGPUCommandEncoderDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUComputePipelineId wgpu_device_create_compute_pipeline(WGPUDeviceId device_id,
const WGPUComputePipelineDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUPipelineLayoutId wgpu_device_create_pipeline_layout(WGPUDeviceId device_id,
const WGPUPipelineLayoutDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPURenderPipelineId wgpu_device_create_render_pipeline(WGPUDeviceId device_id,
const WGPURenderPipelineDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUSamplerId wgpu_device_create_sampler(WGPUDeviceId device_id, const WGPUSamplerDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUShaderModuleId wgpu_device_create_shader_module(WGPUDeviceId device_id,
const WGPUShaderModuleDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id,
WGPUSurfaceId surface_id,
const WGPUSwapChainDescriptor *desc);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc);
#endif

#if defined(WGPU_LOCAL)
void wgpu_device_destroy(WGPUDeviceId device_id);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
void wgpu_device_get_limits(WGPUDeviceId _device_id, WGPULimits *limits);
#endif

#if defined(WGPU_LOCAL)
WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_device_poll(WGPUDeviceId device_id, bool force_wait);
#endif

#if defined(WGPU_LOCAL)
void wgpu_queue_submit(WGPUQueueId queue_id,
const WGPUCommandBufferId *command_buffers,
uintptr_t command_buffers_length);
#endif

#if defined(WGPU_LOCAL)
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_LOCAL)
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_LOCAL)
void wgpu_render_pass_draw_indexed_indirect(WGPURenderPassId pass_id,
WGPUBufferId indirect_buffer_id,
WGPUBufferAddress indirect_offset);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_draw_indirect(WGPURenderPassId pass_id,
WGPUBufferId indirect_buffer_id,
WGPUBufferAddress indirect_offset);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_end_pass(WGPURenderPassId pass_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_execute_bundles(WGPURenderPassId _pass_id,
const WGPURenderBundleId *_bundles,
uintptr_t _bundles_length);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_insert_debug_marker(WGPURenderPassId _pass_id, WGPURawString _label);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_pop_debug_group(WGPURenderPassId _pass_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_push_debug_group(WGPURenderPassId _pass_id, WGPURawString _label);
#endif

#if defined(WGPU_LOCAL)
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_LOCAL)
void wgpu_render_pass_set_blend_color(WGPURenderPassId pass_id, const WGPUColor *color);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_set_index_buffer(WGPURenderPassId pass_id,
WGPUBufferId buffer_id,
WGPUBufferAddress offset);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_set_pipeline(WGPURenderPassId pass_id, WGPURenderPipelineId pipeline_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_set_scissor_rect(WGPURenderPassId pass_id,
uint32_t x,
uint32_t y,
uint32_t w,
uint32_t h);
#endif

#if defined(WGPU_LOCAL)
void wgpu_render_pass_set_stencil_reference(WGPURenderPassId pass_id, uint32_t value);
#endif

#if defined(WGPU_LOCAL)
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_LOCAL)
void wgpu_render_pass_set_viewport(WGPURenderPassId pass_id,
float x,
float y,
float w,
float h,
float min_depth,
float max_depth);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUAdapterId wgpu_request_adapter(const WGPURequestAdapterOptions *desc);
#endif

#if defined(WGPU_LOCAL)
void wgpu_sampler_destroy(WGPUSamplerId sampler_id);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUSwapChainOutput wgpu_swap_chain_get_next_texture(WGPUSwapChainId swap_chain_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_swap_chain_present(WGPUSwapChainId swap_chain_id);
#endif

#if !defined(WGPU_REMOTE)
#if defined(WGPU_LOCAL)
WGPUTextureViewId wgpu_texture_create_view(WGPUTextureId texture_id,
const WGPUTextureViewDescriptor *desc);
#endif

#if defined(WGPU_LOCAL)
void wgpu_texture_destroy(WGPUTextureId texture_id);
#endif

#if defined(WGPU_LOCAL)
void wgpu_texture_view_destroy(WGPUTextureViewId texture_view_id);
#endif
4 changes: 2 additions & 2 deletions wgpu-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ crate-type = ["lib", "cdylib", "staticlib"]

[features]
default = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to move to local instead of remote? I could see usefulness in being able to opt out of remote-specific concepts if we expose more in wgpu-native (even though we don't have much currently). Either way it might still be good to list local as a default feature to make it easier for people to build wgpu-native directly (thinking of https://nest.pijul.com/porky11/wgpu for example)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The answer is - remote used to add some extra capabilities, like the Serde derives. As I was trying to integrate it into Gecko, I realized that using Gecko's IPC is the only way. That means Serde is no longer useful, or at least, doesn't get associated with "remote" feature.

At the same time, this PR gets rid of the static GLOBAL in general case. So it's "local" that adds features now: it exposes C entry points and declares a lazy static used in them.

remote = ["serde"]
local = ["lazy_static"]
metal-auto-capture = ["gfx-backend-metal/auto-capture"]
#NOTE: glutin feature is not stable, use at your own risk
#glutin = ["gfx-backend-gl/glutin"]
Expand All @@ -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 = { version = "1.1.0", optional = true }
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" }
Expand Down
Loading