summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_decompiler.h
blob: 0397a000c216329e6016e7ae46d02d12ec6f205b (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
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "common/common_types.h"
#include "video_core/engines/maxwell_3d.h"
#include "video_core/engines/shader_type.h"
#include "video_core/shader/registry.h"
#include "video_core/shader/shader_ir.h"

namespace OpenGL {

class Device;

using Maxwell = Tegra::Engines::Maxwell3D::Regs;
using SamplerEntry = VideoCommon::Shader::SamplerEntry;
using ImageEntry = VideoCommon::Shader::ImageEntry;

class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer {
public:
    explicit ConstBufferEntry(u32 max_offset_, bool is_indirect_, u32 index_)
        : ConstBuffer{max_offset_, is_indirect_}, index{index_} {}

    u32 GetIndex() const {
        return index;
    }

private:
    u32 index = 0;
};

struct GlobalMemoryEntry {
    constexpr explicit GlobalMemoryEntry(u32 cbuf_index_, u32 cbuf_offset_, bool is_read_,
                                         bool is_written_)
        : cbuf_index{cbuf_index_}, cbuf_offset{cbuf_offset_}, is_read{is_read_}, is_written{
                                                                                     is_written_} {}

    u32 cbuf_index = 0;
    u32 cbuf_offset = 0;
    bool is_read = false;
    bool is_written = false;
};

struct ShaderEntries {
    std::vector<ConstBufferEntry> const_buffers;
    std::vector<GlobalMemoryEntry> global_memory_entries;
    std::vector<SamplerEntry> samplers;
    std::vector<ImageEntry> images;
    std::size_t shader_length{};
    u32 clip_distances{};
    u32 enabled_uniform_buffers{};
};

ShaderEntries MakeEntries(const Device& device, const VideoCommon::Shader::ShaderIR& ir,
                          Tegra::Engines::ShaderType stage);

std::string DecompileShader(const Device& device, const VideoCommon::Shader::ShaderIR& ir,
                            const VideoCommon::Shader::Registry& registry,
                            Tegra::Engines::ShaderType stage, std::string_view identifier,
                            std::string_view suffix = {});

} // namespace OpenGL