mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-28 13:56:59 +01:00
shader: emit constant-true guarded blocks inline and fold immediate constant-buffer indices
This commit is contained in:
@@ -580,6 +580,10 @@ auto EmitIndexSwitch(EmitterState& state, uint32_t index, uint32_t count,
|
|||||||
|
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void EmitIfCondition(EmitterState& state, uint32_t condition, Fn&& 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 then_label = state.builder.AllocateId();
|
||||||
const auto merge_label = state.builder.AllocateId();
|
const auto merge_label = state.builder.AllocateId();
|
||||||
state.builder.AddFunction(spv::OpSelectionMerge, merge_label, spv::SelectionControlMaskNone);
|
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>
|
template <typename Fn>
|
||||||
uint32_t EmitValueOrDefaultIfCondition(EmitterState& state, uint32_t condition, uint32_t type,
|
uint32_t EmitValueOrDefaultIfCondition(EmitterState& state, uint32_t condition, uint32_t type,
|
||||||
uint32_t default_value, Fn&& fn) {
|
uint32_t default_value, Fn&& fn) {
|
||||||
|
if (condition == ConstantBool(state, true)) return fn();
|
||||||
const auto then_label = state.builder.AllocateId();
|
const auto then_label = state.builder.AllocateId();
|
||||||
const auto header = state.current_label;
|
const auto header = state.current_label;
|
||||||
const auto merge_label = state.builder.AllocateId();
|
const auto merge_label = state.builder.AllocateId();
|
||||||
|
|||||||
@@ -1605,9 +1605,12 @@ void EmitReadConstBuffer(ValueEmitContext& ctx, const IR::Inst& inst) {
|
|||||||
}
|
}
|
||||||
auto& state = ctx.state;
|
auto& state = ctx.state;
|
||||||
mem.kind = IR::ResourceKind::ScalarBuffer;
|
mem.kind = IR::ResourceKind::ScalarBuffer;
|
||||||
auto index = Binary(state, spv::OpShiftRightLogical, TypeU32(state), ctx.Arg(inst, 1),
|
const auto offset = inst.Arg(1).Resolve();
|
||||||
ConstantU32(state, 2));
|
auto index = offset.IsImmediate()
|
||||||
if (mem.offset >= 4u) {
|
? 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));
|
index = Binary(state, spv::OpIAdd, TypeU32(state), index, ConstantU32(state, mem.offset >> 2u));
|
||||||
}
|
}
|
||||||
const auto access = PrepareMemoryResourceAccess(state, mem);
|
const auto access = PrepareMemoryResourceAccess(state, mem);
|
||||||
|
|||||||
@@ -10532,6 +10532,7 @@ void TestComputeDispatchWaveSize() {
|
|||||||
|
|
||||||
void TestNewShaderRecompilerBufferLoadsGuardedByExec() {
|
void TestNewShaderRecompilerBufferLoadsGuardedByExec() {
|
||||||
const uint32_t shader[] = {
|
const uint32_t shader[] = {
|
||||||
|
EncodeVopc(0xd4, 0 + 256, 1), // v_cmpx_gt_u32 v0, v1
|
||||||
EncodeMubuf0(0x0c),
|
EncodeMubuf0(0x0c),
|
||||||
EncodeMubuf1(0, 0, 1), // buffer_load_dword
|
EncodeMubuf1(0, 0, 1), // buffer_load_dword
|
||||||
// v0
|
// v0
|
||||||
|
|||||||
Reference in New Issue
Block a user