merge v3.3.0 and fix conflict

This commit is contained in:
minggo
2021-08-13 22:28:13 +08:00
54 changed files with 525 additions and 346 deletions
+8 -4
View File
@@ -1551,8 +1551,6 @@ cocos_source_files(
cocos/bindings/manual/jsb_gfx_manual.h
NO_WERROR cocos/bindings/manual/jsb_global.cpp
cocos/bindings/manual/jsb_global.h
NO_WERROR cocos/bindings/manual/jsb_global_init.cpp
cocos/bindings/manual/jsb_global_init.h
NO_WERROR cocos/bindings/manual/jsb_helper.cpp
cocos/bindings/manual/jsb_helper.h
cocos/bindings/manual/jsb_module_register.h
@@ -1693,7 +1691,9 @@ cocos_source_files(MODULE ccbindings
cocos/bindings/jswrapper/State.cpp
cocos/bindings/jswrapper/State.h
cocos/bindings/jswrapper/Value.cpp
cocos/bindings/jswrapper/Value.h
cocos/bindings/jswrapper/Value.h
NO_WERROR cocos/bindings/manual/jsb_global_init.cpp
cocos/bindings/manual/jsb_global_init.h
)
cocos_source_files(
@@ -1822,7 +1822,7 @@ if(USE_MODULES)
add_library(ccmath ${ccmath_SOURCE_LIST})
add_library(cclog ${cclog_SOURCE_LIST})
add_library(ccfilesystem ${ccfilesystem_SOURCE_LIST} ${CC_TINYDIR_SOURCES})
add_library(ccutils ${ccutils_SOURCE_LIST} ${CC_FS_SOURCES})
add_library(ccutils ${ccutils_SOURCE_LIST} ${CC_UTILS_SOURCES})
add_library(ccunzip ${ccunzip_SOURCE_LIST} ${CC_UNZIP_SOURCES})
add_library(ccbindings ${ccbindings_SOURCE_LIST})
@@ -1848,6 +1848,8 @@ if(USE_MODULES)
)
target_include_directories(ccbindings PRIVATE
${CWD}/cocos
${CWD}/cocos/bindings/jswrapper
${CWD}/cocos/editor-support # TODO: refactor include path
${CWD}
${CC_EXTERNAL_INCLUDES}
)
@@ -2145,11 +2147,13 @@ if(MSVC)
file(GLOB_RECURSE WIN32_DLLS
${CWD}/external/win32/libs/*.dll
${CWD}/external/win32/libs/Debug/*.dll
${CWD}/external/win32/libs/glslang/*.dll
)
else()
file(GLOB_RECURSE WIN32_DLLS
${CWD}/external/win64/libs/*.dll
${CWD}/external/win64/libs/Debug/*.dll
${CWD}/external/win64/libs/glslang/*.dll
)
endif()
target_compile_options(cocos2d PUBLIC /MP)
+4
View File
@@ -70,6 +70,10 @@ uint nextPOT(uint x) {
return x + 1;
}
uint alignTo(uint size, uint alignment) {
return ((size - 1) / alignment + 1) * alignment;
}
// painfully slow to execute, use with caution
std::string getStacktrace(uint skip, uint maxDepth) {
return boost::stacktrace::to_string(boost::stacktrace::stacktrace(skip, maxDepth));
+2
View File
@@ -62,6 +62,8 @@ CC_DLL uint nextPOT(uint x);
*/
CC_DLL double atof(const char *str);
CC_DLL uint alignTo(uint size, uint alignment);
template <typename T, size_t Size>
char (*countOfHelper(T (&array)[Size]))[Size];
@@ -16035,6 +16035,25 @@ static bool js_gfx_Buffer_getUsage(se::State& s) // NOLINT(readability-identifie
}
SE_BIND_PROP_GET(js_gfx_Buffer_getUsage)
static bool js_gfx_Buffer_isBufferView(se::State& s) // NOLINT(readability-identifier-naming)
{
auto* cobj = SE_THIS_OBJECT<cc::gfx::Buffer>(s);
SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_isBufferView : Invalid Native Object");
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 0) {
bool result = cobj->isBufferView();
ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "js_gfx_Buffer_isBufferView : Error processing arguments");
SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval());
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_gfx_Buffer_isBufferView)
static bool js_gfx_Buffer_resize(se::State& s) // NOLINT(readability-identifier-naming)
{
auto* cobj = SE_THIS_OBJECT<cc::gfx::Buffer>(s);
@@ -16110,6 +16129,7 @@ bool js_register_gfx_Buffer(se::Object* obj) // NOLINT(readability-identifier-na
cls->defineProperty("usage", _SE(js_gfx_Buffer_getUsage), nullptr);
cls->defineProperty("size", _SE(js_gfx_Buffer_getSize), nullptr);
cls->defineFunction("destroy", _SE(js_gfx_Buffer_destroy));
cls->defineFunction("isBufferView", _SE(js_gfx_Buffer_isBufferView));
cls->defineFunction("resize", _SE(js_gfx_Buffer_resize));
cls->defineStaticFunction("computeHash", _SE(js_gfx_Buffer_computeHash));
cls->defineFinalizeFunction(_SE(js_cc_gfx_Buffer_finalize));
@@ -20867,6 +20887,19 @@ static bool js_gfx_DeviceManager_create(se::State& s) // NOLINT(readability-iden
}
SE_BIND_FUNC(js_gfx_DeviceManager_create)
static bool js_gfx_DeviceManager_addCustomEvent(se::State& s) // NOLINT(readability-identifier-naming)
{
const auto& args = s.args();
size_t argc = args.size();
if (argc == 0) {
cc::gfx::DeviceManager::addCustomEvent();
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
return false;
}
SE_BIND_FUNC(js_gfx_DeviceManager_addCustomEvent)
static bool js_cc_gfx_DeviceManager_finalize(se::State& s) // NOLINT(readability-identifier-naming)
{
@@ -20887,6 +20920,7 @@ bool js_register_gfx_DeviceManager(se::Object* obj) // NOLINT(readability-identi
cls->defineStaticFunction("destroy", _SE(js_gfx_DeviceManager_destroy));
cls->defineStaticFunction("create", _SE(js_gfx_DeviceManager_create));
cls->defineStaticFunction("addCustomEvent", _SE(js_gfx_DeviceManager_addCustomEvent));
cls->defineFinalizeFunction(_SE(js_cc_gfx_DeviceManager_finalize));
cls->install();
JSBClassType::registerClass<cc::gfx::DeviceManager>(cls);
@@ -584,6 +584,7 @@ bool register_all_gfx(se::Object* obj);
JSB_REGISTER_OBJECT_TYPE(cc::gfx::Buffer);
SE_DECLARE_FUNC(js_gfx_Buffer_destroy);
SE_DECLARE_FUNC(js_gfx_Buffer_isBufferView);
SE_DECLARE_FUNC(js_gfx_Buffer_resize);
SE_DECLARE_FUNC(js_gfx_Buffer_computeHash);
SE_DECLARE_FUNC(js_gfx_Buffer_Buffer);
@@ -847,4 +848,5 @@ bool register_all_gfx(se::Object* obj);
JSB_REGISTER_OBJECT_TYPE(cc::gfx::DeviceManager);
SE_DECLARE_FUNC(js_gfx_DeviceManager_destroy);
SE_DECLARE_FUNC(js_gfx_DeviceManager_create);
SE_DECLARE_FUNC(js_gfx_DeviceManager_addCustomEvent);
@@ -4130,7 +4130,7 @@ static bool js_scene_SubModel_getPass(se::State& s) // NOLINT(readability-identi
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
HolderType<int, false> arg0 = {};
HolderType<unsigned int, false> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_SubModel_getPass : Error processing arguments");
cc::scene::Pass* result = cobj->getPass(arg0.value());
@@ -4228,7 +4228,7 @@ static bool js_scene_SubModel_getShader(se::State& s) // NOLINT(readability-iden
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc == 1) {
HolderType<int, false> arg0 = {};
HolderType<unsigned int, false> arg0 = {};
ok &= sevalue_to_native(args[0], &arg0, s.thisObject());
SE_PRECONDITION2(ok, false, "js_scene_SubModel_getShader : Error processing arguments");
cc::gfx::Shader* result = cobj->getShader(arg0.value());
@@ -23,6 +23,14 @@
THE SOFTWARE.
****************************************************************************/
// clang-format: off
#if CC_PLATFORM == CC_PLATFORM_WINDOWS
// Fix ssize_t defination
#include "cocos/bindings/jswrapper/config.h"
#endif
#include "uv.h"
// clang-format: on
#include "base/CoreStd.h"
#include "base/Scheduler.h"
#include "base/ZipUtils.h"
@@ -55,6 +63,31 @@ static std::string removeFileExt(const std::string &filePath) {
return filePath;
}
static int selectPort(int port) {
uv_tcp_t server;
struct sockaddr_in addr;
uv_loop_t * loop = uv_default_loop();
int tryTimes = 200;
int startPort = port;
uv_tcp_init(loop, &server);
while (true) {
if (tryTimes-- < 0) {
return port; // allow failure
}
uv_ip4_addr("0.0.0.0", startPort, &addr);
uv_tcp_bind(&server, reinterpret_cast<const struct sockaddr *>(&addr), 0);
int r = uv_listen(reinterpret_cast<uv_stream_t *>(&server), 5, nullptr);
if (r) {
SE_LOGD("Failed to listen port %d, error: %s. Try next port\n", startPort, uv_strerror(r));
startPort += 1;
uv_close(reinterpret_cast<uv_handle_t *>(&server), nullptr);
} else {
uv_close(reinterpret_cast<uv_handle_t *>(&server), nullptr);
return startPort;
}
}
}
void jsb_init_file_operation_delegate() { //NOLINT
static se::ScriptEngine::FileOperationDelegate delegate;
@@ -170,7 +203,9 @@ bool jsb_enable_debugger(const std::string &debuggerServerAddr, uint32_t port, b
return false;
}
auto se = se::ScriptEngine::getInstance();
port = static_cast<uint32_t>(selectPort(static_cast<int>(port)));
auto *se = se::ScriptEngine::getInstance();
se->enableDebugger(debuggerServerAddr, port, isWaitForConnect);
// For debugger main loop
@@ -209,6 +209,7 @@ bool register_all_scene_ext_manual(se::Object *obj) { //NOLINT
globalThis = se::ScriptEngine::getInstance()->getGlobalObject();
msgQueue = se::Object::createArrayObject(1);
msgQueueInfo = se::Object::createTypedArray(se::Object::TypedArrayType::UINT32, nullptr, sizeof(uint32_t) * 2);
msgQueuePtrs.clear();
{
uint8_t *data{nullptr};
@@ -118,7 +118,6 @@ SkeletonAnimation::~SkeletonAnimation() {
_eventListener = nullptr;
if (_state) {
clearTracks();
if (_ownsAnimationStateData) delete _state->getData();
delete _state;
}
@@ -31,11 +31,11 @@
#include <algorithm>
#include <vector>
using namespace spine;
using namespace spine; //NOLINT
namespace spine {
class SkeletonDataInfo : public cc::Ref {
class SkeletonDataInfo {
public:
SkeletonDataInfo() = default;
@@ -64,7 +64,7 @@ public:
} // namespace spine
SkeletonDataMgr *SkeletonDataMgr::_instance = nullptr;
SkeletonDataMgr *SkeletonDataMgr::instance = nullptr;
bool SkeletonDataMgr::hasSkeletonData(const std::string &uuid) {
auto it = _dataMap.find(uuid);
@@ -76,7 +76,7 @@ void SkeletonDataMgr::setSkeletonData(const std::string &uuid, SkeletonData *dat
if (it != _dataMap.end()) {
releaseByUUID(uuid);
}
SkeletonDataInfo *info = new SkeletonDataInfo();
auto *info = new SkeletonDataInfo();
info->data = data;
info->atlas = atlas;
info->attachmentLoader = attachmentLoader;
@@ -89,7 +89,6 @@ SkeletonData *SkeletonDataMgr::retainByUUID(const std::string &uuid) {
if (dataIt == _dataMap.end()) {
return nullptr;
}
dataIt->second->retain();
return dataIt->second->data;
}
@@ -99,15 +98,11 @@ void SkeletonDataMgr::releaseByUUID(const std::string &uuid) {
return;
}
SkeletonDataInfo *info = dataIt->second;
// If info reference count is 1, then info will be destroy.
if (info->getReferenceCount() == 1) {
_dataMap.erase(dataIt);
if (_destroyCallback) {
auto &texturesIndex = info->texturesIndex;
for (auto it = texturesIndex.begin(); it != texturesIndex.end(); it++) {
_destroyCallback(*it);
}
_dataMap.erase(dataIt);
if (_destroyCallback) {
for (auto &item : info->texturesIndex) {
_destroyCallback(item);
}
}
info->release();
delete info;
}
@@ -47,36 +47,38 @@ class SkeletonDataInfo;
class SkeletonDataMgr {
public:
static SkeletonDataMgr *getInstance() {
if (_instance == nullptr) {
_instance = new SkeletonDataMgr();
if (instance == nullptr) {
instance = new SkeletonDataMgr();
}
return _instance;
return instance;
}
static void destroyInstance() {
if (_instance) {
delete _instance;
_instance = nullptr;
if (instance) {
delete instance;
instance = nullptr;
}
}
SkeletonDataMgr() {}
SkeletonDataMgr() = default;
virtual ~SkeletonDataMgr() {
_destroyCallback = NULL;
_destroyCallback = nullptr;
}
bool hasSkeletonData(const std::string &uuid);
void setSkeletonData(const std::string &uuid, SkeletonData *data, Atlas *atlas, AttachmentLoader *attachmentLoader, const std::vector<int> &texturesIndex);
// equal to 'findByUUID'
SkeletonData *retainByUUID(const std::string &uuid);
// equal to 'deleteByUUID'
void releaseByUUID(const std::string &uuid);
typedef std::function<void(int)> destroyCallback;
using destroyCallback = std::function<void(int)>;
void setDestroyCallback(destroyCallback callback) {
_destroyCallback = callback;
_destroyCallback = std::move(callback);
}
private:
static SkeletonDataMgr *_instance;
static SkeletonDataMgr* instance;
destroyCallback _destroyCallback = nullptr;
std::map<std::string, SkeletonDataInfo *> _dataMap;
};
@@ -156,7 +156,6 @@ SkeletonRenderer::~SkeletonRenderer() {
if (_ownsSkeleton) delete _skeleton;
if (_ownsAtlas && _atlas) delete _atlas;
delete _attachmentLoader;
if (!_uuid.empty()) SkeletonDataMgr::getInstance()->releaseByUUID(_uuid);
delete _clipper;
if (_debugBuffer) {
+3 -1
View File
@@ -26,6 +26,7 @@
#include "cocos/platform/Application.h"
#include "cocos/bindings/jswrapper/SeApi.h"
#include "pipeline/RenderPipeline.h"
#include "cocos/renderer/GFXDeviceManager.h"
#if USE_AUDIO
#include "cocos/audio/include/AudioEngine.h"
@@ -64,6 +65,7 @@ void Application::restartVM() {
cc::EventDispatcher::init();
init();
cc::gfx::DeviceManager::addCustomEvent();
}
void Application::close() { // NOLINT
@@ -107,7 +109,7 @@ void Application::tick() {
++_totalFrames;
// iOS/macOS use its own fps limitation algorithm.
#if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_WINDOWS)
#if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_OHOS)
if (dtNS < static_cast<double>(_prefererredNanosecondsPerFrame)) {
std::this_thread::sleep_for(
std::chrono::nanoseconds(_prefererredNanosecondsPerFrame - static_cast<int64_t>(dtNS)));
@@ -156,7 +156,7 @@ void glThreadEntry() {
std::this_thread::yield();
}
if (game) {
if (game && cc::cocosApp.animating) {
// Handle java events send by UI thread. Input events are handled here too.
cc::JniHelper::callStaticVoidMethod("com.cocos.lib.CocosHelper",
"flushTasksOnGameThread");
+11 -8
View File
@@ -89,6 +89,16 @@ public:
static void destroy() {
CC_SAFE_DESTROY(Device::instance);
}
static void addCustomEvent() {
Device *device = Device::instance;
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void {
device->releaseSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void {
device->acquireSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
}
private:
template <typename DeviceCtor, typename Enable = std::enable_if_t<std::is_base_of<Device, DeviceCtor>::value>>
@@ -108,14 +118,7 @@ private:
return false;
}
EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void {
device->releaseSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void {
device->acquireSurface(reinterpret_cast<uintptr_t>(e.args->ptrVal));
});
addCustomEvent();
*pDevice = device;
return true;
@@ -44,12 +44,15 @@ public:
virtual void update(const void *buffer, uint size) = 0;
inline void update(const void *buffer) { update(buffer, _size); }
inline BufferUsage getUsage() const { return _usage; }
inline MemoryUsage getMemUsage() const { return _memUsage; }
inline uint getStride() const { return _stride; }
inline uint getCount() const { return _count; }
inline uint getSize() const { return _size; }
inline BufferFlags getFlags() const { return _flags; }
inline bool isBufferView() const { return _isBufferView; }
protected:
virtual void doInit(const BufferInfo &info) = 0;
@@ -1078,7 +1078,7 @@ struct ColorAttachment {
LoadOp loadOp = LoadOp::CLEAR;
StoreOp storeOp = StoreOp::STORE;
std::vector<AccessType> beginAccesses;
std::vector<AccessType> endAccesses{AccessType::PRESENT};
std::vector<AccessType> endAccesses{AccessType::COLOR_ATTACHMENT_WRITE};
bool isGeneralLayout = false;
};
@@ -158,6 +158,10 @@ GLenum mapGLInternalFormat(Format format) {
case Format::SRGB8: return GL_SRGB_EXT;
case Format::RGBA8SN: return GL_RGBA8_SNORM;
case Format::SRGB8_A8: return GL_SRGB_ALPHA_EXT;
case Format::R16F: return GL_R16F_EXT;
case Format::RG16F: return GL_RG16F_EXT;
case Format::RGB16F: return GL_RGB16F_EXT;
case Format::RGBA16F: return GL_RGBA16F_EXT;
case Format::R32F: return GL_R32F_EXT;
case Format::RG32F: return GL_RG32F_EXT;
case Format::RGB32F: return GL_RGB32F_EXT;
@@ -1010,12 +1014,8 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) {
gpuUniform.stride = GFX_TYPE_SIZES[static_cast<int>(uniform.type)];
gpuUniform.count = uniform.count;
gpuUniform.size = gpuUniform.stride * gpuUniform.count;
gpuUniform.offset = gpuBlock.size;
gpuUniform.glType = mapGLType(gpuUniform.type);
gpuUniform.glLoc = -1;
gpuUniform.buff = nullptr;
gpuBlock.size += gpuUniform.size;
}
}
} // if
@@ -1049,10 +1049,10 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) {
}
// parse glUniforms
GLint glActiveUniforms;
GL_CHECK(glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORMS, &glActiveUniforms));
GLint glActiveUniformCount;
GL_CHECK(glGetProgramiv(gpuShader->glProgram, GL_ACTIVE_UNIFORMS, &glActiveUniformCount));
for (GLint i = 0; i < glActiveUniforms; ++i) {
for (GLint i = 0; i < glActiveUniformCount; ++i) {
memset(glName, 0, sizeof(glName));
GL_CHECK(glGetActiveUniform(gpuShader->glProgram, i, 255, &glLength, &glSize, &glType, glName));
char *offset = strchr(glName, '[');
@@ -1069,15 +1069,17 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) {
(glType == GL_INT_SAMPLER_CUBE_MAP_ARRAY_OES) ||
(glType == GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES);
if (!isSampler) {
for (size_t b = 0; b < gpuShader->glBlocks.size(); ++b) {
GLES2GPUUniformBlock &gpuBlock = gpuShader->glBlocks[b];
for (size_t u = 0; u < gpuBlock.glUniforms.size(); ++u) {
if (gpuBlock.glUniforms[u].name == name) {
GLES2GPUUniform &gpuUniform = gpuBlock.glUniforms[u];
gpuUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName);
gpuUniform.buff = static_cast<uint8_t *>(CC_MALLOC(gpuUniform.size));
for (auto &glBlock : gpuShader->glBlocks) {
for (uint i = 0; i < glBlock.glUniforms.size(); ++i) {
auto &glUniform = glBlock.glUniforms[i];
if (glUniform.name == name) {
glUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName);
glUniform.count = glSize;
glUniform.size = glUniform.stride * glUniform.count;
gpuBlock.glActiveUniforms.emplace_back(gpuUniform);
auto &activeUniform = glBlock.glActiveUniforms.emplace_back(glUniform);
activeUniform.buff.resize(activeUniform.size);
glBlock.activeUniformIndices.push_back(i);
break;
}
}
@@ -1085,6 +1087,19 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) {
}
} // for
// calculate offset & size
for (auto &gpuBlock : gpuShader->glBlocks) {
for (auto &gpuUniform : gpuBlock.glUniforms) {
gpuUniform.offset = gpuBlock.size;
gpuBlock.size += gpuUniform.size;
}
for (uint i = 0; i < gpuBlock.glActiveUniforms.size(); ++i) {
auto &activeUniform = gpuBlock.glActiveUniforms[i];
uint index = gpuBlock.activeUniformIndices[i];
activeUniform.offset = gpuBlock.glUniforms[index].offset;
}
}
// texture unit index mapping optimization
vector<GLES2GPUUniformSamplerTexture> glActiveSamplerTextures;
vector<GLint> glActiveSamplerLocations;
@@ -1932,13 +1947,14 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli
// bind descriptor sets
if (gpuPipelineState && gpuPipelineState->gpuShader && gpuPipelineState->gpuPipelineLayout) {
size_t blockLen = gpuPipelineState->gpuShader->glBlocks.size();
const vector<vector<int>> &dynamicOffsetIndices = gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices;
uint8_t * uniformBuffBase = nullptr;
uint8_t * uniformBuff;
size_t blockLen{gpuPipelineState->gpuShader->glBlocks.size()};
const vector<vector<int>> &dynamicOffsetIndices{gpuPipelineState->gpuPipelineLayout->dynamicOffsetIndices};
uint8_t * uniformBuffBase{nullptr};
uint8_t * uniformBuff{nullptr};
uint8_t * uniformCachedBuff{nullptr};
for (size_t j = 0; j < blockLen; j++) {
const GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j];
GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j];
const GLES2GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glBlock.set];
const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glBlock.binding);
@@ -1964,87 +1980,89 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli
uniformBuffBase = gpuDescriptor.gpuBuffer->buffer + offset;
}
for (const auto &gpuUniform : glBlock.glActiveUniforms) {
uniformBuff = uniformBuffBase + gpuUniform.offset;
for (auto &gpuUniform : glBlock.glActiveUniforms) {
uniformBuff = uniformBuffBase + gpuUniform.offset;
uniformCachedBuff = gpuUniform.buff.data();
switch (gpuUniform.glType) {
case GL_BOOL:
case GL_INT: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform1iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLint *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_BOOL_VEC2:
case GL_INT_VEC2: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform2iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLint *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_BOOL_VEC3:
case GL_INT_VEC3: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform3iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLint *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_BOOL_VEC4:
case GL_INT_VEC4: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform4iv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLint *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform1fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT_VEC2: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform2fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT_VEC3: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform3fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT_VEC4: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniform4fv(gpuUniform.glLoc, gpuUniform.count, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT_MAT2: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniformMatrix2fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT_MAT3: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniformMatrix3fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
case GL_FLOAT_MAT4: {
if (memcmp(gpuUniform.buff, uniformBuff, gpuUniform.size) != 0) {
if (memcmp(uniformCachedBuff, uniformBuff, gpuUniform.size) != 0) {
GL_CHECK(glUniformMatrix4fv(gpuUniform.glLoc, gpuUniform.count, GL_FALSE, reinterpret_cast<const GLfloat *>(uniformBuff)));
memcpy(gpuUniform.buff, uniformBuff, gpuUniform.size);
memcpy(uniformCachedBuff, uniformBuff, gpuUniform.size);
}
break;
}
@@ -2611,19 +2629,19 @@ void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const
CC_GLES2_API void cmdFuncGLES2CopyTextureToBuffers(GLES2Device *device, GLES2GPUTexture *gpuTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) {
GLuint framebuffer = device->framebufferCacheMap()->getFramebufferFromTexture(gpuTexture);
auto glFormat = mapGLFormat(gpuTexture->format);
auto glType = formatToGLType(gpuTexture->format);
auto glFormat = mapGLFormat(gpuTexture->format);
auto glType = formatToGLType(gpuTexture->format);
if (device->stateCache()->glFramebuffer != framebuffer) {
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer));
device->stateCache()->glFramebuffer = framebuffer;
}
for(uint32_t i = 0; i < count; ++i) {
auto region = regions[i];
auto w = region.texExtent.width;
auto h = region.texExtent.height;
auto memSize = static_cast<GLsizei>(formatSize(gpuTexture->format, w, h, 1));
uint8_t* copyDst = buffers[i];
for (uint32_t i = 0; i < count; ++i) {
auto region = regions[i];
auto w = region.texExtent.width;
auto h = region.texExtent.height;
auto memSize = static_cast<GLsizei>(formatSize(gpuTexture->format, w, h, 1));
uint8_t *copyDst = buffers[i];
GL_CHECK(glReadPixels(region.texOffset.x, region.texOffset.y, region.texExtent.width, region.texExtent.height, glFormat, glType, copyDst));
}
}
@@ -130,47 +130,16 @@ struct GLES2GPUInput final {
using GLES2GPUInputList = vector<GLES2GPUInput>;
struct GLES2GPUUniform final {
uint binding = INVALID_BINDING;
String name;
Type type = Type::UNKNOWN;
uint stride = 0;
uint count = 0;
uint size = 0;
uint offset = 0;
GLenum glType = 0;
GLint glLoc = -1;
uint8_t *buff = nullptr;
GLES2GPUUniform() = default;
GLES2GPUUniform(const GLES2GPUUniform &rhs) {
*this = rhs;
}
GLES2GPUUniform &operator=(const GLES2GPUUniform &rhs) {
if (this != &rhs) {
binding = rhs.binding;
name = rhs.name;
type = rhs.type;
stride = rhs.stride;
count = rhs.count;
offset = rhs.offset;
glType = rhs.glType;
glLoc = rhs.glLoc;
if (size != rhs.size) {
size = rhs.size;
CC_SAFE_FREE(buff);
buff = static_cast<uint8_t *>(CC_MALLOC(size));
}
if (buff && rhs.buff) {
memcpy(buff, rhs.buff, size);
}
}
return *this;
}
~GLES2GPUUniform() {
CC_SAFE_FREE(buff);
}
uint binding = INVALID_BINDING;
String name;
Type type = Type::UNKNOWN;
uint stride = 0;
uint count = 0;
uint size = 0;
uint offset = 0;
GLenum glType = 0;
GLint glLoc = -1;
vector<uint8_t> buff;
};
using GLES2GPUUniformList = vector<GLES2GPUUniform>;
@@ -182,6 +151,7 @@ struct GLES2GPUUniformBlock final {
uint size = 0;
GLES2GPUUniformList glUniforms;
GLES2GPUUniformList glActiveUniforms;
vector<uint> activeUniformIndices;
};
using GLES2GPUUniformBlockList = vector<GLES2GPUUniformBlock>;
@@ -2265,6 +2265,9 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli
if (cache->glBindUBOs[glBuffer.glBinding] != gpuDescriptor.gpuBuffer->glBuffer ||
cache->glBindUBOOffsets[glBuffer.glBinding] != offset) {
if (offset) {
GLint size{0};
glGetIntegeri_v(GL_UNIFORM_BUFFER_SIZE, glBuffer.glBinding, &size);
GL_CHECK(glBindBufferRange(GL_UNIFORM_BUFFER, glBuffer.glBinding, gpuDescriptor.gpuBuffer->glBuffer,
offset, gpuDescriptor.gpuBuffer->size));
} else {
+6 -3
View File
@@ -34,8 +34,8 @@
namespace cc {
namespace gfx {
class CCMTLBuffer;
class CCMTLCommandEncoder;
class CCMTLGPUBuffer;
class CCMTLBuffer final : public Buffer {
public:
@@ -50,7 +50,9 @@ public:
void encodeBuffer(CCMTLCommandEncoder &encoder, uint offset, uint binding, ShaderStageFlags stages);
inline id<MTLBuffer> getMTLBuffer() const { return _mtlBuffer; }
id<MTLBuffer> getMTLBuffer() const;
inline CCMTLGPUBuffer* gpuBuffer() { return _gpuBuffer; }
inline MTLIndexType getIndexType() const { return _indexType; }
inline bool isDrawIndirectByIndex() const { return _isDrawIndirectByIndex; }
inline const DrawInfoList &getDrawInfos() const { return _drawInfos; }
@@ -64,7 +66,6 @@ protected:
bool createMTLBuffer(uint size, MemoryUsage usage);
void updateMTLBuffer(const void *buffer, uint offset, uint size);
id<MTLBuffer> _mtlBuffer = nullptr;
MTLIndexType _indexType = MTLIndexTypeUInt16;
MTLResourceOptions _mtlResourceOptions = MTLResourceStorageModePrivate;
bool _isIndirectDrawSupported = false;
@@ -74,6 +75,8 @@ protected:
vector<MTLDrawIndexedPrimitivesIndirectArguments> _indexedPrimitivesIndirectArguments;
vector<MTLDrawPrimitivesIndirectArguments> _primitiveIndirectArguments;
DrawInfoList _drawInfos;
CCMTLGPUBuffer* _gpuBuffer = nullptr;
};
} // namespace gfx
+36 -20
View File
@@ -33,6 +33,7 @@
#include "MTLDevice.h"
#include "MTLRenderCommandEncoder.h"
#include "MTLUtils.h"
#include "MTLGPUObjects.h"
namespace cc {
namespace gfx {
@@ -46,6 +47,13 @@ CCMTLBuffer::~CCMTLBuffer() {
}
void CCMTLBuffer::doInit(const BufferInfo &info) {
_gpuBuffer = CC_NEW(CCMTLGPUBuffer);
_gpuBuffer->count = _count;
_gpuBuffer->mappedData = nullptr;
_gpuBuffer->size = _size;
_gpuBuffer->startOffset = _offset;
_gpuBuffer->stride = _stride;
_isIndirectDrawSupported = CCMTLDevice::getInstance()->isIndirectDrawSupported();
if (hasFlag(_usage, BufferUsage::INDEX)) {
switch (_stride) {
@@ -75,7 +83,7 @@ void CCMTLBuffer::doInit(const BufferInfo &info) {
void CCMTLBuffer::doInit(const BufferViewInfo &info) {
auto* ccBuffer = static_cast<CCMTLBuffer *>(info.buffer);
_mtlBuffer = ccBuffer->getMTLBuffer();
_gpuBuffer = ccBuffer->gpuBuffer();
_indexType = ccBuffer->getIndexType();
_mtlResourceOptions = ccBuffer->_mtlResourceOptions;
_isIndirectDrawSupported = ccBuffer->_isIndirectDrawSupported;
@@ -90,8 +98,8 @@ void CCMTLBuffer::doInit(const BufferViewInfo &info) {
bool CCMTLBuffer::createMTLBuffer(uint size, MemoryUsage usage) {
_mtlResourceOptions = mu::toMTLResourceOption(usage);
if (_mtlBuffer) {
id<MTLBuffer> mtlBuffer = _mtlBuffer;
if (_gpuBuffer->mtlBuffer) {
id<MTLBuffer> mtlBuffer = _gpuBuffer->mtlBuffer;
std::function<void(void)> destroyFunc = [=]() {
if (mtlBuffer) {
@@ -104,8 +112,8 @@ bool CCMTLBuffer::createMTLBuffer(uint size, MemoryUsage usage) {
}
id<MTLDevice> mtlDevice = id<MTLDevice>(CCMTLDevice::getInstance()->getMTLDevice());
_mtlBuffer = [mtlDevice newBufferWithLength:size options:_mtlResourceOptions];
if (_mtlBuffer == nil) {
_gpuBuffer->mtlBuffer = [mtlDevice newBufferWithLength:size options:_mtlResourceOptions];
if (_gpuBuffer->mtlBuffer == nil) {
return false;
}
return true;
@@ -130,17 +138,21 @@ void CCMTLBuffer::doDestroy() {
_drawInfos.clear();
}
id<MTLBuffer> mtlBuffer = _mtlBuffer;
_mtlBuffer = nil;
if(_gpuBuffer) {
id<MTLBuffer> mtlBuffer = _gpuBuffer->mtlBuffer;
_gpuBuffer->mtlBuffer = nil;
std::function<void(void)> destroyFunc = [=]() {
if (mtlBuffer) {
[mtlBuffer setPurgeableState:MTLPurgeableStateEmpty];
[mtlBuffer release];
}
};
//gpu object only
CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc);
std::function<void(void)> destroyFunc = [=]() {
if (mtlBuffer) {
[mtlBuffer setPurgeableState:MTLPurgeableStateEmpty];
[mtlBuffer release];
}
};
//gpu object only
CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc);
}
CC_SAFE_DELETE(_gpuBuffer);
}
void CCMTLBuffer::doResize(uint size, uint count) {
@@ -221,13 +233,13 @@ void CCMTLBuffer::update(const void *buffer, uint size) {
}
void CCMTLBuffer::updateMTLBuffer(const void *buffer, uint /*offset*/, uint size) {
if (_mtlBuffer) {
if (_gpuBuffer->mtlBuffer) {
CommandBuffer *cmdBuffer = CCMTLDevice::getInstance()->getCommandBuffer();
cmdBuffer->begin();
static_cast<CCMTLCommandBuffer *>(cmdBuffer)->updateBuffer(this, buffer, size);
#if (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
if (_mtlResourceOptions == MTLResourceStorageModeManaged) {
[_mtlBuffer didModifyRange:NSMakeRange(0, _size)]; // Synchronize the managed buffer.
[_gpuBuffer->mtlBuffer didModifyRange:NSMakeRange(0, _size)]; // Synchronize the managed buffer.
}
#endif
}
@@ -240,19 +252,23 @@ void CCMTLBuffer::encodeBuffer(CCMTLCommandEncoder &encoder, uint offset, uint b
if (hasFlag(stages, ShaderStageFlagBit::VERTEX)) {
CCMTLRenderCommandEncoder* renderEncoder = static_cast<CCMTLRenderCommandEncoder*>(&encoder);
renderEncoder->setVertexBuffer(_mtlBuffer, offset, binding);
renderEncoder->setVertexBuffer(_gpuBuffer->mtlBuffer, offset, binding);
}
if (hasFlag(stages, ShaderStageFlagBit::FRAGMENT)) {
CCMTLRenderCommandEncoder* renderEncoder = static_cast<CCMTLRenderCommandEncoder*>(&encoder);
renderEncoder->setFragmentBuffer(_mtlBuffer, offset, binding);
renderEncoder->setFragmentBuffer(_gpuBuffer->mtlBuffer, offset, binding);
}
if(hasFlag(stages, ShaderStageFlagBit::COMPUTE)) {
CCMTLComputeCommandEncoder* computeEncoder = static_cast<CCMTLComputeCommandEncoder*>(&encoder);
computeEncoder->setBuffer(_mtlBuffer, offset, binding);
computeEncoder->setBuffer(_gpuBuffer->mtlBuffer, offset, binding);
}
}
id<MTLBuffer> CCMTLBuffer::getMTLBuffer() const {
return _gpuBuffer->mtlBuffer;
}
} // namespace gfx
} // namespace cc
+1 -1
View File
@@ -31,7 +31,7 @@
#include "MTLPipelineState.h"
#include "MTLRenderPass.h"
#include "MTLShader.h"
#include "StandAlone/ResourceLimits.h"
#include "glslang/StandAlone/ResourceLimits.h"
#include "glslang/SPIRV/GlslangToSpv.h"
#include "spirv_cross/spirv_msl.hpp"
#include "TargetConditionals.h"
@@ -289,6 +289,14 @@ void CommandBufferValidator::draw(const DrawInfo &info) {
_recorder.recordDrawcall(_curStates);
}
const auto &psoLayouts = _curStates.pipelineState->getPipelineLayout()->getSetLayouts();
for (size_t i = 0; i < psoLayouts.size(); ++i) {
if (!_curStates.descriptorSets[i]) continue; // there may be inactive sets
const auto &dsBindings = _curStates.descriptorSets[i]->getLayout()->getBindings();
const auto &psoBindings = psoLayouts[i]->getBindings();
CCASSERT(psoBindings.size() == dsBindings.size(), "Descriptor set layout mismatch");
}
/////////// execute ///////////
_actor->draw(info);
@@ -75,6 +75,9 @@ void DescriptorSetValidator::bindBuffer(uint binding, Buffer *buffer, uint index
CCASSERT(binding < bindingIndices.size() && bindingIndices[binding] < bindings.size(), "Illegal binding");
const DescriptorSetLayoutBinding &info = bindings[bindingIndices[binding]];
if (hasAnyFlags(info.descriptorType, DESCRIPTOR_DYNAMIC_TYPE)) {
CCASSERT(buffer->isBufferView(), "Should bind buffer views for dynamic descriptors");
}
CCASSERT(hasAnyFlags(info.descriptorType, DESCRIPTOR_BUFFER_TYPE), "Setting binding is not DESCRIPTOR_BUFFER_TYPE");
/////////// execute ///////////
+14 -11
View File
@@ -40,12 +40,12 @@ CCVKBuffer::~CCVKBuffer() {
}
void CCVKBuffer::doInit(const BufferInfo & /*info*/) {
_gpuBuffer = CC_NEW(CCVKGPUBuffer);
_gpuBuffer->usage = _usage;
_gpuBuffer = CC_NEW(CCVKGPUBuffer);
_gpuBuffer->usage = _usage;
_gpuBuffer->memUsage = _memUsage;
_gpuBuffer->size = _size;
_gpuBuffer->stride = _stride;
_gpuBuffer->count = _count;
_gpuBuffer->size = _size;
_gpuBuffer->stride = _stride;
_gpuBuffer->count = _count;
if (hasFlag(_usage, BufferUsageBit::INDIRECT)) {
const size_t drawInfoCount = _size / sizeof(DrawInfo);
@@ -61,16 +61,16 @@ void CCVKBuffer::doInit(const BufferInfo & /*info*/) {
}
void CCVKBuffer::doInit(const BufferViewInfo &info) {
auto *buffer = static_cast<CCVKBuffer *>(info.buffer);
_gpuBuffer = buffer->gpuBuffer();
auto *buffer = static_cast<CCVKBuffer *>(info.buffer);
_gpuBuffer = buffer->gpuBuffer();
_gpuBufferView = CC_NEW(CCVKGPUBufferView);
createBufferView();
}
void CCVKBuffer::createBufferView() {
_gpuBufferView->gpuBuffer = _gpuBuffer;
_gpuBufferView->offset = _offset;
_gpuBufferView->range = _size;
_gpuBufferView->offset = _offset;
_gpuBufferView->range = _size;
CCVKDevice::getInstance()->gpuDescriptorHub()->update(_gpuBufferView);
}
@@ -94,14 +94,17 @@ void CCVKBuffer::doDestroy() {
}
void CCVKBuffer::doResize(uint size, uint count) {
VkDeviceSize oldStartOffset = _gpuBuffer->startOffset;
CCVKDevice::getInstance()->getMemoryStatus().bufferSize -= _size;
CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer);
_gpuBuffer->size = size;
_gpuBuffer->size = size;
_gpuBuffer->count = count;
cmdFuncCCVKCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer);
createBufferView();
_gpuBufferView->range = size;
CCVKDevice::getInstance()->gpuDescriptorHub()->update(_gpuBuffer, oldStartOffset);
if (hasFlag(_usage, BufferUsageBit::INDIRECT)) {
const size_t drawInfoCount = _size / sizeof(DrawInfo);
@@ -57,8 +57,7 @@ void CCVKCommandBuffer::doInit(const CommandBufferInfo & /*info*/) {
size_t setCount = CCVKDevice::getInstance()->bindingMappingInfo().bufferOffsets.size();
_curGPUDescriptorSets.resize(setCount);
_curVkDescriptorSets.resize(setCount);
_curDynamicOffsetPtrs.resize(setCount);
_curDynamicOffsetCounts.resize(setCount);
_curDynamicOffsetsArray.resize(setCount);
}
void CCVKCommandBuffer::doDestroy() {
@@ -76,7 +75,7 @@ void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer
_curGPUPipelineState = nullptr;
_curGPUInputAssember = nullptr;
_curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr);
_curDynamicOffsetCounts.assign(_curDynamicOffsetCounts.size(), 0U);
_curDynamicOffsetsArray.assign(_curDynamicOffsetsArray.size(), {});
_firstDirtyDescriptorSet = UINT_MAX;
_numDrawCalls = 0;
@@ -127,10 +126,10 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo
// guard against RAW hazard
VkMemoryBarrier vkBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
vkBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vkBarrier.dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT;
vkBarrier.dstAccessMask = VK_ACCESS_UNIFORM_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
vkCmdPipelineBarrier(_gpuCommandBuffer->vkCommandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
0, 1, &vkBarrier, 0, nullptr, 0, nullptr);
#endif
@@ -223,8 +222,7 @@ void CCVKCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet
if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set;
}
if (dynamicOffsetCount) {
_curDynamicOffsetPtrs[set] = dynamicOffsets;
_curDynamicOffsetCounts[set] = dynamicOffsetCount;
_curDynamicOffsetsArray[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount);
if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set;
}
}
@@ -573,8 +571,8 @@ void CCVKCommandBuffer::bindDescriptorSets(VkPipelineBindPoint bindPoint) {
}
uint count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i];
//CCASSERT(_curDynamicOffsetCounts[i] >= count, "missing dynamic offsets?");
count = std::min(count, _curDynamicOffsetCounts[i]);
if (count > 0) memcpy(&_curDynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsetPtrs[i], count * sizeof(uint));
count = std::min(count, utils::toUint(_curDynamicOffsetsArray[i].size()));
if (count > 0) memcpy(&_curDynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsetsArray[i].data(), count * sizeof(uint));
}
uint dynamicOffsetStartIndex = dynamicOffsetOffsets[_firstDirtyDescriptorSet];
@@ -77,8 +77,7 @@ protected:
vector<CCVKGPUDescriptorSet *> _curGPUDescriptorSets;
vector<VkDescriptorSet> _curVkDescriptorSets;
vector<uint> _curDynamicOffsets;
vector<const uint *> _curDynamicOffsetPtrs;
vector<uint> _curDynamicOffsetCounts;
vector<vector<uint>> _curDynamicOffsetsArray;
uint _firstDirtyDescriptorSet = UINT_MAX;
CCVKGPUInputAssembler *_curGPUInputAssember = nullptr;
@@ -107,6 +107,10 @@ void cmdFuncCCVKCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) {
if (!gpuTexture->size) return;
gpuTexture->aspectMask = mapVkImageAspectFlags(gpuTexture->format);
// storage images has to be in general layout
if (hasFlag(gpuTexture->usage, TextureUsageBit::STORAGE)) gpuTexture->flags |= TextureFlagBit::GENERAL_LAYOUT;
// remove stencil aspect for depth textures with sampled usage
if (hasFlag(gpuTexture->usage, TextureUsageBit::SAMPLED)) gpuTexture->aspectMask &= ~VK_IMAGE_ASPECT_STENCIL_BIT;
VkFormat format = mapVkFormat(gpuTexture->format);
VkFormatFeatureFlags features = mapVkFormatFeatureFlags(gpuTexture->usage);
@@ -227,9 +231,9 @@ void cmdFuncCCVKCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) {
bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT;
allocInfo.usage = VMA_MEMORY_USAGE_GPU_ONLY;
} else if (gpuBuffer->memUsage == (MemoryUsage::HOST | MemoryUsage::DEVICE)) {
gpuBuffer->instanceSize = roundUp(gpuBuffer->size, device->getCapabilities().uboOffsetAlignment);
bufferInfo.size = gpuBuffer->instanceSize * device->gpuDevice()->backBufferCount;
allocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT;
//gpuBuffer->instanceSize = roundUp(gpuBuffer->size, device->getCapabilities().uboOffsetAlignment);
//bufferInfo.size = gpuBuffer->instanceSize * device->gpuDevice()->backBufferCount;
//allocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT;
allocInfo.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
}
@@ -293,7 +297,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
attachmentDescriptions[i].storeOp = mapVkStoreOp(attachment.storeOp);
attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachmentDescriptions[i].initialLayout = beginAccessInfo.imageLayout;
attachmentDescriptions[i].initialLayout = attachment.loadOp == gfx::LoadOp::LOAD ? beginAccessInfo.imageLayout : VK_IMAGE_LAYOUT_UNDEFINED;
attachmentDescriptions[i].finalLayout = endAccessInfo.imageLayout;
}
if (hasDepth) {
@@ -323,7 +327,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende
attachmentDescriptions[colorAttachmentCount].storeOp = mapVkStoreOp(depthStencilAttachment.depthStoreOp);
attachmentDescriptions[colorAttachmentCount].stencilLoadOp = mapVkLoadOp(depthStencilAttachment.stencilLoadOp);
attachmentDescriptions[colorAttachmentCount].stencilStoreOp = mapVkStoreOp(depthStencilAttachment.stencilStoreOp);
attachmentDescriptions[colorAttachmentCount].initialLayout = beginAccessInfo.imageLayout;
attachmentDescriptions[colorAttachmentCount].initialLayout = depthStencilAttachment.depthLoadOp == gfx::LoadOp::LOAD ? beginAccessInfo.imageLayout : VK_IMAGE_LAYOUT_UNDEFINED;
attachmentDescriptions[colorAttachmentCount].finalLayout = endAccessInfo.imageLayout;
}
@@ -1212,6 +1216,9 @@ CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTe
}
void cmdFuncCCVKDestroyRenderPass(CCVKGPUDevice *gpuDevice, CCVKGPURenderPass *gpuRenderPass) {
gpuRenderPass->beginAccesses.clear();
gpuRenderPass->endAccesses.clear();
if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) {
vkDestroyRenderPass(gpuDevice->vkDevice, gpuRenderPass->vkRenderPass, nullptr);
gpuRenderPass->vkRenderPass = VK_NULL_HANDLE;
@@ -108,7 +108,9 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) {
} else if (hasFlag(DESCRIPTOR_TEXTURE_TYPE, binding.descriptorType)) {
instance.descriptorInfos[k].image.sampler = gpuDevice->defaultSampler.vkSampler;
instance.descriptorInfos[k].image.imageView = gpuDevice->defaultTextureView.vkImageView;
instance.descriptorInfos[k].image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
instance.descriptorInfos[k].image.imageLayout = hasFlag(binding.descriptorType, DescriptorType::STORAGE_IMAGE)
? VK_IMAGE_LAYOUT_GENERAL
: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
}
}
@@ -935,6 +935,20 @@ public:
}
}
}
// for resize events
void update(const CCVKGPUBuffer *buffer, VkDeviceSize oldStartOffset) {
for (const auto &it : _buffers) {
if (it.first->gpuBuffer != buffer) continue;
const auto &info = it.second;
for (uint i = 0U; i < info.descriptors.size(); i++) {
info.descriptors[i]->buffer = buffer->vkBuffer;
info.descriptors[i]->offset += buffer->startOffset - oldStartOffset;
}
for (const auto *set : info.sets) {
_descriptorSetHub->record(set);
}
}
}
void disengage(const CCVKGPUBufferView *buffer) {
auto it = _buffers.find(buffer);
+1 -1
View File
@@ -28,7 +28,7 @@
#include "base/Log.h"
#include "gfx-base/GFXDef.h"
#include "StandAlone/ResourceLimits.h"
#include "glslang/StandAlone/ResourceLimits.h"
#include "glslang/Public/ShaderLang.h"
#include "glslang/SPIRV/GlslangToSpv.h"
+1 -1
View File
@@ -37,7 +37,7 @@
#include "thsvs_simpler_vulkan_synchronization.h"
#define DEFAULT_TIMEOUT 1000000000 // 1 second
#define DEFAULT_TIMEOUT 10000000000 // 10 second
#define BARRIER_DEDUCTION_LEVEL_NONE 0
#define BARRIER_DEDUCTION_LEVEL_BASIC 1
+1
View File
@@ -250,6 +250,7 @@ enum class CC_DLL SetIndex {
MATERIAL,
LOCAL,
};
CC_ENUM_CONVERSION_OPERATOR(SetIndex)
extern CC_DLL uint globalSet;
extern CC_DLL uint materialSet;
+79 -80
View File
@@ -70,8 +70,7 @@ void PipelineUBO::updateGlobalUBOView(const RenderPipeline * /*pipeline*/, std::
uboGlobalView[UBOGlobal::NATIVE_SIZE_OFFSET + 3] = 1.0F / uboGlobalView[UBOGlobal::NATIVE_SIZE_OFFSET + 1];
}
void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array<float, UBOCamera::COUNT> *bufferView,
const scene::Camera *camera) {
void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *output, const scene::Camera *camera) {
const auto *const scene = camera->scene;
const scene::DirectionalLight *mainLight = scene->getMainLight();
auto * sceneData = pipeline->getPipelineSceneData();
@@ -83,41 +82,40 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array
const auto isHDR = sharedData->isHDR;
const auto shadingScale = sharedData->shadingScale;
auto *device = gfx::Device::getInstance();
auto &uboCameraView = *bufferView;
auto *device = gfx::Device::getInstance();
const auto shadingWidth = std::floor(device->getWidth());
const auto shadingHeight = std::floor(device->getHeight());
uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 0] = static_cast<float>(camera->width / shadingWidth * shadingScale);
uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 1] = static_cast<float>(camera->height / shadingHeight * shadingScale);
uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 2] = 1.0F / uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET];
uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 3] = 1.0F / uboCameraView[UBOCamera::SCREEN_SCALE_OFFSET + 1];
output[UBOCamera::SCREEN_SCALE_OFFSET + 0] = static_cast<float>(camera->width / shadingWidth * shadingScale);
output[UBOCamera::SCREEN_SCALE_OFFSET + 1] = static_cast<float>(camera->height / shadingHeight * shadingScale);
output[UBOCamera::SCREEN_SCALE_OFFSET + 2] = 1.0F / output[UBOCamera::SCREEN_SCALE_OFFSET];
output[UBOCamera::SCREEN_SCALE_OFFSET + 3] = 1.0F / output[UBOCamera::SCREEN_SCALE_OFFSET + 1];
const auto exposure = camera->exposure;
uboCameraView[UBOCamera::EXPOSURE_OFFSET + 0] = exposure;
uboCameraView[UBOCamera::EXPOSURE_OFFSET + 1] = 1.0F / exposure;
uboCameraView[UBOCamera::EXPOSURE_OFFSET + 2] = isHDR ? 1.0F : 0.0F;
uboCameraView[UBOCamera::EXPOSURE_OFFSET + 3] = fpScale / exposure;
const auto exposure = camera->exposure;
output[UBOCamera::EXPOSURE_OFFSET + 0] = exposure;
output[UBOCamera::EXPOSURE_OFFSET + 1] = 1.0F / exposure;
output[UBOCamera::EXPOSURE_OFFSET + 2] = isHDR ? 1.0F : 0.0F;
output[UBOCamera::EXPOSURE_OFFSET + 3] = fpScale / exposure;
if (mainLight) {
TO_VEC3(uboCameraView, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET);
TO_VEC3(uboCameraView, mainLight->getColor(), UBOCamera::MAIN_LIT_COLOR_OFFSET);
TO_VEC3(output, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET);
TO_VEC3(output, mainLight->getColor(), UBOCamera::MAIN_LIT_COLOR_OFFSET);
if (mainLight->getUseColorTemperature()) {
const auto &colorTempRGB = mainLight->getColorTemperatureRGB();
uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 0] *= colorTempRGB.x;
uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 1] *= colorTempRGB.y;
uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 2] *= colorTempRGB.z;
output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 0] *= colorTempRGB.x;
output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 1] *= colorTempRGB.y;
output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 2] *= colorTempRGB.z;
}
if (isHDR) {
uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * fpScale;
output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * fpScale;
} else {
uboCameraView[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * exposure;
output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 3] = mainLight->getIlluminance() * exposure;
}
} else {
TO_VEC3(uboCameraView, Vec3::UNIT_Z, UBOCamera::MAIN_LIT_DIR_OFFSET);
TO_VEC4(uboCameraView, Vec4::ZERO, UBOCamera::MAIN_LIT_COLOR_OFFSET);
TO_VEC3(output, Vec3::UNIT_Z, UBOCamera::MAIN_LIT_DIR_OFFSET);
TO_VEC4(output, Vec4::ZERO, UBOCamera::MAIN_LIT_COLOR_OFFSET);
}
Vec4 skyColor = ambient->skyColor;
@@ -126,36 +124,36 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, std::array
} else {
skyColor.w = ambient->skyIllum * exposure;
}
TO_VEC4(uboCameraView, skyColor, UBOCamera::AMBIENT_SKY_OFFSET);
TO_VEC4(output, skyColor, UBOCamera::AMBIENT_SKY_OFFSET);
uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 0] = ambient->groundAlbedo.x;
uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 1] = ambient->groundAlbedo.y;
uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 2] = ambient->groundAlbedo.z;
auto *const envmap = descriptorSet->getTexture(static_cast<uint>(PipelineGlobalBindings::SAMPLER_ENVIRONMENT));
output[UBOCamera::AMBIENT_GROUND_OFFSET + 0] = ambient->groundAlbedo.x;
output[UBOCamera::AMBIENT_GROUND_OFFSET + 1] = ambient->groundAlbedo.y;
output[UBOCamera::AMBIENT_GROUND_OFFSET + 2] = ambient->groundAlbedo.z;
auto *const envmap = descriptorSet->getTexture(static_cast<uint>(PipelineGlobalBindings::SAMPLER_ENVIRONMENT));
if (envmap) {
uboCameraView[UBOCamera::AMBIENT_GROUND_OFFSET + 3] = static_cast<float>(envmap->getLevelCount());
output[UBOCamera::AMBIENT_GROUND_OFFSET + 3] = static_cast<float>(envmap->getLevelCount());
}
memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_OFFSET, camera->matView.m, sizeof(cc::Mat4));
memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_INV_OFFSET, camera->node->getWorldMatrix().m, sizeof(cc::Mat4));
TO_VEC3(uboCameraView, camera->position, UBOCamera::CAMERA_POS_OFFSET);
memcpy(output + UBOCamera::MAT_VIEW_OFFSET, camera->matView.m, sizeof(cc::Mat4));
memcpy(output + UBOCamera::MAT_VIEW_INV_OFFSET, camera->node->getWorldMatrix().m, sizeof(cc::Mat4));
TO_VEC3(output, camera->position, UBOCamera::CAMERA_POS_OFFSET);
memcpy(uboCameraView.data() + UBOCamera::MAT_PROJ_OFFSET, camera->matProj.m, sizeof(cc::Mat4));
memcpy(uboCameraView.data() + UBOCamera::MAT_PROJ_INV_OFFSET, camera->matProjInv.m, sizeof(cc::Mat4));
memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_PROJ_OFFSET, camera->matViewProj.m, sizeof(cc::Mat4));
memcpy(uboCameraView.data() + UBOCamera::MAT_VIEW_PROJ_INV_OFFSET, camera->matViewProjInv.m, sizeof(cc::Mat4));
uboCameraView[UBOCamera::CAMERA_POS_OFFSET + 3] = getCombineSignY();
memcpy(output + UBOCamera::MAT_PROJ_OFFSET, camera->matProj.m, sizeof(cc::Mat4));
memcpy(output + UBOCamera::MAT_PROJ_INV_OFFSET, camera->matProjInv.m, sizeof(cc::Mat4));
memcpy(output + UBOCamera::MAT_VIEW_PROJ_OFFSET, camera->matViewProj.m, sizeof(cc::Mat4));
memcpy(output + UBOCamera::MAT_VIEW_PROJ_INV_OFFSET, camera->matViewProjInv.m, sizeof(cc::Mat4));
output[UBOCamera::CAMERA_POS_OFFSET + 3] = getCombineSignY();
if (fog->enabled) {
TO_VEC4(uboCameraView, fog->color, UBOCamera::GLOBAL_FOG_COLOR_OFFSET);
TO_VEC4(output, fog->color, UBOCamera::GLOBAL_FOG_COLOR_OFFSET);
uboCameraView[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 0] = fog->start;
uboCameraView[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 1] = fog->end;
uboCameraView[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 2] = fog->density;
output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 0] = fog->start;
output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 1] = fog->end;
output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 2] = fog->density;
uboCameraView[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 0] = fog->top;
uboCameraView[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 1] = fog->range;
uboCameraView[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 2] = fog->atten;
output[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 0] = fog->top;
output[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 1] = fog->range;
output[UBOCamera::GLOBAL_FOG_ADD_OFFSET + 2] = fog->atten;
}
}
@@ -173,7 +171,7 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array
if (shadowInfo->enabled) {
if (mainLight && shadowInfo->shadowType == scene::ShadowType::SHADOWMAP) {
auto *const node = mainLight->getNode();
cc::Mat4 matShadowCamera;
cc::Mat4 matShadowCamera;
// light proj
float x;
@@ -206,15 +204,15 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array
matShadowViewProj.multiply(matShadowView);
memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj));
const float linear = hFTexture ? 1.0F : 0.0F;
float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, 1.0F - shadowInfo->saturation};
const float linear = hFTexture ? 1.0F : 0.0F;
float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, 1.0F - shadowInfo->saturation};
memcpy(shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos));
float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast<float>(shadowInfo->pcfType), shadowInfo->bias};
memcpy(shadowUBO.data() + UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET, &shadowWHPBInfos, sizeof(shadowWHPBInfos));
const float packing = hFTexture ? 0.0F : 1.0F;
float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F};
const float packing = hFTexture ? 0.0F : 1.0F;
float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F};
memcpy(shadowUBO.data() + UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET, &shadowLPNNInfos, sizeof(shadowLPNNInfos));
} else if (mainLight && shadowInfo->shadowType == scene::ShadowType::PLANAR) {
updateDirLight(shadowInfo, mainLight, &shadowUBO);
@@ -226,14 +224,14 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array
}
void PipelineUBO::updateShadowUBOLightView(const RenderPipeline *pipeline, std::array<float, UBOShadow::COUNT> *bufferView, const scene::Light *light) {
auto *const sceneData = pipeline->getPipelineSceneData();
auto * shadowInfo = sceneData->getSharedData()->shadow;
auto * device = gfx::Device::getInstance();
auto * sphere = sceneData->getSphere();
auto & shadowUBO = *bufferView;
const bool hFTexture = supportsHalfFloatTexture(device);
const float linear = hFTexture ? 1.0F : 0.0F;
const float packing = hFTexture ? 0.0F : 1.0F;
auto *const sceneData = pipeline->getPipelineSceneData();
auto * shadowInfo = sceneData->getSharedData()->shadow;
auto * device = gfx::Device::getInstance();
auto * sphere = sceneData->getSphere();
auto & shadowUBO = *bufferView;
const bool hFTexture = supportsHalfFloatTexture(device);
const float linear = hFTexture ? 1.0F : 0.0F;
const float packing = hFTexture ? 0.0F : 1.0F;
switch (light->getType()) {
case scene::LightType::DIRECTIONAL: {
const auto *directionalLight = static_cast<const scene::DirectionalLight *>(light);
@@ -330,12 +328,21 @@ void PipelineUBO::activate(gfx::Device *device, RenderPipeline *pipeline) {
descriptorSet->bindBuffer(UBOGlobal::BINDING, globalUBO);
_ubos.push_back(globalUBO);
auto *cameraUBO = _device->createBuffer({
_alignedCameraUBOSize = utils::alignTo(UBOCamera::SIZE, _device->getCapabilities().uboOffsetAlignment);
_cameraBuffer = _device->createBuffer({
gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST,
gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE,
_alignedCameraUBOSize,
_alignedCameraUBOSize,
});
_ubos.push_back(_cameraBuffer);
_cameraUBOs.resize(_alignedCameraUBOSize / sizeof(float));
auto *cameraUBO = _device->createBuffer({
_cameraBuffer,
0,
UBOCamera::SIZE,
UBOCamera::SIZE,
gfx::BufferFlagBit::NONE,
});
descriptorSet->bindBuffer(UBOCamera::BINDING, cameraUBO);
_ubos.push_back(cameraUBO);
@@ -373,37 +380,29 @@ void PipelineUBO::updateCameraUBO(const scene::Camera *camera) {
auto *const globalDSManager = _pipeline->getGlobalDSManager();
auto *const ds = _pipeline->getDescriptorSet();
auto *const cmdBuffer = _pipeline->getCommandBuffers()[0];
PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBO, camera);
cmdBuffer->updateBuffer(ds->getBuffer(UBOCamera::BINDING), _cameraUBO.data(), UBOCamera::SIZE);
globalDSManager->bindBuffer(UBOCamera::BINDING, ds->getBuffer(UBOCamera::BINDING));
globalDSManager->update();
PipelineUBO::updateCameraUBOView(_pipeline, _cameraUBOs.data(), camera);
cmdBuffer->updateBuffer(_cameraBuffer, _cameraUBOs.data());
}
void PipelineUBO::updateMultiCameraUBO(const vector<scene::Camera *> &cameras) {
auto *const ds = _pipeline->getDescriptorSet();
auto * device = _pipeline->getDevice();
auto uboAlignment = device->getCapabilities().uboOffsetAlignment;
_alignedCameraUBOSize = static_cast<uint>(std::ceil(UBOCamera::SIZE / static_cast<float>(uboAlignment))) * uboAlignment;
auto cameraCount = cameras.size();
auto totalUboSize = static_cast<uint>(_alignedCameraUBOSize * cameraCount);
auto cameraCount = cameras.size();
auto totalUboSize = static_cast<uint>(_alignedCameraUBOSize * cameraCount);
if (_cameraBuffer->getSize() < totalUboSize) {
_cameraBuffer->resize(totalUboSize);
_cameraUBOs.resize(totalUboSize / sizeof(float));
}
_cameraUBOs.resize(totalUboSize);
_currentCameraUBOOffset = 0;
for (uint cameraIdx = 0; cameraIdx < cameraCount; ++cameraIdx) {
auto *camera = cameras[cameraIdx];
PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBO, camera);
auto offset = cameraIdx * _alignedCameraUBOSize;
memcpy(&_cameraUBOs[offset], _cameraUBO.data(), UBOCamera::SIZE);
auto offset = cameraIdx * _alignedCameraUBOSize / sizeof(float);
PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBOs[offset], camera);
}
auto *uboBuffer = ds->getBuffer(UBOCamera::BINDING);
if (uboBuffer->getSize() < totalUboSize) {
uboBuffer->resize(totalUboSize);
}
uboBuffer->update(_cameraUBOs.data(), totalUboSize);
_cameraBuffer->update(_cameraUBOs.data());
ds->bindBuffer(UBOCamera::BINDING, uboBuffer);
ds->update();
_currentCameraUBOOffset = 0;
}
void PipelineUBO::updateShadowUBO(const scene::Camera *camera) {
+4 -5
View File
@@ -41,7 +41,7 @@ class RenderPipeline;
class CC_DLL PipelineUBO : public Object {
public:
static void updateGlobalUBOView(const RenderPipeline *pipeline, std::array<float, UBOGlobal::COUNT> *bufferView);
static void updateCameraUBOView(const RenderPipeline *pipeline, std::array<float, UBOCamera::COUNT> *bufferView, const scene::Camera *camera);
static void updateCameraUBOView(const RenderPipeline *pipeline, float *output, const scene::Camera *camera);
static void updateShadowUBOView(const RenderPipeline *pipeline, std::array<float, UBOShadow::COUNT> *bufferView, const scene::Camera *camera);
static void updateShadowUBOLightView(const RenderPipeline *pipeline, std::array<float, UBOShadow::COUNT> *bufferView, const scene::Light *light);
static uint8_t getCombineSignY();
@@ -52,11 +52,10 @@ public:
void destroy();
void updateGlobalUBO();
void updateCameraUBO(const scene::Camera *camera);
void updateMultiCameraUBO(const vector<scene::Camera*> &cameras);
void updateMultiCameraUBO(const vector<scene::Camera *> &cameras);
void updateShadowUBO(const scene::Camera *camera);
void updateShadowUBOLight(const scene::Light *light);
void updateShadowUBORange(uint offset, const Mat4 *data);
void destroyShadowFrameBuffers();
uint getCurrentCameraUBOOffset() const;
void incCameraUBOOffset();
@@ -66,12 +65,12 @@ private:
gfx::Device * _device = nullptr;
std::array<float, UBOGlobal::COUNT> _globalUBO;
std::array<float, UBOCamera::COUNT> _cameraUBO;
std::array<float, UBOShadow::COUNT> _shadowUBO;
std::vector<gfx::Buffer *> _ubos;
void initCombineSignY();
std::vector<std::byte> _cameraUBOs;
std::vector<float> _cameraUBOs;
gfx::Buffer * _cameraBuffer{nullptr};
uint _currentCameraUBOOffset{0};
uint _alignedCameraUBOSize{0};
};
@@ -198,6 +198,8 @@ void DeferredPipeline::prepareFrameGraph() {
}
void DeferredPipeline::render(const vector<scene::Camera *> &cameras) {
static gfx::TextureBarrier *present{_device->createTextureBarrier({{gfx::AccessType::COLOR_ATTACHMENT_WRITE}, {gfx::AccessType::PRESENT}})};
static gfx::Texture * backBuffer{nullptr};
_commandBuffers[0]->begin();
_pipelineUBO->updateGlobalUBO();
_pipelineUBO->updateMultiCameraUBO(cameras);
@@ -217,6 +219,7 @@ void DeferredPipeline::render(const vector<scene::Camera *> &cameras) {
_pipelineUBO->incCameraUBOOffset();
}
_commandBuffers[0]->pipelineBarrier(nullptr, &present, &backBuffer, 1);
_commandBuffers[0]->end();
_device->flushCommands(_commandBuffers);
_device->getQueue()->submit(_commandBuffers);
@@ -247,10 +250,12 @@ gfx::InputAssembler *DeferredPipeline::getIAByRenderArea(const gfx::Rect &rect)
}
void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform /*surfaceTransform*/, const gfx::Rect &renderArea, float *vbData) {
float minX = float(renderArea.x) / _width;
float maxX = float(renderArea.x + renderArea.width) / _width;
float minY = float(renderArea.y) / _height;
float maxY = float(renderArea.y + renderArea.height) / _height;
auto width = float(_width);
auto height = float(_height);
auto minX = float(renderArea.x) / width;
auto maxX = float(renderArea.x + renderArea.width) / width;
auto minY = float(renderArea.y) / height;
auto maxY = float(renderArea.y + renderArea.height) / height;
if (_device->getCapabilities().screenSpaceSignY > 0) {
std::swap(minY, maxY);
}
@@ -32,11 +32,13 @@
#include "../RenderInstancedQueue.h"
#include "../RenderQueue.h"
#include "DeferredPipeline.h"
#include "base/Utils.h"
#include "gfx-base/GFXCommandBuffer.h"
#include "gfx-base/GFXDescriptorSet.h"
#include "gfx-base/GFXDevice.h"
#include "gfx-base/GFXFramebuffer.h"
#include "gfx-base/GFXQueue.h"
#include "pipeline/Define.h"
#include "scene/RenderScene.h"
#include "scene/Sphere.h"
#include "scene/SphereLight.h"
@@ -253,8 +255,8 @@ void LightingStage::initLightingBuffer() {
auto *const device = _pipeline->getDevice();
// color/pos/dir/angle 都是vec4存储, 最后一个vec4只要x存储光源个数
uint totalSize = sizeof(Vec4) * 4 * _maxDeferredLights;
totalSize = static_cast<uint>(std::ceil(static_cast<float>(totalSize) / device->getCapabilities().uboOffsetAlignment) * device->getCapabilities().uboOffsetAlignment);
uint stride = utils::alignTo(sizeof(Vec4) * 4, device->getCapabilities().uboOffsetAlignment);
uint totalSize = stride * _maxDeferredLights;
// create lighting buffer and view
if (_deferredLitsBufs == nullptr) {
@@ -262,7 +264,7 @@ void LightingStage::initLightingBuffer() {
gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST,
gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE,
totalSize,
static_cast<uint>(device->getCapabilities().uboOffsetAlignment),
stride,
};
_deferredLitsBufs = device->createBuffer(bfInfo);
assert(_deferredLitsBufs != nullptr);
@@ -334,11 +336,10 @@ void LightingStage::recordCommandsLit(DeferredPipeline *pipeline, gfx::RenderPas
auto *cmdBuff = pipeline->getCommandBuffers()[0];
vector<uint> dynamicOffsets = {0};
cmdBuff->bindDescriptorSet(static_cast<uint>(SetIndex::LOCAL), _descriptorSet, dynamicOffsets);
cmdBuff->bindDescriptorSet(localSet, _descriptorSet, dynamicOffsets);
uint const globalOffsets[] = {_pipeline->getPipelineUBO()->getCurrentCameraUBOOffset()};
cmdBuff->bindDescriptorSet(static_cast<uint>(SetIndex::GLOBAL), pipeline->getDescriptorSet(), static_cast<uint>(std::size(globalOffsets)), globalOffsets);
cmdBuff->bindDescriptorSet(globalSet, pipeline->getDescriptorSet(), static_cast<uint>(std::size(globalOffsets)), globalOffsets);
// get pso and draw quad
auto rendeArea = pipeline->getRenderArea(pipeline->getFrameGraphCamera(), false);
@@ -351,6 +352,7 @@ void LightingStage::recordCommandsLit(DeferredPipeline *pipeline, gfx::RenderPas
cmdBuff->bindPipelineState(pState);
cmdBuff->bindInputAssembler(inputAssembler);
cmdBuff->bindDescriptorSet(materialSet, pass->getDescriptorSet());
cmdBuff->draw(inputAssembler);
}
@@ -32,6 +32,7 @@
#include "gfx-base/GFXCommandBuffer.h"
#include "gfx-base/GFXDevice.h"
#include "gfx-base/GFXFramebuffer.h"
#include "pipeline/Define.h"
#include "scene/SubModel.h"
#include "frame-graph/PassNodeBuilder.h"
#include "frame-graph/DevicePass.h"
@@ -70,7 +70,7 @@ gfx::RenderPass *ForwardPipeline::getOrCreateRenderPass(gfx::ClearFlags clearFla
colorAttachment.loadOp = gfx::LoadOp::DISCARD;
} else {
colorAttachment.loadOp = gfx::LoadOp::LOAD;
colorAttachment.beginAccesses = {gfx::AccessType::PRESENT};
colorAttachment.beginAccesses = {gfx::AccessType::COLOR_ATTACHMENT_WRITE};
}
}
@@ -122,6 +122,8 @@ bool ForwardPipeline::activate() {
}
void ForwardPipeline::render(const vector<scene::Camera *> &cameras) {
static gfx::TextureBarrier *present{_device->createTextureBarrier({{gfx::AccessType::COLOR_ATTACHMENT_WRITE}, {gfx::AccessType::PRESENT}})};
static gfx::Texture * backBuffer{nullptr};
_commandBuffers[0]->begin();
_pipelineUBO->updateGlobalUBO();
_pipelineUBO->updateMultiCameraUBO(cameras);
@@ -132,6 +134,7 @@ void ForwardPipeline::render(const vector<scene::Camera *> &cameras) {
}
_pipelineUBO->incCameraUBOOffset();
}
_commandBuffers[0]->pipelineBarrier(nullptr, &present, &backBuffer, 1);
_commandBuffers[0]->end();
_device->flushCommands(_commandBuffers);
_device->getQueue()->submit(_commandBuffers);
+1
View File
@@ -173,6 +173,7 @@ void Node::initWithData(uint8_t *data, uint8_t *flagChunk, const se::Value &dirt
dirtyNodes->incRef();
se::ScriptEngine::getInstance()->addBeforeCleanupHook([]() {
dirtyNodes->decRef();
dirtyNodes = nullptr;
});
}
}
+8 -8
View File
@@ -1,8 +1,8 @@
/****************************************************************************
Copyright (c) 2021 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
@@ -10,10 +10,10 @@
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -39,16 +39,16 @@ SubModel::~SubModel() {
delete _subMesh;
}
gfx::Shader *SubModel::getShader(int index) const {
if (index >= static_cast<int>(_shaders.size())) {
gfx::Shader *SubModel::getShader(uint index) const {
if (index >= _shaders.size()) {
return nullptr;
}
return _shaders[index];
}
Pass *SubModel::getPass(int index) const {
if (index >= static_cast<int>(_passes.size())) {
Pass *SubModel::getPass(uint index) const {
if (index >= _passes.size()) {
return nullptr;
}
+6 -6
View File
@@ -1,8 +1,8 @@
/****************************************************************************
Copyright (c) 2021 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
@@ -10,10 +10,10 @@
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -47,8 +47,8 @@ public:
void update();
gfx::Shader *getShader(int) const;
Pass * getPass(int) const;
gfx::Shader *getShader(uint) const;
Pass * getPass(uint) const;
inline void setShaders(const std::vector<gfx::Shader *> &shaders) { _shaders = shaders; }
inline void setPasses(const std::vector<Pass *> &passes) { _passes = passes; }
@@ -34,10 +34,6 @@
#include <stdlib.h>
#include <memory>
#ifdef _WIN64
#define GWL_WNDPROC (-4)
#endif
extern std::shared_ptr<cc::View> cc_get_application_view();
namespace cc {
+3 -3
View File
@@ -1,9 +1,9 @@
{
"version": "v3d-gfx-55",
"version": "v3d-gfx-69",
"from": {
"type": "github",
"owner": "cocos-creator",
"name": "engine-native-external",
"checkout": "v3d-gfx-55"
"checkout": "v3d-gfx-69"
}
}
}
+16 -7
View File
@@ -36,7 +36,7 @@ var fs = require('fs-extra');
const which = require('which');
const del = require('del');
function absolutePath (relativePath) {
function absolutePath(relativePath) {
return Path.join(__dirname, relativePath);
}
@@ -54,7 +54,7 @@ else {
gulp.task('publish', gulpSequence('update', 'init', 'bump-version', 'make-simulator'));
}
function execSync (cmd, workPath) {
function execSync(cmd, workPath) {
var execOptions = {
cwd: workPath || '.',
stdio: 'inherit'
@@ -62,7 +62,7 @@ function execSync (cmd, workPath) {
ExecSync(cmd, execOptions);
}
function upload2Ftp (localPath, ftpPath, config, cb) {
function upload2Ftp(localPath, ftpPath, config, cb) {
var ftpClient = new Ftp();
ftpClient.on('error', function (err) {
if (err) {
@@ -96,7 +96,7 @@ function upload2Ftp (localPath, ftpPath, config, cb) {
ftpClient.connect(config);
}
function uploadZipFile (zipFileName, path, cb) {
function uploadZipFile(zipFileName, path, cb) {
var branch = getCurrentBranch();
if (branch === 'develop') {
branch = 'dev';
@@ -110,14 +110,14 @@ function uploadZipFile (zipFileName, path, cb) {
}, cb);
}
function getCurrentBranch () {
function getCurrentBranch() {
var spawnSync = require('child_process').spawnSync;
var output = spawnSync('git', ['symbolic-ref', '--short', '-q', 'HEAD']);
// console.log(output);
return output.stdout.toString().trim();
}
function formatPath (p) {
function formatPath(p) {
return p.replace(/\\/g, '/');
}
@@ -161,7 +161,16 @@ gulp.task('gen-simulator', async function () {
console.log('make project\n');
console.log('=====================================\n');
await new Promise((resolve, reject) => {
let cmakeProcess = spawn(cmakeBin, ['-G', isWin32 ? 'Visual Studio 15 2017' : 'Xcode', absolutePath('./tools/simulator/frameworks/runtime-src/')], {
var args = [];
args.push('-G');
if (isWin32) {
args.push('Visual Studio 15 2017','-A','Win32');
}
else {
args.push('Xcode');
}
args.push(absolutePath('./tools/simulator/frameworks/runtime-src/'));
let cmakeProcess = spawn(cmakeBin, args, {
cwd: simulatorProject,
});
cmakeProcess.on('close', () => {
@@ -9,7 +9,7 @@
<application
android:allowBackup="true"
android:label="@string/cc_app_name"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
@@ -21,7 +21,7 @@
android:name="com.cocos.game.AppActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
android:label="@string/cc_app_name"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:taskAffinity="" >
@@ -75,15 +75,15 @@ android {
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
resValue "string", "cc_app_name", PROP_APP_NAME
// resValue "string", "app_name", PROP_APP_NAME
}
debug {
debuggable true
jniDebuggable true
renderscriptDebuggable true
resValue "string", "cc_app_name", "${PROP_APP_NAME}-dbg"
applicationIdSuffix ".debug"
// resValue "string", "app_name", "${PROP_APP_NAME}-dbg"
// applicationIdSuffix ".debug"
}
}
}
@@ -11,7 +11,7 @@
<application
android:allowBackup="true"
android:label="@string/cc_app_name"
android:label="@string/app_name"
android:supportsRtl="true"
android:icon="@mipmap/ic_launcher">
<meta-data
@@ -24,7 +24,7 @@
android:name="com.cocos.game.InstantActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
android:label="@string/cc_app_name"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:taskAffinity="" >
@@ -71,15 +71,15 @@ android {
if (project.hasProperty("RELEASE_STORE_FILE")) {
signingConfig signingConfigs.release
}
resValue "string", "cc_app_name", PROP_APP_NAME
// resValue "string", "app_name", PROP_APP_NAME
}
debug {
debuggable true
jniDebuggable true
renderscriptDebuggable true
resValue "string", "cc_app_name", "${PROP_APP_NAME}-dbg"
applicationIdSuffix ".debug"
// resValue "string", "app_name", "${PROP_APP_NAME}-dbg"
// applicationIdSuffix ".debug"
}
}
}
@@ -0,0 +1,10 @@
oldmath/
newmath/
out*
dist*
index.ts
tsconfig.json
webpack.config.js
package.json
package-lock.json
node_modules/*
@@ -1,14 +1,37 @@
#include "cocos/bindings/jswrapper/SeApi.h"
#include "cocos/platform/FileUtils.h"
#include <string>
#include <sstream>
#include <cstdlib>
#include "cocos/bindings/manual/jsb_global_init.h"
int main(int argc, char **argv) {
std::string scriptPath = "index.js";
if(argc > 1) {
scriptPath = argv[1];
}
auto *engine = se::ScriptEngine::getInstance();
engine->init();
auto *fu = cc::FileUtils::getInstance();
// TODO: replace search path
auto *currentDir = getenv("PWD");
fu->addSearchPath(currentDir);
jsb_set_xxtea_key("");
jsb_init_file_operation_delegate();
engine->start();
engine->evalString("console.log('------------------------------------------');");
engine->evalString("console.log('----------hello from evalString()---------');");
engine->evalString("console.log('------------------------------------------');");
engine->evalString("console.log('begin execute')");
auto ret = engine->runScript(scriptPath);
engine->evalString("console.log('end')");
if(!ret) return EXIT_FAILURE;
se::ScriptEngine::destroyInstance();
cc::FileUtils::destroyInstance();
return 0;
}
@@ -7,9 +7,9 @@ const eglRegistry = { local: `${specDir}/egl.xml`, remote: 'https://www.khronos.
const glRegistry = { local: `${specDir}/gl.xml`, remote: 'https://www.khronos.org/registry/OpenGL/xml/gl.xml' };
const downloadSpec = async (specInfo) => {
if (fs.existsSync(specInfo.local)) return;
if (fs.existsSync(specInfo.local)) { return; }
fs.writeFileSync(specInfo.local, (await axios.get(specInfo.remote)).data);
}
};
const options = {
clear: false,
@@ -23,7 +23,7 @@ for (let i = 2; i < argc; i++) {
}
(async () => {
if (!fs.existsSync(specDir)) fs.mkdirSync(specDir);
if (!fs.existsSync(specDir)) { fs.mkdirSync(specDir); }
await downloadSpec(eglRegistry);
await downloadSpec(glRegistry);
@@ -68,9 +68,9 @@ for (let i = 2; i < argc; i++) {
append(`/* ${featureName} */\n`);
const feature = spec.feature.find((f) => f.name === featureName);
for (const manifest of feature.require) {
if (!manifest.command) continue;
if (!manifest.command) { continue; }
for (const command of manifest.command) {
if (nameRecord.has(command.name)) continue;
if (nameRecord.has(command.name)) { continue; }
writeCommand(command.name);
}
append(`\n`);
@@ -80,12 +80,12 @@ for (let i = 2; i < argc; i++) {
if (!noExtension) {
const featureAPI = spec.feature.find((f) => f.name === featureNames[0]).api;
for (const extension of spec.extensions[0].extension) {
if (!extension.supported.includes(featureAPI) || !extension.require) continue;
if (!extension.supported.includes(featureAPI) || !extension.require) { continue; }
let needDeclare = false;
for (const require of extension.require) {
if (require.api && !require.api.includes(featureAPI) ||
!require.command || !require.command.length ||
require.command.every((cmd) => nameRecord.has(cmd.name))) continue;
require.command.every((cmd) => nameRecord.has(cmd.name))) { continue; }
if (!needDeclare) {
append(`#if defined(${extension.name})\n`);
needDeclare = true;
@@ -93,7 +93,7 @@ for (let i = 2; i < argc; i++) {
append(`\n`);
}
for (const command of require.command) {
if (nameRecord.has(command.name)) continue;
if (nameRecord.has(command.name)) { continue; }
writeCommand(command.name);
}
}
@@ -103,9 +103,10 @@ for (let i = 2; i < argc; i++) {
}
}
return { headerDecl, sourceDef, sourceLoad };
}
};
const eglSrc = generate(eglSpec, ['EGL_VERSION_1_0', 'EGL_VERSION_1_1', 'EGL_VERSION_1_2', 'EGL_VERSION_1_3', 'EGL_VERSION_1_4', 'EGL_VERSION_1_5'], 'eglw', ['eglGetProcAddress']);
const eglSrc = generate(eglSpec, ['EGL_VERSION_1_0', 'EGL_VERSION_1_1', 'EGL_VERSION_1_2',
'EGL_VERSION_1_3', 'EGL_VERSION_1_4', 'EGL_VERSION_1_5'], 'eglw', ['eglGetProcAddress']);
const es2Src = generate(glSpec, ['GL_ES_VERSION_2_0'], 'gles2w');
const es3Src = generate(glSpec, ['GL_ES_VERSION_3_0', 'GL_ES_VERSION_3_1', 'GL_ES_VERSION_3_2'], 'gles3w', [], true);
@@ -113,11 +114,11 @@ for (let i = 2; i < argc; i++) {
const flag = `/\\* ${moduleName.toUpperCase()}_GENERATE_${keyword} \\*/\n`;
const flagRE = new RegExp(flag, 'g');
const indices = [];
while (flagRE.exec(source)) indices.push(flagRE.lastIndex);
if (indices.length !== 2) return source;
while (flagRE.exec(source)) { indices.push(flagRE.lastIndex); }
if (indices.length !== 2) { return source; }
indices[1] -= flag.length - 2; // two escape characters
if (options.clear) content = '';
if (indentEnd) content += ' ';
if (options.clear) { content = ''; }
if (indentEnd) { content += ' '; }
return source.slice(0, indices[0]) + content + source.slice(indices[1]);
};
@@ -514,13 +514,13 @@ int SimulatorWin::run()
// prepare
_project.dump();
g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)SimulatorWin::windowProc);
g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWLP_WNDPROC, (LONG)SimulatorWin::windowProc);
// update window title
updateWindowTitle();
bool resume, pause, close;
se::ScriptEngine::getInstance()->addRegisterCallback(setCanvasCallback);
se::ScriptEngine::getInstance()->addPermanentRegisterCallback(setCanvasCallback);
if (!_app->init()) return 1;
_quit = false;