gpu/vk_res.rs#
Source: lib/gpu/vk_res.rs
vk_res -- Vulkan resources, bindings and pipelines
device.create_buffer(&BufferDesc) -> Buffer copies to and from it always allowed;
Upload / Readback buffers are mapped for their lifetime: write(off, &[T]) /
read(off, &mut [T]) (non-coherent memory flushed / invalidated by atom)
device.create_texture(&TextureDesc) -> Texture optimal tiling, starts in Layout::
Undefined; its default view covers everything (2D, 2D array, cube, cube array, 3D);
texture.create_view(&ViewDesc) -> TextureView a range of mips and layers
device.create_sampler(&SamplerDesc) -> Sampler
ShaderModule::from_spirv(&device, &[u32]) SPIR-V up to 1.3 (Vulkan 1.1), 1.5
(1.2), 1.6 (1.3); the header and the instruction lengths are checked, the code is the
driver's; entry points and specialization constants are read (shader::reflect)
device.create_bind_group_layout(&[Binding]) descriptor set layout (one descriptor
per binding)
device.create_pipeline_layout(&PipelineLayoutDesc) set g = groups[g]; push constants as one
range for every stage (VK_SHADER_STAGE_ALL)
device.create_bind_group(&BindGroupDesc) a descriptor set from the device's pools
(freed individually); it keeps its resources alive
device.create_bindless(&BindlessDesc) -> Bindless (Voll) one update-after-bind,
partially bound set: binding 0 sampled textures, 1 samplers, 2 storage buffers,
3 storage textures; table.group() binds it, table.layout() goes into pipeline layouts
device.create_compute_pipeline / create_render_pipeline (dynamic rendering: the target
formats are part of the pipeline; viewport and scissor are dynamic); per stage: the
entry point must exist with the stage's model, its pipeline constants become a
VkSpecializationInfo (types and ids checked against the module), a compute workgroup
size (LocalSize, LocalSizeId or the WorkgroupSize built-in, after specialization)
must fit the limits, LocalSizeId needs maintenance4
device.create_timestamps(n) -> Timestamps read_ticks(first, n) / read_ms(first, n)
(Err(NotReady) until every one was written and finished)
Every object holds the device (Arc) and is destroyed through the device's garbage once the
GPU has finished the submissions made before it was dropped (vk_dev.rs).
struct Buffer(Arc<BufInner>)GPU memory for data: vertices, indices, storage, uniforms, indirect arguments
impl Buffer
fn size(&self) -> u64fn usage(&self) -> BufferUsagefn memory(&self) -> MemoryKindfn write<T: Pod>(&self, offset: u64, data: &[T]) -> Result<()>copy data into a mapped buffer (Upload / Readback) at offset; the GPU sees it in the next submission -- do not write what a pending submission still readsfn read<T: Pod>(&self, offset: u64, out: &mut [T]) -> Result<()>copy a mapped buffer's contents at offset into out (wait for the submission that wrote them first)
impl Device
fn create_buffer(&self, desc: &BufferDesc) -> Result<Buffer>struct TextureView(pub(crate) Arc<ViewInner>)a range of a texture's mips and layers as shaders and render passes see it
impl TextureView
fn format(&self) -> Formatfn size(&self) -> (u32, u32)width and height of the view's first mipfn usage(&self) -> TextureUsagewhat its texture may be used forfn same(&self, other: &TextureView) -> boolthe same view (it or a clone of it), not merely one of the same range: a cache's keystruct Texturean image on the GPU: 2D, 2D array, cube (array) or 3D, with mips
impl Texture
fn view(&self) -> &TextureViewthe view of everything (its natural dimension)fn width(&self) -> u32fn height(&self) -> u32fn depth(&self) -> u32fn layers(&self) -> u32fn mips(&self) -> u32fn format(&self) -> Formatfn usage(&self) -> TextureUsagefn create_view(&self, desc: &ViewDesc) -> Result<TextureView>a view of some mips / layers (counts 0: to the end)
impl Device
fn create_texture(&self, desc: &TextureDesc) -> Result<Texture>struct Sampler(pub(crate) Arc<SamplerInner>)how textures are filtered and addressed
impl Device
fn create_sampler(&self, desc: &SamplerDesc) -> Result<Sampler>struct ShaderModule(pub(crate) Arc<ShaderInner>)compiled shader code (SPIR-V)
impl ShaderModule
fn from_spirv(device: &Device, code: &[u32]) -> Result<ShaderModule>a module from SPIR-V words: version up to 1.3 on Vulkan 1.1 devices, 1.5 on 1.2, 1.6 on 1.3 (the magic number and version are checked; the code itself is the driver's)fn entry_points(&self) -> Vec<(u32, &str)>the entry points: (model as SPIR-V numbers it: 0 vertex, 4 fragment, 5 compute, name)fn constants(&self) -> Vec<(u32, shader::reflect::Kind, f64)>the pipeline-overridable constants the module declares: (id, kind, default value)struct BindGroupLayout(pub(crate) Arc<BglInner>)the bindings of one bind group (@group)
impl Device
fn create_bind_group_layout(&self, bindings: &[Binding]) -> Result<BindGroupLayout>struct PipelineLayout(pub(crate) Arc<PlInner>)the bind group layouts and push constants of pipelines
impl Device
fn create_pipeline_layout(&self, desc: &PipelineLayoutDesc) -> Result<PipelineLayout>struct BindGroup(pub(crate) Arc<BgInner>)resources bound for shaders (a descriptor set)
impl Device
fn create_bind_group(&self, desc: &BindGroupDesc) -> Result<BindGroup>struct Bindlessa large table of textures, samplers and buffers that shaders index (level Voll): binding 0 sampled textures, 1 samplers, 2 storage buffers, 3 storage textures; slots may be changed while command buffers that use the table are pending, as long as those do not use the slot
impl Device
fn create_bindless(&self, desc: &BindlessDesc) -> Result<Bindless>
impl Bindless
fn group(&self) -> &BindGroupthe table as a bind group (CommandEncoder::set_bind_group)fn layout(&self) -> &BindGroupLayoutits layout (PipelineLayoutDesc::groups)fn counts(&self) -> [u32; 4]slots per binding: textures, samplers, buffers, storage texturesfn set_texture(&self, slot: u32, view: &TextureView) -> Result<()>slot of binding 0: a sampled texture (Layout::Sampled when shaders read it)fn set_sampler(&self, slot: u32, s: &Sampler) -> Result<()>slot of binding 1: a samplerfn set_buffer(&self, slot: u32, buf: &Buffer, offset: u64, size: u64) -> Result<()>slot of binding 2: a storage buffer range (size 0: to the end)fn set_storage_texture(&self, slot: u32, view: &TextureView) -> Result<()>slot of binding 3: a storage texture (Layout::General when shaders use it)struct ComputePipeline(pub(crate) Arc<PipeInner>)a compute shader with its layoutstruct RenderPipeline(pub(crate) Arc<PipeInner>)vertex + fragment shaders with their fixed state and target formats
impl Device
fn create_compute_pipeline(&self, desc: &ComputePipelineDesc) -> Result<ComputePipeline>fn create_compute_pipeline_sized(&self, desc: &ComputePipelineDesc, size: u32) -> Result<ComputePipeline>create_compute_pipeline with a required subgroup size (WGSL @subgroup_size, what wgsl::Output::subgroup_size returns): Features::subgroup_size_control, a power of two in Limits::subgroup_min_size ..= subgroup_max_size; size 0: the driver's choicefn create_render_pipeline(&self, desc: &RenderPipelineDesc) -> Result<RenderPipeline>struct Timestamps(pub(crate) Arc<TsInner>)GPU timestamps (CommandEncoder::reset_timestamps / timestamp)
impl Device
fn create_timestamps(&self, count: u32) -> Result<Timestamps>
impl Timestamps
fn count(&self) -> u32fn read_ticks(&self, first: u32, n: u32) -> Result<Vec<u64>>the raw ticks of timestamps first .. first + n (Err(NotReady): not all written and done)fn read_ms(&self, first: u32, n: u32) -> Result<Vec<f64>>timestamps first .. first + n in milliseconds on the GPU's clock, counted from the first timestamp the device read (so f64 keeps every tick: absolute ticks reach 10^18 ns)