summaryrefslogtreecommitdiffstats
path: root/src/video_core/engines/maxwell_dma.h
blob: 8eab1332e4dd680a1a4f42a22d6a8154cae691f4 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright 2018 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <cstddef>
#include <vector>
#include "common/bit_field.h"
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "video_core/gpu.h"

namespace Core {
class System;
}

namespace Tegra {
class MemoryManager;
}

namespace VideoCore {
class RasterizerInterface;
}

namespace Tegra::Engines {

/**
 * This Engine is known as GK104_Copy. Documentation can be found in:
 * https://github.com/envytools/envytools/blob/master/rnndb/fifo/gk104_copy.xml
 */

class MaxwellDMA final {
public:
    explicit MaxwellDMA(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
                        MemoryManager& memory_manager);
    ~MaxwellDMA() = default;

    /// Write the value to the register identified by method.
    void CallMethod(const GPU::MethodCall& method_call);

    struct Regs {
        static constexpr std::size_t NUM_REGS = 0x1D6;

        struct Parameters {
            union {
                BitField<0, 4, u32> block_depth;
                BitField<4, 4, u32> block_height;
                BitField<8, 4, u32> block_width;
            };
            u32 size_x;
            u32 size_y;
            u32 size_z;
            u32 pos_z;
            union {
                BitField<0, 16, u32> pos_x;
                BitField<16, 16, u32> pos_y;
            };

            u32 BlockHeight() const {
                return 1 << block_height;
            }

            u32 BlockDepth() const {
                return 1 << block_depth;
            }
        };

        static_assert(sizeof(Parameters) == 24, "Parameters has wrong size");

        enum class ComponentMode : u32 {
            SRC0 = 0,
            SRC1 = 1,
            SRC2 = 2,
            SRC3 = 3,
            CONST0 = 4,
            CONST1 = 5,
            ZERO = 6,
        };

        enum class CopyMode : u32 {
            None = 0,
            Unk1 = 1,
            Unk2 = 2,
        };

        enum class QueryMode : u32 {
            None = 0,
            Short = 1,
            Long = 2,
        };

        enum class QueryIntr : u32 {
            None = 0,
            Block = 1,
            NonBlock = 2,
        };

        union {
            struct {
                INSERT_PADDING_WORDS(0xC0);

                struct {
                    union {
                        BitField<0, 2, CopyMode> copy_mode;
                        BitField<2, 1, u32> flush;

                        BitField<3, 2, QueryMode> query_mode;
                        BitField<5, 2, QueryIntr> query_intr;

                        BitField<7, 1, u32> is_src_linear;
                        BitField<8, 1, u32> is_dst_linear;

                        BitField<9, 1, u32> enable_2d;
                        BitField<10, 1, u32> enable_swizzle;
                    };
                } exec;

                INSERT_PADDING_WORDS(0x3F);

                struct {
                    u32 address_high;
                    u32 address_low;

                    GPUVAddr Address() const {
                        return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
                                                     address_low);
                    }
                } src_address;

                struct {
                    u32 address_high;
                    u32 address_low;

                    GPUVAddr Address() const {
                        return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
                                                     address_low);
                    }
                } dst_address;

                u32 src_pitch;
                u32 dst_pitch;
                u32 x_count;
                u32 y_count;

                INSERT_PADDING_WORDS(0xB8);

                u32 const0;
                u32 const1;
                union {
                    BitField<0, 4, ComponentMode> component0;
                    BitField<4, 4, ComponentMode> component1;
                    BitField<8, 4, ComponentMode> component2;
                    BitField<12, 4, ComponentMode> component3;
                    BitField<16, 2, u32> component_size;
                    BitField<20, 3, u32> src_num_components;
                    BitField<24, 3, u32> dst_num_components;

                    u32 SrcBytePerPixel() const {
                        return src_num_components.Value() * component_size.Value();
                    }
                    u32 DstBytePerPixel() const {
                        return dst_num_components.Value() * component_size.Value();
                    }
                } swizzle_config;

                Parameters dst_params;

                INSERT_PADDING_WORDS(1);

                Parameters src_params;

                INSERT_PADDING_WORDS(0x13);
            };
            std::array<u32, NUM_REGS> reg_array;
        };
    } regs{};

private:
    Core::System& system;

    VideoCore::RasterizerInterface& rasterizer;

    MemoryManager& memory_manager;

    std::vector<u8> read_buffer;
    std::vector<u8> write_buffer;

    /// Performs the copy from the source buffer to the destination buffer as configured in the
    /// registers.
    void HandleCopy();
};

#define ASSERT_REG_POSITION(field_name, position)                                                  \
    static_assert(offsetof(MaxwellDMA::Regs, field_name) == position * 4,                          \
                  "Field " #field_name " has invalid position")

ASSERT_REG_POSITION(exec, 0xC0);
ASSERT_REG_POSITION(src_address, 0x100);
ASSERT_REG_POSITION(dst_address, 0x102);
ASSERT_REG_POSITION(src_pitch, 0x104);
ASSERT_REG_POSITION(dst_pitch, 0x105);
ASSERT_REG_POSITION(x_count, 0x106);
ASSERT_REG_POSITION(y_count, 0x107);
ASSERT_REG_POSITION(const0, 0x1C0);
ASSERT_REG_POSITION(const1, 0x1C1);
ASSERT_REG_POSITION(swizzle_config, 0x1C2);
ASSERT_REG_POSITION(dst_params, 0x1C3);
ASSERT_REG_POSITION(src_params, 0x1CA);

#undef ASSERT_REG_POSITION

} // namespace Tegra::Engines