From ea3be6000fc970ec2e95295787981f8ee9e28521 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Fri, 17 Jul 2020 13:55:42 +0800 Subject: [PATCH] vk: async submission (#2647) --- .../renderer/core/gfx/GFXCommandBuffer.h | 4 +- native/cocos/renderer/core/gfx/GFXDef.h | 27 +- native/cocos/renderer/core/gfx/GFXDevice.h | 6 +- native/cocos/renderer/core/gfx/GFXTexture.h | 18 +- .../renderer/gfx-gles2/GLES2CommandBuffer.cc | 27 +- .../renderer/gfx-gles2/GLES2CommandBuffer.h | 4 +- .../cocos/renderer/gfx-gles2/GLES2Commands.cc | 56 +- .../cocos/renderer/gfx-gles2/GLES2Commands.h | 19 +- .../cocos/renderer/gfx-gles2/GLES2Device.cc | 4 +- native/cocos/renderer/gfx-gles2/GLES2Device.h | 2 +- .../renderer/gfx-gles2/GLES2InputAssembler.cc | 14 +- .../cocos/renderer/gfx-gles2/GLES2Texture.cc | 8 +- .../renderer/gfx-gles3/GLES3CommandBuffer.cc | 27 +- .../renderer/gfx-gles3/GLES3CommandBuffer.h | 4 +- .../cocos/renderer/gfx-gles3/GLES3Commands.cc | 54 +- .../cocos/renderer/gfx-gles3/GLES3Commands.h | 19 +- .../cocos/renderer/gfx-gles3/GLES3Device.cc | 5 +- native/cocos/renderer/gfx-gles3/GLES3Device.h | 2 +- .../renderer/gfx-gles3/GLES3InputAssembler.cc | 14 +- .../cocos/renderer/gfx-gles3/GLES3Texture.cc | 8 +- .../renderer/gfx-metal/MTLCommandBuffer.h | 4 +- .../renderer/gfx-metal/MTLCommandBuffer.mm | 11 +- native/cocos/renderer/gfx-metal/MTLDevice.h | 2 +- native/cocos/renderer/gfx-metal/MTLDevice.mm | 6 +- native/cocos/renderer/gfx-metal/MTLTexture.h | 2 +- native/cocos/renderer/gfx-metal/MTLTexture.mm | 26 +- native/cocos/renderer/gfx-metal/MTLUtils.h | 4 +- native/cocos/renderer/gfx-metal/MTLUtils.mm | 8 +- native/cocos/renderer/gfx-vulkan/VKBuffer.cc | 6 +- .../renderer/gfx-vulkan/VKCommandBuffer.cc | 6 +- .../renderer/gfx-vulkan/VKCommandBuffer.h | 4 +- .../cocos/renderer/gfx-vulkan/VKCommands.cc | 840 +++++++++--------- native/cocos/renderer/gfx-vulkan/VKCommands.h | 26 +- native/cocos/renderer/gfx-vulkan/VKDevice.cc | 70 +- native/cocos/renderer/gfx-vulkan/VKDevice.h | 37 +- native/cocos/renderer/gfx-vulkan/VKFence.cc | 12 +- .../renderer/gfx-vulkan/VKFramebuffer.cc | 3 +- .../cocos/renderer/gfx-vulkan/VKGPUObjects.h | 318 +++++-- .../renderer/gfx-vulkan/VKInputAssembler.cc | 20 +- .../renderer/gfx-vulkan/VKPipelineState.cc | 4 +- native/cocos/renderer/gfx-vulkan/VKQueue.cc | 24 +- .../cocos/renderer/gfx-vulkan/VKRenderPass.cc | 4 +- native/cocos/renderer/gfx-vulkan/VKSampler.cc | 4 +- native/cocos/renderer/gfx-vulkan/VKShader.cc | 4 +- native/cocos/renderer/gfx-vulkan/VKTexture.cc | 83 +- native/cocos/renderer/gfx-vulkan/VKTexture.h | 2 +- .../js-bindings/auto/jsb_gfx_auto.cpp | 149 +--- .../js-bindings/auto/jsb_gfx_auto.hpp | 1 - .../js-bindings/manual/jsb_gfx_manual.cpp | 634 ++++++------- native/external/config.json | 4 +- native/tools/tojs/gfx.ini | 6 +- native/tools/tojs/vulkan.ini | 2 +- 52 files changed, 1338 insertions(+), 1310 deletions(-) diff --git a/native/cocos/renderer/core/gfx/GFXCommandBuffer.h b/native/cocos/renderer/core/gfx/GFXCommandBuffer.h index 3eb573978d..41908be6ed 100755 --- a/native/cocos/renderer/core/gfx/GFXCommandBuffer.h +++ b/native/cocos/renderer/core/gfx/GFXCommandBuffer.h @@ -31,8 +31,8 @@ public: virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) = 0; virtual void draw(InputAssembler *ia) = 0; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset = 0) = 0; - virtual void copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) = 0; - virtual void execute(const vector &cmd_buffs, uint32_t count) = 0; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) = 0; + virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) = 0; CC_INLINE Device *getDevice() const { return _device; } CC_INLINE Queue *getQueue() const { return _queue; } diff --git a/native/cocos/renderer/core/gfx/GFXDef.h b/native/cocos/renderer/core/gfx/GFXDef.h index c77fa2f4e4..9bcf5f3066 100755 --- a/native/cocos/renderer/core/gfx/GFXDef.h +++ b/native/cocos/renderer/core/gfx/GFXDef.h @@ -40,11 +40,9 @@ enum class ObjectType : uint8_t { PIPELINE_STATE, BINDING_LAYOUT, INPUT_ASSEMBLER, - COMMAND_ALLOCATOR, COMMAND_BUFFER, FENCE, QUEUE, - WINDOW, }; enum class Status : uint8_t { @@ -610,10 +608,7 @@ struct BufferTextureCopy { TextureSubres texSubres; }; typedef vector BufferTextureCopyList; - -struct DataArray { - vector datas; -}; +typedef vector BufferDataList; struct Viewport { int left = 0; @@ -709,11 +704,11 @@ struct TextureInfo { TextureType type = TextureType::TEX2D; TextureUsage usage = TextureUsageBit::NONE; Format format = Format::UNKNOWN; - uint width = 0; - uint height = 0; - uint depth = 1; - uint arrayLayer = 1; - uint mipLevel = 1; + uint width = 0u; + uint height = 0u; + uint depth = 1u; + uint layerCount = 1u; + uint levelCount = 1u; SampleCount samples = SampleCount::X1; TextureFlags flags = TextureFlagBit::NONE; }; @@ -722,10 +717,10 @@ struct TextureViewInfo { Texture *texture = nullptr; TextureType type = TextureType::TEX2D; Format format = Format::UNKNOWN; - uint baseLevel = 0; - uint levelCount = 1; - uint baseLayer = 0; - uint layerCount = 1; + uint baseLevel = 0u; + uint levelCount = 1u; + uint baseLayer = 0u; + uint layerCount = 1u; }; struct SamplerInfo { @@ -966,10 +961,10 @@ struct CommandBufferInfo { Queue *queue = nullptr; CommandBufferType type = CommandBufferType::PRIMARY; }; +typedef vector CommandBufferList; struct QueueInfo { QueueType type = QueueType::GRAPHICS; - bool forceSync = false; }; struct FenceInfo { diff --git a/native/cocos/renderer/core/gfx/GFXDevice.h b/native/cocos/renderer/core/gfx/GFXDevice.h index e2b07a686b..e9f713c8fb 100755 --- a/native/cocos/renderer/core/gfx/GFXDevice.h +++ b/native/cocos/renderer/core/gfx/GFXDevice.h @@ -30,7 +30,7 @@ public: virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) = 0; virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) = 0; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) = 0; - virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) = 0; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) = 0; CC_INLINE API getGfxAPI() const { return _API; } CC_INLINE const String &getDeviceName() const { return _deviceName; } @@ -63,7 +63,7 @@ public: CC_INLINE bool hasFeature(Feature feature) const { return _features[static_cast(feature)]; } CC_INLINE void defineMacro(const String ¯o, const String &value) { _macros[macro] = value; } CC_INLINE float getClipSpaceMinZ() const { return _clipSpaceMinZ; } - CC_INLINE float getClipSpaceSignY() const { return _clipSpaceSignY; } + CC_INLINE float getScreenSpaceSignY() const { return _screenSpaceSignY; } CC_INLINE float getUVSpaceSignY() const { return _UVSpaceSignY; } protected: @@ -98,7 +98,7 @@ protected: uint _shaderIdGen = 0; unordered_map _macros; float _clipSpaceMinZ = -1.0f; - float _clipSpaceSignY = 1.0f; + float _screenSpaceSignY = 1.0f; float _UVSpaceSignY = -1.0f; }; // namespace gfx diff --git a/native/cocos/renderer/core/gfx/GFXTexture.h b/native/cocos/renderer/core/gfx/GFXTexture.h index 832724106d..31fa9fc72a 100755 --- a/native/cocos/renderer/core/gfx/GFXTexture.h +++ b/native/cocos/renderer/core/gfx/GFXTexture.h @@ -23,8 +23,8 @@ public: CC_INLINE uint getWidth() const { return _width; } CC_INLINE uint getHeight() const { return _height; } CC_INLINE uint getDepth() const { return _depth; } - CC_INLINE uint getArrayLayer() const { return _arrayLayer; } - CC_INLINE uint getMipLevel() const { return _mipLevel; } + CC_INLINE uint getLayerCount() const { return _layerCount; } + CC_INLINE uint getLevelCount() const { return _levelCount; } CC_INLINE uint getSize() const { return _size; } CC_INLINE SampleCount getSamples() const { return _samples; } CC_INLINE TextureFlags getFlags() const { return _flags; } @@ -35,12 +35,14 @@ protected: TextureType _type = TextureType::TEX2D; TextureUsage _usage = TextureUsageBit::NONE; Format _format = Format::UNKNOWN; - uint _width = 0; - uint _height = 0; - uint _depth = 1; - uint _arrayLayer = 1; - uint _mipLevel = 1; - uint _size = 0; + uint _width = 0u; + uint _height = 0u; + uint _depth = 1u; + uint _baseLevel = 0u; + uint _levelCount = 1u; + uint _baseLayer = 0u; + uint _layerCount = 1u; + uint _size = 0u; SampleCount _samples = SampleCount::X1; TextureFlags _flags = TextureFlagBit::NONE; uint8_t *_buffer = nullptr; diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc index 19fe74b46c..714509fb81 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc @@ -152,10 +152,10 @@ void GLES2CommandBuffer::setBlendConstants(const Color &constants) { } void GLES2CommandBuffer::setDepthBound(float min_bounds, float max_bounds) { - if (math::IsNotEqualF(_curDepthBounds.min_bounds, min_bounds) || - math::IsNotEqualF(_curDepthBounds.max_bounds, max_bounds)) { - _curDepthBounds.min_bounds = min_bounds; - _curDepthBounds.max_bounds = max_bounds; + if (math::IsNotEqualF(_curDepthBounds.minBounds, min_bounds) || + math::IsNotEqualF(_curDepthBounds.maxBounds, max_bounds)) { + _curDepthBounds.minBounds = min_bounds; + _curDepthBounds.maxBounds = max_bounds; _isStateInvalid = true; } } @@ -172,10 +172,10 @@ void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { void GLES2CommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint mask) { if ((_curStencilCompareMask.face != face) || (_curStencilCompareMask.refrence != ref) || - (_curStencilCompareMask.compare_mask != mask)) { + (_curStencilCompareMask.compareMask != mask)) { _curStencilCompareMask.face = face; _curStencilCompareMask.refrence = ref; - _curStencilCompareMask.compare_mask = mask; + _curStencilCompareMask.compareMask = mask; _isStateInvalid = true; } } @@ -237,18 +237,17 @@ void GLES2CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint } } -void GLES2CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) { +void GLES2CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) || (_type == CommandBufferType::SECONDARY)) { - GLES2GPUBuffer *gpuBuffer = ((GLES2Buffer *)src)->gpuBuffer(); - GLES2GPUTexture *gpuTexture = ((GLES2Texture *)dst)->gpuTexture(); - if (gpuBuffer && gpuTexture) { + GLES2GPUTexture *gpuTexture = ((GLES2Texture *)texture)->gpuTexture(); + if (gpuTexture) { GLES2CmdCopyBufferToTexture *cmd = _gles2Allocator->copyBufferToTextureCmdPool.alloc(); - cmd->gpuBuffer = gpuBuffer; cmd->gpuTexture = gpuTexture; - cmd->dst_layout = layout; + cmd->buffers.resize(buffers.size()); cmd->regions.resize(regions.size()); for (uint i = 0; i < static_cast(regions.size()); ++i) { + cmd->buffers[i] = buffers[i]; cmd->regions[i] = regions[i]; } @@ -256,11 +255,11 @@ void GLES2CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureL _cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE); } } else { - CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded outside a render pass."); + CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass."); } } -void GLES2CommandBuffer::execute(const vector &cmd_buffs, uint32_t count) { +void GLES2CommandBuffer::execute(const CommandBufferList &cmd_buffs, uint32_t count) { for (uint i = 0; i < count; ++i) { GLES2CommandBuffer *cmd_buff = (GLES2CommandBuffer *)cmd_buffs[i]; diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h index 3781a3a263..e17ca29ab6 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h @@ -36,8 +36,8 @@ public: virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; virtual void draw(InputAssembler *ia) override; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override; - virtual void copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) override; - virtual void execute(const vector &cmd_buffs, uint32_t count) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override; + virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override; private: void BindStates(); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.cc b/native/cocos/renderer/gfx-gles2/GLES2Commands.cc index d25eb0b78c..b696afde0a 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.cc +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.cc @@ -1,9 +1,9 @@ #include "GLES2Std.h" #include "GLES2Commands.h" +#include "GLES2Context.h" #include "GLES2Device.h" #include "GLES2StateCache.h" -#include "GLES2Context.h" #define BUFFER_OFFSET(idx) (static_cast(0) + (idx)) @@ -1999,43 +1999,43 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { switch (cmd->stencilCompareMask.face) { case StencilFace::FRONT: if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask)) { + (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask)) { glStencilFuncSeparate(GL_FRONT, GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncFront], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask; } break; case StencilFace::BACK: if ((cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) { + (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) { glStencilFuncSeparate(GL_BACK, GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncBack], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask; } break; case StencilFace::ALL: if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask) || + (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask) || (cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) { + (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) { glStencilFuncSeparate(GL_FRONT, GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncFront], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); glStencilFuncSeparate(GL_BACK, GLES2_CMP_FUNCS[(uint)cache->dss.stencilFuncBack], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask; cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask; } break; } @@ -2053,22 +2053,22 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { if (gpuInputAssembler && gpuPipelineState) { if (!gpuInputAssembler->gpuIndirectBuffer) { - if (gpuInputAssembler->gpuIndexBuffer && cmd->draw_info.indexCount >= 0) { + if (gpuInputAssembler->gpuIndexBuffer && cmd->drawInfo.indexCount >= 0) { uint8_t *offset = 0; - offset += cmd->draw_info.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; - if (cmd->draw_info.instanceCount == 0) { - glDrawElements(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset); + 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->draw_info.indexCount, gpuInputAssembler->glIndexType, offset, cmd->draw_info.instanceCount); + glDrawElementsInstancedEXT(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount); } } } else { - if (cmd->draw_info.instanceCount == 0) { - glDrawArrays(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount); + if (cmd->drawInfo.instanceCount == 0) { + glDrawArrays(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount); } else { if (device->useDrawInstanced()) { - glDrawArraysInstancedEXT(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount, cmd->draw_info.instanceCount); + glDrawArraysInstancedEXT(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount, cmd->drawInfo.instanceCount); } } } @@ -2078,7 +2078,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { if (gpuInputAssembler->gpuIndexBuffer && draw.indexCount >= 0) { uint8_t *offset = 0; offset += draw.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; - if (cmd->draw_info.instanceCount == 0) { + if (cmd->drawInfo.instanceCount == 0) { glDrawElements(glPrimitive, draw.indexCount, gpuInputAssembler->glIndexType, offset); } else { if (device->useDrawInstanced()) { @@ -2106,7 +2106,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } case GFXCmdType::COPY_BUFFER_TO_TEXTURE: { GLES2CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES2CmdFuncCopyBuffersToTexture(device, &cmd->gpuBuffer->buffer, cmd->gpuTexture, cmd->regions); + GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions); break; } default: @@ -2116,7 +2116,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { } } -void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { +void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint]; if (glTexture != gpuTexture->glTexture) { glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture); @@ -2134,7 +2134,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage2D(GL_TEXTURE_2D, @@ -2169,7 +2169,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe for (uint z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage3DOES(GL_TEXTURE_2D_ARRAY, @@ -2204,7 +2204,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe w = region.texExtent.width; h = region.texExtent.height; d = region.texExtent.depth; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, d + 1, 1); glCompressedTexSubImage3DOES(GL_TEXTURE_3D, @@ -2240,7 +2240,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffe for (f = region.texSubres.baseArrayLayer; f < face_count; ++f) { w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.h b/native/cocos/renderer/gfx-gles2/GLES2Commands.h index 0bb70fd54e..687ce517e5 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.h @@ -15,8 +15,8 @@ struct GLES2DepthBias { }; struct GLES2DepthBounds { - float min_bounds = 0.0f; - float max_bounds = 0.0f; + float minBounds = 0.0f; + float maxBounds = 0.0f; }; struct GLES2StencilWriteMask { @@ -27,7 +27,7 @@ struct GLES2StencilWriteMask { struct GLES2StencilCompareMask { StencilFace face = StencilFace::FRONT; int refrence = 0; - uint compare_mask = 0; + uint compareMask = 0; }; struct GLES2TextureSubres { @@ -81,7 +81,7 @@ public: GLES2GPUPipelineState *gpuPipelineState = nullptr; GLES2GPUBindingLayout *gpuBindingLayout = nullptr; GLES2GPUInputAssembler *gpuInputAssembler = nullptr; - uint8_t state_flags[(int)GLES2State::COUNT] = {0}; + uint8_t stateFlags[(int)GLES2State::COUNT] = {0}; Viewport viewport; Rect scissor; float lineWidth = 1.0f; @@ -98,13 +98,13 @@ public: gpuPipelineState = nullptr; gpuBindingLayout = nullptr; gpuInputAssembler = nullptr; - memset(state_flags, 0, sizeof(state_flags)); + memset(stateFlags, 0, sizeof(stateFlags)); } }; class GLES2CmdDraw : public GFXCmd { public: - DrawInfo draw_info; + DrawInfo drawInfo; GLES2CmdDraw() : GFXCmd(GFXCmdType::DRAW) {} virtual void clear() override {} @@ -127,16 +127,15 @@ public: class GLES2CmdCopyBufferToTexture : public GFXCmd { public: - GLES2GPUBuffer *gpuBuffer = nullptr; GLES2GPUTexture *gpuTexture = nullptr; - TextureLayout dst_layout; + BufferDataList buffers; BufferTextureCopyList regions; GLES2CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {} virtual void clear() override { - gpuBuffer = nullptr; gpuTexture = nullptr; + buffers.clear(); regions.clear(); } }; @@ -167,7 +166,7 @@ CC_GLES2_API void GLES2CmdFuncDestroyInputAssembler(GLES2Device *device, GLES2GP CC_GLES2_API void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); CC_GLES2_API void GLES2CmdFuncDestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); CC_GLES2_API void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmd_package); -CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions); +CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList ®ions); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cc b/native/cocos/renderer/gfx-gles2/GLES2Device.cc index 2999294da0..9259c96ac4 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cc +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cc @@ -282,8 +282,8 @@ PipelineState *GLES2Device::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void GLES2Device::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - GLES2CmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((GLES2Texture *)dst)->gpuTexture(), regions); +void GLES2Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { + GLES2CmdFuncCopyBuffersToTexture(this, buffers, ((GLES2Texture *)dst)->gpuTexture(), regions); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index 4c1660d038..f37e7e96ad 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -33,7 +33,7 @@ public: virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; CC_INLINE bool useVAO() const { return _useVAO; } CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cc b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cc index b3b7bed273..55c33bd660 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cc +++ b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cc @@ -56,13 +56,13 @@ void GLES2InputAssembler::destroy() { } void GLES2InputAssembler::ExtractCmdDraw(GLES2CmdDraw *cmd) { - cmd->draw_info.vertexCount = _vertexCount; - cmd->draw_info.firstVertex = _firstVertex; - cmd->draw_info.indexCount = _indexCount; - cmd->draw_info.firstIndex = _firstIndex; - cmd->draw_info.vertexOffset = _vertexOffset; - cmd->draw_info.instanceCount = _instanceCount; - cmd->draw_info.firstInstance = _firstInstance; + cmd->drawInfo.vertexCount = _vertexCount; + cmd->drawInfo.firstVertex = _firstVertex; + cmd->drawInfo.indexCount = _indexCount; + cmd->drawInfo.firstIndex = _firstIndex; + cmd->drawInfo.vertexOffset = _vertexOffset; + cmd->drawInfo.instanceCount = _instanceCount; + cmd->drawInfo.firstInstance = _firstInstance; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.cc b/native/cocos/renderer/gfx-gles2/GLES2Texture.cc index 8e5ddce50a..081adae01e 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.cc +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.cc @@ -21,8 +21,8 @@ bool GLES2Texture::initialize(const TextureInfo &info) { _width = info.width; _height = info.height; _depth = info.depth; - _arrayLayer = info.arrayLayer; - _mipLevel = info.mipLevel; + _layerCount = info.layerCount; + _levelCount = info.levelCount; _samples = info.samples; _flags = info.flags; _size = FormatSize(_format, _width, _height, _depth); @@ -83,8 +83,8 @@ bool GLES2Texture::initialize(const TextureInfo &info) { _gpuTexture->height = _height; _gpuTexture->depth = _depth; _gpuTexture->size = _size; - _gpuTexture->arrayLayer = _arrayLayer; - _gpuTexture->mipLevel = _mipLevel; + _gpuTexture->arrayLayer = _layerCount; + _gpuTexture->mipLevel = _levelCount; _gpuTexture->samples = _samples; _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc index 3b8791e7b8..2f8b3e45a6 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc @@ -156,11 +156,11 @@ void GLES3CommandBuffer::setBlendConstants(const Color &constants) { } void GLES3CommandBuffer::setDepthBound(float min_bounds, float max_bounds) { - if (math::IsNotEqualF(_curDepthBounds.min_bounds, min_bounds) || - math::IsNotEqualF(_curDepthBounds.max_bounds, max_bounds)) { + if (math::IsNotEqualF(_curDepthBounds.minBounds, min_bounds) || + math::IsNotEqualF(_curDepthBounds.maxBounds, max_bounds)) { - _curDepthBounds.min_bounds = min_bounds; - _curDepthBounds.max_bounds = max_bounds; + _curDepthBounds.minBounds = min_bounds; + _curDepthBounds.maxBounds = max_bounds; _isStateInvalid = true; } } @@ -178,11 +178,11 @@ void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { void GLES3CommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint mask) { if ((_curStencilCompareMask.face != face) || (_curStencilCompareMask.refrence != ref) || - (_curStencilCompareMask.compare_mask != mask)) { + (_curStencilCompareMask.compareMask != mask)) { _curStencilCompareMask.face = face; _curStencilCompareMask.refrence = ref; - _curStencilCompareMask.compare_mask = mask; + _curStencilCompareMask.compareMask = mask; _isStateInvalid = true; } } @@ -242,19 +242,18 @@ void GLES3CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint } } -void GLES3CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) { +void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) || (_type == CommandBufferType::SECONDARY)) { - GLES3GPUBuffer *gpuBuffer = ((GLES3Buffer *)src)->gpuBuffer(); - GLES3GPUTexture *gpuTexture = ((GLES3Texture *)dst)->gpuTexture(); - if (gpuBuffer && gpuTexture) { + GLES3GPUTexture *gpuTexture = ((GLES3Texture *)texture)->gpuTexture(); + if (gpuTexture) { GLES3CmdCopyBufferToTexture *cmd = _gles3Allocator->copyBufferToTextureCmdPool.alloc(); - cmd->gpuBuffer = gpuBuffer; cmd->gpuTexture = gpuTexture; - cmd->dst_layout = layout; + cmd->buffers.resize(buffers.size()); cmd->regions.resize(regions.size()); for (uint i = 0; i < static_cast(regions.size()); ++i) { + cmd->buffers[i] = buffers[i]; cmd->regions[i] = regions[i]; } @@ -262,11 +261,11 @@ void GLES3CommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureL _cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE); } } else { - CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded outside a render pass."); + CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass."); } } -void GLES3CommandBuffer::execute(const vector &cmd_buffs, uint32_t count) { +void GLES3CommandBuffer::execute(const CommandBufferList &cmd_buffs, uint32_t count) { for (uint i = 0; i < count; ++i) { GLES3CommandBuffer *cmd_buff = (GLES3CommandBuffer *)cmd_buffs[i]; diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index b882715cc8..94f0f3c1df 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -36,8 +36,8 @@ public: virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; virtual void draw(InputAssembler *ia) override; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override; - virtual void copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) override; - virtual void execute(const vector &cmd_buffs, uint32_t count) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override; + virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override; private: void BindStates(); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cc b/native/cocos/renderer/gfx-gles3/GLES3Commands.cc index aea739c8c7..55118a3d73 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cc +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cc @@ -1,9 +1,9 @@ #include "GLES3Std.h" #include "GLES3Commands.h" +#include "GLES3Context.h" #include "GLES3Device.h" #include "GLES3StateCache.h" -#include "GLES3Context.h" #define BUFFER_OFFSET(idx) (static_cast(0) + (idx)) @@ -1972,43 +1972,43 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { switch (cmd->stencilCompareMask.face) { case StencilFace::FRONT: if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask)) { + (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask)) { glStencilFuncSeparate(GL_FRONT, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask; } break; case StencilFace::BACK: if ((cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) { + (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) { glStencilFuncSeparate(GL_BACK, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask; } break; case StencilFace::ALL: if ((cache->dss.stencilRefFront != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compare_mask) || + (cache->dss.stencilReadMaskFront != cmd->stencilCompareMask.compareMask) || (cache->dss.stencilRefBack != (uint)cmd->stencilCompareMask.refrence) || - (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compare_mask)) { + (cache->dss.stencilReadMaskBack != cmd->stencilCompareMask.compareMask)) { glStencilFuncSeparate(GL_FRONT, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncFront], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); glStencilFuncSeparate(GL_BACK, GLES3_CMP_FUNCS[(int)cache->dss.stencilFuncBack], cmd->stencilCompareMask.refrence, - cmd->stencilCompareMask.compare_mask); + cmd->stencilCompareMask.compareMask); cache->dss.stencilRefFront = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskFront = cmd->stencilCompareMask.compareMask; cache->dss.stencilRefBack = cmd->stencilCompareMask.refrence; - cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compare_mask; + cache->dss.stencilReadMaskBack = cmd->stencilCompareMask.compareMask; } break; } @@ -2025,19 +2025,19 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { GLES3CmdDraw *cmd = cmdPackage->drawCmds[cmdIdx]; if (gpuInputAssembler && gpuPipelineState) { if (!gpuInputAssembler->gpuIndirectBuffer) { - if (gpuInputAssembler->gpuIndexBuffer && cmd->draw_info.indexCount >= 0) { + if (gpuInputAssembler->gpuIndexBuffer && cmd->drawInfo.indexCount >= 0) { uint8_t *offset = 0; - offset += cmd->draw_info.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; - if (cmd->draw_info.instanceCount == 0) { - glDrawElements(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset); + offset += cmd->drawInfo.firstIndex * gpuInputAssembler->gpuIndexBuffer->stride; + if (cmd->drawInfo.instanceCount == 0) { + glDrawElements(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset); } else { - glDrawElementsInstanced(glPrimitive, cmd->draw_info.indexCount, gpuInputAssembler->glIndexType, offset, cmd->draw_info.instanceCount); + glDrawElementsInstanced(glPrimitive, cmd->drawInfo.indexCount, gpuInputAssembler->glIndexType, offset, cmd->drawInfo.instanceCount); } } else { - if (cmd->draw_info.instanceCount == 0) { - glDrawArrays(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount); + if (cmd->drawInfo.instanceCount == 0) { + glDrawArrays(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount); } else { - glDrawArraysInstanced(glPrimitive, cmd->draw_info.firstIndex, cmd->draw_info.vertexCount, cmd->draw_info.instanceCount); + glDrawArraysInstanced(glPrimitive, cmd->drawInfo.firstIndex, cmd->drawInfo.vertexCount, cmd->drawInfo.instanceCount); } } } else { @@ -2070,7 +2070,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } case GFXCmdType::COPY_BUFFER_TO_TEXTURE: { GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx]; - GLES3CmdFuncCopyBuffersToTexture(device, &(cmd->gpuBuffer->buffer), cmd->gpuTexture, cmd->regions); + GLES3CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions); break; } default: @@ -2080,7 +2080,7 @@ void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { } } -void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { +void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList &buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint]; if (glTexture != gpuTexture->glTexture) { glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture); @@ -2098,7 +2098,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage2D(GL_TEXTURE_2D, @@ -2133,7 +2133,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe for (uint z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, @@ -2169,7 +2169,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe w = region.texExtent.width; h = region.texExtent.height; d = region.texExtent.depth; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage3D(GL_TEXTURE_3D, @@ -2205,7 +2205,7 @@ void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffe for (f = region.texSubres.baseArrayLayer; f < face_count; ++f) { w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buff = buffers[n++]; + const uint8_t *buff = buffers[n++]; if (isCompressed) { GLsizei memSize = (GLsizei)FormatSize(gpuTexture->format, w, h, 1); glCompressedTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 5acb95151b..f6998f06f5 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -15,8 +15,8 @@ struct GLES3DepthBias { }; struct GLES3DepthBounds { - float min_bounds = 0.0f; - float max_bounds = 0.0f; + float minBounds = 0.0f; + float maxBounds = 0.0f; }; struct GLES3StencilWriteMask { @@ -27,7 +27,7 @@ struct GLES3StencilWriteMask { struct GLES3StencilCompareMask { StencilFace face = StencilFace::FRONT; int refrence = 0; - uint compare_mask = 0; + uint compareMask = 0; }; struct GLES3TextureSubres { @@ -81,7 +81,7 @@ public: GLES3GPUPipelineState *gpuPipelineState = nullptr; GLES3GPUBindingLayout *gpuBindingLayout = nullptr; GLES3GPUInputAssembler *gpuInputAssembler = nullptr; - uint8_t state_flags[(int)GLES3State::COUNT] = {0}; + uint8_t stateFlags[(int)GLES3State::COUNT] = {0}; Viewport viewport; Rect scissor; float lineWidth = 1.0f; @@ -98,13 +98,13 @@ public: gpuPipelineState = nullptr; gpuBindingLayout = nullptr; gpuInputAssembler = nullptr; - memset(state_flags, 0, sizeof(state_flags)); + memset(stateFlags, 0, sizeof(stateFlags)); } }; class GLES3CmdDraw : public GFXCmd { public: - DrawInfo draw_info; + DrawInfo drawInfo; GLES3CmdDraw() : GFXCmd(GFXCmdType::DRAW) {} virtual void clear() override {} @@ -127,16 +127,15 @@ public: class GLES3CmdCopyBufferToTexture : public GFXCmd { public: - GLES3GPUBuffer *gpuBuffer = nullptr; GLES3GPUTexture *gpuTexture = nullptr; - TextureLayout dst_layout; + BufferDataList buffers; BufferTextureCopyList regions; GLES3CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {} virtual void clear() override { - gpuBuffer = nullptr; gpuTexture = nullptr; + buffers.clear(); regions.clear(); } }; @@ -167,7 +166,7 @@ CC_GLES3_API void GLES3CmdFuncDestroyInputAssembler(GLES3Device *device, GLES3GP CC_GLES3_API void GLES3CmdFuncCreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); CC_GLES3_API void GLES3CmdFuncDestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); CC_GLES3_API void GLES3CmdFuncExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmd_package); -CC_GLES3_API void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions); +CC_GLES3_API void GLES3CmdFuncCopyBuffersToTexture(GLES3Device *device, const BufferDataList &buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopyList ®ions); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cc b/native/cocos/renderer/gfx-gles3/GLES3Device.cc index 4439812ae4..cf8974d9d3 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cc +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cc @@ -278,9 +278,8 @@ PipelineState *GLES3Device::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void GLES3Device::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - - GLES3CmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((GLES3Texture *)dst)->gpuTexture(), regions); +void GLES3Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { + GLES3CmdFuncCopyBuffersToTexture(this, buffers, ((GLES3Texture *)dst)->gpuTexture(), regions); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index 3b3ea892b2..d5f000fb4b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -33,7 +33,7 @@ public: virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; CC_INLINE GLES3CommandAllocator *cmdAllocator() const { return _cmdAllocator; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cc b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cc index 267b628107..7ce7bae4d7 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cc +++ b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cc @@ -56,13 +56,13 @@ void GLES3InputAssembler::destroy() { } void GLES3InputAssembler::ExtractCmdDraw(GLES3CmdDraw *cmd) { - cmd->draw_info.vertexCount = _vertexCount; - cmd->draw_info.firstVertex = _firstVertex; - cmd->draw_info.indexCount = _indexCount; - cmd->draw_info.firstIndex = _firstIndex; - cmd->draw_info.vertexOffset = _vertexOffset; - cmd->draw_info.instanceCount = _instanceCount; - cmd->draw_info.firstInstance = _firstInstance; + cmd->drawInfo.vertexCount = _vertexCount; + cmd->drawInfo.firstVertex = _firstVertex; + cmd->drawInfo.indexCount = _indexCount; + cmd->drawInfo.firstIndex = _firstIndex; + cmd->drawInfo.vertexOffset = _vertexOffset; + cmd->drawInfo.instanceCount = _instanceCount; + cmd->drawInfo.firstInstance = _firstInstance; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.cc b/native/cocos/renderer/gfx-gles3/GLES3Texture.cc index 8232d0b571..47c548a08b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.cc +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.cc @@ -21,8 +21,8 @@ bool GLES3Texture::initialize(const TextureInfo &info) { _width = info.width; _height = info.height; _depth = info.depth; - _arrayLayer = info.arrayLayer; - _mipLevel = info.mipLevel; + _layerCount = info.layerCount; + _levelCount = info.levelCount; _samples = info.samples; _flags = info.flags; _size = FormatSize(_format, _width, _height, _depth); @@ -83,8 +83,8 @@ bool GLES3Texture::initialize(const TextureInfo &info) { _gpuTexture->height = _height; _gpuTexture->depth = _depth; _gpuTexture->size = _size; - _gpuTexture->arrayLayer = _arrayLayer; - _gpuTexture->mipLevel = _mipLevel; + _gpuTexture->arrayLayer = _layerCount; + _gpuTexture->mipLevel = _levelCount; _gpuTexture->samples = _samples; _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h index e715868321..4082af9970 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h @@ -39,8 +39,8 @@ public: virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; virtual void draw(InputAssembler *ia) override; virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset = 0) override; - virtual void copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) override; - virtual void execute(const vector &cmd_buffs, uint32_t count) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) override; + virtual void execute(const CommandBufferList &cmd_buffs, uint32_t count) override; private: void bindStates(); diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index b447f04230..e6ee071e65 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -288,21 +288,20 @@ void CCMTLCommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint } } -void CCMTLCommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) { +void CCMTLCommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { if ((_type == CommandBufferType::PRIMARY) || (_type == CommandBufferType::SECONDARY)) { - if (src && dst) { - auto buffer = src->getBufferView(); - static_cast(dst)->update(&buffer, regions); + if (texture) { + static_cast(texture)->update(buffers.data(), regions); } else { - CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: buffer 0x%p or texture 0x%p is nullptr", (void *)src, (void *)dst); + CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: texture is nullptr"); } } else { CC_LOG_ERROR("CCMTLCommandBuffer::copyBufferToTexture: invalid command buffer type %d.", _type); } } -void CCMTLCommandBuffer::execute(const vector &commandBuffs, uint32_t count) { +void CCMTLCommandBuffer::execute(const CommandBufferList &commandBuffs, uint32_t count) { for (uint i = 0; i < count; ++i) { auto commandBuffer = static_cast(commandBuffs[i]); _numDrawCalls += commandBuffer->_numDrawCalls; diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.h b/native/cocos/renderer/gfx-metal/MTLDevice.h index a03a43dcec..0b8cb1a0d8 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.h +++ b/native/cocos/renderer/gfx-metal/MTLDevice.h @@ -29,7 +29,7 @@ public: virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; virtual void blitBuffer(void *srcBuffer, uint offset, uint size, void *dstBuffer); CC_INLINE CCMTLStateCache *getStateCache() const { return _stateCache; } diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index c77b477539..5cc046809d 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -25,7 +25,7 @@ namespace gfx { CCMTLDevice::CCMTLDevice() { _clipSpaceMinZ = 0.0f; - _clipSpaceSignY = 1.0f; + _screenSpaceSignY = 1.0f; _UVSpaceSignY = 1.0f; } @@ -257,8 +257,8 @@ PipelineState *CCMTLDevice::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void CCMTLDevice::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - static_cast(dst)->update(buffers.datas.data(), regions); +void CCMTLDevice::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { + static_cast(texture)->update(buffers.data(), regions); } void CCMTLDevice::blitBuffer(void *srcData, uint offset, uint size, void *dstBuffer) { diff --git a/native/cocos/renderer/gfx-metal/MTLTexture.h b/native/cocos/renderer/gfx-metal/MTLTexture.h index 6e2fc965e0..a3229e5cb7 100644 --- a/native/cocos/renderer/gfx-metal/MTLTexture.h +++ b/native/cocos/renderer/gfx-metal/MTLTexture.h @@ -22,7 +22,7 @@ public: CC_INLINE Format getConvertedFormat() const { return _convertedFormat; } private: - void update(uint8_t *const *datas, const BufferTextureCopyList ®ions); + void update(const uint8_t *const *datas, const BufferTextureCopyList ®ions); bool createMTLTexture(); void generateMipmaps(); diff --git a/native/cocos/renderer/gfx-metal/MTLTexture.mm b/native/cocos/renderer/gfx-metal/MTLTexture.mm index e42191c79c..7f04d0edab 100644 --- a/native/cocos/renderer/gfx-metal/MTLTexture.mm +++ b/native/cocos/renderer/gfx-metal/MTLTexture.mm @@ -8,7 +8,7 @@ namespace cc { namespace gfx { namespace { -uint8_t *convertData(uint8_t *source, uint length, Format type) { +const uint8_t *convertData(const uint8_t *source, uint length, Format type) { switch (type) { case Format::RGB8: return mu::convertRGB8ToRGBA8(source, length); case Format::RGB32F: return mu::convertRGB32FToRGBA32F(source, length); @@ -27,8 +27,8 @@ bool CCMTLTexture::initialize(const TextureInfo &info) { _width = info.width; _height = info.height; _depth = info.depth; - _arrayLayer = info.arrayLayer; - _mipLevel = info.mipLevel; + _layerCount = info.layerCount; + _levelCount = info.levelCount; _samples = info.samples; _flags = info.flags; _size = FormatSize(_format, _width, _height, _depth); @@ -101,8 +101,8 @@ bool CCMTLTexture::initialize(const TextureViewInfo &info) { _width = info.texture->getWidth(); _height = info.texture->getHeight(); _depth = info.texture->getDepth(); - _arrayLayer = info.texture->getArrayLayer(); - _mipLevel = info.texture->getMipLevel(); + _layerCount = info.texture->getLayerCount(); + _levelCount = info.texture->getLevelCount(); _samples = info.texture->getSamples(); _flags = info.texture->getFlags(); _size = info.texture->getSize(); @@ -138,7 +138,7 @@ bool CCMTLTexture::createMTLTexture() { switch (mtlTextureType) { case MTLTextureType2D: case MTLTextureType2DArray: - //No need to set mipmapped flag since mipmapLevelCount was explicty set via `_mipLevel`. + //No need to set mipmapped flag since mipmapLevelCount was explicty set via `_levelCount`. descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:mtlFormat width:_width height:_height @@ -160,8 +160,8 @@ bool CCMTLTexture::createMTLTexture() { descriptor.usage = mu::toMTLTextureUsage(_usage); descriptor.textureType = mu::toMTLTextureType(_type); descriptor.sampleCount = mu::toMTLSampleCount(_samples); - descriptor.mipmapLevelCount = _mipLevel; - descriptor.arrayLength = _flags & TextureFlagBit::CUBEMAP ? 1 : _arrayLayer; + descriptor.mipmapLevelCount = _levelCount; + descriptor.arrayLength = _flags & TextureFlagBit::CUBEMAP ? 1 : _layerCount; //FIXME: should change to MTLStorageModeManaged if texture usage is TextureFlags::BAKUP_BUFFER? if (_usage & TextureUsage::COLOR_ATTACHMENT || @@ -237,7 +237,7 @@ void CCMTLTexture::resize(uint width, uint height) { _status = Status::SUCCESS; } -void CCMTLTexture::update(uint8_t *const *datas, const BufferTextureCopyList ®ions) { +void CCMTLTexture::update(const uint8_t *const *datas, const BufferTextureCopyList ®ions) { if (!_mtlTexture) return; @@ -252,8 +252,8 @@ void CCMTLTexture::update(uint8_t *const *datas, const BufferTextureCopyList &re w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buffer = datas[n]; - uint8_t *convertedData = convertData(buffer, w * h, _format); + const uint8_t *buffer = datas[n]; + const uint8_t *convertedData = convertData(buffer, w * h, _format); MTLRegion mtlRegion = {{(uint)region.texOffset.x, (uint)region.texOffset.y, (uint)region.texOffset.z}, {w, h, 1}}; [_mtlTexture replaceRegion:mtlRegion mipmapLevel:region.texSubres.mipLevel @@ -274,8 +274,8 @@ void CCMTLTexture::update(uint8_t *const *datas, const BufferTextureCopyList &re for (; layer < layerCount; layer++) { w = region.texExtent.width; h = region.texExtent.height; - uint8_t *buffer = datas[n]; - uint8_t *convertedData = convertData(buffer, w * h, _format); + const uint8_t *buffer = datas[n]; + const uint8_t *convertedData = convertData(buffer, w * h, _format); MTLRegion mtlRegion = {{(uint)region.texOffset.x, (uint)region.texOffset.y, (uint)region.texOffset.z}, {w, h, 1}}; [_mtlTexture replaceRegion:mtlRegion mipmapLevel:region.texSubres.mipLevel diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.h b/native/cocos/renderer/gfx-metal/MTLUtils.h index ef14fb5d3a..c4ae54f996 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.h +++ b/native/cocos/renderer/gfx-metal/MTLUtils.h @@ -40,8 +40,8 @@ MTLSamplerBorderColor toMTLSamplerBorderColor(const Color &); MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(Filter); MTLSamplerMipFilter toMTLSamplerMipFilter(Filter); String compileGLSLShader2Msl(const String &src, ShaderType shaderType, Device* device, unordered_map &samplerBindings); -uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length); -uint8_t *convertRGB32FToRGBA32F(uint8_t *source, uint length); +const uint8_t *convertRGB8ToRGBA8(const uint8_t *source, uint length); +const uint8_t *convertRGB32FToRGBA32F(const uint8_t *source, uint length); NSUInteger highestSupportedFeatureSet(id device); uint getGPUFamily(MTLFeatureSet featureSet); uint getMaxVertexAttributes(uint family); diff --git a/native/cocos/renderer/gfx-metal/MTLUtils.mm b/native/cocos/renderer/gfx-metal/MTLUtils.mm index 5347325a57..78688bd149 100644 --- a/native/cocos/renderer/gfx-metal/MTLUtils.mm +++ b/native/cocos/renderer/gfx-metal/MTLUtils.mm @@ -591,7 +591,7 @@ String compileGLSLShader2Msl(const String &src, #endif } -uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length) { +const uint8_t *convertRGB8ToRGBA8(const uint8_t *source, uint length) { uint finalLength = length * 4; uint8 *out = (uint8 *)CC_MALLOC(finalLength); if (!out) { @@ -599,7 +599,7 @@ uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length) { return source; } - uint8_t *src = source; + const uint8_t *src = source; uint8_t *dst = out; for (uint i = 0; i < length; ++i) { *dst++ = *src++; @@ -611,7 +611,7 @@ uint8_t *convertRGB8ToRGBA8(uint8_t *source, uint length) { return out; } -uint8_t *convertRGB32FToRGBA32F(uint8_t *source, uint length) { +const uint8_t *convertRGB32FToRGBA32F(const uint8_t *source, uint length) { uint finalLength = length * sizeof(float) * 4; uint8 *out = (uint8 *)CC_MALLOC(finalLength); if (!out) { @@ -619,7 +619,7 @@ uint8_t *convertRGB32FToRGBA32F(uint8_t *source, uint length) { return source; } - float *src = reinterpret_cast(source); + const float *src = reinterpret_cast(source); float *dst = reinterpret_cast(out); for (uint i = 0; i < length; ++i) { *dst++ = *src++; diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cc b/native/cocos/renderer/gfx-vulkan/VKBuffer.cc index 049b289d98..bea8c28ce5 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cc +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKBuffer.h" +#include "VKDevice.h" #include "VKCommands.h" namespace cc { @@ -50,7 +51,7 @@ bool CCVKBuffer::initialize(const BufferInfo &info) { void CCVKBuffer::destroy() { if (_gpuBuffer) { - CCVKCmdFuncDestroyBuffer((CCVKDevice *)_device, _gpuBuffer); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); _device->getMemoryStatus().bufferSize -= _size; CC_DELETE(_gpuBuffer); _gpuBuffer = nullptr; @@ -74,7 +75,8 @@ void CCVKBuffer::resize(uint size) { MemoryStatus &status = _device->getMemoryStatus(); _gpuBuffer->size = _size; _gpuBuffer->count = _count; - CCVKCmdFuncResizeBuffer((CCVKDevice *)_device, _gpuBuffer); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); + CCVKCmdFuncCreateBuffer((CCVKDevice *)_device, _gpuBuffer); status.bufferSize -= oldSize; status.bufferSize += _size; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc index b48d9f6b36..3834475a89 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cc @@ -403,7 +403,7 @@ void CCVKCommandBuffer::draw(InputAssembler *ia) { } } -void CCVKCommandBuffer::execute(const vector &cmdBuffs, uint count) { +void CCVKCommandBuffer::execute(const CommandBufferList &cmdBuffs, uint count) { if (!count) { return; } @@ -431,7 +431,7 @@ void CCVKCommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint o } } -void CCVKCommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions) { +void CCVKCommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { if ((_type == CommandBufferType::PRIMARY && !_curGPUFBO) || (_type == CommandBufferType::SECONDARY)) { //const CCVKGPUBuffer* gpuBuffer = ((CCVKBuffer*)src)->gpuBuffer(); @@ -439,7 +439,7 @@ void CCVKCommandBuffer::copyBufferToTexture(Buffer *src, Texture *dst, TextureLa //vkCmdCopyBufferToImage(_gpuCommandBuffer->vkCommandBuffer, gpuBuffer->vkBuffer, gpuTexture->vkImage, MapVkImageLayout(layout), // regions.size(), regions.data()); } else { - CC_LOG_ERROR("Command 'copyBufferToTexture' must be recorded outside a render pass."); + CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass."); } } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h index e8ce7d0cc9..47463e0218 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h @@ -34,8 +34,8 @@ public: void setStencilCompareMask(StencilFace face, int reference, uint mask); void draw(InputAssembler *ia); void updateBuffer(Buffer *buff, void *data, uint size, uint offset); - void copyBufferToTexture(Buffer *src, Texture *dst, TextureLayout layout, const BufferTextureCopyList ®ions); - void execute(const vector &cmd_buffs, uint count); + void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions); + void execute(const CommandBufferList &cmd_buffs, uint count); CCVKGPUCommandBuffer *gpuCommandBuffer() const { return _gpuCommandBuffer; } diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cc b/native/cocos/renderer/gfx-vulkan/VKCommands.cc index 056c72573c..241681b747 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cc +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cc @@ -36,126 +36,6 @@ void insertVkDynamicStates(vector &out, const vectorlevel = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - cmdBuff->queueFamilyIndex = ((CCVKQueue *)device->getQueue())->gpuQueue()->queueFamilyIndex; - device->gpuCommandBufferPool()->request(cmdBuff); - - VkCommandBufferBeginInfo beginInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; - beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; - VK_CHECK(vkBeginCommandBuffer(cmdBuff->vkCommandBuffer, &beginInfo)); -} - -void endOneTimeCommands(CCVKDevice *device, CCVKGPUCommandBuffer *cmdBuff) { - VK_CHECK(vkEndCommandBuffer(cmdBuff->vkCommandBuffer)); - - VkFence fence = device->gpuFencePool()->alloc(); - const CCVKGPUQueue *queue = ((CCVKQueue *)device->getQueue())->gpuQueue(); - VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO}; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &cmdBuff->vkCommandBuffer; - VK_CHECK(vkQueueSubmit(queue->vkQueue, 1, &submitInfo, fence)); - VK_CHECK(vkWaitForFences(device->gpuDevice()->vkDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT)); - device->gpuCommandBufferPool()->yield(cmdBuff); -} - -void insertImageMemoryBarrior( - VkCommandBuffer cmdBuffer, - VkImage image, - VkAccessFlags srcAccessMask, - VkAccessFlags dstAccessMask, - VkImageLayout oldImageLayout, - VkImageLayout newImageLayout, - VkPipelineStageFlags srcStageMask, - VkPipelineStageFlags dstStageMask, - VkImageSubresourceRange subresourceRange) { - VkImageMemoryBarrier barrier{VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER}; - barrier.image = image; - barrier.srcAccessMask = srcAccessMask; - barrier.dstAccessMask = dstAccessMask; - barrier.oldLayout = oldImageLayout; - barrier.newLayout = newImageLayout; - barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - barrier.subresourceRange = subresourceRange; - - vkCmdPipelineBarrier(cmdBuffer, - srcStageMask, dstStageMask, 0, - 0, nullptr, - 0, nullptr, - 1, &barrier); -} - -void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { - size_t colorAttachmentCount = gpuRenderPass->colorAttachments.size(); - vector attachmentDescriptions(colorAttachmentCount + 1); - gpuRenderPass->clearValues.resize(colorAttachmentCount + 1); - for (size_t i = 0u; i < colorAttachmentCount; i++) { - const ColorAttachment &attachment = gpuRenderPass->colorAttachments[i]; - const VkImageLayout beginLayout = MapVkImageLayout(attachment.beginLayout); - const VkImageLayout endLayout = MapVkImageLayout(attachment.endLayout); - const VkAccessFlags beginAccessMask = MapVkAccessFlags(attachment.beginLayout); - const VkAccessFlags endAccessMask = MapVkAccessFlags(attachment.endLayout); - attachmentDescriptions[i].format = MapVkFormat(attachment.format); - attachmentDescriptions[i].samples = MapVkSampleCount(attachment.sampleCount); - attachmentDescriptions[i].loadOp = MapVkLoadOp(attachment.loadOp); - attachmentDescriptions[i].storeOp = MapVkStoreOp(attachment.storeOp); - attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachmentDescriptions[i].initialLayout = beginLayout; - attachmentDescriptions[i].finalLayout = endLayout; - } - const DepthStencilAttachment &depthStencilAttachment = gpuRenderPass->depthStencilAttachment; - const VkImageLayout beginLayout = MapVkImageLayout(depthStencilAttachment.beginLayout); - const VkImageLayout endLayout = MapVkImageLayout(depthStencilAttachment.endLayout); - const VkAccessFlags beginAccessMask = MapVkAccessFlags(depthStencilAttachment.beginLayout); - const VkAccessFlags endAccessMask = MapVkAccessFlags(depthStencilAttachment.endLayout); - const VkImageAspectFlags aspectMask = GFX_FORMAT_INFOS[(uint)depthStencilAttachment.format].hasStencil ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT; - attachmentDescriptions[colorAttachmentCount].format = MapVkFormat(depthStencilAttachment.format); - attachmentDescriptions[colorAttachmentCount].samples = MapVkSampleCount(depthStencilAttachment.sampleCount); - attachmentDescriptions[colorAttachmentCount].loadOp = MapVkLoadOp(depthStencilAttachment.depthLoadOp); - attachmentDescriptions[colorAttachmentCount].storeOp = MapVkStoreOp(depthStencilAttachment.depthStoreOp); - attachmentDescriptions[colorAttachmentCount].stencilLoadOp = MapVkLoadOp(depthStencilAttachment.stencilLoadOp); - attachmentDescriptions[colorAttachmentCount].stencilStoreOp = MapVkStoreOp(depthStencilAttachment.stencilStoreOp); - attachmentDescriptions[colorAttachmentCount].initialLayout = beginLayout; - attachmentDescriptions[colorAttachmentCount].finalLayout = endLayout; - - size_t subpassCount = gpuRenderPass->subPasses.size(); - vector subpassDescriptions(1, {VK_PIPELINE_BIND_POINT_GRAPHICS}); - vector attachmentReferences; - if (subpassCount) { // pass on user-specified subpasses - subpassDescriptions.resize(subpassCount); - for (size_t i = 0u; i < subpassCount; i++) { - const SubPass &subpass = gpuRenderPass->subPasses[i]; - subpassDescriptions[i].pipelineBindPoint = MapVkPipelineBindPoint(subpass.bindPoint); - // TODO - } - } else { // generate a default subpass from attachment info - for (size_t i = 0u; i < colorAttachmentCount; i++) { - attachmentReferences.push_back({(uint32_t)i, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}); - } - attachmentReferences.push_back({(uint32_t)colorAttachmentCount, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL}); - subpassDescriptions[0].colorAttachmentCount = attachmentReferences.size() - 1; - subpassDescriptions[0].pColorAttachments = attachmentReferences.data(); - subpassDescriptions[0].pDepthStencilAttachment = &attachmentReferences.back(); - } - - VkRenderPassCreateInfo renderPassCreateInfo{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO}; - renderPassCreateInfo.attachmentCount = attachmentDescriptions.size(); - renderPassCreateInfo.pAttachments = attachmentDescriptions.data(); - renderPassCreateInfo.subpassCount = subpassDescriptions.size(); - renderPassCreateInfo.pSubpasses = subpassDescriptions.data(); - - VK_CHECK(vkCreateRenderPass(device->gpuDevice()->vkDevice, &renderPassCreateInfo, nullptr, &gpuRenderPass->vkRenderPass)); -} - -void CCVKCmdFuncDestroyRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { - if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) { - vkDestroyRenderPass(device->gpuDevice()->vkDevice, gpuRenderPass->vkRenderPass, nullptr); - gpuRenderPass->vkRenderPass = VK_NULL_HANDLE; - } -} - void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) { uint queueType = 0u; VkBool32 needPresentable = VK_FALSE; @@ -212,77 +92,6 @@ void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { gpuBuffer->startOffset = 0; // we are creating one VkBuffer each for now } -void CCVKCmdFuncDestroyBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { - if (gpuBuffer->vmaAllocation) { - vmaDestroyBuffer(device->gpuDevice()->memoryAllocator, gpuBuffer->vkBuffer, gpuBuffer->vmaAllocation); - gpuBuffer->buffer = VK_NULL_HANDLE; - gpuBuffer->vmaAllocation = VK_NULL_HANDLE; - } -} - -void CCVKCmdFuncResizeBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { - CCVKCmdFuncDestroyBuffer(device, gpuBuffer); - CCVKCmdFuncCreateBuffer(device, gpuBuffer); -} - -void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size) { - if (!gpuBuffer) return; - - const void *dataToUpload = nullptr; - size_t sizeToUpload = 0u; - - if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { - size_t drawInfoCount = size / sizeof(DrawInfo); - DrawInfo *drawInfo = static_cast(buffer); - if (drawInfoCount > 0) { - if (drawInfo->indexCount) { - for (size_t i = 0; i < drawInfoCount; i++) { - gpuBuffer->indexedIndirectCmds[i].indexCount = drawInfo->indexCount; - gpuBuffer->indexedIndirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1u); - gpuBuffer->indexedIndirectCmds[i].firstIndex = drawInfo->firstIndex; - gpuBuffer->indexedIndirectCmds[i].vertexOffset = drawInfo->vertexOffset; - gpuBuffer->indexedIndirectCmds[i].firstInstance = drawInfo->firstInstance; - drawInfo++; - } - dataToUpload = gpuBuffer->indexedIndirectCmds.data(); - sizeToUpload = drawInfoCount * sizeof(VkDrawIndexedIndirectCommand); - gpuBuffer->isDrawIndirectByIndex = true; - } else { - for (size_t i = 0; i < drawInfoCount; i++) { - gpuBuffer->indirectCmds[i].vertexCount = drawInfo->vertexCount; - gpuBuffer->indirectCmds[i].instanceCount = drawInfo->instanceCount; - gpuBuffer->indirectCmds[i].firstVertex = drawInfo->firstVertex; - gpuBuffer->indirectCmds[i].firstInstance = drawInfo->firstInstance; - drawInfo++; - } - dataToUpload = gpuBuffer->indirectCmds.data(); - sizeToUpload = drawInfoCount * sizeof(VkDrawIndirectCommand); - gpuBuffer->isDrawIndirectByIndex = false; - } - } - } else { - dataToUpload = buffer; - sizeToUpload = size; - } - - if (gpuBuffer->mappedData) { - memcpy(gpuBuffer->mappedData + offset, dataToUpload, sizeToUpload); - } else { - const CCVKGPUBuffer *stagingBuffer = device->stagingBuffer()->gpuBuffer(); - if (stagingBuffer->size < sizeToUpload) device->stagingBuffer()->resize(nextPowerOf2(sizeToUpload)); - - memcpy(stagingBuffer->mappedData, dataToUpload, sizeToUpload); - - CCVKGPUCommandBuffer cmdBuff; - beginOneTimeCommands(device, &cmdBuff); - - VkBufferCopy region{0, gpuBuffer->startOffset + offset, sizeToUpload}; - vkCmdCopyBuffer(cmdBuff.vkCommandBuffer, stagingBuffer->vkBuffer, gpuBuffer->vkBuffer, 1, ®ion); - - endOneTimeCommands(device, &cmdBuff); - } -} - void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { if (!gpuTexture->size) return; @@ -306,8 +115,8 @@ void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { createInfo.imageType = MapVkImageType(gpuTexture->type); createInfo.format = format; createInfo.extent = {gpuTexture->width, gpuTexture->height, gpuTexture->depth}; - createInfo.mipLevels = gpuTexture->mipLevel; - createInfo.arrayLayers = gpuTexture->arrayLayer; + createInfo.mipLevels = gpuTexture->mipLevels; + createInfo.arrayLayers = gpuTexture->arrayLayers; createInfo.samples = MapVkSampleCount(gpuTexture->samples); createInfo.tiling = VK_IMAGE_TILING_OPTIMAL; createInfo.usage = usageFlags; @@ -320,44 +129,10 @@ void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { VK_CHECK(vmaCreateImage(device->gpuDevice()->memoryAllocator, &createInfo, &allocInfo, &gpuTexture->vkImage, &gpuTexture->vmaAllocation, &res)); //CC_LOG_DEBUG("Allocated texture: %llu %llx %llx %llu %x", res.size, gpuTexture->vkImage, res.deviceMemory, res.offset, res.pMappedData); - gpuTexture->currentLayout = MapVkImageLayout(gpuTexture->usage, gpuTexture->format); + gpuTexture->layout = MapVkImageLayout(gpuTexture->usage, gpuTexture->format); gpuTexture->accessMask = MapVkAccessFlags(gpuTexture->usage, gpuTexture->format); gpuTexture->aspectMask = MapVkImageAspectFlags(gpuTexture->format); gpuTexture->targetStage = MapVkPipelineStageFlags(gpuTexture->usage); - - if (gpuTexture->currentLayout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { - CCVKGPUCommandBuffer cmfBuff; - beginOneTimeCommands(device, &cmfBuff); - - VkImageSubresourceRange subresourceRange{}; - subresourceRange.aspectMask = gpuTexture->aspectMask; - subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; - subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; - insertImageMemoryBarrior(cmfBuff.vkCommandBuffer, - gpuTexture->vkImage, - 0, - gpuTexture->accessMask, - VK_IMAGE_LAYOUT_UNDEFINED, - gpuTexture->currentLayout, - VK_PIPELINE_STAGE_HOST_BIT, - gpuTexture->targetStage, - subresourceRange); - - endOneTimeCommands(device, &cmfBuff); - } -} - -void CCVKCmdFuncDestroyTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { - if (gpuTexture->vmaAllocation) { - vmaDestroyImage(device->gpuDevice()->memoryAllocator, gpuTexture->vkImage, gpuTexture->vmaAllocation); - gpuTexture->vkImage = VK_NULL_HANDLE; - gpuTexture->vmaAllocation = VK_NULL_HANDLE; - } -} - -void CCVKCmdFuncResizeTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture) { - CCVKCmdFuncDestroyTexture(device, gpuTexture); - CCVKCmdFuncCreateTexture(device, gpuTexture); } void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView) { @@ -370,17 +145,77 @@ void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTex createInfo.subresourceRange.aspectMask = GFX_FORMAT_INFOS[(uint)gpuTextureView->format].hasDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; createInfo.subresourceRange.baseMipLevel = gpuTextureView->baseLevel; createInfo.subresourceRange.levelCount = gpuTextureView->levelCount; - createInfo.subresourceRange.baseArrayLayer = 0; - createInfo.subresourceRange.layerCount = gpuTextureView->gpuTexture->arrayLayer; + createInfo.subresourceRange.baseArrayLayer = gpuTextureView->baseLayer; + createInfo.subresourceRange.layerCount = gpuTextureView->layerCount; VK_CHECK(vkCreateImageView(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuTextureView->vkImageView)); } -void CCVKCmdFuncDestroyTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView) { - if (gpuTextureView->vkImageView != VK_NULL_HANDLE) { - vkDestroyImageView(device->gpuDevice()->vkDevice, gpuTextureView->vkImageView, nullptr); - gpuTextureView->vkImageView = VK_NULL_HANDLE; +void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { + const size_t colorAttachmentCount = gpuRenderPass->colorAttachments.size(); + const size_t hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN ? 1 : 0; + vector attachmentDescriptions(colorAttachmentCount + hasDepth); + gpuRenderPass->clearValues.resize(colorAttachmentCount + hasDepth); + for (size_t i = 0u; i < colorAttachmentCount; i++) { + const ColorAttachment &attachment = gpuRenderPass->colorAttachments[i]; + const VkImageLayout beginLayout = MapVkImageLayout(attachment.beginLayout); + const VkImageLayout endLayout = MapVkImageLayout(attachment.endLayout); + const VkAccessFlags beginAccessMask = MapVkAccessFlags(attachment.beginLayout); + const VkAccessFlags endAccessMask = MapVkAccessFlags(attachment.endLayout); + attachmentDescriptions[i].format = MapVkFormat(attachment.format); + attachmentDescriptions[i].samples = MapVkSampleCount(attachment.sampleCount); + attachmentDescriptions[i].loadOp = MapVkLoadOp(attachment.loadOp); + attachmentDescriptions[i].storeOp = MapVkStoreOp(attachment.storeOp); + attachmentDescriptions[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + attachmentDescriptions[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + attachmentDescriptions[i].initialLayout = beginLayout; + attachmentDescriptions[i].finalLayout = endLayout; } + if (hasDepth) { + const DepthStencilAttachment &depthStencilAttachment = gpuRenderPass->depthStencilAttachment; + const VkImageLayout beginLayout = MapVkImageLayout(depthStencilAttachment.beginLayout); + const VkImageLayout endLayout = MapVkImageLayout(depthStencilAttachment.endLayout); + const VkAccessFlags beginAccessMask = MapVkAccessFlags(depthStencilAttachment.beginLayout); + const VkAccessFlags endAccessMask = MapVkAccessFlags(depthStencilAttachment.endLayout); + const bool hasStencil = GFX_FORMAT_INFOS[(uint)depthStencilAttachment.format].hasStencil; + const VkImageAspectFlags aspectMask = hasStencil ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT; + attachmentDescriptions[colorAttachmentCount].format = MapVkFormat(depthStencilAttachment.format); + attachmentDescriptions[colorAttachmentCount].samples = MapVkSampleCount(depthStencilAttachment.sampleCount); + attachmentDescriptions[colorAttachmentCount].loadOp = MapVkLoadOp(depthStencilAttachment.depthLoadOp); + attachmentDescriptions[colorAttachmentCount].storeOp = MapVkStoreOp(depthStencilAttachment.depthStoreOp); + attachmentDescriptions[colorAttachmentCount].stencilLoadOp = MapVkLoadOp(depthStencilAttachment.stencilLoadOp); + attachmentDescriptions[colorAttachmentCount].stencilStoreOp = MapVkStoreOp(depthStencilAttachment.stencilStoreOp); + attachmentDescriptions[colorAttachmentCount].initialLayout = beginLayout; + attachmentDescriptions[colorAttachmentCount].finalLayout = endLayout; + } + + const size_t subpassCount = gpuRenderPass->subPasses.size(); + vector subpassDescriptions(1, {VK_PIPELINE_BIND_POINT_GRAPHICS}); + vector attachmentReferences; + if (subpassCount) { // pass on user-specified subpasses + subpassDescriptions.resize(subpassCount); + for (size_t i = 0u; i < subpassCount; i++) { + const SubPass &subpass = gpuRenderPass->subPasses[i]; + subpassDescriptions[i].pipelineBindPoint = MapVkPipelineBindPoint(subpass.bindPoint); + // TODO + } + } else { // generate a default subpass from attachment info + for (size_t i = 0u; i < colorAttachmentCount; i++) { + attachmentReferences.push_back({(uint32_t)i, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}); + } + attachmentReferences.push_back({(uint32_t)colorAttachmentCount, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL}); + subpassDescriptions[0].colorAttachmentCount = attachmentReferences.size() - 1; + subpassDescriptions[0].pColorAttachments = attachmentReferences.data(); + subpassDescriptions[0].pDepthStencilAttachment = &attachmentReferences.back(); + } + + VkRenderPassCreateInfo renderPassCreateInfo{VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO}; + renderPassCreateInfo.attachmentCount = attachmentDescriptions.size(); + renderPassCreateInfo.pAttachments = attachmentDescriptions.data(); + renderPassCreateInfo.subpassCount = subpassDescriptions.size(); + renderPassCreateInfo.pSubpasses = subpassDescriptions.data(); + + VK_CHECK(vkCreateRenderPass(device->gpuDevice()->vkDevice, &renderPassCreateInfo, nullptr, &gpuRenderPass->vkRenderPass)); } void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) { @@ -404,13 +239,6 @@ void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) { VK_CHECK(vkCreateSampler(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuSampler->vkSampler)); } -void CCVKCmdFuncDestroySampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler) { - if (gpuSampler->vkSampler != VK_NULL_HANDLE) { - vkDestroySampler(device->gpuDevice()->vkDevice, gpuSampler->vkSampler, nullptr); - gpuSampler->vkSampler = VK_NULL_HANDLE; - } -} - void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { vector spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, ((CCVKContext *)device->getContext())->minorVersion()); @@ -463,7 +291,7 @@ void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { for (size_t i = 0u; i < bindingCount; i++) { entries[i].dstBinding = setBindings[i].binding; entries[i].dstArrayElement = 0; - entries[i].descriptorCount = 1; + entries[i].descriptorCount = setBindings[i].descriptorCount; // TODO: texture arrays entries[i].descriptorType = setBindings[i].descriptorType; entries[i].offset = sizeof(CCVKDescriptorInfo) * i; entries[i].stride = sizeof(CCVKDescriptorInfo); @@ -489,69 +317,30 @@ void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { for (size_t i = 0u; i < bindingCount; i++) { entries[i].dstBinding = setBindings[i].binding; entries[i].dstArrayElement = 0; - entries[i].descriptorCount = 1; + entries[i].descriptorCount = setBindings[i].descriptorCount; entries[i].descriptorType = setBindings[i].descriptorType; } } } -void CCVKCmdFuncDestroyShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { - for (uint i = 0u; i < gpuShader->vkDescriptorUpdateTemplates.size(); i++) { - if (gpuShader->vkDescriptorUpdateTemplates[i] != VK_NULL_HANDLE) { - vkDestroyDescriptorUpdateTemplateKHR(device->gpuDevice()->vkDevice, gpuShader->vkDescriptorUpdateTemplates[i], nullptr); - } - } - gpuShader->vkDescriptorUpdateTemplates.clear(); - - if (gpuShader->vkPipelineLayout != VK_NULL_HANDLE) { - vkDestroyPipelineLayout(device->gpuDevice()->vkDevice, gpuShader->vkPipelineLayout, nullptr); - gpuShader->vkPipelineLayout = VK_NULL_HANDLE; - } - - for (uint i = 0u; i < gpuShader->vkDescriptorSetLayouts.size(); i++) { - if (gpuShader->vkDescriptorSetLayouts[i] != VK_NULL_HANDLE) { - vkDestroyDescriptorSetLayout(device->gpuDevice()->vkDevice, gpuShader->vkDescriptorSetLayouts[i], nullptr); - } - } - gpuShader->vkDescriptorSetLayouts.clear(); - - for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { - vkDestroyShaderModule(device->gpuDevice()->vkDevice, stage.vkShader, nullptr); - stage.vkShader = VK_NULL_HANDLE; - } -} - -void CCVKCmdFuncCreateInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler) { - size_t vbCount = gpuInputAssembler->gpuVertexBuffers.size(); - gpuInputAssembler->vertexBuffers.resize(vbCount); - gpuInputAssembler->vertexBufferOffsets.resize(vbCount); - - for (size_t i = 0u; i < vbCount; i++) { - gpuInputAssembler->vertexBuffers[i] = gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer; - gpuInputAssembler->vertexBufferOffsets[i] = gpuInputAssembler->gpuVertexBuffers[i]->startOffset; - } -} - -void CCVKCmdFuncDestroyInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler) { - gpuInputAssembler->vertexBuffers.clear(); - gpuInputAssembler->vertexBufferOffsets.clear(); -} - void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer) { size_t colorViewCount = gpuFramebuffer->gpuColorViews.size(); bool depthSpecified = gpuFramebuffer->gpuDepthStencilView; bool hasDepth = gpuFramebuffer->gpuRenderPass->depthStencilAttachment.format == device->getDepthStencilFormat(); vector attachments(colorViewCount + (depthSpecified || hasDepth ? 1 : 0)); uint swapchainImageIndices = 0; + CCVKGPUTexture *gpuTexture = nullptr; for (size_t i = 0u; i < colorViewCount; i++) { CCVKGPUTextureView *texView = gpuFramebuffer->gpuColorViews[i]; if (texView) { + gpuTexture = gpuFramebuffer->gpuColorViews[i]->gpuTexture; attachments[i] = gpuFramebuffer->gpuColorViews[i]->vkImageView; } else { swapchainImageIndices |= (1 << i); } } if (depthSpecified) { + gpuTexture = gpuFramebuffer->gpuDepthStencilView->gpuTexture; attachments[colorViewCount] = gpuFramebuffer->gpuDepthStencilView->vkImageView; } else if (hasDepth) { swapchainImageIndices |= (1 << colorViewCount); @@ -563,8 +352,8 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra createInfo.renderPass = gpuFramebuffer->gpuRenderPass->vkRenderPass; createInfo.attachmentCount = attachments.size(); createInfo.pAttachments = attachments.data(); - createInfo.width = colorViewCount ? gpuFramebuffer->gpuColorViews[0]->gpuTexture->width : 1; - createInfo.height = colorViewCount ? gpuFramebuffer->gpuColorViews[0]->gpuTexture->height : 1; + createInfo.width = gpuTexture ? gpuTexture->width : 1; + createInfo.height = gpuTexture ? gpuTexture->height : 1; createInfo.layers = 1; VK_CHECK(vkCreateFramebuffer(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuFramebuffer->vkFramebuffer)); } else { @@ -604,25 +393,6 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra } } -void CCVKCmdFuncDestroyFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer) { - if (gpuFramebuffer->isOffscreen) { - if (gpuFramebuffer->vkFramebuffer != VK_NULL_HANDLE) { - vkDestroyFramebuffer(device->gpuDevice()->vkDevice, gpuFramebuffer->vkFramebuffer, nullptr); - gpuFramebuffer->vkFramebuffer = VK_NULL_HANDLE; - } - } else { - FramebufferListMap &fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap; - FramebufferListMapIter fboListMapIter = fboListMap.find(gpuFramebuffer); - if (fboListMapIter != fboListMap.end()) { - for (size_t i = 0u; i < fboListMapIter->second.size(); i++) { - vkDestroyFramebuffer(device->gpuDevice()->vkDevice, fboListMapIter->second[i], nullptr); - } - fboListMapIter->second.clear(); - fboListMap.erase(fboListMapIter); - } - } -} - void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { VkGraphicsPipelineCreateInfo createInfo{VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO}; @@ -816,150 +586,338 @@ void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gp 1, &createInfo, nullptr, &gpuPipelineState->vkPipeline)); } -void CCVKCmdFuncDestroyPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState) { +void CCVKCmdFuncCreateFence(CCVKDevice *device, CCVKGPUFence *gpuFence) { + VkFenceCreateInfo createInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO}; + VK_CHECK(vkCreateFence(device->gpuDevice()->vkDevice, &createInfo, nullptr, &gpuFence->vkFence)); +} + +void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size) { + if (!gpuBuffer) return; + + const void *dataToUpload = nullptr; + size_t sizeToUpload = 0u; + + if (gpuBuffer->usage & BufferUsageBit::INDIRECT) { + size_t drawInfoCount = size / sizeof(DrawInfo); + DrawInfo *drawInfo = static_cast(buffer); + if (drawInfoCount > 0) { + if (drawInfo->indexCount) { + for (size_t i = 0; i < drawInfoCount; i++) { + gpuBuffer->indexedIndirectCmds[i].indexCount = drawInfo->indexCount; + gpuBuffer->indexedIndirectCmds[i].instanceCount = std::max(drawInfo->instanceCount, 1u); + gpuBuffer->indexedIndirectCmds[i].firstIndex = drawInfo->firstIndex; + gpuBuffer->indexedIndirectCmds[i].vertexOffset = drawInfo->vertexOffset; + gpuBuffer->indexedIndirectCmds[i].firstInstance = drawInfo->firstInstance; + drawInfo++; + } + dataToUpload = gpuBuffer->indexedIndirectCmds.data(); + sizeToUpload = drawInfoCount * sizeof(VkDrawIndexedIndirectCommand); + gpuBuffer->isDrawIndirectByIndex = true; + } else { + for (size_t i = 0; i < drawInfoCount; i++) { + gpuBuffer->indirectCmds[i].vertexCount = drawInfo->vertexCount; + gpuBuffer->indirectCmds[i].instanceCount = drawInfo->instanceCount; + gpuBuffer->indirectCmds[i].firstVertex = drawInfo->firstVertex; + gpuBuffer->indirectCmds[i].firstInstance = drawInfo->firstInstance; + drawInfo++; + } + dataToUpload = gpuBuffer->indirectCmds.data(); + sizeToUpload = drawInfoCount * sizeof(VkDrawIndirectCommand); + gpuBuffer->isDrawIndirectByIndex = false; + } + } + } else { + dataToUpload = buffer; + sizeToUpload = size; + } + + if (gpuBuffer->mappedData) { + device->gpuTransportHub()->checkIn(gpuBuffer->mappedData + offset, dataToUpload, sizeToUpload); + } else { + CCVKGPUBuffer stagingBuffer; + stagingBuffer.size = sizeToUpload; + device->gpuStagingBufferPool()->alloc(&stagingBuffer); + memcpy(stagingBuffer.mappedData, dataToUpload, sizeToUpload); + + VkBufferCopy region{stagingBuffer.startOffset, gpuBuffer->startOffset + offset, sizeToUpload}; + device->gpuTransportHub()->checkIn([&](VkCommandBuffer cmdBuff) { + vkCmdCopyBuffer(cmdBuff, stagingBuffer.vkBuffer, gpuBuffer->vkBuffer, 1, ®ion); + }); + } +} + +void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { + device->gpuTransportHub()->checkIn([&](VkCommandBuffer cmdBuff) { + //bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed; + + VkImageMemoryBarrier barriers[2]{}; + barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[0].image = gpuTexture->vkImage; + barriers[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[0].subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS; + barriers[0].subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; + barriers[0].subresourceRange.aspectMask = gpuTexture->aspectMask; + barriers[0].srcAccessMask = gpuTexture->accessMask; + barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barriers[0].oldLayout = gpuTexture->currentLayout; + barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + vkCmdPipelineBarrier(cmdBuff, gpuTexture->targetStage, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, barriers); + + uint regionCount = regions.size(), totalSize = 0u; + vector regionSizes(regionCount); + for (size_t i = 0u; i < regionCount; ++i) { + const BufferTextureCopy ®ion = regions[i]; + uint w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; + uint h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; + totalSize += regionSizes[i] = FormatSize(gpuTexture->format, w, h, region.texExtent.depth); + } + + CCVKGPUBuffer stagingBuffer; + stagingBuffer.size = totalSize; + device->gpuStagingBufferPool()->alloc(&stagingBuffer); + + vector stagingRegions(regionCount); + VkDeviceSize offset = 0; + for (size_t i = 0u; i < regionCount; ++i) { + const BufferTextureCopy ®ion = regions[i]; + VkBufferImageCopy &stagingRegion = stagingRegions[i]; + stagingRegion.bufferOffset = stagingBuffer.startOffset + offset; + stagingRegion.bufferRowLength = region.buffStride; + stagingRegion.bufferImageHeight = region.buffTexHeight; + stagingRegion.imageSubresource = {gpuTexture->aspectMask, region.texSubres.mipLevel, region.texSubres.baseArrayLayer, region.texSubres.layerCount}; + stagingRegion.imageOffset = {region.texOffset.x, region.texOffset.y, region.texOffset.z}; + stagingRegion.imageExtent = {region.texExtent.width, region.texExtent.height, region.texExtent.depth}; + + memcpy(stagingBuffer.mappedData + offset, buffers[i], regionSizes[i]); + offset += regionSizes[i]; + } + + vkCmdCopyBufferToImage(cmdBuff, stagingBuffer.vkBuffer, gpuTexture->vkImage, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, stagingRegions.size(), stagingRegions.data()); + + bool layoutReady = false; + if (gpuTexture->flags & TextureFlags::GEN_MIPMAP) { + VkFormatProperties formatProperties; + vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, MapVkFormat(gpuTexture->format), &formatProperties); + VkFormatFeatureFlags mipmapFeatures = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; + + if (formatProperties.optimalTilingFeatures & mipmapFeatures) { + const int32_t width = gpuTexture->width; + const int32_t height = gpuTexture->height; + + VkImageBlit blitInfo{}; + blitInfo.srcSubresource.aspectMask = gpuTexture->aspectMask; + blitInfo.srcSubresource.layerCount = gpuTexture->arrayLayers; + blitInfo.dstSubresource.aspectMask = gpuTexture->aspectMask; + blitInfo.dstSubresource.layerCount = gpuTexture->arrayLayers; + blitInfo.srcOffsets[1] = {width, height, 1}; + blitInfo.dstOffsets[1] = {std::max(width >> 1, 1), std::max(height >> 1, 1), 1}; + barriers[0].subresourceRange.levelCount = 1; + barriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barriers[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + + for (uint i = 1u; i < gpuTexture->mipLevels; i++) { + barriers[0].subresourceRange.baseMipLevel = i - 1; + vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, barriers); + + blitInfo.srcSubresource.mipLevel = i - 1; + blitInfo.dstSubresource.mipLevel = i; + vkCmdBlitImage(cmdBuff, gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blitInfo, VK_FILTER_LINEAR); + + const int32_t w = blitInfo.srcOffsets[1].x = blitInfo.dstOffsets[1].x; + const int32_t h = blitInfo.srcOffsets[1].y = blitInfo.dstOffsets[1].y; + blitInfo.dstOffsets[1].x = std::max(w >> 1, 1); + blitInfo.dstOffsets[1].y = std::max(h >> 1, 1); + } + + barriers[0].subresourceRange.baseMipLevel = gpuTexture->mipLevels - 1; + barriers[0].dstAccessMask = gpuTexture->accessMask; + barriers[0].newLayout = gpuTexture->layout; + + barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + barriers[1].image = gpuTexture->vkImage; + barriers[1].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[1].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barriers[1].subresourceRange.aspectMask = gpuTexture->aspectMask; + barriers[1].subresourceRange.baseMipLevel = 0; + barriers[1].subresourceRange.levelCount = gpuTexture->mipLevels - 1; + barriers[1].subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; + barriers[1].srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + barriers[1].dstAccessMask = gpuTexture->accessMask; + barriers[1].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; + barriers[1].newLayout = gpuTexture->layout; + + vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_TRANSFER_BIT, gpuTexture->targetStage, + VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 2, barriers); + layoutReady = true; + } else { + const char *formatName = GFX_FORMAT_INFOS[(uint)gpuTexture->format].name.c_str(); + CC_LOG_WARNING("CCVKCmdFuncCopyBuffersToTexture: generate mipmap for %s is not supported on this platform", formatName); + } + } + + if (!layoutReady) { + barriers[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + barriers[0].dstAccessMask = gpuTexture->accessMask; + barriers[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; + barriers[0].newLayout = gpuTexture->layout; + vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_TRANSFER_BIT, gpuTexture->targetStage, + VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1, barriers); + } + + gpuTexture->currentLayout = gpuTexture->layout; + }); +} + +void CCVKCmdFuncDestroyRenderPass(CCVKGPUDevice *gpuDevice, CCVKGPURenderPass *gpuRenderPass) { + if (gpuRenderPass->vkRenderPass != VK_NULL_HANDLE) { + vkDestroyRenderPass(gpuDevice->vkDevice, gpuRenderPass->vkRenderPass, nullptr); + gpuRenderPass->vkRenderPass = VK_NULL_HANDLE; + } +} + +void CCVKCmdFuncDestroySampler(CCVKGPUDevice *gpuDevice, CCVKGPUSampler *gpuSampler) { + if (gpuSampler->vkSampler != VK_NULL_HANDLE) { + vkDestroySampler(gpuDevice->vkDevice, gpuSampler->vkSampler, nullptr); + gpuSampler->vkSampler = VK_NULL_HANDLE; + } +} + +void CCVKCmdFuncDestroyShader(CCVKGPUDevice *gpuDevice, CCVKGPUShader *gpuShader) { + for (uint i = 0u; i < gpuShader->vkDescriptorUpdateTemplates.size(); i++) { + if (gpuShader->vkDescriptorUpdateTemplates[i] != VK_NULL_HANDLE) { + vkDestroyDescriptorUpdateTemplateKHR(gpuDevice->vkDevice, gpuShader->vkDescriptorUpdateTemplates[i], nullptr); + } + } + gpuShader->vkDescriptorUpdateTemplates.clear(); + + if (gpuShader->vkPipelineLayout != VK_NULL_HANDLE) { + vkDestroyPipelineLayout(gpuDevice->vkDevice, gpuShader->vkPipelineLayout, nullptr); + gpuShader->vkPipelineLayout = VK_NULL_HANDLE; + } + + for (uint i = 0u; i < gpuShader->vkDescriptorSetLayouts.size(); i++) { + if (gpuShader->vkDescriptorSetLayouts[i] != VK_NULL_HANDLE) { + vkDestroyDescriptorSetLayout(gpuDevice->vkDevice, gpuShader->vkDescriptorSetLayouts[i], nullptr); + } + } + gpuShader->vkDescriptorSetLayouts.clear(); + + for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { + vkDestroyShaderModule(gpuDevice->vkDevice, stage.vkShader, nullptr); + stage.vkShader = VK_NULL_HANDLE; + } +} + +void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *gpuDevice, CCVKGPUFramebuffer *gpuFramebuffer) { + if (gpuFramebuffer->isOffscreen) { + if (gpuFramebuffer->vkFramebuffer != VK_NULL_HANDLE) { + vkDestroyFramebuffer(gpuDevice->vkDevice, gpuFramebuffer->vkFramebuffer, nullptr); + gpuFramebuffer->vkFramebuffer = VK_NULL_HANDLE; + } + } else { + FramebufferListMap &fboListMap = gpuFramebuffer->swapchain->vkSwapchainFramebufferListMap; + FramebufferListMapIter fboListMapIter = fboListMap.find(gpuFramebuffer); + if (fboListMapIter != fboListMap.end()) { + for (size_t i = 0u; i < fboListMapIter->second.size(); i++) { + vkDestroyFramebuffer(gpuDevice->vkDevice, fboListMapIter->second[i], nullptr); + } + fboListMapIter->second.clear(); + fboListMap.erase(fboListMapIter); + } + } +} + +void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *gpuDevice, CCVKGPUPipelineState *gpuPipelineState) { if (gpuPipelineState->vkPipeline != VK_NULL_HANDLE) { - vkDestroyPipeline(device->gpuDevice()->vkDevice, gpuPipelineState->vkPipeline, nullptr); + vkDestroyPipeline(gpuDevice->vkDevice, gpuPipelineState->vkPipeline, nullptr); gpuPipelineState->vkPipeline = VK_NULL_HANDLE; } } -void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions) { - //bool isCompressed = GFX_FORMAT_INFOS[(int)gpuTexture->format].isCompressed; - CCVKGPUCommandBuffer cmdBuff; - beginOneTimeCommands(device, &cmdBuff); - - //transfer image layout to destination for later copy. - VkImageSubresourceRange subresoureceRange{}; - subresoureceRange.aspectMask = gpuTexture->aspectMask; - subresoureceRange.levelCount = VK_REMAINING_MIP_LEVELS; - subresoureceRange.layerCount = VK_REMAINING_ARRAY_LAYERS; - insertImageMemoryBarrior(cmdBuff.vkCommandBuffer, - gpuTexture->vkImage, - gpuTexture->accessMask, - VK_ACCESS_TRANSFER_WRITE_BIT, - gpuTexture->currentLayout, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - gpuTexture->targetStage, - VK_PIPELINE_STAGE_TRANSFER_BIT, - subresoureceRange); - - uint regionCount = regions.size(), totalSize = 0u; - vector regionSizes(regionCount); - for (size_t i = 0u; i < regionCount; ++i) { - const BufferTextureCopy ®ion = regions[i]; - uint w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; - uint h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; - totalSize += regionSizes[i] = FormatSize(gpuTexture->format, w, h, region.texExtent.depth); +void CCVKCmdFuncDestroyFence(CCVKGPUDevice *gpuDevice, CCVKGPUFence *gpuFence) { + if (gpuFence->vkFence) { + vkDestroyFence(gpuDevice->vkDevice, gpuFence->vkFence, nullptr); + gpuFence->vkFence = VK_NULL_HANDLE; } +} - CCVKGPUBuffer *stagingBuffer = device->stagingBuffer()->gpuBuffer(); - if (stagingBuffer->size < totalSize) device->stagingBuffer()->resize(nextPowerOf2(totalSize)); - - vector stagingRegions(regionCount); - VkDeviceSize offset = stagingBuffer->startOffset; - for (size_t i = 0u; i < regionCount; ++i) { - const BufferTextureCopy ®ion = regions[i]; - VkBufferImageCopy &stagingRegion = stagingRegions[i]; - stagingRegion.bufferOffset = offset; - stagingRegion.bufferRowLength = region.buffStride; - stagingRegion.bufferImageHeight = region.buffTexHeight; - stagingRegion.imageSubresource = {gpuTexture->aspectMask, region.texSubres.mipLevel, region.texSubres.baseArrayLayer, region.texSubres.layerCount}; - stagingRegion.imageOffset = {region.texOffset.x, region.texOffset.y, region.texOffset.z}; - stagingRegion.imageExtent = {region.texExtent.width, region.texExtent.height, region.texExtent.depth}; - - memcpy(stagingBuffer->mappedData + offset, buffers[i], regionSizes[i]); - offset += regionSizes[i]; - } - - vkCmdCopyBufferToImage(cmdBuff.vkCommandBuffer, stagingBuffer->vkBuffer, gpuTexture->vkImage, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, stagingRegions.size(), stagingRegions.data()); - - bool layoutReady = false; - if (gpuTexture->flags & TextureFlags::GEN_MIPMAP) { - VkFormatProperties formatProperties; - vkGetPhysicalDeviceFormatProperties(device->gpuContext()->physicalDevice, MapVkFormat(gpuTexture->format), &formatProperties); - VkFormatFeatureFlags mipmapFeatures = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT; - - if (formatProperties.optimalTilingFeatures & mipmapFeatures) { - VkImageSubresourceRange mipSubRange{}; - mipSubRange.aspectMask = gpuTexture->aspectMask; - mipSubRange.levelCount = 1; - mipSubRange.layerCount = VK_REMAINING_ARRAY_LAYERS; - - int32_t mipWidth = gpuTexture->width; - int32_t mipHeight = gpuTexture->height; - - for (uint i = 1u; i < gpuTexture->mipLevel; i++) { - mipSubRange.baseMipLevel = i - 1; - insertImageMemoryBarrior(cmdBuff.vkCommandBuffer, - gpuTexture->vkImage, - VK_ACCESS_TRANSFER_WRITE_BIT, - VK_ACCESS_TRANSFER_READ_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_TRANSFER_BIT, - mipSubRange); - - VkImageBlit blit{}; - blit.srcOffsets[1] = {mipWidth, mipHeight, 1}; - blit.srcSubresource.aspectMask = gpuTexture->aspectMask; - blit.srcSubresource.mipLevel = i - 1; - blit.srcSubresource.layerCount = gpuTexture->arrayLayer; - blit.dstOffsets[1] = {mipWidth > 1 ? mipWidth >> 1 : 1, mipHeight > 1 ? mipHeight >> 1 : 1, 1}; - blit.dstSubresource.aspectMask = gpuTexture->aspectMask; - blit.dstSubresource.mipLevel = i; - blit.dstSubresource.layerCount = gpuTexture->arrayLayer; - vkCmdBlitImage(cmdBuff.vkCommandBuffer, - gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - gpuTexture->vkImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - 1, &blit, - VK_FILTER_LINEAR); - - insertImageMemoryBarrior(cmdBuff.vkCommandBuffer, - gpuTexture->vkImage, - VK_ACCESS_TRANSFER_READ_BIT, - gpuTexture->accessMask, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, - gpuTexture->currentLayout, - VK_PIPELINE_STAGE_TRANSFER_BIT, - gpuTexture->targetStage, - mipSubRange); - - if (mipWidth > 1) mipWidth = mipWidth >> 1; - if (mipHeight > 1) mipHeight = mipHeight >> 1; - } - - mipSubRange.baseMipLevel = gpuTexture->mipLevel - 1; - insertImageMemoryBarrior(cmdBuff.vkCommandBuffer, - gpuTexture->vkImage, - VK_ACCESS_TRANSFER_WRITE_BIT, - gpuTexture->accessMask, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - gpuTexture->currentLayout, - VK_PIPELINE_STAGE_TRANSFER_BIT, - gpuTexture->targetStage, - mipSubRange); - layoutReady = true; - } else { - const char *formatName = GFX_FORMAT_INFOS[(uint)gpuTexture->format].name.c_str(); - CC_LOG_WARNING("CCVKCmdFuncCopyBuffersToTexture: generate mipmap for %s is not supported on this platform", formatName); +void CCVKGPURecycleBin::clear() { + for (uint i = 0u; i < _count; i++) { + Resource &res = _resources[i]; + switch (res.type) { + case ObjectType::BUFFER: + if (res.buffer.vkBuffer) { + vmaDestroyBuffer(_device->memoryAllocator, res.buffer.vkBuffer, res.buffer.vmaAllocation); + res.buffer.vkBuffer = VK_NULL_HANDLE; + res.buffer.vmaAllocation = VK_NULL_HANDLE; + } + break; + case ObjectType::TEXTURE: + if (res.image.vkImage) { + vmaDestroyImage(_device->memoryAllocator, res.image.vkImage, res.image.vmaAllocation); + res.image.vkImage = VK_NULL_HANDLE; + res.image.vmaAllocation = VK_NULL_HANDLE; + } + break; + case ObjectType::TEXTURE_VIEW: + if (res.vkImageView) { + vkDestroyImageView(_device->vkDevice, res.vkImageView, nullptr); + res.vkImageView = VK_NULL_HANDLE; + } + break; + case ObjectType::RENDER_PASS: + if (res.gpuRenderPass) { + CCVKCmdFuncDestroyRenderPass(_device, res.gpuRenderPass); + CC_DELETE(res.gpuRenderPass); + res.gpuRenderPass = nullptr; + } + break; + case ObjectType::FRAMEBUFFER: + if (res.gpuFramebuffer) { + CCVKCmdFuncDestroyFramebuffer(_device, res.gpuFramebuffer); + CC_DELETE(res.gpuFramebuffer); + res.gpuFramebuffer = nullptr; + } + break; + case ObjectType::SAMPLER: + if (res.gpuSampler) { + CCVKCmdFuncDestroySampler(_device, res.gpuSampler); + CC_DELETE(res.gpuSampler); + res.gpuSampler = nullptr; + } + break; + case ObjectType::SHADER: + if (res.gpuShader) { + CCVKCmdFuncDestroyShader(_device, res.gpuShader); + CC_DELETE(res.gpuShader); + res.gpuShader = nullptr; + } + break; + case ObjectType::PIPELINE_STATE: + if (res.gpuPipelineState) { + CCVKCmdFuncDestroyPipelineState(_device, res.gpuPipelineState); + CC_DELETE(res.gpuPipelineState); + res.gpuPipelineState = nullptr; + } + break; + case ObjectType::FENCE: + if (res.gpuFence) { + CCVKCmdFuncDestroyFence(_device, res.gpuFence); + CC_DELETE(res.gpuFence); + res.gpuFence = nullptr; + } + break; } + res.type = ObjectType::UNKNOWN; } - - if (!layoutReady) { - insertImageMemoryBarrior(cmdBuff.vkCommandBuffer, - gpuTexture->vkImage, - VK_ACCESS_TRANSFER_WRITE_BIT, - gpuTexture->accessMask, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - gpuTexture->currentLayout, - VK_PIPELINE_STAGE_TRANSFER_BIT, - gpuTexture->targetStage, - subresoureceRange); - } - - endOneTimeCommands(device, &cmdBuff); + _count = 0; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.h b/native/cocos/renderer/gfx-vulkan/VKCommands.h index 60fd171eac..dc5a2c5a4d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.h @@ -31,30 +31,26 @@ struct CCVKStencilCompareMask { }; CC_VULKAN_API void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue); -CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass); -CC_VULKAN_API void CCVKCmdFuncDestroyRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass); CC_VULKAN_API void CCVKCmdFuncCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer); -CC_VULKAN_API void CCVKCmdFuncDestroyBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer); -CC_VULKAN_API void CCVKCmdFuncResizeBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer); -CC_VULKAN_API void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size); CC_VULKAN_API void CCVKCmdFuncCreateTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture); -CC_VULKAN_API void CCVKCmdFuncDestroyTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture); CC_VULKAN_API void CCVKCmdFuncCreateTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView); -CC_VULKAN_API void CCVKCmdFuncDestroyTextureView(CCVKDevice *device, CCVKGPUTextureView *gpuTextureView); -CC_VULKAN_API void CCVKCmdFuncResizeTexture(CCVKDevice *device, CCVKGPUTexture *gpuTexture); +CC_VULKAN_API void CCVKCmdFuncCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass); CC_VULKAN_API void CCVKCmdFuncCreateSampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler); -CC_VULKAN_API void CCVKCmdFuncDestroySampler(CCVKDevice *device, CCVKGPUSampler *gpuSampler); CC_VULKAN_API void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader); -CC_VULKAN_API void CCVKCmdFuncDestroyShader(CCVKDevice *device, CCVKGPUShader *gpuShader); -CC_VULKAN_API void CCVKCmdFuncCreateInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler); -CC_VULKAN_API void CCVKCmdFuncDestroyInputAssembler(CCVKDevice *device, CCVKGPUInputAssembler *gpuInputAssembler); CC_VULKAN_API void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); -CC_VULKAN_API void CCVKCmdFuncDestroyFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); CC_VULKAN_API void CCVKCmdFuncCreatePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); -CC_VULKAN_API void CCVKCmdFuncDestroyPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); +CC_VULKAN_API void CCVKCmdFuncCreateFence(CCVKDevice *device, CCVKGPUFence *gpuFence); -CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions); +CC_VULKAN_API void CCVKCmdFuncUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, void *buffer, uint offset, uint size); +CC_VULKAN_API void CCVKCmdFuncCopyBuffersToTexture(CCVKDevice *device, const BufferDataList &buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopyList ®ions); + +CC_VULKAN_API void CCVKCmdFuncDestroyRenderPass(CCVKGPUDevice *device, CCVKGPURenderPass *gpuRenderPass); +CC_VULKAN_API void CCVKCmdFuncDestroySampler(CCVKGPUDevice *device, CCVKGPUSampler *gpuSampler); +CC_VULKAN_API void CCVKCmdFuncDestroyShader(CCVKGPUDevice *device, CCVKGPUShader *gpuShader); +CC_VULKAN_API void CCVKCmdFuncDestroyFramebuffer(CCVKGPUDevice *device, CCVKGPUFramebuffer *gpuFramebuffer); +CC_VULKAN_API void CCVKCmdFuncDestroyPipelineState(CCVKGPUDevice *device, CCVKGPUPipelineState *gpuPipelineState); +CC_VULKAN_API void CCVKCmdFuncDestroyFence(CCVKGPUDevice *device, CCVKGPUFence *gpuFence); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cc b/native/cocos/renderer/gfx-vulkan/VKDevice.cc index 1b96fb91dd..81167874da 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cc +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cc @@ -26,7 +26,7 @@ namespace gfx { CCVKDevice::CCVKDevice() { _clipSpaceMinZ = 0.0f; - _clipSpaceSignY = -1.0f; + _screenSpaceSignY = -1.0f; _UVSpaceSignY = 1.0f; } @@ -63,8 +63,7 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { //const VkPhysicalDeviceVulkan12Features &deviceVulkan12Features = gpuContext->physicalDeviceVulkan12Features; // only enable the absolute essentials for now - vector requestedValidationLayers{ - }; + vector requestedValidationLayers{}; #if COCOS2D_DEBUG > 0 requestedValidationLayers.push_back("VK_LAYER_KHRONOS_validation"); #endif @@ -259,30 +258,28 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { VK_CHECK(vmaCreateAllocator(&allocatorInfo, &_gpuDevice->memoryAllocator)); - _gpuSemaphorePool = CC_NEW(CCVKGPUSemaphorePool(_gpuDevice)); - _gpuFencePool = CC_NEW(CCVKGPUFencePool(_gpuDevice)); - _gpuDescriptorSetPool = CC_NEW(CCVKGPUDescriptorSetPool(_gpuDevice)); - _gpuCommandBufferPool = CC_NEW(CCVKGPUCommandBufferPool(_gpuDevice)); - - BufferInfo stagingBufferInfo; - stagingBufferInfo.usage = BufferUsage::TRANSFER_SRC; - stagingBufferInfo.memUsage = MemoryUsage::HOST; - stagingBufferInfo.stride = _defaultStagingBufferSize; - stagingBufferInfo.size = _defaultStagingBufferSize; - _stagingBuffer = (CCVKBuffer *)createBuffer(stagingBufferInfo); - QueueInfo queueInfo; queueInfo.type = QueueType::GRAPHICS; - queueInfo.forceSync = true; + //queueInfo.forceSync = true; _queue = createQueue(queueInfo); + _gpuFencePool = CC_NEW(CCVKGPUFencePool(_gpuDevice)); + _gpuRecycleBin = CC_NEW(CCVKGPURecycleBin(_gpuDevice)); + _gpuTransportHub = CC_NEW(CCVKGPUTransportHub(_gpuDevice)); + _gpuSemaphorePool = CC_NEW(CCVKGPUSemaphorePool(_gpuDevice)); + _gpuDescriptorSetPool = CC_NEW(CCVKGPUDescriptorSetPool(_gpuDevice)); + _gpuCommandBufferPool = CC_NEW(CCVKGPUCommandBufferPool(_gpuDevice)); + _gpuStagingBufferPool = CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice)); + + _gpuTransportHub->link(((CCVKQueue *)_queue)->gpuQueue(), _gpuFencePool, _gpuCommandBufferPool); + for (uint i = 0u; i < gpuContext->swapchainCreateInfo.minImageCount; i++) { TextureInfo depthStencilTexInfo; depthStencilTexInfo.type = TextureType::TEX2D; depthStencilTexInfo.usage = TextureUsageBit::DEPTH_STENCIL_ATTACHMENT | TextureUsageBit::SAMPLED; depthStencilTexInfo.format = _context->getDepthStencilFormat(); - depthStencilTexInfo.width = 1; - depthStencilTexInfo.height = 1; + depthStencilTexInfo.width = _width; + depthStencilTexInfo.height = _height; CCVKTexture *texture = (CCVKTexture *)createTexture(depthStencilTexInfo); _depthStencilTextures.push_back(texture); } @@ -328,6 +325,8 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { } void CCVKDevice::destroy() { + VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice)); + if (_gpuSwapchain) { if (_gpuSwapchain->vkSwapchain != VK_NULL_HANDLE) { _gpuSwapchain->depthStencilImageViews.clear(); @@ -352,21 +351,22 @@ void CCVKDevice::destroy() { vkDestroySwapchainKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, nullptr); _gpuSwapchain->vkSwapchain = VK_NULL_HANDLE; } - - CC_DELETE(_gpuSwapchain); - _gpuSwapchain = nullptr; } for (CCVKTexture *texture : _depthStencilTextures) { CC_SAFE_DESTROY(texture); } _depthStencilTextures.clear(); + _gpuRecycleBin->clear(); - CC_SAFE_DESTROY(_stagingBuffer); CC_SAFE_DESTROY(_queue); + CC_SAFE_DELETE(_gpuSwapchain); + CC_SAFE_DELETE(_gpuStagingBufferPool); CC_SAFE_DELETE(_gpuCommandBufferPool); CC_SAFE_DELETE(_gpuDescriptorSetPool); CC_SAFE_DELETE(_gpuSemaphorePool); + CC_SAFE_DELETE(_gpuTransportHub); + CC_SAFE_DELETE(_gpuRecycleBin); CC_SAFE_DELETE(_gpuFencePool); if (_gpuDevice) { @@ -482,18 +482,13 @@ void CCVKDevice::buildSwapchain() { void CCVKDevice::acquire() { if (!_swapchainReady) return; - VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice)); _gpuSemaphorePool->reset(); - _gpuFencePool->reset(); - _gpuDescriptorSetPool->reset(); - _gpuCommandBufferPool->reset(); - VkSemaphore acquireSemaphore = _gpuSemaphorePool->alloc(); VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, ~0ull, acquireSemaphore, VK_NULL_HANDLE, &_gpuSwapchain->curImageIndex)); - // Clear queue stats CCVKQueue *queue = (CCVKQueue *)_queue; + // Clear queue stats queue->_numDrawCalls = 0; queue->_numInstances = 0; queue->_numTriangles = 0; @@ -517,6 +512,21 @@ void CCVKDevice::present() { presentInfo.pImageIndices = &_gpuSwapchain->curImageIndex; VK_CHECK(vkQueuePresentKHR(queue->gpuQueue()->vkQueue, &presentInfo)); + + // TODO: these can be moved to acquire-time after pipeline refactoring, + // which should guarantee that no transfer operation will be issued before acquiring + + VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice)); + + queue->gpuQueue()->lastAutoFence = VK_NULL_HANDLE; + // reset everything only when no pending commands + if (_gpuTransportHub->empty()) { + _gpuFencePool->reset(); + _gpuRecycleBin->clear(); + _gpuDescriptorSetPool->reset(); + _gpuCommandBufferPool->reset(); + _gpuStagingBufferPool->reset(); + } } CommandBuffer *CCVKDevice::createCommandBuffer(const CommandBufferInfo &info) { @@ -636,8 +646,8 @@ PipelineState *CCVKDevice::createPipelineState(const PipelineStateInfo &info) { return nullptr; } -void CCVKDevice::copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - CCVKCmdFuncCopyBuffersToTexture(this, buffers.datas.data(), ((CCVKTexture *)dst)->gpuTexture(), regions); +void CCVKDevice::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { + CCVKCmdFuncCopyBuffersToTexture(this, buffers, ((CCVKTexture *)dst)->gpuTexture(), regions); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.h b/native/cocos/renderer/gfx-vulkan/VKDevice.h index 6bdce48d84..f49808d555 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.h +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.h @@ -4,16 +4,21 @@ namespace cc { namespace gfx { -class CCVKGPUContext; -class CCVKGPUDevice; -class CCVKGPUSwapchain; -class CCVKGPUSemaphorePool; -class CCVKGPUFencePool; -class CCVKGPUDescriptorSetPool; -class CCVKGPUCommandBufferPool; +class CCVKBuffer; class CCVKTexture; class CCVKRenderPass; -class CCVKBuffer; + +class CCVKGPUDevice; +class CCVKGPUContext; +class CCVKGPUSwapchain; + +class CCVKGPUFencePool; +class CCVKGPURecycleBin; +class CCVKGPUTransportHub; +class CCVKGPUSemaphorePool; +class CCVKGPUDescriptorSetPool; +class CCVKGPUCommandBufferPool; +class CCVKGPUStagingBufferPool; class CC_VULKAN_API CCVKDevice : public Device { public: @@ -39,7 +44,7 @@ public: virtual Framebuffer *createFramebuffer(const FramebufferInfo &info) override; virtual BindingLayout *createBindingLayout(const BindingLayoutInfo &info) override; virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override; - virtual void copyBuffersToTexture(const DataArray &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; + virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) override; CC_INLINE bool checkExtension(const String &extension) const { return std::find_if(_extensions.begin(), _extensions.end(), @@ -51,11 +56,13 @@ public: CCVKGPUContext *gpuContext() const; CC_INLINE CCVKGPUDevice *gpuDevice() const { return _gpuDevice; } CC_INLINE CCVKGPUSwapchain *gpuSwapchain() { return _gpuSwapchain; } - CC_INLINE CCVKGPUSemaphorePool *gpuSemaphorePool() { return _gpuSemaphorePool; } CC_INLINE CCVKGPUFencePool *gpuFencePool() { return _gpuFencePool; } + CC_INLINE CCVKGPURecycleBin *gpuRecycleBin() { return _gpuRecycleBin; } + CC_INLINE CCVKGPUTransportHub *gpuTransportHub() { return _gpuTransportHub; } + CC_INLINE CCVKGPUSemaphorePool *gpuSemaphorePool() { return _gpuSemaphorePool; } CC_INLINE CCVKGPUDescriptorSetPool *gpuDescriptorSetPool() { return _gpuDescriptorSetPool; } CC_INLINE CCVKGPUCommandBufferPool *gpuCommandBufferPool() { return _gpuCommandBufferPool; } - CC_INLINE CCVKBuffer *stagingBuffer() { return _stagingBuffer; } + CC_INLINE CCVKGPUStagingBufferPool *gpuStagingBufferPool() { return _gpuStagingBufferPool; } CC_INLINE const vector &getLayers() const { return _layers; } CC_INLINE const vector &getExtensions() const { return _extensions; } CC_INLINE bool isSwapchainReady() const { return _swapchainReady; } @@ -68,15 +75,15 @@ private: void buildSwapchain(); CCVKGPUDevice *_gpuDevice = nullptr; - CCVKGPUSemaphorePool *_gpuSemaphorePool = nullptr; CCVKGPUFencePool *_gpuFencePool = nullptr; + CCVKGPURecycleBin *_gpuRecycleBin = nullptr; + CCVKGPUTransportHub *_gpuTransportHub = nullptr; + CCVKGPUSemaphorePool *_gpuSemaphorePool = nullptr; CCVKGPUDescriptorSetPool *_gpuDescriptorSetPool = nullptr; CCVKGPUCommandBufferPool *_gpuCommandBufferPool = nullptr; + CCVKGPUStagingBufferPool *_gpuStagingBufferPool = nullptr; CCVKGPUSwapchain *_gpuSwapchain = nullptr; vector _depthStencilTextures; - CCVKBuffer *_stagingBuffer = nullptr; - - uint32_t _defaultStagingBufferSize = 1024; vector _layers; vector _extensions; diff --git a/native/cocos/renderer/gfx-vulkan/VKFence.cc b/native/cocos/renderer/gfx-vulkan/VKFence.cc index 19d29e08d3..21f12a1601 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFence.cc +++ b/native/cocos/renderer/gfx-vulkan/VKFence.cc @@ -2,7 +2,7 @@ #include "VKDevice.h" #include "VKFence.h" -#include "VKGPUObjects.h" +#include "VKCommands.h" namespace cc { namespace gfx { @@ -17,12 +17,11 @@ CCVKFence::~CCVKFence() { bool CCVKFence::initialize(const FenceInfo &info) { _gpuFence = CC_NEW(CCVKGPUFence); if (!_gpuFence) { - CC_LOG_ERROR("GLES2Fence: CC_NEW CCVKGPUFence failed."); + CC_LOG_ERROR("CCVKFence: CC_NEW CCVKGPUFence failed."); return false; } - VkFenceCreateInfo createInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO}; - VK_CHECK(vkCreateFence(((CCVKDevice *)_device)->gpuDevice()->vkDevice, &createInfo, nullptr, &_gpuFence->vkFence)); + CCVKCmdFuncCreateFence((CCVKDevice *)_device, _gpuFence); _status = Status::SUCCESS; return true; @@ -30,14 +29,13 @@ bool CCVKFence::initialize(const FenceInfo &info) { void CCVKFence::destroy() { if (_gpuFence) { - vkDestroyFence(((CCVKDevice *)_device)->gpuDevice()->vkDevice, _gpuFence->vkFence, nullptr); - - CC_DELETE(_gpuFence); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuFence); _gpuFence = nullptr; } _status = Status::UNREADY; } +// TODO: move these two to device void CCVKFence::wait() { VK_CHECK(vkWaitForFences(((CCVKDevice *)_device)->gpuDevice()->vkDevice, 1, &_gpuFence->vkFence, VK_TRUE, DEFAULT_FENCE_TIMEOUT)); } diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cc b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cc index 835adbb17c..daeb98e289 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cc +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cc @@ -45,8 +45,7 @@ bool CCVKFramebuffer::initialize(const FramebufferInfo &info) { void CCVKFramebuffer::destroy() { if (_gpuFBO) { - CCVKCmdFuncDestroyFramebuffer((CCVKDevice *)_device, _gpuFBO); - CC_DELETE(_gpuFBO); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuFBO); _gpuFBO = nullptr; } diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index a8e779910d..f514db080c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -55,14 +55,15 @@ public: uint height = 0u; uint depth = 1u; uint size = 0u; - uint arrayLayer = 1u; - uint mipLevel = 1u; + uint arrayLayers = 1u; + uint mipLevels = 1u; SampleCount samples = SampleCount::X1; TextureFlags flags = TextureFlagBit::NONE; bool isPowerOf2 = false; VkImage vkImage = VK_NULL_HANDLE; VmaAllocation vmaAllocation = VK_NULL_HANDLE; + VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; VkImageLayout currentLayout = VK_IMAGE_LAYOUT_UNDEFINED; VkAccessFlags accessMask = VK_ACCESS_SHADER_READ_BIT; VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -76,6 +77,8 @@ public: Format format = Format::UNKNOWN; uint baseLevel = 0u; uint levelCount = 1u; + uint baseLayer = 0u; + uint layerCount = 1u; VkImageView vkImageView = VK_NULL_HANDLE; }; @@ -124,6 +127,7 @@ public: VkSemaphore nextSignalSemaphore = VK_NULL_HANDLE; VkPipelineStageFlags submitStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; CachedArray commandBuffers; + VkFence lastAutoFence = VK_NULL_HANDLE; }; class CCVKGPUBuffer : public Object { @@ -239,48 +243,6 @@ public: VkFence vkFence; }; -class CCVKGPUSemaphorePool : public Object { -public: - CCVKGPUSemaphorePool(CCVKGPUDevice *device) - : _device(device) { - } - - ~CCVKGPUSemaphorePool() { - for (VkSemaphore semaphore : _semaphores) { - vkDestroySemaphore(_device->vkDevice, semaphore, nullptr); - } - _semaphores.clear(); - _count = 0; - } - - VkSemaphore alloc() { - if (_count < _semaphores.size()) { - return _semaphores[_count++]; - } - - VkSemaphore semaphore = VK_NULL_HANDLE; - VkSemaphoreCreateInfo createInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; - VK_CHECK(vkCreateSemaphore(_device->vkDevice, &createInfo, nullptr, &semaphore)); - _semaphores.push_back(semaphore); - _count++; - - return semaphore; - } - - void reset() { - _count = 0; - } - - uint size() { - return _count; - } - -private: - CCVKGPUDevice *_device; - uint _count = 0; - vector _semaphores; -}; - class CCVKGPUFencePool : public Object { public: CCVKGPUFencePool(CCVKGPUDevice *device) @@ -322,10 +284,52 @@ public: private: CCVKGPUDevice *_device; - uint _count = 0; + uint _count = 0u; vector _fences; }; +class CCVKGPUSemaphorePool : public Object { +public: + CCVKGPUSemaphorePool(CCVKGPUDevice *device) + : _device(device) { + } + + ~CCVKGPUSemaphorePool() { + for (VkSemaphore semaphore : _semaphores) { + vkDestroySemaphore(_device->vkDevice, semaphore, nullptr); + } + _semaphores.clear(); + _count = 0; + } + + VkSemaphore alloc() { + if (_count < _semaphores.size()) { + return _semaphores[_count++]; + } + + VkSemaphore semaphore = VK_NULL_HANDLE; + VkSemaphoreCreateInfo createInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}; + VK_CHECK(vkCreateSemaphore(_device->vkDevice, &createInfo, nullptr, &semaphore)); + _semaphores.push_back(semaphore); + _count++; + + return semaphore; + } + + void reset() { + _count = 0; + } + + uint size() { + return _count; + } + +private: + CCVKGPUDevice *_device; + uint _count = 0u; + vector _semaphores; +}; + class CCVKGPUDescriptorSetPool : public Object { public: CCVKGPUDescriptorSetPool(CCVKGPUDevice *device) @@ -395,12 +399,6 @@ private: class CCVKGPUCommandBufferPool : public Object { public: - struct CommandBufferPool { - VkCommandPool vkCommandPool = VK_NULL_HANDLE; - CachedArray commandBuffers[2]; - CachedArray usedCommandBuffers[2]; - }; - CCVKGPUCommandBufferPool(CCVKGPUDevice *device) : _device(device) { } @@ -465,11 +463,229 @@ public: } private: + struct CommandBufferPool { + VkCommandPool vkCommandPool = VK_NULL_HANDLE; + CachedArray commandBuffers[2]; + CachedArray usedCommandBuffers[2]; + }; + CCVKGPUDevice *_device = nullptr; map _pools; vector _counts; }; +class CCVKGPUStagingBufferPool : public Object { +public: + CCVKGPUStagingBufferPool(CCVKGPUDevice *device) + : _device(device) { + } + + ~CCVKGPUStagingBufferPool() { + for (Buffer &buffer : _pool) { + vmaDestroyBuffer(_device->memoryAllocator, buffer.vkBuffer, buffer.vmaAllocation); + } + _pool.clear(); + } + + void alloc(CCVKGPUBuffer *gpuBuffer) { + size_t bufferCount = _pool.size(); + Buffer *buffer = nullptr; + for (size_t idx = 0u; idx < bufferCount; idx++) { + Buffer *cur = &_pool[idx]; + if (cur->size - cur->curOffset > gpuBuffer->size) { + buffer = cur; + break; + } + } + if (!buffer) { + _pool.resize(bufferCount + 1); + buffer = &_pool.back(); + VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; + bufferInfo.size = buffer->size; + bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; + VmaAllocationCreateInfo allocInfo{}; + allocInfo.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT; + allocInfo.usage = VMA_MEMORY_USAGE_CPU_ONLY; + VmaAllocationInfo res; + VK_CHECK(vmaCreateBuffer(_device->memoryAllocator, &bufferInfo, &allocInfo, &buffer->vkBuffer, &buffer->vmaAllocation, &res)); + buffer->mappedData = (uint8_t *)res.pMappedData; + } + gpuBuffer->vkBuffer = buffer->vkBuffer; + gpuBuffer->startOffset = buffer->curOffset; + gpuBuffer->mappedData = buffer->mappedData + buffer->curOffset; + buffer->curOffset += gpuBuffer->size; + } + + void reset() { + for (Buffer &buffer : _pool) { + buffer.curOffset = 0u; + } + } + +private: + struct Buffer { + VkBuffer vkBuffer = VK_NULL_HANDLE; + VkDeviceSize size = 16 * 1024 * 1024; // 16M per block by default + uint8_t *mappedData = nullptr; + VmaAllocation vmaAllocation = VK_NULL_HANDLE; + + VkDeviceSize curOffset = 0u; + }; + + CCVKGPUDevice *_device = nullptr; + vector _pool; +}; + +class CCVKGPURecycleBin : public Object { +public: + CCVKGPURecycleBin(CCVKGPUDevice *device) + : _device(device) { + _resources.resize(16); + } + +#define DEFINE_COLLECT_FN(_type, typeValue, expr) \ + void collect(_type *gpuRes) { \ + if (_resources.size() <= _count) { \ + _resources.resize(_count * 2); \ + } \ + Resource &res = _resources[_count++]; \ + res.type = typeValue; \ + expr; \ + } + DEFINE_COLLECT_FN(CCVKGPUBuffer, ObjectType::BUFFER, (res.buffer = {gpuRes->vkBuffer, gpuRes->vmaAllocation})) + DEFINE_COLLECT_FN(CCVKGPUTexture, ObjectType::TEXTURE, (res.image = {gpuRes->vkImage, gpuRes->vmaAllocation})) + DEFINE_COLLECT_FN(CCVKGPUTextureView, ObjectType::TEXTURE_VIEW, res.vkImageView = gpuRes->vkImageView) + DEFINE_COLLECT_FN(CCVKGPURenderPass, ObjectType::RENDER_PASS, res.gpuRenderPass = gpuRes) + DEFINE_COLLECT_FN(CCVKGPUFramebuffer, ObjectType::FRAMEBUFFER, res.gpuFramebuffer = gpuRes) + DEFINE_COLLECT_FN(CCVKGPUSampler, ObjectType::SAMPLER, res.gpuSampler = gpuRes) + DEFINE_COLLECT_FN(CCVKGPUShader, ObjectType::SHADER, res.gpuShader = gpuRes) + DEFINE_COLLECT_FN(CCVKGPUPipelineState, ObjectType::PIPELINE_STATE, res.gpuPipelineState = gpuRes) + DEFINE_COLLECT_FN(CCVKGPUFence, ObjectType::FENCE, res.gpuFence = gpuRes) + + void clear(); + +private: + struct Buffer { + VkBuffer vkBuffer; + VmaAllocation vmaAllocation; + }; + struct Image { + VkImage vkImage; + VmaAllocation vmaAllocation; + }; + struct Resource { + ObjectType type = ObjectType::UNKNOWN; + union { + // resizable resources, cannot take over directly + // or descriptor sets won't work + Buffer buffer; + Image image; + VkImageView vkImageView; + + CCVKGPURenderPass *gpuRenderPass; + CCVKGPUFramebuffer *gpuFramebuffer; + CCVKGPUSampler *gpuSampler; + CCVKGPUShader *gpuShader; + CCVKGPUPipelineState *gpuPipelineState; + CCVKGPUFence *gpuFence; + }; + }; + CCVKGPUDevice *_device = nullptr; + vector _resources; + uint _count = 0u; +}; + +#define ASYNC_SUBMISSION +class CCVKGPUTransportHub : public Object { +public: + CCVKGPUTransportHub(CCVKGPUDevice *device) + : _device(device) { + _transfers.resize(16); + } + + void link(CCVKGPUQueue *queue, CCVKGPUFencePool *fencePool, CCVKGPUCommandBufferPool *commandBufferPool) { + _queue = queue; + _fencePool = fencePool; + _commandBufferPool = commandBufferPool; + + _cmdBuff.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + _cmdBuff.queueFamilyIndex = _queue->queueFamilyIndex; + } + + CC_INLINE bool empty() { + return !_cmdBuff.vkCommandBuffer && !_count; + } + + void checkIn(void *dst, const void *src, size_t size) { + if (_transfers.size() <= _count) { + _transfers.resize(_count * 2); + } + Transfer &transfer = _transfers[_count++]; + transfer.dst = dst; + transfer.src = src; + transfer.size = size; + } + + template + void checkIn(const TFunc &record) { + if (!_cmdBuff.vkCommandBuffer) { + _commandBufferPool->request(&_cmdBuff); + VkCommandBufferBeginInfo beginInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; + beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + VK_CHECK(vkBeginCommandBuffer(_cmdBuff.vkCommandBuffer, &beginInfo)); + } + + record(_cmdBuff.vkCommandBuffer); + +#ifndef ASYNC_SUBMISSION + VK_CHECK(vkEndCommandBuffer(_cmdBuff.vkCommandBuffer)); + VkFence fence = _fencePool->alloc(); + VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO}; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &_cmdBuff.vkCommandBuffer; + VK_CHECK(vkQueueSubmit(_queue->vkQueue, 1, &submitInfo, fence)); + VK_CHECK(vkWaitForFences(_device->vkDevice, 1, &fence, VK_TRUE, DEFAULT_FENCE_TIMEOUT)); + _commandBufferPool->yield(&_cmdBuff); +#endif // ASYNC_SUBMISSION + } + + void depart() { + if (_cmdBuff.vkCommandBuffer) { + VK_CHECK(vkEndCommandBuffer(_cmdBuff.vkCommandBuffer)); + _queue->commandBuffers.push(_cmdBuff.vkCommandBuffer); + _commandBufferPool->yield(&_cmdBuff); + } + + if (_count) { + if (_queue->lastAutoFence) { + vkWaitForFences(_device->vkDevice, 1, &_queue->lastAutoFence, VK_TRUE, DEFAULT_FENCE_TIMEOUT); + _queue->lastAutoFence = VK_NULL_HANDLE; + } + for (const Transfer &transfer : _transfers) { + memcpy(transfer.dst, transfer.src, transfer.size); + } + _count = 0u; + } + } + +private: + struct Transfer { + void *dst = nullptr; + const void *src = nullptr; + size_t size = 0u; + }; + + CCVKGPUDevice *_device = nullptr; + + CCVKGPUQueue *_queue = nullptr; + CCVKGPUFencePool *_fencePool = nullptr; + CCVKGPUCommandBufferPool *_commandBufferPool = nullptr; + + CCVKGPUCommandBuffer _cmdBuff; + vector _transfers; + uint _count = 0u; +}; + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cc b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cc index ee4768732b..3c8b069d9e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cc +++ b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKBuffer.h" +#include "VKDevice.h" #include "VKCommands.h" #include "VKInputAssembler.h" @@ -19,18 +20,19 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) { _vertexBuffers = info.vertexBuffers; _indexBuffer = info.indexBuffer; _indirectBuffer = info.indirectBuffer; + size_t vbCount = _vertexBuffers.size(); if (_indexBuffer) { _indexCount = _indexBuffer->getCount(); - } else if (_vertexBuffers.size()) { + } else if (vbCount) { _vertexCount = _vertexBuffers[0]->getCount(); } _gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler); _gpuInputAssembler->attributes = _attributes; - _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); + _gpuInputAssembler->gpuVertexBuffers.resize(vbCount); - for (size_t i = 0u; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { + for (size_t i = 0u; i < vbCount; ++i) { CCVKBuffer *vb = (CCVKBuffer *)_vertexBuffers[i]; _gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer(); } @@ -43,7 +45,14 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) { _gpuInputAssembler->gpuIndirectBuffer = static_cast(info.indirectBuffer)->gpuBuffer(); } - CCVKCmdFuncCreateInputAssembler((CCVKDevice *)_device, _gpuInputAssembler); + _gpuInputAssembler->vertexBuffers.resize(vbCount); + _gpuInputAssembler->vertexBufferOffsets.resize(vbCount); + + for (size_t i = 0u; i < vbCount; i++) { + _gpuInputAssembler->vertexBuffers[i] = _gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer; + _gpuInputAssembler->vertexBufferOffsets[i] = _gpuInputAssembler->gpuVertexBuffers[i]->startOffset; + } + _attributesHash = computeAttributesHash(); _status = Status::SUCCESS; @@ -52,7 +61,8 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) { void CCVKInputAssembler::destroy() { if (_gpuInputAssembler) { - CCVKCmdFuncDestroyInputAssembler((CCVKDevice *)_device, _gpuInputAssembler); + _gpuInputAssembler->vertexBuffers.clear(); + _gpuInputAssembler->vertexBufferOffsets.clear(); CC_DELETE(_gpuInputAssembler); _gpuInputAssembler = nullptr; } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cc b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cc index 714dea3e41..31e6187624 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cc +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKCommands.h" +#include "VKDevice.h" #include "VKPipelineState.h" #include "VKRenderPass.h" #include "VKShader.h" @@ -44,8 +45,7 @@ bool CCVKPipelineState::initialize(const PipelineStateInfo &info) { void CCVKPipelineState::destroy() { if (_gpuPipelineState) { - CCVKCmdFuncDestroyPipelineState((CCVKDevice *)_device, _gpuPipelineState); - CC_DELETE(_gpuPipelineState); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuPipelineState); _gpuPipelineState = nullptr; } _status = Status::UNREADY; diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.cc b/native/cocos/renderer/gfx-vulkan/VKQueue.cc index b3aa58f472..3595505bd4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.cc +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.cc @@ -18,7 +18,7 @@ CCVKQueue::~CCVKQueue() { bool CCVKQueue::initialize(const QueueInfo &info) { _type = info.type; - _isAsync = !info.forceSync; + _isAsync = true; _gpuQueue = CC_NEW(CCVKGPUQueue); _gpuQueue->type = _type; @@ -39,8 +39,9 @@ void CCVKQueue::destroy() { void CCVKQueue::submit(const vector &cmdBuffs, Fence *fence) { CCVKDevice *device = (CCVKDevice *)_device; - _gpuQueue->commandBuffers.clear(); + device->gpuTransportHub()->depart(); + uint count = cmdBuffs.size(); for (uint i = 0u; i < count; ++i) { CCVKCommandBuffer *cmdBuffer = (CCVKCommandBuffer *)cmdBuffs[i]; @@ -54,23 +55,24 @@ void CCVKQueue::submit(const vector &cmdBuffs, Fence *fence) { } VkSubmitInfo submitInfo{VK_STRUCTURE_TYPE_SUBMIT_INFO}; - submitInfo.waitSemaphoreCount = 1; + submitInfo.waitSemaphoreCount = _gpuQueue->nextWaitSemaphore ? 1 : 0; submitInfo.pWaitSemaphores = &_gpuQueue->nextWaitSemaphore; submitInfo.pWaitDstStageMask = &_gpuQueue->submitStageMask; - submitInfo.commandBufferCount = count; + submitInfo.commandBufferCount = _gpuQueue->commandBuffers.size(); submitInfo.pCommandBuffers = &_gpuQueue->commandBuffers[0]; - submitInfo.signalSemaphoreCount = 1; + submitInfo.signalSemaphoreCount = _gpuQueue->nextSignalSemaphore ? 1 : 0; submitInfo.pSignalSemaphores = &_gpuQueue->nextSignalSemaphore; - if (_isAsync) { - VkFence vkFence = fence ? ((CCVKFence *)fence)->gpuFence()->vkFence : VK_NULL_HANDLE; - VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence)); + VkFence vkFence = VK_NULL_HANDLE; + if (fence) { + vkFence = ((CCVKFence *)fence)->gpuFence()->vkFence; } else { - VkFence vkFence = fence ? ((CCVKFence *)fence)->gpuFence()->vkFence : device->gpuFencePool()->alloc(); - VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence)); - VK_CHECK(vkWaitForFences(device->gpuDevice()->vkDevice, 1, &vkFence, VK_TRUE, DEFAULT_FENCE_TIMEOUT)); + vkFence = device->gpuFencePool()->alloc(); + _gpuQueue->lastAutoFence = vkFence; } + VK_CHECK(vkQueueSubmit(_gpuQueue->vkQueue, 1, &submitInfo, vkFence)); + _gpuQueue->nextWaitSemaphore = _gpuQueue->nextSignalSemaphore; _gpuQueue->nextSignalSemaphore = device->gpuSemaphorePool()->alloc(); } diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cc b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cc index cf53d7e3b3..55d1ffabd1 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cc +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKCommands.h" +#include "VKDevice.h" #include "VKRenderPass.h" namespace cc { @@ -32,8 +33,7 @@ bool CCVKRenderPass::initialize(const RenderPassInfo &info) { void CCVKRenderPass::destroy() { if (_gpuRenderPass) { - CCVKCmdFuncDestroyRenderPass((CCVKDevice *)_device, _gpuRenderPass); - CC_DELETE(_gpuRenderPass); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuRenderPass); _gpuRenderPass = nullptr; } diff --git a/native/cocos/renderer/gfx-vulkan/VKSampler.cc b/native/cocos/renderer/gfx-vulkan/VKSampler.cc index 0bf9b3871b..0e9f7bab6e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSampler.cc +++ b/native/cocos/renderer/gfx-vulkan/VKSampler.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKCommands.h" +#include "VKDevice.h" #include "VKSampler.h" namespace cc { @@ -51,8 +52,7 @@ bool CCVKSampler::initialize(const SamplerInfo &info) { void CCVKSampler::destroy() { if (_gpuSampler) { - CCVKCmdFuncDestroySampler((CCVKDevice *)_device, _gpuSampler); - CC_DELETE(_gpuSampler); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuSampler); _gpuSampler = nullptr; } _status = Status::UNREADY; diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.cc b/native/cocos/renderer/gfx-vulkan/VKShader.cc index cc1809e396..95997db314 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.cc +++ b/native/cocos/renderer/gfx-vulkan/VKShader.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKCommands.h" +#include "VKDevice.h" #include "VKShader.h" namespace cc { @@ -38,8 +39,7 @@ bool CCVKShader::initialize(const ShaderInfo &info) { void CCVKShader::destroy() { if (_gpuShader) { - CCVKCmdFuncDestroyShader((CCVKDevice *)_device, _gpuShader); - CC_DELETE(_gpuShader); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuShader); _gpuShader = nullptr; } diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.cc b/native/cocos/renderer/gfx-vulkan/VKTexture.cc index cd39c9303a..6146cac035 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.cc +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.cc @@ -1,6 +1,7 @@ #include "VKStd.h" #include "VKCommands.h" +#include "VKDevice.h" #include "VKTexture.h" namespace cc { @@ -20,8 +21,8 @@ bool CCVKTexture::initialize(const TextureInfo &info) { _width = info.width; _height = info.height; _depth = info.depth; - _arrayLayer = info.arrayLayer; - _mipLevel = info.mipLevel; + _layerCount = info.layerCount; + _levelCount = info.levelCount; _samples = info.samples; _flags = info.flags; _size = FormatSize(_format, _width, _height, _depth); @@ -72,8 +73,8 @@ bool CCVKTexture::initialize(const TextureInfo &info) { _gpuTexture->height = _height; _gpuTexture->depth = _depth; _gpuTexture->size = _size; - _gpuTexture->arrayLayer = _arrayLayer; - _gpuTexture->mipLevel = _mipLevel; + _gpuTexture->arrayLayers = _layerCount; + _gpuTexture->mipLevels = _levelCount; _gpuTexture->samples = _samples; _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); @@ -81,62 +82,61 @@ bool CCVKTexture::initialize(const TextureInfo &info) { CCVKCmdFuncCreateTexture((CCVKDevice *)_device, _gpuTexture); _device->getMemoryStatus().textureSize += _size; - TextureViewInfo textureViewInfo; - textureViewInfo.texture = this; - textureViewInfo.type = _type; - textureViewInfo.format = _format; - textureViewInfo.baseLevel = 0; - textureViewInfo.levelCount = _mipLevel; - textureViewInfo.baseLayer = 0; - textureViewInfo.layerCount = _arrayLayer; - createTextureView(textureViewInfo); + _gpuTextureView = CC_NEW(CCVKGPUTextureView); + createTextureView(); _status = Status::SUCCESS; return true; } bool CCVKTexture::initialize(const TextureViewInfo &info) { - if (info.texture) { - _type = info.texture->getType(); - _format = info.texture->getFormat(); - _arrayLayer = info.texture->getArrayLayer(); - _mipLevel = info.texture->getMipLevel(); - _usage = info.texture->getUsage(); - _width = info.texture->getWidth(); - _height = info.texture->getHeight(); - _depth = info.texture->getDepth(); - _samples = info.texture->getSamples(); - _flags = info.texture->getFlags(); - _size = FormatSize(_format, _width, _height, _depth); + if (!info.texture) { + _status = Status::FAILED; + return false; } - createTextureView(info); + _type = info.texture->getType(); + _format = info.format; + _baseLayer = info.baseLayer; + _layerCount = info.layerCount; + _baseLevel = info.baseLevel; + _levelCount = info.levelCount; + _usage = info.texture->getUsage(); + _width = info.texture->getWidth(); + _height = info.texture->getHeight(); + _depth = info.texture->getDepth(); + _samples = info.texture->getSamples(); + _flags = info.texture->getFlags(); + _size = FormatSize(_format, _width, _height, _depth); + + _gpuTexture = ((CCVKTexture *)info.texture)->gpuTexture(); + _gpuTextureView = CC_NEW(CCVKGPUTextureView); + createTextureView(); _status = Status::SUCCESS; return true; } -void CCVKTexture::createTextureView(const TextureViewInfo &info) { - if (!_gpuTextureView) { - _gpuTextureView = CC_NEW(CCVKGPUTextureView); - } - _gpuTextureView->gpuTexture = info.texture ? static_cast(info.texture)->gpuTexture() : nullptr; - _gpuTextureView->type = info.type; - _gpuTextureView->format = info.format; - _gpuTextureView->baseLevel = info.baseLevel; - _gpuTextureView->levelCount = info.levelCount; +void CCVKTexture::createTextureView() { + _gpuTextureView->gpuTexture = _gpuTexture; + _gpuTextureView->type = _type; + _gpuTextureView->format = _format; + _gpuTextureView->baseLevel = _baseLevel; + _gpuTextureView->levelCount = _levelCount; + _gpuTextureView->baseLayer = _baseLayer; + _gpuTextureView->layerCount = _layerCount; CCVKCmdFuncCreateTextureView((CCVKDevice *)_device, _gpuTextureView); } void CCVKTexture::destroy() { if (_gpuTextureView) { - CCVKCmdFuncDestroyTextureView((CCVKDevice *)_device, _gpuTextureView); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTextureView); CC_DELETE(_gpuTextureView); _gpuTextureView = nullptr; } if (_gpuTexture) { - CCVKCmdFuncDestroyTexture((CCVKDevice *)_device, _gpuTexture); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture); _device->getMemoryStatus().textureSize -= _size; CC_DELETE(_gpuTexture); _gpuTexture = nullptr; @@ -158,17 +158,18 @@ void CCVKTexture::resize(uint width, uint height) { _height = height; _size = size; + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTextureView); + ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture); + MemoryStatus &status = _device->getMemoryStatus(); _gpuTexture->width = _width; _gpuTexture->height = _height; _gpuTexture->size = _size; - CCVKCmdFuncResizeTexture((CCVKDevice *)_device, _gpuTexture); + + CCVKCmdFuncCreateTexture((CCVKDevice *)_device, _gpuTexture); status.bufferSize -= old_size; status.bufferSize += _size; - CCVKCmdFuncDestroyTextureView((CCVKDevice *)_device, _gpuTextureView); - - _gpuTextureView->gpuTexture = _gpuTexture; CCVKCmdFuncCreateTextureView((CCVKDevice *)_device, _gpuTextureView); if (_buffer) { diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.h b/native/cocos/renderer/gfx-vulkan/VKTexture.h index 7075087427..4414a90fbd 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.h +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.h @@ -22,7 +22,7 @@ public: CC_INLINE CCVKGPUTextureView *gpuTextureView() const { return _gpuTextureView; } private: - void createTextureView(const TextureViewInfo &info); + void createTextureView(); CCVKGPUTexture *_gpuTexture = nullptr; CCVKGPUTextureView *_gpuTextureView = nullptr; diff --git a/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp index 94b83fb25a..d71b3ab170 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.cpp @@ -3483,7 +3483,7 @@ static bool js_gfx_TextureInfo_get_arrayLayer(se::State& s) CC_UNUSED bool ok = true; se::Value jsret; - ok &= uint32_to_seval((unsigned int)cobj->arrayLayer, &jsret); + ok &= uint32_to_seval((unsigned int)cobj->layerCount, &jsret); s.rval() = jsret; return true; } @@ -3499,7 +3499,7 @@ static bool js_gfx_TextureInfo_set_arrayLayer(se::State& s) unsigned int arg0 = 0; ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); SE_PRECONDITION2(ok, false, "js_gfx_TextureInfo_set_arrayLayer : Error processing new value"); - cobj->arrayLayer = arg0; + cobj->layerCount = arg0; return true; } SE_BIND_PROP_SET(js_gfx_TextureInfo_set_arrayLayer) @@ -3511,7 +3511,7 @@ static bool js_gfx_TextureInfo_get_mipLevel(se::State& s) CC_UNUSED bool ok = true; se::Value jsret; - ok &= uint32_to_seval((unsigned int)cobj->mipLevel, &jsret); + ok &= uint32_to_seval((unsigned int)cobj->levelCount, &jsret); s.rval() = jsret; return true; } @@ -3527,7 +3527,7 @@ static bool js_gfx_TextureInfo_set_mipLevel(se::State& s) unsigned int arg0 = 0; ok &= seval_to_uint32(args[0], (uint32_t*)&arg0); SE_PRECONDITION2(ok, false, "js_gfx_TextureInfo_set_mipLevel : Error processing new value"); - cobj->mipLevel = arg0; + cobj->levelCount = arg0; return true; } SE_BIND_PROP_SET(js_gfx_TextureInfo_set_mipLevel) @@ -3649,13 +3649,13 @@ static bool js_gfx_TextureInfo_constructor(se::State& s) json->getProperty("arrayLayer", &field); if(!field.isUndefined()) { ok &= seval_to_uint32(field, (uint32_t*)&arg6); - cobj->arrayLayer = arg6; + cobj->layerCount = arg6; } unsigned int arg7 = 0; json->getProperty("mipLevel", &field); if(!field.isUndefined()) { ok &= seval_to_uint32(field, (uint32_t*)&arg7); - cobj->mipLevel = arg7; + cobj->levelCount = arg7; } cc::gfx::SampleCount arg8; json->getProperty("samples", &field); @@ -3716,12 +3716,12 @@ static bool js_gfx_TextureInfo_constructor(se::State& s) unsigned int arg6 = 0; if (!args[6].isUndefined()) { ok &= seval_to_uint32(args[6], (uint32_t*)&arg6); - cobj->arrayLayer = arg6; + cobj->layerCount = arg6; } unsigned int arg7 = 0; if (!args[7].isUndefined()) { ok &= seval_to_uint32(args[7], (uint32_t*)&arg7); - cobj->mipLevel = arg7; + cobj->levelCount = arg7; } cc::gfx::SampleCount arg8; if (!args[8].isUndefined()) { @@ -11165,34 +11165,6 @@ static bool js_gfx_QueueInfo_set_type(se::State& s) } SE_BIND_PROP_SET(js_gfx_QueueInfo_set_type) -static bool js_gfx_QueueInfo_get_forceSync(se::State& s) -{ - cc::gfx::QueueInfo* cobj = (cc::gfx::QueueInfo*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_QueueInfo_get_forceSync : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= boolean_to_seval(cobj->forceSync, &jsret); - s.rval() = jsret; - return true; -} -SE_BIND_PROP_GET(js_gfx_QueueInfo_get_forceSync) - -static bool js_gfx_QueueInfo_set_forceSync(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::QueueInfo* cobj = (cc::gfx::QueueInfo*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_QueueInfo_set_forceSync : Invalid Native Object"); - - CC_UNUSED bool ok = true; - bool arg0; - ok &= seval_to_boolean(args[0], &arg0); - SE_PRECONDITION2(ok, false, "js_gfx_QueueInfo_set_forceSync : Error processing new value"); - cobj->forceSync = arg0; - return true; -} -SE_BIND_PROP_SET(js_gfx_QueueInfo_set_forceSync) - SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_QueueInfo_finalize) static bool js_gfx_QueueInfo_constructor(se::State& s) @@ -11208,36 +11180,7 @@ static bool js_gfx_QueueInfo_constructor(se::State& s) se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; } - else if(argc == 1 && args[0].isObject()) - { - se::Object *json = args[0].toObject(); - se::Value field; - - cc::gfx::QueueInfo* cobj = JSB_ALLOC(cc::gfx::QueueInfo); - cc::gfx::QueueType arg0; - json->getProperty("type", &field); - if(!field.isUndefined()) { - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::QueueType)tmp; } while(false); - cobj->type = arg0; - } - bool arg1; - json->getProperty("forceSync", &field); - if(!field.isUndefined()) { - ok &= seval_to_boolean(field, &arg1); - cobj->forceSync = arg1; - } - - if(!ok) { - JSB_FREE(cobj); - SE_REPORT_ERROR("argument convertion error"); - return false; - } - - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; - } - else if(argc == 2) + else if(argc == 1) { cc::gfx::QueueInfo* cobj = JSB_ALLOC(cc::gfx::QueueInfo); cc::gfx::QueueType arg0; @@ -11245,11 +11188,6 @@ static bool js_gfx_QueueInfo_constructor(se::State& s) do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::QueueType)tmp; } while(false); cobj->type = arg0; } - bool arg1; - if (!args[1].isUndefined()) { - ok &= seval_to_boolean(args[1], &arg1); - cobj->forceSync = arg1; - } if(!ok) { JSB_FREE(cobj); @@ -11288,7 +11226,6 @@ bool js_register_gfx_QueueInfo(se::Object* obj) auto cls = se::Class::create("QueueInfo", obj, nullptr, _SE(js_gfx_QueueInfo_constructor)); cls->defineProperty("type", _SE(js_gfx_QueueInfo_get_type), _SE(js_gfx_QueueInfo_set_type)); - cls->defineProperty("forceSync", _SE(js_gfx_QueueInfo_get_forceSync), _SE(js_gfx_QueueInfo_set_forceSync)); cls->defineFinalizeFunction(_SE(js_cc_gfx_QueueInfo_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -12113,6 +12050,24 @@ static bool js_gfx_Device_getWidth(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getWidth) +static bool js_gfx_Device_getScreenSpaceSignY(se::State& s) +{ + cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_getScreenSpaceSignY : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + float result = cobj->getScreenSpaceSignY(); + ok &= float_to_seval(result, &s.rval()); + SE_PRECONDITION2(ok, false, "js_gfx_Device_getScreenSpaceSignY : 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_Device_getScreenSpaceSignY) + static bool js_gfx_Device_getQueue(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); @@ -12752,24 +12707,6 @@ static bool js_gfx_Device_getMemoryStatus(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getMemoryStatus) -static bool js_gfx_Device_getClipSpaceSignY(se::State& s) -{ - cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_getClipSpaceSignY : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - float result = cobj->getClipSpaceSignY(); - ok &= float_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_gfx_Device_getClipSpaceSignY : 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_Device_getClipSpaceSignY) - static bool js_gfx_Device_getMaxTextureUnits(se::State& s) { cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); @@ -12912,9 +12849,9 @@ bool js_register_gfx_Device(se::Object* obj) cls->defineProperty("maxUniformBlockSize", _SE(js_gfx_Device_getMaxUniformBlockSize), nullptr); cls->defineProperty("maxTextureSize", _SE(js_gfx_Device_getMaxTextureSize), nullptr); cls->defineProperty("nativeHeight", _SE(js_gfx_Device_getNativeHeight), nullptr); - cls->defineProperty("clipSpaceSignY", _SE(js_gfx_Device_getClipSpaceSignY), nullptr); cls->defineProperty("depthStencilFormat", _SE(js_gfx_Device_getDepthStencilFormat), nullptr); cls->defineProperty("numTris", _SE(js_gfx_Device_getNumTris), nullptr); + cls->defineProperty("screenSpaceSignY", _SE(js_gfx_Device_getScreenSpaceSignY), nullptr); cls->defineProperty("stencilBits", _SE(js_gfx_Device_getStencilBits), nullptr); cls->defineProperty("queue", _SE(js_gfx_Device_getQueue), nullptr); cls->defineProperty("context", _SE(js_gfx_Device_getContext), nullptr); @@ -13321,7 +13258,7 @@ static bool js_gfx_Texture_getMipLevel(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - unsigned int result = cobj->getMipLevel(); + unsigned int result = cobj->getLevelCount(); ok &= uint32_to_seval((unsigned int)result, &s.rval()); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getMipLevel : Error processing arguments"); return true; @@ -13339,7 +13276,7 @@ static bool js_gfx_Texture_getArrayLayer(se::State& s) size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 0) { - unsigned int result = cobj->getArrayLayer(); + unsigned int result = cobj->getLayerCount(); ok &= uint32_to_seval((unsigned int)result, &s.rval()); SE_PRECONDITION2(ok, false, "js_gfx_Texture_getArrayLayer : Error processing arguments"); return true; @@ -15397,31 +15334,6 @@ static bool js_gfx_CommandBuffer_setDepthBound(se::State& s) } SE_BIND_FUNC(js_gfx_CommandBuffer_setDepthBound) -static bool js_gfx_CommandBuffer_copyBufferToTexture(se::State& s) -{ - cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_copyBufferToTexture : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 4) { - cc::gfx::Buffer* arg0 = nullptr; - cc::gfx::Texture* arg1 = nullptr; - cc::gfx::TextureLayout arg2; - std::vector arg3; - ok &= seval_to_native_ptr(args[0], &arg0); - ok &= seval_to_native_ptr(args[1], &arg1); - do { int32_t tmp = 0; ok &= seval_to_int32(args[2], &tmp); arg2 = (cc::gfx::TextureLayout)tmp; } while(false); - ok &= seval_to_std_vector(args[3], &arg3); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_copyBufferToTexture : Error processing arguments"); - cobj->copyBufferToTexture(arg0, arg1, arg2, arg3); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4); - return false; -} -SE_BIND_FUNC(js_gfx_CommandBuffer_copyBufferToTexture) - static bool js_gfx_CommandBuffer_getQueue(se::State& s) { cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject(); @@ -15919,7 +15831,6 @@ bool js_register_gfx_CommandBuffer(se::Object* obj) cls->defineFunction("draw", _SE(js_gfx_CommandBuffer_draw)); cls->defineFunction("setBlendConstants", _SE(js_gfx_CommandBuffer_setBlendConstants)); cls->defineFunction("setDepthBound", _SE(js_gfx_CommandBuffer_setDepthBound)); - cls->defineFunction("copyBufferToTexture", _SE(js_gfx_CommandBuffer_copyBufferToTexture)); cls->defineFunction("getQueue", _SE(js_gfx_CommandBuffer_getQueue)); cls->defineFunction("setLineWidth", _SE(js_gfx_CommandBuffer_setLineWidth)); cls->defineFunction("updateBuffer", _SE(js_gfx_CommandBuffer_updateBuffer)); diff --git a/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp index 151d15c107..c56cfd8657 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_gfx_auto.hpp @@ -369,7 +369,6 @@ bool register_all_gfx(se::Object* obj); SE_DECLARE_FUNC(js_gfx_CommandBuffer_draw); SE_DECLARE_FUNC(js_gfx_CommandBuffer_setBlendConstants); SE_DECLARE_FUNC(js_gfx_CommandBuffer_setDepthBound); -SE_DECLARE_FUNC(js_gfx_CommandBuffer_copyBufferToTexture); SE_DECLARE_FUNC(js_gfx_CommandBuffer_getQueue); SE_DECLARE_FUNC(js_gfx_CommandBuffer_setLineWidth); SE_DECLARE_FUNC(js_gfx_CommandBuffer_updateBuffer); diff --git a/native/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp index f4a5d07b0c..58a330a783 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_gfx_manual.cpp @@ -1,94 +1,87 @@ #include "jsb_gfx_manual.hpp" +#include "scripting/js-bindings/auto/jsb_gfx_auto.hpp" +#include "scripting/js-bindings/jswrapper/SeApi.h" #include "scripting/js-bindings/manual/jsb_conversions.hpp" #include "scripting/js-bindings/manual/jsb_global.h" -#include "scripting/js-bindings/jswrapper/SeApi.h" -#include "scripting/js-bindings/auto/jsb_gfx_auto.hpp" - #if (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_WINDOWS) -#define USE_VULKAN -#define USE_GLES3 -#define USE_GLES2 + #define USE_VULKAN + #define USE_GLES3 + #define USE_GLES2 #elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS) -#define USE_GLES3 + #define USE_GLES3 #else -#define USE_METAL + #define USE_METAL #endif #if !(defined(USE_GLES2) || defined(USE_GLES3) || defined(USE_VULKAN) || defined(USE_METAL)) -#error "gfx backend is not defined!" + #error "gfx backend is not defined!" #endif #ifdef USE_VULKAN -#include "scripting/js-bindings/auto/jsb_vk_auto.hpp" -#include "renderer/gfx-vulkan/GFXVulkan.h" + #include "renderer/gfx-vulkan/GFXVulkan.h" + #include "scripting/js-bindings/auto/jsb_vk_auto.hpp" #endif #ifdef USE_METAL -#include "scripting/js-bindings/auto/jsb_mtl_auto.hpp" -#include "renderer/gfx-metal/GFXMTL.h" + #include "renderer/gfx-metal/GFXMTL.h" + #include "scripting/js-bindings/auto/jsb_mtl_auto.hpp" #endif #ifdef USE_GLES3 -#include "scripting/js-bindings/auto/jsb_gles3_auto.hpp" -#include "renderer/gfx-gles3/GFXGLES3.h" + #include "renderer/gfx-gles3/GFXGLES3.h" + #include "scripting/js-bindings/auto/jsb_gles3_auto.hpp" #endif #ifdef USE_GLES2 -#include "scripting/js-bindings/auto/jsb_gles2_auto.hpp" -#include "renderer/gfx-gles2/GFXGLES2.h" + #include "renderer/gfx-gles2/GFXGLES2.h" + #include "scripting/js-bindings/auto/jsb_gles2_auto.hpp" #endif #include #include #define GFX_MAX_VERTEX_ATTRIBUTES 16 -#define GFX_MAX_TEXTURE_UNITS 16 -#define GFX_MAX_ATTACHMENTS 4 -#define GFX_MAX_BUFFER_BINDINGS 24 -#define GFX_INVALID_BINDING ((uint8_t)-1) -#define GFX_INVALID_HANDLE ((uint)-1) +#define GFX_MAX_TEXTURE_UNITS 16 +#define GFX_MAX_ATTACHMENTS 4 +#define GFX_MAX_BUFFER_BINDINGS 24 +#define GFX_INVALID_BINDING ((uint8_t)-1) +#define GFX_INVALID_HANDLE ((uint)-1) -bool js_Device_copyBuffersToTexture(se::State& s, cc::gfx::Device* cobj) -{ - const auto& args = s.args(); +bool js_gfx_Device_copyBuffersToTexture(se::State &s) { + cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_copyBuffersToTexture : Invalid Native Object"); + + const auto &args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 3) { - cc::gfx::DataArray arg0; - cc::gfx::Texture* arg1 = nullptr; - std::vector arg2; - if (args[0].isObject()) - { - se::Object* dataObj = args[0].toObject(); + cc::gfx::BufferDataList arg0; + cc::gfx::Texture *arg1 = nullptr; + cc::gfx::BufferTextureCopyList arg2; + if (args[0].isObject()) { + se::Object *dataObj = args[0].toObject(); SE_PRECONDITION2(dataObj->isArray(), false, "Buffers must be an array!"); uint32_t length = 0; dataObj->getArrayLength(&length); - arg0.datas.resize(length); - + arg0.resize(length); + se::Value value; - for (uint32_t i = 0; i < length; ++i) - { - if (dataObj->getArrayElement(i, &value)) - { - uint8_t* ptr = nullptr; + for (uint32_t i = 0; i < length; ++i) { + if (dataObj->getArrayElement(i, &value)) { + uint8_t *ptr = nullptr; CC_UNUSED size_t dataLength = 0; - se::Object* obj = value.toObject(); - if (obj->isArrayBuffer()) - { + se::Object *obj = value.toObject(); + if (obj->isArrayBuffer()) { ok = obj->getArrayBufferData(&ptr, &dataLength); SE_PRECONDITION2(ok, false, "getArrayBufferData failed!"); - } - else if (obj->isTypedArray()) - { + } else if (obj->isTypedArray()) { ok = obj->getTypedArrayData(&ptr, &dataLength); SE_PRECONDITION2(ok, false, "getTypedArrayData failed!"); - } - else - { + } else { assert(false); } - arg0.datas[i] = ptr; + arg0[i] = ptr; } } } @@ -98,42 +91,40 @@ bool js_Device_copyBuffersToTexture(se::State& s, cc::gfx::Device* cobj) cobj->copyBuffersToTexture(arg0, arg1, arg2); return true; } - + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3); return false; } +SE_BIND_FUNC(js_gfx_Device_copyBuffersToTexture) -bool js_Device_copyTexImagesToTexture(se::State& s, cc::gfx::Device* cobj) -{ - const auto& args = s.args(); +bool js_gfx_Device_copyTexImagesToTexture(se::State &s) { + cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_copyBuffersToTexture : Invalid Native Object"); + + const auto &args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 3) { - cc::gfx::DataArray arg0; - cc::gfx::Texture* arg1 = nullptr; - std::vector arg2; - if (args[0].isObject()) - { - se::Object* dataObj = args[0].toObject(); + cc::gfx::BufferDataList arg0; + cc::gfx::Texture *arg1 = nullptr; + cc::gfx::BufferTextureCopyList arg2; + if (args[0].isObject()) { + se::Object *dataObj = args[0].toObject(); SE_PRECONDITION2(dataObj->isArray(), false, "Buffers must be an array!"); uint32_t length = 0; dataObj->getArrayLength(&length); - arg0.datas.resize(length); - + arg0.resize(length); + se::Value value; - for (uint32_t i = 0; i < length; ++i) - { - if (dataObj->getArrayElement(i, &value)) - { + for (uint32_t i = 0; i < length; ++i) { + if (dataObj->getArrayElement(i, &value)) { CC_UNUSED size_t dataLength = 0; cc::Data bufferData; ok &= seval_to_Data(value, &bufferData); - arg0.datas[i] = bufferData.takeBuffer(); + arg0[i] = bufferData.takeBuffer(); } } - } - else - { + } else { ok &= false; } ok &= seval_to_native_ptr(args[1], &arg1); @@ -145,172 +136,87 @@ bool js_Device_copyTexImagesToTexture(se::State& s, cc::gfx::Device* cobj) SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3); return false; } +SE_BIND_FUNC(js_gfx_Device_copyTexImagesToTexture) -static bool js_gfx_Device_createTexture(se::State& s) -{ - cc::gfx::Device* cobj = (cc::gfx::Device*)s.nativeThisObject(); - SE_PRECONDITION2( cobj, false, "js_gfx_Device_createTexture : Invalid Native Object"); - const auto& args = s.args(); +static bool js_gfx_Device_createTexture(se::State &s) { + cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Device_createTexture : Invalid Native Object"); + const auto &args = s.args(); size_t argc = args.size(); - + if (argc == 2) { - cc::gfx::Texture* texture = nullptr; - + cc::gfx::Texture *texture = nullptr; + bool createTextureView = false; seval_to_boolean(args[1], &createTextureView); - - if (createTextureView) - { - auto textureViewInfo = (cc::gfx::TextureViewInfo*)(args[0].toObject()->getPrivateData()); + + if (createTextureView) { + auto textureViewInfo = (cc::gfx::TextureViewInfo *)(args[0].toObject()->getPrivateData()); texture = cobj->createTexture(*textureViewInfo); - } - else - { - auto textureInfo = (cc::gfx::TextureInfo*)(args[0].toObject()->getPrivateData()); + } else { + auto textureInfo = (cc::gfx::TextureInfo *)(args[0].toObject()->getPrivateData()); texture = cobj->createTexture(*textureInfo); } - + CC_UNUSED bool ok = native_ptr_to_seval(texture, &s.rval()); SE_PRECONDITION2(ok, false, "js_gfx_Device_createTexture : Error processing arguments"); return true; } - + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } SE_BIND_FUNC(js_gfx_Device_createTexture) -static bool js_gfx_Texture_initialize(se::State& s) -{ +static bool js_gfx_Texture_initialize(se::State &s) { CC_UNUSED bool ok = true; - cc::gfx::Texture* cobj = (cc::gfx::Texture*)s.nativeThisObject(); - SE_PRECONDITION2( cobj, false, "js_gfx_Texture_initialize : Invalid Native Object"); - const auto& args = s.args(); + cc::gfx::Texture *cobj = (cc::gfx::Texture *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_Texture_initialize : Invalid Native Object"); + const auto &args = s.args(); size_t argc = args.size(); - + if (argc == 2) { bool initWithTextureViewInfo = false; seval_to_boolean(args[1], &initWithTextureViewInfo); - - if (initWithTextureViewInfo) - { - auto textureViewInfo = (cc::gfx::TextureViewInfo*)(args[0].toObject()->getPrivateData()); + + if (initWithTextureViewInfo) { + auto textureViewInfo = (cc::gfx::TextureViewInfo *)(args[0].toObject()->getPrivateData()); ok &= cobj->initialize(*textureViewInfo); - } - else - { - auto textureInfo = (cc::gfx::TextureInfo*)(args[0].toObject()->getPrivateData()); + } else { + auto textureInfo = (cc::gfx::TextureInfo *)(args[0].toObject()->getPrivateData()); ok &= cobj->initialize(*textureInfo); } - + ok &= boolean_to_seval(ok, &s.rval()); SE_PRECONDITION2(ok, false, "js_gfx_Texture_initialize : Error processing arguments"); return true; } - + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); return false; } SE_BIND_FUNC(js_gfx_Texture_initialize) -#ifdef USE_VULKAN -static bool js_gfx_CCVKDevice_copyBuffersToTexture(se::State& s) -{ - cc::gfx::CCVKDevice* cobj = (cc::gfx::CCVKDevice*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CCVKDevice_copyBuffersToTexture : Invalid Native Object"); - return js_Device_copyBuffersToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_CCVKDevice_copyBuffersToTexture) - -static bool js_gfx_CCVKDevice_copyTexImagesToTexture(se::State& s) -{ - cc::gfx::CCVKDevice* cobj = (cc::gfx::CCVKDevice*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CCVKDevice_copyTexImagesToTexture : Invalid Native Object"); - return js_Device_copyTexImagesToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_CCVKDevice_copyTexImagesToTexture); -#endif // USE_GLES3 - -#ifdef USE_METAL -static bool js_gfx_CCMTLDevice_copyBuffersToTexture(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = (cc::gfx::CCMTLDevice*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CCMTLDevice_copyBuffersToTexture : Invalid Native Object"); - return js_Device_copyBuffersToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_CCMTLDevice_copyBuffersToTexture) - -static bool js_gfx_CCMTLDevice_copyTexImagesToTexture(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = (cc::gfx::CCMTLDevice*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_CCMTLDevice_copyTexImagesToTexture : Invalid Native Object"); - return js_Device_copyTexImagesToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_CCMTLDevice_copyTexImagesToTexture); -#endif // USE_METAL - -#ifdef USE_GLES3 -static bool js_gfx_GLES3Device_copyBuffersToTexture(se::State& s) -{ - cc::gfx::GLES3Device* cobj = (cc::gfx::GLES3Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_GLES3Device_copyBuffersToTexture : Invalid Native Object"); - return js_Device_copyBuffersToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_GLES3Device_copyBuffersToTexture) - -static bool js_gfx_GLES3Device_copyTexImagesToTexture(se::State& s) -{ - cc::gfx::GLES3Device* cobj = (cc::gfx::GLES3Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_GLES3Device_copyTexImagesToTexture : Invalid Native Object"); - return js_Device_copyTexImagesToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_GLES3Device_copyTexImagesToTexture); -#endif // USE_GLES3 - -#ifdef USE_GLES2 -static bool js_gfx_GLES2Device_copyBuffersToTexture(se::State& s) -{ - cc::gfx::GLES2Device* cobj = (cc::gfx::GLES2Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_GLES2Device_copyBuffersToTexture : Invalid Native Object"); - return js_Device_copyBuffersToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_GLES2Device_copyBuffersToTexture) - -static bool js_gfx_GLES2Device_copyTexImagesToTexture(se::State& s) -{ - cc::gfx::GLES2Device* cobj = (cc::gfx::GLES2Device*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_gfx_GLES2Device_copyTexImagesToTexture : Invalid Native Object"); - return js_Device_copyTexImagesToTexture(s, cobj); -} -SE_BIND_FUNC(js_gfx_GLES2Device_copyTexImagesToTexture); -#endif // USE_GLES2 - -static bool js_gfx_GFXBuffer_update(se::State& s) -{ - cc::gfx::Buffer* cobj = (cc::gfx::Buffer*)s.nativeThisObject(); +static bool js_gfx_GFXBuffer_update(se::State &s) { + cc::gfx::Buffer *cobj = (cc::gfx::Buffer *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_GFXBuffer_update : Invalid Native Object"); - const auto& args = s.args(); + const auto &args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - uint8_t* arg0 = nullptr; + uint8_t *arg0 = nullptr; CC_UNUSED size_t dataLength = 0; - se::Object* obj = args[0].toObject(); - if (obj->isArrayBuffer()) - { + se::Object *obj = args[0].toObject(); + if (obj->isArrayBuffer()) { ok = obj->getArrayBufferData(&arg0, &dataLength); SE_PRECONDITION2(ok, false, "getArrayBufferData failed!"); - } - else if (obj->isTypedArray()) - { + } else if (obj->isTypedArray()) { ok = obj->getTypedArrayData(&arg0, &dataLength); SE_PRECONDITION2(ok, false, "getTypedArrayData failed!"); - } - else - { + } else { ok = false; } - + if (argc == 1) { SE_PRECONDITION2(ok, false, "js_gfx_GFXBuffer_update : Error processing arguments"); cobj->update(arg0, 0, static_cast(dataLength)); @@ -318,7 +224,7 @@ static bool js_gfx_GFXBuffer_update(se::State& s) } if (argc == 2) { unsigned int arg1 = 0; - ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); + ok &= seval_to_uint32(args[1], (uint32_t *)&arg1); SE_PRECONDITION2(ok, false, "js_gfx_GFXBuffer_update : Error processing arguments"); cobj->update(arg0, arg1, static_cast(dataLength)); return true; @@ -326,8 +232,8 @@ static bool js_gfx_GFXBuffer_update(se::State& s) if (argc == 3) { unsigned int arg1 = 0; unsigned int arg2 = 0; - ok &= seval_to_uint32(args[1], (uint32_t*)&arg1); - ok &= seval_to_uint32(args[2], (uint32_t*)&arg2); + ok &= seval_to_uint32(args[1], (uint32_t *)&arg1); + ok &= seval_to_uint32(args[2], (uint32_t *)&arg2); SE_PRECONDITION2(ok, false, "js_gfx_GFXBuffer_update : Error processing arguments"); cobj->update(arg0, arg1, arg2); return true; @@ -337,12 +243,11 @@ static bool js_gfx_GFXBuffer_update(se::State& s) } SE_BIND_FUNC(js_gfx_GFXBuffer_update) -se::Object* __jsb_cocos2d_SubPass_proto = nullptr; -se::Class* __jsb_cocos2d_SubPass_class = nullptr; +se::Object *__jsb_cocos2d_SubPass_proto = nullptr; +se::Class *__jsb_cocos2d_SubPass_class = nullptr; -static bool js_gfx_SubPass_get_bind_point(se::State& s) -{ - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_get_bind_point(se::State &s) { + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_get_bind_point : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -353,30 +258,31 @@ static bool js_gfx_SubPass_get_bind_point(se::State& s) } SE_BIND_PROP_GET(js_gfx_SubPass_get_bind_point) -static bool js_gfx_SubPass_set_bind_point(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_set_bind_point(se::State &s) { + const auto &args = s.args(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_set_bind_point : Invalid Native Object"); CC_UNUSED bool ok = true; cc::gfx::PipelineBindPoint arg0 = cc::gfx::PipelineBindPoint::GRAPHICS; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::PipelineBindPoint)tmp; } while(false); + do { + int32_t tmp = 0; + ok &= seval_to_int32(args[0], &tmp); + arg0 = (cc::gfx::PipelineBindPoint)tmp; + } while (false); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_set_bind_point : Error processing new value"); cobj->bindPoint = arg0; return true; } SE_BIND_PROP_SET(js_gfx_SubPass_set_bind_point) -static bool js_gfx_SubPass_get_inputs(se::State& s) -{ - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_get_inputs(se::State &s) { + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_get_inputs : Invalid Native Object"); se::Value jsret; se::HandleObject obj(se::Object::createArrayObject(GFX_MAX_ATTACHMENTS)); - for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) - { + for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) { obj->setArrayElement(i, se::Value(cobj->inputs[i])); } jsret.setObject(obj); @@ -384,10 +290,9 @@ static bool js_gfx_SubPass_get_inputs(se::State& s) } SE_BIND_PROP_GET(js_gfx_SubPass_get_inputs) -static bool js_gfx_SubPass_set_inputs(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_set_inputs(se::State &s) { + const auto &args = s.args(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_set_inputs : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -397,15 +302,13 @@ static bool js_gfx_SubPass_set_inputs(se::State& s) } SE_BIND_PROP_SET(js_gfx_SubPass_set_inputs) -static bool js_gfx_SubPass_get_colors(se::State& s) -{ - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_get_colors(se::State &s) { + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_get_colors : Invalid Native Object"); se::Value jsret; se::HandleObject obj(se::Object::createArrayObject(GFX_MAX_ATTACHMENTS)); - for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) - { + for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) { obj->setArrayElement(i, se::Value(cobj->colors[i])); } jsret.setObject(obj); @@ -413,10 +316,9 @@ static bool js_gfx_SubPass_get_colors(se::State& s) } SE_BIND_PROP_GET(js_gfx_SubPass_get_colors) -static bool js_gfx_SubPass_set_colors(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_set_colors(se::State &s) { + const auto &args = s.args(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_set_colors : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -426,15 +328,13 @@ static bool js_gfx_SubPass_set_colors(se::State& s) } SE_BIND_PROP_SET(js_gfx_SubPass_set_colors) -static bool js_gfx_SubPass_get_resolves(se::State& s) -{ - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_get_resolves(se::State &s) { + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_get_resolves : Invalid Native Object"); se::Value jsret; se::HandleObject obj(se::Object::createArrayObject(GFX_MAX_ATTACHMENTS)); - for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) - { + for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) { obj->setArrayElement(i, se::Value(cobj->resolves[i])); } jsret.setObject(obj); @@ -442,10 +342,9 @@ static bool js_gfx_SubPass_get_resolves(se::State& s) } SE_BIND_PROP_GET(js_gfx_SubPass_get_resolves) -static bool js_gfx_SubPass_set_resolves(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_set_resolves(se::State &s) { + const auto &args = s.args(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_set_resolves : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -456,9 +355,8 @@ static bool js_gfx_SubPass_set_resolves(se::State& s) } SE_BIND_PROP_SET(js_gfx_SubPass_set_resolves) -static bool js_gfx_SubPass_get_depth_stencil(se::State& s) -{ - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_get_depth_stencil(se::State &s) { + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_get_depth_stencil : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -469,30 +367,27 @@ static bool js_gfx_SubPass_get_depth_stencil(se::State& s) } SE_BIND_PROP_GET(js_gfx_SubPass_get_depth_stencil) -static bool js_gfx_SubPass_set_depth_stencil(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_set_depth_stencil(se::State &s) { + const auto &args = s.args(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_set_depth_stencil : Invalid Native Object"); CC_UNUSED bool ok = true; uint8_t arg0; - ok &= seval_to_uint8(args[0], (uint8_t*)&arg0); + ok &= seval_to_uint8(args[0], (uint8_t *)&arg0); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_set_depth_stencil : Error processing new value"); cobj->depthStencil = arg0; return true; } SE_BIND_PROP_SET(js_gfx_SubPass_set_depth_stencil) -static bool js_gfx_SubPass_get_preserves(se::State& s) -{ - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_get_preserves(se::State &s) { + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_get_preserves : Invalid Native Object"); se::Value jsret; se::HandleObject obj(se::Object::createArrayObject(GFX_MAX_ATTACHMENTS)); - for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) - { + for (uint8_t i = 0; i < GFX_MAX_ATTACHMENTS; ++i) { obj->setArrayElement(i, se::Value(cobj->preserves[i])); } jsret.setObject(obj); @@ -500,10 +395,9 @@ static bool js_gfx_SubPass_get_preserves(se::State& s) } SE_BIND_PROP_GET(js_gfx_SubPass_get_preserves) -static bool js_gfx_SubPass_set_preserves(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); +static bool js_gfx_SubPass_set_preserves(se::State &s) { + const auto &args = s.args(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_SubPass_set_preserves : Invalid Native Object"); CC_UNUSED bool ok = true; @@ -516,71 +410,71 @@ SE_BIND_PROP_SET(js_gfx_SubPass_set_preserves) SE_DECLARE_FINALIZE_FUNC(js_cocos2d_SubPass_finalize) -static bool js_gfx_SubPass_constructor(se::State& s) -{ +static bool js_gfx_SubPass_constructor(se::State &s) { CC_UNUSED bool ok = true; - const auto& args = s.args(); + const auto &args = s.args(); size_t argc = args.size(); - if(argc == 0) - { - cc::gfx::SubPass* cobj = new (std::nothrow) cc::gfx::SubPass(); + if (argc == 0) { + cc::gfx::SubPass *cobj = new (std::nothrow) cc::gfx::SubPass(); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; - } - else if(argc == 1 && args[0].isObject()) - { + } else if (argc == 1 && args[0].isObject()) { se::Object *json = args[0].toObject(); se::Value field; - cc::gfx::SubPass* cobj = new (std::nothrow) cc::gfx::SubPass(); + cc::gfx::SubPass *cobj = new (std::nothrow) cc::gfx::SubPass(); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); cc::gfx::PipelineBindPoint arg0 = cc::gfx::PipelineBindPoint::GRAPHICS; - json->getProperty("bind_point", &field); - if(field.isUndefined()) { + json->getProperty("bind_point", &field); + if (field.isUndefined()) { SE_REPORT_ERROR("argument Field \".bind_point\" is undefined!"); return false; } - do { int32_t tmp = 0; ok &= seval_to_int32(field, &tmp); arg0 = (cc::gfx::PipelineBindPoint)tmp; } while(false); + do { + int32_t tmp = 0; + ok &= seval_to_int32(field, &tmp); + arg0 = (cc::gfx::PipelineBindPoint)tmp; + } while (false); cobj->bindPoint = arg0; - - json->getProperty("inputs", &field); - if(field.isUndefined()) { + + json->getProperty("inputs", &field); + if (field.isUndefined()) { SE_REPORT_ERROR("argument Field \".inputs\" is undefined!"); return false; - } + } ok &= seval_to_Uint8Array(field, cobj->inputs); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing inputs value"); - json->getProperty("colors", &field); - if(field.isUndefined()) { + json->getProperty("colors", &field); + if (field.isUndefined()) { SE_REPORT_ERROR("argument Field \".colors\" is undefined!"); return false; } ok &= seval_to_Uint8Array(field, cobj->colors); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing colors value"); - json->getProperty("resolves", &field); - if(field.isUndefined()) { + json->getProperty("resolves", &field); + if (field.isUndefined()) { SE_REPORT_ERROR("argument Field \".resolves\" is undefined!"); return false; } ok &= seval_to_Uint8Array(field, cobj->resolves); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing resolves value"); - json->getProperty("depth_stencil", &field); - if(field.isUndefined()) { + json->getProperty("depth_stencil", &field); + if (field.isUndefined()) { SE_REPORT_ERROR("argument Field \".depth_stencil\" is undefined!"); return false; } - ok &= seval_to_uint8(field, (uint8_t*)&cobj->depthStencil); + ok &= seval_to_uint8(field, (uint8_t *)&cobj->depthStencil); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing depth_stencil value"); - - json->getProperty("preserves", &field); - if(field.isUndefined()) { + + json->getProperty("preserves", &field); + if (field.isUndefined()) { SE_REPORT_ERROR("argument Field \".preserves\" is undefined!"); return false; } @@ -588,32 +482,34 @@ static bool js_gfx_SubPass_constructor(se::State& s) SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing preserves value"); return true; - } - else if(argc == 6) - { - cc::gfx::SubPass* cobj = new (std::nothrow) cc::gfx::SubPass(); + } else if (argc == 6) { + cc::gfx::SubPass *cobj = new (std::nothrow) cc::gfx::SubPass(); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); cc::gfx::PipelineBindPoint arg0 = cc::gfx::PipelineBindPoint::GRAPHICS; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (cc::gfx::PipelineBindPoint)tmp; } while(false); + do { + int32_t tmp = 0; + ok &= seval_to_int32(args[0], &tmp); + arg0 = (cc::gfx::PipelineBindPoint)tmp; + } while (false); cobj->bindPoint = arg0; - ok &= seval_to_Uint8Array(args[1], (uint8_t*)&cobj->inputs); + ok &= seval_to_Uint8Array(args[1], (uint8_t *)&cobj->inputs); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing inputs value"); - ok &= seval_to_Uint8Array(args[2], (uint8_t*)&cobj->colors); + ok &= seval_to_Uint8Array(args[2], (uint8_t *)&cobj->colors); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing colors value"); - ok &= seval_to_Uint8Array(args[3], (uint8_t*)&cobj->resolves); + ok &= seval_to_Uint8Array(args[3], (uint8_t *)&cobj->resolves); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing resolves value"); - ok &= seval_to_uint8(args[4], (uint8_t*)&cobj->depthStencil); + ok &= seval_to_uint8(args[4], (uint8_t *)&cobj->depthStencil); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing depth_stencil value"); - ok &= seval_to_Uint8Array(args[5], (uint8_t*)&cobj->preserves); + ok &= seval_to_Uint8Array(args[5], (uint8_t *)&cobj->preserves); SE_PRECONDITION2(ok, false, "js_gfx_SubPass_constructor : Error processing preserves value"); - + return true; } @@ -622,22 +518,19 @@ static bool js_gfx_SubPass_constructor(se::State& s) } SE_BIND_CTOR(js_gfx_SubPass_constructor, __jsb_cocos2d_SubPass_class, js_cocos2d_SubPass_finalize) -static bool js_cocos2d_SubPass_finalize(se::State& s) -{ +static bool js_cocos2d_SubPass_finalize(se::State &s) { CC_LOG_INFO("jsbindings: finalizing JS object %p (cc::SubPass)", s.nativeThisObject()); auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { + if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::SubPass* cobj = (cc::gfx::SubPass*)s.nativeThisObject(); + cc::gfx::SubPass *cobj = (cc::gfx::SubPass *)s.nativeThisObject(); JSB_FREE(cobj); } return true; } SE_BIND_FINALIZE_FUNC(js_cocos2d_SubPass_finalize) -bool js_register_gfx_SubPass(se::Object* obj) -{ +bool js_register_gfx_SubPass(se::Object *obj) { auto cls = se::Class::create("SubPass", obj, nullptr, _SE(js_gfx_SubPass_constructor)); cls->defineProperty("bindPoint", _SE(js_gfx_SubPass_get_bind_point), _SE(js_gfx_SubPass_set_bind_point)); @@ -657,39 +550,36 @@ bool js_register_gfx_SubPass(se::Object* obj) return true; } -static bool js_gfx_BlendState_get_targets(se::State& s) -{ - cc::gfx::BlendState* cobj = (cc::gfx::BlendState*)s.nativeThisObject(); +static bool js_gfx_BlendState_get_targets(se::State &s) { + cc::gfx::BlendState *cobj = (cc::gfx::BlendState *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_GFXBlendState_get_targets : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value *jsTargets = &s.rval(); - const std::vector& targets = cobj->targets; + cc::gfx::BlendTargetList &targets = cobj->targets; se::HandleObject arr(se::Object::createArrayObject(targets.size())); jsTargets->setObject(arr); - - uint32_t i = 0; - for (const auto&target : targets) - { + + uint32_t i = 0; + for (const auto &target : targets) { se::Value out = se::Value::Null; native_ptr_to_seval(target, &out); arr->setArrayElement(i, out); - + ++i; } return true; } SE_BIND_PROP_GET(js_gfx_BlendState_get_targets) -static bool js_gfx_BlendState_set_targets(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::BlendState* cobj = (cc::gfx::BlendState*)s.nativeThisObject(); +static bool js_gfx_BlendState_set_targets(se::State &s) { + const auto &args = s.args(); + cc::gfx::BlendState *cobj = (cc::gfx::BlendState *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_GFXBlendState_set_targets : Invalid Native Object"); CC_UNUSED bool ok = true; - std::vector arg0; + cc::gfx::BlendTargetList arg0; ok &= seval_to_std_vector(args[0], &arg0); SE_PRECONDITION2(ok, false, "js_gfx_GFXBlendState_set_targets : Error processing new value"); cobj->targets = arg0; @@ -697,45 +587,40 @@ static bool js_gfx_BlendState_set_targets(se::State& s) } SE_BIND_PROP_SET(js_gfx_BlendState_set_targets) -static bool js_gfx_CommandBuffer_execute(se::State& s) -{ - cc::gfx::CommandBuffer* cobj = (cc::gfx::CommandBuffer*)s.nativeThisObject(); +static bool js_gfx_CommandBuffer_execute(se::State &s) { + cc::gfx::CommandBuffer *cobj = (cc::gfx::CommandBuffer *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_execute : Invalid Native Object"); - const auto& args = s.args(); + const auto &args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; if (argc == 2) { - std::vector cmdBufs; + cc::gfx::CommandBufferList cmdBufs; unsigned int count = 0; - ok &= seval_to_uint32(args[1], (uint32_t*)&count); - - se::Object* jsarr = args[0].toObject(); + ok &= seval_to_uint32(args[1], (uint32_t *)&count); + + se::Object *jsarr = args[0].toObject(); assert(jsarr->isArray()); uint32_t len = 0; ok &= jsarr->getArrayLength(&len); - if (len < count) - { + if (len < count) { ok = false; } - if (ok) - { + if (ok) { cmdBufs.resize(count); - + se::Value tmp; - for (uint32_t i = 0; i < count; ++i) - { + for (uint32_t i = 0; i < count; ++i) { ok = jsarr->getArrayElement(i, &tmp); - if (!ok || !tmp.isObject()) - { + if (!ok || !tmp.isObject()) { cmdBufs.clear(); break; } - - cc::gfx::CommandBuffer *cmdBuf = (cc::gfx::CommandBuffer*)tmp.toObject()->getPrivateData(); + + cc::gfx::CommandBuffer *cmdBuf = (cc::gfx::CommandBuffer *)tmp.toObject()->getPrivateData(); cmdBufs[i] = cmdBuf; } } - + SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_execute : Error processing arguments"); cobj->execute(cmdBufs, count); return true; @@ -745,35 +630,82 @@ static bool js_gfx_CommandBuffer_execute(se::State& s) } SE_BIND_FUNC(js_gfx_CommandBuffer_execute) -static bool js_gfx_InputAssembler_extractDrawInfo(se::State& s) -{ - cc::gfx::InputAssembler* cobj = (cc::gfx::InputAssembler*)s.nativeThisObject(); +static bool js_gfx_CommandBuffer_copyBuffersToTexture(se::State &s) { + cc::gfx::CommandBuffer *cobj = (cc::gfx::CommandBuffer *)s.nativeThisObject(); + SE_PRECONDITION2(cobj, false, "js_gfx_CommandBuffer_copyBuffersToTexture : Invalid Native Object"); + + const auto &args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 3) { + cc::gfx::BufferDataList arg0; + cc::gfx::Texture *arg1 = nullptr; + cc::gfx::BufferTextureCopyList arg2; + if (args[0].isObject()) { + se::Object *dataObj = args[0].toObject(); + SE_PRECONDITION2(dataObj->isArray(), false, "Buffers must be an array!"); + uint32_t length = 0; + dataObj->getArrayLength(&length); + arg0.resize(length); + + se::Value value; + for (uint32_t i = 0; i < length; ++i) { + if (dataObj->getArrayElement(i, &value)) { + uint8_t *ptr = nullptr; + CC_UNUSED size_t dataLength = 0; + se::Object *obj = value.toObject(); + if (obj->isArrayBuffer()) { + ok = obj->getArrayBufferData(&ptr, &dataLength); + SE_PRECONDITION2(ok, false, "getArrayBufferData failed!"); + } else if (obj->isTypedArray()) { + ok = obj->getTypedArrayData(&ptr, &dataLength); + SE_PRECONDITION2(ok, false, "getTypedArrayData failed!"); + } else { + assert(false); + } + arg0[i] = ptr; + } + } + } + ok &= seval_to_native_ptr(args[1], &arg1); + ok &= seval_to_std_vector(args[2], &arg2); + SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_copyBuffersToTexture : Error processing arguments"); + cobj->copyBuffersToTexture(arg0, arg1, arg2); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3); + return false; +} +SE_BIND_FUNC(js_gfx_CommandBuffer_copyBuffersToTexture) + +static bool js_gfx_InputAssembler_extractDrawInfo(se::State &s) { + cc::gfx::InputAssembler *cobj = (cc::gfx::InputAssembler *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_InputAssembler_extractDrawInfo : Invalid Native Object"); - const auto& args = s.args(); + const auto &args = s.args(); size_t argc = args.size(); if (argc == 1) { cc::gfx::DrawInfo nativeDrawInfo; cobj->extractDrawInfo(nativeDrawInfo); - - se::Object* drawInfo = args[0].toObject(); + + se::Object *drawInfo = args[0].toObject(); se::Value attrValue(nativeDrawInfo.vertexCount); drawInfo->setProperty("vertexCount", attrValue); - + attrValue.setUint32(nativeDrawInfo.firstVertex); drawInfo->setProperty("firstVertex", attrValue); - + attrValue.setUint32(nativeDrawInfo.indexCount); drawInfo->setProperty("indexCount", attrValue); - + attrValue.setUint32(nativeDrawInfo.firstIndex); drawInfo->setProperty("firstIndex", attrValue); - + attrValue.setUint32(nativeDrawInfo.vertexOffset); drawInfo->setProperty("vertexOffset", attrValue); - + attrValue.setUint32(nativeDrawInfo.instanceCount); drawInfo->setProperty("instanceCount", attrValue); - + attrValue.setUint32(nativeDrawInfo.firstInstance); drawInfo->setProperty("firstInstance", attrValue); @@ -784,40 +716,36 @@ static bool js_gfx_InputAssembler_extractDrawInfo(se::State& s) } SE_BIND_FUNC(js_gfx_InputAssembler_extractDrawInfo) -bool register_all_gfx_manual(se::Object* obj) -{ +bool register_all_gfx_manual(se::Object *obj) { + __jsb_cc_gfx_Device_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_Device_copyBuffersToTexture)); + __jsb_cc_gfx_Device_proto->defineFunction("copyTexImagesToTexture", _SE(js_gfx_Device_copyTexImagesToTexture)); + __jsb_cc_gfx_Device_proto->defineFunction("createTexture", _SE(js_gfx_Device_createTexture)); + __jsb_cc_gfx_Buffer_proto->defineFunction("update", _SE(js_gfx_GFXBuffer_update)); - + __jsb_cc_gfx_BlendState_proto->defineProperty("targets", _SE(js_gfx_BlendState_get_targets), _SE(js_gfx_BlendState_set_targets)); - + __jsb_cc_gfx_CommandBuffer_proto->defineFunction("execute", _SE(js_gfx_CommandBuffer_execute)); + __jsb_cc_gfx_CommandBuffer_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_CommandBuffer_copyBuffersToTexture)); __jsb_cc_gfx_InputAssembler_proto->defineFunction("extractDrawInfo", _SE(js_gfx_InputAssembler_extractDrawInfo)); - + + __jsb_cc_gfx_Texture_proto->defineFunction("initialize", _SE(js_gfx_Texture_initialize)); + js_register_gfx_SubPass(obj); #if defined USE_VULKAN register_all_vk(obj); - __jsb_cc_gfx_CCVKDevice_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_CCVKDevice_copyBuffersToTexture)); - __jsb_cc_gfx_CCVKDevice_proto->defineFunction("copyTexImagesToTexture", _SE(js_gfx_CCVKDevice_copyTexImagesToTexture)); #endif #if defined USE_GLES3 register_all_gles3(obj); - __jsb_cc_gfx_GLES3Device_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_GLES3Device_copyBuffersToTexture)); - __jsb_cc_gfx_GLES3Device_proto->defineFunction("copyTexImagesToTexture", _SE(js_gfx_GLES3Device_copyTexImagesToTexture)); #endif #ifdef USE_GLES2 register_all_gles2(obj); - __jsb_cc_gfx_GLES2Device_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_GLES2Device_copyBuffersToTexture)); - __jsb_cc_gfx_GLES2Device_proto->defineFunction("copyTexImagesToTexture", _SE(js_gfx_GLES2Device_copyTexImagesToTexture)); #endif #if defined USE_METAL register_all_mtl(obj); - __jsb_cc_gfx_CCMTLDevice_proto->defineFunction("copyBuffersToTexture", _SE(js_gfx_CCMTLDevice_copyBuffersToTexture)); - __jsb_cc_gfx_CCMTLDevice_proto->defineFunction("copyTexImagesToTexture", _SE(js_gfx_CCMTLDevice_copyTexImagesToTexture)); #endif - __jsb_cc_gfx_Device_proto->defineFunction("createTexture", _SE(js_gfx_Device_createTexture)); - __jsb_cc_gfx_Texture_proto->defineFunction("initialize", _SE(js_gfx_Texture_initialize)); - + return true; } diff --git a/native/external/config.json b/native/external/config.json index 5652728e79..64ead4c911 100644 --- a/native/external/config.json +++ b/native/external/config.json @@ -1,9 +1,9 @@ { - "version": "v3d-gfx-20", + "version": "v3d-gfx-22", "from": { "type": "github", "owner": "cocos-creator", "name": "cocos2d-x-lite-external", - "checkout": "v3d-gfx-20" + "checkout": "v3d-gfx-22" } } diff --git a/native/tools/tojs/gfx.ini b/native/tools/tojs/gfx.ini index b7693e21e4..5e7aebb47d 100644 --- a/native/tools/tojs/gfx.ini +++ b/native/tools/tojs/gfx.ini @@ -46,7 +46,7 @@ classes_need_extend = skip = BindingLayout::[BindingLayout], Buffer::[Buffer update], - CommandBuffer::[CommandBuffer execute], + CommandBuffer::[CommandBuffer execute copyBuffersToTexture], Framebuffer::[Framebuffer], InputAssembler::[InputAssembler extractDrawInfo], PipelineState::[PipelineState], @@ -59,9 +59,9 @@ skip = BindingLayout::[BindingLayout], Device::[copyBuffersToTexture createTexture], BlendState::[targets] -getter_setter = Device::[gfxAPI deviceName width height nativeWidth nativeHeight memoryStatus context queue renderer vendor numDrawCalls numInstances numTris maxVertexAttributes maxVertexUniformVectors maxFragmentUniformVectors maxTextureUnits maxVertexTextureUnits maxUniformBufferBindings maxUniformBlockSize maxTextureSize maxCubeMapTextureSize depthBits stencilBits shaderIdGen colorFormat depthStencilFormat clipSpaceMinZ clipSpaceSignY UVSpaceSignY], +getter_setter = Device::[gfxAPI deviceName width height nativeWidth nativeHeight memoryStatus context queue renderer vendor numDrawCalls numInstances numTris maxVertexAttributes maxVertexUniformVectors maxFragmentUniformVectors maxTextureUnits maxVertexTextureUnits maxUniformBufferBindings maxUniformBlockSize maxTextureSize maxCubeMapTextureSize depthBits stencilBits shaderIdGen colorFormat depthStencilFormat clipSpaceMinZ screenSpaceSignY UVSpaceSignY], Shader::[device name hash stages attributes blocks samplers], - Texture::[type usage format width height depth arrayLayer mipLevel size samples flags buffer], + 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], diff --git a/native/tools/tojs/vulkan.ini b/native/tools/tojs/vulkan.ini index b34f7d1c75..532aa78240 100644 --- a/native/tools/tojs/vulkan.ini +++ b/native/tools/tojs/vulkan.ini @@ -44,7 +44,7 @@ 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 = CCVKDevice::[copyBuffersToTexture gpuContext gpuDevice gpuSwapchain gpuSemaphorePool gpuFencePool gpuDescriptorSetPool gpuCommandBufferPool stagingBuffer getLayers getExtensions isSwapchainReady isDescriptorUpdateTemplateSupported isPushDescriptorSetSupported isMultiDrawIndirectSupported] +skip = CCVKDevice::[copyBuffersToTexture gpuContext gpuDevice gpuSwapchain gpuFencePool gpuRecycleBin gpuTransportHub gpuSemaphorePool gpuDescriptorSetPool gpuCommandBufferPool gpuStagingBufferPool getLayers getExtensions isSwapchainReady isDescriptorUpdateTemplateSupported isPushDescriptorSetSupported isMultiDrawIndirectSupported] getter_setter =