GpuDevice

A GPU device. Create one with the GpuDevice factory, claim a window to present into, and close it after releasing every window and GPU resource created from it.

Samples live in the sandbox because they need a display.

Properties

Link copied to clipboard

Name of the backend SDL chose, such as metal, vulkan or direct3d12.

Link copied to clipboard

Shader formats the chosen backend accepts; on every current backend exactly one.

Functions

Link copied to clipboard

Returns a command buffer to record one frame's work into. Every acquired buffer must be submitted with CommandBuffer.submit.

Link copied to clipboard
fun claim(window: Window)

Creates a swapchain for window so this device can present into it.

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun GpuDevice.createBuffer(usage: BufferUsage, sizeInBytes: Int): GpuBuffer

Creates a buffer of sizeInBytes bytes for usage.

Link copied to clipboard

Creates a pipeline drawing triangle lists with vertex and fragment into a single color target of colorFormat, blended with blend. No vertex buffers: vertex data is pulled from storage buffers by vertex index.

Link copied to clipboard
fun GpuDevice.createSampler(filter: SamplerFilter, address: SamplerAddress = SamplerAddress.CLAMP): Sampler

Creates a sampler using filter for both minification and magnification, with texture coordinates outside the texture handled as address says, on both axes of a 2D texture.

Link copied to clipboard

Creates the backend's shader from shader, picking the format this device supports.

fun GpuDevice.createShader(code: ByteArray, format: ShaderFormat, stage: ShaderStage, entryPoint: String, samplers: Int = 0, storageTextures: Int = 0, storageBuffers: Int = 0, uniformBuffers: Int = 0): GpuShader

Creates a shader for stage from code in format. The resource counts must match what the shader declares, or binding at draw time fails. Pass the Int counts by name.

Link copied to clipboard

Creates an RGBA8 texture of the size of image for sampling and uploads its pixels.

fun GpuDevice.createTexture(width: Int, height: Int, format: TextureFormat = TextureFormat.RGBA8, usage: TextureUsage = TextureUsage.SAMPLED): GpuTexture

Creates a 2D texture of width by height texels in format for usage.

Link copied to clipboard

Creates an upload staging buffer of sizeInBytes bytes.

Link copied to clipboard

Maps buffer for writing and returns its memory as floats. Call unmap before uploading.

Link copied to clipboard

Frees buffer. Work already submitted may still read it; SDL defers the actual release.

Frees fence.

Frees shader. Pipelines built from it keep working.

Frees texture. Never call this on a swapchain texture.

Frees pipeline.

fun GpuDevice.release(sampler: Sampler)

Frees sampler.

Frees buffer.

Link copied to clipboard
fun setPresentMode(window: Window, mode: PresentMode)

Changes how frames are presented into a claimed window.

Link copied to clipboard

Returns true if a claimed window can present with mode.

Link copied to clipboard

Returns the pixel format of the swapchain of a claimed window. Pipelines that draw into it must match.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun unclaim(window: Window)

Undoes claim: destroys the swapchain of a window claimed earlier.

Link copied to clipboard

Ends a mapping started with map. The MappedFloats handed out is invalid afterwards.

Link copied to clipboard
fun GpuDevice.uploadToTexture(texture: GpuTexture, image: Image, x: Int, y: Int)

Copies the pixels of image into texture as given, alpha included and nothing blended, with the image's top-left corner at texel x, y, and leaves the rest of texture as it was. The image must lie inside texture, an RGBA8 texture; SDL does not check it.

Link copied to clipboard

Blocks until the work behind fence has finished on the GPU.

Link copied to clipboard
fun GpuDevice.write(buffer: TransferBuffer, bytes: ByteArray, offset: Int = 0)

Copies bytes into buffer at byte offset. Convenient for one-off uploads such as texture pixels; per-frame data should be written through map instead to avoid the extra copy.