Skip to content

PipelineCache.kt

src/jvmMain/kotlin/afield/graphics/vulkan/device/PipelineCache.kt · 37 lines

package afield.graphics.vulkan.device

import org.lwjgl.system.MemoryStack
import org.lwjgl.vulkan.VK10
import org.lwjgl.vulkan.VkPipelineCacheCreateInfo
import afield.graphics.vulkan.util.vkCheck

A Vulkan pipeline cache that the renderer passes to the pipelines it builds on one Device.

PipelineCache is created empty and lives only for the device's lifetime; nothing is saved to or loaded from disk.

class PipelineCache(device: Device)

val device: Device

var vkPipelineCache: Long = 0

init

    init {
        this.device = device
        MemoryStack.stackPush().use { stack ->
            val createInfo = VkPipelineCacheCreateInfo.calloc(stack)
                .sType(VK10.VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO)
            val lp = stack.mallocLong(1)
            vkCheck(
                VK10.vkCreatePipelineCache(device.vkDevice, createInfo, null, lp),
                "Error creating pipeline cache"
            )
            vkPipelineCache = lp[0]
        }
    }

fun cleanup()

    fun cleanup() {
        VK10.vkDestroyPipelineCache(device.vkDevice, vkPipelineCache, null)
    }
}