2017-10-14 23:52:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-05-01 16:45:28 +02:00
|
|
|
#include <mutex>
|
2017-10-14 23:52:47 +02:00
|
|
|
|
2018-01-10 11:44:40 +01:00
|
|
|
#include "dxvk_binding.h"
|
2017-11-20 13:21:27 +01:00
|
|
|
#include "dxvk_constant_state.h"
|
2018-01-13 22:18:32 +01:00
|
|
|
#include "dxvk_pipecache.h"
|
2018-05-10 14:54:44 +02:00
|
|
|
#include "dxvk_pipecompiler.h"
|
2017-12-07 09:38:31 +01:00
|
|
|
#include "dxvk_pipelayout.h"
|
2018-05-03 19:33:41 +02:00
|
|
|
#include "dxvk_renderpass.h"
|
2017-10-14 23:52:47 +02:00
|
|
|
#include "dxvk_resource.h"
|
2017-12-03 00:40:58 +01:00
|
|
|
#include "dxvk_shader.h"
|
2018-04-03 15:52:39 +02:00
|
|
|
#include "dxvk_stats.h"
|
2017-10-14 23:52:47 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-01-16 15:00:19 +01:00
|
|
|
class DxvkDevice;
|
|
|
|
|
2017-11-17 19:49:44 +01:00
|
|
|
/**
|
|
|
|
* \brief Graphics pipeline state info
|
|
|
|
*
|
2017-11-20 13:21:27 +01:00
|
|
|
* Stores all information that is required to create
|
|
|
|
* a graphics pipeline, except the shader objects
|
|
|
|
* themselves. Also used to identify pipelines using
|
|
|
|
* the current pipeline state vector.
|
2017-11-17 19:49:44 +01:00
|
|
|
*/
|
2017-10-15 17:56:06 +02:00
|
|
|
struct DxvkGraphicsPipelineStateInfo {
|
2017-12-07 21:47:38 +01:00
|
|
|
DxvkGraphicsPipelineStateInfo();
|
|
|
|
DxvkGraphicsPipelineStateInfo(
|
|
|
|
const DxvkGraphicsPipelineStateInfo& other);
|
2017-11-20 13:21:27 +01:00
|
|
|
|
2017-12-07 21:47:38 +01:00
|
|
|
DxvkGraphicsPipelineStateInfo& operator = (
|
|
|
|
const DxvkGraphicsPipelineStateInfo& other);
|
2017-10-15 13:02:59 +02:00
|
|
|
|
2018-01-10 21:28:20 +01:00
|
|
|
bool operator == (const DxvkGraphicsPipelineStateInfo& other) const;
|
|
|
|
bool operator != (const DxvkGraphicsPipelineStateInfo& other) const;
|
|
|
|
|
2018-01-10 11:44:40 +01:00
|
|
|
DxvkBindingState bsBindingState;
|
|
|
|
|
2017-12-07 21:47:38 +01:00
|
|
|
VkPrimitiveTopology iaPrimitiveTopology;
|
|
|
|
VkBool32 iaPrimitiveRestart;
|
2018-01-29 11:31:00 +01:00
|
|
|
uint32_t iaPatchVertexCount;
|
2017-10-15 13:02:59 +02:00
|
|
|
|
2017-12-07 21:47:38 +01:00
|
|
|
uint32_t ilAttributeCount;
|
|
|
|
uint32_t ilBindingCount;
|
|
|
|
VkVertexInputAttributeDescription ilAttributes[DxvkLimits::MaxNumVertexAttributes];
|
|
|
|
VkVertexInputBindingDescription ilBindings[DxvkLimits::MaxNumVertexBindings];
|
2018-04-17 17:24:16 +02:00
|
|
|
uint32_t ilDivisors[DxvkLimits::MaxNumVertexBindings];
|
2017-12-07 21:47:38 +01:00
|
|
|
|
|
|
|
VkBool32 rsEnableDepthClamp;
|
|
|
|
VkBool32 rsEnableDiscard;
|
|
|
|
VkPolygonMode rsPolygonMode;
|
|
|
|
VkCullModeFlags rsCullMode;
|
|
|
|
VkFrontFace rsFrontFace;
|
|
|
|
VkBool32 rsDepthBiasEnable;
|
|
|
|
uint32_t rsViewportCount;
|
|
|
|
|
|
|
|
VkSampleCountFlagBits msSampleCount;
|
|
|
|
uint32_t msSampleMask;
|
|
|
|
VkBool32 msEnableAlphaToCoverage;
|
|
|
|
VkBool32 msEnableAlphaToOne;
|
|
|
|
|
|
|
|
VkBool32 dsEnableDepthTest;
|
|
|
|
VkBool32 dsEnableDepthWrite;
|
|
|
|
VkBool32 dsEnableStencilTest;
|
|
|
|
VkCompareOp dsDepthCompareOp;
|
|
|
|
VkStencilOpState dsStencilOpFront;
|
|
|
|
VkStencilOpState dsStencilOpBack;
|
|
|
|
|
|
|
|
VkBool32 omEnableLogicOp;
|
|
|
|
VkLogicOp omLogicOp;
|
2018-01-16 15:00:19 +01:00
|
|
|
VkPipelineColorBlendAttachmentState omBlendAttachments[MaxNumRenderTargets];
|
2017-12-07 21:47:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-08 21:49:30 +02:00
|
|
|
/**
|
|
|
|
* \brief Common graphics pipeline state
|
|
|
|
*
|
|
|
|
* Non-dynamic pipeline state that cannot
|
|
|
|
* be changed dynamically.
|
|
|
|
*/
|
|
|
|
struct DxvkGraphicsCommonPipelineStateInfo {
|
|
|
|
bool msSampleShadingEnable;
|
|
|
|
float msSampleShadingFactor;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-09 22:23:50 +02:00
|
|
|
/**
|
|
|
|
* \brief Graphics pipeline instance
|
|
|
|
*
|
|
|
|
* Stores a state vector and the corresponding
|
2018-05-10 14:15:47 +02:00
|
|
|
* unoptimized and optimized pipeline handles.
|
2018-05-09 22:23:50 +02:00
|
|
|
*/
|
|
|
|
class DxvkGraphicsPipelineInstance : public RcObject {
|
2018-05-10 14:15:47 +02:00
|
|
|
friend class DxvkGraphicsPipeline;
|
2018-05-09 22:23:50 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkGraphicsPipelineInstance(
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
const DxvkGraphicsPipelineStateInfo& stateVector,
|
2018-05-10 14:15:47 +02:00
|
|
|
VkRenderPass renderPass,
|
|
|
|
VkPipeline basePipeline);
|
2018-05-09 22:23:50 +02:00
|
|
|
|
|
|
|
~DxvkGraphicsPipelineInstance();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Checks for matching pipeline state
|
|
|
|
*
|
|
|
|
* \param [in] stateVector Graphics pipeline state
|
|
|
|
* \param [in] renderPass Render pass handle
|
|
|
|
* \returns \c true if the specialization is compatible
|
|
|
|
*/
|
|
|
|
bool isCompatible(
|
|
|
|
const DxvkGraphicsPipelineStateInfo& stateVector,
|
|
|
|
VkRenderPass renderPass) const {
|
|
|
|
return m_renderPass == renderPass
|
|
|
|
&& m_stateVector == stateVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-10 14:15:47 +02:00
|
|
|
* \brief Sets the optimized pipeline handle
|
|
|
|
*
|
|
|
|
* If an optimized pipeline handle has already been
|
|
|
|
* set up, this method will fail and the new pipeline
|
|
|
|
* handle should be destroyed.
|
|
|
|
* \param [in] pipeline The optimized pipeline
|
2018-05-09 22:23:50 +02:00
|
|
|
*/
|
2018-05-10 14:15:47 +02:00
|
|
|
bool setFastPipeline(VkPipeline pipeline) {
|
|
|
|
VkPipeline expected = VK_NULL_HANDLE;
|
|
|
|
return m_fastPipeline.compare_exchange_strong(expected, pipeline);
|
2018-05-09 22:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Retrieves pipeline
|
2018-05-10 14:15:47 +02:00
|
|
|
*
|
|
|
|
* Returns the optimized version of the pipeline if
|
|
|
|
* if has been set, or the base pipeline if not.
|
|
|
|
* \returns The pipeline handle
|
2018-05-09 22:23:50 +02:00
|
|
|
*/
|
|
|
|
VkPipeline getPipeline() const {
|
2018-05-10 14:15:47 +02:00
|
|
|
VkPipeline basePipeline = m_basePipeline.load();
|
|
|
|
VkPipeline fastPipeline = m_fastPipeline.load();
|
|
|
|
|
|
|
|
return fastPipeline != VK_NULL_HANDLE
|
|
|
|
? fastPipeline : basePipeline;
|
2018-05-09 22:23:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
const Rc<vk::DeviceFn> m_vkd;
|
|
|
|
|
|
|
|
DxvkGraphicsPipelineStateInfo m_stateVector;
|
|
|
|
VkRenderPass m_renderPass;
|
|
|
|
|
2018-05-10 14:15:47 +02:00
|
|
|
std::atomic<VkPipeline> m_basePipeline;
|
|
|
|
std::atomic<VkPipeline> m_fastPipeline;
|
2018-05-09 22:23:50 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-14 23:52:47 +02:00
|
|
|
/**
|
|
|
|
* \brief Graphics pipeline
|
|
|
|
*
|
|
|
|
* Stores the pipeline layout as well as methods to
|
|
|
|
* recompile the graphics pipeline against a given
|
|
|
|
* pipeline state vector.
|
|
|
|
*/
|
|
|
|
class DxvkGraphicsPipeline : public DxvkResource {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkGraphicsPipeline(
|
2018-05-10 14:54:44 +02:00
|
|
|
const DxvkDevice* device,
|
|
|
|
const Rc<DxvkPipelineCache>& cache,
|
|
|
|
const Rc<DxvkPipelineCompiler>& compiler,
|
|
|
|
const Rc<DxvkShader>& vs,
|
|
|
|
const Rc<DxvkShader>& tcs,
|
|
|
|
const Rc<DxvkShader>& tes,
|
|
|
|
const Rc<DxvkShader>& gs,
|
|
|
|
const Rc<DxvkShader>& fs);
|
2017-10-14 23:52:47 +02:00
|
|
|
~DxvkGraphicsPipeline();
|
|
|
|
|
2017-11-20 14:11:09 +01:00
|
|
|
/**
|
2017-12-03 00:40:58 +01:00
|
|
|
* \brief Pipeline layout
|
2017-11-20 14:11:09 +01:00
|
|
|
*
|
2017-12-03 20:23:26 +01:00
|
|
|
* Stores the pipeline layout and the descriptor set
|
|
|
|
* layout, as well as information on the resource
|
|
|
|
* slots used by the pipeline.
|
|
|
|
* \returns Pipeline layout
|
2017-11-20 14:11:09 +01:00
|
|
|
*/
|
2018-01-23 17:40:36 +01:00
|
|
|
Rc<DxvkPipelineLayout> layout() const {
|
2017-12-03 20:23:26 +01:00
|
|
|
return m_layout;
|
2017-11-20 14:11:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Pipeline handle
|
2018-01-13 22:18:32 +01:00
|
|
|
*
|
|
|
|
* Retrieves a pipeline handle for the given pipeline
|
|
|
|
* state. If necessary, a new pipeline will be created.
|
|
|
|
* \param [in] state Pipeline state vector
|
2018-05-03 19:33:41 +02:00
|
|
|
* \param [in] renderPass The render pass
|
2018-04-03 15:52:39 +02:00
|
|
|
* \param [in,out] stats Stat counter
|
2017-11-20 14:11:09 +01:00
|
|
|
* \returns Pipeline handle
|
|
|
|
*/
|
2017-10-15 13:02:59 +02:00
|
|
|
VkPipeline getPipelineHandle(
|
2018-05-10 14:15:47 +02:00
|
|
|
const DxvkGraphicsPipelineStateInfo& state,
|
|
|
|
const DxvkRenderPass& renderPass,
|
|
|
|
DxvkStatCounters& stats);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Compiles optimized pipeline
|
|
|
|
*
|
|
|
|
* Compiles an optimized version of a pipeline
|
|
|
|
* and makes it available to the system.
|
|
|
|
* \param [in] instance The pipeline instance
|
|
|
|
*/
|
2018-05-10 14:54:44 +02:00
|
|
|
void compileInstance(
|
2018-05-10 14:15:47 +02:00
|
|
|
const Rc<DxvkGraphicsPipelineInstance>& instance);
|
2017-10-15 13:02:59 +02:00
|
|
|
|
2017-10-14 23:52:47 +02:00
|
|
|
private:
|
|
|
|
|
2018-01-10 21:28:20 +01:00
|
|
|
struct PipelineStruct {
|
|
|
|
DxvkGraphicsPipelineStateInfo stateVector;
|
2018-05-03 19:33:41 +02:00
|
|
|
VkRenderPass renderPass;
|
2018-01-10 21:28:20 +01:00
|
|
|
VkPipeline pipeline;
|
|
|
|
};
|
|
|
|
|
2018-01-16 15:00:19 +01:00
|
|
|
const DxvkDevice* const m_device;
|
|
|
|
const Rc<vk::DeviceFn> m_vkd;
|
|
|
|
|
2018-05-10 14:54:44 +02:00
|
|
|
Rc<DxvkPipelineCache> m_cache;
|
|
|
|
Rc<DxvkPipelineCompiler> m_compiler;
|
|
|
|
Rc<DxvkPipelineLayout> m_layout;
|
2017-10-15 13:02:59 +02:00
|
|
|
|
2017-12-07 09:38:31 +01:00
|
|
|
Rc<DxvkShaderModule> m_vs;
|
|
|
|
Rc<DxvkShaderModule> m_tcs;
|
|
|
|
Rc<DxvkShaderModule> m_tes;
|
|
|
|
Rc<DxvkShaderModule> m_gs;
|
|
|
|
Rc<DxvkShaderModule> m_fs;
|
2017-10-15 13:02:59 +02:00
|
|
|
|
2018-01-12 14:25:26 +01:00
|
|
|
uint32_t m_vsIn = 0;
|
|
|
|
uint32_t m_fsOut = 0;
|
|
|
|
|
2018-04-08 21:49:30 +02:00
|
|
|
DxvkGraphicsCommonPipelineStateInfo m_common;
|
|
|
|
|
2018-05-13 15:36:44 +02:00
|
|
|
// List of pipeline instances, shared between threads
|
|
|
|
alignas(CACHE_LINE_SIZE) sync::Spinlock m_mutex;
|
2018-05-09 22:23:50 +02:00
|
|
|
std::vector<Rc<DxvkGraphicsPipelineInstance>> m_pipelines;
|
2017-10-15 13:02:59 +02:00
|
|
|
|
2018-05-13 15:36:44 +02:00
|
|
|
// Pipeline handles used for derivative pipelines
|
|
|
|
std::atomic<VkPipeline> m_basePipelineBase = { VK_NULL_HANDLE };
|
|
|
|
std::atomic<VkPipeline> m_fastPipelineBase = { VK_NULL_HANDLE };
|
|
|
|
|
2018-05-09 22:23:50 +02:00
|
|
|
DxvkGraphicsPipelineInstance* findInstance(
|
2018-05-01 16:45:28 +02:00
|
|
|
const DxvkGraphicsPipelineStateInfo& state,
|
2018-05-09 22:23:50 +02:00
|
|
|
VkRenderPass renderPass) const;
|
2018-05-01 16:45:28 +02:00
|
|
|
|
2018-01-10 22:54:00 +01:00
|
|
|
VkPipeline compilePipeline(
|
|
|
|
const DxvkGraphicsPipelineStateInfo& state,
|
2018-05-03 19:33:41 +02:00
|
|
|
VkRenderPass renderPass,
|
2018-05-10 14:54:44 +02:00
|
|
|
VkPipelineCreateFlags createFlags,
|
2018-01-10 22:54:00 +01:00
|
|
|
VkPipeline baseHandle) const;
|
2018-01-12 14:25:26 +01:00
|
|
|
|
|
|
|
bool validatePipelineState(
|
|
|
|
const DxvkGraphicsPipelineStateInfo& state) const;
|
|
|
|
|
2018-02-07 16:44:30 +01:00
|
|
|
void logPipelineState(
|
2018-04-02 19:05:41 +02:00
|
|
|
LogLevel level,
|
2018-02-07 16:44:30 +01:00
|
|
|
const DxvkGraphicsPipelineStateInfo& state) const;
|
|
|
|
|
2017-10-14 23:52:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|