Giovanni Mascellani (@giomasce) commented about libs/vkd3d-shader/ir.c:
- struct vkd3d_shader_instruction_array *instructions = &parser->instructions;
- struct vkd3d_shader_instruction *texkill_ins, *ins;
- struct vkd3d_shader_src_param *src_param;
- struct vkd3d_shader_dst_param *dst_param;
- for (int i = 0; i < instructions->count; ++i)
- {
unsigned int tmp_idx;
texkill_ins = &instructions->elements[i];
if (texkill_ins->handler_idx != VKD3DSIH_TEXKILL)
continue;
if (!shader_instruction_array_insert_at(instructions, i + 1, 4))
return VKD3D_ERROR_OUT_OF_MEMORY;
For a shader with many `texkill` instructions that's going to copy most of it many times over. Rather than inserting in place I'd suggest to simply rewrite the whole array. This is, at least, the approach I'm following with the preliminary passes for my CFG structurizer, see for example https://gitlab.winehq.org/giomasce/vkd3d/-/commit/b771e30fd5c5f52478c9f92f8c... (but notice that's still work in progress).