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.
|
|
|
|
|
2019-11-19 01:38:15 +01:00
|
|
|
#include <string>
|
|
|
|
|
2018-12-09 22:33:10 +01:00
|
|
|
#include <fmt/format.h>
|
2019-11-19 01:38:15 +01:00
|
|
|
|
2018-04-15 09:32:12 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2019-11-18 22:35:21 +01:00
|
|
|
#include "video_core/engines/shader_type.h"
|
2019-11-19 01:38:15 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_device.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-11-18 22:35:21 +01:00
|
|
|
using Tegra::Engines::ShaderType;
|
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();
|
2019-11-19 01:38:15 +01:00
|
|
|
out += fmt::format(R"(
|
|
|
|
layout (std140, binding = {}) uniform vs_config {{
|
2019-10-30 04:23:09 +01:00
|
|
|
float y_direction;
|
2019-11-19 01:38:15 +01:00
|
|
|
}};
|
2018-12-26 06:08:32 +01:00
|
|
|
|
2019-11-19 01:38:15 +01:00
|
|
|
)",
|
|
|
|
EmulationUniformBlockBinding);
|
2019-11-18 22:35:21 +01:00
|
|
|
out += Decompile(device, ir, ShaderType::Vertex, "vertex");
|
2019-09-25 04:34:18 +02:00
|
|
|
if (ir_b) {
|
2019-11-18 22:35:21 +01:00
|
|
|
out += Decompile(device, *ir_b, ShaderType::Vertex, "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() {
|
2019-11-20 00:32:01 +01:00
|
|
|
gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
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
|
|
|
}
|
2019-10-30 04:23:09 +01:00
|
|
|
out += "}\n";
|
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();
|
2019-11-19 01:38:15 +01:00
|
|
|
out += fmt::format(R"(
|
|
|
|
layout (std140, binding = {}) uniform gs_config {{
|
2019-10-30 04:23:09 +01:00
|
|
|
float y_direction;
|
2019-11-19 01:38:15 +01:00
|
|
|
}};
|
2018-12-21 02:29:15 +01:00
|
|
|
|
2019-11-19 01:38:15 +01:00
|
|
|
)",
|
|
|
|
EmulationUniformBlockBinding);
|
2019-11-18 22:35:21 +01:00
|
|
|
out += Decompile(device, ir, ShaderType::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();
|
2019-11-19 01:38:15 +01:00
|
|
|
out += fmt::format(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-11-19 01:38:15 +01:00
|
|
|
layout (std140, binding = {}) uniform fs_config {{
|
2019-10-30 04:23:09 +01:00
|
|
|
float y_direction;
|
2019-11-19 01:38:15 +01:00
|
|
|
}};
|
2018-04-18 22:42:40 +02:00
|
|
|
|
2019-11-19 01:38:15 +01:00
|
|
|
)",
|
|
|
|
EmulationUniformBlockBinding);
|
2019-11-18 22:35:21 +01:00
|
|
|
out += Decompile(device, ir, ShaderType::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();
|
2019-11-18 22:35:21 +01:00
|
|
|
out += Decompile(device, ir, ShaderType::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
|