From 77d1f10493def30dd17bc5744f8fba9d119b4d89 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 18 Jun 2018 17:34:03 -0400 Subject: [PATCH] OpenGL: Split OpenGLBackend in Forward.h and DeviceGL --- src/backend/CMakeLists.txt | 5 +- src/backend/opengl/BlendStateGL.cpp | 1 - src/backend/opengl/BufferGL.cpp | 2 - src/backend/opengl/CommandBufferGL.cpp | 3 +- src/backend/opengl/DepthStencilStateGL.cpp | 1 - .../{OpenGLBackend.cpp => DeviceGL.cpp} | 22 +---- .../opengl/{OpenGLBackend.h => DeviceGL.h} | 81 ++----------------- src/backend/opengl/Forward.h | 78 ++++++++++++++++++ src/backend/opengl/GeneratedCodeIncludes.h | 5 +- src/backend/opengl/InputStateGL.cpp | 1 - .../opengl/PersistentPipelineStateGL.cpp | 2 - src/backend/opengl/PipelineGL.cpp | 3 +- src/backend/opengl/PipelineLayoutGL.cpp | 2 +- src/backend/opengl/RenderPipelineGL.cpp | 2 +- src/backend/opengl/SamplerGL.cpp | 2 +- 15 files changed, 101 insertions(+), 109 deletions(-) rename src/backend/opengl/{OpenGLBackend.cpp => DeviceGL.cpp} (90%) rename src/backend/opengl/{OpenGLBackend.h => DeviceGL.h} (51%) create mode 100644 src/backend/opengl/Forward.h diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt index a93acbbab5..4436f635d6 100644 --- a/src/backend/CMakeLists.txt +++ b/src/backend/CMakeLists.txt @@ -66,10 +66,11 @@ if (NXT_ENABLE_OPENGL) ${OPENGL_DIR}/ComputePipelineGL.h ${OPENGL_DIR}/DepthStencilStateGL.cpp ${OPENGL_DIR}/DepthStencilStateGL.h + ${OPENGL_DIR}/DeviceGL.cpp + ${OPENGL_DIR}/DeviceGL.h + ${OPENGL_DIR}/Forward.h ${OPENGL_DIR}/InputStateGL.cpp ${OPENGL_DIR}/InputStateGL.h - ${OPENGL_DIR}/OpenGLBackend.cpp - ${OPENGL_DIR}/OpenGLBackend.h ${OPENGL_DIR}/PersistentPipelineStateGL.cpp ${OPENGL_DIR}/PersistentPipelineStateGL.h ${OPENGL_DIR}/PipelineGL.cpp diff --git a/src/backend/opengl/BlendStateGL.cpp b/src/backend/opengl/BlendStateGL.cpp index 42d981e905..1f49138bda 100644 --- a/src/backend/opengl/BlendStateGL.cpp +++ b/src/backend/opengl/BlendStateGL.cpp @@ -14,7 +14,6 @@ #include "backend/opengl/BlendStateGL.h" -#include "backend/opengl/OpenGLBackend.h" #include "common/Assert.h" namespace backend { namespace opengl { diff --git a/src/backend/opengl/BufferGL.cpp b/src/backend/opengl/BufferGL.cpp index 6fa5a95a01..e282975c6b 100644 --- a/src/backend/opengl/BufferGL.cpp +++ b/src/backend/opengl/BufferGL.cpp @@ -14,8 +14,6 @@ #include "backend/opengl/BufferGL.h" -#include "backend/opengl/OpenGLBackend.h" - namespace backend { namespace opengl { // Buffer diff --git a/src/backend/opengl/CommandBufferGL.cpp b/src/backend/opengl/CommandBufferGL.cpp index 5343f40d80..b5a1540636 100644 --- a/src/backend/opengl/CommandBufferGL.cpp +++ b/src/backend/opengl/CommandBufferGL.cpp @@ -14,11 +14,12 @@ #include "backend/opengl/CommandBufferGL.h" +#include "backend/BindGroup.h" #include "backend/Commands.h" #include "backend/opengl/BufferGL.h" #include "backend/opengl/ComputePipelineGL.h" +#include "backend/opengl/Forward.h" #include "backend/opengl/InputStateGL.h" -#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PipelineLayoutGL.h" #include "backend/opengl/RenderPipelineGL.h" diff --git a/src/backend/opengl/DepthStencilStateGL.cpp b/src/backend/opengl/DepthStencilStateGL.cpp index 0df1cf08f0..97a7f1588f 100644 --- a/src/backend/opengl/DepthStencilStateGL.cpp +++ b/src/backend/opengl/DepthStencilStateGL.cpp @@ -14,7 +14,6 @@ #include "backend/opengl/DepthStencilStateGL.h" -#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/PersistentPipelineStateGL.h" #include "common/Assert.h" diff --git a/src/backend/opengl/OpenGLBackend.cpp b/src/backend/opengl/DeviceGL.cpp similarity index 90% rename from src/backend/opengl/OpenGLBackend.cpp rename to src/backend/opengl/DeviceGL.cpp index 6aec34db1e..1b77e9b127 100644 --- a/src/backend/opengl/OpenGLBackend.cpp +++ b/src/backend/opengl/DeviceGL.cpp @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "backend/opengl/OpenGLBackend.h" +#include "backend/opengl/DeviceGL.h" +#include "backend/BindGroup.h" +#include "backend/BindGroupLayout.h" +#include "backend/RenderPassDescriptor.h" #include "backend/opengl/BlendStateGL.h" #include "backend/opengl/BufferGL.h" #include "backend/opengl/CommandBufferGL.h" @@ -106,17 +109,6 @@ namespace backend { namespace opengl { void Device::TickImpl() { } - // Bind Group - - BindGroup::BindGroup(BindGroupBuilder* builder) : BindGroupBase(builder) { - } - - // Bind Group Layout - - BindGroupLayout::BindGroupLayout(BindGroupLayoutBuilder* builder) - : BindGroupLayoutBase(builder) { - } - // Queue Queue::Queue(Device* device) : QueueBase(device) { @@ -128,10 +120,4 @@ namespace backend { namespace opengl { } } - // RenderPassDescriptor - - RenderPassDescriptor::RenderPassDescriptor(RenderPassDescriptorBuilder* builder) - : RenderPassDescriptorBase(builder) { - } - }} // namespace backend::opengl diff --git a/src/backend/opengl/OpenGLBackend.h b/src/backend/opengl/DeviceGL.h similarity index 51% rename from src/backend/opengl/OpenGLBackend.h rename to src/backend/opengl/DeviceGL.h index a6dc1b7f4e..4fdcea1994 100644 --- a/src/backend/opengl/OpenGLBackend.h +++ b/src/backend/opengl/DeviceGL.h @@ -1,4 +1,4 @@ -// Copyright 2017 The NXT Authors +// Copyright 2018 The NXT Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,75 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef BACKEND_OPENGL_OPENGLBACKEND_H_ -#define BACKEND_OPENGL_OPENGLBACKEND_H_ +#ifndef BACKEND_OPENGL_DEVICEGL_H_ +#define BACKEND_OPENGL_DEVICEGL_H_ #include "nxt/nxtcpp.h" -#include "backend/BindGroup.h" -#include "backend/BindGroupLayout.h" -#include "backend/BlendState.h" -#include "backend/Buffer.h" -#include "backend/DepthStencilState.h" #include "backend/Device.h" -#include "backend/InputState.h" #include "backend/Queue.h" -#include "backend/RenderPassDescriptor.h" -#include "backend/ToBackend.h" +#include "backend/opengl/Forward.h" #include "glad/glad.h" namespace backend { namespace opengl { - class BindGroup; - class BindGroupLayout; - class BlendState; - class Buffer; - class BufferView; - class CommandBuffer; - class ComputePipeline; - class DepthStencilState; - class Device; - class InputState; - class PersistentPipelineState; - class PipelineLayout; - class Queue; - class RenderPassDescriptor; - class RenderPipeline; - class Sampler; - class ShaderModule; - class SwapChain; - class Texture; - class TextureView; - - struct OpenGLBackendTraits { - using BindGroupType = BindGroup; - using BindGroupLayoutType = BindGroupLayout; - using BlendStateType = BlendState; - using BufferType = Buffer; - using BufferViewType = BufferView; - using CommandBufferType = CommandBuffer; - using ComputePipelineType = ComputePipeline; - using DepthStencilStateType = DepthStencilState; - using DeviceType = Device; - using InputStateType = InputState; - using PipelineLayoutType = PipelineLayout; - using QueueType = Queue; - using RenderPassDescriptorType = RenderPassDescriptor; - using RenderPipelineType = RenderPipeline; - using SamplerType = Sampler; - using ShaderModuleType = ShaderModule; - using SwapChainType = SwapChain; - using TextureType = Texture; - using TextureViewType = TextureView; - }; - - template - auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { - return ToBackendBase(common); - } - - // Definition of backend types class Device : public DeviceBase { public: BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override; @@ -109,16 +53,6 @@ namespace backend { namespace opengl { const nxt::SamplerDescriptor* descriptor) override; }; - class BindGroup : public BindGroupBase { - public: - BindGroup(BindGroupBuilder* builder); - }; - - class BindGroupLayout : public BindGroupLayoutBase { - public: - BindGroupLayout(BindGroupLayoutBuilder* builder); - }; - class Queue : public QueueBase { public: Queue(Device* device); @@ -127,11 +61,6 @@ namespace backend { namespace opengl { void Submit(uint32_t numCommands, CommandBuffer* const* commands); }; - class RenderPassDescriptor : public RenderPassDescriptorBase { - public: - RenderPassDescriptor(RenderPassDescriptorBuilder* builder); - }; - }} // namespace backend::opengl -#endif // BACKEND_OPENGL_OPENGLBACKEND_H_ +#endif // BACKEND_OPENGL_DEVICEGL_H_ diff --git a/src/backend/opengl/Forward.h b/src/backend/opengl/Forward.h new file mode 100644 index 0000000000..79a00cf795 --- /dev/null +++ b/src/backend/opengl/Forward.h @@ -0,0 +1,78 @@ +// Copyright 2018 The NXT Authors +// +// 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. + +#ifndef BACKEND_OPENGL_FORWARD_H_ +#define BACKEND_OPENGL_FORWARD_H_ + +#include "backend/ToBackend.h" + +namespace { + class BindGroupBase; + class BindGroup; + class RenderPassDescriptor; +} // namespace + +namespace backend { namespace opengl { + + using BindGroup = BindGroupBase; + using BindGroupLayout = BindGroupLayoutBase; + class BlendState; + class Buffer; + class BufferView; + class CommandBuffer; + class ComputePipeline; + class DepthStencilState; + class Device; + class InputState; + class PersistentPipelineState; + class PipelineLayout; + class Queue; + using RenderPassDescriptor = RenderPassDescriptorBase; + class RenderPipeline; + class Sampler; + class ShaderModule; + class SwapChain; + class Texture; + class TextureView; + + struct OpenGLBackendTraits { + using BindGroupType = BindGroup; + using BindGroupLayoutType = BindGroupLayout; + using BlendStateType = BlendState; + using BufferType = Buffer; + using BufferViewType = BufferView; + using CommandBufferType = CommandBuffer; + using ComputePipelineType = ComputePipeline; + using DepthStencilStateType = DepthStencilState; + using DeviceType = Device; + using InputStateType = InputState; + using PipelineLayoutType = PipelineLayout; + using QueueType = Queue; + using RenderPassDescriptorType = RenderPassDescriptor; + using RenderPipelineType = RenderPipeline; + using SamplerType = Sampler; + using ShaderModuleType = ShaderModule; + using SwapChainType = SwapChain; + using TextureType = Texture; + using TextureViewType = TextureView; + }; + + template + auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { + return ToBackendBase(common); + } + +}} // namespace backend::opengl + +#endif // BACKEND_OPENGL_FORWARD_H_ diff --git a/src/backend/opengl/GeneratedCodeIncludes.h b/src/backend/opengl/GeneratedCodeIncludes.h index b47f055eaa..33b38d10f8 100644 --- a/src/backend/opengl/GeneratedCodeIncludes.h +++ b/src/backend/opengl/GeneratedCodeIncludes.h @@ -12,13 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "backend/BindGroup.h" +#include "backend/BindGroupLayout.h" +#include "backend/RenderPassDescriptor.h" #include "backend/opengl/BlendStateGL.h" #include "backend/opengl/BufferGL.h" #include "backend/opengl/CommandBufferGL.h" #include "backend/opengl/ComputePipelineGL.h" #include "backend/opengl/DepthStencilStateGL.h" +#include "backend/opengl/DeviceGL.h" #include "backend/opengl/InputStateGL.h" -#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PipelineLayoutGL.h" #include "backend/opengl/RenderPipelineGL.h" diff --git a/src/backend/opengl/InputStateGL.cpp b/src/backend/opengl/InputStateGL.cpp index 8bb04e532e..7f20bfb361 100644 --- a/src/backend/opengl/InputStateGL.cpp +++ b/src/backend/opengl/InputStateGL.cpp @@ -14,7 +14,6 @@ #include "backend/opengl/InputStateGL.h" -#include "backend/opengl/OpenGLBackend.h" #include "common/Assert.h" namespace backend { namespace opengl { diff --git a/src/backend/opengl/PersistentPipelineStateGL.cpp b/src/backend/opengl/PersistentPipelineStateGL.cpp index 7f0f54cade..0f88c74378 100644 --- a/src/backend/opengl/PersistentPipelineStateGL.cpp +++ b/src/backend/opengl/PersistentPipelineStateGL.cpp @@ -14,8 +14,6 @@ #include "backend/opengl/PersistentPipelineStateGL.h" -#include "backend/opengl/OpenGLBackend.h" - namespace backend { namespace opengl { void PersistentPipelineState::SetDefaultState() { diff --git a/src/backend/opengl/PipelineGL.cpp b/src/backend/opengl/PipelineGL.cpp index b33875e1b9..a71702b7dd 100644 --- a/src/backend/opengl/PipelineGL.cpp +++ b/src/backend/opengl/PipelineGL.cpp @@ -14,7 +14,8 @@ #include "backend/opengl/PipelineGL.h" -#include "backend/opengl/OpenGLBackend.h" +#include "backend/BindGroupLayout.h" +#include "backend/opengl/Forward.h" #include "backend/opengl/PersistentPipelineStateGL.h" #include "backend/opengl/PipelineLayoutGL.h" #include "backend/opengl/ShaderModuleGL.h" diff --git a/src/backend/opengl/PipelineLayoutGL.cpp b/src/backend/opengl/PipelineLayoutGL.cpp index c9c0b563ab..444246df80 100644 --- a/src/backend/opengl/PipelineLayoutGL.cpp +++ b/src/backend/opengl/PipelineLayoutGL.cpp @@ -14,7 +14,7 @@ #include "backend/opengl/PipelineLayoutGL.h" -#include "backend/opengl/OpenGLBackend.h" +#include "backend/BindGroupLayout.h" namespace backend { namespace opengl { diff --git a/src/backend/opengl/RenderPipelineGL.cpp b/src/backend/opengl/RenderPipelineGL.cpp index 96a5b3c343..057d09d1ab 100644 --- a/src/backend/opengl/RenderPipelineGL.cpp +++ b/src/backend/opengl/RenderPipelineGL.cpp @@ -16,8 +16,8 @@ #include "backend/opengl/BlendStateGL.h" #include "backend/opengl/DepthStencilStateGL.h" +#include "backend/opengl/Forward.h" #include "backend/opengl/InputStateGL.h" -#include "backend/opengl/OpenGLBackend.h" #include "backend/opengl/PersistentPipelineStateGL.h" namespace backend { namespace opengl { diff --git a/src/backend/opengl/SamplerGL.cpp b/src/backend/opengl/SamplerGL.cpp index db2eb530b3..3ad06aa9b1 100644 --- a/src/backend/opengl/SamplerGL.cpp +++ b/src/backend/opengl/SamplerGL.cpp @@ -14,7 +14,7 @@ #include "backend/opengl/SamplerGL.h" -#include "backend/opengl/OpenGLBackend.h" +#include "backend/opengl/DeviceGL.h" #include "common/Assert.h" namespace backend { namespace opengl {