Update gl41 an gl45 texture backends to take into account min avail mip

This commit is contained in:
Ryan Huffman 2017-04-26 10:04:52 -07:00 committed by Atlante45
parent 674e767513
commit b9ec573c8b
5 changed files with 28 additions and 10 deletions

View file

@ -100,7 +100,7 @@ public:
GL41VariableAllocationTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture);
~GL41VariableAllocationTexture();
bool canPopulate() const override { return _populatedMip > _allocatedMip && _gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0); }
bool canPopulate() const override { return _gpuObject.isStoredMipFaceAvailable(_populatedMip - 1, 0); }
void allocateStorage(uint16 allocatedMip);
void syncSampler() const override;
void promote() override;

View file

@ -231,15 +231,20 @@ using GL41VariableAllocationTexture = GL41Backend::GL41VariableAllocationTexture
GL41VariableAllocationTexture::GL41VariableAllocationTexture(const std::weak_ptr<GLBackend>& backend, const Texture& texture) : GL41Texture(backend, texture) {
auto mipLevels = texture.getNumMips();
_allocatedMip = mipLevels;
_maxAllocatedMip = _populatedMip = mipLevels;
uint16_t minAvailableMip = texture.minAvailableMipLevel();
uvec3 mipDimensions;
for (uint16_t mip = 0; mip < mipLevels; ++mip) {
if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS))) {
if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS))
&& mip >= minAvailableMip) {
_maxAllocatedMip = _populatedMip = mip;
break;
}
}
uint16_t allocatedMip = _populatedMip - std::min<uint16_t>(_populatedMip, 2);
auto targetMip = _populatedMip - std::min<uint16_t>(_populatedMip, 2);
uint16_t allocatedMip = std::max<uint16_t>(minAvailableMip, targetMip);
allocateStorage(allocatedMip);
_memoryPressureStateStale = true;
size_t maxFace = GLTexture::getFaceCount(_target);
@ -292,6 +297,14 @@ void GL41VariableAllocationTexture::syncSampler() const {
void GL41VariableAllocationTexture::promote() {
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
Q_ASSERT(_allocatedMip > 0);
uint16_t targetAllocatedMip = _allocatedMip - std::min<uint16_t>(_allocatedMip, 2);
targetAllocatedMip = std::max<uint16_t>(_gpuObject.minAvailableMipLevel(), targetAllocatedMip);
if (targetAllocatedMip >= _allocatedMip || !_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) {
return;
}
GLuint oldId = _id;
auto oldSize = _size;
// create new texture
@ -299,7 +312,7 @@ void GL41VariableAllocationTexture::promote() {
uint16_t oldAllocatedMip = _allocatedMip;
// allocate storage for new level
allocateStorage(_allocatedMip - std::min<uint16_t>(_allocatedMip, 2));
allocateStorage(targetAllocatedMip);
withPreservedTexture([&] {
GLuint fbo { 0 };

View file

@ -46,16 +46,20 @@ GL45ResourceTexture::GL45ResourceTexture(const std::weak_ptr<GLBackend>& backend
_maxAllocatedMip = _populatedMip = mipLevels;
uint16_t minAvailableMip = texture.minAvailableMipLevel();
uvec3 mipDimensions;
for (uint16_t mip = 0; mip < mipLevels; ++mip) {
if (glm::all(glm::lessThanEqual(texture.evalMipDimensions(mip), INITIAL_MIP_TRANSFER_DIMENSIONS))
&& texture.isStoredMipFaceAvailable(mip)) {
&& mip >= minAvailableMip) {
_maxAllocatedMip = _populatedMip = mip;
break;
}
}
uint16_t allocatedMip = _populatedMip - std::min<uint16_t>(_populatedMip, 2);
auto targetMip = _populatedMip - std::min<uint16_t>(_populatedMip, 2);
uint16_t allocatedMip = std::max<uint16_t>(minAvailableMip, targetMip);
allocateStorage(allocatedMip);
_memoryPressureStateStale = true;
copyMipsFromTexture();
@ -99,8 +103,11 @@ void GL45ResourceTexture::syncSampler() const {
void GL45ResourceTexture::promote() {
PROFILE_RANGE(render_gpu_gl, __FUNCTION__);
Q_ASSERT(_allocatedMip > 0);
uint16_t targetAllocatedMip = _allocatedMip - std::min<uint16_t>(_allocatedMip, 2);
if (!_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) {
targetAllocatedMip = std::max<uint16_t>(_gpuObject.minAvailableMipLevel(), targetAllocatedMip);
if (targetAllocatedMip >= _allocatedMip || !_gpuObject.isStoredMipFaceAvailable(targetAllocatedMip, 0)) {
return;
}
GLuint oldId = _id;

View file

@ -588,8 +588,7 @@ void NetworkTexture::maybeHandleFinishedInitialLoad() {
_ktxResourceState = FAILED_TO_LOAD;
finishedLoading(false);
return;
}
else {
} else {
_file = file;
}

View file

@ -46,7 +46,6 @@ class NetworkTexture : public Resource, public Texture {
public:
NetworkTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels);
~NetworkTexture() override;
QString getType() const override { return "NetworkTexture"; }