Skip to content

Commit

Permalink
Merge pull request #2 from KhronosGroup/master
Browse files Browse the repository at this point in the history
update to upstream
  • Loading branch information
UX3D-becher authored Oct 8, 2020
2 parents 2ac2fbd + 78790b5 commit 43ef010
Show file tree
Hide file tree
Showing 26 changed files with 340 additions and 124 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ before_deploy:
deploy:
- provider: pages
#edge: true # Use bleeding edge (dplv2)
skip-cleanup: true
github-token: $GITHUB_TOKEN # Set in the repo settings page as a secure variable
local-dir: build-macos/docs/html
skip_cleanup: true
github_token: $GITHUB_TOKEN # Set in the repo settings page as a secure variable
local_dir: build-macos/docs/html
on:
#branch: master
condition: $TRAVIS_OS_NAME = osx
Expand Down
2 changes: 1 addition & 1 deletion lib/basis_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ extern "C" KTX_API const ktx_uint32_t KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL
* @memberof ktxTexture2
* @ingroup writer
* @~English
* @brief Supercompress a KTX2 texture with uncpompressed images.
* @brief Supercompress a KTX2 texture with uncompressed images.
*
* The images are encoded to ETC1S block-compressed format and supercompressed
* with Basis Universal. The encoded images replace the original images and the
Expand Down
6 changes: 6 additions & 0 deletions lib/dfdutils/dfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents,
/* Return the number of components described by a DFD. */
uint32_t getDFDNumComponents(const uint32_t* DFD);

/* Recreate and return the value of bytesPlane0 as it should be for the data
* post-inflation from variable-rate compression.
*/
void
recreateBytesPlane0FromSampleInfo(const uint32_t* DFD, uint32_t* bytesPlane0);

typedef struct _Primaries {
float Rx;
float Ry;
Expand Down
2 changes: 1 addition & 1 deletion lib/dfdutils/interpretdfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ enum InterpretDFDResult interpretDFD(const uint32_t *DFD,
uint32_t currentBitOffset = 0;
uint32_t currentByteOffset = 0;
uint32_t currentBitLength = 0;
*wordBytes = (BDFDB[4] & 0xFFU);
*wordBytes = (BDFDB[KHR_DF_WORD_BYTESPLANE0] & 0xFFU);
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
uint32_t sampleBitOffset = KHR_DFDSVAL(BDFDB, sampleCounter, BITOFFSET);
uint32_t sampleByteOffset = sampleBitOffset >> 3U;
Expand Down
50 changes: 50 additions & 0 deletions lib/dfdutils/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <KHR/khr_df.h>
#include "dfd.h"

Expand Down Expand Up @@ -79,3 +81,51 @@ uint32_t getDFDNumComponents(const uint32_t* DFD)
}
return numComponents;
}

/**
* @~English
* @brief Recreate the value of bytesPlane0 from sample info.
*
* This can be use to recreate the value of bytesPlane0 for data that
* has been variable-rate compressed so has bytesPlane0 = 0. For DFDs
* that are valid for KTX files. Little-endian data only and no multi-plane
* formats.
*
* @param DFD Pointer to a Data Format Descriptor for which,
* described as 32-bit words in native endianness.
* Note that this is the whole descriptor, not just
* the basic descriptor block.
* @param bytesPlane0 pointer to a 32-bit word in which the recreated
* value of bytesPlane0 will be written.
*/
void
recreateBytesPlane0FromSampleInfo(const uint32_t* DFD, uint32_t* bytesPlane0)
{
const uint32_t *BDFDB = DFD+1;
uint32_t numSamples = KHR_DFDSAMPLECOUNT(BDFDB);
uint32_t sampleCounter;

uint32_t bitsPlane0 = 0;
int32_t* bitOffsets = malloc(sizeof(uint32_t) * numSamples);
memset(bitOffsets, -1, sizeof(uint32_t) * numSamples);
for (sampleCounter = 0; sampleCounter < numSamples; ++sampleCounter) {
uint32_t sampleBitOffset = KHR_DFDSVAL(BDFDB, sampleCounter, BITOFFSET);
/* The sample bitLength field stores the bit length - 1. */
uint32_t sampleBitLength = KHR_DFDSVAL(BDFDB, sampleCounter, BITLENGTH) + 1;
uint32_t i;
for (i = 0; i < numSamples; i++) {
if (sampleBitOffset == bitOffsets[i]) {
// This sample is being repeated as in e.g. RGB9E5.
break;
}
}
if (i == numSamples) {
// Previously unseen bitOffset. Bump size.
bitsPlane0 += sampleBitLength;
bitOffsets[sampleCounter] = sampleBitOffset;
}
}
free(bitOffsets);
*bytesPlane0 = bitsPlane0 >> 3U;
}

111 changes: 60 additions & 51 deletions lib/texture2.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ struct ktxTexture_vtblInt ktxTexture2_vtblInt;
bool
ktxFormatSize_initFromDfd(ktxFormatSize* This, ktx_uint32_t* pDfd)
{
bool notDepthStencil = false;
uint32_t* pBdb = pDfd + 1;
This->blockWidth = KHR_DFDVAL(pBdb, TEXELBLOCKDIMENSION0) + 1;
This->blockHeight = KHR_DFDVAL(pBdb, TEXELBLOCKDIMENSION1) + 1;
This->blockDepth = KHR_DFDVAL(pBdb, TEXELBLOCKDIMENSION2) + 1;
This->blockSizeInBits = KHR_DFDVAL(pBdb, BYTESPLANE0) * 8;
This->paletteSizeInBits = 0; // No paletted formats in ktx v2.
This->flags = 0;
if (KHR_DFDVAL(pBdb, MODEL) >= KHR_DF_MODEL_DXT1A) {
// A block compressed format. Entire block is a single sample.
Expand All @@ -84,17 +86,30 @@ ktxFormatSize_initFromDfd(ktxFormatSize* This, ktx_uint32_t* pDfd)
} else if (KHR_DFDSVAL(pBdb, 0, CHANNELID) == KHR_DF_CHANNEL_RGBSDA_STENCIL) {
This->flags |= KTX_FORMAT_SIZE_STENCIL_BIT;
} else {
InterpretedDFDChannel r, g, b, a;
InterpretedDFDChannel rgba[4];
uint32_t wordBytes;
enum InterpretDFDResult result;

result = interpretDFD(pDfd, &r, &g, &b, &a, &wordBytes);
result = interpretDFD(pDfd, &rgba[0], &rgba[1], &rgba[2], &rgba[3],
&wordBytes);
if (result >= i_UNSUPPORTED_ERROR_BIT)
return false;
if (result & i_PACKED_FORMAT_BIT)
This->flags |= KTX_FORMAT_SIZE_PACKED_BIT;
}
}
if (This->blockSizeInBits == 0) {
// The DFD shows a supercompressed texture. Complete the ktxFormatSize
// struct by figuring out the post inflation value for bytesPlane0.
// Setting it here simplifies stuff later in this file. Setting the
// post inflation block size here will not cause any problems for
// the following reasons. (1) in v2 files levelIndex is always used to
// calculate data size and, of course, for the level offsets. (2) Finer
// grain access to supercompressed data than levels is not possible.
uint32_t blockByteLength;
recreateBytesPlane0FromSampleInfo(pDfd, &blockByteLength);
This->blockSizeInBits = blockByteLength * 8;
}
return true;
}

Expand Down Expand Up @@ -1143,6 +1158,7 @@ ktxTexture2_calcDataSizeLevels(ktxTexture2* This, ktx_uint32_t levels)
ktx_size_t dataSize = 0;

assert(This != NULL);
assert(This->supercompressionScheme == KTX_SS_NONE);
assert(levels <= This->numLevels);
for (ktx_uint32_t i = levels - 1; i > 0; i--) {
ktx_size_t levelSize = ktxTexture_calcLevelSize(ktxTexture(This), i,
Expand All @@ -1164,6 +1180,8 @@ ktxTexture2_calcDataSizeLevels(ktxTexture2* This, ktx_uint32_t levels)
ktx_size_t
ktxTexture2_calcFaceLodSize(ktxTexture2* This, ktx_uint32_t level)
{
assert(This != NULL);
assert(This->supercompressionScheme == KTX_SS_NONE);
/*
* For non-array cubemaps this is the size of a face. For everything
* else it is the size of the level.
Expand Down Expand Up @@ -1193,6 +1211,7 @@ ktx_size_t
ktxTexture2_calcLevelOffset(ktxTexture2* This, ktx_uint32_t level)
{
assert (This != NULL);
assert(This->supercompressionScheme == KTX_SS_NONE);
assert (level < This->numLevels);
ktx_size_t levelOffset = 0;
for (ktx_uint32_t i = This->numLevels - 1; i > level; i--) {
Expand Down Expand Up @@ -1269,25 +1288,18 @@ lcm4(uint32_t a)
* @return The required alignment for levels.
*/
ktx_uint32_t
ktxTexture2_calcPostInflationBlockSizeAndAlignment(ktxTexture2* This,
ktx_uint32_t* pBlockByteLength)
ktxTexture2_calcPostInflationLevelAlignment(ktxTexture2* This)
{
ktx_uint32_t alignment;
ktx_uint32_t componentCount, componentByteLength;

// Should actually work for none supercompressed but don't want to
// encourage use of it.
assert(This->supercompressionScheme >= KTX_SS_ZSTD);

// This extracts the info based on samples and sample bit lengths which
// are still - supposed to be - valid for Zstd compressed textures.
getDFDComponentInfoUnpacked(This->pDfd, &componentCount,
&componentByteLength);
*pBlockByteLength = componentCount * componentByteLength;
if (This->vkFormat != VK_FORMAT_UNDEFINED)
alignment = lcm4(*pBlockByteLength);
else
alignment = 16;
ktx_uint32_t alignment;

// Should actually work for none supercompressed but don't want to
// encourage use of it.
assert(This->supercompressionScheme >= KTX_SS_ZSTD);

if (This->vkFormat != VK_FORMAT_UNDEFINED)
alignment = lcm4(This->_protected->_formatSize.blockSizeInBits / 8);
else
alignment = 16;

return alignment;
}
Expand All @@ -1300,7 +1312,7 @@ ktxTexture2_calcPostInflationBlockSizeAndAlignment(ktxTexture2* This,
*
* @param[in] This pointer to the ktxTexture object of interest.
* @param[in,out] pNumComponents pointer to location in which to write the
* number of ocmponents in the textures images.
* number of components in the textures images.
* @param[in,out] pComponentByteLength
* pointer to the location in which to write
* byte length of a component.
Expand Down Expand Up @@ -1474,27 +1486,27 @@ ktxTexture2_GetDataSizeUncompressed(ktxTexture2* This)
return This->dataSize;
case KTX_SS_ZSTD:
{
ktx_size_t uncompressedSize = 0;
ktx_uint32_t uncompressedLevelAlignment, unused;
ktxLevelIndexEntry* levelIndex = This->_private->_levelIndex;

uncompressedLevelAlignment =
ktxTexture2_calcPostInflationBlockSizeAndAlignment(This, &unused);

for (ktx_int32_t level = This->numLevels - 1; level >= 1; level--) {
ktx_size_t uncompressedLevelSize;
uncompressedLevelSize = levelIndex[level].uncompressedByteLength;
uncompressedLevelSize = _KTX_PADN(uncompressedLevelAlignment,
uncompressedLevelSize);
uncompressedSize += uncompressedLevelSize;
}
uncompressedSize += levelIndex[0].uncompressedByteLength;
return uncompressedSize;
ktx_size_t uncompressedSize = 0;
ktx_uint32_t uncompressedLevelAlignment;
ktxLevelIndexEntry* levelIndex = This->_private->_levelIndex;

uncompressedLevelAlignment =
ktxTexture2_calcPostInflationLevelAlignment(This);

for (ktx_int32_t level = This->numLevels - 1; level >= 1; level--) {
ktx_size_t uncompressedLevelSize;
uncompressedLevelSize = levelIndex[level].uncompressedByteLength;
uncompressedLevelSize = _KTX_PADN(uncompressedLevelAlignment,
uncompressedLevelSize);
uncompressedSize += uncompressedLevelSize;
}
uncompressedSize += levelIndex[0].uncompressedByteLength;
return uncompressedSize;
}
case KTX_SS_BEGIN_VENDOR_RANGE:
case KTX_SS_END_VENDOR_RANGE:
case KTX_SS_BEGIN_RESERVED:
default:
default:
return 0;
}
}
Expand Down Expand Up @@ -1686,12 +1698,8 @@ ktxTexture2_IterateLoadLevelFaces(ktxTexture2* This, PFNKTXITERCB iterCb,
}
dctx = ZSTD_createDCtx();
pData = uncompressedDataBuf;
(void)ktxTexture2_calcPostInflationBlockSizeAndAlignment(This,
&blockByteLength);
// TODO: Should we fix up the texture's formatSize and dataSize?
} else {
pData = dataBuf;
blockByteLength = prtctd->_formatSize.blockSizeInBits / 8;
}

for (ktx_int32_t level = This->numLevels - 1; level >= 0; --level)
Expand Down Expand Up @@ -1738,7 +1746,9 @@ ktxTexture2_IterateLoadLevelFaces(ktxTexture2* This, PFNKTXITERCB iterCb,
return KTX_FILE_DATA_ERROR;
}
}
// TODO: Should we fix up the levelIndex?
// We don't fix up the texture's dataSize, levelIndex or
// _requiredAlignment because after this function completes there
// is no way to get at the texture's data.
//nindex[level].byteOffset = levelOffset;
//nindex[level].uncompressedByteLength = nindex[level].byteLength =
//levelByteLength;
Expand Down Expand Up @@ -1775,7 +1785,8 @@ ktxTexture2_IterateLoadLevelFaces(ktxTexture2* This, PFNKTXITERCB iterCb,
= (uint32_t)ceilf((float)height / prtctd->_formatSize.blockHeight);
blockCount.x = MAX(1, blockCount.x);
blockCount.y = MAX(1, blockCount.y);
faceSize = blockCount.x * blockCount.y * blockByteLength;
faceSize = blockCount.x * blockCount.y
* prtctd->_formatSize.blockSizeInBits / 8;

for (ktx_uint32_t face = 0; face < This->numFaces; ++face) {
result = iterCb(level, face,
Expand Down Expand Up @@ -1971,12 +1982,12 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData,
ktx_uint8_t* pInflatedData,
ktx_size_t inflatedDataCapacity)
{
DECLARE_PROTECTED(ktxTexture);
ktx_uint32_t levelIndexByteLength =
This->numLevels * sizeof(ktxLevelIndexEntry);
uint32_t levelOffset = 0;
ktxLevelIndexEntry* cindex = This->_private->_levelIndex;
ktxLevelIndexEntry* nindex;
ktx_uint32_t blockByteLength;
ktx_uint32_t uncompressedLevelAlignment;

ZSTD_DCtx* dctx = ZSTD_createDCtx();
Expand All @@ -1995,8 +2006,7 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData,
return KTX_OUT_OF_MEMORY;

uncompressedLevelAlignment =
ktxTexture2_calcPostInflationBlockSizeAndAlignment(This,
&blockByteLength);
ktxTexture2_calcPostInflationLevelAlignment(This);

ktx_size_t inflatedByteLength = 0;
for (int32_t level = This->numLevels - 1; level >= 0; level--) {
Expand Down Expand Up @@ -2030,12 +2040,11 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData,
This->dataSize = inflatedByteLength;
This->supercompressionScheme = KTX_SS_NONE;
memcpy(cindex, nindex, levelIndexByteLength); // Update level index
This->_private->_requiredLevelAlignment = uncompressedLevelAlignment;
// Set bytesPlane as we're now sized.
uint32_t* bdb = This->pDfd + 1;
// bytesPlane0 = componentCount * componentByteLength, bytesPlane3..1 = 0
bdb[KHR_DF_WORD_BYTESPLANE0] = blockByteLength;
ktxFormatSize_initFromDfd(&This->_protected->_formatSize, This->pDfd);
This->_private->_requiredLevelAlignment = uncompressedLevelAlignment;
// blockSizeInBits was set to the inflated size on file load.
bdb[KHR_DF_WORD_BYTESPLANE0] = prtctd->_formatSize.blockSizeInBits / 8;

return KTX_SUCCESS;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/loadtests/compile_shader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,35 @@ function(compile_shader shader_target shader_name shader_src_path shader_path)
set(SHADER_SOURCES ${SHADER_SOURCES} ${frag2spirv_out} ${vert2spirv_out} PARENT_SCOPE)

endfunction(compile_shader)

function(compile_shader_list shader_target shader_src_path shader_path)

foreach(shader ${ARGN})
set(spirv_in "${shader_src_path}/${shader}")
set(spirv_out "${CMAKE_CURRENT_BINARY_DIR}/${shader_path}/${shader}.spv")

add_custom_command(OUTPUT
${spirv_out}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${shader_path}
COMMAND glslc -o "${spirv_out}" "${spirv_in}"
DEPENDS ${spirv_in}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMENT "Compiling ${shader}."
VERBATIM
)

list(APPEND inputs ${spirv_in})
list(APPEND outputs ${spirv_out})
endforeach()

add_custom_target(
${shader_target}
DEPENDS ${outputs}
SOURCES ${inputs}
)

set_target_properties(${shader_target} PROPERTIES EXCLUDE_FROM_ALL "FALSE")

set(SHADER_SOURCES ${SHADER_SOURCES} ${outputs} PARENT_SCOPE)

endfunction()
Loading

0 comments on commit 43ef010

Please sign in to comment.