forked from ShuriZma/suyu
1
0
Fork 0

Pica/VertexShader: Some cleanups using std::array.

This commit is contained in:
Tony Wasserka 2014-12-16 01:20:29 +01:00
parent ce36ad454e
commit b85524c760
2 changed files with 19 additions and 5 deletions

View File

@ -31,8 +31,8 @@ static struct {
// TODO: Not sure where the shader binary and swizzle patterns are supposed to be loaded to! // TODO: Not sure where the shader binary and swizzle patterns are supposed to be loaded to!
// For now, we just keep these local arrays around. // For now, we just keep these local arrays around.
static u32 shader_memory[1024]; static std::array<u32, 1024> shader_memory;
static u32 swizzle_data[1024]; static std::array<u32, 1024> swizzle_data;
void SubmitShaderMemoryChange(u32 addr, u32 value) void SubmitShaderMemoryChange(u32 addr, u32 value)
{ {
@ -49,6 +49,17 @@ Math::Vec4<float24>& GetFloatUniform(u32 index)
return shader_uniforms.f[index]; return shader_uniforms.f[index];
} }
const std::array<u32, 1024>& GetShaderBinary()
{
return shader_memory;
}
const std::array<u32, 1024>& GetSwizzlePatterns()
{
return swizzle_data;
}
struct VertexShaderState { struct VertexShaderState {
u32* program_counter; u32* program_counter;
@ -75,7 +86,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
bool increment_pc = true; bool increment_pc = true;
bool exit_loop = false; bool exit_loop = false;
const Instruction& instr = *(const Instruction*)state.program_counter; const Instruction& instr = *(const Instruction*)state.program_counter;
state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + (state.program_counter - shader_memory)); state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + (state.program_counter - shader_memory.data()));
auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* { auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* {
switch (source_reg.GetRegisterType()) { switch (source_reg.GetRegisterType()) {
@ -233,7 +244,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
_dbg_assert_(HW_GPU, state.call_stack_pointer - state.call_stack < sizeof(state.call_stack)); _dbg_assert_(HW_GPU, state.call_stack_pointer - state.call_stack < sizeof(state.call_stack));
*++state.call_stack_pointer = state.program_counter - shader_memory; *++state.call_stack_pointer = state.program_counter - shader_memory.data();
state.program_counter = &shader_memory[instr.flow_control.dest_offset]; state.program_counter = &shader_memory[instr.flow_control.dest_offset];
break; break;
@ -305,7 +316,7 @@ OutputVertex RunShader(const InputVertex& input, int num_attributes)
state.call_stack_pointer = &state.call_stack[0]; state.call_stack_pointer = &state.call_stack[0];
ProcessShaderCode(state); ProcessShaderCode(state);
DebugUtils::DumpShader(shader_memory, state.debug.max_offset, swizzle_data, DebugUtils::DumpShader(shader_memory.data(), state.debug.max_offset, swizzle_data.data(),
state.debug.max_opdesc_id, registers.vs_main_offset, state.debug.max_opdesc_id, registers.vs_main_offset,
registers.vs_output_attributes); registers.vs_output_attributes);

View File

@ -73,6 +73,9 @@ OutputVertex RunShader(const InputVertex& input, int num_attributes);
Math::Vec4<float24>& GetFloatUniform(u32 index); Math::Vec4<float24>& GetFloatUniform(u32 index);
const std::array<u32, 1024>& GetShaderBinary();
const std::array<u32, 1024>& GetSwizzlePatterns();
} // namespace } // namespace
} // namespace } // namespace