Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 34 +++++++++++++++++++++++++++++++++- libs/vkd3d-shader/sm4.h | 1 + 2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 977b8395..c9a427d8 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -20,12 +20,44 @@
#include "hlsl.h" #include <stdio.h> +#include "sm4.h" + +static void write_sm4_shdr(struct hlsl_ctx *ctx, struct dxbc_writer *dxbc) +{ + const struct hlsl_profile_info *profile = ctx->profile; + struct vkd3d_bytecode_buffer buffer = {0}; + + static const uint16_t shader_types[VKD3D_SHADER_TYPE_COUNT] = + { + VKD3D_SM4_PS, + VKD3D_SM4_VS, + VKD3D_SM4_GS, + VKD3D_SM5_HS, + VKD3D_SM5_DS, + VKD3D_SM5_CS, + 0, /* EFFECT */ + 0, /* TEXTURE */ + VKD3D_SM4_LIB, + }; + + put_u32(&buffer, (shader_types[profile->type] << 16) | (profile->major_version << 4) | profile->minor_version); + put_u32(&buffer, 0); /* FIXME: instruction token count */ + + dxbc_writer_add_section(dxbc, TAG_SHDR, buffer.data, buffer.size); +}
int hlsl_sm4_write(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, struct vkd3d_shader_code *out) { struct dxbc_writer dxbc; + size_t i; + int ret;
dxbc_writer_init(&dxbc);
- return dxbc_writer_write(&dxbc, out); + write_sm4_shdr(ctx, &dxbc); + + ret = dxbc_writer_write(&dxbc, out); + for (i = 0; i < dxbc.section_count; ++i) + vkd3d_free((void *)dxbc.sections[i].data); + return ret; } diff --git a/libs/vkd3d-shader/sm4.h b/libs/vkd3d-shader/sm4.h index 5622d6df..b4dd1632 100644 --- a/libs/vkd3d-shader/sm4.h +++ b/libs/vkd3d-shader/sm4.h @@ -25,6 +25,7 @@ #define VKD3D_SM5_HS 0x0003u #define VKD3D_SM5_DS 0x0004u #define VKD3D_SM5_CS 0x0005u +#define VKD3D_SM4_LIB 0xfff0u
#define VKD3D_SM4_INSTRUCTION_MODIFIER (0x1u << 31)