2 * Copyright © 2015 Intel Corporation
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:
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
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
24 #include "compiler/blob.h"
25 #include "util/hash_table.h"
26 #include "util/debug.h"
27 #include "util/disk_cache.h"
28 #include "util/mesa-sha1.h"
29 #include "nir/nir_serialize.h"
30 #include "anv_private.h"
31 #include "nir/nir_xfb_info.h"
33 struct anv_shader_bin
*
34 anv_shader_bin_create(struct anv_device
*device
,
35 const void *key_data
, uint32_t key_size
,
36 const void *kernel_data
, uint32_t kernel_size
,
37 const void *constant_data
, uint32_t constant_data_size
,
38 const struct brw_stage_prog_data
*prog_data_in
,
39 uint32_t prog_data_size
, const void *prog_data_param_in
,
40 const nir_xfb_info
*xfb_info_in
,
41 const struct anv_pipeline_bind_map
*bind_map
)
43 struct anv_shader_bin
*shader
;
44 struct anv_shader_bin_key
*key
;
45 struct brw_stage_prog_data
*prog_data
;
46 uint32_t *prog_data_param
;
47 nir_xfb_info
*xfb_info
;
48 struct anv_pipeline_binding
*surface_to_descriptor
, *sampler_to_descriptor
;
51 anv_multialloc_add(&ma
, &shader
, 1);
52 anv_multialloc_add_size(&ma
, &key
, sizeof(*key
) + key_size
);
53 anv_multialloc_add_size(&ma
, &prog_data
, prog_data_size
);
54 anv_multialloc_add(&ma
, &prog_data_param
, prog_data_in
->nr_params
);
56 uint32_t xfb_info_size
= nir_xfb_info_size(xfb_info_in
->output_count
);
57 anv_multialloc_add_size(&ma
, &xfb_info
, xfb_info_size
);
59 anv_multialloc_add(&ma
, &surface_to_descriptor
,
60 bind_map
->surface_count
);
61 anv_multialloc_add(&ma
, &sampler_to_descriptor
,
62 bind_map
->sampler_count
);
64 if (!anv_multialloc_alloc(&ma
, &device
->alloc
,
65 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
))
71 memcpy(key
->data
, key_data
, key_size
);
75 anv_state_pool_alloc(&device
->instruction_state_pool
, kernel_size
, 64);
76 memcpy(shader
->kernel
.map
, kernel_data
, kernel_size
);
77 shader
->kernel_size
= kernel_size
;
79 if (constant_data_size
) {
80 shader
->constant_data
=
81 anv_state_pool_alloc(&device
->dynamic_state_pool
,
82 constant_data_size
, 32);
83 memcpy(shader
->constant_data
.map
, constant_data
, constant_data_size
);
85 shader
->constant_data
= ANV_STATE_NULL
;
87 shader
->constant_data_size
= constant_data_size
;
89 memcpy(prog_data
, prog_data_in
, prog_data_size
);
90 memcpy(prog_data_param
, prog_data_param_in
,
91 prog_data
->nr_params
* sizeof(*prog_data_param
));
92 prog_data
->param
= prog_data_param
;
93 shader
->prog_data
= prog_data
;
94 shader
->prog_data_size
= prog_data_size
;
97 *xfb_info
= *xfb_info_in
;
98 typed_memcpy(xfb_info
->outputs
, xfb_info_in
->outputs
,
99 xfb_info_in
->output_count
);
100 shader
->xfb_info
= xfb_info
;
102 shader
->xfb_info
= NULL
;
105 shader
->bind_map
= *bind_map
;
106 typed_memcpy(surface_to_descriptor
, bind_map
->surface_to_descriptor
,
107 bind_map
->surface_count
);
108 shader
->bind_map
.surface_to_descriptor
= surface_to_descriptor
;
109 typed_memcpy(sampler_to_descriptor
, bind_map
->sampler_to_descriptor
,
110 bind_map
->sampler_count
);
111 shader
->bind_map
.sampler_to_descriptor
= sampler_to_descriptor
;
117 anv_shader_bin_destroy(struct anv_device
*device
,
118 struct anv_shader_bin
*shader
)
120 assert(shader
->ref_cnt
== 0);
121 anv_state_pool_free(&device
->instruction_state_pool
, shader
->kernel
);
122 anv_state_pool_free(&device
->dynamic_state_pool
, shader
->constant_data
);
123 vk_free(&device
->alloc
, shader
);
127 anv_shader_bin_write_to_blob(const struct anv_shader_bin
*shader
,
130 blob_write_uint32(blob
, shader
->key
->size
);
131 blob_write_bytes(blob
, shader
->key
->data
, shader
->key
->size
);
133 blob_write_uint32(blob
, shader
->kernel_size
);
134 blob_write_bytes(blob
, shader
->kernel
.map
, shader
->kernel_size
);
136 blob_write_uint32(blob
, shader
->constant_data_size
);
137 blob_write_bytes(blob
, shader
->constant_data
.map
,
138 shader
->constant_data_size
);
140 blob_write_uint32(blob
, shader
->prog_data_size
);
141 blob_write_bytes(blob
, shader
->prog_data
, shader
->prog_data_size
);
142 blob_write_bytes(blob
, shader
->prog_data
->param
,
143 shader
->prog_data
->nr_params
*
144 sizeof(*shader
->prog_data
->param
));
146 if (shader
->xfb_info
) {
147 uint32_t xfb_info_size
=
148 nir_xfb_info_size(shader
->xfb_info
->output_count
);
149 blob_write_uint32(blob
, xfb_info_size
);
150 blob_write_bytes(blob
, shader
->xfb_info
, xfb_info_size
);
152 blob_write_uint32(blob
, 0);
155 blob_write_uint32(blob
, shader
->bind_map
.surface_count
);
156 blob_write_uint32(blob
, shader
->bind_map
.sampler_count
);
157 blob_write_bytes(blob
, shader
->bind_map
.surface_to_descriptor
,
158 shader
->bind_map
.surface_count
*
159 sizeof(*shader
->bind_map
.surface_to_descriptor
));
160 blob_write_bytes(blob
, shader
->bind_map
.sampler_to_descriptor
,
161 shader
->bind_map
.sampler_count
*
162 sizeof(*shader
->bind_map
.sampler_to_descriptor
));
164 return !blob
->out_of_memory
;
167 static struct anv_shader_bin
*
168 anv_shader_bin_create_from_blob(struct anv_device
*device
,
169 struct blob_reader
*blob
)
171 uint32_t key_size
= blob_read_uint32(blob
);
172 const void *key_data
= blob_read_bytes(blob
, key_size
);
174 uint32_t kernel_size
= blob_read_uint32(blob
);
175 const void *kernel_data
= blob_read_bytes(blob
, kernel_size
);
177 uint32_t constant_data_size
= blob_read_uint32(blob
);
178 const void *constant_data
= blob_read_bytes(blob
, constant_data_size
);
180 uint32_t prog_data_size
= blob_read_uint32(blob
);
181 const struct brw_stage_prog_data
*prog_data
=
182 blob_read_bytes(blob
, prog_data_size
);
185 const void *prog_data_param
=
186 blob_read_bytes(blob
, prog_data
->nr_params
* sizeof(*prog_data
->param
));
188 const nir_xfb_info
*xfb_info
= NULL
;
189 uint32_t xfb_size
= blob_read_uint32(blob
);
191 xfb_info
= blob_read_bytes(blob
, xfb_size
);
193 struct anv_pipeline_bind_map bind_map
;
194 bind_map
.surface_count
= blob_read_uint32(blob
);
195 bind_map
.sampler_count
= blob_read_uint32(blob
);
196 bind_map
.surface_to_descriptor
= (void *)
197 blob_read_bytes(blob
, bind_map
.surface_count
*
198 sizeof(*bind_map
.surface_to_descriptor
));
199 bind_map
.sampler_to_descriptor
= (void *)
200 blob_read_bytes(blob
, bind_map
.sampler_count
*
201 sizeof(*bind_map
.sampler_to_descriptor
));
206 return anv_shader_bin_create(device
,
208 kernel_data
, kernel_size
,
209 constant_data
, constant_data_size
,
210 prog_data
, prog_data_size
, prog_data_param
,
211 xfb_info
, &bind_map
);
216 * - Compact binding table layout so it's tight and not dependent on
217 * descriptor set layout.
219 * - Review prog_data struct for size and cacheability: struct
220 * brw_stage_prog_data has binding_table which uses a lot of uint32_t for 8
221 * bit quantities etc; use bit fields for all bools, eg dual_src_blend.
225 shader_bin_key_hash_func(const void *void_key
)
227 const struct anv_shader_bin_key
*key
= void_key
;
228 return _mesa_hash_data(key
->data
, key
->size
);
232 shader_bin_key_compare_func(const void *void_a
, const void *void_b
)
234 const struct anv_shader_bin_key
*a
= void_a
, *b
= void_b
;
235 if (a
->size
!= b
->size
)
238 return memcmp(a
->data
, b
->data
, a
->size
) == 0;
242 sha1_hash_func(const void *sha1
)
244 return _mesa_hash_data(sha1
, 20);
248 sha1_compare_func(const void *sha1_a
, const void *sha1_b
)
250 return memcmp(sha1_a
, sha1_b
, 20) == 0;
254 anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
255 struct anv_device
*device
,
258 cache
->device
= device
;
259 pthread_mutex_init(&cache
->mutex
, NULL
);
262 cache
->cache
= _mesa_hash_table_create(NULL
, shader_bin_key_hash_func
,
263 shader_bin_key_compare_func
);
264 cache
->nir_cache
= _mesa_hash_table_create(NULL
, sha1_hash_func
,
268 cache
->nir_cache
= NULL
;
273 anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
)
275 pthread_mutex_destroy(&cache
->mutex
);
278 /* This is a bit unfortunate. In order to keep things from randomly
279 * going away, the shader cache has to hold a reference to all shader
280 * binaries it contains. We unref them when we destroy the cache.
282 hash_table_foreach(cache
->cache
, entry
)
283 anv_shader_bin_unref(cache
->device
, entry
->data
);
285 _mesa_hash_table_destroy(cache
->cache
, NULL
);
288 if (cache
->nir_cache
) {
289 hash_table_foreach(cache
->nir_cache
, entry
)
290 ralloc_free(entry
->data
);
292 _mesa_hash_table_destroy(cache
->nir_cache
, NULL
);
296 static struct anv_shader_bin
*
297 anv_pipeline_cache_search_locked(struct anv_pipeline_cache
*cache
,
298 const void *key_data
, uint32_t key_size
)
300 uint32_t vla
[1 + DIV_ROUND_UP(key_size
, sizeof(uint32_t))];
301 struct anv_shader_bin_key
*key
= (void *)vla
;
302 key
->size
= key_size
;
303 memcpy(key
->data
, key_data
, key_size
);
305 struct hash_entry
*entry
= _mesa_hash_table_search(cache
->cache
, key
);
312 struct anv_shader_bin
*
313 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
314 const void *key_data
, uint32_t key_size
)
319 pthread_mutex_lock(&cache
->mutex
);
321 struct anv_shader_bin
*shader
=
322 anv_pipeline_cache_search_locked(cache
, key_data
, key_size
);
324 pthread_mutex_unlock(&cache
->mutex
);
326 /* We increment refcount before handing it to the caller */
328 anv_shader_bin_ref(shader
);
334 anv_pipeline_cache_add_shader_bin(struct anv_pipeline_cache
*cache
,
335 struct anv_shader_bin
*bin
)
340 pthread_mutex_lock(&cache
->mutex
);
342 struct hash_entry
*entry
= _mesa_hash_table_search(cache
->cache
, bin
->key
);
344 /* Take a reference for the cache */
345 anv_shader_bin_ref(bin
);
346 _mesa_hash_table_insert(cache
->cache
, bin
->key
, bin
);
349 pthread_mutex_unlock(&cache
->mutex
);
352 static struct anv_shader_bin
*
353 anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache
*cache
,
354 const void *key_data
, uint32_t key_size
,
355 const void *kernel_data
,
356 uint32_t kernel_size
,
357 const void *constant_data
,
358 uint32_t constant_data_size
,
359 const struct brw_stage_prog_data
*prog_data
,
360 uint32_t prog_data_size
,
361 const void *prog_data_param
,
362 const nir_xfb_info
*xfb_info
,
363 const struct anv_pipeline_bind_map
*bind_map
)
365 struct anv_shader_bin
*shader
=
366 anv_pipeline_cache_search_locked(cache
, key_data
, key_size
);
370 struct anv_shader_bin
*bin
=
371 anv_shader_bin_create(cache
->device
, key_data
, key_size
,
372 kernel_data
, kernel_size
,
373 constant_data
, constant_data_size
,
374 prog_data
, prog_data_size
, prog_data_param
,
379 _mesa_hash_table_insert(cache
->cache
, bin
->key
, bin
);
384 struct anv_shader_bin
*
385 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
386 const void *key_data
, uint32_t key_size
,
387 const void *kernel_data
, uint32_t kernel_size
,
388 const void *constant_data
,
389 uint32_t constant_data_size
,
390 const struct brw_stage_prog_data
*prog_data
,
391 uint32_t prog_data_size
,
392 const nir_xfb_info
*xfb_info
,
393 const struct anv_pipeline_bind_map
*bind_map
)
396 pthread_mutex_lock(&cache
->mutex
);
398 struct anv_shader_bin
*bin
=
399 anv_pipeline_cache_add_shader_locked(cache
, key_data
, key_size
,
400 kernel_data
, kernel_size
,
401 constant_data
, constant_data_size
,
402 prog_data
, prog_data_size
,
406 pthread_mutex_unlock(&cache
->mutex
);
408 /* We increment refcount before handing it to the caller */
410 anv_shader_bin_ref(bin
);
414 /* In this case, we're not caching it so the caller owns it entirely */
415 return anv_shader_bin_create(cache
->device
, key_data
, key_size
,
416 kernel_data
, kernel_size
,
417 constant_data
, constant_data_size
,
418 prog_data
, prog_data_size
,
424 struct cache_header
{
425 uint32_t header_size
;
426 uint32_t header_version
;
429 uint8_t uuid
[VK_UUID_SIZE
];
433 anv_pipeline_cache_load(struct anv_pipeline_cache
*cache
,
434 const void *data
, size_t size
)
436 struct anv_device
*device
= cache
->device
;
437 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
439 if (cache
->cache
== NULL
)
442 struct blob_reader blob
;
443 blob_reader_init(&blob
, data
, size
);
445 struct cache_header header
;
446 blob_copy_bytes(&blob
, &header
, sizeof(header
));
447 uint32_t count
= blob_read_uint32(&blob
);
451 if (header
.header_size
< sizeof(header
))
453 if (header
.header_version
!= VK_PIPELINE_CACHE_HEADER_VERSION_ONE
)
455 if (header
.vendor_id
!= 0x8086)
457 if (header
.device_id
!= device
->chipset_id
)
459 if (memcmp(header
.uuid
, pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
) != 0)
462 for (uint32_t i
= 0; i
< count
; i
++) {
463 struct anv_shader_bin
*bin
=
464 anv_shader_bin_create_from_blob(device
, &blob
);
467 _mesa_hash_table_insert(cache
->cache
, bin
->key
, bin
);
471 VkResult
anv_CreatePipelineCache(
473 const VkPipelineCacheCreateInfo
* pCreateInfo
,
474 const VkAllocationCallbacks
* pAllocator
,
475 VkPipelineCache
* pPipelineCache
)
477 ANV_FROM_HANDLE(anv_device
, device
, _device
);
478 struct anv_pipeline_cache
*cache
;
480 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
);
481 assert(pCreateInfo
->flags
== 0);
483 cache
= vk_alloc2(&device
->alloc
, pAllocator
,
485 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
487 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
489 anv_pipeline_cache_init(cache
, device
,
490 device
->instance
->pipeline_cache_enabled
);
492 if (pCreateInfo
->initialDataSize
> 0)
493 anv_pipeline_cache_load(cache
,
494 pCreateInfo
->pInitialData
,
495 pCreateInfo
->initialDataSize
);
497 *pPipelineCache
= anv_pipeline_cache_to_handle(cache
);
502 void anv_DestroyPipelineCache(
504 VkPipelineCache _cache
,
505 const VkAllocationCallbacks
* pAllocator
)
507 ANV_FROM_HANDLE(anv_device
, device
, _device
);
508 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
513 anv_pipeline_cache_finish(cache
);
515 vk_free2(&device
->alloc
, pAllocator
, cache
);
518 VkResult
anv_GetPipelineCacheData(
520 VkPipelineCache _cache
,
524 ANV_FROM_HANDLE(anv_device
, device
, _device
);
525 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
526 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
530 blob_init_fixed(&blob
, pData
, *pDataSize
);
532 blob_init_fixed(&blob
, NULL
, SIZE_MAX
);
535 struct cache_header header
= {
536 .header_size
= sizeof(struct cache_header
),
537 .header_version
= VK_PIPELINE_CACHE_HEADER_VERSION_ONE
,
539 .device_id
= device
->chipset_id
,
541 memcpy(header
.uuid
, pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
542 blob_write_bytes(&blob
, &header
, sizeof(header
));
545 intptr_t count_offset
= blob_reserve_uint32(&blob
);
546 if (count_offset
< 0) {
549 return VK_INCOMPLETE
;
552 VkResult result
= VK_SUCCESS
;
554 hash_table_foreach(cache
->cache
, entry
) {
555 struct anv_shader_bin
*shader
= entry
->data
;
557 size_t save_size
= blob
.size
;
558 if (!anv_shader_bin_write_to_blob(shader
, &blob
)) {
559 /* If it fails reset to the previous size and bail */
560 blob
.size
= save_size
;
561 result
= VK_INCOMPLETE
;
569 blob_overwrite_uint32(&blob
, count_offset
, count
);
571 *pDataSize
= blob
.size
;
578 VkResult
anv_MergePipelineCaches(
580 VkPipelineCache destCache
,
581 uint32_t srcCacheCount
,
582 const VkPipelineCache
* pSrcCaches
)
584 ANV_FROM_HANDLE(anv_pipeline_cache
, dst
, destCache
);
589 for (uint32_t i
= 0; i
< srcCacheCount
; i
++) {
590 ANV_FROM_HANDLE(anv_pipeline_cache
, src
, pSrcCaches
[i
]);
594 hash_table_foreach(src
->cache
, entry
) {
595 struct anv_shader_bin
*bin
= entry
->data
;
598 if (_mesa_hash_table_search(dst
->cache
, bin
->key
))
601 anv_shader_bin_ref(bin
);
602 _mesa_hash_table_insert(dst
->cache
, bin
->key
, bin
);
609 struct anv_shader_bin
*
610 anv_device_search_for_kernel(struct anv_device
*device
,
611 struct anv_pipeline_cache
*cache
,
612 const void *key_data
, uint32_t key_size
,
613 bool *user_cache_hit
)
615 struct anv_shader_bin
*bin
;
617 *user_cache_hit
= false;
620 bin
= anv_pipeline_cache_search(cache
, key_data
, key_size
);
622 *user_cache_hit
= cache
!= &device
->default_pipeline_cache
;
627 #ifdef ENABLE_SHADER_CACHE
628 struct disk_cache
*disk_cache
= device
->instance
->physicalDevice
.disk_cache
;
629 if (disk_cache
&& device
->instance
->pipeline_cache_enabled
) {
631 disk_cache_compute_key(disk_cache
, key_data
, key_size
, cache_key
);
634 uint8_t *buffer
= disk_cache_get(disk_cache
, cache_key
, &buffer_size
);
636 struct blob_reader blob
;
637 blob_reader_init(&blob
, buffer
, buffer_size
);
638 bin
= anv_shader_bin_create_from_blob(device
, &blob
);
643 anv_pipeline_cache_add_shader_bin(cache
, bin
);
653 struct anv_shader_bin
*
654 anv_device_upload_kernel(struct anv_device
*device
,
655 struct anv_pipeline_cache
*cache
,
656 const void *key_data
, uint32_t key_size
,
657 const void *kernel_data
, uint32_t kernel_size
,
658 const void *constant_data
,
659 uint32_t constant_data_size
,
660 const struct brw_stage_prog_data
*prog_data
,
661 uint32_t prog_data_size
,
662 const nir_xfb_info
*xfb_info
,
663 const struct anv_pipeline_bind_map
*bind_map
)
665 struct anv_shader_bin
*bin
;
667 bin
= anv_pipeline_cache_upload_kernel(cache
, key_data
, key_size
,
668 kernel_data
, kernel_size
,
669 constant_data
, constant_data_size
,
670 prog_data
, prog_data_size
,
673 bin
= anv_shader_bin_create(device
, key_data
, key_size
,
674 kernel_data
, kernel_size
,
675 constant_data
, constant_data_size
,
676 prog_data
, prog_data_size
,
684 #ifdef ENABLE_SHADER_CACHE
685 struct disk_cache
*disk_cache
= device
->instance
->physicalDevice
.disk_cache
;
689 if (anv_shader_bin_write_to_blob(bin
, &binary
)) {
691 disk_cache_compute_key(disk_cache
, key_data
, key_size
, cache_key
);
693 disk_cache_put(disk_cache
, cache_key
, binary
.data
, binary
.size
, NULL
);
696 blob_finish(&binary
);
703 struct serialized_nir
{
704 unsigned char sha1_key
[20];
710 anv_device_search_for_nir(struct anv_device
*device
,
711 struct anv_pipeline_cache
*cache
,
712 const nir_shader_compiler_options
*nir_options
,
713 unsigned char sha1_key
[20],
716 if (cache
&& cache
->nir_cache
) {
717 const struct serialized_nir
*snir
= NULL
;
719 pthread_mutex_lock(&cache
->mutex
);
720 struct hash_entry
*entry
=
721 _mesa_hash_table_search(cache
->nir_cache
, sha1_key
);
724 pthread_mutex_unlock(&cache
->mutex
);
727 struct blob_reader blob
;
728 blob_reader_init(&blob
, snir
->data
, snir
->size
);
730 nir_shader
*nir
= nir_deserialize(mem_ctx
, nir_options
, &blob
);
743 anv_device_upload_nir(struct anv_device
*device
,
744 struct anv_pipeline_cache
*cache
,
745 const struct nir_shader
*nir
,
746 unsigned char sha1_key
[20])
748 if (cache
&& cache
->nir_cache
) {
749 pthread_mutex_lock(&cache
->mutex
);
750 struct hash_entry
*entry
=
751 _mesa_hash_table_search(cache
->nir_cache
, sha1_key
);
752 pthread_mutex_unlock(&cache
->mutex
);
759 nir_serialize(&blob
, nir
);
760 if (blob
.out_of_memory
) {
765 pthread_mutex_lock(&cache
->mutex
);
766 /* Because ralloc isn't thread-safe, we have to do all this inside the
767 * lock. We could unlock for the big memcpy but it's probably not worth
770 entry
= _mesa_hash_table_search(cache
->nir_cache
, sha1_key
);
773 pthread_mutex_unlock(&cache
->mutex
);
777 struct serialized_nir
*snir
=
778 ralloc_size(cache
->nir_cache
, sizeof(*snir
) + blob
.size
);
779 memcpy(snir
->sha1_key
, sha1_key
, 20);
780 snir
->size
= blob
.size
;
781 memcpy(snir
->data
, blob
.data
, blob
.size
);
785 _mesa_hash_table_insert(cache
->nir_cache
, snir
->sha1_key
, snir
);
787 pthread_mutex_unlock(&cache
->mutex
);