/* kernel follows prog_data at next 64 byte aligned address */
};
+static uint32_t
+entry_size(struct cache_entry *entry)
+{
+ /* This returns the number of bytes needed to serialize an entry, which
+ * doesn't include the alignment padding bytes.
+ */
+
+ return sizeof(*entry) + entry->prog_data_size + entry->kernel_size;
+}
+
void
anv_hash_shader(unsigned char *hash, const void *key, size_t key_size,
struct anv_shader_module *module,
}
}
- /* We don't include the alignment padding bytes when we serialize, so
- * don't include taht in the the total size. */
- cache->total_size +=
- sizeof(*entry) + entry->prog_data_size + entry->kernel_size;
+ cache->total_size += entry_size(entry);
cache->kernel_count++;
}
return VK_SUCCESS;
}
- if (*pDataSize < size) {
+ if (*pDataSize < sizeof(*header)) {
*pDataSize = 0;
return VK_INCOMPLETE;
}
- void *p = pData;
+ void *p = pData, *end = pData + *pDataSize;
header = p;
header->header_size = sizeof(*header);
header->header_version = VK_PIPELINE_CACHE_HEADER_VERSION_ONE;
continue;
entry = cache->program_stream.block_pool->map + cache->table[i];
+ if (end < p + entry_size(entry))
+ break;
memcpy(p, entry, sizeof(*entry) + entry->prog_data_size);
p += sizeof(*entry) + entry->prog_data_size;
p += entry->kernel_size;
}
+ *pDataSize = p - pData;
+
return VK_SUCCESS;
}