vkd3d-shader/fx: Add initial support for writing passes for fx_2_0.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov
2023-11-15 23:31:01 +01:00
committed by Alexandre Julliard
parent b478f0a300
commit 0117e4fb7e
Notes: Alexandre Julliard 2024-01-23 23:03:22 +01:00
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/565

View File

@ -49,6 +49,7 @@ struct fx_write_context_ops
{ {
uint32_t (*write_string)(const char *string, struct fx_write_context *fx); uint32_t (*write_string)(const char *string, struct fx_write_context *fx);
void (*write_technique)(struct hlsl_ir_var *var, struct fx_write_context *fx); void (*write_technique)(struct hlsl_ir_var *var, struct fx_write_context *fx);
void (*write_pass)(struct hlsl_ir_var *var, struct fx_write_context *fx);
}; };
struct fx_write_context struct fx_write_context
@ -75,6 +76,11 @@ static uint32_t write_string(const char *string, struct fx_write_context *fx)
return fx->ops->write_string(string, fx); return fx->ops->write_string(string, fx);
} }
static void write_pass(struct hlsl_ir_var *var, struct fx_write_context *fx)
{
fx->ops->write_pass(var, fx);
}
static void fx_write_context_init(struct hlsl_ctx *ctx, const struct fx_write_context_ops *ops, static void fx_write_context_init(struct hlsl_ctx *ctx, const struct fx_write_context_ops *ops,
struct fx_write_context *fx) struct fx_write_context *fx)
{ {
@ -147,7 +153,21 @@ static uint32_t write_fx_4_string(const char *string, struct fx_write_context *f
return string_entry->offset; return string_entry->offset;
} }
static void write_pass(struct hlsl_ir_var *var, struct fx_write_context *fx) static void write_fx_4_pass(struct hlsl_ir_var *var, struct fx_write_context *fx)
{
struct vkd3d_bytecode_buffer *buffer = &fx->structured;
uint32_t name_offset;
name_offset = write_string(var->name, fx);
put_u32(buffer, name_offset);
put_u32(buffer, 0); /* Assignment count. */
put_u32(buffer, 0); /* Annotation count. */
/* TODO: annotations */
/* TODO: assignments */
}
static void write_fx_2_pass(struct hlsl_ir_var *var, struct fx_write_context *fx)
{ {
struct vkd3d_bytecode_buffer *buffer = &fx->structured; struct vkd3d_bytecode_buffer *buffer = &fx->structured;
uint32_t name_offset; uint32_t name_offset;
@ -156,6 +176,9 @@ static void write_pass(struct hlsl_ir_var *var, struct fx_write_context *fx)
put_u32(buffer, name_offset); put_u32(buffer, name_offset);
put_u32(buffer, 0); /* Annotation count. */ put_u32(buffer, 0); /* Annotation count. */
put_u32(buffer, 0); /* Assignment count. */ put_u32(buffer, 0); /* Assignment count. */
/* TODO: annotations */
/* TODO: assignments */
} }
static void write_fx_4_technique(struct hlsl_ir_var *var, struct fx_write_context *fx) static void write_fx_4_technique(struct hlsl_ir_var *var, struct fx_write_context *fx)
@ -261,21 +284,30 @@ static uint32_t write_fx_2_string(const char *string, struct fx_write_context *f
static void write_fx_2_technique(struct hlsl_ir_var *var, struct fx_write_context *fx) static void write_fx_2_technique(struct hlsl_ir_var *var, struct fx_write_context *fx)
{ {
struct vkd3d_bytecode_buffer *buffer = &fx->structured; struct vkd3d_bytecode_buffer *buffer = &fx->structured;
uint32_t name_offset; uint32_t name_offset, count_offset, count = 0;
struct hlsl_ir_var *pass;
name_offset = write_string(var->name, fx); name_offset = write_string(var->name, fx);
put_u32(buffer, name_offset); put_u32(buffer, name_offset);
put_u32(buffer, 0); /* Annotation count. */ put_u32(buffer, 0); /* Annotation count. */
put_u32(buffer, 0); /* Pass count. */ count_offset = put_u32(buffer, 0); /* Pass count. */
/* FIXME: annotations */ /* FIXME: annotations */
/* FIXME: passes */
LIST_FOR_EACH_ENTRY(pass, &var->scope->vars, struct hlsl_ir_var, scope_entry)
{
write_pass(pass, fx);
++count;
}
set_u32(buffer, count_offset, count);
} }
static const struct fx_write_context_ops fx_2_ops = static const struct fx_write_context_ops fx_2_ops =
{ {
.write_string = write_fx_2_string, .write_string = write_fx_2_string,
.write_technique = write_fx_2_technique, .write_technique = write_fx_2_technique,
.write_pass = write_fx_2_pass,
}; };
static int hlsl_fx_2_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) static int hlsl_fx_2_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out)
@ -311,7 +343,6 @@ static int hlsl_fx_2_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out)
/* TODO: resources */ /* TODO: resources */
size = align(fx.unstructured.size, 4); size = align(fx.unstructured.size, 4);
/* Accounts for additional 4 bytes before the raw data section. */
set_u32(&buffer, offset, size); set_u32(&buffer, offset, size);
bytecode_put_bytes(&buffer, fx.unstructured.data, fx.unstructured.size); bytecode_put_bytes(&buffer, fx.unstructured.data, fx.unstructured.size);
@ -336,6 +367,7 @@ static const struct fx_write_context_ops fx_4_ops =
{ {
.write_string = write_fx_4_string, .write_string = write_fx_4_string,
.write_technique = write_fx_4_technique, .write_technique = write_fx_4_technique,
.write_pass = write_fx_4_pass,
}; };
static int hlsl_fx_4_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out) static int hlsl_fx_4_write(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out)