diff --git a/native/.vscode/c_cpp_properties.json b/native/.vscode/c_cpp_properties.json index 22ea0dd8ed..b3c838cb16 100644 --- a/native/.vscode/c_cpp_properties.json +++ b/native/.vscode/c_cpp_properties.json @@ -13,7 +13,6 @@ "external/sources", "external/sources/khronos", "external/win32/include", - "external/win32/include/glslang", "external/win32/include/v8" ], "compileCommands": "${workspaceFolder}/compile_commands.json" diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.cpp b/native/cocos/bindings/auto/jsb_gfx_auto.cpp index 5803a4c144..a577298da6 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.cpp +++ b/native/cocos/bindings/auto/jsb_gfx_auto.cpp @@ -3545,86 +3545,221 @@ bool js_register_gfx_Color(se::Object* obj) // NOLINT(readability-identifier-nam se::Object* __jsb_cc_gfx_BindingMappingInfo_proto = nullptr; se::Class* __jsb_cc_gfx_BindingMappingInfo_class = nullptr; -static bool js_gfx_BindingMappingInfo_get_bufferOffsets(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_gfx_BindingMappingInfo_get_maxBlockCounts(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_bufferOffsets : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxBlockCounts : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= nativevalue_to_se(cobj->bufferOffsets, jsret, s.thisObject() /*ctx*/); + ok &= nativevalue_to_se(cobj->maxBlockCounts, jsret, s.thisObject() /*ctx*/); s.rval() = jsret; - SE_HOLD_RETURN_VALUE(cobj->bufferOffsets, s.thisObject(), s.rval()); + SE_HOLD_RETURN_VALUE(cobj->maxBlockCounts, s.thisObject(), s.rval()); return true; } -SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_bufferOffsets) +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxBlockCounts) -static bool js_gfx_BindingMappingInfo_set_bufferOffsets(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_gfx_BindingMappingInfo_set_maxBlockCounts(se::State& s) // NOLINT(readability-identifier-naming) { const auto& args = s.args(); auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_bufferOffsets : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxBlockCounts : Invalid Native Object"); CC_UNUSED bool ok = true; - ok &= sevalue_to_native(args[0], &cobj->bufferOffsets, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_bufferOffsets : Error processing new value"); + ok &= sevalue_to_native(args[0], &cobj->maxBlockCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxBlockCounts : Error processing new value"); return true; } -SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_bufferOffsets) +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxBlockCounts) -static bool js_gfx_BindingMappingInfo_get_samplerOffsets(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_gfx_BindingMappingInfo_get_maxSamplerTextureCounts(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_samplerOffsets : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxSamplerTextureCounts : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= nativevalue_to_se(cobj->samplerOffsets, jsret, s.thisObject() /*ctx*/); + ok &= nativevalue_to_se(cobj->maxSamplerTextureCounts, jsret, s.thisObject() /*ctx*/); s.rval() = jsret; - SE_HOLD_RETURN_VALUE(cobj->samplerOffsets, s.thisObject(), s.rval()); + SE_HOLD_RETURN_VALUE(cobj->maxSamplerTextureCounts, s.thisObject(), s.rval()); return true; } -SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_samplerOffsets) +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxSamplerTextureCounts) -static bool js_gfx_BindingMappingInfo_set_samplerOffsets(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_gfx_BindingMappingInfo_set_maxSamplerTextureCounts(se::State& s) // NOLINT(readability-identifier-naming) { const auto& args = s.args(); auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_samplerOffsets : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxSamplerTextureCounts : Invalid Native Object"); CC_UNUSED bool ok = true; - ok &= sevalue_to_native(args[0], &cobj->samplerOffsets, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_samplerOffsets : Error processing new value"); + ok &= sevalue_to_native(args[0], &cobj->maxSamplerTextureCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxSamplerTextureCounts : Error processing new value"); return true; } -SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_samplerOffsets) +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxSamplerTextureCounts) -static bool js_gfx_BindingMappingInfo_get_flexibleSet(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_gfx_BindingMappingInfo_get_maxSamplerCounts(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_flexibleSet : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxSamplerCounts : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= nativevalue_to_se(cobj->flexibleSet, jsret, s.thisObject() /*ctx*/); + ok &= nativevalue_to_se(cobj->maxSamplerCounts, jsret, s.thisObject() /*ctx*/); s.rval() = jsret; - SE_HOLD_RETURN_VALUE(cobj->flexibleSet, s.thisObject(), s.rval()); + SE_HOLD_RETURN_VALUE(cobj->maxSamplerCounts, s.thisObject(), s.rval()); return true; } -SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_flexibleSet) +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxSamplerCounts) -static bool js_gfx_BindingMappingInfo_set_flexibleSet(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_gfx_BindingMappingInfo_set_maxSamplerCounts(se::State& s) // NOLINT(readability-identifier-naming) { const auto& args = s.args(); auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_flexibleSet : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxSamplerCounts : Invalid Native Object"); CC_UNUSED bool ok = true; - ok &= sevalue_to_native(args[0], &cobj->flexibleSet, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_flexibleSet : Error processing new value"); + ok &= sevalue_to_native(args[0], &cobj->maxSamplerCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxSamplerCounts : Error processing new value"); return true; } -SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_flexibleSet) +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxSamplerCounts) + +static bool js_gfx_BindingMappingInfo_get_maxTextureCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxTextureCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->maxTextureCounts, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->maxTextureCounts, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxTextureCounts) + +static bool js_gfx_BindingMappingInfo_set_maxTextureCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxTextureCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->maxTextureCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxTextureCounts : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxTextureCounts) + +static bool js_gfx_BindingMappingInfo_get_maxBufferCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxBufferCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->maxBufferCounts, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->maxBufferCounts, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxBufferCounts) + +static bool js_gfx_BindingMappingInfo_set_maxBufferCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxBufferCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->maxBufferCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxBufferCounts : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxBufferCounts) + +static bool js_gfx_BindingMappingInfo_get_maxImageCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxImageCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->maxImageCounts, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->maxImageCounts, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxImageCounts) + +static bool js_gfx_BindingMappingInfo_set_maxImageCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxImageCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->maxImageCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxImageCounts : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxImageCounts) + +static bool js_gfx_BindingMappingInfo_get_maxSubpassInputCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_maxSubpassInputCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->maxSubpassInputCounts, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->maxSubpassInputCounts, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_maxSubpassInputCounts) + +static bool js_gfx_BindingMappingInfo_set_maxSubpassInputCounts(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_maxSubpassInputCounts : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->maxSubpassInputCounts, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_maxSubpassInputCounts : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_maxSubpassInputCounts) + +static bool js_gfx_BindingMappingInfo_get_setIndices(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_get_setIndices : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->setIndices, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->setIndices, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_gfx_BindingMappingInfo_get_setIndices) + +static bool js_gfx_BindingMappingInfo_set_setIndices(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_BindingMappingInfo_set_setIndices : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->setIndices, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_BindingMappingInfo_set_setIndices : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_gfx_BindingMappingInfo_set_setIndices) template<> @@ -3639,17 +3774,37 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::BindingMappingInfo * to, } se::Value field; bool ok = true; - json->getProperty("bufferOffsets", &field); + json->getProperty("maxBlockCounts", &field); if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->bufferOffsets), ctx); + ok &= sevalue_to_native(field, &(to->maxBlockCounts), ctx); } - json->getProperty("samplerOffsets", &field); + json->getProperty("maxSamplerTextureCounts", &field); if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->samplerOffsets), ctx); + ok &= sevalue_to_native(field, &(to->maxSamplerTextureCounts), ctx); } - json->getProperty("flexibleSet", &field); + json->getProperty("maxSamplerCounts", &field); if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->flexibleSet), ctx); + ok &= sevalue_to_native(field, &(to->maxSamplerCounts), ctx); + } + json->getProperty("maxTextureCounts", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->maxTextureCounts), ctx); + } + json->getProperty("maxBufferCounts", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->maxBufferCounts), ctx); + } + json->getProperty("maxImageCounts", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->maxImageCounts), ctx); + } + json->getProperty("maxSubpassInputCounts", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->maxSubpassInputCounts), ctx); + } + json->getProperty("setIndices", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->setIndices), ctx); } return ok; } @@ -3690,13 +3845,28 @@ static bool js_gfx_BindingMappingInfo_constructor(se::State& s) // NOLINT(readab cc::gfx::BindingMappingInfo* cobj = JSB_ALLOC(cc::gfx::BindingMappingInfo); if (argc > 0 && !args[0].isUndefined()) { - ok &= sevalue_to_native(args[0], &(cobj->bufferOffsets), nullptr); + ok &= sevalue_to_native(args[0], &(cobj->maxBlockCounts), nullptr); } if (argc > 1 && !args[1].isUndefined()) { - ok &= sevalue_to_native(args[1], &(cobj->samplerOffsets), nullptr); + ok &= sevalue_to_native(args[1], &(cobj->maxSamplerTextureCounts), nullptr); } if (argc > 2 && !args[2].isUndefined()) { - ok &= sevalue_to_native(args[2], &(cobj->flexibleSet), nullptr); + ok &= sevalue_to_native(args[2], &(cobj->maxSamplerCounts), nullptr); + } + if (argc > 3 && !args[3].isUndefined()) { + ok &= sevalue_to_native(args[3], &(cobj->maxTextureCounts), nullptr); + } + if (argc > 4 && !args[4].isUndefined()) { + ok &= sevalue_to_native(args[4], &(cobj->maxBufferCounts), nullptr); + } + if (argc > 5 && !args[5].isUndefined()) { + ok &= sevalue_to_native(args[5], &(cobj->maxImageCounts), nullptr); + } + if (argc > 6 && !args[6].isUndefined()) { + ok &= sevalue_to_native(args[6], &(cobj->maxSubpassInputCounts), nullptr); + } + if (argc > 7 && !args[7].isUndefined()) { + ok &= sevalue_to_native(args[7], &(cobj->setIndices), nullptr); } if(!ok) { @@ -3730,9 +3900,14 @@ bool js_register_gfx_BindingMappingInfo(se::Object* obj) // NOLINT(readability-i { auto* cls = se::Class::create("BindingMappingInfo", obj, nullptr, _SE(js_gfx_BindingMappingInfo_constructor)); - cls->defineProperty("bufferOffsets", _SE(js_gfx_BindingMappingInfo_get_bufferOffsets), _SE(js_gfx_BindingMappingInfo_set_bufferOffsets)); - cls->defineProperty("samplerOffsets", _SE(js_gfx_BindingMappingInfo_get_samplerOffsets), _SE(js_gfx_BindingMappingInfo_set_samplerOffsets)); - cls->defineProperty("flexibleSet", _SE(js_gfx_BindingMappingInfo_get_flexibleSet), _SE(js_gfx_BindingMappingInfo_set_flexibleSet)); + cls->defineProperty("maxBlockCounts", _SE(js_gfx_BindingMappingInfo_get_maxBlockCounts), _SE(js_gfx_BindingMappingInfo_set_maxBlockCounts)); + cls->defineProperty("maxSamplerTextureCounts", _SE(js_gfx_BindingMappingInfo_get_maxSamplerTextureCounts), _SE(js_gfx_BindingMappingInfo_set_maxSamplerTextureCounts)); + cls->defineProperty("maxSamplerCounts", _SE(js_gfx_BindingMappingInfo_get_maxSamplerCounts), _SE(js_gfx_BindingMappingInfo_set_maxSamplerCounts)); + cls->defineProperty("maxTextureCounts", _SE(js_gfx_BindingMappingInfo_get_maxTextureCounts), _SE(js_gfx_BindingMappingInfo_set_maxTextureCounts)); + cls->defineProperty("maxBufferCounts", _SE(js_gfx_BindingMappingInfo_get_maxBufferCounts), _SE(js_gfx_BindingMappingInfo_set_maxBufferCounts)); + cls->defineProperty("maxImageCounts", _SE(js_gfx_BindingMappingInfo_get_maxImageCounts), _SE(js_gfx_BindingMappingInfo_set_maxImageCounts)); + cls->defineProperty("maxSubpassInputCounts", _SE(js_gfx_BindingMappingInfo_get_maxSubpassInputCounts), _SE(js_gfx_BindingMappingInfo_set_maxSubpassInputCounts)); + cls->defineProperty("setIndices", _SE(js_gfx_BindingMappingInfo_get_setIndices), _SE(js_gfx_BindingMappingInfo_set_setIndices)); cls->defineFinalizeFunction(_SE(js_cc_gfx_BindingMappingInfo_finalize)); cls->install(); JSBClassType::registerClass(cls); diff --git a/native/cocos/renderer/frame-graph/DevicePass.cpp b/native/cocos/renderer/frame-graph/DevicePass.cpp index e75329d601..a15173e668 100644 --- a/native/cocos/renderer/frame-graph/DevicePass.cpp +++ b/native/cocos/renderer/frame-graph/DevicePass.cpp @@ -24,16 +24,18 @@ ****************************************************************************/ #include "DevicePass.h" -#include #include "CallbackPass.h" #include "DevicePassResourceTable.h" #include "FrameGraph.h" #include "PassNode.h" #include "ResourceNode.h" + #include "base/Utils.h" #include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDef-common.h" +#include + namespace cc { namespace framegraph { @@ -225,8 +227,8 @@ void DevicePass::begin(gfx::CommandBuffer *cmdBuff) { // calculate the union of all viewports as render area _viewport.left = _scissor.x = std::min(_scissor.x, pass.viewport.left); _viewport.top = _scissor.y = std::min(_scissor.y, pass.viewport.top); - _viewport.width = _scissor.width = std::max(_scissor.width, pass.viewport.width); - _viewport.height = _scissor.height = std::max(_scissor.height, pass.viewport.height); + _viewport.width = _scissor.width = std::max(_scissor.width, pass.viewport.width + pass.viewport.left - _scissor.x); + _viewport.height = _scissor.height = std::max(_scissor.height, pass.viewport.height + pass.viewport.top - _scissor.y); } } } diff --git a/native/cocos/renderer/frame-graph/FrameGraph.cpp b/native/cocos/renderer/frame-graph/FrameGraph.cpp index 9265ecd96c..8ce1bc9666 100644 --- a/native/cocos/renderer/frame-graph/FrameGraph.cpp +++ b/native/cocos/renderer/frame-graph/FrameGraph.cpp @@ -191,12 +191,7 @@ void FrameGraph::move(const TextureHandle from, const TextureHandle to, uint8_t } bool FrameGraph::hasPass(StringHandle handle) { - for (const auto &passNode : _passNodes) { - if (passNode->_name == handle) { - return true; - } - } - return false; + return std::any_of(_passNodes.begin(), _passNodes.end(), [&](const auto &passNode) { return passNode->_name == handle; }); } Handle FrameGraph::create(VirtualResource *const virtualResource) { diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index e7899ce942..ffc66622bf 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -123,6 +123,7 @@ enum class API : uint32_t { GLES3, METAL, VULKAN, + NVN, WEBGL, WEBGL2, WEBGPU, @@ -884,12 +885,22 @@ using ColorList = vector; * 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 - * offsets for each descriptor type in each set. + * capacity for each descriptor type in each set. + * + * The `setIndices` field defines the binding ordering between different sets. + * The last set index is treated as the 'flexible set', whose capacity is dynamically + * assigned based on the total available descriptor slots on the runtime device. */ struct BindingMappingInfo { - std::vector bufferOffsets; - std::vector samplerOffsets; - uint32_t flexibleSet{0U}; + std::vector maxBlockCounts{0}; + std::vector maxSamplerTextureCounts{0}; + std::vector maxSamplerCounts{0}; + std::vector maxTextureCounts{0}; + std::vector maxBufferCounts{0}; + std::vector maxImageCounts{0}; + std::vector maxSubpassInputCounts{0}; + + std::vector setIndices{0}; }; struct SwapchainInfo { diff --git a/native/cocos/renderer/gfx-base/GFXDevice.cpp b/native/cocos/renderer/gfx-base/GFXDevice.cpp index 5d16229c8c..f5c8944de1 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.cpp +++ b/native/cocos/renderer/gfx-base/GFXDevice.cpp @@ -49,12 +49,6 @@ Device::~Device() { bool Device::initialize(const DeviceInfo &info) { _bindingMappingInfo = info.bindingMappingInfo; - if (_bindingMappingInfo.bufferOffsets.empty()) { - _bindingMappingInfo.bufferOffsets.push_back(0); - } - if (_bindingMappingInfo.samplerOffsets.empty()) { - _bindingMappingInfo.samplerOffsets.push_back(0); - } #if CC_CPU_ARCH == CC_CPU_ARCH_32 static_assert(sizeof(void*) == 4, "pointer size assumption broken"); @@ -78,9 +72,6 @@ void Device::destroy() { CC_SAFE_DELETE(pair.second); } - _bindingMappingInfo.bufferOffsets.clear(); - _bindingMappingInfo.samplerOffsets.clear(); - doDestroy(); CC_SAFE_DELETE(_onAcquire); diff --git a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h index d6b9f289fa..a23e19ccf7 100644 --- a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h +++ b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h @@ -61,6 +61,13 @@ enum class GLESCmdType : uint8_t { COUNT, }; +class GLESBindingMapping { +public: + vector blockOffsets; + vector samplerTextureOffsets; + uint32_t flexibleSet{0}; +}; + class GLESCmd : public Object { public: GLESCmdType type; diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp index 3c99072121..af8ba8679a 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp @@ -54,7 +54,7 @@ void GLES2CommandBuffer::doInit(const CommandBufferInfo &info) { _cmdAllocator = CC_NEW(GLES2GPUCommandAllocator); _curCmdPackage = CC_NEW(GLES2CmdPackage); - size_t setCount = GLES2Device::getInstance()->bindingMappingInfo().bufferOffsets.size(); + size_t setCount = GLES2Device::getInstance()->bindingMappingInfo().setIndices.size(); _curGPUDescriptorSets.resize(setCount); _curDynamicOffsets.resize(setCount); } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp index 380e31ba12..955f37c096 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp @@ -27,6 +27,7 @@ #include "GLES2Commands.h" #include "GLES2Device.h" +#include "gfx-gles-common/GLESCommandPool.h" #define BUFFER_OFFSET(idx) (static_cast(0) + (idx)) @@ -1100,14 +1101,14 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { // texture unit index mapping optimization vector glActiveSamplerTextures; vector glActiveSamplerLocations; - const BindingMappingInfo & bindingMappingInfo = device->bindingMappingInfo(); - unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; + const GLESBindingMapping & bindingMappings = device->bindingMappings(); + unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; // sampler bindings in the flexible set comes strictly after buffer bindings // so we need to subtract the buffer count for these samplers uint32_t flexibleSetBaseOffset = 0U; - for (auto &block : gpuShader->blocks) { - if (block.set == bindingMappingInfo.flexibleSet) { + for (const auto &block : gpuShader->blocks) { + if (block.set == bindingMappings.flexibleSet) { flexibleSetBaseOffset++; } } @@ -1122,8 +1123,8 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { glActiveSamplerLocations.push_back(glLoc); } if (!texUnitCacheMap.count(samplerTexture.name)) { - uint32_t binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; - if (samplerTexture.set == bindingMappingInfo.flexibleSet) binding -= flexibleSetBaseOffset; + uint32_t binding = samplerTexture.binding + bindingMappings.samplerTextureOffsets[samplerTexture.set] + arrayOffset; + if (samplerTexture.set == bindingMappings.flexibleSet) binding -= flexibleSetBaseOffset; texUnitCacheMap[samplerTexture.name] = binding % device->getCapabilities().maxTextureUnits; arrayOffset += samplerTexture.count - 1; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp index b4511d98b5..0706fb8144 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp @@ -73,23 +73,23 @@ void GLES2DescriptorSet::doDestroy() { void GLES2DescriptorSet::update() { if (_isDirty && _gpuDescriptorSet) { - const GLES2GPUDescriptorList &descriptors = _gpuDescriptorSet->gpuDescriptors; + auto &descriptors = _gpuDescriptorSet->gpuDescriptors; for (size_t i = 0; i < descriptors.size(); i++) { if (hasAnyFlags(descriptors[i].type, DESCRIPTOR_BUFFER_TYPE)) { auto *buffer = static_cast(_buffers[i]); if (buffer) { if (buffer->gpuBuffer()) { - _gpuDescriptorSet->gpuDescriptors[i].gpuBuffer = buffer->gpuBuffer(); + descriptors[i].gpuBuffer = buffer->gpuBuffer(); } else if (buffer->gpuBufferView()) { - _gpuDescriptorSet->gpuDescriptors[i].gpuBufferView = buffer->gpuBufferView(); + descriptors[i].gpuBufferView = buffer->gpuBufferView(); } } } else if (hasAnyFlags(descriptors[i].type, DESCRIPTOR_TEXTURE_TYPE)) { if (_textures[i]) { - _gpuDescriptorSet->gpuDescriptors[i].gpuTexture = static_cast(_textures[i])->gpuTexture(); + descriptors[i].gpuTexture = static_cast(_textures[i])->gpuTexture(); } if (_samplers[i]) { - _gpuDescriptorSet->gpuDescriptors[i].gpuSampler = static_cast(_samplers[i])->gpuSampler(); + descriptors[i].gpuSampler = static_cast(_samplers[i])->gpuSampler(); } } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 481d72bbd5..7487dfdd0a 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -83,6 +83,21 @@ bool GLES2Device::doInit(const DeviceInfo & /*info*/) { return false; }; + _bindingMappings.blockOffsets.resize(_bindingMappingInfo.setIndices.size()); + _bindingMappings.samplerTextureOffsets.resize(_bindingMappingInfo.setIndices.size()); + for (size_t i = 0; i < _bindingMappingInfo.setIndices.size(); ++i) { + uint32_t curSet{_bindingMappingInfo.setIndices[i]}; + uint32_t prevSet{i ? _bindingMappingInfo.setIndices[i - 1] : curSet}; + // accumulate the per set offset according to the specified capacity + _bindingMappings.blockOffsets[curSet] = i ? static_cast(_bindingMappingInfo.maxBlockCounts[prevSet]) + _bindingMappings.blockOffsets[prevSet] : 0; + _bindingMappings.samplerTextureOffsets[curSet] = i ? static_cast(_bindingMappingInfo.maxSamplerTextureCounts[prevSet]) + _bindingMappings.samplerTextureOffsets[prevSet] : 0; + } + for (uint32_t curSet : _bindingMappingInfo.setIndices) { + // textures always come after UBOs + _bindingMappings.samplerTextureOffsets[curSet] -= static_cast(_bindingMappingInfo.maxBlockCounts[curSet]); + } + _bindingMappings.flexibleSet = _bindingMappingInfo.setIndices.back(); + String extStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); _extensions = StringUtil::split(extStr, " "); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index 2dbf30409f..0cb8cdf631 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -28,6 +28,7 @@ #include "GLES2Std.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXSwapchain.h" +#include "gfx-gles-common/GLESCommandPool.h" namespace cc { namespace gfx { @@ -67,6 +68,8 @@ public: void acquire(Swapchain *const *swapchains, uint32_t count) override; void present() override; + inline const GLESBindingMapping &bindingMappings() const { return _bindingMappings; } + inline GLES2GPUContext * context() const { return _gpuContext; } inline GLES2GPUStateCache * stateCache() const { return _gpuStateCache; } inline GLES2GPUBlitManager * blitManager() const { return _gpuBlitManager; } @@ -123,6 +126,8 @@ protected: vector _swapchains; + GLESBindingMapping _bindingMappings; + StringArray _extensions; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index b9ae5ac68a..e85ca86ae9 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -53,7 +53,7 @@ void GLES3CommandBuffer::doInit(const CommandBufferInfo & /*info*/) { _cmdAllocator = CC_NEW(GLES3GPUCommandAllocator); _curCmdPackage = CC_NEW(GLES3CmdPackage); - size_t setCount = GLES3Device::getInstance()->bindingMappingInfo().bufferOffsets.size(); + size_t setCount = GLES3Device::getInstance()->bindingMappingInfo().setIndices.size(); _curGPUDescriptorSets.resize(setCount); _curDynamicOffsets.resize(setCount); } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index 33856964fc..21c2df7013 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -29,6 +29,7 @@ #include "GLES3Device.h" #include "GLES3QueryPool.h" #include "gfx-base/GFXDef-common.h" +#include "gfx-gles-common/GLESCommandPool.h" #define BUFFER_OFFSET(idx) (static_cast(0) + (idx)) @@ -1147,7 +1148,7 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { if (block.name == glBlock.name) { glBlock.set = block.set; glBlock.binding = block.binding; - glBlock.glBinding = block.binding + device->bindingMappingInfo().bufferOffsets[block.set]; + glBlock.glBinding = block.binding + device->bindingMappings().blockOffsets[block.set]; GL_CHECK(glUniformBlockBinding(gpuShader->glProgram, i, glBlock.glBinding)); break; } @@ -1216,14 +1217,14 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { // texture unit index mapping optimization vector glActiveSamplerTextures; vector glActiveSamplerLocations; - const BindingMappingInfo & bindingMappingInfo = device->bindingMappingInfo(); - unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; + const GLESBindingMapping & bindingMappings = device->bindingMappings(); + unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; // sampler bindings in the flexible set comes strictly after buffer bindings // so we need to subtract the buffer count for these samplers uint32_t flexibleSetBaseOffset = 0U; - for (GLES3GPUUniformBuffer &buffer : gpuShader->glBuffers) { - if (buffer.set == bindingMappingInfo.flexibleSet) { + for (const auto &buffer : gpuShader->blocks) { + if (buffer.set == bindingMappings.flexibleSet) { flexibleSetBaseOffset++; } } @@ -1239,8 +1240,8 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { glActiveSamplerLocations.push_back(glLoc); if (texUnitCacheMap.count(samplerTexture.name) == 0U) { - uint32_t binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; - if (samplerTexture.set == bindingMappingInfo.flexibleSet) binding -= flexibleSetBaseOffset; + uint32_t binding = samplerTexture.binding + bindingMappings.samplerTextureOffsets[samplerTexture.set] + arrayOffset; + if (samplerTexture.set == bindingMappings.flexibleSet) binding -= flexibleSetBaseOffset; texUnitCacheMap[samplerTexture.name] = binding % device->getCapabilities().maxTextureUnits; arrayOffset += samplerTexture.count - 1; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp index 300c0c2852..678df0dc28 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp @@ -69,18 +69,18 @@ void GLES3DescriptorSet::doDestroy() { void GLES3DescriptorSet::update() { if (_isDirty && _gpuDescriptorSet) { - const GLES3GPUDescriptorList &descriptors = _gpuDescriptorSet->gpuDescriptors; + auto &descriptors = _gpuDescriptorSet->gpuDescriptors; for (size_t i = 0; i < descriptors.size(); i++) { if (hasAnyFlags(descriptors[i].type, DESCRIPTOR_BUFFER_TYPE)) { if (_buffers[i]) { - _gpuDescriptorSet->gpuDescriptors[i].gpuBuffer = static_cast(_buffers[i])->gpuBuffer(); + descriptors[i].gpuBuffer = static_cast(_buffers[i])->gpuBuffer(); } } else if (hasAnyFlags(descriptors[i].type, DESCRIPTOR_TEXTURE_TYPE)) { if (_textures[i]) { - _gpuDescriptorSet->gpuDescriptors[i].gpuTexture = static_cast(_textures[i])->gpuTexture(); + descriptors[i].gpuTexture = static_cast(_textures[i])->gpuTexture(); } if (_samplers[i]) { - _gpuDescriptorSet->gpuDescriptors[i].gpuSampler = static_cast(_samplers[i])->gpuSampler(); + descriptors[i].gpuSampler = static_cast(_samplers[i])->gpuSampler(); } } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index 263324ea2a..1863ad40d0 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -83,6 +83,21 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) { return false; }; + _bindingMappings.blockOffsets.resize(_bindingMappingInfo.setIndices.size()); + _bindingMappings.samplerTextureOffsets.resize(_bindingMappingInfo.setIndices.size()); + for (size_t i = 0; i < _bindingMappingInfo.setIndices.size(); ++i) { + uint32_t curSet{_bindingMappingInfo.setIndices[i]}; + uint32_t prevSet{i ? _bindingMappingInfo.setIndices[i - 1] : curSet}; + // accumulate the per set offset according to the specified capacity + _bindingMappings.blockOffsets[curSet] = i ? static_cast(_bindingMappingInfo.maxBlockCounts[prevSet]) + _bindingMappings.blockOffsets[prevSet] : 0; + _bindingMappings.samplerTextureOffsets[curSet] = i ? static_cast(_bindingMappingInfo.maxSamplerTextureCounts[prevSet]) + _bindingMappings.samplerTextureOffsets[prevSet] : 0; + } + for (uint32_t curSet : _bindingMappingInfo.setIndices) { + // textures always come after UBOs + _bindingMappings.samplerTextureOffsets[curSet] -= static_cast(_bindingMappingInfo.maxBlockCounts[curSet]); + } + _bindingMappings.flexibleSet = _bindingMappingInfo.setIndices.back(); + String extStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); _extensions = StringUtil::split(extStr, " "); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index 2aaec972dc..db19feb9ab 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -27,6 +27,7 @@ #include "GLES3Std.h" #include "gfx-base/GFXDevice.h" +#include "gfx-gles-common/GLESCommandPool.h" namespace cc { namespace gfx { @@ -67,6 +68,8 @@ public: void acquire(Swapchain *const *swapchains, uint32_t count) override; void present() override; + inline const GLESBindingMapping &bindingMappings() const { return _bindingMappings; } + inline GLES3GPUContext * context() const { return _gpuContext; } inline GLES3GPUStateCache * stateCache() const { return _gpuStateCache; } inline GLES3GPUFramebufferHub * framebufferHub() const { return _gpuFramebufferHub; } @@ -122,6 +125,8 @@ protected: vector _swapchains; + GLESBindingMapping _bindingMappings; + StringArray _extensions; }; diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index 236d1ecee5..c317623b4e 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -52,7 +52,7 @@ CCMTLCommandBuffer::CCMTLCommandBuffer() _mtlCommandQueue = id(_mtlDevice->getMTLCommandQueue()); _indirectDrawSuppotred = _mtlDevice->isIndirectDrawSupported(); - const auto setCount = _mtlDevice->bindingMappingInfo().bufferOffsets.size(); + const auto setCount = _mtlDevice->bindingMappingInfo().setIndices.size(); _GPUDescriptorSets.resize(setCount); _dynamicOffsets.resize(setCount); _indirectDrawSuppotred = _mtlDevice->isIndirectDrawSupported(); @@ -71,14 +71,14 @@ void CCMTLCommandBuffer::doDestroy() { CC_DELETE(_texCopySemaphore); _texCopySemaphore = nullptr; } - + if(_commandBufferBegan) { if(_gpuCommandBufferObj && _gpuCommandBufferObj->mtlCommandBuffer) { [_gpuCommandBufferObj->mtlCommandBuffer commit]; } _commandBufferBegan = false; } - + _GPUDescriptorSets.clear(); _dynamicOffsets.clear(); _firstDirtyDescriptorSet = UINT_MAX; @@ -146,7 +146,7 @@ void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb if (_gpuCommandBufferObj->isSecondary) { return; } - + _gpuCommandBufferObj->renderPass = static_cast(renderPass); _gpuCommandBufferObj->fbo = static_cast(fbo); @@ -229,7 +229,7 @@ void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb mtlRenderPassDescriptor.colorAttachments[color].storeAction = MTLStoreActionMultisampleResolve; } } - + for (size_t j = 0; j < subpasses[i].preserves.size(); ++j) { uint32_t preserves = subpasses[i].preserves[j]; mtlRenderPassDescriptor.colorAttachments[preserves].storeAction = MTLStoreActionStoreAndMultisampleResolve; @@ -237,7 +237,7 @@ void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb } updateDepthStencilState(ccMtlRenderPass->getCurrentSubpassIndex(), mtlRenderPassDescriptor); } - + mtlRenderPassDescriptor.depthAttachment.clearDepth = clampf(depth, 0.0F, 1.0F); mtlRenderPassDescriptor.stencilAttachment.clearStencil = stencil; @@ -258,7 +258,7 @@ void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb _renderEncoder.initialize(mtlCommandBuffer, mtlRenderPassDescriptor); //[_renderEncoder.getMTLEncoder() memoryBarrierWithScope:MTLBarrierScopeTextures afterStages:MTLRenderStageFragment beforeStages:MTLRenderStageFragment]; } - + if (!renderingFullFramebuffer) { //Metal doesn't apply the viewports and scissors to renderpass load-action clearing. mu::clearRenderArea(_mtlDevice, _renderEncoder.getMTLEncoder(), renderPass, renderArea, colors, depth, stencil); @@ -272,7 +272,7 @@ void CCMTLCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb #endif _renderEncoder.setViewport(scissorArea); _renderEncoder.setScissor(scissorArea); - + if(_firstRenderPass) { _firstRenderPass = false; } @@ -301,7 +301,7 @@ void CCMTLCommandBuffer::updateDepthStencilState(uint32_t index, MTLRenderPassDe CCMTLRenderPass * curRenderPass = _gpuCommandBufferObj->renderPass; CCMTLFramebuffer * curFBO = _gpuCommandBufferObj->fbo; const SubpassInfoList &subpasses = curRenderPass->getSubpasses(); - + const DepthStencilAttachment& dsAttachment = curRenderPass->getDepthStencilAttachment(); const SubpassInfo& subpass = subpasses[index]; if (subpass.depthStencil != INVALID_BINDING) { @@ -359,7 +359,7 @@ void CCMTLCommandBuffer::updateDepthStencilState(uint32_t index, MTLRenderPassDe if (@available(iOS 12.0, *)) { descriptor.stencilAttachment.stencilResolveFilter = mu::toMTLStencilResolveMode(subpass.stencilResolveMode); } - + if(index == subpasses.size() - 1) { descriptor.depthAttachment.storeAction = dsAttachment.depthStoreOp == StoreOp::STORE ? MTLStoreActionStoreAndMultisampleResolve : MTLStoreActionMultisampleResolve; descriptor.stencilAttachment.storeAction = dsAttachment.stencilStoreOp == StoreOp::STORE ? MTLStoreActionStoreAndMultisampleResolve : MTLStoreActionMultisampleResolve; @@ -877,7 +877,7 @@ void CCMTLCommandBuffer::copyTextureToBuffers(Texture *src, uint8_t *const *buff auto * ccMTLTexture = static_cast(src); Format convertedFormat = ccMTLTexture->getConvertedFormat(); id mtlTexture = ccMTLTexture->getMTLTexture(); - + if([mtlTexture storageMode] == MTLStorageModeShared) { for (size_t i = 0; i < count; ++i) { uint32_t width = regions[i].texExtent.width; @@ -897,7 +897,7 @@ void CCMTLCommandBuffer::copyTextureToBuffers(Texture *src, uint8_t *const *buff } } else { id mtlCommandBuffer = getMTLCommandBuffer(); - + std::vector> stagingAddrs(count); for (size_t i = 0; i < count; ++i) { uint32_t width = regions[i].texExtent.width; @@ -927,7 +927,7 @@ void CCMTLCommandBuffer::copyTextureToBuffers(Texture *src, uint8_t *const *buff if(!_texCopySemaphore) { _texCopySemaphore = CC_NEW(CCMTLSemaphore(0)); } - + [mtlCommandBuffer addCompletedHandler:^(id commandBuffer) { for(size_t i = 0; i < count; ++i) { memcpy(buffers[i], stagingAddrs[i].first, stagingAddrs[i].second); diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.mm b/native/cocos/renderer/gfx-metal/MTLUtils.mm index 1b32ae9d66..92f6564481 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/native/cocos/renderer/gfx-metal/MTLUtils.mm @@ -370,7 +370,7 @@ CCMTLGPUPipelineState *getClearRenderPassPipelineState(CCMTLDevice *device, Rend pipelineInfo.shader = createShader(device); pipelineInfo.inputState = {{position}}; pipelineInfo.renderPass = curPass; - + DepthStencilState dsState; dsState.depthWrite = 0; dsState.depthTest = 1; @@ -927,7 +927,6 @@ String mu::spirv2MSL(const uint32_t *ir, size_t word_count, // TODO: bindings from shader just kind of validation, cannot be directly input // Get all uniform buffers in the shader. uint maxBufferBindingIndex = device->getMaximumBufferBindingIndex(); - const auto &bufferBindingOffset = device->bindingMappingInfo().bufferOffsets; for (const auto &ubo : resources.uniform_buffers) { auto set = msl.get_decoration(ubo.id, spv::DecorationDescriptorSet); auto binding = msl.get_decoration(ubo.id, spv::DecorationBinding); @@ -965,7 +964,7 @@ String mu::spirv2MSL(const uint32_t *ir, size_t word_count, if (binding >= maxBufferBindingIndex) { CC_LOG_ERROR("Implementation limits: %s binding at %d, should not use more than %d entries in the buffer argument table", ubo.name.c_str(), binding, maxBufferBindingIndex); } - + uint nameHash = static_cast(std::hash{}(ubo.name)); if (gpuShader->blocks.find(nameHash) == gpuShader->blocks.end()) { auto mappedBinding = gpuShader->bufferIndex; @@ -992,9 +991,6 @@ String mu::spirv2MSL(const uint32_t *ir, size_t word_count, return ""; } - // Get all sampled images in the shader. - const auto &samplerBindingOffset = device->bindingMappingInfo().samplerOffsets; - // avoid conflict index with input attachments. const uint8_t rtOffsets = executionModel == spv::ExecutionModelFragment ? resources.subpass_inputs.size() : 0; for (const auto &sampler : resources.sampled_images) { @@ -1634,7 +1630,7 @@ void mu::clearRenderArea(CCMTLDevice *device, id render const auto gpuPSO = getClearRenderPassPipelineState(device, renderPass); const auto mtlRenderPass = static_cast(renderPass); uint slot = 0u; - + const auto &renderTargetSizes = mtlRenderPass->getRenderTargetSizes(); float renderTargetWidth = renderTargetSizes[slot].x; float renderTargetHeight = renderTargetSizes[slot].y; diff --git a/native/cocos/renderer/gfx-validator/BufferValidator.cpp b/native/cocos/renderer/gfx-validator/BufferValidator.cpp index ea29550b40..854c866837 100644 --- a/native/cocos/renderer/gfx-validator/BufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/BufferValidator.cpp @@ -40,6 +40,8 @@ namespace cc { namespace gfx { +bool BufferValidator::recordInitStack{true}; + BufferValidator::BufferValidator(Buffer *actor) : Agent(actor) { _typedID = actor->getTypedID(); @@ -66,7 +68,7 @@ void BufferValidator::doInit(const BufferInfo &info) { CCASSERT(info.size, "zero-sized buffer?"); CCASSERT(info.size / info.stride * info.stride == info.size, "size is not multiple of stride?"); - _initStack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); + if (recordInitStack) _initStack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); _creationFrame = DeviceValidator::getInstance()->currentFrame(); _totalUpdateTimes = 0U; diff --git a/native/cocos/renderer/gfx-validator/BufferValidator.h b/native/cocos/renderer/gfx-validator/BufferValidator.h index 4d488ded70..bf8ddbc4a6 100644 --- a/native/cocos/renderer/gfx-validator/BufferValidator.h +++ b/native/cocos/renderer/gfx-validator/BufferValidator.h @@ -33,6 +33,8 @@ namespace gfx { class CC_DLL BufferValidator final : public Agent { public: + static bool recordInitStack; + explicit BufferValidator(Buffer *actor); ~BufferValidator() override; diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp index 15ef060fa6..55cdbae47b 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp @@ -58,7 +58,7 @@ void CommandBufferValidator::initValidator() { CCASSERT(!isInited(), "initializing twice?"); _inited = true; - size_t descriptorSetCount = DeviceValidator::getInstance()->bindingMappingInfo().bufferOffsets.size(); + size_t descriptorSetCount = DeviceValidator::getInstance()->bindingMappingInfo().setIndices.size(); _curStates.descriptorSets.resize(descriptorSetCount); _curStates.dynamicOffsets.resize(descriptorSetCount); } @@ -238,7 +238,7 @@ void CommandBufferValidator::bindDescriptorSet(uint32_t set, DescriptorSet *desc CCASSERT(isInited(), "alread destroyed?"); CCASSERT(descriptorSet && static_cast(descriptorSet)->isInited(), "already destroyed?"); - CCASSERT(set < DeviceValidator::getInstance()->bindingMappingInfo().bufferOffsets.size(), "invalid set index"); + CCASSERT(set < DeviceValidator::getInstance()->bindingMappingInfo().setIndices.size(), "invalid set index"); //CCASSERT(descriptorSet->getLayout()->getDynamicBindings().size() == dynamicOffsetCount, "wrong number of dynamic offsets"); // be more lenient on this _curStates.descriptorSets[set] = descriptorSet; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index f133c592d0..985f0f495a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -35,10 +35,8 @@ #include "VKQueue.h" #include "VKRenderPass.h" #include "VKTexture.h" -#include "gfx-base/GFXDef-common.h" #include "states/VKGlobalBarrier.h" #include "states/VKTextureBarrier.h" -#include "vulkan/vulkan_core.h" namespace cc { namespace gfx { @@ -56,7 +54,7 @@ void CCVKCommandBuffer::doInit(const CommandBufferInfo & /*info*/) { _gpuCommandBuffer->level = mapVkCommandBufferLevel(_type); _gpuCommandBuffer->queueFamilyIndex = static_cast(_queue)->gpuQueue()->queueFamilyIndex; - size_t setCount = CCVKDevice::getInstance()->bindingMappingInfo().bufferOffsets.size(); + size_t setCount = CCVKDevice::getInstance()->bindingMappingInfo().setIndices.size(); _curGPUDescriptorSets.resize(setCount); _curVkDescriptorSets.resize(setCount); _curDynamicOffsetsArray.resize(setCount); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index 8476935a60..047d0a0587 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -477,18 +477,14 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende if (subpassInfo.depthStencilResolve != INVALID_BINDING) { Format dsFormat{Format::UNKNOWN}; bool isGeneralLayout{false}; - if (subpassInfo.depthStencil >= colorAttachmentCount) { - const DepthStencilAttachment & desc = gpuRenderPass->depthStencilAttachment; - const VkAttachmentDescription2 &attachment = attachmentDescriptions.back(); - isGeneralLayout = desc.isGeneralLayout; - dsFormat = desc.format; - sampleCount = std::max(sampleCount, attachment.samples); + if (subpassInfo.depthStencilResolve >= colorAttachmentCount) { + const DepthStencilAttachment &desc = gpuRenderPass->depthStencilAttachment; + isGeneralLayout = desc.isGeneralLayout; + dsFormat = desc.format; } else { - const ColorAttachment & desc = gpuRenderPass->colorAttachments[subpassInfo.depthStencil]; - const VkAttachmentDescription2 &attachment = attachmentDescriptions[subpassInfo.depthStencil]; - isGeneralLayout = desc.isGeneralLayout; - dsFormat = desc.format; - sampleCount = std::max(sampleCount, attachment.samples); + const ColorAttachment &desc = gpuRenderPass->colorAttachments[subpassInfo.depthStencilResolve]; + isGeneralLayout = desc.isGeneralLayout; + dsFormat = desc.format; } VkImageAspectFlags aspect = GFX_FORMAT_INFOS[toNumber(dsFormat)].hasStencil @@ -1170,7 +1166,7 @@ void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const } else { for (size_t i = 0; i < drawInfoCount; ++i) { gpuBuffer->indirectCmds[i].vertexCount = drawInfo->vertexCount; - gpuBuffer->indirectCmds[i].instanceCount = drawInfo->instanceCount; + gpuBuffer->indirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1U); gpuBuffer->indirectCmds[i].firstVertex = drawInfo->firstVertex; gpuBuffer->indirectCmds[i].firstInstance = drawInfo->firstInstance; drawInfo++; @@ -1355,7 +1351,7 @@ void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b } void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTexture *srcTexture, CCVKGPUBuffer *destBuffer, - const BufferTextureCopy *regions, uint32_t count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { + const BufferTextureCopy *regions, uint32_t count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { vector &curTypes = srcTexture->currentAccessTypes; ThsvsImageBarrier barrier{}; diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index d7c0e1b3ae..b2b64dd31e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -40,6 +40,7 @@ #include "VKSwapchain.h" #include "VKTexture.h" #include "VKUtils.h" +#include "base/Utils.h" #include "states/VKGlobalBarrier.h" #include "states/VKSampler.h" #include "states/VKTextureBarrier.h" @@ -283,7 +284,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { _caps.maxVertexTextureUnits = limits.maxPerStageDescriptorSampledImages; _caps.maxTextureSize = limits.maxImageDimension2D; _caps.maxCubeMapTextureSize = limits.maxImageDimensionCube; - _caps.uboOffsetAlignment = static_cast(limits.minUniformBufferOffsetAlignment); + _caps.uboOffsetAlignment = utils::toUint(limits.minUniformBufferOffsetAlignment); // compute shaders _caps.maxComputeSharedMemorySize = limits.maxComputeSharedMemorySize; _caps.maxComputeWorkGroupInvocations = limits.maxComputeWorkGroupInvocations; @@ -597,8 +598,9 @@ void CCVKDevice::acquire(Swapchain *const *swapchains, uint32_t count) { for (uint32_t i = 0; i < vkSwapchains.size(); ++i) { VkSemaphore acquireSemaphore = _gpuSemaphorePool->alloc(); - VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, vkSwapchains[i], ~0ULL, - acquireSemaphore, VK_NULL_HANDLE, &vkSwapchainIndices[i])); + VkResult res = vkAcquireNextImageKHR(_gpuDevice->vkDevice, vkSwapchains[i], ~0ULL, + acquireSemaphore, VK_NULL_HANDLE, &vkSwapchainIndices[i]); + CCASSERT(res == VK_SUCCESS || res == VK_SUBOPTIMAL_KHR, "acquire surface failed"); gpuSwapchains[i]->curImageIndex = vkSwapchainIndices[i]; queue->gpuQueue()->lastSignaledSemaphores.push_back(acquireSemaphore); diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index f731e05d9e..65ef3bd57a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -274,8 +274,6 @@ class CCVKGPUShader final : public Object { public: String name; AttributeList attributes; - UniformBlockList blocks; - UniformSamplerList samplers; vector gpuStages; }; @@ -979,6 +977,18 @@ public: } } } + void update(const CCVKGPUTexture *texture) { + for (auto &it : _textures) { + if (it.first->gpuTexture != texture) continue; + const auto &info = it.second; + for (uint32_t i = 0U; i < info.descriptors.size(); i++) { + doUpdate(it.first, info.descriptors[i]); + } + for (const auto *set : info.sets) { + _descriptorSetHub->record(set); + } + } + } void disengage(const CCVKGPUBufferView *buffer) { auto it = _buffers.find(buffer); diff --git a/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp b/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp index fcff56751e..13c27fbe58 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueryPool.cpp @@ -27,7 +27,6 @@ #include "VKCommandBuffer.h" #include "VKCommands.h" #include "VKDevice.h" -#include "vulkan/vulkan_core.h" namespace cc { namespace gfx { diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp index d13243acc9..522a4e7003 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp @@ -29,7 +29,6 @@ #include "VKCommands.h" #include "VKDevice.h" #include "VKQueue.h" -#include "vulkan/vulkan_core.h" namespace cc { namespace gfx { diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.cpp b/native/cocos/renderer/gfx-vulkan/VKShader.cpp index fe47695c04..3dca39c09a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKShader.cpp @@ -44,8 +44,6 @@ void CCVKShader::doInit(const ShaderInfo & /*info*/) { _gpuShader = CC_NEW(CCVKGPUShader); _gpuShader->name = _name; _gpuShader->attributes = _attributes; - _gpuShader->blocks = _blocks; - _gpuShader->samplers = _samplers; for (ShaderStage &stage : _stages) { _gpuShader->gpuStages.push_back({stage.stage, stage.source}); } diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp index ffb73e8493..677e956b65 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp @@ -126,6 +126,7 @@ void CCVKTexture::doResize(uint32_t width, uint32_t height, uint32_t size) { cmdFuncCCVKCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); CCVKDevice::getInstance()->gpuFramebufferHub()->update(_gpuTexture); + CCVKDevice::getInstance()->gpuDescriptorHub()->update(_gpuTexture); } ///////////////////////////// Swapchain Specific ///////////////////////////// diff --git a/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp b/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp index 3de225d47b..025bb4334b 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp @@ -24,7 +24,7 @@ ****************************************************************************/ #include "VKGlobalBarrier.h" -#include "../VKCommands.h" +#include "../VKGPUObjects.h" namespace cc { namespace gfx { diff --git a/native/cocos/renderer/pipeline/Define.cpp b/native/cocos/renderer/pipeline/Define.cpp index 9515482b48..fd65fc993c 100644 --- a/native/cocos/renderer/pipeline/Define.cpp +++ b/native/cocos/renderer/pipeline/Define.cpp @@ -30,20 +30,25 @@ namespace cc { namespace pipeline { -int globalUBOCount = static_cast(PipelineGlobalBindings::SAMPLER_SHADOWMAP); -int globalSamplerCount = static_cast(PipelineGlobalBindings::COUNT) - globalUBOCount; +static uint32_t globalUBOCount = static_cast(PipelineGlobalBindings::SAMPLER_SHADOWMAP); +static uint32_t globalSamplerCount = static_cast(PipelineGlobalBindings::COUNT) - globalUBOCount; -int localUBOCount = static_cast(ModelLocalBindings::SAMPLER_JOINTS); -int localSamplerCount = static_cast(ModelLocalBindings::COUNT) - localUBOCount; +static uint32_t localUBOCount = static_cast(ModelLocalBindings::SAMPLER_JOINTS); +static uint32_t localSamplerCount = static_cast(ModelLocalBindings::COUNT) - localUBOCount; uint globalSet = static_cast(SetIndex::GLOBAL); uint materialSet = static_cast(SetIndex::MATERIAL); uint localSet = static_cast(SetIndex::LOCAL); gfx::BindingMappingInfo bindingMappingInfo = { - {0, globalUBOCount + localUBOCount, globalUBOCount}, - {-globalUBOCount, globalSamplerCount + localSamplerCount, globalSamplerCount - localUBOCount}, - 1, + {globalUBOCount, 0, localUBOCount}, // Uniform Buffer Counts + {globalSamplerCount, 0, localSamplerCount}, // Combined Sampler Texture Counts + {0, 0, 0}, // Sampler Counts + {0, 0, 0}, // Texture Counts + {0, 0, 0}, // Storage Buffer Counts + {0, 0, 0}, // Storage Image Counts + {0, 0, 0}, // Subpass Input Counts + {0, 2, 1}, // Set Order Indices }; DescriptorSetLayoutInfos globalDescriptorSetLayout; diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index b184b0fce5..6102f078be 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -222,9 +222,6 @@ enum class CC_DLL PipelineGlobalBindings { }; CC_ENUM_CONVERSION_OPERATOR(PipelineGlobalBindings) -extern CC_DLL int globalUBOCount; -extern CC_DLL int globalSamplerCount; - enum class CC_DLL ModelLocalBindings { UBO_LOCAL, UBO_FORWARD_LIGHTS, @@ -246,9 +243,6 @@ enum class CC_DLL ModelLocalBindings { }; CC_ENUM_CONVERSION_OPERATOR(ModelLocalBindings) -extern CC_DLL int localUBOCount; -extern CC_DLL int localSamplerCount; - enum class CC_DLL SetIndex { GLOBAL, MATERIAL, diff --git a/native/tools/bindings-generator/generator.py b/native/tools/bindings-generator/generator.py index 031e37a78f..9b70aae8fc 100755 --- a/native/tools/bindings-generator/generator.py +++ b/native/tools/bindings-generator/generator.py @@ -1153,7 +1153,7 @@ class NativeClass(object): def generate_struct_constructor(self): stream = open(os.path.join(self.generator.target, "conversions.yaml"), "r") - config = yaml.load(stream) + config = yaml.safe_load(stream) tpl = Template(config['definitions']['constructor'], searchList=[self]) self.struct_constructor_name = str(tpl) @@ -1585,7 +1585,7 @@ class Generator(object): return False def should_skip_public_field(self, class_name, field_name, verbose=False): - + if class_name == "*" and "*" in self.skip_public_fields_classes: for func in self.skip_public_fields_classes["*"]: if re.match(func, field_name): @@ -1697,7 +1697,7 @@ class Generator(object): def generate_code(self): # must read the yaml file first stream = open(os.path.join(self.target, "conversions.yaml"), "r") - data = yaml.load(stream) + data = yaml.safe_load(stream) self.config = data implfilepath = os.path.join(self.outdir, self.out_file + ".cpp") headfilepath = os.path.join(self.outdir, self.out_file + ".h") diff --git a/native/tools/gfx-define-generator/generate.js b/native/tools/gfx-define-generator/generate.js index aae8ea8081..1faf4070ab 100644 --- a/native/tools/gfx-define-generator/generate.js +++ b/native/tools/gfx-define-generator/generate.js @@ -72,12 +72,19 @@ while (enumCap) { enumCap = enumRE.exec(header); } -// now discard all block comments -header = header.replace(/\/\*.*?\*\//gs, ''); -header = header.replace(/\s*[*&](.)/g, (_, c) => (c === '>' ? '' : ' ') + c); -header = header.replace(/(?:\w*::)?vector<(.+?)>/g, '$1[]'); -// and preprocessors +// save & strip block comments +const blockComments = []; +const blockCommentsRE = /(\/\*\*.*?\*\/)\s*(.+?\n)/gs; +header = header.replace(blockCommentsRE, (_, comments, succeeding) => { + blockComments.push({ succeeding, source: comments }); + return succeeding; +}); +// discard preprocessors header = header.replace(/\s*#(if|else|elif|end).*/gm, ''); +// replace vector +header = header.replace(/(?:\w*::)?vector<(.+?)>/g, (_, type) => { + return `${type.replace(/[*\s]+/g, '')}[]`; +}); const typedefRE = /^\s*using\s+(.+?)\s*=\s*(.+?);/gsm; const typedefMap = { lists: {}, others: [] }; @@ -124,7 +131,7 @@ const getMemberList = (() => { }; })(); -const structRE = /(struct\s+(?:\w+\(\w+\)\s+)?)(\w+).*?{\s*(.+?)\s*};/gs; +const structRE = /(struct\s+(?:\w+\(\w+\)\s+)?(\w+).*?){\s*.+?\s*};/gs; const structMemberRE = /^\s*(const\w*\s*)?([\w[\]]+)\s+?(\w+)(?:\s*[={]?\s*(.*?)\s*}*\s*)?;(?:\s*\/\/\s*@ts-(.*?)$)?/gm; const structMap = {}; const replaceConstants = (() => { @@ -153,9 +160,13 @@ const getArrayValue = (decayedType, value) => { let structCap = structRE.exec(header); while (structCap) { const struct = structMap[structCap[2]] = {}; + struct.comments = blockComments.find((c) => structCap[0].startsWith(c.succeeding))?.source; + struct.member = {}; // structRE can not reliably extract the correct member declaration range - const memberList = getMemberList(header, structCap.index + structCap[1].length); + let memberList = getMemberList(header, structCap.index + structCap[1].length); + // discard pointer signs + memberList = memberList.replace(/\*/g, ''); let memberCap = structMemberRE.exec(memberList); while (memberCap) { @@ -178,6 +189,7 @@ while (structCap) { let n = Number.parseInt(value); if (!Number.isNaN(n)) { if (!value.startsWith('0x')) { value = n; } // keep hexadecimal numbers + if (isArray) { value = `[${value}]`; } } else if (value) { value = replaceConstants(value); if (isArray) { value = getArrayValue(decayedType, value); } @@ -242,12 +254,13 @@ output += `\n`; for (const name of Object.keys(structMap)) { if (name in ignoreList) { continue; } + const struct = structMap[name]; + if (struct.comments) { output += struct.comments + '\n'; } output += `export class ${name} {\n declare private _token: never; `; output += `// to make sure all usages must be an instance of this exact class, not assembled from plain object`; output += `\n\n constructor (\n`; - const struct = structMap[name]; for (const key in struct.member) { const { readonly, type, value } = struct.member[key]; const decl = readonly ? `readonly ${key}` : key;