DynamicGpuBufferWriter

class DynamicGpuBufferWriter @JvmOverloads constructor(val label: String, val usage: Int, val growPolicy: DynamicGpuBufferWriter.GrowPolicy = GrowPolicy.DEFAULT) : AutoCloseable

Per-frame dynamic com.mojang.blaze3d.buffers.GpuBuffer writer for streaming VBO/IBO uploads.

Follows vanilla's net.minecraft.client.renderer.StagedVertexBuffer pattern: CPU data is written to a properly-flagged GPU buffer via com.mojang.blaze3d.systems.CommandEncoder.writeToBuffer, which performs an immediate DMA copy without mapping. Buffers are recycled via fence when the GPU has finished consuming them.

Unlike net.minecraft.client.renderer.MappableRingBuffer, this class does not use persistent mapping, avoiding the fence issue of wrapping within a single command encoder submit.

Lifecycle

  • upload: acquire/write data (auto-grows buffer as needed)

  • endFrame: fence the current buffer for recycling

Author

MukjepScarlet

Constructors

Link copied to clipboard
constructor(label: String, usage: Int, growPolicy: DynamicGpuBufferWriter.GrowPolicy = GrowPolicy.DEFAULT)

Types

Link copied to clipboard
fun interface GrowPolicy

Properties

Link copied to clipboard
Link copied to clipboard
val usage: Int

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun endFrame()

End the current frame: fence all buffers used by this writer for deferred recycling.

Link copied to clipboard
fun peakBytes(): Int

Peak bytes written in the current frame (for adaptive sizing).

Link copied to clipboard
fun upload(data: ByteBuffer, alignment: Int = 1): GpuBufferSlice

Upload data into the buffer and return a slice.