From 50c6030a8dc19454f558ba38562aed44b8c294f2 Mon Sep 17 00:00:00 2001
From: ReinUsesLisp <reinuseslisp@airmail.cc>
Date: Tue, 30 Jun 2020 04:23:03 -0300
Subject: [PATCH] video_core: Implement RG32_SINT render target

---
 src/video_core/gpu.h                                | 1 +
 src/video_core/morton.cpp                           | 2 ++
 src/video_core/renderer_opengl/gl_texture_cache.cpp | 1 +
 src/video_core/renderer_vulkan/maxwell_to_vk.cpp    | 1 +
 src/video_core/renderer_vulkan/vk_device.cpp        | 1 +
 src/video_core/surface.cpp                          | 2 ++
 src/video_core/surface.h                            | 5 +++++
 7 files changed, 13 insertions(+)

diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index a6f846f3c4..b0a2ad21b2 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -46,6 +46,7 @@ enum class RenderTargetFormat : u32 {
     RGBA16_UINT = 0xC9,
     RGBA16_FLOAT = 0xCA,
     RG32_FLOAT = 0xCB,
+    RG32_SINT = 0xCC,
     RG32_UINT = 0xCD,
     RGBX16_FLOAT = 0xCE,
     BGRA8_UNORM = 0xCF,
diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp
index 9e50aa11de..f932df53f2 100644
--- a/src/video_core/morton.cpp
+++ b/src/video_core/morton.cpp
@@ -70,6 +70,7 @@ static constexpr ConversionArray morton_to_linear_fns = {
     MortonCopy<true, PixelFormat::BGRA8>,
     MortonCopy<true, PixelFormat::RGBA32F>,
     MortonCopy<true, PixelFormat::RG32F>,
+    MortonCopy<true, PixelFormat::RG32I>,
     MortonCopy<true, PixelFormat::R32F>,
     MortonCopy<true, PixelFormat::R16F>,
     MortonCopy<true, PixelFormat::R16U>,
@@ -157,6 +158,7 @@ static constexpr ConversionArray linear_to_morton_fns = {
     MortonCopy<false, PixelFormat::BGRA8>,
     MortonCopy<false, PixelFormat::RGBA32F>,
     MortonCopy<false, PixelFormat::RG32F>,
+    MortonCopy<false, PixelFormat::RG32I>,
     MortonCopy<false, PixelFormat::R32F>,
     MortonCopy<false, PixelFormat::R16F>,
     MortonCopy<false, PixelFormat::R16U>,
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index ef17298940..1d7824324f 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -70,6 +70,7 @@ constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex_format
     {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE},                        // BGRA8
     {GL_RGBA32F, GL_RGBA, GL_FLOAT},                              // RGBA32F
     {GL_RG32F, GL_RG, GL_FLOAT},                                  // RG32F
+    {GL_RG32I, GL_RG_INTEGER, GL_INT},                            // RG32I
     {GL_R32F, GL_RED, GL_FLOAT},                                  // R32F
     {GL_R16F, GL_RED, GL_HALF_FLOAT},                             // R16F
     {GL_R16, GL_RED, GL_UNSIGNED_SHORT},                          // R16U
diff --git a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
index 43264ce145..4086d1bb69 100644
--- a/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
+++ b/src/video_core/renderer_vulkan/maxwell_to_vk.cpp
@@ -146,6 +146,7 @@ struct FormatTuple {
     {VK_FORMAT_B8G8R8A8_UNORM, Attachable},                     // BGRA8
     {VK_FORMAT_R32G32B32A32_SFLOAT, Attachable | Storage},      // RGBA32F
     {VK_FORMAT_R32G32_SFLOAT, Attachable | Storage},            // RG32F
+    {VK_FORMAT_R32G32_SINT, Attachable | Storage},              // RG32I
     {VK_FORMAT_R32_SFLOAT, Attachable | Storage},               // R32F
     {VK_FORMAT_R16_SFLOAT, Attachable | Storage},               // R16F
     {VK_FORMAT_R16_UNORM, Attachable | Storage},                // R16U
diff --git a/src/video_core/renderer_vulkan/vk_device.cpp b/src/video_core/renderer_vulkan/vk_device.cpp
index 06c6169dc2..e1128efe65 100644
--- a/src/video_core/renderer_vulkan/vk_device.cpp
+++ b/src/video_core/renderer_vulkan/vk_device.cpp
@@ -84,6 +84,7 @@ std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(
         VK_FORMAT_R32G32B32A32_SFLOAT,
         VK_FORMAT_R32G32B32A32_UINT,
         VK_FORMAT_R32G32_SFLOAT,
+        VK_FORMAT_R32G32_SINT,
         VK_FORMAT_R32G32_UINT,
         VK_FORMAT_R16G16B16A16_UINT,
         VK_FORMAT_R16G16B16A16_SNORM,
diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp
index 1f12163fed..13e598972c 100644
--- a/src/video_core/surface.cpp
+++ b/src/video_core/surface.cpp
@@ -106,6 +106,8 @@ PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format)
         return PixelFormat::RGBA16F;
     case Tegra::RenderTargetFormat::RG32_FLOAT:
         return PixelFormat::RG32F;
+    case Tegra::RenderTargetFormat::RG32_SINT:
+        return PixelFormat::RG32I;
     case Tegra::RenderTargetFormat::RG32_UINT:
         return PixelFormat::RG32UI;
     case Tegra::RenderTargetFormat::RGBX16_FLOAT:
diff --git a/src/video_core/surface.h b/src/video_core/surface.h
index 6999d9dc36..3e9dd797a1 100644
--- a/src/video_core/surface.h
+++ b/src/video_core/surface.h
@@ -44,6 +44,7 @@ enum class PixelFormat {
     BGRA8,
     RGBA32F,
     RG32F,
+    RG32I,
     R32F,
     R16F,
     R16U,
@@ -162,6 +163,7 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{
     0, // BGRA8
     0, // RGBA32F
     0, // RG32F
+    0, // RG32I
     0, // R32F
     0, // R16F
     0, // R16U
@@ -264,6 +266,7 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{
     1,  // BGRA8
     1,  // RGBA32F
     1,  // RG32F
+    1,  // RG32I
     1,  // R32F
     1,  // R16F
     1,  // R16U
@@ -358,6 +361,7 @@ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{
     1,  // BGRA8
     1,  // RGBA32F
     1,  // RG32F
+    1,  // RG32I
     1,  // R32F
     1,  // R16F
     1,  // R16U
@@ -452,6 +456,7 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
     32,  // BGRA8
     128, // RGBA32F
     64,  // RG32F
+    64,  // RG32I
     32,  // R32F
     16,  // R16F
     16,  // R16U