mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-13 19:29:14 +01:00
[d3d11] Move all remaining context code to D3D11CommonContext
This commit is contained in:
parent
a3ed84c0c1
commit
20df9fc899
@ -21,90 +21,4 @@ namespace dxvk {
|
||||
|
||||
}
|
||||
|
||||
|
||||
VkClearValue D3D11DeviceContext::ConvertColorValue(
|
||||
const FLOAT Color[4],
|
||||
const DxvkFormatInfo* pFormatInfo) {
|
||||
VkClearValue result;
|
||||
|
||||
if (pFormatInfo->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
if (pFormatInfo->flags.test(DxvkFormatFlag::SampledUInt))
|
||||
result.color.uint32[i] = uint32_t(std::max(0.0f, Color[i]));
|
||||
else if (pFormatInfo->flags.test(DxvkFormatFlag::SampledSInt))
|
||||
result.color.int32[i] = int32_t(Color[i]);
|
||||
else
|
||||
result.color.float32[i] = Color[i];
|
||||
}
|
||||
} else {
|
||||
result.depthStencil.depth = Color[0];
|
||||
result.depthStencil.stencil = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::InitDefaultPrimitiveTopology(
|
||||
DxvkInputAssemblyState* pIaState) {
|
||||
pIaState->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
|
||||
pIaState->primitiveRestart = VK_FALSE;
|
||||
pIaState->patchVertexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::InitDefaultRasterizerState(
|
||||
DxvkRasterizerState* pRsState) {
|
||||
pRsState->polygonMode = VK_POLYGON_MODE_FILL;
|
||||
pRsState->cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
pRsState->frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||
pRsState->depthClipEnable = VK_TRUE;
|
||||
pRsState->depthBiasEnable = VK_FALSE;
|
||||
pRsState->conservativeMode = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT;
|
||||
pRsState->sampleCount = 0;
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::InitDefaultDepthStencilState(
|
||||
DxvkDepthStencilState* pDsState) {
|
||||
VkStencilOpState stencilOp;
|
||||
stencilOp.failOp = VK_STENCIL_OP_KEEP;
|
||||
stencilOp.passOp = VK_STENCIL_OP_KEEP;
|
||||
stencilOp.depthFailOp = VK_STENCIL_OP_KEEP;
|
||||
stencilOp.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||
stencilOp.compareMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
||||
stencilOp.writeMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
||||
stencilOp.reference = 0;
|
||||
|
||||
pDsState->enableDepthTest = VK_TRUE;
|
||||
pDsState->enableDepthWrite = VK_TRUE;
|
||||
pDsState->enableStencilTest = VK_FALSE;
|
||||
pDsState->depthCompareOp = VK_COMPARE_OP_LESS;
|
||||
pDsState->stencilOpFront = stencilOp;
|
||||
pDsState->stencilOpBack = stencilOp;
|
||||
}
|
||||
|
||||
|
||||
void D3D11DeviceContext::InitDefaultBlendState(
|
||||
DxvkBlendMode* pCbState,
|
||||
DxvkLogicOpState* pLoState,
|
||||
DxvkMultisampleState* pMsState,
|
||||
UINT SampleMask) {
|
||||
pCbState->enableBlending = VK_FALSE;
|
||||
pCbState->colorSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
pCbState->colorDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
pCbState->colorBlendOp = VK_BLEND_OP_ADD;
|
||||
pCbState->alphaSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
pCbState->alphaDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
pCbState->alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
pCbState->writeMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
pLoState->enableLogicOp = VK_FALSE;
|
||||
pLoState->logicOp = VK_LOGIC_OP_NO_OP;
|
||||
|
||||
pMsState->sampleMask = SampleMask;
|
||||
pMsState->enableAlphaToCoverage = VK_FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,49 +27,6 @@ namespace dxvk {
|
||||
|
||||
~D3D11DeviceContext();
|
||||
|
||||
protected:
|
||||
|
||||
VkClearValue ConvertColorValue(
|
||||
const FLOAT Color[4],
|
||||
const DxvkFormatInfo* pFormatInfo);
|
||||
|
||||
static void InitDefaultPrimitiveTopology(
|
||||
DxvkInputAssemblyState* pIaState);
|
||||
|
||||
static void InitDefaultRasterizerState(
|
||||
DxvkRasterizerState* pRsState);
|
||||
|
||||
static void InitDefaultDepthStencilState(
|
||||
DxvkDepthStencilState* pDsState);
|
||||
|
||||
static void InitDefaultBlendState(
|
||||
DxvkBlendMode* pCbState,
|
||||
DxvkLogicOpState* pLoState,
|
||||
DxvkMultisampleState* pMsState,
|
||||
UINT SampleMask);
|
||||
|
||||
template<typename T>
|
||||
const D3D11CommonShader* GetCommonShader(T* pShader) const {
|
||||
return pShader != nullptr ? pShader->GetCommonShader() : nullptr;
|
||||
}
|
||||
|
||||
static uint32_t GetIndirectCommandStride(const D3D11CmdDrawIndirectData* cmdData, uint32_t offset, uint32_t minStride) {
|
||||
if (likely(cmdData->stride))
|
||||
return cmdData->offset + cmdData->count * cmdData->stride == offset ? cmdData->stride : 0;
|
||||
|
||||
uint32_t stride = offset - cmdData->offset;
|
||||
return stride >= minStride && stride <= 32 ? stride : 0;
|
||||
}
|
||||
|
||||
static bool ValidateDrawBufferSize(ID3D11Buffer* pBuffer, UINT Offset, UINT Size) {
|
||||
UINT bufferSize = 0;
|
||||
|
||||
if (likely(pBuffer != nullptr))
|
||||
bufferSize = static_cast<D3D11Buffer*>(pBuffer)->Desc()->ByteWidth;
|
||||
|
||||
return bufferSize >= Offset + Size;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3540,6 +3540,30 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
VkClearValue D3D11CommonContext<ContextType>::ConvertColorValue(
|
||||
const FLOAT Color[4],
|
||||
const DxvkFormatInfo* pFormatInfo) {
|
||||
VkClearValue result;
|
||||
|
||||
if (pFormatInfo->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
if (pFormatInfo->flags.test(DxvkFormatFlag::SampledUInt))
|
||||
result.color.uint32[i] = uint32_t(std::max(0.0f, Color[i]));
|
||||
else if (pFormatInfo->flags.test(DxvkFormatFlag::SampledSInt))
|
||||
result.color.int32[i] = int32_t(Color[i]);
|
||||
else
|
||||
result.color.float32[i] = Color[i];
|
||||
}
|
||||
} else {
|
||||
result.depthStencil.depth = Color[0];
|
||||
result.depthStencil.stencil = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::CopyBuffer(
|
||||
D3D11Buffer* pDstBuffer,
|
||||
@ -4916,6 +4940,72 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::InitDefaultPrimitiveTopology(
|
||||
DxvkInputAssemblyState* pIaState) {
|
||||
pIaState->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
|
||||
pIaState->primitiveRestart = VK_FALSE;
|
||||
pIaState->patchVertexCount = 0;
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::InitDefaultRasterizerState(
|
||||
DxvkRasterizerState* pRsState) {
|
||||
pRsState->polygonMode = VK_POLYGON_MODE_FILL;
|
||||
pRsState->cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
pRsState->frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||
pRsState->depthClipEnable = VK_TRUE;
|
||||
pRsState->depthBiasEnable = VK_FALSE;
|
||||
pRsState->conservativeMode = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT;
|
||||
pRsState->sampleCount = 0;
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::InitDefaultDepthStencilState(
|
||||
DxvkDepthStencilState* pDsState) {
|
||||
VkStencilOpState stencilOp;
|
||||
stencilOp.failOp = VK_STENCIL_OP_KEEP;
|
||||
stencilOp.passOp = VK_STENCIL_OP_KEEP;
|
||||
stencilOp.depthFailOp = VK_STENCIL_OP_KEEP;
|
||||
stencilOp.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||
stencilOp.compareMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
||||
stencilOp.writeMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
||||
stencilOp.reference = 0;
|
||||
|
||||
pDsState->enableDepthTest = VK_TRUE;
|
||||
pDsState->enableDepthWrite = VK_TRUE;
|
||||
pDsState->enableStencilTest = VK_FALSE;
|
||||
pDsState->depthCompareOp = VK_COMPARE_OP_LESS;
|
||||
pDsState->stencilOpFront = stencilOp;
|
||||
pDsState->stencilOpBack = stencilOp;
|
||||
}
|
||||
|
||||
|
||||
template<typename ContextType>
|
||||
void D3D11CommonContext<ContextType>::InitDefaultBlendState(
|
||||
DxvkBlendMode* pCbState,
|
||||
DxvkLogicOpState* pLoState,
|
||||
DxvkMultisampleState* pMsState,
|
||||
UINT SampleMask) {
|
||||
pCbState->enableBlending = VK_FALSE;
|
||||
pCbState->colorSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
pCbState->colorDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
pCbState->colorBlendOp = VK_BLEND_OP_ADD;
|
||||
pCbState->alphaSrcFactor = VK_BLEND_FACTOR_ONE;
|
||||
pCbState->alphaDstFactor = VK_BLEND_FACTOR_ZERO;
|
||||
pCbState->alphaBlendOp = VK_BLEND_OP_ADD;
|
||||
pCbState->writeMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT
|
||||
| VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||
|
||||
pLoState->enableLogicOp = VK_FALSE;
|
||||
pLoState->logicOp = VK_LOGIC_OP_NO_OP;
|
||||
|
||||
pMsState->sampleMask = SampleMask;
|
||||
pMsState->enableAlphaToCoverage = VK_FALSE;
|
||||
}
|
||||
|
||||
// Explicitly instantiate here
|
||||
template class D3D11CommonContext<D3D11DeferredContext>;
|
||||
template class D3D11CommonContext<D3D11ImmediateContext>;
|
||||
|
@ -842,6 +842,10 @@ namespace dxvk {
|
||||
UINT CtrSlot,
|
||||
UINT Counter);
|
||||
|
||||
VkClearValue ConvertColorValue(
|
||||
const FLOAT Color[4],
|
||||
const DxvkFormatInfo* pFormatInfo);
|
||||
|
||||
void CopyBuffer(
|
||||
D3D11Buffer* pDstBuffer,
|
||||
VkDeviceSize DstOffset,
|
||||
@ -1017,6 +1021,21 @@ namespace dxvk {
|
||||
ID3D11RenderTargetView* const* ppRenderTargetViews,
|
||||
ID3D11DepthStencilView* pDepthStencilView);
|
||||
|
||||
static void InitDefaultPrimitiveTopology(
|
||||
DxvkInputAssemblyState* pIaState);
|
||||
|
||||
static void InitDefaultRasterizerState(
|
||||
DxvkRasterizerState* pRsState);
|
||||
|
||||
static void InitDefaultDepthStencilState(
|
||||
DxvkDepthStencilState* pDsState);
|
||||
|
||||
static void InitDefaultBlendState(
|
||||
DxvkBlendMode* pCbState,
|
||||
DxvkLogicOpState* pLoState,
|
||||
DxvkMultisampleState* pMsState,
|
||||
UINT SampleMask);
|
||||
|
||||
template<typename Cmd>
|
||||
void EmitCs(Cmd&& command) {
|
||||
m_cmdData = nullptr;
|
||||
@ -1054,6 +1073,28 @@ namespace dxvk {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const D3D11CommonShader* GetCommonShader(T* pShader) const {
|
||||
return pShader != nullptr ? pShader->GetCommonShader() : nullptr;
|
||||
}
|
||||
|
||||
static uint32_t GetIndirectCommandStride(const D3D11CmdDrawIndirectData* cmdData, uint32_t offset, uint32_t minStride) {
|
||||
if (likely(cmdData->stride))
|
||||
return cmdData->offset + cmdData->count * cmdData->stride == offset ? cmdData->stride : 0;
|
||||
|
||||
uint32_t stride = offset - cmdData->offset;
|
||||
return stride >= minStride && stride <= 32 ? stride : 0;
|
||||
}
|
||||
|
||||
static bool ValidateDrawBufferSize(ID3D11Buffer* pBuffer, UINT Offset, UINT Size) {
|
||||
UINT bufferSize = 0;
|
||||
|
||||
if (likely(pBuffer != nullptr))
|
||||
bufferSize = static_cast<D3D11Buffer*>(pBuffer)->Desc()->ByteWidth;
|
||||
|
||||
return bufferSize >= Offset + Size;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
ContextType* GetTypedContext() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user