[sync] Travis compile vulkan (#3343)

This commit is contained in:
江战
2021-03-25 13:48:03 +08:00
committed by GitHub
parent b6a78bd153
commit fe6da4a1d2
6 changed files with 100 additions and 74 deletions
+48 -47
View File
@@ -29,18 +29,19 @@
#include "uv.h"
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <memory>
#include <map>
#include <list>
#include <unordered_map>
#include <thread>
#include <mutex>
#include <atomic>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
#include "cocos/base/Macros.h"
#include "websockets/libwebsockets.h"
namespace cc {
@@ -89,9 +90,9 @@ public:
unsigned char *getData() { return _underlyingData.data() + LWS_PRE; }
private:
std::vector<unsigned char> _underlyingData;
int _consumed = 0;
bool _isBinary = false;
std::vector<unsigned char> _underlyingData;
int _consumed = 0;
bool _isBinary = false;
std::function<void(const std::string &)> _callback;
};
@@ -102,9 +103,9 @@ public:
enum ReadyState {
CONNECTING = 1,
OPEN = 2,
CLOSING = 3,
CLOSED = 4
OPEN = 2,
CLOSING = 3,
CLOSED = 4
};
void sendTextAsync(const std::string &, std::function<void(const std::string &)> callback);
@@ -162,7 +163,7 @@ public:
void onClientCloseInit();
inline void setData(void *d) { _data = d; }
inline void setData(void *d) { _data = d; }
inline void *getData() const { return _data; }
private:
@@ -176,31 +177,31 @@ private:
void onConnected();
void onDataReceive(void *in, int len);
int onDrainData();
int onDrainData();
void onHTTP();
void onClientCloseInit(int code, const std::string &msg);
void onDestroyClient();
struct lws *_wsi = nullptr;
std::map<std::string, std::string> _headers;
struct lws * _wsi = nullptr;
std::map<std::string, std::string> _headers;
std::list<std::shared_ptr<DataFrame>> _sendQueue;
std::shared_ptr<DataFrame> _prevPkg;
bool _closed = false;
std::string _closeReason = "close connection";
int _closeCode = 1000;
std::atomic<ReadyState> _readyState{ReadyState::CLOSED};
std::shared_ptr<DataFrame> _prevPkg;
bool _closed = false;
std::string _closeReason = "close connection";
int _closeCode = 1000;
std::atomic<ReadyState> _readyState{ReadyState::CLOSED};
// Attention: do not reference **this** in callbacks
std::function<void(int, const std::string &)> _onclose;
std::function<void(const std::string &)> _onerror;
std::function<void(int, const std::string &)> _onclose;
std::function<void(const std::string &)> _onerror;
std::function<void(std::shared_ptr<DataFrame>)> _ontext;
std::function<void(std::shared_ptr<DataFrame>)> _onbinary;
std::function<void(std::shared_ptr<DataFrame>)> _ondata;
std::function<void()> _onconnect;
std::function<void()> _onend;
uv_async_t _async = {0};
void *_data = nullptr;
std::function<void()> _onconnect;
std::function<void()> _onend;
uv_async_t _async = {0};
void * _data = nullptr;
friend class WebSocketServer;
};
@@ -211,7 +212,7 @@ public:
virtual ~WebSocketServer();
static void listenAsync(std::shared_ptr<WebSocketServer> &server, int port, const std::string &host, std::function<void(const std::string &errorMsg)> callback);
void closeAsync(std::function<void(const std::string &errorMsg)> callback = nullptr);
void closeAsync(std::function<void(const std::string &errorMsg)> callback = nullptr);
std::vector<std::shared_ptr<WebSocketServerConnection>> getConnections() const;
@@ -239,39 +240,39 @@ public:
_onbegin = cb;
}
inline void setData(void *d) { _data = d; }
inline void setData(void *d) { _data = d; }
inline void *getData() const { return _data; }
protected:
static void listen(std::shared_ptr<WebSocketServer> server, int port, const std::string &host, std::function<void(const std::string &errorMsg)> callback);
bool close(std::function<void(const std::string &errorMsg)> callback = nullptr);
bool close(std::function<void(const std::string &errorMsg)> callback = nullptr);
void onCreateClient(struct lws *wsi);
void onDestroyClient(struct lws *wsi);
void onCloseClient(struct lws *wsi);
void onCloseClientInit(struct lws *wsi, void *in, int len);
void onClientReceive(struct lws *wsi, void *in, int len);
int onServerWritable(struct lws *wsi);
int onServerWritable(struct lws *wsi);
void onClientHTTP(struct lws *wsi);
private:
std::shared_ptr<WebSocketServerConnection> findConnection(struct lws *wsi);
void destroyContext();
void destroyContext();
std::string _host;
lws_context *_ctx = nullptr;
uv_async_t _async = {0};
std::string _host;
lws_context *_ctx = nullptr;
uv_async_t _async = {0};
mutable std::mutex _connsMtx;
mutable std::mutex _connsMtx;
std::unordered_map<struct lws *, std::shared_ptr<WebSocketServerConnection>> _conns;
// Attention: do not reference **this** in callbacks
std::function<void(const std::string &)> _onlistening;
std::function<void(const std::string &)> _onerror;
std::function<void(const std::string &)> _onclose;
std::function<void(const std::string &)> _onclose_cb;
std::function<void()> _onend;
std::function<void()> _onbegin;
std::function<void(const std::string &)> _onlistening;
std::function<void(const std::string &)> _onerror;
std::function<void(const std::string &)> _onclose;
std::function<void(const std::string &)> _onclose_cb;
std::function<void()> _onend;
std::function<void()> _onbegin;
std::function<void(std::shared_ptr<WebSocketServerConnection>)> _onconnection;
enum class ServerThreadState {
@@ -282,8 +283,8 @@ private:
DESTROIED
};
std::atomic<ServerThreadState> _serverState{ServerThreadState::NOT_BOOTED};
std::mutex _serverLock;
void *_data = nullptr;
std::mutex _serverLock;
void * _data = nullptr;
public:
static int _websocketServerCallback(struct lws *wsi, enum lws_callback_reasons reason,
@@ -37,7 +37,7 @@ CCMTLInputAssembler::CCMTLInputAssembler() : InputAssembler() {}
void CCMTLInputAssembler::doInit(const InputAssemblerInfo &info) {
_GPUInputAssembler = CC_NEW(CCMTLGPUInputAssembler);
if (!_GPUInputAssembler) {
return false;
return;
}
if (info.indexBuffer) {
+20 -20
View File
@@ -41,7 +41,7 @@ void CCMTLShader::doInit(const ShaderInfo &info) {
for (const auto &stage : _stages) {
if (!createMTLFunction(stage)) {
destroy();
return false;
return;
}
}
@@ -52,11 +52,11 @@ void CCMTLShader::doInit(const ShaderInfo &info) {
void CCMTLShader::doDestroy() {
id<MTLFunction> vertFunc = _vertexMTLFunction;
_vertexMTLFunction = nil;
_vertexMTLFunction = nil;
id<MTLFunction> fragFunc = _fragmentMTLFunction;
_fragmentMTLFunction = nil;
_fragmentMTLFunction = nil;
id<MTLFunction> cmptFunc = _computeMTLFunction;
_computeMTLFunction = nil;
_computeMTLFunction = nil;
CC_SAFE_DELETE(_gpuShader);
@@ -75,10 +75,10 @@ void CCMTLShader::doDestroy() {
}
bool CCMTLShader::createMTLFunction(const ShaderStage &stage) {
bool isVertexShader = false;
bool isVertexShader = false;
bool isFragmentShader = false;
bool isComputeShader = false;
bool isComputeShader = false;
if (stage.stage == ShaderStageFlagBit::VERTEX) {
isVertexShader = true;
} else if (stage.stage == ShaderStageFlagBit::FRAGMENT) {
@@ -86,7 +86,7 @@ bool CCMTLShader::createMTLFunction(const ShaderStage &stage) {
} else if (stage.stage == ShaderStageFlagBit::COMPUTE) {
isComputeShader = true;
}
id<MTLDevice> mtlDevice = id<MTLDevice>(CCMTLDevice::getInstance()->getMTLDevice());
auto mtlShader = mu::compileGLSLShader2Msl(stage.source,
@@ -94,14 +94,14 @@ bool CCMTLShader::createMTLFunction(const ShaderStage &stage) {
CCMTLDevice::getInstance(),
_gpuShader);
NSString *shader = [NSString stringWithUTF8String:mtlShader.c_str()];
NSError *error = nil;
NSString * shader = [NSString stringWithUTF8String:mtlShader.c_str()];
NSError * error = nil;
id<MTLLibrary> library = [mtlDevice newLibraryWithSource:shader
options:nil
error:&error];
if (!library) {
CC_LOG_ERROR("Can not compile %s shader: %s", isVertexShader ? "vertex" :
isFragmentShader ? "fragment" : "compute",
CC_LOG_ERROR("Can not compile %s shader: %s", isVertexShader ? "vertex" : isFragmentShader ? "fragment"
: "compute",
[[error localizedDescription] UTF8String]);
CC_LOG_ERROR("%s", stage.source.c_str());
return false;
@@ -138,13 +138,13 @@ bool CCMTLShader::createMTLFunction(const ShaderStage &stage) {
#ifdef DEBUG_SHADER
if (isVertexShader) {
_vertGlslShader = stage.source;
_vertMtlShader = mtlShader;
_vertMtlShader = mtlShader;
} else if (isFragmenShader) {
_fragGlslShader = stage.source;
_fragMtlShader = mtlShader;
_fragMtlShader = mtlShader;
} else if (isComputeShader) {
_cmptGlslShader = stage.source;
_cmptMtlShader = mtlShader;
_cmptMtlShader = mtlShader;
}
#endif
return true;
@@ -164,10 +164,10 @@ uint CCMTLShader::getAvailableBufferBindingIndex(ShaderStageFlagBit stage, uint
}
void CCMTLShader::setAvailableBufferBindingIndex() {
uint usedVertexBufferBindingIndexes = 0;
uint usedVertexBufferBindingIndexes = 0;
uint usedFragmentBufferBindingIndexes = 0;
uint vertexBindingCount = 0;
uint fragmentBindingCount = 0;
uint vertexBindingCount = 0;
uint fragmentBindingCount = 0;
for (const auto &block : _gpuShader->blocks) {
if (block.second.stages & ShaderStageFlagBit::VERTEX) {
vertexBindingCount++;
@@ -182,9 +182,9 @@ void CCMTLShader::setAvailableBufferBindingIndex() {
auto maxBufferBindingIndex = CCMTLDevice::getInstance()->getMaximumBufferBindingIndex();
_availableVertexBufferBindingIndex.resize(maxBufferBindingIndex - vertexBindingCount);
_availableFragmentBufferBindingIndex.resize(maxBufferBindingIndex - fragmentBindingCount);
uint availableVertexBufferBit = ~usedVertexBufferBindingIndexes;
uint availableVertexBufferBit = ~usedVertexBufferBindingIndexes;
uint availableFragmentBufferBit = ~usedFragmentBufferBindingIndexes;
int theBit = maxBufferBindingIndex - 1;
int theBit = maxBufferBindingIndex - 1;
uint i = 0, j = 0;
for (; theBit >= 0; theBit--) {
if ((availableVertexBufferBit & (1 << theBit))) {
@@ -60,6 +60,11 @@ function install_python_win32()
export PATH="/c/Python27":$PATH
}
function install_vulkan_sdk_win32()
{
choco install vulkan-sdk
}
function install_python_module()
{
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
@@ -68,6 +73,7 @@ function install_python_module()
pip install Cheetah
elif [ "$TRAVIS_OS_NAME" == "windows" ]; then
install_python_win32
install_vulkan_sdk_win32
python -m easy_install pip
python -m pip install PyYAML
python -m pip install Cheetah
+2 -1
View File
@@ -147,8 +147,9 @@ echo " finish push ..."
# set +x
# 7.
ENCODED_MESSAGE=$(python -c "import urllib; print urllib.quote('''$TRAVIS_COMMIT_MESSAGE''')")
echo "Sending Pull Request to base repo ..."
curl -H "Authorization: token $GH_TOKEN" --request POST --data "{ \"title\": \"$COMMITTAG\", \"body\": \"> $TRAVIS_COMMIT_MESSAGE\", \"head\": \"${GH_USER}:${COCOS_BRANCH}\", \"base\": \"${TRAVIS_BRANCH}\"}" "${PULL_REQUEST_REPO}" # 2> /dev/null > /dev/null
curl -H "Authorization: token $GH_TOKEN" --request POST --data "{ \"title\": \"$COMMITTAG\", \"body\": \"> $ENCODED_MESSAGE\", \"head\": \"${GH_USER}:${COCOS_BRANCH}\", \"base\": \"${TRAVIS_BRANCH}\"}" "${PULL_REQUEST_REPO}" # 2> /dev/null > /dev/null
echo " finish sending PR ..."
+23 -5
View File
@@ -65,6 +65,11 @@ function build_android()
cd $COCOS2DX_ROOT/templates/android/build
mkdir -p build-android/proj
touch build-android/proj/cfg.cmake
echo "set(CC_USE_GLES3 ON)" >> build-android/proj/cfg.cmake
echo "set(CC_USE_VULKAN ON)" >> build-android/proj/cfg.cmake
echo "set(CC_USE_GLES2 ON)" >> build-android/proj/cfg.cmake
echo "set(USE_WEBSOCKET_SERVER ON)" >> build-android/proj/cfg.cmake
mkdir -p build-android/assets
ASSET_DIR=$COCOS2DX_ROOT/templates/android/build/build-android/
@@ -76,6 +81,7 @@ function build_android()
sed -i "s@^APPLICATION_ID.*@APPLICATION_ID=com.cocos.android@g" gradle.properties
sed -i "s@^RES_PATH.*@RES_PATH=$ASSET_DIR@g" gradle.properties
sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$COCOS2DX_ROOT@g" gradle.properties
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties
#echo "Compile Android - ndk-build ..."
#./gradlew assembleDebug --quiet
@@ -123,17 +129,21 @@ function build_macosx()
cd $COCOS2DX_ROOT/templates/mac
mkdir -p build-mac/proj
touch build-mac/proj/cfg.cmake
echo "set(CC_USE_VULKAN OFF)" >> build-mac/proj/cfg.cmake
echo "set(CC_USE_GLES2 OFF)" >> build-mac/proj/cfg.cmake
echo "set(CC_USE_METAL ON)" >> build-mac/proj/cfg.cmake
echo "set(USE_WEBSOCKET_SERVER OFF)" >> build-mac/proj/cfg.cmake
mkdir build-mac/assets
RES_DIR=$COCOS2DX_ROOT/templates/mac/build-mac
cd build-mac
cmake ../ -GXcode -DCC_USE_METAL=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
cmake ../ -GXcode -DCC_USE_GLES3=ON -DCMAKE_OSX_ARCHITECTURES=x86_64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch x86_64
echo "Compile MacOSX X86_64 Release Done!"
cd ..
mkdir build-mac-apple-silicon
cd build-mac-apple-silicon
cmake ../ -GXcode -DCC_USE_METAL=ON -DCC_USE_GLES3=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
cmake ../ -GXcode -DCC_USE_GLES3=OFF -DCMAKE_OSX_ARCHITECTURES=arm64 -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -arch arm64
echo "Compile MacOSX ARM64 Release Done!"
}
@@ -146,13 +156,17 @@ function build_ios()
cd $COCOS2DX_ROOT/templates/ios
mkdir -p build-ios/proj
touch build-ios/proj/cfg.cmake
echo "set(CC_USE_GLES3 OFF)" >> build-ios/proj/cfg.cmake
echo "set(CC_USE_VULKAN OFF)" >> build-ios/proj/cfg.cmake
echo "set(CC_USE_GLES2 OFF)" >> build-ios/proj/cfg.cmake
echo "set(CC_USE_METAL ON)" >> build-ios/proj/cfg.cmake
echo "set(USE_WEBSOCKET_SERVER OFF)" >> build-ios/proj/cfg.cmake
mkdir build-ios/assets
cd build-ios
RES_DIR=$COCOS2DX_ROOT/templates/ios/build-ios
cmake ../ -GXcode -DCMAKE_SYSTEM_NAME=iOS \
-DCMAKE_OSX_SYSROOT=iphonesimulator \
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
-DCC_USE_METAL=ON \
-DRES_DIR=$RES_DIR \
-DCOCOS_X_PATH=$COCOS2DX_ROOT
cmake --build . --config Debug -- -quiet -jobs $NUM_OF_CORES -allowProvisioningUpdates
@@ -165,14 +179,18 @@ function build_windows()
cd $COCOS2DX_ROOT/templates/win32
mkdir -p build-win32/proj
touch build-win32/proj/cfg.cmake
echo "set(CC_USE_GLES3 ON)" >> build-win32/proj/cfg.cmake
echo "set(CC_USE_VULKAN ON)" >> build-win32/proj/cfg.cmake
echo "set(CC_USE_GLES2 ON)" >> build-win32/proj/cfg.cmake
echo "set(USE_WEBSOCKET_SERVER ON)" >> build-win32/proj/cfg.cmake
mkdir build-win32/assets
cd build-win32
RES_DIR=$COCOS2DX_ROOT/templates/win32/build-win32
cmake ../ -G"Visual Studio 15 2017" -DRES_DIR=$RES_DIR -DCOCOS_X_PATH=$COCOS2DX_ROOT
cmake --build . --config Debug
echo "Compile Win32 Debug Done!"
cmake --build . --config Release
echo "Compile Win32 Debug Done!"
# cmake --build . --config Release
# echo "Compile Win32 Debug Done!"
}