vkd3d-shader: Align the start offset instead of the size in bytecode_put_bytes().

The practical effect this has is that we avoid potential trailing padding at
the end of DXBC blobs. Unfortunately this also means we need to be more
careful about using bytecode_get_size() to find the offset where subsequent
data would get written, although in many cases this follows a put_u32() call.
This commit is contained in:
Henri Verbeet
2023-04-04 18:27:59 +02:00
committed by Alexandre Julliard
parent a0a3fb0e5f
commit d6d9aab31c
Notes: Alexandre Julliard 2023-04-04 22:36:34 +02:00
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/144
5 changed files with 23 additions and 19 deletions

View File

@@ -342,20 +342,19 @@ void vkd3d_shader_error(struct vkd3d_shader_message_context *context, const stru
size_t bytecode_put_bytes(struct vkd3d_bytecode_buffer *buffer, const void *bytes, size_t size)
{
size_t aligned_size = align(size, 4);
size_t offset = buffer->size;
size_t offset = bytecode_get_next_offset(buffer);
if (buffer->status)
return offset;
if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->capacity, offset + aligned_size, 1))
if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->capacity, offset + size, 1))
{
buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
return offset;
}
memset(buffer->data + buffer->size, 0xab, offset - buffer->size);
memcpy(buffer->data + offset, bytes, size);
memset(buffer->data + offset + size, 0xab, aligned_size - size);
buffer->size = offset + aligned_size;
buffer->size = offset + size;
return offset;
}