Merge pull request #1859 from heapo/lut_array_codegen

Convert high-frequency LUT arrays from constexpr to static constexpr
This commit is contained in:
bunnei 2018-12-04 22:07:12 -05:00 committed by GitHub
commit db3200b515
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -125,16 +125,6 @@ enum class SurfaceTarget {
TextureCubeArray, TextureCubeArray,
}; };
/**
* Gets the compression factor for the specified PixelFormat. This applies to just the
* "compressed width" and "compressed height", not the overall compression factor of a
* 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;
constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{ constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{
1, // ABGR8U 1, // ABGR8U
1, // ABGR8S 1, // ABGR8S
@ -204,13 +194,20 @@ static constexpr u32 GetCompressionFactor(PixelFormat format) {
1, // Z32FS8 1, // Z32FS8
}}; }};
/**
* Gets the compression factor for the specified PixelFormat. This applies to just the
* "compressed width" and "compressed height", not the overall compression factor of a
* 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;
ASSERT(static_cast<std::size_t>(format) < compression_factor_table.size()); ASSERT(static_cast<std::size_t>(format) < compression_factor_table.size());
return compression_factor_table[static_cast<std::size_t>(format)]; return compression_factor_table[static_cast<std::size_t>(format)];
} }
static constexpr u32 GetDefaultBlockWidth(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
constexpr std::array<u32, MaxPixelFormat> block_width_table = {{ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{
1, // ABGR8U 1, // ABGR8U
1, // ABGR8S 1, // ABGR8S
@ -279,14 +276,15 @@ static constexpr u32 GetDefaultBlockWidth(PixelFormat format) {
1, // S8Z24 1, // S8Z24
1, // Z32FS8 1, // Z32FS8
}}; }};
static constexpr u32 GetDefaultBlockWidth(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
ASSERT(static_cast<std::size_t>(format) < block_width_table.size()); ASSERT(static_cast<std::size_t>(format) < block_width_table.size());
return block_width_table[static_cast<std::size_t>(format)]; return block_width_table[static_cast<std::size_t>(format)];
} }
static constexpr u32 GetDefaultBlockHeight(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
constexpr std::array<u32, MaxPixelFormat> block_height_table = {{ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{
1, // ABGR8U 1, // ABGR8U
1, // ABGR8S 1, // ABGR8S
@ -356,14 +354,14 @@ static constexpr u32 GetDefaultBlockHeight(PixelFormat format) {
1, // Z32FS8 1, // Z32FS8
}}; }};
static constexpr u32 GetDefaultBlockHeight(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
ASSERT(static_cast<std::size_t>(format) < block_height_table.size()); ASSERT(static_cast<std::size_t>(format) < block_height_table.size());
return block_height_table[static_cast<std::size_t>(format)]; return block_height_table[static_cast<std::size_t>(format)];
} }
static constexpr u32 GetFormatBpp(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
constexpr std::array<u32, MaxPixelFormat> bpp_table = {{ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
32, // ABGR8U 32, // ABGR8U
32, // ABGR8S 32, // ABGR8S
@ -433,6 +431,10 @@ static constexpr u32 GetFormatBpp(PixelFormat format) {
64, // Z32FS8 64, // Z32FS8
}}; }};
static constexpr u32 GetFormatBpp(PixelFormat format) {
if (format == PixelFormat::Invalid)
return 0;
ASSERT(static_cast<std::size_t>(format) < bpp_table.size()); ASSERT(static_cast<std::size_t>(format) < bpp_table.size());
return bpp_table[static_cast<std::size_t>(format)]; return bpp_table[static_cast<std::size_t>(format)];
} }