Merge pull request #1780 from JayFoxRox/shadersetup-class
Turn ShaderSetup into a class
This commit is contained in:
commit
996f14f757
|
@ -501,7 +501,7 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d
|
||||||
info.labels.insert({ entry_point, "main" });
|
info.labels.insert({ entry_point, "main" });
|
||||||
|
|
||||||
// Generate debug information
|
// Generate debug information
|
||||||
debug_data = Pica::Shader::ProduceDebugInfo(input_vertex, num_attributes, shader_config, shader_setup);
|
debug_data = Pica::g_state.vs.ProduceDebugInfo(input_vertex, num_attributes, shader_config, shader_setup);
|
||||||
|
|
||||||
// Reload widget state
|
// Reload widget state
|
||||||
for (int attr = 0; attr < num_attributes; ++attr) {
|
for (int attr = 0; attr < num_attributes; ++attr) {
|
||||||
|
|
|
@ -144,12 +144,12 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
|
||||||
immediate_attribute_id = 0;
|
immediate_attribute_id = 0;
|
||||||
|
|
||||||
Shader::UnitState<false> shader_unit;
|
Shader::UnitState<false> shader_unit;
|
||||||
Shader::Setup();
|
g_state.vs.Setup();
|
||||||
|
|
||||||
// Send to vertex shader
|
// Send to vertex shader
|
||||||
if (g_debug_context)
|
if (g_debug_context)
|
||||||
g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, static_cast<void*>(&immediate_input));
|
g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, static_cast<void*>(&immediate_input));
|
||||||
Shader::OutputVertex output = Shader::Run(shader_unit, immediate_input, regs.vs.num_input_attributes+1);
|
Shader::OutputVertex output = g_state.vs.Run(shader_unit, immediate_input, regs.vs.num_input_attributes+1);
|
||||||
|
|
||||||
// Send to renderer
|
// Send to renderer
|
||||||
using Pica::Shader::OutputVertex;
|
using Pica::Shader::OutputVertex;
|
||||||
|
@ -237,7 +237,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
|
||||||
vertex_cache_ids.fill(-1);
|
vertex_cache_ids.fill(-1);
|
||||||
|
|
||||||
Shader::UnitState<false> shader_unit;
|
Shader::UnitState<false> shader_unit;
|
||||||
Shader::Setup();
|
g_state.vs.Setup();
|
||||||
|
|
||||||
for (unsigned int index = 0; index < regs.num_vertices; ++index)
|
for (unsigned int index = 0; index < regs.num_vertices; ++index)
|
||||||
{
|
{
|
||||||
|
@ -274,7 +274,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
|
||||||
// Send to vertex shader
|
// Send to vertex shader
|
||||||
if (g_debug_context)
|
if (g_debug_context)
|
||||||
g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, (void*)&input);
|
g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, (void*)&input);
|
||||||
output = Shader::Run(shader_unit, input, loader.GetNumTotalAttributes());
|
output = g_state.vs.Run(shader_unit, input, loader.GetNumTotalAttributes());
|
||||||
|
|
||||||
if (is_indexed) {
|
if (is_indexed) {
|
||||||
vertex_cache[vertex_cache_pos] = output;
|
vertex_cache[vertex_cache_pos] = output;
|
||||||
|
|
|
@ -500,7 +500,7 @@ void Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
Shader::Shutdown();
|
Shader::ClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -35,7 +35,13 @@ static std::unordered_map<u64, std::unique_ptr<JitShader>> shader_map;
|
||||||
static const JitShader* jit_shader;
|
static const JitShader* jit_shader;
|
||||||
#endif // ARCHITECTURE_x86_64
|
#endif // ARCHITECTURE_x86_64
|
||||||
|
|
||||||
void Setup() {
|
void ClearCache() {
|
||||||
|
#ifdef ARCHITECTURE_x86_64
|
||||||
|
shader_map.clear();
|
||||||
|
#endif // ARCHITECTURE_x86_64
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShaderSetup::Setup() {
|
||||||
#ifdef ARCHITECTURE_x86_64
|
#ifdef ARCHITECTURE_x86_64
|
||||||
if (VideoCore::g_shader_jit_enabled) {
|
if (VideoCore::g_shader_jit_enabled) {
|
||||||
u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^
|
u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^
|
||||||
|
@ -54,18 +60,12 @@ void Setup() {
|
||||||
#endif // ARCHITECTURE_x86_64
|
#endif // ARCHITECTURE_x86_64
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240));
|
||||||
#ifdef ARCHITECTURE_x86_64
|
|
||||||
shader_map.clear();
|
|
||||||
#endif // ARCHITECTURE_x86_64
|
|
||||||
}
|
|
||||||
|
|
||||||
MICROPROFILE_DEFINE(GPU_VertexShader, "GPU", "Vertex Shader", MP_RGB(50, 50, 240));
|
OutputVertex ShaderSetup::Run(UnitState<false>& state, const InputVertex& input, int num_attributes) {
|
||||||
|
|
||||||
OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attributes) {
|
|
||||||
auto& config = g_state.regs.vs;
|
auto& config = g_state.regs.vs;
|
||||||
|
|
||||||
MICROPROFILE_SCOPE(GPU_VertexShader);
|
MICROPROFILE_SCOPE(GPU_Shader);
|
||||||
|
|
||||||
state.program_counter = config.main_offset;
|
state.program_counter = config.main_offset;
|
||||||
state.debug.max_offset = 0;
|
state.debug.max_offset = 0;
|
||||||
|
@ -140,7 +140,7 @@ OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attr
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugData<true> 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.program_counter = config.main_offset;
|
||||||
|
|
|
@ -83,23 +83,6 @@ struct OutputVertex {
|
||||||
static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD");
|
static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD");
|
||||||
static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size");
|
static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size");
|
||||||
|
|
||||||
/// Vertex shader memory
|
|
||||||
struct ShaderSetup {
|
|
||||||
struct {
|
|
||||||
// The float uniforms are accessed by the shader JIT using SSE instructions, and are
|
|
||||||
// therefore required to be 16-byte aligned.
|
|
||||||
alignas(16) Math::Vec4<float24> f[96];
|
|
||||||
|
|
||||||
std::array<bool, 16> b;
|
|
||||||
std::array<Math::Vec4<u8>, 4> i;
|
|
||||||
} uniforms;
|
|
||||||
|
|
||||||
Math::Vec4<float24> default_attributes[16];
|
|
||||||
|
|
||||||
std::array<u32, 1024> program_code;
|
|
||||||
std::array<u32, 1024> swizzle_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Helper structure used to keep track of data useful for inspection of shader emulation
|
// Helper structure used to keep track of data useful for inspection of shader emulation
|
||||||
template<bool full_debugging>
|
template<bool full_debugging>
|
||||||
struct DebugData;
|
struct DebugData;
|
||||||
|
@ -342,15 +325,31 @@ struct UnitState {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Clears the shader cache
|
||||||
|
void ClearCache();
|
||||||
|
|
||||||
|
struct ShaderSetup {
|
||||||
|
|
||||||
|
struct {
|
||||||
|
// The float uniforms are accessed by the shader JIT using SSE instructions, and are
|
||||||
|
// therefore required to be 16-byte aligned.
|
||||||
|
alignas(16) Math::Vec4<float24> f[96];
|
||||||
|
|
||||||
|
std::array<bool, 16> b;
|
||||||
|
std::array<Math::Vec4<u8>, 4> i;
|
||||||
|
} uniforms;
|
||||||
|
|
||||||
|
Math::Vec4<float24> default_attributes[16];
|
||||||
|
|
||||||
|
std::array<u32, 1024> program_code;
|
||||||
|
std::array<u32, 1024> swizzle_data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs any shader unit setup that only needs to happen once per shader (as opposed to once per
|
* Performs any shader unit setup that only needs to happen once per shader (as opposed to once per
|
||||||
* vertex, which would happen within the `Run` function).
|
* vertex, which would happen within the `Run` function).
|
||||||
*/
|
*/
|
||||||
void Setup();
|
void Setup();
|
||||||
|
|
||||||
/// Performs any cleanup when the emulator is shutdown
|
|
||||||
void Shutdown();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the currently setup shader
|
* Runs the currently setup shader
|
||||||
* @param state Shader unit state, must be setup per shader and per shader unit
|
* @param state Shader unit state, must be setup per shader and per shader unit
|
||||||
|
@ -370,6 +369,8 @@ OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attr
|
||||||
*/
|
*/
|
||||||
DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup);
|
DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Shader
|
} // namespace Shader
|
||||||
|
|
||||||
} // namespace Pica
|
} // namespace Pica
|
||||||
|
|
Reference in New Issue