package net.halbear.Terrain4J.EngineCore.Vulkan.Rendering.Pipeline;

import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DeviceLayers.Device;
import net.halbear.Terrain4J.EngineCore.Vulkan.Util.VulkanUtils;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.vulkan.VkPipelineCacheCreateInfo;
import org.tinylog.Logger;

import java.nio.LongBuffer;

import static org.lwjgl.vulkan.VK13.vkCreatePipelineCache;
import static org.lwjgl.vulkan.VK13.vkDestroyPipelineCache;

public class PipelineCache {
    private final long VulkanPipelineCache;
    public PipelineCache(Device device){
        Logger.debug("Creating new Vk Pipeline Cache");
        try(var MemStack = MemoryStack.stackPush()){
            var PipelineCacheCreateInfo = VkPipelineCacheCreateInfo.calloc(MemStack).sType$Default();
            LongBuffer longPtr = MemStack.mallocLong(1);
            VulkanUtils.vkCheck(vkCreatePipelineCache(device.FetchVulkanDevice(), PipelineCacheCreateInfo
            ,null, longPtr),"Error Creating New Pipeline Cache");
            VulkanPipelineCache = longPtr.get(0);
        }
    }
    public void CleanUp(Device device){
        Logger.debug("Destroying Vulkan Pipeline Cache");
        vkDestroyPipelineCache(device.FetchVulkanDevice(), VulkanPipelineCache, null);
    }
    public long GetVkPipelineCache(){return VulkanPipelineCache;}
}
