diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 97ee0f2739..ea8983330f 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -836,6 +836,7 @@ cocos_source_files( cocos/renderer/pipeline/shadow/ShadowStage.h cocos/renderer/pipeline/helper/DefineMap.h cocos/renderer/pipeline/helper/DefineMap.cpp + cocos/renderer/pipeline/helper/Utils.h ) ##### scene diff --git a/native/cocos/renderer/GFXDeviceManager.h b/native/cocos/renderer/GFXDeviceManager.h index d33888aa67..71b2ba4a10 100644 --- a/native/cocos/renderer/GFXDeviceManager.h +++ b/native/cocos/renderer/GFXDeviceManager.h @@ -32,12 +32,11 @@ #include "gfx-empty/EmptyDevice.h" #include "gfx-validator/DeviceValidator.h" -//#undef CC_USE_VULKAN +#undef CC_USE_VULKAN //#undef CC_USE_METAL //#undef CC_USE_GLES3 //#undef CC_USE_GLES2 - #ifdef CC_USE_VULKAN #include "gfx-vulkan/GFXVulkan.h" #endif @@ -58,7 +57,7 @@ namespace cc { namespace gfx { class CC_DLL DeviceManager final { - static constexpr bool DETACH_DEVICE_THREAD{true}; + static constexpr bool DETACH_DEVICE_THREAD{0}; static constexpr bool FORCE_DISABLE_VALIDATION{false}; static constexpr bool FORCE_ENABLE_VALIDATION{false}; diff --git a/native/cocos/renderer/frame-graph/DevicePass.cpp b/native/cocos/renderer/frame-graph/DevicePass.cpp index b817dacc1f..58c06e9801 100644 --- a/native/cocos/renderer/frame-graph/DevicePass.cpp +++ b/native/cocos/renderer/frame-graph/DevicePass.cpp @@ -30,6 +30,7 @@ #include "FrameGraph.h" #include "PassNode.h" #include "ResourceNode.h" +#include "base/Utils.h" #include "gfx-base/GFXCommandBuffer.h" namespace cc { @@ -68,8 +69,10 @@ void DevicePass::execute() { begin(cmdBuff); - for (size_t i = 0; i < _subpasses.size(); ++i) { - Subpass &subpass = _subpasses[i]; + for (uint32_t i = 0; i < utils::toUint(_subpasses.size()); ++i) { + Subpass &subpass = _subpasses[i]; + _resourceTable._subpassIndex = i; + for (LogicPass &pass : subpass.logicPasses) { gfx::Viewport &viewport = pass.customViewport ? pass.viewport : _viewport; gfx::Rect & scissor = pass.customViewport ? pass.scissor : _scissor; @@ -112,7 +115,7 @@ void DevicePass::append(const FrameGraph &graph, const PassNode *passNode, std:: return attachment.textureHandle == handle; }); if (it != attachments->end()) { - uint input = utils::toUint(it - attachments->begin()); + uint32_t input = utils::toUint(it - attachments->begin()); if (std::find(subpass.desc.inputs.begin(), subpass.desc.inputs.end(), input) == subpass.desc.inputs.end()) { subpass.desc.inputs.push_back(input); } @@ -175,7 +178,7 @@ void DevicePass::begin(gfx::CommandBuffer *cmdBuff) { gfx::RenderPassInfo rpInfo; gfx::FramebufferInfo fboInfo; float clearDepth = 1.F; - uint clearStencil = 0; + uint32_t clearStencil = 0; static std::vector clearColors; clearColors.clear(); _viewport = gfx::Viewport(); diff --git a/native/cocos/renderer/frame-graph/DevicePassResourceTable.h b/native/cocos/renderer/frame-graph/DevicePassResourceTable.h index ee8b61ebf7..824020234f 100644 --- a/native/cocos/renderer/frame-graph/DevicePassResourceTable.h +++ b/native/cocos/renderer/frame-graph/DevicePassResourceTable.h @@ -55,6 +55,7 @@ public: getWrite(TypedHandle handle) const noexcept; gfx::RenderPass *getRenderPass() const { return _renderPass; } + uint32_t getSubpassIndex() const { return _subpassIndex; } private: using ResourceDictionary = std::unordered_map; @@ -67,6 +68,7 @@ private: ResourceDictionary _writes{}; gfx::RenderPass *_renderPass{nullptr}; + uint32_t _subpassIndex{0U}; friend class DevicePass; }; diff --git a/native/cocos/renderer/frame-graph/FrameGraph.cpp b/native/cocos/renderer/frame-graph/FrameGraph.cpp index 2ae0134e8c..da61c2762a 100644 --- a/native/cocos/renderer/frame-graph/FrameGraph.cpp +++ b/native/cocos/renderer/frame-graph/FrameGraph.cpp @@ -78,8 +78,8 @@ void FrameGraph::present(const TextureHandle &input, gfx::Texture *target) { gfx::TextureBlit region; region.srcExtent.width = input->getWidth(); region.srcExtent.height = input->getHeight(); - region.dstExtent.width = input->getWidth(); - region.dstExtent.height = input->getHeight(); + region.dstExtent.width = target->getWidth(); + region.dstExtent.height = target->getHeight(); cmdBuff->blitTexture(input, target, ®ion, 1, gfx::Filter::POINT); } }); @@ -143,9 +143,9 @@ void FrameGraph::move(const TextureHandle from, const TextureHandle to, uint8_t CC_ASSERT(!toResourceNode.writer); const gfx::TextureInfo &toTextureDesc = static_cast *>(toResourceNode.virtualResource)->get().getDesc(); - uint const toTextureWidth = toTextureDesc.width >> mipmapLevel; - uint const toTextureHeight = toTextureDesc.height >> mipmapLevel; - uint const toTextureDepth = toTextureDesc.depth >> mipmapLevel; + uint32_t const toTextureWidth = toTextureDesc.width >> mipmapLevel; + uint32_t const toTextureHeight = toTextureDesc.height >> mipmapLevel; + uint32_t const toTextureDepth = toTextureDesc.depth >> mipmapLevel; CC_ASSERT(toTextureWidth && toTextureHeight && toTextureDepth); CC_ASSERT(toTextureDesc.levelCount > mipmapLevel && toTextureDesc.layerCount > arrayPosition); @@ -352,7 +352,7 @@ void FrameGraph::mergePassNodes() noexcept { void FrameGraph::computeStoreActionAndMemoryless() { ID passId = 0; - bool lastPassSubPassEnable = false; + bool lastPassSubpassEnable = false; for (const auto &passNode : _passNodes) { if (passNode->_refCount == 0) { @@ -360,10 +360,10 @@ void FrameGraph::computeStoreActionAndMemoryless() { } ID const oldPassId = passId; - passId += !passNode->_subpass || lastPassSubPassEnable != passNode->_subpass; - passId += oldPassId == passId ? passNode->_hasClearedAttachment * !passNode->_clearActionIgnoreable : 0; + passId += !passNode->_subpass || lastPassSubpassEnable != passNode->_subpass; + passId += oldPassId == passId ? passNode->_hasClearedAttachment * !passNode->_clearActionIgnorable : 0; passNode->setDevicePassId(passId); - lastPassSubPassEnable = passNode->_subpass && !passNode->_subpassEnd; + lastPassSubpassEnable = passNode->_subpass && !passNode->_subpassEnd; } static std::set renderTargets; diff --git a/native/cocos/renderer/frame-graph/PassNode.h b/native/cocos/renderer/frame-graph/PassNode.h index 7ac7acb8bc..404bf07819 100644 --- a/native/cocos/renderer/frame-graph/PassNode.h +++ b/native/cocos/renderer/frame-graph/PassNode.h @@ -51,7 +51,7 @@ public: Handle write(FrameGraph &graph, const Handle &output); void createRenderTargetAttachment(RenderTargetAttachment &&attachment); inline void sideEffect(); - inline void subpass(bool clearActionIgnoreable, bool end); + inline void subpass(bool end, bool clearActionIgnorable); inline void setViewport(const gfx::Viewport &viewport, const gfx::Rect &scissor); private: @@ -82,7 +82,7 @@ private: bool _subpass{false}; bool _subpassEnd{false}; bool _hasClearedAttachment{false}; - bool _clearActionIgnoreable{false}; + bool _clearActionIgnorable{false}; bool _customViewport{false}; gfx::Viewport _viewport; @@ -99,10 +99,10 @@ void PassNode::sideEffect() { _sideEffect = true; } -void PassNode::subpass(bool clearActionIgnoreable, bool end) { +void PassNode::subpass(bool end, bool clearActionIgnorable) { _subpass = true; - _clearActionIgnoreable = clearActionIgnoreable; _subpassEnd = end; + _clearActionIgnorable = clearActionIgnorable; } void PassNode::setViewport(const gfx::Viewport &viewport, const gfx::Rect &scissor) { diff --git a/native/cocos/renderer/frame-graph/PassNodeBuilder.h b/native/cocos/renderer/frame-graph/PassNodeBuilder.h index c0e4e97333..95a8b7070a 100644 --- a/native/cocos/renderer/frame-graph/PassNodeBuilder.h +++ b/native/cocos/renderer/frame-graph/PassNodeBuilder.h @@ -52,7 +52,7 @@ public: TextureHandle write(const TextureHandle &output, const RenderTargetAttachment::Descriptor &attachmentDesc) const noexcept; inline void sideEffect() const noexcept; - inline void subpass(bool clearActionIgnoreable, bool end) const noexcept; + inline void subpass(bool end = false, bool clearActionIgnorable = true) const noexcept; inline void setViewport(const gfx::Viewport &viewport, const gfx::Rect &scissor) noexcept; void writeToBlackboard(const StringHandle &name, const Handle &handle) const noexcept; @@ -81,8 +81,8 @@ void PassNodeBuilder::sideEffect() const noexcept { _passNode.sideEffect(); } -void PassNodeBuilder::subpass(bool clearActionIgnoreable, bool end) const noexcept { - _passNode.subpass(clearActionIgnoreable, end); +void PassNodeBuilder::subpass(bool end, bool clearActionIgnorable) const noexcept { + _passNode.subpass(end, clearActionIgnorable); } void PassNodeBuilder::setViewport(const gfx::Viewport &viewport, const gfx::Rect &scissor) noexcept { diff --git a/native/cocos/renderer/gfx-agent/BufferAgent.cpp b/native/cocos/renderer/gfx-agent/BufferAgent.cpp index e285331a1d..dbb18bd522 100644 --- a/native/cocos/renderer/gfx-agent/BufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/BufferAgent.cpp @@ -48,7 +48,7 @@ BufferAgent::~BufferAgent() { } void BufferAgent::doInit(const BufferInfo &info) { - uint size = getSize(); + uint32_t size = getSize(); if (size > STAGING_BUFFER_THRESHOLD && hasFlag(_memUsage, MemoryUsageBit::HOST)) { for (size_t i = 0; i < DeviceAgent::MAX_FRAME_INDEX; ++i) { _stagingBuffers.push_back(reinterpret_cast(malloc(size))); @@ -81,7 +81,7 @@ void BufferAgent::doInit(const BufferViewInfo &info) { }); } -void BufferAgent::doResize(uint size, uint /*count*/) { +void BufferAgent::doResize(uint32_t size, uint32_t /*count*/) { auto *mq = DeviceAgent::getInstance()->getMessageQueue(); if (!_stagingBuffers.empty()) { @@ -140,7 +140,7 @@ void BufferAgent::doDestroy() { }); } -void BufferAgent::update(const void *buffer, uint size) { +void BufferAgent::update(const void *buffer, uint32_t size) { uint8_t *actorBuffer{nullptr}; bool needFreeing{false}; auto * mq{DeviceAgent::getInstance()->getMessageQueue()}; @@ -160,10 +160,10 @@ void BufferAgent::update(const void *buffer, uint size) { }); } -void BufferAgent::getActorBuffer(const BufferAgent *buffer, MessageQueue *mq, uint size, uint8_t **pActorBuffer, bool *pNeedFreeing) { +void BufferAgent::getActorBuffer(const BufferAgent *buffer, MessageQueue *mq, uint32_t size, uint8_t **pActorBuffer, bool *pNeedFreeing) { if (!buffer->_stagingBuffers.empty()) { // for frequent updates on big buffers - uint frameIndex = DeviceAgent::getInstance()->getCurrentIndex(); - *pActorBuffer = buffer->_stagingBuffers[frameIndex]; + uint32_t frameIndex = DeviceAgent::getInstance()->getCurrentIndex(); + *pActorBuffer = buffer->_stagingBuffers[frameIndex]; } else if (size > STAGING_BUFFER_THRESHOLD) { // less frequent updates on big buffers *pActorBuffer = reinterpret_cast(malloc(size)); *pNeedFreeing = true; diff --git a/native/cocos/renderer/gfx-agent/BufferAgent.h b/native/cocos/renderer/gfx-agent/BufferAgent.h index b9ce7d4129..58a794cb92 100644 --- a/native/cocos/renderer/gfx-agent/BufferAgent.h +++ b/native/cocos/renderer/gfx-agent/BufferAgent.h @@ -40,17 +40,17 @@ public: explicit BufferAgent(Buffer *actor); ~BufferAgent() override; - void update(const void *buffer, uint size) override; + void update(const void *buffer, uint32_t size) override; - static void getActorBuffer(const BufferAgent *buffer, MessageQueue *mq, uint size, uint8_t **pActorBuffer, bool *pNeedFreeing); + static void getActorBuffer(const BufferAgent *buffer, MessageQueue *mq, uint32_t size, uint8_t **pActorBuffer, bool *pNeedFreeing); private: void doInit(const BufferInfo &info) override; void doInit(const BufferViewInfo &info) override; - void doResize(uint size, uint count) override; + void doResize(uint32_t size, uint32_t count) override; void doDestroy() override; - static constexpr uint STAGING_BUFFER_THRESHOLD = MessageQueue::MEMORY_CHUNK_SIZE / 2; + static constexpr uint32_t STAGING_BUFFER_THRESHOLD = MessageQueue::MEMORY_CHUNK_SIZE / 2; vector _stagingBuffers; }; diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp index ce134d23e8..022985ddb5 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp @@ -34,6 +34,7 @@ #include "RenderPassAgent.h" #include "TextureAgent.h" #include "base/CoreStd.h" +#include "base/Utils.h" #include "base/job-system/JobSystem.h" #include "base/threading/MessageQueue.h" #include "base/threading/ThreadSafeLinearAllocator.h" @@ -46,23 +47,23 @@ CommandBufferAgent::CommandBufferAgent(CommandBuffer *actor) _typedID = actor->getTypedID(); } -void CommandBufferAgent::flushCommands(uint count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded) { - uint jobThreadCount = JobSystem::getInstance()->threadCount(); - uint workForThisThread = (count - 1) / jobThreadCount + 1; // ceil(count / jobThreadCount) +void CommandBufferAgent::flushCommands(uint32_t count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded) { + uint32_t jobThreadCount = JobSystem::getInstance()->threadCount(); + uint32_t workForThisThread = (count - 1) / jobThreadCount + 1; // ceil(count / jobThreadCount) if (count > workForThisThread + 1 && multiThreaded) { // more than one job to dispatch JobGraph g(JobSystem::getInstance()); - g.createForEachIndexJob(workForThisThread, count, 1U, [cmdBuffs](uint i) { + g.createForEachIndexJob(workForThisThread, count, 1U, [cmdBuffs](uint32_t i) { cmdBuffs[i]->getMessageQueue()->flushMessages(); }); g.run(); - for (uint i = 0U; i < workForThisThread; ++i) { + for (uint32_t i = 0U; i < workForThisThread; ++i) { cmdBuffs[i]->getMessageQueue()->flushMessages(); } g.waitForAll(); } else { - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { cmdBuffs[i]->getMessageQueue()->flushMessages(); } } @@ -120,7 +121,7 @@ void CommandBufferAgent::doDestroy() { }); } -void CommandBufferAgent::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void CommandBufferAgent::begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) { ENQUEUE_MESSAGE_4( _messageQueue, CommandBufferBegin, @@ -142,8 +143,8 @@ void CommandBufferAgent::end() { }); } -void CommandBufferAgent::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { - uint attachmentCount = static_cast(renderPass->getColorAttachments().size()); +void CommandBufferAgent::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) { + auto attachmentCount = utils::toUint(renderPass->getColorAttachments().size()); Color *actorColors = nullptr; if (attachmentCount) { actorColors = _messageQueue->allocate(attachmentCount); @@ -153,7 +154,7 @@ void CommandBufferAgent::beginRenderPass(RenderPass *renderPass, Framebuffer *fb CommandBuffer **actorSecondaryCBs = nullptr; if (secondaryCBCount) { actorSecondaryCBs = _messageQueue->allocate(secondaryCBCount); - for (uint i = 0; i < secondaryCBCount; ++i) { + for (uint32_t i = 0; i < secondaryCBCount; ++i) { actorSecondaryCBs[i] = static_cast(secondaryCBs[i])->getActor(); } } @@ -187,7 +188,7 @@ void CommandBufferAgent::execute(CommandBuffer *const *cmdBuffs, uint32_t count) if (!count) return; auto **actorCmdBuffs = _messageQueue->allocate(count); - for (uint i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { actorCmdBuffs[i] = static_cast(cmdBuffs[i])->getActor(); } @@ -211,11 +212,11 @@ void CommandBufferAgent::bindPipelineState(PipelineState *pso) { }); } -void CommandBufferAgent::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { - uint *actorDynamicOffsets = nullptr; +void CommandBufferAgent::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) { + uint32_t *actorDynamicOffsets = nullptr; if (dynamicOffsetCount) { - actorDynamicOffsets = _messageQueue->allocate(dynamicOffsetCount); - memcpy(actorDynamicOffsets, dynamicOffsets, dynamicOffsetCount * sizeof(uint)); + actorDynamicOffsets = _messageQueue->allocate(dynamicOffsetCount); + memcpy(actorDynamicOffsets, dynamicOffsets, dynamicOffsetCount * sizeof(uint32_t)); } ENQUEUE_MESSAGE_5( @@ -303,7 +304,7 @@ void CommandBufferAgent::setDepthBound(float minBounds, float maxBounds) { }); } -void CommandBufferAgent::setStencilWriteMask(StencilFace face, uint mask) { +void CommandBufferAgent::setStencilWriteMask(StencilFace face, uint32_t mask) { ENQUEUE_MESSAGE_3( _messageQueue, CommandBufferSetStencilWriteMask, actor, getActor(), @@ -314,7 +315,7 @@ void CommandBufferAgent::setStencilWriteMask(StencilFace face, uint mask) { }); } -void CommandBufferAgent::setStencilCompareMask(StencilFace face, uint ref, uint mask) { +void CommandBufferAgent::setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) { ENQUEUE_MESSAGE_4( _messageQueue, CommandBufferSetStencilCompareMask, actor, getActor(), @@ -345,7 +346,7 @@ void CommandBufferAgent::draw(const DrawInfo &info) { }); } -void CommandBufferAgent::updateBuffer(Buffer *buff, const void *data, uint size) { +void CommandBufferAgent::updateBuffer(Buffer *buff, const void *data, uint32_t size) { auto *bufferAgent = static_cast(buff); uint8_t *actorBuffer{nullptr}; @@ -367,16 +368,16 @@ void CommandBufferAgent::updateBuffer(Buffer *buff, const void *data, uint size) }); } -void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { - uint bufferCount = 0U; - for (uint i = 0U; i < count; i++) { +void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { + uint32_t bufferCount = 0U; + for (uint32_t i = 0U; i < count; i++) { bufferCount += regions[i].texSubres.layerCount; } - uint totalSize = sizeof(BufferTextureCopy) * count + sizeof(uint8_t *) * bufferCount; - for (uint i = 0U; i < count; i++) { + uint32_t totalSize = sizeof(BufferTextureCopy) * count + sizeof(uint8_t *) * bufferCount; + for (uint32_t i = 0U; i < count; i++) { const BufferTextureCopy ®ion = regions[i]; - uint size = formatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, 1); + uint32_t size = formatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, 1); totalSize += size * region.texSubres.layerCount; } @@ -386,11 +387,11 @@ void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Tex memcpy(actorRegions, regions, count * sizeof(BufferTextureCopy)); const auto **actorBuffers = allocator->allocate(bufferCount); - for (uint i = 0U, n = 0U; i < count; i++) { + for (uint32_t i = 0U, n = 0U; i < count; i++) { const BufferTextureCopy ®ion = regions[i]; - uint size = formatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, 1); - for (uint l = 0; l < region.texSubres.layerCount; l++) { + uint32_t size = formatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, 1); + for (uint32_t l = 0; l < region.texSubres.layerCount; l++) { auto *buffer = allocator->allocate(size); memcpy(buffer, buffers[n], size); actorBuffers[n++] = buffer; @@ -411,7 +412,7 @@ void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Tex }); } -void CommandBufferAgent::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void CommandBufferAgent::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { Texture *actorSrcTexture = nullptr; Texture *actorDstTexture = nullptr; if (srcTexture) actorSrcTexture = static_cast(srcTexture)->getActor(); @@ -446,7 +447,7 @@ void CommandBufferAgent::dispatch(const DispatchInfo &info) { }); } -void CommandBufferAgent::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) { +void CommandBufferAgent::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) { TextureBarrier **actorTextureBarriers = nullptr; Texture ** actorTextures = nullptr; @@ -455,7 +456,7 @@ void CommandBufferAgent::pipelineBarrier(const GlobalBarrier *barrier, const Tex memcpy(actorTextureBarriers, textureBarriers, textureBarrierCount * sizeof(uintptr_t)); actorTextures = _messageQueue->allocate(textureBarrierCount); - for (uint i = 0U; i < textureBarrierCount; ++i) { + for (uint32_t i = 0U; i < textureBarrierCount; ++i) { actorTextures[i] = textures[i] ? static_cast(textures[i])->getActor() : nullptr; } } diff --git a/native/cocos/renderer/gfx-agent/CommandBufferAgent.h b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h index 92cde71613..3d89db89c8 100644 --- a/native/cocos/renderer/gfx-agent/CommandBufferAgent.h +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h @@ -39,14 +39,14 @@ public: explicit CommandBufferAgent(CommandBuffer *actor); ~CommandBufferAgent() override; - static void flushCommands(uint count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded); + static void flushCommands(uint32_t count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded); - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void bindPipelineState(PipelineState *pso) override; - void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override; void bindInputAssembler(InputAssembler *ia) override; void setViewport(const Viewport &vp) override; void setScissor(const Rect &rect) override; @@ -54,20 +54,20 @@ public: void setDepthBias(float constant, float clamp, float slope) override; void setBlendConstants(const Color &constants) override; void setDepthBound(float minBounds, float maxBounds) override; - void setStencilWriteMask(StencilFace face, uint mask) override; - void setStencilCompareMask(StencilFace face, uint ref, uint mask) override; + void setStencilWriteMask(StencilFace face, uint32_t mask) override; + void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override; - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override; - uint getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } - uint getNumInstances() const override { return _actor->getNumInstances(); } - uint getNumTris() const override { return _actor->getNumTris(); } + uint32_t getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } + uint32_t getNumInstances() const override { return _actor->getNumInstances(); } + uint32_t getNumTris() const override { return _actor->getNumTris(); } inline MessageQueue *getMessageQueue() { return _messageQueue; } @@ -77,9 +77,9 @@ protected: void doInit(const CommandBufferInfo &info) override; void doDestroy() override; - void initMessageQueue(); - void destroyMessageQueue(); - MessageQueue * _messageQueue = nullptr; + void initMessageQueue(); + void destroyMessageQueue(); + MessageQueue *_messageQueue = nullptr; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp index 3e5db285ea..c15402ab67 100644 --- a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp @@ -89,7 +89,7 @@ void DescriptorSetAgent::update() { }); } -void DescriptorSetAgent::bindBuffer(uint binding, Buffer *buffer, uint index) { +void DescriptorSetAgent::bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index) { DescriptorSet::bindBuffer(binding, buffer, index); ENQUEUE_MESSAGE_4( @@ -104,7 +104,7 @@ void DescriptorSetAgent::bindBuffer(uint binding, Buffer *buffer, uint index) { }); } -void DescriptorSetAgent::bindTexture(uint binding, Texture *texture, uint index) { +void DescriptorSetAgent::bindTexture(uint32_t binding, Texture *texture, uint32_t index) { DescriptorSet::bindTexture(binding, texture, index); ENQUEUE_MESSAGE_4( @@ -119,7 +119,7 @@ void DescriptorSetAgent::bindTexture(uint binding, Texture *texture, uint index) }); } -void DescriptorSetAgent::bindSampler(uint binding, Sampler *sampler, uint index) { +void DescriptorSetAgent::bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) { DescriptorSet::bindSampler(binding, sampler, index); ENQUEUE_MESSAGE_4( diff --git a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.h b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.h index 6ebfbec6b6..709c74ef0b 100644 --- a/native/cocos/renderer/gfx-agent/DescriptorSetAgent.h +++ b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.h @@ -38,9 +38,9 @@ public: void update() override; - void bindBuffer(uint binding, Buffer *buffer, uint index) override; - void bindTexture(uint binding, Texture *texture, uint index) override; - void bindSampler(uint binding, Sampler *sampler, uint index) override; + void bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index) override; + void bindTexture(uint32_t binding, Texture *texture, uint32_t index) override; + void bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) override; protected: void doInit(const DescriptorSetInfo &info) override; diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp index 1ca78eeb4d..e976ac8fc0 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp @@ -74,7 +74,7 @@ bool DeviceAgent::doInit(const DeviceInfo &info) { _renderer = _actor->getRenderer(); _vendor = _actor->getVendor(); _caps = _actor->_caps; - memcpy(_features.data(), _actor->_features.data(), static_cast(Feature::COUNT) * sizeof(bool)); + memcpy(_features.data(), _actor->_features.data(), static_cast(Feature::COUNT) * sizeof(bool)); _mainMessageQueue = CC_NEW(MessageQueue); @@ -242,28 +242,28 @@ PipelineState *DeviceAgent::createPipelineState() { return CC_NEW(PipelineStateAgent(actor)); } -Sampler *DeviceAgent::createSampler(const SamplerInfo &info) { - return _actor->createSampler(info); +Sampler *DeviceAgent::createSampler(const SamplerInfo &info, uint32_t hash) { + return _actor->createSampler(info, hash); } -GlobalBarrier *DeviceAgent::createGlobalBarrier(const GlobalBarrierInfo &info) { - return _actor->createGlobalBarrier(info); +GlobalBarrier *DeviceAgent::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) { + return _actor->createGlobalBarrier(info, hash); } -TextureBarrier *DeviceAgent::createTextureBarrier(const TextureBarrierInfo &info) { - return _actor->createTextureBarrier(info); +TextureBarrier *DeviceAgent::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) { + return _actor->createTextureBarrier(info, hash); } -void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { - uint bufferCount = 0U; - for (uint i = 0U; i < count; i++) { +void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { + uint32_t bufferCount = 0U; + for (uint32_t i = 0U; i < count; i++) { bufferCount += regions[i].texSubres.layerCount; } - uint totalSize = sizeof(BufferTextureCopy) * count + sizeof(uint8_t *) * bufferCount; - for (uint i = 0U; i < count; i++) { + uint32_t totalSize = sizeof(BufferTextureCopy) * count + sizeof(uint8_t *) * bufferCount; + for (uint32_t i = 0U; i < count; i++) { const BufferTextureCopy ®ion = regions[i]; - uint size = formatSize(dst->getFormat(), region.texExtent.width, region.texExtent.height, 1); + uint32_t size = formatSize(dst->getFormat(), region.texExtent.width, region.texExtent.height, 1); totalSize += size * region.texSubres.layerCount; } @@ -273,11 +273,11 @@ void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *d memcpy(actorRegions, regions, count * sizeof(BufferTextureCopy)); const auto **actorBuffers = allocator->allocate(bufferCount); - for (uint i = 0U, n = 0U; i < count; i++) { + for (uint32_t i = 0U, n = 0U; i < count; i++) { const BufferTextureCopy ®ion = regions[i]; - uint size = formatSize(dst->getFormat(), region.texExtent.width, region.texExtent.height, 1); - for (uint l = 0; l < region.texSubres.layerCount; l++) { + uint32_t size = formatSize(dst->getFormat(), region.texExtent.width, region.texExtent.height, 1); + for (uint32_t l = 0; l < region.texSubres.layerCount; l++) { auto *buffer = allocator->allocate(size); memcpy(buffer, buffers[n], size); actorBuffers[n++] = buffer; @@ -298,7 +298,7 @@ void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *d }); } -void DeviceAgent::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { +void DeviceAgent::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { ENQUEUE_MESSAGE_5( _mainMessageQueue, DeviceCopyTextureToBuffers, @@ -314,12 +314,12 @@ void DeviceAgent::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buff _mainMessageQueue->kickAndWait(); } -void DeviceAgent::flushCommands(CommandBuffer *const *cmdBuffs, uint count) { +void DeviceAgent::flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) { if (!_multithreaded) return; // all command buffers are immediately executed auto **agentCmdBuffs = _mainMessageQueue->allocate(count); - for (uint i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { agentCmdBuffs[i] = static_cast(cmdBuffs[i]); MessageQueue::freeChunksInFreeQueue(agentCmdBuffs[i]->_messageQueue); agentCmdBuffs[i]->_messageQueue->finishWriting(); diff --git a/native/cocos/renderer/gfx-agent/DeviceAgent.h b/native/cocos/renderer/gfx-agent/DeviceAgent.h index 0cc8c2dbfb..ed1bd42a44 100644 --- a/native/cocos/renderer/gfx-agent/DeviceAgent.h +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.h @@ -40,9 +40,9 @@ class CommandBufferAgent; class CC_DLL DeviceAgent final : public Agent { public: - static DeviceAgent * getInstance(); - static constexpr uint MAX_CPU_FRAME_AHEAD = 1; - static constexpr uint MAX_FRAME_INDEX = MAX_CPU_FRAME_AHEAD + 1; + static DeviceAgent * getInstance(); + static constexpr uint32_t MAX_CPU_FRAME_AHEAD = 1; + static constexpr uint32_t MAX_FRAME_INDEX = MAX_CPU_FRAME_AHEAD + 1; ~DeviceAgent() override; @@ -80,20 +80,20 @@ public: PipelineLayout * createPipelineLayout() override; PipelineState * createPipelineState() override; - Sampler * createSampler(const SamplerInfo &info) override; - GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) override; + Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override; + GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; - void flushCommands(CommandBuffer *const *cmdBuffs, uint count) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override; + void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override; + void flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) override; MemoryStatus &getMemoryStatus() override { return _actor->getMemoryStatus(); } - uint getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } - uint getNumInstances() const override { return _actor->getNumInstances(); } - uint getNumTris() const override { return _actor->getNumTris(); } + uint32_t getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } + uint32_t getNumInstances() const override { return _actor->getNumInstances(); } + uint32_t getNumTris() const override { return _actor->getNumTris(); } - uint getCurrentIndex() const { return _currentIndex; } - void setMultithreaded(bool multithreaded); + uint32_t getCurrentIndex() const { return _currentIndex; } + void setMultithreaded(bool multithreaded); inline MessageQueue *getMessageQueue() const { return _mainMessageQueue; } @@ -111,7 +111,7 @@ protected: bool _multithreaded{false}; MessageQueue *_mainMessageQueue{nullptr}; - uint _currentIndex = 0U; + uint32_t _currentIndex = 0U; Semaphore _frameBoundarySemaphore{MAX_CPU_FRAME_AHEAD}; unordered_set _cmdBuffRefs; diff --git a/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp b/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp index 21cd1f8e20..e7ff860e65 100644 --- a/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp @@ -51,7 +51,7 @@ FramebufferAgent::~FramebufferAgent() { void FramebufferAgent::doInit(const FramebufferInfo &info) { FramebufferInfo actorInfo = info; - for (uint i = 0U; i < info.colorTextures.size(); ++i) { + for (uint32_t i = 0U; i < info.colorTextures.size(); ++i) { if (info.colorTextures[i]) { actorInfo.colorTextures[i] = static_cast(info.colorTextures[i])->getActor(); } diff --git a/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp index 4d93e1e488..d1e5d4c31b 100644 --- a/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp +++ b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp @@ -80,82 +80,5 @@ void InputAssemblerAgent::doDestroy() { }); } -void InputAssemblerAgent::setVertexCount(uint32_t count) { - _drawInfo.vertexCount = count; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - count, count, - { - actor->setVertexCount(count); - }); -} - -void InputAssemblerAgent::setFirstVertex(uint32_t first) { - _drawInfo.firstVertex = first; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - first, first, - { - actor->setFirstVertex(first); - }); -} - -void InputAssemblerAgent::setIndexCount(uint32_t count) { - _drawInfo.indexCount = count; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - count, count, - { - actor->setIndexCount(count); - }); -} - -void InputAssemblerAgent::setFirstIndex(uint32_t first) { - _drawInfo.firstIndex = first; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - first, first, - { - actor->setFirstIndex(first); - }); -} - -void InputAssemblerAgent::setVertexOffset(int32_t offset) { - _drawInfo.vertexOffset = offset; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - offset, offset, - { - actor->setVertexOffset(offset); - }); -} - -void InputAssemblerAgent::setInstanceCount(uint32_t count) { - _drawInfo.instanceCount = count; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - count, count, - { - actor->setInstanceCount(count); - }); -} - -void InputAssemblerAgent::setFirstInstance(uint32_t first) { - _drawInfo.firstInstance = first; - ENQUEUE_MESSAGE_2( - DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, - actor, getActor(), - first, first, - { - actor->setFirstInstance(first); - }); -} - } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-agent/InputAssemblerAgent.h b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.h index bae35762c1..af1e2e0654 100644 --- a/native/cocos/renderer/gfx-agent/InputAssemblerAgent.h +++ b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.h @@ -36,14 +36,6 @@ public: explicit InputAssemblerAgent(InputAssembler *actor); ~InputAssemblerAgent() override; - void setVertexCount(uint32_t count) override; - void setFirstVertex(uint32_t first) override; - void setIndexCount(uint32_t count) override; - void setFirstIndex(uint32_t first) override; - void setVertexOffset(int32_t offset) override; - void setInstanceCount(uint32_t count) override; - void setFirstInstance(uint32_t first) override; - protected: void doInit(const InputAssemblerInfo &info) override; void doDestroy() override; diff --git a/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp index 57c3fc3526..38026eb0ea 100644 --- a/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp +++ b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp @@ -51,7 +51,7 @@ PipelineLayoutAgent::~PipelineLayoutAgent() { void PipelineLayoutAgent::doInit(const PipelineLayoutInfo &info) { PipelineLayoutInfo actorInfo; actorInfo.setLayouts.resize(info.setLayouts.size()); - for (uint i = 0U; i < info.setLayouts.size(); i++) { + for (uint32_t i = 0U; i < info.setLayouts.size(); i++) { actorInfo.setLayouts[i] = static_cast(info.setLayouts[i])->getActor(); } diff --git a/native/cocos/renderer/gfx-agent/QueueAgent.cpp b/native/cocos/renderer/gfx-agent/QueueAgent.cpp index 5b8b40fe59..001e3d1a0b 100644 --- a/native/cocos/renderer/gfx-agent/QueueAgent.cpp +++ b/native/cocos/renderer/gfx-agent/QueueAgent.cpp @@ -70,12 +70,12 @@ void QueueAgent::doDestroy() { }); } -void QueueAgent::submit(CommandBuffer *const *cmdBuffs, uint count) { +void QueueAgent::submit(CommandBuffer *const *cmdBuffs, uint32_t count) { if (!count) return; - MessageQueue *msgQ = DeviceAgent::getInstance()->getMessageQueue(); - auto **actorCmdBuffs = msgQ->allocate(count); - for (uint i = 0U; i < count; ++i) { + MessageQueue *msgQ = DeviceAgent::getInstance()->getMessageQueue(); + auto ** actorCmdBuffs = msgQ->allocate(count); + for (uint32_t i = 0U; i < count; ++i) { actorCmdBuffs[i] = static_cast(cmdBuffs[i])->getActor(); } diff --git a/native/cocos/renderer/gfx-agent/QueueAgent.h b/native/cocos/renderer/gfx-agent/QueueAgent.h index 43a317f0b2..6ca1259442 100644 --- a/native/cocos/renderer/gfx-agent/QueueAgent.h +++ b/native/cocos/renderer/gfx-agent/QueueAgent.h @@ -38,7 +38,7 @@ public: explicit QueueAgent(Queue *actor); ~QueueAgent() override; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override; protected: friend class DeviceAgent; diff --git a/native/cocos/renderer/gfx-agent/TextureAgent.cpp b/native/cocos/renderer/gfx-agent/TextureAgent.cpp index 41c951a661..21a40b9fbe 100644 --- a/native/cocos/renderer/gfx-agent/TextureAgent.cpp +++ b/native/cocos/renderer/gfx-agent/TextureAgent.cpp @@ -90,7 +90,7 @@ void TextureAgent::doDestroy() { }); } -void TextureAgent::doResize(uint width, uint height, uint /*size*/) { +void TextureAgent::doResize(uint32_t width, uint32_t height, uint32_t /*size*/) { ENQUEUE_MESSAGE_3( DeviceAgent::getInstance()->getMessageQueue(), TextureResize, diff --git a/native/cocos/renderer/gfx-agent/TextureAgent.h b/native/cocos/renderer/gfx-agent/TextureAgent.h index 4a2501607f..c400abe001 100644 --- a/native/cocos/renderer/gfx-agent/TextureAgent.h +++ b/native/cocos/renderer/gfx-agent/TextureAgent.h @@ -43,7 +43,7 @@ protected: void doInit(const TextureViewInfo &info) override; void doInit(const SwapchainTextureInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, uint size) override; + void doResize(uint32_t width, uint32_t height, uint32_t size) override; bool _ownTheActor = true; }; diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.cpp b/native/cocos/renderer/gfx-base/GFXBuffer.cpp index 071955b8d8..a9f3d0861a 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXBuffer.cpp @@ -38,12 +38,12 @@ Buffer::Buffer() Buffer::~Buffer() = default; -uint Buffer::computeHash(const BufferInfo &info) { - uint seed = 4; - seed ^= static_cast(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.memUsage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.size) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +uint32_t Buffer::computeHash(const BufferInfo &info) { + uint32_t seed = 4; + seed ^= static_cast(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.memUsage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.size) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } @@ -76,9 +76,9 @@ void Buffer::destroy() { _offset = _size = _stride = _count = 0U; } -void Buffer::resize(uint size) { +void Buffer::resize(uint32_t size) { if (size != _size) { - uint count = size / _stride; + uint32_t count = size / _stride; doResize(size, count); _size = size; diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.h b/native/cocos/renderer/gfx-base/GFXBuffer.h index 69951edd20..aa18bf9aa9 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXBuffer.h @@ -35,37 +35,37 @@ public: Buffer(); ~Buffer() override; - static uint computeHash(const BufferInfo &info); + static uint32_t computeHash(const BufferInfo &info); void initialize(const BufferInfo &info); void initialize(const BufferViewInfo &info); - void resize(uint size); + void resize(uint32_t size); void destroy(); - virtual void update(const void *buffer, uint size) = 0; + virtual void update(const void *buffer, uint32_t size) = 0; inline void update(const void *buffer) { update(buffer, _size); } inline BufferUsage getUsage() const { return _usage; } inline MemoryUsage getMemUsage() const { return _memUsage; } - inline uint getStride() const { return _stride; } - inline uint getCount() const { return _count; } - inline uint getSize() const { return _size; } + inline uint32_t getStride() const { return _stride; } + inline uint32_t getCount() const { return _count; } + inline uint32_t getSize() const { return _size; } inline BufferFlags getFlags() const { return _flags; } inline bool isBufferView() const { return _isBufferView; } protected: - virtual void doInit(const BufferInfo &info) = 0; - virtual void doInit(const BufferViewInfo &info) = 0; - virtual void doResize(uint size, uint count) = 0; - virtual void doDestroy() = 0; + virtual void doInit(const BufferInfo &info) = 0; + virtual void doInit(const BufferViewInfo &info) = 0; + virtual void doResize(uint32_t size, uint32_t count) = 0; + virtual void doDestroy() = 0; BufferUsage _usage = BufferUsageBit::NONE; MemoryUsage _memUsage = MemoryUsageBit::NONE; - uint _stride = 0U; - uint _count = 0U; - uint _size = 0U; - uint _offset = 0U; + uint32_t _stride = 0U; + uint32_t _count = 0U; + uint32_t _size = 0U; + uint32_t _offset = 0U; BufferFlags _flags = BufferFlagBit::NONE; bool _isBufferView = false; }; diff --git a/native/cocos/renderer/gfx-base/GFXCommandBuffer.h b/native/cocos/renderer/gfx-base/GFXCommandBuffer.h index 477beb420e..34ae4eda98 100644 --- a/native/cocos/renderer/gfx-base/GFXCommandBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXCommandBuffer.h @@ -41,44 +41,44 @@ public: void initialize(const CommandBufferInfo &info); void destroy(); - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) = 0; - virtual void end() = 0; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) = 0; - virtual void endRenderPass() = 0; - virtual void bindPipelineState(PipelineState *pso) = 0; - virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) = 0; - virtual void bindInputAssembler(InputAssembler *ia) = 0; - virtual void setViewport(const Viewport &vp) = 0; - virtual void setScissor(const Rect &rect) = 0; - virtual void setLineWidth(float width) = 0; - virtual void setDepthBias(float constant, float clamp, float slope) = 0; - virtual void setBlendConstants(const Color &constants) = 0; - virtual void setDepthBound(float minBounds, float maxBounds) = 0; - virtual void setStencilWriteMask(StencilFace face, uint mask) = 0; - virtual void setStencilCompareMask(StencilFace face, uint ref, uint mask) = 0; - virtual void nextSubpass() = 0; - virtual void draw(const DrawInfo &info) = 0; - virtual void updateBuffer(Buffer *buff, const void *data, uint size) = 0; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) = 0; - virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) = 0; - virtual void execute(CommandBuffer *const *cmdBuffs, uint32_t count) = 0; - virtual void dispatch(const DispatchInfo &info) = 0; - virtual void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) = 0; + virtual void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) = 0; + virtual void end() = 0; + virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) = 0; + virtual void endRenderPass() = 0; + virtual void bindPipelineState(PipelineState *pso) = 0; + virtual void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) = 0; + virtual void bindInputAssembler(InputAssembler *ia) = 0; + virtual void setViewport(const Viewport &vp) = 0; + virtual void setScissor(const Rect &rect) = 0; + virtual void setLineWidth(float width) = 0; + virtual void setDepthBias(float constant, float clamp, float slope) = 0; + virtual void setBlendConstants(const Color &constants) = 0; + virtual void setDepthBound(float minBounds, float maxBounds) = 0; + virtual void setStencilWriteMask(StencilFace face, uint32_t mask) = 0; + virtual void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) = 0; + virtual void nextSubpass() = 0; + virtual void draw(const DrawInfo &info) = 0; + virtual void updateBuffer(Buffer *buff, const void *data, uint32_t size) = 0; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) = 0; + virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) = 0; + virtual void execute(CommandBuffer *const *cmdBuffs, uint32_t count) = 0; + virtual void dispatch(const DispatchInfo &info) = 0; + virtual void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) = 0; inline void begin(); inline void begin(RenderPass *renderPass); - inline void begin(RenderPass *renderPass, uint subpass); + inline void begin(RenderPass *renderPass, uint32_t subpass); inline void updateBuffer(Buffer *buff, const void *data); inline void execute(const CommandBufferList &cmdBuffs, uint32_t count); - inline void bindDescriptorSet(uint set, DescriptorSet *descriptorSet); - inline void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets); + inline void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet); + inline void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, const vector &dynamicOffsets); - inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint stencil, const CommandBufferList &secondaryCBs); - inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint stencil); - inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil); + inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint32_t stencil, const CommandBufferList &secondaryCBs); + inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint32_t stencil); + inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil); inline void draw(InputAssembler *ia); inline void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions); @@ -91,9 +91,9 @@ public: inline Queue * getQueue() const { return _queue; } inline CommandBufferType getType() const { return _type; } - virtual uint getNumDrawCalls() const { return _numDrawCalls; } - virtual uint getNumInstances() const { return _numInstances; } - virtual uint getNumTris() const { return _numTriangles; } + virtual uint32_t getNumDrawCalls() const { return _numDrawCalls; } + virtual uint32_t getNumInstances() const { return _numInstances; } + virtual uint32_t getNumTris() const { return _numTriangles; } protected: virtual void doInit(const CommandBufferInfo &info) = 0; @@ -117,7 +117,7 @@ void CommandBuffer::begin(RenderPass *renderPass) { begin(renderPass, 0, nullptr); } -void CommandBuffer::begin(RenderPass *renderPass, uint subpass) { +void CommandBuffer::begin(RenderPass *renderPass, uint32_t subpass) { begin(renderPass, subpass, nullptr); } @@ -129,23 +129,23 @@ void CommandBuffer::execute(const CommandBufferList &cmdBuffs, uint32_t count) { execute(cmdBuffs.data(), count); } -void CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet) { +void CommandBuffer::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet) { bindDescriptorSet(set, descriptorSet, 0, nullptr); } -void CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { +void CommandBuffer::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { bindDescriptorSet(set, descriptorSet, utils::toUint(dynamicOffsets.size()), dynamicOffsets.data()); } -void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint stencil, const CommandBufferList &secondaryCBs) { +void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint32_t stencil, const CommandBufferList &secondaryCBs) { beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), utils::toUint(secondaryCBs.size())); } -void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint stencil) { +void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, uint32_t stencil) { beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, nullptr, 0); } -void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil) { +void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil) { beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, nullptr, 0); } diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index 5b7161f2d3..ef4c4e41b7 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -153,8 +153,21 @@ enum class Feature : uint32_t { MULTIPLE_RENDER_TARGETS, BLEND_MINMAX, COMPUTE_SHADER, - GL_FRAMEBUFFER_FETCH, - GL_PIXEL_LOCAL_STORAGE, + // This flag indicates whether the device can benefit from subpass-style usages. + // Specifically, this only differs on the GLES backends: the Framebuffer Fetch + // extension is used to simulate input attachments, so the flag is not set when + // the extension is not supported, and you should switch to the fallback branch + // (without the extension requirement) in GLSL shader sources accordingly. + // Everything else can remain the same. + // + // Another caveat when using the Framebuffer Fetch extensions in shaders is that + // for subpasses with exactly 4 inout attachments the output is automatically set + // to the last attachment (taking advantage of 'inout' property), and a separate + // blit operation (if needed) will be added for you afterwards to transfer the + // rendering result to the corrent subpass output texture. This is to ameliorate + // the maxnumber of attachment limit(4) situation for many devices, and shader + // sources inside this kind of subpass must match this behavior. + INPUT_ATTACHMENT_BENEFIT, COUNT, }; CC_ENUM_CONVERSION_OPERATOR(Feature); @@ -685,14 +698,12 @@ CC_ENUM_CONVERSION_OPERATOR(CullMode); enum class DynamicStateFlagBit : uint32_t { NONE = 0x0, - VIEWPORT = 0x1, - SCISSOR = 0x2, - LINE_WIDTH = 0x4, - DEPTH_BIAS = 0x8, - BLEND_CONSTANTS = 0x10, - DEPTH_BOUNDS = 0x20, - STENCIL_WRITE_MASK = 0x40, - STENCIL_COMPARE_MASK = 0x80, + LINE_WIDTH = 0x1, + DEPTH_BIAS = 0x2, + BLEND_CONSTANTS = 0x4, + DEPTH_BOUNDS = 0x8, + STENCIL_WRITE_MASK = 0x10, + STENCIL_COMPARE_MASK = 0x20, }; using DynamicStateFlags = DynamicStateFlagBit; CC_ENUM_BITWISE_OPERATORS(DynamicStateFlagBit); diff --git a/native/cocos/renderer/gfx-base/GFXDef.cpp b/native/cocos/renderer/gfx-base/GFXDef.cpp index c772565480..65437dff71 100644 --- a/native/cocos/renderer/gfx-base/GFXDef.cpp +++ b/native/cocos/renderer/gfx-base/GFXDef.cpp @@ -163,11 +163,11 @@ bool isCombinedImageSampler(Type type) { return type >= Type::SAMPLER1D && type bool isSampledImage(Type type) { return type >= Type::TEXTURE1D && type <= Type::TEXTURE_CUBE; } bool isStorageImage(Type type) { return type >= Type::IMAGE1D && type <= Type::IMAGE_CUBE; } -uint ceilDiv(uint x, uint y) { return (x - 1) / y + 1; } +uint32_t ceilDiv(uint32_t x, uint32_t y) { return (x - 1) / y + 1; } -uint formatSize(Format format, uint width, uint height, uint depth) { - if (!GFX_FORMAT_INFOS[static_cast(format)].isCompressed) { - return (width * height * depth * GFX_FORMAT_INFOS[static_cast(format)].size); +uint32_t formatSize(Format format, uint32_t width, uint32_t height, uint32_t depth) { + if (!GFX_FORMAT_INFOS[static_cast(format)].isCompressed) { + return (width * height * depth * GFX_FORMAT_INFOS[static_cast(format)].size); } switch (format) { case Format::BC1: @@ -259,7 +259,7 @@ uint formatSize(Format format, uint width, uint height, uint depth) { } } -const uint GFX_TYPE_SIZES[] = { +const uint32_t GFX_TYPE_SIZES[] = { 0, // UNKNOWN 4, // BOOL 8, // BOOL2 @@ -294,10 +294,10 @@ const uint GFX_TYPE_SIZES[] = { 4, // SAMPLER_CUBE }; -uint formatSurfaceSize(Format format, uint width, uint height, uint depth, uint mips) { - uint size = 0; +uint32_t formatSurfaceSize(Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t mips) { + uint32_t size = 0; - for (uint i = 0; i < mips; ++i) { + for (uint32_t i = 0; i < mips; ++i) { size += formatSize(format, width, height, depth); width = std::max(width >> 1, 1U); height = std::max(height >> 1, 1U); diff --git a/native/cocos/renderer/gfx-base/GFXDef.h b/native/cocos/renderer/gfx-base/GFXDef.h index 4fe9b0479a..43bd2ba026 100644 --- a/native/cocos/renderer/gfx-base/GFXDef.h +++ b/native/cocos/renderer/gfx-base/GFXDef.h @@ -38,35 +38,35 @@ struct SwapchainTextureInfo { }; constexpr TextureUsage TEXTURE_USAGE_TRANSIENT = static_cast( - static_cast(TextureUsageBit::COLOR_ATTACHMENT) | - static_cast(TextureUsageBit::DEPTH_STENCIL_ATTACHMENT) | - static_cast(TextureUsageBit::INPUT_ATTACHMENT)); + static_cast(TextureUsageBit::COLOR_ATTACHMENT) | + static_cast(TextureUsageBit::DEPTH_STENCIL_ATTACHMENT) | + static_cast(TextureUsageBit::INPUT_ATTACHMENT)); constexpr DescriptorType DESCRIPTOR_BUFFER_TYPE = static_cast( - static_cast(DescriptorType::STORAGE_BUFFER) | - static_cast(DescriptorType::DYNAMIC_STORAGE_BUFFER) | - static_cast(DescriptorType::UNIFORM_BUFFER) | - static_cast(DescriptorType::DYNAMIC_UNIFORM_BUFFER)); + static_cast(DescriptorType::STORAGE_BUFFER) | + static_cast(DescriptorType::DYNAMIC_STORAGE_BUFFER) | + static_cast(DescriptorType::UNIFORM_BUFFER) | + static_cast(DescriptorType::DYNAMIC_UNIFORM_BUFFER)); constexpr DescriptorType DESCRIPTOR_TEXTURE_TYPE = static_cast( - static_cast(DescriptorType::SAMPLER_TEXTURE) | - static_cast(DescriptorType::SAMPLER) | - static_cast(DescriptorType::TEXTURE) | - static_cast(DescriptorType::STORAGE_IMAGE) | - static_cast(DescriptorType::INPUT_ATTACHMENT)); + static_cast(DescriptorType::SAMPLER_TEXTURE) | + static_cast(DescriptorType::SAMPLER) | + static_cast(DescriptorType::TEXTURE) | + static_cast(DescriptorType::STORAGE_IMAGE) | + static_cast(DescriptorType::INPUT_ATTACHMENT)); constexpr DescriptorType DESCRIPTOR_DYNAMIC_TYPE = static_cast( - static_cast(DescriptorType::DYNAMIC_STORAGE_BUFFER) | - static_cast(DescriptorType::DYNAMIC_UNIFORM_BUFFER)); + static_cast(DescriptorType::DYNAMIC_STORAGE_BUFFER) | + static_cast(DescriptorType::DYNAMIC_UNIFORM_BUFFER)); -constexpr uint DRAW_INFO_SIZE = 28U; +constexpr uint32_t DRAW_INFO_SIZE = 28U; extern const FormatInfo GFX_FORMAT_INFOS[]; -extern const uint GFX_TYPE_SIZES[]; +extern const uint32_t GFX_TYPE_SIZES[]; -extern uint formatSize(Format format, uint width, uint height, uint depth); +extern uint32_t formatSize(Format format, uint32_t width, uint32_t height, uint32_t depth); -extern uint formatSurfaceSize(Format format, uint width, uint height, uint depth, uint mips); +extern uint32_t formatSurfaceSize(Format format, uint32_t width, uint32_t height, uint32_t depth, uint32_t mips); } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp b/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp index 217182c51d..7fac26c906 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp @@ -41,8 +41,8 @@ DescriptorSet::~DescriptorSet() = default; void DescriptorSet::initialize(const DescriptorSetInfo &info) { CCASSERT(info.layout, "Invalid set layout"); - _layout = info.layout; - uint descriptorCount = _layout->getDescriptorCount(); + _layout = info.layout; + uint32_t descriptorCount = _layout->getDescriptorCount(); _buffers.resize(descriptorCount); _textures.resize(descriptorCount); _samplers.resize(descriptorCount); @@ -60,65 +60,65 @@ void DescriptorSet::destroy() { _samplers.clear(); } -void DescriptorSet::bindBuffer(uint binding, Buffer *buffer, uint index) { - const uint descriptorIndex = _layout->getDescriptorIndices()[binding]; +void DescriptorSet::bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index) { + const uint32_t descriptorIndex = _layout->getDescriptorIndices()[binding]; if (_buffers[descriptorIndex + index] != buffer) { _buffers[descriptorIndex + index] = buffer; _isDirty = true; } } -void DescriptorSet::bindTexture(uint binding, Texture *texture, uint index) { - const uint descriptorIndex = _layout->getDescriptorIndices()[binding]; +void DescriptorSet::bindTexture(uint32_t binding, Texture *texture, uint32_t index) { + const uint32_t descriptorIndex = _layout->getDescriptorIndices()[binding]; if (_textures[descriptorIndex + index] != texture) { _textures[descriptorIndex + index] = texture; _isDirty = true; } } -void DescriptorSet::bindSampler(uint binding, Sampler *sampler, uint index) { - const uint descriptorIndex = _layout->getDescriptorIndices()[binding]; +void DescriptorSet::bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) { + const uint32_t descriptorIndex = _layout->getDescriptorIndices()[binding]; if (_samplers[descriptorIndex + index] != sampler) { _samplers[descriptorIndex + index] = sampler; _isDirty = true; } } -bool DescriptorSet::bindBufferJSB(uint binding, Buffer *buffer, uint index) { +bool DescriptorSet::bindBufferJSB(uint32_t binding, Buffer *buffer, uint32_t index) { bindBuffer(binding, buffer, index); return _isDirty; } -bool DescriptorSet::bindTextureJSB(uint binding, Texture *texture, uint index) { +bool DescriptorSet::bindTextureJSB(uint32_t binding, Texture *texture, uint32_t index) { bindTexture(binding, texture, index); return _isDirty; } -bool DescriptorSet::bindSamplerJSB(uint binding, Sampler *sampler, uint index) { +bool DescriptorSet::bindSamplerJSB(uint32_t binding, Sampler *sampler, uint32_t index) { bindSampler(binding, sampler, index); return _isDirty; } -Buffer *DescriptorSet::getBuffer(uint binding, uint index) const { - const vector &descriptorIndices = _layout->getDescriptorIndices(); +Buffer *DescriptorSet::getBuffer(uint32_t binding, uint32_t index) const { + const vector &descriptorIndices = _layout->getDescriptorIndices(); if (binding >= descriptorIndices.size()) return nullptr; - const uint descriptorIndex = descriptorIndices[binding] + index; + const uint32_t descriptorIndex = descriptorIndices[binding] + index; if (descriptorIndex >= _buffers.size()) return nullptr; return _buffers[descriptorIndex]; } -Texture *DescriptorSet::getTexture(uint binding, uint index) const { - const vector &descriptorIndices = _layout->getDescriptorIndices(); +Texture *DescriptorSet::getTexture(uint32_t binding, uint32_t index) const { + const vector &descriptorIndices = _layout->getDescriptorIndices(); if (binding >= descriptorIndices.size()) return nullptr; - const uint descriptorIndex = descriptorIndices[binding] + index; + const uint32_t descriptorIndex = descriptorIndices[binding] + index; if (descriptorIndex >= _textures.size()) return nullptr; return _textures[descriptorIndex]; } -Sampler *DescriptorSet::getSampler(uint binding, uint index) const { - const vector &descriptorIndices = _layout->getDescriptorIndices(); +Sampler *DescriptorSet::getSampler(uint32_t binding, uint32_t index) const { + const vector &descriptorIndices = _layout->getDescriptorIndices(); if (binding >= descriptorIndices.size()) return nullptr; - const uint descriptorIndex = descriptorIndices[binding] + index; + const uint32_t descriptorIndex = descriptorIndices[binding] + index; if (descriptorIndex >= _samplers.size()) return nullptr; return _samplers[descriptorIndex]; } diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSet.h b/native/cocos/renderer/gfx-base/GFXDescriptorSet.h index 2c73218e72..8a69f5ecaa 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSet.h +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSet.h @@ -40,27 +40,27 @@ public: virtual void update() = 0; - virtual void bindBuffer(uint binding, Buffer *buffer, uint index); - virtual void bindTexture(uint binding, Texture *texture, uint index); - virtual void bindSampler(uint binding, Sampler *sampler, uint index); + virtual void bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index); + virtual void bindTexture(uint32_t binding, Texture *texture, uint32_t index); + virtual void bindSampler(uint32_t binding, Sampler *sampler, uint32_t index); // Functions invoked by JSB adapter - bool bindBufferJSB(uint binding, Buffer *buffer, uint index); - bool bindTextureJSB(uint binding, Texture *texture, uint index); - bool bindSamplerJSB(uint binding, Sampler *sampler, uint index); + bool bindBufferJSB(uint32_t binding, Buffer *buffer, uint32_t index); + bool bindTextureJSB(uint32_t binding, Texture *texture, uint32_t index); + bool bindSamplerJSB(uint32_t binding, Sampler *sampler, uint32_t index); - Buffer * getBuffer(uint binding, uint index) const; - Texture *getTexture(uint binding, uint index) const; - Sampler *getSampler(uint binding, uint index) const; + Buffer * getBuffer(uint32_t binding, uint32_t index) const; + Texture *getTexture(uint32_t binding, uint32_t index) const; + Sampler *getSampler(uint32_t binding, uint32_t index) const; inline DescriptorSetLayout *getLayout() { return _layout; } - inline void bindBuffer(uint binding, Buffer *buffer) { bindBuffer(binding, buffer, 0U); } - inline void bindTexture(uint binding, Texture *texture) { bindTexture(binding, texture, 0U); } - inline void bindSampler(uint binding, Sampler *sampler) { bindSampler(binding, sampler, 0U); } - inline Buffer * getBuffer(uint binding) const { return getBuffer(binding, 0U); } - inline Texture *getTexture(uint binding) const { return getTexture(binding, 0U); } - inline Sampler *getSampler(uint binding) const { return getSampler(binding, 0U); } + inline void bindBuffer(uint32_t binding, Buffer *buffer) { bindBuffer(binding, buffer, 0U); } + inline void bindTexture(uint32_t binding, Texture *texture) { bindTexture(binding, texture, 0U); } + inline void bindSampler(uint32_t binding, Sampler *sampler) { bindSampler(binding, sampler, 0U); } + inline Buffer * getBuffer(uint32_t binding) const { return getBuffer(binding, 0U); } + inline Texture *getTexture(uint32_t binding) const { return getTexture(binding, 0U); } + inline Sampler *getSampler(uint32_t binding) const { return getSampler(binding, 0U); } protected: virtual void doInit(const DescriptorSetInfo &info) = 0; diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp index 2102104020..c486a84cf0 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp @@ -25,6 +25,7 @@ #include "GFXObject.h" #include "base/CoreStd.h" +#include "base/Utils.h" #include "GFXDescriptorSetLayout.h" @@ -39,13 +40,13 @@ DescriptorSetLayout::~DescriptorSetLayout() = default; void DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { _bindings = info.bindings; - uint bindingCount = static_cast(_bindings.size()); + auto bindingCount = utils::toUint(_bindings.size()); _descriptorCount = 0U; if (bindingCount) { - uint maxBinding = 0U; - vector flattenedIndices(bindingCount); - for (uint i = 0U; i < bindingCount; i++) { + uint32_t maxBinding = 0U; + vector flattenedIndices(bindingCount); + for (uint32_t i = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; if (binding.binding > maxBinding) maxBinding = binding.binding; flattenedIndices[i] = _descriptorCount; @@ -54,12 +55,12 @@ void DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { _bindingIndices.resize(maxBinding + 1, INVALID_BINDING); _descriptorIndices.resize(maxBinding + 1, INVALID_BINDING); - for (uint i = 0U; i < bindingCount; i++) { + for (uint32_t i = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; _bindingIndices[binding.binding] = i; _descriptorIndices[binding.binding] = flattenedIndices[i]; if (hasFlag(DESCRIPTOR_DYNAMIC_TYPE, binding.descriptorType)) { - for (uint j = 0U; j < binding.count; ++j) { + for (uint32_t j = 0U; j < binding.count; ++j) { _dynamicBindings.push_back(binding.binding); } } diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h index c517c6bc19..177cf448d9 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h @@ -39,20 +39,20 @@ public: void destroy(); inline const DescriptorSetLayoutBindingList &getBindings() const { return _bindings; } - inline const vector & getDynamicBindings() const { return _dynamicBindings; } - inline const vector & getBindingIndices() const { return _bindingIndices; } - inline const vector & getDescriptorIndices() const { return _descriptorIndices; } - inline uint getDescriptorCount() const { return _descriptorCount; } + inline const vector & getDynamicBindings() const { return _dynamicBindings; } + inline const vector & getBindingIndices() const { return _bindingIndices; } + inline const vector & getDescriptorIndices() const { return _descriptorIndices; } + inline uint32_t getDescriptorCount() const { return _descriptorCount; } protected: virtual void doInit(const DescriptorSetLayoutInfo &info) = 0; virtual void doDestroy() = 0; DescriptorSetLayoutBindingList _bindings; - uint _descriptorCount = 0U; - vector _bindingIndices; - vector _descriptorIndices; - vector _dynamicBindings; + uint32_t _descriptorCount = 0U; + vector _bindingIndices; + vector _descriptorIndices; + vector _dynamicBindings; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index 6892ff14a0..8bf785dfde 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -59,12 +59,12 @@ public: virtual void acquire(Swapchain *const *swapchains, uint32_t count) = 0; virtual void present() = 0; - virtual void flushCommands(CommandBuffer *const *cmdBuffs, uint count) {} + virtual void flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) {} virtual MemoryStatus &getMemoryStatus() { return _memoryStatus; } - virtual uint getNumDrawCalls() const { return _numDrawCalls; } - virtual uint getNumInstances() const { return _numInstances; } - virtual uint getNumTris() const { return _numTriangles; } + virtual uint32_t getNumDrawCalls() const { return _numDrawCalls; } + virtual uint32_t getNumInstances() const { return _numInstances; } + virtual uint32_t getNumTris() const { return _numTriangles; } inline CommandBuffer * createCommandBuffer(const CommandBufferInfo &info); inline Queue * createQueue(const QueueInfo &info); @@ -86,8 +86,8 @@ public: inline GlobalBarrier * getGlobalBarrier(const GlobalBarrierInfo &info); inline TextureBarrier *getTextureBarrier(const TextureBarrierInfo &info); - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) = 0; - virtual void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) = 0; + virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) = 0; + virtual void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) = 0; inline void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions); inline void flushCommands(const vector &cmdBuffs); @@ -100,7 +100,7 @@ public: inline const String & getDeviceName() const { return _deviceName; } inline const String & getRenderer() const { return _renderer; } inline const String & getVendor() const { return _vendor; } - inline bool hasFeature(Feature feature) const { return _features[static_cast(feature)]; } + inline bool hasFeature(Feature feature) const { return _features[static_cast(feature)]; } inline const BindingMappingInfo &bindingMappingInfo() const { return _bindingMappingInfo; } @@ -133,9 +133,9 @@ protected: virtual PipelineLayout * createPipelineLayout() = 0; virtual PipelineState * createPipelineState() = 0; - virtual Sampler * createSampler(const SamplerInfo &info) = 0; - virtual GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) = 0; - virtual TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) = 0; + virtual Sampler * createSampler(const SamplerInfo &info, uint32_t hash) = 0; + virtual GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) = 0; + virtual TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) = 0; // For context switching between threads virtual void bindContext(bool bound) {} @@ -154,14 +154,14 @@ protected: Queue * _queue{nullptr}; CommandBuffer *_cmdBuff{nullptr}; - uint _numDrawCalls{0U}; - uint _numInstances{0U}; - uint _numTriangles{0U}; + uint32_t _numDrawCalls{0U}; + uint32_t _numInstances{0U}; + uint32_t _numTriangles{0U}; MemoryStatus _memoryStatus; - unordered_map _samplers; - unordered_map _globalBarriers; - unordered_map _textureBarriers; + unordered_map _samplers; + unordered_map _globalBarriers; + unordered_map _textureBarriers; private: vector _swapchains; @@ -261,25 +261,25 @@ PipelineState *Device::createPipelineState(const PipelineStateInfo &info) { } Sampler *Device::getSampler(const SamplerInfo &info) { - uint hash = gfx::Sampler::computeHash(info); + uint32_t hash = gfx::Sampler::computeHash(info); if (!_samplers.count(hash)) { - _samplers[hash] = createSampler(info); + _samplers[hash] = createSampler(info, hash); } return _samplers[hash]; } GlobalBarrier *Device::getGlobalBarrier(const GlobalBarrierInfo &info) { - uint hash = gfx::GlobalBarrier::computeHash(info); + uint32_t hash = gfx::GlobalBarrier::computeHash(info); if (!_globalBarriers.count(hash)) { - _globalBarriers[hash] = createGlobalBarrier(info); + _globalBarriers[hash] = createGlobalBarrier(info, hash); } return _globalBarriers[hash]; } TextureBarrier *Device::getTextureBarrier(const TextureBarrierInfo &info) { - uint hash = gfx::TextureBarrier::computeHash(info); + uint32_t hash = gfx::TextureBarrier::computeHash(info); if (!_textureBarriers.count(hash)) { - _textureBarriers[hash] = createTextureBarrier(info); + _textureBarriers[hash] = createTextureBarrier(info, hash); } return _textureBarriers[hash]; } diff --git a/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp b/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp index 62bfe9201d..f7f752f1d1 100644 --- a/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp @@ -27,6 +27,7 @@ #include "GFXFramebuffer.h" #include "GFXTexture.h" +#include "base/Utils.h" namespace cc { namespace gfx { @@ -37,8 +38,8 @@ Framebuffer::Framebuffer() Framebuffer::~Framebuffer() = default; -uint Framebuffer::computeHash(const FramebufferInfo &info) { - uint seed = static_cast(info.colorTextures.size() * 2 + (info.depthStencilTexture ? 2 : 0)); +uint32_t Framebuffer::computeHash(const FramebufferInfo &info) { + auto seed = utils::toUint(info.colorTextures.size() * 2 + (info.depthStencilTexture ? 2 : 0)); for (const Texture *attachment : info.colorTextures) { seed ^= attachment->getHash() + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attachment->getTypedID() + 0x9e3779b9 + (seed << 6) + (seed >> 2); diff --git a/native/cocos/renderer/gfx-base/GFXFramebuffer.h b/native/cocos/renderer/gfx-base/GFXFramebuffer.h index c2e49491e5..4f984a6b60 100644 --- a/native/cocos/renderer/gfx-base/GFXFramebuffer.h +++ b/native/cocos/renderer/gfx-base/GFXFramebuffer.h @@ -35,7 +35,7 @@ public: Framebuffer(); ~Framebuffer() override; - static uint computeHash(const FramebufferInfo &info); + static uint32_t computeHash(const FramebufferInfo &info); void initialize(const FramebufferInfo &info); void destroy(); diff --git a/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp b/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp index 72dc00d20c..3bd538d3be 100644 --- a/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp +++ b/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp @@ -38,19 +38,19 @@ InputAssembler::InputAssembler() InputAssembler::~InputAssembler() = default; -uint InputAssembler::computeAttributesHash() const { +uint32_t InputAssembler::computeAttributesHash() const { // https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector // 6: Attribute has 6 elements. std::size_t seed = _attributes.size() * 6; for (const auto &attribute : _attributes) { seed ^= std::hash{}(attribute.name) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attribute.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attribute.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.isNormalized + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.stream + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.isInstanced + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= attribute.location + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - return static_cast(seed); + return static_cast(seed); } void InputAssembler::initialize(const InputAssemblerInfo &info) { diff --git a/native/cocos/renderer/gfx-base/GFXInputAssembler.h b/native/cocos/renderer/gfx-base/GFXInputAssembler.h index 71cdca9166..a9a12a63ea 100644 --- a/native/cocos/renderer/gfx-base/GFXInputAssembler.h +++ b/native/cocos/renderer/gfx-base/GFXInputAssembler.h @@ -42,23 +42,23 @@ public: inline const BufferList & getVertexBuffers() const { return _vertexBuffers; } inline Buffer * getIndexBuffer() const { return _indexBuffer; } inline Buffer * getIndirectBuffer() const { return _indirectBuffer; } - inline uint getAttributesHash() const { return _attributesHash; } + inline uint32_t getAttributesHash() const { return _attributesHash; } inline const DrawInfo &getDrawInfo() const { return _drawInfo; } - virtual void setVertexCount(uint32_t count) { _drawInfo.vertexCount = count; } - virtual void setFirstVertex(uint32_t first) { _drawInfo.firstVertex = first; } - virtual void setIndexCount(uint32_t count) { _drawInfo.indexCount = count; } - virtual void setFirstIndex(uint32_t first) { _drawInfo.firstIndex = first; } - virtual void setVertexOffset(int32_t offset) { _drawInfo.vertexOffset = offset; } - virtual void setInstanceCount(uint32_t count) { _drawInfo.instanceCount = count; } - virtual void setFirstInstance(uint32_t first) { _drawInfo.firstInstance = first; } + inline void setVertexCount(uint32_t count) { _drawInfo.vertexCount = count; } + inline void setFirstVertex(uint32_t first) { _drawInfo.firstVertex = first; } + inline void setIndexCount(uint32_t count) { _drawInfo.indexCount = count; } + inline void setFirstIndex(uint32_t first) { _drawInfo.firstIndex = first; } + inline void setVertexOffset(int32_t offset) { _drawInfo.vertexOffset = offset; } + inline void setInstanceCount(uint32_t count) { _drawInfo.instanceCount = count; } + inline void setFirstInstance(uint32_t first) { _drawInfo.firstInstance = first; } protected: virtual void doInit(const InputAssemblerInfo &info) = 0; virtual void doDestroy() = 0; - uint computeAttributesHash() const; + uint32_t computeAttributesHash() const; AttributeList _attributes; uint32_t _attributesHash = 0; diff --git a/native/cocos/renderer/gfx-base/GFXObject.h b/native/cocos/renderer/gfx-base/GFXObject.h index 6405eff00a..95561e7f3d 100644 --- a/native/cocos/renderer/gfx-base/GFXObject.h +++ b/native/cocos/renderer/gfx-base/GFXObject.h @@ -37,20 +37,20 @@ public: ~GFXObject() override = default; inline ObjectType getObjectType() const { return _objectType; } - inline uint getObjectID() const { return _objectID; } - inline uint getTypedID() const { return _typedID; } + inline uint32_t getObjectID() const { return _objectID; } + inline uint32_t getTypedID() const { return _typedID; } protected: template - static uint generateObjectID() noexcept { - static uint generator = 1 << 16; + static uint32_t generateObjectID() noexcept { + static uint32_t generator = 1 << 16; return ++generator; } ObjectType _objectType = ObjectType::UNKNOWN; - uint _objectID = 0U; + uint32_t _objectID = 0U; - uint _typedID = 0U; // inited by sub-classes + uint32_t _typedID = 0U; // inited by sub-classes }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXPipelineState.h b/native/cocos/renderer/gfx-base/GFXPipelineState.h index 4a80a7aeea..1b5997388d 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineState.h +++ b/native/cocos/renderer/gfx-base/GFXPipelineState.h @@ -62,7 +62,7 @@ protected: DepthStencilState _depthStencilState; BlendState _blendState; RenderPass * _renderPass = nullptr; - uint _subpass = 0U; + uint32_t _subpass = 0U; PipelineLayout * _pipelineLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-base/GFXQueue.h b/native/cocos/renderer/gfx-base/GFXQueue.h index fc8f54335a..0e78bd754e 100644 --- a/native/cocos/renderer/gfx-base/GFXQueue.h +++ b/native/cocos/renderer/gfx-base/GFXQueue.h @@ -39,7 +39,7 @@ public: void initialize(const QueueInfo &info); void destroy(); - virtual void submit(CommandBuffer *const *cmdBuffs, uint count) = 0; + virtual void submit(CommandBuffer *const *cmdBuffs, uint32_t count) = 0; inline void submit(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), utils::toUint(cmdBuffs.size())); } diff --git a/native/cocos/renderer/gfx-base/GFXRenderPass.cpp b/native/cocos/renderer/gfx-base/GFXRenderPass.cpp index 28129b8acf..27bcbfc455 100644 --- a/native/cocos/renderer/gfx-base/GFXRenderPass.cpp +++ b/native/cocos/renderer/gfx-base/GFXRenderPass.cpp @@ -38,24 +38,24 @@ RenderPass::RenderPass() RenderPass::~RenderPass() = default; // Based on render pass compatibility -uint RenderPass::computeHash() { +uint32_t RenderPass::computeHash() { // https://stackoverflow.com/questions/20511347/a-good-hash-function-for-a-vector - uint seed = 0; + uint32_t seed = 0; if (!_subpasses.empty()) { for (const SubpassInfo &subPass : _subpasses) { - for (const uint iaIndex : subPass.inputs) { + for (const uint32_t iaIndex : subPass.inputs) { if (iaIndex >= _colorAttachments.size()) break; seed += 2; } - for (const uint caIndex : subPass.colors) { + for (const uint32_t caIndex : subPass.colors) { if (caIndex >= _colorAttachments.size()) break; seed += 2; } - for (const uint raIndex : subPass.resolves) { + for (const uint32_t raIndex : subPass.resolves) { if (raIndex >= _colorAttachments.size()) break; seed += 2; } - for (const uint paIndex : subPass.preserves) { + for (const uint32_t paIndex : subPass.preserves) { if (paIndex >= _colorAttachments.size()) break; seed += 2; } @@ -64,101 +64,101 @@ uint RenderPass::computeHash() { } } for (const SubpassInfo &subpass : _subpasses) { - for (const uint iaIndex : subpass.inputs) { + for (const uint32_t iaIndex : subpass.inputs) { if (iaIndex >= _colorAttachments.size()) break; const ColorAttachment &ia = _colorAttachments[iaIndex]; - seed ^= static_cast(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(ia.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ia.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ia.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - for (const uint caIndex : subpass.colors) { + for (const uint32_t caIndex : subpass.colors) { if (caIndex >= _colorAttachments.size()) break; const ColorAttachment &ca = _colorAttachments[caIndex]; - seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - for (const uint raIndex : subpass.resolves) { + for (const uint32_t raIndex : subpass.resolves) { if (raIndex >= _colorAttachments.size()) break; const ColorAttachment &ca = _colorAttachments[raIndex]; - seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - for (const uint paIndex : subpass.preserves) { + for (const uint32_t paIndex : subpass.preserves) { if (paIndex >= _colorAttachments.size()) break; const ColorAttachment &ca = _colorAttachments[paIndex]; - seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ca.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } if (subpass.depthStencil != INVALID_BINDING) { if (subpass.depthStencil < _colorAttachments.size()) { const auto &ds = _colorAttachments[subpass.depthStencil]; - seed ^= static_cast(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } else { const auto &ds = _depthStencilAttachment; - seed ^= static_cast(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ds.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(ds.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } } } } else { - seed = static_cast(_colorAttachments.size() * 2 + 2); + seed = static_cast(_colorAttachments.size() * 2 + 2); for (const ColorAttachment &colorAttachment : _colorAttachments) { - seed ^= static_cast(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(colorAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(colorAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(colorAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } - seed ^= static_cast(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(_depthStencilAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(_depthStencilAttachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(_depthStencilAttachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; } -uint RenderPass::computeHash(const RenderPassInfo &info) { - static auto computeAttachmentHash = [](const ColorAttachment &attachment, uint &seed) { - seed ^= static_cast(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.loadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.storeOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +uint32_t RenderPass::computeHash(const RenderPassInfo &info) { + static auto computeAttachmentHash = [](const ColorAttachment &attachment, uint32_t &seed) { + seed ^= static_cast(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.loadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.storeOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); for (AccessType type : attachment.beginAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (AccessType type : attachment.endAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } }; - static auto computeDSAttachmentHash = [](const DepthStencilAttachment &attachment, uint &seed) { - seed ^= static_cast(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.depthLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.depthStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.stencilLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(attachment.stencilStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + static auto computeDSAttachmentHash = [](const DepthStencilAttachment &attachment, uint32_t &seed) { + seed ^= static_cast(attachment.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.sampleCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.depthLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.depthStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.stencilLoadOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(attachment.stencilStoreOp) + 0x9e3779b9 + (seed << 6) + (seed >> 2); for (AccessType type : attachment.beginAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (AccessType type : attachment.endAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } }; - uint seed = 0; + uint32_t seed = 0; if (!info.subpasses.empty()) { for (const SubpassInfo &subpass : info.subpasses) { - for (const uint iaIndex : subpass.inputs) { + for (const uint32_t iaIndex : subpass.inputs) { if (iaIndex >= info.colorAttachments.size()) break; const ColorAttachment &ia = info.colorAttachments[iaIndex]; seed += 4 + ia.beginAccesses.size() + ia.endAccesses.size(); } - for (const uint caIndex : subpass.colors) { + for (const uint32_t caIndex : subpass.colors) { if (caIndex >= info.colorAttachments.size()) break; const ColorAttachment &ca = info.colorAttachments[caIndex]; seed += 4 + ca.beginAccesses.size() + ca.endAccesses.size(); } - for (const uint raIndex : subpass.resolves) { + for (const uint32_t raIndex : subpass.resolves) { if (raIndex >= info.colorAttachments.size()) break; const ColorAttachment &ra = info.colorAttachments[raIndex]; seed += 4 + ra.beginAccesses.size() + ra.endAccesses.size(); } - for (const uint paIndex : subpass.preserves) { + for (const uint32_t paIndex : subpass.preserves) { if (paIndex >= info.colorAttachments.size()) break; const ColorAttachment &pa = info.colorAttachments[paIndex]; seed += 4 + pa.beginAccesses.size() + pa.endAccesses.size(); @@ -174,19 +174,19 @@ uint RenderPass::computeHash(const RenderPassInfo &info) { } } for (const SubpassInfo &subpass : info.subpasses) { - for (const uint iaIndex : subpass.inputs) { + for (const uint32_t iaIndex : subpass.inputs) { if (iaIndex >= info.colorAttachments.size()) break; computeAttachmentHash(info.colorAttachments[iaIndex], seed); } - for (const uint caIndex : subpass.colors) { + for (const uint32_t caIndex : subpass.colors) { if (caIndex >= info.colorAttachments.size()) break; computeAttachmentHash(info.colorAttachments[caIndex], seed); } - for (const uint raIndex : subpass.resolves) { + for (const uint32_t raIndex : subpass.resolves) { if (raIndex >= info.colorAttachments.size()) break; computeAttachmentHash(info.colorAttachments[raIndex], seed); } - for (const uint paIndex : subpass.preserves) { + for (const uint32_t paIndex : subpass.preserves) { if (paIndex >= info.colorAttachments.size()) break; computeAttachmentHash(info.colorAttachments[paIndex], seed); } diff --git a/native/cocos/renderer/gfx-base/GFXRenderPass.h b/native/cocos/renderer/gfx-base/GFXRenderPass.h index 112da006a1..25a25df021 100644 --- a/native/cocos/renderer/gfx-base/GFXRenderPass.h +++ b/native/cocos/renderer/gfx-base/GFXRenderPass.h @@ -35,7 +35,7 @@ public: RenderPass(); ~RenderPass() override; - static uint computeHash(const RenderPassInfo &info); + static uint32_t computeHash(const RenderPassInfo &info); void initialize(const RenderPassInfo &info); void destroy(); @@ -44,10 +44,10 @@ public: inline const DepthStencilAttachment &getDepthStencilAttachment() const { return _depthStencilAttachment; } inline const SubpassInfoList & getSubpasses() const { return _subpasses; } inline const SubpassDependencyList & getDependencies() const { return _dependencies; } - inline uint getHash() const { return _hash; } + inline uint32_t getHash() const { return _hash; } protected: - uint computeHash(); + uint32_t computeHash(); virtual void doInit(const RenderPassInfo &info) = 0; virtual void doDestroy() = 0; @@ -56,7 +56,7 @@ protected: DepthStencilAttachment _depthStencilAttachment; SubpassInfoList _subpasses; SubpassDependencyList _dependencies; - uint _hash = 0; + uint32_t _hash = 0; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXSwapchain.cpp b/native/cocos/renderer/gfx-base/GFXSwapchain.cpp index e7812e3696..0e45494ac4 100644 --- a/native/cocos/renderer/gfx-base/GFXSwapchain.cpp +++ b/native/cocos/renderer/gfx-base/GFXSwapchain.cpp @@ -55,7 +55,7 @@ void Swapchain::resize(uint32_t width, uint32_t height, SurfaceTransform transfo // if pre-rotation is enabled, width & height should always be measured in un-oriented space uint32_t newWidth = width; uint32_t newHeight = height; - if (_preRotationEnabled && toNumber(transform) & 1) std::swap(newWidth, newHeight); + if (_preRotationEnabled && (toNumber(transform) & 1)) std::swap(newWidth, newHeight); if (newWidth != _colorTexture->getWidth() || newHeight != _colorTexture->getHeight() || (_preRotationEnabled && transform != _transform)) { diff --git a/native/cocos/renderer/gfx-base/GFXTexture.cpp b/native/cocos/renderer/gfx-base/GFXTexture.cpp index 598eebd8b1..5af7d77ff7 100644 --- a/native/cocos/renderer/gfx-base/GFXTexture.cpp +++ b/native/cocos/renderer/gfx-base/GFXTexture.cpp @@ -37,13 +37,13 @@ Texture::Texture() Texture::~Texture() = default; -uint Texture::computeHash(const TextureInfo &info) { - uint seed = 10; - seed ^= static_cast(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.samples) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +uint32_t Texture::computeHash(const TextureInfo &info) { + uint32_t seed = 10; + seed ^= toNumber(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(info.usage) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(info.flags) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(info.samples) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= (info.width) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= (info.height) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= (info.depth) + 0x9e3779b9 + (seed << 6) + (seed >> 2); @@ -52,11 +52,11 @@ uint Texture::computeHash(const TextureInfo &info) { return seed; } -uint Texture::computeHash(const TextureViewInfo &info) { - uint seed = 7; - seed ^= static_cast(info.texture->getHash()) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= static_cast(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +uint32_t Texture::computeHash(const TextureViewInfo &info) { + uint32_t seed = 7; + seed ^= info.texture->getHash() + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(info.type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(info.format) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= (info.baseLevel) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= (info.levelCount) + 0x9e3779b9 + (seed << 6) + (seed >> 2); seed ^= (info.baseLayer) + 0x9e3779b9 + (seed << 6) + (seed >> 2); @@ -64,8 +64,8 @@ uint Texture::computeHash(const TextureViewInfo &info) { return seed; } -uint Texture::computeHash(const Texture *texture) { - uint hash = texture->isTextureView() ? computeHash(texture->getViewInfo()) : computeHash(texture->getInfo()); +uint32_t Texture::computeHash(const Texture *texture) { + uint32_t hash = texture->isTextureView() ? computeHash(texture->getViewInfo()) : computeHash(texture->getInfo()); if (texture->_swapchain) hash ^= (texture->_swapchain->getObjectID()) + 0x9e3779b9 + (hash << 6) + (hash >> 2); return hash; } @@ -97,9 +97,9 @@ void Texture::initialize(const TextureViewInfo &info) { doInit(info); } -void Texture::resize(uint width, uint height) { +void Texture::resize(uint32_t width, uint32_t height) { if (_info.width != width || _info.height != height) { - uint size = formatSize(_info.format, width, height, _info.depth); + uint32_t size = formatSize(_info.format, width, height, _info.depth); doResize(width, height, size); _info.width = width; @@ -119,7 +119,7 @@ void Texture::destroy() { _size = _hash = 0; } -///////////////////////////// Swapchian Specific ///////////////////////////// +///////////////////////////// Swapchain Specific ///////////////////////////// void Texture::initialize(const SwapchainTextureInfo &info, Texture *out) { out->_info.type = TextureType::TEX2D; diff --git a/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.cpp b/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.cpp index 4400b8d591..ea242cfa20 100644 --- a/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.cpp @@ -26,23 +26,25 @@ #include "base/CoreStd.h" #include "GFXGlobalBarrier.h" +#include "base/Utils.h" namespace cc { namespace gfx { -GlobalBarrier::GlobalBarrier(const GlobalBarrierInfo &info) +GlobalBarrier::GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) : GFXObject(ObjectType::GLOBAL_BARRIER) { _info = info; + _hash = hash; } -uint GlobalBarrier::computeHash(const GlobalBarrierInfo &info) { - uint seed = static_cast(info.prevAccesses.size() + info.nextAccesses.size()); +uint32_t GlobalBarrier::computeHash(const GlobalBarrierInfo &info) { + auto seed = utils::toUint(info.prevAccesses.size() + info.nextAccesses.size()); for (const AccessType type : info.prevAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const AccessType type : info.nextAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } return seed; diff --git a/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.h b/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.h index 7a02a3f5a7..d945642128 100644 --- a/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.h +++ b/native/cocos/renderer/gfx-base/states/GFXGlobalBarrier.h @@ -32,14 +32,16 @@ namespace gfx { class CC_DLL GlobalBarrier : public GFXObject { public: - explicit GlobalBarrier(const GlobalBarrierInfo &info); + GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash); - static uint computeHash(const GlobalBarrierInfo &info); + static uint32_t computeHash(const GlobalBarrierInfo &info); inline const GlobalBarrierInfo &getInfo() const { return _info; } + inline const uint32_t & getHash() const { return _hash; } protected: GlobalBarrierInfo _info; + uint32_t _hash{0U}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/states/GFXSampler.cpp b/native/cocos/renderer/gfx-base/states/GFXSampler.cpp index b81ff46144..6f26b69b5b 100644 --- a/native/cocos/renderer/gfx-base/states/GFXSampler.cpp +++ b/native/cocos/renderer/gfx-base/states/GFXSampler.cpp @@ -30,9 +30,10 @@ namespace cc { namespace gfx { -Sampler::Sampler(const SamplerInfo &info) +Sampler::Sampler(const SamplerInfo &info, uint32_t hash) : GFXObject(ObjectType::SAMPLER) { _info = info; + _hash = hash; } uint32_t Sampler::computeHash(const SamplerInfo &info) { diff --git a/native/cocos/renderer/gfx-base/states/GFXSampler.h b/native/cocos/renderer/gfx-base/states/GFXSampler.h index 8b555b94f6..4a203111cb 100644 --- a/native/cocos/renderer/gfx-base/states/GFXSampler.h +++ b/native/cocos/renderer/gfx-base/states/GFXSampler.h @@ -33,14 +33,16 @@ namespace gfx { class CC_DLL Sampler : public GFXObject { public: - explicit Sampler(const SamplerInfo &info); + Sampler(const SamplerInfo &info, uint32_t hash); static uint32_t computeHash(const SamplerInfo &info); inline const SamplerInfo &getInfo() const { return _info; } + inline const uint32_t & getHash() const { return _hash; } protected: SamplerInfo _info; + uint32_t _hash{0U}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.cpp b/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.cpp index 605d89d1c0..8dcad8ca83 100644 --- a/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.cpp @@ -27,28 +27,30 @@ #include "../GFXQueue.h" #include "GFXTextureBarrier.h" +#include "base/Utils.h" namespace cc { namespace gfx { -TextureBarrier::TextureBarrier(const TextureBarrierInfo &info) +TextureBarrier::TextureBarrier(const TextureBarrierInfo &info, uint32_t hash) : GFXObject(ObjectType::TEXTURE_BARRIER) { _info = info; + _hash = hash; } -uint TextureBarrier::computeHash(const TextureBarrierInfo &info) { - uint seed = static_cast(info.prevAccesses.size() + info.nextAccesses.size() + 3); +uint32_t TextureBarrier::computeHash(const TextureBarrierInfo &info) { + auto seed = utils::toUint(info.prevAccesses.size() + info.nextAccesses.size() + 3); for (const AccessType type : info.prevAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } for (const AccessType type : info.nextAccesses) { - seed ^= static_cast(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= toNumber(type) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } seed ^= info.discardContents + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (info.srcQueue ? static_cast(info.srcQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - seed ^= (info.dstQueue ? static_cast(info.dstQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.srcQueue ? toNumber(info.srcQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2); + seed ^= (info.dstQueue ? toNumber(info.dstQueue->getType()) : 0U) + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } diff --git a/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.h b/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.h index 03905b565c..e7ae287aca 100644 --- a/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.h +++ b/native/cocos/renderer/gfx-base/states/GFXTextureBarrier.h @@ -32,14 +32,16 @@ namespace gfx { class CC_DLL TextureBarrier : public GFXObject { public: - explicit TextureBarrier(const TextureBarrierInfo &info); + TextureBarrier(const TextureBarrierInfo &info, uint32_t hash); - static uint computeHash(const TextureBarrierInfo &info); + static uint32_t computeHash(const TextureBarrierInfo &info); inline const TextureBarrierInfo &getInfo() const { return _info; } + inline const uint32_t & getHash() const { return _hash; } protected: TextureBarrierInfo _info; + uint32_t _hash{0U}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp b/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp index 867eedfb96..5e00116335 100644 --- a/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp @@ -34,13 +34,13 @@ void EmptyBuffer::doInit(const BufferInfo &info) { void EmptyBuffer::doInit(const BufferViewInfo &info) { } -void EmptyBuffer::doResize(uint size, uint count) { +void EmptyBuffer::doResize(uint32_t size, uint32_t count) { } void EmptyBuffer::doDestroy() { } -void EmptyBuffer::update(const void *buffer, uint size) { +void EmptyBuffer::update(const void *buffer, uint32_t size) { } } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyBuffer.h b/native/cocos/renderer/gfx-empty/EmptyBuffer.h index 39916c2f1c..1b505b1b3c 100644 --- a/native/cocos/renderer/gfx-empty/EmptyBuffer.h +++ b/native/cocos/renderer/gfx-empty/EmptyBuffer.h @@ -32,12 +32,12 @@ namespace gfx { class CC_DLL EmptyBuffer final : public Buffer { public: - void update(const void *buffer, uint size) override; + void update(const void *buffer, uint32_t size) override; protected: void doInit(const BufferInfo &info) override; void doInit(const BufferViewInfo &info) override; - void doResize(uint size, uint count) override; + void doResize(uint32_t size, uint32_t count) override; void doDestroy() override; }; diff --git a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp index 5a7c7a6e2b..5658bb0819 100644 --- a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp @@ -34,13 +34,13 @@ void EmptyCommandBuffer::doInit(const CommandBufferInfo &info) { void EmptyCommandBuffer::doDestroy() { } -void EmptyCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void EmptyCommandBuffer::begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) { } void EmptyCommandBuffer::end() { } -void EmptyCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { +void EmptyCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) { } void EmptyCommandBuffer::endRenderPass() { @@ -52,7 +52,7 @@ void EmptyCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) void EmptyCommandBuffer::bindPipelineState(PipelineState *pso) { } -void EmptyCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { +void EmptyCommandBuffer::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) { } void EmptyCommandBuffer::bindInputAssembler(InputAssembler *ia) { @@ -76,10 +76,10 @@ void EmptyCommandBuffer::setBlendConstants(const Color &constants) { void EmptyCommandBuffer::setDepthBound(float minBounds, float maxBounds) { } -void EmptyCommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { +void EmptyCommandBuffer::setStencilWriteMask(StencilFace face, uint32_t mask) { } -void EmptyCommandBuffer::setStencilCompareMask(StencilFace face, uint ref, uint mask) { +void EmptyCommandBuffer::setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) { } void EmptyCommandBuffer::nextSubpass() { @@ -88,19 +88,19 @@ void EmptyCommandBuffer::nextSubpass() { void EmptyCommandBuffer::draw(const DrawInfo &info) { } -void EmptyCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +void EmptyCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint32_t size) { } -void EmptyCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void EmptyCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { } -void EmptyCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void EmptyCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { } void EmptyCommandBuffer::dispatch(const DispatchInfo &info) { } -void EmptyCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) { +void EmptyCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) { } } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h index c0682b1ac7..a045386c26 100644 --- a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h +++ b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h @@ -32,12 +32,12 @@ namespace gfx { class CC_DLL EmptyCommandBuffer final : public CommandBuffer { public: - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void bindPipelineState(PipelineState *pso) override; - void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override; void bindInputAssembler(InputAssembler *ia) override; void setViewport(const Viewport &vp) override; void setScissor(const Rect &rect) override; @@ -45,16 +45,16 @@ public: void setDepthBias(float constant, float clamp, float slope) override; void setBlendConstants(const Color &constants) override; void setDepthBound(float minBounds, float maxBounds) override; - void setStencilWriteMask(StencilFace face, uint mask) override; - void setStencilCompareMask(StencilFace face, uint ref, uint mask) override; + void setStencilWriteMask(StencilFace face, uint32_t mask) override; + void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override; - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override; protected: void doInit(const CommandBufferInfo &info) override; diff --git a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp index 45f4e243c5..ef51116b69 100644 --- a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp @@ -136,22 +136,22 @@ PipelineState *EmptyDevice::createPipelineState() { return CC_NEW(EmptyPipelineState()); } -Sampler *EmptyDevice::createSampler(const SamplerInfo &info) { - return CC_NEW(Sampler(info)); +Sampler *EmptyDevice::createSampler(const SamplerInfo &info, uint32_t hash) { + return CC_NEW(Sampler(info, hash)); } -GlobalBarrier *EmptyDevice::createGlobalBarrier(const GlobalBarrierInfo &info) { - return CC_NEW(GlobalBarrier(info)); +GlobalBarrier *EmptyDevice::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) { + return CC_NEW(GlobalBarrier(info, hash)); } -TextureBarrier *EmptyDevice::createTextureBarrier(const TextureBarrierInfo &info) { - return CC_NEW(TextureBarrier(info)); +TextureBarrier *EmptyDevice::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) { + return CC_NEW(TextureBarrier(info, hash)); } -void EmptyDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { +void EmptyDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { } -void EmptyDevice::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) { +void EmptyDevice::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) { } } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyDevice.h b/native/cocos/renderer/gfx-empty/EmptyDevice.h index c8004bb0d8..44dc1f4bd6 100644 --- a/native/cocos/renderer/gfx-empty/EmptyDevice.h +++ b/native/cocos/renderer/gfx-empty/EmptyDevice.h @@ -72,12 +72,12 @@ public: PipelineLayout * createPipelineLayout() override; PipelineState * createPipelineState() override; - Sampler * createSampler(const SamplerInfo &info) override; - GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) override; + Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override; + GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override; + void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override; protected: static EmptyDevice *instance; diff --git a/native/cocos/renderer/gfx-empty/EmptyQueue.cpp b/native/cocos/renderer/gfx-empty/EmptyQueue.cpp index fc282fd457..2a0a0c9ed4 100644 --- a/native/cocos/renderer/gfx-empty/EmptyQueue.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyQueue.cpp @@ -34,7 +34,7 @@ void EmptyQueue::doInit(const QueueInfo &info) { void EmptyQueue::doDestroy() { } -void EmptyQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { +void EmptyQueue::submit(CommandBuffer *const *cmdBuffs, uint32_t count) { } } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyQueue.h b/native/cocos/renderer/gfx-empty/EmptyQueue.h index b74d22b06d..9f69f127e9 100644 --- a/native/cocos/renderer/gfx-empty/EmptyQueue.h +++ b/native/cocos/renderer/gfx-empty/EmptyQueue.h @@ -34,7 +34,7 @@ class CC_DLL EmptyQueue final : public Queue { public: using Queue::submit; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override; protected: void doInit(const QueueInfo &info) override; diff --git a/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp b/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp index d7a0ea1aca..70c6395d20 100644 --- a/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp +++ b/native/cocos/renderer/gfx-empty/EmptySwapchain.cpp @@ -50,7 +50,7 @@ void EmptySwapchain::doDestroy() { CC_SAFE_DESTROY(_colorTexture); } -void EmptySwapchain::doResize(uint width, uint height, SurfaceTransform transform) { +void EmptySwapchain::doResize(uint32_t width, uint32_t height, SurfaceTransform transform) { } void EmptySwapchain::doDestroySurface() { diff --git a/native/cocos/renderer/gfx-empty/EmptySwapchain.h b/native/cocos/renderer/gfx-empty/EmptySwapchain.h index 3bf6defa3b..456e201842 100644 --- a/native/cocos/renderer/gfx-empty/EmptySwapchain.h +++ b/native/cocos/renderer/gfx-empty/EmptySwapchain.h @@ -35,7 +35,7 @@ public: protected: void doInit(const SwapchainInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, SurfaceTransform transform) override; + void doResize(uint32_t width, uint32_t height, SurfaceTransform transform) override; void doDestroySurface() override; void doCreateSurface(void *windowHandle) override; }; diff --git a/native/cocos/renderer/gfx-empty/EmptyTexture.cpp b/native/cocos/renderer/gfx-empty/EmptyTexture.cpp index 42c7878545..a10d59b0c2 100644 --- a/native/cocos/renderer/gfx-empty/EmptyTexture.cpp +++ b/native/cocos/renderer/gfx-empty/EmptyTexture.cpp @@ -41,7 +41,7 @@ void EmptyTexture::doInit(const SwapchainTextureInfo &info) { void EmptyTexture::doDestroy() { } -void EmptyTexture::doResize(uint width, uint height, uint size) { +void EmptyTexture::doResize(uint32_t width, uint32_t height, uint32_t size) { } } // namespace gfx diff --git a/native/cocos/renderer/gfx-empty/EmptyTexture.h b/native/cocos/renderer/gfx-empty/EmptyTexture.h index 81533ad7fb..d762a41371 100644 --- a/native/cocos/renderer/gfx-empty/EmptyTexture.h +++ b/native/cocos/renderer/gfx-empty/EmptyTexture.h @@ -38,7 +38,7 @@ protected: void doInit(const TextureViewInfo &info) override; void doInit(const SwapchainTextureInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, uint size) override; + void doResize(uint32_t width, uint32_t height, uint32_t size) override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h index 5effabf533..435f2f88a4 100644 --- a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h +++ b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h @@ -47,13 +47,6 @@ enum class FBFSupportLevel { NON_COHERENT_QCOM, }; -// Pixel Local Storage -enum class PLSSupportLevel { - NONE, - LEVEL1, - LEVEL2, -}; - enum class GLESCmdType : uint8_t { BEGIN_RENDER_PASS, END_RENDER_PASS, @@ -70,7 +63,7 @@ enum class GLESCmdType : uint8_t { class GLESCmd : public Object { public: GLESCmdType type; - uint refCount = 0; + uint32_t refCount = 0; explicit GLESCmd(GLESCmdType type) : type(type) {} ~GLESCmd() override = default; @@ -87,18 +80,18 @@ public: _frees = new T *[INITIAL_CAPACITY]; _count = INITIAL_CAPACITY; _freeIdx = INITIAL_CAPACITY - 1; - for (uint i = 0; i < _count; ++i) { + for (uint32_t i = 0; i < _count; ++i) { _frees[i] = CC_NEW(T); } } ~CommandPool() { - for (uint i = 0; i < _count; ++i) { + for (uint32_t i = 0; i < _count; ++i) { CC_DELETE(_frees[i]); } delete[](_frees); - for (uint i = 0; i < _freeCmds.size(); ++i) { + for (uint32_t i = 0; i < _freeCmds.size(); ++i) { CC_DELETE(_freeCmds[i]); } _freeCmds.clear(); @@ -107,13 +100,13 @@ public: T *alloc() { if (_freeIdx < 0) { T **oldFrees = _frees; - uint size = _count * 2; + uint32_t size = _count * 2; _frees = new T *[size]; - uint increase = size - _count; - for (uint i = 0; i < increase; ++i) { + uint32_t increase = size - _count; + for (uint32_t i = 0; i < increase; ++i) { _frees[i] = CC_NEW(T); } - for (uint i = increase, j = 0; i < size; ++i, ++j) { + for (uint32_t i = increase, j = 0; i < size; ++i, ++j) { _frees[i] = oldFrees[j]; } delete[](oldFrees); @@ -135,7 +128,7 @@ public: } void freeCmds(CachedArray &cmds) { - for (uint i = 0; i < cmds.size(); ++i) { + for (uint32_t i = 0; i < cmds.size(); ++i) { if (--cmds[i]->refCount == 0) { _freeCmds.push(cmds[i]); } @@ -144,7 +137,7 @@ public: } void release() { - for (uint i = 0; i < _freeCmds.size(); ++i) { + for (uint32_t i = 0; i < _freeCmds.size(); ++i) { T *cmd = _freeCmds[i]; cmd->clear(); _frees[++_freeIdx] = cmd; @@ -154,7 +147,7 @@ public: protected: T **_frees = nullptr; - uint _count = 0; + uint32_t _count = 0; CachedArray _freeCmds; int _freeIdx = 0; }; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp index 4d6cb72b07..b6d6d5a657 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp @@ -75,7 +75,7 @@ void GLES2Buffer::doDestroy() { CC_SAFE_DELETE(_gpuBufferView); } -void GLES2Buffer::doResize(uint size, uint count) { +void GLES2Buffer::doResize(uint32_t size, uint32_t count) { GLES2Device::getInstance()->getMemoryStatus().bufferSize -= _size; _gpuBuffer->size = size; _gpuBuffer->count = count; @@ -83,7 +83,7 @@ void GLES2Buffer::doResize(uint size, uint count) { GLES2Device::getInstance()->getMemoryStatus().bufferSize += size; } -void GLES2Buffer::update(const void *buffer, uint size) { +void GLES2Buffer::update(const void *buffer, uint32_t size) { cmdFuncGLES2UpdateBuffer(GLES2Device::getInstance(), _gpuBuffer, buffer, 0U, size); } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Buffer.h b/native/cocos/renderer/gfx-gles2/GLES2Buffer.h index 7bbed53103..04a8f621ef 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Buffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Buffer.h @@ -39,16 +39,16 @@ public: GLES2Buffer(); ~GLES2Buffer() override; - void update(const void *buffer, uint size) override; + void update(const void *buffer, uint32_t size) override; - inline GLES2GPUBuffer *gpuBuffer() const { return _gpuBuffer; } + inline GLES2GPUBuffer * gpuBuffer() const { return _gpuBuffer; } inline GLES2GPUBufferView *gpuBufferView() const { return _gpuBufferView; } protected: void doInit(const BufferInfo &info) override; void doInit(const BufferViewInfo &info) override; void doDestroy() override; - void doResize(uint size, uint count) override; + void doResize(uint32_t size, uint32_t count) override; GLES2GPUBuffer * _gpuBuffer = nullptr; GLES2GPUBufferView *_gpuBufferView = nullptr; diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp index c45a74efb6..f375539b97 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp @@ -83,7 +83,7 @@ void GLES2CommandBuffer::doDestroy() { CC_SAFE_DELETE(_cmdAllocator); } -void GLES2CommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { +void GLES2CommandBuffer::begin(RenderPass * /*renderPass*/, uint32_t /*subpass*/, Framebuffer * /*frameBuffer*/) { _cmdAllocator->clearCmds(_curCmdPackage); _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; @@ -108,7 +108,7 @@ void GLES2CommandBuffer::end() { } } -void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { +void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const * /*secondaryCBs*/, uint32_t /*secondaryCBCount*/) { _curSubpassIdx = 0U; GLES2CmdBeginRenderPass *cmd = _cmdAllocator->beginRenderPassCmdPool.alloc(); @@ -123,7 +123,7 @@ void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb _curCmdPackage->beginRenderPassCmds.push(cmd); _curCmdPackage->cmds.push(GLESCmdType::BEGIN_RENDER_PASS); _curDynamicStates.viewport = {renderArea.x, renderArea.y, renderArea.width, renderArea.height}; - _curDynamicStates.scissor = renderArea; + _curDynamicStates.scissor = renderArea; } void GLES2CommandBuffer::endRenderPass() { @@ -146,7 +146,7 @@ void GLES2CommandBuffer::bindPipelineState(PipelineState *pso) { } } -void GLES2CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { +void GLES2CommandBuffer::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) { CCASSERT(_curGPUDescriptorSets.size() > set, "Invalid set index"); GLES2GPUDescriptorSet *gpuDescriptorSet = static_cast(descriptorSet)->gpuDescriptorSet(); @@ -227,7 +227,7 @@ void GLES2CommandBuffer::setDepthBound(float minBounds, float maxBounds) { } } -void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { +void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint32_t mask) { auto update = [&](DynamicStencilStates &stencilState) { if (stencilState.writeMask != mask) { stencilState.writeMask = mask; @@ -238,7 +238,7 @@ void GLES2CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { if (hasFlag(face, StencilFace::BACK)) update(_curDynamicStates.stencilStatesBack); } -void GLES2CommandBuffer::setStencilCompareMask(StencilFace face, uint ref, uint mask) { +void GLES2CommandBuffer::setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) { auto update = [&](DynamicStencilStates &stencilState) { if ((stencilState.reference != ref) || (stencilState.compareMask != mask)) { @@ -263,7 +263,7 @@ void GLES2CommandBuffer::draw(const DrawInfo &info) { ++_numDrawCalls; _numInstances += info.instanceCount; - uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; + uint32_t indexCount = info.indexCount ? info.indexCount : info.vertexCount; if (_curGPUPipelineState) { switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { @@ -281,7 +281,7 @@ void GLES2CommandBuffer::draw(const DrawInfo &info) { } } -void GLES2CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +void GLES2CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint32_t size) { GLES2GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { GLES2CmdUpdateBuffer *cmd = _cmdAllocator->updateBufferCmdPool.alloc(); @@ -294,7 +294,7 @@ void GLES2CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) } } -void GLES2CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void GLES2CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { GLES2GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { GLES2CmdCopyBufferToTexture *cmd = _cmdAllocator->copyBufferToTextureCmdPool.alloc(); @@ -308,7 +308,7 @@ void GLES2CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Tex } } -void GLES2CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void GLES2CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { GLES2CmdBlitTexture *cmd = _cmdAllocator->blitTextureCmdPool.alloc(); if (srcTexture) cmd->gpuTextureSrc = static_cast(srcTexture)->gpuTexture(); if (dstTexture) cmd->gpuTextureDst = static_cast(dstTexture)->gpuTexture(); @@ -323,36 +323,36 @@ void GLES2CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, c void GLES2CommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { CCASSERT(false, "Command 'execute' must be recorded in primary command buffers."); - for (uint i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { auto * cmdBuff = static_cast(cmdBuffs[i]); GLES2CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - for (uint j = 0; j < cmdPackage->beginRenderPassCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->beginRenderPassCmds.size(); ++j) { GLES2CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[j]; ++cmd->refCount; _curCmdPackage->beginRenderPassCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->bindStatesCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->bindStatesCmds.size(); ++j) { GLES2CmdBindStates *cmd = cmdPackage->bindStatesCmds[j]; ++cmd->refCount; _curCmdPackage->bindStatesCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->drawCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->drawCmds.size(); ++j) { GLES2CmdDraw *cmd = cmdPackage->drawCmds[j]; ++cmd->refCount; _curCmdPackage->drawCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->updateBufferCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->updateBufferCmds.size(); ++j) { GLES2CmdUpdateBuffer *cmd = cmdPackage->updateBufferCmds[j]; ++cmd->refCount; _curCmdPackage->updateBufferCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->copyBufferToTextureCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->copyBufferToTextureCmds.size(); ++j) { GLES2CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[j]; ++cmd->refCount; _curCmdPackage->copyBufferToTextureCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->blitTextureCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->blitTextureCmds.size(); ++j) { GLES2CmdBlitTexture *cmd = cmdPackage->blitTextureCmds[j]; ++cmd->refCount; _curCmdPackage->blitTextureCmds.push(cmd); @@ -381,13 +381,13 @@ void GLES2CommandBuffer::bindStates() { cmd->gpuDescriptorSets = _curGPUDescriptorSets; if (_curGPUPipelineState) { - vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; + vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; cmd->dynamicOffsets.resize(_curGPUPipelineState->gpuPipelineLayout->dynamicOffsetCount); for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); - if (count) memcpy(&cmd->dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); + if (count) memcpy(&cmd->dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint32_t)); } } cmd->dynamicStates = _curDynamicStates; diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h index 3fb68bf9f8..c3871b9718 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h @@ -44,12 +44,12 @@ public: friend class GLES2Queue; - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void bindPipelineState(PipelineState *pso) override; - void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override; void bindInputAssembler(InputAssembler *ia) override; void setViewport(const Viewport &vp) override; void setScissor(const Rect &rect) override; @@ -57,16 +57,16 @@ public: void setDepthBias(float constant, float clamp, float slope) override; void setBlendConstants(const Color &constants) override; void setDepthBound(float minBounds, float maxBounds) override; - void setStencilWriteMask(StencilFace face, uint mask) override; - void setStencilCompareMask(StencilFace face, uint ref, uint mask) override; + void setStencilWriteMask(StencilFace face, uint32_t mask) override; + void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override {} - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override {} + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override {} protected: void doInit(const CommandBufferInfo &info) override; @@ -78,10 +78,10 @@ protected: GLES2CmdPackage * _curCmdPackage = nullptr; queue _pendingPackages, _freePackages; - uint _curSubpassIdx = 0U; + uint32_t _curSubpassIdx = 0U; GLES2GPUPipelineState * _curGPUPipelineState = nullptr; vector _curGPUDescriptorSets; - vector> _curDynamicOffsets; + vector> _curDynamicOffsets; GLES2GPUInputAssembler * _curGPUInputAssember = nullptr; DynamicStates _curDynamicStates; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp index d7026e2ecc..e08660c215 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.cpp @@ -331,7 +331,7 @@ GLenum formatToGLType(Format format) { } } -uint glTypeSize(GLenum glType) { +uint32_t glTypeSize(GLenum glType) { switch (glType) { case GL_BOOL: return 4; case GL_BOOL_VEC2: return 8; @@ -363,7 +363,7 @@ uint glTypeSize(GLenum glType) { } } -uint glComponentCount(GLenum glType) { +uint32_t glComponentCount(GLenum glType) { switch (glType) { case GL_FLOAT_MAT2: return 2; case GL_FLOAT_MAT3: return 3; @@ -622,17 +622,17 @@ void cmdFuncGLES2CreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_2D, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - uint w = gpuTexture->width; - uint h = gpuTexture->height; + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } else { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -651,21 +651,21 @@ void cmdFuncGLES2CreateTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) glTexture = gpuTexture->glTexture; } if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { - for (uint f = 0; f < 6; ++f) { - uint w = gpuTexture->width; - uint h = gpuTexture->height; - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t f = 0; f < 6; ++f) { + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } } else { - for (uint f = 0; f < 6; ++f) { - uint w = gpuTexture->width; - uint h = gpuTexture->height; - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t f = 0; f < 6; ++f) { + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -740,17 +740,17 @@ void cmdFuncGLES2ResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_2D, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - uint w = gpuTexture->width; - uint h = gpuTexture->height; + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } else { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -768,21 +768,21 @@ void cmdFuncGLES2ResizeTexture(GLES2Device *device, GLES2GPUTexture *gpuTexture) glTexture = gpuTexture->glTexture; } if (!GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed) { - for (uint f = 0; f < 6; ++f) { - uint w = gpuTexture->width; - uint h = gpuTexture->height; - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t f = 0; f < 6; ++f) { + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } } else { - for (uint f = 0; f < 6; ++f) { - uint w = gpuTexture->width; - uint h = gpuTexture->height; - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t f = 0; f < 6; ++f) { + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -995,7 +995,7 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } // if - // fallback subpassInputs into samplerTextures if not using FBF or PLS + // fallback subpassInputs into samplerTextures if not using FBF if (device->constantRegistry()->mFBF == FBFSupportLevel::NONE) { for (const auto &subpassInput : gpuShader->subpassInputs) { auto &samplerTexture = gpuShader->samplerTextures.emplace_back(); @@ -1045,7 +1045,7 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { (glType == GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY_OES); if (!isSampler) { for (auto &glBlock : gpuShader->glBlocks) { - for (uint j = 0; j < glBlock.glUniforms.size(); ++j) { + for (uint32_t j = 0; j < glBlock.glUniforms.size(); ++j) { auto &glUniform = glBlock.glUniforms[j]; if (glUniform.name == name) { glUniform.glLoc = glGetUniformLocation(gpuShader->glProgram, glName); @@ -1070,10 +1070,10 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { gpuUniform.offset = gpuBlock.size; gpuBlock.size += gpuUniform.size; } - for (uint i = 0; i < gpuBlock.glActiveUniforms.size(); ++i) { - auto &activeUniform = gpuBlock.glActiveUniforms[i]; - uint index = gpuBlock.activeUniformIndices[i]; - activeUniform.offset = gpuBlock.glUniforms[index].offset; + for (uint32_t i = 0; i < gpuBlock.glActiveUniforms.size(); ++i) { + auto & activeUniform = gpuBlock.glActiveUniforms[i]; + uint32_t index = gpuBlock.activeUniformIndices[i]; + activeUniform.offset = gpuBlock.glUniforms[index].offset; } } @@ -1081,20 +1081,20 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { vector glActiveSamplerTextures; vector glActiveSamplerLocations; const BindingMappingInfo & bindingMappingInfo = device->bindingMappingInfo(); - unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; + unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; // sampler bindings in the flexible set comes strictly after buffer bindings // so we need to subtract the buffer count for these samplers - uint flexibleSetBaseOffset = 0U; + uint32_t flexibleSetBaseOffset = 0U; for (auto &block : gpuShader->blocks) { if (block.set == bindingMappingInfo.flexibleSet) { flexibleSetBaseOffset++; } } - uint arrayOffset = 0U; + uint32_t arrayOffset = 0U; - for (uint i = 0U; i < gpuShader->samplerTextures.size(); i++) { + for (uint32_t i = 0U; i < gpuShader->samplerTextures.size(); i++) { const UniformSamplerTexture &samplerTexture = gpuShader->samplerTextures[i]; GLint glLoc = glGetUniformLocation(gpuShader->glProgram, samplerTexture.name.c_str()); if (glLoc >= 0) { @@ -1102,7 +1102,7 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { glActiveSamplerLocations.push_back(glLoc); } if (!texUnitCacheMap.count(samplerTexture.name)) { - uint binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; + uint32_t binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; if (samplerTexture.set == bindingMappingInfo.flexibleSet) binding -= flexibleSetBaseOffset; texUnitCacheMap[samplerTexture.name] = binding % device->getCapabilities().maxTextureUnits; arrayOffset += samplerTexture.count - 1; @@ -1112,13 +1112,13 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { if (!glActiveSamplerTextures.empty()) { vector usedTexUnits(device->getCapabilities().maxTextureUnits, false); // try to reuse existing mappings first - for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { + for (uint32_t i = 0U; i < glActiveSamplerTextures.size(); i++) { GLES2GPUUniformSamplerTexture &glSamplerTexture = glActiveSamplerTextures[i]; if (texUnitCacheMap.count(glSamplerTexture.name)) { - uint cachedUnit = texUnitCacheMap[glSamplerTexture.name]; + uint32_t cachedUnit = texUnitCacheMap[glSamplerTexture.name]; glSamplerTexture.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U; t < glSamplerTexture.count; t++) { + for (uint32_t t = 0U; t < glSamplerTexture.count; t++) { while (usedTexUnits[cachedUnit]) { // the shader already compiles so we should be safe to do this here cachedUnit = (cachedUnit + 1) % device->getCapabilities().maxTextureUnits; } @@ -1128,13 +1128,13 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } // fill in the rest sequencially - uint unitIdx = 0U; - for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { + uint32_t unitIdx = 0U; + for (uint32_t i = 0U; i < glActiveSamplerTextures.size(); i++) { GLES2GPUUniformSamplerTexture &glSamplerTexture = glActiveSamplerTextures[i]; if (glSamplerTexture.glLoc < 0) { glSamplerTexture.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U; t < glSamplerTexture.count; t++) { + for (uint32_t t = 0U; t < glSamplerTexture.count; t++) { while (usedTexUnits[unitIdx]) { unitIdx = (unitIdx + 1) % device->getCapabilities().maxTextureUnits; } @@ -1161,7 +1161,7 @@ void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } // strip out the inactive ones - for (uint i = 0U; i < gpuShader->glBlocks.size();) { + for (uint32_t i = 0U; i < gpuShader->glBlocks.size();) { if (!gpuShader->glBlocks[i].glActiveUniforms.empty()) { i++; } else { @@ -1185,6 +1185,50 @@ void cmdFuncGLES2DestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader) { } } +void cmdFuncGLES2CreateRenderPass(GLES2Device * /*device*/, GLES2GPURenderPass *gpuRenderPass) { + // calculate the life cycle of each attachments + auto updateLifeCycle = [](GLES2GPURenderPass::AttachmentStatistics &statistics, uint32_t index) { + if (statistics.loadSubpass == SUBPASS_EXTERNAL) statistics.loadSubpass = index; + statistics.storeSubpass = index; + }; + auto calculateLifeCycle = [&](GLES2GPURenderPass::AttachmentStatistics &statistics, uint32_t targetAttachment) { + for (size_t j = 0U; j < gpuRenderPass->subpasses.size(); ++j) { + auto &subpass = gpuRenderPass->subpasses[j]; + for (size_t k = 0U; k < subpass.colors.size(); ++k) { + if (subpass.colors[k] == targetAttachment) { + updateLifeCycle(statistics, j); + } + if (!subpass.resolves.empty() && subpass.resolves[k] == targetAttachment) { + updateLifeCycle(statistics, j); + } + } + for (unsigned int input : subpass.inputs) { + if (input == targetAttachment) { + updateLifeCycle(statistics, j); + } + } + if (subpass.depthStencil == targetAttachment) { + updateLifeCycle(statistics, j); + } + if (subpass.depthStencilResolve == targetAttachment) { + updateLifeCycle(statistics, j); + } + } + }; + + bool hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN; + gpuRenderPass->statistics.resize(gpuRenderPass->colorAttachments.size() + hasDepth); + for (size_t i = 0U; i < gpuRenderPass->statistics.size(); ++i) { + calculateLifeCycle(gpuRenderPass->statistics[i], i); + CC_ASSERT(gpuRenderPass->statistics[i].loadSubpass != SUBPASS_EXTERNAL && + gpuRenderPass->statistics[i].storeSubpass != SUBPASS_EXTERNAL); + } +} + +void cmdFuncGLES2DestroyRenderPass(GLES2Device * /*device*/, GLES2GPURenderPass *gpuRenderPass) { + gpuRenderPass->statistics.clear(); +} + void cmdFuncGLES2CreateInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler) { if (gpuInputAssembler->gpuIndexBuffer) { switch (gpuInputAssembler->gpuIndexBuffer->stride) { @@ -1197,7 +1241,7 @@ void cmdFuncGLES2CreateInputAssembler(GLES2Device *device, GLES2GPUInputAssemble } } - vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0U); + vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0U); gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size()); for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) { @@ -1237,9 +1281,9 @@ void cmdFuncGLES2DestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembl } static GLuint doCreateFramebuffer(GLES2Device * device, - const vector &attachments, const uint *colors, size_t colorCount, + const vector &attachments, const uint32_t *colors, size_t colorCount, const GLES2GPUTexture *depthStencil, - const uint * resolves = nullptr, + const uint32_t * resolves = nullptr, const GLES2GPUTexture *depthStencilResolve = nullptr, GLbitfield * resolveMask = nullptr) { static vector drawBuffers; @@ -1343,9 +1387,9 @@ static GLES2GPUSwapchain *getSwapchainIfExists(const vector & return swapchain; } -static void doCreateFramebufferInstance(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO, const vector &colors, - uint depthStencil, GLES2GPUFramebuffer::Framebuffer *outFBO, - const uint *resolves = nullptr, uint depthStencilResolve = INVALID_BINDING) { +static void doCreateFramebufferInstance(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO, const vector &colors, + uint32_t depthStencil, GLES2GPUFramebuffer::Framebuffer *outFBO, + const uint32_t *resolves = nullptr, uint32_t depthStencilResolve = INVALID_BINDING) { GLES2GPUSwapchain *swapchain{getSwapchainIfExists(gpuFBO->gpuColorTextures, colors.data(), colors.size())}; if (!swapchain) { @@ -1384,14 +1428,27 @@ void cmdFuncGLES2CreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpu } if (gpuFBO->usesFBF) { + for (auto &subpass : gpuFBO->gpuRenderPass->subpasses) { + if (subpass.inputs.size() == 4) { + gpuFBO->uberOnChipOutput = subpass.inputs.back(); + gpuFBO->uberFinalOutput = subpass.colors.back(); + break; + } + } + gpuFBO->uberColorAttachmentIndices.clear(); - for (uint i = 0U; i < gpuFBO->gpuColorTextures.size(); ++i) { + bool hasDepth{gpuFBO->gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN}; + gpuFBO->uberDepthStencil = hasDepth ? gpuFBO->gpuColorTextures.size() : INVALID_BINDING; + for (uint32_t i = 0U; i < gpuFBO->gpuColorTextures.size(); ++i) { + if (i == gpuFBO->uberFinalOutput) continue; const auto *gpuTexture = gpuFBO->gpuColorTextures[i]; - if (!gpuTexture || gpuTexture->memoryless) continue; - if (GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].hasDepth) continue; + if (GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].hasDepth) { + gpuFBO->uberDepthStencil = i; + continue; + } gpuFBO->uberColorAttachmentIndices.push_back(i); } - doCreateFramebufferInstance(device, gpuFBO, gpuFBO->uberColorAttachmentIndices, utils::toUint(gpuFBO->gpuColorTextures.size()), &gpuFBO->uberInstance); + doCreateFramebufferInstance(device, gpuFBO, gpuFBO->uberColorAttachmentIndices, gpuFBO->uberDepthStencil, &gpuFBO->uberInstance); } else { for (const auto &subpass : gpuFBO->gpuRenderPass->subpasses) { doCreateFramebufferInstance(device, gpuFBO, subpass.colors, subpass.depthStencil, &gpuFBO->instances.emplace_back(), @@ -1428,9 +1485,8 @@ void cmdFuncGLES2DestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gp gpuFBO->uberInstance.resolveFramebuffer.destroy(cache, framebufferCacheMap); } -void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFramebuffer, - const Rect *renderArea, const Color *clearColors, float clearDepth, uint clearStencil) { - static uint attachmentLoadOpRecord = 0U; +void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint32_t subpassIdx, GLES2GPURenderPass *gpuRenderPass, GLES2GPUFramebuffer *gpuFramebuffer, + const Rect *renderArea, const Color *clearColors, float clearDepth, uint32_t clearStencil) { static vector invalidAttachments; GLES2GPUStateCache *cache = device->stateCache(); @@ -1450,7 +1506,6 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPUR gfxStateCache.clearColors.assign(clearColors, clearColors + gpuRenderPass->colorAttachments.size()); gfxStateCache.clearDepth = clearDepth; gfxStateCache.clearStencil = clearStencil; - attachmentLoadOpRecord = 0U; } if (gpuFramebuffer && gpuRenderPass) { @@ -1464,33 +1519,37 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPUR cache->glFramebuffer = glFramebuffer; } - if (cache->viewport.left != renderArea->x || - cache->viewport.top != renderArea->y || - cache->viewport.width != renderArea->width || - cache->viewport.height != renderArea->height) { - GL_CHECK(glViewport(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); - cache->viewport.left = renderArea->x; - cache->viewport.top = renderArea->y; - cache->viewport.width = renderArea->width; - cache->viewport.height = renderArea->height; - } + if (subpassIdx == 0) { + if (cache->viewport.left != renderArea->x || + cache->viewport.top != renderArea->y || + cache->viewport.width != renderArea->width || + cache->viewport.height != renderArea->height) { + GL_CHECK(glViewport(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); + cache->viewport.left = renderArea->x; + cache->viewport.top = renderArea->y; + cache->viewport.width = renderArea->width; + cache->viewport.height = renderArea->height; + } - if (cache->scissor.x != renderArea->x || - cache->scissor.y != renderArea->y || - cache->scissor.width != renderArea->width || - cache->scissor.height != renderArea->height) { - GL_CHECK(glScissor(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); - cache->scissor.x = renderArea->x; - cache->scissor.y = renderArea->y; - cache->scissor.width = renderArea->width; - cache->scissor.height = renderArea->height; + if (cache->scissor.x != renderArea->x || + cache->scissor.y != renderArea->y || + cache->scissor.width != renderArea->width || + cache->scissor.height != renderArea->height) { + GL_CHECK(glScissor(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); + cache->scissor.x = renderArea->x; + cache->scissor.y = renderArea->y; + cache->scissor.width = renderArea->width; + cache->scissor.height = renderArea->height; + } } GLbitfield glClears = 0; bool maskSet = false; invalidAttachments.clear(); - auto performLoadOp = [&](uint attachmentIndex, uint glAttachmentIndex) { + auto performLoadOp = [&](uint32_t attachmentIndex, uint32_t glAttachmentIndex) { + if (attachmentIndex == gpuFramebuffer->uberOnChipOutput) attachmentIndex = gpuFramebuffer->uberFinalOutput; + const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[attachmentIndex]; if (colorAttachment.format != Format::UNKNOWN) { switch (colorAttachment.loadOp) { @@ -1519,12 +1578,17 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPUR } }; - auto performDepthStencilLoadOp = [&]() { - if (gpuRenderPass->depthStencilAttachment.format == Format::UNKNOWN) return; + auto performDepthStencilLoadOp = [&](uint32_t attachmentIndex, bool skipLoad) { + if (attachmentIndex != INVALID_BINDING && !skipLoad) { + LoadOp depthLoadOp = gpuRenderPass->depthStencilAttachment.depthLoadOp; + LoadOp stencilLoadOp = gpuRenderPass->depthStencilAttachment.stencilLoadOp; + bool hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)].hasStencil; + if (attachmentIndex < gpuRenderPass->colorAttachments.size()) { + depthLoadOp = stencilLoadOp = gpuRenderPass->colorAttachments[attachmentIndex].loadOp; + hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->colorAttachments[attachmentIndex].format)].hasStencil; + } - bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; - if (hasDepth) { - switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { + switch (depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: { if (!cache->dss.depthWrite) { @@ -1538,29 +1602,28 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPUR invalidAttachments.push_back(glFramebuffer ? GL_DEPTH_ATTACHMENT : GL_DEPTH_EXT); break; } - } - bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; - if (hasStencils) { - switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { - case LoadOp::LOAD: break; // GL default behaviour - case LoadOp::CLEAR: { - if (!cache->dss.stencilWriteMaskFront) { - GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff)); - } - if (!cache->dss.stencilWriteMaskBack) { - GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff)); - } - GL_CHECK(glClearStencil(clearStencil)); - glClears |= GL_STENCIL_BUFFER_BIT; - } break; - case LoadOp::DISCARD: - // invalidate fbo - invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); - break; + if (hasStencils) { + switch (depthLoadOp) { + case LoadOp::LOAD: break; // GL default behaviour + case LoadOp::CLEAR: { + if (!cache->dss.stencilWriteMaskFront) { + GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff)); + } + if (!cache->dss.stencilWriteMaskBack) { + GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff)); + } + GL_CHECK(glClearStencil(clearStencil)); + glClears |= GL_STENCIL_BUFFER_BIT; + } break; + case LoadOp::DISCARD: + // invalidate fbo + invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); + break; + } } } - if (!invalidAttachments.empty() && device->constantRegistry()->useDiscardFramebuffer) { + if (device->constantRegistry()->useDiscardFramebuffer && !invalidAttachments.empty()) { GL_CHECK(glDiscardFramebufferEXT(GL_FRAMEBUFFER, utils::toUint(invalidAttachments.size()), invalidAttachments.data())); } @@ -1593,21 +1656,21 @@ void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, GLES2GPUR } }; - uint glAttachmentIndex = 0U; + uint32_t glAttachmentIndex = 0U; if (gpuFramebuffer->usesFBF) { if (subpassIdx == 0) { for (const auto attachmentIndex : gpuFramebuffer->uberColorAttachmentIndices) { performLoadOp(attachmentIndex, glAttachmentIndex++); } - performDepthStencilLoadOp(); + performDepthStencilLoadOp(gpuFramebuffer->uberDepthStencil, false); } } else { for (const auto attachmentIndex : gpuRenderPass->subpasses[subpassIdx].colors) { - if (attachmentLoadOpRecord & (1 << attachmentIndex)) continue; + if (gpuRenderPass->statistics[attachmentIndex].loadSubpass != subpassIdx) continue; performLoadOp(attachmentIndex, glAttachmentIndex++); - attachmentLoadOpRecord |= 1 << attachmentIndex; } - performDepthStencilLoadOp(); + auto depthIndex = gpuRenderPass->subpasses[subpassIdx].depthStencil; + performDepthStencilLoadOp(depthIndex, gpuRenderPass->statistics[depthIndex].loadSubpass != subpassIdx); } } } @@ -1627,7 +1690,9 @@ void cmdFuncGLES2EndRenderPass(GLES2Device *device) { bool skipDiscard = false; invalidAttachments.clear(); - auto performStoreOp = [&](uint attachmentIndex, uint glAttachmentIndex) { + auto performStoreOp = [&](uint32_t attachmentIndex, uint32_t glAttachmentIndex) { + if (attachmentIndex == gpuFramebuffer->uberOnChipOutput) attachmentIndex = gpuFramebuffer->uberFinalOutput; + const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[attachmentIndex]; if (colorAttachment.format != Format::UNKNOWN) { switch (colorAttachment.storeOp) { @@ -1640,31 +1705,33 @@ void cmdFuncGLES2EndRenderPass(GLES2Device *device) { } }; - auto performDepthStencilStoreOp = [&]() { - if (gpuRenderPass->depthStencilAttachment.format == Format::UNKNOWN) return; + auto performDepthStencilStoreOp = [&](uint32_t attachmentIndex, bool skipStore) { + if (attachmentIndex != INVALID_BINDING && !skipStore) { + StoreOp depthStoreOp = gpuRenderPass->depthStencilAttachment.depthStoreOp; + StoreOp stencilStoreOp = gpuRenderPass->depthStencilAttachment.stencilStoreOp; + bool hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)].hasStencil; + if (attachmentIndex < gpuRenderPass->colorAttachments.size()) { + depthStoreOp = stencilStoreOp = gpuRenderPass->colorAttachments[attachmentIndex].storeOp; + hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->colorAttachments[attachmentIndex].format)].hasStencil; + } - bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; - if (hasDepth) { switch (gpuRenderPass->depthStencilAttachment.depthStoreOp) { case StoreOp::STORE: break; case StoreOp::DISCARD: - // invalidate fbo invalidAttachments.push_back(glFramebuffer ? GL_DEPTH_ATTACHMENT : GL_DEPTH_EXT); break; } - } // if (hasDepth) - bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; - if (hasStencils) { - switch (gpuRenderPass->depthStencilAttachment.stencilStoreOp) { - case StoreOp::STORE: break; - case StoreOp::DISCARD: - // invalidate fbo - invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); - break; + if (hasStencils) { + switch (gpuRenderPass->depthStencilAttachment.stencilStoreOp) { + case StoreOp::STORE: break; + case StoreOp::DISCARD: + invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL_EXT); + break; + } } } - if (!skipDiscard && !invalidAttachments.empty() && device->constantRegistry()->useDiscardFramebuffer) { + if (!skipDiscard && device->constantRegistry()->useDiscardFramebuffer && !invalidAttachments.empty()) { GL_CHECK(glDiscardFramebufferEXT(GL_FRAMEBUFFER, utils::toUint(invalidAttachments.size()), invalidAttachments.data())); } }; @@ -1680,7 +1747,7 @@ void cmdFuncGLES2EndRenderPass(GLES2Device *device) { TextureBlit region; if (instance.resolveMask & GL_COLOR_BUFFER_BIT) { - for (uint i = 0; i < subpass.colors.size(); ++i) { + for (uint32_t i = 0; i < subpass.colors.size(); ++i) { GLES2GPUTexture *srcTexture = gpuFramebuffer->gpuColorTextures[subpass.colors[i]]; GLES2GPUTexture *dstTexture = gpuFramebuffer->gpuColorTextures[subpass.resolves[i]]; @@ -1710,14 +1777,23 @@ void cmdFuncGLES2EndRenderPass(GLES2Device *device) { skipDiscard = true; // framebuffer was already stored } - uint glAttachmentIndex = 0U; + uint32_t glAttachmentIndex = 0U; if (gpuFramebuffer->usesFBF) { if (isTheLastSubpass) { for (const auto attachmentIndex : gpuFramebuffer->uberColorAttachmentIndices) { performStoreOp(attachmentIndex, glAttachmentIndex++); } - performDepthStencilStoreOp(); - } else if (gpuFramebuffer->usesFBF) { + performDepthStencilStoreOp(gpuFramebuffer->uberDepthStencil, false); + + if (gpuFramebuffer->uberOnChipOutput != INVALID_BINDING) { + TextureBlit region; + auto * blitSrc = gpuFramebuffer->gpuColorTextures[gpuFramebuffer->uberOnChipOutput]; + auto * blitDst = gpuFramebuffer->gpuColorTextures[gpuFramebuffer->uberFinalOutput]; + region.srcExtent.width = region.dstExtent.width = blitSrc->width; + region.srcExtent.height = region.dstExtent.height = blitSrc->height; + cmdFuncGLES2BlitTexture(device, blitSrc, blitDst, ®ion, 1, Filter::POINT); + } + } else { if (device->constantRegistry()->mFBF == FBFSupportLevel::NON_COHERENT_EXT) { glFramebufferFetchBarrierEXT(); } else if (device->constantRegistry()->mFBF == FBFSupportLevel::NON_COHERENT_QCOM) { @@ -1725,18 +1801,18 @@ void cmdFuncGLES2EndRenderPass(GLES2Device *device) { } } } else { - if (isTheLastSubpass) { - const auto &indices = subpass.resolves.empty() ? subpass.colors : subpass.resolves; - for (const auto attachmentIndex : indices) { - performStoreOp(attachmentIndex, glAttachmentIndex++); - } - performDepthStencilStoreOp(); + const auto &indices = subpass.resolves.empty() ? subpass.colors : subpass.resolves; + for (const auto attachmentIndex : indices) { + if (gpuRenderPass->statistics[attachmentIndex].storeSubpass != gfxStateCache.subpassIdx) continue; + performStoreOp(attachmentIndex, glAttachmentIndex++); } + performDepthStencilStoreOp(subpass.depthStencil, gpuRenderPass->statistics[subpass.depthStencil].loadSubpass != gfxStateCache.subpassIdx); } } +// NOLINTNEXTLINE(google-readability-function-size, readability-function-size) void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipelineState, GLES2GPUInputAssembler *gpuInputAssembler, - const GLES2GPUDescriptorSet *const *gpuDescriptorSets, const uint *dynamicOffsets, + const GLES2GPUDescriptorSet *const *gpuDescriptorSets, const uint32_t *dynamicOffsets, const DynamicStates *dynamicStates) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; @@ -1958,7 +2034,7 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli GLES2GPUUniformBlock &glBlock = gpuPipelineState->gpuShader->glBlocks[j]; const GLES2GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glBlock.set]; - const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glBlock.binding); + const uint32_t descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glBlock.binding); const GLES2GPUDescriptor & gpuDescriptor = gpuDescriptorSet->gpuDescriptors[descriptorIndex]; if (!gpuDescriptor.gpuBuffer && !gpuDescriptor.gpuBufferView) { @@ -1967,7 +2043,7 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli continue; } - uint offset = 0U; + uint32_t offset = 0U; const vector &dynamicOffsetIndexSet = dynamicOffsetIndices[glBlock.set]; if (dynamicOffsetIndexSet.size() > glBlock.binding) { int dynamicOffsetIndex = dynamicOffsetIndexSet[glBlock.binding]; @@ -2078,11 +2154,11 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli const GLES2GPUUniformSamplerTexture &glSamplerTexture = gpuPipelineState->gpuShader->glSamplerTextures[j]; const GLES2GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glSamplerTexture.set]; - const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glSamplerTexture.binding); + const uint32_t descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glSamplerTexture.binding); const GLES2GPUDescriptor * gpuDescriptor = &gpuDescriptorSet->gpuDescriptors[descriptorIndex]; for (size_t u = 0; u < glSamplerTexture.units.size(); u++, gpuDescriptor++) { - uint unit = static_cast(glSamplerTexture.units[u]); + auto unit = static_cast(glSamplerTexture.units[u]); if (!gpuDescriptor->gpuTexture || !gpuDescriptor->gpuSampler) { CC_LOG_ERROR( @@ -2189,9 +2265,9 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli if (gpuAttribute.name == gpuInput.name) { GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer)); - for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLuint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + for (uint32_t c = 0; c < gpuAttribute.componentCount; ++c) { + GLuint glLoc = gpuInput.glLoc + c; + uint32_t attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glEnabledAttribLocs[glLoc] = true; @@ -2240,9 +2316,9 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli cache->glArrayBuffer = gpuAttribute.glBuffer; } - for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLuint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + for (uint32_t c = 0; c < gpuAttribute.componentCount; ++c) { + GLuint glLoc = gpuInput.glLoc + c; + uint32_t attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glEnabledAttribLocs[glLoc] = true; cache->glCurrentAttribLocs[glLoc] = true; @@ -2258,8 +2334,8 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } break; } - } // for - } // for + } + } if (gpuInputAssembler->gpuIndexBuffer) { if (cache->glElementArrayBuffer != @@ -2269,32 +2345,18 @@ void cmdFuncGLES2BindState(GLES2Device *device, GLES2GPUPipelineState *gpuPipeli } } - for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { + for (uint32_t a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { if (cache->glEnabledAttribLocs[a] != cache->glCurrentAttribLocs[a]) { GL_CHECK(glDisableVertexAttribArray(a)); cache->glEnabledAttribLocs[a] = false; } } } - } // if + } if (gpuPipelineState && !gpuPipelineState->dynamicStates.empty()) { for (DynamicStateFlagBit dynamicState : gpuPipelineState->dynamicStates) { switch (dynamicState) { - case DynamicStateFlagBit::VIEWPORT: - if (cache->viewport != dynamicStates->viewport) { - cache->viewport = dynamicStates->viewport; - GL_CHECK(glViewport(dynamicStates->viewport.left, dynamicStates->viewport.top, - dynamicStates->viewport.width, dynamicStates->viewport.height)); - } - break; - case DynamicStateFlagBit::SCISSOR: - if (cache->scissor != dynamicStates->scissor) { - cache->scissor = dynamicStates->scissor; - GL_CHECK(glScissor(dynamicStates->scissor.x, dynamicStates->scissor.y, - dynamicStates->scissor.width, dynamicStates->scissor.height)); - } - break; case DynamicStateFlagBit::LINE_WIDTH: if (cache->rs.lineWidth != dynamicStates->lineWidth) { cache->rs.lineWidth = dynamicStates->lineWidth; @@ -2421,7 +2483,7 @@ void cmdFuncGLES2Draw(GLES2Device *device, const DrawInfo &drawInfo) { } } -void cmdFuncGLES2UpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { +void cmdFuncGLES2UpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, const void *buffer, uint32_t offset, uint32_t size) { GLES2ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; CCASSERT(buffer, "Buffer should not be nullptr"); if ((hasFlag(gpuBuffer->usage, BufferUsageBit::UNIFORM)) || @@ -2469,20 +2531,20 @@ void cmdFuncGLES2UpdateBuffer(GLES2Device *device, GLES2GPUBuffer *gpuBuffer, co } void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, - GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { + GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint32_t count) { GLuint &glTexture = device->stateCache()->glTextures[device->stateCache()->texUint]; if (glTexture != gpuTexture->glTexture) { GL_CHECK(glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - bool isCompressed = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed; - uint n = 0; + bool isCompressed = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed; + uint32_t n = 0; switch (gpuTexture->glTarget) { case GL_TEXTURE_2D: { - uint w; - uint h; + uint32_t w; + uint32_t h; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; @@ -2512,14 +2574,14 @@ void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const break; } case GL_TEXTURE_2D_ARRAY: { - uint w; - uint h; + uint32_t w; + uint32_t h; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; - uint d = region.texSubres.layerCount; - uint layerCount = d + region.texSubres.baseArrayLayer; + uint32_t d = region.texSubres.layerCount; + uint32_t layerCount = d + region.texSubres.baseArrayLayer; - for (uint z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { + for (uint32_t z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { w = region.texExtent.width; h = region.texExtent.height; const uint8_t *buff = buffers[n++]; @@ -2549,9 +2611,9 @@ void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const break; } case GL_TEXTURE_3D: { - uint w; - uint h; - uint d; + uint32_t w; + uint32_t h; + uint32_t d; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; @@ -2584,12 +2646,12 @@ void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const break; } case GL_TEXTURE_CUBE_MAP: { - uint w; - uint h; - uint f; + uint32_t w; + uint32_t h; + uint32_t f; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; - uint faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount; + uint32_t faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount; for (f = region.texSubres.baseArrayLayer; f < faceCount; ++f) { w = region.texExtent.width; h = region.texExtent.height; @@ -2628,7 +2690,7 @@ void cmdFuncGLES2CopyBuffersToTexture(GLES2Device *device, const uint8_t *const } } -CC_GLES2_API void cmdFuncGLES2CopyTextureToBuffers(GLES2Device *device, GLES2GPUTexture *gpuTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { +CC_GLES2_API void cmdFuncGLES2CopyTextureToBuffers(GLES2Device *device, GLES2GPUTexture *gpuTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { GLuint framebuffer = device->framebufferCacheMap()->getFramebufferFromTexture(gpuTexture); auto glFormat = gpuTexture->glFormat; auto glType = gpuTexture->glType; @@ -2645,7 +2707,7 @@ CC_GLES2_API void cmdFuncGLES2CopyTextureToBuffers(GLES2Device *device, GLES2GPU } } -void cmdFuncGLES2BlitTexture(GLES2Device *device, GLES2GPUTexture *gpuTextureSrc, GLES2GPUTexture *gpuTextureDst, const TextureBlit *regions, uint count, Filter filter) { +void cmdFuncGLES2BlitTexture(GLES2Device *device, GLES2GPUTexture *gpuTextureSrc, GLES2GPUTexture *gpuTextureDst, const TextureBlit *regions, uint32_t count, Filter filter) { GLES2GPUStateCache *cache = device->stateCache(); GLuint dstFramebuffer = 0U; @@ -2667,12 +2729,12 @@ void cmdFuncGLES2BlitTexture(GLES2Device *device, GLES2GPUTexture *gpuTextureSrc void cmdFuncGLES2ExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) { if (!cmdPackage->cmds.size()) return; - static uint cmdIndices[static_cast(GLESCmdType::COUNT)] = {0}; + static uint32_t cmdIndices[static_cast(GLESCmdType::COUNT)] = {0}; memset(cmdIndices, 0, sizeof(cmdIndices)); - for (uint i = 0; i < cmdPackage->cmds.size(); ++i) { + for (uint32_t i = 0; i < cmdPackage->cmds.size(); ++i) { GLESCmdType cmdType = cmdPackage->cmds[i]; - uint & cmdIdx = cmdIndices[static_cast(cmdType)]; + uint32_t & cmdIdx = cmdIndices[static_cast(cmdType)]; switch (cmdType) { case GLESCmdType::BEGIN_RENDER_PASS: { @@ -2849,14 +2911,14 @@ static void ensureScissorRect(GLES2GPUStateCache *cache, int32_t x, int32_t y, u } void GLES2GPUBlitManager::draw(GLES2GPUTexture *gpuTextureSrc, GLES2GPUTexture *gpuTextureDst, - const TextureBlit *regions, uint count, Filter filter) { + const TextureBlit *regions, uint32_t count, Filter filter) { GLES2GPUDescriptorSet *gpuDescriptorSet = &_gpuDescriptorSet; GLES2Device * device = GLES2Device::getInstance(); auto & descriptor = _gpuDescriptorSet.gpuDescriptors.back(); descriptor.gpuTexture = gpuTextureSrc; descriptor.gpuSampler = filter == Filter::POINT ? &_gpuPointSampler : &_gpuLinearSampler; - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { const auto ®ion = regions[i]; auto srcWidth = static_cast(gpuTextureSrc->width); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.h b/native/cocos/renderer/gfx-gles2/GLES2Commands.h index 0f73fa0c87..0e6b2ddaee 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.h @@ -47,8 +47,8 @@ public: Rect renderArea; Color clearColors[MAX_ATTACHMENTS]; float clearDepth = 1.0F; - uint clearStencil = 0; - uint subpassIdx = 0U; + uint32_t clearStencil = 0; + uint32_t subpassIdx = 0U; GLES2CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} @@ -63,7 +63,7 @@ public: GLES2GPUPipelineState * gpuPipelineState = nullptr; GLES2GPUInputAssembler * gpuInputAssembler = nullptr; vector gpuDescriptorSets; - vector dynamicOffsets; + vector dynamicOffsets; DynamicStates dynamicStates; GLES2CmdBindStates() : GLESCmd(GLESCmdType::BIND_STATES) {} @@ -88,8 +88,8 @@ class GLES2CmdUpdateBuffer final : public GLESCmd { public: GLES2GPUBuffer *gpuBuffer = nullptr; const uint8_t * buffer = nullptr; - uint size = 0; - uint offset = 0; + uint32_t size = 0; + uint32_t offset = 0; GLES2CmdUpdateBuffer() : GLESCmd(GLESCmdType::UPDATE_BUFFER) {} @@ -103,7 +103,7 @@ class GLES2CmdCopyBufferToTexture final : public GLESCmd { public: GLES2GPUTexture * gpuTexture = nullptr; const BufferTextureCopy *regions = nullptr; - uint count = 0U; + uint32_t count = 0U; const uint8_t *const * buffers; GLES2CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} @@ -121,7 +121,7 @@ public: GLES2GPUTexture * gpuTextureSrc = nullptr; GLES2GPUTexture * gpuTextureDst = nullptr; const TextureBlit *regions = nullptr; - uint count = 0U; + uint32_t count = 0U; Filter filter = Filter::POINT; GLES2CmdBlitTexture() : GLESCmd(GLESCmdType::BLIT_TEXTURE) {} @@ -197,18 +197,20 @@ CC_GLES2_API void cmdFuncGLES2CreateSampler(GLES2Device *device, GLES2GPUSampler CC_GLES2_API void cmdFuncGLES2DestroySampler(GLES2Device *device, GLES2GPUSampler *gpuSampler); CC_GLES2_API void cmdFuncGLES2CreateShader(GLES2Device *device, GLES2GPUShader *gpuShader); CC_GLES2_API void cmdFuncGLES2DestroyShader(GLES2Device *device, GLES2GPUShader *gpuShader); +CC_GLES2_API void cmdFuncGLES2CreateRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRenderPass); +CC_GLES2_API void cmdFuncGLES2DestroyRenderPass(GLES2Device *device, GLES2GPURenderPass *gpuRenderPass); CC_GLES2_API void cmdFuncGLES2CreateInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler); CC_GLES2_API void cmdFuncGLES2DestroyInputAssembler(GLES2Device *device, GLES2GPUInputAssembler *gpuInputAssembler); CC_GLES2_API void cmdFuncGLES2CreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); CC_GLES2_API void cmdFuncGLES2DestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO); -CC_GLES2_API void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint subpassIdx, +CC_GLES2_API void cmdFuncGLES2BeginRenderPass(GLES2Device *device, uint32_t subpassIdx, GLES2GPURenderPass * gpuRenderPass = nullptr, GLES2GPUFramebuffer *gpuFramebuffer = nullptr, const Rect * renderArea = nullptr, const Color * clearColors = nullptr, float clearDepth = 1.F, - uint clearStencil = 0); + uint32_t clearStencil = 0); CC_GLES2_API void cmdFuncGLES2EndRenderPass(GLES2Device *device); @@ -216,7 +218,7 @@ CC_GLES2_API void cmdFuncGLES2BindState(GLES2Device * devi GLES2GPUPipelineState * gpuPipelineState, GLES2GPUInputAssembler * gpuInputAssembler, const GLES2GPUDescriptorSet *const *gpuDescriptorSets, - const uint * dynamicOffsets = nullptr, + const uint32_t * dynamicOffsets = nullptr, const DynamicStates * dynamicStates = nullptr); CC_GLES2_API void cmdFuncGLES2Draw(GLES2Device *device, const DrawInfo &drawInfo); @@ -224,26 +226,26 @@ CC_GLES2_API void cmdFuncGLES2Draw(GLES2Device *device, const DrawInfo &drawInfo CC_GLES2_API void cmdFuncGLES2UpdateBuffer(GLES2Device * device, GLES2GPUBuffer *gpuBuffer, const void * buffer, - uint offset, - uint size); + uint32_t offset, + uint32_t size); CC_GLES2_API void cmdFuncGLES2CopyBuffersToTexture(GLES2Device * device, const uint8_t *const * buffers, GLES2GPUTexture * gpuTexture, const BufferTextureCopy *regions, - uint count); + uint32_t count); CC_GLES2_API void cmdFuncGLES2CopyTextureToBuffers(GLES2Device * device, GLES2GPUTexture * gpuTexture, uint8_t *const * buffers, const BufferTextureCopy *regions, - uint count); + uint32_t count); CC_GLES2_API void cmdFuncGLES2BlitTexture(GLES2Device * device, GLES2GPUTexture * gpuTextureSrc, GLES2GPUTexture * gpuTextureDst, const TextureBlit *regions, - uint count, + uint32_t count, Filter filter); CC_GLES2_API void cmdFuncGLES2ExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage); diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp index 45ee26103d..b4511d98b5 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp @@ -56,7 +56,7 @@ void GLES2DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); for (size_t i = 0U, k = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; - for (uint j = 0; j < binding.count; j++, k++) { + for (uint32_t j = 0; j < binding.count; j++, k++) { _gpuDescriptorSet->gpuDescriptors[k].type = binding.descriptorType; } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp index e1f3d53653..d6a1640f89 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp @@ -48,7 +48,7 @@ void GLES2DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo& /*info*/) { for (auto& binding : _bindings) { if (hasAnyFlags(binding.descriptorType, DESCRIPTOR_DYNAMIC_TYPE)) { - for (uint j = 0U; j < binding.count; j++) { + for (uint32_t j = 0U; j < binding.count; j++) { _gpuDescriptorSetLayout->dynamicBindings.push_back(binding.binding); } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index c2fdbc1998..9f718ba3a9 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -168,7 +168,7 @@ bool GLES2Device::doInit(const DeviceInfo & /*info*/) { _gpuConstantRegistry->mFBF = FBFSupportLevel::COHERENT; fbfLevelStr = "COHERENT"; } - _features[toNumber(Feature::GL_FRAMEBUFFER_FETCH)] = true; + _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = true; } #endif @@ -327,23 +327,23 @@ PipelineState *GLES2Device::createPipelineState() { return CC_NEW(GLES2PipelineState); } -Sampler *GLES2Device::createSampler(const SamplerInfo &info) { - return CC_NEW(GLES2Sampler(info)); +Sampler *GLES2Device::createSampler(const SamplerInfo &info, uint32_t hash) { + return CC_NEW(GLES2Sampler(info, hash)); } -GlobalBarrier *GLES2Device::createGlobalBarrier(const GlobalBarrierInfo &info) { - return CC_NEW(GlobalBarrier(info)); +GlobalBarrier *GLES2Device::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) { + return CC_NEW(GlobalBarrier(info, hash)); } -TextureBarrier *GLES2Device::createTextureBarrier(const TextureBarrierInfo &info) { - return CC_NEW(TextureBarrier(info)); +TextureBarrier *GLES2Device::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) { + return CC_NEW(TextureBarrier(info, hash)); } -void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { +void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { cmdFuncGLES2CopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count); } -void GLES2Device::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) { +void GLES2Device::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) { cmdFuncGLES2CopyTextureToBuffers(this, static_cast(src)->gpuTexture(), buffers, region, count); } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index 3279ff8f9f..3429c82001 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -100,12 +100,12 @@ protected: PipelineLayout * createPipelineLayout() override; PipelineState * createPipelineState() override; - Sampler * createSampler(const SamplerInfo &info) override; - GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) override; + Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override; + GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override; + void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override; void bindContext(bool bound) override; diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp b/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp index 0941cef398..38e611313d 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUContext.cpp @@ -31,7 +31,7 @@ namespace cc { namespace gfx { #if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION -constexpr uint DISABLE_VALIDATION_ASSERTIONS = 1; // 0 for default behavior, otherwise assertions will be disabled +constexpr uint32_t DISABLE_VALIDATION_ASSERTIONS = 1; // 0 for default behavior, otherwise assertions will be disabled void GL_APIENTRY GLES2EGLDebugProc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { String sourceDesc; diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h index eed1bf653c..2c8826ed24 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h @@ -103,9 +103,9 @@ class GLES2GPUBuffer final : public Object { public: BufferUsage usage = BufferUsage::NONE; MemoryUsage memUsage = MemoryUsage::NONE; - uint size = 0; - uint stride = 0; - uint count = 0; + uint32_t size = 0; + uint32_t stride = 0; + uint32_t count = 0; GLenum glTarget = 0; GLuint glBuffer = 0; uint8_t * buffer = nullptr; @@ -116,8 +116,8 @@ using GLES2GPUBufferList = vector; class GLES2GPUBufferView final : public Object { public: GLES2GPUBuffer *gpuBuffer = nullptr; - uint offset = 0U; - uint range = 0U; + uint32_t offset = 0U; + uint32_t range = 0U; }; class GLES2GPUTexture final : public Object { @@ -125,12 +125,12 @@ public: TextureType type{TextureType::TEX2D}; Format format{Format::UNKNOWN}; TextureUsage usage{TextureUsageBit::NONE}; - uint width{0}; - uint height{0}; - uint depth{1}; - uint size{0}; - uint arrayLayer{1}; - uint mipLevel{1}; + uint32_t width{0}; + uint32_t height{0}; + uint32_t depth{1}; + uint32_t size{0}; + uint32_t arrayLayer{1}; + uint32_t mipLevel{1}; SampleCount samples{SampleCount::ONE}; TextureFlags flags{TextureFlagBit::NONE}; bool isPowerOf2{false}; @@ -168,25 +168,25 @@ public: }; struct GLES2GPUInput final { - uint binding = 0; - String name; - Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; - GLenum glType = 0; - GLint glLoc = -1; + uint32_t binding = 0; + String name; + Type type = Type::UNKNOWN; + uint32_t stride = 0; + uint32_t count = 0; + uint32_t size = 0; + GLenum glType = 0; + GLint glLoc = -1; }; using GLES2GPUInputList = vector; struct GLES2GPUUniform final { - uint binding = INVALID_BINDING; + uint32_t binding = INVALID_BINDING; String name; Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; - uint offset = 0; + uint32_t stride = 0; + uint32_t count = 0; + uint32_t size = 0; + uint32_t offset = 0; GLenum glType = 0; GLint glLoc = -1; vector buff; @@ -194,23 +194,23 @@ struct GLES2GPUUniform final { using GLES2GPUUniformList = vector; struct GLES2GPUUniformBlock final { - uint set = 0; - uint binding = 0; - uint idx = 0; + uint32_t set = 0; + uint32_t binding = 0; + uint32_t idx = 0; String name; - uint size = 0; + uint32_t size = 0; GLES2GPUUniformList glUniforms; GLES2GPUUniformList glActiveUniforms; - vector activeUniformIndices; + vector activeUniformIndices; }; using GLES2GPUUniformBlockList = vector; struct GLES2GPUUniformSamplerTexture final { - uint set = 0; - uint binding = 0; - String name; - Type type = Type::UNKNOWN; - uint count = 0U; + uint32_t set = 0; + uint32_t binding = 0; + String name; + Type type = Type::UNKNOWN; + uint32_t count = 0U; vector units; GLenum glType = 0; @@ -239,16 +239,16 @@ public: }; struct GLES2GPUAttribute final { - String name; - GLuint glBuffer = 0; - GLenum glType = 0; - uint size = 0; - uint count = 0; - uint stride = 1; - uint componentCount = 1; - bool isNormalized = false; - bool isInstanced = false; - uint offset = 0; + String name; + GLuint glBuffer = 0; + GLenum glType = 0; + uint32_t size = 0; + uint32_t count = 0; + uint32_t stride = 1; + uint32_t componentCount = 1; + bool isNormalized = false; + bool isInstanced = false; + uint32_t offset = 0; }; using GLES2GPUAttributeList = vector; @@ -265,19 +265,25 @@ public: class GLES2GPURenderPass final : public Object { public: + struct AttachmentStatistics { + uint32_t loadSubpass{SUBPASS_EXTERNAL}; + uint32_t storeSubpass{SUBPASS_EXTERNAL}; + }; + ColorAttachmentList colorAttachments; DepthStencilAttachment depthStencilAttachment; SubpassInfoList subpasses; + + vector statistics; // per attachment }; class GLES2GPUFramebufferCacheMap; class GLES2GPUFramebuffer final : public Object { public: - GLES2GPURenderPass *gpuRenderPass = nullptr; + GLES2GPURenderPass *gpuRenderPass{nullptr}; GLES2GPUTextureList gpuColorTextures; - GLES2GPUTexture * gpuDepthStencilTexture = nullptr; - - bool usesFBF = false; + GLES2GPUTexture * gpuDepthStencilTexture{nullptr}; + bool usesFBF{false}; struct GLFramebuffer { inline void initialize(GLES2GPUSwapchain *sc) { swapchain = sc; } @@ -303,18 +309,24 @@ public: // one per subpass, if not using FBF vector instances; - vector uberColorAttachmentIndices; - Framebuffer uberInstance; + vector uberColorAttachmentIndices; + uint32_t uberDepthStencil{INVALID_BINDING}; + Framebuffer uberInstance; + + // the assumed shader output, may differ from actual subpass output + // see Feature::INPUT_ATTACHMENT_BENEFIT for more + uint32_t uberOnChipOutput{INVALID_BINDING}; + uint32_t uberFinalOutput{INVALID_BINDING}; }; class GLES2GPUDescriptorSetLayout final : public Object { public: DescriptorSetLayoutBindingList bindings; - vector dynamicBindings; + vector dynamicBindings; - vector bindingIndices; - vector descriptorIndices; - uint descriptorCount = 0U; + vector bindingIndices; + vector descriptorIndices; + uint32_t descriptorCount = 0U; }; using GLES2GPUDescriptorSetLayoutList = vector; @@ -324,9 +336,9 @@ public: // helper storages vector> dynamicOffsetIndices; - vector dynamicOffsetOffsets; - vector dynamicOffsets; - uint dynamicOffsetCount = 0U; + vector dynamicOffsetOffsets; + vector dynamicOffsets; + uint32_t dynamicOffsetCount = 0U; }; class GLES2GPUPipelineState final : public Object { @@ -353,8 +365,8 @@ using GLES2GPUDescriptorList = vector; class GLES2GPUDescriptorSet final : public Object { public: - GLES2GPUDescriptorList gpuDescriptors; - const vector * descriptorIndices = nullptr; + GLES2GPUDescriptorList gpuDescriptors; + const vector *descriptorIndices = nullptr; }; class GLES2GPUFence final : public Object { @@ -362,7 +374,7 @@ public: }; struct GLES2ObjectCache final { - uint subpassIdx = 0U; + uint32_t subpassIdx = 0U; GLES2GPURenderPass * gpuRenderPass = nullptr; GLES2GPUFramebuffer * gpuFramebuffer = nullptr; GLES2GPUPipelineState * gpuPipelineState = nullptr; @@ -371,32 +383,32 @@ struct GLES2ObjectCache final { Rect renderArea; ColorList clearColors; float clearDepth = 1.F; - uint clearStencil = 0U; + uint32_t clearStencil = 0U; }; class GLES2GPUStateCache final : public Object { public: - GLuint glArrayBuffer = 0; - GLuint glElementArrayBuffer = 0; - GLuint glUniformBuffer = 0; - GLuint glVAO = 0; - uint texUint = 0; - vector glTextures; - GLuint glProgram = 0; - vector glEnabledAttribLocs; - vector glCurrentAttribLocs; - GLuint glFramebuffer = 0; - GLuint glRenderbuffer = 0; - GLuint glReadFBO = 0; - Viewport viewport; - Rect scissor; - RasterizerState rs; - DepthStencilState dss; - BlendState bs; - bool isCullFaceEnabled = true; - bool isStencilTestEnabled = false; - unordered_map texUnitCacheMap; - GLES2ObjectCache gfxStateCache; + GLuint glArrayBuffer = 0; + GLuint glElementArrayBuffer = 0; + GLuint glUniformBuffer = 0; + GLuint glVAO = 0; + uint32_t texUint = 0; + vector glTextures; + GLuint glProgram = 0; + vector glEnabledAttribLocs; + vector glCurrentAttribLocs; + GLuint glFramebuffer = 0; + GLuint glRenderbuffer = 0; + GLuint glReadFBO = 0; + Viewport viewport; + Rect scissor; + RasterizerState rs; + DepthStencilState dss; + BlendState bs; + bool isCullFaceEnabled = true; + bool isStencilTestEnabled = false; + unordered_map texUnitCacheMap; + GLES2ObjectCache gfxStateCache; void initialize(size_t texUnits, size_t vertexAttributes) { glTextures.resize(texUnits, 0U); @@ -438,7 +450,7 @@ class GLES2GPUBlitManager final : public Object { public: void initialize(); void destroy(); - void draw(GLES2GPUTexture *gpuTextureSrc, GLES2GPUTexture *gpuTextureDst, const TextureBlit *regions, uint count, Filter filter); + void draw(GLES2GPUTexture *gpuTextureSrc, GLES2GPUTexture *gpuTextureDst, const TextureBlit *regions, uint32_t count, Filter filter); private: GLES2GPUShader _gpuShader; @@ -498,7 +510,7 @@ public: _cache->glFramebuffer = glFramebuffer; } - const FormatInfo &info = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)]; + const FormatInfo &info = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)]; if (isTexture) { if (info.hasDepth) { GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, gpuTexture->glTarget, glResource, 0)); diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp index b2e74afd85..e978a09406 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp @@ -45,17 +45,17 @@ GLES2PipelineLayout::~GLES2PipelineLayout() { void GLES2PipelineLayout::doInit(const PipelineLayoutInfo & /*info*/) { _gpuPipelineLayout = CC_NEW(GLES2GPUPipelineLayout); - uint offset = 0U; + uint32_t offset = 0U; _gpuPipelineLayout->dynamicOffsetIndices.resize(_setLayouts.size()); - for (uint i = 0U; i < _setLayouts.size(); i++) { + for (uint32_t i = 0U; i < _setLayouts.size(); i++) { DescriptorSetLayout * setLayout = _setLayouts[i]; GLES2GPUDescriptorSetLayout *gpuSetLayout = static_cast(setLayout)->gpuDescriptorSetLayout(); - uint dynamicCount = utils::toUint(gpuSetLayout->dynamicBindings.size()); + uint32_t dynamicCount = utils::toUint(gpuSetLayout->dynamicBindings.size()); vector & indices = _gpuPipelineLayout->dynamicOffsetIndices[i]; indices.assign(setLayout->getBindingIndices().size(), -1); - for (uint j = 0U; j < dynamicCount; j++) { - uint binding = gpuSetLayout->dynamicBindings[j]; + for (uint32_t j = 0U; j < dynamicCount; j++) { + uint32_t binding = gpuSetLayout->dynamicBindings[j]; if (indices[binding] < 0) indices[binding] = offset + j; } _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp index bdab797d7c..d46029ad3a 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp @@ -69,8 +69,8 @@ void GLES2PipelineState::doInit(const PipelineStateInfo & /*info*/) { _gpuPipelineState->gpuPipelineLayout = static_cast(_pipelineLayout)->gpuPipelineLayout(); if (_renderPass) _gpuPipelineState->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); - for (uint i = 0; i < 31; i++) { - if (static_cast(_dynamicStates) & (1 << i)) { + for (uint32_t i = 0; i < 31; i++) { + if (static_cast(_dynamicStates) & (1 << i)) { _gpuPipelineState->dynamicStates.push_back(static_cast(1 << i)); } } diff --git a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp index 65dd2bde32..bcb1adfb0b 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp @@ -43,7 +43,7 @@ GLES2PrimaryCommandBuffer::~GLES2PrimaryCommandBuffer() { destroy(); } -void GLES2PrimaryCommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { +void GLES2PrimaryCommandBuffer::begin(RenderPass * /*renderPass*/, uint32_t /*subpass*/, Framebuffer * /*frameBuffer*/) { _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); @@ -59,7 +59,7 @@ void GLES2PrimaryCommandBuffer::end() { } } -void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { +void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const * /*secondaryCBs*/, uint32_t /*secondaryCBCount*/) { _curSubpassIdx = 0U; GLES2GPURenderPass * gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); @@ -68,7 +68,7 @@ void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuf cmdFuncGLES2BeginRenderPass(GLES2Device::getInstance(), _curSubpassIdx, gpuRenderPass, gpuFramebuffer, &renderArea, colors, depth, stencil); _curDynamicStates.viewport = {renderArea.x, renderArea.y, renderArea.width, renderArea.height}; - _curDynamicStates.scissor = renderArea; + _curDynamicStates.scissor = renderArea; } void GLES2PrimaryCommandBuffer::endRenderPass() { @@ -82,13 +82,13 @@ void GLES2PrimaryCommandBuffer::nextSubpass() { void GLES2PrimaryCommandBuffer::draw(const DrawInfo &info) { if (_isStateInvalid) { - vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; - vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; + vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; + vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); - if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); + if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint32_t)); } cmdFuncGLES2BindState(GLES2Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets.data(), dynamicOffsets.data(), &_curDynamicStates); @@ -100,7 +100,7 @@ void GLES2PrimaryCommandBuffer::draw(const DrawInfo &info) { ++_numDrawCalls; _numInstances += info.instanceCount; - uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; + uint32_t indexCount = info.indexCount ? info.indexCount : info.vertexCount; if (_curGPUPipelineState) { switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { @@ -118,21 +118,37 @@ void GLES2PrimaryCommandBuffer::draw(const DrawInfo &info) { } } -void GLES2PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +void GLES2PrimaryCommandBuffer::setViewport(const Viewport &vp) { + auto *cache = GLES2Device::getInstance()->stateCache(); + if (cache->viewport != vp) { + cache->viewport = vp; + GL_CHECK(glViewport(vp.left, vp.top, vp.width, vp.height)); + } +} + +void GLES2PrimaryCommandBuffer::setScissor(const Rect &rect) { + auto *cache = GLES2Device::getInstance()->stateCache(); + if (cache->scissor != rect) { + cache->scissor = rect; + GL_CHECK(glScissor(rect.x, rect.y, rect.width, rect.height)); + } +} + +void GLES2PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint32_t size) { GLES2GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { cmdFuncGLES2UpdateBuffer(GLES2Device::getInstance(), gpuBuffer, data, 0U, size); } } -void GLES2PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void GLES2PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { GLES2GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { cmdFuncGLES2CopyBuffersToTexture(GLES2Device::getInstance(), buffers, gpuTexture, regions, count); } } -void GLES2PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void GLES2PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { GLES2GPUTexture *gpuTextureSrc = nullptr; GLES2GPUTexture *gpuTextureDst = nullptr; if (srcTexture) gpuTextureSrc = static_cast(srcTexture)->gpuTexture(); @@ -142,7 +158,7 @@ void GLES2PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTex } void GLES2PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { - for (uint i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { @@ -164,13 +180,13 @@ void GLES2PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t void GLES2PrimaryCommandBuffer::bindStates() { if (_curGPUPipelineState) { - vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; - vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; + vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; + vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); - if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); + if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint32_t)); } cmdFuncGLES2BindState(GLES2Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets.data(), dynamicOffsets.data(), &_curDynamicStates); } diff --git a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h index fa72a8f3fa..936488cd71 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h @@ -35,15 +35,17 @@ public: GLES2PrimaryCommandBuffer() = default; ~GLES2PrimaryCommandBuffer() override; - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void setViewport(const Viewport &vp) override; + void setScissor(const Rect &rect) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; protected: diff --git a/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp b/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp index cc50149cbf..bd1e95a8ef 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp @@ -47,8 +47,8 @@ void GLES2Queue::doInit(const QueueInfo &info) { void GLES2Queue::doDestroy() { } -void GLES2Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { - for (uint i = 0; i < count; ++i) { +void GLES2Queue::submit(CommandBuffer *const *cmdBuffs, uint32_t count) { + for (uint32_t i = 0; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Queue.h b/native/cocos/renderer/gfx-gles2/GLES2Queue.h index a6bccd1bdd..6675fe3907 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Queue.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Queue.h @@ -36,7 +36,7 @@ public: GLES2Queue(); ~GLES2Queue() override; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override; protected: friend class GLES2Device; @@ -44,9 +44,9 @@ protected: void doInit(const QueueInfo &info) override; void doDestroy() override; - uint _numDrawCalls = 0; - uint _numInstances = 0; - uint _numTriangles = 0; + uint32_t _numDrawCalls = 0; + uint32_t _numInstances = 0; + uint32_t _numTriangles = 0; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp index 0fbee51df8..642576c190 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp @@ -26,6 +26,7 @@ #include "GLES2Std.h" #include "GLES2Commands.h" +#include "GLES2Device.h" #include "GLES2RenderPass.h" namespace cc { @@ -49,17 +50,31 @@ void GLES2RenderPass::doInit(const RenderPassInfo & /*info*/) { if (_gpuRenderPass->subpasses.empty()) { auto &subpass = _gpuRenderPass->subpasses.emplace_back(); subpass.colors.resize(_colorAttachments.size()); - for (uint i = 0U; i < _colorAttachments.size(); ++i) { + for (uint32_t i = 0U; i < _colorAttachments.size(); ++i) { subpass.colors[i] = i; } if (_depthStencilAttachment.format != Format::UNKNOWN) { subpass.depthStencil = _colorAttachments.size(); } + } else { + // unify depth stencil index + uint32_t colorCount = _gpuRenderPass->colorAttachments.size(); + for (auto &subpass : _gpuRenderPass->subpasses) { + if (subpass.depthStencil != INVALID_BINDING && subpass.depthStencil > colorCount) { + subpass.depthStencil = colorCount; + } + if (subpass.depthStencilResolve != INVALID_BINDING && subpass.depthStencilResolve > colorCount) { + subpass.depthStencilResolve = colorCount; + } + } } + + cmdFuncGLES2CreateRenderPass(GLES2Device::getInstance(), _gpuRenderPass); } void GLES2RenderPass::doDestroy() { if (_gpuRenderPass) { + cmdFuncGLES2CreateRenderPass(GLES2Device::getInstance(), _gpuRenderPass); CC_DELETE(_gpuRenderPass); _gpuRenderPass = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp b/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp index c71ab9b973..65ebcf6cd4 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Swapchain.cpp @@ -111,8 +111,6 @@ void GLES2Swapchain::doDestroy() { } void GLES2Swapchain::doResize(uint32_t width, uint32_t height, SurfaceTransform /*transform*/) { - doDestroySurface(); - _colorTexture->resize(width, height); _depthStencilTexture->resize(width, height); @@ -137,7 +135,7 @@ void GLES2Swapchain::doCreateSurface(void* windowHandle) { return; } - auto width = static_cast(_colorTexture->getWidth()); + auto width = static_cast(_colorTexture->getWidth()); auto height = static_cast(_colorTexture->getHeight()); #if CC_PLATFORM == CC_PLATFORM_ANDROID ANativeWindow_setBuffersGeometry(window, width, height, nFmt); @@ -146,10 +144,12 @@ void GLES2Swapchain::doCreateSurface(void* windowHandle) { NativeLayerHandle(window, SET_FORMAT, nFmt); #endif - EGL_CHECK(_gpuSwapchain->eglSurface = eglCreateWindowSurface(context->eglDisplay, context->eglConfig, window, nullptr)); if (_gpuSwapchain->eglSurface == EGL_NO_SURFACE) { - CC_LOG_ERROR("Recreate window surface failed."); - return; + EGL_CHECK(_gpuSwapchain->eglSurface = eglCreateWindowSurface(context->eglDisplay, context->eglConfig, window, nullptr)); + if (_gpuSwapchain->eglSurface == EGL_NO_SURFACE) { + CC_LOG_ERROR("Recreate window surface failed."); + return; + } } context->makeCurrent(_gpuSwapchain, _gpuSwapchain); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp index 1dc2519431..a808dacc8e 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp @@ -79,7 +79,7 @@ void GLES2Texture::doDestroy() { } } -void GLES2Texture::doResize(uint width, uint height, uint size) { +void GLES2Texture::doResize(uint32_t width, uint32_t height, uint32_t size) { if (!_gpuTexture->memoryless) { GLES2Device::getInstance()->getMemoryStatus().textureSize -= _size; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.h b/native/cocos/renderer/gfx-gles2/GLES2Texture.h index 9d97a5870d..3b2bbc0e45 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.h @@ -44,7 +44,7 @@ protected: void doInit(const TextureInfo &info) override; void doInit(const TextureViewInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, uint size) override; + void doResize(uint32_t width, uint32_t height, uint32_t size) override; void doInit(const SwapchainTextureInfo &info) override; GLES2GPUTexture *_gpuTexture = nullptr; diff --git a/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp b/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp index 82ff2cfd35..c84a0ca16b 100644 --- a/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp +++ b/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.cpp @@ -30,7 +30,7 @@ namespace cc { namespace gfx { -GLES2Sampler::GLES2Sampler(const SamplerInfo &info) : Sampler(info) { +GLES2Sampler::GLES2Sampler(const SamplerInfo &info, uint32_t hash) : Sampler(info, hash) { _typedID = generateObjectID(); _gpuSampler = CC_NEW(GLES2GPUSampler); diff --git a/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.h b/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.h index efe99dea96..ec0c62e3bd 100644 --- a/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.h +++ b/native/cocos/renderer/gfx-gles2/states/GLES2Sampler.h @@ -36,7 +36,7 @@ class GLES2GPUSampler; class CC_GLES2_API GLES2Sampler final : public Sampler { public: - explicit GLES2Sampler(const SamplerInfo &info); + GLES2Sampler(const SamplerInfo &info, uint32_t hash); ~GLES2Sampler() override; inline GLES2GPUSampler *gpuSampler() const { return _gpuSampler; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp index fa85e62113..c23e3ec213 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp @@ -82,7 +82,7 @@ void GLES3Buffer::doDestroy() { } } -void GLES3Buffer::doResize(uint size, uint count) { +void GLES3Buffer::doResize(uint32_t size, uint32_t count) { GLES3Device::getInstance()->getMemoryStatus().bufferSize -= _size; _gpuBuffer->size = size; @@ -92,7 +92,7 @@ void GLES3Buffer::doResize(uint size, uint count) { GLES3Device::getInstance()->getMemoryStatus().bufferSize += size; } -void GLES3Buffer::update(const void *buffer, uint size) { +void GLES3Buffer::update(const void *buffer, uint32_t size) { cmdFuncGLES3UpdateBuffer(GLES3Device::getInstance(), _gpuBuffer, buffer, 0U, size); } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Buffer.h b/native/cocos/renderer/gfx-gles3/GLES3Buffer.h index 6d3696ed51..1835b3051e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Buffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Buffer.h @@ -38,7 +38,7 @@ public: GLES3Buffer(); ~GLES3Buffer() override; - void update(const void *buffer, uint size) override; + void update(const void *buffer, uint32_t size) override; inline GLES3GPUBuffer *gpuBuffer() const { return _gpuBuffer; } @@ -46,7 +46,7 @@ protected: void doInit(const BufferInfo &info) override; void doInit(const BufferViewInfo &info) override; void doDestroy() override; - void doResize(uint size, uint count) override; + void doResize(uint32_t size, uint32_t count) override; GLES3GPUBuffer *_gpuBuffer = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index c655deed88..b079b93915 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -81,7 +81,7 @@ void GLES3CommandBuffer::doDestroy() { CC_SAFE_DELETE(_cmdAllocator); } -void GLES3CommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { +void GLES3CommandBuffer::begin(RenderPass * /*renderPass*/, uint32_t /*subpass*/, Framebuffer * /*frameBuffer*/) { _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); @@ -107,7 +107,7 @@ void GLES3CommandBuffer::end() { } } -void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { +void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const * /*secondaryCBs*/, uint32_t /*secondaryCBCount*/) { _curSubpassIdx = 0U; GLES3CmdBeginRenderPass *cmd = _cmdAllocator->beginRenderPassCmdPool.alloc(); @@ -123,7 +123,7 @@ void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fb _curCmdPackage->cmds.push(GLESCmdType::BEGIN_RENDER_PASS); _curDynamicStates.viewport = {renderArea.x, renderArea.y, renderArea.width, renderArea.height}; - _curDynamicStates.scissor = renderArea; + _curDynamicStates.scissor = renderArea; } void GLES3CommandBuffer::endRenderPass() { @@ -146,7 +146,7 @@ void GLES3CommandBuffer::bindPipelineState(PipelineState *pso) { } } -void GLES3CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { +void GLES3CommandBuffer::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) { CCASSERT(_curGPUDescriptorSets.size() > set, "Invalid set index"); GLES3GPUDescriptorSet *gpuDescriptorSet = static_cast(descriptorSet)->gpuDescriptorSet(); @@ -227,7 +227,7 @@ void GLES3CommandBuffer::setDepthBound(float minBounds, float maxBounds) { } } -void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { +void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint32_t mask) { auto update = [&](DynamicStencilStates &stencilState) { if (stencilState.writeMask != mask) { stencilState.writeMask = mask; @@ -238,7 +238,7 @@ void GLES3CommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { if (hasFlag(face, StencilFace::BACK)) update(_curDynamicStates.stencilStatesBack); } -void GLES3CommandBuffer::setStencilCompareMask(StencilFace face, uint ref, uint mask) { +void GLES3CommandBuffer::setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) { auto update = [&](DynamicStencilStates &stencilState) { if ((stencilState.reference != ref) || (stencilState.compareMask != mask)) { @@ -264,7 +264,7 @@ void GLES3CommandBuffer::draw(const DrawInfo &info) { ++_numDrawCalls; _numInstances += info.instanceCount; if (_curGPUPipelineState) { - uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; + uint32_t indexCount = info.indexCount ? info.indexCount : info.vertexCount; switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); @@ -281,7 +281,7 @@ void GLES3CommandBuffer::draw(const DrawInfo &info) { } } -void GLES3CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +void GLES3CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint32_t size) { GLES3GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { GLES3CmdUpdateBuffer *cmd = _cmdAllocator->updateBufferCmdPool.alloc(); @@ -294,7 +294,7 @@ void GLES3CommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) } } -void GLES3CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void GLES3CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { GLES3CmdBlitTexture *cmd = _cmdAllocator->blitTextureCmdPool.alloc(); if (srcTexture) cmd->gpuTextureSrc = static_cast(srcTexture)->gpuTexture(); if (dstTexture) cmd->gpuTextureDst = static_cast(dstTexture)->gpuTexture(); @@ -306,7 +306,7 @@ void GLES3CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, c _curCmdPackage->cmds.push(GLESCmdType::BLIT_TEXTURE); } -void GLES3CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void GLES3CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { GLES3GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { GLES3CmdCopyBufferToTexture *cmd = _cmdAllocator->copyBufferToTextureCmdPool.alloc(); @@ -323,46 +323,46 @@ void GLES3CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Tex void GLES3CommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { CCASSERT(false, "Command 'execute' must be recorded in primary command buffers."); - for (uint i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { auto * cmdBuff = static_cast(cmdBuffs[i]); GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - for (uint j = 0; j < cmdPackage->beginRenderPassCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->beginRenderPassCmds.size(); ++j) { GLES3CmdBeginRenderPass *cmd = cmdPackage->beginRenderPassCmds[j]; ++cmd->refCount; _curCmdPackage->beginRenderPassCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->bindStatesCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->bindStatesCmds.size(); ++j) { GLES3CmdBindStates *cmd = cmdPackage->bindStatesCmds[j]; ++cmd->refCount; _curCmdPackage->bindStatesCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->drawCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->drawCmds.size(); ++j) { GLES3CmdDraw *cmd = cmdPackage->drawCmds[j]; ++cmd->refCount; _curCmdPackage->drawCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->dispatchCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->dispatchCmds.size(); ++j) { GLES3CmdDispatch *cmd = cmdPackage->dispatchCmds[j]; ++cmd->refCount; _curCmdPackage->dispatchCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->barrierCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->barrierCmds.size(); ++j) { GLES3CmdBarrier *cmd = cmdPackage->barrierCmds[j]; ++cmd->refCount; _curCmdPackage->barrierCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->updateBufferCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->updateBufferCmds.size(); ++j) { GLES3CmdUpdateBuffer *cmd = cmdPackage->updateBufferCmds[j]; ++cmd->refCount; _curCmdPackage->updateBufferCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->copyBufferToTextureCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->copyBufferToTextureCmds.size(); ++j) { GLES3CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[j]; ++cmd->refCount; _curCmdPackage->copyBufferToTextureCmds.push(cmd); } - for (uint j = 0; j < cmdPackage->blitTextureCmds.size(); ++j) { + for (uint32_t j = 0; j < cmdPackage->blitTextureCmds.size(); ++j) { GLES3CmdBlitTexture *cmd = cmdPackage->blitTextureCmds[j]; ++cmd->refCount; _curCmdPackage->blitTextureCmds.push(cmd); @@ -390,13 +390,13 @@ void GLES3CommandBuffer::bindStates() { cmd->gpuDescriptorSets = _curGPUDescriptorSets; if (_curGPUPipelineState) { - vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; + vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; cmd->dynamicOffsets.resize(_curGPUPipelineState->gpuPipelineLayout->dynamicOffsetCount); for (size_t i = 0U; i < _curDynamicOffsets.size(); i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); - if (count) memcpy(&cmd->dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); + if (count) memcpy(&cmd->dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint32_t)); } } cmd->dynamicStates = _curDynamicStates; @@ -424,7 +424,7 @@ void GLES3CommandBuffer::dispatch(const DispatchInfo &info) { _curCmdPackage->cmds.push(GLESCmdType::DISPATCH); } -void GLES3CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const * /*textureBarriers*/, const Texture *const * /*textures*/, uint /*textureBarrierCount*/) { +void GLES3CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const * /*textureBarriers*/, const Texture *const * /*textures*/, uint32_t /*textureBarrierCount*/) { if (!barrier) return; const auto *gpuBarrier = static_cast(barrier)->gpuBarrier(); diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index 4924fa6a78..cefd9198db 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -42,12 +42,12 @@ public: GLES3CommandBuffer(); ~GLES3CommandBuffer() override; - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void bindPipelineState(PipelineState *pso) override; - void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override; void bindInputAssembler(InputAssembler *ia) override; void setViewport(const Viewport &vp) override; void setScissor(const Rect &rect) override; @@ -55,16 +55,16 @@ public: void setDepthBias(float constant, float clamp, float slope) override; void setBlendConstants(const Color &constants) override; void setDepthBound(float minBounds, float maxBounds) override; - void setStencilWriteMask(StencilFace face, uint mask) override; - void setStencilCompareMask(StencilFace face, uint ref, uint mask) override; + void setStencilWriteMask(StencilFace face, uint32_t mask) override; + void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override; - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override; protected: friend class GLES3Queue; @@ -78,11 +78,11 @@ protected: GLES3CmdPackage * _curCmdPackage = nullptr; queue _pendingPackages, _freePackages; - uint _curSubpassIdx = 0U; + uint32_t _curSubpassIdx = 0U; GLES3GPUPipelineState * _curGPUPipelineState = nullptr; GLES3GPUInputAssembler * _curGPUInputAssember = nullptr; vector _curGPUDescriptorSets; - vector> _curDynamicOffsets; + vector> _curDynamicOffsets; DynamicStates _curDynamicStates; bool _isStateInvalid = false; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp index e80eec49bd..89a1eb1433 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.cpp @@ -27,12 +27,11 @@ #include "GLES3Commands.h" #include "GLES3Device.h" -#include "gfx-gles-common/gles3w.h" -#include "gfx-gles3/GLES3GPUObjects.h" +#include "gfx-base/GFXDef-common.h" #define BUFFER_OFFSET(idx) (static_cast(0) + (idx)) -constexpr uint USE_VAO = true; +constexpr uint32_t USE_VAO = true; namespace cc { namespace gfx { @@ -487,7 +486,7 @@ GLenum formatToGLType(Format format) { } } -uint glTypeSize(GLenum glType) { +uint32_t glTypeSize(GLenum glType) { switch (glType) { case GL_BOOL: return 4; case GL_BOOL_VEC2: return 8; @@ -534,7 +533,7 @@ uint glTypeSize(GLenum glType) { } } -uint glComponentCount(GLenum glType) { +uint32_t glComponentCount(GLenum glType) { switch (glType) { case GL_FLOAT_MAT2: case GL_FLOAT_MAT2x3: @@ -874,16 +873,6 @@ void cmdFuncGLES3CreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) } } - // memoryless resources for PLS-based input attachments - // enabled only if FBF is not available - if (device->constantRegistry()->mFBF == FBFSupportLevel::NONE && - device->constantRegistry()->mPLS != PLSSupportLevel::NONE && - hasFlag(gpuTexture->usage, TextureUsageBit::INPUT_ATTACHMENT) && - hasAllFlags(MEMORYLESS, gpuTexture->usage)) { - gpuTexture->memoryless = true; - return; - } - if (gpuTexture->glTexture) { gpuTexture->glTarget = GL_TEXTURE_EXTERNAL_OES; return; @@ -900,18 +889,18 @@ void cmdFuncGLES3CreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_2D, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - uint w = gpuTexture->width; - uint h = gpuTexture->height; + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; if (hasFlag(gpuTexture->flags, TextureFlagBit::RESIZABLE)) { if (!GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].isCompressed) { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } else { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -932,21 +921,21 @@ void cmdFuncGLES3CreateTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_CUBE_MAP, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - uint w = gpuTexture->width; - uint h = gpuTexture->height; + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; if (hasFlag(gpuTexture->flags, TextureFlagBit::RESIZABLE)) { if (!GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].isCompressed) { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - for (uint f = 0; f < 6; ++f) { + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t f = 0; f < 6; ++f) { GL_CHECK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); } w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } else { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); - for (uint f = 0; f < 6; ++f) { + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t f = 0; f < 6; ++f) { GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); } w = std::max(1U, w >> 1); @@ -1021,17 +1010,17 @@ void cmdFuncGLES3ResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) GL_CHECK(glBindTexture(GL_TEXTURE_2D, gpuTexture->glTexture)); glTexture = gpuTexture->glTexture; } - uint w = gpuTexture->width; - uint h = gpuTexture->height; + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; if (!GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].isCompressed) { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } else { - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_2D, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -1048,21 +1037,21 @@ void cmdFuncGLES3ResizeTexture(GLES3Device *device, GLES3GPUTexture *gpuTexture) glTexture = gpuTexture->glTexture; } if (!GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].isCompressed) { - for (uint f = 0; f < 6; ++f) { - uint w = gpuTexture->width; - uint h = gpuTexture->height; - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { + for (uint32_t f = 0; f < 6; ++f) { + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { GL_CHECK(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, gpuTexture->glFormat, gpuTexture->glType, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); } } } else { - for (uint f = 0; f < 6; ++f) { - uint w = gpuTexture->width; - uint h = gpuTexture->height; - for (uint i = 0; i < gpuTexture->mipLevel; ++i) { - uint imgSize = formatSize(gpuTexture->format, w, h, 1); + for (uint32_t f = 0; f < 6; ++f) { + uint32_t w = gpuTexture->width; + uint32_t h = gpuTexture->height; + for (uint32_t i = 0; i < gpuTexture->mipLevel; ++i) { + uint32_t imgSize = formatSize(gpuTexture->format, w, h, 1); GL_CHECK(glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, i, gpuTexture->glInternalFmt, w, h, 0, imgSize, nullptr)); w = std::max(1U, w >> 1); h = std::max(1U, h >> 1); @@ -1146,6 +1135,7 @@ void cmdFuncGLES3DestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler } } +// NOLINTNEXTLINE(google-readability-function-size, readability-function-size) void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { GLenum glShaderStage = 0; String shaderStageStr; @@ -1177,7 +1167,7 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } GL_CHECK(gpuStage.glShader = glCreateShader(glShaderStage)); - uint version = device->constantRegistry()->glMinorVersion ? 310 : 300; + uint32_t version = device->constantRegistry()->glMinorVersion ? 310 : 300; String shaderSource = StringUtil::format("#version %u es\n", version) + gpuStage.source; const char *source = shaderSource.c_str(); GL_CHECK(glShaderSource(gpuStage.glShader, 1, (const GLchar **)&source, nullptr)); @@ -1334,9 +1324,8 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } } - // fallback subpassInputs into samplerTextures if not using FBF or PLS - if (device->constantRegistry()->mFBF == FBFSupportLevel::NONE && - device->constantRegistry()->mPLS == PLSSupportLevel::NONE) { + // fallback subpassInputs into samplerTextures if not using FBF + if (device->constantRegistry()->mFBF == FBFSupportLevel::NONE) { for (const auto &subpassInput : gpuShader->subpassInputs) { auto &samplerTexture = gpuShader->samplerTextures.emplace_back(); samplerTexture.name = subpassInput.name; @@ -1368,20 +1357,20 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { vector glActiveSamplerTextures; vector glActiveSamplerLocations; const BindingMappingInfo & bindingMappingInfo = device->bindingMappingInfo(); - unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; + unordered_map & texUnitCacheMap = device->stateCache()->texUnitCacheMap; // sampler bindings in the flexible set comes strictly after buffer bindings // so we need to subtract the buffer count for these samplers - uint flexibleSetBaseOffset = 0U; + uint32_t flexibleSetBaseOffset = 0U; for (GLES3GPUUniformBuffer &buffer : gpuShader->glBuffers) { if (buffer.set == bindingMappingInfo.flexibleSet) { flexibleSetBaseOffset++; } } - uint arrayOffset = 0U; + uint32_t arrayOffset = 0U; - for (uint i = 0U; i < gpuShader->samplerTextures.size(); i++) { + for (uint32_t i = 0U; i < gpuShader->samplerTextures.size(); i++) { const UniformSamplerTexture &samplerTexture = gpuShader->samplerTextures[i]; GLint glLoc = -1; GL_CHECK(glLoc = glGetUniformLocation(gpuShader->glProgram, samplerTexture.name.c_str())); @@ -1390,7 +1379,7 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { glActiveSamplerLocations.push_back(glLoc); if (texUnitCacheMap.count(samplerTexture.name) == 0U) { - uint binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; + uint32_t binding = samplerTexture.binding + bindingMappingInfo.samplerOffsets[samplerTexture.set] + arrayOffset; if (samplerTexture.set == bindingMappingInfo.flexibleSet) binding -= flexibleSetBaseOffset; texUnitCacheMap[samplerTexture.name] = binding % device->getCapabilities().maxTextureUnits; arrayOffset += samplerTexture.count - 1; @@ -1401,13 +1390,13 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { if (!glActiveSamplerTextures.empty()) { vector usedTexUnits(device->getCapabilities().maxTextureUnits, false); // try to reuse existing mappings first - for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { + for (uint32_t i = 0U; i < glActiveSamplerTextures.size(); i++) { GLES3GPUUniformSamplerTexture &glSamplerTexture = glActiveSamplerTextures[i]; if (texUnitCacheMap.count(glSamplerTexture.name)) { - uint cachedUnit = texUnitCacheMap[glSamplerTexture.name]; + uint32_t cachedUnit = texUnitCacheMap[glSamplerTexture.name]; glSamplerTexture.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U; t < glSamplerTexture.count; t++) { + for (uint32_t t = 0U; t < glSamplerTexture.count; t++) { while (usedTexUnits[cachedUnit]) { // the shader already compiles so we should be safe to do this here cachedUnit = (cachedUnit + 1) % device->getCapabilities().maxTextureUnits; } @@ -1417,13 +1406,13 @@ void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } } // fill in the rest sequencially - uint unitIdx = 0U; - for (uint i = 0U; i < glActiveSamplerTextures.size(); i++) { + uint32_t unitIdx = 0U; + for (uint32_t i = 0U; i < glActiveSamplerTextures.size(); i++) { GLES3GPUUniformSamplerTexture &glSamplerTexture = glActiveSamplerTextures[i]; if (glSamplerTexture.glLoc < 0) { glSamplerTexture.glLoc = glActiveSamplerLocations[i]; - for (uint t = 0U; t < glSamplerTexture.count; t++) { + for (uint32_t t = 0U; t < glSamplerTexture.count; t++) { while (usedTexUnits[unitIdx]) { unitIdx = (unitIdx + 1) % device->getCapabilities().maxTextureUnits; } @@ -1487,6 +1476,54 @@ void cmdFuncGLES3DestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader) { } } +void cmdFuncGLES3CreateRenderPass(GLES3Device * /*device*/, GLES3GPURenderPass *gpuRenderPass) { + // calculate the life cycle of each attachments + auto updateLifeCycle = [](GLES3GPURenderPass::AttachmentStatistics &statistics, uint32_t index) { + if (statistics.loadSubpass == SUBPASS_EXTERNAL) statistics.loadSubpass = index; + statistics.storeSubpass = index; + }; + auto calculateLifeCycle = [&](GLES3GPURenderPass::AttachmentStatistics &statistics, uint32_t targetAttachment) { + for (size_t j = 0U; j < gpuRenderPass->subpasses.size(); ++j) { + auto &subpass = gpuRenderPass->subpasses[j]; + for (size_t k = 0U; k < subpass.colors.size(); ++k) { + if (subpass.colors[k] == targetAttachment) { + updateLifeCycle(statistics, j); + } + if (!subpass.resolves.empty() && subpass.resolves[k] == targetAttachment) { + updateLifeCycle(statistics, j); + } + } + for (unsigned int input : subpass.inputs) { + if (input == targetAttachment) { + updateLifeCycle(statistics, j); + } + } + if (subpass.depthStencil == targetAttachment) { + updateLifeCycle(statistics, j); + } + if (subpass.depthStencilResolve == targetAttachment) { + updateLifeCycle(statistics, j); + } + } + }; + + bool hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN; + gpuRenderPass->statistics.resize(gpuRenderPass->colorAttachments.size() + hasDepth); + for (size_t i = 0U; i < gpuRenderPass->statistics.size(); ++i) { + calculateLifeCycle(gpuRenderPass->statistics[i], i); + CC_ASSERT(gpuRenderPass->statistics[i].loadSubpass != SUBPASS_EXTERNAL && + gpuRenderPass->statistics[i].storeSubpass != SUBPASS_EXTERNAL); + } + + // should deduce this from subpass & attachment access infos + gpuRenderPass->barriers.resize(gpuRenderPass->subpasses.size() + 1); +} + +void cmdFuncGLES3DestroyRenderPass(GLES3Device * /*device*/, GLES3GPURenderPass *gpuRenderPass) { + gpuRenderPass->statistics.clear(); + gpuRenderPass->barriers.clear(); +} + void cmdFuncGLES3CreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler) { if (gpuInputAssembler->gpuIndexBuffer) { switch (gpuInputAssembler->gpuIndexBuffer->stride) { @@ -1499,7 +1536,7 @@ void cmdFuncGLES3CreateInputAssembler(GLES3Device *device, GLES3GPUInputAssemble } } - vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0U); + vector streamOffsets(device->getCapabilities().maxVertexAttributes, 0U); gpuInputAssembler->glAttribs.resize(gpuInputAssembler->attributes.size()); for (size_t i = 0; i < gpuInputAssembler->glAttribs.size(); ++i) { @@ -1538,9 +1575,9 @@ void cmdFuncGLES3DestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembl } static GLuint doCreateFramebuffer(GLES3Device * device, - const vector &attachments, const uint *colors, size_t colorCount, + const vector &attachments, const uint32_t *colors, size_t colorCount, const GLES3GPUTexture *depthStencil, - const uint * resolves = nullptr, + const uint32_t * resolves = nullptr, const GLES3GPUTexture *depthStencilResolve = nullptr, GLbitfield * resolveMask = nullptr) { static vector drawBuffers; @@ -1644,9 +1681,9 @@ static GLES3GPUSwapchain *getSwapchainIfExists(const vector & return swapchain; } -static void doCreateFramebufferInstance(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO, const vector &colors, - uint depthStencil, GLES3GPUFramebuffer::Framebuffer *outFBO, - const uint *resolves = nullptr, uint depthStencilResolve = INVALID_BINDING) { +static void doCreateFramebufferInstance(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO, const vector &colors, + uint32_t depthStencil, GLES3GPUFramebuffer::Framebuffer *outFBO, + const uint32_t *resolves = nullptr, uint32_t depthStencilResolve = INVALID_BINDING) { GLES3GPUSwapchain *swapchain{getSwapchainIfExists(gpuFBO->gpuColorTextures, colors.data(), colors.size())}; if (!swapchain) { const GLES3GPUTexture *depthStencilTexture = nullptr; @@ -1681,20 +1718,30 @@ static void doCreateFramebufferInstance(GLES3Device *device, GLES3GPUFramebuffer void cmdFuncGLES3CreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO) { if (gpuFBO->gpuRenderPass->subpasses.size() > 1) { gpuFBO->usesFBF = device->constantRegistry()->mFBF != FBFSupportLevel::NONE; - gpuFBO->usesPLS = std::any_of(gpuFBO->gpuColorTextures.begin(), gpuFBO->gpuColorTextures.end(), [](const auto *gpuTexture) { - return gpuTexture && gpuTexture->memoryless; - }); } - if (gpuFBO->usesFBF || gpuFBO->usesPLS) { + if (gpuFBO->usesFBF) { + for (auto &subpass : gpuFBO->gpuRenderPass->subpasses) { + if (subpass.inputs.size() == 4) { + gpuFBO->uberOnChipOutput = subpass.inputs.back(); + gpuFBO->uberFinalOutput = subpass.colors.back(); + break; + } + } + gpuFBO->uberColorAttachmentIndices.clear(); - for (uint i = 0U; i < gpuFBO->gpuColorTextures.size(); ++i) { + bool hasDepth{gpuFBO->gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN}; + gpuFBO->uberDepthStencil = hasDepth ? gpuFBO->gpuColorTextures.size() : INVALID_BINDING; + for (uint32_t i = 0U; i < gpuFBO->gpuColorTextures.size(); ++i) { + if (i == gpuFBO->uberFinalOutput) continue; const auto *gpuTexture = gpuFBO->gpuColorTextures[i]; - if (!gpuTexture || gpuTexture->memoryless) continue; - if (GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].hasDepth) continue; + if (GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].hasDepth) { + gpuFBO->uberDepthStencil = i; + continue; + } gpuFBO->uberColorAttachmentIndices.push_back(i); } - doCreateFramebufferInstance(device, gpuFBO, gpuFBO->uberColorAttachmentIndices, utils::toUint(gpuFBO->gpuColorTextures.size()), &gpuFBO->uberInstance); + doCreateFramebufferInstance(device, gpuFBO, gpuFBO->uberColorAttachmentIndices, gpuFBO->uberDepthStencil, &gpuFBO->uberInstance); } else { for (const auto &subpass : gpuFBO->gpuRenderPass->subpasses) { doCreateFramebufferInstance(device, gpuFBO, subpass.colors, subpass.depthStencil, &gpuFBO->instances.emplace_back(), @@ -1813,10 +1860,9 @@ void cmdFuncGLES3CreateGlobalBarrier(const std::vector &prevAccesses } } -void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPURenderPass *gpuRenderPass, +void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3GPURenderPass *gpuRenderPass, GLES3GPUFramebuffer *gpuFramebuffer, const Rect *renderArea, - const Color *clearColors, float clearDepth, uint clearStencil) { - static uint attachmentLoadOpRecord = 0U; + const Color *clearColors, float clearDepth, uint32_t clearStencil) { static vector invalidAttachments; GLES3GPUStateCache *cache = device->stateCache(); @@ -1836,11 +1882,10 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPUR gfxStateCache.clearColors.assign(clearColors, clearColors + gpuRenderPass->colorAttachments.size()); gfxStateCache.clearDepth = clearDepth; gfxStateCache.clearStencil = clearStencil; - attachmentLoadOpRecord = 0U; } if (gpuFramebuffer && gpuRenderPass) { - auto &instance = gpuFramebuffer->usesPLS || gpuFramebuffer->usesFBF ? gpuFramebuffer->uberInstance : gpuFramebuffer->instances[subpassIdx]; + auto &instance = gpuFramebuffer->usesFBF ? gpuFramebuffer->uberInstance : gpuFramebuffer->instances[subpassIdx]; GLuint glFramebuffer = instance.framebuffer.getFramebuffer(); device->context()->makeCurrent(instance.framebuffer.swapchain, instance.framebuffer.swapchain); @@ -1850,36 +1895,39 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPUR cache->glDrawFramebuffer = glFramebuffer; } - if (cache->viewport.left != renderArea->x || - cache->viewport.top != renderArea->y || - cache->viewport.width != renderArea->width || - cache->viewport.height != renderArea->height) { - GL_CHECK(glViewport(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); - cache->viewport.left = renderArea->x; - cache->viewport.top = renderArea->y; - cache->viewport.width = renderArea->width; - cache->viewport.height = renderArea->height; - } + if (subpassIdx == 0) { + if (cache->viewport.left != renderArea->x || + cache->viewport.top != renderArea->y || + cache->viewport.width != renderArea->width || + cache->viewport.height != renderArea->height) { + GL_CHECK(glViewport(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); + cache->viewport.left = renderArea->x; + cache->viewport.top = renderArea->y; + cache->viewport.width = renderArea->width; + cache->viewport.height = renderArea->height; + } - if (cache->scissor.x != renderArea->x || - cache->scissor.y != renderArea->y || - cache->scissor.width != renderArea->width || - cache->scissor.height != renderArea->height) { - GL_CHECK(glScissor(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); - cache->scissor.x = renderArea->x; - cache->scissor.y = renderArea->y; - cache->scissor.width = renderArea->width; - cache->scissor.height = renderArea->height; + if (cache->scissor.x != renderArea->x || + cache->scissor.y != renderArea->y || + cache->scissor.width != renderArea->width || + cache->scissor.height != renderArea->height) { + GL_CHECK(glScissor(renderArea->x, renderArea->y, renderArea->width, renderArea->height)); + cache->scissor.x = renderArea->x; + cache->scissor.y = renderArea->y; + cache->scissor.width = renderArea->width; + cache->scissor.height = renderArea->height; + } } GLbitfield glClears = 0; invalidAttachments.clear(); - static const Color ZERO; - float fColors[4]{}; - bool maskSet = false; + float fColors[4]{}; + bool maskSet = false; + + auto performLoadOp = [&](uint32_t attachmentIndex, uint32_t glAttachmentIndex) { + if (attachmentIndex == gpuFramebuffer->uberOnChipOutput) attachmentIndex = gpuFramebuffer->uberFinalOutput; - auto performLoadOp = [&](uint attachmentIndex, uint glAttachmentIndex, bool clearToZero) { const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[attachmentIndex]; if (colorAttachment.format != Format::UNKNOWN) { switch (colorAttachment.loadOp) { @@ -1890,7 +1938,7 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPUR maskSet = true; } - const Color &color = clearToZero ? ZERO : clearColors[attachmentIndex]; + const Color &color = clearColors[attachmentIndex]; if (glFramebuffer) { fColors[0] = color.x; fColors[1] = color.y; @@ -1910,11 +1958,15 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPUR } }; - auto performDepthStencilLoadOp = [&]() { - if (gpuRenderPass->depthStencilAttachment.format == Format::UNKNOWN) return; - - bool hasDepth = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasDepth; - if (hasDepth) { + auto performDepthStencilLoadOp = [&](uint32_t attachmentIndex, bool skipLoad) { + if (attachmentIndex != INVALID_BINDING && !skipLoad) { + LoadOp depthLoadOp = gpuRenderPass->depthStencilAttachment.depthLoadOp; + LoadOp stencilLoadOp = gpuRenderPass->depthStencilAttachment.stencilLoadOp; + bool hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)].hasStencil; + if (attachmentIndex < gpuRenderPass->colorAttachments.size()) { + depthLoadOp = stencilLoadOp = gpuRenderPass->colorAttachments[attachmentIndex].loadOp; + hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->colorAttachments[attachmentIndex].format)].hasStencil; + } switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { case LoadOp::LOAD: break; // GL default behaviour case LoadOp::CLEAR: @@ -1928,24 +1980,23 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPUR invalidAttachments.push_back(glFramebuffer ? GL_DEPTH_ATTACHMENT : GL_DEPTH); break; } - } - bool hasStencils = GFX_FORMAT_INFOS[static_cast(gpuRenderPass->depthStencilAttachment.format)].hasStencil; - if (hasStencils) { - switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { - case LoadOp::LOAD: break; // GL default behaviour - case LoadOp::CLEAR: { - if (!cache->dss.stencilWriteMaskFront) { - GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff)); - } - if (!cache->dss.stencilWriteMaskBack) { - GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff)); - } - GL_CHECK(glClearStencil(clearStencil)); - glClears |= GL_STENCIL_BUFFER_BIT; - } break; - case LoadOp::DISCARD: - invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL); - break; + if (hasStencils) { + switch (gpuRenderPass->depthStencilAttachment.depthLoadOp) { + case LoadOp::LOAD: break; // GL default behaviour + case LoadOp::CLEAR: { + if (!cache->dss.stencilWriteMaskFront) { + GL_CHECK(glStencilMaskSeparate(GL_FRONT, 0xffffffff)); + } + if (!cache->dss.stencilWriteMaskBack) { + GL_CHECK(glStencilMaskSeparate(GL_BACK, 0xffffffff)); + } + GL_CHECK(glClearStencil(clearStencil)); + glClears |= GL_STENCIL_BUFFER_BIT; + } break; + case LoadOp::DISCARD: + invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL); + break; + } } } @@ -1980,30 +2031,25 @@ void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, GLES3GPUR } }; - uint glAttachmentIndex = 0U; - if (gpuFramebuffer->usesPLS || gpuFramebuffer->usesFBF) { + uint32_t glAttachmentIndex = 0U; + if (gpuFramebuffer->usesFBF) { if (subpassIdx == 0) { cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->barriers[0].glBarriers, gpuRenderPass->barriers[0].glBarriersByRegion); - if (gpuFramebuffer->usesPLS) { - GL_CHECK(glEnable(GL_SHADER_PIXEL_LOCAL_STORAGE_EXT)); - cache->isPLSEnabled = true; - } - for (const auto attachmentIndex : gpuFramebuffer->uberColorAttachmentIndices) { - performLoadOp(attachmentIndex, glAttachmentIndex++, gpuFramebuffer->usesPLS); + performLoadOp(attachmentIndex, glAttachmentIndex++); } - performDepthStencilLoadOp(); + performDepthStencilLoadOp(gpuFramebuffer->uberDepthStencil, false); } } else { cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->barriers[subpassIdx].glBarriers, gpuRenderPass->barriers[subpassIdx].glBarriersByRegion); for (const auto attachmentIndex : gpuRenderPass->subpasses[subpassIdx].colors) { - if (attachmentLoadOpRecord & (1 << attachmentIndex)) continue; - performLoadOp(attachmentIndex, glAttachmentIndex++, false); - attachmentLoadOpRecord |= 1 << attachmentIndex; + if (gpuRenderPass->statistics[attachmentIndex].loadSubpass != subpassIdx) continue; + performLoadOp(attachmentIndex, glAttachmentIndex++); } - performDepthStencilLoadOp(); + auto depthIndex = gpuRenderPass->subpasses[subpassIdx].depthStencil; + performDepthStencilLoadOp(depthIndex, gpuRenderPass->statistics[depthIndex].loadSubpass != subpassIdx); } } } @@ -2028,7 +2074,7 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { GLES3ObjectCache & gfxStateCache = cache->gfxStateCache; GLES3GPURenderPass * gpuRenderPass = gfxStateCache.gpuRenderPass; GLES3GPUFramebuffer *gpuFramebuffer = gfxStateCache.gpuFramebuffer; - const auto & instance = gpuFramebuffer->usesPLS || gpuFramebuffer->usesFBF ? gpuFramebuffer->uberInstance : gpuFramebuffer->instances[gfxStateCache.subpassIdx]; + const auto & instance = gpuFramebuffer->usesFBF ? gpuFramebuffer->uberInstance : gpuFramebuffer->instances[gfxStateCache.subpassIdx]; const SubpassInfo & subpass = gpuRenderPass->subpasses[gfxStateCache.subpassIdx]; bool isTheLastSubpass = gfxStateCache.subpassIdx == gpuRenderPass->subpasses.size() - 1; GLuint glFramebuffer = instance.framebuffer.getFramebuffer(); @@ -2037,7 +2083,9 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { invalidAttachments.clear(); - auto performStoreOp = [&](uint attachmentIndex, uint glAttachmentIndex) { + auto performStoreOp = [&](uint32_t attachmentIndex, uint32_t glAttachmentIndex) { + if (attachmentIndex == gpuFramebuffer->uberOnChipOutput) attachmentIndex = gpuFramebuffer->uberFinalOutput; + const ColorAttachment &colorAttachment = gpuRenderPass->colorAttachments[attachmentIndex]; if (colorAttachment.format != Format::UNKNOWN) { switch (colorAttachment.storeOp) { @@ -2050,26 +2098,32 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { } }; - auto performDepthStencilStoreOp = [&]() { - if (gpuRenderPass->depthStencilAttachment.format == Format::UNKNOWN) return; + auto performDepthStencilStoreOp = [&](uint32_t attachmentIndex, bool skipStore) { + if (attachmentIndex != INVALID_BINDING && !skipStore) { + StoreOp depthStoreOp = gpuRenderPass->depthStencilAttachment.depthStoreOp; + StoreOp stencilStoreOp = gpuRenderPass->depthStencilAttachment.stencilStoreOp; + bool hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)].hasStencil; + if (attachmentIndex < gpuRenderPass->colorAttachments.size()) { + depthStoreOp = stencilStoreOp = gpuRenderPass->colorAttachments[attachmentIndex].storeOp; + hasStencils = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->colorAttachments[attachmentIndex].format)].hasStencil; + } - const auto &formatInfo = GFX_FORMAT_INFOS[toNumber(gpuRenderPass->depthStencilAttachment.format)]; - if (formatInfo.hasDepth) { switch (gpuRenderPass->depthStencilAttachment.depthStoreOp) { case StoreOp::STORE: break; case StoreOp::DISCARD: invalidAttachments.push_back(glFramebuffer ? GL_DEPTH_ATTACHMENT : GL_DEPTH); break; } - } - if (formatInfo.hasStencil) { - switch (gpuRenderPass->depthStencilAttachment.stencilStoreOp) { - case StoreOp::STORE: break; - case StoreOp::DISCARD: - invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL); - break; + if (hasStencils) { + switch (gpuRenderPass->depthStencilAttachment.stencilStoreOp) { + case StoreOp::STORE: break; + case StoreOp::DISCARD: + invalidAttachments.push_back(glFramebuffer ? GL_STENCIL_ATTACHMENT : GL_STENCIL); + break; + } } } + if (!invalidAttachments.empty()) { GL_CHECK(glInvalidateFramebuffer(invalidateTarget, utils::toUint(invalidAttachments.size()), invalidAttachments.data())); } @@ -2089,7 +2143,7 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { } if (instance.resolveMask & GL_COLOR_BUFFER_BIT) { - for (uint i = 0; i < subpass.colors.size(); ++i) { + for (uint32_t i = 0; i < subpass.colors.size(); ++i) { auto attachment = static_cast(GL_COLOR_ATTACHMENT0 + i); GL_CHECK(glReadBuffer(attachment)); GL_CHECK(glDrawBuffers(1, &attachment)); @@ -2123,16 +2177,21 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { invalidateTarget = GL_READ_FRAMEBUFFER; } - uint glAttachmentIndex = 0U; - if (gpuFramebuffer->usesPLS || gpuFramebuffer->usesFBF) { + uint32_t glAttachmentIndex = 0U; + if (gpuFramebuffer->usesFBF) { if (isTheLastSubpass) { for (const auto attachmentIndex : gpuFramebuffer->uberColorAttachmentIndices) { performStoreOp(attachmentIndex, glAttachmentIndex++); } - performDepthStencilStoreOp(); - if (cache->isPLSEnabled) { - GL_CHECK(glDisable(GL_SHADER_PIXEL_LOCAL_STORAGE_EXT)); - cache->isPLSEnabled = false; + performDepthStencilStoreOp(gpuFramebuffer->uberDepthStencil, false); + + if (gpuFramebuffer->uberOnChipOutput != INVALID_BINDING) { + TextureBlit region; + auto * blitSrc = gpuFramebuffer->gpuColorTextures[gpuFramebuffer->uberOnChipOutput]; + auto * blitDst = gpuFramebuffer->gpuColorTextures[gpuFramebuffer->uberFinalOutput]; + region.srcExtent.width = region.dstExtent.width = blitSrc->width; + region.srcExtent.height = region.dstExtent.height = blitSrc->height; + cmdFuncGLES3BlitTexture(device, blitSrc, blitDst, ®ion, 1, Filter::POINT); } cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->barriers.back().glBarriers, gpuRenderPass->barriers.back().glBarriersByRegion); @@ -2144,20 +2203,20 @@ void cmdFuncGLES3EndRenderPass(GLES3Device *device) { } } } else { - if (isTheLastSubpass) { - const auto &indices = subpass.resolves.empty() ? subpass.colors : subpass.resolves; - for (const auto attachmentIndex : indices) { - performStoreOp(attachmentIndex, glAttachmentIndex++); - } - performDepthStencilStoreOp(); - - cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->barriers.back().glBarriers, gpuRenderPass->barriers.back().glBarriersByRegion); + const auto &indices = subpass.resolves.empty() ? subpass.colors : subpass.resolves; + for (const auto attachmentIndex : indices) { + if (gpuRenderPass->statistics[attachmentIndex].storeSubpass != gfxStateCache.subpassIdx) continue; + performStoreOp(attachmentIndex, glAttachmentIndex++); } + performDepthStencilStoreOp(subpass.depthStencil, gpuRenderPass->statistics[subpass.depthStencil].loadSubpass != gfxStateCache.subpassIdx); + + cmdFuncGLES3MemoryBarrier(device, gpuRenderPass->barriers.back().glBarriers, gpuRenderPass->barriers.back().glBarriersByRegion); } } +// NOLINTNEXTLINE(google-readability-function-size, readability-function-size) void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipelineState, GLES3GPUInputAssembler *gpuInputAssembler, - const GLES3GPUDescriptorSet *const *gpuDescriptorSets, const uint *dynamicOffsets, const DynamicStates *dynamicStates) { + const GLES3GPUDescriptorSet *const *gpuDescriptorSets, const uint32_t *dynamicOffsets, const DynamicStates *dynamicStates) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; GLES3GPUStateCache *cache = device->stateCache(); @@ -2372,7 +2431,7 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const GLES3GPUUniformBuffer &glBuffer = gpuPipelineState->gpuShader->glBuffers[j]; const GLES3GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glBuffer.set]; - const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glBuffer.binding); + const uint32_t descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glBuffer.binding); const GLES3GPUDescriptor & gpuDescriptor = gpuDescriptorSet->gpuDescriptors[descriptorIndex]; if (!gpuDescriptor.gpuBuffer) { @@ -2381,7 +2440,7 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli continue; } - uint offset = gpuDescriptor.gpuBuffer->glOffset; + uint32_t offset = gpuDescriptor.gpuBuffer->glOffset; const vector &dynamicOffsetSetIndices = dynamicOffsetIndices[glBuffer.set]; int dynamicOffsetIndex = glBuffer.binding < dynamicOffsetSetIndices.size() ? dynamicOffsetSetIndices[glBuffer.binding] : -1; @@ -2422,11 +2481,11 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const GLES3GPUUniformSamplerTexture &glSamplerTexture = gpuPipelineState->gpuShader->glSamplerTextures[j]; const GLES3GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glSamplerTexture.set]; - const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glSamplerTexture.binding); + const uint32_t descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glSamplerTexture.binding); const GLES3GPUDescriptor * gpuDescriptor = &gpuDescriptorSet->gpuDescriptors[descriptorIndex]; for (size_t u = 0; u < glSamplerTexture.units.size(); u++, gpuDescriptor++) { - uint unit = static_cast(glSamplerTexture.units[u]); + auto unit = static_cast(glSamplerTexture.units[u]); if (!gpuDescriptor->gpuTexture || !gpuDescriptor->gpuSampler) { CC_LOG_ERROR("Sampler texture '%s' at binding %d set %d index %d is not bounded", @@ -2459,11 +2518,11 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli const GLES3GPUUniformStorageImage &glImage = gpuPipelineState->gpuShader->glImages[j]; const GLES3GPUDescriptorSet *gpuDescriptorSet = gpuDescriptorSets[glImage.set]; - const uint descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glImage.binding); + const uint32_t descriptorIndex = gpuDescriptorSet->descriptorIndices->at(glImage.binding); const GLES3GPUDescriptor * gpuDescriptor = &gpuDescriptorSet->gpuDescriptors[descriptorIndex]; for (size_t u = 0; u < glImage.units.size(); u++, gpuDescriptor++) { - uint unit = static_cast(glImage.units[u]); + auto unit = static_cast(glImage.units[u]); if (!gpuDescriptor->gpuTexture) { CC_LOG_ERROR("Storage image '%s' at binding %d set %d index %d is not bounded", @@ -2502,9 +2561,9 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (gpuAttribute.name == gpuInput.name) { GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, gpuAttribute.glBuffer)); - for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLuint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + for (uint32_t c = 0; c < gpuAttribute.componentCount; ++c) { + GLuint glLoc = gpuInput.glLoc + c; + uint32_t attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glEnabledAttribLocs[glLoc] = true; @@ -2546,9 +2605,9 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli cache->glArrayBuffer = gpuAttribute.glBuffer; } - for (uint c = 0; c < gpuAttribute.componentCount; ++c) { - GLuint glLoc = gpuInput.glLoc + c; - uint attribOffset = gpuAttribute.offset + gpuAttribute.size * c; + for (uint32_t c = 0; c < gpuAttribute.componentCount; ++c) { + GLuint glLoc = gpuInput.glLoc + c; + uint32_t attribOffset = gpuAttribute.offset + gpuAttribute.size * c; GL_CHECK(glEnableVertexAttribArray(glLoc)); cache->glCurrentAttribLocs[glLoc] = true; cache->glEnabledAttribLocs[glLoc] = true; @@ -2567,7 +2626,7 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli } } - for (uint a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { + for (uint32_t a = 0; a < cache->glCurrentAttribLocs.size(); ++a) { if (cache->glEnabledAttribLocs[a] != cache->glCurrentAttribLocs[a]) { GL_CHECK(glDisableVertexAttribArray(a)); cache->glEnabledAttribLocs[a] = false; @@ -2579,20 +2638,6 @@ void cmdFuncGLES3BindState(GLES3Device *device, GLES3GPUPipelineState *gpuPipeli if (gpuPipelineState && !gpuPipelineState->dynamicStates.empty()) { for (DynamicStateFlagBit dynamicState : gpuPipelineState->dynamicStates) { switch (dynamicState) { - case DynamicStateFlagBit::VIEWPORT: - if (cache->viewport != dynamicStates->viewport) { - cache->viewport = dynamicStates->viewport; - GL_CHECK(glViewport(dynamicStates->viewport.left, dynamicStates->viewport.top, - dynamicStates->viewport.width, dynamicStates->viewport.height)); - } - break; - case DynamicStateFlagBit::SCISSOR: - if (cache->scissor != dynamicStates->scissor) { - cache->scissor = dynamicStates->scissor; - GL_CHECK(glScissor(dynamicStates->scissor.x, dynamicStates->scissor.y, - dynamicStates->scissor.width, dynamicStates->scissor.height)); - } - break; case DynamicStateFlagBit::LINE_WIDTH: if (cache->rs.lineWidth != dynamicStates->lineWidth) { cache->rs.lineWidth = dynamicStates->lineWidth; @@ -2729,7 +2774,7 @@ void cmdFuncGLES3MemoryBarrier(GLES3Device * /*device*/, GLbitfield barriers, GL if (barriersByRegion) GL_CHECK(glMemoryBarrierByRegion(barriersByRegion)); } -void cmdFuncGLES3UpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint offset, uint size) { +void cmdFuncGLES3UpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, const void *buffer, uint32_t offset, uint32_t size) { GLES3ObjectCache &gfxStateCache = device->stateCache()->gfxStateCache; if (hasFlag(gpuBuffer->usage, BufferUsageBit::INDIRECT)) { memcpy(reinterpret_cast(gpuBuffer->indirects.data()) + offset, buffer, size); @@ -2786,7 +2831,7 @@ void cmdFuncGLES3UpdateBuffer(GLES3Device *device, GLES3GPUBuffer *gpuBuffer, co } } -void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) { +void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const *buffers, GLES3GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint32_t count) { if (gpuTexture->memoryless) return; GLuint &glTexture = device->stateCache()->glTextures[device->stateCache()->texUint]; @@ -2795,13 +2840,13 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const glTexture = gpuTexture->glTexture; } - bool isCompressed = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed; - uint n = 0; + bool isCompressed = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)].isCompressed; + uint32_t n = 0; switch (gpuTexture->glTarget) { case GL_TEXTURE_2D: { - uint w; - uint h; + uint32_t w; + uint32_t h; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; @@ -2831,14 +2876,14 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const break; } case GL_TEXTURE_2D_ARRAY: { - uint w; - uint h; + uint32_t w; + uint32_t h; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; - uint d = region.texSubres.layerCount; - uint layerCount = d + region.texSubres.baseArrayLayer; + uint32_t d = region.texSubres.layerCount; + uint32_t layerCount = d + region.texSubres.baseArrayLayer; - for (uint z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { + for (uint32_t z = region.texSubres.baseArrayLayer; z < layerCount; ++z) { w = region.texExtent.width; h = region.texExtent.height; const uint8_t *buff = buffers[n++]; @@ -2869,9 +2914,9 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const break; } case GL_TEXTURE_3D: { - uint w; - uint h; - uint d; + uint32_t w; + uint32_t h; + uint32_t d; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; w = region.texExtent.width; @@ -2904,12 +2949,12 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const break; } case GL_TEXTURE_CUBE_MAP: { - uint w; - uint h; - uint f; + uint32_t w; + uint32_t h; + uint32_t f; for (size_t i = 0; i < count; ++i) { const BufferTextureCopy ®ion = regions[i]; - uint faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount; + uint32_t faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount; for (f = region.texSubres.baseArrayLayer; f < faceCount; ++f) { w = region.texExtent.width; h = region.texExtent.height; @@ -2950,7 +2995,7 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const } } -CC_GLES3_API void cmdFuncGLES3CopyTextureToBuffers(GLES3Device *device, GLES3GPUTexture *gpuTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { +CC_GLES3_API void cmdFuncGLES3CopyTextureToBuffers(GLES3Device *device, GLES3GPUTexture *gpuTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { auto glFormat = gpuTexture->glFormat; auto glType = gpuTexture->glType; @@ -2967,7 +3012,7 @@ CC_GLES3_API void cmdFuncGLES3CopyTextureToBuffers(GLES3Device *device, GLES3GPU } void cmdFuncGLES3BlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc, GLES3GPUTexture *gpuTextureDst, - const TextureBlit *regions, uint count, Filter filter) { + const TextureBlit *regions, uint32_t count, Filter filter) { GLES3GPUStateCache *cache = device->stateCache(); GLbitfield mask = 0U; @@ -2979,7 +3024,7 @@ void cmdFuncGLES3BlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc mask = GL_COLOR_BUFFER_BIT; } - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { const TextureBlit ®ion = regions[i]; device->context()->makeCurrent(gpuTextureDst->swapchain, gpuTextureSrc->swapchain); @@ -3016,19 +3061,19 @@ void cmdFuncGLES3BlitTexture(GLES3Device *device, GLES3GPUTexture *gpuTextureSrc region.dstOffset.y, region.dstOffset.x + region.dstExtent.width, region.dstOffset.y + region.dstExtent.height, - mask, GLES3_FILTERS[(uint)filter])); + mask, GLES3_FILTERS[(uint32_t)filter])); } } void cmdFuncGLES3ExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage) { if (!cmdPackage->cmds.size()) return; - static uint cmdIndices[static_cast(GLESCmdType::COUNT)] = {0}; + static uint32_t cmdIndices[static_cast(GLESCmdType::COUNT)] = {0}; memset(cmdIndices, 0, sizeof(cmdIndices)); - for (uint i = 0; i < cmdPackage->cmds.size(); ++i) { + for (uint32_t i = 0; i < cmdPackage->cmds.size(); ++i) { GLESCmdType cmdType = cmdPackage->cmds[i]; - uint & cmdIdx = cmdIndices[static_cast(cmdType)]; + uint32_t & cmdIdx = cmdIndices[static_cast(cmdType)]; switch (cmdType) { case GLESCmdType::BEGIN_RENDER_PASS: { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 7480c81d13..7aa01eea19 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -39,8 +39,8 @@ public: Rect renderArea; Color clearColors[MAX_ATTACHMENTS]; float clearDepth = 1.0F; - uint clearStencil = 0U; - uint subpassIdx = 0U; + uint32_t clearStencil = 0U; + uint32_t subpassIdx = 0U; GLES3CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} @@ -55,7 +55,7 @@ public: GLES3GPUPipelineState * gpuPipelineState = nullptr; GLES3GPUInputAssembler * gpuInputAssembler = nullptr; vector gpuDescriptorSets; - vector dynamicOffsets; + vector dynamicOffsets; DynamicStates dynamicStates; GLES3CmdBindStates() : GLESCmd(GLESCmdType::BIND_STATES) {} @@ -103,8 +103,8 @@ class GLES3CmdUpdateBuffer final : public GLESCmd { public: GLES3GPUBuffer *gpuBuffer = nullptr; const uint8_t * buffer = nullptr; - uint size = 0; - uint offset = 0; + uint32_t size = 0; + uint32_t offset = 0; GLES3CmdUpdateBuffer() : GLESCmd(GLESCmdType::UPDATE_BUFFER) {} @@ -118,7 +118,7 @@ class GLES3CmdCopyBufferToTexture final : public GLESCmd { public: GLES3GPUTexture * gpuTexture = nullptr; const BufferTextureCopy *regions = nullptr; - uint count = 0U; + uint32_t count = 0U; const uint8_t *const * buffers = nullptr; GLES3CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} @@ -136,7 +136,7 @@ public: GLES3GPUTexture * gpuTextureSrc = nullptr; GLES3GPUTexture * gpuTextureDst = nullptr; const TextureBlit *regions = nullptr; - uint count = 0U; + uint32_t count = 0U; Filter filter = Filter::POINT; GLES3CmdBlitTexture() : GLESCmd(GLESCmdType::BLIT_TEXTURE) {} @@ -224,19 +224,21 @@ CC_GLES3_API void cmdFuncGLES3CreateSampler(GLES3Device *device, GLES3GPUSampler CC_GLES3_API void cmdFuncGLES3DestroySampler(GLES3Device *device, GLES3GPUSampler *gpuSampler); CC_GLES3_API void cmdFuncGLES3CreateShader(GLES3Device *device, GLES3GPUShader *gpuShader); CC_GLES3_API void cmdFuncGLES3DestroyShader(GLES3Device *device, GLES3GPUShader *gpuShader); +CC_GLES3_API void cmdFuncGLES3CreateRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass); +CC_GLES3_API void cmdFuncGLES3DestroyRenderPass(GLES3Device *device, GLES3GPURenderPass *gpuRenderPass); CC_GLES3_API void cmdFuncGLES3CreateInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler); CC_GLES3_API void cmdFuncGLES3DestroyInputAssembler(GLES3Device *device, GLES3GPUInputAssembler *gpuInputAssembler); CC_GLES3_API void cmdFuncGLES3CreateFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); CC_GLES3_API void cmdFuncGLES3DestroyFramebuffer(GLES3Device *device, GLES3GPUFramebuffer *gpuFBO); CC_GLES3_API void cmdFuncGLES3CreateGlobalBarrier(const std::vector &prevAccesses, const std::vector &nextAccesses, GLES3GPUGlobalBarrier *barrier); -CC_GLES3_API void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint subpassIdx, +CC_GLES3_API void cmdFuncGLES3BeginRenderPass(GLES3Device *device, uint32_t subpassIdx, GLES3GPURenderPass * gpuRenderPass = nullptr, GLES3GPUFramebuffer *gpuFramebuffer = nullptr, const Rect * renderArea = nullptr, const Color * clearColors = nullptr, float clearDepth = 1.F, - uint clearStencil = 0); + uint32_t clearStencil = 0); CC_GLES3_API void cmdFuncGLES3EndRenderPass(GLES3Device *device); @@ -244,7 +246,7 @@ CC_GLES3_API void cmdFuncGLES3BindState(GLES3Device * devi GLES3GPUPipelineState * gpuPipelineState, GLES3GPUInputAssembler * gpuInputAssembler, const GLES3GPUDescriptorSet *const *gpuDescriptorSets, - const uint * dynamicOffsets = nullptr, + const uint32_t * dynamicOffsets = nullptr, const DynamicStates * dynamicStates = nullptr); CC_GLES3_API void cmdFuncGLES3Draw(GLES3Device *device, const DrawInfo &drawInfo); @@ -252,25 +254,25 @@ CC_GLES3_API void cmdFuncGLES3Draw(GLES3Device *device, const DrawInfo &drawInfo CC_GLES3_API void cmdFuncGLES3UpdateBuffer(GLES3Device * device, GLES3GPUBuffer *gpuBuffer, const void * buffer, - uint offset, - uint size); + uint32_t offset, + uint32_t size); CC_GLES3_API void cmdFuncGLES3CopyBuffersToTexture(GLES3Device * device, const uint8_t *const * buffers, GLES3GPUTexture * gpuTexture, const BufferTextureCopy *regions, - uint count); + uint32_t count); CC_GLES3_API void cmdFuncGLES3CopyTextureToBuffers(GLES3Device * device, GLES3GPUTexture * gpuTexture, uint8_t *const * buffers, const BufferTextureCopy *regions, - uint count); + uint32_t count); CC_GLES3_API void cmdFuncGLES3BlitTexture(GLES3Device * device, GLES3GPUTexture * gpuTextureSrc, GLES3GPUTexture * gpuTextureDst, const TextureBlit *regions, - uint count, + uint32_t count, Filter filter); CC_GLES3_API void cmdFuncGLES3ExecuteCmds(GLES3Device *device, GLES3CmdPackage *cmdPackage); diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp index e23bfeb983..300c0c2852 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp @@ -52,7 +52,7 @@ void GLES3DescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); for (size_t i = 0U, k = 0U; i < bindingCount; i++) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; - for (uint j = 0; j < binding.count; j++, k++) { + for (uint32_t j = 0; j < binding.count; j++, k++) { _gpuDescriptorSet->gpuDescriptors[k].type = binding.descriptorType; } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp index 579bd2e006..61f67a517e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp @@ -48,7 +48,7 @@ void GLES3DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo& /*info*/) { for (auto& binding : _bindings) { if (hasAnyFlags(binding.descriptorType, DESCRIPTOR_DYNAMIC_TYPE)) { - for (uint j = 0U; j < binding.count; j++) { + for (uint32_t j = 0U; j < binding.count; j++) { _gpuDescriptorSetLayout->dynamicBindings.push_back(binding.binding); } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index 84b818706b..1a34cb6916 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -150,17 +150,7 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) { _gpuConstantRegistry->mFBF = FBFSupportLevel::COHERENT; fbfLevelStr = "COHERENT"; } - _features[toNumber(Feature::GL_FRAMEBUFFER_FETCH)] = true; - } - - if (checkExtension("pixel_local_storage")) { - if (checkExtension("pixel_local_storage2")) { - _gpuConstantRegistry->mPLS = PLSSupportLevel::LEVEL2; - } else { - _gpuConstantRegistry->mPLS = PLSSupportLevel::LEVEL1; - } - glGetIntegerv(GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_SIZE_EXT, reinterpret_cast(&_gpuConstantRegistry->mPLSsize)); - _features[toNumber(Feature::GL_PIXEL_LOCAL_STORAGE)] = true; + _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = true; } #endif @@ -232,7 +222,6 @@ bool GLES3Device::doInit(const DeviceInfo & /*info*/) { CC_LOG_INFO("VENDOR: %s", _vendor.c_str()); CC_LOG_INFO("VERSION: %s", _version.c_str()); CC_LOG_INFO("COMPRESSED_FORMATS: %s", compressedFmts.c_str()); - CC_LOG_INFO("PIXEL_LOCAL_STORAGE: level %d, size %d", _gpuConstantRegistry->mPLS, _gpuConstantRegistry->mPLSsize); CC_LOG_INFO("FRAMEBUFFER_FETCH: %s", fbfLevelStr.c_str()); return true; @@ -331,23 +320,23 @@ PipelineState *GLES3Device::createPipelineState() { return CC_NEW(GLES3PipelineState); } -Sampler *GLES3Device::createSampler(const SamplerInfo &info) { - return CC_NEW(GLES3Sampler(info)); +Sampler *GLES3Device::createSampler(const SamplerInfo &info, uint32_t hash) { + return CC_NEW(GLES3Sampler(info, hash)); } -GlobalBarrier *GLES3Device::createGlobalBarrier(const GlobalBarrierInfo &info) { - return CC_NEW(GLES3GlobalBarrier(info)); +GlobalBarrier *GLES3Device::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) { + return CC_NEW(GLES3GlobalBarrier(info, hash)); } -TextureBarrier *GLES3Device::createTextureBarrier(const TextureBarrierInfo &info) { - return CC_NEW(TextureBarrier(info)); +TextureBarrier *GLES3Device::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) { + return CC_NEW(TextureBarrier(info, hash)); } -void GLES3Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { +void GLES3Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { cmdFuncGLES3CopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count); } -void GLES3Device::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { +void GLES3Device::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { cmdFuncGLES3CopyTextureToBuffers(this, static_cast(srcTexture)->gpuTexture(), buffers, regions, count); } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index fe052c67cd..66c4583003 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -98,12 +98,12 @@ protected: PipelineLayout * createPipelineLayout() override; PipelineState * createPipelineState() override; - Sampler * createSampler(const SamplerInfo &info) override; - GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) override; + Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override; + GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override; + void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override; void bindContext(bool bound) override; diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp b/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp index 2c174ea79a..b1cc52cb34 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUContext.cpp @@ -31,7 +31,7 @@ namespace cc { namespace gfx { #if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION -constexpr uint DISABLE_VALIDATION_ASSERTIONS = 1; // 0 for default behavior, otherwise assertions will be disabled +constexpr uint32_t DISABLE_VALIDATION_ASSERTIONS = 1; // 0 for default behavior, otherwise assertions will be disabled void GL_APIENTRY GLES3EGLDebugProc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { String sourceDesc; @@ -331,8 +331,8 @@ bool GLES3GPUContext::makeCurrent(EGLSurface drawSurface, EGLSurface readSurface return succeeded; } -void GLES3GPUContext::resetStates() const { // NOLINT - +// NOLINTNEXTLINE(google-readability-function-size, readability-function-size) +void GLES3GPUContext::resetStates() const { GL_CHECK(glPixelStorei(GL_PACK_ALIGNMENT, 1)); GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); GL_CHECK(glActiveTexture(GL_TEXTURE0)); diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h index cc659d99ce..49c8ee15b1 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h @@ -26,6 +26,7 @@ #pragma once #include "base/Macros.h" +#include "gfx-base/GFXDef-common.h" #include "gfx-base/GFXDef.h" #include "gfx-gles-common/GLESCommandPool.h" @@ -37,13 +38,11 @@ namespace gfx { class GLES3GPUConstantRegistry final : public Object { public: - size_t currentBoundThreadID{0U}; - uint glMinorVersion{0U}; + size_t currentBoundThreadID{0U}; + uint32_t glMinorVersion{0U}; MSRTSupportLevel mMSRT{MSRTSupportLevel::NONE}; FBFSupportLevel mFBF{FBFSupportLevel::NONE}; - PLSSupportLevel mPLS{PLSSupportLevel::NONE}; - uint mPLSsize{0U}; }; class GLES3GPUStateCache; @@ -102,9 +101,9 @@ class GLES3GPUBuffer final : public Object { public: BufferUsage usage = BufferUsage::NONE; MemoryUsage memUsage = MemoryUsage::NONE; - uint size = 0; - uint stride = 0; - uint count = 0; + uint32_t size = 0; + uint32_t stride = 0; + uint32_t count = 0; GLenum glTarget = 0; GLuint glBuffer = 0; GLuint glOffset = 0; @@ -118,12 +117,12 @@ public: TextureType type{TextureType::TEX2D}; Format format{Format::UNKNOWN}; TextureUsage usage{TextureUsageBit::NONE}; - uint width{0}; - uint height{0}; - uint depth{1}; - uint size{0}; - uint arrayLayer{1}; - uint mipLevel{1}; + uint32_t width{0}; + uint32_t height{0}; + uint32_t depth{1}; + uint32_t size{0}; + uint32_t arrayLayer{1}; + uint32_t mipLevel{1}; SampleCount samples{SampleCount::ONE}; TextureFlags flags{TextureFlagBit::NONE}; bool isPowerOf2{false}; @@ -163,49 +162,49 @@ public: class GLES3GPUInput final : public Object { public: - uint binding = 0; - String name; - Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; - GLenum glType = 0; - GLint glLoc = -1; + uint32_t binding = 0; + String name; + Type type = Type::UNKNOWN; + uint32_t stride = 0; + uint32_t count = 0; + uint32_t size = 0; + GLenum glType = 0; + GLint glLoc = -1; }; using GLES3GPUInputList = vector; class GLES3GPUUniform final : public Object { public: - uint binding = INVALID_BINDING; - String name; - Type type = Type::UNKNOWN; - uint stride = 0; - uint count = 0; - uint size = 0; - uint offset = 0; - GLenum glType = 0; - GLint glLoc = -1; + uint32_t binding = INVALID_BINDING; + String name; + Type type = Type::UNKNOWN; + uint32_t stride = 0; + uint32_t count = 0; + uint32_t size = 0; + uint32_t offset = 0; + GLenum glType = 0; + GLint glLoc = -1; }; using GLES3GPUUniformList = vector; class GLES3GPUUniformBuffer final : public Object { public: - uint set = INVALID_BINDING; - uint binding = INVALID_BINDING; - String name; - uint size = 0; - uint glBinding = 0xffffffff; - bool isStorage = false; + uint32_t set = INVALID_BINDING; + uint32_t binding = INVALID_BINDING; + String name; + uint32_t size = 0; + uint32_t glBinding = 0xffffffff; + bool isStorage = false; }; using GLES3GPUUniformBufferList = vector; class GLES3GPUUniformSamplerTexture final : public Object { public: - uint set = 0; - uint binding = 0; - String name; - Type type = Type::UNKNOWN; - uint count = 0U; + uint32_t set = 0; + uint32_t binding = 0; + String name; + Type type = Type::UNKNOWN; + uint32_t count = 0U; vector units; GLenum glType = 0; @@ -215,11 +214,11 @@ using GLES3GPUUniformSamplerTextureList = vector; class GLES3GPUUniformStorageImage final : public Object { public: - uint set = 0; - uint binding = 0; - String name; - Type type = Type::UNKNOWN; - uint count = 0U; + uint32_t set = 0; + uint32_t binding = 0; + String name; + Type type = Type::UNKNOWN; + uint32_t count = 0U; vector units; GLenum glMemoryAccess = GL_READ_WRITE; @@ -260,16 +259,16 @@ public: class GLES3GPUAttribute final : public Object { public: - String name; - GLuint glBuffer = 0; - GLenum glType = 0; - uint size = 0; - uint count = 0; - uint stride = 1; - uint componentCount = 1; - bool isNormalized = false; - bool isInstanced = false; - uint offset = 0; + String name; + GLuint glBuffer = 0; + GLenum glType = 0; + uint32_t size = 0; + uint32_t count = 0; + uint32_t stride = 1; + uint32_t componentCount = 1; + bool isNormalized = false; + bool isInstanced = false; + uint32_t offset = 0; }; using GLES3GPUAttributeList = vector; @@ -292,20 +291,27 @@ public: class GLES3GPURenderPass final : public Object { public: - ColorAttachmentList colorAttachments; - DepthStencilAttachment depthStencilAttachment; - SubpassInfoList subpasses; - vector barriers; + struct AttachmentStatistics { + uint32_t loadSubpass{SUBPASS_EXTERNAL}; + uint32_t storeSubpass{SUBPASS_EXTERNAL}; + }; + + ColorAttachmentList colorAttachments; + DepthStencilAttachment depthStencilAttachment; + SubpassInfoList subpasses; + + vector statistics; // per attachment + + vector barriers; // per subpass }; class GLES3GPUFramebufferCacheMap; class GLES3GPUFramebuffer final : public Object { public: - GLES3GPURenderPass *gpuRenderPass = nullptr; + GLES3GPURenderPass *gpuRenderPass{nullptr}; GLES3GPUTextureList gpuColorTextures; - GLES3GPUTexture * gpuDepthStencilTexture = nullptr; - bool usesPLS = false; - bool usesFBF = false; + GLES3GPUTexture * gpuDepthStencilTexture{nullptr}; + bool usesFBF{false}; struct GLFramebuffer { inline void initialize(GLES3GPUSwapchain *sc) { swapchain = sc; } @@ -328,21 +334,27 @@ public: GLFramebuffer resolveFramebuffer; }; - // one per subpass, if not using FBF or PLS + // one per subpass, if not using FBF vector instances; - vector uberColorAttachmentIndices; - Framebuffer uberInstance; + vector uberColorAttachmentIndices; + uint32_t uberDepthStencil{INVALID_BINDING}; + Framebuffer uberInstance; + + // the assumed shader output, may differ from actual subpass output + // see Feature::INPUT_ATTACHMENT_BENEFIT for more details on this + uint32_t uberOnChipOutput{INVALID_BINDING}; + uint32_t uberFinalOutput{INVALID_BINDING}; }; class GLES3GPUDescriptorSetLayout final : public Object { public: DescriptorSetLayoutBindingList bindings; - vector dynamicBindings; + vector dynamicBindings; - vector bindingIndices; - vector descriptorIndices; - uint descriptorCount = 0U; + vector bindingIndices; + vector descriptorIndices; + uint32_t descriptorCount = 0U; }; using GLES3GPUDescriptorSetLayoutList = vector; @@ -352,9 +364,9 @@ public: // helper storages vector> dynamicOffsetIndices; - vector dynamicOffsetOffsets; - vector dynamicOffsets; - uint dynamicOffsetCount; + vector dynamicOffsetOffsets; + vector dynamicOffsets; + uint32_t dynamicOffsetCount; }; class GLES3GPUPipelineState final : public Object { @@ -381,23 +393,23 @@ using GLES3GPUDescriptorList = vector; class GLES3GPUDescriptorSet final : public Object { public: - GLES3GPUDescriptorList gpuDescriptors; - const vector * descriptorIndices = nullptr; + GLES3GPUDescriptorList gpuDescriptors; + const vector *descriptorIndices = nullptr; }; class GLES3GPUDispatchInfo final : public Object { public: - uint groupCountX = 0; - uint groupCountY = 0; - uint groupCountZ = 0; + uint32_t groupCountX = 0; + uint32_t groupCountY = 0; + uint32_t groupCountZ = 0; GLES3GPUBuffer *indirectBuffer = nullptr; - uint indirectOffset = 0; + uint32_t indirectOffset = 0; }; class GLES3ObjectCache final : public Object { public: - uint subpassIdx = 0U; + uint32_t subpassIdx = 0U; GLES3GPURenderPass * gpuRenderPass = nullptr; GLES3GPUFramebuffer * gpuFramebuffer = nullptr; GLES3GPUPipelineState * gpuPipelineState = nullptr; @@ -406,41 +418,40 @@ public: Rect renderArea; ColorList clearColors; float clearDepth = 1.F; - uint clearStencil = 0U; + uint32_t clearStencil = 0U; }; class GLES3GPUStateCache final : public Object { public: - GLuint glArrayBuffer = 0; - GLuint glElementArrayBuffer = 0; - GLuint glUniformBuffer = 0; - vector glBindUBOs; - vector glBindUBOOffsets; - GLuint glShaderStorageBuffer = 0; - vector glBindSSBOs; - vector glBindSSBOOffsets; - GLuint glDispatchIndirectBuffer = 0; - GLuint glVAO = 0; - uint texUint = 0; - vector glTextures; - vector glImages; - vector glSamplers; - GLuint glProgram = 0; - vector glEnabledAttribLocs; - vector glCurrentAttribLocs; - GLuint glReadFramebuffer = 0; - GLuint glDrawFramebuffer = 0; - GLuint glRenderbuffer = 0; - Viewport viewport; - Rect scissor; - RasterizerState rs; - DepthStencilState dss; - BlendState bs; - bool isCullFaceEnabled = true; - bool isStencilTestEnabled = false; - bool isPLSEnabled = false; - unordered_map texUnitCacheMap; - GLES3ObjectCache gfxStateCache; + GLuint glArrayBuffer = 0; + GLuint glElementArrayBuffer = 0; + GLuint glUniformBuffer = 0; + vector glBindUBOs; + vector glBindUBOOffsets; + GLuint glShaderStorageBuffer = 0; + vector glBindSSBOs; + vector glBindSSBOOffsets; + GLuint glDispatchIndirectBuffer = 0; + GLuint glVAO = 0; + uint32_t texUint = 0; + vector glTextures; + vector glImages; + vector glSamplers; + GLuint glProgram = 0; + vector glEnabledAttribLocs; + vector glCurrentAttribLocs; + GLuint glReadFramebuffer = 0; + GLuint glDrawFramebuffer = 0; + GLuint glRenderbuffer = 0; + Viewport viewport; + Rect scissor; + RasterizerState rs; + DepthStencilState dss; + BlendState bs; + bool isCullFaceEnabled = true; + bool isStencilTestEnabled = false; + unordered_map texUnitCacheMap; + GLES3ObjectCache gfxStateCache; void initialize(size_t texUnits, size_t imageUnits, size_t uboBindings, size_t ssboBindings, size_t vertexAttributes) { glBindUBOs.resize(uboBindings, 0U); @@ -480,7 +491,6 @@ public: glRenderbuffer = 0; isCullFaceEnabled = true; isStencilTestEnabled = false; - isPLSEnabled = false; viewport = Viewport(); scissor = Rect(); @@ -537,10 +547,10 @@ public: } GLuint getFramebufferFromTexture(const GLES3GPUTexture *gpuTexture, const TextureSubresLayers &subres) { - bool isTexture = gpuTexture->glTexture; - GLuint glResource = isTexture ? gpuTexture->glTexture : gpuTexture->glRenderbuffer; - auto & cacheMap = isTexture ? _textureMap : _renderbufferMap; - uint mipLevel = isTexture ? subres.mipLevel : 0; + bool isTexture = gpuTexture->glTexture; + GLuint glResource = isTexture ? gpuTexture->glTexture : gpuTexture->glRenderbuffer; + auto & cacheMap = isTexture ? _textureMap : _renderbufferMap; + uint32_t mipLevel = isTexture ? subres.mipLevel : 0; if (gpuTexture->swapchain) return gpuTexture->swapchain->glFramebuffer; CCASSERT(gpuTexture->glTexture || gpuTexture->glRenderbuffer, "Texture already destroyed?"); @@ -555,7 +565,7 @@ public: _cache->glDrawFramebuffer = glFramebuffer; } - const FormatInfo &info = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)]; + const FormatInfo &info = GFX_FORMAT_INFOS[static_cast(gpuTexture->format)]; GLenum attachment = GL_COLOR_ATTACHMENT0; if (info.hasStencil) { attachment = GL_DEPTH_STENCIL_ATTACHMENT; diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp index ebe545f5a2..68d4873c35 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp @@ -69,8 +69,8 @@ void GLES3PipelineState::doInit(const PipelineStateInfo & /*info*/) { _gpuPipelineState->gpuPipelineLayout = static_cast(_pipelineLayout)->gpuPipelineLayout(); if (_renderPass) _gpuPipelineState->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); - for (uint i = 0; i < 31; i++) { - if (static_cast(_dynamicStates) & (1 << i)) { + for (uint32_t i = 0; i < 31; i++) { + if (static_cast(_dynamicStates) & (1 << i)) { _gpuPipelineState->dynamicStates.push_back(static_cast(1 << i)); } } diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp index 1ef3e22429..088fda79d4 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp @@ -44,7 +44,7 @@ GLES3PrimaryCommandBuffer::~GLES3PrimaryCommandBuffer() { destroy(); } -void GLES3PrimaryCommandBuffer::begin(RenderPass * /*renderPass*/, uint /*subpass*/, Framebuffer * /*frameBuffer*/) { +void GLES3PrimaryCommandBuffer::begin(RenderPass * /*renderPass*/, uint32_t /*subpass*/, Framebuffer * /*frameBuffer*/) { _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; _curGPUDescriptorSets.assign(_curGPUDescriptorSets.size(), nullptr); @@ -60,7 +60,7 @@ void GLES3PrimaryCommandBuffer::end() { } } -void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const * /*secondaryCBs*/, uint /*secondaryCBCount*/) { +void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const * /*secondaryCBs*/, uint32_t /*secondaryCBCount*/) { _curSubpassIdx = 0U; GLES3GPURenderPass * gpuRenderPass = static_cast(renderPass)->gpuRenderPass(); @@ -70,7 +70,7 @@ void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuf &renderArea, colors, depth, stencil); _curDynamicStates.viewport = {renderArea.x, renderArea.y, renderArea.width, renderArea.height}; - _curDynamicStates.scissor = renderArea; + _curDynamicStates.scissor = renderArea; } void GLES3PrimaryCommandBuffer::endRenderPass() { @@ -92,7 +92,7 @@ void GLES3PrimaryCommandBuffer::draw(const DrawInfo &info) { ++_numDrawCalls; _numInstances += info.instanceCount; if (_curGPUPipelineState) { - uint indexCount = info.indexCount ? info.indexCount : info.vertexCount; + uint32_t indexCount = info.indexCount ? info.indexCount : info.vertexCount; switch (_curGPUPipelineState->glPrimitive) { case GL_TRIANGLES: { _numTriangles += indexCount / 3 * std::max(info.instanceCount, 1U); @@ -109,21 +109,37 @@ void GLES3PrimaryCommandBuffer::draw(const DrawInfo &info) { } } -void GLES3PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +void GLES3PrimaryCommandBuffer::setViewport(const Viewport &vp) { + auto *cache = GLES3Device::getInstance()->stateCache(); + if (cache->viewport != vp) { + cache->viewport = vp; + GL_CHECK(glViewport(vp.left, vp.top, vp.width, vp.height)); + } +} + +void GLES3PrimaryCommandBuffer::setScissor(const Rect &rect) { + auto *cache = GLES3Device::getInstance()->stateCache(); + if (cache->scissor != rect) { + cache->scissor = rect; + GL_CHECK(glScissor(rect.x, rect.y, rect.width, rect.height)); + } +} + +void GLES3PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint32_t size) { GLES3GPUBuffer *gpuBuffer = static_cast(buff)->gpuBuffer(); if (gpuBuffer) { cmdFuncGLES3UpdateBuffer(GLES3Device::getInstance(), gpuBuffer, data, 0U, size); } } -void GLES3PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void GLES3PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { GLES3GPUTexture *gpuTexture = static_cast(texture)->gpuTexture(); if (gpuTexture) { cmdFuncGLES3CopyBuffersToTexture(GLES3Device::getInstance(), buffers, gpuTexture, regions, count); } } -void GLES3PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void GLES3PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { GLES3GPUTexture *gpuTextureSrc = nullptr; GLES3GPUTexture *gpuTextureDst = nullptr; if (srcTexture) gpuTextureSrc = static_cast(srcTexture)->gpuTexture(); @@ -133,7 +149,7 @@ void GLES3PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTex } void GLES3PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { - for (uint i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { @@ -155,13 +171,13 @@ void GLES3PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t void GLES3PrimaryCommandBuffer::bindStates() { if (_curGPUPipelineState) { - vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; - vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; + vector &dynamicOffsetOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsetOffsets; + vector &dynamicOffsets = _curGPUPipelineState->gpuPipelineLayout->dynamicOffsets; for (size_t i = 0U, len = dynamicOffsetOffsets.size() - 1; i < len; i++) { size_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsets[i].size() >= count, "missing dynamic offsets?"); count = std::min(count, _curDynamicOffsets[i].size()); - if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); + if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint32_t)); } cmdFuncGLES3BindState(GLES3Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets.data(), dynamicOffsets.data(), &_curDynamicStates); @@ -187,7 +203,7 @@ void GLES3PrimaryCommandBuffer::dispatch(const DispatchInfo &info) { cmdFuncGLES3Dispatch(GLES3Device::getInstance(), gpuInfo); } -void GLES3PrimaryCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const * /*textureBarriers*/, const Texture *const * /*textures*/, uint /*textureBarrierCount*/) { +void GLES3PrimaryCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const * /*textureBarriers*/, const Texture *const * /*textures*/, uint32_t /*textureBarrierCount*/) { if (!barrier) return; const auto *gpuBarrier = static_cast(barrier)->gpuBarrier(); diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h index 0e857b1c6e..85400d4703 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h @@ -35,18 +35,20 @@ public: GLES3PrimaryCommandBuffer() = default; ~GLES3PrimaryCommandBuffer() override; - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; + void setViewport(const Viewport &vp) override; + void setScissor(const Rect &rect) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override; - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; protected: friend class GLES3Queue; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp index 283b3b5074..095ca09f3b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp @@ -47,8 +47,8 @@ void GLES3Queue::doInit(const QueueInfo &info) { void GLES3Queue::doDestroy() { } -void GLES3Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { - for (uint i = 0; i < count; ++i) { +void GLES3Queue::submit(CommandBuffer *const *cmdBuffs, uint32_t count) { + for (uint32_t i = 0; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingPackages.empty()) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Queue.h b/native/cocos/renderer/gfx-gles3/GLES3Queue.h index d4e0ae6967..457f9a57bb 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Queue.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Queue.h @@ -36,7 +36,7 @@ public: GLES3Queue(); ~GLES3Queue() override; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override; protected: friend class GLES3Device; @@ -44,9 +44,9 @@ protected: void doInit(const QueueInfo &info) override; void doDestroy() override; - uint _numDrawCalls = 0; - uint _numInstances = 0; - uint _numTriangles = 0; + uint32_t _numDrawCalls = 0; + uint32_t _numInstances = 0; + uint32_t _numTriangles = 0; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp index a83d93aced..93f1136c59 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp @@ -26,8 +26,9 @@ #include "GLES3Std.h" #include "GLES3Commands.h" +#include "GLES3Device.h" #include "GLES3RenderPass.h" -#include "base/Utils.h" +#include "gfx-base/GFXDef-common.h" namespace cc { namespace gfx { @@ -50,23 +51,31 @@ void GLES3RenderPass::doInit(const RenderPassInfo & /*info*/) { if (_gpuRenderPass->subpasses.empty()) { auto &subpass = _gpuRenderPass->subpasses.emplace_back(); subpass.colors.resize(_colorAttachments.size()); - for (uint i = 0U; i < _colorAttachments.size(); ++i) { + for (uint32_t i = 0U; i < _colorAttachments.size(); ++i) { subpass.colors[i] = i; } if (_depthStencilAttachment.format != Format::UNKNOWN) { subpass.depthStencil = _colorAttachments.size(); } + } else { + // unify depth stencil index + uint32_t colorCount = _gpuRenderPass->colorAttachments.size(); + for (auto &subpass : _gpuRenderPass->subpasses) { + if (subpass.depthStencil != INVALID_BINDING && subpass.depthStencil > colorCount) { + subpass.depthStencil = colorCount; + } + if (subpass.depthStencilResolve != INVALID_BINDING && subpass.depthStencilResolve > colorCount) { + subpass.depthStencilResolve = colorCount; + } + } } - _gpuRenderPass->barriers.resize(_subpasses.size() + 1); - for (auto &dependency : _dependencies) { - size_t idx = dependency.dstSubpass == SUBPASS_EXTERNAL ? _subpasses.size() : dependency.dstSubpass; - cmdFuncGLES3CreateGlobalBarrier(dependency.srcAccesses, dependency.dstAccesses, &_gpuRenderPass->barriers[idx]); - } + cmdFuncGLES3CreateRenderPass(GLES3Device::getInstance(), _gpuRenderPass); } void GLES3RenderPass::doDestroy() { if (_gpuRenderPass) { + cmdFuncGLES3DestroyRenderPass(GLES3Device::getInstance(), _gpuRenderPass); CC_DELETE(_gpuRenderPass); _gpuRenderPass = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp b/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp index 532dbbb0d3..a02e6b0c6c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Swapchain.cpp @@ -111,8 +111,6 @@ void GLES3Swapchain::doDestroy() { } void GLES3Swapchain::doResize(uint32_t width, uint32_t height, SurfaceTransform /*transform*/) { - doDestroySurface(); - _colorTexture->resize(width, height); _depthStencilTexture->resize(width, height); @@ -138,7 +136,7 @@ void GLES3Swapchain::doCreateSurface(void* windowHandle) { return; } - auto width = static_cast(_colorTexture->getWidth()); + auto width = static_cast(_colorTexture->getWidth()); auto height = static_cast(_colorTexture->getHeight()); #if CC_PLATFORM == CC_PLATFORM_ANDROID ANativeWindow_setBuffersGeometry(window, width, height, nFmt); @@ -147,10 +145,12 @@ void GLES3Swapchain::doCreateSurface(void* windowHandle) { NativeLayerHandle(window, SET_FORMAT, nFmt); #endif - EGL_CHECK(_gpuSwapchain->eglSurface = eglCreateWindowSurface(context->eglDisplay, context->eglConfig, window, nullptr)); if (_gpuSwapchain->eglSurface == EGL_NO_SURFACE) { - CC_LOG_ERROR("Recreate window surface failed."); - return; + EGL_CHECK(_gpuSwapchain->eglSurface = eglCreateWindowSurface(context->eglDisplay, context->eglConfig, window, nullptr)); + if (_gpuSwapchain->eglSurface == EGL_NO_SURFACE) { + CC_LOG_ERROR("Recreate window surface failed."); + return; + } } context->makeCurrent(_gpuSwapchain, _gpuSwapchain); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp index 08766b9d75..d275014e5f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp @@ -79,7 +79,7 @@ void GLES3Texture::doDestroy() { } } -void GLES3Texture::doResize(uint width, uint height, uint size) { +void GLES3Texture::doResize(uint32_t width, uint32_t height, uint32_t size) { if (!_gpuTexture->memoryless) { GLES3Device::getInstance()->getMemoryStatus().textureSize -= _size; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.h b/native/cocos/renderer/gfx-gles3/GLES3Texture.h index 62dcc1c584..b4475de813 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.h @@ -44,7 +44,7 @@ protected: void doInit(const TextureInfo &info) override; void doInit(const TextureViewInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, uint size) override; + void doResize(uint32_t width, uint32_t height, uint32_t size) override; void doInit(const SwapchainTextureInfo &info) override; GLES3GPUTexture *_gpuTexture = nullptr; diff --git a/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.cpp b/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.cpp index 7e3a2d34da..f485ba0b80 100644 --- a/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.cpp @@ -29,7 +29,7 @@ namespace cc { namespace gfx { -GLES3GlobalBarrier::GLES3GlobalBarrier(const GlobalBarrierInfo &info) : GlobalBarrier(info) { +GLES3GlobalBarrier::GLES3GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) : GlobalBarrier(info, hash) { _typedID = generateObjectID(); _gpuBarrier = CC_NEW(GLES3GPUGlobalBarrier); diff --git a/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.h b/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.h index 8541ed6030..fb9be2297e 100644 --- a/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.h +++ b/native/cocos/renderer/gfx-gles3/states/GLES3GlobalBarrier.h @@ -35,7 +35,7 @@ class GLES3GPUGlobalBarrier; class CC_GLES3_API GLES3GlobalBarrier : public GlobalBarrier { public: - explicit GLES3GlobalBarrier(const GlobalBarrierInfo &info); + explicit GLES3GlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash); ~GLES3GlobalBarrier() override; inline const GLES3GPUGlobalBarrier *gpuBarrier() const { return _gpuBarrier; } diff --git a/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp b/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp index 6636294ea8..42bf542ee4 100644 --- a/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp +++ b/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.cpp @@ -30,7 +30,7 @@ namespace cc { namespace gfx { -GLES3Sampler::GLES3Sampler(const SamplerInfo &info) : Sampler(info) { +GLES3Sampler::GLES3Sampler(const SamplerInfo &info, uint32_t hash) : Sampler(info, hash) { _typedID = generateObjectID(); _gpuSampler = CC_NEW(GLES3GPUSampler); diff --git a/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.h b/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.h index 497052d6c1..70b7fdafe9 100644 --- a/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.h +++ b/native/cocos/renderer/gfx-gles3/states/GLES3Sampler.h @@ -35,7 +35,7 @@ class GLES3GPUSampler; class CC_GLES3_API GLES3Sampler final : public Sampler { public: - explicit GLES3Sampler(const SamplerInfo &info); + explicit GLES3Sampler(const SamplerInfo &info, uint32_t hash); ~GLES3Sampler() override; inline GLES3GPUSampler *gpuSampler() const { return _gpuSampler; } diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.h b/native/cocos/renderer/gfx-metal/MTLDevice.h index 11f06c8d14..7e8b8fb014 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.h +++ b/native/cocos/renderer/gfx-metal/MTLDevice.h @@ -78,7 +78,7 @@ public: inline CCMTLGPUStagingBufferPool *gpuStagingBufferPool() const { return _gpuStagingBufferPools[_currentFrameIndex]; } inline bool isSamplerDescriptorCompareFunctionSupported() const { return _isSamplerDescriptorCompareFunctionSupported; } inline uint currentFrameIndex() const { return _currentFrameIndex; } - + inline void registerSwapchain(CCMTLSwapchain* swapchain) { _swapchains.push_back(swapchain); } inline void unRegisterSwapchain(CCMTLSwapchain* swapchain) { auto iter = std::find(_swapchains.begin(), _swapchains.end(), swapchain); @@ -106,9 +106,9 @@ protected: DescriptorSetLayout *createDescriptorSetLayout() override; PipelineLayout *createPipelineLayout() override; PipelineState *createPipelineState() override; - GlobalBarrier *createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo& info) override; - Sampler *createSampler(const SamplerInfo& info) override; + GlobalBarrier *createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo& info, uint32_t hash) override; + Sampler *createSampler(const SamplerInfo& info, uint32_t hash) override; Swapchain *createSwapchain() override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; @@ -130,9 +130,9 @@ protected: uint _currentFrameIndex = 0; CCMTLSemaphore *_inFlightSemaphore = nullptr; CC_UNUSED uint32_t _memoryAlarmListenerId = 0; - + std::vector _swapchains; - + CCMTLGPUDeviceObject* _gpuDeviceObj = nullptr; }; diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index fc7f97d6dd..52095064a8 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -106,40 +106,41 @@ bool CCMTLDevice::doInit(const DeviceInfo &info) { _gpuStagingBufferPools[i] = CC_NEW(CCMTLGPUStagingBufferPool(mtlDevice)); } - _features[static_cast(Feature::COLOR_FLOAT)] = mu::isColorBufferFloatSupported(gpuFamily); - _features[static_cast(Feature::COLOR_HALF_FLOAT)] = mu::isColorBufferHalfFloatSupported(gpuFamily); - _features[static_cast(Feature::TEXTURE_FLOAT_LINEAR)] = mu::isLinearTextureSupported(gpuFamily); - _features[static_cast(Feature::TEXTURE_HALF_FLOAT_LINEAR)] = mu::isLinearTextureSupported(gpuFamily); + _features[toNumber(Feature::COLOR_FLOAT)] = mu::isColorBufferFloatSupported(gpuFamily); + _features[toNumber(Feature::COLOR_HALF_FLOAT)] = mu::isColorBufferHalfFloatSupported(gpuFamily); + _features[toNumber(Feature::TEXTURE_FLOAT_LINEAR)] = mu::isLinearTextureSupported(gpuFamily); + _features[toNumber(Feature::TEXTURE_HALF_FLOAT_LINEAR)] = mu::isLinearTextureSupported(gpuFamily); String compressedFormats; if (mu::isPVRTCSuppported(gpuFamily)) { - _features[static_cast(Feature::FORMAT_PVRTC)] = true; + _features[toNumber(Feature::FORMAT_PVRTC)] = true; compressedFormats += "pvrtc "; } if (mu::isEAC_ETCCSuppported(gpuFamily)) { - _features[static_cast(Feature::FORMAT_ETC2)] = true; + _features[toNumber(Feature::FORMAT_ETC2)] = true; compressedFormats += "etc2 "; } if (mu::isASTCSuppported(gpuFamily)) { - _features[static_cast(Feature::FORMAT_ASTC)] = true; + _features[toNumber(Feature::FORMAT_ASTC)] = true; compressedFormats += "astc "; } if (mu::isBCSupported(gpuFamily)) { - _features[static_cast(Feature::FORMAT_ASTC)] = true; + _features[toNumber(Feature::FORMAT_ASTC)] = true; compressedFormats += "dxt "; } - _features[static_cast(Feature::TEXTURE_FLOAT)] = true; - _features[static_cast(Feature::TEXTURE_HALF_FLOAT)] = true; - _features[static_cast(Feature::FORMAT_R11G11B10F)] = true; - _features[static_cast(Feature::FORMAT_SRGB)] = true; - _features[static_cast(Feature::INSTANCED_ARRAYS)] = true; - _features[static_cast(Feature::MULTIPLE_RENDER_TARGETS)] = true; - _features[static_cast(Feature::BLEND_MINMAX)] = true; - _features[static_cast(Feature::ELEMENT_INDEX_UINT)] = true; - _features[static_cast(Feature::COMPUTE_SHADER)] = true; + _features[toNumber(Feature::TEXTURE_FLOAT)] = true; + _features[toNumber(Feature::TEXTURE_HALF_FLOAT)] = true; + _features[toNumber(Feature::FORMAT_R11G11B10F)] = true; + _features[toNumber(Feature::FORMAT_SRGB)] = true; + _features[toNumber(Feature::INSTANCED_ARRAYS)] = true; + _features[toNumber(Feature::MULTIPLE_RENDER_TARGETS)] = true; + _features[toNumber(Feature::BLEND_MINMAX)] = true; + _features[toNumber(Feature::ELEMENT_INDEX_UINT)] = true; + _features[toNumber(Feature::COMPUTE_SHADER)] = true; + _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = true; - _features[static_cast(Feature::FORMAT_RGB8)] = false; + _features[toNumber(Feature::FORMAT_RGB8)] = false; // _memoryAlarmListenerId = EventDispatcher::addCustomEventListener(EVENT_MEMORY_WARNING, std::bind(&CCMTLDevice::onMemoryWarning, this)); @@ -298,16 +299,16 @@ PipelineState *CCMTLDevice::createPipelineState() { return CC_NEW(CCMTLPipelineState); } -GlobalBarrier *CCMTLDevice::createGlobalBarrier(const GlobalBarrierInfo& info) { - return new GlobalBarrier(info); +GlobalBarrier *CCMTLDevice::createGlobalBarrier(const GlobalBarrierInfo& info, uint32_t hash) { + return new GlobalBarrier(info, hash); } -TextureBarrier *CCMTLDevice::createTextureBarrier(const TextureBarrierInfo& info) { - return new TextureBarrier(info); +TextureBarrier *CCMTLDevice::createTextureBarrier(const TextureBarrierInfo& info, uint32_t hash) { + return new TextureBarrier(info, hash); } -Sampler *CCMTLDevice::createSampler(const SamplerInfo &info) { - return new CCMTLSampler(info); +Sampler *CCMTLDevice::createSampler(const SamplerInfo &info, uint32_t hash) { + return new CCMTLSampler(info, hash); } Swapchain *CCMTLDevice::createSwapchain() { diff --git a/native/cocos/renderer/gfx-metal/MTLSampler.h b/native/cocos/renderer/gfx-metal/MTLSampler.h index 01be302526..1854a77218 100644 --- a/native/cocos/renderer/gfx-metal/MTLSampler.h +++ b/native/cocos/renderer/gfx-metal/MTLSampler.h @@ -34,7 +34,7 @@ namespace gfx { class CCMTLSampler final : public Sampler { public: - explicit CCMTLSampler(const SamplerInfo& info); + explicit CCMTLSampler(const SamplerInfo& info, uint32_t hash); ~CCMTLSampler(); CCMTLSampler() = delete; CCMTLSampler(const CCMTLSampler &)=delete; diff --git a/native/cocos/renderer/gfx-metal/MTLSampler.mm b/native/cocos/renderer/gfx-metal/MTLSampler.mm index d5ef6ce131..d46c6423b2 100644 --- a/native/cocos/renderer/gfx-metal/MTLSampler.mm +++ b/native/cocos/renderer/gfx-metal/MTLSampler.mm @@ -34,7 +34,7 @@ namespace cc { namespace gfx { -CCMTLSampler::CCMTLSampler(const SamplerInfo& info) : Sampler(info) { +CCMTLSampler::CCMTLSampler(const SamplerInfo& info, uint32_t hash) : Sampler(info, hash) { _typedID = generateObjectID(); MTLSamplerDescriptor *descriptor = [[MTLSamplerDescriptor alloc] init]; #if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) diff --git a/native/cocos/renderer/gfx-validator/BufferValidator.cpp b/native/cocos/renderer/gfx-validator/BufferValidator.cpp index 3649533f14..807be44f2c 100644 --- a/native/cocos/renderer/gfx-validator/BufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/BufferValidator.cpp @@ -47,7 +47,7 @@ BufferValidator::~BufferValidator() { DeviceResourceTracker::erase(this); CC_SAFE_DELETE(_actor); - uint lifeTime = DeviceValidator::getInstance()->currentFrame() - _creationFrame; + uint32_t lifeTime = DeviceValidator::getInstance()->currentFrame() - _creationFrame; // skip those that have never been updated if (!_isBufferView && hasFlag(_memUsage, MemoryUsageBit::HOST) && _totalUpdateTimes && _totalUpdateTimes < lifeTime / 3) { CC_LOG_WARNING("Triple buffer enabled for infrequently-updated buffer, consider using MemoryUsageBit::DEVICE instead"); @@ -56,13 +56,16 @@ BufferValidator::~BufferValidator() { } void BufferValidator::doInit(const BufferInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CCASSERT(info.usage != BufferUsageBit::NONE, "invalid buffer param"); CCASSERT(info.memUsage != MemoryUsageBit::NONE, "invalid buffer param"); // CCASSERT(info.size, "zero-sized buffer?"); // be more lenient on this for now _initStack = se::ScriptEngine::getInstance()->getCurrentStackTrace(); - _creationFrame = DeviceValidator::getInstance()->currentFrame(); + _creationFrame = DeviceValidator::getInstance()->currentFrame(); _totalUpdateTimes = 0U; if (hasFlag(info.usage, BufferUsageBit::VERTEX) && !info.stride) { @@ -75,7 +78,11 @@ void BufferValidator::doInit(const BufferInfo &info) { } void BufferValidator::doInit(const BufferViewInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CCASSERT(info.buffer, "invalid source buffer"); + CCASSERT(static_cast(info.buffer)->isInited(), "already destroyed?"); CCASSERT(info.offset + info.range <= info.buffer->getSize(), "invalid range"); /////////// execute /////////// @@ -86,7 +93,9 @@ void BufferValidator::doInit(const BufferViewInfo &info) { _actor->initialize(actorInfo); } -void BufferValidator::doResize(uint size, uint /*count*/) { +void BufferValidator::doResize(uint32_t size, uint32_t /*count*/) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(!_isBufferView, "cannot resize through buffer views"); CCASSERT(size, "invalid size"); @@ -96,10 +105,17 @@ void BufferValidator::doResize(uint size, uint /*count*/) { } void BufferValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } -void BufferValidator::update(const void *buffer, uint size) { +void BufferValidator::update(const void *buffer, uint32_t size) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(!_isBufferView, "cannot update through buffer views"); CCASSERT(size && size <= _size, "invalid size"); CCASSERT(buffer, "invalid buffer data"); @@ -123,8 +139,8 @@ void BufferValidator::update(const void *buffer, uint size) { _actor->update(buffer, size); } -void BufferValidator::sanityCheck(const void *buffer, uint size) { - uint cur = DeviceValidator::getInstance()->currentFrame(); +void BufferValidator::sanityCheck(const void *buffer, uint32_t size) { + uint32_t cur = DeviceValidator::getInstance()->currentFrame(); if (cur == _lastUpdateFrame) { // FIXME: minggo: as current implementation need to update some buffers more than once, so disable it. diff --git a/native/cocos/renderer/gfx-validator/BufferValidator.h b/native/cocos/renderer/gfx-validator/BufferValidator.h index 7cd45dd99e..4d488ded70 100644 --- a/native/cocos/renderer/gfx-validator/BufferValidator.h +++ b/native/cocos/renderer/gfx-validator/BufferValidator.h @@ -36,21 +36,25 @@ public: explicit BufferValidator(Buffer *actor); ~BufferValidator() override; - void update(const void *buffer, uint size) override; + void update(const void *buffer, uint32_t size) override; - void sanityCheck(const void *buffer, uint size); + void sanityCheck(const void *buffer, uint32_t size); + + inline bool isInited() const { return _inited; } protected: void doInit(const BufferInfo &info) override; void doInit(const BufferViewInfo &info) override; - void doResize(uint size, uint count) override; + void doResize(uint32_t size, uint32_t count) override; void doDestroy() override; vector _buffer; - uint _lastUpdateFrame{0U}; - uint _totalUpdateTimes{0U}; - uint _creationFrame{0U}; + uint32_t _lastUpdateFrame{0U}; + uint32_t _totalUpdateTimes{0U}; + uint32_t _creationFrame{0U}; + + bool _inited{false}; String _initStack; }; diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp index a3f060a23f..1e4108c682 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.cpp @@ -53,6 +53,9 @@ CommandBufferValidator::~CommandBufferValidator() { } void CommandBufferValidator::initValidator() { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + size_t descriptorSetCount = DeviceValidator::getInstance()->bindingMappingInfo().bufferOffsets.size(); _curStates.descriptorSets.resize(descriptorSetCount); _curStates.dynamicOffsets.resize(descriptorSetCount); @@ -61,6 +64,8 @@ void CommandBufferValidator::initValidator() { void CommandBufferValidator::doInit(const CommandBufferInfo &info) { initValidator(); + CCASSERT(static_cast(info.queue)->isInited(), "already destroyed?"); + /////////// execute /////////// CommandBufferInfo actorInfo = info; @@ -70,10 +75,19 @@ void CommandBufferValidator::doInit(const CommandBufferInfo &info) { } void CommandBufferValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } -void CommandBufferValidator::begin(RenderPass *renderPass, uint subpass, Framebuffer *framebuffer) { +void CommandBufferValidator::begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *framebuffer) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(!renderPass || static_cast(renderPass)->isInited(), "already destroyed?"); + CCASSERT(!framebuffer || static_cast(framebuffer)->isInited(), "already destroyed?"); + CCASSERT(!_insideRenderPass, "Already inside a render pass?"); CCASSERT(_type != CommandBufferType::PRIMARY || !renderPass, "Primary command buffer cannot inherit render passes"); @@ -93,6 +107,8 @@ void CommandBufferValidator::begin(RenderPass *renderPass, uint subpass, Framebu } void CommandBufferValidator::end() { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(_type != CommandBufferType::PRIMARY || !_insideRenderPass, "Still inside a render pass?"); _insideRenderPass = false; @@ -101,9 +117,10 @@ void CommandBufferValidator::end() { _actor->end(); } -void CommandBufferValidator::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { - CCASSERT(renderPass, "invalid render pass"); - CCASSERT(fbo, "invalid framebuffer"); +void CommandBufferValidator::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(renderPass)->isInited(), "already destroyed?"); + CCASSERT(static_cast(fbo)->isInited(), "already destroyed?"); CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'endRenderPass' must be recorded in primary command buffers."); CCASSERT(!_insideRenderPass, "Already inside a render pass?"); @@ -129,21 +146,23 @@ void CommandBufferValidator::beginRenderPass(RenderPass *renderPass, Framebuffer static vector secondaryCBActors; secondaryCBActors.resize(secondaryCBCount); - RenderPass * renderPassActor = renderPass ? static_cast(renderPass)->getActor() : nullptr; - Framebuffer *framebufferActor = fbo ? static_cast(fbo)->getActor() : nullptr; - CommandBuffer **actorSecondaryCBs = nullptr; if (secondaryCBCount) { actorSecondaryCBs = secondaryCBActors.data(); - for (uint i = 0; i < secondaryCBCount; ++i) { + for (uint32_t i = 0; i < secondaryCBCount; ++i) { actorSecondaryCBs[i] = static_cast(secondaryCBs[i])->getActor(); } } + RenderPass * renderPassActor = static_cast(renderPass)->getActor(); + Framebuffer *framebufferActor = static_cast(fbo)->getActor(); + _actor->beginRenderPass(renderPassActor, framebufferActor, renderArea, colors, depth, stencil, actorSecondaryCBs, secondaryCBCount); } void CommandBufferValidator::nextSubpass() { + CCASSERT(isInited(), "alread destroyed?"); + ++_curSubpass; /////////// execute /////////// @@ -152,6 +171,8 @@ void CommandBufferValidator::nextSubpass() { } void CommandBufferValidator::endRenderPass() { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'endRenderPass' must be recorded in primary command buffers."); CCASSERT(_insideRenderPass, "No render pass to end?"); _insideRenderPass = false; @@ -166,15 +187,21 @@ void CommandBufferValidator::endRenderPass() { } void CommandBufferValidator::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { + CCASSERT(isInited(), "alread destroyed?"); + if (!count) return; // be more lenient on this for now CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'execute' must be recorded in primary command buffers."); + for (uint32_t i = 0U; i < count; ++i) { + CCASSERT(static_cast(cmdBuffs[i])->isInited(), "already destroyed?"); + } + /////////// execute /////////// static vector cmdBuffActors; cmdBuffActors.resize(count); - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { cmdBuffActors[i] = static_cast(cmdBuffs[i])->getActor(); } @@ -182,6 +209,9 @@ void CommandBufferValidator::execute(CommandBuffer *const *cmdBuffs, uint32_t co } void CommandBufferValidator::bindPipelineState(PipelineState *pso) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(pso)->isInited(), "already destroyed?"); + _curStates.pipelineState = pso; /////////// execute /////////// @@ -189,9 +219,11 @@ void CommandBufferValidator::bindPipelineState(PipelineState *pso) { _actor->bindPipelineState(static_cast(pso)->getActor()); } -void CommandBufferValidator::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { +void CommandBufferValidator::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(descriptorSet)->isInited(), "already destroyed?"); + CCASSERT(set < DeviceValidator::getInstance()->bindingMappingInfo().bufferOffsets.size(), "invalid set index"); - CCASSERT(descriptorSet, "invalid descriptor set"); //CCASSERT(descriptorSet->getLayout()->getDynamicBindings().size() == dynamicOffsetCount, "wrong number of dynamic offsets"); // be more lenient on this _curStates.descriptorSets[set] = descriptorSet; @@ -203,6 +235,9 @@ void CommandBufferValidator::bindDescriptorSet(uint set, DescriptorSet *descript } void CommandBufferValidator::bindInputAssembler(InputAssembler *ia) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(ia)->isInited(), "already destroyed?"); + _curStates.inputAssembler = ia; /////////// execute /////////// @@ -211,6 +246,8 @@ void CommandBufferValidator::bindInputAssembler(InputAssembler *ia) { } void CommandBufferValidator::setViewport(const Viewport &vp) { + CCASSERT(isInited(), "alread destroyed?"); + _curStates.viewport = vp; /////////// execute /////////// @@ -219,6 +256,8 @@ void CommandBufferValidator::setViewport(const Viewport &vp) { } void CommandBufferValidator::setScissor(const Rect &rect) { + CCASSERT(isInited(), "alread destroyed?"); + _curStates.scissor = rect; /////////// execute /////////// @@ -227,6 +266,8 @@ void CommandBufferValidator::setScissor(const Rect &rect) { } void CommandBufferValidator::setLineWidth(float width) { + CCASSERT(isInited(), "alread destroyed?"); + _curStates.lineWidth = width; /////////// execute /////////// @@ -235,6 +276,8 @@ void CommandBufferValidator::setLineWidth(float width) { } void CommandBufferValidator::setDepthBias(float constant, float clamp, float slope) { + CCASSERT(isInited(), "alread destroyed?"); + _curStates.depthBiasConstant = constant; _curStates.depthBiasClamp = clamp; _curStates.depthBiasSlope = slope; @@ -245,6 +288,8 @@ void CommandBufferValidator::setDepthBias(float constant, float clamp, float slo } void CommandBufferValidator::setBlendConstants(const Color &constants) { + CCASSERT(isInited(), "alread destroyed?"); + _curStates.blendConstant = constants; /////////// execute /////////// @@ -253,6 +298,8 @@ void CommandBufferValidator::setBlendConstants(const Color &constants) { } void CommandBufferValidator::setDepthBound(float minBounds, float maxBounds) { + CCASSERT(isInited(), "alread destroyed?"); + _curStates.depthMinBounds = minBounds; _curStates.depthMaxBounds = maxBounds; @@ -261,7 +308,9 @@ void CommandBufferValidator::setDepthBound(float minBounds, float maxBounds) { _actor->setDepthBound(minBounds, maxBounds); } -void CommandBufferValidator::setStencilWriteMask(StencilFace face, uint mask) { +void CommandBufferValidator::setStencilWriteMask(StencilFace face, uint32_t mask) { + CCASSERT(isInited(), "alread destroyed?"); + if (hasFlag(face, StencilFace::FRONT)) { _curStates.stencilStatesFront.writeMask = mask; } @@ -274,7 +323,9 @@ void CommandBufferValidator::setStencilWriteMask(StencilFace face, uint mask) { _actor->setStencilWriteMask(face, mask); } -void CommandBufferValidator::setStencilCompareMask(StencilFace face, uint ref, uint mask) { +void CommandBufferValidator::setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) { + CCASSERT(isInited(), "alread destroyed?"); + if (hasFlag(face, StencilFace::FRONT)) { _curStates.stencilStatesFront.reference = ref; _curStates.stencilStatesFront.compareMask = mask; @@ -290,6 +341,8 @@ void CommandBufferValidator::setStencilCompareMask(StencilFace face, uint ref, u } void CommandBufferValidator::draw(const DrawInfo &info) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(_insideRenderPass, "Command 'draw' must be recorded inside render passes."); if (DeviceValidator::getInstance()->isRecording()) { @@ -309,7 +362,10 @@ void CommandBufferValidator::draw(const DrawInfo &info) { _actor->draw(info); } -void CommandBufferValidator::updateBuffer(Buffer *buff, const void *data, uint size) { +void CommandBufferValidator::updateBuffer(Buffer *buff, const void *data, uint32_t size) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(buff)->isInited(), "already destroyed?"); + CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'updateBuffer' must be recorded in primary command buffers."); CCASSERT(!_insideRenderPass, "Command 'updateBuffer' must be recorded outside render passes."); @@ -321,7 +377,10 @@ void CommandBufferValidator::updateBuffer(Buffer *buff, const void *data, uint s _actor->updateBuffer(bufferValidator->getActor(), data, size); } -void CommandBufferValidator::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void CommandBufferValidator::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(texture)->isInited(), "already destroyed?"); + CCASSERT(_type == CommandBufferType::PRIMARY, "Command 'copyBuffersToTexture' must be recorded in primary command buffers."); CCASSERT(!_insideRenderPass, "Command 'copyBuffersToTexture' must be recorded outside render passes."); @@ -333,7 +392,11 @@ void CommandBufferValidator::copyBuffersToTexture(const uint8_t *const *buffers, _actor->copyBuffersToTexture(buffers, textureValidator->getActor(), regions, count); } -void CommandBufferValidator::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void CommandBufferValidator::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(srcTexture)->isInited(), "already destroyed?"); + CCASSERT(static_cast(dstTexture)->isInited(), "already destroyed?"); + CCASSERT(!_insideRenderPass, "Command 'blitTexture' must be recorded outside render passes."); for (uint32_t i = 0; i < count; ++i) { @@ -358,6 +421,8 @@ void CommandBufferValidator::blitTexture(Texture *srcTexture, Texture *dstTextur } void CommandBufferValidator::dispatch(const DispatchInfo &info) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(!_insideRenderPass, "Command 'dispatch' must be recorded outside render passes."); /////////// execute /////////// @@ -368,7 +433,13 @@ void CommandBufferValidator::dispatch(const DispatchInfo &info) { _actor->dispatch(info); } -void CommandBufferValidator::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) { +void CommandBufferValidator::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) { + CCASSERT(isInited(), "alread destroyed?"); + + for (uint32_t i = 0U; i < textureBarrierCount; ++i) { + CCASSERT(static_cast(textures[i])->isInited(), "already destroyed?"); + } + /////////// execute /////////// static vector textureActors; @@ -377,7 +448,7 @@ void CommandBufferValidator::pipelineBarrier(const GlobalBarrier *barrier, const Texture **actorTextures = nullptr; if (textureBarrierCount) { actorTextures = textureActors.data(); - for (uint i = 0U; i < textureBarrierCount; ++i) { + for (uint32_t i = 0U; i < textureBarrierCount; ++i) { actorTextures[i] = textures[i] ? static_cast(textures[i])->getActor() : nullptr; } } diff --git a/native/cocos/renderer/gfx-validator/CommandBufferValidator.h b/native/cocos/renderer/gfx-validator/CommandBufferValidator.h index b4f2bb7f78..81c6f78888 100644 --- a/native/cocos/renderer/gfx-validator/CommandBufferValidator.h +++ b/native/cocos/renderer/gfx-validator/CommandBufferValidator.h @@ -38,12 +38,12 @@ public: explicit CommandBufferValidator(CommandBuffer *actor); ~CommandBufferValidator() override; - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void bindPipelineState(PipelineState *pso) override; - void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override; void bindInputAssembler(InputAssembler *ia) override; void setViewport(const Viewport &vp) override; void setScissor(const Rect &rect) override; @@ -51,24 +51,26 @@ public: void setDepthBias(float constant, float clamp, float slope) override; void setBlendConstants(const Color &constants) override; void setDepthBound(float minBounds, float maxBounds) override; - void setStencilWriteMask(StencilFace face, uint mask) override; - void setStencilCompareMask(StencilFace face, uint ref, uint mask) override; + void setStencilWriteMask(StencilFace face, uint32_t mask) override; + void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buff, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void updateBuffer(Buffer *buff, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override; - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override; - uint getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } - uint getNumInstances() const override { return _actor->getNumInstances(); } - uint getNumTris() const override { return _actor->getNumTris(); } + uint32_t getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } + uint32_t getNumInstances() const override { return _actor->getNumInstances(); } + uint32_t getNumTris() const override { return _actor->getNumTris(); } + + inline bool isInited() const { return _inited; } + inline bool isCommandsFlushed() const { return _commandsFlushed; } protected: friend class DeviceValidator; - friend class QueueValidator; void initValidator(); @@ -78,9 +80,11 @@ protected: CommandBufferStorage _curStates; CommandRecorder _recorder; - bool _insideRenderPass{false}; - bool _commandsFlushed{false}; - uint _curSubpass{0U}; + bool _insideRenderPass{false}; + bool _commandsFlushed{false}; + uint32_t _curSubpass{0U}; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp b/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp index 0cc1edfd43..bfb8bff2b0 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.cpp @@ -44,6 +44,9 @@ DescriptorSetLayoutValidator::~DescriptorSetLayoutValidator() { } void DescriptorSetLayoutValidator::doInit(const DescriptorSetLayoutInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + for (const DescriptorSetLayoutBinding &binding : info.bindings) { CCASSERT(binding.binding != INVALID_BINDING, "Invalid binding"); CCASSERT(binding.descriptorType != DescriptorType::UNKNOWN, "Invalid binding type"); @@ -60,6 +63,11 @@ void DescriptorSetLayoutValidator::doInit(const DescriptorSetLayoutInfo &info) { } void DescriptorSetLayoutValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.h b/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.h index f9f9b01255..2ddd04c505 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.h +++ b/native/cocos/renderer/gfx-validator/DescriptorSetLayoutValidator.h @@ -36,9 +36,13 @@ public: explicit DescriptorSetLayoutValidator(DescriptorSetLayout *actor); ~DescriptorSetLayoutValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const DescriptorSetLayoutInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp index 3e009b877d..1e37942f28 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.cpp @@ -47,7 +47,9 @@ DescriptorSetValidator::~DescriptorSetValidator() { } void DescriptorSetValidator::doInit(const DescriptorSetInfo &info) { - CCASSERT(info.layout, "Invalid set layout"); + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CCASSERT(static_cast(info.layout)->isInited(), "already destroyed?"); /////////// execute /////////// @@ -58,18 +60,28 @@ void DescriptorSetValidator::doInit(const DescriptorSetInfo &info) { } void DescriptorSetValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } void DescriptorSetValidator::update() { + CCASSERT(isInited(), "alread destroyed?"); + if (!_isDirty) return; _isDirty = false; _actor->update(); } -void DescriptorSetValidator::bindBuffer(uint binding, Buffer *buffer, uint index) { - const vector & bindingIndices = _layout->getBindingIndices(); +void DescriptorSetValidator::bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(buffer)->isInited(), "already destroyed?"); + + const vector & bindingIndices = _layout->getBindingIndices(); const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); CCASSERT(binding < bindingIndices.size() && bindingIndices[binding] < bindings.size(), "Illegal binding"); @@ -86,8 +98,11 @@ void DescriptorSetValidator::bindBuffer(uint binding, Buffer *buffer, uint index _actor->bindBuffer(binding, static_cast(buffer)->getActor(), index); } -void DescriptorSetValidator::bindTexture(uint binding, Texture *texture, uint index) { - const vector & bindingIndices = _layout->getBindingIndices(); +void DescriptorSetValidator::bindTexture(uint32_t binding, Texture *texture, uint32_t index) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(static_cast(texture)->isInited(), "already destroyed?"); + + const vector & bindingIndices = _layout->getBindingIndices(); const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); CCASSERT(binding < bindingIndices.size() && bindingIndices[binding] < bindings.size(), "Illegal binding"); @@ -101,8 +116,10 @@ void DescriptorSetValidator::bindTexture(uint binding, Texture *texture, uint in _actor->bindTexture(binding, static_cast(texture)->getActor(), index); } -void DescriptorSetValidator::bindSampler(uint binding, Sampler *sampler, uint index) { - const vector & bindingIndices = _layout->getBindingIndices(); +void DescriptorSetValidator::bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) { + CCASSERT(isInited(), "alread destroyed?"); + + const vector & bindingIndices = _layout->getBindingIndices(); const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); CCASSERT(binding < bindingIndices.size() && bindingIndices[binding] < bindings.size(), "Illegal binding"); diff --git a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.h b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.h index 9613f6e80b..8d5a25204f 100644 --- a/native/cocos/renderer/gfx-validator/DescriptorSetValidator.h +++ b/native/cocos/renderer/gfx-validator/DescriptorSetValidator.h @@ -38,13 +38,17 @@ public: void update() override; - void bindBuffer(uint binding, Buffer *buffer, uint index) override; - void bindTexture(uint binding, Texture *texture, uint index) override; - void bindSampler(uint binding, Sampler *sampler, uint index) override; + void bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index) override; + void bindTexture(uint32_t binding, Texture *texture, uint32_t index) override; + void bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) override; + + inline bool isInited() const { return _inited; } protected: void doInit(const DescriptorSetInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp index 45fa397803..30b19796b9 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.cpp +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.cpp @@ -72,8 +72,9 @@ bool DeviceValidator::doInit(const DeviceInfo &info) { _renderer = _actor->getRenderer(); _vendor = _actor->getVendor(); _caps = _actor->_caps; - memcpy(_features.data(), _actor->_features.data(), static_cast(Feature::COUNT) * sizeof(bool)); + memcpy(_features.data(), _actor->_features.data(), static_cast(Feature::COUNT) * sizeof(bool)); + static_cast(_queue)->_inited = true; static_cast(_cmdBuff)->_queue = _queue; static_cast(_cmdBuff)->initValidator(); @@ -119,7 +120,7 @@ void DeviceValidator::acquire(Swapchain *const *swapchains, uint32_t count) { static vector swapchainActors; swapchainActors.resize(count); - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { auto *swapchain = static_cast(swapchains[i]); swapchainActors[i] = swapchain->getActor(); } @@ -224,31 +225,36 @@ PipelineState *DeviceValidator::createPipelineState() { return result; } -Sampler *DeviceValidator::createSampler(const SamplerInfo &info) { - return _actor->createSampler(info); +Sampler *DeviceValidator::createSampler(const SamplerInfo &info, uint32_t hash) { + return _actor->createSampler(info, hash); } -GlobalBarrier *DeviceValidator::createGlobalBarrier(const GlobalBarrierInfo &info) { - return _actor->createGlobalBarrier(info); +GlobalBarrier *DeviceValidator::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) { + return _actor->createGlobalBarrier(info, hash); } -TextureBarrier *DeviceValidator::createTextureBarrier(const TextureBarrierInfo &info) { - return _actor->createTextureBarrier(info); +TextureBarrier *DeviceValidator::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) { + return _actor->createTextureBarrier(info, hash); } -void DeviceValidator::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { +void DeviceValidator::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { auto *textureValidator = static_cast(dst); textureValidator->sanityCheck(); + /////////// execute /////////// + _actor->copyBuffersToTexture(buffers, textureValidator->getActor(), regions, count); } -void DeviceValidator::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { +void DeviceValidator::copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { auto *textureValidator = static_cast(src); + + /////////// execute /////////// + _actor->copyTextureToBuffers(textureValidator->getActor(), buffers, regions, count); } -void DeviceValidator::flushCommands(CommandBuffer *const *cmdBuffs, uint count) { +void DeviceValidator::flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) { if (!count) return; /////////// execute /////////// @@ -256,7 +262,7 @@ void DeviceValidator::flushCommands(CommandBuffer *const *cmdBuffs, uint count) static vector cmdBuffActors; cmdBuffActors.resize(count); - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); cmdBuff->_commandsFlushed = true; cmdBuffActors[i] = cmdBuff->getActor(); diff --git a/native/cocos/renderer/gfx-validator/DeviceValidator.h b/native/cocos/renderer/gfx-validator/DeviceValidator.h index 841fbbf11a..4c59de705c 100644 --- a/native/cocos/renderer/gfx-validator/DeviceValidator.h +++ b/native/cocos/renderer/gfx-validator/DeviceValidator.h @@ -71,22 +71,22 @@ public: PipelineLayout * createPipelineLayout() override; PipelineState * createPipelineState() override; - Sampler * createSampler(const SamplerInfo &info) override; - GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) override; + Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override; + GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override; + void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override; - void flushCommands(CommandBuffer *const *cmdBuffs, uint count) override; + void flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) override; MemoryStatus &getMemoryStatus() override { return _actor->getMemoryStatus(); } - uint getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } - uint getNumInstances() const override { return _actor->getNumInstances(); } - uint getNumTris() const override { return _actor->getNumTris(); } + uint32_t getNumDrawCalls() const override { return _actor->getNumDrawCalls(); } + uint32_t getNumInstances() const override { return _actor->getNumInstances(); } + uint32_t getNumTris() const override { return _actor->getNumTris(); } - inline void enableRecording(bool recording) { _recording = recording; } - inline bool isRecording() const { return _recording; } - inline uint currentFrame() const { return _currentFrame; } + inline void enableRecording(bool recording) { _recording = recording; } + inline bool isRecording() const { return _recording; } + inline uint32_t currentFrame() const { return _currentFrame; } protected: static DeviceValidator *instance; @@ -100,8 +100,8 @@ protected: void bindContext(bool bound) override { _actor->bindContext(bound); } - bool _recording{false}; - uint _currentFrame{1U}; + bool _recording{false}; + uint32_t _currentFrame{1U}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp b/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp index 59c9572353..cd79ea9ab7 100644 --- a/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp +++ b/native/cocos/renderer/gfx-validator/FramebufferValidator.cpp @@ -46,8 +46,21 @@ FramebufferValidator::~FramebufferValidator() { } void FramebufferValidator::doInit(const FramebufferInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + + for (auto *colorTexture : info.colorTextures) { + CCASSERT(static_cast(colorTexture)->isInited(), "already destroyed?"); + } + if (info.depthStencilTexture) { + CCASSERT(static_cast(info.depthStencilTexture)->isInited(), "already destroyed?"); + } + CCASSERT(static_cast(info.renderPass)->isInited(), "already destroyed?"); + + /////////// execute /////////// + FramebufferInfo actorInfo = info; - for (uint i = 0U; i < info.colorTextures.size(); ++i) { + for (uint32_t i = 0U; i < info.colorTextures.size(); ++i) { if (info.colorTextures[i]) { actorInfo.colorTextures[i] = static_cast(info.colorTextures[i])->getActor(); } @@ -61,6 +74,11 @@ void FramebufferValidator::doInit(const FramebufferInfo &info) { } void FramebufferValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } diff --git a/native/cocos/renderer/gfx-validator/FramebufferValidator.h b/native/cocos/renderer/gfx-validator/FramebufferValidator.h index 2ef5af2810..a69f3049e3 100644 --- a/native/cocos/renderer/gfx-validator/FramebufferValidator.h +++ b/native/cocos/renderer/gfx-validator/FramebufferValidator.h @@ -36,9 +36,13 @@ public: explicit FramebufferValidator(Framebuffer *actor); ~FramebufferValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const FramebufferInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp b/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp index d7bc0cc13d..e6fd6ad820 100644 --- a/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp +++ b/native/cocos/renderer/gfx-validator/InputAssemblerValidator.cpp @@ -45,6 +45,21 @@ InputAssemblerValidator::~InputAssemblerValidator() { } void InputAssemblerValidator::doInit(const InputAssemblerInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + + for (auto *vertexBuffer : info.vertexBuffers) { + CCASSERT(static_cast(vertexBuffer)->isInited(), "already destroyed?"); + } + if (info.indexBuffer) { + CCASSERT(static_cast(info.indexBuffer)->isInited(), "already destroyed?"); + } + if (info.indirectBuffer) { + CCASSERT(static_cast(info.indirectBuffer)->isInited(), "already destroyed?"); + } + + /////////// execute /////////// + InputAssemblerInfo actorInfo = info; for (auto &vertexBuffer : actorInfo.vertexBuffers) { vertexBuffer = static_cast(vertexBuffer)->getActor(); @@ -60,50 +75,13 @@ void InputAssemblerValidator::doInit(const InputAssemblerInfo &info) { } void InputAssemblerValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } -void InputAssemblerValidator::setVertexCount(uint32_t count) { - _drawInfo.vertexCount = count; - - _actor->setVertexCount(count); -} - -void InputAssemblerValidator::setFirstVertex(uint32_t first) { - _drawInfo.firstVertex = first; - - _actor->setFirstVertex(first); -} - -void InputAssemblerValidator::setIndexCount(uint32_t count) { - _drawInfo.indexCount = count; - - _actor->setIndexCount(count); -} - -void InputAssemblerValidator::setFirstIndex(uint32_t first) { - _drawInfo.firstIndex = first; - - _actor->setFirstIndex(first); -} - -void InputAssemblerValidator::setVertexOffset(int32_t offset) { - _drawInfo.vertexOffset = offset; - - _actor->setVertexOffset(offset); -} - -void InputAssemblerValidator::setInstanceCount(uint32_t count) { - _drawInfo.instanceCount = count; - - _actor->setInstanceCount(count); -} - -void InputAssemblerValidator::setFirstInstance(uint32_t first) { - _drawInfo.firstInstance = first; - - _actor->setFirstInstance(first); -} - } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-validator/InputAssemblerValidator.h b/native/cocos/renderer/gfx-validator/InputAssemblerValidator.h index 444f863aa8..cb2419d69f 100644 --- a/native/cocos/renderer/gfx-validator/InputAssemblerValidator.h +++ b/native/cocos/renderer/gfx-validator/InputAssemblerValidator.h @@ -36,17 +36,13 @@ public: explicit InputAssemblerValidator(InputAssembler *actor); ~InputAssemblerValidator() override; - void setVertexCount(uint32_t count) override; - void setFirstVertex(uint32_t first) override; - void setIndexCount(uint32_t count) override; - void setFirstIndex(uint32_t first) override; - void setVertexOffset(int32_t offset) override; - void setInstanceCount(uint32_t count) override; - void setFirstInstance(uint32_t first) override; + inline bool isInited() const { return _inited; } protected: void doInit(const InputAssemblerInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp b/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp index 08f977154b..b843d6954d 100644 --- a/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp +++ b/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.cpp @@ -45,10 +45,18 @@ PipelineLayoutValidator::~PipelineLayoutValidator() { } void PipelineLayoutValidator::doInit(const PipelineLayoutInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + + for (auto *layout : info.setLayouts) { + CCASSERT(static_cast(layout)->isInited(), "already destroyed?"); + } + + /////////// execute /////////// + PipelineLayoutInfo actorInfo; actorInfo.setLayouts.resize(info.setLayouts.size()); - for (uint i = 0U; i < info.setLayouts.size(); i++) { - CCASSERT(info.setLayouts[i], "invalid descriptor set layout"); + for (uint32_t i = 0U; i < info.setLayouts.size(); i++) { actorInfo.setLayouts[i] = static_cast(info.setLayouts[i])->getActor(); } @@ -56,6 +64,11 @@ void PipelineLayoutValidator::doInit(const PipelineLayoutInfo &info) { } void PipelineLayoutValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } diff --git a/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.h b/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.h index c43f8f5929..60dc5e9342 100644 --- a/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.h +++ b/native/cocos/renderer/gfx-validator/PipelineLayoutValidator.h @@ -36,9 +36,13 @@ public: explicit PipelineLayoutValidator(PipelineLayout *actor); ~PipelineLayoutValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const PipelineLayoutInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp b/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp index aed4fbfcc7..df2d4a1df6 100644 --- a/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp +++ b/native/cocos/renderer/gfx-validator/PipelineStateValidator.cpp @@ -47,23 +47,26 @@ PipelineStateValidator::~PipelineStateValidator() { } void PipelineStateValidator::doInit(const PipelineStateInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CCASSERT(static_cast(info.shader)->isInited(), "already destroyed?"); + CCASSERT(static_cast(info.pipelineLayout)->isInited(), "already destroyed?"); + + /////////// execute /////////// + PipelineStateInfo actorInfo = info; actorInfo.shader = static_cast(info.shader)->getActor(); actorInfo.pipelineLayout = static_cast(info.pipelineLayout)->getActor(); - if (info.renderPass) { - actorInfo.renderPass = static_cast(info.renderPass)->getActor(); - - // const auto &subpasses = info.renderPass->getSubpasses(); - // size_t colorAttachmentCount = info.subpass >= subpasses.size() - // ? info.renderPass->getColorAttachments().size() - // : subpasses[info.subpass].colors.size(); - //CCASSERT(colorAttachmentCount == info.blendState.targets.size(), "Wrong number of blend targets"); // be more lenient on this - } _actor->initialize(actorInfo); } void PipelineStateValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } diff --git a/native/cocos/renderer/gfx-validator/PipelineStateValidator.h b/native/cocos/renderer/gfx-validator/PipelineStateValidator.h index 44c79ac329..12e54fca00 100644 --- a/native/cocos/renderer/gfx-validator/PipelineStateValidator.h +++ b/native/cocos/renderer/gfx-validator/PipelineStateValidator.h @@ -36,9 +36,13 @@ public: explicit PipelineStateValidator(PipelineState *actor); ~PipelineStateValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const PipelineStateInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/QueueValidator.cpp b/native/cocos/renderer/gfx-validator/QueueValidator.cpp index 7e66b4c752..83befa951c 100644 --- a/native/cocos/renderer/gfx-validator/QueueValidator.cpp +++ b/native/cocos/renderer/gfx-validator/QueueValidator.cpp @@ -44,23 +44,40 @@ QueueValidator::~QueueValidator() { } void QueueValidator::doInit(const QueueInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + + /////////// execute /////////// + _actor->initialize(info); } void QueueValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } -void QueueValidator::submit(CommandBuffer *const *cmdBuffs, uint count) { +void QueueValidator::submit(CommandBuffer *const *cmdBuffs, uint32_t count) { + CCASSERT(isInited(), "alread destroyed?"); + if (!count) return; + for (uint32_t i = 0U; i < count; ++i) { + auto *cmdBuff = static_cast(cmdBuffs[i]); + CCASSERT(cmdBuff->isInited(), "alread destroyed?"); + CCASSERT(cmdBuff->isCommandsFlushed(), "command buffers must be flushed before submit"); + } + + /////////// execute /////////// static vector cmdBuffActors; cmdBuffActors.resize(count); - for (uint i = 0U; i < count; ++i) { - auto *cmdBuff = static_cast(cmdBuffs[i]); - CCASSERT(cmdBuff->_commandsFlushed, "command buffers must be flushed before submit"); - cmdBuffActors[i] = cmdBuff->getActor(); + for (uint32_t i = 0U; i < count; ++i) { + cmdBuffActors[i] = static_cast(cmdBuffs[i])->getActor(); } _actor->submit(cmdBuffActors.data(), count); diff --git a/native/cocos/renderer/gfx-validator/QueueValidator.h b/native/cocos/renderer/gfx-validator/QueueValidator.h index b95d3ab468..402340a601 100644 --- a/native/cocos/renderer/gfx-validator/QueueValidator.h +++ b/native/cocos/renderer/gfx-validator/QueueValidator.h @@ -38,13 +38,17 @@ public: explicit QueueValidator(Queue *actor); ~QueueValidator() override; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override; + + inline bool isInited() const { return _inited; } protected: friend class DeviceValidator; void doInit(const QueueInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp b/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp index 1d995f5ca1..047645a4f2 100644 --- a/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp +++ b/native/cocos/renderer/gfx-validator/RenderPassValidator.cpp @@ -44,6 +44,9 @@ RenderPassValidator::~RenderPassValidator() { } void RenderPassValidator::doInit(const RenderPassInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + bool hasDepth = info.depthStencilAttachment.format != Format::UNKNOWN; if (!hasDepth) { for (const auto &subpass : info.subpasses) { @@ -52,10 +55,17 @@ void RenderPassValidator::doInit(const RenderPassInfo &info) { } } + /////////// execute /////////// + _actor->initialize(info); } void RenderPassValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } diff --git a/native/cocos/renderer/gfx-validator/RenderPassValidator.h b/native/cocos/renderer/gfx-validator/RenderPassValidator.h index faf22f1741..6f097faf5a 100644 --- a/native/cocos/renderer/gfx-validator/RenderPassValidator.h +++ b/native/cocos/renderer/gfx-validator/RenderPassValidator.h @@ -36,9 +36,13 @@ public: explicit RenderPassValidator(RenderPass *actor); ~RenderPassValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const RenderPassInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/ShaderValidator.cpp b/native/cocos/renderer/gfx-validator/ShaderValidator.cpp index 938bb288ae..a183adc7d8 100644 --- a/native/cocos/renderer/gfx-validator/ShaderValidator.cpp +++ b/native/cocos/renderer/gfx-validator/ShaderValidator.cpp @@ -44,10 +44,20 @@ ShaderValidator::~ShaderValidator() { } void ShaderValidator::doInit(const ShaderInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + + /////////// execute /////////// + _actor->initialize(info); } void ShaderValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } diff --git a/native/cocos/renderer/gfx-validator/ShaderValidator.h b/native/cocos/renderer/gfx-validator/ShaderValidator.h index daddea8dbb..aa997947c1 100644 --- a/native/cocos/renderer/gfx-validator/ShaderValidator.h +++ b/native/cocos/renderer/gfx-validator/ShaderValidator.h @@ -36,9 +36,13 @@ public: explicit ShaderValidator(Shader *actor); ~ShaderValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const ShaderInfo &info) override; void doDestroy() override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp b/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp index 870e9fad5d..89df8467a2 100644 --- a/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp +++ b/native/cocos/renderer/gfx-validator/SwapchainValidator.cpp @@ -49,6 +49,11 @@ SwapchainValidator::~SwapchainValidator() { } void SwapchainValidator::doInit(const SwapchainInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + + /////////// execute /////////// + _actor->initialize(info); auto *colorTexture = CC_NEW(TextureValidator(_actor->getColorTexture())); @@ -73,6 +78,11 @@ void SwapchainValidator::doInit(const SwapchainInfo &info) { } void SwapchainValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + CC_SAFE_DELETE(_depthStencilTexture); CC_SAFE_DELETE(_colorTexture); @@ -80,14 +90,20 @@ void SwapchainValidator::doDestroy() { } void SwapchainValidator::doResize(uint32_t width, uint32_t height, SurfaceTransform transform) { + CCASSERT(isInited(), "alread destroyed?"); + _actor->resize(width, height, transform); } void SwapchainValidator::doDestroySurface() { + CCASSERT(isInited(), "alread destroyed?"); + _actor->destroySurface(); } void SwapchainValidator::doCreateSurface(void *windowHandle) { + CCASSERT(isInited(), "alread destroyed?"); + _actor->createSurface(windowHandle); } diff --git a/native/cocos/renderer/gfx-validator/SwapchainValidator.h b/native/cocos/renderer/gfx-validator/SwapchainValidator.h index b393236414..6a3a145a43 100644 --- a/native/cocos/renderer/gfx-validator/SwapchainValidator.h +++ b/native/cocos/renderer/gfx-validator/SwapchainValidator.h @@ -37,12 +37,16 @@ public: explicit SwapchainValidator(Swapchain *actor); ~SwapchainValidator() override; + inline bool isInited() const { return _inited; } + protected: void doInit(const SwapchainInfo &info) override; void doDestroy() override; void doResize(uint32_t width, uint32_t height, SurfaceTransform transform) override; void doDestroySurface() override; void doCreateSurface(void *windowHandle) override; + + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/TextureValidator.cpp b/native/cocos/renderer/gfx-validator/TextureValidator.cpp index f8607308ea..2c2376ec05 100644 --- a/native/cocos/renderer/gfx-validator/TextureValidator.cpp +++ b/native/cocos/renderer/gfx-validator/TextureValidator.cpp @@ -28,6 +28,7 @@ #include "DeviceValidator.h" #include "TextureValidator.h" #include "ValidationUtils.h" +#include "base/Macros.h" #include "gfx-validator/SwapchainValidator.h" namespace cc { @@ -51,16 +52,27 @@ TextureValidator::~TextureValidator() { } void TextureValidator::doInit(const TextureInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CCASSERT(!featureCheckMap.count(_info.format) || DeviceValidator::getInstance()->hasFeature(featureCheckMap[_info.format]), "unsupported format"); // Potentially inefficient static const TextureUsageBit INEFFICIENT_MASK{TextureUsageBit::INPUT_ATTACHMENT | TextureUsageBit::SAMPLED}; CCASSERT((info.usage & INEFFICIENT_MASK) != INEFFICIENT_MASK, "Both SAMPLED and INPUT_ATTACHMENT are specified?"); + /////////// execute /////////// + _actor->initialize(info); } void TextureValidator::doInit(const TextureViewInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CCASSERT(static_cast(info.texture)->isInited(), "alread destroyed?"); + + /////////// execute /////////// + TextureViewInfo actorInfo = info; actorInfo.texture = static_cast(info.texture)->getActor(); @@ -68,22 +80,38 @@ void TextureValidator::doInit(const TextureViewInfo &info) { } void TextureValidator::doInit(const SwapchainTextureInfo &info) { + CCASSERT(!isInited(), "initializing twice?"); + _inited = true; + CC_UNUSED_PARAM(info); // workaround tidy issue + CCASSERT(static_cast(info.swapchain)->isInited(), "alread destroyed?"); + // the actor is already initialized } void TextureValidator::doDestroy() { + CCASSERT(isInited(), "destroying twice?"); + _inited = false; + + /////////// execute /////////// + _actor->destroy(); } -void TextureValidator::doResize(uint width, uint height, uint /*size*/) { +void TextureValidator::doResize(uint32_t width, uint32_t height, uint32_t /*size*/) { + CCASSERT(isInited(), "alread destroyed?"); + CCASSERT(hasFlag(_info.flags, TextureFlagBit::RESIZABLE), "Cannot resize immutable textures"); CCASSERT(!_isTextureView, "Cannot resize texture views"); + /////////// execute /////////// + _actor->resize(width, height); } void TextureValidator::sanityCheck() { - uint cur = DeviceValidator::getInstance()->currentFrame(); + CCASSERT(isInited(), "alread destroyed?"); + + uint32_t cur = DeviceValidator::getInstance()->currentFrame(); // FIXME: minggo: as current implementation need to update some textures more than once, so disable it. // Should enable it when it is fixed. diff --git a/native/cocos/renderer/gfx-validator/TextureValidator.h b/native/cocos/renderer/gfx-validator/TextureValidator.h index 1b5f9a6ddc..e7eec6ca31 100644 --- a/native/cocos/renderer/gfx-validator/TextureValidator.h +++ b/native/cocos/renderer/gfx-validator/TextureValidator.h @@ -39,16 +39,18 @@ public: void sanityCheck(); inline void renounceOwnership() { _ownTheActor = false; } + inline bool isInited() const { return _inited; } protected: void doInit(const TextureInfo &info) override; void doInit(const TextureViewInfo &info) override; void doInit(const SwapchainTextureInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, uint size) override; + void doResize(uint32_t width, uint32_t height, uint32_t size) override; - uint _lastUpdateFrame = 0U; - bool _ownTheActor = true; + uint32_t _lastUpdateFrame{0U}; + bool _ownTheActor{true}; + bool _inited{false}; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-validator/ValidationUtils.h b/native/cocos/renderer/gfx-validator/ValidationUtils.h index 0cbe932a31..3d6a1da438 100644 --- a/native/cocos/renderer/gfx-validator/ValidationUtils.h +++ b/native/cocos/renderer/gfx-validator/ValidationUtils.h @@ -45,14 +45,14 @@ struct RenderPassSnapshot { Rect renderArea; vector clearColors; float clearDepth = 1.F; - uint clearStencil = 0U; + uint32_t clearStencil = 0U; }; struct DrawcallSnapshot { - PipelineState * pipelineState; - InputAssembler * inputAssembler; - vector descriptorSets; - vector> dynamicOffsets; + PipelineState * pipelineState; + InputAssembler * inputAssembler; + vector descriptorSets; + vector> dynamicOffsets; }; struct CommandBufferStorage : public DynamicStates, RenderPassSnapshot, DrawcallSnapshot {}; @@ -82,7 +82,7 @@ private: Rect renderArea; vector clearColors; float clearDepth = 1.F; - uint clearStencil = 0U; + uint32_t clearStencil = 0U; }; struct DrawcallCommand { @@ -97,7 +97,7 @@ private: DrawInfo drawInfo; vector descriptorSets; - vector dynamicOffsets; + vector dynamicOffsets; }; vector _commands; @@ -108,7 +108,7 @@ private: BufferInfo info; vector data; }; - unordered_map _bufferMap; + unordered_map _bufferMap; }; ////////////////////////////////////////////////////////////////////////// diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp index 68def4b867..65b82ef50f 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp @@ -95,7 +95,7 @@ void CCVKBuffer::doDestroy() { } } -void CCVKBuffer::doResize(uint size, uint count) { +void CCVKBuffer::doResize(uint32_t size, uint32_t count) { CCVKDevice::getInstance()->getMemoryStatus().bufferSize -= _size; CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer); @@ -114,7 +114,7 @@ void CCVKBuffer::doResize(uint size, uint count) { CCVKDevice::getInstance()->getMemoryStatus().bufferSize += size; } -void CCVKBuffer::update(const void *buffer, uint size) { +void CCVKBuffer::update(const void *buffer, uint32_t size) { cmdFuncCCVKUpdateBuffer(CCVKDevice::getInstance(), _gpuBuffer, buffer, size, nullptr); } diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.h b/native/cocos/renderer/gfx-vulkan/VKBuffer.h index 6dd92db60d..8aa7113029 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.h @@ -39,7 +39,7 @@ public: CCVKBuffer(); ~CCVKBuffer() override; - void update(const void *buffer, uint size) override; + void update(const void *buffer, uint32_t size) override; inline CCVKGPUBuffer * gpuBuffer() const { return _gpuBuffer; } inline CCVKGPUBufferView *gpuBufferView() const { return _gpuBufferView; } @@ -48,7 +48,7 @@ protected: void doInit(const BufferInfo &info) override; void doInit(const BufferViewInfo &info) override; void doDestroy() override; - void doResize(uint size, uint count) override; + void doResize(uint32_t size, uint32_t count) override; void createBufferView(); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 0143f0766f..6ad304fba9 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -70,7 +70,7 @@ void CCVKCommandBuffer::doDestroy() { } } -void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +void CCVKCommandBuffer::begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) { if (_gpuCommandBuffer->began) return; CCVKDevice::getInstance()->gpuDevice()->getCommandBufferPool()->request(_gpuCommandBuffer); @@ -124,7 +124,7 @@ void CCVKCommandBuffer::end() { } void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, - float depth, uint stencil, CommandBuffer *const * /*secondaryCBs*/, uint secondaryCBCount) { + float depth, uint32_t stencil, CommandBuffer *const * /*secondaryCBs*/, uint32_t secondaryCBCount) { #if BARRIER_DEDUCTION_LEVEL >= BARRIER_DEDUCTION_LEVEL_BASIC // guard against RAW hazard VkMemoryBarrier vkBarrier{VK_STRUCTURE_TYPE_MEMORY_BARRIER}; @@ -152,7 +152,7 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo } if (depthEnabled) { - clearValues[attachmentCount].depthStencil = { depth, stencil }; + clearValues[attachmentCount].depthStencil = {depth, stencil}; } VkRenderPassBeginInfo passBeginInfo{VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO}; passBeginInfo.renderPass = gpuRenderPass->vkRenderPass; @@ -171,7 +171,7 @@ void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo vkCmdSetViewport(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &viewport); vkCmdSetScissor(_gpuCommandBuffer->vkCommandBuffer, 0, 1, &passBeginInfo.renderArea); _curDynamicStates.viewport = {renderArea.x, renderArea.y, renderArea.width, renderArea.height}; - _curDynamicStates.scissor = renderArea; + _curDynamicStates.scissor = renderArea; } } @@ -206,7 +206,7 @@ void CCVKCommandBuffer::bindPipelineState(PipelineState *pso) { } } -void CCVKCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) { +void CCVKCommandBuffer::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) { CCASSERT(_curGPUDescriptorSets.size() > set, "Invalid set index"); CCVKGPUDescriptorSet *gpuDescriptorSet = static_cast(descriptorSet)->gpuDescriptorSet(); @@ -228,14 +228,14 @@ void CCVKCommandBuffer::bindInputAssembler(InputAssembler *ia) { if (_curGPUInputAssember != gpuInputAssembler) { // buffers may be rebuilt(e.g. resize event) without IA's acknowledge - uint vbCount = utils::toUint(gpuInputAssembler->gpuVertexBuffers.size()); + uint32_t vbCount = utils::toUint(gpuInputAssembler->gpuVertexBuffers.size()); if (gpuInputAssembler->vertexBuffers.size() < vbCount) { gpuInputAssembler->vertexBuffers.resize(vbCount); gpuInputAssembler->vertexBufferOffsets.resize(vbCount); } CCVKGPUDevice *gpuDevice = CCVKDevice::getInstance()->gpuDevice(); - for (uint i = 0U; i < vbCount; ++i) { + for (uint32_t i = 0U; i < vbCount; ++i) { gpuInputAssembler->vertexBuffers[i] = gpuInputAssembler->gpuVertexBuffers[i]->gpuBuffer->vkBuffer; gpuInputAssembler->vertexBufferOffsets[i] = gpuInputAssembler->gpuVertexBuffers[i]->getStartOffset(gpuDevice->curBackBufferIndex); } @@ -309,7 +309,7 @@ void CCVKCommandBuffer::setDepthBound(float minBounds, float maxBounds) { } } -void CCVKCommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { +void CCVKCommandBuffer::setStencilWriteMask(StencilFace face, uint32_t mask) { DynamicStencilStates &front = _curDynamicStates.stencilStatesFront; DynamicStencilStates &back = _curDynamicStates.stencilStatesBack; if (face == StencilFace::ALL) { @@ -327,7 +327,7 @@ void CCVKCommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { } } -void CCVKCommandBuffer::setStencilCompareMask(StencilFace face, uint reference, uint mask) { +void CCVKCommandBuffer::setStencilCompareMask(StencilFace face, uint32_t reference, uint32_t mask) { DynamicStencilStates &front = _curDynamicStates.stencilStatesFront; DynamicStencilStates &back = _curDynamicStates.stencilStatesBack; if (face == StencilFace::ALL) { @@ -364,7 +364,7 @@ void CCVKCommandBuffer::draw(const DrawInfo &info) { const auto *gpuIndirectBuffer = _curGPUInputAssember->gpuIndirectBuffer; if (gpuIndirectBuffer) { - uint drawInfoCount = gpuIndirectBuffer->range / gpuIndirectBuffer->gpuBuffer->stride; + uint32_t drawInfoCount = gpuIndirectBuffer->range / gpuIndirectBuffer->gpuBuffer->stride; CCVKGPUDevice *gpuDevice = CCVKDevice::getInstance()->gpuDevice(); VkDeviceSize offset = gpuIndirectBuffer->getStartOffset(gpuDevice->curBackBufferIndex); if (gpuDevice->useMultiDrawIndirect) { @@ -401,8 +401,8 @@ void CCVKCommandBuffer::draw(const DrawInfo &info) { } } } else { - uint instanceCount = std::max(info.instanceCount, 1U); - bool hasIndexBuffer = _curGPUInputAssember->gpuIndexBuffer && info.indexCount > 0; + uint32_t instanceCount = std::max(info.instanceCount, 1U); + bool hasIndexBuffer = _curGPUInputAssember->gpuIndexBuffer && info.indexCount > 0; if (hasIndexBuffer) { vkCmdDrawIndexed(_gpuCommandBuffer->vkCommandBuffer, info.indexCount, instanceCount, @@ -415,7 +415,7 @@ void CCVKCommandBuffer::draw(const DrawInfo &info) { ++_numDrawCalls; _numInstances += info.instanceCount; if (_curGPUPipelineState) { - uint indexCount = hasIndexBuffer ? info.indexCount : info.vertexCount; + uint32_t indexCount = hasIndexBuffer ? info.indexCount : info.vertexCount; switch (_curGPUPipelineState->primitive) { case PrimitiveMode::TRIANGLE_LIST: _numTriangles += indexCount / 3 * instanceCount; @@ -430,12 +430,12 @@ void CCVKCommandBuffer::draw(const DrawInfo &info) { } } -void CCVKCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint count) { +void CCVKCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t count) { if (!count) return; _vkCommandBuffers.resize(count); - uint validCount = 0U; - for (uint i = 0U; i < count; ++i) { + uint32_t validCount = 0U; + for (uint32_t i = 0U; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingQueue.empty()) { _vkCommandBuffers[validCount++] = cmdBuff->_pendingQueue.front(); @@ -452,16 +452,16 @@ void CCVKCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint count) { } } -void CCVKCommandBuffer::updateBuffer(Buffer *buffer, const void *data, uint size) { +void CCVKCommandBuffer::updateBuffer(Buffer *buffer, const void *data, uint32_t size) { CCVKGPUBuffer *gpuBuffer = static_cast(buffer)->gpuBuffer(); cmdFuncCCVKUpdateBuffer(CCVKDevice::getInstance(), gpuBuffer, data, size, _gpuCommandBuffer); } -void CCVKCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +void CCVKCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) { cmdFuncCCVKCopyBuffersToTexture(CCVKDevice::getInstance(), buffers, static_cast(texture)->gpuTexture(), regions, count, _gpuCommandBuffer); } -void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { +void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) { VkImageAspectFlags srcAspectMask = VK_IMAGE_ASPECT_COLOR_BIT; VkImageAspectFlags dstAspectMask = VK_IMAGE_ASPECT_COLOR_BIT; VkImage srcImage = VK_NULL_HANDLE; @@ -499,7 +499,7 @@ void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, co } _blitRegions.resize(count); - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { const TextureBlit ®ion = regions[i]; _blitRegions[i].srcSubresource.aspectMask = srcAspectMask; _blitRegions[i].srcSubresource.mipLevel = region.srcSubres.mipLevel; @@ -551,27 +551,27 @@ void CCVKCommandBuffer::bindDescriptorSets(VkPipelineBindPoint bindPoint) { CCVKDevice * device = CCVKDevice::getInstance(); CCVKGPUDevice * gpuDevice = device->gpuDevice(); CCVKGPUPipelineLayout *pipelineLayout = _curGPUPipelineState->gpuPipelineLayout; - vector & dynamicOffsetOffsets = pipelineLayout->dynamicOffsetOffsets; - uint descriptorSetCount = utils::toUint(pipelineLayout->setLayouts.size()); + vector & dynamicOffsetOffsets = pipelineLayout->dynamicOffsetOffsets; + uint32_t descriptorSetCount = utils::toUint(pipelineLayout->setLayouts.size()); _curDynamicOffsets.resize(pipelineLayout->dynamicOffsetCount); - uint dirtyDescriptorSetCount = descriptorSetCount - _firstDirtyDescriptorSet; - for (uint i = _firstDirtyDescriptorSet; i < descriptorSetCount; ++i) { + uint32_t dirtyDescriptorSetCount = descriptorSetCount - _firstDirtyDescriptorSet; + for (uint32_t i = _firstDirtyDescriptorSet; i < descriptorSetCount; ++i) { if (_curGPUDescriptorSets[i]) { const CCVKGPUDescriptorSet::Instance &instance = _curGPUDescriptorSets[i]->instances[gpuDevice->curBackBufferIndex]; _curVkDescriptorSets[i] = instance.vkDescriptorSet; } else { _curVkDescriptorSets[i] = pipelineLayout->setLayouts[i]->defaultDescriptorSet; } - uint count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; + uint32_t count = dynamicOffsetOffsets[i + 1] - dynamicOffsetOffsets[i]; //CCASSERT(_curDynamicOffsetCounts[i] >= count, "missing dynamic offsets?"); count = std::min(count, utils::toUint(_curDynamicOffsetsArray[i].size())); - if (count > 0) memcpy(&_curDynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsetsArray[i].data(), count * sizeof(uint)); + if (count > 0) memcpy(&_curDynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsetsArray[i].data(), count * sizeof(uint32_t)); } - uint dynamicOffsetStartIndex = dynamicOffsetOffsets[_firstDirtyDescriptorSet]; - uint dynamicOffsetEndIndex = dynamicOffsetOffsets[_firstDirtyDescriptorSet + dirtyDescriptorSetCount]; - uint dynamicOffsetCount = dynamicOffsetEndIndex - dynamicOffsetStartIndex; + uint32_t dynamicOffsetStartIndex = dynamicOffsetOffsets[_firstDirtyDescriptorSet]; + uint32_t dynamicOffsetEndIndex = dynamicOffsetOffsets[_firstDirtyDescriptorSet + dirtyDescriptorSetCount]; + uint32_t dynamicOffsetCount = dynamicOffsetEndIndex - dynamicOffsetStartIndex; vkCmdBindDescriptorSets(_gpuCommandBuffer->vkCommandBuffer, bindPoint, pipelineLayout->vkPipelineLayout, _firstDirtyDescriptorSet, dirtyDescriptorSetCount, @@ -587,8 +587,8 @@ void CCVKCommandBuffer::dispatch(const DispatchInfo &info) { } if (info.indirectBuffer) { - CCVKGPUDevice *gpuDevice = CCVKDevice::getInstance()->gpuDevice(); - auto *indirectBuffer = static_cast(info.indirectBuffer); + CCVKGPUDevice *gpuDevice = CCVKDevice::getInstance()->gpuDevice(); + auto * indirectBuffer = static_cast(info.indirectBuffer); vkCmdDispatchIndirect(_gpuCommandBuffer->vkCommandBuffer, indirectBuffer->gpuBuffer()->vkBuffer, indirectBuffer->gpuBufferView()->getStartOffset(gpuDevice->curBackBufferIndex) + info.indirectOffset); } else { @@ -596,11 +596,11 @@ void CCVKCommandBuffer::dispatch(const DispatchInfo &info) { } } -void CCVKCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) { +void CCVKCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) { VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; VkMemoryBarrier const * pMemoryBarrier = nullptr; - uint memoryBarrierCount = 0U; + uint32_t memoryBarrierCount = 0U; VkImageMemoryBarrier const *pImageMemoryBarriers = nullptr; if (barrier) { @@ -615,7 +615,7 @@ void CCVKCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const Text _imageMemoryBarriers.resize(textureBarrierCount); pImageMemoryBarriers = _imageMemoryBarriers.data(); - for (uint i = 0U; i < textureBarrierCount; ++i) { + for (uint32_t i = 0U; i < textureBarrierCount; ++i) { const auto *gpuBarrier = static_cast(textureBarriers[i])->gpuBarrier(); auto * gpuTexture = static_cast(textures[i])->gpuTexture(); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h index 07be54f84c..3997a238fd 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h @@ -37,12 +37,12 @@ public: CCVKCommandBuffer(); ~CCVKCommandBuffer() override; - void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override; void end() override; - void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override; void endRenderPass() override; void bindPipelineState(PipelineState *pso) override; - void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override; void bindInputAssembler(InputAssembler *ia) override; void setViewport(const Viewport &vp) override; void setScissor(const Rect &rect) override; @@ -50,16 +50,16 @@ public: void setDepthBias(float constant, float clamp, float slope) override; void setBlendConstants(const Color &constants) override; void setDepthBound(float minBounds, float maxBounds) override; - void setStencilWriteMask(StencilFace face, uint mask) override; - void setStencilCompareMask(StencilFace face, uint reference, uint mask) override; + void setStencilWriteMask(StencilFace face, uint32_t mask) override; + void setStencilCompareMask(StencilFace face, uint32_t reference, uint32_t mask) override; void nextSubpass() override; void draw(const DrawInfo &info) override; - void updateBuffer(Buffer *buffer, const void *data, uint size) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; - void execute(CommandBuffer *const *cmdBuffs, uint count) override; + void updateBuffer(Buffer *buffer, const void *data, uint32_t size) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override; + void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override; + void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; void dispatch(const DispatchInfo &info) override; - void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override; CCVKGPUCommandBuffer *gpuCommandBuffer() const { return _gpuCommandBuffer; } @@ -76,9 +76,9 @@ protected: CCVKGPUPipelineState * _curGPUPipelineState = nullptr; vector _curGPUDescriptorSets; vector _curVkDescriptorSets; - vector _curDynamicOffsets; - vector> _curDynamicOffsetsArray; - uint _firstDirtyDescriptorSet = UINT_MAX; + vector _curDynamicOffsets; + vector> _curDynamicOffsetsArray; + uint32_t _firstDirtyDescriptorSet = UINT_MAX; CCVKGPUInputAssembler *_curGPUInputAssember = nullptr; CCVKGPUFramebuffer * _curGPUFBO = nullptr; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index 31be2dd115..9ea5efdf08 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -45,15 +45,13 @@ CCVKGPUCommandBufferPool *CCVKGPUDevice::getCommandBufferPool() { return _commandBufferPools[threadID]; } -CCVKGPUDescriptorSetPool *CCVKGPUDevice::getDescriptorSetPool(uint layoutID) { +CCVKGPUDescriptorSetPool *CCVKGPUDevice::getDescriptorSetPool(uint32_t layoutID) { return &_descriptorSetPools[layoutID]; } void insertVkDynamicStates(vector *out, const vector &dynamicStates) { for (DynamicStateFlagBit dynamicState : dynamicStates) { switch (dynamicState) { - case DynamicStateFlagBit::VIEWPORT: - case DynamicStateFlagBit::SCISSOR: break; // we make this dynamic by default case DynamicStateFlagBit::LINE_WIDTH: out->push_back(VK_DYNAMIC_STATE_LINE_WIDTH); break; case DynamicStateFlagBit::DEPTH_BIAS: out->push_back(VK_DYNAMIC_STATE_DEPTH_BIAS); break; case DynamicStateFlagBit::BLEND_CONSTANTS: out->push_back(VK_DYNAMIC_STATE_BLEND_CONSTANTS); break; @@ -73,7 +71,7 @@ void insertVkDynamicStates(vector *out, const vectorpossibleQueueFamilyIndices.empty()) { - uint queueType = 0U; + uint32_t queueType = 0U; switch (gpuQueue->type) { case QueueType::GRAPHICS: queueType = VK_QUEUE_GRAPHICS_BIT; break; case QueueType::COMPUTE: queueType = VK_QUEUE_COMPUTE_BIT; break; @@ -82,8 +80,8 @@ void cmdFuncCCVKGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) { const CCVKGPUContext *context = device->gpuContext(); - uint queueCount = utils::toUint(context->queueFamilyProperties.size()); - for (uint i = 0U; i < queueCount; ++i) { + uint32_t queueCount = utils::toUint(context->queueFamilyProperties.size()); + for (uint32_t i = 0U; i < queueCount; ++i) { const VkQueueFamilyProperties &properties = context->queueFamilyProperties[i]; if (properties.queueCount > 0 && (properties.queueFlags & queueType)) { gpuQueue->possibleQueueFamilyIndices.push_back(i); @@ -271,15 +269,69 @@ void cmdFuncCCVKCreateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer) { if (hasFlag(gpuBuffer->usage, BufferUsageBit::INDIRECT)) gpuBuffer->renderAccessTypes.push_back(THSVS_ACCESS_INDIRECT_BUFFER); } +struct AttachmentStatistics final { + enum class SubpassUsage { + COLOR = 0x1, + COLOR_RESOLVE = 0x2, + DEPTH = 0x4, + DEPTH_RESOLVE = 0x8, + INPUT = 0x10, + }; + struct SubpassRef final { + VkImageLayout layout{VK_IMAGE_LAYOUT_UNDEFINED}; + SubpassUsage usage{SubpassUsage::COLOR}; + + bool hasDepth() const { return usage == SubpassUsage::DEPTH || usage == SubpassUsage::DEPTH_RESOLVE; } + }; + + uint32_t loadSubpass{VK_SUBPASS_EXTERNAL}; + uint32_t storeSubpass{VK_SUBPASS_EXTERNAL}; + map records; // ordered + + void clear() { + loadSubpass = VK_SUBPASS_EXTERNAL; + storeSubpass = VK_SUBPASS_EXTERNAL; + records.clear(); + } +}; +CC_ENUM_BITWISE_OPERATORS(AttachmentStatistics::SubpassUsage) + +struct SubpassDependencyManager final { + vector subpassDependencies; + + void clear() { + subpassDependencies.clear(); + _hashes.clear(); + } + + void append(const VkSubpassDependency2 &dependency) { + uint32_t hash = 6U; + hash ^= (dependency.srcSubpass) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= (dependency.srcStageMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= (dependency.srcAccessMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= (dependency.dstSubpass) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= (dependency.dstStageMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + hash ^= (dependency.dstAccessMask) + 0x9e3779b9 + (hash << 6) + (hash >> 2); + + if (_hashes.count(hash)) return; + subpassDependencies.push_back(dependency); + _hashes.insert(hash); + } + +private: + unordered_set _hashes; +}; + void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRenderPass) { static vector depthStencilResolves; static vector attachmentDescriptions; static vector attachmentReferences; static vector subpassDescriptions; - static vector subpassDependencies; static vector accessTypeCaches; static vector beginAccessInfos; static vector endAccessInfos; + static vector attachmentStatistics; + static SubpassDependencyManager dependencyManager; const size_t colorAttachmentCount = gpuRenderPass->colorAttachments.size(); const size_t hasDepth = gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN ? 1 : 0; @@ -362,33 +414,31 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende for (const auto &subpassInfo : gpuRenderPass->subpasses) { VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT; - for (uint input : subpassInfo.inputs) { + for (uint32_t input : subpassInfo.inputs) { VkImageLayout layout = gpuRenderPass->colorAttachments[input].isGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, input, layout, VK_IMAGE_ASPECT_COLOR_BIT}); } - for (uint color : subpassInfo.colors) { + for (uint32_t color : subpassInfo.colors) { const ColorAttachment & desc = gpuRenderPass->colorAttachments[color]; const VkAttachmentDescription2 &attachment = attachmentDescriptions[color]; VkImageLayout layout = desc.isGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, color, layout, VK_IMAGE_ASPECT_COLOR_BIT}); sampleCount = std::max(sampleCount, attachment.samples); } - for (uint resolve : subpassInfo.resolves) { + for (uint32_t resolve : subpassInfo.resolves) { VkImageLayout layout = gpuRenderPass->colorAttachments[resolve].isGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, resolve, layout, VK_IMAGE_ASPECT_COLOR_BIT}); } - Format dsFormat{Format::UNKNOWN}; if (subpassInfo.depthStencil != INVALID_BINDING) { - bool isGeneralLayout{false}; - uint attachmentIdx = subpassInfo.depthStencil; + Format dsFormat{Format::UNKNOWN}; + bool isGeneralLayout{false}; if (subpassInfo.depthStencil >= colorAttachmentCount) { const DepthStencilAttachment & desc = gpuRenderPass->depthStencilAttachment; const VkAttachmentDescription2 &attachment = attachmentDescriptions.back(); isGeneralLayout = desc.isGeneralLayout; dsFormat = desc.format; sampleCount = std::max(sampleCount, attachment.samples); - attachmentIdx = utils::toUint(colorAttachmentCount); } else { const ColorAttachment & desc = gpuRenderPass->colorAttachments[subpassInfo.depthStencil]; const VkAttachmentDescription2 &attachment = attachmentDescriptions[subpassInfo.depthStencil]; @@ -401,27 +451,41 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT; VkImageLayout layout = isGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, attachmentIdx, layout, aspect}); + attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, subpassInfo.depthStencil, layout, aspect}); + } + + if (subpassInfo.depthStencilResolve != INVALID_BINDING) { + Format dsFormat{Format::UNKNOWN}; + bool isGeneralLayout{false}; + if (subpassInfo.depthStencil >= colorAttachmentCount) { + const DepthStencilAttachment & desc = gpuRenderPass->depthStencilAttachment; + const VkAttachmentDescription2 &attachment = attachmentDescriptions.back(); + isGeneralLayout = desc.isGeneralLayout; + dsFormat = desc.format; + sampleCount = std::max(sampleCount, attachment.samples); + } else { + const ColorAttachment & desc = gpuRenderPass->colorAttachments[subpassInfo.depthStencil]; + const VkAttachmentDescription2 &attachment = attachmentDescriptions[subpassInfo.depthStencil]; + isGeneralLayout = desc.isGeneralLayout; + dsFormat = desc.format; + sampleCount = std::max(sampleCount, attachment.samples); + } + + VkImageAspectFlags aspect = GFX_FORMAT_INFOS[toNumber(dsFormat)].hasStencil + ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT + : VK_IMAGE_ASPECT_DEPTH_BIT; + VkImageLayout layout = isGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, subpassInfo.depthStencilResolve, layout, aspect}); } gpuRenderPass->sampleCounts.push_back(sampleCount); - - if (subpassInfo.depthStencilResolve != INVALID_BINDING) { - const ColorAttachment &desc = gpuRenderPass->colorAttachments[subpassInfo.depthStencilResolve]; - - VkImageAspectFlags aspect = GFX_FORMAT_INFOS[toNumber(desc.format)].hasStencil - ? VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT - : VK_IMAGE_ASPECT_DEPTH_BIT; - VkImageLayout layout = desc.isGeneralLayout ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - attachmentReferences.push_back({VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2, nullptr, subpassInfo.depthStencilResolve, layout, aspect}); - } } size_t offset{0U}; subpassDescriptions.assign(subpassCount, {VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2}); // init to zeros first depthStencilResolves.resize(subpassCount, {VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE}); const VkPhysicalDeviceDepthStencilResolveProperties &prop{device->gpuContext()->physicalDeviceDepthStencilResolveProperties}; - for (uint i = 0U; i < gpuRenderPass->subpasses.size(); ++i) { + for (uint32_t i = 0U; i < gpuRenderPass->subpasses.size(); ++i) { const SubpassInfo subpassInfo = gpuRenderPass->subpasses[i]; VkSubpassDescription2 &desc = subpassDescriptions[i]; @@ -479,7 +543,7 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende size_t dependencyCount = gpuRenderPass->dependencies.size(); accessTypeCaches.clear(); - subpassDependencies.clear(); + dependencyManager.clear(); if (dependencyCount) { for (const auto &dependency : gpuRenderPass->dependencies) { @@ -495,13 +559,12 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende VkImageLayout imageLayout{VK_IMAGE_LAYOUT_UNDEFINED}; bool hasWriteAccess{false}; - for (uint i = 0U; i < dependencyCount; ++i) { + for (uint32_t i = 0U; i < dependencyCount; ++i) { const SubpassDependency &dependency = gpuRenderPass->dependencies[i]; - subpassDependencies.push_back({VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2}); - VkSubpassDependency2 &vkDependency = subpassDependencies.back(); - vkDependency.srcSubpass = dependency.srcSubpass; - vkDependency.dstSubpass = dependency.dstSubpass; - vkDependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; + VkSubpassDependency2 vkDependency{VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2}; + vkDependency.srcSubpass = dependency.srcSubpass; + vkDependency.dstSubpass = dependency.dstSubpass; + vkDependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; thsvsGetAccessInfo( utils::toUint(dependency.srcAccesses.size()), @@ -519,109 +582,149 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende &vkDependency.dstAccessMask, &imageLayout, &hasWriteAccess); + dependencyManager.append(vkDependency); + offset += dependency.dstAccesses.size(); } } else { // try to deduce dependencies if not specified - // wait for resources to become available by the specified access types - VkSubpassDependency2 beginDependency{VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, nullptr, - VK_SUBPASS_EXTERNAL, 0, - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT}; - - auto beginDependencyCheck = [&beginDependency](const VkAttachmentReference2 &ref, VkPipelineStageFlags dstStage, - VkPipelineStageFlags dstAccessRead, VkAccessFlags dstAccessWrite) { - const VkAttachmentDescription2 &desc = attachmentDescriptions[ref.attachment]; - const CCVKAccessInfo & info = beginAccessInfos[ref.attachment]; - if (desc.loadOp == VK_ATTACHMENT_LOAD_OP_DONT_CARE) return; - if (desc.initialLayout != ref.layout || info.hasWriteAccess || desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { - beginDependency.srcStageMask |= info.stageMask; - beginDependency.dstStageMask |= dstStage; - beginDependency.srcAccessMask |= info.hasWriteAccess ? info.accessMask : 0; - beginDependency.dstAccessMask |= (desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? dstAccessWrite : dstAccessRead); + // first, gather necessary statistics for each attachment + auto updateLifeCycle = [subpassCount](AttachmentStatistics &statistics, uint32_t index, VkImageLayout layout, AttachmentStatistics::SubpassUsage usage) { + if (statistics.records.count(index)) { + CC_ASSERT(statistics.records[index].layout == layout); + statistics.records[index].usage |= usage; + } else { + statistics.records[index] = {layout, usage}; } + if (statistics.loadSubpass == VK_SUBPASS_EXTERNAL) statistics.loadSubpass = index; + statistics.storeSubpass = index; }; - VkSubpassDescription2 &firstSubpass = subpassDescriptions[0]; - for (size_t j = 0U; j < firstSubpass.colorAttachmentCount; ++j) { - beginDependencyCheck(firstSubpass.pColorAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); - if (firstSubpass.pResolveAttachments) { - beginDependencyCheck(firstSubpass.pResolveAttachments[j], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, - VK_ACCESS_COLOR_ATTACHMENT_READ_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); - } - } - if (firstSubpass.pDepthStencilAttachment) { - beginDependencyCheck(*firstSubpass.pDepthStencilAttachment, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT); - } - if (depthStencilResolves[0].pDepthStencilResolveAttachment) { - beginDependencyCheck(*depthStencilResolves[0].pDepthStencilResolveAttachment, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT, - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT); - } - if (beginDependency.srcStageMask != VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT) { - subpassDependencies.push_back(beginDependency); - } - - // make rendering result visible for the specified access types - VkSubpassDependency2 endDependency{VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, nullptr, - static_cast(subpassCount) - 1, VK_SUBPASS_EXTERNAL, - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT}; - - auto endDependencyCheck = [&endDependency](const VkAttachmentReference2 &ref, VkPipelineStageFlags srcStage, VkAccessFlags srcAccess) { - const VkAttachmentDescription2 &desc = attachmentDescriptions[ref.attachment]; - if (desc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) { - const CCVKAccessInfo &info = endAccessInfos[ref.attachment]; - endDependency.srcStageMask |= srcStage; - endDependency.srcAccessMask |= srcAccess; - endDependency.dstStageMask |= info.stageMask; - endDependency.dstAccessMask |= info.accessMask; - } - }; - VkSubpassDescription2 &lastSubpass = subpassDescriptions[subpassCount - 1]; - for (size_t j = 0U; j < lastSubpass.colorAttachmentCount; ++j) { - endDependencyCheck(lastSubpass.pColorAttachments[j], - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); - if (lastSubpass.pResolveAttachments) { - endDependencyCheck(lastSubpass.pResolveAttachments[j], - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); - } - } - if (lastSubpass.pDepthStencilAttachment) { - endDependencyCheck(*lastSubpass.pDepthStencilAttachment, - VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT); - } - if (gpuRenderPass->subpasses[subpassCount - 1].depthStencilResolve != INVALID_BINDING) { - endDependencyCheck(*depthStencilResolves[subpassCount - 1].pDepthStencilResolveAttachment, - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); - } - if (endDependency.dstAccessMask) { - subpassDependencies.push_back(endDependency); - } - - auto findSrcSubpass = [](uint dstSubpass, const VkSubpassDescription2 &target) { - for (uint j = 0; j < dstSubpass; ++j) { - const auto &desc = subpassDescriptions[j]; - for (uint k = 0; k < target.inputAttachmentCount; ++k) { - uint idx = target.pInputAttachments[k].attachment; - for (uint l = 0; l < desc.colorAttachmentCount; ++l) { - if (desc.pColorAttachments[l].attachment == idx) { - return j; - } + auto calculateLifeCycle = [&](uint32_t targetAttachment, AttachmentStatistics &statistics) { + for (size_t j = 0U; j < subpassCount; ++j) { + auto &subpass = subpassDescriptions[j]; + for (size_t k = 0U; k < subpass.colorAttachmentCount; ++k) { + if (subpass.pColorAttachments[k].attachment == targetAttachment) { + updateLifeCycle(statistics, j, subpass.pColorAttachments[k].layout, AttachmentStatistics::SubpassUsage::COLOR); + } + if (subpass.pResolveAttachments && subpass.pResolveAttachments[k].attachment == targetAttachment) { + updateLifeCycle(statistics, j, subpass.pResolveAttachments[k].layout, AttachmentStatistics::SubpassUsage::COLOR_RESOLVE); } } + for (size_t k = 0U; k < subpass.inputAttachmentCount; ++k) { + if (subpass.pInputAttachments[k].attachment == targetAttachment) { + updateLifeCycle(statistics, j, subpass.pInputAttachments[k].layout, AttachmentStatistics::SubpassUsage::INPUT); + } + } + if (subpass.pDepthStencilAttachment->attachment == targetAttachment) { + updateLifeCycle(statistics, j, subpass.pDepthStencilAttachment->layout, AttachmentStatistics::SubpassUsage::DEPTH); + } + if (depthStencilResolves[j].pDepthStencilResolveAttachment && + depthStencilResolves[j].pDepthStencilResolveAttachment->attachment == targetAttachment) { + updateLifeCycle(statistics, j, depthStencilResolves[j].pDepthStencilResolveAttachment->layout, AttachmentStatistics::SubpassUsage::DEPTH_RESOLVE); + } } - return VK_SUBPASS_EXTERNAL; }; + attachmentStatistics.resize(colorAttachmentCount + hasDepth); + for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) { + attachmentStatistics[i].clear(); + calculateLifeCycle(i, attachmentStatistics[i]); + CC_ASSERT(attachmentStatistics[i].loadSubpass != VK_SUBPASS_EXTERNAL && + attachmentStatistics[i].storeSubpass != VK_SUBPASS_EXTERNAL); + } - // find input attachment dependencies - for (uint i = 0; i < subpassDescriptions.size(); ++i) { - const auto &target = subpassDescriptions[i]; - if (target.inputAttachmentCount) { - subpassDependencies.push_back({VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, nullptr, - findSrcSubpass(i, target), i, - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, - VK_DEPENDENCY_BY_REGION_BIT}); + // wait for resources to become available (begin accesses) + auto beginDependencyCheck = [](VkSubpassDependency2 &dependency, uint32_t attachment, const AttachmentStatistics::SubpassRef &ref) { + const VkAttachmentDescription2 &desc = attachmentDescriptions[attachment]; + const CCVKAccessInfo & info = beginAccessInfos[attachment]; + if (desc.initialLayout != ref.layout || info.hasWriteAccess || desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { + VkPipelineStageFlagBits dstStage{ref.hasDepth() ? VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; + VkAccessFlagBits dstAccessRead{ref.hasDepth() ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT : VK_ACCESS_COLOR_ATTACHMENT_READ_BIT}; + VkAccessFlagBits dstAccessWrite{ref.hasDepth() ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT}; + dependency.srcStageMask |= info.stageMask; + dependency.dstStageMask |= dstStage; + dependency.srcAccessMask |= info.hasWriteAccess ? info.accessMask : 0; + dependency.dstAccessMask |= (desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? dstAccessWrite : dstAccessRead); + return true; + } + return false; + }; + VkSubpassDependency2 beginDependency; + uint32_t lastLoadSubpass{VK_SUBPASS_EXTERNAL}; + bool beginDependencyValid{false}; + for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) { + auto &statistics = attachmentStatistics[i]; + if (lastLoadSubpass != statistics.loadSubpass) { + if (beginDependencyValid) dependencyManager.append(beginDependency); + beginDependency = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, nullptr, + VK_SUBPASS_EXTERNAL, statistics.loadSubpass, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT}; + lastLoadSubpass = statistics.loadSubpass; + beginDependencyValid = false; + } + beginDependencyValid |= beginDependencyCheck(beginDependency, i, statistics.records[statistics.loadSubpass]); + } + if (beginDependencyValid) dependencyManager.append(beginDependency); + + // make rendering result visible (end accesses) + auto endDependencyCheck = [](VkSubpassDependency2 &dependency, uint32_t attachment, const AttachmentStatistics::SubpassRef &ref) { + const VkAttachmentDescription2 &desc = attachmentDescriptions[attachment]; + const CCVKAccessInfo & info = endAccessInfos[attachment]; + if (desc.initialLayout != ref.layout || info.hasWriteAccess || desc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) { + VkPipelineStageFlagBits srcStage{ref.hasDepth() ? VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; + VkAccessFlagBits srcAccess{ref.hasDepth() ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT}; + dependency.srcStageMask |= srcStage; + dependency.srcAccessMask |= srcAccess; + dependency.dstStageMask |= info.stageMask; + dependency.dstAccessMask |= info.accessMask; + return true; + } + return false; + }; + VkSubpassDependency2 endDependency; + uint32_t lastStoreSubpass{VK_SUBPASS_EXTERNAL}; + bool endDependencyValid{false}; + for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) { + auto &statistics = attachmentStatistics[i]; + if (lastStoreSubpass != statistics.storeSubpass) { + if (endDependencyValid) dependencyManager.append(endDependency); + endDependency = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, nullptr, + statistics.storeSubpass, VK_SUBPASS_EXTERNAL, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT}; + lastStoreSubpass = statistics.storeSubpass; + endDependencyValid = false; + } + endDependencyValid |= endDependencyCheck(endDependency, i, statistics.records[statistics.storeSubpass]); + } + if (endDependencyValid) dependencyManager.append(endDependency); + + // other transitioning dependencies + auto mapAccessFlags = [](AttachmentStatistics::SubpassUsage usage) { + // there may be more kind of dependencies + if (hasFlag(usage, AttachmentStatistics::SubpassUsage::INPUT)) { + return std::make_pair(VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT); + } + return std::make_pair(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT); + }; + auto genDependency = [&](uint32_t srcIdx, AttachmentStatistics::SubpassUsage srcUsage, + uint32_t dstIdx, AttachmentStatistics::SubpassUsage dstUsage) { + VkSubpassDependency2 dependency{VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2, nullptr, srcIdx, dstIdx}; + std::tie(dependency.srcStageMask, dependency.srcAccessMask) = mapAccessFlags(srcUsage); + std::tie(dependency.dstStageMask, dependency.dstAccessMask) = mapAccessFlags(dstUsage); + dependency.dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT; + return dependency; + }; + for (size_t i = 0U; i < colorAttachmentCount + hasDepth; ++i) { + auto &statistics{attachmentStatistics[i]}; + + const AttachmentStatistics::SubpassRef *prevRef{nullptr}; + uint32_t prevIdx{0U}; + for (const auto &it : statistics.records) { + if (prevRef && prevRef->usage != it.second.usage) { + dependencyManager.append(genDependency(prevIdx, prevRef->usage, it.first, it.second.usage)); + } + prevIdx = it.first; + prevRef = &it.second; } } } @@ -631,8 +734,8 @@ void cmdFuncCCVKCreateRenderPass(CCVKDevice *device, CCVKGPURenderPass *gpuRende renderPassCreateInfo.pAttachments = attachmentDescriptions.data(); renderPassCreateInfo.subpassCount = utils::toUint(subpassDescriptions.size()); renderPassCreateInfo.pSubpasses = subpassDescriptions.data(); - renderPassCreateInfo.dependencyCount = utils::toUint(subpassDependencies.size()); - renderPassCreateInfo.pDependencies = subpassDependencies.data(); + renderPassCreateInfo.dependencyCount = utils::toUint(dependencyManager.subpassDependencies.size()); + renderPassCreateInfo.pDependencies = dependencyManager.subpassDependencies.data(); VK_CHECK(device->gpuDevice()->createRenderPass2(device->gpuDevice()->vkDevice, &renderPassCreateInfo, nullptr, &gpuRenderPass->vkRenderPass)); @@ -643,7 +746,7 @@ void cmdFuncCCVKCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra bool hasDepth = gpuFramebuffer->gpuRenderPass->depthStencilAttachment.format != Format::UNKNOWN; vector attachments(colorViewCount + hasDepth); - uint swapchainImageIndices = 0; + uint32_t swapchainImageIndices = 0; for (size_t i = 0U; i < colorViewCount; ++i) { CCVKGPUTextureView *texView = gpuFramebuffer->gpuColorViews[i]; if (texView->gpuTexture->swapchain) { @@ -786,7 +889,7 @@ void cmdFuncCCVKCreatePipelineLayout(CCVKDevice *device, CCVKGPUPipelineLayout * size_t layoutCount = gpuPipelineLayout->setLayouts.size(); vector descriptorSetLayouts(layoutCount); - for (uint i = 0; i < layoutCount; ++i) { + for (uint32_t i = 0; i < layoutCount; ++i) { descriptorSetLayouts[i] = gpuPipelineLayout->setLayouts[i]->vkDescriptorSetLayout; } @@ -820,7 +923,7 @@ void cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS static vector stageInfos; static vector bindingDescriptions; static vector attributeDescriptions; - static vector offsets; + static vector offsets; static vector dynamicStates; static vector blendTargets; @@ -844,14 +947,14 @@ void cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS const AttributeList &attributes = gpuPipelineState->inputState.attributes; const size_t attributeCount = attributes.size(); - uint bindingCount = 1U; + uint32_t bindingCount = 1U; for (size_t i = 0U; i < attributeCount; ++i) { const Attribute &attr = attributes[i]; bindingCount = std::max(bindingCount, attr.stream + 1); } bindingDescriptions.resize(bindingCount); - for (uint i = 0U; i < bindingCount; ++i) { + for (uint32_t i = 0U; i < bindingCount; ++i) { bindingDescriptions[i].binding = i; bindingDescriptions[i].stride = 0; bindingDescriptions[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; @@ -1022,7 +1125,7 @@ void cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineS 1, &createInfo, nullptr, &gpuPipelineState->vkPipeline)); } -void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint size, const CCVKGPUCommandBuffer *cmdBuffer) { +void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint32_t size, const CCVKGPUCommandBuffer *cmdBuffer) { if (!gpuBuffer) return; const void *dataToUpload = nullptr; @@ -1063,7 +1166,7 @@ void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const } // back buffer instances update command - uint backBufferIndex = device->gpuDevice()->curBackBufferIndex; + uint32_t backBufferIndex = device->gpuDevice()->curBackBufferIndex; if (gpuBuffer->instanceSize) { device->gpuBufferHub()->record(gpuBuffer, backBufferIndex, sizeToUpload, !cmdBuffer); if (!cmdBuffer) { @@ -1110,7 +1213,7 @@ void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const } void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, - const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { + const BufferTextureCopy *regions, uint32_t count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { vector &curTypes = gpuTexture->currentAccessTypes; ThsvsImageBarrier barrier{}; @@ -1139,18 +1242,18 @@ void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b 0, 1, &vkBarrier, 0, nullptr, 0, nullptr); } - uint totalSize = 0U; - vector regionSizes(count); + uint32_t totalSize = 0U; + vector regionSizes(count); for (size_t i = 0U; i < count; ++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; + uint32_t w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; + uint32_t 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; - uint texelSize = GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].size; + uint32_t texelSize = GFX_FORMAT_INFOS[toNumber(gpuTexture->format)].size; device->gpuStagingBufferPool()->alloc(&stagingBuffer, texelSize); vector stagingRegions(count); @@ -1193,7 +1296,7 @@ void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b barrier.pPrevAccesses = &THSVS_ACCESS_TYPES[toNumber(AccessType::TRANSFER_WRITE)]; barrier.pNextAccesses = &THSVS_ACCESS_TYPES[toNumber(AccessType::TRANSFER_READ)]; - for (uint i = 1U; i < gpuTexture->mipLevels; ++i) { + for (uint32_t i = 1U; i < gpuTexture->mipLevels; ++i) { barrier.subresourceRange.baseMipLevel = i - 1; cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier); @@ -1225,8 +1328,8 @@ void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *b device->gpuBarrierManager()->checkIn(gpuTexture); } -CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice * device, CCVKGPUTexture *srcTexture, CCVKGPUBuffer *destBuffer, - const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { +CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTexture *srcTexture, CCVKGPUBuffer *destBuffer, + const BufferTextureCopy *regions, uint32_t count, const CCVKGPUCommandBuffer *gpuCommandBuffer) { vector &curTypes = srcTexture->currentAccessTypes; ThsvsImageBarrier barrier{}; @@ -1240,7 +1343,7 @@ CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice * device, CCVKGPUT barrier.prevAccessCount = utils::toUint(curTypes.size()); barrier.pPrevAccesses = curTypes.data(); barrier.nextAccessCount = 1; - barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_READ)]; + barrier.pNextAccesses = &THSVS_ACCESS_TYPES[static_cast(AccessType::TRANSFER_READ)]; if (srcTexture->transferAccess != THSVS_ACCESS_TRANSFER_READ) { cmdFuncCCVKImageMemoryBarrier(gpuCommandBuffer, barrier); @@ -1258,9 +1361,9 @@ CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice * device, CCVKGPUT stagingRegion.imageOffset = {region.texOffset.x, region.texOffset.y, region.texOffset.z}; stagingRegion.imageExtent = {region.texExtent.width, region.texExtent.height, region.texExtent.depth}; - uint w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; - uint h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; - uint regionSize = formatSize(srcTexture->format, w, h, region.texExtent.depth); + uint32_t w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; + uint32_t h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; + uint32_t regionSize = formatSize(srcTexture->format, w, h, region.texExtent.depth); offset += regionSize; } @@ -1363,7 +1466,7 @@ void cmdFuncCCVKImageMemoryBarrier(const CCVKGPUCommandBuffer *gpuCommandBuffer, } void CCVKGPURecycleBin::clear() { - for (uint i = 0U; i < _count; ++i) { + for (uint32_t i = 0U; i < _count; ++i) { Resource &res = _resources[i]; switch (res.type) { case RecycledType::BUFFER: diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.h b/native/cocos/renderer/gfx-vulkan/VKCommands.h index 258e9369f6..11e236006f 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.h @@ -46,9 +46,9 @@ CC_VULKAN_API void cmdFuncCCVKCreatePipelineLayout(CCVKDevice *device, CCVKGPUPi CC_VULKAN_API void cmdFuncCCVKCreateGraphicsPipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); CC_VULKAN_API void cmdFuncCCVKCreateComputePipelineState(CCVKDevice *device, CCVKGPUPipelineState *gpuPipelineState); -CC_VULKAN_API void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint size, const CCVKGPUCommandBuffer *cmdBuffer = nullptr); -CC_VULKAN_API void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer); -CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTexture *srcTexture, CCVKGPUBuffer *destBuffer, const BufferTextureCopy *regions, uint count, const CCVKGPUCommandBuffer *gpuCommandBuffer); +CC_VULKAN_API void cmdFuncCCVKUpdateBuffer(CCVKDevice *device, CCVKGPUBuffer *gpuBuffer, const void *buffer, uint32_t size, const CCVKGPUCommandBuffer *cmdBuffer = nullptr); +CC_VULKAN_API void cmdFuncCCVKCopyBuffersToTexture(CCVKDevice *device, const uint8_t *const *buffers, CCVKGPUTexture *gpuTexture, const BufferTextureCopy *regions, uint32_t count, const CCVKGPUCommandBuffer *gpuCommandBuffer); +CC_VULKAN_API void cmdFuncCCVKCopyTextureToBuffers(CCVKDevice *device, CCVKGPUTexture *srcTexture, CCVKGPUBuffer *destBuffer, const BufferTextureCopy *regions, uint32_t count, const CCVKGPUCommandBuffer *gpuCommandBuffer); CC_VULKAN_API void cmdFuncCCVKDestroyRenderPass(CCVKGPUDevice *device, CCVKGPURenderPass *gpuRenderPass); CC_VULKAN_API void cmdFuncCCVKDestroySampler(CCVKGPUDevice *device, CCVKGPUSampler *gpuSampler); diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index ba126ba9b9..abf87901b1 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -48,8 +48,8 @@ CCVKDescriptorSet::~CCVKDescriptorSet() { void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); - uint bindingCount = utils::toUint(gpuDescriptorSetLayout->bindings.size()); - uint descriptorCount = gpuDescriptorSetLayout->descriptorCount; + uint32_t bindingCount = utils::toUint(gpuDescriptorSetLayout->bindings.size()); + uint32_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; _gpuDescriptorSet = CC_NEW(CCVKGPUDescriptorSet); _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount, {}); @@ -57,7 +57,7 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { for (size_t i = 0U, k = 0U; i < bindingCount; ++i) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; - for (uint j = 0; j < binding.count; ++j, ++k) { + for (uint32_t j = 0; j < binding.count; ++j, ++k) { CCVKGPUDescriptor &gpuDescriptor = _gpuDescriptorSet->gpuDescriptors[k]; gpuDescriptor.type = binding.descriptorType; switch (binding.descriptorType) { @@ -95,14 +95,14 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { _gpuDescriptorSet->gpuLayout = gpuDescriptorSetLayout; _gpuDescriptorSet->instances.resize(gpuDevice->backBufferCount); - for (uint t = 0U; t < gpuDevice->backBufferCount; ++t) { + for (uint32_t t = 0U; t < gpuDevice->backBufferCount; ++t) { CCVKGPUDescriptorSet::Instance &instance = _gpuDescriptorSet->instances[t]; instance.vkDescriptorSet = gpuDevice->getDescriptorSetPool(_gpuDescriptorSet->layoutID)->request(t); instance.descriptorInfos.resize(descriptorCount, {}); - for (uint i = 0U, k = 0U; i < bindingCount; ++i) { + for (uint32_t i = 0U, k = 0U; i < bindingCount; ++i) { const DescriptorSetLayoutBinding &binding = gpuDescriptorSetLayout->bindings[i]; - for (uint j = 0; j < binding.count; ++j, ++k) { + for (uint32_t j = 0; j < binding.count; ++j, ++k) { if (hasFlag(DESCRIPTOR_BUFFER_TYPE, binding.descriptorType)) { instance.descriptorInfos[k].buffer.buffer = gpuDevice->defaultBuffer.vkBuffer; instance.descriptorInfos[k].buffer.offset = gpuDevice->defaultBuffer.getStartOffset(t); @@ -121,9 +121,9 @@ void CCVKDescriptorSet::doInit(const DescriptorSetInfo & /*info*/) { vector &entries = instance.descriptorUpdateEntries; entries.resize(descriptorCount, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}); - for (uint i = 0U, j = 0U; i < bindingCount; i++) { + for (uint32_t i = 0U, j = 0U; i < bindingCount; i++) { const VkDescriptorSetLayoutBinding &descriptor = gpuDescriptorSetLayout->vkBindings[i]; - for (uint k = 0U; k < descriptor.descriptorCount; k++, j++) { + for (uint32_t k = 0U; k < descriptor.descriptorCount; k++, j++) { entries[j].dstSet = instance.vkDescriptorSet; entries[j].dstBinding = descriptor.binding; entries[j].dstArrayElement = k; @@ -159,12 +159,12 @@ void CCVKDescriptorSet::doDestroy() { if (_gpuDescriptorSet) { CCVKGPUDevice * gpuDevice = CCVKDevice::getInstance()->gpuDevice(); CCVKGPUDescriptorHub *descriptorHub = CCVKDevice::getInstance()->gpuDescriptorHub(); - uint instanceCount = utils::toUint(_gpuDescriptorSet->instances.size()); + uint32_t instanceCount = utils::toUint(_gpuDescriptorSet->instances.size()); - for (uint t = 0U; t < instanceCount; ++t) { + for (uint32_t t = 0U; t < instanceCount; ++t) { CCVKGPUDescriptorSet::Instance &instance = _gpuDescriptorSet->instances[t]; - for (uint i = 0U; i < _gpuDescriptorSet->gpuDescriptors.size(); i++) { + for (uint32_t i = 0U; i < _gpuDescriptorSet->gpuDescriptors.size(); i++) { CCVKGPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; CCVKDescriptorInfo &descriptorInfo = instance.descriptorInfos[i]; @@ -195,8 +195,8 @@ void CCVKDescriptorSet::update() { if (_isDirty && _gpuDescriptorSet) { CCVKGPUDescriptorHub * descriptorHub = CCVKDevice::getInstance()->gpuDescriptorHub(); CCVKGPUBarrierManager *layoutMgr = CCVKDevice::getInstance()->gpuBarrierManager(); - uint descriptorCount = utils::toUint(_gpuDescriptorSet->gpuDescriptors.size()); - uint instanceCount = utils::toUint(_gpuDescriptorSet->instances.size()); + uint32_t descriptorCount = utils::toUint(_gpuDescriptorSet->gpuDescriptors.size()); + uint32_t instanceCount = utils::toUint(_gpuDescriptorSet->instances.size()); for (size_t i = 0U; i < descriptorCount; i++) { CCVKGPUDescriptor &binding = _gpuDescriptorSet->gpuDescriptors[i]; @@ -205,7 +205,7 @@ void CCVKDescriptorSet::update() { if (_buffers[i]) { CCVKGPUBufferView *bufferView = static_cast(_buffers[i])->gpuBufferView(); if (binding.gpuBufferView != bufferView) { - for (uint t = 0U; t < instanceCount; ++t) { + for (uint32_t t = 0U; t < instanceCount; ++t) { CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->instances[t].descriptorInfos[i]; if (binding.gpuBufferView) { diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h index 6d1c58f4f2..74a38e7e99 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXDescriptorSet.h" namespace cc { @@ -35,7 +36,7 @@ class CCVKGPUDescriptorSet; class CC_VULKAN_API CCVKDescriptorSet final : public DescriptorSet { public: CCVKDescriptorSet(); - ~CCVKDescriptorSet(); + ~CCVKDescriptorSet() override; void update() override; diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp index 759cefd917..0aa8ba5921 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp @@ -52,7 +52,7 @@ void CCVKDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo& /*info*/) { for (auto& binding : _bindings) { if (hasAnyFlags(binding.descriptorType, DESCRIPTOR_DYNAMIC_TYPE)) { - for (uint j = 0U; j < binding.count; j++) { + for (uint32_t j = 0U; j < binding.count; j++) { _gpuDescriptorSetLayout->dynamicBindings.push_back(binding.binding); } } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h index f23d4d9c6b..801da2e9f3 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h @@ -23,9 +23,9 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_DESCRIPTOR_SET_LAYOUT_H_ -#define CC_GFXVULKAN_DESCRIPTOR_SET_LAYOUT_H_ +#pragma once +#include "VKStd.h" #include "gfx-base/GFXDescriptorSetLayout.h" namespace cc { @@ -36,14 +36,14 @@ class CCVKGPUDescriptorSetLayout; class CC_VULKAN_API CCVKDescriptorSetLayout final : public DescriptorSetLayout { public: CCVKDescriptorSetLayout(); - ~CCVKDescriptorSetLayout(); + ~CCVKDescriptorSetLayout() override; inline CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } protected: - static uint generateID() noexcept { - static uint _idGen = 10000; - return _idGen++; + static uint32_t generateID() noexcept { + static uint32_t idGen = 10000; + return idGen++; } void doInit(const DescriptorSetLayoutInfo &info) override; @@ -54,5 +54,3 @@ protected: } // namespace gfx } // namespace cc - -#endif // CC_GFXVULKAN_DESCRIPTOR_SET_LAYOUT_H_ diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index fefb4580a5..c1e343853f 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -131,12 +131,12 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { } // check extensions - uint availableLayerCount; + uint32_t availableLayerCount; VK_CHECK(vkEnumerateDeviceLayerProperties(_gpuContext->physicalDevice, &availableLayerCount, nullptr)); _gpuDevice->layers.resize(availableLayerCount); VK_CHECK(vkEnumerateDeviceLayerProperties(_gpuContext->physicalDevice, &availableLayerCount, _gpuDevice->layers.data())); - uint availableExtensionCount; + uint32_t availableExtensionCount; VK_CHECK(vkEnumerateDeviceExtensionProperties(_gpuContext->physicalDevice, nullptr, &availableExtensionCount, nullptr)); _gpuDevice->extensions.resize(availableExtensionCount); VK_CHECK(vkEnumerateDeviceExtensionProperties(_gpuContext->physicalDevice, nullptr, &availableExtensionCount, _gpuDevice->extensions.data())); @@ -154,11 +154,11 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { } // prepare the device queues - uint queueFamilyPropertiesCount = utils::toUint(_gpuContext->queueFamilyProperties.size()); + uint32_t queueFamilyPropertiesCount = utils::toUint(_gpuContext->queueFamilyProperties.size()); vector queueCreateInfos(queueFamilyPropertiesCount, {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}); vector> queuePriorities(queueFamilyPropertiesCount); - for (uint queueFamilyIndex = 0U; queueFamilyIndex < queueFamilyPropertiesCount; ++queueFamilyIndex) { + for (uint32_t queueFamilyIndex = 0U; queueFamilyIndex < queueFamilyPropertiesCount; ++queueFamilyIndex) { const VkQueueFamilyProperties &queueFamilyProperty = _gpuContext->queueFamilyProperties[queueFamilyIndex]; queuePriorities[queueFamilyIndex].resize(queueFamilyProperty.queueCount, 1.0F); @@ -238,6 +238,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { _features[toNumber(Feature::MULTIPLE_RENDER_TARGETS)] = true; _features[toNumber(Feature::BLEND_MINMAX)] = true; _features[toNumber(Feature::COMPUTE_SHADER)] = true; + _features[toNumber(Feature::INPUT_ATTACHMENT_BENEFIT)] = true; _gpuDevice->useMultiDrawIndirect = deviceFeatures.multiDrawIndirect; _gpuDevice->useDescriptorUpdateTemplate = _gpuDevice->minorVersion > 0 || checkExtension(VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME); @@ -279,7 +280,7 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { _caps.maxVertexTextureUnits = limits.maxPerStageDescriptorSampledImages; _caps.maxTextureSize = limits.maxImageDimension2D; _caps.maxCubeMapTextureSize = limits.maxImageDimensionCube; - _caps.uboOffsetAlignment = static_cast(limits.minUniformBufferOffsetAlignment); + _caps.uboOffsetAlignment = static_cast(limits.minUniformBufferOffsetAlignment); // compute shaders _caps.maxComputeSharedMemorySize = limits.maxComputeSharedMemorySize; _caps.maxComputeWorkGroupInvocations = limits.maxComputeWorkGroupInvocations; @@ -355,8 +356,8 @@ bool CCVKDevice::doInit(const DeviceInfo & /*info*/) { VK_CHECK(vmaCreateAllocator(&allocatorInfo, &_gpuDevice->memoryAllocator)); - uint backBufferCount = _gpuDevice->backBufferCount; - for (uint i = 0U; i < backBufferCount; i++) { + uint32_t backBufferCount = _gpuDevice->backBufferCount; + for (uint32_t i = 0U; i < backBufferCount; i++) { _gpuFencePools.push_back(CC_NEW(CCVKGPUFencePool(_gpuDevice))); _gpuRecycleBins.push_back(CC_NEW(CCVKGPURecycleBin(_gpuDevice))); _gpuStagingBufferPools.push_back(CC_NEW(CCVKGPUStagingBufferPool(_gpuDevice))); @@ -465,8 +466,8 @@ void CCVKDevice::doDestroy() { CC_SAFE_DELETE(_gpuBarrierManager) CC_SAFE_DELETE(_gpuDescriptorSetHub) - uint backBufferCount = _gpuDevice->backBufferCount; - for (uint i = 0U; i < backBufferCount; i++) { + uint32_t backBufferCount = _gpuDevice->backBufferCount; + for (uint32_t i = 0U; i < backBufferCount; i++) { _gpuRecycleBins[i]->clear(); CC_SAFE_DELETE(_gpuStagingBufferPools[i]) @@ -641,7 +642,7 @@ void CCVKDevice::present() { _gpuDevice->curBackBufferIndex = (_gpuDevice->curBackBufferIndex + 1) % _gpuDevice->backBufferCount; - uint fenceCount = gpuFencePool()->size(); + uint32_t fenceCount = gpuFencePool()->size(); if (fenceCount) { VK_CHECK(vkWaitForFences(_gpuDevice->vkDevice, fenceCount, gpuFencePool()->data(), VK_TRUE, DEFAULT_TIMEOUT)); @@ -725,40 +726,40 @@ PipelineState *CCVKDevice::createPipelineState() { return CC_NEW(CCVKPipelineState); } -Sampler *CCVKDevice::createSampler(const SamplerInfo &info) { - return CC_NEW(CCVKSampler(info)); +Sampler *CCVKDevice::createSampler(const SamplerInfo &info, uint32_t hash) { + return CC_NEW(CCVKSampler(info, hash)); } -GlobalBarrier *CCVKDevice::createGlobalBarrier(const GlobalBarrierInfo &info) { - return CC_NEW(CCVKGlobalBarrier(info)); +GlobalBarrier *CCVKDevice::createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) { + return CC_NEW(CCVKGlobalBarrier(info, hash)); } -TextureBarrier *CCVKDevice::createTextureBarrier(const TextureBarrierInfo &info) { - return CC_NEW(CCVKTextureBarrier(info)); +TextureBarrier *CCVKDevice::createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) { + return CC_NEW(CCVKTextureBarrier(info, hash)); } -void CCVKDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { +void CCVKDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) { gpuTransportHub()->checkIn([this, buffers, dst, regions, count](CCVKGPUCommandBuffer *gpuCommandBuffer) { cmdFuncCCVKCopyBuffersToTexture(this, buffers, static_cast(dst)->gpuTexture(), regions, count, gpuCommandBuffer); }); } -void CCVKDevice::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint count) { - uint totalSize = 0U; - Format format = srcTexture->getFormat(); - vector> regionOffsetSizes(count); +void CCVKDevice::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) { + uint32_t totalSize = 0U; + Format format = srcTexture->getFormat(); + vector> regionOffsetSizes(count); for (size_t i = 0U; i < count; ++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; - uint regionSize = formatSize(format, w, h, region.texExtent.depth); + uint32_t w = region.buffStride > 0 ? region.buffStride : region.texExtent.width; + uint32_t h = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height; + uint32_t regionSize = formatSize(format, w, h, region.texExtent.depth); regionOffsetSizes[i] = {totalSize, regionSize}; totalSize += regionSize; } CCVKGPUBuffer stagingBuffer; stagingBuffer.size = totalSize; - uint texelSize = GFX_FORMAT_INFOS[toNumber(format)].size; + uint32_t texelSize = GFX_FORMAT_INFOS[toNumber(format)].size; gpuStagingBufferPool()->alloc(&stagingBuffer, texelSize); // make sure the src texture is up-to-date @@ -770,9 +771,9 @@ void CCVKDevice::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffe }, true); - for (uint i = 0; i < count; ++i) { - uint regionOffset = 0; - uint regionSize = 0; + for (uint32_t i = 0; i < count; ++i) { + uint32_t regionOffset = 0; + uint32_t regionSize = 0; std::tie(regionOffset, regionSize) = regionOffsetSizes[i]; memcpy(buffers[i], stagingBuffer.mappedData + regionOffset, regionSize); } @@ -795,7 +796,7 @@ static VkResult VKAPI_PTR vkCreateRenderPass2KHRFallback( static vector depths; attachmentDescriptions.resize(pCreateInfo->attachmentCount); - for (uint i = 0; i < pCreateInfo->attachmentCount; ++i) { + for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { VkAttachmentDescription & desc{attachmentDescriptions[i]}; const VkAttachmentDescription2 &desc2{pCreateInfo->pAttachments[i]}; desc.flags = desc2.flags; @@ -815,22 +816,22 @@ static VkResult VKAPI_PTR vkCreateRenderPass2KHRFallback( colors.assign(pCreateInfo->subpassCount, std::numeric_limits::max()); resolves.assign(pCreateInfo->subpassCount, std::numeric_limits::max()); depths.assign(pCreateInfo->subpassCount, std::numeric_limits::max()); - for (uint i = 0; i < pCreateInfo->subpassCount; ++i) { + for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { const VkSubpassDescription2 &desc2{pCreateInfo->pSubpasses[i]}; if (desc2.inputAttachmentCount) { inputs[i] = attachmentReferences.size(); - for (uint j = 0; j < desc2.inputAttachmentCount; ++j) { + for (uint32_t j = 0; j < desc2.inputAttachmentCount; ++j) { attachmentReferences.push_back({desc2.pInputAttachments[j].attachment, desc2.pInputAttachments[j].layout}); } } if (desc2.colorAttachmentCount) { colors[i] = attachmentReferences.size(); - for (uint j = 0; j < desc2.colorAttachmentCount; ++j) { + for (uint32_t j = 0; j < desc2.colorAttachmentCount; ++j) { attachmentReferences.push_back({desc2.pColorAttachments[j].attachment, desc2.pColorAttachments[j].layout}); } if (desc2.pResolveAttachments) { resolves[i] = attachmentReferences.size(); - for (uint j = 0; j < desc2.colorAttachmentCount; ++j) { + for (uint32_t j = 0; j < desc2.colorAttachmentCount; ++j) { attachmentReferences.push_back({desc2.pResolveAttachments[j].attachment, desc2.pResolveAttachments[j].layout}); } } @@ -840,7 +841,7 @@ static VkResult VKAPI_PTR vkCreateRenderPass2KHRFallback( attachmentReferences.push_back({desc2.pDepthStencilAttachment->attachment, desc2.pDepthStencilAttachment->layout}); } } - for (uint i = 0; i < pCreateInfo->subpassCount; ++i) { + for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) { VkSubpassDescription & desc{subpassDescriptions[i]}; const VkSubpassDescription2 &desc2{pCreateInfo->pSubpasses[i]}; desc.flags = desc2.flags; @@ -856,7 +857,7 @@ static VkResult VKAPI_PTR vkCreateRenderPass2KHRFallback( } subpassDependencies.resize(pCreateInfo->dependencyCount); - for (uint i = 0; i < pCreateInfo->dependencyCount; ++i) { + for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) { VkSubpassDependency & desc{subpassDependencies[i]}; const VkSubpassDependency2 &desc2{pCreateInfo->pDependencies[i]}; desc.srcSubpass = desc2.srcSubpass; diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.h b/native/cocos/renderer/gfx-vulkan/VKDevice.h index 1ce1bc2b4f..b61a00b6c4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.h +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.h @@ -118,12 +118,12 @@ protected: PipelineLayout * createPipelineLayout() override; PipelineState * createPipelineState() override; - Sampler * createSampler(const SamplerInfo &info) override; - GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info) override; - TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) override; + Sampler * createSampler(const SamplerInfo &info, uint32_t hash) override; + GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) override; + TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) override; - void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; - void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint count) override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override; + void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override; void destroySwapchain(); bool checkSwapchainStatus(); diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h index 03c72c9e00..3b49cfaaef 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXFramebuffer.h" namespace cc { diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUContext.cpp b/native/cocos/renderer/gfx-vulkan/VKGPUContext.cpp index c78d86f765..64aebf978d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUContext.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKGPUContext.cpp @@ -32,28 +32,31 @@ namespace gfx { namespace { -constexpr uint FORCE_MINOR_VERSION = 0; // 0 for default version, otherwise minorVersion = (FORCE_MINOR_VERSION - 1) -constexpr uint DISABLE_VALIDATION_ASSERTIONS = 1; // 0 for default behavior, otherwise assertions will be disabled +constexpr uint32_t FORCE_MINOR_VERSION = 0; // 0 for default version, otherwise minorVersion = (FORCE_MINOR_VERSION - 1) +constexpr uint32_t DISABLE_VALIDATION_ASSERTIONS = 1; // 0 for default behavior, otherwise assertions will be disabled #define FORCE_ENABLE_VALIDATION 0 -#define FORCE_DISABLE_VALIDATION 1 +#define FORCE_DISABLE_VALIDATION 0 #if CC_DEBUG > 0 && !FORCE_DISABLE_VALIDATION || FORCE_ENABLE_VALIDATION -VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, - VkDebugUtilsMessageTypeFlagsEXT messageType, +VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, + VkDebugUtilsMessageTypeFlagsEXT /*messageType*/, const VkDebugUtilsMessengerCallbackDataEXT *callbackData, - void * userData) { + void * /*userData*/) { if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { CC_LOG_ERROR("%s: %s", callbackData->pMessageIdName, callbackData->pMessage); CCASSERT(DISABLE_VALIDATION_ASSERTIONS, "Validation Error"); return VK_FALSE; - } else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { + } + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { CC_LOG_WARNING("%s: %s", callbackData->pMessageIdName, callbackData->pMessage); return VK_FALSE; - } else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { + } + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { //CC_LOG_INFO("%s: %s", callbackData->pMessageIdName, callbackData->pMessage); return VK_FALSE; - } else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { + } + if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { //CC_LOG_DEBUG("%s: %s", callbackData->pMessageIdName, callbackData->pMessage); return VK_FALSE; } @@ -61,25 +64,28 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback(VkDebugUtilsMessageSe return VK_FALSE; } -VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback(VkDebugReportFlagsEXT flags, - VkDebugReportObjectTypeEXT type, - uint64_t object, - size_t location, - int32_t messageCode, - const char * layerPrefix, - const char * message, - void * userData) { +VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback(VkDebugReportFlagsEXT flags, + VkDebugReportObjectTypeEXT /*type*/, + uint64_t /*object*/, + size_t /*location*/, + int32_t /*messageCode*/, + const char *layerPrefix, + const char *message, + void * /*userData*/) { if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { CC_LOG_ERROR("%s: %s", layerPrefix, message); CCASSERT(DISABLE_VALIDATION_ASSERTIONS, "Validation Error"); return VK_FALSE; - } else if (flags & (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)) { + } + if (flags & (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)) { CC_LOG_WARNING("%s: %s", layerPrefix, message); return VK_FALSE; - } else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) { + } + if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) { //CC_LOG_INFO("%s: %s", layerPrefix, message); return VK_FALSE; - } else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) { + } + if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) { //CC_LOG_DEBUG("%s: %s", layerPrefix, message); return VK_FALSE; } @@ -103,7 +109,7 @@ bool CCVKGPUContext::initialize() { return false; } - uint apiVersion = VK_API_VERSION_1_0; + uint32_t apiVersion = VK_API_VERSION_1_0; if (vkEnumerateInstanceVersion) { vkEnumerateInstanceVersion(&apiVersion); if (FORCE_MINOR_VERSION) { @@ -116,12 +122,12 @@ bool CCVKGPUContext::initialize() { requestedExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); } - uint availableLayerCount; + uint32_t availableLayerCount; VK_CHECK(vkEnumerateInstanceLayerProperties(&availableLayerCount, nullptr)); vector supportedLayers(availableLayerCount); VK_CHECK(vkEnumerateInstanceLayerProperties(&availableLayerCount, supportedLayers.data())); - uint availableExtensionCount; + uint32_t availableExtensionCount; VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, nullptr)); vector supportedExtensions(availableExtensionCount); VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &availableExtensionCount, supportedExtensions.data())); @@ -253,7 +259,7 @@ bool CCVKGPUContext::initialize() { ///////////////////// Physical Device Selection ///////////////////// // Querying valid physical devices on the machine - uint physicalDeviceCount{0}; + uint32_t physicalDeviceCount{0}; res = vkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, nullptr); if (res || physicalDeviceCount < 1) { @@ -265,7 +271,7 @@ bool CCVKGPUContext::initialize() { vector physicalDevicePropertiesList(physicalDeviceCount); - uint deviceIndex; + uint32_t deviceIndex; for (deviceIndex = 0U; deviceIndex < physicalDeviceCount; ++deviceIndex) { VkPhysicalDeviceProperties &properties = physicalDevicePropertiesList[deviceIndex]; vkGetPhysicalDeviceProperties(physicalDeviceHandles[deviceIndex], &properties); @@ -303,7 +309,7 @@ bool CCVKGPUContext::initialize() { } vkGetPhysicalDeviceMemoryProperties(physicalDevice, &physicalDeviceMemoryProperties); - uint queueFamilyPropertiesCount = 0; + uint32_t queueFamilyPropertiesCount = 0; vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyPropertiesCount, nullptr); queueFamilyProperties.resize(queueFamilyPropertiesCount); vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &queueFamilyPropertiesCount, queueFamilyProperties.data()); diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 928d9ebcae..0cd4c74a56 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -104,12 +104,12 @@ public: TextureType type = TextureType::TEX2D; Format format = Format::UNKNOWN; TextureUsage usage = TextureUsageBit::NONE; - uint width = 0U; - uint height = 0U; - uint depth = 1U; - uint size = 0U; - uint arrayLayers = 1U; - uint mipLevels = 1U; + uint32_t width = 0U; + uint32_t height = 0U; + uint32_t depth = 1U; + uint32_t size = 0U; + uint32_t arrayLayers = 1U; + uint32_t mipLevels = 1U; SampleCount samples = SampleCount::ONE; TextureFlags flags = TextureFlagBit::NONE; VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -134,10 +134,10 @@ public: CCVKGPUTexture *gpuTexture = nullptr; TextureType type = TextureType::TEX2D; Format format = Format::UNKNOWN; - uint baseLevel = 0U; - uint levelCount = 1U; - uint baseLayer = 0U; - uint layerCount = 1U; + uint32_t baseLevel = 0U; + uint32_t levelCount = 1U; + uint32_t baseLayer = 0U; + uint32_t layerCount = 1U; vector swapchainVkImageViews; @@ -153,7 +153,7 @@ public: Address addressU = Address::WRAP; Address addressV = Address::WRAP; Address addressW = Address::WRAP; - uint maxAnisotropy = 0U; + uint32_t maxAnisotropy = 0U; ComparisonFunc cmpFunc = ComparisonFunc::NEVER; // descriptor infos @@ -164,8 +164,8 @@ class CCVKGPUBuffer final : public Object { public: BufferUsage usage = BufferUsage::NONE; MemoryUsage memUsage = MemoryUsage::NONE; - uint stride = 0U; - uint count = 0U; + uint32_t stride = 0U; + uint32_t count = 0U; void * buffer = nullptr; bool isDrawIndirectByIndex = false; @@ -186,7 +186,7 @@ public: vector renderAccessTypes; // gathered from descriptor sets ThsvsAccessType transferAccess = THSVS_ACCESS_NONE; - VkDeviceSize getStartOffset(uint curBackBufferIndex) const { + VkDeviceSize getStartOffset(uint32_t curBackBufferIndex) const { return startOffset + instanceSize * curBackBufferIndex; } }; @@ -194,10 +194,10 @@ public: class CCVKGPUBufferView final : public Object { public: CCVKGPUBuffer *gpuBuffer = nullptr; - uint offset = 0U; - uint range = 0U; + uint32_t offset = 0U; + uint32_t range = 0U; - VkDeviceSize getStartOffset(uint curBackBufferIndex) const { + VkDeviceSize getStartOffset(uint32_t curBackBufferIndex) const { return gpuBuffer->getStartOffset(curBackBufferIndex) + offset; } }; @@ -221,7 +221,7 @@ public: VkSurfaceKHR vkSurface = VK_NULL_HANDLE; VkSwapchainCreateInfoKHR createInfo{VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR}; - uint curImageIndex = 0U; + uint32_t curImageIndex = 0U; VkSwapchainKHR vkSwapchain = VK_NULL_HANDLE; FramebufferListMap vkSwapchainFramebufferListMap; vector queueFamilyPresentables; @@ -235,7 +235,7 @@ class CCVKGPUCommandBuffer final : public Object { public: VkCommandBuffer vkCommandBuffer = VK_NULL_HANDLE; VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - uint queueFamilyIndex = 0U; + uint32_t queueFamilyIndex = 0U; bool began = false; mutable unordered_set recordedBuffers; }; @@ -244,8 +244,8 @@ class CCVKGPUQueue final : public Object { public: QueueType type = QueueType::GRAPHICS; VkQueue vkQueue = VK_NULL_HANDLE; - uint queueFamilyIndex = 0U; - vector possibleQueueFamilyIndices; + uint32_t queueFamilyIndex = 0U; + vector possibleQueueFamilyIndices; vector lastSignaledSemaphores; vector submitStageMasks; vector commandBuffers; @@ -308,7 +308,7 @@ public: }; vector instances; // per swapchain image - uint layoutID = 0U; + uint32_t layoutID = 0U; }; class CCVKGPUPipelineLayout final : public Object { @@ -318,8 +318,8 @@ public: VkPipelineLayout vkPipelineLayout = VK_NULL_HANDLE; // helper storage - vector dynamicOffsetOffsets; - uint dynamicOffsetCount; + vector dynamicOffsetOffsets; + uint32_t dynamicOffsetCount; }; class CCVKGPUPipelineState final : public Object { @@ -334,7 +334,7 @@ public: BlendState bs; DynamicStateList dynamicStates; CCVKGPURenderPass * gpuRenderPass = nullptr; - uint subpass = 0U; + uint32_t subpass = 0U; VkPipeline vkPipeline = VK_NULL_HANDLE; }; @@ -367,13 +367,13 @@ public: vector extensions; VmaAllocator memoryAllocator{VK_NULL_HANDLE}; VkPipelineCache vkPipelineCache{VK_NULL_HANDLE}; - uint minorVersion{0U}; + uint32_t minorVersion{0U}; VkFormat depthFormat{VK_FORMAT_UNDEFINED}; VkFormat depthStencilFormat{VK_FORMAT_UNDEFINED}; - uint curBackBufferIndex{0U}; - uint backBufferCount{3U}; + uint32_t curBackBufferIndex{0U}; + uint32_t backBufferCount{3U}; bool useDescriptorUpdateTemplate{false}; bool useMultiDrawIndirect{false}; @@ -389,7 +389,7 @@ public: unordered_set swapchains; CCVKGPUCommandBufferPool *getCommandBufferPool(); - CCVKGPUDescriptorSetPool *getDescriptorSetPool(uint layoutID); + CCVKGPUDescriptorSetPool *getDescriptorSetPool(uint32_t layoutID); private: friend class CCVKDevice; @@ -398,7 +398,7 @@ private: using CommandBufferPools = tbb::concurrent_unordered_map>; CommandBufferPools _commandBufferPools; - unordered_map _descriptorSetPools; + unordered_map _descriptorSetPools; }; /** @@ -443,13 +443,13 @@ public: return _fences.data(); } - uint size() const { + uint32_t size() const { return _count; } private: CCVKGPUDevice * _device = nullptr; - uint _count = 0U; + uint32_t _count = 0U; vector _fences; }; @@ -488,13 +488,13 @@ public: _count = 0; } - uint size() const { + uint32_t size() const { return _count; } private: CCVKGPUDevice * _device; - uint _count = 0U; + uint32_t _count = 0U; vector _semaphores; }; @@ -525,13 +525,13 @@ public: _pools.clear(); } - void link(CCVKGPUDevice *device, uint maxSetsPerPool, const vector &bindings, VkDescriptorSetLayout setLayout) { + void link(CCVKGPUDevice *device, uint32_t maxSetsPerPool, const vector &bindings, VkDescriptorSetLayout setLayout) { _device = device; _maxSetsPerPool = maxSetsPerPool; _setLayouts.insert(_setLayouts.cbegin(), _maxSetsPerPool, setLayout); _fleaMarkets.resize(device->backBufferCount); - unordered_map typeMap; + unordered_map typeMap; for (const auto &vkBinding : bindings) { typeMap[vkBinding.descriptorType] += maxSetsPerPool * vkBinding.descriptorCount; } @@ -547,7 +547,7 @@ public: } } - VkDescriptorSet request(uint backBufferIndex) { + VkDescriptorSet request(uint32_t backBufferIndex) { VkDescriptorSet output = VK_NULL_HANDLE; if (!_fleaMarkets[backBufferIndex].empty()) { @@ -557,7 +557,7 @@ public: } size_t size = _pools.size(); - uint idx = 0U; + uint32_t idx = 0U; for (; idx < size; idx++) { if (!_pools[idx].freeSets.empty()) { output = _pools[idx].freeSets.back(); @@ -591,7 +591,7 @@ public: return output; } - void yield(VkDescriptorSet set, uint backBufferIndex) { + void yield(VkDescriptorSet set, uint32_t backBufferIndex) { bool found = false; for (DescriptorSetPool &pool : _pools) { if (pool.activeSets.count(set)) { @@ -617,25 +617,25 @@ private: vector _poolSizes; vector _setLayouts; - uint _maxSetsPerPool = 0U; + uint32_t _maxSetsPerPool = 0U; }; class CCVKGPUDescriptorSetLayout final : public Object { public: DescriptorSetLayoutBindingList bindings; - vector dynamicBindings; + vector dynamicBindings; vector vkBindings; VkDescriptorSetLayout vkDescriptorSetLayout = VK_NULL_HANDLE; VkDescriptorUpdateTemplate vkDescriptorUpdateTemplate = VK_NULL_HANDLE; VkDescriptorSet defaultDescriptorSet = VK_NULL_HANDLE; - vector bindingIndices; - vector descriptorIndices; - uint descriptorCount = 0U; + vector bindingIndices; + vector descriptorIndices; + uint32_t descriptorCount = 0U; - uint id = 0U; - uint maxSetsPerPool = 10U; + uint32_t id = 0U; + uint32_t maxSetsPerPool = 10U; }; /** @@ -660,15 +660,15 @@ public: _pools.clear(); } - uint getHash(uint queueFamilyIndex) { + uint32_t getHash(uint32_t queueFamilyIndex) { return (queueFamilyIndex << 10) | _device->curBackBufferIndex; } - static uint getBackBufferIndex(uint hash) { + static uint32_t getBackBufferIndex(uint32_t hash) { return hash & ((1 << 10) - 1); } void request(CCVKGPUCommandBuffer *gpuCommandBuffer) { - uint hash = getHash(gpuCommandBuffer->queueFamilyIndex); + uint32_t hash = getHash(gpuCommandBuffer->queueFamilyIndex); if (_device->curBackBufferIndex != _lastBackBufferIndex) { reset(); @@ -697,7 +697,7 @@ public: void yield(CCVKGPUCommandBuffer *gpuCommandBuffer) { if (gpuCommandBuffer->vkCommandBuffer) { - uint hash = getHash(gpuCommandBuffer->queueFamilyIndex); + uint32_t hash = getHash(gpuCommandBuffer->queueFamilyIndex); CCASSERT(_pools.count(hash), "wrong command pool to yield?"); CommandBufferPool &pool = _pools[hash]; @@ -714,7 +714,7 @@ public: CommandBufferPool &pool = it.second; bool needsReset = false; - for (uint i = 0U; i < 2U; ++i) { + for (uint32_t i = 0U; i < 2U; ++i) { CachedArray &usedList = pool.usedCommandBuffers[i]; if (usedList.size()) { pool.commandBuffers[i].concat(usedList); @@ -736,9 +736,9 @@ private: }; CCVKGPUDevice *_device = nullptr; - uint _lastBackBufferIndex = 0U; + uint32_t _lastBackBufferIndex = 0U; - unordered_map _pools; + unordered_map _pools; }; /** @@ -759,7 +759,7 @@ public: } void alloc(CCVKGPUBuffer *gpuBuffer) { alloc(gpuBuffer, 1U); } - void alloc(CCVKGPUBuffer *gpuBuffer, uint alignment) { + void alloc(CCVKGPUBuffer *gpuBuffer, uint32_t alignment) { size_t bufferCount = _pool.size(); Buffer * buffer = nullptr; VkDeviceSize offset = 0U; @@ -827,7 +827,7 @@ public: void record(const CCVKGPUDescriptorSet *gpuDescriptorSet) { update(gpuDescriptorSet); - for (uint i = 0U; i < _device->backBufferCount; ++i) { + for (uint32_t i = 0U; i < _device->backBufferCount; ++i) { if (i == _device->curBackBufferIndex) { _setsToBeUpdated[i].erase(gpuDescriptorSet); } else { @@ -837,7 +837,7 @@ public: } void erase(CCVKGPUDescriptorSet *gpuDescriptorSet) { - for (uint i = 0U; i < _device->backBufferCount; ++i) { + for (uint32_t i = 0U; i < _device->backBufferCount; ++i) { if (_setsToBeUpdated[i].count(gpuDescriptorSet)) { _setsToBeUpdated[i].erase(gpuDescriptorSet); } @@ -884,7 +884,7 @@ public: _descriptorSetHub = descriptorSetHub; } - void connect(const CCVKGPUDescriptorSet *set, const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor, uint instanceIdx) { + void connect(const CCVKGPUDescriptorSet *set, const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor, uint32_t instanceIdx) { _buffers[buffer].sets.insert(set); _buffers[buffer].descriptors.push(descriptor); _bufferInstanceIndices[descriptor] = instanceIdx; @@ -901,7 +901,7 @@ public: for (const auto &it : _buffers) { if (it.first->gpuBuffer != buffer->gpuBuffer) continue; const auto &info = it.second; - for (uint i = 0U; i < info.descriptors.size(); i++) { + for (uint32_t i = 0U; i < info.descriptors.size(); i++) { doUpdate(buffer, info.descriptors[i]); } for (const auto *set : info.sets) { @@ -913,7 +913,7 @@ public: auto it = _buffers.find(buffer); if (it == _buffers.end()) return; auto &descriptors = it->second.descriptors; - for (uint i = 0U; i < descriptors.size(); i++) { + for (uint32_t i = 0U; i < descriptors.size(); i++) { if (descriptors[i] == descriptor) { doUpdate(buffer, descriptor); break; @@ -924,7 +924,7 @@ public: for (const auto &it : _textures) { if (it.first->gpuTexture != texture->gpuTexture) continue; const auto &info = it.second; - for (uint i = 0U; i < info.descriptors.size(); i++) { + for (uint32_t i = 0U; i < info.descriptors.size(); i++) { doUpdate(texture, info.descriptors[i]); } for (const auto *set : info.sets) { @@ -936,7 +936,7 @@ public: auto it = _textures.find(texture); if (it == _textures.end()) return; auto &descriptors = it->second.descriptors; - for (uint i = 0U; i < descriptors.size(); i++) { + for (uint32_t i = 0U; i < descriptors.size(); i++) { if (descriptors[i] == descriptor) { doUpdate(texture, descriptor); break; @@ -947,7 +947,7 @@ public: auto it = _samplers.find(sampler); if (it == _samplers.end()) return; auto &descriptors = it->second; - for (uint i = 0U; i < descriptors.size(); ++i) { + for (uint32_t i = 0U; i < descriptors.size(); ++i) { if (descriptors[i] == descriptor) { doUpdate(sampler, descriptor); break; @@ -959,7 +959,7 @@ public: for (const auto &it : _buffers) { if (it.first->gpuBuffer != buffer) continue; const auto &info = it.second; - for (uint i = 0U; i < info.descriptors.size(); i++) { + for (uint32_t i = 0U; i < info.descriptors.size(); i++) { doUpdate(it.first, info.descriptors[i]); } for (const auto *set : info.sets) { @@ -971,7 +971,7 @@ public: void disengage(const CCVKGPUBufferView *buffer) { auto it = _buffers.find(buffer); if (it == _buffers.end()) return; - for (uint i = 0; i < it->second.descriptors.size(); ++i) { + for (uint32_t i = 0; i < it->second.descriptors.size(); ++i) { _bufferInstanceIndices.erase(it->second.descriptors[i]); } _buffers.erase(it); @@ -1034,7 +1034,7 @@ private: CachedArray descriptors; }; - unordered_map _bufferInstanceIndices; + unordered_map _bufferInstanceIndices; unordered_map> _buffers; unordered_map> _textures; unordered_map> _samplers; @@ -1151,7 +1151,7 @@ private: }; CCVKGPUDevice * _device = nullptr; vector _resources; - uint _count = 0U; + uint32_t _count = 0U; }; /** @@ -1243,9 +1243,9 @@ public: _buffersToBeChecked.insert(gpuBuffer); } - void checkIn(CCVKGPUTexture *gpuTexture, const ThsvsAccessType *newTypes = nullptr, uint newTypeCount = 0) { + void checkIn(CCVKGPUTexture *gpuTexture, const ThsvsAccessType *newTypes = nullptr, uint32_t newTypeCount = 0) { vector &target = gpuTexture->renderAccessTypes; - for (uint i = 0U; i < newTypeCount; ++i) { + for (uint32_t i = 0U; i < newTypeCount; ++i) { if (std::find(target.begin(), target.end(), newTypes[i]) == target.end()) { target.push_back(newTypes[i]); } @@ -1274,8 +1274,8 @@ public: _buffersToBeUpdated.resize(device->backBufferCount); } - void record(CCVKGPUBuffer *gpuBuffer, uint backBufferIndex, size_t size, bool canMemcpy) { - for (uint i = 0U; i < _device->backBufferCount; ++i) { + void record(CCVKGPUBuffer *gpuBuffer, uint32_t backBufferIndex, size_t size, bool canMemcpy) { + for (uint32_t i = 0U; i < _device->backBufferCount; ++i) { if (i == backBufferIndex) { _buffersToBeUpdated[i].erase(gpuBuffer); } else { @@ -1285,7 +1285,7 @@ public: } void erase(CCVKGPUBuffer *gpuBuffer) { - for (uint i = 0U; i < _device->backBufferCount; ++i) { + for (uint32_t i = 0U; i < _device->backBufferCount; ++i) { if (_buffersToBeUpdated[i].count(gpuBuffer)) { _buffersToBeUpdated[i].erase(gpuBuffer); } @@ -1296,7 +1296,7 @@ public: private: struct BufferUpdate { - uint srcIndex = 0U; + uint32_t srcIndex = 0U; size_t size = 0U; bool canMemcpy = false; }; diff --git a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h index 49366b8d88..3ef7b3b339 100644 --- a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h +++ b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXInputAssembler.h" namespace cc { @@ -35,7 +36,7 @@ class CCVKGPUInputAssembler; class CC_VULKAN_API CCVKInputAssembler final : public InputAssembler { public: CCVKInputAssembler(); - ~CCVKInputAssembler(); + ~CCVKInputAssembler() override; inline CCVKGPUInputAssembler *gpuInputAssembler() const { return _gpuInputAssembler; } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h index 0043f8443b..df6016b54a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h @@ -23,9 +23,9 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_PIPELINE_LAYOUT_H_ -#define CC_GFXVULKAN_PIPELINE_LAYOUT_H_ +#pragma once +#include "VKStd.h" #include "gfx-base/GFXPipelineLayout.h" namespace cc { @@ -36,7 +36,7 @@ class CCVKGPUPipelineLayout; class CC_VULKAN_API CCVKPipelineLayout final : public PipelineLayout { public: CCVKPipelineLayout(); - ~CCVKPipelineLayout(); + ~CCVKPipelineLayout() override; inline CCVKGPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } @@ -49,5 +49,3 @@ protected: } // namespace gfx } // namespace cc - -#endif // CC_GFXVULKAN_PIPELINE_LAYOUT_H_ diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp index ff7d1bca04..109fa05ca1 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp @@ -56,8 +56,8 @@ void CCVKPipelineState::doInit(const PipelineStateInfo & /*info*/) { _gpuPipelineState->gpuPipelineLayout = static_cast(_pipelineLayout)->gpuPipelineLayout(); if (_renderPass) _gpuPipelineState->gpuRenderPass = static_cast(_renderPass)->gpuRenderPass(); - for (uint i = 0; i < 31; i++) { - if (static_cast(_dynamicStates) & (1 << i)) { + for (uint32_t i = 0; i < 31; i++) { + if (static_cast(_dynamicStates) & (1 << i)) { _gpuPipelineState->dynamicStates.push_back(static_cast(1 << i)); } } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.h b/native/cocos/renderer/gfx-vulkan/VKPipelineState.h index d0f5b22cb0..ea9c1ce7d6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.h +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXPipelineState.h" namespace cc { @@ -35,7 +36,7 @@ class CCVKGPUPipelineState; class CC_VULKAN_API CCVKPipelineState final : public PipelineState { public: CCVKPipelineState(); - ~CCVKPipelineState(); + ~CCVKPipelineState() override; inline CCVKGPUPipelineState *gpuPipelineState() const { return _gpuPipelineState; } diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp index a998f25966..d13243acc9 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp @@ -56,7 +56,7 @@ void CCVKQueue::doDestroy() { } } -void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { +void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint32_t count) { CCVKDevice *device = CCVKDevice::getInstance(); _gpuQueue->commandBuffers.clear(); @@ -69,7 +69,7 @@ void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { _gpuQueue->commandBuffers.push_back(device->gpuTransportHub()->packageForFlight(false)); } - for (uint i = 0U; i < count; ++i) { + for (uint32_t i = 0U; i < count; ++i) { auto *cmdBuff = static_cast(cmdBuffs[i]); if (!cmdBuff->_pendingQueue.empty()) { _gpuQueue->commandBuffers.push_back(cmdBuff->_pendingQueue.front()); diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.h b/native/cocos/renderer/gfx-vulkan/VKQueue.h index 932551f2ad..1d9d21fe7a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.h +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.h @@ -38,7 +38,7 @@ public: CCVKQueue(); ~CCVKQueue() override; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override; inline CCVKGPUQueue *gpuQueue() const { return _gpuQueue; } @@ -50,9 +50,9 @@ protected: CCVKGPUQueue *_gpuQueue = nullptr; - uint _numDrawCalls = 0; - uint _numInstances = 0; - uint _numTriangles = 0; + uint32_t _numDrawCalls = 0; + uint32_t _numInstances = 0; + uint32_t _numTriangles = 0; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp index af5f41d88c..3d068c2eb5 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp @@ -51,12 +51,23 @@ void CCVKRenderPass::doInit(const RenderPassInfo & /*info*/) { if (_gpuRenderPass->subpasses.empty()) { auto &subpass = _gpuRenderPass->subpasses.emplace_back(); subpass.colors.resize(_colorAttachments.size()); - for (uint i = 0U; i < _colorAttachments.size(); ++i) { + for (uint32_t i = 0U; i < _colorAttachments.size(); ++i) { subpass.colors[i] = i; } if (_depthStencilAttachment.format != Format::UNKNOWN) { subpass.depthStencil = utils::toUint(_colorAttachments.size()); } + } else { + // unify depth stencil index + uint32_t colorCount = _gpuRenderPass->colorAttachments.size(); + for (auto &subpass : _gpuRenderPass->subpasses) { + if (subpass.depthStencil != INVALID_BINDING && subpass.depthStencil > colorCount) { + subpass.depthStencil = colorCount; + } + if (subpass.depthStencilResolve != INVALID_BINDING && subpass.depthStencilResolve > colorCount) { + subpass.depthStencilResolve = colorCount; + } + } } cmdFuncCCVKCreateRenderPass(CCVKDevice::getInstance(), _gpuRenderPass); diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.h b/native/cocos/renderer/gfx-vulkan/VKRenderPass.h index 0fba283ba7..8b6b33ebcf 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.h +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXRenderPass.h" namespace cc { @@ -35,7 +36,7 @@ class CCVKGPURenderPass; class CC_VULKAN_API CCVKRenderPass final : public RenderPass { public: CCVKRenderPass(); - ~CCVKRenderPass(); + ~CCVKRenderPass() override; inline CCVKGPURenderPass *gpuRenderPass() const { return _gpuRenderPass; } diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.h b/native/cocos/renderer/gfx-vulkan/VKShader.h index d4ad49a460..70acbc32eb 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.h +++ b/native/cocos/renderer/gfx-vulkan/VKShader.h @@ -25,6 +25,7 @@ #pragma once +#include "VKStd.h" #include "gfx-base/GFXShader.h" namespace cc { @@ -35,7 +36,7 @@ class CCVKGPUShader; class CC_VULKAN_API CCVKShader final : public Shader { public: CCVKShader(); - ~CCVKShader(); + ~CCVKShader() override; inline CCVKGPUShader *gpuShader() const { return _gpuShader; } diff --git a/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp b/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp index e4540b8f2a..08458044de 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKSwapchain.cpp @@ -81,12 +81,12 @@ void CCVKSwapchain::doInit(const SwapchainInfo &info) { VkSurfaceCapabilitiesKHR surfaceCapabilities{}; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpuContext->physicalDevice, _gpuSwapchain->vkSurface, &surfaceCapabilities); - uint surfaceFormatCount = 0U; + uint32_t surfaceFormatCount = 0U; VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(gpuContext->physicalDevice, _gpuSwapchain->vkSurface, &surfaceFormatCount, nullptr)); vector surfaceFormats(surfaceFormatCount); VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(gpuContext->physicalDevice, _gpuSwapchain->vkSurface, &surfaceFormatCount, surfaceFormats.data())); - uint presentModeCount = 0U; + uint32_t presentModeCount = 0U; VK_CHECK(vkGetPhysicalDeviceSurfacePresentModesKHR(gpuContext->physicalDevice, _gpuSwapchain->vkSurface, &presentModeCount, nullptr)); vector presentModes(presentModeCount); VK_CHECK(vkGetPhysicalDeviceSurfacePresentModesKHR(gpuContext->physicalDevice, _gpuSwapchain->vkSurface, &presentModeCount, presentModes.data())); @@ -151,7 +151,7 @@ void CCVKSwapchain::doInit(const SwapchainInfo &info) { // Determine the number of images // for now we assume triple buffer is universal - uint desiredNumberOfSwapchainImages = gpuDevice->backBufferCount; + uint32_t desiredNumberOfSwapchainImages = gpuDevice->backBufferCount; CCASSERT(desiredNumberOfSwapchainImages <= surfaceCapabilities.maxImageCount && desiredNumberOfSwapchainImages >= surfaceCapabilities.minImageCount, "Swapchain image count assumption broken"); @@ -257,8 +257,8 @@ bool CCVKSwapchain::checkSwapchainStatus(uint32_t width, uint32_t height) { // surfaceCapabilities.currentExtent seems to remain the same // during any size/orientation change events on android devices // so we prefer the system input (oriented size) here - uint newWidth = width ? width : surfaceCapabilities.currentExtent.width; - uint newHeight = height ? height : surfaceCapabilities.currentExtent.height; + uint32_t newWidth = width ? width : surfaceCapabilities.currentExtent.width; + uint32_t newHeight = height ? height : surfaceCapabilities.currentExtent.height; VkSurfaceTransformFlagBitsKHR preTransform = surfaceCapabilities.currentTransform; if (ENABLE_PRE_ROTATION) { @@ -275,7 +275,7 @@ bool CCVKSwapchain::checkSwapchainStatus(uint32_t width, uint32_t height) { return true; } - if (newWidth == static_cast(-1)) { + if (newWidth == static_cast(-1)) { _gpuSwapchain->createInfo.imageExtent.width = _colorTexture->getWidth(); _gpuSwapchain->createInfo.imageExtent.height = _colorTexture->getHeight(); } else { @@ -293,7 +293,7 @@ bool CCVKSwapchain::checkSwapchainStatus(uint32_t width, uint32_t height) { _gpuSwapchain->createInfo.surface = _gpuSwapchain->vkSurface; _gpuSwapchain->createInfo.oldSwapchain = _gpuSwapchain->vkSwapchain; - CC_LOG_INFO("Resizing surface: %dx%d, surface rotation: %d degrees", newWidth, newHeight, (uint)_transform * 90); + CC_LOG_INFO("Resizing surface: %dx%d, surface rotation: %d degrees", newWidth, newHeight, (uint32_t)_transform * 90); CCVKDevice::getInstance()->waitAllFences(); @@ -306,7 +306,7 @@ bool CCVKSwapchain::checkSwapchainStatus(uint32_t width, uint32_t height) { _gpuSwapchain->curImageIndex = 0; _gpuSwapchain->vkSwapchain = vkSwapchain; - uint imageCount; + uint32_t imageCount; VK_CHECK(vkGetSwapchainImagesKHR(gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, &imageCount, nullptr)); _gpuSwapchain->swapchainImages.resize(imageCount); VK_CHECK(vkGetSwapchainImagesKHR(gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, &imageCount, _gpuSwapchain->swapchainImages.data())); @@ -332,7 +332,7 @@ bool CCVKSwapchain::checkSwapchainStatus(uint32_t width, uint32_t height) { VkPipelineStageFlags tempDstStageMask = 0; auto * colorGPUTexture = static_cast(_colorTexture)->gpuTexture(); auto * depthStencilGPUTexture = static_cast(_depthStencilTexture)->gpuTexture(); - for (uint i = 0U; i < imageCount; i++) { + for (uint32_t i = 0U; i < imageCount; i++) { tempBarrier.nextAccessCount = 1; tempBarrier.pNextAccesses = &THSVS_ACCESS_TYPES[toNumber(AccessType::PRESENT)]; tempBarrier.image = _gpuSwapchain->swapchainImages[i]; diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp index 97c6bf6fa6..56416221f4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp @@ -106,7 +106,7 @@ void CCVKTexture::doDestroy() { } } -void CCVKTexture::doResize(uint width, uint height, uint size) { +void CCVKTexture::doResize(uint32_t width, uint32_t height, uint32_t size) { if (!width || !height) return; if (!_gpuTexture->memoryless) { diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.h b/native/cocos/renderer/gfx-vulkan/VKTexture.h index 929ac92252..8ada991c93 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.h +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.h @@ -49,7 +49,7 @@ protected: void doInit(const TextureViewInfo &info) override; void doInit(const SwapchainTextureInfo &info) override; void doDestroy() override; - void doResize(uint width, uint height, uint size) override; + void doResize(uint32_t width, uint32_t height, uint32_t size) override; void createTextureView(); diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.cpp b/native/cocos/renderer/gfx-vulkan/VKUtils.cpp index b40f572533..31c8675529 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.cpp @@ -181,7 +181,7 @@ VkAttachmentStoreOp mapVkStoreOp(StoreOp storeOp) { } VkBufferUsageFlagBits mapVkBufferUsageFlagBits(BufferUsage usage) { - uint flags = 0U; + uint32_t flags = 0U; if (hasFlag(usage, BufferUsage::TRANSFER_SRC)) flags |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT; if (hasFlag(usage, BufferUsage::TRANSFER_DST)) flags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; if (hasFlag(usage, BufferUsage::INDEX)) flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; @@ -208,7 +208,7 @@ VkImageType mapVkImageType(TextureType type) { } VkFormatFeatureFlags mapVkFormatFeatureFlags(TextureUsage usage) { - uint flags = 0U; + uint32_t flags = 0U; if (hasFlag(usage, TextureUsage::TRANSFER_SRC)) flags |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT; if (hasFlag(usage, TextureUsage::TRANSFER_DST)) flags |= VK_FORMAT_FEATURE_TRANSFER_DST_BIT; if (hasFlag(usage, TextureUsage::SAMPLED)) flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; @@ -219,7 +219,7 @@ VkFormatFeatureFlags mapVkFormatFeatureFlags(TextureUsage usage) { } VkImageUsageFlagBits mapVkImageUsageFlagBits(TextureUsage usage) { - uint flags = 0U; + uint32_t flags = 0U; if (hasFlag(usage, TextureUsage::TRANSFER_SRC)) flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; if (hasFlag(usage, TextureUsage::TRANSFER_DST)) flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; if (hasFlag(usage, TextureUsage::SAMPLED)) flags |= VK_IMAGE_USAGE_SAMPLED_BIT; @@ -239,7 +239,7 @@ VkImageAspectFlags mapVkImageAspectFlags(Format format) { } VkImageCreateFlags mapVkImageCreateFlags(TextureType type) { - uint res = 0U; + uint32_t res = 0U; switch (type) { case TextureType::CUBE: res |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; break; case TextureType::TEX2D_ARRAY: res |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; break; @@ -293,7 +293,7 @@ VkDescriptorType mapVkDescriptorType(DescriptorType type) { } VkColorComponentFlags mapVkColorComponentFlags(ColorMask colorMask) { - uint flags = 0U; + uint32_t flags = 0U; if (hasFlag(colorMask, ColorMask::R)) flags |= VK_COLOR_COMPONENT_R_BIT; if (hasFlag(colorMask, ColorMask::G)) flags |= VK_COLOR_COMPONENT_G_BIT; if (hasFlag(colorMask, ColorMask::B)) flags |= VK_COLOR_COMPONENT_B_BIT; @@ -317,7 +317,7 @@ VkShaderStageFlagBits mapVkShaderStageFlagBits(ShaderStageFlagBit stage) { } VkShaderStageFlags mapVkShaderStageFlags(ShaderStageFlagBit stages) { - uint flags = 0U; + uint32_t flags = 0U; if (hasFlag(stages, ShaderStageFlagBit::VERTEX)) flags |= VK_SHADER_STAGE_VERTEX_BIT; if (hasFlag(stages, ShaderStageFlagBit::CONTROL)) flags |= VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; if (hasFlag(stages, ShaderStageFlagBit::EVALUATION)) flags |= VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; @@ -551,7 +551,7 @@ void fullPipelineBarrier(VkCommandBuffer cmdBuff) { #endif } -VkDeviceSize roundUp(VkDeviceSize numToRound, uint multiple) { +VkDeviceSize roundUp(VkDeviceSize numToRound, uint32_t multiple) { return ((numToRound + multiple - 1) / multiple) * multiple; } diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.h b/native/cocos/renderer/gfx-vulkan/VKUtils.h index 7cfcd796ce..79f6b6387d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.h +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.h @@ -71,7 +71,7 @@ extern SurfaceTransform mapSurfaceTransform(VkSurfaceTransformFlagBitsKHR t extern String mapVendorName(uint32_t vendorID); extern void fullPipelineBarrier(VkCommandBuffer cmdBuff); -extern VkDeviceSize roundUp(VkDeviceSize numToRound, uint multiple); +extern VkDeviceSize roundUp(VkDeviceSize numToRound, uint32_t multiple); extern bool isLayerSupported(const char *required, const vector &available); extern bool isExtensionSupported(const char *required, const vector &available); diff --git a/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp b/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp index 288cb21d14..c4875d3ee7 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.cpp @@ -29,18 +29,18 @@ namespace cc { namespace gfx { -CCVKGlobalBarrier::CCVKGlobalBarrier(const GlobalBarrierInfo &info) : GlobalBarrier(info) { +CCVKGlobalBarrier::CCVKGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash) : GlobalBarrier(info, hash) { _typedID = generateObjectID(); _gpuBarrier = CC_NEW(CCVKGPUGlobalBarrier); _gpuBarrier->accessTypes.resize(info.prevAccesses.size() + info.nextAccesses.size()); - uint index = 0U; + uint32_t index = 0U; for (AccessType type : info.prevAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } for (AccessType type : info.nextAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } _gpuBarrier->barrier.prevAccessCount = utils::toUint(info.prevAccesses.size()); diff --git a/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.h b/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.h index cc6f0eabc4..e46fedbc11 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.h +++ b/native/cocos/renderer/gfx-vulkan/states/VKGlobalBarrier.h @@ -35,7 +35,7 @@ class CCVKGPUGlobalBarrier; class CC_VULKAN_API CCVKGlobalBarrier : public GlobalBarrier { public: - explicit CCVKGlobalBarrier(const GlobalBarrierInfo &info); + explicit CCVKGlobalBarrier(const GlobalBarrierInfo &info, uint32_t hash); ~CCVKGlobalBarrier() override; inline const CCVKGPUGlobalBarrier *gpuBarrier() const { return _gpuBarrier; } diff --git a/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp b/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp index 580f4e9843..39ff0dcf62 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKSampler.cpp @@ -30,7 +30,7 @@ namespace cc { namespace gfx { -CCVKSampler::CCVKSampler(const SamplerInfo &info) : Sampler(info) { +CCVKSampler::CCVKSampler(const SamplerInfo &info, uint32_t hash) : Sampler(info, hash) { _typedID = generateObjectID(); _gpuSampler = CC_NEW(CCVKGPUSampler); diff --git a/native/cocos/renderer/gfx-vulkan/states/VKSampler.h b/native/cocos/renderer/gfx-vulkan/states/VKSampler.h index 0262bc3a42..dc738df8f6 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKSampler.h +++ b/native/cocos/renderer/gfx-vulkan/states/VKSampler.h @@ -35,7 +35,7 @@ class CCVKGPUSampler; class CC_VULKAN_API CCVKSampler final : public Sampler { public: - explicit CCVKSampler(const SamplerInfo &info); + explicit CCVKSampler(const SamplerInfo &info, uint32_t hash); ~CCVKSampler() override; inline CCVKGPUSampler *gpuSampler() const { return _gpuSampler; } diff --git a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp index 230e1eac5f..716209fdae 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.cpp @@ -30,18 +30,18 @@ namespace cc { namespace gfx { -CCVKTextureBarrier::CCVKTextureBarrier(const TextureBarrierInfo &info) : TextureBarrier(info) { +CCVKTextureBarrier::CCVKTextureBarrier(const TextureBarrierInfo &info, uint32_t hash) : TextureBarrier(info, hash) { _typedID = generateObjectID(); _gpuBarrier = CC_NEW(CCVKGPUTextureBarrier); _gpuBarrier->accessTypes.resize(info.prevAccesses.size() + info.nextAccesses.size()); - uint index = 0U; + uint32_t index = 0U; for (AccessType type : info.prevAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } for (AccessType type : info.nextAccesses) { - _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; + _gpuBarrier->accessTypes[index++] = THSVS_ACCESS_TYPES[static_cast(type)]; } _gpuBarrier->barrier.prevAccessCount = utils::toUint(info.prevAccesses.size()); diff --git a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.h b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.h index d4f964b8f7..ccb40454b9 100644 --- a/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.h +++ b/native/cocos/renderer/gfx-vulkan/states/VKTextureBarrier.h @@ -35,7 +35,7 @@ class CCVKGPUTextureBarrier; class CC_VULKAN_API CCVKTextureBarrier : public TextureBarrier { public: - explicit CCVKTextureBarrier(const TextureBarrierInfo &info); + explicit CCVKTextureBarrier(const TextureBarrierInfo &info, uint32_t hash); ~CCVKTextureBarrier() override; inline const CCVKGPUTextureBarrier *gpuBarrier() const { return _gpuBarrier; } diff --git a/native/cocos/renderer/pipeline/PipelineStateManager.cpp b/native/cocos/renderer/pipeline/PipelineStateManager.cpp index 9a72b82f67..ae72c1af14 100644 --- a/native/cocos/renderer/pipeline/PipelineStateManager.cpp +++ b/native/cocos/renderer/pipeline/PipelineStateManager.cpp @@ -54,7 +54,7 @@ gfx::PipelineState *PipelineStateManager::getOrCreatePipelineState(const scene:: *(pass->getDepthStencilState()), *(pass->getBlendState()), pass->getPrimitive(), - pass->getDynamicState() | gfx::DynamicStateFlagBit::VIEWPORT | gfx::DynamicStateFlagBit::SCISSOR, + pass->getDynamicState(), }); psoHashMap[hash] = pso; diff --git a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp index 5310f80be5..a6133dfb24 100644 --- a/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp +++ b/native/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp @@ -26,6 +26,7 @@ #include "DeferredPipeline.h" #include "../SceneCulling.h" #include "../shadow/ShadowFlow.h" +#include "../helper/Utils.h" #include "MainFlow.h" #include "gfx-base/GFXBuffer.h" #include "gfx-base/GFXCommandBuffer.h" @@ -38,7 +39,6 @@ namespace cc { namespace pipeline { -namespace { #define TO_VEC3(dst, src, offset) \ dst[offset] = (src).x; \ (dst)[(offset) + 1] = (src).y; \ @@ -48,13 +48,6 @@ namespace { (dst)[(offset) + 1] = (src).y; \ (dst)[(offset) + 2] = (src).z; \ (dst)[(offset) + 3] = (src).w; -} // namespace - -void srgbToLinear(gfx::Color *out, const gfx::Color &gamma) { - out->x = gamma.x * gamma.x; - out->y = gamma.y * gamma.y; - out->z = gamma.z * gamma.z; -} framegraph::StringHandle DeferredPipeline::fgStrHandleGbufferTexture[GBUFFER_COUNT] = { framegraph::FrameGraph::stringToHandle("gbufferAlbedoTexture"), diff --git a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp index 79afd199b9..c6e2c7dc84 100644 --- a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp @@ -42,24 +42,8 @@ namespace cc { namespace pipeline { -namespace { -const String STAGE_NAME = "GbufferStage"; - -void srgbToLinear(gfx::Color *out, const gfx::Color &gamma) { - out->x = gamma.x * gamma.x; - out->y = gamma.y * gamma.y; - out->z = gamma.z * gamma.z; -} - -void linearToSrgb(gfx::Color *out, const gfx::Color &linear) { - out->x = std::sqrt(linear.x); - out->y = std::sqrt(linear.y); - out->z = std::sqrt(linear.z); -} -} // namespace - RenderStageInfo GbufferStage::initInfo = { - STAGE_NAME, + "GbufferStage", static_cast(DeferredStagePriority::GBUFFER), static_cast(RenderFlowTag::SCENE), {{false, RenderQueueSortMode::FRONT_TO_BACK, {"default"}}, diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index 3291e4e72f..82e058e3b2 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -49,17 +49,6 @@ namespace cc { namespace pipeline { namespace { -void srgbToLinear(gfx::Color *out, const gfx::Color &gamma) { - out->x = gamma.x * gamma.x; - out->y = gamma.y * gamma.y; - out->z = gamma.z * gamma.z; -} - -void linearToSrgb(gfx::Color *out, const gfx::Color &linear) { - out->x = std::sqrt(linear.x); - out->y = std::sqrt(linear.y); - out->z = std::sqrt(linear.z); -} const String STAGE_NAME = "LightingStage"; const uint MAX_REFLECTOR_SIZE = 5; diff --git a/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp b/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp index 27ebcfdc39..fb4899fd7d 100644 --- a/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/PostprocessStage.cpp @@ -36,6 +36,7 @@ #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" #include "pipeline/Define.h" +#include "pipeline/helper/Utils.h" #include "scene/SubModel.h" namespace cc { @@ -212,6 +213,7 @@ void PostprocessStage::render(scene::Camera *camera) { } _uiPhase->render(camera, renderPass); + renderProfiler(renderPass, cmdBuff, pipeline->getProfiler(), camera->window->swapchain); }; // add pass diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index b329359fa3..7006af5ad7 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -31,6 +31,7 @@ #include "../RenderBatchedQueue.h" #include "../RenderInstancedQueue.h" #include "../RenderQueue.h" +#include "../helper/Utils.h" #include "ForwardPipeline.h" #include "UIPhase.h" #include "gfx-base/GFXCommandBuffer.h" @@ -40,19 +41,6 @@ namespace cc { namespace pipeline { -namespace { -void srgbToLinear(gfx::Color *out, const gfx::Color &gamma) { - out->x = gamma.x * gamma.x; - out->y = gamma.y * gamma.y; - out->z = gamma.z * gamma.z; -} - -void linearToSrgb(gfx::Color *out, const gfx::Color &linear) { - out->x = std::sqrt(linear.x); - out->y = std::sqrt(linear.y); - out->z = std::sqrt(linear.z); -} -} // namespace RenderStageInfo ForwardStage::initInfo = { "ForwardStage", @@ -156,9 +144,9 @@ void ForwardStage::render(scene::Camera *camera) { _planarShadowQueue->gatherShadowPasses(camera, cmdBuff); // render area is not oriented - bool flipWH = camera->window->swapchain && static_cast(camera->window->swapchain->getSurfaceTransform()) % 2; - auto w = static_cast(flipWH ? camera->height : camera->width); - auto h = static_cast(flipWH ? camera->width : camera->height); + bool flipWH = camera->window->swapchain && static_cast(camera->window->swapchain->getSurfaceTransform()) % 2; + auto w = static_cast(flipWH ? camera->height : camera->width); + auto h = static_cast(flipWH ? camera->width : camera->height); _renderArea.x = static_cast(camera->viewPort.x * w); _renderArea.y = static_cast(camera->viewPort.y * h); _renderArea.width = static_cast(camera->viewPort.z * w * sharedData->shadingScale); @@ -199,6 +187,7 @@ void ForwardStage::render(scene::Camera *camera) { _planarShadowQueue->recordCommandBuffer(_device, renderPass, cmdBuff); _renderQueues[1]->recordCommandBuffer(_device, renderPass, cmdBuff); _uiPhase->render(camera, renderPass); + renderProfiler(renderPass, cmdBuff, pipeline->getProfiler(), camera->window->swapchain); cmdBuff->endRenderPass(); } diff --git a/native/cocos/renderer/pipeline/forward/UIPhase.cpp b/native/cocos/renderer/pipeline/forward/UIPhase.cpp index 1424ab7872..a1ac83ad21 100644 --- a/native/cocos/renderer/pipeline/forward/UIPhase.cpp +++ b/native/cocos/renderer/pipeline/forward/UIPhase.cpp @@ -58,20 +58,6 @@ void UIPhase::render(scene::Camera *camera, gfx::RenderPass *renderPass) { cmdBuff->draw(inputAssembler); } } - - auto *profiler = _pipeline->getProfiler(); - if (profiler && profiler->getEnabled() && camera->window->swapchain) { - auto *submodel = profiler->getSubModels()[0]; - auto *pass = submodel->getPasses()[0]; - auto *inputAssembler = submodel->getInputAssembler(); - auto *pso = PipelineStateManager::getOrCreatePipelineState( - pass, submodel->getShaders()[0], inputAssembler, renderPass); - cmdBuff->bindPipelineState(pso); - cmdBuff->bindDescriptorSet(materialSet, pass->getDescriptorSet()); - cmdBuff->bindDescriptorSet(localSet, submodel->getDescriptorSet()); - cmdBuff->bindInputAssembler(inputAssembler); - cmdBuff->draw(inputAssembler); - } } } // namespace pipeline diff --git a/native/cocos/renderer/pipeline/helper/Utils.h b/native/cocos/renderer/pipeline/helper/Utils.h new file mode 100644 index 0000000000..900010c5a1 --- /dev/null +++ b/native/cocos/renderer/pipeline/helper/Utils.h @@ -0,0 +1,73 @@ +/**************************************************************************** + Copyright (c) 2020-2021 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +****************************************************************************/ + +#pragma once + +#include "../PipelineStateManager.h" +#include "gfx-base/GFXCommandBuffer.h" +#include "gfx-base/GFXDef.h" +#include "gfx-base/GFXSwapchain.h" +#include "pipeline/Define.h" +#include "scene/Model.h" +#include "scene/SubModel.h" + + +namespace cc { +namespace pipeline { + +inline void srgbToLinear(gfx::Color *out, const gfx::Color &gamma) { + out->x = gamma.x * gamma.x; + out->y = gamma.y * gamma.y; + out->z = gamma.z * gamma.z; +} + +inline void linearToSrgb(gfx::Color *out, const gfx::Color &linear) { + out->x = std::sqrt(linear.x); + out->y = std::sqrt(linear.y); + out->z = std::sqrt(linear.z); +} + +inline void renderProfiler(gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuff, scene::Model *profiler, gfx::Swapchain *swapchain) { + if (profiler && profiler->getEnabled() && swapchain) { + gfx::Viewport viewport{0, 0, swapchain->getWidth(), swapchain->getHeight()}; + gfx::Rect scissor{0, 0, swapchain->getWidth(), swapchain->getHeight()}; + + auto *submodel = profiler->getSubModels()[0]; + auto *pass = submodel->getPass(0); + auto *ia = submodel->getInputAssembler(); + auto *pso = PipelineStateManager::getOrCreatePipelineState(pass, submodel->getShader(0), ia, renderPass); + + cmdBuff->setViewport(viewport); + cmdBuff->setScissor(scissor); + cmdBuff->bindPipelineState(pso); + cmdBuff->bindDescriptorSet(materialSet, pass->getDescriptorSet()); + cmdBuff->bindDescriptorSet(localSet, submodel->getDescriptorSet()); + cmdBuff->bindInputAssembler(ia); + cmdBuff->draw(ia); + } +} + +} // namespace pipeline +} // namespace cc