Skip to content

Instantly share code, notes, and snippets.

@FernandoS27
Created September 2, 2018 17:09
Show Gist options
  • Save FernandoS27/a85cdfd37c2f6eab784e75dd6648575b to your computer and use it in GitHub Desktop.
Save FernandoS27/a85cdfd37c2f6eab784e75dd6648575b to your computer and use it in GitHub Desktop.
bool IsSchedInstruction(u32 offset, u32 main_offset) {
// sched instructions appear once every 4 instructions.
static constexpr size_t SchedPeriod = 4;
u32 absolute_offset = offset - main_offset;
return (absolute_offset % SchedPeriod) == 0;
}
void ShaderDumper::dump() {
FileUtil::IOFile sFile;
std::string name = prefix + hashName();
sFile.Open(name, "w");
u32 start_offset = 10;
u32 offset = start_offset;
u64 size = 0;
while (true) { // dump until hitting not finding a valid instruction
if (IsSchedInstruction(offset, start_offset)) {
offset += 1;
}
u64 inst = program[offset];
const Tegra::Shader::Instruction instr = {inst};
const auto opcode = Tegra::Shader::OpCode::Decode(instr);
if (!opcode) {
break;
}
sFile.WriteArray<u64>(&inst, 1);
size += 8;
offset += 1;
}
u32 fill = 0;
// Align to 32 bytes for nvdisasm
while ((size % 0x20) != 0) {
sFile.WriteArray<u32>(&fill, 1);
size += 4;
}
sFile.Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment