It is not necessary to store the extra pointer.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21967>
struct blob_reader *blob);
static void
-tu_shaders_destroy(struct vk_pipeline_cache_object *object)
+tu_shaders_destroy(struct vk_device *device,
+ struct vk_pipeline_cache_object *object)
{
struct tu_compiled_shaders *shaders =
container_of(object, struct tu_compiled_shaders, base);
ralloc_free(shaders->safe_const_variants[i]);
vk_pipeline_cache_object_finish(&shaders->base);
- vk_free(&object->device->alloc, shaders);
+ vk_free(&device->alloc, shaders);
}
const struct vk_pipeline_cache_object_ops tu_shaders_ops = {
struct blob_reader *blob);
static void
-tu_nir_shaders_destroy(struct vk_pipeline_cache_object *object)
+tu_nir_shaders_destroy(struct vk_device *device,
+ struct vk_pipeline_cache_object *object)
{
struct tu_nir_shaders *shaders =
container_of(object, struct tu_nir_shaders, base);
ralloc_free(shaders->nir[i]);
vk_pipeline_cache_object_finish(&shaders->base);
- vk_free(&object->device->alloc, shaders);
+ vk_free(&device->alloc, shaders);
}
const struct vk_pipeline_cache_object_ops tu_nir_shaders_ops = {
* when compiling all stages, but make sure we don't leak.
*/
if (nir_shaders)
- vk_pipeline_cache_object_unref(&nir_shaders->base);
+ vk_pipeline_cache_object_unref(&builder->device->vk,
+ &nir_shaders->base);
} else {
pipeline->compiled_shaders = compiled_shaders;
pipeline->nir_shaders = nir_shaders;
}
if (compiled_shaders)
- vk_pipeline_cache_object_unref(&compiled_shaders->base);
+ vk_pipeline_cache_object_unref(&builder->device->vk,
+ &compiled_shaders->base);
if (nir_shaders)
- vk_pipeline_cache_object_unref(&nir_shaders->base);
+ vk_pipeline_cache_object_unref(&builder->device->vk,
+ &nir_shaders->base);
return result;
}
tu_bo_finish(dev, pipeline->pvtmem_bo);
if (pipeline->compiled_shaders)
- vk_pipeline_cache_object_unref(&pipeline->compiled_shaders->base);
+ vk_pipeline_cache_object_unref(&dev->vk,
+ &pipeline->compiled_shaders->base);
if (pipeline->nir_shaders)
- vk_pipeline_cache_object_unref(&pipeline->nir_shaders->base);
+ vk_pipeline_cache_object_unref(&dev->vk, &pipeline->nir_shaders->base);
for (unsigned i = 0; i < pipeline->num_sets; i++) {
if (pipeline->layouts[i])
tu_pipeline_builder_finish(struct tu_pipeline_builder *builder)
{
if (builder->compiled_shaders)
- vk_pipeline_cache_object_unref(&builder->compiled_shaders->base);
+ vk_pipeline_cache_object_unref(&builder->device->vk,
+ &builder->compiled_shaders->base);
ralloc_free(builder->mem_ctx);
}
pipeline->program.cs_instrlen = v->instrlen;
- vk_pipeline_cache_object_unref(&compiled->base);
+ vk_pipeline_cache_object_unref(&dev->vk, &compiled->base);
ralloc_free(pipeline_mem_ctx);
*pPipeline = tu_pipeline_to_handle(pipeline);
fail:
if (compiled)
- vk_pipeline_cache_object_unref(&compiled->base);
+ vk_pipeline_cache_object_unref(&dev->vk, &compiled->base);
ralloc_free(pipeline_mem_ctx);
struct blob_reader *blob);
static void
-anv_shader_bin_destroy(struct vk_pipeline_cache_object *object)
+anv_shader_bin_destroy(struct vk_device *_device,
+ struct vk_pipeline_cache_object *object)
{
struct anv_device *device =
- container_of(object->device, struct anv_device, vk);
+ container_of(_device, struct anv_device, vk);
+
struct anv_shader_bin *shader =
container_of(object, struct anv_shader_bin, base);
nir, sha1);
device->fp64_nir = nir;
-}
\ No newline at end of file
+}
static inline void
anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
{
- vk_pipeline_cache_object_unref(&shader->base);
+ vk_pipeline_cache_object_unref(&device->vk, &shader->base);
}
struct anv_pipeline_executable {
struct blob_reader *blob);
static void
-anv_shader_bin_destroy(struct vk_pipeline_cache_object *object)
+anv_shader_bin_destroy(struct vk_device *_device,
+ struct vk_pipeline_cache_object *object)
{
struct anv_device *device =
- container_of(object->device, struct anv_device, vk);
+ container_of(_device, struct anv_device, vk);
struct anv_shader_bin *shader =
container_of(object, struct anv_shader_bin, base);
static inline void
anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
{
- vk_pipeline_cache_object_unref(&shader->base);
+ vk_pipeline_cache_object_unref(&device->vk, &shader->base);
}
struct anv_pipeline_executable {
}
static void
-dzn_cached_blob_destroy(struct vk_pipeline_cache_object *object)
+dzn_cached_blob_destroy(struct vk_device *device,
+ struct vk_pipeline_cache_object *object)
{
struct dzn_cached_blob *shader =
container_of(object, struct dzn_cached_blob, base);
- vk_free(&shader->base.device->alloc, shader);
+ vk_free(&device->alloc, shader);
}
static struct vk_pipeline_cache_object *
*stage = info->stage;
out:
- vk_pipeline_cache_object_unref(cache_obj);
+ vk_pipeline_cache_object_unref(cache->base.device, cache_obj);
return ret;
}
memcpy(info->data, bc->pShaderBytecode, bc->BytecodeLength);
cache_obj = vk_pipeline_cache_add_object(cache, cache_obj);
- vk_pipeline_cache_object_unref(cache_obj);
+ vk_pipeline_cache_object_unref(cache->base.device, cache_obj);
}
struct dzn_cached_gfx_pipeline_header {
*cache_hit = true;
- vk_pipeline_cache_object_unref(cache_obj);
+ vk_pipeline_cache_object_unref(cache->base.device, cache_obj);
return VK_SUCCESS;
}
}
cache_obj = vk_pipeline_cache_add_object(cache, cache_obj);
- vk_pipeline_cache_object_unref(cache_obj);
+ vk_pipeline_cache_object_unref(cache->base.device, cache_obj);
}
static void
*cache_hit = true;
out:
- vk_pipeline_cache_object_unref(cache_obj);
+ vk_pipeline_cache_object_unref(cache->base.device, cache_obj);
return ret;
}
memcpy((void *)cached_blob->data, dxil_hash, SHA1_DIGEST_LENGTH);
cache_obj = vk_pipeline_cache_add_object(cache, cache_obj);
- vk_pipeline_cache_object_unref(cache_obj);
+ vk_pipeline_cache_object_unref(cache->base.device, cache_obj);
}
static VkResult
}
static void
-raw_data_object_destroy(struct vk_pipeline_cache_object *object)
+raw_data_object_destroy(struct vk_device *device,
+ struct vk_pipeline_cache_object *object)
{
struct raw_data_object *data_obj =
container_of(object, struct raw_data_object, base);
- vk_free(&data_obj->base.device->alloc, data_obj);
+ vk_free(&device->alloc, data_obj);
}
static const struct vk_pipeline_cache_object_ops raw_data_object_ops = {
_mesa_set_search_pre_hashed(cache->object_cache, hash, object);
if (entry && entry->key == (const void *)object) {
/* Drop the reference owned by the cache */
- vk_pipeline_cache_object_unref(object);
+ vk_pipeline_cache_object_unref(cache->base.device, object);
_mesa_set_remove(cache->object_cache, entry);
}
vk_pipeline_cache_unlock(cache);
/* Drop our reference */
- vk_pipeline_cache_object_unref(object);
+ vk_pipeline_cache_object_unref(cache->base.device, object);
}
/* Consumes references to both search and replace and produces a reference */
if (entry) {
if (entry->key == (const void *)search) {
/* Drop the reference owned by the cache */
- vk_pipeline_cache_object_unref(search);
+ vk_pipeline_cache_object_unref(cache->base.device, search);
entry->key = vk_pipeline_cache_object_ref(replace);
} else {
}
vk_pipeline_cache_unlock(cache);
- vk_pipeline_cache_object_unref(search);
+ vk_pipeline_cache_object_unref(cache->base.device, search);
if (found) {
- vk_pipeline_cache_object_unref(replace);
+ vk_pipeline_cache_object_unref(cache->base.device, replace);
return found;
} else {
return replace;
}
assert(reader.current == reader.end && !reader.overrun);
- assert(object->device == cache->base.device);
assert(object->ops == ops);
assert(object->ref_cnt == 1);
assert(object->key_size == key_size);
vk_pipeline_cache_unlock(cache);
if (found) {
- vk_pipeline_cache_object_unref(object);
+ vk_pipeline_cache_object_unref(cache->base.device, object);
return found_object;
} else {
/* If it wasn't in the object cache, it might not be in the disk cache
blob_reader_init(&blob, data_obj->data, data_obj->data_size);
nir_shader *nir = nir_deserialize(mem_ctx, nir_options, &blob);
- vk_pipeline_cache_object_unref(object);
+ vk_pipeline_cache_object_unref(cache->base.device, object);
if (blob.overrun) {
ralloc_free(nir);
struct vk_pipeline_cache_object *cached =
vk_pipeline_cache_add_object(cache, &data_obj->base);
- vk_pipeline_cache_object_unref(cached);
+ vk_pipeline_cache_object_unref(cache->base.device, cached);
}
static int32_t
continue;
object = vk_pipeline_cache_add_object(cache, object);
- vk_pipeline_cache_object_unref(object);
+ vk_pipeline_cache_object_unref(cache->base.device, object);
}
}
return cache;
}
-static void
-object_unref_cb(struct set_entry *entry)
-{
- vk_pipeline_cache_object_unref((void *)entry->key);
-}
-
void
vk_pipeline_cache_destroy(struct vk_pipeline_cache *cache,
const VkAllocationCallbacks *pAllocator)
{
- if (cache->object_cache)
- _mesa_set_destroy(cache->object_cache, object_unref_cb);
+ if (cache->object_cache) {
+ set_foreach_remove(cache->object_cache, entry) {
+ vk_pipeline_cache_object_unref(cache->base.device,
+ (void *)entry->key);
+ }
+ _mesa_set_destroy(cache->object_cache, NULL);
+ }
simple_mtx_destroy(&cache->lock);
vk_object_free(cache->base.device, pAllocator, cache);
}
}
VKAPI_ATTR VkResult VKAPI_CALL
-vk_common_MergePipelineCaches(VkDevice device,
+vk_common_MergePipelineCaches(VkDevice _device,
VkPipelineCache dstCache,
uint32_t srcCacheCount,
const VkPipelineCache *pSrcCaches)
{
VK_FROM_HANDLE(vk_pipeline_cache, dst, dstCache);
+ VK_FROM_HANDLE(vk_device, device, _device);
+ assert(dst->base.device == device);
if (!dst->object_cache)
return VK_SUCCESS;
for (uint32_t i = 0; i < srcCacheCount; i++) {
VK_FROM_HANDLE(vk_pipeline_cache, src, pSrcCaches[i]);
+ assert(src->base.device == device);
if (!src->object_cache)
continue;
/* Even though dst has the object, it only has the blob version
* which isn't as useful. Replace it with the real object.
*/
- vk_pipeline_cache_object_unref(dst_object);
+ vk_pipeline_cache_object_unref(device, dst_object);
dst_entry->key = vk_pipeline_cache_object_ref(src_object);
}
} else {
*
* Called when vk_pipeline_cache_object.ref_cnt hits 0.
*/
- void (*destroy)(struct vk_pipeline_cache_object *object);
+ void (*destroy)(struct vk_device *device,
+ struct vk_pipeline_cache_object *object);
};
/** Base struct for cached objects
* it never has two objects of different types with the same key.
*/
struct vk_pipeline_cache_object {
- struct vk_device *device;
const struct vk_pipeline_cache_object_ops *ops;
uint32_t ref_cnt;
const void *key_data, uint32_t key_size)
{
memset(object, 0, sizeof(*object));
- object->device = device;
object->ops = ops;
p_atomic_set(&object->ref_cnt, 1);
object->data_size = 0; /* Unknown */
}
static inline void
-vk_pipeline_cache_object_unref(struct vk_pipeline_cache_object *object)
+vk_pipeline_cache_object_unref(struct vk_device *device,
+ struct vk_pipeline_cache_object *object)
{
assert(object && p_atomic_read(&object->ref_cnt) >= 1);
if (p_atomic_dec_zero(&object->ref_cnt))
- object->ops->destroy(object);
+ object->ops->destroy(device, object);
}
/** A generic implementation of VkPipelineCache */