shader: emit constant-true guarded blocks inline and fold immediate constant-buffer indices

This commit is contained in:
nmzik
2026-10-21 23:26:07 +02:00
parent ae47ac26e7
commit 0f7d112545
3 changed files with 12 additions and 3 deletions
@@ -580,6 +580,10 @@ auto EmitIndexSwitch(EmitterState& state, uint32_t index, uint32_t count,
template <typename Fn>
void EmitIfCondition(EmitterState& state, uint32_t condition, Fn&& fn) {
if (condition == ConstantBool(state, true)) {
fn();
return;
}
const auto then_label = state.builder.AllocateId();
const auto merge_label = state.builder.AllocateId();
state.builder.AddFunction(spv::OpSelectionMerge, merge_label, spv::SelectionControlMaskNone);
@@ -593,6 +597,7 @@ void EmitIfCondition(EmitterState& state, uint32_t condition, Fn&& fn) {
template <typename Fn>
uint32_t EmitValueOrDefaultIfCondition(EmitterState& state, uint32_t condition, uint32_t type,
uint32_t default_value, Fn&& fn) {
if (condition == ConstantBool(state, true)) return fn();
const auto then_label = state.builder.AllocateId();
const auto header = state.current_label;
const auto merge_label = state.builder.AllocateId();