ReXGlue SDK
Loading...
Searching...
No Matches
state.h
Go to the documentation of this file.
1
13
14#pragma once
15
16#include <utility>
17
18#include <rex/assert.h>
19#include <rex/types.h>
20
21namespace rex::xenos {
22
23// NOLINTNEXTLINE(performance-enum-size): packed key bit field, MSVC packs per type
24enum class ShaderType : u32 {
25 kVertex = 0,
26 kPixel = 1,
27};
28
30constexpr u32 kVertexIndexBits = 24;
31constexpr u32 kVertexIndexMask = (static_cast<u32>(1) << kVertexIndexBits) - 1;
32
34// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
35enum class PrimitiveType : u32 {
36 kNone = 0x00,
37 kPointList = 0x01,
38 kLineList = 0x02,
39 kLineStrip = 0x03,
40 kTriangleList = 0x04,
41 kTriangleFan = 0x05,
42 kTriangleStrip = 0x06,
43 kTriangleWithWFlags = 0x07,
45 kLineLoop = 0x0C,
46 kQuadList = 0x0D,
47 kQuadStrip = 0x0E,
48 kPolygon = 0x0F,
49 kExplicitMajorModeForceStart = 0x10,
50 k2DCopyRectListV0 = 0x10,
51 k2DCopyRectListV1 = 0x11,
52 k2DCopyRectListV2 = 0x12,
53 k2DCopyRectListV3 = 0x13,
54 k2DFillRectList = 0x14,
55 k2DLineStrip = 0x15,
56 k2DTriStrip = 0x16,
57 kLinePatch = 0x10,
59 kQuadPatch = 0x12,
60};
61
62// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
63enum class SampleLocation : u32 {
64 kCentroid = 0,
65 kCenter = 1,
66};
67
68// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
69enum class MSAASamples : u32 {
70 k1X = 0,
71 k2X = 1,
72 k4X = 2,
73};
74
75constexpr u32 kMSAASamplesBits = 2;
76
77constexpr u32 kColorRenderTargetIndexBits = 2;
78constexpr u32 kMaxColorRenderTargets = 4;
79
81constexpr f32 kPolygonOffsetScaleSubpixelUnit = 1.0f / 16.0f;
82
84constexpr u32 kEDRAMTileWidthSamples = 80;
86constexpr u32 kEDRAMTileHeightSamples = 16;
88constexpr u32 kEDRAMTileCount = 2048;
89constexpr u32 kEDRAMSizeBytes = static_cast<u32>(u64{kEDRAMTileCount} * kEDRAMTileHeightSamples *
90 kEDRAMTileWidthSamples * sizeof(u32));
91
93constexpr u32 kEDRAMPitchPixelsBits = 14;
95constexpr u32 kEDRAMBaseTilesBits = 11;
96
104constexpr u32 GetSurfacePitchTiles(u32 pitch_pixels, MSAASamples msaa_samples, bool is_64bpp) {
105 u32 pitch_samples = pitch_pixels << static_cast<u32>(msaa_samples >= MSAASamples::k4X);
106 u32 pitch_tiles = (pitch_samples + (kEDRAMTileWidthSamples - 1)) / kEDRAMTileWidthSamples;
107 if (is_64bpp) {
108 pitch_tiles <<= 1;
109 }
110 return pitch_tiles;
111}
112
114constexpr u32 kEDRAMPitchTilesBits = 10;
115
116// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
117enum class CompareFunction : u32 {
118 kNever = 0b000,
119 kLess = 0b001,
120 kEqual = 0b010,
121 kLessEqual = 0b011,
122 kGreater = 0b100,
123 kNotEqual = 0b101,
124 kGreaterEqual = 0b110,
125 kAlways = 0b111,
126};
127
128// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
129enum class StencilOp : u32 {
130 kKeep = 0,
131 kZero = 1,
132 kReplace = 2,
133 kIncrementClamp = 3,
134 kDecrementClamp = 4,
135 kInvert = 5,
136 kIncrementWrap = 6,
137 kDecrementWrap = 7,
138};
139
141// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
142enum class BlendFactor : u32 {
143 kZero = 0,
144 kOne = 1,
145 kSrcColor = 4,
146 kOneMinusSrcColor = 5,
147 kSrcAlpha = 6,
148 kOneMinusSrcAlpha = 7,
149 kDstColor = 8,
150 kOneMinusDstColor = 9,
151 kDstAlpha = 10,
152 kOneMinusDstAlpha = 11,
153 kConstantColor = 12,
154 kOneMinusConstantColor = 13,
155 kConstantAlpha = 14,
156 kOneMinusConstantAlpha = 15,
157 kSrcAlphaSaturate = 16,
158};
159
160// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
161enum class BlendOp : u32 {
162 kAdd = 0,
163 kSubtract = 1,
164 kMin = 2,
165 kMax = 3,
167};
168
169enum class InvalidateMask : u16 {
170 kVertexShader = 1 << 8,
171 kPixelShader = 1 << 9,
172 kAll = 0x7FFF,
173};
174
176// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
177enum class SourceSelect : u32 {
179 kImmediate,
181};
182
184// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
185enum class MajorMode : u32 {
186 kImplicit,
187 kExplicit,
188};
189
195inline bool IsMajorModeExplicit(MajorMode major_mode, PrimitiveType primitive_type) {
196 return major_mode != MajorMode::kImplicit ||
197 primitive_type >= PrimitiveType::kExplicitMajorModeForceStart;
198}
199
201// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
206
208// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
209enum class ArbitraryFilter : u32 {
210 k2x4Sym = 0,
211 k2x4Asym = 1,
212 k4x2Sym = 2,
213 k4x2Asym = 3,
214 k4x4Sym = 4,
215 k4x4Asym = 5,
217};
218
219constexpr u32 kMaxShaderTempRegistersLog2 = 6;
220constexpr u32 kMaxShaderTempRegisters = UINT32_C(1) << kMaxShaderTempRegistersLog2;
221
223// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
224enum class VertexShaderExportMode : u32 {
225 kPosition1Vector = 0,
226 kPosition2VectorsSprite = 2,
227 kPosition2VectorsEdge = 3,
228 kPosition2VectorsKill = 4,
229 kPosition2VectorsSpriteKill = 5,
230 kPosition2VectorsEdgeKill = 6,
232};
233
234constexpr u32 kMaxInterpolators = 16;
235
237// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
238enum class SampleControl : u32 {
239 kCentroidsOnly = 0,
240 kCentersOnly = 1,
242};
243
251inline u32 GetInterpolatorSamplingPattern(MSAASamples msaa_samples, SampleControl sample_control,
252 u32 interpolator_control_sampling_pattern) {
253 if (msaa_samples == MSAASamples::k1X || sample_control == SampleControl::kCentersOnly) {
254 return ((1 << kMaxInterpolators) - 1) * std::to_underlying(SampleLocation::kCenter);
255 }
256 if (sample_control == SampleControl::kCentroidsOnly) {
257 return ((1 << kMaxInterpolators) - 1) * std::to_underlying(SampleLocation::kCentroid);
258 }
260 return interpolator_control_sampling_pattern;
261}
262
264// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
265enum class VGTOutputPath : u32 {
266 kVertexReuse = 0,
267 kTessellationEnable = 1,
268 kPassthru = 2,
269};
270
271// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
272enum class TessellationMode : u32 {
273 kDiscrete = 0,
274 kContinuous = 1,
275 kAdaptive = 2,
276};
277
279// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
280enum class PolygonModeEnable : u32 {
281 kDisabled = 0,
282 kDualMode = 1,
283};
284
285// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
286enum class PolygonType : u32 {
287 kPoints = 0,
288 kLines = 1,
289 kTriangles = 2,
290};
291
293// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
294enum class PixelCenter : u32 {
297};
298
299// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
300enum class VertexRounding : u32 {
302 kRound = 1,
304 kRoundToOdd = 3,
305};
306
307// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
308enum class VertexQuantization : u32 {
309 k_1_16th = 0,
310 k_1_8th = 1,
311 k_1_4th = 2,
312 k_1_2 = 3,
313 k_1 = 4,
314};
315
316// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
317enum class EDRAMMode : u32 {
318 kNoOperation = 0,
319 kColorDepth = 4,
321 kCopy = 6,
322};
323
324constexpr u32 kResolveAlignmentPixelsLog2 = 3;
325constexpr u32 kResolveAlignmentPixels = 1 << kResolveAlignmentPixelsLog2;
326
328constexpr u32 kResolveSizeBits = 14;
329constexpr u32 kMaxResolveSize = (1 << kResolveSizeBits) - kResolveAlignmentPixels;
330
331// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
332enum class CopyCommand : u32 {
333 kRaw = 0,
334 kConvert = 1,
335 kConstantOne = 2,
336 kNull = 3,
337};
338
340// NOLINTNEXTLINE(performance-enum-size): Xenos bit field, MSVC packs per type
341enum class CopySampleSelect : u32 {
342 k0,
343 k1,
344 k2,
345 k3,
349};
350
356constexpr bool IsSingleCopySampleSelected(CopySampleSelect copy_sample_select) {
357 return copy_sample_select >= CopySampleSelect::k0 && copy_sample_select <= CopySampleSelect::k3;
358}
359
361struct alignas(u32) DepthSampleCounts {
362 LE<u32> Total_A;
363 LE<u32> Total_B;
364 LE<u32> ZFail_A;
365 LE<u32> ZFail_B;
366 LE<u32> ZPass_A;
367 LE<u32> ZPass_B;
368 LE<u32> StencilFail_A;
369 LE<u32> StencilFail_B;
370};
371REX_STATIC_ASSERT_SIZE(DepthSampleCounts, sizeof(u32) * 8);
372
373} // namespace rex::xenos
#define REX_ASSERT(cond,...)
Definition assert.h:84
@ kUseFetchConst
Definition fetch.h:69
@ kSubtract
Definition input_keys.h:157
@ kAdd
Definition input_keys.h:155
PolygonModeEnable
Definition state.h:280
constexpr f32 kPolygonOffsetScaleSubpixelUnit
Definition state.h:81
constexpr u32 kEDRAMTileHeightSamples
Definition state.h:86
SampleControl
Definition state.h:238
@ kCentroidsAndCenters
Definition state.h:241
constexpr u32 kResolveSizeBits
Definition state.h:328
PrimitiveType
Definition state.h:35
@ kRectangleList
Definition state.h:44
@ kQuadPatch
Definition state.h:59
@ kTrianglePatch
Definition state.h:58
@ kLinePatch
Definition state.h:57
BlendFactor
Definition state.h:142
bool IsMajorModeExplicit(MajorMode major_mode, PrimitiveType primitive_type)
Definition state.h:195
constexpr u32 kEDRAMBaseTilesBits
Definition state.h:95
constexpr u32 kEDRAMTileCount
Definition state.h:88
constexpr u32 kEDRAMTileWidthSamples
Definition state.h:84
MSAASamples
Definition state.h:69
@ k2X
Definition state.h:71
@ k4X
Definition state.h:72
constexpr u32 kVertexIndexBits
Definition state.h:30
constexpr u32 kEDRAMPitchTilesBits
Definition state.h:114
BlendOp
Definition state.h:161
@ kRevSubtract
Definition state.h:166
CopySampleSelect
Definition state.h:341
@ k01
Definition state.h:346
@ k23
Definition state.h:347
@ k0123
Definition state.h:348
ArbitraryFilter
Definition state.h:209
SourceSelect
Definition state.h:177
@ kAutoIndex
Definition state.h:180
@ kDMA
Definition state.h:178
u32 GetInterpolatorSamplingPattern(MSAASamples msaa_samples, SampleControl sample_control, u32 interpolator_control_sampling_pattern)
Definition state.h:251
VGTOutputPath
Definition state.h:265
constexpr u32 GetSurfacePitchTiles(u32 pitch_pixels, MSAASamples msaa_samples, bool is_64bpp)
Definition state.h:104
PixelCenter
Definition state.h:294
@ kD3DZero
Definition state.h:295
@ kOGLHalf
Definition state.h:296
constexpr u32 kEDRAMPitchPixelsBits
Definition state.h:93
VertexRounding
Definition state.h:300
@ kTruncate
Definition state.h:301
@ kRoundToEven
Definition state.h:303
SignedRepeatingFractionMode
Definition state.h:202
@ kZeroClampMinusOne
Definition state.h:203
VertexShaderExportMode
Definition state.h:224
@ kMultipass
Definition state.h:231
EDRAMMode
Definition state.h:317
@ kDepthOnly
Definition state.h:320
MajorMode
Definition state.h:185
constexpr bool IsSingleCopySampleSelected(CopySampleSelect copy_sample_select)
Definition state.h:356
Definition state.h:361
Integer types, byte order wrappers and size literals.