Zebediah Figura : vkd3d-shader/hlsl: Always align section sizes.
Module: vkd3d Branch: master Commit: 616c4bf51fe338e1abf96627f6ce52404d5f4d8b URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/616c4bf51fe338e1abf96627f6ce52... Author: Zebediah Figura <zfigura(a)codeweavers.com> Date: Wed Apr 5 17:01:52 2023 -0500 vkd3d-shader/hlsl: Always align section sizes. This fixes disassembly using native D3DDisassemble() of shaders generated with vkd3d-shader. Fixes: d6d9aab31c290d3dc7a67110ba2b0ac916377929 --- libs/vkd3d-shader/hlsl_sm4.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 65378f90..5bd4f2d6 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -147,6 +147,16 @@ bool hlsl_sm4_usage_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_semant return true; } +static void add_section(struct dxbc_writer *dxbc, uint32_t tag, struct vkd3d_bytecode_buffer *buffer) +{ + /* Native D3DDisassemble() expects at least the sizes of the ISGN and OSGN + * sections to be aligned. Without this, the sections themselves will be + * aligned, but their reported sizes won't. */ + size_t size = bytecode_align(buffer); + + dxbc_writer_add_section(dxbc, tag, buffer->data, size); +} + static void write_sm4_signature(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc, bool output) { struct vkd3d_bytecode_buffer buffer = {0}; @@ -252,7 +262,7 @@ static void write_sm4_signature(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc, set_u32(&buffer, count_position, i); - dxbc_writer_add_section(dxbc, output ? TAG_OSGN : TAG_ISGN, buffer.data, buffer.size); + add_section(dxbc, output ? TAG_OSGN : TAG_ISGN, &buffer); } static const struct hlsl_type *get_array_type(const struct hlsl_type *type) @@ -745,7 +755,7 @@ static void write_sm4_rdef(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) creator_offset = put_string(&buffer, vkd3d_shader_get_version(NULL, NULL)); set_u32(&buffer, creator_position, creator_offset); - dxbc_writer_add_section(dxbc, TAG_RDEF, buffer.data, buffer.size); + add_section(dxbc, TAG_RDEF, &buffer); vkd3d_free(extern_resources); } @@ -2502,7 +2512,7 @@ static void write_sm4_shdr(struct hlsl_ctx *ctx, set_u32(&buffer, token_count_position, bytecode_get_size(&buffer) / sizeof(uint32_t)); - dxbc_writer_add_section(dxbc, TAG_SHDR, buffer.data, buffer.size); + add_section(dxbc, TAG_SHDR, &buffer); vkd3d_free(extern_resources); }
participants (1)
-
Alexandre Julliard