surface_params: Optimize CreateForTexture

Instead of using Common::AlignUp, use Common::AlignBits to align the
texture compression factor.
This commit is contained in:
ReinUsesLisp 2019-05-10 23:02:14 -03:00
parent 41b4674458
commit 2131f71573
2 changed files with 76 additions and 72 deletions

View file

@ -122,71 +122,71 @@ enum class SurfaceTarget {
TextureCubeArray,
};
constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{
1, // ABGR8U
1, // ABGR8S
1, // ABGR8UI
1, // B5G6R5U
1, // A2B10G10R10U
1, // A1B5G5R5U
1, // R8U
1, // R8UI
1, // RGBA16F
1, // RGBA16U
1, // RGBA16UI
1, // R11FG11FB10F
1, // RGBA32UI
4, // DXT1
4, // DXT23
4, // DXT45
4, // DXN1
4, // DXN2UNORM
4, // DXN2SNORM
4, // BC7U
4, // BC6H_UF16
4, // BC6H_SF16
4, // ASTC_2D_4X4
1, // BGRA8
1, // RGBA32F
1, // RG32F
1, // R32F
1, // R16F
1, // R16U
1, // R16S
1, // R16UI
1, // R16I
1, // RG16
1, // RG16F
1, // RG16UI
1, // RG16I
1, // RG16S
1, // RGB32F
1, // RGBA8_SRGB
1, // RG8U
1, // RG8S
1, // RG32UI
1, // R32UI
4, // ASTC_2D_8X8
4, // ASTC_2D_8X5
4, // ASTC_2D_5X4
1, // BGRA8_SRGB
4, // DXT1_SRGB
4, // DXT23_SRGB
4, // DXT45_SRGB
4, // BC7U_SRGB
4, // ASTC_2D_4X4_SRGB
4, // ASTC_2D_8X8_SRGB
4, // ASTC_2D_8X5_SRGB
4, // ASTC_2D_5X4_SRGB
4, // ASTC_2D_5X5
4, // ASTC_2D_5X5_SRGB
4, // ASTC_2D_10X8
4, // ASTC_2D_10X8_SRGB
1, // Z32F
1, // Z16
1, // Z24S8
1, // S8Z24
1, // Z32FS8
inline constexpr std::array<u32, MaxPixelFormat> compression_factor_shift_table = {{
0, // ABGR8U
0, // ABGR8S
0, // ABGR8UI
0, // B5G6R5U
0, // A2B10G10R10U
0, // A1B5G5R5U
0, // R8U
0, // R8UI
0, // RGBA16F
0, // RGBA16U
0, // RGBA16UI
0, // R11FG11FB10F
0, // RGBA32UI
2, // DXT1
2, // DXT23
2, // DXT45
2, // DXN1
2, // DXN2UNORM
2, // DXN2SNORM
2, // BC7U
2, // BC6H_UF16
2, // BC6H_SF16
2, // ASTC_2D_4X4
0, // BGRA8
0, // RGBA32F
0, // RG32F
0, // R32F
0, // R16F
0, // R16U
0, // R16S
0, // R16UI
0, // R16I
0, // RG16
0, // RG16F
0, // RG16UI
0, // RG16I
0, // RG16S
0, // RGB32F
0, // RGBA8_SRGB
0, // RG8U
0, // RG8S
0, // RG32UI
0, // R32UI
2, // ASTC_2D_8X8
2, // ASTC_2D_8X5
2, // ASTC_2D_5X4
0, // BGRA8_SRGB
2, // DXT1_SRGB
2, // DXT23_SRGB
2, // DXT45_SRGB
2, // BC7U_SRGB
2, // ASTC_2D_4X4_SRGB
2, // ASTC_2D_8X8_SRGB
2, // ASTC_2D_8X5_SRGB
2, // ASTC_2D_5X4_SRGB
2, // ASTC_2D_5X5
2, // ASTC_2D_5X5_SRGB
2, // ASTC_2D_10X8
2, // ASTC_2D_10X8_SRGB
0, // Z32F
0, // Z16
0, // Z24S8
0, // S8Z24
0, // Z32FS8
}};
/**
@ -195,12 +195,14 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{
* compressed image. This is used for maintaining proper surface sizes for compressed
* texture formats.
*/
static constexpr u32 GetCompressionFactor(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
inline constexpr u32 GetCompressionFactorShift(PixelFormat format) {
DEBUG_ASSERT(format != PixelFormat::Invalid);
DEBUG_ASSERT(static_cast<std::size_t>(format) < compression_factor_table.size());
return compression_factor_shift_table[static_cast<std::size_t>(format)];
}
ASSERT(static_cast<std::size_t>(format) < compression_factor_table.size());
return compression_factor_table[static_cast<std::size_t>(format)];
inline constexpr u32 GetCompressionFactor(PixelFormat format) {
return 1U << GetCompressionFactorShift(format);
}
constexpr std::array<u32, MaxPixelFormat> block_width_table = {{

View file

@ -76,8 +76,10 @@ SurfaceParams SurfaceParams::CreateForTexture(Core::System& system,
params.type = GetFormatType(params.pixel_format);
// TODO: on 1DBuffer we should use the tic info.
params.target = TextureType2SurfaceTarget(entry.GetType(), entry.IsArray());
params.width = Common::AlignUp(config.tic.Width(), GetCompressionFactor(params.pixel_format));
params.height = Common::AlignUp(config.tic.Height(), GetCompressionFactor(params.pixel_format));
params.width =
Common::AlignBits(config.tic.Width(), GetCompressionFactorShift(params.pixel_format));
params.height =
Common::AlignBits(config.tic.Height(), GetCompressionFactorShift(params.pixel_format));
params.depth = config.tic.Depth();
if (params.target == SurfaceTarget::TextureCubemap ||
params.target == SurfaceTarget::TextureCubeArray) {