Merge pull request #1783 from JayFoxRox/cleanup-shadersetup
Cleanup ShaderSetup (Part 1)
This commit is contained in:
commit
d474d117f6
7 changed files with 47 additions and 50 deletions
|
@ -74,7 +74,7 @@ void GraphicsTracingWidget::StartRecording() {
|
||||||
std::array<u32, 4 * 16> default_attributes;
|
std::array<u32, 4 * 16> default_attributes;
|
||||||
for (unsigned i = 0; i < 16; ++i) {
|
for (unsigned i = 0; i < 16; ++i) {
|
||||||
for (unsigned comp = 0; comp < 3; ++comp) {
|
for (unsigned comp = 0; comp < 3; ++comp) {
|
||||||
default_attributes[4 * i + comp] = nihstro::to_float24(Pica::g_state.vs.default_attributes[i][comp].ToFloat32());
|
default_attributes[4 * i + comp] = nihstro::to_float24(Pica::g_state.vs_default_attributes[i][comp].ToFloat32());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
|
||||||
|
|
||||||
// TODO: Verify that this actually modifies the register!
|
// TODO: Verify that this actually modifies the register!
|
||||||
if (setup.index < 15) {
|
if (setup.index < 15) {
|
||||||
g_state.vs.default_attributes[setup.index] = attribute;
|
g_state.vs_default_attributes[setup.index] = attribute;
|
||||||
setup.index++;
|
setup.index++;
|
||||||
} else {
|
} else {
|
||||||
// Put each attribute into an immediate input buffer.
|
// Put each attribute into an immediate input buffer.
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct State {
|
||||||
Shader::ShaderSetup vs;
|
Shader::ShaderSetup vs;
|
||||||
Shader::ShaderSetup gs;
|
Shader::ShaderSetup gs;
|
||||||
|
|
||||||
|
std::array<Math::Vec4<float24>, 16> vs_default_attributes;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
union LutEntry {
|
union LutEntry {
|
||||||
// Used for raw access
|
// Used for raw access
|
||||||
|
|
|
@ -67,7 +67,6 @@ OutputVertex ShaderSetup::Run(UnitState<false>& state, const InputVertex& input,
|
||||||
|
|
||||||
MICROPROFILE_SCOPE(GPU_Shader);
|
MICROPROFILE_SCOPE(GPU_Shader);
|
||||||
|
|
||||||
state.program_counter = config.main_offset;
|
|
||||||
state.debug.max_offset = 0;
|
state.debug.max_offset = 0;
|
||||||
state.debug.max_opdesc_id = 0;
|
state.debug.max_opdesc_id = 0;
|
||||||
|
|
||||||
|
@ -143,7 +142,6 @@ OutputVertex ShaderSetup::Run(UnitState<false>& state, const InputVertex& input,
|
||||||
DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup) {
|
DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup) {
|
||||||
UnitState<true> state;
|
UnitState<true> state;
|
||||||
|
|
||||||
state.program_counter = config.main_offset;
|
|
||||||
state.debug.max_offset = 0;
|
state.debug.max_offset = 0;
|
||||||
state.debug.max_opdesc_id = 0;
|
state.debug.max_opdesc_id = 0;
|
||||||
|
|
||||||
|
|
|
@ -272,29 +272,12 @@ struct UnitState {
|
||||||
} registers;
|
} registers;
|
||||||
static_assert(std::is_pod<Registers>::value, "Structure is not POD");
|
static_assert(std::is_pod<Registers>::value, "Structure is not POD");
|
||||||
|
|
||||||
u32 program_counter;
|
|
||||||
bool conditional_code[2];
|
bool conditional_code[2];
|
||||||
|
|
||||||
// Two Address registers and one loop counter
|
// Two Address registers and one loop counter
|
||||||
// TODO: How many bits do these actually have?
|
// TODO: How many bits do these actually have?
|
||||||
s32 address_registers[3];
|
s32 address_registers[3];
|
||||||
|
|
||||||
enum {
|
|
||||||
INVALID_ADDRESS = 0xFFFFFFFF
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CallStackElement {
|
|
||||||
u32 final_address; // Address upon which we jump to return_address
|
|
||||||
u32 return_address; // Where to jump when leaving scope
|
|
||||||
u8 repeat_counter; // How often to repeat until this call stack element is removed
|
|
||||||
u8 loop_increment; // Which value to add to the loop counter after an iteration
|
|
||||||
// TODO: Should this be a signed value? Does it even matter?
|
|
||||||
u32 loop_address; // The address where we'll return to after each loop iteration
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Is there a maximal size for this?
|
|
||||||
boost::container::static_vector<CallStackElement, 16> call_stack;
|
|
||||||
|
|
||||||
DebugData<Debug> debug;
|
DebugData<Debug> debug;
|
||||||
|
|
||||||
static size_t InputOffset(const SourceRegister& reg) {
|
static size_t InputOffset(const SourceRegister& reg) {
|
||||||
|
@ -340,8 +323,6 @@ struct ShaderSetup {
|
||||||
std::array<Math::Vec4<u8>, 4> i;
|
std::array<Math::Vec4<u8>, 4> i;
|
||||||
} uniforms;
|
} uniforms;
|
||||||
|
|
||||||
Math::Vec4<float24> default_attributes[16];
|
|
||||||
|
|
||||||
std::array<u32, 1024> program_code;
|
std::array<u32, 1024> program_code;
|
||||||
std::array<u32, 1024> swizzle_data;
|
std::array<u32, 1024> swizzle_data;
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,24 @@ namespace Pica {
|
||||||
|
|
||||||
namespace Shader {
|
namespace Shader {
|
||||||
|
|
||||||
|
constexpr u32 INVALID_ADDRESS = 0xFFFFFFFF;
|
||||||
|
|
||||||
|
struct CallStackElement {
|
||||||
|
u32 final_address; // Address upon which we jump to return_address
|
||||||
|
u32 return_address; // Where to jump when leaving scope
|
||||||
|
u8 repeat_counter; // How often to repeat until this call stack element is removed
|
||||||
|
u8 loop_increment; // Which value to add to the loop counter after an iteration
|
||||||
|
// TODO: Should this be a signed value? Does it even matter?
|
||||||
|
u32 loop_address; // The address where we'll return to after each loop iteration
|
||||||
|
};
|
||||||
|
|
||||||
template<bool Debug>
|
template<bool Debug>
|
||||||
void RunInterpreter(UnitState<Debug>& state) {
|
void RunInterpreter(UnitState<Debug>& state) {
|
||||||
|
// TODO: Is there a maximal size for this?
|
||||||
|
boost::container::static_vector<CallStackElement, 16> call_stack;
|
||||||
|
|
||||||
|
u32 program_counter = g_state.regs.vs.main_offset;
|
||||||
|
|
||||||
const auto& uniforms = g_state.vs.uniforms;
|
const auto& uniforms = g_state.vs.uniforms;
|
||||||
const auto& swizzle_data = g_state.vs.swizzle_data;
|
const auto& swizzle_data = g_state.vs.swizzle_data;
|
||||||
const auto& program_code = g_state.vs.program_code;
|
const auto& program_code = g_state.vs.program_code;
|
||||||
|
@ -41,16 +57,16 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
unsigned iteration = 0;
|
unsigned iteration = 0;
|
||||||
bool exit_loop = false;
|
bool exit_loop = false;
|
||||||
while (!exit_loop) {
|
while (!exit_loop) {
|
||||||
if (!state.call_stack.empty()) {
|
if (!call_stack.empty()) {
|
||||||
auto& top = state.call_stack.back();
|
auto& top = call_stack.back();
|
||||||
if (state.program_counter == top.final_address) {
|
if (program_counter == top.final_address) {
|
||||||
state.address_registers[2] += top.loop_increment;
|
state.address_registers[2] += top.loop_increment;
|
||||||
|
|
||||||
if (top.repeat_counter-- == 0) {
|
if (top.repeat_counter-- == 0) {
|
||||||
state.program_counter = top.return_address;
|
program_counter = top.return_address;
|
||||||
state.call_stack.pop_back();
|
call_stack.pop_back();
|
||||||
} else {
|
} else {
|
||||||
state.program_counter = top.loop_address;
|
program_counter = top.loop_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Is "trying again" accurate to hardware?
|
// TODO: Is "trying again" accurate to hardware?
|
||||||
|
@ -58,20 +74,20 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Instruction instr = { program_code[state.program_counter] };
|
const Instruction instr = { program_code[program_counter] };
|
||||||
const SwizzlePattern swizzle = { swizzle_data[instr.common.operand_desc_id] };
|
const SwizzlePattern swizzle = { swizzle_data[instr.common.operand_desc_id] };
|
||||||
|
|
||||||
static auto call = [](UnitState<Debug>& state, u32 offset, u32 num_instructions,
|
static auto call = [&program_counter, &call_stack](UnitState<Debug>& state, u32 offset, u32 num_instructions,
|
||||||
u32 return_offset, u8 repeat_count, u8 loop_increment) {
|
u32 return_offset, u8 repeat_count, u8 loop_increment) {
|
||||||
state.program_counter = offset - 1; // -1 to make sure when incrementing the PC we end up at the correct offset
|
program_counter = offset - 1; // -1 to make sure when incrementing the PC we end up at the correct offset
|
||||||
ASSERT(state.call_stack.size() < state.call_stack.capacity());
|
ASSERT(call_stack.size() < call_stack.capacity());
|
||||||
state.call_stack.push_back({ offset + num_instructions, return_offset, repeat_count, loop_increment, offset });
|
call_stack.push_back({ offset + num_instructions, return_offset, repeat_count, loop_increment, offset });
|
||||||
};
|
};
|
||||||
Record<DebugDataRecord::CUR_INSTR>(state.debug, iteration, state.program_counter);
|
Record<DebugDataRecord::CUR_INSTR>(state.debug, iteration, program_counter);
|
||||||
if (iteration > 0)
|
if (iteration > 0)
|
||||||
Record<DebugDataRecord::NEXT_INSTR>(state.debug, iteration - 1, state.program_counter);
|
Record<DebugDataRecord::NEXT_INSTR>(state.debug, iteration - 1, program_counter);
|
||||||
|
|
||||||
state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + state.program_counter);
|
state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + program_counter);
|
||||||
|
|
||||||
auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* {
|
auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* {
|
||||||
switch (source_reg.GetRegisterType()) {
|
switch (source_reg.GetRegisterType()) {
|
||||||
|
@ -519,7 +535,7 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
case OpCode::Id::JMPC:
|
case OpCode::Id::JMPC:
|
||||||
Record<DebugDataRecord::COND_CMP_IN>(state.debug, iteration, state.conditional_code);
|
Record<DebugDataRecord::COND_CMP_IN>(state.debug, iteration, state.conditional_code);
|
||||||
if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
|
if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
|
||||||
state.program_counter = instr.flow_control.dest_offset - 1;
|
program_counter = instr.flow_control.dest_offset - 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -527,7 +543,7 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
Record<DebugDataRecord::COND_BOOL_IN>(state.debug, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
Record<DebugDataRecord::COND_BOOL_IN>(state.debug, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
||||||
|
|
||||||
if (uniforms.b[instr.flow_control.bool_uniform_id] == !(instr.flow_control.num_instructions & 1)) {
|
if (uniforms.b[instr.flow_control.bool_uniform_id] == !(instr.flow_control.num_instructions & 1)) {
|
||||||
state.program_counter = instr.flow_control.dest_offset - 1;
|
program_counter = instr.flow_control.dest_offset - 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -535,7 +551,7 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
call(state,
|
call(state,
|
||||||
instr.flow_control.dest_offset,
|
instr.flow_control.dest_offset,
|
||||||
instr.flow_control.num_instructions,
|
instr.flow_control.num_instructions,
|
||||||
state.program_counter + 1, 0, 0);
|
program_counter + 1, 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OpCode::Id::CALLU:
|
case OpCode::Id::CALLU:
|
||||||
|
@ -544,7 +560,7 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
call(state,
|
call(state,
|
||||||
instr.flow_control.dest_offset,
|
instr.flow_control.dest_offset,
|
||||||
instr.flow_control.num_instructions,
|
instr.flow_control.num_instructions,
|
||||||
state.program_counter + 1, 0, 0);
|
program_counter + 1, 0, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -554,7 +570,7 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
call(state,
|
call(state,
|
||||||
instr.flow_control.dest_offset,
|
instr.flow_control.dest_offset,
|
||||||
instr.flow_control.num_instructions,
|
instr.flow_control.num_instructions,
|
||||||
state.program_counter + 1, 0, 0);
|
program_counter + 1, 0, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -565,8 +581,8 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
Record<DebugDataRecord::COND_BOOL_IN>(state.debug, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
Record<DebugDataRecord::COND_BOOL_IN>(state.debug, iteration, uniforms.b[instr.flow_control.bool_uniform_id]);
|
||||||
if (uniforms.b[instr.flow_control.bool_uniform_id]) {
|
if (uniforms.b[instr.flow_control.bool_uniform_id]) {
|
||||||
call(state,
|
call(state,
|
||||||
state.program_counter + 1,
|
program_counter + 1,
|
||||||
instr.flow_control.dest_offset - state.program_counter - 1,
|
instr.flow_control.dest_offset - program_counter - 1,
|
||||||
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
|
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
call(state,
|
call(state,
|
||||||
|
@ -584,8 +600,8 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
Record<DebugDataRecord::COND_CMP_IN>(state.debug, iteration, state.conditional_code);
|
Record<DebugDataRecord::COND_CMP_IN>(state.debug, iteration, state.conditional_code);
|
||||||
if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
|
if (evaluate_condition(state, instr.flow_control.refx, instr.flow_control.refy, instr.flow_control)) {
|
||||||
call(state,
|
call(state,
|
||||||
state.program_counter + 1,
|
program_counter + 1,
|
||||||
instr.flow_control.dest_offset - state.program_counter - 1,
|
instr.flow_control.dest_offset - program_counter - 1,
|
||||||
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
|
instr.flow_control.dest_offset + instr.flow_control.num_instructions, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
call(state,
|
call(state,
|
||||||
|
@ -607,8 +623,8 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
|
|
||||||
Record<DebugDataRecord::LOOP_INT_IN>(state.debug, iteration, loop_param);
|
Record<DebugDataRecord::LOOP_INT_IN>(state.debug, iteration, loop_param);
|
||||||
call(state,
|
call(state,
|
||||||
state.program_counter + 1,
|
program_counter + 1,
|
||||||
instr.flow_control.dest_offset - state.program_counter + 1,
|
instr.flow_control.dest_offset - program_counter + 1,
|
||||||
instr.flow_control.dest_offset + 1,
|
instr.flow_control.dest_offset + 1,
|
||||||
loop_param.x,
|
loop_param.x,
|
||||||
loop_param.z);
|
loop_param.z);
|
||||||
|
@ -625,7 +641,7 @@ void RunInterpreter(UnitState<Debug>& state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++state.program_counter;
|
++program_counter;
|
||||||
++iteration;
|
++iteration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::I
|
||||||
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(), input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
|
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(), input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
|
||||||
} else if (vertex_attribute_is_default[i]) {
|
} else if (vertex_attribute_is_default[i]) {
|
||||||
// Load the default attribute if we're configured to do so
|
// Load the default attribute if we're configured to do so
|
||||||
input.attr[i] = g_state.vs.default_attributes[i];
|
input.attr[i] = g_state.vs_default_attributes[i];
|
||||||
LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)",
|
LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)",
|
||||||
i, vertex, index,
|
i, vertex, index,
|
||||||
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
|
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
|
||||||
|
|
Loading…
Reference in a new issue