From fff76bfa3e0eba3ff33de605afd020fddbbbde89 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Mon, 3 Dec 2018 16:06:03 -0800 Subject: [PATCH] Resurrect the NOOP driver. --- build/common/test_list.txt | 1 + filament/CMakeLists.txt | 1 + filament/src/driver/Platform.cpp | 9 +++++ filament/src/driver/noop/NoopDriver.cpp | 11 +++++- filament/src/driver/noop/NoopDriver.h | 7 +++- filament/src/driver/noop/PlatformNoop.cpp | 27 +++++++++++++ filament/src/driver/noop/PlatformNoop.h | 39 +++++++++++++++++++ .../include/filament/driver/DriverEnums.h | 1 + libs/filameshio/tests/test_filamesh.cpp | 2 +- 9 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 filament/src/driver/noop/PlatformNoop.cpp create mode 100644 filament/src/driver/noop/PlatformNoop.h diff --git a/build/common/test_list.txt b/build/common/test_list.txt index 09d40fb208..87f7c03459 100644 --- a/build/common/test_list.txt +++ b/build/common/test_list.txt @@ -6,3 +6,4 @@ libs/utils/test_utils libs/filamat/test_filamat tools/matc/test_matc tools/cmgen/test_cmgen compare +libs/filameshio/test_filameshio diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt index a77d914c18..8791e5a471 100644 --- a/filament/CMakeLists.txt +++ b/filament/CMakeLists.txt @@ -156,6 +156,7 @@ set(MATERIAL_SRCS # Remove it from release builds, since it uses some space needlessly. if (CMAKE_BUILD_TYPE MATCHES Debug) list(APPEND SRCS src/driver/noop/NoopDriver.cpp) + list(APPEND SRCS src/driver/noop/PlatformNoop.cpp) endif() if(IOS AND NOT FILAMENT_SUPPORTS_VULKAN) diff --git a/filament/src/driver/Platform.cpp b/filament/src/driver/Platform.cpp index 903962a914..7c0a8a9dfe 100644 --- a/filament/src/driver/Platform.cpp +++ b/filament/src/driver/Platform.cpp @@ -59,6 +59,10 @@ #endif #endif +#ifndef NDEBUG + #include "driver/noop/PlatformNoop.h" +#endif + namespace filament { namespace driver { @@ -77,6 +81,11 @@ Platform* Platform::create(Backend* backend) noexcept { if (*backend == Backend::DEFAULT) { *backend = Backend::OPENGL; } + #ifndef NDEBUG + if (*backend == Backend::NOOP) { + return new PlatformNoop(); + } + #endif if (*backend == Backend::VULKAN) { #if defined(FILAMENT_DRIVER_SUPPORTS_VULKAN) #if defined(ANDROID) diff --git a/filament/src/driver/noop/NoopDriver.cpp b/filament/src/driver/noop/NoopDriver.cpp index 1b13463dd6..e301ce4208 100644 --- a/filament/src/driver/noop/NoopDriver.cpp +++ b/filament/src/driver/noop/NoopDriver.cpp @@ -24,12 +24,19 @@ Driver* NoopDriver::create() { return new NoopDriver(); } -NoopDriver::NoopDriver() noexcept - : DriverBase(new ConcreteDispatcher(this)) { +NoopDriver::NoopDriver() noexcept : DriverBase(new ConcreteDispatcher(this)) { } NoopDriver::~NoopDriver() noexcept = default; +driver::ShaderModel NoopDriver::getShaderModel() const noexcept { +#if defined(GLES31_HEADERS) + return driver::ShaderModel::GL_CORE_30; +#else + return driver::ShaderModel::GL_CORE_41; +#endif +} + // explicit instantiation of the Dispatcher template class ConcreteDispatcher; diff --git a/filament/src/driver/noop/NoopDriver.h b/filament/src/driver/noop/NoopDriver.h index b46edd2a91..3233b95fe8 100644 --- a/filament/src/driver/noop/NoopDriver.h +++ b/filament/src/driver/noop/NoopDriver.h @@ -32,7 +32,7 @@ public: static Driver* create(); private: - ShaderModel getShaderModel() const noexcept final { return ShaderModel::UNKNOWN; } + ShaderModel getShaderModel() const noexcept final; /* * Driver interface @@ -44,8 +44,11 @@ private: #define DECL_DRIVER_API(methodName, paramsDecl, params) \ UTILS_ALWAYS_INLINE void methodName(paramsDecl) { } + // The only reason we return a non-zero value is so that "isTextureFormatSupported" + // returns true, which is necessary because Engine creates an internal 1x1 texture + // during its initialization phase. #define DECL_DRIVER_API_SYNCHRONOUS(RetType, methodName, paramsDecl, params) \ - RetType methodName(paramsDecl) override { return RetType(); } + RetType methodName(paramsDecl) override { return RetType(true); } #define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params) \ RetType methodName##Synchronous() noexcept override { \ diff --git a/filament/src/driver/noop/PlatformNoop.cpp b/filament/src/driver/noop/PlatformNoop.cpp new file mode 100644 index 0000000000..189d741d60 --- /dev/null +++ b/filament/src/driver/noop/PlatformNoop.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * 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. + */ + +#include "driver/noop/PlatformNoop.h" + +#include "driver/noop/NoopDriver.h" + +namespace filament { + +Driver* PlatformNoop::createDriver(void* const sharedGLContext) noexcept { + return NoopDriver::create(); +} + +} // namespace filament diff --git a/filament/src/driver/noop/PlatformNoop.h b/filament/src/driver/noop/PlatformNoop.h new file mode 100644 index 0000000000..47590c7105 --- /dev/null +++ b/filament/src/driver/noop/PlatformNoop.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * 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 TNT_FILAMENT_DRIVER_NOOP_PLATFORM_NOOP_H +#define TNT_FILAMENT_DRIVER_NOOP_PLATFORM_NOOP_H + +#include +#include + +namespace filament { + +class PlatformNoop final : public driver::Platform { +public: + + int getOSVersion() const noexcept final override { return 0; } + + ~PlatformNoop() noexcept override { } + +protected: + + Driver* createDriver(void* sharedContext) noexcept override; +}; + +} // namespace filament + +#endif // TNT_FILAMENT_DRIVER_NOOP_PLATFORM_NOOP_H diff --git a/libs/filabridge/include/filament/driver/DriverEnums.h b/libs/filabridge/include/filament/driver/DriverEnums.h index b4fa8c1da4..20e567e703 100644 --- a/libs/filabridge/include/filament/driver/DriverEnums.h +++ b/libs/filabridge/include/filament/driver/DriverEnums.h @@ -42,6 +42,7 @@ enum class Backend : uint8_t { DEFAULT = 0, //!< Automatically selects an appropriate driver for the platform. OPENGL = 1, //!< Selects the OpenGL driver (which supports OpenGL ES as well). VULKAN = 2, //!< Selects the Vulkan driver if the platform supports it. + NOOP = 3, //!< Selects the no-op driver for testing purposes. }; /** diff --git a/libs/filameshio/tests/test_filamesh.cpp b/libs/filameshio/tests/test_filamesh.cpp index 33951b2991..705cacdd86 100644 --- a/libs/filameshio/tests/test_filamesh.cpp +++ b/libs/filameshio/tests/test_filamesh.cpp @@ -107,7 +107,7 @@ static const InterleavedVertex interleavedVertices[] = { { class FilameshTest : public testing::Test { protected: void SetUp() override { - engine = Engine::create(Engine::Backend::OPENGL); + engine = Engine::create(Engine::Backend::NOOP); } void TearDown() override {