-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEffectFormat.hpp
More file actions
251 lines (211 loc) · 6.14 KB
/
EffectFormat.hpp
File metadata and controls
251 lines (211 loc) · 6.14 KB
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
#pragma once
#include "gapi/Shader.hpp"
#include "gapi/PipelineState.hpp"
#include "gapi/BindingGroupLayout.hpp"
#include <vector>
#include <cstdint>
#include <cstddef>
namespace RR::EffectLibrary
{
namespace Asset
{
#pragma pack(push, 1)
static constexpr uint32_t INVALID_INDEX = static_cast<uint32_t>(-1);
enum class FieldType : uint8_t
{
Array,
Struct,
Bool,
Bool2,
Bool3,
Bool4,
Uint8,
Uint8_2,
Uint8_3,
Uint8_4,
Uint16,
Uint16_2,
Uint16_3,
Uint16_4,
Uint,
Uint2,
Uint3,
Uint4,
Uint64,
Uint64_2,
Uint64_3,
Uint64_4,
Int8,
Int8_2,
Int8_3,
Int8_4,
Int16,
Int16_2,
Int16_3,
Int16_4,
Int,
Int2,
Int3,
Int4,
Int64,
Int64_2,
Int64_3,
Int64_4,
Float16,
Float16_2,
Float16_3,
Float16_4,
Float16_2x2,
Float16_2x3,
Float16_2x4,
Float16_3x2,
Float16_3x3,
Float16_3x4,
Float16_4x2,
Float16_4x3,
Float16_4x4,
Float,
Float2,
Float3,
Float4,
Float2x2,
Float2x3,
Float2x4,
Float3x2,
Float3x3,
Float3x4,
Float4x2,
Float4x3,
Float4x4,
Float64,
Float64_2,
Float64_3,
Float64_4,
};
struct SrvReflection
{
uint32_t nameIndex;
GAPI::ShaderStageMask usageMask;
GAPI::GpuResourceDimension dimension;
GAPI::TextureSampleType sampleType;
uint32_t binding; // Slot index
uint32_t count; // 0 or 1 = not array, >1 = array
};
struct UavReflection
{
uint32_t nameIndex;
GAPI::ShaderStageMask usageMask;
GAPI::GpuResourceDimension dimension;
GAPI::GpuResourceFormat format;
// TODO: Store acess type.
uint32_t binding; // Slot indexx
uint32_t count; // 0 or 1 = not array, >1 = array
};
struct CbvReflection
{
uint32_t nameIndex;
GAPI::ShaderStageMask usageMask;
uint32_t binding; // Slot index
uint32_t count; // 0 or 1 = not array, >1 = array
uint32_t layoutIndex;
};
struct UniformReflection
{
uint32_t nameIndex;
FieldType type;
uint32_t offset; // Offset in bytes relative to the start of the parent structure/buffer
uint32_t size; // Size in bytes
uint32_t arraySize; // 0 or 1 = not array, >1 = array
uint32_t layoutIndex; // For structs
};
struct Layout
{
uint32_t elementsCount;
// List of indexes to fields or other resources
};
struct BindGroup
{
uint32_t nameIndex;
uint32_t bindingSpace;
uint32_t uniformCBV;
uint32_t resourcesLayoutIndex;
};
struct Header
{
static constexpr uint32_t MAGIC = 0x4C584652;
static constexpr uint32_t VERSION = 2;
uint32_t magic;
uint32_t version;
uint32_t stringsSectionSize;
uint32_t stringsCount;
uint32_t shadersSectionSize;
uint32_t shadersCount;
uint32_t srvSectionSize;
uint32_t srvCount;
uint32_t uavSectionSize;
uint32_t uavCount;
uint32_t cbvSectionSize;
uint32_t cbvCount;
uint32_t effectsSectionSize;
uint32_t effectsCount;
uint32_t uniformsSectionSize;
uint32_t uniformsCount;
uint32_t layoutsSectionSize;
uint32_t layoutsCount;
uint32_t bindGroupsSectionSize;
uint32_t bindGroupsCount;
};
struct ShaderDesc
{
uint32_t nameIndex;
GAPI::ShaderStage stage;
uint32_t size;
// DATA block
};
struct PassDesc
{
uint32_t nameIndex;
GAPI::BlendDesc blendDesc;
GAPI::RasterizerDesc rasterizerDesc;
GAPI::DepthStencilDesc depthStencilDesc;
GAPI::ShaderStageMask shaderStages;
uint32_t rootBindingGroupIndex;
// List of shader indexes based on shaderStages mask
};
struct EffectDesc
{
uint32_t nameIndex;
uint32_t passCount;
// PASSES block
};
#pragma pack(pop)
// Resource ID encoding: upper 4 bits = type tag, lower 28 bits = index.
//
// [31..28] ResourceType (4 bits, 16 possible types)
// [27.. 0] index (28 bits, up to 268M resources per type)
//
// INVALID_INDEX (0xFFFFFFFF) is a special sentinel and is NOT a
// valid tagged resource ID.
enum class ResourceType : uint32_t
{
SRV = 0,
UAV = 1,
CBV = 2,
};
static constexpr uint32_t RESOURCE_TYPE_SHIFT = 28u;
static constexpr uint32_t RESOURCE_TYPE_MASK = 0xF0000000u;
static constexpr uint32_t RESOURCE_INDEX_MASK = 0x0FFFFFFFu;
inline uint32_t MakeResourceId(ResourceType type, uint32_t index)
{
return (static_cast<uint32_t>(type) << RESOURCE_TYPE_SHIFT) | (index & RESOURCE_INDEX_MASK);
}
inline ResourceType GetResourceType(uint32_t id)
{
return static_cast<ResourceType>((id >> RESOURCE_TYPE_SHIFT) & 0xFu);
}
inline uint32_t GetResourceIndex(uint32_t id)
{
return id & RESOURCE_INDEX_MASK;
}
}
}