summaryrefslogtreecommitdiff
path: root/src/video_core/textures
diff options
context:
space:
mode:
authorGravatar bunnei2020-07-21 00:13:04 -0400
committerGravatar GitHub2020-07-21 00:13:04 -0400
commit3d13d7f48f3bf7c1fb7b7673e963aa3e54db2838 (patch)
tree3214c882ce18526a3e57223ae96f06e7083369f2 /src/video_core/textures
parentMerge pull request #4168 from ReinUsesLisp/global-memory (diff)
parentvideo_core: Rearrange pixel format names (diff)
downloadyuzu-3d13d7f48f3bf7c1fb7b7673e963aa3e54db2838.tar.gz
yuzu-3d13d7f48f3bf7c1fb7b7673e963aa3e54db2838.tar.xz
yuzu-3d13d7f48f3bf7c1fb7b7673e963aa3e54db2838.zip
Merge pull request #4324 from ReinUsesLisp/formats
video_core: Fix, add and rename pixel formats
Diffstat (limited to 'src/video_core/textures')
-rw-r--r--src/video_core/textures/convert.cpp6
-rw-r--r--src/video_core/textures/decoders.cpp89
-rw-r--r--src/video_core/textures/decoders.h4
-rw-r--r--src/video_core/textures/texture.h49
4 files changed, 26 insertions, 122 deletions
diff --git a/src/video_core/textures/convert.cpp b/src/video_core/textures/convert.cpp
index f3efa7eb0..962921483 100644
--- a/src/video_core/textures/convert.cpp
+++ b/src/video_core/textures/convert.cpp
@@ -35,7 +35,7 @@ void SwapS8Z24ToZ24S8(u8* data, u32 width, u32 height) {
35 S8Z24 s8z24_pixel{}; 35 S8Z24 s8z24_pixel{};
36 Z24S8 z24s8_pixel{}; 36 Z24S8 z24s8_pixel{};
37 constexpr auto bpp{ 37 constexpr auto bpp{
38 VideoCore::Surface::GetBytesPerPixel(VideoCore::Surface::PixelFormat::S8Z24)}; 38 VideoCore::Surface::GetBytesPerPixel(VideoCore::Surface::PixelFormat::S8_UINT_D24_UNORM)};
39 for (std::size_t y = 0; y < height; ++y) { 39 for (std::size_t y = 0; y < height; ++y) {
40 for (std::size_t x = 0; x < width; ++x) { 40 for (std::size_t x = 0; x < width; ++x) {
41 const std::size_t offset{bpp * (y * width + x)}; 41 const std::size_t offset{bpp * (y * width + x)};
@@ -73,7 +73,7 @@ void ConvertFromGuestToHost(u8* in_data, u8* out_data, PixelFormat pixel_format,
73 in_data, width, height, depth, block_width, block_height); 73 in_data, width, height, depth, block_width, block_height);
74 std::copy(rgba8_data.begin(), rgba8_data.end(), out_data); 74 std::copy(rgba8_data.begin(), rgba8_data.end(), out_data);
75 75
76 } else if (convert_s8z24 && pixel_format == PixelFormat::S8Z24) { 76 } else if (convert_s8z24 && pixel_format == PixelFormat::S8_UINT_D24_UNORM) {
77 Tegra::Texture::ConvertS8Z24ToZ24S8(in_data, width, height); 77 Tegra::Texture::ConvertS8Z24ToZ24S8(in_data, width, height);
78 } 78 }
79} 79}
@@ -85,7 +85,7 @@ void ConvertFromHostToGuest(u8* data, PixelFormat pixel_format, u32 width, u32 h
85 static_cast<u32>(pixel_format)); 85 static_cast<u32>(pixel_format));
86 UNREACHABLE(); 86 UNREACHABLE();
87 87
88 } else if (convert_s8z24 && pixel_format == PixelFormat::S8Z24) { 88 } else if (convert_s8z24 && pixel_format == PixelFormat::S8_UINT_D24_UNORM) {
89 Tegra::Texture::ConvertZ24S8ToS8Z24(data, width, height); 89 Tegra::Texture::ConvertZ24S8ToS8Z24(data, width, height);
90 } 90 }
91} 91}
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp
index 98beabef1..474ae620a 100644
--- a/src/video_core/textures/decoders.cpp
+++ b/src/video_core/textures/decoders.cpp
@@ -184,53 +184,6 @@ void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel,
184 } 184 }
185} 185}
186 186
187u32 BytesPerPixel(TextureFormat format) {
188 switch (format) {
189 case TextureFormat::DXT1:
190 case TextureFormat::DXN1:
191 // In this case a 'pixel' actually refers to a 4x4 tile.
192 return 8;
193 case TextureFormat::DXT23:
194 case TextureFormat::DXT45:
195 case TextureFormat::DXN2:
196 case TextureFormat::BC7U:
197 case TextureFormat::BC6H_UF16:
198 case TextureFormat::BC6H_SF16:
199 // In this case a 'pixel' actually refers to a 4x4 tile.
200 return 16;
201 case TextureFormat::R32_G32_B32:
202 return 12;
203 case TextureFormat::ASTC_2D_4X4:
204 case TextureFormat::ASTC_2D_5X4:
205 case TextureFormat::ASTC_2D_8X8:
206 case TextureFormat::ASTC_2D_8X5:
207 case TextureFormat::ASTC_2D_10X8:
208 case TextureFormat::ASTC_2D_5X5:
209 case TextureFormat::A8R8G8B8:
210 case TextureFormat::A2B10G10R10:
211 case TextureFormat::BF10GF11RF11:
212 case TextureFormat::R32:
213 case TextureFormat::R16_G16:
214 return 4;
215 case TextureFormat::A1B5G5R5:
216 case TextureFormat::B5G6R5:
217 case TextureFormat::G8R8:
218 case TextureFormat::R16:
219 return 2;
220 case TextureFormat::R8:
221 return 1;
222 case TextureFormat::R16_G16_B16_A16:
223 return 8;
224 case TextureFormat::R32_G32_B32_A32:
225 return 16;
226 case TextureFormat::R32_G32:
227 return 8;
228 default:
229 UNIMPLEMENTED_MSG("Format not implemented");
230 return 1;
231 }
232}
233
234void UnswizzleTexture(u8* const unswizzled_data, u8* address, u32 tile_size_x, u32 tile_size_y, 187void UnswizzleTexture(u8* const unswizzled_data, u8* address, u32 tile_size_x, u32 tile_size_y,
235 u32 bytes_per_pixel, u32 width, u32 height, u32 depth, u32 block_height, 188 u32 bytes_per_pixel, u32 width, u32 height, u32 depth, u32 block_height,
236 u32 block_depth, u32 width_spacing) { 189 u32 block_depth, u32 width_spacing) {
@@ -348,48 +301,6 @@ void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32
348 } 301 }
349} 302}
350 303
351std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width,
352 u32 height) {
353 std::vector<u8> rgba_data;
354
355 // TODO(Subv): Implement.
356 switch (format) {
357 case TextureFormat::DXT1:
358 case TextureFormat::DXT23:
359 case TextureFormat::DXT45:
360 case TextureFormat::DXN1:
361 case TextureFormat::DXN2:
362 case TextureFormat::BC7U:
363 case TextureFormat::BC6H_UF16:
364 case TextureFormat::BC6H_SF16:
365 case TextureFormat::ASTC_2D_4X4:
366 case TextureFormat::ASTC_2D_8X8:
367 case TextureFormat::ASTC_2D_5X5:
368 case TextureFormat::ASTC_2D_10X8:
369 case TextureFormat::A8R8G8B8:
370 case TextureFormat::A2B10G10R10:
371 case TextureFormat::A1B5G5R5:
372 case TextureFormat::B5G6R5:
373 case TextureFormat::R8:
374 case TextureFormat::G8R8:
375 case TextureFormat::BF10GF11RF11:
376 case TextureFormat::R32_G32_B32_A32:
377 case TextureFormat::R32_G32:
378 case TextureFormat::R32:
379 case TextureFormat::R16:
380 case TextureFormat::R16_G16:
381 case TextureFormat::R32_G32_B32:
382 // TODO(Subv): For the time being just forward the same data without any decoding.
383 rgba_data = texture_data;
384 break;
385 default:
386 UNIMPLEMENTED_MSG("Format not implemented");
387 break;
388 }
389
390 return rgba_data;
391}
392
393std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, 304std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth,
394 u32 block_height, u32 block_depth) { 305 u32 block_height, u32 block_depth) {
395 if (tiled) { 306 if (tiled) {
diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h
index 232b696b3..d6fe35d37 100644
--- a/src/video_core/textures/decoders.h
+++ b/src/video_core/textures/decoders.h
@@ -38,10 +38,6 @@ void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel,
38 u32 out_bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, 38 u32 out_bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data,
39 bool unswizzle, u32 block_height, u32 block_depth, u32 width_spacing); 39 bool unswizzle, u32 block_height, u32 block_depth, u32 width_spacing);
40 40
41/// Decodes an unswizzled texture into a A8R8G8B8 texture.
42std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width,
43 u32 height);
44
45/// This function calculates the correct size of a texture depending if it's tiled or not. 41/// This function calculates the correct size of a texture depending if it's tiled or not.
46std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, 42std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth,
47 u32 block_height, u32 block_depth); 43 u32 block_height, u32 block_depth);
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h
index eba05aced..0574fef12 100644
--- a/src/video_core/textures/texture.h
+++ b/src/video_core/textures/texture.h
@@ -12,10 +12,10 @@
12namespace Tegra::Texture { 12namespace Tegra::Texture {
13 13
14enum class TextureFormat : u32 { 14enum class TextureFormat : u32 {
15 R32_G32_B32_A32 = 0x01, 15 R32G32B32A32 = 0x01,
16 R32_G32_B32 = 0x02, 16 R32G32B32 = 0x02,
17 R16_G16_B16_A16 = 0x03, 17 R16G16B16A16 = 0x03,
18 R32_G32 = 0x04, 18 R32G32 = 0x04,
19 R32_B24G8 = 0x05, 19 R32_B24G8 = 0x05,
20 ETC2_RGB = 0x06, 20 ETC2_RGB = 0x06,
21 X8B8G8R8 = 0x07, 21 X8B8G8R8 = 0x07,
@@ -23,19 +23,19 @@ enum class TextureFormat : u32 {
23 A2B10G10R10 = 0x09, 23 A2B10G10R10 = 0x09,
24 ETC2_RGB_PTA = 0x0a, 24 ETC2_RGB_PTA = 0x0a,
25 ETC2_RGBA = 0x0b, 25 ETC2_RGBA = 0x0b,
26 R16_G16 = 0x0c, 26 R16G16 = 0x0c,
27 G8R24 = 0x0d, 27 R24G8 = 0x0d,
28 G24R8 = 0x0e, 28 R8G24 = 0x0e,
29 R32 = 0x0f, 29 R32 = 0x0f,
30 BC6H_SF16 = 0x10, 30 BC6H_SFLOAT = 0x10,
31 BC6H_UF16 = 0x11, 31 BC6H_UFLOAT = 0x11,
32 A4B4G4R4 = 0x12, 32 A4B4G4R4 = 0x12,
33 A5B5G5R1 = 0x13, 33 A5B5G5R1 = 0x13,
34 A1B5G5R5 = 0x14, 34 A1B5G5R5 = 0x14,
35 B5G6R5 = 0x15, 35 B5G6R5 = 0x15,
36 B6G5R5 = 0x16, 36 B6G5R5 = 0x16,
37 BC7U = 0x17, 37 BC7 = 0x17,
38 G8R8 = 0x18, 38 R8G8 = 0x18,
39 EAC = 0x19, 39 EAC = 0x19,
40 EACX2 = 0x1a, 40 EACX2 = 0x1a,
41 R16 = 0x1b, 41 R16 = 0x1b,
@@ -43,23 +43,23 @@ enum class TextureFormat : u32 {
43 R8 = 0x1d, 43 R8 = 0x1d,
44 G4R4 = 0x1e, 44 G4R4 = 0x1e,
45 R1 = 0x1f, 45 R1 = 0x1f,
46 E5B9G9R9_SHAREDEXP = 0x20, 46 E5B9G9R9 = 0x20,
47 BF10GF11RF11 = 0x21, 47 B10G11R11 = 0x21,
48 G8B8G8R8 = 0x22, 48 G8B8G8R8 = 0x22,
49 B8G8R8G8 = 0x23, 49 B8G8R8G8 = 0x23,
50 DXT1 = 0x24, 50 BC1_RGBA = 0x24,
51 DXT23 = 0x25, 51 BC2 = 0x25,
52 DXT45 = 0x26, 52 BC3 = 0x26,
53 DXN1 = 0x27, 53 BC4 = 0x27,
54 DXN2 = 0x28, 54 BC5 = 0x28,
55 S8Z24 = 0x29, 55 S8D24 = 0x29,
56 X8Z24 = 0x2a, 56 X8Z24 = 0x2a,
57 Z24S8 = 0x2b, 57 D24S8 = 0x2b,
58 X4V4Z24__COV4R4V = 0x2c, 58 X4V4Z24__COV4R4V = 0x2c,
59 X4V4Z24__COV8R8V = 0x2d, 59 X4V4Z24__COV8R8V = 0x2d,
60 V8Z24__COV4R12V = 0x2e, 60 V8Z24__COV4R12V = 0x2e,
61 ZF32 = 0x2f, 61 D32 = 0x2f,
62 ZF32_X24S8 = 0x30, 62 D32S8 = 0x30,
63 X8Z24_X20V4S8__COV4R4V = 0x31, 63 X8Z24_X20V4S8__COV4R4V = 0x31,
64 X8Z24_X20V4S8__COV8R8V = 0x32, 64 X8Z24_X20V4S8__COV8R8V = 0x32,
65 ZF32_X20V4X8__COV4R4V = 0x33, 65 ZF32_X20V4X8__COV4R4V = 0x33,
@@ -69,7 +69,7 @@ enum class TextureFormat : u32 {
69 X8Z24_X16V8S8__COV4R12V = 0x37, 69 X8Z24_X16V8S8__COV4R12V = 0x37,
70 ZF32_X16V8X8__COV4R12V = 0x38, 70 ZF32_X16V8X8__COV4R12V = 0x38,
71 ZF32_X16V8S8__COV4R12V = 0x39, 71 ZF32_X16V8S8__COV4R12V = 0x39,
72 Z16 = 0x3a, 72 D16 = 0x3a,
73 V8Z24__COV8R24V = 0x3b, 73 V8Z24__COV8R24V = 0x3b,
74 X8Z24_X16V8S8__COV8R24V = 0x3c, 74 X8Z24_X16V8S8__COV8R24V = 0x3c,
75 ZF32_X16V8X8__COV8R24V = 0x3d, 75 ZF32_X16V8X8__COV8R24V = 0x3d,
@@ -375,7 +375,4 @@ struct FullTextureInfo {
375 TSCEntry tsc; 375 TSCEntry tsc;
376}; 376};
377 377
378/// Returns the number of bytes per pixel of the input texture format.
379u32 BytesPerPixel(TextureFormat format);
380
381} // namespace Tegra::Texture 378} // namespace Tegra::Texture