summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2018-04-18 20:48:53 -0500
committerGravatar Subv2018-04-18 20:48:53 -0500
commit057170928ce71fb262d4d9969b7889971dc7232a (patch)
tree13c219cf533d215e6f20ce47a3ea92465974fd98 /src
parentMerge pull request #351 from Subv/tex_formats (diff)
downloadyuzu-057170928ce71fb262d4d9969b7889971dc7232a.tar.gz
yuzu-057170928ce71fb262d4d9969b7889971dc7232a.tar.xz
yuzu-057170928ce71fb262d4d9969b7889971dc7232a.zip
GPU: Add support for the DXT23 and DXT45 compressed texture formats.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.cpp35
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer_cache.h18
-rw-r--r--src/video_core/textures/decoders.cpp10
3 files changed, 35 insertions, 28 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
index 2a0858eac..561c6913d 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp
@@ -49,9 +49,11 @@ struct FormatTuple {
49}; 49};
50 50
51static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{ 51static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_format_tuples = {{
52 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false, 1}, // ABGR8 52 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false, 1}, // ABGR8
53 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, false, 1}, // B5G6R5 53 {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV, false, 1}, // B5G6R5
54 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT1 54 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT1
55 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT23
56 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT45
55}}; 57}};
56 58
57static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) { 59static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) {
@@ -82,23 +84,6 @@ static u16 GetResolutionScaleFactor() {
82} 84}
83 85
84template <bool morton_to_gl, PixelFormat format> 86template <bool morton_to_gl, PixelFormat format>
85static void MortonCopyTile(u32 stride, u8* tile_buffer, u8* gl_buffer) {
86 constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / 8;
87 constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format);
88 for (u32 y = 0; y < 8; ++y) {
89 for (u32 x = 0; x < 8; ++x) {
90 u8* tile_ptr = tile_buffer + VideoCore::MortonInterleave(x, y) * bytes_per_pixel;
91 u8* gl_ptr = gl_buffer + ((7 - y) * stride + x) * gl_bytes_per_pixel;
92 if (morton_to_gl) {
93 std::memcpy(gl_ptr, tile_ptr, bytes_per_pixel);
94 } else {
95 std::memcpy(tile_ptr, gl_ptr, bytes_per_pixel);
96 }
97 }
98 }
99}
100
101template <bool morton_to_gl, PixelFormat format>
102void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, VAddr base, VAddr start, 87void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, VAddr base, VAddr start,
103 VAddr end) { 88 VAddr end) {
104 constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / 8; 89 constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / 8;
@@ -121,9 +106,9 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, VAddr b
121static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr), 106static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr),
122 SurfaceParams::MaxPixelFormat> 107 SurfaceParams::MaxPixelFormat>
123 morton_to_gl_fns = { 108 morton_to_gl_fns = {
124 MortonCopy<true, PixelFormat::ABGR8>, 109 MortonCopy<true, PixelFormat::ABGR8>, MortonCopy<true, PixelFormat::B5G6R5>,
125 MortonCopy<true, PixelFormat::B5G6R5>, 110 MortonCopy<true, PixelFormat::DXT1>, MortonCopy<true, PixelFormat::DXT23>,
126 MortonCopy<true, PixelFormat::DXT1>, 111 MortonCopy<true, PixelFormat::DXT45>,
127}; 112};
128 113
129static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr), 114static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr),
@@ -131,7 +116,9 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, VAddr, VAddr, VAddr),
131 gl_to_morton_fns = { 116 gl_to_morton_fns = {
132 MortonCopy<false, PixelFormat::ABGR8>, 117 MortonCopy<false, PixelFormat::ABGR8>,
133 MortonCopy<false, PixelFormat::B5G6R5>, 118 MortonCopy<false, PixelFormat::B5G6R5>,
134 // TODO(Subv): Swizzling the DXT1 format is not yet supported 119 // TODO(Subv): Swizzling the DXT1/DXT23/DXT45 formats is not yet supported
120 nullptr,
121 nullptr,
135 nullptr, 122 nullptr,
136}; 123};
137 124
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
index 23e4d02d8..6861efe16 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h
@@ -55,6 +55,8 @@ struct SurfaceParams {
55 ABGR8 = 0, 55 ABGR8 = 0,
56 B5G6R5 = 1, 56 B5G6R5 = 1,
57 DXT1 = 2, 57 DXT1 = 2,
58 DXT23 = 3,
59 DXT45 = 4,
58 60
59 Max, 61 Max,
60 Invalid = 255, 62 Invalid = 255,
@@ -84,9 +86,11 @@ struct SurfaceParams {
84 return 0; 86 return 0;
85 87
86 constexpr std::array<unsigned int, MaxPixelFormat> bpp_table = { 88 constexpr std::array<unsigned int, MaxPixelFormat> bpp_table = {
87 32, // ABGR8 89 32, // ABGR8
88 16, // B5G6R5 90 16, // B5G6R5
89 64, // DXT1 91 64, // DXT1
92 128, // DXT23
93 128, // DXT45
90 }; 94 };
91 95
92 ASSERT(static_cast<size_t>(format) < bpp_table.size()); 96 ASSERT(static_cast<size_t>(format) < bpp_table.size());
@@ -125,6 +129,10 @@ struct SurfaceParams {
125 return PixelFormat::B5G6R5; 129 return PixelFormat::B5G6R5;
126 case Tegra::Texture::TextureFormat::DXT1: 130 case Tegra::Texture::TextureFormat::DXT1:
127 return PixelFormat::DXT1; 131 return PixelFormat::DXT1;
132 case Tegra::Texture::TextureFormat::DXT23:
133 return PixelFormat::DXT23;
134 case Tegra::Texture::TextureFormat::DXT45:
135 return PixelFormat::DXT45;
128 default: 136 default:
129 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); 137 NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
130 UNREACHABLE(); 138 UNREACHABLE();
@@ -140,6 +148,10 @@ struct SurfaceParams {
140 return Tegra::Texture::TextureFormat::B5G6R5; 148 return Tegra::Texture::TextureFormat::B5G6R5;
141 case PixelFormat::DXT1: 149 case PixelFormat::DXT1:
142 return Tegra::Texture::TextureFormat::DXT1; 150 return Tegra::Texture::TextureFormat::DXT1;
151 case PixelFormat::DXT23:
152 return Tegra::Texture::TextureFormat::DXT23;
153 case PixelFormat::DXT45:
154 return Tegra::Texture::TextureFormat::DXT45;
143 default: 155 default:
144 UNREACHABLE(); 156 UNREACHABLE();
145 } 157 }
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp
index f4c7e40df..4df687786 100644
--- a/src/video_core/textures/decoders.cpp
+++ b/src/video_core/textures/decoders.cpp
@@ -48,6 +48,10 @@ u32 BytesPerPixel(TextureFormat format) {
48 case TextureFormat::DXT1: 48 case TextureFormat::DXT1:
49 // In this case a 'pixel' actually refers to a 4x4 tile. 49 // In this case a 'pixel' actually refers to a 4x4 tile.
50 return 8; 50 return 8;
51 case TextureFormat::DXT23:
52 case TextureFormat::DXT45:
53 // In this case a 'pixel' actually refers to a 4x4 tile.
54 return 16;
51 case TextureFormat::A8R8G8B8: 55 case TextureFormat::A8R8G8B8:
52 return 4; 56 return 4;
53 case TextureFormat::B5G6R5: 57 case TextureFormat::B5G6R5:
@@ -67,7 +71,9 @@ std::vector<u8> UnswizzleTexture(VAddr address, TextureFormat format, u32 width,
67 71
68 switch (format) { 72 switch (format) {
69 case TextureFormat::DXT1: 73 case TextureFormat::DXT1:
70 // In the DXT1 format, each 4x4 tile is swizzled instead of just individual pixel values. 74 case TextureFormat::DXT23:
75 case TextureFormat::DXT45:
76 // In the DXT formats, each 4x4 tile is swizzled instead of just individual pixel values.
71 CopySwizzledData(width / 4, height / 4, bytes_per_pixel, bytes_per_pixel, data, 77 CopySwizzledData(width / 4, height / 4, bytes_per_pixel, bytes_per_pixel, data,
72 unswizzled_data.data(), true, block_height); 78 unswizzled_data.data(), true, block_height);
73 break; 79 break;
@@ -91,6 +97,8 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat
91 // TODO(Subv): Implement. 97 // TODO(Subv): Implement.
92 switch (format) { 98 switch (format) {
93 case TextureFormat::DXT1: 99 case TextureFormat::DXT1:
100 case TextureFormat::DXT23:
101 case TextureFormat::DXT45:
94 case TextureFormat::A8R8G8B8: 102 case TextureFormat::A8R8G8B8:
95 case TextureFormat::B5G6R5: 103 case TextureFormat::B5G6R5:
96 // TODO(Subv): For the time being just forward the same data without any decoding. 104 // TODO(Subv): For the time being just forward the same data without any decoding.