Working ring frame buffer with antialiasing but still issues with TAA on HMD

This commit is contained in:
Olivier Prat 2018-02-20 09:22:19 +01:00
parent 18af60f3eb
commit 247a1f5769
7 changed files with 88 additions and 27 deletions

View file

@ -99,12 +99,16 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
(&::gpu::gl::GLBackend::do_setUniformBuffer),
(&::gpu::gl::GLBackend::do_setResourceBuffer),
(&::gpu::gl::GLBackend::do_setResourceTexture),
(&::gpu::gl::GLBackend::do_setResourceFramebufferRingTexture),
(&::gpu::gl::GLBackend::do_setFramebuffer),
(&::gpu::gl::GLBackend::do_setFramebufferRing),
(&::gpu::gl::GLBackend::do_clearFramebuffer),
(&::gpu::gl::GLBackend::do_blit),
(&::gpu::gl::GLBackend::do_generateTextureMips),
(&::gpu::gl::GLBackend::do_advance),
(&::gpu::gl::GLBackend::do_beginQuery),
(&::gpu::gl::GLBackend::do_endQuery),
(&::gpu::gl::GLBackend::do_getQuery),

View file

@ -126,15 +126,19 @@ public:
// Resource Stage
virtual void do_setResourceBuffer(const Batch& batch, size_t paramOffset) final;
virtual void do_setResourceTexture(const Batch& batch, size_t paramOffset) final;
virtual void do_setResourceFramebufferRingTexture(const Batch& batch, size_t paramOffset) final;
// Pipeline Stage
virtual void do_setPipeline(const Batch& batch, size_t paramOffset) final;
// Output stage
virtual void do_setFramebuffer(const Batch& batch, size_t paramOffset) final;
virtual void do_setFramebufferRing(const Batch& batch, size_t paramOffset) final;
virtual void do_clearFramebuffer(const Batch& batch, size_t paramOffset) final;
virtual void do_blit(const Batch& batch, size_t paramOffset) = 0;
virtual void do_advance(const Batch& batch, size_t paramOffset) final;
// Query section
virtual void do_beginQuery(const Batch& batch, size_t paramOffset) final;
virtual void do_endQuery(const Batch& batch, size_t paramOffset) final;
@ -245,6 +249,8 @@ protected:
void setupStereoSide(int side);
#endif
virtual void setResourceTexture(unsigned int slot, const TexturePointer& resourceTexture);
virtual void setFramebuffer(const FramebufferPointer& framebuffer);
virtual void initInput() final;
virtual void killInput() final;
virtual void syncInputStateCache() final;

View file

@ -37,6 +37,19 @@ void GLBackend::resetOutputStage() {
void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) {
auto framebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint);
setFramebuffer(framebuffer);
}
void GLBackend::do_setFramebufferRing(const Batch& batch, size_t paramOffset) {
auto ringbuffer = batch._ringbuffers.get(batch._params[paramOffset]._uint);
if (ringbuffer) {
auto index = batch._params[paramOffset + 1]._uint;
FramebufferPointer framebuffer = static_cast<const FramebufferRing*>(ringbuffer.get())->get(index);
setFramebuffer(framebuffer);
}
}
void GLBackend::setFramebuffer(const FramebufferPointer& framebuffer) {
if (_output._framebuffer != framebuffer) {
auto newFBO = getFramebufferID(framebuffer);
if (_output._drawFBO != newFBO) {
@ -47,6 +60,13 @@ void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) {
}
}
void GLBackend::do_advance(const Batch& batch, size_t paramOffset) {
auto ringbuffer = batch._ringbuffers.get(batch._params[paramOffset]._uint);
if (ringbuffer) {
ringbuffer->advance();
}
}
void GLBackend::do_clearFramebuffer(const Batch& batch, size_t paramOffset) {
if (_stereo.isStereo() && !_pipeline._stateCache.scissorEnable) {
qWarning("Clear without scissor in stereo mode");

View file

@ -253,6 +253,31 @@ void GLBackend::do_setResourceTexture(const Batch& batch, size_t paramOffset) {
releaseResourceTexture(slot);
return;
}
setResourceTexture(slot, resourceTexture);
}
void GLBackend::do_setResourceFramebufferRingTexture(const Batch& batch, size_t paramOffset) {
GLuint slot = batch._params[paramOffset + 1]._uint;
if (slot >= (GLuint)MAX_NUM_RESOURCE_TEXTURES) {
qCDebug(gpugllogging) << "GLBackend::do_setResourceFramebufferRingTexture: Trying to set a resource Texture at slot #" << slot << " which doesn't exist. MaxNumResourceTextures = " << getMaxNumResourceTextures();
return;
}
RingBufferPointer ringBuffer = batch._ringbuffers.get(batch._params[paramOffset + 0]._uint);
if (!ringBuffer) {
releaseResourceTexture(slot);
return;
}
auto index = batch._params[paramOffset + 2]._uint;
auto renderBufferSlot = batch._params[paramOffset + 3]._uint;
FramebufferPointer resourceFramebuffer = static_cast<const FramebufferRing*>(ringBuffer.get())->get(index);
TexturePointer resourceTexture = resourceFramebuffer->getRenderBuffer(renderBufferSlot);
setResourceTexture(slot, resourceTexture);
}
void GLBackend::setResourceTexture(unsigned int slot, const TexturePointer& resourceTexture) {
// check cache before thinking
if (_resource._textures[slot] == resourceTexture) {
return;
@ -269,11 +294,11 @@ void GLBackend::do_setResourceTexture(const Batch& batch, size_t paramOffset) {
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(target, to);
(void) CHECK_GL_ERROR();
(void)CHECK_GL_ERROR();
_resource._textures[slot] = resourceTexture;
_stats._RSAmountTextureMemoryBounded += (int) object->size();
_stats._RSAmountTextureMemoryBounded += (int)object->size();
} else {
releaseResourceTexture(slot);

View file

@ -73,6 +73,7 @@ Batch::Batch(const Batch& batch_) {
_transforms._items.swap(batch._transforms._items);
_pipelines._items.swap(batch._pipelines._items);
_framebuffers._items.swap(batch._framebuffers._items);
_ringbuffers._items.swap(batch._ringbuffers._items);
_drawCallInfos.swap(batch._drawCallInfos);
_queries._items.swap(batch._queries._items);
_lambdas._items.swap(batch._lambdas._items);
@ -110,6 +111,7 @@ void Batch::clear() {
_transforms.clear();
_pipelines.clear();
_framebuffers.clear();
_ringbuffers.clear();
_objects.clear();
_drawCallInfos.clear();
}
@ -320,12 +322,13 @@ void Batch::setResourceTexture(uint32 slot, const TextureView& view) {
setResourceTexture(slot, view._texture);
}
void Batch::setResourceFramebufferRingTexture(uint32 slot, const FramebufferRingPointer& framebuffer, unsigned int ringIndex) {
void Batch::setResourceFramebufferRingTexture(uint32 slot, const FramebufferRingPointer& framebuffer, unsigned int ringIndex, unsigned int renderBufferSlot) {
ADD_COMMAND(setResourceFramebufferRingTexture);
_params.emplace_back(_ringbuffers.cache(framebuffer));
_params.emplace_back(slot);
_params.emplace_back(ringIndex);
_params.emplace_back(renderBufferSlot);
}
void Batch::setFramebuffer(const FramebufferPointer& framebuffer) {

View file

@ -187,7 +187,7 @@ public:
void setResourceTexture(uint32 slot, const TexturePointer& texture);
void setResourceTexture(uint32 slot, const TextureView& view); // not a command, just a shortcut from a TextureView
void setResourceFramebufferRingTexture(uint32 slot, const FramebufferRingPointer& framebuffer, unsigned int ringIndex); // not a command, just a shortcut from a TextureView
void setResourceFramebufferRingTexture(uint32 slot, const FramebufferRingPointer& framebuffer, unsigned int ringIndex, unsigned int renderBufferSlot = 0U); // not a command, just a shortcut from a TextureView
// Ouput Stage
void setFramebuffer(const FramebufferPointer& framebuffer);

View file

@ -435,44 +435,47 @@ void Scene::queryTransitionItems(const Transaction::TransitionQueries& transacti
void Scene::resetHighlights(const Transaction::HighlightResets& transactions) {
auto outlineStage = getStage<HighlightStage>(HighlightStage::getName());
if (outlineStage) {
for (auto& transaction : transactions) {
const auto& selectionName = std::get<0>(transaction);
const auto& newStyle = std::get<1>(transaction);
auto outlineId = outlineStage->getHighlightIdBySelection(selectionName);
for (auto& transaction : transactions) {
const auto& selectionName = std::get<0>(transaction);
const auto& newStyle = std::get<1>(transaction);
auto outlineId = outlineStage->getHighlightIdBySelection(selectionName);
if (HighlightStage::isIndexInvalid(outlineId)) {
outlineStage->addHighlight(selectionName, newStyle);
} else {
outlineStage->editHighlight(outlineId)._style = newStyle;
if (HighlightStage::isIndexInvalid(outlineId)) {
outlineStage->addHighlight(selectionName, newStyle);
} else {
outlineStage->editHighlight(outlineId)._style = newStyle;
}
}
}
}
void Scene::removeHighlights(const Transaction::HighlightRemoves& transactions) {
auto outlineStage = getStage<HighlightStage>(HighlightStage::getName());
if (outlineStage) {
for (auto& selectionName : transactions) {
auto outlineId = outlineStage->getHighlightIdBySelection(selectionName);
for (auto& selectionName : transactions) {
auto outlineId = outlineStage->getHighlightIdBySelection(selectionName);
if (!HighlightStage::isIndexInvalid(outlineId)) {
outlineStage->removeHighlight(outlineId);
if (!HighlightStage::isIndexInvalid(outlineId)) {
outlineStage->removeHighlight(outlineId);
}
}
}
}
void Scene::queryHighlights(const Transaction::HighlightQueries& transactions) {
auto outlineStage = getStage<HighlightStage>(HighlightStage::getName());
if (outlineStage) {
for (auto& transaction : transactions) {
const auto& selectionName = std::get<0>(transaction);
const auto& func = std::get<1>(transaction);
auto outlineId = outlineStage->getHighlightIdBySelection(selectionName);
for (auto& transaction : transactions) {
const auto& selectionName = std::get<0>(transaction);
const auto& func = std::get<1>(transaction);
auto outlineId = outlineStage->getHighlightIdBySelection(selectionName);
if (!HighlightStage::isIndexInvalid(outlineId)) {
func(&outlineStage->editHighlight(outlineId)._style);
} else {
func(nullptr);
if (!HighlightStage::isIndexInvalid(outlineId)) {
func(&outlineStage->editHighlight(outlineId)._style);
} else {
func(nullptr);
}
}
}
}