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.
|
|
|
|
|
2018-12-09 22:33:10 +01:00
|
|
|
#include <fmt/format.h>
|
2018-04-15 09:32:12 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-12-26 05:57:14 +01:00
|
|
|
#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-12-21 02:29:15 +01:00
|
|
|
#include "video_core/shader/shader_ir.h"
|
2018-03-20 01:55:14 +01:00
|
|
|
|
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;
|
2019-08-16 22:25:02 +02:00
|
|
|
using VideoCommon::Shader::CompileDepth;
|
|
|
|
using VideoCommon::Shader::CompilerSettings;
|
2018-12-21 02:29:15 +01:00
|
|
|
using VideoCommon::Shader::ProgramCode;
|
|
|
|
using VideoCommon::Shader::ShaderIR;
|
2018-04-15 09:32:12 +02:00
|
|
|
|
2019-09-25 04:34:18 +02:00
|
|
|
std::string GenerateVertexShader(const Device& device, const ShaderIR& ir, const ShaderIR* ir_b) {
|
|
|
|
std::string out = GetCommonDeclarations();
|
2018-12-21 02:29:15 +01:00
|
|
|
out += R"(
|
2019-01-05 05:00:06 +01:00
|
|
|
layout (std140, binding = EMULATION_UBO_BINDING) uniform vs_config {
|
2018-10-07 04:17:31 +02:00
|
|
|
vec4 viewport_flip;
|
2018-11-25 08:37:29 +01:00
|
|
|
uvec4 config_pack; // instance_id, flip_stage, y_direction, padding
|
2018-10-07 04:17:31 +02:00
|
|
|
};
|
2018-12-26 06:08:32 +01:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
)";
|
2019-09-25 04:34:18 +02:00
|
|
|
const auto stage = ir_b ? ProgramType::VertexA : ProgramType::VertexB;
|
|
|
|
out += Decompile(device, ir, stage, "vertex");
|
|
|
|
if (ir_b) {
|
|
|
|
out += Decompile(device, *ir_b, ProgramType::VertexB, "vertex_b");
|
2018-10-07 04:17:31 +02:00
|
|
|
}
|
2018-04-16 02:26:45 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
out += R"(
|
2018-04-15 09:32:12 +02:00
|
|
|
void main() {
|
2018-12-21 02:29:15 +01:00
|
|
|
execute_vertex();
|
2018-07-13 04:25:03 +02:00
|
|
|
)";
|
|
|
|
|
2019-09-25 04:34:18 +02:00
|
|
|
if (ir_b) {
|
2018-12-21 02:29:15 +01:00
|
|
|
out += " execute_vertex_b();";
|
2018-07-13 04:25:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
out += R"(
|
2019-04-20 02:49:00 +02:00
|
|
|
|
|
|
|
// Set Position Y direction
|
2019-06-03 06:01:34 +02:00
|
|
|
gl_Position.y *= utof(config_pack[2]);
|
2018-10-07 04:17:31 +02:00
|
|
|
// Check if the flip stage is VertexB
|
2018-11-25 08:37:29 +01:00
|
|
|
// Config pack's second value is flip_stage
|
|
|
|
if (config_pack[1] == 1) {
|
2018-10-07 04:17:31 +02:00
|
|
|
// Viewport can be flipped, which is unsupported by glViewport
|
2019-06-03 06:01:34 +02:00
|
|
|
gl_Position.xy *= viewport_flip.xy;
|
2018-10-07 04:17:31 +02:00
|
|
|
}
|
2019-09-25 04:34:18 +02:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
return out;
|
2018-10-07 04:17:31 +02:00
|
|
|
}
|
2018-07-13 04:25:03 +02:00
|
|
|
|
2019-09-25 04:34:18 +02:00
|
|
|
std::string GenerateGeometryShader(const Device& device, const ShaderIR& ir) {
|
|
|
|
std::string out = GetCommonDeclarations();
|
2018-12-26 06:08:32 +01:00
|
|
|
out += R"(
|
2019-01-05 05:00:06 +01:00
|
|
|
layout (std140, binding = EMULATION_UBO_BINDING) uniform gs_config {
|
2018-10-07 04:17:31 +02:00
|
|
|
vec4 viewport_flip;
|
2018-11-25 08:37:29 +01:00
|
|
|
uvec4 config_pack; // instance_id, flip_stage, y_direction, padding
|
2018-10-07 04:17:31 +02:00
|
|
|
};
|
2018-12-21 02:29:15 +01:00
|
|
|
|
2018-12-26 06:08:32 +01:00
|
|
|
)";
|
2019-09-25 04:34:18 +02:00
|
|
|
out += Decompile(device, ir, ProgramType::Geometry, "geometry");
|
2018-10-07 04:17:31 +02:00
|
|
|
|
2018-12-24 06:24:38 +01:00
|
|
|
out += R"(
|
2018-10-07 04:17:31 +02:00
|
|
|
void main() {
|
2018-12-21 02:29:15 +01:00
|
|
|
execute_geometry();
|
2019-09-25 04:34:18 +02:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
return out;
|
2018-04-15 09:32:12 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 04:34:18 +02:00
|
|
|
std::string GenerateFragmentShader(const Device& device, const ShaderIR& ir) {
|
|
|
|
std::string out = GetCommonDeclarations();
|
2018-04-15 09:32:12 +02:00
|
|
|
out += R"(
|
2018-12-26 06:08:32 +01: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
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
layout (std140, binding = EMULATION_UBO_BINDING) uniform fs_config {
|
2018-04-18 22:42:40 +02:00
|
|
|
vec4 viewport_flip;
|
2018-11-25 08:37:29 +01:00
|
|
|
uvec4 config_pack; // instance_id, flip_stage, y_direction, padding
|
2018-04-18 22:42:40 +02:00
|
|
|
};
|
|
|
|
|
2018-12-26 06:08:32 +01:00
|
|
|
)";
|
2019-09-25 04:34:18 +02:00
|
|
|
out += Decompile(device, ir, ProgramType::Fragment, "fragment");
|
2018-12-21 02:29:15 +01:00
|
|
|
|
|
|
|
out += R"(
|
2018-04-15 09:32:12 +02:00
|
|
|
void main() {
|
2018-12-21 02:29:15 +01:00
|
|
|
execute_fragment();
|
2018-03-20 01:55:14 +01:00
|
|
|
}
|
2018-04-15 09:32:12 +02:00
|
|
|
)";
|
2019-09-25 04:34:18 +02:00
|
|
|
return out;
|
2018-03-20 01:55:14 +01:00
|
|
|
}
|
2018-12-26 06:08:32 +01:00
|
|
|
|
2019-09-25 04:34:18 +02:00
|
|
|
std::string GenerateComputeShader(const Device& device, const ShaderIR& ir) {
|
|
|
|
std::string out = GetCommonDeclarations();
|
|
|
|
out += Decompile(device, ir, ProgramType::Compute, "compute");
|
2019-07-15 03:25:13 +02:00
|
|
|
out += R"(
|
|
|
|
void main() {
|
|
|
|
execute_compute();
|
|
|
|
}
|
|
|
|
)";
|
2019-09-25 04:34:18 +02:00
|
|
|
return out;
|
2019-07-15 03:25:13 +02:00
|
|
|
}
|
|
|
|
|
2019-02-13 02:14:39 +01:00
|
|
|
} // namespace OpenGL::GLShader
|