2017-11-29 20:19:40 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2017-12-06 14:16:14 +01:00
|
|
|
#include "d3d11_buffer.h"
|
2017-12-07 12:45:02 +01:00
|
|
|
#include "d3d11_input_layout.h"
|
2018-03-09 16:47:20 +01:00
|
|
|
#include "d3d11_query.h"
|
2017-12-09 21:17:26 +01:00
|
|
|
#include "d3d11_sampler.h"
|
2020-07-18 00:10:31 +02:00
|
|
|
#include "d3d11_shader.h"
|
2017-12-06 12:11:59 +01:00
|
|
|
#include "d3d11_state.h"
|
2018-02-05 22:35:23 +01:00
|
|
|
#include "d3d11_view_dsv.h"
|
|
|
|
#include "d3d11_view_rtv.h"
|
|
|
|
#include "d3d11_view_srv.h"
|
|
|
|
#include "d3d11_view_uav.h"
|
2017-11-29 20:19:40 +01:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2022-08-04 15:47:24 +02:00
|
|
|
/**
|
|
|
|
* \brief Per-stage state
|
|
|
|
*
|
|
|
|
* Stores an object of the given type for each shader stage.
|
|
|
|
* \tparam Object type
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class D3D11ShaderStageState {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
T& operator [] (DxbcProgramType type) { return m_state[uint32_t(type)]; }
|
|
|
|
const T& operator [] (DxbcProgramType type) const { return m_state[uint32_t(type)]; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Calls reset method on all objects
|
|
|
|
*/
|
|
|
|
void reset() {
|
|
|
|
for (auto& state : m_state)
|
|
|
|
state.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::array<T, 6> m_state = { };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Constant buffer bindings
|
|
|
|
*
|
|
|
|
* Stores the bound buffer range from a runtime point of view,
|
|
|
|
* as well as the range that is actually bound to the context.
|
|
|
|
*/
|
2018-03-18 12:36:45 +01:00
|
|
|
struct D3D11ConstantBufferBinding {
|
2022-09-16 06:44:02 +00:00
|
|
|
Com<D3D11Buffer, false> buffer = nullptr;
|
2018-03-18 12:36:45 +01:00
|
|
|
UINT constantOffset = 0;
|
|
|
|
UINT constantCount = 0;
|
2019-03-28 13:45:41 +01:00
|
|
|
UINT constantBound = 0;
|
2018-03-18 12:36:45 +01:00
|
|
|
};
|
|
|
|
|
2022-08-04 15:47:24 +02:00
|
|
|
struct D3D11ShaderStageCbvBinding {
|
|
|
|
std::array<D3D11ConstantBufferBinding, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT> buffers = { };
|
|
|
|
|
2022-08-04 17:37:10 +02:00
|
|
|
uint32_t maxCount = 0;
|
|
|
|
|
2022-08-04 15:47:24 +02:00
|
|
|
void reset() {
|
2022-08-04 17:37:10 +02:00
|
|
|
for (uint32_t i = 0; i < maxCount; i++)
|
2022-08-04 15:47:24 +02:00
|
|
|
buffers[i] = D3D11ConstantBufferBinding();
|
2022-08-04 17:37:10 +02:00
|
|
|
|
|
|
|
maxCount = 0;
|
2022-08-04 15:47:24 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using D3D11CbvBindings = D3D11ShaderStageState<D3D11ShaderStageCbvBinding>;
|
2017-12-10 01:56:07 +01:00
|
|
|
|
2022-08-04 15:56:49 +02:00
|
|
|
/**
|
|
|
|
* \brief Shader resource bindings
|
|
|
|
*
|
|
|
|
* Stores bound shader resource views, as well as a bit
|
|
|
|
* set of views that are potentially hazardous.
|
|
|
|
*/
|
|
|
|
struct D3D11ShaderStageSrvBinding {
|
2022-09-16 06:50:43 +00:00
|
|
|
std::array<Com<D3D11ShaderResourceView, false>, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> views = { };
|
2020-03-16 18:39:46 +01:00
|
|
|
DxvkBindingSet<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> hazardous = { };
|
2022-08-04 15:56:49 +02:00
|
|
|
|
2022-08-04 17:54:51 +02:00
|
|
|
uint32_t maxCount = 0;
|
|
|
|
|
2022-08-04 15:56:49 +02:00
|
|
|
void reset() {
|
2022-08-04 17:54:51 +02:00
|
|
|
for (uint32_t i = 0; i < maxCount; i++)
|
2022-08-04 15:56:49 +02:00
|
|
|
views[i] = nullptr;
|
|
|
|
|
|
|
|
hazardous.clear();
|
2022-08-04 17:54:51 +02:00
|
|
|
maxCount = 0;
|
2022-08-04 15:56:49 +02:00
|
|
|
}
|
2019-08-26 18:53:23 +02:00
|
|
|
};
|
2017-12-10 01:56:07 +01:00
|
|
|
|
2022-08-04 15:56:49 +02:00
|
|
|
using D3D11SrvBindings = D3D11ShaderStageState<D3D11ShaderStageSrvBinding>;
|
2022-08-04 16:05:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Sampler bindings
|
|
|
|
*
|
|
|
|
* Stores bound samplers.
|
|
|
|
*/
|
|
|
|
struct D3D11ShaderStageSamplerBinding {
|
|
|
|
std::array<D3D11SamplerState*, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT> samplers = { };
|
|
|
|
|
2022-08-04 18:04:17 +02:00
|
|
|
uint32_t maxCount = 0;
|
|
|
|
|
2022-08-04 16:05:21 +02:00
|
|
|
void reset() {
|
2022-08-04 18:04:17 +02:00
|
|
|
for (uint32_t i = 0; i < maxCount; i++)
|
2022-08-04 16:05:21 +02:00
|
|
|
samplers[i] = nullptr;
|
2022-08-04 18:04:17 +02:00
|
|
|
|
|
|
|
maxCount = 0;
|
2022-08-04 16:05:21 +02:00
|
|
|
}
|
|
|
|
};
|
2017-12-27 01:36:45 +01:00
|
|
|
|
2022-08-04 16:05:21 +02:00
|
|
|
using D3D11SamplerBindings = D3D11ShaderStageState<D3D11ShaderStageSamplerBinding>;
|
2022-08-04 16:23:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief UAV bindings
|
|
|
|
*
|
|
|
|
* Stores bound UAVs. For compute shader UAVs,
|
|
|
|
* we also store a bit mask of bound UAVs.
|
|
|
|
*/
|
2022-09-16 06:50:43 +00:00
|
|
|
using D3D11ShaderStageUavBinding = std::array<Com<D3D11UnorderedAccessView, false>, D3D11_1_UAV_SLOT_COUNT>;
|
2022-08-04 15:56:49 +02:00
|
|
|
|
2022-08-04 16:23:47 +02:00
|
|
|
struct D3D11UavBindings {
|
|
|
|
D3D11ShaderStageUavBinding views = { };
|
|
|
|
DxvkBindingSet<D3D11_1_UAV_SLOT_COUNT> mask = { };
|
|
|
|
|
2022-08-04 18:17:23 +02:00
|
|
|
uint32_t maxCount = 0;
|
|
|
|
|
2022-08-04 16:23:47 +02:00
|
|
|
void reset() {
|
2022-08-04 18:17:23 +02:00
|
|
|
for (uint32_t i = 0; i < maxCount; i++)
|
2022-08-04 16:23:47 +02:00
|
|
|
views[i] = nullptr;
|
|
|
|
|
|
|
|
mask.clear();
|
2022-08-04 18:17:23 +02:00
|
|
|
maxCount = 0;
|
2022-08-04 16:23:47 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-04 16:34:49 +02:00
|
|
|
/**
|
|
|
|
* \brief Input assembly state
|
|
|
|
*
|
|
|
|
* Stores vertex buffers, the index buffer, the
|
|
|
|
* input layout, and the dynamic primitive topology.
|
|
|
|
*/
|
2017-12-07 14:03:15 +01:00
|
|
|
struct D3D11VertexBufferBinding {
|
2022-09-16 06:51:51 +00:00
|
|
|
Com<D3D11Buffer, false> buffer = nullptr;
|
|
|
|
UINT offset = 0;
|
|
|
|
UINT stride = 0;
|
2017-12-07 14:03:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct D3D11IndexBufferBinding {
|
2022-09-16 06:51:51 +00:00
|
|
|
Com<D3D11Buffer, false> buffer = nullptr;
|
|
|
|
UINT offset = 0;
|
|
|
|
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
|
2017-12-07 14:03:15 +01:00
|
|
|
};
|
2018-10-08 09:23:11 +02:00
|
|
|
|
2017-12-06 14:16:14 +01:00
|
|
|
struct D3D11ContextStateIA {
|
2022-09-16 06:53:58 +00:00
|
|
|
Com<D3D11InputLayout, false> inputLayout = nullptr;
|
|
|
|
D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
2017-12-07 14:03:15 +01:00
|
|
|
|
2020-03-16 18:39:46 +01:00
|
|
|
std::array<D3D11VertexBufferBinding, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> vertexBuffers = { };
|
|
|
|
D3D11IndexBufferBinding indexBuffer = { };
|
2022-08-04 16:34:49 +02:00
|
|
|
|
2022-08-04 18:11:19 +02:00
|
|
|
uint32_t maxVbCount = 0;
|
|
|
|
|
2022-08-04 16:34:49 +02:00
|
|
|
void reset() {
|
|
|
|
inputLayout = nullptr;
|
|
|
|
|
|
|
|
primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
|
|
|
|
2022-08-04 18:11:19 +02:00
|
|
|
for (uint32_t i = 0; i < maxVbCount; i++)
|
2022-08-04 16:34:49 +02:00
|
|
|
vertexBuffers[i] = D3D11VertexBufferBinding();
|
|
|
|
|
|
|
|
indexBuffer = D3D11IndexBufferBinding();
|
|
|
|
}
|
2017-12-06 14:16:14 +01:00
|
|
|
};
|
|
|
|
|
2022-08-04 16:23:47 +02:00
|
|
|
/**
|
|
|
|
* \brief Output merger state
|
|
|
|
*
|
|
|
|
* Stores RTV, DSV, and graphics UAV bindings, as well as related state.
|
|
|
|
*/
|
|
|
|
using D3D11RenderTargetViewBinding = std::array<Com<D3D11RenderTargetView, false>, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT>;
|
2017-12-06 14:16:14 +01:00
|
|
|
|
2017-12-04 13:39:37 +01:00
|
|
|
struct D3D11ContextStateOM {
|
2022-08-04 16:23:47 +02:00
|
|
|
D3D11ShaderStageUavBinding uavs = { };
|
|
|
|
D3D11RenderTargetViewBinding rtvs = { };
|
|
|
|
Com<D3D11DepthStencilView, false> dsv = { };
|
2017-12-11 14:11:18 +01:00
|
|
|
|
2019-10-14 02:05:39 +02:00
|
|
|
D3D11BlendState* cbState = nullptr;
|
|
|
|
D3D11DepthStencilState* dsState = nullptr;
|
2017-12-11 14:11:18 +01:00
|
|
|
|
|
|
|
FLOAT blendFactor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
2022-06-30 19:26:26 +02:00
|
|
|
|
|
|
|
UINT sampleCount = 0u;
|
2022-08-04 16:23:47 +02:00
|
|
|
UINT sampleMask = D3D11_DEFAULT_SAMPLE_MASK;
|
|
|
|
UINT stencilRef = D3D11_DEFAULT_STENCIL_REFERENCE;
|
2019-06-27 15:30:31 +02:00
|
|
|
|
|
|
|
UINT maxRtv = 0u;
|
|
|
|
UINT maxUav = 0u;
|
2022-08-04 16:23:47 +02:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
for (uint32_t i = 0; i < maxUav; i++)
|
|
|
|
uavs[i] = nullptr;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < maxRtv; i++)
|
|
|
|
rtvs[i] = nullptr;
|
|
|
|
|
|
|
|
dsv = nullptr;
|
|
|
|
|
|
|
|
cbState = nullptr;
|
|
|
|
dsState = nullptr;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < 4; i++)
|
|
|
|
blendFactor[i] = 1.0f;
|
|
|
|
|
|
|
|
sampleCount = 0u;
|
|
|
|
sampleMask = D3D11_DEFAULT_SAMPLE_MASK;
|
|
|
|
stencilRef = D3D11_DEFAULT_STENCIL_REFERENCE;
|
|
|
|
|
|
|
|
maxRtv = 0;
|
|
|
|
maxUav = 0;
|
|
|
|
}
|
2017-12-04 13:39:37 +01:00
|
|
|
};
|
|
|
|
|
2022-08-04 16:34:49 +02:00
|
|
|
/**
|
|
|
|
* \brief Indirect draw state
|
|
|
|
*
|
|
|
|
* Stores the current indirct draw
|
|
|
|
* argument and draw count buffer.
|
|
|
|
*/
|
|
|
|
struct D3D11ContextStateID {
|
2022-09-16 10:03:50 +00:00
|
|
|
Com<D3D11Buffer, false> argBuffer = nullptr;
|
|
|
|
Com<D3D11Buffer, false> cntBuffer = nullptr;
|
2022-08-04 16:34:49 +02:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
argBuffer = nullptr;
|
|
|
|
cntBuffer = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Rasterizer state
|
|
|
|
*
|
|
|
|
* Stores viewport info and the rasterizer state object.
|
|
|
|
*/
|
2017-12-06 12:11:59 +01:00
|
|
|
struct D3D11ContextStateRS {
|
|
|
|
uint32_t numViewports = 0;
|
|
|
|
uint32_t numScissors = 0;
|
|
|
|
|
2020-03-16 18:39:46 +01:00
|
|
|
std::array<D3D11_VIEWPORT, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE> viewports = { };
|
|
|
|
std::array<D3D11_RECT, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE> scissors = { };
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2020-03-16 18:39:46 +01:00
|
|
|
D3D11RasterizerState* state = nullptr;
|
2018-07-24 17:09:11 +02:00
|
|
|
|
2022-08-04 16:34:49 +02:00
|
|
|
void reset() {
|
|
|
|
for (uint32_t i = 0; i < numViewports; i++)
|
|
|
|
viewports[i] = D3D11_VIEWPORT();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < numScissors; i++)
|
|
|
|
scissors[i] = D3D11_RECT();
|
|
|
|
|
|
|
|
numViewports = 0;
|
|
|
|
numScissors = 0;
|
2018-07-24 17:09:11 +02:00
|
|
|
|
2022-08-04 16:34:49 +02:00
|
|
|
state = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Stream output binding
|
|
|
|
*
|
|
|
|
* Stores stream output buffers with offset.
|
|
|
|
*/
|
2018-07-24 17:09:11 +02:00
|
|
|
struct D3D11ContextSoTarget {
|
2022-09-16 10:05:15 +00:00
|
|
|
Com<D3D11Buffer, false> buffer = nullptr;
|
|
|
|
UINT offset = 0;
|
2018-07-24 17:09:11 +02:00
|
|
|
};
|
|
|
|
|
2018-03-07 15:32:19 +01:00
|
|
|
struct D3D11ContextStateSO {
|
2020-03-16 18:39:46 +01:00
|
|
|
std::array<D3D11ContextSoTarget, D3D11_SO_BUFFER_SLOT_COUNT> targets = { };
|
2022-08-04 16:34:49 +02:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
for (uint32_t i = 0; i < targets.size(); i++)
|
|
|
|
targets[i] = D3D11ContextSoTarget();
|
|
|
|
}
|
2018-03-07 15:32:19 +01:00
|
|
|
};
|
|
|
|
|
2022-08-04 16:34:49 +02:00
|
|
|
/**
|
|
|
|
* \brief Predication state
|
|
|
|
*
|
|
|
|
* Stores predication info.
|
|
|
|
*/
|
2018-03-09 16:47:20 +01:00
|
|
|
struct D3D11ContextStatePR {
|
2022-09-16 10:05:40 +00:00
|
|
|
Com<D3D11Query, false> predicateObject = nullptr;
|
|
|
|
BOOL predicateValue = false;
|
2022-08-04 16:34:49 +02:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
predicateObject = nullptr;
|
|
|
|
predicateValue = false;
|
|
|
|
}
|
2018-03-09 16:47:20 +01:00
|
|
|
};
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
/**
|
|
|
|
* \brief Context state
|
|
|
|
*/
|
|
|
|
struct D3D11ContextState {
|
2022-09-16 06:42:52 +00:00
|
|
|
Com<D3D11VertexShader, false> vs;
|
|
|
|
Com<D3D11HullShader, false> hs;
|
|
|
|
Com<D3D11DomainShader, false> ds;
|
|
|
|
Com<D3D11GeometryShader, false> gs;
|
|
|
|
Com<D3D11PixelShader, false> ps;
|
|
|
|
Com<D3D11ComputeShader, false> cs;
|
2022-08-04 16:37:23 +02:00
|
|
|
|
2018-10-08 09:23:11 +02:00
|
|
|
D3D11ContextStateID id;
|
2017-12-06 14:16:14 +01:00
|
|
|
D3D11ContextStateIA ia;
|
2017-12-04 13:39:37 +01:00
|
|
|
D3D11ContextStateOM om;
|
2017-12-06 12:11:59 +01:00
|
|
|
D3D11ContextStateRS rs;
|
2018-03-07 15:32:19 +01:00
|
|
|
D3D11ContextStateSO so;
|
2018-03-09 16:47:20 +01:00
|
|
|
D3D11ContextStatePR pr;
|
2022-08-04 15:47:24 +02:00
|
|
|
|
|
|
|
D3D11CbvBindings cbv;
|
2022-08-04 15:56:49 +02:00
|
|
|
D3D11SrvBindings srv;
|
2022-08-04 16:23:47 +02:00
|
|
|
D3D11UavBindings uav;
|
2022-08-04 16:05:21 +02:00
|
|
|
D3D11SamplerBindings samplers;
|
2017-11-29 20:19:40 +01:00
|
|
|
};
|
2022-08-04 17:20:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Maximum used binding numbers in a shader stage
|
|
|
|
*/
|
|
|
|
struct D3D11MaxUsedStageBindings {
|
|
|
|
uint32_t cbvCount : 5;
|
|
|
|
uint32_t srvCount : 9;
|
|
|
|
uint32_t uavCount : 7;
|
|
|
|
uint32_t samplerCount : 5;
|
|
|
|
uint32_t reserved : 6;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Maximum used binding numbers for all context state
|
|
|
|
*/
|
|
|
|
struct D3D11MaxUsedBindings {
|
|
|
|
std::array<D3D11MaxUsedStageBindings, 6> stages;
|
|
|
|
uint32_t vbCount;
|
|
|
|
uint32_t soCount;
|
|
|
|
};
|
|
|
|
|
2017-11-29 20:19:40 +01:00
|
|
|
}
|