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;
#[cfg(feature = "capturer")]
pub use self::texture::capturer::{
AwaitWorkerTimeout as TextureCapturerAwaitWorkerTimeout, Capturer as TextureCapturer,
Snapshot as TextureSnapshot,
};
#[cfg(feature = "image")]
pub use self::texture::image::{
format_from_image_color_type as texture_format_from_image_color_type, ImageHolder,
ImageReadMapping, WithDeviceQueuePair,
};
pub use self::texture::reshaper::Reshaper as TextureReshaper;
pub use self::texture::row_padded_buffer::RowPaddedBuffer;
pub use self::texture::{
descriptor_eq as texture_descriptor_eq, extent_3d_eq,
format_size_bytes as texture_format_size_bytes, Builder as TextureBuilder, Texture, TextureId,
TextureView, TextureViewId, ToTextureView,
};
#[doc(inline)]
pub use wgpu_upstream::{
include_wgsl,
util::{self, BufferInitDescriptor},
vertex_attr_array, Adapter, AdapterInfo, AddressMode, Backend, Backends, BindGroup,
BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingResource, BindingType, BlendComponent, BlendFactor,
BlendOperation, BlendState, Buffer, BufferAddress, BufferAsyncError, BufferBinding,
BufferBindingType, BufferDescriptor, BufferSize, BufferSlice, BufferUsages, BufferView,
BufferViewMut, Color, ColorTargetState, ColorWrites, CommandBuffer, CommandBufferDescriptor,
CommandEncoder, CommandEncoderDescriptor, CompareFunction, ComputePass, ComputePassDescriptor,
ComputePipeline, ComputePipelineDescriptor, DepthBiasState, DepthStencilState, Device,
DeviceDescriptor, DeviceType, DownlevelCapabilities, DownlevelFlags, DynamicOffset, Error,
Extent3d, Face, Features, FilterMode, FragmentState, FrontFace, ImageCopyBuffer,
ImageCopyBufferBase, ImageCopyTexture, ImageCopyTextureBase, ImageDataLayout,
ImageSubresourceRange, IndexFormat, Instance, Label, Limits, LoadOp, Maintain, MapMode,
MultisampleState, Operations, Origin3d, PipelineLayout, PipelineLayoutDescriptor,
PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState,
PrimitiveTopology, PushConstantRange, QuerySet, QuerySetDescriptor, QueryType, Queue,
RenderBundle, RenderBundleDepthStencil, RenderBundleDescriptor, RenderBundleEncoder,
RenderBundleEncoderDescriptor, RenderPass, RenderPassColorAttachment,
RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPipeline,
RenderPipelineDescriptor, RequestAdapterOptions, RequestAdapterOptionsBase, RequestDeviceError,
Sampler, SamplerBorderColor, SamplerDescriptor, ShaderLocation, ShaderModel, ShaderModule,
ShaderModuleDescriptor, ShaderSource, ShaderStages, StencilFaceState, StencilOperation,
StencilState, StorageTextureAccess, Surface, SurfaceConfiguration, SurfaceError, SurfaceStatus,
SurfaceTexture, Texture as TextureHandle, TextureAspect, TextureDescriptor, TextureDimension,
TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType,
TextureUsages, TextureView as TextureViewHandle, TextureViewDescriptor, TextureViewDimension,
UncapturedErrorHandler, VertexAttribute, VertexBufferLayout, VertexFormat, VertexState,
VertexStepMode, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT,
PUSH_CONSTANT_ALIGNMENT, QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE,
VERTEX_STRIDE_ALIGNMENT,
};
pub const DEFAULT_POWER_PREFERENCE: PowerPreference = PowerPreference::HighPerformance;
pub const DEFAULT_BACKENDS: Backends = Backends::PRIMARY.union(Backends::GL);
#[cfg(feature = "spirv")]
pub fn shader_from_spirv_bytes(
device: &wgpu_upstream::Device,
bytes: &[u8],
) -> wgpu_upstream::ShaderModule {
let source = util::make_spirv(bytes);
let desc = ShaderModuleDescriptor {
label: Some("nannou_shader_module"),
source,
};
device.create_shader_module(desc)
}
pub fn clear_texture(
texture: &TextureViewHandle,
clear_color: Color,
encoder: &mut CommandEncoder,
) {
RenderPassBuilder::new()
.color_attachment(texture, |builder| {
builder.load_op(LoadOp::Clear(clear_color))
})
.begin(encoder);
}
pub fn default_device_descriptor() -> DeviceDescriptor<'static> {
let features = Features::default();
let limits = Limits::default();
DeviceDescriptor {
label: Some("nannou_device"),
features,
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<'p>(
device: &wgpu_upstream::Device,
label: Option<&'p str>,
bind_group_layouts: &[&wgpu_upstream::BindGroupLayout],
push_constant_ranges: &'p [wgpu_upstream::PushConstantRange],
) -> wgpu_upstream::PipelineLayout {
let descriptor = wgpu_upstream::PipelineLayoutDescriptor {
label,
bind_group_layouts,
push_constant_ranges,
};
device.create_pipeline_layout(&descriptor)
}
pub fn sampler_filtering(desc: &SamplerDescriptor) -> bool {
match (desc.mag_filter, desc.min_filter, desc.mipmap_filter) {
(FilterMode::Nearest, FilterMode::Nearest, FilterMode::Nearest) => false,
_ => true,
}
}
pub fn compute_row_padding(bytes_per_row: u32) -> u32 {
COPY_BYTES_PER_ROW_ALIGNMENT - (bytes_per_row % COPY_BYTES_PER_ROW_ALIGNMENT)
}
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)
}
pub unsafe fn to_slice<T>(slice: &[u8]) -> &[T]
where
T: Copy + Sized,
{
let size = std::mem::size_of::<T>();
let align = std::mem::align_of::<T>();
assert_eq!(slice.len() % size, 0, "incorrect buffer size");
assert_eq!(
slice.as_ptr() as usize % align,
0,
"incorrect buffer alignment"
);
let len = slice.len() / size;
let ptr = slice.as_ptr() as *const T;
std::slice::from_raw_parts(ptr, len)
}
}