Merge pull request #19513 from Mee-gu/feature/AddDeviceInfo

Feature/add device info
This commit is contained in:
minggo 2019-03-19 09:24:18 +08:00 committed by GitHub
commit 8452b55b82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 143 additions and 10 deletions

View File

@ -32,6 +32,7 @@
#include "base/CCMap.h" #include "base/CCMap.h"
#include "base/ccUTF8.h" #include "base/ccUTF8.h"
#include "renderer/CCTextureCache.h" #include "renderer/CCTextureCache.h"
#include "renderer/backend/Device.h"
#include <cmath> #include <cmath>
#include <set> #include <set>
@ -524,15 +525,14 @@ void BMFontConfiguration::parseCommonArguments(const char* line)
tmp = strstr(tmp, "scaleW=") + 7; tmp = strstr(tmp, "scaleW=") + 7;
sscanf(tmp, "%d", &value); sscanf(tmp, "%d", &value);
//TODO coulsonwang auto deviceInfo = backend::Device::getInstance()->getDeviceInfo();
// int maxTextureSize = Configuration::getInstance()->getMaxTextureSize(); int maxTextureSize = deviceInfo->getMaxTextureSize();
// CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported"); CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
// scaleH. sanity check // scaleH. sanity check
tmp = strstr(tmp, "scaleH=") + 7; tmp = strstr(tmp, "scaleH=") + 7;
sscanf(tmp, "%d", &value); sscanf(tmp, "%d", &value);
//TODO coulsonwang CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
// CCASSERT(value <= maxTextureSize, "CCLabelBMFont: page can't be larger than supported");
// pages. sanity check // pages. sanity check
tmp = strstr(tmp, "pages=") + 6; tmp = strstr(tmp, "pages=") + 6;

View File

@ -39,6 +39,7 @@ set(COCOS_RENDERER_HEADER
renderer/backend/VertexLayout.h renderer/backend/VertexLayout.h
renderer/backend/ProgramState.h renderer/backend/ProgramState.h
renderer/backend/ShaderCache.h renderer/backend/ShaderCache.h
renderer/backend/DeviceInfo.h
) )
set(COCOS_RENDERER_SRC set(COCOS_RENDERER_SRC
@ -88,6 +89,7 @@ list(APPEND COCOS_RENDERER_HEADER
renderer/backend/opengl/ShaderModuleGL.h renderer/backend/opengl/ShaderModuleGL.h
renderer/backend/opengl/TextureGL.h renderer/backend/opengl/TextureGL.h
renderer/backend/opengl/UtilsGL.h renderer/backend/opengl/UtilsGL.h
renderer/backend/opengl/DeviceInfoGL.h
) )
list(APPEND COCOS_RENDERER_SRC list(APPEND COCOS_RENDERER_SRC
@ -101,6 +103,7 @@ list(APPEND COCOS_RENDERER_SRC
renderer/backend/opengl/ShaderModuleGL.cpp renderer/backend/opengl/ShaderModuleGL.cpp
renderer/backend/opengl/TextureGL.cpp renderer/backend/opengl/TextureGL.cpp
renderer/backend/opengl/UtilsGL.cpp renderer/backend/opengl/UtilsGL.cpp
renderer/backend/opengl/DeviceInfoGL.cpp
) )
else() else()
@ -117,6 +120,7 @@ list(APPEND COCOS_RENDERER_HEADER
renderer/backend/metal/TextureMTL.h renderer/backend/metal/TextureMTL.h
renderer/backend/metal/Utils.h renderer/backend/metal/Utils.h
renderer/backend/metal/ProgramMTL.h renderer/backend/metal/ProgramMTL.h
renderer/backend/metal/DeviceInfoMTL.h
) )
list(APPEND COCOS_RENDERER_SRC list(APPEND COCOS_RENDERER_SRC
@ -131,6 +135,7 @@ list(APPEND COCOS_RENDERER_SRC
renderer/backend/metal/TextureMTL.mm renderer/backend/metal/TextureMTL.mm
renderer/backend/metal/Utils.mm renderer/backend/metal/Utils.mm
renderer/backend/metal/ProgramMTL.mm renderer/backend/metal/ProgramMTL.mm
renderer/backend/metal/DeviceInfoMTL.mm
) )
endif() endif()

View File

@ -9,6 +9,7 @@
#include "BlendState.h" #include "BlendState.h"
#include "ProgramCache.h" #include "ProgramCache.h"
#include "ShaderCache.h" #include "ShaderCache.h"
#include "DeviceInfo.h"
#include "base/CCRef.h" #include "base/CCRef.h"
@ -45,12 +46,15 @@ public:
// Create a render pipeline, not auto released. // Create a render pipeline, not auto released.
virtual RenderPipeline* newRenderPipeline(const RenderPipelineDescriptor& descriptor) = 0; virtual RenderPipeline* newRenderPipeline(const RenderPipelineDescriptor& descriptor) = 0;
inline DeviceInfo* getDeviceInfo() const { return _deviceInfo; }
protected: protected:
// Create a auto released shader module. // Create a auto released shader module.
virtual ShaderModule* newShaderModule(ShaderStage stage, const std::string& source) = 0; virtual ShaderModule* newShaderModule(ShaderStage stage, const std::string& source) = 0;
// Create a auto released program. // Create a auto released program.
virtual Program* newProgram(const std::string& vertexShader, const std::string& fragmentShader) = 0; virtual Program* newProgram(const std::string& vertexShader, const std::string& fragmentShader) = 0;
DeviceInfo* _deviceInfo = nullptr;
private: private:
static Device* _instance; static Device* _instance;
}; };

View File

@ -0,0 +1,25 @@
#pragma once
#include <string>
#include "Macros.h"
CC_BACKEND_BEGIN
class DeviceInfo
{
public:
virtual ~DeviceInfo() = default;
virtual bool init() = 0;
inline int getMaxTextureSize() const { return _maxTextureSize; }
inline int getMaxAttributes() const { return _maxAttributes; }
protected:
DeviceInfo() = default;
int _maxAttributes = 0;
int _maxTextureSize = 0;
};
CC_BACKEND_END

View File

@ -0,0 +1,22 @@
#pragma once
#include "../DeviceInfo.h"
#import <Metal/Metal.h>
CC_BACKEND_BEGIN
class DeviceInfoMTL : public DeviceInfo
{
public:
DeviceInfoMTL(id<MTLDevice> device);
virtual ~DeviceInfoMTL() = default;
virtual bool init() override;
private:
void getTextureSizeInfo();
//MTLFeatureSet _currentFeatureSet;
};
CC_BACKEND_END

View File

@ -0,0 +1,29 @@
#include "DeviceInfoMTL.h"
#include "base/ccMacros.h"
CC_BACKEND_BEGIN
DeviceInfoMTL::DeviceInfoMTL(id<MTLDevice> device)
{
}
bool DeviceInfoMTL::init()
{
_maxAttributes = 31;
getTextureSizeInfo();
return true;
}
//todo coulsonwang
void DeviceInfoMTL::getTextureSizeInfo()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
_maxTextureSize = 4096;
#else
_maxTextureSize = 16384;
#endif
}
CC_BACKEND_END

View File

@ -8,8 +8,9 @@
#include "BlendStateMTL.h" #include "BlendStateMTL.h"
#include "Utils.h" #include "Utils.h"
#include "ProgramMTL.h" #include "ProgramMTL.h"
#include "base/ccMacros.h" #include "DeviceInfoMTL.h"
#include "base/ccMacros.h"
CC_BACKEND_BEGIN CC_BACKEND_BEGIN
@ -46,12 +47,19 @@ DeviceMTL::DeviceMTL()
{ {
_mtlDevice = DeviceMTL::_metalLayer.device; _mtlDevice = DeviceMTL::_metalLayer.device;
_mtlCommandQueue = [_mtlDevice newCommandQueue]; _mtlCommandQueue = [_mtlDevice newCommandQueue];
ProgramCache::getInstance(); _deviceInfo = new (std::nothrow) DeviceInfoMTL(_mtlDevice);
if(!_deviceInfo || _deviceInfo->init() == false)
{
delete _deviceInfo;
_deviceInfo = nullptr;
}
} }
DeviceMTL::~DeviceMTL() DeviceMTL::~DeviceMTL()
{ {
ProgramCache::destroyInstance(); ProgramCache::destroyInstance();
delete _deviceInfo;
_deviceInfo = nullptr;
} }
CommandBuffer* DeviceMTL::newCommandBuffer() CommandBuffer* DeviceMTL::newCommandBuffer()

View File

@ -7,6 +7,7 @@
#include "DepthStencilStateGL.h" #include "DepthStencilStateGL.h"
#include "BlendStateGL.h" #include "BlendStateGL.h"
#include "ProgramGL.h" #include "ProgramGL.h"
#include "DeviceInfoGL.h"
CC_BACKEND_BEGIN CC_BACKEND_BEGIN
@ -20,12 +21,19 @@ Device* Device::getInstance()
DeviceGL::DeviceGL() DeviceGL::DeviceGL()
{ {
ProgramCache::getInstance(); _deviceInfo = new (std::nothrow) DeviceInfoGL();
if(!_deviceInfo || _deviceInfo->init() == false)
{
delete _deviceInfo;
_deviceInfo = nullptr;
}
} }
DeviceGL::~DeviceGL() DeviceGL::~DeviceGL()
{ {
ProgramCache::destroyInstance(); ProgramCache::destroyInstance();
delete _deviceInfo;
_deviceInfo = nullptr;
} }
CommandBuffer* DeviceGL::newCommandBuffer() CommandBuffer* DeviceGL::newCommandBuffer()

View File

@ -0,0 +1,13 @@
#include "DeviceInfoGL.h"
#include "platform/CCGL.h"
CC_BACKEND_BEGIN
bool DeviceInfoGL::init()
{
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_maxAttributes);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize);
return true;
}
CC_BACKEND_END

View File

@ -0,0 +1,18 @@
#pragma once
#include "../DeviceInfo.h"
CC_BACKEND_BEGIN
class DeviceInfoGL: public DeviceInfo
{
public:
DeviceInfoGL() = default;
virtual ~DeviceInfoGL() = default;
virtual bool init() override;
private:
};
CC_BACKEND_END

View File

@ -34,6 +34,7 @@
#include <algorithm> #include <algorithm>
#include "../testResource.h" #include "../testResource.h"
#include "renderer/backend/Device.h"
USING_NS_CC; USING_NS_CC;
@ -2565,8 +2566,8 @@ Sprite3DNormalMappingTest::Sprite3DNormalMappingTest()
addChild(sprite); addChild(sprite);
} }
int maxAttributes; auto deviceInfo = backend::Device::getInstance()->getDeviceInfo();
maxAttributes = Configuration::getInstance()->getValue("max_vertex_attributes").asInt(); int maxAttributes = deviceInfo->getMaxAttributes();
CCASSERT(maxAttributes > 8, "attributes supported must be greater than 8"); CCASSERT(maxAttributes > 8, "attributes supported must be greater than 8");
if (maxAttributes > 8) if (maxAttributes > 8)
{ {