]> git.tdb.fi Git - libs/gl.git/commitdiff
Take care of SPIR-V load IDs in ternary expressions
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Mar 2022 06:54:56 +0000 (08:54 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Mar 2022 06:54:56 +0000 (08:54 +0200)
source/glsl/spirv.cpp

index 7b3e104e372c65a7d845bfd0a77c93358762aee3..c6f15614f5c8a56a36c7e7236a1c785f081e0a19 100644 (file)
@@ -1021,18 +1021,22 @@ void SpirVGenerator::visit(TernaryExpression &ternary)
        writer.write_op(content.function_body, OP_SELECTION_MERGE, merge_block_id, 0);  // Selection control (none)
        writer.write_op(content.function_body, OP_BRANCH_CONDITIONAL, condition_id, true_label_id, false_label_id);
 
+       std::map<const VariableDeclaration *, Id> saved_load_ids = variable_load_ids;
+
        writer.write_op_label(true_label_id);
        ternary.true_expr->visit(*this);
        Id true_result_id = r_expression_result_id;
        true_label_id = writer.get_current_block();
        writer.write_op(content.function_body, OP_BRANCH, merge_block_id);
 
+       swap(saved_load_ids, variable_load_ids);
        writer.write_op_label(false_label_id);
        ternary.false_expr->visit(*this);
        Id false_result_id = r_expression_result_id;
        false_label_id = writer.get_current_block();
 
        writer.write_op_label(merge_block_id);
+       prune_loads(true_label_id);
        r_expression_result_id = begin_expression(OP_PHI, get_id(*ternary.type), 4);
        writer.write(true_result_id);
        writer.write(true_label_id);