Skip to content

Commit

Permalink
[vk] always initialize image hash properly (incl. for non-owning images)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicebyte committed May 12, 2024
1 parent 350acdd commit 534866d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions source/ngf-common/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <string.h>

void (*ngfi_dict_hashfn)(uintptr_t, uint32_t, void*) = NULL;
uint32_t ngfi_dict_hashseed = 0x9e3779b9;
static const uint32_t ngfi_dict_hashseed = 0x9e3779b9;

struct ngfi_dict_t {
size_t nslots;
Expand Down Expand Up @@ -110,7 +110,7 @@ void* ngfi_dict_get(
assert(*dict);
assert(key != NGFI_DICT_INVALID_KEY);

uint64_t mmh3_out[2];
uint64_t mmh3_out[2] = {0, 0};
if (ngfi_dict_hashfn == NULL) {
ngfi_mmh3_x64_128(key, ngfi_dict_hashseed, mmh3_out);
} else {
Expand Down
15 changes: 7 additions & 8 deletions source/ngf-vk/impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,12 @@ static ngf_error ngfvk_create_vk_image_view(
}
}

static inline uint64_t ngfvk_ptr_hash(void* data) {
uint64_t mmh3_out[2] = {0, 0};
ngfi_mmh3_x64_128((uintptr_t)data, 0x9e3779b9, mmh3_out);
return mmh3_out[0]^mmh3_out[1];
}

static ngf_error ngfvk_create_image(
const ngf_image_info* info,
const ngfvk_alloc* backing_resource_alloc,
Expand All @@ -984,6 +990,7 @@ static ngf_error ngfvk_create_image(
(*result)->owns_backing_resource = owns_backing_resource;
memset(&(*result)->sync_state, 0, sizeof((*result)->sync_state));
(*result)->sync_state.layout = VK_IMAGE_LAYOUT_UNDEFINED;
(*result)->hash = ngfvk_ptr_hash(*result);

if (owns_backing_resource) {
err = ngfvk_create_vk_image_view(
Expand Down Expand Up @@ -2439,12 +2446,6 @@ static void ngfvk_cmd_buf_reset_res_states(ngf_cmd_buffer cmd_buf) {
ngfi_dict_clear(cmd_buf->local_res_states);
}

static inline uint64_t ngfvk_ptr_hash(void* data) {
uint64_t mmh3_out[2];
ngfi_mmh3_x64_128((uintptr_t)data, 0x9e3779b9, mmh3_out);
return mmh3_out[0]^mmh3_out[1];
}

static inline ngfvk_sync_res ngfvk_sync_res_from_buf(ngf_buffer buf) {
ngfvk_sync_res sync_res = {
.data = {.buf = buf},
Expand Down Expand Up @@ -5856,8 +5857,6 @@ ngf_error ngf_create_image(const ngf_image_info* info, ngf_image* result) {

if (err != NGF_ERROR_OK) { goto ngf_create_image_cleanup; }

(*result)->hash = ngfvk_ptr_hash(*result);

ngf_create_image_cleanup:
if (err != NGF_ERROR_OK) { ngf_destroy_image(*result); }
return err;
Expand Down

0 comments on commit 534866d

Please sign in to comment.