Merge pull request #13077 from jherico/fix/14638_rc67

Make resource swapchains immutable
This commit is contained in:
John Conklin II 2018-05-02 15:42:30 -07:00 committed by GitHub
commit f983714702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 28 deletions

View file

@ -46,10 +46,10 @@ void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) {
} }
void GLBackend::do_setFramebufferSwapChain(const Batch& batch, size_t paramOffset) { void GLBackend::do_setFramebufferSwapChain(const Batch& batch, size_t paramOffset) {
auto swapChain = batch._swapChains.get(batch._params[paramOffset]._uint); auto swapChain = std::static_pointer_cast<FramebufferSwapChain>(batch._swapChains.get(batch._params[paramOffset]._uint));
if (swapChain) { if (swapChain) {
auto index = batch._params[paramOffset + 1]._uint; auto index = batch._params[paramOffset + 1]._uint;
FramebufferPointer framebuffer = static_cast<const FramebufferSwapChain*>(swapChain.get())->get(index); const auto& framebuffer = swapChain->get(index);
setFramebuffer(framebuffer); setFramebuffer(framebuffer);
} }
} }

View file

@ -268,7 +268,7 @@ void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, si
return; return;
} }
SwapChainPointer swapChain = batch._swapChains.get(batch._params[paramOffset + 0]._uint); auto swapChain = std::static_pointer_cast<FramebufferSwapChain>(batch._swapChains.get(batch._params[paramOffset + 0]._uint));
if (!swapChain) { if (!swapChain) {
releaseResourceTexture(slot); releaseResourceTexture(slot);
@ -276,9 +276,8 @@ void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, si
} }
auto index = batch._params[paramOffset + 2]._uint; auto index = batch._params[paramOffset + 2]._uint;
auto renderBufferSlot = batch._params[paramOffset + 3]._uint; auto renderBufferSlot = batch._params[paramOffset + 3]._uint;
FramebufferPointer resourceFramebuffer = static_cast<const FramebufferSwapChain*>(swapChain.get())->get(index); auto resourceFramebuffer = swapChain->get(index);
TexturePointer resourceTexture = resourceFramebuffer->getRenderBuffer(renderBufferSlot); auto resourceTexture = resourceFramebuffer->getRenderBuffer(renderBufferSlot);
setResourceTexture(slot, resourceTexture); setResourceTexture(slot, resourceTexture);
} }

View file

@ -15,18 +15,18 @@ namespace gpu {
class SwapChain { class SwapChain {
public: public:
SwapChain(unsigned int size = 2U) : _size{ size } {} SwapChain(uint8_t size = 2U) : _size{ size } {}
virtual ~SwapChain() {} virtual ~SwapChain() {}
void advance() { void advance() {
_frontIndex = (_frontIndex + 1) % _size; _frontIndex = (_frontIndex + 1) % _size;
} }
unsigned int getSize() const { return _size; } uint8_t getSize() const { return _size; }
protected: protected:
unsigned int _size; const uint8_t _size;
unsigned int _frontIndex{ 0U }; uint8_t _frontIndex{ 0U };
}; };
typedef std::shared_ptr<SwapChain> SwapChainPointer; typedef std::shared_ptr<SwapChain> SwapChainPointer;
@ -41,16 +41,13 @@ namespace gpu {
using Type = R; using Type = R;
using TypePointer = std::shared_ptr<R>; using TypePointer = std::shared_ptr<R>;
using TypeConstPointer = std::shared_ptr<const R>;
ResourceSwapChain(unsigned int size = 2U) : SwapChain{ size } {} ResourceSwapChain(const std::vector<TypePointer>& v) : SwapChain{ std::min<uint8_t>((uint8_t)v.size(), MAX_SIZE) } {
for (size_t i = 0; i < _size; ++i) {
void reset() { _resources[i] = v[i];
for (auto& ptr : _resources) {
ptr.reset();
} }
} }
TypePointer& edit(unsigned int index) { return _resources[(index + _frontIndex) % _size]; }
const TypePointer& get(unsigned int index) const { return _resources[(index + _frontIndex) % _size]; } const TypePointer& get(unsigned int index) const { return _resources[(index + _frontIndex) % _size]; }
private: private:

View file

@ -189,7 +189,6 @@ const int AntialiasingPass_NextMapSlot = 4;
Antialiasing::Antialiasing(bool isSharpenEnabled) : Antialiasing::Antialiasing(bool isSharpenEnabled) :
_isSharpenEnabled{ isSharpenEnabled } { _isSharpenEnabled{ isSharpenEnabled } {
_antialiasingBuffers = std::make_shared<gpu::FramebufferSwapChain>(2U);
} }
Antialiasing::~Antialiasing() { Antialiasing::~Antialiasing() {
@ -321,25 +320,25 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
int width = sourceBuffer->getWidth(); int width = sourceBuffer->getWidth();
int height = sourceBuffer->getHeight(); int height = sourceBuffer->getHeight();
if (_antialiasingBuffers->get(0)) { if (_antialiasingBuffers && _antialiasingBuffers->get(0) && _antialiasingBuffers->get(0)->getSize() != uvec2(width, height)) {
if (_antialiasingBuffers->get(0)->getSize() != uvec2(width, height)) {// || (sourceBuffer && (_antialiasingBuffer->getRenderBuffer(1) != sourceBuffer->getRenderBuffer(0)))) { _antialiasingBuffers.reset();
_antialiasingBuffers->edit(0).reset(); _antialiasingTextures[0].reset();
_antialiasingBuffers->edit(1).reset(); _antialiasingTextures[1].reset();
_antialiasingTextures[0].reset();
_antialiasingTextures[1].reset();
}
} }
if (!_antialiasingBuffers->get(0)) {
if (!_antialiasingBuffers) {
std::vector<gpu::FramebufferPointer> antiAliasingBuffers;
// Link the antialiasing FBO to texture // Link the antialiasing FBO to texture
auto format = sourceBuffer->getRenderBuffer(0)->getTexelFormat(); auto format = sourceBuffer->getRenderBuffer(0)->getTexelFormat();
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR, gpu::Sampler::WRAP_CLAMP); auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR, gpu::Sampler::WRAP_CLAMP);
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
auto& antiAliasingBuffer = _antialiasingBuffers->edit(i); antiAliasingBuffers.emplace_back(gpu::Framebuffer::create("antialiasing"));
antiAliasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing")); const auto& antiAliasingBuffer = antiAliasingBuffers.back();
_antialiasingTextures[i] = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler); _antialiasingTextures[i] = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler);
antiAliasingBuffer->setRenderBuffer(0, _antialiasingTextures[i]); antiAliasingBuffer->setRenderBuffer(0, _antialiasingTextures[i]);
} }
_antialiasingBuffers = std::make_shared<gpu::FramebufferSwapChain>(antiAliasingBuffers);
} }
gpu::doInBatch("Antialiasing::run", args->_context, [&](gpu::Batch& batch) { gpu::doInBatch("Antialiasing::run", args->_context, [&](gpu::Batch& batch) {