* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
*/
#include "tu_private.h"
+
#include "util/debug.h"
#include "util/disk_cache.h"
#include "util/mesa-sha1.h"
struct cache_entry
{
- union
- {
+ union {
unsigned char sha1[20];
uint32_t sha1_dw[5];
};
char code[0];
};
-void
+static void
tu_pipeline_cache_init(struct tu_pipeline_cache *cache,
- struct tu_device *device)
+ struct tu_device *device)
{
cache->device = device;
pthread_mutex_init(&cache->mutex, NULL);
memset(cache->hash_table, 0, byte_size);
}
-void
+static void
tu_pipeline_cache_finish(struct tu_pipeline_cache *cache)
{
for (unsigned i = 0; i < cache->table_size; ++i)
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];
+ ret +=
+ sizeof(struct cache_entry_variant_info) + entry->code_sizes[i];
return ret;
}
-void
-tu_hash_shaders(unsigned char *hash,
- const VkPipelineShaderStageCreateInfo **stages,
- const struct tu_pipeline_layout *layout,
- const struct tu_pipeline_key *key,
- uint32_t flags)
-{
- struct mesa_sha1 ctx;
-
- _mesa_sha1_init(&ctx);
- if (key)
- _mesa_sha1_update(&ctx, key, sizeof(*key));
- if (layout)
- _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
-
- for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
- if (stages[i]) {
- TU_FROM_HANDLE(tu_shader_module, module, stages[i]->module);
- const VkSpecializationInfo *spec_info = stages[i]->pSpecializationInfo;
-
- _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
- _mesa_sha1_update(&ctx, stages[i]->pName, strlen(stages[i]->pName));
- if (spec_info) {
- _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, &flags, 4);
- _mesa_sha1_final(&ctx, hash);
-}
-
static struct cache_entry *
tu_pipeline_cache_search_unlocked(struct tu_pipeline_cache *cache,
- const unsigned char *sha1)
+ const unsigned char *sha1)
{
const uint32_t mask = cache->table_size - 1;
- const uint32_t start = (*(uint32_t *)sha1);
+ const uint32_t start = (*(uint32_t *) sha1);
if (cache->table_size == 0)
return NULL;
static struct cache_entry *
tu_pipeline_cache_search(struct tu_pipeline_cache *cache,
- const unsigned char *sha1)
+ const unsigned char *sha1)
{
struct cache_entry *entry;
static void
tu_pipeline_cache_set_entry(struct tu_pipeline_cache *cache,
- struct cache_entry *entry)
+ struct cache_entry *entry)
{
const uint32_t mask = cache->table_size - 1;
const uint32_t start = entry->sha1_dw[0];
static void
tu_pipeline_cache_add_entry(struct tu_pipeline_cache *cache,
- struct cache_entry *entry)
+ struct cache_entry *entry)
{
if (cache->kernel_count == cache->table_size / 2)
tu_pipeline_cache_grow(cache);
uint8_t uuid[VK_UUID_SIZE];
};
-void
+static void
tu_pipeline_cache_load(struct tu_pipeline_cache *cache,
- const void *data,
- size_t size)
+ const void *data,
+ size_t size)
{
struct tu_device *device = cache->device;
struct cache_header header;
return;
if (header.device_id != 0 /* TODO */)
return;
- if (memcmp(header.uuid, device->physical_device->cache_uuid, VK_UUID_SIZE) !=
- 0)
+ if (memcmp(header.uuid, device->physical_device->cache_uuid,
+ VK_UUID_SIZE) != 0)
return;
- char *end = (void *)data + size;
- char *p = (void *)data + header.header_size;
+ char *end = (void *) data + size;
+ char *p = (void *) data + header.header_size;
while (end - p >= sizeof(struct cache_entry)) {
- struct cache_entry *entry = (struct cache_entry *)p;
+ struct cache_entry *entry = (struct cache_entry *) p;
struct cache_entry *dest_entry;
size_t size = entry_size(entry);
if (end - p < size)
break;
dest_entry =
- vk_alloc(&cache->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
+ vk_alloc(&cache->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_CACHE);
if (dest_entry) {
memcpy(dest_entry, entry, size);
for (int i = 0; i < MESA_SHADER_STAGES; ++i)
VkResult
tu_CreatePipelineCache(VkDevice _device,
- const VkPipelineCacheCreateInfo *pCreateInfo,
- const VkAllocationCallbacks *pAllocator,
- VkPipelineCache *pPipelineCache)
+ const VkPipelineCacheCreateInfo *pCreateInfo,
+ const VkAllocationCallbacks *pAllocator,
+ VkPipelineCache *pPipelineCache)
{
TU_FROM_HANDLE(tu_device, device, _device);
struct tu_pipeline_cache *cache;
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO);
assert(pCreateInfo->flags == 0);
- cache = vk_alloc2(&device->alloc,
- pAllocator,
- sizeof(*cache),
- 8,
+ cache = vk_alloc2(&device->alloc, pAllocator, sizeof(*cache), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (cache == NULL)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
tu_pipeline_cache_init(cache, device);
if (pCreateInfo->initialDataSize > 0) {
- tu_pipeline_cache_load(
- cache, pCreateInfo->pInitialData, pCreateInfo->initialDataSize);
+ tu_pipeline_cache_load(cache, pCreateInfo->pInitialData,
+ pCreateInfo->initialDataSize);
}
*pPipelineCache = tu_pipeline_cache_to_handle(cache);
void
tu_DestroyPipelineCache(VkDevice _device,
- VkPipelineCache _cache,
- const VkAllocationCallbacks *pAllocator)
+ VkPipelineCache _cache,
+ const VkAllocationCallbacks *pAllocator)
{
TU_FROM_HANDLE(tu_device, device, _device);
TU_FROM_HANDLE(tu_pipeline_cache, cache, _cache);
VkResult
tu_GetPipelineCacheData(VkDevice _device,
- VkPipelineCache _cache,
- size_t *pDataSize,
- void *pData)
+ VkPipelineCache _cache,
+ size_t *pDataSize,
+ void *pData)
{
TU_FROM_HANDLE(tu_device, device, _device);
TU_FROM_HANDLE(tu_pipeline_cache, cache, _cache);
memcpy(p, entry, size);
for (int j = 0; j < MESA_SHADER_STAGES; ++j)
- ((struct cache_entry *)p)->variants[j] = NULL;
+ ((struct cache_entry *) p)->variants[j] = NULL;
p += size;
}
*pDataSize = p - pData;
static void
tu_pipeline_cache_merge(struct tu_pipeline_cache *dst,
- struct tu_pipeline_cache *src)
+ struct tu_pipeline_cache *src)
{
for (uint32_t i = 0; i < src->table_size; i++) {
struct cache_entry *entry = src->hash_table[i];
VkResult
tu_MergePipelineCaches(VkDevice _device,
- VkPipelineCache destCache,
- uint32_t srcCacheCount,
- const VkPipelineCache *pSrcCaches)
+ VkPipelineCache destCache,
+ uint32_t srcCacheCount,
+ const VkPipelineCache *pSrcCaches)
{
TU_FROM_HANDLE(tu_pipeline_cache, dst, destCache);