From f9079f9dce484ac025510e09d6cf09438d040240 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Wed, 12 Oct 2022 00:28:50 +0300 Subject: [PATCH] [Shader interpreter] Implement CALL --- include/PICA/shader.hpp | 2 ++ src/core/PICA/shader_interpreter.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/PICA/shader.hpp b/include/PICA/shader.hpp index 847391f8..f282da72 100644 --- a/include/PICA/shader.hpp +++ b/include/PICA/shader.hpp @@ -22,6 +22,7 @@ namespace ShaderOpcodes { MOV = 0x13, NOP = 0x21, END = 0x22, + CALL = 0x24, CALLU = 0x26, IFU = 0x27, IFC = 0x28, @@ -83,6 +84,7 @@ class PICAShader { // Shader opcodes void add(u32 instruction); + void call(u32 instruction); void callu(u32 instruction); void cmp(u32 instruction); void dp3(u32 instruction); diff --git a/src/core/PICA/shader_interpreter.cpp b/src/core/PICA/shader_interpreter.cpp index 58be21d5..3931f033 100644 --- a/src/core/PICA/shader_interpreter.cpp +++ b/src/core/PICA/shader_interpreter.cpp @@ -13,6 +13,7 @@ void PICAShader::run() { switch (opcode) { case ShaderOpcodes::ADD: add(instruction); break; + case ShaderOpcodes::CALL: call(instruction); break; case ShaderOpcodes::CALLU: callu(instruction); break; case ShaderOpcodes::CMP1: case ShaderOpcodes::CMP2: cmp(instruction); @@ -393,6 +394,20 @@ void PICAShader::ifu(u32 instruction) { } } +void PICAShader::call(u32 instruction) { + if (callIndex >= 4) [[unlikely]] + Helpers::panic("[PICA] Overflowed CALL stack"); + + const u32 num = instruction & 0xff; + const u32 dest = (instruction >> 10) & 0xfff; + + auto& block = callInfo[callIndex++]; + block.endingPC = dest + num; + block.returnPC = pc; + + pc = dest; +} + void PICAShader::callu(u32 instruction) { const u32 bit = (instruction >> 22) & 0xf; // Bit of the bool uniform to check