JFLib

gpu crate root#

  • type Result<T> = core::result::Result<T, GpuError>
/// the most push-constant bytes a pipeline layout may declare (every backend guarantees it)
PUSH_CONSTANTS_MAX: u32 = 128
/// the most bind groups of a pipeline layout
BIND_GROUPS_MAX: u32 = 4
/// the most colour targets of a render pass
COLOR_TARGETS_MAX: usize = 8
  • enum GpuError what went wrong

    • Disabled -- the GPU is switched off (jfgui_GPU=0)
    • NoLoader -- the GPU API is not installed (no vulkan-1.dll or libvulkan.so.1, jfgui_GPU_DLL names a missing file, a Linux program not linked against glibc, a browser without navigator.gpu); never on macOS and iOS, where Metal is part of the system: a Mac without a Metal device gives NoAdapter
    • NoAdapter -- no usable GPU (or jfgui_GPU_ADAPTER matched none)
    • Unsupported(&'static str) -- the adapter or this backend lacks something (a feature, a format, the level)
    • Invalid(&'static str) -- a call the API does not allow (sizes, alignments, states, order)
    • OutOfMemory -- host or device memory exhausted
    • DeviceLost -- the device was lost (driver reset, GPU removed): recreate it
    • SurfaceLost -- the window's surface is gone
    • Timeout -- a wait ran out of time
    • NotReady -- results are not available yet (timestamps not written or not finished)
    • Failed(i32) -- another failure of the GPU API (its code: a VkResult)
  • unsafe trait Pod: Copy + 'static plain data that may be copied to and from GPU memory byte for byte: no padding, no pointers, every bit pattern valid

    Safety#

    Implemented here for the integer and float types and arrays of them.

  • fn bytes_of<T: Pod>(s: &[T]) -> &[u8] the bytes of a slice of plain data

  • enum Level the feature level of a device (Basis < Voll)

    • Basis -- WebGPU / Vulkan 1.1: compute, storage buffers, single indirect draws, texture arrays
    • Voll -- Vulkan 1.3 with bindless descriptors, indirect count, multi-draw, subgroups
  • enum AdapterKind what kind of GPU

    • Discrete
    • Integrated
    • Virtual
    • Cpu
    • Other
  • struct AdapterInfo who an adapter is

    • name: String -- the GPU's name ("NVIDIA GeForce RTX 2070 SUPER")
    • vendor_id: u32
    • device_id: u32
    • vendor: &'static str -- the vendor's name for well-known vendor ids ("NVIDIA", "AMD", "Intel", ..)
    • kind: AdapterKind
    • driver: String -- the driver's name ("NVIDIA") and its information string (the version as the vendor writes it)
    • driver_info: String
    • driver_version: String -- the driver version decoded by the vendor's scheme
    • api_version: (u32, u32, u32) -- the API version the device supports (major, minor, patch)
    • backend: &'static str -- "Vulkan", later "WebGPU" / "Metal"
    • missing: Option<&'static str> -- why the backend cannot use this adapter (None: usable)
  • struct Features what a device can do beyond the Basis level

    • timestamps: bool -- GPU timestamps on the queue (Timestamps)
    • multi_draw_indirect: bool -- draw_indexed_indirect_multi (several draws from one buffer)
    • draw_indirect_first_instance: bool -- a first instance other than 0 in indirect draws
    • draw_indirect_count: bool -- draw_indexed_indirect_count
    • bindless: bool -- Bindless tables (descriptor indexing, update after bind)
    • subgroups: bool -- subgroup operations (basic, vote, ballot, arithmetic, shuffle) in compute shaders
    • subgroups_webgpu: bool -- what WebGPU's subgroups feature needs (lib/wgsl's enable subgroups): the operations of subgroups plus relative shuffles and quad operations, in compute and fragment shaders
    • subgroup_stages: u32 -- the stages with subgroup operations (subgroup_stage::*) and the operations (subgroup_op::*), as the device reports them
    • subgroup_ops: u32
    • subgroup_size_control: bool -- Device::create_compute_pipeline_sized: a required subgroup size (WGSL @subgroup_size; Limits::subgroup_min_size ..= subgroup_max_size)
    • subgroup_extended_types: bool -- subgroup operations on f16 values too
    • draw_parameters: bool -- the base vertex / base instance / draw index builtins
    • shader_f16: bool
    • shader_f64: bool
    • shader_i16: bool
    • shader_i64: bool
    • shader_i8: bool
    • storage_16bit: bool -- 16 / 8 bit values in storage buffers
    • uniform_16bit: bool -- 16-bit values in uniform buffers and push constants too (WGSL f16 there)
    • push_constant_16bit: bool
    • uniform_standard_layout: bool -- uniform buffers in the storage layout (uniformBufferStandardLayout: a WGSL uniform buffer whose layout is not std140, e.g. mat2x2f)
    • demote: bool -- OpDemoteToHelperInvocation (lib/wgsl's discard at the level Voll)
    • clip_distances: bool -- WGSL @builtin(clip_distances), @builtin(primitive_index) (geometryShader), @interpolate(.., sample) / @builtin(sample_index) (sampleRateShading)
    • primitive_index: bool
    • sample_shading: bool
    • storage_8bit: bool
    • texture_bc: bool -- BC1 .. BC7 compressed textures
    • anisotropy: bool
    • depth_clamp: bool
    • vertex_stores: bool -- storage writes in vertex / fragment shaders
    • fragment_stores: bool
    • storage_write_without_format: bool -- storage textures without a format in the shader
    • buffer_address: bool -- shader access to buffers by address
    • swapchain: bool -- presentation to windows (Swapchain)
    • mesh_shader: bool -- present on the adapter, not enabled yet: mesh shaders, ray queries, ray-tracing pipelines
    • ray_query: bool
    • ray_pipeline: bool
  • struct Limits the device's limits

    • max_texture_2d: u32
    • max_texture_3d: u32
    • max_texture_layers: u32
    • max_storage_binding: u32 -- the largest range of a storage / uniform buffer binding (bytes)
    • max_uniform_binding: u32
    • max_push_constants: u32 -- push-constant bytes of the device (the API allows PUSH_CONSTANTS_MAX)
    • max_bind_groups: u32
    • max_compute_workgroup_size: [u32; 3]
    • max_compute_invocations: u32
    • max_compute_workgroups: [u32; 3]
    • max_compute_shared_memory: u32
    • min_uniform_offset_alignment: u32
    • min_storage_offset_alignment: u32
    • max_color_targets: u32
    • max_vertex_buffers: u32
    • max_vertex_attributes: u32
    • max_draw_indirect_count: u32
    • max_anisotropy: f32
    • timestamp_period_ns: f32 -- nanoseconds per timestamp tick
    • subgroup_size: u32 -- threads per subgroup (0: unknown)
    • subgroup_min_size: u32 -- the subgroup sizes shaders can get (without size control: subgroup_size twice)
    • subgroup_max_size: u32
    • max_bindless_textures: u32 -- the most slots of a Bindless table (Voll; 0 on Basis)
    • max_bindless_samplers: u32
    • max_bindless_buffers: u32
    • max_bindless_storage_textures: u32
    • device_memory: u64 -- bytes of the device-local memory heaps
  • struct InstanceDesc<'a> Instance::with

    • app_name: &'a str -- the application's name for the driver
    • validate: bool -- the validation layer (as jfgui_GPU_VALIDATE=1)

impl InstanceDesc<'_>

  • const DEFAULT: InstanceDesc<'static> = InstanceDesc { app_name: "jfgui", validate: false }

  • struct DeviceDesc Adapter::create_device

    • max_level: Level -- the highest level to enable (the device gets the highest it supports up to this one)

impl DeviceDesc

  • const DEFAULT: DeviceDesc = DeviceDesc { max_level: Level::Voll }

  • struct DeviceOptions (G5d) what Adapter::create_device_with sets up beyond DeviceDesc; DEFAULT is what create_device does. Fields may come in later versions: start from DEFAULT

    • compute_queue: bool -- a queue of its own for compute and copies (Device::compute_queue): Vulkan, where the device has a family without graphics. Then every buffer and every texture that is no render target is shared by both queues' families (concurrently), which some GPUs may pay for; off by default, and jfgui_GPU_COMPUTE=0 turns it off

impl DeviceOptions

  • const DEFAULT: DeviceOptions = DeviceOptions { compute_queue: false }

  • const fn with_compute_queue(self) -> DeviceOptions these options with a compute queue asked for

  • struct SubmitId(pub u64) a submission's place on the device timeline (Device::wait)

  • enum MemoryKind where a buffer's memory lives

    • Device -- GPU memory (fastest for the GPU; filled by copies or Queue::write_buffer)
    • Upload -- CPU memory the GPU reads (staging, per-frame data; Buffer::write)
    • Readback -- CPU memory the GPU writes (results; Buffer::read)
  • struct BufferDesc Device::create_buffer

    • size: u64
    • usage: BufferUsage
    • memory: MemoryKind
  • enum Format texel formats

    • R8Unorm
    • Rg8Unorm
    • Rgba8Unorm
    • Rgba8Srgb
    • Bgra8Unorm
    • Bgra8Srgb
    • Rgb10a2Unorm
    • Rg11b10Float
    • R16Float
    • Rg16Float
    • Rgba16Float
    • R32Uint
    • R32Sint
    • R32Float
    • Rg32Uint
    • Rg32Float
    • Rgba32Uint
    • Rgba32Float
    • Depth16
    • Depth32Float
    • Depth24Stencil8
    • Depth32FloatStencil8
    • Bc1Unorm
    • Bc1Srgb
    • Bc3Unorm
    • Bc3Srgb
    • Bc4Unorm
    • Bc5Unorm
    • Bc7Unorm
    • Bc7Srgb

impl Format

  • const fn block_bytes(self) -> u32 bytes per texel block (a texel, or a 4 x 4 block of a compressed format)

  • const fn block_dim(self) -> u32 the block's width and height in texels (4 for compressed formats, else 1)

  • const fn is_compressed(self) -> bool

  • const fn is_depth(self) -> bool

  • const fn has_stencil(self) -> bool

  • const fn is_srgb(self) -> bool

  • struct TextureDesc Device::create_texture: a 2D texture (layers > 1: an array; cube: 6 * n layers) or a 3D one (depth > 1)

    • width: u32
    • height: u32
    • depth: u32 -- 1 for 2D textures
    • layers: u32 -- 1 for a single texture
    • mips: u32 -- mip levels (1 = none)
    • format: Format
    • usage: TextureUsage
    • cube: bool -- cube faces: layers is a multiple of 6

impl TextureDesc

  • const fn d2(width: u32, height: u32, format: Format, usage: TextureUsage) -> TextureDesc a single-level 2D texture

  • enum ViewDim a view's dimension

    • D2
    • D2Array
    • Cube
    • CubeArray
    • D3
  • struct ViewDesc Texture::create_view: a range of mips and layers (counts 0 = to the end)

    • dim: ViewDim
    • base_mip: u32
    • mips: u32
    • base_layer: u32
    • layers: u32
  • enum Layout the state a texture is in (texture_barrier, render pass attachments, write_texture)

    • Undefined -- contents discarded; waits for earlier colour, copy and compute work (and for the swapchain image's acquisition)
    • General -- storage textures and anything at once (slower on some GPUs)
    • CopySrc
    • CopyDst
    • Sampled -- sampled in shaders (also depth textures)
    • ColorTarget
    • DepthTarget
    • DepthRead -- depth test without writes while shaders sample it
    • Present -- handed to the window (the last layout of a swapchain image)
  • enum Filter

    • Nearest
    • Linear
  • enum AddressMode

    • Repeat
    • MirrorRepeat
    • ClampToEdge
  • enum Compare comparison functions (depth test, comparison samplers)

    • Never
    • Less
    • Equal
    • LessEqual
    • Greater
    • NotEqual
    • GreaterEqual
    • Always
  • struct SamplerDesc Device::create_sampler

    • mag: Filter
    • min: Filter
    • mip: Filter
    • address: [AddressMode; 3] -- u, v, w
    • anisotropy: u16 -- 1 = off, up to Limits::max_anisotropy (needs Features::anisotropy)
    • compare: Option<Compare> -- a comparison sampler (shadow maps)
    • lod_min: f32
    • lod_max: f32

impl SamplerDesc

  • const LINEAR: SamplerDesc = SamplerDesc { mag: Filter::Linear, min: Filter::Linear, m ...

  • const NEAREST: SamplerDesc = SamplerDesc { mag: Filter::Nearest, min: Filter::Nearest, ...

  • enum BindingKind what a binding holds

    • UniformBuffer
    • StorageBuffer -- read and written by shaders
    • StorageBufferRead -- read only (also visible to vertex shaders without Features::vertex_stores)
    • Texture -- a sampled texture (Layout::Sampled)
    • StorageTexture -- a storage texture (Layout::General)
    • Sampler
  • struct Binding one binding of a BindGroupLayout

    • binding: u32
    • kind: BindingKind
    • stages: Stages
  • struct PipelineLayoutDesc<'a> Device::create_pipeline_layout

    • groups: &'a [&'a BindGroupLayout] -- bind group g = @group(g); at most BIND_GROUPS_MAX
    • push_constants: u32 -- push-constant bytes (a multiple of 4, at most PUSH_CONSTANTS_MAX)
  • enum Resource<'a> a resource bound into a BindGroup

    • Buffer { buffer: &'a Buffer, offset: u64, size: u64 } -- a buffer range (size 0: to the end); offsets aligned to Limits::min_*_offset_alignment
    • Texture(&'a TextureView)
    • StorageTexture(&'a TextureView)
    • Sampler(&'a Sampler)
  • struct BindEntry<'a>

    • binding: u32
    • resource: Resource<'a>
  • struct BindGroupDesc<'a> Device::create_bind_group: one entry per binding of the layout

    • layout: &'a BindGroupLayout
    • entries: &'a [BindEntry<'a>]
  • struct BindlessDesc Device::create_bindless: the slots of each kind (bindings 0 textures, 1 samplers, 2 storage buffers, 3 storage textures of one group)

    • textures: u32
    • samplers: u32
    • buffers: u32
    • storage_textures: u32
  • struct Constant a pipeline-overridable constant: WGSL @id(id) override, SPIR-V SpecId id. The value is an f64 as in WebGPU's GPUProgrammableStage.constants and is converted to the override's type the way WebGPU converts it: bool true unless 0 or NaN; i32 / u32 (and the other integers) truncated toward 0, Invalid when not finite or out of range; f32 / f16 / f64 rounded to nearest, Invalid when not finite or out of range. An id the module does not declare, or the same id twice, is Invalid (Vulkan would ignore it; WebGPU does not). Overrides the pipeline leaves out keep the module's default.

    • id: u32
    • value: f64
  • struct ShaderStage<'a> a shader entry point and its pipeline constants

    • module: &'a ShaderModule
    • entry: &'a str
    • constants: &'a [Constant] -- pipeline-overridable constants of this stage (empty: the module's defaults)

impl<'a> ShaderStage<'a>

  • const fn new(module: &'a ShaderModule, entry: &'a str) -> ShaderStage<'a> an entry point without pipeline constants

  • struct ComputePipelineDesc<'a> Device::create_compute_pipeline

    • layout: &'a PipelineLayout
    • shader: ShaderStage<'a>
  • enum Topology

    • Points
    • Lines
    • LineStrip
    • Triangles
    • TriangleStrip
  • enum Cull

    • None
    • Front
    • Back
  • enum VertexFormat vertex attribute formats

    • F32
    • F32x2
    • F32x3
    • F32x4
    • U32
    • U32x2
    • U32x4
    • Unorm8x4 -- four bytes as 0 ..= 1
  • struct VertexAttribute

    • location: u32
    • format: VertexFormat
    • offset: u32
  • struct VertexBufferLayout<'a> a vertex buffer slot (empty list: vertex pulling)

    • stride: u32
    • per_instance: bool
    • attributes: &'a [VertexAttribute]
  • enum BlendFactor

    • Zero
    • One
    • Src
    • OneMinusSrc
    • Dst
    • OneMinusDst
    • SrcAlpha
    • OneMinusSrcAlpha
    • DstAlpha
    • OneMinusDstAlpha
  • enum BlendOp

    • Add
    • Subtract
    • ReverseSubtract
    • Min
    • Max
  • struct BlendComponent

    • src: BlendFactor
    • dst: BlendFactor
    • op: BlendOp
  • struct Blend colour and alpha blending of a colour target

    • color: BlendComponent
    • alpha: BlendComponent

impl Blend

  • const PREMULTIPLIED: Blend = Blend { color: BlendComponent { src: BlendFactor::One, ds ... premultiplied alpha: src + dst * (1 - src.a)

  • const ALPHA: Blend = Blend { color: BlendComponent { src: BlendFactor::SrcAlph ... straight alpha: src * src.a + dst * (1 - src.a)

  • const ADD: Blend = Blend { color: BlendComponent { src: BlendFactor::One, ds ... additive: src + dst

  • struct ColorTarget a colour target of a render pipeline

    • format: Format
    • blend: Option<Blend>
    • write_mask: u32 -- bits 0..3 = r, g, b, a (0xF: all)
  • struct DepthState the depth test of a render pipeline

    • format: Format
    • write: bool
    • compare: Compare
  • struct RenderPipelineDesc<'a> Device::create_render_pipeline

    • layout: &'a PipelineLayout
    • vertex: ShaderStage<'a>
    • fragment: Option<ShaderStage<'a>>
    • buffers: &'a [VertexBufferLayout<'a>] -- vertex buffer slots (empty: the vertex shader pulls its data)
    • topology: Topology
    • cull: Cull
    • front_cw: bool -- front faces are clockwise (default counter-clockwise)
    • targets: &'a [ColorTarget]
    • depth: Option<DepthState>
  • enum Load what a render pass does with an attachment's old contents

    • Keep
    • Clear
    • Discard
  • struct ColorAttachment<'a> a colour attachment of a render pass: the view goes from before to ColorTarget at the start and to after at the end

    • view: &'a TextureView
    • load: Load
    • clear: [f32; 4]
    • store: bool
    • before: Layout
    • after: Layout
  • struct DepthAttachment<'a> the depth attachment of a render pass (DepthTarget during the pass)

    • view: &'a TextureView
    • load: Load
    • clear: f32
    • store: bool
    • before: Layout
    • after: Layout
  • struct RenderPassDesc<'d, 'a> CommandEncoder::begin_render (the slice may be a temporary: only the views are borrowed for the encoder's lifetime)

    • color: &'d [ColorAttachment<'a>]
    • depth: Option<DepthAttachment<'a>>
  • enum IndexFormat

    • U16
    • U32
  • struct TextureRegion<'a> a region of one mip of a texture: origin and size in texels (z: 3D textures), layers

    • texture: &'a Texture
    • mip: u32
    • origin: [u32; 3]
    • size: [u32; 3]
    • base_layer: u32
    • layers: u32

impl<'a> TextureRegion<'a>

  • fn mip(texture: &'a Texture, mip: u32) -> TextureRegion<'a> all of mip mip and every layer

  • struct DataLayout the layout of texel data in a buffer or slice: rows of bytes_per_row bytes (0: tightly packed), rows_per_image rows per layer / slice (0: the region's height)

    • offset: u64
    • bytes_per_row: u32
    • rows_per_image: u32
  • enum PresentMode how frames reach the window

    • Fifo -- vsync: one image per refresh, never tears (always available)
    • Mailbox -- the newest image at the refresh, older ones dropped (no tearing, low latency)
    • Immediate -- at once (tears; for measurements)
  • struct SwapchainDesc Device::create_swapchain

    • present: PresentMode
    • srgb: bool -- an sRGB format (the GPU encodes gamma on writes)
    • copy_src: bool -- the images may be copied from (read-back of the presented image)
    • frames_in_flight: u32 -- frames the CPU may record ahead of the GPU (1 ..= 3)
    • min_images: u32 -- images of the swapchain at least (0: the surface's minimum + 1)

impl SwapchainDesc

  • const DEFAULT: SwapchainDesc = SwapchainDesc { present: PresentMode::Fifo, srgb: false, ...

mod subgroup_stage

the bits of Features::subgroup_stages

COMPUTE: u32 = 1
FRAGMENT: u32 = 2
VERTEX: u32 = 4

mod subgroup_op

the bits of Features::subgroup_ops (the Vulkan feature bits)

BASIC: u32 = 1
VOTE: u32 = 2
ARITHMETIC: u32 = 4
BALLOT: u32 = 8
SHUFFLE: u32 = 0x10
SHUFFLE_RELATIVE: u32 = 0x20
CLUSTERED: u32 = 0x40
QUAD: u32 = 0x80

Source: docs/API.md in the JFLib repository.