Skip to content

Commit

Permalink
Fixed a number of MSVC conformance mode issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 9, 2023
1 parent 00464ed commit 59b2c51
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Common/interface/AdvancedMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,9 +1444,9 @@ TriangulatePolygon3D(const std::vector<Vector3<ComponentType>>& Polygon, bool Ve
const auto AbsNormal = abs(Normal);

Vector3<ComponentType> Tangent;
if (AbsNormal.z > std::max(AbsNormal.x, AbsNormal.y))
if (AbsNormal.z > (std::max)(AbsNormal.x, AbsNormal.y))
Tangent = cross(Vector3<ComponentType>{ComponentType{0}, ComponentType{1}, ComponentType{0}}, Normal);
else if (AbsNormal.y > std::max(AbsNormal.x, AbsNormal.z))
else if (AbsNormal.y > (std::max)(AbsNormal.x, AbsNormal.z))
Tangent = cross(Vector3<ComponentType>{ComponentType{1}, ComponentType{0}, ComponentType{0}}, Normal);
else
Tangent = cross(Vector3<ComponentType>{ComponentType{0}, ComponentType{0}, ComponentType{1}}, Normal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ class ShaderResourceCacheD3D11 : public ShaderResourceCacheBase
typename CachedResourceTraits<ResRange>::D3D11ResourceType**>
GetResourceArrays(Uint32 ShaderInd) const
{
using CachedResourceType = CachedResourceTraits<ResRange>::CachedResourceType;
using D3D11ResourceType = CachedResourceTraits<ResRange>::D3D11ResourceType;
using CachedResourceType = typename CachedResourceTraits<ResRange>::CachedResourceType;
using D3D11ResourceType = typename CachedResourceTraits<ResRange>::D3D11ResourceType;
static_assert(alignof(CachedResourceType) == alignof(D3D11ResourceType*), "Alignment mismatch, pointer to D3D11 resource may not be properly aligned");

const auto DataOffset = GetResourceDataOffset<ResRange>(ShaderInd);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -83,8 +83,10 @@ class ShaderVariableManagerD3D11 : ShaderVariableManagerBase<EngineD3D11ImplTrai
struct ShaderVariableD3D11Base : ShaderVariableBase<ThisImplType, ShaderVariableManagerD3D11, IShaderResourceVariableD3D>
{
public:
using TBase = ShaderVariableBase<ThisImplType, ShaderVariableManagerD3D11, IShaderResourceVariableD3D>;

ShaderVariableD3D11Base(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
ShaderVariableBase<ThisImplType, ShaderVariableManagerD3D11, IShaderResourceVariableD3D>{ParentLayout, ResIndex}
TBase{ParentLayout, ResIndex}
{}

// clang-format off
Expand All @@ -94,6 +96,9 @@ class ShaderVariableManagerD3D11 : ShaderVariableManagerBase<EngineD3D11ImplTrai
ShaderVariableD3D11Base& operator= ( ShaderVariableD3D11Base&&) = delete;
// clang-format on

using TBase::m_ParentManager;
using TBase::m_ResIndex;

const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetResourceAttribs(m_ResIndex); }

virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final
Expand All @@ -111,13 +116,13 @@ class ShaderVariableManagerD3D11 : ShaderVariableManagerBase<EngineD3D11ImplTrai

virtual void DILIGENT_CALL_TYPE GetHLSLResourceDesc(HLSLShaderResourceDesc& HLSLResDesc) const override final
{
GetResourceDesc(HLSLResDesc);
this->GetResourceDesc(HLSLResDesc);
HLSLResDesc.ShaderRegister = GetAttribs().BindPoints[m_ParentManager.m_ShaderTypeIndex];
}

virtual IDeviceObject* DILIGENT_CALL_TYPE Get(Uint32 ArrayIndex) const override final
{
VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
VERIFY_EXPR(ArrayIndex < this->GetDesc().ArraySize);
return m_ParentManager.m_ResourceCache.GetResource<ResRange>(GetAttribs().BindPoints + ArrayIndex).Get();
}

Expand Down
19 changes: 18 additions & 1 deletion Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -47,6 +47,23 @@
namespace Diligent
{

bool CheckAdapterD3D11Compatibility(IDXGIAdapter1* pDXGIAdapter, D3D_FEATURE_LEVEL FeatureLevel)
{
auto hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.
0,
0, // Flags.
&FeatureLevel, // Feature levels.
1, // Number of feature levels
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
nullptr, // No need to keep the D3D device reference.
nullptr, // Feature level of the created adapter.
nullptr // No need to keep the D3D device context reference.
);
return SUCCEEDED(hr);
}

/// Engine factory for D3D11 implementation
class EngineFactoryD3D11Impl : public EngineFactoryD3DBase<IEngineFactoryD3D11, RENDER_DEVICE_TYPE_D3D11>
{
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineD3D12/src/D3D12Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Char* GetD3D12DescriptorHeapTypeLiteralName(D3D12_DESCRIPTOR_HEAP_TYPE Typ
static_assert(D3D12_DESCRIPTOR_HEAP_TYPE_RTV == 2, "D3D12_DESCRIPTOR_HEAP_TYPE_RTV is expected to be 2");
static_assert(D3D12_DESCRIPTOR_HEAP_TYPE_DSV == 3, "D3D12_DESCRIPTOR_HEAP_TYPE_DSV is expected to be 3");
// clang-format on
static constexpr std::array<Char*, D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES> HeapTypeNames{
static constexpr std::array<const Char*, D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES> HeapTypeNames{
"D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV",
"D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER",
"D3D12_DESCRIPTOR_HEAP_TYPE_RTV",
Expand Down
7 changes: 7 additions & 0 deletions Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
namespace Diligent
{

bool CheckAdapterD3D12Compatibility(IDXGIAdapter1* pDXGIAdapter,
D3D_FEATURE_LEVEL FeatureLevel)
{
auto hr = D3D12CreateDevice(pDXGIAdapter, FeatureLevel, _uuidof(ID3D12Device), nullptr);
return SUCCEEDED(hr);
}

/// Engine factory for D3D12 implementation
class EngineFactoryD3D12Impl : public EngineFactoryD3DBase<IEngineFactoryD3D12, RENDER_DEVICE_TYPE_D3D12>
{
Expand Down
3 changes: 2 additions & 1 deletion Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -36,6 +36,7 @@
#include "WinHPostface.h"

#include "RenderDeviceD3D12Impl.hpp"
#include "StringTools.hpp"

namespace Diligent
{
Expand Down
22 changes: 6 additions & 16 deletions Graphics/GraphicsEngineD3DBase/include/EngineFactoryD3DBase.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -36,6 +36,9 @@
namespace Diligent
{

bool CheckAdapterD3D11Compatibility(IDXGIAdapter1* pDXGIAdapter, D3D_FEATURE_LEVEL FeatureLevel);
bool CheckAdapterD3D12Compatibility(IDXGIAdapter1* pDXGIAdapter, D3D_FEATURE_LEVEL FeatureLevel);

template <typename BaseInterface, RENDER_DEVICE_TYPE DevType>
class EngineFactoryD3DBase : public EngineFactoryBase<BaseInterface>
{
Expand Down Expand Up @@ -302,27 +305,14 @@ class EngineFactoryD3DBase : public EngineFactoryBase<BaseInterface>
bool CheckAdapterCompatibility<RENDER_DEVICE_TYPE_D3D11>(IDXGIAdapter1* pDXGIAdapter,
D3D_FEATURE_LEVEL FeatureLevel) const
{
auto hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.
0,
0, // Flags.
&FeatureLevel, // Feature levels.
1, // Number of feature levels
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
nullptr, // No need to keep the D3D device reference.
nullptr, // Feature level of the created adapter.
nullptr // No need to keep the D3D device context reference.
);
return SUCCEEDED(hr);
return CheckAdapterD3D11Compatibility(pDXGIAdapter, FeatureLevel);
}

template <>
bool CheckAdapterCompatibility<RENDER_DEVICE_TYPE_D3D12>(IDXGIAdapter1* pDXGIAdapter,
D3D_FEATURE_LEVEL FeatureLevel) const
{
auto hr = D3D12CreateDevice(pDXGIAdapter, FeatureLevel, _uuidof(ID3D12Device), nullptr);
return SUCCEEDED(hr);
return CheckAdapterD3D12Compatibility(pDXGIAdapter, FeatureLevel);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -57,7 +57,7 @@ class RenderDeviceD3DBase : public RenderDeviceBase<EngineImplTraits>
// Flag texture formats always supported in D3D11 and D3D12

// clang-format off
#define FLAG_FORMAT(Fmt, IsSupported) m_TextureFormatsInfo[Fmt].Supported=IsSupported
#define FLAG_FORMAT(Fmt, IsSupported) this->m_TextureFormatsInfo[Fmt].Supported=IsSupported

FLAG_FORMAT(TEX_FORMAT_RGBA32_TYPELESS, true);
FLAG_FORMAT(TEX_FORMAT_RGBA32_FLOAT, true);
Expand Down Expand Up @@ -161,9 +161,9 @@ class RenderDeviceD3DBase : public RenderDeviceBase<EngineImplTraits>
#undef FLAG_FORMAT
// clang-format on

m_DeviceInfo.NDC = NDCAttribs{0.0f, 1.0f, -0.5f};
this->m_DeviceInfo.NDC = NDCAttribs{0.0f, 1.0f, -0.5f};

if (m_AdapterInfo.Vendor == ADAPTER_VENDOR_NVIDIA)
if (this->m_AdapterInfo.Vendor == ADAPTER_VENDOR_NVIDIA)
{
m_NVApi.Load();
}
Expand Down
8 changes: 7 additions & 1 deletion Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -29,6 +29,8 @@

#include <VersionHelpers.h>
#include "SwapChainBase.hpp"
#include "DXGITypeConversions.hpp"
#include "GraphicsAccessories.hpp"

/// \file
/// Base implementation of a D3D swap chain
Expand Down Expand Up @@ -360,6 +362,10 @@ class SwapChainD3DBase : public SwapChainBase<BaseInterface>

virtual void SetDXGIDeviceMaximumFrameLatency() {}

using TBase::m_pRenderDevice;
using TBase::m_SwapChainDesc;
using TBase::m_DesiredPreTransform;

FullScreenModeDesc m_FSDesc;
CComPtr<DXGISwapChainType> m_pSwapChain;
NativeWindow m_Window;
Expand Down

0 comments on commit 59b2c51

Please sign in to comment.