Merge pull request #570 from bunnei/astc
gl_rasterizer: Implement texture format ASTC_2D_4X4.
This commit is contained in:
commit
0e13d9cb7b
6 changed files with 1709 additions and 1 deletions
|
@ -41,6 +41,8 @@ add_library(video_core STATIC
|
||||||
renderer_opengl/maxwell_to_gl.h
|
renderer_opengl/maxwell_to_gl.h
|
||||||
renderer_opengl/renderer_opengl.cpp
|
renderer_opengl/renderer_opengl.cpp
|
||||||
renderer_opengl/renderer_opengl.h
|
renderer_opengl/renderer_opengl.h
|
||||||
|
textures/astc.cpp
|
||||||
|
textures/astc.h
|
||||||
textures/decoders.cpp
|
textures/decoders.cpp
|
||||||
textures/decoders.h
|
textures/decoders.h
|
||||||
textures/texture.h
|
textures/texture.h
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
#include "video_core/engines/maxwell_3d.h"
|
||||||
#include "video_core/renderer_opengl/gl_rasterizer_cache.h"
|
#include "video_core/renderer_opengl/gl_rasterizer_cache.h"
|
||||||
#include "video_core/renderer_opengl/gl_state.h"
|
#include "video_core/renderer_opengl/gl_state.h"
|
||||||
|
#include "video_core/textures/astc.h"
|
||||||
#include "video_core/textures/decoders.h"
|
#include "video_core/textures/decoders.h"
|
||||||
#include "video_core/utils.h"
|
#include "video_core/utils.h"
|
||||||
#include "video_core/video_core.h"
|
#include "video_core/video_core.h"
|
||||||
|
@ -55,6 +56,7 @@ static constexpr std::array<FormatTuple, SurfaceParams::MaxPixelFormat> tex_form
|
||||||
{GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, true}, // DXT23
|
{GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, true}, // DXT23
|
||||||
{GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, true}, // DXT45
|
{GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, true}, // DXT45
|
||||||
{GL_COMPRESSED_RED_RGTC1, GL_RED, GL_UNSIGNED_INT_8_8_8_8, true}, // DXN1
|
{GL_COMPRESSED_RED_RGTC1, GL_RED, GL_UNSIGNED_INT_8_8_8_8, true}, // DXN1
|
||||||
|
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, false}, // ASTC_2D_4X4
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) {
|
static const FormatTuple& GetFormatTuple(PixelFormat pixel_format, ComponentType component_type) {
|
||||||
|
@ -86,6 +88,23 @@ static u16 GetResolutionScaleFactor() {
|
||||||
: Settings::values.resolution_factor);
|
: Settings::values.resolution_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ConvertASTCToRGBA8(std::vector<u8>& data, PixelFormat format, u32 width, u32 height) {
|
||||||
|
u32 block_width{};
|
||||||
|
u32 block_height{};
|
||||||
|
|
||||||
|
switch (format) {
|
||||||
|
case PixelFormat::ASTC_2D_4X4:
|
||||||
|
block_width = 4;
|
||||||
|
block_height = 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NGLOG_CRITICAL(HW_GPU, "Unhandled format: {}", static_cast<u32>(format));
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
data = Tegra::Texture::ASTC::Decompress(data, width, height, block_width, block_height);
|
||||||
|
}
|
||||||
|
|
||||||
template <bool morton_to_gl, PixelFormat format>
|
template <bool morton_to_gl, PixelFormat format>
|
||||||
void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, Tegra::GPUVAddr base,
|
void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, Tegra::GPUVAddr base,
|
||||||
Tegra::GPUVAddr start, Tegra::GPUVAddr end) {
|
Tegra::GPUVAddr start, Tegra::GPUVAddr end) {
|
||||||
|
@ -97,6 +116,12 @@ void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, Tegra::
|
||||||
auto data = Tegra::Texture::UnswizzleTexture(
|
auto data = Tegra::Texture::UnswizzleTexture(
|
||||||
*gpu.memory_manager->GpuToCpuAddress(base),
|
*gpu.memory_manager->GpuToCpuAddress(base),
|
||||||
SurfaceParams::TextureFormatFromPixelFormat(format), stride, height, block_height);
|
SurfaceParams::TextureFormatFromPixelFormat(format), stride, height, block_height);
|
||||||
|
|
||||||
|
if (SurfaceParams::IsFormatASTC(format)) {
|
||||||
|
// ASTC formats are converted to RGBA8 in software, as most PC GPUs do not support this
|
||||||
|
ConvertASTCToRGBA8(data, format, stride, height);
|
||||||
|
}
|
||||||
|
|
||||||
std::memcpy(gl_buffer, data.data(), data.size());
|
std::memcpy(gl_buffer, data.data(), data.size());
|
||||||
} else {
|
} else {
|
||||||
// TODO(bunnei): Assumes the default rendering GOB size of 16 (128 lines). We should check
|
// TODO(bunnei): Assumes the default rendering GOB size of 16 (128 lines). We should check
|
||||||
|
@ -118,7 +143,7 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr, Tegra:
|
||||||
MortonCopy<true, PixelFormat::R8>, MortonCopy<true, PixelFormat::RGBA16F>,
|
MortonCopy<true, PixelFormat::R8>, MortonCopy<true, PixelFormat::RGBA16F>,
|
||||||
MortonCopy<true, PixelFormat::R11FG11FB10F>, MortonCopy<true, PixelFormat::DXT1>,
|
MortonCopy<true, PixelFormat::R11FG11FB10F>, MortonCopy<true, PixelFormat::DXT1>,
|
||||||
MortonCopy<true, PixelFormat::DXT23>, MortonCopy<true, PixelFormat::DXT45>,
|
MortonCopy<true, PixelFormat::DXT23>, MortonCopy<true, PixelFormat::DXT45>,
|
||||||
MortonCopy<true, PixelFormat::DXN1>,
|
MortonCopy<true, PixelFormat::DXN1>, MortonCopy<true, PixelFormat::ASTC_2D_4X4>,
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr, Tegra::GPUVAddr,
|
static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr, Tegra::GPUVAddr,
|
||||||
|
@ -137,6 +162,7 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr, Tegra:
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
|
MortonCopy<false, PixelFormat::ABGR8>,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Allocate an uninitialized texture of appropriate size and format for the surface
|
// Allocate an uninitialized texture of appropriate size and format for the surface
|
||||||
|
|
|
@ -65,6 +65,7 @@ struct SurfaceParams {
|
||||||
DXT23 = 8,
|
DXT23 = 8,
|
||||||
DXT45 = 9,
|
DXT45 = 9,
|
||||||
DXN1 = 10, // This is also known as BC4
|
DXN1 = 10, // This is also known as BC4
|
||||||
|
ASTC_2D_4X4 = 11,
|
||||||
|
|
||||||
Max,
|
Max,
|
||||||
Invalid = 255,
|
Invalid = 255,
|
||||||
|
@ -111,6 +112,7 @@ struct SurfaceParams {
|
||||||
4, // DXT23
|
4, // DXT23
|
||||||
4, // DXT45
|
4, // DXT45
|
||||||
4, // DXN1
|
4, // DXN1
|
||||||
|
1, // ASTC_2D_4X4
|
||||||
}};
|
}};
|
||||||
|
|
||||||
ASSERT(static_cast<size_t>(format) < compression_factor_table.size());
|
ASSERT(static_cast<size_t>(format) < compression_factor_table.size());
|
||||||
|
@ -136,6 +138,7 @@ struct SurfaceParams {
|
||||||
128, // DXT23
|
128, // DXT23
|
||||||
128, // DXT45
|
128, // DXT45
|
||||||
64, // DXN1
|
64, // DXN1
|
||||||
|
32, // ASTC_2D_4X4
|
||||||
}};
|
}};
|
||||||
|
|
||||||
ASSERT(static_cast<size_t>(format) < bpp_table.size());
|
ASSERT(static_cast<size_t>(format) < bpp_table.size());
|
||||||
|
@ -162,6 +165,15 @@ struct SurfaceParams {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsFormatASTC(PixelFormat format) {
|
||||||
|
switch (format) {
|
||||||
|
case PixelFormat::ASTC_2D_4X4:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) {
|
static PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case Tegra::FramebufferConfig::PixelFormat::ABGR8:
|
case Tegra::FramebufferConfig::PixelFormat::ABGR8:
|
||||||
|
@ -197,6 +209,8 @@ struct SurfaceParams {
|
||||||
return PixelFormat::DXT45;
|
return PixelFormat::DXT45;
|
||||||
case Tegra::Texture::TextureFormat::DXN1:
|
case Tegra::Texture::TextureFormat::DXN1:
|
||||||
return PixelFormat::DXN1;
|
return PixelFormat::DXN1;
|
||||||
|
case Tegra::Texture::TextureFormat::ASTC_2D_4X4:
|
||||||
|
return PixelFormat::ASTC_2D_4X4;
|
||||||
default:
|
default:
|
||||||
NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
NGLOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
@ -228,6 +242,8 @@ struct SurfaceParams {
|
||||||
return Tegra::Texture::TextureFormat::DXT45;
|
return Tegra::Texture::TextureFormat::DXT45;
|
||||||
case PixelFormat::DXN1:
|
case PixelFormat::DXN1:
|
||||||
return Tegra::Texture::TextureFormat::DXN1;
|
return Tegra::Texture::TextureFormat::DXN1;
|
||||||
|
case PixelFormat::ASTC_2D_4X4:
|
||||||
|
return Tegra::Texture::TextureFormat::ASTC_2D_4X4;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
1646
src/video_core/textures/astc.cpp
Normal file
1646
src/video_core/textures/astc.cpp
Normal file
File diff suppressed because it is too large
Load diff
15
src/video_core/textures/astc.h
Normal file
15
src/video_core/textures/astc.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2018 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Tegra::Texture::ASTC {
|
||||||
|
|
||||||
|
std::vector<uint8_t> Decompress(std::vector<uint8_t>& data, uint32_t width, uint32_t height,
|
||||||
|
uint32_t block_width, uint32_t block_height);
|
||||||
|
|
||||||
|
} // namespace Tegra::Texture::ASTC
|
|
@ -53,6 +53,7 @@ u32 BytesPerPixel(TextureFormat format) {
|
||||||
case TextureFormat::DXT45:
|
case TextureFormat::DXT45:
|
||||||
// In this case a 'pixel' actually refers to a 4x4 tile.
|
// In this case a 'pixel' actually refers to a 4x4 tile.
|
||||||
return 16;
|
return 16;
|
||||||
|
case TextureFormat::ASTC_2D_4X4:
|
||||||
case TextureFormat::A8R8G8B8:
|
case TextureFormat::A8R8G8B8:
|
||||||
case TextureFormat::A2B10G10R10:
|
case TextureFormat::A2B10G10R10:
|
||||||
case TextureFormat::BF10GF11RF11:
|
case TextureFormat::BF10GF11RF11:
|
||||||
|
@ -94,6 +95,7 @@ std::vector<u8> UnswizzleTexture(VAddr address, TextureFormat format, u32 width,
|
||||||
case TextureFormat::R8:
|
case TextureFormat::R8:
|
||||||
case TextureFormat::R16_G16_B16_A16:
|
case TextureFormat::R16_G16_B16_A16:
|
||||||
case TextureFormat::BF10GF11RF11:
|
case TextureFormat::BF10GF11RF11:
|
||||||
|
case TextureFormat::ASTC_2D_4X4:
|
||||||
CopySwizzledData(width, height, bytes_per_pixel, bytes_per_pixel, data,
|
CopySwizzledData(width, height, bytes_per_pixel, bytes_per_pixel, data,
|
||||||
unswizzled_data.data(), true, block_height);
|
unswizzled_data.data(), true, block_height);
|
||||||
break;
|
break;
|
||||||
|
@ -115,6 +117,7 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat
|
||||||
case TextureFormat::DXT23:
|
case TextureFormat::DXT23:
|
||||||
case TextureFormat::DXT45:
|
case TextureFormat::DXT45:
|
||||||
case TextureFormat::DXN1:
|
case TextureFormat::DXN1:
|
||||||
|
case TextureFormat::ASTC_2D_4X4:
|
||||||
case TextureFormat::A8R8G8B8:
|
case TextureFormat::A8R8G8B8:
|
||||||
case TextureFormat::A2B10G10R10:
|
case TextureFormat::A2B10G10R10:
|
||||||
case TextureFormat::A1B5G5R5:
|
case TextureFormat::A1B5G5R5:
|
||||||
|
|
Loading…
Reference in a new issue