From 55d272efe66a30307567db10f32c623364f58848 Mon Sep 17 00:00:00 2001
From: FearlessTobi <thm.frey@gmail.com>
Date: Sun, 22 Sep 2019 01:40:46 +0200
Subject: [PATCH 1/3] video_core: Implement RGBX16F PixelFormat

---
 src/video_core/gpu.cpp                        |  1 +
 src/video_core/gpu.h                          |  1 +
 src/video_core/morton.cpp                     |  2 +
 .../renderer_opengl/gl_texture_cache.cpp      |  1 +
 .../renderer_vulkan/maxwell_to_vk.cpp         |  1 +
 src/video_core/surface.cpp                    |  3 ++
 src/video_core/surface.h                      | 50 +++++++++++--------
 7 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index 2c47541cb3..76cfe81070 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -122,6 +122,7 @@ u32 RenderTargetBytesPerPixel(RenderTargetFormat format) {
     case RenderTargetFormat::RGBA16_UINT:
     case RenderTargetFormat::RGBA16_UNORM:
     case RenderTargetFormat::RGBA16_FLOAT:
+    case RenderTargetFormat::RGBX16_FLOAT:
     case RenderTargetFormat::RG32_FLOAT:
     case RenderTargetFormat::RG32_UINT:
         return 8;
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index 78bc0601a0..29fa8e95bd 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -42,6 +42,7 @@ enum class RenderTargetFormat : u32 {
     RGBA16_FLOAT = 0xCA,
     RG32_FLOAT = 0xCB,
     RG32_UINT = 0xCD,
+    RGBX16_FLOAT = 0xCE,
     BGRA8_UNORM = 0xCF,
     BGRA8_SRGB = 0xD0,
     RGB10_A2_UNORM = 0xD1,
diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp
index 084f85e670..ab71870ab6 100644
--- a/src/video_core/morton.cpp
+++ b/src/video_core/morton.cpp
@@ -83,6 +83,7 @@ static constexpr ConversionArray morton_to_linear_fns = {
     MortonCopy<true, PixelFormat::RG8U>,
     MortonCopy<true, PixelFormat::RG8S>,
     MortonCopy<true, PixelFormat::RG32UI>,
+    MortonCopy<true, PixelFormat::RGBX16F>,
     MortonCopy<true, PixelFormat::R32UI>,
     MortonCopy<true, PixelFormat::ASTC_2D_8X8>,
     MortonCopy<true, PixelFormat::ASTC_2D_8X5>,
@@ -151,6 +152,7 @@ static constexpr ConversionArray linear_to_morton_fns = {
     MortonCopy<false, PixelFormat::RG8U>,
     MortonCopy<false, PixelFormat::RG8S>,
     MortonCopy<false, PixelFormat::RG32UI>,
+    MortonCopy<false, PixelFormat::RGBX16F>,
     MortonCopy<false, PixelFormat::R32UI>,
     nullptr,
     nullptr,
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index 4f135fe030..5b81af37fc 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -97,6 +97,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format
     {GL_RG8, GL_RG, GL_UNSIGNED_BYTE, ComponentType::UNorm, false},            // RG8U
     {GL_RG8, GL_RG, GL_BYTE, ComponentType::SNorm, false},                     // RG8S
     {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false},   // RG32UI
+    {GL_RGB16F, GL_RGBA16, GL_HALF_FLOAT, ComponentType::Float, false},       // RGBX16F TODO
     {GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false},   // R32UI
     {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false},        // ASTC_2D_8X8
     {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false},        // ASTC_2D_8X5
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
index 0bbbf68510..3c5acda3e8 100644
--- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
+++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
@@ -143,6 +143,7 @@ static constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex
     {vk::Format::eUndefined, ComponentType::Invalid, false},           // RG8U
     {vk::Format::eUndefined, ComponentType::Invalid, false},           // RG8S
     {vk::Format::eUndefined, ComponentType::Invalid, false},           // RG32UI
+    {vk::Format::eUndefined, ComponentType::Invalid, false},           // RGBX16F
     {vk::Format::eUndefined, ComponentType::Invalid, false},           // R32UI
     {vk::Format::eUndefined, ComponentType::Invalid, false},           // ASTC_2D_8X8
     {vk::Format::eUndefined, ComponentType::Invalid, false},           // ASTC_2D_8X5
diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp
index 53d0142cb1..250afc6d6a 100644
--- a/src/video_core/surface.cpp
+++ b/src/video_core/surface.cpp
@@ -159,6 +159,8 @@ PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format)
         return PixelFormat::R32UI;
     case Tegra::RenderTargetFormat::RG32_UINT:
         return PixelFormat::RG32UI;
+    case Tegra::RenderTargetFormat::RGBX16_FLOAT:
+        return PixelFormat::RGBX16F;
     default:
         LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
         UNREACHABLE();
@@ -415,6 +417,7 @@ ComponentType ComponentTypeFromRenderTarget(Tegra::RenderTargetFormat format) {
     case Tegra::RenderTargetFormat::RG8_SNORM:
         return ComponentType::SNorm;
     case Tegra::RenderTargetFormat::RGBA16_FLOAT:
+    case Tegra::RenderTargetFormat::RGBX16_FLOAT:
     case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
     case Tegra::RenderTargetFormat::RGBA32_FLOAT:
     case Tegra::RenderTargetFormat::RG32_FLOAT:
diff --git a/src/video_core/surface.h b/src/video_core/surface.h
index 19268b7cd5..1e1c432a58 100644
--- a/src/video_core/surface.h
+++ b/src/video_core/surface.h
@@ -57,36 +57,37 @@ enum class PixelFormat {
     RG8U = 39,
     RG8S = 40,
     RG32UI = 41,
-    R32UI = 42,
-    ASTC_2D_8X8 = 43,
-    ASTC_2D_8X5 = 44,
-    ASTC_2D_5X4 = 45,
-    BGRA8_SRGB = 46,
-    DXT1_SRGB = 47,
-    DXT23_SRGB = 48,
-    DXT45_SRGB = 49,
-    BC7U_SRGB = 50,
-    ASTC_2D_4X4_SRGB = 51,
-    ASTC_2D_8X8_SRGB = 52,
-    ASTC_2D_8X5_SRGB = 53,
-    ASTC_2D_5X4_SRGB = 54,
-    ASTC_2D_5X5 = 55,
-    ASTC_2D_5X5_SRGB = 56,
-    ASTC_2D_10X8 = 57,
-    ASTC_2D_10X8_SRGB = 58,
+    RGBX16F = 42,
+    R32UI = 43,
+    ASTC_2D_8X8 = 44,
+    ASTC_2D_8X5 = 45,
+    ASTC_2D_5X4 = 46,
+    BGRA8_SRGB = 47,
+    DXT1_SRGB = 48,
+    DXT23_SRGB = 49,
+    DXT45_SRGB = 50,
+    BC7U_SRGB = 51,
+    ASTC_2D_4X4_SRGB = 52,
+    ASTC_2D_8X8_SRGB = 53,
+    ASTC_2D_8X5_SRGB = 54,
+    ASTC_2D_5X4_SRGB = 55,
+    ASTC_2D_5X5 = 56,
+    ASTC_2D_5X5_SRGB = 57,
+    ASTC_2D_10X8 = 58,
+    ASTC_2D_10X8_SRGB = 59,
 
     MaxColorFormat,
 
     // Depth formats
-    Z32F = 59,
-    Z16 = 60,
+    Z32F = 60,
+    Z16 = 61,
 
     MaxDepthFormat,
 
     // DepthStencil formats
-    Z24S8 = 61,
-    S8Z24 = 62,
-    Z32FS8 = 63,
+    Z24S8 = 62,
+    S8Z24 = 63,
+    Z32FS8 = 64,
 
     MaxDepthStencilFormat,
 
@@ -166,6 +167,7 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{
     0, // RG8U
     0, // RG8S
     0, // RG32UI
+    0, // RGBX16F
     0, // R32UI
     2, // ASTC_2D_8X8
     2, // ASTC_2D_8X5
@@ -249,6 +251,7 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{
     1,  // RG8U
     1,  // RG8S
     1,  // RG32UI
+    1,  // RGBX16F
     1,  // R32UI
     8,  // ASTC_2D_8X8
     8,  // ASTC_2D_8X5
@@ -324,6 +327,7 @@ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{
     1, // RG8U
     1, // RG8S
     1, // RG32UI
+    1, // RGBX16F
     1, // R32UI
     8, // ASTC_2D_8X8
     5, // ASTC_2D_8X5
@@ -399,6 +403,7 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
     16,  // RG8U
     16,  // RG8S
     64,  // RG32UI
+    64,  // RGBX16F
     32,  // R32UI
     128, // ASTC_2D_8X8
     128, // ASTC_2D_8X5
@@ -489,6 +494,7 @@ constexpr std::array<SurfaceCompression, MaxPixelFormat> compression_type_table
     SurfaceCompression::None,       // RG8U
     SurfaceCompression::None,       // RG8S
     SurfaceCompression::None,       // RG32UI
+    SurfaceCompression::None,       // RGBX16F
     SurfaceCompression::None,       // R32UI
     SurfaceCompression::Converted,  // ASTC_2D_8X8
     SurfaceCompression::Converted,  // ASTC_2D_8X5

From 366e9003763457cce77fb9959042e8bf5acaf8fe Mon Sep 17 00:00:00 2001
From: FearlessTobi <thm.frey@gmail.com>
Date: Sun, 22 Sep 2019 02:18:57 +0200
Subject: [PATCH 2/3] fermi_2d: Lower surface copy log severity to DEBUG

---
 src/video_core/engines/fermi_2d.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp
index 98a8b53374..20672f70e6 100644
--- a/src/video_core/engines/fermi_2d.cpp
+++ b/src/video_core/engines/fermi_2d.cpp
@@ -29,7 +29,7 @@ void Fermi2D::CallMethod(const GPU::MethodCall& method_call) {
 }
 
 void Fermi2D::HandleSurfaceCopy() {
-    LOG_WARNING(HW_GPU, "Requested a surface copy with operation {}",
+    LOG_DEBUG(HW_GPU, "Requested a surface copy with operation {}",
                 static_cast<u32>(regs.operation));
 
     // TODO(Subv): Only raw copies are implemented.

From 01fc969a5f5427f22cd8260b2e38fb4fc607265a Mon Sep 17 00:00:00 2001
From: FearlessTobi <thm.frey@gmail.com>
Date: Sun, 22 Sep 2019 02:21:56 +0200
Subject: [PATCH 3/3] Fix clang-format

---
 src/video_core/engines/fermi_2d.cpp                 | 2 +-
 src/video_core/renderer_opengl/gl_texture_cache.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp
index 20672f70e6..7ff44f06d2 100644
--- a/src/video_core/engines/fermi_2d.cpp
+++ b/src/video_core/engines/fermi_2d.cpp
@@ -30,7 +30,7 @@ void Fermi2D::CallMethod(const GPU::MethodCall& method_call) {
 
 void Fermi2D::HandleSurfaceCopy() {
     LOG_DEBUG(HW_GPU, "Requested a surface copy with operation {}",
-                static_cast<u32>(regs.operation));
+              static_cast<u32>(regs.operation));
 
     // TODO(Subv): Only raw copies are implemented.
     ASSERT(regs.operation == Operation::SrcCopy);
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index 5b81af37fc..173b76c4ed 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -97,7 +97,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format
     {GL_RG8, GL_RG, GL_UNSIGNED_BYTE, ComponentType::UNorm, false},            // RG8U
     {GL_RG8, GL_RG, GL_BYTE, ComponentType::SNorm, false},                     // RG8S
     {GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false},   // RG32UI
-    {GL_RGB16F, GL_RGBA16, GL_HALF_FLOAT, ComponentType::Float, false},       // RGBX16F TODO
+    {GL_RGB16F, GL_RGBA16, GL_HALF_FLOAT, ComponentType::Float, false},        // RGBX16F
     {GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, ComponentType::UInt, false},   // R32UI
     {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false},        // ASTC_2D_8X8
     {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false},        // ASTC_2D_8X5