mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 21:03:17 +02:00
Adjust gl45 backend to request interest in mips and keep track of min requested
This commit is contained in:
parent
970be9d2c5
commit
14f8c91e23
4 changed files with 17 additions and 11 deletions
|
@ -117,6 +117,8 @@ public:
|
||||||
|
|
||||||
void allocateStorage(uint16 mip);
|
void allocateStorage(uint16 mip);
|
||||||
void copyMipsFromTexture();
|
void copyMipsFromTexture();
|
||||||
|
|
||||||
|
uint16 _lowestRequestedMip { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -119,8 +119,10 @@ GL45Texture::GL45Texture(const std::weak_ptr<GLBackend>& backend, const Texture&
|
||||||
GLuint GL45Texture::allocate(const Texture& texture) {
|
GLuint GL45Texture::allocate(const Texture& texture) {
|
||||||
GLuint result;
|
GLuint result;
|
||||||
glCreateTextures(getGLTextureType(texture), 1, &result);
|
glCreateTextures(getGLTextureType(texture), 1, &result);
|
||||||
|
#ifdef DEBUG
|
||||||
auto source = texture.source();
|
auto source = texture.source();
|
||||||
glObjectLabel(GL_TEXTURE, result, source.length(), source.data());
|
glObjectLabel(GL_TEXTURE, result, source.length(), source.data());
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,11 @@ void GL45ResourceTexture::allocateStorage(uint16 allocatedMip) {
|
||||||
for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) {
|
for (uint16_t mip = _allocatedMip; mip < mipLevels; ++mip) {
|
||||||
_size += _gpuObject.evalMipSize(mip);
|
_size += _gpuObject.evalMipSize(mip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_gpuObject.isStoredMipFaceAvailable(allocatedMip, 0)) {
|
||||||
|
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(allocatedMip);
|
||||||
|
}
|
||||||
|
|
||||||
Backend::updateTextureGPUMemoryUsage(0, _size);
|
Backend::updateTextureGPUMemoryUsage(0, _size);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -98,9 +103,11 @@ void GL45ResourceTexture::syncSampler() const {
|
||||||
|
|
||||||
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);
|
||||||
if (!_gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0)) {
|
uint16_t targetAllocatedMip = _allocatedMip - std::min<uint16_t>(_allocatedMip, 2);
|
||||||
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(_populatedMip - 1);
|
if (!_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) {
|
||||||
|
_lowestRequestedMip = targetAllocatedMip;
|
||||||
|
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(targetAllocatedMip);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GLuint oldId = _id;
|
GLuint oldId = _id;
|
||||||
|
@ -109,7 +116,7 @@ void GL45ResourceTexture::promote() {
|
||||||
const_cast<GLuint&>(_id) = allocate(_gpuObject);
|
const_cast<GLuint&>(_id) = allocate(_gpuObject);
|
||||||
uint16_t oldAllocatedMip = _allocatedMip;
|
uint16_t oldAllocatedMip = _allocatedMip;
|
||||||
// allocate storage for new level
|
// allocate storage for new level
|
||||||
allocateStorage(_allocatedMip - std::min<uint16_t>(_allocatedMip, 2));
|
allocateStorage(targetAllocatedMip);
|
||||||
uint16_t mips = _gpuObject.getNumMips();
|
uint16_t mips = _gpuObject.getNumMips();
|
||||||
// copy pre-existing mips
|
// copy pre-existing mips
|
||||||
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
for (uint16_t mip = _populatedMip; mip < mips; ++mip) {
|
||||||
|
@ -176,23 +183,21 @@ void GL45ResourceTexture::populateTransferQueue() {
|
||||||
|
|
||||||
const uint8_t maxFace = GLTexture::getFaceCount(_target);
|
const uint8_t maxFace = GLTexture::getFaceCount(_target);
|
||||||
uint16_t sourceMip = _populatedMip;
|
uint16_t sourceMip = _populatedMip;
|
||||||
//qDebug() << "populateTransferQueue info : " << _populatedMip << " " << _maxAllocatedMip << " " << _allocatedMip;
|
|
||||||
do {
|
do {
|
||||||
--sourceMip;
|
--sourceMip;
|
||||||
auto targetMip = sourceMip - _allocatedMip;
|
auto targetMip = sourceMip - _allocatedMip;
|
||||||
auto mipDimensions = _gpuObject.evalMipDimensions(sourceMip);
|
auto mipDimensions = _gpuObject.evalMipDimensions(sourceMip);
|
||||||
bool transferQueued = false;
|
bool transferQueued = false;
|
||||||
//qDebug() << "populateTransferQueue " << QString::fromStdString(_gpuObject.source()) << sourceMip << " " << targetMip;
|
|
||||||
for (uint8_t face = 0; face < maxFace; ++face) {
|
for (uint8_t face = 0; face < maxFace; ++face) {
|
||||||
if (!_gpuObject.isStoredMipFaceAvailable(sourceMip, face)) {
|
if (!_gpuObject.isStoredMipFaceAvailable(sourceMip, face)) {
|
||||||
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(sourceMip);
|
const_cast<gpu::Texture&>(_gpuObject).requestInterestInMip(sourceMip);
|
||||||
_minRequestedMip = sourceMip;
|
_lowestRequestedMip = sourceMip;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
_lowestRequestedMip = sourceMip;
|
||||||
|
|
||||||
// If the mip is less than the max transfer size, then just do it in one transfer
|
// If the mip is less than the max transfer size, then just do it in one transfer
|
||||||
if (glm::all(glm::lessThanEqual(mipDimensions, MAX_TRANSFER_DIMENSIONS))) {
|
if (glm::all(glm::lessThanEqual(mipDimensions, MAX_TRANSFER_DIMENSIONS))) {
|
||||||
qDebug() << "mip is less than max transfer size";
|
|
||||||
// Can the mip be transferred in one go
|
// Can the mip be transferred in one go
|
||||||
_pendingTransfers.emplace(new TransferJob(*this, sourceMip, targetMip, face));
|
_pendingTransfers.emplace(new TransferJob(*this, sourceMip, targetMip, face));
|
||||||
transferQueued = true;
|
transferQueued = true;
|
||||||
|
@ -207,14 +212,12 @@ void GL45ResourceTexture::populateTransferQueue() {
|
||||||
Q_ASSERT(0 == (mipSize % lines));
|
Q_ASSERT(0 == (mipSize % lines));
|
||||||
uint32_t linesPerTransfer = (uint32_t)(MAX_TRANSFER_SIZE / bytesPerLine);
|
uint32_t linesPerTransfer = (uint32_t)(MAX_TRANSFER_SIZE / bytesPerLine);
|
||||||
uint32_t lineOffset = 0;
|
uint32_t lineOffset = 0;
|
||||||
qDebug() << "queing up single line transfers " << linesPerTransfer << " " << lineOffset;
|
|
||||||
while (lineOffset < lines) {
|
while (lineOffset < lines) {
|
||||||
uint32_t linesToCopy = std::min<uint32_t>(lines - lineOffset, linesPerTransfer);
|
uint32_t linesToCopy = std::min<uint32_t>(lines - lineOffset, linesPerTransfer);
|
||||||
_pendingTransfers.emplace(new TransferJob(*this, sourceMip, targetMip, face, linesToCopy, lineOffset));
|
_pendingTransfers.emplace(new TransferJob(*this, sourceMip, targetMip, face, linesToCopy, lineOffset));
|
||||||
lineOffset += linesToCopy;
|
lineOffset += linesToCopy;
|
||||||
transferQueued = true;
|
transferQueued = true;
|
||||||
}
|
}
|
||||||
_minRequestedMip = std::min(_minRequestedMip, sourceMip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// queue up the sampler and populated mip change for after the transfer has completed
|
// queue up the sampler and populated mip change for after the transfer has completed
|
||||||
|
|
|
@ -397,7 +397,6 @@ Size Texture::evalTotalSize(uint16 startingMip) const {
|
||||||
Size size = 0;
|
Size size = 0;
|
||||||
uint16 minMipLevel = std::max(getMinMip(), startingMip);
|
uint16 minMipLevel = std::max(getMinMip(), startingMip);
|
||||||
uint16 maxMipLevel = getMaxMip();
|
uint16 maxMipLevel = getMaxMip();
|
||||||
qDebug() << " min: " << minMipLevel << " " << maxMipLevel;
|
|
||||||
for (uint16 level = minMipLevel; level <= maxMipLevel; level++) {
|
for (uint16 level = minMipLevel; level <= maxMipLevel; level++) {
|
||||||
size += evalMipSize(level);
|
size += evalMipSize(level);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue