2017-11-29 20:19:40 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
#include "d3d11_context.h"
|
|
|
|
#include "d3d11_device.h"
|
2018-01-01 20:59:54 +01:00
|
|
|
#include "d3d11_query.h"
|
2017-12-25 20:40:48 +01:00
|
|
|
#include "d3d11_texture.h"
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2017-12-08 22:30:41 +01:00
|
|
|
#include "../dxbc/dxbc_util.h"
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
2017-10-11 15:32:24 +02:00
|
|
|
D3D11DeviceContext::D3D11DeviceContext(
|
2018-04-28 14:17:52 +02:00
|
|
|
D3D11Device* pParent,
|
|
|
|
const Rc<DxvkDevice>& Device)
|
2018-06-11 14:29:47 +02:00
|
|
|
: m_parent (pParent),
|
|
|
|
m_annotation(this),
|
|
|
|
m_device (Device),
|
2018-08-27 16:07:38 +02:00
|
|
|
m_csChunk (AllocCsChunk()) {
|
2017-12-11 14:11:18 +01:00
|
|
|
// Create default state objects. We won't ever return them
|
|
|
|
// to the application, but we'll use them to apply state.
|
|
|
|
Com<ID3D11BlendState> defaultBlendState;
|
|
|
|
Com<ID3D11DepthStencilState> defaultDepthStencilState;
|
|
|
|
Com<ID3D11RasterizerState> defaultRasterizerState;
|
|
|
|
|
|
|
|
if (FAILED(m_parent->CreateBlendState (nullptr, &defaultBlendState))
|
|
|
|
|| FAILED(m_parent->CreateDepthStencilState(nullptr, &defaultDepthStencilState))
|
|
|
|
|| FAILED(m_parent->CreateRasterizerState (nullptr, &defaultRasterizerState)))
|
|
|
|
throw DxvkError("D3D11DeviceContext: Failed to create default state objects");
|
|
|
|
|
|
|
|
// Apply default state to the context. This is required
|
|
|
|
// in order to initialize the DXVK contex properly.
|
2018-01-20 18:01:43 +01:00
|
|
|
m_defaultBlendState = static_cast<D3D11BlendState*> (defaultBlendState.ptr());
|
2017-12-11 14:11:18 +01:00
|
|
|
m_defaultDepthStencilState = static_cast<D3D11DepthStencilState*>(defaultDepthStencilState.ptr());
|
2018-01-20 18:01:43 +01:00
|
|
|
m_defaultRasterizerState = static_cast<D3D11RasterizerState*> (defaultRasterizerState.ptr());
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D11DeviceContext::~D3D11DeviceContext() {
|
2017-11-26 14:01:41 +01:00
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 12:52:02 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE D3D11DeviceContext::QueryInterface(REFIID riid, void** ppvObject) {
|
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceChild)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceContext)
|
|
|
|
|| riid == __uuidof(ID3D11DeviceContext1)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2018-06-11 14:29:47 +02:00
|
|
|
if (riid == __uuidof(ID3DUserDefinedAnnotation)) {
|
|
|
|
*ppvObject = ref(&m_annotation);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2018-03-05 01:07:09 +01:00
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::warn("D3D11DeviceContext::QueryInterface: Unknown interface query");
|
2018-03-05 01:07:09 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-10-11 09:51:48 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2018-08-03 11:10:40 +02:00
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DiscardResource(ID3D11Resource* pResource) {
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!pResource)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We don't support the Discard API for images
|
2018-08-03 11:10:40 +02:00
|
|
|
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
pResource->GetType(&resType);
|
|
|
|
|
|
|
|
if (resType == D3D11_RESOURCE_DIMENSION_BUFFER)
|
2018-08-03 11:22:26 +02:00
|
|
|
DiscardBuffer(static_cast<D3D11Buffer*>(pResource));
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
2018-08-03 11:10:40 +02:00
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DiscardView(ID3D11View* pResourceView) {
|
|
|
|
// Ignore. We don't do Discard for images or image
|
|
|
|
// subresources, and for buffers we could only really
|
|
|
|
// do this if the view covers the entire buffer.
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
2018-08-03 11:10:40 +02:00
|
|
|
|
2018-03-17 18:54:09 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DiscardView1(
|
|
|
|
ID3D11View* pResourceView,
|
|
|
|
const D3D11_RECT* pRects,
|
|
|
|
UINT NumRects) {
|
2018-07-08 15:53:30 +02:00
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::DiscardView1: Not implemented");
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SwapDeviceContextState(
|
|
|
|
ID3DDeviceContextState* pState,
|
|
|
|
ID3DDeviceContextState** ppPreviousState) {
|
|
|
|
Logger::err("D3D11DeviceContext::SwapDeviceContextState: Not implemented");
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GetDevice(ID3D11Device **ppDevice) {
|
2017-10-11 15:32:24 +02:00
|
|
|
*ppDevice = ref(m_parent);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearState() {
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default shaders
|
|
|
|
m_state.vs.shader = nullptr;
|
|
|
|
m_state.hs.shader = nullptr;
|
|
|
|
m_state.ds.shader = nullptr;
|
|
|
|
m_state.gs.shader = nullptr;
|
|
|
|
m_state.ps.shader = nullptr;
|
|
|
|
m_state.cs.shader = nullptr;
|
|
|
|
|
|
|
|
// Default constant buffers
|
|
|
|
for (uint32_t i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; i++) {
|
2018-03-18 12:36:45 +01:00
|
|
|
m_state.vs.constantBuffers[i] = { nullptr, 0, 0 };
|
|
|
|
m_state.hs.constantBuffers[i] = { nullptr, 0, 0 };
|
|
|
|
m_state.ds.constantBuffers[i] = { nullptr, 0, 0 };
|
|
|
|
m_state.gs.constantBuffers[i] = { nullptr, 0, 0 };
|
|
|
|
m_state.ps.constantBuffers[i] = { nullptr, 0, 0 };
|
|
|
|
m_state.cs.constantBuffers[i] = { nullptr, 0, 0 };
|
2017-12-20 17:37:46 +01:00
|
|
|
}
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default samplers
|
|
|
|
for (uint32_t i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; i++) {
|
|
|
|
m_state.vs.samplers[i] = nullptr;
|
|
|
|
m_state.hs.samplers[i] = nullptr;
|
|
|
|
m_state.ds.samplers[i] = nullptr;
|
|
|
|
m_state.gs.samplers[i] = nullptr;
|
|
|
|
m_state.ps.samplers[i] = nullptr;
|
|
|
|
m_state.cs.samplers[i] = nullptr;
|
2017-12-20 17:37:46 +01:00
|
|
|
}
|
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default shader resources
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
2018-03-10 13:06:15 +01:00
|
|
|
m_state.vs.shaderResources[i] = nullptr;
|
|
|
|
m_state.hs.shaderResources[i] = nullptr;
|
|
|
|
m_state.ds.shaderResources[i] = nullptr;
|
|
|
|
m_state.gs.shaderResources[i] = nullptr;
|
|
|
|
m_state.ps.shaderResources[i] = nullptr;
|
|
|
|
m_state.cs.shaderResources[i] = nullptr;
|
2017-12-20 17:37:46 +01:00
|
|
|
}
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default UAVs
|
|
|
|
for (uint32_t i = 0; i < D3D11_1_UAV_SLOT_COUNT; i++) {
|
|
|
|
m_state.ps.unorderedAccessViews[i] = nullptr;
|
|
|
|
m_state.cs.unorderedAccessViews[i] = nullptr;
|
2017-12-20 17:37:46 +01:00
|
|
|
}
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default IA state
|
|
|
|
m_state.ia.inputLayout = nullptr;
|
|
|
|
m_state.ia.primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) {
|
|
|
|
m_state.ia.vertexBuffers[i].buffer = nullptr;
|
|
|
|
m_state.ia.vertexBuffers[i].offset = 0;
|
|
|
|
m_state.ia.vertexBuffers[i].stride = 0;
|
2017-12-28 19:05:53 +01:00
|
|
|
}
|
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
m_state.ia.indexBuffer.buffer = nullptr;
|
|
|
|
m_state.ia.indexBuffer.offset = 0;
|
|
|
|
m_state.ia.indexBuffer.format = DXGI_FORMAT_UNKNOWN;
|
|
|
|
|
|
|
|
// Default OM State
|
|
|
|
for (uint32_t i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
|
|
|
|
m_state.om.renderTargetViews[i] = nullptr;
|
|
|
|
m_state.om.depthStencilView = nullptr;
|
|
|
|
|
|
|
|
m_state.om.cbState = nullptr;
|
|
|
|
m_state.om.dsState = nullptr;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < 4; i++)
|
|
|
|
m_state.om.blendFactor[i] = 0.0f;
|
|
|
|
|
|
|
|
m_state.om.sampleMask = D3D11_DEFAULT_SAMPLE_MASK;
|
|
|
|
m_state.om.stencilRef = D3D11_DEFAULT_STENCIL_REFERENCE;
|
|
|
|
|
|
|
|
// Default RS state
|
|
|
|
m_state.rs.state = nullptr;
|
|
|
|
m_state.rs.numViewports = 0;
|
|
|
|
m_state.rs.numScissors = 0;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; i++) {
|
|
|
|
m_state.rs.viewports[i] = D3D11_VIEWPORT { };
|
|
|
|
m_state.rs.scissors [i] = D3D11_RECT { };
|
|
|
|
}
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default SO state
|
|
|
|
for (uint32_t i = 0; i < D3D11_SO_STREAM_COUNT; i++)
|
|
|
|
m_state.so.targets[i] = nullptr;
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Default predication
|
|
|
|
m_state.pr.predicateObject = nullptr;
|
|
|
|
m_state.pr.predicateValue = FALSE;
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-03-10 13:06:15 +01:00
|
|
|
// Make sure to apply all state
|
|
|
|
RestoreState();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::Begin(ID3D11Asynchronous *pAsync) {
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!pAsync)
|
2018-04-17 13:57:40 +02:00
|
|
|
return;
|
|
|
|
|
2018-02-18 22:34:23 +01:00
|
|
|
Com<ID3D11Query> query;
|
|
|
|
|
|
|
|
if (SUCCEEDED(pAsync->QueryInterface(__uuidof(ID3D11Query), reinterpret_cast<void**>(&query)))) {
|
|
|
|
Com<D3D11Query> queryPtr = static_cast<D3D11Query*>(query.ptr());
|
|
|
|
|
|
|
|
if (queryPtr->HasBeginEnabled()) {
|
|
|
|
const uint32_t revision = queryPtr->Reset();
|
|
|
|
|
|
|
|
EmitCs([revision, queryPtr] (DxvkContext* ctx) {
|
|
|
|
queryPtr->Begin(ctx, revision);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::End(ID3D11Asynchronous *pAsync) {
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!pAsync)
|
2018-04-17 13:57:40 +02:00
|
|
|
return;
|
2018-05-14 02:40:17 +02:00
|
|
|
|
2018-02-18 22:34:23 +01:00
|
|
|
Com<ID3D11Query> query;
|
2018-05-14 02:40:17 +02:00
|
|
|
|
2018-02-18 22:34:23 +01:00
|
|
|
if (SUCCEEDED(pAsync->QueryInterface(__uuidof(ID3D11Query), reinterpret_cast<void**>(&query)))) {
|
|
|
|
Com<D3D11Query> queryPtr = static_cast<D3D11Query*>(query.ptr());
|
|
|
|
|
|
|
|
if (queryPtr->HasBeginEnabled()) {
|
|
|
|
EmitCs([queryPtr] (DxvkContext* ctx) {
|
|
|
|
queryPtr->End(ctx);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const uint32_t revision = queryPtr->Reset();
|
|
|
|
|
|
|
|
EmitCs([revision, queryPtr] (DxvkContext* ctx) {
|
|
|
|
queryPtr->Signal(ctx, revision);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SetPredication(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Predicate* pPredicate,
|
2018-03-06 18:34:34 +01:00
|
|
|
BOOL PredicateValue) {
|
2018-03-09 16:47:20 +01:00
|
|
|
static bool s_errorShown = false;
|
|
|
|
|
|
|
|
if (!std::exchange(s_errorShown, true))
|
|
|
|
Logger::err("D3D11DeviceContext::SetPredication: Stub");
|
|
|
|
|
|
|
|
m_state.pr.predicateObject = static_cast<D3D11Query*>(pPredicate);
|
|
|
|
m_state.pr.predicateValue = PredicateValue;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GetPredication(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Predicate** ppPredicate,
|
2018-03-06 18:34:34 +01:00
|
|
|
BOOL* pPredicateValue) {
|
2018-03-09 16:47:20 +01:00
|
|
|
if (ppPredicate != nullptr)
|
|
|
|
*ppPredicate = m_state.pr.predicateObject.ref();
|
|
|
|
|
|
|
|
if (pPredicateValue != nullptr)
|
|
|
|
*pPredicateValue = m_state.pr.predicateValue;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CopySubresourceRegion(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
UINT DstSubresource,
|
|
|
|
UINT DstX,
|
|
|
|
UINT DstY,
|
|
|
|
UINT DstZ,
|
|
|
|
ID3D11Resource* pSrcResource,
|
|
|
|
UINT SrcSubresource,
|
|
|
|
const D3D11_BOX* pSrcBox) {
|
2018-08-03 11:22:26 +02:00
|
|
|
CopySubresourceRegion1(
|
|
|
|
pDstResource, DstSubresource, DstX, DstY, DstZ,
|
|
|
|
pSrcResource, SrcSubresource, pSrcBox, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CopySubresourceRegion1(
|
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
UINT DstSubresource,
|
2018-08-27 16:07:38 +02:00
|
|
|
UINT DstX,
|
2018-08-03 11:22:26 +02:00
|
|
|
UINT DstY,
|
2018-08-27 16:07:38 +02:00
|
|
|
UINT DstZ,
|
|
|
|
ID3D11Resource* pSrcResource,
|
|
|
|
UINT SrcSubresource,
|
2018-08-03 11:22:26 +02:00
|
|
|
const D3D11_BOX* pSrcBox,
|
|
|
|
UINT CopyFlags) {
|
2017-12-30 19:10:45 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION dstResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
D3D11_RESOURCE_DIMENSION srcResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
|
|
|
|
pDstResource->GetType(&dstResourceDim);
|
|
|
|
pSrcResource->GetType(&srcResourceDim);
|
|
|
|
|
2018-04-17 22:22:49 +02:00
|
|
|
// Copying 2D image slices to 3D images and vice versa is legal
|
|
|
|
const bool copy2Dto3D = dstResourceDim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
|
|
|
|
&& srcResourceDim == D3D11_RESOURCE_DIMENSION_TEXTURE2D;
|
|
|
|
const bool copy3Dto2D = dstResourceDim == D3D11_RESOURCE_DIMENSION_TEXTURE2D
|
|
|
|
&& srcResourceDim == D3D11_RESOURCE_DIMENSION_TEXTURE3D;
|
|
|
|
|
|
|
|
if (dstResourceDim != srcResourceDim && !copy2Dto3D && !copy3Dto2D) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopySubresourceRegion: Incompatible resources",
|
|
|
|
"\n Dst resource type: ", dstResourceDim,
|
|
|
|
"\n Src resource type: ", srcResourceDim));
|
2017-12-30 19:10:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstResourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
2018-02-03 21:14:55 +01:00
|
|
|
auto dstBuffer = static_cast<D3D11Buffer*>(pDstResource)->GetBufferSlice();
|
|
|
|
auto srcBuffer = static_cast<D3D11Buffer*>(pSrcResource)->GetBufferSlice();
|
2018-08-03 11:22:26 +02:00
|
|
|
|
|
|
|
if (CopyFlags & D3D11_COPY_DISCARD)
|
|
|
|
DiscardBuffer(static_cast<D3D11Buffer*>(pDstResource));
|
2018-02-03 21:14:55 +01:00
|
|
|
|
2018-04-20 23:35:29 +02:00
|
|
|
VkDeviceSize dstOffset = DstX;
|
2018-02-03 21:14:55 +01:00
|
|
|
VkDeviceSize srcOffset = 0;
|
2018-04-20 23:35:29 +02:00
|
|
|
VkDeviceSize regLength = srcBuffer.length();
|
|
|
|
|
|
|
|
if (dstOffset >= dstBuffer.length())
|
|
|
|
return;
|
2018-02-03 21:14:55 +01:00
|
|
|
|
|
|
|
if (pSrcBox != nullptr) {
|
2018-04-20 23:35:29 +02:00
|
|
|
if (pSrcBox->left >= pSrcBox->right)
|
2018-02-03 21:14:55 +01:00
|
|
|
return; // no-op, but legal
|
|
|
|
|
|
|
|
srcOffset = pSrcBox->left;
|
2018-04-20 23:35:29 +02:00
|
|
|
regLength = pSrcBox->right - pSrcBox->left;
|
|
|
|
|
|
|
|
if (srcOffset >= srcBuffer.length())
|
|
|
|
return;
|
2018-02-03 21:14:55 +01:00
|
|
|
}
|
|
|
|
|
2018-04-20 23:35:29 +02:00
|
|
|
// Clamp copy region to prevent out-of-bounds access
|
|
|
|
regLength = std::min(regLength, srcBuffer.length() - srcOffset);
|
|
|
|
regLength = std::min(regLength, dstBuffer.length() - dstOffset);
|
|
|
|
|
2018-02-03 21:14:55 +01:00
|
|
|
EmitCs([
|
2018-04-20 23:35:29 +02:00
|
|
|
cDstSlice = dstBuffer.subSlice(dstOffset, regLength),
|
|
|
|
cSrcSlice = srcBuffer.subSlice(srcOffset, regLength)
|
2018-02-03 21:14:55 +01:00
|
|
|
] (DxvkContext* ctx) {
|
2018-09-18 16:22:47 +02:00
|
|
|
bool sameResource = cDstSlice.buffer() == cSrcSlice.buffer();
|
|
|
|
|
|
|
|
if (!sameResource) {
|
|
|
|
ctx->copyBuffer(
|
|
|
|
cDstSlice.buffer(),
|
|
|
|
cDstSlice.offset(),
|
|
|
|
cSrcSlice.buffer(),
|
|
|
|
cSrcSlice.offset(),
|
|
|
|
cSrcSlice.length());
|
|
|
|
} else {
|
|
|
|
ctx->copyBufferRegion(
|
|
|
|
cDstSlice.buffer(),
|
|
|
|
cDstSlice.offset(),
|
|
|
|
cSrcSlice.offset(),
|
|
|
|
cSrcSlice.length());
|
|
|
|
}
|
2018-02-03 21:14:55 +01:00
|
|
|
});
|
2017-12-30 19:10:45 +01:00
|
|
|
} else {
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* dstTextureInfo = GetCommonTexture(pDstResource);
|
|
|
|
const D3D11CommonTexture* srcTextureInfo = GetCommonTexture(pSrcResource);
|
2017-12-30 19:10:45 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
const Rc<DxvkImage> dstImage = dstTextureInfo->GetImage();
|
|
|
|
const Rc<DxvkImage> srcImage = srcTextureInfo->GetImage();
|
2018-01-06 02:09:07 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
const DxvkFormatInfo* dstFormatInfo = imageFormatInfo(dstImage->info().format);
|
|
|
|
const DxvkFormatInfo* srcFormatInfo = imageFormatInfo(srcImage->info().format);
|
|
|
|
|
|
|
|
const VkImageSubresource dstSubresource = dstTextureInfo->GetSubresourceFromIndex(dstFormatInfo->aspectMask, DstSubresource);
|
|
|
|
const VkImageSubresource srcSubresource = srcTextureInfo->GetSubresourceFromIndex(srcFormatInfo->aspectMask, SrcSubresource);
|
2018-01-06 02:09:07 +01:00
|
|
|
|
2018-04-20 23:35:29 +02:00
|
|
|
// Copies are only supported on size-compatible formats
|
|
|
|
if (dstFormatInfo->elementSize != srcFormatInfo->elementSize) {
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopySubresourceRegion: Incompatible texel size"
|
|
|
|
"\n Dst texel size: ", dstFormatInfo->elementSize,
|
|
|
|
"\n Src texel size: ", srcFormatInfo->elementSize));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copies are only supported if the sample count matches
|
|
|
|
if (dstImage->info().sampleCount != srcImage->info().sampleCount) {
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopySubresourceRegion: Incompatible sample count",
|
|
|
|
"\n Dst sample count: ", dstImage->info().sampleCount,
|
|
|
|
"\n Src sample count: ", srcImage->info().sampleCount));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-30 19:10:45 +01:00
|
|
|
VkOffset3D srcOffset = { 0, 0, 0 };
|
2018-04-20 23:35:29 +02:00
|
|
|
VkOffset3D dstOffset = { int32_t(DstX), int32_t(DstY), int32_t(DstZ) };
|
|
|
|
|
|
|
|
VkExtent3D srcExtent = srcImage->mipLevelExtent(srcSubresource.mipLevel);
|
|
|
|
VkExtent3D dstExtent = dstImage->mipLevelExtent(dstSubresource.mipLevel);
|
|
|
|
VkExtent3D regExtent = srcExtent;
|
2017-12-30 19:10:45 +01:00
|
|
|
|
2018-04-20 23:35:29 +02:00
|
|
|
if (uint32_t(dstOffset.x) >= dstExtent.width
|
|
|
|
|| uint32_t(dstOffset.y) >= dstExtent.height
|
|
|
|
|| uint32_t(dstOffset.z) >= dstExtent.depth)
|
|
|
|
return;
|
2017-12-30 19:10:45 +01:00
|
|
|
|
|
|
|
if (pSrcBox != nullptr) {
|
|
|
|
if (pSrcBox->left >= pSrcBox->right
|
|
|
|
|| pSrcBox->top >= pSrcBox->bottom
|
|
|
|
|| pSrcBox->front >= pSrcBox->back)
|
|
|
|
return; // no-op, but legal
|
|
|
|
|
|
|
|
srcOffset.x = pSrcBox->left;
|
|
|
|
srcOffset.y = pSrcBox->top;
|
|
|
|
srcOffset.z = pSrcBox->front;
|
|
|
|
|
2018-04-20 23:35:29 +02:00
|
|
|
regExtent.width = pSrcBox->right - pSrcBox->left;
|
|
|
|
regExtent.height = pSrcBox->bottom - pSrcBox->top;
|
|
|
|
regExtent.depth = pSrcBox->back - pSrcBox->front;
|
|
|
|
|
|
|
|
if (uint32_t(srcOffset.x) >= srcExtent.width
|
|
|
|
|| uint32_t(srcOffset.y) >= srcExtent.height
|
|
|
|
|| uint32_t(srcOffset.z) >= srcExtent.depth)
|
|
|
|
return;
|
2017-12-30 19:10:45 +01:00
|
|
|
}
|
|
|
|
|
2018-04-17 22:22:49 +02:00
|
|
|
VkImageSubresourceLayers dstLayers = {
|
2017-12-31 00:25:19 +01:00
|
|
|
dstSubresource.aspectMask,
|
|
|
|
dstSubresource.mipLevel,
|
|
|
|
dstSubresource.arrayLayer, 1 };
|
|
|
|
|
2018-04-17 22:22:49 +02:00
|
|
|
VkImageSubresourceLayers srcLayers = {
|
2017-12-31 00:25:19 +01:00
|
|
|
srcSubresource.aspectMask,
|
|
|
|
srcSubresource.mipLevel,
|
|
|
|
srcSubresource.arrayLayer, 1 };
|
2017-12-30 19:10:45 +01:00
|
|
|
|
2018-04-17 22:22:49 +02:00
|
|
|
// Copying multiple slices does not
|
|
|
|
// seem to be supported in D3D11
|
|
|
|
if (copy2Dto3D || copy3Dto2D) {
|
2018-04-20 23:35:29 +02:00
|
|
|
regExtent.depth = 1;
|
2018-04-17 22:22:49 +02:00
|
|
|
dstLayers.layerCount = 1;
|
|
|
|
srcLayers.layerCount = 1;
|
|
|
|
}
|
|
|
|
|
2018-04-20 23:35:29 +02:00
|
|
|
// Don't perform the copy if the offsets aren't aligned
|
|
|
|
if (!util::isBlockAligned(srcOffset, srcFormatInfo->blockSize)
|
|
|
|
|| !util::isBlockAligned(dstOffset, dstFormatInfo->blockSize)) {
|
2018-04-22 22:34:18 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopySubresourceRegion: Unaligned block offset",
|
|
|
|
"\n Src offset: (", srcOffset.x, ",", srcOffset.y, ",", srcOffset.z, ")",
|
|
|
|
"\n Src block size: (", srcFormatInfo->blockSize.width, "x", srcFormatInfo->blockSize.height, "x", srcFormatInfo->blockSize.depth, ")",
|
|
|
|
"\n Dst offset: (", dstOffset.x, ",", dstOffset.y, ",", dstOffset.z, ")",
|
|
|
|
"\n Dst block size: (", dstFormatInfo->blockSize.width, "x", dstFormatInfo->blockSize.height, "x", dstFormatInfo->blockSize.depth, ")"));
|
2018-04-20 23:35:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp the image region in order to avoid out-of-bounds access
|
|
|
|
VkExtent3D regBlockCount = util::computeBlockCount(regExtent, srcFormatInfo->blockSize);
|
|
|
|
VkExtent3D dstBlockCount = util::computeMaxBlockCount(dstOffset, dstExtent, dstFormatInfo->blockSize);
|
|
|
|
VkExtent3D srcBlockCount = util::computeMaxBlockCount(srcOffset, srcExtent, srcFormatInfo->blockSize);
|
|
|
|
|
|
|
|
regBlockCount = util::minExtent3D(regBlockCount, dstBlockCount);
|
|
|
|
regBlockCount = util::minExtent3D(regBlockCount, srcBlockCount);
|
|
|
|
|
|
|
|
regExtent = util::minExtent3D(regExtent, util::computeBlockExtent(regBlockCount, srcFormatInfo->blockSize));
|
|
|
|
|
|
|
|
// Don't perform the copy if the image extent is not aligned and
|
|
|
|
// if it does not touch the image border for unaligned dimensons
|
2018-04-22 23:00:31 +02:00
|
|
|
if (!util::isBlockAligned(srcOffset, regExtent, srcFormatInfo->blockSize, srcExtent)) {
|
2018-04-22 22:34:18 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopySubresourceRegion: Unaligned block size",
|
|
|
|
"\n Src offset: (", srcOffset.x, ",", srcOffset.y, ",", srcOffset.z, ")",
|
|
|
|
"\n Src extent: (", srcExtent.width, "x", srcExtent.height, "x", srcExtent.depth, ")",
|
|
|
|
"\n Src block size: (", srcFormatInfo->blockSize.width, "x", srcFormatInfo->blockSize.height, "x", srcFormatInfo->blockSize.depth, ")",
|
|
|
|
"\n Dst offset: (", dstOffset.x, ",", dstOffset.y, ",", dstOffset.z, ")",
|
|
|
|
"\n Dst extent: (", dstExtent.width, "x", dstExtent.height, "x", dstExtent.depth, ")",
|
|
|
|
"\n Dst block size: (", dstFormatInfo->blockSize.width, "x", dstFormatInfo->blockSize.height, "x", dstFormatInfo->blockSize.depth, ")",
|
|
|
|
"\n Region extent: (", regExtent.width, "x", regExtent.height, "x", regExtent.depth, ")"));
|
2018-04-20 23:35:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:30:31 +01:00
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = dstImage,
|
|
|
|
cSrcImage = srcImage,
|
2018-01-20 19:30:31 +01:00
|
|
|
cDstLayers = dstLayers,
|
|
|
|
cSrcLayers = srcLayers,
|
|
|
|
cDstOffset = dstOffset,
|
|
|
|
cSrcOffset = srcOffset,
|
2018-04-20 23:35:29 +02:00
|
|
|
cExtent = regExtent
|
2018-01-20 19:30:31 +01:00
|
|
|
] (DxvkContext* ctx) {
|
2018-09-18 16:22:47 +02:00
|
|
|
bool sameSubresource = cDstImage == cSrcImage
|
|
|
|
&& cDstLayers == cSrcLayers;
|
|
|
|
|
|
|
|
if (!sameSubresource) {
|
|
|
|
ctx->copyImage(
|
|
|
|
cDstImage, cDstLayers, cDstOffset,
|
|
|
|
cSrcImage, cSrcLayers, cSrcOffset,
|
|
|
|
cExtent);
|
|
|
|
} else {
|
|
|
|
ctx->copyImageRegion(
|
|
|
|
cDstImage, cDstLayers,
|
|
|
|
cDstOffset, cSrcOffset,
|
|
|
|
cExtent);
|
|
|
|
}
|
2018-01-20 19:30:31 +01:00
|
|
|
});
|
2017-12-30 19:10:45 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2018-04-04 11:24:16 +02:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CopyResource(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
ID3D11Resource* pSrcResource) {
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!pDstResource || !pSrcResource)
|
|
|
|
return;
|
|
|
|
|
2017-12-28 19:05:53 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION dstResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
D3D11_RESOURCE_DIMENSION srcResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
|
|
|
|
|
|
|
pDstResource->GetType(&dstResourceDim);
|
|
|
|
pSrcResource->GetType(&srcResourceDim);
|
|
|
|
|
|
|
|
if (dstResourceDim != srcResourceDim) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopyResource: Incompatible resources",
|
|
|
|
"\n Dst resource type: ", dstResourceDim,
|
|
|
|
"\n Src resource type: ", srcResourceDim));
|
2017-12-28 19:05:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dstResourceDim == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
|
|
|
auto dstBuffer = static_cast<D3D11Buffer*>(pDstResource)->GetBufferSlice();
|
|
|
|
auto srcBuffer = static_cast<D3D11Buffer*>(pSrcResource)->GetBufferSlice();
|
|
|
|
|
|
|
|
if (dstBuffer.length() != srcBuffer.length()) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopyResource: Mismatched buffer size",
|
|
|
|
"\n Dst buffer size: ", dstBuffer.length(),
|
|
|
|
"\n Src buffer size: ", srcBuffer.length()));
|
2017-12-28 19:05:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:30:31 +01:00
|
|
|
EmitCs([
|
|
|
|
cDstBuffer = std::move(dstBuffer),
|
|
|
|
cSrcBuffer = std::move(srcBuffer)
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyBuffer(
|
|
|
|
cDstBuffer.buffer(),
|
|
|
|
cDstBuffer.offset(),
|
|
|
|
cSrcBuffer.buffer(),
|
|
|
|
cSrcBuffer.offset(),
|
|
|
|
cSrcBuffer.length());
|
|
|
|
});
|
2017-12-28 19:05:53 +01:00
|
|
|
} else {
|
2018-03-14 00:45:07 +01:00
|
|
|
const Rc<DxvkImage> dstImage = GetCommonTexture(pDstResource)->GetImage();
|
|
|
|
const Rc<DxvkImage> srcImage = GetCommonTexture(pSrcResource)->GetImage();
|
2018-01-14 10:39:59 +01:00
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
const DxvkFormatInfo* dstFormatInfo = imageFormatInfo(dstImage->info().format);
|
|
|
|
const DxvkFormatInfo* srcFormatInfo = imageFormatInfo(srcImage->info().format);
|
2018-04-20 23:35:29 +02:00
|
|
|
|
|
|
|
// Copies are only supported on size-compatible formats
|
|
|
|
if (dstFormatInfo->elementSize != srcFormatInfo->elementSize) {
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopyResource: Incompatible texel size"
|
|
|
|
"\n Dst texel size: ", dstFormatInfo->elementSize,
|
|
|
|
"\n Src texel size: ", srcFormatInfo->elementSize));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layer count, mip level count, and sample count must match
|
|
|
|
if (srcImage->info().numLayers != dstImage->info().numLayers
|
|
|
|
|| srcImage->info().mipLevels != dstImage->info().mipLevels
|
|
|
|
|| srcImage->info().sampleCount != dstImage->info().sampleCount) {
|
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: CopyResource: Incompatible images"
|
|
|
|
"\n Dst: (", dstImage->info().numLayers,
|
|
|
|
",", dstImage->info().mipLevels,
|
|
|
|
",", dstImage->info().sampleCount, ")",
|
|
|
|
"\n Src: (", srcImage->info().numLayers,
|
|
|
|
",", srcImage->info().mipLevels,
|
|
|
|
",", srcImage->info().sampleCount, ")"));
|
|
|
|
return;
|
|
|
|
}
|
2018-03-14 00:45:07 +01:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < srcImage->info().mipLevels; i++) {
|
2018-04-20 23:35:29 +02:00
|
|
|
VkImageSubresourceLayers dstLayers = { dstFormatInfo->aspectMask, i, 0, dstImage->info().numLayers };
|
|
|
|
VkImageSubresourceLayers srcLayers = { srcFormatInfo->aspectMask, i, 0, srcImage->info().numLayers };
|
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
VkExtent3D extent = srcImage->mipLevelExtent(i);
|
2018-01-20 19:30:31 +01:00
|
|
|
|
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = dstImage,
|
|
|
|
cSrcImage = srcImage,
|
2018-01-20 19:30:31 +01:00
|
|
|
cDstLayers = dstLayers,
|
|
|
|
cSrcLayers = srcLayers,
|
|
|
|
cExtent = extent
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyImage(
|
|
|
|
cDstImage, cDstLayers, VkOffset3D { 0, 0, 0 },
|
2018-01-21 01:57:12 +01:00
|
|
|
cSrcImage, cSrcLayers, VkOffset3D { 0, 0, 0 },
|
2018-01-20 19:30:31 +01:00
|
|
|
cExtent);
|
|
|
|
});
|
2018-01-14 21:17:51 +01:00
|
|
|
}
|
2017-12-28 19:05:53 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-01-14 21:17:51 +01:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CopyStructureCount(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pDstBuffer,
|
|
|
|
UINT DstAlignedByteOffset,
|
|
|
|
ID3D11UnorderedAccessView* pSrcView) {
|
2018-01-11 12:23:55 +01:00
|
|
|
auto buf = static_cast<D3D11Buffer*>(pDstBuffer);
|
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(pSrcView);
|
2018-01-14 21:17:51 +01:00
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!buf || !uav)
|
|
|
|
return;
|
|
|
|
|
2018-01-20 19:30:31 +01:00
|
|
|
EmitCs([
|
|
|
|
cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset),
|
|
|
|
cSrcSlice = uav->GetCounterSlice()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyBuffer(
|
|
|
|
cDstSlice.buffer(),
|
|
|
|
cDstSlice.offset(),
|
|
|
|
cSrcSlice.buffer(),
|
|
|
|
cSrcSlice.offset(),
|
|
|
|
sizeof(uint32_t));
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearRenderTargetView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11RenderTargetView* pRenderTargetView,
|
|
|
|
const FLOAT ColorRGBA[4]) {
|
2017-12-04 13:39:37 +01:00
|
|
|
auto rtv = static_cast<D3D11RenderTargetView*>(pRenderTargetView);
|
2018-02-24 23:39:22 +01:00
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!rtv)
|
2018-02-24 23:39:22 +01:00
|
|
|
return;
|
2017-12-01 00:52:39 +01:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
const Rc<DxvkImageView> view = rtv->GetImageView();
|
2017-11-29 20:19:40 +01:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
VkClearValue clearValue;
|
|
|
|
clearValue.color.float32[0] = ColorRGBA[0];
|
|
|
|
clearValue.color.float32[1] = ColorRGBA[1];
|
|
|
|
clearValue.color.float32[2] = ColorRGBA[2];
|
|
|
|
clearValue.color.float32[3] = ColorRGBA[3];
|
2017-11-29 20:19:40 +01:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cImageView = view
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearRenderTarget(
|
2018-07-06 15:01:37 +02:00
|
|
|
cImageView,
|
2018-03-17 17:59:43 +01:00
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
cClearValue);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearUnorderedAccessViewUint(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11UnorderedAccessView* pUnorderedAccessView,
|
|
|
|
const UINT Values[4]) {
|
2018-02-04 23:57:43 +01:00
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);
|
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!uav)
|
2018-02-24 23:39:22 +01:00
|
|
|
return;
|
|
|
|
|
2018-04-12 23:25:40 +02:00
|
|
|
// Gather UAV format info. We'll use this to determine
|
|
|
|
// whether we need to create a temporary view or not.
|
|
|
|
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
|
|
|
|
uav->GetDesc(&uavDesc);
|
|
|
|
|
|
|
|
VkFormat uavFormat = m_parent->LookupFormat(uavDesc.Format, DXGI_VK_FORMAT_MODE_ANY).Format;
|
|
|
|
VkFormat rawFormat = m_parent->LookupFormat(uavDesc.Format, DXGI_VK_FORMAT_MODE_RAW).Format;
|
|
|
|
|
|
|
|
// FIXME support packed formats
|
|
|
|
if (uavFormat != rawFormat && rawFormat == VK_FORMAT_UNDEFINED) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format("D3D11: ClearUnorderedAccessViewUint: No raw format found for ", uavFormat));
|
2018-04-12 23:25:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up clear color struct
|
2018-08-15 18:06:52 +02:00
|
|
|
VkClearValue clearValue;
|
|
|
|
clearValue.color.uint32[0] = Values[0];
|
|
|
|
clearValue.color.uint32[1] = Values[1];
|
|
|
|
clearValue.color.uint32[2] = Values[2];
|
|
|
|
clearValue.color.uint32[3] = Values[3];
|
2018-04-11 23:39:12 +02:00
|
|
|
|
2018-02-04 23:57:43 +01:00
|
|
|
if (uav->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
2018-04-12 23:25:40 +02:00
|
|
|
// In case of raw and structured buffers as well as typed
|
|
|
|
// buffers that can be used for atomic operations, we can
|
|
|
|
// use the fast Vulkan buffer clear function.
|
|
|
|
Rc<DxvkBufferView> bufferView = uav->GetBufferView();
|
2018-03-07 16:29:13 +01:00
|
|
|
|
2018-04-11 23:39:12 +02:00
|
|
|
if (bufferView->info().format == VK_FORMAT_R32_UINT
|
|
|
|
|| bufferView->info().format == VK_FORMAT_R32_SINT
|
|
|
|
|| bufferView->info().format == VK_FORMAT_R32_SFLOAT) {
|
2018-03-07 16:29:13 +01:00
|
|
|
EmitCs([
|
|
|
|
cClearValue = Values[0],
|
|
|
|
cDstSlice = bufferView->slice()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBuffer(
|
|
|
|
cDstSlice.buffer(),
|
|
|
|
cDstSlice.offset(),
|
|
|
|
cDstSlice.length(),
|
|
|
|
cClearValue);
|
|
|
|
});
|
|
|
|
} else {
|
2018-04-12 23:25:40 +02:00
|
|
|
// Create a view with an integer format if necessary
|
|
|
|
if (uavFormat != rawFormat) {
|
|
|
|
DxvkBufferViewCreateInfo info = bufferView->info();
|
|
|
|
info.format = rawFormat;
|
|
|
|
|
|
|
|
bufferView = m_device->createBufferView(
|
|
|
|
bufferView->buffer(), info);
|
|
|
|
}
|
2018-04-11 23:39:12 +02:00
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cDstView = bufferView
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cDstView, 0,
|
|
|
|
cDstView->elementCount(),
|
2018-08-15 18:06:52 +02:00
|
|
|
cClearValue.color);
|
2018-04-11 23:39:12 +02:00
|
|
|
});
|
2018-03-07 16:29:13 +01:00
|
|
|
}
|
2018-02-04 23:57:43 +01:00
|
|
|
} else {
|
2018-04-12 23:25:40 +02:00
|
|
|
// Create a view with an integer format if necessary
|
2018-04-11 23:39:12 +02:00
|
|
|
Rc<DxvkImageView> imageView = uav->GetImageView();
|
2018-02-04 23:57:43 +01:00
|
|
|
|
2018-04-12 23:25:40 +02:00
|
|
|
if (uavFormat != rawFormat) {
|
|
|
|
DxvkImageViewCreateInfo info = imageView->info();
|
|
|
|
info.format = rawFormat;
|
|
|
|
|
|
|
|
imageView = m_device->createImageView(
|
|
|
|
imageView->image(), info);
|
|
|
|
}
|
|
|
|
|
2018-02-04 23:57:43 +01:00
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
2018-04-11 23:39:12 +02:00
|
|
|
cDstView = imageView
|
2018-02-04 23:57:43 +01:00
|
|
|
] (DxvkContext* ctx) {
|
2018-04-11 23:39:12 +02:00
|
|
|
ctx->clearImageView(cDstView,
|
|
|
|
VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstView->mipLevelExtent(0),
|
|
|
|
cClearValue);
|
2018-02-04 23:57:43 +01:00
|
|
|
});
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearUnorderedAccessViewFloat(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11UnorderedAccessView* pUnorderedAccessView,
|
|
|
|
const FLOAT Values[4]) {
|
2018-04-11 23:39:12 +02:00
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);
|
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!uav)
|
2018-04-11 23:39:12 +02:00
|
|
|
return;
|
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
VkClearValue clearValue;
|
|
|
|
clearValue.color.float32[0] = Values[0];
|
|
|
|
clearValue.color.float32[1] = Values[1];
|
|
|
|
clearValue.color.float32[2] = Values[2];
|
|
|
|
clearValue.color.float32[3] = Values[3];
|
2018-04-11 23:39:12 +02:00
|
|
|
|
|
|
|
if (uav->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cDstView = uav->GetBufferView()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cDstView, 0,
|
|
|
|
cDstView->elementCount(),
|
2018-08-15 18:06:52 +02:00
|
|
|
cClearValue.color);
|
2018-04-11 23:39:12 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cDstView = uav->GetImageView()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearImageView(cDstView,
|
|
|
|
VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstView->mipLevelExtent(0),
|
|
|
|
cClearValue);
|
|
|
|
});
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearDepthStencilView(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11DepthStencilView* pDepthStencilView,
|
|
|
|
UINT ClearFlags,
|
|
|
|
FLOAT Depth,
|
|
|
|
UINT8 Stencil) {
|
2017-12-09 03:53:42 +01:00
|
|
|
auto dsv = static_cast<D3D11DepthStencilView*>(pDepthStencilView);
|
2018-02-24 23:39:22 +01:00
|
|
|
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!dsv)
|
2018-02-24 23:39:22 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Figure out which aspects to clear based
|
|
|
|
// on the image format and the clear flags.
|
|
|
|
const Rc<DxvkImageView> view = dsv->GetImageView();
|
2017-12-09 03:53:42 +01:00
|
|
|
|
2018-01-23 19:01:07 +01:00
|
|
|
VkImageAspectFlags aspectMask = 0;
|
|
|
|
|
|
|
|
if (ClearFlags & D3D11_CLEAR_DEPTH)
|
|
|
|
aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
|
|
|
|
|
|
|
if (ClearFlags & D3D11_CLEAR_STENCIL)
|
|
|
|
aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
aspectMask &= imageFormatInfo(view->info().format)->aspectMask;
|
|
|
|
|
|
|
|
VkClearValue clearValue;
|
|
|
|
clearValue.depthStencil.depth = Depth;
|
|
|
|
clearValue.depthStencil.stencil = Stencil;
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cAspectMask = aspectMask,
|
|
|
|
cImageView = view
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearRenderTarget(
|
2018-07-06 15:01:37 +02:00
|
|
|
cImageView,
|
|
|
|
cAspectMask,
|
|
|
|
cClearValue);
|
2018-03-17 17:59:43 +01:00
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
|
2018-03-17 18:54:09 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ClearView(
|
|
|
|
ID3D11View* pView,
|
|
|
|
const FLOAT Color[4],
|
|
|
|
const D3D11_RECT* pRect,
|
|
|
|
UINT NumRects) {
|
2018-08-15 19:02:14 +02:00
|
|
|
// ID3D11View has no methods to query the exact type of
|
|
|
|
// the view, so we'll have to check each possible class
|
|
|
|
auto dsv = dynamic_cast<D3D11DepthStencilView*>(pView);
|
|
|
|
auto rtv = dynamic_cast<D3D11RenderTargetView*>(pView);
|
|
|
|
auto uav = dynamic_cast<D3D11UnorderedAccessView*>(pView);
|
|
|
|
|
|
|
|
// Retrieve underlying resource view
|
|
|
|
Rc<DxvkBufferView> bufView;
|
|
|
|
Rc<DxvkImageView> imgView;
|
|
|
|
|
|
|
|
if (dsv != nullptr)
|
|
|
|
imgView = dsv->GetImageView();
|
|
|
|
|
|
|
|
if (rtv != nullptr)
|
|
|
|
imgView = rtv->GetImageView();
|
|
|
|
|
|
|
|
if (uav != nullptr) {
|
|
|
|
bufView = uav->GetBufferView();
|
|
|
|
imgView = uav->GetImageView();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3D views are unsupported
|
|
|
|
if (imgView != nullptr
|
|
|
|
&& imgView->info().type == VK_IMAGE_VIEW_TYPE_3D)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Query the view format. We'll have to convert
|
|
|
|
// the clear color based on the format's data type.
|
|
|
|
VkFormat format = VK_FORMAT_UNDEFINED;
|
|
|
|
|
|
|
|
if (bufView != nullptr)
|
|
|
|
format = bufView->info().format;
|
|
|
|
|
|
|
|
if (imgView != nullptr)
|
|
|
|
format = imgView->info().format;
|
|
|
|
|
|
|
|
if (format == VK_FORMAT_UNDEFINED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We'll need the format info to determine the buffer
|
|
|
|
// element size, and we also need it for depth images.
|
|
|
|
const DxvkFormatInfo* formatInfo = imageFormatInfo(format);
|
|
|
|
|
|
|
|
// Convert the clear color format. ClearView takes
|
|
|
|
// the clear value for integer formats as a set of
|
|
|
|
// integral floats, so we'll have to convert.
|
|
|
|
VkClearValue clearValue;
|
|
|
|
|
|
|
|
if (imgView == nullptr || imgView->info().aspect & VK_IMAGE_ASPECT_COLOR_BIT) {
|
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
|
|
|
if (formatInfo->flags.test(DxvkFormatFlag::SampledUInt))
|
|
|
|
clearValue.color.uint32[i] = uint32_t(Color[i]);
|
|
|
|
else if (formatInfo->flags.test(DxvkFormatFlag::SampledSInt))
|
|
|
|
clearValue.color.int32[i] = int32_t(Color[i]);
|
|
|
|
else
|
|
|
|
clearValue.color.float32[i] = Color[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
clearValue.depthStencil.depth = Color[0];
|
|
|
|
clearValue.depthStencil.stencil = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear all the rectangles that are specified
|
|
|
|
for (uint32_t i = 0; i < NumRects; i++) {
|
|
|
|
if (pRect[i].left >= pRect[i].right
|
|
|
|
|| pRect[i].top >= pRect[i].bottom)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bufView != nullptr) {
|
|
|
|
VkDeviceSize offset = pRect[i].left;
|
|
|
|
VkDeviceSize length = pRect[i].right - pRect[i].left;
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cBufferView = bufView,
|
|
|
|
cRangeOffset = offset,
|
|
|
|
cRangeLength = length,
|
|
|
|
cClearValue = clearValue
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(
|
|
|
|
cBufferView,
|
|
|
|
cRangeOffset,
|
|
|
|
cRangeLength,
|
|
|
|
cClearValue.color);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imgView != nullptr) {
|
|
|
|
VkOffset3D offset = { pRect[i].left, pRect[i].top, 0 };
|
|
|
|
VkExtent3D extent = {
|
|
|
|
uint32_t(pRect[i].right - pRect[i].left),
|
|
|
|
uint32_t(pRect[i].bottom - pRect[i].top), 1 };
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cImageView = imgView,
|
|
|
|
cAreaOffset = offset,
|
|
|
|
cAreaExtent = extent,
|
|
|
|
cClearValue = clearValue
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearImageView(
|
|
|
|
cImageView,
|
|
|
|
cAreaOffset,
|
|
|
|
cAreaExtent,
|
|
|
|
cClearValue);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The rect array is optional, so if it is not
|
|
|
|
// specified, we'll have to clear the entire view
|
|
|
|
if (pRect == nullptr) {
|
|
|
|
if (bufView != nullptr) {
|
|
|
|
EmitCs([
|
|
|
|
cBufferView = bufView,
|
|
|
|
cClearValue = clearValue,
|
|
|
|
cElementSize = formatInfo->elementSize
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->clearBufferView(cBufferView,
|
|
|
|
cBufferView->info().rangeOffset / cElementSize,
|
|
|
|
cBufferView->info().rangeLength / cElementSize,
|
|
|
|
cClearValue.color);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imgView != nullptr) {
|
|
|
|
EmitCs([
|
|
|
|
cImageView = imgView,
|
|
|
|
cClearValue = clearValue
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
VkOffset3D offset = { 0, 0, 0 };
|
|
|
|
VkExtent3D extent = cImageView->mipLevelExtent(0);
|
|
|
|
|
|
|
|
ctx->clearImageView(cImageView,
|
|
|
|
offset, extent, cClearValue);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
2018-08-15 18:06:52 +02:00
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView* pShaderResourceView) {
|
2018-01-20 09:46:54 +01:00
|
|
|
auto view = static_cast<D3D11ShaderResourceView*>(pShaderResourceView);
|
2018-09-19 11:59:53 +02:00
|
|
|
|
|
|
|
if (!view || view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER)
|
2018-08-15 16:35:26 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
EmitCs([cDstImageView = view->GetImageView()]
|
|
|
|
(DxvkContext* ctx) {
|
|
|
|
ctx->generateMipmaps(cDstImageView);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::UpdateSubresource(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
UINT DstSubresource,
|
|
|
|
const D3D11_BOX* pDstBox,
|
|
|
|
const void* pSrcData,
|
|
|
|
UINT SrcRowPitch,
|
|
|
|
UINT SrcDepthPitch) {
|
2018-08-03 11:22:26 +02:00
|
|
|
UpdateSubresource1(pDstResource,
|
|
|
|
DstSubresource, pDstBox, pSrcData,
|
|
|
|
SrcRowPitch, SrcDepthPitch, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::UpdateSubresource1(
|
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
UINT DstSubresource,
|
|
|
|
const D3D11_BOX* pDstBox,
|
|
|
|
const void* pSrcData,
|
|
|
|
UINT SrcRowPitch,
|
|
|
|
UINT SrcDepthPitch,
|
|
|
|
UINT CopyFlags) {
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!pDstResource)
|
|
|
|
return;
|
|
|
|
|
2017-12-08 19:39:33 +01:00
|
|
|
// We need a different code path for buffers
|
|
|
|
D3D11_RESOURCE_DIMENSION resourceType;
|
|
|
|
pDstResource->GetType(&resourceType);
|
|
|
|
|
|
|
|
if (resourceType == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
2017-12-14 19:07:08 +01:00
|
|
|
const auto bufferResource = static_cast<D3D11Buffer*>(pDstResource);
|
2017-12-15 19:11:10 +01:00
|
|
|
const auto bufferSlice = bufferResource->GetBufferSlice();
|
2018-08-03 11:22:26 +02:00
|
|
|
|
|
|
|
if (CopyFlags & D3D11_COPY_DISCARD)
|
|
|
|
DiscardBuffer(bufferResource);
|
2017-12-08 19:39:33 +01:00
|
|
|
|
2018-01-20 21:42:11 +01:00
|
|
|
VkDeviceSize offset = bufferSlice.offset();
|
|
|
|
VkDeviceSize size = bufferSlice.length();
|
2017-12-08 19:39:33 +01:00
|
|
|
|
|
|
|
if (pDstBox != nullptr) {
|
|
|
|
offset = pDstBox->left;
|
|
|
|
size = pDstBox->right - pDstBox->left;
|
|
|
|
}
|
|
|
|
|
2017-12-14 19:11:13 +01:00
|
|
|
if (offset + size > bufferSlice.length()) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: UpdateSubresource: Buffer update range out of bounds",
|
|
|
|
"\n Dst slice offset: ", bufferSlice.offset(),
|
|
|
|
"\n Dst slice length: ", bufferSlice.length(),
|
|
|
|
"\n Src slice offset: ", offset,
|
|
|
|
"\n Src slice length: ", size));
|
2017-12-14 19:07:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-18 11:55:27 +01:00
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (((size == bufferSlice.length())
|
2018-01-18 18:50:44 +01:00
|
|
|
&& (bufferSlice.buffer()->memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))) {
|
2018-01-23 12:16:28 +01:00
|
|
|
D3D11_MAPPED_SUBRESOURCE mappedSr;
|
|
|
|
Map(pDstResource, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedSr);
|
|
|
|
std::memcpy(mappedSr.pData, pSrcData, size);
|
|
|
|
Unmap(pDstResource, 0);
|
2018-01-18 11:55:27 +01:00
|
|
|
} else {
|
2018-01-23 16:43:55 +01:00
|
|
|
DxvkDataSlice dataSlice = AllocUpdateBufferSlice(size);
|
|
|
|
std::memcpy(dataSlice.ptr(), pSrcData, size);
|
|
|
|
|
2018-01-20 21:42:11 +01:00
|
|
|
EmitCs([
|
2018-01-23 16:43:55 +01:00
|
|
|
cDataBuffer = std::move(dataSlice),
|
2018-01-20 21:42:11 +01:00
|
|
|
cBufferSlice = bufferSlice.subSlice(offset, size)
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->updateBuffer(
|
|
|
|
cBufferSlice.buffer(),
|
|
|
|
cBufferSlice.offset(),
|
|
|
|
cBufferSlice.length(),
|
2018-01-23 16:43:55 +01:00
|
|
|
cDataBuffer.ptr());
|
2018-01-20 21:42:11 +01:00
|
|
|
});
|
2017-12-14 19:07:08 +01:00
|
|
|
}
|
2017-12-08 19:39:33 +01:00
|
|
|
} else {
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* textureInfo = GetCommonTexture(pDstResource);
|
2017-12-25 20:40:48 +01:00
|
|
|
|
2018-01-06 02:09:07 +01:00
|
|
|
const VkImageSubresource subresource =
|
2018-03-14 00:45:07 +01:00
|
|
|
textureInfo->GetSubresourceFromIndex(
|
|
|
|
VK_IMAGE_ASPECT_COLOR_BIT, DstSubresource);
|
2018-01-06 02:09:07 +01:00
|
|
|
|
2017-12-25 20:40:48 +01:00
|
|
|
VkOffset3D offset = { 0, 0, 0 };
|
2018-03-14 00:45:07 +01:00
|
|
|
VkExtent3D extent = textureInfo->GetImage()->mipLevelExtent(subresource.mipLevel);
|
2017-12-25 20:40:48 +01:00
|
|
|
|
|
|
|
if (pDstBox != nullptr) {
|
|
|
|
if (pDstBox->left >= pDstBox->right
|
|
|
|
|| pDstBox->top >= pDstBox->bottom
|
|
|
|
|| pDstBox->front >= pDstBox->back)
|
|
|
|
return; // no-op, but legal
|
|
|
|
|
|
|
|
offset.x = pDstBox->left;
|
|
|
|
offset.y = pDstBox->top;
|
|
|
|
offset.z = pDstBox->front;
|
|
|
|
|
|
|
|
extent.width = pDstBox->right - pDstBox->left;
|
|
|
|
extent.height = pDstBox->bottom - pDstBox->top;
|
|
|
|
extent.depth = pDstBox->back - pDstBox->front;
|
|
|
|
}
|
|
|
|
|
2018-01-06 02:09:07 +01:00
|
|
|
const VkImageSubresourceLayers layers = {
|
|
|
|
subresource.aspectMask,
|
|
|
|
subresource.mipLevel,
|
|
|
|
subresource.arrayLayer, 1 };
|
2017-12-25 20:40:48 +01:00
|
|
|
|
2018-01-20 21:42:11 +01:00
|
|
|
auto formatInfo = imageFormatInfo(
|
2018-03-14 00:45:07 +01:00
|
|
|
textureInfo->GetImage()->info().format);
|
2018-01-20 21:42:11 +01:00
|
|
|
|
|
|
|
const VkExtent3D regionExtent = util::computeBlockCount(extent, formatInfo->blockSize);
|
|
|
|
|
|
|
|
const VkDeviceSize bytesPerRow = regionExtent.width * formatInfo->elementSize;
|
|
|
|
const VkDeviceSize bytesPerLayer = regionExtent.height * bytesPerRow;
|
|
|
|
const VkDeviceSize bytesTotal = regionExtent.depth * bytesPerLayer;
|
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
DxvkDataSlice imageDataBuffer = AllocUpdateBufferSlice(bytesTotal);
|
2018-01-20 21:42:11 +01:00
|
|
|
|
|
|
|
util::packImageData(
|
2018-01-23 16:43:55 +01:00
|
|
|
reinterpret_cast<char*>(imageDataBuffer.ptr()),
|
2018-01-20 21:42:11 +01:00
|
|
|
reinterpret_cast<const char*>(pSrcData),
|
|
|
|
regionExtent, formatInfo->elementSize,
|
2017-12-25 20:40:48 +01:00
|
|
|
SrcRowPitch, SrcDepthPitch);
|
2018-01-20 21:42:11 +01:00
|
|
|
|
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = textureInfo->GetImage(),
|
2018-01-20 21:42:11 +01:00
|
|
|
cDstLayers = layers,
|
|
|
|
cDstOffset = offset,
|
|
|
|
cDstExtent = extent,
|
|
|
|
cSrcData = std::move(imageDataBuffer),
|
|
|
|
cSrcBytesPerRow = bytesPerRow,
|
|
|
|
cSrcBytesPerLayer = bytesPerLayer
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->updateImage(cDstImage, cDstLayers,
|
2018-01-23 16:43:55 +01:00
|
|
|
cDstOffset, cDstExtent, cSrcData.ptr(),
|
2018-01-20 21:42:11 +01:00
|
|
|
cSrcBytesPerRow, cSrcBytesPerLayer);
|
|
|
|
});
|
2017-12-08 19:39:33 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SetResourceMinLOD(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
FLOAT MinLOD) {
|
|
|
|
Logger::err("D3D11DeviceContext::SetResourceMinLOD: Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
FLOAT STDMETHODCALLTYPE D3D11DeviceContext::GetResourceMinLOD(ID3D11Resource* pResource) {
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::err("D3D11DeviceContext::GetResourceMinLOD: Not implemented");
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::ResolveSubresource(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Resource* pDstResource,
|
|
|
|
UINT DstSubresource,
|
|
|
|
ID3D11Resource* pSrcResource,
|
|
|
|
UINT SrcSubresource,
|
|
|
|
DXGI_FORMAT Format) {
|
2018-09-19 11:59:53 +02:00
|
|
|
if (!pDstResource || !pSrcResource)
|
|
|
|
return;
|
|
|
|
|
2018-01-28 18:06:41 +01:00
|
|
|
D3D11_RESOURCE_DIMENSION dstResourceType;
|
|
|
|
D3D11_RESOURCE_DIMENSION srcResourceType;
|
|
|
|
|
|
|
|
pDstResource->GetType(&dstResourceType);
|
|
|
|
pSrcResource->GetType(&srcResourceType);
|
|
|
|
|
|
|
|
if (dstResourceType != D3D11_RESOURCE_DIMENSION_TEXTURE2D
|
|
|
|
|| srcResourceType != D3D11_RESOURCE_DIMENSION_TEXTURE2D) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: ResolveSubresource: Incompatible resources",
|
|
|
|
"\n Dst resource type: ", dstResourceType,
|
|
|
|
"\n Src resource type: ", srcResourceType));
|
2018-01-28 18:06:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dstTexture = static_cast<D3D11Texture2D*>(pDstResource);
|
|
|
|
auto srcTexture = static_cast<D3D11Texture2D*>(pSrcResource);
|
|
|
|
|
|
|
|
D3D11_TEXTURE2D_DESC dstDesc;
|
|
|
|
D3D11_TEXTURE2D_DESC srcDesc;
|
|
|
|
|
|
|
|
dstTexture->GetDesc(&dstDesc);
|
|
|
|
srcTexture->GetDesc(&srcDesc);
|
|
|
|
|
2018-01-30 01:18:43 +01:00
|
|
|
if (dstDesc.SampleDesc.Count != 1) {
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err(str::format(
|
|
|
|
"D3D11: ResolveSubresource: Invalid sample counts",
|
|
|
|
"\n Dst sample count: ", dstDesc.SampleDesc.Count,
|
|
|
|
"\n Src sample count: ", srcDesc.SampleDesc.Count));
|
2018-01-28 18:06:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-14 00:45:07 +01:00
|
|
|
const D3D11CommonTexture* dstTextureInfo = GetCommonTexture(pDstResource);
|
|
|
|
const D3D11CommonTexture* srcTextureInfo = GetCommonTexture(pSrcResource);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
2018-04-12 17:49:14 +02:00
|
|
|
const DXGI_VK_FORMAT_INFO dstFormatInfo = m_parent->LookupFormat(dstDesc.Format, DXGI_VK_FORMAT_MODE_ANY);
|
|
|
|
const DXGI_VK_FORMAT_INFO srcFormatInfo = m_parent->LookupFormat(srcDesc.Format, DXGI_VK_FORMAT_MODE_ANY);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
2018-06-21 10:17:59 +02:00
|
|
|
auto dstVulkanFormatInfo = imageFormatInfo(dstFormatInfo.Format);
|
|
|
|
auto srcVulkanFormatInfo = imageFormatInfo(srcFormatInfo.Format);
|
|
|
|
|
2018-01-28 18:06:41 +01:00
|
|
|
const VkImageSubresource dstSubresource =
|
2018-03-14 00:45:07 +01:00
|
|
|
dstTextureInfo->GetSubresourceFromIndex(
|
2018-06-21 10:17:59 +02:00
|
|
|
dstVulkanFormatInfo->aspectMask, DstSubresource);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
|
|
|
const VkImageSubresource srcSubresource =
|
2018-03-14 00:45:07 +01:00
|
|
|
srcTextureInfo->GetSubresourceFromIndex(
|
2018-06-21 10:17:59 +02:00
|
|
|
srcVulkanFormatInfo->aspectMask, SrcSubresource);
|
2018-01-28 18:06:41 +01:00
|
|
|
|
2018-01-30 02:20:28 +01:00
|
|
|
const VkImageSubresourceLayers dstSubresourceLayers = {
|
|
|
|
dstSubresource.aspectMask,
|
|
|
|
dstSubresource.mipLevel,
|
|
|
|
dstSubresource.arrayLayer, 1 };
|
|
|
|
|
|
|
|
const VkImageSubresourceLayers srcSubresourceLayers = {
|
|
|
|
srcSubresource.aspectMask,
|
|
|
|
srcSubresource.mipLevel,
|
|
|
|
srcSubresource.arrayLayer, 1 };
|
|
|
|
|
2018-01-30 01:18:43 +01:00
|
|
|
if (srcDesc.SampleDesc.Count == 1) {
|
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = dstTextureInfo->GetImage(),
|
|
|
|
cSrcImage = srcTextureInfo->GetImage(),
|
2018-01-30 01:18:43 +01:00
|
|
|
cDstLayers = dstSubresourceLayers,
|
|
|
|
cSrcLayers = srcSubresourceLayers
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->copyImage(
|
|
|
|
cDstImage, cDstLayers, VkOffset3D { 0, 0, 0 },
|
|
|
|
cSrcImage, cSrcLayers, VkOffset3D { 0, 0, 0 },
|
|
|
|
cDstImage->mipLevelExtent(cDstLayers.mipLevel));
|
|
|
|
});
|
2018-02-20 22:26:23 +01:00
|
|
|
} else {
|
|
|
|
const VkFormat format = m_parent->LookupFormat(
|
2018-04-12 17:49:14 +02:00
|
|
|
Format, DXGI_VK_FORMAT_MODE_ANY).Format;
|
2018-01-28 18:06:41 +01:00
|
|
|
|
|
|
|
EmitCs([
|
2018-03-14 00:45:07 +01:00
|
|
|
cDstImage = dstTextureInfo->GetImage(),
|
|
|
|
cSrcImage = srcTextureInfo->GetImage(),
|
2018-01-28 18:06:41 +01:00
|
|
|
cDstSubres = dstSubresourceLayers,
|
2018-02-20 22:26:23 +01:00
|
|
|
cSrcSubres = srcSubresourceLayers,
|
|
|
|
cFormat = format
|
2018-01-28 18:06:41 +01:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->resolveImage(
|
|
|
|
cDstImage, cDstSubres,
|
2018-02-20 22:26:23 +01:00
|
|
|
cSrcImage, cSrcSubres,
|
|
|
|
cFormat);
|
2018-01-28 18:06:41 +01:00
|
|
|
});
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawAuto() {
|
2017-10-11 09:51:48 +02:00
|
|
|
Logger::err("D3D11DeviceContext::DrawAuto: Not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::Draw(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT VertexCount,
|
|
|
|
UINT StartVertexLocation) {
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->draw(
|
|
|
|
VertexCount, 1,
|
|
|
|
StartVertexLocation, 0);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawIndexed(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT IndexCount,
|
|
|
|
UINT StartIndexLocation,
|
|
|
|
INT BaseVertexLocation) {
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->drawIndexed(
|
|
|
|
IndexCount, 1,
|
|
|
|
StartIndexLocation,
|
|
|
|
BaseVertexLocation, 0);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawInstanced(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT VertexCountPerInstance,
|
|
|
|
UINT InstanceCount,
|
|
|
|
UINT StartVertexLocation,
|
|
|
|
UINT StartInstanceLocation) {
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->draw(
|
|
|
|
VertexCountPerInstance,
|
|
|
|
InstanceCount,
|
|
|
|
StartVertexLocation,
|
|
|
|
StartInstanceLocation);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawIndexedInstanced(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT IndexCountPerInstance,
|
|
|
|
UINT InstanceCount,
|
|
|
|
UINT StartIndexLocation,
|
|
|
|
INT BaseVertexLocation,
|
|
|
|
UINT StartInstanceLocation) {
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->drawIndexed(
|
|
|
|
IndexCountPerInstance,
|
|
|
|
InstanceCount,
|
|
|
|
StartIndexLocation,
|
|
|
|
BaseVertexLocation,
|
|
|
|
StartInstanceLocation);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawIndexedInstancedIndirect(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
UINT AlignedByteOffsetForArgs) {
|
2017-12-31 01:31:08 +01:00
|
|
|
D3D11Buffer* buffer = static_cast<D3D11Buffer*>(pBufferForArgs);
|
2017-12-31 00:25:19 +01:00
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([bufferSlice = buffer->GetBufferSlice(AlignedByteOffsetForArgs)]
|
|
|
|
(DxvkContext* ctx) {
|
|
|
|
ctx->drawIndexedIndirect(
|
|
|
|
bufferSlice, 1, 0);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DrawInstancedIndirect(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
UINT AlignedByteOffsetForArgs) {
|
2017-12-31 01:31:08 +01:00
|
|
|
D3D11Buffer* buffer = static_cast<D3D11Buffer*>(pBufferForArgs);
|
2017-12-31 00:25:19 +01:00
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([bufferSlice = buffer->GetBufferSlice(AlignedByteOffsetForArgs)]
|
|
|
|
(DxvkContext* ctx) {
|
|
|
|
ctx->drawIndirect(bufferSlice, 1, 0);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::Dispatch(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT ThreadGroupCountX,
|
|
|
|
UINT ThreadGroupCountY,
|
|
|
|
UINT ThreadGroupCountZ) {
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([=] (DxvkContext* ctx) {
|
|
|
|
ctx->dispatch(
|
|
|
|
ThreadGroupCountX,
|
|
|
|
ThreadGroupCountY,
|
|
|
|
ThreadGroupCountZ);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DispatchIndirect(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pBufferForArgs,
|
|
|
|
UINT AlignedByteOffsetForArgs) {
|
2017-12-31 01:31:08 +01:00
|
|
|
D3D11Buffer* buffer = static_cast<D3D11Buffer*>(pBufferForArgs);
|
2017-12-31 00:25:19 +01:00
|
|
|
|
2018-01-20 18:26:17 +01:00
|
|
|
EmitCs([bufferSlice = buffer->GetBufferSlice(AlignedByteOffsetForArgs)]
|
|
|
|
(DxvkContext* ctx) {
|
|
|
|
ctx->dispatchIndirect(bufferSlice);
|
|
|
|
});
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IASetInputLayout(ID3D11InputLayout* pInputLayout) {
|
2018-03-10 11:44:27 +01:00
|
|
|
auto inputLayout = static_cast<D3D11InputLayout*>(pInputLayout);
|
2017-12-07 12:45:02 +01:00
|
|
|
|
|
|
|
if (m_state.ia.inputLayout != inputLayout) {
|
2018-05-27 01:10:49 +02:00
|
|
|
bool equal = false;
|
|
|
|
|
|
|
|
// Some games (e.g. Grim Dawn) create lots and lots of
|
|
|
|
// identical input layouts, so we'll only apply the state
|
|
|
|
// if the input layouts has actually changed between calls.
|
|
|
|
if (m_state.ia.inputLayout != nullptr && inputLayout != nullptr)
|
|
|
|
equal = m_state.ia.inputLayout->Compare(inputLayout);
|
|
|
|
|
2017-12-07 12:45:02 +01:00
|
|
|
m_state.ia.inputLayout = inputLayout;
|
2018-05-27 01:10:49 +02:00
|
|
|
|
|
|
|
if (!equal)
|
|
|
|
ApplyInputLayout();
|
2017-12-07 12:45:02 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY Topology) {
|
2017-12-06 18:54:01 +01:00
|
|
|
if (m_state.ia.primitiveTopology != Topology) {
|
|
|
|
m_state.ia.primitiveTopology = Topology;
|
2018-03-10 11:44:27 +01:00
|
|
|
ApplyPrimitiveTopology();
|
2017-12-06 18:54:01 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IASetVertexBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppVertexBuffers,
|
|
|
|
const UINT* pStrides,
|
|
|
|
const UINT* pOffsets) {
|
2017-12-07 14:03:15 +01:00
|
|
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
2017-12-20 17:37:46 +01:00
|
|
|
auto newBuffer = static_cast<D3D11Buffer*>(ppVertexBuffers[i]);
|
2017-12-15 19:11:10 +01:00
|
|
|
|
2018-03-10 10:39:07 +01:00
|
|
|
m_state.ia.vertexBuffers[StartSlot + i].buffer = newBuffer;
|
|
|
|
m_state.ia.vertexBuffers[StartSlot + i].offset = pOffsets[i];
|
|
|
|
m_state.ia.vertexBuffers[StartSlot + i].stride = pStrides[i];
|
2017-12-09 15:57:05 +01:00
|
|
|
|
2018-03-10 10:39:07 +01:00
|
|
|
BindVertexBuffer(StartSlot + i, newBuffer, pOffsets[i], pStrides[i]);
|
2017-12-07 14:03:15 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IASetIndexBuffer(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11Buffer* pIndexBuffer,
|
|
|
|
DXGI_FORMAT Format,
|
|
|
|
UINT Offset) {
|
2017-12-20 17:37:46 +01:00
|
|
|
auto newBuffer = static_cast<D3D11Buffer*>(pIndexBuffer);
|
2017-12-08 01:51:49 +01:00
|
|
|
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.ia.indexBuffer.buffer = newBuffer;
|
|
|
|
m_state.ia.indexBuffer.offset = Offset;
|
|
|
|
m_state.ia.indexBuffer.format = Format;
|
2017-12-08 01:51:49 +01:00
|
|
|
|
2018-03-10 10:39:07 +01:00
|
|
|
BindIndexBuffer(newBuffer, Offset, Format);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IAGetInputLayout(ID3D11InputLayout** ppInputLayout) {
|
2017-12-07 12:45:02 +01:00
|
|
|
*ppInputLayout = m_state.ia.inputLayout.ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IAGetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY* pTopology) {
|
2017-12-06 18:54:01 +01:00
|
|
|
*pTopology = m_state.ia.primitiveTopology;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IAGetVertexBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppVertexBuffers,
|
|
|
|
UINT* pStrides,
|
|
|
|
UINT* pOffsets) {
|
2018-01-23 19:10:48 +01:00
|
|
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
|
|
|
if (ppVertexBuffers != nullptr)
|
|
|
|
ppVertexBuffers[i] = m_state.ia.vertexBuffers[StartSlot + i].buffer.ref();
|
|
|
|
|
|
|
|
if (pStrides != nullptr)
|
|
|
|
pStrides[i] = m_state.ia.vertexBuffers[StartSlot + i].stride;
|
|
|
|
|
|
|
|
if (pOffsets != nullptr)
|
|
|
|
pOffsets[i] = m_state.ia.vertexBuffers[StartSlot + i].offset;
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::IAGetIndexBuffer(
|
2018-01-23 19:10:48 +01:00
|
|
|
ID3D11Buffer** ppIndexBuffer,
|
|
|
|
DXGI_FORMAT* pFormat,
|
|
|
|
UINT* pOffset) {
|
|
|
|
if (ppIndexBuffer != nullptr)
|
|
|
|
*ppIndexBuffer = m_state.ia.indexBuffer.buffer.ref();
|
|
|
|
|
|
|
|
if (pFormat != nullptr)
|
|
|
|
*pFormat = m_state.ia.indexBuffer.format;
|
|
|
|
|
|
|
|
if (pOffset != nullptr)
|
|
|
|
*pOffset = m_state.ia.indexBuffer.offset;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSSetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11VertexShader* pVertexShader,
|
|
|
|
ID3D11ClassInstance* const* ppClassInstances,
|
|
|
|
UINT NumClassInstances) {
|
2017-12-07 10:12:48 +01:00
|
|
|
auto shader = static_cast<D3D11VertexShader*>(pVertexShader);
|
|
|
|
|
|
|
|
if (NumClassInstances != 0)
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err("D3D11: Class instances not supported");
|
2017-12-07 10:12:48 +01:00
|
|
|
|
|
|
|
if (m_state.vs.shader != shader) {
|
|
|
|
m_state.vs.shader = shader;
|
2018-07-30 19:34:48 +02:00
|
|
|
|
|
|
|
BindShader(
|
|
|
|
DxbcProgramType::VertexShader,
|
|
|
|
GetCommonShader(shader));
|
2017-12-07 10:12:48 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSSetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2017-12-08 22:30:41 +01:00
|
|
|
DxbcProgramType::VertexShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.vs.constantBuffers,
|
2017-12-08 19:39:33 +01:00
|
|
|
StartSlot, NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSSetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2018-03-18 12:39:11 +01:00
|
|
|
DxbcProgramType::VertexShader,
|
|
|
|
m_state.vs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSSetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetShaderResources(
|
2017-12-10 01:56:07 +01:00
|
|
|
DxbcProgramType::VertexShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.vs.shaderResources,
|
2017-12-10 01:56:07 +01:00
|
|
|
StartSlot, NumViews,
|
|
|
|
ppShaderResourceViews);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSSetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetSamplers(
|
2017-12-09 21:17:26 +01:00
|
|
|
DxbcProgramType::VertexShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.vs.samplers,
|
2017-12-09 21:17:26 +01:00
|
|
|
StartSlot, NumSamplers,
|
|
|
|
ppSamplers);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSGetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11VertexShader** ppVertexShader,
|
|
|
|
ID3D11ClassInstance** ppClassInstances,
|
|
|
|
UINT* pNumClassInstances) {
|
2017-12-11 14:21:24 +01:00
|
|
|
if (ppVertexShader != nullptr)
|
|
|
|
*ppVertexShader = m_state.vs.shader.ref();
|
|
|
|
|
2018-01-17 23:49:26 +01:00
|
|
|
if (pNumClassInstances != nullptr)
|
2017-12-11 14:21:24 +01:00
|
|
|
*pNumClassInstances = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSGetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.vs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSGetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.vs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSGetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumViews; i++)
|
|
|
|
ppShaderResourceViews[i] = m_state.vs.shaderResources.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::VSGetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState** ppSamplers) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++)
|
|
|
|
ppSamplers[i] = m_state.vs.samplers.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSSetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11HullShader* pHullShader,
|
|
|
|
ID3D11ClassInstance* const* ppClassInstances,
|
|
|
|
UINT NumClassInstances) {
|
2018-02-26 17:29:10 +01:00
|
|
|
auto shader = static_cast<D3D11HullShader*>(pHullShader);
|
|
|
|
|
|
|
|
if (NumClassInstances != 0)
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err("D3D11: Class instances not supported");
|
2018-02-26 17:29:10 +01:00
|
|
|
|
|
|
|
if (m_state.hs.shader != shader) {
|
|
|
|
m_state.hs.shader = shader;
|
2018-07-30 19:34:48 +02:00
|
|
|
|
|
|
|
BindShader(
|
|
|
|
DxbcProgramType::HullShader,
|
|
|
|
GetCommonShader(shader));
|
2018-02-26 17:29:10 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSSetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetShaderResources(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::HullShader,
|
|
|
|
m_state.hs.shaderResources,
|
|
|
|
StartSlot, NumViews,
|
|
|
|
ppShaderResourceViews);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSSetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::HullShader,
|
|
|
|
m_state.hs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSSetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2018-03-18 12:39:11 +01:00
|
|
|
DxbcProgramType::HullShader,
|
2018-03-18 12:45:27 +01:00
|
|
|
m_state.hs.constantBuffers,
|
2018-03-18 12:39:11 +01:00
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSSetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetSamplers(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::HullShader,
|
|
|
|
m_state.hs.samplers,
|
|
|
|
StartSlot, NumSamplers,
|
|
|
|
ppSamplers);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSGetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11HullShader** ppHullShader,
|
|
|
|
ID3D11ClassInstance** ppClassInstances,
|
|
|
|
UINT* pNumClassInstances) {
|
2017-12-20 17:37:46 +01:00
|
|
|
if (ppHullShader != nullptr)
|
|
|
|
*ppHullShader = m_state.hs.shader.ref();
|
|
|
|
|
2018-01-17 23:49:26 +01:00
|
|
|
if (pNumClassInstances != nullptr)
|
2017-12-20 17:37:46 +01:00
|
|
|
*pNumClassInstances = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSGetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.hs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::HSGetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.hs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSGetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumViews; i++)
|
|
|
|
ppShaderResourceViews[i] = m_state.hs.shaderResources.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::HSGetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState** ppSamplers) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++)
|
|
|
|
ppSamplers[i] = m_state.hs.samplers.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSSetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11DomainShader* pDomainShader,
|
|
|
|
ID3D11ClassInstance* const* ppClassInstances,
|
|
|
|
UINT NumClassInstances) {
|
2018-02-26 17:29:10 +01:00
|
|
|
auto shader = static_cast<D3D11DomainShader*>(pDomainShader);
|
|
|
|
|
|
|
|
if (NumClassInstances != 0)
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err("D3D11: Class instances not supported");
|
2018-02-26 17:29:10 +01:00
|
|
|
|
|
|
|
if (m_state.ds.shader != shader) {
|
|
|
|
m_state.ds.shader = shader;
|
2018-07-30 19:34:48 +02:00
|
|
|
|
|
|
|
BindShader(
|
|
|
|
DxbcProgramType::DomainShader,
|
|
|
|
GetCommonShader(shader));
|
2018-02-26 17:29:10 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSSetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetShaderResources(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::DomainShader,
|
|
|
|
m_state.ds.shaderResources,
|
|
|
|
StartSlot, NumViews,
|
|
|
|
ppShaderResourceViews);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSSetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::DomainShader,
|
|
|
|
m_state.ds.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSSetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2018-03-18 12:39:11 +01:00
|
|
|
DxbcProgramType::DomainShader,
|
2018-03-18 12:45:27 +01:00
|
|
|
m_state.ds.constantBuffers,
|
2018-03-18 12:39:11 +01:00
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSSetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetSamplers(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::DomainShader,
|
|
|
|
m_state.ds.samplers,
|
|
|
|
StartSlot, NumSamplers,
|
|
|
|
ppSamplers);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSGetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11DomainShader** ppDomainShader,
|
|
|
|
ID3D11ClassInstance** ppClassInstances,
|
|
|
|
UINT* pNumClassInstances) {
|
2017-12-20 17:37:46 +01:00
|
|
|
if (ppDomainShader != nullptr)
|
|
|
|
*ppDomainShader = m_state.ds.shader.ref();
|
|
|
|
|
2018-01-17 23:49:26 +01:00
|
|
|
if (pNumClassInstances != nullptr)
|
2017-12-20 17:37:46 +01:00
|
|
|
*pNumClassInstances = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSGetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.ds.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 18:54:09 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSGetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.ds.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSGetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumViews; i++)
|
|
|
|
ppShaderResourceViews[i] = m_state.ds.shaderResources.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::DSGetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState** ppSamplers) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++)
|
|
|
|
ppSamplers[i] = m_state.ds.samplers.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSSetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11GeometryShader* pShader,
|
|
|
|
ID3D11ClassInstance* const* ppClassInstances,
|
|
|
|
UINT NumClassInstances) {
|
2017-12-18 12:53:53 +01:00
|
|
|
auto shader = static_cast<D3D11GeometryShader*>(pShader);
|
|
|
|
|
|
|
|
if (NumClassInstances != 0)
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err("D3D11: Class instances not supported");
|
2017-12-18 12:53:53 +01:00
|
|
|
|
|
|
|
if (m_state.gs.shader != shader) {
|
|
|
|
m_state.gs.shader = shader;
|
2018-07-30 19:34:48 +02:00
|
|
|
|
|
|
|
BindShader(
|
|
|
|
DxbcProgramType::GeometryShader,
|
|
|
|
GetCommonShader(shader));
|
2017-12-18 12:53:53 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSSetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2017-12-18 12:53:53 +01:00
|
|
|
DxbcProgramType::GeometryShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.gs.constantBuffers,
|
2017-12-18 12:53:53 +01:00
|
|
|
StartSlot, NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::GSSetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2018-03-18 12:39:11 +01:00
|
|
|
DxbcProgramType::GeometryShader,
|
2018-03-18 12:45:27 +01:00
|
|
|
m_state.gs.constantBuffers,
|
2018-03-18 12:39:11 +01:00
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSSetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetShaderResources(
|
2017-12-18 12:53:53 +01:00
|
|
|
DxbcProgramType::GeometryShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.gs.shaderResources,
|
2017-12-18 12:53:53 +01:00
|
|
|
StartSlot, NumViews,
|
|
|
|
ppShaderResourceViews);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSSetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetSamplers(
|
2017-12-18 12:53:53 +01:00
|
|
|
DxbcProgramType::GeometryShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.gs.samplers,
|
2017-12-18 12:53:53 +01:00
|
|
|
StartSlot, NumSamplers,
|
|
|
|
ppSamplers);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSGetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11GeometryShader** ppGeometryShader,
|
|
|
|
ID3D11ClassInstance** ppClassInstances,
|
|
|
|
UINT* pNumClassInstances) {
|
2017-12-18 12:53:53 +01:00
|
|
|
if (ppGeometryShader != nullptr)
|
|
|
|
*ppGeometryShader = m_state.gs.shader.ref();
|
|
|
|
|
2018-01-17 23:49:26 +01:00
|
|
|
if (pNumClassInstances != nullptr)
|
2017-12-18 12:53:53 +01:00
|
|
|
*pNumClassInstances = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSGetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.gs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::GSGetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.gs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSGetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
2017-12-18 12:53:53 +01:00
|
|
|
for (uint32_t i = 0; i < NumViews; i++)
|
|
|
|
ppShaderResourceViews[i] = m_state.gs.shaderResources.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::GSGetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState** ppSamplers) {
|
2017-12-18 12:53:53 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++)
|
|
|
|
ppSamplers[i] = m_state.gs.samplers.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSSetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11PixelShader* pPixelShader,
|
|
|
|
ID3D11ClassInstance* const* ppClassInstances,
|
|
|
|
UINT NumClassInstances) {
|
2017-12-07 10:12:48 +01:00
|
|
|
auto shader = static_cast<D3D11PixelShader*>(pPixelShader);
|
|
|
|
|
|
|
|
if (NumClassInstances != 0)
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err("D3D11: Class instances not supported");
|
2017-12-07 10:12:48 +01:00
|
|
|
|
|
|
|
if (m_state.ps.shader != shader) {
|
|
|
|
m_state.ps.shader = shader;
|
2018-07-30 19:34:48 +02:00
|
|
|
|
|
|
|
BindShader(
|
|
|
|
DxbcProgramType::PixelShader,
|
|
|
|
GetCommonShader(shader));
|
2017-12-07 10:12:48 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSSetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2017-12-08 22:30:41 +01:00
|
|
|
DxbcProgramType::PixelShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.ps.constantBuffers,
|
2017-12-08 19:39:33 +01:00
|
|
|
StartSlot, NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::PSSetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2018-03-18 12:39:11 +01:00
|
|
|
DxbcProgramType::PixelShader,
|
2018-03-18 12:45:27 +01:00
|
|
|
m_state.ps.constantBuffers,
|
2018-03-18 12:39:11 +01:00
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSSetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetShaderResources(
|
2017-12-10 01:56:07 +01:00
|
|
|
DxbcProgramType::PixelShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.ps.shaderResources,
|
2017-12-10 01:56:07 +01:00
|
|
|
StartSlot, NumViews,
|
|
|
|
ppShaderResourceViews);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSSetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetSamplers(
|
2017-12-09 21:17:26 +01:00
|
|
|
DxbcProgramType::PixelShader,
|
2017-12-20 17:37:46 +01:00
|
|
|
m_state.ps.samplers,
|
2017-12-09 21:17:26 +01:00
|
|
|
StartSlot, NumSamplers,
|
|
|
|
ppSamplers);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSGetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11PixelShader** ppPixelShader,
|
|
|
|
ID3D11ClassInstance** ppClassInstances,
|
|
|
|
UINT* pNumClassInstances) {
|
2017-12-11 14:21:24 +01:00
|
|
|
if (ppPixelShader != nullptr)
|
|
|
|
*ppPixelShader = m_state.ps.shader.ref();
|
|
|
|
|
2018-01-17 23:49:26 +01:00
|
|
|
if (pNumClassInstances != nullptr)
|
2017-12-11 14:21:24 +01:00
|
|
|
*pNumClassInstances = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSGetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.ps.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::PSGetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.ps.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSGetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
2017-12-11 14:21:24 +01:00
|
|
|
for (uint32_t i = 0; i < NumViews; i++)
|
|
|
|
ppShaderResourceViews[i] = m_state.ps.shaderResources.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::PSGetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState** ppSamplers) {
|
2017-12-11 14:21:24 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++)
|
|
|
|
ppSamplers[i] = m_state.ps.samplers.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSSetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11ComputeShader* pComputeShader,
|
|
|
|
ID3D11ClassInstance* const* ppClassInstances,
|
|
|
|
UINT NumClassInstances) {
|
2017-12-21 17:27:40 +01:00
|
|
|
auto shader = static_cast<D3D11ComputeShader*>(pComputeShader);
|
|
|
|
|
|
|
|
if (NumClassInstances != 0)
|
2018-04-14 11:45:31 +02:00
|
|
|
Logger::err("D3D11: Class instances not supported");
|
2017-12-21 17:27:40 +01:00
|
|
|
|
|
|
|
if (m_state.cs.shader != shader) {
|
|
|
|
m_state.cs.shader = shader;
|
2018-07-30 19:34:48 +02:00
|
|
|
|
|
|
|
BindShader(
|
|
|
|
DxbcProgramType::ComputeShader,
|
|
|
|
GetCommonShader(shader));
|
2017-12-21 17:27:40 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSSetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::ComputeShader,
|
|
|
|
m_state.cs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSSetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetConstantBuffers(
|
2018-03-18 12:39:11 +01:00
|
|
|
DxbcProgramType::ComputeShader,
|
2018-03-18 12:45:27 +01:00
|
|
|
m_state.cs.constantBuffers,
|
2018-03-18 12:39:11 +01:00
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSSetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView* const* ppShaderResourceViews) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetShaderResources(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::ComputeShader,
|
|
|
|
m_state.cs.shaderResources,
|
|
|
|
StartSlot, NumViews,
|
|
|
|
ppShaderResourceViews);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSSetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetSamplers(
|
2017-12-20 17:37:46 +01:00
|
|
|
DxbcProgramType::ComputeShader,
|
|
|
|
m_state.cs.samplers,
|
|
|
|
StartSlot, NumSamplers,
|
|
|
|
ppSamplers);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSSetUnorderedAccessViews(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView* const* ppUnorderedAccessViews,
|
|
|
|
const UINT* pUAVInitialCounts) {
|
2018-03-18 12:57:39 +01:00
|
|
|
SetUnorderedAccessViews(
|
2017-12-28 19:05:53 +01:00
|
|
|
DxbcProgramType::ComputeShader,
|
|
|
|
m_state.cs.unorderedAccessViews,
|
|
|
|
StartSlot, NumUAVs,
|
|
|
|
ppUnorderedAccessViews);
|
2018-01-11 12:23:55 +01:00
|
|
|
|
|
|
|
if (pUAVInitialCounts != nullptr) {
|
2018-03-18 12:57:39 +01:00
|
|
|
InitUnorderedAccessViewCounters(
|
2018-01-11 12:23:55 +01:00
|
|
|
NumUAVs, ppUnorderedAccessViews,
|
|
|
|
pUAVInitialCounts);
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSGetShader(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11ComputeShader** ppComputeShader,
|
|
|
|
ID3D11ClassInstance** ppClassInstances,
|
|
|
|
UINT* pNumClassInstances) {
|
2017-12-20 17:37:46 +01:00
|
|
|
if (ppComputeShader != nullptr)
|
|
|
|
*ppComputeShader = m_state.cs.shader.ref();
|
|
|
|
|
2018-01-17 23:49:26 +01:00
|
|
|
if (pNumClassInstances != nullptr)
|
2017-12-20 17:37:46 +01:00
|
|
|
*pNumClassInstances = 0;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSGetConstantBuffers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.cs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
nullptr, nullptr);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
2018-03-17 18:54:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSGetConstantBuffers1(
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
2018-03-18 12:45:27 +01:00
|
|
|
GetConstantBuffers(
|
|
|
|
m_state.cs.constantBuffers,
|
|
|
|
StartSlot, NumBuffers,
|
|
|
|
ppConstantBuffers,
|
|
|
|
pFirstConstant,
|
|
|
|
pNumConstants);
|
2018-03-17 18:54:09 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSGetShaderResources(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11ShaderResourceView** ppShaderResourceViews) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumViews; i++)
|
|
|
|
ppShaderResourceViews[i] = m_state.cs.shaderResources.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSGetSamplers(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState** ppSamplers) {
|
2017-12-20 17:37:46 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++)
|
|
|
|
ppSamplers[i] = m_state.cs.samplers.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::CSGetUnorderedAccessViews(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView** ppUnorderedAccessViews) {
|
2018-03-01 07:02:39 +01:00
|
|
|
for (uint32_t i = 0; i < NumUAVs; i++)
|
|
|
|
ppUnorderedAccessViews[i] = m_state.cs.unorderedAccessViews.at(StartSlot + i).ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMSetRenderTargets(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumViews,
|
|
|
|
ID3D11RenderTargetView* const* ppRenderTargetViews,
|
|
|
|
ID3D11DepthStencilView* pDepthStencilView) {
|
2018-06-15 20:49:24 +02:00
|
|
|
SetRenderTargets(NumViews, ppRenderTargetViews, pDepthStencilView);
|
|
|
|
BindFramebuffer(std::exchange(m_state.om.isUavRendering, false));
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumRTVs,
|
|
|
|
ID3D11RenderTargetView* const* ppRenderTargetViews,
|
|
|
|
ID3D11DepthStencilView* pDepthStencilView,
|
|
|
|
UINT UAVStartSlot,
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView* const* ppUnorderedAccessViews,
|
2017-11-29 20:19:40 +01:00
|
|
|
const UINT* pUAVInitialCounts) {
|
2018-06-15 20:49:24 +02:00
|
|
|
bool spillOnBind = m_state.om.isUavRendering;
|
|
|
|
|
2018-01-12 15:38:07 +01:00
|
|
|
if (NumRTVs != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
|
2018-06-15 20:49:24 +02:00
|
|
|
SetRenderTargets(NumRTVs, ppRenderTargetViews, pDepthStencilView);
|
2018-01-12 15:38:07 +01:00
|
|
|
|
|
|
|
if (NumUAVs != D3D11_KEEP_UNORDERED_ACCESS_VIEWS) {
|
2018-06-15 20:49:24 +02:00
|
|
|
// Check whether there actually are any UAVs bound
|
|
|
|
m_state.om.isUavRendering = false;
|
2018-06-10 04:19:30 +02:00
|
|
|
|
2018-06-15 20:49:24 +02:00
|
|
|
for (uint32_t i = 0; i < NumUAVs && !m_state.om.isUavRendering; i++)
|
|
|
|
m_state.om.isUavRendering = ppUnorderedAccessViews[i] != nullptr;
|
2018-06-08 12:42:09 +02:00
|
|
|
|
2018-01-12 15:38:07 +01:00
|
|
|
// UAVs are made available to all shader stages in
|
|
|
|
// the graphics pipeline even though this code may
|
|
|
|
// suggest that they are limited to the pixel shader.
|
|
|
|
// This behaviour is only required for FL_11_1.
|
2018-03-10 11:16:52 +01:00
|
|
|
SetUnorderedAccessViews(
|
2018-01-12 15:38:07 +01:00
|
|
|
DxbcProgramType::PixelShader,
|
|
|
|
m_state.ps.unorderedAccessViews,
|
|
|
|
UAVStartSlot, NumUAVs,
|
|
|
|
ppUnorderedAccessViews);
|
|
|
|
|
|
|
|
if (pUAVInitialCounts != nullptr) {
|
|
|
|
InitUnorderedAccessViewCounters(NumUAVs,
|
|
|
|
ppUnorderedAccessViews, pUAVInitialCounts);
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 20:49:24 +02:00
|
|
|
|
|
|
|
BindFramebuffer(spillOnBind);
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMSetBlendState(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11BlendState* pBlendState,
|
|
|
|
const FLOAT BlendFactor[4],
|
|
|
|
UINT SampleMask) {
|
2018-03-10 12:11:17 +01:00
|
|
|
auto blendState = static_cast<D3D11BlendState*>(pBlendState);
|
2017-12-11 14:11:18 +01:00
|
|
|
|
|
|
|
if (m_state.om.cbState != blendState
|
|
|
|
|| m_state.om.sampleMask != SampleMask) {
|
|
|
|
m_state.om.cbState = blendState;
|
|
|
|
m_state.om.sampleMask = SampleMask;
|
|
|
|
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyBlendState();
|
2017-12-11 14:11:18 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 15:41:06 +01:00
|
|
|
if (BlendFactor != nullptr) {
|
2018-03-10 11:56:58 +01:00
|
|
|
for (uint32_t i = 0; i < 4; i++)
|
2018-01-20 19:11:42 +01:00
|
|
|
m_state.om.blendFactor[i] = BlendFactor[i];
|
|
|
|
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyBlendFactor();
|
2017-12-11 14:11:18 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMSetDepthStencilState(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11DepthStencilState* pDepthStencilState,
|
|
|
|
UINT StencilRef) {
|
2018-03-10 12:11:17 +01:00
|
|
|
auto depthStencilState = static_cast<D3D11DepthStencilState*>(pDepthStencilState);
|
2017-12-11 14:11:18 +01:00
|
|
|
|
|
|
|
if (m_state.om.dsState != depthStencilState) {
|
|
|
|
m_state.om.dsState = depthStencilState;
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyDepthStencilState();
|
2017-12-11 14:11:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_state.om.stencilRef != StencilRef) {
|
|
|
|
m_state.om.stencilRef = StencilRef;
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyStencilRef();
|
2017-12-11 14:11:18 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMGetRenderTargets(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumViews,
|
|
|
|
ID3D11RenderTargetView** ppRenderTargetViews,
|
|
|
|
ID3D11DepthStencilView** ppDepthStencilView) {
|
2017-11-29 20:19:40 +01:00
|
|
|
if (ppRenderTargetViews != nullptr) {
|
|
|
|
for (UINT i = 0; i < NumViews; i++)
|
2018-03-09 16:47:20 +01:00
|
|
|
ppRenderTargetViews[i] = m_state.om.renderTargetViews[i].ref();
|
2017-11-29 20:19:40 +01:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:14:11 +01:00
|
|
|
if (ppDepthStencilView != nullptr)
|
|
|
|
*ppDepthStencilView = m_state.om.depthStencilView.ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMGetRenderTargetsAndUnorderedAccessViews(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumRTVs,
|
|
|
|
ID3D11RenderTargetView** ppRenderTargetViews,
|
|
|
|
ID3D11DepthStencilView** ppDepthStencilView,
|
|
|
|
UINT UAVStartSlot,
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView** ppUnorderedAccessViews) {
|
2018-03-09 16:47:20 +01:00
|
|
|
OMGetRenderTargets(NumRTVs, ppRenderTargetViews, ppDepthStencilView);
|
|
|
|
|
|
|
|
if (ppUnorderedAccessViews != nullptr) {
|
|
|
|
for (UINT i = 0; i < NumUAVs; i++)
|
|
|
|
ppUnorderedAccessViews[i] = m_state.ps.unorderedAccessViews[UAVStartSlot + i].ref();
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMGetBlendState(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11BlendState** ppBlendState,
|
|
|
|
FLOAT BlendFactor[4],
|
|
|
|
UINT* pSampleMask) {
|
2017-12-11 14:21:24 +01:00
|
|
|
if (ppBlendState != nullptr)
|
|
|
|
*ppBlendState = m_state.om.cbState.ref();
|
|
|
|
|
|
|
|
if (BlendFactor != nullptr)
|
|
|
|
std::memcpy(BlendFactor, m_state.om.blendFactor, sizeof(FLOAT) * 4);
|
|
|
|
|
|
|
|
if (pSampleMask != nullptr)
|
|
|
|
*pSampleMask = m_state.om.sampleMask;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::OMGetDepthStencilState(
|
2017-10-11 09:51:48 +02:00
|
|
|
ID3D11DepthStencilState** ppDepthStencilState,
|
|
|
|
UINT* pStencilRef) {
|
2017-12-11 14:21:24 +01:00
|
|
|
if (ppDepthStencilState != nullptr)
|
|
|
|
*ppDepthStencilState = m_state.om.dsState.ref();
|
|
|
|
|
|
|
|
if (pStencilRef != nullptr)
|
|
|
|
*pStencilRef = m_state.om.stencilRef;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::RSSetState(ID3D11RasterizerState* pRasterizerState) {
|
2018-03-10 12:11:17 +01:00
|
|
|
auto rasterizerState = static_cast<D3D11RasterizerState*>(pRasterizerState);
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2017-12-06 13:16:54 +01:00
|
|
|
if (m_state.rs.state != rasterizerState) {
|
|
|
|
m_state.rs.state = rasterizerState;
|
|
|
|
|
2018-03-10 11:56:58 +01:00
|
|
|
// In D3D11, the rasterizer state defines whether the
|
|
|
|
// scissor test is enabled, so we have to update the
|
|
|
|
// scissor rectangles as well.
|
|
|
|
ApplyRasterizerState();
|
|
|
|
ApplyViewportState();
|
2017-12-06 13:16:54 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::RSSetViewports(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumViewports,
|
|
|
|
const D3D11_VIEWPORT* pViewports) {
|
2017-12-06 12:11:59 +01:00
|
|
|
m_state.rs.numViewports = NumViewports;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < NumViewports; i++)
|
|
|
|
m_state.rs.viewports.at(i) = pViewports[i];
|
|
|
|
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyViewportState();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::RSSetScissorRects(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumRects,
|
|
|
|
const D3D11_RECT* pRects) {
|
2017-12-06 12:11:59 +01:00
|
|
|
m_state.rs.numScissors = NumRects;
|
|
|
|
|
2018-05-25 00:08:28 +02:00
|
|
|
for (uint32_t i = 0; i < NumRects; i++) {
|
|
|
|
if (pRects[i].bottom >= pRects[i].top
|
|
|
|
&& pRects[i].right >= pRects[i].left)
|
|
|
|
m_state.rs.scissors.at(i) = pRects[i];
|
|
|
|
}
|
2017-12-06 12:11:59 +01:00
|
|
|
|
|
|
|
if (m_state.rs.state != nullptr) {
|
|
|
|
D3D11_RASTERIZER_DESC rsDesc;
|
|
|
|
m_state.rs.state->GetDesc(&rsDesc);
|
|
|
|
|
|
|
|
if (rsDesc.ScissorEnable)
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyViewportState();
|
2017-12-06 12:11:59 +01:00
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::RSGetState(ID3D11RasterizerState** ppRasterizerState) {
|
2017-12-11 14:21:24 +01:00
|
|
|
if (ppRasterizerState != nullptr)
|
|
|
|
*ppRasterizerState = m_state.rs.state.ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::RSGetViewports(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT* pNumViewports,
|
|
|
|
D3D11_VIEWPORT* pViewports) {
|
2017-12-06 12:11:59 +01:00
|
|
|
if (pViewports != nullptr) {
|
|
|
|
for (uint32_t i = 0; i < *pNumViewports; i++) {
|
|
|
|
if (i < m_state.rs.numViewports) {
|
|
|
|
pViewports[i] = m_state.rs.viewports.at(i);
|
|
|
|
} else {
|
|
|
|
pViewports[i].TopLeftX = 0.0f;
|
|
|
|
pViewports[i].TopLeftY = 0.0f;
|
|
|
|
pViewports[i].Width = 0.0f;
|
|
|
|
pViewports[i].Height = 0.0f;
|
|
|
|
pViewports[i].MinDepth = 0.0f;
|
|
|
|
pViewports[i].MaxDepth = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pNumViewports = m_state.rs.numViewports;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::RSGetScissorRects(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT* pNumRects,
|
|
|
|
D3D11_RECT* pRects) {
|
2017-12-06 12:11:59 +01:00
|
|
|
if (pRects != nullptr) {
|
|
|
|
for (uint32_t i = 0; i < *pNumRects; i++) {
|
|
|
|
if (i < m_state.rs.numScissors) {
|
|
|
|
pRects[i] = m_state.rs.scissors.at(i);
|
|
|
|
} else {
|
|
|
|
pRects[i].left = 0;
|
|
|
|
pRects[i].top = 0;
|
|
|
|
pRects[i].right = 0;
|
|
|
|
pRects[i].bottom = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pNumRects = m_state.rs.numScissors;
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SOSetTargets(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer* const* ppSOTargets,
|
|
|
|
const UINT* pOffsets) {
|
2018-03-07 15:32:19 +01:00
|
|
|
// TODO implement properly, including pOffsets
|
|
|
|
for (uint32_t i = 0; i < D3D11_SO_STREAM_COUNT; i++) {
|
|
|
|
m_state.so.targets[i] = (ppSOTargets != nullptr && i < NumBuffers)
|
|
|
|
? static_cast<D3D11Buffer*>(ppSOTargets[i])
|
|
|
|
: nullptr;
|
|
|
|
}
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::SOGetTargets(
|
2017-10-11 09:51:48 +02:00
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppSOTargets) {
|
2018-03-07 15:32:19 +01:00
|
|
|
for (uint32_t i = 0; i < NumBuffers; i++)
|
|
|
|
ppSOTargets[i] = m_state.so.targets[i].ref();
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|
|
|
|
|
2017-12-06 12:11:59 +01:00
|
|
|
|
2018-04-20 00:19:03 +02:00
|
|
|
void STDMETHODCALLTYPE D3D11DeviceContext::TransitionSurfaceLayout(
|
|
|
|
IDXGIVkInteropSurface* pSurface,
|
|
|
|
const VkImageSubresourceRange* pSubresources,
|
|
|
|
VkImageLayout OldLayout,
|
|
|
|
VkImageLayout NewLayout) {
|
|
|
|
// Get the underlying D3D11 resource
|
|
|
|
Com<ID3D11Resource> resource;
|
|
|
|
|
|
|
|
pSurface->QueryInterface(__uuidof(ID3D11Resource),
|
|
|
|
reinterpret_cast<void**>(&resource));
|
|
|
|
|
|
|
|
// Get the texture from that resource
|
|
|
|
D3D11CommonTexture* texture = GetCommonTexture(resource.ptr());
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cImage = texture->GetImage(),
|
|
|
|
cSubresources = *pSubresources,
|
|
|
|
cOldLayout = OldLayout,
|
|
|
|
cNewLayout = NewLayout
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->transformImage(
|
|
|
|
cImage, cSubresources,
|
|
|
|
cOldLayout, cNewLayout);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
void D3D11DeviceContext::ApplyInputLayout() {
|
|
|
|
if (m_state.ia.inputLayout != nullptr) {
|
|
|
|
EmitCs([cInputLayout = m_state.ia.inputLayout] (DxvkContext* ctx) {
|
|
|
|
cInputLayout->BindToContext(ctx);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EmitCs([] (DxvkContext* ctx) {
|
|
|
|
ctx->setInputLayout(0, nullptr, 0, nullptr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyPrimitiveTopology() {
|
|
|
|
if (m_state.ia.primitiveTopology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const DxvkInputAssemblyState iaState =
|
|
|
|
[Topology = m_state.ia.primitiveTopology] () -> DxvkInputAssemblyState {
|
|
|
|
if (Topology >= D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST
|
|
|
|
&& Topology <= D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST) {
|
|
|
|
// Tessellation patch. The number of control points per
|
|
|
|
// patch can be inferred from the enum value in D3D11.
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE,
|
|
|
|
uint32_t(Topology - D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST + 1) };
|
|
|
|
} else {
|
|
|
|
switch (Topology) {
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_POINTLIST:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_POINT_LIST, VK_FALSE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_LINELIST:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_LINE_LIST, VK_FALSE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_LINE_STRIP, VK_TRUE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_FALSE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, VK_TRUE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY, VK_FALSE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY, VK_TRUE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY, VK_FALSE, 0 };
|
|
|
|
|
|
|
|
case D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ:
|
|
|
|
return { VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY, VK_TRUE, 0 };
|
|
|
|
|
|
|
|
default:
|
|
|
|
Logger::err(str::format("D3D11: Invalid primitive topology: ", Topology));
|
|
|
|
return { };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
EmitCs([iaState] (DxvkContext* ctx) {
|
|
|
|
ctx->setInputAssemblyState(iaState);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:56:58 +01:00
|
|
|
void D3D11DeviceContext::ApplyBlendState() {
|
|
|
|
EmitCs([
|
|
|
|
cBlendState = m_state.om.cbState != nullptr
|
|
|
|
? m_state.om.cbState
|
|
|
|
: m_defaultBlendState,
|
|
|
|
cSampleMask = m_state.om.sampleMask
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
cBlendState->BindToContext(ctx, cSampleMask);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyBlendFactor() {
|
|
|
|
EmitCs([
|
|
|
|
cBlendConstants = DxvkBlendConstants {
|
|
|
|
m_state.om.blendFactor[0], m_state.om.blendFactor[1],
|
|
|
|
m_state.om.blendFactor[2], m_state.om.blendFactor[3] }
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setBlendConstants(cBlendConstants);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyDepthStencilState() {
|
|
|
|
EmitCs([
|
|
|
|
cDepthStencilState = m_state.om.dsState != nullptr
|
|
|
|
? m_state.om.dsState
|
|
|
|
: m_defaultDepthStencilState
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
cDepthStencilState->BindToContext(ctx);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyStencilRef() {
|
|
|
|
EmitCs([
|
|
|
|
cStencilRef = m_state.om.stencilRef
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setStencilReference(cStencilRef);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::ApplyRasterizerState() {
|
|
|
|
EmitCs([
|
|
|
|
cRasterizerState = m_state.rs.state != nullptr
|
|
|
|
? m_state.rs.state
|
|
|
|
: m_defaultRasterizerState
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
cRasterizerState->BindToContext(ctx);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
void D3D11DeviceContext::ApplyViewportState() {
|
|
|
|
// We cannot set less than one viewport in Vulkan, and
|
|
|
|
// rendering with no active viewport is illegal anyway.
|
|
|
|
if (m_state.rs.numViewports == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::array<VkViewport, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE> viewports;
|
|
|
|
std::array<VkRect2D, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE> scissors;
|
|
|
|
|
|
|
|
// D3D11's coordinate system has its origin in the bottom left,
|
|
|
|
// but the viewport coordinates are aligned to the top-left
|
|
|
|
// corner so we can get away with flipping the viewport.
|
|
|
|
for (uint32_t i = 0; i < m_state.rs.numViewports; i++) {
|
|
|
|
const D3D11_VIEWPORT& vp = m_state.rs.viewports.at(i);
|
|
|
|
|
|
|
|
viewports.at(i) = VkViewport {
|
|
|
|
vp.TopLeftX, vp.Height + vp.TopLeftY,
|
|
|
|
vp.Width, -vp.Height,
|
|
|
|
vp.MinDepth, vp.MaxDepth,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scissor rectangles. Vulkan does not provide an easy way
|
|
|
|
// to disable the scissor test, so we'll have to set scissor
|
|
|
|
// rects that are at least as large as the framebuffer.
|
|
|
|
bool enableScissorTest = false;
|
|
|
|
|
|
|
|
if (m_state.rs.state != nullptr) {
|
|
|
|
D3D11_RASTERIZER_DESC rsDesc;
|
|
|
|
m_state.rs.state->GetDesc(&rsDesc);
|
|
|
|
enableScissorTest = rsDesc.ScissorEnable;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < m_state.rs.numViewports; i++) {
|
|
|
|
if (enableScissorTest && (i < m_state.rs.numScissors)) {
|
2018-05-25 00:08:28 +02:00
|
|
|
D3D11_RECT sr = m_state.rs.scissors.at(i);
|
2018-03-10 11:44:27 +01:00
|
|
|
|
2018-05-25 00:08:28 +02:00
|
|
|
VkOffset2D srPosA;
|
|
|
|
srPosA.x = std::max<int32_t>(0, sr.left);
|
|
|
|
srPosA.y = std::max<int32_t>(0, sr.top);
|
|
|
|
|
|
|
|
VkOffset2D srPosB;
|
|
|
|
srPosB.x = std::max<int32_t>(srPosA.x, sr.right);
|
|
|
|
srPosB.y = std::max<int32_t>(srPosA.y, sr.bottom);
|
|
|
|
|
|
|
|
VkExtent2D srSize;
|
|
|
|
srSize.width = uint32_t(srPosB.x - srPosA.x);
|
|
|
|
srSize.height = uint32_t(srPosB.y - srPosA.y);
|
|
|
|
|
|
|
|
scissors.at(i) = VkRect2D { srPosA, srSize };
|
2018-03-10 11:44:27 +01:00
|
|
|
} else {
|
|
|
|
scissors.at(i) = VkRect2D {
|
|
|
|
VkOffset2D { 0, 0 },
|
|
|
|
VkExtent2D {
|
|
|
|
D3D11_VIEWPORT_BOUNDS_MAX,
|
|
|
|
D3D11_VIEWPORT_BOUNDS_MAX } };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cViewportCount = m_state.rs.numViewports,
|
|
|
|
cViewports = viewports,
|
|
|
|
cScissors = scissors
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->setViewports(
|
|
|
|
cViewportCount,
|
|
|
|
cViewports.data(),
|
|
|
|
cScissors.data());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-30 19:34:48 +02:00
|
|
|
void D3D11DeviceContext::BindShader(
|
|
|
|
DxbcProgramType ShaderStage,
|
|
|
|
const D3D11CommonShader* pShaderModule) {
|
2018-07-30 20:15:19 +02:00
|
|
|
// Bind the shader and the ICB at once
|
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
ShaderStage, DxbcBindingType::ConstantBuffer,
|
|
|
|
D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
|
|
|
|
|
2018-07-30 19:34:48 +02:00
|
|
|
EmitCs([
|
2018-07-30 20:15:19 +02:00
|
|
|
cSlotId = slotId,
|
2018-07-30 19:34:48 +02:00
|
|
|
cStage = GetShaderStage(ShaderStage),
|
2018-07-30 20:15:19 +02:00
|
|
|
cSlice = pShaderModule != nullptr
|
|
|
|
&& pShaderModule->GetIcb() != nullptr
|
|
|
|
? DxvkBufferSlice(pShaderModule->GetIcb())
|
|
|
|
: DxvkBufferSlice(),
|
|
|
|
cShader = pShaderModule != nullptr
|
|
|
|
? pShaderModule->GetShader()
|
|
|
|
: nullptr
|
2018-07-30 19:34:48 +02:00
|
|
|
] (DxvkContext* ctx) {
|
2018-07-30 20:15:19 +02:00
|
|
|
ctx->bindShader (cStage, cShader);
|
|
|
|
ctx->bindResourceBuffer(cSlotId, cSlice);
|
2018-07-30 19:34:48 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-15 20:49:24 +02:00
|
|
|
void D3D11DeviceContext::BindFramebuffer(BOOL Spill) {
|
2018-03-03 22:15:41 +01:00
|
|
|
// NOTE According to the Microsoft docs, we are supposed to
|
|
|
|
// unbind overlapping shader resource views. Since this comes
|
|
|
|
// with a large performance penalty we'll ignore this until an
|
|
|
|
// application actually relies on this behaviour.
|
|
|
|
DxvkRenderTargets attachments;
|
|
|
|
|
|
|
|
// D3D11 doesn't have the concept of a framebuffer object,
|
|
|
|
// so we'll just create a new one every time the render
|
|
|
|
// target bindings are updated. Set up the attachments.
|
|
|
|
for (UINT i = 0; i < m_state.om.renderTargetViews.size(); i++) {
|
|
|
|
if (m_state.om.renderTargetViews.at(i) != nullptr) {
|
2018-04-30 13:12:28 +02:00
|
|
|
attachments.color[i] = {
|
2018-03-03 22:15:41 +01:00
|
|
|
m_state.om.renderTargetViews.at(i)->GetImageView(),
|
2018-04-30 13:12:28 +02:00
|
|
|
m_state.om.renderTargetViews.at(i)->GetRenderLayout() };
|
2018-03-03 22:15:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_state.om.depthStencilView != nullptr) {
|
2018-04-30 13:12:28 +02:00
|
|
|
attachments.depth = {
|
2018-03-03 22:15:41 +01:00
|
|
|
m_state.om.depthStencilView->GetImageView(),
|
2018-04-30 13:12:28 +02:00
|
|
|
m_state.om.depthStencilView->GetRenderLayout() };
|
2018-03-03 22:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create and bind the framebuffer object to the context
|
2018-06-15 20:49:24 +02:00
|
|
|
EmitCs([
|
|
|
|
cAttachments = std::move(attachments),
|
|
|
|
cSpill = Spill
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindRenderTargets(cAttachments, cSpill);
|
2018-03-03 22:15:41 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 10:39:07 +01:00
|
|
|
void D3D11DeviceContext::BindVertexBuffer(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11Buffer* pBuffer,
|
|
|
|
UINT Offset,
|
|
|
|
UINT Stride) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cBufferSlice = pBuffer != nullptr ? pBuffer->GetBufferSlice(Offset) : DxvkBufferSlice(),
|
|
|
|
cStride = pBuffer != nullptr ? Stride : 0
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindVertexBuffer(cSlotId, cBufferSlice, cStride);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::BindIndexBuffer(
|
|
|
|
D3D11Buffer* pBuffer,
|
|
|
|
UINT Offset,
|
|
|
|
DXGI_FORMAT Format) {
|
|
|
|
// As in Vulkan, the index format can be either a 32-bit
|
|
|
|
// or 16-bit unsigned integer, no other formats are allowed.
|
2018-03-10 12:11:17 +01:00
|
|
|
VkIndexType indexType = VK_INDEX_TYPE_UINT32;
|
2018-03-10 10:39:07 +01:00
|
|
|
|
2018-03-10 12:11:17 +01:00
|
|
|
if (pBuffer != nullptr) {
|
|
|
|
switch (Format) {
|
|
|
|
case DXGI_FORMAT_R16_UINT: indexType = VK_INDEX_TYPE_UINT16; break;
|
|
|
|
case DXGI_FORMAT_R32_UINT: indexType = VK_INDEX_TYPE_UINT32; break;
|
|
|
|
default: Logger::err(str::format("D3D11: Invalid index format: ", Format));
|
|
|
|
}
|
2018-03-10 10:39:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EmitCs([
|
|
|
|
cBufferSlice = pBuffer != nullptr ? pBuffer->GetBufferSlice(Offset) : DxvkBufferSlice(),
|
|
|
|
cIndexType = indexType
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindIndexBuffer(cBufferSlice, cIndexType);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::BindConstantBuffer(
|
|
|
|
UINT Slot,
|
2018-03-18 12:36:45 +01:00
|
|
|
const D3D11ConstantBufferBinding* pBufferBinding) {
|
2018-03-10 11:16:52 +01:00
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
2018-03-18 12:36:45 +01:00
|
|
|
cBufferSlice = pBufferBinding->buffer != nullptr
|
|
|
|
? pBufferBinding->buffer->GetBufferSlice(
|
|
|
|
pBufferBinding->constantOffset * 16,
|
|
|
|
pBufferBinding->constantCount * 16)
|
|
|
|
: DxvkBufferSlice()
|
2018-03-10 11:16:52 +01:00
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindResourceBuffer(cSlotId, cBufferSlice);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::BindSampler(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11SamplerState* pSampler) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cSampler = pSampler != nullptr ? pSampler->GetDXVKSampler() : nullptr
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindResourceSampler(cSlotId, cSampler);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::BindShaderResource(
|
|
|
|
UINT Slot,
|
|
|
|
D3D11ShaderResourceView* pResource) {
|
|
|
|
EmitCs([
|
|
|
|
cSlotId = Slot,
|
|
|
|
cImageView = pResource != nullptr ? pResource->GetImageView() : nullptr,
|
|
|
|
cBufferView = pResource != nullptr ? pResource->GetBufferView() : nullptr
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindResourceView(cSlotId, cImageView, cBufferView);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::BindUnorderedAccessView(
|
|
|
|
UINT UavSlot,
|
|
|
|
UINT CtrSlot,
|
|
|
|
D3D11UnorderedAccessView* pUav) {
|
|
|
|
EmitCs([
|
|
|
|
cUavSlotId = UavSlot,
|
|
|
|
cCtrSlotId = CtrSlot,
|
|
|
|
cImageView = pUav != nullptr ? pUav->GetImageView() : nullptr,
|
|
|
|
cBufferView = pUav != nullptr ? pUav->GetBufferView() : nullptr,
|
|
|
|
cCounterSlice = pUav != nullptr ? pUav->GetCounterSlice() : DxvkBufferSlice()
|
|
|
|
] (DxvkContext* ctx) {
|
|
|
|
ctx->bindResourceView (cUavSlotId, cImageView, cBufferView);
|
|
|
|
ctx->bindResourceBuffer (cCtrSlotId, cCounterSlice);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-03 11:10:40 +02:00
|
|
|
void D3D11DeviceContext::DiscardBuffer(
|
|
|
|
D3D11Buffer* pBuffer) {
|
|
|
|
EmitCs([cBuffer = pBuffer->GetBuffer()] (DxvkContext* ctx) {
|
2018-08-03 11:28:00 +02:00
|
|
|
ctx->discardBuffer(cBuffer);
|
2018-08-03 11:10:40 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::SetConstantBuffers(
|
2017-12-08 22:30:41 +01:00
|
|
|
DxbcProgramType ShaderStage,
|
2017-12-20 17:37:46 +01:00
|
|
|
D3D11ConstantBufferBindings& Bindings,
|
2017-12-08 19:39:33 +01:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
2018-03-18 12:36:45 +01:00
|
|
|
ID3D11Buffer* const* ppConstantBuffers,
|
|
|
|
const UINT* pFirstConstant,
|
|
|
|
const UINT* pNumConstants) {
|
2017-12-20 17:37:46 +01:00
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
ShaderStage, DxbcBindingType::ConstantBuffer,
|
|
|
|
StartSlot);
|
|
|
|
|
2017-12-08 19:39:33 +01:00
|
|
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
2017-12-20 17:37:46 +01:00
|
|
|
auto newBuffer = static_cast<D3D11Buffer*>(ppConstantBuffers[i]);
|
2017-12-08 19:39:33 +01:00
|
|
|
|
2018-03-18 12:36:45 +01:00
|
|
|
UINT constantOffset = 0;
|
|
|
|
UINT constantCount = newBuffer != nullptr
|
|
|
|
? newBuffer->GetSize() / 16
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
if (newBuffer != nullptr && pFirstConstant != nullptr && pNumConstants != nullptr) {
|
|
|
|
constantOffset = pFirstConstant[i];
|
|
|
|
constantCount = pNumConstants [i];
|
|
|
|
}
|
|
|
|
|
2018-03-21 03:26:31 +01:00
|
|
|
if (Bindings[StartSlot + i].buffer != newBuffer
|
|
|
|
|| Bindings[StartSlot + i].constantOffset != constantOffset
|
|
|
|
|| Bindings[StartSlot + i].constantCount != constantCount) {
|
2018-03-18 12:36:45 +01:00
|
|
|
Bindings[StartSlot + i].buffer = newBuffer;
|
|
|
|
Bindings[StartSlot + i].constantOffset = constantOffset;
|
|
|
|
Bindings[StartSlot + i].constantCount = constantCount;
|
|
|
|
|
|
|
|
BindConstantBuffer(slotId + i, &Bindings[StartSlot + i]);
|
2017-12-08 19:39:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::SetSamplers(
|
2017-12-09 21:17:26 +01:00
|
|
|
DxbcProgramType ShaderStage,
|
2017-12-20 17:37:46 +01:00
|
|
|
D3D11SamplerBindings& Bindings,
|
2017-12-09 21:17:26 +01:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumSamplers,
|
|
|
|
ID3D11SamplerState* const* ppSamplers) {
|
2017-12-20 17:37:46 +01:00
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
ShaderStage, DxbcBindingType::ImageSampler,
|
|
|
|
StartSlot);
|
|
|
|
|
2017-12-09 21:17:26 +01:00
|
|
|
for (uint32_t i = 0; i < NumSamplers; i++) {
|
2017-12-20 17:37:46 +01:00
|
|
|
auto sampler = static_cast<D3D11SamplerState*>(ppSamplers[i]);
|
2017-12-09 21:17:26 +01:00
|
|
|
|
2017-12-20 17:37:46 +01:00
|
|
|
if (Bindings[StartSlot + i] != sampler) {
|
|
|
|
Bindings[StartSlot + i] = sampler;
|
2018-03-10 11:16:52 +01:00
|
|
|
BindSampler(slotId + i, sampler);
|
2017-12-09 21:17:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::SetShaderResources(
|
2017-12-10 01:56:07 +01:00
|
|
|
DxbcProgramType ShaderStage,
|
2017-12-20 17:37:46 +01:00
|
|
|
D3D11ShaderResourceBindings& Bindings,
|
2017-12-10 01:56:07 +01:00
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumResources,
|
|
|
|
ID3D11ShaderResourceView* const* ppResources) {
|
2017-12-20 17:37:46 +01:00
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
ShaderStage, DxbcBindingType::ShaderResource,
|
|
|
|
StartSlot);
|
|
|
|
|
2017-12-10 01:56:07 +01:00
|
|
|
for (uint32_t i = 0; i < NumResources; i++) {
|
2017-12-20 17:37:46 +01:00
|
|
|
auto resView = static_cast<D3D11ShaderResourceView*>(ppResources[i]);
|
2017-12-10 01:56:07 +01:00
|
|
|
|
2017-12-20 17:37:46 +01:00
|
|
|
if (Bindings[StartSlot + i] != resView) {
|
|
|
|
Bindings[StartSlot + i] = resView;
|
2018-03-10 11:16:52 +01:00
|
|
|
BindShaderResource(slotId + i, resView);
|
2017-12-10 01:56:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-10 11:16:52 +01:00
|
|
|
void D3D11DeviceContext::SetUnorderedAccessViews(
|
2017-12-28 19:05:53 +01:00
|
|
|
DxbcProgramType ShaderStage,
|
|
|
|
D3D11UnorderedAccessBindings& Bindings,
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView* const* ppUnorderedAccessViews) {
|
2018-01-11 17:12:39 +01:00
|
|
|
const uint32_t uavSlotId = computeResourceSlotId(
|
2017-12-28 19:05:53 +01:00
|
|
|
ShaderStage, DxbcBindingType::UnorderedAccessView,
|
|
|
|
StartSlot);
|
|
|
|
|
2018-01-11 17:12:39 +01:00
|
|
|
const uint32_t ctrSlotId = computeResourceSlotId(
|
|
|
|
ShaderStage, DxbcBindingType::UavCounter,
|
|
|
|
StartSlot);
|
|
|
|
|
2017-12-28 19:05:53 +01:00
|
|
|
for (uint32_t i = 0; i < NumUAVs; i++) {
|
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(ppUnorderedAccessViews[i]);
|
|
|
|
|
|
|
|
if (Bindings[StartSlot + i] != uav) {
|
|
|
|
Bindings[StartSlot + i] = uav;
|
2018-03-10 11:16:52 +01:00
|
|
|
BindUnorderedAccessView(uavSlotId + i, ctrSlotId + i, uav);
|
2017-12-28 19:05:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 20:49:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::SetRenderTargets(
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11RenderTargetView* const* ppRenderTargetViews,
|
|
|
|
ID3D11DepthStencilView* pDepthStencilView) {
|
|
|
|
// Native D3D11 does not change the render targets if
|
|
|
|
// the parameters passed to this method are invalid.
|
|
|
|
if (!ValidateRenderTargets(NumViews, ppRenderTargetViews, pDepthStencilView))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (UINT i = 0; i < m_state.om.renderTargetViews.size(); i++) {
|
|
|
|
m_state.om.renderTargetViews.at(i) = i < NumViews
|
|
|
|
? static_cast<D3D11RenderTargetView*>(ppRenderTargetViews[i])
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_state.om.depthStencilView = static_cast<D3D11DepthStencilView*>(pDepthStencilView);
|
|
|
|
}
|
2017-12-28 19:05:53 +01:00
|
|
|
|
|
|
|
|
2018-01-11 12:23:55 +01:00
|
|
|
void D3D11DeviceContext::InitUnorderedAccessViewCounters(
|
|
|
|
UINT NumUAVs,
|
|
|
|
ID3D11UnorderedAccessView* const* ppUnorderedAccessViews,
|
|
|
|
const UINT* pUAVInitialCounts) {
|
|
|
|
for (uint32_t i = 0; i < NumUAVs; i++) {
|
|
|
|
auto uav = static_cast<D3D11UnorderedAccessView*>(ppUnorderedAccessViews[i]);
|
|
|
|
|
|
|
|
if (uav != nullptr) {
|
|
|
|
const DxvkBufferSlice counterSlice = uav->GetCounterSlice();
|
|
|
|
const D3D11UavCounter counterValue = { pUAVInitialCounts[i] };
|
|
|
|
|
2018-06-16 10:22:38 +02:00
|
|
|
if (counterSlice.defined() && counterValue.atomicCtr != 0xFFFFFFFFu) {
|
2018-01-20 18:54:37 +01:00
|
|
|
EmitCs([counterSlice, counterValue] (DxvkContext* ctx) {
|
2018-06-16 10:22:38 +02:00
|
|
|
ctx->clearBuffer(
|
2018-01-20 18:54:37 +01:00
|
|
|
counterSlice.buffer(),
|
|
|
|
counterSlice.offset(),
|
|
|
|
counterSlice.length(),
|
2018-06-16 10:22:38 +02:00
|
|
|
counterValue.atomicCtr);
|
2018-01-20 18:54:37 +01:00
|
|
|
});
|
2018-01-11 12:23:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-18 12:45:27 +01:00
|
|
|
void D3D11DeviceContext::GetConstantBuffers(
|
|
|
|
const D3D11ConstantBufferBindings& Bindings,
|
|
|
|
UINT StartSlot,
|
|
|
|
UINT NumBuffers,
|
|
|
|
ID3D11Buffer** ppConstantBuffers,
|
|
|
|
UINT* pFirstConstant,
|
|
|
|
UINT* pNumConstants) {
|
|
|
|
for (uint32_t i = 0; i < NumBuffers; i++) {
|
|
|
|
if (ppConstantBuffers != nullptr)
|
|
|
|
ppConstantBuffers[i] = Bindings[StartSlot + i].buffer.ref();
|
|
|
|
|
|
|
|
if (pFirstConstant != nullptr)
|
|
|
|
pFirstConstant[i] = Bindings[StartSlot + i].constantOffset;
|
|
|
|
|
|
|
|
if (pNumConstants != nullptr)
|
|
|
|
pNumConstants[i] = Bindings[StartSlot + i].constantCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-03 20:59:17 +01:00
|
|
|
void D3D11DeviceContext::RestoreState() {
|
2018-06-15 20:49:24 +02:00
|
|
|
BindFramebuffer(m_state.om.isUavRendering);
|
2018-03-10 10:19:07 +01:00
|
|
|
|
2018-07-30 19:34:48 +02:00
|
|
|
BindShader(DxbcProgramType::VertexShader, GetCommonShader(m_state.vs.shader.ptr()));
|
|
|
|
BindShader(DxbcProgramType::HullShader, GetCommonShader(m_state.hs.shader.ptr()));
|
|
|
|
BindShader(DxbcProgramType::DomainShader, GetCommonShader(m_state.ds.shader.ptr()));
|
|
|
|
BindShader(DxbcProgramType::GeometryShader, GetCommonShader(m_state.gs.shader.ptr()));
|
|
|
|
BindShader(DxbcProgramType::PixelShader, GetCommonShader(m_state.ps.shader.ptr()));
|
|
|
|
BindShader(DxbcProgramType::ComputeShader, GetCommonShader(m_state.cs.shader.ptr()));
|
2018-03-10 10:39:07 +01:00
|
|
|
|
2018-03-10 11:44:27 +01:00
|
|
|
ApplyInputLayout();
|
|
|
|
ApplyPrimitiveTopology();
|
2018-03-10 11:56:58 +01:00
|
|
|
ApplyBlendState();
|
|
|
|
ApplyBlendFactor();
|
|
|
|
ApplyDepthStencilState();
|
|
|
|
ApplyStencilRef();
|
|
|
|
ApplyRasterizerState();
|
2018-03-10 11:44:27 +01:00
|
|
|
ApplyViewportState();
|
|
|
|
|
2018-03-10 10:39:07 +01:00
|
|
|
BindIndexBuffer(
|
|
|
|
m_state.ia.indexBuffer.buffer.ptr(),
|
|
|
|
m_state.ia.indexBuffer.offset,
|
|
|
|
m_state.ia.indexBuffer.format);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < m_state.ia.vertexBuffers.size(); i++) {
|
|
|
|
BindVertexBuffer(i,
|
|
|
|
m_state.ia.vertexBuffers[i].buffer.ptr(),
|
|
|
|
m_state.ia.vertexBuffers[i].offset,
|
|
|
|
m_state.ia.vertexBuffers[i].stride);
|
|
|
|
}
|
2018-03-10 11:30:32 +01:00
|
|
|
|
|
|
|
RestoreConstantBuffers(DxbcProgramType::VertexShader, m_state.vs.constantBuffers);
|
|
|
|
RestoreConstantBuffers(DxbcProgramType::HullShader, m_state.hs.constantBuffers);
|
|
|
|
RestoreConstantBuffers(DxbcProgramType::DomainShader, m_state.ds.constantBuffers);
|
|
|
|
RestoreConstantBuffers(DxbcProgramType::GeometryShader, m_state.gs.constantBuffers);
|
|
|
|
RestoreConstantBuffers(DxbcProgramType::PixelShader, m_state.ps.constantBuffers);
|
|
|
|
RestoreConstantBuffers(DxbcProgramType::ComputeShader, m_state.cs.constantBuffers);
|
|
|
|
|
|
|
|
RestoreSamplers(DxbcProgramType::VertexShader, m_state.vs.samplers);
|
|
|
|
RestoreSamplers(DxbcProgramType::HullShader, m_state.hs.samplers);
|
|
|
|
RestoreSamplers(DxbcProgramType::DomainShader, m_state.ds.samplers);
|
|
|
|
RestoreSamplers(DxbcProgramType::GeometryShader, m_state.gs.samplers);
|
|
|
|
RestoreSamplers(DxbcProgramType::PixelShader, m_state.ps.samplers);
|
|
|
|
RestoreSamplers(DxbcProgramType::ComputeShader, m_state.cs.samplers);
|
|
|
|
|
|
|
|
RestoreShaderResources(DxbcProgramType::VertexShader, m_state.vs.shaderResources);
|
|
|
|
RestoreShaderResources(DxbcProgramType::HullShader, m_state.hs.shaderResources);
|
|
|
|
RestoreShaderResources(DxbcProgramType::DomainShader, m_state.ds.shaderResources);
|
|
|
|
RestoreShaderResources(DxbcProgramType::GeometryShader, m_state.gs.shaderResources);
|
|
|
|
RestoreShaderResources(DxbcProgramType::PixelShader, m_state.ps.shaderResources);
|
|
|
|
RestoreShaderResources(DxbcProgramType::ComputeShader, m_state.cs.shaderResources);
|
|
|
|
|
2018-03-21 04:56:33 +01:00
|
|
|
RestoreUnorderedAccessViews(DxbcProgramType::PixelShader, m_state.ps.unorderedAccessViews);
|
|
|
|
RestoreUnorderedAccessViews(DxbcProgramType::ComputeShader, m_state.cs.unorderedAccessViews);
|
2018-03-10 11:30:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::RestoreConstantBuffers(
|
|
|
|
DxbcProgramType Stage,
|
|
|
|
D3D11ConstantBufferBindings& Bindings) {
|
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
Stage, DxbcBindingType::ConstantBuffer, 0);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < Bindings.size(); i++)
|
2018-03-18 12:36:45 +01:00
|
|
|
BindConstantBuffer(slotId + i, &Bindings[i]);
|
2018-03-10 11:30:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::RestoreSamplers(
|
|
|
|
DxbcProgramType Stage,
|
|
|
|
D3D11SamplerBindings& Bindings) {
|
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
Stage, DxbcBindingType::ImageSampler, 0);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < Bindings.size(); i++)
|
|
|
|
BindSampler(slotId + i, Bindings[i].ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::RestoreShaderResources(
|
|
|
|
DxbcProgramType Stage,
|
|
|
|
D3D11ShaderResourceBindings& Bindings) {
|
|
|
|
const uint32_t slotId = computeResourceSlotId(
|
|
|
|
Stage, DxbcBindingType::ShaderResource, 0);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < Bindings.size(); i++)
|
|
|
|
BindShaderResource(slotId + i, Bindings[i].ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D11DeviceContext::RestoreUnorderedAccessViews(
|
|
|
|
DxbcProgramType Stage,
|
2018-03-21 04:56:33 +01:00
|
|
|
D3D11UnorderedAccessBindings& Bindings) {
|
2018-03-10 11:30:32 +01:00
|
|
|
const uint32_t uavSlotId = computeResourceSlotId(
|
|
|
|
Stage, DxbcBindingType::UnorderedAccessView, 0);
|
|
|
|
|
|
|
|
const uint32_t ctrSlotId = computeResourceSlotId(
|
|
|
|
Stage, DxbcBindingType::UavCounter, 0);
|
|
|
|
|
2018-03-21 04:56:33 +01:00
|
|
|
for (uint32_t i = 0; i < Bindings.size(); i++) {
|
2018-03-10 11:30:32 +01:00
|
|
|
BindUnorderedAccessView(
|
|
|
|
uavSlotId + i, ctrSlotId + i,
|
|
|
|
Bindings[i].ptr());
|
|
|
|
}
|
2018-03-03 20:59:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-05 09:12:36 +02:00
|
|
|
bool D3D11DeviceContext::ValidateRenderTargets(
|
|
|
|
UINT NumViews,
|
|
|
|
ID3D11RenderTargetView* const* ppRenderTargetViews,
|
|
|
|
ID3D11DepthStencilView* pDepthStencilView) {
|
|
|
|
Rc<DxvkImageView> refView;
|
|
|
|
|
|
|
|
if (pDepthStencilView != nullptr) {
|
|
|
|
refView = static_cast<D3D11DepthStencilView*>(
|
|
|
|
pDepthStencilView)->GetImageView();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < NumViews; i++) {
|
|
|
|
if (ppRenderTargetViews[i] != nullptr) {
|
|
|
|
auto curView = static_cast<D3D11RenderTargetView*>(
|
|
|
|
ppRenderTargetViews[i])->GetImageView();
|
|
|
|
|
|
|
|
if (refView != nullptr) {
|
|
|
|
// Render target views must all have the same
|
|
|
|
// size, sample count, layer count, and type
|
|
|
|
if (curView->info().type != refView->info().type
|
|
|
|
|| curView->info().numLayers != refView->info().numLayers)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (curView->imageInfo().sampleCount
|
|
|
|
!= refView->imageInfo().sampleCount)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Set reference view. All remaining views
|
|
|
|
// must be compatible to the reference view.
|
|
|
|
refView = curView;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-13 11:12:54 +02:00
|
|
|
|
2018-01-23 16:43:55 +01:00
|
|
|
DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) {
|
2018-05-13 14:45:50 +02:00
|
|
|
constexpr size_t UpdateBufferSize = 16 * 1024 * 1024;
|
2018-01-23 16:43:55 +01:00
|
|
|
|
|
|
|
if (Size >= UpdateBufferSize) {
|
|
|
|
Rc<DxvkDataBuffer> buffer = new DxvkDataBuffer(Size);
|
|
|
|
return buffer->alloc(Size);
|
|
|
|
} else {
|
|
|
|
if (m_updateBuffer == nullptr)
|
2018-05-13 11:12:54 +02:00
|
|
|
m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize);
|
2018-01-23 16:43:55 +01:00
|
|
|
|
|
|
|
DxvkDataSlice slice = m_updateBuffer->alloc(Size);
|
|
|
|
|
|
|
|
if (slice.ptr() == nullptr) {
|
2018-05-13 11:12:54 +02:00
|
|
|
m_updateBuffer = new DxvkDataBuffer(UpdateBufferSize);
|
2018-01-23 16:43:55 +01:00
|
|
|
slice = m_updateBuffer->alloc(Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return slice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-27 16:07:38 +02:00
|
|
|
|
|
|
|
DxvkCsChunkRef D3D11DeviceContext::AllocCsChunk() {
|
|
|
|
return m_parent->AllocCsChunk();
|
|
|
|
}
|
|
|
|
|
2017-10-11 09:51:48 +02:00
|
|
|
}
|