aboutsummaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan/radv_pipeline_cache.c
diff options
context:
space:
mode:
authorBas Nieuwenhuizen <[email protected]>2019-07-01 01:29:24 +0200
committerBas Nieuwenhuizen <[email protected]>2019-07-04 10:52:26 +0000
commit726a31df705bba61b91152a84bd0abaea8418768 (patch)
tree5cce8b2fab02ddb0bea3ea43bceca6d45d83331a /src/amd/vulkan/radv_pipeline_cache.c
parent43f2f01cc89def665bd0e33f9ad689825b85e977 (diff)
radv: Add the concept of radv shader binaries.
This simplifies a bunch of stuff by (1) Keeping all the things in a single allocation, making things easier for the cache. (2) creating a shader_variant creation helper. This is immediately put to use by creating rtld shader binaries. This is the main reason for the binaries, as we need to do the linking at upload time, i.e. post caching. We do not enable rtld yet. Reviewed-by: Samuel Pitoiset <[email protected]>
Diffstat (limited to 'src/amd/vulkan/radv_pipeline_cache.c')
-rw-r--r--src/amd/vulkan/radv_pipeline_cache.c62
1 files changed, 16 insertions, 46 deletions
diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
index a506711898a..2b3fda6eb8e 100644
--- a/src/amd/vulkan/radv_pipeline_cache.c
+++ b/src/amd/vulkan/radv_pipeline_cache.c
@@ -31,17 +31,12 @@
#include "ac_nir_to_llvm.h"
-struct cache_entry_variant_info {
- struct radv_shader_variant_info variant_info;
- struct ac_shader_config config;
-};
-
struct cache_entry {
union {
unsigned char sha1[20];
uint32_t sha1_dw[5];
};
- uint32_t code_sizes[MESA_SHADER_STAGES];
+ uint32_t binary_sizes[MESA_SHADER_STAGES];
struct radv_shader_variant *variants[MESA_SHADER_STAGES];
char code[0];
};
@@ -92,8 +87,8 @@ entry_size(struct cache_entry *entry)
{
size_t ret = sizeof(*entry);
for (int i = 0; i < MESA_SHADER_STAGES; ++i)
- if (entry->code_sizes[i])
- ret += sizeof(struct cache_entry_variant_info) + entry->code_sizes[i];
+ if (entry->binary_sizes[i])
+ ret += entry->binary_sizes[i];
return ret;
}
@@ -308,31 +303,14 @@ radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
char *p = entry->code;
for(int i = 0; i < MESA_SHADER_STAGES; ++i) {
- if (!entry->variants[i] && entry->code_sizes[i]) {
- struct radv_shader_variant *variant;
- struct cache_entry_variant_info info;
-
- variant = calloc(1, sizeof(struct radv_shader_variant));
- if (!variant) {
- pthread_mutex_unlock(&cache->mutex);
- return false;
- }
-
- memcpy(&info, p, sizeof(struct cache_entry_variant_info));
- p += sizeof(struct cache_entry_variant_info);
-
- variant->config = info.config;
- variant->info = info.variant_info;
- variant->code_size = entry->code_sizes[i];
- variant->ref_count = 1;
-
- void *ptr = radv_alloc_shader_memory(device, variant);
- memcpy(ptr, p, entry->code_sizes[i]);
- p += entry->code_sizes[i];
-
- entry->variants[i] = variant;
- } else if (entry->code_sizes[i]) {
- p += sizeof(struct cache_entry_variant_info) + entry->code_sizes[i];
+ if (!entry->variants[i] && entry->binary_sizes[i]) {
+ struct radv_shader_binary *binary = calloc(1, entry->binary_sizes[i]);
+ memcpy(binary, p, entry->binary_sizes[i]);
+ p += entry->binary_sizes[i];
+
+ entry->variants[i] = radv_shader_variant_create(device, binary);
+ } else if (entry->binary_sizes[i]) {
+ p += entry->binary_sizes[i];
}
}
@@ -351,8 +329,7 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device,
struct radv_pipeline_cache *cache,
const unsigned char *sha1,
struct radv_shader_variant **variants,
- const void *const *codes,
- const unsigned *code_sizes)
+ struct radv_shader_binary *const *binaries)
{
if (!cache)
cache = device->mem_cache;
@@ -385,7 +362,7 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device,
size_t size = sizeof(*entry);
for (int i = 0; i < MESA_SHADER_STAGES; ++i)
if (variants[i])
- size += sizeof(struct cache_entry_variant_info) + code_sizes[i];
+ size += binaries[i]->total_size;
entry = vk_alloc(&cache->alloc, size, 8,
@@ -399,22 +376,15 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device,
memcpy(entry->sha1, sha1, 20);
char* p = entry->code;
- struct cache_entry_variant_info info;
- memset(&info, 0, sizeof(info));
for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
if (!variants[i])
continue;
- entry->code_sizes[i] = code_sizes[i];
-
- info.config = variants[i]->config;
- info.variant_info = variants[i]->info;
- memcpy(p, &info, sizeof(struct cache_entry_variant_info));
- p += sizeof(struct cache_entry_variant_info);
+ entry->binary_sizes[i] = binaries[i]->total_size;
- memcpy(p, codes[i], code_sizes[i]);
- p += code_sizes[i];
+ memcpy(p, binaries[i], binaries[i]->total_size);
+ p += binaries[i]->total_size;
}
/* Always add cache items to disk. This will allow collection of