rasterizer_cache: Remove OpenGL references from morton_swizzle
This commit is contained in:
@ -98,8 +98,9 @@ void CachedSurface::LoadGLBuffer(PAddr load_start, PAddr load_end) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
morton_to_gl_fns[static_cast<std::size_t>(pixel_format)](stride, height, &gl_buffer[0],
|
||||
addr, load_start, load_end);
|
||||
const u32 func_index = static_cast<u32>(pixel_format);
|
||||
const MortonFunc func = UNSWIZZLE_TABLE[func_index];
|
||||
func(stride, height, &gl_buffer[0], addr, load_start, load_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,8 +162,9 @@ void CachedSurface::FlushGLBuffer(PAddr flush_start, PAddr flush_end) {
|
||||
flush_end - flush_start);
|
||||
}
|
||||
} else {
|
||||
gl_to_morton_fns[static_cast<std::size_t>(pixel_format)](stride, height, &gl_buffer[0],
|
||||
addr, flush_start, flush_end);
|
||||
const u32 func_index = static_cast<u32>(pixel_format);
|
||||
const MortonFunc func = SWIZZLE_TABLE[func_index];
|
||||
func(stride, height, &gl_buffer[0], addr, flush_start, flush_end);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,95 +12,96 @@
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
template <bool morton_to_gl, PixelFormat format>
|
||||
static void MortonCopyTile(u32 stride, u8* tile_buffer, u8* gl_buffer) {
|
||||
template <bool morton_to_linear, PixelFormat format>
|
||||
static void MortonCopyTile(u32 stride, u8* tile_buffer, u8* linear_buffer) {
|
||||
constexpr u32 bytes_per_pixel = GetFormatBpp(format) / 8;
|
||||
constexpr u32 aligned_bytes_per_pixel = GetBytesPerPixel(format);
|
||||
for (u32 y = 0; y < 8; ++y) {
|
||||
for (u32 x = 0; x < 8; ++x) {
|
||||
|
||||
for (u32 y = 0; y < 8; y++) {
|
||||
for (u32 x = 0; x < 8; x++) {
|
||||
u8* tile_ptr = tile_buffer + VideoCore::MortonInterleave(x, y) * bytes_per_pixel;
|
||||
u8* gl_ptr = gl_buffer + ((7 - y) * stride + x) * aligned_bytes_per_pixel;
|
||||
if constexpr (morton_to_gl) {
|
||||
u8* linear_ptr = linear_buffer + ((7 - y) * stride + x) * aligned_bytes_per_pixel;
|
||||
if constexpr (morton_to_linear) {
|
||||
if constexpr (format == PixelFormat::D24S8) {
|
||||
gl_ptr[0] = tile_ptr[3];
|
||||
std::memcpy(gl_ptr + 1, tile_ptr, 3);
|
||||
linear_ptr[0] = tile_ptr[3];
|
||||
std::memcpy(linear_ptr + 1, tile_ptr, 3);
|
||||
} else if (format == PixelFormat::RGBA8 && GLES) {
|
||||
// because GLES does not have ABGR format
|
||||
// so we will do byteswapping here
|
||||
gl_ptr[0] = tile_ptr[3];
|
||||
gl_ptr[1] = tile_ptr[2];
|
||||
gl_ptr[2] = tile_ptr[1];
|
||||
gl_ptr[3] = tile_ptr[0];
|
||||
linear_ptr[0] = tile_ptr[3];
|
||||
linear_ptr[1] = tile_ptr[2];
|
||||
linear_ptr[2] = tile_ptr[1];
|
||||
linear_ptr[3] = tile_ptr[0];
|
||||
} else if (format == PixelFormat::RGB8 && GLES) {
|
||||
gl_ptr[0] = tile_ptr[2];
|
||||
gl_ptr[1] = tile_ptr[1];
|
||||
gl_ptr[2] = tile_ptr[0];
|
||||
linear_ptr[0] = tile_ptr[2];
|
||||
linear_ptr[1] = tile_ptr[1];
|
||||
linear_ptr[2] = tile_ptr[0];
|
||||
} else {
|
||||
std::memcpy(gl_ptr, tile_ptr, bytes_per_pixel);
|
||||
std::memcpy(linear_ptr, tile_ptr, bytes_per_pixel);
|
||||
}
|
||||
} else {
|
||||
if constexpr (format == PixelFormat::D24S8) {
|
||||
std::memcpy(tile_ptr, gl_ptr + 1, 3);
|
||||
tile_ptr[3] = gl_ptr[0];
|
||||
std::memcpy(tile_ptr, linear_ptr + 1, 3);
|
||||
tile_ptr[3] = linear_ptr[0];
|
||||
} else if (format == PixelFormat::RGBA8 && GLES) {
|
||||
// because GLES does not have ABGR format
|
||||
// so we will do byteswapping here
|
||||
tile_ptr[0] = gl_ptr[3];
|
||||
tile_ptr[1] = gl_ptr[2];
|
||||
tile_ptr[2] = gl_ptr[1];
|
||||
tile_ptr[3] = gl_ptr[0];
|
||||
tile_ptr[0] = linear_ptr[3];
|
||||
tile_ptr[1] = linear_ptr[2];
|
||||
tile_ptr[2] = linear_ptr[1];
|
||||
tile_ptr[3] = linear_ptr[0];
|
||||
} else if (format == PixelFormat::RGB8 && GLES) {
|
||||
tile_ptr[0] = gl_ptr[2];
|
||||
tile_ptr[1] = gl_ptr[1];
|
||||
tile_ptr[2] = gl_ptr[0];
|
||||
tile_ptr[0] = linear_ptr[2];
|
||||
tile_ptr[1] = linear_ptr[1];
|
||||
tile_ptr[2] = linear_ptr[0];
|
||||
} else {
|
||||
std::memcpy(tile_ptr, gl_ptr, bytes_per_pixel);
|
||||
std::memcpy(tile_ptr, linear_ptr, bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <bool morton_to_gl, PixelFormat format>
|
||||
static void MortonCopy(u32 stride, u32 height, u8* gl_buffer, PAddr base, PAddr start, PAddr end) {
|
||||
template <bool morton_to_linear, PixelFormat format>
|
||||
static void MortonCopy(u32 stride, u32 height, u8* linear_buffer, PAddr base, PAddr start, PAddr end) {
|
||||
constexpr u32 bytes_per_pixel = GetFormatBpp(format) / 8;
|
||||
constexpr u32 tile_size = bytes_per_pixel * 64;
|
||||
|
||||
constexpr u32 aligned_bytes_per_pixel = GetBytesPerPixel(format);
|
||||
static_assert(aligned_bytes_per_pixel >= bytes_per_pixel, "");
|
||||
gl_buffer += aligned_bytes_per_pixel - bytes_per_pixel;
|
||||
linear_buffer += aligned_bytes_per_pixel - bytes_per_pixel;
|
||||
|
||||
const PAddr aligned_down_start = base + Common::AlignDown(start - base, tile_size);
|
||||
const PAddr aligned_start = base + Common::AlignUp(start - base, tile_size);
|
||||
const PAddr aligned_end = base + Common::AlignDown(end - base, tile_size);
|
||||
|
||||
ASSERT(!morton_to_gl || (aligned_start == start && aligned_end == end));
|
||||
ASSERT(!morton_to_linear || (aligned_start == start && aligned_end == end));
|
||||
|
||||
const u32 begin_pixel_index = (aligned_down_start - base) / bytes_per_pixel;
|
||||
u32 x = (begin_pixel_index % (stride * 8)) / 8;
|
||||
u32 y = (begin_pixel_index / (stride * 8)) * 8;
|
||||
|
||||
gl_buffer += ((height - 8 - y) * stride + x) * aligned_bytes_per_pixel;
|
||||
linear_buffer += ((height - 8 - y) * stride + x) * aligned_bytes_per_pixel;
|
||||
|
||||
auto glbuf_next_tile = [&] {
|
||||
auto linearbuf_next_tile = [&] {
|
||||
x = (x + 8) % stride;
|
||||
gl_buffer += 8 * aligned_bytes_per_pixel;
|
||||
linear_buffer += 8 * aligned_bytes_per_pixel;
|
||||
if (!x) {
|
||||
y += 8;
|
||||
gl_buffer -= stride * 9 * aligned_bytes_per_pixel;
|
||||
linear_buffer -= stride * 9 * aligned_bytes_per_pixel;
|
||||
}
|
||||
};
|
||||
|
||||
u8* tile_buffer = VideoCore::g_memory->GetPhysicalPointer(start);
|
||||
|
||||
if (start < aligned_start && !morton_to_gl) {
|
||||
if (start < aligned_start && !morton_to_linear) {
|
||||
std::array<u8, tile_size> tmp_buf;
|
||||
MortonCopyTile<morton_to_gl, format>(stride, &tmp_buf[0], gl_buffer);
|
||||
MortonCopyTile<morton_to_linear, format>(stride, &tmp_buf[0], linear_buffer);
|
||||
std::memcpy(tile_buffer, &tmp_buf[start - aligned_down_start],
|
||||
std::min(aligned_start, end) - start);
|
||||
|
||||
tile_buffer += aligned_start - start;
|
||||
glbuf_next_tile();
|
||||
linearbuf_next_tile();
|
||||
}
|
||||
|
||||
const u8* const buffer_end = tile_buffer + aligned_end - aligned_start;
|
||||
@ -113,20 +114,22 @@ static void MortonCopy(u32 stride, u32 height, u8* gl_buffer, PAddr base, PAddr
|
||||
LOG_ERROR(Render_OpenGL, "Out of bound texture");
|
||||
break;
|
||||
}
|
||||
MortonCopyTile<morton_to_gl, format>(stride, tile_buffer, gl_buffer);
|
||||
MortonCopyTile<morton_to_linear, format>(stride, tile_buffer, linear_buffer);
|
||||
tile_buffer += tile_size;
|
||||
current_paddr += tile_size;
|
||||
glbuf_next_tile();
|
||||
linearbuf_next_tile();
|
||||
}
|
||||
|
||||
if (end > std::max(aligned_start, aligned_end) && !morton_to_gl) {
|
||||
if (end > std::max(aligned_start, aligned_end) && !morton_to_linear) {
|
||||
std::array<u8, tile_size> tmp_buf;
|
||||
MortonCopyTile<morton_to_gl, format>(stride, &tmp_buf[0], gl_buffer);
|
||||
MortonCopyTile<morton_to_linear, format>(stride, &tmp_buf[0], linear_buffer);
|
||||
std::memcpy(tile_buffer, &tmp_buf[0], end - aligned_end);
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr std::array<void (*)(u32, u32, u8*, PAddr, PAddr, PAddr), 18> morton_to_gl_fns = {
|
||||
using MortonFunc = void (*)(u32, u32, u8*, PAddr, PAddr, PAddr);
|
||||
|
||||
static constexpr std::array<MortonFunc, 18> UNSWIZZLE_TABLE = {
|
||||
MortonCopy<true, PixelFormat::RGBA8>, // 0
|
||||
MortonCopy<true, PixelFormat::RGB8>, // 1
|
||||
MortonCopy<true, PixelFormat::RGB5A1>, // 2
|
||||
@ -147,7 +150,7 @@ static constexpr std::array<void (*)(u32, u32, u8*, PAddr, PAddr, PAddr), 18> mo
|
||||
MortonCopy<true, PixelFormat::D24S8> // 17
|
||||
};
|
||||
|
||||
static constexpr std::array<void (*)(u32, u32, u8*, PAddr, PAddr, PAddr), 18> gl_to_morton_fns = {
|
||||
static constexpr std::array<MortonFunc, 18> SWIZZLE_TABLE = {
|
||||
MortonCopy<false, PixelFormat::RGBA8>, // 0
|
||||
MortonCopy<false, PixelFormat::RGB8>, // 1
|
||||
MortonCopy<false, PixelFormat::RGB5A1>, // 2
|
||||
|
Reference in New Issue
Block a user