perf(agc): optimize pipeline cache key construction

This commit is contained in:
boykopovar 2026-09-25 08:25:59 +03:00
parent 5a280ced87
commit 7ed5a0beea
2 changed files with 17 additions and 9 deletions

View File

@ -5,6 +5,7 @@
#include "prx/libSceAgcDriver/Graphics/include/RenderCache.hpp"
#include <list>
#include <map>
#include <string>
namespace AgcDriver::Graphics {
@ -15,13 +16,13 @@ public:
private:
struct Entry {
std::vector<std::byte> key;
std::string key;
std::shared_ptr<ResidentColor> target;
std::shared_ptr<Pipeline> pipeline;
};
Context context;
std::list<Entry> entries;
std::map<std::vector<std::byte>, std::list<Entry>::iterator> lookup;
std::map<std::string, std::list<Entry>::iterator> lookup;
};
}

View File

@ -9,14 +9,14 @@ namespace AgcDriver::Graphics {
namespace {
template<typename TValue>
void append(std::vector<std::byte>& key, const TValue& value) {
void append(std::string& key, const TValue& value) {
static_assert(std::is_trivially_copyable_v<TValue>);
const auto bytes = std::as_bytes(std::span(&value, 1));
key.insert(key.end(), bytes.begin(), bytes.end());
key.append(reinterpret_cast<const char*>(&value), sizeof(value));
}
std::vector<std::byte> makeKey(const Context& context, const State& state, const std::shared_ptr<ResidentColor>& target, const ShaderResources& resources, std::span<const CompiledShader> shaders) {
std::vector<std::byte> key;
std::string makeKey(const Context& context, const State& state, const std::shared_ptr<ResidentColor>& target, const ShaderResources& resources, std::span<const CompiledShader> shaders) {
PerformanceTimer timing("Graphics.PipelineKey");
std::string key;
key.reserve(512);
append(key, target ? target->Target().View() : VK_NULL_HANDLE);
append(key, state.hasColorTarget);
@ -67,7 +67,9 @@ std::vector<std::byte> makeKey(const Context& context, const State& state, const
append(key, tessellation.partitioning);
append(key, tessellation.outputTopology);
}
timing.Mark("state");
const auto input = BuildVertexInputLayout(context, shaders.front().program->vertexAttributes);
timing.Mark("vertex_layout");
append(key, input.bindings.size());
for (const auto& binding : input.bindings) {
append(key, binding.binding);
@ -82,15 +84,20 @@ std::vector<std::byte> makeKey(const Context& context, const State& state, const
append(key, attribute.offset);
}
append(key, resources.LayoutKey().size());
for (const auto value : resources.LayoutKey()) append(key, value);
const auto layout = std::span(resources.LayoutKey());
if (!layout.empty()) key.append(reinterpret_cast<const char*>(layout.data()), layout.size_bytes());
append(key, PushConstantStages(shaders));
append(key, shaders.size());
timing.Mark("resources");
std::uint64_t shaderBytes = 0;
for (const auto& shader : shaders) {
append(key, shader.stage);
append(key, shader.program->spirv.size());
const auto bytes = std::as_bytes(std::span(shader.program->spirv));
key.insert(key.end(), bytes.begin(), bytes.end());
if (!bytes.empty()) key.append(reinterpret_cast<const char*>(bytes.data()), bytes.size());
shaderBytes += bytes.size();
}
timing.Mark("shader_code", shaderBytes);
return key;
}