2010-10-21 18:44:10 +00:00
|
|
|
// This code is in the public domain -- castanyo@yahoo.es
|
|
|
|
#pragma once
|
|
|
|
|
2011-08-26 12:11:38 +00:00
|
|
|
#include "nvcore/nvcore.h"
|
|
|
|
#include "nvcore/Debug.h" // nvDebugCheck
|
|
|
|
#include "nvcore/Utils.h" // isPowerOfTwo
|
2010-10-21 18:44:10 +00:00
|
|
|
|
2011-08-26 12:11:38 +00:00
|
|
|
namespace nv {
|
2010-10-21 18:44:10 +00:00
|
|
|
|
2011-08-26 12:11:38 +00:00
|
|
|
// Some utility functions:
|
|
|
|
inline uint computeBitPitch(uint w, uint bitsize, uint alignmentInBits)
|
|
|
|
{
|
|
|
|
nvDebugCheck(isPowerOfTwo(alignmentInBits));
|
2010-10-21 18:44:10 +00:00
|
|
|
|
2011-08-26 12:11:38 +00:00
|
|
|
return ((w * bitsize + alignmentInBits - 1) / alignmentInBits) * alignmentInBits;
|
|
|
|
}
|
|
|
|
|
2011-09-30 01:52:27 +00:00
|
|
|
inline uint computeBytePitch(uint w, uint bitsize, uint alignmentInBytes)
|
2011-08-26 12:11:38 +00:00
|
|
|
{
|
2011-09-30 01:52:27 +00:00
|
|
|
uint pitch = computeBitPitch(w, bitsize, 8*alignmentInBytes);
|
|
|
|
nvDebugCheck((pitch & 7) == 0);
|
2011-08-26 12:11:38 +00:00
|
|
|
|
|
|
|
return (pitch + 7) / 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // nv namespace
|