Skip to content
Merged
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 @@ -31,7 +31,7 @@ struct OptimizedPipeline {
void Release() noexcept;
};

VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPipelineCreateInfo& info, const VkPipelineRenderingCreateInfoKHR& rendering, const VkPipelineLayoutCreateInfo& layout, const PipelineLibraryKeys& keys, std::shared_ptr<OptimizedPipeline>* optimized = nullptr);
VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPipelineCreateInfo& info, const VkPipelineRenderingCreateInfoKHR& rendering, const VkPipelineLayoutCreateInfo& layout, const PipelineLibraryKeys& keys, std::shared_ptr<OptimizedPipeline>* optimized = nullptr, std::span<VkShaderModule> modules = {});

void WaitForOptimizedPipelines(VkDevice device);

Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Pipeline::Pipeline(const Context& context, const State& state, const VertexInput
pipelineInfo.renderPass = renderPass;
if (dynamicRendering) pipelineInfo.pNext = &rendering;
timing.Mark("modules_and_state");
if (libraries) pipeline = LinkPipelineFromLibraries(context, pipelineInfo, rendering, layoutInfo, keys, &optimized);
if (libraries) pipeline = LinkPipelineFromLibraries(context, pipelineInfo, rendering, layoutInfo, keys, &optimized, _modules);
else Check(context.Function<PFN_vkCreateGraphicsPipelines>("vkCreateGraphicsPipelines")(context.device, context.pipelineCache, 1, &pipelineInfo, nullptr, &pipeline), "vkCreateGraphicsPipelines");
if (state.depthBiasPerFace) {
raster.cullMode = VK_CULL_MODE_FRONT_BIT;
Expand Down
17 changes: 15 additions & 2 deletions core/libs/prx/libSceAgcDriver/Graphics/src/PipelineLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ using Key = std::vector<std::byte>;
struct DeviceLibraries {
PFN_vkDestroyPipeline destroyPipeline = nullptr;
PFN_vkDestroyPipelineLayout destroyLayout = nullptr;
PFN_vkDestroyShaderModule destroyModule = nullptr;
std::map<Key, VkPipelineLayout> layouts;
std::array<std::map<Key, VkPipeline>, 4> parts;
std::vector<VkShaderModule> modules;
PipelineLibraryCounters counters;
};

Expand Down Expand Up @@ -99,14 +101,15 @@ std::span<const VkDynamicState> PipelineLibraryDynamicStates() {
return dynamicStates;
}

VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPipelineCreateInfo& info, const VkPipelineRenderingCreateInfoKHR& rendering, const VkPipelineLayoutCreateInfo& layout, const PipelineLibraryKeys& keys, std::shared_ptr<OptimizedPipeline>* optimized) {
VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPipelineCreateInfo& info, const VkPipelineRenderingCreateInfoKHR& rendering, const VkPipelineLayoutCreateInfo& layout, const PipelineLibraryKeys& keys, std::shared_ptr<OptimizedPipeline>* optimized, std::span<VkShaderModule> modules) {
Require(info.renderPass == VK_NULL_HANDLE && info.pDynamicState != nullptr, "pipeline library parts need dynamic rendering and the library dynamic states");
auto& store = Libraries();
std::lock_guard lock(store.mutex);
auto& device = store.devices[context.device];
if (device.destroyPipeline == nullptr) {
device.destroyPipeline = context.Function<PFN_vkDestroyPipeline>("vkDestroyPipeline");
device.destroyLayout = context.Function<PFN_vkDestroyPipelineLayout>("vkDestroyPipelineLayout");
device.destroyModule = context.Function<PFN_vkDestroyShaderModule>("vkDestroyShaderModule");
}
auto pipelineLayout = device.layouts.find(keys.layout);
if (pipelineLayout == device.layouts.end()) {
Expand Down Expand Up @@ -135,6 +138,7 @@ VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPip
const std::array<const Key*, 4> contextKeys{&none, &keys.layout, &keys.layout, &keys.renderPass};
const VkPipelineRenderingCreateInfoKHR shaderRendering{VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR};
VkPipelineDepthStencilStateCreateInfo dynamicDepth{VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO};
static const bool optimize = std::getenv("APS5_NO_PIPELINE_LTO") == nullptr;
std::vector<VkPipeline> libraries;
for (std::size_t part = 0; part < flags.size(); ++part) {
if (part == 0 && mesh) continue;
Expand Down Expand Up @@ -179,6 +183,15 @@ VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPip
VkPipeline handle = VK_NULL_HANDLE;
Check(context.Function<PFN_vkCreateGraphicsPipelines>("vkCreateGraphicsPipelines")(context.device, context.pipelineCache, 1, &create, nullptr, &handle), "vkCreateGraphicsPipelines library");
cache.emplace(key, handle);
if (optimize) {
for (std::uint32_t stage = 0; stage < create.stageCount; ++stage) {
for (auto& module : modules) {
if (module == VK_NULL_HANDLE || module != create.pStages[stage].module) continue;
device.modules.push_back(module);
module = VK_NULL_HANDLE;
}
}
}
++device.counters.built[part];
libraries.push_back(handle);
}
Expand All @@ -191,7 +204,6 @@ VkPipeline LinkPipelineFromLibraries(const Context& context, const VkGraphicsPip
VkPipeline pipeline = VK_NULL_HANDLE;
Check(context.Function<PFN_vkCreateGraphicsPipelines>("vkCreateGraphicsPipelines")(context.device, context.pipelineCache, 1, &create, nullptr, &pipeline), "vkCreateGraphicsPipelines link");
++device.counters.linked;
static const bool optimize = std::getenv("APS5_NO_PIPELINE_LTO") == nullptr;
if (optimize && optimized != nullptr) {
auto slot = std::make_shared<OptimizedPipeline>();
slot->device = context.device;
Expand Down Expand Up @@ -242,6 +254,7 @@ void ClearPipelineLibraries(VkDevice device) {
for (auto& part : libraries.parts) {
for (const auto& [key, handle] : part) libraries.destroyPipeline(device, handle, nullptr);
}
for (const auto module : libraries.modules) libraries.destroyModule(device, module, nullptr);
for (const auto& [key, handle] : libraries.layouts) libraries.destroyLayout(device, handle, nullptr);
store.devices.erase(found);
}
Expand Down
Loading