summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_vulkan/fixed_pipeline_state.h
blob: 4c8ba7f90bb7410efdf977bd046e9a9794110737 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <array>
#include <type_traits>

#include "common/common_types.h"

#include "video_core/engines/maxwell_3d.h"
#include "video_core/surface.h"

namespace Vulkan {

using Maxwell = Tegra::Engines::Maxwell3D::Regs;

// TODO(Rodrigo): Optimize this structure.

struct FixedPipelineState {
    using PixelFormat = VideoCore::Surface::PixelFormat;

    struct VertexBinding {
        constexpr VertexBinding(u32 index, u32 stride, u32 divisor)
            : index{index}, stride{stride}, divisor{divisor} {}
        VertexBinding() = default;

        u32 index;
        u32 stride;
        u32 divisor;

        std::size_t Hash() const noexcept;

        bool operator==(const VertexBinding& rhs) const noexcept;

        bool operator!=(const VertexBinding& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct VertexAttribute {
        constexpr VertexAttribute(u32 index, u32 buffer, Maxwell::VertexAttribute::Type type,
                                  Maxwell::VertexAttribute::Size size, u32 offset)
            : index{index}, buffer{buffer}, type{type}, size{size}, offset{offset} {}
        VertexAttribute() = default;

        u32 index;
        u32 buffer;
        Maxwell::VertexAttribute::Type type;
        Maxwell::VertexAttribute::Size size;
        u32 offset;

        std::size_t Hash() const noexcept;

        bool operator==(const VertexAttribute& rhs) const noexcept;

        bool operator!=(const VertexAttribute& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct StencilFace {
        constexpr StencilFace(Maxwell::StencilOp action_stencil_fail,
                              Maxwell::StencilOp action_depth_fail,
                              Maxwell::StencilOp action_depth_pass, Maxwell::ComparisonOp test_func)
            : action_stencil_fail{action_stencil_fail}, action_depth_fail{action_depth_fail},
              action_depth_pass{action_depth_pass}, test_func{test_func} {}
        StencilFace() = default;

        Maxwell::StencilOp action_stencil_fail;
        Maxwell::StencilOp action_depth_fail;
        Maxwell::StencilOp action_depth_pass;
        Maxwell::ComparisonOp test_func;

        std::size_t Hash() const noexcept;

        bool operator==(const StencilFace& rhs) const noexcept;

        bool operator!=(const StencilFace& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct BlendingAttachment {
        constexpr BlendingAttachment(bool enable, Maxwell::Blend::Equation rgb_equation,
                                     Maxwell::Blend::Factor src_rgb_func,
                                     Maxwell::Blend::Factor dst_rgb_func,
                                     Maxwell::Blend::Equation a_equation,
                                     Maxwell::Blend::Factor src_a_func,
                                     Maxwell::Blend::Factor dst_a_func,
                                     std::array<bool, 4> components)
            : enable{enable}, rgb_equation{rgb_equation}, src_rgb_func{src_rgb_func},
              dst_rgb_func{dst_rgb_func}, a_equation{a_equation}, src_a_func{src_a_func},
              dst_a_func{dst_a_func}, components{components} {}
        BlendingAttachment() = default;

        bool enable;
        Maxwell::Blend::Equation rgb_equation;
        Maxwell::Blend::Factor src_rgb_func;
        Maxwell::Blend::Factor dst_rgb_func;
        Maxwell::Blend::Equation a_equation;
        Maxwell::Blend::Factor src_a_func;
        Maxwell::Blend::Factor dst_a_func;
        std::array<bool, 4> components;

        std::size_t Hash() const noexcept;

        bool operator==(const BlendingAttachment& rhs) const noexcept;

        bool operator!=(const BlendingAttachment& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct VertexInput {
        std::size_t num_bindings = 0;
        std::size_t num_attributes = 0;
        std::array<VertexBinding, Maxwell::NumVertexArrays> bindings;
        std::array<VertexAttribute, Maxwell::NumVertexAttributes> attributes;

        std::size_t Hash() const noexcept;

        bool operator==(const VertexInput& rhs) const noexcept;

        bool operator!=(const VertexInput& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct InputAssembly {
        constexpr InputAssembly(Maxwell::PrimitiveTopology topology, bool primitive_restart_enable,
                                float point_size)
            : topology{topology}, primitive_restart_enable{primitive_restart_enable},
              point_size{point_size} {}
        InputAssembly() = default;

        Maxwell::PrimitiveTopology topology;
        bool primitive_restart_enable;
        float point_size;

        std::size_t Hash() const noexcept;

        bool operator==(const InputAssembly& rhs) const noexcept;

        bool operator!=(const InputAssembly& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct Tessellation {
        constexpr Tessellation(u32 patch_control_points, Maxwell::TessellationPrimitive primitive,
                               Maxwell::TessellationSpacing spacing, bool clockwise)
            : patch_control_points{patch_control_points}, primitive{primitive}, spacing{spacing},
              clockwise{clockwise} {}
        Tessellation() = default;

        u32 patch_control_points;
        Maxwell::TessellationPrimitive primitive;
        Maxwell::TessellationSpacing spacing;
        bool clockwise;

        std::size_t Hash() const noexcept;

        bool operator==(const Tessellation& rhs) const noexcept;

        bool operator!=(const Tessellation& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct Rasterizer {
        constexpr Rasterizer(bool cull_enable, bool depth_bias_enable, bool depth_clamp_enable,
                             bool ndc_minus_one_to_one, Maxwell::CullFace cull_face,
                             Maxwell::FrontFace front_face)
            : cull_enable{cull_enable}, depth_bias_enable{depth_bias_enable},
              depth_clamp_enable{depth_clamp_enable}, ndc_minus_one_to_one{ndc_minus_one_to_one},
              cull_face{cull_face}, front_face{front_face} {}
        Rasterizer() = default;

        bool cull_enable;
        bool depth_bias_enable;
        bool depth_clamp_enable;
        bool ndc_minus_one_to_one;
        Maxwell::CullFace cull_face;
        Maxwell::FrontFace front_face;

        std::size_t Hash() const noexcept;

        bool operator==(const Rasterizer& rhs) const noexcept;

        bool operator!=(const Rasterizer& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct DepthStencil {
        constexpr DepthStencil(bool depth_test_enable, bool depth_write_enable,
                               bool depth_bounds_enable, bool stencil_enable,
                               Maxwell::ComparisonOp depth_test_function, StencilFace front_stencil,
                               StencilFace back_stencil)
            : depth_test_enable{depth_test_enable}, depth_write_enable{depth_write_enable},
              depth_bounds_enable{depth_bounds_enable}, stencil_enable{stencil_enable},
              depth_test_function{depth_test_function}, front_stencil{front_stencil},
              back_stencil{back_stencil} {}
        DepthStencil() = default;

        bool depth_test_enable;
        bool depth_write_enable;
        bool depth_bounds_enable;
        bool stencil_enable;
        Maxwell::ComparisonOp depth_test_function;
        StencilFace front_stencil;
        StencilFace back_stencil;

        std::size_t Hash() const noexcept;

        bool operator==(const DepthStencil& rhs) const noexcept;

        bool operator!=(const DepthStencil& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    struct ColorBlending {
        constexpr ColorBlending(
            std::array<float, 4> blend_constants, std::size_t attachments_count,
            std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments)
            : attachments_count{attachments_count}, attachments{attachments} {}
        ColorBlending() = default;

        std::size_t attachments_count;
        std::array<BlendingAttachment, Maxwell::NumRenderTargets> attachments;

        std::size_t Hash() const noexcept;

        bool operator==(const ColorBlending& rhs) const noexcept;

        bool operator!=(const ColorBlending& rhs) const noexcept {
            return !operator==(rhs);
        }
    };

    std::size_t Hash() const noexcept;

    bool operator==(const FixedPipelineState& rhs) const noexcept;

    bool operator!=(const FixedPipelineState& rhs) const noexcept {
        return !operator==(rhs);
    }

    VertexInput vertex_input;
    InputAssembly input_assembly;
    Tessellation tessellation;
    Rasterizer rasterizer;
    DepthStencil depth_stencil;
    ColorBlending color_blending;
};
static_assert(std::is_trivially_copyable_v<FixedPipelineState::VertexBinding>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::VertexAttribute>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::StencilFace>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::BlendingAttachment>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::VertexInput>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::InputAssembly>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::Tessellation>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::Rasterizer>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::DepthStencil>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState::ColorBlending>);
static_assert(std::is_trivially_copyable_v<FixedPipelineState>);

FixedPipelineState GetFixedPipelineState(const Maxwell& regs);

} // namespace Vulkan

namespace std {

template <>
struct hash<Vulkan::FixedPipelineState> {
    std::size_t operator()(const Vulkan::FixedPipelineState& k) const noexcept {
        return k.Hash();
    }
};

} // namespace std