summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2015-05-22 01:08:30 +0200
committerGravatar Emmanuel Gil Peyrot2015-06-28 15:11:26 +0100
commit641e78bccf2ddfc54ecd805b139cb1e14549d333 (patch)
treec6048794cabe2ce2c3982409597d4f6d15cc87e0 /src
parentGPU: Use shifts instead of multiplications to calculate the actual size of th... (diff)
downloadyuzu-641e78bccf2ddfc54ecd805b139cb1e14549d333.tar.gz
yuzu-641e78bccf2ddfc54ecd805b139cb1e14549d333.tar.xz
yuzu-641e78bccf2ddfc54ecd805b139cb1e14549d333.zip
GPU: Implement blended downscaling for display transfers.
Diffstat (limited to '')
-rw-r--r--src/core/hw/gpu.cpp67
1 files changed, 40 insertions, 27 deletions
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index 2bc650002..dd3b31650 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -53,6 +53,29 @@ inline void Read(T &var, const u32 raw_addr) {
53 var = g_regs[addr / 4]; 53 var = g_regs[addr / 4];
54} 54}
55 55
56static Math::Vec4<u8> DecodePixel(Regs::PixelFormat input_format, const u8* src_pixel) {
57 switch (input_format) {
58 case Regs::PixelFormat::RGBA8:
59 return Color::DecodeRGBA8(src_pixel);
60
61 case Regs::PixelFormat::RGB8:
62 return Color::DecodeRGB8(src_pixel);
63
64 case Regs::PixelFormat::RGB565:
65 return Color::DecodeRGB565(src_pixel);
66
67 case Regs::PixelFormat::RGB5A1:
68 return Color::DecodeRGB5A1(src_pixel);
69
70 case Regs::PixelFormat::RGBA4:
71 return Color::DecodeRGBA4(src_pixel);
72
73 default:
74 LOG_ERROR(HW_GPU, "Unknown source framebuffer format %x", input_format);
75 return {0, 0, 0, 0};
76 }
77}
78
56template <typename T> 79template <typename T>
57inline void Write(u32 addr, const T data) { 80inline void Write(u32 addr, const T data) {
58 addr -= HW::VADDR_GPU; 81 addr -= HW::VADDR_GPU;
@@ -125,6 +148,13 @@ inline void Write(u32 addr, const T data) {
125 break; 148 break;
126 } 149 }
127 150
151 if (config.output_tiled &&
152 (config.scaling == config.ScaleXY || config.scaling == config.ScaleX)) {
153 LOG_CRITICAL(HW_GPU, "Scaling is only implemented on tiled input");
154 UNIMPLEMENTED();
155 break;
156 }
157
128 bool horizontal_scale = config.scaling != config.NoScale; 158 bool horizontal_scale = config.scaling != config.NoScale;
129 bool vertical_scale = config.scaling == config.ScaleXY; 159 bool vertical_scale = config.scaling == config.ScaleXY;
130 160
@@ -153,11 +183,9 @@ inline void Write(u32 addr, const T data) {
153 break; 183 break;
154 } 184 }
155 185
156 // TODO(Subv): Implement the box filter when scaling is enabled
157 // right now we're just skipping the extra pixels.
158 for (u32 y = 0; y < output_height; ++y) { 186 for (u32 y = 0; y < output_height; ++y) {
159 for (u32 x = 0; x < output_width; ++x) { 187 for (u32 x = 0; x < output_width; ++x) {
160 Math::Vec4<u8> src_color = { 0, 0, 0, 0 }; 188 Math::Vec4<u8> src_color;
161 189
162 // Calculate the [x,y] position of the input image 190 // Calculate the [x,y] position of the input image
163 // based on the current output position and the scale 191 // based on the current output position and the scale
@@ -193,30 +221,15 @@ inline void Write(u32 addr, const T data) {
193 } 221 }
194 222
195 const u8* src_pixel = src_pointer + src_offset; 223 const u8* src_pixel = src_pointer + src_offset;
196 switch (config.input_format) { 224 src_color = DecodePixel(config.input_format, src_pixel);
197 case Regs::PixelFormat::RGBA8: 225 if (config.scaling == config.ScaleX) {
198 src_color = Color::DecodeRGBA8(src_pixel); 226 Math::Vec4<u8> pixel = DecodePixel(config.input_format, src_pixel + src_bytes_per_pixel);
199 break; 227 src_color = ((src_color + pixel) / 2).Cast<u8>();
200 228 } else if (config.scaling == config.ScaleXY) {
201 case Regs::PixelFormat::RGB8: 229 Math::Vec4<u8> pixel1 = DecodePixel(config.input_format, src_pixel + 1 * src_bytes_per_pixel);
202 src_color = Color::DecodeRGB8(src_pixel); 230 Math::Vec4<u8> pixel2 = DecodePixel(config.input_format, src_pixel + 2 * src_bytes_per_pixel);
203 break; 231 Math::Vec4<u8> pixel3 = DecodePixel(config.input_format, src_pixel + 3 * src_bytes_per_pixel);
204 232 src_color = (((src_color + pixel1) + (pixel2 + pixel3)) / 4).Cast<u8>();
205 case Regs::PixelFormat::RGB565:
206 src_color = Color::DecodeRGB565(src_pixel);
207 break;
208
209 case Regs::PixelFormat::RGB5A1:
210 src_color = Color::DecodeRGB5A1(src_pixel);
211 break;
212
213 case Regs::PixelFormat::RGBA4:
214 src_color = Color::DecodeRGBA4(src_pixel);
215 break;
216
217 default:
218 LOG_ERROR(HW_GPU, "Unknown source framebuffer format %x", config.input_format.Value());
219 break;
220 } 233 }
221 234
222 u8* dst_pixel = dst_pointer + dst_offset; 235 u8* dst_pixel = dst_pointer + dst_offset;