summaryrefslogtreecommitdiff
path: root/src/video_core/textures/decoders.cpp
diff options
context:
space:
mode:
authorGravatar David Marcec2018-08-11 10:35:47 +1000
committerGravatar David Marcec2018-08-11 10:35:47 +1000
commitb76ddb7647cbb390cce4143d91a1db171b0fa503 (patch)
treea6e2e334e82b035923c41458150604dd5fb31d65 /src/video_core/textures/decoders.cpp
parentAdded IsUserRegistrationRequestPermitted (diff)
parentMerge pull request #1007 from MerryMage/dynarmic (diff)
downloadyuzu-b76ddb7647cbb390cce4143d91a1db171b0fa503.tar.gz
yuzu-b76ddb7647cbb390cce4143d91a1db171b0fa503.tar.xz
yuzu-b76ddb7647cbb390cce4143d91a1db171b0fa503.zip
Merge remote-tracking branch 'origin/master' into better-account
Diffstat (limited to 'src/video_core/textures/decoders.cpp')
-rw-r--r--src/video_core/textures/decoders.cpp86
1 files changed, 6 insertions, 80 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp
index 65db84ad3..70746a34e 100644
--- a/src/video_core/textures/decoders.cpp
+++ b/src/video_core/textures/decoders.cpp
@@ -54,6 +54,7 @@ u32 BytesPerPixel(TextureFormat format) {
54 return 8; 54 return 8;
55 case TextureFormat::DXT23: 55 case TextureFormat::DXT23:
56 case TextureFormat::DXT45: 56 case TextureFormat::DXT45:
57 case TextureFormat::DXN2:
57 case TextureFormat::BC7U: 58 case TextureFormat::BC7U:
58 // In this case a 'pixel' actually refers to a 4x4 tile. 59 // In this case a 'pixel' actually refers to a 4x4 tile.
59 return 16; 60 return 16;
@@ -85,87 +86,11 @@ u32 BytesPerPixel(TextureFormat format) {
85 } 86 }
86} 87}
87 88
88static u32 DepthBytesPerPixel(DepthFormat format) { 89std::vector<u8> UnswizzleTexture(VAddr address, u32 tile_size, u32 bytes_per_pixel, u32 width,
89 switch (format) { 90 u32 height, u32 block_height) {
90 case DepthFormat::Z16_UNORM:
91 return 2;
92 case DepthFormat::S8_Z24_UNORM:
93 case DepthFormat::Z24_S8_UNORM:
94 case DepthFormat::Z32_FLOAT:
95 return 4;
96 case DepthFormat::Z32_S8_X24_FLOAT:
97 return 8;
98 default:
99 UNIMPLEMENTED_MSG("Format not implemented");
100 break;
101 }
102}
103
104std::vector<u8> UnswizzleTexture(VAddr address, TextureFormat format, u32 width, u32 height,
105 u32 block_height) {
106 u8* data = Memory::GetPointer(address);
107 u32 bytes_per_pixel = BytesPerPixel(format);
108
109 std::vector<u8> unswizzled_data(width * height * bytes_per_pixel); 91 std::vector<u8> unswizzled_data(width * height * bytes_per_pixel);
110 92 CopySwizzledData(width / tile_size, height / tile_size, bytes_per_pixel, bytes_per_pixel,
111 switch (format) { 93 Memory::GetPointer(address), unswizzled_data.data(), true, block_height);
112 case TextureFormat::DXT1:
113 case TextureFormat::DXT23:
114 case TextureFormat::DXT45:
115 case TextureFormat::DXN1:
116 case TextureFormat::BC7U:
117 // In the DXT and DXN formats, each 4x4 tile is swizzled instead of just individual pixel
118 // values.
119 CopySwizzledData(width / 4, height / 4, bytes_per_pixel, bytes_per_pixel, data,
120 unswizzled_data.data(), true, block_height);
121 break;
122 case TextureFormat::A8R8G8B8:
123 case TextureFormat::A2B10G10R10:
124 case TextureFormat::A1B5G5R5:
125 case TextureFormat::B5G6R5:
126 case TextureFormat::R8:
127 case TextureFormat::G8R8:
128 case TextureFormat::R16_G16_B16_A16:
129 case TextureFormat::R32_G32_B32_A32:
130 case TextureFormat::R32_G32:
131 case TextureFormat::R32:
132 case TextureFormat::R16:
133 case TextureFormat::R16_G16:
134 case TextureFormat::BF10GF11RF11:
135 case TextureFormat::ASTC_2D_4X4:
136 case TextureFormat::R32_G32_B32:
137 CopySwizzledData(width, height, bytes_per_pixel, bytes_per_pixel, data,
138 unswizzled_data.data(), true, block_height);
139 break;
140 default:
141 UNIMPLEMENTED_MSG("Format not implemented");
142 break;
143 }
144
145 return unswizzled_data;
146}
147
148std::vector<u8> UnswizzleDepthTexture(VAddr address, DepthFormat format, u32 width, u32 height,
149 u32 block_height) {
150 u8* data = Memory::GetPointer(address);
151 u32 bytes_per_pixel = DepthBytesPerPixel(format);
152
153 std::vector<u8> unswizzled_data(width * height * bytes_per_pixel);
154
155 switch (format) {
156 case DepthFormat::Z16_UNORM:
157 case DepthFormat::S8_Z24_UNORM:
158 case DepthFormat::Z24_S8_UNORM:
159 case DepthFormat::Z32_FLOAT:
160 case DepthFormat::Z32_S8_X24_FLOAT:
161 CopySwizzledData(width, height, bytes_per_pixel, bytes_per_pixel, data,
162 unswizzled_data.data(), true, block_height);
163 break;
164 default:
165 UNIMPLEMENTED_MSG("Format not implemented");
166 break;
167 }
168
169 return unswizzled_data; 94 return unswizzled_data;
170} 95}
171 96
@@ -179,6 +104,7 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat
179 case TextureFormat::DXT23: 104 case TextureFormat::DXT23:
180 case TextureFormat::DXT45: 105 case TextureFormat::DXT45:
181 case TextureFormat::DXN1: 106 case TextureFormat::DXN1:
107 case TextureFormat::DXN2:
182 case TextureFormat::BC7U: 108 case TextureFormat::BC7U:
183 case TextureFormat::ASTC_2D_4X4: 109 case TextureFormat::ASTC_2D_4X4:
184 case TextureFormat::A8R8G8B8: 110 case TextureFormat::A8R8G8B8: