Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class ShaderResources {
// (their count and size remain): a compute template then serves dispatches whose constants
// differ, and the hit refreshes its data buffers with the dispatch's words (RefreshData).
static std::vector<std::uint32_t> ContentKey(const CompiledShader& shader, bool dataWords = true, bool movableBuffers = false);
static void AppendContentKey(std::vector<std::uint32_t>& key, const CompiledShader& shader, bool dataWords = true, bool movableBuffers = false);
static bool DiffContentKeys(std::span<const std::uint32_t> previous, std::span<const std::uint32_t> key, bool draw, ContentKeyDiff& diff);
// Records the shader's ShaderData and FlattenedSrt words into this object's data buffers
// (vkCmdUpdateBuffer, a transfer write the caller's pre-dispatch barrier makes visible; a
Expand Down
17 changes: 13 additions & 4 deletions core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,26 @@ bool MovableBuffers() {
}

ResourceCache::Key DrawResourceKey(const Context& context, std::span<const CompiledShader> shaders, const ColorTarget& target, std::uint32_t colorAttachments, std::uint64_t indexAddress, std::uint64_t indexBytes, bool ranges) {
ResourceCache::Key key{0xffffffffu};
ResourceCache::Key key;
std::size_t reserve = 16u;
for (const auto& shader : shaders) {
Require(shader.program != nullptr, "missing compiled shader");
if (reserve > key.max_size() - 8u || shader.program->bindings.size() > (key.max_size() - reserve - 8u) / 12u) throw std::length_error("draw resource key exceeds vector limits");
reserve += 8u + shader.program->bindings.size() * 12u;
}
key.reserve(reserve);
key.push_back(0xffffffffu);
const auto append64 = [&](std::uint64_t value) {
key.push_back(static_cast<std::uint32_t>(value));
key.push_back(static_cast<std::uint32_t>(value >> 32u));
};
append64(reinterpret_cast<std::uint64_t>(context.device));
key.push_back(static_cast<std::uint32_t>(shaders.size()));
for (const auto& shader : shaders) {
const auto part = ShaderResources::ContentKey(shader, true, MovableBuffers());
key.push_back(static_cast<std::uint32_t>(part.size()));
key.insert(key.end(), part.begin(), part.end());
const auto length = key.size();
key.push_back(0);
ShaderResources::AppendContentKey(key, shader, true, MovableBuffers());
key[length] = static_cast<std::uint32_t>(key.size() - length - 1u);
}
key.push_back(colorAttachments);
if (ranges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1850,10 +1850,14 @@ std::vector<std::uint32_t> ShaderResources::ContentKey(const CompiledShader& sha
for (const auto* bits : {&binding.imageWritten, &binding.samplerDepthCompare, &binding.imageDepthCompare, &binding.imageAtomic, &binding.samplerUnnormalized, &binding.samplerIntegerBorder, &binding.imageUnnormalized, &binding.imageUnnormalizedBaseLevel, &binding.bufferWritten}) addWords(bits->size() / 32u + (bits->size() % 32u != 0 ? 1u : 0u));
}
key.reserve(words);
VisitContentKey(shader, dataWords, movableBuffers, [&](std::uint32_t word) { key.push_back(word); });
AppendContentKey(key, shader, dataWords, movableBuffers);
return key;
}

void ShaderResources::AppendContentKey(std::vector<std::uint32_t>& key, const CompiledShader& shader, bool dataWords, bool movableBuffers) {
VisitContentKey(shader, dataWords, movableBuffers, [&](std::uint32_t word) { key.push_back(word); });
}

namespace {

using Component = ContentKeyComponent;
Expand Down
5 changes: 5 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6006,6 +6006,11 @@ void ResourceContentKeyTests(bool benchmark) {
const AgcDriver::Graphics::CompiledShader shader{ShaderRecompiler::ShaderStage::Compute, &program, 0};
for (const bool dataWords : {false, true}) for (const bool movable : {false, true}) {
const auto original = ShaderResources::ContentKey(shader, dataWords, movable);
std::vector<std::uint32_t> combined{0x12345678u, 0xabcdef01u};
ShaderResources::AppendContentKey(combined, shader, dataWords, movable);
Require(combined.size() == original.size() + 2u && combined[0] == 0x12345678u && combined[1] == 0xabcdef01u && std::ranges::equal(std::span(combined).subspan(2), original), "appending a content key changed its prefix or serialized words");
ShaderResources::AppendContentKey(combined, shader, dataWords, movable);
Require(combined.size() == original.size() * 2u + 2u && std::ranges::equal(std::span(combined).subspan(2, original.size()), original) && std::ranges::equal(std::span(combined).subspan(2 + original.size()), original), "appending another stage changed an earlier content key");
program.bindings[1].guestDescriptor.back() ^= 1u;
Require((ShaderResources::ContentKey(shader, dataWords, movable) != original) == (dataWords && !movable), "content key changed its data-word policy");
program.bindings[1].guestDescriptor.back() ^= 1u;
Expand Down
Loading