This essentially works for me, but note that it doesn't currently apply cleanly. I do have some comments, although they're fairly minor in the scheme of things:
From 8e68aad88d82ca9d61d6ef8525f6604c885bf7f9 Mon Sep 17 00:00:00 2001 From: Francisco Casas <fcasas@codeweavers.com> Date: Wed, 19 Jul 2023 12:19:02 -0400 Subject: [PATCH 4/9] vkd3d-shader/tpf: Introduce struct tpf_writer to group sm4 write arguments. We will add register information lookup tables on this struct later. They will be used by sm4_encode_register(), and thus, they will be required by write_sm4_instruction(). --- libs/vkd3d-shader/tpf.c | 459 ++++++++++++++++++++-------------------- 1 file changed, 228 insertions(+), 231 deletions(-)
I generally prefer doing changes like these function by function; start in write_sm4_shdr(), and then push down from there. That would also make potential conflicts easier to handle/avoid. I think this change is straightforward enough that I'm not going to require splitting the commit, but please take it into future consideration.
+ tpf.ctx = ctx; + tpf.buffer = &buffer;
That works, but it might be nice to introduce a tpf_writer_init() function as well, particularly once the lookup tables are introduced.
From 126f01a3b9e622d25aad053d51bd999f1b6e60dd Mon Sep 17 00:00:00 2001 From: Francisco Casas <fcasas@codeweavers.com> Date: Wed, 19 Jul 2023 12:19:02 -0400 Subject: [PATCH 5/9] vkd3d-shader/tpf: Make register_type_table an array of structs with lookup tables. --- libs/vkd3d-shader/tpf.c | 170 +++++++++++++++-------- libs/vkd3d-shader/vkd3d_shader_private.h | 2 + 2 files changed, 111 insertions(+), 61 deletions(-)
Somewhat like patch 4/9, this could probably be split in sm4_encode_register() and shader_sm4_read_param() parts.
+ for (i = 0; i < ARRAY_SIZE(register_type_table); ++i) + { + t = register_type_table[i].sm4_type; + lookup->register_type_info_from_sm4[t] = ®ister_type_table[i]; + t = register_type_table[i].vkd3d_type; + lookup->register_type_info_from_vkd3d[t] = ®ister_type_table[i]; + }
This works too, but perhaps something like the following is nicer?
```c const struct vkd3d_sm4_register_type_info *info; ... for (i = 0; i < ARRAY_SIZE(register_type_table); ++i) { info = ®ister_type_table[i]; lookup->register_type_info_from_sm4[info->sm4_type] = info; lookup->register_type_info_from_vkd3d[info->vkd3d_type] = info; } ```