From 6a1dcb9565002a7bdec1ff40710ce2f8d1a98966 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 14 May 2019 08:03:26 -0400 Subject: [PATCH 1/5] API update with naming, formats, and extra fields --- examples/hello_triangle_c/main.c | 16 +-- ffi/wgpu-remote.h | 5 + ffi/wgpu.h | 178 +++++++++++++--------------- wgpu-native/src/binding_model.rs | 16 +-- wgpu-native/src/command/mod.rs | 7 +- wgpu-native/src/command/render.rs | 21 +++- wgpu-native/src/command/transfer.rs | 68 +++++------ wgpu-native/src/conv.rs | 69 ++++------- wgpu-native/src/device.rs | 100 ++++++++-------- wgpu-native/src/instance.rs | 22 +++- wgpu-native/src/lib.rs | 18 ++- wgpu-native/src/pipeline.rs | 45 ++----- wgpu-native/src/resource.rs | 32 ++--- wgpu-native/src/swap_chain.rs | 8 +- wgpu-native/src/track.rs | 14 +-- 15 files changed, 308 insertions(+), 311 deletions(-) diff --git a/examples/hello_triangle_c/main.c b/examples/hello_triangle_c/main.c index d81506a54b..b1352f46da 100644 --- a/examples/hello_triangle_c/main.c +++ b/examples/hello_triangle_c/main.c @@ -49,7 +49,7 @@ int main() { .power_preference = WGPUPowerPreference_LowPower, }); - WGPUDeviceId device = wgpu_adapter_create_device(adapter, + WGPUDeviceId device = wgpu_adapter_request_device(adapter, &(WGPUDeviceDescriptor){ .extensions = { @@ -102,7 +102,7 @@ int main() { .entry_point = "main", }, .fragment_stage = - (WGPUPipelineStageDescriptor){ + &(WGPUPipelineStageDescriptor){ .module = fragment_shader, .entry_point = "main", }, @@ -118,24 +118,24 @@ int main() { .color_states = &(WGPUColorStateDescriptor){ .format = WGPUTextureFormat_Bgra8Unorm, - .alpha = + .alpha_blend = (WGPUBlendDescriptor){ .src_factor = WGPUBlendFactor_One, .dst_factor = WGPUBlendFactor_Zero, .operation = WGPUBlendOperation_Add, }, - .color = + .color_blend = (WGPUBlendDescriptor){ .src_factor = WGPUBlendFactor_One, .dst_factor = WGPUBlendFactor_Zero, .operation = WGPUBlendOperation_Add, }, - .write_mask = WGPUColorWriteFlags_ALL, + .write_mask = WGPUColorWrite_ALL, }, .color_states_length = 1, .depth_stencil_state = NULL, - .vertex_buffer_state = - (WGPUVertexBufferStateDescriptor){ + .vertex_input = + (WGPUVertexInputDescriptor){ .index_format = WGPUIndexFormat_Uint16, .vertex_buffers = NULL, .vertex_buffers_count = 0, @@ -194,7 +194,7 @@ int main() { WGPUSwapChainId swap_chain = wgpu_device_create_swap_chain(device, surface, &(WGPUSwapChainDescriptor){ - .usage = WGPUTextureUsageFlags_OUTPUT_ATTACHMENT, + .usage = WGPUTextureUsage_OUTPUT_ATTACHMENT, .format = WGPUTextureFormat_Bgra8Unorm, .width = prev_width, .height = prev_height, diff --git a/ffi/wgpu-remote.h b/ffi/wgpu-remote.h index dd528251f5..e41ecdc9e0 100644 --- a/ffi/wgpu-remote.h +++ b/ffi/wgpu-remote.h @@ -38,8 +38,13 @@ typedef struct { bool anisotropic_filtering; } WGPUExtensions; +typedef struct { + uint32_t max_bind_groups; +} WGPULimits; + typedef struct { WGPUExtensions extensions; + WGPULimits limits; } WGPUDeviceDescriptor; typedef struct { diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 03c9085cc8..e12762ae69 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -15,7 +15,6 @@ typedef enum { WGPUAddressMode_ClampToEdge = 0, WGPUAddressMode_Repeat = 1, WGPUAddressMode_MirrorRepeat = 2, - WGPUAddressMode_ClampToBorderColor = 3, } WGPUAddressMode; typedef enum { @@ -25,6 +24,7 @@ typedef enum { WGPUBindingType_StorageBuffer = 3, WGPUBindingType_UniformBufferDynamic = 4, WGPUBindingType_StorageBufferDynamic = 5, + WGPUBindingType_StorageTexture = 10, } WGPUBindingType; typedef enum { @@ -51,12 +51,6 @@ typedef enum { WGPUBlendOperation_Max = 4, } WGPUBlendOperation; -typedef enum { - WGPUBorderColor_TransparentBlack = 0, - WGPUBorderColor_OpaqueBlack = 1, - WGPUBorderColor_OpaqueWhite = 2, -} WGPUBorderColor; - typedef enum { WGPUBufferMapAsyncStatus_Success, WGPUBufferMapAsyncStatus_Error, @@ -202,42 +196,23 @@ typedef enum { } WGPUTextureViewDimension; typedef enum { - WGPUVertexFormat_Uchar = 0, WGPUVertexFormat_Uchar2 = 1, - WGPUVertexFormat_Uchar3 = 2, WGPUVertexFormat_Uchar4 = 3, - WGPUVertexFormat_Char = 4, WGPUVertexFormat_Char2 = 5, - WGPUVertexFormat_Char3 = 6, WGPUVertexFormat_Char4 = 7, - WGPUVertexFormat_UcharNorm = 8, WGPUVertexFormat_Uchar2Norm = 9, - WGPUVertexFormat_Uchar3Norm = 10, WGPUVertexFormat_Uchar4Norm = 11, - WGPUVertexFormat_Uchar4NormBgra = 12, - WGPUVertexFormat_CharNorm = 13, WGPUVertexFormat_Char2Norm = 14, - WGPUVertexFormat_Char3Norm = 15, WGPUVertexFormat_Char4Norm = 16, - WGPUVertexFormat_Ushort = 17, WGPUVertexFormat_Ushort2 = 18, - WGPUVertexFormat_Ushort3 = 19, WGPUVertexFormat_Ushort4 = 20, - WGPUVertexFormat_Short = 21, WGPUVertexFormat_Short2 = 22, - WGPUVertexFormat_Short3 = 23, WGPUVertexFormat_Short4 = 24, - WGPUVertexFormat_UshortNorm = 25, WGPUVertexFormat_Ushort2Norm = 26, - WGPUVertexFormat_Ushort3Norm = 27, WGPUVertexFormat_Ushort4Norm = 28, - WGPUVertexFormat_ShortNorm = 29, WGPUVertexFormat_Short2Norm = 30, - WGPUVertexFormat_Short3Norm = 31, WGPUVertexFormat_Short4Norm = 32, - WGPUVertexFormat_Half = 33, WGPUVertexFormat_Half2 = 34, - WGPUVertexFormat_Half3 = 35, WGPUVertexFormat_Half4 = 36, WGPUVertexFormat_Float = 37, WGPUVertexFormat_Float2 = 38, @@ -272,14 +247,21 @@ typedef struct { bool anisotropic_filtering; } WGPUExtensions; +typedef struct { + uint32_t max_bind_groups; +} WGPULimits; + typedef struct { WGPUExtensions extensions; + WGPULimits limits; } WGPUDeviceDescriptor; typedef WGPUId WGPUBindGroupId; typedef WGPUId WGPUBufferId; +typedef uint64_t WGPUBufferAddress; + typedef void (*WGPUBufferMapReadCallback)(WGPUBufferMapAsyncStatus status, const uint8_t *data, uint8_t *userdata); typedef void (*WGPUBufferMapWriteCallback)(WGPUBufferMapAsyncStatus status, uint8_t *data, uint8_t *userdata); @@ -288,7 +270,7 @@ typedef WGPUId WGPUCommandBufferId; typedef struct { WGPUBufferId buffer; - uint32_t offset; + WGPUBufferAddress offset; uint32_t row_pitch; uint32_t image_height; } WGPUBufferCopyView; @@ -300,11 +282,12 @@ typedef struct { float y; float z; } WGPUOrigin3d; +#define WGPUOrigin3d_ZERO (WGPUOrigin3d){ .x = 0, .y = 0, .z = 0 } typedef struct { WGPUTextureId texture; - uint32_t level; - uint32_t slice; + uint32_t mip_level; + uint32_t array_layer; WGPUOrigin3d origin; } WGPUTextureCopyView; @@ -337,6 +320,7 @@ typedef struct { typedef struct { WGPUTextureViewId attachment; + const WGPUTextureViewId *resolve_target; WGPULoadOp load_op; WGPUStoreOp store_op; WGPUColor clear_color; @@ -366,8 +350,8 @@ typedef WGPUId WGPUBindGroupLayoutId; typedef struct { WGPUBufferId buffer; - uint32_t offset; - uint32_t size; + WGPUBufferAddress offset; + WGPUBufferAddress size; } WGPUBufferBinding; typedef WGPUId WGPUSamplerId; @@ -402,22 +386,23 @@ typedef struct { typedef struct { uint32_t binding; WGPUBindingResource resource; -} WGPUBinding; +} WGPUBindGroupBinding; typedef struct { WGPUBindGroupLayoutId layout; - const WGPUBinding *bindings; + const WGPUBindGroupBinding *bindings; uintptr_t bindings_length; } WGPUBindGroupDescriptor; -typedef uint32_t WGPUShaderStageFlags; -#define WGPUShaderStageFlags_VERTEX 1 -#define WGPUShaderStageFlags_FRAGMENT 2 -#define WGPUShaderStageFlags_COMPUTE 4 +typedef uint32_t WGPUShaderStage; +#define WGPUShaderStage_NONE 0 +#define WGPUShaderStage_VERTEX 1 +#define WGPUShaderStage_FRAGMENT 2 +#define WGPUShaderStage_COMPUTE 4 typedef struct { uint32_t binding; - WGPUShaderStageFlags visibility; + WGPUShaderStage visibility; WGPUBindingType ty; } WGPUBindGroupLayoutBinding; @@ -426,21 +411,21 @@ typedef struct { uintptr_t bindings_length; } WGPUBindGroupLayoutDescriptor; -typedef uint32_t WGPUBufferUsageFlags; -#define WGPUBufferUsageFlags_MAP_READ 1 -#define WGPUBufferUsageFlags_MAP_WRITE 2 -#define WGPUBufferUsageFlags_TRANSFER_SRC 4 -#define WGPUBufferUsageFlags_TRANSFER_DST 8 -#define WGPUBufferUsageFlags_INDEX 16 -#define WGPUBufferUsageFlags_VERTEX 32 -#define WGPUBufferUsageFlags_UNIFORM 64 -#define WGPUBufferUsageFlags_STORAGE 128 -#define WGPUBufferUsageFlags_NONE 0 -#define WGPUBufferUsageFlags_WRITE_ALL 2 + 8 + 128 +typedef uint32_t WGPUBufferUsage; +#define WGPUBufferUsage_MAP_READ 1 +#define WGPUBufferUsage_MAP_WRITE 2 +#define WGPUBufferUsage_TRANSFER_SRC 4 +#define WGPUBufferUsage_TRANSFER_DST 8 +#define WGPUBufferUsage_INDEX 16 +#define WGPUBufferUsage_VERTEX 32 +#define WGPUBufferUsage_UNIFORM 64 +#define WGPUBufferUsage_STORAGE 128 +#define WGPUBufferUsage_NONE 0 +#define WGPUBufferUsage_WRITE_ALL 2 + 8 + 128 typedef struct { - uint32_t size; - WGPUBufferUsageFlags usage; + WGPUBufferAddress size; + WGPUBufferUsage usage; } WGPUBufferDescriptor; typedef struct { @@ -451,9 +436,11 @@ typedef WGPUId WGPUPipelineLayoutId; typedef WGPUId WGPUShaderModuleId; +typedef const char *WGPURawString; + typedef struct { WGPUShaderModuleId module; - const char *entry_point; + WGPURawString entry_point; } WGPUPipelineStageDescriptor; typedef struct { @@ -482,19 +469,19 @@ typedef struct { WGPUBlendOperation operation; } WGPUBlendDescriptor; -typedef uint32_t WGPUColorWriteFlags; -#define WGPUColorWriteFlags_RED 1 -#define WGPUColorWriteFlags_GREEN 2 -#define WGPUColorWriteFlags_BLUE 4 -#define WGPUColorWriteFlags_ALPHA 8 -#define WGPUColorWriteFlags_COLOR 7 -#define WGPUColorWriteFlags_ALL 15 +typedef uint32_t WGPUColorWrite; +#define WGPUColorWrite_RED 1 +#define WGPUColorWrite_GREEN 2 +#define WGPUColorWrite_BLUE 4 +#define WGPUColorWrite_ALPHA 8 +#define WGPUColorWrite_COLOR 7 +#define WGPUColorWrite_ALL 15 typedef struct { WGPUTextureFormat format; - WGPUBlendDescriptor alpha; - WGPUBlendDescriptor color; - WGPUColorWriteFlags write_mask; + WGPUBlendDescriptor alpha_blend; + WGPUBlendDescriptor color_blend; + WGPUColorWrite write_mask; } WGPUColorStateDescriptor; typedef struct { @@ -514,16 +501,16 @@ typedef struct { uint32_t stencil_write_mask; } WGPUDepthStencilStateDescriptor; -typedef uint32_t WGPUShaderAttributeIndex; +typedef uint32_t WGPUShaderLocation; typedef struct { - uint32_t offset; + WGPUBufferAddress offset; WGPUVertexFormat format; - WGPUShaderAttributeIndex attribute_index; + WGPUShaderLocation shader_location; } WGPUVertexAttributeDescriptor; typedef struct { - uint32_t stride; + WGPUBufferAddress stride; WGPUInputStepMode step_mode; const WGPUVertexAttributeDescriptor *attributes; uintptr_t attributes_count; @@ -533,33 +520,31 @@ typedef struct { WGPUIndexFormat index_format; const WGPUVertexBufferDescriptor *vertex_buffers; uintptr_t vertex_buffers_count; -} WGPUVertexBufferStateDescriptor; +} WGPUVertexInputDescriptor; typedef struct { WGPUPipelineLayoutId layout; WGPUPipelineStageDescriptor vertex_stage; - WGPUPipelineStageDescriptor fragment_stage; + const WGPUPipelineStageDescriptor *fragment_stage; WGPUPrimitiveTopology primitive_topology; WGPURasterizationStateDescriptor rasterization_state; const WGPUColorStateDescriptor *color_states; uintptr_t color_states_length; const WGPUDepthStencilStateDescriptor *depth_stencil_state; - WGPUVertexBufferStateDescriptor vertex_buffer_state; + WGPUVertexInputDescriptor vertex_input; uint32_t sample_count; } WGPURenderPipelineDescriptor; typedef struct { - WGPUAddressMode r_address_mode; - WGPUAddressMode s_address_mode; - WGPUAddressMode t_address_mode; + WGPUAddressMode address_mode_u; + WGPUAddressMode address_mode_v; + WGPUAddressMode address_mode_w; WGPUFilterMode mag_filter; WGPUFilterMode min_filter; WGPUFilterMode mipmap_filter; float lod_min_clamp; float lod_max_clamp; - uint32_t max_anisotropy; WGPUCompareFunction compare_function; - WGPUBorderColor border_color; } WGPUSamplerDescriptor; typedef struct { @@ -575,18 +560,18 @@ typedef WGPUId WGPUSurfaceId; typedef WGPUSurfaceId WGPUSwapChainId; -typedef uint32_t WGPUTextureUsageFlags; -#define WGPUTextureUsageFlags_TRANSFER_SRC 1 -#define WGPUTextureUsageFlags_TRANSFER_DST 2 -#define WGPUTextureUsageFlags_SAMPLED 4 -#define WGPUTextureUsageFlags_STORAGE 8 -#define WGPUTextureUsageFlags_OUTPUT_ATTACHMENT 16 -#define WGPUTextureUsageFlags_NONE 0 -#define WGPUTextureUsageFlags_WRITE_ALL 2 + 8 + 16 -#define WGPUTextureUsageFlags_UNINITIALIZED 65535 +typedef uint32_t WGPUTextureUsage; +#define WGPUTextureUsage_TRANSFER_SRC 1 +#define WGPUTextureUsage_TRANSFER_DST 2 +#define WGPUTextureUsage_SAMPLED 4 +#define WGPUTextureUsage_STORAGE 8 +#define WGPUTextureUsage_OUTPUT_ATTACHMENT 16 +#define WGPUTextureUsage_NONE 0 +#define WGPUTextureUsage_WRITE_ALL 2 + 8 + 16 +#define WGPUTextureUsage_UNINITIALIZED 65535 typedef struct { - WGPUTextureUsageFlags usage; + WGPUTextureUsage usage; WGPUTextureFormat format; uint32_t width; uint32_t height; @@ -594,10 +579,12 @@ typedef struct { typedef struct { WGPUExtent3d size; - uint32_t array_size; + uint32_t array_layer_count; + uint32_t mip_level_count; + uint32_t sample_count; WGPUTextureDimension dimension; WGPUTextureFormat format; - WGPUTextureUsageFlags usage; + WGPUTextureUsage usage; } WGPUTextureDescriptor; typedef WGPUDeviceId WGPUQueueId; @@ -631,7 +618,8 @@ typedef struct { #if defined(WGPU_LOCAL) -WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, const WGPUDeviceDescriptor *desc); +WGPUDeviceId wgpu_adapter_request_device(WGPUAdapterId adapter_id, + const WGPUDeviceDescriptor *desc); #endif void wgpu_bind_group_destroy(WGPUBindGroupId bind_group_id); @@ -639,14 +627,14 @@ void wgpu_bind_group_destroy(WGPUBindGroupId bind_group_id); void wgpu_buffer_destroy(WGPUBufferId buffer_id); void wgpu_buffer_map_read_async(WGPUBufferId buffer_id, - uint32_t start, - uint32_t size, + WGPUBufferAddress start, + WGPUBufferAddress size, WGPUBufferMapReadCallback callback, uint8_t *userdata); void wgpu_buffer_map_write_async(WGPUBufferId buffer_id, - uint32_t start, - uint32_t size, + WGPUBufferAddress start, + WGPUBufferAddress size, WGPUBufferMapWriteCallback callback, uint8_t *userdata); @@ -654,10 +642,10 @@ void wgpu_buffer_unmap(WGPUBufferId buffer_id); void wgpu_command_buffer_copy_buffer_to_buffer(WGPUCommandBufferId command_buffer_id, WGPUBufferId src, - uint32_t src_offset, + WGPUBufferAddress src_offset, WGPUBufferId dst, - uint32_t dst_offset, - uint32_t size); + WGPUBufferAddress dst_offset, + WGPUBufferAddress size); void wgpu_command_buffer_copy_buffer_to_texture(WGPUCommandBufferId command_buffer_id, const WGPUBufferCopyView *source, @@ -827,6 +815,8 @@ void wgpu_render_pass_set_scissor_rect(WGPURenderPassId pass_id, uint32_t w, uint32_t h); +void wgpu_render_pass_set_stencil_reference(WGPURenderPassId pass_id, uint32_t value); + void wgpu_render_pass_set_vertex_buffers(WGPURenderPassId pass_id, const WGPUBufferId *buffer_ptr, const uint32_t *offset_ptr, diff --git a/wgpu-native/src/binding_model.rs b/wgpu-native/src/binding_model.rs index f2c7c6759d..c307bd2226 100644 --- a/wgpu-native/src/binding_model.rs +++ b/wgpu-native/src/binding_model.rs @@ -1,4 +1,4 @@ -use crate::{track::TrackerSet, BindGroupLayoutId, BufferId, LifeGuard, SamplerId, TextureViewId}; +use crate::{track::TrackerSet, BindGroupLayoutId, BufferId, LifeGuard, SamplerId, TextureViewId, BufferAddress}; use arrayvec::ArrayVec; use bitflags::bitflags; @@ -7,7 +7,8 @@ pub const MAX_BIND_GROUPS: usize = 4; bitflags! { #[repr(transparent)] - pub struct ShaderStageFlags: u32 { + pub struct ShaderStage: u32 { + const NONE = 0; const VERTEX = 1; const FRAGMENT = 2; const COMPUTE = 4; @@ -23,13 +24,14 @@ pub enum BindingType { StorageBuffer = 3, UniformBufferDynamic = 4, StorageBufferDynamic = 5, + StorageTexture = 10, } #[repr(C)] #[derive(Clone, Debug, Hash)] pub struct BindGroupLayoutBinding { pub binding: u32, - pub visibility: ShaderStageFlags, + pub visibility: ShaderStage, pub ty: BindingType, } @@ -59,8 +61,8 @@ pub struct PipelineLayout { #[repr(C)] pub struct BufferBinding { pub buffer: BufferId, - pub offset: u32, - pub size: u32, + pub offset: BufferAddress, + pub size: BufferAddress, } #[repr(C)] @@ -71,7 +73,7 @@ pub enum BindingResource { } #[repr(C)] -pub struct Binding { +pub struct BindGroupBinding { pub binding: u32, pub resource: BindingResource, } @@ -79,7 +81,7 @@ pub struct Binding { #[repr(C)] pub struct BindGroupDescriptor { pub layout: BindGroupLayoutId, - pub bindings: *const Binding, + pub bindings: *const BindGroupBinding, pub bindings_length: usize, } diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index f783a13bfc..3e592b33ac 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -34,7 +34,7 @@ use crate::{ Stored, TextureHandle, TextureId, - TextureUsageFlags, + TextureUsage, TextureViewId, }; #[cfg(feature = "local")] @@ -62,6 +62,7 @@ pub enum StoreOp { #[repr(C)] pub struct RenderPassColorAttachmentDescriptor { pub attachment: T, + pub resolve_target: *const TextureViewId, pub load_op: LoadOp, pub store_op: StoreOp, pub clear_color: Color, @@ -202,7 +203,7 @@ pub fn command_encoder_begin_render_pass( let query = trackers.textures.query( view.texture_id.value, &view.texture_id.ref_count, - TextureUsageFlags::empty(), + TextureUsage::empty(), ); let (_, layout) = conv::map_texture_state( query.usage, @@ -243,7 +244,7 @@ pub fn command_encoder_begin_render_pass( let query = trackers.textures.query( view.texture_id.value, &view.texture_id.ref_count, - TextureUsageFlags::empty(), + TextureUsage::empty(), ); let (_, layout) = conv::map_texture_state(query.usage, hal::format::Aspects::COLOR); hal::pass::Attachment { diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 56e1bf37c4..ef55ad116c 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -4,7 +4,7 @@ use crate::{ device::RenderPassContext, hub::HUB, pipeline::{IndexFormat, PipelineFlags}, - resource::BufferUsageFlags, + resource::BufferUsage, track::{Stitch, TrackerSet}, BindGroupId, BufferId, @@ -131,7 +131,7 @@ pub extern "C" fn wgpu_render_pass_set_index_buffer( let buffer = pass .trackers .buffers - .get_with_extended_usage(&*buffer_guard, buffer_id, BufferUsageFlags::INDEX) + .get_with_extended_usage(&*buffer_guard, buffer_id, BufferUsage::INDEX) .unwrap(); let view = hal::buffer::IndexBufferView { @@ -163,7 +163,7 @@ pub extern "C" fn wgpu_render_pass_set_vertex_buffers( for &id in buffers { pass.trackers .buffers - .get_with_extended_usage(&*buffer_guard, id, BufferUsageFlags::VERTEX) + .get_with_extended_usage(&*buffer_guard, id, BufferUsage::VERTEX) .unwrap(); } @@ -327,7 +327,7 @@ pub extern "C" fn wgpu_render_pass_set_pipeline( let buffer = pass .trackers .buffers - .get_with_extended_usage(&*buffer_guard, buffer_id, BufferUsageFlags::INDEX) + .get_with_extended_usage(&*buffer_guard, buffer_id, BufferUsage::INDEX) .unwrap(); let view = hal::buffer::IndexBufferView { @@ -355,6 +355,19 @@ pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color: } } +#[no_mangle] +pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: RenderPassId, value: u32) { + let mut pass_guard = HUB.render_passes.write(); + let pass = &mut pass_guard[pass_id]; + + //TODO + //pass.blend_color_status = BlendColorStatus::Set; + + unsafe { + pass.raw.set_stencil_reference(hal::pso::Face::all(), value); + } +} + #[no_mangle] pub extern "C" fn wgpu_render_pass_set_scissor_rect( pass_id: RenderPassId, diff --git a/wgpu-native/src/command/transfer.rs b/wgpu-native/src/command/transfer.rs index 47ae776760..ec05325fc6 100644 --- a/wgpu-native/src/command/transfer.rs +++ b/wgpu-native/src/command/transfer.rs @@ -4,13 +4,14 @@ use crate::{ hub::HUB, resource::TexturePlacement, swap_chain::SwapChainLink, + BufferAddress, BufferId, - BufferUsageFlags, + BufferUsage, CommandBufferId, Extent3d, Origin3d, TextureId, - TextureUsageFlags, + TextureUsage, }; use copyless::VecHelper as _; @@ -23,7 +24,7 @@ const BITS_PER_BYTE: u32 = 8; #[repr(C)] pub struct BufferCopyView { pub buffer: BufferId, - pub offset: u32, + pub offset: BufferAddress, pub row_pitch: u32, pub image_height: u32, } @@ -31,20 +32,19 @@ pub struct BufferCopyView { #[repr(C)] pub struct TextureCopyView { pub texture: TextureId, - pub level: u32, - pub slice: u32, + pub mip_level: u32, + pub array_layer: u32, pub origin: Origin3d, - //TODO: pub aspect: TextureAspect, } #[no_mangle] pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( command_buffer_id: CommandBufferId, src: BufferId, - src_offset: u32, + src_offset: BufferAddress, dst: BufferId, - dst_offset: u32, - size: u32, + dst_offset: BufferAddress, + size: BufferAddress, ) { let mut cmb_guard = HUB.command_buffers.write(); let cmb = &mut cmb_guard[command_buffer_id]; @@ -53,7 +53,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( let (src_buffer, src_usage) = cmb .trackers .buffers - .get_with_replaced_usage(&*buffer_guard, src, BufferUsageFlags::TRANSFER_SRC) + .get_with_replaced_usage(&*buffer_guard, src, BufferUsage::TRANSFER_SRC) .unwrap(); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Buffer { states: conv::map_buffer_state(old)..hal::buffer::Access::TRANSFER_READ, @@ -65,7 +65,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( let (dst_buffer, dst_usage) = cmb .trackers .buffers - .get_with_replaced_usage(&*buffer_guard, dst, BufferUsageFlags::TRANSFER_DST) + .get_with_replaced_usage(&*buffer_guard, dst, BufferUsage::TRANSFER_DST) .unwrap(); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Buffer { states: conv::map_buffer_state(old)..hal::buffer::Access::TRANSFER_WRITE, @@ -75,9 +75,9 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( }); let region = hal::command::BufferCopy { - src: src_offset as hal::buffer::Offset, - dst: dst_offset as hal::buffer::Offset, - size: size as hal::buffer::Offset, + src: src_offset, + dst: dst_offset, + size, }; let cmb_raw = cmb.raw.last_mut().unwrap(); unsafe { @@ -108,7 +108,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( .get_with_replaced_usage( &*buffer_guard, source.buffer, - BufferUsageFlags::TRANSFER_SRC, + BufferUsage::TRANSFER_SRC, ) .unwrap(); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Buffer { @@ -124,11 +124,11 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( .get_with_replaced_usage( &*texture_guard, destination.texture, - TextureUsageFlags::TRANSFER_DST, + TextureUsage::TRANSFER_DST, ) .unwrap(); let aspects = dst_texture.full_range.aspects; - let dst_texture_state = conv::map_texture_state(TextureUsageFlags::TRANSFER_DST, aspects); + let dst_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_DST, aspects); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Image { states: conv::map_texture_state(old, aspects)..dst_texture_state, target: &dst_texture.raw, @@ -151,13 +151,13 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( let buffer_width = source.row_pitch / bytes_per_texel; assert_eq!(source.row_pitch % bytes_per_texel, 0); let region = hal::command::BufferImageCopy { - buffer_offset: source.offset as hal::buffer::Offset, + buffer_offset: source.offset, buffer_width, buffer_height: source.image_height, image_layers: hal::image::SubresourceLayers { aspects, //TODO - level: destination.level as hal::image::Level, - layers: destination.slice as u16..destination.slice as u16 + 1, + level: destination.mip_level as hal::image::Level, + layers: destination.array_layer as u16 .. destination.array_layer as u16 + 1, }, image_offset: conv::map_origin(destination.origin), image_extent: conv::map_extent(copy_size), @@ -197,11 +197,11 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( .get_with_replaced_usage( &*texture_guard, source.texture, - TextureUsageFlags::TRANSFER_SRC, + TextureUsage::TRANSFER_SRC, ) .unwrap(); let aspects = src_texture.full_range.aspects; - let src_texture_state = conv::map_texture_state(TextureUsageFlags::TRANSFER_SRC, aspects); + let src_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_SRC, aspects); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Image { states: conv::map_texture_state(old, aspects)..src_texture_state, target: &src_texture.raw, @@ -220,7 +220,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( .get_with_replaced_usage( &*buffer_guard, destination.buffer, - BufferUsageFlags::TRANSFER_DST, + BufferUsage::TRANSFER_DST, ) .unwrap(); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Buffer { @@ -237,13 +237,13 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( let buffer_width = destination.row_pitch / bytes_per_texel; assert_eq!(destination.row_pitch % bytes_per_texel, 0); let region = hal::command::BufferImageCopy { - buffer_offset: destination.offset as hal::buffer::Offset, + buffer_offset: destination.offset, buffer_width, buffer_height: destination.image_height, image_layers: hal::image::SubresourceLayers { aspects, //TODO - level: source.level as hal::image::Level, - layers: source.slice as u16..source.slice as u16 + 1, + level: source.mip_level as hal::image::Level, + layers: source.array_layer as u16 .. source.array_layer as u16 + 1, }, image_offset: conv::map_origin(source.origin), image_extent: conv::map_extent(copy_size), @@ -282,7 +282,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( .get_with_replaced_usage( &*texture_guard, source.texture, - TextureUsageFlags::TRANSFER_SRC, + TextureUsage::TRANSFER_SRC, ) .unwrap(); let (dst_texture, dst_usage) = cmb @@ -291,13 +291,13 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( .get_with_replaced_usage( &*texture_guard, destination.texture, - TextureUsageFlags::TRANSFER_DST, + TextureUsage::TRANSFER_DST, ) .unwrap(); let aspects = src_texture.full_range.aspects & dst_texture.full_range.aspects; - let src_texture_state = conv::map_texture_state(TextureUsageFlags::TRANSFER_SRC, aspects); - let dst_texture_state = conv::map_texture_state(TextureUsageFlags::TRANSFER_DST, aspects); + let src_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_SRC, aspects); + let dst_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_DST, aspects); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Image { states: conv::map_texture_state(old, aspects)..src_texture_state, @@ -323,14 +323,14 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( let region = hal::command::ImageCopy { src_subresource: hal::image::SubresourceLayers { aspects, - level: source.level as hal::image::Level, - layers: source.slice as u16..source.slice as u16 + 1, + level: source.mip_level as hal::image::Level, + layers: source.array_layer as u16 .. source.array_layer as u16 + 1, }, src_offset: conv::map_origin(source.origin), dst_subresource: hal::image::SubresourceLayers { aspects, - level: destination.level as hal::image::Level, - layers: destination.slice as u16..destination.slice as u16 + 1, + level: destination.mip_level as hal::image::Level, + layers: destination.array_layer as u16 .. destination.array_layer as u16 + 1, }, dst_offset: conv::map_origin(destination.origin), extent: conv::map_extent(copy_size), diff --git a/wgpu-native/src/conv.rs b/wgpu-native/src/conv.rs index dd752d9bf1..5ba3245bb1 100644 --- a/wgpu-native/src/conv.rs +++ b/wgpu-native/src/conv.rs @@ -1,9 +1,9 @@ use crate::{binding_model, command, pipeline, resource, Color, Extent3d, Origin3d}; pub fn map_buffer_usage( - usage: resource::BufferUsageFlags, + usage: resource::BufferUsage, ) -> (hal::buffer::Usage, hal::memory::Properties) { - use crate::resource::BufferUsageFlags as W; + use crate::resource::BufferUsage as W; use hal::buffer::Usage as U; use hal::memory::Properties as P; @@ -39,10 +39,10 @@ pub fn map_buffer_usage( } pub fn map_texture_usage( - usage: resource::TextureUsageFlags, + usage: resource::TextureUsage, aspects: hal::format::Aspects, ) -> hal::image::Usage { - use crate::resource::TextureUsageFlags as W; + use crate::resource::TextureUsage as W; use hal::image::Usage as U; let mut value = U::empty(); @@ -65,7 +65,7 @@ pub fn map_texture_usage( value |= U::COLOR_ATTACHMENT; } } - // Note: TextureUsageFlags::Present does not need to be handled explicitly + // Note: TextureUsage::Present does not need to be handled explicitly // TODO: HAL Transient Attachment, HAL Input Attachment value } @@ -77,6 +77,7 @@ pub fn map_binding_type(binding_ty: binding_model::BindingType) -> hal::pso::Des UniformBuffer => H::UniformBuffer, Sampler => H::Sampler, SampledTexture => H::SampledImage, + StorageTexture => H::StorageImage, StorageBuffer => H::StorageBuffer, UniformBufferDynamic => H::UniformBufferDynamic, StorageBufferDynamic => H::StorageBufferDynamic, @@ -84,19 +85,19 @@ pub fn map_binding_type(binding_ty: binding_model::BindingType) -> hal::pso::Des } pub fn map_shader_stage_flags( - shader_stage_flags: binding_model::ShaderStageFlags, + shader_stage_flags: binding_model::ShaderStage, ) -> hal::pso::ShaderStageFlags { - use crate::binding_model::ShaderStageFlags as F; + use crate::binding_model::ShaderStage as Ss; use hal::pso::ShaderStageFlags as H; let mut value = H::empty(); - if shader_stage_flags.contains(F::VERTEX) { + if shader_stage_flags.contains(Ss::VERTEX) { value |= H::VERTEX; } - if shader_stage_flags.contains(F::FRAGMENT) { + if shader_stage_flags.contains(Ss::FRAGMENT) { value |= H::FRAGMENT; } - if shader_stage_flags.contains(F::COMPUTE) { + if shader_stage_flags.contains(Ss::COMPUTE) { value |= H::COMPUTE; } value @@ -134,12 +135,12 @@ pub fn map_color_state_descriptor( desc: &pipeline::ColorStateDescriptor, ) -> hal::pso::ColorBlendDesc { let color_mask = desc.write_mask; - let blend_state = if desc.color != pipeline::BlendDescriptor::REPLACE - || desc.alpha != pipeline::BlendDescriptor::REPLACE + let blend_state = if desc.color_blend != pipeline::BlendDescriptor::REPLACE + || desc.alpha_blend != pipeline::BlendDescriptor::REPLACE { hal::pso::BlendState::On { - color: map_blend_descriptor(&desc.color), - alpha: map_blend_descriptor(&desc.alpha), + color: map_blend_descriptor(&desc.color_blend), + alpha: map_blend_descriptor(&desc.alpha_blend), } } else { hal::pso::BlendState::Off @@ -147,21 +148,21 @@ pub fn map_color_state_descriptor( hal::pso::ColorBlendDesc(map_color_write_flags(color_mask), blend_state) } -fn map_color_write_flags(flags: pipeline::ColorWriteFlags) -> hal::pso::ColorMask { - use crate::pipeline::ColorWriteFlags as F; +fn map_color_write_flags(flags: pipeline::ColorWrite) -> hal::pso::ColorMask { + use crate::pipeline::ColorWrite as Cw; use hal::pso::ColorMask as H; let mut value = H::empty(); - if flags.contains(F::RED) { + if flags.contains(Cw::RED) { value |= H::RED; } - if flags.contains(F::GREEN) { + if flags.contains(Cw::GREEN) { value |= H::GREEN; } - if flags.contains(F::BLUE) { + if flags.contains(Cw::BLUE) { value |= H::BLUE; } - if flags.contains(F::ALPHA) { + if flags.contains(Cw::ALPHA) { value |= H::ALPHA; } value @@ -367,42 +368,23 @@ pub fn map_vertex_format(vertex_format: pipeline::VertexFormat) -> hal::format:: use crate::pipeline::VertexFormat::*; use hal::format::Format as H; match vertex_format { - Uchar => H::R8Uint, Uchar2 => H::Rg8Uint, - Uchar3 => H::Rgb8Uint, Uchar4 => H::Rgba8Uint, - Char => H::R8Sint, Char2 => H::Rg8Sint, - Char3 => H::Rgb8Sint, Char4 => H::Rgba8Sint, - UcharNorm => H::R8Unorm, Uchar2Norm => H::Rg8Unorm, - Uchar3Norm => H::Rgb8Unorm, Uchar4Norm => H::Rgba8Unorm, - Uchar4NormBgra => H::Bgra8Unorm, - CharNorm => H::R8Snorm, Char2Norm => H::Rg8Snorm, - Char3Norm => H::Rgb8Snorm, Char4Norm => H::Rgba8Snorm, - Ushort => H::R16Uint, Ushort2 => H::Rg16Uint, - Ushort3 => H::Rgb16Uint, Ushort4 => H::Rgba16Uint, - Short => H::R16Sint, Short2 => H::Rg16Sint, - Short3 => H::Rgb16Sint, Short4 => H::Rgba16Sint, - UshortNorm => H::R16Unorm, Ushort2Norm => H::Rg16Unorm, - Ushort3Norm => H::Rgb16Unorm, Ushort4Norm => H::Rgba16Unorm, - ShortNorm => H::R16Snorm, Short2Norm => H::Rg16Snorm, - Short3Norm => H::Rgb16Snorm, Short4Norm => H::Rgba16Snorm, - Half => H::R16Sfloat, Half2 => H::Rg16Sfloat, - Half3 => H::Rgb16Sfloat, Half4 => H::Rgba16Sfloat, Float => H::R32Sfloat, Float2 => H::Rg32Sfloat, @@ -486,8 +468,8 @@ pub fn map_texture_aspect_flags(aspect: resource::TextureAspectFlags) -> hal::fo flags } -pub fn map_buffer_state(usage: resource::BufferUsageFlags) -> hal::buffer::State { - use crate::resource::BufferUsageFlags as W; +pub fn map_buffer_state(usage: resource::BufferUsage) -> hal::buffer::State { + use crate::resource::BufferUsage as W; use hal::buffer::Access as A; let mut access = A::empty(); @@ -514,10 +496,10 @@ pub fn map_buffer_state(usage: resource::BufferUsageFlags) -> hal::buffer::State } pub fn map_texture_state( - usage: resource::TextureUsageFlags, + usage: resource::TextureUsage, aspects: hal::format::Aspects, ) -> hal::image::State { - use crate::resource::TextureUsageFlags as W; + use crate::resource::TextureUsage as W; use hal::image::{Access as A, Layout as L}; let is_color = aspects.contains(hal::format::Aspects::COLOR); @@ -589,7 +571,6 @@ pub fn map_wrap(address: resource::AddressMode) -> hal::image::WrapMode { Am::ClampToEdge => W::Clamp, Am::Repeat => W::Tile, Am::MirrorRepeat => W::Mirror, - Am::ClampToBorderColor => W::Border, } } diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 3ed7442f6a..17b886a6ad 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -9,6 +9,7 @@ use crate::{ track::{DummyUsage, Stitch, TrackPermit, TrackerSet, Tracktion}, AdapterId, BindGroupId, + BufferAddress, BufferId, BufferMapAsyncStatus, BufferMapOperation, @@ -375,7 +376,7 @@ fn map_buffer( raw: &::Device, limits: &hal::Limits, buffer: &mut resource::Buffer, - original_range: &std::ops::Range, + original_range: &std::ops::Range, kind: HostMap, ) -> BufferMapResult { // gfx-rs requires mapping and flushing/invalidation ranges to be done at `non_coherent_atom_size` @@ -572,7 +573,7 @@ pub fn device_create_buffer( let device = &device_guard[device_id]; let (usage, memory_properties) = conv::map_buffer_usage(desc.usage); - let mut buffer = unsafe { device.raw.create_buffer(desc.size as u64, usage).unwrap() }; + let mut buffer = unsafe { device.raw.create_buffer(desc.size, usage).unwrap() }; let requirements = unsafe { device.raw.get_buffer_requirements(&buffer) }; let device_type = device .mem_props @@ -622,7 +623,7 @@ pub fn device_track_buffer( device_id: DeviceId, buffer_id: BufferId, ref_count: RefCount, - flags: resource::BufferUsageFlags, + flags: resource::BufferUsage, ) { let query = HUB.devices.read()[device_id] .trackers @@ -645,7 +646,7 @@ pub extern "C" fn wgpu_device_create_buffer( device_id, id, ref_count, - resource::BufferUsageFlags::empty(), + resource::BufferUsage::empty(), ); id } @@ -658,13 +659,13 @@ pub extern "C" fn wgpu_device_create_buffer_mapped( mapped_ptr_out: *mut *mut u8, ) -> BufferId { let mut desc = desc.clone(); - desc.usage |= resource::BufferUsageFlags::MAP_WRITE; + desc.usage |= resource::BufferUsage::MAP_WRITE; let mut buffer = device_create_buffer(device_id, &desc); { let device_guard = HUB.devices.read(); let device = &device_guard[device_id]; - let range = 0..desc.size as u64; + let range = 0..desc.size; match map_buffer( &device.raw, @@ -691,7 +692,7 @@ pub extern "C" fn wgpu_device_create_buffer_mapped( device_id, id, ref_count, - resource::BufferUsageFlags::MAP_WRITE, + resource::BufferUsage::MAP_WRITE, ); id } @@ -714,7 +715,7 @@ pub fn device_create_texture( device_id: DeviceId, desc: &resource::TextureDescriptor, ) -> resource::Texture { - let kind = conv::map_texture_dimension_size(desc.dimension, desc.size, desc.array_size); + let kind = conv::map_texture_dimension_size(desc.dimension, desc.size, desc.array_layer_count); let format = conv::map_texture_format(desc.format); let aspects = format.surface_desc().aspects; let usage = conv::map_texture_usage(desc.usage, aspects); @@ -724,9 +725,9 @@ pub fn device_create_texture( let mut image = unsafe { device.raw.create_image( kind, - 1, // TODO: mips + desc.mip_level_count as hal::image::Level, format, - hal::image::Tiling::Optimal, // TODO: linear + hal::image::Tiling::Optimal, usage, hal::image::ViewCapabilities::empty(), // TODO: format, 2d array, cube ) @@ -771,8 +772,8 @@ pub fn device_create_texture( format: desc.format, full_range: hal::image::SubresourceRange { aspects, - levels: 0..1, //TODO: mips - layers: 0..desc.array_size as u16, + levels: 0..desc.mip_level_count as hal::image::Level, + layers: 0..desc.array_layer_count as hal::image::Layer, }, placement: resource::TexturePlacement::Memory(memory), life_guard: LifeGuard::new(), @@ -787,7 +788,7 @@ pub fn device_track_texture(device_id: DeviceId, texture_id: TextureId, ref_coun .query( texture_id, &ref_count, - resource::TextureUsageFlags::UNINITIALIZED, + resource::TextureUsage::UNINITIALIZED, ); assert!(query.initialized); } @@ -935,9 +936,9 @@ pub fn device_create_sampler( mag_filter: conv::map_filter(desc.mag_filter), mip_filter: conv::map_filter(desc.mipmap_filter), wrap_mode: ( - conv::map_wrap(desc.r_address_mode), - conv::map_wrap(desc.s_address_mode), - conv::map_wrap(desc.t_address_mode), + conv::map_wrap(desc.address_mode_u), + conv::map_wrap(desc.address_mode_v), + conv::map_wrap(desc.address_mode_w), ), lod_bias: 0.0.into(), lod_range: desc.lod_min_clamp.into()..desc.lod_max_clamp.into(), @@ -946,11 +947,7 @@ pub fn device_create_sampler( } else { Some(conv::map_compare_function(desc.compare_function)) }, - border: hal::image::PackedColor(match desc.border_color { - resource::BorderColor::TransparentBlack => 0x00000000, - resource::BorderColor::OpaqueBlack => 0x000000FF, - resource::BorderColor::OpaqueWhite => 0xFFFFFFFF, - }), + border: hal::image::PackedColor(0), anisotropic: hal::image::Anisotropic::Off, //TODO }; let raw = unsafe { device.raw.create_sampler(info).unwrap() }; @@ -1081,7 +1078,7 @@ pub fn device_create_bind_group( .get_with_extended_usage( &*buffer_guard, bb.buffer, - resource::BufferUsageFlags::UNIFORM, + resource::BufferUsage::UNIFORM, ) .unwrap(); let alignment = match decl.ty { @@ -1094,7 +1091,8 @@ pub fn device_create_bind_group( device.limits.min_storage_buffer_offset_alignment } binding_model::BindingType::Sampler - | binding_model::BindingType::SampledTexture => { + | binding_model::BindingType::SampledTexture + | binding_model::BindingType::StorageTexture => { panic!("Mismatched buffer binding for {:?}", decl) } }; @@ -1104,7 +1102,7 @@ pub fn device_create_bind_group( "Misaligned buffer offset {}", bb.offset ); - let range = Some(bb.offset as u64)..Some((bb.offset + bb.size) as u64); + let range = Some(bb.offset)..Some(bb.offset + bb.size); hal::pso::Descriptor::Buffer(&buffer.raw, range) } binding_model::BindingResource::Sampler(id) => { @@ -1120,7 +1118,7 @@ pub fn device_create_bind_group( .transit( view.texture_id.value, &view.texture_id.ref_count, - resource::TextureUsageFlags::SAMPLED, + resource::TextureUsage::SAMPLED, TrackPermit::EXTEND, ) .unwrap(); @@ -1449,28 +1447,29 @@ pub fn device_create_render_pipeline( module: &shader_module_guard[desc.vertex_stage.module].raw, specialization: hal::pso::Specialization::EMPTY, }; - let fragment = hal::pso::EntryPoint:: { - entry: unsafe { ffi::CStr::from_ptr(desc.fragment_stage.entry_point) } - .to_str() - .to_owned() - .unwrap(), // TODO - module: &shader_module_guard[desc.fragment_stage.module].raw, - specialization: hal::pso::Specialization::EMPTY, - }; + let fragment = unsafe { desc.fragment_stage.as_ref() } + .map(|stage| hal::pso::EntryPoint:: { + entry: unsafe { ffi::CStr::from_ptr(stage.entry_point) } + .to_str() + .to_owned() + .unwrap(), // TODO + module: &shader_module_guard[stage.module].raw, + specialization: hal::pso::Specialization::EMPTY, + }); let shaders = hal::pso::GraphicsShaderSet { vertex, hull: None, domain: None, geometry: None, - fragment: Some(fragment), + fragment, }; let rasterizer = conv::map_rasterization_state_descriptor(&desc.rasterization_state); let desc_vbs = unsafe { slice::from_raw_parts( - desc.vertex_buffer_state.vertex_buffers, - desc.vertex_buffer_state.vertex_buffers_count, + desc.vertex_input.vertex_buffers, + desc.vertex_input.vertex_buffers_count, ) }; let mut vertex_buffers = Vec::with_capacity(desc_vbs.len()); @@ -1481,7 +1480,7 @@ pub fn device_create_render_pipeline( } vertex_buffers.alloc().init(hal::pso::VertexBufferDesc { binding: i as u32, - stride: vb_state.stride, + stride: vb_state.stride as u32, rate: match vb_state.step_mode { pipeline::InputStepMode::Vertex => hal::pso::VertexInputRate::Vertex, pipeline::InputStepMode::Instance => hal::pso::VertexInputRate::Instance(1), @@ -1490,12 +1489,13 @@ pub fn device_create_render_pipeline( let desc_atts = unsafe { slice::from_raw_parts(vb_state.attributes, vb_state.attributes_count) }; for attribute in desc_atts { + assert_eq!(0, attribute.offset >> 32); attributes.alloc().init(hal::pso::AttributeDesc { - location: attribute.attribute_index, + location: attribute.shader_location, binding: i as u32, element: hal::pso::Element { format: conv::map_vertex_format(attribute.format), - offset: attribute.offset, + offset: attribute.offset as u32, }, }); } @@ -1570,7 +1570,7 @@ pub fn device_create_render_pipeline( let mut flags = pipeline::PipelineFlags::empty(); if color_states .iter() - .any(|state| state.color.uses_color() | state.alpha.uses_color()) + .any(|state| state.color_blend.uses_color() | state.alpha_blend.uses_color()) { flags |= pipeline::PipelineFlags::BLEND_COLOR; } @@ -1580,7 +1580,7 @@ pub fn device_create_render_pipeline( layout_id: desc.layout, pass_context, flags, - index_format: desc.vertex_buffer_state.index_format, + index_format: desc.vertex_input.index_format, } } @@ -1806,7 +1806,7 @@ pub fn swap_chain_populate_textures( trackers.textures.query( texture_id.value, &texture_id.ref_count, - resource::TextureUsageFlags::UNINITIALIZED, + resource::TextureUsage::UNINITIALIZED, ); let view = resource::TextureView { @@ -1872,8 +1872,8 @@ pub type BufferMapWriteCallback = #[no_mangle] pub extern "C" fn wgpu_buffer_map_read_async( buffer_id: BufferId, - start: u32, - size: u32, + start: BufferAddress, + size: BufferAddress, callback: BufferMapReadCallback, userdata: *mut u8, ) { @@ -1887,7 +1887,7 @@ pub extern "C" fn wgpu_buffer_map_read_async( return; } - let range = start as u64..(start + size) as u64; + let range = start .. start + size; buffer.pending_map_operation = Some(BufferMapOperation::Read(range, callback, userdata)); (buffer.device_id.value, buffer.life_guard.ref_count.clone()) }; @@ -1895,7 +1895,7 @@ pub extern "C" fn wgpu_buffer_map_read_async( let device_guard = HUB.devices.read(); let device = &device_guard[device_id]; - let usage = resource::BufferUsageFlags::MAP_READ; + let usage = resource::BufferUsage::MAP_READ; match device .trackers .lock() @@ -1915,8 +1915,8 @@ pub extern "C" fn wgpu_buffer_map_read_async( #[no_mangle] pub extern "C" fn wgpu_buffer_map_write_async( buffer_id: BufferId, - start: u32, - size: u32, + start: BufferAddress, + size: BufferAddress, callback: BufferMapWriteCallback, userdata: *mut u8, ) { @@ -1930,7 +1930,7 @@ pub extern "C" fn wgpu_buffer_map_write_async( return; } - let range = start as u64..(start + size) as u64; + let range = start .. start + size; buffer.pending_map_operation = Some(BufferMapOperation::Write(range, callback, userdata)); (buffer.device_id.value, buffer.life_guard.ref_count.clone()) }; @@ -1938,7 +1938,7 @@ pub extern "C" fn wgpu_buffer_map_write_async( let device_guard = HUB.devices.read(); let device = &device_guard[device_id]; - let usage = resource::BufferUsageFlags::MAP_WRITE; + let usage = resource::BufferUsage::MAP_WRITE; match device .trackers .lock() diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index 539182f1f2..a637864c03 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -1,4 +1,4 @@ -use crate::{hub::HUB, AdapterHandle, AdapterId, DeviceHandle, InstanceId, SurfaceHandle}; +use crate::{binding_model::MAX_BIND_GROUPS, hub::HUB, AdapterHandle, AdapterId, DeviceHandle, InstanceId, SurfaceHandle}; #[cfg(feature = "local")] use crate::{DeviceId, SurfaceId}; @@ -26,17 +26,33 @@ pub struct AdapterDescriptor { } #[repr(C)] -#[derive(Debug)] +#[derive(Debug, Default)] #[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))] pub struct Extensions { pub anisotropic_filtering: bool, } +#[repr(C)] +#[derive(Debug)] +#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))] +pub struct Limits { + pub max_bind_groups: u32, +} + +impl Default for Limits { + fn default() -> Self { + Limits { + max_bind_groups: MAX_BIND_GROUPS as u32, + } + } +} + #[repr(C)] #[derive(Debug)] #[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))] pub struct DeviceDescriptor { pub extensions: Extensions, + pub limits: Limits, } pub fn create_instance() -> ::back::Instance { @@ -186,7 +202,7 @@ pub fn adapter_create_device(adapter_id: AdapterId, _desc: &DeviceDescriptor) -> #[cfg(feature = "local")] #[no_mangle] -pub extern "C" fn wgpu_adapter_create_device( +pub extern "C" fn wgpu_adapter_request_device( adapter_id: AdapterId, desc: &DeviceDescriptor, ) -> DeviceId { diff --git a/wgpu-native/src/lib.rs b/wgpu-native/src/lib.rs index 272c69f412..ca20ac6611 100644 --- a/wgpu-native/src/lib.rs +++ b/wgpu-native/src/lib.rs @@ -40,14 +40,20 @@ pub use self::swap_chain::*; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::ptr; -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::{ + os::raw::c_char, + ptr, + sync::atomic::{AtomicUsize, Ordering}, +}; type SubmissionIndex = usize; pub(crate) type Index = u32; pub(crate) type Epoch = u32; +pub type BufferAddress = u64; +pub type RawString = *const c_char; + //TODO: make it private. Currently used for swapchain creation impl. #[derive(Debug)] pub struct RefCount(ptr::NonNull); @@ -156,6 +162,14 @@ pub struct Origin3d { pub z: f32, } +impl Origin3d { + pub const ZERO: Self = Origin3d { + x: 0.0, + y: 0.0, + z: 0.0, + }; +} + #[repr(C)] #[derive(Clone, Copy, Debug)] pub struct Extent3d { diff --git a/wgpu-native/src/pipeline.rs b/wgpu-native/src/pipeline.rs index b03e09b797..60c02a960f 100644 --- a/wgpu-native/src/pipeline.rs +++ b/wgpu-native/src/pipeline.rs @@ -1,8 +1,8 @@ -use crate::{device::RenderPassContext, resource, ByteArray, PipelineLayoutId, ShaderModuleId}; +use crate::{device::RenderPassContext, resource, BufferAddress, ByteArray, PipelineLayoutId, ShaderModuleId, RawString}; use bitflags::bitflags; -pub type ShaderAttributeIndex = u32; +pub type ShaderLocation = u32; #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] @@ -34,7 +34,7 @@ pub enum BlendOperation { bitflags! { #[repr(transparent)] - pub struct ColorWriteFlags: u32 { + pub struct ColorWrite: u32 { const RED = 1; const GREEN = 2; const BLUE = 4; @@ -74,9 +74,9 @@ impl BlendDescriptor { #[derive(Clone, Debug)] pub struct ColorStateDescriptor { pub format: resource::TextureFormat, - pub alpha: BlendDescriptor, - pub color: BlendDescriptor, - pub write_mask: ColorWriteFlags, + pub alpha_blend: BlendDescriptor, + pub color_blend: BlendDescriptor, + pub write_mask: ColorWrite, } #[repr(C)] @@ -132,42 +132,23 @@ pub enum IndexFormat { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum VertexFormat { - Uchar = 0, Uchar2 = 1, - Uchar3 = 2, Uchar4 = 3, - Char = 4, Char2 = 5, - Char3 = 6, Char4 = 7, - UcharNorm = 8, Uchar2Norm = 9, - Uchar3Norm = 10, Uchar4Norm = 11, - Uchar4NormBgra = 12, - CharNorm = 13, Char2Norm = 14, - Char3Norm = 15, Char4Norm = 16, - Ushort = 17, Ushort2 = 18, - Ushort3 = 19, Ushort4 = 20, - Short = 21, Short2 = 22, - Short3 = 23, Short4 = 24, - UshortNorm = 25, Ushort2Norm = 26, - Ushort3Norm = 27, Ushort4Norm = 28, - ShortNorm = 29, Short2Norm = 30, - Short3Norm = 31, Short4Norm = 32, - Half = 33, Half2 = 34, - Half3 = 35, Half4 = 36, Float = 37, Float2 = 38, @@ -193,21 +174,21 @@ pub enum InputStepMode { #[repr(C)] #[derive(Clone, Debug)] pub struct VertexAttributeDescriptor { - pub offset: u32, + pub offset: BufferAddress, pub format: VertexFormat, - pub attribute_index: ShaderAttributeIndex, + pub shader_location: ShaderLocation, } #[repr(C)] pub struct VertexBufferDescriptor { - pub stride: u32, + pub stride: BufferAddress, pub step_mode: InputStepMode, pub attributes: *const VertexAttributeDescriptor, pub attributes_count: usize, } #[repr(C)] -pub struct VertexBufferStateDescriptor { +pub struct VertexInputDescriptor { pub index_format: IndexFormat, pub vertex_buffers: *const VertexBufferDescriptor, pub vertex_buffers_count: usize, @@ -221,7 +202,7 @@ pub struct ShaderModuleDescriptor { #[repr(C)] pub struct PipelineStageDescriptor { pub module: ShaderModuleId, - pub entry_point: *const ::std::os::raw::c_char, + pub entry_point: RawString, } #[repr(C)] @@ -274,13 +255,13 @@ pub struct RasterizationStateDescriptor { pub struct RenderPipelineDescriptor { pub layout: PipelineLayoutId, pub vertex_stage: PipelineStageDescriptor, - pub fragment_stage: PipelineStageDescriptor, + pub fragment_stage: *const PipelineStageDescriptor, pub primitive_topology: PrimitiveTopology, pub rasterization_state: RasterizationStateDescriptor, pub color_states: *const ColorStateDescriptor, pub color_states_length: usize, pub depth_stencil_state: *const DepthStencilStateDescriptor, - pub vertex_buffer_state: VertexBufferStateDescriptor, + pub vertex_input: VertexInputDescriptor, pub sample_count: u32, } diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index 046007806e..431fd8991d 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -1,5 +1,6 @@ use crate::{ swap_chain::{SwapChainLink, SwapImageEpoch}, + BufferAddress, BufferMapReadCallback, BufferMapWriteCallback, DeviceId, @@ -18,7 +19,7 @@ use std::borrow::Borrow; bitflags! { #[repr(transparent)] - pub struct BufferUsageFlags: u32 { + pub struct BufferUsage: u32 { const MAP_READ = 1; const MAP_WRITE = 2; const TRANSFER_SRC = 4; @@ -35,8 +36,8 @@ bitflags! { #[repr(C)] #[derive(Clone)] pub struct BufferDescriptor { - pub size: u32, - pub usage: BufferUsageFlags, + pub size: BufferAddress, + pub usage: BufferUsage, } #[repr(C)] @@ -151,7 +152,7 @@ pub enum TextureFormat { bitflags! { #[repr(transparent)] - pub struct TextureUsageFlags: u32 { + pub struct TextureUsage: u32 { const TRANSFER_SRC = 1; const TRANSFER_DST = 2; const SAMPLED = 4; @@ -166,10 +167,12 @@ bitflags! { #[repr(C)] pub struct TextureDescriptor { pub size: Extent3d, - pub array_size: u32, + pub array_layer_count: u32, + pub mip_level_count: u32, + pub sample_count: u32, pub dimension: TextureDimension, pub format: TextureFormat, - pub usage: TextureUsageFlags, + pub usage: TextureUsage, } pub(crate) enum TexturePlacement { @@ -255,7 +258,6 @@ pub enum AddressMode { ClampToEdge = 0, Repeat = 1, MirrorRepeat = 2, - ClampToBorderColor = 3, } #[repr(C)] @@ -278,27 +280,17 @@ pub enum CompareFunction { Always = 7, } -#[repr(C)] -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -pub enum BorderColor { - TransparentBlack = 0, - OpaqueBlack = 1, - OpaqueWhite = 2, -} - #[repr(C)] pub struct SamplerDescriptor { - pub r_address_mode: AddressMode, - pub s_address_mode: AddressMode, - pub t_address_mode: AddressMode, + pub address_mode_u: AddressMode, + pub address_mode_v: AddressMode, + pub address_mode_w: AddressMode, pub mag_filter: FilterMode, pub min_filter: FilterMode, pub mipmap_filter: FilterMode, pub lod_min_clamp: f32, pub lod_max_clamp: f32, - pub max_anisotropy: u32, pub compare_function: CompareFunction, - pub border_color: BorderColor, } pub struct Sampler { diff --git a/wgpu-native/src/swap_chain.rs b/wgpu-native/src/swap_chain.rs index 0dab656ada..9b3395f0ac 100644 --- a/wgpu-native/src/swap_chain.rs +++ b/wgpu-native/src/swap_chain.rs @@ -78,7 +78,7 @@ pub struct SwapChain { #[repr(C)] #[derive(Clone, Debug)] pub struct SwapChainDescriptor { - pub usage: resource::TextureUsageFlags, + pub usage: resource::TextureUsage, pub format: resource::TextureFormat, pub width: u32, pub height: u32, @@ -92,7 +92,9 @@ impl SwapChainDescriptor { height: self.height, depth: 1, }, - array_size: 1, + mip_level_count: 1, + array_layer_count: 1, + sample_count: 1, dimension: resource::TextureDimension::D2, format: self.format, usage: self.usage, @@ -220,7 +222,7 @@ pub extern "C" fn wgpu_swap_chain_present(swap_chain_id: SwapChainId) { .transit( frame.texture_id.value, &texture.life_guard.ref_count, - resource::TextureUsageFlags::UNINITIALIZED, + resource::TextureUsage::UNINITIALIZED, TrackPermit::REPLACE, ) .unwrap() diff --git a/wgpu-native/src/track.rs b/wgpu-native/src/track.rs index 71b6af0686..2e0d5fc092 100644 --- a/wgpu-native/src/track.rs +++ b/wgpu-native/src/track.rs @@ -1,6 +1,6 @@ use crate::{ hub::{Storage}, - resource::{BufferUsageFlags, TextureUsageFlags}, + resource::{BufferUsage, TextureUsage}, BufferId, Epoch, Index, @@ -69,14 +69,14 @@ impl BitOr for DummyUsage { } } -impl GenericUsage for BufferUsageFlags { +impl GenericUsage for BufferUsage { fn is_exclusive(&self) -> bool { - BufferUsageFlags::WRITE_ALL.intersects(*self) + BufferUsage::WRITE_ALL.intersects(*self) } } -impl GenericUsage for TextureUsageFlags { +impl GenericUsage for TextureUsage { fn is_exclusive(&self) -> bool { - TextureUsageFlags::WRITE_ALL.intersects(*self) + TextureUsage::WRITE_ALL.intersects(*self) } } impl GenericUsage for DummyUsage { @@ -98,8 +98,8 @@ pub struct Tracker { map: FastHashMap>, _phantom: PhantomData, } -pub type BufferTracker = Tracker; -pub type TextureTracker = Tracker; +pub type BufferTracker = Tracker; +pub type TextureTracker = Tracker; pub type TextureViewTracker = Tracker; //TODO: make this a generic parameter. From f024758e0731fdff5aa1220c630d7827c46c8c10 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 14 May 2019 11:51:12 -0400 Subject: [PATCH 2/5] Track stencil reference --- examples/hello_triangle_c/main.c | 2 +- wgpu-native/src/command/render.rs | 34 ++++++++++++++++++++----------- wgpu-native/src/device.rs | 14 ++++++++----- wgpu-native/src/pipeline.rs | 8 ++++++++ wgpu-native/src/resource.rs | 10 +++++++++ 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/examples/hello_triangle_c/main.c b/examples/hello_triangle_c/main.c index b1352f46da..c36e011764 100644 --- a/examples/hello_triangle_c/main.c +++ b/examples/hello_triangle_c/main.c @@ -210,7 +210,7 @@ int main() { swap_chain = wgpu_device_create_swap_chain(device, surface, &(WGPUSwapChainDescriptor){ - .usage = WGPUTextureUsageFlags_OUTPUT_ATTACHMENT, + .usage = WGPUTextureUsage_OUTPUT_ATTACHMENT, .format = WGPUTextureFormat_Bgra8Unorm, .width = width, .height = height, diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index ef55ad116c..a388a98ac3 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -21,15 +21,24 @@ use hal::command::RawCommandBuffer; use std::{iter, slice}; #[derive(Debug, PartialEq)] -enum BlendColorStatus { +enum OptionalState { Unused, Required, Set, } +impl OptionalState { + fn require(&mut self, require: bool) { + if require && *self == OptionalState::Unused { + *self = OptionalState::Required; + } + } +} + #[derive(Debug, PartialEq)] enum DrawError { MissingBlendColor, + MissingStencilReference, IncompatibleBindGroup { index: u32, //expected: BindGroupLayoutId, @@ -49,7 +58,8 @@ pub struct RenderPass { context: RenderPassContext, binder: Binder, trackers: TrackerSet, - blend_color_status: BlendColorStatus, + blend_color_status: OptionalState, + stencil_reference_status: OptionalState, index_state: IndexState, } @@ -66,7 +76,8 @@ impl RenderPass { context, binder: Binder::default(), trackers: TrackerSet::new(), - blend_color_status: BlendColorStatus::Unused, + blend_color_status: OptionalState::Unused, + stencil_reference_status: OptionalState::Unused, index_state, } } @@ -80,9 +91,12 @@ impl RenderPass { index: bind_mask.trailing_zeros() as u32, }); } - if self.blend_color_status == BlendColorStatus::Required { + if self.blend_color_status == OptionalState::Required { return Err(DrawError::MissingBlendColor); } + if self.stencil_reference_status == OptionalState::Required { + return Err(DrawError::MissingStencilReference); + } Ok(()) } } @@ -276,11 +290,8 @@ pub extern "C" fn wgpu_render_pass_set_pipeline( "The render pipeline is not compatible with the pass!" ); - if pipeline.flags.contains(PipelineFlags::BLEND_COLOR) - && pass.blend_color_status == BlendColorStatus::Unused - { - pass.blend_color_status = BlendColorStatus::Required; - } + pass.blend_color_status.require(pipeline.flags.contains(PipelineFlags::BLEND_COLOR)); + pass.stencil_reference_status.require(pipeline.flags.contains(PipelineFlags::STENCIL_REFERENCE)); unsafe { pass.raw.bind_graphics_pipeline(&pipeline.raw); @@ -348,7 +359,7 @@ pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color: let mut pass_guard = HUB.render_passes.write(); let pass = &mut pass_guard[pass_id]; - pass.blend_color_status = BlendColorStatus::Set; + pass.blend_color_status = OptionalState::Set; unsafe { pass.raw.set_blend_constants(conv::map_color(color)); @@ -360,8 +371,7 @@ pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: RenderPassId, let mut pass_guard = HUB.render_passes.write(); let pass = &mut pass_guard[pass_id]; - //TODO - //pass.blend_color_status = BlendColorStatus::Set; + pass.stencil_reference_status = OptionalState::Set; unsafe { pass.raw.set_stencil_reference(hal::pso::Face::all(), value); diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 17b886a6ad..4670b8f0b7 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -1568,11 +1568,15 @@ pub fn device_create_render_pipeline( }; let mut flags = pipeline::PipelineFlags::empty(); - if color_states - .iter() - .any(|state| state.color_blend.uses_color() | state.alpha_blend.uses_color()) - { - flags |= pipeline::PipelineFlags::BLEND_COLOR; + for state in color_states { + if state.color_blend.uses_color() | state.alpha_blend.uses_color() { + flags |= pipeline::PipelineFlags::BLEND_COLOR; + } + } + if let Some(ds) = depth_stencil_state { + if ds.needs_stencil_reference() { + flags |= pipeline::PipelineFlags::STENCIL_REFERENCE; + } } pipeline::RenderPipeline { diff --git a/wgpu-native/src/pipeline.rs b/wgpu-native/src/pipeline.rs index 60c02a960f..a4651eadd3 100644 --- a/wgpu-native/src/pipeline.rs +++ b/wgpu-native/src/pipeline.rs @@ -122,6 +122,13 @@ pub struct DepthStencilStateDescriptor { pub stencil_write_mask: u32, } +impl DepthStencilStateDescriptor { + pub fn needs_stencil_reference(&self) -> bool { + !self.stencil_front.compare.is_trivial() || + !self.stencil_back.compare.is_trivial() + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum IndexFormat { @@ -269,6 +276,7 @@ bitflags! { #[repr(transparent)] pub struct PipelineFlags: u32 { const BLEND_COLOR = 1; + const STENCIL_REFERENCE = 2; } } diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index 431fd8991d..5e80599426 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -280,6 +280,16 @@ pub enum CompareFunction { Always = 7, } +impl CompareFunction { + pub fn is_trivial(&self) -> bool { + match *self { + CompareFunction::Never | + CompareFunction::Always => true, + _ => false, + } + } +} + #[repr(C)] pub struct SamplerDescriptor { pub address_mode_u: AddressMode, From a6f3637c0cf38d2d91b041c7b91b9499b35c9df5 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 14 May 2019 12:49:10 -0400 Subject: [PATCH 3/5] Debug labels --- Makefile | 4 +- ffi/wgpu.h | 16 ++++- wgpu-native/src/command/compute.rs | 42 +++++++++-- wgpu-native/src/command/render.rs | 112 ++++++++++++++++++----------- 4 files changed, 121 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index 8f5bb9825f..f2779bfab4 100644 --- a/Makefile +++ b/Makefile @@ -53,10 +53,10 @@ lib-native: Cargo.lock wgpu-native/Cargo.toml $(wildcard wgpu-native/**/*.rs) lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(wildcard wgpu-native/**/*.rs wgpu-remote/**/*.rs) cargo build --manifest-path wgpu-remote/Cargo.toml --features $(FEATURE_RUST) -ffi/wgpu.h: wgpu-native/cbindgen.toml $(wildcard wgpu-native/**/*.rs) +ffi/wgpu.h: wgpu-native/cbindgen.toml $(wildcard wgpu-native/src/**/*.rs) rustup run nightly cbindgen wgpu-native >ffi/wgpu.h -ffi/wgpu-remote.h: wgpu-remote/cbindgen.toml $(wildcard wgpu-native/**/*.rs wgpu-remote/**/*.rs) +ffi/wgpu-remote.h: wgpu-remote/cbindgen.toml $(wildcard wgpu-native/src/**/*.rs wgpu-remote/src/**/*.rs) rustup run nightly cbindgen wgpu-remote >ffi/wgpu-remote.h examples-native: lib-native ffi/wgpu.h examples/hello_triangle_c/main.c diff --git a/ffi/wgpu.h b/ffi/wgpu.h index e12762ae69..44688b3985 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -342,6 +342,8 @@ typedef struct { const WGPURenderPassDepthStencilAttachmentDescriptor_TextureViewId *depth_stencil_attachment; } WGPURenderPassDescriptor; +typedef const char *WGPURawString; + typedef WGPUId WGPUComputePipelineId; typedef WGPUId WGPUInstanceId; @@ -436,8 +438,6 @@ typedef WGPUId WGPUPipelineLayoutId; typedef WGPUId WGPUShaderModuleId; -typedef const char *WGPURawString; - typedef struct { WGPUShaderModuleId module; WGPURawString entry_point; @@ -677,6 +677,12 @@ void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id); +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); + void wgpu_compute_pass_set_bind_group(WGPUComputePassId pass_id, uint32_t index, WGPUBindGroupId bind_group_id, @@ -795,6 +801,12 @@ void wgpu_render_pass_draw_indexed(WGPURenderPassId pass_id, WGPUCommandBufferId wgpu_render_pass_end_pass(WGPURenderPassId pass_id); +void wgpu_render_pass_insert_debug_marker(WGPURenderPassId _pass_id, WGPURawString _label); + +void wgpu_render_pass_pop_debug_group(WGPURenderPassId _pass_id); + +void wgpu_render_pass_push_debug_group(WGPURenderPassId _pass_id, WGPURawString _label); + void wgpu_render_pass_set_bind_group(WGPURenderPassId pass_id, uint32_t index, WGPUBindGroupId bind_group_id, diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index 032b4d2c8e..044c3fe85c 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -7,6 +7,7 @@ use crate::{ CommandBufferId, ComputePassId, ComputePipelineId, + RawString, Stored, }; @@ -33,6 +34,8 @@ impl ComputePass { } } +// Common routines between render/compute + #[no_mangle] pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: ComputePassId) -> CommandBufferId { let pass = HUB.compute_passes.unregister(pass_id); @@ -45,13 +48,6 @@ pub extern "C" fn wgpu_compute_pass_end_pass(pass_id: ComputePassId) -> CommandB pass.cmb_id.value } -#[no_mangle] -pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u32, z: u32) { - unsafe { - HUB.compute_passes.write()[pass_id].raw.dispatch([x, y, z]); - } -} - #[no_mangle] pub extern "C" fn wgpu_compute_pass_set_bind_group( pass_id: ComputePassId, @@ -104,6 +100,38 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group( }; } +#[no_mangle] +pub extern "C" fn wgpu_compute_pass_push_debug_group( + _pass_id: ComputePassId, + _label: RawString, +) { + //TODO +} + +#[no_mangle] +pub extern "C" fn wgpu_compute_pass_pop_debug_group( + _pass_id: ComputePassId, +) { + //TODO +} + +#[no_mangle] +pub extern "C" fn wgpu_compute_pass_insert_debug_marker( + _pass_id: ComputePassId, + _label: RawString, +) { + //TODO +} + +// Compute-specific routines + +#[no_mangle] +pub extern "C" fn wgpu_compute_pass_dispatch(pass_id: ComputePassId, x: u32, y: u32, z: u32) { + unsafe { + HUB.compute_passes.write()[pass_id].raw.dispatch([x, y, z]); + } +} + #[no_mangle] pub extern "C" fn wgpu_compute_pass_set_pipeline( pass_id: ComputePassId, diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index a388a98ac3..9001790003 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -11,6 +11,7 @@ use crate::{ Color, CommandBuffer, CommandBufferId, + RawString, RenderPassId, RenderPipelineId, Stored, @@ -101,6 +102,8 @@ impl RenderPass { } } +// Common routines between render/compute + #[no_mangle] pub extern "C" fn wgpu_render_pass_end_pass(pass_id: RenderPassId) -> CommandBufferId { let mut pass = HUB.render_passes.unregister(pass_id); @@ -132,6 +135,73 @@ pub extern "C" fn wgpu_render_pass_end_pass(pass_id: RenderPassId) -> CommandBuf pass.cmb_id.value } +#[no_mangle] +pub extern "C" fn wgpu_render_pass_set_bind_group( + pass_id: RenderPassId, + index: u32, + bind_group_id: BindGroupId, + offsets_ptr: *const u32, + offsets_count: usize, +) { + let mut pass_guard = HUB.render_passes.write(); + let pass = &mut pass_guard[pass_id]; + let bind_group_guard = HUB.bind_groups.read(); + let bind_group = &bind_group_guard[bind_group_id]; + + assert_eq!(bind_group.dynamic_count, offsets_count); + let offsets = if offsets_count != 0 { + unsafe { + slice::from_raw_parts(offsets_ptr, offsets_count) + } + } else { + &[] + }; + + pass.trackers.consume_by_extend(&bind_group.used); + + if let Some((pipeline_layout_id, follow_up)) = + pass.binder + .provide_entry(index as usize, bind_group_id, bind_group, offsets) + { + let pipeline_layout_guard = HUB.pipeline_layouts.read(); + let bind_groups = + iter::once(&bind_group.raw).chain(follow_up.map(|bg_id| &bind_group_guard[bg_id].raw)); + unsafe { + pass.raw.bind_graphics_descriptor_sets( + &&pipeline_layout_guard[pipeline_layout_id].raw, + index as usize, + bind_groups, + offsets, + ); + } + }; +} + +#[no_mangle] +pub extern "C" fn wgpu_render_pass_push_debug_group( + _pass_id: RenderPassId, + _label: RawString, +) { + //TODO +} + +#[no_mangle] +pub extern "C" fn wgpu_render_pass_pop_debug_group( + _pass_id: RenderPassId, +) { + //TODO +} + +#[no_mangle] +pub extern "C" fn wgpu_render_pass_insert_debug_marker( + _pass_id: RenderPassId, + _label: RawString, +) { + //TODO +} + +// Render-specific routines + #[no_mangle] pub extern "C" fn wgpu_render_pass_set_index_buffer( pass_id: RenderPassId, @@ -233,48 +303,6 @@ pub extern "C" fn wgpu_render_pass_draw_indexed( } } -#[no_mangle] -pub extern "C" fn wgpu_render_pass_set_bind_group( - pass_id: RenderPassId, - index: u32, - bind_group_id: BindGroupId, - offsets_ptr: *const u32, - offsets_count: usize, -) { - let mut pass_guard = HUB.render_passes.write(); - let pass = &mut pass_guard[pass_id]; - let bind_group_guard = HUB.bind_groups.read(); - let bind_group = &bind_group_guard[bind_group_id]; - - assert_eq!(bind_group.dynamic_count, offsets_count); - let offsets = if offsets_count != 0 { - unsafe { - slice::from_raw_parts(offsets_ptr, offsets_count) - } - } else { - &[] - }; - - pass.trackers.consume_by_extend(&bind_group.used); - - if let Some((pipeline_layout_id, follow_up)) = - pass.binder - .provide_entry(index as usize, bind_group_id, bind_group, offsets) - { - let pipeline_layout_guard = HUB.pipeline_layouts.read(); - let bind_groups = - iter::once(&bind_group.raw).chain(follow_up.map(|bg_id| &bind_group_guard[bg_id].raw)); - unsafe { - pass.raw.bind_graphics_descriptor_sets( - &&pipeline_layout_guard[pipeline_layout_id].raw, - index as usize, - bind_groups, - offsets, - ); - } - }; -} - #[no_mangle] pub extern "C" fn wgpu_render_pass_set_pipeline( pass_id: RenderPassId, From 48e74e77d79b9280e569f1c47bbb493de66f14f8 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 14 May 2019 12:57:03 -0400 Subject: [PATCH 4/5] Add set_viewport --- ffi/wgpu.h | 10 +++++++- wgpu-native/src/command/render.rs | 41 ++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 44688b3985..14686fc49f 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -817,7 +817,7 @@ void wgpu_render_pass_set_blend_color(WGPURenderPassId pass_id, const WGPUColor void wgpu_render_pass_set_index_buffer(WGPURenderPassId pass_id, WGPUBufferId buffer_id, - uint32_t offset); + WGPUBufferAddress offset); void wgpu_render_pass_set_pipeline(WGPURenderPassId pass_id, WGPURenderPipelineId pipeline_id); @@ -834,6 +834,14 @@ void wgpu_render_pass_set_vertex_buffers(WGPURenderPassId pass_id, const uint32_t *offset_ptr, uintptr_t count); +void wgpu_render_pass_set_viewport(WGPURenderPassId pass_id, + float x, + float y, + float w, + float h, + float min_depth, + float max_depth); + WGPUSwapChainOutput wgpu_swap_chain_get_next_texture(WGPUSwapChainId swap_chain_id); void wgpu_swap_chain_present(WGPUSwapChainId swap_chain_id); diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 9001790003..c43f138c65 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -7,6 +7,7 @@ use crate::{ resource::BufferUsage, track::{Stitch, TrackerSet}, BindGroupId, + BufferAddress, BufferId, Color, CommandBuffer, @@ -49,7 +50,7 @@ enum DrawError { #[derive(Debug)] pub struct IndexState { - pub(crate) bound_buffer_view: Option<(BufferId, u32)>, + pub(crate) bound_buffer_view: Option<(BufferId, BufferAddress)>, pub(crate) format: IndexFormat, } @@ -206,7 +207,7 @@ pub extern "C" fn wgpu_render_pass_insert_debug_marker( pub extern "C" fn wgpu_render_pass_set_index_buffer( pass_id: RenderPassId, buffer_id: BufferId, - offset: u32, + offset: BufferAddress, ) { let mut pass_guard = HUB.render_passes.write(); let buffer_guard = HUB.buffers.read(); @@ -220,7 +221,7 @@ pub extern "C" fn wgpu_render_pass_set_index_buffer( let view = hal::buffer::IndexBufferView { buffer: &buffer.raw, - offset: offset as u64, + offset, index_type: conv::map_index_format(pass.index_state.format), }; @@ -371,7 +372,7 @@ pub extern "C" fn wgpu_render_pass_set_pipeline( let view = hal::buffer::IndexBufferView { buffer: &buffer.raw, - offset: offset as u64, + offset, index_type: conv::map_index_format(pass.index_state.format), }; @@ -406,6 +407,38 @@ pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: RenderPassId, } } +#[no_mangle] +pub extern "C" fn wgpu_render_pass_set_viewport( + pass_id: RenderPassId, + x: f32, + y: f32, + w: f32, + h: f32, + min_depth: f32, + max_depth: f32, +) { + let mut pass_guard = HUB.render_passes.write(); + let pass = &mut pass_guard[pass_id]; + + unsafe { + use std::convert::TryFrom; + use std::i16; + + pass.raw.set_viewports( + 0, + &[hal::pso::Viewport { + rect: hal::pso::Rect { + x: i16::try_from(x.round() as i64).unwrap_or(0), + y: i16::try_from(y.round() as i64).unwrap_or(0), + w: i16::try_from(w.round() as i64).unwrap_or(i16::MAX), + h: i16::try_from(h.round() as i64).unwrap_or(i16::MAX), + }, + depth: min_depth .. max_depth, + }], + ); + } +} + #[no_mangle] pub extern "C" fn wgpu_render_pass_set_scissor_rect( pass_id: RenderPassId, From 1875523a6ae180b640a6cd64a932b82c7bfff469 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 14 May 2019 12:59:41 -0400 Subject: [PATCH 5/5] Rust formatting pass --- wgpu-native/src/binding_model.rs | 10 ++- wgpu-native/src/command/allocator.rs | 2 +- wgpu-native/src/command/bind.rs | 13 ++-- wgpu-native/src/command/compute.rs | 14 +--- wgpu-native/src/command/mod.rs | 18 +++--- wgpu-native/src/command/render.rs | 32 ++++------ wgpu-native/src/command/transfer.rs | 50 ++++++--------- wgpu-native/src/device.rs | 96 +++++++++++----------------- wgpu-native/src/hub.rs | 25 +++++--- wgpu-native/src/instance.rs | 17 +++-- wgpu-native/src/lib.rs | 13 ++-- wgpu-native/src/pipeline.rs | 13 +++- wgpu-native/src/resource.rs | 3 +- wgpu-native/src/swap_chain.rs | 56 ++++++++++------ wgpu-native/src/track.rs | 8 +-- wgpu-remote/src/lib.rs | 9 +-- wgpu-remote/src/server.rs | 8 +-- 17 files changed, 188 insertions(+), 199 deletions(-) diff --git a/wgpu-native/src/binding_model.rs b/wgpu-native/src/binding_model.rs index c307bd2226..77086ce121 100644 --- a/wgpu-native/src/binding_model.rs +++ b/wgpu-native/src/binding_model.rs @@ -1,4 +1,12 @@ -use crate::{track::TrackerSet, BindGroupLayoutId, BufferId, LifeGuard, SamplerId, TextureViewId, BufferAddress}; +use crate::{ + track::TrackerSet, + BindGroupLayoutId, + BufferAddress, + BufferId, + LifeGuard, + SamplerId, + TextureViewId, +}; use arrayvec::ArrayVec; use bitflags::bitflags; diff --git a/wgpu-native/src/command/allocator.rs b/wgpu-native/src/command/allocator.rs index e21ebc10d9..48b52a712a 100644 --- a/wgpu-native/src/command/allocator.rs +++ b/wgpu-native/src/command/allocator.rs @@ -109,7 +109,7 @@ impl CommandAllocator { pub fn maintain(&self, last_done: SubmissionIndex) { let mut inner = self.inner.lock(); - for i in (0..inner.pending.len()).rev() { + for i in (0 .. inner.pending.len()).rev() { let index = inner.pending[i] .life_guard .submission_index diff --git a/wgpu-native/src/command/bind.rs b/wgpu-native/src/command/bind.rs index db7670fecb..d1d5edafa4 100644 --- a/wgpu-native/src/command/bind.rs +++ b/wgpu-native/src/command/bind.rs @@ -46,7 +46,12 @@ pub struct BindGroupEntry { } impl BindGroupEntry { - fn provide(&mut self, bind_group_id: BindGroupId, bind_group: &BindGroupHandle, offsets: &[u32]) -> Provision { + fn provide( + &mut self, + bind_group_id: BindGroupId, + bind_group: &BindGroupHandle, + offsets: &[u32], + ) -> Provision { let was_compatible = match self.provided { Some(BindGroupPair { layout_id, @@ -120,7 +125,7 @@ pub struct Binder { impl Binder { pub(crate) fn reset_expectations(&mut self, length: usize) { - for entry in self.entries[length..].iter_mut() { + for entry in self.entries[length ..].iter_mut() { entry.expected_layout_id = None; } } @@ -148,7 +153,7 @@ impl Binder { None } Provision::Changed { was_compatible, .. } => { - if self.entries[..index].iter().all(|entry| entry.is_valid()) { + if self.entries[.. index].iter().all(|entry| entry.is_valid()) { self.pipeline_layout_id.map(move |pipeline_layout_id| { let end = if was_compatible { trace!("\t\tgenerating follow-up sequence"); @@ -159,7 +164,7 @@ impl Binder { ( pipeline_layout_id, TakeSome { - iter: self.entries[index + 1..end] + iter: self.entries[index + 1 .. end] .iter() .map(|entry| entry.actual_value()), }, diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index 044c3fe85c..c84c21b210 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -15,7 +15,6 @@ use hal::{self, command::RawCommandBuffer}; use std::{iter, slice}; - pub struct ComputePass { raw: B::CommandBuffer, cmb_id: Stored, @@ -63,9 +62,7 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group( assert_eq!(bind_group.dynamic_count, offsets_count); let offsets = if offsets_count != 0 { - unsafe { - slice::from_raw_parts(offsets_ptr, offsets_count) - } + unsafe { slice::from_raw_parts(offsets_ptr, offsets_count) } } else { &[] }; @@ -101,17 +98,12 @@ pub extern "C" fn wgpu_compute_pass_set_bind_group( } #[no_mangle] -pub extern "C" fn wgpu_compute_pass_push_debug_group( - _pass_id: ComputePassId, - _label: RawString, -) { +pub extern "C" fn wgpu_compute_pass_push_debug_group(_pass_id: ComputePassId, _label: RawString) { //TODO } #[no_mangle] -pub extern "C" fn wgpu_compute_pass_pop_debug_group( - _pass_id: ComputePassId, -) { +pub extern "C" fn wgpu_compute_pass_pop_debug_group(_pass_id: ComputePassId) { //TODO } diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index 3e592b33ac..bf71f1b7ce 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -23,8 +23,8 @@ use crate::{ resource::TexturePlacement, swap_chain::{SwapChainLink, SwapImageEpoch}, track::{DummyUsage, Stitch, TrackerSet}, - BufferId, BufferHandle, + BufferId, Color, CommandBufferHandle, CommandBufferId, @@ -113,9 +113,9 @@ impl CommandBufferHandle { trace!("transit buffer {:?} {:?}", id, transit); hal::memory::Barrier::Buffer { states: conv::map_buffer_state(transit.start) - ..conv::map_buffer_state(transit.end), + .. conv::map_buffer_state(transit.end), target: &b.raw, - range: None..None, + range: None .. None, families: None, } }); @@ -128,7 +128,7 @@ impl CommandBufferHandle { let aspects = t.full_range.aspects; hal::memory::Barrier::Image { states: conv::map_texture_state(transit.start, aspects) - ..conv::map_texture_state(transit.end, aspects), + .. conv::map_texture_state(transit.end, aspects), target: &t.raw, range: t.full_range.clone(), //TODO? families: None, @@ -139,7 +139,7 @@ impl CommandBufferHandle { let stages = all_buffer_stages() | all_image_stages(); unsafe { raw.pipeline_barrier( - stages..stages, + stages .. stages, hal::memory::Dependencies::empty(), buffer_barriers.chain(texture_barriers), ); @@ -214,7 +214,7 @@ pub fn command_encoder_begin_render_pass( samples: view.samples, ops: conv::map_load_store_ops(at.depth_load_op, at.depth_store_op), stencil_ops: conv::map_load_store_ops(at.stencil_load_op, at.stencil_store_op), - layouts: layout..layout, + layouts: layout .. layout, } }); @@ -252,7 +252,7 @@ pub fn command_encoder_begin_render_pass( samples: view.samples, ops: conv::map_load_store_ops(at.load_op, at.store_op), stencil_ops: hal::pass::AttachmentOps::DONT_CARE, - layouts: layout..layout, + layouts: layout .. layout, } }); @@ -278,7 +278,7 @@ pub fn command_encoder_begin_render_pass( ); let subpass = hal::pass::SubpassDesc { - colors: &color_ids[..color_attachments.len()], + colors: &color_ids[.. color_attachments.len()], depth_stencil: depth_stencil_attachment.map(|_| &depth_id), inputs: &[], resolves: &[], @@ -352,7 +352,7 @@ pub fn command_encoder_begin_render_pass( 0, iter::once(hal::pso::Viewport { rect, - depth: 0.0..1.0, + depth: 0.0 .. 1.0, }), ); } diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index c43f138c65..760e2b9eff 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -151,9 +151,7 @@ pub extern "C" fn wgpu_render_pass_set_bind_group( assert_eq!(bind_group.dynamic_count, offsets_count); let offsets = if offsets_count != 0 { - unsafe { - slice::from_raw_parts(offsets_ptr, offsets_count) - } + unsafe { slice::from_raw_parts(offsets_ptr, offsets_count) } } else { &[] }; @@ -179,25 +177,17 @@ pub extern "C" fn wgpu_render_pass_set_bind_group( } #[no_mangle] -pub extern "C" fn wgpu_render_pass_push_debug_group( - _pass_id: RenderPassId, - _label: RawString, -) { +pub extern "C" fn wgpu_render_pass_push_debug_group(_pass_id: RenderPassId, _label: RawString) { //TODO } #[no_mangle] -pub extern "C" fn wgpu_render_pass_pop_debug_group( - _pass_id: RenderPassId, -) { +pub extern "C" fn wgpu_render_pass_pop_debug_group(_pass_id: RenderPassId) { //TODO } #[no_mangle] -pub extern "C" fn wgpu_render_pass_insert_debug_marker( - _pass_id: RenderPassId, - _label: RawString, -) { +pub extern "C" fn wgpu_render_pass_insert_debug_marker(_pass_id: RenderPassId, _label: RawString) { //TODO } @@ -276,8 +266,8 @@ pub extern "C" fn wgpu_render_pass_draw( unsafe { pass.raw.draw( - first_vertex..first_vertex + vertex_count, - first_instance..first_instance + instance_count, + first_vertex .. first_vertex + vertex_count, + first_instance .. first_instance + instance_count, ); } } @@ -297,9 +287,9 @@ pub extern "C" fn wgpu_render_pass_draw_indexed( unsafe { pass.raw.draw_indexed( - first_index..first_index + index_count, + first_index .. first_index + index_count, base_vertex, - first_instance..first_instance + instance_count, + first_instance .. first_instance + instance_count, ); } } @@ -319,8 +309,10 @@ pub extern "C" fn wgpu_render_pass_set_pipeline( "The render pipeline is not compatible with the pass!" ); - pass.blend_color_status.require(pipeline.flags.contains(PipelineFlags::BLEND_COLOR)); - pass.stencil_reference_status.require(pipeline.flags.contains(PipelineFlags::STENCIL_REFERENCE)); + pass.blend_color_status + .require(pipeline.flags.contains(PipelineFlags::BLEND_COLOR)); + pass.stencil_reference_status + .require(pipeline.flags.contains(PipelineFlags::STENCIL_REFERENCE)); unsafe { pass.raw.bind_graphics_pipeline(&pipeline.raw); diff --git a/wgpu-native/src/command/transfer.rs b/wgpu-native/src/command/transfer.rs index ec05325fc6..7de9ed8924 100644 --- a/wgpu-native/src/command/transfer.rs +++ b/wgpu-native/src/command/transfer.rs @@ -56,10 +56,10 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( .get_with_replaced_usage(&*buffer_guard, src, BufferUsage::TRANSFER_SRC) .unwrap(); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Buffer { - states: conv::map_buffer_state(old)..hal::buffer::Access::TRANSFER_READ, + states: conv::map_buffer_state(old) .. hal::buffer::Access::TRANSFER_READ, target: &src_buffer.raw, families: None, - range: None..None, + range: None .. None, }); let (dst_buffer, dst_usage) = cmb @@ -68,10 +68,10 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( .get_with_replaced_usage(&*buffer_guard, dst, BufferUsage::TRANSFER_DST) .unwrap(); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Buffer { - states: conv::map_buffer_state(old)..hal::buffer::Access::TRANSFER_WRITE, + states: conv::map_buffer_state(old) .. hal::buffer::Access::TRANSFER_WRITE, target: &dst_buffer.raw, families: None, - range: None..None, + range: None .. None, }); let region = hal::command::BufferCopy { @@ -82,7 +82,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( let cmb_raw = cmb.raw.last_mut().unwrap(); unsafe { cmb_raw.pipeline_barrier( - all_buffer_stages()..all_buffer_stages(), + all_buffer_stages() .. all_buffer_stages(), hal::memory::Dependencies::empty(), src_barrier.into_iter().chain(dst_barrier), ); @@ -105,17 +105,13 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( let (src_buffer, src_usage) = cmb .trackers .buffers - .get_with_replaced_usage( - &*buffer_guard, - source.buffer, - BufferUsage::TRANSFER_SRC, - ) + .get_with_replaced_usage(&*buffer_guard, source.buffer, BufferUsage::TRANSFER_SRC) .unwrap(); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Buffer { - states: conv::map_buffer_state(old)..hal::buffer::Access::TRANSFER_READ, + states: conv::map_buffer_state(old) .. hal::buffer::Access::TRANSFER_READ, target: &src_buffer.raw, families: None, - range: None..None, + range: None .. None, }); let (dst_texture, dst_usage) = cmb @@ -130,7 +126,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( let aspects = dst_texture.full_range.aspects; let dst_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_DST, aspects); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Image { - states: conv::map_texture_state(old, aspects)..dst_texture_state, + states: conv::map_texture_state(old, aspects) .. dst_texture_state, target: &dst_texture.raw, families: None, range: dst_texture.full_range.clone(), @@ -166,7 +162,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( let stages = all_buffer_stages() | all_image_stages(); unsafe { cmb_raw.pipeline_barrier( - stages..stages, + stages .. stages, hal::memory::Dependencies::empty(), src_barrier.into_iter().chain(dst_barrier), ); @@ -194,16 +190,12 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( let (src_texture, src_usage) = cmb .trackers .textures - .get_with_replaced_usage( - &*texture_guard, - source.texture, - TextureUsage::TRANSFER_SRC, - ) + .get_with_replaced_usage(&*texture_guard, source.texture, TextureUsage::TRANSFER_SRC) .unwrap(); let aspects = src_texture.full_range.aspects; let src_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_SRC, aspects); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Image { - states: conv::map_texture_state(old, aspects)..src_texture_state, + states: conv::map_texture_state(old, aspects) .. src_texture_state, target: &src_texture.raw, families: None, range: src_texture.full_range.clone(), @@ -224,10 +216,10 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( ) .unwrap(); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Buffer { - states: conv::map_buffer_state(old)..hal::buffer::Access::TRANSFER_WRITE, + states: conv::map_buffer_state(old) .. hal::buffer::Access::TRANSFER_WRITE, target: &dst_buffer.raw, families: None, - range: None..None, + range: None .. None, }); let bytes_per_texel = conv::map_texture_format(src_texture.format) @@ -252,7 +244,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( let stages = all_buffer_stages() | all_image_stages(); unsafe { cmb_raw.pipeline_barrier( - stages..stages, + stages .. stages, hal::memory::Dependencies::empty(), src_barrier.into_iter().chain(dst_barrier), ); @@ -279,11 +271,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( let (src_texture, src_usage) = cmb .trackers .textures - .get_with_replaced_usage( - &*texture_guard, - source.texture, - TextureUsage::TRANSFER_SRC, - ) + .get_with_replaced_usage(&*texture_guard, source.texture, TextureUsage::TRANSFER_SRC) .unwrap(); let (dst_texture, dst_usage) = cmb .trackers @@ -300,13 +288,13 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( let dst_texture_state = conv::map_texture_state(TextureUsage::TRANSFER_DST, aspects); let src_barrier = src_usage.map(|old| hal::memory::Barrier::Image { - states: conv::map_texture_state(old, aspects)..src_texture_state, + states: conv::map_texture_state(old, aspects) .. src_texture_state, target: &src_texture.raw, families: None, range: src_texture.full_range.clone(), }); let dst_barrier = dst_usage.map(|old| hal::memory::Barrier::Image { - states: conv::map_texture_state(old, aspects)..dst_texture_state, + states: conv::map_texture_state(old, aspects) .. dst_texture_state, target: &dst_texture.raw, families: None, range: dst_texture.full_range.clone(), @@ -338,7 +326,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( let cmb_raw = cmb.raw.last_mut().unwrap(); unsafe { cmb_raw.pipeline_barrier( - all_image_stages()..all_image_stages(), + all_image_stages() .. all_image_stages(), hal::memory::Dependencies::empty(), src_barrier.into_iter().chain(dst_barrier), ); diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 4670b8f0b7..104f7a5313 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -52,17 +52,9 @@ use log::{info, trace}; //use rendy_memory::{allocator, Config, Heaps}; use parking_lot::Mutex; -use std::{ - collections::hash_map::Entry, - ffi, - iter, - ptr, - slice, - sync::atomic::Ordering, -}; #[cfg(feature = "local")] use std::sync::atomic::AtomicBool; - +use std::{collections::hash_map::Entry, ffi, iter, ptr, slice, sync::atomic::Ordering}; const CLEANUP_WAIT_MS: u64 = 5000; pub const MAX_COLOR_TARGETS: usize = 4; @@ -189,11 +181,10 @@ impl PendingResources { //TODO: enable when `is_sorted_by_key` is stable //debug_assert!(self.active.is_sorted_by_key(|a| a.index)); - let done_count = self.active + let done_count = self + .active .iter() - .position(|a| unsafe { - !device.get_fence_status(&a.fence).unwrap() - }) + .position(|a| unsafe { !device.get_fence_status(&a.fence).unwrap() }) .unwrap_or(self.active.len()); let last_done = if done_count != 0 { self.active[done_count - 1].index @@ -201,7 +192,7 @@ impl PendingResources { 0 }; - for a in self.active.drain(..done_count) { + for a in self.active.drain(.. done_count) { trace!("Active submission {} is done", a.index); self.free.extend(a.resources.into_iter().map(|(_, r)| r)); self.ready_to_map.extend(a.mapped); @@ -235,7 +226,7 @@ impl PendingResources { impl PendingResources { fn triage_referenced(&mut self, trackers: &mut TrackerSet) { - for i in (0..self.referenced.len()).rev() { + for i in (0 .. self.referenced.len()).rev() { let num_refs = self.referenced[i].1.load(); // Before destruction, a resource is expected to have the following strong refs: // 1. in resource itself @@ -391,7 +382,7 @@ fn map_buffer( limits.non_coherent_atom_size as u64 - 1 }; let atom_offset = original_range.start & atom_mask; - let range = (original_range.start & !atom_mask)..((original_range.end - 1) | atom_mask) + 1; + let range = (original_range.start & !atom_mask) .. ((original_range.end - 1) | atom_mask) + 1; let pointer = unsafe { raw.map_memory(&buffer.memory, range.clone()) }?; if !is_coherent { @@ -524,9 +515,7 @@ impl Device { } impl Device { - fn maintain( - &self, force_wait: bool - ) -> Vec { + fn maintain(&self, force_wait: bool) -> Vec { let mut pending = self.pending.lock(); let mut trackers = self.trackers.lock(); @@ -642,12 +631,7 @@ pub extern "C" fn wgpu_device_create_buffer( let buffer = device_create_buffer(device_id, desc); let ref_count = buffer.life_guard.ref_count.clone(); let id = HUB.buffers.register_local(buffer); - device_track_buffer( - device_id, - id, - ref_count, - resource::BufferUsage::empty(), - ); + device_track_buffer(device_id, id, ref_count, resource::BufferUsage::empty()); id } @@ -665,7 +649,7 @@ pub extern "C" fn wgpu_device_create_buffer_mapped( { let device_guard = HUB.devices.read(); let device = &device_guard[device_id]; - let range = 0..desc.size; + let range = 0 .. desc.size; match map_buffer( &device.raw, @@ -688,12 +672,7 @@ pub extern "C" fn wgpu_device_create_buffer_mapped( let ref_count = buffer.life_guard.ref_count.clone(); let id = HUB.buffers.register_local(buffer); - device_track_buffer( - device_id, - id, - ref_count, - resource::BufferUsage::MAP_WRITE, - ); + device_track_buffer(device_id, id, ref_count, resource::BufferUsage::MAP_WRITE); id } @@ -702,13 +681,10 @@ pub extern "C" fn wgpu_buffer_destroy(buffer_id: BufferId) { let device_guard = HUB.devices.read(); let buffer_guard = HUB.buffers.read(); let buffer = &buffer_guard[buffer_id]; - device_guard[buffer.device_id.value] - .pending - .lock() - .destroy( - ResourceId::Buffer(buffer_id), - buffer.life_guard.ref_count.clone(), - ); + device_guard[buffer.device_id.value].pending.lock().destroy( + ResourceId::Buffer(buffer_id), + buffer.life_guard.ref_count.clone(), + ); } pub fn device_create_texture( @@ -772,8 +748,8 @@ pub fn device_create_texture( format: desc.format, full_range: hal::image::SubresourceRange { aspects, - levels: 0..desc.mip_level_count as hal::image::Level, - layers: 0..desc.array_layer_count as hal::image::Layer, + levels: 0 .. desc.mip_level_count as hal::image::Level, + layers: 0 .. desc.array_layer_count as hal::image::Layer, }, placement: resource::TexturePlacement::Memory(memory), life_guard: LifeGuard::new(), @@ -865,8 +841,9 @@ pub extern "C" fn wgpu_texture_create_view( conv::map_texture_view_dimension(desc.dimension), hal::image::SubresourceRange { aspects: conv::map_texture_aspect_flags(desc.aspect), - levels: desc.base_mip_level as u8..(desc.base_mip_level + desc.level_count) as u8, - layers: desc.base_array_layer as u16..(desc.base_array_layer + desc.array_count) as u16, + levels: desc.base_mip_level as u8 .. (desc.base_mip_level + desc.level_count) as u8, + layers: desc.base_array_layer as u16 + .. (desc.base_array_layer + desc.array_count) as u16, }, ); let ref_count = view.life_guard.ref_count.clone(); @@ -941,7 +918,7 @@ pub fn device_create_sampler( conv::map_wrap(desc.address_mode_w), ), lod_bias: 0.0.into(), - lod_range: desc.lod_min_clamp.into()..desc.lod_max_clamp.into(), + lod_range: desc.lod_min_clamp.into() .. desc.lod_max_clamp.into(), comparison: if desc.compare_function == resource::CompareFunction::Always { None } else { @@ -1102,7 +1079,7 @@ pub fn device_create_bind_group( "Misaligned buffer offset {}", bb.offset ); - let range = Some(bb.offset)..Some(bb.offset + bb.size); + let range = Some(bb.offset) .. Some(bb.offset + bb.size); hal::pso::Descriptor::Buffer(&buffer.raw, range) } binding_model::BindingResource::Sampler(id) => { @@ -1394,7 +1371,7 @@ pub fn device_create_render_pipeline( samples: desc.sample_count as u8, ops: hal::pass::AttachmentOps::PRESERVE, stencil_ops: hal::pass::AttachmentOps::DONT_CARE, - layouts: hal::image::Layout::General..hal::image::Layout::General, + layouts: hal::image::Layout::General .. hal::image::Layout::General, }) .collect(), depth_stencil: depth_stencil_state.map(|at| hal::pass::Attachment { @@ -1402,7 +1379,7 @@ pub fn device_create_render_pipeline( samples: desc.sample_count as u8, ops: hal::pass::AttachmentOps::PRESERVE, stencil_ops: hal::pass::AttachmentOps::PRESERVE, - layouts: hal::image::Layout::General..hal::image::Layout::General, + layouts: hal::image::Layout::General .. hal::image::Layout::General, }), }; @@ -1422,7 +1399,7 @@ pub fn device_create_render_pipeline( ); let subpass = hal::pass::SubpassDesc { - colors: &color_ids[..desc.color_states_length], + colors: &color_ids[.. desc.color_states_length], depth_stencil: depth_stencil_state.map(|_| &depth_id), inputs: &[], resolves: &[], @@ -1447,15 +1424,16 @@ pub fn device_create_render_pipeline( module: &shader_module_guard[desc.vertex_stage.module].raw, specialization: hal::pso::Specialization::EMPTY, }; - let fragment = unsafe { desc.fragment_stage.as_ref() } - .map(|stage| hal::pso::EntryPoint:: { - entry: unsafe { ffi::CStr::from_ptr(stage.entry_point) } - .to_str() - .to_owned() - .unwrap(), // TODO - module: &shader_module_guard[stage.module].raw, - specialization: hal::pso::Specialization::EMPTY, - }); + let fragment = unsafe { desc.fragment_stage.as_ref() }.map(|stage| hal::pso::EntryPoint::< + back::Backend, + > { + entry: unsafe { ffi::CStr::from_ptr(stage.entry_point) } + .to_str() + .to_owned() + .unwrap(), // TODO + module: &shader_module_guard[stage.module].raw, + specialization: hal::pso::Specialization::EMPTY, + }); let shaders = hal::pso::GraphicsShaderSet { vertex, @@ -1762,8 +1740,8 @@ pub fn device_create_swap_chain( format: desc.format, full_range: hal::image::SubresourceRange { aspects: hal::format::Aspects::COLOR, - levels: 0..1, - layers: 0..1, + levels: 0 .. 1, + layers: 0 .. 1, }, placement: resource::TexturePlacement::Void, life_guard: LifeGuard::new(), diff --git a/wgpu-native/src/hub.rs b/wgpu-native/src/hub.rs index 0d652b0e86..4724e837bf 100644 --- a/wgpu-native/src/hub.rs +++ b/wgpu-native/src/hub.rs @@ -35,7 +35,7 @@ use crate::{ TextureId, TextureViewHandle, TextureViewId, - TypedId + TypedId, }; use lazy_static::lazy_static; #[cfg(feature = "local")] @@ -46,7 +46,7 @@ use vec_map::VecMap; use std::{ops, sync::Arc}; /// A simple structure to manage identities of objects. -pub struct IdentityManager { +pub struct IdentityManager { free: Vec, epochs: Vec, phantom: std::marker::PhantomData, @@ -87,13 +87,13 @@ impl IdentityManager { } } -pub struct Storage { +pub struct Storage { //TODO: consider concurrent hashmap? map: VecMap<(T, Epoch)>, _phantom: std::marker::PhantomData, } -impl ops::Index for Storage { +impl ops::Index for Storage { type Output = T; fn index(&self, id: I) -> &T { let (ref value, epoch) = self.map[id.index() as usize]; @@ -102,7 +102,7 @@ impl ops::Index for Storage { } } -impl ops::IndexMut for Storage { +impl ops::IndexMut for Storage { fn index_mut(&mut self, id: I) -> &mut T { let (ref mut value, epoch) = self.map[id.index() as usize]; assert_eq!(epoch, id.epoch()); @@ -110,7 +110,7 @@ impl ops::IndexMut for Storage { } } -impl Storage { +impl Storage { pub fn contains(&self, id: I) -> bool { match self.map.get(id.index() as usize) { Some(&(_, epoch)) if epoch == id.epoch() => true, @@ -119,7 +119,7 @@ impl Storage { } } -pub struct Registry { +pub struct Registry { #[cfg(feature = "local")] identity: Mutex>, data: RwLock>, @@ -130,7 +130,10 @@ impl Default for Registry { Registry { #[cfg(feature = "local")] identity: Mutex::new(IdentityManager::default()), - data: RwLock::new(Storage { map: VecMap::new(), _phantom: std::marker::PhantomData }), + data: RwLock::new(Storage { + map: VecMap::new(), + _phantom: std::marker::PhantomData, + }), } } } @@ -150,7 +153,11 @@ impl ops::DerefMut for Registry { impl Registry { pub fn register(&self, id: I, value: T) { - let old = self.data.write().map.insert(id.index() as usize, (value, id.epoch())); + let old = self + .data + .write() + .map + .insert(id.index() as usize, (value, id.epoch())); assert!(old.is_none()); } diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index a637864c03..67eb992c53 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -1,4 +1,12 @@ -use crate::{binding_model::MAX_BIND_GROUPS, hub::HUB, AdapterHandle, AdapterId, DeviceHandle, InstanceId, SurfaceHandle}; +use crate::{ + binding_model::MAX_BIND_GROUPS, + hub::HUB, + AdapterHandle, + AdapterId, + DeviceHandle, + InstanceId, + SurfaceHandle, +}; #[cfg(feature = "local")] use crate::{DeviceId, SurfaceId}; @@ -66,7 +74,6 @@ pub extern "C" fn wgpu_create_instance() -> InstanceId { HUB.instances.register_local(inst) } - #[cfg(feature = "window-winit")] #[no_mangle] pub extern "C" fn wgpu_instance_create_surface_from_winit( @@ -111,8 +118,10 @@ pub fn instance_create_surface_from_macos_layer( unimplemented!(); #[cfg(feature = "gfx-backend-metal")] - SurfaceHandle::new(HUB.instances.read()[instance_id] - .create_surface_from_layer(layer as *mut _, cfg!(debug_assertions))) + SurfaceHandle::new( + HUB.instances.read()[instance_id] + .create_surface_from_layer(layer as *mut _, cfg!(debug_assertions)), + ) } #[cfg(feature = "local")] diff --git a/wgpu-native/src/lib.rs b/wgpu-native/src/lib.rs index ca20ac6611..a11825b311 100644 --- a/wgpu-native/src/lib.rs +++ b/wgpu-native/src/lib.rs @@ -46,7 +46,6 @@ use std::{ sync::atomic::{AtomicUsize, Ordering}, }; - type SubmissionIndex = usize; pub(crate) type Index = u32; pub(crate) type Epoch = u32; @@ -199,20 +198,20 @@ macro_rules! define_id { ($i:ident) => { transparent!($i); typed_id!($i); - } + }; } macro_rules! transparent { - ($i:ident) => ( + ($i:ident) => { #[repr(transparent)] #[derive(Clone, Copy, Debug, Hash, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct $i(Id); - ) + }; } macro_rules! typed_id { - ($i:ident) => ( + ($i:ident) => { impl $i { fn raw(&self) -> Id { self.0 @@ -229,10 +228,10 @@ macro_rules! typed_id { } fn epoch(&self) -> Epoch { - (self.raw()).1 + (self.raw()).1 } } - ) + }; } define_id!(InstanceId); diff --git a/wgpu-native/src/pipeline.rs b/wgpu-native/src/pipeline.rs index a4651eadd3..e14fea4e78 100644 --- a/wgpu-native/src/pipeline.rs +++ b/wgpu-native/src/pipeline.rs @@ -1,4 +1,12 @@ -use crate::{device::RenderPassContext, resource, BufferAddress, ByteArray, PipelineLayoutId, ShaderModuleId, RawString}; +use crate::{ + device::RenderPassContext, + resource, + BufferAddress, + ByteArray, + PipelineLayoutId, + RawString, + ShaderModuleId, +}; use bitflags::bitflags; @@ -124,8 +132,7 @@ pub struct DepthStencilStateDescriptor { impl DepthStencilStateDescriptor { pub fn needs_stencil_reference(&self) -> bool { - !self.stencil_front.compare.is_trivial() || - !self.stencil_back.compare.is_trivial() + !self.stencil_front.compare.is_trivial() || !self.stencil_back.compare.is_trivial() } } diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index 5e80599426..00a2d06c26 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -283,8 +283,7 @@ pub enum CompareFunction { impl CompareFunction { pub fn is_trivial(&self) -> bool { match *self { - CompareFunction::Never | - CompareFunction::Always => true, + CompareFunction::Never | CompareFunction::Always => true, _ => false, } } diff --git a/wgpu-native/src/swap_chain.rs b/wgpu-native/src/swap_chain.rs index 9b3395f0ac..3e610c7742 100644 --- a/wgpu-native/src/swap_chain.rs +++ b/wgpu-native/src/swap_chain.rs @@ -17,7 +17,9 @@ use log::{trace, warn}; use parking_lot::Mutex; use std::{ - iter, mem, sync::atomic::{AtomicBool, Ordering}, + iter, + mem, + sync::atomic::{AtomicBool, Ordering}, }; pub type SwapImageEpoch = u16; @@ -114,11 +116,9 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) - let mut surface_guard = HUB.surfaces.write(); let swap_chain = surface_guard[swap_chain_id].swap_chain.as_mut().unwrap(); let result = unsafe { - swap_chain.raw.acquire_image( - !0, - Some(&swap_chain.sem_available), - None, - ) + swap_chain + .raw + .acquire_image(!0, Some(&swap_chain.sem_available), None) }; ( result.ok(), @@ -150,12 +150,9 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) - index } None => unsafe { - swap_chain.raw - .acquire_image( - !0, - Some(&swap_chain.sem_available), - None, - ) + swap_chain + .raw + .acquire_image(!0, Some(&swap_chain.sem_available), None) .unwrap() .0 }, @@ -173,9 +170,16 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) - let frame = &mut swap_chain.frames[image_index as usize]; let status = unsafe { - device.raw.wait_for_fence(&frame.fence, FRAME_TIMEOUT_MS * 1_000_000) + device + .raw + .wait_for_fence(&frame.fence, FRAME_TIMEOUT_MS * 1_000_000) }; - assert_eq!(status, Ok(true), "GPU got stuck on a frame (image {}) :(", image_index); + assert_eq!( + status, + Ok(true), + "GPU got stuck on a frame (image {}) :(", + image_index + ); mem::swap(&mut frame.sem_available, &mut swap_chain.sem_available); frame.need_waiting.store(true, Ordering::Release); @@ -184,8 +188,11 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) - .as_swap_chain() .bump_epoch(); - assert_eq!(frame.acquired_epoch, None, "Last swapchain output hasn't been presented"); - frame.acquired_epoch =Some(frame_epoch); + assert_eq!( + frame.acquired_epoch, None, + "Last swapchain output hasn't been presented" + ); + frame.acquired_epoch = Some(frame_epoch); SwapChainOutput { texture_id: frame.texture_id.value, @@ -201,9 +208,16 @@ pub extern "C" fn wgpu_swap_chain_present(swap_chain_id: SwapChainId) { let image_index = swap_chain.acquired.remove(0); let frame = &mut swap_chain.frames[image_index as usize]; let epoch = frame.acquired_epoch.take(); - assert!(epoch.is_some(), "Presented frame (image {}) was not acquired", image_index); - assert!(!frame.need_waiting.load(Ordering::Acquire), - "No rendering work has been submitted for the presented frame (image {})", image_index); + assert!( + epoch.is_some(), + "Presented frame (image {}) was not acquired", + image_index + ); + assert!( + !frame.need_waiting.load(Ordering::Acquire), + "No rendering work has been submitted for the presented frame (image {})", + image_index + ); let mut device_guard = HUB.devices.write(); let device = &mut device_guard[swap_chain.device_id.value]; @@ -229,7 +243,7 @@ pub extern "C" fn wgpu_swap_chain_present(swap_chain_id: SwapChainId) { .into_source() .map(|old| hal::memory::Barrier::Image { states: conv::map_texture_state(old, hal::format::Aspects::COLOR) - ..( + .. ( hal::image::Access::COLOR_ATTACHMENT_WRITE, hal::image::Layout::Present, ), @@ -241,7 +255,7 @@ pub extern "C" fn wgpu_swap_chain_present(swap_chain_id: SwapChainId) { let err = unsafe { frame.comb.begin(false); frame.comb.pipeline_barrier( - all_image_stages()..hal::pso::PipelineStage::COLOR_ATTACHMENT_OUTPUT, + all_image_stages() .. hal::pso::PipelineStage::COLOR_ATTACHMENT_OUTPUT, hal::memory::Dependencies::empty(), barrier, ); diff --git a/wgpu-native/src/track.rs b/wgpu-native/src/track.rs index 2e0d5fc092..3374e9ee70 100644 --- a/wgpu-native/src/track.rs +++ b/wgpu-native/src/track.rs @@ -1,5 +1,5 @@ use crate::{ - hub::{Storage}, + hub::Storage, resource::{BufferUsage, TextureUsage}, BufferId, Epoch, @@ -7,7 +7,7 @@ use crate::{ RefCount, TextureId, TextureViewId, - TypedId + TypedId, }; use bitflags::bitflags; @@ -240,7 +240,7 @@ impl + PartialEq> Tracker Stitch::Init => new.init, Stitch::Last => new.last, }; - Some((I::new(index, new.epoch), old..state)) + Some((I::new(index, new.epoch), old .. state)) } } }) @@ -261,7 +261,7 @@ impl + PartialEq> Tracker let extended = old | new.last; if extended.is_exclusive() { let id = I::new(index, new.epoch); - return Err((id, old..new.last)); + return Err((id, old .. new.last)); } e.get_mut().last = extended; } diff --git a/wgpu-remote/src/lib.rs b/wgpu-remote/src/lib.rs index 0fc43a0dd1..662d04cce9 100644 --- a/wgpu-remote/src/lib.rs +++ b/wgpu-remote/src/lib.rs @@ -13,7 +13,6 @@ use std::ptr; mod server; - #[derive(Serialize, Deserialize)] enum InstanceMessage { Create(wgn::InstanceId), @@ -85,9 +84,7 @@ pub extern "C" fn wgpu_initialize() -> Infrastructure { #[no_mangle] pub extern "C" fn wgpu_terminate(factory: *mut ClientFactory) { - let factory = unsafe { - Box::from_raw(factory) - }; + let factory = unsafe { Box::from_raw(factory) }; let _ = factory.channel.send(GlobalMessage::Terminate); } @@ -106,9 +103,7 @@ pub extern "C" fn wgpu_client_create(factory: &ClientFactory) -> *mut Client { #[no_mangle] pub extern "C" fn wgpu_client_destroy(factory: &ClientFactory, client: *mut Client) { - let client = unsafe { - Box::from_raw(client) - }; + let client = unsafe { Box::from_raw(client) }; factory.instance_identities.lock().free(client.instance_id); let msg = GlobalMessage::Instance(InstanceMessage::Destroy(client.instance_id)); client.channel.send(msg).unwrap(); diff --git a/wgpu-remote/src/server.rs b/wgpu-remote/src/server.rs index 96a359a6df..0fbe59efd9 100644 --- a/wgpu-remote/src/server.rs +++ b/wgpu-remote/src/server.rs @@ -3,16 +3,13 @@ use crate::{GlobalMessage, InstanceMessage}; use ipc_channel::ipc::IpcReceiver; use wgn; - pub struct Server { channel: IpcReceiver, } impl Server { pub(crate) fn new(channel: IpcReceiver) -> Self { - Server { - channel, - } + Server { channel } } } @@ -46,12 +43,11 @@ fn process(message: GlobalMessage) -> ControlFlow { ControlFlow::Continue } - #[no_mangle] pub extern "C" fn wgpu_server_process(server: &Server) { while let Ok(message) = server.channel.try_recv() { match process(message) { - ControlFlow::Continue => {}, + ControlFlow::Continue => {} ControlFlow::Terminate => break, } }