#include "util/mesa-sha1.h"
#include "util/debug.h"
+#include "util/u_atomic.h"
+#include "radv_debug.h"
#include "radv_private.h"
#include "ac_nir_to_llvm.h"
/* We don't consider allocation failure fatal, we just start with a 0-sized
* cache. */
if (cache->hash_table == NULL ||
- !env_var_as_boolean("RADV_ENABLE_PIPELINE_CACHE", true))
+ (device->debug_flags & RADV_DEBUG_NO_CACHE))
cache->table_size = 0;
else
memset(cache->hash_table, 0, byte_size);
if (cache->hash_table[i]->variant)
radv_shader_variant_destroy(cache->device,
cache->hash_table[i]->variant);
- radv_free(&cache->alloc, cache->hash_table[i]);
+ vk_free(&cache->alloc, cache->hash_table[i]);
}
pthread_mutex_destroy(&cache->mutex);
free(cache->hash_table);
const char *entrypoint,
const VkSpecializationInfo *spec_info,
const struct radv_pipeline_layout *layout,
- const union ac_shader_variant_key *key)
+ const struct ac_shader_variant_key *key,
+ uint32_t is_geom_copy_shader)
{
- struct mesa_sha1 *ctx;
+ struct mesa_sha1 ctx;
- ctx = _mesa_sha1_init();
+ _mesa_sha1_init(&ctx);
if (key)
- _mesa_sha1_update(ctx, key, sizeof(*key));
- _mesa_sha1_update(ctx, module->sha1, sizeof(module->sha1));
- _mesa_sha1_update(ctx, entrypoint, strlen(entrypoint));
+ _mesa_sha1_update(&ctx, key, sizeof(*key));
+ _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
+ _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
if (layout)
- _mesa_sha1_update(ctx, layout->sha1, sizeof(layout->sha1));
+ _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
if (spec_info) {
- _mesa_sha1_update(ctx, spec_info->pMapEntries,
+ _mesa_sha1_update(&ctx, spec_info->pMapEntries,
spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]);
- _mesa_sha1_update(ctx, spec_info->pData, spec_info->dataSize);
+ _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize);
}
- _mesa_sha1_final(ctx, hash);
+ _mesa_sha1_update(&ctx, &is_geom_copy_shader, 4);
+ _mesa_sha1_final(&ctx, hash);
}
const uint32_t mask = cache->table_size - 1;
const uint32_t start = (*(uint32_t *) sha1);
+ if (cache->table_size == 0)
+ return NULL;
+
for (uint32_t i = 0; i < cache->table_size; i++) {
const uint32_t index = (start + i) & mask;
struct cache_entry *entry = cache->hash_table[index];
struct radv_pipeline_cache *cache,
const unsigned char *sha1)
{
- struct cache_entry *entry = radv_pipeline_cache_search(cache, sha1);
+ struct cache_entry *entry = NULL;
+
+ if (cache)
+ entry = radv_pipeline_cache_search(cache, sha1);
if (!entry)
return NULL;
if (!variant)
return NULL;
+ variant->code_size = entry->code_size;
variant->config = entry->config;
variant->info = entry->variant_info;
variant->rsrc1 = entry->rsrc1;
variant->rsrc2 = entry->rsrc2;
+ variant->code_size = entry->code_size;
variant->ref_count = 1;
- variant->bo = device->ws->buffer_create(device->ws, entry->code_size, 256,
- RADEON_DOMAIN_GTT, RADEON_FLAG_CPU_ACCESS);
-
- void *ptr = device->ws->buffer_map(variant->bo);
+ void *ptr = radv_alloc_shader_memory(device, variant);
memcpy(ptr, entry->code, entry->code_size);
- device->ws->buffer_unmap(variant->bo);
entry->variant = variant;
}
- __sync_fetch_and_add(&entry->variant->ref_count, 1);
+ p_atomic_inc(&entry->variant->ref_count);
return entry->variant;
}
struct radv_shader_variant *variant,
const void *code, unsigned code_size)
{
+ if (!cache)
+ return variant;
+
pthread_mutex_lock(&cache->mutex);
struct cache_entry *entry = radv_pipeline_cache_search_unlocked(cache, sha1);
if (entry) {
} else {
entry->variant = variant;
}
- __sync_fetch_and_add(&variant->ref_count, 1);
+ p_atomic_inc(&variant->ref_count);
pthread_mutex_unlock(&cache->mutex);
return variant;
}
- entry = radv_alloc(&cache->alloc, sizeof(*entry) + code_size, 8,
+ entry = vk_alloc(&cache->alloc, sizeof(*entry) + code_size, 8,
VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
if (!entry) {
pthread_mutex_unlock(&cache->mutex);
entry->rsrc2 = variant->rsrc2;
entry->code_size = code_size;
entry->variant = variant;
- __sync_fetch_and_add(&variant->ref_count, 1);
+ p_atomic_inc(&variant->ref_count);
radv_pipeline_cache_add_entry(cache, entry);
uint32_t device_id;
uint8_t uuid[VK_UUID_SIZE];
};
+
void
radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
const void *data, size_t size)
{
struct radv_device *device = cache->device;
struct cache_header header;
- uint8_t uuid[VK_UUID_SIZE];
if (size < sizeof(header))
return;
return;
if (header.vendor_id != 0x1002)
return;
- if (header.device_id != device->instance->physicalDevice.rad_info.pci_id)
+ if (header.device_id != device->physical_device->rad_info.pci_id)
return;
- radv_device_get_cache_uuid(uuid);
- if (memcmp(header.uuid, uuid, VK_UUID_SIZE) != 0)
+ if (memcmp(header.uuid, device->physical_device->cache_uuid, VK_UUID_SIZE) != 0)
return;
char *end = (void *) data + size;
if(end - p < sizeof(*entry) + entry->code_size)
break;
- dest_entry = radv_alloc(&cache->alloc, sizeof(*entry) + entry->code_size,
+ dest_entry = vk_alloc(&cache->alloc, sizeof(*entry) + entry->code_size,
8, VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
if (dest_entry) {
memcpy(dest_entry, entry, sizeof(*entry) + entry->code_size);
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO);
assert(pCreateInfo->flags == 0);
- cache = radv_alloc2(&device->alloc, pAllocator,
+ cache = vk_alloc2(&device->alloc, pAllocator,
sizeof(*cache), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (cache == NULL)
return;
radv_pipeline_cache_finish(cache);
- radv_free2(&device->alloc, pAllocator, cache);
+ vk_free2(&device->alloc, pAllocator, cache);
}
VkResult radv_GetPipelineCacheData(
header->header_size = sizeof(*header);
header->header_version = VK_PIPELINE_CACHE_HEADER_VERSION_ONE;
header->vendor_id = 0x1002;
- header->device_id = device->instance->physicalDevice.rad_info.pci_id;
- radv_device_get_cache_uuid(header->uuid);
+ header->device_id = device->physical_device->rad_info.pci_id;
+ memcpy(header->uuid, device->physical_device->cache_uuid, VK_UUID_SIZE);
p += header->header_size;
struct cache_entry *entry;