Skip to content

Commit

Permalink
Traktor: Using RG render target for caching Spark glyphs instead of m…
Browse files Browse the repository at this point in the history
…anual render target.
  • Loading branch information
apistol78 committed Mar 9, 2024
1 parent cdfd9fc commit eac5b48
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 39 deletions.
40 changes: 19 additions & 21 deletions code/Spark/Acc/AccDisplayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const uint32_t c_cacheGlyphCount = c_cacheGlyphCountX * c_cacheGlyphCountY;
const uint32_t c_cacheGlyphDimX = c_cacheGlyphSize * c_cacheGlyphCountX;
const uint32_t c_cacheGlyphDimY = c_cacheGlyphSize * c_cacheGlyphCountY;

const render::Handle c_glyphsTargetSetId(L"Spark_GlyphsTargetSet");

const ColorTransform c_cxfZero(Color4f(0.0f, 0.0f, 0.0f, 0.0f), Color4f(0.0f, 0.0f, 0.0f, 0.0f));
const ColorTransform c_cxfWhite(Color4f(0.0f, 0.0f, 0.0f, 0.0f), Color4f(1.0f, 1.0f, 1.0f, 1.0f));
const ColorTransform c_cxfIdentity(Color4f(1.0f, 1.0f, 1.0f, 1.0f), Color4f(0.0f, 0.0f, 0.0f, 0.0f));
Expand Down Expand Up @@ -160,22 +162,6 @@ bool AccDisplayRenderer::create(
return false;
}

render::RenderTargetSetCreateDesc rtscd;
rtscd.count = 1;
rtscd.width = c_cacheGlyphDimX;
rtscd.height = c_cacheGlyphDimY;
rtscd.multiSample = 0;
rtscd.createDepthStencil = false;
rtscd.usingPrimaryDepthStencil = false;
rtscd.targets[0].format = render::TfR8;

m_renderTargetGlyphs = m_renderSystem->createRenderTargetSet(rtscd, nullptr, T_FILE_LINE_W);
if (!m_renderTargetGlyphs)
{
log::error << L"Unable to create accelerated display renderer; failed to create glyph cache target." << Endl;
return false;
}

return true;
}

Expand All @@ -187,7 +173,6 @@ void AccDisplayRenderer::destroy()
safeDestroy(m_quad);
safeDestroy(m_gradientCache);
safeDestroy(m_textureCache);
safeDestroy(m_renderTargetGlyphs);

for (auto i = m_shapeCache.begin(); i != m_shapeCache.end(); ++i)
safeDestroy(i->second.shape);
Expand All @@ -207,9 +192,22 @@ void AccDisplayRenderer::beginSetup(render::RenderGraph* renderGraph)
{
m_renderGraph = renderGraph;

auto glyphsTargetSetId = m_renderGraph->addExplicitTargetSet(L"Spark glyph", m_renderTargetGlyphs);
render::RenderGraphTargetSetDesc rgtsd;
rgtsd.count = 1;
rgtsd.width = c_cacheGlyphDimX;
rgtsd.height = c_cacheGlyphDimY;
rgtsd.targets[0].colorFormat = render::TfR8;

m_glyphsTargetSetId = m_renderGraph->addPersistentTargetSet(
L"Spark glyphs",
c_glyphsTargetSetId,
false,
rgtsd
);

m_renderPassOutput = new render::RenderPass(L"Spark");
m_renderPassOutput->addInput(m_glyphsTargetSetId);

if (m_clearBackground)
{
render::Clear cl;
Expand All @@ -229,13 +227,13 @@ void AccDisplayRenderer::beginSetup(render::RenderGraph* renderGraph)

m_renderPassGlyph = new render::RenderPass(L"Spark glyphs");
if (!m_firstFrame)
m_renderPassGlyph->setOutput(glyphsTargetSetId, render::TfColor, render::TfColor);
m_renderPassGlyph->setOutput(m_glyphsTargetSetId, render::TfColor, render::TfColor);
else
{
render::Clear cl;
cl.mask = render::CfColor;
cl.colors[0] = Color4f(0.5f, 0.5f, 0.5f, 1.0);
m_renderPassGlyph->setOutput(glyphsTargetSetId, cl, render::TfNone, render::TfColor);
m_renderPassGlyph->setOutput(m_glyphsTargetSetId, cl, render::TfNone, render::TfColor);
}

m_frameTransform.set(0.0f, 0.0f, 1.0f, 1.0f);
Expand Down Expand Up @@ -667,9 +665,9 @@ void AccDisplayRenderer::renderEnqueuedGlyphs()
{
m_glyph->render(
m_renderPassOutput,
m_glyphsTargetSetId,
m_frameBounds,
m_frameTransform,
m_renderTargetGlyphs->getColorTexture(0),
m_maskReference,
m_glyphFilter,
m_glyphColor,
Expand Down
2 changes: 1 addition & 1 deletion code/Spark/Acc/AccDisplayRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class T_DLLCLASS AccDisplayRenderer : public IDisplayRenderer
Ref< render::RenderGraph > m_renderGraph;
Ref< render::RenderPass > m_renderPassOutput;
Ref< render::RenderPass > m_renderPassGlyph;
Ref< render::IRenderTargetSet > m_renderTargetGlyphs;
Ref< AccShapeResources > m_shapeResources;
Ref< AccShapeVertexPool > m_fillVertexPool;
Ref< AccShapeVertexPool > m_lineVertexPool;
Expand All @@ -163,6 +162,7 @@ class T_DLLCLASS AccDisplayRenderer : public IDisplayRenderer
Ref< AccQuad > m_quad;
SmallMap< int32_t, ShapeCache > m_shapeCache;
SmallMap< int32_t, GlyphCache > m_glyphCache;
render::handle_t m_glyphsTargetSetId;
int32_t m_nextIndex;
Vector4 m_frameBounds; //!< [left, top, right, bottom] in twips.
Vector4 m_frameTransform; //!< [offset x, offset y, scale x, scale y] in normalized values.
Expand Down
21 changes: 11 additions & 10 deletions code/Spark/Acc/AccGlyph.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,19 +11,19 @@
#include "Core/Misc/SafeDestroy.h"
#include "Render/Buffer.h"
#include "Render/IRenderSystem.h"
#include "Render/IRenderTargetSet.h"
#include "Render/Shader.h"
#include "Render/VertexElement.h"
#include "Render/Context/RenderContext.h"
#include "Render/Frame/RenderGraph.h"
#include "Render/Frame/RenderPass.h"
#include "Resource/IResourceManager.h"
#include "Spark/Acc/AccGlyph.h"

namespace traktor
namespace traktor::spark
{
namespace spark
namespace
{
namespace
{

#pragma pack(1)
struct Vertex
Expand Down Expand Up @@ -59,7 +59,7 @@ const render::Handle s_handleTexture(L"Spark_Texture");
const render::Handle s_handleColor(L"Spark_Color");
const render::Handle s_handleFilterColor(L"Spark_FilterColor");

}
}

T_IMPLEMENT_RTTI_CLASS(L"traktor.spark.AccGlyph", AccGlyph, Object)

Expand Down Expand Up @@ -186,9 +186,9 @@ void AccGlyph::add(

void AccGlyph::render(
render::RenderPass* renderPass,
render::handle_t glyphCacheTargetSetId,
const Vector4& frameBounds,
const Vector4& frameTransform,
render::ITexture* texture,
uint8_t maskReference,
uint8_t glyphFilter,
const Color4f& glyphColor,
Expand All @@ -210,7 +210,9 @@ void AccGlyph::render(
uint32_t offset = m_offset;
uint32_t count = m_count;

renderPass->addBuild([=](const render::RenderGraph&, render::RenderContext* renderContext) {
renderPass->addBuild([=](const render::RenderGraph& renderGraph, render::RenderContext* renderContext) {

auto glyphCacheTargetSet = renderGraph.getTargetSet(glyphCacheTargetSetId);

render::IndexedRenderBlock* renderBlock = renderContext->allocNamed< render::IndexedRenderBlock >(L"Flash AccGlyph");
renderBlock->program = sp.program;
Expand All @@ -229,7 +231,7 @@ void AccGlyph::render(
renderBlock->programParams->setVectorParameter(s_handleFrameBounds, frameBounds);
renderBlock->programParams->setVectorParameter(s_handleFrameTransform, frameTransform);
renderBlock->programParams->setStencilReference(maskReference);
renderBlock->programParams->setTextureParameter(s_handleTexture, texture);
renderBlock->programParams->setTextureParameter(s_handleTexture, glyphCacheTargetSet->getColorTexture(0)); // texture);
renderBlock->programParams->setVectorParameter(s_handleColor, glyphColor);

if (glyphFilter != 0)
Expand All @@ -245,5 +247,4 @@ void AccGlyph::render(
m_count = 0;
}

}
}
2 changes: 1 addition & 1 deletion code/Spark/Acc/AccGlyph.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class AccGlyph : public Object

void render(
render::RenderPass* renderPass,
render::handle_t glyphCacheTargetSetId,
const Vector4& frameSize,
const Vector4& frameTransform,
render::ITexture* texture,
uint8_t maskReference,
uint8_t glyphFilter,
const Color4f& glyphColor,
Expand Down
7 changes: 1 addition & 6 deletions code/Spark/Runtime/SparkLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ void SparkLayer::destroy()
void SparkLayer::transition(Layer* fromLayer)
{
SparkLayer* fromSparkLayer = checked_type_cast< SparkLayer*, false >(fromLayer);
bool shouldFlush = true;

// Pass movie as well, if it's the same movie and we're allowed.
const bool permit = fromLayer->isTransitionPermitted() && isTransitionPermitted();
Expand All @@ -189,10 +188,6 @@ void SparkLayer::transition(Layer* fromLayer)
m_moviePlayer = fromSparkLayer->m_moviePlayer;
fromSparkLayer->m_moviePlayer = nullptr;
}

// Also do not flush caches if same movie will be used again;
// this improve performance as images and such doesn't need to be reloaded.
shouldFlush = false;
}

// Keep display and sound renderer.
Expand All @@ -202,7 +197,7 @@ void SparkLayer::transition(Layer* fromLayer)
fromSparkLayer->m_soundRenderer = nullptr;

// Ensure display renderer's caches are fresh.
if (m_displayRenderer && shouldFlush)
if (m_displayRenderer)
m_displayRenderer->flushCaches();

// Update setting on display renderer.
Expand Down

0 comments on commit eac5b48

Please sign in to comment.