Merge pull request #2793 from ReinUsesLisp/bgr565
renderer_opengl: Implement RGB565 framebuffer format
This commit is contained in:
		| @@ -37,7 +37,7 @@ void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u3 | |||||||
|         transform, crop_rect}; |         transform, crop_rect}; | ||||||
|  |  | ||||||
|     system.GetPerfStats().EndGameFrame(); |     system.GetPerfStats().EndGameFrame(); | ||||||
|     system.GPU().SwapBuffers(framebuffer); |     system.GPU().SwapBuffers(&framebuffer); | ||||||
| } | } | ||||||
|  |  | ||||||
| } // namespace Service::Nvidia::Devices | } // namespace Service::Nvidia::Devices | ||||||
|   | |||||||
| @@ -17,18 +17,6 @@ | |||||||
|  |  | ||||||
| namespace Tegra { | namespace Tegra { | ||||||
|  |  | ||||||
| u32 FramebufferConfig::BytesPerPixel(PixelFormat format) { |  | ||||||
|     switch (format) { |  | ||||||
|     case PixelFormat::ABGR8: |  | ||||||
|     case PixelFormat::BGRA8: |  | ||||||
|         return 4; |  | ||||||
|     default: |  | ||||||
|         return 4; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     UNREACHABLE(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| GPU::GPU(Core::System& system, VideoCore::RendererBase& renderer, bool is_async) | GPU::GPU(Core::System& system, VideoCore::RendererBase& renderer, bool is_async) | ||||||
|     : system{system}, renderer{renderer}, is_async{is_async} { |     : system{system}, renderer{renderer}, is_async{is_async} { | ||||||
|     auto& rasterizer{renderer.Rasterizer()}; |     auto& rasterizer{renderer.Rasterizer()}; | ||||||
|   | |||||||
| @@ -95,14 +95,10 @@ class DebugContext; | |||||||
| struct FramebufferConfig { | struct FramebufferConfig { | ||||||
|     enum class PixelFormat : u32 { |     enum class PixelFormat : u32 { | ||||||
|         ABGR8 = 1, |         ABGR8 = 1, | ||||||
|  |         RGB565 = 4, | ||||||
|         BGRA8 = 5, |         BGRA8 = 5, | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Returns the number of bytes per pixel. |  | ||||||
|      */ |  | ||||||
|     static u32 BytesPerPixel(PixelFormat format); |  | ||||||
|  |  | ||||||
|     VAddr address; |     VAddr address; | ||||||
|     u32 offset; |     u32 offset; | ||||||
|     u32 width; |     u32 width; | ||||||
| @@ -253,8 +249,7 @@ public: | |||||||
|     virtual void PushGPUEntries(Tegra::CommandList&& entries) = 0; |     virtual void PushGPUEntries(Tegra::CommandList&& entries) = 0; | ||||||
|  |  | ||||||
|     /// Swap buffers (render frame) |     /// Swap buffers (render frame) | ||||||
|     virtual void SwapBuffers( |     virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0; | ||||||
|         std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) = 0; |  | ||||||
|  |  | ||||||
|     /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory |     /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory | ||||||
|     virtual void FlushRegion(CacheAddr addr, u64 size) = 0; |     virtual void FlushRegion(CacheAddr addr, u64 size) = 0; | ||||||
|   | |||||||
| @@ -23,9 +23,8 @@ void GPUAsynch::PushGPUEntries(Tegra::CommandList&& entries) { | |||||||
|     gpu_thread.SubmitList(std::move(entries)); |     gpu_thread.SubmitList(std::move(entries)); | ||||||
| } | } | ||||||
|  |  | ||||||
| void GPUAsynch::SwapBuffers( | void GPUAsynch::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | ||||||
|     std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) { |     gpu_thread.SwapBuffers(framebuffer); | ||||||
|     gpu_thread.SwapBuffers(std::move(framebuffer)); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void GPUAsynch::FlushRegion(CacheAddr addr, u64 size) { | void GPUAsynch::FlushRegion(CacheAddr addr, u64 size) { | ||||||
|   | |||||||
| @@ -14,15 +14,14 @@ class RendererBase; | |||||||
| namespace VideoCommon { | namespace VideoCommon { | ||||||
|  |  | ||||||
| /// Implementation of GPU interface that runs the GPU asynchronously | /// Implementation of GPU interface that runs the GPU asynchronously | ||||||
| class GPUAsynch : public Tegra::GPU { | class GPUAsynch final : public Tegra::GPU { | ||||||
| public: | public: | ||||||
|     explicit GPUAsynch(Core::System& system, VideoCore::RendererBase& renderer); |     explicit GPUAsynch(Core::System& system, VideoCore::RendererBase& renderer); | ||||||
|     ~GPUAsynch() override; |     ~GPUAsynch() override; | ||||||
|  |  | ||||||
|     void Start() override; |     void Start() override; | ||||||
|     void PushGPUEntries(Tegra::CommandList&& entries) override; |     void PushGPUEntries(Tegra::CommandList&& entries) override; | ||||||
|     void SwapBuffers( |     void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override; | ||||||
|         std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) override; |  | ||||||
|     void FlushRegion(CacheAddr addr, u64 size) override; |     void FlushRegion(CacheAddr addr, u64 size) override; | ||||||
|     void InvalidateRegion(CacheAddr addr, u64 size) override; |     void InvalidateRegion(CacheAddr addr, u64 size) override; | ||||||
|     void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override; |     void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override; | ||||||
|   | |||||||
| @@ -19,9 +19,8 @@ void GPUSynch::PushGPUEntries(Tegra::CommandList&& entries) { | |||||||
|     dma_pusher->DispatchCalls(); |     dma_pusher->DispatchCalls(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void GPUSynch::SwapBuffers( | void GPUSynch::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | ||||||
|     std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) { |     renderer.SwapBuffers(framebuffer); | ||||||
|     renderer.SwapBuffers(std::move(framebuffer)); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void GPUSynch::FlushRegion(CacheAddr addr, u64 size) { | void GPUSynch::FlushRegion(CacheAddr addr, u64 size) { | ||||||
|   | |||||||
| @@ -13,15 +13,14 @@ class RendererBase; | |||||||
| namespace VideoCommon { | namespace VideoCommon { | ||||||
|  |  | ||||||
| /// Implementation of GPU interface that runs the GPU synchronously | /// Implementation of GPU interface that runs the GPU synchronously | ||||||
| class GPUSynch : public Tegra::GPU { | class GPUSynch final : public Tegra::GPU { | ||||||
| public: | public: | ||||||
|     explicit GPUSynch(Core::System& system, VideoCore::RendererBase& renderer); |     explicit GPUSynch(Core::System& system, VideoCore::RendererBase& renderer); | ||||||
|     ~GPUSynch() override; |     ~GPUSynch() override; | ||||||
|  |  | ||||||
|     void Start() override; |     void Start() override; | ||||||
|     void PushGPUEntries(Tegra::CommandList&& entries) override; |     void PushGPUEntries(Tegra::CommandList&& entries) override; | ||||||
|     void SwapBuffers( |     void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override; | ||||||
|         std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) override; |  | ||||||
|     void FlushRegion(CacheAddr addr, u64 size) override; |     void FlushRegion(CacheAddr addr, u64 size) override; | ||||||
|     void InvalidateRegion(CacheAddr addr, u64 size) override; |     void InvalidateRegion(CacheAddr addr, u64 size) override; | ||||||
|     void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override; |     void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override; | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ static void RunThread(VideoCore::RendererBase& renderer, Tegra::DmaPusher& dma_p | |||||||
|                 dma_pusher.Push(std::move(submit_list->entries)); |                 dma_pusher.Push(std::move(submit_list->entries)); | ||||||
|                 dma_pusher.DispatchCalls(); |                 dma_pusher.DispatchCalls(); | ||||||
|             } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) { |             } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) { | ||||||
|                 renderer.SwapBuffers(std::move(data->framebuffer)); |                 renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr); | ||||||
|             } else if (const auto data = std::get_if<FlushRegionCommand>(&next.data)) { |             } else if (const auto data = std::get_if<FlushRegionCommand>(&next.data)) { | ||||||
|                 renderer.Rasterizer().FlushRegion(data->addr, data->size); |                 renderer.Rasterizer().FlushRegion(data->addr, data->size); | ||||||
|             } else if (const auto data = std::get_if<InvalidateRegionCommand>(&next.data)) { |             } else if (const auto data = std::get_if<InvalidateRegionCommand>(&next.data)) { | ||||||
| @@ -78,9 +78,9 @@ void ThreadManager::SubmitList(Tegra::CommandList&& entries) { | |||||||
|     system.CoreTiming().ScheduleEvent(synchronization_ticks, synchronization_event, fence); |     system.CoreTiming().ScheduleEvent(synchronization_ticks, synchronization_event, fence); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ThreadManager::SwapBuffers( | void ThreadManager::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | ||||||
|     std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) { |     PushCommand(SwapBuffersCommand(framebuffer ? *framebuffer | ||||||
|     PushCommand(SwapBuffersCommand(std::move(framebuffer))); |                                                : std::optional<const Tegra::FramebufferConfig>{})); | ||||||
| } | } | ||||||
|  |  | ||||||
| void ThreadManager::FlushRegion(CacheAddr addr, u64 size) { | void ThreadManager::FlushRegion(CacheAddr addr, u64 size) { | ||||||
|   | |||||||
| @@ -110,8 +110,7 @@ public: | |||||||
|     void SubmitList(Tegra::CommandList&& entries); |     void SubmitList(Tegra::CommandList&& entries); | ||||||
|  |  | ||||||
|     /// Swap buffers (render frame) |     /// Swap buffers (render frame) | ||||||
|     void SwapBuffers( |     void SwapBuffers(const Tegra::FramebufferConfig* framebuffer); | ||||||
|         std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer); |  | ||||||
|  |  | ||||||
|     /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory |     /// Notify rasterizer that any caches of the specified region should be flushed to Switch memory | ||||||
|     void FlushRegion(CacheAddr addr, u64 size); |     void FlushRegion(CacheAddr addr, u64 size); | ||||||
|   | |||||||
| @@ -25,8 +25,8 @@ static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth | |||||||
|  |  | ||||||
|     // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual |     // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual | ||||||
|     // pixel values. |     // pixel values. | ||||||
|     const u32 tile_size_x{GetDefaultBlockWidth(format)}; |     constexpr u32 tile_size_x{GetDefaultBlockWidth(format)}; | ||||||
|     const u32 tile_size_y{GetDefaultBlockHeight(format)}; |     constexpr u32 tile_size_y{GetDefaultBlockHeight(format)}; | ||||||
|  |  | ||||||
|     if constexpr (morton_to_linear) { |     if constexpr (morton_to_linear) { | ||||||
|         Tegra::Texture::UnswizzleTexture(buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel, |         Tegra::Texture::UnswizzleTexture(buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel, | ||||||
| @@ -186,99 +186,6 @@ static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFor | |||||||
|     return morton_to_linear_fns[static_cast<std::size_t>(format)]; |     return morton_to_linear_fns[static_cast<std::size_t>(format)]; | ||||||
| } | } | ||||||
|  |  | ||||||
| static u32 MortonInterleave128(u32 x, u32 y) { |  | ||||||
|     // 128x128 Z-Order coordinate from 2D coordinates |  | ||||||
|     static constexpr u32 xlut[] = { |  | ||||||
|         0x0000, 0x0001, 0x0002, 0x0003, 0x0008, 0x0009, 0x000a, 0x000b, 0x0040, 0x0041, 0x0042, |  | ||||||
|         0x0043, 0x0048, 0x0049, 0x004a, 0x004b, 0x0800, 0x0801, 0x0802, 0x0803, 0x0808, 0x0809, |  | ||||||
|         0x080a, 0x080b, 0x0840, 0x0841, 0x0842, 0x0843, 0x0848, 0x0849, 0x084a, 0x084b, 0x1000, |  | ||||||
|         0x1001, 0x1002, 0x1003, 0x1008, 0x1009, 0x100a, 0x100b, 0x1040, 0x1041, 0x1042, 0x1043, |  | ||||||
|         0x1048, 0x1049, 0x104a, 0x104b, 0x1800, 0x1801, 0x1802, 0x1803, 0x1808, 0x1809, 0x180a, |  | ||||||
|         0x180b, 0x1840, 0x1841, 0x1842, 0x1843, 0x1848, 0x1849, 0x184a, 0x184b, 0x2000, 0x2001, |  | ||||||
|         0x2002, 0x2003, 0x2008, 0x2009, 0x200a, 0x200b, 0x2040, 0x2041, 0x2042, 0x2043, 0x2048, |  | ||||||
|         0x2049, 0x204a, 0x204b, 0x2800, 0x2801, 0x2802, 0x2803, 0x2808, 0x2809, 0x280a, 0x280b, |  | ||||||
|         0x2840, 0x2841, 0x2842, 0x2843, 0x2848, 0x2849, 0x284a, 0x284b, 0x3000, 0x3001, 0x3002, |  | ||||||
|         0x3003, 0x3008, 0x3009, 0x300a, 0x300b, 0x3040, 0x3041, 0x3042, 0x3043, 0x3048, 0x3049, |  | ||||||
|         0x304a, 0x304b, 0x3800, 0x3801, 0x3802, 0x3803, 0x3808, 0x3809, 0x380a, 0x380b, 0x3840, |  | ||||||
|         0x3841, 0x3842, 0x3843, 0x3848, 0x3849, 0x384a, 0x384b, 0x0000, 0x0001, 0x0002, 0x0003, |  | ||||||
|         0x0008, 0x0009, 0x000a, 0x000b, 0x0040, 0x0041, 0x0042, 0x0043, 0x0048, 0x0049, 0x004a, |  | ||||||
|         0x004b, 0x0800, 0x0801, 0x0802, 0x0803, 0x0808, 0x0809, 0x080a, 0x080b, 0x0840, 0x0841, |  | ||||||
|         0x0842, 0x0843, 0x0848, 0x0849, 0x084a, 0x084b, 0x1000, 0x1001, 0x1002, 0x1003, 0x1008, |  | ||||||
|         0x1009, 0x100a, 0x100b, 0x1040, 0x1041, 0x1042, 0x1043, 0x1048, 0x1049, 0x104a, 0x104b, |  | ||||||
|         0x1800, 0x1801, 0x1802, 0x1803, 0x1808, 0x1809, 0x180a, 0x180b, 0x1840, 0x1841, 0x1842, |  | ||||||
|         0x1843, 0x1848, 0x1849, 0x184a, 0x184b, 0x2000, 0x2001, 0x2002, 0x2003, 0x2008, 0x2009, |  | ||||||
|         0x200a, 0x200b, 0x2040, 0x2041, 0x2042, 0x2043, 0x2048, 0x2049, 0x204a, 0x204b, 0x2800, |  | ||||||
|         0x2801, 0x2802, 0x2803, 0x2808, 0x2809, 0x280a, 0x280b, 0x2840, 0x2841, 0x2842, 0x2843, |  | ||||||
|         0x2848, 0x2849, 0x284a, 0x284b, 0x3000, 0x3001, 0x3002, 0x3003, 0x3008, 0x3009, 0x300a, |  | ||||||
|         0x300b, 0x3040, 0x3041, 0x3042, 0x3043, 0x3048, 0x3049, 0x304a, 0x304b, 0x3800, 0x3801, |  | ||||||
|         0x3802, 0x3803, 0x3808, 0x3809, 0x380a, 0x380b, 0x3840, 0x3841, 0x3842, 0x3843, 0x3848, |  | ||||||
|         0x3849, 0x384a, 0x384b, 0x0000, 0x0001, 0x0002, 0x0003, 0x0008, 0x0009, 0x000a, 0x000b, |  | ||||||
|         0x0040, 0x0041, 0x0042, 0x0043, 0x0048, 0x0049, 0x004a, 0x004b, 0x0800, 0x0801, 0x0802, |  | ||||||
|         0x0803, 0x0808, 0x0809, 0x080a, 0x080b, 0x0840, 0x0841, 0x0842, 0x0843, 0x0848, 0x0849, |  | ||||||
|         0x084a, 0x084b, 0x1000, 0x1001, 0x1002, 0x1003, 0x1008, 0x1009, 0x100a, 0x100b, 0x1040, |  | ||||||
|         0x1041, 0x1042, 0x1043, 0x1048, 0x1049, 0x104a, 0x104b, 0x1800, 0x1801, 0x1802, 0x1803, |  | ||||||
|         0x1808, 0x1809, 0x180a, 0x180b, 0x1840, 0x1841, 0x1842, 0x1843, 0x1848, 0x1849, 0x184a, |  | ||||||
|         0x184b, 0x2000, 0x2001, 0x2002, 0x2003, 0x2008, 0x2009, 0x200a, 0x200b, 0x2040, 0x2041, |  | ||||||
|         0x2042, 0x2043, 0x2048, 0x2049, 0x204a, 0x204b, 0x2800, 0x2801, 0x2802, 0x2803, 0x2808, |  | ||||||
|         0x2809, 0x280a, 0x280b, 0x2840, 0x2841, 0x2842, 0x2843, 0x2848, 0x2849, 0x284a, 0x284b, |  | ||||||
|         0x3000, 0x3001, 0x3002, 0x3003, 0x3008, 0x3009, 0x300a, 0x300b, 0x3040, 0x3041, 0x3042, |  | ||||||
|         0x3043, 0x3048, 0x3049, 0x304a, 0x304b, 0x3800, 0x3801, 0x3802, 0x3803, 0x3808, 0x3809, |  | ||||||
|         0x380a, 0x380b, 0x3840, 0x3841, 0x3842, 0x3843, 0x3848, 0x3849, 0x384a, 0x384b, |  | ||||||
|     }; |  | ||||||
|     static constexpr u32 ylut[] = { |  | ||||||
|         0x0000, 0x0004, 0x0010, 0x0014, 0x0020, 0x0024, 0x0030, 0x0034, 0x0080, 0x0084, 0x0090, |  | ||||||
|         0x0094, 0x00a0, 0x00a4, 0x00b0, 0x00b4, 0x0100, 0x0104, 0x0110, 0x0114, 0x0120, 0x0124, |  | ||||||
|         0x0130, 0x0134, 0x0180, 0x0184, 0x0190, 0x0194, 0x01a0, 0x01a4, 0x01b0, 0x01b4, 0x0200, |  | ||||||
|         0x0204, 0x0210, 0x0214, 0x0220, 0x0224, 0x0230, 0x0234, 0x0280, 0x0284, 0x0290, 0x0294, |  | ||||||
|         0x02a0, 0x02a4, 0x02b0, 0x02b4, 0x0300, 0x0304, 0x0310, 0x0314, 0x0320, 0x0324, 0x0330, |  | ||||||
|         0x0334, 0x0380, 0x0384, 0x0390, 0x0394, 0x03a0, 0x03a4, 0x03b0, 0x03b4, 0x0400, 0x0404, |  | ||||||
|         0x0410, 0x0414, 0x0420, 0x0424, 0x0430, 0x0434, 0x0480, 0x0484, 0x0490, 0x0494, 0x04a0, |  | ||||||
|         0x04a4, 0x04b0, 0x04b4, 0x0500, 0x0504, 0x0510, 0x0514, 0x0520, 0x0524, 0x0530, 0x0534, |  | ||||||
|         0x0580, 0x0584, 0x0590, 0x0594, 0x05a0, 0x05a4, 0x05b0, 0x05b4, 0x0600, 0x0604, 0x0610, |  | ||||||
|         0x0614, 0x0620, 0x0624, 0x0630, 0x0634, 0x0680, 0x0684, 0x0690, 0x0694, 0x06a0, 0x06a4, |  | ||||||
|         0x06b0, 0x06b4, 0x0700, 0x0704, 0x0710, 0x0714, 0x0720, 0x0724, 0x0730, 0x0734, 0x0780, |  | ||||||
|         0x0784, 0x0790, 0x0794, 0x07a0, 0x07a4, 0x07b0, 0x07b4, 0x0000, 0x0004, 0x0010, 0x0014, |  | ||||||
|         0x0020, 0x0024, 0x0030, 0x0034, 0x0080, 0x0084, 0x0090, 0x0094, 0x00a0, 0x00a4, 0x00b0, |  | ||||||
|         0x00b4, 0x0100, 0x0104, 0x0110, 0x0114, 0x0120, 0x0124, 0x0130, 0x0134, 0x0180, 0x0184, |  | ||||||
|         0x0190, 0x0194, 0x01a0, 0x01a4, 0x01b0, 0x01b4, 0x0200, 0x0204, 0x0210, 0x0214, 0x0220, |  | ||||||
|         0x0224, 0x0230, 0x0234, 0x0280, 0x0284, 0x0290, 0x0294, 0x02a0, 0x02a4, 0x02b0, 0x02b4, |  | ||||||
|         0x0300, 0x0304, 0x0310, 0x0314, 0x0320, 0x0324, 0x0330, 0x0334, 0x0380, 0x0384, 0x0390, |  | ||||||
|         0x0394, 0x03a0, 0x03a4, 0x03b0, 0x03b4, 0x0400, 0x0404, 0x0410, 0x0414, 0x0420, 0x0424, |  | ||||||
|         0x0430, 0x0434, 0x0480, 0x0484, 0x0490, 0x0494, 0x04a0, 0x04a4, 0x04b0, 0x04b4, 0x0500, |  | ||||||
|         0x0504, 0x0510, 0x0514, 0x0520, 0x0524, 0x0530, 0x0534, 0x0580, 0x0584, 0x0590, 0x0594, |  | ||||||
|         0x05a0, 0x05a4, 0x05b0, 0x05b4, 0x0600, 0x0604, 0x0610, 0x0614, 0x0620, 0x0624, 0x0630, |  | ||||||
|         0x0634, 0x0680, 0x0684, 0x0690, 0x0694, 0x06a0, 0x06a4, 0x06b0, 0x06b4, 0x0700, 0x0704, |  | ||||||
|         0x0710, 0x0714, 0x0720, 0x0724, 0x0730, 0x0734, 0x0780, 0x0784, 0x0790, 0x0794, 0x07a0, |  | ||||||
|         0x07a4, 0x07b0, 0x07b4, 0x0000, 0x0004, 0x0010, 0x0014, 0x0020, 0x0024, 0x0030, 0x0034, |  | ||||||
|         0x0080, 0x0084, 0x0090, 0x0094, 0x00a0, 0x00a4, 0x00b0, 0x00b4, 0x0100, 0x0104, 0x0110, |  | ||||||
|         0x0114, 0x0120, 0x0124, 0x0130, 0x0134, 0x0180, 0x0184, 0x0190, 0x0194, 0x01a0, 0x01a4, |  | ||||||
|         0x01b0, 0x01b4, 0x0200, 0x0204, 0x0210, 0x0214, 0x0220, 0x0224, 0x0230, 0x0234, 0x0280, |  | ||||||
|         0x0284, 0x0290, 0x0294, 0x02a0, 0x02a4, 0x02b0, 0x02b4, 0x0300, 0x0304, 0x0310, 0x0314, |  | ||||||
|         0x0320, 0x0324, 0x0330, 0x0334, 0x0380, 0x0384, 0x0390, 0x0394, 0x03a0, 0x03a4, 0x03b0, |  | ||||||
|         0x03b4, 0x0400, 0x0404, 0x0410, 0x0414, 0x0420, 0x0424, 0x0430, 0x0434, 0x0480, 0x0484, |  | ||||||
|         0x0490, 0x0494, 0x04a0, 0x04a4, 0x04b0, 0x04b4, 0x0500, 0x0504, 0x0510, 0x0514, 0x0520, |  | ||||||
|         0x0524, 0x0530, 0x0534, 0x0580, 0x0584, 0x0590, 0x0594, 0x05a0, 0x05a4, 0x05b0, 0x05b4, |  | ||||||
|         0x0600, 0x0604, 0x0610, 0x0614, 0x0620, 0x0624, 0x0630, 0x0634, 0x0680, 0x0684, 0x0690, |  | ||||||
|         0x0694, 0x06a0, 0x06a4, 0x06b0, 0x06b4, 0x0700, 0x0704, 0x0710, 0x0714, 0x0720, 0x0724, |  | ||||||
|         0x0730, 0x0734, 0x0780, 0x0784, 0x0790, 0x0794, 0x07a0, 0x07a4, 0x07b0, 0x07b4, |  | ||||||
|     }; |  | ||||||
|     return xlut[x % 128] + ylut[y % 128]; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static u32 GetMortonOffset128(u32 x, u32 y, u32 bytes_per_pixel) { |  | ||||||
|     // Calculates the offset of the position of the pixel in Morton order |  | ||||||
|     // Framebuffer images are split into 128x128 tiles. |  | ||||||
|  |  | ||||||
|     constexpr u32 block_height = 128; |  | ||||||
|     const u32 coarse_x = x & ~127; |  | ||||||
|  |  | ||||||
|     const u32 i = MortonInterleave128(x, y); |  | ||||||
|  |  | ||||||
|     const u32 offset = coarse_x * block_height; |  | ||||||
|  |  | ||||||
|     return (i + offset) * bytes_per_pixel; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride, | void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride, | ||||||
|                    u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, |                    u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, | ||||||
|                    u8* buffer, u8* addr) { |                    u8* buffer, u8* addr) { | ||||||
| @@ -286,23 +193,4 @@ void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stri | |||||||
|                                      tile_width_spacing, buffer, addr); |                                      tile_width_spacing, buffer, addr); | ||||||
| } | } | ||||||
|  |  | ||||||
| void MortonCopyPixels128(MortonSwizzleMode mode, u32 width, u32 height, u32 bytes_per_pixel, |  | ||||||
|                          u32 linear_bytes_per_pixel, u8* morton_data, u8* linear_data) { |  | ||||||
|     const bool morton_to_linear = mode == MortonSwizzleMode::MortonToLinear; |  | ||||||
|     u8* data_ptrs[2]; |  | ||||||
|     for (u32 y = 0; y < height; ++y) { |  | ||||||
|         for (u32 x = 0; x < width; ++x) { |  | ||||||
|             const u32 coarse_y = y & ~127; |  | ||||||
|             const u32 morton_offset = |  | ||||||
|                 GetMortonOffset128(x, y, bytes_per_pixel) + coarse_y * width * bytes_per_pixel; |  | ||||||
|             const u32 linear_pixel_index = (x + y * width) * linear_bytes_per_pixel; |  | ||||||
|  |  | ||||||
|             data_ptrs[morton_to_linear ? 1 : 0] = morton_data + morton_offset; |  | ||||||
|             data_ptrs[morton_to_linear ? 0 : 1] = &linear_data[linear_pixel_index]; |  | ||||||
|  |  | ||||||
|             std::memcpy(data_ptrs[0], data_ptrs[1], bytes_per_pixel); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| } // namespace VideoCore | } // namespace VideoCore | ||||||
|   | |||||||
| @@ -15,7 +15,4 @@ void MortonSwizzle(MortonSwizzleMode mode, VideoCore::Surface::PixelFormat forma | |||||||
|                    u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, |                    u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, | ||||||
|                    u8* buffer, u8* addr); |                    u8* buffer, u8* addr); | ||||||
|  |  | ||||||
| void MortonCopyPixels128(MortonSwizzleMode mode, u32 width, u32 height, u32 bytes_per_pixel, |  | ||||||
|                          u32 linear_bytes_per_pixel, u8* morton_data, u8* linear_data); |  | ||||||
|  |  | ||||||
| } // namespace VideoCore | } // namespace VideoCore | ||||||
|   | |||||||
| @@ -36,8 +36,7 @@ public: | |||||||
|     virtual ~RendererBase(); |     virtual ~RendererBase(); | ||||||
|  |  | ||||||
|     /// Swap buffers (render frame) |     /// Swap buffers (render frame) | ||||||
|     virtual void SwapBuffers( |     virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0; | ||||||
|         std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) = 0; |  | ||||||
|  |  | ||||||
|     /// Initialize the renderer |     /// Initialize the renderer | ||||||
|     virtual bool Init() = 0; |     virtual bool Init() = 0; | ||||||
|   | |||||||
| @@ -101,9 +101,7 @@ RendererOpenGL::RendererOpenGL(Core::Frontend::EmuWindow& emu_window, Core::Syst | |||||||
|  |  | ||||||
| RendererOpenGL::~RendererOpenGL() = default; | RendererOpenGL::~RendererOpenGL() = default; | ||||||
|  |  | ||||||
| void RendererOpenGL::SwapBuffers( | void RendererOpenGL::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | ||||||
|     std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) { |  | ||||||
|  |  | ||||||
|     system.GetPerfStats().EndSystemFrame(); |     system.GetPerfStats().EndSystemFrame(); | ||||||
|  |  | ||||||
|     // Maintain the rasterizer's state as a priority |     // Maintain the rasterizer's state as a priority | ||||||
| @@ -113,9 +111,9 @@ void RendererOpenGL::SwapBuffers( | |||||||
|  |  | ||||||
|     if (framebuffer) { |     if (framebuffer) { | ||||||
|         // If framebuffer is provided, reload it from memory to a texture |         // If framebuffer is provided, reload it from memory to a texture | ||||||
|         if (screen_info.texture.width != (GLsizei)framebuffer->get().width || |         if (screen_info.texture.width != static_cast<GLsizei>(framebuffer->width) || | ||||||
|             screen_info.texture.height != (GLsizei)framebuffer->get().height || |             screen_info.texture.height != static_cast<GLsizei>(framebuffer->height) || | ||||||
|             screen_info.texture.pixel_format != framebuffer->get().pixel_format) { |             screen_info.texture.pixel_format != framebuffer->pixel_format) { | ||||||
|             // Reallocate texture if the framebuffer size has changed. |             // Reallocate texture if the framebuffer size has changed. | ||||||
|             // This is expected to not happen very often and hence should not be a |             // This is expected to not happen very often and hence should not be a | ||||||
|             // performance problem. |             // performance problem. | ||||||
| @@ -149,43 +147,43 @@ void RendererOpenGL::SwapBuffers( | |||||||
|  * Loads framebuffer from emulated memory into the active OpenGL texture. |  * Loads framebuffer from emulated memory into the active OpenGL texture. | ||||||
|  */ |  */ | ||||||
| void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer) { | void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer) { | ||||||
|     const u32 bytes_per_pixel{Tegra::FramebufferConfig::BytesPerPixel(framebuffer.pixel_format)}; |  | ||||||
|     const u64 size_in_bytes{framebuffer.stride * framebuffer.height * bytes_per_pixel}; |  | ||||||
|     const VAddr framebuffer_addr{framebuffer.address + framebuffer.offset}; |  | ||||||
|  |  | ||||||
|     // Framebuffer orientation handling |     // Framebuffer orientation handling | ||||||
|     framebuffer_transform_flags = framebuffer.transform_flags; |     framebuffer_transform_flags = framebuffer.transform_flags; | ||||||
|     framebuffer_crop_rect = framebuffer.crop_rect; |     framebuffer_crop_rect = framebuffer.crop_rect; | ||||||
|  |  | ||||||
|     // Ensure no bad interactions with GL_UNPACK_ALIGNMENT, which by default |     const VAddr framebuffer_addr{framebuffer.address + framebuffer.offset}; | ||||||
|     // only allows rows to have a memory alignement of 4. |     if (rasterizer->AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride)) { | ||||||
|     ASSERT(framebuffer.stride % 4 == 0); |         return; | ||||||
|  |  | ||||||
|     if (!rasterizer->AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride)) { |  | ||||||
|         // Reset the screen info's display texture to its own permanent texture |  | ||||||
|         screen_info.display_texture = screen_info.texture.resource.handle; |  | ||||||
|  |  | ||||||
|         rasterizer->FlushRegion(ToCacheAddr(Memory::GetPointer(framebuffer_addr)), size_in_bytes); |  | ||||||
|  |  | ||||||
|         constexpr u32 linear_bpp = 4; |  | ||||||
|         VideoCore::MortonCopyPixels128(VideoCore::MortonSwizzleMode::MortonToLinear, |  | ||||||
|                                        framebuffer.width, framebuffer.height, bytes_per_pixel, |  | ||||||
|                                        linear_bpp, Memory::GetPointer(framebuffer_addr), |  | ||||||
|                                        gl_framebuffer_data.data()); |  | ||||||
|  |  | ||||||
|         glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(framebuffer.stride)); |  | ||||||
|  |  | ||||||
|         // Update existing texture |  | ||||||
|         // TODO: Test what happens on hardware when you change the framebuffer dimensions so that |  | ||||||
|         //       they differ from the LCD resolution. |  | ||||||
|         // TODO: Applications could theoretically crash yuzu here by specifying too large |  | ||||||
|         //       framebuffer sizes. We should make sure that this cannot happen. |  | ||||||
|         glTextureSubImage2D(screen_info.texture.resource.handle, 0, 0, 0, framebuffer.width, |  | ||||||
|                             framebuffer.height, screen_info.texture.gl_format, |  | ||||||
|                             screen_info.texture.gl_type, gl_framebuffer_data.data()); |  | ||||||
|  |  | ||||||
|         glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Reset the screen info's display texture to its own permanent texture | ||||||
|  |     screen_info.display_texture = screen_info.texture.resource.handle; | ||||||
|  |  | ||||||
|  |     const auto pixel_format{ | ||||||
|  |         VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)}; | ||||||
|  |     const u32 bytes_per_pixel{VideoCore::Surface::GetBytesPerPixel(pixel_format)}; | ||||||
|  |     const u64 size_in_bytes{framebuffer.stride * framebuffer.height * bytes_per_pixel}; | ||||||
|  |     const auto host_ptr{Memory::GetPointer(framebuffer_addr)}; | ||||||
|  |     rasterizer->FlushRegion(ToCacheAddr(host_ptr), size_in_bytes); | ||||||
|  |  | ||||||
|  |     // TODO(Rodrigo): Read this from HLE | ||||||
|  |     constexpr u32 block_height_log2 = 4; | ||||||
|  |     VideoCore::MortonSwizzle(VideoCore::MortonSwizzleMode::MortonToLinear, pixel_format, | ||||||
|  |                              framebuffer.stride, block_height_log2, framebuffer.height, 0, 1, 1, | ||||||
|  |                              gl_framebuffer_data.data(), host_ptr); | ||||||
|  |  | ||||||
|  |     glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(framebuffer.stride)); | ||||||
|  |  | ||||||
|  |     // Update existing texture | ||||||
|  |     // TODO: Test what happens on hardware when you change the framebuffer dimensions so that | ||||||
|  |     //       they differ from the LCD resolution. | ||||||
|  |     // TODO: Applications could theoretically crash yuzu here by specifying too large | ||||||
|  |     //       framebuffer sizes. We should make sure that this cannot happen. | ||||||
|  |     glTextureSubImage2D(screen_info.texture.resource.handle, 0, 0, 0, framebuffer.width, | ||||||
|  |                         framebuffer.height, screen_info.texture.gl_format, | ||||||
|  |                         screen_info.texture.gl_type, gl_framebuffer_data.data()); | ||||||
|  |  | ||||||
|  |     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -276,22 +274,29 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture, | |||||||
|     texture.height = framebuffer.height; |     texture.height = framebuffer.height; | ||||||
|     texture.pixel_format = framebuffer.pixel_format; |     texture.pixel_format = framebuffer.pixel_format; | ||||||
|  |  | ||||||
|  |     const auto pixel_format{ | ||||||
|  |         VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)}; | ||||||
|  |     const u32 bytes_per_pixel{VideoCore::Surface::GetBytesPerPixel(pixel_format)}; | ||||||
|  |     gl_framebuffer_data.resize(texture.width * texture.height * bytes_per_pixel); | ||||||
|  |  | ||||||
|     GLint internal_format; |     GLint internal_format; | ||||||
|     switch (framebuffer.pixel_format) { |     switch (framebuffer.pixel_format) { | ||||||
|     case Tegra::FramebufferConfig::PixelFormat::ABGR8: |     case Tegra::FramebufferConfig::PixelFormat::ABGR8: | ||||||
|         internal_format = GL_RGBA8; |         internal_format = GL_RGBA8; | ||||||
|         texture.gl_format = GL_RGBA; |         texture.gl_format = GL_RGBA; | ||||||
|         texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; |         texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; | ||||||
|         gl_framebuffer_data.resize(texture.width * texture.height * 4); |         break; | ||||||
|  |     case Tegra::FramebufferConfig::PixelFormat::RGB565: | ||||||
|  |         internal_format = GL_RGB565; | ||||||
|  |         texture.gl_format = GL_RGB; | ||||||
|  |         texture.gl_type = GL_UNSIGNED_SHORT_5_6_5; | ||||||
|         break; |         break; | ||||||
|     default: |     default: | ||||||
|         internal_format = GL_RGBA8; |         internal_format = GL_RGBA8; | ||||||
|         texture.gl_format = GL_RGBA; |         texture.gl_format = GL_RGBA; | ||||||
|         texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; |         texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV; | ||||||
|         gl_framebuffer_data.resize(texture.width * texture.height * 4); |         UNIMPLEMENTED_MSG("Unknown framebuffer pixel format: {}", | ||||||
|         LOG_CRITICAL(Render_OpenGL, "Unknown framebuffer pixel format: {}", |                           static_cast<u32>(framebuffer.pixel_format)); | ||||||
|                      static_cast<u32>(framebuffer.pixel_format)); |  | ||||||
|         UNREACHABLE(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     texture.resource.Release(); |     texture.resource.Release(); | ||||||
|   | |||||||
| @@ -43,14 +43,13 @@ struct ScreenInfo { | |||||||
|     TextureInfo texture; |     TextureInfo texture; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| class RendererOpenGL : public VideoCore::RendererBase { | class RendererOpenGL final : public VideoCore::RendererBase { | ||||||
| public: | public: | ||||||
|     explicit RendererOpenGL(Core::Frontend::EmuWindow& emu_window, Core::System& system); |     explicit RendererOpenGL(Core::Frontend::EmuWindow& emu_window, Core::System& system); | ||||||
|     ~RendererOpenGL() override; |     ~RendererOpenGL() override; | ||||||
|  |  | ||||||
|     /// Swap buffers (render frame) |     /// Swap buffers (render frame) | ||||||
|     void SwapBuffers( |     void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override; | ||||||
|         std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) override; |  | ||||||
|  |  | ||||||
|     /// Initialize the renderer |     /// Initialize the renderer | ||||||
|     bool Init() override; |     bool Init() override; | ||||||
|   | |||||||
| @@ -445,11 +445,12 @@ PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat | |||||||
|     switch (format) { |     switch (format) { | ||||||
|     case Tegra::FramebufferConfig::PixelFormat::ABGR8: |     case Tegra::FramebufferConfig::PixelFormat::ABGR8: | ||||||
|         return PixelFormat::ABGR8U; |         return PixelFormat::ABGR8U; | ||||||
|  |     case Tegra::FramebufferConfig::PixelFormat::RGB565: | ||||||
|  |         return PixelFormat::B5G6R5U; | ||||||
|     case Tegra::FramebufferConfig::PixelFormat::BGRA8: |     case Tegra::FramebufferConfig::PixelFormat::BGRA8: | ||||||
|         return PixelFormat::BGRA8; |         return PixelFormat::BGRA8; | ||||||
|     default: |     default: | ||||||
|         LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format)); |         UNIMPLEMENTED_MSG("Unimplemented format={}", static_cast<u32>(format)); | ||||||
|         UNREACHABLE(); |  | ||||||
|         return PixelFormat::ABGR8U; |         return PixelFormat::ABGR8U; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user