mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Change the sync of native pass to message queue. (#3785)
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
#define JSB_FREE(ptr) delete ptr
|
||||
#endif
|
||||
|
||||
extern bool register_all_drawbatch2d_ext_manual(se::Object* obj); //NOLINT
|
||||
extern bool register_all_scene_ext_manual(se::Object* obj); //NOLINT
|
||||
|
||||
static bool js_scene_Pass_setRootBufferAndBlock(se::State& s) // NOLINT(readability-identifier-naming)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ bool register_all_scene_manual(se::Object* obj) // NOLINT(readability-identifier
|
||||
__jsb_cc_scene_RenderScene_proto->defineFunction("updateBatches", _SE(js_scene_RenderScene_updateBatches));
|
||||
|
||||
// Impl MQ for DrawBatch2D
|
||||
register_all_drawbatch2d_ext_manual(obj);
|
||||
register_all_scene_ext_manual(obj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,43 @@ void fastSetShaders(void *buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
// for pass message
|
||||
void fastSetPassBlendState(void *buffer) {
|
||||
struct Heap {
|
||||
AlignedPtr<cc::scene::Pass> selfPtr;
|
||||
AlignedPtr<cc::gfx::BlendState> bsPtr;
|
||||
};
|
||||
Heap *heap = reinterpret_cast<Heap *>(buffer);
|
||||
heap->selfPtr.get()->setBlendState(heap->bsPtr.get());
|
||||
}
|
||||
|
||||
void fastSetPassDepthStencilState(void *buffer) {
|
||||
struct Heap {
|
||||
AlignedPtr<cc::scene::Pass> selfPtr;
|
||||
AlignedPtr<cc::gfx::DepthStencilState> dsPtr;
|
||||
};
|
||||
Heap *heap = reinterpret_cast<Heap *>(buffer);
|
||||
heap->selfPtr.get()->setDepthStencilState(heap->dsPtr.get());
|
||||
}
|
||||
|
||||
void fastSetPassRasterizerState(void *buffer) {
|
||||
struct Heap {
|
||||
AlignedPtr<cc::scene::Pass> selfPtr;
|
||||
AlignedPtr<cc::gfx::RasterizerState> rsPtr;
|
||||
};
|
||||
Heap *heap = reinterpret_cast<Heap *>(buffer);
|
||||
heap->selfPtr.get()->setRasterizerState(heap->rsPtr.get());
|
||||
}
|
||||
|
||||
void fastSetPassDescriptorSet(void *buffer) {
|
||||
struct Heap {
|
||||
AlignedPtr<cc::scene::Pass> selfPtr;
|
||||
AlignedPtr<cc::gfx::DescriptorSet> dsPtr;
|
||||
};
|
||||
Heap *heap = reinterpret_cast<Heap *>(buffer);
|
||||
heap->selfPtr.get()->setDescriptorSet(heap->dsPtr.get());
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
uint64_t convertPtr(F *in) {
|
||||
return static_cast<uint64_t>(reinterpret_cast<intptr_t>(in));
|
||||
@@ -137,7 +174,34 @@ void jsbFlushFastMQ() {
|
||||
msgInfoPtr[1] = 0;
|
||||
}
|
||||
|
||||
bool register_all_drawbatch2d_ext_manual(se::Object *obj) { //NOLINT
|
||||
void registerDrawBatch2DFunction(se::Object *cls) {
|
||||
// register function table of DrawBatch2D
|
||||
se::Value jsValue;
|
||||
cls->getProperty("DrawBatch2D", &jsValue);
|
||||
se::Object *jsObj = jsValue.toObject();
|
||||
se::Object *fnTable = se::Object::createPlainObject();
|
||||
fnTable->setProperty("visFlags", se::Value(convertPtr(fastSetFlag)));
|
||||
fnTable->setProperty("descriptorSet", se::Value(convertPtr(fastSetDescriptorSet)));
|
||||
fnTable->setProperty("inputAssembler", se::Value(convertPtr(fastSetInputAssembler)));
|
||||
fnTable->setProperty("passes", se::Value(convertPtr(fastSetPasses)));
|
||||
fnTable->setProperty("shaders", se::Value(convertPtr(fastSetShaders)));
|
||||
jsObj->setProperty("fnTable", se::Value(fnTable));
|
||||
}
|
||||
|
||||
void registerPassFunction(se::Object *cls) {
|
||||
// register function table of DrawBatch2D
|
||||
se::Value jsValue;
|
||||
cls->getProperty("Pass", &jsValue);
|
||||
se::Object *jsObj = jsValue.toObject();
|
||||
se::Object *fnTable = se::Object::createPlainObject();
|
||||
fnTable->setProperty("blendState", se::Value(convertPtr(fastSetPassBlendState)));
|
||||
fnTable->setProperty("depthStencilState", se::Value(convertPtr(fastSetPassDepthStencilState)));
|
||||
fnTable->setProperty("rasterizerState", se::Value(convertPtr(fastSetPassRasterizerState)));
|
||||
fnTable->setProperty("descriptorSet", se::Value(convertPtr(fastSetPassDescriptorSet)));
|
||||
jsObj->setProperty("fnTable", se::Value(fnTable));
|
||||
}
|
||||
|
||||
bool register_all_scene_ext_manual(se::Object *obj) { //NOLINT
|
||||
// allocate global message queue
|
||||
|
||||
se::AutoHandleScope scope;
|
||||
@@ -164,23 +228,14 @@ bool register_all_drawbatch2d_ext_manual(se::Object *obj) { //NOLINT
|
||||
mqInitialized = true;
|
||||
|
||||
// register function table, serialize to queue
|
||||
|
||||
se::Value dbJSValue;
|
||||
se::Object *nsObj{nullptr};
|
||||
|
||||
se::Value nsValue;
|
||||
obj->getProperty("ns", &nsValue);
|
||||
nsObj = nsValue.toObject();
|
||||
|
||||
nsObj->getProperty("DrawBatch2D", &dbJSValue);
|
||||
se::Object *dbJSObj = dbJSValue.toObject();
|
||||
se::Object *fnTable = se::Object::createPlainObject();
|
||||
fnTable->setProperty("visFlags", se::Value(convertPtr(fastSetFlag)));
|
||||
fnTable->setProperty("descriptorSet", se::Value(convertPtr(fastSetDescriptorSet)));
|
||||
fnTable->setProperty("inputAssembler", se::Value(convertPtr(fastSetInputAssembler)));
|
||||
fnTable->setProperty("passes", se::Value(convertPtr(fastSetPasses)));
|
||||
fnTable->setProperty("shaders", se::Value(convertPtr(fastSetShaders)));
|
||||
dbJSObj->setProperty("fnTable", se::Value(fnTable));
|
||||
registerDrawBatch2DFunction(nsObj);
|
||||
registerPassFunction(nsObj);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,13 @@
|
||||
|
||||
#include "scene/Pass.h"
|
||||
|
||||
extern void jsbFlushFastMQ();
|
||||
|
||||
namespace cc {
|
||||
namespace scene {
|
||||
|
||||
void Pass::update() {
|
||||
jsbFlushFastMQ();
|
||||
if (_rootBufferDirty && _rootBuffer) {
|
||||
_rootBuffer->update(_rootBlock, _rootBuffer->getSize());
|
||||
_rootBufferDirty = false;
|
||||
@@ -40,12 +43,5 @@ void Pass::initWithData(uint8_t *data) {
|
||||
_passLayout = reinterpret_cast<PassLayout *>(data);
|
||||
}
|
||||
|
||||
void Pass::setState(gfx::BlendState *bs, gfx::DepthStencilState *ds, gfx::RasterizerState *rs, gfx::DescriptorSet *descriptorSet) {
|
||||
_blendState = bs;
|
||||
_depthStencilState = ds;
|
||||
_rasterizerState = rs;
|
||||
_descriptorSet = descriptorSet;
|
||||
}
|
||||
|
||||
} // namespace scene
|
||||
} // namespace cc
|
||||
|
||||
@@ -57,7 +57,6 @@ public:
|
||||
|
||||
void initWithData(uint8_t *data);
|
||||
void update();
|
||||
void setState(gfx::BlendState *bs, gfx::DepthStencilState *ds, gfx::RasterizerState *rs, gfx::DescriptorSet *descriptorSet);
|
||||
|
||||
inline void setBatchingScheme(BatchingSchemes value) { _passLayout->batchingScheme = value; }
|
||||
inline void setBlendState(gfx::BlendState *blendState) { _blendState = blendState; }
|
||||
@@ -99,7 +98,7 @@ private:
|
||||
gfx::DescriptorSet * _descriptorSet{nullptr};
|
||||
gfx::PipelineLayout * _pipelineLayout{nullptr};
|
||||
gfx::Buffer * _rootBuffer{nullptr};
|
||||
uint8_t * _rootBlock{nullptr};
|
||||
uint8_t * _rootBlock{nullptr};
|
||||
};
|
||||
|
||||
} // namespace scene
|
||||
|
||||
Reference in New Issue
Block a user