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

Xenos texture info, memory layout and format conversion. More...

#include <memory>
#include <algorithm>
#include <cstring>
#include <functional>
#include <rex/platform.h>
#include <rex/assert.h>
#include <rex/types.h>
#include <rex/xenos/fetch.h>
#include <rex/xenos/format.h>
#include <rex/bit.h>

Go to the source code of this file.

Classes

struct  rex::xenos::GuestTextureLayout
struct  rex::xenos::GuestTextureLayout::Level
struct  rex::xenos::FormatInfo
struct  rex::xenos::TextureExtent
struct  rex::xenos::TextureMemoryRanges
struct  rex::xenos::TextureInfo
struct  rex::xenos::UntileRegion

Namespaces

namespace  rex

Typedefs

using rex::xenos::CopyBlockCallback = std::function<void(xenos::Endian, void*, const void*, size_t)>
using rex::xenos::UntileCopyBlockCallback = std::function<void(void*, const void*, size_t)>

Enumerations

enum class  rex::xenos::FormatType : u8 { kResolvable , kUncompressed , kCompressed }

Functions

void rex::xenos::GetSubresourcesFromFetchConstant (const xenos::TextureFetch &fetch, u32 *width_minus_1_out, u32 *height_minus_1_out, u32 *depth_or_array_size_minus_1_out, u32 *base_page_out, u32 *mip_page_out, u32 *mip_min_level_out, u32 *mip_max_level_out)
u32 rex::xenos::GetPackedMipLevel (u32 width, u32 height)
bool rex::xenos::GetPackedMipOffset (u32 width, u32 height, u32 depth, xenos::TextureFormat format, u32 mip, u32 &x_blocks, u32 &y_blocks, u32 &z_blocks)
GuestTextureLayout rex::xenos::GetGuestTextureLayout (xenos::DataDimension dimension, u32 base_pitch_texels_div_32, u32 width_texels, u32 height_texels, u32 depth_or_array_size, bool is_tiled, xenos::TextureFormat format, bool has_packed_levels, bool has_base, u32 max_level)
i32 rex::xenos::GetTiledOffset2D (i32 x, i32 y, u32 pitch, u32 bytes_per_block_log2)
i32 rex::xenos::GetTiledOffset3D (i32 x, i32 y, i32 z, u32 pitch, u32 height, u32 bytes_per_block_log2)
u32 rex::xenos::GetTiledAddressLowerBound2D (u32 left, u32 top, u32 pitch, u32 bytes_per_block_log2)
u32 rex::xenos::GetTiledAddressLowerBound3D (u32 left, u32 top, u32 front, u32 pitch, u32 height, u32 bytes_per_block_log2)
u32 rex::xenos::GetTiledAddressUpperBound2D (u32 right, u32 bottom, u32 pitch, u32 bytes_per_block_log2)
u32 rex::xenos::GetTiledAddressUpperBound3D (u32 right, u32 bottom, u32 back, u32 pitch, u32 height, u32 bytes_per_block_log2)
u8 rex::xenos::SwizzleSigns (const xenos::TextureFetch &fetch)
constexpr bool rex::xenos::HasNonSignedComponent (u8 packed_signs)
constexpr bool rex::xenos::HasSignedComponent (u8 packed_signs)
void rex::xenos::GetClampModesForDimension (const xenos::TextureFetch &fetch, xenos::ClampMode &clamp_x_out, xenos::ClampMode &clamp_y_out, xenos::ClampMode &clamp_z_out)
xenos::TextureFormat rex::xenos::GetBaseFormat (xenos::TextureFormat texture_format)
size_t rex::xenos::GetTexelSize (xenos::TextureFormat format)
xenos::TextureFormat rex::xenos::ColorFormatToTextureFormat (xenos::ColorFormat color_format)
xenos::TextureFormat rex::xenos::DepthRenderTargetToTextureFormat (xenos::DepthRenderTargetFormat depth_format)
void rex::xenos::CopySwapBlock (xenos::Endian endian, void *output, const void *input, size_t length)
void rex::xenos::ConvertTexelCTX1ToR8G8 (xenos::Endian endian, void *output, const void *input, size_t output_pitch)
void rex::xenos::ConvertTexelDXT3AToDXT3 (xenos::Endian endian, void *output, const void *input, size_t length)
void rex::xenos::Untile (u8 *output_buffer, const u8 *input_buffer, const UntileRegion *untile_info)

Detailed Description

Xenos texture info, memory layout and format conversion.

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

Typedef Documentation

◆ CopyBlockCallback

using rex::xenos::CopyBlockCallback = std::function<void(xenos::Endian, void*, const void*, size_t)>

Copies a block, swapping bytes by the given endian mode.

Enumeration Type Documentation

◆ FormatType

enum class rex::xenos::FormatType : u8
strong
Enumerator
kResolvable 

Uncompressed and usable as a resolve target.

kUncompressed 

Uncompressed, not a resolve or memory export target.

Function Documentation

◆ ColorFormatToTextureFormat()

xenos::TextureFormat rex::xenos::ColorFormatToTextureFormat ( xenos::ColorFormat color_format)
inline

Returns the texture format with the same numeric value as a color format.

◆ ConvertTexelCTX1ToR8G8()

void rex::xenos::ConvertTexelCTX1ToR8G8 ( xenos::Endian endian,
void * output,
const void * input,
size_t output_pitch )

Decodes an 8 byte CTX1 block into 4x4 R8G8 texels.

Parameters
endianThe swap mode of the source block.
outputDestination for 4 rows of 4 R8G8 texels.
inputSource CTX1 block.
output_pitchDestination row pitch in bytes.

◆ ConvertTexelDXT3AToDXT3()

void rex::xenos::ConvertTexelDXT3AToDXT3 ( xenos::Endian endian,
void * output,
const void * input,
size_t length )

Expands a DXT3A block into a DXT3 block with the color half zeroed.

Parameters
endianThe swap mode of the source block.
outputDestination 16 byte DXT3 block.
inputSource 8 byte DXT3A block.
lengthUnused.

◆ CopySwapBlock()

void rex::xenos::CopySwapBlock ( xenos::Endian endian,
void * output,
const void * input,
size_t length )

Copies bytes, swapping them as endian specifies.

◆ DepthRenderTargetToTextureFormat()

xenos::TextureFormat rex::xenos::DepthRenderTargetToTextureFormat ( xenos::DepthRenderTargetFormat depth_format)
inline

Returns the texture format that matches a depth render target format, or TextureFormat(~0) for an unhandled format.

◆ GetBaseFormat()

xenos::TextureFormat rex::xenos::GetBaseFormat ( xenos::TextureFormat texture_format)
inline

Maps a resampling or gamma control variant to its base format.

Returns
The base format, or texture_format when it has no base variant.

◆ GetClampModesForDimension()

void rex::xenos::GetClampModesForDimension ( const xenos::TextureFetch & fetch,
xenos::ClampMode & clamp_x_out,
xenos::ClampMode & clamp_y_out,
xenos::ClampMode & clamp_z_out )

Reads the clamp modes a fetch constant uses for its dimension. Unused axes and cube textures get kClampToEdge.

Parameters
clamp_x_outReceives the X clamp mode.
clamp_y_outReceives the Y clamp mode.
clamp_z_outReceives the Z clamp mode.

◆ GetGuestTextureLayout()

GuestTextureLayout rex::xenos::GetGuestTextureLayout ( xenos::DataDimension dimension,
u32 base_pitch_texels_div_32,
u32 width_texels,
u32 height_texels,
u32 depth_or_array_size,
bool is_tiled,
xenos::TextureFormat format,
bool has_packed_levels,
bool has_base,
u32 max_level )

Calculates the guest memory layout of a texture, all zero when it has no texels.

Parameters
base_pitch_texels_div_32Base level row pitch in texels divided by 32.
depth_or_array_sizeDepth for 3D textures, array size otherwise.
is_tiledTrue for tiled data, false for linear.
has_packed_levelsTrue when small levels share a packed mip tail.
has_baseTrue when the base level is present.

◆ GetPackedMipLevel()

u32 rex::xenos::GetPackedMipLevel ( u32 width,
u32 height )
inline

Returns the first mip level stored in the packed mip tail.

◆ GetPackedMipOffset()

bool rex::xenos::GetPackedMipOffset ( u32 width,
u32 height,
u32 depth,
xenos::TextureFormat format,
u32 mip,
u32 & x_blocks,
u32 & y_blocks,
u32 & z_blocks )

Finds the offset of a mip level within the packed mip tail.

Parameters
depthDepth in texels, 1 for textures other than 3D.
x_blocksReceives the X offset in blocks.
y_blocksReceives the Y offset in blocks.
z_blocksReceives the Z offset in blocks.
Returns
False when the level is not packed, with all offsets set to 0.

◆ GetSubresourcesFromFetchConstant()

void rex::xenos::GetSubresourcesFromFetchConstant ( const xenos::TextureFetch & fetch,
u32 * width_minus_1_out,
u32 * height_minus_1_out,
u32 * depth_or_array_size_minus_1_out,
u32 * base_page_out,
u32 * mip_page_out,
u32 * mip_min_level_out,
u32 * mip_max_level_out )

Reads the size and present levels from a fetch constant. Every output pointer may be null.

Parameters
width_minus_1_outReceives the width in texels minus 1.
height_minus_1_outReceives the height in texels minus 1.
depth_or_array_size_minus_1_outReceives the depth or array size minus 1, 5 for cubes.
base_page_outReceives the base level page, 0 when the base level is absent.
mip_page_outReceives the mip page, 0 when no mips are present.
mip_min_level_outReceives the first present level.
mip_max_level_outReceives the last present level.

◆ GetTexelSize()

size_t rex::xenos::GetTexelSize ( xenos::TextureFormat format)
inline

Returns the size of one texel of an uncompressed format in bytes, or 0 for an unhandled format.

◆ GetTiledAddressLowerBound2D()

u32 rex::xenos::GetTiledAddressLowerBound2D ( u32 left,
u32 top,
u32 pitch,
u32 bytes_per_block_log2 )
inline

Returns the lowest address a 2D region can touch, the origin of its first 32x32 tile. The offset is in bytes.

Parameters
leftLeft edge in blocks.
topTop edge in blocks.
pitchRow pitch in blocks.
bytes_per_block_log2log2_floor of the bytes per block.

◆ GetTiledAddressLowerBound3D()

u32 rex::xenos::GetTiledAddressLowerBound3D ( u32 left,
u32 top,
u32 front,
u32 pitch,
u32 height,
u32 bytes_per_block_log2 )
inline

Returns the lowest address a 3D region can touch, the origin of its first 32x32x4 tile. The offset is in bytes.

Parameters
leftLeft edge in blocks.
topTop edge in blocks.
pitchRow pitch in blocks.
heightHeight in blocks.
bytes_per_block_log2log2_floor of the bytes per block.

◆ GetTiledAddressUpperBound2D()

u32 rex::xenos::GetTiledAddressUpperBound2D ( u32 right,
u32 bottom,
u32 pitch,
u32 bytes_per_block_log2 )

Returns the exclusive upper address bound of a 2D region, or 0 for an empty region. The region may extend past the pitch.

Parameters
rightExclusive right edge in blocks.
bottomExclusive bottom edge in blocks.
pitchRow pitch in blocks.
bytes_per_block_log2log2_floor of the bytes per block.

◆ GetTiledAddressUpperBound3D()

u32 rex::xenos::GetTiledAddressUpperBound3D ( u32 right,
u32 bottom,
u32 back,
u32 pitch,
u32 height,
u32 bytes_per_block_log2 )

Returns the exclusive upper address bound of a 3D region, or 0 for an empty region. The region may extend past the pitch and height.

Parameters
rightExclusive right edge in blocks.
bottomExclusive bottom edge in blocks.
backExclusive back layer.
pitchRow pitch in blocks.
heightHeight in blocks.
bytes_per_block_log2log2_floor of the bytes per block.

◆ GetTiledOffset2D()

i32 rex::xenos::GetTiledOffset2D ( i32 x,
i32 y,
u32 pitch,
u32 bytes_per_block_log2 )

Returns the offset of a block in a 2D tiled texture. Negative coordinates are valid.

Parameters
pitchRow pitch in blocks, aligned to 32 internally.
bytes_per_block_log2log2_floor of the bytes per block.

◆ GetTiledOffset3D()

i32 rex::xenos::GetTiledOffset3D ( i32 x,
i32 y,
i32 z,
u32 pitch,
u32 height,
u32 bytes_per_block_log2 )

Returns the offset of a block in a 3D tiled texture. Each 32 block row by 4 layer portion occupies its own 4 KB aligned range.

Parameters
pitchRow pitch in blocks, aligned to 32 internally.
heightHeight in blocks, aligned to 32 internally.
bytes_per_block_log2log2_floor of the bytes per block.

◆ HasNonSignedComponent()

bool rex::xenos::HasNonSignedComponent ( u8 packed_signs)
constexpr

Reports whether any component is not kSigned.

Parameters
packed_signsPacked signs from SwizzleSigns.

◆ HasSignedComponent()

bool rex::xenos::HasSignedComponent ( u8 packed_signs)
constexpr

Reports whether any component is kSigned.

Parameters
packed_signsPacked signs from SwizzleSigns.

◆ SwizzleSigns()

u8 rex::xenos::SwizzleSigns ( const xenos::TextureFetch & fetch)

Packs the TextureSign of each component after the swizzle. Constant 0 and 1 count as unsigned unless every other component is signed.

Returns
Four TextureSign values, 2 bits each.

◆ Untile()

void rex::xenos::Untile ( u8 * output_buffer,
const u8 * input_buffer,
const UntileRegion * untile_info )

Converts a region of a 2D tiled texture to linear layout.

Parameters
output_bufferLinear destination.
input_bufferTiled source.
untile_infoThe region, pitches, formats and block copy callback.