From a9f3971989a42f08aba554addb49e825b07a7402 Mon Sep 17 00:00:00 2001 From: Powei Feng Date: Thu, 16 May 2024 10:37:27 -0700 Subject: [PATCH] Refactor stereo build flags and configs (#7857) - Add option to build.sh to build for paritcular stereo techniques (default to NONE). Only applies to samples. - Consoldiate viewer checkbox for debugging stereo rendering - Add DriverConfig flag for stereoscopic type so that it can be used to determine availability of the feature and (to be completed) enable corresponding GPU features. Co-authored-by: Mathias Agopian --- CMakeLists.txt | 10 +++++--- .../com/google/android/filament/Engine.java | 7 ++++-- build.sh | 25 +++++++++++++++++-- .../backend/include/backend/DriverEnums.h | 9 ++----- filament/backend/include/backend/Platform.h | 25 +++++++++++++++++++ .../include/private/backend/DriverAPI.inc | 2 +- filament/backend/src/metal/MetalDriver.h | 2 ++ filament/backend/src/metal/MetalDriver.mm | 19 ++++++++------ filament/backend/src/noop/NoopDriver.cpp | 2 +- filament/backend/src/opengl/OpenGLDriver.cpp | 16 ++++++------ filament/backend/src/vulkan/VulkanDriver.cpp | 18 +++++++------ filament/backend/src/vulkan/VulkanDriver.h | 3 ++- filament/include/filament/Engine.h | 2 +- filament/src/Engine.cpp | 2 +- filament/src/details/Engine.cpp | 7 ++++-- filament/src/details/Engine.h | 4 +-- filament/src/details/Material.cpp | 3 +-- filament/src/details/Skybox.cpp | 4 ++- filament/src/details/View.cpp | 2 +- libs/filamat/src/GLSLPostProcessor.cpp | 7 +++--- libs/filamat/src/shaders/CodeGenerator.cpp | 8 ++++++ libs/filamentapp/src/FilamentApp.cpp | 2 ++ libs/viewer/CMakeLists.txt | 6 +++++ libs/viewer/src/ViewerGui.cpp | 14 ++++++++--- samples/gltf_viewer.cpp | 5 ---- 25 files changed, 141 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7809decd28..e17aba1a7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -524,13 +524,15 @@ else() endif() # This only affects the prebuilt shader files in gltfio and samples, not filament library. -# The value can be either "instanced" or "multiview". -set(FILAMENT_SAMPLES_STEREO_TYPE "instanced" CACHE STRING +# The value can be either "instanced", "multiview", or "none" +set(FILAMENT_SAMPLES_STEREO_TYPE "none" CACHE STRING "Stereoscopic type that shader files in gltfio and samples are built for." ) string(TOLOWER "${FILAMENT_SAMPLES_STEREO_TYPE}" FILAMENT_SAMPLES_STEREO_TYPE) -if (NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced" AND NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") - message(FATAL_ERROR "Invalid stereo type: \"${FILAMENT_SAMPLES_STEREO_TYPE}\" choose either \"instanced\" or \"multiview\" ") +if (NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced" + AND NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview" + AND NOT FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "none") + message(FATAL_ERROR "Invalid stereo type: \"${FILAMENT_SAMPLES_STEREO_TYPE}\" choose either \"instanced\", \"multiview\", or \"none\" ") endif () # Compiling samples for multiview implies enabling multiview feature as well. diff --git a/android/filament-android/src/main/java/com/google/android/filament/Engine.java b/android/filament-android/src/main/java/com/google/android/filament/Engine.java index 8d53c412b4..827fcf11ca 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/Engine.java +++ b/android/filament-android/src/main/java/com/google/android/filament/Engine.java @@ -159,9 +159,12 @@ public class Engine { }; /** - * The type of technique for stereoscopic rendering + * The type of technique for stereoscopic rendering. (Note that the materials used will need to be + * compatible with the chosen technique.) */ public enum StereoscopicType { + /** No stereoscopic rendering. */ + NONE, /** Stereoscopic rendering is performed using instanced rendering technique. */ INSTANCED, /** Stereoscopic rendering is performed using the multiview feature from the graphics backend. */ @@ -405,7 +408,7 @@ public class Engine { * * @see View#setStereoscopicOptions */ - public StereoscopicType stereoscopicType = StereoscopicType.INSTANCED; + public StereoscopicType stereoscopicType = StereoscopicType.NONE; /** * The number of eyes to render when stereoscopic rendering is enabled. Supported values are diff --git a/build.sh b/build.sh index f2c986344d..ab6440f45d 100755 --- a/build.sh +++ b/build.sh @@ -64,6 +64,9 @@ function print_help { echo " enabling debug paths in the backend from the build script. For example, make a" echo " systrace-enabled build without directly changing #defines. Remember to add -f when" echo " changing this option." + echo " -S type" + echo " Enable stereoscopic rendering where type is one of [instanced|multiview]. This is only" + echo " meant for building the samples." echo "" echo "Build types:" echo " release" @@ -175,6 +178,8 @@ ASAN_UBSAN_OPTION="" BACKEND_DEBUG_FLAG_OPTION="" +STEREOSCOPIC_OPTION="" + IOS_BUILD_SIMULATOR=false BUILD_UNIVERSAL_LIBRARIES=false @@ -234,6 +239,7 @@ function build_desktop_target { ${MATOPT_OPTION} \ ${ASAN_UBSAN_OPTION} \ ${BACKEND_DEBUG_FLAG_OPTION} \ + ${STEREOSCOPIC_OPTION} \ ${architectures} \ ../.. ln -sf "out/cmake-${lc_target}/compile_commands.json" \ @@ -368,6 +374,7 @@ function build_android_target { ${MATOPT_OPTION} \ ${VULKAN_ANDROID_OPTION} \ ${BACKEND_DEBUG_FLAG_OPTION} \ + ${STEREOSCOPIC_OPTION} \ ../.. ln -sf "out/cmake-android-${lc_target}-${arch}/compile_commands.json" \ ../../compile_commands.json @@ -602,7 +609,7 @@ function build_ios_target { -DCMAKE_TOOLCHAIN_FILE=../../third_party/clang/iOS.cmake \ ${MATDBG_OPTION} \ ${MATOPT_OPTION} \ - ${BACKEND_DEBUG_FLAG_OPTION} \ + ${STEREOSCOPIC_OPTION} \ ../.. ln -sf "out/cmake-ios-${lc_target}-${arch}/compile_commands.json" \ ../../compile_commands.json @@ -789,7 +796,7 @@ function check_debug_release_build { pushd "$(dirname "$0")" > /dev/null -while getopts ":hacCfgijmp:q:uvslwedk:bx:" opt; do +while getopts ":hacCfgijmp:q:uvslwedk:bx:S:" opt; do case ${opt} in h) print_help @@ -929,6 +936,20 @@ while getopts ":hacCfgijmp:q:uvslwedk:bx:" opt; do ;; x) BACKEND_DEBUG_FLAG_OPTION="-DFILAMENT_BACKEND_DEBUG_FLAG=${OPTARG}" ;; + S) case $(echo "${OPTARG}" | tr '[:upper:]' '[:lower:]') in + instanced) + STEREOSCOPIC_OPTION="-DFILAMENT_SAMPLES_STEREO_TYPE=instanced" + ;; + multiview) + STEREOSCOPIC_OPTION="-DFILAMENT_SAMPLES_STEREO_TYPE=multiview" + ;; + *) + echo "Unknown stereoscopic type ${OPTARG}" + echo "Type must be one of [instanced|multiview]" + echo "" + exit 1 + esac + ;; \?) echo "Invalid option: -${OPTARG}" >&2 echo "" diff --git a/filament/backend/include/backend/DriverEnums.h b/filament/backend/include/backend/DriverEnums.h index 490b889fa2..c6965a17e5 100644 --- a/filament/backend/include/backend/DriverEnums.h +++ b/filament/backend/include/backend/DriverEnums.h @@ -22,6 +22,7 @@ #include #include // Because we define ERROR in the FenceStatus enum. +#include #include #include @@ -1250,13 +1251,7 @@ enum class Workaround : uint16_t { POWER_VR_SHADER_WORKAROUNDS, }; -//! The type of technique for stereoscopic rendering -enum class StereoscopicType : uint8_t { - // Stereoscopic rendering is performed using instanced rendering technique. - INSTANCED, - // Stereoscopic rendering is performed using the multiview feature from the graphics backend. - MULTIVIEW, -}; +using StereoscopicType = backend::Platform::StereoscopicType; } // namespace filament::backend diff --git a/filament/backend/include/backend/Platform.h b/filament/backend/include/backend/Platform.h index 45b0bb8268..4f73c4375c 100644 --- a/filament/backend/include/backend/Platform.h +++ b/filament/backend/include/backend/Platform.h @@ -41,6 +41,26 @@ public: struct Fence {}; struct Stream {}; + /** + * The type of technique for stereoscopic rendering. (Note that the materials used will need to + * be compatible with the chosen technique.) + */ + enum class StereoscopicType : uint8_t { + /** + * No stereoscopic rendering + */ + NONE, + /** + * Stereoscopic rendering is performed using instanced rendering technique. + */ + INSTANCED, + /** + * Stereoscopic rendering is performed using the multiview feature from the graphics + * backend. + */ + MULTIVIEW, + }; + struct DriverConfig { /** * Size of handle arena in bytes. Setting to 0 indicates default value is to be used. @@ -71,6 +91,11 @@ public: * GLES 3.x backends. */ bool forceGLES2Context = false; + + /** + * Sets the technique for stereoscopic rendering. + */ + StereoscopicType stereoscopicType = StereoscopicType::NONE; }; Platform() noexcept; diff --git a/filament/backend/include/private/backend/DriverAPI.inc b/filament/backend/include/private/backend/DriverAPI.inc index bb64f3d436..b92a07f37b 100644 --- a/filament/backend/include/private/backend/DriverAPI.inc +++ b/filament/backend/include/private/backend/DriverAPI.inc @@ -300,7 +300,7 @@ DECL_DRIVER_API_SYNCHRONOUS_0(bool, isFrameTimeSupported) DECL_DRIVER_API_SYNCHRONOUS_0(bool, isAutoDepthResolveSupported) DECL_DRIVER_API_SYNCHRONOUS_0(bool, isSRGBSwapChainSupported) DECL_DRIVER_API_SYNCHRONOUS_0(bool, isProtectedContentSupported) -DECL_DRIVER_API_SYNCHRONOUS_N(bool, isStereoSupported, backend::StereoscopicType, stereoscopicType) +DECL_DRIVER_API_SYNCHRONOUS_0(bool, isStereoSupported) DECL_DRIVER_API_SYNCHRONOUS_0(bool, isParallelShaderCompileSupported) DECL_DRIVER_API_SYNCHRONOUS_0(bool, isDepthStencilResolveSupported) DECL_DRIVER_API_SYNCHRONOUS_N(bool, isDepthStencilBlitSupported, backend::TextureFormat, format) diff --git a/filament/backend/src/metal/MetalDriver.h b/filament/backend/src/metal/MetalDriver.h index 51cd7902dd..e38b65b375 100644 --- a/filament/backend/src/metal/MetalDriver.h +++ b/filament/backend/src/metal/MetalDriver.h @@ -17,6 +17,7 @@ #ifndef TNT_FILAMENT_DRIVER_METALDRIVER_H #define TNT_FILAMENT_DRIVER_METALDRIVER_H +#include #include "private/backend/Driver.h" #include "DriverBase.h" @@ -140,6 +141,7 @@ private: void enumerateBoundBuffers(BufferObjectBinding bindingType, const std::function& f); + backend::StereoscopicType const mStereoscopicType; }; } // namespace backend diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index 0172be1ce1..043a7b02db 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -102,7 +102,8 @@ MetalDriver::MetalDriver(MetalPlatform* platform, const Platform::DriverConfig& mContext(new MetalContext(driverConfig.textureUseAfterFreePoolSize)), mHandleAllocator("Handles", driverConfig.handleArenaSize, - driverConfig.disableHandleUseAfterFreeCheck) { + driverConfig.disableHandleUseAfterFreeCheck), + mStereoscopicType(driverConfig.stereoscopicType) { mContext->driver = this; ScopedAllocationTimer::setPlatform(platform); @@ -803,13 +804,15 @@ bool MetalDriver::isProtectedContentSupported() { return false; } -bool MetalDriver::isStereoSupported(backend::StereoscopicType stereoscopicType) { - switch (stereoscopicType) { - case backend::StereoscopicType::INSTANCED: - return true; - case backend::StereoscopicType::MULTIVIEW: - // TODO: implement multiview feature in Metal. - return false; +bool MetalDriver::isStereoSupported() { + switch (mStereoscopicType) { + case backend::StereoscopicType::INSTANCED: + return true; + case backend::StereoscopicType::MULTIVIEW: + // TODO: implement multiview feature in Metal. + return false; + case backend::StereoscopicType::NONE: + return false; } } diff --git a/filament/backend/src/noop/NoopDriver.cpp b/filament/backend/src/noop/NoopDriver.cpp index 4b4b73fe18..ea5c526402 100644 --- a/filament/backend/src/noop/NoopDriver.cpp +++ b/filament/backend/src/noop/NoopDriver.cpp @@ -182,7 +182,7 @@ bool NoopDriver::isProtectedContentSupported() { return false; } -bool NoopDriver::isStereoSupported(backend::StereoscopicType) { +bool NoopDriver::isStereoSupported() { return false; } diff --git a/filament/backend/src/opengl/OpenGLDriver.cpp b/filament/backend/src/opengl/OpenGLDriver.cpp index 38d82a6866..884db62459 100644 --- a/filament/backend/src/opengl/OpenGLDriver.cpp +++ b/filament/backend/src/opengl/OpenGLDriver.cpp @@ -2050,19 +2050,19 @@ bool OpenGLDriver::isProtectedContentSupported() { return mPlatform.isProtectedContextSupported(); } -bool OpenGLDriver::isStereoSupported(backend::StereoscopicType stereoscopicType) { +bool OpenGLDriver::isStereoSupported() { // Instanced-stereo requires instancing and EXT_clip_cull_distance. // Multiview-stereo requires ES 3.0 and OVR_multiview2. if (UTILS_UNLIKELY(mContext.isES2())) { return false; } - switch (stereoscopicType) { - case backend::StereoscopicType::INSTANCED: - return mContext.ext.EXT_clip_cull_distance; - case backend::StereoscopicType::MULTIVIEW: - return mContext.ext.OVR_multiview2; - default: - return false; + switch (mDriverConfig.stereoscopicType) { + case backend::StereoscopicType::INSTANCED: + return mContext.ext.EXT_clip_cull_distance; + case backend::StereoscopicType::MULTIVIEW: + return mContext.ext.OVR_multiview2; + case backend::StereoscopicType::NONE: + return false; } } diff --git a/filament/backend/src/vulkan/VulkanDriver.cpp b/filament/backend/src/vulkan/VulkanDriver.cpp index e0f62822bf..e9c4f499ce 100644 --- a/filament/backend/src/vulkan/VulkanDriver.cpp +++ b/filament/backend/src/vulkan/VulkanDriver.cpp @@ -228,7 +228,8 @@ VulkanDriver::VulkanDriver(VulkanPlatform* platform, VulkanContext const& contex mBlitter(mPlatform->getPhysicalDevice(), &mCommands), mReadPixels(mPlatform->getDevice()), mDescriptorSetManager(mPlatform->getDevice(), &mResourceAllocator), - mIsSRGBSwapChainSupported(mPlatform->getCustomization().isSRGBSwapChainSupported) { + mIsSRGBSwapChainSupported(mPlatform->getCustomization().isSRGBSwapChainSupported), + mStereoscopicType(driverConfig.stereoscopicType) { #if FVK_ENABLED(FVK_DEBUG_DEBUG_UTILS) DebugUtils::mSingleton = @@ -899,13 +900,14 @@ bool VulkanDriver::isProtectedContentSupported() { return false; } -bool VulkanDriver::isStereoSupported(backend::StereoscopicType stereoscopicType) { - switch (stereoscopicType) { - case backend::StereoscopicType::INSTANCED: - return true; - case backend::StereoscopicType::MULTIVIEW: - // TODO: implement multiview feature in Vulkan. - return false; +bool VulkanDriver::isStereoSupported() { + switch (mStereoscopicType) { + case backend::StereoscopicType::INSTANCED: + return true; + case backend::StereoscopicType::MULTIVIEW: + // TODO: implement multiview feature in Vulkan. + case backend::StereoscopicType::NONE: + return false; } } diff --git a/filament/backend/src/vulkan/VulkanDriver.h b/filament/backend/src/vulkan/VulkanDriver.h index 2ededd06c2..abdbc6304f 100644 --- a/filament/backend/src/vulkan/VulkanDriver.h +++ b/filament/backend/src/vulkan/VulkanDriver.h @@ -28,6 +28,7 @@ #include "VulkanSamplerCache.h" #include "VulkanStagePool.h" #include "VulkanUtility.h" +#include "backend/DriverEnums.h" #include "caching/VulkanDescriptorSetManager.h" #include "caching/VulkanPipelineLayoutCache.h" @@ -166,10 +167,10 @@ private: VkPipelineLayout pipelineLayout; }; BoundPipeline mBoundPipeline = {}; - RenderPassFboBundle mRenderPassFboInfo; bool const mIsSRGBSwapChainSupported; + backend::StereoscopicType const mStereoscopicType; }; } // namespace filament::backend diff --git a/filament/include/filament/Engine.h b/filament/include/filament/Engine.h index e77fc5f45f..bade124fbe 100644 --- a/filament/include/filament/Engine.h +++ b/filament/include/filament/Engine.h @@ -315,7 +315,7 @@ public: * * @see View::setStereoscopicOptions */ - StereoscopicType stereoscopicType = StereoscopicType::INSTANCED; + StereoscopicType stereoscopicType = StereoscopicType::NONE; /* * The number of eyes to render when stereoscopic rendering is enabled. Supported values are diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp index ca370bc85c..75e16b109b 100644 --- a/filament/src/Engine.cpp +++ b/filament/src/Engine.cpp @@ -355,7 +355,7 @@ const Engine::Config& Engine::getConfig() const noexcept { } bool Engine::isStereoSupported(StereoscopicType stereoscopicType) const noexcept { - return downcast(this)->isStereoSupported(stereoscopicType); + return downcast(this)->isStereoSupported(); } size_t Engine::getMaxStereoscopicEyes() noexcept { diff --git a/filament/src/details/Engine.cpp b/filament/src/details/Engine.cpp index 0f8077bb09..fa75cf93ed 100644 --- a/filament/src/details/Engine.cpp +++ b/filament/src/details/Engine.cpp @@ -103,7 +103,8 @@ Engine* FEngine::create(Engine::Builder const& builder) { .textureUseAfterFreePoolSize = instance->getConfig().textureUseAfterFreePoolSize, .disableParallelShaderCompile = instance->getConfig().disableParallelShaderCompile, .disableHandleUseAfterFreeCheck = instance->getConfig().disableHandleUseAfterFreeCheck, - .forceGLES2Context = instance->getConfig().forceGLES2Context + .forceGLES2Context = instance->getConfig().forceGLES2Context, + .stereoscopicType = instance->getConfig().stereoscopicType, }; instance->mDriver = platform->createDriver(sharedContext, driverConfig); @@ -352,6 +353,7 @@ void FEngine::init() { FMaterial::DefaultMaterialBuilder defaultMaterialBuilder; switch (mConfig.stereoscopicType) { + case StereoscopicType::NONE: case StereoscopicType::INSTANCED: defaultMaterialBuilder.package( MATERIALS_DEFAULTMATERIAL_DATA, MATERIALS_DEFAULTMATERIAL_SIZE); @@ -675,7 +677,8 @@ int FEngine::loop() { .textureUseAfterFreePoolSize = mConfig.textureUseAfterFreePoolSize, .disableParallelShaderCompile = mConfig.disableParallelShaderCompile, .disableHandleUseAfterFreeCheck = mConfig.disableHandleUseAfterFreeCheck, - .forceGLES2Context = mConfig.forceGLES2Context + .forceGLES2Context = mConfig.forceGLES2Context, + .stereoscopicType = mConfig.stereoscopicType, }; mDriver = mPlatform->createDriver(mSharedGLContext, driverConfig); diff --git a/filament/src/details/Engine.h b/filament/src/details/Engine.h index 5d72ac9c2e..a0de5720b2 100644 --- a/filament/src/details/Engine.h +++ b/filament/src/details/Engine.h @@ -184,8 +184,8 @@ public: return CONFIG_MAX_INSTANCES; } - bool isStereoSupported(StereoscopicType stereoscopicType) const noexcept { - return getDriver().isStereoSupported(stereoscopicType); + bool isStereoSupported() const noexcept { + return getDriver().isStereoSupported(); } static size_t getMaxStereoscopicEyes() noexcept { diff --git a/filament/src/details/Material.cpp b/filament/src/details/Material.cpp index 80011d7f31..e0d2f86984 100644 --- a/filament/src/details/Material.cpp +++ b/filament/src/details/Material.cpp @@ -385,8 +385,7 @@ void FMaterial::compile(CompilerPriorityQueue priority, utils::Invocable&& callback) noexcept { // Turn off the STE variant if stereo is not supported. - const StereoscopicType stereoscopicType = mEngine.getConfig().stereoscopicType; - if (!mEngine.getDriverApi().isStereoSupported(stereoscopicType)) { + if (!mEngine.getDriverApi().isStereoSupported()) { variantSpec &= ~UserVariantFilterMask(UserVariantFilterBit::STE); } diff --git a/filament/src/details/Skybox.cpp b/filament/src/details/Skybox.cpp index 311e5f4b2f..07da628051 100644 --- a/filament/src/details/Skybox.cpp +++ b/filament/src/details/Skybox.cpp @@ -132,6 +132,7 @@ FMaterial const* FSkybox::createMaterial(FEngine& engine) { #endif { switch (engine.getConfig().stereoscopicType) { + case Engine::StereoscopicType::NONE: case Engine::StereoscopicType::INSTANCED: builder.package(MATERIALS_SKYBOX_DATA, MATERIALS_SKYBOX_SIZE); break; @@ -139,7 +140,8 @@ FMaterial const* FSkybox::createMaterial(FEngine& engine) { #ifdef FILAMENT_ENABLE_MULTIVIEW builder.package(MATERIALS_SKYBOX_MULTIVIEW_DATA, MATERIALS_SKYBOX_MULTIVIEW_SIZE); #else - assert_invariant(false); + PANIC_POSTCONDITION("Multiview is enabled in the Engine, but this build has not " + "been compiled for multiview."); #endif break; } diff --git a/filament/src/details/View.cpp b/filament/src/details/View.cpp index 19b50ce776..7b7d160cb4 100644 --- a/filament/src/details/View.cpp +++ b/filament/src/details/View.cpp @@ -60,7 +60,7 @@ static constexpr float PID_CONTROLLER_Kd = 0.0f; FView::FView(FEngine& engine) : mFroxelizer(engine), mFogEntity(engine.getEntityManager().create()), - mIsStereoSupported(engine.getDriverApi().isStereoSupported(engine.getConfig().stereoscopicType)), + mIsStereoSupported(engine.getDriverApi().isStereoSupported()), mPerViewUniforms(engine) { DriverApi& driver = engine.getDriverApi(); diff --git a/libs/filamat/src/GLSLPostProcessor.cpp b/libs/filamat/src/GLSLPostProcessor.cpp index 6765b122f5..5ee352a9c9 100644 --- a/libs/filamat/src/GLSLPostProcessor.cpp +++ b/libs/filamat/src/GLSLPostProcessor.cpp @@ -539,15 +539,16 @@ bool GLSLPostProcessor::fullOptimization(const TShader& tShader, if (config.variant.hasStereo() && config.shaderType == ShaderStage::VERTEX) { switch (config.materialInfo->stereoscopicType) { - case StereoscopicType::INSTANCED: - // Nothing to generate - break; case StereoscopicType::MULTIVIEW: // For stereo variants using multiview feature, this generates the shader code below. // #extension GL_OVR_multiview2 : require // layout(num_views = 2) in; glslOptions.ovr_multiview_view_count = config.materialInfo->stereoscopicEyeCount; break; + case StereoscopicType::INSTANCED: + case StereoscopicType::NONE: + // Nothing to generate + break; } } diff --git a/libs/filamat/src/shaders/CodeGenerator.cpp b/libs/filamat/src/shaders/CodeGenerator.cpp index 09a085a407..75d2b940d8 100644 --- a/libs/filamat/src/shaders/CodeGenerator.cpp +++ b/libs/filamat/src/shaders/CodeGenerator.cpp @@ -78,6 +78,8 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade case StereoscopicType::MULTIVIEW: out << "#extension GL_OVR_multiview2 : require\n"; break; + case StereoscopicType::NONE: + break; } } break; @@ -99,6 +101,8 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade case StereoscopicType::MULTIVIEW: out << "#extension GL_OVR_multiview2 : require\n"; break; + case StereoscopicType::NONE: + break; } } break; @@ -120,6 +124,8 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade case StereoscopicType::MULTIVIEW: out << "layout(num_views = " << material.stereoscopicEyeCount << ") in;\n"; break; + case StereoscopicType::NONE: + break; } } @@ -217,6 +223,8 @@ utils::io::sstream& CodeGenerator::generateProlog(utils::io::sstream& out, Shade case StereoscopicType::MULTIVIEW: generateDefine(out, "FILAMENT_STEREO_MULTIVIEW", true); break; + case StereoscopicType::NONE: + break; } if (stage == ShaderStage::VERTEX) { diff --git a/libs/filamentapp/src/FilamentApp.cpp b/libs/filamentapp/src/FilamentApp.cpp index 043fb4c950..635f482ccf 100644 --- a/libs/filamentapp/src/FilamentApp.cpp +++ b/libs/filamentapp/src/FilamentApp.cpp @@ -619,6 +619,8 @@ FilamentApp::Window::Window(FilamentApp* filamentApp, engineConfig.stereoscopicType = Engine::StereoscopicType::INSTANCED; #elif defined (FILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) engineConfig.stereoscopicType = Engine::StereoscopicType::MULTIVIEW; +#else + engineConfig.stereoscopicType = Engine::StereoscopicType::NONE; #endif if (backend == Engine::Backend::VULKAN) { diff --git a/libs/viewer/CMakeLists.txt b/libs/viewer/CMakeLists.txt index 5d2a13ecbc..58fe66c98f 100644 --- a/libs/viewer/CMakeLists.txt +++ b/libs/viewer/CMakeLists.txt @@ -34,6 +34,12 @@ target_link_libraries(${TARGET} PUBLIC imgui filament gltfio_core filagui jsmn c target_include_directories(${TARGET} PUBLIC ${PUBLIC_HDR_DIR}) set_target_properties(${TARGET} PROPERTIES FOLDER Libs) +if (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "instanced") + add_definitions(-DFILAMENT_SAMPLES_STEREO_TYPE_INSTANCED) +elseif (FILAMENT_SAMPLES_STEREO_TYPE STREQUAL "multiview") + add_definitions(-DFILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) +endif () + # ================================================================================================== # Compiler flags # ================================================================================================== diff --git a/libs/viewer/src/ViewerGui.cpp b/libs/viewer/src/ViewerGui.cpp index 216288d3f8..d29868c185 100644 --- a/libs/viewer/src/ViewerGui.cpp +++ b/libs/viewer/src/ViewerGui.cpp @@ -1094,9 +1094,17 @@ void ViewerGui::updateUserInterface() { ImGui::ListBox("Cameras", &mCurrentCamera, cstrings.data(), cstrings.size()); } - ImGui::Checkbox("Instanced stereo", &mSettings.view.stereoscopicOptions.enabled); - ImGui::SliderFloat( - "Ocular distance", &mSettings.viewer.cameraEyeOcularDistance, 0.0f, 1.0f); +#if defined(FILAMENT_SAMPLES_STEREO_TYPE_INSTANCED) \ + || defined(FILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) + ImGui::Checkbox("Stereo mode", &mSettings.view.stereoscopicOptions.enabled); + + #if defined(FILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) + *debug.getPropertyAddress("d.stereo.combine_multiview_images") + = mSettings.view.stereoscopicOptions.enabled; + #endif +#endif + ImGui::SliderFloat("Ocular distance", &mSettings.viewer.cameraEyeOcularDistance, 0.0f, + 1.0f); float toeInDegrees = mSettings.viewer.cameraEyeToeIn / f::PI * 180.0f; ImGui::SliderFloat("Toe in", &toeInDegrees, 0.0f, 30.0, "%.3f°"); diff --git a/samples/gltf_viewer.cpp b/samples/gltf_viewer.cpp index 80a06298e7..b846fea6f9 100644 --- a/samples/gltf_viewer.cpp +++ b/samples/gltf_viewer.cpp @@ -893,11 +893,6 @@ int main(int argc, char** argv) { "d.shadowmap.display_shadow_texture_channel"), 0, 3); ImGui::Unindent(); } -#if defined(FILAMENT_SAMPLES_STEREO_TYPE_MULTIVIEW) - ImGui::Checkbox("Combine Multiview Images", - debug.getPropertyAddress("d.stereo.combine_multiview_images")); -#endif - bool debugFroxelVisualization; if (debug.getProperty("d.lighting.debug_froxel_visualization", &debugFroxelVisualization)) {