On 6/30/21 7:44 AM, Matteo Bruni wrote:
On Tue, Jun 29, 2021 at 8:00 PM Zebediah Figura zfigura@codeweavers.com wrote:
And change the way we handle alignment.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl.h | 4 +- libs/vkd3d-shader/hlsl_codegen.c | 92 +++++++++++++------------------- 2 files changed, 39 insertions(+), 57 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 9afa590a..27bbd9b6 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c
@@ -1631,20 +1612,21 @@ static void write_sm1_uniforms(struct hlsl_ctx *ctx, struct bytecode_buffer *buf { if (!var->semantic.name && var->reg.allocated) {
set_dword(buffer, vars_start + (uniform_count * 5), (buffer->count - ctab_start) * sizeof(*buffer->data));
size_t var_offset = vars_start + (uniform_count * 5 * sizeof(uint32_t));
set_dword(buffer, var_offset, buffer->size - ctab_start); put_string(buffer, var->name); write_sm1_type(buffer, var->data_type, ctab_start);
set_dword(buffer, vars_start + (uniform_count * 5) + 3,
(var->data_type->bytecode_offset - ctab_start) * sizeof(*buffer->data));
set_dword(buffer, var_offset + 3 * sizeof(uint32_t), var->data_type->bytecode_offset - ctab_start); ++uniform_count; } } offset = put_string(buffer, vkd3d_shader_get_version(NULL, NULL));
- set_dword(buffer, creator_offset, (offset - ctab_start) * sizeof(*buffer->data));
- set_dword(buffer, creator_offset, offset - ctab_start);
- set_dword(buffer, size_offset, D3DSIO_COMMENT | ((buffer->count - (ctab_start - 1)) << 16));
- set_dword(buffer, size_offset, D3DSIO_COMMENT | (((buffer->size - (ctab_start - 1)) / sizeof(uint32_t)) << 16));
I think this is broken, or at least changed from previous output, for two different reasons: buffer->size is now not aligned (since alignment happens on the following put_bytes()) and we want to subtract ctab_start - 1 * sizeof(DWORD) (or, equivalently, strlen("CTAB")) from the current offset.
I suggest to replace all the raw uses of buffer->size with a helper call e.g. size_t get_current_offset_aligned(buffer, alignment) to make sure we're not falling into this trap.
Yeah, this is broken. I think the helper makes sense; naming it is hard, but...