mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader: Use a hash to build the filename when dumping shaders.
This way the same shader is always dumped to the same path and when launching the same program over and over we avoid both creating new copies of the same file each time and overwriting different dumped shaders.
This commit is contained in:
committed by
Henri Verbeet
parent
0e72aba0bc
commit
1a0d6a4db4
Notes:
Henri Verbeet
2024-08-29 19:26:26 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/992
@@ -33,6 +33,11 @@
|
||||
* will fill a supplied 16-byte array with the digest.
|
||||
*/
|
||||
|
||||
/*
|
||||
* DXBC uses a variation of the MD5 algorithm, which only changes the way
|
||||
* the message is padded in the final step.
|
||||
*/
|
||||
|
||||
#include "vkd3d_shader_private.h"
|
||||
|
||||
#define DXBC_CHECKSUM_BLOCK_SIZE 64
|
||||
@@ -230,10 +235,9 @@ static void md5_update(struct md5_ctx *ctx, const unsigned char *buf, unsigned i
|
||||
memcpy(ctx->in, buf, len);
|
||||
}
|
||||
|
||||
static void dxbc_checksum_final(struct md5_ctx *ctx)
|
||||
static void md5_final(struct md5_ctx *ctx, enum vkd3d_md5_variant variant)
|
||||
{
|
||||
unsigned int padding;
|
||||
unsigned int length;
|
||||
unsigned int count;
|
||||
unsigned char *p;
|
||||
|
||||
@@ -260,7 +264,7 @@ static void dxbc_checksum_final(struct md5_ctx *ctx)
|
||||
/* Now fill the next block */
|
||||
memset(ctx->in, 0, DXBC_CHECKSUM_BLOCK_SIZE);
|
||||
}
|
||||
else
|
||||
else if (variant == VKD3D_MD5_DXBC)
|
||||
{
|
||||
/* Make place for bitcount at the beginning of the block */
|
||||
memmove(&ctx->in[4], ctx->in, count);
|
||||
@@ -268,33 +272,44 @@ static void dxbc_checksum_final(struct md5_ctx *ctx)
|
||||
/* Pad block to 60 bytes */
|
||||
memset(p + 4, 0, padding - 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, padding - 8);
|
||||
}
|
||||
|
||||
/* Append length in bits and transform */
|
||||
length = ctx->i[0];
|
||||
memcpy(&ctx->in[0], &length, sizeof(length));
|
||||
byte_reverse(&ctx->in[4], 14);
|
||||
length = ctx->i[0] >> 2 | 0x1;
|
||||
memcpy(&ctx->in[DXBC_CHECKSUM_BLOCK_SIZE - 4], &length, sizeof(length));
|
||||
if (variant == VKD3D_MD5_DXBC)
|
||||
{
|
||||
unsigned int length;
|
||||
|
||||
length = ctx->i[0];
|
||||
memcpy(&ctx->in[0], &length, sizeof(length));
|
||||
byte_reverse(&ctx->in[4], 14);
|
||||
length = ctx->i[0] >> 2 | 0x1;
|
||||
memcpy(&ctx->in[DXBC_CHECKSUM_BLOCK_SIZE - 4], &length, sizeof(length));
|
||||
}
|
||||
else
|
||||
{
|
||||
byte_reverse(ctx->in, 14);
|
||||
|
||||
((unsigned int *)ctx->in)[14] = ctx->i[0];
|
||||
((unsigned int *)ctx->in)[15] = ctx->i[1];
|
||||
}
|
||||
|
||||
md5_transform(ctx->buf, (unsigned int *)ctx->in);
|
||||
byte_reverse((unsigned char *)ctx->buf, 4);
|
||||
memcpy(ctx->digest, ctx->buf, 16);
|
||||
}
|
||||
|
||||
#define DXBC_CHECKSUM_SKIP_BYTE_COUNT 20
|
||||
|
||||
void vkd3d_compute_dxbc_checksum(const void *dxbc, size_t size, uint32_t checksum[4])
|
||||
void vkd3d_compute_md5(const void *data, size_t size, uint32_t checksum[4], enum vkd3d_md5_variant variant)
|
||||
{
|
||||
const uint8_t *ptr = dxbc;
|
||||
const uint8_t *ptr = data;
|
||||
struct md5_ctx ctx;
|
||||
|
||||
VKD3D_ASSERT(size > DXBC_CHECKSUM_SKIP_BYTE_COUNT);
|
||||
ptr += DXBC_CHECKSUM_SKIP_BYTE_COUNT;
|
||||
size -= DXBC_CHECKSUM_SKIP_BYTE_COUNT;
|
||||
|
||||
md5_init(&ctx);
|
||||
md5_update(&ctx, ptr, size);
|
||||
dxbc_checksum_final(&ctx);
|
||||
md5_final(&ctx, variant);
|
||||
|
||||
memcpy(checksum, ctx.digest, sizeof(ctx.digest));
|
||||
}
|
||||
|
Reference in New Issue
Block a user