|
|
@@ -9,6 +9,7 @@
|
|
|
#include <AnKi/Renderer/LightShading.h>
|
|
|
#include <AnKi/Renderer/Tonemapping.h>
|
|
|
#include <AnKi/Renderer/MotionVectors.h>
|
|
|
+#include <AnKi/Core/ConfigSet.h>
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
@@ -34,17 +35,23 @@ Error TemporalAA::init()
|
|
|
|
|
|
Error TemporalAA::initInternal()
|
|
|
{
|
|
|
- ANKI_CHECK(m_r->getResourceManager().loadResource("Shaders/TemporalAAResolve.ankiprog", m_prog));
|
|
|
+ ANKI_CHECK(m_r->getResourceManager().loadResource(
|
|
|
+ (getConfig().getRPreferCompute()) ? "Shaders/TemporalAACompute.ankiprog" : "Shaders/TemporalAARaster.ankiprog",
|
|
|
+ m_prog));
|
|
|
|
|
|
{
|
|
|
ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
|
|
|
variantInitInfo.addConstant("VARIANCE_CLIPPING_GAMMA", 2.7f);
|
|
|
variantInitInfo.addConstant("BLEND_FACTOR", 1.0f / 16.0f);
|
|
|
- variantInitInfo.addConstant("FB_SIZE",
|
|
|
- UVec2(m_r->getInternalResolution().x(), m_r->getInternalResolution().y()));
|
|
|
variantInitInfo.addMutation("VARIANCE_CLIPPING", 1);
|
|
|
variantInitInfo.addMutation("YCBCR", 0);
|
|
|
|
|
|
+ if(getConfig().getRPreferCompute())
|
|
|
+ {
|
|
|
+ variantInitInfo.addConstant("FB_SIZE",
|
|
|
+ UVec2(m_r->getInternalResolution().x(), m_r->getInternalResolution().y()));
|
|
|
+ }
|
|
|
+
|
|
|
const ShaderProgramResourceVariant* variant;
|
|
|
m_prog->getOrCreateVariant(variantInitInfo, variant);
|
|
|
m_grProg = variant->getProgram();
|
|
|
@@ -52,11 +59,13 @@ Error TemporalAA::initInternal()
|
|
|
|
|
|
for(U i = 0; i < 2; ++i)
|
|
|
{
|
|
|
- TextureInitInfo texinit = m_r->create2DRenderTargetInitInfo(
|
|
|
- m_r->getInternalResolution().x(), m_r->getInternalResolution().y(),
|
|
|
- LIGHT_SHADING_COLOR_ATTACHMENT_PIXEL_FORMAT,
|
|
|
- TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::SAMPLED_COMPUTE | TextureUsageBit::IMAGE_COMPUTE_WRITE,
|
|
|
- "TemporalAA");
|
|
|
+ TextureUsageBit usage = TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::SAMPLED_COMPUTE;
|
|
|
+ usage |= (getConfig().getRPreferCompute()) ? TextureUsageBit::IMAGE_COMPUTE_WRITE
|
|
|
+ : TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE;
|
|
|
+
|
|
|
+ TextureInitInfo texinit =
|
|
|
+ m_r->create2DRenderTargetInitInfo(m_r->getInternalResolution().x(), m_r->getInternalResolution().y(),
|
|
|
+ LIGHT_SHADING_COLOR_ATTACHMENT_PIXEL_FORMAT, usage, "TemporalAA");
|
|
|
|
|
|
texinit.m_initialUsage = TextureUsageBit::SAMPLED_FRAGMENT;
|
|
|
|
|
|
@@ -68,6 +77,9 @@ Error TemporalAA::initInternal()
|
|
|
Format::R8G8B8A8_UNORM, "TemporalAA Tonemapped");
|
|
|
m_tonemappedRtDescr.bake();
|
|
|
|
|
|
+ m_fbDescr.m_colorAttachmentCount = 2;
|
|
|
+ m_fbDescr.bake();
|
|
|
+
|
|
|
return Error::NONE;
|
|
|
}
|
|
|
|
|
|
@@ -77,6 +89,7 @@ void TemporalAA::populateRenderGraph(RenderingContext& ctx)
|
|
|
|
|
|
const U32 historyRtIdx = (m_r->getFrameCount() + 1) & 1;
|
|
|
const U32 renderRtIdx = !historyRtIdx;
|
|
|
+ const Bool preferCompute = getConfig().getRPreferCompute();
|
|
|
|
|
|
// Import RTs
|
|
|
if(ANKI_LIKELY(m_rtTexturesImportedOnce[historyRtIdx]))
|
|
|
@@ -93,9 +106,40 @@ void TemporalAA::populateRenderGraph(RenderingContext& ctx)
|
|
|
m_runCtx.m_tonemappedRt = rgraph.newRenderTarget(m_tonemappedRtDescr);
|
|
|
|
|
|
// Create pass
|
|
|
- ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("TemporalAA");
|
|
|
+ TextureUsageBit readUsage;
|
|
|
+ RenderPassDescriptionBase* prpass;
|
|
|
+ if(preferCompute)
|
|
|
+ {
|
|
|
+ ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("TemporalAA");
|
|
|
+
|
|
|
+ pass.newDependency(RenderPassDependency(m_runCtx.m_renderRt, TextureUsageBit::IMAGE_COMPUTE_WRITE));
|
|
|
+ pass.newDependency(RenderPassDependency(m_runCtx.m_tonemappedRt, TextureUsageBit::IMAGE_COMPUTE_WRITE));
|
|
|
+
|
|
|
+ readUsage = TextureUsageBit::SAMPLED_COMPUTE;
|
|
|
+
|
|
|
+ prpass = &pass;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GraphicsRenderPassDescription& pass = rgraph.newGraphicsRenderPass("TemporalAA");
|
|
|
+ pass.setFramebufferInfo(m_fbDescr, {m_runCtx.m_renderRt, m_runCtx.m_tonemappedRt}, {});
|
|
|
+
|
|
|
+ pass.newDependency(RenderPassDependency(m_runCtx.m_renderRt, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE));
|
|
|
+ pass.newDependency(
|
|
|
+ RenderPassDependency(m_runCtx.m_tonemappedRt, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE));
|
|
|
+
|
|
|
+ readUsage = TextureUsageBit::SAMPLED_FRAGMENT;
|
|
|
+
|
|
|
+ prpass = &pass;
|
|
|
+ }
|
|
|
|
|
|
- pass.setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
+ prpass->newDependency(RenderPassDependency(m_r->getGBuffer().getDepthRt(), readUsage,
|
|
|
+ TextureSubresourceInfo(DepthStencilAspectBit::DEPTH)));
|
|
|
+ prpass->newDependency(RenderPassDependency(m_r->getLightShading().getRt(), readUsage));
|
|
|
+ prpass->newDependency(RenderPassDependency(m_runCtx.m_historyRt, readUsage));
|
|
|
+ prpass->newDependency(RenderPassDependency(m_r->getMotionVectors().getMotionVectorsRt(), readUsage));
|
|
|
+
|
|
|
+ prpass->setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
|
|
|
|
|
|
cmdb->bindShaderProgram(m_grProg);
|
|
|
@@ -106,20 +150,22 @@ void TemporalAA::populateRenderGraph(RenderingContext& ctx)
|
|
|
rgraphCtx.bindColorTexture(0, 2, m_r->getLightShading().getRt());
|
|
|
rgraphCtx.bindColorTexture(0, 3, m_runCtx.m_historyRt);
|
|
|
rgraphCtx.bindColorTexture(0, 4, m_r->getMotionVectors().getMotionVectorsRt());
|
|
|
- rgraphCtx.bindImage(0, 5, m_runCtx.m_renderRt, TextureSubresourceInfo());
|
|
|
- rgraphCtx.bindImage(0, 6, m_runCtx.m_tonemappedRt, TextureSubresourceInfo());
|
|
|
- rgraphCtx.bindUniformBuffer(0, 7, m_r->getTonemapping().getAverageLuminanceBuffer());
|
|
|
+ rgraphCtx.bindUniformBuffer(0, 5, m_r->getTonemapping().getAverageLuminanceBuffer());
|
|
|
|
|
|
- dispatchPPCompute(cmdb, 8, 8, m_r->getInternalResolution().x(), m_r->getInternalResolution().y());
|
|
|
- });
|
|
|
+ if(getConfig().getRPreferCompute())
|
|
|
+ {
|
|
|
+ rgraphCtx.bindImage(0, 6, m_runCtx.m_renderRt, TextureSubresourceInfo());
|
|
|
+ rgraphCtx.bindImage(0, 7, m_runCtx.m_tonemappedRt, TextureSubresourceInfo());
|
|
|
|
|
|
- pass.newDependency({m_runCtx.m_renderRt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
|
|
|
- pass.newDependency({m_runCtx.m_tonemappedRt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
|
|
|
- pass.newDependency({m_r->getGBuffer().getDepthRt(), TextureUsageBit::SAMPLED_COMPUTE,
|
|
|
- TextureSubresourceInfo(DepthStencilAspectBit::DEPTH)});
|
|
|
- pass.newDependency({m_r->getLightShading().getRt(), TextureUsageBit::SAMPLED_COMPUTE});
|
|
|
- pass.newDependency({m_runCtx.m_historyRt, TextureUsageBit::SAMPLED_COMPUTE});
|
|
|
- pass.newDependency({m_r->getMotionVectors().getMotionVectorsRt(), TextureUsageBit::SAMPLED_COMPUTE});
|
|
|
+ dispatchPPCompute(cmdb, 8, 8, m_r->getInternalResolution().x(), m_r->getInternalResolution().y());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cmdb->setViewport(0, 0, m_r->getInternalResolution().x(), m_r->getInternalResolution().y());
|
|
|
+
|
|
|
+ cmdb->drawArrays(PrimitiveTopology::TRIANGLES, 3);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
} // end namespace anki
|