2018-06-22 01:36:01 +02:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
2018-03-19 22:45:22 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2018-06-22 01:36:01 +02:00
|
|
|
#include <map>
|
2018-03-19 22:45:22 +01:00
|
|
|
#include <memory>
|
2018-06-26 21:05:13 +02:00
|
|
|
#include <vector>
|
2018-08-06 05:30:18 +02:00
|
|
|
|
2018-03-19 22:45:22 +01:00
|
|
|
#include "common/common_types.h"
|
2018-08-22 04:04:54 +02:00
|
|
|
#include "common/hash.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
#include "common/math_util.h"
|
2018-06-24 15:50:08 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-08-23 21:44:41 +02:00
|
|
|
#include "video_core/rasterizer_cache.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-09-14 17:42:28 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.h"
|
2018-03-27 04:46:11 +02:00
|
|
|
#include "video_core/textures/texture.h"
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
class CachedSurface;
|
2018-03-19 22:45:22 +01:00
|
|
|
using Surface = std::shared_ptr<CachedSurface>;
|
|
|
|
using SurfaceSurfaceRect_Tuple = std::tuple<Surface, Surface, MathUtil::Rectangle<u32>>;
|
|
|
|
|
|
|
|
struct SurfaceParams {
|
|
|
|
enum class PixelFormat {
|
2018-08-10 17:44:43 +02:00
|
|
|
ABGR8U = 0,
|
|
|
|
ABGR8S = 1,
|
2018-08-20 14:26:54 +02:00
|
|
|
ABGR8UI = 2,
|
|
|
|
B5G6R5U = 3,
|
|
|
|
A2B10G10R10U = 4,
|
|
|
|
A1B5G5R5U = 5,
|
|
|
|
R8U = 6,
|
|
|
|
R8UI = 7,
|
|
|
|
RGBA16F = 8,
|
|
|
|
RGBA16U = 9,
|
|
|
|
RGBA16UI = 10,
|
|
|
|
R11FG11FB10F = 11,
|
|
|
|
RGBA32UI = 12,
|
|
|
|
DXT1 = 13,
|
|
|
|
DXT23 = 14,
|
|
|
|
DXT45 = 15,
|
|
|
|
DXN1 = 16, // This is also known as BC4
|
|
|
|
DXN2UNORM = 17,
|
|
|
|
DXN2SNORM = 18,
|
|
|
|
BC7U = 19,
|
2018-08-31 18:11:19 +02:00
|
|
|
BC6H_UF16 = 20,
|
|
|
|
BC6H_SF16 = 21,
|
|
|
|
ASTC_2D_4X4 = 22,
|
|
|
|
G8R8U = 23,
|
|
|
|
G8R8S = 24,
|
|
|
|
BGRA8 = 25,
|
|
|
|
RGBA32F = 26,
|
|
|
|
RG32F = 27,
|
|
|
|
R32F = 28,
|
|
|
|
R16F = 29,
|
|
|
|
R16U = 30,
|
|
|
|
R16S = 31,
|
|
|
|
R16UI = 32,
|
|
|
|
R16I = 33,
|
|
|
|
RG16 = 34,
|
|
|
|
RG16F = 35,
|
|
|
|
RG16UI = 36,
|
|
|
|
RG16I = 37,
|
|
|
|
RG16S = 38,
|
|
|
|
RGB32F = 39,
|
|
|
|
SRGBA8 = 40,
|
|
|
|
RG8U = 41,
|
|
|
|
RG8S = 42,
|
|
|
|
RG32UI = 43,
|
|
|
|
R32UI = 44,
|
2018-09-16 16:47:02 +02:00
|
|
|
ASTC_2D_8X8 = 45,
|
2018-04-19 01:11:14 +02:00
|
|
|
|
2018-07-02 19:42:04 +02:00
|
|
|
MaxColorFormat,
|
|
|
|
|
2018-08-16 03:24:04 +02:00
|
|
|
// Depth formats
|
2018-09-16 16:47:02 +02:00
|
|
|
Z32F = 46,
|
|
|
|
Z16 = 47,
|
2018-08-16 03:24:04 +02:00
|
|
|
|
|
|
|
MaxDepthFormat,
|
|
|
|
|
2018-07-02 19:42:04 +02:00
|
|
|
// DepthStencil formats
|
2018-09-16 16:47:02 +02:00
|
|
|
Z24S8 = 48,
|
|
|
|
S8Z24 = 49,
|
|
|
|
Z32FS8 = 50,
|
2018-07-02 19:42:04 +02:00
|
|
|
|
|
|
|
MaxDepthStencilFormat,
|
|
|
|
|
|
|
|
Max = MaxDepthStencilFormat,
|
2018-03-19 22:45:22 +01:00
|
|
|
Invalid = 255,
|
|
|
|
};
|
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
static constexpr std::size_t MaxPixelFormat = static_cast<std::size_t>(PixelFormat::Max);
|
2018-04-19 01:11:14 +02:00
|
|
|
|
2018-04-18 21:17:05 +02:00
|
|
|
enum class ComponentType {
|
|
|
|
Invalid = 0,
|
|
|
|
SNorm = 1,
|
|
|
|
UNorm = 2,
|
|
|
|
SInt = 3,
|
|
|
|
UInt = 4,
|
|
|
|
Float = 5,
|
|
|
|
};
|
|
|
|
|
2018-03-19 22:45:22 +01:00
|
|
|
enum class SurfaceType {
|
2018-04-18 20:54:10 +02:00
|
|
|
ColorTexture = 0,
|
|
|
|
Depth = 1,
|
|
|
|
DepthStencil = 2,
|
|
|
|
Fill = 3,
|
|
|
|
Invalid = 4,
|
2018-03-19 22:45:22 +01:00
|
|
|
};
|
|
|
|
|
2018-09-01 08:42:43 +02:00
|
|
|
enum class SurfaceTarget {
|
|
|
|
Texture1D,
|
|
|
|
Texture2D,
|
|
|
|
Texture3D,
|
|
|
|
Texture1DArray,
|
|
|
|
Texture2DArray,
|
|
|
|
TextureCubemap,
|
|
|
|
};
|
|
|
|
|
|
|
|
static SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_type) {
|
|
|
|
switch (texture_type) {
|
|
|
|
case Tegra::Texture::TextureType::Texture1D:
|
|
|
|
return SurfaceTarget::Texture1D;
|
|
|
|
case Tegra::Texture::TextureType::Texture2D:
|
|
|
|
case Tegra::Texture::TextureType::Texture2DNoMipmap:
|
|
|
|
return SurfaceTarget::Texture2D;
|
|
|
|
case Tegra::Texture::TextureType::Texture1DArray:
|
|
|
|
return SurfaceTarget::Texture1DArray;
|
|
|
|
case Tegra::Texture::TextureType::Texture2DArray:
|
|
|
|
return SurfaceTarget::Texture2DArray;
|
|
|
|
default:
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented texture_type={}", static_cast<u32>(texture_type));
|
|
|
|
UNREACHABLE();
|
|
|
|
return SurfaceTarget::Texture2D;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 23:55:41 +02:00
|
|
|
static std::string SurfaceTargetName(SurfaceTarget target) {
|
|
|
|
switch (target) {
|
|
|
|
case SurfaceTarget::Texture1D:
|
|
|
|
return "Texture1D";
|
|
|
|
case SurfaceTarget::Texture2D:
|
|
|
|
return "Texture2D";
|
|
|
|
case SurfaceTarget::Texture3D:
|
|
|
|
return "Texture3D";
|
|
|
|
case SurfaceTarget::Texture1DArray:
|
|
|
|
return "Texture1DArray";
|
|
|
|
case SurfaceTarget::Texture2DArray:
|
|
|
|
return "Texture2DArray";
|
|
|
|
case SurfaceTarget::TextureCubemap:
|
|
|
|
return "TextureCubemap";
|
|
|
|
default:
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast<u32>(target));
|
|
|
|
UNREACHABLE();
|
|
|
|
return fmt::format("TextureUnknown({})", static_cast<u32>(target));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 05:45:47 +02:00
|
|
|
/**
|
|
|
|
* Gets the compression factor for the specified PixelFormat. This applies to just the
|
|
|
|
* "compressed width" and "compressed height", not the overall compression factor of a
|
2018-06-22 01:36:01 +02:00
|
|
|
* compressed image. This is used for maintaining proper surface sizes for compressed
|
|
|
|
* texture formats.
|
2018-04-24 05:45:47 +02:00
|
|
|
*/
|
2018-06-22 01:36:01 +02:00
|
|
|
static constexpr u32 GetCompressionFactor(PixelFormat format) {
|
2018-03-27 04:46:11 +02:00
|
|
|
if (format == PixelFormat::Invalid)
|
|
|
|
return 0;
|
|
|
|
|
2018-04-24 05:45:47 +02:00
|
|
|
constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{
|
2018-08-10 17:44:43 +02:00
|
|
|
1, // ABGR8U
|
|
|
|
1, // ABGR8S
|
2018-08-20 14:26:54 +02:00
|
|
|
1, // ABGR8UI
|
2018-08-15 05:11:27 +02:00
|
|
|
1, // B5G6R5U
|
|
|
|
1, // A2B10G10R10U
|
|
|
|
1, // A1B5G5R5U
|
|
|
|
1, // R8U
|
2018-08-12 03:44:42 +02:00
|
|
|
1, // R8UI
|
2018-06-06 04:55:17 +02:00
|
|
|
1, // RGBA16F
|
2018-08-13 06:34:20 +02:00
|
|
|
1, // RGBA16U
|
2018-08-13 06:04:52 +02:00
|
|
|
1, // RGBA16UI
|
2018-06-06 04:57:16 +02:00
|
|
|
1, // R11FG11FB10F
|
2018-06-30 21:23:13 +02:00
|
|
|
1, // RGBA32UI
|
2018-04-24 05:45:47 +02:00
|
|
|
4, // DXT1
|
|
|
|
4, // DXT23
|
|
|
|
4, // DXT45
|
2018-06-02 20:17:09 +02:00
|
|
|
4, // DXN1
|
2018-08-10 01:15:32 +02:00
|
|
|
4, // DXN2UNORM
|
|
|
|
4, // DXN2SNORM
|
2018-07-05 00:22:48 +02:00
|
|
|
4, // BC7U
|
2018-08-31 18:11:19 +02:00
|
|
|
4, // BC6H_UF16
|
|
|
|
4, // BC6H_SF16
|
2018-06-26 21:05:13 +02:00
|
|
|
4, // ASTC_2D_4X4
|
2018-08-15 02:31:19 +02:00
|
|
|
1, // G8R8U
|
|
|
|
1, // G8R8S
|
2018-07-23 22:56:52 +02:00
|
|
|
1, // BGRA8
|
2018-07-23 23:12:16 +02:00
|
|
|
1, // RGBA32F
|
2018-07-24 01:10:00 +02:00
|
|
|
1, // RG32F
|
2018-07-24 05:21:31 +02:00
|
|
|
1, // R32F
|
2018-07-24 20:39:16 +02:00
|
|
|
1, // R16F
|
2018-08-15 05:11:27 +02:00
|
|
|
1, // R16U
|
2018-08-11 20:01:50 +02:00
|
|
|
1, // R16S
|
|
|
|
1, // R16UI
|
|
|
|
1, // R16I
|
2018-07-26 02:01:29 +02:00
|
|
|
1, // RG16
|
|
|
|
1, // RG16F
|
|
|
|
1, // RG16UI
|
|
|
|
1, // RG16I
|
|
|
|
1, // RG16S
|
2018-08-02 20:56:38 +02:00
|
|
|
1, // RGB32F
|
2018-07-25 16:52:39 +02:00
|
|
|
1, // SRGBA8
|
2018-08-13 05:02:34 +02:00
|
|
|
1, // RG8U
|
2018-08-10 18:07:37 +02:00
|
|
|
1, // RG8S
|
2018-08-13 14:55:16 +02:00
|
|
|
1, // RG32UI
|
|
|
|
1, // R32UI
|
2018-09-16 16:47:02 +02:00
|
|
|
4, // ASTC_2D_8X8
|
2018-07-04 17:42:33 +02:00
|
|
|
1, // Z32F
|
2018-07-14 05:25:11 +02:00
|
|
|
1, // Z16
|
2018-08-16 03:24:04 +02:00
|
|
|
1, // Z24S8
|
|
|
|
1, // S8Z24
|
2018-07-25 03:41:40 +02:00
|
|
|
1, // Z32FS8
|
2018-04-24 05:45:47 +02:00
|
|
|
}};
|
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
ASSERT(static_cast<std::size_t>(format) < compression_factor_table.size());
|
|
|
|
return compression_factor_table[static_cast<std::size_t>(format)];
|
2018-04-24 05:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr u32 GetFormatBpp(PixelFormat format) {
|
|
|
|
if (format == PixelFormat::Invalid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
|
2018-08-10 17:44:43 +02:00
|
|
|
32, // ABGR8U
|
|
|
|
32, // ABGR8S
|
2018-08-20 14:26:54 +02:00
|
|
|
32, // ABGR8UI
|
2018-08-15 05:11:27 +02:00
|
|
|
16, // B5G6R5U
|
|
|
|
32, // A2B10G10R10U
|
|
|
|
16, // A1B5G5R5U
|
|
|
|
8, // R8U
|
2018-08-12 03:44:42 +02:00
|
|
|
8, // R8UI
|
2018-05-31 04:24:07 +02:00
|
|
|
64, // RGBA16F
|
2018-08-13 06:34:20 +02:00
|
|
|
64, // RGBA16U
|
2018-08-13 06:04:52 +02:00
|
|
|
64, // RGBA16UI
|
2018-06-06 04:57:16 +02:00
|
|
|
32, // R11FG11FB10F
|
2018-06-30 21:23:13 +02:00
|
|
|
128, // RGBA32UI
|
2018-04-19 03:48:53 +02:00
|
|
|
64, // DXT1
|
|
|
|
128, // DXT23
|
|
|
|
128, // DXT45
|
2018-06-02 20:17:09 +02:00
|
|
|
64, // DXN1
|
2018-08-10 01:15:32 +02:00
|
|
|
128, // DXN2UNORM
|
|
|
|
128, // DXN2SNORM
|
2018-07-05 00:22:48 +02:00
|
|
|
128, // BC7U
|
2018-08-31 18:11:19 +02:00
|
|
|
128, // BC6H_UF16
|
|
|
|
128, // BC6H_SF16
|
2018-06-18 05:50:44 +02:00
|
|
|
32, // ASTC_2D_4X4
|
2018-08-15 02:31:19 +02:00
|
|
|
16, // G8R8U
|
|
|
|
16, // G8R8S
|
2018-07-23 22:56:52 +02:00
|
|
|
32, // BGRA8
|
2018-07-23 23:12:16 +02:00
|
|
|
128, // RGBA32F
|
2018-07-24 01:10:00 +02:00
|
|
|
64, // RG32F
|
2018-07-24 05:21:31 +02:00
|
|
|
32, // R32F
|
2018-07-24 20:39:16 +02:00
|
|
|
16, // R16F
|
2018-08-15 05:11:27 +02:00
|
|
|
16, // R16U
|
2018-08-11 20:01:50 +02:00
|
|
|
16, // R16S
|
|
|
|
16, // R16UI
|
|
|
|
16, // R16I
|
2018-07-26 02:01:29 +02:00
|
|
|
32, // RG16
|
|
|
|
32, // RG16F
|
|
|
|
32, // RG16UI
|
|
|
|
32, // RG16I
|
|
|
|
32, // RG16S
|
2018-08-02 20:56:38 +02:00
|
|
|
96, // RGB32F
|
2018-07-25 16:52:39 +02:00
|
|
|
32, // SRGBA8
|
2018-08-13 05:02:34 +02:00
|
|
|
16, // RG8U
|
2018-08-10 18:07:37 +02:00
|
|
|
16, // RG8S
|
2018-08-13 14:55:16 +02:00
|
|
|
64, // RG32UI
|
|
|
|
32, // R32UI
|
2018-09-16 16:47:02 +02:00
|
|
|
16, // ASTC_2D_8X8
|
2018-07-04 17:42:33 +02:00
|
|
|
32, // Z32F
|
2018-07-14 05:25:11 +02:00
|
|
|
16, // Z16
|
2018-08-16 03:24:04 +02:00
|
|
|
32, // Z24S8
|
|
|
|
32, // S8Z24
|
2018-07-25 03:41:40 +02:00
|
|
|
64, // Z32FS8
|
2018-04-24 05:45:47 +02:00
|
|
|
}};
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
ASSERT(static_cast<std::size_t>(format) < bpp_table.size());
|
|
|
|
return bpp_table[static_cast<std::size_t>(format)];
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
2018-07-21 20:36:32 +02:00
|
|
|
|
2018-04-24 05:45:47 +02:00
|
|
|
u32 GetFormatBpp() const {
|
2018-03-19 22:45:22 +01:00
|
|
|
return GetFormatBpp(pixel_format);
|
|
|
|
}
|
|
|
|
|
2018-07-02 19:42:04 +02:00
|
|
|
static PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format) {
|
|
|
|
switch (format) {
|
2018-07-03 20:05:13 +02:00
|
|
|
case Tegra::DepthFormat::S8_Z24_UNORM:
|
|
|
|
return PixelFormat::S8Z24;
|
2018-07-02 19:42:04 +02:00
|
|
|
case Tegra::DepthFormat::Z24_S8_UNORM:
|
|
|
|
return PixelFormat::Z24S8;
|
2018-07-04 17:42:33 +02:00
|
|
|
case Tegra::DepthFormat::Z32_FLOAT:
|
|
|
|
return PixelFormat::Z32F;
|
2018-07-14 05:25:11 +02:00
|
|
|
case Tegra::DepthFormat::Z16_UNORM:
|
|
|
|
return PixelFormat::Z16;
|
2018-07-25 03:41:40 +02:00
|
|
|
case Tegra::DepthFormat::Z32_S8_X24_FLOAT:
|
|
|
|
return PixelFormat::Z32FS8;
|
2018-07-02 19:42:04 +02:00
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
2018-07-02 19:42:04 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-24 05:47:33 +01:00
|
|
|
static PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) {
|
|
|
|
switch (format) {
|
2018-08-08 00:59:51 +02:00
|
|
|
// TODO (Hexagon12): Converting SRGBA to RGBA is a hack and doesn't completely correct the
|
|
|
|
// gamma.
|
2018-05-27 16:02:05 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA8_SRGB:
|
2018-07-25 16:52:39 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA8_UNORM:
|
2018-08-10 17:44:43 +02:00
|
|
|
return PixelFormat::ABGR8U;
|
|
|
|
case Tegra::RenderTargetFormat::RGBA8_SNORM:
|
|
|
|
return PixelFormat::ABGR8S;
|
2018-08-20 14:26:54 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA8_UINT:
|
|
|
|
return PixelFormat::ABGR8UI;
|
2018-09-10 05:41:37 +02:00
|
|
|
case Tegra::RenderTargetFormat::BGRA8_SRGB:
|
2018-07-23 22:56:52 +02:00
|
|
|
case Tegra::RenderTargetFormat::BGRA8_UNORM:
|
|
|
|
return PixelFormat::BGRA8;
|
2018-04-23 17:50:28 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
|
2018-08-15 05:11:27 +02:00
|
|
|
return PixelFormat::A2B10G10R10U;
|
2018-05-31 04:24:07 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA16_FLOAT:
|
|
|
|
return PixelFormat::RGBA16F;
|
2018-08-13 06:34:20 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA16_UNORM:
|
|
|
|
return PixelFormat::RGBA16U;
|
2018-08-13 06:04:52 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA16_UINT:
|
|
|
|
return PixelFormat::RGBA16UI;
|
2018-07-23 23:12:16 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA32_FLOAT:
|
|
|
|
return PixelFormat::RGBA32F;
|
2018-07-24 01:10:00 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG32_FLOAT:
|
|
|
|
return PixelFormat::RG32F;
|
2018-06-06 04:57:16 +02:00
|
|
|
case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
|
|
|
|
return PixelFormat::R11FG11FB10F;
|
2018-08-08 07:22:48 +02:00
|
|
|
case Tegra::RenderTargetFormat::B5G6R5_UNORM:
|
2018-08-15 05:11:27 +02:00
|
|
|
return PixelFormat::B5G6R5U;
|
2018-09-15 17:48:02 +02:00
|
|
|
case Tegra::RenderTargetFormat::BGR5A1_UNORM:
|
|
|
|
return PixelFormat::A1B5G5R5U;
|
2018-06-30 21:23:13 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA32_UINT:
|
|
|
|
return PixelFormat::RGBA32UI;
|
2018-07-24 23:47:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R8_UNORM:
|
2018-08-15 05:11:27 +02:00
|
|
|
return PixelFormat::R8U;
|
2018-08-12 03:44:42 +02:00
|
|
|
case Tegra::RenderTargetFormat::R8_UINT:
|
|
|
|
return PixelFormat::R8UI;
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG16_FLOAT:
|
|
|
|
return PixelFormat::RG16F;
|
|
|
|
case Tegra::RenderTargetFormat::RG16_UINT:
|
|
|
|
return PixelFormat::RG16UI;
|
|
|
|
case Tegra::RenderTargetFormat::RG16_SINT:
|
|
|
|
return PixelFormat::RG16I;
|
|
|
|
case Tegra::RenderTargetFormat::RG16_UNORM:
|
|
|
|
return PixelFormat::RG16;
|
|
|
|
case Tegra::RenderTargetFormat::RG16_SNORM:
|
|
|
|
return PixelFormat::RG16S;
|
2018-08-13 05:02:34 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG8_UNORM:
|
|
|
|
return PixelFormat::RG8U;
|
2018-08-10 18:07:37 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG8_SNORM:
|
|
|
|
return PixelFormat::RG8S;
|
2018-07-26 06:19:15 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_FLOAT:
|
|
|
|
return PixelFormat::R16F;
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_UNORM:
|
2018-08-15 05:11:27 +02:00
|
|
|
return PixelFormat::R16U;
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_SNORM:
|
|
|
|
return PixelFormat::R16S;
|
|
|
|
case Tegra::RenderTargetFormat::R16_UINT:
|
|
|
|
return PixelFormat::R16UI;
|
|
|
|
case Tegra::RenderTargetFormat::R16_SINT:
|
|
|
|
return PixelFormat::R16I;
|
2018-08-01 15:31:42 +02:00
|
|
|
case Tegra::RenderTargetFormat::R32_FLOAT:
|
|
|
|
return PixelFormat::R32F;
|
2018-08-13 14:55:16 +02:00
|
|
|
case Tegra::RenderTargetFormat::R32_UINT:
|
|
|
|
return PixelFormat::R32UI;
|
|
|
|
case Tegra::RenderTargetFormat::RG32_UINT:
|
|
|
|
return PixelFormat::RG32UI;
|
2018-03-24 05:47:33 +01:00
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
2018-03-24 05:47:33 +01:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 23:12:16 +02:00
|
|
|
static PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
|
|
|
|
Tegra::Texture::ComponentType component_type) {
|
2018-03-27 04:46:11 +02:00
|
|
|
// TODO(Subv): Properly implement this
|
|
|
|
switch (format) {
|
|
|
|
case Tegra::Texture::TextureFormat::A8R8G8B8:
|
2018-08-10 17:44:43 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::ABGR8U;
|
|
|
|
case Tegra::Texture::ComponentType::SNORM:
|
|
|
|
return PixelFormat::ABGR8S;
|
2018-08-20 14:26:54 +02:00
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::ABGR8UI;
|
2018-08-10 17:44:43 +02:00
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-04-19 01:11:14 +02:00
|
|
|
case Tegra::Texture::TextureFormat::B5G6R5:
|
2018-08-15 05:11:27 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::B5G6R5U;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-04-22 00:32:25 +02:00
|
|
|
case Tegra::Texture::TextureFormat::A2B10G10R10:
|
2018-08-15 05:11:27 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::A2B10G10R10U;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-05-27 16:02:05 +02:00
|
|
|
case Tegra::Texture::TextureFormat::A1B5G5R5:
|
2018-08-15 05:11:27 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::A1B5G5R5U;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-05-30 04:49:37 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R8:
|
2018-08-12 03:44:42 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
2018-08-15 05:11:27 +02:00
|
|
|
return PixelFormat::R8U;
|
2018-08-12 03:44:42 +02:00
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::R8UI;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-07-15 07:33:42 +02:00
|
|
|
case Tegra::Texture::TextureFormat::G8R8:
|
2018-08-15 02:31:19 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::G8R8U;
|
|
|
|
case Tegra::Texture::ComponentType::SNORM:
|
|
|
|
return PixelFormat::G8R8S;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-05-31 04:24:07 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R16_G16_B16_A16:
|
2018-08-15 05:08:37 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::RGBA16U;
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::RGBA16F;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-06-06 04:57:16 +02:00
|
|
|
case Tegra::Texture::TextureFormat::BF10GF11RF11:
|
2018-08-15 05:11:27 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::R11FG11FB10F;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-06-30 21:23:13 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R32_G32_B32_A32:
|
2018-07-23 23:12:16 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::RGBA32F;
|
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::RGBA32UI;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-07-24 01:10:00 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R32_G32:
|
2018-08-13 14:55:16 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::RG32F;
|
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::RG32UI;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-08-02 20:56:38 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R32_G32_B32:
|
2018-08-15 05:11:27 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::RGB32F;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-07-24 20:39:16 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R16:
|
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::R16F;
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
2018-08-15 05:11:27 +02:00
|
|
|
return PixelFormat::R16U;
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::Texture::ComponentType::SNORM:
|
|
|
|
return PixelFormat::R16S;
|
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::R16UI;
|
|
|
|
case Tegra::Texture::ComponentType::SINT:
|
|
|
|
return PixelFormat::R16I;
|
2018-07-24 20:39:16 +02:00
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-07-24 05:21:31 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R32:
|
2018-08-13 14:55:16 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::R32F;
|
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::R32UI;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-07-25 00:14:59 +02:00
|
|
|
case Tegra::Texture::TextureFormat::ZF32:
|
|
|
|
return PixelFormat::Z32F;
|
2018-08-15 01:10:37 +02:00
|
|
|
case Tegra::Texture::TextureFormat::Z16:
|
|
|
|
return PixelFormat::Z16;
|
2018-07-24 23:45:16 +02:00
|
|
|
case Tegra::Texture::TextureFormat::Z24S8:
|
|
|
|
return PixelFormat::Z24S8;
|
2018-03-27 04:46:11 +02:00
|
|
|
case Tegra::Texture::TextureFormat::DXT1:
|
|
|
|
return PixelFormat::DXT1;
|
2018-04-19 03:48:53 +02:00
|
|
|
case Tegra::Texture::TextureFormat::DXT23:
|
|
|
|
return PixelFormat::DXT23;
|
|
|
|
case Tegra::Texture::TextureFormat::DXT45:
|
|
|
|
return PixelFormat::DXT45;
|
2018-06-02 20:17:09 +02:00
|
|
|
case Tegra::Texture::TextureFormat::DXN1:
|
|
|
|
return PixelFormat::DXN1;
|
2018-08-09 18:57:13 +02:00
|
|
|
case Tegra::Texture::TextureFormat::DXN2:
|
2018-08-10 01:15:32 +02:00
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::DXN2UNORM;
|
|
|
|
case Tegra::Texture::ComponentType::SNORM:
|
|
|
|
return PixelFormat::DXN2SNORM;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-07-05 00:22:48 +02:00
|
|
|
case Tegra::Texture::TextureFormat::BC7U:
|
|
|
|
return PixelFormat::BC7U;
|
2018-08-31 18:11:19 +02:00
|
|
|
case Tegra::Texture::TextureFormat::BC6H_UF16:
|
|
|
|
return PixelFormat::BC6H_UF16;
|
|
|
|
case Tegra::Texture::TextureFormat::BC6H_SF16:
|
|
|
|
return PixelFormat::BC6H_SF16;
|
2018-06-18 05:50:44 +02:00
|
|
|
case Tegra::Texture::TextureFormat::ASTC_2D_4X4:
|
|
|
|
return PixelFormat::ASTC_2D_4X4;
|
2018-09-16 16:47:02 +02:00
|
|
|
case Tegra::Texture::TextureFormat::ASTC_2D_8X8:
|
|
|
|
return PixelFormat::ASTC_2D_8X8;
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::Texture::TextureFormat::R16_G16:
|
|
|
|
switch (component_type) {
|
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return PixelFormat::RG16F;
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return PixelFormat::RG16;
|
|
|
|
case Tegra::Texture::ComponentType::SNORM:
|
|
|
|
return PixelFormat::RG16S;
|
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return PixelFormat::RG16UI;
|
|
|
|
case Tegra::Texture::ComponentType::SINT:
|
|
|
|
return PixelFormat::RG16I;
|
|
|
|
}
|
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}",
|
|
|
|
static_cast<u32>(component_type));
|
|
|
|
UNREACHABLE();
|
2018-03-27 04:46:11 +02:00
|
|
|
default:
|
2018-07-23 23:12:16 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented format={}, component_type={}",
|
|
|
|
static_cast<u32>(format), static_cast<u32>(component_type));
|
2018-03-27 04:46:11 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2018-04-16 02:54:38 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 21:17:05 +02:00
|
|
|
static ComponentType ComponentTypeFromTexture(Tegra::Texture::ComponentType type) {
|
|
|
|
// TODO(Subv): Implement more component types
|
|
|
|
switch (type) {
|
|
|
|
case Tegra::Texture::ComponentType::UNORM:
|
|
|
|
return ComponentType::UNorm;
|
2018-07-23 23:12:16 +02:00
|
|
|
case Tegra::Texture::ComponentType::FLOAT:
|
|
|
|
return ComponentType::Float;
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::Texture::ComponentType::SNORM:
|
|
|
|
return ComponentType::SNorm;
|
|
|
|
case Tegra::Texture::ComponentType::UINT:
|
|
|
|
return ComponentType::UInt;
|
|
|
|
case Tegra::Texture::ComponentType::SINT:
|
|
|
|
return ComponentType::SInt;
|
2018-04-18 21:17:05 +02:00
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented component type={}", static_cast<u32>(type));
|
2018-04-18 21:17:05 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static ComponentType ComponentTypeFromRenderTarget(Tegra::RenderTargetFormat format) {
|
|
|
|
// TODO(Subv): Implement more render targets
|
|
|
|
switch (format) {
|
|
|
|
case Tegra::RenderTargetFormat::RGBA8_UNORM:
|
2018-05-27 16:02:05 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA8_SRGB:
|
2018-07-23 22:56:52 +02:00
|
|
|
case Tegra::RenderTargetFormat::BGRA8_UNORM:
|
2018-09-10 05:41:37 +02:00
|
|
|
case Tegra::RenderTargetFormat::BGRA8_SRGB:
|
2018-04-18 21:17:05 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
|
2018-07-24 23:47:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R8_UNORM:
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG16_UNORM:
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_UNORM:
|
2018-08-08 07:22:48 +02:00
|
|
|
case Tegra::RenderTargetFormat::B5G6R5_UNORM:
|
2018-09-15 17:48:02 +02:00
|
|
|
case Tegra::RenderTargetFormat::BGR5A1_UNORM:
|
2018-08-13 05:02:34 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG8_UNORM:
|
2018-08-13 06:34:20 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA16_UNORM:
|
2018-04-18 21:17:05 +02:00
|
|
|
return ComponentType::UNorm;
|
2018-08-10 17:44:43 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA8_SNORM:
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG16_SNORM:
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_SNORM:
|
2018-08-10 18:07:37 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG8_SNORM:
|
2018-07-26 02:01:29 +02:00
|
|
|
return ComponentType::SNorm;
|
2018-05-31 04:24:07 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA16_FLOAT:
|
2018-06-06 04:57:16 +02:00
|
|
|
case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
|
2018-07-23 23:12:16 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA32_FLOAT:
|
2018-07-24 01:10:00 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG32_FLOAT:
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG16_FLOAT:
|
2018-07-26 06:19:15 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_FLOAT:
|
2018-08-01 15:31:42 +02:00
|
|
|
case Tegra::RenderTargetFormat::R32_FLOAT:
|
2018-05-31 04:24:07 +02:00
|
|
|
return ComponentType::Float;
|
2018-06-30 21:23:13 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA32_UINT:
|
2018-08-13 06:04:52 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA16_UINT:
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG16_UINT:
|
2018-08-12 03:44:42 +02:00
|
|
|
case Tegra::RenderTargetFormat::R8_UINT:
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_UINT:
|
2018-08-13 14:55:16 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG32_UINT:
|
|
|
|
case Tegra::RenderTargetFormat::R32_UINT:
|
2018-08-20 14:26:54 +02:00
|
|
|
case Tegra::RenderTargetFormat::RGBA8_UINT:
|
2018-06-30 21:23:13 +02:00
|
|
|
return ComponentType::UInt;
|
2018-07-26 02:01:29 +02:00
|
|
|
case Tegra::RenderTargetFormat::RG16_SINT:
|
2018-08-11 20:01:50 +02:00
|
|
|
case Tegra::RenderTargetFormat::R16_SINT:
|
2018-07-26 02:01:29 +02:00
|
|
|
return ComponentType::SInt;
|
2018-04-18 21:17:05 +02:00
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
2018-04-18 21:17:05 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 23:42:29 +02:00
|
|
|
static PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) {
|
|
|
|
switch (format) {
|
|
|
|
case Tegra::FramebufferConfig::PixelFormat::ABGR8:
|
2018-08-10 17:44:43 +02:00
|
|
|
return PixelFormat::ABGR8U;
|
2018-06-24 23:42:29 +02:00
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
2018-06-24 23:42:29 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 19:42:04 +02:00
|
|
|
static ComponentType ComponentTypeFromDepthFormat(Tegra::DepthFormat format) {
|
|
|
|
switch (format) {
|
2018-07-14 05:25:11 +02:00
|
|
|
case Tegra::DepthFormat::Z16_UNORM:
|
2018-07-03 20:05:13 +02:00
|
|
|
case Tegra::DepthFormat::S8_Z24_UNORM:
|
2018-07-02 19:42:04 +02:00
|
|
|
case Tegra::DepthFormat::Z24_S8_UNORM:
|
|
|
|
return ComponentType::UNorm;
|
2018-07-04 17:42:33 +02:00
|
|
|
case Tegra::DepthFormat::Z32_FLOAT:
|
2018-07-25 03:41:40 +02:00
|
|
|
case Tegra::DepthFormat::Z32_S8_X24_FLOAT:
|
2018-07-04 17:42:33 +02:00
|
|
|
return ComponentType::Float;
|
2018-07-02 19:42:04 +02:00
|
|
|
default:
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
2018-07-02 19:42:04 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 04:46:11 +02:00
|
|
|
static SurfaceType GetFormatType(PixelFormat pixel_format) {
|
2018-09-15 15:21:06 +02:00
|
|
|
if (static_cast<std::size_t>(pixel_format) <
|
|
|
|
static_cast<std::size_t>(PixelFormat::MaxColorFormat)) {
|
2018-04-18 20:54:10 +02:00
|
|
|
return SurfaceType::ColorTexture;
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
if (static_cast<std::size_t>(pixel_format) <
|
|
|
|
static_cast<std::size_t>(PixelFormat::MaxDepthFormat)) {
|
2018-08-16 03:24:04 +02:00
|
|
|
return SurfaceType::Depth;
|
|
|
|
}
|
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
if (static_cast<std::size_t>(pixel_format) <
|
|
|
|
static_cast<std::size_t>(PixelFormat::MaxDepthStencilFormat)) {
|
2018-07-02 19:42:04 +02:00
|
|
|
return SurfaceType::DepthStencil;
|
|
|
|
}
|
|
|
|
|
2018-03-27 04:46:11 +02:00
|
|
|
// TODO(Subv): Implement the other formats
|
|
|
|
ASSERT(false);
|
2018-03-19 22:45:22 +01:00
|
|
|
|
|
|
|
return SurfaceType::Invalid;
|
|
|
|
}
|
|
|
|
|
2018-06-26 22:14:14 +02:00
|
|
|
/// Returns the rectangle corresponding to this surface
|
2018-06-26 21:05:13 +02:00
|
|
|
MathUtil::Rectangle<u32> GetRect() const;
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-09-14 17:33:55 +02:00
|
|
|
/// Returns the size of this surface as a 2D texture in bytes, adjusted for compression
|
|
|
|
std::size_t SizeInBytes2D() const {
|
2018-06-24 15:50:08 +02:00
|
|
|
const u32 compression_factor{GetCompressionFactor(pixel_format)};
|
2018-06-22 01:36:01 +02:00
|
|
|
ASSERT(width % compression_factor == 0);
|
|
|
|
ASSERT(height % compression_factor == 0);
|
|
|
|
return (width / compression_factor) * (height / compression_factor) *
|
2018-09-14 17:33:55 +02:00
|
|
|
GetFormatBpp(pixel_format) / CHAR_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the total size of this surface in bytes, adjusted for compression
|
|
|
|
std::size_t SizeInBytesTotal() const {
|
|
|
|
return SizeInBytes2D() * depth;
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2018-07-04 05:32:59 +02:00
|
|
|
/// Creates SurfaceParams from a texture configuration
|
2018-09-14 17:42:28 +02:00
|
|
|
static SurfaceParams CreateForTexture(const Tegra::Texture::FullTextureInfo& config,
|
|
|
|
const GLShader::SamplerEntry& entry);
|
2018-06-26 20:59:45 +02:00
|
|
|
|
2018-07-04 05:32:59 +02:00
|
|
|
/// Creates SurfaceParams from a framebuffer configuration
|
2018-09-15 15:21:06 +02:00
|
|
|
static SurfaceParams CreateForFramebuffer(std::size_t index);
|
2018-06-26 20:59:45 +02:00
|
|
|
|
2018-07-04 05:32:59 +02:00
|
|
|
/// Creates SurfaceParams for a depth buffer configuration
|
2018-07-21 20:29:36 +02:00
|
|
|
static SurfaceParams CreateForDepthBuffer(u32 zeta_width, u32 zeta_height,
|
|
|
|
Tegra::GPUVAddr zeta_address,
|
|
|
|
Tegra::DepthFormat format);
|
2018-07-04 05:32:59 +02:00
|
|
|
|
2018-08-06 05:30:18 +02:00
|
|
|
/// Checks if surfaces are compatible for caching
|
|
|
|
bool IsCompatibleSurface(const SurfaceParams& other) const {
|
2018-09-12 02:12:29 +02:00
|
|
|
return std::tie(pixel_format, type, width, height) ==
|
|
|
|
std::tie(other.pixel_format, other.type, other.width, other.height);
|
2018-08-06 05:30:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-28 03:35:15 +02:00
|
|
|
VAddr addr;
|
2018-06-26 20:59:45 +02:00
|
|
|
bool is_tiled;
|
|
|
|
u32 block_height;
|
|
|
|
PixelFormat pixel_format;
|
|
|
|
ComponentType component_type;
|
|
|
|
SurfaceType type;
|
|
|
|
u32 width;
|
|
|
|
u32 height;
|
2018-09-05 04:00:24 +02:00
|
|
|
u32 depth;
|
2018-06-26 21:05:13 +02:00
|
|
|
u32 unaligned_height;
|
2018-09-14 17:33:55 +02:00
|
|
|
std::size_t size_in_bytes_total;
|
|
|
|
std::size_t size_in_bytes_2d;
|
2018-09-01 08:42:43 +02:00
|
|
|
SurfaceTarget target;
|
2018-06-26 20:59:45 +02:00
|
|
|
};
|
|
|
|
|
2018-08-22 04:04:54 +02:00
|
|
|
}; // namespace OpenGL
|
|
|
|
|
|
|
|
/// Hashable variation of SurfaceParams, used for a key in the surface cache
|
|
|
|
struct SurfaceReserveKey : Common::HashableStruct<OpenGL::SurfaceParams> {
|
|
|
|
static SurfaceReserveKey Create(const OpenGL::SurfaceParams& params) {
|
|
|
|
SurfaceReserveKey res;
|
|
|
|
res.state = params;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<SurfaceReserveKey> {
|
2018-09-15 15:21:06 +02:00
|
|
|
std::size_t operator()(const SurfaceReserveKey& k) const {
|
2018-08-22 04:04:54 +02:00
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
class CachedSurface final {
|
|
|
|
public:
|
|
|
|
CachedSurface(const SurfaceParams& params);
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-08-28 03:35:15 +02:00
|
|
|
VAddr GetAddr() const {
|
2018-08-23 21:44:41 +02:00
|
|
|
return params.addr;
|
|
|
|
}
|
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
std::size_t GetSizeInBytes() const {
|
2018-09-14 17:33:55 +02:00
|
|
|
return params.size_in_bytes_total;
|
2018-08-23 21:44:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
const OGLTexture& Texture() const {
|
|
|
|
return texture;
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2018-09-01 08:42:43 +02:00
|
|
|
GLenum Target() const {
|
|
|
|
return gl_target;
|
|
|
|
}
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
static constexpr unsigned int GetGLBytesPerPixel(SurfaceParams::PixelFormat format) {
|
|
|
|
if (format == SurfaceParams::PixelFormat::Invalid)
|
2018-03-27 04:46:11 +02:00
|
|
|
return 0;
|
|
|
|
|
2018-04-25 00:01:06 +02:00
|
|
|
return SurfaceParams::GetFormatBpp(format) / CHAR_BIT;
|
2018-03-19 22:45:22 +01:00
|
|
|
}
|
|
|
|
|
2018-06-22 01:36:01 +02:00
|
|
|
const SurfaceParams& GetSurfaceParams() const {
|
|
|
|
return params;
|
|
|
|
}
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-03-23 04:06:54 +01:00
|
|
|
// Read/Write data in Switch memory to/from gl_buffer
|
2018-06-22 01:36:01 +02:00
|
|
|
void LoadGLBuffer();
|
|
|
|
void FlushGLBuffer();
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-09-01 08:42:43 +02:00
|
|
|
// Upload data in gl_buffer to this surface's texture
|
2018-06-22 01:36:01 +02:00
|
|
|
void UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle);
|
|
|
|
|
|
|
|
private:
|
|
|
|
OGLTexture texture;
|
2018-06-26 21:05:13 +02:00
|
|
|
std::vector<u8> gl_buffer;
|
2018-06-22 01:36:01 +02:00
|
|
|
SurfaceParams params;
|
2018-09-01 08:42:43 +02:00
|
|
|
GLenum gl_target;
|
2018-03-19 22:45:22 +01:00
|
|
|
};
|
|
|
|
|
2018-08-23 21:44:41 +02:00
|
|
|
class RasterizerCacheOpenGL final : public RasterizerCache<Surface> {
|
2018-03-19 22:45:22 +01:00
|
|
|
public:
|
|
|
|
RasterizerCacheOpenGL();
|
|
|
|
|
2018-06-26 22:14:14 +02:00
|
|
|
/// Get a surface based on the texture configuration
|
2018-09-14 17:42:28 +02:00
|
|
|
Surface GetTextureSurface(const Tegra::Texture::FullTextureInfo& config,
|
|
|
|
const GLShader::SamplerEntry& entry);
|
2018-06-26 22:14:14 +02:00
|
|
|
|
2018-09-10 01:01:21 +02:00
|
|
|
/// Get the depth surface based on the framebuffer configuration
|
|
|
|
Surface GetDepthBufferSurface(bool preserve_contents);
|
|
|
|
|
|
|
|
/// Get the color surface based on the framebuffer configuration and the specified render target
|
2018-09-15 15:21:06 +02:00
|
|
|
Surface GetColorBufferSurface(std::size_t index, bool preserve_contents);
|
2018-06-26 22:14:14 +02:00
|
|
|
|
2018-07-21 20:36:32 +02:00
|
|
|
/// Flushes the surface to Switch memory
|
|
|
|
void FlushSurface(const Surface& surface);
|
2018-06-26 22:14:14 +02:00
|
|
|
|
2018-08-28 03:35:15 +02:00
|
|
|
/// Tries to find a framebuffer using on the provided CPU address
|
|
|
|
Surface TryFindFramebufferSurface(VAddr addr) const;
|
2018-03-19 22:45:22 +01:00
|
|
|
|
|
|
|
private:
|
2018-06-26 22:14:14 +02:00
|
|
|
void LoadSurface(const Surface& surface);
|
2018-08-20 22:18:51 +02:00
|
|
|
Surface GetSurface(const SurfaceParams& params, bool preserve_contents = true);
|
2018-03-19 22:45:22 +01:00
|
|
|
|
2018-08-31 02:08:43 +02:00
|
|
|
/// Gets an uncached surface, creating it if need be
|
|
|
|
Surface GetUncachedSurface(const SurfaceParams& params);
|
|
|
|
|
2018-07-21 22:04:01 +02:00
|
|
|
/// Recreates a surface with new parameters
|
2018-09-14 17:33:55 +02:00
|
|
|
Surface RecreateSurface(const Surface& old_surface, const SurfaceParams& new_params);
|
2018-07-21 22:04:01 +02:00
|
|
|
|
2018-08-22 04:04:54 +02:00
|
|
|
/// Reserves a unique surface that can be reused later
|
|
|
|
void ReserveSurface(const Surface& surface);
|
|
|
|
|
|
|
|
/// Tries to get a reserved surface for the specified parameters
|
|
|
|
Surface TryGetReservedSurface(const SurfaceParams& params);
|
|
|
|
|
|
|
|
/// The surface reserve is a "backup" cache, this is where we put unique surfaces that have
|
|
|
|
/// previously been used. This is to prevent surfaces from being constantly created and
|
|
|
|
/// destroyed when used with different surface parameters.
|
|
|
|
std::unordered_map<SurfaceReserveKey, Surface> surface_reserve;
|
|
|
|
|
2018-03-19 22:45:22 +01:00
|
|
|
OGLFramebuffer read_framebuffer;
|
|
|
|
OGLFramebuffer draw_framebuffer;
|
2018-09-08 07:04:47 +02:00
|
|
|
|
|
|
|
/// Use a Pixel Buffer Object to download the previous texture and then upload it to the new one
|
|
|
|
/// using the new format.
|
|
|
|
OGLBuffer copy_pbo;
|
2018-03-19 22:45:22 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|