|
|
|
@ -19,77 +19,86 @@ namespace gpu {
|
|
|
|
|
using namespace xe::gpu::ucode;
|
|
|
|
|
using namespace xe::gpu::xenos;
|
|
|
|
|
|
|
|
|
|
static const FormatInfo format_infos[64] = {
|
|
|
|
|
{TextureFormat::k_1_REVERSE, FormatType::kUncompressed, 1, 1, 1},
|
|
|
|
|
{TextureFormat::k_1, FormatType::kUncompressed, 1, 1, 1},
|
|
|
|
|
{TextureFormat::k_8, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_1_5_5_5, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_5_6_5, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_6_5_5, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_8_8_8_8, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_2_10_10_10, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_8_A, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_8_B, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_8_8, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_Cr_Y1_Cb_Y0, FormatType::kCompressed, 2, 1, 16},
|
|
|
|
|
{TextureFormat::k_Y1_Cr_Y0_Cb, FormatType::kCompressed, 2, 1, 16},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
{TextureFormat::k_8_8_8_8_A, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_4_4_4_4, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_10_11_11, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_11_11_10, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_DXT1, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT2_3, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::k_DXT4_5, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
{TextureFormat::k_24_8, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_24_8_FLOAT, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16_16_16_16, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_16_EXPAND, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_EXPAND, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16_16_16_16_EXPAND, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_16_FLOAT, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_FLOAT, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16_16_16_16_FLOAT, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_32, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_32_32, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_32_32_32_32, FormatType::kUncompressed, 1, 1, 128},
|
|
|
|
|
{TextureFormat::k_32_FLOAT, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_32_32_FLOAT, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_32_32_32_32_FLOAT, FormatType::kUncompressed, 1, 1, 128},
|
|
|
|
|
{TextureFormat::k_32_AS_8, FormatType::kCompressed, 4, 1, 8},
|
|
|
|
|
{TextureFormat::k_32_AS_8_8, FormatType::kCompressed, 2, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_MPEG, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_MPEG, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_8_INTERLACED, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_32_AS_8_INTERLACED, FormatType::kCompressed, 4, 1, 8},
|
|
|
|
|
{TextureFormat::k_32_AS_8_8_INTERLACED, FormatType::kCompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_INTERLACED, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_MPEG_INTERLACED, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_MPEG_INTERLACED, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
32},
|
|
|
|
|
{TextureFormat::k_DXN, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::k_8_8_8_8_AS_16_16_16_16, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
32},
|
|
|
|
|
{TextureFormat::k_DXT1_AS_16_16_16_16, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT2_3_AS_16_16_16_16, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::k_DXT4_5_AS_16_16_16_16, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::k_2_10_10_10_AS_16_16_16_16, FormatType::kUncompressed, 1,
|
|
|
|
|
1, 32},
|
|
|
|
|
{TextureFormat::k_10_11_11_AS_16_16_16_16, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
32},
|
|
|
|
|
{TextureFormat::k_11_11_10_AS_16_16_16_16, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
32},
|
|
|
|
|
{TextureFormat::k_32_32_32_FLOAT, FormatType::kUncompressed, 1, 1, 96},
|
|
|
|
|
{TextureFormat::k_DXT3A, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT5A, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_CTX1, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT3A_AS_1_1_1_1, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
};
|
|
|
|
|
const FormatInfo* FormatInfo::Get(uint32_t gpu_format) {
|
|
|
|
|
static const FormatInfo format_infos[64] = {
|
|
|
|
|
{TextureFormat::k_1_REVERSE, FormatType::kUncompressed, 1, 1, 1},
|
|
|
|
|
{TextureFormat::k_1, FormatType::kUncompressed, 1, 1, 1},
|
|
|
|
|
{TextureFormat::k_8, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_1_5_5_5, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_5_6_5, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_6_5_5, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_8_8_8_8, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_2_10_10_10, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_8_A, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_8_B, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_8_8, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_Cr_Y1_Cb_Y0, FormatType::kCompressed, 2, 1, 16},
|
|
|
|
|
{TextureFormat::k_Y1_Cr_Y0_Cb, FormatType::kCompressed, 2, 1, 16},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
{TextureFormat::k_8_8_8_8_A, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_4_4_4_4, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_10_11_11, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_11_11_10, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_DXT1, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT2_3, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::k_DXT4_5, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
{TextureFormat::k_24_8, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_24_8_FLOAT, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16_16_16_16, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_16_EXPAND, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_EXPAND, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16_16_16_16_EXPAND, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
64},
|
|
|
|
|
{TextureFormat::k_16_FLOAT, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_FLOAT, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_16_16_16_16_FLOAT, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_32, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_32_32, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_32_32_32_32, FormatType::kUncompressed, 1, 1, 128},
|
|
|
|
|
{TextureFormat::k_32_FLOAT, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_32_32_FLOAT, FormatType::kUncompressed, 1, 1, 64},
|
|
|
|
|
{TextureFormat::k_32_32_32_32_FLOAT, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
128},
|
|
|
|
|
{TextureFormat::k_32_AS_8, FormatType::kCompressed, 4, 1, 8},
|
|
|
|
|
{TextureFormat::k_32_AS_8_8, FormatType::kCompressed, 2, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_MPEG, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_16_MPEG, FormatType::kUncompressed, 1, 1, 32},
|
|
|
|
|
{TextureFormat::k_8_INTERLACED, FormatType::kUncompressed, 1, 1, 8},
|
|
|
|
|
{TextureFormat::k_32_AS_8_INTERLACED, FormatType::kCompressed, 4, 1, 8},
|
|
|
|
|
{TextureFormat::k_32_AS_8_8_INTERLACED, FormatType::kCompressed, 1, 1,
|
|
|
|
|
16},
|
|
|
|
|
{TextureFormat::k_16_INTERLACED, FormatType::kUncompressed, 1, 1, 16},
|
|
|
|
|
{TextureFormat::k_16_MPEG_INTERLACED, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
16},
|
|
|
|
|
{TextureFormat::k_16_16_MPEG_INTERLACED, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
32},
|
|
|
|
|
{TextureFormat::k_DXN, FormatType::kCompressed, 4, 4, 8},
|
|
|
|
|
{TextureFormat::k_8_8_8_8_AS_16_16_16_16, FormatType::kUncompressed, 1, 1,
|
|
|
|
|
32},
|
|
|
|
|
{TextureFormat::k_DXT1_AS_16_16_16_16, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT2_3_AS_16_16_16_16, FormatType::kCompressed, 4, 4,
|
|
|
|
|
8},
|
|
|
|
|
{TextureFormat::k_DXT4_5_AS_16_16_16_16, FormatType::kCompressed, 4, 4,
|
|
|
|
|
8},
|
|
|
|
|
{TextureFormat::k_2_10_10_10_AS_16_16_16_16, FormatType::kUncompressed, 1,
|
|
|
|
|
1, 32},
|
|
|
|
|
{TextureFormat::k_10_11_11_AS_16_16_16_16, FormatType::kUncompressed, 1,
|
|
|
|
|
1, 32},
|
|
|
|
|
{TextureFormat::k_11_11_10_AS_16_16_16_16, FormatType::kUncompressed, 1,
|
|
|
|
|
1, 32},
|
|
|
|
|
{TextureFormat::k_32_32_32_FLOAT, FormatType::kUncompressed, 1, 1, 96},
|
|
|
|
|
{TextureFormat::k_DXT3A, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT5A, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_CTX1, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::k_DXT3A_AS_1_1_1_1, FormatType::kCompressed, 4, 4, 4},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
{TextureFormat::kUnknown, FormatType::kUncompressed, 0, 0},
|
|
|
|
|
};
|
|
|
|
|
return &format_infos[gpu_format];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TextureInfo::Prepare(const xe_gpu_texture_fetch_t& fetch,
|
|
|
|
|
TextureInfo* out_info) {
|
|
|
|
@ -118,7 +127,7 @@ bool TextureInfo::Prepare(const xe_gpu_texture_fetch_t& fetch,
|
|
|
|
|
info.depth = fetch.size_3d.depth;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
info.format_info = &format_infos[fetch.format];
|
|
|
|
|
info.format_info = FormatInfo::Get(fetch.format);
|
|
|
|
|
info.endianness = static_cast<Endian>(fetch.endianness);
|
|
|
|
|
info.is_tiled = fetch.tiled;
|
|
|
|
|
info.input_length = 0; // Populated below.
|
|
|
|
@ -199,6 +208,62 @@ void TextureInfo::CalculateTextureSizes2D(const xe_gpu_texture_fetch_t& fetch) {
|
|
|
|
|
output_length = size_2d.output_pitch * block_height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextureInfo::GetPackedTileOffset(const TextureInfo& texture_info,
|
|
|
|
|
uint32_t* out_offset_x,
|
|
|
|
|
uint32_t* out_offset_y) {
|
|
|
|
|
// Tile size is 32x32, and once textures go <=16 they are packed into a
|
|
|
|
|
// single tile together. The math here is insane. Most sourced
|
|
|
|
|
// from graph paper and looking at dds dumps.
|
|
|
|
|
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
// 0 +.4x4.+ +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 1 +.4x4.+ +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 2 +.4x4.+ +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 3 +.4x4.+ +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 4 x +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 5 +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 6 +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 7 +.....8x8.....+ +............16x16............+
|
|
|
|
|
// 8 2x2 +............16x16............+
|
|
|
|
|
// 9 2x2 +............16x16............+
|
|
|
|
|
// 0 +............16x16............+
|
|
|
|
|
// ... .....
|
|
|
|
|
// This only works for square textures, or textures that are some non-pot
|
|
|
|
|
// <= square. As soon as the aspect ratio goes weird, the textures start to
|
|
|
|
|
// stretch across tiles.
|
|
|
|
|
// if (tile_aligned(w) > tile_aligned(h)) {
|
|
|
|
|
// // wider than tall, so packed horizontally
|
|
|
|
|
// } else if (tile_aligned(w) < tile_aligned(h)) {
|
|
|
|
|
// // taller than wide, so packed vertically
|
|
|
|
|
// } else {
|
|
|
|
|
// square
|
|
|
|
|
// }
|
|
|
|
|
// It's important to use logical sizes here, as the input sizes will be
|
|
|
|
|
// for the entire packed tile set, not the actual texture.
|
|
|
|
|
// The minimum dimension is what matters most: if either width or height
|
|
|
|
|
// is <= 16 this mode kicks in.
|
|
|
|
|
|
|
|
|
|
if (std::min(texture_info.size_2d.logical_width,
|
|
|
|
|
texture_info.size_2d.logical_height) > 16) {
|
|
|
|
|
// Too big, not packed.
|
|
|
|
|
*out_offset_x = 0;
|
|
|
|
|
*out_offset_y = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (poly::log2_ceil(texture_info.size_2d.logical_width) >
|
|
|
|
|
poly::log2_ceil(texture_info.size_2d.logical_height)) {
|
|
|
|
|
// Wider than tall. Laid out vertically.
|
|
|
|
|
*out_offset_x = 0;
|
|
|
|
|
*out_offset_y = 16;
|
|
|
|
|
} else {
|
|
|
|
|
// Taller than wide. Laid out horizontally.
|
|
|
|
|
*out_offset_x = 16;
|
|
|
|
|
*out_offset_y = 0;
|
|
|
|
|
}
|
|
|
|
|
*out_offset_x /= texture_info.format_info->block_width;
|
|
|
|
|
*out_offset_y /= texture_info.format_info->block_height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://code.google.com/p/crunch/source/browse/trunk/inc/crn_decomp.h#4104
|
|
|
|
|
uint32_t TextureInfo::TiledOffset2DOuter(uint32_t y, uint32_t width,
|
|
|
|
|
uint32_t log_bpp) {
|
|
|
|
|