1/*
2 * Copyright © 2019 Red Hat.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include "lvp_private.h"
25
26VKAPI_ATTR VkResult VKAPI_CALL lvp_CreatePipelineCache(
27    VkDevice                                    _device,
28    const VkPipelineCacheCreateInfo*            pCreateInfo,
29    const VkAllocationCallbacks*                pAllocator,
30    VkPipelineCache*                            pPipelineCache)
31{
32   LVP_FROM_HANDLE(lvp_device, device, _device);
33   struct lvp_pipeline_cache *cache;
34
35   assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO);
36
37   cache = vk_alloc2(&device->vk.alloc, pAllocator,
38                       sizeof(*cache), 8,
39                       VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
40   if (cache == NULL)
41      return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
42
43   vk_object_base_init(&device->vk, &cache->base,
44                       VK_OBJECT_TYPE_PIPELINE_CACHE);
45   if (pAllocator)
46     cache->alloc = *pAllocator;
47   else
48     cache->alloc = device->vk.alloc;
49
50   cache->device = device;
51   *pPipelineCache = lvp_pipeline_cache_to_handle(cache);
52
53   return VK_SUCCESS;
54}
55
56VKAPI_ATTR void VKAPI_CALL lvp_DestroyPipelineCache(
57    VkDevice                                    _device,
58    VkPipelineCache                             _cache,
59    const VkAllocationCallbacks*                pAllocator)
60{
61   LVP_FROM_HANDLE(lvp_device, device, _device);
62   LVP_FROM_HANDLE(lvp_pipeline_cache, cache, _cache);
63
64   if (!_cache)
65      return;
66//   lvp_pipeline_cache_finish(cache);
67   vk_object_base_finish(&cache->base);
68   vk_free2(&device->vk.alloc, pAllocator, cache);
69}
70
71VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPipelineCacheData(
72        VkDevice                                    _device,
73        VkPipelineCache                             _cache,
74        size_t*                                     pDataSize,
75        void*                                       pData)
76{
77   VkResult result = VK_SUCCESS;
78   if (pData) {
79      if (*pDataSize < 32) {
80         *pDataSize = 0;
81         result = VK_INCOMPLETE;
82      } else {
83         uint32_t *hdr = (uint32_t *)pData;
84         hdr[0] = 32;
85         hdr[1] = 1;
86         hdr[2] = VK_VENDOR_ID_MESA;
87         hdr[3] = 0;
88         lvp_device_get_cache_uuid(&hdr[4]);
89      }
90   } else
91      *pDataSize = 32;
92   return result;
93}
94
95VKAPI_ATTR VkResult VKAPI_CALL lvp_MergePipelineCaches(
96        VkDevice                                    _device,
97        VkPipelineCache                             destCache,
98        uint32_t                                    srcCacheCount,
99        const VkPipelineCache*                      pSrcCaches)
100{
101   return VK_SUCCESS;
102}
103