Add RoundUpToMultiple and DivideAndRoundUp functions to MathUtils.h (#6989)
* Add RoundUpToMultiple and DivideAndRoundUp functions to MathUtils.h Signed-off-by: Tommy Walton <waltont@amazon.com> * Rename DivideByMultiple2 back to DivideByMultiple, now that I've confirmed it's not in use in the codebase. RHI::DivideByMultiple can be fully deprecated in favor of AZ::DivideAndRoundUp at a later date, once the deprecation strategy has been finalized. Signed-off-by: Tommy Walton <waltont@amazon.com> * Update based on PR feedback Signed-off-by: Tommy Walton <waltont@amazon.com> * Switched from std::numeric_limits to AZStd::numeric_limits and updated the header to indicate it works for non-power of two alignments, but that SizeAlignUp is more efficient if the alignment is a power of 2 Signed-off-by: Tommy Walton <waltont@amazon.com> * Added missing arguments to the assert, and a missing namespace and include that failed to compile on non-unity builds Signed-off-by: Tommy Walton <waltont@amazon.com>
This commit is contained in:
@@ -179,7 +179,7 @@ namespace ImageProcessingAtom
|
||||
|
||||
// Create a context based on the configuration
|
||||
astcenc_context* context;
|
||||
AZ::u32 blockCount = ((srcImage->GetWidth(0)+ dstFormatInfo->blockWidth-1)/dstFormatInfo->blockWidth) * ((srcImage->GetHeight(0) + dstFormatInfo->blockHeight-1)/dstFormatInfo->blockHeight);
|
||||
AZ::u32 blockCount = AZ::DivideAndRoundUp(srcImage->GetWidth(0), dstFormatInfo->blockWidth) * AZ::DivideAndRoundUp(srcImage->GetHeight(0), dstFormatInfo->blockHeight);
|
||||
AZ::u32 threadCount = AZStd::min(AZStd::thread::hardware_concurrency()/2, blockCount);
|
||||
status = astcenc_context_alloc(&config, threadCount, &context);
|
||||
AZ_Assert( status == ASTCENC_SUCCESS, "ERROR: Codec context alloc failed: %s\n", astcenc_get_error_string(status));
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <Processing/PixelFormatInfo.h>
|
||||
#include <Processing/DDSHeader.h>
|
||||
|
||||
#include <AzCore/Math/MathUtils.h>
|
||||
|
||||
namespace ImageProcessingAtom
|
||||
{
|
||||
CPixelFormats* CPixelFormats::s_instance = nullptr;
|
||||
@@ -370,11 +372,11 @@ namespace ImageProcessingAtom
|
||||
{
|
||||
if (outWidth % pFormatInfo->blockWidth != 0)
|
||||
{
|
||||
outWidth = ((outWidth + pFormatInfo->blockWidth - 1) / pFormatInfo->blockWidth) * pFormatInfo->blockWidth;
|
||||
outWidth = AZ::RoundUpToMultiple(outWidth, pFormatInfo->blockWidth);
|
||||
}
|
||||
if (outHeight % pFormatInfo->blockHeight != 0)
|
||||
{
|
||||
outHeight = ((outHeight + pFormatInfo->blockHeight - 1) / pFormatInfo->blockHeight) * pFormatInfo->blockHeight;
|
||||
outHeight = AZ::RoundUpToMultiple(outHeight, pFormatInfo->blockHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -390,10 +392,11 @@ namespace ImageProcessingAtom
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get number of blocks (ceiling round up for block count) and multiply with bits per block. Divided by 8 to get
|
||||
// get number of blocks and multiply with bits per block. Divided by 8 to get
|
||||
// final byte size
|
||||
return (((imageWidth + pFormatInfo->blockWidth - 1) / pFormatInfo->blockWidth) *
|
||||
((imageHeight + pFormatInfo->blockHeight - 1) / pFormatInfo->blockHeight) * pFormatInfo->bitsPerBlock) / 8;
|
||||
return (AZ::DivideAndRoundUp(imageWidth, pFormatInfo->blockWidth) *
|
||||
AZ::DivideAndRoundUp(imageHeight, pFormatInfo->blockHeight) *
|
||||
pFormatInfo->bitsPerBlock) / 8;
|
||||
}
|
||||
|
||||
bool CPixelFormats::IsFormatSingleChannel(EPixelFormat fmt)
|
||||
|
||||
Reference in New Issue
Block a user