mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-27 21:34:18 +01:00
GLCache: Unify texture and framebuffer formats when converting to OpenGL.
This commit is contained in:
parent
b2c1672e10
commit
5b3fab6766
@ -47,26 +47,20 @@ struct FormatTuple {
|
|||||||
u32 compression_factor;
|
u32 compression_factor;
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr std::array<FormatTuple, 1> fb_format_tuples = {{
|
|
||||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, false, 1}, // RGBA8
|
|
||||||
}};
|
|
||||||
|
|
||||||
static constexpr std::array<FormatTuple, 2> tex_format_tuples = {{
|
static constexpr std::array<FormatTuple, 2> tex_format_tuples = {{
|
||||||
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false, 1}, // ABGR8
|
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, false, 1}, // ABGR8
|
||||||
{GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT1
|
{GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, true, 16}, // DXT1
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static const FormatTuple& GetFormatTuple(PixelFormat pixel_format) {
|
static const FormatTuple& GetFormatTuple(PixelFormat pixel_format) {
|
||||||
|
using Tegra::Texture::ComponentType;
|
||||||
const SurfaceType type = SurfaceParams::GetFormatType(pixel_format);
|
const SurfaceType type = SurfaceParams::GetFormatType(pixel_format);
|
||||||
if (type == SurfaceType::Color) {
|
if (type == SurfaceType::ColorTexture) {
|
||||||
ASSERT(static_cast<size_t>(pixel_format) < fb_format_tuples.size());
|
ASSERT(static_cast<size_t>(pixel_format) < tex_format_tuples.size());
|
||||||
return fb_format_tuples[static_cast<unsigned int>(pixel_format)];
|
return tex_format_tuples[static_cast<unsigned int>(pixel_format)];
|
||||||
} else if (type == SurfaceType::Depth || type == SurfaceType::DepthStencil) {
|
} else if (type == SurfaceType::Depth || type == SurfaceType::DepthStencil) {
|
||||||
// TODO(Subv): Implement depth formats
|
// TODO(Subv): Implement depth formats
|
||||||
ASSERT_MSG(false, "Unimplemented");
|
ASSERT_MSG(false, "Unimplemented");
|
||||||
} else if (type == SurfaceType::Texture) {
|
|
||||||
ASSERT(static_cast<size_t>(pixel_format) < tex_format_tuples.size());
|
|
||||||
return tex_format_tuples[static_cast<unsigned int>(pixel_format)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -180,7 +174,7 @@ static bool BlitTextures(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rec
|
|||||||
|
|
||||||
u32 buffers = 0;
|
u32 buffers = 0;
|
||||||
|
|
||||||
if (type == SurfaceType::Color || type == SurfaceType::Texture) {
|
if (type == SurfaceType::ColorTexture) {
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src_tex,
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, src_tex,
|
||||||
0);
|
0);
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,
|
||||||
@ -658,7 +652,7 @@ void CachedSurface::DownloadGLTexture(const MathUtil::Rectangle<u32>& rect, GLui
|
|||||||
state.draw.read_framebuffer = read_fb_handle;
|
state.draw.read_framebuffer = read_fb_handle;
|
||||||
state.Apply();
|
state.Apply();
|
||||||
|
|
||||||
if (type == SurfaceType::Color || type == SurfaceType::Texture) {
|
if (type == SurfaceType::ColorTexture) {
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
|
||||||
texture.handle, 0);
|
texture.handle, 0);
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,
|
||||||
@ -1300,7 +1294,6 @@ void RasterizerCacheOpenGL::InvalidateRegion(VAddr addr, u64 size, const Surface
|
|||||||
const SurfaceInterval invalid_interval(addr, addr + size);
|
const SurfaceInterval invalid_interval(addr, addr + size);
|
||||||
|
|
||||||
if (region_owner != nullptr) {
|
if (region_owner != nullptr) {
|
||||||
ASSERT(region_owner->type != SurfaceType::Texture);
|
|
||||||
ASSERT(addr >= region_owner->addr && addr + size <= region_owner->end);
|
ASSERT(addr >= region_owner->addr && addr + size <= region_owner->end);
|
||||||
// Surfaces can't have a gap
|
// Surfaces can't have a gap
|
||||||
ASSERT(region_owner->width == region_owner->stride);
|
ASSERT(region_owner->width == region_owner->stride);
|
||||||
|
@ -58,12 +58,11 @@ struct SurfaceParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum class SurfaceType {
|
enum class SurfaceType {
|
||||||
Color = 0,
|
ColorTexture = 0,
|
||||||
Texture = 1,
|
Depth = 1,
|
||||||
Depth = 2,
|
DepthStencil = 2,
|
||||||
DepthStencil = 3,
|
Fill = 3,
|
||||||
Fill = 4,
|
Invalid = 4,
|
||||||
Invalid = 5
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr unsigned int GetFormatBpp(PixelFormat format) {
|
static constexpr unsigned int GetFormatBpp(PixelFormat format) {
|
||||||
@ -131,8 +130,7 @@ struct SurfaceParams {
|
|||||||
SurfaceType a_type = GetFormatType(pixel_format_a);
|
SurfaceType a_type = GetFormatType(pixel_format_a);
|
||||||
SurfaceType b_type = GetFormatType(pixel_format_b);
|
SurfaceType b_type = GetFormatType(pixel_format_b);
|
||||||
|
|
||||||
if ((a_type == SurfaceType::Color || a_type == SurfaceType::Texture) &&
|
if (a_type == SurfaceType::ColorTexture && b_type == SurfaceType::ColorTexture) {
|
||||||
(b_type == SurfaceType::Color || b_type == SurfaceType::Texture)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,12 +146,8 @@ struct SurfaceParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static SurfaceType GetFormatType(PixelFormat pixel_format) {
|
static SurfaceType GetFormatType(PixelFormat pixel_format) {
|
||||||
if ((unsigned int)pixel_format <= static_cast<unsigned int>(PixelFormat::ABGR8)) {
|
|
||||||
return SurfaceType::Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((unsigned int)pixel_format <= static_cast<unsigned int>(PixelFormat::DXT1)) {
|
if ((unsigned int)pixel_format <= static_cast<unsigned int>(PixelFormat::DXT1)) {
|
||||||
return SurfaceType::Texture;
|
return SurfaceType::ColorTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(Subv): Implement the other formats
|
// TODO(Subv): Implement the other formats
|
||||||
|
Loading…
Reference in New Issue
Block a user