Skip to content

Commit

Permalink
Vulkan: Move pipeline cache graph dump to renderer
Browse files Browse the repository at this point in the history
In preparation for moving some caches to the share group.

Bug: angleproject:6565
Bug: angleproject:8629
Change-Id: I1a06a18417502e499da0edb9abb0d510e3ad99ce
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5401513
Auto-Submit: Shahbaz Youssefi <[email protected]>
Reviewed-by: Charlie Lao <[email protected]>
Commit-Queue: Charlie Lao <[email protected]>
Reviewed-by: mohan maiya <[email protected]>
  • Loading branch information
ShabbyX authored and Angle LUCI CQ committed Mar 28, 2024
1 parent 0e9254b commit c71a67d
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 109 deletions.
60 changes: 1 addition & 59 deletions src/libANGLE/renderer/vulkan/ContextVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@

namespace rx
{

#if defined(ANGLE_PLATFORM_ANDROID)
constexpr const char *kDefaultPipelineCacheGraphDumpPath = "/data/local/tmp/angle_dumps/";
#else
constexpr const char *kDefaultPipelineCacheGraphDumpPath = "";
#endif // ANGLE_PLATFORM_ANDROID

namespace
{
// If the total size of copyBufferToImage commands in the outside command buffer reaches the
Expand Down Expand Up @@ -678,40 +671,6 @@ VkDependencyFlags GetLocalDependencyFlags(ContextVk *contextVk)
return dependencyFlags;
}

void DumpPipelineCacheGraph(ContextVk *contextVk, const std::ostringstream &graph)
{
std::string dumpPath = contextVk->getPipelineCacheGraphDumpPath();
if (dumpPath.size() == 0)
{
WARN() << "No path supplied for pipeline cache graph dump!";
return;
}

static std::atomic<uint32_t> sContextIndex(0);
std::string filename = dumpPath;
filename += angle::GetExecutableName();
filename += std::to_string(sContextIndex.fetch_add(1));
filename += ".dump";

INFO() << "Dumping pipeline cache transition graph to: \"" << filename << "\"";

std::ofstream out = std::ofstream(filename, std::ofstream::binary);
if (!out.is_open())
{
ERR() << "Failed to open \"" << filename << "\"";
}

out << "digraph {\n" << " node [shape=box";
if (contextVk->getFeatures().supportsPipelineCreationFeedback.enabled)
{
out << ",color=green";
}
out << "]\n";
out << graph.str();
out << "}\n";
out.close();
}

bool BlendModeSupportsDither(const ContextVk *contextVk, size_t colorIndex)
{
const gl::State &state = contextVk->getState();
Expand Down Expand Up @@ -1258,26 +1217,9 @@ ContextVk::ContextVk(const gl::State &state, gl::ErrorSet *errorSet, vk::Rendere
#undef ANGLE_ADD_PERF_MONITOR_COUNTER_GROUP

mPerfMonitorCounters.push_back(vulkanGroup);

mDumpPipelineCacheGraph =
(angle::GetEnvironmentVarOrAndroidProperty("ANGLE_DUMP_PIPELINE_CACHE_GRAPH",
"angle.dump_pipeline_cache_graph") == "1");

mPipelineCacheGraphDumpPath = angle::GetEnvironmentVarOrAndroidProperty(
"ANGLE_PIPELINE_CACHE_GRAPH_DUMP_PATH", "angle.pipeline_cache_graph_dump_path");
if (mPipelineCacheGraphDumpPath.size() == 0)
{
mPipelineCacheGraphDumpPath = kDefaultPipelineCacheGraphDumpPath;
}
}

ContextVk::~ContextVk()
{
if (!mPipelineCacheGraph.str().empty())
{
DumpPipelineCacheGraph(this, mPipelineCacheGraph);
}
}
ContextVk::~ContextVk() {}

void ContextVk::onDestroy(const gl::Context *context)
{
Expand Down
13 changes: 0 additions & 13 deletions src/libANGLE/renderer/vulkan/ContextVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,6 @@ class ContextVk : public ContextImpl, public vk::Context, public MultisampleText
mVulkanCacheStats[cache].accumulate(stats);
}

std::ostringstream &getPipelineCacheGraphStream() { return mPipelineCacheGraph; }

// Whether VK_EXT_pipeline_robustness should be used to enable robust buffer access in the
// pipeline.
vk::PipelineRobustness pipelineRobustness() const
Expand Down Expand Up @@ -819,12 +817,6 @@ class ContextVk : public ContextImpl, public vk::Context, public MultisampleText
mShareGroupVk->getContexts().size() == 1;
}

bool isPipelineCacheGraphDumpEnabled() const { return mDumpPipelineCacheGraph; }
const char *getPipelineCacheGraphDumpPath() const
{
return mPipelineCacheGraphDumpPath.c_str();
}

vk::RenderPassUsageFlags getDepthStencilAttachmentFlags() const
{
return mDepthStencilAttachmentFlags;
Expand Down Expand Up @@ -1701,11 +1693,6 @@ class ContextVk : public ContextImpl, public vk::Context, public MultisampleText

VulkanCacheStats mVulkanCacheStats;

// A graph built from pipeline descs and their transitions.
std::ostringstream mPipelineCacheGraph;
bool mDumpPipelineCacheGraph;
std::string mPipelineCacheGraphDumpPath;

RangedSerialFactory mOutsideRenderPassSerialFactory;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
if (externalRenderTargetSupported)
{
angle::FormatID externalFormatID =
renderer->mExternalFormatTable.getOrAllocExternalFormatID(
renderer->getExternalFormatTable()->getOrAllocExternalFormatID(
bufferFormatProperties.externalFormat,
bufferFormatResolveProperties.colorAttachmentFormat,
bufferFormatProperties.formatFeatures);
Expand Down
66 changes: 34 additions & 32 deletions src/libANGLE/renderer/vulkan/vk_cache_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ PipelineState GetPipelineState(size_t stateIndex, bool *isRangedOut, size_t *sub
out << "\\n";
}

[[maybe_unused]] void OutputAllPipelineState(ContextVk *contextVk,
[[maybe_unused]] void OutputAllPipelineState(Context *context,
std::ostream &out,
const UnpackedPipelineState &pipeline,
GraphicsPipelineSubset subset,
Expand Down Expand Up @@ -2062,7 +2062,7 @@ PipelineState GetPipelineState(size_t stateIndex, bool *isRangedOut, size_t *sub

// Shaders state
{PipelineState::ViewportNegativeOneToOne,
hasShaders && contextVk->getFeatures().supportsDepthClipControl.enabled},
hasShaders && context->getFeatures().supportsDepthClipControl.enabled},
{PipelineState::DepthClampEnable, 0},
{PipelineState::PolygonMode, hasShaders ? VK_POLYGON_MODE_FILL : 0},
{PipelineState::CullMode, hasShaders ? VK_CULL_MODE_NONE : 0},
Expand Down Expand Up @@ -2146,15 +2146,15 @@ PipelineState GetPipelineState(size_t stateIndex, bool *isRangedOut, size_t *sub

template <typename Hash>
void DumpPipelineCacheGraph(
ContextVk *contextVk,
Context *context,
const std::unordered_map<GraphicsPipelineDesc,
PipelineHelper,
Hash,
typename GraphicsPipelineCacheTypeHelper<Hash>::KeyEqual> &cache)
{
constexpr GraphicsPipelineSubset kSubset = GraphicsPipelineCacheTypeHelper<Hash>::kSubset;

std::ostream &out = contextVk->getPipelineCacheGraphStream();
std::ostream &out = context->getRenderer()->getPipelineCacheGraphStream();

static std::atomic<uint32_t> sCacheSerial(0);
angle::HashMap<GraphicsPipelineDesc, uint32_t, Hash,
Expand Down Expand Up @@ -2198,7 +2198,7 @@ void DumpPipelineCacheGraph(
out << " subgraph cluster_" << subsetTag << cacheSerial << "{\n";
out << " label=\"Program " << cacheSerial << "\\n"
<< subsetDescription << "\\nCommon state:\\n";
OutputAllPipelineState(contextVk, out, pipelines[0], kSubset, commonState, true);
OutputAllPipelineState(context, out, pipelines[0], kSubset, commonState, true);
out << "\";\n";

descId = 0;
Expand Down Expand Up @@ -2250,7 +2250,7 @@ void DumpPipelineCacheGraph(
out << " p" << subsetTag << cacheSerial << "_" << descId << "[label=\"Pipeline " << descId
<< "\\n"
<< feedbackDesc << "\\n";
OutputAllPipelineState(contextVk, out, pipelines[descId], kSubset, nodeState, false);
OutputAllPipelineState(context, out, pipelines[descId], kSubset, nodeState, false);
out << "\"]" << style << ";\n";

descToId[desc] = descId++;
Expand Down Expand Up @@ -2366,9 +2366,9 @@ angle::Result InitializePipelineFromLibraries(Context *context,
return angle::Result::Continue;
}

bool ShouldDumpPipelineCacheGraph(ContextVk *contextVk)
bool ShouldDumpPipelineCacheGraph(Context *context)
{
return kDumpPipelineCacheGraph && contextVk->isPipelineCacheGraphDumpEnabled();
return kDumpPipelineCacheGraph && context->getRenderer()->isPipelineCacheGraphDumpEnabled();
}
} // anonymous namespace

Expand Down Expand Up @@ -4444,19 +4444,21 @@ void PipelineHelper::destroy(VkDevice device)
reset();
}

void PipelineHelper::release(ContextVk *contextVk)
void PipelineHelper::release(Context *context)
{
contextVk->getRenderer()->collectGarbage(mUse, &mPipeline);
contextVk->getRenderer()->collectGarbage(mUse, &mLinkedPipelineToRelease);
Renderer *renderer = context->getRenderer();

renderer->collectGarbage(mUse, &mPipeline);
renderer->collectGarbage(mUse, &mLinkedPipelineToRelease);

// If there is a pending task, wait for it before release.
if (mMonolithicPipelineCreationTask.isValid())
{
if (mMonolithicPipelineCreationTask.isPosted())
{
mMonolithicPipelineCreationTask.wait();
contextVk->getRenderer()->collectGarbage(
mUse, &mMonolithicPipelineCreationTask.getTask()->getPipeline());
renderer->collectGarbage(mUse,
&mMonolithicPipelineCreationTask.getTask()->getPipeline());
}
mMonolithicPipelineCreationTask.reset();
}
Expand Down Expand Up @@ -6770,7 +6772,7 @@ angle::Result RenderPassCache::MakeRenderPass(vk::Context *context,
if (isYUVExternalFormat)
{
const vk::ExternalYuvFormatInfo &externalFormatInfo =
context->getRenderer()->mExternalFormatTable.getExternalFormatInfo(
context->getRenderer()->getExternalFormatTable()->getExternalFormatInfo(
attachmentFormatID);
attachmentDescs[attachmentCount.get()].format =
externalFormatInfo.colorAttachmentFormat;
Expand Down Expand Up @@ -6880,7 +6882,7 @@ angle::Result RenderPassCache::MakeRenderPass(vk::Context *context,
if (isYUVExternalFormat)
{
const vk::ExternalYuvFormatInfo &externalFormatInfo =
context->getRenderer()->mExternalFormatTable.getExternalFormatInfo(
context->getRenderer()->getExternalFormatTable()->getExternalFormatInfo(
attachmentFormatID);
externalFormat.externalFormat = externalFormatInfo.externalFormat;
VkAttachmentDescription2 &attachment = attachmentDescs[attachmentCount.get()];
Expand Down Expand Up @@ -7090,16 +7092,16 @@ angle::Result RenderPassCache::MakeRenderPass(vk::Context *context,

// GraphicsPipelineCache implementation.
template <typename Hash>
void GraphicsPipelineCache<Hash>::destroy(ContextVk *contextVk)
void GraphicsPipelineCache<Hash>::destroy(vk::Context *context)
{
if (vk::ShouldDumpPipelineCacheGraph(contextVk) && !mPayload.empty())
if (vk::ShouldDumpPipelineCacheGraph(context) && !mPayload.empty())
{
vk::DumpPipelineCacheGraph<Hash>(contextVk, mPayload);
vk::DumpPipelineCacheGraph<Hash>(context, mPayload);
}

accumulateCacheStats(contextVk->getRenderer());
accumulateCacheStats(context->getRenderer());

VkDevice device = contextVk->getDevice();
VkDevice device = context->getDevice();

for (auto &item : mPayload)
{
Expand All @@ -7111,17 +7113,17 @@ void GraphicsPipelineCache<Hash>::destroy(ContextVk *contextVk)
}

template <typename Hash>
void GraphicsPipelineCache<Hash>::release(ContextVk *contextVk)
void GraphicsPipelineCache<Hash>::release(vk::Context *context)
{
if (vk::ShouldDumpPipelineCacheGraph(contextVk) && !mPayload.empty())
if (vk::ShouldDumpPipelineCacheGraph(context) && !mPayload.empty())
{
vk::DumpPipelineCacheGraph<Hash>(contextVk, mPayload);
vk::DumpPipelineCacheGraph<Hash>(context, mPayload);
}

for (auto &item : mPayload)
{
vk::PipelineHelper &pipeline = item.second;
pipeline.release(contextVk);
pipeline.release(context);
}

mPayload.clear();
Expand Down Expand Up @@ -7240,9 +7242,9 @@ void GraphicsPipelineCache<Hash>::populate(const vk::GraphicsPipelineDesc &desc,

// Instantiate the pipeline cache functions
template void GraphicsPipelineCache<GraphicsPipelineDescCompleteHash>::destroy(
ContextVk *contextVk);
vk::Context *context);
template void GraphicsPipelineCache<GraphicsPipelineDescCompleteHash>::release(
ContextVk *contextVk);
vk::Context *context);
template angle::Result GraphicsPipelineCache<GraphicsPipelineDescCompleteHash>::createPipeline(
vk::Context *context,
vk::PipelineCacheAccess *pipelineCache,
Expand All @@ -7269,9 +7271,9 @@ template void GraphicsPipelineCache<GraphicsPipelineDescCompleteHash>::populate(
vk::Pipeline &&pipeline);

template void GraphicsPipelineCache<GraphicsPipelineDescVertexInputHash>::destroy(
ContextVk *contextVk);
vk::Context *context);
template void GraphicsPipelineCache<GraphicsPipelineDescVertexInputHash>::release(
ContextVk *contextVk);
vk::Context *context);
template angle::Result GraphicsPipelineCache<GraphicsPipelineDescVertexInputHash>::createPipeline(
vk::Context *context,
vk::PipelineCacheAccess *pipelineCache,
Expand All @@ -7287,8 +7289,8 @@ template void GraphicsPipelineCache<GraphicsPipelineDescVertexInputHash>::popula
const vk::GraphicsPipelineDesc &desc,
vk::Pipeline &&pipeline);

template void GraphicsPipelineCache<GraphicsPipelineDescShadersHash>::destroy(ContextVk *contextVk);
template void GraphicsPipelineCache<GraphicsPipelineDescShadersHash>::release(ContextVk *contextVk);
template void GraphicsPipelineCache<GraphicsPipelineDescShadersHash>::destroy(vk::Context *context);
template void GraphicsPipelineCache<GraphicsPipelineDescShadersHash>::release(vk::Context *context);
template angle::Result GraphicsPipelineCache<GraphicsPipelineDescShadersHash>::createPipeline(
vk::Context *context,
vk::PipelineCacheAccess *pipelineCache,
Expand All @@ -7305,9 +7307,9 @@ template void GraphicsPipelineCache<GraphicsPipelineDescShadersHash>::populate(
vk::Pipeline &&pipeline);

template void GraphicsPipelineCache<GraphicsPipelineDescFragmentOutputHash>::destroy(
ContextVk *contextVk);
vk::Context *context);
template void GraphicsPipelineCache<GraphicsPipelineDescFragmentOutputHash>::release(
ContextVk *contextVk);
vk::Context *context);
template angle::Result
GraphicsPipelineCache<GraphicsPipelineDescFragmentOutputHash>::createPipeline(
vk::Context *context,
Expand Down
6 changes: 3 additions & 3 deletions src/libANGLE/renderer/vulkan/vk_cache_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ class PipelineHelper final : public Resource
inline explicit PipelineHelper(Pipeline &&pipeline, CacheLookUpFeedback feedback);

void destroy(VkDevice device);
void release(ContextVk *contextVk);
void release(Context *context);

bool valid() const { return mPipeline.valid(); }
const Pipeline &getPipeline() const { return mPipeline; }
Expand Down Expand Up @@ -2457,8 +2457,8 @@ class GraphicsPipelineCache final : public HasCacheStats<VulkanCacheType::Graphi
GraphicsPipelineCache() = default;
~GraphicsPipelineCache() override { ASSERT(mPayload.empty()); }

void destroy(ContextVk *contextVk);
void release(ContextVk *contextVk);
void destroy(vk::Context *context);
void release(vk::Context *context);

void populate(const vk::GraphicsPipelineDesc &desc, vk::Pipeline &&pipeline);

Expand Down
Loading

0 comments on commit c71a67d

Please sign in to comment.