1
0
Fork 0
forked from suyu/suyu

Merge pull request #2369 from FernandoS27/mip-align

gl_backend: Align Pixel Storage
This commit is contained in:
bunnei 2019-04-09 17:20:43 -04:00 committed by GitHub
commit bc7e149835
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -661,8 +661,8 @@ void CachedSurface::FlushGLBuffer() {
gl_buffer[0].resize(GetSizeInBytes()); gl_buffer[0].resize(GetSizeInBytes());
const FormatTuple& tuple = GetFormatTuple(params.pixel_format, params.component_type); const FormatTuple& tuple = GetFormatTuple(params.pixel_format, params.component_type);
// Ensure no bad interactions with GL_UNPACK_ALIGNMENT const u32 align = std::clamp(params.RowAlign(0), 1U, 8U);
ASSERT(params.width * GetBytesPerPixel(params.pixel_format) % 4 == 0); glPixelStorei(GL_PACK_ALIGNMENT, align);
glPixelStorei(GL_PACK_ROW_LENGTH, static_cast<GLint>(params.width)); glPixelStorei(GL_PACK_ROW_LENGTH, static_cast<GLint>(params.width));
ASSERT(!tuple.compressed); ASSERT(!tuple.compressed);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
@ -707,8 +707,8 @@ void CachedSurface::UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle,
const FormatTuple& tuple = GetFormatTuple(params.pixel_format, params.component_type); const FormatTuple& tuple = GetFormatTuple(params.pixel_format, params.component_type);
// Ensure no bad interactions with GL_UNPACK_ALIGNMENT const u32 align = std::clamp(params.RowAlign(mip_map), 1U, 8U);
ASSERT(params.MipWidth(mip_map) * GetBytesPerPixel(params.pixel_format) % 4 == 0); glPixelStorei(GL_UNPACK_ALIGNMENT, align);
glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.MipWidth(mip_map))); glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.MipWidth(mip_map)));
const auto image_size = static_cast<GLsizei>(params.GetMipmapSizeGL(mip_map, false)); const auto image_size = static_cast<GLsizei>(params.GetMipmapSizeGL(mip_map, false));

View file

@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include "common/alignment.h" #include "common/alignment.h"
#include "common/bit_util.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/hash.h" #include "common/hash.h"
#include "common/math_util.h" #include "common/math_util.h"
@ -205,6 +206,13 @@ struct SurfaceParams {
return bd; return bd;
} }
u32 RowAlign(u32 mip_level) const {
const u32 m_width = MipWidth(mip_level);
const u32 bytes_per_pixel = GetBytesPerPixel(pixel_format);
const u32 l2 = Common::CountTrailingZeroes32(m_width * bytes_per_pixel);
return (1U << l2);
}
/// Creates SurfaceParams from a texture configuration /// Creates SurfaceParams from a texture configuration
static SurfaceParams CreateForTexture(const Tegra::Texture::FullTextureInfo& config, static SurfaceParams CreateForTexture(const Tegra::Texture::FullTextureInfo& config,
const GLShader::SamplerEntry& entry); const GLShader::SamplerEntry& entry);