Skip to content
Merged
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
58 changes: 58 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,63 @@ void verifyDescriptorPhis() {
expectFailure([&] { static_cast<void>(planImages(splitReloads(260u))); }, "GetImageResource dword 0 is not a valid runtime value", "descriptor Phi: a web over more than 512 descriptor tuples was accepted");
}

void verifyUniformTableImage() {
using namespace ShaderRecompiler;
constexpr std::uint32_t Format8888UNorm = 56;
constexpr std::uint32_t Type2D = 9;
struct alignas(256) Texture { std::array<std::uint8_t, 256> bytes{}; };
static Texture textures[2];
struct alignas(4096) GuestTables {
std::array<std::array<std::uint32_t, 12>, 3> table{};
std::array<std::uint32_t, 4> output{};
std::array<std::uint32_t, 16> srt{};
};
static GuestTables guest;
const auto texture = [](const Texture& image) {
const auto base = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(image.bytes.data()));
return std::array<std::uint32_t, 8>{static_cast<std::uint32_t>(base >> 8u), static_cast<std::uint32_t>((base >> 40u) & 0xffu) | (Format8888UNorm << 20u) | (3u << 30u), 3u << 14u, 0xfacu | (Type2D << 28u), 0u, 0u, 0u, 0u};
};
const auto first = texture(textures[0]);
const auto second = texture(textures[1]);
std::copy(first.begin(), first.end(), guest.table[1].begin() + 4);
std::copy(second.begin(), second.end(), guest.table[2].begin() + 4);
const auto bufferDescriptor = [](const void* base, std::uint32_t records) {
const auto address = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(base));
return std::array<std::uint32_t, 4>{static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu), records, 0xfacu};
};
const auto tableV = bufferDescriptor(guest.table.data(), static_cast<std::uint32_t>(sizeof(guest.table)));
const auto outputV = bufferDescriptor(guest.output.data(), 16u);
std::copy(tableV.begin(), tableV.end(), guest.srt.begin());
std::copy(outputV.begin(), outputV.end(), guest.srt.begin() + 12);
const auto srtAddress = static_cast<std::uint64_t>(reinterpret_cast<std::uintptr_t>(guest.srt.data()));
std::array<std::uint32_t, 3> userData{static_cast<std::uint32_t>(srtAddress), static_cast<std::uint32_t>(srtAddress >> 32u), 2u};
const std::array<std::uint32_t, 4> capabilities{29u, spv::CapabilityInt64, spv::CapabilityPhysicalStorageBufferAddresses, spv::CapabilityStorageBuffer8BitAccess};
const std::array<std::string_view, 2> extensions{"SPV_KHR_physical_storage_buffer", "SPV_KHR_8bit_storage"};
const std::vector<std::uint32_t> code{0xf4080100u, 0xfa000000u, 0xf4080200u, 0xfa000010u, 0xf4080700u, 0xfa000030u, 0x9310b002u, 0xf42c0502u, 0x20000010u, 0xf09c0f08u, 0x00450000u, 0xe0700000u, 0x80070000u, 0xbf810000u};
RecompileRequest request{};
request.shader = {ShaderStage::Compute, 0x20000u, code, 0, {}};
request.context.waveSize = 64;
request.context.userDataBaseRegister = 0;
request.context.userData = userData;
request.context.compute = ShaderComputeStageInfo{{64u, 1u, 1u}, 0u, {false, false, false}, false, 1u};
request.target.vulkanVersion = 0x00401000u;
request.target.spirvVersion = 0x00010300u;
request.target.subgroupSize = 32;
request.target.supportedCapabilities = capabilities;
request.target.supportedExtensions = extensions;
request.target.bdaAbiVersion = BdaAbi::Version;
request.target.fragmentShaderBarycentricEnabled = false;
request.layout.pushConstantSizeBytes = 128;
const auto plan = GetResourcePlan(request);
require(plan->info.images.size() == 1u && !plan->descriptorSources.at(plan->info.images[0].source).indirectImage.has_value(), "uniform table image: the T# read from a constant buffer was not planned as one image");
for (const auto& [key, expected] : {std::pair{2u, second}, std::pair{1u, first}}) {
userData[2] = key;
AgcDriver::ShaderMemory memory({});
const auto capture = memory.Capture(request);
require(capture->snapshot.images.size() == 1u && std::equal(expected.begin(), expected.end(), capture->snapshot.images[0].dwords.begin()), "uniform table image: the T# of the record the user data selects was not read");
}
}

void verifyLaneSelectedDescriptors() {
std::vector<std::uint32_t> code{0xf40c0200u, 0xfa000000u, 0xf4080500u, 0xfa000020u, 0xf4080600u, 0xfa000040u, 0xf4000400u, 0xfa000050u, 0xf40c0800u, 0xfa000060u, 0xbf8cc07fu, 0x7d880090u, 0xbf068010u, 0xbf850011u};
for (std::uint32_t dword = 0; dword < 8u; dword++) {
Expand Down Expand Up @@ -3558,6 +3615,7 @@ int main(int argc, char** argv) {
verifyGuardedDescriptorSources();
verifyBindlessTable();
verifyDescriptorPhis();
verifyUniformTableImage();
verifyLaneSelectedDescriptors();
verifyProgramCounterRelativeData();
verifyLanesOutsideHostSubgroup();
Expand Down
9 changes: 0 additions & 9 deletions core/shader/recompiler/Optimization/src/ResourceTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,15 +1156,6 @@ class Tracker {
DescriptorSource descriptor;
MakeSource(*handle, width, sampler, sampleAdjust, descriptor);
std::uint32_t badDword = 0;
if (expected == IrOpcode::GetImageResource) {
for (; badDword < descriptor.dwordCount; badDword++) {
const IrValue* value2 = descriptor.dwords[badDword]->Resolve();
if (value2->Opcode() == IrOpcode::ReadConstBuffer) {
fail(std::string(IrOpcodeName(expected)) + " dword " + std::to_string(badDword) + " is not a valid runtime value; chain: " + describeValueChain(descriptor.dwords[badDword], 8u));
}
}
badDword = 0;
}
if (!ValidateSource(descriptor, badDword)) {
fail(std::string(IrOpcodeName(expected)) + " dword " + std::to_string(badDword) + " is not a valid runtime value; chain: " + describeValueChain(descriptor.dwords[badDword], 8u));
}
Expand Down
Loading