Merge remote-tracking branch 'origin/master' into 1.10
# Conflicts: # Source/Engine/Networking/NetworkReplicator.cpp
This commit is contained in:
@@ -23,18 +23,18 @@ ID3D11ShaderResourceView* EmptySRHandles[GPU_MAX_SR_BINDED] = {};
|
||||
// Ensure to match the indirect commands arguments layout
|
||||
static_assert(sizeof(GPUDispatchIndirectArgs) == sizeof(uint32) * 3, "Wrong size of GPUDrawIndirectArgs.");
|
||||
static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountX) == sizeof(uint32) * 0, "Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountX");
|
||||
static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountY) == sizeof(uint32) * 1,"Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountY");
|
||||
static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountY) == sizeof(uint32) * 1, "Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountY");
|
||||
static_assert(OFFSET_OF(GPUDispatchIndirectArgs, ThreadGroupCountZ) == sizeof(uint32) * 2, "Wrong offset for GPUDrawIndirectArgs::ThreadGroupCountZ");
|
||||
//
|
||||
static_assert(sizeof(GPUDrawIndirectArgs) == sizeof(D3D11_DRAW_INSTANCED_INDIRECT_ARGS), "Wrong size of GPUDrawIndirectArgs.");
|
||||
static_assert(OFFSET_OF(GPUDrawIndirectArgs, VerticesCount) == OFFSET_OF(D3D11_DRAW_INSTANCED_INDIRECT_ARGS, VertexCountPerInstance), "Wrong offset for GPUDrawIndirectArgs::VerticesCount");
|
||||
static_assert(OFFSET_OF(GPUDrawIndirectArgs, InstanceCount) == OFFSET_OF(D3D11_DRAW_INSTANCED_INDIRECT_ARGS, InstanceCount),"Wrong offset for GPUDrawIndirectArgs::InstanceCount");
|
||||
static_assert(OFFSET_OF(GPUDrawIndirectArgs, InstanceCount) == OFFSET_OF(D3D11_DRAW_INSTANCED_INDIRECT_ARGS, InstanceCount), "Wrong offset for GPUDrawIndirectArgs::InstanceCount");
|
||||
static_assert(OFFSET_OF(GPUDrawIndirectArgs, StartVertex) == OFFSET_OF(D3D11_DRAW_INSTANCED_INDIRECT_ARGS, StartVertexLocation), "Wrong offset for GPUDrawIndirectArgs::StartVertex");
|
||||
static_assert(OFFSET_OF(GPUDrawIndirectArgs, StartInstance) == OFFSET_OF(D3D11_DRAW_INSTANCED_INDIRECT_ARGS, StartInstanceLocation), "Wrong offset for GPUDrawIndirectArgs::StartInstance");
|
||||
//
|
||||
static_assert(sizeof(GPUDrawIndexedIndirectArgs) == sizeof(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS), "Wrong size of GPUDrawIndexedIndirectArgs.");
|
||||
static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, IndicesCount) == OFFSET_OF(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS, IndexCountPerInstance), "Wrong offset for GPUDrawIndexedIndirectArgs::IndicesCount");
|
||||
static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, InstanceCount) == OFFSET_OF(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS, InstanceCount),"Wrong offset for GPUDrawIndexedIndirectArgs::InstanceCount");
|
||||
static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, InstanceCount) == OFFSET_OF(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS, InstanceCount), "Wrong offset for GPUDrawIndexedIndirectArgs::InstanceCount");
|
||||
static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, StartIndex) == OFFSET_OF(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS, StartIndexLocation), "Wrong offset for GPUDrawIndexedIndirectArgs::StartIndex");
|
||||
static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, StartVertex) == OFFSET_OF(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS, BaseVertexLocation), "Wrong offset for GPUDrawIndexedIndirectArgs::StartVertex");
|
||||
static_assert(OFFSET_OF(GPUDrawIndexedIndirectArgs, StartInstance) == OFFSET_OF(D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS, StartInstanceLocation), "Wrong offset for GPUDrawIndexedIndirectArgs::StartInstance");
|
||||
@@ -559,15 +559,13 @@ void GPUContextDX11::SetState(GPUPipelineState* state)
|
||||
#endif
|
||||
GPUShaderProgramPSDX11* ps = nullptr;
|
||||
D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
|
||||
|
||||
if (state)
|
||||
{
|
||||
ASSERT(_currentState->IsValid());
|
||||
|
||||
blendState = _currentState->BlendState;
|
||||
rasterizerState = _device->RasterizerStates[_currentState->RasterizerStateIndex];
|
||||
depthStencilState = _device->DepthStencilStates[_currentState->DepthStencilStateIndex];
|
||||
|
||||
//depthStencilState = _device->DepthStencilStates2[_currentState->DepthStencilStateIndex];
|
||||
depthStencilState = _currentState->DepthStencilState;
|
||||
ASSERT(_currentState->VS != nullptr);
|
||||
vs = _currentState->VS;
|
||||
#if GPU_ALLOW_TESSELLATION_SHADERS
|
||||
@@ -578,7 +576,6 @@ void GPUContextDX11::SetState(GPUPipelineState* state)
|
||||
gs = _currentState->GS;
|
||||
#endif
|
||||
ps = _currentState->PS;
|
||||
|
||||
primitiveTopology = _currentState->PrimitiveTopology;
|
||||
}
|
||||
|
||||
@@ -858,13 +855,13 @@ void GPUContextDX11::flushSRVs()
|
||||
{
|
||||
_srMaskDirtyGraphics = 0;
|
||||
FLUSH_STAGE(VS);
|
||||
#if GPU_ALLOW_TESSELLATION_SHADERS
|
||||
#if GPU_ALLOW_TESSELLATION_SHADERS
|
||||
FLUSH_STAGE(HS);
|
||||
FLUSH_STAGE(DS);
|
||||
#endif
|
||||
#if GPU_ALLOW_GEOMETRY_SHADERS
|
||||
#endif
|
||||
#if GPU_ALLOW_GEOMETRY_SHADERS
|
||||
FLUSH_STAGE(GS);
|
||||
#endif
|
||||
#endif
|
||||
FLUSH_STAGE(PS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,56 @@
|
||||
#define DX11_FORCE_USE_DX10 0
|
||||
#define DX11_FORCE_USE_DX10_1 0
|
||||
|
||||
static D3D11_COMPARISON_FUNC ToDX11(ComparisonFunc value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case ComparisonFunc::Never:
|
||||
return D3D11_COMPARISON_NEVER;
|
||||
case ComparisonFunc::Less:
|
||||
return D3D11_COMPARISON_LESS;
|
||||
case ComparisonFunc::Equal:
|
||||
return D3D11_COMPARISON_EQUAL;
|
||||
case ComparisonFunc::LessEqual:
|
||||
return D3D11_COMPARISON_LESS_EQUAL;
|
||||
case ComparisonFunc::Greater:
|
||||
return D3D11_COMPARISON_GREATER;
|
||||
case ComparisonFunc::NotEqual:
|
||||
return D3D11_COMPARISON_NOT_EQUAL;
|
||||
case ComparisonFunc::GreaterEqual:
|
||||
return D3D11_COMPARISON_GREATER_EQUAL;
|
||||
case ComparisonFunc::Always:
|
||||
return D3D11_COMPARISON_ALWAYS;
|
||||
default:
|
||||
return (D3D11_COMPARISON_FUNC)-1;
|
||||
}
|
||||
}
|
||||
|
||||
static D3D11_STENCIL_OP ToDX11(StencilOperation value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case StencilOperation::Keep:
|
||||
return D3D11_STENCIL_OP_KEEP;
|
||||
case StencilOperation::Zero:
|
||||
return D3D11_STENCIL_OP_ZERO;
|
||||
case StencilOperation::Replace:
|
||||
return D3D11_STENCIL_OP_REPLACE;
|
||||
case StencilOperation::IncrementSaturated:
|
||||
return D3D11_STENCIL_OP_INCR_SAT;
|
||||
case StencilOperation::DecrementSaturated:
|
||||
return D3D11_STENCIL_OP_DECR_SAT;
|
||||
case StencilOperation::Invert:
|
||||
return D3D11_STENCIL_OP_INVERT;
|
||||
case StencilOperation::Increment:
|
||||
return D3D11_STENCIL_OP_INCR;
|
||||
case StencilOperation::Decrement:
|
||||
return D3D11_STENCIL_OP_DECR;
|
||||
default:
|
||||
return (D3D11_STENCIL_OP)-1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool TryCreateDevice(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL maxFeatureLevel, D3D_FEATURE_LEVEL* featureLevel)
|
||||
{
|
||||
ID3D11Device* device = nullptr;
|
||||
@@ -251,22 +301,66 @@ GPUDeviceDX11::GPUDeviceDX11(IDXGIFactory* dxgiFactory, GPUAdapterDX* adapter)
|
||||
, _factoryDXGI(dxgiFactory)
|
||||
{
|
||||
Platform::MemoryClear(RasterizerStates, sizeof(RasterizerStates));
|
||||
Platform::MemoryClear(DepthStencilStates, sizeof(DepthStencilStates));
|
||||
}
|
||||
|
||||
ID3D11DepthStencilState* GPUDeviceDX11::GetDepthStencilState(const void* descriptionPtr)
|
||||
{
|
||||
const GPUPipelineState::Description& description = *(const GPUPipelineState::Description*)descriptionPtr;
|
||||
DepthStencilMode key;
|
||||
Platform::MemoryClear(&key, sizeof(key)); // Ensure to clear any padding bytes for raw memory compare/hashing
|
||||
key.DepthEnable = description.DepthEnable ? 1 : 0;
|
||||
key.DepthWriteEnable = description.DepthWriteEnable ? 1 : 0;
|
||||
key.DepthClipEnable = description.DepthClipEnable ? 1 : 0;
|
||||
key.StencilEnable = description.StencilEnable ? 1 : 0;
|
||||
key.StencilReadMask = description.StencilReadMask;
|
||||
key.StencilWriteMask = description.StencilWriteMask;
|
||||
key.DepthFunc = description.DepthFunc;
|
||||
key.StencilFunc = description.StencilFunc;
|
||||
key.StencilFailOp = description.StencilFailOp;
|
||||
key.StencilDepthFailOp = description.StencilDepthFailOp;
|
||||
key.StencilPassOp = description.StencilPassOp;
|
||||
|
||||
// Use lookup
|
||||
ID3D11DepthStencilState* state = nullptr;
|
||||
if (DepthStencilStates.TryGet(key, state))
|
||||
return state;
|
||||
|
||||
// Try again but with lock to prevent race condition with double-adding the same thing
|
||||
ScopeLock lock(StatesWriteLocker);
|
||||
if (DepthStencilStates.TryGet(key, state))
|
||||
return state;
|
||||
|
||||
// Prepare description
|
||||
D3D11_DEPTH_STENCIL_DESC desc;
|
||||
desc.DepthEnable = !!description.DepthEnable;
|
||||
desc.DepthWriteMask = description.DepthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
desc.DepthFunc = ToDX11(description.DepthFunc);
|
||||
desc.StencilEnable = !!description.StencilEnable;
|
||||
desc.StencilReadMask = description.StencilReadMask;
|
||||
desc.StencilWriteMask = description.StencilWriteMask;
|
||||
desc.FrontFace.StencilFailOp = ToDX11(description.StencilFailOp);
|
||||
desc.FrontFace.StencilDepthFailOp = ToDX11(description.StencilDepthFailOp);
|
||||
desc.FrontFace.StencilPassOp = ToDX11(description.StencilPassOp);
|
||||
desc.FrontFace.StencilFunc = ToDX11(description.StencilFunc);
|
||||
desc.BackFace = desc.FrontFace;
|
||||
|
||||
// Create object and cache it
|
||||
VALIDATE_DIRECTX_CALL(_device->CreateDepthStencilState(&desc, &state));
|
||||
DepthStencilStates.Add(key, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
ID3D11BlendState* GPUDeviceDX11::GetBlendState(const BlendingMode& blending)
|
||||
{
|
||||
// Use lookup
|
||||
ID3D11BlendState* blendState = nullptr;
|
||||
if (BlendStates.TryGet(blending, blendState))
|
||||
return blendState;
|
||||
|
||||
// Make it safe
|
||||
ScopeLock lock(BlendStatesWriteLocker);
|
||||
|
||||
// Try again to prevent race condition with double-adding the same thing
|
||||
if (BlendStates.TryGet(blending, blendState))
|
||||
return blendState;
|
||||
ID3D11BlendState* state = nullptr;
|
||||
if (BlendStates.TryGet(blending, state))
|
||||
return state;
|
||||
|
||||
// Try again but with lock to prevent race condition with double-adding the same thing
|
||||
ScopeLock lock(StatesWriteLocker);
|
||||
if (BlendStates.TryGet(blending, state))
|
||||
return state;
|
||||
|
||||
// Prepare description
|
||||
D3D11_BLEND_DESC desc;
|
||||
@@ -285,13 +379,10 @@ ID3D11BlendState* GPUDeviceDX11::GetBlendState(const BlendingMode& blending)
|
||||
desc.RenderTarget[i] = desc.RenderTarget[0];
|
||||
#endif
|
||||
|
||||
// Create object
|
||||
VALIDATE_DIRECTX_CALL(_device->CreateBlendState(&desc, &blendState));
|
||||
|
||||
// Cache blend state
|
||||
BlendStates.Add(blending, blendState);
|
||||
|
||||
return blendState;
|
||||
// Create object and cache it
|
||||
VALIDATE_DIRECTX_CALL(_device->CreateBlendState(&desc, &state));
|
||||
BlendStates.Add(blending, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
bool GPUDeviceDX11::Init()
|
||||
@@ -326,9 +417,9 @@ bool GPUDeviceDX11::Init()
|
||||
#if PLATFORM_WINDOWS
|
||||
// Detect RenderDoc usage (UUID {A7AA6116-9C8D-4BBA-9083-B4D816B71B78})
|
||||
IUnknown* unknown = nullptr;
|
||||
const GUID uuidRenderDoc = { 0xa7aa6116, 0x9c8d, 0x4bba, {0x90, 0x83, 0xb4, 0xd8, 0x16, 0xb7, 0x1b, 0x78}};
|
||||
const GUID uuidRenderDoc = { 0xa7aa6116, 0x9c8d, 0x4bba, { 0x90, 0x83, 0xb4, 0xd8, 0x16, 0xb7, 0x1b, 0x78 } };
|
||||
HRESULT hr = _device->QueryInterface(uuidRenderDoc, (void**)&unknown);
|
||||
if(SUCCEEDED(hr) && unknown)
|
||||
if (SUCCEEDED(hr) && unknown)
|
||||
{
|
||||
IsDebugToolAttached = true;
|
||||
unknown->Release();
|
||||
@@ -560,31 +651,6 @@ bool GPUDeviceDX11::Init()
|
||||
#undef CREATE_RASTERIZER_STATE
|
||||
}
|
||||
|
||||
// Depth Stencil States
|
||||
{
|
||||
D3D11_DEPTH_STENCIL_DESC dsDesc;
|
||||
dsDesc.StencilEnable = FALSE;
|
||||
dsDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
||||
dsDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
||||
const D3D11_DEPTH_STENCILOP_DESC defaultStencilOp = { D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_COMPARISON_ALWAYS };
|
||||
dsDesc.FrontFace = defaultStencilOp;
|
||||
dsDesc.BackFace = defaultStencilOp;
|
||||
int32 index;
|
||||
#define CREATE_DEPTH_STENCIL_STATE(depthEnable, depthWrite) \
|
||||
dsDesc.DepthEnable = depthEnable; \
|
||||
dsDesc.DepthWriteMask = depthWrite ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; \
|
||||
for(int32 depthFunc = 1; depthFunc <= 8; depthFunc++) { \
|
||||
dsDesc.DepthFunc = (D3D11_COMPARISON_FUNC)depthFunc; \
|
||||
index = (int32)depthFunc + (depthEnable ? 0 : 9) + (depthWrite ? 0 : 18); \
|
||||
HRESULT result = _device->CreateDepthStencilState(&dsDesc, &DepthStencilStates[index]); \
|
||||
LOG_DIRECTX_RESULT_WITH_RETURN(result, true); }
|
||||
CREATE_DEPTH_STENCIL_STATE(false, false);
|
||||
CREATE_DEPTH_STENCIL_STATE(false, true);
|
||||
CREATE_DEPTH_STENCIL_STATE(true, true);
|
||||
CREATE_DEPTH_STENCIL_STATE(true, false);
|
||||
#undef CREATE_DEPTH_STENCIL_STATE
|
||||
}
|
||||
|
||||
_state = DeviceState::Ready;
|
||||
return GPUDeviceDX::Init();
|
||||
}
|
||||
@@ -624,20 +690,15 @@ void GPUDeviceDX11::Dispose()
|
||||
SAFE_RELEASE(_samplerPointWrap);
|
||||
SAFE_RELEASE(_samplerShadow);
|
||||
SAFE_RELEASE(_samplerShadowLinear);
|
||||
//
|
||||
for (auto i = BlendStates.Begin(); i.IsNotEnd(); ++i)
|
||||
{
|
||||
i->Value->Release();
|
||||
}
|
||||
for (auto i = DepthStencilStates.Begin(); i.IsNotEnd(); ++i)
|
||||
i->Value->Release();
|
||||
BlendStates.Clear();
|
||||
for (uint32 i = 0; i < ARRAY_COUNT(RasterizerStates); i++)
|
||||
{
|
||||
SAFE_RELEASE(RasterizerStates[i]);
|
||||
}
|
||||
for (uint32 i = 0; i < ARRAY_COUNT(DepthStencilStates); i++)
|
||||
{
|
||||
SAFE_RELEASE(DepthStencilStates[i]);
|
||||
}
|
||||
|
||||
// Clear DirectX stuff
|
||||
SAFE_DELETE(_mainContext);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#if GRAPHICS_API_DIRECTX11
|
||||
|
||||
class Engine;
|
||||
enum class StencilOperation : byte;
|
||||
class GPUContextDX11;
|
||||
class GPUSwapChainDX11;
|
||||
|
||||
@@ -23,6 +24,34 @@ class GPUDeviceDX11 : public GPUDeviceDX
|
||||
friend GPUSwapChainDX11;
|
||||
private:
|
||||
|
||||
struct DepthStencilMode
|
||||
{
|
||||
int8 DepthEnable : 1;
|
||||
int8 DepthWriteEnable : 1;
|
||||
int8 DepthClipEnable : 1;
|
||||
int8 StencilEnable : 1;
|
||||
uint8 StencilReadMask;
|
||||
uint8 StencilWriteMask;
|
||||
ComparisonFunc DepthFunc;
|
||||
ComparisonFunc StencilFunc;
|
||||
StencilOperation StencilFailOp;
|
||||
StencilOperation StencilDepthFailOp;
|
||||
StencilOperation StencilPassOp;
|
||||
|
||||
bool operator==(const DepthStencilMode& other) const
|
||||
{
|
||||
return Platform::MemoryCompare(this, &other, sizeof(DepthStencilMode)) == 0;
|
||||
}
|
||||
|
||||
friend uint32 GetHash(const DepthStencilMode& key)
|
||||
{
|
||||
uint32 hash = 0;
|
||||
for (int32 i = 0; i < sizeof(DepthStencilMode) / 4; i++)
|
||||
CombineHash(hash, ((uint32*)&key)[i]);
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
// Private Stuff
|
||||
ID3D11Device* _device = nullptr;
|
||||
ID3D11DeviceContext* _imContext = nullptr;
|
||||
@@ -40,10 +69,10 @@ private:
|
||||
ID3D11SamplerState* _samplerShadowLinear = nullptr;
|
||||
|
||||
// Shared data for pipeline states
|
||||
CriticalSection BlendStatesWriteLocker;
|
||||
CriticalSection StatesWriteLocker;
|
||||
Dictionary<BlendingMode, ID3D11BlendState*> BlendStates;
|
||||
Dictionary<DepthStencilMode, ID3D11DepthStencilState*> DepthStencilStates;
|
||||
ID3D11RasterizerState* RasterizerStates[3 * 2 * 2]; // Index = CullMode[0-2] + Wireframe[0?3] + DepthClipEnable[0?6]
|
||||
ID3D11DepthStencilState* DepthStencilStates[9 * 2 * 2]; // Index = ComparisonFunc[0-8] + DepthTestEnable[0?9] + DepthWriteEnable[0?18]
|
||||
|
||||
public:
|
||||
static GPUDevice* Create();
|
||||
@@ -75,6 +104,7 @@ public:
|
||||
return _mainContext;
|
||||
}
|
||||
|
||||
ID3D11DepthStencilState* GetDepthStencilState(const void* descriptionPtr);
|
||||
ID3D11BlendState* GetBlendState(const BlendingMode& blending);
|
||||
|
||||
public:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
void GPUPipelineStateDX11::OnReleaseGPU()
|
||||
{
|
||||
DepthStencilState = nullptr;
|
||||
BlendState = nullptr;
|
||||
VS = nullptr;
|
||||
#if GPU_ALLOW_TESSELLATION_SHADERS
|
||||
@@ -58,8 +59,8 @@ bool GPUPipelineStateDX11::Init(const Description& desc)
|
||||
#endif
|
||||
|
||||
// States
|
||||
DepthStencilStateIndex = static_cast<int32>(desc.DepthFunc) + (desc.DepthEnable ? 0 : 9) + (desc.DepthWriteEnable ? 0 : 18);
|
||||
RasterizerStateIndex = static_cast<int32>(desc.CullMode) + (desc.Wireframe ? 0 : 3) + (desc.DepthClipEnable ? 0 : 6);
|
||||
DepthStencilState = _device->GetDepthStencilState(&desc);
|
||||
BlendState = _device->GetBlendState(desc.BlendMode);
|
||||
|
||||
// Calculate approx. memory usage (just to set sth)
|
||||
|
||||
@@ -15,8 +15,8 @@ class GPUPipelineStateDX11 : public GPUResourceDX11<GPUPipelineState>
|
||||
{
|
||||
public:
|
||||
|
||||
int32 DepthStencilStateIndex;
|
||||
int32 RasterizerStateIndex;
|
||||
ID3D11DepthStencilState* DepthStencilState = nullptr;
|
||||
ID3D11BlendState* BlendState = nullptr;
|
||||
GPUShaderProgramVSDX11* VS = nullptr;
|
||||
#if GPU_ALLOW_TESSELLATION_SHADERS
|
||||
|
||||
@@ -77,7 +77,7 @@ GPUDevice* GPUDeviceDX12::Create()
|
||||
#endif
|
||||
#ifdef __ID3D12DeviceRemovedExtendedDataSettings_FWD_DEFINED__
|
||||
ComPtr<ID3D12DeviceRemovedExtendedDataSettings> dredSettings;
|
||||
VALIDATE_DIRECTX_CALL(D3D12GetDebugInterface(IID_PPV_ARGS(&dredSettings)));
|
||||
D3D12GetDebugInterface(IID_PPV_ARGS(&dredSettings));
|
||||
if (dredSettings)
|
||||
{
|
||||
// Turn on AutoBreadcrumbs and Page Fault reporting
|
||||
|
||||
@@ -723,11 +723,14 @@ void GPUContextVulkan::FrameBegin()
|
||||
Platform::MemoryCopy(_samplerHandles, _device->HelperResources.GetStaticSamplers(), sizeof(VkSampler) * GPU_STATIC_SAMPLERS_COUNT);
|
||||
Platform::MemoryClear(_samplerHandles + GPU_STATIC_SAMPLERS_COUNT, sizeof(_samplerHandles) - sizeof(VkSampler) * GPU_STATIC_SAMPLERS_COUNT);
|
||||
|
||||
// Init command buffer
|
||||
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
|
||||
vkCmdSetStencilReference(cmdBuffer->GetHandle(), VK_STENCIL_FRONT_AND_BACK, _stencilRef);
|
||||
|
||||
#if VULKAN_RESET_QUERY_POOLS
|
||||
// Reset pending queries
|
||||
if (_device->QueriesToReset.HasItems())
|
||||
{
|
||||
const auto cmdBuffer = _cmdBufferManager->GetCmdBuffer();
|
||||
for (auto query : _device->QueriesToReset)
|
||||
query->Reset(cmdBuffer);
|
||||
_device->QueriesToReset.Clear();
|
||||
|
||||
@@ -34,6 +34,49 @@ static VkStencilOp ToVulkanStencilOp(const StencilOperation value)
|
||||
}
|
||||
}
|
||||
|
||||
static VkBlendFactor ToVulkanBlendFactor(const BlendingMode::Blend value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case BlendingMode::Blend::Zero:
|
||||
return VK_BLEND_FACTOR_ZERO;
|
||||
case BlendingMode::Blend::One:
|
||||
return VK_BLEND_FACTOR_ONE;
|
||||
case BlendingMode::Blend::SrcColor:
|
||||
return VK_BLEND_FACTOR_SRC_COLOR;
|
||||
case BlendingMode::Blend::InvSrcColor:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
|
||||
case BlendingMode::Blend::SrcAlpha:
|
||||
return VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
case BlendingMode::Blend::InvSrcAlpha:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
case BlendingMode::Blend::DestAlpha:
|
||||
return VK_BLEND_FACTOR_DST_ALPHA;
|
||||
case BlendingMode::Blend::InvDestAlpha:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
|
||||
case BlendingMode::Blend::DestColor:
|
||||
return VK_BLEND_FACTOR_DST_COLOR;
|
||||
case BlendingMode::Blend::InvDestColor:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
|
||||
case BlendingMode::Blend::SrcAlphaSat:
|
||||
return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
|
||||
case BlendingMode::Blend::BlendFactor:
|
||||
return VK_BLEND_FACTOR_CONSTANT_COLOR;
|
||||
case BlendingMode::Blend::BlendInvFactor:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
|
||||
case BlendingMode::Blend::Src1Color:
|
||||
return VK_BLEND_FACTOR_SRC1_COLOR;
|
||||
case BlendingMode::Blend::InvSrc1Color:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR;
|
||||
case BlendingMode::Blend::Src1Alpha:
|
||||
return VK_BLEND_FACTOR_SRC1_ALPHA;
|
||||
case BlendingMode::Blend::InvSrc1Alpha:
|
||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA;
|
||||
default:
|
||||
return VK_BLEND_FACTOR_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
GPUShaderProgramCSVulkan::~GPUShaderProgramCSVulkan()
|
||||
{
|
||||
if (_pipelineState)
|
||||
@@ -316,7 +359,13 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_VIEWPORT;
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_SCISSOR;
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_STENCIL_REFERENCE;
|
||||
static_assert(ARRAY_COUNT(_dynamicStates) <= 3, "Invalid dynamic states array.");
|
||||
#define IsBlendUsingBlendFactor(blend) blend == BlendingMode::Blend::BlendFactor || blend == BlendingMode::Blend::BlendInvFactor
|
||||
if (desc.BlendMode.BlendEnable && (
|
||||
IsBlendUsingBlendFactor(desc.BlendMode.SrcBlend) || IsBlendUsingBlendFactor(desc.BlendMode.SrcBlendAlpha) ||
|
||||
IsBlendUsingBlendFactor(desc.BlendMode.DestBlend) || IsBlendUsingBlendFactor(desc.BlendMode.DestBlendAlpha)))
|
||||
_dynamicStates[_descDynamic.dynamicStateCount++] = VK_DYNAMIC_STATE_BLEND_CONSTANTS;
|
||||
#undef IsBlendUsingBlendFactor
|
||||
static_assert(ARRAY_COUNT(_dynamicStates) <= 4, "Invalid dynamic states array.");
|
||||
_desc.pDynamicState = &_descDynamic;
|
||||
|
||||
// Multisample
|
||||
@@ -337,7 +386,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
|
||||
_descDepthStencil.front.failOp = ToVulkanStencilOp(desc.StencilFailOp);
|
||||
_descDepthStencil.front.depthFailOp = ToVulkanStencilOp(desc.StencilDepthFailOp);
|
||||
_descDepthStencil.front.passOp = ToVulkanStencilOp(desc.StencilPassOp);
|
||||
_descDepthStencil.front = _descDepthStencil.back;
|
||||
_descDepthStencil.back = _descDepthStencil.front;
|
||||
_desc.pDepthStencilState = &_descDepthStencil;
|
||||
DepthReadEnable = desc.DepthEnable && desc.DepthFunc != ComparisonFunc::Always;
|
||||
DepthWriteEnable = _descDepthStencil.depthWriteEnable;
|
||||
@@ -370,21 +419,21 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
|
||||
{
|
||||
auto& blend = _descColorBlendAttachments[0];
|
||||
blend.blendEnable = desc.BlendMode.BlendEnable;
|
||||
blend.srcColorBlendFactor = RenderToolsVulkan::ToVulkanBlendFactor(desc.BlendMode.SrcBlend);
|
||||
blend.dstColorBlendFactor = RenderToolsVulkan::ToVulkanBlendFactor(desc.BlendMode.DestBlend);
|
||||
blend.srcColorBlendFactor = ToVulkanBlendFactor(desc.BlendMode.SrcBlend);
|
||||
blend.dstColorBlendFactor = ToVulkanBlendFactor(desc.BlendMode.DestBlend);
|
||||
blend.colorBlendOp = RenderToolsVulkan::ToVulkanBlendOp(desc.BlendMode.BlendOp);
|
||||
blend.srcAlphaBlendFactor = RenderToolsVulkan::ToVulkanBlendFactor(desc.BlendMode.SrcBlendAlpha);
|
||||
blend.dstAlphaBlendFactor = RenderToolsVulkan::ToVulkanBlendFactor(desc.BlendMode.DestBlendAlpha);
|
||||
blend.srcAlphaBlendFactor = ToVulkanBlendFactor(desc.BlendMode.SrcBlendAlpha);
|
||||
blend.dstAlphaBlendFactor = ToVulkanBlendFactor(desc.BlendMode.DestBlendAlpha);
|
||||
blend.alphaBlendOp = RenderToolsVulkan::ToVulkanBlendOp(desc.BlendMode.BlendOpAlpha);
|
||||
blend.colorWriteMask = (VkColorComponentFlags)desc.BlendMode.RenderTargetWriteMask;
|
||||
}
|
||||
for (int32 i = 1; i < GPU_MAX_RT_BINDED; i++)
|
||||
_descColorBlendAttachments[i] = _descColorBlendAttachments[i - 1];
|
||||
_descColorBlend.pAttachments = _descColorBlendAttachments;
|
||||
_descColorBlend.blendConstants[0] = 0.0f;
|
||||
_descColorBlend.blendConstants[1] = 0.0f;
|
||||
_descColorBlend.blendConstants[2] = 0.0f;
|
||||
_descColorBlend.blendConstants[3] = 0.0f;
|
||||
_descColorBlend.blendConstants[0] = 1.0f;
|
||||
_descColorBlend.blendConstants[1] = 1.0f;
|
||||
_descColorBlend.blendConstants[2] = 1.0f;
|
||||
_descColorBlend.blendConstants[3] = 1.0f;
|
||||
_desc.pColorBlendState = &_descColorBlend;
|
||||
|
||||
ASSERT(DSWriteContainer.DescriptorWrites.IsEmpty());
|
||||
|
||||
@@ -98,7 +98,7 @@ private:
|
||||
#endif
|
||||
VkPipelineViewportStateCreateInfo _descViewport;
|
||||
VkPipelineDynamicStateCreateInfo _descDynamic;
|
||||
VkDynamicState _dynamicStates[3];
|
||||
VkDynamicState _dynamicStates[4];
|
||||
VkPipelineMultisampleStateCreateInfo _descMultisample;
|
||||
VkPipelineDepthStencilStateCreateInfo _descDepthStencil;
|
||||
VkPipelineRasterizationStateCreateInfo _descRasterization;
|
||||
|
||||
@@ -122,28 +122,6 @@ VkFormat RenderToolsVulkan::PixelFormatToVkFormat[110] =
|
||||
VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, // NV12
|
||||
};
|
||||
|
||||
VkBlendFactor RenderToolsVulkan::BlendToVkBlendFactor[20] =
|
||||
{
|
||||
VK_BLEND_FACTOR_MAX_ENUM,
|
||||
VK_BLEND_FACTOR_ZERO, // Zero
|
||||
VK_BLEND_FACTOR_ONE, // One
|
||||
VK_BLEND_FACTOR_SRC_COLOR, // SrcColor
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR, // InvSrcColor
|
||||
VK_BLEND_FACTOR_SRC_ALPHA, // SrcAlpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, // InvSrcAlpha
|
||||
VK_BLEND_FACTOR_DST_ALPHA, // DestAlpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, // InvDestAlpha
|
||||
VK_BLEND_FACTOR_DST_COLOR, // DestColor,
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR, // InvDestColor
|
||||
VK_BLEND_FACTOR_SRC_ALPHA_SATURATE, // SrcAlphaSat
|
||||
VK_BLEND_FACTOR_CONSTANT_ALPHA, // BlendFactor
|
||||
VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA, // BlendInvFactor
|
||||
VK_BLEND_FACTOR_SRC1_COLOR, // Src1Color
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR, // InvSrc1Color
|
||||
VK_BLEND_FACTOR_SRC1_ALPHA, // Src1Alpha
|
||||
VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA, // InvSrc1Alpha
|
||||
};
|
||||
|
||||
VkBlendOp RenderToolsVulkan::OperationToVkBlendOp[6] =
|
||||
{
|
||||
VK_BLEND_OP_MAX_ENUM,
|
||||
|
||||
@@ -164,16 +164,6 @@ public:
|
||||
return PixelFormatToVkFormat[(int32)value];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts Flax blend mode to the Vulkan blend factor.
|
||||
/// </summary>
|
||||
/// <param name="value">The Flax blend mode.</param>
|
||||
/// <returns>The Vulkan blend factor.</returns>
|
||||
static FORCE_INLINE VkBlendFactor ToVulkanBlendFactor(const BlendingMode::Blend value)
|
||||
{
|
||||
return BlendToVkBlendFactor[(int32)value];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts Flax blend operation to the Vulkan blend operation.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user