+static uint32_t spirv_compiler_emit_load_ssa_reg(struct spirv_compiler *compiler, + const struct vkd3d_shader_register *reg, enum vkd3d_shader_component_type component_type, + unsigned int swizzle, unsigned int write_mask) +{ + uint32_t val_id = spirv_compiler_get_ssa_register_id(compiler, reg); + assert(val_id); + return val_id; +}
This doesn't emit anything, and "component_type", "swizzle", and "write_mask" are unused. More generally, it seems the only caller could just call spirv_compiler_get_ssa_register_id() instead.
@@ -3912,6 +3938,13 @@ static void spirv_compiler_emit_store_reg(struct spirv_compiler *compiler, assert(!register_is_constant_or_undef(reg)); + if (reg->type == VKD3DSPR_SSA) + { + assert(reg->idx[0].offset < compiler->ssa_register_count); + compiler->ssa_register_ids[reg->idx[0].offset] = val_id; + return; + } +
Here we seem to go entirely the other way, and simply inline the counterpart to spirv_compiler_get_ssa_register_id(). I.e., why do we have spirv_compiler_get_ssa_register_id() but not spirv_compiler_set_ssa_register_id()?
+static void spirv_compiler_emit_ssas(struct spirv_compiler *compiler, unsigned int count) +{ + assert(!compiler->ssa_register_ids); + if (!(compiler->ssa_register_ids = vkd3d_calloc(count, sizeof(*compiler->ssa_register_ids)))) + { + ERR("Failed to allocate SSA register value id array, count %u.\n", count); + spirv_compiler_error(compiler, VKD3D_SHADER_ERROR_SPV_OUT_OF_MEMORY, + "Failed to allocate SSA register value id array of count %u.", count); + } + compiler->ssa_register_count = count; +}
This doesn't emit any SPIR-V.
@@ -523,6 +524,7 @@ enum vkd3d_shader_register_type VKD3DSPR_RASTERIZER, VKD3DSPR_OUTSTENCILREF, VKD3DSPR_UNDEF, + VKD3DSPR_SSA, VKD3DSPR_COUNT,
This is perhaps subtle, but note that this will cause init_sm4_lookup_tables() to map VKD3DSPR_SSA (like VKD3DSPR_UNDEF) to VKD3D_SM4_RT_TEMP, while ideally that lookup would fail.
@@ -2838,7 +2855,8 @@ static enum vkd3d_result sm6_parser_init(struct sm6_parser *sm6, const uint32_t return ret; } - if (!(sm6->output_params = shader_parser_get_dst_params(&sm6->p, output_signature->element_count))) + if (!(sm6->output_params = shader_parser_get_dst_params(&sm6->p, output_signature->element_count)) + || !(sm6->input_params = shader_parser_get_dst_params(&sm6->p, input_signature->element_count))) { ERR("Failed to allocate output parameters.\n"); vkd3d_shader_error(message_context, &location, VKD3D_SHADER_ERROR_DXIL_OUT_OF_MEMORY,
That makes the error message inaccurate.
+static inline unsigned int sm6_parser_alloc_ssa_id(struct sm6_parser *sm6) +{ + return sm6->ssa_next_id++; +}
Why is that "static inline"? The main thing it'll do in .c files is to make it harder to spot unused code. We seem to have some more instances of that in both the existing dxil.c code and this MR.
+static void register_init_with_id(struct vkd3d_shader_register *reg, + enum vkd3d_shader_register_type reg_type, enum vkd3d_data_type data_type, unsigned int index) +{ + shader_register_init(reg, reg_type, data_type, 1); + reg->idx[0].offset = index; +}
This is pretty minor in the scheme of things, but where is the ID above? I'm guessing it's supposed to be the "index" parameter.
+static void register_init_ssa_vector(struct vkd3d_shader_register *reg, enum vkd3d_data_type data_type, + unsigned int component_count, struct sm6_parser *sm6) ... +static inline void register_init_ssa_scalar(struct vkd3d_shader_register *reg, const struct sm6_type *type, + struct sm6_parser *sm6)
Why does initialising a SSA vector require a vkd3d_data_type, while initialising a SSA scalar requires a sm6_type? Also, register_init_ssa_vector() is only ever called with a "component_count" of 1.
+static void instruction_dst_param_init_ssa_scalar_component(struct vkd3d_shader_instruction *ins, + unsigned int component_idx, struct sm6_parser *sm6) +{ + struct vkd3d_shader_dst_param *param = instruction_dst_params_alloc(ins, 1, sm6); + struct sm6_value *dst = sm6_parser_get_current_value(sm6); + + dst_param_init_ssa_scalar(param, dst->type, sm6); + param->write_mask = VKD3DSP_WRITEMASK_0 << component_idx; + dst->u.reg = param->reg; +}
Somewhat like register_init_ssa_vector() above, we're only ever calling instruction_dst_param_init_ssa_scalar_component() with a "component_idx" of 0.
I'm guessing future patches will make some of these issues go away, but that's not ideal.