Skip to content

Latest commit

 

History

History
141 lines (106 loc) · 5.5 KB

basislz-gdata.adoc

File metadata and controls

141 lines (106 loc) · 5.5 KB

Appendix A: BasisLZ Global Data

BasisLZ combines encoding to a block-compressed format, that can be easily transcoded to various GPU-native block-compressed formats, with lossless supercompression. Supercompression is accomplished by conditioning the block-compressed representation for entropy encoding then Huffman encoding the result. BasisLZ creates a global codebook referenced by each supercompressed image that contains the processed endpoint and selector data from the block-compression and the Huffman tables. The global data block contains this codebook.

It also contains an array of image descriptors with flags for each image and the offset and length within the mip level of the data for that image.

The global data structure is designed to accommodate various transcodable block-compressed formats. The format in use is indicated by the Data Format Descriptor. Currently BasisLZ only supports one, ETC1S (a subset of ETC1, see Section 21.1 of [KDF13]). ETC1S is a common subset of many GPU-native formats.

The bitstreams for endpoints, selectors, Huffman tables and the image data are specific to the transcodable format in use. Those for ETC1S are defined in [basisLZ/etc1s]. These bitstreams have to be decoded to reconstruct the base images.

The structure of the global data is shown below.

BasisLZ Global Data Structure
UInt16 endpointCount;
UInt16 selectorCount;
UInt32 endpointsByteLength;
UInt32 selectorsByteLength;
UInt32 tablesByteLength;
UInt32 extendedByteLength;

ImageDesc[imageCount] imageDescs;

Byte[endpointsByteLength] endpointsData
Byte[selectorsByteLength] selectorsData
Byte[tablesByteLength] tablesData
Byte[extendedByteLength] extendedData

ImageDesc is the following structure.

ImageDesc
UInt32 imageFlags
UInt32 rgbSliceByteOffset
UInt32 rgbSliceByteLength
UInt32 alphaSliceByteOffset
UInt32 alphaSliceByteLength

Descriptions in the imageDescs array are in the order layer, face and z_slice as if arranged by the following pseudo code.

for each level in max(levelCount, 1)
    for each layer in max (layerCount, 1)
        for each face in faceCount // 1 or 6
            for each z_slice in max((pixelDepth of level), 1)

imageCount is the total number of images in the Mip Level Array.

Tip

imageCount may be calculated as follows:

int imageCount = max(layerCount, 1) * faceCount * layerPixelDepth;

// where layerPixelDepth can be derived as
int layerPixelDepth = max(pixelDepth, 1);
for(int i = 1; i < levelCount; i++)
    layerPixelDepth += max(pixelDepth >> i, 1);

There must be no trailing bytes in the global data section after the extendedData field, i.e., the following condition must always be true:

sgdByteLength == 20 +
                 20 * imageCount +
                 endpointsByteLength +
                 selectorsByteLength +
                 tablesByteLength +
                 extendedByteLength

endpointCount

The number of endpoints in endpointsData.

selectorCount

The number of selectors in selectorsData.

endpointsByteLength

The length of endpointsData.

selectorsByteLength

The length of selectorsData.

tablesByteLength

The length of tablesData.

extendedByteLength

The length of extendedData. Must be 0 if the data format descriptor colorModel is KHR_DF_MODEL_ETC1S (= 163).

ImageDesc

imageFlags

Flags giving information about an individual image. The following flag is valid:

isPFrame = 0x02

BasisLZ/ETC1S supports inter-frame (video) encoding for 2D slices. If isPFrame is set the image (frame) is a P frame. That is, it refers to the previous image of an animation sequence. All other images are I frames. Only animation sequences can have P frames. See [Animation Sequence] for details.

rgbSliceByteOffset, rgbSliceByteLength

The offset of the start of the RGB slice within the levelImages of its mip level and its byte length. The offset of levelImages within the file is given in the Level Index.

rgbSliceByteLength must not be zero.

rgbSliceByteOffset + rgbSliceByteLength must not be greater than the byte length of the corresponding mip level.

alphaSliceByteOffset, alphaSliceByteLength

The offset of the start of the alpha slice within the levelImages of its mip level and its byte length.

If there is only one slice these values must be 0. For ETC1S with the Data Format Descriptor color model of KHR_DF_MODEL_ETC1S this corresponds to the DFD having only one sample. (As the format is supercompressed bytesPlane fields can’t be used to determine the number of planes.)

If the second slice is present, alphaSliceByteLength must not be zero.

alphaSliceByteOffset + alphaSliceByteLength must not be greater than the byte length of the corresponding mip level.

endpointsData

Compressed endpoints data. The bitstream of this for ETC1S is described in [ETC1S Endpoint Codebooks].

selectorsData

Compressed selectors data. The bitstream of this for ETC1S is described in [ETC1S Selector Codebooks].

tablesData

Huffman tables data. The format of this data for ETC1S is described in [ETC1S Slice Huffman Tables].

extendedData

Extended data. This is not used for ETC1S.