/
GXPipelineTypes.h
130 lines (121 loc) · 4.04 KB
/
GXPipelineTypes.h
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
// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "VideoCommon/GeometryShaderGen.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/RenderState.h"
#include "VideoCommon/UberShaderPixel.h"
#include "VideoCommon/UberShaderVertex.h"
#include "VideoCommon/VertexShaderGen.h"
class NativeVertexFormat;
namespace VideoCommon
{
// This version number must be incremented whenever any of the shader UID structures change.
// As pipelines encompass both shader UIDs and render states, changes to either of these should
// also increment the pipeline UID version. Incrementing the UID version will cause all UID
// caches to be invalidated.
constexpr u32 GX_PIPELINE_UID_VERSION = 4; // Last changed in PR 10215
struct GXPipelineUid
{
const NativeVertexFormat* vertex_format;
VertexShaderUid vs_uid;
GeometryShaderUid gs_uid;
PixelShaderUid ps_uid;
RasterizationState rasterization_state;
DepthState depth_state;
BlendingState blending_state;
// We use memcmp() for comparing pipelines as std::tie generates a large number of instructions,
// and this map lookup can happen every draw call. However, as using memcmp() will also compare
// any padding bytes, we have to ensure these are zeroed out.
GXPipelineUid() { std::memset(static_cast<void*>(this), 0, sizeof(*this)); }
#ifdef _MSC_VER
#pragma warning(push)
// Disable warning for uninitialized member variables, as MSVC doesn't recognise that memcpy
// performs this initialization.
#pragma warning(disable : 26495)
#endif
GXPipelineUid(const GXPipelineUid& rhs)
{
std::memcpy(static_cast<void*>(this), &rhs, sizeof(*this));
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
GXPipelineUid& operator=(const GXPipelineUid& rhs)
{
std::memcpy(static_cast<void*>(this), &rhs, sizeof(*this));
return *this;
}
bool operator<(const GXPipelineUid& rhs) const
{
return std::memcmp(this, &rhs, sizeof(*this)) < 0;
}
bool operator==(const GXPipelineUid& rhs) const
{
return std::memcmp(this, &rhs, sizeof(*this)) == 0;
}
bool operator!=(const GXPipelineUid& rhs) const { return !operator==(rhs); }
};
struct GXUberPipelineUid
{
const NativeVertexFormat* vertex_format;
UberShader::VertexShaderUid vs_uid;
GeometryShaderUid gs_uid;
UberShader::PixelShaderUid ps_uid;
RasterizationState rasterization_state;
DepthState depth_state;
BlendingState blending_state;
GXUberPipelineUid() { std::memset(static_cast<void*>(this), 0, sizeof(*this)); }
#ifdef _MSC_VER
#pragma warning(push)
// Disable warning for uninitialized member variables
#pragma warning(disable : 26495)
#endif
GXUberPipelineUid(const GXUberPipelineUid& rhs)
{
std::memcpy(static_cast<void*>(this), &rhs, sizeof(*this));
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
GXUberPipelineUid& operator=(const GXUberPipelineUid& rhs)
{
std::memcpy(static_cast<void*>(this), &rhs, sizeof(*this));
return *this;
}
bool operator<(const GXUberPipelineUid& rhs) const
{
return std::memcmp(this, &rhs, sizeof(*this)) < 0;
}
bool operator==(const GXUberPipelineUid& rhs) const
{
return std::memcmp(this, &rhs, sizeof(*this)) == 0;
}
bool operator!=(const GXUberPipelineUid& rhs) const { return !operator==(rhs); }
};
// Disk cache of pipeline UIDs. We can't use the whole UID as a type as it contains pointers.
// This structure is safe to save to disk, and should be compiler/platform independent.
#pragma pack(push, 1)
struct SerializedGXPipelineUid
{
PortableVertexDeclaration vertex_decl{};
VertexShaderUid vs_uid;
GeometryShaderUid gs_uid;
PixelShaderUid ps_uid;
u32 rasterization_state_bits = 0;
u32 depth_state_bits = 0;
u32 blending_state_bits = 0;
};
struct SerializedGXUberPipelineUid
{
PortableVertexDeclaration vertex_decl{};
UberShader::VertexShaderUid vs_uid;
GeometryShaderUid gs_uid;
UberShader::PixelShaderUid ps_uid;
u32 rasterization_state_bits = 0;
u32 depth_state_bits = 0;
u32 blending_state_bits = 0;
};
#pragma pack(pop)
} // namespace VideoCommon