gpu/web_res.rs#
Source: lib/gpu/web_res.rs
web_res -- WebGPU resources, bindings and pipelines in the browser (through web/gpu.js)
device.create_buffer(&BufferDesc) copies to and from it allowed. Upload: Buffer::write is
queue.writeBuffer (before the next submission, as mapped memory would be there). Readback:
only copies may write it (WebGPU: MAP_READ goes with COPY_DST alone); after a submission that
copied into it the browser maps it, Buffer::read says NotReady until then
device.create_texture, texture.create_view, device.create_sampler as WebGPU's
ShaderModule::from_wgsl(&device, &str) the browser takes the WGSL as it is, its validator is the
only one (lib/wgsl is not in the bundle; scan below reads names, overrides and bindings for
what the API promises). from_spirv: Unsupported
Push constants: WGSL `var<immediate> x: T;` becomes `@group(3) @binding(0) var<uniform> x: T;`
(one block, a uniform layout), group 3 of a pipeline layout with push constants: at most
three groups of its own then. web/gpu.js puts them into a ring behind a dynamic offset.
Pipeline constants: WebGPU's `constants`, the key the id as text; an override without @id (ids from
0x10000: docs/GPU.md "Pipeline-Konstanten") by its name. Unknown or doubled ids are Invalid.
device.create_bind_group_layout(&[Binding]) WebGPU wants more than Binding says (a texture's view
dimension and sample type, a storage texture's format, a sampler's kind). So the layout is made
late: from the first bind group's resources, or from the WGSL of the first pipeline that uses
it, whichever comes first
A browser's errors come later than the call (web_dev.rs); what can be known here is Invalid at once.
struct Buffer(pub(crate) Rc<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<()>data into an Upload buffer at offset: the GPU sees it in the next submission (queue.writeBuffer)fn read<T: Pod>(&self, offset: u64, out: &mut [T]) -> Result<()>a Readback buffer's contents at offset into out: Err(NotReady) until the submission that copied into it has finished and the browser has mapped it
impl Device
fn create_buffer(&self, desc: &BufferDesc) -> Result<Buffer>struct TextureView(pub(crate) Rc<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 for (a swapchain frame's: a colour target)fn 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, d: &ViewDesc) -> Result<TextureView>a view of some mips / layers (counts 0: to the end)
impl Device
fn create_texture(&self, desc: &TextureDesc) -> Result<Texture>fn create_sampler(&self, d: &SamplerDesc) -> Result<Sampler>struct Sampler(pub(crate) Rc<SamplerInner>)how textures are filtered and addressedstruct ShaderModule(pub(crate) Rc<ShaderInner>)shader code: WGSL, as the browser takes it
impl ShaderModule
fn from_spirv(_device: &Device, _code: &[u32]) -> Result<ShaderModule>the browser takes WGSL: ShaderModule::from_wgslfn from_wgsl(device: &Device, source: &str) -> Result<ShaderModule>a module from WGSL source, which the browser compiles and validates (its errors come later: web_dev.rs);var<immediate>becomes the uniform block behind push constantsfn 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) Rc<BglInner>)the bindings of one bind group (@group)struct PipelineLayout(pub(crate) Rc<PlInner>)the bind group layouts and push constants of pipelinesstruct BindGroup(pub(crate) Rc<BgInner>)resources bound for shaders
impl Device
fn create_bind_group_layout(&self, bindings: &[Binding]) -> Result<BindGroupLayout>fn create_pipeline_layout(&self, desc: &PipelineLayoutDesc) -> Result<PipelineLayout>groups: at most BIND_GROUPS_MAX, and with push constants at most 3 (the last is theirs)fn create_bind_group(&self, desc: &BindGroupDesc) -> Result<BindGroup>fn create_bindless(&self, _desc: &BindlessDesc) -> Result<Bindless>(level Voll)struct Bindlessa large table of textures, samplers and buffers (level Voll: never in the browser)
impl Bindless
fn group(&self) -> &BindGroupfn layout(&self) -> &BindGroupLayoutfn counts(&self) -> [u32; 4]fn set_texture(&self, _slot: u32, _view: &TextureView) -> Result<()>fn set_sampler(&self, _slot: u32, _s: &Sampler) -> Result<()>fn set_buffer(&self, _slot: u32, _buf: &Buffer, _offset: u64, _size: u64) -> Result<()>fn set_storage_texture(&self, _slot: u32, _view: &TextureView) -> Result<()>struct ComputePipeline(pub(crate) Rc<PipeInner>)a compute shader with its layoutstruct RenderPipeline(pub(crate) Rc<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>(a required subgroup size: not built in the browser; size 0 is the plain pipeline)fn create_render_pipeline(&self, desc: &RenderPipelineDesc) -> Result<RenderPipeline>fn create_timestamps(&self, _count: u32) -> Result<Timestamps>(not built in the browser: Features::timestamps is false; WebGPU has them only at the start and the end of a pass)struct TimestampsGPU timestamps (not built in the browser)
impl Timestamps
fn count(&self) -> u32fn read_ticks(&self, _first: u32, _n: u32) -> Result<Vec<u64>>fn read_ms(&self, _first: u32, _n: u32) -> Result<Vec<f64>>