2017-12-07 09:38:31 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-05-01 16:45:28 +02:00
|
|
|
#include <mutex>
|
2017-12-07 09:38:31 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "dxvk_compute.h"
|
|
|
|
#include "dxvk_graphics.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
2018-09-21 22:28:06 +02:00
|
|
|
|
2018-09-21 23:23:43 +02:00
|
|
|
class DxvkStateCache;
|
|
|
|
|
2018-09-21 22:28:06 +02:00
|
|
|
/**
|
|
|
|
* \brief Pipeline count
|
|
|
|
*
|
|
|
|
* Stores number of graphics and
|
|
|
|
* compute pipelines, individually.
|
|
|
|
*/
|
|
|
|
struct DxvkPipelineCount {
|
|
|
|
uint32_t numGraphicsPipelines;
|
|
|
|
uint32_t numComputePipelines;
|
|
|
|
};
|
2017-12-07 09:38:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct DxvkPipelineKeyHash {
|
2019-07-23 12:41:09 +02:00
|
|
|
size_t operator () (const DxvkComputePipelineShaders& key) const;
|
|
|
|
size_t operator () (const DxvkGraphicsPipelineShaders& key) const;
|
2017-12-07 09:38:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DxvkPipelineKeyEq {
|
2019-07-23 12:41:09 +02:00
|
|
|
bool operator () (const DxvkComputePipelineShaders& a, const DxvkComputePipelineShaders& b) const;
|
|
|
|
bool operator () (const DxvkGraphicsPipelineShaders& a, const DxvkGraphicsPipelineShaders& b) const;
|
2017-12-07 09:38:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Pipeline manager
|
|
|
|
*
|
|
|
|
* Creates and stores graphics pipelines and compute
|
|
|
|
* pipelines for each combination of shaders that is
|
|
|
|
* used within the application. This is necessary
|
|
|
|
* because DXVK does not expose the concept of shader
|
|
|
|
* pipeline objects to the client API.
|
|
|
|
*/
|
|
|
|
class DxvkPipelineManager : public RcObject {
|
2018-09-21 19:42:48 +02:00
|
|
|
friend class DxvkComputePipeline;
|
|
|
|
friend class DxvkGraphicsPipeline;
|
2017-12-07 09:38:31 +01:00
|
|
|
public:
|
|
|
|
|
2018-09-21 23:23:43 +02:00
|
|
|
DxvkPipelineManager(
|
|
|
|
const DxvkDevice* device,
|
|
|
|
DxvkRenderPassPool* passManager);
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
~DxvkPipelineManager();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Retrieves a compute pipeline object
|
|
|
|
*
|
|
|
|
* If a pipeline for the given shader stage object
|
|
|
|
* already exists, it will be returned. Otherwise,
|
|
|
|
* a new pipeline will be created.
|
|
|
|
* \param [in] cs Compute shader
|
|
|
|
* \returns Compute pipeline object
|
|
|
|
*/
|
|
|
|
Rc<DxvkComputePipeline> createComputePipeline(
|
2018-01-13 22:18:32 +01:00
|
|
|
const Rc<DxvkShader>& cs);
|
2017-12-07 09:38:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Retrieves a graphics pipeline object
|
|
|
|
*
|
|
|
|
* If a pipeline for the given shader stage objects
|
|
|
|
* already exists, it will be returned. Otherwise,
|
|
|
|
* a new pipeline will be created.
|
|
|
|
* \param [in] vs Vertex shader
|
|
|
|
* \param [in] tcs Tessellation control shader
|
|
|
|
* \param [in] tes Tessellation evaluation shader
|
|
|
|
* \param [in] gs Geometry shader
|
|
|
|
* \param [in] fs Fragment shader
|
|
|
|
* \returns Graphics pipeline object
|
|
|
|
*/
|
|
|
|
Rc<DxvkGraphicsPipeline> createGraphicsPipeline(
|
2018-01-13 22:18:32 +01:00
|
|
|
const Rc<DxvkShader>& vs,
|
|
|
|
const Rc<DxvkShader>& tcs,
|
|
|
|
const Rc<DxvkShader>& tes,
|
|
|
|
const Rc<DxvkShader>& gs,
|
|
|
|
const Rc<DxvkShader>& fs);
|
2017-12-07 09:38:31 +01:00
|
|
|
|
2018-09-21 23:23:43 +02:00
|
|
|
/*
|
|
|
|
* \brief Registers a shader
|
|
|
|
*
|
|
|
|
* Starts compiling pipelines asynchronously
|
|
|
|
* in case the state cache contains state
|
|
|
|
* vectors for this shader.
|
|
|
|
* \param [in] shader Newly compiled shader
|
|
|
|
*/
|
|
|
|
void registerShader(
|
|
|
|
const Rc<DxvkShader>& shader);
|
|
|
|
|
2018-09-21 22:28:06 +02:00
|
|
|
/**
|
|
|
|
* \brief Retrieves total pipeline count
|
|
|
|
* \returns Number of compute/graphics pipelines
|
|
|
|
*/
|
|
|
|
DxvkPipelineCount getPipelineCount() const;
|
2019-04-14 12:15:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Checks whether async compiler is busy
|
|
|
|
* \returns \c true if shaders are being compiled
|
|
|
|
*/
|
|
|
|
bool isCompilingShaders() const;
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
private:
|
|
|
|
|
2018-05-13 16:02:23 +02:00
|
|
|
const DxvkDevice* m_device;
|
|
|
|
Rc<DxvkPipelineCache> m_cache;
|
2018-09-21 23:23:43 +02:00
|
|
|
Rc<DxvkStateCache> m_stateCache;
|
2018-09-21 22:28:06 +02:00
|
|
|
|
|
|
|
std::atomic<uint32_t> m_numComputePipelines = { 0 };
|
|
|
|
std::atomic<uint32_t> m_numGraphicsPipelines = { 0 };
|
2017-12-07 09:38:31 +01:00
|
|
|
|
2018-05-01 16:45:28 +02:00
|
|
|
std::mutex m_mutex;
|
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
std::unordered_map<
|
2019-07-23 12:41:09 +02:00
|
|
|
DxvkComputePipelineShaders,
|
2017-12-07 09:38:31 +01:00
|
|
|
Rc<DxvkComputePipeline>,
|
|
|
|
DxvkPipelineKeyHash,
|
|
|
|
DxvkPipelineKeyEq> m_computePipelines;
|
|
|
|
|
|
|
|
std::unordered_map<
|
2019-07-23 12:41:09 +02:00
|
|
|
DxvkGraphicsPipelineShaders,
|
2017-12-07 09:38:31 +01:00
|
|
|
Rc<DxvkGraphicsPipeline>,
|
|
|
|
DxvkPipelineKeyHash,
|
|
|
|
DxvkPipelineKeyEq> m_graphicsPipelines;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|