Adjust handling of requested mips in gl backend

This commit is contained in:
Ryan Huffman 2017-04-19 17:01:36 -07:00 committed by Atlante45
parent 472c888529
commit d5f1e6fb37
5 changed files with 28 additions and 19 deletions

View file

@ -450,7 +450,7 @@ void GLVariableAllocationSupport::updateMemoryPressure() {
// Track how much we're actually using
totalVariableMemoryAllocation += gltexture->size();
canDemote |= vartexture->canDemote();
canPromote |= vartexture->canPromote();
canPromote |= vartexture->canPromote() || (texture->minAvailableMipLevel() < vartexture->_allocatedMip);
hasTransfers |= vartexture->hasPendingTransfers();
}

View file

@ -98,18 +98,14 @@ void GL45ResourceTexture::copyMipsFromTexture() {
void GL45ResourceTexture::syncSampler() const {
Parent::syncSampler();
qDebug() << "glTextureParameteri " << QString::fromStdString(_source) << _populatedMip << _populatedMip - _allocatedMip;
if (_source == "test" && _populatedMip == 0) {
qDebug() << "here";
}
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip);
}
void GL45ResourceTexture::promote() {
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
//Q_ASSERT(_allocatedMip > 0);
uint16_t sourceMip = _populatedMip;
if (!_gpuObject.isStoredMipFaceAvailable(sourceMip, 0)) {
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(sourceMip);
if (!_gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0)) {
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(_populatedMip - 1);
return;
}
GLuint oldId = _id;

View file

@ -123,8 +123,9 @@ uint16 KtxStorage::minAvailableMipLevel() const {
}
void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& storage) {
qDebug() << "Populating " << level << " " << _filename.c_str();
if (level != _minMipLevelAvailable - 1) {
qWarning() << "Invalid level to be stored, expected: " << (_minMipLevelAvailable - 1) << ", got: " << level;
qWarning() << "Invalid level to be stored, expected: " << (_minMipLevelAvailable - 1) << ", got: " << level << " " << _filename.c_str();
//throw std::runtime_error("Invalid image size for level");
return;
}

View file

@ -50,7 +50,7 @@ namespace ktx {
bool checkIdentifier(const Byte* identifier) {
if (!(0 == memcmp(identifier, Header::IDENTIFIER.data(), Header::IDENTIFIER_LENGTH))) {
throw ReaderException("identifier field invalid");
//throw ReaderException("identifier field invalid");
return false;
}
return true;

View file

@ -353,7 +353,8 @@ void NetworkTexture::makeRequest() {
_ktxHeaderRequest = ResourceManager::createResourceRequest(this, _activeUrl);
if (!_ktxHeaderRequest) {
//qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID));
return;
}
@ -424,6 +425,13 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) {
_ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl);
if (!_ktxMipRequest) {
qCDebug(networking).noquote() << "Failed to get request for" << _url.toDisplayString();
PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID));
return;
}
_ktxMipLevelRangeInFlight = { low, high };
if (isHighMipRequest) {
// This is a special case where we load the high 7 mips
@ -450,8 +458,8 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) {
void NetworkTexture::ktxHeaderRequestFinished() {
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA);
_ktxHeaderRequestFinished = true;
maybeHandleFinishedInitialLoad();
_ktxHeaderRequestFinished = true;
maybeHandleFinishedInitialLoad();
}
void NetworkTexture::ktxMipRequestFinished() {
@ -470,10 +478,11 @@ void NetworkTexture::ktxMipRequestFinished() {
auto texture = _textureSource->getGPUTexture();
if (texture) {
_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first;
//_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first;
//qDebug() << "Writing mip for " << _url;
texture->assignStoredMip(_ktxMipLevelRangeInFlight.first,
_ktxMipRequest->getData().size(), reinterpret_cast<uint8_t*>(_ktxMipRequest->getData().data()));
_lowestKnownPopulatedMip = _textureSource->getGPUTexture()->minAvailableMipLevel();
}
else {
qWarning(networking) << "Trying to update mips but texture is null";
@ -529,11 +538,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
auto ktxHeaderData = _ktxHeaderRequest->getData();
auto ktxHighMipData = _ktxMipRequest->getData();
_ktxHeaderRequest->deleteLater();
_ktxHeaderRequest = nullptr;
_ktxMipRequest->deleteLater();
_ktxMipRequest = nullptr;
auto header = reinterpret_cast<const ktx::Header*>(ktxHeaderData.data());
qDebug() << "Creating KTX";
@ -548,10 +552,11 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
qWarning() << "Cannot load " << _url << ", invalid header identifier";
_ktxResourceState = FAILED_TO_LOAD;
finishedLoading(false);
return;
}
auto kvSize = header->bytesOfKeyValueData;
if (kvSize > ktxHeaderData.size() - ktx::KTX_HEADER_SIZE) {
if (kvSize > (ktxHeaderData.size() - ktx::KTX_HEADER_SIZE)) {
qWarning() << "Cannot load " << _url << ", did not receive all kv data with initial request";
_ktxResourceState = FAILED_TO_LOAD;
finishedLoading(false);
@ -663,11 +668,18 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
}
}
_lowestKnownPopulatedMip = texture->minAvailableMipLevel();
texture->registerMipInterestListener(this);
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
qDebug() << "Loaded KTX: " << QString::fromStdString(hash) << " : " << _url;
_ktxHeaderRequest->deleteLater();
_ktxHeaderRequest = nullptr;
_ktxMipRequest->deleteLater();
_ktxMipRequest = nullptr;
}
}
}