| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2008 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 23:53:03 +10:00
										 |  |  | #include <tuple>
 | 
					
						
							| 
									
										
										
										
											2016-01-17 16:54:31 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 01:23:17 -04:00
										 |  |  | enum | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   TMEM_SIZE = 1024 * 1024, | 
					
						
							|  |  |  |   TMEM_LINE_SIZE = 32, | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-09-05 11:44:21 -04:00
										 |  |  | alignas(16) extern u8 texMem[TMEM_SIZE]; | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  | enum class TextureFormat | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07: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 17:02:09 -05: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.
 | 
					
						
							|  |  |  |   XFB = 0xF, | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  | static inline bool IsColorIndexed(TextureFormat format) | 
					
						
							| 
									
										
										
										
											2014-08-10 15:04:29 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07: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 17:02:09 -05: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.
 | 
					
						
							|  |  |  |   XFB = 0xF, | 
					
						
							| 
									
										
										
										
											2014-08-10 15:04:29 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  | enum class TLUTFormat | 
					
						
							| 
									
										
										
										
											2017-04-04 23:53:03 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  |   // These values represent TLUT format in GX registers.
 | 
					
						
							|  |  |  |   IA8 = 0x0, | 
					
						
							|  |  |  |   RGB565 = 0x1, | 
					
						
							|  |  |  |   RGB5A3 = 0x2, | 
					
						
							| 
									
										
										
										
											2017-04-04 23:53:03 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  | static inline bool IsValidTLUTFormat(TLUTFormat tlutfmt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return tlutfmt == TLUTFormat::IA8 || tlutfmt == TLUTFormat::RGB565 || | 
					
						
							|  |  |  |          tlutfmt == TLUTFormat::RGB5A3; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | void TexDecoder_DecodeRGBA8FromTmem(u8* dst, const u8* src_ar, const u8* src_gb, int width, | 
					
						
							|  |  |  |                                     int height); | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  | void TexDecoder_DecodeTexel(u8* dst, const u8* src, int s, int t, int imageWidth, | 
					
						
							|  |  |  |                             TextureFormat texformat, const u8* tlut, TLUTFormat tlutfmt); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | void TexDecoder_DecodeTexelRGBA8FromTmem(u8* dst, const u8* src_ar, const u8* src_gb, int s, int t, | 
					
						
							|  |  |  |                                          int imageWidth); | 
					
						
							| 
									
										
										
										
											2014-07-12 10:49:24 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-08 04:46:09 +00:00
										 |  |  | void TexDecoder_SetTexFmtOverlayOptions(bool enable, bool center); | 
					
						
							| 
									
										
										
										
											2014-07-12 10:49:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Internal method, implemented by TextureDecoder_Generic and TextureDecoder_x64. */ | 
					
						
							| 
									
										
										
										
											2017-07-30 12:45:55 -07:00
										 |  |  | void _TexDecoder_DecodeImpl(u32* dst, const u8* src, int width, int height, TextureFormat texformat, | 
					
						
							|  |  |  |                             const u8* tlut, TLUTFormat tlutfmt); |