mod bind_group_builder;
pub mod blend;
mod device_map;
mod render_pass;
mod render_pipeline_builder;
mod sampler_builder;
mod texture;
pub use self::bind_group_builder::{
Builder as BindGroupBuilder, LayoutBuilder as BindGroupLayoutBuilder,
};
pub use self::device_map::{
ActiveAdapter, AdapterMap, AdapterMapKey, DeviceMap, DeviceMapKey, DeviceQueuePair,
};
pub use self::render_pass::{
Builder as RenderPassBuilder,
ColorAttachmentDescriptorBuilder as RenderPassColorAttachmentDescriptorBuilder,
};
pub use self::render_pipeline_builder::RenderPipelineBuilder;
pub use self::sampler_builder::SamplerBuilder;
pub use self::texture::capturer::{
AwaitWorkerTimeout as TextureCapturerAwaitWorkerTimeout, Capturer as TextureCapturer,
Rgba8ReadMapping, Snapshot as TextureSnapshot,
};
pub use self::texture::image::{
format_from_image_color_type as texture_format_from_image_color_type, BufferImage,
ImageReadMapping,
};
pub use self::texture::reshaper::Reshaper as TextureReshaper;
pub use self::texture::{
descriptor_eq as texture_descriptor_eq, extent_3d_eq,
format_size_bytes as texture_format_size_bytes,
format_to_component_type as texture_format_to_component_type, BufferBytes,
Builder as TextureBuilder, Texture, TextureId, TextureView, TextureViewId, ToTextureView,
};
#[doc(inline)]
pub use wgpu::{
read_spirv, vertex_attr_array, vertex_format_size, Adapter, AdapterInfo, AddressMode, Backend,
BackendBit, BindGroup, BindGroupDescriptor, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, Binding, BindingResource, BindingType, BlendDescriptor, BlendFactor,
BlendOperation, Buffer, BufferAddress, BufferAsyncErr, BufferCopyView, BufferDescriptor,
BufferReadMapping, BufferUsage, BufferWriteMapping, Color, ColorStateDescriptor, ColorWrite,
CommandBuffer, CommandBufferDescriptor, CommandEncoder, CommandEncoderDescriptor,
CompareFunction, ComputePass, ComputePipeline, ComputePipelineDescriptor, CreateBufferMapped,
CullMode, DepthStencilStateDescriptor, Device, DeviceDescriptor, DeviceType, DynamicOffset,
Extensions, Extent3d, FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, LoadOp,
Maintain, Origin3d, PipelineLayout, PipelineLayoutDescriptor, PowerPreference, PresentMode,
PrimitiveTopology, ProgrammableStageDescriptor, Queue, RasterizationStateDescriptor,
RenderPass, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
RenderPassDescriptor, RenderPipeline, RenderPipelineDescriptor, RequestAdapterOptions, Sampler,
SamplerDescriptor, ShaderLocation, ShaderModule, ShaderStage, StencilOperation,
StencilStateFaceDescriptor, StoreOp, Surface, SwapChain, SwapChainDescriptor, SwapChainOutput,
Texture as TextureHandle, TextureAspect, TextureComponentType, TextureCopyView,
TextureDescriptor, TextureDimension, TextureFormat, TextureUsage,
TextureView as TextureViewHandle, TextureViewDescriptor, TextureViewDimension, TimeOut,
VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat, VertexStateDescriptor,
BIND_BUFFER_ALIGNMENT, MAX_BIND_GROUPS,
};
pub fn shader_from_spirv_bytes(device: &wgpu::Device, bytes: &[u8]) -> wgpu::ShaderModule {
let cursor = std::io::Cursor::new(bytes);
let vs_spirv = read_spirv(cursor).expect("failed to read hard-coded SPIRV");
device.create_shader_module(&vs_spirv)
}
pub const DEFAULT_POWER_PREFERENCE: PowerPreference = PowerPreference::HighPerformance;
pub const DEFAULT_BACKENDS: BackendBit = BackendBit::PRIMARY;
pub const DEFAULT_EXTENSIONS: Extensions = Extensions {
anisotropic_filtering: true,
};
pub fn clear_texture(
texture: &TextureViewHandle,
clear_color: Color,
encoder: &mut CommandEncoder,
) {
RenderPassBuilder::new()
.color_attachment(texture, |builder| builder.clear_color(clear_color))
.begin(encoder);
}
pub fn default_device_descriptor() -> DeviceDescriptor {
let extensions = DEFAULT_EXTENSIONS;
let limits = Limits::default();
DeviceDescriptor { extensions, limits }
}
pub fn resolve_texture(
src_texture: &TextureViewHandle,
dst_texture: &TextureViewHandle,
encoder: &mut CommandEncoder,
) {
RenderPassBuilder::new()
.color_attachment(src_texture, |color| {
color
.load_op(LoadOp::Load)
.resolve_target_handle(Some(dst_texture))
})
.begin(encoder);
}
pub fn create_pipeline_layout(
device: &wgpu::Device,
bind_group_layouts: &[&wgpu::BindGroupLayout],
) -> wgpu::PipelineLayout {
let descriptor = wgpu::PipelineLayoutDescriptor { bind_group_layouts };
device.create_pipeline_layout(&descriptor)
}
pub fn sampler_descriptor_clone(sampler: &wgpu::SamplerDescriptor) -> wgpu::SamplerDescriptor {
wgpu::SamplerDescriptor {
address_mode_u: sampler.address_mode_u,
address_mode_v: sampler.address_mode_v,
address_mode_w: sampler.address_mode_w,
mag_filter: sampler.mag_filter,
min_filter: sampler.min_filter,
mipmap_filter: sampler.mipmap_filter,
lod_min_clamp: sampler.lod_min_clamp,
lod_max_clamp: sampler.lod_max_clamp,
compare: sampler.compare,
}
}
pub mod bytes {
pub unsafe fn from_slice<T>(slice: &[T]) -> &[u8]
where
T: Copy + Sized,
{
let len = slice.len() * std::mem::size_of::<T>();
let ptr = slice.as_ptr() as *const u8;
std::slice::from_raw_parts(ptr, len)
}
pub unsafe fn from<T>(t: &T) -> &[u8]
where
T: Copy + Sized,
{
let len = std::mem::size_of::<T>();
let ptr = t as *const T as *const u8;
std::slice::from_raw_parts(ptr, len)
}
}