diff --git a/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp b/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp index 7a3fbb1c33..ce5555e884 100644 --- a/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp +++ b/core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp @@ -1101,11 +1101,11 @@ uint32_t LoadIndirectScalarBuffer(ValueEmitContext& ctx, const IR::Inst& inst) { Unary(state, spv::OpUConvert, TypeU64(state), EmitUMax32(state, stride, ConstantU32(state, 1))), Unary(state, spv::OpUConvert, TypeU64(state), ctx.Arg(handle, 2))); - const auto offset = Binary(state, spv::OpIAdd, TypeU64(state), - Unary(state, spv::OpUConvert, TypeU64(state), - Binary(state, spv::OpBitwiseAnd, TypeU32(state), - ctx.Arg(inst, 1), ConstantU32(state, ~3u))), - ConstantU64(state, ctx.Memory(inst).offset & ~3u)); + const auto offset = Binary(state, spv::OpBitwiseAnd, TypeU64(state), + Binary(state, spv::OpIAdd, TypeU64(state), + Unary(state, spv::OpUConvert, TypeU64(state), ctx.Arg(inst, 1)), + ConstantU64(state, ctx.Memory(inst).offset)), + ConstantU64(state, ~uint64_t {3})); const auto end = Binary(state, spv::OpIAdd, TypeU64(state), offset, ConstantU64(state, sizeof(uint32_t))); const auto scalar_address = [&]() { @@ -2608,6 +2608,7 @@ uint32_t EmitReadConst(ValueEmitContext& ctx, const IR::Inst& inst) { void EmitReadConstBuffer(ValueEmitContext& ctx, const IR::Inst& inst) { auto mem = ctx.Memory(inst); if (mem.planning_only) return; + if (static_cast(mem.offset) < 0) ctx.Fail(inst, "has a negative scalar buffer immediate offset"); if (mem.kind == IR::ResourceKind::IndirectBuffer) { ctx.Define(inst, LoadIndirectScalarBuffer(ctx, inst)); return; @@ -2615,12 +2616,26 @@ void EmitReadConstBuffer(ValueEmitContext& ctx, const IR::Inst& inst) { auto& state = ctx.state; mem.kind = IR::ResourceKind::ScalarBuffer; 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 static_index = offset.IsImmediate() + ? static_cast((uint64_t {offset.U32()} + mem.offset) >> 2u) + : 0u; + auto index = offset.IsImmediate() + ? ConstantU32(state, static_index) + : Binary(state, spv::OpShiftRightLogical, TypeU32(state), ctx.Arg(inst, 1), + ConstantU32(state, 2)); + if (!offset.IsImmediate() && mem.offset != 0u) { + if ((mem.offset & 3u) != 0u) { + const auto low = Binary(state, spv::OpBitwiseAnd, TypeU32(state), ctx.Arg(inst, 1), + ConstantU32(state, 3)); + const auto carry = Binary(state, spv::OpIAdd, TypeU32(state), low, + ConstantU32(state, mem.offset)); + index = Binary(state, spv::OpIAdd, TypeU32(state), index, + Binary(state, spv::OpShiftRightLogical, TypeU32(state), carry, + ConstantU32(state, 2))); + } else { + index = Binary(state, spv::OpIAdd, TypeU32(state), index, + ConstantU32(state, mem.offset >> 2u)); + } } const auto storage_load = [&]() { const auto access = PrepareMemoryResourceAccess(state, mem); @@ -2629,7 +2644,7 @@ void EmitReadConstBuffer(ValueEmitContext& ctx, const IR::Inst& inst) { ConstantU32(state, 2))); constexpr uint32_t last_element = UINT32_MAX >> 2u; if (state.profile.robust_buffer_access && - (!offset.IsImmediate() || (offset.U32() >> 2u) + (mem.offset >> 2u) > last_element - 63u)) { + (!offset.IsImmediate() || static_index > last_element - 63u)) { element = EmitGlsl(state, element, ConstantU32(state, last_element)); } const auto condition = EmitStorageElementInBounds(state, access, element); @@ -2662,7 +2677,7 @@ void EmitReadConstBuffer(ValueEmitContext& ctx, const IR::Inst& inst) { }; constexpr uint32_t uniform_words = IR::UniformBufferBytes / sizeof(uint32_t); constexpr uint32_t base_words = IR::UniformBufferBaseSlack / sizeof(uint32_t); - if (offset.IsImmediate() && (offset.U32() >> 2u) + (mem.offset >> 2u) < uniform_words - base_words) { + if (offset.IsImmediate() && static_index < uniform_words - base_words) { ctx.Define(inst, bounded_load()); return; } diff --git a/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp b/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp index d5625623bf..44ad99bfc4 100644 --- a/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp +++ b/core/kyty/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp @@ -573,13 +573,14 @@ bool ResolveSelectorKeys(const ResourcePlan& program, const DescriptorSource::In } else { ShaderBufferResource material; if (!DecodeBufferDescriptor(material_value, material) || selector->stride < 4u || - !std::has_single_bit(selector->stride) || (selector->offset & 3u) != 0u) + !std::has_single_bit(selector->stride) || + ((selector->offset & 3u) != 0u && indirect.selector_byte_bias.IsEmpty())) return false; const auto domain_count = (uint64_t {1} << 32u) / selector->stride; uint32_t bias = 0; if (!indirect.selector_byte_bias.IsEmpty() && !WalkedValue(program, indirect.selector_byte_bias, bias)) return false; - const auto first = uint64_t {selector->offset} + ((bias % selector->stride) & ~3u); + const auto first = (uint64_t {selector->offset} + (bias % selector->stride)) & ~uint64_t {3}; const auto available = material.GetSize() > first ? material.GetSize() - first : 0u; const auto count = std::min(domain_count, available < 4u ? 0u : (available - 4u) / selector->stride + 1u); @@ -660,6 +661,9 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p "read_address={:#x} requested_bytes={}", row, child, base, offset, (base & AddressMask & ~uint64_t {3}) + (offset & ~uint64_t {3}), bytes)); }; + const auto scalar_buffer_offset = [&](uint64_t offset) { + return (offset + indirect.table_immediate) & ~uint64_t {3}; + }; const auto normalization_failed = [&](uint64_t offset, uint32_t key, uint64_t step, std::string_view key_kind) { return failed("candidate", fmt::format("candidate_offset={:#x} {}={} stride={} step={}", @@ -672,7 +676,7 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p table_base = table.Base48(); table_size = table.GetSize(); descriptors[resource_index] = {.dword_count = dword_count}; - const uint64_t first = uint64_t {indirect.table_offset & ~3u} + (indirect.table_immediate & ~3u); + const uint64_t first = scalar_buffer_offset(indirect.table_offset); const uint64_t rows = table_size >= first + 8u ? (table_size - first - 8u) / indirect.table_stride + 1u : 0u; std::vector words(table_size / 4u); @@ -684,8 +688,9 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p }; std::optional function_slot; if (pointer.function != 0u) { + const auto pointer_slot = first - (indirect.table_offset & ~3u); for (uint64_t slot = 0; slot + 8u <= indirect.table_stride && !function_slot; slot += 8u) { - if (slot == (indirect.table_immediate & ~7u)) continue; + if (slot < pointer_slot + 8u && pointer_slot < slot + 8u) continue; for (uint64_t row = 0; row < rows; ++row) { if (((indirect.table_offset & ~3u) + row * indirect.table_stride + slot + 8u) > table_size) break; if ((row_word(row, (indirect.table_offset & ~3u) + slot) & AddressMask) == @@ -943,8 +948,8 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p : 4u; uint64_t first = 0u; if (table_value.dword_count != 2u) - first = ((indirect.table_maximum ? indirect.table_offset : indirect.table_offset % step) & - ~uint64_t {3}) + (indirect.table_immediate & ~3u); + first = scalar_buffer_offset(indirect.table_maximum ? indirect.table_offset + : indirect.table_offset % step); if (!indirect.table_maximum) domain /= step; const auto count = table_size >= first + 4u ? std::min((table_size - first - 4u) / step + 1u, domain) @@ -1131,8 +1136,10 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p byte_offsets.clear(); byte_offsets.reserve(keys.size()); for (const auto key: keys) { - const auto offset = uint64_t {(key * indirect.table_stride + indirect.table_offset) & ~3u} + - (indirect.table_immediate & ~3u); + const auto indexed_offset = uint64_t {key * indirect.table_stride + indirect.table_offset}; + const auto offset = table_value.dword_count == 4u + ? scalar_buffer_offset(indexed_offset) + : (indexed_offset & ~uint64_t {3}) + (indirect.table_immediate & ~3u); byte_offsets.push_back(offset <= UINT32_MAX ? static_cast(offset) : UINT32_MAX); } std::ranges::sort(byte_offsets); @@ -1157,9 +1164,11 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p DescriptorValue candidate; candidate.dword_count = dword_count; if (sources.empty()) { + const auto indexed_offset = uint64_t {key * indirect.table_stride + indirect.table_offset}; table_offset = byte_keys ? key - : uint64_t {(key * indirect.table_stride + indirect.table_offset) & ~3u} + - (indirect.table_immediate & ~3u); + : table_value.dword_count == 4u ? scalar_buffer_offset(indexed_offset) + : (indexed_offset & ~uint64_t {3}) + + (indirect.table_immediate & ~3u); if (!(byte_keys && key == UINT32_MAX) && table_offset <= UINT32_MAX && !ReadScalarTable(table_base, table_size, table_offset, runtime, std::span(candidate.dwords).first(read_dwords))) { diff --git a/core/kyty/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp b/core/kyty/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp index 7e3afa421b..43e42ab32b 100644 --- a/core/kyty/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp +++ b/core/kyty/graphics/shader/recompiler/ir/passes/ResourceTracking.cpp @@ -608,8 +608,9 @@ class Tracker { offset = emit(ValueOpcode::ISub32, {dynamic, Value(indirect.table_offset)}); valid = emit(ValueOpcode::ULessThanEqual32, {Value(indirect.table_offset), dynamic}); } else { - offset = emit(ValueOpcode::IAdd32, {dynamic, Value(memory.offset & ~3u)}); - valid = emit(ValueOpcode::ULessThanEqual32, {dynamic, offset}); + const auto sum = emit(ValueOpcode::IAdd32, {read.Arg(1), Value(memory.offset)}); + offset = emit(ValueOpcode::BitwiseAnd32, {sum, Value(~3u)}); + valid = emit(ValueOpcode::ULessThanEqual32, {read.Arg(1), sum}); } } key = emit(ValueOpcode::SelectU32, {valid, offset, Value(UINT32_MAX)}); @@ -2765,9 +2766,14 @@ class Tracker { } if (require_bound && count.IsEmpty() && workgroup_axis == UINT32_MAX && !rows) return false; if (!MakeRuntimeTableSource(*read, material_source)) return false; + if (memory->kind == ResourceKind::ScalarBuffer && + uint64_t {offset} + memory->offset > UINT32_MAX) return false; selector.source = InternSource(material_source); selector.stride = stride; - selector.offset = offset + (memory->offset & ~3u); + selector.offset = memory->kind == ResourceKind::ScalarBuffer + ? static_cast((uint64_t {offset} + memory->offset) & + (byte_bias.IsEmpty() ? ~uint64_t {3} : UINT32_MAX)) + : offset + (memory->offset & ~3u); indirect.selector = std::move(selector); indirect.selector_byte_bias = byte_bias; indirect.key_count = count; @@ -3210,6 +3216,11 @@ class Tracker { Inst* table_handle = nullptr; Value table_guard; const uint32_t alignment_mask = allow_fixed ? ~3u : UINT32_MAX; + const auto physical_offset = [&](uint32_t offset, uint32_t immediate, ResourceKind kind) { + return allow_fixed && kind == ResourceKind::ScalarBuffer + ? (uint64_t {offset} + immediate) & ~uint64_t {3} + : uint64_t {offset & alignment_mask} + (immediate & alignment_mask); + }; for (uint32_t dword = 0; dword < plan.read_dwords; ++dword) { auto* read = descriptor.dwords[dword].Resolve().TryInstruction(); if (read == nullptr) { @@ -3276,10 +3287,11 @@ class Tracker { table_stride = stride; if (table_mask != nullptr) *table_mask = mask; } else if (plan.table_indexed != indexed || table_stride != stride || + memory->kind != m_program.memory_info[plan.memory[0]].kind || !EquivalentValue(m_program, key, current_key) || - uint64_t {table_offset & alignment_mask} + (table_immediate & alignment_mask) + + physical_offset(table_offset, table_immediate, memory->kind) + dword * sizeof(uint32_t) != - uint64_t {offset & alignment_mask} + (memory->offset & alignment_mask)) { + physical_offset(offset, memory->offset, memory->kind)) { return false; } plan.split_offsets |= !indexed && offset != table_offset; @@ -3357,16 +3369,17 @@ class Tracker { low_memory->kind != ResourceKind::ScalarBuffer || high_memory->kind != ResourceKind::ScalarBuffer || low_memory->offset > INT32_MAX || high_memory->offset > INT32_MAX || - (low_memory->offset & ~3u) + 4u != (high_memory->offset & ~3u) || !EquivalentValue(m_program, low->Arg(0), high->Arg(0)) || !EquivalentValue(m_program, low->Arg(1), high->Arg(1)) || !AvailableBefore(*low, *pointer) || !AvailableBefore(*high, *pointer) || !MatchTableOffset(low->Arg(1), key, indirect.table_offset, indirect.table_stride) || + ((uint64_t {indirect.table_offset} + low_memory->offset) & ~uint64_t {3}) + 4u != + ((uint64_t {indirect.table_offset} + high_memory->offset) & ~uint64_t {3}) || indirect.table_stride < 8u || (indirect.table_stride & 3u) != 0u || !SetExactTableMaximum(key, indirect) || (key.TryInstruction() != nullptr && !AvailableBefore(*key.Instruction(), handle)) || !MakeRuntimeTableSource(*low, table_source)) return false; - indirect.table_immediate = low_memory->offset & ~3u; + indirect.table_immediate = low_memory->offset; } else { if (handle.GetOpcode() != ValueOpcode::GetImageResource || !ImmediateU32(UnsignedResourceBound(child_key, handle), child.count) || child.count == 0u || @@ -3598,13 +3611,14 @@ class Tracker { low_memory->kind != ResourceKind::ScalarBuffer || high_memory->kind != ResourceKind::ScalarBuffer || low_memory->offset > INT32_MAX || high_memory->offset > INT32_MAX || - (low_memory->offset & ~3u) + 4u != (high_memory->offset & ~3u) || !EquivalentValue(m_program, low->Arg(0), high->Arg(0)) || !EquivalentValue(m_program, low->Arg(1), high->Arg(1)) || !MatchTableOffset(low->Arg(1), row_key, indirect.table_offset, indirect.table_stride) || + ((uint64_t {indirect.table_offset} + low_memory->offset) & ~uint64_t {3}) + 4u != + ((uint64_t {indirect.table_offset} + high_memory->offset) & ~uint64_t {3}) || row_key.IsEmpty() || indirect.table_stride < 8u || (indirect.table_stride & 3u) != 0u || !MakeRuntimeTableSource(*low, table_source) || table_source.dword_count != 4u) return false; - indirect.table_immediate = low_memory->offset & ~3u; + indirect.table_immediate = low_memory->offset; indirect.table_source = InternSource(table_source); indirect.table_scalar = true; uint64_t function = 0; @@ -3615,11 +3629,12 @@ class Tracker { functions = body.aliases; } } + if (uint64_t {element_offset} + element_immediate > UINT32_MAX) return false; indirect.pointer_table = DescriptorSource::IndirectDescriptor::PointerTable { .offset = record_offset, .buffer = true, .element_stride = element_stride, - .element_offset = (element_offset & ~3u) + (element_immediate & ~3u), + .element_offset = (element_offset + element_immediate) & ~3u, .function = function, .functions = std::move(functions)}; DescriptorSource source; diff --git a/core/kyty/graphics/shader/recompiler/ir/passes/SrtWalker.cpp b/core/kyty/graphics/shader/recompiler/ir/passes/SrtWalker.cpp index 0751f98c7c..3d5397db77 100644 --- a/core/kyty/graphics/shader/recompiler/ir/passes/SrtWalker.cpp +++ b/core/kyty/graphics/shader/recompiler/ir/passes/SrtWalker.cpp @@ -1309,13 +1309,17 @@ void WalkerCompiler::EmitRead(const Node& node, uint32_t index) { } if (!args.empty()) { for (const auto& arg: args) Branch(arg, m_ret); - const auto immediate = - static_cast(static_cast(m_plan.memory_info[inst.Flags().index].offset)) & - ~int64_t {3}; - const auto constant = int64_t {static_cast(args[2].value) & ~3u} + immediate; + const auto raw_immediate = + static_cast(static_cast(m_plan.memory_info[inst.Flags().index].offset)); + const auto scalar_buffer = op == ValueOpcode::ReadConstBuffer && (raw_immediate & 3) != 0; + const auto immediate = raw_immediate & ~int64_t {3}; + const auto constant = scalar_buffer + ? (int64_t {static_cast(args[2].value)} + raw_immediate) & ~int64_t {3} + : int64_t {static_cast(args[2].value) & ~3u} + immediate; const bool folded = args[2].kind == Kind::Constant && constant + 4 <= INT32_MAX; const auto offset = folded ? Xbyak::RegExp(static_cast(constant)) - : c.r9 + static_cast(immediate); + : scalar_buffer ? Xbyak::RegExp(c.r9) + : c.r9 + static_cast(immediate); if (args[0].kind == Kind::UserData && args[1].kind == Kind::UserData) { c.mov(c.rax, c.qword[At(m_bases.at({args[0].value, args[1].value}))]); } else { @@ -1323,7 +1327,13 @@ void WalkerCompiler::EmitRead(const Node& node, uint32_t index) { } if (!folded) { Load(c.r9, args[2]); - c.and_(c.r9d, ~3u); + if (scalar_buffer) { + c.mov(c.r9d, c.r9d); + c.add(c.r9, static_cast(raw_immediate)); + c.and_(c.r9, ~3u); + } else { + c.and_(c.r9d, ~3u); + } } c.lea(c.r10, c.ptr[c.rax + offset]); if (op == ValueOpcode::LoadAddressU32) { diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarLoads.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarLoads.cpp index 8725971d54..731d504f11 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarLoads.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarLoads.cpp @@ -299,13 +299,15 @@ const IR::Inst* ReadLaneSource(IR::Value value) { } } -enum class RecordIndex { UserData, FirstLane, Waterfall }; +enum class RecordIndex { UserData, FirstLane, Waterfall, CombinedOffsets, OverlappingOffsets }; void RuntimeOffsetDescriptors(RecordIndex index) { - const bool waterfall = index == RecordIndex::Waterfall; + const bool overlap = index == RecordIndex::OverlappingOffsets; + const bool combined = index == RecordIndex::CombinedOffsets || overlap; + const bool waterfall = index == RecordIndex::Waterfall || combined; const bool wave_record = index != RecordIndex::UserData; - const uint32_t sampler_field = waterfall ? 128u : 8u; - const uint32_t image_field = waterfall ? 64u : 0u; + const uint32_t sampler_field = combined ? (overlap ? 1u : 5u) : waterfall ? 128u : 8u; + const uint32_t image_field = combined ? (overlap ? 4u : 1u) : waterfall ? 64u : 0u; std::vector code; uint32_t loop_start = 0; if (waterfall) { @@ -376,15 +378,22 @@ void RuntimeOffsetDescriptors(RecordIndex index) { }; bind_table(0, sampler_table, sizeof(samplers)); bind_table(4, image_table, sizeof(images)); - bind_table(8, ConstantAddress, waterfall ? 160u : 96u); - if (waterfall) user_data[13] = 5u; + bind_table(8, ConstantAddress, combined ? 32u : waterfall ? 160u : 96u); + if (waterfall) user_data[13] = combined ? 3u : 5u; const IR::SrtRuntime runtime {.user_data = user_data, .read_specialization_memory = ReadMemory}; IR::ResourceSpecialization specialization; for (uint32_t record = 0; record < 2u; ++record) { - const auto address = ConstantAddress + (waterfall ? 4u + record * 16u : record * 48u); - if (waterfall) Poke(address - 4u + sampler_field, 7u); - Poke(address + image_field, 1u - record); - Poke(address + sampler_field, record); + if (combined) { + const auto address = ConstantAddress + record * 16u; + Poke(address, 7u); + Poke(address + 4u, overlap ? record : 0u); + Poke(address + 8u, overlap ? 7u : record); + } else { + const auto address = ConstantAddress + (waterfall ? 4u + record * 16u : record * 48u); + if (waterfall) Poke(address - 4u + sampler_field, 7u); + Poke(address + image_field, 1u - record); + Poke(address + sampler_field, record); + } } IR::ResourceSnapshot snapshot; for (uint32_t record = 0; record < 2u; ++record) { @@ -395,7 +404,7 @@ void RuntimeOffsetDescriptors(RecordIndex index) { return; } const auto sampler = record; - const auto image = 1u - record; + const auto image = overlap ? record : combined ? 0u : 1u - record; auto selected_image = snapshot.images.at(0); uint32_t selected_sampler = 0; if (wave_record) { @@ -403,8 +412,10 @@ void RuntimeOffsetDescriptors(RecordIndex index) { selected_image = table.slots.at(table.mapping.at(1u + image)); const auto offset = specialization.samplers.at(0).indirect_mapping_offset; const auto& mapping = snapshot.flattened_srt; - Check(mapping.at(offset) == 2u && mapping.at(offset + 1u + sampler * 2u) == sampler, - "both record keys occur in the sampler mapping"); + const bool sampler_keys = + mapping.at(offset) == 2u && mapping.at(offset + 1u + sampler * 2u) == sampler; + Check(sampler_keys, "both record keys occur in the sampler mapping"); + if (combined && !sampler_keys) return; selected_sampler = mapping.at(offset + 2u + sampler * 2u); } Check(selected_image.dwords == images[image], "the sample uses the selected texture"); @@ -447,6 +458,8 @@ int main() { RuntimeOffsetDescriptors(RecordIndex::FirstLane); try { RuntimeOffsetDescriptors(RecordIndex::Waterfall); + RuntimeOffsetDescriptors(RecordIndex::CombinedOffsets); + RuntimeOffsetDescriptors(RecordIndex::OverlappingOffsets); } catch (const Common::SoftExitError& error) { Check(false, error.what()); } diff --git a/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarReplay.cpp b/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarReplay.cpp index 00b66296e4..03cea47abc 100644 --- a/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarReplay.cpp +++ b/core/libs/prx/libSceAgcDriver/KytyShim/tests/UniformScalarReplay.cpp @@ -53,6 +53,12 @@ struct Case { std::uint32_t offset; }; +struct OffsetCase { + Case test; + std::uint32_t immediate; + std::uint32_t equivalent; +}; + constexpr std::array Cases{ Case{"aligned", Input, 0x100u, 0x24u}, Case{"unaligned", Input + 0x44u, 0x100u, 0x24u}, @@ -241,6 +247,30 @@ int main(int argc, char** argv) { std::cerr << test.name << ": " << failure << '\n'; printTail(scalar.log); } + constexpr std::array combined_cases { + OffsetCase{Case{"combined offset in bounds", Input, 8u, 3u}, 1u, 4u}, + OffsetCase{Case{"combined offset outside", Input, 4u, 3u}, 1u, 4u}, + OffsetCase{Case{"combined offset without carry", Input, 8u, 2u}, 1u, 0u}, + }; + for (std::size_t index = 0; index < combined_cases.size(); ++index) { + const auto& offset_case = combined_cases[index]; + auto combined_words = ScalarWords; + combined_words[1] = 0x10000000u | offset_case.immediate; + auto single_words = ScalarWords; + single_words[1] = 0xfa000000u | offset_case.equivalent; + const auto combined = replay(tool, root / ("combined-" + std::to_string(index)), offset_case.test, + combined_words); + const auto single = replay(tool, root / ("single-" + std::to_string(index)), offset_case.test, + single_words); + if (combined.completed && single.completed && combined.frame == single.frame) { + std::cout << offset_case.test.name << ": ok\n"; + continue; + } + ++failures; + std::cerr << offset_case.test.name << ": combining the register and immediate offsets changed the scalar load\n"; + printTail(combined.log); + printTail(single.log); + } if (failures != 0) return 1; std::filesystem::remove_all(root); std::cout << "kyty_shim_uniform_scalar_replay: ok\n"; diff --git a/docs/dev/debt/changes/fix-kyty-sbuffer-offset-alignment.md b/docs/dev/debt/changes/fix-kyty-sbuffer-offset-alignment.md new file mode 100644 index 0000000000..0fba22f7ca --- /dev/null +++ b/docs/dev/debt/changes/fix-kyty-sbuffer-offset-alignment.md @@ -0,0 +1,5 @@ +# kyty + +## add Functional + +- [Scalar buffer load offsets](../../../core/kyty/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp) have not been measured on PS5 hardware when the low bits of `SOFFSET` and the instruction immediate carry into the next dword. The implementation combines the byte offsets before alignment as [RDNA2 ISA section 7.2.1](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) specifies. Synthetic replay covers a carry, no carry and a crossed bound; the console result remains unverified. Closes when a PS5 hardware oracle measures those cases, including a multi-dword load at the bound.