mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-20 19:54:19 +01:00
[dxvk] Repurpose asynchronous pipeline compiler
Removes support for DISABLE_OPTIMIZATION_BIT. Instead, pipelines will not be made available until compiled by one of the worker threads.
This commit is contained in:
parent
012a5c2f74
commit
c3b542878c
@ -39,19 +39,17 @@ namespace dxvk {
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkGraphicsPipelineStateInfo& stateVector,
|
||||
VkRenderPass renderPass,
|
||||
VkPipeline basePipeline)
|
||||
VkPipeline pipeline)
|
||||
: m_vkd (vkd),
|
||||
m_stateVector (stateVector),
|
||||
m_renderPass (renderPass),
|
||||
m_basePipeline(basePipeline),
|
||||
m_fastPipeline(VK_NULL_HANDLE) {
|
||||
m_pipeline (pipeline) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
DxvkGraphicsPipelineInstance::~DxvkGraphicsPipelineInstance() {
|
||||
m_vkd->vkDestroyPipeline(m_vkd->device(), m_basePipeline, nullptr);
|
||||
m_vkd->vkDestroyPipeline(m_vkd->device(), m_fastPipeline, nullptr);
|
||||
m_vkd->vkDestroyPipeline(m_vkd->device(), m_pipeline, nullptr);
|
||||
}
|
||||
|
||||
|
||||
@ -123,14 +121,17 @@ namespace dxvk {
|
||||
|
||||
// If no pipeline instance exists with the given state
|
||||
// vector, create a new one and add it to the list.
|
||||
VkPipeline newPipelineBase = m_basePipelineBase.load();
|
||||
VkPipeline newPipelineHandle = this->compilePipeline(state, renderPassHandle,
|
||||
m_compiler != nullptr ? VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT : 0,
|
||||
newPipelineBase);
|
||||
VkPipeline newPipelineBase = m_basePipeline.load();
|
||||
VkPipeline newPipelineHandle = VK_NULL_HANDLE;
|
||||
|
||||
if (m_compiler == nullptr) {
|
||||
newPipelineHandle = this->compilePipeline(
|
||||
state, renderPassHandle, newPipelineBase);
|
||||
}
|
||||
|
||||
Rc<DxvkGraphicsPipelineInstance> newPipeline =
|
||||
new DxvkGraphicsPipelineInstance(m_device->vkd(), state,
|
||||
renderPassHandle, newPipelineHandle);
|
||||
new DxvkGraphicsPipelineInstance(m_device->vkd(),
|
||||
state, renderPassHandle, newPipelineHandle);
|
||||
|
||||
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
|
||||
|
||||
@ -144,15 +145,15 @@ namespace dxvk {
|
||||
|
||||
// Add new pipeline to the set
|
||||
m_pipelines.push_back(newPipeline);
|
||||
|
||||
|
||||
stats.addCtr(DxvkStatCounter::PipeCountGraphics, 1);
|
||||
}
|
||||
|
||||
// Use the new pipeline as the base pipeline for derivative pipelines
|
||||
if (newPipelineBase == VK_NULL_HANDLE && newPipelineHandle != VK_NULL_HANDLE)
|
||||
m_basePipelineBase.compare_exchange_strong(newPipelineBase, newPipelineHandle);
|
||||
m_basePipeline.compare_exchange_strong(newPipelineBase, newPipelineHandle);
|
||||
|
||||
// Compile optimized pipeline asynchronously
|
||||
// Compile pipeline asynchronously if requested
|
||||
if (m_compiler != nullptr)
|
||||
m_compiler->queueCompilation(this, newPipeline);
|
||||
|
||||
@ -163,18 +164,18 @@ namespace dxvk {
|
||||
void DxvkGraphicsPipeline::compileInstance(
|
||||
const Rc<DxvkGraphicsPipelineInstance>& instance) {
|
||||
// Compile an optimized version of the pipeline
|
||||
VkPipeline newPipelineBase = m_fastPipelineBase.load();
|
||||
VkPipeline newPipelineBase = m_basePipeline.load();
|
||||
VkPipeline newPipelineHandle = this->compilePipeline(
|
||||
instance->m_stateVector, instance->m_renderPass,
|
||||
0, m_fastPipelineBase);
|
||||
newPipelineBase);
|
||||
|
||||
if (!instance->setFastPipeline(newPipelineHandle)) {
|
||||
if (!instance->setPipeline(newPipelineHandle)) {
|
||||
// If another thread finished compiling an optimized version of this
|
||||
// pipeline before this one finished, discard the new pipeline object.
|
||||
m_vkd->vkDestroyPipeline(m_vkd->device(), newPipelineHandle, nullptr);
|
||||
} else if (newPipelineBase == VK_NULL_HANDLE && newPipelineHandle != VK_NULL_HANDLE) {
|
||||
// Use the new pipeline as the base pipeline for derivative pipelines.
|
||||
m_fastPipelineBase.compare_exchange_strong(newPipelineBase, newPipelineHandle);
|
||||
m_basePipeline.compare_exchange_strong(newPipelineBase, newPipelineHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +195,6 @@ namespace dxvk {
|
||||
VkPipeline DxvkGraphicsPipeline::compilePipeline(
|
||||
const DxvkGraphicsPipelineStateInfo& state,
|
||||
VkRenderPass renderPass,
|
||||
VkPipelineCreateFlags createFlags,
|
||||
VkPipeline baseHandle) const {
|
||||
if (Logger::logLevel() <= LogLevel::Debug) {
|
||||
Logger::debug("Compiling graphics pipeline...");
|
||||
@ -363,7 +363,7 @@ namespace dxvk {
|
||||
VkGraphicsPipelineCreateInfo info;
|
||||
info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
info.flags = createFlags;
|
||||
info.flags = 0;
|
||||
info.stageCount = stages.size();
|
||||
info.pStages = stages.data();
|
||||
info.pVertexInputState = &viInfo;
|
||||
|
@ -88,8 +88,8 @@ namespace dxvk {
|
||||
/**
|
||||
* \brief Graphics pipeline instance
|
||||
*
|
||||
* Stores a state vector and the corresponding
|
||||
* unoptimized and optimized pipeline handles.
|
||||
* Stores a state vector and the
|
||||
* corresponding pipeline handle.
|
||||
*/
|
||||
class DxvkGraphicsPipelineInstance : public RcObject {
|
||||
friend class DxvkGraphicsPipeline;
|
||||
@ -99,7 +99,7 @@ namespace dxvk {
|
||||
const Rc<vk::DeviceFn>& vkd,
|
||||
const DxvkGraphicsPipelineStateInfo& stateVector,
|
||||
VkRenderPass renderPass,
|
||||
VkPipeline basePipeline);
|
||||
VkPipeline pipeline);
|
||||
|
||||
~DxvkGraphicsPipelineInstance();
|
||||
|
||||
@ -125,9 +125,9 @@ namespace dxvk {
|
||||
* handle should be destroyed.
|
||||
* \param [in] pipeline The optimized pipeline
|
||||
*/
|
||||
bool setFastPipeline(VkPipeline pipeline) {
|
||||
bool setPipeline(VkPipeline pipeline) {
|
||||
VkPipeline expected = VK_NULL_HANDLE;
|
||||
return m_fastPipeline.compare_exchange_strong(expected, pipeline);
|
||||
return m_pipeline.compare_exchange_strong(expected, pipeline);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,11 +138,7 @@ namespace dxvk {
|
||||
* \returns The pipeline handle
|
||||
*/
|
||||
VkPipeline getPipeline() const {
|
||||
VkPipeline basePipeline = m_basePipeline.load();
|
||||
VkPipeline fastPipeline = m_fastPipeline.load();
|
||||
|
||||
return fastPipeline != VK_NULL_HANDLE
|
||||
? fastPipeline : basePipeline;
|
||||
return m_pipeline.load();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -151,9 +147,8 @@ namespace dxvk {
|
||||
|
||||
DxvkGraphicsPipelineStateInfo m_stateVector;
|
||||
VkRenderPass m_renderPass;
|
||||
|
||||
std::atomic<VkPipeline> m_basePipeline;
|
||||
std::atomic<VkPipeline> m_fastPipeline;
|
||||
|
||||
std::atomic<VkPipeline> m_pipeline;
|
||||
|
||||
};
|
||||
|
||||
@ -248,8 +243,7 @@ namespace dxvk {
|
||||
std::vector<Rc<DxvkGraphicsPipelineInstance>> m_pipelines;
|
||||
|
||||
// Pipeline handles used for derivative pipelines
|
||||
std::atomic<VkPipeline> m_basePipelineBase = { VK_NULL_HANDLE };
|
||||
std::atomic<VkPipeline> m_fastPipelineBase = { VK_NULL_HANDLE };
|
||||
std::atomic<VkPipeline> m_basePipeline = { VK_NULL_HANDLE };
|
||||
|
||||
DxvkGraphicsPipelineInstance* findInstance(
|
||||
const DxvkGraphicsPipelineStateInfo& state,
|
||||
@ -258,7 +252,6 @@ namespace dxvk {
|
||||
VkPipeline compilePipeline(
|
||||
const DxvkGraphicsPipelineStateInfo& state,
|
||||
VkRenderPass renderPass,
|
||||
VkPipelineCreateFlags createFlags,
|
||||
VkPipeline baseHandle) const;
|
||||
|
||||
bool validatePipelineState(
|
||||
|
Loading…
x
Reference in New Issue
Block a user