1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/dxvk/dxvk_compute.h

168 lines
4.0 KiB
C
Raw Normal View History

#pragma once
#include <atomic>
#include <vector>
#include "dxvk_bind_mask.h"
#include "dxvk_pipecache.h"
#include "dxvk_pipelayout.h"
2017-10-14 23:52:47 +02:00
#include "dxvk_resource.h"
#include "dxvk_shader.h"
#include "dxvk_stats.h"
namespace dxvk {
class DxvkDevice;
class DxvkPipelineManager;
/**
* \brief Shaders used in compute pipelines
*/
struct DxvkComputePipelineShaders {
Rc<DxvkShader> cs;
};
/**
* \brief Compute pipeline state info
*/
struct DxvkComputePipelineStateInfo {
DxvkComputePipelineStateInfo();
DxvkComputePipelineStateInfo(
const DxvkComputePipelineStateInfo& other);
DxvkComputePipelineStateInfo& operator = (
const DxvkComputePipelineStateInfo& other);
bool operator == (const DxvkComputePipelineStateInfo& other) const;
bool operator != (const DxvkComputePipelineStateInfo& other) const;
DxvkBindingMask bsBindingMask;
uint32_t scSpecConstants[MaxNumSpecConstants];
};
/**
* \brief Compute pipeline instance
*/
class DxvkComputePipelineInstance {
public:
DxvkComputePipelineInstance()
: m_stateVector (),
m_pipeline (VK_NULL_HANDLE) { }
DxvkComputePipelineInstance(
const DxvkComputePipelineStateInfo& state,
VkPipeline pipe)
: m_stateVector (state),
m_pipeline (pipe) { }
/**
* \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 DxvkComputePipelineStateInfo& state) const {
return m_stateVector == state;
}
/**
* \brief Retrieves pipeline
* \returns The pipeline handle
*/
VkPipeline pipeline() const {
return m_pipeline;
}
private:
DxvkComputePipelineStateInfo m_stateVector;
VkPipeline m_pipeline;
};
/**
* \brief Compute pipeline
*
2017-10-14 13:45:00 +02:00
* Stores a compute pipeline object and the corresponding
* pipeline layout. Unlike graphics pipelines, compute
* pipelines do not need to be recompiled against any sort
* of pipeline state.
*/
class DxvkComputePipeline {
public:
2017-10-14 23:52:47 +02:00
DxvkComputePipeline(
DxvkPipelineManager* pipeMgr,
DxvkComputePipelineShaders shaders);
~DxvkComputePipeline();
2017-10-14 23:52:47 +02:00
/**
* \brief Pipeline layout
2017-10-14 23:52:47 +02: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-10-14 23:52:47 +02:00
*/
DxvkPipelineLayout* layout() const {
return m_layout.ptr();
}
/**
* \brief Retrieves pipeline handle
*
* \param [in] state Pipeline state
* \returns Pipeline handle
*/
VkPipeline getPipelineHandle(
const DxvkComputePipelineStateInfo& state);
/**
* \brief Compiles a pipeline
*
* Asynchronously compiles the given pipeline
* and stores the result for future use.
* \param [in] state Pipeline state
*/
void compilePipeline(
const DxvkComputePipelineStateInfo& state);
private:
Rc<vk::DeviceFn> m_vkd;
DxvkPipelineManager* m_pipeMgr;
DxvkComputePipelineShaders m_shaders;
DxvkDescriptorSlotMapping m_slotMapping;
Rc<DxvkPipelineLayout> m_layout;
2017-10-14 23:52:47 +02:00
sync::Spinlock m_mutex;
std::vector<DxvkComputePipelineInstance> m_pipelines;
DxvkComputePipelineInstance* createInstance(
const DxvkComputePipelineStateInfo& state);
DxvkComputePipelineInstance* findInstance(
const DxvkComputePipelineStateInfo& state);
VkPipeline createPipeline(
const DxvkComputePipelineStateInfo& state) const;
void destroyPipeline(
VkPipeline pipeline);
void writePipelineStateToCache(
const DxvkComputePipelineStateInfo& state) const;
};
}