From 37afa0d98a969daa19d919dabd10de1484932b6e Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 14 Aug 2019 22:10:57 -0400 Subject: [PATCH] Update API according to the upstream spec Includes changes in texture view creation, enumeration mapping, binding types, and more. --- examples/compute/main.c | 18 +- examples/triangle/main.c | 2 +- ffi/wgpu.h | 161 +++++++------- wgpu-native/src/binding_model.rs | 15 +- wgpu-native/src/command/mod.rs | 3 +- wgpu-native/src/command/render.rs | 10 + wgpu-native/src/command/transfer.rs | 16 +- wgpu-native/src/conv.rs | 316 +++++++++++++--------------- wgpu-native/src/device.rs | 102 +++++---- wgpu-native/src/instance.rs | 4 +- wgpu-native/src/lib.rs | 16 +- wgpu-native/src/pipeline.rs | 44 ++++ wgpu-native/src/resource.rs | 147 +++++++------ 13 files changed, 468 insertions(+), 386 deletions(-) diff --git a/examples/compute/main.c b/examples/compute/main.c index 09740c47b..d821b11ac 100644 --- a/examples/compute/main.c +++ b/examples/compute/main.c @@ -12,7 +12,7 @@ #define BIND_GROUP_LAYOUTS_LENGTH (1) int main( - int argc, + int argc, char *argv[]) { if (argc != 5) { @@ -33,7 +33,7 @@ int main( WGPUInstanceId instance = wgpu_create_instance(); - WGPUAdapterId adapter = wgpu_instance_get_adapter(instance, + WGPUAdapterId adapter = wgpu_instance_request_adapter(instance, &(WGPUAdapterDescriptor){ .power_preference = WGPUPowerPreference_LowPower, }); @@ -47,13 +47,13 @@ int main( WGPUBufferId staging_buffer = wgpu_device_create_buffer_mapped(device, &(WGPUBufferDescriptor){ - .size = size, + .size = size, .usage = WGPUBufferUsage_MAP_READ}, &staging_memory); memcpy((uint32_t *) staging_memory, numbers, size); - - wgpu_buffer_unmap(staging_buffer); + + wgpu_buffer_unmap(staging_buffer); WGPUBufferId storage_buffer = wgpu_device_create_buffer(device, &(WGPUBufferDescriptor){ @@ -72,14 +72,14 @@ int main( WGPUBindingResource resource = { .tag = WGPUBindingResource_Buffer, .buffer = (WGPUBufferBinding){ - .buffer = storage_buffer, - .size = size, + .buffer = storage_buffer, + .size = size, .offset = 0}}; WGPUBindGroupId bind_group = wgpu_device_create_bind_group(device, &(WGPUBindGroupDescriptor){.layout = bind_group_layout, .bindings = &(WGPUBindGroupBinding){ - .binding = 0, + .binding = 0, .resource = resource}, .bindings_length = BINDINGS_LENGTH}); @@ -135,4 +135,4 @@ int main( wgpu_device_poll(device, true); return 0; -} \ No newline at end of file +} diff --git a/examples/triangle/main.c b/examples/triangle/main.c index 8540922d6..28036e1b3 100644 --- a/examples/triangle/main.c +++ b/examples/triangle/main.c @@ -35,7 +35,7 @@ int main() { WGPUInstanceId instance = wgpu_create_instance(); - WGPUAdapterId adapter = wgpu_instance_get_adapter(instance, + WGPUAdapterId adapter = wgpu_instance_request_adapter(instance, &(WGPUAdapterDescriptor){ .power_preference = WGPUPowerPreference_LowPower, }); diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 37c871efa..802430b72 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -23,12 +23,11 @@ typedef enum { typedef enum { WGPUBindingType_UniformBuffer = 0, - WGPUBindingType_Sampler = 1, - WGPUBindingType_SampledTexture = 2, - WGPUBindingType_StorageBuffer = 3, - WGPUBindingType_UniformBufferDynamic = 4, - WGPUBindingType_StorageBufferDynamic = 5, - WGPUBindingType_StorageTexture = 10, + WGPUBindingType_StorageBuffer = 1, + WGPUBindingType_ReadonlyStorageBuffer = 2, + WGPUBindingType_Sampler = 3, + WGPUBindingType_SampledTexture = 4, + WGPUBindingType_StorageTexture = 5, } WGPUBindingType; typedef enum { @@ -135,9 +134,16 @@ typedef enum { } WGPUStencilOperation; typedef enum { - WGPUStoreOp_Store = 0, + WGPUStoreOp_Clear = 0, + WGPUStoreOp_Store = 1, } WGPUStoreOp; +typedef enum { + WGPUTextureAspect_All, + WGPUTextureAspect_StencilOnly, + WGPUTextureAspect_DepthOnly, +} WGPUTextureAspect; + typedef enum { WGPUTextureDimension_D1, WGPUTextureDimension_D2, @@ -146,53 +152,49 @@ typedef enum { typedef enum { WGPUTextureFormat_R8Unorm = 0, - WGPUTextureFormat_R8UnormSrgb = 1, - WGPUTextureFormat_R8Snorm = 2, - WGPUTextureFormat_R8Uint = 3, - WGPUTextureFormat_R8Sint = 4, - WGPUTextureFormat_R16Unorm = 5, - WGPUTextureFormat_R16Snorm = 6, - WGPUTextureFormat_R16Uint = 7, - WGPUTextureFormat_R16Sint = 8, - WGPUTextureFormat_R16Float = 9, - WGPUTextureFormat_Rg8Unorm = 10, - WGPUTextureFormat_Rg8UnormSrgb = 11, - WGPUTextureFormat_Rg8Snorm = 12, - WGPUTextureFormat_Rg8Uint = 13, - WGPUTextureFormat_Rg8Sint = 14, - WGPUTextureFormat_B5g6r5Unorm = 15, - WGPUTextureFormat_R32Uint = 16, - WGPUTextureFormat_R32Sint = 17, - WGPUTextureFormat_R32Float = 18, - WGPUTextureFormat_Rg16Unorm = 19, - WGPUTextureFormat_Rg16Snorm = 20, - WGPUTextureFormat_Rg16Uint = 21, - WGPUTextureFormat_Rg16Sint = 22, - WGPUTextureFormat_Rg16Float = 23, - WGPUTextureFormat_Rgba8Unorm = 24, - WGPUTextureFormat_Rgba8UnormSrgb = 25, - WGPUTextureFormat_Rgba8Snorm = 26, - WGPUTextureFormat_Rgba8Uint = 27, - WGPUTextureFormat_Rgba8Sint = 28, - WGPUTextureFormat_Bgra8Unorm = 29, - WGPUTextureFormat_Bgra8UnormSrgb = 30, - WGPUTextureFormat_Rgb10a2Unorm = 31, - WGPUTextureFormat_Rg11b10Float = 32, - WGPUTextureFormat_Rg32Uint = 33, - WGPUTextureFormat_Rg32Sint = 34, - WGPUTextureFormat_Rg32Float = 35, - WGPUTextureFormat_Rgba16Unorm = 36, - WGPUTextureFormat_Rgba16Snorm = 37, - WGPUTextureFormat_Rgba16Uint = 38, - WGPUTextureFormat_Rgba16Sint = 39, - WGPUTextureFormat_Rgba16Float = 40, - WGPUTextureFormat_Rgba32Uint = 41, - WGPUTextureFormat_Rgba32Sint = 42, - WGPUTextureFormat_Rgba32Float = 43, - WGPUTextureFormat_D16Unorm = 44, - WGPUTextureFormat_D32Float = 45, - WGPUTextureFormat_D24UnormS8Uint = 46, - WGPUTextureFormat_D32FloatS8Uint = 47, + WGPUTextureFormat_R8Snorm = 1, + WGPUTextureFormat_R8Uint = 2, + WGPUTextureFormat_R8Sint = 3, + WGPUTextureFormat_R16Unorm = 4, + WGPUTextureFormat_R16Snorm = 5, + WGPUTextureFormat_R16Uint = 6, + WGPUTextureFormat_R16Sint = 7, + WGPUTextureFormat_R16Float = 8, + WGPUTextureFormat_Rg8Unorm = 9, + WGPUTextureFormat_Rg8Snorm = 10, + WGPUTextureFormat_Rg8Uint = 11, + WGPUTextureFormat_Rg8Sint = 12, + WGPUTextureFormat_R32Uint = 13, + WGPUTextureFormat_R32Sint = 14, + WGPUTextureFormat_R32Float = 15, + WGPUTextureFormat_Rg16Unorm = 16, + WGPUTextureFormat_Rg16Snorm = 17, + WGPUTextureFormat_Rg16Uint = 18, + WGPUTextureFormat_Rg16Sint = 19, + WGPUTextureFormat_Rg16Float = 20, + WGPUTextureFormat_Rgba8Unorm = 21, + WGPUTextureFormat_Rgba8UnormSrgb = 22, + WGPUTextureFormat_Rgba8Snorm = 23, + WGPUTextureFormat_Rgba8Uint = 24, + WGPUTextureFormat_Rgba8Sint = 25, + WGPUTextureFormat_Bgra8Unorm = 26, + WGPUTextureFormat_Bgra8UnormSrgb = 27, + WGPUTextureFormat_Rgb10a2Unorm = 28, + WGPUTextureFormat_Rg11b10Float = 29, + WGPUTextureFormat_Rg32Uint = 30, + WGPUTextureFormat_Rg32Sint = 31, + WGPUTextureFormat_Rg32Float = 32, + WGPUTextureFormat_Rgba16Unorm = 33, + WGPUTextureFormat_Rgba16Snorm = 34, + WGPUTextureFormat_Rgba16Uint = 35, + WGPUTextureFormat_Rgba16Sint = 36, + WGPUTextureFormat_Rgba16Float = 37, + WGPUTextureFormat_Rgba32Uint = 38, + WGPUTextureFormat_Rgba32Sint = 39, + WGPUTextureFormat_Rgba32Float = 40, + WGPUTextureFormat_Depth32Float = 41, + WGPUTextureFormat_Depth24Plus = 42, + WGPUTextureFormat_Depth24PlusStencil8 = 43, } WGPUTextureFormat; typedef enum { @@ -313,10 +315,10 @@ typedef WGPUId WGPURenderPassId; typedef WGPUId WGPUTextureViewId; typedef struct { - float r; - float g; - float b; - float a; + double r; + double g; + double b; + double a; } WGPUColor; #define WGPUColor_TRANSPARENT (WGPUColor){ .r = 0, .g = 0, .b = 0, .a = 0 } #define WGPUColor_BLACK (WGPUColor){ .r = 0, .g = 0, .b = 0, .a = 1 } @@ -413,6 +415,9 @@ typedef struct { uint32_t binding; WGPUShaderStage visibility; WGPUBindingType ty; + WGPUTextureViewDimension texture_dimension; + bool multisampled; + bool dynamic; } WGPUBindGroupLayoutBinding; typedef struct { @@ -423,13 +428,14 @@ typedef struct { 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_COPY_SRC 4 +#define WGPUBufferUsage_COPY_DST 8 #define WGPUBufferUsage_INDEX 16 #define WGPUBufferUsage_VERTEX 32 #define WGPUBufferUsage_UNIFORM 64 #define WGPUBufferUsage_STORAGE 128 -#define WGPUBufferUsage_INDIRECT 256 +#define WGPUBufferUsage_STORAGE_READ 256 +#define WGPUBufferUsage_INDIRECT 512 #define WGPUBufferUsage_NONE 0 typedef struct { @@ -540,6 +546,8 @@ typedef struct { const WGPUDepthStencilStateDescriptor *depth_stencil_state; WGPUVertexInputDescriptor vertex_input; uint32_t sample_count; + uint32_t sample_mask; + bool alpha_coverage_enabled; } WGPURenderPipelineDescriptor; typedef struct { @@ -568,8 +576,8 @@ typedef WGPUId WGPUSurfaceId; typedef WGPUSurfaceId WGPUSwapChainId; typedef uint32_t WGPUTextureUsage; -#define WGPUTextureUsage_TRANSFER_SRC 1 -#define WGPUTextureUsage_TRANSFER_DST 2 +#define WGPUTextureUsage_COPY_SRC 1 +#define WGPUTextureUsage_COPY_DST 2 #define WGPUTextureUsage_SAMPLED 4 #define WGPUTextureUsage_STORAGE 8 #define WGPUTextureUsage_OUTPUT_ATTACHMENT 16 @@ -600,24 +608,21 @@ typedef struct { WGPUPowerPreference power_preference; } WGPUAdapterDescriptor; +typedef WGPUId WGPURenderBundleId; + typedef struct { WGPUTextureId texture_id; WGPUTextureViewId view_id; } WGPUSwapChainOutput; -typedef uint32_t WGPUTextureAspectFlags; -#define WGPUTextureAspectFlags_COLOR 1 -#define WGPUTextureAspectFlags_DEPTH 2 -#define WGPUTextureAspectFlags_STENCIL 4 - typedef struct { WGPUTextureFormat format; WGPUTextureViewDimension dimension; - WGPUTextureAspectFlags aspect; + WGPUTextureAspect aspect; uint32_t base_mip_level; uint32_t level_count; uint32_t base_array_layer; - uint32_t array_count; + uint32_t array_layer_count; } WGPUTextureViewDescriptor; #if defined(WGPU_LOCAL) @@ -763,6 +768,10 @@ WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextu void wgpu_device_destroy(WGPUDeviceId device_id); +#if defined(WGPU_LOCAL) +void wgpu_device_get_limits(WGPUDeviceId _device_id, WGPULimits *limits); +#endif + WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id); void wgpu_device_poll(WGPUDeviceId device_id, bool force_wait); @@ -785,8 +794,8 @@ WGPUSurfaceId wgpu_instance_create_surface_from_xlib(WGPUInstanceId instance_id, #endif #if defined(WGPU_LOCAL) -WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, - const WGPUAdapterDescriptor *desc); +WGPUAdapterId wgpu_instance_request_adapter(WGPUInstanceId instance_id, + const WGPUAdapterDescriptor *desc); #endif void wgpu_queue_submit(WGPUQueueId queue_id, @@ -816,6 +825,10 @@ void wgpu_render_pass_draw_indirect(WGPURenderPassId pass_id, void wgpu_render_pass_end_pass(WGPURenderPassId pass_id); +void wgpu_render_pass_execute_bundles(WGPURenderPassId _pass_id, + const WGPURenderBundleId *_bundles, + uintptr_t _bundles_length); + void wgpu_render_pass_insert_debug_marker(WGPURenderPassId _pass_id, WGPURawString _label); void wgpu_render_pass_pop_debug_group(WGPURenderPassId _pass_id); @@ -861,10 +874,6 @@ WGPUSwapChainOutput wgpu_swap_chain_get_next_texture(WGPUSwapChainId swap_chain_ void wgpu_swap_chain_present(WGPUSwapChainId swap_chain_id); -#if defined(WGPU_LOCAL) -WGPUTextureViewId wgpu_texture_create_default_view(WGPUTextureId texture_id); -#endif - #if defined(WGPU_LOCAL) WGPUTextureViewId wgpu_texture_create_view(WGPUTextureId texture_id, const WGPUTextureViewDescriptor *desc); diff --git a/wgpu-native/src/binding_model.rs b/wgpu-native/src/binding_model.rs index d50e0277e..190a4e413 100644 --- a/wgpu-native/src/binding_model.rs +++ b/wgpu-native/src/binding_model.rs @@ -1,4 +1,5 @@ use crate::{ + resource::TextureViewDimension, track::TrackerSet, BindGroupLayoutId, BufferAddress, @@ -33,12 +34,11 @@ bitflags! { #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum BindingType { UniformBuffer = 0, - Sampler = 1, - SampledTexture = 2, - StorageBuffer = 3, - UniformBufferDynamic = 4, - StorageBufferDynamic = 5, - StorageTexture = 10, + StorageBuffer = 1, + ReadonlyStorageBuffer = 2, + Sampler = 3, + SampledTexture = 4, + StorageTexture = 5, } #[repr(C)] @@ -47,6 +47,9 @@ pub struct BindGroupLayoutBinding { pub binding: u32, pub visibility: ShaderStage, pub ty: BindingType, + pub texture_dimension: TextureViewDimension, + pub multisampled: bool, + pub dynamic: bool, } #[repr(C)] diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index edc052cb8..86873e91a 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -60,7 +60,8 @@ pub enum LoadOp { #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum StoreOp { - Store = 0, + Clear = 0, + Store = 1, } #[repr(C)] diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 7d1ff78d5..e4f27943a 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -13,6 +13,7 @@ use crate::{ CommandBuffer, CommandBufferId, RawString, + RenderBundleId, RenderPassId, RenderPipelineId, Stored, @@ -637,3 +638,12 @@ pub extern "C" fn wgpu_render_pass_set_scissor_rect( ); } } + +#[no_mangle] +pub extern "C" fn wgpu_render_pass_execute_bundles( + _pass_id: RenderPassId, + _bundles: *const RenderBundleId, + _bundles_length: usize, +) { + unimplemented!() +} diff --git a/wgpu-native/src/command/transfer.rs b/wgpu-native/src/command/transfer.rs index 08a6d68fe..41c4c0d3f 100644 --- a/wgpu-native/src/command/transfer.rs +++ b/wgpu-native/src/command/transfer.rs @@ -84,7 +84,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( let (src_buffer, src_pending) = cmb .trackers .buffers - .use_replace(&*buffer_guard, src, (), BufferUsage::TRANSFER_SRC); + .use_replace(&*buffer_guard, src, (), BufferUsage::COPY_SRC); barriers.extend(src_pending.map(|pending| hal::memory::Barrier::Buffer { states: pending.to_states(), target: &src_buffer.raw, @@ -95,7 +95,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer( let (dst_buffer, dst_pending) = cmb .trackers .buffers - .use_replace(&*buffer_guard, dst, (), BufferUsage::TRANSFER_DST); + .use_replace(&*buffer_guard, dst, (), BufferUsage::COPY_DST); barriers.extend(dst_pending.map(|pending| hal::memory::Barrier::Buffer { states: pending.to_states(), target: &dst_buffer.raw, @@ -136,7 +136,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( let (src_buffer, src_pending) = cmb .trackers .buffers - .use_replace(&*buffer_guard, source.buffer, (), BufferUsage::TRANSFER_SRC); + .use_replace(&*buffer_guard, source.buffer, (), BufferUsage::COPY_SRC); let src_barriers = src_pending.map(|pending| hal::memory::Barrier::Buffer { states: pending.to_states(), target: &src_buffer.raw, @@ -148,7 +148,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_texture( &*texture_guard, destination.texture, destination.to_selector(aspects), - TextureUsage::TRANSFER_DST, + TextureUsage::COPY_DST, ); let dst_barriers = dst_pending.map(|pending| hal::memory::Barrier::Image { states: pending.to_states(), @@ -215,7 +215,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( &*texture_guard, source.texture, source.to_selector(aspects), - TextureUsage::TRANSFER_SRC, + TextureUsage::COPY_SRC, ); let src_barriers = src_pending.map(|pending| hal::memory::Barrier::Image { states: pending.to_states(), @@ -233,7 +233,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_buffer( &*buffer_guard, destination.buffer, (), - BufferUsage::TRANSFER_DST, + BufferUsage::COPY_DST, ); let dst_barrier = dst_barriers.map(|pending| hal::memory::Barrier::Buffer { states: pending.to_states(), @@ -296,7 +296,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( &*texture_guard, source.texture, source.to_selector(aspects), - TextureUsage::TRANSFER_SRC, + TextureUsage::COPY_SRC, ); barriers.extend(src_pending.map(|pending| hal::memory::Barrier::Image { states: pending.to_states(), @@ -309,7 +309,7 @@ pub extern "C" fn wgpu_command_buffer_copy_texture_to_texture( &*texture_guard, destination.texture, destination.to_selector(aspects), - TextureUsage::TRANSFER_DST, + TextureUsage::COPY_DST, ); barriers.extend(dst_pending.map(|pending| hal::memory::Barrier::Image { states: pending.to_states(), diff --git a/wgpu-native/src/conv.rs b/wgpu-native/src/conv.rs index b73c7f9e3..1669c46c5 100644 --- a/wgpu-native/src/conv.rs +++ b/wgpu-native/src/conv.rs @@ -16,10 +16,10 @@ pub fn map_buffer_usage( } let mut hal_usage = U::empty(); - if usage.contains(W::TRANSFER_SRC) { + if usage.contains(W::COPY_SRC) { hal_usage |= U::TRANSFER_SRC; } - if usage.contains(W::TRANSFER_DST) { + if usage.contains(W::COPY_DST) { hal_usage |= U::TRANSFER_DST; } if usage.contains(W::INDEX) { @@ -49,10 +49,10 @@ pub fn map_texture_usage( use hal::image::Usage as U; let mut value = U::empty(); - if usage.contains(W::TRANSFER_SRC) { + if usage.contains(W::COPY_SRC) { value |= U::TRANSFER_SRC; } - if usage.contains(W::TRANSFER_DST) { + if usage.contains(W::COPY_DST) { value |= U::TRANSFER_DST; } if usage.contains(W::SAMPLED) { @@ -73,17 +73,24 @@ pub fn map_texture_usage( value } -pub fn map_binding_type(binding_ty: binding_model::BindingType) -> hal::pso::DescriptorType { - use crate::binding_model::BindingType::*; +pub fn map_binding_type(binding: &binding_model::BindGroupLayoutBinding) -> hal::pso::DescriptorType { + use crate::binding_model::BindingType as Bt; use hal::pso::DescriptorType as H; - match binding_ty { - UniformBuffer => H::UniformBuffer, - Sampler => H::Sampler, - SampledTexture => H::SampledImage, - StorageTexture => H::StorageImage, - StorageBuffer => H::StorageBuffer, - UniformBufferDynamic => H::UniformBufferDynamic, - StorageBufferDynamic => H::StorageBufferDynamic, + match binding.ty { + Bt::UniformBuffer => if binding.dynamic { + H::UniformBufferDynamic + } else { + H::UniformBuffer + }, + Bt::StorageBuffer | + Bt::ReadonlyStorageBuffer => if binding.dynamic { + H::StorageBufferDynamic + } else { + H::StorageBuffer + }, + Bt::Sampler => H::Sampler, + Bt::SampledTexture => H::SampledImage, + Bt::StorageTexture => H::StorageImage, } } @@ -123,14 +130,14 @@ pub fn map_extent(extent: Extent3d) -> hal::image::Extent { } pub fn map_primitive_topology(primitive_topology: pipeline::PrimitiveTopology) -> hal::Primitive { - use crate::pipeline::PrimitiveTopology::*; + use crate::pipeline::PrimitiveTopology as Pt; use hal::Primitive as H; match primitive_topology { - PointList => H::PointList, - LineList => H::LineList, - LineStrip => H::LineStrip, - TriangleList => H::TriangleList, - TriangleStrip => H::TriangleStrip, + Pt::PointList => H::PointList, + Pt::LineList => H::LineList, + Pt::LineStrip => H::LineStrip, + Pt::TriangleList => H::TriangleList, + Pt::TriangleStrip => H::TriangleStrip, } } @@ -175,43 +182,43 @@ fn map_color_write_flags(flags: pipeline::ColorWrite) -> hal::pso::ColorMask { } fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::BlendOp { - use crate::pipeline::BlendOperation::*; + use crate::pipeline::BlendOperation as Bo; use hal::pso::BlendOp as H; match blend_desc.operation { - Add => H::Add { + Bo::Add => H::Add { src: map_blend_factor(blend_desc.src_factor), dst: map_blend_factor(blend_desc.dst_factor), }, - Subtract => H::Sub { + Bo::Subtract => H::Sub { src: map_blend_factor(blend_desc.src_factor), dst: map_blend_factor(blend_desc.dst_factor), }, - ReverseSubtract => H::RevSub { + Bo::ReverseSubtract => H::RevSub { src: map_blend_factor(blend_desc.src_factor), dst: map_blend_factor(blend_desc.dst_factor), }, - Min => H::Min, - Max => H::Max, + Bo::Min => H::Min, + Bo::Max => H::Max, } } fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor { - use crate::pipeline::BlendFactor::*; + use crate::pipeline::BlendFactor as Bf; use hal::pso::Factor as H; match blend_factor { - Zero => H::Zero, - One => H::One, - SrcColor => H::SrcColor, - OneMinusSrcColor => H::OneMinusSrcColor, - SrcAlpha => H::SrcAlpha, - OneMinusSrcAlpha => H::OneMinusSrcAlpha, - DstColor => H::DstColor, - OneMinusDstColor => H::OneMinusDstColor, - DstAlpha => H::DstAlpha, - OneMinusDstAlpha => H::OneMinusDstAlpha, - SrcAlphaSaturated => H::SrcAlphaSaturate, - BlendColor => H::ConstColor, - OneMinusBlendColor => H::OneMinusConstColor, + Bf::Zero => H::Zero, + Bf::One => H::One, + Bf::SrcColor => H::SrcColor, + Bf::OneMinusSrcColor => H::OneMinusSrcColor, + Bf::SrcAlpha => H::SrcAlpha, + Bf::OneMinusSrcAlpha => H::OneMinusSrcAlpha, + Bf::DstColor => H::DstColor, + Bf::OneMinusDstColor => H::OneMinusDstColor, + Bf::DstAlpha => H::DstAlpha, + Bf::OneMinusDstAlpha => H::OneMinusDstAlpha, + Bf::SrcAlphaSaturated => H::SrcAlphaSaturate, + Bf::BlendColor => H::ConstColor, + Bf::OneMinusBlendColor => H::OneMinusConstColor, } } @@ -274,140 +281,134 @@ fn map_stencil_face( } pub fn map_compare_function(compare_function: resource::CompareFunction) -> hal::pso::Comparison { - use crate::resource::CompareFunction::*; + use crate::resource::CompareFunction as Cf; use hal::pso::Comparison as H; match compare_function { - Never => H::Never, - Less => H::Less, - Equal => H::Equal, - LessEqual => H::LessEqual, - Greater => H::Greater, - NotEqual => H::NotEqual, - GreaterEqual => H::GreaterEqual, - Always => H::Always, + Cf::Never => H::Never, + Cf::Less => H::Less, + Cf::Equal => H::Equal, + Cf::LessEqual => H::LessEqual, + Cf::Greater => H::Greater, + Cf::NotEqual => H::NotEqual, + Cf::GreaterEqual => H::GreaterEqual, + Cf::Always => H::Always, } } fn map_stencil_operation(stencil_operation: pipeline::StencilOperation) -> hal::pso::StencilOp { - use crate::pipeline::StencilOperation::*; + use crate::pipeline::StencilOperation as So; use hal::pso::StencilOp as H; match stencil_operation { - Keep => H::Keep, - Zero => H::Zero, - Replace => H::Replace, - Invert => H::Invert, - IncrementClamp => H::IncrementClamp, - DecrementClamp => H::DecrementClamp, - IncrementWrap => H::IncrementWrap, - DecrementWrap => H::DecrementWrap, + So::Keep => H::Keep, + So::Zero => H::Zero, + So::Replace => H::Replace, + So::Invert => H::Invert, + So::IncrementClamp => H::IncrementClamp, + So::DecrementClamp => H::DecrementClamp, + So::IncrementWrap => H::IncrementWrap, + So::DecrementWrap => H::DecrementWrap, } } pub fn map_texture_format(texture_format: resource::TextureFormat) -> hal::format::Format { - use crate::resource::TextureFormat::*; + use crate::resource::TextureFormat as Tf; use hal::format::Format as H; match texture_format { // Normal 8 bit formats - R8Unorm => H::R8Unorm, - R8UnormSrgb => H::R8Srgb, - R8Snorm => H::R8Snorm, - R8Uint => H::R8Uint, - R8Sint => H::R8Sint, + Tf::R8Unorm => H::R8Unorm, + Tf::R8Snorm => H::R8Snorm, + Tf::R8Uint => H::R8Uint, + Tf::R8Sint => H::R8Sint, // Normal 16 bit formats - R16Unorm => H::R16Unorm, - R16Snorm => H::R16Snorm, - R16Uint => H::R16Uint, - R16Sint => H::R16Sint, - R16Float => H::R16Sfloat, + Tf::R16Unorm => H::R16Unorm, + Tf::R16Snorm => H::R16Snorm, + Tf::R16Uint => H::R16Uint, + Tf::R16Sint => H::R16Sint, + Tf::R16Float => H::R16Sfloat, - Rg8Unorm => H::Rg8Unorm, - Rg8UnormSrgb => H::Rg8Srgb, - Rg8Snorm => H::Rg8Snorm, - Rg8Uint => H::Rg8Uint, - Rg8Sint => H::Rg8Sint, - - // Packed 16 bit formats - B5g6r5Unorm => H::B5g6r5Unorm, + Tf::Rg8Unorm => H::Rg8Unorm, + Tf::Rg8Snorm => H::Rg8Snorm, + Tf::Rg8Uint => H::Rg8Uint, + Tf::Rg8Sint => H::Rg8Sint, // Normal 32 bit formats - R32Uint => H::R32Uint, - R32Sint => H::R32Sint, - R32Float => H::R32Sfloat, - Rg16Unorm => H::Rg16Unorm, - Rg16Snorm => H::Rg16Snorm, - Rg16Uint => H::Rg16Uint, - Rg16Sint => H::Rg16Sint, - Rg16Float => H::Rg16Sfloat, - Rgba8Unorm => H::Rgba8Unorm, - Rgba8UnormSrgb => H::Rgba8Srgb, - Rgba8Snorm => H::Rgba8Snorm, - Rgba8Uint => H::Rgba8Uint, - Rgba8Sint => H::Rgba8Sint, - Bgra8Unorm => H::Bgra8Unorm, - Bgra8UnormSrgb => H::Bgra8Srgb, + Tf::R32Uint => H::R32Uint, + Tf::R32Sint => H::R32Sint, + Tf::R32Float => H::R32Sfloat, + Tf::Rg16Unorm => H::Rg16Unorm, + Tf::Rg16Snorm => H::Rg16Snorm, + Tf::Rg16Uint => H::Rg16Uint, + Tf::Rg16Sint => H::Rg16Sint, + Tf::Rg16Float => H::Rg16Sfloat, + Tf::Rgba8Unorm => H::Rgba8Unorm, + Tf::Rgba8UnormSrgb => H::Rgba8Srgb, + Tf::Rgba8Snorm => H::Rgba8Snorm, + Tf::Rgba8Uint => H::Rgba8Uint, + Tf::Rgba8Sint => H::Rgba8Sint, + Tf::Bgra8Unorm => H::Bgra8Unorm, + Tf::Bgra8UnormSrgb => H::Bgra8Srgb, // Packed 32 bit formats - Rgb10a2Unorm => H::A2r10g10b10Unorm, - Rg11b10Float => H::B10g11r11Ufloat, + Tf::Rgb10a2Unorm => H::A2r10g10b10Unorm, + Tf::Rg11b10Float => H::B10g11r11Ufloat, // Normal 64 bit formats - Rg32Uint => H::Rg32Uint, - Rg32Sint => H::Rg32Sint, - Rg32Float => H::Rg32Sfloat, - Rgba16Unorm => H::Rgba16Unorm, - Rgba16Snorm => H::Rgba16Snorm, - Rgba16Uint => H::Rgba16Uint, - Rgba16Sint => H::Rgba16Sint, - Rgba16Float => H::Rgba16Sfloat, + Tf::Rg32Uint => H::Rg32Uint, + Tf::Rg32Sint => H::Rg32Sint, + Tf::Rg32Float => H::Rg32Sfloat, + Tf::Rgba16Unorm => H::Rgba16Unorm, + Tf::Rgba16Snorm => H::Rgba16Snorm, + Tf::Rgba16Uint => H::Rgba16Uint, + Tf::Rgba16Sint => H::Rgba16Sint, + Tf::Rgba16Float => H::Rgba16Sfloat, // Normal 128 bit formats - Rgba32Uint => H::Rgba32Uint, - Rgba32Sint => H::Rgba32Sint, - Rgba32Float => H::Rgba32Sfloat, + Tf::Rgba32Uint => H::Rgba32Uint, + Tf::Rgba32Sint => H::Rgba32Sint, + Tf::Rgba32Float => H::Rgba32Sfloat, // Depth and stencil formats - D16Unorm => H::D16Unorm, - D32Float => H::D32Sfloat, - D24UnormS8Uint => H::D24UnormS8Uint, - D32FloatS8Uint => H::D32SfloatS8Uint, + Tf::Depth32Float => H::D32Sfloat, + Tf::Depth24Plus => H::D24UnormS8Uint, //TODO: substitute + Tf::Depth24PlusStencil8 => H::D24UnormS8Uint, //TODO: substitute } } pub fn map_vertex_format(vertex_format: pipeline::VertexFormat) -> hal::format::Format { - use crate::pipeline::VertexFormat::*; + use crate::pipeline::VertexFormat as Vf; use hal::format::Format as H; match vertex_format { - Uchar2 => H::Rg8Uint, - Uchar4 => H::Rgba8Uint, - Char2 => H::Rg8Sint, - Char4 => H::Rgba8Sint, - Uchar2Norm => H::Rg8Unorm, - Uchar4Norm => H::Rgba8Unorm, - Char2Norm => H::Rg8Snorm, - Char4Norm => H::Rgba8Snorm, - Ushort2 => H::Rg16Uint, - Ushort4 => H::Rgba16Uint, - Short2 => H::Rg16Sint, - Short4 => H::Rgba16Sint, - Ushort2Norm => H::Rg16Unorm, - Ushort4Norm => H::Rgba16Unorm, - Short2Norm => H::Rg16Snorm, - Short4Norm => H::Rgba16Snorm, - Half2 => H::Rg16Sfloat, - Half4 => H::Rgba16Sfloat, - Float => H::R32Sfloat, - Float2 => H::Rg32Sfloat, - Float3 => H::Rgb32Sfloat, - Float4 => H::Rgba32Sfloat, - Uint => H::R32Uint, - Uint2 => H::Rg32Uint, - Uint3 => H::Rgb32Uint, - Uint4 => H::Rgba32Uint, - Int => H::R32Sint, - Int2 => H::Rg32Sint, - Int3 => H::Rgb32Sint, - Int4 => H::Rgba32Sint, + Vf::Uchar2 => H::Rg8Uint, + Vf::Uchar4 => H::Rgba8Uint, + Vf::Char2 => H::Rg8Sint, + Vf::Char4 => H::Rgba8Sint, + Vf::Uchar2Norm => H::Rg8Unorm, + Vf::Uchar4Norm => H::Rgba8Unorm, + Vf::Char2Norm => H::Rg8Snorm, + Vf::Char4Norm => H::Rgba8Snorm, + Vf::Ushort2 => H::Rg16Uint, + Vf::Ushort4 => H::Rgba16Uint, + Vf::Short2 => H::Rg16Sint, + Vf::Short4 => H::Rgba16Sint, + Vf::Ushort2Norm => H::Rg16Unorm, + Vf::Ushort4Norm => H::Rgba16Unorm, + Vf::Short2Norm => H::Rg16Snorm, + Vf::Short4Norm => H::Rgba16Snorm, + Vf::Half2 => H::Rg16Sfloat, + Vf::Half4 => H::Rgba16Sfloat, + Vf::Float => H::R32Sfloat, + Vf::Float2 => H::Rg32Sfloat, + Vf::Float3 => H::Rgb32Sfloat, + Vf::Float4 => H::Rgba32Sfloat, + Vf::Uint => H::R32Uint, + Vf::Uint2 => H::Rg32Uint, + Vf::Uint3 => H::Rgb32Uint, + Vf::Uint4 => H::Rgba32Uint, + Vf::Int => H::R32Sint, + Vf::Int2 => H::Rg32Sint, + Vf::Int3 => H::Rgb32Sint, + Vf::Int4 => H::Rgba32Sint, } } @@ -466,33 +467,15 @@ pub fn map_texture_view_dimension( } } -#[cfg(feature = "local")] -pub fn map_texture_aspect_flags(aspect: resource::TextureAspectFlags) -> hal::format::Aspects { - use crate::resource::TextureAspectFlags as Taf; - use hal::format::Aspects; - - let mut flags = Aspects::empty(); - if aspect.contains(Taf::COLOR) { - flags |= Aspects::COLOR; - } - if aspect.contains(Taf::DEPTH) { - flags |= Aspects::DEPTH; - } - if aspect.contains(Taf::STENCIL) { - flags |= Aspects::STENCIL; - } - flags -} - 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(); - if usage.contains(W::TRANSFER_SRC) { + if usage.contains(W::COPY_SRC) { access |= A::TRANSFER_READ; } - if usage.contains(W::TRANSFER_DST) { + if usage.contains(W::COPY_DST) { access |= A::TRANSFER_WRITE; } if usage.contains(W::INDEX) { @@ -521,8 +504,8 @@ pub fn map_texture_state( let is_color = aspects.contains(hal::format::Aspects::COLOR); let layout = match usage { W::UNINITIALIZED => return (A::empty(), L::Undefined), - W::TRANSFER_SRC => L::TransferSrcOptimal, - W::TRANSFER_DST => L::TransferDstOptimal, + W::COPY_SRC => L::TransferSrcOptimal, + W::COPY_DST => L::TransferDstOptimal, W::SAMPLED => L::ShaderReadOnlyOptimal, W::OUTPUT_ATTACHMENT if is_color => L::ColorAttachmentOptimal, W::OUTPUT_ATTACHMENT => L::DepthStencilAttachmentOptimal, //TODO: read-only depth/stencil @@ -530,10 +513,10 @@ pub fn map_texture_state( }; let mut access = A::empty(); - if usage.contains(W::TRANSFER_SRC) { + if usage.contains(W::COPY_SRC) { access |= A::TRANSFER_READ; } - if usage.contains(W::TRANSFER_DST) { + if usage.contains(W::COPY_DST) { access |= A::TRANSFER_WRITE; } if usage.contains(W::SAMPLED) { @@ -564,19 +547,18 @@ pub fn map_load_store_ops( command::LoadOp::Load => hal::pass::AttachmentLoadOp::Load, }, store: match store { + command::StoreOp::Clear => hal::pass::AttachmentStoreOp::DontCare, //TODO! command::StoreOp::Store => hal::pass::AttachmentStoreOp::Store, }, } } pub fn map_color_f32(color: &Color) -> hal::pso::ColorValue { - [color.r, color.g, color.b, color.a] + [color.r as f32, color.g as f32, color.b as f32, color.a as f32] } - pub fn map_color_i32(color: &Color) -> [i32; 4] { [color.r as i32, color.g as i32, color.b as i32, color.a as i32] } - pub fn map_color_u32(color: &Color) -> [u32; 4] { [color.r as u32, color.g as u32, color.b as u32, color.a as u32] } diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 0c7172017..0559fc39d 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -26,6 +26,7 @@ use crate::{ }; #[cfg(feature = "local")] use crate::{ + instance::Limits, BindGroupLayoutId, CommandEncoderId, ComputePipelineId, @@ -581,6 +582,15 @@ impl Device { } } +#[cfg(feature = "local")] +#[no_mangle] +pub extern "C" fn wgpu_device_get_limits( + _device_id: DeviceId, + limits: &mut Limits, +) { + *limits = Limits::default(); // TODO +} + #[derive(Debug)] pub struct ShaderModule { pub(crate) raw: B::ShaderModule, @@ -600,9 +610,9 @@ pub fn device_create_buffer( if !desc.usage.intersects(Bu::MAP_READ | Bu::MAP_WRITE) { Muv::Data - } else if (Bu::MAP_WRITE | Bu::TRANSFER_SRC).contains(desc.usage) { + } else if (Bu::MAP_WRITE | Bu::COPY_SRC).contains(desc.usage) { Muv::Upload - } else if (Bu::MAP_READ | Bu::TRANSFER_DST).contains(desc.usage) { + } else if (Bu::MAP_READ | Bu::COPY_DST).contains(desc.usage) { Muv::Download } else { Muv::Dynamic @@ -883,43 +893,48 @@ pub fn device_track_view( #[no_mangle] pub extern "C" fn wgpu_texture_create_view( texture_id: TextureId, - desc: &resource::TextureViewDescriptor, + desc: Option<&resource::TextureViewDescriptor>, ) -> TextureViewId { let mut token = Token::root(); - let view = texture_create_view( - texture_id, - desc.format, - 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, - }, - &mut token, - ); - let ref_count = view.life_guard.ref_count.clone(); - let id = HUB.texture_views.register_local(view, &mut token); - device_track_view(texture_id, id, ref_count, &mut token); - id -} + let (texture_guard, _) = HUB.textures.read(&mut token); + let texture = &texture_guard[texture_id]; -#[cfg(feature = "local")] -#[no_mangle] -pub extern "C" fn wgpu_texture_create_default_view(texture_id: TextureId) -> TextureViewId { - let mut token = Token::root(); - let (format, view_kind, range) = { - let (texture_guard, _) = HUB.textures.read(&mut token); - let texture = &texture_guard[texture_id]; - let view_kind = match texture.kind { - hal::image::Kind::D1(_, 1) => hal::image::ViewKind::D1, - hal::image::Kind::D1(..) => hal::image::ViewKind::D1Array, - hal::image::Kind::D2(_, _, 1, _) => hal::image::ViewKind::D2, - hal::image::Kind::D2(..) => hal::image::ViewKind::D2Array, - hal::image::Kind::D3(..) => hal::image::ViewKind::D3, - }; - (texture.format, view_kind, texture.full_range.clone()) + let (format, view_kind, range) = match desc { + Some(desc) => { + let kind = conv::map_texture_view_dimension(desc.dimension); + let end_level = if desc.level_count == 0 { + texture.full_range.levels.end + } else { + (desc.base_mip_level + desc.level_count) as u8 + }; + let end_layer = if desc.array_layer_count == 0 { + texture.full_range.layers.end + } else { + (desc.base_array_layer + desc.array_layer_count) as u16 + }; + let range = hal::image::SubresourceRange { + aspects: match desc.aspect { + resource::TextureAspect::All => texture.full_range.aspects, + resource::TextureAspect::DepthOnly => hal::format::Aspects::DEPTH, + resource::TextureAspect::StencilOnly => hal::format::Aspects::STENCIL, + }, + levels: desc.base_mip_level as u8 .. end_level, + layers: desc.base_array_layer as u16 .. end_layer, + }; + (desc.format, kind, range) + } + None => { + let kind = match texture.kind { + hal::image::Kind::D1(_, 1) => hal::image::ViewKind::D1, + hal::image::Kind::D1(..) => hal::image::ViewKind::D1Array, + hal::image::Kind::D2(_, _, 1, _) => hal::image::ViewKind::D2, + hal::image::Kind::D2(..) => hal::image::ViewKind::D2Array, + hal::image::Kind::D3(..) => hal::image::ViewKind::D3, + }; + (texture.format, kind, texture.full_range.clone()) + } }; + let view = texture_create_view(texture_id, format, view_kind, range, &mut token); let ref_count = view.life_guard.ref_count.clone(); let id = HUB.texture_views.register_local(view, &mut token); @@ -1011,7 +1026,7 @@ pub fn device_create_bind_group_layout( .iter() .map(|binding| hal::pso::DescriptorSetLayoutBinding { binding: binding.binding, - ty: conv::map_binding_type(binding.ty), + ty: conv::map_binding_type(binding), count: 1, //TODO: consolidate stage_flags: conv::map_shader_stage_flags(binding.visibility), immutable_samplers: false, // TODO @@ -1032,11 +1047,7 @@ pub fn device_create_bind_group_layout( desc_ranges: DescriptorRanges::from_bindings(&raw_bindings), dynamic_count: bindings .iter() - .filter(|b| match b.ty { - binding_model::BindingType::UniformBufferDynamic - | binding_model::BindingType::StorageBufferDynamic => true, - _ => false, - }) + .filter(|b| b.dynamic) .count(), } } @@ -1129,14 +1140,15 @@ pub fn device_create_bind_group( let descriptor = match b.resource { binding_model::BindingResource::Buffer(ref bb) => { let (alignment, usage) = match decl.ty { - binding_model::BindingType::UniformBuffer - | binding_model::BindingType::UniformBufferDynamic => { + binding_model::BindingType::UniformBuffer => { (BIND_BUFFER_ALIGNMENT, resource::BufferUsage::UNIFORM) } - binding_model::BindingType::StorageBuffer - | binding_model::BindingType::StorageBufferDynamic => { + binding_model::BindingType::StorageBuffer => { (BIND_BUFFER_ALIGNMENT, resource::BufferUsage::STORAGE) } + binding_model::BindingType::ReadonlyStorageBuffer => { + (BIND_BUFFER_ALIGNMENT, resource::BufferUsage::STORAGE_READ) + } binding_model::BindingType::Sampler | binding_model::BindingType::SampledTexture | binding_model::BindingType::StorageTexture => { diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index bc9c1b3bd..c6231d689 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -220,7 +220,7 @@ pub fn instance_get_adapter( let (mut integrated_first, mut discrete_first, mut discrete_last, mut alternative) = (None, None, None, None); - + // On Windows > 1803, dx12 enumerate_adapters returns the adapters in order from highest to // lowest performance. Therefore, the first found adapter in each category is selected. // @@ -256,7 +256,7 @@ pub fn instance_get_adapter( #[cfg(feature = "local")] #[no_mangle] -pub extern "C" fn wgpu_instance_get_adapter( +pub extern "C" fn wgpu_instance_request_adapter( instance_id: InstanceId, desc: &AdapterDescriptor, ) -> AdapterId { diff --git a/wgpu-native/src/lib.rs b/wgpu-native/src/lib.rs index 9503d41b0..e48d95f2e 100644 --- a/wgpu-native/src/lib.rs +++ b/wgpu-native/src/lib.rs @@ -116,10 +116,10 @@ struct Stored { #[repr(C)] #[derive(Clone, Copy, Debug)] pub struct Color { - pub r: f32, - pub g: f32, - pub b: f32, - pub a: f32, + pub r: f64, + pub g: f64, + pub b: f64, + pub a: f64, } impl Color { @@ -177,6 +177,12 @@ impl Origin3d { }; } +impl Default for Origin3d { + fn default() -> Self { + Origin3d::ZERO + } +} + #[repr(C)] #[derive(Clone, Copy, Debug)] pub struct Extent3d { @@ -296,6 +302,8 @@ define_id!(CommandBufferId); type CommandBufferHandle = CommandBuffer; pub type CommandEncoderId = CommandBufferId; +define_id!(RenderBundleId); + define_id!(RenderPassId); type RenderPassHandle = RenderPass; diff --git a/wgpu-native/src/pipeline.rs b/wgpu-native/src/pipeline.rs index e9f7029d8..f1a6c51e9 100644 --- a/wgpu-native/src/pipeline.rs +++ b/wgpu-native/src/pipeline.rs @@ -40,6 +40,12 @@ pub enum BlendOperation { Max = 4, } +impl Default for BlendOperation { + fn default() -> Self { + BlendOperation::Add + } +} + bitflags! { #[repr(transparent)] pub struct ColorWrite: u32 { @@ -52,6 +58,12 @@ bitflags! { } } +impl Default for ColorWrite { + fn default() -> Self { + ColorWrite::ALL + } +} + #[repr(C)] #[derive(Clone, Debug, PartialEq)] pub struct BlendDescriptor { @@ -78,6 +90,12 @@ impl BlendDescriptor { } } +impl Default for BlendDescriptor { + fn default() -> Self { + BlendDescriptor::REPLACE + } +} + #[repr(C)] #[derive(Clone, Debug)] pub struct ColorStateDescriptor { @@ -100,6 +118,12 @@ pub enum StencilOperation { DecrementWrap = 7, } +impl Default for StencilOperation { + fn default() -> Self { + StencilOperation::Keep + } +} + #[repr(C)] #[derive(Clone, Debug, PartialEq)] pub struct StencilStateFaceDescriptor { @@ -118,6 +142,12 @@ impl StencilStateFaceDescriptor { }; } +impl Default for StencilStateFaceDescriptor { + fn default() -> Self { + StencilStateFaceDescriptor::IGNORE + } +} + #[repr(C)] #[derive(Clone, Debug)] pub struct DepthStencilStateDescriptor { @@ -253,6 +283,12 @@ pub enum FrontFace { Cw = 1, } +impl Default for FrontFace { + fn default() -> Self { + FrontFace::Ccw + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum CullMode { @@ -261,6 +297,12 @@ pub enum CullMode { Back = 2, } +impl Default for CullMode { + fn default() -> Self { + CullMode::None + } +} + #[repr(C)] #[derive(Clone, Debug)] pub struct RasterizationStateDescriptor { @@ -284,6 +326,8 @@ pub struct RenderPipelineDescriptor { pub depth_stencil_state: *const DepthStencilStateDescriptor, pub vertex_input: VertexInputDescriptor, pub sample_count: u32, + pub sample_mask: u32, + pub alpha_coverage_enabled: bool, } bitflags! { diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index d912adc08..418dc8ac2 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -23,19 +23,21 @@ bitflags! { pub struct BufferUsage: u32 { const MAP_READ = 1; const MAP_WRITE = 2; - const TRANSFER_SRC = 4; - const TRANSFER_DST = 8; + const COPY_SRC = 4; + const COPY_DST = 8; const INDEX = 16; const VERTEX = 32; const UNIFORM = 64; const STORAGE = 128; - const INDIRECT = 256; + const STORAGE_READ = 256; + const INDIRECT = 512; const NONE = 0; /// The combination of all read-only usages. - const READ_ALL = Self::MAP_READ.bits | Self::TRANSFER_SRC.bits | - Self::INDEX.bits | Self::VERTEX.bits | Self::UNIFORM.bits | Self::INDIRECT.bits; + const READ_ALL = Self::MAP_READ.bits | Self::COPY_SRC.bits | + Self::INDEX.bits | Self::VERTEX.bits | Self::UNIFORM.bits | + Self::STORAGE_READ.bits | Self::INDIRECT.bits; /// The combination of all write-only and read-write usages. - const WRITE_ALL = Self::MAP_WRITE.bits | Self::TRANSFER_DST.bits | Self::STORAGE.bits; + const WRITE_ALL = Self::MAP_WRITE.bits | Self::COPY_DST.bits | Self::STORAGE.bits; /// The combination of all usages that the are guaranteed to be be ordered by the hardware. /// If a usage is not ordered, then even if it doesn't change between draw calls, there /// still need to be pipeline barriers inserted for synchronization. @@ -98,83 +100,77 @@ pub enum TextureDimension { pub enum TextureFormat { // Normal 8 bit formats R8Unorm = 0, - R8UnormSrgb = 1, - R8Snorm = 2, - R8Uint = 3, - R8Sint = 4, + R8Snorm = 1, + R8Uint = 2, + R8Sint = 3, // Normal 16 bit formats - R16Unorm = 5, - R16Snorm = 6, - R16Uint = 7, - R16Sint = 8, - R16Float = 9, + R16Unorm = 4, + R16Snorm = 5, + R16Uint = 6, + R16Sint = 7, + R16Float = 8, - Rg8Unorm = 10, - Rg8UnormSrgb = 11, - Rg8Snorm = 12, - Rg8Uint = 13, - Rg8Sint = 14, - - // Packed 16 bit formats - B5g6r5Unorm = 15, + Rg8Unorm = 9, + Rg8Snorm = 10, + Rg8Uint = 11, + Rg8Sint = 12, // Normal 32 bit formats - R32Uint = 16, - R32Sint = 17, - R32Float = 18, - Rg16Unorm = 19, - Rg16Snorm = 20, - Rg16Uint = 21, - Rg16Sint = 22, - Rg16Float = 23, - Rgba8Unorm = 24, - Rgba8UnormSrgb = 25, - Rgba8Snorm = 26, - Rgba8Uint = 27, - Rgba8Sint = 28, - Bgra8Unorm = 29, - Bgra8UnormSrgb = 30, + R32Uint = 13, + R32Sint = 14, + R32Float = 15, + Rg16Unorm = 16, + Rg16Snorm = 17, + Rg16Uint = 18, + Rg16Sint = 19, + Rg16Float = 20, + Rgba8Unorm = 21, + Rgba8UnormSrgb = 22, + Rgba8Snorm = 23, + Rgba8Uint = 24, + Rgba8Sint = 25, + Bgra8Unorm = 26, + Bgra8UnormSrgb = 27, // Packed 32 bit formats - Rgb10a2Unorm = 31, - Rg11b10Float = 32, + Rgb10a2Unorm = 28, + Rg11b10Float = 29, // Normal 64 bit formats - Rg32Uint = 33, - Rg32Sint = 34, - Rg32Float = 35, - Rgba16Unorm = 36, - Rgba16Snorm = 37, - Rgba16Uint = 38, - Rgba16Sint = 39, - Rgba16Float = 40, + Rg32Uint = 30, + Rg32Sint = 31, + Rg32Float = 32, + Rgba16Unorm = 33, + Rgba16Snorm = 34, + Rgba16Uint = 35, + Rgba16Sint = 36, + Rgba16Float = 37, // Normal 128 bit formats - Rgba32Uint = 41, - Rgba32Sint = 42, - Rgba32Float = 43, + Rgba32Uint = 38, + Rgba32Sint = 39, + Rgba32Float = 40, // Depth and stencil formats - D16Unorm = 44, - D32Float = 45, - D24UnormS8Uint = 46, - D32FloatS8Uint = 47, + Depth32Float = 41, + Depth24Plus = 42, + Depth24PlusStencil8 = 43, } bitflags! { #[repr(transparent)] pub struct TextureUsage: u32 { - const TRANSFER_SRC = 1; - const TRANSFER_DST = 2; + const COPY_SRC = 1; + const COPY_DST = 2; const SAMPLED = 4; const STORAGE = 8; const OUTPUT_ATTACHMENT = 16; const NONE = 0; /// The combination of all read-only usages. - const READ_ALL = Self::TRANSFER_SRC.bits | Self::SAMPLED.bits; + const READ_ALL = Self::COPY_SRC.bits | Self::SAMPLED.bits; /// The combination of all write-only and read-write usages. - const WRITE_ALL = Self::TRANSFER_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.bits; + const WRITE_ALL = Self::COPY_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.bits; /// The combination of all usages that the are guaranteed to be be ordered by the hardware. /// If a usage is not ordered, then even if it doesn't change between draw calls, there /// still need to be pipeline barriers inserted for synchronization. @@ -231,12 +227,17 @@ impl Borrow for Texture { } } -bitflags! { - #[repr(transparent)] - pub struct TextureAspectFlags: u32 { - const COLOR = 1; - const DEPTH = 2; - const STENCIL = 4; +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +pub enum TextureAspect { + All, + StencilOnly, + DepthOnly, +} + +impl Default for TextureAspect { + fn default() -> Self { + TextureAspect::All } } @@ -256,11 +257,11 @@ pub enum TextureViewDimension { pub struct TextureViewDescriptor { pub format: TextureFormat, pub dimension: TextureViewDimension, - pub aspect: TextureAspectFlags, + pub aspect: TextureAspect, pub base_mip_level: u32, pub level_count: u32, pub base_array_layer: u32, - pub array_count: u32, + pub array_layer_count: u32, } #[derive(Debug)] @@ -291,6 +292,12 @@ pub enum AddressMode { MirrorRepeat = 2, } +impl Default for AddressMode { + fn default() -> Self { + AddressMode::ClampToEdge + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum FilterMode { @@ -298,6 +305,12 @@ pub enum FilterMode { Linear = 1, } +impl Default for FilterMode { + fn default() -> Self { + FilterMode::Nearest + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum CompareFunction {