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
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,21 @@ void DecodeInstruction(std::span<const uint32_t> code, uint32_t word_index, Inst
}
}

uint32_t ExecWaveSize(const Program& program) {
bool narrow = false;
bool wide = false;
for (const auto& inst: program.instructions) {
if (inst.dst.kind == OperandKind::ExecHi) return 64u;
const auto name = magic_enum::enum_name(inst.opcode);
if (!name.starts_with("S_")) continue;
if (inst.dst.kind != OperandKind::ExecLo && name.find("SAVEEXEC") == std::string_view::npos) continue;
const bool pair = name.find("_B64") != std::string_view::npos;
narrow = narrow || (!pair && name.ends_with("_B32"));
wide = wide || pair;
}
return narrow == wide ? 0u : narrow ? 32u : 64u;
}

Program DecodeFrontProgram(std::span<const uint32_t> front) {
Program result;
uint32_t front_words = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ struct Program {
Family GetInstructionFamily(uint32_t word);
void DecodeInstruction(std::span<const uint32_t> code, uint32_t word_index, Instruction& inst);
Program DecodeFrontProgram(std::span<const uint32_t> front);
[[nodiscard]] uint32_t ExecWaveSize(const Program& program);
void DecodeProgram(std::span<const uint32_t> code, Program& program,
std::span<const LongBranch> long_branches = {});
bool IsConditionalBranch(Opcode opcode);
Expand Down
27 changes: 27 additions & 0 deletions core/libs/prx/libSceAgcDriver/KytyShim/tests/RtOracle.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "graphics/shader/recompiler/frontend/decode/ShaderDecoder.h"
#include "graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h"
#include "graphics/shader/recompiler/ir/Block.h"
#include "graphics/shader/recompiler/ir/RayQuery.h"
Expand Down Expand Up @@ -404,6 +405,31 @@ void TwoTlasWalks() {
"two walks over one TLAS bind no extra source and keep the single-TLAS query");
}

void CodeWaveSize() {
namespace Decoder = Libs::Graphics::ShaderRecompiler::Decoder;
const auto wave = [](std::vector<uint32_t> code) {
code.push_back(0xbf810000u);
Decoder::Program program;
Decoder::DecodeProgram(code, program);
return Decoder::ExecWaveSize(program);
};
constexpr uint32_t mov_exec_lo = 0xbefe0300u;
constexpr uint32_t mov_exec = 0xbefe0400u;
constexpr uint32_t saveexec_b32 = 0xbe823c6au;
constexpr uint32_t saveexec_b64 = 0xbe82246au;
constexpr uint32_t mov_s2 = 0xbe820300u;
constexpr uint32_t mov_exec_hi = 0xbeff0300u;
constexpr uint32_t and_exec_lo = 0x877e007eu;
constexpr uint32_t and_exec = 0x87fe007eu;
Expect(wave({mov_exec_lo, saveexec_b32}) == 32u, "code that writes exec with 32-bit operations is wave32");
Expect(wave({mov_exec, saveexec_b64}) == 64u, "code that writes exec with 64-bit operations is wave64");
Expect(wave({saveexec_b32}) == 32u && wave({saveexec_b64}) == 64u, "a saveexec alone decides the width");
Expect(wave({mov_exec_lo, saveexec_b64}) == 0u, "code that mixes both widths has no known wave size");
Expect(wave({mov_s2}) == 0u && wave({}) == 0u, "code that never writes exec has no known wave size");
Expect(wave({mov_exec_lo, mov_exec_hi}) == 64u, "code that writes exec_hi is wave64 even with 32-bit operations");
Expect(wave({and_exec_lo}) == 32u && wave({and_exec}) == 64u, "a scalar ALU write to exec decides the width");
}

void RecordLayouts() {
constexpr std::array<uint32_t, 4> masked {0x76543210u, 0x3dc6ba98u, 0x000801dfu, 0u};
constexpr std::array<uint32_t, 4> plain {0x76543210u, 0x3dc6ba98u, 0u, 0u};
Expand Down Expand Up @@ -490,6 +516,7 @@ int main() {
PrologueFlag();
TwoTlasWalks();
RecordLayouts();
CodeWaveSize();
DescriptorHighWord();
Marking();
EmptyWalks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ requireLine("program ${cacheOnlyHash} stage=cs wave=64 group=8,8,1 lds=8192 scra
set(stopped "status=stop bvh=0 native=0 oracle=0 lane=0 empty=0 emulated=0 spirv=none[^\n]* phase=translate stop=shader_resource_tracking:[^\n]*buffer_descriptor_is_not_a_valid_runtime_value[^\n]*\n")
requireLine("program ${stoppingHash} stage=cs wave=32 group=8,8,1 lds=8192 scratch=16384 modules=0 source=code ${stopped}")
requireLine("program ${stoppingHash} stage=cs wave=64 group=8,8,1 lds=8192 scratch=16384 modules=0 source=code ${stopped}")
requireLine("summary records=4 manifest_modules=3 manifest_skipped=0 code_only=2 programs=5 intersections=3 missing_code=1 unreadable=0 undecodable=0 truncated=0 seconds=")
requireLine("summary records=4 manifest_modules=3 manifest_skipped=0 code_only=2 programs=5 intersections=3 code_only_wave_known=0 missing_code=1 unreadable=0 undecodable=0 truncated=0 seconds=")
if(stdout MATCHES "program ${plainHash}")
message(FATAL_ERROR "kyty_rt_probe --all listed a program without BVH intersections\n${stdout}")
endif()
Expand Down
14 changes: 11 additions & 3 deletions core/libs/prx/libSceAgcDriver/KytyShim/tools/RtSurvey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct Decoded {
std::uint32_t bvh = 0;
std::uint32_t exportsPosition = 0;
std::uint32_t exportsTarget = 0;
std::uint32_t wave = 0;
bool stopped = false;
};

Expand Down Expand Up @@ -258,6 +259,7 @@ Decoded Inspect(const Recompiler::ShaderSource& source) {
else if (inst.exp.target <= 8) ++decoded.exportsTarget;
}
}
decoded.wave = Recompiler::Decoder::ExecWaveSize(source.decoded);
return decoded;
}

Expand Down Expand Up @@ -504,6 +506,7 @@ int RunSurvey(const SurveySettings& settings) {
}

std::uint32_t orphans = 0;
std::uint32_t sized = 0;
std::vector<const CachedShaderEntry*> unlisted;
for (const auto& entry: index.entries) {
if (!listed.contains(entry.hash)) unlisted.push_back(&entry);
Expand Down Expand Up @@ -535,7 +538,12 @@ int RunSurvey(const SurveySettings& settings) {
rows.push_back(std::move(row));
continue;
}
for (const std::uint32_t wave: {64u, 32u}) {
std::vector<std::uint32_t> waves {64u, 32u};
if (decoded->wave != 0) {
waves = {decoded->wave};
++sized;
}
for (const std::uint32_t wave: waves) {
Prepared guess{DefaultComputeModule(wave), {}, {}};
guess.module.code_hash = entry->hash;
Prepare(guess, settings, {});
Expand All @@ -560,8 +568,8 @@ int RunSurvey(const SurveySettings& settings) {
}
const auto seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - begin).count();
std::printf("summary records=%zu manifest_modules=%zu manifest_skipped=%u code_only=%u programs=%u intersections=%u "
"missing_code=%u unreadable=%u undecodable=%u truncated=%d seconds=%.1f\n",
index.entries.size(), manifest.modules.size(), skipped, orphans, programs, intersections, missing, unreadable,
"code_only_wave_known=%u missing_code=%u unreadable=%u undecodable=%u truncated=%d seconds=%.1f\n",
index.entries.size(), manifest.modules.size(), skipped, orphans, programs, intersections, sized, missing, unreadable,
undecodable, index.truncated ? 1 : 0, seconds);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/rt_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def render_text(document, limit=60):
]
labels = (
("manifest", "Programs the game ran (pipeline manifest, inputs as the game set them)"),
("code", "Programs only in the code cache (inputs guessed, both wave sizes tried)"),
("code", "Programs only in the code cache (inputs guessed; wave size read from the code, both tried when the code does not show it)"),
)
for source, label in labels:
part = totals["bySource"][source]
Expand Down
Loading