Fix AMD crash caused by missing glFlush

This commit is contained in:
Brad Davis 2016-10-14 16:25:23 -07:00
parent 72d3a594b2
commit 0be1f82bbc
3 changed files with 43 additions and 22 deletions

View file

@ -37,8 +37,7 @@ void TextureRecycler::clear() {
_allTextures.clear(); _allTextures.clear();
} }
uint32_t TextureRecycler::getNextTexture() { void TextureRecycler::addTexture() {
if (_readyTextures.empty()) {
uint32_t newTexture; uint32_t newTexture;
glGenTextures(1, &newTexture); glGenTextures(1, &newTexture);
glBindTexture(GL_TEXTURE_2D, newTexture); glBindTexture(GL_TEXTURE_2D, newTexture);
@ -58,6 +57,15 @@ uint32_t TextureRecycler::getNextTexture() {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, _size.x, _size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, _size.x, _size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
_allTextures.emplace(std::piecewise_construct, std::forward_as_tuple(newTexture), std::forward_as_tuple(newTexture, _size)); _allTextures.emplace(std::piecewise_construct, std::forward_as_tuple(newTexture), std::forward_as_tuple(newTexture, _size));
_readyTextures.push(newTexture); _readyTextures.push(newTexture);
}
uint32_t TextureRecycler::getNextTexture() {
while (_allTextures.size() < _textureCount) {
addTexture();
}
if (_readyTextures.empty()) {
addTexture();
} }
uint32_t result = _readyTextures.front(); uint32_t result = _readyTextures.front();

View file

@ -19,11 +19,13 @@ class TextureRecycler {
public: public:
TextureRecycler(bool useMipmaps) : _useMipmaps(useMipmaps) {} TextureRecycler(bool useMipmaps) : _useMipmaps(useMipmaps) {}
void setSize(const uvec2& size); void setSize(const uvec2& size);
void setTextureCount(uint8_t textureCount);
void clear(); void clear();
uint32_t getNextTexture(); uint32_t getNextTexture();
void recycleTexture(uint32_t texture); void recycleTexture(uint32_t texture);
private: private:
void addTexture();
struct TexInfo { struct TexInfo {
const uint32_t _tex{ 0 }; const uint32_t _tex{ 0 };
@ -42,6 +44,7 @@ private:
Queue _readyTextures; Queue _readyTextures;
uvec2 _size{ 1920, 1080 }; uvec2 _size{ 1920, 1080 };
bool _useMipmaps; bool _useMipmaps;
uint8_t _textureCount { 3 };
}; };
#endif #endif

View file

@ -663,11 +663,21 @@ void GLBackend::recycle() const {
Lock lock(_trashMutex); Lock lock(_trashMutex);
std::swap(_externalTexturesTrash, externalTexturesTrash); std::swap(_externalTexturesTrash, externalTexturesTrash);
} }
if (!externalTexturesTrash.empty()) {
std::vector<GLsync> fences;
fences.resize(externalTexturesTrash.size());
for (size_t i = 0; i < externalTexturesTrash.size(); ++i) {
fences[i] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
}
// External texture fences will be read in another thread/context, so we need a flush
glFlush();
size_t index = 0;
for (auto pair : externalTexturesTrash) { for (auto pair : externalTexturesTrash) {
auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); auto fence = fences[index++];
pair.second(pair.first, fence); pair.second(pair.first, fence);
} }
} }
}
{ {
std::list<GLuint> programsTrash; std::list<GLuint> programsTrash;