ReXGlue SDK
Loading...
Searching...
No Matches
format.h File Reference

Data, texture, vertex and render target formats and conversions. More...

#include <algorithm>
#include <bit>
#include <rex/assert.h>
#include <rex/platform.h>
#include <rex/types.h>

Go to the source code of this file.

Namespaces

namespace  rex

Enumerations

enum class  rex::xenos::Endian : u32 { kNone = 0 , k8in16 = 1 , k8in32 = 2 , k16in32 = 3 }
enum class  rex::xenos::Endian128 : u32 {
  kNone = 0 , k8in16 = 1 , k8in32 = 2 , k16in32 = 3 ,
  k8in64 = 4 , k8in128 = 5
}
enum class  IndexFormat : u32 { kInt16 , kInt32 }
enum class  rex::xenos::SurfaceNumberFormat : u32 {
  kUnsignedRepeatingFraction = 0 , kSignedRepeatingFraction = 1 , kUnsignedInteger = 2 , kSignedInteger = 3 ,
  kFloat = 7
}
enum class  rex::xenos::ColorRenderTargetFormat : u32 {
  k_8_8_8_8 = 0 , k_8_8_8_8_GAMMA = 1 , k_2_10_10_10 = 2 , k_2_10_10_10_FLOAT = 3 ,
  k_16_16 = 4 , k_16_16_16_16 = 5 , k_16_16_FLOAT = 6 , k_16_16_16_16_FLOAT = 7 ,
  k_2_10_10_10_AS_10_10_10_10 = 10 , k_2_10_10_10_FLOAT_AS_16_16_16_16 = 12 , k_32_FLOAT = 14 , k_32_32_FLOAT = 15
}
enum class  rex::xenos::DepthRenderTargetFormat : u32 { kD24S8 = 0 , kD24FS8 = 1 }
enum class  rex::xenos::TextureFormat : u32 {
  k_1_REVERSE = 0 , k_1 = 1 , k_8 = 2 , k_1_5_5_5 = 3 ,
  k_5_6_5 = 4 , k_6_5_5 = 5 , k_8_8_8_8 = 6 , k_2_10_10_10 = 7 ,
  k_8_A = 8 , k_8_B = 9 , k_8_8 = 10 , k_Cr_Y1_Cb_Y0_REP = 11 ,
  k_Y1_Cr_Y0_Cb_REP = 12 , k_16_16_EDRAM = 13 , k_8_8_8_8_A = 14 , k_4_4_4_4 = 15 ,
  k_10_11_11 = 16 , k_11_11_10 = 17 , k_DXT1 = 18 , k_DXT2_3 = 19 ,
  k_DXT4_5 = 20 , k_16_16_16_16_EDRAM = 21 , k_24_8 = 22 , k_24_8_FLOAT = 23 ,
  k_16 = 24 , k_16_16 = 25 , k_16_16_16_16 = 26 , k_16_EXPAND = 27 ,
  k_16_16_EXPAND = 28 , k_16_16_16_16_EXPAND = 29 , k_16_FLOAT = 30 , k_16_16_FLOAT = 31 ,
  k_16_16_16_16_FLOAT = 32 , k_32 = 33 , k_32_32 = 34 , k_32_32_32_32 = 35 ,
  k_32_FLOAT = 36 , k_32_32_FLOAT = 37 , k_32_32_32_32_FLOAT = 38 , k_32_AS_8 = 39 ,
  k_32_AS_8_8 = 40 , k_16_MPEG = 41 , k_16_16_MPEG = 42 , k_8_INTERLACED = 43 ,
  k_32_AS_8_INTERLACED = 44 , k_32_AS_8_8_INTERLACED = 45 , k_16_INTERLACED = 46 , k_16_MPEG_INTERLACED = 47 ,
  k_16_16_MPEG_INTERLACED = 48 , k_DXN = 49 , k_8_8_8_8_AS_16_16_16_16 = 50 , k_DXT1_AS_16_16_16_16 = 51 ,
  k_DXT2_3_AS_16_16_16_16 = 52 , k_DXT4_5_AS_16_16_16_16 = 53 , k_2_10_10_10_AS_16_16_16_16 = 54 , k_10_11_11_AS_16_16_16_16 = 55 ,
  k_11_11_10_AS_16_16_16_16 = 56 , k_32_32_32_FLOAT = 57 , k_DXT3A = 58 , k_DXT5A = 59 ,
  k_CTX1 = 60 , k_DXT3A_AS_1_1_1_1 = 61 , k_8_8_8_8_GAMMA_EDRAM = 62 , k_2_10_10_10_FLOAT_EDRAM = 63
}
enum class  rex::xenos::ColorFormat : u32 {
  k_8 = 2 , k_1_5_5_5 = 3 , k_5_6_5 = 4 , k_6_5_5 = 5 ,
  k_8_8_8_8 = 6 , k_2_10_10_10 = 7 , k_8_A = 8 , k_8_B = 9 ,
  k_8_8 = 10 , k_8_8_8_8_A = 14 , k_4_4_4_4 = 15 , k_10_11_11 = 16 ,
  k_11_11_10 = 17 , k_16 = 24 , k_16_16 = 25 , k_16_16_16_16 = 26 ,
  k_16_FLOAT = 30 , k_16_16_FLOAT = 31 , k_16_16_16_16_FLOAT = 32 , k_32_FLOAT = 36 ,
  k_32_32_FLOAT = 37 , k_32_32_32_32_FLOAT = 38 , k_8_8_8_8_AS_16_16_16_16 = 50 , k_2_10_10_10_AS_16_16_16_16 = 54 ,
  k_10_11_11_AS_16_16_16_16 = 55 , k_11_11_10_AS_16_16_16_16 = 56
}
enum class  VertexFormat : u32 {
  kUndefined = 0 , k_8_8_8_8 = 6 , k_2_10_10_10 = 7 , k_10_11_11 = 16 ,
  k_11_11_10 = 17 , k_16_16 = 25 , k_16_16_16_16 = 26 , k_16_16_FLOAT = 31 ,
  k_16_16_16_16_FLOAT = 32 , k_32 = 33 , k_32_32 = 34 , k_32_32_32_32 = 35 ,
  k_32_FLOAT = 36 , k_32_32_FLOAT = 37 , k_32_32_32_32_FLOAT = 38 , k_32_32_32_FLOAT = 57
}

Functions

const char * rex::xenos::GetColorRenderTargetFormatName (ColorRenderTargetFormat format)
constexpr bool rex::xenos::IsColorRenderTargetFormat64bpp (ColorRenderTargetFormat format)
u32 rex::xenos::GetColorRenderTargetFormatComponentCount (ColorRenderTargetFormat format)
constexpr ColorRenderTargetFormat rex::xenos::GetStorageColorFormat (ColorRenderTargetFormat format)
const char * rex::xenos::GetDepthRenderTargetFormatName (DepthRenderTargetFormat format)
f32 rex::xenos::PWLGammaToLinear (f32 gamma)
f32 rex::xenos::LinearToPWLGamma (f32 linear)
f32 rex::xenos::Float7e3To32 (u32 f10)
u32 rex::xenos::Float32To20e4 (f32 value, bool round_to_nearest_even)
f32 rex::xenos::Float20e4To32 (u32 f24)
constexpr f32 rex::xenos::UNorm24To32 (u32 n24)
constexpr bool rex::xenos::IsColorResolveFormatBitwiseEquivalent (ColorRenderTargetFormat render_target_format, ColorFormat color_format)
int rex::xenos::GetVertexFormatComponentCount (VertexFormat format)
u32 rex::xenos::GetVertexFormatNeededWords (VertexFormat format, u32 used_components)
u16 rex::xenos::GPUSwap (u16 value, Endian endianness)
u32 rex::xenos::GPUSwap (u32 value, Endian endianness)
f32 rex::xenos::GPUSwap (f32 value, Endian endianness)
u32 rex::xenos::GPUToCPU (u32 p)
u32 rex::xenos::CPUToGPU (u32 p)
u16 rex::xenos::FloatToHalf (f32 value, bool preserve_denormal=false, bool round_to_nearest_even=false)
f32 rex::xenos::HalfToFloat (u16 value, bool preserve_denormal=false)

Variables

constexpr u32 rex::xenos::kColorRenderTargetFormatBits = 4
constexpr u32 rex::xenos::kDepthRenderTargetFormatBits = 1
constexpr u32 rex::xenos::kRenderTargetFormatBits
constexpr u32 rex::xenos::kFormatBits = 6

Detailed Description

Data, texture, vertex and render target formats and conversions.

License
BSD 3-Clause License See LICENSE file in the project root for full license text.
Remarks
Derived from Xenia's xenia/gpu/xenos.h (Ben Vanik, 2020).

Enumeration Type Documentation

◆ ColorFormat

enum class rex::xenos::ColorFormat : u32
strong

Subset of TextureFormat that render targets can be resolved to.

◆ ColorRenderTargetFormat

enum class rex::xenos::ColorRenderTargetFormat : u32
strong
Enumerator
k_8_8_8_8 

Four 8 bit unorm components.

k_8_8_8_8_GAMMA 

Four 8 bit components with gamma.

k_2_10_10_10 

Three 10 bit and one 2 bit unorm component.

k_2_10_10_10_FLOAT 

7e3 [0, 32) RGB with unorm alpha.

k_16_16 

Two 16 bit fixed point components in -32...32.

k_16_16_16_16 

Four 16 bit fixed point components in -32...32.

k_2_10_10_10_AS_10_10_10_10 

k_2_10_10_10 with 10 bit blending precision.

k_2_10_10_10_FLOAT_AS_16_16_16_16 

k_2_10_10_10_FLOAT with 16 bit blending.

◆ DepthRenderTargetFormat

enum class rex::xenos::DepthRenderTargetFormat : u32
strong
Enumerator
kD24S8 

24 bit unorm depth, 8 bit stencil.

kD24FS8 

20e4 [0, 2) floating point depth, 8 bit stencil.

◆ Endian

enum class rex::xenos::Endian : u32
strong

Endian swap mode for 32 bit data.

Enumerator
k8in16 

Swap bytes in 16 bit words.

k8in32 

Swap bytes in 32 bit words.

k16in32 

Swap 16 bit halves in 32 bit words.

◆ Endian128

enum class rex::xenos::Endian128 : u32
strong

Endian swap mode for up to 128 bit data.

Enumerator
k8in16 

Swap bytes in 16 bit words.

k8in32 

Swap bytes in 32 bit words.

k16in32 

Swap 16 bit halves in 32 bit words.

k8in64 

Swap bytes in 64 bit words.

k8in128 

Swap bytes in 128 bit words.

◆ SurfaceNumberFormat

enum class rex::xenos::SurfaceNumberFormat : u32
strong
Enumerator
kUnsignedRepeatingFraction 

Unsigned normalized.

kSignedRepeatingFraction 

Signed normalized with scale 2^(n-1) - 1.

◆ TextureFormat

enum class rex::xenos::TextureFormat : u32
strong
Enumerator
k_1_REVERSE 

1 bit, reversed.

k_8_A 

Sampled as k_8, may hold alpha in resolves.

k_8_B 

Sampled as k_8, may hold blue in resolves.

k_Cr_Y1_Cb_Y0_REP 

Packed unorm YCbCr, Cr Y1 Cb Y0 order.

k_Y1_Cr_Y0_Cb_REP 

Packed unorm YCbCr, Y1 Cr Y0 Cb order.

k_8_8_8_8_A 

Resolved and memexported as k_8_8_8_8.

k_24_8 

24 bit unorm depth and 8 bit stencil.

k_24_8_FLOAT 

20e4 depth and 8 bit stencil.

k_DXN 

DXN two component block compression.

k_CTX1 

CTX1 two component block compression.

k_2_10_10_10_FLOAT_EDRAM 

EDRAM 7e3 data.

Function Documentation

◆ CPUToGPU()

u32 rex::xenos::CPUToGPU ( u32 p)
inline

Converts a CPU address to a GPU physical address.

Parameters
pCPU address.
Returns
Low 29 bits of the address.

◆ Float20e4To32()

f32 rex::xenos::Float20e4To32 ( u32 f24)

Converts Xenos 20e4 depth to an IEEE 754 32 bit number without clamping.

Parameters
f24Value in bits 0:23.

◆ Float32To20e4()

u32 rex::xenos::Float32To20e4 ( f32 value,
bool round_to_nearest_even )

Converts an IEEE 754 32 bit number to Xenos 20e4 depth.

Parameters
valueValue to convert. Values not above 0 become 0.
round_to_nearest_evenRound to the nearest even value instead of toward 0.
Returns
20e4 value in bits 0:23.

◆ Float7e3To32()

f32 rex::xenos::Float7e3To32 ( u32 f10)

Converts a Xenos 7e3 color value to an IEEE 754 32 bit number without clamping.

Parameters
f10Value in bits 0:9.

◆ FloatToHalf()

u16 rex::xenos::FloatToHalf ( f32 value,
bool preserve_denormal = false,
bool round_to_nearest_even = false )
inline

Converts a 32 bit value to the Xenos 16 bit floating point encoding.

The encoding uses the extended range instead of infinity and NaN, and saturates.

Parameters
preserve_denormalKeep denormalized results instead of flushing them to 0.
round_to_nearest_evenRound to the nearest even value instead of toward 0.
Returns
16 bit encoded value.

◆ GetColorRenderTargetFormatComponentCount()

u32 rex::xenos::GetColorRenderTargetFormatComponentCount ( ColorRenderTargetFormat format)
inline
Returns
1, 2 or 4, or 0 for an unknown format.

◆ GetColorRenderTargetFormatName()

const char * rex::xenos::GetColorRenderTargetFormatName ( ColorRenderTargetFormat format)
Returns
Enumerator name, or "kUnknown".

◆ GetDepthRenderTargetFormatName()

const char * rex::xenos::GetDepthRenderTargetFormatName ( DepthRenderTargetFormat format)
Returns
Enumerator name, or "kUnknown".

◆ GetStorageColorFormat()

ColorRenderTargetFormat rex::xenos::GetStorageColorFormat ( ColorRenderTargetFormat format)
constexpr

Strips the blending precision modifier from a color render target format.

Returns
Format with the same packing and value meaning, without the modifier.

◆ GetVertexFormatComponentCount()

int rex::xenos::GetVertexFormatComponentCount ( VertexFormat format)
inline
Returns
1 to 4, or 0 for an unknown format.

◆ GetVertexFormatNeededWords()

u32 rex::xenos::GetVertexFormatNeededWords ( VertexFormat format,
u32 used_components )
inline

Returns which 32 bit words of a vertex element hold the used components. The mask uses bits 0:3.

Parameters
used_componentsMask of used components in bits 0:3.

◆ GPUSwap() [1/2]

f32 rex::xenos::GPUSwap ( f32 value,
Endian endianness )
inline

Applies a GPU endian swap to the bits of a 32 bit floating point value.

◆ GPUSwap() [2/2]

u16 rex::xenos::GPUSwap ( u16 value,
Endian endianness )
inline

Applies a GPU endian swap to a 16 bit value.

Parameters
endiannessSwap mode, kNone or k8in16.

◆ GPUToCPU()

u32 rex::xenos::GPUToCPU ( u32 p)
inline

Converts a GPU address to a CPU address.

Parameters
pGPU address.
Returns
The address unchanged.

◆ HalfToFloat()

f32 rex::xenos::HalfToFloat ( u16 value,
bool preserve_denormal = false )
inline

Converts a Xenos 16 bit floating point value to 32 bits.

Parameters
value16 bit encoded value.
preserve_denormalKeep denormalized inputs instead of flushing them to 0.

◆ IsColorRenderTargetFormat64bpp()

bool rex::xenos::IsColorRenderTargetFormat64bpp ( ColorRenderTargetFormat format)
constexpr

Reports whether a color render target format uses 64 bits per sample.

Returns
True when the format is k_16_16_16_16, k_16_16_16_16_FLOAT or k_32_32_FLOAT.

◆ IsColorResolveFormatBitwiseEquivalent()

bool rex::xenos::IsColorResolveFormatBitwiseEquivalent ( ColorRenderTargetFormat render_target_format,
ColorFormat color_format )
constexpr

Reports whether resolving a render target format to a color format copies bits unchanged.

Resolves write unsigned data for fixed point formats, so the signed k_16_16 and k_16_16_16_16 render target formats never match.

Returns
True when the resolve is a bitwise copy.

◆ LinearToPWLGamma()

f32 rex::xenos::LinearToPWLGamma ( f32 linear)

Converts a linear value to piecewise linear gamma.

Parameters
linearLinear value, saturated before conversion.
Returns
Value from 0 to 1 on the gamma curve.

◆ PWLGammaToLinear()

f32 rex::xenos::PWLGammaToLinear ( f32 gamma)

Converts a piecewise linear gamma value to linear.

Parameters
gammaGamma value, saturated before conversion.
Returns
Value from 0 to 1 on the linear scale.

◆ UNorm24To32()

f32 rex::xenos::UNorm24To32 ( u32 n24)
constexpr

Converts 24 bit unorm depth to an IEEE 754 32 bit number without clamping.

Variable Documentation

◆ kRenderTargetFormatBits

u32 rex::xenos::kRenderTargetFormatBits
constexpr
Initial value:
=
std::max(kColorRenderTargetFormatBits, kDepthRenderTargetFormatBits)

Width of a field that holds either render target format.