From 16aebd657c96bd86617dc2167aac4abe065fb00f Mon Sep 17 00:00:00 2001 From: assiduous Date: Sun, 26 Jan 2020 13:59:38 -0800 Subject: Renamed .h -> .hpp in GraphicsEngineNextGenBase and GraphicsEngineD3D12 projects --- Graphics/GraphicsEngineOpenGL/CMakeLists.txt | 74 +-- .../include/AsyncWritableResource.h | 69 --- .../include/AsyncWritableResource.hpp | 69 +++ .../GraphicsEngineOpenGL/include/BufferGLImpl.h | 98 ---- .../GraphicsEngineOpenGL/include/BufferGLImpl.hpp | 98 ++++ .../include/BufferViewGLImpl.h | 68 --- .../include/BufferViewGLImpl.hpp | 68 +++ .../include/DeviceContextGLImpl.h | 258 ----------- .../include/DeviceContextGLImpl.hpp | 258 +++++++++++ Graphics/GraphicsEngineOpenGL/include/FBOCache.h | 97 ---- Graphics/GraphicsEngineOpenGL/include/FBOCache.hpp | 97 ++++ .../GraphicsEngineOpenGL/include/FenceGLImpl.h | 76 --- .../GraphicsEngineOpenGL/include/FenceGLImpl.hpp | 76 +++ Graphics/GraphicsEngineOpenGL/include/GLContext.h | 42 -- .../GraphicsEngineOpenGL/include/GLContext.hpp | 42 ++ .../GraphicsEngineOpenGL/include/GLContextState.h | 276 ----------- .../include/GLContextState.hpp | 276 +++++++++++ .../include/GLContextWindows.h | 49 -- .../include/GLContextWindows.hpp | 49 ++ .../GraphicsEngineOpenGL/include/GLObjectWrapper.h | 343 -------------- .../include/GLObjectWrapper.hpp | 343 ++++++++++++++ .../include/GLPipelineResourceLayout.h | 459 ------------------ .../include/GLPipelineResourceLayout.hpp | 459 ++++++++++++++++++ .../include/GLProgramResourceCache.h | 276 ----------- .../include/GLProgramResourceCache.hpp | 276 +++++++++++ .../include/GLProgramResources.h | 513 --------------------- .../include/GLProgramResources.hpp | 513 +++++++++++++++++++++ .../include/PipelineStateGLImpl.h | 123 ----- .../include/PipelineStateGLImpl.hpp | 123 +++++ .../GraphicsEngineOpenGL/include/QueryGLImpl.h | 71 --- .../GraphicsEngineOpenGL/include/QueryGLImpl.hpp | 71 +++ .../include/RenderDeviceGLImpl.h | 157 ------- .../include/RenderDeviceGLImpl.hpp | 157 +++++++ .../GraphicsEngineOpenGL/include/SamplerGLImpl.h | 59 --- .../GraphicsEngineOpenGL/include/SamplerGLImpl.hpp | 59 +++ .../GraphicsEngineOpenGL/include/ShaderGLImpl.h | 102 ---- .../GraphicsEngineOpenGL/include/ShaderGLImpl.hpp | 102 ++++ .../include/ShaderResourceBindingGLImpl.h | 88 ---- .../include/ShaderResourceBindingGLImpl.hpp | 88 ++++ .../GraphicsEngineOpenGL/include/SwapChainGLBase.h | 113 ----- .../include/SwapChainGLBase.hpp | 113 +++++ .../GraphicsEngineOpenGL/include/SwapChainGLImpl.h | 70 --- .../include/SwapChainGLImpl.hpp | 70 +++ .../GraphicsEngineOpenGL/include/TexRegionRender.h | 68 --- .../include/TexRegionRender.hpp | 68 +++ .../include/Texture1DArray_OGL.h | 68 --- .../include/Texture1DArray_OGL.hpp | 68 +++ .../GraphicsEngineOpenGL/include/Texture1D_OGL.h | 68 --- .../GraphicsEngineOpenGL/include/Texture1D_OGL.hpp | 68 +++ .../include/Texture2DArray_OGL.h | 68 --- .../include/Texture2DArray_OGL.hpp | 68 +++ .../GraphicsEngineOpenGL/include/Texture2D_OGL.h | 76 --- .../GraphicsEngineOpenGL/include/Texture2D_OGL.hpp | 76 +++ .../GraphicsEngineOpenGL/include/Texture3D_OGL.h | 68 --- .../GraphicsEngineOpenGL/include/Texture3D_OGL.hpp | 68 +++ .../GraphicsEngineOpenGL/include/TextureBaseGL.h | 138 ------ .../GraphicsEngineOpenGL/include/TextureBaseGL.hpp | 138 ++++++ .../include/TextureCubeArray_OGL.h | 68 --- .../include/TextureCubeArray_OGL.hpp | 68 +++ .../GraphicsEngineOpenGL/include/TextureCube_OGL.h | 68 --- .../include/TextureCube_OGL.hpp | 68 +++ .../include/TextureViewGLImpl.h | 68 --- .../include/TextureViewGLImpl.hpp | 68 +++ Graphics/GraphicsEngineOpenGL/include/VAOCache.h | 141 ------ Graphics/GraphicsEngineOpenGL/include/VAOCache.hpp | 141 ++++++ Graphics/GraphicsEngineOpenGL/include/pch.h | 2 +- Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp | 8 +- .../GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp | 8 +- .../src/DeviceContextGLImpl.cpp | 30 +- .../src/EngineFactoryOpenGL.cpp | 6 +- Graphics/GraphicsEngineOpenGL/src/FBOCache.cpp | 8 +- Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp | 2 +- .../GraphicsEngineOpenGL/src/GLContextState.cpp | 12 +- .../GraphicsEngineOpenGL/src/GLContextWindows.cpp | 2 +- .../GraphicsEngineOpenGL/src/GLObjectWrapper.cpp | 2 +- .../src/GLPipelineResourceLayout.cpp | 2 +- .../src/GLProgramResourceCache.cpp | 2 +- .../src/GLProgramResources.cpp | 6 +- .../src/PipelineStateGLImpl.cpp | 10 +- Graphics/GraphicsEngineOpenGL/src/QueryGLImpl.cpp | 2 +- .../src/RenderDeviceGLImpl.cpp | 36 +- .../GraphicsEngineOpenGL/src/SamplerGLImpl.cpp | 4 +- Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp | 6 +- .../src/ShaderResourceBindingGLImpl.cpp | 6 +- .../GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp | 6 +- .../GraphicsEngineOpenGL/src/TexRegionRender.cpp | 6 +- .../src/Texture1DArray_OGL.cpp | 8 +- .../GraphicsEngineOpenGL/src/Texture1D_OGL.cpp | 8 +- .../src/Texture2DArray_OGL.cpp | 8 +- .../GraphicsEngineOpenGL/src/Texture2D_OGL.cpp | 8 +- .../GraphicsEngineOpenGL/src/Texture3D_OGL.cpp | 8 +- .../GraphicsEngineOpenGL/src/TextureBaseGL.cpp | 10 +- .../src/TextureCubeArray_OGL.cpp | 8 +- .../GraphicsEngineOpenGL/src/TextureCube_OGL.cpp | 8 +- .../GraphicsEngineOpenGL/src/TextureViewGLImpl.cpp | 8 +- Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp | 12 +- 96 files changed, 4469 insertions(+), 4469 deletions(-) delete mode 100644 Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/FBOCache.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/FBOCache.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLContext.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLContext.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLContextState.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLContextState.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/GLProgramResources.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TexRegionRender.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/TexRegionRender.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.hpp delete mode 100644 Graphics/GraphicsEngineOpenGL/include/VAOCache.h create mode 100644 Graphics/GraphicsEngineOpenGL/include/VAOCache.hpp (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index dda4887b..c0d3bd36 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -3,38 +3,38 @@ cmake_minimum_required (VERSION 3.3) project(Diligent-GraphicsEngineOpenGL CXX) set(INCLUDE - include/AsyncWritableResource.h - include/BufferGLImpl.h - include/BufferViewGLImpl.h - include/DeviceContextGLImpl.h - include/FBOCache.h - include/FenceGLImpl.h - include/GLContext.h - include/GLContextState.h - include/GLObjectWrapper.h - include/GLProgramResourceCache.h - include/GLPipelineResourceLayout.h - include/GLProgramResources.h + include/AsyncWritableResource.hpp + include/BufferGLImpl.hpp + include/BufferViewGLImpl.hpp + include/DeviceContextGLImpl.hpp + include/FBOCache.hpp + include/FenceGLImpl.hpp + include/GLContext.hpp + include/GLContextState.hpp + include/GLObjectWrapper.hpp + include/GLProgramResourceCache.hpp + include/GLPipelineResourceLayout.hpp + include/GLProgramResources.hpp include/GLTypeConversions.h include/pch.h - include/PipelineStateGLImpl.h - include/QueryGLImpl.h - include/RenderDeviceGLImpl.h - include/SamplerGLImpl.h - include/ShaderGLImpl.h - include/ShaderResourceBindingGLImpl.h - include/SwapChainGLBase.h - include/TexRegionRender.h - include/Texture1D_OGL.h - include/Texture1DArray_OGL.h - include/Texture2D_OGL.h - include/Texture2DArray_OGL.h - include/Texture3D_OGL.h - include/TextureBaseGL.h - include/TextureCube_OGL.h - include/TextureCubeArray_OGL.h - include/TextureViewGLImpl.h - include/VAOCache.h + include/PipelineStateGLImpl.hpp + include/QueryGLImpl.hpp + include/RenderDeviceGLImpl.hpp + include/SamplerGLImpl.hpp + include/ShaderGLImpl.hpp + include/ShaderResourceBindingGLImpl.hpp + include/SwapChainGLBase.hpp + include/TexRegionRender.hpp + include/Texture1D_OGL.hpp + include/Texture1DArray_OGL.hpp + include/Texture2D_OGL.hpp + include/Texture2DArray_OGL.hpp + include/Texture3D_OGL.hpp + include/TextureBaseGL.hpp + include/TextureCube_OGL.hpp + include/TextureCubeArray_OGL.hpp + include/TextureViewGLImpl.hpp + include/VAOCache.hpp ) set(INTERFACE @@ -90,30 +90,30 @@ set(SOURCE if(PLATFORM_WIN32) list(APPEND SOURCE src/GLContextWindows.cpp) list(APPEND SOURCE src/SwapChainGLImpl.cpp) - list(APPEND INCLUDE include/GLContextWindows.h) - list(APPEND INCLUDE include/SwapChainGLImpl.h) + list(APPEND INCLUDE include/GLContextWindows.hpp) + list(APPEND INCLUDE include/SwapChainGLImpl.hpp) elseif(PLATFORM_ANDROID) list(APPEND SOURCE src/GLContextAndroid.cpp) list(APPEND SOURCE src/RenderDeviceGLESImpl.cpp) list(APPEND SOURCE src/GLStubsAndroid.cpp) list(APPEND SOURCE src/SwapChainGLImpl.cpp) - list(APPEND INCLUDE include/GLContextAndroid.h) + list(APPEND INCLUDE include/GLContextAndroid.hpp) list(APPEND INCLUDE include/GLStubsAndroid.h) list(APPEND INCLUDE include/RenderDeviceGLESImpl.h) - list(APPEND INCLUDE include/SwapChainGLImpl.h) + list(APPEND INCLUDE include/SwapChainGLImpl.hpp) list(APPEND INTERFACE interface/RenderDeviceGLES.h) elseif(PLATFORM_LINUX) list(APPEND SOURCE src/GLContextLinux.cpp) list(APPEND SOURCE src/SwapChainGLImpl.cpp) - list(APPEND INCLUDE include/GLContextLinux.h) - list(APPEND INCLUDE include/SwapChainGLImpl.h) + list(APPEND INCLUDE include/GLContextLinux.hpp) + list(APPEND INCLUDE include/SwapChainGLImpl.hpp) elseif(PLATFORM_MACOS) list(APPEND SOURCE src/GLContextMacOS.mm) list(APPEND INCLUDE include/GLContextMacOS.h) list(APPEND SOURCE src/SwapChainGLImpl.cpp) - list(APPEND INCLUDE include/SwapChainGLImpl.h) + list(APPEND INCLUDE include/SwapChainGLImpl.hpp) elseif(PLATFORM_IOS) list(APPEND SOURCE src/GLContextIOS.mm) list(APPEND INCLUDE include/GLContextIOS.h) diff --git a/Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.h b/Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.h deleted file mode 100644 index 9c286fb4..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.h +++ /dev/null @@ -1,69 +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 -{ - -class AsyncWritableResource -{ -public: - AsyncWritableResource() noexcept {} - - void SetPendingMemoryBarriers(Uint32 Barriers) { m_PendingMemoryBarriers |= Barriers; } - Uint32 GetPendingMemortBarriers() { return m_PendingMemoryBarriers; } - -private: - friend class GLContextState; - void ResetPendingMemoryBarriers(Uint32 Barriers) { m_PendingMemoryBarriers = Barriers; } - void ClearPendingMemoryBarriers(Uint32 Barriers) { m_PendingMemoryBarriers &= ~Barriers; } - - // Buffer barriers: - // GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT - // GL_ELEMENT_ARRAY_BARRIER_BIT - // GL_UNIFORM_BARRIER_BIT - // GL_BUFFER_UPDATE_BARRIER_BIT - // GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT - // GL_SHADER_STORAGE_BARRIER_BIT - - // Texture barriers: - // GL_TEXTURE_FETCH_BARRIER_BIT - // GL_SHADER_IMAGE_ACCESS_BARRIER_BIT - // GL_PIXEL_BUFFER_BARRIER_BIT - // GL_TEXTURE_UPDATE_BARRIER_BIT - - // Misc barriers: - // GL_FRAMEBUFFER_BARRIER_BIT - // GL_TRANSFORM_FEEDBACK_BARRIER_BIT - // GL_ATOMIC_COUNTER_BARRIER_BIT - // GL_QUERY_BUFFER_BARRIER_BIT - - Uint32 m_PendingMemoryBarriers = 0; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.hpp b/Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.hpp new file mode 100644 index 00000000..9c286fb4 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/AsyncWritableResource.hpp @@ -0,0 +1,69 @@ +/* + * 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 +{ + +class AsyncWritableResource +{ +public: + AsyncWritableResource() noexcept {} + + void SetPendingMemoryBarriers(Uint32 Barriers) { m_PendingMemoryBarriers |= Barriers; } + Uint32 GetPendingMemortBarriers() { return m_PendingMemoryBarriers; } + +private: + friend class GLContextState; + void ResetPendingMemoryBarriers(Uint32 Barriers) { m_PendingMemoryBarriers = Barriers; } + void ClearPendingMemoryBarriers(Uint32 Barriers) { m_PendingMemoryBarriers &= ~Barriers; } + + // Buffer barriers: + // GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT + // GL_ELEMENT_ARRAY_BARRIER_BIT + // GL_UNIFORM_BARRIER_BIT + // GL_BUFFER_UPDATE_BARRIER_BIT + // GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT + // GL_SHADER_STORAGE_BARRIER_BIT + + // Texture barriers: + // GL_TEXTURE_FETCH_BARRIER_BIT + // GL_SHADER_IMAGE_ACCESS_BARRIER_BIT + // GL_PIXEL_BUFFER_BARRIER_BIT + // GL_TEXTURE_UPDATE_BARRIER_BIT + + // Misc barriers: + // GL_FRAMEBUFFER_BARRIER_BIT + // GL_TRANSFORM_FEEDBACK_BARRIER_BIT + // GL_ATOMIC_COUNTER_BARRIER_BIT + // GL_QUERY_BUFFER_BARRIER_BIT + + Uint32 m_PendingMemoryBarriers = 0; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h deleted file mode 100644 index d20387a0..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h +++ /dev/null @@ -1,98 +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 "BufferGL.h" -#include "BufferBase.hpp" -#include "GLObjectWrapper.h" -#include "AsyncWritableResource.h" -#include "BaseInterfacesGL.h" -#include "BufferViewGLImpl.h" -#include "RenderDeviceGLImpl.h" -#include "GLContextState.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Buffer object implementation in OpenGL backend. -class BufferGLImpl final : public BufferBase, public AsyncWritableResource -{ -public: - using TBufferBase = BufferBase; - - BufferGLImpl(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& BuffViewObjMemAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& CtxState, - const BufferDesc& BuffDesc, - const BufferData* pBuffData, - bool bIsDeviceInternal); - - BufferGLImpl(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& BuffViewObjMemAllocator, - class RenderDeviceGLImpl* pDeviceGL, - GLContextState& CtxState, - const BufferDesc& BuffDesc, - GLuint GLHandle, - bool bIsDeviceInternal); - - ~BufferGLImpl(); - - /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; - - void UpdateData(GLContextState& CtxState, Uint32 Offset, Uint32 Size, const void* pData); - void CopyData(GLContextState& CtxState, BufferGLImpl& SrcBufferGL, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size); - void Map(GLContextState& CtxState, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData); - void MapRange(GLContextState& CtxState, MAP_TYPE MapType, Uint32 MapFlags, Uint32 Offset, Uint32 Length, PVoid& pMappedData); - void Unmap(GLContextState& CtxState); - - void BufferMemoryBarrier(Uint32 RequiredBarriers, class GLContextState& GLContextState); - - const GLObjectWrappers::GLBufferObj& GetGLHandle() { return m_GlBuffer; } - - /// Implementation of IBufferGL::GetGLBufferHandle(). - virtual GLuint GetGLBufferHandle() override final { return GetGLHandle(); } - - /// Implementation of IBuffer::GetNativeHandle() in OpenGL backend. - virtual void* GetNativeHandle() override final { return reinterpret_cast(static_cast(GetGLBufferHandle())); } - -private: - virtual void CreateViewInternal(const struct BufferViewDesc& ViewDesc, class IBufferView** ppView, bool bIsDefaultView) override; - - friend class DeviceContextGLImpl; - friend class VAOCache; - - GLObjectWrappers::GLBufferObj m_GlBuffer; - const Uint32 m_BindTarget; - const GLenum m_GLUsageHint; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp new file mode 100644 index 00000000..72142592 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp @@ -0,0 +1,98 @@ +/* + * 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 "BufferGL.h" +#include "BufferBase.hpp" +#include "GLObjectWrapper.hpp" +#include "AsyncWritableResource.hpp" +#include "BaseInterfacesGL.h" +#include "BufferViewGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "GLContextState.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Buffer object implementation in OpenGL backend. +class BufferGLImpl final : public BufferBase, public AsyncWritableResource +{ +public: + using TBufferBase = BufferBase; + + BufferGLImpl(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& BuffViewObjMemAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& CtxState, + const BufferDesc& BuffDesc, + const BufferData* pBuffData, + bool bIsDeviceInternal); + + BufferGLImpl(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& BuffViewObjMemAllocator, + class RenderDeviceGLImpl* pDeviceGL, + GLContextState& CtxState, + const BufferDesc& BuffDesc, + GLuint GLHandle, + bool bIsDeviceInternal); + + ~BufferGLImpl(); + + /// Queries the specific interface, see IObject::QueryInterface() for details + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; + + void UpdateData(GLContextState& CtxState, Uint32 Offset, Uint32 Size, const void* pData); + void CopyData(GLContextState& CtxState, BufferGLImpl& SrcBufferGL, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size); + void Map(GLContextState& CtxState, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData); + void MapRange(GLContextState& CtxState, MAP_TYPE MapType, Uint32 MapFlags, Uint32 Offset, Uint32 Length, PVoid& pMappedData); + void Unmap(GLContextState& CtxState); + + void BufferMemoryBarrier(Uint32 RequiredBarriers, class GLContextState& GLContextState); + + const GLObjectWrappers::GLBufferObj& GetGLHandle() { return m_GlBuffer; } + + /// Implementation of IBufferGL::GetGLBufferHandle(). + virtual GLuint GetGLBufferHandle() override final { return GetGLHandle(); } + + /// Implementation of IBuffer::GetNativeHandle() in OpenGL backend. + virtual void* GetNativeHandle() override final { return reinterpret_cast(static_cast(GetGLBufferHandle())); } + +private: + virtual void CreateViewInternal(const struct BufferViewDesc& ViewDesc, class IBufferView** ppView, bool bIsDefaultView) override; + + friend class DeviceContextGLImpl; + friend class VAOCache; + + GLObjectWrappers::GLBufferObj m_GlBuffer; + const Uint32 m_BindTarget; + const GLenum m_GLUsageHint; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.h deleted file mode 100644 index af999d75..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.h +++ /dev/null @@ -1,68 +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 "BufferViewGL.h" -#include "BaseInterfacesGL.h" -#include "BufferViewBase.hpp" -#include "RenderDevice.h" -#include "GLObjectWrapper.h" -#include "RenderDeviceGLImpl.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; -class IRenderDevice; -class IDeviceContext; -class BufferGLImpl; -struct BufferViewDesc; - -/// Buffer view implementation in OpenGL backend. -class BufferViewGLImpl final : public BufferViewBase -{ -public: - using TBuffViewBase = BufferViewBase; - - BufferViewGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDevice, - IDeviceContext* pContext, - const BufferViewDesc& ViewDesc, - BufferGLImpl* pBuffer, - bool bIsDefaultView); - - /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - const GLObjectWrappers::GLTextureObj& GetTexBufferHandle() { return m_GLTexBuffer; } - -private: - GLObjectWrappers::GLTextureObj m_GLTexBuffer; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.hpp new file mode 100644 index 00000000..5cefada0 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/BufferViewGLImpl.hpp @@ -0,0 +1,68 @@ +/* + * 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 "BufferViewGL.h" +#include "BaseInterfacesGL.h" +#include "BufferViewBase.hpp" +#include "RenderDevice.h" +#include "GLObjectWrapper.hpp" +#include "RenderDeviceGLImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; +class IRenderDevice; +class IDeviceContext; +class BufferGLImpl; +struct BufferViewDesc; + +/// Buffer view implementation in OpenGL backend. +class BufferViewGLImpl final : public BufferViewBase +{ +public: + using TBuffViewBase = BufferViewBase; + + BufferViewGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDevice, + IDeviceContext* pContext, + const BufferViewDesc& ViewDesc, + BufferGLImpl* pBuffer, + bool bIsDefaultView); + + /// Queries the specific interface, see IObject::QueryInterface() for details + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + const GLObjectWrappers::GLTextureObj& GetTexBufferHandle() { return m_GLTexBuffer; } + +private: + GLObjectWrappers::GLTextureObj m_GLTexBuffer; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h deleted file mode 100644 index 1c314e48..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h +++ /dev/null @@ -1,258 +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 "DeviceContextGL.h" -#include "DeviceContextBase.hpp" -#include "BaseInterfacesGL.h" -#include "GLContextState.h" -#include "GLObjectWrapper.h" -#include "BufferGLImpl.h" -#include "TextureBaseGL.h" -#include "QueryGLImpl.h" -#include "PipelineStateGLImpl.h" - -namespace Diligent -{ - -class RenderDeviceGLImpl; -class ISwapChainGL; - -struct DeviceContextGLImplTraits -{ - using BufferType = BufferGLImpl; - using TextureType = TextureBaseGL; - using PipelineStateType = PipelineStateGLImpl; - using DeviceType = RenderDeviceGLImpl; - using QueryType = QueryGLImpl; -}; - -/// Device context implementation in OpenGL backend. -class DeviceContextGLImpl final : public DeviceContextBase -{ -public: - using TDeviceContextBase = DeviceContextBase; - - DeviceContextGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDeviceGL, bool bIsDeferred); - - /// Queries the specific interface, see IObject::QueryInterface() for details. - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - /// Implementation of IDeviceContext::SetPipelineState() in OpenGL backend. - virtual void SetPipelineState(IPipelineState* pPipelineState) override final; - - /// Implementation of IDeviceContext::TransitionShaderResources() in OpenGL backend. - virtual void TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) override final; - - /// Implementation of IDeviceContext::CommitShaderResources() in OpenGL backend. - virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; - - /// Implementation of IDeviceContext::SetStencilRef() in OpenGL backend. - virtual void SetStencilRef(Uint32 StencilRef) override final; - - /// Implementation of IDeviceContext::SetBlendFactors() in OpenGL backend. - virtual void SetBlendFactors(const float* pBlendFactors = nullptr) override final; - - /// Implementation of IDeviceContext::SetVertexBuffers() in OpenGL backend. - virtual void SetVertexBuffers(Uint32 StartSlot, - Uint32 NumBuffersSet, - IBuffer** ppBuffers, - Uint32* pOffsets, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, - SET_VERTEX_BUFFERS_FLAGS Flags) override final; - - /// Implementation of IDeviceContext::InvalidateState() in OpenGL backend. - virtual void InvalidateState() override final; - - /// Implementation of IDeviceContext::SetIndexBuffer() in OpenGL backend. - virtual void SetIndexBuffer(IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; - - /// Implementation of IDeviceContext::SetViewports() in OpenGL backend. - virtual void SetViewports(Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight) override final; - - /// Implementation of IDeviceContext::SetScissorRects() in OpenGL backend. - virtual void SetScissorRects(Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight) override final; - - /// Implementation of IDeviceContext::SetRenderTargets() in OpenGL backend. - virtual void SetRenderTargets(Uint32 NumRenderTargets, - ITextureView* ppRenderTargets[], - ITextureView* pDepthStencil, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; - - // clang-format off - - /// Implementation of IDeviceContext::Draw() in OpenGL backend. - virtual void Draw (const DrawAttribs& Attribs) override final; - /// Implementation of IDeviceContext::DrawIndexed() in OpenGL backend. - virtual void DrawIndexed (const DrawIndexedAttribs& Attribs) override final; - /// Implementation of IDeviceContext::DrawIndirect() in OpenGL backend. - virtual void DrawIndirect (const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; - /// Implementation of IDeviceContext::DrawIndexedIndirect() in OpenGL backend. - virtual void DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; - - /// Implementation of IDeviceContext::DispatchCompute() in OpenGL backend. - virtual void DispatchCompute (const DispatchComputeAttribs& Attribs) override final; - /// Implementation of IDeviceContext::DispatchComputeIndirect() in OpenGL backend. - virtual void DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; - - // clang-format on - - /// Implementation of IDeviceContext::ClearDepthStencil() in OpenGL backend. - virtual void ClearDepthStencil(ITextureView* pView, - CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, - float fDepth, - Uint8 Stencil, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; - - /// Implementation of IDeviceContext::ClearRenderTarget() in OpenGL backend. - virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; - - /// Implementation of IDeviceContext::UpdateBuffer() in OpenGL backend. - virtual void UpdateBuffer(IBuffer* pBuffer, - Uint32 Offset, - Uint32 Size, - const void* pData, - RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; - - /// Implementation of IDeviceContext::CopyBuffer() in OpenGL backend. - virtual void CopyBuffer(IBuffer* pSrcBuffer, - Uint32 SrcOffset, - RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, - IBuffer* pDstBuffer, - Uint32 DstOffset, - Uint32 Size, - RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) override final; - - /// Implementation of IDeviceContext::MapBuffer() in OpenGL backend. - virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData) override final; - - /// Implementation of IDeviceContext::UnmapBuffer() in OpenGL backend. - virtual void UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) override final; - - /// Implementation of IDeviceContext::UpdateTexture() in OpenGL backend. - virtual void UpdateTexture(ITexture* pTexture, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData, - RESOURCE_STATE_TRANSITION_MODE SrcBufferStateTransitionMode, - RESOURCE_STATE_TRANSITION_MODE TextureStateTransitionMode) override final; - - /// Implementation of IDeviceContext::CopyTexture() in OpenGL backend. - virtual void CopyTexture(const CopyTextureAttribs& CopyAttribs) override final; - - /// Implementation of IDeviceContext::MapTextureSubresource() in OpenGL backend. - virtual void MapTextureSubresource(ITexture* pTexture, - Uint32 MipLevel, - Uint32 ArraySlice, - MAP_TYPE MapType, - MAP_FLAGS MapFlags, - const Box* pMapRegion, - MappedTextureSubresource& MappedData) override final; - - /// Implementation of IDeviceContext::UnmapTextureSubresource() in OpenGL backend. - virtual void UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice) override final; - - /// Implementation of IDeviceContext::GenerateMips() in OpenGL backend. - virtual void GenerateMips(ITextureView* pTexView) override; - - /// Implementation of IDeviceContext::FinishFrame() in OpenGL backend. - virtual void FinishFrame() override final; - - /// Implementation of IDeviceContext::TransitionResourceStates() in OpenGL backend. - virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) override final; - - /// Implementation of IDeviceContext::ResolveTextureSubresource() in OpenGL backend. - virtual void ResolveTextureSubresource(ITexture* pSrcTexture, - ITexture* pDstTexture, - const ResolveTextureSubresourceAttribs& ResolveAttribs) override final; - - /// Implementation of IDeviceContext::FinishCommandList() in OpenGL backend. - virtual void FinishCommandList(class ICommandList** ppCommandList) override final; - - /// Implementation of IDeviceContext::ExecuteCommandList() in OpenGL backend. - virtual void ExecuteCommandList(class ICommandList* pCommandList) override final; - - /// Implementation of IDeviceContext::SignalFence() in OpenGL backend. - virtual void SignalFence(IFence* pFence, Uint64 Value) override final; - - /// Implementation of IDeviceContext::WaitForFence() in OpenGL backend. - virtual void WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext) override final; - - /// Implementation of IDeviceContext::WaitForIdle() in OpenGL backend. - virtual void WaitForIdle() override final; - - /// Implementation of IDeviceContext::BeginQuery() in OpenGL backend. - virtual void BeginQuery(IQuery* pQuery) override final; - - /// Implementation of IDeviceContext::EndQuery() in OpenGL backend. - virtual void EndQuery(IQuery* pQuery) override final; - - /// Implementation of IDeviceContext::Flush() in OpenGL backend. - virtual void Flush() override final; - - /// Implementation of IDeviceContextGL::UpdateCurrentGLContext(). - virtual bool UpdateCurrentGLContext() override final; - - void BindProgramResources(Uint32& NewMemoryBarriers, IShaderResourceBinding* pResBinding); - - GLContextState& GetContextState() { return m_ContextState; } - - void CommitRenderTargets(); - - virtual void SetSwapChain(ISwapChainGL* pSwapChain) override final; - - virtual void ResetRenderTargets() override final; - - -protected: - friend class BufferGLImpl; - friend class TextureBaseGL; - friend class ShaderGLImpl; - - GLContextState m_ContextState; - -private: - __forceinline void PrepareForDraw(DRAW_FLAGS Flags, bool IsIndexed, GLenum& GlTopology); - __forceinline void PrepareForIndexedDraw(VALUE_TYPE IndexType, Uint32 FirstIndexLocation, GLenum& GLIndexType, Uint32& FirstIndexByteOffset); - __forceinline void PrepareForIndirectDraw(IBuffer* pAttribsBuffer); - __forceinline void PostDraw(); - - Uint32 m_CommitedResourcesTentativeBarriers = 0; - - std::vector m_BoundWritableTextures; - std::vector m_BoundWritableBuffers; - - RefCntAutoPtr m_pSwapChain; - - bool m_IsDefaultFBOBound = false; - - GLObjectWrappers::GLFrameBufferObj m_DefaultFBO; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp new file mode 100644 index 00000000..c6218595 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.hpp @@ -0,0 +1,258 @@ +/* + * 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 "DeviceContextGL.h" +#include "DeviceContextBase.hpp" +#include "BaseInterfacesGL.h" +#include "GLContextState.hpp" +#include "GLObjectWrapper.hpp" +#include "BufferGLImpl.hpp" +#include "TextureBaseGL.hpp" +#include "QueryGLImpl.hpp" +#include "PipelineStateGLImpl.hpp" + +namespace Diligent +{ + +class RenderDeviceGLImpl; +class ISwapChainGL; + +struct DeviceContextGLImplTraits +{ + using BufferType = BufferGLImpl; + using TextureType = TextureBaseGL; + using PipelineStateType = PipelineStateGLImpl; + using DeviceType = RenderDeviceGLImpl; + using QueryType = QueryGLImpl; +}; + +/// Device context implementation in OpenGL backend. +class DeviceContextGLImpl final : public DeviceContextBase +{ +public: + using TDeviceContextBase = DeviceContextBase; + + DeviceContextGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDeviceGL, bool bIsDeferred); + + /// Queries the specific interface, see IObject::QueryInterface() for details. + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + /// Implementation of IDeviceContext::SetPipelineState() in OpenGL backend. + virtual void SetPipelineState(IPipelineState* pPipelineState) override final; + + /// Implementation of IDeviceContext::TransitionShaderResources() in OpenGL backend. + virtual void TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) override final; + + /// Implementation of IDeviceContext::CommitShaderResources() in OpenGL backend. + virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + + /// Implementation of IDeviceContext::SetStencilRef() in OpenGL backend. + virtual void SetStencilRef(Uint32 StencilRef) override final; + + /// Implementation of IDeviceContext::SetBlendFactors() in OpenGL backend. + virtual void SetBlendFactors(const float* pBlendFactors = nullptr) override final; + + /// Implementation of IDeviceContext::SetVertexBuffers() in OpenGL backend. + virtual void SetVertexBuffers(Uint32 StartSlot, + Uint32 NumBuffersSet, + IBuffer** ppBuffers, + Uint32* pOffsets, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode, + SET_VERTEX_BUFFERS_FLAGS Flags) override final; + + /// Implementation of IDeviceContext::InvalidateState() in OpenGL backend. + virtual void InvalidateState() override final; + + /// Implementation of IDeviceContext::SetIndexBuffer() in OpenGL backend. + virtual void SetIndexBuffer(IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + + /// Implementation of IDeviceContext::SetViewports() in OpenGL backend. + virtual void SetViewports(Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight) override final; + + /// Implementation of IDeviceContext::SetScissorRects() in OpenGL backend. + virtual void SetScissorRects(Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight) override final; + + /// Implementation of IDeviceContext::SetRenderTargets() in OpenGL backend. + virtual void SetRenderTargets(Uint32 NumRenderTargets, + ITextureView* ppRenderTargets[], + ITextureView* pDepthStencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + + // clang-format off + + /// Implementation of IDeviceContext::Draw() in OpenGL backend. + virtual void Draw (const DrawAttribs& Attribs) override final; + /// Implementation of IDeviceContext::DrawIndexed() in OpenGL backend. + virtual void DrawIndexed (const DrawIndexedAttribs& Attribs) override final; + /// Implementation of IDeviceContext::DrawIndirect() in OpenGL backend. + virtual void DrawIndirect (const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; + /// Implementation of IDeviceContext::DrawIndexedIndirect() in OpenGL backend. + virtual void DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; + + /// Implementation of IDeviceContext::DispatchCompute() in OpenGL backend. + virtual void DispatchCompute (const DispatchComputeAttribs& Attribs) override final; + /// Implementation of IDeviceContext::DispatchComputeIndirect() in OpenGL backend. + virtual void DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; + + // clang-format on + + /// Implementation of IDeviceContext::ClearDepthStencil() in OpenGL backend. + virtual void ClearDepthStencil(ITextureView* pView, + CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, + float fDepth, + Uint8 Stencil, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + + /// Implementation of IDeviceContext::ClearRenderTarget() in OpenGL backend. + virtual void ClearRenderTarget(ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + + /// Implementation of IDeviceContext::UpdateBuffer() in OpenGL backend. + virtual void UpdateBuffer(IBuffer* pBuffer, + Uint32 Offset, + Uint32 Size, + const void* pData, + RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) override final; + + /// Implementation of IDeviceContext::CopyBuffer() in OpenGL backend. + virtual void CopyBuffer(IBuffer* pSrcBuffer, + Uint32 SrcOffset, + RESOURCE_STATE_TRANSITION_MODE SrcBufferTransitionMode, + IBuffer* pDstBuffer, + Uint32 DstOffset, + Uint32 Size, + RESOURCE_STATE_TRANSITION_MODE DstBufferTransitionMode) override final; + + /// Implementation of IDeviceContext::MapBuffer() in OpenGL backend. + virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData) override final; + + /// Implementation of IDeviceContext::UnmapBuffer() in OpenGL backend. + virtual void UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) override final; + + /// Implementation of IDeviceContext::UpdateTexture() in OpenGL backend. + virtual void UpdateTexture(ITexture* pTexture, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData, + RESOURCE_STATE_TRANSITION_MODE SrcBufferStateTransitionMode, + RESOURCE_STATE_TRANSITION_MODE TextureStateTransitionMode) override final; + + /// Implementation of IDeviceContext::CopyTexture() in OpenGL backend. + virtual void CopyTexture(const CopyTextureAttribs& CopyAttribs) override final; + + /// Implementation of IDeviceContext::MapTextureSubresource() in OpenGL backend. + virtual void MapTextureSubresource(ITexture* pTexture, + Uint32 MipLevel, + Uint32 ArraySlice, + MAP_TYPE MapType, + MAP_FLAGS MapFlags, + const Box* pMapRegion, + MappedTextureSubresource& MappedData) override final; + + /// Implementation of IDeviceContext::UnmapTextureSubresource() in OpenGL backend. + virtual void UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice) override final; + + /// Implementation of IDeviceContext::GenerateMips() in OpenGL backend. + virtual void GenerateMips(ITextureView* pTexView) override; + + /// Implementation of IDeviceContext::FinishFrame() in OpenGL backend. + virtual void FinishFrame() override final; + + /// Implementation of IDeviceContext::TransitionResourceStates() in OpenGL backend. + virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) override final; + + /// Implementation of IDeviceContext::ResolveTextureSubresource() in OpenGL backend. + virtual void ResolveTextureSubresource(ITexture* pSrcTexture, + ITexture* pDstTexture, + const ResolveTextureSubresourceAttribs& ResolveAttribs) override final; + + /// Implementation of IDeviceContext::FinishCommandList() in OpenGL backend. + virtual void FinishCommandList(class ICommandList** ppCommandList) override final; + + /// Implementation of IDeviceContext::ExecuteCommandList() in OpenGL backend. + virtual void ExecuteCommandList(class ICommandList* pCommandList) override final; + + /// Implementation of IDeviceContext::SignalFence() in OpenGL backend. + virtual void SignalFence(IFence* pFence, Uint64 Value) override final; + + /// Implementation of IDeviceContext::WaitForFence() in OpenGL backend. + virtual void WaitForFence(IFence* pFence, Uint64 Value, bool FlushContext) override final; + + /// Implementation of IDeviceContext::WaitForIdle() in OpenGL backend. + virtual void WaitForIdle() override final; + + /// Implementation of IDeviceContext::BeginQuery() in OpenGL backend. + virtual void BeginQuery(IQuery* pQuery) override final; + + /// Implementation of IDeviceContext::EndQuery() in OpenGL backend. + virtual void EndQuery(IQuery* pQuery) override final; + + /// Implementation of IDeviceContext::Flush() in OpenGL backend. + virtual void Flush() override final; + + /// Implementation of IDeviceContextGL::UpdateCurrentGLContext(). + virtual bool UpdateCurrentGLContext() override final; + + void BindProgramResources(Uint32& NewMemoryBarriers, IShaderResourceBinding* pResBinding); + + GLContextState& GetContextState() { return m_ContextState; } + + void CommitRenderTargets(); + + virtual void SetSwapChain(ISwapChainGL* pSwapChain) override final; + + virtual void ResetRenderTargets() override final; + + +protected: + friend class BufferGLImpl; + friend class TextureBaseGL; + friend class ShaderGLImpl; + + GLContextState m_ContextState; + +private: + __forceinline void PrepareForDraw(DRAW_FLAGS Flags, bool IsIndexed, GLenum& GlTopology); + __forceinline void PrepareForIndexedDraw(VALUE_TYPE IndexType, Uint32 FirstIndexLocation, GLenum& GLIndexType, Uint32& FirstIndexByteOffset); + __forceinline void PrepareForIndirectDraw(IBuffer* pAttribsBuffer); + __forceinline void PostDraw(); + + Uint32 m_CommitedResourcesTentativeBarriers = 0; + + std::vector m_BoundWritableTextures; + std::vector m_BoundWritableBuffers; + + RefCntAutoPtr m_pSwapChain; + + bool m_IsDefaultFBOBound = false; + + GLObjectWrappers::GLFrameBufferObj m_DefaultFBO; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/FBOCache.h b/Graphics/GraphicsEngineOpenGL/include/FBOCache.h deleted file mode 100644 index 250d4f71..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/FBOCache.h +++ /dev/null @@ -1,97 +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 "GraphicsTypes.h" -#include "TextureView.h" -#include "LockHelper.h" -#include "HashUtils.h" -#include "GLObjectWrapper.h" - -namespace Diligent -{ - -class TextureViewGLImpl; - -class FBOCache -{ -public: - FBOCache(); - ~FBOCache(); - - // clang-format off - FBOCache (const FBOCache&) = delete; - FBOCache ( FBOCache&&) = delete; - FBOCache& operator = (const FBOCache&) = delete; - FBOCache& operator = ( FBOCache&&) = delete; - // clang-format on - - const GLObjectWrappers::GLFrameBufferObj& GetFBO(Uint32 NumRenderTargets, - TextureViewGLImpl* ppRTVs[], - TextureViewGLImpl* pDSV, - class GLContextState& ContextState); - - void OnReleaseTexture(ITexture* pTexture); - -private: - // This structure is used as the key to find FBO - struct FBOCacheKey - { - // Using pointers is not reliable! - - Uint32 NumRenderTargets = 0; - - // Unique IDs of textures bound as render targets - UniqueIdentifier RTIds[MAX_RENDER_TARGETS] = {}; - TextureViewDesc RTVDescs[MAX_RENDER_TARGETS]; - - // Unique IDs of texture bound as depth stencil - UniqueIdentifier DSId = 0; - TextureViewDesc DSVDesc = {}; - - mutable size_t Hash = 0; - - bool operator==(const FBOCacheKey& Key) const; - }; - - struct FBOCacheKeyHashFunc - { - std::size_t operator()(const FBOCacheKey& Key) const; - }; - - - friend class RenderDeviceGLImpl; - ThreadingTools::LockFlag m_CacheLockFlag; - std::unordered_map m_Cache; - - // Multimap that sets up correspondence between unique texture id and all - // FBOs it is used in - std::unordered_multimap m_TexIdToKey; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/FBOCache.hpp b/Graphics/GraphicsEngineOpenGL/include/FBOCache.hpp new file mode 100644 index 00000000..761f9e27 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/FBOCache.hpp @@ -0,0 +1,97 @@ +/* + * 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 "GraphicsTypes.h" +#include "TextureView.h" +#include "LockHelper.h" +#include "HashUtils.h" +#include "GLObjectWrapper.hpp" + +namespace Diligent +{ + +class TextureViewGLImpl; + +class FBOCache +{ +public: + FBOCache(); + ~FBOCache(); + + // clang-format off + FBOCache (const FBOCache&) = delete; + FBOCache ( FBOCache&&) = delete; + FBOCache& operator = (const FBOCache&) = delete; + FBOCache& operator = ( FBOCache&&) = delete; + // clang-format on + + const GLObjectWrappers::GLFrameBufferObj& GetFBO(Uint32 NumRenderTargets, + TextureViewGLImpl* ppRTVs[], + TextureViewGLImpl* pDSV, + class GLContextState& ContextState); + + void OnReleaseTexture(ITexture* pTexture); + +private: + // This structure is used as the key to find FBO + struct FBOCacheKey + { + // Using pointers is not reliable! + + Uint32 NumRenderTargets = 0; + + // Unique IDs of textures bound as render targets + UniqueIdentifier RTIds[MAX_RENDER_TARGETS] = {}; + TextureViewDesc RTVDescs[MAX_RENDER_TARGETS]; + + // Unique IDs of texture bound as depth stencil + UniqueIdentifier DSId = 0; + TextureViewDesc DSVDesc = {}; + + mutable size_t Hash = 0; + + bool operator==(const FBOCacheKey& Key) const; + }; + + struct FBOCacheKeyHashFunc + { + std::size_t operator()(const FBOCacheKey& Key) const; + }; + + + friend class RenderDeviceGLImpl; + ThreadingTools::LockFlag m_CacheLockFlag; + std::unordered_map m_Cache; + + // Multimap that sets up correspondence between unique texture id and all + // FBOs it is used in + std::unordered_multimap m_TexIdToKey; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h deleted file mode 100644 index f7fc4338..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h +++ /dev/null @@ -1,76 +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 -/// Declaration of Diligent::FenceGLImpl class - -#include -#include "FenceGL.h" -#include "RenderDeviceGL.h" -#include "FenceBase.hpp" -#include "GLObjectWrapper.h" -#include "RenderDeviceGLImpl.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Fence object implementation in OpenGL backend. -class FenceGLImpl final : public FenceBase -{ -public: - using TFenceBase = FenceBase; - - FenceGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDevice, - const FenceDesc& Desc); - ~FenceGLImpl(); - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_FenceGL, TFenceBase); - - /// Implementation of IFence::GetCompletedValue() in OpenGL backend. - virtual Uint64 GetCompletedValue() override final; - - /// Implementation of IFence::Reset() in OpenGL backend. - virtual void Reset(Uint64 Value) override final; - - void AddPendingFence(GLObjectWrappers::GLSyncObj&& Fence, Uint64 Value) - { - m_PendingFences.emplace_back(Value, std::move(Fence)); - } - - void Wait(Uint64 Value, bool FlushCommands); - -private: - std::deque> m_PendingFences; - volatile Uint64 m_LastCompletedFenceValue = 0; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp new file mode 100644 index 00000000..6de13da9 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.hpp @@ -0,0 +1,76 @@ +/* + * 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 +/// Declaration of Diligent::FenceGLImpl class + +#include +#include "FenceGL.h" +#include "RenderDeviceGL.h" +#include "FenceBase.hpp" +#include "GLObjectWrapper.hpp" +#include "RenderDeviceGLImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Fence object implementation in OpenGL backend. +class FenceGLImpl final : public FenceBase +{ +public: + using TFenceBase = FenceBase; + + FenceGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDevice, + const FenceDesc& Desc); + ~FenceGLImpl(); + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_FenceGL, TFenceBase); + + /// Implementation of IFence::GetCompletedValue() in OpenGL backend. + virtual Uint64 GetCompletedValue() override final; + + /// Implementation of IFence::Reset() in OpenGL backend. + virtual void Reset(Uint64 Value) override final; + + void AddPendingFence(GLObjectWrappers::GLSyncObj&& Fence, Uint64 Value) + { + m_PendingFences.emplace_back(Value, std::move(Fence)); + } + + void Wait(Uint64 Value, bool FlushCommands); + +private: + std::deque> m_PendingFences; + volatile Uint64 m_LastCompletedFenceValue = 0; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContext.h b/Graphics/GraphicsEngineOpenGL/include/GLContext.h deleted file mode 100644 index b94ef8ff..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLContext.h +++ /dev/null @@ -1,42 +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 - -#if PLATFORM_WIN32 -# include "GLContextWindows.h" -#elif PLATFORM_ANDROID -# include "GLContextAndroid.h" -#elif PLATFORM_LINUX -# include "GLContextLinux.h" -#elif PLATFORM_MACOS -# include "GLContextMacOS.h" -#elif PLATFORM_IOS -# include "GLContextIOS.h" -#else -# error Unsupported platform -#endif diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContext.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContext.hpp new file mode 100644 index 00000000..6c1abe8a --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLContext.hpp @@ -0,0 +1,42 @@ +/* + * 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 + +#if PLATFORM_WIN32 +# include "GLContextWindows.hpp" +#elif PLATFORM_ANDROID +# include "GLContextAndroid.hpp" +#elif PLATFORM_LINUX +# include "GLContextLinux.hpp" +#elif PLATFORM_MACOS +# include "GLContextMacOS.h" +#elif PLATFORM_IOS +# include "GLContextIOS.h" +#else +# error Unsupported platform +#endif diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextState.h b/Graphics/GraphicsEngineOpenGL/include/GLContextState.h deleted file mode 100644 index 66879e65..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextState.h +++ /dev/null @@ -1,276 +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 "GraphicsTypes.h" -#include "GLObjectWrapper.h" -#include "UniqueIdentifier.h" -#include "GLContext.h" - -namespace Diligent -{ - -class GLContextState -{ -public: - GLContextState(class RenderDeviceGLImpl* pDeviceGL); - - // clang-format off - - void SetProgram (const GLObjectWrappers::GLProgramObj& GLProgram); - void SetPipeline (const GLObjectWrappers::GLPipelineObj& GLPipeline); - void BindVAO (const GLObjectWrappers::GLVertexArrayObj& VAO); - void BindFBO (const GLObjectWrappers::GLFrameBufferObj& FBO); - void SetActiveTexture (Int32 Index); - void BindTexture (Int32 Index, GLenum BindTarget, const GLObjectWrappers::GLTextureObj& Tex); - void BindUniformBuffer (Int32 Index, const GLObjectWrappers::GLBufferObj& Buff); - void BindBuffer (GLenum BindTarget, const GLObjectWrappers::GLBufferObj& Buff, bool ResetVAO); - void BindSampler (Uint32 Index, const GLObjectWrappers::GLSamplerObj& GLSampler); - void BindImage (Uint32 Index, class TextureViewGLImpl* pTexView, GLint MipLevel, GLboolean IsLayered, GLint Layer, GLenum Access, GLenum Format); - void BindImage (Uint32 Index, class BufferViewGLImpl* pBuffView, GLenum Access, GLenum Format); - void BindStorageBlock (Int32 Index, const GLObjectWrappers::GLBufferObj& Buff, GLintptr Offset, GLsizeiptr Size); - - void EnsureMemoryBarrier(Uint32 RequiredBarriers, class AsyncWritableResource *pRes = nullptr); - void SetPendingMemoryBarriers(Uint32 PendingBarriers); - - void EnableDepthTest (bool bEnable); - void EnableDepthWrites (bool bEnable); - void SetDepthFunc (COMPARISON_FUNCTION CmpFunc); - void EnableStencilTest (bool bEnable); - void SetStencilWriteMask (Uint8 StencilWriteMask); - void SetStencilRef (GLenum Face, Int32 Ref); - void SetStencilFunc (GLenum Face, COMPARISON_FUNCTION Func, Int32 Ref, Uint32 Mask); - void SetStencilOp (GLenum Face, STENCIL_OP StencilFailOp, STENCIL_OP StencilDepthFailOp, STENCIL_OP StencilPassOp); - void SetFillMode (FILL_MODE FillMode); - void SetCullMode (CULL_MODE CullMode); - void SetFrontFace (bool FrontCounterClockwise); - void SetDepthBias (float DepthBias, float fSlopeScaledDepthBias); - void SetDepthClamp (bool bEnableDepthClamp); - void EnableScissorTest (bool bEnableScissorTest); - - void SetBlendFactors(const float* BlendFactors); - void SetBlendState(const BlendStateDesc& BSDsc, Uint32 SampleMask); - - Bool GetDepthWritesEnabled(){ return m_DSState.m_DepthWritesEnableState; } - Bool GetScissorTestEnabled(){ return m_RSState.ScissorTestEnable; } - void GetColorWriteMask(Uint32 RTIndex, Uint32& WriteMask, Bool& bIsIndependent); - void SetColorWriteMask(Uint32 RTIndex, Uint32 WriteMask, Bool bIsIndependent); - - // clang-format on - - void SetNumPatchVertices(Int32 NumVertices); - void Invalidate(); - - void InvalidateVAO() - { - m_VAOId = -1; - // Resetting VAO after that with BindVAO(GLVertexArrayObj::Null()) will still have the effect because - // null VAO's ID is 0, not -1. - } - - void InvalidateFBO() - { - m_FBOId = -1; - } - bool IsValidVAOBound() const { return m_VAOId > 0; } - - void SetCurrentGLContext(GLContext::NativeGLContextType Context) { m_CurrentGLContext = Context; } - - GLContext::NativeGLContextType GetCurrentGLContext() const { return m_CurrentGLContext; } - - struct ContextCaps - { - bool bFillModeSelectionSupported = true; - GLint m_iMaxCombinedTexUnits = 0; - GLint m_iMaxDrawBuffers = 0; - GLint m_iMaxUniformBufferBindings = 0; - }; - const ContextCaps& GetContextCaps() { return m_Caps; } - -private: - // It is unsafe to use GL handle to keep track of bound objects - // When an object is released, GL is free to reuse its handle for - // the new created objects. - // Even using pointers is not safe as when an object is created, - // the system can reuse the same address - // The safest way is to keep global unique ID for all objects - - UniqueIdentifier m_GLProgId = -1; - UniqueIdentifier m_GLPipelineId = -1; - UniqueIdentifier m_VAOId = -1; - UniqueIdentifier m_FBOId = -1; - std::vector m_BoundTextures; - std::vector m_BoundSamplers; - std::vector m_BoundUniformBuffers; - - struct BoundImageInfo - { - UniqueIdentifier InterfaceID = -1; - GLint MipLevel = 0; - GLboolean IsLayered = 0; - GLint Layer = 0; - GLenum Access = 0; - GLenum Format = 0; - - BoundImageInfo(){}; - - BoundImageInfo(UniqueIdentifier _UniqueID, - GLint _MipLevel, - GLboolean _IsLayered, - GLint _Layer, - GLenum _Access, - GLenum _Format) : - // clang-format off - InterfaceID{_UniqueID}, - MipLevel {_MipLevel}, - IsLayered {_IsLayered}, - Layer {_Layer}, - Access {_Access}, - Format {_Format} - // clang-format on - {} - - bool operator==(const BoundImageInfo& rhs) const - { - // clang-format off - return InterfaceID == rhs.InterfaceID && - MipLevel == rhs.MipLevel && - IsLayered == rhs.IsLayered && - Layer == rhs.Layer && - Access == rhs.Access && - Format == rhs.Format; - // clang-format on - } - }; - std::vector m_BoundImages; - - struct BoundSSBOInfo - { - BoundSSBOInfo() {} - BoundSSBOInfo(UniqueIdentifier _BufferID, - GLintptr _Offset, - GLsizeiptr _Size) : - // clang-format off - BufferID{_BufferID}, - Offset {_Offset}, - Size {_Size} - // clang-format on - {} - UniqueIdentifier BufferID = -1; - GLintptr Offset = 0; - GLsizeiptr Size = 0; - - bool operator==(const BoundSSBOInfo& rhs) const - { - // clang-format off - return BufferID == rhs.BufferID && - Offset == rhs.Offset && - Size == rhs.Size; - // clang-format on - } - }; - std::vector m_BoundStorageBlocks; - - Uint32 m_PendingMemoryBarriers = 0; - - class EnableStateHelper - { - public: - enum class ENABLE_STATE : Int32 - { - UNKNOWN, - ENABLED, - DISABLED - }; - - bool operator==(bool bEnabled) const - { - return (bEnabled && m_EnableState == ENABLE_STATE::ENABLED) || - (!bEnabled && m_EnableState == ENABLE_STATE::DISABLED); - } - bool operator!=(bool bEnabled) const - { - return !(*this == bEnabled); - } - - const EnableStateHelper& operator=(bool bEnabled) - { - m_EnableState = bEnabled ? ENABLE_STATE::ENABLED : ENABLE_STATE::DISABLED; - return *this; - } - - operator bool() const - { - return m_EnableState == ENABLE_STATE::ENABLED; - } - - private: - ENABLE_STATE m_EnableState = ENABLE_STATE::UNKNOWN; - }; - - struct DepthStencilGLState - { - EnableStateHelper m_DepthEnableState; - EnableStateHelper m_DepthWritesEnableState; - COMPARISON_FUNCTION m_DepthCmpFunc = COMPARISON_FUNC_UNKNOWN; - EnableStateHelper m_StencilTestEnableState; - Uint16 m_StencilReadMask = 0xFFFF; - Uint16 m_StencilWriteMask = 0xFFFF; - struct StencilOpState - { - COMPARISON_FUNCTION Func = COMPARISON_FUNC_UNKNOWN; - STENCIL_OP StencilFailOp = STENCIL_OP_UNDEFINED; - STENCIL_OP StencilDepthFailOp = STENCIL_OP_UNDEFINED; - STENCIL_OP StencilPassOp = STENCIL_OP_UNDEFINED; - Int32 Ref = std::numeric_limits::min(); - Uint32 Mask = static_cast(-1); - } m_StencilOpState[2]; - } m_DSState; - - struct RasterizerGLState - { - FILL_MODE FillMode = FILL_MODE_UNDEFINED; - CULL_MODE CullMode = CULL_MODE_UNDEFINED; - EnableStateHelper FrontCounterClockwise; - float fDepthBias = std::numeric_limits::max(); - float fSlopeScaledDepthBias = std::numeric_limits::max(); - EnableStateHelper DepthClampEnable; - EnableStateHelper ScissorTestEnable; - } m_RSState; - - ContextCaps m_Caps; - - Uint32 m_ColorWriteMasks[MAX_RENDER_TARGETS] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - EnableStateHelper m_bIndependentWriteMasks; - Int32 m_iActiveTexture = -1; - Int32 m_NumPatchVertices = -1; - - GLContext::NativeGLContextType m_CurrentGLContext = {}; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextState.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextState.hpp new file mode 100644 index 00000000..0e36bfb6 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextState.hpp @@ -0,0 +1,276 @@ +/* + * 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 "GraphicsTypes.h" +#include "GLObjectWrapper.hpp" +#include "UniqueIdentifier.h" +#include "GLContext.hpp" + +namespace Diligent +{ + +class GLContextState +{ +public: + GLContextState(class RenderDeviceGLImpl* pDeviceGL); + + // clang-format off + + void SetProgram (const GLObjectWrappers::GLProgramObj& GLProgram); + void SetPipeline (const GLObjectWrappers::GLPipelineObj& GLPipeline); + void BindVAO (const GLObjectWrappers::GLVertexArrayObj& VAO); + void BindFBO (const GLObjectWrappers::GLFrameBufferObj& FBO); + void SetActiveTexture (Int32 Index); + void BindTexture (Int32 Index, GLenum BindTarget, const GLObjectWrappers::GLTextureObj& Tex); + void BindUniformBuffer (Int32 Index, const GLObjectWrappers::GLBufferObj& Buff); + void BindBuffer (GLenum BindTarget, const GLObjectWrappers::GLBufferObj& Buff, bool ResetVAO); + void BindSampler (Uint32 Index, const GLObjectWrappers::GLSamplerObj& GLSampler); + void BindImage (Uint32 Index, class TextureViewGLImpl* pTexView, GLint MipLevel, GLboolean IsLayered, GLint Layer, GLenum Access, GLenum Format); + void BindImage (Uint32 Index, class BufferViewGLImpl* pBuffView, GLenum Access, GLenum Format); + void BindStorageBlock (Int32 Index, const GLObjectWrappers::GLBufferObj& Buff, GLintptr Offset, GLsizeiptr Size); + + void EnsureMemoryBarrier(Uint32 RequiredBarriers, class AsyncWritableResource *pRes = nullptr); + void SetPendingMemoryBarriers(Uint32 PendingBarriers); + + void EnableDepthTest (bool bEnable); + void EnableDepthWrites (bool bEnable); + void SetDepthFunc (COMPARISON_FUNCTION CmpFunc); + void EnableStencilTest (bool bEnable); + void SetStencilWriteMask (Uint8 StencilWriteMask); + void SetStencilRef (GLenum Face, Int32 Ref); + void SetStencilFunc (GLenum Face, COMPARISON_FUNCTION Func, Int32 Ref, Uint32 Mask); + void SetStencilOp (GLenum Face, STENCIL_OP StencilFailOp, STENCIL_OP StencilDepthFailOp, STENCIL_OP StencilPassOp); + void SetFillMode (FILL_MODE FillMode); + void SetCullMode (CULL_MODE CullMode); + void SetFrontFace (bool FrontCounterClockwise); + void SetDepthBias (float DepthBias, float fSlopeScaledDepthBias); + void SetDepthClamp (bool bEnableDepthClamp); + void EnableScissorTest (bool bEnableScissorTest); + + void SetBlendFactors(const float* BlendFactors); + void SetBlendState(const BlendStateDesc& BSDsc, Uint32 SampleMask); + + Bool GetDepthWritesEnabled(){ return m_DSState.m_DepthWritesEnableState; } + Bool GetScissorTestEnabled(){ return m_RSState.ScissorTestEnable; } + void GetColorWriteMask(Uint32 RTIndex, Uint32& WriteMask, Bool& bIsIndependent); + void SetColorWriteMask(Uint32 RTIndex, Uint32 WriteMask, Bool bIsIndependent); + + // clang-format on + + void SetNumPatchVertices(Int32 NumVertices); + void Invalidate(); + + void InvalidateVAO() + { + m_VAOId = -1; + // Resetting VAO after that with BindVAO(GLVertexArrayObj::Null()) will still have the effect because + // null VAO's ID is 0, not -1. + } + + void InvalidateFBO() + { + m_FBOId = -1; + } + bool IsValidVAOBound() const { return m_VAOId > 0; } + + void SetCurrentGLContext(GLContext::NativeGLContextType Context) { m_CurrentGLContext = Context; } + + GLContext::NativeGLContextType GetCurrentGLContext() const { return m_CurrentGLContext; } + + struct ContextCaps + { + bool bFillModeSelectionSupported = true; + GLint m_iMaxCombinedTexUnits = 0; + GLint m_iMaxDrawBuffers = 0; + GLint m_iMaxUniformBufferBindings = 0; + }; + const ContextCaps& GetContextCaps() { return m_Caps; } + +private: + // It is unsafe to use GL handle to keep track of bound objects + // When an object is released, GL is free to reuse its handle for + // the new created objects. + // Even using pointers is not safe as when an object is created, + // the system can reuse the same address + // The safest way is to keep global unique ID for all objects + + UniqueIdentifier m_GLProgId = -1; + UniqueIdentifier m_GLPipelineId = -1; + UniqueIdentifier m_VAOId = -1; + UniqueIdentifier m_FBOId = -1; + std::vector m_BoundTextures; + std::vector m_BoundSamplers; + std::vector m_BoundUniformBuffers; + + struct BoundImageInfo + { + UniqueIdentifier InterfaceID = -1; + GLint MipLevel = 0; + GLboolean IsLayered = 0; + GLint Layer = 0; + GLenum Access = 0; + GLenum Format = 0; + + BoundImageInfo(){}; + + BoundImageInfo(UniqueIdentifier _UniqueID, + GLint _MipLevel, + GLboolean _IsLayered, + GLint _Layer, + GLenum _Access, + GLenum _Format) : + // clang-format off + InterfaceID{_UniqueID}, + MipLevel {_MipLevel}, + IsLayered {_IsLayered}, + Layer {_Layer}, + Access {_Access}, + Format {_Format} + // clang-format on + {} + + bool operator==(const BoundImageInfo& rhs) const + { + // clang-format off + return InterfaceID == rhs.InterfaceID && + MipLevel == rhs.MipLevel && + IsLayered == rhs.IsLayered && + Layer == rhs.Layer && + Access == rhs.Access && + Format == rhs.Format; + // clang-format on + } + }; + std::vector m_BoundImages; + + struct BoundSSBOInfo + { + BoundSSBOInfo() {} + BoundSSBOInfo(UniqueIdentifier _BufferID, + GLintptr _Offset, + GLsizeiptr _Size) : + // clang-format off + BufferID{_BufferID}, + Offset {_Offset}, + Size {_Size} + // clang-format on + {} + UniqueIdentifier BufferID = -1; + GLintptr Offset = 0; + GLsizeiptr Size = 0; + + bool operator==(const BoundSSBOInfo& rhs) const + { + // clang-format off + return BufferID == rhs.BufferID && + Offset == rhs.Offset && + Size == rhs.Size; + // clang-format on + } + }; + std::vector m_BoundStorageBlocks; + + Uint32 m_PendingMemoryBarriers = 0; + + class EnableStateHelper + { + public: + enum class ENABLE_STATE : Int32 + { + UNKNOWN, + ENABLED, + DISABLED + }; + + bool operator==(bool bEnabled) const + { + return (bEnabled && m_EnableState == ENABLE_STATE::ENABLED) || + (!bEnabled && m_EnableState == ENABLE_STATE::DISABLED); + } + bool operator!=(bool bEnabled) const + { + return !(*this == bEnabled); + } + + const EnableStateHelper& operator=(bool bEnabled) + { + m_EnableState = bEnabled ? ENABLE_STATE::ENABLED : ENABLE_STATE::DISABLED; + return *this; + } + + operator bool() const + { + return m_EnableState == ENABLE_STATE::ENABLED; + } + + private: + ENABLE_STATE m_EnableState = ENABLE_STATE::UNKNOWN; + }; + + struct DepthStencilGLState + { + EnableStateHelper m_DepthEnableState; + EnableStateHelper m_DepthWritesEnableState; + COMPARISON_FUNCTION m_DepthCmpFunc = COMPARISON_FUNC_UNKNOWN; + EnableStateHelper m_StencilTestEnableState; + Uint16 m_StencilReadMask = 0xFFFF; + Uint16 m_StencilWriteMask = 0xFFFF; + struct StencilOpState + { + COMPARISON_FUNCTION Func = COMPARISON_FUNC_UNKNOWN; + STENCIL_OP StencilFailOp = STENCIL_OP_UNDEFINED; + STENCIL_OP StencilDepthFailOp = STENCIL_OP_UNDEFINED; + STENCIL_OP StencilPassOp = STENCIL_OP_UNDEFINED; + Int32 Ref = std::numeric_limits::min(); + Uint32 Mask = static_cast(-1); + } m_StencilOpState[2]; + } m_DSState; + + struct RasterizerGLState + { + FILL_MODE FillMode = FILL_MODE_UNDEFINED; + CULL_MODE CullMode = CULL_MODE_UNDEFINED; + EnableStateHelper FrontCounterClockwise; + float fDepthBias = std::numeric_limits::max(); + float fSlopeScaledDepthBias = std::numeric_limits::max(); + EnableStateHelper DepthClampEnable; + EnableStateHelper ScissorTestEnable; + } m_RSState; + + ContextCaps m_Caps; + + Uint32 m_ColorWriteMasks[MAX_RENDER_TARGETS] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + EnableStateHelper m_bIndependentWriteMasks; + Int32 m_iActiveTexture = -1; + Int32 m_NumPatchVertices = -1; + + GLContext::NativeGLContextType m_CurrentGLContext = {}; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h deleted file mode 100644 index 48c0a7ac..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h +++ /dev/null @@ -1,49 +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 -{ - -class GLContext -{ -public: - using NativeGLContextType = HGLRC; - - GLContext(const struct EngineGLCreateInfo& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc); - ~GLContext(); - void SwapBuffers(); - - NativeGLContextType GetCurrentNativeGLContext(); - -private: - HGLRC m_Context = NULL; - HDC m_WindowHandleToDeviceContext = NULL; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp new file mode 100644 index 00000000..48c0a7ac --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.hpp @@ -0,0 +1,49 @@ +/* + * 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 +{ + +class GLContext +{ +public: + using NativeGLContextType = HGLRC; + + GLContext(const struct EngineGLCreateInfo& InitAttribs, struct DeviceCaps& DeviceCaps, const struct SwapChainDesc* pSCDesc); + ~GLContext(); + void SwapBuffers(); + + NativeGLContextType GetCurrentNativeGLContext(); + +private: + HGLRC m_Context = NULL; + HDC m_WindowHandleToDeviceContext = NULL; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h deleted file mode 100644 index 5e963b61..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h +++ /dev/null @@ -1,343 +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 "UniqueIdentifier.h" - -namespace GLObjectWrappers -{ - -template -class GLObjWrapper -{ -public: - explicit GLObjWrapper(bool CreateObject, CreateReleaseHelperType CreateReleaseHelper = CreateReleaseHelperType()) : - // clang-format off - m_uiHandle {0 }, - m_CreateReleaseHelper{CreateReleaseHelper} - // clang-format on - { - if (CreateObject) - { - Create(); - if (!m_uiHandle) - { - LOG_ERROR_AND_THROW("Failed to create ", m_CreateReleaseHelper.Name, " GL object"); - } - } - } - - ~GLObjWrapper() - { - Release(); - } - - // clang-format off - GLObjWrapper (const GLObjWrapper&) = delete; - GLObjWrapper& operator=(const GLObjWrapper&) = delete; - // clang-format on - - GLObjWrapper(GLObjWrapper&& Wrapper) : - // clang-format off - m_uiHandle {Wrapper.m_uiHandle }, - m_CreateReleaseHelper{std::move(Wrapper.m_CreateReleaseHelper)}, - m_UniqueId {std::move(Wrapper.m_UniqueId) } - // clang-format on - { - Wrapper.m_uiHandle = 0; - } - - GLObjWrapper& operator=(GLObjWrapper&& Wrapper) - { - Release(); - - m_uiHandle = Wrapper.m_uiHandle; - m_CreateReleaseHelper = std::move(Wrapper.m_CreateReleaseHelper); - m_UniqueId = std::move(Wrapper.m_UniqueId); - - Wrapper.m_uiHandle = 0; - - return *this; - } - - void Create() - { - VERIFY(m_uiHandle == 0, "GL object is already initialized"); - Release(); - m_CreateReleaseHelper.Create(m_uiHandle); - VERIFY(m_uiHandle, "Failed to initialize GL object"); - } - - void Release() - { - if (m_uiHandle) - { - m_CreateReleaseHelper.Release(m_uiHandle); - m_uiHandle = 0; - } - } - - Diligent::UniqueIdentifier GetUniqueID() const - { - // This unique ID is used to unambiguously identify the object for - // tracking purposes. - // Niether GL handle nor pointer could be safely used for this purpose - // as both GL reuses released handles and the OS reuses released pointers - return m_UniqueId.GetID(); - } - - operator GLuint() const { return m_uiHandle; } - - static GLObjWrapper Null() - { - return GLObjWrapper{false}; - } - -private: - GLuint m_uiHandle; - CreateReleaseHelperType m_CreateReleaseHelper; - - // Have separate counter for every type of wrappers - Diligent::UniqueIdHelper m_UniqueId; -}; - -class GLBufferObjCreateReleaseHelper -{ -public: - explicit GLBufferObjCreateReleaseHelper(GLuint ExternalGLBufferHandle = 0) : - m_ExternalGLBufferHandle{ExternalGLBufferHandle} - {} - - void Create(GLuint& BuffObj) - { - if (m_ExternalGLBufferHandle != 0) - BuffObj = m_ExternalGLBufferHandle; // Attach to external GL buffer handle - else - glGenBuffers(1, &BuffObj); - } - - void Release(GLuint BuffObj) - { - if (m_ExternalGLBufferHandle != 0) - m_ExternalGLBufferHandle = 0; // Detach from external GL buffer. DO NOT delete the buffer - else - glDeleteBuffers(1, &BuffObj); - } - static const char* Name; - -private: - GLuint m_ExternalGLBufferHandle; -}; -typedef GLObjWrapper GLBufferObj; - - -class GLProgramObjCreateReleaseHelper -{ -public: - static void Create(GLuint& ProgObj) { ProgObj = glCreateProgram(); } - static void Release(GLuint ProgObj) { glDeleteProgram(ProgObj); } - - static const char* Name; -}; -typedef GLObjWrapper GLProgramObj; - - -class GLShaderObjCreateReleaseHelper -{ -public: - GLShaderObjCreateReleaseHelper(GLenum ShaderType) : - m_ShaderType(ShaderType) {} - void Create(GLuint& ShaderObj) { ShaderObj = glCreateShader(m_ShaderType); } - void Release(GLuint ShaderObj) { glDeleteShader(ShaderObj); } - - static const char* Name; - -private: - GLenum m_ShaderType; -}; -typedef GLObjWrapper GLShaderObj; - - -class GLPipelineObjCreateReleaseHelper -{ -public: - void Create(GLuint& Pipeline) { glGenProgramPipelines(1, &Pipeline); } - void Release(GLuint Pipeline) { glDeleteProgramPipelines(1, &Pipeline); } - - static const char* Name; -}; -typedef GLObjWrapper GLPipelineObj; - - -class GLVAOCreateReleaseHelper -{ -public: - void Create(GLuint& VAO) { glGenVertexArrays(1, &VAO); } - void Release(GLuint VAO) { glDeleteVertexArrays(1, &VAO); } - - static const char* Name; -}; -typedef GLObjWrapper GLVertexArrayObj; - - -class GLTextureCreateReleaseHelper -{ -public: - explicit GLTextureCreateReleaseHelper(GLuint ExternalGLTextureHandle = 0) : - m_ExternalGLTextureHandle(ExternalGLTextureHandle) - {} - - void Create(GLuint& Tex) - { - if (m_ExternalGLTextureHandle != 0) - Tex = m_ExternalGLTextureHandle; // Attach to the external texture - else - glGenTextures(1, &Tex); - } - - void Release(GLuint Tex) - { - if (m_ExternalGLTextureHandle != 0) - m_ExternalGLTextureHandle = 0; // Detach from the external texture. DO NOT delete it! - else - glDeleteTextures(1, &Tex); - } - - static const char* Name; - -private: - GLuint m_ExternalGLTextureHandle; -}; -typedef GLObjWrapper GLTextureObj; - -class GLSamplerCreateReleaseHelper -{ -public: - void Create(GLuint& Sampler) { glGenSamplers(1, &Sampler); } - void Release(GLuint Sampler) { glDeleteSamplers(1, &Sampler); } - - static const char* Name; -}; -typedef GLObjWrapper GLSamplerObj; - - -class GLFBOCreateReleaseHelper -{ -public: - explicit GLFBOCreateReleaseHelper(GLuint ExternalFBOHandle = 0) : - m_ExternalFBOHandle(ExternalFBOHandle) - {} - - void Create(GLuint& FBO) - { - if (m_ExternalFBOHandle != 0) - FBO = m_ExternalFBOHandle; // Attach to external FBO handle - else - glGenFramebuffers(1, &FBO); - } - - void Release(GLuint FBO) - { - if (m_ExternalFBOHandle != 0) - m_ExternalFBOHandle = 0; // DO NOT delete the FBO - else - glDeleteFramebuffers(1, &FBO); - } - - static const char* Name; - -private: - GLuint m_ExternalFBOHandle; -}; -typedef GLObjWrapper GLFrameBufferObj; - - -class GLRBOCreateReleaseHelper -{ -public: - void Create(GLuint& RBO) { glGenRenderbuffers(1, &RBO); } - void Release(GLuint RBO) { glDeleteRenderbuffers(1, &RBO); } - - static const char* Name; -}; -typedef GLObjWrapper GLRenderBufferObj; - -struct GLSyncObj -{ - GLSyncObj() {} - GLSyncObj(GLsync _SyncHandle) : - SyncHandle{_SyncHandle} {} - - // clang-format off - GLSyncObj (const GLSyncObj&) = delete; - GLSyncObj& operator = (const GLSyncObj&) = delete; - // clang-format on - - GLSyncObj(GLSyncObj&& rhs) - { - SyncHandle = rhs.SyncHandle; - rhs.SyncHandle = GLsync{}; - } - - GLSyncObj& operator=(GLSyncObj&& rhs) - { - Release(); - SyncHandle = rhs.SyncHandle; - rhs.SyncHandle = GLsync{}; - return *this; - } - - void Release() - { - if (SyncHandle != GLsync{}) - glDeleteSync(SyncHandle); - SyncHandle = GLsync{}; - } - - ~GLSyncObj() - { - Release(); - } - - operator GLsync() const { return SyncHandle; } - -private: - GLsync SyncHandle = {}; -}; - -class GLQueryCreateReleaseHelper -{ -public: - void Create(GLuint& Query) { glGenQueries(1, &Query); } - void Release(GLuint Query) { glDeleteQueries(1, &Query); } - - static const char* Name; -}; -typedef GLObjWrapper GLQueryObj; - -} // namespace GLObjectWrappers diff --git a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.hpp b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.hpp new file mode 100644 index 00000000..5e963b61 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.hpp @@ -0,0 +1,343 @@ +/* + * 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 "UniqueIdentifier.h" + +namespace GLObjectWrappers +{ + +template +class GLObjWrapper +{ +public: + explicit GLObjWrapper(bool CreateObject, CreateReleaseHelperType CreateReleaseHelper = CreateReleaseHelperType()) : + // clang-format off + m_uiHandle {0 }, + m_CreateReleaseHelper{CreateReleaseHelper} + // clang-format on + { + if (CreateObject) + { + Create(); + if (!m_uiHandle) + { + LOG_ERROR_AND_THROW("Failed to create ", m_CreateReleaseHelper.Name, " GL object"); + } + } + } + + ~GLObjWrapper() + { + Release(); + } + + // clang-format off + GLObjWrapper (const GLObjWrapper&) = delete; + GLObjWrapper& operator=(const GLObjWrapper&) = delete; + // clang-format on + + GLObjWrapper(GLObjWrapper&& Wrapper) : + // clang-format off + m_uiHandle {Wrapper.m_uiHandle }, + m_CreateReleaseHelper{std::move(Wrapper.m_CreateReleaseHelper)}, + m_UniqueId {std::move(Wrapper.m_UniqueId) } + // clang-format on + { + Wrapper.m_uiHandle = 0; + } + + GLObjWrapper& operator=(GLObjWrapper&& Wrapper) + { + Release(); + + m_uiHandle = Wrapper.m_uiHandle; + m_CreateReleaseHelper = std::move(Wrapper.m_CreateReleaseHelper); + m_UniqueId = std::move(Wrapper.m_UniqueId); + + Wrapper.m_uiHandle = 0; + + return *this; + } + + void Create() + { + VERIFY(m_uiHandle == 0, "GL object is already initialized"); + Release(); + m_CreateReleaseHelper.Create(m_uiHandle); + VERIFY(m_uiHandle, "Failed to initialize GL object"); + } + + void Release() + { + if (m_uiHandle) + { + m_CreateReleaseHelper.Release(m_uiHandle); + m_uiHandle = 0; + } + } + + Diligent::UniqueIdentifier GetUniqueID() const + { + // This unique ID is used to unambiguously identify the object for + // tracking purposes. + // Niether GL handle nor pointer could be safely used for this purpose + // as both GL reuses released handles and the OS reuses released pointers + return m_UniqueId.GetID(); + } + + operator GLuint() const { return m_uiHandle; } + + static GLObjWrapper Null() + { + return GLObjWrapper{false}; + } + +private: + GLuint m_uiHandle; + CreateReleaseHelperType m_CreateReleaseHelper; + + // Have separate counter for every type of wrappers + Diligent::UniqueIdHelper m_UniqueId; +}; + +class GLBufferObjCreateReleaseHelper +{ +public: + explicit GLBufferObjCreateReleaseHelper(GLuint ExternalGLBufferHandle = 0) : + m_ExternalGLBufferHandle{ExternalGLBufferHandle} + {} + + void Create(GLuint& BuffObj) + { + if (m_ExternalGLBufferHandle != 0) + BuffObj = m_ExternalGLBufferHandle; // Attach to external GL buffer handle + else + glGenBuffers(1, &BuffObj); + } + + void Release(GLuint BuffObj) + { + if (m_ExternalGLBufferHandle != 0) + m_ExternalGLBufferHandle = 0; // Detach from external GL buffer. DO NOT delete the buffer + else + glDeleteBuffers(1, &BuffObj); + } + static const char* Name; + +private: + GLuint m_ExternalGLBufferHandle; +}; +typedef GLObjWrapper GLBufferObj; + + +class GLProgramObjCreateReleaseHelper +{ +public: + static void Create(GLuint& ProgObj) { ProgObj = glCreateProgram(); } + static void Release(GLuint ProgObj) { glDeleteProgram(ProgObj); } + + static const char* Name; +}; +typedef GLObjWrapper GLProgramObj; + + +class GLShaderObjCreateReleaseHelper +{ +public: + GLShaderObjCreateReleaseHelper(GLenum ShaderType) : + m_ShaderType(ShaderType) {} + void Create(GLuint& ShaderObj) { ShaderObj = glCreateShader(m_ShaderType); } + void Release(GLuint ShaderObj) { glDeleteShader(ShaderObj); } + + static const char* Name; + +private: + GLenum m_ShaderType; +}; +typedef GLObjWrapper GLShaderObj; + + +class GLPipelineObjCreateReleaseHelper +{ +public: + void Create(GLuint& Pipeline) { glGenProgramPipelines(1, &Pipeline); } + void Release(GLuint Pipeline) { glDeleteProgramPipelines(1, &Pipeline); } + + static const char* Name; +}; +typedef GLObjWrapper GLPipelineObj; + + +class GLVAOCreateReleaseHelper +{ +public: + void Create(GLuint& VAO) { glGenVertexArrays(1, &VAO); } + void Release(GLuint VAO) { glDeleteVertexArrays(1, &VAO); } + + static const char* Name; +}; +typedef GLObjWrapper GLVertexArrayObj; + + +class GLTextureCreateReleaseHelper +{ +public: + explicit GLTextureCreateReleaseHelper(GLuint ExternalGLTextureHandle = 0) : + m_ExternalGLTextureHandle(ExternalGLTextureHandle) + {} + + void Create(GLuint& Tex) + { + if (m_ExternalGLTextureHandle != 0) + Tex = m_ExternalGLTextureHandle; // Attach to the external texture + else + glGenTextures(1, &Tex); + } + + void Release(GLuint Tex) + { + if (m_ExternalGLTextureHandle != 0) + m_ExternalGLTextureHandle = 0; // Detach from the external texture. DO NOT delete it! + else + glDeleteTextures(1, &Tex); + } + + static const char* Name; + +private: + GLuint m_ExternalGLTextureHandle; +}; +typedef GLObjWrapper GLTextureObj; + +class GLSamplerCreateReleaseHelper +{ +public: + void Create(GLuint& Sampler) { glGenSamplers(1, &Sampler); } + void Release(GLuint Sampler) { glDeleteSamplers(1, &Sampler); } + + static const char* Name; +}; +typedef GLObjWrapper GLSamplerObj; + + +class GLFBOCreateReleaseHelper +{ +public: + explicit GLFBOCreateReleaseHelper(GLuint ExternalFBOHandle = 0) : + m_ExternalFBOHandle(ExternalFBOHandle) + {} + + void Create(GLuint& FBO) + { + if (m_ExternalFBOHandle != 0) + FBO = m_ExternalFBOHandle; // Attach to external FBO handle + else + glGenFramebuffers(1, &FBO); + } + + void Release(GLuint FBO) + { + if (m_ExternalFBOHandle != 0) + m_ExternalFBOHandle = 0; // DO NOT delete the FBO + else + glDeleteFramebuffers(1, &FBO); + } + + static const char* Name; + +private: + GLuint m_ExternalFBOHandle; +}; +typedef GLObjWrapper GLFrameBufferObj; + + +class GLRBOCreateReleaseHelper +{ +public: + void Create(GLuint& RBO) { glGenRenderbuffers(1, &RBO); } + void Release(GLuint RBO) { glDeleteRenderbuffers(1, &RBO); } + + static const char* Name; +}; +typedef GLObjWrapper GLRenderBufferObj; + +struct GLSyncObj +{ + GLSyncObj() {} + GLSyncObj(GLsync _SyncHandle) : + SyncHandle{_SyncHandle} {} + + // clang-format off + GLSyncObj (const GLSyncObj&) = delete; + GLSyncObj& operator = (const GLSyncObj&) = delete; + // clang-format on + + GLSyncObj(GLSyncObj&& rhs) + { + SyncHandle = rhs.SyncHandle; + rhs.SyncHandle = GLsync{}; + } + + GLSyncObj& operator=(GLSyncObj&& rhs) + { + Release(); + SyncHandle = rhs.SyncHandle; + rhs.SyncHandle = GLsync{}; + return *this; + } + + void Release() + { + if (SyncHandle != GLsync{}) + glDeleteSync(SyncHandle); + SyncHandle = GLsync{}; + } + + ~GLSyncObj() + { + Release(); + } + + operator GLsync() const { return SyncHandle; } + +private: + GLsync SyncHandle = {}; +}; + +class GLQueryCreateReleaseHelper +{ +public: + void Create(GLuint& Query) { glGenQueries(1, &Query); } + void Release(GLuint Query) { glDeleteQueries(1, &Query); } + + static const char* Name; +}; +typedef GLObjWrapper GLQueryObj; + +} // namespace GLObjectWrappers diff --git a/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.h b/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.h deleted file mode 100644 index 967f9411..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.h +++ /dev/null @@ -1,459 +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 - -// GLPipelineResourceLayout class manages resource bindings for all stages in a pipeline - -// -// -// To program resource cache -// -// A A A A A A A A -// | | | | | | | | -// Binding Binding Binding Binding Binding Binding Binding Binding -// ___________________ ____|__________|__________________|________|______________|___________|______________|____________|____________ -// | | | | | | | | | | | | | | | -// |GLProgramResources |--------------->| UB[0] | UB[1] | ... | Sam[0] | Sam[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... | -// |___________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______| -// A A A A -// | | | | -// Ref Ref Ref Ref -// .-==========================-. _____|____________________________________|________________________|____________________________|______________ -// || || | | | | | | | | | | | -// __|| GLPipelineResourceLayout ||------->| UBInfo[0] | UBInfo[1] | ... | SamInfo[0] | SamInfo[1] | ... | ImgInfo[0] | ... | SSBO[0] | ... | -// | || || |___________|___________|_______|____________|____________|_______|____________|_________|___________|__________| -// | '-==========================-' / \ -// | Ref Ref -// | / \ -// | ___________________ ________V________________________________________________V_____________________________________________________ -// | | | | | | | | | | | | | | | | -// | |GLProgramResources |--------------->| UB[0] | UB[1] | ... | Sam[0] | Sam[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... | -// | |___________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______| -// | | | | | | | | | -// | Binding Binding Binding Binding Binding Binding Binding Binding -// | | | | | | | | | -// | _______________________ ____V___________V________________V_________V________________V________V________________V___________V_____________ -// | | | | | | | | -// '-->|GLProgramResourceCache |----------->| Uinform Buffers | Samplers | Images | Storge Buffers | -// |_______________________| |___________________________|___________________________|___________________________|___________________________| -// -// -// Note that GLProgramResources are kept by PipelineStateGLImpl. GLPipelineResourceLayout class is either part of the same PSO class, -// or part of ShaderResourceBindingGLImpl object that keeps a strong reference to the pipeline. So all references from GLVariableBase -// are always valid. - -#include - -#include "Object.h" -#include "ShaderResourceVariableBase.hpp" -#include "GLProgramResources.h" -#include "GLProgramResourceCache.h" - -namespace Diligent -{ - -class IMemoryAllocator; - -class GLPipelineResourceLayout -{ -public: - GLPipelineResourceLayout(IObject& Owner) : - m_Owner(Owner) - {} - ~GLPipelineResourceLayout(); - - // No copies, only moves are allowed - // clang-format off - GLPipelineResourceLayout (const GLPipelineResourceLayout&) = delete; - GLPipelineResourceLayout& operator = (const GLPipelineResourceLayout&) = delete; - GLPipelineResourceLayout ( GLPipelineResourceLayout&&) = default; - GLPipelineResourceLayout& operator = ( GLPipelineResourceLayout&&) = delete; - // clang-format on - - void Initialize(GLProgramResources* ProgramResources, - Uint32 NumPrograms, - const PipelineResourceLayoutDesc& ResourceLayout, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - GLProgramResourceCache* pResourceCache); - - static size_t GetRequiredMemorySize(GLProgramResources* ProgramResources, - Uint32 NumPrograms, - const PipelineResourceLayoutDesc& ResourceLayout, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes); - - void CopyResources(GLProgramResourceCache& DstCache) const; - - struct GLVariableBase : public ShaderVariableBase - { - using TBase = ShaderVariableBase; - GLVariableBase(const GLProgramResources::GLResourceAttribs& ResourceAttribs, - GLPipelineResourceLayout& ParentLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType, - Int32 StaticSamplerIdx) : - // clang-format off - TBase {ParentLayout}, - m_Attribs {ResourceAttribs }, - m_VariableType {VariableType }, - m_StaticSamplerIdx{StaticSamplerIdx} - // clang-format on - { - VERIFY_EXPR(StaticSamplerIdx < 0 || ResourceAttribs.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV); - } - - virtual SHADER_RESOURCE_VARIABLE_TYPE GetType() const override final - { - return m_VariableType; - } - - virtual void GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final - { - ResourceDesc = m_Attribs.GetResourceDesc(); - } - - virtual Uint32 GetIndex() const override final - { - return m_ParentResLayout.GetVariableIndex(*this); - } - - const GLProgramResources::GLResourceAttribs& m_Attribs; - const SHADER_RESOURCE_VARIABLE_TYPE m_VariableType; - const Int32 m_StaticSamplerIdx; - }; - - - struct UniformBuffBindInfo final : GLVariableBase - { - UniformBuffBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, - GLPipelineResourceLayout& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, -1} - {} - - // Non-virtual function - void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - - virtual void Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final - { - VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - - virtual bool IsBound(Uint32 ArrayIndex) const override final - { - VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); - return m_ParentResLayout.m_pResourceCache->IsUBBound(m_Attribs.Binding + ArrayIndex); - } - }; - - - struct SamplerBindInfo final : GLVariableBase - { - SamplerBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, - GLPipelineResourceLayout& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType, - Int32 StaticSamplerIdx) : - GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, StaticSamplerIdx} - {} - - // Non-virtual function - void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - - virtual void Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final - { - VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - - virtual bool IsBound(Uint32 ArrayIndex) const override final - { - VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); - return m_ParentResLayout.m_pResourceCache->IsSamplerBound(m_Attribs.Binding + ArrayIndex, m_Attribs.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV); - } - }; - - - struct ImageBindInfo final : GLVariableBase - { - ImageBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, - GLPipelineResourceLayout& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, -1} - {} - - // Provide non-virtual function - void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - - virtual void Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final - { - VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - - virtual bool IsBound(Uint32 ArrayIndex) const override final - { - VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); - return m_ParentResLayout.m_pResourceCache->IsImageBound(m_Attribs.Binding + ArrayIndex, m_Attribs.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_UAV); - } - }; - - - struct StorageBufferBindInfo final : GLVariableBase - { - StorageBufferBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, - GLPipelineResourceLayout& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, -1} - {} - - // Non-virtual function - void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); - - virtual void Set(IDeviceObject* pObject) override final - { - BindResource(pObject, 0); - } - - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final - { - VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); - for (Uint32 elem = 0; elem < NumElements; ++elem) - BindResource(ppObjects[elem], FirstElement + elem); - } - - virtual bool IsBound(Uint32 ArrayIndex) const override final - { - VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); - return m_ParentResLayout.m_pResourceCache->IsSSBOBound(m_Attribs.Binding + ArrayIndex); - } - }; - - - // dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive - // while Layout is alive - void BindResources(SHADER_TYPE ShaderStage, IResourceMapping* pResourceMapping, Uint32 Flags, const GLProgramResourceCache& dbgResourceCache); - -#ifdef DEVELOPMENT - bool dvpVerifyBindings(const GLProgramResourceCache& ResourceCache) const; -#endif - - IShaderResourceVariable* GetShaderVariable(SHADER_TYPE ShaderStage, const Char* Name); - IShaderResourceVariable* GetShaderVariable(SHADER_TYPE ShaderStage, Uint32 Index); - - IObject& GetOwner() { return m_Owner; } - - Uint32 GetNumVariables(SHADER_TYPE ShaderStage) const; - - // clang-format off - Uint32 GetNumUBs() const { return (m_SamplerOffset - m_UBOffset) / sizeof(UniformBuffBindInfo); } - Uint32 GetNumSamplers() const { return (m_ImageOffset - m_SamplerOffset) / sizeof(SamplerBindInfo); } - Uint32 GetNumImages() const { return (m_StorageBufferOffset - m_ImageOffset) / sizeof(ImageBindInfo) ; } - Uint32 GetNumStorageBuffers() const { return (m_VariableEndOffset - m_StorageBufferOffset) / sizeof(StorageBufferBindInfo); } - // clang-format on - - template Uint32 GetNumResources() const; - - template - const ResourceType& GetConstResource(Uint32 ResIndex) const - { - VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources(), ")"); - auto Offset = GetResourceOffset(); - return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; - } - - Uint32 GetVariableIndex(const GLVariableBase& Var) const; - -private: - // clang-format off -/* 0*/ IObject& m_Owner; - // No need to use shared pointer, as the resource cache is either part of the same - // ShaderGLImpl object, or ShaderResourceBindingGLImpl object -/* 8*/ GLProgramResourceCache* m_pResourceCache = nullptr; -/*16*/ std::unique_ptr > m_ResourceBuffer; - - // Offsets in bytes - using OffsetType = Uint16; - static constexpr OffsetType m_UBOffset = 0; -/*32*/ OffsetType m_SamplerOffset = 0; -/*34*/ OffsetType m_ImageOffset = 0; -/*36*/ OffsetType m_StorageBufferOffset = 0; -/*38*/ OffsetType m_VariableEndOffset = 0; -/*40*/ std::array m_ProgramIndex = {{-1, -1, -1, -1, -1, -1}}; -/*46*/ Uint8 m_NumPrograms = 0; -/*48*/ - // clang-format on - - template OffsetType GetResourceOffset() const; - - template - ResourceType& GetResource(Uint32 ResIndex) - { - VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources() - 1, ")"); - auto Offset = GetResourceOffset(); - return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; - } - - GLProgramResources::ResourceCounters& GetProgramVarEndOffsets(Uint32 prog) - { - VERIFY_EXPR(prog < m_NumPrograms); - return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + m_VariableEndOffset)[prog]; - } - - const GLProgramResources::ResourceCounters& GetProgramVarEndOffsets(Uint32 prog) const - { - VERIFY_EXPR(prog < m_NumPrograms); - return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + m_VariableEndOffset)[prog]; - } - - template - IShaderResourceVariable* GetResourceByName(SHADER_TYPE ShaderStage, const Char* Name); - - template - void HandleResources(THandleUB HandleUB, - THandleSampler HandleSampler, - THandleImage HandleImage, - THandleStorageBuffer HandleStorageBuffer) - { - for (Uint32 ub = 0; ub < GetNumResources(); ++ub) - HandleUB(GetResource(ub)); - - for (Uint32 s = 0; s < GetNumResources(); ++s) - HandleSampler(GetResource(s)); - - for (Uint32 i = 0; i < GetNumResources(); ++i) - HandleImage(GetResource(i)); - - for (Uint32 s = 0; s < GetNumResources(); ++s) - HandleStorageBuffer(GetResource(s)); - } - - template - void HandleConstResources(THandleUB HandleUB, - THandleSampler HandleSampler, - THandleImage HandleImage, - THandleStorageBuffer HandleStorageBuffer) const - { - for (Uint32 ub = 0; ub < GetNumResources(); ++ub) - HandleUB(GetConstResource(ub)); - - for (Uint32 s = 0; s < GetNumResources(); ++s) - HandleSampler(GetConstResource(s)); - - for (Uint32 i = 0; i < GetNumResources(); ++i) - HandleImage(GetConstResource(i)); - - for (Uint32 s = 0; s < GetNumResources(); ++s) - HandleStorageBuffer(GetConstResource(s)); - } - - friend class ShaderVariableIndexLocator; - friend class ShaderVariableLocator; -}; - - - -template <> -inline Uint32 GLPipelineResourceLayout::GetNumResources() const -{ - return GetNumUBs(); -} - -template <> -inline Uint32 GLPipelineResourceLayout::GetNumResources() const -{ - return GetNumSamplers(); -} - -template <> -inline Uint32 GLPipelineResourceLayout::GetNumResources() const -{ - return GetNumImages(); -} - -template <> -inline Uint32 GLPipelineResourceLayout::GetNumResources() const -{ - return GetNumStorageBuffers(); -} - - - -template <> -inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: - GetResourceOffset() const -{ - return m_UBOffset; -} - -template <> -inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: - GetResourceOffset() const -{ - return m_SamplerOffset; -} - -template <> -inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: - GetResourceOffset() const -{ - return m_ImageOffset; -} - -template <> -inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: - GetResourceOffset() const -{ - return m_StorageBufferOffset; -} - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp b/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp new file mode 100644 index 00000000..d97db39f --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLPipelineResourceLayout.hpp @@ -0,0 +1,459 @@ +/* + * 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 + +// GLPipelineResourceLayout class manages resource bindings for all stages in a pipeline + +// +// +// To program resource cache +// +// A A A A A A A A +// | | | | | | | | +// Binding Binding Binding Binding Binding Binding Binding Binding +// ___________________ ____|__________|__________________|________|______________|___________|______________|____________|____________ +// | | | | | | | | | | | | | | | +// |GLProgramResources |--------------->| UB[0] | UB[1] | ... | Sam[0] | Sam[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... | +// |___________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______| +// A A A A +// | | | | +// Ref Ref Ref Ref +// .-==========================-. _____|____________________________________|________________________|____________________________|______________ +// || || | | | | | | | | | | | +// __|| GLPipelineResourceLayout ||------->| UBInfo[0] | UBInfo[1] | ... | SamInfo[0] | SamInfo[1] | ... | ImgInfo[0] | ... | SSBO[0] | ... | +// | || || |___________|___________|_______|____________|____________|_______|____________|_________|___________|__________| +// | '-==========================-' / \ +// | Ref Ref +// | / \ +// | ___________________ ________V________________________________________________V_____________________________________________________ +// | | | | | | | | | | | | | | | | +// | |GLProgramResources |--------------->| UB[0] | UB[1] | ... | Sam[0] | Sam[1] | ... | Img[0] | Img[1] | ... | SSBOs[0] | SSBOs[1] | ... | +// | |___________________| |__________|__________|_______|________|________|_______|________|________|_______|__________|__________|_______| +// | | | | | | | | | +// | Binding Binding Binding Binding Binding Binding Binding Binding +// | | | | | | | | | +// | _______________________ ____V___________V________________V_________V________________V________V________________V___________V_____________ +// | | | | | | | | +// '-->|GLProgramResourceCache |----------->| Uinform Buffers | Samplers | Images | Storge Buffers | +// |_______________________| |___________________________|___________________________|___________________________|___________________________| +// +// +// Note that GLProgramResources are kept by PipelineStateGLImpl. GLPipelineResourceLayout class is either part of the same PSO class, +// or part of ShaderResourceBindingGLImpl object that keeps a strong reference to the pipeline. So all references from GLVariableBase +// are always valid. + +#include + +#include "Object.h" +#include "ShaderResourceVariableBase.hpp" +#include "GLProgramResources.hpp" +#include "GLProgramResourceCache.hpp" + +namespace Diligent +{ + +class IMemoryAllocator; + +class GLPipelineResourceLayout +{ +public: + GLPipelineResourceLayout(IObject& Owner) : + m_Owner(Owner) + {} + ~GLPipelineResourceLayout(); + + // No copies, only moves are allowed + // clang-format off + GLPipelineResourceLayout (const GLPipelineResourceLayout&) = delete; + GLPipelineResourceLayout& operator = (const GLPipelineResourceLayout&) = delete; + GLPipelineResourceLayout ( GLPipelineResourceLayout&&) = default; + GLPipelineResourceLayout& operator = ( GLPipelineResourceLayout&&) = delete; + // clang-format on + + void Initialize(GLProgramResources* ProgramResources, + Uint32 NumPrograms, + const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + GLProgramResourceCache* pResourceCache); + + static size_t GetRequiredMemorySize(GLProgramResources* ProgramResources, + Uint32 NumPrograms, + const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes); + + void CopyResources(GLProgramResourceCache& DstCache) const; + + struct GLVariableBase : public ShaderVariableBase + { + using TBase = ShaderVariableBase; + GLVariableBase(const GLProgramResources::GLResourceAttribs& ResourceAttribs, + GLPipelineResourceLayout& ParentLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType, + Int32 StaticSamplerIdx) : + // clang-format off + TBase {ParentLayout}, + m_Attribs {ResourceAttribs }, + m_VariableType {VariableType }, + m_StaticSamplerIdx{StaticSamplerIdx} + // clang-format on + { + VERIFY_EXPR(StaticSamplerIdx < 0 || ResourceAttribs.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV); + } + + virtual SHADER_RESOURCE_VARIABLE_TYPE GetType() const override final + { + return m_VariableType; + } + + virtual void GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final + { + ResourceDesc = m_Attribs.GetResourceDesc(); + } + + virtual Uint32 GetIndex() const override final + { + return m_ParentResLayout.GetVariableIndex(*this); + } + + const GLProgramResources::GLResourceAttribs& m_Attribs; + const SHADER_RESOURCE_VARIABLE_TYPE m_VariableType; + const Int32 m_StaticSamplerIdx; + }; + + + struct UniformBuffBindInfo final : GLVariableBase + { + UniformBuffBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, + GLPipelineResourceLayout& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, -1} + {} + + // Non-virtual function + void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); + + virtual void Set(IDeviceObject* pObject) override final + { + BindResource(pObject, 0); + } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final + { + VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); + } + + virtual bool IsBound(Uint32 ArrayIndex) const override final + { + VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); + return m_ParentResLayout.m_pResourceCache->IsUBBound(m_Attribs.Binding + ArrayIndex); + } + }; + + + struct SamplerBindInfo final : GLVariableBase + { + SamplerBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, + GLPipelineResourceLayout& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType, + Int32 StaticSamplerIdx) : + GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, StaticSamplerIdx} + {} + + // Non-virtual function + void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); + + virtual void Set(IDeviceObject* pObject) override final + { + BindResource(pObject, 0); + } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final + { + VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); + } + + virtual bool IsBound(Uint32 ArrayIndex) const override final + { + VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); + return m_ParentResLayout.m_pResourceCache->IsSamplerBound(m_Attribs.Binding + ArrayIndex, m_Attribs.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV); + } + }; + + + struct ImageBindInfo final : GLVariableBase + { + ImageBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, + GLPipelineResourceLayout& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, -1} + {} + + // Provide non-virtual function + void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); + + virtual void Set(IDeviceObject* pObject) override final + { + BindResource(pObject, 0); + } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final + { + VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); + } + + virtual bool IsBound(Uint32 ArrayIndex) const override final + { + VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); + return m_ParentResLayout.m_pResourceCache->IsImageBound(m_Attribs.Binding + ArrayIndex, m_Attribs.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_UAV); + } + }; + + + struct StorageBufferBindInfo final : GLVariableBase + { + StorageBufferBindInfo(const GLProgramResources::GLResourceAttribs& ResourceAttribs, + GLPipelineResourceLayout& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + GLVariableBase{ResourceAttribs, ParentResLayout, VariableType, -1} + {} + + // Non-virtual function + void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); + + virtual void Set(IDeviceObject* pObject) override final + { + BindResource(pObject, 0); + } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) override final + { + VerifyAndCorrectSetArrayArguments(m_Attribs.Name, m_Attribs.ArraySize, FirstElement, NumElements); + for (Uint32 elem = 0; elem < NumElements; ++elem) + BindResource(ppObjects[elem], FirstElement + elem); + } + + virtual bool IsBound(Uint32 ArrayIndex) const override final + { + VERIFY_EXPR(ArrayIndex < m_Attribs.ArraySize); + return m_ParentResLayout.m_pResourceCache->IsSSBOBound(m_Attribs.Binding + ArrayIndex); + } + }; + + + // dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive + // while Layout is alive + void BindResources(SHADER_TYPE ShaderStage, IResourceMapping* pResourceMapping, Uint32 Flags, const GLProgramResourceCache& dbgResourceCache); + +#ifdef DEVELOPMENT + bool dvpVerifyBindings(const GLProgramResourceCache& ResourceCache) const; +#endif + + IShaderResourceVariable* GetShaderVariable(SHADER_TYPE ShaderStage, const Char* Name); + IShaderResourceVariable* GetShaderVariable(SHADER_TYPE ShaderStage, Uint32 Index); + + IObject& GetOwner() { return m_Owner; } + + Uint32 GetNumVariables(SHADER_TYPE ShaderStage) const; + + // clang-format off + Uint32 GetNumUBs() const { return (m_SamplerOffset - m_UBOffset) / sizeof(UniformBuffBindInfo); } + Uint32 GetNumSamplers() const { return (m_ImageOffset - m_SamplerOffset) / sizeof(SamplerBindInfo); } + Uint32 GetNumImages() const { return (m_StorageBufferOffset - m_ImageOffset) / sizeof(ImageBindInfo) ; } + Uint32 GetNumStorageBuffers() const { return (m_VariableEndOffset - m_StorageBufferOffset) / sizeof(StorageBufferBindInfo); } + // clang-format on + + template Uint32 GetNumResources() const; + + template + const ResourceType& GetConstResource(Uint32 ResIndex) const + { + VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources(), ")"); + auto Offset = GetResourceOffset(); + return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; + } + + Uint32 GetVariableIndex(const GLVariableBase& Var) const; + +private: + // clang-format off +/* 0*/ IObject& m_Owner; + // No need to use shared pointer, as the resource cache is either part of the same + // ShaderGLImpl object, or ShaderResourceBindingGLImpl object +/* 8*/ GLProgramResourceCache* m_pResourceCache = nullptr; +/*16*/ std::unique_ptr > m_ResourceBuffer; + + // Offsets in bytes + using OffsetType = Uint16; + static constexpr OffsetType m_UBOffset = 0; +/*32*/ OffsetType m_SamplerOffset = 0; +/*34*/ OffsetType m_ImageOffset = 0; +/*36*/ OffsetType m_StorageBufferOffset = 0; +/*38*/ OffsetType m_VariableEndOffset = 0; +/*40*/ std::array m_ProgramIndex = {{-1, -1, -1, -1, -1, -1}}; +/*46*/ Uint8 m_NumPrograms = 0; +/*48*/ + // clang-format on + + template OffsetType GetResourceOffset() const; + + template + ResourceType& GetResource(Uint32 ResIndex) + { + VERIFY(ResIndex < GetNumResources(), "Resource index (", ResIndex, ") exceeds max allowed value (", GetNumResources() - 1, ")"); + auto Offset = GetResourceOffset(); + return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + Offset)[ResIndex]; + } + + GLProgramResources::ResourceCounters& GetProgramVarEndOffsets(Uint32 prog) + { + VERIFY_EXPR(prog < m_NumPrograms); + return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + m_VariableEndOffset)[prog]; + } + + const GLProgramResources::ResourceCounters& GetProgramVarEndOffsets(Uint32 prog) const + { + VERIFY_EXPR(prog < m_NumPrograms); + return reinterpret_cast(reinterpret_cast(m_ResourceBuffer.get()) + m_VariableEndOffset)[prog]; + } + + template + IShaderResourceVariable* GetResourceByName(SHADER_TYPE ShaderStage, const Char* Name); + + template + void HandleResources(THandleUB HandleUB, + THandleSampler HandleSampler, + THandleImage HandleImage, + THandleStorageBuffer HandleStorageBuffer) + { + for (Uint32 ub = 0; ub < GetNumResources(); ++ub) + HandleUB(GetResource(ub)); + + for (Uint32 s = 0; s < GetNumResources(); ++s) + HandleSampler(GetResource(s)); + + for (Uint32 i = 0; i < GetNumResources(); ++i) + HandleImage(GetResource(i)); + + for (Uint32 s = 0; s < GetNumResources(); ++s) + HandleStorageBuffer(GetResource(s)); + } + + template + void HandleConstResources(THandleUB HandleUB, + THandleSampler HandleSampler, + THandleImage HandleImage, + THandleStorageBuffer HandleStorageBuffer) const + { + for (Uint32 ub = 0; ub < GetNumResources(); ++ub) + HandleUB(GetConstResource(ub)); + + for (Uint32 s = 0; s < GetNumResources(); ++s) + HandleSampler(GetConstResource(s)); + + for (Uint32 i = 0; i < GetNumResources(); ++i) + HandleImage(GetConstResource(i)); + + for (Uint32 s = 0; s < GetNumResources(); ++s) + HandleStorageBuffer(GetConstResource(s)); + } + + friend class ShaderVariableIndexLocator; + friend class ShaderVariableLocator; +}; + + + +template <> +inline Uint32 GLPipelineResourceLayout::GetNumResources() const +{ + return GetNumUBs(); +} + +template <> +inline Uint32 GLPipelineResourceLayout::GetNumResources() const +{ + return GetNumSamplers(); +} + +template <> +inline Uint32 GLPipelineResourceLayout::GetNumResources() const +{ + return GetNumImages(); +} + +template <> +inline Uint32 GLPipelineResourceLayout::GetNumResources() const +{ + return GetNumStorageBuffers(); +} + + + +template <> +inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: + GetResourceOffset() const +{ + return m_UBOffset; +} + +template <> +inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: + GetResourceOffset() const +{ + return m_SamplerOffset; +} + +template <> +inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: + GetResourceOffset() const +{ + return m_ImageOffset; +} + +template <> +inline GLPipelineResourceLayout::OffsetType GLPipelineResourceLayout:: + GetResourceOffset() const +{ + return m_StorageBufferOffset; +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.h b/Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.h deleted file mode 100644 index f3b1fb1a..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.h +++ /dev/null @@ -1,276 +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 "BufferGLImpl.h" -#include "TextureBaseGL.h" -#include "SamplerGLImpl.h" - -namespace Diligent -{ - -/// The class implements a cache that holds resources bound to a specific GL program -// All resources are stored in the continuous memory using the following layout: -// -// | Cached UBs | Cached Samplers | Cached Images | Cached Storage Blocks | -// |----------------------------------------------------|--------------------------|---------------------------| -// | 0 | 1 | ... | UBCount-1 | 0 | 1 | ...| SmpCount-1 | 0 | 1 | ... | ImgCount-1 | 0 | 1 | ... | SBOCount-1 | -// ----------------------------------------------------------------------------------------------------------- -// -class GLProgramResourceCache -{ -public: - GLProgramResourceCache() - {} - - ~GLProgramResourceCache(); - - // clang-format off - GLProgramResourceCache (const GLProgramResourceCache&) = delete; - GLProgramResourceCache& operator = (const GLProgramResourceCache&) = delete; - GLProgramResourceCache (GLProgramResourceCache&&) = delete; - GLProgramResourceCache& operator = (GLProgramResourceCache&&) = delete; - // clang-format on - - /// Describes a resource bound to a uniform buffer or a shader storage block slot - struct CachedUB - { - /// Strong reference to the buffer - RefCntAutoPtr pBuffer; - }; - - /// Describes a resource bound to a sampler or an image slot - struct CachedResourceView - { - /// We keep strong reference to the view instead of the reference - /// to the texture or buffer because this is more efficient from - /// performance point of view: this avoids one pair of - /// AddStrongRef()/ReleaseStrongRef(). The view holds a strong reference - /// to the texture or the buffer, so it makes no difference. - RefCntAutoPtr pView; - - TextureBaseGL* pTexture = nullptr; - union - { - BufferGLImpl* pBuffer = nullptr; // When pTexture == nullptr - SamplerGLImpl* pSampler; // When pTexture != nullptr - }; - CachedResourceView() noexcept {} - - void Set(RefCntAutoPtr&& pTexView, bool SetSampler) - { - // Do not null out pSampler as it could've been initialized by PipelineStateGLImpl::InitializeSRBResourceCache! - // pSampler = nullptr; - - // Avoid unnecessary virtual function calls - pTexture = pTexView ? ValidatedCast(pTexView->TextureViewGLImpl::GetTexture()) : nullptr; - if (pTexView && SetSampler) - { - pSampler = ValidatedCast(pTexView->GetSampler()); - } - - pView.Attach(pTexView.Detach()); - } - - void Set(RefCntAutoPtr&& pBufView) - { - pTexture = nullptr; - // Avoid unnecessary virtual function calls - pBuffer = pBufView ? ValidatedCast(pBufView->BufferViewGLImpl::GetBuffer()) : nullptr; - pView.Attach(pBufView.Detach()); - } - }; - - struct CachedSSBO - { - /// Strong reference to the buffer - RefCntAutoPtr pBufferView; - }; - - - static size_t GetRequriedMemorySize(Uint32 UBCount, Uint32 SamplerCount, Uint32 ImageCount, Uint32 SSBOCount); - - void Initialize(Uint32 UBCount, Uint32 SamplerCount, Uint32 ImageCount, Uint32 SSBOCount, class IMemoryAllocator& MemAllocator); - void Destroy(class IMemoryAllocator& MemAllocator); - - void SetUniformBuffer(Uint32 Binding, RefCntAutoPtr&& pBuff) - { - GetUB(Binding).pBuffer = std::move(pBuff); - } - - void SetTexSampler(Uint32 Binding, RefCntAutoPtr&& pTexView, bool SetSampler) - { - GetSampler(Binding).Set(std::move(pTexView), SetSampler); - } - - void SetStaticSampler(Uint32 Binding, ISampler* pStaticSampler) - { - GetSampler(Binding).pSampler = ValidatedCast(pStaticSampler); - } - - void CopySampler(Uint32 Binding, const CachedResourceView& SrcSam) - { - GetSampler(Binding) = SrcSam; - } - - void SetBufSampler(Uint32 Binding, RefCntAutoPtr&& pBuffView) - { - GetSampler(Binding).Set(std::move(pBuffView)); - } - - void SetTexImage(Uint32 Binding, RefCntAutoPtr&& pTexView) - { - GetImage(Binding).Set(std::move(pTexView), false); - } - - void SetBufImage(Uint32 Binding, RefCntAutoPtr&& pBuffView) - { - GetImage(Binding).Set(std::move(pBuffView)); - } - - void CopyImage(Uint32 Binding, const CachedResourceView& SrcImg) - { - GetImage(Binding) = SrcImg; - } - - void SetSSBO(Uint32 Binding, RefCntAutoPtr&& pBuffView) - { - GetSSBO(Binding).pBufferView = std::move(pBuffView); - } - - bool IsUBBound(Uint32 Binding) const - { - if (Binding >= GetUBCount()) - return false; - - const auto& UB = GetConstUB(Binding); - return UB.pBuffer; - } - - bool IsSamplerBound(Uint32 Binding, bool dbgIsTextureView) const - { - if (Binding >= GetSamplerCount()) - return false; - - const auto& Sampler = GetConstSampler(Binding); - VERIFY_EXPR(dbgIsTextureView || Sampler.pTexture == nullptr); - return Sampler.pView; - } - - bool IsImageBound(Uint32 Binding, bool dbgIsTextureView) const - { - if (Binding >= GetImageCount()) - return false; - - const auto& Image = GetConstImage(Binding); - VERIFY_EXPR(dbgIsTextureView || Image.pTexture == nullptr); - return Image.pView; - } - - bool IsSSBOBound(Uint32 Binding) const - { - if (Binding >= GetSSBOCount()) - return false; - - const auto& SSBO = GetConstSSBO(Binding); - return SSBO.pBufferView; - } - - // clang-format off - Uint32 GetUBCount() const { return (m_SmplrsOffset - m_UBsOffset) / sizeof(CachedUB); } - Uint32 GetSamplerCount() const { return (m_ImgsOffset - m_SmplrsOffset) / sizeof(CachedResourceView); } - Uint32 GetImageCount() const { return (m_SSBOsOffset - m_ImgsOffset) / sizeof(CachedResourceView); } - Uint32 GetSSBOCount() const { return (m_MemoryEndOffset - m_SSBOsOffset) / sizeof(CachedSSBO); } - // clang-format on - - const CachedUB& GetConstUB(Uint32 Binding) const - { - VERIFY(Binding < GetUBCount(), "Uniform buffer binding (", Binding, ") is out of range"); - return reinterpret_cast(m_pResourceData + m_UBsOffset)[Binding]; - } - - const CachedResourceView& GetConstSampler(Uint32 Binding) const - { - VERIFY(Binding < GetSamplerCount(), "Sampler binding (", Binding, ") is out of range"); - return reinterpret_cast(m_pResourceData + m_SmplrsOffset)[Binding]; - } - - const CachedResourceView& GetConstImage(Uint32 Binding) const - { - VERIFY(Binding < GetImageCount(), "Image buffer binding (", Binding, ") is out of range"); - return reinterpret_cast(m_pResourceData + m_ImgsOffset)[Binding]; - } - - const CachedSSBO& GetConstSSBO(Uint32 Binding) const - { - VERIFY(Binding < GetSSBOCount(), "Shader storage block binding (", Binding, ") is out of range"); - return reinterpret_cast(m_pResourceData + m_SSBOsOffset)[Binding]; - } - - bool IsInitialized() const - { - return m_MemoryEndOffset != InvalidResourceOffset; - } - -private: - CachedUB& GetUB(Uint32 Binding) - { - return const_cast(const_cast(this)->GetConstUB(Binding)); - } - - CachedResourceView& GetSampler(Uint32 Binding) - { - return const_cast(const_cast(this)->GetConstSampler(Binding)); - } - - CachedResourceView& GetImage(Uint32 Binding) - { - return const_cast(const_cast(this)->GetConstImage(Binding)); - } - - CachedSSBO& GetSSBO(Uint32 Binding) - { - return const_cast(const_cast(this)->GetConstSSBO(Binding)); - } - - static constexpr const Uint16 InvalidResourceOffset = 0xFFFF; - static constexpr const Uint16 m_UBsOffset = 0; - - Uint16 m_SmplrsOffset = InvalidResourceOffset; - Uint16 m_ImgsOffset = InvalidResourceOffset; - Uint16 m_SSBOsOffset = InvalidResourceOffset; - Uint16 m_MemoryEndOffset = InvalidResourceOffset; - - Uint8* m_pResourceData = nullptr; - -#ifdef _DEBUG - IMemoryAllocator* m_pdbgMemoryAllocator = nullptr; -#endif -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.hpp b/Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.hpp new file mode 100644 index 00000000..0a0bdd5a --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgramResourceCache.hpp @@ -0,0 +1,276 @@ +/* + * 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 "BufferGLImpl.hpp" +#include "TextureBaseGL.hpp" +#include "SamplerGLImpl.hpp" + +namespace Diligent +{ + +/// The class implements a cache that holds resources bound to a specific GL program +// All resources are stored in the continuous memory using the following layout: +// +// | Cached UBs | Cached Samplers | Cached Images | Cached Storage Blocks | +// |----------------------------------------------------|--------------------------|---------------------------| +// | 0 | 1 | ... | UBCount-1 | 0 | 1 | ...| SmpCount-1 | 0 | 1 | ... | ImgCount-1 | 0 | 1 | ... | SBOCount-1 | +// ----------------------------------------------------------------------------------------------------------- +// +class GLProgramResourceCache +{ +public: + GLProgramResourceCache() + {} + + ~GLProgramResourceCache(); + + // clang-format off + GLProgramResourceCache (const GLProgramResourceCache&) = delete; + GLProgramResourceCache& operator = (const GLProgramResourceCache&) = delete; + GLProgramResourceCache (GLProgramResourceCache&&) = delete; + GLProgramResourceCache& operator = (GLProgramResourceCache&&) = delete; + // clang-format on + + /// Describes a resource bound to a uniform buffer or a shader storage block slot + struct CachedUB + { + /// Strong reference to the buffer + RefCntAutoPtr pBuffer; + }; + + /// Describes a resource bound to a sampler or an image slot + struct CachedResourceView + { + /// We keep strong reference to the view instead of the reference + /// to the texture or buffer because this is more efficient from + /// performance point of view: this avoids one pair of + /// AddStrongRef()/ReleaseStrongRef(). The view holds a strong reference + /// to the texture or the buffer, so it makes no difference. + RefCntAutoPtr pView; + + TextureBaseGL* pTexture = nullptr; + union + { + BufferGLImpl* pBuffer = nullptr; // When pTexture == nullptr + SamplerGLImpl* pSampler; // When pTexture != nullptr + }; + CachedResourceView() noexcept {} + + void Set(RefCntAutoPtr&& pTexView, bool SetSampler) + { + // Do not null out pSampler as it could've been initialized by PipelineStateGLImpl::InitializeSRBResourceCache! + // pSampler = nullptr; + + // Avoid unnecessary virtual function calls + pTexture = pTexView ? ValidatedCast(pTexView->TextureViewGLImpl::GetTexture()) : nullptr; + if (pTexView && SetSampler) + { + pSampler = ValidatedCast(pTexView->GetSampler()); + } + + pView.Attach(pTexView.Detach()); + } + + void Set(RefCntAutoPtr&& pBufView) + { + pTexture = nullptr; + // Avoid unnecessary virtual function calls + pBuffer = pBufView ? ValidatedCast(pBufView->BufferViewGLImpl::GetBuffer()) : nullptr; + pView.Attach(pBufView.Detach()); + } + }; + + struct CachedSSBO + { + /// Strong reference to the buffer + RefCntAutoPtr pBufferView; + }; + + + static size_t GetRequriedMemorySize(Uint32 UBCount, Uint32 SamplerCount, Uint32 ImageCount, Uint32 SSBOCount); + + void Initialize(Uint32 UBCount, Uint32 SamplerCount, Uint32 ImageCount, Uint32 SSBOCount, class IMemoryAllocator& MemAllocator); + void Destroy(class IMemoryAllocator& MemAllocator); + + void SetUniformBuffer(Uint32 Binding, RefCntAutoPtr&& pBuff) + { + GetUB(Binding).pBuffer = std::move(pBuff); + } + + void SetTexSampler(Uint32 Binding, RefCntAutoPtr&& pTexView, bool SetSampler) + { + GetSampler(Binding).Set(std::move(pTexView), SetSampler); + } + + void SetStaticSampler(Uint32 Binding, ISampler* pStaticSampler) + { + GetSampler(Binding).pSampler = ValidatedCast(pStaticSampler); + } + + void CopySampler(Uint32 Binding, const CachedResourceView& SrcSam) + { + GetSampler(Binding) = SrcSam; + } + + void SetBufSampler(Uint32 Binding, RefCntAutoPtr&& pBuffView) + { + GetSampler(Binding).Set(std::move(pBuffView)); + } + + void SetTexImage(Uint32 Binding, RefCntAutoPtr&& pTexView) + { + GetImage(Binding).Set(std::move(pTexView), false); + } + + void SetBufImage(Uint32 Binding, RefCntAutoPtr&& pBuffView) + { + GetImage(Binding).Set(std::move(pBuffView)); + } + + void CopyImage(Uint32 Binding, const CachedResourceView& SrcImg) + { + GetImage(Binding) = SrcImg; + } + + void SetSSBO(Uint32 Binding, RefCntAutoPtr&& pBuffView) + { + GetSSBO(Binding).pBufferView = std::move(pBuffView); + } + + bool IsUBBound(Uint32 Binding) const + { + if (Binding >= GetUBCount()) + return false; + + const auto& UB = GetConstUB(Binding); + return UB.pBuffer; + } + + bool IsSamplerBound(Uint32 Binding, bool dbgIsTextureView) const + { + if (Binding >= GetSamplerCount()) + return false; + + const auto& Sampler = GetConstSampler(Binding); + VERIFY_EXPR(dbgIsTextureView || Sampler.pTexture == nullptr); + return Sampler.pView; + } + + bool IsImageBound(Uint32 Binding, bool dbgIsTextureView) const + { + if (Binding >= GetImageCount()) + return false; + + const auto& Image = GetConstImage(Binding); + VERIFY_EXPR(dbgIsTextureView || Image.pTexture == nullptr); + return Image.pView; + } + + bool IsSSBOBound(Uint32 Binding) const + { + if (Binding >= GetSSBOCount()) + return false; + + const auto& SSBO = GetConstSSBO(Binding); + return SSBO.pBufferView; + } + + // clang-format off + Uint32 GetUBCount() const { return (m_SmplrsOffset - m_UBsOffset) / sizeof(CachedUB); } + Uint32 GetSamplerCount() const { return (m_ImgsOffset - m_SmplrsOffset) / sizeof(CachedResourceView); } + Uint32 GetImageCount() const { return (m_SSBOsOffset - m_ImgsOffset) / sizeof(CachedResourceView); } + Uint32 GetSSBOCount() const { return (m_MemoryEndOffset - m_SSBOsOffset) / sizeof(CachedSSBO); } + // clang-format on + + const CachedUB& GetConstUB(Uint32 Binding) const + { + VERIFY(Binding < GetUBCount(), "Uniform buffer binding (", Binding, ") is out of range"); + return reinterpret_cast(m_pResourceData + m_UBsOffset)[Binding]; + } + + const CachedResourceView& GetConstSampler(Uint32 Binding) const + { + VERIFY(Binding < GetSamplerCount(), "Sampler binding (", Binding, ") is out of range"); + return reinterpret_cast(m_pResourceData + m_SmplrsOffset)[Binding]; + } + + const CachedResourceView& GetConstImage(Uint32 Binding) const + { + VERIFY(Binding < GetImageCount(), "Image buffer binding (", Binding, ") is out of range"); + return reinterpret_cast(m_pResourceData + m_ImgsOffset)[Binding]; + } + + const CachedSSBO& GetConstSSBO(Uint32 Binding) const + { + VERIFY(Binding < GetSSBOCount(), "Shader storage block binding (", Binding, ") is out of range"); + return reinterpret_cast(m_pResourceData + m_SSBOsOffset)[Binding]; + } + + bool IsInitialized() const + { + return m_MemoryEndOffset != InvalidResourceOffset; + } + +private: + CachedUB& GetUB(Uint32 Binding) + { + return const_cast(const_cast(this)->GetConstUB(Binding)); + } + + CachedResourceView& GetSampler(Uint32 Binding) + { + return const_cast(const_cast(this)->GetConstSampler(Binding)); + } + + CachedResourceView& GetImage(Uint32 Binding) + { + return const_cast(const_cast(this)->GetConstImage(Binding)); + } + + CachedSSBO& GetSSBO(Uint32 Binding) + { + return const_cast(const_cast(this)->GetConstSSBO(Binding)); + } + + static constexpr const Uint16 InvalidResourceOffset = 0xFFFF; + static constexpr const Uint16 m_UBsOffset = 0; + + Uint16 m_SmplrsOffset = InvalidResourceOffset; + Uint16 m_ImgsOffset = InvalidResourceOffset; + Uint16 m_SSBOsOffset = InvalidResourceOffset; + Uint16 m_MemoryEndOffset = InvalidResourceOffset; + + Uint8* m_pResourceData = nullptr; + +#ifdef _DEBUG + IMemoryAllocator* m_pdbgMemoryAllocator = nullptr; +#endif +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h deleted file mode 100644 index 40c64c8e..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h +++ /dev/null @@ -1,513 +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 - -// GLProgramResources class allocates single continuous chunk of memory to store all program resources, as follows: -// -// -// m_UniformBuffers m_Samplers m_Images m_StorageBlocks -// | | | | | | -// | UB[0] ... UB[Nu-1] | Sam[0] ... Sam[Ns-1] | Img[0] ... Img[Ni-1] | SB[0] ... SB[Nsb-1] | Resource Names | -// -// Nu - number of uniform buffers -// Ns - number of samplers -// Ni - number of images -// Nsb - number of storage blocks - -#include - -#include "Object.h" -#include "StringPool.h" -#include "HashUtils.h" -#include "ShaderResourceVariableBase.hpp" - -namespace Diligent -{ - -class GLProgramResources -{ -public: - GLProgramResources() {} - ~GLProgramResources(); - // clang-format off - GLProgramResources (GLProgramResources&& Program)noexcept; - - GLProgramResources (const GLProgramResources&) = delete; - GLProgramResources& operator = (const GLProgramResources&) = delete; - GLProgramResources& operator = ( GLProgramResources&&) = delete; - // clang-format on - - /// Loads program uniforms and assigns bindings - void LoadUniforms(SHADER_TYPE ShaderStages, - const GLObjectWrappers::GLProgramObj& GLProgram, - class GLContextState& State, - Uint32& UniformBufferBinding, - Uint32& SamplerBinding, - Uint32& ImageBinding, - Uint32& StorageBufferBinding); - - struct GLResourceAttribs - { - // clang-format off -/* 0 */ const Char* Name; -/* 8 */ const SHADER_TYPE ShaderStages; -/* 12 */ const SHADER_RESOURCE_TYPE ResourceType; -/* 16 */ const Uint32 Binding; -/* 20 */ Uint32 ArraySize; -/* 24 */ // End of data - // clang-format on - - GLResourceAttribs(const Char* _Name, - SHADER_TYPE _ShaderStages, - SHADER_RESOURCE_TYPE _ResourceType, - Uint32 _Binding, - Uint32 _ArraySize) noexcept : - // clang-format off - Name {_Name }, - ShaderStages {_ShaderStages}, - ResourceType {_ResourceType}, - Binding {_Binding }, - ArraySize {_ArraySize } - // clang-format on - { - VERIFY(_ShaderStages != SHADER_TYPE_UNKNOWN, "At least one shader stage must be specified"); - VERIFY(_ResourceType != SHADER_RESOURCE_TYPE_UNKNOWN, "Unknown shader resource type"); - VERIFY(_ArraySize >= 1, "Array size must be greater than 1"); - } - - GLResourceAttribs(const GLResourceAttribs& Attribs, - StringPool& NamesPool) noexcept : - // clang-format off - GLResourceAttribs - { - NamesPool.CopyString(Attribs.Name), - Attribs.ShaderStages, - Attribs.ResourceType, - Attribs.Binding, - Attribs.ArraySize - } - // clang-format on - { - } - - bool IsCompatibleWith(const GLResourceAttribs& Var)const - { - // clang-format off - return ShaderStages == Var.ShaderStages && - ResourceType == Var.ResourceType && - Binding == Var.Binding && - ArraySize == Var.ArraySize; - // clang-format on - } - - size_t GetHash() const - { - return ComputeHash(static_cast(ShaderStages), static_cast(ResourceType), Binding, ArraySize); - } - - String GetPrintName(Uint32 ArrayInd) const - { - VERIFY_EXPR(ArrayInd < ArraySize); - if (ArraySize > 1) - return String(Name) + '[' + std::to_string(ArrayInd) + ']'; - else - return Name; - } - - ShaderResourceDesc GetResourceDesc() const - { - ShaderResourceDesc ResourceDesc; - ResourceDesc.Name = Name; - ResourceDesc.ArraySize = ArraySize; - ResourceDesc.Type = ResourceType; - return ResourceDesc; - } - }; - - struct UniformBufferInfo final : GLResourceAttribs - { - // clang-format off - UniformBufferInfo (const UniformBufferInfo&) = delete; - UniformBufferInfo& operator= (const UniformBufferInfo&) = delete; - UniformBufferInfo ( UniformBufferInfo&&) = default; - UniformBufferInfo& operator= ( UniformBufferInfo&&) = delete; - - UniformBufferInfo(const Char* _Name, - SHADER_TYPE _ShaderStages, - SHADER_RESOURCE_TYPE _ResourceType, - Uint32 _Binding, - Uint32 _ArraySize, - GLuint _UBIndex)noexcept : - GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, - UBIndex {_UBIndex} - {} - - UniformBufferInfo(const UniformBufferInfo& UB, - StringPool& NamesPool)noexcept : - GLResourceAttribs{UB, NamesPool}, - UBIndex {UB.UBIndex } - {} - // clang-format on - - bool IsCompatibleWith(const UniformBufferInfo& UB) const - { - return UBIndex == UB.UBIndex && - GLResourceAttribs::IsCompatibleWith(UB); - } - - size_t GetHash() const - { - return ComputeHash(UBIndex, GLResourceAttribs::GetHash()); - } - - const GLuint UBIndex; - }; - static_assert((sizeof(UniformBufferInfo) % sizeof(void*)) == 0, "sizeof(UniformBufferInfo) must be multiple of sizeof(void*)"); - - - struct SamplerInfo final : GLResourceAttribs - { - // clang-format off - SamplerInfo (const SamplerInfo&) = delete; - SamplerInfo& operator= (const SamplerInfo&) = delete; - SamplerInfo ( SamplerInfo&&) = default; - SamplerInfo& operator= ( SamplerInfo&&) = delete; - - SamplerInfo(const Char* _Name, - SHADER_TYPE _ShaderStages, - SHADER_RESOURCE_TYPE _ResourceType, - Uint32 _Binding, - Uint32 _ArraySize, - GLint _Location, - GLenum _SamplerType)noexcept : - GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, - Location {_Location }, - SamplerType {_SamplerType} - {} - - SamplerInfo(const SamplerInfo& Sam, - StringPool& NamesPool)noexcept : - GLResourceAttribs{Sam, NamesPool}, - Location {Sam.Location }, - SamplerType {Sam.SamplerType} - {} - - bool IsCompatibleWith(const SamplerInfo& Sam)const - { - return Location == Sam.Location && - SamplerType == Sam.SamplerType && - GLResourceAttribs::IsCompatibleWith(Sam); - } - // clang-format on - - size_t GetHash() const - { - return ComputeHash(Location, SamplerType, GLResourceAttribs::GetHash()); - } - - const GLint Location; - const GLenum SamplerType; - }; - static_assert((sizeof(SamplerInfo) % sizeof(void*)) == 0, "sizeof(SamplerInfo) must be multiple of sizeof(void*)"); - - - struct ImageInfo final : GLResourceAttribs - { - // clang-format off - ImageInfo (const ImageInfo&) = delete; - ImageInfo& operator= (const ImageInfo&) = delete; - ImageInfo ( ImageInfo&&) = default; - ImageInfo& operator= ( ImageInfo&&) = delete; - - ImageInfo(const Char* _Name, - SHADER_TYPE _ShaderStages, - SHADER_RESOURCE_TYPE _ResourceType, - Uint32 _Binding, - Uint32 _ArraySize, - GLint _Location, - GLenum _ImageType)noexcept : - GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, - Location {_Location }, - ImageType {_ImageType} - {} - - ImageInfo(const ImageInfo& Img, - StringPool& NamesPool)noexcept : - GLResourceAttribs{Img, NamesPool}, - Location {Img.Location }, - ImageType {Img.ImageType} - {} - - bool IsCompatibleWith(const ImageInfo& Img)const - { - return Location == Img.Location && - ImageType == Img.ImageType && - GLResourceAttribs::IsCompatibleWith(Img); - } - // clang-format on - - size_t GetHash() const - { - return ComputeHash(Location, ImageType, GLResourceAttribs::GetHash()); - } - - const GLint Location; - const GLenum ImageType; - }; - static_assert((sizeof(ImageInfo) % sizeof(void*)) == 0, "sizeof(ImageInfo) must be multiple of sizeof(void*)"); - - - struct StorageBlockInfo final : GLResourceAttribs - { - // clang-format off - StorageBlockInfo (const StorageBlockInfo&) = delete; - StorageBlockInfo& operator= (const StorageBlockInfo&) = delete; - StorageBlockInfo ( StorageBlockInfo&&) = default; - StorageBlockInfo& operator= ( StorageBlockInfo&&) = delete; - - StorageBlockInfo(const Char* _Name, - SHADER_TYPE _ShaderStages, - SHADER_RESOURCE_TYPE _ResourceType, - Uint32 _Binding, - Uint32 _ArraySize, - GLint _SBIndex)noexcept : - GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, - SBIndex {_SBIndex} - {} - - StorageBlockInfo(const StorageBlockInfo& SB, - StringPool& NamesPool)noexcept : - GLResourceAttribs{SB, NamesPool}, - SBIndex {SB.SBIndex} - {} - - bool IsCompatibleWith(const StorageBlockInfo& SB)const - { - return SBIndex == SB.SBIndex && - GLResourceAttribs::IsCompatibleWith(SB); - } - // clang-format on - - size_t GetHash() const - { - return ComputeHash(SBIndex, GLResourceAttribs::GetHash()); - } - - const GLint SBIndex; - }; - static_assert((sizeof(StorageBlockInfo) % sizeof(void*)) == 0, "sizeof(StorageBlockInfo) must be multiple of sizeof(void*)"); - - - // clang-format off - Uint32 GetNumUniformBuffers()const { return m_NumUniformBuffers; } - Uint32 GetNumSamplers() const { return m_NumSamplers; } - Uint32 GetNumImages() const { return m_NumImages; } - Uint32 GetNumStorageBlocks() const { return m_NumStorageBlocks; } - // clang-format on - - UniformBufferInfo& GetUniformBuffer(Uint32 Index) - { - VERIFY(Index < m_NumUniformBuffers, "Uniform buffer index (", Index, ") is out of range"); - return m_UniformBuffers[Index]; - } - - SamplerInfo& GetSampler(Uint32 Index) - { - VERIFY(Index < m_NumSamplers, "Sampler index (", Index, ") is out of range"); - return m_Samplers[Index]; - } - - ImageInfo& GetImage(Uint32 Index) - { - VERIFY(Index < m_NumImages, "Image index (", Index, ") is out of range"); - return m_Images[Index]; - } - - StorageBlockInfo& GetStorageBlock(Uint32 Index) - { - VERIFY(Index < m_NumStorageBlocks, "Storage block index (", Index, ") is out of range"); - return m_StorageBlocks[Index]; - } - - - const UniformBufferInfo& GetUniformBuffer(Uint32 Index) const - { - VERIFY(Index < m_NumUniformBuffers, "Uniform buffer index (", Index, ") is out of range"); - return m_UniformBuffers[Index]; - } - - const SamplerInfo& GetSampler(Uint32 Index) const - { - VERIFY(Index < m_NumSamplers, "Sampler index (", Index, ") is out of range"); - return m_Samplers[Index]; - } - - const ImageInfo& GetImage(Uint32 Index) const - { - VERIFY(Index < m_NumImages, "Image index (", Index, ") is out of range"); - return m_Images[Index]; - } - - const StorageBlockInfo& GetStorageBlock(Uint32 Index) const - { - VERIFY(Index < m_NumStorageBlocks, "Storage block index (", Index, ") is out of range"); - return m_StorageBlocks[Index]; - } - - Uint32 GetVariableCount() const - { - return m_NumUniformBuffers + m_NumSamplers + m_NumImages + m_NumStorageBlocks; - } - - ShaderResourceDesc GetResourceDesc(Uint32 Index) const; - - bool IsCompatibleWith(const GLProgramResources& Res) const; - size_t GetHash() const; - - SHADER_TYPE GetShaderStages() const { return m_ShaderStages; } - - template - void ProcessConstResources(THandleUB HandleUB, - THandleSampler HandleSampler, - THandleImg HandleImg, - THandleSB HandleSB, - const PipelineResourceLayoutDesc* pResourceLayout = nullptr, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes = nullptr, - Uint32 NumAllowedTypes = 0) const - { - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); - - auto CheckResourceType = [&](const char* Name) // - { - if (pResourceLayout == nullptr) - return true; - else - { - auto VarType = GetShaderVariableType(m_ShaderStages, Name, *pResourceLayout); - return IsAllowedType(VarType, AllowedTypeBits); - } - }; - - for (Uint32 ub = 0; ub < m_NumUniformBuffers; ++ub) - { - const auto& UB = GetUniformBuffer(ub); - if (CheckResourceType(UB.Name)) - HandleUB(UB); - } - - for (Uint32 s = 0; s < m_NumSamplers; ++s) - { - const auto& Sam = GetSampler(s); - if (CheckResourceType(Sam.Name)) - HandleSampler(Sam); - } - - for (Uint32 img = 0; img < m_NumImages; ++img) - { - const auto& Img = GetImage(img); - if (CheckResourceType(Img.Name)) - HandleImg(Img); - } - - for (Uint32 sb = 0; sb < m_NumStorageBlocks; ++sb) - { - const auto& SB = GetStorageBlock(sb); - if (CheckResourceType(SB.Name)) - HandleSB(SB); - } - } - - template - void ProcessResources(THandleUB HandleUB, - THandleSampler HandleSampler, - THandleImg HandleImg, - THandleSB HandleSB) - { - for (Uint32 ub = 0; ub < m_NumUniformBuffers; ++ub) - HandleUB(GetUniformBuffer(ub)); - - for (Uint32 s = 0; s < m_NumSamplers; ++s) - HandleSampler(GetSampler(s)); - - for (Uint32 img = 0; img < m_NumImages; ++img) - HandleImg(GetImage(img)); - - for (Uint32 sb = 0; sb < m_NumStorageBlocks; ++sb) - HandleSB(GetStorageBlock(sb)); - } - - struct ResourceCounters - { - Uint32 NumUBs = 0; - Uint32 NumSamplers = 0; - Uint32 NumImages = 0; - Uint32 NumStorageBlocks = 0; - }; - void CountResources(const PipelineResourceLayoutDesc& ResourceLayout, - const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, - Uint32 NumAllowedTypes, - ResourceCounters& Counters) const; - - -private: - void AllocateResources(std::vector& UniformBlocks, - std::vector& Samplers, - std::vector& Images, - std::vector& StorageBlocks); - - // clang-format off - // There could be more than one stage if using non-separable programs - SHADER_TYPE m_ShaderStages = SHADER_TYPE_UNKNOWN; - - // Memory layout: - // - // | Uniform buffers | Samplers | Images | Storage Blocks | String Pool Data | - // - - UniformBufferInfo* m_UniformBuffers = nullptr; - SamplerInfo* m_Samplers = nullptr; - ImageInfo* m_Images = nullptr; - StorageBlockInfo* m_StorageBlocks = nullptr; - - StringPool m_StringPool; - - Uint32 m_NumUniformBuffers = 0; - Uint32 m_NumSamplers = 0; - Uint32 m_NumImages = 0; - Uint32 m_NumStorageBlocks = 0; - // clang-format on - // When adding new member DO NOT FORGET TO UPDATE GLProgramResources( GLProgramResources&& ProgramResources )!!! -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.hpp b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.hpp new file mode 100644 index 00000000..40c64c8e --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.hpp @@ -0,0 +1,513 @@ +/* + * 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 + +// GLProgramResources class allocates single continuous chunk of memory to store all program resources, as follows: +// +// +// m_UniformBuffers m_Samplers m_Images m_StorageBlocks +// | | | | | | +// | UB[0] ... UB[Nu-1] | Sam[0] ... Sam[Ns-1] | Img[0] ... Img[Ni-1] | SB[0] ... SB[Nsb-1] | Resource Names | +// +// Nu - number of uniform buffers +// Ns - number of samplers +// Ni - number of images +// Nsb - number of storage blocks + +#include + +#include "Object.h" +#include "StringPool.h" +#include "HashUtils.h" +#include "ShaderResourceVariableBase.hpp" + +namespace Diligent +{ + +class GLProgramResources +{ +public: + GLProgramResources() {} + ~GLProgramResources(); + // clang-format off + GLProgramResources (GLProgramResources&& Program)noexcept; + + GLProgramResources (const GLProgramResources&) = delete; + GLProgramResources& operator = (const GLProgramResources&) = delete; + GLProgramResources& operator = ( GLProgramResources&&) = delete; + // clang-format on + + /// Loads program uniforms and assigns bindings + void LoadUniforms(SHADER_TYPE ShaderStages, + const GLObjectWrappers::GLProgramObj& GLProgram, + class GLContextState& State, + Uint32& UniformBufferBinding, + Uint32& SamplerBinding, + Uint32& ImageBinding, + Uint32& StorageBufferBinding); + + struct GLResourceAttribs + { + // clang-format off +/* 0 */ const Char* Name; +/* 8 */ const SHADER_TYPE ShaderStages; +/* 12 */ const SHADER_RESOURCE_TYPE ResourceType; +/* 16 */ const Uint32 Binding; +/* 20 */ Uint32 ArraySize; +/* 24 */ // End of data + // clang-format on + + GLResourceAttribs(const Char* _Name, + SHADER_TYPE _ShaderStages, + SHADER_RESOURCE_TYPE _ResourceType, + Uint32 _Binding, + Uint32 _ArraySize) noexcept : + // clang-format off + Name {_Name }, + ShaderStages {_ShaderStages}, + ResourceType {_ResourceType}, + Binding {_Binding }, + ArraySize {_ArraySize } + // clang-format on + { + VERIFY(_ShaderStages != SHADER_TYPE_UNKNOWN, "At least one shader stage must be specified"); + VERIFY(_ResourceType != SHADER_RESOURCE_TYPE_UNKNOWN, "Unknown shader resource type"); + VERIFY(_ArraySize >= 1, "Array size must be greater than 1"); + } + + GLResourceAttribs(const GLResourceAttribs& Attribs, + StringPool& NamesPool) noexcept : + // clang-format off + GLResourceAttribs + { + NamesPool.CopyString(Attribs.Name), + Attribs.ShaderStages, + Attribs.ResourceType, + Attribs.Binding, + Attribs.ArraySize + } + // clang-format on + { + } + + bool IsCompatibleWith(const GLResourceAttribs& Var)const + { + // clang-format off + return ShaderStages == Var.ShaderStages && + ResourceType == Var.ResourceType && + Binding == Var.Binding && + ArraySize == Var.ArraySize; + // clang-format on + } + + size_t GetHash() const + { + return ComputeHash(static_cast(ShaderStages), static_cast(ResourceType), Binding, ArraySize); + } + + String GetPrintName(Uint32 ArrayInd) const + { + VERIFY_EXPR(ArrayInd < ArraySize); + if (ArraySize > 1) + return String(Name) + '[' + std::to_string(ArrayInd) + ']'; + else + return Name; + } + + ShaderResourceDesc GetResourceDesc() const + { + ShaderResourceDesc ResourceDesc; + ResourceDesc.Name = Name; + ResourceDesc.ArraySize = ArraySize; + ResourceDesc.Type = ResourceType; + return ResourceDesc; + } + }; + + struct UniformBufferInfo final : GLResourceAttribs + { + // clang-format off + UniformBufferInfo (const UniformBufferInfo&) = delete; + UniformBufferInfo& operator= (const UniformBufferInfo&) = delete; + UniformBufferInfo ( UniformBufferInfo&&) = default; + UniformBufferInfo& operator= ( UniformBufferInfo&&) = delete; + + UniformBufferInfo(const Char* _Name, + SHADER_TYPE _ShaderStages, + SHADER_RESOURCE_TYPE _ResourceType, + Uint32 _Binding, + Uint32 _ArraySize, + GLuint _UBIndex)noexcept : + GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, + UBIndex {_UBIndex} + {} + + UniformBufferInfo(const UniformBufferInfo& UB, + StringPool& NamesPool)noexcept : + GLResourceAttribs{UB, NamesPool}, + UBIndex {UB.UBIndex } + {} + // clang-format on + + bool IsCompatibleWith(const UniformBufferInfo& UB) const + { + return UBIndex == UB.UBIndex && + GLResourceAttribs::IsCompatibleWith(UB); + } + + size_t GetHash() const + { + return ComputeHash(UBIndex, GLResourceAttribs::GetHash()); + } + + const GLuint UBIndex; + }; + static_assert((sizeof(UniformBufferInfo) % sizeof(void*)) == 0, "sizeof(UniformBufferInfo) must be multiple of sizeof(void*)"); + + + struct SamplerInfo final : GLResourceAttribs + { + // clang-format off + SamplerInfo (const SamplerInfo&) = delete; + SamplerInfo& operator= (const SamplerInfo&) = delete; + SamplerInfo ( SamplerInfo&&) = default; + SamplerInfo& operator= ( SamplerInfo&&) = delete; + + SamplerInfo(const Char* _Name, + SHADER_TYPE _ShaderStages, + SHADER_RESOURCE_TYPE _ResourceType, + Uint32 _Binding, + Uint32 _ArraySize, + GLint _Location, + GLenum _SamplerType)noexcept : + GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, + Location {_Location }, + SamplerType {_SamplerType} + {} + + SamplerInfo(const SamplerInfo& Sam, + StringPool& NamesPool)noexcept : + GLResourceAttribs{Sam, NamesPool}, + Location {Sam.Location }, + SamplerType {Sam.SamplerType} + {} + + bool IsCompatibleWith(const SamplerInfo& Sam)const + { + return Location == Sam.Location && + SamplerType == Sam.SamplerType && + GLResourceAttribs::IsCompatibleWith(Sam); + } + // clang-format on + + size_t GetHash() const + { + return ComputeHash(Location, SamplerType, GLResourceAttribs::GetHash()); + } + + const GLint Location; + const GLenum SamplerType; + }; + static_assert((sizeof(SamplerInfo) % sizeof(void*)) == 0, "sizeof(SamplerInfo) must be multiple of sizeof(void*)"); + + + struct ImageInfo final : GLResourceAttribs + { + // clang-format off + ImageInfo (const ImageInfo&) = delete; + ImageInfo& operator= (const ImageInfo&) = delete; + ImageInfo ( ImageInfo&&) = default; + ImageInfo& operator= ( ImageInfo&&) = delete; + + ImageInfo(const Char* _Name, + SHADER_TYPE _ShaderStages, + SHADER_RESOURCE_TYPE _ResourceType, + Uint32 _Binding, + Uint32 _ArraySize, + GLint _Location, + GLenum _ImageType)noexcept : + GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, + Location {_Location }, + ImageType {_ImageType} + {} + + ImageInfo(const ImageInfo& Img, + StringPool& NamesPool)noexcept : + GLResourceAttribs{Img, NamesPool}, + Location {Img.Location }, + ImageType {Img.ImageType} + {} + + bool IsCompatibleWith(const ImageInfo& Img)const + { + return Location == Img.Location && + ImageType == Img.ImageType && + GLResourceAttribs::IsCompatibleWith(Img); + } + // clang-format on + + size_t GetHash() const + { + return ComputeHash(Location, ImageType, GLResourceAttribs::GetHash()); + } + + const GLint Location; + const GLenum ImageType; + }; + static_assert((sizeof(ImageInfo) % sizeof(void*)) == 0, "sizeof(ImageInfo) must be multiple of sizeof(void*)"); + + + struct StorageBlockInfo final : GLResourceAttribs + { + // clang-format off + StorageBlockInfo (const StorageBlockInfo&) = delete; + StorageBlockInfo& operator= (const StorageBlockInfo&) = delete; + StorageBlockInfo ( StorageBlockInfo&&) = default; + StorageBlockInfo& operator= ( StorageBlockInfo&&) = delete; + + StorageBlockInfo(const Char* _Name, + SHADER_TYPE _ShaderStages, + SHADER_RESOURCE_TYPE _ResourceType, + Uint32 _Binding, + Uint32 _ArraySize, + GLint _SBIndex)noexcept : + GLResourceAttribs{_Name, _ShaderStages, _ResourceType, _Binding, _ArraySize}, + SBIndex {_SBIndex} + {} + + StorageBlockInfo(const StorageBlockInfo& SB, + StringPool& NamesPool)noexcept : + GLResourceAttribs{SB, NamesPool}, + SBIndex {SB.SBIndex} + {} + + bool IsCompatibleWith(const StorageBlockInfo& SB)const + { + return SBIndex == SB.SBIndex && + GLResourceAttribs::IsCompatibleWith(SB); + } + // clang-format on + + size_t GetHash() const + { + return ComputeHash(SBIndex, GLResourceAttribs::GetHash()); + } + + const GLint SBIndex; + }; + static_assert((sizeof(StorageBlockInfo) % sizeof(void*)) == 0, "sizeof(StorageBlockInfo) must be multiple of sizeof(void*)"); + + + // clang-format off + Uint32 GetNumUniformBuffers()const { return m_NumUniformBuffers; } + Uint32 GetNumSamplers() const { return m_NumSamplers; } + Uint32 GetNumImages() const { return m_NumImages; } + Uint32 GetNumStorageBlocks() const { return m_NumStorageBlocks; } + // clang-format on + + UniformBufferInfo& GetUniformBuffer(Uint32 Index) + { + VERIFY(Index < m_NumUniformBuffers, "Uniform buffer index (", Index, ") is out of range"); + return m_UniformBuffers[Index]; + } + + SamplerInfo& GetSampler(Uint32 Index) + { + VERIFY(Index < m_NumSamplers, "Sampler index (", Index, ") is out of range"); + return m_Samplers[Index]; + } + + ImageInfo& GetImage(Uint32 Index) + { + VERIFY(Index < m_NumImages, "Image index (", Index, ") is out of range"); + return m_Images[Index]; + } + + StorageBlockInfo& GetStorageBlock(Uint32 Index) + { + VERIFY(Index < m_NumStorageBlocks, "Storage block index (", Index, ") is out of range"); + return m_StorageBlocks[Index]; + } + + + const UniformBufferInfo& GetUniformBuffer(Uint32 Index) const + { + VERIFY(Index < m_NumUniformBuffers, "Uniform buffer index (", Index, ") is out of range"); + return m_UniformBuffers[Index]; + } + + const SamplerInfo& GetSampler(Uint32 Index) const + { + VERIFY(Index < m_NumSamplers, "Sampler index (", Index, ") is out of range"); + return m_Samplers[Index]; + } + + const ImageInfo& GetImage(Uint32 Index) const + { + VERIFY(Index < m_NumImages, "Image index (", Index, ") is out of range"); + return m_Images[Index]; + } + + const StorageBlockInfo& GetStorageBlock(Uint32 Index) const + { + VERIFY(Index < m_NumStorageBlocks, "Storage block index (", Index, ") is out of range"); + return m_StorageBlocks[Index]; + } + + Uint32 GetVariableCount() const + { + return m_NumUniformBuffers + m_NumSamplers + m_NumImages + m_NumStorageBlocks; + } + + ShaderResourceDesc GetResourceDesc(Uint32 Index) const; + + bool IsCompatibleWith(const GLProgramResources& Res) const; + size_t GetHash() const; + + SHADER_TYPE GetShaderStages() const { return m_ShaderStages; } + + template + void ProcessConstResources(THandleUB HandleUB, + THandleSampler HandleSampler, + THandleImg HandleImg, + THandleSB HandleSB, + const PipelineResourceLayoutDesc* pResourceLayout = nullptr, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes = nullptr, + Uint32 NumAllowedTypes = 0) const + { + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + + auto CheckResourceType = [&](const char* Name) // + { + if (pResourceLayout == nullptr) + return true; + else + { + auto VarType = GetShaderVariableType(m_ShaderStages, Name, *pResourceLayout); + return IsAllowedType(VarType, AllowedTypeBits); + } + }; + + for (Uint32 ub = 0; ub < m_NumUniformBuffers; ++ub) + { + const auto& UB = GetUniformBuffer(ub); + if (CheckResourceType(UB.Name)) + HandleUB(UB); + } + + for (Uint32 s = 0; s < m_NumSamplers; ++s) + { + const auto& Sam = GetSampler(s); + if (CheckResourceType(Sam.Name)) + HandleSampler(Sam); + } + + for (Uint32 img = 0; img < m_NumImages; ++img) + { + const auto& Img = GetImage(img); + if (CheckResourceType(Img.Name)) + HandleImg(Img); + } + + for (Uint32 sb = 0; sb < m_NumStorageBlocks; ++sb) + { + const auto& SB = GetStorageBlock(sb); + if (CheckResourceType(SB.Name)) + HandleSB(SB); + } + } + + template + void ProcessResources(THandleUB HandleUB, + THandleSampler HandleSampler, + THandleImg HandleImg, + THandleSB HandleSB) + { + for (Uint32 ub = 0; ub < m_NumUniformBuffers; ++ub) + HandleUB(GetUniformBuffer(ub)); + + for (Uint32 s = 0; s < m_NumSamplers; ++s) + HandleSampler(GetSampler(s)); + + for (Uint32 img = 0; img < m_NumImages; ++img) + HandleImg(GetImage(img)); + + for (Uint32 sb = 0; sb < m_NumStorageBlocks; ++sb) + HandleSB(GetStorageBlock(sb)); + } + + struct ResourceCounters + { + Uint32 NumUBs = 0; + Uint32 NumSamplers = 0; + Uint32 NumImages = 0; + Uint32 NumStorageBlocks = 0; + }; + void CountResources(const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes, + ResourceCounters& Counters) const; + + +private: + void AllocateResources(std::vector& UniformBlocks, + std::vector& Samplers, + std::vector& Images, + std::vector& StorageBlocks); + + // clang-format off + // There could be more than one stage if using non-separable programs + SHADER_TYPE m_ShaderStages = SHADER_TYPE_UNKNOWN; + + // Memory layout: + // + // | Uniform buffers | Samplers | Images | Storage Blocks | String Pool Data | + // + + UniformBufferInfo* m_UniformBuffers = nullptr; + SamplerInfo* m_Samplers = nullptr; + ImageInfo* m_Images = nullptr; + StorageBlockInfo* m_StorageBlocks = nullptr; + + StringPool m_StringPool; + + Uint32 m_NumUniformBuffers = 0; + Uint32 m_NumSamplers = 0; + Uint32 m_NumImages = 0; + Uint32 m_NumStorageBlocks = 0; + // clang-format on + // When adding new member DO NOT FORGET TO UPDATE GLProgramResources( GLProgramResources&& ProgramResources )!!! +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h deleted file mode 100644 index 1893f2c7..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h +++ /dev/null @@ -1,123 +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 "PipelineStateGL.h" -#include "PipelineStateBase.hpp" -#include "RenderDevice.h" -#include "GLObjectWrapper.h" -#include "GLContext.h" -#include "RenderDeviceGLImpl.h" -#include "GLProgramResources.h" -#include "GLPipelineResourceLayout.h" -#include "GLProgramResourceCache.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Pipeline state object implementation in OpenGL backend. -class PipelineStateGLImpl final : public PipelineStateBase -{ -public: - using TPipelineStateBase = PipelineStateBase; - - PipelineStateGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDeviceGL, - const PipelineStateDesc& PipelineDesc, - bool IsDeviceInternal = false); - ~PipelineStateGLImpl(); - - /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; - - /// Implementation of IPipelineState::BindStaticResources() in OpenGL backend. - virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) override final; - - /// Implementation of IPipelineState::GetStaticVariableCount() in OpenGL backend. - virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; - - /// Implementation of IPipelineState::GetStaticVariableByName() in OpenGL backend. - virtual IShaderResourceVariable* GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) override final; - - /// Implementation of IPipelineState::GetStaticVariableByIndex() in OpenGL backend. - virtual IShaderResourceVariable* GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; - - /// Implementation of IPipelineState::CreateShaderResourceBinding() in OpenGL backend. - virtual void CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) override final; - - /// Implementation of IPipelineState::IsCompatibleWith() in OpenGL backend. - virtual bool IsCompatibleWith(const IPipelineState* pPSO) const override final; - - void CommitProgram(GLContextState& State); - - void InitializeSRBResourceCache(GLProgramResourceCache& ResourceCache) const; - - const GLPipelineResourceLayout& GetResourceLayout() const { return m_ResourceLayout; } - const GLPipelineResourceLayout& GetStaticResourceLayout() const { return m_StaticResourceLayout; } - const GLProgramResourceCache& GetStaticResourceCache() const { return m_StaticResourceCache; } - -private: - GLObjectWrappers::GLPipelineObj& GetGLProgramPipeline(GLContext::NativeGLContextType Context); - - void InitStaticSamplersInResourceCache(const GLPipelineResourceLayout& ResourceLayout, GLProgramResourceCache& Cache) const; - - // Linked GL programs for every shader stage. Every pipeline needs to have its own programs - // because resource bindings assigned by GLProgramResources::LoadUniforms depend on other - // shader stages. - std::vector m_GLPrograms; - - ThreadingTools::LockFlag m_ProgPipelineLockFlag; - - std::vector> m_GLProgPipelines; - - // Resource layout that keeps variables of all types, but does not reference a - // resource cache. - // This layout is used by SRB objects to initialize only mutable and dynamic variables and by - // DeviceContextGLImpl::BindProgramResources to verify resource bindings. - GLPipelineResourceLayout m_ResourceLayout; - - // Resource layout that only keeps static variables - GLPipelineResourceLayout m_StaticResourceLayout; - // Resource cache for static resource variables only - GLProgramResourceCache m_StaticResourceCache; - - // Program resources for all shader stages in the pipeline - std::vector m_ProgramResources; - - Uint32 m_TotalUniformBufferBindings = 0; - Uint32 m_TotalSamplerBindings = 0; - Uint32 m_TotalImageBindings = 0; - Uint32 m_TotalStorageBufferBindings = 0; - - std::vector> m_StaticSamplers; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp new file mode 100644 index 00000000..f6ab7b0c --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp @@ -0,0 +1,123 @@ +/* + * 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 "PipelineStateGL.h" +#include "PipelineStateBase.hpp" +#include "RenderDevice.h" +#include "GLObjectWrapper.hpp" +#include "GLContext.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "GLProgramResources.hpp" +#include "GLPipelineResourceLayout.hpp" +#include "GLProgramResourceCache.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Pipeline state object implementation in OpenGL backend. +class PipelineStateGLImpl final : public PipelineStateBase +{ +public: + using TPipelineStateBase = PipelineStateBase; + + PipelineStateGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDeviceGL, + const PipelineStateDesc& PipelineDesc, + bool IsDeviceInternal = false); + ~PipelineStateGLImpl(); + + /// Queries the specific interface, see IObject::QueryInterface() for details + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; + + /// Implementation of IPipelineState::BindStaticResources() in OpenGL backend. + virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) override final; + + /// Implementation of IPipelineState::GetStaticVariableCount() in OpenGL backend. + virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; + + /// Implementation of IPipelineState::GetStaticVariableByName() in OpenGL backend. + virtual IShaderResourceVariable* GetStaticVariableByName(SHADER_TYPE ShaderType, const Char* Name) override final; + + /// Implementation of IPipelineState::GetStaticVariableByIndex() in OpenGL backend. + virtual IShaderResourceVariable* GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; + + /// Implementation of IPipelineState::CreateShaderResourceBinding() in OpenGL backend. + virtual void CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) override final; + + /// Implementation of IPipelineState::IsCompatibleWith() in OpenGL backend. + virtual bool IsCompatibleWith(const IPipelineState* pPSO) const override final; + + void CommitProgram(GLContextState& State); + + void InitializeSRBResourceCache(GLProgramResourceCache& ResourceCache) const; + + const GLPipelineResourceLayout& GetResourceLayout() const { return m_ResourceLayout; } + const GLPipelineResourceLayout& GetStaticResourceLayout() const { return m_StaticResourceLayout; } + const GLProgramResourceCache& GetStaticResourceCache() const { return m_StaticResourceCache; } + +private: + GLObjectWrappers::GLPipelineObj& GetGLProgramPipeline(GLContext::NativeGLContextType Context); + + void InitStaticSamplersInResourceCache(const GLPipelineResourceLayout& ResourceLayout, GLProgramResourceCache& Cache) const; + + // Linked GL programs for every shader stage. Every pipeline needs to have its own programs + // because resource bindings assigned by GLProgramResources::LoadUniforms depend on other + // shader stages. + std::vector m_GLPrograms; + + ThreadingTools::LockFlag m_ProgPipelineLockFlag; + + std::vector> m_GLProgPipelines; + + // Resource layout that keeps variables of all types, but does not reference a + // resource cache. + // This layout is used by SRB objects to initialize only mutable and dynamic variables and by + // DeviceContextGLImpl::BindProgramResources to verify resource bindings. + GLPipelineResourceLayout m_ResourceLayout; + + // Resource layout that only keeps static variables + GLPipelineResourceLayout m_StaticResourceLayout; + // Resource cache for static resource variables only + GLProgramResourceCache m_StaticResourceCache; + + // Program resources for all shader stages in the pipeline + std::vector m_ProgramResources; + + Uint32 m_TotalUniformBufferBindings = 0; + Uint32 m_TotalSamplerBindings = 0; + Uint32 m_TotalImageBindings = 0; + Uint32 m_TotalStorageBufferBindings = 0; + + std::vector> m_StaticSamplers; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.h deleted file mode 100644 index 4725db86..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.h +++ /dev/null @@ -1,71 +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 -/// Declaration of Diligent::QueryGLImpl class - -#include "QueryGL.h" -#include "RenderDeviceGL.h" -#include "QueryBase.hpp" -#include "GLObjectWrapper.h" -#include "RenderDeviceGLImpl.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Query object implementation in OpenGL backend. -class QueryGLImpl final : public QueryBase -{ -public: - using TQueryBase = QueryBase; - - QueryGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDevice, - const QueryDesc& Desc); - ~QueryGLImpl(); - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_QueryGL, TQueryBase); - - /// Implementation of IQuery::GetData() in OpenGL backend. - virtual bool GetData(void* pData, Uint32 DataSize, bool AutoInvalidate) override final; - - - /// Implementation of IQueryGL::GetGlQueryHandle(). - virtual GLuint GetGlQueryHandle() const override final - { - return m_GlQuery; - } - -private: - GLObjectWrappers::GLQueryObj m_GlQuery; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.hpp new file mode 100644 index 00000000..ab2170b9 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/QueryGLImpl.hpp @@ -0,0 +1,71 @@ +/* + * 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 +/// Declaration of Diligent::QueryGLImpl class + +#include "QueryGL.h" +#include "RenderDeviceGL.h" +#include "QueryBase.hpp" +#include "GLObjectWrapper.hpp" +#include "RenderDeviceGLImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Query object implementation in OpenGL backend. +class QueryGLImpl final : public QueryBase +{ +public: + using TQueryBase = QueryBase; + + QueryGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDevice, + const QueryDesc& Desc); + ~QueryGLImpl(); + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_QueryGL, TQueryBase); + + /// Implementation of IQuery::GetData() in OpenGL backend. + virtual bool GetData(void* pData, Uint32 DataSize, bool AutoInvalidate) override final; + + + /// Implementation of IQueryGL::GetGlQueryHandle(). + virtual GLuint GetGlQueryHandle() const override final + { + return m_GlQuery; + } + +private: + GLObjectWrappers::GLQueryObj m_GlQuery; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h deleted file mode 100644 index b5dcfa80..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h +++ /dev/null @@ -1,157 +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 "RenderDeviceBase.hpp" -#include "GLContext.h" -#include "VAOCache.h" -#include "BaseInterfacesGL.h" -#include "FBOCache.h" -#include "TexRegionRender.h" - -enum class GPU_VENDOR -{ - UNKNOWN, - INTEL, - ATI, - NVIDIA, - QUALCOMM -}; - -struct GPUInfo -{ - GPU_VENDOR Vendor = GPU_VENDOR::UNKNOWN; -}; - -namespace Diligent -{ - -/// Render device implementation in OpenGL backend. -// RenderDeviceGLESImpl is inherited from RenderDeviceGLImpl -class RenderDeviceGLImpl : public RenderDeviceBase -{ -public: - using TRenderDeviceBase = RenderDeviceBase; - - RenderDeviceGLImpl(IReferenceCounters* pRefCounters, - IMemoryAllocator& RawMemAllocator, - IEngineFactory* pEngineFactory, - const EngineGLCreateInfo& InitAttribs, - const SwapChainDesc* pSCDesc = nullptr); - ~RenderDeviceGLImpl(); - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; - - /// Implementation of IRenderDevice::CreateBuffer() in OpenGL backend. - void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer, bool bIsDeviceInternal); - virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* BuffData, IBuffer** ppBuffer) override final; - - /// Implementation of IRenderDevice::CreateShader() in OpenGL backend. - void CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader** ppShader, bool bIsDeviceInternal); - virtual void CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader** ppShader) override final; - - /// Implementation of IRenderDevice::CreateTexture() in OpenGL backend. - void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture, bool bIsDeviceInternal); - virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* Data, ITexture** ppTexture) override final; - - /// Implementation of IRenderDevice::CreateSampler() in OpenGL backend. - void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler, bool bIsDeviceInternal); - virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler) override final; - - /// Implementation of IRenderDevice::CreatePipelineState() in OpenGL backend. - void CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState, bool bIsDeviceInternal); - virtual void CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState) override final; - - /// Implementation of IRenderDevice::CreateFence() in OpenGL backend. - virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence) override final; - - /// Implementation of IRenderDevice::CreateQuery() in OpenGL backend. - virtual void CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) override final; - - /// Implementation of IRenderDeviceGL::CreateTextureFromGLHandle(). - virtual void CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; - - /// Implementation of IRenderDeviceGL::CreateBufferFromGLHandle(). - virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer) override final; - - /// Implementation of IRenderDeviceGL::CreateDummyTexture(). - virtual void CreateDummyTexture(const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; - - /// Implementation of IRenderDevice::ReleaseStaleResources() in OpenGL backend. - virtual void ReleaseStaleResources(bool ForceRelease = false) override final {} - - /// Implementation of IRenderDevice::IdleGPU() in OpenGL backend. - virtual void IdleGPU() override final; - - const GPUInfo& GetGPUInfo() { return m_GPUInfo; } - - FBOCache& GetFBOCache(GLContext::NativeGLContextType Context); - void OnReleaseTexture(ITexture* pTexture); - - VAOCache& GetVAOCache(GLContext::NativeGLContextType Context); - void OnDestroyPSO(IPipelineState* pPSO); - void OnDestroyBuffer(IBuffer* pBuffer); - - size_t GetCommandQueueCount() const { return 1; } - Uint64 GetCommandQueueMask() const { return Uint64{1}; } - - void InitTexRegionRender(); - -protected: - friend class DeviceContextGLImpl; - friend class TextureBaseGL; - friend class PipelineStateGLImpl; - friend class ShaderGLImpl; - friend class BufferGLImpl; - friend class TextureViewGLImpl; - friend class SwapChainGLImpl; - friend class GLContextState; - - // Must be the first member because its constructor initializes OpenGL - GLContext m_GLContext; - - std::unordered_set m_ExtensionStrings; - - ThreadingTools::LockFlag m_VAOCacheLockFlag; - std::unordered_map m_VAOCache; - - ThreadingTools::LockFlag m_FBOCacheLockFlag; - std::unordered_map m_FBOCache; - - GPUInfo m_GPUInfo; - - std::unique_ptr m_pTexRegionRender; - -private: - virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final; - bool CheckExtension(const Char* ExtensionString); - void FlagSupportedTexFormats(); - void QueryDeviceCaps(); -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp new file mode 100644 index 00000000..94e0c87c --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp @@ -0,0 +1,157 @@ +/* + * 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 "RenderDeviceBase.hpp" +#include "GLContext.hpp" +#include "VAOCache.hpp" +#include "BaseInterfacesGL.h" +#include "FBOCache.hpp" +#include "TexRegionRender.hpp" + +enum class GPU_VENDOR +{ + UNKNOWN, + INTEL, + ATI, + NVIDIA, + QUALCOMM +}; + +struct GPUInfo +{ + GPU_VENDOR Vendor = GPU_VENDOR::UNKNOWN; +}; + +namespace Diligent +{ + +/// Render device implementation in OpenGL backend. +// RenderDeviceGLESImpl is inherited from RenderDeviceGLImpl +class RenderDeviceGLImpl : public RenderDeviceBase +{ +public: + using TRenderDeviceBase = RenderDeviceBase; + + RenderDeviceGLImpl(IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, + IEngineFactory* pEngineFactory, + const EngineGLCreateInfo& InitAttribs, + const SwapChainDesc* pSCDesc = nullptr); + ~RenderDeviceGLImpl(); + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; + + /// Implementation of IRenderDevice::CreateBuffer() in OpenGL backend. + void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer, bool bIsDeviceInternal); + virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* BuffData, IBuffer** ppBuffer) override final; + + /// Implementation of IRenderDevice::CreateShader() in OpenGL backend. + void CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader** ppShader, bool bIsDeviceInternal); + virtual void CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader** ppShader) override final; + + /// Implementation of IRenderDevice::CreateTexture() in OpenGL backend. + void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture, bool bIsDeviceInternal); + virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* Data, ITexture** ppTexture) override final; + + /// Implementation of IRenderDevice::CreateSampler() in OpenGL backend. + void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler, bool bIsDeviceInternal); + virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler) override final; + + /// Implementation of IRenderDevice::CreatePipelineState() in OpenGL backend. + void CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState, bool bIsDeviceInternal); + virtual void CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState** ppPipelineState) override final; + + /// Implementation of IRenderDevice::CreateFence() in OpenGL backend. + virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence) override final; + + /// Implementation of IRenderDevice::CreateQuery() in OpenGL backend. + virtual void CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) override final; + + /// Implementation of IRenderDeviceGL::CreateTextureFromGLHandle(). + virtual void CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; + + /// Implementation of IRenderDeviceGL::CreateBufferFromGLHandle(). + virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer) override final; + + /// Implementation of IRenderDeviceGL::CreateDummyTexture(). + virtual void CreateDummyTexture(const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture) override final; + + /// Implementation of IRenderDevice::ReleaseStaleResources() in OpenGL backend. + virtual void ReleaseStaleResources(bool ForceRelease = false) override final {} + + /// Implementation of IRenderDevice::IdleGPU() in OpenGL backend. + virtual void IdleGPU() override final; + + const GPUInfo& GetGPUInfo() { return m_GPUInfo; } + + FBOCache& GetFBOCache(GLContext::NativeGLContextType Context); + void OnReleaseTexture(ITexture* pTexture); + + VAOCache& GetVAOCache(GLContext::NativeGLContextType Context); + void OnDestroyPSO(IPipelineState* pPSO); + void OnDestroyBuffer(IBuffer* pBuffer); + + size_t GetCommandQueueCount() const { return 1; } + Uint64 GetCommandQueueMask() const { return Uint64{1}; } + + void InitTexRegionRender(); + +protected: + friend class DeviceContextGLImpl; + friend class TextureBaseGL; + friend class PipelineStateGLImpl; + friend class ShaderGLImpl; + friend class BufferGLImpl; + friend class TextureViewGLImpl; + friend class SwapChainGLImpl; + friend class GLContextState; + + // Must be the first member because its constructor initializes OpenGL + GLContext m_GLContext; + + std::unordered_set m_ExtensionStrings; + + ThreadingTools::LockFlag m_VAOCacheLockFlag; + std::unordered_map m_VAOCache; + + ThreadingTools::LockFlag m_FBOCacheLockFlag; + std::unordered_map m_FBOCache; + + GPUInfo m_GPUInfo; + + std::unique_ptr m_pTexRegionRender; + +private: + virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final; + bool CheckExtension(const Char* ExtensionString); + void FlagSupportedTexFormats(); + void QueryDeviceCaps(); +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.h deleted file mode 100644 index 23c94545..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.h +++ /dev/null @@ -1,59 +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 "BaseInterfacesGL.h" -#include "SamplerGL.h" -#include "SamplerBase.hpp" -#include "RenderDevice.h" -#include "GLObjectWrapper.h" -#include "RenderDeviceGLImpl.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Sampler implementation in OpenGL backend. -class SamplerGLImpl final : public SamplerBase -{ -public: - using TSamplerBase = SamplerBase; - - SamplerGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDeviceGL, const SamplerDesc& SamplerDesc, bool bIsDeviceInternal = false); - ~SamplerGLImpl(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - const GLObjectWrappers::GLSamplerObj& GetHandle() { return m_GlSampler; } - -private: - GLObjectWrappers::GLSamplerObj m_GlSampler; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.hpp new file mode 100644 index 00000000..4460b975 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/SamplerGLImpl.hpp @@ -0,0 +1,59 @@ +/* + * 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 "BaseInterfacesGL.h" +#include "SamplerGL.h" +#include "SamplerBase.hpp" +#include "RenderDevice.h" +#include "GLObjectWrapper.hpp" +#include "RenderDeviceGLImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Sampler implementation in OpenGL backend. +class SamplerGLImpl final : public SamplerBase +{ +public: + using TSamplerBase = SamplerBase; + + SamplerGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDeviceGL, const SamplerDesc& SamplerDesc, bool bIsDeviceInternal = false); + ~SamplerGLImpl(); + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + const GLObjectWrappers::GLSamplerObj& GetHandle() { return m_GlSampler; } + +private: + GLObjectWrappers::GLSamplerObj m_GlSampler; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h deleted file mode 100644 index 5a855e18..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h +++ /dev/null @@ -1,102 +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 "BaseInterfacesGL.h" -#include "ShaderGL.h" -#include "ShaderBase.hpp" -#include "RenderDevice.h" -#include "GLObjectWrapper.h" -#include "RenderDeviceGLImpl.h" -#include "GLProgramResources.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -inline GLenum GetGLShaderType(SHADER_TYPE ShaderType) -{ - switch (ShaderType) - { - // clang-format off - case SHADER_TYPE_VERTEX: return GL_VERTEX_SHADER; break; - case SHADER_TYPE_PIXEL: return GL_FRAGMENT_SHADER; break; - case SHADER_TYPE_GEOMETRY: return GL_GEOMETRY_SHADER; break; - case SHADER_TYPE_HULL: return GL_TESS_CONTROL_SHADER; break; - case SHADER_TYPE_DOMAIN: return GL_TESS_EVALUATION_SHADER; break; - case SHADER_TYPE_COMPUTE: return GL_COMPUTE_SHADER; break; - default: return 0; - // clang-format on - } -} - -inline GLenum ShaderTypeToGLShaderBit(SHADER_TYPE ShaderType) -{ - switch (ShaderType) - { - // clang-format off - case SHADER_TYPE_VERTEX: return GL_VERTEX_SHADER_BIT; break; - case SHADER_TYPE_PIXEL: return GL_FRAGMENT_SHADER_BIT; break; - case SHADER_TYPE_GEOMETRY: return GL_GEOMETRY_SHADER_BIT; break; - case SHADER_TYPE_HULL: return GL_TESS_CONTROL_SHADER_BIT; break; - case SHADER_TYPE_DOMAIN: return GL_TESS_EVALUATION_SHADER_BIT; break; - case SHADER_TYPE_COMPUTE: return GL_COMPUTE_SHADER_BIT; break; - default: return 0; - // clang-format on - } -} - -/// Shader object implementation in OpenGL backend. -class ShaderGLImpl final : public ShaderBase -{ -public: - using TShaderBase = ShaderBase; - - ShaderGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDeviceGL, - const ShaderCreateInfo& ShaderCreateInfo, - bool bIsDeviceInternal = false); - ~ShaderGLImpl(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - /// Implementation of IShader::GetResourceCount() in OpenGL backend. - virtual Uint32 GetResourceCount() const override final; - - /// Implementation of IShader::GetResource() in OpenGL backend. - virtual void GetResourceDesc(Uint32 Index, ShaderResourceDesc& ResourceDesc) const override final; - - static GLObjectWrappers::GLProgramObj LinkProgram(IShader** ppShaders, Uint32 NumShaders, bool IsSeparableProgram); - -private: - GLObjectWrappers::GLShaderObj m_GLShaderObj; - GLProgramResources m_Resources; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp new file mode 100644 index 00000000..8f9769f7 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp @@ -0,0 +1,102 @@ +/* + * 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 "BaseInterfacesGL.h" +#include "ShaderGL.h" +#include "ShaderBase.hpp" +#include "RenderDevice.h" +#include "GLObjectWrapper.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "GLProgramResources.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +inline GLenum GetGLShaderType(SHADER_TYPE ShaderType) +{ + switch (ShaderType) + { + // clang-format off + case SHADER_TYPE_VERTEX: return GL_VERTEX_SHADER; break; + case SHADER_TYPE_PIXEL: return GL_FRAGMENT_SHADER; break; + case SHADER_TYPE_GEOMETRY: return GL_GEOMETRY_SHADER; break; + case SHADER_TYPE_HULL: return GL_TESS_CONTROL_SHADER; break; + case SHADER_TYPE_DOMAIN: return GL_TESS_EVALUATION_SHADER; break; + case SHADER_TYPE_COMPUTE: return GL_COMPUTE_SHADER; break; + default: return 0; + // clang-format on + } +} + +inline GLenum ShaderTypeToGLShaderBit(SHADER_TYPE ShaderType) +{ + switch (ShaderType) + { + // clang-format off + case SHADER_TYPE_VERTEX: return GL_VERTEX_SHADER_BIT; break; + case SHADER_TYPE_PIXEL: return GL_FRAGMENT_SHADER_BIT; break; + case SHADER_TYPE_GEOMETRY: return GL_GEOMETRY_SHADER_BIT; break; + case SHADER_TYPE_HULL: return GL_TESS_CONTROL_SHADER_BIT; break; + case SHADER_TYPE_DOMAIN: return GL_TESS_EVALUATION_SHADER_BIT; break; + case SHADER_TYPE_COMPUTE: return GL_COMPUTE_SHADER_BIT; break; + default: return 0; + // clang-format on + } +} + +/// Shader object implementation in OpenGL backend. +class ShaderGLImpl final : public ShaderBase +{ +public: + using TShaderBase = ShaderBase; + + ShaderGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDeviceGL, + const ShaderCreateInfo& ShaderCreateInfo, + bool bIsDeviceInternal = false); + ~ShaderGLImpl(); + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + /// Implementation of IShader::GetResourceCount() in OpenGL backend. + virtual Uint32 GetResourceCount() const override final; + + /// Implementation of IShader::GetResource() in OpenGL backend. + virtual void GetResourceDesc(Uint32 Index, ShaderResourceDesc& ResourceDesc) const override final; + + static GLObjectWrappers::GLProgramObj LinkProgram(IShader** ppShaders, Uint32 NumShaders, bool IsSeparableProgram); + +private: + GLObjectWrappers::GLShaderObj m_GLShaderObj; + GLProgramResources m_Resources; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.h deleted file mode 100644 index 46b4ebd1..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.h +++ /dev/null @@ -1,88 +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 -/// Declaration of Diligent::ShaderResourceBindingGLImpl class - -#include "ShaderResourceBindingGL.h" -#include "RenderDeviceGL.h" -#include "ShaderResourceBindingBase.hpp" -#include "GLProgramResources.h" -#include "ShaderBase.hpp" -#include "GLProgramResourceCache.h" -#include "GLPipelineResourceLayout.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; -class PipelineStateGLImpl; - -/// Shader resource binding object implementation in OpenGL backend. -class ShaderResourceBindingGLImpl final : public ShaderResourceBindingBase -{ -public: - using TBase = ShaderResourceBindingBase; - - ShaderResourceBindingGLImpl(IReferenceCounters* pRefCounters, - PipelineStateGLImpl* pPSO, - GLProgramResources* ProgramResources, - Uint32 NumPrograms); - ~ShaderResourceBindingGLImpl(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - /// Implementation of IShaderResourceBinding::BindResources() in OpenGL backend. - virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) override final; - - /// Implementation of IShaderResourceBinding::GetVariableByName() in OpenGL backend. - virtual IShaderResourceVariable* GetVariableByName(SHADER_TYPE ShaderType, const char* Name) override final; - - /// Implementation of IShaderResourceBinding::GetVariableCount() in OpenGL backend. - virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const override final; - - /// Implementation of IShaderResourceBinding::GetVariableByIndex() in OpenGL backend. - virtual IShaderResourceVariable* GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; - - /// Implementation of IShaderResourceBinding::InitializeStaticResources() in OpenGL backend. - virtual void InitializeStaticResources(const IPipelineState* pPipelineState) override final; - - const GLProgramResourceCache& GetResourceCache(PipelineStateGLImpl* pdbgPSO); - -private: - // The resource layout only references mutable and dynamic variables - GLPipelineResourceLayout m_ResourceLayout; - - // The resource cache holds resource bindings for all variables - GLProgramResourceCache m_ResourceCache; - - bool m_bIsStaticResourcesBound = false; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp new file mode 100644 index 00000000..3803a2ff --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceBindingGLImpl.hpp @@ -0,0 +1,88 @@ +/* + * 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 +/// Declaration of Diligent::ShaderResourceBindingGLImpl class + +#include "ShaderResourceBindingGL.h" +#include "RenderDeviceGL.h" +#include "ShaderResourceBindingBase.hpp" +#include "GLProgramResources.hpp" +#include "ShaderBase.hpp" +#include "GLProgramResourceCache.hpp" +#include "GLPipelineResourceLayout.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; +class PipelineStateGLImpl; + +/// Shader resource binding object implementation in OpenGL backend. +class ShaderResourceBindingGLImpl final : public ShaderResourceBindingBase +{ +public: + using TBase = ShaderResourceBindingBase; + + ShaderResourceBindingGLImpl(IReferenceCounters* pRefCounters, + PipelineStateGLImpl* pPSO, + GLProgramResources* ProgramResources, + Uint32 NumPrograms); + ~ShaderResourceBindingGLImpl(); + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + /// Implementation of IShaderResourceBinding::BindResources() in OpenGL backend. + virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags) override final; + + /// Implementation of IShaderResourceBinding::GetVariableByName() in OpenGL backend. + virtual IShaderResourceVariable* GetVariableByName(SHADER_TYPE ShaderType, const char* Name) override final; + + /// Implementation of IShaderResourceBinding::GetVariableCount() in OpenGL backend. + virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const override final; + + /// Implementation of IShaderResourceBinding::GetVariableByIndex() in OpenGL backend. + virtual IShaderResourceVariable* GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final; + + /// Implementation of IShaderResourceBinding::InitializeStaticResources() in OpenGL backend. + virtual void InitializeStaticResources(const IPipelineState* pPipelineState) override final; + + const GLProgramResourceCache& GetResourceCache(PipelineStateGLImpl* pdbgPSO); + +private: + // The resource layout only references mutable and dynamic variables + GLPipelineResourceLayout m_ResourceLayout; + + // The resource cache holds resource bindings for all variables + GLProgramResourceCache m_ResourceCache; + + bool m_bIsStaticResourcesBound = false; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h deleted file mode 100644 index 19d5afb0..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h +++ /dev/null @@ -1,113 +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 "SwapChainBase.hpp" -#include "TextureViewGLImpl.h" - -namespace Diligent -{ - -class IMemoryAllocator; - -/// Base implementation of a swap chain for OpenGL. -template -class SwapChainGLBase : public SwapChainBase -{ -public: - using TSwapChainBase = SwapChainBase; - - SwapChainGLBase(IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, - IDeviceContext* pDeviceContext, - const SwapChainDesc& SCDesc) : - TSwapChainBase{pRefCounters, pDevice, pDeviceContext, SCDesc} - {} - - - /// Implementation of ISwapChain::GetCurrentBackBufferRTV() in OpenGL backend. - virtual ITextureView* GetCurrentBackBufferRTV() override final { return m_pRenderTargetView; } - - /// Implementation of ISwapChain::GetDepthBufferDSV() in OpenGL backend. - virtual ITextureView* GetDepthBufferDSV() override final { return m_pDepthStencilView; } - -protected: - bool Resize(Uint32 NewWidth, Uint32 NewHeight, Int32 /*To be different from virtual function*/) - { - if (TSwapChainBase::Resize(NewWidth, NewHeight, 0)) - { - if (m_pRenderTargetView) - { - if (auto pDeviceContext = this->m_wpDeviceContext.Lock()) - { - auto* pImmediateCtxGL = pDeviceContext.template RawPtr(); - // Unbind the back buffer to be consistent with other backends - auto* pCurrentBackBuffer = ValidatedCast(m_pRenderTargetView->GetTexture()); - auto RenderTargetsReset = pImmediateCtxGL->UnbindTextureFromFramebuffer(pCurrentBackBuffer, false); - if (RenderTargetsReset) - { - LOG_INFO_MESSAGE_ONCE("Resizing the swap chain requires back and depth-stencil buffers to be unbound from the device context. " - "An application should use SetRenderTargets() to restore them."); - } - } - } - - CreateDummyBuffers(this->m_pRenderDevice.template RawPtr()); - return true; - } - - return false; - } - - void CreateDummyBuffers(RenderDeviceGLImpl* pRenderDeviceGL) - { - TextureDesc ColorBuffDesc; - ColorBuffDesc.Type = RESOURCE_DIM_TEX_2D; - ColorBuffDesc.Name = "Main color buffer stub"; - ColorBuffDesc.Width = this->m_SwapChainDesc.Width; - ColorBuffDesc.Height = this->m_SwapChainDesc.Height; - ColorBuffDesc.Format = this->m_SwapChainDesc.ColorBufferFormat; - ColorBuffDesc.BindFlags = BIND_RENDER_TARGET; - RefCntAutoPtr pDummyColorBuffer; - pRenderDeviceGL->CreateDummyTexture(ColorBuffDesc, RESOURCE_STATE_RENDER_TARGET, &pDummyColorBuffer); - m_pRenderTargetView = ValidatedCast(pDummyColorBuffer->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET)); - - TextureDesc DepthBuffDesc = ColorBuffDesc; - DepthBuffDesc.Name = "Main depth buffer stub"; - DepthBuffDesc.Format = this->m_SwapChainDesc.DepthBufferFormat; - DepthBuffDesc.BindFlags = BIND_DEPTH_STENCIL; - RefCntAutoPtr pDummyDepthBuffer; - pRenderDeviceGL->CreateDummyTexture(DepthBuffDesc, RESOURCE_STATE_DEPTH_WRITE, &pDummyDepthBuffer); - m_pDepthStencilView = ValidatedCast(pDummyDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL)); - } - - RefCntAutoPtr m_pRenderTargetView; - RefCntAutoPtr m_pDepthStencilView; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.hpp b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.hpp new file mode 100644 index 00000000..4d18927b --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.hpp @@ -0,0 +1,113 @@ +/* + * 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 "SwapChainBase.hpp" +#include "TextureViewGLImpl.hpp" + +namespace Diligent +{ + +class IMemoryAllocator; + +/// Base implementation of a swap chain for OpenGL. +template +class SwapChainGLBase : public SwapChainBase +{ +public: + using TSwapChainBase = SwapChainBase; + + SwapChainGLBase(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pDeviceContext, + const SwapChainDesc& SCDesc) : + TSwapChainBase{pRefCounters, pDevice, pDeviceContext, SCDesc} + {} + + + /// Implementation of ISwapChain::GetCurrentBackBufferRTV() in OpenGL backend. + virtual ITextureView* GetCurrentBackBufferRTV() override final { return m_pRenderTargetView; } + + /// Implementation of ISwapChain::GetDepthBufferDSV() in OpenGL backend. + virtual ITextureView* GetDepthBufferDSV() override final { return m_pDepthStencilView; } + +protected: + bool Resize(Uint32 NewWidth, Uint32 NewHeight, Int32 /*To be different from virtual function*/) + { + if (TSwapChainBase::Resize(NewWidth, NewHeight, 0)) + { + if (m_pRenderTargetView) + { + if (auto pDeviceContext = this->m_wpDeviceContext.Lock()) + { + auto* pImmediateCtxGL = pDeviceContext.template RawPtr(); + // Unbind the back buffer to be consistent with other backends + auto* pCurrentBackBuffer = ValidatedCast(m_pRenderTargetView->GetTexture()); + auto RenderTargetsReset = pImmediateCtxGL->UnbindTextureFromFramebuffer(pCurrentBackBuffer, false); + if (RenderTargetsReset) + { + LOG_INFO_MESSAGE_ONCE("Resizing the swap chain requires back and depth-stencil buffers to be unbound from the device context. " + "An application should use SetRenderTargets() to restore them."); + } + } + } + + CreateDummyBuffers(this->m_pRenderDevice.template RawPtr()); + return true; + } + + return false; + } + + void CreateDummyBuffers(RenderDeviceGLImpl* pRenderDeviceGL) + { + TextureDesc ColorBuffDesc; + ColorBuffDesc.Type = RESOURCE_DIM_TEX_2D; + ColorBuffDesc.Name = "Main color buffer stub"; + ColorBuffDesc.Width = this->m_SwapChainDesc.Width; + ColorBuffDesc.Height = this->m_SwapChainDesc.Height; + ColorBuffDesc.Format = this->m_SwapChainDesc.ColorBufferFormat; + ColorBuffDesc.BindFlags = BIND_RENDER_TARGET; + RefCntAutoPtr pDummyColorBuffer; + pRenderDeviceGL->CreateDummyTexture(ColorBuffDesc, RESOURCE_STATE_RENDER_TARGET, &pDummyColorBuffer); + m_pRenderTargetView = ValidatedCast(pDummyColorBuffer->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET)); + + TextureDesc DepthBuffDesc = ColorBuffDesc; + DepthBuffDesc.Name = "Main depth buffer stub"; + DepthBuffDesc.Format = this->m_SwapChainDesc.DepthBufferFormat; + DepthBuffDesc.BindFlags = BIND_DEPTH_STENCIL; + RefCntAutoPtr pDummyDepthBuffer; + pRenderDeviceGL->CreateDummyTexture(DepthBuffDesc, RESOURCE_STATE_DEPTH_WRITE, &pDummyDepthBuffer); + m_pDepthStencilView = ValidatedCast(pDummyDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL)); + } + + RefCntAutoPtr m_pRenderTargetView; + RefCntAutoPtr m_pDepthStencilView; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h deleted file mode 100644 index ac3639a4..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h +++ /dev/null @@ -1,70 +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 "SwapChainGL.h" -#include "SwapChainGLBase.h" -#include "GLObjectWrapper.h" - -namespace Diligent -{ - -class IMemoryAllocator; - -/// Swap chain implementation in OpenGL backend. -class SwapChainGLImpl final : public SwapChainGLBase -{ -public: - using TSwapChainGLBase = SwapChainGLBase; - - SwapChainGLImpl(IReferenceCounters* pRefCounters, - const EngineGLCreateInfo& InitAttribs, - const SwapChainDesc& SwapChainDesc, - class RenderDeviceGLImpl* pRenderDeviceGL, - class DeviceContextGLImpl* pImmediateContextGL); - ~SwapChainGLImpl(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - /// Implementation of ISwapChain::Present() in OpenGL backend. - virtual void Present(Uint32 SyncInterval) override final; - - /// Implementation of ISwapChain::Resize() in OpenGL backend. - virtual void Resize(Uint32 NewWidth, Uint32 NewHeight) override final; - - /// Implementation of ISwapChain::SetFullscreenMode() in OpenGL backend. - virtual void SetFullscreenMode(const DisplayModeAttribs& DisplayMode) override final; - - /// Implementation of ISwapChain::SetWindowedMode() in OpenGL backend. - virtual void SetWindowedMode() override final; - - /// Implementation of ISwapChainGL::GetDefaultFBO(). - virtual GLuint GetDefaultFBO() const override final { return 0; } -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.hpp new file mode 100644 index 00000000..fb069301 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.hpp @@ -0,0 +1,70 @@ +/* + * 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 "SwapChainGL.h" +#include "SwapChainGLBase.hpp" +#include "GLObjectWrapper.hpp" + +namespace Diligent +{ + +class IMemoryAllocator; + +/// Swap chain implementation in OpenGL backend. +class SwapChainGLImpl final : public SwapChainGLBase +{ +public: + using TSwapChainGLBase = SwapChainGLBase; + + SwapChainGLImpl(IReferenceCounters* pRefCounters, + const EngineGLCreateInfo& InitAttribs, + const SwapChainDesc& SwapChainDesc, + class RenderDeviceGLImpl* pRenderDeviceGL, + class DeviceContextGLImpl* pImmediateContextGL); + ~SwapChainGLImpl(); + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + /// Implementation of ISwapChain::Present() in OpenGL backend. + virtual void Present(Uint32 SyncInterval) override final; + + /// Implementation of ISwapChain::Resize() in OpenGL backend. + virtual void Resize(Uint32 NewWidth, Uint32 NewHeight) override final; + + /// Implementation of ISwapChain::SetFullscreenMode() in OpenGL backend. + virtual void SetFullscreenMode(const DisplayModeAttribs& DisplayMode) override final; + + /// Implementation of ISwapChain::SetWindowedMode() in OpenGL backend. + virtual void SetWindowedMode() override final; + + /// Implementation of ISwapChainGL::GetDefaultFBO(). + virtual GLuint GetDefaultFBO() const override final { return 0; } +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TexRegionRender.h b/Graphics/GraphicsEngineOpenGL/include/TexRegionRender.h deleted file mode 100644 index a24b1243..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TexRegionRender.h +++ /dev/null @@ -1,68 +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 -{ - -// Helper class to facilitate texture copying by rendering -class TexRegionRender -{ -public: - TexRegionRender(class RenderDeviceGLImpl* pDeviceGL); - void SetStates(class DeviceContextGLImpl* pCtxGL); - void RestoreStates(class DeviceContextGLImpl* pCtxGL); - - void Render(class DeviceContextGLImpl* pCtxGL, - ITextureView* pSrcSRV, - RESOURCE_DIMENSION TexType, - TEXTURE_FORMAT TexFormat, - Int32 DstToSrcXOffset, - Int32 DstToSrcYOffset, - Int32 SrcZ, - Int32 SrcMipLevel); - -private: - RefCntAutoPtr m_pVertexShader; - RefCntAutoPtr m_pFragmentShaders[RESOURCE_DIM_NUM_DIMENSIONS * 3]; - RefCntAutoPtr m_pConstantBuffer; - - RefCntAutoPtr m_pPSO[RESOURCE_DIM_NUM_DIMENSIONS * 3]; - RefCntAutoPtr m_pSRB; - IShaderResourceVariable* m_pSrcTexVar = nullptr; - - RefCntAutoPtr m_pOrigPSO; - Uint32 m_OrigStencilRef = 0; - float m_OrigBlendFactors[4] = {}; - Uint32 m_NumRenderTargets = 0; - ITextureView* m_pOrigRTVs[MAX_RENDER_TARGETS] = {}; - RefCntAutoPtr m_pOrigDSV; - std::vector m_OrigViewports; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TexRegionRender.hpp b/Graphics/GraphicsEngineOpenGL/include/TexRegionRender.hpp new file mode 100644 index 00000000..a24b1243 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TexRegionRender.hpp @@ -0,0 +1,68 @@ +/* + * 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 +{ + +// Helper class to facilitate texture copying by rendering +class TexRegionRender +{ +public: + TexRegionRender(class RenderDeviceGLImpl* pDeviceGL); + void SetStates(class DeviceContextGLImpl* pCtxGL); + void RestoreStates(class DeviceContextGLImpl* pCtxGL); + + void Render(class DeviceContextGLImpl* pCtxGL, + ITextureView* pSrcSRV, + RESOURCE_DIMENSION TexType, + TEXTURE_FORMAT TexFormat, + Int32 DstToSrcXOffset, + Int32 DstToSrcYOffset, + Int32 SrcZ, + Int32 SrcMipLevel); + +private: + RefCntAutoPtr m_pVertexShader; + RefCntAutoPtr m_pFragmentShaders[RESOURCE_DIM_NUM_DIMENSIONS * 3]; + RefCntAutoPtr m_pConstantBuffer; + + RefCntAutoPtr m_pPSO[RESOURCE_DIM_NUM_DIMENSIONS * 3]; + RefCntAutoPtr m_pSRB; + IShaderResourceVariable* m_pSrcTexVar = nullptr; + + RefCntAutoPtr m_pOrigPSO; + Uint32 m_OrigStencilRef = 0; + float m_OrigBlendFactors[4] = {}; + Uint32 m_NumRenderTargets = 0; + ITextureView* m_pOrigRTVs[MAX_RENDER_TARGETS] = {}; + RefCntAutoPtr m_pOrigDSV; + std::vector m_OrigViewports; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.h b/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.h deleted file mode 100644 index 33e8797c..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.h +++ /dev/null @@ -1,68 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// 1D texture array implementation in OpenGL backend. -class Texture1DArray_OGL final : public TextureBaseGL -{ -public: - Texture1DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture1DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - ~Texture1DArray_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 1D texture array. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture array. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp new file mode 100644 index 00000000..3bc0c2fe --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture1DArray_OGL.hpp @@ -0,0 +1,68 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 1D texture array implementation in OpenGL backend. +class Texture1DArray_OGL final : public TextureBaseGL +{ +public: + Texture1DArray_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture1DArray_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + ~Texture1DArray_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for 1D texture array. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture array. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.h b/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.h deleted file mode 100644 index c8859c81..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.h +++ /dev/null @@ -1,68 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// 1D texture implementation in OpenGL backend. -class Texture1D_OGL final : public TextureBaseGL -{ -public: - Texture1D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture1D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - ~Texture1D_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 1D texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp new file mode 100644 index 00000000..9f98e248 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture1D_OGL.hpp @@ -0,0 +1,68 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 1D texture implementation in OpenGL backend. +class Texture1D_OGL final : public TextureBaseGL +{ +public: + Texture1D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture1D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + ~Texture1D_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for 1D texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 1D texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.h b/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.h deleted file mode 100644 index 5b482989..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.h +++ /dev/null @@ -1,68 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// 2D texture array implementation in OpenGL backend. -class Texture2DArray_OGL final : public TextureBaseGL -{ -public: - Texture2DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture2DArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - ~Texture2DArray_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 2D texture array. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture array. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp new file mode 100644 index 00000000..605a2453 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture2DArray_OGL.hpp @@ -0,0 +1,68 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 2D texture array implementation in OpenGL backend. +class Texture2DArray_OGL final : public TextureBaseGL +{ +public: + Texture2DArray_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture2DArray_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + ~Texture2DArray_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for 2D texture array. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture array. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.h b/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.h deleted file mode 100644 index 5b0461fa..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.h +++ /dev/null @@ -1,76 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// 2D texture implementation in OpenGL backend. -class Texture2D_OGL final : public TextureBaseGL -{ -public: - Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - - /// This constructor is used to create a dummy texture object for the default framebuffer. - Texture2D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - const TextureDesc& TexDesc, - bool bIsDeviceInternal = false); - - ~Texture2D_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 2D texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp new file mode 100644 index 00000000..24ee46b0 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture2D_OGL.hpp @@ -0,0 +1,76 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 2D texture implementation in OpenGL backend. +class Texture2D_OGL final : public TextureBaseGL +{ +public: + Texture2D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture2D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + + /// This constructor is used to create a dummy texture object for the default framebuffer. + Texture2D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + const TextureDesc& TexDesc, + bool bIsDeviceInternal = false); + + ~Texture2D_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for 2D texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 2D texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.h b/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.h deleted file mode 100644 index 158f3dbf..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.h +++ /dev/null @@ -1,68 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// 3D texture implementation in OpenGL backend. -class Texture3D_OGL final : public TextureBaseGL -{ -public: - Texture3D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - Texture3D_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - ~Texture3D_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for 3D texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for 3D texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp new file mode 100644 index 00000000..6902a907 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/Texture3D_OGL.hpp @@ -0,0 +1,68 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// 3D texture implementation in OpenGL backend. +class Texture3D_OGL final : public TextureBaseGL +{ +public: + Texture3D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + Texture3D_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + ~Texture3D_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for 3D texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for 3D texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.h b/Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.h deleted file mode 100644 index 5865f435..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.h +++ /dev/null @@ -1,138 +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 "BaseInterfacesGL.h" -#include "TextureGL.h" -#include "TextureBase.hpp" -#include "RenderDevice.h" -#include "GLObjectWrapper.h" -#include "TextureViewGLImpl.h" -#include "AsyncWritableResource.h" -#include "RenderDeviceGLImpl.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Base implementation of a texture object in OpenGL backend. -class TextureBaseGL : public TextureBase, public AsyncWritableResource -{ -public: - using TTextureBase = TextureBase; - using ViewImplType = TextureViewGLImpl; - - TextureBaseGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - const TextureDesc& TexDesc, - GLenum BindTarget, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - TextureBaseGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - GLenum BindTarget, - bool bIsDeviceInternal); - - /// Initializes a dummy texture (dummy textures are used by the swap chain to - /// proxy default framebuffer). - TextureBaseGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - RenderDeviceGLImpl* pDeviceGL, - const TextureDesc& TexDesc, - bool bIsDeviceInternal); - - ~TextureBaseGL(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; - - const GLObjectWrappers::GLTextureObj& GetGLHandle() const { return m_GlTexture; } - - /// Implementation of ITextureGL::GetBindTarget(). - virtual GLenum GetBindTarget() const override final { return m_BindTarget; } - - GLenum GetGLTexFormat() const { return m_GLTexFormat; } - - void TextureMemoryBarrier(Uint32 RequiredBarriers, class GLContextState& GLContextState); - - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, GLenum AttachmentPoint) = 0; - - void CopyData(DeviceContextGLImpl* pDeviceCtxGL, - TextureBaseGL* pSrcTextureGL, - Uint32 SrcMipLevel, - Uint32 SrcSlice, - const Box* pSrcBox, - Uint32 DstMipLevel, - Uint32 DstSlice, - Uint32 DstX, - Uint32 DstY, - Uint32 DstZ); - - /// Implementation of ITextureGL::GetGLTextureHandle(). - virtual GLuint GetGLTextureHandle() override final { return GetGLHandle(); } - - /// Implementation of ITexture::GetNativeHandle() in OpenGL backend. - virtual void* GetNativeHandle() override final - { - return reinterpret_cast(static_cast(GetGLTextureHandle())); - } - - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) = 0; - - static Uint32 GetPBODataOffset(const TextureDesc& TexDesc, Uint32 ArraySlice, Uint32 MipLevel); - - IBuffer* GetPBO() - { - return m_pPBO; - } - -protected: - virtual void CreateViewInternal(const struct TextureViewDesc& ViewDesc, - class ITextureView** ppView, - bool bIsDefaultView) override; - - void SetDefaultGLParameters(); - - GLObjectWrappers::GLTextureObj m_GlTexture; - RefCntAutoPtr m_pPBO; // For staging textures - const GLenum m_BindTarget; - const GLenum m_GLTexFormat; - //Uint32 m_uiMapTarget; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.hpp new file mode 100644 index 00000000..306ddb64 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TextureBaseGL.hpp @@ -0,0 +1,138 @@ +/* + * 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 "BaseInterfacesGL.h" +#include "TextureGL.h" +#include "TextureBase.hpp" +#include "RenderDevice.h" +#include "GLObjectWrapper.hpp" +#include "TextureViewGLImpl.hpp" +#include "AsyncWritableResource.hpp" +#include "RenderDeviceGLImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Base implementation of a texture object in OpenGL backend. +class TextureBaseGL : public TextureBase, public AsyncWritableResource +{ +public: + using TTextureBase = TextureBase; + using ViewImplType = TextureViewGLImpl; + + TextureBaseGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + const TextureDesc& TexDesc, + GLenum BindTarget, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + TextureBaseGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + GLenum BindTarget, + bool bIsDeviceInternal); + + /// Initializes a dummy texture (dummy textures are used by the swap chain to + /// proxy default framebuffer). + TextureBaseGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + RenderDeviceGLImpl* pDeviceGL, + const TextureDesc& TexDesc, + bool bIsDeviceInternal); + + ~TextureBaseGL(); + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override; + + const GLObjectWrappers::GLTextureObj& GetGLHandle() const { return m_GlTexture; } + + /// Implementation of ITextureGL::GetBindTarget(). + virtual GLenum GetBindTarget() const override final { return m_BindTarget; } + + GLenum GetGLTexFormat() const { return m_GLTexFormat; } + + void TextureMemoryBarrier(Uint32 RequiredBarriers, class GLContextState& GLContextState); + + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, GLenum AttachmentPoint) = 0; + + void CopyData(DeviceContextGLImpl* pDeviceCtxGL, + TextureBaseGL* pSrcTextureGL, + Uint32 SrcMipLevel, + Uint32 SrcSlice, + const Box* pSrcBox, + Uint32 DstMipLevel, + Uint32 DstSlice, + Uint32 DstX, + Uint32 DstY, + Uint32 DstZ); + + /// Implementation of ITextureGL::GetGLTextureHandle(). + virtual GLuint GetGLTextureHandle() override final { return GetGLHandle(); } + + /// Implementation of ITexture::GetNativeHandle() in OpenGL backend. + virtual void* GetNativeHandle() override final + { + return reinterpret_cast(static_cast(GetGLTextureHandle())); + } + + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) = 0; + + static Uint32 GetPBODataOffset(const TextureDesc& TexDesc, Uint32 ArraySlice, Uint32 MipLevel); + + IBuffer* GetPBO() + { + return m_pPBO; + } + +protected: + virtual void CreateViewInternal(const struct TextureViewDesc& ViewDesc, + class ITextureView** ppView, + bool bIsDefaultView) override; + + void SetDefaultGLParameters(); + + GLObjectWrappers::GLTextureObj m_GlTexture; + RefCntAutoPtr m_pPBO; // For staging textures + const GLenum m_BindTarget; + const GLenum m_GLTexFormat; + //Uint32 m_uiMapTarget; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.h b/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.h deleted file mode 100644 index efbf7ed8..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.h +++ /dev/null @@ -1,68 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// Cube array texture implementation in OpenGL backend. -class TextureCubeArray_OGL final : public TextureBaseGL -{ -public: - TextureCubeArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - TextureCubeArray_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - ~TextureCubeArray_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for cube texture array. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture array. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp new file mode 100644 index 00000000..be583c0c --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TextureCubeArray_OGL.hpp @@ -0,0 +1,68 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// Cube array texture implementation in OpenGL backend. +class TextureCubeArray_OGL final : public TextureBaseGL +{ +public: + TextureCubeArray_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + TextureCubeArray_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + ~TextureCubeArray_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for cube texture array. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture array. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.h b/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.h deleted file mode 100644 index c2b314f3..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.h +++ /dev/null @@ -1,68 +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 "TextureBaseGL.h" - -namespace Diligent -{ - -/// Cube texture implementation in OpenGL backend. -class TextureCube_OGL final : public TextureBaseGL -{ -public: - TextureCube_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - const TextureData* pInitData = nullptr, - bool bIsDeviceInternal = false); - - TextureCube_OGL(IReferenceCounters* pRefCounters, - FixedBlockMemoryAllocator& TexViewObjAllocator, - class RenderDeviceGLImpl* pDeviceGL, - class GLContextState& GLState, - const TextureDesc& TexDesc, - GLuint GLTextureHandle, - bool bIsDeviceInternal = false); - ~TextureCube_OGL(); - - /// Implementation of TextureBaseGL::UpdateData() for cube texture. - virtual void UpdateData(class GLContextState& CtxState, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox, - const TextureSubResData& SubresData) override final; - - /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture. - virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, - GLenum AttachmentPoint) override final; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp new file mode 100644 index 00000000..f91196d2 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TextureCube_OGL.hpp @@ -0,0 +1,68 @@ +/* + * 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 "TextureBaseGL.hpp" + +namespace Diligent +{ + +/// Cube texture implementation in OpenGL backend. +class TextureCube_OGL final : public TextureBaseGL +{ +public: + TextureCube_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + const TextureData* pInitData = nullptr, + bool bIsDeviceInternal = false); + + TextureCube_OGL(IReferenceCounters* pRefCounters, + FixedBlockMemoryAllocator& TexViewObjAllocator, + class RenderDeviceGLImpl* pDeviceGL, + class GLContextState& GLState, + const TextureDesc& TexDesc, + GLuint GLTextureHandle, + bool bIsDeviceInternal = false); + ~TextureCube_OGL(); + + /// Implementation of TextureBaseGL::UpdateData() for cube texture. + virtual void UpdateData(class GLContextState& CtxState, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox, + const TextureSubResData& SubresData) override final; + + /// Implementation of TextureBaseGL::AttachToFramebuffer() for cube texture. + virtual void AttachToFramebuffer(const struct TextureViewDesc& ViewDesc, + GLenum AttachmentPoint) override final; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.h deleted file mode 100644 index 2a3b831c..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.h +++ /dev/null @@ -1,68 +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 "BaseInterfacesGL.h" -#include "TextureViewGL.h" -#include "TextureViewBase.hpp" -#include "RenderDevice.h" -#include "GLObjectWrapper.h" -#include "RenderDeviceGLImpl.h" - -namespace Diligent -{ - -class FixedBlockMemoryAllocator; - -/// Texture view implementation in OpenGL backend. -class TextureViewGLImpl final : public TextureViewBase -{ -public: - using TTextureViewBase = TextureViewBase; - - TextureViewGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDevice, - const struct TextureViewDesc& ViewDesc, - class TextureBaseGL* pTexture, - bool bCreateGLViewTex, - bool bIsDefaultView); - ~TextureViewGLImpl(); - - virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; - - const GLObjectWrappers::GLTextureObj& GetHandle(); - - GLenum GetBindTarget(); - void SetBindTarget(GLenum ViewTexBindTarget) { m_ViewTexBindTarget = ViewTexBindTarget; } - -protected: - GLObjectWrappers::GLTextureObj m_ViewTexGLHandle; - GLenum m_ViewTexBindTarget; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.hpp new file mode 100644 index 00000000..eab94be1 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/TextureViewGLImpl.hpp @@ -0,0 +1,68 @@ +/* + * 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 "BaseInterfacesGL.h" +#include "TextureViewGL.h" +#include "TextureViewBase.hpp" +#include "RenderDevice.h" +#include "GLObjectWrapper.hpp" +#include "RenderDeviceGLImpl.hpp" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Texture view implementation in OpenGL backend. +class TextureViewGLImpl final : public TextureViewBase +{ +public: + using TTextureViewBase = TextureViewBase; + + TextureViewGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDevice, + const struct TextureViewDesc& ViewDesc, + class TextureBaseGL* pTexture, + bool bCreateGLViewTex, + bool bIsDefaultView); + ~TextureViewGLImpl(); + + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final; + + const GLObjectWrappers::GLTextureObj& GetHandle(); + + GLenum GetBindTarget(); + void SetBindTarget(GLenum ViewTexBindTarget) { m_ViewTexBindTarget = ViewTexBindTarget; } + +protected: + GLObjectWrappers::GLTextureObj m_ViewTexGLHandle; + GLenum m_ViewTexBindTarget; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/VAOCache.h b/Graphics/GraphicsEngineOpenGL/include/VAOCache.h deleted file mode 100644 index b7dbd93f..00000000 --- a/Graphics/GraphicsEngineOpenGL/include/VAOCache.h +++ /dev/null @@ -1,141 +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 "GraphicsTypes.h" -#include "Buffer.h" -#include "InputLayout.h" -#include "LockHelper.h" -#include "HashUtils.h" -#include "DeviceContextBase.hpp" -#include "BaseInterfacesGL.h" - -namespace Diligent -{ - -class VAOCache -{ -public: - VAOCache(); - ~VAOCache(); - - // clang-format off - VAOCache (const VAOCache&) = delete; - VAOCache ( VAOCache&&) = delete; - VAOCache& operator = (const VAOCache&) = delete; - VAOCache& operator = ( VAOCache&&) = delete; - // clang-format on - - const GLObjectWrappers::GLVertexArrayObj& GetVAO(IPipelineState* pPSO, - IBuffer* pIndexBuffer, - VertexStreamInfo VertexStreams[], - Uint32 NumVertexStreams, - class GLContextState& GLContextState); - const GLObjectWrappers::GLVertexArrayObj& GetEmptyVAO(); - - void OnDestroyBuffer(IBuffer* pBuffer); - void OnDestroyPSO(IPipelineState* pPSO); - -private: - // This structure is used as the key to find VAO - struct VAOCacheKey - { - VAOCacheKey(UniqueIdentifier pso_id, UniqueIdentifier ib_id) : - // clang-format off - PSOUId {pso_id}, - IndexBufferUId {ib_id }, - NumUsedSlots {0 } - // clang-format on - {} - - // Note that using pointers is unsafe as they may (and will) be reused: - // pBuffer->Release(); - // pDevice->CreateBuffer(&pBuffer); // Returns same pointer - - // VAO encapsulates both input layout and all bound buffers. - // PSO uniqly defines the layout (attrib pointers, divisors, etc.), - // so we do not need to add individual layout elements to the key. - // The key needs to contain all bound buffers. - const UniqueIdentifier PSOUId; - const UniqueIdentifier IndexBufferUId; - Uint32 NumUsedSlots; - struct StreamAttribs - { - UniqueIdentifier BufferUId; - Uint32 Stride; - Uint32 Offset; - } Streams[MAX_BUFFER_SLOTS]; - - mutable size_t Hash = 0; - - bool operator==(const VAOCacheKey& Key) const - { - return PSOUId == Key.PSOUId && - IndexBufferUId == Key.IndexBufferUId && - NumUsedSlots == Key.NumUsedSlots && - std::memcmp(Streams, Key.Streams, sizeof(StreamAttribs) * NumUsedSlots) == 0; - } - }; - - struct VAOCacheKeyHashFunc - { - std::size_t operator()(const VAOCacheKey& Key) const - { - if (Key.Hash == 0) - { - std::size_t Seed = 0; - HashCombine(Seed, Key.PSOUId, Key.IndexBufferUId, Key.NumUsedSlots); - for (Uint32 slot = 0; slot < Key.NumUsedSlots; ++slot) - { - auto& CurrStream = Key.Streams[slot]; - HashCombine(Seed, CurrStream.BufferUId); - HashCombine(Seed, CurrStream.Offset); - HashCombine(Seed, CurrStream.Stride); - } - Key.Hash = Seed; - } - return Key.Hash; - } - }; - - - friend class RenderDeviceGLImpl; - ThreadingTools::LockFlag m_CacheLockFlag; - std::unordered_map m_Cache; - - std::unordered_multimap m_PSOToKey; - std::unordered_multimap m_BuffToKey; - - // Any draw command fails if no VAO is bound. We will use this empty - // VAO for draw commands with null input layout, such as these that - // only use VertexID as input. - GLObjectWrappers::GLVertexArrayObj m_EmptyVAO; -}; - -} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/VAOCache.hpp b/Graphics/GraphicsEngineOpenGL/include/VAOCache.hpp new file mode 100644 index 00000000..b7dbd93f --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/VAOCache.hpp @@ -0,0 +1,141 @@ +/* + * 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 "GraphicsTypes.h" +#include "Buffer.h" +#include "InputLayout.h" +#include "LockHelper.h" +#include "HashUtils.h" +#include "DeviceContextBase.hpp" +#include "BaseInterfacesGL.h" + +namespace Diligent +{ + +class VAOCache +{ +public: + VAOCache(); + ~VAOCache(); + + // clang-format off + VAOCache (const VAOCache&) = delete; + VAOCache ( VAOCache&&) = delete; + VAOCache& operator = (const VAOCache&) = delete; + VAOCache& operator = ( VAOCache&&) = delete; + // clang-format on + + const GLObjectWrappers::GLVertexArrayObj& GetVAO(IPipelineState* pPSO, + IBuffer* pIndexBuffer, + VertexStreamInfo VertexStreams[], + Uint32 NumVertexStreams, + class GLContextState& GLContextState); + const GLObjectWrappers::GLVertexArrayObj& GetEmptyVAO(); + + void OnDestroyBuffer(IBuffer* pBuffer); + void OnDestroyPSO(IPipelineState* pPSO); + +private: + // This structure is used as the key to find VAO + struct VAOCacheKey + { + VAOCacheKey(UniqueIdentifier pso_id, UniqueIdentifier ib_id) : + // clang-format off + PSOUId {pso_id}, + IndexBufferUId {ib_id }, + NumUsedSlots {0 } + // clang-format on + {} + + // Note that using pointers is unsafe as they may (and will) be reused: + // pBuffer->Release(); + // pDevice->CreateBuffer(&pBuffer); // Returns same pointer + + // VAO encapsulates both input layout and all bound buffers. + // PSO uniqly defines the layout (attrib pointers, divisors, etc.), + // so we do not need to add individual layout elements to the key. + // The key needs to contain all bound buffers. + const UniqueIdentifier PSOUId; + const UniqueIdentifier IndexBufferUId; + Uint32 NumUsedSlots; + struct StreamAttribs + { + UniqueIdentifier BufferUId; + Uint32 Stride; + Uint32 Offset; + } Streams[MAX_BUFFER_SLOTS]; + + mutable size_t Hash = 0; + + bool operator==(const VAOCacheKey& Key) const + { + return PSOUId == Key.PSOUId && + IndexBufferUId == Key.IndexBufferUId && + NumUsedSlots == Key.NumUsedSlots && + std::memcmp(Streams, Key.Streams, sizeof(StreamAttribs) * NumUsedSlots) == 0; + } + }; + + struct VAOCacheKeyHashFunc + { + std::size_t operator()(const VAOCacheKey& Key) const + { + if (Key.Hash == 0) + { + std::size_t Seed = 0; + HashCombine(Seed, Key.PSOUId, Key.IndexBufferUId, Key.NumUsedSlots); + for (Uint32 slot = 0; slot < Key.NumUsedSlots; ++slot) + { + auto& CurrStream = Key.Streams[slot]; + HashCombine(Seed, CurrStream.BufferUId); + HashCombine(Seed, CurrStream.Offset); + HashCombine(Seed, CurrStream.Stride); + } + Key.Hash = Seed; + } + return Key.Hash; + } + }; + + + friend class RenderDeviceGLImpl; + ThreadingTools::LockFlag m_CacheLockFlag; + std::unordered_map m_Cache; + + std::unordered_multimap m_PSOToKey; + std::unordered_multimap m_BuffToKey; + + // Any draw command fails if no VAO is bound. We will use this empty + // VAO for draw commands with null input layout, such as these that + // only use VertexID as input. + GLObjectWrappers::GLVertexArrayObj m_EmptyVAO; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/pch.h b/Graphics/GraphicsEngineOpenGL/include/pch.h index 706fa9a7..bb975773 100644 --- a/Graphics/GraphicsEngineOpenGL/include/pch.h +++ b/Graphics/GraphicsEngineOpenGL/include/pch.h @@ -117,7 +117,7 @@ #include "PlatformDefinitions.h" #include "RefCntAutoPtr.h" #include "DebugUtilities.h" -#include "GLObjectWrapper.h" +#include "GLObjectWrapper.hpp" #include "ValidatedCast.h" #include "RenderDevice.h" #include "BaseInterfacesGL.h" diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp index e37baf13..f4bff6a0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp @@ -27,11 +27,11 @@ #include "pch.h" -#include "BufferGLImpl.h" -#include "RenderDeviceGLImpl.h" +#include "BufferGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" #include "GLTypeConversions.h" -#include "BufferViewGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "BufferViewGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "EngineMemory.h" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp index 01bbd168..024c2dae 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferViewGLImpl.cpp @@ -27,10 +27,10 @@ #include "pch.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" -#include "BufferViewGLImpl.h" -#include "BufferGLImpl.h" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" +#include "BufferViewGLImpl.hpp" +#include "BufferGLImpl.hpp" #include "GLTypeConversions.h" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 0d80cbb7..eca2ccfe 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -31,24 +31,24 @@ #include #include "SwapChainGL.h" -#include "DeviceContextGLImpl.h" -#include "RenderDeviceGLImpl.h" +#include "DeviceContextGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" #include "GLTypeConversions.h" -#include "BufferGLImpl.h" -#include "ShaderGLImpl.h" -#include "VAOCache.h" -#include "Texture1D_OGL.h" -#include "Texture1DArray_OGL.h" -#include "Texture2D_OGL.h" -#include "Texture2DArray_OGL.h" -#include "Texture3D_OGL.h" -#include "SamplerGLImpl.h" +#include "BufferGLImpl.hpp" +#include "ShaderGLImpl.hpp" +#include "VAOCache.hpp" +#include "Texture1D_OGL.hpp" +#include "Texture1DArray_OGL.hpp" +#include "Texture2D_OGL.hpp" +#include "Texture2DArray_OGL.hpp" +#include "Texture3D_OGL.hpp" +#include "SamplerGLImpl.hpp" #include "GraphicsAccessories.hpp" -#include "BufferViewGLImpl.h" -#include "PipelineStateGLImpl.h" -#include "FenceGLImpl.h" -#include "ShaderResourceBindingGLImpl.h" +#include "BufferViewGLImpl.hpp" +#include "PipelineStateGLImpl.hpp" +#include "FenceGLImpl.hpp" +#include "ShaderResourceBindingGLImpl.hpp" using namespace std; diff --git a/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp index d8bb9d51..2a35bd28 100644 --- a/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp @@ -30,8 +30,8 @@ #include "pch.h" #include "EngineFactoryOpenGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "EngineMemory.h" #include "HLSL2GLSLConverterObject.h" #include "EngineFactoryBase.hpp" @@ -39,7 +39,7 @@ #if PLATFORM_IOS # include "SwapChainGLIOS.h" #else -# include "SwapChainGLImpl.h" +# include "SwapChainGLImpl.hpp" #endif #if PLATFORM_ANDROID diff --git a/Graphics/GraphicsEngineOpenGL/src/FBOCache.cpp b/Graphics/GraphicsEngineOpenGL/src/FBOCache.cpp index 5ed081cd..1165dba8 100644 --- a/Graphics/GraphicsEngineOpenGL/src/FBOCache.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/FBOCache.cpp @@ -27,10 +27,10 @@ #include "pch.h" -#include "FBOCache.h" -#include "RenderDeviceGLImpl.h" -#include "TextureBaseGL.h" -#include "GLContextState.h" +#include "FBOCache.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "TextureBaseGL.hpp" +#include "GLContextState.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp index 25d8e23a..31e3eaa8 100644 --- a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp @@ -27,7 +27,7 @@ #include "pch.h" -#include "FenceGLImpl.h" +#include "FenceGLImpl.hpp" #include "EngineMemory.h" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp index ba06b018..da7a2847 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp @@ -27,13 +27,13 @@ #include "pch.h" -#include "GLContextState.h" -#include "TextureBaseGL.h" -#include "SamplerGLImpl.h" -#include "AsyncWritableResource.h" +#include "GLContextState.hpp" +#include "TextureBaseGL.hpp" +#include "SamplerGLImpl.hpp" +#include "AsyncWritableResource.hpp" #include "GLTypeConversions.h" -#include "BufferViewGLImpl.h" -#include "RenderDeviceGLImpl.h" +#include "BufferViewGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" using namespace GLObjectWrappers; diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp index ac45e04a..71c23a13 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp @@ -27,7 +27,7 @@ #include "pch.h" -#include "GLContextWindows.h" +#include "GLContextWindows.hpp" #include "DeviceCaps.h" #include "GLTypeConversions.h" #include "GraphicsAccessories.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/GLObjectWrapper.cpp b/Graphics/GraphicsEngineOpenGL/src/GLObjectWrapper.cpp index c894d340..715373b5 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLObjectWrapper.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLObjectWrapper.cpp @@ -26,7 +26,7 @@ */ #include "pch.h" -#include "GLObjectWrapper.h" +#include "GLObjectWrapper.hpp" namespace GLObjectWrappers { diff --git a/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp b/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp index fb4feea1..bd61a2af 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLPipelineResourceLayout.cpp @@ -27,7 +27,7 @@ #include "pch.h" #include -#include "GLPipelineResourceLayout.h" +#include "GLPipelineResourceLayout.hpp" #include "Align.h" #include "PlatformMisc.h" #include "ShaderBase.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResourceCache.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResourceCache.cpp index 888c096e..a23abd3e 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResourceCache.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResourceCache.cpp @@ -26,7 +26,7 @@ */ #include "pch.h" -#include "GLProgramResourceCache.h" +#include "GLProgramResourceCache.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp index 0c618c2f..7c3f70d6 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp @@ -27,9 +27,9 @@ #include "pch.h" #include -#include "GLContextState.h" -#include "GLProgramResources.h" -#include "RenderDeviceGLImpl.h" +#include "GLContextState.hpp" +#include "GLProgramResources.hpp" +#include "RenderDeviceGLImpl.hpp" #include "ShaderResourceBindingBase.hpp" #include "ShaderResourceVariableBase.hpp" #include "Align.h" diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index 033d17e7..ccf9e565 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -26,12 +26,12 @@ */ #include "pch.h" -#include "PipelineStateGLImpl.h" -#include "RenderDeviceGLImpl.h" -#include "ShaderGLImpl.h" -#include "ShaderResourceBindingGLImpl.h" +#include "PipelineStateGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "ShaderGLImpl.hpp" +#include "ShaderResourceBindingGLImpl.hpp" #include "EngineMemory.h" -#include "DeviceContextGLImpl.h" +#include "DeviceContextGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/QueryGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/QueryGLImpl.cpp index 3308e841..0666194c 100644 --- a/Graphics/GraphicsEngineOpenGL/src/QueryGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/QueryGLImpl.cpp @@ -27,7 +27,7 @@ #include "pch.h" -#include "QueryGLImpl.h" +#include "QueryGLImpl.hpp" #include "EngineMemory.h" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 54746823..af705f90 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -27,25 +27,25 @@ #include "pch.h" -#include "RenderDeviceGLImpl.h" - -#include "BufferGLImpl.h" -#include "ShaderGLImpl.h" -#include "VAOCache.h" -#include "Texture1D_OGL.h" -#include "Texture1DArray_OGL.h" -#include "Texture2D_OGL.h" -#include "Texture2DArray_OGL.h" -#include "Texture3D_OGL.h" -#include "TextureCube_OGL.h" -#include "TextureCubeArray_OGL.h" -#include "SamplerGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "RenderDeviceGLImpl.hpp" + +#include "BufferGLImpl.hpp" +#include "ShaderGLImpl.hpp" +#include "VAOCache.hpp" +#include "Texture1D_OGL.hpp" +#include "Texture1DArray_OGL.hpp" +#include "Texture2D_OGL.hpp" +#include "Texture2DArray_OGL.hpp" +#include "Texture3D_OGL.hpp" +#include "TextureCube_OGL.hpp" +#include "TextureCubeArray_OGL.hpp" +#include "SamplerGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" -#include "PipelineStateGLImpl.h" -#include "ShaderResourceBindingGLImpl.h" -#include "FenceGLImpl.h" -#include "QueryGLImpl.h" +#include "PipelineStateGLImpl.hpp" +#include "ShaderResourceBindingGLImpl.hpp" +#include "FenceGLImpl.hpp" +#include "QueryGLImpl.hpp" #include "EngineMemory.h" #include "StringTools.h" diff --git a/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp index e45b145d..2b34841c 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SamplerGLImpl.cpp @@ -26,8 +26,8 @@ */ #include "pch.h" -#include "SamplerGLImpl.h" -#include "RenderDeviceGLImpl.h" +#include "SamplerGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" #include "GLTypeConversions.h" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp index 60df2d10..b7be0ce2 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp @@ -27,9 +27,9 @@ #include "pch.h" -#include "ShaderGLImpl.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "ShaderGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "DataBlobImpl.h" #include "GLSLSourceBuilder.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp index bc2abb50..c4bc2665 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp @@ -26,9 +26,9 @@ */ #include "pch.h" -#include "ShaderResourceBindingGLImpl.h" -#include "PipelineStateGLImpl.h" -#include "ShaderGLImpl.h" +#include "ShaderResourceBindingGLImpl.hpp" +#include "PipelineStateGLImpl.hpp" +#include "ShaderGLImpl.hpp" #include "FixedBlockMemoryAllocator.h" namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index 386deab1..6245c02e 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -26,9 +26,9 @@ */ #include "pch.h" -#include "DeviceContextGLImpl.h" -#include "RenderDeviceGLImpl.h" -#include "SwapChainGLImpl.h" +#include "DeviceContextGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "SwapChainGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp index 073c2434..2275a4d1 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp @@ -27,9 +27,9 @@ #include "pch.h" -#include "TexRegionRender.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "TexRegionRender.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "../../GraphicsTools/interface/MapHelper.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp index b42321a8..4cbfa8e0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture1DArray_OGL.cpp @@ -27,11 +27,11 @@ #include "pch.h" -#include "Texture1DArray_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "Texture1DArray_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp index da7205b0..40cea68d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture1D_OGL.cpp @@ -27,11 +27,11 @@ #include "pch.h" -#include "Texture1D_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "Texture1D_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp index 5b09a048..39e65b03 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp @@ -27,12 +27,12 @@ #include "pch.h" -#include "Texture2DArray_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "Texture2DArray_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" #include "GraphicsAccessories.hpp" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp index 58b568fa..4bdaf683 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture2D_OGL.cpp @@ -27,12 +27,12 @@ #include "pch.h" -#include "Texture2D_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "Texture2D_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" #include "GraphicsAccessories.hpp" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp index f4166b2d..e915a3ed 100644 --- a/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/Texture3D_OGL.cpp @@ -27,12 +27,12 @@ #include "pch.h" -#include "Texture3D_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "Texture3D_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" #include "GraphicsAccessories.hpp" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp index 5e824ef5..dc463a24 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp @@ -27,12 +27,12 @@ #include "pch.h" -#include "TextureBaseGL.h" -#include "RenderDeviceGLImpl.h" +#include "TextureBaseGL.hpp" +#include "RenderDeviceGLImpl.hpp" #include "GLTypeConversions.h" -#include "TextureViewGLImpl.h" -#include "GLContextState.h" -#include "DeviceContextGLImpl.h" +#include "TextureViewGLImpl.hpp" +#include "GLContextState.hpp" +#include "DeviceContextGLImpl.hpp" #include "EngineMemory.h" #include "GraphicsAccessories.hpp" diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp index c8168559..e58863ed 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureCubeArray_OGL.cpp @@ -27,12 +27,12 @@ #include "pch.h" -#include "TextureCubeArray_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "TextureCubeArray_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" #include "GraphicsAccessories.hpp" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp index 1236a307..27a296e1 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureCube_OGL.cpp @@ -27,12 +27,12 @@ #include "pch.h" -#include "TextureCube_OGL.h" -#include "RenderDeviceGLImpl.h" -#include "DeviceContextGLImpl.h" +#include "TextureCube_OGL.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "DeviceContextGLImpl.hpp" #include "GLTypeConversions.h" #include "GraphicsAccessories.hpp" -#include "BufferGLImpl.h" +#include "BufferGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/TextureViewGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/TextureViewGLImpl.cpp index fcdfaa99..b437a487 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TextureViewGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TextureViewGLImpl.cpp @@ -27,10 +27,10 @@ #include "pch.h" -#include "TextureViewGLImpl.h" -#include "RenderDeviceGLImpl.h" -#include "TextureBaseGL.h" -#include "DeviceContextGLImpl.h" +#include "TextureViewGLImpl.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "TextureBaseGL.hpp" +#include "DeviceContextGLImpl.hpp" namespace Diligent { diff --git a/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp b/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp index 55080ad0..a3388293 100644 --- a/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/VAOCache.cpp @@ -27,13 +27,13 @@ #include "pch.h" -#include "VAOCache.h" -#include "RenderDeviceGLImpl.h" -#include "GLObjectWrapper.h" -#include "BufferGLImpl.h" +#include "VAOCache.hpp" +#include "RenderDeviceGLImpl.hpp" +#include "GLObjectWrapper.hpp" +#include "BufferGLImpl.hpp" #include "GLTypeConversions.h" -#include "GLContextState.h" -#include "PipelineStateGLImpl.h" +#include "GLContextState.hpp" +#include "PipelineStateGLImpl.hpp" namespace Diligent { -- cgit v1.2.3