46enum class IndexFormat : u32 {
69 k_16_16_16_16_FLOAT = 7,
88 format == ColorRenderTargetFormat::k_16_16_16_16_FLOAT ||
89 format == ColorRenderTargetFormat::k_32_32_FLOAT;
102 case ColorRenderTargetFormat::k_16_16_16_16_FLOAT:
107 case ColorRenderTargetFormat::k_16_16_FLOAT:
108 case ColorRenderTargetFormat::k_32_32_FLOAT:
110 case ColorRenderTargetFormat::k_32_FLOAT:
186 return static_cast<f32
>(n24 + (n24 >> 23)) * (1.0f /
static_cast<f32
>(1 << 24));
189constexpr u32 kColorRenderTargetFormatBits = 4;
190constexpr u32 kDepthRenderTargetFormatBits = 1;
193 std::max(kColorRenderTargetFormatBits, kDepthRenderTargetFormatBits);
195constexpr u32 kFormatBits = 6;
220 k_16_16_16_16_EDRAM = 21,
228 k_16_16_16_16_EXPAND = 29,
231 k_16_16_16_16_FLOAT = 32,
237 k_32_32_32_32_FLOAT = 38,
243 k_32_AS_8_INTERLACED = 44,
244 k_32_AS_8_8_INTERLACED = 45,
245 k_16_INTERLACED = 46,
246 k_16_MPEG_INTERLACED = 47,
247 k_16_16_MPEG_INTERLACED = 48,
249 k_8_8_8_8_AS_16_16_16_16 = 50,
250 k_DXT1_AS_16_16_16_16 = 51,
251 k_DXT2_3_AS_16_16_16_16 = 52,
252 k_DXT4_5_AS_16_16_16_16 = 53,
253 k_2_10_10_10_AS_16_16_16_16 = 54,
254 k_10_11_11_AS_16_16_16_16 = 55,
255 k_11_11_10_AS_16_16_16_16 = 56,
256 k_32_32_32_FLOAT = 57,
260 k_DXT3A_AS_1_1_1_1 = 61,
261 k_8_8_8_8_GAMMA_EDRAM = 62,
286 k_16_16_16_16_FLOAT = 32,
289 k_32_32_32_32_FLOAT = 38,
290 k_8_8_8_8_AS_16_16_16_16 = 50,
291 k_2_10_10_10_AS_16_16_16_16 = 54,
292 k_10_11_11_AS_16_16_16_16 = 55,
293 k_11_11_10_AS_16_16_16_16 = 56,
306 switch (render_target_format) {
309 return color_format == ColorFormat::k_8_8_8_8 || color_format == ColorFormat::k_8_8_8_8_A ||
310 color_format == ColorFormat::k_8_8_8_8_AS_16_16_16_16;
313 return color_format == ColorFormat::k_2_10_10_10 ||
314 color_format == ColorFormat::k_2_10_10_10_AS_16_16_16_16;
315 case ColorRenderTargetFormat::k_16_16_FLOAT:
316 return color_format == ColorFormat::k_16_16_FLOAT;
317 case ColorRenderTargetFormat::k_16_16_16_16_FLOAT:
318 return color_format == ColorFormat::k_16_16_16_16_FLOAT;
319 case ColorRenderTargetFormat::k_32_FLOAT:
320 return color_format == ColorFormat::k_32_FLOAT;
321 case ColorRenderTargetFormat::k_32_32_FLOAT:
322 return color_format == ColorFormat::k_32_32_FLOAT;
329enum class VertexFormat : u32 {
338 k_16_16_16_16_FLOAT = 32,
344 k_32_32_32_32_FLOAT = 38,
345 k_32_32_32_FLOAT = 57,
353 case VertexFormat::k_32:
354 case VertexFormat::k_32_FLOAT:
356 case VertexFormat::k_16_16:
357 case VertexFormat::k_16_16_FLOAT:
358 case VertexFormat::k_32_32:
359 case VertexFormat::k_32_32_FLOAT:
361 case VertexFormat::k_10_11_11:
362 case VertexFormat::k_11_11_10:
363 case VertexFormat::k_32_32_32_FLOAT:
365 case VertexFormat::k_8_8_8_8:
366 case VertexFormat::k_2_10_10_10:
367 case VertexFormat::k_16_16_16_16:
368 case VertexFormat::k_16_16_16_16_FLOAT:
369 case VertexFormat::k_32_32_32_32:
370 case VertexFormat::k_32_32_32_32_FLOAT:
384 REX_ASSERT((used_components & ~
static_cast<u32
>(0b1111)) == 0);
385 if (!used_components) {
389 case VertexFormat::k_8_8_8_8:
390 case VertexFormat::k_2_10_10_10:
392 case VertexFormat::k_10_11_11:
393 case VertexFormat::k_11_11_10:
394 return (used_components & 0b0111) ? 0b0001 : 0b0000;
395 case VertexFormat::k_16_16:
396 case VertexFormat::k_16_16_FLOAT:
397 return (used_components & 0b0011) ? 0b0001 : 0b0000;
398 case VertexFormat::k_16_16_16_16:
399 case VertexFormat::k_16_16_16_16_FLOAT:
400 return ((used_components & 0b0011) ? 0b0001 : 0b0000) |
401 ((used_components & 0b1100) ? 0b0010 : 0b0000);
402 case VertexFormat::k_32:
403 case VertexFormat::k_32_FLOAT:
404 return used_components & 0b0001;
405 case VertexFormat::k_32_32:
406 case VertexFormat::k_32_32_FLOAT:
407 return used_components & 0b0011;
408 case VertexFormat::k_32_32_32_32:
409 case VertexFormat::k_32_32_32_32_FLOAT:
410 return used_components;
411 case VertexFormat::k_32_32_32_FLOAT:
412 return used_components & 0b0111;
425 switch (endianness) {
429 return ((value << 8) & 0xFF00FF00) | ((value >> 8) & 0x00FF00FF);
436inline u32 GPUSwap(u32 value, Endian endianness) {
437 switch (endianness) {
442 return ((value << 8) & 0xFF00FF00) | ((value >> 8) & 0x00FF00FF);
444 return std::byteswap(value);
445 case Endian::k16in32:
446 return ((value >> 16) & 0xFFFF) | (value << 16);
457 v.i =
GPUSwap(v.i, endianness);
478 return p & 0x1FFFFFFF;
491 bool round_to_nearest_even =
false) {
492 u32 integer_value = std::bit_cast<u32>(value);
493 u32 abs_value = integer_value & 0x7FFFFFFFu;
495 if (abs_value >= 0x47FFE000u) {
498 if (abs_value < 0x38800000u) {
499 if (preserve_denormal) {
500 u32 shift = std::min(
static_cast<u32
>(113u - (abs_value >> 23u)),
static_cast<u32
>(24u));
501 result = (0x800000u | (abs_value & 0x7FFFFFu)) >> shift;
506 result = abs_value + 0xC8000000u;
508 if (round_to_nearest_even) {
509 result += 0xFFFu + ((result >> 13u) & 1u);
511 result = (result >> 13u) & 0x7FFFu;
513 return static_cast<u16
>(result | ((integer_value & 0x80000000u) >> 16u));
522inline f32
HalfToFloat(u16 value,
bool preserve_denormal =
false) {
523 u32 mantissa = value & 0x3FFu;
524 u32 exponent = (value >> 10u) & 0x1Fu;
526 if (!preserve_denormal) {
528 }
else if (mantissa) {
529 u32 mantissa_lzcnt =
static_cast<u32
>(std::countl_zero(mantissa)) - (32u - 11u);
530 exponent =
static_cast<u32
>(1 -
static_cast<i32
>(mantissa_lzcnt));
531 mantissa = (mantissa << mantissa_lzcnt) & 0x3FFu;
534 exponent =
static_cast<u32
>(-112);
538 (
static_cast<u32
>(value & 0x8000u) << 16u) | ((exponent + 112u) << 23u) | (mantissa << 13u);
539 return std::bit_cast<f32>(result);
#define REX_UNHANDLED_CASE(var)
Definition assert.h:119
#define REX_ASSERT(cond,...)
Definition assert.h:84
Integer types, byte order wrappers and size literals.