From dd8aa2ec91358b74561c94e2ea3d0b11071107e8 Mon Sep 17 00:00:00 2001 From: Francisco Casas Date: Mon, 20 May 2024 16:29:09 -0400 Subject: [PATCH] vkd3d-shader/hlsl: Generate CTAB outside d3dbc_compile(). There is no way to store this information from the vsir_program alone, so we make d3dbc_compile() expect the CTAB blob. --- libs/vkd3d-shader/d3dbc.c | 7 +++---- libs/vkd3d-shader/hlsl.h | 3 ++- libs/vkd3d-shader/hlsl_codegen.c | 24 +++++++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c index 1b966afc..82d1af29 100644 --- a/libs/vkd3d-shader/d3dbc.c +++ b/libs/vkd3d-shader/d3dbc.c @@ -1683,8 +1683,7 @@ static void sm1_sort_externs(struct hlsl_ctx *ctx) list_move_tail(&ctx->extern_vars, &sorted); } -static void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, - struct hlsl_ir_function_decl *entry_func) +void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer) { size_t ctab_offset, ctab_start, ctab_end, vars_start, size_offset, creator_offset, offset; unsigned int uniform_count = 0; @@ -2784,7 +2783,7 @@ static void write_sm1_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer * * and be declared in vkd3d_shader_private.h and used without relying on HLSL * IR structs. */ int d3dbc_compile(struct vsir_program *program, uint64_t config_flags, - const struct vkd3d_shader_compile_info *compile_info, + const struct vkd3d_shader_compile_info *compile_info, const struct vkd3d_shader_code *ctab, struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context, struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func) { @@ -2792,7 +2791,7 @@ int d3dbc_compile(struct vsir_program *program, uint64_t config_flags, put_u32(&buffer, sm1_version(ctx->profile->type, ctx->profile->major_version, ctx->profile->minor_version)); - write_sm1_uniforms(ctx, &buffer, entry_func); + bytecode_put_bytes(&buffer, ctab->code, ctab->size); write_sm1_constant_defs(ctx, &buffer); write_sm1_semantic_dcls(ctx, &buffer); diff --git a/libs/vkd3d-shader/hlsl.h b/libs/vkd3d-shader/hlsl.h index 9ea6bc2e..8ca1aa6b 100644 --- a/libs/vkd3d-shader/hlsl.h +++ b/libs/vkd3d-shader/hlsl.h @@ -1473,8 +1473,9 @@ bool hlsl_sm1_register_from_semantic(struct hlsl_ctx *ctx, const struct hlsl_sem bool output, enum vkd3d_shader_register_type *type, unsigned int *reg); bool hlsl_sm1_usage_from_semantic(const struct hlsl_semantic *semantic, D3DDECLUSAGE *usage, uint32_t *usage_idx); +void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer); int d3dbc_compile(struct vsir_program *program, uint64_t config_flags, - const struct vkd3d_shader_compile_info *compile_info, + const struct vkd3d_shader_compile_info *compile_info, const struct vkd3d_shader_code *ctab, struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context, struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func); diff --git a/libs/vkd3d-shader/hlsl_codegen.c b/libs/vkd3d-shader/hlsl_codegen.c index 458d2fec..777dbea8 100644 --- a/libs/vkd3d-shader/hlsl_codegen.c +++ b/libs/vkd3d-shader/hlsl_codegen.c @@ -5523,12 +5523,13 @@ void hlsl_run_const_passes(struct hlsl_ctx *ctx, struct hlsl_block *body) } /* OBJECTIVE: Translate all the information from ctx and entry_func to the - * vsir_program, so it can be used as input to d3dbc_compile() without relying - * on ctx and entry_func. */ + * vsir_program and ctab blob, so they can be used as input to d3dbc_compile() + * without relying on ctx and entry_func. */ static void sm1_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, - uint64_t config_flags, struct vsir_program *program) + uint64_t config_flags, struct vsir_program *program, struct vkd3d_shader_code *ctab) { struct vkd3d_shader_version version = {0}; + struct vkd3d_bytecode_buffer buffer = {0}; version.major = ctx->profile->major_version; version.minor = ctx->profile->minor_version; @@ -5538,6 +5539,16 @@ static void sm1_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl ctx->result = VKD3D_ERROR_OUT_OF_MEMORY; return; } + + write_sm1_uniforms(ctx, &buffer); + if (buffer.status) + { + vkd3d_free(buffer.data); + ctx->result = buffer.status; + return; + } + ctab->code = buffer.data; + ctab->size = buffer.size; } int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, @@ -5724,18 +5735,21 @@ int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry case VKD3D_SHADER_TARGET_D3D_BYTECODE: { uint32_t config_flags = vkd3d_shader_init_config_flags(); + struct vkd3d_shader_code ctab = {0}; struct vsir_program program; int result; - sm1_generate_vsir(ctx, entry_func, config_flags, &program); + sm1_generate_vsir(ctx, entry_func, config_flags, &program, &ctab); if (ctx->result) { vsir_program_cleanup(&program); + vkd3d_shader_free_shader_code(&ctab); return ctx->result; } - result = d3dbc_compile(&program, config_flags, NULL, out, ctx->message_context, ctx, entry_func); + result = d3dbc_compile(&program, config_flags, NULL, &ctab, out, ctx->message_context, ctx, entry_func); vsir_program_cleanup(&program); + vkd3d_shader_free_shader_code(&ctab); return result; }