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_uint32(blob
, shader
->bind_map
.image_param_count
);
158 blob_write_bytes(blob
, shader
->bind_map
.surface_to_descriptor
,
159 shader
->bind_map
.surface_count
*
160 sizeof(*shader
->bind_map
.surface_to_descriptor
));
161 blob_write_bytes(blob
, shader
->bind_map
.sampler_to_descriptor
,
162 shader
->bind_map
.sampler_count
*
163 sizeof(*shader
->bind_map
.sampler_to_descriptor
));
165 return !blob
->out_of_memory
;
168 static struct anv_shader_bin
*
169 anv_shader_bin_create_from_blob(struct anv_device
*device
,
170 struct blob_reader
*blob
)
172 uint32_t key_size
= blob_read_uint32(blob
);
173 const void *key_data
= blob_read_bytes(blob
, key_size
);
175 uint32_t kernel_size
= blob_read_uint32(blob
);
176 const void *kernel_data
= blob_read_bytes(blob
, kernel_size
);
178 uint32_t constant_data_size
= blob_read_uint32(blob
);
179 const void *constant_data
= blob_read_bytes(blob
, constant_data_size
);
181 uint32_t prog_data_size
= blob_read_uint32(blob
);
182 const struct brw_stage_prog_data
*prog_data
=
183 blob_read_bytes(blob
, prog_data_size
);
186 const void *prog_data_param
=
187 blob_read_bytes(blob
, prog_data
->nr_params
* sizeof(*prog_data
->param
));
189 const nir_xfb_info
*xfb_info
= NULL
;
190 uint32_t xfb_size
= blob_read_uint32(blob
);
192 xfb_info
= blob_read_bytes(blob
, xfb_size
);
194 struct anv_pipeline_bind_map bind_map
;
195 bind_map
.surface_count
= blob_read_uint32(blob
);
196 bind_map
.sampler_count
= blob_read_uint32(blob
);
197 bind_map
.image_param_count
= blob_read_uint32(blob
);
198 bind_map
.surface_to_descriptor
= (void *)
199 blob_read_bytes(blob
, bind_map
.surface_count
*
200 sizeof(*bind_map
.surface_to_descriptor
));
201 bind_map
.sampler_to_descriptor
= (void *)
202 blob_read_bytes(blob
, bind_map
.sampler_count
*
203 sizeof(*bind_map
.sampler_to_descriptor
));
208 return anv_shader_bin_create(device
,
210 kernel_data
, kernel_size
,
211 constant_data
, constant_data_size
,
212 prog_data
, prog_data_size
, prog_data_param
,
213 xfb_info
, &bind_map
);
218 * - Compact binding table layout so it's tight and not dependent on
219 * descriptor set layout.
221 * - Review prog_data struct for size and cacheability: struct
222 * brw_stage_prog_data has binding_table which uses a lot of uint32_t for 8
223 * bit quantities etc; use bit fields for all bools, eg dual_src_blend.
227 shader_bin_key_hash_func(const void *void_key
)
229 const struct anv_shader_bin_key
*key
= void_key
;
230 return _mesa_hash_data(key
->data
, key
->size
);
234 shader_bin_key_compare_func(const void *void_a
, const void *void_b
)
236 const struct anv_shader_bin_key
*a
= void_a
, *b
= void_b
;
237 if (a
->size
!= b
->size
)
240 return memcmp(a
->data
, b
->data
, a
->size
) == 0;
244 sha1_hash_func(const void *sha1
)
246 return _mesa_hash_data(sha1
, 20);
250 sha1_compare_func(const void *sha1_a
, const void *sha1_b
)
252 return memcmp(sha1_a
, sha1_b
, 20) == 0;
256 anv_pipeline_cache_init(struct anv_pipeline_cache
*cache
,
257 struct anv_device
*device
,
260 cache
->device
= device
;
261 pthread_mutex_init(&cache
->mutex
, NULL
);
264 cache
->cache
= _mesa_hash_table_create(NULL
, shader_bin_key_hash_func
,
265 shader_bin_key_compare_func
);
266 cache
->nir_cache
= _mesa_hash_table_create(NULL
, sha1_hash_func
,
270 cache
->nir_cache
= NULL
;
275 anv_pipeline_cache_finish(struct anv_pipeline_cache
*cache
)
277 pthread_mutex_destroy(&cache
->mutex
);
280 /* This is a bit unfortunate. In order to keep things from randomly
281 * going away, the shader cache has to hold a reference to all shader
282 * binaries it contains. We unref them when we destroy the cache.
284 hash_table_foreach(cache
->cache
, entry
)
285 anv_shader_bin_unref(cache
->device
, entry
->data
);
287 _mesa_hash_table_destroy(cache
->cache
, NULL
);
290 if (cache
->nir_cache
) {
291 hash_table_foreach(cache
->nir_cache
, entry
)
292 ralloc_free(entry
->data
);
294 _mesa_hash_table_destroy(cache
->nir_cache
, NULL
);
298 static struct anv_shader_bin
*
299 anv_pipeline_cache_search_locked(struct anv_pipeline_cache
*cache
,
300 const void *key_data
, uint32_t key_size
)
302 uint32_t vla
[1 + DIV_ROUND_UP(key_size
, sizeof(uint32_t))];
303 struct anv_shader_bin_key
*key
= (void *)vla
;
304 key
->size
= key_size
;
305 memcpy(key
->data
, key_data
, key_size
);
307 struct hash_entry
*entry
= _mesa_hash_table_search(cache
->cache
, key
);
314 struct anv_shader_bin
*
315 anv_pipeline_cache_search(struct anv_pipeline_cache
*cache
,
316 const void *key_data
, uint32_t key_size
)
321 pthread_mutex_lock(&cache
->mutex
);
323 struct anv_shader_bin
*shader
=
324 anv_pipeline_cache_search_locked(cache
, key_data
, key_size
);
326 pthread_mutex_unlock(&cache
->mutex
);
328 /* We increment refcount before handing it to the caller */
330 anv_shader_bin_ref(shader
);
336 anv_pipeline_cache_add_shader_bin(struct anv_pipeline_cache
*cache
,
337 struct anv_shader_bin
*bin
)
342 pthread_mutex_lock(&cache
->mutex
);
344 struct hash_entry
*entry
= _mesa_hash_table_search(cache
->cache
, bin
->key
);
346 /* Take a reference for the cache */
347 anv_shader_bin_ref(bin
);
348 _mesa_hash_table_insert(cache
->cache
, bin
->key
, bin
);
351 pthread_mutex_unlock(&cache
->mutex
);
354 static struct anv_shader_bin
*
355 anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache
*cache
,
356 const void *key_data
, uint32_t key_size
,
357 const void *kernel_data
,
358 uint32_t kernel_size
,
359 const void *constant_data
,
360 uint32_t constant_data_size
,
361 const struct brw_stage_prog_data
*prog_data
,
362 uint32_t prog_data_size
,
363 const void *prog_data_param
,
364 const nir_xfb_info
*xfb_info
,
365 const struct anv_pipeline_bind_map
*bind_map
)
367 struct anv_shader_bin
*shader
=
368 anv_pipeline_cache_search_locked(cache
, key_data
, key_size
);
372 struct anv_shader_bin
*bin
=
373 anv_shader_bin_create(cache
->device
, key_data
, key_size
,
374 kernel_data
, kernel_size
,
375 constant_data
, constant_data_size
,
376 prog_data
, prog_data_size
, prog_data_param
,
381 _mesa_hash_table_insert(cache
->cache
, bin
->key
, bin
);
386 struct anv_shader_bin
*
387 anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache
*cache
,
388 const void *key_data
, uint32_t key_size
,
389 const void *kernel_data
, uint32_t kernel_size
,
390 const void *constant_data
,
391 uint32_t constant_data_size
,
392 const struct brw_stage_prog_data
*prog_data
,
393 uint32_t prog_data_size
,
394 const nir_xfb_info
*xfb_info
,
395 const struct anv_pipeline_bind_map
*bind_map
)
398 pthread_mutex_lock(&cache
->mutex
);
400 struct anv_shader_bin
*bin
=
401 anv_pipeline_cache_add_shader_locked(cache
, key_data
, key_size
,
402 kernel_data
, kernel_size
,
403 constant_data
, constant_data_size
,
404 prog_data
, prog_data_size
,
408 pthread_mutex_unlock(&cache
->mutex
);
410 /* We increment refcount before handing it to the caller */
412 anv_shader_bin_ref(bin
);
416 /* In this case, we're not caching it so the caller owns it entirely */
417 return anv_shader_bin_create(cache
->device
, key_data
, key_size
,
418 kernel_data
, kernel_size
,
419 constant_data
, constant_data_size
,
420 prog_data
, prog_data_size
,
426 struct cache_header
{
427 uint32_t header_size
;
428 uint32_t header_version
;
431 uint8_t uuid
[VK_UUID_SIZE
];
435 anv_pipeline_cache_load(struct anv_pipeline_cache
*cache
,
436 const void *data
, size_t size
)
438 struct anv_device
*device
= cache
->device
;
439 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
441 if (cache
->cache
== NULL
)
444 struct blob_reader blob
;
445 blob_reader_init(&blob
, data
, size
);
447 struct cache_header header
;
448 blob_copy_bytes(&blob
, &header
, sizeof(header
));
449 uint32_t count
= blob_read_uint32(&blob
);
453 if (header
.header_size
< sizeof(header
))
455 if (header
.header_version
!= VK_PIPELINE_CACHE_HEADER_VERSION_ONE
)
457 if (header
.vendor_id
!= 0x8086)
459 if (header
.device_id
!= device
->chipset_id
)
461 if (memcmp(header
.uuid
, pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
) != 0)
464 for (uint32_t i
= 0; i
< count
; i
++) {
465 struct anv_shader_bin
*bin
=
466 anv_shader_bin_create_from_blob(device
, &blob
);
469 _mesa_hash_table_insert(cache
->cache
, bin
->key
, bin
);
473 VkResult
anv_CreatePipelineCache(
475 const VkPipelineCacheCreateInfo
* pCreateInfo
,
476 const VkAllocationCallbacks
* pAllocator
,
477 VkPipelineCache
* pPipelineCache
)
479 ANV_FROM_HANDLE(anv_device
, device
, _device
);
480 struct anv_pipeline_cache
*cache
;
482 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
);
483 assert(pCreateInfo
->flags
== 0);
485 cache
= vk_alloc2(&device
->alloc
, pAllocator
,
487 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
489 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
491 anv_pipeline_cache_init(cache
, device
,
492 device
->instance
->pipeline_cache_enabled
);
494 if (pCreateInfo
->initialDataSize
> 0)
495 anv_pipeline_cache_load(cache
,
496 pCreateInfo
->pInitialData
,
497 pCreateInfo
->initialDataSize
);
499 *pPipelineCache
= anv_pipeline_cache_to_handle(cache
);
504 void anv_DestroyPipelineCache(
506 VkPipelineCache _cache
,
507 const VkAllocationCallbacks
* pAllocator
)
509 ANV_FROM_HANDLE(anv_device
, device
, _device
);
510 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
515 anv_pipeline_cache_finish(cache
);
517 vk_free2(&device
->alloc
, pAllocator
, cache
);
520 VkResult
anv_GetPipelineCacheData(
522 VkPipelineCache _cache
,
526 ANV_FROM_HANDLE(anv_device
, device
, _device
);
527 ANV_FROM_HANDLE(anv_pipeline_cache
, cache
, _cache
);
528 struct anv_physical_device
*pdevice
= &device
->instance
->physicalDevice
;
532 blob_init_fixed(&blob
, pData
, *pDataSize
);
534 blob_init_fixed(&blob
, NULL
, SIZE_MAX
);
537 struct cache_header header
= {
538 .header_size
= sizeof(struct cache_header
),
539 .header_version
= VK_PIPELINE_CACHE_HEADER_VERSION_ONE
,
541 .device_id
= device
->chipset_id
,
543 memcpy(header
.uuid
, pdevice
->pipeline_cache_uuid
, VK_UUID_SIZE
);
544 blob_write_bytes(&blob
, &header
, sizeof(header
));
547 intptr_t count_offset
= blob_reserve_uint32(&blob
);
548 if (count_offset
< 0) {
551 return VK_INCOMPLETE
;
554 VkResult result
= VK_SUCCESS
;
556 hash_table_foreach(cache
->cache
, entry
) {
557 struct anv_shader_bin
*shader
= entry
->data
;
559 size_t save_size
= blob
.size
;
560 if (!anv_shader_bin_write_to_blob(shader
, &blob
)) {
561 /* If it fails reset to the previous size and bail */
562 blob
.size
= save_size
;
563 result
= VK_INCOMPLETE
;
571 blob_overwrite_uint32(&blob
, count_offset
, count
);
573 *pDataSize
= blob
.size
;
580 VkResult
anv_MergePipelineCaches(
582 VkPipelineCache destCache
,
583 uint32_t srcCacheCount
,
584 const VkPipelineCache
* pSrcCaches
)
586 ANV_FROM_HANDLE(anv_pipeline_cache
, dst
, destCache
);
591 for (uint32_t i
= 0; i
< srcCacheCount
; i
++) {
592 ANV_FROM_HANDLE(anv_pipeline_cache
, src
, pSrcCaches
[i
]);
596 hash_table_foreach(src
->cache
, entry
) {
597 struct anv_shader_bin
*bin
= entry
->data
;
600 if (_mesa_hash_table_search(dst
->cache
, bin
->key
))
603 anv_shader_bin_ref(bin
);
604 _mesa_hash_table_insert(dst
->cache
, bin
->key
, bin
);
611 struct anv_shader_bin
*
612 anv_device_search_for_kernel(struct anv_device
*device
,
613 struct anv_pipeline_cache
*cache
,
614 const void *key_data
, uint32_t key_size
)
616 struct anv_shader_bin
*bin
;
619 bin
= anv_pipeline_cache_search(cache
, key_data
, key_size
);
624 #ifdef ENABLE_SHADER_CACHE
625 struct disk_cache
*disk_cache
= device
->instance
->physicalDevice
.disk_cache
;
626 if (disk_cache
&& device
->instance
->pipeline_cache_enabled
) {
628 disk_cache_compute_key(disk_cache
, key_data
, key_size
, cache_key
);
631 uint8_t *buffer
= disk_cache_get(disk_cache
, cache_key
, &buffer_size
);
633 struct blob_reader blob
;
634 blob_reader_init(&blob
, buffer
, buffer_size
);
635 bin
= anv_shader_bin_create_from_blob(device
, &blob
);
640 anv_pipeline_cache_add_shader_bin(cache
, bin
);
650 struct anv_shader_bin
*
651 anv_device_upload_kernel(struct anv_device
*device
,
652 struct anv_pipeline_cache
*cache
,
653 const void *key_data
, uint32_t key_size
,
654 const void *kernel_data
, uint32_t kernel_size
,
655 const void *constant_data
,
656 uint32_t constant_data_size
,
657 const struct brw_stage_prog_data
*prog_data
,
658 uint32_t prog_data_size
,
659 const nir_xfb_info
*xfb_info
,
660 const struct anv_pipeline_bind_map
*bind_map
)
662 struct anv_shader_bin
*bin
;
664 bin
= anv_pipeline_cache_upload_kernel(cache
, key_data
, key_size
,
665 kernel_data
, kernel_size
,
666 constant_data
, constant_data_size
,
667 prog_data
, prog_data_size
,
670 bin
= anv_shader_bin_create(device
, key_data
, key_size
,
671 kernel_data
, kernel_size
,
672 constant_data
, constant_data_size
,
673 prog_data
, prog_data_size
,
681 #ifdef ENABLE_SHADER_CACHE
682 struct disk_cache
*disk_cache
= device
->instance
->physicalDevice
.disk_cache
;
686 if (anv_shader_bin_write_to_blob(bin
, &binary
)) {
688 disk_cache_compute_key(disk_cache
, key_data
, key_size
, cache_key
);
690 disk_cache_put(disk_cache
, cache_key
, binary
.data
, binary
.size
, NULL
);
693 blob_finish(&binary
);
700 struct serialized_nir
{
701 unsigned char sha1_key
[20];
707 anv_device_search_for_nir(struct anv_device
*device
,
708 struct anv_pipeline_cache
*cache
,
709 const nir_shader_compiler_options
*nir_options
,
710 unsigned char sha1_key
[20],
713 if (cache
&& cache
->nir_cache
) {
714 const struct serialized_nir
*snir
= NULL
;
716 pthread_mutex_lock(&cache
->mutex
);
717 struct hash_entry
*entry
=
718 _mesa_hash_table_search(cache
->nir_cache
, sha1_key
);
721 pthread_mutex_unlock(&cache
->mutex
);
724 struct blob_reader blob
;
725 blob_reader_init(&blob
, snir
->data
, snir
->size
);
727 nir_shader
*nir
= nir_deserialize(mem_ctx
, nir_options
, &blob
);
740 anv_device_upload_nir(struct anv_device
*device
,
741 struct anv_pipeline_cache
*cache
,
742 const struct nir_shader
*nir
,
743 unsigned char sha1_key
[20])
745 if (cache
&& cache
->nir_cache
) {
746 pthread_mutex_lock(&cache
->mutex
);
747 struct hash_entry
*entry
=
748 _mesa_hash_table_search(cache
->nir_cache
, sha1_key
);
749 pthread_mutex_unlock(&cache
->mutex
);
756 nir_serialize(&blob
, nir
);
757 if (blob
.out_of_memory
) {
762 pthread_mutex_lock(&cache
->mutex
);
763 /* Because ralloc isn't thread-safe, we have to do all this inside the
764 * lock. We could unlock for the big memcpy but it's probably not worth
767 entry
= _mesa_hash_table_search(cache
->nir_cache
, sha1_key
);
770 pthread_mutex_unlock(&cache
->mutex
);
774 struct serialized_nir
*snir
=
775 ralloc_size(cache
->nir_cache
, sizeof(*snir
) + blob
.size
);
776 memcpy(snir
->sha1_key
, sha1_key
, 20);
777 snir
->size
= blob
.size
;
778 memcpy(snir
->data
, blob
.data
, blob
.size
);
782 _mesa_hash_table_insert(cache
->nir_cache
, snir
->sha1_key
, snir
);
784 pthread_mutex_unlock(&cache
->mutex
);