Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to retrieve the GL_RENDERER and GL_VENDOR strings #8383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,13 @@ enum class Workaround : uint16_t {

using StereoscopicType = backend::Platform::StereoscopicType;

enum class BackendString : uint8_t {
// OpenGL backend only. Return the GL_VENDOR string.
VENDOR,
// OpenGL backend only. Return the GL_RENDERER string.
RENDERER
};

} // namespace filament::backend

template<> struct utils::EnableBitMaskOperators<filament::backend::ShaderStageFlags>
Expand Down
1 change: 1 addition & 0 deletions filament/backend/include/private/backend/DriverAPI.inc
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ DECL_DRIVER_API_SYNCHRONOUS_N(void, setupExternalImage, void*, image)
DECL_DRIVER_API_SYNCHRONOUS_N(backend::TimerQueryResult, getTimerQueryValue, backend::TimerQueryHandle, query, uint64_t*, elapsedTime)
DECL_DRIVER_API_SYNCHRONOUS_N(bool, isWorkaroundNeeded, backend::Workaround, workaround)
DECL_DRIVER_API_SYNCHRONOUS_0(backend::FeatureLevel, getFeatureLevel)
DECL_DRIVER_API_SYNCHRONOUS_N(char const*, getString, backend::BackendString, stringName)

/*
* Updating driver objects
Expand Down
4 changes: 4 additions & 0 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@
return FeatureLevel::FEATURE_LEVEL_2;
}

char const* MetalDriver::getString(backend::BackendString) {
return nullptr;
}

math::float2 MetalDriver::getClipSpaceParams() {
// virtual and physical z-coordinate of clip-space is in [-w, 0]
// Note: this is actually never used (see: main.vs), but it's a backend API so we implement it
Expand Down
9 changes: 9 additions & 0 deletions filament/backend/src/noop/NoopDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
* limitations under the License.
*/

#include <backend/DriverEnums.h>
#include <backend/Handle.h>

#include "noop/NoopDriver.h"
#include "CommandStreamDispatcher.h"

#include<stdint.h>

namespace filament::backend {

Driver* NoopDriver::create() {
Expand Down Expand Up @@ -217,6 +222,10 @@ FeatureLevel NoopDriver::getFeatureLevel() {
return FeatureLevel::FEATURE_LEVEL_1;
}

char const* NoopDriver::getString(backend::BackendString) {
return nullptr;
}

math::float2 NoopDriver::getClipSpaceParams() {
return math::float2{ 1.0f, 0.0f };
}
Expand Down
10 changes: 10 additions & 0 deletions filament/backend/src/opengl/OpenGLDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,16 @@ FeatureLevel OpenGLDriver::getFeatureLevel() {
return mContext.getFeatureLevel();
}

char const* OpenGLDriver::getString(BackendString stringName) {
switch (stringName) {
case BackendString::VENDOR:
return mContext.state.vendor;
case BackendString::RENDERER:
return mContext.state.renderer;
}
return nullptr;
}

math::float2 OpenGLDriver::getClipSpaceParams() {
return mContext.ext.EXT_clip_control ?
// z-coordinate of virtual and physical clip-space is in [-w, 0]
Expand Down
4 changes: 4 additions & 0 deletions filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,10 @@ FeatureLevel VulkanDriver::getFeatureLevel() {
return FeatureLevel::FEATURE_LEVEL_3;
}

char const* VulkanDriver::getString(backend::BackendString) {
return nullptr;
}

math::float2 VulkanDriver::getClipSpaceParams() {
// virtual and physical z-coordinate of clip-space is in [-w, 0]
// Note: this is actually never used (see: main.vs), but it's a backend API, so we implement it
Expand Down
15 changes: 15 additions & 0 deletions filament/include/filament/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,21 @@ class UTILS_PUBLIC Engine {
*/
static void destroy(Engine* UTILS_NULLABLE engine);


/**
* This is only available with the OpenGL backend.
* @see getBackend
* @return GL_VENDOR string or nullptr if the backend is not OpenGL.
*/
char const* UTILS_NULLABLE getVendorString() const noexcept;

/**
* This is only available with the OpenGL backend.
* @see getBackend
* @return GL_RENDERER string or nullptr if the backend is not OpenGL.
*/
char const* UTILS_NULLABLE getRendererString() const noexcept;

/**
* Query the feature level supported by the selected backend.
*
Expand Down
8 changes: 8 additions & 0 deletions filament/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ void Engine::destroy(Engine** pEngine) {
}
}

char const* Engine::getVendorString() const noexcept {
return downcast(this)->getVendorString();
}

char const* Engine::getRendererString() const noexcept {
return downcast(this)->getRendererString();
}

// -----------------------------------------------------------------------------------------------
// Resource management
// -----------------------------------------------------------------------------------------------
Expand Down
17 changes: 13 additions & 4 deletions filament/src/details/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#include <filament/Texture.h>
#include <filament/VertexBuffer.h>

#include <backend/DriverEnums.h>

#include <utils/Allocator.h>
#include <utils/compiler.h>
#include <utils/CountDownLatch.h>
Expand Down Expand Up @@ -114,12 +116,11 @@ class ResourceAllocator;
*/
class FEngine : public Engine {
public:

inline void* operator new(std::size_t const size) noexcept {
void* operator new(std::size_t const size) noexcept {
return utils::aligned_alloc(size, alignof(FEngine));
}

inline void operator delete(void* p) noexcept {
void operator delete(void* p) noexcept {
utils::aligned_free(p);
}

Expand All @@ -140,6 +141,14 @@ class FEngine : public Engine {

~FEngine() noexcept;

char const* getVendorString() const noexcept {
return getDriver().getString(backend::BackendString::VENDOR);
}

char const* getRendererString() const noexcept {
return getDriver().getString(backend::BackendString::RENDERER);
}

backend::ShaderModel getShaderModel() const noexcept { return getDriver().getShaderModel(); }

DriverApi& getDriverApi() noexcept {
Expand Down Expand Up @@ -489,7 +498,7 @@ class FEngine : public Engine {
backend::Handle<backend::HwTexture> getOneTextureArray() const { return mDummyOneTextureArray; }
backend::Handle<backend::HwTexture> getZeroTextureArray() const { return mDummyZeroTextureArray; }

static constexpr const size_t MiB = 1024u * 1024u;
static constexpr size_t MiB = 1024u * 1024u;
size_t getMinCommandBufferSize() const noexcept { return mConfig.minCommandBufferSizeMB * MiB; }
size_t getCommandBufferSize() const noexcept { return mConfig.commandBufferSizeMB * MiB; }
size_t getPerFrameCommandsSize() const noexcept { return mConfig.perFrameCommandsSizeMB * MiB; }
Expand Down
Loading