summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/frontend/maxwell/translate/impl/exit_program.cpp
blob: 537b5bde26455eb41619e91cc2bf5a021c38603a (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
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include "common/common_types.h"
#include "shader_recompiler/exception.h"
#include "shader_recompiler/frontend/maxwell/translate/impl/impl.h"

namespace Shader::Maxwell {
namespace {
void ExitFragment(TranslatorVisitor& v) {
    const ProgramHeader sph{v.env.SPH()};
    IR::Reg src_reg{IR::Reg::R0};
    for (u32 render_target = 0; render_target < 8; ++render_target) {
        if (!sph.ps.HasOutputComponents(render_target)) {
            continue;
        }
        const std::array<bool, 4> mask{sph.ps.EnabledOutputComponents(render_target)};
        for (u32 component = 0; component < 4; ++component) {
            if (!mask[component]) {
                ++src_reg;
                continue;
            }
            v.ir.SetFragColor(render_target, component, v.F(src_reg));
            ++src_reg;
        }
    }
    if (sph.ps.omap.sample_mask != 0) {
        v.ir.SetSampleMask(v.X(src_reg));
    }
    if (sph.ps.omap.depth != 0) {
        v.ir.SetFragDepth(v.F(src_reg + 1));
    }
}
} // Anonymous namespace

void TranslatorVisitor::EXIT() {
    switch (env.ShaderStage()) {
    case Stage::Fragment:
        ExitFragment(*this);
        break;
    default:
        break;
    }
}

} // namespace Shader::Maxwell