CACHE_BASE::CACHE_BASE(std::string name, UINT32 cacheSize, UINT32 lineSize, UINT32 associativity) : _name(name), _cacheSize(cacheSize), _lineSize(lineSize), _associativity(associativity), _lineShift(FloorLog2(lineSize)), _setIndexMask((cacheSize / (associativity * lineSize)) - 1) { ASSERTX(IsPower2(_lineSize)); ASSERTX(IsPower2(_setIndexMask + 1)); for (UINT32 accessType = 0; accessType < ACCESS_TYPE_NUM; accessType++) { _access[accessType][false] = 0; _access[accessType][true] = 0; } }
void DDS::readBioWareHeader(Common::SeekableReadStream &dds) { dds.seek(0); // Image dimensions uint32 width = dds.readUint32LE(); uint32 height = dds.readUint32LE(); // Check that the width and height are really powers of 2 if (!IsPower2(width) || !IsPower2(height)) throw Common::Exception("Width and height must be powers of 2"); // Always compressed _compressed = true; // Check which compression uint32 bpp = dds.readUint32LE(); if (bpp == 3) { _hasAlpha = false; _format = kPixelFormatBGR; _formatRaw = kPixelFormatDXT1; _dataType = kPixelDataType8; } else if (bpp == 4) { _hasAlpha = true; _format = kPixelFormatBGRA; _formatRaw = kPixelFormatDXT5; _dataType = kPixelDataType8; } else throw Common::Exception("Unsupported bytes per pixel value (%d)", bpp); // Sanity check for the image data size uint32 dataSize = dds.readUint32LE(); if (((bpp == 3) && (dataSize != ((width * height) / 2))) || ((bpp == 4) && (dataSize != ((width * height) )))) throw Common::Exception("Invalid data size (%dx%dx%d %d)", width, height, bpp, dataSize); dds.skip(4); // Some float // Number of bytes left for the image data uint32 fullDataSize = dds.size() - dds.pos(); // Detect how many mip maps are in the DDS do { MipMap *mipMap = new MipMap; mipMap->width = MAX<uint32>(width, 1); mipMap->height = MAX<uint32>(height, 1); setSize(*mipMap); if (fullDataSize < mipMap->size) { // Wouldn't fit delete mipMap; break; } fullDataSize -= mipMap->size; _mipMaps.push_back(mipMap); width >>= 1; height >>= 1; } while ((width >= 1) && (height >= 1)); }