From ce428af2e67d046e22b115354b568a966d567d46 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 3 Dec 2022 14:41:42 +0000 Subject: [PATCH] Use attachment formats rather than views in VK pipeline cache --- .../gpu/cache/graphics_pipeline_cache.cpp | 87 +++++++------------ .../gpu/cache/graphics_pipeline_cache.h | 13 +-- 2 files changed, 36 insertions(+), 64 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.cpp b/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.cpp index 7d6bd0ae..300222cd 100644 --- a/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.cpp +++ b/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.cpp @@ -36,15 +36,11 @@ namespace skyline::gpu::cache { colorBlendState.pAttachments = colorBlendAttachments.data(); - for (auto &colorAttachment : state.colorAttachments) { - if (colorAttachment) - colorAttachments.emplace_back(AttachmentMetadata{colorAttachment->format->vkFormat, colorAttachment->texture->sampleCount}); - else - colorAttachments.emplace_back(AttachmentMetadata{vk::Format::eUndefined, vk::SampleCountFlagBits::e1}); - } + for (auto &colorFormat : state.colorFormats) + colorFormats.emplace_back(colorFormat); - if (state.depthStencilAttachment) - depthStencilAttachment.emplace(AttachmentMetadata{state.depthStencilAttachment->format->vkFormat, state.depthStencilAttachment->texture->sampleCount}); + depthStencilFormat = state.depthStencilFormat; + sampleCount = state.sampleCount; } #undef VEC_CPY @@ -168,45 +164,23 @@ namespace skyline::gpu::cache { HASH(static_cast(attachment.srcColorBlendFactor)); } + HASH(key.colorFormats.size()); + for (auto format : key.colorFormats) { + HASH(format); + } + + HASH(key.depthStencilFormat); + HASH(key.sampleCount); + return hash; } size_t GraphicsPipelineCache::PipelineStateHash::operator()(const GraphicsPipelineCache::PipelineState &key) const { - size_t hash{HashCommonPipelineState(key)}; - - HASH(key.colorAttachments.size()); - for (const auto &attachment : key.colorAttachments) { - if (attachment) { - HASH(attachment->format->vkFormat); - HASH(attachment->texture->sampleCount); - } - } - - HASH(key.depthStencilAttachment != nullptr); - if (key.depthStencilAttachment != nullptr) { - HASH(key.depthStencilAttachment->format->vkFormat); - HASH(key.depthStencilAttachment->texture->sampleCount); - } - - return hash; + return HashCommonPipelineState(key); } size_t GraphicsPipelineCache::PipelineStateHash::operator()(const GraphicsPipelineCache::PipelineCacheKey &key) const { - size_t hash{HashCommonPipelineState(key)}; - - HASH(key.colorAttachments.size()); - for (const auto &attachment : key.colorAttachments) { - HASH(attachment.format); - HASH(attachment.sampleCount); - } - - HASH(key.depthStencilAttachment.has_value()); - if (key.depthStencilAttachment) { - HASH(key.depthStencilAttachment->format); - HASH(key.depthStencilAttachment->sampleCount); - } - - return hash; + return HashCommonPipelineState(key); } #undef HASH @@ -296,16 +270,13 @@ namespace skyline::gpu::cache { KEYNEQ(colorBlendState.blendConstants) ) - RETF(CARREQ(colorAttachments.begin(), colorAttachments.size(), { - return lhs.format == rhs->format->vkFormat && lhs.sampleCount == rhs->texture->sampleCount; + RETF(CARREQ(colorFormats.begin(), colorFormats.size(), { + return lhs == rhs; })) - RETF(lhs.depthStencilAttachment.has_value() != (rhs.depthStencilAttachment != nullptr) || - (lhs.depthStencilAttachment.has_value() && - lhs.depthStencilAttachment->format != rhs.depthStencilAttachment->format->vkFormat && - lhs.depthStencilAttachment->sampleCount != rhs.depthStencilAttachment->texture->sampleCount - ) - ) + RETF(lhs.depthStencilFormat == rhs.depthStencilFormat) + RETF(lhs.sampleCount == rhs.sampleCount) + #undef ARREQ #undef CARREQ @@ -349,22 +320,22 @@ namespace skyline::gpu::cache { boost::container::small_vector attachmentDescriptions; boost::container::small_vector attachmentReferences; - auto pushAttachment{[&](TextureView *view) { - if (view) { + auto pushAttachment{[&](vk::Format format) { + if (format != vk::Format::eUndefined) { attachmentDescriptions.push_back(vk::AttachmentDescription{ - .format = view->format->vkFormat, - .samples = view->texture->sampleCount, + .format = format, + .samples = state.sampleCount, .loadOp = vk::AttachmentLoadOp::eLoad, .storeOp = vk::AttachmentStoreOp::eStore, .stencilLoadOp = vk::AttachmentLoadOp::eLoad, .stencilStoreOp = vk::AttachmentStoreOp::eStore, - .initialLayout = view->texture->layout, - .finalLayout = view->texture->layout, + .initialLayout = vk::ImageLayout::eGeneral, + .finalLayout = vk::ImageLayout::eGeneral, .flags = vk::AttachmentDescriptionFlagBits::eMayAlias }); attachmentReferences.push_back(vk::AttachmentReference{ .attachment = static_cast(attachmentDescriptions.size() - 1), - .layout = view->texture->layout, + .layout = vk::ImageLayout::eGeneral, }); } else { attachmentReferences.push_back(vk::AttachmentReference{ @@ -378,11 +349,11 @@ namespace skyline::gpu::cache { .pipelineBindPoint = vk::PipelineBindPoint::eGraphics, }; - for (auto &colorAttachment : state.colorAttachments) + for (auto &colorAttachment : state.colorFormats) pushAttachment(colorAttachment); - if (state.depthStencilAttachment) { - pushAttachment(state.depthStencilAttachment); + if (state.depthStencilFormat != vk::Format::eUndefined) { + pushAttachment(state.depthStencilFormat); subpassDescription.pColorAttachments = attachmentReferences.data(); subpassDescription.colorAttachmentCount = static_cast(attachmentReferences.size() - 1); diff --git a/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.h b/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.h index 215515b1..8607f1c0 100644 --- a/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.h +++ b/app/src/main/cpp/skyline/gpu/cache/graphics_pipeline_cache.h @@ -31,8 +31,9 @@ namespace skyline::gpu::cache { const vk::PipelineColorBlendStateCreateInfo &colorBlendState; const vk::PipelineDynamicStateCreateInfo &dynamicState; - span colorAttachments; //!< All color attachments in the subpass of this pipeline - TextureView *depthStencilAttachment; //!< A nullable pointer to the depth/stencil attachment in the subpass of this pipeline + span colorFormats; //!< All color attachment formats in the subpass of this pipeline + vk::Format depthStencilFormat; //!< The depth attachment format in the subpass of this pipeline, 'Undefined' if there is no depth attachment + vk::SampleCountFlagBits sampleCount; //!< The sample count of the subpass of this pipeline constexpr const vk::PipelineVertexInputStateCreateInfo &VertexInputState() const { return vertexState.get(); @@ -63,9 +64,8 @@ namespace skyline::gpu::cache { */ struct AttachmentMetadata { vk::Format format; - vk::SampleCountFlagBits sampleCount; - constexpr AttachmentMetadata(vk::Format format, vk::SampleCountFlagBits sampleCount) : format(format), sampleCount(sampleCount) {} + constexpr AttachmentMetadata(vk::Format format, vk::SampleCountFlagBits sampleCount) : format(format) {} bool operator==(const AttachmentMetadata &rhs) const = default; }; @@ -91,8 +91,9 @@ namespace skyline::gpu::cache { vk::PipelineDynamicStateCreateInfo dynamicState; std::vector colorBlendAttachments; - std::vector colorAttachments; - std::optional depthStencilAttachment; + std::vector colorFormats; + vk::Format depthStencilFormat; + vk::SampleCountFlagBits sampleCount; PipelineCacheKey(const PipelineState& state);