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();
@@ -1605,9 +1605,12 @@ void EmitReadConstBuffer(ValueEmitContext& ctx, const IR::Inst& inst) {
}
auto& state = ctx.state;
mem.kind = IR::ResourceKind::ScalarBuffer;
auto index = Binary(state, spv::OpShiftRightLogical, TypeU32(state), ctx.Arg(inst, 1),
ConstantU32(state, 2));
if (mem.offset >= 4u) {
const auto offset = inst.Arg(1).Resolve();
auto index = offset.IsImmediate()
? ConstantU32(state, (offset.U32() >> 2u) + (mem.offset >> 2u))
: Binary(state, spv::OpShiftRightLogical, TypeU32(state),
ctx.Arg(inst, 1), ConstantU32(state, 2));
if (!offset.IsImmediate() && mem.offset >= 4u) {
index = Binary(state, spv::OpIAdd, TypeU32(state), index, ConstantU32(state, mem.offset >> 2u));
}
const auto access = PrepareMemoryResourceAccess(state, mem);
+1
View File
@@ -10532,6 +10532,7 @@ void TestComputeDispatchWaveSize() {
void TestNewShaderRecompilerBufferLoadsGuardedByExec() {
const uint32_t shader[] = {
EncodeVopc(0xd4, 0 + 256, 1), // v_cmpx_gt_u32 v0, v1
EncodeMubuf0(0x0c),
EncodeMubuf1(0, 0, 1), // buffer_load_dword
// v0