Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/execution/ImageTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,43 @@ void RunTests(AgcDriver::VulkanDevice& device) {
Require(!Faulted(classes), "image table: valid entries faulted:\n" + classes.log);
Require(classes.imageTableCount == 3u, "image table: the table binding does not hold one element per distinct T# (" + std::to_string(classes.imageTableCount) + ")");

constexpr std::size_t sample = 19u;
const auto adjustedCode = [&] {
static_assert(TableCode[sample] == 0xf09c8f08u);
std::array<std::uint32_t, TableCode.size() + 2u> code{};
std::copy_n(TableCode.begin(), sample, code.begin());
code[sample] = 0x8823ff23u;
code[sample + 1u] = 0x1000u;
std::copy(TableCode.begin() + sample, TableCode.end(), code.begin() + sample + 2u);
code[sample + 2u] = 0xf0808f09u;
return code;
}();
const auto adjusted = Run(device, adjustedCode, 6, Lanes, 64);
Require(!Faulted(adjusted), "adjusted sampler table: a valid record faulted:\n" + adjusted.log);
Require(adjusted.words == classes.words, "adjusted sampler table: the reference texels changed");

constexpr std::size_t afterAdjustedSample = sample + 4u;
constexpr std::array ordinarySampleAndMerge{0xf09c8f08u, 0x01090a01u, 0x38081504u, 0x380a1705u, 0x380c1906u, 0x380e1b07u};
std::array<std::uint32_t, adjustedCode.size() + ordinarySampleAndMerge.size()> mixedCode{};
const auto adjustedTail = adjustedCode.begin() + afterAdjustedSample;
auto next = std::copy(adjustedCode.begin(), adjustedTail, mixedCode.begin());
next = std::copy(ordinarySampleAndMerge.begin(), ordinarySampleAndMerge.end(), next);
std::copy(adjustedTail, adjustedCode.end(), next);
auto plainMixedCode = mixedCode;
plainMixedCode[sample] = 0xbf800000u;
plainMixedCode[sample + 1u] = 0xbf800000u;
const auto plainMixed = Run(device, plainMixedCode, 6, Lanes, 64);
Require(!Faulted(plainMixed) && plainMixed.words == classes.words, "mixed sampler table: ordinary and adjusted samples changed the reference texels");
bool rejected = false;
try {
static_cast<void>(Run(device, mixedCode, 6, Lanes, 64));
} catch (const std::runtime_error& error) {
const std::string message = error.what();
if (message.find("GetSamplerResource dword ") == std::string::npos || message.find("is not a valid runtime value") == std::string::npos) throw;
rejected = true;
}
Require(rejected, "mixed sampler table: an ordinary use lost its dword-3 expression");

const auto invariantPhiCode = [] {
std::array<std::uint32_t, 39> code{};
std::copy_n(TableCode.begin(), 19, code.begin());
Expand Down
11 changes: 11 additions & 0 deletions core/shader/recompiler/Optimization/src/ResourceTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ class Tracker {
}
}

IrValue* tableSamplerDword3(IrValue& handle, IrValue* word) {
if (word->Opcode() != IrOpcode::BitwiseOr32) return word;
const auto onlyAdjusted = std::ranges::all_of(handle.Uses(), [&](const IrValue* use) {
if (!ImageOpcodeInfoOf(use->Opcode()).needsSampler || use->ArgumentCount() < 2u || use->Argument(1)->Resolve() != &handle) return false;
const auto index = use->Flags<MemoryFlags>().index;
return index < m_program.Resources().memoryInfo.size() && (m_program.Resources().memoryInfo[index].imageSampleFlags & RdnaImageSampleFlagAdjust) != 0u;
});
return onlyAdjusted ? canonicalizeSampleAdjustDword3(word) : word;
}

bool ValidateSource(const DescriptorSource& descriptor, std::uint32_t& badDword) const {
constexpr SrtWalker walker;
for (std::uint32_t i = 0; i < descriptor.dwordCount; i++) {
Expand Down Expand Up @@ -853,6 +863,7 @@ class Tracker {
for (std::uint32_t dword = 0; dword < words; dword++) {
IrValue* read = ResolveInvariantPhi(m_program.Resources(), handle.Argument(dword));
if (read == nullptr) return false;
if (sampler && dword == 3u) read = tableSamplerDword3(handle, read);
std::uint32_t memoryIndex = 0;
const MemoryInfo* memory = ScalarReadMemory(*read, memoryIndex);
const bool addressRead = memory == nullptr && (memory = ScalarAddressMemory(*read, memoryIndex)) != nullptr;
Expand Down
Loading