diff --git a/filament/src/driver/CommandStream.h b/filament/src/driver/CommandStream.h index 1d43d4f327..4613b14aeb 100644 --- a/filament/src/driver/CommandStream.h +++ b/filament/src/driver/CommandStream.h @@ -119,6 +119,8 @@ struct CommandType { /* * Command is templated on a specific method of Driver, using CommandType's template * parameter. + * Note that we're never calling this method (which is why it doesn't appear in the + * template parameter below). The actual call is made through Command::execute(). */ template class Command : public CommandBase { @@ -158,6 +160,9 @@ struct CommandType { }; }; +// convert an method of "class Driver" into a Command<> type +#define COMMAND_TYPE(method) CommandType::Command<&Driver::method> + // ------------------------------------------------------------------------------------------------ class CustomCommand : public CommandBase { @@ -196,8 +201,7 @@ public: #define DECL_DRIVER_API(methodName, paramsDecl, params) \ inline void methodName(paramsDecl) { \ DEBUG_COMMAND(methodName, params); \ - using CmdType = CommandType; \ - using Cmd = CmdType::Command<&Driver::methodName>; \ + using Cmd = COMMAND_TYPE(methodName); \ void* const p = allocateCommand(CommandBase::align(sizeof(Cmd))); \ new(p) Cmd(mDispatcher->methodName##_, params); \ } @@ -212,8 +216,7 @@ public: inline RetType methodName(paramsDecl) { \ DEBUG_COMMAND(methodName, params); \ RetType result = mDriver->methodName##S(); \ - using CmdType = CommandType; \ - using Cmd = CmdType::Command<&Driver::methodName##R>; \ + using Cmd = COMMAND_TYPE(methodName##R); \ void* const p = allocateCommand(CommandBase::align(sizeof(Cmd))); \ new(p) Cmd(mDispatcher->methodName##_, RetType(result), params); \ return result; \ diff --git a/filament/src/driver/CommandStreamDispatcher.h b/filament/src/driver/CommandStreamDispatcher.h index 4c72ff8609..788b47a7b9 100644 --- a/filament/src/driver/CommandStreamDispatcher.h +++ b/filament/src/driver/CommandStreamDispatcher.h @@ -50,10 +50,10 @@ template class ConcreteDispatcher final : public Dispatcher { public: // initialize the dispatch table - explicit ConcreteDispatcher(ConcreteDriver* driver) noexcept : Dispatcher() { + explicit ConcreteDispatcher() noexcept : Dispatcher() { #define DECL_DRIVER_API_SYNCHRONOUS(RetType, methodName, paramsDecl, params) -#define DECL_DRIVER_API(methodName, paramsDecl, params) methodName##_ = methodName; -#define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params) methodName##_ = methodName; +#define DECL_DRIVER_API(methodName, paramsDecl, params) methodName##_ = &ConcreteDispatcher::methodName; +#define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params) methodName##_ = &ConcreteDispatcher::methodName; #include "driver/DriverAPI.inc" } private: @@ -61,16 +61,14 @@ private: #define DECL_DRIVER_API(methodName, paramsDecl, params) \ static void methodName(Driver& driver, CommandBase* base, intptr_t* next) { \ SYSTRACE() \ - using Type = CommandType; \ - using Cmd = typename Type::template Command<&Driver::methodName>; \ + using Cmd = COMMAND_TYPE(methodName); \ ConcreteDriver& concreteDriver = static_cast(driver); \ Cmd::execute(&ConcreteDriver::methodName, concreteDriver, base, next); \ } #define DECL_DRIVER_API_RETURN(RetType, methodName, paramsDecl, params) \ static void methodName(Driver& driver, CommandBase* base, intptr_t* next) { \ SYSTRACE() \ - using Type = CommandType; \ - using Cmd = typename Type::template Command<&Driver::methodName##R>; \ + using Cmd = COMMAND_TYPE(methodName##R); \ ConcreteDriver& concreteDriver = static_cast(driver); \ Cmd::execute(&ConcreteDriver::methodName##R, concreteDriver, base, next); \ } diff --git a/filament/src/driver/metal/MetalDriver.mm b/filament/src/driver/metal/MetalDriver.mm index 1d5e5b49e7..6583392324 100644 --- a/filament/src/driver/metal/MetalDriver.mm +++ b/filament/src/driver/metal/MetalDriver.mm @@ -85,7 +85,7 @@ Driver* MetalDriver::create(MetalPlatform* const platform) { } MetalDriver::MetalDriver(driver::MetalPlatform* platform) noexcept - : DriverBase(new ConcreteDispatcher(this)), + : DriverBase(new ConcreteDispatcher()), mPlatform(*platform), pImpl(new MetalDriverImpl) { pImpl->mDriverPool = [[NSAutoreleasePool alloc] init]; diff --git a/filament/src/driver/noop/NoopDriver.cpp b/filament/src/driver/noop/NoopDriver.cpp index 230d56adaa..7461de761e 100644 --- a/filament/src/driver/noop/NoopDriver.cpp +++ b/filament/src/driver/noop/NoopDriver.cpp @@ -28,7 +28,7 @@ Driver* NoopDriver::create() { return new NoopDriver(); } -NoopDriver::NoopDriver() noexcept : DriverBase(new ConcreteDispatcher(this)) { +NoopDriver::NoopDriver() noexcept : DriverBase(new ConcreteDispatcher()) { } NoopDriver::~NoopDriver() noexcept = default; diff --git a/filament/src/driver/opengl/OpenGLDriver.cpp b/filament/src/driver/opengl/OpenGLDriver.cpp index 7498ee75b3..7d426510bf 100644 --- a/filament/src/driver/opengl/OpenGLDriver.cpp +++ b/filament/src/driver/opengl/OpenGLDriver.cpp @@ -98,7 +98,7 @@ Driver* OpenGLDriver::create( } OpenGLDriver::OpenGLDriver(OpenGLPlatform* platform) noexcept - : DriverBase(new ConcreteDispatcher(this)), + : DriverBase(new ConcreteDispatcher()), mHandleArena("Handles", 2U * 1024U * 1024U), // TODO: set the amount in configuration mSamplerMap(32), mPlatform(*platform) { diff --git a/filament/src/driver/vulkan/VulkanDriver.cpp b/filament/src/driver/vulkan/VulkanDriver.cpp index 581f58df00..59041a304e 100644 --- a/filament/src/driver/vulkan/VulkanDriver.cpp +++ b/filament/src/driver/vulkan/VulkanDriver.cpp @@ -40,7 +40,7 @@ namespace driver { VulkanDriver::VulkanDriver(VulkanPlatform* platform, const char* const* ppEnabledExtensions, uint32_t enabledExtensionCount) noexcept : - DriverBase(new ConcreteDispatcher(this)), + DriverBase(new ConcreteDispatcher()), mContextManager(*platform), mStagePool(mContext), mFramebufferCache(mContext), mSamplerCache(mContext) { mContext.rasterState = mBinder.getDefaultRasterState();