mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 05:52:31 +02:00
Adjust handling of requested mips in gl backend
This commit is contained in:
parent
472c888529
commit
d5f1e6fb37
5 changed files with 28 additions and 19 deletions
|
@ -450,7 +450,7 @@ void GLVariableAllocationSupport::updateMemoryPressure() {
|
||||||
// Track how much we're actually using
|
// Track how much we're actually using
|
||||||
totalVariableMemoryAllocation += gltexture->size();
|
totalVariableMemoryAllocation += gltexture->size();
|
||||||
canDemote |= vartexture->canDemote();
|
canDemote |= vartexture->canDemote();
|
||||||
canPromote |= vartexture->canPromote();
|
canPromote |= vartexture->canPromote() || (texture->minAvailableMipLevel() < vartexture->_allocatedMip);
|
||||||
hasTransfers |= vartexture->hasPendingTransfers();
|
hasTransfers |= vartexture->hasPendingTransfers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,18 +98,14 @@ void GL45ResourceTexture::copyMipsFromTexture() {
|
||||||
void GL45ResourceTexture::syncSampler() const {
|
void GL45ResourceTexture::syncSampler() const {
|
||||||
Parent::syncSampler();
|
Parent::syncSampler();
|
||||||
qDebug() << "glTextureParameteri " << QString::fromStdString(_source) << _populatedMip << _populatedMip - _allocatedMip;
|
qDebug() << "glTextureParameteri " << QString::fromStdString(_source) << _populatedMip << _populatedMip - _allocatedMip;
|
||||||
if (_source == "test" && _populatedMip == 0) {
|
|
||||||
qDebug() << "here";
|
|
||||||
}
|
|
||||||
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip);
|
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, _populatedMip - _allocatedMip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GL45ResourceTexture::promote() {
|
void GL45ResourceTexture::promote() {
|
||||||
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
|
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
|
||||||
//Q_ASSERT(_allocatedMip > 0);
|
//Q_ASSERT(_allocatedMip > 0);
|
||||||
uint16_t sourceMip = _populatedMip;
|
if (!_gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0)) {
|
||||||
if (!_gpuObject.isStoredMipFaceAvailable(sourceMip, 0)) {
|
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(_populatedMip - 1);
|
||||||
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(sourceMip);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GLuint oldId = _id;
|
GLuint oldId = _id;
|
||||||
|
|
|
@ -123,8 +123,9 @@ uint16 KtxStorage::minAvailableMipLevel() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& storage) {
|
void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& storage) {
|
||||||
|
qDebug() << "Populating " << level << " " << _filename.c_str();
|
||||||
if (level != _minMipLevelAvailable - 1) {
|
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");
|
//throw std::runtime_error("Invalid image size for level");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace ktx {
|
||||||
|
|
||||||
bool checkIdentifier(const Byte* identifier) {
|
bool checkIdentifier(const Byte* identifier) {
|
||||||
if (!(0 == memcmp(identifier, Header::IDENTIFIER.data(), Header::IDENTIFIER_LENGTH))) {
|
if (!(0 == memcmp(identifier, Header::IDENTIFIER.data(), Header::IDENTIFIER_LENGTH))) {
|
||||||
throw ReaderException("identifier field invalid");
|
//throw ReaderException("identifier field invalid");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -353,7 +353,8 @@ void NetworkTexture::makeRequest() {
|
||||||
_ktxHeaderRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
_ktxHeaderRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
||||||
|
|
||||||
if (!_ktxHeaderRequest) {
|
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));
|
PROFILE_ASYNC_END(resource, "Resource:" + getType(), QString::number(_requestID));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -424,6 +425,13 @@ void NetworkTexture::startMipRangeRequest(uint16_t low, uint16_t high) {
|
||||||
|
|
||||||
_ktxMipRequest = ResourceManager::createResourceRequest(this, _activeUrl);
|
_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 };
|
_ktxMipLevelRangeInFlight = { low, high };
|
||||||
if (isHighMipRequest) {
|
if (isHighMipRequest) {
|
||||||
// This is a special case where we load the high 7 mips
|
// 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() {
|
void NetworkTexture::ktxHeaderRequestFinished() {
|
||||||
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA);
|
Q_ASSERT(_ktxResourceState == LOADING_INITIAL_DATA);
|
||||||
|
|
||||||
_ktxHeaderRequestFinished = true;
|
_ktxHeaderRequestFinished = true;
|
||||||
maybeHandleFinishedInitialLoad();
|
maybeHandleFinishedInitialLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkTexture::ktxMipRequestFinished() {
|
void NetworkTexture::ktxMipRequestFinished() {
|
||||||
|
@ -470,10 +478,11 @@ void NetworkTexture::ktxMipRequestFinished() {
|
||||||
|
|
||||||
auto texture = _textureSource->getGPUTexture();
|
auto texture = _textureSource->getGPUTexture();
|
||||||
if (texture) {
|
if (texture) {
|
||||||
_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first;
|
//_lowestKnownPopulatedMip = _ktxMipLevelRangeInFlight.first;
|
||||||
//qDebug() << "Writing mip for " << _url;
|
//qDebug() << "Writing mip for " << _url;
|
||||||
texture->assignStoredMip(_ktxMipLevelRangeInFlight.first,
|
texture->assignStoredMip(_ktxMipLevelRangeInFlight.first,
|
||||||
_ktxMipRequest->getData().size(), reinterpret_cast<uint8_t*>(_ktxMipRequest->getData().data()));
|
_ktxMipRequest->getData().size(), reinterpret_cast<uint8_t*>(_ktxMipRequest->getData().data()));
|
||||||
|
_lowestKnownPopulatedMip = _textureSource->getGPUTexture()->minAvailableMipLevel();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qWarning(networking) << "Trying to update mips but texture is null";
|
qWarning(networking) << "Trying to update mips but texture is null";
|
||||||
|
@ -529,11 +538,6 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
auto ktxHeaderData = _ktxHeaderRequest->getData();
|
auto ktxHeaderData = _ktxHeaderRequest->getData();
|
||||||
auto ktxHighMipData = _ktxMipRequest->getData();
|
auto ktxHighMipData = _ktxMipRequest->getData();
|
||||||
|
|
||||||
_ktxHeaderRequest->deleteLater();
|
|
||||||
_ktxHeaderRequest = nullptr;
|
|
||||||
_ktxMipRequest->deleteLater();
|
|
||||||
_ktxMipRequest = nullptr;
|
|
||||||
|
|
||||||
auto header = reinterpret_cast<const ktx::Header*>(ktxHeaderData.data());
|
auto header = reinterpret_cast<const ktx::Header*>(ktxHeaderData.data());
|
||||||
|
|
||||||
qDebug() << "Creating KTX";
|
qDebug() << "Creating KTX";
|
||||||
|
@ -548,10 +552,11 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
qWarning() << "Cannot load " << _url << ", invalid header identifier";
|
qWarning() << "Cannot load " << _url << ", invalid header identifier";
|
||||||
_ktxResourceState = FAILED_TO_LOAD;
|
_ktxResourceState = FAILED_TO_LOAD;
|
||||||
finishedLoading(false);
|
finishedLoading(false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto kvSize = header->bytesOfKeyValueData;
|
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";
|
qWarning() << "Cannot load " << _url << ", did not receive all kv data with initial request";
|
||||||
_ktxResourceState = FAILED_TO_LOAD;
|
_ktxResourceState = FAILED_TO_LOAD;
|
||||||
finishedLoading(false);
|
finishedLoading(false);
|
||||||
|
@ -663,11 +668,18 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lowestKnownPopulatedMip = texture->minAvailableMipLevel();
|
||||||
|
|
||||||
|
|
||||||
texture->registerMipInterestListener(this);
|
texture->registerMipInterestListener(this);
|
||||||
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
|
_ktxResourceState = WAITING_FOR_MIP_REQUEST;
|
||||||
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
|
setImage(texture, header->getPixelWidth(), header->getPixelHeight());
|
||||||
qDebug() << "Loaded KTX: " << QString::fromStdString(hash) << " : " << _url;
|
qDebug() << "Loaded KTX: " << QString::fromStdString(hash) << " : " << _url;
|
||||||
|
|
||||||
|
_ktxHeaderRequest->deleteLater();
|
||||||
|
_ktxHeaderRequest = nullptr;
|
||||||
|
_ktxMipRequest->deleteLater();
|
||||||
|
_ktxMipRequest = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue