@@ -905,6 +905,18 @@ pub trait Device: WasmNotSendSync {
905905 /// Creates a new buffer.
906906 ///
907907 /// The initial usage is `wgt::BufferUses::empty()`.
908+ ///
909+ /// `wgpu_hal` may adjust the size in `desc` to a larger value if required
910+ /// by the platform. On success, it returns a tuple of the buffer itself
911+ /// and its actual allocated size. `wgpu-core` is responsible for
912+ /// initializing any portion of the buffer that may be accessed, including
913+ /// any padding added by `create_buffer`.
914+ ///
915+ /// Platform-dependent padding is currently required for uniform buffers on
916+ /// dx12. Support for zero-size vertex and index bindings is also platform
917+ /// dependent, but presently, `wgpu-core` adds padding to the end of all
918+ /// buffers with vertex or index usage, and redirects all zero-size bindings
919+ /// to that padding region, regardless of platform.
908920 unsafe fn create_buffer (
909921 & self ,
910922 desc : & BufferDescriptor ,
@@ -1655,11 +1667,39 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
16551667
16561668 unsafe fn set_render_pipeline ( & mut self , pipeline : & <Self :: A as Api >:: RenderPipeline ) ;
16571669
1670+ /// Register an index buffer binding.
1671+ ///
1672+ /// The binding offset must be 4B-aligned and strictly less than the buffer
1673+ /// size. On some backends, the binding size is ignored. This means that
1674+ /// zero-size bindings must be simulated by binding a region of zeros
1675+ /// spanning from the provided offset to the end of the buffer. See
1676+ /// [`CommandEncoder::set_vertex_buffer`] for more detail.
16581677 unsafe fn set_index_buffer < ' a > (
16591678 & mut self ,
16601679 binding : BufferBinding < ' a , <Self :: A as Api >:: Buffer , wgt:: BufferAddress > ,
16611680 format : wgt:: IndexFormat ,
16621681 ) ;
1682+ /// Register a vertex buffer binding.
1683+ ///
1684+ /// The binding offset must be 4B-aligned and strictly less than the buffer
1685+ /// size. On some backends, the binding size is ignored. This means that
1686+ /// zero-size bindings must be simulated by binding a region of zeros
1687+ /// spanning from the provided offset to the end of the buffer.
1688+ ///
1689+ /// These restrictions arise from Vulkan's `vkCmdBindVertexBuffers` and
1690+ /// `vkCmdBindIndexBuffer`, which:
1691+ ///
1692+ /// 1. Do not support specifying the size of the binding.
1693+ /// 2. Require that the binding offset is strictly less than the buffer size.
1694+ ///
1695+ /// A read at any offset from a zero-size binding is out-of-bounds, and
1696+ /// should return zero. Because the binding size is not respected, this
1697+ /// means there may not be non-zero data between the binding offset and
1698+ /// the end of the buffer.
1699+ ///
1700+ /// Because the binding offset must be strictly less than the buffer size,
1701+ /// supporting zero-size bindings requires zero padding at the end of the
1702+ /// buffer.
16631703 unsafe fn set_vertex_buffer < ' a > (
16641704 & mut self ,
16651705 index : u32 ,
0 commit comments