b08395f5cfb3b6bcb024e4558b80c906d3ac6470
[mesa.git] / src / amd / vulkan / radv_pipeline_cache.c
1 /*
2 * Copyright © 2015 Intel Corporation
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 "util/mesa-sha1.h"
25 #include "util/debug.h"
26 #include "util/disk_cache.h"
27 #include "util/u_atomic.h"
28 #include "radv_debug.h"
29 #include "radv_private.h"
30 #include "radv_shader.h"
31
32 #include "ac_nir_to_llvm.h"
33
34 struct cache_entry {
35 union {
36 unsigned char sha1[20];
37 uint32_t sha1_dw[5];
38 };
39 uint32_t binary_sizes[MESA_SHADER_STAGES];
40 struct radv_shader_variant *variants[MESA_SHADER_STAGES];
41 char code[0];
42 };
43
44 static void
45 radv_pipeline_cache_lock(struct radv_pipeline_cache *cache)
46 {
47 if (cache->flags & VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT_EXT)
48 return;
49
50 pthread_mutex_lock(&cache->mutex);
51 }
52
53 static void
54 radv_pipeline_cache_unlock(struct radv_pipeline_cache *cache)
55 {
56 if (cache->flags & VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT_EXT)
57 return;
58
59 pthread_mutex_unlock(&cache->mutex);
60 }
61
62 void
63 radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
64 struct radv_device *device)
65 {
66 cache->device = device;
67 pthread_mutex_init(&cache->mutex, NULL);
68 cache->flags = 0;
69
70 cache->modified = false;
71 cache->kernel_count = 0;
72 cache->total_size = 0;
73 cache->table_size = 1024;
74 const size_t byte_size = cache->table_size * sizeof(cache->hash_table[0]);
75 cache->hash_table = malloc(byte_size);
76
77 /* We don't consider allocation failure fatal, we just start with a 0-sized
78 * cache. Disable caching when we want to keep shader debug info, since
79 * we don't get the debug info on cached shaders. */
80 if (cache->hash_table == NULL ||
81 (device->instance->debug_flags & RADV_DEBUG_NO_CACHE))
82 cache->table_size = 0;
83 else
84 memset(cache->hash_table, 0, byte_size);
85 }
86
87 void
88 radv_pipeline_cache_finish(struct radv_pipeline_cache *cache)
89 {
90 for (unsigned i = 0; i < cache->table_size; ++i)
91 if (cache->hash_table[i]) {
92 for(int j = 0; j < MESA_SHADER_STAGES; ++j) {
93 if (cache->hash_table[i]->variants[j])
94 radv_shader_variant_destroy(cache->device,
95 cache->hash_table[i]->variants[j]);
96 }
97 vk_free(&cache->alloc, cache->hash_table[i]);
98 }
99 pthread_mutex_destroy(&cache->mutex);
100 free(cache->hash_table);
101 }
102
103 static uint32_t
104 entry_size(struct cache_entry *entry)
105 {
106 size_t ret = sizeof(*entry);
107 for (int i = 0; i < MESA_SHADER_STAGES; ++i)
108 if (entry->binary_sizes[i])
109 ret += entry->binary_sizes[i];
110 return ret;
111 }
112
113 void
114 radv_hash_shaders(unsigned char *hash,
115 const VkPipelineShaderStageCreateInfo **stages,
116 const struct radv_pipeline_layout *layout,
117 const struct radv_pipeline_key *key,
118 uint32_t flags)
119 {
120 struct mesa_sha1 ctx;
121
122 _mesa_sha1_init(&ctx);
123 if (key)
124 _mesa_sha1_update(&ctx, key, sizeof(*key));
125 if (layout)
126 _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
127
128 for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
129 if (stages[i]) {
130 RADV_FROM_HANDLE(radv_shader_module, module, stages[i]->module);
131 const VkSpecializationInfo *spec_info = stages[i]->pSpecializationInfo;
132
133 _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
134 _mesa_sha1_update(&ctx, stages[i]->pName, strlen(stages[i]->pName));
135 if (spec_info) {
136 _mesa_sha1_update(&ctx, spec_info->pMapEntries,
137 spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]);
138 _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize);
139 }
140 }
141 }
142 _mesa_sha1_update(&ctx, &flags, 4);
143 _mesa_sha1_final(&ctx, hash);
144 }
145
146
147 static struct cache_entry *
148 radv_pipeline_cache_search_unlocked(struct radv_pipeline_cache *cache,
149 const unsigned char *sha1)
150 {
151 const uint32_t mask = cache->table_size - 1;
152 const uint32_t start = (*(uint32_t *) sha1);
153
154 if (cache->table_size == 0)
155 return NULL;
156
157 for (uint32_t i = 0; i < cache->table_size; i++) {
158 const uint32_t index = (start + i) & mask;
159 struct cache_entry *entry = cache->hash_table[index];
160
161 if (!entry)
162 return NULL;
163
164 if (memcmp(entry->sha1, sha1, sizeof(entry->sha1)) == 0) {
165 return entry;
166 }
167 }
168
169 unreachable("hash table should never be full");
170 }
171
172 static struct cache_entry *
173 radv_pipeline_cache_search(struct radv_pipeline_cache *cache,
174 const unsigned char *sha1)
175 {
176 struct cache_entry *entry;
177
178 radv_pipeline_cache_lock(cache);
179
180 entry = radv_pipeline_cache_search_unlocked(cache, sha1);
181
182 radv_pipeline_cache_unlock(cache);
183
184 return entry;
185 }
186
187 static void
188 radv_pipeline_cache_set_entry(struct radv_pipeline_cache *cache,
189 struct cache_entry *entry)
190 {
191 const uint32_t mask = cache->table_size - 1;
192 const uint32_t start = entry->sha1_dw[0];
193
194 /* We'll always be able to insert when we get here. */
195 assert(cache->kernel_count < cache->table_size / 2);
196
197 for (uint32_t i = 0; i < cache->table_size; i++) {
198 const uint32_t index = (start + i) & mask;
199 if (!cache->hash_table[index]) {
200 cache->hash_table[index] = entry;
201 break;
202 }
203 }
204
205 cache->total_size += entry_size(entry);
206 cache->kernel_count++;
207 }
208
209
210 static VkResult
211 radv_pipeline_cache_grow(struct radv_pipeline_cache *cache)
212 {
213 const uint32_t table_size = cache->table_size * 2;
214 const uint32_t old_table_size = cache->table_size;
215 const size_t byte_size = table_size * sizeof(cache->hash_table[0]);
216 struct cache_entry **table;
217 struct cache_entry **old_table = cache->hash_table;
218
219 table = malloc(byte_size);
220 if (table == NULL)
221 return vk_error(cache->device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
222
223 cache->hash_table = table;
224 cache->table_size = table_size;
225 cache->kernel_count = 0;
226 cache->total_size = 0;
227
228 memset(cache->hash_table, 0, byte_size);
229 for (uint32_t i = 0; i < old_table_size; i++) {
230 struct cache_entry *entry = old_table[i];
231 if (!entry)
232 continue;
233
234 radv_pipeline_cache_set_entry(cache, entry);
235 }
236
237 free(old_table);
238
239 return VK_SUCCESS;
240 }
241
242 static void
243 radv_pipeline_cache_add_entry(struct radv_pipeline_cache *cache,
244 struct cache_entry *entry)
245 {
246 if (cache->kernel_count == cache->table_size / 2)
247 radv_pipeline_cache_grow(cache);
248
249 /* Failing to grow that hash table isn't fatal, but may mean we don't
250 * have enough space to add this new kernel. Only add it if there's room.
251 */
252 if (cache->kernel_count < cache->table_size / 2)
253 radv_pipeline_cache_set_entry(cache, entry);
254 }
255
256 static bool
257 radv_is_cache_disabled(struct radv_device *device)
258 {
259 /* Pipeline caches can be disabled with RADV_DEBUG=nocache, with
260 * MESA_GLSL_CACHE_DISABLE=1, and when VK_AMD_shader_info is requested.
261 */
262 return (device->instance->debug_flags & RADV_DEBUG_NO_CACHE);
263 }
264
265 /*
266 * Secure compiles cannot open files so we get the parent process to load the
267 * cache entry for us.
268 */
269 static struct cache_entry *
270 radv_sc_read_from_disk_cache(struct radv_device *device, uint8_t *disk_sha1)
271 {
272 struct cache_entry *entry;
273 unsigned process = device->sc_state->secure_compile_thread_counter;
274 enum radv_secure_compile_type sc_type = RADV_SC_TYPE_READ_DISK_CACHE;
275
276 write(device->sc_state->secure_compile_processes[process].fd_secure_output,
277 &sc_type, sizeof(enum radv_secure_compile_type));
278 write(device->sc_state->secure_compile_processes[process].fd_secure_output,
279 disk_sha1, sizeof(uint8_t) * 20);
280
281 uint8_t found_cache_entry;
282 if (!radv_sc_read(device->sc_state->secure_compile_processes[process].fd_secure_input,
283 &found_cache_entry, sizeof(uint8_t), true))
284 return NULL;
285
286 if (found_cache_entry) {
287 size_t entry_size;
288 if (!radv_sc_read(device->sc_state->secure_compile_processes[process].fd_secure_input,
289 &entry_size, sizeof(size_t), true))
290 return NULL;
291
292 entry = malloc(entry_size);
293 if (!radv_sc_read(device->sc_state->secure_compile_processes[process].fd_secure_input,
294 entry, entry_size, true))
295 return NULL;
296
297 return entry;
298 }
299
300 return NULL;
301 }
302
303 /*
304 * Secure compiles cannot open files so we get the parent process to write to
305 * the disk cache for us.
306 */
307 static void
308 radv_sc_write_to_disk_cache(struct radv_device *device, uint8_t *disk_sha1,
309 struct cache_entry *entry)
310 {
311 unsigned process = device->sc_state->secure_compile_thread_counter;
312 enum radv_secure_compile_type sc_type = RADV_SC_TYPE_WRITE_DISK_CACHE;
313
314 write(device->sc_state->secure_compile_processes[process].fd_secure_output,
315 &sc_type, sizeof(enum radv_secure_compile_type));
316 write(device->sc_state->secure_compile_processes[process].fd_secure_output,
317 disk_sha1, sizeof(uint8_t) * 20);
318
319 uint32_t size = entry_size(entry);
320 write(device->sc_state->secure_compile_processes[process].fd_secure_output,
321 &size, sizeof(uint32_t));
322 write(device->sc_state->secure_compile_processes[process].fd_secure_output,
323 entry, size);
324 }
325
326 bool
327 radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
328 struct radv_pipeline_cache *cache,
329 const unsigned char *sha1,
330 struct radv_shader_variant **variants,
331 bool *found_in_application_cache)
332 {
333 struct cache_entry *entry;
334
335 if (!cache) {
336 cache = device->mem_cache;
337 *found_in_application_cache = false;
338 }
339
340 radv_pipeline_cache_lock(cache);
341
342 entry = radv_pipeline_cache_search_unlocked(cache, sha1);
343
344 if (!entry) {
345 *found_in_application_cache = false;
346
347 /* Don't cache when we want debug info, since this isn't
348 * present in the cache.
349 */
350 if (radv_is_cache_disabled(device) || !device->physical_device->disk_cache) {
351 radv_pipeline_cache_unlock(cache);
352 return false;
353 }
354
355 uint8_t disk_sha1[20];
356 disk_cache_compute_key(device->physical_device->disk_cache,
357 sha1, 20, disk_sha1);
358
359 if (radv_device_use_secure_compile(device->instance)) {
360 entry = radv_sc_read_from_disk_cache(device, disk_sha1);
361 } else {
362 entry = (struct cache_entry *)
363 disk_cache_get(device->physical_device->disk_cache,
364 disk_sha1, NULL);
365 }
366
367 if (!entry) {
368 radv_pipeline_cache_unlock(cache);
369 return false;
370 } else {
371 size_t size = entry_size(entry);
372 struct cache_entry *new_entry = vk_alloc(&cache->alloc, size, 8,
373 VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
374 if (!new_entry) {
375 free(entry);
376 radv_pipeline_cache_unlock(cache);
377 return false;
378 }
379
380 memcpy(new_entry, entry, entry_size(entry));
381 free(entry);
382 entry = new_entry;
383
384 if (!(device->instance->debug_flags & RADV_DEBUG_NO_MEMORY_CACHE) ||
385 cache != device->mem_cache)
386 radv_pipeline_cache_add_entry(cache, new_entry);
387 }
388 }
389
390 char *p = entry->code;
391 for(int i = 0; i < MESA_SHADER_STAGES; ++i) {
392 if (!entry->variants[i] && entry->binary_sizes[i]) {
393 struct radv_shader_binary *binary = calloc(1, entry->binary_sizes[i]);
394 memcpy(binary, p, entry->binary_sizes[i]);
395 p += entry->binary_sizes[i];
396
397 entry->variants[i] = radv_shader_variant_create(device, binary, false);
398 free(binary);
399 } else if (entry->binary_sizes[i]) {
400 p += entry->binary_sizes[i];
401 }
402
403 }
404
405 memcpy(variants, entry->variants, sizeof(entry->variants));
406
407 if (device->instance->debug_flags & RADV_DEBUG_NO_MEMORY_CACHE &&
408 cache == device->mem_cache)
409 vk_free(&cache->alloc, entry);
410 else {
411 for (int i = 0; i < MESA_SHADER_STAGES; ++i)
412 if (entry->variants[i])
413 p_atomic_inc(&entry->variants[i]->ref_count);
414 }
415
416 radv_pipeline_cache_unlock(cache);
417 return true;
418 }
419
420 void
421 radv_pipeline_cache_insert_shaders(struct radv_device *device,
422 struct radv_pipeline_cache *cache,
423 const unsigned char *sha1,
424 struct radv_shader_variant **variants,
425 struct radv_shader_binary *const *binaries)
426 {
427 if (!cache)
428 cache = device->mem_cache;
429
430 radv_pipeline_cache_lock(cache);
431 struct cache_entry *entry = radv_pipeline_cache_search_unlocked(cache, sha1);
432 if (entry) {
433 for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
434 if (entry->variants[i]) {
435 radv_shader_variant_destroy(cache->device, variants[i]);
436 variants[i] = entry->variants[i];
437 } else {
438 entry->variants[i] = variants[i];
439 }
440 if (variants[i])
441 p_atomic_inc(&variants[i]->ref_count);
442 }
443 radv_pipeline_cache_unlock(cache);
444 return;
445 }
446
447 /* Don't cache when we want debug info, since this isn't
448 * present in the cache.
449 */
450 if (radv_is_cache_disabled(device)) {
451 radv_pipeline_cache_unlock(cache);
452 return;
453 }
454
455 size_t size = sizeof(*entry);
456 for (int i = 0; i < MESA_SHADER_STAGES; ++i)
457 if (variants[i])
458 size += binaries[i]->total_size;
459
460
461 entry = vk_alloc(&cache->alloc, size, 8,
462 VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
463 if (!entry) {
464 radv_pipeline_cache_unlock(cache);
465 return;
466 }
467
468 memset(entry, 0, sizeof(*entry));
469 memcpy(entry->sha1, sha1, 20);
470
471 char* p = entry->code;
472
473 for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
474 if (!variants[i])
475 continue;
476
477 entry->binary_sizes[i] = binaries[i]->total_size;
478
479 memcpy(p, binaries[i], binaries[i]->total_size);
480 p += binaries[i]->total_size;
481 }
482
483 /* Always add cache items to disk. This will allow collection of
484 * compiled shaders by third parties such as steam, even if the app
485 * implements its own pipeline cache.
486 */
487 if (device->physical_device->disk_cache) {
488 uint8_t disk_sha1[20];
489 disk_cache_compute_key(device->physical_device->disk_cache, sha1, 20,
490 disk_sha1);
491
492 /* Write the cache item out to the parent of this forked
493 * process.
494 */
495 if (radv_device_use_secure_compile(device->instance)) {
496 radv_sc_write_to_disk_cache(device, disk_sha1, entry);
497 } else {
498 disk_cache_put(device->physical_device->disk_cache,
499 disk_sha1, entry, entry_size(entry),
500 NULL);
501 }
502 }
503
504 if (device->instance->debug_flags & RADV_DEBUG_NO_MEMORY_CACHE &&
505 cache == device->mem_cache) {
506 vk_free2(&cache->alloc, NULL, entry);
507 radv_pipeline_cache_unlock(cache);
508 return;
509 }
510
511 /* We delay setting the variant so we have reproducible disk cache
512 * items.
513 */
514 for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
515 if (!variants[i])
516 continue;
517
518 entry->variants[i] = variants[i];
519 p_atomic_inc(&variants[i]->ref_count);
520 }
521
522 radv_pipeline_cache_add_entry(cache, entry);
523
524 cache->modified = true;
525 radv_pipeline_cache_unlock(cache);
526 return;
527 }
528
529 struct cache_header {
530 uint32_t header_size;
531 uint32_t header_version;
532 uint32_t vendor_id;
533 uint32_t device_id;
534 uint8_t uuid[VK_UUID_SIZE];
535 };
536
537 bool
538 radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
539 const void *data, size_t size)
540 {
541 struct radv_device *device = cache->device;
542 struct cache_header header;
543
544 if (size < sizeof(header))
545 return false;
546 memcpy(&header, data, sizeof(header));
547 if (header.header_size < sizeof(header))
548 return false;
549 if (header.header_version != VK_PIPELINE_CACHE_HEADER_VERSION_ONE)
550 return false;
551 if (header.vendor_id != ATI_VENDOR_ID)
552 return false;
553 if (header.device_id != device->physical_device->rad_info.pci_id)
554 return false;
555 if (memcmp(header.uuid, device->physical_device->cache_uuid, VK_UUID_SIZE) != 0)
556 return false;
557
558 char *end = (void *) data + size;
559 char *p = (void *) data + header.header_size;
560
561 while (end - p >= sizeof(struct cache_entry)) {
562 struct cache_entry *entry = (struct cache_entry*)p;
563 struct cache_entry *dest_entry;
564 size_t size = entry_size(entry);
565 if(end - p < size)
566 break;
567
568 dest_entry = vk_alloc(&cache->alloc, size,
569 8, VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
570 if (dest_entry) {
571 memcpy(dest_entry, entry, size);
572 for (int i = 0; i < MESA_SHADER_STAGES; ++i)
573 dest_entry->variants[i] = NULL;
574 radv_pipeline_cache_add_entry(cache, dest_entry);
575 }
576 p += size;
577 }
578
579 return true;
580 }
581
582 VkResult radv_CreatePipelineCache(
583 VkDevice _device,
584 const VkPipelineCacheCreateInfo* pCreateInfo,
585 const VkAllocationCallbacks* pAllocator,
586 VkPipelineCache* pPipelineCache)
587 {
588 RADV_FROM_HANDLE(radv_device, device, _device);
589 struct radv_pipeline_cache *cache;
590
591 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO);
592 assert(pCreateInfo->flags == 0);
593
594 cache = vk_alloc2(&device->vk.alloc, pAllocator,
595 sizeof(*cache), 8,
596 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
597 if (cache == NULL)
598 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
599
600 vk_object_base_init(&device->vk, &cache->base,
601 VK_OBJECT_TYPE_PIPELINE_CACHE);
602
603 if (pAllocator)
604 cache->alloc = *pAllocator;
605 else
606 cache->alloc = device->vk.alloc;
607
608 radv_pipeline_cache_init(cache, device);
609 cache->flags = pCreateInfo->flags;
610
611 if (pCreateInfo->initialDataSize > 0) {
612 radv_pipeline_cache_load(cache,
613 pCreateInfo->pInitialData,
614 pCreateInfo->initialDataSize);
615 }
616
617 *pPipelineCache = radv_pipeline_cache_to_handle(cache);
618
619 return VK_SUCCESS;
620 }
621
622 void radv_DestroyPipelineCache(
623 VkDevice _device,
624 VkPipelineCache _cache,
625 const VkAllocationCallbacks* pAllocator)
626 {
627 RADV_FROM_HANDLE(radv_device, device, _device);
628 RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache);
629
630 if (!cache)
631 return;
632 radv_pipeline_cache_finish(cache);
633
634 vk_object_base_finish(&cache->base);
635 vk_free2(&device->vk.alloc, pAllocator, cache);
636 }
637
638 VkResult radv_GetPipelineCacheData(
639 VkDevice _device,
640 VkPipelineCache _cache,
641 size_t* pDataSize,
642 void* pData)
643 {
644 RADV_FROM_HANDLE(radv_device, device, _device);
645 RADV_FROM_HANDLE(radv_pipeline_cache, cache, _cache);
646 struct cache_header *header;
647 VkResult result = VK_SUCCESS;
648
649 radv_pipeline_cache_lock(cache);
650
651 const size_t size = sizeof(*header) + cache->total_size;
652 if (pData == NULL) {
653 radv_pipeline_cache_unlock(cache);
654 *pDataSize = size;
655 return VK_SUCCESS;
656 }
657 if (*pDataSize < sizeof(*header)) {
658 radv_pipeline_cache_unlock(cache);
659 *pDataSize = 0;
660 return VK_INCOMPLETE;
661 }
662 void *p = pData, *end = pData + *pDataSize;
663 header = p;
664 header->header_size = sizeof(*header);
665 header->header_version = VK_PIPELINE_CACHE_HEADER_VERSION_ONE;
666 header->vendor_id = ATI_VENDOR_ID;
667 header->device_id = device->physical_device->rad_info.pci_id;
668 memcpy(header->uuid, device->physical_device->cache_uuid, VK_UUID_SIZE);
669 p += header->header_size;
670
671 struct cache_entry *entry;
672 for (uint32_t i = 0; i < cache->table_size; i++) {
673 if (!cache->hash_table[i])
674 continue;
675 entry = cache->hash_table[i];
676 const uint32_t size = entry_size(entry);
677 if (end < p + size) {
678 result = VK_INCOMPLETE;
679 break;
680 }
681
682 memcpy(p, entry, size);
683 for(int j = 0; j < MESA_SHADER_STAGES; ++j)
684 ((struct cache_entry*)p)->variants[j] = NULL;
685 p += size;
686 }
687 *pDataSize = p - pData;
688
689 radv_pipeline_cache_unlock(cache);
690 return result;
691 }
692
693 static void
694 radv_pipeline_cache_merge(struct radv_pipeline_cache *dst,
695 struct radv_pipeline_cache *src)
696 {
697 for (uint32_t i = 0; i < src->table_size; i++) {
698 struct cache_entry *entry = src->hash_table[i];
699 if (!entry || radv_pipeline_cache_search(dst, entry->sha1))
700 continue;
701
702 radv_pipeline_cache_add_entry(dst, entry);
703
704 src->hash_table[i] = NULL;
705 }
706 }
707
708 VkResult radv_MergePipelineCaches(
709 VkDevice _device,
710 VkPipelineCache destCache,
711 uint32_t srcCacheCount,
712 const VkPipelineCache* pSrcCaches)
713 {
714 RADV_FROM_HANDLE(radv_pipeline_cache, dst, destCache);
715
716 for (uint32_t i = 0; i < srcCacheCount; i++) {
717 RADV_FROM_HANDLE(radv_pipeline_cache, src, pSrcCaches[i]);
718
719 radv_pipeline_cache_merge(dst, src);
720 }
721
722 return VK_SUCCESS;
723 }