diff --git a/libs/vkd3d/resource.c b/libs/vkd3d/resource.c index b95ad720..55bf2e78 100644 --- a/libs/vkd3d/resource.c +++ b/libs/vkd3d/resource.c @@ -1574,6 +1574,35 @@ static struct vkd3d_view *vkd3d_view_create(enum vkd3d_view_type type); static HRESULT d3d12_create_sampler(struct d3d12_device *device, const D3D12_SAMPLER_DESC *desc, VkSampler *vk_sampler); +#include + +static FILE* fp_debug_map = 0; + +static void print_vkd3d_view_key(FILE* fp, struct vkd3d_view_map *view_map, const struct vkd3d_view_key *k) { + fprintf(fp, "ThID: %li\tmap:%p\thash: %lu\t", GetCurrentThreadId(), view_map, vkd3d_view_entry_hash(k)); + switch(k->view_type) { + case VKD3D_VIEW_TYPE_BUFFER: + fprintf(fp, "key: VKD3D_VIEW_TYPE_BUFFER %lld %p %lld %lld\n", k->u.buffer.buffer, k->u.buffer.format, k->u.buffer.offset, k->u.buffer.size); + break; + + case VKD3D_VIEW_TYPE_IMAGE: + fprintf(fp, "key: VKD3D_VIEW_TYPE_IMAGE %lld %lld %lld %p %lld %lld %lld %lld %lld %lld %lld %lld %lld\n", + k->u.texture.image, k->u.texture.view_type, k->u.texture.layout, k->u.texture.format, + k->u.texture.miplevel_idx, k->u.texture.miplevel_count, k->u.texture.layer_idx, k->u.texture.layer_count, + k->u.texture.components.r, k->u.texture.components.g, k->u.texture.components.b, k->u.texture.components.a, + k->u.texture.allowed_swizzle); + break; + + case VKD3D_VIEW_TYPE_SAMPLER: + fprintf(fp, "key: VKD3D_VIEW_TYPE_SAMPLER\n"); + break; + + default: + fprintf(fp, "Invalid vkd3d_view_key type %i\n", k->view_type); + } + fflush(fp); +} + struct vkd3d_view *vkd3d_view_map_create_view(struct vkd3d_view_map *view_map, struct d3d12_device *device, const struct vkd3d_view_key *key) { @@ -1588,13 +1617,34 @@ struct vkd3d_view *vkd3d_view_map_create_view(struct vkd3d_view_map *view_map, return NULL; } + /* We're already mutex protected here... + * no need to check fo concurrent access + */ + + if(!fp_debug_map) { + fp_debug_map = fopen("/home/ema/vkd3d.log", "a"); + if(fp_debug_map) { + fprintf(fp_debug_map, "LOG started\n"); + } + } + if(fp_debug_map) print_vkd3d_view_key(fp_debug_map, view_map, key); + if ((e = (struct vkd3d_view_entry *)hash_map_find(&view_map->map, key))) { + if(fp_debug_map) { + fprintf(fp_debug_map, "ThID: %li\tGot it: %p\n", GetCurrentThreadId(), e); + fflush(fp_debug_map); + } view = e->view; pthread_mutex_unlock(&view_map->mutex); return view; } + if(fp_debug_map) { + fprintf(fp_debug_map, "ThID: %li\tProceeding to create\n", GetCurrentThreadId()); + fflush(fp_debug_map); + } + switch (key->view_type) { case VKD3D_VIEW_TYPE_BUFFER: @@ -1612,11 +1662,20 @@ struct vkd3d_view *vkd3d_view_map_create_view(struct vkd3d_view_map *view_map, default: ERR("Unsupported view type %u.\n", key->view_type); + // TODO: why aren't we unlocking here? + if(fp_debug_map) { + fprintf(fp_debug_map, "ThID: %li\tInvalid view_type %i\n", GetCurrentThreadId(), key->view_type); + fflush(fp_debug_map); + } return NULL; } if (!success) { + if(fp_debug_map) { + fprintf(fp_debug_map, "ThID: %li\tCreation failure\n", GetCurrentThreadId()); + fflush(fp_debug_map); + } pthread_mutex_unlock(&view_map->mutex); return NULL; } @@ -1624,8 +1683,18 @@ struct vkd3d_view *vkd3d_view_map_create_view(struct vkd3d_view_map *view_map, entry.key = *key; entry.view = view; - if (!hash_map_insert(&view_map->map, key, &entry.entry)) - ERR("Failed to insert view into hash map.\n"); + if (!hash_map_insert(&view_map->map, key, &entry.entry)) { + if(fp_debug_map) { + fprintf(fp_debug_map, "ThID: %li\tInsertion failure!\n", GetCurrentThreadId()); + fflush(fp_debug_map); + } + ERR("Failed to insert view into hash map.\n"); + } + + if(fp_debug_map) { + fprintf(fp_debug_map, "ThID: %li\tAdded\n", GetCurrentThreadId()); + fflush(fp_debug_map); + } pthread_mutex_unlock(&view_map->mutex); return view;