2018-03-20 01:55:14 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
2018-04-15 09:32:12 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
|
2018-03-20 01:55:14 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL::GLShader {
|
2018-03-20 01:55:14 +01:00
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
using Tegra::Engines::Maxwell3D;
|
|
|
|
|
|
|
|
static constexpr u32 PROGRAM_OFFSET{10};
|
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
ProgramResult GenerateVertexShader(const ShaderSetup& setup) {
|
2018-04-15 09:32:12 +02:00
|
|
|
std::string out = "#version 430 core\n";
|
|
|
|
out += "#extension GL_ARB_separate_shader_objects : enable\n\n";
|
|
|
|
out += Decompiler::GetCommonDeclarations();
|
2018-10-07 04:17:31 +02:00
|
|
|
|
|
|
|
out += R"(
|
|
|
|
out gl_PerVertex {
|
|
|
|
vec4 gl_Position;
|
|
|
|
};
|
|
|
|
|
|
|
|
layout(std140) uniform vs_config {
|
|
|
|
vec4 viewport_flip;
|
|
|
|
uvec4 instance_id;
|
|
|
|
uvec4 flip_stage;
|
|
|
|
};
|
|
|
|
)";
|
2018-07-13 04:25:03 +02:00
|
|
|
|
|
|
|
if (setup.IsDualProgram()) {
|
|
|
|
out += "bool exec_vertex_b();\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramResult program =
|
|
|
|
Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET,
|
|
|
|
Maxwell3D::Regs::ShaderStage::Vertex, "vertex")
|
|
|
|
.get_value_or({});
|
2018-04-15 09:32:12 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
out += program.first;
|
2018-04-15 09:32:12 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
if (setup.IsDualProgram()) {
|
|
|
|
ProgramResult program_b =
|
|
|
|
Decompiler::DecompileProgram(setup.program.code_b, PROGRAM_OFFSET,
|
|
|
|
Maxwell3D::Regs::ShaderStage::Vertex, "vertex_b")
|
|
|
|
.get_value_or({});
|
|
|
|
out += program_b.first;
|
|
|
|
}
|
2018-04-16 02:26:45 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
out += R"(
|
2018-04-18 22:42:40 +02:00
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
void main() {
|
2018-09-06 12:45:47 +02:00
|
|
|
position = vec4(0.0, 0.0, 0.0, 0.0);
|
2018-07-13 04:25:03 +02:00
|
|
|
exec_vertex();
|
|
|
|
)";
|
|
|
|
|
|
|
|
if (setup.IsDualProgram()) {
|
|
|
|
out += " exec_vertex_b();";
|
|
|
|
}
|
|
|
|
|
|
|
|
out += R"(
|
2018-04-15 09:32:12 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
// Check if the flip stage is VertexB
|
|
|
|
if (flip_stage[0] == 1) {
|
|
|
|
// Viewport can be flipped, which is unsupported by glViewport
|
|
|
|
position.xy *= viewport_flip.xy;
|
|
|
|
}
|
2018-04-16 02:26:45 +02:00
|
|
|
gl_Position = position;
|
2018-06-16 01:25:36 +02:00
|
|
|
|
|
|
|
// TODO(bunnei): This is likely a hack, position.w should be interpolated as 1.0
|
|
|
|
// For now, this is here to bring order in lieu of proper emulation
|
2018-10-07 04:17:31 +02:00
|
|
|
if (flip_stage[0] == 1) {
|
|
|
|
position.w = 1.0;
|
|
|
|
}
|
2018-04-16 02:26:45 +02:00
|
|
|
}
|
2018-07-13 04:25:03 +02:00
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
)";
|
2018-07-13 04:25:03 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
return {out, program.second};
|
|
|
|
}
|
2018-07-13 04:25:03 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
ProgramResult GenerateGeometryShader(const ShaderSetup& setup) {
|
|
|
|
std::string out = "#version 430 core\n";
|
|
|
|
out += "#extension GL_ARB_separate_shader_objects : enable\n\n";
|
|
|
|
out += Decompiler::GetCommonDeclarations();
|
|
|
|
out += "bool exec_geometry();\n";
|
|
|
|
|
|
|
|
ProgramResult program =
|
|
|
|
Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET,
|
|
|
|
Maxwell3D::Regs::ShaderStage::Geometry, "geometry")
|
|
|
|
.get_value_or({});
|
|
|
|
out += R"(
|
|
|
|
out gl_PerVertex {
|
|
|
|
vec4 gl_Position;
|
|
|
|
};
|
2018-07-13 04:25:03 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
layout (std140) uniform gs_config {
|
|
|
|
vec4 viewport_flip;
|
|
|
|
uvec4 instance_id;
|
|
|
|
uvec4 flip_stage;
|
|
|
|
};
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
exec_geometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
)";
|
|
|
|
out += program.first;
|
2018-04-15 09:32:12 +02:00
|
|
|
return {out, program.second};
|
|
|
|
}
|
|
|
|
|
2018-08-23 23:30:27 +02:00
|
|
|
ProgramResult GenerateFragmentShader(const ShaderSetup& setup) {
|
2018-04-15 09:32:12 +02:00
|
|
|
std::string out = "#version 430 core\n";
|
|
|
|
out += "#extension GL_ARB_separate_shader_objects : enable\n\n";
|
|
|
|
out += Decompiler::GetCommonDeclarations();
|
2018-07-13 04:25:03 +02:00
|
|
|
out += "bool exec_fragment();\n";
|
2018-04-15 09:32:12 +02:00
|
|
|
|
2018-07-13 04:25:03 +02:00
|
|
|
ProgramResult program =
|
|
|
|
Decompiler::DecompileProgram(setup.program.code, PROGRAM_OFFSET,
|
|
|
|
Maxwell3D::Regs::ShaderStage::Fragment, "fragment")
|
|
|
|
.get_value_or({});
|
2018-04-15 09:32:12 +02:00
|
|
|
out += R"(
|
2018-09-11 05:26:56 +02:00
|
|
|
layout(location = 0) out vec4 FragColor0;
|
|
|
|
layout(location = 1) out vec4 FragColor1;
|
|
|
|
layout(location = 2) out vec4 FragColor2;
|
|
|
|
layout(location = 3) out vec4 FragColor3;
|
|
|
|
layout(location = 4) out vec4 FragColor4;
|
|
|
|
layout(location = 5) out vec4 FragColor5;
|
|
|
|
layout(location = 6) out vec4 FragColor6;
|
|
|
|
layout(location = 7) out vec4 FragColor7;
|
2018-04-15 09:32:12 +02:00
|
|
|
|
2018-04-18 22:42:40 +02:00
|
|
|
layout (std140) uniform fs_config {
|
|
|
|
vec4 viewport_flip;
|
2018-08-12 02:21:31 +02:00
|
|
|
uvec4 instance_id;
|
2018-10-07 04:17:31 +02:00
|
|
|
uvec4 flip_stage;
|
2018-04-18 22:42:40 +02:00
|
|
|
};
|
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
void main() {
|
2018-07-13 04:25:03 +02:00
|
|
|
exec_fragment();
|
2018-03-20 01:55:14 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
)";
|
|
|
|
out += program.first;
|
|
|
|
return {out, program.second};
|
2018-03-20 01:55:14 +01:00
|
|
|
}
|
2018-10-07 04:17:31 +02:00
|
|
|
} // namespace OpenGL::GLShader
|