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.
This commit is contained in:
Francisco Casas 2024-05-20 16:29:09 -04:00 committed by Henri Verbeet
parent 130b3335cb
commit dd8aa2ec91
Notes: Henri Verbeet 2024-07-09 21:08:22 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/877
3 changed files with 24 additions and 10 deletions

View File

@ -1683,8 +1683,7 @@ static void sm1_sort_externs(struct hlsl_ctx *ctx)
list_move_tail(&ctx->extern_vars, &sorted); list_move_tail(&ctx->extern_vars, &sorted);
} }
static void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, void write_sm1_uniforms(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer)
struct hlsl_ir_function_decl *entry_func)
{ {
size_t ctab_offset, ctab_start, ctab_end, vars_start, size_offset, creator_offset, offset; size_t ctab_offset, ctab_start, ctab_end, vars_start, size_offset, creator_offset, offset;
unsigned int uniform_count = 0; 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 * and be declared in vkd3d_shader_private.h and used without relying on HLSL
* IR structs. */ * IR structs. */
int d3dbc_compile(struct vsir_program *program, uint64_t config_flags, 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 vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context,
struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func) 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)); 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_constant_defs(ctx, &buffer);
write_sm1_semantic_dcls(ctx, &buffer); write_sm1_semantic_dcls(ctx, &buffer);

View File

@ -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 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); 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, 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 vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context,
struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func); struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func);

View File

@ -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 /* 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 * vsir_program and ctab blob, so they can be used as input to d3dbc_compile()
* on ctx and entry_func. */ * without relying on ctx and entry_func. */
static void sm1_generate_vsir(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *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_shader_version version = {0};
struct vkd3d_bytecode_buffer buffer = {0};
version.major = ctx->profile->major_version; version.major = ctx->profile->major_version;
version.minor = ctx->profile->minor_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; ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
return; 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, 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: case VKD3D_SHADER_TARGET_D3D_BYTECODE:
{ {
uint32_t config_flags = vkd3d_shader_init_config_flags(); uint32_t config_flags = vkd3d_shader_init_config_flags();
struct vkd3d_shader_code ctab = {0};
struct vsir_program program; struct vsir_program program;
int result; int result;
sm1_generate_vsir(ctx, entry_func, config_flags, &program); sm1_generate_vsir(ctx, entry_func, config_flags, &program, &ctab);
if (ctx->result) if (ctx->result)
{ {
vsir_program_cleanup(&program); vsir_program_cleanup(&program);
vkd3d_shader_free_shader_code(&ctab);
return ctx->result; 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); vsir_program_cleanup(&program);
vkd3d_shader_free_shader_code(&ctab);
return result; return result;
} }