2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-04 13:53:03 +00:00
|
|
|
#include <tuple>
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2021-02-11 02:11:31 +00:00
|
|
|
#include "Common/EnumFormatter.h"
|
2014-02-10 18:54:46 +00:00
|
|
|
|
2009-05-09 07:55:30 +00:00
|
|
|
enum
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2015-02-15 19:43:31 +00:00
|
|
|
TMEM_SIZE = 1024 * 1024,
|
2012-01-29 20:17:22 +00:00
|
|
|
TMEM_LINE_SIZE = 32,
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
2015-09-05 15:44:21 +00:00
|
|
|
alignas(16) extern u8 texMem[TMEM_SIZE];
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-07-30 19:45:55 +00:00
|
|
|
enum class TextureFormat
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2017-07-30 19:45:55 +00:00
|
|
|
// These values represent texture format in GX registers.
|
|
|
|
I4 = 0x0,
|
|
|
|
I8 = 0x1,
|
|
|
|
IA4 = 0x2,
|
|
|
|
IA8 = 0x3,
|
|
|
|
RGB565 = 0x4,
|
|
|
|
RGB5A3 = 0x5,
|
|
|
|
RGBA8 = 0x6,
|
|
|
|
C4 = 0x8,
|
|
|
|
C8 = 0x9,
|
|
|
|
C14X2 = 0xA,
|
|
|
|
CMPR = 0xE,
|
2017-05-29 22:02:09 +00:00
|
|
|
|
|
|
|
// Special texture format used to represent YUVY xfb copies.
|
|
|
|
// They aren't really textures, but they share so much hardware and usecases that it makes sense
|
|
|
|
// to emulate them as part of texture cache.
|
2021-02-11 02:11:31 +00:00
|
|
|
// This isn't a real value that can be used on console; it only exists for ease of implementation.
|
2017-05-29 22:02:09 +00:00
|
|
|
XFB = 0xF,
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
2021-02-11 02:11:31 +00:00
|
|
|
template <>
|
|
|
|
struct fmt::formatter<TextureFormat> : EnumFormatter<TextureFormat::CMPR>
|
|
|
|
{
|
|
|
|
static constexpr array_type names = {"I4", "I8", "IA4", "IA8", "RGB565",
|
|
|
|
"RGB5A3", "RGBA8", nullptr, "C4", "C8",
|
|
|
|
"C14X2", nullptr, nullptr, nullptr, "CMPR"};
|
2022-01-13 01:28:17 +00:00
|
|
|
constexpr formatter() : EnumFormatter(names) {}
|
2021-02-11 02:11:31 +00:00
|
|
|
};
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-07-30 19:45:55 +00:00
|
|
|
static inline bool IsColorIndexed(TextureFormat format)
|
2014-08-10 19:04:29 +00:00
|
|
|
{
|
2017-07-30 19:45:55 +00:00
|
|
|
return format == TextureFormat::C4 || format == TextureFormat::C8 ||
|
|
|
|
format == TextureFormat::C14X2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The EFB Copy pipeline looks like:
|
|
|
|
//
|
|
|
|
// 1. Read EFB -> 2. Select color/depth -> 3. Downscale (optional)
|
|
|
|
// -> 4. YUV conversion (optional) -> 5. Encode Tiles -> 6. Write RAM
|
|
|
|
//
|
|
|
|
// The "Encode Tiles" stage receives RGBA8 texels from previous stages and encodes them to various
|
|
|
|
// formats. EFBCopyFormat is the tile encoder mode. Note that the tile encoder does not care about
|
|
|
|
// color vs. depth or intensity formats - it only sees RGBA8 texels.
|
|
|
|
enum class EFBCopyFormat
|
|
|
|
{
|
|
|
|
// These values represent EFB copy format in GX registers.
|
|
|
|
// Most (but not all) of these values correspond to values of TextureFormat.
|
|
|
|
R4 = 0x0, // R4, I4, Z4
|
|
|
|
|
|
|
|
// FIXME: Does 0x1 (Z8) have identical results to 0x8 (Z8H)?
|
|
|
|
// Is either or both of 0x1 and 0x8 used in games?
|
|
|
|
R8_0x1 = 0x1, // R8, I8, Z8H (?)
|
|
|
|
|
|
|
|
RA4 = 0x2, // RA4, IA4
|
|
|
|
|
|
|
|
// FIXME: Earlier versions of this file named the value 0x3 "GX_TF_Z16", which does not reflect
|
|
|
|
// the results one would expect when copying from the depth buffer with this format.
|
|
|
|
// For reference: When copying from the depth buffer, R should receive the top 8 bits of
|
|
|
|
// the Z value, and A should be either 0xFF or 0 (please investigate).
|
|
|
|
// Please test original hardware and make sure dolphin-emu implements this format
|
|
|
|
// correctly.
|
|
|
|
RA8 = 0x3, // RA8, IA8, (FIXME: Z16 too?)
|
|
|
|
|
|
|
|
RGB565 = 0x4,
|
|
|
|
RGB5A3 = 0x5,
|
|
|
|
RGBA8 = 0x6, // RGBA8, Z24
|
|
|
|
A8 = 0x7,
|
|
|
|
R8 = 0x8, // R8, I8, Z8H
|
|
|
|
G8 = 0x9, // G8, Z8M
|
|
|
|
B8 = 0xA, // B8, Z8L
|
|
|
|
RG8 = 0xB, // RG8, Z16R (Note: G and R are reversed)
|
|
|
|
GB8 = 0xC, // GB8, Z16L
|
2017-05-29 22:02:09 +00:00
|
|
|
|
|
|
|
// Special texture format used to represent YUVY xfb copies.
|
|
|
|
// They aren't really textures, but they share so much hardware and usecases that it makes sense
|
|
|
|
// to emulate them as part of texture cache.
|
2021-02-11 02:11:31 +00:00
|
|
|
// This isn't a real value that can be used on console; it only exists for ease of implementation.
|
2017-05-29 22:02:09 +00:00
|
|
|
XFB = 0xF,
|
2014-08-10 19:04:29 +00:00
|
|
|
};
|
2021-02-11 02:11:31 +00:00
|
|
|
template <>
|
|
|
|
struct fmt::formatter<EFBCopyFormat> : EnumFormatter<EFBCopyFormat::GB8>
|
|
|
|
{
|
|
|
|
static constexpr array_type names = {
|
|
|
|
"R4/I4/Z4", "R8/I8/Z8H (?)", "RA4/IA4", "RA8/IA8 (Z16 too?)",
|
|
|
|
"RGB565", "RGB5A3", "RGBA8", "A8",
|
|
|
|
"R8/I8/Z8H", "G8/Z8M", "B8/Z8L", "RG8/Z16R (Note: G and R are reversed)",
|
|
|
|
"GB8/Z16L",
|
|
|
|
};
|
2022-01-13 01:28:17 +00:00
|
|
|
constexpr formatter() : EnumFormatter(names) {}
|
2021-02-11 02:11:31 +00:00
|
|
|
};
|
2014-08-10 19:04:29 +00:00
|
|
|
|
2017-07-30 19:45:55 +00:00
|
|
|
enum class TLUTFormat
|
2017-04-04 13:53:03 +00:00
|
|
|
{
|
2017-07-30 19:45:55 +00:00
|
|
|
// These values represent TLUT format in GX registers.
|
|
|
|
IA8 = 0x0,
|
|
|
|
RGB565 = 0x1,
|
|
|
|
RGB5A3 = 0x2,
|
2017-04-04 13:53:03 +00:00
|
|
|
};
|
2021-02-11 02:11:31 +00:00
|
|
|
template <>
|
|
|
|
struct fmt::formatter<TLUTFormat> : EnumFormatter<TLUTFormat::RGB5A3>
|
|
|
|
{
|
2022-01-13 01:28:17 +00:00
|
|
|
constexpr formatter() : EnumFormatter({"IA8", "RGB565", "RGB5A3"}) {}
|
2021-02-11 02:11:31 +00:00
|
|
|
};
|
2017-04-04 13:53:03 +00:00
|
|
|
|
2017-07-30 19:45:55 +00:00
|
|
|
static inline bool IsValidTLUTFormat(TLUTFormat tlutfmt)
|
|
|
|
{
|
|
|
|
return tlutfmt == TLUTFormat::IA8 || tlutfmt == TLUTFormat::RGB565 ||
|
|
|
|
tlutfmt == TLUTFormat::RGB5A3;
|
|
|
|
}
|
|
|
|
|
2019-07-14 05:24:12 +00:00
|
|
|
static inline bool IsCompatibleTextureFormat(TextureFormat from_format, TextureFormat to_format)
|
|
|
|
{
|
|
|
|
if (from_format == to_format)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Indexed and paletted formats are "compatible", that is do not require conversion.
|
|
|
|
switch (from_format)
|
|
|
|
{
|
|
|
|
case TextureFormat::I4:
|
|
|
|
case TextureFormat::C4:
|
|
|
|
return to_format == TextureFormat::I4 || to_format == TextureFormat::C4;
|
|
|
|
|
|
|
|
case TextureFormat::I8:
|
|
|
|
case TextureFormat::C8:
|
|
|
|
return to_format == TextureFormat::I8 || to_format == TextureFormat::C8;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool CanReinterpretTextureOnGPU(TextureFormat from_format, TextureFormat to_format)
|
|
|
|
{
|
|
|
|
// Currently, we can only reinterpret textures of the same width.
|
|
|
|
switch (from_format)
|
|
|
|
{
|
|
|
|
case TextureFormat::I8:
|
|
|
|
case TextureFormat::IA4:
|
|
|
|
return to_format == TextureFormat::I8 || to_format == TextureFormat::IA4;
|
|
|
|
|
|
|
|
case TextureFormat::IA8:
|
|
|
|
case TextureFormat::RGB565:
|
|
|
|
case TextureFormat::RGB5A3:
|
|
|
|
return to_format == TextureFormat::IA8 || to_format == TextureFormat::RGB565 ||
|
|
|
|
to_format == TextureFormat::RGB5A3;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-30 19:45:55 +00:00
|
|
|
int TexDecoder_GetTexelSizeInNibbles(TextureFormat format);
|
|
|
|
int TexDecoder_GetTextureSizeInBytes(int width, int height, TextureFormat format);
|
|
|
|
int TexDecoder_GetBlockWidthInTexels(TextureFormat format);
|
|
|
|
int TexDecoder_GetBlockHeightInTexels(TextureFormat format);
|
|
|
|
int TexDecoder_GetEFBCopyBlockWidthInTexels(EFBCopyFormat format);
|
|
|
|
int TexDecoder_GetEFBCopyBlockHeightInTexels(EFBCopyFormat format);
|
|
|
|
int TexDecoder_GetPaletteSize(TextureFormat fmt);
|
|
|
|
TextureFormat TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat format);
|
|
|
|
|
|
|
|
void TexDecoder_Decode(u8* dst, const u8* src, int width, int height, TextureFormat texformat,
|
|
|
|
const u8* tlut, TLUTFormat tlutfmt);
|
2015-01-17 08:46:31 +00:00
|
|
|
void TexDecoder_DecodeRGBA8FromTmem(u8* dst, const u8* src_ar, const u8* src_gb, int width,
|
|
|
|
int height);
|
2017-07-30 19:45:55 +00:00
|
|
|
void TexDecoder_DecodeTexel(u8* dst, const u8* src, int s, int t, int imageWidth,
|
|
|
|
TextureFormat texformat, const u8* tlut, TLUTFormat tlutfmt);
|
2013-01-09 09:19:18 +00:00
|
|
|
void TexDecoder_DecodeTexelRGBA8FromTmem(u8* dst, const u8* src_ar, const u8* src_gb, int s, int t,
|
|
|
|
int imageWidth);
|
2019-03-24 03:10:01 +00:00
|
|
|
void TexDecoder_DecodeXFB(u8* dst, const u8* src, u32 width, u32 height, u32 stride);
|
2014-07-12 14:49:24 +00:00
|
|
|
|
2008-08-06 01:08:02 +00:00
|
|
|
void TexDecoder_SetTexFmtOverlayOptions(bool enable, bool center);
|
2014-07-12 14:49:24 +00:00
|
|
|
|
|
|
|
/* Internal method, implemented by TextureDecoder_Generic and TextureDecoder_x64. */
|
2017-07-30 19:45:55 +00:00
|
|
|
void _TexDecoder_DecodeImpl(u32* dst, const u8* src, int width, int height, TextureFormat texformat,
|
|
|
|
const u8* tlut, TLUTFormat tlutfmt);
|