mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
array pool refactor (#2883)
* fix draw call issueing * vk: descriptor set: default sampler only * array pool refactor * skip backupBuffer & device bindings * MRT feature flag * skip getDevice
This commit is contained in:
@@ -781,8 +781,8 @@ cocos_source_files(
|
||||
cocos/bindings/dop/jsb_dop.cpp
|
||||
cocos/bindings/dop/jsb_dop.h
|
||||
cocos/bindings/dop/PoolType.h
|
||||
cocos/bindings/dop/ArrayPool.h
|
||||
cocos/bindings/dop/ArrayPool.cpp
|
||||
cocos/bindings/dop/BufferAllocator.h
|
||||
cocos/bindings/dop/BufferAllocator.cpp
|
||||
)
|
||||
|
||||
######## auto
|
||||
|
||||
@@ -14194,24 +14194,6 @@ static bool js_gfx_Buffer_getMemUsage(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Buffer_getMemUsage)
|
||||
|
||||
static bool js_gfx_Buffer_getBackupBuffer(se::State& s)
|
||||
{
|
||||
cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject();
|
||||
SE_PRECONDITION2(cobj, false, "js_gfx_Buffer_getBackupBuffer : Invalid Native Object");
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc == 0) {
|
||||
unsigned char* result = cobj->getBackupBuffer();
|
||||
#pragma warning NO CONVERSION FROM NATIVE FOR unsigned char*;
|
||||
SE_PRECONDITION2(ok, false, "js_gfx_Buffer_getBackupBuffer : Error processing arguments");
|
||||
return true;
|
||||
}
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Buffer_getBackupBuffer)
|
||||
|
||||
static bool js_gfx_Buffer_getSize(se::State& s)
|
||||
{
|
||||
cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject();
|
||||
@@ -14297,7 +14279,7 @@ static bool js_gfx_Buffer_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Buffer_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_Buffer_getDevice)
|
||||
|
||||
static bool js_gfx_Buffer_getFlags(se::State& s)
|
||||
{
|
||||
@@ -14370,12 +14352,11 @@ bool js_register_gfx_Buffer(se::Object* obj)
|
||||
cls->defineProperty("count", _SE(js_gfx_Buffer_getCount), nullptr);
|
||||
cls->defineProperty("memUsage", _SE(js_gfx_Buffer_getMemUsage), nullptr);
|
||||
cls->defineProperty("stride", _SE(js_gfx_Buffer_getStride), nullptr);
|
||||
cls->defineProperty("usage", _SE(js_gfx_Buffer_getUsage), nullptr);
|
||||
cls->defineProperty("flags", _SE(js_gfx_Buffer_getFlags), nullptr);
|
||||
cls->defineProperty("device", _SE(js_gfx_Buffer_getDevice), nullptr);
|
||||
cls->defineProperty("backupBuffer", _SE(js_gfx_Buffer_getBackupBuffer), nullptr);
|
||||
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("getDevice", _SE(js_gfx_Buffer_getDevice));
|
||||
cls->defineFunction("resize", _SE(js_gfx_Buffer_resize));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_Buffer_finalize));
|
||||
cls->install();
|
||||
@@ -14953,7 +14934,7 @@ static bool js_gfx_Sampler_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Sampler_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_Sampler_getDevice)
|
||||
|
||||
static bool js_gfx_Sampler_getMinLOD(se::State& s)
|
||||
{
|
||||
@@ -15052,10 +15033,10 @@ bool js_register_gfx_Sampler(se::Object* obj)
|
||||
cls->defineProperty("cmpFunc", _SE(js_gfx_Sampler_getCmpFunc), nullptr);
|
||||
cls->defineProperty("maxAnisotropy", _SE(js_gfx_Sampler_getMaxAnisotropy), nullptr);
|
||||
cls->defineProperty("mipLODBias", _SE(js_gfx_Sampler_getMipLODBias), nullptr);
|
||||
cls->defineProperty("device", _SE(js_gfx_Sampler_getDevice), nullptr);
|
||||
cls->defineProperty("minLOD", _SE(js_gfx_Sampler_getMinLOD), nullptr);
|
||||
cls->defineFunction("initialize", _SE(js_gfx_Sampler_initialize));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_Sampler_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_Sampler_getDevice));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_Sampler_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cc::gfx::Sampler>(cls);
|
||||
@@ -15212,7 +15193,7 @@ static bool js_gfx_Shader_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Shader_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_Shader_getDevice)
|
||||
|
||||
static bool js_gfx_Shader_getBlocks(se::State& s)
|
||||
{
|
||||
@@ -15267,11 +15248,11 @@ bool js_register_gfx_Shader(se::Object* obj)
|
||||
cls->defineProperty("name", _SE(js_gfx_Shader_getName), nullptr);
|
||||
cls->defineProperty("samplers", _SE(js_gfx_Shader_getSamplers), nullptr);
|
||||
cls->defineProperty("shaderID", _SE(js_gfx_Shader_getID), nullptr);
|
||||
cls->defineProperty("device", _SE(js_gfx_Shader_getDevice), nullptr);
|
||||
cls->defineProperty("attributes", _SE(js_gfx_Shader_getAttributes), nullptr);
|
||||
cls->defineProperty("stages", _SE(js_gfx_Shader_getStages), nullptr);
|
||||
cls->defineFunction("initialize", _SE(js_gfx_Shader_initialize));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_Shader_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_Shader_getDevice));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_Shader_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cc::gfx::Shader>(cls);
|
||||
@@ -15427,7 +15408,7 @@ static bool js_gfx_InputAssembler_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_InputAssembler_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_InputAssembler_getDevice)
|
||||
|
||||
static bool js_gfx_InputAssembler_setVertexOffset(se::State& s)
|
||||
{
|
||||
@@ -15724,16 +15705,16 @@ bool js_register_gfx_InputAssembler(se::Object* obj)
|
||||
cls->defineProperty("vertexBuffers", _SE(js_gfx_InputAssembler_getVertexBuffers), nullptr);
|
||||
cls->defineProperty("attributesHash", _SE(js_gfx_InputAssembler_getAttributesHash), nullptr);
|
||||
cls->defineProperty("firstInstance", _SE(js_gfx_InputAssembler_getFirstInstance), _SE(js_gfx_InputAssembler_setFirstInstance));
|
||||
cls->defineProperty("vertexOffset", _SE(js_gfx_InputAssembler_getVertexOffset), _SE(js_gfx_InputAssembler_setVertexOffset));
|
||||
cls->defineProperty("vertexCount", _SE(js_gfx_InputAssembler_getVertexCount), _SE(js_gfx_InputAssembler_setVertexCount));
|
||||
cls->defineProperty("indexBuffer", _SE(js_gfx_InputAssembler_getIndexBuffer), nullptr);
|
||||
cls->defineProperty("device", _SE(js_gfx_InputAssembler_getDevice), nullptr);
|
||||
cls->defineProperty("vertexOffset", _SE(js_gfx_InputAssembler_getVertexOffset), _SE(js_gfx_InputAssembler_setVertexOffset));
|
||||
cls->defineProperty("attributes", _SE(js_gfx_InputAssembler_getAttributes), nullptr);
|
||||
cls->defineProperty("indexCount", _SE(js_gfx_InputAssembler_getIndexCount), _SE(js_gfx_InputAssembler_setIndexCount));
|
||||
cls->defineProperty("firstIndex", _SE(js_gfx_InputAssembler_getFirstIndex), _SE(js_gfx_InputAssembler_setFirstIndex));
|
||||
cls->defineProperty("indirectBuffer", _SE(js_gfx_InputAssembler_getIndirectBuffer), nullptr);
|
||||
cls->defineProperty("firstVertex", _SE(js_gfx_InputAssembler_getFirstVertex), _SE(js_gfx_InputAssembler_setFirstVertex));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_InputAssembler_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_InputAssembler_getDevice));
|
||||
cls->defineFunction("initialize", _SE(js_gfx_InputAssembler_initialize));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_InputAssembler_finalize));
|
||||
cls->install();
|
||||
@@ -15855,7 +15836,7 @@ static bool js_gfx_RenderPass_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_RenderPass_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_RenderPass_getDevice)
|
||||
|
||||
static bool js_gfx_RenderPass_getDepthStencilAttachment(se::State& s)
|
||||
{
|
||||
@@ -15906,13 +15887,13 @@ bool js_register_gfx_RenderPass(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("RenderPass", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_RenderPass_constructor));
|
||||
|
||||
cls->defineProperty("device", _SE(js_gfx_RenderPass_getDevice), nullptr);
|
||||
cls->defineProperty("subPasses", _SE(js_gfx_RenderPass_getSubPasses), nullptr);
|
||||
cls->defineProperty("colorAttachments", _SE(js_gfx_RenderPass_getColorAttachments), nullptr);
|
||||
cls->defineProperty("depthStencilAttachment", _SE(js_gfx_RenderPass_getDepthStencilAttachment), nullptr);
|
||||
cls->defineProperty("hash", _SE(js_gfx_RenderPass_getHash), nullptr);
|
||||
cls->defineProperty("subPasses", _SE(js_gfx_RenderPass_getSubPasses), nullptr);
|
||||
cls->defineFunction("initialize", _SE(js_gfx_RenderPass_initialize));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_RenderPass_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_RenderPass_getDevice));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_RenderPass_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cc::gfx::RenderPass>(cls);
|
||||
@@ -16033,7 +16014,7 @@ static bool js_gfx_Framebuffer_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Framebuffer_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_Framebuffer_getDevice)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_Framebuffer_finalize)
|
||||
|
||||
@@ -16066,12 +16047,12 @@ bool js_register_gfx_Framebuffer(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("Framebuffer", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_Framebuffer_constructor));
|
||||
|
||||
cls->defineProperty("device", _SE(js_gfx_Framebuffer_getDevice), nullptr);
|
||||
cls->defineProperty("renderPass", _SE(js_gfx_Framebuffer_getRenderPass), nullptr);
|
||||
cls->defineProperty("colorTextures", _SE(js_gfx_Framebuffer_getColorTextures), nullptr);
|
||||
cls->defineProperty("renderPass", _SE(js_gfx_Framebuffer_getRenderPass), nullptr);
|
||||
cls->defineProperty("depthStencilTexture", _SE(js_gfx_Framebuffer_getDepthStencilTexture), nullptr);
|
||||
cls->defineFunction("initialize", _SE(js_gfx_Framebuffer_initialize));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_Framebuffer_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_Framebuffer_getDevice));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_Framebuffer_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cc::gfx::Framebuffer>(cls);
|
||||
@@ -16543,7 +16524,7 @@ static bool js_gfx_PipelineState_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_PipelineState_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_PipelineState_getDevice)
|
||||
|
||||
static bool js_gfx_PipelineState_getDynamicStates(se::State& s)
|
||||
{
|
||||
@@ -16599,12 +16580,12 @@ bool js_register_gfx_PipelineState(se::Object* obj)
|
||||
cls->defineProperty("shader", _SE(js_gfx_PipelineState_getShader), nullptr);
|
||||
cls->defineProperty("blendState", _SE(js_gfx_PipelineState_getBlendState), nullptr);
|
||||
cls->defineProperty("renderPass", _SE(js_gfx_PipelineState_getRenderPass), nullptr);
|
||||
cls->defineProperty("device", _SE(js_gfx_PipelineState_getDevice), nullptr);
|
||||
cls->defineProperty("inputState", _SE(js_gfx_PipelineState_getInputState), nullptr);
|
||||
cls->defineProperty("depthStencilState", _SE(js_gfx_PipelineState_getDepthStencilState), nullptr);
|
||||
cls->defineFunction("getPipelineLayout", _SE(js_gfx_PipelineState_getPipelineLayout));
|
||||
cls->defineFunction("initialize", _SE(js_gfx_PipelineState_initialize));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_PipelineState_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_PipelineState_getDevice));
|
||||
cls->defineFunction("getDynamicStates", _SE(js_gfx_PipelineState_getDynamicStates));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_PipelineState_finalize));
|
||||
cls->install();
|
||||
@@ -17883,7 +17864,7 @@ static bool js_gfx_Queue_getDevice(se::State& s)
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_gfx_Queue_getDevice)
|
||||
SE_BIND_FUNC(js_gfx_Queue_getDevice)
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_Queue_finalize)
|
||||
|
||||
@@ -17916,12 +17897,12 @@ bool js_register_gfx_Queue(se::Object* obj)
|
||||
{
|
||||
auto cls = se::Class::create("Queue", obj, __jsb_cc_gfx_GFXObject_proto, _SE(js_gfx_Queue_constructor));
|
||||
|
||||
cls->defineProperty("device", _SE(js_gfx_Queue_getDevice), nullptr);
|
||||
cls->defineProperty("type", _SE(js_gfx_Queue_getType), nullptr);
|
||||
cls->defineFunction("submit", _SE(js_gfx_Queue_submit));
|
||||
cls->defineFunction("isAsync", _SE(js_gfx_Queue_isAsync));
|
||||
cls->defineFunction("initialize", _SE(js_gfx_Queue_initialize));
|
||||
cls->defineFunction("destroy", _SE(js_gfx_Queue_destroy));
|
||||
cls->defineFunction("getDevice", _SE(js_gfx_Queue_getDevice));
|
||||
cls->defineFinalizeFunction(_SE(js_cc_gfx_Queue_finalize));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<cc::gfx::Queue>(cls);
|
||||
|
||||
@@ -301,6 +301,7 @@ extern se::Class* __jsb_cc_gfx_Buffer_class;
|
||||
bool js_register_cc_gfx_Buffer(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Buffer_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_Buffer_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_Buffer_resize);
|
||||
SE_DECLARE_FUNC(js_gfx_Buffer_Buffer);
|
||||
|
||||
@@ -321,6 +322,7 @@ bool js_register_cc_gfx_Sampler(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Sampler_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_Sampler_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_Sampler_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_Sampler_Sampler);
|
||||
|
||||
extern se::Object* __jsb_cc_gfx_Shader_proto;
|
||||
@@ -330,6 +332,7 @@ bool js_register_cc_gfx_Shader(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Shader_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_Shader_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_Shader_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_Shader_Shader);
|
||||
|
||||
extern se::Object* __jsb_cc_gfx_InputAssembler_proto;
|
||||
@@ -338,6 +341,7 @@ extern se::Class* __jsb_cc_gfx_InputAssembler_class;
|
||||
bool js_register_cc_gfx_InputAssembler(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_InputAssembler_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_InputAssembler_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_InputAssembler_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_InputAssembler_InputAssembler);
|
||||
|
||||
@@ -348,6 +352,7 @@ bool js_register_cc_gfx_RenderPass(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderPass_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderPass_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderPass_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_RenderPass_RenderPass);
|
||||
|
||||
extern se::Object* __jsb_cc_gfx_Framebuffer_proto;
|
||||
@@ -357,6 +362,7 @@ bool js_register_cc_gfx_Framebuffer(se::Object* obj);
|
||||
bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_Framebuffer_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_Framebuffer_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_Framebuffer_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_Framebuffer_Framebuffer);
|
||||
|
||||
extern se::Object* __jsb_cc_gfx_DescriptorSetLayout_proto;
|
||||
@@ -387,6 +393,7 @@ bool register_all_gfx(se::Object* obj);
|
||||
SE_DECLARE_FUNC(js_gfx_PipelineState_getPipelineLayout);
|
||||
SE_DECLARE_FUNC(js_gfx_PipelineState_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_PipelineState_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_PipelineState_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_PipelineState_getDynamicStates);
|
||||
SE_DECLARE_FUNC(js_gfx_PipelineState_PipelineState);
|
||||
|
||||
@@ -458,5 +465,6 @@ SE_DECLARE_FUNC(js_gfx_Queue_submit);
|
||||
SE_DECLARE_FUNC(js_gfx_Queue_isAsync);
|
||||
SE_DECLARE_FUNC(js_gfx_Queue_initialize);
|
||||
SE_DECLARE_FUNC(js_gfx_Queue_destroy);
|
||||
SE_DECLARE_FUNC(js_gfx_Queue_getDevice);
|
||||
SE_DECLARE_FUNC(js_gfx_Queue_Queue);
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
#include "ArrayPool.h"
|
||||
#include "base/memory/Memory.h"
|
||||
#include "base/Log.h"
|
||||
|
||||
// Data type of array element is uint32_t
|
||||
#define BYTES_PER_ELEMENT 4
|
||||
|
||||
namespace se {
|
||||
|
||||
cc::map<PoolType, ArrayPool *> ArrayPool::_pools;
|
||||
|
||||
ArrayPool::ArrayPool(PoolType type, uint size)
|
||||
: _type(type), _size(size) {
|
||||
ArrayPool::_pools[_type] = this;
|
||||
}
|
||||
|
||||
ArrayPool::~ArrayPool() {
|
||||
ArrayPool::_pools.erase(_type);
|
||||
}
|
||||
|
||||
Object *ArrayPool::alloc(uint index) {
|
||||
uint bytes = _size * BYTES_PER_ELEMENT;
|
||||
auto obj = Object::createTypedArray(Object::TypedArrayType::UINT32, nullptr, bytes);
|
||||
obj->incRef();
|
||||
_objects[index] = obj;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object *ArrayPool::resize(Object *origin, uint size, uint index) {
|
||||
uint bytes = size * BYTES_PER_ELEMENT;
|
||||
uint8_t *buffer = static_cast<uint8_t *>(CC_MALLOC(bytes));
|
||||
if (!buffer) {
|
||||
CC_LOG_ERROR("Can not resize array.");
|
||||
return origin;
|
||||
}
|
||||
memset(buffer, 0, bytes);
|
||||
|
||||
uint8_t *originData = nullptr;
|
||||
size_t len = 0;
|
||||
origin->getTypedArrayData(&originData, &len);
|
||||
memcpy(buffer, originData, len);
|
||||
|
||||
auto obj = Object::createTypedArray(Object::TypedArrayType::UINT32, buffer, bytes);
|
||||
CC_FREE(buffer);
|
||||
|
||||
CC_ASSERT(_objects.count(index) != 0);
|
||||
_objects[index] = obj;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
uint32_t *ArrayPool::getArray(PoolType type, uint index) {
|
||||
index &= ~(1 << 30);
|
||||
if (ArrayPool::_pools.count(type) != 0) {
|
||||
const auto pool = ArrayPool::_pools[type];
|
||||
if (pool->_objects.count(index) != 0) {
|
||||
uint8_t *ret = nullptr;
|
||||
size_t len = 0;
|
||||
pool->_objects[index]->getTypedArrayData(&ret, &len);
|
||||
return reinterpret_cast<uint32_t *>(ret);
|
||||
}
|
||||
else {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace se
|
||||
@@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "cocos/base/Object.h"
|
||||
#include "cocos/bindings/jswrapper/Object.h"
|
||||
#include "cocos/base/memory/StlAlloc.h"
|
||||
#include "cocos/base/Macros.h"
|
||||
#include "cocos/base/TypeDef.h"
|
||||
#include "PoolType.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class CC_DLL ArrayPool final : public cc::Object {
|
||||
public:
|
||||
static uint32_t *getArray(PoolType type, uint index);
|
||||
|
||||
ArrayPool(PoolType type, uint size);
|
||||
~ArrayPool();
|
||||
|
||||
Object *alloc(uint index);
|
||||
Object *resize(Object *origin, uint size, uint index);
|
||||
|
||||
private:
|
||||
static cc::map<PoolType, ArrayPool *> _pools;
|
||||
|
||||
cc::map<uint, Object *> _objects;
|
||||
PoolType _type;
|
||||
uint _size = 0;
|
||||
};
|
||||
|
||||
} // namespace se
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "BufferAllocator.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/memory/Memory.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
cc::map<PoolType, BufferAllocator *> BufferAllocator::_pools;
|
||||
|
||||
BufferAllocator::BufferAllocator(PoolType type)
|
||||
: _type(type) {
|
||||
BufferAllocator::_pools[_type] = this;
|
||||
}
|
||||
|
||||
BufferAllocator::~BufferAllocator() {
|
||||
for (auto buffer : _buffers) {
|
||||
buffer.second->decRef();
|
||||
}
|
||||
_buffers.clear();
|
||||
BufferAllocator::_pools.erase(_type);
|
||||
}
|
||||
|
||||
Object *BufferAllocator::alloc(uint index, uint bytes) {
|
||||
if (_buffers.count(index)) {
|
||||
Object *oldObj = _buffers[index];
|
||||
oldObj->decRef();
|
||||
}
|
||||
Object *obj = Object::createArrayBufferObject(nullptr, bytes);
|
||||
obj->incRef();
|
||||
_buffers[index] = obj;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void BufferAllocator::free(uint index) {
|
||||
if (_buffers.count(index)) {
|
||||
Object *oldObj = _buffers[index];
|
||||
oldObj->decRef();
|
||||
_buffers.erase(index);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace se
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "cocos/base/Object.h"
|
||||
#include "cocos/bindings/jswrapper/Object.h"
|
||||
#include "cocos/base/memory/StlAlloc.h"
|
||||
#include "cocos/base/Macros.h"
|
||||
#include "cocos/base/TypeDef.h"
|
||||
#include "PoolType.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class CC_DLL BufferAllocator final : public cc::Object {
|
||||
public:
|
||||
template <class T>
|
||||
static T *getBuffer(PoolType type, uint index) {
|
||||
index &= ~(1 << 30);
|
||||
if (BufferAllocator::_pools.count(type) != 0) {
|
||||
const auto pool = BufferAllocator::_pools[type];
|
||||
if (pool->_buffers.count(index) != 0) {
|
||||
T *ret = nullptr;
|
||||
size_t len = 0;
|
||||
pool->_buffers[index]->getArrayBufferData((uint8_t **)&ret, &len);
|
||||
return ret;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
BufferAllocator(PoolType type);
|
||||
~BufferAllocator();
|
||||
|
||||
Object *alloc(uint index, uint bytes);
|
||||
void free(uint index);
|
||||
|
||||
private:
|
||||
static cc::map<PoolType, BufferAllocator *> _pools;
|
||||
|
||||
cc::map<uint, Object *> _buffers;
|
||||
PoolType _type = PoolType::UNKNOWN;
|
||||
};
|
||||
|
||||
} // namespace se
|
||||
@@ -31,7 +31,7 @@ using namespace se;
|
||||
cc::map<PoolType, BufferPool *> BufferPool::_poolMap;
|
||||
|
||||
BufferPool::BufferPool(PoolType type, uint entryBits, uint bytesPerEntry)
|
||||
: _entryBits(entryBits), _bytesPerEntry(bytesPerEntry), _type(type) {
|
||||
: _allocator(type), _entryBits(entryBits), _bytesPerEntry(bytesPerEntry), _type(type) {
|
||||
CCASSERT(BufferPool::_poolMap.count(type) == 0, "The type of pool is already exist");
|
||||
|
||||
_entriesPerChunk = 1 << entryBits;
|
||||
@@ -48,12 +48,12 @@ BufferPool::~BufferPool() {
|
||||
}
|
||||
|
||||
Object *BufferPool::allocateNewChunk() {
|
||||
Object *jsObj = Object::createArrayBufferObject(nullptr, _bytesPerChunk);
|
||||
|
||||
Object *jsObj = _allocator.alloc(_chunks.size(), _bytesPerChunk);
|
||||
|
||||
uint8_t *realPtr = nullptr;
|
||||
size_t len = 0;
|
||||
jsObj->getArrayBufferData(&realPtr, &len);
|
||||
_chunks.push_back(realPtr);
|
||||
|
||||
|
||||
return jsObj;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ THE SOFTWARE.
|
||||
#pragma once
|
||||
|
||||
#include "PoolType.h"
|
||||
#include "BufferAllocator.h"
|
||||
#include "cocos/base/Macros.h"
|
||||
#include "cocos/base/Object.h"
|
||||
#include "cocos/base/TypeDef.h"
|
||||
@@ -32,6 +33,7 @@ THE SOFTWARE.
|
||||
#include "cocos/bindings/jswrapper/Object.h"
|
||||
|
||||
namespace se {
|
||||
|
||||
class CC_DLL BufferPool final : public cc::Object {
|
||||
public:
|
||||
using Chunk = uint8_t *;
|
||||
@@ -54,9 +56,10 @@ public:
|
||||
|
||||
private:
|
||||
static cc::map<PoolType, BufferPool *> _poolMap;
|
||||
|
||||
cc::vector<Chunk> _chunks;
|
||||
static constexpr uint _poolFlag = 1 << 30;
|
||||
|
||||
BufferAllocator _allocator;
|
||||
cc::vector<Chunk> _chunks;
|
||||
uint _entryBits = 1 << 8;
|
||||
uint _chunkMask = 0;
|
||||
uint _entryMask = 0;
|
||||
|
||||
@@ -6,6 +6,7 @@ enum class PoolType {
|
||||
RASTERIZER_STATE,
|
||||
DEPTH_STENCIL_STATE,
|
||||
BLEND_STATE,
|
||||
ATTRIBUTE,
|
||||
DESCRIPTOR_SETS,
|
||||
SHADER,
|
||||
INPUT_ASSEMBLER,
|
||||
@@ -38,6 +39,10 @@ enum class PoolType {
|
||||
// array
|
||||
SUB_MODEL_ARRAY = 200,
|
||||
MODEL_ARRAY,
|
||||
ATTRIBUTE_ARRAY,
|
||||
|
||||
// raw buffer
|
||||
RAW_BUFFER = 300,
|
||||
UNKNOWN
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||
|
||||
#include "BufferPool.h"
|
||||
#include "ObjectPool.h"
|
||||
#include "ArrayPool.h"
|
||||
#include "BufferAllocator.h"
|
||||
#include "cocos/bindings/manual/jsb_global.h"
|
||||
#include "cocos/bindings/manual/jsb_classtype.h"
|
||||
#include "cocos/bindings/manual/jsb_conversions.h"
|
||||
@@ -155,96 +155,85 @@ static bool js_register_se_ObjectPool(se::Object *obj) {
|
||||
/*****************************************************
|
||||
Array binding
|
||||
******************************************************/
|
||||
static se::Class *jsb_ArrayPool_class = nullptr;
|
||||
static se::Class *jsb_BufferAllocator_class = nullptr;
|
||||
|
||||
SE_DECLARE_FINALIZE_FUNC(jsb_ArrayPool_finalize)
|
||||
SE_DECLARE_FINALIZE_FUNC(jsb_BufferAllocator_finalize)
|
||||
|
||||
static bool jsb_ArrayPool_constructor(se::State &s) {
|
||||
static bool jsb_BufferAllocator_constructor(se::State &s) {
|
||||
const auto &args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 2) {
|
||||
if (argc == 1) {
|
||||
uint type = 0;
|
||||
bool ok = seval_to_uint(args[0], &type);
|
||||
uint size = 0;
|
||||
ok &= seval_to_uint(args[1], &size);
|
||||
|
||||
se::ArrayPool *arrayPool = JSB_ALLOC(se::ArrayPool, static_cast<se::PoolType>(type), size);
|
||||
s.thisObject()->setPrivateData(arrayPool);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(arrayPool);
|
||||
se::BufferAllocator *BufferAllocator = JSB_ALLOC(se::BufferAllocator, static_cast<se::PoolType>(type));
|
||||
s.thisObject()->setPrivateData(BufferAllocator);
|
||||
se::NonRefNativePtrCreatedByCtorMap::emplace(BufferAllocator);
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_CTOR(jsb_ArrayPool_constructor, jsb_ArrayPool_class, jsb_ArrayPool_finalize)
|
||||
SE_BIND_CTOR(jsb_BufferAllocator_constructor, jsb_BufferAllocator_class, jsb_BufferAllocator_finalize)
|
||||
|
||||
static bool jsb_ArrayPool_finalize(se::State &s) {
|
||||
static bool jsb_BufferAllocator_finalize(se::State &s) {
|
||||
auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject());
|
||||
if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) {
|
||||
se::NonRefNativePtrCreatedByCtorMap::erase(iter);
|
||||
se::ArrayPool *cobj = (se::ArrayPool *)s.nativeThisObject();
|
||||
se::BufferAllocator *cobj = (se::BufferAllocator *)s.nativeThisObject();
|
||||
JSB_FREE(cobj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FINALIZE_FUNC(jsb_ArrayPool_finalize)
|
||||
|
||||
static bool jsb_ArrayPool_resize(se::State &s) {
|
||||
se::ArrayPool *arrayPool = (se::ArrayPool *)s.nativeThisObject();
|
||||
SE_PRECONDITION2(arrayPool, false, "jsb_ArrayPool_reize : Invalid native array pool");
|
||||
SE_BIND_FINALIZE_FUNC(jsb_BufferAllocator_finalize)
|
||||
|
||||
static bool jsb_BufferAllocator_alloc(se::State &s) {
|
||||
se::BufferAllocator *bufferAllocator = (se::BufferAllocator *)s.nativeThisObject();
|
||||
SE_PRECONDITION2(bufferAllocator, false, "jsb_Array_alloc : Invalid Native Object");
|
||||
|
||||
const auto &args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 3) {
|
||||
uint size = 0;
|
||||
if (!seval_to_uint(args[1], &size)) {
|
||||
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to get size.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
uint index = 0;
|
||||
if (!seval_to_uint(args[2], &index)) {
|
||||
SE_REPORT_ERROR("jsb_ArrayPool_reize: failed to get index.");
|
||||
return false;
|
||||
} else {
|
||||
s.rval().setObject(arrayPool->resize(args[0].toObject(), size, index));
|
||||
}
|
||||
|
||||
seval_to_uint(args[0], &index);
|
||||
uint bytes = 0;
|
||||
seval_to_uint(args[1], &bytes);
|
||||
s.rval().setObject(bufferAllocator->alloc(index, bytes));
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(jsb_ArrayPool_resize);
|
||||
SE_BIND_FUNC(jsb_BufferAllocator_alloc);
|
||||
|
||||
static bool jsb_BufferAllocator_free(se::State &s) {
|
||||
se::BufferAllocator *bufferAllocator = (se::BufferAllocator *)s.nativeThisObject();
|
||||
SE_PRECONDITION2(bufferAllocator, false, "jsb_Array_alloc : Invalid Native Object");
|
||||
|
||||
static bool jsb_ArrayPool_alloc(se::State &s) {
|
||||
se::ArrayPool *arrayPool = (se::ArrayPool *)s.nativeThisObject();
|
||||
SE_PRECONDITION2(arrayPool, false, "jsb_Array_alloc : Invalid Native Object");
|
||||
|
||||
const auto &args = s.args();
|
||||
size_t argc = args.size();
|
||||
if (argc == 1) {
|
||||
uint index = 0;
|
||||
seval_to_uint(args[0], &index);
|
||||
s.rval().setObject(arrayPool->alloc(index));
|
||||
bufferAllocator->free(index);
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(jsb_ArrayPool_alloc);
|
||||
SE_BIND_FUNC(jsb_BufferAllocator_free);
|
||||
|
||||
static bool js_register_se_ArrayPool(se::Object *obj) {
|
||||
se::Class *cls = se::Class::create("NativeArrayPool", obj, nullptr, _SE(jsb_ArrayPool_constructor));
|
||||
cls->defineFunction("resize", _SE(jsb_ArrayPool_resize));
|
||||
cls->defineFunction("alloc", _SE(jsb_ArrayPool_alloc));
|
||||
static bool js_register_se_BufferAllocator(se::Object *obj) {
|
||||
se::Class *cls = se::Class::create("NativeBufferAllocator", obj, nullptr, _SE(jsb_BufferAllocator_constructor));
|
||||
cls->defineFunction("alloc", _SE(jsb_BufferAllocator_alloc));
|
||||
cls->defineFunction("free", _SE(jsb_BufferAllocator_free));
|
||||
cls->install();
|
||||
JSBClassType::registerClass<se::ArrayPool>(cls);
|
||||
JSBClassType::registerClass<se::BufferAllocator>(cls);
|
||||
|
||||
jsb_ArrayPool_class = cls;
|
||||
jsb_BufferAllocator_class = cls;
|
||||
|
||||
se::ScriptEngine::getInstance()->clearException();
|
||||
return true;
|
||||
@@ -260,8 +249,8 @@ bool register_all_dop_bindings(se::Object *obj) {
|
||||
}
|
||||
se::Object *ns = nsVal.toObject();
|
||||
|
||||
js_register_se_BufferAllocator(ns);
|
||||
js_register_se_BufferPool(ns);
|
||||
js_register_se_ObjectPool(ns);
|
||||
js_register_se_ArrayPool(ns);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ public:
|
||||
CC_INLINE uint getCount() const { return _count; }
|
||||
CC_INLINE uint getSize() const { return _size; }
|
||||
CC_INLINE BufferFlags getFlags() const { return _flags; }
|
||||
CC_INLINE uint8_t *getBackupBuffer() const { return _buffer; }
|
||||
|
||||
protected:
|
||||
Device *_device = nullptr;
|
||||
|
||||
@@ -87,6 +87,7 @@ enum class Feature : uint8_t {
|
||||
MSAA,
|
||||
ELEMENT_INDEX_UINT,
|
||||
INSTANCED_ARRAYS,
|
||||
MULTIPLE_RENDER_TARGETS,
|
||||
DEPTH_BOUNDS,
|
||||
LINE_WIDTH,
|
||||
STENCIL_WRITE_MASK,
|
||||
@@ -657,10 +658,10 @@ typedef vector<Color> ColorList;
|
||||
* to be mapped to backend-specific bindings based on maximum limit
|
||||
* of available descriptor slots in each set.
|
||||
*
|
||||
* Because the binding numbers are guaranteed to be consecutive for each
|
||||
* descriptor type inside each set, the mapping procedure can be reduced
|
||||
* The GFX layer assumes the binding numbers for each descriptor type inside each set
|
||||
* are guaranteed to be consecutive, so the mapping procedure is reduced
|
||||
* to a simple shifting operation. This data structure specifies the
|
||||
* exact offsets for each descriptor type in each set.
|
||||
* offsets for each descriptor type in each set.
|
||||
*/
|
||||
struct BindingMappingInfo {
|
||||
vector<int> bufferOffsets;
|
||||
|
||||
@@ -2138,17 +2138,19 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
if (gpuInputAssembler && gpuPipelineState) {
|
||||
if (!gpuInputAssembler->gpuIndirectBuffer) {
|
||||
|
||||
if (gpuInputAssembler->gpuIndexBuffer && cmd->drawInfo.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
glDrawElementsInstancedEXT(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount);
|
||||
if (gpuInputAssembler->gpuIndexBuffer) {
|
||||
if (cmd->drawInfo.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
glDrawElementsInstancedEXT(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (cmd->drawInfo.vertexCount > 0) {
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount);
|
||||
} else {
|
||||
@@ -2160,17 +2162,19 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
|
||||
} else {
|
||||
for (size_t j = 0; j < gpuInputAssembler->gpuIndirectBuffer->indirects.size(); ++j) {
|
||||
const DrawInfo &draw = gpuInputAssembler->gpuIndirectBuffer->indirects[j];
|
||||
if (gpuInputAssembler->gpuIndexBuffer && draw.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
glDrawElementsInstancedEXT(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset, draw.instanceCount);
|
||||
if (gpuInputAssembler->gpuIndexBuffer) {
|
||||
if (draw.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
if (device->useDrawInstanced()) {
|
||||
glDrawElementsInstancedEXT(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset, draw.instanceCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (draw.vertexCount > 0) {
|
||||
if (draw.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, draw.firstIndex, draw.vertexCount);
|
||||
} else {
|
||||
|
||||
@@ -78,6 +78,9 @@ bool GLES2Device::initialize(const DeviceInfo &info) {
|
||||
if (checkExtension("texture_half_float_linear"))
|
||||
_features[(int)Feature::TEXTURE_HALF_FLOAT_LINEAR] = true;
|
||||
|
||||
if (checkExtension("draw_buffers"))
|
||||
_features[(int)Feature::MULTIPLE_RENDER_TARGETS] = true;
|
||||
|
||||
_useVAO = checkExtension("vertex_array_object");
|
||||
_useDrawInstanced = checkExtension("draw_instanced");
|
||||
_useInstancedArrays = _features[(int)Feature::INSTANCED_ARRAYS] = checkExtension("instanced_arrays");
|
||||
|
||||
@@ -2089,15 +2089,17 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
|
||||
GLES3CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx];
|
||||
if (gpuInputAssembler && gpuPipelineState) {
|
||||
if (!gpuInputAssembler->gpuIndirectBuffer) {
|
||||
if (gpuInputAssembler->gpuIndexBuffer && cmd->drawInfo.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
glDrawElementsInstanced(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount);
|
||||
if (gpuInputAssembler->gpuIndexBuffer) {
|
||||
if (cmd->drawInfo.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
glDrawElementsInstanced(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (cmd->drawInfo.vertexCount > 0) {
|
||||
if (cmd->drawInfo.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount);
|
||||
} else {
|
||||
@@ -2107,15 +2109,17 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) {
|
||||
} else {
|
||||
for (size_t j = 0; j < gpuInputAssembler->gpuIndirectBuffer->indirects.size(); ++j) {
|
||||
const DrawInfo &draw = gpuInputAssembler->gpuIndirectBuffer->indirects[j];
|
||||
if (gpuInputAssembler->gpuIndexBuffer && draw.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (draw.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
glDrawElementsInstanced(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset, draw.instanceCount);
|
||||
if (gpuInputAssembler->gpuIndexBuffer) {
|
||||
if (draw.indexCount > 0) {
|
||||
uint8_t *offset = 0;
|
||||
offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride;
|
||||
if (draw.instanceCount == 0) {
|
||||
glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset);
|
||||
} else {
|
||||
glDrawElementsInstanced(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset, draw.instanceCount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (draw.vertexCount > 0) {
|
||||
if (draw.instanceCount == 0) {
|
||||
glDrawArrays(glPrimitive, draw.firstIndex, draw.vertexCount);
|
||||
} else {
|
||||
|
||||
@@ -66,6 +66,7 @@ bool GLES3Device::initialize(const DeviceInfo &info) {
|
||||
_features[(int)Feature::FORMAT_D24S8] = true;
|
||||
_features[(int)Feature::MSAA] = true;
|
||||
_features[(int)Feature::INSTANCED_ARRAYS] = true;
|
||||
_features[(int)Feature::MULTIPLE_RENDER_TARGETS] = true;
|
||||
|
||||
if (checkExtension("color_buffer_float"))
|
||||
_features[(int)Feature::COLOR_FLOAT] = true;
|
||||
|
||||
@@ -124,6 +124,7 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) {
|
||||
_features[(int)Feature::FORMAT_R11G11B10F] = true;
|
||||
_features[(int)Feature::MSAA] = true;
|
||||
_features[(int)Feature::INSTANCED_ARRAYS] = true;
|
||||
_features[(int)Feature::MULTIPLE_RENDER_TARGETS] = true;
|
||||
_features[static_cast<uint>(Feature::DEPTH_BOUNDS)] = false;
|
||||
_features[static_cast<uint>(Feature::LINE_WIDTH)] = false;
|
||||
_features[static_cast<uint>(Feature::STENCIL_COMPARE_MASK)] = false;
|
||||
|
||||
@@ -34,23 +34,15 @@ bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) {
|
||||
|
||||
CCVKGPUDevice *gpuDevice = ((CCVKDevice *)_device)->gpuDevice();
|
||||
_gpuDescriptorSet = CC_NEW(CCVKGPUDescriptorSet);
|
||||
_gpuDescriptorSet->gpuDescriptors.resize(descriptorCount);
|
||||
_gpuDescriptorSet->descriptorInfos.resize(descriptorCount);
|
||||
_gpuDescriptorSet->gpuDescriptors.resize(descriptorCount, {});
|
||||
_gpuDescriptorSet->descriptorInfos.resize(descriptorCount, {});
|
||||
for (size_t i = 0u; i < bindingCount; i++) {
|
||||
const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i];
|
||||
uint descriptorIndex = indices[i];
|
||||
for (uint j = descriptorIndex; j < descriptorIndex + binding.count; j++) {
|
||||
_gpuDescriptorSet->gpuDescriptors[j].type = binding.descriptorType;
|
||||
// although by spec only VkSamplers must be non-null,
|
||||
// many drivers crash on any null handles.
|
||||
// So here we make a default value for every descriptor.
|
||||
if ((uint)binding.descriptorType & DESCRIPTOR_BUFFER_TYPE) {
|
||||
_gpuDescriptorSet->descriptorInfos[j].buffer.buffer = gpuDevice->defaultBuffer.vkBuffer;
|
||||
_gpuDescriptorSet->descriptorInfos[j].buffer.offset = gpuDevice->defaultBuffer.startOffset;
|
||||
_gpuDescriptorSet->descriptorInfos[j].buffer.range = gpuDevice->defaultBuffer.size;
|
||||
} else if ((uint)binding.descriptorType & DESCRIPTOR_SAMPLER_TYPE) {
|
||||
if ((uint)binding.descriptorType & DESCRIPTOR_SAMPLER_TYPE) {
|
||||
_gpuDescriptorSet->descriptorInfos[j].image.sampler = gpuDevice->defaultSampler.vkSampler;
|
||||
_gpuDescriptorSet->descriptorInfos[j].image.imageView = gpuDevice->defaultTextureView.vkImageView;
|
||||
_gpuDescriptorSet->descriptorInfos[j].image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +180,7 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
_features[(uint)Feature::MSAA] = true;
|
||||
_features[(uint)Feature::ELEMENT_INDEX_UINT] = true;
|
||||
_features[(uint)Feature::INSTANCED_ARRAYS] = true;
|
||||
_features[(uint)Feature::MULTIPLE_RENDER_TARGETS] = true;
|
||||
_features[(uint)Feature::DEPTH_BOUNDS] = deviceFeatures.depthBounds;
|
||||
_features[(uint)Feature::LINE_WIDTH] = true;
|
||||
_features[(uint)Feature::STENCIL_COMPARE_MASK] = true;
|
||||
@@ -301,22 +302,6 @@ bool CCVKDevice::initialize(const DeviceInfo &info) {
|
||||
|
||||
CCVKCmdFuncCreateSampler(this, &_gpuDevice->defaultSampler);
|
||||
|
||||
_gpuDevice->defaultTexture.format = Format::RGBA8;
|
||||
_gpuDevice->defaultTexture.usage = TextureUsageBit::SAMPLED;
|
||||
_gpuDevice->defaultTexture.width = _gpuDevice->defaultTexture.height = 1u;
|
||||
_gpuDevice->defaultTexture.size = FormatSize(Format::RGBA8, 1u, 1u, 1u);
|
||||
CCVKCmdFuncCreateTexture(this, &_gpuDevice->defaultTexture);
|
||||
|
||||
_gpuDevice->defaultTextureView.gpuTexture = &_gpuDevice->defaultTexture;
|
||||
_gpuDevice->defaultTextureView.format = Format::RGBA8;
|
||||
CCVKCmdFuncCreateTextureView(this, &_gpuDevice->defaultTextureView);
|
||||
|
||||
_gpuDevice->defaultBuffer.usage = BufferUsage::UNIFORM;
|
||||
_gpuDevice->defaultBuffer.memUsage = MemoryUsage::HOST | MemoryUsage::DEVICE;
|
||||
_gpuDevice->defaultBuffer.size = _gpuDevice->defaultBuffer.stride = 16u;
|
||||
_gpuDevice->defaultBuffer.count = 1u;
|
||||
CCVKCmdFuncCreateBuffer(this, &_gpuDevice->defaultBuffer);
|
||||
|
||||
for (uint i = 0u; i < gpuContext->swapchainCreateInfo.minImageCount; i++) {
|
||||
TextureInfo depthStencilTexInfo;
|
||||
depthStencilTexInfo.type = TextureType::TEX2D;
|
||||
@@ -420,20 +405,6 @@ void CCVKDevice::destroy() {
|
||||
CC_SAFE_DELETE(_gpuFencePool);
|
||||
|
||||
if (_gpuDevice) {
|
||||
if (_gpuDevice->defaultBuffer.vkBuffer) {
|
||||
vmaDestroyBuffer(_gpuDevice->memoryAllocator, _gpuDevice->defaultBuffer.vkBuffer, _gpuDevice->defaultBuffer.vmaAllocation);
|
||||
_gpuDevice->defaultBuffer.vkBuffer = VK_NULL_HANDLE;
|
||||
_gpuDevice->defaultBuffer.vmaAllocation = VK_NULL_HANDLE;
|
||||
}
|
||||
if (_gpuDevice->defaultTextureView.vkImageView) {
|
||||
vkDestroyImageView(_gpuDevice->vkDevice, _gpuDevice->defaultTextureView.vkImageView, nullptr);
|
||||
_gpuDevice->defaultTextureView.vkImageView = VK_NULL_HANDLE;
|
||||
}
|
||||
if (_gpuDevice->defaultTexture.vkImage) {
|
||||
vmaDestroyImage(_gpuDevice->memoryAllocator, _gpuDevice->defaultTexture.vkImage, _gpuDevice->defaultTexture.vmaAllocation);
|
||||
_gpuDevice->defaultTexture.vkImage = VK_NULL_HANDLE;
|
||||
_gpuDevice->defaultTexture.vmaAllocation = VK_NULL_HANDLE;
|
||||
}
|
||||
CCVKCmdFuncDestroySampler(_gpuDevice, &_gpuDevice->defaultSampler);
|
||||
|
||||
if (_gpuDevice->memoryAllocator != VK_NULL_HANDLE) {
|
||||
|
||||
@@ -279,10 +279,7 @@ public:
|
||||
bool useDescriptorUpdateTemplate = false;
|
||||
bool useMultiDrawIndirect = false;
|
||||
|
||||
CCVKGPUBuffer defaultBuffer;
|
||||
CCVKGPUSampler defaultSampler;
|
||||
CCVKGPUTexture defaultTexture;
|
||||
CCVKGPUTextureView defaultTextureView;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "renderer/core/CoreStd.h"
|
||||
|
||||
#include "bindings/dop/ArrayPool.h"
|
||||
#include "bindings/dop/BufferAllocator.h"
|
||||
#include "bindings/dop/BufferPool.h"
|
||||
#include "bindings/dop/ObjectPool.h"
|
||||
#include "math/Vec2.h"
|
||||
@@ -25,9 +25,9 @@ struct CC_DLL ModelView {
|
||||
uint32_t worldBoundsID = 0; // aabb
|
||||
uint32_t nodeID = 0;
|
||||
uint32_t transformID = 0;
|
||||
uint32_t subModelsID = 0; // array pool id
|
||||
// InstancedAttributeBlock instancedAttributeBlock;
|
||||
|
||||
uint32_t subModelsID = 0; // array pool id
|
||||
uint32_t instancedBufferID = 0; // raw buffer id
|
||||
uint32_t instancedAttrsID = 0; // array pool id
|
||||
const static se::PoolType type;
|
||||
};
|
||||
|
||||
@@ -286,7 +286,7 @@ struct CC_DLL RenderWindow {
|
||||
const static se::PoolType type;
|
||||
};
|
||||
|
||||
//Get buffer pool data
|
||||
// Get buffer pool data
|
||||
#define GET_SUBMODEL(index) SharedMemory::getBuffer<SubModelView>(index)
|
||||
#define GET_PASS(index) SharedMemory::getBuffer<PassView>(index)
|
||||
#define GET_MODEL(index) SharedMemory::getBuffer<ModelView>(index)
|
||||
@@ -308,23 +308,27 @@ struct CC_DLL RenderWindow {
|
||||
#define GET_WINDOW(index) SharedMemory::getBuffer<RenderWindow>(index)
|
||||
#define GET_SHADOWS(index) SharedMemory::getBuffer<Shadows>(index)
|
||||
|
||||
//TODO
|
||||
// TODO
|
||||
#define GET_NAME(index) (String(0))
|
||||
|
||||
//Get object pool data
|
||||
// Get object pool data
|
||||
#define GET_DESCRIPTOR_SET(index) SharedMemory::getObject<gfx::DescriptorSet, se::PoolType::DESCRIPTOR_SETS>(index)
|
||||
#define GET_IA(index) SharedMemory::getObject<gfx::InputAssembler, se::PoolType::INPUT_ASSEMBLER>(index)
|
||||
#define GET_SHADER(index) SharedMemory::getObject<gfx::Shader, se::PoolType::SHADER>(index)
|
||||
#define GET_RASTERIZER_STATE(index) SharedMemory::getObject<gfx::RasterizerState, se::PoolType::RASTERIZER_STATE>(index)
|
||||
#define GET_DEPTH_STENCIL_STATE(index) SharedMemory::getObject<gfx::DepthStencilState, se::PoolType::DEPTH_STENCIL_STATE>(index)
|
||||
#define GET_BLEND_STATE(index) SharedMemory::getObject<gfx::BlendState, se::PoolType::BLEND_STATE>(index)
|
||||
#define GET_FRAMEBUFFER(index) SharedMemory::getObject<gfx::Framebuffer, se::PoolType::FRAMEBUFFER>(index)
|
||||
#define GET_ATTRIBUTE(index) SharedMemory::getObject<gfx::Attribute, se::PoolType::ATTRIBUTE>(index)
|
||||
#define GET_PIPELINE_LAYOUT(index) SharedMemory::getObject<gfx::PipelineLayout, se::PoolType::PIPELINE_LAYOUT>(index)
|
||||
#define GET_FRAMEBUFFER(index) SharedMemory::getObject<gfx::Framebuffer, se::PoolType::FRAMEBUFFER>(index)
|
||||
|
||||
//Get array pool data
|
||||
#define GET_MODEL_ARRAY(index) SharedMemory::getArray(se::PoolType::MODEL_ARRAY, index)
|
||||
#define GET_SUBMODEL_ARRAY(index) SharedMemory::getArray(se::PoolType::SUB_MODEL_ARRAY, index)
|
||||
#define GET_PLANE_ARRAY(index) (static_cast<uint32_t *>(0))
|
||||
// Get array pool data
|
||||
#define GET_MODEL_ARRAY(index) SharedMemory::getHandleArray(se::PoolType::MODEL_ARRAY, index)
|
||||
#define GET_SUBMODEL_ARRAY(index) SharedMemory::getHandleArray(se::PoolType::SUB_MODEL_ARRAY, index)
|
||||
#define GET_ATTRIBUTE_ARRAY(index) SharedMemory::getHandleArray(se::PoolType::ATTRIBUTE_ARRAY, index)
|
||||
#define GET_PLANE_ARRAY(index) (static_cast<uint32_t *>(0))
|
||||
|
||||
#define GET_RAW_BUFFER(index) SharedMemory::getRawBuffer<uint8_t>(se::PoolType::RAW_BUFFER, index)
|
||||
|
||||
class CC_DLL SharedMemory : public Object {
|
||||
public:
|
||||
@@ -350,8 +354,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t *getArray(se::PoolType type, uint index) {
|
||||
return se::ArrayPool::getArray(type, index);
|
||||
static uint32_t *getHandleArray(se::PoolType type, uint index) {
|
||||
return se::BufferAllocator::getBuffer<uint32_t>(type, index);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T *getRawBuffer(se::PoolType type, uint index) {
|
||||
return se::BufferAllocator::getBuffer<T>(type, index);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+25
-25
@@ -44,38 +44,38 @@ classes_need_extend =
|
||||
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
|
||||
# functions from all classes.
|
||||
|
||||
skip = Buffer::[Buffer initialize update],
|
||||
CommandBuffer::[CommandBuffer execute updateBuffer copyBuffersToTexture],
|
||||
Framebuffer::[Framebuffer],
|
||||
InputAssembler::[InputAssembler extractDrawInfo],
|
||||
DescriptorSet::[DescriptorSet],
|
||||
DescriptorSetLayout::[DescriptorSetLayout],
|
||||
PipelineLayout::[PipelineLayout],
|
||||
PipelineState::[PipelineState],
|
||||
Fence::[Fence],
|
||||
Queue::[Queue],
|
||||
RenderPass::[RenderPass],
|
||||
Sampler::[Sampler],
|
||||
Shader::[Shader],
|
||||
Texture::[Texture initialize],
|
||||
skip = Buffer::[Buffer getDevice initialize update],
|
||||
CommandBuffer::[CommandBuffer getDevice execute updateBuffer copyBuffersToTexture],
|
||||
Framebuffer::[Framebuffer getDevice],
|
||||
InputAssembler::[InputAssembler getDevice extractDrawInfo],
|
||||
DescriptorSet::[DescriptorSet getDevice],
|
||||
DescriptorSetLayout::[DescriptorSetLayout getDevice],
|
||||
PipelineLayout::[PipelineLayout getDevice],
|
||||
PipelineState::[PipelineState getDevice],
|
||||
Fence::[Fence getDevice],
|
||||
Queue::[Queue getDevice],
|
||||
RenderPass::[RenderPass getDevice],
|
||||
Sampler::[Sampler getDevice],
|
||||
Shader::[Shader getDevice],
|
||||
Texture::[Texture getDevice initialize],
|
||||
Device::[copyBuffersToTexture createBuffer createTexture getInstance],
|
||||
BlendState::[targets]
|
||||
|
||||
getter_setter = Device::[gfxAPI deviceName width height nativeWidth nativeHeight memoryStatus context queue commandBuffer renderer vendor numDrawCalls numInstances numTris maxVertexAttributes maxVertexUniformVectors maxFragmentUniformVectors maxTextureUnits maxVertexTextureUnits maxUniformBufferBindings maxUniformBlockSize maxTextureSize maxCubeMapTextureSize uboOffsetAlignment depthBits stencilBits shaderIdGen colorFormat depthStencilFormat clipSpaceMinZ screenSpaceSignY UVSpaceSignY],
|
||||
Shader::[device name shaderID/getID stages attributes blocks samplers],
|
||||
Shader::[name shaderID/getID stages attributes blocks samplers],
|
||||
Texture::[type usage format width height depth layerCount levelCount size samples flags buffer],
|
||||
BindingLayout::[device bindingUnits],
|
||||
Queue::[device type],
|
||||
RenderPass::[device colorAttachments depthStencilAttachment subPasses hash],
|
||||
BindingLayout::[bindingUnits],
|
||||
Queue::[type],
|
||||
RenderPass::[colorAttachments depthStencilAttachment subPasses hash],
|
||||
DescriptorSetLayout::[bindings descriptorIndices],
|
||||
PipelineLayout::[setLayouts],
|
||||
PipelineState::[device shader primitive inputState rasterizerState depthStencilState blendState renderPass],
|
||||
InputAssembler::[device vertexBuffers attributes indexBuffer indirectBuffer vertexCount firstVertex indexCount firstIndex vertexOffset instanceCount firstInstance attributesHash],
|
||||
Commanduffer::[device type queue numDrawCalls numInstances numTris],
|
||||
Context::[device sharedContext/sharedContext vsyncMode colorFormat depthStencilFormat],
|
||||
Framebuffer::[device renderPass colorTextures depthStencilTexture],
|
||||
Buffer::[device usage memUsage stride count size flags backupBuffer],
|
||||
Sampler::[device name minFilter magFilter mipFilter addressU addressV addressW maxAnisotropy cmpFunc borderColor minLOD maxLOD mipLODBias],
|
||||
PipelineState::[shader primitive inputState rasterizerState depthStencilState blendState renderPass],
|
||||
InputAssembler::[vertexBuffers attributes indexBuffer indirectBuffer vertexCount firstVertex indexCount firstIndex vertexOffset instanceCount firstInstance attributesHash],
|
||||
Commanduffer::[type queue numDrawCalls numInstances numTris],
|
||||
Context::[sharedContext/sharedContext vsyncMode colorFormat depthStencilFormat],
|
||||
Framebuffer::[renderPass colorTextures depthStencilTexture],
|
||||
Buffer::[usage memUsage stride count size flags],
|
||||
Sampler::[name minFilter magFilter mipFilter addressU addressV addressW maxAnisotropy cmpFunc borderColor minLOD maxLOD mipLODBias],
|
||||
GFXObject::[gfxType/getType]
|
||||
|
||||
rename_functions =
|
||||
|
||||
Reference in New Issue
Block a user