From 00e8dcdb71c6ae3fefd83958ead19b1d72f544e4 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 26 Jan 2020 15:21:35 -0800 Subject: More .h -> .hpp renamings --- Graphics/GLSLTools/src/GLSLSourceBuilder.cpp | 2 +- .../interface/ColorConversion.h | 5 +- Graphics/GraphicsEngine/include/EngineMemory.h | 6 +- Graphics/GraphicsEngineD3D11/CMakeLists.txt | 2 +- .../include/D3D11TypeConversions.h | 192 ------ .../include/D3D11TypeConversions.hpp | 192 ++++++ Graphics/GraphicsEngineD3D11/include/pch.h | 2 +- .../GraphicsEngineD3D11/src/BufferD3D11Impl.cpp | 2 +- .../src/D3D11TypeConversions.cpp | 2 +- .../src/DeviceContextD3D11Impl.cpp | 2 +- .../GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp | 2 +- .../src/RenderDeviceD3D11Impl.cpp | 2 +- .../GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp | 2 +- .../GraphicsEngineD3D11/src/Texture1D_D3D11.cpp | 2 +- .../GraphicsEngineD3D11/src/Texture2D_D3D11.cpp | 2 +- .../GraphicsEngineD3D11/src/Texture3D_D3D11.cpp | 2 +- .../GraphicsEngineD3D11/src/TextureBaseD3D11.cpp | 2 +- Graphics/GraphicsEngineD3D12/CMakeLists.txt | 2 +- .../include/D3D12TypeConversions.h | 74 --- .../include/D3D12TypeConversions.hpp | 74 +++ .../GraphicsEngineD3D12/src/BufferD3D12Impl.cpp | 4 +- .../GraphicsEngineD3D12/src/CommandContext.cpp | 2 +- .../src/D3D12TypeConversions.cpp | 4 +- .../src/DeviceContextD3D12Impl.cpp | 4 +- .../GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp | 2 +- .../src/PipelineStateD3D12Impl.cpp | 4 +- .../GraphicsEngineD3D12/src/QueryManagerD3D12.cpp | 2 +- .../src/RenderDeviceD3D12Impl.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 2 +- .../GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp | 2 +- .../GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp | 2 +- .../GraphicsEngineD3D12/src/TextureD3D12Impl.cpp | 4 +- Graphics/GraphicsEngineD3DBase/CMakeLists.txt | 2 +- .../include/D3DViewDescConversionImpl.hpp | 2 +- .../include/DXGITypeConversions.h | 41 -- .../include/DXGITypeConversions.hpp | 41 ++ .../include/EngineFactoryD3DBase.hpp | 2 +- .../src/DXGITypeConversions.cpp | 2 +- Graphics/GraphicsEngineOpenGL/CMakeLists.txt | 2 +- .../include/GLTypeConversions.h | 308 ---------- .../include/GLTypeConversions.hpp | 308 ++++++++++ Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp | 2 +- .../GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp | 2 +- .../src/DeviceContextGLImpl.cpp | 2 +- .../src/EngineFactoryOpenGL.cpp | 2 +- .../GraphicsEngineOpenGL/src/GLContextState.cpp | 2 +- .../GraphicsEngineOpenGL/src/GLContextWindows.cpp | 2 +- .../GraphicsEngineOpenGL/src/GLTypeConversions.cpp | 2 +- .../src/RenderDeviceGLImpl.cpp | 2 +- .../GraphicsEngineOpenGL/src/SamplerGLImpl.cpp | 2 +- .../src/Texture1DArray_OGL.cpp | 2 +- .../GraphicsEngineOpenGL/src/Texture1D_OGL.cpp | 2 +- .../src/Texture2DArray_OGL.cpp | 2 +- .../GraphicsEngineOpenGL/src/Texture2D_OGL.cpp | 2 +- .../GraphicsEngineOpenGL/src/Texture3D_OGL.cpp | 2 +- .../GraphicsEngineOpenGL/src/TextureBaseGL.cpp | 2 +- .../src/TextureCubeArray_OGL.cpp | 2 +- .../GraphicsEngineOpenGL/src/TextureCube_OGL.cpp | 2 +- Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp | 2 +- .../GraphicsTools/interface/CommonlyUsedStates.h | 5 +- .../GraphicsTools/interface/GraphicsUtilities.h | 5 +- .../GraphicsTools/src/TextureUploaderD3D11.cpp | 2 +- Graphics/HLSL2GLSLConverterLib/CMakeLists.txt | 4 +- .../include/HLSL2GLSLConverterImpl.h | 661 --------------------- .../include/HLSL2GLSLConverterImpl.hpp | 661 +++++++++++++++++++++ .../include/HLSL2GLSLConverterObject.h | 55 -- .../include/HLSL2GLSLConverterObject.hpp | 55 ++ .../interface/HLSL2GLSLConverter.h | 17 +- .../src/HLSL2GLSLConverterImpl.cpp | 2 +- .../src/HLSL2GLSLConverterObject.cpp | 4 +- 70 files changed, 1414 insertions(+), 1406 deletions(-) delete mode 100644 Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h create mode 100644 Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.hpp delete mode 100644 Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h create mode 100644 Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.hpp delete mode 100644 Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h create mode 100644 Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp delete mode 100644 Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h create mode 100644 Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.hpp delete mode 100644 Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.h create mode 100644 Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.hpp (limited to 'Graphics') diff --git a/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp b/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp index a93f0f98..539d998f 100644 --- a/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp +++ b/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp @@ -30,7 +30,7 @@ #include "GLSLSourceBuilder.hpp" #include "DebugUtilities.h" -#include "HLSL2GLSLConverterImpl.h" +#include "HLSL2GLSLConverterImpl.hpp" #include "RefCntAutoPtr.hpp" #include "DataBlobImpl.hpp" diff --git a/Graphics/GraphicsAccessories/interface/ColorConversion.h b/Graphics/GraphicsAccessories/interface/ColorConversion.h index 97fae201..ee064a78 100644 --- a/Graphics/GraphicsAccessories/interface/ColorConversion.h +++ b/Graphics/GraphicsAccessories/interface/ColorConversion.h @@ -30,8 +30,7 @@ #include #include "../../../Primitives/interface/BasicTypes.h" -namespace Diligent -{ +DILIGENT_BEGIN_NAMESPACE(Diligent) // https://en.wikipedia.org/wiki/SRGB inline float LinearToSRGB(float x) @@ -58,4 +57,4 @@ inline float FastSRGBToLinear(float x) return x * (x * (x * 0.305306011f + 0.682171111f) + 0.012522878f); } -} // namespace Diligent +DILIGENT_END_NAMESPACE // namespace Diligent diff --git a/Graphics/GraphicsEngine/include/EngineMemory.h b/Graphics/GraphicsEngine/include/EngineMemory.h index b3197aed..8211bf35 100644 --- a/Graphics/GraphicsEngine/include/EngineMemory.h +++ b/Graphics/GraphicsEngine/include/EngineMemory.h @@ -32,8 +32,8 @@ #include "MemoryAllocator.h" -namespace Diligent -{ +DILIGENT_BEGIN_NAMESPACE(Diligent) + /// Sets raw memory allocator. This function must be called before any memory allocation/deallocation function /// is called. void SetRawAllocator(IMemoryAllocator* pRawAllocator); @@ -47,7 +47,7 @@ IMemoryAllocator& GetStringAllocator(); #define ALLOCATE(Allocator, Desc, Type, Count) reinterpret_cast(ALLOCATE_RAW(Allocator, Desc, sizeof(Type) * (Count))) #define FREE(Allocator, Ptr) Allocator.Free(Ptr) -} // namespace Diligent +DILIGENT_END_NAMESPACE // namespace Diligent #if 0 diff --git a/Graphics/GraphicsEngineD3D11/CMakeLists.txt b/Graphics/GraphicsEngineD3D11/CMakeLists.txt index 614f6264..91b61477 100644 --- a/Graphics/GraphicsEngineD3D11/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D11/CMakeLists.txt @@ -7,7 +7,7 @@ set(INCLUDE include/BufferD3D11Impl.hpp include/BufferViewD3D11Impl.hpp include/CommandListD3D11Impl.hpp - include/D3D11TypeConversions.h + include/D3D11TypeConversions.hpp include/D3D11TypeDefinitions.h include/DeviceContextD3D11Impl.hpp include/DisjointQueryPool.hpp diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h deleted file mode 100644 index a2126492..00000000 --- a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Type conversion routines - -#include "GraphicsTypes.h" -#include "DXGITypeConversions.h" - -namespace Diligent -{ - -inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags) -{ - // clang-format off - UINT D3D11BindFlags = 0; - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_VERTEX_BUFFER) ? D3D11_BIND_VERTEX_BUFFER : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_INDEX_BUFFER) ? D3D11_BIND_INDEX_BUFFER : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNIFORM_BUFFER) ? D3D11_BIND_CONSTANT_BUFFER : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_SHADER_RESOURCE) ? D3D11_BIND_SHADER_RESOURCE : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_STREAM_OUTPUT) ? D3D11_BIND_STREAM_OUTPUT : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_RENDER_TARGET) ? D3D11_BIND_RENDER_TARGET : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_DEPTH_STENCIL) ? D3D11_BIND_DEPTH_STENCIL : 0); - D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNORDERED_ACCESS) ? D3D11_BIND_UNORDERED_ACCESS : 0); - // clang-format on - return D3D11BindFlags; -} - -inline BIND_FLAGS D3D11BindFlagsToBindFlags(UINT D3D11BindFlags) -{ - BIND_FLAGS BindFlags = BIND_NONE; - // clang-format off - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_VERTEX_BUFFER) ? BIND_VERTEX_BUFFER : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_INDEX_BUFFER) ? BIND_INDEX_BUFFER : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_CONSTANT_BUFFER) ? BIND_UNIFORM_BUFFER : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_SHADER_RESOURCE) ? BIND_SHADER_RESOURCE : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_STREAM_OUTPUT) ? BIND_STREAM_OUTPUT : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_RENDER_TARGET) ? BIND_RENDER_TARGET : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_DEPTH_STENCIL) ? BIND_DEPTH_STENCIL : BIND_NONE); - BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? BIND_UNORDERED_ACCESS : BIND_NONE); - VERIFY_EXPR( (D3D11BindFlags & - (D3D11_BIND_VERTEX_BUFFER|D3D11_BIND_INDEX_BUFFER|D3D11_BIND_CONSTANT_BUFFER| - D3D11_BIND_SHADER_RESOURCE|D3D11_BIND_STREAM_OUTPUT|D3D11_BIND_RENDER_TARGET| - D3D11_BIND_DEPTH_STENCIL|D3D11_BIND_UNORDERED_ACCESS)) == BindFlagsToD3D11BindFlags(BindFlags)); - // clang-format on - return BindFlags; -} - -D3D11_PRIMITIVE_TOPOLOGY TopologyToD3D11Topology(PRIMITIVE_TOPOLOGY Topology); - -inline D3D11_USAGE UsageToD3D11Usage(USAGE Usage) -{ - switch (Usage) - { - // clang-format off - case USAGE_STATIC: return D3D11_USAGE_IMMUTABLE; - case USAGE_DEFAULT: return D3D11_USAGE_DEFAULT; - case USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC; - case USAGE_STAGING: return D3D11_USAGE_STAGING; - // clang-format on - default: UNEXPECTED("Unknow usage"); return D3D11_USAGE_DEFAULT; - } -} - -inline USAGE D3D11UsageToUsage(D3D11_USAGE D3D11Usage) -{ - switch (D3D11Usage) - { - // clang-format off - case D3D11_USAGE_IMMUTABLE: return USAGE_STATIC; - case D3D11_USAGE_DEFAULT: return USAGE_DEFAULT; - case D3D11_USAGE_DYNAMIC: return USAGE_DYNAMIC; - case D3D11_USAGE_STAGING: return USAGE_STAGING; - // clang-format on - default: UNEXPECTED("Unknow D3D11 usage"); return USAGE_DEFAULT; - } -} - -inline void MapParamsToD3D11MapParams(MAP_TYPE MapType, Uint32 MapFlags, D3D11_MAP& d3d11MapType, UINT& d3d11MapFlags) -{ - d3d11MapType = static_cast(0); - switch (MapType) - { - case MAP_READ: - d3d11MapType = D3D11_MAP_READ; - break; - - case MAP_WRITE: - if (MapFlags & MAP_FLAG_DISCARD) - d3d11MapType = D3D11_MAP_WRITE_DISCARD; - else if (MapFlags & MAP_FLAG_NO_OVERWRITE) - d3d11MapType = D3D11_MAP_WRITE_NO_OVERWRITE; - else - d3d11MapType = D3D11_MAP_WRITE; - break; - - case MAP_READ_WRITE: - d3d11MapType = D3D11_MAP_READ_WRITE; - break; - - default: - UNEXPECTED("Unknown map type"); - } - - d3d11MapFlags = 0; - d3d11MapFlags |= (MapFlags & MAP_FLAG_DO_NOT_WAIT) ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0; -} - -inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags) -{ - UINT D3D11CPUAccessFlags = 0; - D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_READ) ? D3D11_CPU_ACCESS_READ : 0; - D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_WRITE) ? D3D11_CPU_ACCESS_WRITE : 0; - return D3D11CPUAccessFlags; -} - -inline CPU_ACCESS_FLAGS D3D11CPUAccessFlagsToCPUAccessFlags(UINT D3D11CPUAccessFlags) -{ - CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_NONE; - CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_READ) ? CPU_ACCESS_READ : CPU_ACCESS_NONE; - CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) ? CPU_ACCESS_WRITE : CPU_ACCESS_NONE; - VERIFY_EXPR(D3D11CPUAccessFlags == CPUAccessFlagsToD3D11CPUAccessFlags(CPUAccessFlags)); - return CPUAccessFlags; -} - -inline UINT MiscTextureFlagsToD3D11Flags(Uint32 Flags) -{ - UINT D3D11MiscFlags = 0; - D3D11MiscFlags |= (Flags & MISC_TEXTURE_FLAG_GENERATE_MIPS) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0; - return D3D11MiscFlags; -} - -inline MISC_TEXTURE_FLAGS D3D11MiscFlagsToMiscTextureFlags(UINT D3D11MiscFlags) -{ - MISC_TEXTURE_FLAGS MiscFlags = MISC_TEXTURE_FLAG_NONE; - MiscFlags |= (D3D11MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) ? MISC_TEXTURE_FLAG_GENERATE_MIPS : MISC_TEXTURE_FLAG_NONE; - return MiscFlags; -} - -D3D11_FILTER FilterTypeToD3D11Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter); - -D3D11_TEXTURE_ADDRESS_MODE TexAddressModeToD3D11AddressMode(TEXTURE_ADDRESS_MODE Mode); - -D3D11_COMPARISON_FUNC ComparisonFuncToD3D11ComparisonFunc(COMPARISON_FUNCTION Func); - -void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, - D3D11_DEPTH_STENCIL_DESC& d3d11DSSDesc); - -void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, - D3D11_RASTERIZER_DESC& d3d11RSDesc); - -void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc& BSDesc, - D3D11_BLEND_DESC& D3D11BSDesc); - -void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, - std::vector>& D3D11InputElements); - -void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, D3D11_RENDER_TARGET_VIEW_DESC& D3D11RTVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, D3D11_DEPTH_STENCIL_VIEW_DESC& D3D11DSVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc); - -void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& SRVDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc); -void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& UAVDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc); - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.hpp b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.hpp new file mode 100644 index 00000000..5a87cfd7 --- /dev/null +++ b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.hpp @@ -0,0 +1,192 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Type conversion routines + +#include "GraphicsTypes.h" +#include "DXGITypeConversions.hpp" + +namespace Diligent +{ + +inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags) +{ + // clang-format off + UINT D3D11BindFlags = 0; + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_VERTEX_BUFFER) ? D3D11_BIND_VERTEX_BUFFER : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_INDEX_BUFFER) ? D3D11_BIND_INDEX_BUFFER : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNIFORM_BUFFER) ? D3D11_BIND_CONSTANT_BUFFER : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_SHADER_RESOURCE) ? D3D11_BIND_SHADER_RESOURCE : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_STREAM_OUTPUT) ? D3D11_BIND_STREAM_OUTPUT : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_RENDER_TARGET) ? D3D11_BIND_RENDER_TARGET : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_DEPTH_STENCIL) ? D3D11_BIND_DEPTH_STENCIL : 0); + D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNORDERED_ACCESS) ? D3D11_BIND_UNORDERED_ACCESS : 0); + // clang-format on + return D3D11BindFlags; +} + +inline BIND_FLAGS D3D11BindFlagsToBindFlags(UINT D3D11BindFlags) +{ + BIND_FLAGS BindFlags = BIND_NONE; + // clang-format off + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_VERTEX_BUFFER) ? BIND_VERTEX_BUFFER : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_INDEX_BUFFER) ? BIND_INDEX_BUFFER : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_CONSTANT_BUFFER) ? BIND_UNIFORM_BUFFER : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_SHADER_RESOURCE) ? BIND_SHADER_RESOURCE : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_STREAM_OUTPUT) ? BIND_STREAM_OUTPUT : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_RENDER_TARGET) ? BIND_RENDER_TARGET : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_DEPTH_STENCIL) ? BIND_DEPTH_STENCIL : BIND_NONE); + BindFlags = BindFlags | ((D3D11BindFlags & D3D11_BIND_UNORDERED_ACCESS) ? BIND_UNORDERED_ACCESS : BIND_NONE); + VERIFY_EXPR( (D3D11BindFlags & + (D3D11_BIND_VERTEX_BUFFER|D3D11_BIND_INDEX_BUFFER|D3D11_BIND_CONSTANT_BUFFER| + D3D11_BIND_SHADER_RESOURCE|D3D11_BIND_STREAM_OUTPUT|D3D11_BIND_RENDER_TARGET| + D3D11_BIND_DEPTH_STENCIL|D3D11_BIND_UNORDERED_ACCESS)) == BindFlagsToD3D11BindFlags(BindFlags)); + // clang-format on + return BindFlags; +} + +D3D11_PRIMITIVE_TOPOLOGY TopologyToD3D11Topology(PRIMITIVE_TOPOLOGY Topology); + +inline D3D11_USAGE UsageToD3D11Usage(USAGE Usage) +{ + switch (Usage) + { + // clang-format off + case USAGE_STATIC: return D3D11_USAGE_IMMUTABLE; + case USAGE_DEFAULT: return D3D11_USAGE_DEFAULT; + case USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC; + case USAGE_STAGING: return D3D11_USAGE_STAGING; + // clang-format on + default: UNEXPECTED("Unknow usage"); return D3D11_USAGE_DEFAULT; + } +} + +inline USAGE D3D11UsageToUsage(D3D11_USAGE D3D11Usage) +{ + switch (D3D11Usage) + { + // clang-format off + case D3D11_USAGE_IMMUTABLE: return USAGE_STATIC; + case D3D11_USAGE_DEFAULT: return USAGE_DEFAULT; + case D3D11_USAGE_DYNAMIC: return USAGE_DYNAMIC; + case D3D11_USAGE_STAGING: return USAGE_STAGING; + // clang-format on + default: UNEXPECTED("Unknow D3D11 usage"); return USAGE_DEFAULT; + } +} + +inline void MapParamsToD3D11MapParams(MAP_TYPE MapType, Uint32 MapFlags, D3D11_MAP& d3d11MapType, UINT& d3d11MapFlags) +{ + d3d11MapType = static_cast(0); + switch (MapType) + { + case MAP_READ: + d3d11MapType = D3D11_MAP_READ; + break; + + case MAP_WRITE: + if (MapFlags & MAP_FLAG_DISCARD) + d3d11MapType = D3D11_MAP_WRITE_DISCARD; + else if (MapFlags & MAP_FLAG_NO_OVERWRITE) + d3d11MapType = D3D11_MAP_WRITE_NO_OVERWRITE; + else + d3d11MapType = D3D11_MAP_WRITE; + break; + + case MAP_READ_WRITE: + d3d11MapType = D3D11_MAP_READ_WRITE; + break; + + default: + UNEXPECTED("Unknown map type"); + } + + d3d11MapFlags = 0; + d3d11MapFlags |= (MapFlags & MAP_FLAG_DO_NOT_WAIT) ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0; +} + +inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags) +{ + UINT D3D11CPUAccessFlags = 0; + D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_READ) ? D3D11_CPU_ACCESS_READ : 0; + D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_WRITE) ? D3D11_CPU_ACCESS_WRITE : 0; + return D3D11CPUAccessFlags; +} + +inline CPU_ACCESS_FLAGS D3D11CPUAccessFlagsToCPUAccessFlags(UINT D3D11CPUAccessFlags) +{ + CPU_ACCESS_FLAGS CPUAccessFlags = CPU_ACCESS_NONE; + CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_READ) ? CPU_ACCESS_READ : CPU_ACCESS_NONE; + CPUAccessFlags |= (D3D11CPUAccessFlags & D3D11_CPU_ACCESS_WRITE) ? CPU_ACCESS_WRITE : CPU_ACCESS_NONE; + VERIFY_EXPR(D3D11CPUAccessFlags == CPUAccessFlagsToD3D11CPUAccessFlags(CPUAccessFlags)); + return CPUAccessFlags; +} + +inline UINT MiscTextureFlagsToD3D11Flags(Uint32 Flags) +{ + UINT D3D11MiscFlags = 0; + D3D11MiscFlags |= (Flags & MISC_TEXTURE_FLAG_GENERATE_MIPS) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0; + return D3D11MiscFlags; +} + +inline MISC_TEXTURE_FLAGS D3D11MiscFlagsToMiscTextureFlags(UINT D3D11MiscFlags) +{ + MISC_TEXTURE_FLAGS MiscFlags = MISC_TEXTURE_FLAG_NONE; + MiscFlags |= (D3D11MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS) ? MISC_TEXTURE_FLAG_GENERATE_MIPS : MISC_TEXTURE_FLAG_NONE; + return MiscFlags; +} + +D3D11_FILTER FilterTypeToD3D11Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter); + +D3D11_TEXTURE_ADDRESS_MODE TexAddressModeToD3D11AddressMode(TEXTURE_ADDRESS_MODE Mode); + +D3D11_COMPARISON_FUNC ComparisonFuncToD3D11ComparisonFunc(COMPARISON_FUNCTION Func); + +void DepthStencilStateDesc_To_D3D11_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, + D3D11_DEPTH_STENCIL_DESC& d3d11DSSDesc); + +void RasterizerStateDesc_To_D3D11_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, + D3D11_RASTERIZER_DESC& d3d11RSDesc); + +void BlendStateDesc_To_D3D11_BLEND_DESC(const BlendStateDesc& BSDesc, + D3D11_BLEND_DESC& D3D11BSDesc); + +void LayoutElements_To_D3D11_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, + std::vector>& D3D11InputElements); + +void TextureViewDesc_to_D3D11_SRV_DESC(const TextureViewDesc& TexViewDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D11_RTV_DESC(const TextureViewDesc& TexViewDesc, D3D11_RENDER_TARGET_VIEW_DESC& D3D11RTVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D11_DSV_DESC(const TextureViewDesc& TexViewDesc, D3D11_DEPTH_STENCIL_VIEW_DESC& D3D11DSVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D11_UAV_DESC(const TextureViewDesc& TexViewDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc); + +void BufferViewDesc_to_D3D11_SRV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& SRVDesc, D3D11_SHADER_RESOURCE_VIEW_DESC& D3D11SRVDesc); +void BufferViewDesc_to_D3D11_UAV_DESC(const BufferDesc& BuffDesc, const BufferViewDesc& UAVDesc, D3D11_UNORDERED_ACCESS_VIEW_DESC& D3D11UAVDesc); + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D11/include/pch.h b/Graphics/GraphicsEngineD3D11/include/pch.h index 47017eda..6018b4b8 100644 --- a/Graphics/GraphicsEngineD3D11/include/pch.h +++ b/Graphics/GraphicsEngineD3D11/include/pch.h @@ -76,6 +76,6 @@ #include "DebugUtilities.h" #include "D3DErrors.hpp" #include "RenderDeviceBase.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "ValidatedCast.hpp" #include diff --git a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp index 2d2d10b5..bd0eaaf1 100644 --- a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp @@ -31,7 +31,7 @@ #include "BufferD3D11Impl.hpp" #include "RenderDeviceD3D11Impl.hpp" #include "DeviceContextD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "BufferViewD3D11Impl.hpp" #include "GraphicsAccessories.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp b/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp index 0d76db58..e717f09d 100644 --- a/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp +++ b/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp @@ -26,7 +26,7 @@ */ #include "pch.h" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "D3D11TypeDefinitions.h" #include "D3DTypeConversionImpl.hpp" diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 0c19756c..f7e8c886 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -33,7 +33,7 @@ #include "Texture2D_D3D11.hpp" #include "Texture3D_D3D11.hpp" #include "SamplerD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "TextureViewD3D11Impl.hpp" #include "PipelineStateD3D11Impl.hpp" #include "ShaderResourceBindingD3D11Impl.hpp" diff --git a/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp index 252697bd..5b11cf12 100644 --- a/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/EngineFactoryD3D11.cpp @@ -33,7 +33,7 @@ #include "RenderDeviceD3D11Impl.hpp" #include "DeviceContextD3D11Impl.hpp" #include "SwapChainD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "EngineMemory.h" #include "EngineFactoryD3DBase.hpp" #include diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp index bcd9bec6..1046f6ff 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp @@ -34,7 +34,7 @@ #include "Texture2D_D3D11.hpp" #include "Texture3D_D3D11.hpp" #include "SamplerD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "TextureViewD3D11Impl.hpp" #include "PipelineStateD3D11Impl.hpp" #include "ShaderResourceBindingD3D11Impl.hpp" diff --git a/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp index 6d23f951..8ffe8939 100644 --- a/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp @@ -28,7 +28,7 @@ #include "pch.h" #include "SamplerD3D11Impl.hpp" #include "RenderDeviceD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp index 89104a55..8980db2a 100644 --- a/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp @@ -28,7 +28,7 @@ #include "pch.h" #include "Texture1D_D3D11.hpp" #include "RenderDeviceD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp index cc36b713..42041ec6 100644 --- a/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp @@ -28,7 +28,7 @@ #include "pch.h" #include "Texture2D_D3D11.hpp" #include "RenderDeviceD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp index 322043e8..6756f957 100644 --- a/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp @@ -28,7 +28,7 @@ #include "pch.h" #include "Texture3D_D3D11.hpp" #include "RenderDeviceD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp index 39918856..7a744b57 100644 --- a/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp @@ -29,7 +29,7 @@ #include "TextureBaseD3D11.hpp" #include "RenderDeviceD3D11Impl.hpp" #include "DeviceContextD3D11Impl.hpp" -#include "D3D11TypeConversions.h" +#include "D3D11TypeConversions.hpp" #include "TextureViewD3D11Impl.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineD3D12/CMakeLists.txt b/Graphics/GraphicsEngineD3D12/CMakeLists.txt index fa3b4b70..6ea2fc22 100644 --- a/Graphics/GraphicsEngineD3D12/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D12/CMakeLists.txt @@ -10,7 +10,7 @@ set(INCLUDE include/CommandListManager.hpp include/CommandQueueD3D12Impl.hpp include/D3D12ResourceBase.hpp - include/D3D12TypeConversions.h + include/D3D12TypeConversions.hpp include/D3D12TypeDefinitions.h include/D3D12Utils.h include/d3dx12_win.h diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h b/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h deleted file mode 100644 index bdaa3f5e..00000000 --- a/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Type conversion routines - -#include "GraphicsTypes.h" - -namespace Diligent -{ - -D3D12_COMPARISON_FUNC ComparisonFuncToD3D12ComparisonFunc(COMPARISON_FUNCTION Func); -D3D12_FILTER FilterTypeToD3D12Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter); -D3D12_TEXTURE_ADDRESS_MODE TexAddressModeToD3D12AddressMode(TEXTURE_ADDRESS_MODE Mode); -D3D12_PRIMITIVE_TOPOLOGY TopologyToD3D12Topology(PRIMITIVE_TOPOLOGY Topology); - -void DepthStencilStateDesc_To_D3D12_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, - D3D12_DEPTH_STENCIL_DESC& d3d12DSSDesc); -void RasterizerStateDesc_To_D3D12_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, - D3D12_RASTERIZER_DESC& d3d11RSDesc); -void BlendStateDesc_To_D3D12_BLEND_DESC(const BlendStateDesc& BSDesc, - D3D12_BLEND_DESC& d3d12BlendDesc); - -void LayoutElements_To_D3D12_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, - std::vector>& d3d12InputElements); - -// clang-format off -void TextureViewDesc_to_D3D12_SRV_DESC(const TextureViewDesc& SRVDesc, D3D12_SHADER_RESOURCE_VIEW_DESC &D3D12SRVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D12_RTV_DESC(const TextureViewDesc& RTVDesc, D3D12_RENDER_TARGET_VIEW_DESC &D3D12RTVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D12_DSV_DESC(const TextureViewDesc& DSVDesc, D3D12_DEPTH_STENCIL_VIEW_DESC &D3D12DSVDesc, Uint32 SampleCount); -void TextureViewDesc_to_D3D12_UAV_DESC(const TextureViewDesc& UAVDesc, D3D12_UNORDERED_ACCESS_VIEW_DESC &D3D12UAVDesc); -// clang-format on - -void BufferViewDesc_to_D3D12_SRV_DESC(const BufferDesc& BuffDesc, - const BufferViewDesc& SRVDesc, - D3D12_SHADER_RESOURCE_VIEW_DESC& D3D12SRVDesc); -void BufferViewDesc_to_D3D12_UAV_DESC(const BufferDesc& BuffDesc, - const BufferViewDesc& UAVDesc, - D3D12_UNORDERED_ACCESS_VIEW_DESC& D3D12UAVDesc); - -D3D12_STATIC_BORDER_COLOR BorderColorToD3D12StaticBorderColor(const Float32 BorderColor[]); -D3D12_RESOURCE_STATES ResourceStateFlagsToD3D12ResourceStates(RESOURCE_STATE StateFlags); -RESOURCE_STATE D3D12ResourceStatesToResourceStateFlags(D3D12_RESOURCE_STATES StateFlags); - -D3D12_QUERY_HEAP_TYPE QueryTypeToD3D12QueryHeapType(QUERY_TYPE QueryType); -D3D12_QUERY_TYPE QueryTypeToD3D12QueryType(QUERY_TYPE QueryType); - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.hpp b/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.hpp new file mode 100644 index 00000000..bdaa3f5e --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.hpp @@ -0,0 +1,74 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Type conversion routines + +#include "GraphicsTypes.h" + +namespace Diligent +{ + +D3D12_COMPARISON_FUNC ComparisonFuncToD3D12ComparisonFunc(COMPARISON_FUNCTION Func); +D3D12_FILTER FilterTypeToD3D12Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter); +D3D12_TEXTURE_ADDRESS_MODE TexAddressModeToD3D12AddressMode(TEXTURE_ADDRESS_MODE Mode); +D3D12_PRIMITIVE_TOPOLOGY TopologyToD3D12Topology(PRIMITIVE_TOPOLOGY Topology); + +void DepthStencilStateDesc_To_D3D12_DEPTH_STENCIL_DESC(const DepthStencilStateDesc& DepthStencilDesc, + D3D12_DEPTH_STENCIL_DESC& d3d12DSSDesc); +void RasterizerStateDesc_To_D3D12_RASTERIZER_DESC(const RasterizerStateDesc& RasterizerDesc, + D3D12_RASTERIZER_DESC& d3d11RSDesc); +void BlendStateDesc_To_D3D12_BLEND_DESC(const BlendStateDesc& BSDesc, + D3D12_BLEND_DESC& d3d12BlendDesc); + +void LayoutElements_To_D3D12_INPUT_ELEMENT_DESCs(const InputLayoutDesc& InputLayout, + std::vector>& d3d12InputElements); + +// clang-format off +void TextureViewDesc_to_D3D12_SRV_DESC(const TextureViewDesc& SRVDesc, D3D12_SHADER_RESOURCE_VIEW_DESC &D3D12SRVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D12_RTV_DESC(const TextureViewDesc& RTVDesc, D3D12_RENDER_TARGET_VIEW_DESC &D3D12RTVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D12_DSV_DESC(const TextureViewDesc& DSVDesc, D3D12_DEPTH_STENCIL_VIEW_DESC &D3D12DSVDesc, Uint32 SampleCount); +void TextureViewDesc_to_D3D12_UAV_DESC(const TextureViewDesc& UAVDesc, D3D12_UNORDERED_ACCESS_VIEW_DESC &D3D12UAVDesc); +// clang-format on + +void BufferViewDesc_to_D3D12_SRV_DESC(const BufferDesc& BuffDesc, + const BufferViewDesc& SRVDesc, + D3D12_SHADER_RESOURCE_VIEW_DESC& D3D12SRVDesc); +void BufferViewDesc_to_D3D12_UAV_DESC(const BufferDesc& BuffDesc, + const BufferViewDesc& UAVDesc, + D3D12_UNORDERED_ACCESS_VIEW_DESC& D3D12UAVDesc); + +D3D12_STATIC_BORDER_COLOR BorderColorToD3D12StaticBorderColor(const Float32 BorderColor[]); +D3D12_RESOURCE_STATES ResourceStateFlagsToD3D12ResourceStates(RESOURCE_STATE StateFlags); +RESOURCE_STATE D3D12ResourceStatesToResourceStateFlags(D3D12_RESOURCE_STATES StateFlags); + +D3D12_QUERY_HEAP_TYPE QueryTypeToD3D12QueryHeapType(QUERY_TYPE QueryType); +D3D12_QUERY_TYPE QueryTypeToD3D12QueryType(QUERY_TYPE QueryType); + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index 71d4ebce..b1c4c8e8 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -29,10 +29,10 @@ #include "BufferD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "BufferViewD3D12Impl.hpp" #include "GraphicsAccessories.hpp" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "EngineMemory.h" #include "StringTools.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index ebc46582..253d2822 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -31,7 +31,7 @@ #include "TextureD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" #include "CommandListManager.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp b/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp index dfb01d88..e1da052f 100644 --- a/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp +++ b/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp @@ -29,8 +29,8 @@ #include -#include "D3D12TypeConversions.h" -#include "DXGITypeConversions.h" +#include "D3D12TypeConversions.hpp" +#include "DXGITypeConversions.hpp" #include "D3D12TypeDefinitions.h" #include "D3DTypeConversionImpl.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index ba509cd5..582b8cad 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -34,11 +34,11 @@ #include "TextureD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" #include "FenceD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "d3dx12_win.h" #include "D3D12DynamicHeap.hpp" #include "CommandListD3D12Impl.hpp" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp index ad68183d..bed9a84b 100644 --- a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp @@ -37,7 +37,7 @@ #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" #include "SwapChainD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "EngineFactoryD3DBase.hpp" #include "StringTools.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 3534c891..6cfe1b1e 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -29,9 +29,9 @@ #include #include "PipelineStateD3D12Impl.hpp" #include "ShaderD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "RenderDeviceD3D12Impl.hpp" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "ShaderResourceBindingD3D12Impl.hpp" #include "CommandContext.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineD3D12/src/QueryManagerD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/QueryManagerD3D12.cpp index bf99bdcc..e27d6be6 100644 --- a/Graphics/GraphicsEngineD3D12/src/QueryManagerD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/QueryManagerD3D12.cpp @@ -29,7 +29,7 @@ #include #include "QueryManagerD3D12.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "GraphicsAccessories.hpp" #include "CommandContext.hpp" #include "Align.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 73be3632..781a711d 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -31,7 +31,7 @@ #include "PipelineStateD3D12Impl.hpp" #include "ShaderD3D12Impl.hpp" #include "TextureD3D12Impl.hpp" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "SamplerD3D12Impl.hpp" #include "BufferD3D12Impl.hpp" #include "ShaderResourceBindingD3D12Impl.hpp" diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 26c02d7d..33978eaf 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -33,7 +33,7 @@ #include "CommandContext.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "TextureD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "HashUtils.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp index e53fa1b5..1002dc37 100644 --- a/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp @@ -28,7 +28,7 @@ #include "pch.h" #include "SamplerD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp index ac24533c..ef133c48 100644 --- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp @@ -29,7 +29,7 @@ #include "SwapChainD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "TextureD3D12Impl.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp index 7155863d..a4033f51 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp @@ -29,9 +29,9 @@ #include "TextureD3D12Impl.hpp" #include "RenderDeviceD3D12Impl.hpp" #include "DeviceContextD3D12Impl.hpp" -#include "D3D12TypeConversions.h" +#include "D3D12TypeConversions.hpp" #include "TextureViewD3D12Impl.hpp" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "d3dx12_win.h" #include "EngineMemory.h" #include "StringTools.hpp" diff --git a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt index a60f000f..0f208b6d 100644 --- a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt @@ -7,7 +7,7 @@ set(INCLUDE include/D3DShaderResourceLoader.hpp include/D3DTypeConversionImpl.hpp include/D3DViewDescConversionImpl.hpp - include/DXGITypeConversions.h + include/DXGITypeConversions.hpp include/EngineFactoryD3DBase.hpp include/HLSLDefinitions.fxh include/RenderDeviceD3DBase.hpp diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.hpp b/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.hpp index 5f6939a8..02f72d86 100644 --- a/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.hpp @@ -32,7 +32,7 @@ /// This file must be included after D3D11TypeDefinitions.h or D3D12TypeDefinitions.h -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h b/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h deleted file mode 100644 index 91808f8f..00000000 --- a/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Common D3D type conversion utilities - -#include -#include "GraphicsTypes.h" - -namespace Diligent -{ -DXGI_FORMAT TexFormatToDXGI_Format(TEXTURE_FORMAT TexFormat, Uint32 BindFlags = 0); -TEXTURE_FORMAT DXGI_FormatToTexFormat(DXGI_FORMAT DXGIFormat); -DXGI_FORMAT TypeToDXGI_Format(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized); -} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.hpp b/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.hpp new file mode 100644 index 00000000..91808f8f --- /dev/null +++ b/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.hpp @@ -0,0 +1,41 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Common D3D type conversion utilities + +#include +#include "GraphicsTypes.h" + +namespace Diligent +{ +DXGI_FORMAT TexFormatToDXGI_Format(TEXTURE_FORMAT TexFormat, Uint32 BindFlags = 0); +TEXTURE_FORMAT DXGI_FormatToTexFormat(DXGI_FORMAT DXGIFormat); +DXGI_FORMAT TypeToDXGI_Format(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized); +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3DBase/include/EngineFactoryD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/EngineFactoryD3DBase.hpp index 1e610f62..88680ff5 100644 --- a/Graphics/GraphicsEngineD3DBase/include/EngineFactoryD3DBase.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/EngineFactoryD3DBase.hpp @@ -27,7 +27,7 @@ #pragma once -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "EngineFactoryBase.hpp" /// \file diff --git a/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp b/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp index 32f3e60e..a181d534 100644 --- a/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp @@ -25,7 +25,7 @@ * of the possibility of such damages. */ -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "BasicTypes.h" #include "DebugUtilities.h" diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index c0d3bd36..2ee218be 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -15,7 +15,7 @@ set(INCLUDE include/GLProgramResourceCache.hpp include/GLPipelineResourceLayout.hpp include/GLProgramResources.hpp - include/GLTypeConversions.h + include/GLTypeConversions.hpp include/pch.h include/PipelineStateGLImpl.hpp include/QueryGLImpl.hpp diff --git a/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.h b/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.h deleted file mode 100644 index 4f149399..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.h +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -namespace Diligent -{ - -// clang-format off -static const GLenum PrimTopologyToGLTopologyMap[] = -{ - 0, //PRIMITIVE_TOPOLOGY_UNDEFINED = 0 - GL_TRIANGLES, //PRIMITIVE_TOPOLOGY_TRIANGLE_LIST - GL_TRIANGLE_STRIP, //PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, - GL_POINTS, //PRIMITIVE_TOPOLOGY_POINT_LIST - GL_LINES //PRIMITIVE_TOPOLOGY_LINE_LIST -}; -// clang-format on - -inline GLenum PrimitiveTopologyToGLTopology(PRIMITIVE_TOPOLOGY PrimTopology) -{ - VERIFY_EXPR(PrimTopology < _countof(PrimTopologyToGLTopologyMap)); - auto GLTopology = PrimTopologyToGLTopologyMap[PrimTopology]; -#ifdef _DEBUG - switch (PrimTopology) - { - // clang-format off - case PRIMITIVE_TOPOLOGY_UNDEFINED: VERIFY_EXPR(GLTopology == 0); break; - case PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: VERIFY_EXPR(GLTopology == GL_TRIANGLES); break; - case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: VERIFY_EXPR(GLTopology == GL_TRIANGLE_STRIP); break; - case PRIMITIVE_TOPOLOGY_POINT_LIST: VERIFY_EXPR(GLTopology == GL_POINTS); break; - case PRIMITIVE_TOPOLOGY_LINE_LIST: VERIFY_EXPR(GLTopology == GL_LINES); break; - default: UNEXPECTED("Unexpected primitive topology"); - // clang-format on - } -#endif - return GLTopology; -} - -// clang-format off -static const GLenum TypeToGLTypeMap[] = -{ - 0, //VT_UNDEFINED = 0 - GL_BYTE, //VT_INT8 - GL_SHORT, //VT_INT16 - GL_INT, //VT_INT32 - GL_UNSIGNED_BYTE, //VT_UINT8 - GL_UNSIGNED_SHORT, //VT_UINT16 - GL_UNSIGNED_INT, //VT_UINT32 - 0, //VT_FLOAT16 - GL_FLOAT //VT_FLOAT32 -}; -// clang-format on - -inline GLenum TypeToGLType(VALUE_TYPE Value) -{ - VERIFY_EXPR(Value < _countof(TypeToGLTypeMap)); - auto GLType = TypeToGLTypeMap[Value]; -#ifdef _DEBUG - switch (Value) - { - // clang-format off - case VT_INT8: VERIFY_EXPR(GLType == GL_BYTE); break; - case VT_INT16: VERIFY_EXPR(GLType == GL_SHORT); break; - case VT_INT32: VERIFY_EXPR(GLType == GL_INT); break; - case VT_UINT8: VERIFY_EXPR(GLType == GL_UNSIGNED_BYTE); break; - case VT_UINT16: VERIFY_EXPR(GLType == GL_UNSIGNED_SHORT); break; - case VT_UINT32: VERIFY_EXPR(GLType == GL_UNSIGNED_INT); break; - case VT_FLOAT32: VERIFY_EXPR(GLType == GL_FLOAT); break; - default: UNEXPECTED("Unexpected value type"); - // clang-format on - } -#endif - return GLType; -} - -inline GLenum UsageToGLUsage(const BufferDesc& Desc) -{ - // http://www.informit.com/articles/article.aspx?p=2033340&seqNum=2 - // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glBufferData.xml - switch (Desc.Usage) - { - // STATIC: The data store contents will be modified once and used many times. - // STREAM: The data store contents will be modified once and used at MOST a few times. - // DYNAMIC: The data store contents will be modified repeatedly and used many times. - - // clang-format off - case USAGE_STATIC: return GL_STATIC_DRAW; - case USAGE_DEFAULT: return GL_STATIC_DRAW; - case USAGE_DYNAMIC: return GL_DYNAMIC_DRAW; - case USAGE_STAGING: - if(Desc.CPUAccessFlags & CPU_ACCESS_READ) - return GL_STATIC_READ; - else - return GL_STATIC_COPY; - - default: UNEXPECTED( "Unknow usage" ); return 0; - // clang-format on - } -} - -inline void FilterTypeToGLFilterType(FILTER_TYPE Filter, GLenum& GLFilter, Bool& bIsAnisotropic, Bool& bIsComparison) -{ - switch (Filter) - { - case FILTER_TYPE_UNKNOWN: - UNEXPECTED("Unspecified filter type"); - bIsAnisotropic = false; - bIsComparison = false; - GLFilter = GL_NEAREST; - break; - - case FILTER_TYPE_POINT: - bIsAnisotropic = false; - bIsComparison = false; - GLFilter = GL_NEAREST; - break; - - case FILTER_TYPE_LINEAR: - bIsAnisotropic = false; - bIsComparison = false; - GLFilter = GL_LINEAR; - break; - - case FILTER_TYPE_ANISOTROPIC: - bIsAnisotropic = true; - bIsComparison = false; - GLFilter = GL_LINEAR; - break; - - case FILTER_TYPE_COMPARISON_POINT: - bIsAnisotropic = false; - bIsComparison = true; - GLFilter = GL_NEAREST; - break; - - case FILTER_TYPE_COMPARISON_LINEAR: - bIsAnisotropic = false; - bIsComparison = true; - GLFilter = GL_LINEAR; - break; - - case FILTER_TYPE_COMPARISON_ANISOTROPIC: - bIsAnisotropic = true; - bIsComparison = true; - GLFilter = GL_LINEAR; - break; - - default: - UNEXPECTED("Unknown filter type"); - bIsAnisotropic = false; - bIsComparison = false; - GLFilter = GL_NEAREST; - break; - } -} - -GLenum TexFormatToGLInternalTexFormat(TEXTURE_FORMAT TexFormat, Uint32 BindFlags = 0); -TEXTURE_FORMAT GLInternalTexFormatToTexFormat(GLenum GlFormat); -GLenum CorrectGLTexFormat(GLenum GLTexFormat, Uint32 BindFlags); - -inline GLenum TexAddressModeToGLAddressMode(TEXTURE_ADDRESS_MODE Mode) -{ - switch (Mode) - { - // clang-format off - case TEXTURE_ADDRESS_UNKNOWN: UNEXPECTED( "Texture address mode is not specified" ); return GL_CLAMP_TO_EDGE; - case TEXTURE_ADDRESS_WRAP: return GL_REPEAT; - case TEXTURE_ADDRESS_MIRROR: return GL_MIRRORED_REPEAT; - case TEXTURE_ADDRESS_CLAMP: return GL_CLAMP_TO_EDGE; - case TEXTURE_ADDRESS_BORDER: return GL_CLAMP_TO_BORDER; - case TEXTURE_ADDRESS_MIRROR_ONCE: return GL_MIRROR_CLAMP_TO_EDGE; // only available with OpenGL 4.4 - // This mode seems to be different from D3D11_TEXTURE_ADDRESS_MIRROR_ONCE - // The texture coord is clamped to the [-1, 1] range, but mirrors the - // negative direction with the positive. Basically, it acts as - // GL_CLAMP_TO_EDGE except that it takes the absolute value of the texture - // coordinates before clamping. - default: UNEXPECTED( "Unknown texture address mode" ); return GL_CLAMP_TO_EDGE; - // clang-format on - } -} - -inline GLenum CompareFuncToGLCompareFunc(COMPARISON_FUNCTION Func) -{ - switch (Func) - { - // clang-format off - case COMPARISON_FUNC_UNKNOWN: UNEXPECTED( "Comparison function is not specified" ); return GL_ALWAYS; - case COMPARISON_FUNC_NEVER: return GL_NEVER; - case COMPARISON_FUNC_LESS: return GL_LESS; - case COMPARISON_FUNC_EQUAL: return GL_EQUAL; - case COMPARISON_FUNC_LESS_EQUAL: return GL_LEQUAL; - case COMPARISON_FUNC_GREATER: return GL_GREATER; - case COMPARISON_FUNC_NOT_EQUAL: return GL_NOTEQUAL; - case COMPARISON_FUNC_GREATER_EQUAL: return GL_GEQUAL; - case COMPARISON_FUNC_ALWAYS: return GL_ALWAYS; - default: UNEXPECTED( "Unknown comparison func" ); return GL_ALWAYS; - // clang-format on - } -} - -struct NativePixelAttribs -{ - GLenum PixelFormat = 0; - GLenum DataType = 0; - Bool IsCompressed = 0; - - NativePixelAttribs() noexcept {} - - explicit NativePixelAttribs(GLenum _PixelFormat, GLenum _DataType, Bool _IsCompressed = False) noexcept : - PixelFormat{_PixelFormat}, - DataType{_DataType}, - IsCompressed{_IsCompressed} - {} -}; - -inline Uint32 GetNumPixelFormatComponents(GLenum Format) -{ - switch (Format) - { - case GL_RGBA: - case GL_RGBA_INTEGER: - return 4; - - case GL_RGB: - case GL_RGB_INTEGER: - return 3; - - case GL_RG: - case GL_RG_INTEGER: - return 2; - - case GL_RED: - case GL_RED_INTEGER: - case GL_DEPTH_COMPONENT: - case GL_DEPTH_STENCIL: - return 1; - - default: UNEXPECTED("Unknonw pixel format"); return 0; - }; -} - -inline Uint32 GetPixelTypeSize(GLenum Type) -{ - switch (Type) - { - // clang-format off - case GL_FLOAT: return sizeof(GLfloat); - - case GL_UNSIGNED_INT_10_10_10_2: - case GL_UNSIGNED_INT_2_10_10_10_REV: - case GL_UNSIGNED_INT_10F_11F_11F_REV: - case GL_UNSIGNED_INT_24_8: - case GL_UNSIGNED_INT_5_9_9_9_REV: - case GL_UNSIGNED_INT: return sizeof(GLuint); - - case GL_INT: return sizeof(GLint); - case GL_HALF_FLOAT: return sizeof(GLhalf); - - case GL_UNSIGNED_SHORT_5_6_5: - case GL_UNSIGNED_SHORT_5_6_5_REV: - case GL_UNSIGNED_SHORT_5_5_5_1: - case GL_UNSIGNED_SHORT_1_5_5_5_REV: - case GL_UNSIGNED_SHORT: return sizeof(GLushort); - - case GL_SHORT: return sizeof(GLshort); - case GL_UNSIGNED_BYTE: return sizeof(GLubyte); - case GL_BYTE: return sizeof(GLbyte); - - case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:return sizeof(GLfloat) + sizeof(GLuint); - - default: UNEXPECTED( "Unknonw pixel type" ); return 0; - // clang-format on - } -} - -NativePixelAttribs GetNativePixelTransferAttribs(TEXTURE_FORMAT TexFormat); -GLenum AccessFlags2GLAccess(Uint32 UAVAccessFlags); -GLenum TypeToGLTexFormat(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized); -GLenum StencilOp2GlStencilOp(STENCIL_OP StencilOp); -GLenum BlendFactor2GLBlend(BLEND_FACTOR bf); -GLenum BlendOperation2GLBlendOp(BLEND_OPERATION BlendOp); - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp b/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp new file mode 100644 index 00000000..4f149399 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLTypeConversions.hpp @@ -0,0 +1,308 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +namespace Diligent +{ + +// clang-format off +static const GLenum PrimTopologyToGLTopologyMap[] = +{ + 0, //PRIMITIVE_TOPOLOGY_UNDEFINED = 0 + GL_TRIANGLES, //PRIMITIVE_TOPOLOGY_TRIANGLE_LIST + GL_TRIANGLE_STRIP, //PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, + GL_POINTS, //PRIMITIVE_TOPOLOGY_POINT_LIST + GL_LINES //PRIMITIVE_TOPOLOGY_LINE_LIST +}; +// clang-format on + +inline GLenum PrimitiveTopologyToGLTopology(PRIMITIVE_TOPOLOGY PrimTopology) +{ + VERIFY_EXPR(PrimTopology < _countof(PrimTopologyToGLTopologyMap)); + auto GLTopology = PrimTopologyToGLTopologyMap[PrimTopology]; +#ifdef _DEBUG + switch (PrimTopology) + { + // clang-format off + case PRIMITIVE_TOPOLOGY_UNDEFINED: VERIFY_EXPR(GLTopology == 0); break; + case PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: VERIFY_EXPR(GLTopology == GL_TRIANGLES); break; + case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: VERIFY_EXPR(GLTopology == GL_TRIANGLE_STRIP); break; + case PRIMITIVE_TOPOLOGY_POINT_LIST: VERIFY_EXPR(GLTopology == GL_POINTS); break; + case PRIMITIVE_TOPOLOGY_LINE_LIST: VERIFY_EXPR(GLTopology == GL_LINES); break; + default: UNEXPECTED("Unexpected primitive topology"); + // clang-format on + } +#endif + return GLTopology; +} + +// clang-format off +static const GLenum TypeToGLTypeMap[] = +{ + 0, //VT_UNDEFINED = 0 + GL_BYTE, //VT_INT8 + GL_SHORT, //VT_INT16 + GL_INT, //VT_INT32 + GL_UNSIGNED_BYTE, //VT_UINT8 + GL_UNSIGNED_SHORT, //VT_UINT16 + GL_UNSIGNED_INT, //VT_UINT32 + 0, //VT_FLOAT16 + GL_FLOAT //VT_FLOAT32 +}; +// clang-format on + +inline GLenum TypeToGLType(VALUE_TYPE Value) +{ + VERIFY_EXPR(Value < _countof(TypeToGLTypeMap)); + auto GLType = TypeToGLTypeMap[Value]; +#ifdef _DEBUG + switch (Value) + { + // clang-format off + case VT_INT8: VERIFY_EXPR(GLType == GL_BYTE); break; + case VT_INT16: VERIFY_EXPR(GLType == GL_SHORT); break; + case VT_INT32: VERIFY_EXPR(GLType == GL_INT); break; + case VT_UINT8: VERIFY_EXPR(GLType == GL_UNSIGNED_BYTE); break; + case VT_UINT16: VERIFY_EXPR(GLType == GL_UNSIGNED_SHORT); break; + case VT_UINT32: VERIFY_EXPR(GLType == GL_UNSIGNED_INT); break; + case VT_FLOAT32: VERIFY_EXPR(GLType == GL_FLOAT); break; + default: UNEXPECTED("Unexpected value type"); + // clang-format on + } +#endif + return GLType; +} + +inline GLenum UsageToGLUsage(const BufferDesc& Desc) +{ + // http://www.informit.com/articles/article.aspx?p=2033340&seqNum=2 + // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glBufferData.xml + switch (Desc.Usage) + { + // STATIC: The data store contents will be modified once and used many times. + // STREAM: The data store contents will be modified once and used at MOST a few times. + // DYNAMIC: The data store contents will be modified repeatedly and used many times. + + // clang-format off + case USAGE_STATIC: return GL_STATIC_DRAW; + case USAGE_DEFAULT: return GL_STATIC_DRAW; + case USAGE_DYNAMIC: return GL_DYNAMIC_DRAW; + case USAGE_STAGING: + if(Desc.CPUAccessFlags & CPU_ACCESS_READ) + return GL_STATIC_READ; + else + return GL_STATIC_COPY; + + default: UNEXPECTED( "Unknow usage" ); return 0; + // clang-format on + } +} + +inline void FilterTypeToGLFilterType(FILTER_TYPE Filter, GLenum& GLFilter, Bool& bIsAnisotropic, Bool& bIsComparison) +{ + switch (Filter) + { + case FILTER_TYPE_UNKNOWN: + UNEXPECTED("Unspecified filter type"); + bIsAnisotropic = false; + bIsComparison = false; + GLFilter = GL_NEAREST; + break; + + case FILTER_TYPE_POINT: + bIsAnisotropic = false; + bIsComparison = false; + GLFilter = GL_NEAREST; + break; + + case FILTER_TYPE_LINEAR: + bIsAnisotropic = false; + bIsComparison = false; + GLFilter = GL_LINEAR; + break; + + case FILTER_TYPE_ANISOTROPIC: + bIsAnisotropic = true; + bIsComparison = false; + GLFilter = GL_LINEAR; + break; + + case FILTER_TYPE_COMPARISON_POINT: + bIsAnisotropic = false; + bIsComparison = true; + GLFilter = GL_NEAREST; + break; + + case FILTER_TYPE_COMPARISON_LINEAR: + bIsAnisotropic = false; + bIsComparison = true; + GLFilter = GL_LINEAR; + break; + + case FILTER_TYPE_COMPARISON_ANISOTROPIC: + bIsAnisotropic = true; + bIsComparison = true; + GLFilter = GL_LINEAR; + break; + + default: + UNEXPECTED("Unknown filter type"); + bIsAnisotropic = false; + bIsComparison = false; + GLFilter = GL_NEAREST; + break; + } +} + +GLenum TexFormatToGLInternalTexFormat(TEXTURE_FORMAT TexFormat, Uint32 BindFlags = 0); +TEXTURE_FORMAT GLInternalTexFormatToTexFormat(GLenum GlFormat); +GLenum CorrectGLTexFormat(GLenum GLTexFormat, Uint32 BindFlags); + +inline GLenum TexAddressModeToGLAddressMode(TEXTURE_ADDRESS_MODE Mode) +{ + switch (Mode) + { + // clang-format off + case TEXTURE_ADDRESS_UNKNOWN: UNEXPECTED( "Texture address mode is not specified" ); return GL_CLAMP_TO_EDGE; + case TEXTURE_ADDRESS_WRAP: return GL_REPEAT; + case TEXTURE_ADDRESS_MIRROR: return GL_MIRRORED_REPEAT; + case TEXTURE_ADDRESS_CLAMP: return GL_CLAMP_TO_EDGE; + case TEXTURE_ADDRESS_BORDER: return GL_CLAMP_TO_BORDER; + case TEXTURE_ADDRESS_MIRROR_ONCE: return GL_MIRROR_CLAMP_TO_EDGE; // only available with OpenGL 4.4 + // This mode seems to be different from D3D11_TEXTURE_ADDRESS_MIRROR_ONCE + // The texture coord is clamped to the [-1, 1] range, but mirrors the + // negative direction with the positive. Basically, it acts as + // GL_CLAMP_TO_EDGE except that it takes the absolute value of the texture + // coordinates before clamping. + default: UNEXPECTED( "Unknown texture address mode" ); return GL_CLAMP_TO_EDGE; + // clang-format on + } +} + +inline GLenum CompareFuncToGLCompareFunc(COMPARISON_FUNCTION Func) +{ + switch (Func) + { + // clang-format off + case COMPARISON_FUNC_UNKNOWN: UNEXPECTED( "Comparison function is not specified" ); return GL_ALWAYS; + case COMPARISON_FUNC_NEVER: return GL_NEVER; + case COMPARISON_FUNC_LESS: return GL_LESS; + case COMPARISON_FUNC_EQUAL: return GL_EQUAL; + case COMPARISON_FUNC_LESS_EQUAL: return GL_LEQUAL; + case COMPARISON_FUNC_GREATER: return GL_GREATER; + case COMPARISON_FUNC_NOT_EQUAL: return GL_NOTEQUAL; + case COMPARISON_FUNC_GREATER_EQUAL: return GL_GEQUAL; + case COMPARISON_FUNC_ALWAYS: return GL_ALWAYS; + default: UNEXPECTED( "Unknown comparison func" ); return GL_ALWAYS; + // clang-format on + } +} + +struct NativePixelAttribs +{ + GLenum PixelFormat = 0; + GLenum DataType = 0; + Bool IsCompressed = 0; + + NativePixelAttribs() noexcept {} + + explicit NativePixelAttribs(GLenum _PixelFormat, GLenum _DataType, Bool _IsCompressed = False) noexcept : + PixelFormat{_PixelFormat}, + DataType{_DataType}, + IsCompressed{_IsCompressed} + {} +}; + +inline Uint32 GetNumPixelFormatComponents(GLenum Format) +{ + switch (Format) + { + case GL_RGBA: + case GL_RGBA_INTEGER: + return 4; + + case GL_RGB: + case GL_RGB_INTEGER: + return 3; + + case GL_RG: + case GL_RG_INTEGER: + return 2; + + case GL_RED: + case GL_RED_INTEGER: + case GL_DEPTH_COMPONENT: + case GL_DEPTH_STENCIL: + return 1; + + default: UNEXPECTED("Unknonw pixel format"); return 0; + }; +} + +inline Uint32 GetPixelTypeSize(GLenum Type) +{ + switch (Type) + { + // clang-format off + case GL_FLOAT: return sizeof(GLfloat); + + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + case GL_UNSIGNED_INT_10F_11F_11F_REV: + case GL_UNSIGNED_INT_24_8: + case GL_UNSIGNED_INT_5_9_9_9_REV: + case GL_UNSIGNED_INT: return sizeof(GLuint); + + case GL_INT: return sizeof(GLint); + case GL_HALF_FLOAT: return sizeof(GLhalf); + + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + case GL_UNSIGNED_SHORT: return sizeof(GLushort); + + case GL_SHORT: return sizeof(GLshort); + case GL_UNSIGNED_BYTE: return sizeof(GLubyte); + case GL_BYTE: return sizeof(GLbyte); + + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:return sizeof(GLfloat) + sizeof(GLuint); + + default: UNEXPECTED( "Unknonw pixel type" ); return 0; + // clang-format on + } +} + +NativePixelAttribs GetNativePixelTransferAttribs(TEXTURE_FORMAT TexFormat); +GLenum AccessFlags2GLAccess(Uint32 UAVAccessFlags); +GLenum TypeToGLTexFormat(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized); +GLenum StencilOp2GlStencilOp(STENCIL_OP StencilOp); +GLenum BlendFactor2GLBlend(BLEND_FACTOR bf); +GLenum BlendOperation2GLBlendOp(BLEND_OPERATION BlendOp); + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp index f4bff6a0..bce00b60 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp @@ -29,7 +29,7 @@ #include "BufferGLImpl.hpp" #include "RenderDeviceGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "BufferViewGLImpl.hpp" #include "DeviceContextGLImpl.hpp" #include "EngineMemory.h" diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp index 024c2dae..8133df48 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp @@ -31,7 +31,7 @@ #include "DeviceContextGLImpl.hpp" #include "BufferViewGLImpl.hpp" #include "BufferGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index eca2ccfe..8b13486d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -33,7 +33,7 @@ #include "SwapChainGL.h" #include "DeviceContextGLImpl.hpp" #include "RenderDeviceGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "BufferGLImpl.hpp" #include "ShaderGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp index 2a35bd28..d81620a4 100644 --- a/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp @@ -33,7 +33,7 @@ #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" #include "EngineMemory.h" -#include "HLSL2GLSLConverterObject.h" +#include "HLSL2GLSLConverterObject.hpp" #include "EngineFactoryBase.hpp" #if PLATFORM_IOS diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp index da7a2847..9980d69f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp @@ -31,7 +31,7 @@ #include "TextureBaseGL.hpp" #include "SamplerGLImpl.hpp" #include "AsyncWritableResource.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "BufferViewGLImpl.hpp" #include "RenderDeviceGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp index 71c23a13..2bfd7d9d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp @@ -29,7 +29,7 @@ #include "GLContextWindows.hpp" #include "DeviceCaps.h" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/GLTypeConversions.cpp b/Graphics/GraphicsEngineOpenGL/src/GLTypeConversions.cpp index e534f64d..dde10533 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLTypeConversions.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLTypeConversions.cpp @@ -26,7 +26,7 @@ */ #include "pch.h" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 3f254d5c..c2e6a576 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -41,7 +41,7 @@ #include "TextureCubeArray_OGL.hpp" #include "SamplerGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "PipelineStateGLImpl.hpp" #include "ShaderResourceBindingGLImpl.hpp" #include "FenceGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp index 2b34841c..ddf73df4 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp @@ -28,7 +28,7 @@ #include "pch.h" #include "SamplerGLImpl.hpp" #include "RenderDeviceGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp index 4cbfa8e0..2dd93b6c 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp @@ -30,7 +30,7 @@ #include "Texture1DArray_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "BufferGLImpl.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp index 40cea68d..8f385238 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp @@ -30,7 +30,7 @@ #include "Texture1D_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "BufferGLImpl.hpp" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp index 39e65b03..4c9c0e19 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp @@ -30,7 +30,7 @@ #include "Texture2DArray_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" #include "BufferGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp index 4bdaf683..e854960f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp @@ -30,7 +30,7 @@ #include "Texture2D_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" #include "BufferGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp index e915a3ed..7b4d19a0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp @@ -30,7 +30,7 @@ #include "Texture3D_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" #include "BufferGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp index dc463a24..72733d70 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp @@ -29,7 +29,7 @@ #include "TextureBaseGL.hpp" #include "RenderDeviceGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "TextureViewGLImpl.hpp" #include "GLContextState.hpp" #include "DeviceContextGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp index e58863ed..646e78f2 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp @@ -30,7 +30,7 @@ #include "TextureCubeArray_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" #include "BufferGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp index 27a296e1..8193aca5 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp @@ -30,7 +30,7 @@ #include "TextureCube_OGL.hpp" #include "RenderDeviceGLImpl.hpp" #include "DeviceContextGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GraphicsAccessories.hpp" #include "BufferGLImpl.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp b/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp index a3388293..cecadcba 100644 --- a/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp @@ -31,7 +31,7 @@ #include "RenderDeviceGLImpl.hpp" #include "GLObjectWrapper.hpp" #include "BufferGLImpl.hpp" -#include "GLTypeConversions.h" +#include "GLTypeConversions.hpp" #include "GLContextState.hpp" #include "PipelineStateGLImpl.hpp" diff --git a/Graphics/GraphicsTools/interface/CommonlyUsedStates.h b/Graphics/GraphicsTools/interface/CommonlyUsedStates.h index 34c58b19..3b18d6ae 100644 --- a/Graphics/GraphicsTools/interface/CommonlyUsedStates.h +++ b/Graphics/GraphicsTools/interface/CommonlyUsedStates.h @@ -36,8 +36,7 @@ #include "../../GraphicsEngine/interface/RasterizerState.h" #include "../../GraphicsEngine/interface/Sampler.h" -namespace Diligent -{ +DILIGENT_BEGIN_NAMESPACE(Diligent) // clang-format off @@ -224,4 +223,4 @@ static const SamplerDesc Sam_Aniso8xWrap 8 // MaxAnisotropy }; -} +DILIGENT_END_NAMESPACE // namespace Diligent diff --git a/Graphics/GraphicsTools/interface/GraphicsUtilities.h b/Graphics/GraphicsTools/interface/GraphicsUtilities.h index 03dcd829..0ca5ad54 100644 --- a/Graphics/GraphicsTools/interface/GraphicsUtilities.h +++ b/Graphics/GraphicsTools/interface/GraphicsUtilities.h @@ -34,8 +34,7 @@ #include "../../GraphicsEngine/interface/Buffer.h" #include "../../GraphicsEngine/interface/RenderDevice.h" -namespace Diligent -{ +DILIGENT_BEGIN_NAMESPACE(Diligent) void CreateUniformBuffer(IRenderDevice* pDevice, Uint32 Size, @@ -54,4 +53,4 @@ void GenerateCheckerBoardPattern(Uint32 Width, Uint8* pData, Uint32 StrideInBytes); -} // namespace Diligent +DILIGENT_END_NAMESPACE // namespace Diligent diff --git a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp index 14fe131a..624a615a 100644 --- a/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp +++ b/Graphics/GraphicsTools/src/TextureUploaderD3D11.cpp @@ -38,7 +38,7 @@ #include "RenderDeviceD3D11.h" #include "DeviceContextD3D11.h" #include "TextureD3D11.h" -#include "DXGITypeConversions.h" +#include "DXGITypeConversions.hpp" #include "ThreadSignal.hpp" #include "GraphicsAccessories.hpp" diff --git a/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt b/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt index 90730324..109687df 100644 --- a/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt +++ b/Graphics/HLSL2GLSLConverterLib/CMakeLists.txt @@ -4,8 +4,8 @@ project(Diligent-HLSL2GLSLConverterLib CXX) set(INCLUDE include/GLSLDefinitions.h - include/HLSL2GLSLConverterImpl.h - include/HLSL2GLSLConverterObject.h + include/HLSL2GLSLConverterImpl.hpp + include/HLSL2GLSLConverterObject.hpp include/HLSLKeywords.h ) diff --git a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h deleted file mode 100644 index 0777dbdd..00000000 --- a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.h +++ /dev/null @@ -1,661 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include -#include -#include -#include - -#include "HLSL2GLSLConverter.h" -#include "ObjectBase.h" -#include "HLSLKeywords.h" -#include "Shader.h" -#include "HashUtils.hpp" -#include "HLSLKeywords.h" - -namespace Diligent -{ - -struct FunctionStubHashKey -{ - // clang-format off - FunctionStubHashKey(const String& _Obj, const String& _Func, Uint32 _NumArgs) : - Object {_Obj }, - Function {_Func }, - NumArguments{_NumArgs} - { - } - - FunctionStubHashKey(const Char* _Obj, const Char* _Func, Uint32 _NumArgs) : - Object {_Obj }, - Function {_Func }, - NumArguments{_NumArgs} - { - } - - FunctionStubHashKey(FunctionStubHashKey&& Key) : - Object {std::move(Key.Object) }, - Function {std::move(Key.Function)}, - NumArguments{Key.NumArguments } - { - } - // clang-format on - - bool operator==(const FunctionStubHashKey& rhs) const - { - return Object == rhs.Object && - Function == rhs.Function && - NumArguments == rhs.NumArguments; - } - - HashMapStringKey Object; - HashMapStringKey Function; - Uint32 NumArguments; - - struct Hasher - { - size_t operator()(const FunctionStubHashKey& Key) const - { - return ComputeHash(Key.Object.GetHash(), Key.Function.GetHash(), Key.NumArguments); - } - }; -}; - -/// HLSL to GLSL shader source code converter implementation -class HLSL2GLSLConverterImpl -{ -public: - static const HLSL2GLSLConverterImpl& GetInstance(); - - // clang-format off - - /// Conversion attributes - struct ConversionAttribs - { - /// Shader source input stream factory. Used to load shader source when HLSLSource is null as - /// well as to load shader includes. - IShaderSourceInputStreamFactory* pSourceStreamFactory = nullptr; - - /// Optional pointer to a conversion stream. - IHLSL2GLSLConversionStream** ppConversionStream = nullptr; - - /// HLSL source code. Can be null, in which case the source code will be loaded from the - /// input stream factory (that must not be null in this case) using InputFileName. - const Char* HLSLSource = nullptr; - - /// Number of symbols in HLSLSource string. Ignored if HLSLSource is null. - size_t NumSymbols = 0; - - /// Shader entry point. - const Char* EntryPoint = nullptr; - - /// Shader type. See Diligent::SHADER_TYPE. - SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN; - - /// Whether to include GLSL definitions supporting HLSL->GLSL conversion. - bool IncludeDefinitions = false; - - /// Input file name. If HLSLSource is not null, this name will only be used for - /// information purposes. If HLSLSource is null, the name will be used to load - /// shader source from the input stream factory. - const Char* InputFileName = nullptr; - - /// Combined texture sampler suffix. - const Char* SamplerSuffix = "_sampler"; - - /// Whether to use in-out location qualifiers. - /// This requires separate shader objects extension: - /// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_separate_shader_objects.txt - bool UseInOutLocationQualifiers = true; - }; - - // clang-format on - - /// Converts HLSL source to GLSL - - /// \param [in] Attribs - Conversion attributes. - /// \return Converted GLSL source code. - String Convert(ConversionAttribs& Attribs) const; - - /// Creates a conversion stream - - /// \param [in] InputFileName - Input file name. If HLSLSource is null, this name will be - /// used to load shader source code from the input stream factory. - /// If HLSLSource is not null, the name will only be used for information - /// purposes. - /// \param [in] pSourceStreamFactory - Input stream factory that is used to load shader includes as well - /// as to load the shader source code if HLSLSource is null. - /// \param [in] HLSLSource - HLSL source code. If this parameter is null, the source will be loaded from - /// the input stream factory using InputFileName. - /// \param [in] NumSymbols - Number of symbols in the HLSLSource string - /// \prarm [out] ppStream - Memory address where pointer to the created stream will be written - void CreateStream(const Char* InputFileName, - IShaderSourceInputStreamFactory* pSourceStreamFactory, - const Char* HLSLSource, - size_t NumSymbols, - IHLSL2GLSLConversionStream** ppStream) const; - -private: - HLSL2GLSLConverterImpl(); - - struct HLSLObjectInfo - { - String GLSLType; // sampler2D, sampler2DShadow, image2D, etc. - Uint32 NumComponents; // 0,1,2,3 or 4 - // Texture2D -> 4 - // Texture2D -> 1 - // Texture2D -> 0 - HLSLObjectInfo(const String& Type, Uint32 NComp) : - GLSLType{Type}, - NumComponents{NComp} - {} - }; - struct ObjectsTypeHashType - { - // This is only required to make the code compile on paranoid MSVC 2017 compiler (19.10.25017): - // https://stackoverflow.com/questions/47604029/move-constructors-of-stl-containers-in-msvc-2017-are-not-marked-as-noexcept - ObjectsTypeHashType() noexcept {} - ObjectsTypeHashType(ObjectsTypeHashType&& rhs) noexcept : - m{std::move(rhs.m)} - {} - // clang-format off - ObjectsTypeHashType& operator = (ObjectsTypeHashType&&) = delete; - ObjectsTypeHashType (ObjectsTypeHashType&) = delete; - ObjectsTypeHashType& operator = (ObjectsTypeHashType&) = delete; - // clang-format on - - std::unordered_map m; - }; - - struct GLSLStubInfo - { - String Name; - String Swizzle; - GLSLStubInfo(const String& _Name, const char* _Swizzle) : - Name{_Name}, - Swizzle{_Swizzle} - {} - }; - // Hash map that maps GLSL object, method and number of arguments - // passed to the original function, to the GLSL stub function - // Example: {"sampler2D", "Sample", 2} -> {"Sample_2", "_SWIZZLE"} - std::unordered_map m_GLSLStubs; - - // clang-format off - enum class TokenType - { - Undefined, -#define ADD_KEYWORD(keyword)kw_##keyword, - ITERATE_KEYWORDS(ADD_KEYWORD) -#undef ADD_KEYWORD - PreprocessorDirective, - Operator, - OpenBrace, - ClosingBrace, - OpenBracket, - ClosingBracket, - OpenStaple, - ClosingStaple, - OpenAngleBracket, - ClosingAngleBracket, - Identifier, - NumericConstant, - SrtingConstant, - Semicolon, - Comma, - TextBlock, - Assignment, - ComparisonOp, - BooleanOp, - BitwiseOp, - IncDecOp, - MathOp - }; - // clang-format on - - struct TokenInfo - { - TokenType Type; - String Literal; - String Delimiter; - - bool IsBuiltInType() const - { - static_assert(static_cast(TokenType::kw_bool) == 1 && static_cast(TokenType::kw_void) == 191, - "If you updated built-in types, double check that all types are defined between bool and void"); - return Type >= TokenType::kw_bool && Type <= TokenType::kw_void; - } - - bool IsFlowControl() const - { - static_assert(static_cast(TokenType::kw_break) == 192 && static_cast(TokenType::kw_while) == 202, - "If you updated control flow keywords, double check that all keywords are defined between break and while"); - return Type >= TokenType::kw_break && Type <= TokenType::kw_while; - } - - TokenInfo(TokenType _Type = TokenType::Undefined, - const Char* _Literal = "", - const Char* _Delimiter = "") : - Type{_Type}, - Literal{_Literal}, - Delimiter{_Delimiter} - {} - }; - typedef std::list TokenListType; - - - class ConversionStream : public ObjectBase - { - public: - using TBase = ObjectBase; - - /// Conversion stream constructor. - - /// \param [in] pRefCounters - Pointer to a reference counters object - /// \param [in] Converter - Reference to HLSL2GLSLConverterImpl class instance - /// \param [in] InputFileName - Input file name. If HLSLSource is null, this name will be - /// used to load shader source code from the input stream factory. - /// If HLSLSource is not null, the name will only be used for information - /// purposes. - /// \param [in] pInputStreamFactory - Input stream factory that is used to load shader includes as well - /// as to load the shader source code if HLSLSource is null. - /// \param [in] HLSLSource - HLSL source code. If this parameter is null, the source will be loaded from - /// the input stream factory using InputFileName. - /// \param [in] NumSymbols - Number of symbols in the HLSLSource string - /// \param [in] bPreserveTokens - Whether to preserve original tokens. This must be set to true if the stream - /// will be used for multiple conversions. - ConversionStream(IReferenceCounters* pRefCounters, - const HLSL2GLSLConverterImpl& Converter, - const char* InputFileName, - IShaderSourceInputStreamFactory* pInputStreamFactory, - const Char* HLSLSource, - size_t NumSymbols, - bool bPreserveTokens); - - String Convert(const Char* EntryPoint, - SHADER_TYPE ShaderType, - bool IncludeDefintions, - const char* SamplerSuffix, - bool UseInOutLocationQualifiers); - - virtual void Convert(const Char* EntryPoint, - SHADER_TYPE ShaderType, - bool IncludeDefintions, - const char* SamplerSuffix, - bool UseInOutLocationQualifiers, - IDataBlob** ppGLSLSource) override final; - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_HLSL2GLSLConversionStream, TBase) - - const String& GetInputFileName() const { return m_InputFileName; } - - private: - void InsertIncludes(String& GLSLSource, IShaderSourceInputStreamFactory* pSourceStreamFactory); - void Tokenize(const String& Source); - - typedef std::unordered_map SamplerHashType; - - const HLSLObjectInfo* FindHLSLObject(const String& Name); - - void ProcessShaderDeclaration(TokenListType::iterator EntryPointToken, SHADER_TYPE ShaderType); - - void ProcessObjectMethods(const TokenListType::iterator& ScopeStart, const TokenListType::iterator& ScopeEnd); - - void ProcessRWTextures(const TokenListType::iterator& ScopeStart, const TokenListType::iterator& ScopeEnd); - - void ProcessAtomics(const TokenListType::iterator& ScopeStart, - const TokenListType::iterator& ScopeEnd); - - void RegisterStruct(TokenListType::iterator& Token); - - void ProcessConstantBuffer(TokenListType::iterator& Token); - void ProcessStructuredBuffer(TokenListType::iterator& Token, Uint32& ShaderStorageBlockBinding); - void ParseSamplers(TokenListType::iterator& ScopeStart, SamplerHashType& SamplersHash); - - void ProcessTextureDeclaration(TokenListType::iterator& Token, - const std::vector& SamplersHash, - ObjectsTypeHashType& Objects, - const char* SamplerSuffix, - Uint32& ImageBinding); - - bool ProcessObjectMethod(TokenListType::iterator& Token, - const TokenListType::iterator& ScopeStart, - const TokenListType::iterator& ScopeEnd); - - Uint32 CountFunctionArguments(TokenListType::iterator& Token, const TokenListType::iterator& ScopeEnd); - bool ProcessRWTextureStore(TokenListType::iterator& Token, const TokenListType::iterator& ScopeEnd); - void RemoveFlowControlAttribute(TokenListType::iterator& Token); - void RemoveSemantics(); - void RemoveSpecialShaderAttributes(); - void RemoveSemanticsFromBlock(TokenListType::iterator& Token, TokenType OpenBracketType, TokenType ClosingBracketType); - void RemoveSamplerRegister(TokenListType::iterator& Token); - - // IteratorType may be String::iterator or String::const_iterator. - // While iterator is convertible to const_iterator, - // iterator& cannot be converted to const_iterator& (Microsoft compiler allows - // such conversion, while gcc does not) - template - String PrintTokenContext(IteratorType& TargetToken, Int32 NumAdjacentLines); - - struct ShaderParameterInfo - { - enum class StorageQualifier : Int8 - { - Unknown = 0, - In = 1, - Out = 2, - InOut = 3, - Ret = 4 - } storageQualifier; - - struct GSAttributes - { - enum class PrimitiveType : Int8 - { - Undefined = 0, - Point = 1, - Line = 2, - Triangle = 3, - LineAdj = 4, - TriangleAdj = 5 - }; - enum class StreamType : Int8 - { - Undefined = 0, - Point = 1, - Line = 2, - Triangle = 3 - }; - PrimitiveType PrimType; - StreamType Stream; - GSAttributes() : - PrimType{PrimitiveType::Undefined}, - Stream{StreamType::Undefined} - {} - } GSAttribs; - - struct HSAttributes - { - enum class InOutPatchType : Int8 - { - Undefined = 0, - InputPatch = 1, - OutputPatch = 2 - } PatchType; - HSAttributes() : - PatchType{InOutPatchType::Undefined} - {} - } HSAttribs; - - String ArraySize; - String Type; - String Name; - String Semantic; - - std::vector members; - - ShaderParameterInfo() : - storageQualifier{StorageQualifier::Unknown} - {} - }; - void ParseShaderParameter(TokenListType::iterator& Token, - ShaderParameterInfo& ParamInfo); - void ProcessFunctionParameters(TokenListType::iterator& Token, - std::vector& Params, - bool& bIsVoid); - bool RequiresFlatQualifier(const String& Type); - void ProcessFragmentShaderArguments(std::vector& Params, - String& GlobalVariables, - std::stringstream& ReturnHandlerSS, - String& Prologue); - - String BuildParameterName(const std::vector& MemberStack, - Char Separator, - const Char* Prefix = "", - const Char* SubstituteInstName = "", - const Char* Index = ""); - - template - void ProcessScope(TokenListType::iterator& Token, - TokenListType::iterator ScopeEnd, - TokenType OpenParenType, - TokenType ClosingParenType, - THandler Handler); - - template - void ProcessShaderArgument(const ShaderParameterInfo& Param, - int ShaderInd, - int IsOutVar, - std::stringstream& PrologueSS, - TArgHandler ArgHandler); - - void ProcessVertexShaderArguments(std::vector& Params, - String& Globals, - std::stringstream& ReturnHandlerSS, - String& Prologue); - - void ProcessGeometryShaderArguments(TokenListType::iterator& TypeToken, - std::vector& Params, - String& Globals, - String& Prologue); - - void ProcessHullShaderConstantFunction(const Char* FuncName, bool& bTakesInputPatch); - - void ProcessShaderAttributes(TokenListType::iterator& TypeToken, - std::unordered_map& Attributes); - - void ProcessHullShaderArguments(TokenListType::iterator& TypeToken, - std::vector& Params, - String& Globals, - std::stringstream& ReturnHandlerSS, - String& Prologue); - void ProcessDomainShaderArguments(TokenListType::iterator& TypeToken, - std::vector& Params, - String& Globals, - std::stringstream& ReturnHandlerSS, - String& Prologue); - void ProcessComputeShaderArguments(TokenListType::iterator& TypeToken, - std::vector& Params, - String& Globals, - String& Prologue); - - void FindClosingBracket(TokenListType::iterator& Token, - const TokenListType::iterator& ScopeEnd, - TokenType OpenBracketType, - TokenType ClosingBracketType); - - void ProcessReturnStatements(TokenListType::iterator& Token, - bool IsVoid, - const Char* EntryPoint, - const Char* MacroName); - - void ProcessGSOutStreamOperations(TokenListType::iterator& Token, - const String& OutStreamName, - const char* EntryPoint); - - String BuildGLSLSource(); - - // Tokenized source code - TokenListType m_Tokens; - - // List of tokens defining structs - std::unordered_map m_StructDefinitions; - - // Stack of parsed objects, for every scope level. - // There are currently only two levels: - // level 0 - global scope, contains all global objects - // (textures, buffers) - // level 1 - function body, contains all objects - // defined as function arguments - std::vector m_Objects; - - const bool m_bPreserveTokens; - bool m_bUseInOutLocationQualifiers = true; - - const HLSL2GLSLConverterImpl& m_Converter; - - // This member is only used to compare input name - // when subsequent shaders are converted from already tokenized source - const String m_InputFileName; - }; - - // HLSL keyword->token info hash map - // Example: "Texture2D" -> TokenInfo(TokenType::Texture2D, "Texture2D") - std::unordered_map m_HLSLKeywords; - - // Set of all GLSL image types (image1D, uimage1D, iimage1D, image2D, ... ) - std::unordered_set m_ImageTypes; - - // Set of all HLSL atomic operations (InterlockedAdd, InterlockedOr, ...) - std::unordered_set m_AtomicOperations; - - // HLSL semantic -> glsl variable, for every shader stage and input/output type (in == 0, out == 1) - // Example: [vertex, output] SV_Position -> gl_Position - // [fragment, input] SV_Position -> gl_FragCoord - static constexpr int InVar = 0; - static constexpr int OutVar = 1; - std::unordered_map m_HLSLSemanticToGLSLVar[6][2]; -}; - -} // namespace Diligent - -// Intro -// DirectX and OpenGL use different shading languages. While mostly being very similar, -// the language syntax differs substantially sometimes. Having two versions of each -// shader is clearly not an option for real projects. Maintaining intermediate representation -// that translates to both languages is one solution, but it might complicate shader development -// and debugging. -// -// HLSL converter allows HLSL shader files to be converted into GLSL source. -// The entire shader development can thus be performed using HLSL tools. Since no intermediate -// representation is used, shader files can be directly compiled by the HLSL compiler. -// All tools available for HLSL shader devlopment, analysis and optimization can be -// used. The source can then be transaprently converted to GLSL. -// -// -// Using HLSL Converter -// * The following rules are used to convert HLSL texture declaration into GLSL sampler: -// - HLSL texture dimension defines GLSL sampler dimension: -// - Texture2D -> sampler2D -// - TextureCube -> samplerCube -// - HLSL texture component type defines GLSL sampler type. If no type is specified, float4 is assumed: -// - Texture2D -> sampler2D -// - Texture3D -> usampler3D -// - Texture2DArray -> isampler2DArray -// - Texture2D -> sampler2D -// - To distinguish if sampler should be shadow or not, the converter tries to find _sampler -// among samplers (global variables and function arguments). If the sampler type is comparison, -// the texture is converted to shadow sampler. If sampler state is either not comparison or not found, -// regular sampler is used. -// Examples: -// - Texture2D g_ShadowMap; -> sampler2DShadow g_ShadowMap; -// SamplerComparisonState g_ShadowMap_sampler; -// - Texture2D g_Tex2D; -> sampler2D g_Tex2D; -// SamplerState g_Tex2D_sampler; -// Texture3D g_Tex3D; -> sampler3D g_Tex3D; -// -// * GLSL requires format to be specified for all images allowing writes. HLSL converter allows GLSL image -// format specification inside the special comment block: -// Example: -// RWTexture2D Tex2D; -// * In OpenGL tessellation, domain, partitioning, and topology are properties of tessellation evaluation -// shader rather than tessellation control shader. The following specially formatted comment should be placed -// on top of domain shader declararion to specify the attributes -// /* partitioning = {integer|fractional_even|fractional_odd}, outputtopology = {triangle_cw|triangle_ccw} */ -// Example: -// /* partitioning = fractional_even, outputtopology = triangle_cw */ - - -// Requirements: -// * GLSL allows samplers to be declared as global variables or function arguments only. -// It does not allow local variables of sampler type. -// -// Important notes/known issues: -// -// * GLSL compiler does not handle float3 structure members correctly. It is -// strongly suggested not to use this type in structure definitions -// -// * At least NVidia GLSL compiler does not apply layout(row_major) to -// structure members. By default, all matrices in both HLSL and GLSL -// are column major -// -// * GLSL compiler does not properly handle structs passed as function arguments!!!! -// struct MyStruct -// { -// matrix Matr; -// } -// void Func(in MyStruct S) -// { -// ... -// mul(f4PosWS, S.Matr); <--- This will not work!!! -// } -// DO NOT pass structs to functions, use only built-in types!!! -// -// * GLSL does not support most of the implicit type conversions. The following are some -// examples of required modifications to HLSL code: -// ** float4 vec = 0; -> float4 vec = float4(0.0, 0.0, 0.0, 0.0); -// ** float x = 0; -> float x = 0.0; -// ** uint x = 0; -> uint x = 0u; -// ** GLES is immensely strict about type conversions. For instance, -// this code will produce compiler error: float4(0, 0, 0, 0) -// It must be written as float4(0.0, 0.0, 0.0, 0.0) -// * GLSL does not support relational and boolean operations on vector types: -// ** float2 p = float2(1.0,2.0), q = float2(3.0,4.0); -// bool2 b = x < y; -> Error -// all(p Error -// ** To facilitate relational and boolean operations on vector types, the following -// functions are predefined: -// - Less -// - LessEqual -// - Greater -// - GreaterEqual -// - Equal -// - NotEqual -// - Not -// - And -// - Or -// - BoolToFloat -// ** Examples: -// bool2 b = x < y; -> bool2 b = Less(x, y); -// all(p>=q) -> all( GreaterEqual(p,q) ) -// -// * When accessing elements of an HLSL matrix, the first index is always row: -// mat[row][column] -// In GLSL, the first index is always column: -// mat[column][row] -// MATRIX_ELEMENT(mat, row, col) macros is provided to facilitate matrix element retrieval - -// * The following functions do not have counterparts in GLSL and should be avoided: -// ** Texture2DArray.SampleCmpLevelZero() -// ** TextureCube.SampleCmpLevelZero() -// ** TextureCubeArray.SampleCmpLevelZero() - - -// * Input variables to a shader stage must be listed in exact same order as outputs from -// the previous stage. Function return value counts as the first output argument. diff --git a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.hpp b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.hpp new file mode 100644 index 00000000..0777dbdd --- /dev/null +++ b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterImpl.hpp @@ -0,0 +1,661 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include +#include +#include +#include + +#include "HLSL2GLSLConverter.h" +#include "ObjectBase.h" +#include "HLSLKeywords.h" +#include "Shader.h" +#include "HashUtils.hpp" +#include "HLSLKeywords.h" + +namespace Diligent +{ + +struct FunctionStubHashKey +{ + // clang-format off + FunctionStubHashKey(const String& _Obj, const String& _Func, Uint32 _NumArgs) : + Object {_Obj }, + Function {_Func }, + NumArguments{_NumArgs} + { + } + + FunctionStubHashKey(const Char* _Obj, const Char* _Func, Uint32 _NumArgs) : + Object {_Obj }, + Function {_Func }, + NumArguments{_NumArgs} + { + } + + FunctionStubHashKey(FunctionStubHashKey&& Key) : + Object {std::move(Key.Object) }, + Function {std::move(Key.Function)}, + NumArguments{Key.NumArguments } + { + } + // clang-format on + + bool operator==(const FunctionStubHashKey& rhs) const + { + return Object == rhs.Object && + Function == rhs.Function && + NumArguments == rhs.NumArguments; + } + + HashMapStringKey Object; + HashMapStringKey Function; + Uint32 NumArguments; + + struct Hasher + { + size_t operator()(const FunctionStubHashKey& Key) const + { + return ComputeHash(Key.Object.GetHash(), Key.Function.GetHash(), Key.NumArguments); + } + }; +}; + +/// HLSL to GLSL shader source code converter implementation +class HLSL2GLSLConverterImpl +{ +public: + static const HLSL2GLSLConverterImpl& GetInstance(); + + // clang-format off + + /// Conversion attributes + struct ConversionAttribs + { + /// Shader source input stream factory. Used to load shader source when HLSLSource is null as + /// well as to load shader includes. + IShaderSourceInputStreamFactory* pSourceStreamFactory = nullptr; + + /// Optional pointer to a conversion stream. + IHLSL2GLSLConversionStream** ppConversionStream = nullptr; + + /// HLSL source code. Can be null, in which case the source code will be loaded from the + /// input stream factory (that must not be null in this case) using InputFileName. + const Char* HLSLSource = nullptr; + + /// Number of symbols in HLSLSource string. Ignored if HLSLSource is null. + size_t NumSymbols = 0; + + /// Shader entry point. + const Char* EntryPoint = nullptr; + + /// Shader type. See Diligent::SHADER_TYPE. + SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN; + + /// Whether to include GLSL definitions supporting HLSL->GLSL conversion. + bool IncludeDefinitions = false; + + /// Input file name. If HLSLSource is not null, this name will only be used for + /// information purposes. If HLSLSource is null, the name will be used to load + /// shader source from the input stream factory. + const Char* InputFileName = nullptr; + + /// Combined texture sampler suffix. + const Char* SamplerSuffix = "_sampler"; + + /// Whether to use in-out location qualifiers. + /// This requires separate shader objects extension: + /// https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_separate_shader_objects.txt + bool UseInOutLocationQualifiers = true; + }; + + // clang-format on + + /// Converts HLSL source to GLSL + + /// \param [in] Attribs - Conversion attributes. + /// \return Converted GLSL source code. + String Convert(ConversionAttribs& Attribs) const; + + /// Creates a conversion stream + + /// \param [in] InputFileName - Input file name. If HLSLSource is null, this name will be + /// used to load shader source code from the input stream factory. + /// If HLSLSource is not null, the name will only be used for information + /// purposes. + /// \param [in] pSourceStreamFactory - Input stream factory that is used to load shader includes as well + /// as to load the shader source code if HLSLSource is null. + /// \param [in] HLSLSource - HLSL source code. If this parameter is null, the source will be loaded from + /// the input stream factory using InputFileName. + /// \param [in] NumSymbols - Number of symbols in the HLSLSource string + /// \prarm [out] ppStream - Memory address where pointer to the created stream will be written + void CreateStream(const Char* InputFileName, + IShaderSourceInputStreamFactory* pSourceStreamFactory, + const Char* HLSLSource, + size_t NumSymbols, + IHLSL2GLSLConversionStream** ppStream) const; + +private: + HLSL2GLSLConverterImpl(); + + struct HLSLObjectInfo + { + String GLSLType; // sampler2D, sampler2DShadow, image2D, etc. + Uint32 NumComponents; // 0,1,2,3 or 4 + // Texture2D -> 4 + // Texture2D -> 1 + // Texture2D -> 0 + HLSLObjectInfo(const String& Type, Uint32 NComp) : + GLSLType{Type}, + NumComponents{NComp} + {} + }; + struct ObjectsTypeHashType + { + // This is only required to make the code compile on paranoid MSVC 2017 compiler (19.10.25017): + // https://stackoverflow.com/questions/47604029/move-constructors-of-stl-containers-in-msvc-2017-are-not-marked-as-noexcept + ObjectsTypeHashType() noexcept {} + ObjectsTypeHashType(ObjectsTypeHashType&& rhs) noexcept : + m{std::move(rhs.m)} + {} + // clang-format off + ObjectsTypeHashType& operator = (ObjectsTypeHashType&&) = delete; + ObjectsTypeHashType (ObjectsTypeHashType&) = delete; + ObjectsTypeHashType& operator = (ObjectsTypeHashType&) = delete; + // clang-format on + + std::unordered_map m; + }; + + struct GLSLStubInfo + { + String Name; + String Swizzle; + GLSLStubInfo(const String& _Name, const char* _Swizzle) : + Name{_Name}, + Swizzle{_Swizzle} + {} + }; + // Hash map that maps GLSL object, method and number of arguments + // passed to the original function, to the GLSL stub function + // Example: {"sampler2D", "Sample", 2} -> {"Sample_2", "_SWIZZLE"} + std::unordered_map m_GLSLStubs; + + // clang-format off + enum class TokenType + { + Undefined, +#define ADD_KEYWORD(keyword)kw_##keyword, + ITERATE_KEYWORDS(ADD_KEYWORD) +#undef ADD_KEYWORD + PreprocessorDirective, + Operator, + OpenBrace, + ClosingBrace, + OpenBracket, + ClosingBracket, + OpenStaple, + ClosingStaple, + OpenAngleBracket, + ClosingAngleBracket, + Identifier, + NumericConstant, + SrtingConstant, + Semicolon, + Comma, + TextBlock, + Assignment, + ComparisonOp, + BooleanOp, + BitwiseOp, + IncDecOp, + MathOp + }; + // clang-format on + + struct TokenInfo + { + TokenType Type; + String Literal; + String Delimiter; + + bool IsBuiltInType() const + { + static_assert(static_cast(TokenType::kw_bool) == 1 && static_cast(TokenType::kw_void) == 191, + "If you updated built-in types, double check that all types are defined between bool and void"); + return Type >= TokenType::kw_bool && Type <= TokenType::kw_void; + } + + bool IsFlowControl() const + { + static_assert(static_cast(TokenType::kw_break) == 192 && static_cast(TokenType::kw_while) == 202, + "If you updated control flow keywords, double check that all keywords are defined between break and while"); + return Type >= TokenType::kw_break && Type <= TokenType::kw_while; + } + + TokenInfo(TokenType _Type = TokenType::Undefined, + const Char* _Literal = "", + const Char* _Delimiter = "") : + Type{_Type}, + Literal{_Literal}, + Delimiter{_Delimiter} + {} + }; + typedef std::list TokenListType; + + + class ConversionStream : public ObjectBase + { + public: + using TBase = ObjectBase; + + /// Conversion stream constructor. + + /// \param [in] pRefCounters - Pointer to a reference counters object + /// \param [in] Converter - Reference to HLSL2GLSLConverterImpl class instance + /// \param [in] InputFileName - Input file name. If HLSLSource is null, this name will be + /// used to load shader source code from the input stream factory. + /// If HLSLSource is not null, the name will only be used for information + /// purposes. + /// \param [in] pInputStreamFactory - Input stream factory that is used to load shader includes as well + /// as to load the shader source code if HLSLSource is null. + /// \param [in] HLSLSource - HLSL source code. If this parameter is null, the source will be loaded from + /// the input stream factory using InputFileName. + /// \param [in] NumSymbols - Number of symbols in the HLSLSource string + /// \param [in] bPreserveTokens - Whether to preserve original tokens. This must be set to true if the stream + /// will be used for multiple conversions. + ConversionStream(IReferenceCounters* pRefCounters, + const HLSL2GLSLConverterImpl& Converter, + const char* InputFileName, + IShaderSourceInputStreamFactory* pInputStreamFactory, + const Char* HLSLSource, + size_t NumSymbols, + bool bPreserveTokens); + + String Convert(const Char* EntryPoint, + SHADER_TYPE ShaderType, + bool IncludeDefintions, + const char* SamplerSuffix, + bool UseInOutLocationQualifiers); + + virtual void Convert(const Char* EntryPoint, + SHADER_TYPE ShaderType, + bool IncludeDefintions, + const char* SamplerSuffix, + bool UseInOutLocationQualifiers, + IDataBlob** ppGLSLSource) override final; + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_HLSL2GLSLConversionStream, TBase) + + const String& GetInputFileName() const { return m_InputFileName; } + + private: + void InsertIncludes(String& GLSLSource, IShaderSourceInputStreamFactory* pSourceStreamFactory); + void Tokenize(const String& Source); + + typedef std::unordered_map SamplerHashType; + + const HLSLObjectInfo* FindHLSLObject(const String& Name); + + void ProcessShaderDeclaration(TokenListType::iterator EntryPointToken, SHADER_TYPE ShaderType); + + void ProcessObjectMethods(const TokenListType::iterator& ScopeStart, const TokenListType::iterator& ScopeEnd); + + void ProcessRWTextures(const TokenListType::iterator& ScopeStart, const TokenListType::iterator& ScopeEnd); + + void ProcessAtomics(const TokenListType::iterator& ScopeStart, + const TokenListType::iterator& ScopeEnd); + + void RegisterStruct(TokenListType::iterator& Token); + + void ProcessConstantBuffer(TokenListType::iterator& Token); + void ProcessStructuredBuffer(TokenListType::iterator& Token, Uint32& ShaderStorageBlockBinding); + void ParseSamplers(TokenListType::iterator& ScopeStart, SamplerHashType& SamplersHash); + + void ProcessTextureDeclaration(TokenListType::iterator& Token, + const std::vector& SamplersHash, + ObjectsTypeHashType& Objects, + const char* SamplerSuffix, + Uint32& ImageBinding); + + bool ProcessObjectMethod(TokenListType::iterator& Token, + const TokenListType::iterator& ScopeStart, + const TokenListType::iterator& ScopeEnd); + + Uint32 CountFunctionArguments(TokenListType::iterator& Token, const TokenListType::iterator& ScopeEnd); + bool ProcessRWTextureStore(TokenListType::iterator& Token, const TokenListType::iterator& ScopeEnd); + void RemoveFlowControlAttribute(TokenListType::iterator& Token); + void RemoveSemantics(); + void RemoveSpecialShaderAttributes(); + void RemoveSemanticsFromBlock(TokenListType::iterator& Token, TokenType OpenBracketType, TokenType ClosingBracketType); + void RemoveSamplerRegister(TokenListType::iterator& Token); + + // IteratorType may be String::iterator or String::const_iterator. + // While iterator is convertible to const_iterator, + // iterator& cannot be converted to const_iterator& (Microsoft compiler allows + // such conversion, while gcc does not) + template + String PrintTokenContext(IteratorType& TargetToken, Int32 NumAdjacentLines); + + struct ShaderParameterInfo + { + enum class StorageQualifier : Int8 + { + Unknown = 0, + In = 1, + Out = 2, + InOut = 3, + Ret = 4 + } storageQualifier; + + struct GSAttributes + { + enum class PrimitiveType : Int8 + { + Undefined = 0, + Point = 1, + Line = 2, + Triangle = 3, + LineAdj = 4, + TriangleAdj = 5 + }; + enum class StreamType : Int8 + { + Undefined = 0, + Point = 1, + Line = 2, + Triangle = 3 + }; + PrimitiveType PrimType; + StreamType Stream; + GSAttributes() : + PrimType{PrimitiveType::Undefined}, + Stream{StreamType::Undefined} + {} + } GSAttribs; + + struct HSAttributes + { + enum class InOutPatchType : Int8 + { + Undefined = 0, + InputPatch = 1, + OutputPatch = 2 + } PatchType; + HSAttributes() : + PatchType{InOutPatchType::Undefined} + {} + } HSAttribs; + + String ArraySize; + String Type; + String Name; + String Semantic; + + std::vector members; + + ShaderParameterInfo() : + storageQualifier{StorageQualifier::Unknown} + {} + }; + void ParseShaderParameter(TokenListType::iterator& Token, + ShaderParameterInfo& ParamInfo); + void ProcessFunctionParameters(TokenListType::iterator& Token, + std::vector& Params, + bool& bIsVoid); + bool RequiresFlatQualifier(const String& Type); + void ProcessFragmentShaderArguments(std::vector& Params, + String& GlobalVariables, + std::stringstream& ReturnHandlerSS, + String& Prologue); + + String BuildParameterName(const std::vector& MemberStack, + Char Separator, + const Char* Prefix = "", + const Char* SubstituteInstName = "", + const Char* Index = ""); + + template + void ProcessScope(TokenListType::iterator& Token, + TokenListType::iterator ScopeEnd, + TokenType OpenParenType, + TokenType ClosingParenType, + THandler Handler); + + template + void ProcessShaderArgument(const ShaderParameterInfo& Param, + int ShaderInd, + int IsOutVar, + std::stringstream& PrologueSS, + TArgHandler ArgHandler); + + void ProcessVertexShaderArguments(std::vector& Params, + String& Globals, + std::stringstream& ReturnHandlerSS, + String& Prologue); + + void ProcessGeometryShaderArguments(TokenListType::iterator& TypeToken, + std::vector& Params, + String& Globals, + String& Prologue); + + void ProcessHullShaderConstantFunction(const Char* FuncName, bool& bTakesInputPatch); + + void ProcessShaderAttributes(TokenListType::iterator& TypeToken, + std::unordered_map& Attributes); + + void ProcessHullShaderArguments(TokenListType::iterator& TypeToken, + std::vector& Params, + String& Globals, + std::stringstream& ReturnHandlerSS, + String& Prologue); + void ProcessDomainShaderArguments(TokenListType::iterator& TypeToken, + std::vector& Params, + String& Globals, + std::stringstream& ReturnHandlerSS, + String& Prologue); + void ProcessComputeShaderArguments(TokenListType::iterator& TypeToken, + std::vector& Params, + String& Globals, + String& Prologue); + + void FindClosingBracket(TokenListType::iterator& Token, + const TokenListType::iterator& ScopeEnd, + TokenType OpenBracketType, + TokenType ClosingBracketType); + + void ProcessReturnStatements(TokenListType::iterator& Token, + bool IsVoid, + const Char* EntryPoint, + const Char* MacroName); + + void ProcessGSOutStreamOperations(TokenListType::iterator& Token, + const String& OutStreamName, + const char* EntryPoint); + + String BuildGLSLSource(); + + // Tokenized source code + TokenListType m_Tokens; + + // List of tokens defining structs + std::unordered_map m_StructDefinitions; + + // Stack of parsed objects, for every scope level. + // There are currently only two levels: + // level 0 - global scope, contains all global objects + // (textures, buffers) + // level 1 - function body, contains all objects + // defined as function arguments + std::vector m_Objects; + + const bool m_bPreserveTokens; + bool m_bUseInOutLocationQualifiers = true; + + const HLSL2GLSLConverterImpl& m_Converter; + + // This member is only used to compare input name + // when subsequent shaders are converted from already tokenized source + const String m_InputFileName; + }; + + // HLSL keyword->token info hash map + // Example: "Texture2D" -> TokenInfo(TokenType::Texture2D, "Texture2D") + std::unordered_map m_HLSLKeywords; + + // Set of all GLSL image types (image1D, uimage1D, iimage1D, image2D, ... ) + std::unordered_set m_ImageTypes; + + // Set of all HLSL atomic operations (InterlockedAdd, InterlockedOr, ...) + std::unordered_set m_AtomicOperations; + + // HLSL semantic -> glsl variable, for every shader stage and input/output type (in == 0, out == 1) + // Example: [vertex, output] SV_Position -> gl_Position + // [fragment, input] SV_Position -> gl_FragCoord + static constexpr int InVar = 0; + static constexpr int OutVar = 1; + std::unordered_map m_HLSLSemanticToGLSLVar[6][2]; +}; + +} // namespace Diligent + +// Intro +// DirectX and OpenGL use different shading languages. While mostly being very similar, +// the language syntax differs substantially sometimes. Having two versions of each +// shader is clearly not an option for real projects. Maintaining intermediate representation +// that translates to both languages is one solution, but it might complicate shader development +// and debugging. +// +// HLSL converter allows HLSL shader files to be converted into GLSL source. +// The entire shader development can thus be performed using HLSL tools. Since no intermediate +// representation is used, shader files can be directly compiled by the HLSL compiler. +// All tools available for HLSL shader devlopment, analysis and optimization can be +// used. The source can then be transaprently converted to GLSL. +// +// +// Using HLSL Converter +// * The following rules are used to convert HLSL texture declaration into GLSL sampler: +// - HLSL texture dimension defines GLSL sampler dimension: +// - Texture2D -> sampler2D +// - TextureCube -> samplerCube +// - HLSL texture component type defines GLSL sampler type. If no type is specified, float4 is assumed: +// - Texture2D -> sampler2D +// - Texture3D -> usampler3D +// - Texture2DArray -> isampler2DArray +// - Texture2D -> sampler2D +// - To distinguish if sampler should be shadow or not, the converter tries to find _sampler +// among samplers (global variables and function arguments). If the sampler type is comparison, +// the texture is converted to shadow sampler. If sampler state is either not comparison or not found, +// regular sampler is used. +// Examples: +// - Texture2D g_ShadowMap; -> sampler2DShadow g_ShadowMap; +// SamplerComparisonState g_ShadowMap_sampler; +// - Texture2D g_Tex2D; -> sampler2D g_Tex2D; +// SamplerState g_Tex2D_sampler; +// Texture3D g_Tex3D; -> sampler3D g_Tex3D; +// +// * GLSL requires format to be specified for all images allowing writes. HLSL converter allows GLSL image +// format specification inside the special comment block: +// Example: +// RWTexture2D Tex2D; +// * In OpenGL tessellation, domain, partitioning, and topology are properties of tessellation evaluation +// shader rather than tessellation control shader. The following specially formatted comment should be placed +// on top of domain shader declararion to specify the attributes +// /* partitioning = {integer|fractional_even|fractional_odd}, outputtopology = {triangle_cw|triangle_ccw} */ +// Example: +// /* partitioning = fractional_even, outputtopology = triangle_cw */ + + +// Requirements: +// * GLSL allows samplers to be declared as global variables or function arguments only. +// It does not allow local variables of sampler type. +// +// Important notes/known issues: +// +// * GLSL compiler does not handle float3 structure members correctly. It is +// strongly suggested not to use this type in structure definitions +// +// * At least NVidia GLSL compiler does not apply layout(row_major) to +// structure members. By default, all matrices in both HLSL and GLSL +// are column major +// +// * GLSL compiler does not properly handle structs passed as function arguments!!!! +// struct MyStruct +// { +// matrix Matr; +// } +// void Func(in MyStruct S) +// { +// ... +// mul(f4PosWS, S.Matr); <--- This will not work!!! +// } +// DO NOT pass structs to functions, use only built-in types!!! +// +// * GLSL does not support most of the implicit type conversions. The following are some +// examples of required modifications to HLSL code: +// ** float4 vec = 0; -> float4 vec = float4(0.0, 0.0, 0.0, 0.0); +// ** float x = 0; -> float x = 0.0; +// ** uint x = 0; -> uint x = 0u; +// ** GLES is immensely strict about type conversions. For instance, +// this code will produce compiler error: float4(0, 0, 0, 0) +// It must be written as float4(0.0, 0.0, 0.0, 0.0) +// * GLSL does not support relational and boolean operations on vector types: +// ** float2 p = float2(1.0,2.0), q = float2(3.0,4.0); +// bool2 b = x < y; -> Error +// all(p Error +// ** To facilitate relational and boolean operations on vector types, the following +// functions are predefined: +// - Less +// - LessEqual +// - Greater +// - GreaterEqual +// - Equal +// - NotEqual +// - Not +// - And +// - Or +// - BoolToFloat +// ** Examples: +// bool2 b = x < y; -> bool2 b = Less(x, y); +// all(p>=q) -> all( GreaterEqual(p,q) ) +// +// * When accessing elements of an HLSL matrix, the first index is always row: +// mat[row][column] +// In GLSL, the first index is always column: +// mat[column][row] +// MATRIX_ELEMENT(mat, row, col) macros is provided to facilitate matrix element retrieval + +// * The following functions do not have counterparts in GLSL and should be avoided: +// ** Texture2DArray.SampleCmpLevelZero() +// ** TextureCube.SampleCmpLevelZero() +// ** TextureCubeArray.SampleCmpLevelZero() + + +// * Input variables to a shader stage must be listed in exact same order as outputs from +// the previous stage. Function return value counts as the first output argument. diff --git a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.h b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.h deleted file mode 100644 index 8603ced8..00000000 --- a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2019-2020 Diligent Graphics LLC - * Copyright 2015-2019 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "ObjectBase.h" -#include "HLSL2GLSLConverter.h" - -namespace Diligent -{ - -/// Implementation of the Diligent::IHLSL2GLSLConverter interface -class HLSL2GLSLConverterObject : public ObjectBase -{ -public: - typedef ObjectBase TBase; - - HLSL2GLSLConverterObject(IReferenceCounters* pRefCounters) : - TBase{pRefCounters} - {} - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_HLSL2GLSLConverter, TBase) - - virtual void CreateStream(const Char* InputFileName, - IShaderSourceInputStreamFactory* pSourceStreamFactory, - const Char* HLSLSource, - size_t NumSymbols, - IHLSL2GLSLConversionStream** ppStream) const override; -}; - -} // namespace Diligent diff --git a/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.hpp b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.hpp new file mode 100644 index 00000000..8603ced8 --- /dev/null +++ b/Graphics/HLSL2GLSLConverterLib/include/HLSL2GLSLConverterObject.hpp @@ -0,0 +1,55 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "ObjectBase.h" +#include "HLSL2GLSLConverter.h" + +namespace Diligent +{ + +/// Implementation of the Diligent::IHLSL2GLSLConverter interface +class HLSL2GLSLConverterObject : public ObjectBase +{ +public: + typedef ObjectBase TBase; + + HLSL2GLSLConverterObject(IReferenceCounters* pRefCounters) : + TBase{pRefCounters} + {} + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_HLSL2GLSLConverter, TBase) + + virtual void CreateStream(const Char* InputFileName, + IShaderSourceInputStreamFactory* pSourceStreamFactory, + const Char* HLSLSource, + size_t NumSymbols, + IHLSL2GLSLConversionStream** ppStream) const override; +}; + +} // namespace Diligent diff --git a/Graphics/HLSL2GLSLConverterLib/interface/HLSL2GLSLConverter.h b/Graphics/HLSL2GLSLConverterLib/interface/HLSL2GLSLConverter.h index f9b0f503..3633e356 100644 --- a/Graphics/HLSL2GLSLConverterLib/interface/HLSL2GLSLConverter.h +++ b/Graphics/HLSL2GLSLConverterLib/interface/HLSL2GLSLConverter.h @@ -33,13 +33,14 @@ #include "../../GraphicsEngine/interface/Shader.h" #include "../../../Primitives/interface/DataBlob.h" -namespace Diligent -{ +DILIGENT_BEGIN_NAMESPACE(Diligent) // {1FDE020A-9C73-4A76-8AEF-C2C6C2CF0EA5} static constexpr INTERFACE_ID IID_HLSL2GLSLConversionStream = {0x1fde020a, 0x9c73, 0x4a76, {0x8a, 0xef, 0xc2, 0xc6, 0xc2, 0xcf, 0xe, 0xa5}}; +#if DILIGENT_CPP_INTERFACE + class IHLSL2GLSLConversionStream : public IObject { public: @@ -51,11 +52,17 @@ public: IDataBlob** ppGLSLSource) = 0; }; +#else + +#endif + // {44A21160-77E0-4DDC-A57E-B8B8B65B5342} static constexpr INTERFACE_ID IID_HLSL2GLSLConverter = {0x44a21160, 0x77e0, 0x4ddc, {0xa5, 0x7e, 0xb8, 0xb8, 0xb6, 0x5b, 0x53, 0x42}}; +#if DILIGENT_CPP_INTERFACE + /// Interface to the buffer object implemented in OpenGL class IHLSL2GLSLConverter : public IObject { @@ -67,4 +74,8 @@ public: IHLSL2GLSLConversionStream** ppStream) const = 0; }; -} // namespace Diligent +#else + +#endif + +DILIGENT_END_NAMESPACE // namespace Diligent diff --git a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp index ed4e617a..0d3755c1 100644 --- a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp +++ b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp @@ -357,7 +357,7 @@ #include #include -#include "HLSL2GLSLConverterImpl.h" +#include "HLSL2GLSLConverterImpl.hpp" #include "ShaderBase.hpp" #include "DataBlobImpl.hpp" #include "StringDataBlobImpl.hpp" diff --git a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterObject.cpp b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterObject.cpp index 622df3de..e2d8a69d 100644 --- a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterObject.cpp +++ b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterObject.cpp @@ -26,8 +26,8 @@ */ #include "pch.h" -#include "HLSL2GLSLConverterObject.h" -#include "HLSL2GLSLConverterImpl.h" +#include "HLSL2GLSLConverterObject.hpp" +#include "HLSL2GLSLConverterImpl.hpp" #include "StringDataBlobImpl.hpp" namespace Diligent -- cgit v1.2.3