|
|
@@ -32,7 +32,9 @@ Error Bloom::initExposure()
|
|
|
m_exposure.m_rtDescr.bake();
|
|
|
|
|
|
// init shaders
|
|
|
- ANKI_CHECK(getResourceManager().loadResource("Shaders/Bloom.ankiprog", m_exposure.m_prog));
|
|
|
+ ANKI_CHECK(getResourceManager().loadResource((getConfig().getRPreferCompute()) ? "Shaders/BloomCompute.ankiprog"
|
|
|
+ : "Shaders/BloomRaster.ankiprog",
|
|
|
+ m_exposure.m_prog));
|
|
|
|
|
|
ShaderProgramResourceVariantInitInfo variantInitInfo(m_exposure.m_prog);
|
|
|
variantInitInfo.addConstant("FB_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));
|
|
|
@@ -40,9 +42,6 @@ Error Bloom::initExposure()
|
|
|
const ShaderProgramResourceVariant* variant;
|
|
|
m_exposure.m_prog->getOrCreateVariant(variantInitInfo, variant);
|
|
|
m_exposure.m_grProg = variant->getProgram();
|
|
|
- ANKI_ASSERT(variant->getWorkgroupSizes()[0] == m_workgroupSize[0]
|
|
|
- && variant->getWorkgroupSizes()[1] == m_workgroupSize[1]
|
|
|
- && variant->getWorkgroupSizes()[2] == m_workgroupSize[2]);
|
|
|
|
|
|
return Error::NONE;
|
|
|
}
|
|
|
@@ -58,7 +57,10 @@ Error Bloom::initUpscale()
|
|
|
m_upscale.m_rtDescr.bake();
|
|
|
|
|
|
// init shaders
|
|
|
- ANKI_CHECK(getResourceManager().loadResource("Shaders/BloomUpscale.ankiprog", m_upscale.m_prog));
|
|
|
+ ANKI_CHECK(getResourceManager().loadResource((getConfig().getRPreferCompute())
|
|
|
+ ? "Shaders/BloomUpscaleCompute.ankiprog"
|
|
|
+ : "Shaders/BloomUpscaleRaster.ankiprog",
|
|
|
+ m_upscale.m_prog));
|
|
|
|
|
|
ShaderProgramResourceVariantInitInfo variantInitInfo(m_upscale.m_prog);
|
|
|
variantInitInfo.addConstant("FB_SIZE", UVec2(m_upscale.m_width, m_upscale.m_height));
|
|
|
@@ -67,9 +69,6 @@ Error Bloom::initUpscale()
|
|
|
const ShaderProgramResourceVariant* variant;
|
|
|
m_upscale.m_prog->getOrCreateVariant(variantInitInfo, variant);
|
|
|
m_upscale.m_grProg = variant->getProgram();
|
|
|
- ANKI_ASSERT(variant->getWorkgroupSizes()[0] == m_workgroupSize[0]
|
|
|
- && variant->getWorkgroupSizes()[1] == m_workgroupSize[1]
|
|
|
- && variant->getWorkgroupSizes()[2] == m_workgroupSize[2]);
|
|
|
|
|
|
// Textures
|
|
|
ANKI_CHECK(getResourceManager().loadResource("EngineAssets/LensDirt.ankitex", m_upscale.m_lensDirtImage));
|
|
|
@@ -80,6 +79,7 @@ Error Bloom::initUpscale()
|
|
|
void Bloom::populateRenderGraph(RenderingContext& ctx)
|
|
|
{
|
|
|
RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
|
|
|
+ const Bool preferCompute = getConfig().getRPreferCompute();
|
|
|
|
|
|
// Main pass
|
|
|
{
|
|
|
@@ -87,14 +87,34 @@ void Bloom::populateRenderGraph(RenderingContext& ctx)
|
|
|
m_runCtx.m_exposureRt = rgraph.newRenderTarget(m_exposure.m_rtDescr);
|
|
|
|
|
|
// Set the render pass
|
|
|
- ComputeRenderPassDescription& rpass = rgraph.newComputeRenderPass("Bloom Main");
|
|
|
-
|
|
|
TextureSubresourceInfo inputTexSubresource;
|
|
|
inputTexSubresource.m_firstMipmap = m_r->getDownscaleBlur().getMipmapCount() - 1;
|
|
|
- rpass.newDependency({m_r->getDownscaleBlur().getRt(), TextureUsageBit::SAMPLED_COMPUTE, inputTexSubresource});
|
|
|
- rpass.newDependency({m_runCtx.m_exposureRt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
|
|
|
|
|
|
- rpass.setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
+ RenderPassDescriptionBase* prpass;
|
|
|
+ if(preferCompute)
|
|
|
+ {
|
|
|
+ ComputeRenderPassDescription& rpass = rgraph.newComputeRenderPass("Bloom Main");
|
|
|
+
|
|
|
+ rpass.newDependency(RenderPassDependency(m_r->getDownscaleBlur().getRt(), TextureUsageBit::SAMPLED_COMPUTE,
|
|
|
+ inputTexSubresource));
|
|
|
+ rpass.newDependency(RenderPassDependency(m_runCtx.m_exposureRt, TextureUsageBit::IMAGE_COMPUTE_WRITE));
|
|
|
+
|
|
|
+ prpass = &rpass;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GraphicsRenderPassDescription& rpass = rgraph.newGraphicsRenderPass("Bloom Main");
|
|
|
+ rpass.setFramebufferInfo(m_fbDescr, {m_runCtx.m_exposureRt}, {});
|
|
|
+
|
|
|
+ rpass.newDependency(RenderPassDependency(m_r->getDownscaleBlur().getRt(), TextureUsageBit::SAMPLED_FRAGMENT,
|
|
|
+ inputTexSubresource));
|
|
|
+ rpass.newDependency(
|
|
|
+ RenderPassDependency(m_runCtx.m_exposureRt, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE));
|
|
|
+
|
|
|
+ prpass = &rpass;
|
|
|
+ }
|
|
|
+
|
|
|
+ prpass->setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
|
|
|
|
|
|
cmdb->bindShaderProgram(m_exposure.m_grProg);
|
|
|
@@ -110,9 +130,19 @@ void Bloom::populateRenderGraph(RenderingContext& ctx)
|
|
|
|
|
|
rgraphCtx.bindStorageBuffer(0, 2, m_r->getTonemapping().getAverageLuminanceBuffer());
|
|
|
|
|
|
- rgraphCtx.bindImage(0, 3, m_runCtx.m_exposureRt, TextureSubresourceInfo());
|
|
|
+ if(getConfig().getRPreferCompute())
|
|
|
+ {
|
|
|
+ rgraphCtx.bindImage(0, 3, m_runCtx.m_exposureRt, TextureSubresourceInfo());
|
|
|
|
|
|
- dispatchPPCompute(cmdb, m_workgroupSize[0], m_workgroupSize[1], m_exposure.m_width, m_exposure.m_height);
|
|
|
+ dispatchPPCompute(cmdb, m_workgroupSize[0], m_workgroupSize[1], m_exposure.m_width,
|
|
|
+ m_exposure.m_height);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cmdb->setViewport(0, 0, m_exposure.m_width, m_exposure.m_height);
|
|
|
+
|
|
|
+ cmdb->drawArrays(PrimitiveTopology::TRIANGLES, 3);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -122,12 +152,28 @@ void Bloom::populateRenderGraph(RenderingContext& ctx)
|
|
|
m_runCtx.m_upscaleRt = rgraph.newRenderTarget(m_upscale.m_rtDescr);
|
|
|
|
|
|
// Set the render pass
|
|
|
- ComputeRenderPassDescription& rpass = rgraph.newComputeRenderPass("Bloom Upscale");
|
|
|
+ RenderPassDescriptionBase* prpass;
|
|
|
+ if(preferCompute)
|
|
|
+ {
|
|
|
+ ComputeRenderPassDescription& rpass = rgraph.newComputeRenderPass("Bloom Upscale");
|
|
|
+
|
|
|
+ rpass.newDependency({m_runCtx.m_exposureRt, TextureUsageBit::SAMPLED_COMPUTE});
|
|
|
+ rpass.newDependency({m_runCtx.m_upscaleRt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
|
|
|
+
|
|
|
+ prpass = &rpass;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GraphicsRenderPassDescription& rpass = rgraph.newGraphicsRenderPass("Bloom Upscale");
|
|
|
+ rpass.setFramebufferInfo(m_fbDescr, {m_runCtx.m_upscaleRt}, {});
|
|
|
|
|
|
- rpass.newDependency({m_runCtx.m_exposureRt, TextureUsageBit::SAMPLED_COMPUTE});
|
|
|
- rpass.newDependency({m_runCtx.m_upscaleRt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
|
|
|
+ rpass.newDependency({m_runCtx.m_exposureRt, TextureUsageBit::SAMPLED_FRAGMENT});
|
|
|
+ rpass.newDependency({m_runCtx.m_upscaleRt, TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE});
|
|
|
|
|
|
- rpass.setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
+ prpass = &rpass;
|
|
|
+ }
|
|
|
+
|
|
|
+ prpass->setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
|
|
|
|
|
|
cmdb->bindShaderProgram(m_upscale.m_grProg);
|
|
|
@@ -136,9 +182,18 @@ void Bloom::populateRenderGraph(RenderingContext& ctx)
|
|
|
rgraphCtx.bindColorTexture(0, 1, m_runCtx.m_exposureRt);
|
|
|
cmdb->bindTexture(0, 2, m_upscale.m_lensDirtImage->getTextureView());
|
|
|
|
|
|
- rgraphCtx.bindImage(0, 3, m_runCtx.m_upscaleRt, TextureSubresourceInfo());
|
|
|
+ if(getConfig().getRPreferCompute())
|
|
|
+ {
|
|
|
+ rgraphCtx.bindImage(0, 3, m_runCtx.m_upscaleRt, TextureSubresourceInfo());
|
|
|
+
|
|
|
+ dispatchPPCompute(cmdb, m_workgroupSize[0], m_workgroupSize[1], m_upscale.m_width, m_upscale.m_height);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cmdb->setViewport(0, 0, m_upscale.m_width, m_upscale.m_height);
|
|
|
|
|
|
- dispatchPPCompute(cmdb, m_workgroupSize[0], m_workgroupSize[1], m_upscale.m_width, m_upscale.m_height);
|
|
|
+ cmdb->drawArrays(PrimitiveTopology::TRIANGLES, 3);
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
}
|