summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_gen.cpp
blob: 34946fb47f525a3e2ec550a075576e4a7fd95723 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <string>

#include <fmt/format.h>

#include "video_core/engines/maxwell_3d.h"
#include "video_core/engines/shader_type.h"
#include "video_core/renderer_opengl/gl_device.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_gen.h"
#include "video_core/shader/shader_ir.h"

namespace OpenGL::GLShader {

using Tegra::Engines::Maxwell3D;
using Tegra::Engines::ShaderType;
using VideoCommon::Shader::CompileDepth;
using VideoCommon::Shader::CompilerSettings;
using VideoCommon::Shader::ProgramCode;
using VideoCommon::Shader::ShaderIR;

std::string GenerateVertexShader(const Device& device, const ShaderIR& ir, const ShaderIR* ir_b) {
    std::string out = GetCommonDeclarations();
    out += fmt::format(R"(
layout (std140, binding = {}) uniform vs_config {{
    float y_direction;
}};

)",
                       EmulationUniformBlockBinding);
    out += Decompile(device, ir, ShaderType::Vertex, "vertex");
    if (ir_b) {
        out += Decompile(device, *ir_b, ShaderType::Vertex, "vertex_b");
    }

    out += R"(
void main() {
    gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);
    execute_vertex();
)";
    if (ir_b) {
        out += "    execute_vertex_b();";
    }
    out += "}\n";
    return out;
}

std::string GenerateGeometryShader(const Device& device, const ShaderIR& ir) {
    std::string out = GetCommonDeclarations();
    out += fmt::format(R"(
layout (std140, binding = {}) uniform gs_config {{
    float y_direction;
}};

)",
                       EmulationUniformBlockBinding);
    out += Decompile(device, ir, ShaderType::Geometry, "geometry");

    out += R"(
void main() {
    execute_geometry();
}
)";
    return out;
}

std::string GenerateFragmentShader(const Device& device, const ShaderIR& ir) {
    std::string out = GetCommonDeclarations();
    out += fmt::format(R"(
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;

layout (std140, binding = {}) uniform fs_config {{
    float y_direction;
}};

)",
                       EmulationUniformBlockBinding);
    out += Decompile(device, ir, ShaderType::Fragment, "fragment");

    out += R"(
void main() {
    execute_fragment();
}
)";
    return out;
}

std::string GenerateComputeShader(const Device& device, const ShaderIR& ir) {
    std::string out = GetCommonDeclarations();
    out += Decompile(device, ir, ShaderType::Compute, "compute");
    out += R"(
void main() {
    execute_compute();
}
)";
    return out;
}

} // namespace OpenGL::GLShader