[dxvk] Pass pipeline manager to pipeline library constructor

This commit is contained in:
Philip Rebohle 2022-07-08 11:33:07 +02:00
parent 498444f1a8
commit 4535fdc336
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
6 changed files with 34 additions and 27 deletions

View File

@ -41,7 +41,7 @@ namespace dxvk {
// pipeline variant unconditionally since there is no state for us
// to worry about other than specialization constants
if (unlikely(!m_libraryHandle)) {
m_libraryHandle = m_library->getPipelineHandle(m_cache->handle(),
m_libraryHandle = m_library->getPipelineHandle(
DxvkShaderPipelineLibraryCompileArgs());
m_stats->numComputePipelines += 1;
}

View File

@ -707,8 +707,8 @@ namespace dxvk {
std::array<VkPipeline, 4> libraries = {{
key.viLibrary->getHandle(),
m_vsLibrary->getPipelineHandle(m_cache->handle(), key.args),
m_fsLibrary->getPipelineHandle(m_cache->handle(), key.args),
m_vsLibrary->getPipelineHandle(key.args),
m_fsLibrary->getPipelineHandle(key.args),
key.foLibrary->getHandle(),
}};

View File

@ -144,7 +144,7 @@ namespace dxvk {
if (l) {
if (l->pipelineLibrary)
l->pipelineLibrary->compilePipeline(m_cache->handle());
l->pipelineLibrary->compilePipeline();
m_pendingTasks -= 1;
}
@ -172,7 +172,7 @@ namespace dxvk {
if (m_device->canUseGraphicsPipelineLibrary()) {
auto library = createNullFsPipelineLibrary();
library->compilePipeline(m_cache.handle());
library->compilePipeline();
}
}
@ -353,7 +353,7 @@ namespace dxvk {
auto iter = m_shaderLibraries.emplace(
std::piecewise_construct,
std::tuple(key),
std::tuple(m_device, shader.ptr(), layout));
std::tuple(m_device, this, shader.ptr(), layout));
return &iter.first->second;
}
@ -366,7 +366,7 @@ namespace dxvk {
auto iter = m_shaderLibraries.emplace(
std::piecewise_construct,
std::tuple(),
std::tuple(m_device, nullptr, layout));
std::tuple(m_device, this, nullptr, layout));
return &iter.first->second;
}

View File

@ -138,6 +138,7 @@ namespace dxvk {
class DxvkPipelineManager {
friend class DxvkComputePipeline;
friend class DxvkGraphicsPipeline;
friend class DxvkShaderPipelineLibrary;
public:
DxvkPipelineManager(

View File

@ -1,4 +1,5 @@
#include "dxvk_device.h"
#include "dxvk_pipemanager.h"
#include "dxvk_shader.h"
#include <dxvk_dummy_frag.h>
@ -426,9 +427,14 @@ namespace dxvk {
DxvkShaderPipelineLibrary::DxvkShaderPipelineLibrary(
const DxvkDevice* device,
DxvkPipelineManager* manager,
const DxvkShader* shader,
const DxvkBindingLayoutObjects* layout)
: m_device(device), m_shader(shader), m_layout(layout) {
: m_device (device),
m_cache (&manager->m_cache),
m_stats (&manager->m_stats),
m_shader (shader),
m_layout (layout) {
}
@ -442,7 +448,6 @@ namespace dxvk {
VkPipeline DxvkShaderPipelineLibrary::getPipelineHandle(
VkPipelineCache cache,
const DxvkShaderPipelineLibraryCompileArgs& args) {
std::lock_guard lock(m_mutex);
@ -460,15 +465,15 @@ namespace dxvk {
switch (stage) {
case VK_SHADER_STAGE_VERTEX_BIT:
pipeline = compileVertexShaderPipeline(cache, args);
pipeline = compileVertexShaderPipeline(args);
break;
case VK_SHADER_STAGE_FRAGMENT_BIT:
pipeline = compileFragmentShaderPipeline(cache);
pipeline = compileFragmentShaderPipeline();
break;
case VK_SHADER_STAGE_COMPUTE_BIT:
pipeline = compileComputeShaderPipeline(cache);
pipeline = compileComputeShaderPipeline();
break;
default:
@ -480,16 +485,15 @@ namespace dxvk {
}
void DxvkShaderPipelineLibrary::compilePipeline(VkPipelineCache cache) {
void DxvkShaderPipelineLibrary::compilePipeline() {
// Just compile the pipeline with default args. Implicitly skips
// this step if another thread has compiled the pipeline in the
// meantime, in order to avoid duplicate work.
getPipelineHandle(cache, DxvkShaderPipelineLibraryCompileArgs());
getPipelineHandle(DxvkShaderPipelineLibraryCompileArgs());
}
VkPipeline DxvkShaderPipelineLibrary::compileVertexShaderPipeline(
VkPipelineCache cache,
const DxvkShaderPipelineLibraryCompileArgs& args) {
auto vk = m_device->vkd();
@ -552,14 +556,14 @@ namespace dxvk {
VkPipeline pipeline = VK_NULL_HANDLE;
if (vk->vkCreateGraphicsPipelines(vk->device(), cache, 1, &info, nullptr, &pipeline))
if (vk->vkCreateGraphicsPipelines(vk->device(), m_cache->handle(), 1, &info, nullptr, &pipeline))
throw DxvkError("DxvkShaderPipelineLibrary: Failed to create compute pipeline");
return pipeline;
}
VkPipeline DxvkShaderPipelineLibrary::compileFragmentShaderPipeline(VkPipelineCache cache) {
VkPipeline DxvkShaderPipelineLibrary::compileFragmentShaderPipeline() {
auto vk = m_device->vkd();
// Initialize code buffer. As a special case, it is possible that
@ -633,14 +637,14 @@ namespace dxvk {
VkPipeline pipeline = VK_NULL_HANDLE;
if (vk->vkCreateGraphicsPipelines(vk->device(), cache, 1, &info, nullptr, &pipeline))
if (vk->vkCreateGraphicsPipelines(vk->device(), m_cache->handle(), 1, &info, nullptr, &pipeline))
throw DxvkError("DxvkShaderPipelineLibrary: Failed to create compute pipeline");
return pipeline;
}
VkPipeline DxvkShaderPipelineLibrary::compileComputeShaderPipeline(VkPipelineCache cache) {
VkPipeline DxvkShaderPipelineLibrary::compileComputeShaderPipeline() {
auto vk = m_device->vkd();
DxvkShaderStageInfo stageInfo(m_device);
@ -655,7 +659,7 @@ namespace dxvk {
VkPipeline pipeline = VK_NULL_HANDLE;
if (vk->vkCreateComputePipelines(vk->device(), cache, 1, &info, nullptr, &pipeline))
if (vk->vkCreateComputePipelines(vk->device(), m_cache->handle(), 1, &info, nullptr, &pipeline))
throw DxvkError("DxvkShaderPipelineLibrary: Failed to create compute pipeline");
return pipeline;

View File

@ -4,6 +4,7 @@
#include "dxvk_include.h"
#include "dxvk_limits.h"
#include "dxvk_pipecache.h"
#include "dxvk_pipelayout.h"
#include "dxvk_shader_key.h"
@ -14,6 +15,8 @@ namespace dxvk {
class DxvkShader;
class DxvkShaderModule;
class DxvkPipelineManager;
struct DxvkPipelineStats;
/**
* \brief Built-in specialization constants
@ -335,6 +338,7 @@ namespace dxvk {
DxvkShaderPipelineLibrary(
const DxvkDevice* device,
DxvkPipelineManager* manager,
const DxvkShader* shader,
const DxvkBindingLayoutObjects* layout);
@ -345,12 +349,10 @@ namespace dxvk {
*
* Either returns an already compiled pipeline library object, or
* performs the compilation step if that has not happened yet.
* \param [in] cache Pipeline cache handle
* \param [in] args Compile arguments
* \returns Vulkan pipeline handle
*/
VkPipeline getPipelineHandle(
VkPipelineCache cache,
const DxvkShaderPipelineLibraryCompileArgs& args);
/**
@ -359,13 +361,14 @@ namespace dxvk {
* This is meant to be called from a worker thread in
* order to reduce the amount of work done on the app's
* main thread.
* \param [in] cache Pipeline cache handle
*/
void compilePipeline(VkPipelineCache cache);
void compilePipeline();
private:
const DxvkDevice* m_device;
DxvkPipelineCache* m_cache;
DxvkPipelineStats* m_stats;
const DxvkShader* m_shader;
const DxvkBindingLayoutObjects* m_layout;
@ -374,12 +377,11 @@ namespace dxvk {
VkPipeline m_pipelineNoDepthClip = VK_NULL_HANDLE;
VkPipeline compileVertexShaderPipeline(
VkPipelineCache cache,
const DxvkShaderPipelineLibraryCompileArgs& args);
VkPipeline compileFragmentShaderPipeline(VkPipelineCache cache);
VkPipeline compileFragmentShaderPipeline();
VkPipeline compileComputeShaderPipeline(VkPipelineCache cache);
VkPipeline compileComputeShaderPipeline();
};