2017-10-10 23:32:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
#include "dxvk_barrier.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_cmdlist.h"
|
2017-10-11 23:29:05 +02:00
|
|
|
#include "dxvk_context_state.h"
|
2017-10-15 17:56:06 +02:00
|
|
|
#include "dxvk_pipemgr.h"
|
|
|
|
#include "dxvk_util.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief DXVk context
|
|
|
|
*
|
|
|
|
* Tracks pipeline state and records command lists.
|
|
|
|
* This is where the actual rendering commands are
|
|
|
|
* recorded.
|
|
|
|
*/
|
|
|
|
class DxvkContext : public RcObject {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-10-14 23:52:47 +02:00
|
|
|
DxvkContext(
|
2017-10-15 17:56:06 +02:00
|
|
|
const Rc<DxvkDevice>& device,
|
|
|
|
const Rc<DxvkPipelineManager>& pipeMgr);
|
2017-10-10 23:32:13 +02:00
|
|
|
~DxvkContext();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Begins command buffer recording
|
|
|
|
*
|
|
|
|
* Begins recording a command list. This does
|
|
|
|
* not alter any context state other than the
|
|
|
|
* active command list.
|
2017-12-01 09:50:47 +01:00
|
|
|
* \param [in] cmdList Target command list
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
|
|
|
void beginRecording(
|
2017-12-01 09:50:47 +01:00
|
|
|
const Rc<DxvkCommandList>& cmdList);
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Ends command buffer recording
|
|
|
|
*
|
|
|
|
* Finishes recording the active command list.
|
|
|
|
* The command list can then be submitted to
|
|
|
|
* the device.
|
|
|
|
*
|
|
|
|
* This will not change any context state
|
|
|
|
* other than the active command list.
|
2017-12-01 10:08:49 +01:00
|
|
|
* \returns Active command list
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2017-12-01 10:08:49 +01:00
|
|
|
Rc<DxvkCommandList> endRecording();
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
/**
|
|
|
|
* \brief Sets framebuffer
|
|
|
|
* \param [in] fb Framebuffer
|
|
|
|
*/
|
|
|
|
void bindFramebuffer(
|
|
|
|
const Rc<DxvkFramebuffer>& fb);
|
|
|
|
|
2017-11-20 13:21:27 +01:00
|
|
|
/**
|
|
|
|
* \brief Binds index buffer
|
|
|
|
* \param [in] buffer New index buffer
|
|
|
|
*/
|
|
|
|
void bindIndexBuffer(
|
|
|
|
const DxvkBufferBinding& buffer);
|
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
/**
|
|
|
|
* \brief Sets shader for a given shader stage
|
|
|
|
*
|
|
|
|
* Binds a shader to a given stage, while unbinding the
|
|
|
|
* existing one. If \c nullptr is passed as the shader
|
|
|
|
* to bind, the given shader stage will be disabled.
|
|
|
|
* When drawing, at least a vertex shader must be bound.
|
|
|
|
* \param [in] stage The shader stage
|
|
|
|
* \param [in] shader The shader to set
|
|
|
|
*/
|
|
|
|
void bindShader(
|
|
|
|
VkShaderStageFlagBits stage,
|
|
|
|
const Rc<DxvkShader>& shader);
|
|
|
|
|
2017-11-20 13:21:27 +01:00
|
|
|
/**
|
|
|
|
* \brief Binds vertex buffer
|
|
|
|
*
|
|
|
|
* \param [in] binding Vertex buffer binding
|
|
|
|
* \param [in] buffer New vertex buffer
|
|
|
|
*/
|
|
|
|
void bindVertexBuffer(
|
|
|
|
uint32_t binding,
|
|
|
|
const DxvkBufferBinding& buffer);
|
|
|
|
|
2017-12-01 00:52:13 +01:00
|
|
|
/**
|
|
|
|
* \brief Clears subresources of an image
|
|
|
|
*
|
|
|
|
* \param [in] image The image to clear
|
|
|
|
* \param [in] value Clear value
|
|
|
|
* \param [in] subresources Subresources to clear
|
|
|
|
*/
|
|
|
|
void clearColorImage(
|
|
|
|
const Rc<DxvkImage>& image,
|
|
|
|
const VkClearColorValue& value,
|
|
|
|
const VkImageSubresourceRange& subresources);
|
|
|
|
|
2017-10-11 23:29:05 +02:00
|
|
|
/**
|
|
|
|
* \brief Clears an active render target
|
|
|
|
*
|
|
|
|
* \param [in] attachment Attachment to clear
|
|
|
|
* \param [in] clearArea Rectangular area to clear
|
|
|
|
*/
|
|
|
|
void clearRenderTarget(
|
|
|
|
const VkClearAttachment& attachment,
|
|
|
|
const VkClearRect& clearArea);
|
|
|
|
|
2017-11-26 13:24:01 +01:00
|
|
|
/**
|
|
|
|
* \brief Copies data from one buffer to another
|
|
|
|
*
|
|
|
|
* \param [in] dstBuffer Destination buffer
|
|
|
|
* \param [in] dstOffset Destination data offset
|
|
|
|
* \param [in] srcBuffer Source buffer
|
|
|
|
* \param [in] srcOffset Source data offset
|
|
|
|
* \param [in] numBytes Number of bytes to copy
|
|
|
|
*/
|
|
|
|
void copyBuffer(
|
|
|
|
const Rc<DxvkBuffer>& dstBuffer,
|
|
|
|
VkDeviceSize dstOffset,
|
|
|
|
const Rc<DxvkBuffer>& srcBuffer,
|
|
|
|
VkDeviceSize srcOffset,
|
|
|
|
VkDeviceSize numBytes);
|
|
|
|
|
2017-11-23 14:24:00 +01:00
|
|
|
/**
|
|
|
|
* \brief Starts compute jobs
|
|
|
|
*
|
|
|
|
* \param [in] x Number of threads in X direction
|
|
|
|
* \param [in] y Number of threads in Y direction
|
|
|
|
* \param [in] z Number of threads in Z direction
|
|
|
|
*/
|
|
|
|
void dispatch(
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t z);
|
|
|
|
|
2017-10-11 23:29:05 +02:00
|
|
|
/**
|
|
|
|
* \brief Draws primitive without using an index buffer
|
|
|
|
*
|
|
|
|
* \param [in] vertexCount Number of vertices to draw
|
|
|
|
* \param [in] instanceCount Number of instances to render
|
|
|
|
* \param [in] firstVertex First vertex in vertex buffer
|
|
|
|
* \param [in] firstInstance First instance ID
|
|
|
|
*/
|
|
|
|
void draw(
|
|
|
|
uint32_t vertexCount,
|
|
|
|
uint32_t instanceCount,
|
|
|
|
uint32_t firstVertex,
|
|
|
|
uint32_t firstInstance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Draws primitives using an index buffer
|
|
|
|
*
|
|
|
|
* \param [in] indexCount Number of indices to draw
|
|
|
|
* \param [in] instanceCount Number of instances to render
|
|
|
|
* \param [in] firstIndex First index within the index buffer
|
|
|
|
* \param [in] vertexOffset Vertex ID that corresponds to index 0
|
|
|
|
* \param [in] firstInstance First instance ID
|
|
|
|
*/
|
|
|
|
void drawIndexed(
|
|
|
|
uint32_t indexCount,
|
|
|
|
uint32_t instanceCount,
|
|
|
|
uint32_t firstIndex,
|
|
|
|
uint32_t vertexOffset,
|
|
|
|
uint32_t firstInstance);
|
|
|
|
|
2017-11-20 15:35:29 +01:00
|
|
|
/**
|
|
|
|
* \brief Sets viewports
|
|
|
|
*
|
|
|
|
* \param [in] viewportCount Number of viewports
|
|
|
|
* \param [in] viewports The viewports
|
|
|
|
* \param [in] scissorRects Schissor rectangles
|
|
|
|
*/
|
|
|
|
void setViewports(
|
|
|
|
uint32_t viewportCount,
|
|
|
|
const VkViewport* viewports,
|
|
|
|
const VkRect2D* scissorRects);
|
|
|
|
|
2017-11-20 13:38:24 +01:00
|
|
|
/**
|
|
|
|
* \brief Sets input assembly state
|
|
|
|
* \param [in] state New state object
|
|
|
|
*/
|
|
|
|
void setInputAssemblyState(
|
|
|
|
const Rc<DxvkInputAssemblyState>& state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sets input layout state
|
|
|
|
* \param [in] state New state object
|
|
|
|
*/
|
|
|
|
void setInputLayout(
|
|
|
|
const Rc<DxvkInputLayout>& state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sets rasterizer state
|
|
|
|
* \param [in] state New state object
|
|
|
|
*/
|
|
|
|
void setRasterizerState(
|
|
|
|
const Rc<DxvkRasterizerState>& state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sets multisample state
|
|
|
|
* \param [in] state New state object
|
|
|
|
*/
|
|
|
|
void setMultisampleState(
|
|
|
|
const Rc<DxvkMultisampleState>& state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sets depth stencil state
|
|
|
|
* \param [in] state New state object
|
|
|
|
*/
|
|
|
|
void setDepthStencilState(
|
|
|
|
const Rc<DxvkDepthStencilState>& state);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sets color blend state
|
|
|
|
* \param [in] state New state object
|
|
|
|
*/
|
|
|
|
void setBlendState(
|
|
|
|
const Rc<DxvkBlendState>& state);
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
private:
|
|
|
|
|
2017-10-15 17:56:06 +02:00
|
|
|
const Rc<DxvkDevice> m_device;
|
|
|
|
const Rc<DxvkPipelineManager> m_pipeMgr;
|
2017-10-14 23:52:47 +02:00
|
|
|
|
2017-12-01 09:50:47 +01:00
|
|
|
Rc<DxvkCommandList> m_cmd;
|
|
|
|
DxvkContextState m_state;
|
|
|
|
DxvkBarrierSet m_barriers;
|
2017-10-11 23:29:05 +02:00
|
|
|
|
2017-11-17 19:49:44 +01:00
|
|
|
void renderPassBegin();
|
|
|
|
void renderPassEnd();
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-11-23 14:24:00 +01:00
|
|
|
void bindComputePipeline();
|
2017-11-17 19:49:44 +01:00
|
|
|
void bindGraphicsPipeline();
|
2017-11-21 19:50:57 +01:00
|
|
|
|
|
|
|
void updateDynamicState();
|
|
|
|
void updateViewports();
|
|
|
|
|
|
|
|
void updateIndexBufferBinding();
|
|
|
|
void updateVertexBufferBindings();
|
2017-10-15 17:56:06 +02:00
|
|
|
|
2017-11-23 14:24:00 +01:00
|
|
|
void commitComputeState();
|
2017-11-20 14:11:09 +01:00
|
|
|
void commitGraphicsState();
|
2017-10-15 17:56:06 +02:00
|
|
|
|
2017-11-17 19:49:44 +01:00
|
|
|
DxvkShaderStageState* getShaderStage(
|
|
|
|
VkShaderStageFlagBits stage);
|
2017-10-15 17:56:06 +02:00
|
|
|
|
2017-11-26 13:24:01 +01:00
|
|
|
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|