2017-10-10 23:32:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "dxvk_adapter.h"
|
|
|
|
#include "dxvk_buffer.h"
|
2017-10-14 23:52:47 +02:00
|
|
|
#include "dxvk_compute.h"
|
2017-11-21 19:50:57 +01:00
|
|
|
#include "dxvk_constant_state.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_context.h"
|
|
|
|
#include "dxvk_framebuffer.h"
|
2017-11-29 07:55:44 +01:00
|
|
|
#include "dxvk_image.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_memory.h"
|
2017-12-07 09:38:31 +01:00
|
|
|
#include "dxvk_pipemanager.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_renderpass.h"
|
2017-12-03 20:23:26 +01:00
|
|
|
#include "dxvk_sampler.h"
|
2017-10-11 23:29:05 +02:00
|
|
|
#include "dxvk_shader.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_swapchain.h"
|
|
|
|
#include "dxvk_sync.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
class DxvkInstance;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief DXVK device
|
|
|
|
*
|
|
|
|
* Device object. This is responsible for resource creation,
|
|
|
|
* memory allocation, command submission and state tracking.
|
|
|
|
* Rendering commands are recorded into command lists using
|
|
|
|
* contexts. Multiple contexts can be created for a device.
|
|
|
|
*/
|
|
|
|
class DxvkDevice : public RcObject {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DxvkDevice(
|
2017-12-02 16:47:06 +01:00
|
|
|
const Rc<DxvkAdapter>& adapter,
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
const VkPhysicalDeviceFeatures& features);
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
~DxvkDevice();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Vulkan device functions
|
|
|
|
* \returns Vulkan device functions
|
|
|
|
*/
|
|
|
|
Rc<vk::DeviceFn> vkd() const {
|
|
|
|
return m_vkd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Logical device handle
|
|
|
|
* \returns The device handle
|
|
|
|
*/
|
|
|
|
VkDevice handle() const {
|
|
|
|
return m_vkd->device();
|
|
|
|
}
|
|
|
|
|
2017-10-11 15:32:05 +02:00
|
|
|
/**
|
|
|
|
* \brief The adapter
|
|
|
|
*
|
|
|
|
* The physical device that the
|
|
|
|
* device has been created for.
|
|
|
|
* \returns Adapter
|
|
|
|
*/
|
|
|
|
Rc<DxvkAdapter> adapter() const {
|
|
|
|
return m_adapter;
|
|
|
|
}
|
|
|
|
|
2017-12-02 16:47:06 +01:00
|
|
|
/**
|
|
|
|
* \brief Enabled device features
|
|
|
|
* \returns Enabled features
|
|
|
|
*/
|
|
|
|
const VkPhysicalDeviceFeatures& features() const {
|
|
|
|
return m_features;
|
|
|
|
}
|
|
|
|
|
2017-12-10 15:57:51 +01:00
|
|
|
/**
|
|
|
|
* \brief Allocates a staging buffer
|
|
|
|
*
|
|
|
|
* Returns a staging buffer that is at least as large
|
|
|
|
* as the requested size. It is usually bigger so that
|
|
|
|
* a single staging buffer may serve multiple allocations.
|
|
|
|
* \param [in] size Minimum buffer size
|
|
|
|
* \returns The staging buffer
|
|
|
|
*/
|
|
|
|
Rc<DxvkStagingBuffer> allocStagingBuffer(
|
|
|
|
VkDeviceSize size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Recycles a staging buffer
|
|
|
|
*
|
|
|
|
* When a staging buffer is no longer needed, it should
|
|
|
|
* be returned to the device so that it can be reused
|
|
|
|
* for subsequent allocations.
|
|
|
|
* \param [in] buffer The buffer
|
|
|
|
*/
|
|
|
|
void recycleStagingBuffer(
|
|
|
|
const Rc<DxvkStagingBuffer>& buffer);
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
|
|
|
* \brief Creates a command list
|
|
|
|
* \returns The command list
|
|
|
|
*/
|
|
|
|
Rc<DxvkCommandList> createCommandList();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Creates a context
|
|
|
|
*
|
|
|
|
* Creates a context object that can
|
|
|
|
* be used to record command buffers.
|
|
|
|
* \returns The context object
|
|
|
|
*/
|
|
|
|
Rc<DxvkContext> createContext();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Creates framebuffer for a set of render targets
|
|
|
|
*
|
|
|
|
* Automatically deduces framebuffer dimensions
|
|
|
|
* from the supplied render target views.
|
|
|
|
* \param [in] renderTargets Render targets
|
|
|
|
* \returns The framebuffer object
|
|
|
|
*/
|
|
|
|
Rc<DxvkFramebuffer> createFramebuffer(
|
|
|
|
const DxvkRenderTargets& renderTargets);
|
|
|
|
|
2017-10-15 14:36:41 +02:00
|
|
|
/**
|
|
|
|
* \brief Creates a buffer object
|
|
|
|
*
|
|
|
|
* \param [in] createInfo Buffer create info
|
|
|
|
* \param [in] memoryType Memory type flags
|
|
|
|
* \returns The buffer object
|
|
|
|
*/
|
|
|
|
Rc<DxvkBuffer> createBuffer(
|
|
|
|
const DxvkBufferCreateInfo& createInfo,
|
|
|
|
VkMemoryPropertyFlags memoryType);
|
|
|
|
|
2017-11-21 19:50:57 +01:00
|
|
|
/**
|
|
|
|
* \brief Creates a buffer view
|
|
|
|
*
|
|
|
|
* \param [in] buffer The buffer to view
|
|
|
|
* \param [in] createInfo Buffer view properties
|
|
|
|
* \returns The buffer view object
|
|
|
|
*/
|
|
|
|
Rc<DxvkBufferView> createBufferView(
|
|
|
|
const Rc<DxvkBuffer>& buffer,
|
|
|
|
const DxvkBufferViewCreateInfo& createInfo);
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
|
|
|
* \brief Creates an image object
|
|
|
|
*
|
|
|
|
* \param [in] createInfo Image create info
|
|
|
|
* \param [in] memoryType Memory type flags
|
|
|
|
* \returns The image object
|
|
|
|
*/
|
|
|
|
Rc<DxvkImage> createImage(
|
|
|
|
const DxvkImageCreateInfo& createInfo,
|
|
|
|
VkMemoryPropertyFlags memoryType);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Creates an image view
|
|
|
|
*
|
|
|
|
* \param [in] image The image to create a view for
|
|
|
|
* \param [in] createInfo Image view create info
|
|
|
|
* \returns The image view
|
|
|
|
*/
|
|
|
|
Rc<DxvkImageView> createImageView(
|
|
|
|
const Rc<DxvkImage>& image,
|
|
|
|
const DxvkImageViewCreateInfo& createInfo);
|
|
|
|
|
2017-12-03 20:23:26 +01:00
|
|
|
/**
|
|
|
|
* \brief Creates a sampler object
|
|
|
|
*
|
|
|
|
* \param [in] createInfo Sampler parameters
|
|
|
|
* \returns Newly created sampler object
|
|
|
|
*/
|
|
|
|
Rc<DxvkSampler> createSampler(
|
|
|
|
const DxvkSamplerCreateInfo& createInfo);
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
|
|
|
* \brief Creates a semaphore object
|
|
|
|
* \returns Newly created semaphore
|
|
|
|
*/
|
|
|
|
Rc<DxvkSemaphore> createSemaphore();
|
|
|
|
|
2017-11-20 15:35:29 +01:00
|
|
|
/**
|
|
|
|
* \brief Creates a shader module
|
|
|
|
*
|
|
|
|
* \param [in] stage Shader stage
|
|
|
|
* \param [in] code Shader code
|
|
|
|
* \returns New shader module
|
|
|
|
*/
|
|
|
|
Rc<DxvkShader> createShader(
|
|
|
|
VkShaderStageFlagBits stage,
|
2017-12-07 09:38:31 +01:00
|
|
|
uint32_t slotCount,
|
|
|
|
const DxvkResourceSlot* slotInfos,
|
2017-11-20 15:35:29 +01:00
|
|
|
const SpirvCodeBuffer& code);
|
|
|
|
|
2017-12-03 00:40:58 +01:00
|
|
|
/**
|
2017-12-07 09:38:31 +01:00
|
|
|
* \brief Retrieves a compute pipeline
|
2017-12-03 00:40:58 +01:00
|
|
|
*
|
|
|
|
* \param [in] layout Pipeline binding layout
|
|
|
|
* \param [in] cs Compute shader
|
2017-12-07 09:38:31 +01:00
|
|
|
* \returns The compute pipeline
|
2017-12-03 00:40:58 +01:00
|
|
|
*/
|
|
|
|
Rc<DxvkComputePipeline> createComputePipeline(
|
2017-12-07 09:38:31 +01:00
|
|
|
const Rc<DxvkShader>& cs);
|
2017-12-03 00:40:58 +01:00
|
|
|
|
|
|
|
/**
|
2017-12-07 09:38:31 +01:00
|
|
|
* \brief Retrieves a graphics pipeline object
|
2017-12-03 00:40:58 +01:00
|
|
|
*
|
|
|
|
* \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
|
2017-12-07 09:38:31 +01:00
|
|
|
* \returns The graphics pipeline
|
2017-12-03 00:40:58 +01:00
|
|
|
*/
|
|
|
|
Rc<DxvkGraphicsPipeline> createGraphicsPipeline(
|
2017-12-07 09:38:31 +01:00
|
|
|
const Rc<DxvkShader>& vs,
|
|
|
|
const Rc<DxvkShader>& tcs,
|
|
|
|
const Rc<DxvkShader>& tes,
|
|
|
|
const Rc<DxvkShader>& gs,
|
|
|
|
const Rc<DxvkShader>& fs);
|
2017-12-03 00:40:58 +01:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
|
|
|
* \brief Creates a swap chain
|
|
|
|
*
|
|
|
|
* \param [in] surface The target surface
|
|
|
|
* \param [in] properties Swapchain properties
|
|
|
|
* \returns The swapchain object
|
|
|
|
*/
|
|
|
|
Rc<DxvkSwapchain> createSwapchain(
|
|
|
|
const Rc<DxvkSurface>& surface,
|
|
|
|
const DxvkSwapchainProperties& properties);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Submits a command list
|
|
|
|
*
|
|
|
|
* Synchronization arguments are optional.
|
|
|
|
* \param [in] commandList The command list to submit
|
|
|
|
* \param [in] waitSync (Optional) Semaphore to wait on
|
|
|
|
* \param [in] wakeSync (Optional) Semaphore to notify
|
|
|
|
* \returns Synchronization fence
|
|
|
|
*/
|
|
|
|
Rc<DxvkFence> submitCommandList(
|
|
|
|
const Rc<DxvkCommandList>& commandList,
|
|
|
|
const Rc<DxvkSemaphore>& waitSync,
|
|
|
|
const Rc<DxvkSemaphore>& wakeSync);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Waits until the device becomes idle
|
|
|
|
*
|
|
|
|
* Waits for the GPU to complete the execution of all
|
|
|
|
* previously submitted command buffers. This may be
|
|
|
|
* used to ensure that resources that were previously
|
|
|
|
* used by the GPU can be safely destroyed.
|
|
|
|
*/
|
|
|
|
void waitForIdle() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-12-02 16:47:06 +01:00
|
|
|
Rc<DxvkAdapter> m_adapter;
|
|
|
|
Rc<vk::DeviceFn> m_vkd;
|
|
|
|
VkPhysicalDeviceFeatures m_features;
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
Rc<DxvkMemoryAllocator> m_memory;
|
|
|
|
Rc<DxvkRenderPassPool> m_renderPassPool;
|
2017-12-07 09:38:31 +01:00
|
|
|
Rc<DxvkPipelineManager> m_pipelineManager;
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
VkQueue m_graphicsQueue;
|
|
|
|
VkQueue m_presentQueue;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|